From c28fce58f18aee1f65a2e227b4b88d2776bc4221 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 30 Sep 2020 19:57:29 +0200 Subject: [PATCH] :sparkles: Mixed typographies for texts --- .../app/main/ui/workspace/sidebar/assets.cljs | 3 ++- .../ui/workspace/sidebar/options/text.cljs | 1 + .../workspace/sidebar/options/typography.cljs | 25 +++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index 0c6d4f3fb..c2da2a8fc 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -338,6 +338,7 @@ :left nil}) selected (mf/deref refs/selected-shapes) + local (deref refs/workspace-local) add-typography (mf/use-callback @@ -357,7 +358,7 @@ {:typography-ref-file (when-not local? file-id) :typography-ref-id (:id typography)} (d/without-keys typography [:id :name]))] - (run! #(st/emit! (dwt/update-text-attrs {:id % :editor nil :attrs attrs})) + (run! #(st/emit! (dwt/update-text-attrs {:id % :editor (get-in local [:editors %]) :attrs attrs})) selected))) on-context-menu diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/text.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/text.cljs index b3dd41d3f..6c1dbd35a 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/text.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/text.cljs @@ -303,4 +303,5 @@ [:& text-menu {:ids ids :type type :values text-values + :editor editor :shapes [shape]}]])) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/typography.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/typography.cljs index b64eaf7f4..dbb1c9eb4 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/typography.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/typography.cljs @@ -207,10 +207,23 @@ (mf/defc typography-entry - [{:keys [typography read-only? on-select on-change on-deattach on-context-menu]}] - (let [open? (mf/use-state false) + [{:keys [typography read-only? on-select on-change on-deattach on-context-menu editting? focus-name?]}] + (let [open? (mf/use-state editting?) selected (mf/deref refs/selected-shapes) - hover-deattach (mf/use-state false)] + hover-deattach (mf/use-state false) + name-input-ref (mf/use-ref nil)] + + (mf/use-effect + (mf/deps editting?) + (fn [] (reset! open? editting?))) + + (mf/use-effect + (mf/deps focus-name?) + (fn [] + (when-let [node (mf/ref-val name-input-ref)] + (dom/focus! node) + (dom/select-text! node)))) + [:* [:div.element-set-options-group.typography-entry [:div.typography-selection-wrapper @@ -270,10 +283,8 @@ [:div.row-flex [:input.element-name.adv-typography-name {:type "text" + :ref name-input-ref :value (:name typography) :on-change #(on-change {:name (dom/get-target-val %)})}]]] [:& typography-options {:values typography - :on-change on-change}]] - ) - - ]])) + :on-change on-change}]])]]))