mirror of
https://github.com/penpot/penpot.git
synced 2025-04-06 12:01:19 -05:00
✨ Close plugin on esc button
This commit is contained in:
parent
1779fd3e8b
commit
1e68d4ec87
2 changed files with 47 additions and 2 deletions
|
@ -6,14 +6,32 @@
|
|||
|
||||
(ns app.main.data.plugins
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.register :as pr]
|
||||
[app.util.globals :as ug]
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(defn save-current-plugin
|
||||
[id]
|
||||
(ptk/reify ::save-current-plugin
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(update-in state [:workspace-local :open-plugins] (fnil conj #{}) id))))
|
||||
|
||||
(defn remove-current-plugin
|
||||
[id]
|
||||
(ptk/reify ::remove-current-plugin
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(update-in state [:workspace-local :open-plugins] (fnil disj #{}) id))))
|
||||
|
||||
(defn open-plugin!
|
||||
[{:keys [plugin-id name description host code icon permissions]}]
|
||||
(try
|
||||
(st/emit! (save-current-plugin plugin-id))
|
||||
(.ɵloadPlugin
|
||||
^js ug/global
|
||||
#js {:pluginId plugin-id
|
||||
|
@ -22,8 +40,12 @@
|
|||
:host host
|
||||
:code code
|
||||
:icon icon
|
||||
:permissions (apply array permissions)})
|
||||
:permissions (apply array permissions)}
|
||||
(fn []
|
||||
(st/emit! (remove-current-plugin plugin-id))))
|
||||
|
||||
(catch :default e
|
||||
(st/emit! (remove-current-plugin plugin-id))
|
||||
(.error js/console "Error" e))))
|
||||
|
||||
(defn close-plugin!
|
||||
|
@ -33,6 +55,15 @@
|
|||
(catch :default e
|
||||
(.error js/console "Error" e))))
|
||||
|
||||
(defn close-current-plugin
|
||||
[]
|
||||
(ptk/reify ::close-current-plugin
|
||||
ptk/EffectEvent
|
||||
(effect [_ state _]
|
||||
(let [ids (dm/get-in state [:workspace-local :open-plugins])]
|
||||
(doseq [id ids]
|
||||
(close-plugin! (pr/get-plugin id)))))))
|
||||
|
||||
(defn delay-open-plugin
|
||||
[plugin]
|
||||
(ptk/reify ::delay-open-plugin
|
||||
|
|
|
@ -6,9 +6,11 @@
|
|||
|
||||
(ns app.main.data.workspace.shortcuts
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.main.data.events :as ev]
|
||||
[app.main.data.exports :as de]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.data.plugins :as dpl]
|
||||
[app.main.data.preview :as dp]
|
||||
[app.main.data.shortcuts :as ds]
|
||||
[app.main.data.users :as du]
|
||||
|
@ -28,6 +30,7 @@
|
|||
[app.main.store :as st]
|
||||
[app.main.ui.hooks.resize :as r]
|
||||
[app.util.dom :as dom]
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -44,6 +47,17 @@
|
|||
(when-not (deref refs/workspace-read-only?)
|
||||
(run! st/emit! events)))
|
||||
|
||||
(def esc-pressed
|
||||
(ptk/reify ::esc-pressed
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(rx/of
|
||||
:interrupt
|
||||
(let [selection (dm/get-in state [:workspace-local :selected])]
|
||||
(if (empty? selection)
|
||||
(dpl/close-current-plugin)
|
||||
(dw/deselect-all true)))))))
|
||||
|
||||
;; Shortcuts format https://github.com/ccampbell/mousetrap
|
||||
|
||||
(def base-shortcuts
|
||||
|
@ -111,7 +125,7 @@
|
|||
:escape {:tooltip (ds/esc)
|
||||
:command "escape"
|
||||
:subsections [:edit]
|
||||
:fn #(st/emit! :interrupt (dw/deselect-all true))}
|
||||
:fn #(st/emit! esc-pressed)}
|
||||
|
||||
|
||||
;; MODIFY LAYERS
|
||||
|
|
Loading…
Add table
Reference in a new issue