🐛 Fix v2 text editor detaching typography tokens

This commit is contained in:
Alejandro Alonso 2026-06-23 17:01:09 +02:00
parent 5042a34e3c
commit b66d1a657d
3 changed files with 40 additions and 20 deletions

View File

@ -77,6 +77,12 @@
(when (some? font-id) (when (some? font-id)
(fonts/ensure-loaded! font-id variant-id)))))) (fonts/ensure-loaded! font-id variant-id))))))
(defn- strip-text-node-line-height
"Line-height is paragraph-level in the DOM; ignore it on text nodes when
checking whether the editor changed the shape content."
[content]
(txt/transform-nodes txt/is-text-node? #(dissoc % :line-height) content))
(defn- initialize-event-handlers (defn- initialize-event-handlers
"Internal editor events handler initializer/destructor" "Internal editor events handler initializer/destructor"
[shape-id content editor-ref canvas-ref container-ref text-color] [shape-id content editor-ref canvas-ref container-ref text-color]
@ -117,25 +123,29 @@
on-blur on-blur
(fn [] (fn []
(when-let [content (content/dom->cljs (dwt/get-editor-root instance))] (when-let [content (content/dom->cljs (dwt/get-editor-root instance))]
(let [state @st/state (when (or (nil? original-content)
objects (dsh/lookup-page-objects state) (seq (txt/get-diff-attrs
shape (get objects shape-id) (strip-text-node-line-height original-content)
current-name (:name shape) (strip-text-node-line-height content))))
generated-name (gen-name instance) (let [state @st/state
;; Update name if: (1) it's a new shape (nil original content), or objects (dsh/lookup-page-objects state)
;; (2) the current name matches the generated name from original content shape (get objects shape-id)
;; (meaning it was never manually renamed) current-name (:name shape)
update-name? (or (nil? original-content) generated-name (gen-name instance)
(and (some? current-name) ;; Update name if: (1) it's a new shape (nil original content), or
(some? original-content) ;; (2) the current name matches the generated name from original content
(= current-name (txt/generate-shape-name (txt/content->text original-content)))))] ;; (meaning it was never manually renamed)
(st/emit! (dwt/v2-update-text-shape-content shape-id content update-name? (or (nil? original-content)
:update-name? update-name? (and (some? current-name)
:name generated-name (some? original-content)
:finalize? true (= current-name (txt/generate-shape-name (txt/content->text original-content)))))]
;; Single undo entry for the whole edit (st/emit! (dwt/v2-update-text-shape-content shape-id content
:save-undo? true :update-name? update-name?
:original-content original-content)))) :name generated-name
:finalize? true
;; Single undo entry for the whole edit
:save-undo? true
:original-content original-content)))))
(let [container-node (mf/ref-val container-ref)] (let [container-node (mf/ref-val container-ref)]
(dom/set-style! container-node "opacity" 0))) (dom/set-style! container-node "opacity" 0)))

View File

@ -55,9 +55,12 @@
(assoc acc key (if (value-empty? value) (get defaults key) value)))) (assoc acc key (if (value-empty? value) (get defaults key) value))))
{} attrs))) {} attrs)))
(def ^:private text-span-attrs
(vec (remove #{:line-height} txt/text-node-attrs)))
(defn get-text-span-styles (defn get-text-span-styles
[element] [element]
(get-attrs-from-styles element txt/text-node-attrs (txt/get-default-text-attrs))) (get-attrs-from-styles element text-span-attrs (txt/get-default-text-attrs)))
(defn get-paragraph-styles (defn get-paragraph-styles
[element] [element]

View File

@ -6,6 +6,7 @@
(ns app.util.text.content.styles (ns app.util.text.content.styles
(:require (:require
[app.common.data :as d]
[app.common.transit :as transit] [app.common.transit :as transit]
[app.common.types.text :as txt] [app.common.types.text :as txt]
[cuerdas.core :as str])) [cuerdas.core :as str]))
@ -60,6 +61,12 @@
(= k :font-family) (= k :font-family)
(str/unquote (str/replace v ", var(--fallback-families)" "")) (str/unquote (str/replace v ", var(--fallback-families)" ""))
(and (= k :line-height)
(string? v)
(not= v ""))
(let [parsed (d/parse-double v)]
(if (number? parsed) parsed v))
:else :else
v)) v))