mirror of
https://github.com/penpot/penpot.git
synced 2025-02-08 08:09:14 -05:00
move context menu functions to data/tokens
This commit is contained in:
parent
8cb9d9c352
commit
fcd7a35b46
4 changed files with 38 additions and 43 deletions
|
@ -8,6 +8,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.files.changes-builder :as pcb]
|
[app.common.files.changes-builder :as pcb]
|
||||||
|
[app.common.geom.point :as gpt]
|
||||||
[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]
|
||||||
|
@ -108,3 +109,31 @@
|
||||||
(= (toggle-or-apply-token shape-after-token-2-is-applied token-3)
|
(= (toggle-or-apply-token shape-after-token-2-is-applied token-3)
|
||||||
shape-after-token-3-is-applied)
|
shape-after-token-3-is-applied)
|
||||||
nil)
|
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))))))
|
|
@ -7,12 +7,6 @@
|
||||||
(ns app.main.ui.workspace.tokens.common
|
(ns app.main.ui.workspace.tokens.common
|
||||||
(:require-macros [app.main.style :as stl])
|
(:require-macros [app.main.style :as stl])
|
||||||
(:require
|
(: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]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
;; Helpers ---------------------------------------------------------------------
|
;; Helpers ---------------------------------------------------------------------
|
||||||
|
@ -45,31 +39,3 @@
|
||||||
:default-value default-value
|
:default-value default-value
|
||||||
:autoFocus auto-focus?
|
:autoFocus auto-focus?
|
||||||
:on-change on-change}]])
|
: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))))))
|
|
|
@ -12,12 +12,12 @@
|
||||||
[app.main.data.events :as ev]
|
[app.main.data.events :as ev]
|
||||||
[app.main.data.modal :as modal]
|
[app.main.data.modal :as modal]
|
||||||
[app.main.data.shortcuts :as scd]
|
[app.main.data.shortcuts :as scd]
|
||||||
|
[app.main.data.tokens :as dt]
|
||||||
[app.main.data.workspace :as dw]
|
[app.main.data.workspace :as dw]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.components.dropdown :refer [dropdown]]
|
[app.main.ui.components.dropdown :refer [dropdown]]
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
[app.main.ui.workspace.tokens.common :as tcm]
|
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.timers :as timers]
|
[app.util.timers :as timers]
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
|
@ -114,7 +114,7 @@
|
||||||
|
|
||||||
(mf/defc token-pill-context-menu
|
(mf/defc token-pill-context-menu
|
||||||
[{:keys [token-id]}]
|
[{: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
|
do-delete #(st/emit! (modal/show
|
||||||
{:type :confirm
|
{:type :confirm
|
||||||
:title "Delete"
|
:title "Delete"
|
||||||
|
@ -148,7 +148,7 @@
|
||||||
(.setAttribute ^js dropdown "style" new-style))))))
|
(.setAttribute ^js dropdown "style" new-style))))))
|
||||||
|
|
||||||
[:& dropdown {:show (boolean mdata)
|
[:& 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)
|
[:div {:class (stl/css :token-context-menu)
|
||||||
:ref dropdown-ref
|
:ref dropdown-ref
|
||||||
:style {:top top :left left}
|
:style {:top top :left left}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
[app.main.ui.components.search-bar :refer [search-bar]]
|
[app.main.ui.components.search-bar :refer [search-bar]]
|
||||||
[app.main.ui.icons :as i]
|
[app.main.ui.icons :as i]
|
||||||
[app.main.ui.workspace.sidebar.assets.common :as cmm]
|
[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.main.ui.workspace.tokens.core :refer [tokens-applied?] :as wtc]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
(fn [event token]
|
(fn [event token]
|
||||||
(dom/prevent-default event)
|
(dom/prevent-default event)
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(st/emit! (tcm/show-token-context-menu {:type :token
|
(st/emit! (dt/show-token-context-menu {:type :token
|
||||||
:position (dom/get-client-position event)
|
:position (dom/get-client-position event)
|
||||||
:token-id (:id token)}))))
|
:token-id (:id token)}))))
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
token-groups (mf/with-memo [tokens]
|
token-groups (mf/with-memo [tokens]
|
||||||
(sorted-token-groups tokens))
|
(sorted-token-groups tokens))
|
||||||
selected-shape-ids (mf/deref refs/selected-shapes)
|
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
|
[:article
|
||||||
[:div.assets-bar
|
[:div.assets-bar
|
||||||
(for [{:keys [token-key token-type-props tokens]} (concat (:filled token-groups)
|
(for [{:keys [token-key token-type-props tokens]} (concat (:filled token-groups)
|
||||||
|
|
Loading…
Add table
Reference in a new issue