mirror of
https://github.com/penpot/penpot.git
synced 2025-01-06 14:50:20 -05:00
Merge pull request #110 from tokens-studio/duplicate-token
add functionality to duplicate token from context menu
This commit is contained in:
commit
bde2b4b3a5
2 changed files with 15 additions and 1 deletions
|
@ -12,9 +12,11 @@
|
|||
[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.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 +67,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 +94,13 @@
|
|||
(pcb/delete-token id))]
|
||||
(rx/of (dch/commit-changes changes))))))
|
||||
|
||||
(defn duplicate-token
|
||||
[id]
|
||||
(let [new-token (-> (get-token-data-from-token-id id)
|
||||
(dissoc :id)
|
||||
(update :name #(str/concat % "-copy")))]
|
||||
(add-token new-token)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; TEMP (Move to test)
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
(mf/defc token-pill-context-menu
|
||||
[{:keys [token-id]}]
|
||||
(let [do-delete #(st/emit! (dt/delete-token token-id))
|
||||
do-duplicate #(js/console.log "Duplicating")
|
||||
do-duplicate #(st/emit! (dt/duplicate-token token-id))
|
||||
do-edit #(js/console.log "Editing")]
|
||||
[:*
|
||||
[:& menu-entry {:title "Delete Token" :on-click do-delete}]
|
||||
|
|
Loading…
Reference in a new issue