diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index e1e31ed30..b53d2af2a 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -20,13 +20,13 @@ (defn- generate-unapply-tokens "When updating attributes that have a token applied, we must unapply it, because the value of the attribute now has been given directly, and does not come from the token." - [changes objects] + [changes objects changed-sub-attr] (let [mod-obj-changes (->> (:redo-changes changes) (filter #(= (:type %) :mod-obj))) check-attr (fn [shape changes attr] (let [tokens (get shape :applied-tokens {}) - token-attrs (cto/shape-attr->token-attrs attr)] + token-attrs (cto/shape-attr->token-attrs attr changed-sub-attr)] (if (some #(contains? tokens %) token-attrs) (pcb/update-shapes changes [(:id shape)] #(cto/unapply-token-id % token-attrs)) changes))) @@ -44,7 +44,7 @@ mod-obj-changes))) (defn generate-update-shapes - [changes ids update-fn objects {:keys [attrs ignore-tree ignore-touched with-objects?]}] + [changes ids update-fn objects {:keys [attrs changed-sub-attr ignore-tree ignore-touched with-objects?]}] (let [changes (reduce (fn [changes id] (let [opts {:attrs attrs @@ -61,7 +61,7 @@ (pcb/reorder-grid-children ids) (cond-> (not ignore-touched) - (generate-unapply-tokens objects)))] + (generate-unapply-tokens objects changed-sub-attr)))] changes)) (defn- generate-update-shape-flags diff --git a/common/src/app/common/types/token.cljc b/common/src/app/common/types/token.cljc index 6afa458fc..3c68fa0e4 100644 --- a/common/src/app/common/types/token.cljc +++ b/common/src/app/common/types/token.cljc @@ -175,15 +175,20 @@ ::dimensions]) (defn shape-attr->token-attrs - [shape-attr] - (cond - (= :fills shape-attr) #{:fill} - (= :strokes shape-attr) #{:stroke-color :stroke-width} - (border-radius-keys shape-attr) #{shape-attr} - (sizing-keys shape-attr) #{shape-attr} - (opacity-keys shape-attr) #{shape-attr} - (spacing-keys shape-attr) #{shape-attr} - (rotation-keys shape-attr) #{shape-attr})) + ([shape-attr] (shape-attr->token-attrs shape-attr nil)) + ([shape-attr changed-sub-attr] + (cond + (= :fills shape-attr) #{:fill} + (and (= :strokes shape-attr) (nil? changed-sub-attr)) #{:stroke-width :stroke-color} + (= :strokes shape-attr) + (cond + (some #{:stroke-color} changed-sub-attr) #{:stroke-color} + (some #{:stroke-width} changed-sub-attr) #{:stroke-width}) + (border-radius-keys shape-attr) #{shape-attr} + (sizing-keys shape-attr) #{shape-attr} + (opacity-keys shape-attr) #{shape-attr} + (spacing-keys shape-attr) #{shape-attr} + (rotation-keys shape-attr) #{shape-attr}))) (defn token-attr->shape-attr [token-attr] diff --git a/frontend/src/app/main/data/workspace/colors.cljs b/frontend/src/app/main/data/workspace/colors.cljs index cdcc683a7..0b5b53046 100644 --- a/frontend/src/app/main/data/workspace/colors.cljs +++ b/frontend/src/app/main/data/workspace/colors.cljs @@ -272,38 +272,39 @@ (ptk/reify ::change-stroke-color ptk/WatchEvent (watch [_ _ _] - (rx/of (dwsh/update-shapes - ids - (fn [shape] - (let [stroke (get-in shape [:strokes index]) - attrs (cond-> (build-stroke-style-attrs stroke) - (contains? color :color) - (assoc :stroke-color (:color color)) + (rx/of (let [options (assoc options :changed-sub-attr [:stroke-color])] + (dwsh/update-shapes + ids + (fn [shape] + (let [stroke (get-in shape [:strokes index]) + attrs (cond-> (build-stroke-style-attrs stroke) + (contains? color :color) + (assoc :stroke-color (:color color)) - (contains? color :id) - (assoc :stroke-color-ref-id (:id color)) + (contains? color :id) + (assoc :stroke-color-ref-id (:id color)) - (contains? color :file-id) - (assoc :stroke-color-ref-file (:file-id color)) + (contains? color :file-id) + (assoc :stroke-color-ref-file (:file-id color)) - (contains? color :gradient) - (assoc :stroke-color-gradient (:gradient color)) + (contains? color :gradient) + (assoc :stroke-color-gradient (:gradient color)) - (contains? color :opacity) - (assoc :stroke-opacity (:opacity color)) + (contains? color :opacity) + (assoc :stroke-opacity (:opacity color)) - (contains? color :image) - (assoc :stroke-image (:image color)) + (contains? color :image) + (assoc :stroke-image (:image color)) - :always - (d/without-nils))] - (cond-> shape - (not (contains? shape :strokes)) - (assoc :strokes []) + :always + (d/without-nils))] + (cond-> shape + (not (contains? shape :strokes)) + (assoc :strokes []) - :always - (assoc-in [:strokes index] attrs)))) - options)))))) + :always + (assoc-in [:strokes index] attrs)))) + options))))))) (defn change-stroke-attrs ([ids attrs index] (change-stroke-attrs ids attrs index nil)) @@ -311,19 +312,21 @@ (ptk/reify ::change-stroke-attrs ptk/WatchEvent (watch [_ _ _] - (rx/of (dwsh/update-shapes - ids - (fn [shape] - (let [stroke (get-in shape [:strokes index]) - style-attrs (build-stroke-style-attrs stroke) - attrs (merge stroke style-attrs attrs)] - (cond-> shape - (not (contains? shape :strokes)) - (assoc :strokes []) + (let [changed-sub-attr (keys attrs) + options (assoc options :changed-sub-attr changed-sub-attr)] + (rx/of (dwsh/update-shapes + ids + (fn [shape] + (let [stroke (get-in shape [:strokes index]) + style-attrs (build-stroke-style-attrs stroke) + attrs (merge stroke style-attrs attrs)] + (cond-> shape + (not (contains? shape :strokes)) + (assoc :strokes []) - :always - (assoc-in [:strokes index] attrs))))) - options))))) + :always + (assoc-in [:strokes index] attrs)))) + options))))))) (defn change-shadow [ids attrs index] @@ -379,7 +382,9 @@ ptk/WatchEvent (watch [_ _ _] (let [add-stroke (fn [shape] (update shape :strokes #(into [stroke] %)))] - (rx/of (dwsh/update-shapes ids add-stroke)))))) + (rx/of (dwsh/update-shapes ids + add-stroke + {:attrs [:strokes]})))))) (defn remove-stroke [ids position] @@ -397,7 +402,9 @@ (mapv second))) (remove-stroke [shape] (update shape :strokes remove-fill-by-index position))] - (rx/of (dwsh/update-shapes ids remove-stroke)))))) + (rx/of (dwsh/update-shapes ids + remove-stroke + {:attrs [:strokes]})))))) (defn remove-all-strokes [ids] @@ -410,7 +417,9 @@ ptk/WatchEvent (watch [_ _ _] (let [remove-all #(assoc % :strokes [])] - (rx/of (dwsh/update-shapes ids remove-all)))))) + (rx/of (dwsh/update-shapes ids + remove-all + {:attrs [:strokes]})))))) (defn reorder-shadows [ids index new-index] @@ -428,7 +437,8 @@ (watch [_ _ _] (rx/of (dwsh/update-shapes ids - #(swap-attrs % :strokes index new-index)))))) + #(swap-attrs % :strokes index new-index) + {:attrs [:strokes]}))))) (defn picker-for-selected-shape [] diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index fd2e13b2d..f421e6dc5 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -47,7 +47,7 @@ (defn update-shapes ([ids update-fn] (update-shapes ids update-fn nil)) - ([ids update-fn {:keys [reg-objects? save-undo? stack-undo? attrs ignore-tree page-id ignore-touched undo-group with-objects?] + ([ids update-fn {:keys [reg-objects? save-undo? stack-undo? attrs ignore-tree page-id ignore-touched undo-group with-objects? changed-sub-attr] :or {reg-objects? false save-undo? true stack-undo? false ignore-touched false with-objects? false}}] (dm/assert! @@ -76,6 +76,7 @@ update-fn objects {:attrs attrs + :changed-sub-attr changed-sub-attr :ignore-tree ignore-tree :ignore-touched ignore-touched :with-objects? with-objects?})