0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 08:20:45 -05:00

Changes to the manifest loading

This commit is contained in:
alonso.torres 2024-05-22 17:23:24 +02:00 committed by Andrey Antukh
parent 85ae3ff6f8
commit 4f4ce174ae
2 changed files with 43 additions and 21 deletions

View file

@ -24,26 +24,28 @@
(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/deps index url on-open-plugin)
(mf/deps index manifest on-open-plugin)
(fn []
(when on-open-plugin
(on-open-plugin index url))))
(on-open-plugin manifest))))
handle-delete-click
(mf/use-callback
(mf/deps index url on-remove-plugin)
(mf/deps index on-remove-plugin)
(fn []
(when on-remove-plugin
(on-remove-plugin index url))))]
(on-remove-plugin index))))]
[: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-title)} name]
[:div {:class (stl/css :plugin-summary)} description]]
[:div {:class (stl/css :plugin-summary)} (d/nilv description "")]]
[:button {:class (stl/css :open-button)
:on-click handle-open-click} (tr "workspace.plugins.button-open")]
[:button {:class (stl/css :trash-button)
@ -65,8 +67,15 @@
(.setItem ls "plugins" plugins-val)))
(defn open-plugin!
[url]
(.ɵloadPlugin js/window #js {:manifest url}))
[{:keys [name description host code icon permissions]}]
(.ɵloadPlugin
js/window #js
{:name name
:description description
:host host
:code code
:icon icon
:permissions (apply array permissions)}))
(mf/defc plugin-management-dialog
{::mf/register modal/components
@ -107,7 +116,20 @@
(rx/subs!
(fn [body]
(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! plugin-url* "")
(reset! plugins-state* new-state)
@ -117,18 +139,18 @@
handle-open-plugin
(mf/use-callback
(fn [_ url]
(open-plugin! url)
(fn [manifest]
(open-plugin! manifest)
(modal/hide!)))
handle-remove-plugin
(mf/use-callback
(mf/deps plugins-state)
(fn [rm-idx _]
(fn [plugin-index]
(let [new-state
(into []
(keep-indexed (fn [idx item]
(when (not= idx rm-idx) item)))
(when (not= idx plugin-index) item)))
plugins-state)]
(reset! plugins-state* new-state)
@ -170,12 +192,9 @@
[: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)
:name name
:url url
:index idx
:icon nil
:description "Nullam ullamcorper ligula ac felis commodo pulvinar."
:manifest manifest
:on-open-plugin handle-open-plugin
:on-remove-plugin handle-remove-plugin}])])]]]))

View file

@ -101,13 +101,16 @@
min-height: $s-32;
width: $s-32;
height: $s-32;
background: #b1b2b5;
background: var(--button-secondary-background-color-rest);
padding: $s-2;
border-radius: $s-4;
}
.plugin-description {
display: flex;
flex-direction: column;
gap: $s-8;
width: 100%;
}
.plugin-title {