mirror of
https://github.com/penpot/penpot.git
synced 2025-05-24 02:06:10 +02:00
Merge remote-tracking branch 'origin/plugins-beta-test' into develop
This commit is contained in:
commit
35f4a07d27
24 changed files with 189 additions and 57 deletions
|
@ -110,7 +110,7 @@
|
|||
(def privacy-policy-uri (obj/get global "penpotPrivacyPolicyURI" "https://penpot.app/privacy"))
|
||||
(def flex-help-uri (obj/get global "penpotGridHelpURI" "https://help.penpot.app/user-guide/flexible-layouts/"))
|
||||
(def grid-help-uri (obj/get global "penpotGridHelpURI" "https://help.penpot.app/user-guide/flexible-layouts/"))
|
||||
(def plugins-list-uri (obj/get global "penpotPluginsListUri" "https://penpot-docs-plugins.netlify.app/technical-guide/plugins/getting-started/#examples"))
|
||||
(def plugins-list-uri (obj/get global "penpotPluginsListUri" "https://penpot-docs-plugins.pages.dev/technical-guide/plugins/getting-started/#examples"))
|
||||
|
||||
(defn- normalize-uri
|
||||
[uri-str]
|
||||
|
|
|
@ -467,4 +467,5 @@
|
|||
(watch [_ _ _]
|
||||
(->> (svg->clj [name svg-string])
|
||||
(rx/take 1)
|
||||
(rx/map #(svg/add-svg-shapes id % position {:change-selection? false}))))))
|
||||
(rx/map #(svg/add-svg-shapes id % position {:ignore-selection? true
|
||||
:change-selection? false}))))))
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.hooks.resize :as r]
|
||||
[app.util.dom :as dom]))
|
||||
[app.util.dom :as dom]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Shortcuts
|
||||
|
@ -563,7 +564,9 @@
|
|||
:command (ds/c-mod "alt+p")
|
||||
:subsections [:basics]
|
||||
:fn #(when (features/active-feature? @st/state "plugins/runtime")
|
||||
(st/emit! (modal/show :plugin-management {})))}})
|
||||
(st/emit!
|
||||
(ptk/event ::ev/event {::ev/name "open-plugins-manager" ::ev/origin "workspace:shortcuts"})
|
||||
(modal/show :plugin-management {})))}})
|
||||
|
||||
(def debug-shortcuts
|
||||
;; PREVIEW
|
||||
|
|
|
@ -64,7 +64,8 @@
|
|||
([svg-data position]
|
||||
(add-svg-shapes nil svg-data position nil))
|
||||
|
||||
([id svg-data position {:keys [change-selection?] :or {change-selection? false}}]
|
||||
([id svg-data position {:keys [change-selection? ignore-selection?]
|
||||
:or {ignore-selection? false change-selection? true}}]
|
||||
(ptk/reify ::add-svg-shapes
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
|
@ -73,7 +74,7 @@
|
|||
page-id (:current-page-id state)
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
frame-id (ctst/top-nested-frame objects position)
|
||||
selected (wsh/lookup-selected state)
|
||||
selected (if ignore-selection? #{} (wsh/lookup-selected state))
|
||||
base (cfh/get-base-shape objects selected)
|
||||
|
||||
selected-id (first selected)
|
||||
|
|
|
@ -630,13 +630,23 @@
|
|||
(when (d/not-empty? plugins)
|
||||
[:div {:class (stl/css :separator)}])
|
||||
|
||||
(for [[idx {:keys [name] :as manifest}] (d/enumerate plugins)]
|
||||
(for [[idx {:keys [name host] :as manifest}] (d/enumerate plugins)]
|
||||
[:> dropdown-menu-item* {:key (dm/str "plugins-menu-" idx)
|
||||
:on-click #(uwp/open-plugin! manifest)
|
||||
:on-click #(do
|
||||
(st/emit! (ptk/event ::ev/event {::ev/name "start-plugin"
|
||||
::ev/origin "workspace:menu"
|
||||
:name name
|
||||
:host host}))
|
||||
(uwp/open-plugin! manifest))
|
||||
:class (stl/css :submenu-item)
|
||||
:on-key-down (fn [event]
|
||||
(when (kbd/enter? event)
|
||||
#(uwp/open-plugin! manifest)))}
|
||||
#(do
|
||||
(st/emit! (ptk/event ::ev/event {::ev/name "start-plugin"
|
||||
::ev/origin "workspace:menu"
|
||||
:name name
|
||||
:host host}))
|
||||
(uwp/open-plugin! manifest))))}
|
||||
[:span {:class (stl/css :item-name)} name]])])))
|
||||
|
||||
(mf/defc menu
|
||||
|
@ -699,7 +709,9 @@
|
|||
(dom/stop-propagation event)
|
||||
(reset! show-menu* false)
|
||||
(reset! sub-menu* nil)
|
||||
(st/emit! (modal/show :plugin-management {}))))]
|
||||
(st/emit!
|
||||
(ptk/event ::ev/event {::ev/name "open-plugins-manager" ::ev/origin "workspace:menu"})
|
||||
(modal/show :plugin-management {}))))]
|
||||
|
||||
|
||||
[:*
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.config :as cf]
|
||||
[app.main.data.events :as ev]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.components.search-bar :refer [search-bar]]
|
||||
|
@ -21,6 +22,8 @@
|
|||
[app.util.http :as http]
|
||||
[app.util.i18n :as i18n :refer [tr]]
|
||||
[beicon.v2.core :as rx]
|
||||
[cuerdas.core :as str]
|
||||
[potok.v2.core :as ptk]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(def ^:private close-icon
|
||||
|
@ -111,6 +114,7 @@
|
|||
(rx/subs!
|
||||
(fn [body]
|
||||
(let [plugin (plugins/parser-manifest plugin-url body)]
|
||||
(st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url}))
|
||||
(modal/show!
|
||||
:plugin-permissions
|
||||
{:plugin plugin
|
||||
|
@ -126,6 +130,10 @@
|
|||
handle-open-plugin
|
||||
(mf/use-callback
|
||||
(fn [manifest]
|
||||
(st/emit! (ptk/event ::ev/event {::ev/name "start-plugin"
|
||||
::ev/origin "workspace:plugins"
|
||||
:name (:name manifest)
|
||||
:host (:host manifest)}))
|
||||
(open-plugin! manifest)
|
||||
(modal/hide!)))
|
||||
|
||||
|
@ -134,6 +142,9 @@
|
|||
(mf/deps plugins-state)
|
||||
(fn [plugin-index]
|
||||
(let [plugin (nth @plugins/pluginsdb plugin-index)]
|
||||
(st/emit! (ptk/event ::ev/event {::ev/name "remove-plugin"
|
||||
:name (:name plugin)
|
||||
:host (:host plugin)}))
|
||||
(plugins/remove-plugin! plugin)
|
||||
(reset! plugins-state* @plugins/pluginsdb))))]
|
||||
|
||||
|
@ -162,7 +173,10 @@
|
|||
[:div {:class (stl/css :plugins-empty)}
|
||||
[:div {:class (stl/css :plugins-empty-logo)} i/puzzle]
|
||||
[:div {:class (stl/css :plugins-empty-text)} (tr "workspace.plugins.empty-plugins")]
|
||||
[:a {:class (stl/css :plugins-link) :href cf/plugins-list-uri :target "_blank"}
|
||||
[:a {:class (stl/css :plugins-link)
|
||||
:href cf/plugins-list-uri
|
||||
:target "_blank"
|
||||
:on-click #(st/emit! (ptk/event ::ev/event {::ev/name "open-plugins-list"}))}
|
||||
(tr "workspace.plugins.plugin-list-link") i/external-link]]
|
||||
|
||||
[:*
|
||||
|
@ -182,7 +196,7 @@
|
|||
::mf/register-as :plugin-permissions}
|
||||
[{:keys [plugin on-accept]}]
|
||||
|
||||
(let [{:keys [permissions]} plugin
|
||||
(let [{:keys [host permissions]} plugin
|
||||
permissions (set permissions)
|
||||
|
||||
handle-accept-dialog
|
||||
|
@ -190,12 +204,18 @@
|
|||
(fn [event]
|
||||
(dom/prevent-default event)
|
||||
(st/emit! (modal/hide))
|
||||
(ptk/event ::ev/event {::ev/name "allow-plugin-permissions"
|
||||
:host host
|
||||
:permissions (->> permissions (str/join ", "))})
|
||||
(on-accept)))
|
||||
|
||||
handle-close-dialog
|
||||
(mf/use-callback
|
||||
(fn [event]
|
||||
(dom/prevent-default event)
|
||||
(ptk/event ::ev/event {::ev/name "reject-plugin-permissions"
|
||||
:host host
|
||||
:permissions (->> permissions (str/join ", "))})
|
||||
(st/emit! (modal/hide))))]
|
||||
|
||||
[:div {:class (stl/css :modal-overlay)}
|
||||
|
@ -205,35 +225,38 @@
|
|||
|
||||
[:div {:class (stl/css :modal-content)}
|
||||
[:div {:class (stl/css :permissions-list)}
|
||||
(when (contains? permissions "content:read")
|
||||
(cond
|
||||
(contains? permissions "content:write")
|
||||
[:div {:class (stl/css :permissions-list-entry)}
|
||||
i/oauth-1
|
||||
[:p {:class (stl/css :permissions-list-text)}
|
||||
(tr "workspace.plugins.permissions.content-write")]]
|
||||
|
||||
(contains? permissions "content:read")
|
||||
[:div {:class (stl/css :permissions-list-entry)}
|
||||
i/oauth-1
|
||||
[:p {:class (stl/css :permissions-list-text)}
|
||||
(tr "workspace.plugins.permissions.content-read")]])
|
||||
|
||||
(when (contains? permissions "content:write")
|
||||
[:div {:class (stl/css :permissions-list-entry)}
|
||||
i/oauth-1
|
||||
[:p {:class (stl/css :permissions-list-text)}
|
||||
(tr "workspace.plugins.permissions.content-write")]])
|
||||
|
||||
(when (contains? permissions "user:read")
|
||||
(cond
|
||||
(contains? permissions "user:read")
|
||||
[:div {:class (stl/css :permissions-list-entry)}
|
||||
i/oauth-2
|
||||
[:p {:class (stl/css :permissions-list-text)}
|
||||
(tr "workspace.plugins.permissions.user-read")]])
|
||||
|
||||
(when (contains? permissions "library:read")
|
||||
(cond
|
||||
(contains? permissions "library:write")
|
||||
[:div {:class (stl/css :permissions-list-entry)}
|
||||
i/oauth-3
|
||||
[:p {:class (stl/css :permissions-list-text)}
|
||||
(tr "workspace.plugins.permissions.library-read")]])
|
||||
(tr "workspace.plugins.permissions.library-write")]]
|
||||
|
||||
(when (contains? permissions "library:write")
|
||||
(contains? permissions "library:read")
|
||||
[:div {:class (stl/css :permissions-list-entry)}
|
||||
i/oauth-3
|
||||
[:p {:class (stl/css :permissions-list-text)}
|
||||
(tr "workspace.plugins.permissions.library-write")]])]
|
||||
(tr "workspace.plugins.permissions.library-read")]])]
|
||||
|
||||
[:div {:class (stl/css :permissions-disclaimer)}
|
||||
(tr "workspace.plugins.permissions.disclaimer")]]
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
[app.util.i18n :as i18n :refer [tr]]
|
||||
[app.util.timers :as ts]
|
||||
[okulary.core :as l]
|
||||
[potok.v2.core :as ptk]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(mf/defc image-upload
|
||||
|
@ -200,7 +201,9 @@
|
|||
{:title (tr "workspace.toolbar.plugins" (sc/get-tooltip :plugins))
|
||||
:aria-label (tr "workspace.toolbar.plugins" (sc/get-tooltip :plugins))
|
||||
:class (stl/css :main-toolbar-options-button)
|
||||
:on-click #(modal/show! :plugin-management {})
|
||||
:on-click #(st/emit!
|
||||
(ptk/event ::ev/event {::ev/name "open-plugins-manager" ::ev/origin "workspace:toolbar"})
|
||||
(modal/show :plugin-management {}))
|
||||
:data-tool "plugins"
|
||||
:data-testid "plugins-btn"}
|
||||
i/puzzle]])
|
||||
|
|
|
@ -47,7 +47,16 @@
|
|||
desc (obj/get manifest "description")
|
||||
code (obj/get manifest "code")
|
||||
icon (obj/get manifest "icon")
|
||||
permissions (obj/get manifest "permissions")
|
||||
|
||||
permissions (into #{} (obj/get manifest "permissions" []))
|
||||
permissions
|
||||
(cond-> permissions
|
||||
(contains? permissions "content:write")
|
||||
(conj "content:read")
|
||||
|
||||
(contains? permissions "library:write")
|
||||
(conj "content:write"))
|
||||
|
||||
origin (obj/get (js/URL. plugin-url) "origin")
|
||||
plugin-id (str (uuid/next))]
|
||||
{:plugin-id plugin-id
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
[app.main.data.workspace.colors :as dwc]
|
||||
[app.main.data.workspace.groups :as dwg]
|
||||
[app.main.data.workspace.media :as dwm]
|
||||
[app.main.data.workspace.selection :as dws]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.events :as events]
|
||||
[app.plugins.file :as file]
|
||||
|
@ -356,7 +357,19 @@
|
|||
{:name "root" :get #(.getRoot ^js %)}
|
||||
{:name "currentFile" :get #(.getFile ^js %)}
|
||||
{:name "currentPage" :get #(.getPage ^js %)}
|
||||
{:name "selection" :get #(.getSelectedShapes ^js %)}
|
||||
|
||||
{:name "selection"
|
||||
:get #(.getSelectedShapes ^js %)
|
||||
:set
|
||||
(fn [_ shapes]
|
||||
(cond
|
||||
(or (not (array? shapes)) (not (every? shape/shape-proxy? shapes)))
|
||||
(u/display-not-valid :selection shapes)
|
||||
|
||||
:else
|
||||
(let [ids (into (d/ordered-set) (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dws/select-shapes ids)))))}
|
||||
|
||||
{:name "viewport" :get #(.getViewport ^js %)}
|
||||
{:name "currentUser" :get #(.getCurrentUser ^js %)}
|
||||
{:name "activeUsers" :get #(.getActiveUsers ^js %)}
|
||||
|
|
|
@ -229,8 +229,8 @@
|
|||
(when (some? export)
|
||||
(d/without-nils
|
||||
{:type (-> (obj/get export "type") parse-keyword)
|
||||
:scale (obj/get export "scale")
|
||||
:suffix (obj/get export "suffix")})))
|
||||
:scale (obj/get export "scale" 1)
|
||||
:suffix (obj/get export "suffix" "")})))
|
||||
|
||||
(defn parse-exports
|
||||
[^js exports]
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
[app.main.data.workspace.shape-layout :as dwsl]
|
||||
[app.main.data.workspace.shapes :as dwsh]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
[app.main.repo :as rp]
|
||||
[app.main.store :as st]
|
||||
[app.plugins.flex :as flex]
|
||||
[app.plugins.format :as format]
|
||||
|
@ -46,7 +47,9 @@
|
|||
[app.plugins.utils :as u]
|
||||
[app.util.object :as obj]
|
||||
[app.util.path.format :as upf]
|
||||
[cuerdas.core :as str]))
|
||||
[beicon.v2.core :as rx]
|
||||
[cuerdas.core :as str]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(def lib-typography-proxy? nil)
|
||||
(def lib-component-proxy nil)
|
||||
|
@ -436,7 +439,34 @@
|
|||
shape (u/proxy->shape self)]
|
||||
(when (ctn/in-any-component? objects shape)
|
||||
(let [[root component] (u/locate-component objects shape)]
|
||||
(lib-component-proxy $plugin (:component-file root) (:id component)))))))
|
||||
(lib-component-proxy $plugin (:component-file root) (:id component))))))
|
||||
|
||||
(export
|
||||
[self value]
|
||||
(let [value (parser/parse-export value)]
|
||||
(cond
|
||||
(not (sm/validate ::ctse/export value))
|
||||
(u/display-not-valid :export value)
|
||||
|
||||
:else
|
||||
(let [payload
|
||||
{:cmd :export-shapes
|
||||
:profile-id (:profile-id @st/state)
|
||||
:wait true
|
||||
:exports [{:file-id $file
|
||||
:page-id $page
|
||||
:object-id $id
|
||||
:name (obj/get self "name")
|
||||
:type (:type value :png)
|
||||
:suffix (:suffix value "")
|
||||
:scale (:scale value 1)}]}]
|
||||
(p/create
|
||||
(fn [resolve reject]
|
||||
(->> (rp/cmd! :export payload)
|
||||
(rx/mapcat #(rp/cmd! :export {:cmd :get-resource :wait true :id (:id %) :blob? true}))
|
||||
(rx/mapcat #(.arrayBuffer %))
|
||||
(rx/map #(js/Uint8Array. %))
|
||||
(rx/subs! resolve reject)))))))))
|
||||
|
||||
(defn shape-proxy? [p]
|
||||
(instance? ShapeProxy p))
|
||||
|
@ -886,6 +916,12 @@
|
|||
{:name "height"
|
||||
:get #(-> % u/proxy->shape :height)}
|
||||
|
||||
{:name "bounds"
|
||||
:get #(-> % u/proxy->shape :points grc/points->rect format/format-bounds)}
|
||||
|
||||
{:name "center"
|
||||
:get #(-> % u/proxy->shape gsh/shape->center format/format-point)}
|
||||
|
||||
{:name "rotation"
|
||||
:get #(-> % u/proxy->shape :rotation)
|
||||
:set
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue