@contember/react-client 1.1.0-beta.4 → 1.1.0-rc.12
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/development/ContemberClient.js +23 -42
- package/dist/development/ContemberClient.js.map +1 -1
- package/dist/development/apiRequest/apiRequestReducer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/ElementRenderer.js +4 -13
- package/dist/development/components/RichTextRenderer/ElementRenderer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/LeafRenderer.js +12 -11
- package/dist/development/components/RichTextRenderer/LeafRenderer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RenderElementFallback.js +65 -113
- package/dist/development/components/RichTextRenderer/RenderElementFallback.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RenderLeafFallback.js +26 -38
- package/dist/development/components/RichTextRenderer/RenderLeafFallback.js.map +1 -1
- package/dist/development/components/RichTextRenderer/RichTextRenderer.js +55 -35
- package/dist/development/components/RichTextRenderer/RichTextRenderer.js.map +1 -1
- package/dist/development/components/RichTextRenderer/renderChildren.js +22 -28
- package/dist/development/components/RichTextRenderer/renderChildren.js.map +1 -1
- package/dist/development/upload/fileUploadReducer.js.map +1 -1
- package/dist/production/ContemberClient.js +2 -20
- package/dist/production/ContemberClient.js.map +1 -1
- package/dist/production/apiRequest/apiRequestReducer.js.map +1 -1
- package/dist/production/components/RichTextRenderer/ElementRenderer.js +3 -11
- package/dist/production/components/RichTextRenderer/ElementRenderer.js.map +1 -1
- package/dist/production/components/RichTextRenderer/LeafRenderer.js +11 -9
- package/dist/production/components/RichTextRenderer/LeafRenderer.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RenderElementFallback.js +34 -89
- package/dist/production/components/RichTextRenderer/RenderElementFallback.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RenderLeafFallback.js +13 -28
- package/dist/production/components/RichTextRenderer/RenderLeafFallback.js.map +1 -1
- package/dist/production/components/RichTextRenderer/RichTextRenderer.js +42 -32
- package/dist/production/components/RichTextRenderer/RichTextRenderer.js.map +1 -1
- package/dist/production/components/RichTextRenderer/renderChildren.js +10 -19
- package/dist/production/components/RichTextRenderer/renderChildren.js.map +1 -1
- package/dist/production/upload/fileUploadReducer.js.map +1 -1
- package/dist/types/apiRequest/ApiRequestAction.d.ts +1 -1
- package/dist/types/apiRequest/ApiRequestAction.d.ts.map +1 -1
- package/dist/types/apiRequest/ApiRequestState.d.ts +1 -1
- package/dist/types/apiRequest/ApiRequestState.d.ts.map +1 -1
- package/dist/types/apiRequest/apiRequestReducer.d.ts +1 -1
- package/dist/types/apiRequest/apiRequestReducer.d.ts.map +1 -1
- package/dist/types/apiRequest/useApiRequest.d.ts +1 -1
- package/dist/types/apiRequest/useApiRequest.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/BuiltinElements.d.ts +1 -1
- package/dist/types/components/RichTextRenderer/BuiltinElements.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/BuiltinLeaves.d.ts +1 -1
- package/dist/types/components/RichTextRenderer/BuiltinLeaves.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/ElementRenderer.d.ts +1 -1
- package/dist/types/components/RichTextRenderer/ElementRenderer.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/LeafRenderer.d.ts +1 -1
- package/dist/types/components/RichTextRenderer/LeafRenderer.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/ReferenceRenderer.d.ts +2 -2
- package/dist/types/components/RichTextRenderer/ReferenceRenderer.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/RichTextBlock.d.ts +1 -1
- package/dist/types/components/RichTextRenderer/RichTextBlock.d.ts.map +1 -1
- package/dist/types/components/RichTextRenderer/RichTextRenderer.d.ts +1 -1
- package/dist/types/components/RichTextRenderer/RichTextRenderer.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/upload/FileId.d.ts +1 -1
- package/dist/types/upload/FileId.d.ts.map +1 -1
- package/dist/types/upload/FileUploadAction.d.ts +1 -1
- package/dist/types/upload/FileUploadAction.d.ts.map +1 -1
- package/dist/types/upload/FileUploadCompoundState.d.ts +1 -1
- package/dist/types/upload/FileUploadCompoundState.d.ts.map +1 -1
- package/dist/types/upload/FileUploadOperations.d.ts +4 -4
- package/dist/types/upload/FileUploadOperations.d.ts.map +1 -1
- package/dist/types/upload/SingleFileUploadState.d.ts +1 -1
- package/dist/types/upload/SingleFileUploadState.d.ts.map +1 -1
- package/dist/types/upload/useFileUpload.d.ts +1 -1
- package/dist/types/upload/useFileUpload.d.ts.map +1 -1
- package/package.json +11 -10
- package/src/components/RichTextRenderer/RichTextRenderer.tsx +1 -1
- package/LICENSE +0 -186
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LeafRenderer.js","sources":["../../../../src/components/RichTextRenderer/LeafRenderer.tsx"],"sourcesContent":["import type { ComponentType, ReactElement } from 'react'\nimport { createElement } from 'react'\nimport type { BuiltinLeaves } from './BuiltinLeaves'\nimport { RenderLeafFallback } from './RenderLeafFallback'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextLeafMetadata } from './RichTextLeafMetadata'\nimport { useRichTextRenderMetadata } from './RichTextRenderMetadataContext'\n\nexport type RenderLeaf<CustomLeaves extends RichTextLeaf> = ComponentType<\n\t{\n\t\tleaf: CustomLeaves | BuiltinLeaves\n\t\tfallback: ReactElement\n\t} & RichTextLeafMetadata\n>\n\nexport interface LeafRendererProps<CustomLeaves extends RichTextLeaf = never> {\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tleaf: CustomLeaves | BuiltinLeaves\n}\n\nexport function LeafRenderer<CustomLeaves extends RichTextLeaf = never>({\n\tleaf,\n\trenderLeaf,\n}: LeafRendererProps<CustomLeaves>) {\n\tconst formatVersion = useRichTextRenderMetadata().formatVersion\n\tconst fallback = <RenderLeafFallback leaf={leaf} />\n\n\treturn renderLeaf\n\t\t? createElement(\n\t\t\t\trenderLeaf,\n\t\t\t\t{\n\t\t\t\t\tformatVersion,\n\t\t\t\t\tleaf,\n\t\t\t\t\tfallback,\n\t\t\t\t},\n\t\t\t\tleaf.text,\n\t\t )\n\t\t: fallback\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"LeafRenderer.js","sources":["../../../../src/components/RichTextRenderer/LeafRenderer.tsx"],"sourcesContent":["import type { ComponentType, ReactElement } from 'react'\nimport { createElement } from 'react'\nimport type { BuiltinLeaves } from './BuiltinLeaves'\nimport { RenderLeafFallback } from './RenderLeafFallback'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextLeafMetadata } from './RichTextLeafMetadata'\nimport { useRichTextRenderMetadata } from './RichTextRenderMetadataContext'\n\nexport type RenderLeaf<CustomLeaves extends RichTextLeaf> = ComponentType<\n\t{\n\t\tleaf: CustomLeaves | BuiltinLeaves\n\t\tfallback: ReactElement\n\t} & RichTextLeafMetadata\n>\n\nexport interface LeafRendererProps<CustomLeaves extends RichTextLeaf = never> {\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tleaf: CustomLeaves | BuiltinLeaves\n}\n\nexport function LeafRenderer<CustomLeaves extends RichTextLeaf = never>({\n\tleaf,\n\trenderLeaf,\n}: LeafRendererProps<CustomLeaves>) {\n\tconst formatVersion = useRichTextRenderMetadata().formatVersion\n\tconst fallback = <RenderLeafFallback leaf={leaf} />\n\n\treturn renderLeaf\n\t\t? createElement(\n\t\t\t\trenderLeaf,\n\t\t\t\t{\n\t\t\t\t\tformatVersion,\n\t\t\t\t\tleaf,\n\t\t\t\t\tfallback,\n\t\t\t\t},\n\t\t\t\tleaf.text,\n\t\t )\n\t\t: fallback\n}\n"],"names":[],"mappings":";;;;AAoBO,SAAS,aAAwD;AAAA,EACvE;AAAA,EACA;AACD,GAAoC;AAC7B,QAAA,gBAAgB,0BAA4B,EAAA;AAC5C,QAAA,WAAY,oBAAA,oBAAA,EAAmB,KAAY,CAAA;AAEjD,SAAO,aACJ;AAAA,IACA;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA,KAAK;AAAA,EAEL,IAAA;AACJ;"}
|
|
@@ -1,107 +1,57 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
1
2
|
import { createElement } from "react";
|
|
2
3
|
import { renderChildren } from "./renderChildren.js";
|
|
3
4
|
import { resolveRichTextElementMetadata } from "./resolveRichTextElementMetadata.js";
|
|
4
5
|
import { useRichTextRenderMetadata } from "./RichTextRenderMetadataContext.js";
|
|
5
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
6
6
|
const getElementDataAttributes = (element, attributeNamePrefix = "contember-") => {
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return t === "string" || t === "number" || t === "boolean";
|
|
15
|
-
}).map(([attribute, value]) => [`data-${attributeNamePrefix}${attribute.toLowerCase()}`, value]));
|
|
7
|
+
const { children, referenceId, ...extendedSpecifics } = element;
|
|
8
|
+
return Object.fromEntries(
|
|
9
|
+
Object.entries(extendedSpecifics).filter(([, value]) => {
|
|
10
|
+
const t = typeof value;
|
|
11
|
+
return t === "string" || t === "number" || t === "boolean";
|
|
12
|
+
}).map(([attribute, value]) => [`data-${attributeNamePrefix}${attribute.toLowerCase()}`, value])
|
|
13
|
+
);
|
|
16
14
|
};
|
|
17
|
-
function RenderElementFallback({
|
|
18
|
-
element,
|
|
19
|
-
children,
|
|
20
|
-
options
|
|
21
|
-
}) {
|
|
15
|
+
function RenderElementFallback({ element, children, options }) {
|
|
22
16
|
const attributes = getElementDataAttributes(element, options.attributeNamePrefix);
|
|
23
17
|
switch (element.type) {
|
|
24
18
|
case "anchor":
|
|
25
|
-
return /* @__PURE__ */ jsx("a", {
|
|
26
|
-
...attributes,
|
|
27
|
-
href: element.href,
|
|
28
|
-
children
|
|
29
|
-
});
|
|
19
|
+
return /* @__PURE__ */ jsx("a", { ...attributes, href: element.href, children });
|
|
30
20
|
case "heading":
|
|
31
21
|
return createElement(`h${element.level}`, attributes, children);
|
|
32
22
|
case "horizontalRule":
|
|
33
|
-
return /* @__PURE__ */ jsx("hr", {
|
|
34
|
-
...attributes
|
|
35
|
-
});
|
|
23
|
+
return /* @__PURE__ */ jsx("hr", { ...attributes });
|
|
36
24
|
case "listItem":
|
|
37
|
-
return /* @__PURE__ */ jsx("li", {
|
|
38
|
-
...attributes,
|
|
39
|
-
children
|
|
40
|
-
});
|
|
25
|
+
return /* @__PURE__ */ jsx("li", { ...attributes, children });
|
|
41
26
|
case "orderedList":
|
|
42
|
-
return /* @__PURE__ */ jsx("ol", {
|
|
43
|
-
...attributes,
|
|
44
|
-
children
|
|
45
|
-
});
|
|
27
|
+
return /* @__PURE__ */ jsx("ol", { ...attributes, children });
|
|
46
28
|
case "paragraph":
|
|
47
|
-
return /* @__PURE__ */ jsx("p", {
|
|
48
|
-
...attributes,
|
|
49
|
-
children
|
|
50
|
-
});
|
|
29
|
+
return /* @__PURE__ */ jsx("p", { ...attributes, children });
|
|
51
30
|
case "reference": {
|
|
52
|
-
return /* @__PURE__ */ jsx(ReferenceElementFallback, {
|
|
53
|
-
element,
|
|
54
|
-
children
|
|
55
|
-
});
|
|
31
|
+
return /* @__PURE__ */ jsx(ReferenceElementFallback, { element, children });
|
|
56
32
|
}
|
|
57
33
|
case "scrollTarget":
|
|
58
|
-
return /* @__PURE__ */ jsx("span", {
|
|
59
|
-
...attributes,
|
|
60
|
-
id: element.identifier,
|
|
61
|
-
children
|
|
62
|
-
});
|
|
34
|
+
return /* @__PURE__ */ jsx("span", { ...attributes, id: element.identifier, children });
|
|
63
35
|
case "table": {
|
|
64
36
|
const firstRow = element.children[0];
|
|
65
37
|
if (!firstRow || firstRow.headerScope !== "table") {
|
|
66
|
-
return /* @__PURE__ */ jsx("table", {
|
|
67
|
-
...attributes,
|
|
68
|
-
children: /* @__PURE__ */ jsx("tbody", {
|
|
69
|
-
children
|
|
70
|
-
})
|
|
71
|
-
});
|
|
38
|
+
return /* @__PURE__ */ jsx("table", { ...attributes, children: /* @__PURE__ */ jsx("tbody", { children }) });
|
|
72
39
|
}
|
|
73
|
-
return /* @__PURE__ */ jsxs("table", {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}), /* @__PURE__ */ jsx("tbody", {
|
|
78
|
-
children: renderChildren(element.children.slice(1), options)
|
|
79
|
-
})]
|
|
80
|
-
});
|
|
40
|
+
return /* @__PURE__ */ jsxs("table", { ...attributes, children: [
|
|
41
|
+
/* @__PURE__ */ jsx("thead", { children: renderChildren([firstRow], options) }),
|
|
42
|
+
/* @__PURE__ */ jsx("tbody", { children: renderChildren(element.children.slice(1), options) })
|
|
43
|
+
] });
|
|
81
44
|
}
|
|
82
45
|
case "tableRow":
|
|
83
|
-
return /* @__PURE__ */ jsx("tr", {
|
|
84
|
-
...attributes,
|
|
85
|
-
children
|
|
86
|
-
});
|
|
46
|
+
return /* @__PURE__ */ jsx("tr", { ...attributes, children });
|
|
87
47
|
case "tableCell": {
|
|
88
48
|
if (element.headerScope) {
|
|
89
|
-
return /* @__PURE__ */ jsx("th", {
|
|
90
|
-
...attributes,
|
|
91
|
-
scope: element.headerScope,
|
|
92
|
-
children
|
|
93
|
-
});
|
|
49
|
+
return /* @__PURE__ */ jsx("th", { ...attributes, scope: element.headerScope, children });
|
|
94
50
|
}
|
|
95
|
-
return /* @__PURE__ */ jsx("td", {
|
|
96
|
-
...attributes,
|
|
97
|
-
children
|
|
98
|
-
});
|
|
51
|
+
return /* @__PURE__ */ jsx("td", { ...attributes, children });
|
|
99
52
|
}
|
|
100
53
|
case "unorderedList":
|
|
101
|
-
return /* @__PURE__ */ jsx("ul", {
|
|
102
|
-
...attributes,
|
|
103
|
-
children
|
|
104
|
-
});
|
|
54
|
+
return /* @__PURE__ */ jsx("ul", { ...attributes, children });
|
|
105
55
|
default: {
|
|
106
56
|
{
|
|
107
57
|
return children;
|
|
@@ -109,10 +59,7 @@ function RenderElementFallback({
|
|
|
109
59
|
}
|
|
110
60
|
}
|
|
111
61
|
}
|
|
112
|
-
function ReferenceElementFallback({
|
|
113
|
-
element,
|
|
114
|
-
children
|
|
115
|
-
}) {
|
|
62
|
+
function ReferenceElementFallback({ element, children }) {
|
|
116
63
|
const metadata = useRichTextRenderMetadata();
|
|
117
64
|
const elementMetadata = resolveRichTextElementMetadata(element, metadata);
|
|
118
65
|
if (elementMetadata.referenceRenderer === void 0 || elementMetadata.referenceType === void 0 || elementMetadata.reference === void 0) {
|
|
@@ -120,16 +67,14 @@ function ReferenceElementFallback({
|
|
|
120
67
|
return children;
|
|
121
68
|
}
|
|
122
69
|
}
|
|
123
|
-
return /* @__PURE__ */ jsx(Fragment, {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
})
|
|
132
|
-
});
|
|
70
|
+
return /* @__PURE__ */ jsx(Fragment, { children: elementMetadata.referenceRenderer?.({
|
|
71
|
+
referenceType: elementMetadata.referenceType,
|
|
72
|
+
referenceRenderer: elementMetadata.referenceRenderer,
|
|
73
|
+
reference: elementMetadata.reference,
|
|
74
|
+
formatVersion: elementMetadata.formatVersion,
|
|
75
|
+
element,
|
|
76
|
+
children
|
|
77
|
+
}) });
|
|
133
78
|
}
|
|
134
79
|
export {
|
|
135
80
|
RenderElementFallback
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderElementFallback.js","sources":["../../../../src/components/RichTextRenderer/RenderElementFallback.tsx"],"sourcesContent":["import { createElement, ReactElement } from 'react'\nimport type { BuiltinElements, RichTextReferenceElement, RichTextTableRowElement } from './BuiltinElements'\nimport { renderChildren, RenderChildrenOptions } from './renderChildren'\nimport { resolveRichTextElementMetadata } from './resolveRichTextElementMetadata'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { useRichTextRenderMetadata } from './RichTextRenderMetadataContext'\n\nexport interface RenderElementFallbackProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\telement: BuiltinElements<CustomElements, CustomLeaves>\n\tchildren: ReactElement\n\toptions: RenderChildrenOptions<CustomElements, CustomLeaves>\n}\n\nconst getElementDataAttributes = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>(\n\telement: RichTextElement<CustomElements, CustomLeaves>,\n\tattributeNamePrefix: string = 'contember-',\n): {\n\t[dataAttribute: string]: string | number | boolean\n} => {\n\tconst { children, referenceId, ...extendedSpecifics } = element\n\n\treturn Object.fromEntries(\n\t\tObject.entries(extendedSpecifics)\n\t\t\t.filter(([, value]) => {\n\t\t\t\tconst t = typeof value\n\t\t\t\treturn t === 'string' || t === 'number' || t === 'boolean'\n\t\t\t})\n\t\t\t.map(([attribute, value]) => [`data-${attributeNamePrefix}${attribute.toLowerCase()}`, value]),\n\t)\n}\n\nexport function RenderElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({ element, children, options }: RenderElementFallbackProps<CustomElements, CustomLeaves>) {\n\tconst attributes = getElementDataAttributes(element, options.attributeNamePrefix)\n\n\tswitch (element.type) {\n\t\tcase 'anchor':\n\t\t\treturn (\n\t\t\t\t<a {...attributes} href={element.href}>\n\t\t\t\t\t{children}\n\t\t\t\t</a>\n\t\t\t)\n\t\tcase 'heading':\n\t\t\treturn createElement(`h${element.level}`, attributes, children) // TODO numbered\n\t\tcase 'horizontalRule':\n\t\t\treturn <hr {...attributes} />\n\t\tcase 'listItem':\n\t\t\treturn <li {...attributes}>{children}</li>\n\t\tcase 'orderedList':\n\t\t\treturn <ol {...attributes}>{children}</ol>\n\t\tcase 'paragraph':\n\t\t\treturn <p {...attributes}>{children}</p>\n\t\tcase 'reference': {\n\t\t\treturn <ReferenceElementFallback element={element} children={children} />\n\t\t}\n\t\tcase 'scrollTarget':\n\t\t\treturn (\n\t\t\t\t<span {...attributes} id={element.identifier}>\n\t\t\t\t\t{children}\n\t\t\t\t</span>\n\t\t\t)\n\t\tcase 'table': {\n\t\t\tconst firstRow = element.children[0] as RichTextTableRowElement<CustomElements, CustomLeaves> | undefined\n\t\t\tif (!firstRow || firstRow.headerScope !== 'table') {\n\t\t\t\treturn (\n\t\t\t\t\t<table {...attributes}>\n\t\t\t\t\t\t<tbody>{children}</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn (\n\t\t\t\t<table {...attributes}>\n\t\t\t\t\t<thead>{renderChildren<CustomElements, CustomLeaves>([firstRow], options)}</thead>\n\t\t\t\t\t<tbody>{renderChildren<CustomElements, CustomLeaves>(element.children.slice(1) as any, options)}</tbody>\n\t\t\t\t</table>\n\t\t\t)\n\t\t}\n\t\tcase 'tableRow':\n\t\t\treturn <tr {...attributes}>{children}</tr>\n\t\tcase 'tableCell': {\n\t\t\tif (element.headerScope) {\n\t\t\t\treturn (\n\t\t\t\t\t<th {...attributes} scope={element.headerScope}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</th>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn <td {...attributes}>{children}</td>\n\t\t}\n\t\tcase 'unorderedList':\n\t\t\treturn <ul {...attributes}>{children}</ul>\n\t\tdefault: {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t`RichTextRenderer: unknown element of type '${(element as { type: string }).type}'.`,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\treturn children // At least render the text contents\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction ReferenceElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({ element, children }: { element: RichTextReferenceElement<CustomElements, CustomLeaves>; children: ReactElement }) {\n\tconst metadata = useRichTextRenderMetadata<CustomElements, CustomLeaves>()\n\tconst elementMetadata = resolveRichTextElementMetadata<CustomElements, CustomLeaves>(element, metadata)\n\n\tif (\n\t\telementMetadata.referenceRenderer === undefined ||\n\t\telementMetadata.referenceType === undefined ||\n\t\telementMetadata.reference === undefined\n\t) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new RichTextRendererError(\n\t\t\t\t`RichTextRenderer: cannot render reference of type '${elementMetadata.referenceType}'.`,\n\t\t\t)\n\t\t} else {\n\t\t\treturn children // At least render the text contents\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{elementMetadata.referenceRenderer?.({\n\t\t\t\treferenceType: elementMetadata.referenceType,\n\t\t\t\treferenceRenderer: elementMetadata.referenceRenderer,\n\t\t\t\treference: elementMetadata.reference,\n\t\t\t\tformatVersion: elementMetadata.formatVersion,\n\t\t\t\telement,\n\t\t\t\tchildren,\n\t\t\t})}\n\t\t</>\n\t)\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"RenderElementFallback.js","sources":["../../../../src/components/RichTextRenderer/RenderElementFallback.tsx"],"sourcesContent":["import { createElement, ReactElement } from 'react'\nimport type { BuiltinElements, RichTextReferenceElement, RichTextTableRowElement } from './BuiltinElements'\nimport { renderChildren, RenderChildrenOptions } from './renderChildren'\nimport { resolveRichTextElementMetadata } from './resolveRichTextElementMetadata'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { useRichTextRenderMetadata } from './RichTextRenderMetadataContext'\n\nexport interface RenderElementFallbackProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\telement: BuiltinElements<CustomElements, CustomLeaves>\n\tchildren: ReactElement\n\toptions: RenderChildrenOptions<CustomElements, CustomLeaves>\n}\n\nconst getElementDataAttributes = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>(\n\telement: RichTextElement<CustomElements, CustomLeaves>,\n\tattributeNamePrefix: string = 'contember-',\n): {\n\t[dataAttribute: string]: string | number | boolean\n} => {\n\tconst { children, referenceId, ...extendedSpecifics } = element\n\n\treturn Object.fromEntries(\n\t\tObject.entries(extendedSpecifics)\n\t\t\t.filter(([, value]) => {\n\t\t\t\tconst t = typeof value\n\t\t\t\treturn t === 'string' || t === 'number' || t === 'boolean'\n\t\t\t})\n\t\t\t.map(([attribute, value]) => [`data-${attributeNamePrefix}${attribute.toLowerCase()}`, value]),\n\t)\n}\n\nexport function RenderElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({ element, children, options }: RenderElementFallbackProps<CustomElements, CustomLeaves>) {\n\tconst attributes = getElementDataAttributes(element, options.attributeNamePrefix)\n\n\tswitch (element.type) {\n\t\tcase 'anchor':\n\t\t\treturn (\n\t\t\t\t<a {...attributes} href={element.href}>\n\t\t\t\t\t{children}\n\t\t\t\t</a>\n\t\t\t)\n\t\tcase 'heading':\n\t\t\treturn createElement(`h${element.level}`, attributes, children) // TODO numbered\n\t\tcase 'horizontalRule':\n\t\t\treturn <hr {...attributes} />\n\t\tcase 'listItem':\n\t\t\treturn <li {...attributes}>{children}</li>\n\t\tcase 'orderedList':\n\t\t\treturn <ol {...attributes}>{children}</ol>\n\t\tcase 'paragraph':\n\t\t\treturn <p {...attributes}>{children}</p>\n\t\tcase 'reference': {\n\t\t\treturn <ReferenceElementFallback element={element} children={children} />\n\t\t}\n\t\tcase 'scrollTarget':\n\t\t\treturn (\n\t\t\t\t<span {...attributes} id={element.identifier}>\n\t\t\t\t\t{children}\n\t\t\t\t</span>\n\t\t\t)\n\t\tcase 'table': {\n\t\t\tconst firstRow = element.children[0] as RichTextTableRowElement<CustomElements, CustomLeaves> | undefined\n\t\t\tif (!firstRow || firstRow.headerScope !== 'table') {\n\t\t\t\treturn (\n\t\t\t\t\t<table {...attributes}>\n\t\t\t\t\t\t<tbody>{children}</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn (\n\t\t\t\t<table {...attributes}>\n\t\t\t\t\t<thead>{renderChildren<CustomElements, CustomLeaves>([firstRow], options)}</thead>\n\t\t\t\t\t<tbody>{renderChildren<CustomElements, CustomLeaves>(element.children.slice(1) as any, options)}</tbody>\n\t\t\t\t</table>\n\t\t\t)\n\t\t}\n\t\tcase 'tableRow':\n\t\t\treturn <tr {...attributes}>{children}</tr>\n\t\tcase 'tableCell': {\n\t\t\tif (element.headerScope) {\n\t\t\t\treturn (\n\t\t\t\t\t<th {...attributes} scope={element.headerScope}>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</th>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn <td {...attributes}>{children}</td>\n\t\t}\n\t\tcase 'unorderedList':\n\t\t\treturn <ul {...attributes}>{children}</ul>\n\t\tdefault: {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t`RichTextRenderer: unknown element of type '${(element as { type: string }).type}'.`,\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\treturn children // At least render the text contents\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction ReferenceElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({ element, children }: { element: RichTextReferenceElement<CustomElements, CustomLeaves>; children: ReactElement }) {\n\tconst metadata = useRichTextRenderMetadata<CustomElements, CustomLeaves>()\n\tconst elementMetadata = resolveRichTextElementMetadata<CustomElements, CustomLeaves>(element, metadata)\n\n\tif (\n\t\telementMetadata.referenceRenderer === undefined ||\n\t\telementMetadata.referenceType === undefined ||\n\t\telementMetadata.reference === undefined\n\t) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new RichTextRendererError(\n\t\t\t\t`RichTextRenderer: cannot render reference of type '${elementMetadata.referenceType}'.`,\n\t\t\t)\n\t\t} else {\n\t\t\treturn children // At least render the text contents\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{elementMetadata.referenceRenderer?.({\n\t\t\t\treferenceType: elementMetadata.referenceType,\n\t\t\t\treferenceRenderer: elementMetadata.referenceRenderer,\n\t\t\t\treference: elementMetadata.reference,\n\t\t\t\tformatVersion: elementMetadata.formatVersion,\n\t\t\t\telement,\n\t\t\t\tchildren,\n\t\t\t})}\n\t\t</>\n\t)\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,2BAA2B,CAIhC,SACA,sBAA8B,iBAG1B;AACJ,QAAM,EAAE,UAAU,gBAAgB,kBAAA,IAAsB;AAExD,SAAO,OAAO;AAAA,IACb,OAAO,QAAQ,iBAAiB,EAC9B,OAAO,CAAC,CAAG,EAAA,KAAK,MAAM;AACtB,YAAM,IAAI,OAAO;AACjB,aAAO,MAAM,YAAY,MAAM,YAAY,MAAM;AAAA,IACjD,CAAA,EACA,IAAI,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,QAAQ,sBAAsB,UAAU,YAAY,KAAK,KAAK,CAAC;AAAA,EAAA;AAEhG;AAEO,SAAS,sBAGd,EAAE,SAAS,UAAU,WAAqE;AAC3F,QAAM,aAAa,yBAAyB,SAAS,QAAQ,mBAAmB;AAEhF,UAAQ,QAAQ,MAAM;AAAA,IACrB,KAAK;AACJ,iCACE,KAAG,EAAA,GAAG,YAAY,MAAM,QAAQ,MAC/B,SACF,CAAA;AAAA,IAEF,KAAK;AACJ,aAAO,cAAc,IAAI,QAAQ,SAAS,YAAY,QAAQ;AAAA,IAC/D,KAAK;AACG,aAAA,oBAAC,MAAI,EAAA,GAAG,WAAY,CAAA;AAAA,IAC5B,KAAK;AACJ,aAAQ,oBAAA,MAAA,EAAI,GAAG,YAAa,SAAS,CAAA;AAAA,IACtC,KAAK;AACJ,aAAQ,oBAAA,MAAA,EAAI,GAAG,YAAa,SAAS,CAAA;AAAA,IACtC,KAAK;AACJ,aAAQ,oBAAA,KAAA,EAAG,GAAG,YAAa,SAAS,CAAA;AAAA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ACD;AAGC,SAAA,oBAAA,UAAA,EACE,0BAAgB,oBAAoB;AAAA,IACpC,eAAe,gBAAgB;AAAA,IAC/B,mBAAmB,gBAAgB;AAAA,IACnC,WAAW,gBAAgB;AAAA,IAC3B,eAAe,gBAAgB;AAAA,IAC/B;AAAA,IACA;AAAA,EACA,CAAA,EACF,CAAA;AAEF;"}
|
|
@@ -1,51 +1,36 @@
|
|
|
1
|
-
import { Fragment as Fragment$1 } from "react";
|
|
2
1
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment as Fragment$1 } from "react";
|
|
3
3
|
function jsxN2br(text) {
|
|
4
4
|
const lines = text.split("\n");
|
|
5
5
|
if (lines.length <= 1) {
|
|
6
6
|
return text;
|
|
7
7
|
}
|
|
8
|
-
return lines.map((line, i) => /* @__PURE__ */ jsxs(Fragment$1, {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
return lines.map((line, i) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
9
|
+
!!i && /* @__PURE__ */ jsx("br", {}),
|
|
10
|
+
line
|
|
11
|
+
] }, i));
|
|
11
12
|
}
|
|
12
|
-
function RenderLeafFallback({
|
|
13
|
-
leaf
|
|
14
|
-
}) {
|
|
13
|
+
function RenderLeafFallback({ leaf }) {
|
|
15
14
|
let element = jsxN2br(leaf.text);
|
|
16
15
|
if ("isCode" in leaf && leaf.isCode === true) {
|
|
17
|
-
element = /* @__PURE__ */ jsx("code", {
|
|
18
|
-
children: element
|
|
19
|
-
});
|
|
16
|
+
element = /* @__PURE__ */ jsx("code", { children: element });
|
|
20
17
|
}
|
|
21
18
|
if ("isStruckThrough" in leaf && leaf.isStruckThrough === true) {
|
|
22
|
-
element = /* @__PURE__ */ jsx("s", {
|
|
23
|
-
children: element
|
|
24
|
-
});
|
|
19
|
+
element = /* @__PURE__ */ jsx("s", { children: element });
|
|
25
20
|
}
|
|
26
21
|
if ("isHighlighted" in leaf && leaf.isHighlighted === true) {
|
|
27
|
-
element = /* @__PURE__ */ jsx("em", {
|
|
28
|
-
children: element
|
|
29
|
-
});
|
|
22
|
+
element = /* @__PURE__ */ jsx("em", { children: element });
|
|
30
23
|
}
|
|
31
24
|
if ("isUnderlined" in leaf && leaf.isUnderlined === true) {
|
|
32
|
-
element = /* @__PURE__ */ jsx("u", {
|
|
33
|
-
children: element
|
|
34
|
-
});
|
|
25
|
+
element = /* @__PURE__ */ jsx("u", { children: element });
|
|
35
26
|
}
|
|
36
27
|
if ("isItalic" in leaf && leaf.isItalic === true) {
|
|
37
|
-
element = /* @__PURE__ */ jsx("i", {
|
|
38
|
-
children: element
|
|
39
|
-
});
|
|
28
|
+
element = /* @__PURE__ */ jsx("i", { children: element });
|
|
40
29
|
}
|
|
41
30
|
if ("isBold" in leaf && leaf.isBold === true) {
|
|
42
|
-
element = /* @__PURE__ */ jsx("b", {
|
|
43
|
-
children: element
|
|
44
|
-
});
|
|
31
|
+
element = /* @__PURE__ */ jsx("b", { children: element });
|
|
45
32
|
}
|
|
46
|
-
return /* @__PURE__ */ jsx(Fragment, {
|
|
47
|
-
children: element
|
|
48
|
-
});
|
|
33
|
+
return /* @__PURE__ */ jsx(Fragment, { children: element });
|
|
49
34
|
}
|
|
50
35
|
export {
|
|
51
36
|
RenderLeafFallback
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderLeafFallback.js","sources":["../../../../src/components/RichTextRenderer/RenderLeafFallback.tsx"],"sourcesContent":["import { Fragment, ReactNode } from 'react'\nimport type { BuiltinLeaves } from './BuiltinLeaves'\n\nexport interface RenderLeafFallbackProps {\n\tleaf: BuiltinLeaves\n}\n\nfunction jsxN2br(text: string): ReactNode {\n\tconst lines = text.split('\\n')\n\tif (lines.length <= 1) {\n\t\treturn text\n\t}\n\treturn lines.map((line, i) => (\n\t\t<Fragment key={i}>\n\t\t\t{!!i && <br />}\n\t\t\t{line}\n\t\t</Fragment>\n\t))\n}\n\nexport function RenderLeafFallback({ leaf }: RenderLeafFallbackProps) {\n\tlet element = jsxN2br(leaf.text)\n\n\tif ('isCode' in leaf && leaf.isCode === true) {\n\t\telement = <code>{element}</code>\n\t}\n\tif ('isStruckThrough' in leaf && leaf.isStruckThrough === true) {\n\t\telement = <s>{element}</s>\n\t}\n\tif ('isHighlighted' in leaf && leaf.isHighlighted === true) {\n\t\telement = <em>{element}</em>\n\t}\n\tif ('isUnderlined' in leaf && leaf.isUnderlined === true) {\n\t\telement = <u>{element}</u>\n\t}\n\tif ('isItalic' in leaf && leaf.isItalic === true) {\n\t\telement = <i>{element}</i>\n\t}\n\tif ('isBold' in leaf && leaf.isBold === true) {\n\t\telement = <b>{element}</b>\n\t}\n\treturn <>{element}</>\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"RenderLeafFallback.js","sources":["../../../../src/components/RichTextRenderer/RenderLeafFallback.tsx"],"sourcesContent":["import { Fragment, ReactNode } from 'react'\nimport type { BuiltinLeaves } from './BuiltinLeaves'\n\nexport interface RenderLeafFallbackProps {\n\tleaf: BuiltinLeaves\n}\n\nfunction jsxN2br(text: string): ReactNode {\n\tconst lines = text.split('\\n')\n\tif (lines.length <= 1) {\n\t\treturn text\n\t}\n\treturn lines.map((line, i) => (\n\t\t<Fragment key={i}>\n\t\t\t{!!i && <br />}\n\t\t\t{line}\n\t\t</Fragment>\n\t))\n}\n\nexport function RenderLeafFallback({ leaf }: RenderLeafFallbackProps) {\n\tlet element = jsxN2br(leaf.text)\n\n\tif ('isCode' in leaf && leaf.isCode === true) {\n\t\telement = <code>{element}</code>\n\t}\n\tif ('isStruckThrough' in leaf && leaf.isStruckThrough === true) {\n\t\telement = <s>{element}</s>\n\t}\n\tif ('isHighlighted' in leaf && leaf.isHighlighted === true) {\n\t\telement = <em>{element}</em>\n\t}\n\tif ('isUnderlined' in leaf && leaf.isUnderlined === true) {\n\t\telement = <u>{element}</u>\n\t}\n\tif ('isItalic' in leaf && leaf.isItalic === true) {\n\t\telement = <i>{element}</i>\n\t}\n\tif ('isBold' in leaf && leaf.isBold === true) {\n\t\telement = <b>{element}</b>\n\t}\n\treturn <>{element}</>\n}\n"],"names":["Fragment"],"mappings":";;AAOA,SAAS,QAAQ,MAAyB;AACnC,QAAA,QAAQ,KAAK,MAAM,IAAI;AACzB,MAAA,MAAM,UAAU,GAAG;AACf,WAAA;AAAA,EACR;AACA,SAAO,MAAM,IAAI,CAAC,MAAM,MACvB,qBAACA,YAAA,EACC,UAAA;AAAA,IAAC,CAAA,CAAC,KAAK,oBAAC,MAAG,CAAA,CAAA;AAAA,IACX;AAAA,EAAA,EAAA,GAFa,CAGf,CACA;AACF;AAEgB,SAAA,mBAAmB,EAAE,QAAiC;AACjE,MAAA,UAAU,QAAQ,KAAK,IAAI;AAE/B,MAAI,YAAY,QAAQ,KAAK,WAAW,MAAM;AACnC,cAAA,oBAAC,UAAM,UAAQ,QAAA,CAAA;AAAA,EAC1B;AACA,MAAI,qBAAqB,QAAQ,KAAK,oBAAoB,MAAM;AACrD,cAAA,oBAAC,OAAG,UAAQ,QAAA,CAAA;AAAA,EACvB;AACA,MAAI,mBAAmB,QAAQ,KAAK,kBAAkB,MAAM;AACjD,cAAA,oBAAC,QAAI,UAAQ,QAAA,CAAA;AAAA,EACxB;AACA,MAAI,kBAAkB,QAAQ,KAAK,iBAAiB,MAAM;AAC/C,cAAA,oBAAC,OAAG,UAAQ,QAAA,CAAA;AAAA,EACvB;AACA,MAAI,cAAc,QAAQ,KAAK,aAAa,MAAM;AACvC,cAAA,oBAAC,OAAG,UAAQ,QAAA,CAAA;AAAA,EACvB;AACA,MAAI,YAAY,QAAQ,KAAK,WAAW,MAAM;AACnC,cAAA,oBAAC,OAAG,UAAQ,QAAA,CAAA;AAAA,EACvB;AACA,yCAAU,UAAQ,QAAA,CAAA;AACnB;"}
|
|
@@ -1,49 +1,51 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
1
2
|
import { memo, useMemo, createElement } from "react";
|
|
2
3
|
import { defaultDeserialize } from "./defaultDeserialize.js";
|
|
3
4
|
import { renderChildren } from "./renderChildren.js";
|
|
4
5
|
import { RichTextRendererError } from "./RichTextRendererError.js";
|
|
5
6
|
import { RichTextRenderMetadataContext } from "./RichTextRenderMetadataContext.js";
|
|
6
|
-
import { jsx, Fragment } from "react/jsx-runtime";
|
|
7
7
|
const RichTextRenderer = memo(function RichTextRenderer2({
|
|
8
8
|
deserialize = defaultDeserialize,
|
|
9
9
|
renderElement,
|
|
10
10
|
renderLeaf,
|
|
11
|
-
renderBlock = ({
|
|
12
|
-
children
|
|
13
|
-
}) => /* @__PURE__ */ jsx(Fragment, {
|
|
14
|
-
children
|
|
15
|
-
}),
|
|
11
|
+
renderBlock = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children }),
|
|
16
12
|
attributeNamePrefix,
|
|
17
13
|
...sourceProps
|
|
18
14
|
}) {
|
|
19
15
|
const normalizedSource = useMemo(() => {
|
|
20
16
|
if ("source" in sourceProps && !("blocks" in sourceProps)) {
|
|
21
|
-
return [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
content: sourceProps.source ? deserialize(sourceProps.source) : {
|
|
20
|
+
formatVersion: 0,
|
|
21
|
+
children: []
|
|
22
|
+
},
|
|
23
|
+
id: void 0,
|
|
24
|
+
referencesField: void 0,
|
|
25
|
+
referenceDiscriminationField: void 0,
|
|
26
|
+
referenceRenderers: {},
|
|
27
|
+
references: void 0
|
|
28
|
+
}
|
|
29
|
+
];
|
|
32
30
|
}
|
|
33
|
-
if ("
|
|
31
|
+
if (!("source" in sourceProps)) {
|
|
34
32
|
const sourceField = sourceProps.sourceField ?? "source";
|
|
35
33
|
const referencesField = sourceProps.referencesField ?? "references";
|
|
36
34
|
const referenceDiscriminationField = sourceProps.referenceDiscriminationField ?? "type";
|
|
37
35
|
return sourceProps.blocks.map((block) => {
|
|
38
36
|
if (!(sourceField in block)) {
|
|
39
|
-
throw new RichTextRendererError(
|
|
37
|
+
throw new RichTextRendererError(
|
|
38
|
+
`Found a block without a '${sourceField}' field. ` + (sourceProps.sourceField === void 0 ? `The 'sourceField' prop has not been supplied, and so '${sourceField}' was used as a default.` : `That is what the 'sourceField' prop has been set to, and so either this is a typo, or the data supplied is invalid.`)
|
|
39
|
+
);
|
|
40
40
|
}
|
|
41
41
|
const source = block[sourceField];
|
|
42
42
|
if (typeof source !== "string") {
|
|
43
43
|
throw new RichTextRendererError(`Found a block whose source is not a string.`);
|
|
44
44
|
}
|
|
45
45
|
if (sourceProps.referencesField !== void 0 && !(referencesField in block)) {
|
|
46
|
-
throw new RichTextRendererError(
|
|
46
|
+
throw new RichTextRendererError(
|
|
47
|
+
`The 'referencesField' prop is set to '${referencesField}' but a block without such field has been encountered. Unless this is just a typo, if you do not wish to use references, avoid supplying the 'referencesField' prop.`
|
|
48
|
+
);
|
|
47
49
|
}
|
|
48
50
|
const references = block[referencesField];
|
|
49
51
|
let normalizedReferences = void 0;
|
|
@@ -57,7 +59,9 @@ const RichTextRenderer = memo(function RichTextRenderer2({
|
|
|
57
59
|
throw new RichTextRendererError(`Found a reference without an id field.`);
|
|
58
60
|
}
|
|
59
61
|
if (!(referenceDiscriminationField in reference)) {
|
|
60
|
-
throw new RichTextRendererError(
|
|
62
|
+
throw new RichTextRendererError(
|
|
63
|
+
`Found a reference without a '${referenceDiscriminationField}' field. ` + (sourceProps.referenceDiscriminationField === void 0 ? `The 'referenceDiscriminationField' prop has not been supplied, and so '${referenceDiscriminationField}' was used as a default.` : `That is what the 'referenceDiscriminationField' prop has been set to, and so either this is a typo, or the data supplied is invalid.`)
|
|
64
|
+
);
|
|
61
65
|
}
|
|
62
66
|
normalizedReferences.set(reference.id, reference);
|
|
63
67
|
}
|
|
@@ -74,8 +78,9 @@ const RichTextRenderer = memo(function RichTextRenderer2({
|
|
|
74
78
|
}
|
|
75
79
|
throw new RichTextRendererError(`RichTextRenderer: invalid data supplied.`);
|
|
76
80
|
}, [deserialize, sourceProps]);
|
|
77
|
-
return /* @__PURE__ */ jsx(Fragment, {
|
|
78
|
-
|
|
81
|
+
return /* @__PURE__ */ jsx(Fragment, { children: normalizedSource.map((block, i) => /* @__PURE__ */ jsx(
|
|
82
|
+
RichTextRenderMetadataContext.Provider,
|
|
83
|
+
{
|
|
79
84
|
value: {
|
|
80
85
|
formatVersion: block.content.formatVersion,
|
|
81
86
|
referenceRenderers: block.referenceRenderers,
|
|
@@ -83,15 +88,20 @@ const RichTextRenderer = memo(function RichTextRenderer2({
|
|
|
83
88
|
referenceDiscriminationField: block.referenceDiscriminationField,
|
|
84
89
|
references: block.references
|
|
85
90
|
},
|
|
86
|
-
children: createElement(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
children: createElement(
|
|
92
|
+
renderBlock,
|
|
93
|
+
{
|
|
94
|
+
block
|
|
95
|
+
},
|
|
96
|
+
renderChildren(block.content.children, {
|
|
97
|
+
renderLeaf,
|
|
98
|
+
renderElement,
|
|
99
|
+
attributeNamePrefix
|
|
100
|
+
})
|
|
101
|
+
)
|
|
102
|
+
},
|
|
103
|
+
block.id ?? i
|
|
104
|
+
)) });
|
|
95
105
|
});
|
|
96
106
|
export {
|
|
97
107
|
RichTextRenderer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextRenderer.js","sources":["../../../../src/components/RichTextRenderer/RichTextRenderer.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode, useMemo } from 'react'\nimport { defaultDeserialize } from './defaultDeserialize'\nimport type { RenderElement } from './ElementRenderer'\nimport type { RenderLeaf } from './LeafRenderer'\nimport type { NormalizedRichTextBlock } from './NormalizedRichTextBlock'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport { renderChildren } from './renderChildren'\nimport type { RichTextBlock } from './RichTextBlock'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { RichTextRenderMetadataContext } from './RichTextRenderMetadataContext'\nimport type { RootEditorNode } from './RootEditorNode'\n\nexport interface RichTextRendererFieldProps {\n\tsource: string | null\n}\n\nexport interface RichTextRendererBlockProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\tblocks: RichTextBlock[]\n\treferenceRenderers?: Record<string, ReferenceRenderer<any, CustomElements, CustomLeaves>>\n\tsourceField?: string\n\treferencesField?: string\n\treferenceDiscriminationField?: string\n}\n\nexport type RichTextRendererProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> = {\n\tdeserialize?: (source: string) => RootEditorNode<CustomElements, CustomLeaves>\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n\trenderBlock?: ComponentType<{ block: unknown, children?: ReactNode }>\n} & (RichTextRendererFieldProps | RichTextRendererBlockProps<CustomElements, CustomLeaves>)\n\nexport const RichTextRenderer = memo(function RichTextRenderer<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({\n\tdeserialize = defaultDeserialize,\n\trenderElement,\n\trenderLeaf,\n\trenderBlock = ({ children }) => <>{children}</>,\n\tattributeNamePrefix,\n\t...sourceProps\n}: RichTextRendererProps<CustomElements, CustomLeaves>) {\n\tconst normalizedSource = useMemo<NormalizedRichTextBlock<CustomElements, CustomLeaves>[]>(() => {\n\t\tif ('source' in sourceProps && !('blocks' in sourceProps)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tcontent: sourceProps.source\n\t\t\t\t\t\t? deserialize(sourceProps.source)\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tformatVersion: 0,\n\t\t\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\t },\n\t\t\t\t\tid: undefined,\n\t\t\t\t\treferencesField: undefined,\n\t\t\t\t\treferenceDiscriminationField: undefined,\n\t\t\t\t\treferenceRenderers: {},\n\t\t\t\t\treferences: undefined,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t\tif ('
|
|
1
|
+
{"version":3,"file":"RichTextRenderer.js","sources":["../../../../src/components/RichTextRenderer/RichTextRenderer.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode, useMemo } from 'react'\nimport { defaultDeserialize } from './defaultDeserialize'\nimport type { RenderElement } from './ElementRenderer'\nimport type { RenderLeaf } from './LeafRenderer'\nimport type { NormalizedRichTextBlock } from './NormalizedRichTextBlock'\nimport type { ReferenceRenderer } from './ReferenceRenderer'\nimport { renderChildren } from './renderChildren'\nimport type { RichTextBlock } from './RichTextBlock'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\nimport type { RichTextReference } from './RichTextReference'\nimport { RichTextRendererError } from './RichTextRendererError'\nimport { RichTextRenderMetadataContext } from './RichTextRenderMetadataContext'\nimport type { RootEditorNode } from './RootEditorNode'\n\nexport interface RichTextRendererFieldProps {\n\tsource: string | null\n}\n\nexport interface RichTextRendererBlockProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\tblocks: RichTextBlock[]\n\treferenceRenderers?: Record<string, ReferenceRenderer<any, CustomElements, CustomLeaves>>\n\tsourceField?: string\n\treferencesField?: string\n\treferenceDiscriminationField?: string\n}\n\nexport type RichTextRendererProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> = {\n\tdeserialize?: (source: string) => RootEditorNode<CustomElements, CustomLeaves>\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n\trenderBlock?: ComponentType<{ block: unknown, children?: ReactNode }>\n} & (RichTextRendererFieldProps | RichTextRendererBlockProps<CustomElements, CustomLeaves>)\n\nexport const RichTextRenderer = memo(function RichTextRenderer<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>({\n\tdeserialize = defaultDeserialize,\n\trenderElement,\n\trenderLeaf,\n\trenderBlock = ({ children }) => <>{children}</>,\n\tattributeNamePrefix,\n\t...sourceProps\n}: RichTextRendererProps<CustomElements, CustomLeaves>) {\n\tconst normalizedSource = useMemo<NormalizedRichTextBlock<CustomElements, CustomLeaves>[]>(() => {\n\t\tif ('source' in sourceProps && !('blocks' in sourceProps)) {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tcontent: sourceProps.source\n\t\t\t\t\t\t? deserialize(sourceProps.source)\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tformatVersion: 0,\n\t\t\t\t\t\t\t\tchildren: [],\n\t\t\t\t\t\t },\n\t\t\t\t\tid: undefined,\n\t\t\t\t\treferencesField: undefined,\n\t\t\t\t\treferenceDiscriminationField: undefined,\n\t\t\t\t\treferenceRenderers: {},\n\t\t\t\t\treferences: undefined,\n\t\t\t\t},\n\t\t\t]\n\t\t}\n\t\tif (!('source' in sourceProps)) {\n\t\t\tconst sourceField = sourceProps.sourceField ?? 'source'\n\t\t\tconst referencesField = sourceProps.referencesField ?? 'references'\n\t\t\tconst referenceDiscriminationField = sourceProps.referenceDiscriminationField ?? 'type'\n\n\t\t\treturn sourceProps.blocks.map(block => {\n\t\t\t\tif (!(sourceField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`Found a block without a '${sourceField}' field. ` +\n\t\t\t\t\t\t\t(sourceProps.sourceField === undefined\n\t\t\t\t\t\t\t\t? `The 'sourceField' prop has not been supplied, and so '${sourceField}' was used as a default.`\n\t\t\t\t\t\t\t\t: `That is what the 'sourceField' prop has been set to, and so either this is a typo, ` +\n\t\t\t\t\t\t\t\t `or the data supplied is invalid.`),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst source = block[sourceField]\n\t\t\t\tif (typeof source !== 'string') {\n\t\t\t\t\tthrow new RichTextRendererError(`Found a block whose source is not a string.`)\n\t\t\t\t}\n\n\t\t\t\tif (sourceProps.referencesField !== undefined && !(referencesField in block)) {\n\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t`The 'referencesField' prop is set to '${referencesField}' but a block without such field ` +\n\t\t\t\t\t\t\t`has been encountered. Unless this is just a typo, ` +\n\t\t\t\t\t\t\t`if you do not wish to use references, avoid supplying the 'referencesField' prop.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst references = block[referencesField]\n\n\t\t\t\tlet normalizedReferences: Map<string, RichTextReference> | undefined = undefined\n\t\t\t\tif (references) {\n\t\t\t\t\tif (typeof Object(references)[Symbol.iterator] !== 'function') {\n\t\t\t\t\t\tthrow new RichTextRendererError(`The set of references must be an iterable!`)\n\t\t\t\t\t}\n\n\t\t\t\t\tnormalizedReferences = new Map()\n\t\t\t\t\tfor (const reference of references as Iterable<RichTextReference>) {\n\t\t\t\t\t\tif (!('id' in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(`Found a reference without an id field.`)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!(referenceDiscriminationField in reference)) {\n\t\t\t\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t\t\t\t`Found a reference without a '${referenceDiscriminationField}' field. ` +\n\t\t\t\t\t\t\t\t\t(sourceProps.referenceDiscriminationField === undefined\n\t\t\t\t\t\t\t\t\t\t? `The 'referenceDiscriminationField' prop has not been supplied, ` +\n\t\t\t\t\t\t\t\t\t\t `and so '${referenceDiscriminationField}' was used as a default.`\n\t\t\t\t\t\t\t\t\t\t: `That is what the 'referenceDiscriminationField' prop has been set to, ` +\n\t\t\t\t\t\t\t\t\t\t `and so either this is a typo, or the data supplied is invalid.`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnormalizedReferences.set(reference.id, reference)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tid: typeof block.id === 'string' ? block.id : undefined,\n\t\t\t\t\tcontent: deserialize(source),\n\t\t\t\t\treferenceDiscriminationField,\n\t\t\t\t\treferenceRenderers: sourceProps.referenceRenderers ?? {},\n\t\t\t\t\treferencesField,\n\t\t\t\t\treferences: normalizedReferences,\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t\tthrow new RichTextRendererError(`RichTextRenderer: invalid data supplied.`)\n\t}, [deserialize, sourceProps])\n\n\treturn (\n\t\t<>\n\t\t\t{normalizedSource.map((block, i) => (\n\t\t\t\t<RichTextRenderMetadataContext.Provider\n\t\t\t\t\tkey={block.id ?? i}\n\t\t\t\t\tvalue={{\n\t\t\t\t\t\tformatVersion: block.content.formatVersion,\n\t\t\t\t\t\treferenceRenderers: block.referenceRenderers,\n\t\t\t\t\t\treferencesField: block.referencesField,\n\t\t\t\t\t\treferenceDiscriminationField: block.referenceDiscriminationField,\n\t\t\t\t\t\treferences: block.references,\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{createElement(\n\t\t\t\t\t\trenderBlock, {\n\t\t\t\t\t\t\tblock,\n\t\t\t\t\t\t}, renderChildren(block.content.children, {\n\t\t\t\t\t\t\trenderLeaf,\n\t\t\t\t\t\t\trenderElement,\n\t\t\t\t\t\t\tattributeNamePrefix,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)}\n\t\t\t\t</RichTextRenderMetadataContext.Provider>\n\t\t\t))}\n\t\t</>\n\t)\n}) as <CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never>(\n\tprops: RichTextRendererProps<CustomElements, CustomLeaves>,\n) => ReactElement\n"],"names":["RichTextRenderer"],"mappings":";;;;;;AAyCa,MAAA,mBAAmB,KAAK,SAAS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,EAAE,QAAQ,YAAY;AACnB,oBAAA,IAAI,sBAAsB,wCAAwC;AAAA,YACzE;AACI,gBAAA,EAAE,gCAAgC,YAAY;AACjD,oBAAM,IAAI;AAAA,gBACT,gCAAgC,2CAC9B,YAAY,iCAAiC,SAC3C,0EACW,yDACX;AAAA,cAAA;AAAA,YAGN;AACqB,iCAAA,IAAI,UAAU,IAAI,SAAS;AAAA,UACjD;AAAA,QACD;AACO,eAAA;AAAA,UACN,IAAI,OAAO,MAAM,OAAO,WAAW,MAAM,KAAK;AAAA,UAC9C,SAAS,YAAY,MAAM;AAAA,UAC3B;AAAA,UACA,oBAAoB,YAAY,sBAAsB,CAAC;AAAA,UACvD;AAAA,UACA,YAAY;AAAA,QAAA;AAAA,MACb,CACA;AAAA,IACF;AACM,UAAA,IAAI,sBAAsB,0CAA0C;AAAA,EAAA,GACxE,CAAC,aAAa,WAAW,CAAC;AAE7B,SAEG,oBAAA,UAAA,EAAA,UAAA,iBAAiB,IAAI,CAAC,OAAO,MAC7B;AAAA,IAAC,8BAA8B;AAAA,IAA9B;AAAA,MAEA,OAAO;AAAA,QACN,eAAe,MAAM,QAAQ;AAAA,QAC7B,oBAAoB,MAAM;AAAA,QAC1B,iBAAiB,MAAM;AAAA,QACvB,8BAA8B,MAAM;AAAA,QACpC,YAAY,MAAM;AAAA,MACnB;AAAA,MAEC,UAAA;AAAA,QACA;AAAA,QAAa;AAAA,UACZ;AAAA,QACD;AAAA,QAAG,eAAe,MAAM,QAAQ,UAAU;AAAA,UACzC;AAAA,UACA;AAAA,UACA;AAAA,QAAA,CACA;AAAA,MACF;AAAA,IAAA;AAAA,IAjBK,MAAM,MAAM;AAAA,EAmBlB,CAAA,EACF,CAAA;AAEF,CAAC;"}
|
|
@@ -1,28 +1,19 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
1
2
|
import { ElementRenderer } from "./ElementRenderer.js";
|
|
2
3
|
import { LeafRenderer } from "./LeafRenderer.js";
|
|
3
|
-
import { jsx, Fragment } from "react/jsx-runtime";
|
|
4
4
|
const renderChildren = (children, options) => {
|
|
5
5
|
if (!Array.isArray(children)) {
|
|
6
6
|
children = [children];
|
|
7
7
|
}
|
|
8
|
-
return /* @__PURE__ */ jsx(Fragment, {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return /* @__PURE__ */ jsx(ElementRenderer, {
|
|
18
|
-
element: child,
|
|
19
|
-
options,
|
|
20
|
-
children: renderChildren(child.children, options)
|
|
21
|
-
}, i);
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
})
|
|
25
|
-
});
|
|
8
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children.map((child, i) => {
|
|
9
|
+
if ("text" in child) {
|
|
10
|
+
return /* @__PURE__ */ jsx(LeafRenderer, { leaf: child, renderLeaf: options.renderLeaf }, i);
|
|
11
|
+
}
|
|
12
|
+
if ("children" in child) {
|
|
13
|
+
return /* @__PURE__ */ jsx(ElementRenderer, { element: child, options, children: renderChildren(child.children, options) }, i);
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}) });
|
|
26
17
|
};
|
|
27
18
|
export {
|
|
28
19
|
renderChildren
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderChildren.js","sources":["../../../../src/components/RichTextRenderer/renderChildren.tsx"],"sourcesContent":["import type { ReactElement } from 'react'\nimport type { BuiltinElements } from './BuiltinElements'\nimport type { BuiltinLeaves } from './BuiltinLeaves'\nimport { ElementRenderer, RenderElement } from './ElementRenderer'\nimport { LeafRenderer, RenderLeaf } from './LeafRenderer'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\n\nexport interface RenderChildrenOptions<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n}\n\nexport const renderChildren = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>(\n\tchildren:\n\t\t| CustomElements\n\t\t| BuiltinElements<CustomElements, CustomLeaves>\n\t\t| CustomLeaves\n\t\t| BuiltinLeaves\n\t\t| Array<CustomElements | BuiltinElements<CustomElements, CustomLeaves> | CustomLeaves | BuiltinLeaves>,\n\toptions: RenderChildrenOptions<CustomElements, CustomLeaves>,\n): ReactElement => {\n\tif (!Array.isArray(children)) {\n\t\tchildren = [children]\n\t}\n\treturn (\n\t\t<>\n\t\t\t{children.map((child, i) => {\n\t\t\t\tif ('text' in child) {\n\t\t\t\t\treturn <LeafRenderer<CustomLeaves> key={i} leaf={child} renderLeaf={options.renderLeaf} />\n\t\t\t\t}\n\t\t\t\tif ('children' in child) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ElementRenderer<CustomElements, CustomLeaves> key={i} element={child} options={options}>\n\t\t\t\t\t\t\t{renderChildren<CustomElements, CustomLeaves>(child.children as typeof children, options)}\n\t\t\t\t\t\t</ElementRenderer>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn null // Throw?\n\t\t\t})}\n\t\t</>\n\t)\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"renderChildren.js","sources":["../../../../src/components/RichTextRenderer/renderChildren.tsx"],"sourcesContent":["import type { ReactElement } from 'react'\nimport type { BuiltinElements } from './BuiltinElements'\nimport type { BuiltinLeaves } from './BuiltinLeaves'\nimport { ElementRenderer, RenderElement } from './ElementRenderer'\nimport { LeafRenderer, RenderLeaf } from './LeafRenderer'\nimport type { RichTextElement } from './RichTextElement'\nimport type { RichTextLeaf } from './RichTextLeaf'\n\nexport interface RenderChildrenOptions<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n> {\n\trenderElement?: RenderElement<CustomElements, CustomLeaves>\n\trenderLeaf?: RenderLeaf<CustomLeaves>\n\tattributeNamePrefix?: string\n}\n\nexport const renderChildren = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = never,\n>(\n\tchildren:\n\t\t| CustomElements\n\t\t| BuiltinElements<CustomElements, CustomLeaves>\n\t\t| CustomLeaves\n\t\t| BuiltinLeaves\n\t\t| Array<CustomElements | BuiltinElements<CustomElements, CustomLeaves> | CustomLeaves | BuiltinLeaves>,\n\toptions: RenderChildrenOptions<CustomElements, CustomLeaves>,\n): ReactElement => {\n\tif (!Array.isArray(children)) {\n\t\tchildren = [children]\n\t}\n\treturn (\n\t\t<>\n\t\t\t{children.map((child, i) => {\n\t\t\t\tif ('text' in child) {\n\t\t\t\t\treturn <LeafRenderer<CustomLeaves> key={i} leaf={child} renderLeaf={options.renderLeaf} />\n\t\t\t\t}\n\t\t\t\tif ('children' in child) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ElementRenderer<CustomElements, CustomLeaves> key={i} element={child} options={options}>\n\t\t\t\t\t\t\t{renderChildren<CustomElements, CustomLeaves>(child.children as typeof children, options)}\n\t\t\t\t\t\t</ElementRenderer>\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn null // Throw?\n\t\t\t})}\n\t\t</>\n\t)\n}\n"],"names":[],"mappings":";;;AAiBa,MAAA,iBAAiB,CAI7B,UAMA,YACkB;AAClB,MAAI,CAAC,MAAM,QAAQ,QAAQ,GAAG;AAC7B,eAAW,CAAC,QAAQ;AAAA,EACrB;AACA,SAEG,oBAAA,UAAA,EAAA,UAAA,SAAS,IAAI,CAAC,OAAO,MAAM;AAC3B,QAAI,UAAU,OAAO;AACpB,iCAAQ,cAAmC,EAAA,MAAM,OAAO,YAAY,QAAQ,cAApC,CAAgD;AAAA,IACzF;AACA,QAAI,cAAc,OAAO;AAEvB,aAAA,oBAAC,iBAAsD,EAAA,SAAS,OAAO,SACrE,yBAA6C,MAAM,UAA6B,OAAO,EAAA,GADrC,CAEpD;AAAA,IAEF;AACO,WAAA;AAAA,EACP,CAAA,EACF,CAAA;AAEF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileUploadReducer.js","sources":["../../../src/upload/fileUploadReducer.ts"],"sourcesContent":["import { FileUploadError } from '@contember/client'\nimport { assertNever } from '../utils'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport { toFileId } from './toFileId'\n\nexport const initializeFileUploadState = <Result = unknown, Metadata = undefined>(): FileUploadMultiTemporalState<\n\tResult,\n\tMetadata\n> => ({\n\tlastUpdateTime: 0,\n\tfileIdByFile: new WeakMap<File, FileId>(),\n\tliveState: new Map(),\n\tpublicState: new Map(),\n\tisLiveStateDirty: false,\n})\n\nexport const fileUploadReducer = <Result = unknown, Metadata = undefined>(\n\tpreviousState: FileUploadMultiTemporalState<Result, Metadata>,\n\taction: FileUploadAction<Result, Metadata>,\n): FileUploadMultiTemporalState<Result, Metadata> => {\n\tconst publishNewState = (): FileUploadMultiTemporalState<Result, Metadata> => ({\n\t\tpublicState: previousState.liveState,\n\t\tfileIdByFile: previousState.fileIdByFile,\n\t\tlastUpdateTime: previousState.lastUpdateTime,\n\t\tisLiveStateDirty: false,\n\n\t\t// Immediately make the live state referentially unequal so that this doesn't have to happen during each action\n\t\t// several times between two publishes.\n\t\tliveState: new Map(previousState.liveState),\n\t})\n\tconst getNewDirtyState = (): FileUploadMultiTemporalState<Result, Metadata> => ({\n\t\tfileIdByFile: previousState.fileIdByFile,\n\t\tliveState: previousState.liveState,\n\t\tpublicState: previousState.publicState,\n\t\tisLiveStateDirty: true,\n\t\tlastUpdateTime: Date.now(),\n\t})\n\tswitch (action.type) {\n\t\tcase 'publishNewestState': {\n\t\t\treturn publishNewState()\n\t\t}\n\t\tcase 'initialize': {\n\t\t\tfor (const [fileId, metadata] of action.files) {\n\t\t\t\t// Deliberately allowing starting a new upload with the same id\n\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'initializing',\n\t\t\t\t\tabortController: metadata.abortController,\n\t\t\t\t\tpreviewUrl: metadata.previewUrl,\n\t\t\t\t\tfile: metadata.file,\n\t\t\t\t})\n\t\t\t\tpreviousState.fileIdByFile.set(metadata.file, fileId)\n\t\t\t}\n\t\t\treturn publishNewState() /* Making the feedback about new files immediate*/\n\t\t}\n\t\tcase 'startUploading': {\n\t\t\tfor (const [fileOrId, metadata] of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = previousState.liveState.get(fileId)\n\n\t\t\t\tif (fileState === undefined || fileState.readyState !== 'initializing') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tabortController: fileState.abortController,\n\t\t\t\t\tfile: fileState.file,\n\t\t\t\t\tmetadata: metadata.metadata!, // If the user didn't supply the metadata, then that's on them.\n\t\t\t\t\tpreviewUrl: fileState.previewUrl,\n\t\t\t\t\tprogress: undefined,\n\t\t\t\t\tuploader: metadata.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn publishNewState() /* Making the feedback about started upload immediate*/\n\t\t}\n\t\tcase 'finishSuccessfully': {\n\t\t\tfor (const [fileOrId, result] of action.result) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = previousState.liveState.get(fileId)\n\t\t\t\tif (previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'success',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tresult,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\t// return publishNewState() // Making the feedback about successful upload immediate.\n\t\t\treturn getNewDirtyState()\n\t\t}\n\t\tcase 'finishWithError': {\n\t\t\tfor (const errorSpec of action.error) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet rawError: unknown\n\n\t\t\t\tif (Array.isArray(errorSpec)) {\n\t\t\t\t\t[fileOrId, rawError] = errorSpec\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = errorSpec\n\t\t\t\t\trawError = undefined\n\t\t\t\t}\n\n\t\t\t\tconst errors: FileUploadError[] = []\n\n\t\t\t\tif (rawError instanceof FileUploadError) {\n\t\t\t\t\terrors.push(rawError)\n\t\t\t\t} else if (Array.isArray(rawError)) {\n\t\t\t\t\tfor (const error of rawError) {\n\t\t\t\t\t\tif (error instanceof FileUploadError) {\n\t\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = previousState.liveState.get(fileId)\n\t\t\t\tif (\n\t\t\t\t\tpreviousFileState === undefined ||\n\t\t\t\t\t(previousFileState.readyState !== 'initializing' && previousFileState.readyState !== 'uploading')\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst uploader = previousFileState.readyState === 'uploading' ? previousFileState.uploader : undefined\n\t\t\t\tconst metadata = previousFileState.readyState === 'uploading' ? previousFileState.metadata : undefined\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'error',\n\t\t\t\t\terrors: errors.length ? errors : undefined,\n\t\t\t\t\trawError,\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tuploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn getNewDirtyState() // Bad news can wait.\n\t\t}\n\t\tcase 'purge': {\n\t\t\tlet atLeastOnePurged = false\n\t\t\tfor (const fileOrId of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = previousState.liveState.get(fileId)\n\n\t\t\t\tif (fileState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tatLeastOnePurged = true\n\t\t\t\tif (fileState.readyState === 'initializing' || fileState.readyState === 'uploading') {\n\t\t\t\t\tfileState.abortController.abort() // This is a bit naughty… We shouldn't do this from here.\n\t\t\t\t}\n\t\t\t\tpreviousState.liveState.delete(fileId)\n\t\t\t}\n\t\t\tif (atLeastOnePurged) {\n\t\t\t\treturn getNewDirtyState()\n\t\t\t}\n\t\t\treturn previousState\n\t\t}\n\t\tcase 'updateUploadProgress': {\n\t\t\tfor (const [fileOrId, { progress }] of action.progress) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = previousState.liveState.get(fileId)\n\t\t\t\tif (progress === undefined || previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t\tabortController: previousFileState.abortController,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tprogress,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn getNewDirtyState()\n\t\t}\n\t}\n\tassertNever(action)\n}\n"],"names":[],"mappings":";;;AAOO,MAAM,4BAA4B,OAGnC;AAAA,EACL,gBAAgB;AAAA,EAChB,kCAAkB,QAAsB;AAAA,EACxC,+BAAe,IAAI;AAAA,EACnB,iCAAiB,IAAI;AAAA,EACrB,kBAAkB;AACnB;AAEa,MAAA,oBAAoB,CAChC,eACA,WACoD;AACpD,QAAM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B;AAAA,UACxB;AAAA,UACA,YAAY,kBAAkB;AAAA,UAC9B;AAAA,QAAA,CACA;AAAA,MACF;AACA,aAAO,iBAAiB;AAAA,IACzB;AAAA,SACK,SAAS;AACb,UAAI,mBAAmB;AACZ,iBAAA,YAAY,OAAO,OAAO;AAC9B,cAAA,SAAS,SAAS,eAAe,QAAQ;AAC/C,cAAM,YAAY,cAAc,UAAU,IAAI,MAAM;AAEpD,YAAI,cAAc,QAAW;AAC5B;AAAA,QACD;AACmB,2BAAA;AACnB,YAAI,UAAU,eAAe,kBAAkB,UAAU,eAAe,aAAa;AACpF,oBAAU,gBAAgB;QAC3B;AACc,sBAAA,UAAU,OAAO,MAAM;AAAA,MACtC;AACA,UAAI,kBAAkB;AACrB,eAAO,iBAAiB;AAAA,MACzB;AACO,aAAA;AAAA,IACR;AAAA,SACK,wBAAwB;AAC5B,iBAAW,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,UAAU;AACjD,cAAA,SAAS,SAAS,eAAe,QAAQ;AAC/C,cAAM,oBAAoB,cAAc,UAAU,IAAI,MAAM;AAC5D,YAAI,aAAa,UAAa,sBAAsB,UAAa,kBAAkB,eAAe,aAAa;AAC9G;AAAA,QACD;AACc,sBAAA,UAAU,IAAI,QAAQ;AAAA,UACnC,YAAY;AAAA,UACZ,MAAM,kBAAkB;AAAA,UACxB,UAAU,kBAAkB;AAAA,UAC5B,iBAAiB,kBAAkB;AAAA,UACnC,YAAY,kBAAkB;AAAA,UAC9B,UAAU,kBAAkB;AAAA,UAC5B;AAAA,QAAA,CACA;AAAA,MACF;AACA,aAAO,iBAAiB;AAAA,IACzB;AAAA;AAED,cAAkB;AACnB;"}
|
|
1
|
+
{"version":3,"file":"fileUploadReducer.js","sources":["../../../src/upload/fileUploadReducer.ts"],"sourcesContent":["import { FileUploadError } from '@contember/client'\nimport { assertNever } from '../utils'\nimport type { FileId } from './FileId'\nimport type { FileUploadAction } from './FileUploadAction'\nimport type { FileUploadMultiTemporalState } from './FileUploadMultiTemporalState'\nimport { toFileId } from './toFileId'\n\nexport const initializeFileUploadState = <Result = unknown, Metadata = undefined>(): FileUploadMultiTemporalState<\n\tResult,\n\tMetadata\n> => ({\n\tlastUpdateTime: 0,\n\tfileIdByFile: new WeakMap<File, FileId>(),\n\tliveState: new Map(),\n\tpublicState: new Map(),\n\tisLiveStateDirty: false,\n})\n\nexport const fileUploadReducer = <Result = unknown, Metadata = undefined>(\n\tpreviousState: FileUploadMultiTemporalState<Result, Metadata>,\n\taction: FileUploadAction<Result, Metadata>,\n): FileUploadMultiTemporalState<Result, Metadata> => {\n\tconst publishNewState = (): FileUploadMultiTemporalState<Result, Metadata> => ({\n\t\tpublicState: previousState.liveState,\n\t\tfileIdByFile: previousState.fileIdByFile,\n\t\tlastUpdateTime: previousState.lastUpdateTime,\n\t\tisLiveStateDirty: false,\n\n\t\t// Immediately make the live state referentially unequal so that this doesn't have to happen during each action\n\t\t// several times between two publishes.\n\t\tliveState: new Map(previousState.liveState),\n\t})\n\tconst getNewDirtyState = (): FileUploadMultiTemporalState<Result, Metadata> => ({\n\t\tfileIdByFile: previousState.fileIdByFile,\n\t\tliveState: previousState.liveState,\n\t\tpublicState: previousState.publicState,\n\t\tisLiveStateDirty: true,\n\t\tlastUpdateTime: Date.now(),\n\t})\n\tswitch (action.type) {\n\t\tcase 'publishNewestState': {\n\t\t\treturn publishNewState()\n\t\t}\n\t\tcase 'initialize': {\n\t\t\tfor (const [fileId, metadata] of action.files) {\n\t\t\t\t// Deliberately allowing starting a new upload with the same id\n\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'initializing',\n\t\t\t\t\tabortController: metadata.abortController,\n\t\t\t\t\tpreviewUrl: metadata.previewUrl,\n\t\t\t\t\tfile: metadata.file,\n\t\t\t\t})\n\t\t\t\tpreviousState.fileIdByFile.set(metadata.file, fileId)\n\t\t\t}\n\t\t\treturn publishNewState() /* Making the feedback about new files immediate*/\n\t\t}\n\t\tcase 'startUploading': {\n\t\t\tfor (const [fileOrId, metadata] of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = previousState.liveState.get(fileId)\n\n\t\t\t\tif (fileState === undefined || fileState.readyState !== 'initializing') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tabortController: fileState.abortController,\n\t\t\t\t\tfile: fileState.file,\n\t\t\t\t\tmetadata: metadata.metadata!, // If the user didn't supply the metadata, then that's on them.\n\t\t\t\t\tpreviewUrl: fileState.previewUrl,\n\t\t\t\t\tprogress: undefined,\n\t\t\t\t\tuploader: metadata.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn publishNewState() /* Making the feedback about started upload immediate*/\n\t\t}\n\t\tcase 'finishSuccessfully': {\n\t\t\tfor (const [fileOrId, result] of action.result) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = previousState.liveState.get(fileId)\n\t\t\t\tif (previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'success',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tresult,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\t// return publishNewState() // Making the feedback about successful upload immediate.\n\t\t\treturn getNewDirtyState()\n\t\t}\n\t\tcase 'finishWithError': {\n\t\t\tfor (const errorSpec of action.error) {\n\t\t\t\tlet fileOrId: File | FileId\n\t\t\t\tlet rawError: unknown\n\n\t\t\t\tif (Array.isArray(errorSpec)) {\n\t\t\t\t\t[fileOrId, rawError] = errorSpec\n\t\t\t\t} else {\n\t\t\t\t\tfileOrId = errorSpec\n\t\t\t\t\trawError = undefined\n\t\t\t\t}\n\n\t\t\t\tconst errors: FileUploadError[] = []\n\n\t\t\t\tif (rawError instanceof FileUploadError) {\n\t\t\t\t\terrors.push(rawError)\n\t\t\t\t} else if (Array.isArray(rawError)) {\n\t\t\t\t\tfor (const error of rawError) {\n\t\t\t\t\t\tif (error instanceof FileUploadError) {\n\t\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = previousState.liveState.get(fileId)\n\t\t\t\tif (\n\t\t\t\t\tpreviousFileState === undefined ||\n\t\t\t\t\t(previousFileState.readyState !== 'initializing' && previousFileState.readyState !== 'uploading')\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst uploader = previousFileState.readyState === 'uploading' ? previousFileState.uploader : undefined\n\t\t\t\tconst metadata = previousFileState.readyState === 'uploading' ? previousFileState.metadata : undefined\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'error',\n\t\t\t\t\terrors: errors.length ? errors : undefined,\n\t\t\t\t\trawError,\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tmetadata,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tuploader,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn getNewDirtyState() // Bad news can wait.\n\t\t}\n\t\tcase 'purge': {\n\t\t\tlet atLeastOnePurged = false\n\t\t\tfor (const fileOrId of action.files) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst fileState = previousState.liveState.get(fileId)\n\n\t\t\t\tif (fileState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tatLeastOnePurged = true\n\t\t\t\tif (fileState.readyState === 'initializing' || fileState.readyState === 'uploading') {\n\t\t\t\t\tfileState.abortController.abort() // This is a bit naughty… We shouldn't do this from here.\n\t\t\t\t}\n\t\t\t\tpreviousState.liveState.delete(fileId)\n\t\t\t}\n\t\t\tif (atLeastOnePurged) {\n\t\t\t\treturn getNewDirtyState()\n\t\t\t}\n\t\t\treturn previousState\n\t\t}\n\t\tcase 'updateUploadProgress': {\n\t\t\tfor (const [fileOrId, { progress }] of action.progress) {\n\t\t\t\tconst fileId = toFileId(previousState, fileOrId)\n\t\t\t\tconst previousFileState = previousState.liveState.get(fileId)\n\t\t\t\tif (progress === undefined || previousFileState === undefined || previousFileState.readyState !== 'uploading') {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tpreviousState.liveState.set(fileId, {\n\t\t\t\t\treadyState: 'uploading',\n\t\t\t\t\tfile: previousFileState.file,\n\t\t\t\t\tuploader: previousFileState.uploader,\n\t\t\t\t\tabortController: previousFileState.abortController,\n\t\t\t\t\tpreviewUrl: previousFileState.previewUrl,\n\t\t\t\t\tmetadata: previousFileState.metadata,\n\t\t\t\t\tprogress,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn getNewDirtyState()\n\t\t}\n\t}\n\tassertNever(action)\n}\n"],"names":[],"mappings":";;;AAOO,MAAM,4BAA4B,OAGnC;AAAA,EACL,gBAAgB;AAAA,EAChB,kCAAkB,QAAsB;AAAA,EACxC,+BAAe,IAAI;AAAA,EACnB,iCAAiB,IAAI;AAAA,EACrB,kBAAkB;AACnB;AAEa,MAAA,oBAAoB,CAChC,eACA,WACoD;AACpD,QAAM,kBAAkB,OAAuD;AAAA,IAC9E,aAAa,cAAc;AAAA,IAC3B,cAAc,cAAc;AAAA,IAC5B,gBAAgB,cAAc;AAAA,IAC9B,kBAAkB;AAAA,IAIlB,WAAW,IAAI,IAAI,cAAc,SAAS;AAAA,EAAA;AAE3C,QAAM,mBAAmB,OAAuD;AAAA,IAC/E,cAAc,cAAc;AAAA,IAC5B,WAAW,cAAc;AAAA,IACzB,aAAa,cAAc;AAAA,IAC3B,kBAAkB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