diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 0cdcf64de..92f68d2de 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1050,30 +1050,13 @@ selected (get-in state [:workspace-local :selected]) moved (if (= 1 (count selected)) (align-object-to-frame objects (first selected) axis) - (align-objects-list objects selected axis))] - (loop [moved (seq moved) - rchanges [] - uchanges []] - (if (nil? moved) - (do - ;; (println "================ rchanges") - ;; (cljs.pprint/pprint rchanges) - ;; (println "================ uchanges") - ;; (cljs.pprint/pprint uchanges) - (rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}))) - (let [curr (first moved) - prev (get objects (:id curr)) - ops1 (dwc/generate-operations prev curr) - ops2 (dwc/generate-operations curr prev true)] - (recur (next moved) - (conj rchanges {:type :mod-obj - :page-id page-id - :operations ops1 - :id (:id curr)}) - (conj uchanges {:type :mod-obj - :page-id page-id - :operations ops2 - :id (:id curr)}))))))))) + (align-objects-list objects selected axis)) + + moved-objects (->> moved (group-by :id)) + ids (keys moved-objects) + update-fn (fn [shape] (first (get moved-objects (:id shape))))] + + (rx/of (dch/update-shapes ids update-fn {:reg-objects? true})))))) (defn align-object-to-frame [objects object-id axis] @@ -1097,30 +1080,12 @@ objects (dwc/lookup-page-objects state page-id) selected (get-in state [:workspace-local :selected]) moved (-> (map #(get objects %) selected) - (gal/distribute-space axis objects))] - (loop [moved (seq moved) - rchanges [] - uchanges []] - (if (nil? moved) - (do - ;; (println "================ rchanges") - ;; (cljs.pprint/pprint rchanges) - ;; (println "================ uchanges") - ;; (cljs.pprint/pprint uchanges) - (rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}))) - (let [curr (first moved) - prev (get objects (:id curr)) - ops1 (dwc/generate-operations prev curr) - ops2 (dwc/generate-operations curr prev true)] - (recur (next moved) - (conj rchanges {:type :mod-obj - :page-id page-id - :operations ops1 - :id (:id curr)}) - (conj uchanges {:type :mod-obj - :page-id page-id - :operations ops2 - :id (:id curr)}))))))))) + (gal/distribute-space axis objects)) + + moved-objects (->> moved (group-by :id)) + ids (keys moved-objects) + update-fn (fn [shape] (first (get moved-objects (:id shape))))] + (rx/of (dch/update-shapes ids update-fn {:reg-objects? true})))))) ;; --- Shape Proportions diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 955344a8e..c993d431a 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -220,58 +220,41 @@ ptk/WatchEvent (watch [_ state stream] (let [page-id (:current-page-id state) - - objects0 (get-in state [:workspace-file :data :pages-index page-id :objects]) - objects1 (get-in state [:workspace-data :pages-index page-id :objects])] - (if-not (every? #(contains? objects1(first %)) changes) + objects (get-in state [:workspace-data :pages-index page-id :objects])] + (if-not (every? #(contains? objects(first %)) changes) (rx/empty) - (let [change-text-shape - (fn [objects [id [new-width new-height]]] - (when (contains? objects id) - (let [shape (get objects id) - {:keys [selrect grow-type overflow-text]} (gsh/transform-shape shape) - {shape-width :width shape-height :height} selrect - modifier-width (gsh/resize-modifiers shape :width new-width) - modifier-height (gsh/resize-modifiers shape :height new-height) + (let [changes-map (->> changes (into {})) + ids (keys changes-map) + update-fn + (fn [shape] + (let [[new-width new-height] (get changes-map (:id shape)) + {:keys [selrect grow-type overflow-text]} (gsh/transform-shape shape) + {shape-width :width shape-height :height} selrect - shape (cond-> shape - (and overflow-text (not= :fixed grow-type)) - (assoc :overflow-text false) + modifier-width (gsh/resize-modifiers shape :width new-width) + modifier-height (gsh/resize-modifiers shape :height new-height)] - (and (= :fixed grow-type) (not overflow-text) (> new-height shape-height)) - (assoc :overflow-text true) + (cond-> shape + (and overflow-text (not= :fixed grow-type)) + (assoc :overflow-text false) - (and (= :fixed grow-type) overflow-text (<= new-height shape-height)) - (assoc :overflow-text false) + (and (= :fixed grow-type) (not overflow-text) (> new-height shape-height)) + (assoc :overflow-text true) - (and (not-changed? shape-width new-width) (= grow-type :auto-width)) - (-> (assoc :modifiers modifier-width) - (gsh/transform-shape)) + (and (= :fixed grow-type) overflow-text (<= new-height shape-height)) + (assoc :overflow-text false) - (and (not-changed? shape-height new-height) - (or (= grow-type :auto-height) (= grow-type :auto-width))) - (-> (assoc :modifiers modifier-height) - (gsh/transform-shape)))] - (assoc objects id shape)))) + (and (not-changed? shape-width new-width) (= grow-type :auto-width)) + (-> (assoc :modifiers modifier-width) + (gsh/transform-shape)) - undo-transaction (get-in state [:workspace-undo :transaction]) - objects2 (->> changes (reduce change-text-shape objects1)) + (and (not-changed? shape-height new-height) + (or (= grow-type :auto-height) (= grow-type :auto-width))) + (-> (assoc :modifiers modifier-height) + (gsh/transform-shape)))))] - regchg {:type :reg-objects - :page-id page-id - :shapes (vec (keys changes))} - - rchanges (dwc/generate-changes page-id objects1 objects2) - uchanges (dwc/generate-changes page-id objects2 objects0)] - - (if (seq rchanges) - (rx/concat - (when-not undo-transaction - (rx/of (dwc/start-undo-transaction))) - (rx/of (dwc/commit-changes (conj rchanges regchg) (conj uchanges regchg) {:commit-local? true})) - (when-not undo-transaction - (rx/of (dwc/discard-undo-transaction))))))))))) + (rx/of (dch/update-shapes ids update-fn {:reg-objects? true})))))))) ;; When a resize-event arrives we start "buffering" for a time ;; after that time we invoke `resize-text-batch` with all the changes diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index a9cb1c3be..65756a5d3 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -454,35 +454,13 @@ (ptk/reify ::apply-modifiers ptk/WatchEvent (watch [_ state stream] - (let [page-id (:current-page-id state) - - objects0 (get-in state [:workspace-file :data :pages-index page-id :objects]) - objects1 (get-in state [:workspace-data :pages-index page-id :objects]) - - ;; ID's + Children ID's - ids-with-children (d/concat [] (mapcat #(cp/get-children % objects1) ids) ids) - - ;; For each shape applies the modifiers by transforming the objects - update-shape #(update %1 %2 gsh/transform-shape) - objects2 (reduce update-shape objects1 ids-with-children) - - regchg {:type :reg-objects - :page-id page-id - :shapes (vec ids)} - - ;; we need to generate redo chages from current - ;; state (with current temporal values) to new state but - ;; the undo should be calculated from clear current - ;; state (without temporal values in it, for this reason - ;; we have 3 different objects references). - - rchanges (conj (dwc/generate-changes page-id objects1 objects2) regchg) - uchanges (conj (dwc/generate-changes page-id objects2 objects0) regchg)] - - (rx/of (dwc/start-undo-transaction) - (dwc/commit-changes rchanges uchanges {:commit-local? true}) + (let [objects (dwc/lookup-page-objects state) + children-ids (->> ids (mapcat #(cp/get-children % objects))) + ids-with-children (d/concat [] children-ids ids)] + (rx/of (dwu/start-undo-transaction) + (dch/update-shapes ids-with-children gsh/transform-shape {:reg-objects? true}) (clear-local-transform) - (dwc/commit-undo-transaction)))))) + (dwu/commit-undo-transaction)))))) ;; --- Update Dimensions