🐛 Adapt inspect code to color type changes

Still contains broken code because it was already broken
This commit is contained in:
Andrey Antukh 2025-05-27 15:25:17 +02:00
parent 7160334cb9
commit 91636ffc41
3 changed files with 17 additions and 26 deletions

View File

@ -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)]

View File

@ -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]

View File

@ -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 %)}]))