From e43ab51b7d32c8d30317d6fd3f8581bc79654d3b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 25 May 2021 12:18:49 +0200 Subject: [PATCH] :bug: Fix problem with locked shapes when change parents --- CHANGES.md | 1 + common/app/common/geom/shapes.cljc | 2 +- .../main/data/workspace/state_helpers.cljs | 23 ++++-- .../app/main/data/workspace/transforms.cljs | 81 ++++++++++--------- .../app/main/ui/workspace/sidebar/layers.cljs | 4 - .../ui/workspace/viewport/snap_points.cljs | 5 +- 6 files changed, 63 insertions(+), 53 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7d77486b6..3a0659912 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -35,6 +35,7 @@ - Fix order on color palette [#961](https://github.com/penpot/penpot/issues/961) - Fix issue when group creation leaves an empty group [#1724](https://tree.taiga.io/project/penpot/issue/1724) - Fix problem with :multiple for colors and typographies [#1668](https://tree.taiga.io/project/penpot/issue/1668) +- Fix problem with locked shapes when change parents [#974](https://github.com/penpot/penpot/issues/974) ### :arrow_up: Deps updates diff --git a/common/app/common/geom/shapes.cljc b/common/app/common/geom/shapes.cljc index a93c20ad3..db0d51e29 100644 --- a/common/app/common/geom/shapes.cljc +++ b/common/app/common/geom/shapes.cljc @@ -162,7 +162,7 @@ :points points)))) (defn rotation-modifiers - [center shape angle] + [shape center angle] (let [displacement (let [shape-center (gco/center-shape shape)] (-> (gmt/matrix) (gmt/rotate angle center) diff --git a/frontend/src/app/main/data/workspace/state_helpers.cljs b/frontend/src/app/main/data/workspace/state_helpers.cljs index 9ce4a3d3f..0710aba55 100644 --- a/frontend/src/app/main/data/workspace/state_helpers.cljs +++ b/frontend/src/app/main/data/workspace/state_helpers.cljs @@ -26,11 +26,18 @@ (get-in state [:workspace-data :components component-id :objects]))) (defn lookup-selected - [state] - (let [objects (lookup-page-objects state) - selected (->> (get-in state [:workspace-local :selected]) - (cp/clean-loops objects)) - is-present? (fn [id] (contains? objects id))] - (into (d/ordered-set) - (filter is-present?) - selected))) + ([state] + (lookup-selected state nil)) + + ([state {:keys [omit-blocked?] + :or {omit-blocked? false}}] + (let [objects (lookup-page-objects state) + selected (->> (get-in state [:workspace-local :selected]) + (cp/clean-loops objects)) + selectable? (fn [id] + (and (contains? objects id) + (or (not omit-blocked?) + (not (get-in objects [id :blocked] false)))))] + (into (d/ordered-set) + (filter selectable?) + selected)))) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index cc0270a95..e726917de 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -242,23 +242,24 @@ ptk/WatchEvent (watch [it state stream] (let [initial (deref ms/mouse-position) - selected (wsh/lookup-selected state) + selected (wsh/lookup-selected state {:omit-blocked? true}) stopper (rx/filter ms/mouse-up? stream)] - (->> ms/mouse-position - (rx/take-until stopper) - (rx/map #(gpt/to-vec initial %)) - (rx/map #(gpt/length %)) - (rx/filter #(> % 1)) - (rx/take 1) - (rx/with-latest vector ms/mouse-position-alt) - (rx/mapcat - (fn [[_ alt?]] - (if alt? - ;; When alt is down we start a duplicate+move - (rx/of (start-move-duplicate initial) - dws/duplicate-selected) - ;; Otherwise just plain old move - (rx/of (start-move initial selected)))))))))) + (when-not (empty? selected) + (->> ms/mouse-position + (rx/take-until stopper) + (rx/map #(gpt/to-vec initial %)) + (rx/map #(gpt/length %)) + (rx/filter #(> % 1)) + (rx/take 1) + (rx/with-latest vector ms/mouse-position-alt) + (rx/mapcat + (fn [[_ alt?]] + (if alt? + ;; When alt is down we start a duplicate+move + (rx/of (start-move-duplicate initial) + dws/duplicate-selected) + ;; Otherwise just plain old move + (rx/of (start-move initial selected))))))))))) (defn start-move-duplicate [from-position] (ptk/reify ::start-move-selected @@ -319,7 +320,8 @@ (watch [it state stream] (let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id) - ids (if (nil? ids) (wsh/lookup-selected state) ids) + selected (wsh/lookup-selected state {:omit-blocked? true}) + ids (if (nil? ids) selected ids) shapes (mapv #(get objects %) ids) stopper (rx/filter ms/mouse-up? stream) layout (get state :workspace-layout) @@ -398,7 +400,7 @@ ptk/WatchEvent (watch [it state stream] (if (= same-event (get-in state [:workspace-local :current-move-selected])) - (let [selected (wsh/lookup-selected state) + (let [selected (wsh/lookup-selected state {:omit-blocked? true}) move-events (->> stream (rx/filter (ptk/type? ::move-selected)) (rx/filter #(= direction (deref %)))) @@ -435,6 +437,8 @@ page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id) + ids (->> ids (into #{} (remove #(get-in objects [% :blocked] false)))) + not-frame-id? (fn [shape-id] (let [shape (get objects shape-id)] @@ -457,27 +461,28 @@ ;; shape adjusting their position. (defn set-rotation - ([delta-rotation shapes] - (set-rotation delta-rotation shapes (-> shapes gsh/selection-rect gsh/center-selrect))) + ([angle shapes] + (set-rotation angle shapes (-> shapes gsh/selection-rect gsh/center-selrect))) - ([delta-rotation shapes center] - (letfn [(rotate-shape [objects angle shape center] - (update-in objects [(:id shape) :modifiers] merge (gsh/rotation-modifiers center shape angle))) + ([angle shapes center] + (ptk/reify ::set-rotation + ptk/UpdateEvent + (update [_ state] + (let [objects (wsh/lookup-page-objects state) + id->obj #(get objects %) + get-children (fn [shape] (map id->obj (cp/get-children (:id shape) objects))) - (rotate-around-center [objects angle center shapes] - (reduce #(rotate-shape %1 angle %2 center) objects shapes)) + shapes (->> shapes (into [] (remove #(get % :blocked false)))) - (set-rotation [objects] - (let [id->obj #(get objects %) - get-children (fn [shape] (map id->obj (cp/get-children (:id shape) objects))) - shapes (concat shapes (mapcat get-children shapes))] - (rotate-around-center objects delta-rotation center shapes)))] + shapes (->> shapes (mapcat get-children) (concat shapes)) - (ptk/reify ::set-rotation - ptk/UpdateEvent - (update [_ state] - (let [page-id (:current-page-id state)] - (d/update-in-when state [:workspace-data :pages-index page-id :objects] set-rotation))))))) + update-shape + (fn [modifiers shape] + (let [rotate-modifiers (gsh/rotation-modifiers shape center angle)] + (assoc-in modifiers [(:id shape) :modifiers] rotate-modifiers)))] + (-> state + (update :workspace-modifiers + #(reduce update-shape % shapes)))))))) (defn increase-rotation [ids rotation] (ptk/reify ::increase-rotation @@ -583,7 +588,7 @@ ptk/WatchEvent (watch [it state stream] (let [objects (wsh/lookup-page-objects state) - selected (wsh/lookup-selected state) + selected (wsh/lookup-selected state {:omit-blocked? true}) shapes (map #(get objects %) selected) selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape))) origin (gpt/point (:x selrect) (+ (:y selrect) (/ (:height selrect) 2)))] @@ -600,7 +605,7 @@ ptk/WatchEvent (watch [it state stream] (let [objects (wsh/lookup-page-objects state) - selected (wsh/lookup-selected state) + selected (wsh/lookup-selected state {:omit-blocked? true}) shapes (map #(get objects %) selected) selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape))) origin (gpt/point (+ (:x selrect) (/ (:width selrect) 2)) (:y selrect))] @@ -633,5 +638,5 @@ (ptk/reify ::selected-to-path ptk/WatchEvent (watch [_ state stream] - (let [ids (wsh/lookup-selected state)] + (let [ids (wsh/lookup-selected state {:omit-blocked? true})] (rx/of (dch/update-shapes ids ups/convert-to-path)))))) diff --git a/frontend/src/app/main/ui/workspace/sidebar/layers.cljs b/frontend/src/app/main/ui/workspace/sidebar/layers.cljs index fa842aa4d..310ece276 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/layers.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/layers.cljs @@ -150,10 +150,6 @@ (dom/prevent-default event) (let [id (:id item)] (cond - (or (:blocked item) - (:hidden item)) - nil - (kbd/shift? event) (st/emit! (dw/shift-select-shapes id)) diff --git a/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs b/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs index 9dda3ac8f..f9cc2707c 100644 --- a/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs @@ -131,7 +131,7 @@ #(rx/dispose! sub)))) (mf/use-effect - (mf/deps shapes modifiers) + (mf/deps shapes filter-shapes modifiers) (fn [] (rx/push! subject props))) @@ -161,7 +161,8 @@ (map #(get objects %)) (filterv (comp not nil?))) filter-shapes (into #{} - (mapcat #(cp/get-object-with-children % objects)) + (comp (mapcat #(cp/get-object-with-children % objects)) + (map :id)) selected) filter-shapes (fn [id]