@bettercms-ai/ui 0.8.1 → 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 +35 -3
- package/dist/blocks.js.map +1 -1
- package/dist/index.js +35 -3
- package/dist/index.js.map +1 -1
- package/dist/registry.js +35 -3
- package/dist/registry.js.map +1 -1
- package/dist/renderer.js +35 -3
- package/dist/renderer.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -40,6 +40,16 @@ var PT_TYPES = {
|
|
|
40
40
|
mention: "bcmsMention",
|
|
41
41
|
divider: "bcmsDivider",
|
|
42
42
|
code: "bcmsCode",
|
|
43
|
+
/**
|
|
44
|
+
* A video — an uploaded file or a provider URL. DEDICATED rather than another `schemaKey` on
|
|
45
|
+
* the generic block, because a video is the one media node whose rendition depends on its own
|
|
46
|
+
* payload: the same field is a `<video>` for an mp4 and a provider `<iframe>` for a YouTube
|
|
47
|
+
* link (@see resolveVideoSource). The generic block carries a reference this package cannot
|
|
48
|
+
* resolve; a video carries a URL it can.
|
|
49
|
+
*/
|
|
50
|
+
video: "video",
|
|
51
|
+
/** A downloadable document — a PDF, a spec sheet. `<a href download>`, nothing more. */
|
|
52
|
+
file: "file",
|
|
43
53
|
/**
|
|
44
54
|
* A table. Spelled `table`, unprefixed, because that is what every other Portable Text
|
|
45
55
|
* producer calls one — the Sanity-shaped `{_type:"table", rows}` this platform used to refuse
|
|
@@ -62,7 +72,9 @@ var STORABLE_BLOCK_TYPES = /* @__PURE__ */ new Set([
|
|
|
62
72
|
PT_TYPES.table,
|
|
63
73
|
PT_TYPES.code,
|
|
64
74
|
PT_TYPES.divider,
|
|
65
|
-
PT_TYPES.mention
|
|
75
|
+
PT_TYPES.mention,
|
|
76
|
+
PT_TYPES.video,
|
|
77
|
+
PT_TYPES.file
|
|
66
78
|
]);
|
|
67
79
|
|
|
68
80
|
// ../richtext/src/styled.ts
|
|
@@ -430,12 +442,32 @@ function buildComponents() {
|
|
|
430
442
|
unknownBlockStyle: ({ children }) => /* @__PURE__ */ jsx2("p", { children })
|
|
431
443
|
};
|
|
432
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
|
+
}
|
|
433
455
|
function PortableText({ value, bindingBase }) {
|
|
434
456
|
const blocks = React.useMemo(() => normalizePortableText(readValue(value)), [value]);
|
|
435
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]);
|
|
436
466
|
if (blocks.length === 0) return null;
|
|
437
|
-
if (!bindingBase) return /* @__PURE__ */ jsx2(PT, { value: blocks, components });
|
|
438
|
-
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
|
+
) });
|
|
439
471
|
}
|
|
440
472
|
function readValue(value) {
|
|
441
473
|
if (Array.isArray(value)) return value;
|