mirror of
https://github.com/penpot/penpot.git
synced 2026-09-11 22:49:30 +00:00
⚡ Improve efficiency of border radius menu
This commit is contained in:
parent
a2c3208af9
commit
f8bc6e12a9
@ -14,23 +14,39 @@
|
|||||||
[potok.v2.core :as ptk]
|
[potok.v2.core :as ptk]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
(defn all-equal?
|
(defn- all-equal?
|
||||||
[shape]
|
[shape]
|
||||||
(= (:r1 shape) (:r2 shape) (:r3 shape) (:r4 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/defc border-radius-menu*
|
||||||
{::mf/props :obj
|
{::mf/wrap [#(mf/memo' % check-border-radius-menu-props)]}
|
||||||
::mf/wrap [mf/memo]}
|
[{:keys [class ids values]}]
|
||||||
[{:keys [class ids ids-with-children values]}]
|
|
||||||
(let [all-equal? (all-equal? values)
|
(let [all-equal? (all-equal? values)
|
||||||
radius-expanded* (mf/use-state false)
|
radius-expanded* (mf/use-state false)
|
||||||
radius-expanded (deref radius-expanded*)
|
radius-expanded (deref radius-expanded*)
|
||||||
|
|
||||||
change-radius
|
change-radius
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps ids-with-children)
|
(mf/deps ids)
|
||||||
(fn [update-fn]
|
(fn [update-fn]
|
||||||
(dwsh/update-shapes ids-with-children
|
(dwsh/update-shapes ids
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(if (ctsr/has-radius? shape)
|
(if (ctsr/has-radius? shape)
|
||||||
(update-fn shape)
|
(update-fn shape)
|
||||||
|
|||||||
@ -92,7 +92,7 @@
|
|||||||
|
|
||||||
(mf/defc measures-menu*
|
(mf/defc measures-menu*
|
||||||
{::mf/memo true}
|
{::mf/memo true}
|
||||||
[{:keys [ids ids-with-children values type shapes]}]
|
[{:keys [ids values type shapes]}]
|
||||||
(let [all-types
|
(let [all-types
|
||||||
(mf/with-memo [type shapes]
|
(mf/with-memo [type shapes]
|
||||||
;; We only need this when multiple type is used
|
;; We only need this when multiple type is used
|
||||||
@ -105,9 +105,6 @@
|
|||||||
(into #{} xf:mapcat-type-to-options all-types)
|
(into #{} xf:mapcat-type-to-options all-types)
|
||||||
(type->options type)))
|
(type->options type)))
|
||||||
|
|
||||||
ids-with-children
|
|
||||||
(d/nilv ids-with-children ids)
|
|
||||||
|
|
||||||
frames
|
frames
|
||||||
(mf/with-memo [shapes]
|
(mf/with-memo [shapes]
|
||||||
(let [objects (deref refs/workspace-page-objects)]
|
(let [objects (deref refs/workspace-page-objects)]
|
||||||
@ -466,7 +463,6 @@
|
|||||||
(when (options :radius)
|
(when (options :radius)
|
||||||
[:> border-radius-menu* {:class (stl/css :border-radius)
|
[:> border-radius-menu* {:class (stl/css :border-radius)
|
||||||
:ids ids
|
:ids ids
|
||||||
:ids-with-children ids-with-children
|
|
||||||
:values values
|
:values values
|
||||||
:shape shape}])])
|
:shape shape}])])
|
||||||
(when (or (options :clip-content) (options :show-in-viewer))
|
(when (or (options :clip-content) (options :show-in-viewer))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user