@bettercms-ai/ui 0.8.2 → 0.9.0
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.d.ts +6 -1
- package/dist/blocks.js +53 -7
- package/dist/blocks.js.map +1 -1
- package/dist/index.js +53 -7
- package/dist/index.js.map +1 -1
- package/dist/registry.js +53 -7
- package/dist/registry.js.map +1 -1
- package/dist/renderer.js +53 -7
- package/dist/renderer.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -78,7 +78,30 @@ var STORABLE_BLOCK_TYPES = /* @__PURE__ */ new Set([
|
|
|
78
78
|
]);
|
|
79
79
|
|
|
80
80
|
// ../richtext/src/styled.ts
|
|
81
|
-
var STYLED_TAGS = [
|
|
81
|
+
var STYLED_TAGS = [
|
|
82
|
+
"span",
|
|
83
|
+
"small",
|
|
84
|
+
"sup",
|
|
85
|
+
"sub",
|
|
86
|
+
"kbd",
|
|
87
|
+
"abbr",
|
|
88
|
+
"time",
|
|
89
|
+
"strong",
|
|
90
|
+
"b",
|
|
91
|
+
"em",
|
|
92
|
+
"i",
|
|
93
|
+
"u",
|
|
94
|
+
"s",
|
|
95
|
+
"mark",
|
|
96
|
+
"code",
|
|
97
|
+
"q",
|
|
98
|
+
"cite",
|
|
99
|
+
"dfn",
|
|
100
|
+
"var",
|
|
101
|
+
"samp",
|
|
102
|
+
"ins",
|
|
103
|
+
"del"
|
|
104
|
+
];
|
|
82
105
|
var TAG_SET = new Set(STYLED_TAGS);
|
|
83
106
|
var isStyledTag = (tag) => typeof tag === "string" && TAG_SET.has(tag);
|
|
84
107
|
var ATTR_NAMES = /* @__PURE__ */ new Set(["title", "datetime", "style", "aria-label"]);
|
|
@@ -356,7 +379,7 @@ function Table({ value }) {
|
|
|
356
379
|
head < rows.length && /* @__PURE__ */ jsx2("tbody", { children: rendered.slice(head) })
|
|
357
380
|
] });
|
|
358
381
|
}
|
|
359
|
-
function buildComponents() {
|
|
382
|
+
function buildComponents(renderBlock) {
|
|
360
383
|
return {
|
|
361
384
|
types: {
|
|
362
385
|
[PT_TYPES.divider]: () => /* @__PURE__ */ jsx2("hr", {}),
|
|
@@ -370,9 +393,12 @@ function buildComponents() {
|
|
|
370
393
|
* A generic embedded block renders as a marker, not as content: its payload references
|
|
371
394
|
* something (a component, a media id) that has to be RESOLVED against the project, and
|
|
372
395
|
* this renderer has no project. A marker keeps the node visible and addressable rather
|
|
373
|
-
* than rendering nothing at all, which is how embedded content used to vanish.
|
|
396
|
+
* than rendering nothing at all, which is how embedded content used to vanish. A caller
|
|
397
|
+
* that CAN resolve it passes `renderBlock`.
|
|
374
398
|
*/
|
|
375
399
|
[PT_TYPES.block]: ({ value }) => {
|
|
400
|
+
const rendered = renderBlock?.(value);
|
|
401
|
+
if (rendered !== void 0) return /* @__PURE__ */ jsx2(Fragment, { children: rendered });
|
|
376
402
|
const v = value;
|
|
377
403
|
const key = typeof v.schemaKey === "string" ? v.schemaKey : "block";
|
|
378
404
|
return /* @__PURE__ */ jsx2("div", { className: "bcms-block", "data-bcms-schema-key": key });
|
|
@@ -442,12 +468,32 @@ function buildComponents() {
|
|
|
442
468
|
unknownBlockStyle: ({ children }) => /* @__PURE__ */ jsx2("p", { children })
|
|
443
469
|
};
|
|
444
470
|
}
|
|
445
|
-
|
|
471
|
+
var isListItem = (node) => node._type === "block" && typeof node.listItem === "string" && !!node.listItem;
|
|
472
|
+
function runsOf(blocks) {
|
|
473
|
+
const runs = [];
|
|
474
|
+
for (const node of blocks) {
|
|
475
|
+
const last = runs.at(-1);
|
|
476
|
+
if (last && isListItem(node) && isListItem(last[0])) last.push(node);
|
|
477
|
+
else runs.push([node]);
|
|
478
|
+
}
|
|
479
|
+
return runs;
|
|
480
|
+
}
|
|
481
|
+
function PortableText({ value, bindingBase, renderBlock }) {
|
|
446
482
|
const blocks = React.useMemo(() => normalizePortableText(readValue(value)), [value]);
|
|
447
|
-
const components = React.useMemo(buildComponents, []);
|
|
483
|
+
const components = React.useMemo(() => buildComponents(renderBlock), [renderBlock]);
|
|
484
|
+
const listComponents = React.useMemo(() => {
|
|
485
|
+
if (!bindingBase) return null;
|
|
486
|
+
const keys = new Set(blocks.map((b) => b._key));
|
|
487
|
+
return {
|
|
488
|
+
...components,
|
|
489
|
+
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 })
|
|
490
|
+
};
|
|
491
|
+
}, [bindingBase, blocks, components]);
|
|
448
492
|
if (blocks.length === 0) return null;
|
|
449
|
-
if (!bindingBase) return /* @__PURE__ */ jsx2(PT, { value: blocks, components });
|
|
450
|
-
return /* @__PURE__ */ jsx2(Fragment, { children: blocks.map(
|
|
493
|
+
if (!bindingBase || !listComponents) return /* @__PURE__ */ jsx2(PT, { value: blocks, components });
|
|
494
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: runsOf(blocks).map(
|
|
495
|
+
(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)
|
|
496
|
+
) });
|
|
451
497
|
}
|
|
452
498
|
function readValue(value) {
|
|
453
499
|
if (Array.isArray(value)) return value;
|