Merge pull request #4849 from penpot/alotor-plugins-6

 Add events for plugins
This commit is contained in:
Andrey Antukh 2024-07-04 17:17:38 +02:00 committed by GitHub
commit 6f8ce1fc5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 75 additions and 19 deletions

View file

@ -907,10 +907,6 @@
::oapi/format "password"}})
;; FIXME: this should not be here
(define! ::plugin-data
[:map-of {:gen/max 5} :string :string])
;; ---- PREDICATES
(def valid-safe-number?

View file

@ -14,6 +14,7 @@
[app.common.types.color.generic :as-alias color-generic]
[app.common.types.color.gradient :as-alias color-gradient]
[app.common.types.color.gradient.stop :as-alias color-gradient-stop]
[app.common.types.plugins :as ctpg]
[app.common.uuid :as uuid]
[clojure.test.check.generators :as tgen]
[cuerdas.core :as str]))
@ -88,7 +89,7 @@
[:gradient {:optional true} [:maybe ::gradient]]
[:image {:optional true} [:maybe ::image-color]]
[:plugin-data {:optional true}
[:map-of {:gen/max 5} :keyword ::sm/plugin-data]]]
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]]
[::sm/contains-any {:strict true} [:color :gradient :image]]])
(sm/define! ::recent-color

View file

@ -15,6 +15,7 @@
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
[app.common.types.pages-list :as ctpl]
[app.common.types.plugins :as ctpg]
[app.common.types.shape-tree :as ctst]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]))
@ -37,7 +38,7 @@
[:objects {:optional true}
[:map-of {:gen/max 10} ::sm/uuid :map]]
[:plugin-data {:optional true}
[:map-of {:gen/max 5} :keyword ::sm/plugin-data]]])
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]])
(def check-container!
(sm/check-fn ::container))

View file

@ -24,6 +24,7 @@
[app.common.types.container :as ctn]
[app.common.types.page :as ctp]
[app.common.types.pages-list :as ctpl]
[app.common.types.plugins :as ctpg]
[app.common.types.shape-tree :as ctst]
[app.common.types.typographies-list :as ctyl]
[app.common.types.typography :as cty]
@ -59,7 +60,7 @@
[:media {:optional true}
[:map-of {:gen/max 5} ::sm/uuid ::media-object]]
[:plugin-data {:optional true}
[:map-of {:gen/max 5} :keyword ::sm/plugin-data]]])
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]])
(def check-file-data!
(sm/check-fn ::data))

View file

@ -10,6 +10,7 @@
[app.common.schema :as sm]
[app.common.types.color :as-alias ctc]
[app.common.types.grid :as ctg]
[app.common.types.plugins :as ctpg]
[app.common.types.shape :as cts]
[app.common.uuid :as uuid]))
@ -45,7 +46,7 @@
[:guides {:optional true}
[:map-of {:gen/max 2} ::sm/uuid ::guide]]
[:plugin-data {:optional true}
[:map-of {:gen/max 5} :keyword ::sm/plugin-data]]]]])
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]]]])
(def check-page-guide!
(sm/check-fn ::guide))

View file

@ -0,0 +1,16 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.types.plugins
(:require
[app.common.schema :as sm]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SCHEMAS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(sm/define! ::plugin-data
[:map-of {:gen/max 5} :string :string])

View file

@ -20,6 +20,7 @@
[app.common.transit :as t]
[app.common.types.color :as ctc]
[app.common.types.grid :as ctg]
[app.common.types.plugins :as ctpg]
[app.common.types.shape.attrs :refer [default-color]]
[app.common.types.shape.blur :as ctsb]
[app.common.types.shape.export :as ctse]
@ -188,7 +189,7 @@
[:grow-type {:optional true}
[::sm/one-of #{:auto-width :auto-height :fixed}]]
[:plugin-data {:optional true}
[:map-of {:gen/max 5} :keyword ::sm/plugin-data]]])
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]])
(sm/define! ::group-attrs
[:map {:title "GroupAttrs"}

View file

@ -9,6 +9,7 @@
[app.common.data :as d]
[app.common.schema :as sm]
[app.common.text :as txt]
[app.common.types.plugins :as ctpg]
[app.common.uuid :as uuid]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -31,7 +32,7 @@
[:modified-at {:optional true} ::sm/inst]
[:path {:optional true} [:maybe :string]]
[:plugin-data {:optional true}
[:map-of {:gen/max 5} :keyword ::sm/plugin-data]]])
[:map-of {:gen/max 5} :keyword ::ctpg/plugin-data]]])
(def check-typography!
(sm/check-fn ::typography))

View file

@ -27,7 +27,8 @@
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.hooks.resize :as r]
[app.util.dom :as dom]))
[app.util.dom :as dom]
[potok.v2.core :as ptk]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Shortcuts
@ -563,7 +564,9 @@
:command (ds/c-mod "alt+p")
:subsections [:basics]
: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
;; PREVIEW

View file

@ -630,13 +630,23 @@
(when (d/not-empty? plugins)
[: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)
: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)
:on-key-down (fn [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]])])))
(mf/defc menu
@ -699,7 +709,9 @@
(dom/stop-propagation event)
(reset! show-menu* false)
(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.macros :as dm]
[app.config :as cf]
[app.main.data.events :as ev]
[app.main.data.modal :as modal]
[app.main.store :as st]
[app.main.ui.components.search-bar :refer [search-bar]]
@ -21,6 +22,8 @@
[app.util.http :as http]
[app.util.i18n :as i18n :refer [tr]]
[beicon.v2.core :as rx]
[cuerdas.core :as str]
[potok.v2.core :as ptk]
[rumext.v2 :as mf]))
(def ^:private close-icon
@ -111,6 +114,7 @@
(rx/subs!
(fn [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!
:plugin-permissions
{:plugin plugin
@ -126,6 +130,10 @@
handle-open-plugin
(mf/use-callback
(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)
(modal/hide!)))
@ -134,6 +142,9 @@
(mf/deps plugins-state)
(fn [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)
(reset! plugins-state* @plugins/pluginsdb))))]
@ -162,7 +173,10 @@
[:div {:class (stl/css :plugins-empty)}
[:div {:class (stl/css :plugins-empty-logo)} i/puzzle]
[: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]]
[:*
@ -182,7 +196,7 @@
::mf/register-as :plugin-permissions}
[{:keys [plugin on-accept]}]
(let [{:keys [permissions]} plugin
(let [{:keys [host permissions]} plugin
permissions (set permissions)
handle-accept-dialog
@ -190,12 +204,18 @@
(fn [event]
(dom/prevent-default event)
(st/emit! (modal/hide))
(ptk/event ::ev/event {::ev/name "allow-plugin-permissions"
:host host
:permissions (->> permissions (str/join ", "))})
(on-accept)))
handle-close-dialog
(mf/use-callback
(fn [event]
(dom/prevent-default event)
(ptk/event ::ev/event {::ev/name "reject-plugin-permissions"
:host host
:permissions (->> permissions (str/join ", "))})
(st/emit! (modal/hide))))]
[:div {:class (stl/css :modal-overlay)}

View file

@ -27,6 +27,7 @@
[app.util.i18n :as i18n :refer [tr]]
[app.util.timers :as ts]
[okulary.core :as l]
[potok.v2.core :as ptk]
[rumext.v2 :as mf]))
(mf/defc image-upload
@ -200,7 +201,9 @@
{:title (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)
: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-testid "plugins-btn"}
i/puzzle]])