diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 5d431348a..dd4171ab1 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -424,8 +424,8 @@ ids-with-children (concat ids (mapcat #(cp/get-children % objects) (filter not-frame-id? ids)))] - (d/update-in-when state [:workspace-data :pages-index page-id :objects] - #(reduce update-shape % ids-with-children))))))) + (update state :workspace-modifiers + #(reduce update-shape % ids-with-children))))))) ;; Set-rotation is custom because applies different modifiers to each @@ -476,9 +476,13 @@ (watch [it state stream] (let [objects (wsh/lookup-page-objects state) children-ids (->> ids (mapcat #(cp/get-children % objects))) - ids-with-children (d/concat [] children-ids ids)] + ids-with-children (d/concat [] children-ids ids) + object-modifiers (get state :workspace-modifiers)] (rx/of (dwu/start-undo-transaction) - (dch/update-shapes ids-with-children gsh/transform-shape {:reg-objects? true}) + (dch/update-shapes ids-with-children (fn [shape] + (-> shape + (merge (get object-modifiers (:id shape))) + (gsh/transform-shape))) {:reg-objects? true}) (clear-local-transform) (dwu/commit-undo-transaction)))))) @@ -572,4 +576,5 @@ ptk/UpdateEvent (update [_ state] (-> state + (dissoc :workspace-modifiers) (update :workspace-local dissoc :modifiers :current-move-selected))))) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 9b828903c..3a50f2a46 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -1,3 +1,4 @@ + ;; This Source Code Form is subject to the terms of the Mozilla Public ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -209,7 +210,10 @@ st/state)) (def workspace-page-objects - (l/derived :objects workspace-page)) + (l/derived wsh/lookup-page-objects st/state =)) + +(def workspace-modifiers + (l/derived :workspace-modifiers st/state)) (def workspace-page-options (l/derived :options workspace-page)) @@ -228,12 +232,21 @@ (l/derived #(get % id) workspace-page-objects)) (defn objects-by-id - [ids] - (l/derived (fn [objects] - (into [] (comp (map #(get objects %)) - (remove nil?)) - ids)) - workspace-page-objects =)) + ([ids] + (objects-by-id ids nil)) + + ([ids {:keys [with-modifiers?] + :or { with-modifiers? false }}] + (l/derived (fn [state] + (let [objects (wsh/lookup-page-objects state) + modifiers (:workspace-modifiers state) + objects (cond-> objects + with-modifiers? + (d/deep-merge modifiers)) + xform (comp (map #(get objects %)) + (remove nil?))] + (into [] xform ids))) + st/state =))) (def selected-data (l/derived #(let [selected (wsh/lookup-selected %) diff --git a/frontend/src/app/main/ui/measurements.cljs b/frontend/src/app/main/ui/measurements.cljs index 0d6fc0d8b..75dce1ac1 100644 --- a/frontend/src/app/main/ui/measurements.cljs +++ b/frontend/src/app/main/ui/measurements.cljs @@ -235,7 +235,7 @@ [{:keys [bounds frame selected-shapes hover-shape zoom]}] (let [selected-ids (into #{} (map :id) selected-shapes) selected-selrect (gsh/selection-rect selected-shapes) - hover-selrect (:selrect hover-shape) + hover-selrect (-> hover-shape :points gsh/points->selrect) bounds-selrect (bound->selrect bounds) hover-selected-shape? (not (contains? selected-ids (:id hover-shape)))] diff --git a/frontend/src/app/main/ui/workspace/shapes/group.cljs b/frontend/src/app/main/ui/workspace/shapes/group.cljs index d55215d1e..22ca26f1b 100644 --- a/frontend/src/app/main/ui/workspace/shapes/group.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/group.cljs @@ -38,7 +38,7 @@ {:keys [id x y width height]} shape - childs-ref (mf/use-memo (mf/deps shape) #(refs/objects-by-id (:shapes shape))) + childs-ref (mf/use-memo (mf/deps shape) #(refs/objects-by-id (:shapes shape) {:with-modifiers? true})) childs (mf/deref childs-ref)] [:> shape-container {:shape shape} diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 6e2363cb6..b2acf0e1a 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -59,6 +59,8 @@ drawing (mf/deref refs/workspace-drawing) options (mf/deref refs/workspace-page-options) objects (mf/deref refs/workspace-page-objects) + object-modifiers (mf/deref refs/workspace-modifiers) + objects (d/deep-merge objects object-modifiers) ;; STATE alt? (mf/use-state false) @@ -133,8 +135,7 @@ show-snap-distance? (and (contains? layout :dynamic-alignment) (= transform :move) (not (empty? selected))) show-snap-points? (and (contains? layout :dynamic-alignment) (or drawing-obj transform)) show-selrect? (and selrect (empty? drawing)) - show-measures? (and (not transform) (not path-editing?) show-distances?) - ] + show-measures? (and (not transform) (not path-editing?) show-distances?)] (hooks/setup-dom-events viewport-ref zoom disable-paste in-viewport?) (hooks/setup-viewport-size viewport-ref) @@ -205,8 +206,7 @@ :on-pointer-enter on-pointer-enter :on-pointer-leave on-pointer-leave :on-pointer-move on-pointer-move - :on-pointer-up on-pointer-up - } + :on-pointer-up on-pointer-up} [:g {:style {:pointer-events (if disable-events? "none" "auto")}} @@ -222,6 +222,7 @@ (when show-selection-handlers? [:& selection/selection-handlers {:selected selected + :shapes selected-shapes :zoom zoom :edition edition :disable-handlers (or drawing-tool edition) diff --git a/frontend/src/app/main/ui/workspace/viewport/selection.cljs b/frontend/src/app/main/ui/workspace/viewport/selection.cljs index 8cad2d8fc..fa23c720c 100644 --- a/frontend/src/app/main/ui/workspace/viewport/selection.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/selection.cljs @@ -355,13 +355,8 @@ (mf/defc selection-handlers {::mf/wrap [mf/memo]} - [{:keys [selected edition zoom disable-handlers on-move-selected] :as props}] - (let [;; We need remove posible nil values because on shape - ;; deletion many shape will reamin selected and deleted - ;; in the same time for small instant of time - shapes (->> (mf/deref (refs/objects-by-id selected)) - (remove nil?)) - num (count shapes) + [{:keys [shapes selected edition zoom disable-handlers on-move-selected] :as props}] + (let [num (count shapes) {:keys [id type] :as shape} (first shapes) color (if (or (> num 1) (nil? (:shape-ref shape)))