diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index 96336e386d..a6637d0081 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -675,7 +675,7 @@ any-sync? (some need-sync? operations)] (when any-sync? (let [xform (comp (filter :main-instance?) ; Select shapes that are main component instances - (map :id))] + (map :component-id))] (into #{} xform shape-and-parents)))))) (defmethod components-changed :mov-objects @@ -684,7 +684,7 @@ (let [page (ctpl/get-page file-data page-id) xform (comp (filter :main-instance?) - (map :id)) + (map :component-id)) check-shape (fn [shape-id others] @@ -703,7 +703,7 @@ shape-and-parents (map (partial ctn/get-shape page) (cons id (cph/get-parent-ids (:objects page) id))) xform (comp (filter :main-instance?) - (map :id))] + (map :component-id))] (into #{} xform shape-and-parents)))) (defmethod components-changed :default diff --git a/common/src/app/common/pages/changes_builder.cljc b/common/src/app/common/pages/changes_builder.cljc index 37626cf8f8..56ba9e95b7 100644 --- a/common/src/app/common/pages/changes_builder.cljc +++ b/common/src/app/common/pages/changes_builder.cljc @@ -359,54 +359,56 @@ (apply-changes-local))))) (defn remove-objects - [changes ids] - (assert-page-id changes) - (assert-objects changes) - (let [page-id (::page-id (meta changes)) - objects (lookup-objects changes) + ([changes ids] (remove-objects changes ids nil)) + ([changes ids {:keys [ignore-touched] :or {ignore-touched false}}] + (assert-page-id changes) + (assert-objects changes) + (let [page-id (::page-id (meta changes)) + objects (lookup-objects changes) - add-redo-change - (fn [change-set id] - (conj change-set - {:type :del-obj - :page-id page-id - :id id})) + add-redo-change + (fn [change-set id] + (conj change-set + {:type :del-obj + :page-id page-id + :ignore-touched ignore-touched + :id id})) - add-undo-change-shape - (fn [change-set id] - (let [shape (get objects id)] - (d/preconj - change-set - {:type :add-obj - :id id - :page-id page-id - :parent-id (:frame-id shape) - :frame-id (:frame-id shape) - :index (cph/get-position-on-parent objects id) - :obj (cond-> shape - (contains? shape :shapes) - (assoc :shapes []))}))) + add-undo-change-shape + (fn [change-set id] + (let [shape (get objects id)] + (d/preconj + change-set + {:type :add-obj + :id id + :page-id page-id + :parent-id (:frame-id shape) + :frame-id (:frame-id shape) + :index (cph/get-position-on-parent objects id) + :obj (cond-> shape + (contains? shape :shapes) + (assoc :shapes []))}))) - add-undo-change-parent - (fn [change-set id] - (let [shape (get objects id) - prev-sibling (cph/get-prev-sibling objects (:id shape))] - (d/preconj - change-set - {:type :mov-objects - :page-id page-id - :parent-id (:parent-id shape) - :shapes [id] - :after-shape prev-sibling - :index 0 - :ignore-touched true})))] + add-undo-change-parent + (fn [change-set id] + (let [shape (get objects id) + prev-sibling (cph/get-prev-sibling objects (:id shape))] + (d/preconj + change-set + {:type :mov-objects + :page-id page-id + :parent-id (:parent-id shape) + :shapes [id] + :after-shape prev-sibling + :index 0 + :ignore-touched true})))] - (-> changes - (update :redo-changes #(reduce add-redo-change % ids)) - (update :undo-changes #(as-> % $ - (reduce add-undo-change-parent $ ids) - (reduce add-undo-change-shape $ ids))) - (apply-changes-local)))) + (-> changes + (update :redo-changes #(reduce add-redo-change % ids)) + (update :undo-changes #(as-> % $ + (reduce add-undo-change-parent $ ids) + (reduce add-undo-change-shape $ ids))) + (apply-changes-local))))) (defn resize-parents [changes ids] diff --git a/common/src/app/common/types/shape/text.cljc b/common/src/app/common/types/shape/text.cljc index 3eb0918f84..89851ba8e4 100644 --- a/common/src/app/common/types/shape/text.cljc +++ b/common/src/app/common/types/shape/text.cljc @@ -47,7 +47,9 @@ [:map [:text :string] [:key {:optional true} :string] - [:fills [:vector {:gen/max 2} ::shape/fill]] + [:fills {:optional true} + [:maybe + [:vector {:gen/max 2} ::shape/fill]]] [:font-family {:optional true} :string] [:font-size {:optional true} :string] [:font-style {:optional true} :string] diff --git a/frontend/src/app/main/data/workspace/changes.cljs b/frontend/src/app/main/data/workspace/changes.cljs index cfa5cb1a9f..add461c147 100644 --- a/frontend/src/app/main/data/workspace/changes.cljs +++ b/frontend/src/app/main/data/workspace/changes.cljs @@ -51,8 +51,8 @@ (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-remote?] - :or {reg-objects? false save-undo? true stack-undo? false ignore-remote? false}}] + ([ids update-fn {:keys [reg-objects? save-undo? stack-undo? attrs ignore-tree page-id ignore-remote? ignore-touched] + :or {reg-objects? false save-undo? true stack-undo? false ignore-remote? false ignore-touched false}}] (dm/assert! (sm/coll-of-uuid? ids)) (dm/assert! (fn? update-fn)) @@ -71,7 +71,9 @@ changes (reduce (fn [changes id] - (let [opts {:attrs attrs :ignore-geometry? (get ignore-tree id)}] + (let [opts {:attrs attrs + :ignore-geometry? (get ignore-tree id) + :ignore-touched ignore-touched}] (pcb/update-shapes changes [id] update-fn (d/without-nils opts)))) (-> (pcb/empty-changes it page-id) (pcb/set-save-undo? save-undo?) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 52fbef829a..d47efe8020 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -665,6 +665,22 @@ (sync-file file-id file-id :components (:component-id shape) undo-group)) (dwu/commit-undo-transaction undo-id))))))) +(defn launch-component-sync + "Launch a sync of the current file and of the library file of the given component." + ([component-id file-id] (launch-component-sync component-id file-id nil)) + ([component-id file-id undo-group] + (ptk/reify ::launch-component-sync + ptk/WatchEvent + (watch [_ state _] + (let [current-file-id (:current-file-id state) + undo-id (js/Symbol)] + (rx/of + (dwu/start-undo-transaction undo-id) + (sync-file current-file-id file-id :components component-id undo-group) + (when (not= current-file-id file-id) + (sync-file file-id file-id :components component-id undo-group)) + (dwu/commit-undo-transaction undo-id))))))) + (defn update-component-in-bulk [shapes file-id] (ptk/reify ::update-component-in-bulk @@ -897,7 +913,7 @@ :ids (map str components-changed) :undo-group undo-group) (run! st/emit! - (map #(update-component-sync % (:id old-data) undo-group) + (map #(launch-component-sync % (:id old-data) undo-group) components-changed))))))] (when components-v2 diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index 91d70542d4..f40393f4b4 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -90,7 +90,7 @@ (cond-> (nil? index) (pcb/add-object shape)) (cond-> (some? (:parent-id attrs)) - (pcb/change-parent (:parent-id attrs) [shape])) + (pcb/change-parent (:parent-id attrs) [shape] index)) (cond-> (ctl/grid-layout? objects (:parent-id shape)) (pcb/update-shapes [(:parent-id shape)] ctl/assign-cells)))] @@ -314,7 +314,7 @@ components-to-delete) changes (-> changes - (pcb/remove-objects all-children) + (pcb/remove-objects all-children {:ignore-touched true}) (pcb/remove-objects ids) (pcb/remove-objects empty-parents) (pcb/resize-parents all-parents) diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 2328386975..a9a3f4fe70 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -426,7 +426,10 @@ (let [ids (->> (keys props) (filter changed-text?))] (rx/of (dwu/start-undo-transaction undo-id) - (dch/update-shapes ids update-fn {:reg-objects? true :stack-undo? true :ignore-remote? true}) + (dch/update-shapes ids update-fn {:reg-objects? true + :stack-undo? true + :ignore-remote? true + :ignore-touched true}) (ptk/data-event :layout/update ids) (dwu/commit-undo-transaction undo-id)))))))) diff --git a/frontend/src/app/main/ui/shapes/custom_stroke.cljs b/frontend/src/app/main/ui/shapes/custom_stroke.cljs index ebc89b5d2e..43b2af4761 100644 --- a/frontend/src/app/main/ui/shapes/custom_stroke.cljs +++ b/frontend/src/app/main/ui/shapes/custom_stroke.cljs @@ -336,14 +336,10 @@ (> (count (:fills shape)) 1) (some :fill-color-gradient (:fills shape))) - props (-> (obj/get child "props") - (obj/clone)) - - props (cond-> props + props (cond-> (obj/create) (or ;; There are any shadows (and (seq (->> (:shadow shape) (remove :hidden))) (not (cph/frame-shape? shape))) - ;; There is a blur (and (:blur shape) (-> shape :blur :hidden not) (not (cph/frame-shape? shape)))) (obj/set! "filter" (dm/fmt "url(#filter_%)" render-id))) @@ -358,30 +354,33 @@ url-fill? (let [props (obj/set! props "style" - (-> (obj/get props "style") + (-> (obj/get child "props") + (obj/get "style") (obj/clone) (obj/without ["fill" "fillOpacity"])))] (obj/set! props "fill" (dm/fmt "url(#fill-%-%)" position render-id))) (and (some? svg-styles) (obj/contains? svg-styles "fill")) (let [style - (-> (obj/get props "style") + (-> (obj/get child "props") + (obj/get "style") (obj/clone) (obj/set! "fill" (obj/get svg-styles "fill")) (obj/set! "fillOpacity" (obj/get svg-styles "fillOpacity")))] (-> props (obj/set! "style" style))) - (and (some? svg-attrs) (empty? (:fills shape))) + (and (some? svg-attrs) + (obj/contains? svg-attrs "fill") + (empty? (:fills shape))) (let [style - (-> (obj/get props "style") + (-> (obj/get child "props") + (obj/get "style") (obj/clone)) - style (cond-> style - (obj/contains? svg-attrs "fill") - (-> - (obj/set! "fill" (obj/get svg-attrs "fill")) - (obj/set! "fillOpacity" (obj/get svg-attrs "fillOpacity"))))] + style (-> style + (obj/set! "fill" (obj/get svg-attrs "fill")) + (obj/set! "fillOpacity" (obj/get svg-attrs "fillOpacity")))] (-> props (obj/set! "style" style))) @@ -389,7 +388,8 @@ (let [fill-props (attrs/extract-fill-attrs (get-in shape [:fills 0]) render-id 0 (:type shape)) - style (-> (obj/get props "style") + style (-> (obj/get child "props") + (obj/get "style") (obj/clone) (obj/merge! (obj/get fill-props "style")))] @@ -399,14 +399,15 @@ (and (= :path (:type shape)) (empty? (:fills shape))) (let [style - (-> (obj/get props "style") + (-> (obj/get child "props") + (obj/get "style") (obj/clone) (obj/set! "fill" "none"))] (-> props (obj/set! "style" style))) :else - props))) + nil))) (defn build-stroke-props [position child value render-id] (let [props (-> (obj/get child "props") @@ -420,17 +421,20 @@ (obj/set! "fillOpacity" "none"))) (add-style (obj/get (attrs/extract-stroke-attrs value position render-id) "style"))))) - (mf/defc shape-fills {::mf/wrap-props false} [props] - (let [child (obj/get props "children") - shape (obj/get props "shape") - elem-name (obj/get child "type") - position (or (obj/get props "position") 0) - render-id (or (obj/get props "render-id") (mf/use-ctx muc/render-id))] - [:g.fills {:id (dm/fmt "fills-%" (:id shape))} - [:> elem-name (build-fill-props shape child position render-id)]])) + (let [child (obj/get props "children") + shape (obj/get props "shape") + elem-name (obj/get child "type") + position (or (obj/get props "position") 0) + render-id (or (obj/get props "render-id") (mf/use-ctx muc/render-id)) + fill-props (build-fill-props shape child position render-id)] + (when (some? fill-props) + [:g.fills {:id (dm/fmt "fills-%" (:id shape))} + [:> elem-name (-> (obj/get child "props") + (obj/clone) + (obj/merge! fill-props))]]))) (mf/defc shape-strokes {::mf/wrap-props false}