mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 07:29:08 -05:00
Add line-height, letter spacing and text saving for text shape.
This commit is contained in:
parent
8e5d193518
commit
c7fd8570e3
3 changed files with 61 additions and 20 deletions
|
@ -57,7 +57,9 @@
|
||||||
:style [sc/string]
|
:style [sc/string]
|
||||||
:weight [sc/string]
|
:weight [sc/string]
|
||||||
:align [sc/string]
|
:align [sc/string]
|
||||||
:size [sc/number]})
|
:size [sc/number]
|
||||||
|
:letter-spacing [sc/number]
|
||||||
|
:line-height [sc/number]})
|
||||||
|
|
||||||
(def ^:static +shape-radius-attrs-schema+
|
(def ^:static +shape-radius-attrs-schema+
|
||||||
{:rx [sc/integer]
|
{:rx [sc/integer]
|
||||||
|
@ -155,6 +157,15 @@
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(update-in state [:shapes-by-id sid] sh/move' opts))))
|
(update-in state [:shapes-by-id sid] sh/move' opts))))
|
||||||
|
|
||||||
|
(defn update-text
|
||||||
|
"Update the start position coordenate of the shape."
|
||||||
|
[sid {:keys [content]}]
|
||||||
|
{:pre [(string? content)]}
|
||||||
|
(reify
|
||||||
|
rs/UpdateEvent
|
||||||
|
(-apply-update [_ state]
|
||||||
|
(assoc-in state [:shapes-by-id sid :content] content))))
|
||||||
|
|
||||||
(defn update-fill-attrs
|
(defn update-fill-attrs
|
||||||
[sid {:keys [color opacity] :as opts}]
|
[sid {:keys [color opacity] :as opts}]
|
||||||
(sc/validate! +shape-fill-attrs-schema+ opts)
|
(sc/validate! +shape-fill-attrs-schema+ opts)
|
||||||
|
@ -167,13 +178,16 @@
|
||||||
(when opacity {:opacity opacity})))))
|
(when opacity {:opacity opacity})))))
|
||||||
|
|
||||||
(defn update-font-attrs
|
(defn update-font-attrs
|
||||||
[sid {:keys [family style weight size align] :as opts}]
|
[sid {:keys [family style weight size align
|
||||||
|
letter-spacing line-height] :as opts}]
|
||||||
(sc/validate! +shape-font-attrs-schema+ opts)
|
(sc/validate! +shape-font-attrs-schema+ opts)
|
||||||
(reify
|
(reify
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(update-in state [:shapes-by-id sid :font]
|
(update-in state [:shapes-by-id sid :font]
|
||||||
merge
|
merge
|
||||||
|
(when line-height {:line-height line-height})
|
||||||
|
(when letter-spacing {:letter-spacing letter-spacing})
|
||||||
(when align {:align align})
|
(when align {:align align})
|
||||||
(when family {:family family})
|
(when family {:family family})
|
||||||
(when style {:style style})
|
(when style {:style style})
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
[uxbox.rstore :as rs]
|
[uxbox.rstore :as rs]
|
||||||
[uxbox.state :as st]
|
[uxbox.state :as st]
|
||||||
[uxbox.shapes :as ush]
|
[uxbox.shapes :as ush]
|
||||||
|
[uxbox.data.shapes :as ds]
|
||||||
[uxbox.data.workspace :as dw]
|
[uxbox.data.workspace :as dw]
|
||||||
[uxbox.ui.core :as uuc]
|
[uxbox.ui.core :as uuc]
|
||||||
[uxbox.ui.mixins :as mx]
|
[uxbox.ui.mixins :as mx]
|
||||||
|
@ -75,25 +76,31 @@
|
||||||
(uuc/release-action! ::edition)
|
(uuc/release-action! ::edition)
|
||||||
(swap! local assoc :edition false)
|
(swap! local assoc :edition false)
|
||||||
(set! (.-contentEditable container) false)
|
(set! (.-contentEditable container) false)
|
||||||
(.removeAttribute container "contenteditable")))]
|
(.removeAttribute container "contenteditable")))
|
||||||
|
(on-input [ev]
|
||||||
|
(let [content (dom/event->inner-text ev)
|
||||||
|
sid (:id (first (:rum/props own)))]
|
||||||
|
(rs/emit! (ds/update-text sid {:content content}))))]
|
||||||
(let [dom (mx/get-ref-dom own "main")
|
(let [dom (mx/get-ref-dom own "main")
|
||||||
dom2 (mx/get-ref-dom own "container")
|
dom2 (mx/get-ref-dom own "container")
|
||||||
key1 (events/listen dom EventType.DBLCLICK on-double-click)
|
key1 (events/listen dom EventType.DBLCLICK on-double-click)
|
||||||
key2 (events/listen dom2 EventType.BLUR on-blur)]
|
key2 (events/listen dom2 EventType.BLUR on-blur)
|
||||||
(assoc own ::key1 key1))))
|
key3 (events/listen dom2 EventType.INPUT on-input)]
|
||||||
|
(assoc own ::key1 key1 ::key2 key2 ::key3 key3))))
|
||||||
|
|
||||||
(defn- text-component-will-unmount
|
(defn- text-component-will-unmount
|
||||||
[own]
|
[own]
|
||||||
(let [key1 (::key1 own)
|
(let [key1 (::key1 own)
|
||||||
key2 (::key2 own)]
|
key2 (::key2 own)
|
||||||
|
key3 (::key3 own)]
|
||||||
(events/unlistenByKey key1)
|
(events/unlistenByKey key1)
|
||||||
(events/unlistenByKey key2)
|
(events/unlistenByKey key2)
|
||||||
(dissoc own ::key1 ::key2)))
|
(events/unlistenByKey key3)
|
||||||
|
(dissoc own ::key1 ::key2 ::key3)))
|
||||||
|
|
||||||
(defn- text-component-transfer-state
|
(defn- text-component-transfer-state
|
||||||
[old-own own]
|
[old-own own]
|
||||||
(let [data (select-keys old-own [::key1 ::key2])]
|
(let [data (select-keys old-own [::key1 ::key2 ::key3])]
|
||||||
(merge own data)))
|
(merge own data)))
|
||||||
|
|
||||||
(defn- text-component-render
|
(defn- text-component-render
|
||||||
|
@ -136,21 +143,26 @@
|
||||||
|
|
||||||
(defn- build-style
|
(defn- build-style
|
||||||
[{:keys [font fill opacity] :or {fill "#000000" opacity 1}}]
|
[{:keys [font fill opacity] :or {fill "#000000" opacity 1}}]
|
||||||
(let [{:keys [family weight style size align]
|
(let [{:keys [family weight style size align line-height letter-spacing]
|
||||||
:or {family "sourcesanspro"
|
:or {family "sourcesanspro"
|
||||||
weight "normal"
|
weight "normal"
|
||||||
style "normal"
|
style "normal"
|
||||||
|
line-height 1.4
|
||||||
|
letter-spacing 1
|
||||||
align "left"
|
align "left"
|
||||||
size 16}} font
|
size 16}} font
|
||||||
color (-> fill
|
color (-> fill
|
||||||
(color/hex->rgba opacity)
|
(color/hex->rgba opacity)
|
||||||
(color/rgb->str))]
|
(color/rgb->str))]
|
||||||
{:fontSize (str size "px")
|
(merge
|
||||||
:color color
|
{:fontSize (str size "px")
|
||||||
:textAlign align
|
:color color
|
||||||
:fontFamily family
|
:textAlign align
|
||||||
:fontWeight weight
|
:fontFamily family
|
||||||
:fontStyle style}))
|
:fontWeight weight
|
||||||
|
:fontStyle style}
|
||||||
|
(when line-height {:lineHeight line-height})
|
||||||
|
(when letter-spacing {:letterSpacing letter-spacing}))))
|
||||||
|
|
||||||
(defmethod uusc/render-shape :builtin/text
|
(defmethod uusc/render-shape :builtin/text
|
||||||
[{:keys [id x1 y1 x2 y2 content drawing? editing?] :as shape}]
|
[{:keys [id x1 y1 x2 y2 content drawing? editing?] :as shape}]
|
||||||
|
@ -161,7 +173,6 @@
|
||||||
:transform (str rfm)}
|
:transform (str rfm)}
|
||||||
attrs (merge props size)
|
attrs (merge props size)
|
||||||
style (build-style shape)]
|
style (build-style shape)]
|
||||||
|
|
||||||
(html
|
(html
|
||||||
[:g
|
[:g
|
||||||
(if (or drawing? editing?)
|
(if (or drawing? editing?)
|
||||||
|
|
|
@ -511,10 +511,21 @@
|
||||||
params {:size (parse-int value)}
|
params {:size (parse-int value)}
|
||||||
sid (:id shape)]
|
sid (:id shape)]
|
||||||
(rs/emit! (uds/update-font-attrs sid params))))
|
(rs/emit! (uds/update-font-attrs sid params))))
|
||||||
|
(on-font-letter-spacing-change [event]
|
||||||
|
(let [value (dom/event->value event)
|
||||||
|
params {:letter-spacing (parse-float value)}
|
||||||
|
sid (:id shape)]
|
||||||
|
(rs/emit! (uds/update-font-attrs sid params))))
|
||||||
|
(on-font-line-height-change [event]
|
||||||
|
(let [value (dom/event->value event)
|
||||||
|
params {:line-height (parse-float value)}
|
||||||
|
sid (:id shape)]
|
||||||
|
(rs/emit! (uds/update-font-attrs sid params))))
|
||||||
(on-font-align-change [event value]
|
(on-font-align-change [event value]
|
||||||
(let [params {:align value}
|
(let [params {:align value}
|
||||||
sid (:id shape)]
|
sid (:id shape)]
|
||||||
(rs/emit! (uds/update-font-attrs sid params))))
|
(rs/emit! (uds/update-font-attrs sid params))))
|
||||||
|
|
||||||
(on-font-style-change [event]
|
(on-font-style-change [event]
|
||||||
(let [value (dom/event->value event)
|
(let [value (dom/event->value event)
|
||||||
[weight style] (read-string value)
|
[weight style] (read-string value)
|
||||||
|
@ -522,11 +533,13 @@
|
||||||
params {:style style
|
params {:style style
|
||||||
:weight weight}]
|
:weight weight}]
|
||||||
(rs/emit! (uds/update-font-attrs sid params))))]
|
(rs/emit! (uds/update-font-attrs sid params))))]
|
||||||
(let [{:keys [family style weight size align]
|
(let [{:keys [family style weight size align line-height letter-spacing]
|
||||||
:or {family "sourcesanspro"
|
:or {family "sourcesanspro"
|
||||||
align "left"
|
align "left"
|
||||||
style "normal"
|
style "normal"
|
||||||
weight "normal"
|
weight "normal"
|
||||||
|
letter-spacing 1
|
||||||
|
line-height 1.4
|
||||||
size 16}} font
|
size 16}} font
|
||||||
styles (:styles (first (filter #(= (:id %) family) library/+fonts+)))]
|
styles (:styles (first (filter #(= (:id %) family) library/+fonts+)))]
|
||||||
(html
|
(html
|
||||||
|
@ -566,14 +579,17 @@
|
||||||
:step "0.1"
|
:step "0.1"
|
||||||
:min "0"
|
:min "0"
|
||||||
:max "200"
|
:max "200"
|
||||||
:defaultValue "1.5"}]
|
:value line-height
|
||||||
|
:on-change on-font-line-height-change}]
|
||||||
[:input.input-text
|
[:input.input-text
|
||||||
{:placeholder "Letter spacing"
|
{:placeholder "Letter spacing"
|
||||||
:type "number"
|
:type "number"
|
||||||
:step "0.1"
|
:step "0.1"
|
||||||
:min "0"
|
:min "0"
|
||||||
:max "200"
|
:max "200"
|
||||||
:defaultValue "1"}]]
|
:value letter-spacing
|
||||||
|
:on-change on-font-letter-spacing-change}]]
|
||||||
|
|
||||||
|
|
||||||
[:span "Text align"]
|
[:span "Text align"]
|
||||||
[:div.row-flex.align-icons
|
[:div.row-flex.align-icons
|
||||||
|
|
Loading…
Add table
Reference in a new issue