mirror of
https://github.com/penpot/penpot.git
synced 2025-06-09 23:51:38 +02:00
ad functionality to duplicate token from context menu
This commit is contained in:
parent
3e7a422136
commit
e1ae3d55af
2 changed files with 19 additions and 1 deletions
|
@ -12,9 +12,12 @@
|
|||
[app.common.types.shape :as cts]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.workspace.tokens.common :refer [workspace-shapes]]
|
||||
[beicon.v2.core :as rx]
|
||||
[clojure.data :as data]
|
||||
[cuerdas.core :as str]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -65,6 +68,11 @@
|
|||
next-applied-tokens (toggle-or-apply-token shape token)]
|
||||
(rx/of (update-shape shape-id {:applied-tokens next-applied-tokens}))))))
|
||||
|
||||
(defn get-token-data-from-token-id
|
||||
[id]
|
||||
(let [workspace-data (deref refs/workspace-data)]
|
||||
(get (:tokens workspace-data) id)))
|
||||
|
||||
(defn add-token
|
||||
[token]
|
||||
(let [token (update token :id #(or % (uuid/next)))]
|
||||
|
@ -87,6 +95,16 @@
|
|||
(pcb/delete-token id))]
|
||||
(rx/of (dch/commit-changes changes))))))
|
||||
|
||||
(defn duplicate-token
|
||||
[id]
|
||||
(let [token-data (get-token-data-from-token-id id)
|
||||
duplicate-token-name (str/concat (:name token-data) "-copy")
|
||||
duplicate-token {:name duplicate-token-name
|
||||
:value (:value token-data)
|
||||
:type (:type token-data)
|
||||
:description (or (:description token-data) "")}]
|
||||
(st/emit! (add-token duplicate-token))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; TEMP (Move to test)
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue