mirror of
https://github.com/penpot/penpot.git
synced 2025-07-16 13:45:17 +02:00
⚡ Improved set-modifiers-recursive and some utils memoization
This commit is contained in:
parent
9024408ed2
commit
9d66984c62
8 changed files with 70 additions and 63 deletions
|
@ -107,7 +107,6 @@
|
|||
;; geometric attributes of the shapes.
|
||||
|
||||
(declare set-modifiers-recursive)
|
||||
(declare check-delta)
|
||||
(declare set-local-displacement)
|
||||
(declare clear-local-transform)
|
||||
|
||||
|
@ -195,39 +194,6 @@
|
|||
(clear-local-transform)
|
||||
(dwu/commit-undo-transaction))))))
|
||||
|
||||
(defn- set-modifiers-recursive
|
||||
[modif-tree objects shape modifiers root transformed-root ignore-constraints]
|
||||
(let [children (->> (get shape :shapes [])
|
||||
(map #(get objects %)))
|
||||
|
||||
transformed-shape (gsh/transform-shape (assoc shape :modifiers modifiers))
|
||||
|
||||
[root transformed-root ignore-geometry?]
|
||||
(check-delta shape root transformed-shape transformed-root objects)
|
||||
|
||||
modifiers (assoc modifiers :ignore-geometry? ignore-geometry?)
|
||||
|
||||
transformed-rect (gsh/calc-transformed-parent-rect shape modifiers)
|
||||
|
||||
set-child
|
||||
(fn [modif-tree child]
|
||||
(let [child-modifiers
|
||||
(gsh/calc-child-modifiers shape child modifiers ignore-constraints transformed-rect)]
|
||||
|
||||
(set-modifiers-recursive modif-tree
|
||||
objects
|
||||
child
|
||||
child-modifiers
|
||||
root
|
||||
transformed-root
|
||||
ignore-constraints)))
|
||||
|
||||
modif-tree
|
||||
(-> modif-tree
|
||||
(assoc-in [(:id shape) :modifiers] modifiers))]
|
||||
|
||||
(reduce set-child modif-tree children)))
|
||||
|
||||
(defn- check-delta
|
||||
"If the shape is a component instance, check its relative position respect the
|
||||
root of the component, and see if it changes after applying a transformation."
|
||||
|
@ -262,6 +228,35 @@
|
|||
|
||||
[root transformed-root ignore-geometry?]))
|
||||
|
||||
(defn- set-modifiers-recursive
|
||||
[modif-tree objects shape modifiers root transformed-root ignore-constraints]
|
||||
(let [children (map (d/getf objects) (:shapes shape))
|
||||
|
||||
transformed-shape (gsh/transform-shape (assoc shape :modifiers modifiers))
|
||||
|
||||
[root transformed-root ignore-geometry?]
|
||||
(check-delta shape root transformed-shape transformed-root objects)
|
||||
|
||||
modifiers (assoc modifiers :ignore-geometry? ignore-geometry?)
|
||||
|
||||
transformed-rect (gsh/calc-transformed-parent-rect shape modifiers)
|
||||
|
||||
set-child
|
||||
(fn [modif-tree child]
|
||||
(let [child-modifiers
|
||||
(gsh/calc-child-modifiers shape child modifiers ignore-constraints transformed-rect)]
|
||||
|
||||
(cond-> modif-tree
|
||||
(not (empty? (d/without-keys child-modifiers [:ignore-geometry?])))
|
||||
(set-modifiers-new*
|
||||
objects child child-modifiers root transformed-root ignore-constraints))))
|
||||
|
||||
modif-tree
|
||||
(-> modif-tree
|
||||
(assoc-in [(:id shape) :modifiers] modifiers))]
|
||||
|
||||
(reduce set-child modif-tree children)))
|
||||
|
||||
(defn- set-local-displacement [point]
|
||||
(ptk/reify ::start-local-displacement
|
||||
ptk/UpdateEvent
|
||||
|
|
|
@ -245,7 +245,7 @@
|
|||
objects (cond-> objects
|
||||
with-modifiers?
|
||||
(gsh/merge-modifiers modifiers))
|
||||
xform (comp (map #(get objects %))
|
||||
xform (comp (map (d/getf objects))
|
||||
(remove nil?))]
|
||||
(into [] xform ids)))]
|
||||
(l/derived selector st/state =))))
|
||||
|
@ -300,19 +300,10 @@
|
|||
|
||||
(def selected-shapes-with-children
|
||||
(letfn [(selector [{:keys [selected objects]}]
|
||||
(let [children (->> selected
|
||||
(mapcat #(cp/get-children % objects))
|
||||
(filterv (comp not nil?)))]
|
||||
(into selected children)))]
|
||||
(l/derived selector selected-data =)))
|
||||
|
||||
(def selected-objects-with-children
|
||||
(letfn [(selector [{:keys [selected objects]}]
|
||||
(let [children (->> selected
|
||||
(mapcat #(cp/get-children % objects))
|
||||
(filterv (comp not nil?)))
|
||||
shapes (into selected children)]
|
||||
(mapv #(get objects %) shapes)))]
|
||||
(let [xform (comp (remove nil?)
|
||||
(mapcat #(cp/get-children % objects)))
|
||||
shapes (into selected xform selected)]
|
||||
(mapv (d/getf objects) shapes)))]
|
||||
(l/derived selector selected-data =)))
|
||||
|
||||
;; ---- Viewer refs
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
page-id (mf/use-ctx ctx/current-page-id)
|
||||
file-id (mf/use-ctx ctx/current-file-id)
|
||||
shapes (mf/deref refs/selected-objects)
|
||||
shapes-with-children (mf/deref refs/selected-objects-with-children)]
|
||||
shapes-with-children (mf/deref refs/selected-shapes-with-children)]
|
||||
[:& options-content {:shapes shapes
|
||||
:selected selected
|
||||
:shapes-with-children shapes-with-children
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
(mf/defc booleans-options
|
||||
[]
|
||||
(let [selected (mf/deref refs/selected-objects)
|
||||
selected-with-children (mf/deref refs/selected-objects-with-children)
|
||||
selected-with-children (mf/deref refs/selected-shapes-with-children)
|
||||
|
||||
has-invalid-shapes? (->> selected-with-children
|
||||
(some (comp #{:frame :text} :type)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue