mirror of
https://github.com/penpot/penpot.git
synced 2026-10-03 09:16:15 +00:00
⚡ Reduce per-frame CLJS work while dragging (#12027)
Memoize snap points and frame titles on the base objects and compute the drag target frames once per gesture.
This commit is contained in:
parent
822dbd6517
commit
da55d6723c
@ -839,8 +839,9 @@
|
|||||||
|
|
||||||
exclude-frames
|
exclude-frames
|
||||||
(into #{}
|
(into #{}
|
||||||
(filter (partial cfh/frame-shape? objects))
|
(comp (mapcat #(cfh/get-children-ids-with-self objects %))
|
||||||
(cfh/selected-with-children objects selected))
|
(filter (partial cfh/frame-shape? objects)))
|
||||||
|
selected)
|
||||||
|
|
||||||
exclude-frames-siblings
|
exclude-frames-siblings
|
||||||
(into exclude-frames
|
(into exclude-frames
|
||||||
@ -848,6 +849,21 @@
|
|||||||
(filter (partial ctl/any-layout-immediate-child-id? objects)))
|
(filter (partial ctl/any-layout-immediate-child-id? objects)))
|
||||||
selected)
|
selected)
|
||||||
|
|
||||||
|
;; Frame lookups per pointer move only test frames that can be a target
|
||||||
|
frames
|
||||||
|
(ctst/get-frames objects)
|
||||||
|
|
||||||
|
with-target-frames
|
||||||
|
(fn [excluded]
|
||||||
|
(vary-meta objects assoc ::ctst/index-frames
|
||||||
|
(into [] (remove #(contains? excluded (:id %))) frames)))
|
||||||
|
|
||||||
|
target-objects
|
||||||
|
(with-target-frames exclude-frames)
|
||||||
|
|
||||||
|
target-objects-siblings
|
||||||
|
(with-target-frames exclude-frames-siblings)
|
||||||
|
|
||||||
position (->> ms/mouse-position
|
position (->> ms/mouse-position
|
||||||
(rx/map #(gpt/to-vec from-position %)))
|
(rx/map #(gpt/to-vec from-position %)))
|
||||||
|
|
||||||
@ -891,8 +907,9 @@
|
|||||||
(rx/map
|
(rx/map
|
||||||
(fn [[move-vector mod?]]
|
(fn [[move-vector mod?]]
|
||||||
(let [position (gpt/add from-position move-vector)
|
(let [position (gpt/add from-position move-vector)
|
||||||
exclude-frames (if mod? exclude-frames exclude-frames-siblings)
|
target-frame (if mod?
|
||||||
target-frame (ctst/top-nested-frame objects position exclude-frames)
|
(ctst/top-nested-frame target-objects position)
|
||||||
|
(ctst/top-nested-frame target-objects-siblings position))
|
||||||
[target-frame _] (ctn/find-valid-parent-and-frame-ids target-frame objects shapes false libraries parent-validation-cache)
|
[target-frame _] (ctn/find-valid-parent-and-frame-ids target-frame objects shapes false libraries parent-validation-cache)
|
||||||
flex-layout? (ctl/flex-layout? objects target-frame)
|
flex-layout? (ctl/flex-layout? objects target-frame)
|
||||||
grid-layout? (ctl/grid-layout? objects target-frame)
|
grid-layout? (ctl/grid-layout? objects target-frame)
|
||||||
|
|||||||
@ -592,6 +592,7 @@
|
|||||||
|
|
||||||
[:> widgets/frame-titles*
|
[:> widgets/frame-titles*
|
||||||
{:objects base-objects
|
{:objects base-objects
|
||||||
|
:base-objects base-objects
|
||||||
:selected selected
|
:selected selected
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:is-show-artboard-names show-artboard-names?
|
:is-show-artboard-names show-artboard-names?
|
||||||
@ -637,6 +638,7 @@
|
|||||||
:page-id page-id
|
:page-id page-id
|
||||||
:selected selected
|
:selected selected
|
||||||
:objects objects-modified
|
:objects objects-modified
|
||||||
|
:base-objects base-objects
|
||||||
:focus focus}])
|
:focus focus}])
|
||||||
|
|
||||||
(when show-snap-distance?
|
(when show-snap-distance?
|
||||||
|
|||||||
@ -158,12 +158,13 @@
|
|||||||
|
|
||||||
(mf/defc snap-points*
|
(mf/defc snap-points*
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [layout zoom objects selected page-id drawing focus]}]
|
[{:keys [layout zoom objects base-objects selected page-id drawing focus]}]
|
||||||
(dm/assert! (set? selected))
|
(dm/assert! (set? selected))
|
||||||
(let [shapes (into [] (keep (d/getf objects)) selected)
|
(let [shapes (into [] (keep (d/getf objects)) selected)
|
||||||
|
|
||||||
filter-shapes
|
filter-shapes
|
||||||
(into selected (mapcat #(cfh/get-children-ids objects %)) selected)
|
(mf/with-memo [base-objects selected]
|
||||||
|
(into #{} (mapcat #(cfh/get-children-ids-with-self base-objects %)) selected))
|
||||||
|
|
||||||
remove-snap-base?
|
remove-snap-base?
|
||||||
(mf/with-memo [layout filter-shapes objects focus]
|
(mf/with-memo [layout filter-shapes objects focus]
|
||||||
|
|||||||
@ -259,10 +259,12 @@
|
|||||||
|
|
||||||
(mf/defc frame-titles*
|
(mf/defc frame-titles*
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [objects zoom selected focus is-show-artboard-names
|
[{:keys [objects base-objects zoom selected focus is-show-artboard-names
|
||||||
on-frame-enter on-frame-leave on-frame-select]}]
|
on-frame-enter on-frame-leave on-frame-select]}]
|
||||||
(let [selected (or selected #{})
|
(let [selected (or selected #{})
|
||||||
shapes (ctt/get-frames objects {:skip-copies? true :ignore-index? true})
|
frame-ids (mf/with-memo [base-objects]
|
||||||
|
(vec (ctt/get-frames-ids base-objects {:skip-copies? true :ignore-index? true})))
|
||||||
|
shapes (into [] (keep (d/getf objects)) frame-ids)
|
||||||
shapes (if (dbg/enabled? :shape-titles)
|
shapes (if (dbg/enabled? :shape-titles)
|
||||||
(into (set shapes)
|
(into (set shapes)
|
||||||
(map (d/getf objects))
|
(map (d/getf objects))
|
||||||
|
|||||||
@ -870,6 +870,7 @@
|
|||||||
(when-not shapes-loading?
|
(when-not shapes-loading?
|
||||||
[:> widgets/frame-titles*
|
[:> widgets/frame-titles*
|
||||||
{:objects objects-modified
|
{:objects objects-modified
|
||||||
|
:base-objects base-objects
|
||||||
:selected selected
|
:selected selected
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:is-show-artboard-names show-artboard-names?
|
:is-show-artboard-names show-artboard-names?
|
||||||
@ -918,6 +919,7 @@
|
|||||||
:page-id page-id
|
:page-id page-id
|
||||||
:selected selected
|
:selected selected
|
||||||
:objects objects-modified
|
:objects objects-modified
|
||||||
|
:base-objects base-objects
|
||||||
:focus focus}])
|
:focus focus}])
|
||||||
|
|
||||||
(when show-snap-distance?
|
(when show-snap-distance?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user