diff --git a/common/src/app/common/schema.cljc b/common/src/app/common/schema.cljc index 425525ca30..fcb516c3c0 100644 --- a/common/src/app/common/schema.cljc +++ b/common/src/app/common/schema.cljc @@ -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? diff --git a/common/src/app/common/types/color.cljc b/common/src/app/common/types/color.cljc index dea0ee6fc1..aabb2b3ae9 100644 --- a/common/src/app/common/types/color.cljc +++ b/common/src/app/common/types/color.cljc @@ -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 diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 0313870b66..8c62801d4d 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -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)) diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index c8c7fbe432..4dcd6905e3 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -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)) diff --git a/common/src/app/common/types/page.cljc b/common/src/app/common/types/page.cljc index 3e31540dbc..45ab722b10 100644 --- a/common/src/app/common/types/page.cljc +++ b/common/src/app/common/types/page.cljc @@ -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)) diff --git a/common/src/app/common/types/plugins.cljc b/common/src/app/common/types/plugins.cljc new file mode 100644 index 0000000000..82affb339f --- /dev/null +++ b/common/src/app/common/types/plugins.cljc @@ -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]) diff --git a/common/src/app/common/types/shape.cljc b/common/src/app/common/types/shape.cljc index e22353e750..38e172d825 100644 --- a/common/src/app/common/types/shape.cljc +++ b/common/src/app/common/types/shape.cljc @@ -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"} diff --git a/common/src/app/common/types/typography.cljc b/common/src/app/common/types/typography.cljc index 2e5a08b93a..02e7fc6f6c 100644 --- a/common/src/app/common/types/typography.cljc +++ b/common/src/app/common/types/typography.cljc @@ -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)) diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index bd0071602e..87346de670 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -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 diff --git a/frontend/src/app/main/ui/workspace/main_menu.cljs b/frontend/src/app/main/ui/workspace/main_menu.cljs index 135cdc1b59..ea0fc54f41 100644 --- a/frontend/src/app/main/ui/workspace/main_menu.cljs +++ b/frontend/src/app/main/ui/workspace/main_menu.cljs @@ -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 {}))))] [:* diff --git a/frontend/src/app/main/ui/workspace/plugins.cljs b/frontend/src/app/main/ui/workspace/plugins.cljs index 53c41282a6..7a71cf4a00 100644 --- a/frontend/src/app/main/ui/workspace/plugins.cljs +++ b/frontend/src/app/main/ui/workspace/plugins.cljs @@ -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)} diff --git a/frontend/src/app/main/ui/workspace/top_toolbar.cljs b/frontend/src/app/main/ui/workspace/top_toolbar.cljs index dfbb3fe1ae..82e3444452 100644 --- a/frontend/src/app/main/ui/workspace/top_toolbar.cljs +++ b/frontend/src/app/main/ui/workspace/top_toolbar.cljs @@ -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]])