0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 12:59:12 -05:00

Add correct impl for is-direct-child-of-root? helper

And we restore the previously removed helper and incorrectly replaced by
the `is-direct-child-of-root?`.

In penpot exists two concepts: root and root-frame; root is the
artificially created shape that represents the ROOT, and root-frame
means a frame that is shape of frame type which is a direct children
of ROOT.
This commit is contained in:
Andrey Antukh 2023-08-28 16:08:37 +02:00
parent 1a1e55037b
commit c6e248b52f
7 changed files with 23 additions and 17 deletions

View file

@ -29,6 +29,12 @@
(defn is-direct-child-of-root?
([objects id]
(is-direct-child-of-root? (get objects id)))
([shape]
(and (some? shape) (= (dm/get-prop shape :frame-id) uuid/zero))))
(defn root-frame?
([objects id]
(root-frame? (get objects id)))
([shape]
(and (some? shape)
(= (dm/get-prop shape :type) :frame)
@ -229,7 +235,7 @@
(or (root? frame) (nil? frame))
nil
(is-direct-child-of-root? frame)
(root-frame? frame)
frame
:else
@ -614,7 +620,7 @@
(->> (get-parent-ids objects shape-id)
(cons shape-id)
(map (d/getf objects))
(d/seek is-direct-child-of-root?)
(d/seek root-frame?)
:id))
(defn comparator-layout-z-index

View file

@ -34,7 +34,7 @@
[shape hover?]
(fn [event]
(when-not (or (cph/group-shape? shape)
(cph/is-direct-child-of-root? shape))
(cph/root-frame? shape))
(dom/prevent-default event)
(dom/stop-propagation event)
(st/emit! (dv/hover-shape (:id shape) hover?)))))
@ -42,7 +42,7 @@
(defn select-shape [shape]
(fn [event]
(when-not (or (cph/group-shape? shape)
(cph/is-direct-child-of-root? shape))
(cph/root-frame? shape))
(dom/stop-propagation event)
(dom/prevent-default event)
(cond

View file

@ -90,7 +90,7 @@
;; FIXME: WARN: this breaks react rule of hooks (hooks can't be under conditional)
active-frames
(when (cph/is-direct-child-of-root? shape)
(when (cph/root-frame? shape)
(mf/use-ctx ctx/active-frames))
thumbnail?
@ -125,4 +125,3 @@
(def bool-wrapper (bool/bool-wrapper-factory shape-wrapper))
(def root-frame-wrapper (frame/root-frame-wrapper-factory shape-wrapper))
(def nested-frame-wrapper (frame/nested-frame-wrapper-factory shape-wrapper))

View file

@ -141,7 +141,7 @@
(fn []
(let [parent-id
(->> @hover-ids
(d/seek (partial cph/is-direct-child-of-root? base-objects)))]
(d/seek (partial cph/root-frame? base-objects)))]
(when (some? parent-id)
(get base-objects parent-id)))))
@ -244,7 +244,7 @@
first-selected-shape (first selected-shapes)
selecting-first-level-frame? (and one-selected-shape?
(cph/is-direct-child-of-root? first-selected-shape))
(cph/root-frame? first-selected-shape))
offset-x (if selecting-first-level-frame?
(:x first-selected-shape)

View file

@ -293,7 +293,7 @@
(not (is-guide-inside-frame? (assoc guide :position pos) frame)))]
(when (or (nil? frame)
(and (cph/is-direct-child-of-root? frame)
(and (cph/root-frame? frame)
(not (ctst/rotated-frame? frame))))
[:g.guide-area {:opacity (when frame-guide-outside? 0)}
(when-not disabled-guides?

View file

@ -217,7 +217,7 @@
root-frame-with-data?
#(as-> (get objects %) obj
(and (cph/is-direct-child-of-root? obj)
(and (cph/root-frame? obj)
(d/not-empty? (:shapes obj))
(not (ctk/instance-head? obj))
(not (ctk/main-instance? obj))))
@ -240,9 +240,10 @@
no-fill-nested-frames?
(fn [id]
(and (cph/frame-shape? objects id)
(not (cph/is-direct-child-of-root? objects id))
(empty? (dm/get-in objects [id :fills]))))
(let [shape (get objects id)]
(and (cph/frame-shape? shape)
(not (cph/is-direct-child-of-root? shape))
(empty? (get shape :fills)))))
hover-shape
(->> ids
@ -276,7 +277,7 @@
(let [all-frames (mf/use-memo (mf/deps objects) #(ctt/get-root-frames-ids objects))
selected-frames (mf/use-memo (mf/deps selected) #(->> all-frames (filter selected)))
xf-selected-frame (comp (remove cph/is-direct-child-of-root?)
xf-selected-frame (comp (remove cph/root-frame?)
(map #(cph/get-shape-id-root-frame objects %)))
selected-shapes-frames (mf/use-memo (mf/deps selected) #(into #{} xf-selected-frame selected))

View file

@ -30,7 +30,7 @@
(not (ctl/layout-absolute? shape))
(or (cph/group-shape? shape)
(cph/frame-shape? shape)))
(cph/is-direct-child-of-root? shape))
(cph/root-frame? shape))
:relative
(and (ctl/any-layout-immediate-child? objects shape)
@ -54,14 +54,14 @@
;;shape (gsh/transform-shape)
shape-value (get selrect coord)
]
(when (and (not (cph/is-direct-child-of-root? shape))
(when (and (not (cph/root-frame? shape))
(or (not (ctl/any-layout-immediate-child? objects shape))
(ctl/layout-absolute? shape)))
(- shape-value parent-value))))
#_(defn get-shape-position
[shape objects coord]
(when-not (or (cph/is-direct-child-of-root? shape)
(when-not (or (cph/root-frame? shape)
(and (ctl/any-layout-immediate-child? objects shape)
(not (ctl/layout-absolute? shape))))
(let [parent (get objects (:parent-id shape))