mirror of
https://github.com/penpot/penpot.git
synced 2025-05-20 03:26:11 +02:00
🎉 Create typography style from a selected text layer
This commit is contained in:
parent
ccaac2a5c7
commit
aaca901fd9
2 changed files with 40 additions and 4 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
### :sparkles: New features
|
### :sparkles: New features
|
||||||
- Default naming of text layers [Taiga #2836](https://tree.taiga.io/project/penpot/us/2836)
|
- Default naming of text layers [Taiga #2836](https://tree.taiga.io/project/penpot/us/2836)
|
||||||
|
- Create typography style from a selected text layer [Taiga #3041](https://tree.taiga.io/project/penpot/us/3041)
|
||||||
|
|
||||||
### :bug: Bugs fixed
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
[app.common.text :as txt]
|
[app.common.text :as txt]
|
||||||
[app.common.types.components-list :as ctkl]
|
[app.common.types.components-list :as ctkl]
|
||||||
[app.common.types.file :as ctf]
|
[app.common.types.file :as ctf]
|
||||||
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.main.data.events :as ev]
|
[app.main.data.events :as ev]
|
||||||
[app.main.data.modal :as modal]
|
[app.main.data.modal :as modal]
|
||||||
|
@ -35,6 +36,7 @@
|
||||||
[app.main.ui.context :as ctx]
|
[app.main.ui.context :as ctx]
|
||||||
[app.main.ui.hooks :as h]
|
[app.main.ui.hooks :as h]
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
|
[app.main.ui.workspace.sidebar.options.menus.text :refer [generate-typography-name]]
|
||||||
[app.main.ui.workspace.sidebar.options.menus.typography :refer [typography-entry]]
|
[app.main.ui.workspace.sidebar.options.menus.typography :refer [typography-entry]]
|
||||||
[app.util.color :as uc]
|
[app.util.color :as uc]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
|
@ -1735,14 +1737,47 @@
|
||||||
(seq (:colors selected-assets)))
|
(seq (:colors selected-assets)))
|
||||||
workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)
|
workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)
|
||||||
|
|
||||||
|
text-shapes (->>
|
||||||
|
(mf/deref refs/selected-objects)
|
||||||
|
(filter #(= (:type %) :text)))
|
||||||
|
|
||||||
|
state-map (mf/deref refs/workspace-editor-state)
|
||||||
|
text-shape (first text-shapes)
|
||||||
|
editor-state (get state-map (:id text-shape))
|
||||||
|
|
||||||
|
text-values (dwt/current-text-values
|
||||||
|
{:editor-state editor-state
|
||||||
|
:shape text-shape
|
||||||
|
:attrs dwt/text-attrs})
|
||||||
|
|
||||||
|
multiple? (or (> 1 (count text-shape))
|
||||||
|
(->> text-values vals (d/seek #(= % :multiple))))
|
||||||
|
|
||||||
|
values (-> (d/without-nils text-values)
|
||||||
|
(select-keys
|
||||||
|
(d/concat-vec dwt/text-font-attrs
|
||||||
|
dwt/text-spacing-attrs
|
||||||
|
dwt/text-transform-attrs)))
|
||||||
|
|
||||||
|
typography-id (uuid/next)
|
||||||
|
typography (-> (if multiple?
|
||||||
|
txt/default-typography
|
||||||
|
(merge txt/default-typography values))
|
||||||
|
(generate-typography-name)
|
||||||
|
(assoc :id typography-id))
|
||||||
|
|
||||||
add-typography
|
add-typography
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps file-id)
|
(mf/deps file-id typography)
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(st/emit! (dwl/add-typography txt/default-typography)
|
(when (not multiple?)
|
||||||
(ptk/event ::ev/event {::ev/name "add-asset-to-library"
|
(st/emit! (dwt/update-attrs (:id text-shape) {:typography-ref-id typography-id
|
||||||
:asset-type "typography"}))))
|
:typography-ref-file file-id})))
|
||||||
|
|
||||||
|
(st/emit! (dwl/add-typography typography)
|
||||||
|
(ptk/event ::ev/event {::ev/name "add-asset-to-library"
|
||||||
|
:asset-type "typography"}))))
|
||||||
|
|
||||||
handle-change
|
handle-change
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps file-id)
|
(mf/deps file-id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue