From ea20291d2a318e02a2bc0893b5499f0cc90c999c Mon Sep 17 00:00:00 2001 From: Dexterity <173429049+Dexterity104@users.noreply.github.com> Date: Mon, 22 Jun 2026 12:40:01 -0400 Subject: [PATCH] :recycle: Migrate v1 text-editor to modern component syntax (#9446) * :recycle: Migrate v1 text-editor to modern component syntax * :paperclip: Add minor changes Signed-off-by: Andrey Antukh --------- Signed-off-by: Andrey Antukh Co-authored-by: Andrey Antukh --- .../main/ui/workspace/shapes/text/editor.cljs | 38 ++++++++----------- .../src/app/main/ui/workspace/viewport.cljs | 4 +- .../app/main/ui/workspace/viewport_wasm.cljs | 4 +- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs index 766acb2430..3eca4f72fd 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs @@ -30,24 +30,18 @@ ;; --- Text Editor Rendering -(mf/defc block-component - {::mf/wrap-props false} - [props] - (let [bprops (obj/get props "blockProps") - data (obj/get bprops "data") - style (sts/generate-paragraph-styles (obj/get bprops "shape") - (obj/get bprops "data")) - dir (:text-direction data "auto")] - +(mf/defc block-component* + [{:keys [block-props] :as props}] + (let [data (.-data ^js block-props) + style (sts/generate-paragraph-styles (.-shape ^js block-props) data) + dir (:text-direction data "auto")] [:div {:style style :dir dir} [:> draft/EditorBlock props]])) -(mf/defc selection-component - {::mf/wrap-props false} - [props] - (let [children (obj/get props "children")] - [:span {:style {:background "#ccc" :display "inline-block"}} children])) +(mf/defc selection-component* + [{:keys [children]}] + [:span {:style {:background "#ccc" :display "inline-block"}} children]) (defn- render-block [block shape] @@ -55,7 +49,7 @@ (case type "unstyled" #js {:editable true - :component block-component + :component block-component* :props #js {:data (ted/get-editor-block-data block) :shape shape}} nil))) @@ -69,7 +63,7 @@ (sts/generate-text-styles shape data {:show-text? false}))) (def default-decorator - (ted/create-decorator "PENPOT_SELECTION" selection-component)) + (ted/create-decorator "PENPOT_SELECTION" selection-component*)) (def empty-editor-state (ted/create-editor-state nil default-decorator)) @@ -95,12 +89,11 @@ "bottom" "flex-end" nil)) -(mf/defc text-shape-edit-html +(mf/defc text-shape-edit-html* {::mf/wrap [mf/memo] - ::mf/wrap-props false ::mf/forward-ref true} - [props _] - (let [{:keys [id content] :as shape} (obj/get props "shape") + [{:keys [shape]} _] + (let [{:keys [id content]} shape state-map (mf/deref refs/workspace-editor-state) state (get state-map id empty-editor-state) @@ -269,8 +262,7 @@ (-> (gpt/subtract pt box) (gpt/multiply zoom))))) -(mf/defc text-editor-svg - {::mf/wrap-props false} +(mf/defc text-editor-svg* [{:keys [shape modifiers]}] (let [shape-id (dm/get-prop shape :id) modifiers (dm/get-in modifiers [shape-id :modifiers]) @@ -343,6 +335,6 @@ [:foreignObject {:x x :y y :width width :height height} [:div {:style style} - [:& text-shape-edit-html + [:> text-shape-edit-html* {:shape shape :key (dm/str shape-id)}]]]])) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index c7740e9680..ee85719d9b 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -454,8 +454,8 @@ [:& editor-v2/text-editor {:shape editing-shape :canvas-ref canvas-ref :modifiers modifiers}] - [:& editor-v1/text-editor-svg {:shape editing-shape - :modifiers modifiers}])) + [:> editor-v1/text-editor-svg* {:shape editing-shape + :modifiers modifiers}])) (when show-frame-outline? (let [outlined-frame-id diff --git a/frontend/src/app/main/ui/workspace/viewport_wasm.cljs b/frontend/src/app/main/ui/workspace/viewport_wasm.cljs index cdc0a1e094..142134c736 100644 --- a/frontend/src/app/main/ui/workspace/viewport_wasm.cljs +++ b/frontend/src/app/main/ui/workspace/viewport_wasm.cljs @@ -728,8 +728,8 @@ :canvas-ref canvas-ref :ref text-editor-ref}] - :else [:& editor-v1/text-editor-svg {:shape editing-shape - :ref text-editor-ref}])) + :else [:> editor-v1/text-editor-svg* {:shape editing-shape + :ref text-editor-ref}])) (when show-frame-outline? (let [outlined-frame-id (->> @hover-ids