mirror of
https://github.com/penpot/penpot.git
synced 2025-02-01 20:09:04 -05: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.types.shape :as cts]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[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]]
|
[app.main.ui.workspace.tokens.common :refer [workspace-shapes]]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[clojure.data :as data]
|
[clojure.data :as data]
|
||||||
|
[cuerdas.core :as str]
|
||||||
[potok.v2.core :as ptk]))
|
[potok.v2.core :as ptk]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -65,6 +68,11 @@
|
||||||
next-applied-tokens (toggle-or-apply-token shape token)]
|
next-applied-tokens (toggle-or-apply-token shape token)]
|
||||||
(rx/of (update-shape shape-id {:applied-tokens next-applied-tokens}))))))
|
(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
|
(defn add-token
|
||||||
[token]
|
[token]
|
||||||
(let [token (update token :id #(or % (uuid/next)))]
|
(let [token (update token :id #(or % (uuid/next)))]
|
||||||
|
@ -87,6 +95,16 @@
|
||||||
(pcb/delete-token id))]
|
(pcb/delete-token id))]
|
||||||
(rx/of (dch/commit-changes changes))))))
|
(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)
|
;; TEMP (Move to test)
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
(mf/defc token-pill-context-menu
|
(mf/defc token-pill-context-menu
|
||||||
[{:keys [token-id]}]
|
[{:keys [token-id]}]
|
||||||
(let [do-delete #(st/emit! (dt/delete-token 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")]
|
do-edit #(js/console.log "Editing")]
|
||||||
[:*
|
[:*
|
||||||
[:& menu-entry {:title "Delete Token" :on-click do-delete}]
|
[:& menu-entry {:title "Delete Token" :on-click do-delete}]
|
||||||
|
|
Loading…
Add table
Reference in a new issue