mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 12:59:12 -05:00
💄 Add mainly cosmetic improvements to delete-shapes event impl
This commit is contained in:
parent
07eab923f0
commit
8fd908a59f
1 changed files with 30 additions and 32 deletions
|
@ -7,6 +7,7 @@
|
||||||
(ns app.main.data.workspace.shapes
|
(ns app.main.data.workspace.shapes
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.proportions :as gpr]
|
[app.common.geom.proportions :as gpr]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.pages.changes-builder :as pcb]
|
[app.common.pages.changes-builder :as pcb]
|
||||||
|
@ -140,14 +141,15 @@
|
||||||
page (wsh/lookup-page state page-id)
|
page (wsh/lookup-page state page-id)
|
||||||
|
|
||||||
ids (cph/clean-loops objects ids)
|
ids (cph/clean-loops objects ids)
|
||||||
|
lookup (d/getf objects)
|
||||||
|
|
||||||
groups-to-unmask
|
groups-to-unmask
|
||||||
(reduce (fn [group-ids id]
|
(reduce (fn [group-ids id]
|
||||||
;; When the shape to delete is the mask of a masked group,
|
;; When the shape to delete is the mask of a masked group,
|
||||||
;; the mask condition must be removed, and it must be
|
;; the mask condition must be removed, and it must be
|
||||||
;; converted to a normal group.
|
;; converted to a normal group.
|
||||||
(let [obj (get objects id)
|
(let [obj (lookup id)
|
||||||
parent (get objects (:parent-id obj))]
|
parent (lookup (:parent-id obj))]
|
||||||
(if (and (:masked-group? parent)
|
(if (and (:masked-group? parent)
|
||||||
(= id (first (:shapes parent))))
|
(= id (first (:shapes parent))))
|
||||||
(conj group-ids (:id parent))
|
(conj group-ids (:id parent))
|
||||||
|
@ -166,9 +168,11 @@
|
||||||
(vals objects))
|
(vals objects))
|
||||||
|
|
||||||
;; If any of the deleted shapes is a frame with guides
|
;; If any of the deleted shapes is a frame with guides
|
||||||
guides (into {} (map (juxt :id identity) (->> (get-in page [:options :guides])
|
guides (into {}
|
||||||
(vals)
|
(comp (map second)
|
||||||
(filter #(not (contains? ids (:frame-id %)))))))
|
(remove #(contains? ids (:frame-id %)))
|
||||||
|
(map (juxt :id identity)))
|
||||||
|
(dm/get-in page [:options :guides]))
|
||||||
|
|
||||||
starting-flows
|
starting-flows
|
||||||
(filter (fn [flow]
|
(filter (fn [flow]
|
||||||
|
@ -192,22 +196,18 @@
|
||||||
(reverse)
|
(reverse)
|
||||||
(into (d/ordered-set)))
|
(into (d/ordered-set)))
|
||||||
|
|
||||||
find-all-empty-parents (fn recursive-find-empty-parents [empty-parents]
|
find-all-empty-parents
|
||||||
(let [all-ids (into empty-parents ids)
|
(fn recursive-find-empty-parents [empty-parents]
|
||||||
empty-parents-xform
|
(let [all-ids (into empty-parents ids)
|
||||||
(comp
|
contains? (partial contains? all-ids)
|
||||||
(map (fn [id] (get objects id)))
|
xform (comp (map lookup)
|
||||||
(map (fn [{:keys [shapes type] :as obj}]
|
(filter cph/group-shape?)
|
||||||
(when (and (= :group type)
|
(remove #(->> (:shapes %) (remove contains?) seq))
|
||||||
(zero? (count (remove #(contains? all-ids %) shapes))))
|
(map :id))
|
||||||
obj)))
|
parents (into #{} xform all-parents)]
|
||||||
(take-while some?)
|
(if (= empty-parents parents)
|
||||||
(map :id))
|
empty-parents
|
||||||
calculated-empty-parents (into #{} empty-parents-xform all-parents)]
|
(recursive-find-empty-parents parents))))
|
||||||
|
|
||||||
(if (= empty-parents calculated-empty-parents)
|
|
||||||
empty-parents
|
|
||||||
(recursive-find-empty-parents calculated-empty-parents))))
|
|
||||||
|
|
||||||
empty-parents
|
empty-parents
|
||||||
;; Any parent whose children are all deleted, must be deleted too.
|
;; Any parent whose children are all deleted, must be deleted too.
|
||||||
|
@ -226,18 +226,16 @@
|
||||||
(assoc shape :masked-group? false)))
|
(assoc shape :masked-group? false)))
|
||||||
(pcb/update-shapes (map :id interacting-shapes)
|
(pcb/update-shapes (map :id interacting-shapes)
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(update shape :interactions
|
(d/update-when shape :interactions
|
||||||
(fn [interactions]
|
(fn [interactions]
|
||||||
(when interactions
|
(into []
|
||||||
(d/removev #(and (csi/has-destination %)
|
(remove #(and (csi/has-destination %)
|
||||||
(contains? ids (:destination %)))
|
(contains? ids (:destination %))))
|
||||||
interactions))))))
|
interactions)))))
|
||||||
(cond->
|
(cond-> (seq starting-flows)
|
||||||
(seq starting-flows)
|
|
||||||
(pcb/update-page-option :flows (fn [flows]
|
(pcb/update-page-option :flows (fn [flows]
|
||||||
(reduce #(csp/remove-flow %1 (:id %2))
|
(->> (map :id starting-flows)
|
||||||
flows
|
(reduce csp/remove-flow flows))))))]
|
||||||
starting-flows)))))]
|
|
||||||
|
|
||||||
(rx/of (dch/commit-changes changes))))))
|
(rx/of (dch/commit-changes changes))))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue