0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 06:02:32 -05:00

Fix token deletion menu

This commit is contained in:
Florian Schroedl 2024-09-30 09:19:06 +02:00
parent cfec4ae958
commit a59e391b38
7 changed files with 22 additions and 54 deletions

View file

@ -779,10 +779,12 @@
(apply-changes-local)))
(defn delete-token
[changes set-name token-id token-name]
[changes set-name token-name]
(assert-library! changes)
(let [library-data (::library-data (meta changes))
prev-token (get-in library-data [:tokens token-id])]
prev-token (some-> (get library-data :tokens-lib)
(ctob/get-set set-name)
(ctob/get-token token-name))]
(-> changes
(update :redo-changes conj {:type :del-token :set-name set-name :name token-name})
(update :undo-changes conj {:type :add-token :set-name set-name :token prev-token})

View file

@ -63,7 +63,7 @@
[:name token-name-ref]
[:type [::sm/one-of token-types]]
[:value :any]
[:description {:optional true} :string]
[:description {:optional true} [:maybe :string]]
[:modified-at {:optional true} ::sm/inst]])
(sm/register! ::color

View file

@ -260,17 +260,16 @@
(dch/commit-changes changes))))))
(defn delete-token
[set-name id name]
[set-name token-name]
(dm/assert! (string? set-name))
(dm/assert! (uuid? id))
(dm/assert! (string? name))
(dm/assert! (string? token-name))
(ptk/reify ::delete-token
ptk/WatchEvent
(watch [it state _]
(let [data (get state :workspace-data)
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/delete-token set-name id name))]
(pcb/delete-token set-name token-name))]
(rx/of (dch/commit-changes changes))))))
(defn duplicate-token
@ -280,42 +279,6 @@
(update :name #(str/concat % "-copy")))]
(update-create-token new-token)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TEMP (Move to test)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(comment
(def shape-1 {:r3 3})
(def token-1 {:rx 1
:ry 1})
(def shape-after-token-1-is-applied {:rx 1
:ry 1
:r3 3})
(def token-2 {:r3 1})
(def shape-after-token-2-is-applied {:rx 1
:ry 1
:r3 1})
(def token-3 {:r3 1})
(def shape-after-token-3-is-applied {:rx 1
:ry 1})
(= (toggle-or-apply-token shape-1 token-1)
shape-after-token-1-is-applied)
(= (toggle-or-apply-token shape-after-token-1-is-applied token-2)
shape-after-token-2-is-applied)
(= (toggle-or-apply-token shape-after-token-2-is-applied token-3)
shape-after-token-3-is-applied)
nil)
(defn set-token-type-section-open
[token-type open?]
(ptk/reify ::set-token-type-section-open
@ -326,7 +289,7 @@
;; Token Context Menu Functions -------------------------------------------------
(defn show-token-context-menu
[{:keys [position _token-id] :as params}]
[{:keys [position _token-name] :as params}]
(dm/assert! (gpt/point? position))
(ptk/reify ::show-token-context-menu
ptk/UpdateEvent
@ -340,7 +303,7 @@
(assoc-in state [:workspace-local :token-context-menu] nil))))
(defn show-token-set-context-menu
[{:keys [position _token-set-id] :as params}]
[{:keys [position _token-set-name] :as params}]
(dm/assert! (gpt/point? position))
(ptk/reify ::show-token-set-context-menu
ptk/UpdateEvent

View file

@ -492,6 +492,13 @@
(def workspace-active-theme-sets-tokens
(l/derived #(or (some-> % ctob/get-active-themes-set-tokens) {}) tokens-lib))
(def workspace-selected-token-set-token
(fn [token-name]
(l/derived
#(some-> (wtts/get-selected-token-set %)
(ctob/get-token token-name))
st/state)))
(def workspace-selected-token-set-tokens
(l/derived #(or (wtts/get-selected-token-set-tokens %) {}) st/state))

View file

@ -202,16 +202,14 @@
(generic-attribute-actions #{:y} "Y" (assoc context-data :on-update-shape wtch/update-shape-position))))}))
(defn default-actions [{:keys [token selected-token-set-id]}]
(let [{:keys [modal]} (wtty/get-token-properties token)
selected-token-set (dt/get-token-set-data-from-token-set-id selected-token-set-id)]
(let [{:keys [modal]} (wtty/get-token-properties token)]
[{:title "Delete Token"
:action #(st/emit! (dt/delete-token (:name selected-token-set) (:id token) (:name token)))}
:action #(st/emit! (dt/delete-token selected-token-set-id (:name token)))}
{:title "Duplicate Token"
:action #(st/emit! (dt/duplicate-token (:id token)))}
:action #(st/emit! (dt/duplicate-token (:name token)))}
{:title "Edit Token"
:action (fn [event]
(let [{:keys [key fields]} modal
token (dt/get-token-data-from-token-id (:id token))]
(let [{:keys [key fields]} modal]
(st/emit! dt/hide-token-context-menu)
(dom/stop-propagation event)
(modal/show! key {:x (.-clientX ^js event)
@ -303,7 +301,6 @@
(mf/defc token-context-menu-tree
[{:keys [width] :as mdata}]
(js/console.log "mdata" mdata)
(let [objects (mf/deref refs/workspace-page-objects)
selected (mf/deref refs/selected-shapes)
selected-shapes (into [] (keep (d/getf objects)) selected)

View file

@ -93,7 +93,6 @@
(st/emit!
(wdt/show-token-set-context-menu
{:position (dom/get-client-position event)
:token-set-id name
:token-set-name name})))))]
[:div {:class (stl/css :set-item-container)
:on-click on-select

View file

@ -96,7 +96,7 @@
(dom/stop-propagation event)
(st/emit! (dt/show-token-context-menu {:type :token
:position (dom/get-client-position event)
:token-id (:id token)}))))
:token-name (:name token)}))))
on-toggle-open-click (mf/use-fn
(mf/deps open? tokens)