@renderx-plugins/library
Version:
RenderX Library UI plugin (temporary in-repo workspace package)
57 lines (56 loc) • 2.27 kB
JavaScript
// src/symphonies/load.symphony.ts
import { mapJsonComponentToTemplate } from "@renderx-plugins/host-sdk";
function mapJsonComponentToTemplateCompat(json) {
var _a, _b, _c;
const tpl = mapJsonComponentToTemplate(json);
const type = ((_a = json == null ? void 0 : json.metadata) == null ? void 0 : _a.replaces) || ((_b = json == null ? void 0 : json.metadata) == null ? void 0 : _b.type) || "div";
return {
id: `json-${type}`,
name: ((_c = json == null ? void 0 : json.metadata) == null ? void 0 : _c.name) || type,
template: tpl,
metadata: (json == null ? void 0 : json.metadata) || {},
// Preserve original UI for CSS extraction in Node/test path
ui: json == null ? void 0 : json.ui
};
}
var handlers = {
async loadComponents(_data, ctx) {
var _a, _b, _c;
let list = [];
try {
const g = typeof globalThis !== "undefined" ? globalThis : window;
const inv = ((_b = (_a = g == null ? void 0 : g.window) == null ? void 0 : _a.RenderX) == null ? void 0 : _b.inventory) || ((_c = g == null ? void 0 : g.RenderX) == null ? void 0 : _c.inventory);
if (inv && typeof inv.listComponents === "function") {
const items = await inv.listComponents();
list = (items || []).map(mapJsonComponentToTemplateCompat);
} else if (typeof fetch === "function") {
const idxRes = await fetch("/json-components/index.json");
const idx = idxRes.ok ? await idxRes.json() : { components: [] };
const files = (idx == null ? void 0 : idx.components) || [];
const base = "/json-components/";
const items = [];
for (const f of files) {
const res = await fetch(base + f);
if (res.ok) {
const json = await res.json();
items.push(mapJsonComponentToTemplateCompat(json));
}
}
list = items;
} else {
list = [];
}
} catch {
}
ctx.payload.components = Array.isArray(list) ? list : [];
return { count: ctx.payload.components.length };
},
notifyUi(data, ctx) {
var _a;
(_a = data == null ? void 0 : data.onComponentsLoaded) == null ? void 0 : _a.call(data, ctx.payload.components);
}
};
export {
handlers
};
//# sourceMappingURL=chunk-T3LH56OS.js.map