From 91636ffc41a9a2d6912a3d6749ded929b6efced0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 27 May 2025 15:25:17 +0200 Subject: [PATCH] :bug: Adapt inspect code to color type changes Still contains broken code because it was already broken --- .../app/main/ui/inspect/attributes/common.cljs | 18 ++++++++++-------- .../app/main/ui/inspect/attributes/fill.cljs | 14 +++++--------- .../app/main/ui/inspect/attributes/text.cljs | 11 ++--------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/frontend/src/app/main/ui/inspect/attributes/common.cljs b/frontend/src/app/main/ui/inspect/attributes/common.cljs index 1a0f16d2cf..79e953a812 100644 --- a/frontend/src/app/main/ui/inspect/attributes/common.cljs +++ b/frontend/src/app/main/ui/inspect/attributes/common.cljs @@ -26,18 +26,20 @@ (def file-colors-ref (l/derived (l/in [:viewer :file :data :colors]) st/state)) -(defn make-colors-library-ref [libraries-place file-id] +(defn make-colors-library-ref + [libraries-place file-id] (let [get-library (fn [state] (get-in state [libraries-place file-id :data :colors]))] (l/derived get-library st/state))) -(defn- use-colors-library [color] - (-> (mf/use-memo - (mf/deps (:file-id color)) - #(make-colors-library-ref :files (:file-id color))) - mf/deref)) +(defn- use-colors-library + [{:keys [ref-file] :as color}] + (let [library (mf/with-memo [ref-file] + (make-colors-library-ref :files ref-file))] + (mf/deref library))) +;; FIXME: this breaks react hooks rule (broken code) (defn- get-file-colors [] (or (mf/deref file-colors-ref) (mf/deref refs/workspace-file-colors))) @@ -51,8 +53,8 @@ (mf/defc color-row [{:keys [color format copy-data on-change-format]}] (let [colors-library (use-colors-library color) file-colors (get-file-colors) - color-library-name (get-in (or colors-library file-colors) [(:id color) :name]) - color (assoc color :color-library-name color-library-name) + color-library-name (get-in (or colors-library file-colors) [(:ref-id color) :name]) + color (assoc color :name color-library-name) image (:image color)] diff --git a/frontend/src/app/main/ui/inspect/attributes/fill.cljs b/frontend/src/app/main/ui/inspect/attributes/fill.cljs index 415cfce757..a1d8afeae5 100644 --- a/frontend/src/app/main/ui/inspect/attributes/fill.cljs +++ b/frontend/src/app/main/ui/inspect/attributes/fill.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.inspect.attributes.fill (:require-macros [app.main.style :as stl]) (:require + [app.common.types.color :as types.color] [app.main.ui.components.title-bar :refer [inspect-title-bar*]] [app.main.ui.inspect.attributes.common :refer [color-row]] [app.util.code-gen.style-css :as css] @@ -15,14 +16,6 @@ (def properties [:background :background-color :background-image]) -(defn shape->color [shape] - {:color (:fill-color shape) - :opacity (:fill-opacity shape) - :gradient (:fill-color-gradient shape) - :id (:fill-color-ref-id shape) - :file-id (:fill-color-ref-file shape) - :image (:fill-image shape)}) - (defn has-fill? [shape] (and (not (contains? #{:text :group} (:type shape))) @@ -35,7 +28,10 @@ [{:keys [objects shape]}] (let [format* (mf/use-state :hex) format (deref format*) - color (shape->color shape) + ;; FIXME: this looks broken code, because shape does not + ;; longer contains :fill-xxxx attributes but it is preserved + ;; as it was just moved the impl; this need to be fixed + color (types.color/fill->color shape) on-change (mf/use-fn (fn [format] diff --git a/frontend/src/app/main/ui/inspect/attributes/text.cljs b/frontend/src/app/main/ui/inspect/attributes/text.cljs index 71b4306c73..f99037a186 100644 --- a/frontend/src/app/main/ui/inspect/attributes/text.cljs +++ b/frontend/src/app/main/ui/inspect/attributes/text.cljs @@ -10,6 +10,7 @@ [app.common.data :as d] [app.common.data.macros :as dm] [app.common.text :as txt] + [app.common.types.color :as types.color] [app.main.fonts :as fonts] [app.main.refs :as refs] [app.main.store :as st] @@ -34,14 +35,6 @@ (get-in state [:viewer-libraries file-id :data :typographies]))] #(l/derived get-library st/state))) -(defn fill->color [{:keys [fill-color fill-opacity fill-color-gradient fill-color-ref-id fill-color-ref-file fill-image]}] - {:color fill-color - :opacity fill-opacity - :gradient fill-color-gradient - :id fill-color-ref-id - :file-id fill-color-ref-file - :image fill-image}) - (defn copy-style-data [style & properties] (->> properties @@ -73,7 +66,7 @@ (for [[idx fill] (map-indexed vector (:fills style))] [:& color-row {:key idx :format @color-format - :color (fill->color fill) + :color (types.color/fill->color fill) :copy-data (copy-style-data fill :fill-color :fill-color-gradient) :on-change-format #(reset! color-format %)}]))