mirror of
https://github.com/penpot/penpot.git
synced 2025-05-24 06:46:11 +02:00
✨ Changes to the manifest loading
This commit is contained in:
parent
85ae3ff6f8
commit
4f4ce174ae
2 changed files with 43 additions and 21 deletions
|
@ -24,26 +24,28 @@
|
||||||
|
|
||||||
|
|
||||||
(mf/defc plugin-entry
|
(mf/defc plugin-entry
|
||||||
[{:keys [index _icon url name description on-open-plugin on-remove-plugin]}]
|
[{:keys [index manifest on-open-plugin on-remove-plugin]}]
|
||||||
|
|
||||||
(let [handle-open-click
|
(let [{:keys [host icon url name description]} manifest
|
||||||
|
handle-open-click
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps index url on-open-plugin)
|
(mf/deps index manifest on-open-plugin)
|
||||||
(fn []
|
(fn []
|
||||||
(when on-open-plugin
|
(when on-open-plugin
|
||||||
(on-open-plugin index url))))
|
(on-open-plugin manifest))))
|
||||||
|
|
||||||
handle-delete-click
|
handle-delete-click
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps index url on-remove-plugin)
|
(mf/deps index on-remove-plugin)
|
||||||
(fn []
|
(fn []
|
||||||
(when on-remove-plugin
|
(when on-remove-plugin
|
||||||
(on-remove-plugin index url))))]
|
(on-remove-plugin index))))]
|
||||||
[:div {:class (stl/css :plugins-list-element)}
|
[:div {:class (stl/css :plugins-list-element)}
|
||||||
[:div {:class (stl/css :plugin-icon)} ""]
|
[:div {:class (stl/css :plugin-icon)}
|
||||||
|
(when (some? icon) [:img {:src (dm/str host icon)}])]
|
||||||
[:div {:class (stl/css :plugin-description)}
|
[:div {:class (stl/css :plugin-description)}
|
||||||
[:div {:class (stl/css :plugin-title)} name]
|
[:div {:class (stl/css :plugin-title)} name]
|
||||||
[:div {:class (stl/css :plugin-summary)} description]]
|
[:div {:class (stl/css :plugin-summary)} (d/nilv description "")]]
|
||||||
[:button {:class (stl/css :open-button)
|
[:button {:class (stl/css :open-button)
|
||||||
:on-click handle-open-click} (tr "workspace.plugins.button-open")]
|
:on-click handle-open-click} (tr "workspace.plugins.button-open")]
|
||||||
[:button {:class (stl/css :trash-button)
|
[:button {:class (stl/css :trash-button)
|
||||||
|
@ -65,8 +67,15 @@
|
||||||
(.setItem ls "plugins" plugins-val)))
|
(.setItem ls "plugins" plugins-val)))
|
||||||
|
|
||||||
(defn open-plugin!
|
(defn open-plugin!
|
||||||
[url]
|
[{:keys [name description host code icon permissions]}]
|
||||||
(.ɵloadPlugin js/window #js {:manifest url}))
|
(.ɵloadPlugin
|
||||||
|
js/window #js
|
||||||
|
{:name name
|
||||||
|
:description description
|
||||||
|
:host host
|
||||||
|
:code code
|
||||||
|
:icon icon
|
||||||
|
:permissions (apply array permissions)}))
|
||||||
|
|
||||||
(mf/defc plugin-management-dialog
|
(mf/defc plugin-management-dialog
|
||||||
{::mf/register modal/components
|
{::mf/register modal/components
|
||||||
|
@ -107,7 +116,20 @@
|
||||||
(rx/subs!
|
(rx/subs!
|
||||||
(fn [body]
|
(fn [body]
|
||||||
(let [name (obj/get body "name")
|
(let [name (obj/get body "name")
|
||||||
new-state (conj plugins-state {:name name :url plugin-url})]
|
desc (obj/get body "description")
|
||||||
|
host (obj/get body "host")
|
||||||
|
code (obj/get body "code")
|
||||||
|
icon (obj/get body "icon")
|
||||||
|
permissions (obj/get body "permissions")
|
||||||
|
|
||||||
|
new-state
|
||||||
|
(conj plugins-state
|
||||||
|
{:name name
|
||||||
|
:description desc
|
||||||
|
:host host
|
||||||
|
:code code
|
||||||
|
:icon icon
|
||||||
|
:permissions (->> permissions (mapv str))})]
|
||||||
(reset! input-status* :success)
|
(reset! input-status* :success)
|
||||||
(reset! plugin-url* "")
|
(reset! plugin-url* "")
|
||||||
(reset! plugins-state* new-state)
|
(reset! plugins-state* new-state)
|
||||||
|
@ -117,18 +139,18 @@
|
||||||
|
|
||||||
handle-open-plugin
|
handle-open-plugin
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(fn [_ url]
|
(fn [manifest]
|
||||||
(open-plugin! url)
|
(open-plugin! manifest)
|
||||||
(modal/hide!)))
|
(modal/hide!)))
|
||||||
|
|
||||||
handle-remove-plugin
|
handle-remove-plugin
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps plugins-state)
|
(mf/deps plugins-state)
|
||||||
(fn [rm-idx _]
|
(fn [plugin-index]
|
||||||
(let [new-state
|
(let [new-state
|
||||||
(into []
|
(into []
|
||||||
(keep-indexed (fn [idx item]
|
(keep-indexed (fn [idx item]
|
||||||
(when (not= idx rm-idx) item)))
|
(when (not= idx plugin-index) item)))
|
||||||
plugins-state)]
|
plugins-state)]
|
||||||
|
|
||||||
(reset! plugins-state* new-state)
|
(reset! plugins-state* new-state)
|
||||||
|
@ -170,12 +192,9 @@
|
||||||
|
|
||||||
[:div {:class (stl/css :plugins-list)}
|
[:div {:class (stl/css :plugins-list)}
|
||||||
|
|
||||||
(for [[idx {:keys [name url]}] (d/enumerate plugins-state)]
|
(for [[idx manifest] (d/enumerate plugins-state)]
|
||||||
[:& plugin-entry {:key (dm/str "plugin-" idx)
|
[:& plugin-entry {:key (dm/str "plugin-" idx)
|
||||||
:name name
|
|
||||||
:url url
|
|
||||||
:index idx
|
:index idx
|
||||||
:icon nil
|
:manifest manifest
|
||||||
:description "Nullam ullamcorper ligula ac felis commodo pulvinar."
|
|
||||||
:on-open-plugin handle-open-plugin
|
:on-open-plugin handle-open-plugin
|
||||||
:on-remove-plugin handle-remove-plugin}])])]]]))
|
:on-remove-plugin handle-remove-plugin}])])]]]))
|
||||||
|
|
|
@ -101,13 +101,16 @@
|
||||||
min-height: $s-32;
|
min-height: $s-32;
|
||||||
width: $s-32;
|
width: $s-32;
|
||||||
height: $s-32;
|
height: $s-32;
|
||||||
background: #b1b2b5;
|
background: var(--button-secondary-background-color-rest);
|
||||||
|
padding: $s-2;
|
||||||
|
border-radius: $s-4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.plugin-description {
|
.plugin-description {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: $s-8;
|
gap: $s-8;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.plugin-title {
|
.plugin-title {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue