mirror of
https://github.com/penpot/penpot.git
synced 2025-05-12 20:46:38 +02:00
🐛 Fix problem with locked shapes when change parents
This commit is contained in:
parent
95cb6d132b
commit
e43ab51b7d
6 changed files with 63 additions and 53 deletions
|
@ -35,6 +35,7 @@
|
||||||
- Fix order on color palette [#961](https://github.com/penpot/penpot/issues/961)
|
- 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 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 :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
|
### :arrow_up: Deps updates
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@
|
||||||
:points points))))
|
:points points))))
|
||||||
|
|
||||||
(defn rotation-modifiers
|
(defn rotation-modifiers
|
||||||
[center shape angle]
|
[shape center angle]
|
||||||
(let [displacement (let [shape-center (gco/center-shape shape)]
|
(let [displacement (let [shape-center (gco/center-shape shape)]
|
||||||
(-> (gmt/matrix)
|
(-> (gmt/matrix)
|
||||||
(gmt/rotate angle center)
|
(gmt/rotate angle center)
|
||||||
|
|
|
@ -26,11 +26,18 @@
|
||||||
(get-in state [:workspace-data :components component-id :objects])))
|
(get-in state [:workspace-data :components component-id :objects])))
|
||||||
|
|
||||||
(defn lookup-selected
|
(defn lookup-selected
|
||||||
[state]
|
([state]
|
||||||
(let [objects (lookup-page-objects state)
|
(lookup-selected state nil))
|
||||||
selected (->> (get-in state [:workspace-local :selected])
|
|
||||||
(cp/clean-loops objects))
|
([state {:keys [omit-blocked?]
|
||||||
is-present? (fn [id] (contains? objects id))]
|
:or {omit-blocked? false}}]
|
||||||
(into (d/ordered-set)
|
(let [objects (lookup-page-objects state)
|
||||||
(filter is-present?)
|
selected (->> (get-in state [:workspace-local :selected])
|
||||||
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))))
|
||||||
|
|
|
@ -242,23 +242,24 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state stream]
|
(watch [it state stream]
|
||||||
(let [initial (deref ms/mouse-position)
|
(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)]
|
stopper (rx/filter ms/mouse-up? stream)]
|
||||||
(->> ms/mouse-position
|
(when-not (empty? selected)
|
||||||
(rx/take-until stopper)
|
(->> ms/mouse-position
|
||||||
(rx/map #(gpt/to-vec initial %))
|
(rx/take-until stopper)
|
||||||
(rx/map #(gpt/length %))
|
(rx/map #(gpt/to-vec initial %))
|
||||||
(rx/filter #(> % 1))
|
(rx/map #(gpt/length %))
|
||||||
(rx/take 1)
|
(rx/filter #(> % 1))
|
||||||
(rx/with-latest vector ms/mouse-position-alt)
|
(rx/take 1)
|
||||||
(rx/mapcat
|
(rx/with-latest vector ms/mouse-position-alt)
|
||||||
(fn [[_ alt?]]
|
(rx/mapcat
|
||||||
(if alt?
|
(fn [[_ alt?]]
|
||||||
;; When alt is down we start a duplicate+move
|
(if alt?
|
||||||
(rx/of (start-move-duplicate initial)
|
;; When alt is down we start a duplicate+move
|
||||||
dws/duplicate-selected)
|
(rx/of (start-move-duplicate initial)
|
||||||
;; Otherwise just plain old move
|
dws/duplicate-selected)
|
||||||
(rx/of (start-move initial selected))))))))))
|
;; Otherwise just plain old move
|
||||||
|
(rx/of (start-move initial selected)))))))))))
|
||||||
|
|
||||||
(defn start-move-duplicate [from-position]
|
(defn start-move-duplicate [from-position]
|
||||||
(ptk/reify ::start-move-selected
|
(ptk/reify ::start-move-selected
|
||||||
|
@ -319,7 +320,8 @@
|
||||||
(watch [it state stream]
|
(watch [it state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
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)
|
shapes (mapv #(get objects %) ids)
|
||||||
stopper (rx/filter ms/mouse-up? stream)
|
stopper (rx/filter ms/mouse-up? stream)
|
||||||
layout (get state :workspace-layout)
|
layout (get state :workspace-layout)
|
||||||
|
@ -398,7 +400,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state stream]
|
(watch [it state stream]
|
||||||
(if (= same-event (get-in state [:workspace-local :current-move-selected]))
|
(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
|
move-events (->> stream
|
||||||
(rx/filter (ptk/type? ::move-selected))
|
(rx/filter (ptk/type? ::move-selected))
|
||||||
(rx/filter #(= direction (deref %))))
|
(rx/filter #(= direction (deref %))))
|
||||||
|
@ -435,6 +437,8 @@
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
|
|
||||||
|
ids (->> ids (into #{} (remove #(get-in objects [% :blocked] false))))
|
||||||
|
|
||||||
not-frame-id?
|
not-frame-id?
|
||||||
(fn [shape-id]
|
(fn [shape-id]
|
||||||
(let [shape (get objects shape-id)]
|
(let [shape (get objects shape-id)]
|
||||||
|
@ -457,27 +461,28 @@
|
||||||
;; shape adjusting their position.
|
;; shape adjusting their position.
|
||||||
|
|
||||||
(defn set-rotation
|
(defn set-rotation
|
||||||
([delta-rotation shapes]
|
([angle shapes]
|
||||||
(set-rotation delta-rotation shapes (-> shapes gsh/selection-rect gsh/center-selrect)))
|
(set-rotation angle shapes (-> shapes gsh/selection-rect gsh/center-selrect)))
|
||||||
|
|
||||||
([delta-rotation shapes center]
|
([angle shapes center]
|
||||||
(letfn [(rotate-shape [objects angle shape center]
|
(ptk/reify ::set-rotation
|
||||||
(update-in objects [(:id shape) :modifiers] merge (gsh/rotation-modifiers center shape angle)))
|
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]
|
shapes (->> shapes (into [] (remove #(get % :blocked false))))
|
||||||
(reduce #(rotate-shape %1 angle %2 center) objects shapes))
|
|
||||||
|
|
||||||
(set-rotation [objects]
|
shapes (->> shapes (mapcat get-children) (concat shapes))
|
||||||
(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)))]
|
|
||||||
|
|
||||||
(ptk/reify ::set-rotation
|
update-shape
|
||||||
ptk/UpdateEvent
|
(fn [modifiers shape]
|
||||||
(update [_ state]
|
(let [rotate-modifiers (gsh/rotation-modifiers shape center angle)]
|
||||||
(let [page-id (:current-page-id state)]
|
(assoc-in modifiers [(:id shape) :modifiers] rotate-modifiers)))]
|
||||||
(d/update-in-when state [:workspace-data :pages-index page-id :objects] set-rotation)))))))
|
(-> state
|
||||||
|
(update :workspace-modifiers
|
||||||
|
#(reduce update-shape % shapes))))))))
|
||||||
|
|
||||||
(defn increase-rotation [ids rotation]
|
(defn increase-rotation [ids rotation]
|
||||||
(ptk/reify ::increase-rotation
|
(ptk/reify ::increase-rotation
|
||||||
|
@ -583,7 +588,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state stream]
|
(watch [it state stream]
|
||||||
(let [objects (wsh/lookup-page-objects state)
|
(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)
|
shapes (map #(get objects %) selected)
|
||||||
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
||||||
origin (gpt/point (:x selrect) (+ (:y selrect) (/ (:height selrect) 2)))]
|
origin (gpt/point (:x selrect) (+ (:y selrect) (/ (:height selrect) 2)))]
|
||||||
|
@ -600,7 +605,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state stream]
|
(watch [it state stream]
|
||||||
(let [objects (wsh/lookup-page-objects state)
|
(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)
|
shapes (map #(get objects %) selected)
|
||||||
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
|
||||||
origin (gpt/point (+ (:x selrect) (/ (:width selrect) 2)) (:y selrect))]
|
origin (gpt/point (+ (:x selrect) (/ (:width selrect) 2)) (:y selrect))]
|
||||||
|
@ -633,5 +638,5 @@
|
||||||
(ptk/reify ::selected-to-path
|
(ptk/reify ::selected-to-path
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(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))))))
|
(rx/of (dch/update-shapes ids ups/convert-to-path))))))
|
||||||
|
|
|
@ -150,10 +150,6 @@
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
(let [id (:id item)]
|
(let [id (:id item)]
|
||||||
(cond
|
(cond
|
||||||
(or (:blocked item)
|
|
||||||
(:hidden item))
|
|
||||||
nil
|
|
||||||
|
|
||||||
(kbd/shift? event)
|
(kbd/shift? event)
|
||||||
(st/emit! (dw/shift-select-shapes id))
|
(st/emit! (dw/shift-select-shapes id))
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@
|
||||||
#(rx/dispose! sub))))
|
#(rx/dispose! sub))))
|
||||||
|
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
(mf/deps shapes modifiers)
|
(mf/deps shapes filter-shapes modifiers)
|
||||||
(fn []
|
(fn []
|
||||||
(rx/push! subject props)))
|
(rx/push! subject props)))
|
||||||
|
|
||||||
|
@ -161,7 +161,8 @@
|
||||||
(map #(get objects %))
|
(map #(get objects %))
|
||||||
(filterv (comp not nil?)))
|
(filterv (comp not nil?)))
|
||||||
filter-shapes (into #{}
|
filter-shapes (into #{}
|
||||||
(mapcat #(cp/get-object-with-children % objects))
|
(comp (mapcat #(cp/get-object-with-children % objects))
|
||||||
|
(map :id))
|
||||||
selected)
|
selected)
|
||||||
|
|
||||||
filter-shapes (fn [id]
|
filter-shapes (fn [id]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue