Improve efficiency of border radius menu

This commit is contained in:
Andrey Antukh 2025-08-28 09:39:57 +02:00
parent a2c3208af9
commit f8bc6e12a9
2 changed files with 23 additions and 11 deletions

View File

@ -14,23 +14,39 @@
[potok.v2.core :as ptk]
[rumext.v2 :as mf]))
(defn all-equal?
(defn- all-equal?
[shape]
(= (:r1 shape) (:r2 shape) (:r3 shape) (:r4 shape)))
(defn- check-border-radius-menu-props
[old-props new-props]
(let [old-values (unchecked-get old-props "values")
new-values (unchecked-get new-props "values")]
(and (identical? (unchecked-get old-props "class")
(unchecked-get new-props "class"))
(identical? (unchecked-get old-props "ids")
(unchecked-get new-props "ids"))
(identical? (get old-values :r1)
(get new-values :r1))
(identical? (get old-values :r2)
(get new-values :r2))
(identical? (get old-values :r3)
(get new-values :r3))
(identical? (get old-values :r4)
(get new-values :r4)))))
(mf/defc border-radius-menu*
{::mf/props :obj
::mf/wrap [mf/memo]}
[{:keys [class ids ids-with-children values]}]
{::mf/wrap [#(mf/memo' % check-border-radius-menu-props)]}
[{:keys [class ids values]}]
(let [all-equal? (all-equal? values)
radius-expanded* (mf/use-state false)
radius-expanded (deref radius-expanded*)
change-radius
(mf/use-fn
(mf/deps ids-with-children)
(mf/deps ids)
(fn [update-fn]
(dwsh/update-shapes ids-with-children
(dwsh/update-shapes ids
(fn [shape]
(if (ctsr/has-radius? shape)
(update-fn shape)

View File

@ -92,7 +92,7 @@
(mf/defc measures-menu*
{::mf/memo true}
[{:keys [ids ids-with-children values type shapes]}]
[{:keys [ids values type shapes]}]
(let [all-types
(mf/with-memo [type shapes]
;; We only need this when multiple type is used
@ -105,9 +105,6 @@
(into #{} xf:mapcat-type-to-options all-types)
(type->options type)))
ids-with-children
(d/nilv ids-with-children ids)
frames
(mf/with-memo [shapes]
(let [objects (deref refs/workspace-page-objects)]
@ -466,7 +463,6 @@
(when (options :radius)
[:> border-radius-menu* {:class (stl/css :border-radius)
:ids ids
:ids-with-children ids-with-children
:values values
:shape shape}])])
(when (or (options :clip-content) (options :show-in-viewer))