0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-26 00:19:07 -05:00

Add events for plugins

This commit is contained in:
alonso.torres 2024-07-04 15:05:28 +02:00
parent d1dd13fde9
commit 53d3b2abbc
4 changed files with 47 additions and 9 deletions

View file

@ -27,7 +27,8 @@
[app.main.refs :as refs] [app.main.refs :as refs]
[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]
[potok.v2.core :as ptk]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Shortcuts ;; Shortcuts
@ -563,7 +564,9 @@
:command (ds/c-mod "alt+p") :command (ds/c-mod "alt+p")
:subsections [:basics] :subsections [:basics]
:fn #(when (features/active-feature? @st/state "plugins/runtime") :fn #(when (features/active-feature? @st/state "plugins/runtime")
(st/emit! (modal/show :plugin-management {})))}}) (st/emit!
(ptk/event ::ev/event {::ev/name "open-plugins-manager" ::ev/origin "workspace:shortcuts"})
(modal/show :plugin-management {})))}})
(def debug-shortcuts (def debug-shortcuts
;; PREVIEW ;; PREVIEW

View file

@ -630,13 +630,23 @@
(when (d/not-empty? plugins) (when (d/not-empty? plugins)
[:div {:class (stl/css :separator)}]) [:div {:class (stl/css :separator)}])
(for [[idx {:keys [name] :as manifest}] (d/enumerate plugins)] (for [[idx {:keys [name host] :as manifest}] (d/enumerate plugins)]
[:> dropdown-menu-item* {:key (dm/str "plugins-menu-" idx) [:> dropdown-menu-item* {:key (dm/str "plugins-menu-" idx)
:on-click #(uwp/open-plugin! manifest) :on-click #(do
(st/emit! (ptk/event ::ev/event {::ev/name "start-plugin"
::ev/origin "workspace:menu"
:name name
:host host}))
(uwp/open-plugin! manifest))
:class (stl/css :submenu-item) :class (stl/css :submenu-item)
:on-key-down (fn [event] :on-key-down (fn [event]
(when (kbd/enter? event) (when (kbd/enter? event)
#(uwp/open-plugin! manifest)))} #(do
(st/emit! (ptk/event ::ev/event {::ev/name "start-plugin"
::ev/origin "workspace:menu"
:name name
:host host}))
(uwp/open-plugin! manifest))))}
[:span {:class (stl/css :item-name)} name]])]))) [:span {:class (stl/css :item-name)} name]])])))
(mf/defc menu (mf/defc menu
@ -699,7 +709,9 @@
(dom/stop-propagation event) (dom/stop-propagation event)
(reset! show-menu* false) (reset! show-menu* false)
(reset! sub-menu* nil) (reset! sub-menu* nil)
(st/emit! (modal/show :plugin-management {}))))] (st/emit!
(ptk/event ::ev/event {::ev/name "open-plugins-manager" ::ev/origin "workspace:menu"})
(modal/show :plugin-management {}))))]
[:* [:*

View file

@ -10,6 +10,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.config :as cf] [app.config :as cf]
[app.main.data.events :as ev]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.search-bar :refer [search-bar]] [app.main.ui.components.search-bar :refer [search-bar]]
@ -21,6 +22,8 @@
[app.util.http :as http] [app.util.http :as http]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[cuerdas.core :as str]
[potok.v2.core :as ptk]
[rumext.v2 :as mf])) [rumext.v2 :as mf]))
(def ^:private close-icon (def ^:private close-icon
@ -111,6 +114,7 @@
(rx/subs! (rx/subs!
(fn [body] (fn [body]
(let [plugin (plugins/parser-manifest plugin-url body)] (let [plugin (plugins/parser-manifest plugin-url body)]
(st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url}))
(modal/show! (modal/show!
:plugin-permissions :plugin-permissions
{:plugin plugin {:plugin plugin
@ -126,6 +130,10 @@
handle-open-plugin handle-open-plugin
(mf/use-callback (mf/use-callback
(fn [manifest] (fn [manifest]
(st/emit! (ptk/event ::ev/event {::ev/name "start-plugin"
::ev/origin "workspace:plugins"
:name (:name manifest)
:host (:host manifest)}))
(open-plugin! manifest) (open-plugin! manifest)
(modal/hide!))) (modal/hide!)))
@ -134,6 +142,9 @@
(mf/deps plugins-state) (mf/deps plugins-state)
(fn [plugin-index] (fn [plugin-index]
(let [plugin (nth @plugins/pluginsdb plugin-index)] (let [plugin (nth @plugins/pluginsdb plugin-index)]
(st/emit! (ptk/event ::ev/event {::ev/name "remove-plugin"
:name (:name plugin)
:host (:host plugin)}))
(plugins/remove-plugin! plugin) (plugins/remove-plugin! plugin)
(reset! plugins-state* @plugins/pluginsdb))))] (reset! plugins-state* @plugins/pluginsdb))))]
@ -162,7 +173,10 @@
[:div {:class (stl/css :plugins-empty)} [:div {:class (stl/css :plugins-empty)}
[:div {:class (stl/css :plugins-empty-logo)} i/puzzle] [:div {:class (stl/css :plugins-empty-logo)} i/puzzle]
[:div {:class (stl/css :plugins-empty-text)} (tr "workspace.plugins.empty-plugins")] [:div {:class (stl/css :plugins-empty-text)} (tr "workspace.plugins.empty-plugins")]
[:a {:class (stl/css :plugins-link) :href cf/plugins-list-uri :target "_blank"} [:a {:class (stl/css :plugins-link)
:href cf/plugins-list-uri
:target "_blank"
:on-click #(st/emit! (ptk/event ::ev/event {::ev/name "open-plugins-list"}))}
(tr "workspace.plugins.plugin-list-link") i/external-link]] (tr "workspace.plugins.plugin-list-link") i/external-link]]
[:* [:*
@ -182,7 +196,7 @@
::mf/register-as :plugin-permissions} ::mf/register-as :plugin-permissions}
[{:keys [plugin on-accept]}] [{:keys [plugin on-accept]}]
(let [{:keys [permissions]} plugin (let [{:keys [host permissions]} plugin
permissions (set permissions) permissions (set permissions)
handle-accept-dialog handle-accept-dialog
@ -190,12 +204,18 @@
(fn [event] (fn [event]
(dom/prevent-default event) (dom/prevent-default event)
(st/emit! (modal/hide)) (st/emit! (modal/hide))
(ptk/event ::ev/event {::ev/name "allow-plugin-permissions"
:host host
:permissions (->> permissions (str/join ", "))})
(on-accept))) (on-accept)))
handle-close-dialog handle-close-dialog
(mf/use-callback (mf/use-callback
(fn [event] (fn [event]
(dom/prevent-default event) (dom/prevent-default event)
(ptk/event ::ev/event {::ev/name "reject-plugin-permissions"
:host host
:permissions (->> permissions (str/join ", "))})
(st/emit! (modal/hide))))] (st/emit! (modal/hide))))]
[:div {:class (stl/css :modal-overlay)} [:div {:class (stl/css :modal-overlay)}

View file

@ -27,6 +27,7 @@
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.timers :as ts] [app.util.timers :as ts]
[okulary.core :as l] [okulary.core :as l]
[potok.v2.core :as ptk]
[rumext.v2 :as mf])) [rumext.v2 :as mf]))
(mf/defc image-upload (mf/defc image-upload
@ -200,7 +201,9 @@
{:title (tr "workspace.toolbar.plugins" (sc/get-tooltip :plugins)) {:title (tr "workspace.toolbar.plugins" (sc/get-tooltip :plugins))
:aria-label (tr "workspace.toolbar.plugins" (sc/get-tooltip :plugins)) :aria-label (tr "workspace.toolbar.plugins" (sc/get-tooltip :plugins))
:class (stl/css :main-toolbar-options-button) :class (stl/css :main-toolbar-options-button)
:on-click #(modal/show! :plugin-management {}) :on-click #(st/emit!
(ptk/event ::ev/event {::ev/name "open-plugins-manager" ::ev/origin "workspace:toolbar"})
(modal/show :plugin-management {}))
:data-tool "plugins" :data-tool "plugins"
:data-testid "plugins-btn"} :data-testid "plugins-btn"}
i/puzzle]]) i/puzzle]])