@bettercms-ai/ui 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks.js +22 -2
- package/dist/blocks.js.map +1 -1
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/dist/registry.js +22 -2
- package/dist/registry.js.map +1 -1
- package/dist/renderer.js +22 -2
- package/dist/renderer.js.map +1 -1
- package/package.json +2 -2
package/dist/renderer.js
CHANGED
|
@@ -442,12 +442,32 @@ function buildComponents() {
|
|
|
442
442
|
unknownBlockStyle: ({ children }) => /* @__PURE__ */ jsx2("p", { children })
|
|
443
443
|
};
|
|
444
444
|
}
|
|
445
|
+
var isListItem = (node) => node._type === "block" && typeof node.listItem === "string" && !!node.listItem;
|
|
446
|
+
function runsOf(blocks) {
|
|
447
|
+
const runs = [];
|
|
448
|
+
for (const node of blocks) {
|
|
449
|
+
const last = runs.at(-1);
|
|
450
|
+
if (last && isListItem(node) && isListItem(last[0])) last.push(node);
|
|
451
|
+
else runs.push([node]);
|
|
452
|
+
}
|
|
453
|
+
return runs;
|
|
454
|
+
}
|
|
445
455
|
function PortableText({ value, bindingBase }) {
|
|
446
456
|
const blocks = React.useMemo(() => normalizePortableText(readValue(value)), [value]);
|
|
447
457
|
const components = React.useMemo(buildComponents, []);
|
|
458
|
+
const listComponents = React.useMemo(() => {
|
|
459
|
+
if (!bindingBase) return null;
|
|
460
|
+
const keys = new Set(blocks.map((b) => b._key));
|
|
461
|
+
return {
|
|
462
|
+
...components,
|
|
463
|
+
listItem: ({ value: item, children }) => keys.has(item._key) ? /* @__PURE__ */ jsx2("li", { "data-bcms-field": `${bindingBase}#${item._key}`, "data-bcms-kind": "richtext", children }) : /* @__PURE__ */ jsx2("li", { children })
|
|
464
|
+
};
|
|
465
|
+
}, [bindingBase, blocks, components]);
|
|
448
466
|
if (blocks.length === 0) return null;
|
|
449
|
-
if (!bindingBase) return /* @__PURE__ */ jsx2(PT, { value: blocks, components });
|
|
450
|
-
return /* @__PURE__ */ jsx2(Fragment, { children: blocks.map(
|
|
467
|
+
if (!bindingBase || !listComponents) return /* @__PURE__ */ jsx2(PT, { value: blocks, components });
|
|
468
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: runsOf(blocks).map(
|
|
469
|
+
(run) => isListItem(run[0]) ? /* @__PURE__ */ jsx2(PT, { value: run, components: listComponents }, run[0]._key) : /* @__PURE__ */ jsx2(Bound, { base: bindingBase, nodeKey: run[0]._key, children: /* @__PURE__ */ jsx2(PT, { value: run, components }) }, run[0]._key)
|
|
470
|
+
) });
|
|
451
471
|
}
|
|
452
472
|
function readValue(value) {
|
|
453
473
|
if (Array.isArray(value)) return value;
|