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

move context menu functions to data/tokens

This commit is contained in:
Akshay Gupta 2024-05-15 12:59:18 +05:30
parent 8cb9d9c352
commit fcd7a35b46
4 changed files with 38 additions and 43 deletions

View file

@ -8,6 +8,7 @@
(:require
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.geom.point :as gpt]
[app.common.types.shape :as cts]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
@ -108,3 +109,31 @@
(= (toggle-or-apply-token shape-after-token-2-is-applied token-3)
shape-after-token-3-is-applied)
nil)
;; Token Context Menu Functions -------------------------------------------------
(defn show-token-context-menu
[{:keys [position token-id] :as params}]
(dm/assert! (gpt/point? position))
(ptk/reify ::show-token-context-menu
ptk/UpdateEvent
(update [_ state]
(assoc-in state [:workspace-local :token-context-menu] params))))
(def hide-token-context-menu
(ptk/reify ::hide-token-context-menu
ptk/UpdateEvent
(update [_ state]
(assoc-in state [:workspace-local :token-context-menu] nil))))
(defn delete-token
[id]
(dm/assert! (uuid? id))
(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 id))]
(rx/of (dch/commit-changes changes))))))

View file

@ -7,12 +7,6 @@
(ns app.main.ui.workspace.tokens.common
(:require-macros [app.main.style :as stl])
(:require
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.geom.point :as gpt]
[app.main.data.workspace.changes :as dch]
[beicon.v2.core :as rx]
[potok.v2.core :as ptk]
[rumext.v2 :as mf]))
;; Helpers ---------------------------------------------------------------------
@ -44,32 +38,4 @@
[:input {:ref input-ref
:default-value default-value
:autoFocus auto-focus?
:on-change on-change}]])
;; Token Context Menu Functions -------------------------------------------------
(defn show-token-context-menu
[{:keys [position token-id] :as params}]
(dm/assert! (gpt/point? position))
(ptk/reify ::show-token-context-menu
ptk/UpdateEvent
(update [_ state]
(assoc-in state [:workspace-local :token-context-menu] params))))
(def hide-token-context-menu
(ptk/reify ::hide-token-context-menu
ptk/UpdateEvent
(update [_ state]
(assoc-in state [:workspace-local :token-context-menu] nil))))
(defn delete-token
[id]
(dm/assert! (uuid? id))
(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 id))]
(rx/of (dch/commit-changes changes))))))
:on-change on-change}]])

View file

@ -12,12 +12,12 @@
[app.main.data.events :as ev]
[app.main.data.modal :as modal]
[app.main.data.shortcuts :as scd]
[app.main.data.tokens :as dt]
[app.main.data.workspace :as dw]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.components.dropdown :refer [dropdown]]
[app.main.ui.icons :as i]
[app.main.ui.workspace.tokens.common :as tcm]
[app.util.dom :as dom]
[app.util.timers :as timers]
[okulary.core :as l]
@ -114,7 +114,7 @@
(mf/defc token-pill-context-menu
[{:keys [token-id]}]
(let [delete-fn #(st/emit! (tcm/delete-token token-id))
(let [delete-fn #(st/emit! (dt/delete-token token-id))
do-delete #(st/emit! (modal/show
{:type :confirm
:title "Delete"
@ -148,7 +148,7 @@
(.setAttribute ^js dropdown "style" new-style))))))
[:& dropdown {:show (boolean mdata)
:on-close #(st/emit! tcm/hide-token-context-menu)}
:on-close #(st/emit! dt/hide-token-context-menu)}
[:div {:class (stl/css :token-context-menu)
:ref dropdown-ref
:style {:top top :left left}

View file

@ -15,7 +15,7 @@
[app.main.ui.components.search-bar :refer [search-bar]]
[app.main.ui.icons :as i]
[app.main.ui.workspace.sidebar.assets.common :as cmm]
[app.main.ui.workspace.tokens.common :as tcm]
[app.main.ui.workspace.tokens.common :refer [workspace-shapes]]
[app.main.ui.workspace.tokens.core :refer [tokens-applied?] :as wtc]
[app.util.dom :as dom]
[rumext.v2 :as mf]))
@ -54,9 +54,9 @@
(fn [event token]
(dom/prevent-default event)
(dom/stop-propagation event)
(st/emit! (tcm/show-token-context-menu {:type :token
:position (dom/get-client-position event)
:token-id (:id token)}))))
(st/emit! (dt/show-token-context-menu {:type :token
:position (dom/get-client-position event)
:token-id (:id token)}))))
on-toggle-open-click (mf/use-fn
(mf/deps open? tokens)
@ -125,7 +125,7 @@
token-groups (mf/with-memo [tokens]
(sorted-token-groups tokens))
selected-shape-ids (mf/deref refs/selected-shapes)
selected-shapes (tcm/workspace-shapes workspace-data current-page-id selected-shape-ids)]
selected-shapes (workspace-shapes workspace-data current-page-id selected-shape-ids)]
[:article
[:div.assets-bar
(for [{:keys [token-key token-type-props tokens]} (concat (:filled token-groups)