mirror of
https://github.com/penpot/penpot.git
synced 2025-07-19 05:47:19 +02: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
|
(ns app.main.data.plugins
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data :as d]
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
|
[app.main.store :as st]
|
||||||
[app.plugins.register :as pr]
|
[app.plugins.register :as pr]
|
||||||
[app.util.globals :as ug]
|
[app.util.globals :as ug]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[potok.v2.core :as ptk]))
|
[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!
|
(defn open-plugin!
|
||||||
[{:keys [plugin-id name description host code icon permissions]}]
|
[{:keys [plugin-id name description host code icon permissions]}]
|
||||||
(try
|
(try
|
||||||
|
(st/emit! (save-current-plugin plugin-id))
|
||||||
(.ɵloadPlugin
|
(.ɵloadPlugin
|
||||||
^js ug/global
|
^js ug/global
|
||||||
#js {:pluginId plugin-id
|
#js {:pluginId plugin-id
|
||||||
|
@ -22,8 +40,12 @@
|
||||||
:host host
|
:host host
|
||||||
:code code
|
:code code
|
||||||
:icon icon
|
:icon icon
|
||||||
:permissions (apply array permissions)})
|
:permissions (apply array permissions)}
|
||||||
|
(fn []
|
||||||
|
(st/emit! (remove-current-plugin plugin-id))))
|
||||||
|
|
||||||
(catch :default e
|
(catch :default e
|
||||||
|
(st/emit! (remove-current-plugin plugin-id))
|
||||||
(.error js/console "Error" e))))
|
(.error js/console "Error" e))))
|
||||||
|
|
||||||
(defn close-plugin!
|
(defn close-plugin!
|
||||||
|
@ -33,6 +55,15 @@
|
||||||
(catch :default e
|
(catch :default e
|
||||||
(.error js/console "Error" 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
|
(defn delay-open-plugin
|
||||||
[plugin]
|
[plugin]
|
||||||
(ptk/reify ::delay-open-plugin
|
(ptk/reify ::delay-open-plugin
|
||||||
|
|
|
@ -6,9 +6,11 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.shortcuts
|
(ns app.main.data.workspace.shortcuts
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.main.data.events :as ev]
|
[app.main.data.events :as ev]
|
||||||
[app.main.data.exports :as de]
|
[app.main.data.exports :as de]
|
||||||
[app.main.data.modal :as modal]
|
[app.main.data.modal :as modal]
|
||||||
|
[app.main.data.plugins :as dpl]
|
||||||
[app.main.data.preview :as dp]
|
[app.main.data.preview :as dp]
|
||||||
[app.main.data.shortcuts :as ds]
|
[app.main.data.shortcuts :as ds]
|
||||||
[app.main.data.users :as du]
|
[app.main.data.users :as du]
|
||||||
|
@ -28,6 +30,7 @@
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.hooks.resize :as r]
|
[app.main.ui.hooks.resize :as r]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
|
[beicon.v2.core :as rx]
|
||||||
[potok.v2.core :as ptk]))
|
[potok.v2.core :as ptk]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -44,6 +47,17 @@
|
||||||
(when-not (deref refs/workspace-read-only?)
|
(when-not (deref refs/workspace-read-only?)
|
||||||
(run! st/emit! events)))
|
(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
|
;; Shortcuts format https://github.com/ccampbell/mousetrap
|
||||||
|
|
||||||
(def base-shortcuts
|
(def base-shortcuts
|
||||||
|
@ -111,7 +125,7 @@
|
||||||
:escape {:tooltip (ds/esc)
|
:escape {:tooltip (ds/esc)
|
||||||
:command "escape"
|
:command "escape"
|
||||||
:subsections [:edit]
|
:subsections [:edit]
|
||||||
:fn #(st/emit! :interrupt (dw/deselect-all true))}
|
:fn #(st/emit! esc-pressed)}
|
||||||
|
|
||||||
|
|
||||||
;; MODIFY LAYERS
|
;; MODIFY LAYERS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue