From f8bc6e12a99e218abdd9fbfcf20521ebac124117 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 28 Aug 2025 09:39:57 +0200 Subject: [PATCH] :zap: Improve efficiency of border radius menu --- .../sidebar/options/menus/border_radius.cljs | 28 +++++++++++++++---- .../sidebar/options/menus/measures.cljs | 6 +--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/border_radius.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/border_radius.cljs index 3901b56866..f41eba18f6 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/border_radius.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/border_radius.cljs @@ -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) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs index 5712d0977b..c93bf3320e 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs @@ -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))