From 572ccff33bdd2a9e86fd4b4f477fefb506598b5e Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Fri, 27 Sep 2024 09:00:37 +0200 Subject: [PATCH 1/7] feat(pat contentbrowser): Register components with "@plone/registry" --- src/pat/contentbrowser/contentbrowser.js | 23 +++++++ .../contentbrowser/src/SelectedItem.svelte | 59 +++++++++++++++++ .../contentbrowser/src/SelectedItems.svelte | 63 ++++--------------- 3 files changed, 93 insertions(+), 52 deletions(-) create mode 100644 src/pat/contentbrowser/src/SelectedItem.svelte diff --git a/src/pat/contentbrowser/contentbrowser.js b/src/pat/contentbrowser/contentbrowser.js index 71cdad1c4..8f8f6e756 100644 --- a/src/pat/contentbrowser/contentbrowser.js +++ b/src/pat/contentbrowser/contentbrowser.js @@ -2,6 +2,29 @@ import { BasePattern } from "@patternslib/patternslib/src/core/basepattern"; import Parser from "@patternslib/patternslib/src/core/parser"; import registry from "@patternslib/patternslib/src/core/registry"; import utils from "../../core/utils"; +import plone_registry from "@plone/registry"; + +async function init_component_registry() { + // bug? set the component registry as empty dict the first time + // otherwise you get the error: "this._data.components is undefined" + if (plone_registry["components"] === undefined) { + // see @plone/registry + plone_registry["components"] = {}; + } + + if (plone_registry.getComponent("SelectedItem").component === undefined) { + const SelectedItem = (await import("./src/SelectedItem.svelte")).default; + plone_registry.registerComponent({ + name: "SelectedItem", + component: SelectedItem, + }); + } +} + +// register default components in @plone/registry +// here outside the pattern init() so that addons can override this +// when their bundle depends on the "plone" bundle +init_component_registry() // Contentbrowser pattern diff --git a/src/pat/contentbrowser/src/SelectedItem.svelte b/src/pat/contentbrowser/src/SelectedItem.svelte new file mode 100644 index 000000000..1018db267 --- /dev/null +++ b/src/pat/contentbrowser/src/SelectedItem.svelte @@ -0,0 +1,59 @@ + + +
+
+ + +
+ {item.Title}
+ {item.path} +
+
+ {#if item.getURL && (item.getIcon || item.portal_type === "Image")}{item.Title}{/if} +
+ + diff --git a/src/pat/contentbrowser/src/SelectedItems.svelte b/src/pat/contentbrowser/src/SelectedItems.svelte index f5a1fb4a4..84c8546a1 100644 --- a/src/pat/contentbrowser/src/SelectedItems.svelte +++ b/src/pat/contentbrowser/src/SelectedItems.svelte @@ -1,14 +1,18 @@