mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 02:28:18 -05:00
🐛 Fix problem with text content and multiple selection
This commit is contained in:
parent
08d7f5d8a3
commit
67b3040327
8 changed files with 129 additions and 106 deletions
|
@ -7,7 +7,8 @@
|
||||||
(ns app.common.attrs
|
(ns app.common.attrs
|
||||||
(:require
|
(:require
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.math :as mth]))
|
[app.common.math :as mth]
|
||||||
|
[app.common.text :as txt]))
|
||||||
|
|
||||||
(defn- get-attr
|
(defn- get-attr
|
||||||
[obj attr]
|
[obj attr]
|
||||||
|
@ -113,3 +114,15 @@
|
||||||
|
|
||||||
(persistent! result)))))
|
(persistent! result)))))
|
||||||
|
|
||||||
|
(defn get-text-attrs-multi
|
||||||
|
"Gets the multi attributes for a text shape. Splits the content by type and gets the attributes depending
|
||||||
|
on the node type"
|
||||||
|
[{:keys [content]} defaults attrs]
|
||||||
|
(let [root-attrs (->> attrs (filter (set txt/root-attrs)))
|
||||||
|
paragraph-attrs (->> attrs (filter (set txt/paragraph-attrs)))
|
||||||
|
text-node-attrs (->> attrs (filter (set txt/text-node-attrs)))]
|
||||||
|
(merge
|
||||||
|
defaults
|
||||||
|
(get-attrs-multi (->> (txt/node-seq txt/is-root-node? content)) root-attrs)
|
||||||
|
(get-attrs-multi (->> (txt/node-seq txt/is-paragraph-node? content)) paragraph-attrs)
|
||||||
|
(get-attrs-multi (->> (txt/node-seq txt/is-text-node? content)) text-node-attrs))))
|
||||||
|
|
|
@ -13,6 +13,67 @@
|
||||||
[clojure.walk :as walk]
|
[clojure.walk :as walk]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
|
;; -- Attrs
|
||||||
|
|
||||||
|
(def text-typography-attrs
|
||||||
|
[:typography-ref-id
|
||||||
|
:typography-ref-file])
|
||||||
|
|
||||||
|
(def text-fill-attrs
|
||||||
|
[:fill-color
|
||||||
|
:fill-opacity
|
||||||
|
:fill-color-ref-id
|
||||||
|
:fill-color-ref-file
|
||||||
|
:fill-color-gradient])
|
||||||
|
|
||||||
|
(def text-font-attrs
|
||||||
|
[:font-id
|
||||||
|
:font-family
|
||||||
|
:font-variant-id
|
||||||
|
:font-size
|
||||||
|
:font-weight
|
||||||
|
:font-style])
|
||||||
|
|
||||||
|
(def text-align-attrs
|
||||||
|
[:text-align])
|
||||||
|
|
||||||
|
(def text-direction-attrs
|
||||||
|
[:text-direction])
|
||||||
|
|
||||||
|
(def text-spacing-attrs
|
||||||
|
[:line-height
|
||||||
|
:letter-spacing])
|
||||||
|
|
||||||
|
(def text-valign-attrs
|
||||||
|
[:vertical-align])
|
||||||
|
|
||||||
|
(def text-decoration-attrs
|
||||||
|
[:text-decoration])
|
||||||
|
|
||||||
|
(def text-transform-attrs
|
||||||
|
[:text-transform])
|
||||||
|
|
||||||
|
(def shape-attrs
|
||||||
|
[:grow-type])
|
||||||
|
|
||||||
|
(def root-attrs
|
||||||
|
text-valign-attrs)
|
||||||
|
|
||||||
|
(def paragraph-attrs
|
||||||
|
(d/concat-vec
|
||||||
|
text-align-attrs
|
||||||
|
text-direction-attrs))
|
||||||
|
|
||||||
|
(def text-node-attrs
|
||||||
|
(d/concat-vec
|
||||||
|
text-typography-attrs
|
||||||
|
text-font-attrs
|
||||||
|
text-spacing-attrs
|
||||||
|
text-decoration-attrs
|
||||||
|
text-transform-attrs))
|
||||||
|
|
||||||
|
(def text-all-attrs (d/concat-set shape-attrs root-attrs paragraph-attrs text-node-attrs))
|
||||||
|
|
||||||
(def default-text-attrs
|
(def default-text-attrs
|
||||||
{:typography-ref-file nil
|
{:typography-ref-file nil
|
||||||
:typography-ref-id nil
|
:typography-ref-id nil
|
||||||
|
@ -30,8 +91,6 @@
|
||||||
:fills [{:fill-color clr/black
|
:fills [{:fill-color clr/black
|
||||||
:fill-opacity 1}]})
|
:fill-opacity 1}]})
|
||||||
|
|
||||||
(def text-attrs (keys default-text-attrs))
|
|
||||||
|
|
||||||
(def typography-fields
|
(def typography-fields
|
||||||
[:font-id
|
[:font-id
|
||||||
:font-family
|
:font-family
|
||||||
|
@ -274,7 +333,7 @@
|
||||||
[node]
|
[node]
|
||||||
(letfn
|
(letfn
|
||||||
[(rec-style-text-map [acc node style]
|
[(rec-style-text-map [acc node style]
|
||||||
(let [node-style (merge style (select-keys node text-attrs))
|
(let [node-style (merge style (select-keys node text-all-attrs))
|
||||||
head (or (-> acc first) [{} ""])
|
head (or (-> acc first) [{} ""])
|
||||||
[head-style head-text] head
|
[head-style head-text] head
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
|
[app.common.text :as txt]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.main.broadcast :as mbc]
|
[app.main.broadcast :as mbc]
|
||||||
[app.main.data.events :as ev]
|
[app.main.data.events :as ev]
|
||||||
|
@ -673,7 +674,7 @@
|
||||||
(:fills (dwt/current-text-values
|
(:fills (dwt/current-text-values
|
||||||
{:editor-state (dm/get-in state [:workspace-editor-state (:id shape)])
|
{:editor-state (dm/get-in state [:workspace-editor-state (:id shape)])
|
||||||
:shape shape
|
:shape shape
|
||||||
:attrs (conj dwt/text-fill-attrs :fills)}))
|
:attrs (conj txt/text-fill-attrs :fills)}))
|
||||||
(:fills shape))
|
(:fills shape))
|
||||||
fill (first fills)
|
fill (first fills)
|
||||||
single? (and (= 1 (count selected))
|
single? (and (= 1 (count selected))
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
(ns app.main.data.workspace.text.shortcuts
|
(ns app.main.data.workspace.text.shortcuts
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.text :as txt]
|
||||||
[app.main.data.shortcuts :as ds]
|
[app.main.data.shortcuts :as ds]
|
||||||
[app.main.data.workspace.texts :as dwt]
|
[app.main.data.workspace.texts :as dwt]
|
||||||
[app.main.data.workspace.undo :as dwu]
|
[app.main.data.workspace.undo :as dwu]
|
||||||
|
@ -116,15 +117,15 @@
|
||||||
(d/merge
|
(d/merge
|
||||||
(dwt/current-root-values
|
(dwt/current-root-values
|
||||||
{:shape shape
|
{:shape shape
|
||||||
:attrs dwt/root-attrs})
|
:attrs txt/root-attrs})
|
||||||
(dwt/current-paragraph-values
|
(dwt/current-paragraph-values
|
||||||
{:editor-state editor-state
|
{:editor-state editor-state
|
||||||
:shape shape
|
:shape shape
|
||||||
:attrs dwt/paragraph-attrs})
|
:attrs txt/paragraph-attrs})
|
||||||
(dwt/current-text-values
|
(dwt/current-text-values
|
||||||
{:editor-state editor-state
|
{:editor-state editor-state
|
||||||
:shape shape
|
:shape shape
|
||||||
:attrs dwt/text-attrs}))))
|
:attrs txt/text-node-attrs}))))
|
||||||
|
|
||||||
(defn- update-attrs [shape props]
|
(defn- update-attrs [shape props]
|
||||||
(let [text-values (calculate-text-values shape)
|
(let [text-values (calculate-text-values shape)
|
||||||
|
|
|
@ -33,66 +33,6 @@
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[potok.v2.core :as ptk]))
|
[potok.v2.core :as ptk]))
|
||||||
|
|
||||||
;; -- Attrs
|
|
||||||
|
|
||||||
(def text-typography-attrs
|
|
||||||
[:typography-ref-id
|
|
||||||
:typography-ref-file])
|
|
||||||
|
|
||||||
(def text-fill-attrs
|
|
||||||
[:fill-color
|
|
||||||
:fill-opacity
|
|
||||||
:fill-color-ref-id
|
|
||||||
:fill-color-ref-file
|
|
||||||
:fill-color-gradient])
|
|
||||||
|
|
||||||
(def text-font-attrs
|
|
||||||
[:font-id
|
|
||||||
:font-family
|
|
||||||
:font-variant-id
|
|
||||||
:font-size
|
|
||||||
:font-weight
|
|
||||||
:font-style])
|
|
||||||
|
|
||||||
(def text-align-attrs
|
|
||||||
[:text-align])
|
|
||||||
|
|
||||||
(def text-direction-attrs
|
|
||||||
[:text-direction])
|
|
||||||
|
|
||||||
(def text-spacing-attrs
|
|
||||||
[:line-height
|
|
||||||
:letter-spacing])
|
|
||||||
|
|
||||||
(def text-valign-attrs
|
|
||||||
[:vertical-align])
|
|
||||||
|
|
||||||
(def text-decoration-attrs
|
|
||||||
[:text-decoration])
|
|
||||||
|
|
||||||
(def text-transform-attrs
|
|
||||||
[:text-transform])
|
|
||||||
|
|
||||||
(def shape-attrs
|
|
||||||
[:grow-type])
|
|
||||||
|
|
||||||
(def root-attrs text-valign-attrs)
|
|
||||||
|
|
||||||
(def paragraph-attrs
|
|
||||||
(d/concat-vec
|
|
||||||
text-align-attrs
|
|
||||||
text-direction-attrs))
|
|
||||||
|
|
||||||
(def text-attrs
|
|
||||||
(d/concat-vec
|
|
||||||
text-typography-attrs
|
|
||||||
text-font-attrs
|
|
||||||
text-spacing-attrs
|
|
||||||
text-decoration-attrs
|
|
||||||
text-transform-attrs))
|
|
||||||
|
|
||||||
(def attrs (d/concat-set shape-attrs root-attrs paragraph-attrs text-attrs))
|
|
||||||
|
|
||||||
;; -- Editor
|
;; -- Editor
|
||||||
|
|
||||||
(defn update-editor
|
(defn update-editor
|
||||||
|
@ -611,17 +551,17 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(let [attrs (select-keys attrs root-attrs)]
|
(let [attrs (select-keys attrs txt/root-attrs)]
|
||||||
(if-not (empty? attrs)
|
(if-not (empty? attrs)
|
||||||
(rx/of (update-root-attrs {:id id :attrs attrs}))
|
(rx/of (update-root-attrs {:id id :attrs attrs}))
|
||||||
(rx/empty)))
|
(rx/empty)))
|
||||||
|
|
||||||
(let [attrs (select-keys attrs paragraph-attrs)]
|
(let [attrs (select-keys attrs txt/paragraph-attrs)]
|
||||||
(if-not (empty? attrs)
|
(if-not (empty? attrs)
|
||||||
(rx/of (update-paragraph-attrs {:id id :attrs attrs}))
|
(rx/of (update-paragraph-attrs {:id id :attrs attrs}))
|
||||||
(rx/empty)))
|
(rx/empty)))
|
||||||
|
|
||||||
(let [attrs (select-keys attrs text-attrs)]
|
(let [attrs (select-keys attrs txt/text-node-attrs)]
|
||||||
(if-not (empty? attrs)
|
(if-not (empty? attrs)
|
||||||
(rx/of (update-text-attrs {:id id :attrs attrs}))
|
(rx/of (update-text-attrs {:id id :attrs attrs}))
|
||||||
(rx/empty)))))))
|
(rx/empty)))))))
|
||||||
|
@ -683,7 +623,7 @@
|
||||||
values (current-text-values
|
values (current-text-values
|
||||||
{:editor-state (dm/get-in state [:workspace-editor-state (:id shape)])
|
{:editor-state (dm/get-in state [:workspace-editor-state (:id shape)])
|
||||||
:shape shape
|
:shape shape
|
||||||
:attrs text-attrs})
|
:attrs txt/text-node-attrs})
|
||||||
|
|
||||||
multiple? (or (> 1 (count shapes))
|
multiple? (or (> 1 (count shapes))
|
||||||
(d/seek (partial = :multiple)
|
(d/seek (partial = :multiple)
|
||||||
|
@ -691,9 +631,9 @@
|
||||||
|
|
||||||
values (-> (d/without-nils values)
|
values (-> (d/without-nils values)
|
||||||
(select-keys
|
(select-keys
|
||||||
(d/concat-vec text-font-attrs
|
(d/concat-vec txt/text-font-attrs
|
||||||
text-spacing-attrs
|
txt/text-spacing-attrs
|
||||||
text-transform-attrs)))
|
txt/text-transform-attrs)))
|
||||||
|
|
||||||
typ-id (uuid/next)
|
typ-id (uuid/next)
|
||||||
typ (-> (if multiple?
|
typ (-> (if multiple?
|
||||||
|
|
|
@ -212,7 +212,7 @@
|
||||||
(mf/deps values)
|
(mf/deps values)
|
||||||
(fn [ids attrs]
|
(fn [ids attrs]
|
||||||
(st/emit! (dwt/save-font (-> (merge txt/default-text-attrs values attrs)
|
(st/emit! (dwt/save-font (-> (merge txt/default-text-attrs values attrs)
|
||||||
(select-keys dwt/text-attrs)))
|
(select-keys txt/text-node-attrs)))
|
||||||
(dwt/update-all-attrs ids attrs))))
|
(dwt/update-all-attrs ids attrs))))
|
||||||
|
|
||||||
on-change
|
on-change
|
||||||
|
@ -242,9 +242,9 @@
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(let [set-values (-> (d/without-nils values)
|
(let [set-values (-> (d/without-nils values)
|
||||||
(select-keys
|
(select-keys
|
||||||
(d/concat-vec dwt/text-font-attrs
|
(d/concat-vec txt/text-font-attrs
|
||||||
dwt/text-spacing-attrs
|
txt/text-spacing-attrs
|
||||||
dwt/text-transform-attrs)))
|
txt/text-transform-attrs)))
|
||||||
typography (merge txt/default-typography set-values)
|
typography (merge txt/default-typography set-values)
|
||||||
typography (dwt/generate-typography-name typography)
|
typography (dwt/generate-typography-name typography)
|
||||||
id (uuid/next)]
|
id (uuid/next)]
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.shape.attrs :refer [editable-attrs]]
|
[app.common.types.shape.attrs :refer [editable-attrs]]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.main.data.workspace.texts :as dwt]
|
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.ui.hooks :as hooks]
|
[app.main.ui.hooks :as hooks]
|
||||||
[app.main.ui.workspace.sidebar.options.menus.blur :refer [blur-attrs blur-menu]]
|
[app.main.ui.workspace.sidebar.options.menus.blur :refer [blur-attrs blur-menu]]
|
||||||
|
@ -163,7 +162,7 @@
|
||||||
:shadow shadow-attrs
|
:shadow shadow-attrs
|
||||||
:blur blur-attrs
|
:blur blur-attrs
|
||||||
:stroke stroke-attrs
|
:stroke stroke-attrs
|
||||||
:text dwt/attrs
|
:text txt/text-all-attrs
|
||||||
:exports exports-attrs
|
:exports exports-attrs
|
||||||
:layout-container layout-container-flex-attrs
|
:layout-container layout-container-flex-attrs
|
||||||
:layout-item layout-item-attrs})
|
:layout-item layout-item-attrs})
|
||||||
|
@ -211,13 +210,15 @@
|
||||||
:else (attrs/get-attrs-multi [v1 v2] attrs)))
|
:else (attrs/get-attrs-multi [v1 v2] attrs)))
|
||||||
|
|
||||||
extract-attrs
|
extract-attrs
|
||||||
(fn [[ids values] {:keys [id type content] :as shape}]
|
(fn [[ids values] {:keys [id type] :as shape}]
|
||||||
(let [read-mode (get-in type->read-mode [type attr-group])
|
(let [read-mode (get-in type->read-mode [type attr-group])
|
||||||
editable-attrs (filter (get editable-attrs (:type shape)) attrs)]
|
editable-attrs (filter (get editable-attrs (:type shape)) attrs)]
|
||||||
(case read-mode
|
(case read-mode
|
||||||
:ignore [ids values]
|
:ignore
|
||||||
|
[ids values]
|
||||||
|
|
||||||
:shape (let [;; Get the editable attrs from the shape, ensuring that all attributes
|
:shape
|
||||||
|
(let [;; Get the editable attrs from the shape, ensuring that all attributes
|
||||||
;; are present, with value nil if they are not present in the shape.
|
;; are present, with value nil if they are not present in the shape.
|
||||||
shape-values (merge
|
shape-values (merge
|
||||||
(into {} (map #(vector % nil)) editable-attrs)
|
(into {} (map #(vector % nil)) editable-attrs)
|
||||||
|
@ -227,14 +228,21 @@
|
||||||
[(conj ids id)
|
[(conj ids id)
|
||||||
(merge-attrs values shape-values)])
|
(merge-attrs values shape-values)])
|
||||||
|
|
||||||
:text [(conj ids id)
|
:text
|
||||||
(-> values
|
(let [shape-attrs (select-keys shape attrs)
|
||||||
(merge-attrs (select-keys shape attrs))
|
|
||||||
(merge-attrs (merge
|
|
||||||
(select-keys txt/default-text-attrs attrs)
|
|
||||||
(attrs/get-attrs-multi (txt/node-seq content) attrs))))]
|
|
||||||
|
|
||||||
:children (let [children (->> (:shapes shape []) (map #(get objects %)))
|
content-attrs
|
||||||
|
(attrs/get-text-attrs-multi shape txt/default-text-attrs attrs)
|
||||||
|
|
||||||
|
new-values
|
||||||
|
(-> values
|
||||||
|
(merge-attrs shape-attrs)
|
||||||
|
(merge-attrs content-attrs))]
|
||||||
|
[(conj ids id)
|
||||||
|
new-values])
|
||||||
|
|
||||||
|
:children
|
||||||
|
(let [children (->> (:shapes shape []) (map #(get objects %)))
|
||||||
[new-ids new-values] (get-attrs* children objects attr-group)]
|
[new-ids new-values] (get-attrs* children objects attr-group)]
|
||||||
[(d/concat-vec ids new-ids) (merge-attrs values new-values)])
|
[(d/concat-vec ids new-ids) (merge-attrs values new-values)])
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
(ns app.main.ui.workspace.sidebar.options.shapes.text
|
(ns app.main.ui.workspace.sidebar.options.shapes.text
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.text :as txt]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.main.data.workspace.texts :as dwt :refer [text-fill-attrs root-attrs paragraph-attrs text-attrs]]
|
[app.main.data.workspace.texts :as dwt]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.ui.hooks :as hooks]
|
[app.main.ui.hooks :as hooks]
|
||||||
[app.main.ui.workspace.sidebar.options.menus.blur :refer [blur-menu]]
|
[app.main.ui.workspace.sidebar.options.menus.blur :refer [blur-menu]]
|
||||||
|
@ -56,7 +57,7 @@
|
||||||
fill-values (-> (dwt/current-text-values
|
fill-values (-> (dwt/current-text-values
|
||||||
{:editor-state editor-state
|
{:editor-state editor-state
|
||||||
:shape shape
|
:shape shape
|
||||||
:attrs (conj text-fill-attrs :fills)})
|
:attrs (conj txt/text-fill-attrs :fills)})
|
||||||
(d/update-in-when [:fill-color-gradient :type] keyword))
|
(d/update-in-when [:fill-color-gradient :type] keyword))
|
||||||
|
|
||||||
fill-values (if (not (contains? fill-values :fills))
|
fill-values (if (not (contains? fill-values :fills))
|
||||||
|
@ -71,15 +72,15 @@
|
||||||
(select-keys shape fill-attrs)
|
(select-keys shape fill-attrs)
|
||||||
(dwt/current-root-values
|
(dwt/current-root-values
|
||||||
{:shape shape
|
{:shape shape
|
||||||
:attrs root-attrs})
|
:attrs txt/root-attrs})
|
||||||
(dwt/current-paragraph-values
|
(dwt/current-paragraph-values
|
||||||
{:editor-state editor-state
|
{:editor-state editor-state
|
||||||
:shape shape
|
:shape shape
|
||||||
:attrs paragraph-attrs})
|
:attrs txt/paragraph-attrs})
|
||||||
(dwt/current-text-values
|
(dwt/current-text-values
|
||||||
{:editor-state editor-state
|
{:editor-state editor-state
|
||||||
:shape shape
|
:shape shape
|
||||||
:attrs text-attrs}))
|
:attrs txt/text-node-attrs}))
|
||||||
layout-item-values (select-keys shape layout-item-attrs)]
|
layout-item-values (select-keys shape layout-item-attrs)]
|
||||||
|
|
||||||
[:*
|
[:*
|
||||||
|
|
Loading…
Add table
Reference in a new issue