0
Fork 0
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:
Akshay Gupta 2024-05-16 17:15:59 +05:30 committed by GitHub
commit bde2b4b3a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View file

@ -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)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -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}]