mirror of
https://github.com/penpot/penpot.git
synced 2025-02-23 07:16:07 -05:00
🐛 Add function to reparent orphan shapes
This commit is contained in:
parent
83c8e7f03a
commit
4fc3f316e0
3 changed files with 35 additions and 4 deletions
|
@ -696,7 +696,7 @@
|
|||
(pcb/resize-parents parents))))
|
||||
|
||||
(defn relocate-shapes
|
||||
[ids parent-id to-index]
|
||||
[ids parent-id to-index & [ignore-parents?]]
|
||||
(us/verify (s/coll-of ::us/uuid) ids)
|
||||
(us/verify ::us/uuid parent-id)
|
||||
(us/verify number? to-index)
|
||||
|
@ -712,7 +712,9 @@
|
|||
|
||||
;; If we try to move a parent into a child we remove it
|
||||
ids (filter #(not (cph/is-parent? objects parent-id %)) ids)
|
||||
parents (into #{parent-id} (map #(cph/get-parent-id objects %)) ids)
|
||||
parents (if ignore-parents?
|
||||
#{parent-id}
|
||||
(into #{parent-id} (map #(cph/get-parent-id objects %)) ids))
|
||||
|
||||
groups-to-delete
|
||||
(loop [current-id (first parents)
|
||||
|
@ -1832,6 +1834,21 @@
|
|||
(rx/empty)))))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Orphan Shapes
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
(defn fix-orphan-shapes
|
||||
[]
|
||||
(ptk/reify ::fix-orphan-shapes
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [orphans (set (into [] (keys (wsh/find-orphan-shapes state))))]
|
||||
(rx/of (relocate-shapes orphans uuid/zero 0 true))))))
|
||||
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Inspect
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.path.commands :as upc]))
|
||||
[app.common.path.commands :as upc]
|
||||
[app.common.uuid :as uuid]))
|
||||
|
||||
(defn lookup-page
|
||||
([state]
|
||||
|
@ -146,4 +147,14 @@
|
|||
(let [{:keys [x y width height]} (get-in state [:workspace-local :vbox])]
|
||||
(gpt/point (+ x (/ width 2)) (+ y (/ height 2)))))
|
||||
|
||||
|
||||
(defn find-orphan-shapes
|
||||
([state]
|
||||
(find-orphan-shapes state (:current-page-id state)))
|
||||
([state page-id]
|
||||
(let [objects (lookup-page-objects state page-id)
|
||||
objects (filter (fn [item]
|
||||
(and
|
||||
(not= (key item) uuid/zero)
|
||||
(not (contains? objects (:parent-id (val item))))))
|
||||
objects)]
|
||||
objects)))
|
||||
|
|
|
@ -346,3 +346,6 @@
|
|||
[read-only?]
|
||||
(st/emit! (dw/set-workspace-read-only read-only?)))
|
||||
|
||||
(defn ^:export fix-orphan-shapes
|
||||
[]
|
||||
(st/emit! (dw/fix-orphan-shapes)))
|
||||
|
|
Loading…
Add table
Reference in a new issue