diff --git a/frontend/src/app/main/data/plugins.cljs b/frontend/src/app/main/data/plugins.cljs index 905908fa2b..5bdcdb776e 100644 --- a/frontend/src/app/main/data/plugins.cljs +++ b/frontend/src/app/main/data/plugins.cljs @@ -53,7 +53,7 @@ (defn set-plugin-flag [id key value] - (ptk/reify ::reset-plugin-flags + (ptk/reify ::set-plugin-flag ptk/UpdateEvent (update [_ state] (update-in state [:workspace-local :plugin-flags id] assoc key value)))) diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index cd4cfff542..cd9aeef756 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -41,6 +41,7 @@ [app.plugins.page :as page] [app.plugins.parser :as parser] [app.plugins.shape :as shape] + [app.plugins.system-events :as se] [app.plugins.user :as user] [app.plugins.utils :as u] [app.plugins.viewport :as viewport] @@ -66,7 +67,10 @@ (cb/with-objects (:objects page)) (cb/add-object shape))] - (st/emit! (ch/commit-changes changes)) + (st/emit! + (ch/commit-changes changes) + (se/event plugin-id "create-shape" :type type)) + (shape/shape-proxy plugin-id (:id shape)))) (defn create-context @@ -289,7 +293,8 @@ page-id (:current-page-id @st/state) id (uuid/next) ids (into #{} (map #(obj/get % "$id")) shapes)] - (st/emit! (dwg/group-shapes id ids)) + (st/emit! (dwg/group-shapes id ids) + (se/event plugin-id "create-shape" :type type)) (shape/shape-proxy plugin-id file-id page-id id)))) :ungroup @@ -331,7 +336,8 @@ (cb/with-objects (:objects page)) (cb/add-object shape))] - (st/emit! (ch/commit-changes changes)) + (st/emit! (ch/commit-changes changes) + (se/event plugin-id "create-shape" :type :path)) (shape/shape-proxy plugin-id (:id shape)))) :createText @@ -352,7 +358,9 @@ (cb/with-objects (:objects page)) (cb/add-object shape))] - (st/emit! (ch/commit-changes changes)) + (st/emit! + (ch/commit-changes changes) + (se/event plugin-id "create-shape" :type :text)) (shape/shape-proxy plugin-id (:id shape))))) :createShapeFromSvg @@ -365,7 +373,8 @@ (let [id (uuid/next) file-id (:current-file-id @st/state) page-id (:current-page-id @st/state)] - (st/emit! (dwm/create-svg-shape id "svg" svg-string (gpt/point 0 0))) + (st/emit! (dwm/create-svg-shape id "svg" svg-string (gpt/point 0 0)) + (se/event plugin-id "create-shape" :type :svg)) (shape/shape-proxy plugin-id file-id page-id id)))) :createShapeFromSvgWithImages @@ -385,7 +394,8 @@ (st/emit! (dwm/create-svg-shape-with-images file-id id "svg" svg-string (gpt/point 0 0) #(resolve (shape/shape-proxy plugin-id file-id page-id id)) - reject))))))) + reject) + (se/event plugin-id "create-shape" :type :text))))))) :createBoolean (fn [bool-type shapes] @@ -400,7 +410,8 @@ :else (let [ids (into #{} (map #(obj/get % "$id")) shapes) shape-id (uuid/next)] - (st/emit! (dwb/create-bool bool-type :ids ids :force-shape-id shape-id)) + (st/emit! (dwb/create-bool bool-type :ids ids :force-shape-id shape-id) + (se/event plugin-id "create-shape" :type :boolean)) (shape/shape-proxy plugin-id shape-id))))) :generateMarkup diff --git a/frontend/src/app/plugins/system_events.cljs b/frontend/src/app/plugins/system_events.cljs new file mode 100644 index 0000000000..e8816cdfc3 --- /dev/null +++ b/frontend/src/app/plugins/system_events.cljs @@ -0,0 +1,23 @@ +;; 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.plugins.system-events + (:require + [app.main.data.event :as ev] + [app.main.store :as st])) + +;; Formats an event from the plugin system +(defn event + [plugin-id name & {:as props}] + (let [plugin-data (get-in @st/state [:profile :props :plugins :data plugin-id])] + (-> props + (assoc ::ev/name name) + (assoc ::ev/origin "plugin") + (assoc ::ev/context + {:plugin-name (:name plugin-data) + :plugin-url (:url plugin-data)}) + (ev/event)))) +