mirror of
https://github.com/penpot/penpot.git
synced 2025-06-02 11:31:39 +02:00
♻️ Refactor some page helpers usage
This commit is contained in:
parent
d270c9670e
commit
74c6556ad6
5 changed files with 26 additions and 28 deletions
|
@ -23,19 +23,13 @@
|
||||||
(and (= type :frame) (= id uuid/zero)))
|
(and (= type :frame) (= id uuid/zero)))
|
||||||
|
|
||||||
(defn root-frame?
|
(defn root-frame?
|
||||||
([objects id]
|
[{:keys [frame-id type]}]
|
||||||
(root-frame? (get objects id)))
|
(and (= type :frame)
|
||||||
|
(= frame-id uuid/zero)))
|
||||||
([{:keys [frame-id type]}]
|
|
||||||
(and (= type :frame)
|
|
||||||
(= frame-id uuid/zero))))
|
|
||||||
|
|
||||||
(defn frame-shape?
|
(defn frame-shape?
|
||||||
([objects id]
|
[{:keys [type]}]
|
||||||
(frame-shape? (get objects id)))
|
(= type :frame))
|
||||||
|
|
||||||
([{:keys [type]}]
|
|
||||||
(= type :frame)))
|
|
||||||
|
|
||||||
(defn group-shape?
|
(defn group-shape?
|
||||||
[{:keys [type]}]
|
[{:keys [type]}]
|
||||||
|
|
|
@ -161,13 +161,15 @@
|
||||||
(cond
|
(cond
|
||||||
(= base base-shape-id)
|
(= base base-shape-id)
|
||||||
(and (not top-frames?)
|
(and (not top-frames?)
|
||||||
(cph/frame-shape? objects base-shape-id)
|
(let [object (get objects base-shape-id)]
|
||||||
(cph/root-frame? objects base-shape-id))
|
(or (cph/frame-shape? object)
|
||||||
|
(cph/root-frame? object))))
|
||||||
|
|
||||||
(= base over-shape-id)
|
(= base over-shape-id)
|
||||||
(or top-frames?
|
(or top-frames?
|
||||||
(not (cph/frame-shape? objects over-shape-id))
|
(let [object (get objects over-shape-id)]
|
||||||
(not (cph/root-frame? objects over-shape-id)))
|
(or (not (cph/frame-shape? object))
|
||||||
|
(not (cph/root-frame? object)))))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(< index-a index-b))))
|
(< index-a index-b))))
|
||||||
|
|
|
@ -745,24 +745,25 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [position @ms/mouse-position
|
(let [position @ms/mouse-position
|
||||||
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)
|
||||||
frame-id (ctt/frame-id-by-position objects position)
|
frame-id (ctt/frame-id-by-position objects position)
|
||||||
|
lookup (d/getf objects)
|
||||||
|
|
||||||
moving-shapes
|
moving-shapes
|
||||||
(->> ids
|
(->> ids
|
||||||
(cph/clean-loops objects)
|
(cph/clean-loops objects)
|
||||||
(keep #(get objects %))
|
(keep (d/getf objects))
|
||||||
(remove #(= (:frame-id %) frame-id)))
|
(remove #(= (:frame-id %) frame-id)))
|
||||||
|
|
||||||
moving-frames
|
moving-frames
|
||||||
(->> ids
|
(filter #(cph/frame-shape? (lookup %)) ids)
|
||||||
(filter #(cph/frame-shape? objects %)))
|
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it page-id)
|
changes
|
||||||
(pcb/with-objects objects)
|
(-> (pcb/empty-changes it page-id)
|
||||||
(pcb/update-shapes moving-frames (fn [shape] (assoc shape :hide-in-viewer true)))
|
(pcb/with-objects objects)
|
||||||
(pcb/change-parent frame-id moving-shapes))]
|
(pcb/update-shapes moving-frames (fn [shape] (assoc shape :hide-in-viewer true)))
|
||||||
|
(pcb/change-parent frame-id moving-shapes))]
|
||||||
|
|
||||||
(when-not (empty? changes)
|
(when-not (empty? changes)
|
||||||
(rx/of (dch/commit-changes changes)
|
(rx/of (dch/commit-changes changes)
|
||||||
|
|
|
@ -145,7 +145,7 @@
|
||||||
on-pointer-move (actions/on-pointer-move viewport-ref zoom move-stream)
|
on-pointer-move (actions/on-pointer-move viewport-ref zoom move-stream)
|
||||||
on-pointer-up (actions/on-pointer-up)
|
on-pointer-up (actions/on-pointer-up)
|
||||||
on-move-selected (actions/on-move-selected hover hover-ids selected space?)
|
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-enter (actions/on-frame-enter frame-hover)
|
||||||
on-frame-leave (actions/on-frame-leave frame-hover)
|
on-frame-leave (actions/on-frame-leave frame-hover)
|
||||||
|
@ -277,7 +277,7 @@
|
||||||
[:& outline/shape-outlines
|
[:& outline/shape-outlines
|
||||||
{:objects base-objects
|
{:objects base-objects
|
||||||
:hover #{(->> @hover-ids
|
:hover #{(->> @hover-ids
|
||||||
(filter #(cph/frame-shape? base-objects %))
|
(filter #(cph/frame-shape? (get base-objects %)))
|
||||||
(remove selected)
|
(remove selected)
|
||||||
(first))}
|
(first))}
|
||||||
:zoom zoom}])
|
:zoom zoom}])
|
||||||
|
|
|
@ -188,11 +188,12 @@
|
||||||
|
|
||||||
grouped? (fn [id] (contains? #{:group :bool} (get-in objects [id :type])))
|
grouped? (fn [id] (contains? #{:group :bool} (get-in objects [id :type])))
|
||||||
|
|
||||||
|
|
||||||
selected-with-parents
|
selected-with-parents
|
||||||
(into #{} (mapcat #(cph/get-parent-ids objects %)) selected)
|
(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
|
;; Set with the elements to remove from the hover list
|
||||||
remove-id?
|
remove-id?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue