mirror of
https://github.com/penpot/penpot.git
synced 2025-03-20 19:51:23 -05:00
✨ Plugins permissions review
This commit is contained in:
parent
741bf3b666
commit
395a91c00c
13 changed files with 773 additions and 171 deletions
frontend
|
@ -609,7 +609,7 @@
|
|||
::mf/wrap [mf/memo]}
|
||||
[{:keys [open-plugins on-close]}]
|
||||
(when (features/active-feature? @st/state "plugins/runtime")
|
||||
(let [plugins (plugins/load-from-store)]
|
||||
(let [plugins @plugins/pluginsdb]
|
||||
[:& dropdown-menu {:show true
|
||||
:list-class (stl/css-case :sub-menu true :plugins true)
|
||||
:on-close on-close}
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
::mf/register-as :plugin-management}
|
||||
[]
|
||||
|
||||
(let [plugins-state* (mf/use-state [])
|
||||
(let [plugins-state* (mf/use-state @plugins/pluginsdb)
|
||||
plugins-state @plugins-state*
|
||||
|
||||
plugin-url* (mf/use-state "")
|
||||
|
@ -110,20 +110,16 @@
|
|||
(rx/map :body)
|
||||
(rx/subs!
|
||||
(fn [body]
|
||||
(let [plugin (plugins/parser-manifest plugin-url body)
|
||||
new-state (vec (conj (seq plugins-state) plugin))]
|
||||
|
||||
(reset! input-status* :success)
|
||||
(reset! plugin-url* "")
|
||||
(reset! plugins-state* new-state)
|
||||
|
||||
(let [plugin (plugins/parser-manifest plugin-url body)]
|
||||
(modal/show!
|
||||
:plugin-permissions
|
||||
{:plugin plugin
|
||||
:on-accept
|
||||
#(do
|
||||
(plugins/save-to-store new-state)
|
||||
(modal/show! :plugin-management {}))})))
|
||||
(plugins/install-plugin! plugin)
|
||||
(modal/show! :plugin-management {}))})
|
||||
(reset! input-status* :success)
|
||||
(reset! plugin-url* "")))
|
||||
(fn [_]
|
||||
(reset! input-status* :error-url))))))
|
||||
|
||||
|
@ -137,17 +133,9 @@
|
|||
(mf/use-callback
|
||||
(mf/deps plugins-state)
|
||||
(fn [plugin-index]
|
||||
(let [new-state
|
||||
(into []
|
||||
(keep-indexed (fn [idx item]
|
||||
(when (not= idx plugin-index) item)))
|
||||
plugins-state)]
|
||||
(reset! plugins-state* new-state)
|
||||
(plugins/save-to-store new-state))))]
|
||||
|
||||
(mf/use-effect
|
||||
(fn []
|
||||
(reset! plugins-state* (d/nilv (plugins/load-from-store) []))))
|
||||
(let [plugin (nth @plugins/pluginsdb plugin-index)]
|
||||
(plugins/remove-plugin! plugin)
|
||||
(reset! plugins-state* @plugins/pluginsdb))))]
|
||||
|
||||
[:div {:class (stl/css :modal-overlay)}
|
||||
[:div {:class (stl/css :modal-dialog :plugin-management)}
|
||||
|
|
|
@ -12,14 +12,20 @@
|
|||
[app.main.store :as st]
|
||||
[app.plugins.api :as api]
|
||||
[app.plugins.public-utils]
|
||||
[app.plugins.register :as register]
|
||||
[app.util.globals :refer [global]]
|
||||
[app.util.object :as obj]
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(def pluginsdb register/pluginsdb)
|
||||
(def install-plugin! register/install-plugin!)
|
||||
(def remove-plugin! register/remove-plugin!)
|
||||
|
||||
(defn init-plugins-runtime!
|
||||
[]
|
||||
(when-let [init-runtime (obj/get global "initPluginsRuntime")]
|
||||
(register/init)
|
||||
(init-runtime (fn [plugin-id] (api/create-context plugin-id)))))
|
||||
|
||||
(defn initialize
|
||||
|
@ -51,18 +57,3 @@
|
|||
:code code
|
||||
:icon icon
|
||||
:permissions (->> permissions (mapv str))}))
|
||||
|
||||
(defn load-from-store
|
||||
[]
|
||||
(let [ls (.-localStorage js/window)
|
||||
plugins-val (.getItem ls "plugins")]
|
||||
(when plugins-val
|
||||
(let [plugins-js (.parse js/JSON plugins-val)]
|
||||
(js->clj plugins-js {:keywordize-keys true})))))
|
||||
|
||||
(defn save-to-store
|
||||
[plugins]
|
||||
(let [ls (.-localStorage js/window)
|
||||
plugins-js (clj->js plugins)
|
||||
plugins-val (.stringify js/JSON plugins-js)]
|
||||
(.setItem ls "plugins" plugins-val)))
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
[app.main.data.workspace :as dw]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.page :as page]
|
||||
[app.plugins.register :as r]
|
||||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]))
|
||||
|
||||
|
@ -26,7 +27,7 @@
|
|||
[self key]
|
||||
(cond
|
||||
(not (string? key))
|
||||
(u/display-not-valid :file-plugin-data-key key)
|
||||
(u/display-not-valid :getPluginData-key key)
|
||||
|
||||
:else
|
||||
(let [file (u/proxy->file self)]
|
||||
|
@ -36,10 +37,13 @@
|
|||
[_ key value]
|
||||
(cond
|
||||
(or (not (string? key)) (empty? key))
|
||||
(u/display-not-valid :file-plugin-data-key key)
|
||||
(u/display-not-valid :setPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :file-plugin-data value)
|
||||
(u/display-not-valid :setPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :setPluginData "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $id :file (keyword "plugin" (str $plugin)) key value))))
|
||||
|
@ -53,10 +57,10 @@
|
|||
[self namespace key]
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :file-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :getSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :file-plugin-data-key key)
|
||||
(u/display-not-valid :getSharedPluginData-key key)
|
||||
|
||||
:else
|
||||
(let [file (u/proxy->file self)]
|
||||
|
@ -67,13 +71,16 @@
|
|||
|
||||
(cond
|
||||
(or (not (string? namespace)) (empty? namespace))
|
||||
(u/display-not-valid :file-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :setSharedPluginData-namespace namespace)
|
||||
|
||||
(or (not (string? key)) (empty? key))
|
||||
(u/display-not-valid :file-plugin-data-key key)
|
||||
(u/display-not-valid :setSharedPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :file-plugin-data value)
|
||||
(u/display-not-valid :setSharedPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :setSharedPluginData "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $id :file (keyword "shared" namespace) key value))))
|
||||
|
@ -82,7 +89,7 @@
|
|||
[self namespace]
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :file-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :getSharedPluginDataKeys namespace)
|
||||
|
||||
:else
|
||||
(let [file (u/proxy->file self)]
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
[app.main.data.workspace.shape-layout :as dwsl]
|
||||
[app.main.data.workspace.transforms :as dwt]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.register :as r]
|
||||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
@ -58,6 +59,9 @@
|
|||
(not (contains? ctl/flex-direction-types value))
|
||||
(u/display-not-valid :dir value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :dir "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-flex-dir value}))))))}
|
||||
|
@ -71,6 +75,9 @@
|
|||
(not (contains? ctl/align-items-types value))
|
||||
(u/display-not-valid :alignItems value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :alignItems "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-align-items value}))))))}
|
||||
|
@ -84,6 +91,9 @@
|
|||
(not (contains? ctl/align-content-types value))
|
||||
(u/display-not-valid :alignContent value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :alignContent "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-align-content value}))))))}
|
||||
|
@ -97,6 +107,9 @@
|
|||
(not (contains? ctl/justify-items-types value))
|
||||
(u/display-not-valid :justifyItems value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :justifyItems "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-justify-items value}))))))}
|
||||
|
@ -110,6 +123,9 @@
|
|||
(not (contains? ctl/justify-content-types value))
|
||||
(u/display-not-valid :justifyContent value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :justifyContent "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-justify-content value}))))))}
|
||||
|
@ -122,6 +138,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :rowGap value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :rowGap "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-gap {:row-gap value}})))))}
|
||||
|
@ -134,6 +153,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :columnGap value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :columnGap "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-gap {:column-gap value}})))))}
|
||||
|
@ -146,6 +168,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :verticalPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :verticalPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p1 value :p3 value}})))))}
|
||||
|
@ -158,6 +183,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :horizontalPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :horizontalPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p2 value :p4 value}})))))}
|
||||
|
@ -171,6 +199,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :topPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :topPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p1 value}})))))}
|
||||
|
@ -183,6 +214,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :rightPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :rightPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p2 value}})))))}
|
||||
|
@ -195,6 +229,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :bottomPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :bottomPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p3 value}})))))}
|
||||
|
@ -207,6 +244,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :leftPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :leftPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p4 value}})))))})))
|
||||
|
@ -234,6 +274,9 @@
|
|||
(not (boolean? value))
|
||||
(u/display-not-valid :absolute value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :absolute "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-item-absolute value})))))}
|
||||
|
@ -246,6 +289,9 @@
|
|||
(us/safe-int? value)
|
||||
(u/display-not-valid :zIndex value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :zIndex "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-z-index value})))))}
|
||||
|
@ -259,6 +305,9 @@
|
|||
(not (contains? ctl/item-h-sizing-types value))
|
||||
(u/display-not-valid :horizontalPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :horizontalPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-h-sizing value}))))))}
|
||||
|
@ -272,6 +321,9 @@
|
|||
(not (contains? ctl/item-v-sizing-types value))
|
||||
(u/display-not-valid :verticalSizing value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :verticalSizing "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-v-sizing value}))))))}
|
||||
|
@ -285,6 +337,9 @@
|
|||
(not (contains? ctl/item-align-self-types value))
|
||||
(u/display-not-valid :alignSelf value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :alignSelf "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-align-self value}))))))}
|
||||
|
@ -297,6 +352,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :verticalMargin value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :verticalMargin "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m1 value :m3 value}})))))}
|
||||
|
@ -309,6 +367,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :horizontalMargin value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :horizontalMargin "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m2 value :m4 value}})))))}
|
||||
|
@ -321,6 +382,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :topMargin value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :topMargin "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m1 value}})))))}
|
||||
|
@ -333,6 +397,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :rightMargin value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :rightMargin "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m2 value}})))))}
|
||||
|
@ -345,6 +412,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :bottomMargin value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :bottomMargin "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m3 value}})))))}
|
||||
|
@ -357,6 +427,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :leftMargin value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :leftMargin "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-margin {:m4 value}})))))}
|
||||
|
@ -369,6 +442,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :maxWidth value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :maxWidth "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-max-w value})))))}
|
||||
|
@ -381,6 +457,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :minWidth value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :minWidth "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-min-w value})))))}
|
||||
|
@ -393,6 +472,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :maxHeight value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :maxHeight "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-max-h value})))))}
|
||||
|
@ -405,6 +487,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :minHeight value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :minHeight "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout-child #{id} {:layout-item-min-h value})))))})))
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
[app.main.data.workspace.texts :as dwt]
|
||||
[app.main.fonts :as fonts]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.register :as r]
|
||||
[app.plugins.shape :as shape]
|
||||
[app.plugins.text :as text]
|
||||
[app.plugins.utils :as u]
|
||||
|
@ -30,7 +31,8 @@
|
|||
(not (shape/shape-proxy? text))
|
||||
(u/display-not-valid :applyToText text)
|
||||
|
||||
;; TODO: Check variant inside font variants
|
||||
(not (r/check-permission (obj/get text "$plugin") "content:write"))
|
||||
(u/display-not-valid :applyToText "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get text "$id")
|
||||
|
@ -46,7 +48,8 @@
|
|||
(not (text/text-range? range))
|
||||
(u/display-not-valid :applyToRange range)
|
||||
|
||||
;; TODO: Check variant inside font variants
|
||||
(not (r/check-permission (obj/get range "$plugin") "content:write"))
|
||||
(u/display-not-valid :applyToRange "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get range "$id")
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
[app.main.data.workspace.transforms :as dwt]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.format :as format]
|
||||
[app.plugins.register :as r]
|
||||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
@ -35,6 +36,9 @@
|
|||
(not (us/safe-number? value)))
|
||||
(u/display-not-valid :addRow-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :addRow "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/add-layout-track #{$id} :row {:type type :value value})))))
|
||||
|
||||
|
@ -52,6 +56,9 @@
|
|||
(not (us/safe-number? value)))
|
||||
(u/display-not-valid :addRowAtIndex-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :addRowAtIndex "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/add-layout-track #{$id} :row {:type type :value value} index)))))
|
||||
|
||||
|
@ -66,6 +73,9 @@
|
|||
(not (us/safe-number? value)))
|
||||
(u/display-not-valid :addColumn-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :addColumn "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/add-layout-track #{$id} :column {:type type :value value})))))
|
||||
|
||||
|
@ -82,6 +92,9 @@
|
|||
(not (us/safe-number? value)))
|
||||
(u/display-not-valid :addColumnAtIndex-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :addColumnAtIndex "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [type (keyword type)]
|
||||
(st/emit! (dwsl/add-layout-track #{$id} :column {:type type :value value} index)))))
|
||||
|
@ -92,6 +105,9 @@
|
|||
(not (us/safe-int? index))
|
||||
(u/display-not-valid :removeRow index)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :removeRow "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/remove-layout-track #{$id} :row index))))
|
||||
|
||||
|
@ -101,6 +117,9 @@
|
|||
(not (us/safe-int? index))
|
||||
(u/display-not-valid :removeColumn index)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :removeColumn "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/remove-layout-track #{$id} :column index))))
|
||||
|
||||
|
@ -118,6 +137,9 @@
|
|||
(not (us/safe-number? value)))
|
||||
(u/display-not-valid :setColumn-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :setColumn "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/change-layout-track #{$id} :column index (d/without-nils {:type type :value value}))))))
|
||||
|
||||
|
@ -135,12 +157,20 @@
|
|||
(not (us/safe-number? value)))
|
||||
(u/display-not-valid :setRow-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :setRow "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/change-layout-track #{$id} :row index (d/without-nils {:type type :value value}))))))
|
||||
|
||||
(remove
|
||||
[_]
|
||||
(st/emit! (dwsl/remove-layout #{$id})))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :remove "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/remove-layout #{$id}))))
|
||||
|
||||
(appendChild
|
||||
[_ child row column]
|
||||
|
@ -154,6 +184,9 @@
|
|||
(or (< column 0) (not (us/safe-int? column)))
|
||||
(u/display-not-valid :appendChild-column column)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :appendChild "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [child-id (obj/get child "$id")]
|
||||
(st/emit! (dwt/move-shapes-to-frame #{child-id} $id nil [row column])
|
||||
|
@ -180,6 +213,9 @@
|
|||
(not (contains? ctl/grid-direction-types value))
|
||||
(u/display-not-valid :dir value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :dir "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-grid-dir value}))))))}
|
||||
|
@ -199,6 +235,9 @@
|
|||
(not (contains? ctl/align-items-types value))
|
||||
(u/display-not-valid :alignItems value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :alignItems "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-align-items value}))))))}
|
||||
|
@ -212,6 +251,9 @@
|
|||
(not (contains? ctl/align-content-types value))
|
||||
(u/display-not-valid :alignContent value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :alignContent "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-align-content value}))))))}
|
||||
|
@ -225,6 +267,9 @@
|
|||
(not (contains? ctl/justify-items-types value))
|
||||
(u/display-not-valid :justifyItems value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :justifyItems "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-justify-items value}))))))}
|
||||
|
@ -238,6 +283,9 @@
|
|||
(not (contains? ctl/justify-content-types value))
|
||||
(u/display-not-valid :justifyContent value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :justifyContent "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-justify-content value}))))))}
|
||||
|
@ -250,6 +298,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :rowGap value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :rowGap "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-gap {:row-gap value}})))))}
|
||||
|
@ -262,6 +313,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :columnGap value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :columnGap "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-gap {:column-gap value}})))))}
|
||||
|
@ -274,6 +328,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :verticalPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :verticalPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p1 value :p3 value}})))))}
|
||||
|
@ -286,6 +343,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :horizontalPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :horizontalPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p2 value :p4 value}})))))}
|
||||
|
@ -298,6 +358,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :topPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :topPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p1 value}})))))}
|
||||
|
@ -310,6 +373,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :rightPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :righPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p2 value}})))))}
|
||||
|
@ -322,6 +388,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :bottomPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :bottomPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p3 value}})))))}
|
||||
|
@ -334,6 +403,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :leftPadding value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :leftPadding "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-padding {:p4 value}})))))})))
|
||||
|
@ -365,10 +437,13 @@
|
|||
shape (u/proxy->shape self)]
|
||||
(cond
|
||||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :row value)
|
||||
(u/display-not-valid :row-value value)
|
||||
|
||||
(nil? cell)
|
||||
(u/display-not-valid :cell "cell not found")
|
||||
(u/display-not-valid :row-cell "cell not found")
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :row "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/update-grid-cell-position (:parent-id shape) (:id cell) {:row value})))))}
|
||||
|
@ -386,6 +461,9 @@
|
|||
(nil? cell)
|
||||
(u/display-not-valid :rowSpan-cell "cell not found")
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :rowSpan "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/update-grid-cell-position (:parent-id shape) (:id cell) {:row-span value})))))}
|
||||
|
||||
|
@ -402,6 +480,9 @@
|
|||
(nil? cell)
|
||||
(u/display-not-valid :column-cell "cell not found")
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :column "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/update-grid-cell-position (:parent-id shape) (:id cell) {:column value})))))}
|
||||
|
||||
|
@ -418,6 +499,9 @@
|
|||
(nil? cell)
|
||||
(u/display-not-valid :columnSpan-cell "cell not found")
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :columnSpan "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/update-grid-cell-position (:parent-id shape) (:id cell) {:column-span value})))))}
|
||||
|
||||
|
@ -434,6 +518,9 @@
|
|||
(nil? cell)
|
||||
(u/display-not-valid :areaName-cell "cell not found")
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :areaName "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/update-grid-cells (:parent-id shape) #{(:id cell)} {:area-name value})))))}
|
||||
|
||||
|
@ -451,6 +538,9 @@
|
|||
(nil? cell)
|
||||
(u/display-not-valid :position-cell "cell not found")
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :position "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/change-cells-mode (:parent-id shape) #{(:id cell)} value)))))}
|
||||
|
||||
|
@ -468,6 +558,9 @@
|
|||
(nil? cell)
|
||||
(u/display-not-valid :alignSelf-cell "cell not found")
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :alignSelf "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/update-grid-cells (:parent-id shape) #{(:id cell)} {:align-self value})))))}
|
||||
|
||||
|
@ -485,5 +578,8 @@
|
|||
(nil? cell)
|
||||
(u/display-not-valid :justifySelf-cell "cell not found")
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :justifySelf "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/update-grid-cells (:parent-id shape) #{(:id cell)} {:justify-self value})))))}))))
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
[app.main.store :as st]
|
||||
[app.plugins.format :as format]
|
||||
[app.plugins.parser :as parser]
|
||||
[app.plugins.register :as r]
|
||||
[app.plugins.shape :as shape]
|
||||
[app.plugins.text :as text]
|
||||
[app.plugins.utils :as u]
|
||||
|
@ -40,15 +41,25 @@
|
|||
|
||||
(remove
|
||||
[_]
|
||||
(st/emit! (dwl/delete-color {:id $id})))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :remove "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwl/delete-color {:id $id}))))
|
||||
|
||||
(clone
|
||||
[_]
|
||||
(let [color-id (uuid/next)
|
||||
color (-> (u/locate-library-color $file $id)
|
||||
(assoc :id color-id))]
|
||||
(st/emit! (dwl/add-color color {:rename? false}))
|
||||
(lib-color-proxy $plugin $id color-id)))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :clone "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [color-id (uuid/next)
|
||||
color (-> (u/locate-library-color $file $id)
|
||||
(assoc :id color-id))]
|
||||
(st/emit! (dwl/add-color color {:rename? false}))
|
||||
(lib-color-proxy $plugin $id color-id))))
|
||||
|
||||
(asFill [_]
|
||||
(let [color (u/locate-library-color $file $id)]
|
||||
|
@ -76,7 +87,7 @@
|
|||
[self key]
|
||||
(cond
|
||||
(not (string? key))
|
||||
(u/display-not-valid :color-plugin-data-key key)
|
||||
(u/display-not-valid :getPluginData-key key)
|
||||
|
||||
:else
|
||||
(let [color (u/proxy->library-color self)]
|
||||
|
@ -86,13 +97,16 @@
|
|||
[_ key value]
|
||||
(cond
|
||||
(not= $file (:current-file-id @st/state))
|
||||
(u/display-not-valid :color-edit-non-local-library $file)
|
||||
(u/display-not-valid :setPluginData-non-local-library $file)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :color-plugin-data-key key)
|
||||
(u/display-not-valid :setPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :color-plugin-data value)
|
||||
(u/display-not-valid :setPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :setPluginData "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :color $id (keyword "plugin" (str $plugin)) key value))))
|
||||
|
@ -106,10 +120,10 @@
|
|||
[self namespace key]
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :color-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :getSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :color-plugin-data-key key)
|
||||
(u/display-not-valid :getSharedPluginData-key key)
|
||||
|
||||
:else
|
||||
(let [color (u/proxy->library-color self)]
|
||||
|
@ -119,16 +133,19 @@
|
|||
[_ namespace key value]
|
||||
(cond
|
||||
(not= $file (:current-file-id @st/state))
|
||||
(u/display-not-valid :color-edit-non-local-library $file)
|
||||
(u/display-not-valid :setSharedPluginData-non-local-library $file)
|
||||
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :color-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :setSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :color-plugin-data-key key)
|
||||
(u/display-not-valid :setSharedPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :color-plugin-data value)
|
||||
(u/display-not-valid :setSharedPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :setSharedPluginData "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :color $id (keyword "shared" namespace) key value))))
|
||||
|
@ -137,7 +154,7 @@
|
|||
[self namespace]
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :color-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :getSharedPluginDataKeys-namespace namespace)
|
||||
|
||||
:else
|
||||
(let [color (u/proxy->library-color self)]
|
||||
|
@ -165,7 +182,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-color-name value)
|
||||
(u/display-not-valid :name value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :name "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [color (u/proxy->library-color self)
|
||||
|
@ -178,7 +198,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-color-path value)
|
||||
(u/display-not-valid :path value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :path "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [color (-> (u/proxy->library-color self)
|
||||
|
@ -191,7 +214,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(or (not (string? value)) (not (cc/valid-hex-color? value)))
|
||||
(u/display-not-valid :library-color-color value)
|
||||
(u/display-not-valid :color value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :color "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [color (-> (u/proxy->library-color self)
|
||||
|
@ -204,7 +230,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(or (not (number? value)) (< value 0) (> value 1))
|
||||
(u/display-not-valid :library-color-opacity value)
|
||||
(u/display-not-valid :opacity value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :opacity "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [color (-> (u/proxy->library-color self)
|
||||
|
@ -218,7 +247,10 @@
|
|||
(let [value (parser/parse-gradient value)]
|
||||
(cond
|
||||
(not (sm/validate ::ctc/gradient value))
|
||||
(u/display-not-valid :library-color-gradient value)
|
||||
(u/display-not-valid :gradient value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :gradient "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [color (-> (u/proxy->library-color self)
|
||||
|
@ -232,7 +264,10 @@
|
|||
(let [value (parser/parse-image-data value)]
|
||||
(cond
|
||||
(not (sm/validate ::ctc/image-color value))
|
||||
(u/display-not-valid :library-color-image value)
|
||||
(u/display-not-valid :image value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :image "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [color (-> (u/proxy->library-color self)
|
||||
|
@ -243,15 +278,25 @@
|
|||
Object
|
||||
(remove
|
||||
[_]
|
||||
(st/emit! (dwl/delete-typography {:id $id})))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :remove "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwl/delete-typography {:id $id}))))
|
||||
|
||||
(clone
|
||||
[_]
|
||||
(let [typo-id (uuid/next)
|
||||
typo (-> (u/locate-library-typography $file $id)
|
||||
(assoc :id typo-id))]
|
||||
(st/emit! (dwl/add-typography typo false))
|
||||
(lib-typography-proxy $plugin $id typo-id)))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :clone "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo-id (uuid/next)
|
||||
typo (-> (u/locate-library-typography $file $id)
|
||||
(assoc :id typo-id))]
|
||||
(st/emit! (dwl/add-typography typo false))
|
||||
(lib-typography-proxy $plugin $id typo-id))))
|
||||
|
||||
(applyToText
|
||||
[_ shape]
|
||||
|
@ -259,6 +304,9 @@
|
|||
(not (shape/shape-proxy? shape))
|
||||
(u/display-not-valid :applyToText shape)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :applyToText "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [shape-id (obj/get shape "$id")
|
||||
typography (u/locate-library-typography $file $id)]
|
||||
|
@ -270,6 +318,9 @@
|
|||
(not (text/text-range? range))
|
||||
(u/display-not-valid :applyToText range)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :applyToText "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [shape-id (obj/get range "$id")
|
||||
start (obj/get range "start")
|
||||
|
@ -296,13 +347,16 @@
|
|||
[_ key value]
|
||||
(cond
|
||||
(not= $file (:current-file-id @st/state))
|
||||
(u/display-not-valid :typography-edit-non-local-library $file)
|
||||
(u/display-not-valid :setPluginData-non-local-library $file)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :typography-plugin-data-key key)
|
||||
(u/display-not-valid :setPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :typography-plugin-data value)
|
||||
(u/display-not-valid :setPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :setPluginData "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :typography $id (keyword "plugin" (str $plugin)) key value))))
|
||||
|
@ -316,10 +370,10 @@
|
|||
[self namespace key]
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :typography-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :getSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :typography-plugin-data-key key)
|
||||
(u/display-not-valid :getSharedPluginData-key key)
|
||||
|
||||
:else
|
||||
(let [typography (u/proxy->library-typography self)]
|
||||
|
@ -329,16 +383,19 @@
|
|||
[_ namespace key value]
|
||||
(cond
|
||||
(not= $file (:current-file-id @st/state))
|
||||
(u/display-not-valid :typography-edit-non-local-library $file)
|
||||
(u/display-not-valid :setSharedPluginData-non-local-library $file)
|
||||
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :typography-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :setSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :typography-plugin-data-key key)
|
||||
(u/display-not-valid :setSharedPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :typography-plugin-data value)
|
||||
(u/display-not-valid :setSharedPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :setSharedPluginData "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :typography $id (keyword "shared" namespace) key value))))
|
||||
|
@ -347,7 +404,7 @@
|
|||
[self namespace]
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :typography-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :getSharedPluginDataKeys-namespace namespace)
|
||||
|
||||
:else
|
||||
(let [typography (u/proxy->library-typography self)]
|
||||
|
@ -376,7 +433,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-name value)
|
||||
(u/display-not-valid :name value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :name "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (u/proxy->library-typography self)
|
||||
|
@ -389,7 +449,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-path value)
|
||||
(u/display-not-valid :path value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :path "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -402,7 +465,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-font-id value)
|
||||
(u/display-not-valid :fontId value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :fontId "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -415,7 +481,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-font-family value)
|
||||
(u/display-not-valid :fontFamily value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :fontFamily "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -428,7 +497,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-font-variant-id value)
|
||||
(u/display-not-valid :fontVariantId value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :fontVariantId "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -441,7 +513,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-font-size value)
|
||||
(u/display-not-valid :fontSize value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :fontSize "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -454,7 +529,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-font-weight value)
|
||||
(u/display-not-valid :fontWeight value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :fontWeight "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -467,7 +545,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-font-style value)
|
||||
(u/display-not-valid :fontStyle value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :fontStyle "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -480,7 +561,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-font-height value)
|
||||
(u/display-not-valid :lineHeight value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :lineHeight "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -493,7 +577,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-letter-spacing value)
|
||||
(u/display-not-valid :letterSpacing value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :letterSpacing "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -506,7 +593,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-typography-text-transform value)
|
||||
(u/display-not-valid :textTransform value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :textTransform "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typo (-> (u/proxy->library-typography self)
|
||||
|
@ -518,13 +608,23 @@
|
|||
|
||||
(remove
|
||||
[_]
|
||||
(st/emit! (dwl/delete-component {:id $id})))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :remove "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwl/delete-component {:id $id}))))
|
||||
|
||||
(instance
|
||||
[_]
|
||||
(let [id-ref (atom nil)]
|
||||
(st/emit! (dwl/instantiate-component $file $id (gpt/point 0 0) {:id-ref id-ref}))
|
||||
(shape/shape-proxy $plugin @id-ref)))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :instance "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id-ref (atom nil)]
|
||||
(st/emit! (dwl/instantiate-component $file $id (gpt/point 0 0) {:id-ref id-ref}))
|
||||
(shape/shape-proxy $plugin @id-ref))))
|
||||
|
||||
(getPluginData
|
||||
[self key]
|
||||
|
@ -540,13 +640,16 @@
|
|||
[_ key value]
|
||||
(cond
|
||||
(not= $file (:current-file-id @st/state))
|
||||
(u/display-not-valid :component-edit-non-local-library $file)
|
||||
(u/display-not-valid :setPluginData-non-local-library $file)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :component-plugin-data-key key)
|
||||
(u/display-not-valid :setPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :component-plugin-data value)
|
||||
(u/display-not-valid :setPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :setPluginData "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :component $id (keyword "plugin" (str $plugin)) key value))))
|
||||
|
@ -573,16 +676,19 @@
|
|||
[_ namespace key value]
|
||||
(cond
|
||||
(not= $file (:current-file-id @st/state))
|
||||
(u/display-not-valid :component-edit-non-local-library $file)
|
||||
(u/display-not-valid :setSharedPluginData-non-local-library $file)
|
||||
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :component-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :setSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :component-plugin-data-key key)
|
||||
(u/display-not-valid :setSharedPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :component-plugin-data value)
|
||||
(u/display-not-valid :setSharedPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :setSharedPluginData "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :component $id (keyword "shared" namespace) key value))))
|
||||
|
@ -626,7 +732,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-component-name value)
|
||||
(u/display-not-valid :name value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :name "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [component (u/proxy->library-component self)
|
||||
|
@ -639,7 +748,10 @@
|
|||
(fn [self value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :library-component-path value)
|
||||
(u/display-not-valid :path value)
|
||||
|
||||
(not (r/check-permission plugin-id "library:write"))
|
||||
(u/display-not-valid :path "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [component (u/proxy->library-component self)
|
||||
|
@ -653,22 +765,37 @@
|
|||
|
||||
(createColor
|
||||
[_]
|
||||
(let [color-id (uuid/next)]
|
||||
(st/emit! (dwl/add-color {:id color-id :name "Color" :color "#000000" :opacity 1} {:rename? false}))
|
||||
(lib-color-proxy $plugin $id color-id)))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :createColor "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [color-id (uuid/next)]
|
||||
(st/emit! (dwl/add-color {:id color-id :name "Color" :color "#000000" :opacity 1} {:rename? false}))
|
||||
(lib-color-proxy $plugin $id color-id))))
|
||||
|
||||
(createTypography
|
||||
[_]
|
||||
(let [typography-id (uuid/next)]
|
||||
(st/emit! (dwl/add-typography (ctt/make-typography {:id typography-id :name "Typography"}) false))
|
||||
(lib-typography-proxy $plugin $id typography-id)))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :createTypography "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [typography-id (uuid/next)]
|
||||
(st/emit! (dwl/add-typography (ctt/make-typography {:id typography-id :name "Typography"}) false))
|
||||
(lib-typography-proxy $plugin $id typography-id))))
|
||||
|
||||
(createComponent
|
||||
[_ shapes]
|
||||
(let [id-ref (atom nil)
|
||||
ids (into #{} (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dwl/add-component id-ref ids))
|
||||
(lib-component-proxy $plugin $id @id-ref)))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :createComponent "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [id-ref (atom nil)
|
||||
ids (into #{} (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dwl/add-component id-ref ids))
|
||||
(lib-component-proxy $plugin $id @id-ref))))
|
||||
|
||||
;; Plugin data
|
||||
(getPluginData
|
||||
|
@ -685,10 +812,13 @@
|
|||
[_ key value]
|
||||
(cond
|
||||
(not (string? key))
|
||||
(u/display-not-valid :file-plugin-data-key key)
|
||||
(u/display-not-valid :setPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :file-plugin-data value)
|
||||
(u/display-not-valid :setPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :setPluginData "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $id :file (keyword "plugin" (str $plugin)) key value))))
|
||||
|
@ -716,13 +846,16 @@
|
|||
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :file-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :setSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :file-plugin-data-key key)
|
||||
(u/display-not-valid :setSharedPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :file-plugin-data value)
|
||||
(u/display-not-valid :setSharedPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :setSharedPluginData "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $id :file (keyword "shared" namespace) key value))))
|
||||
|
@ -731,7 +864,7 @@
|
|||
[self namespace]
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :file-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :namespace namespace)
|
||||
|
||||
:else
|
||||
(let [file (u/proxy->file self)]
|
||||
|
@ -805,21 +938,26 @@
|
|||
|
||||
(connectLibrary
|
||||
[_ library-id]
|
||||
(p/create
|
||||
(fn [resolve reject]
|
||||
(cond
|
||||
(not (string? library-id))
|
||||
(do (u/display-not-valid :connectLibrary library-id)
|
||||
(reject nil))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "library:write"))
|
||||
(u/display-not-valid :connectLibrary "Plugin doesn't have 'library:write' permission")
|
||||
|
||||
:else
|
||||
(let [file-id (:current-file-id @st/state)
|
||||
library-id (uuid/uuid library-id)]
|
||||
(->> st/stream
|
||||
(rx/filter (ptk/type? ::dwl/attach-library-finished))
|
||||
(rx/take 1)
|
||||
(rx/subs! #(resolve (library-proxy $plugin library-id)) reject))
|
||||
(st/emit! (dwl/link-file-to-library file-id library-id))))))))
|
||||
:else
|
||||
(p/create
|
||||
(fn [resolve reject]
|
||||
(cond
|
||||
(not (string? library-id))
|
||||
(do (u/display-not-valid :connectLibrary library-id)
|
||||
(reject nil))
|
||||
|
||||
:else
|
||||
(let [file-id (:current-file-id @st/state)
|
||||
library-id (uuid/uuid library-id)]
|
||||
(->> st/stream
|
||||
(rx/filter (ptk/type? ::dwl/attach-library-finished))
|
||||
(rx/take 1)
|
||||
(rx/subs! #(resolve (library-proxy $plugin library-id)) reject))
|
||||
(st/emit! (dwl/link-file-to-library file-id library-id)))))))))
|
||||
|
||||
(defn library-subcontext
|
||||
[plugin-id]
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
[app.main.data.workspace :as dw]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.parser :as parser]
|
||||
[app.plugins.register :as r]
|
||||
[app.plugins.shape :as shape]
|
||||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]
|
||||
|
@ -74,10 +75,13 @@
|
|||
[_ key value]
|
||||
(cond
|
||||
(not (string? key))
|
||||
(u/display-not-valid :page-plugin-data-key key)
|
||||
(u/display-not-valid :setPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :page-plugin-data value)
|
||||
(u/display-not-valid :setPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :setPluginData "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :page $id (keyword "plugin" (str $plugin)) key value))))
|
||||
|
@ -105,13 +109,16 @@
|
|||
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :page-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :setSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :page-plugin-data-key key)
|
||||
(u/display-not-valid :setSharedPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :page-plugin-data value)
|
||||
(u/display-not-valid :setSharedPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :setSharedPluginData "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :page $id (keyword "shared" namespace) key value))))
|
||||
|
@ -151,7 +158,10 @@
|
|||
(fn [_ value]
|
||||
(cond
|
||||
(not (string? value))
|
||||
(u/display-not-valid :page-name value)
|
||||
(u/display-not-valid :name value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :name "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/rename-page id value))))}
|
||||
|
@ -167,7 +177,10 @@
|
|||
(fn [_ value]
|
||||
(cond
|
||||
(or (not (string? value)) (not (cc/valid-hex-color? value)))
|
||||
(u/display-not-valid :page-background-color value)
|
||||
(u/display-not-valid :background value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :background "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/change-canvas-color id {:color value}))))}))
|
||||
|
|
55
frontend/src/app/plugins/register.cljs
Normal file
55
frontend/src/app/plugins/register.cljs
Normal file
|
@ -0,0 +1,55 @@
|
|||
;; 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.register
|
||||
"RPC for plugins runtime."
|
||||
(:require
|
||||
[app.common.data :as d]))
|
||||
|
||||
;; TODO: Remove clj->js and parse into a better data structure for accessing the permissions
|
||||
|
||||
(def pluginsdb (atom nil))
|
||||
|
||||
(defn load-from-store
|
||||
[]
|
||||
(let [ls (.-localStorage js/window)
|
||||
plugins-val (.getItem ls "plugins")]
|
||||
(when plugins-val
|
||||
(let [plugins-js (.parse js/JSON plugins-val)]
|
||||
(js->clj plugins-js {:keywordize-keys true})))))
|
||||
|
||||
(defn save-to-store
|
||||
[plugins]
|
||||
(let [ls (.-localStorage js/window)
|
||||
plugins-js (clj->js plugins)
|
||||
plugins-val (.stringify js/JSON plugins-js)]
|
||||
(.setItem ls "plugins" plugins-val)))
|
||||
|
||||
(defn init
|
||||
[]
|
||||
(reset! pluginsdb (load-from-store)))
|
||||
|
||||
(defn install-plugin!
|
||||
[plugin]
|
||||
(let [plugins (vec (conj (seq @pluginsdb) plugin))]
|
||||
(reset! pluginsdb plugins)
|
||||
(save-to-store plugins)))
|
||||
|
||||
(defn remove-plugin!
|
||||
[{:keys [plugin-id]}]
|
||||
(let [plugins
|
||||
(into []
|
||||
(keep (fn [plugin]
|
||||
(when (not= plugin-id (:plugin-id plugin)) plugin)))
|
||||
@pluginsdb)]
|
||||
(reset! pluginsdb plugins)
|
||||
(save-to-store plugins)))
|
||||
|
||||
(defn check-permission
|
||||
[plugin-id permission]
|
||||
(or (= plugin-id "TEST")
|
||||
(let [{:keys [permissions]} (->> @pluginsdb (d/seek #(= (:plugin-id %) plugin-id)))]
|
||||
(->> permissions (d/seek #(= % permission))))))
|
|
@ -41,6 +41,7 @@
|
|||
[app.plugins.format :as format]
|
||||
[app.plugins.grid :as grid]
|
||||
[app.plugins.parser :as parser]
|
||||
[app.plugins.register :as r]
|
||||
[app.plugins.text :as text]
|
||||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]
|
||||
|
@ -93,6 +94,9 @@
|
|||
(or (not (us/safe-number? height)) (<= height 0))
|
||||
(u/display-not-valid :resize height)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :resize "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/update-dimensions [$id] :width width)
|
||||
(dw/update-dimensions [$id] :height height))))
|
||||
|
@ -107,6 +111,9 @@
|
|||
(and (some? center) (or (not (number? (:x center))) (not (number? (:y center)))))
|
||||
(u/display-not-valid :rotate-center center)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :rotate "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dw/increase-rotation [id] angle {:center center :delta? true}))))))
|
||||
|
@ -114,19 +121,29 @@
|
|||
(clone
|
||||
[_]
|
||||
(let [ret-v (atom nil)]
|
||||
(st/emit! (dws/duplicate-shapes #{$id} :change-selection? false :return-ref ret-v))
|
||||
(shape-proxy $plugin (deref ret-v))))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :clone "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(do (st/emit! (dws/duplicate-shapes #{$id} :change-selection? false :return-ref ret-v))
|
||||
(shape-proxy $plugin (deref ret-v))))))
|
||||
|
||||
(remove
|
||||
[_]
|
||||
(st/emit! (dwsh/delete-shapes #{$id})))
|
||||
(cond
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :remove "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/delete-shapes #{$id}))))
|
||||
|
||||
;; Plugin data
|
||||
(getPluginData
|
||||
[self key]
|
||||
(cond
|
||||
(not (string? key))
|
||||
(u/display-not-valid :shape-plugin-data-key key)
|
||||
(u/display-not-valid :getPluginData key)
|
||||
|
||||
:else
|
||||
(let [shape (u/proxy->shape self)]
|
||||
|
@ -136,10 +153,13 @@
|
|||
[_ key value]
|
||||
(cond
|
||||
(not (string? key))
|
||||
(u/display-not-valid :shape-plugin-data-key key)
|
||||
(u/display-not-valid :setPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :shape-plugin-data value)
|
||||
(u/display-not-valid :setPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :setPluginData "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :shape $id $page (keyword "plugin" (str $plugin)) key value))))
|
||||
|
@ -153,10 +173,10 @@
|
|||
[self namespace key]
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :shape-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :getSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :shape-plugin-data-key key)
|
||||
(u/display-not-valid :getSharedPluginData-key key)
|
||||
|
||||
:else
|
||||
(let [shape (u/proxy->shape self)]
|
||||
|
@ -167,13 +187,16 @@
|
|||
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :shape-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :setSharedPluginData-namespace namespace)
|
||||
|
||||
(not (string? key))
|
||||
(u/display-not-valid :shape-plugin-data-key key)
|
||||
(u/display-not-valid :setSharedPluginData-key key)
|
||||
|
||||
(and (some? value) (not (string? value)))
|
||||
(u/display-not-valid :shape-plugin-data value)
|
||||
(u/display-not-valid :setSharedPluginData-value value)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :setSharedPluginData "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/set-plugin-data $file :shape $id $page (keyword "shared" namespace) key value))))
|
||||
|
@ -182,7 +205,7 @@
|
|||
[self namespace]
|
||||
(cond
|
||||
(not (string? namespace))
|
||||
(u/display-not-valid :shape-plugin-data-namespace namespace)
|
||||
(u/display-not-valid :getSharedPluginDataKeys namespace)
|
||||
|
||||
:else
|
||||
(let [shape (u/proxy->shape self)]
|
||||
|
@ -218,6 +241,9 @@
|
|||
(not (shape-proxy? child))
|
||||
(u/display-not-valid :appendChild-child child)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :appendChild "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [child-id (obj/get child "$id")]
|
||||
(st/emit! (dw/relocate-shapes #{child-id} $id 0))))))
|
||||
|
@ -235,6 +261,9 @@
|
|||
(not (shape-proxy? child))
|
||||
(u/display-not-valid :insertChild-child child)
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :insertChild "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [child-id (obj/get child "$id")]
|
||||
(st/emit! (dw/relocate-shapes #{child-id} $id index))))))
|
||||
|
@ -247,6 +276,9 @@
|
|||
(not (cfh/frame-shape? shape))
|
||||
(u/display-not-valid :addFlexLayout (:type shape))
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :addFlexLayout "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(do (st/emit! (dwsl/create-layout-from-id $id :flex :from-frame? true :calculate-params? false))
|
||||
(grid/grid-layout-proxy $plugin $file $page $id)))))
|
||||
|
@ -258,6 +290,9 @@
|
|||
(not (cfh/frame-shape? shape))
|
||||
(u/display-not-valid :addGridLayout (:type shape))
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :addGridLayout "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(do (st/emit! (dwsl/create-layout-from-id $id :grid :from-frame? true :calculate-params? false))
|
||||
(grid/grid-layout-proxy $plugin $file $page $id)))))
|
||||
|
@ -270,6 +305,9 @@
|
|||
(not (cfh/group-shape? shape))
|
||||
(u/display-not-valid :makeMask (:type shape))
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :makeMask "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwg/mask-group #{$id})))))
|
||||
|
||||
|
@ -280,6 +318,9 @@
|
|||
(not (cfh/mask-shape? shape))
|
||||
(u/display-not-valid :removeMask (:type shape))
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :removeMask "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwg/unmask-group #{$id})))))
|
||||
|
||||
|
@ -321,6 +362,9 @@
|
|||
(not (cfh/text-shape? shape))
|
||||
(u/display-not-valid :applyTypography-shape (:type shape))
|
||||
|
||||
(not (r/check-permission $plugin "content:write"))
|
||||
(u/display-not-valid :applyTypography "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [typography (u/proxy->library-typography typography)]
|
||||
(st/emit! (dwt/apply-typography #{$id} typography $file))))))
|
||||
|
@ -442,8 +486,11 @@
|
|||
(not (str/ends-with? value "/"))
|
||||
(not (str/blank? value)))]
|
||||
(cond
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :name "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
(not valid?)
|
||||
(u/display-not-valid :shape-name value)
|
||||
(u/display-not-valid :name value)
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :name value))))))}
|
||||
|
@ -456,6 +503,9 @@
|
|||
(not (boolean? value))
|
||||
(u/display-not-valid :blocked value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :blocked "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :blocked value))))))}
|
||||
|
@ -468,6 +518,9 @@
|
|||
(not (boolean? value))
|
||||
(u/display-not-valid :hidden value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :hidden "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :hidden value))))))}
|
||||
|
@ -480,6 +533,9 @@
|
|||
(not (boolean? value))
|
||||
(u/display-not-valid :proportionLock value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :proportionLock "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :proportion-lock value))))))}
|
||||
|
@ -494,6 +550,9 @@
|
|||
(not (contains? cts/horizontal-constraint-types value))
|
||||
(u/display-not-valid :constraintsHorizontal value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :constraintsHorizontal "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :constraints-h value))))))}
|
||||
|
||||
|
@ -507,6 +566,9 @@
|
|||
(not (contains? cts/vertical-constraint-types value))
|
||||
(u/display-not-valid :constraintsVertical value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :constraintsVertical "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :constraints-v value))))))}
|
||||
|
||||
|
@ -520,6 +582,9 @@
|
|||
(or (not (us/safe-int? value)) (< value 0))
|
||||
(u/display-not-valid :borderRadius value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :borderRadius "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
(or (not (ctsr/has-radius? shape)) (ctsr/radius-4? shape))
|
||||
(st/emit! (dwsh/update-shapes [id] #(-> %
|
||||
ctsr/switch-to-radius-1
|
||||
|
@ -538,6 +603,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :borderRadiusTopLeft value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :borderRadiusTopLeft "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
(or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape)))
|
||||
(st/emit! (dwsh/update-shapes [id] #(-> %
|
||||
(ctsr/switch-to-radius-4)
|
||||
|
@ -556,6 +624,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :borderRadiusTopRight value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :borderRadiusTopRight "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
(or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape)))
|
||||
(st/emit! (dwsh/update-shapes [id] #(-> %
|
||||
(ctsr/switch-to-radius-4)
|
||||
|
@ -574,6 +645,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :borderRadiusBottomRight value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :borderRadiusBottomRight "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
(or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape)))
|
||||
(st/emit! (dwsh/update-shapes [id] #(-> %
|
||||
(ctsr/switch-to-radius-4)
|
||||
|
@ -592,6 +666,9 @@
|
|||
(not (us/safe-int? value))
|
||||
(u/display-not-valid :borderRadiusBottomLeft value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :borderRadiusBottomLeft "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
(or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape)))
|
||||
(st/emit! (dwsh/update-shapes [id] #(-> %
|
||||
(ctsr/switch-to-radius-4)
|
||||
|
@ -605,7 +682,14 @@
|
|||
:set
|
||||
(fn [self value]
|
||||
(let [id (obj/get self "$id")]
|
||||
(when (and (us/safe-number? value) (>= value 0) (<= value 1))
|
||||
(cond
|
||||
(or (not (us/safe-number? value)) (< value 0) (> value 1))
|
||||
(u/display-not-valid :opacity value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :opacity "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :opacity value))))))}
|
||||
|
||||
{:name "blendMode"
|
||||
|
@ -618,6 +702,9 @@
|
|||
(not (contains? cts/blend-modes value))
|
||||
(u/display-not-valid :blendMode value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :blendMode "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :blend-mode value))))))}
|
||||
|
||||
|
@ -631,6 +718,9 @@
|
|||
(not (sm/validate [:vector ::ctss/shadow] value))
|
||||
(u/display-not-valid :shadows value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :shadows "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :shadow value))))))}
|
||||
|
||||
|
@ -646,6 +736,9 @@
|
|||
(not (sm/validate ::ctsb/blur value))
|
||||
(u/display-not-valid :blur value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :blur "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :blur value)))))))}
|
||||
|
||||
|
@ -659,6 +752,9 @@
|
|||
(not (sm/validate [:vector ::ctse/export] value))
|
||||
(u/display-not-valid :exports value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :exports "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :exports value))))))}
|
||||
|
||||
|
@ -672,6 +768,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :x value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :x "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/update-position id {:x value})))))}
|
||||
|
||||
|
@ -684,6 +783,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :y value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :y "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dw/update-position id {:y value})))))}
|
||||
|
||||
|
@ -699,6 +801,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :parentX value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :parentX "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")
|
||||
parent-id (-> self u/proxy->shape :parent-id)
|
||||
|
@ -719,6 +824,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :parentY value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :parentY "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")
|
||||
parent-id (-> self u/proxy->shape :parent-id)
|
||||
|
@ -739,6 +847,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :frameX value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :frameX "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")
|
||||
frame-id (-> self u/proxy->shape :frame-id)
|
||||
|
@ -759,6 +870,9 @@
|
|||
(not (us/safe-number? value))
|
||||
(u/display-not-valid :frameY value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :frameY "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")
|
||||
frame-id (-> self u/proxy->shape :frame-id)
|
||||
|
@ -780,6 +894,9 @@
|
|||
(not (number? value))
|
||||
(u/display-not-valid :rotation value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :rotation "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [shape (u/proxy->shape self)]
|
||||
(st/emit! (dw/increase-rotation #{(:id shape)} value)))))}
|
||||
|
@ -792,6 +909,9 @@
|
|||
(not (boolean? value))
|
||||
(u/display-not-valid :flipX value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :flipX "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dw/flip-horizontal-selected #{id})))))}
|
||||
|
@ -804,6 +924,9 @@
|
|||
(not (boolean? value))
|
||||
(u/display-not-valid :flipY value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :flipY "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [id (obj/get self "$id")]
|
||||
(st/emit! (dw/flip-vertical-selected #{id})))))}
|
||||
|
@ -825,6 +948,9 @@
|
|||
(cfh/text-shape? shape)
|
||||
(st/emit! (dwt/update-attrs id {:fills value}))
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fills "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :fills value))))))}
|
||||
|
||||
|
@ -838,6 +964,9 @@
|
|||
(not (sm/validate [:vector ::cts/stroke] value))
|
||||
(u/display-not-valid :strokes value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :strokes "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :strokes value))))))}
|
||||
|
||||
|
@ -898,6 +1027,9 @@
|
|||
(not (sm/validate [:vector ::ctg/grid] value))
|
||||
(u/display-not-valid :guides value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :guides "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :grids value))))))}
|
||||
|
||||
|
@ -911,6 +1043,9 @@
|
|||
(not (contains? #{:fix :auto} value))
|
||||
(u/display-not-valid :horizontalSizing value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :horizontalSizing "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-item-h-sizing value})))))}
|
||||
|
||||
|
@ -924,10 +1059,13 @@
|
|||
(not (contains? #{:fix :auto} value))
|
||||
(u/display-not-valid :verticalSizing value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :verticalSizing "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsl/update-layout #{id} {:layout-item-v-sizing value})))))})))
|
||||
|
||||
(cond-> (cfh/text-shape? data) (text/add-text-props))
|
||||
(cond-> (cfh/text-shape? data) (text/add-text-props plugin-id))
|
||||
|
||||
(cond-> (or (cfh/path-shape? data) (cfh/bool-shape? data))
|
||||
(crc/add-properties!
|
||||
|
@ -945,6 +1083,9 @@
|
|||
(not (sm/validate ::ctsp/content content))
|
||||
(u/display-not-valid :content value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :content "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(let [selrect (gsh/content->selrect content)
|
||||
points (grc/rect->points selrect)]
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
[app.main.store :as st]
|
||||
[app.plugins.format :as format]
|
||||
[app.plugins.parser :as parser]
|
||||
[app.plugins.register :as r]
|
||||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]
|
||||
[app.util.text-editor :as ted]
|
||||
|
@ -107,6 +108,9 @@
|
|||
(not (some? font))
|
||||
(u/display-not-valid :fontId value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontId "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end (font-data font variant))))))}
|
||||
|
||||
|
@ -123,6 +127,9 @@
|
|||
(not (string? value))
|
||||
(u/display-not-valid :fontFamily value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontFamily "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end (font-data font variant))))))}
|
||||
|
||||
|
@ -138,6 +145,9 @@
|
|||
(not (string? value))
|
||||
(u/display-not-valid :fontVariantId value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontVariantId "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end (variant-data variant))))))}
|
||||
|
||||
|
@ -152,6 +162,9 @@
|
|||
(or (empty? value) (not (re-matches font-size-re value)))
|
||||
(u/display-not-valid :fontSize value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontSize "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end {:font-size value})))))}
|
||||
|
||||
|
@ -167,6 +180,9 @@
|
|||
(nil? variant)
|
||||
(u/display-not-valid :fontWeight (dm/str "Font weight '" value "' not supported for the current font"))
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontWeight "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end (variant-data variant))))))}
|
||||
|
||||
|
@ -182,6 +198,9 @@
|
|||
(nil? variant)
|
||||
(u/display-not-valid :fontStyle (dm/str "Font style '" value "' not supported for the current font"))
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontStyle "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end (variant-data variant))))))}
|
||||
|
||||
|
@ -196,6 +215,9 @@
|
|||
(or (empty? value) (not (re-matches line-height-re value)))
|
||||
(u/display-not-valid :lineHeight value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :lineHeight "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end {:line-height value})))))}
|
||||
|
||||
|
@ -210,6 +232,9 @@
|
|||
(or (empty? value) (re-matches letter-spacing-re value))
|
||||
(u/display-not-valid :letterSpacing value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :letterSpacing "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end {:letter-spacing value})))))}
|
||||
|
||||
|
@ -223,6 +248,9 @@
|
|||
(and (string? value) (re-matches text-transform-re value))
|
||||
(u/display-not-valid :textTransform value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :textTransform "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end {:text-transform value}))))}
|
||||
|
||||
|
@ -236,6 +264,9 @@
|
|||
(and (string? value) (re-matches text-decoration-re value))
|
||||
(u/display-not-valid :textDecoration value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :textDecoration "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end {:text-decoration value}))))}
|
||||
|
||||
|
@ -249,6 +280,9 @@
|
|||
(and (string? value) (re-matches text-direction-re value))
|
||||
(u/display-not-valid :direction value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :direction "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end {:direction value}))))}
|
||||
|
||||
|
@ -260,7 +294,10 @@
|
|||
(fn [_ value]
|
||||
(cond
|
||||
(and (string? value) (re-matches text-align-re value))
|
||||
(u/display-not-valid :text-align value)
|
||||
(u/display-not-valid :align value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :align "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end {:text-align value}))))}
|
||||
|
@ -276,11 +313,14 @@
|
|||
(not (sm/validate [:vector ::cts/fill] value))
|
||||
(u/display-not-valid :fills value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fills "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-text-range id start end {:fills value})))))})))
|
||||
|
||||
(defn add-text-props
|
||||
[shape-proxy]
|
||||
[plugin-id shape-proxy]
|
||||
(crc/add-properties!
|
||||
shape-proxy
|
||||
{:name "characters"
|
||||
|
@ -294,6 +334,9 @@
|
|||
(or (not (string? value)) (empty? value))
|
||||
(u/display-not-valid :characters value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :characters "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
(contains? (:workspace-editor-state @st/state) id)
|
||||
(let [shape (u/proxy->shape self)
|
||||
editor
|
||||
|
@ -317,6 +360,9 @@
|
|||
(not (contains? #{:auto-width :auto-height :fixed} value))
|
||||
(u/display-not-valid :growType value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :growType "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwsh/update-shapes [id] #(assoc % :grow-type value))))))}
|
||||
|
||||
|
@ -331,6 +377,9 @@
|
|||
(not (some? font))
|
||||
(u/display-not-valid :fontId value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontId "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id (font-data font variant))))))}
|
||||
|
||||
|
@ -345,6 +394,9 @@
|
|||
(not (some? font))
|
||||
(u/display-not-valid :fontFamily value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontFamily "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id (font-data font variant))))))}
|
||||
|
||||
|
@ -359,6 +411,9 @@
|
|||
(not (some? variant))
|
||||
(u/display-not-valid :fontVariantId value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontVariantId "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id (variant-data variant))))))}
|
||||
|
||||
|
@ -372,6 +427,9 @@
|
|||
(or (empty? value) (not (re-matches font-size-re value)))
|
||||
(u/display-not-valid :fontSize value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontSize "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id {:font-size value})))))}
|
||||
|
||||
|
@ -386,6 +444,9 @@
|
|||
(nil? variant)
|
||||
(u/display-not-valid :fontWeight (dm/str "Font weight '" value "' not supported for the current font"))
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontWeight "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id (variant-data variant))))))}
|
||||
|
||||
|
@ -400,6 +461,9 @@
|
|||
(nil? variant)
|
||||
(u/display-not-valid :fontStyle (dm/str "Font style '" value "' not supported for the current font"))
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :fontStyle "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id (variant-data variant))))))}
|
||||
|
||||
|
@ -413,6 +477,9 @@
|
|||
(or (empty? value) (not (re-matches line-height-re value)))
|
||||
(u/display-not-valid :lineHeight value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :lineHeight "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id {:line-height value})))))}
|
||||
|
||||
|
@ -426,6 +493,9 @@
|
|||
(or (empty? value) (re-matches letter-spacing-re value))
|
||||
(u/display-not-valid :letterSpacing value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :letterSpacing "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id {:letter-spacing value})))))}
|
||||
|
||||
|
@ -438,6 +508,9 @@
|
|||
(and (string? value) (re-matches text-transform-re value))
|
||||
(u/display-not-valid :textTransform value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :textTransform "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id {:text-transform value})))))}
|
||||
|
||||
|
@ -450,6 +523,9 @@
|
|||
(and (string? value) (re-matches text-decoration-re value))
|
||||
(u/display-not-valid :textDecoration value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :textDecoration "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id {:text-decoration value})))))}
|
||||
|
||||
|
@ -460,10 +536,13 @@
|
|||
(let [id (obj/get self "$id")]
|
||||
(cond
|
||||
(and (string? value) (re-matches text-direction-re value))
|
||||
(u/display-not-valid :textDecoration value)
|
||||
(u/display-not-valid :textDirection value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :textDirection "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id {:text-decoration value})))))}
|
||||
(st/emit! (dwt/update-attrs id {:text-direction value})))))}
|
||||
|
||||
{:name "align"
|
||||
:get #(-> % u/proxy->shape text-props :text-align format/format-mixed)
|
||||
|
@ -474,6 +553,9 @@
|
|||
(and (string? value) (re-matches text-align-re value))
|
||||
(u/display-not-valid :align value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :align "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id {:text-align value})))))}
|
||||
|
||||
|
@ -486,5 +568,8 @@
|
|||
(and (string? value) (re-matches vertical-align-re value))
|
||||
(u/display-not-valid :verticalAlign value)
|
||||
|
||||
(not (r/check-permission plugin-id "content:write"))
|
||||
(u/display-not-valid :verticalAlign "Plugin doesn't have 'content:write' permission")
|
||||
|
||||
:else
|
||||
(st/emit! (dwt/update-attrs id {:vertical-align value})))))}))
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
_ (set! st/state store)
|
||||
|
||||
context (api/create-context "tests")
|
||||
context (api/create-context "TEST")
|
||||
|
||||
page (. context -currentPage)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue