0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 16:21:57 -05:00

♻️ Refactor some page helpers usage

This commit is contained in:
Andrey Antukh 2022-08-01 16:29:21 +02:00
parent d270c9670e
commit 74c6556ad6
5 changed files with 26 additions and 28 deletions

View file

@ -23,19 +23,13 @@
(and (= type :frame) (= id uuid/zero)))
(defn root-frame?
([objects id]
(root-frame? (get objects id)))
([{:keys [frame-id type]}]
(and (= type :frame)
(= frame-id uuid/zero))))
[{:keys [frame-id type]}]
(and (= type :frame)
(= frame-id uuid/zero)))
(defn frame-shape?
([objects id]
(frame-shape? (get objects id)))
([{:keys [type]}]
(= type :frame)))
[{:keys [type]}]
(= type :frame))
(defn group-shape?
[{:keys [type]}]

View file

@ -161,13 +161,15 @@
(cond
(= base base-shape-id)
(and (not top-frames?)
(cph/frame-shape? objects base-shape-id)
(cph/root-frame? objects base-shape-id))
(let [object (get objects base-shape-id)]
(or (cph/frame-shape? object)
(cph/root-frame? object))))
(= base over-shape-id)
(or top-frames?
(not (cph/frame-shape? objects over-shape-id))
(not (cph/root-frame? objects over-shape-id)))
(let [object (get objects over-shape-id)]
(or (not (cph/frame-shape? object))
(not (cph/root-frame? object)))))
:else
(< index-a index-b))))

View file

@ -745,24 +745,25 @@
ptk/WatchEvent
(watch [it state _]
(let [position @ms/mouse-position
page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
frame-id (ctt/frame-id-by-position objects position)
lookup (d/getf objects)
moving-shapes
(->> ids
(cph/clean-loops objects)
(keep #(get objects %))
(keep (d/getf objects))
(remove #(= (:frame-id %) frame-id)))
moving-frames
(->> ids
(filter #(cph/frame-shape? objects %)))
(filter #(cph/frame-shape? (lookup %)) ids)
changes (-> (pcb/empty-changes it page-id)
(pcb/with-objects objects)
(pcb/update-shapes moving-frames (fn [shape] (assoc shape :hide-in-viewer true)))
(pcb/change-parent frame-id moving-shapes))]
changes
(-> (pcb/empty-changes it page-id)
(pcb/with-objects objects)
(pcb/update-shapes moving-frames (fn [shape] (assoc shape :hide-in-viewer true)))
(pcb/change-parent frame-id moving-shapes))]
(when-not (empty? changes)
(rx/of (dch/commit-changes changes)

View file

@ -145,7 +145,7 @@
on-pointer-move (actions/on-pointer-move viewport-ref zoom move-stream)
on-pointer-up (actions/on-pointer-up)
on-move-selected (actions/on-move-selected hover hover-ids selected space?)
on-menu-selected (actions/on-menu-selected hover hover-ids selected)
on-menu-selected (actions/on-menu-selected hover hover-ids selected)
on-frame-enter (actions/on-frame-enter frame-hover)
on-frame-leave (actions/on-frame-leave frame-hover)
@ -277,7 +277,7 @@
[:& outline/shape-outlines
{:objects base-objects
:hover #{(->> @hover-ids
(filter #(cph/frame-shape? base-objects %))
(filter #(cph/frame-shape? (get base-objects %)))
(remove selected)
(first))}
:zoom zoom}])

View file

@ -188,11 +188,12 @@
grouped? (fn [id] (contains? #{:group :bool} (get-in objects [id :type])))
selected-with-parents
(into #{} (mapcat #(cph/get-parent-ids objects %)) selected)
root-frame-with-data? #(and (cph/root-frame? objects %) (d/not-empty? (get-in objects [% :shapes])))
root-frame-with-data?
#(as-> (get objects %) obj
(and (cph/root-frame? obj) (d/not-empty? (:shapes obj))))
;; Set with the elements to remove from the hover list
remove-id?