@contember/react-richtext-renderer 1.3.0-alpha.9
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/RichTextRendererError.cjs +6 -0
- package/dist/development/RichTextRendererError.cjs.map +1 -0
- package/dist/development/RichTextRendererError.js +6 -0
- package/dist/development/RichTextRendererError.js.map +1 -0
- package/dist/development/components/RichText.cjs +32 -0
- package/dist/development/components/RichText.cjs.map +1 -0
- package/dist/development/components/RichText.js +32 -0
- package/dist/development/components/RichText.js.map +1 -0
- package/dist/development/components/RichTextBlocksRenderer.cjs +30 -0
- package/dist/development/components/RichTextBlocksRenderer.cjs.map +1 -0
- package/dist/development/components/RichTextBlocksRenderer.js +30 -0
- package/dist/development/components/RichTextBlocksRenderer.js.map +1 -0
- package/dist/development/components/RichTextFieldRenderer.cjs +28 -0
- package/dist/development/components/RichTextFieldRenderer.cjs.map +1 -0
- package/dist/development/components/RichTextFieldRenderer.js +28 -0
- package/dist/development/components/RichTextFieldRenderer.js.map +1 -0
- package/dist/development/components/RichTextRenderer.cjs +14 -0
- package/dist/development/components/RichTextRenderer.cjs.map +1 -0
- package/dist/development/components/RichTextRenderer.js +14 -0
- package/dist/development/components/RichTextRenderer.js.map +1 -0
- package/dist/development/hooks/useRichTextBlocksSource.cjs +62 -0
- package/dist/development/hooks/useRichTextBlocksSource.cjs.map +1 -0
- package/dist/development/hooks/useRichTextBlocksSource.js +62 -0
- package/dist/development/hooks/useRichTextBlocksSource.js.map +1 -0
- package/dist/development/hooks/useRichTextFieldSource.cjs +26 -0
- package/dist/development/hooks/useRichTextFieldSource.cjs.map +1 -0
- package/dist/development/hooks/useRichTextFieldSource.js +26 -0
- package/dist/development/hooks/useRichTextFieldSource.js.map +1 -0
- package/dist/development/index.cjs +17 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +17 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/internal/components/ElementRenderer.cjs +24 -0
- package/dist/development/internal/components/ElementRenderer.cjs.map +1 -0
- package/dist/development/internal/components/ElementRenderer.js +24 -0
- package/dist/development/internal/components/ElementRenderer.js.map +1 -0
- package/dist/development/internal/components/LeafRenderer.cjs +23 -0
- package/dist/development/internal/components/LeafRenderer.cjs.map +1 -0
- package/dist/development/internal/components/LeafRenderer.js +23 -0
- package/dist/development/internal/components/LeafRenderer.js.map +1 -0
- package/dist/development/internal/components/RenderElementFallback.cjs +84 -0
- package/dist/development/internal/components/RenderElementFallback.cjs.map +1 -0
- package/dist/development/internal/components/RenderElementFallback.js +84 -0
- package/dist/development/internal/components/RenderElementFallback.js.map +1 -0
- package/dist/development/internal/components/RenderLeafFallback.cjs +38 -0
- package/dist/development/internal/components/RenderLeafFallback.cjs.map +1 -0
- package/dist/development/internal/components/RenderLeafFallback.js +38 -0
- package/dist/development/internal/components/RenderLeafFallback.js.map +1 -0
- package/dist/development/internal/defaultDeserialize.cjs +14 -0
- package/dist/development/internal/defaultDeserialize.cjs.map +1 -0
- package/dist/development/internal/defaultDeserialize.js +14 -0
- package/dist/development/internal/defaultDeserialize.js.map +1 -0
- package/dist/development/internal/renderChildren.cjs +18 -0
- package/dist/development/internal/renderChildren.cjs.map +1 -0
- package/dist/development/internal/renderChildren.js +18 -0
- package/dist/development/internal/renderChildren.js.map +1 -0
- package/dist/development/internal/useReferenceMetadata.cjs +37 -0
- package/dist/development/internal/useReferenceMetadata.cjs.map +1 -0
- package/dist/development/internal/useReferenceMetadata.js +37 -0
- package/dist/development/internal/useReferenceMetadata.js.map +1 -0
- package/dist/production/RichTextRendererError.cjs +6 -0
- package/dist/production/RichTextRendererError.cjs.map +1 -0
- package/dist/production/RichTextRendererError.js +6 -0
- package/dist/production/RichTextRendererError.js.map +1 -0
- package/dist/production/components/RichText.cjs +32 -0
- package/dist/production/components/RichText.cjs.map +1 -0
- package/dist/production/components/RichText.js +32 -0
- package/dist/production/components/RichText.js.map +1 -0
- package/dist/production/components/RichTextBlocksRenderer.cjs +30 -0
- package/dist/production/components/RichTextBlocksRenderer.cjs.map +1 -0
- package/dist/production/components/RichTextBlocksRenderer.js +30 -0
- package/dist/production/components/RichTextBlocksRenderer.js.map +1 -0
- package/dist/production/components/RichTextFieldRenderer.cjs +28 -0
- package/dist/production/components/RichTextFieldRenderer.cjs.map +1 -0
- package/dist/production/components/RichTextFieldRenderer.js +28 -0
- package/dist/production/components/RichTextFieldRenderer.js.map +1 -0
- package/dist/production/components/RichTextRenderer.cjs +14 -0
- package/dist/production/components/RichTextRenderer.cjs.map +1 -0
- package/dist/production/components/RichTextRenderer.js +14 -0
- package/dist/production/components/RichTextRenderer.js.map +1 -0
- package/dist/production/hooks/useRichTextBlocksSource.cjs +62 -0
- package/dist/production/hooks/useRichTextBlocksSource.cjs.map +1 -0
- package/dist/production/hooks/useRichTextBlocksSource.js +62 -0
- package/dist/production/hooks/useRichTextBlocksSource.js.map +1 -0
- package/dist/production/hooks/useRichTextFieldSource.cjs +26 -0
- package/dist/production/hooks/useRichTextFieldSource.cjs.map +1 -0
- package/dist/production/hooks/useRichTextFieldSource.js +26 -0
- package/dist/production/hooks/useRichTextFieldSource.js.map +1 -0
- package/dist/production/index.cjs +17 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +17 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/internal/components/ElementRenderer.cjs +24 -0
- package/dist/production/internal/components/ElementRenderer.cjs.map +1 -0
- package/dist/production/internal/components/ElementRenderer.js +24 -0
- package/dist/production/internal/components/ElementRenderer.js.map +1 -0
- package/dist/production/internal/components/LeafRenderer.cjs +23 -0
- package/dist/production/internal/components/LeafRenderer.cjs.map +1 -0
- package/dist/production/internal/components/LeafRenderer.js +23 -0
- package/dist/production/internal/components/LeafRenderer.js.map +1 -0
- package/dist/production/internal/components/RenderElementFallback.cjs +84 -0
- package/dist/production/internal/components/RenderElementFallback.cjs.map +1 -0
- package/dist/production/internal/components/RenderElementFallback.js +84 -0
- package/dist/production/internal/components/RenderElementFallback.js.map +1 -0
- package/dist/production/internal/components/RenderLeafFallback.cjs +38 -0
- package/dist/production/internal/components/RenderLeafFallback.cjs.map +1 -0
- package/dist/production/internal/components/RenderLeafFallback.js +38 -0
- package/dist/production/internal/components/RenderLeafFallback.js.map +1 -0
- package/dist/production/internal/defaultDeserialize.cjs +14 -0
- package/dist/production/internal/defaultDeserialize.cjs.map +1 -0
- package/dist/production/internal/defaultDeserialize.js +14 -0
- package/dist/production/internal/defaultDeserialize.js.map +1 -0
- package/dist/production/internal/renderChildren.cjs +18 -0
- package/dist/production/internal/renderChildren.cjs.map +1 -0
- package/dist/production/internal/renderChildren.js +18 -0
- package/dist/production/internal/renderChildren.js.map +1 -0
- package/dist/production/internal/useReferenceMetadata.cjs +37 -0
- package/dist/production/internal/useReferenceMetadata.cjs.map +1 -0
- package/dist/production/internal/useReferenceMetadata.js +37 -0
- package/dist/production/internal/useReferenceMetadata.js.map +1 -0
- package/dist/types/RichTextRendererError.d.ts +3 -0
- package/dist/types/RichTextRendererError.d.ts.map +1 -0
- package/dist/types/components/RichText.d.ts +13 -0
- package/dist/types/components/RichText.d.ts.map +1 -0
- package/dist/types/components/RichTextBlocksRenderer.d.ts +10 -0
- package/dist/types/components/RichTextBlocksRenderer.d.ts.map +1 -0
- package/dist/types/components/RichTextFieldRenderer.d.ts +10 -0
- package/dist/types/components/RichTextFieldRenderer.d.ts.map +1 -0
- package/dist/types/components/RichTextRenderer.d.ts +12 -0
- package/dist/types/components/RichTextRenderer.d.ts.map +1 -0
- package/dist/types/components/index.d.ts +5 -0
- package/dist/types/components/index.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +3 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/useRichTextBlocksSource.d.ts +3 -0
- package/dist/types/hooks/useRichTextBlocksSource.d.ts.map +1 -0
- package/dist/types/hooks/useRichTextFieldSource.d.ts +3 -0
- package/dist/types/hooks/useRichTextFieldSource.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/internal/components/ElementRenderer.d.ts +14 -0
- package/dist/types/internal/components/ElementRenderer.d.ts.map +1 -0
- package/dist/types/internal/components/LeafRenderer.d.ts +12 -0
- package/dist/types/internal/components/LeafRenderer.d.ts.map +1 -0
- package/dist/types/internal/components/RenderElementFallback.d.ts +14 -0
- package/dist/types/internal/components/RenderElementFallback.d.ts.map +1 -0
- package/dist/types/internal/components/RenderLeafFallback.d.ts +6 -0
- package/dist/types/internal/components/RenderLeafFallback.d.ts.map +1 -0
- package/dist/types/internal/defaultDeserialize.d.ts +5 -0
- package/dist/types/internal/defaultDeserialize.d.ts.map +1 -0
- package/dist/types/internal/renderChildren.d.ts +8 -0
- package/dist/types/internal/renderChildren.d.ts.map +1 -0
- package/dist/types/internal/useReferenceMetadata.d.ts +9 -0
- package/dist/types/internal/useReferenceMetadata.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types/RenderChildren.d.ts +9 -0
- package/dist/types/types/RenderChildren.d.ts.map +1 -0
- package/dist/types/types/RichTextBlock.d.ts +8 -0
- package/dist/types/types/RichTextBlock.d.ts.map +1 -0
- package/dist/types/types/RichTextBlockSource.d.ts +9 -0
- package/dist/types/types/RichTextBlockSource.d.ts.map +1 -0
- package/dist/types/types/RichTextFieldSource.d.ts +6 -0
- package/dist/types/types/RichTextFieldSource.d.ts.map +1 -0
- package/dist/types/types/RichTextReference.d.ts +5 -0
- package/dist/types/types/RichTextReference.d.ts.map +1 -0
- package/dist/types/types/RichTextReferenceMetadata.d.ts +15 -0
- package/dist/types/types/RichTextReferenceMetadata.d.ts.map +1 -0
- package/dist/types/types/RichTextRenderingOptions.d.ts +14 -0
- package/dist/types/types/RichTextRenderingOptions.d.ts.map +1 -0
- package/dist/types/types/builtin/BuiltinElements.d.ts +48 -0
- package/dist/types/types/builtin/BuiltinElements.d.ts.map +1 -0
- package/dist/types/types/builtin/BuiltinLeaves.d.ts +21 -0
- package/dist/types/types/builtin/BuiltinLeaves.d.ts.map +1 -0
- package/dist/types/types/builtin/index.d.ts +3 -0
- package/dist/types/types/builtin/index.d.ts.map +1 -0
- package/dist/types/types/custom/ReferenceRenderer.d.ts +17 -0
- package/dist/types/types/custom/ReferenceRenderer.d.ts.map +1 -0
- package/dist/types/types/custom/RenderBlock.d.ts +7 -0
- package/dist/types/types/custom/RenderBlock.d.ts.map +1 -0
- package/dist/types/types/custom/RenderElement.d.ts +24 -0
- package/dist/types/types/custom/RenderElement.d.ts.map +1 -0
- package/dist/types/types/custom/RenderLeaf.d.ts +11 -0
- package/dist/types/types/custom/RenderLeaf.d.ts.map +1 -0
- package/dist/types/types/custom/index.d.ts +5 -0
- package/dist/types/types/custom/index.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +11 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/structure/RichTextChild.d.ts +5 -0
- package/dist/types/types/structure/RichTextChild.d.ts.map +1 -0
- package/dist/types/types/structure/RichTextElement.d.ts +8 -0
- package/dist/types/types/structure/RichTextElement.d.ts.map +1 -0
- package/dist/types/types/structure/RichTextLeaf.d.ts +4 -0
- package/dist/types/types/structure/RichTextLeaf.d.ts.map +1 -0
- package/dist/types/types/structure/RootEditorNode.d.ts +8 -0
- package/dist/types/types/structure/RootEditorNode.d.ts.map +1 -0
- package/dist/types/types/structure/index.d.ts +5 -0
- package/dist/types/types/structure/index.d.ts.map +1 -0
- package/package.json +50 -0
- package/readme.md +106 -0
- package/src/RichTextRendererError.ts +1 -0
- package/src/components/RichText.tsx +52 -0
- package/src/components/RichTextBlocksRenderer.tsx +40 -0
- package/src/components/RichTextFieldRenderer.tsx +42 -0
- package/src/components/RichTextRenderer.tsx +31 -0
- package/src/components/index.ts +4 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useRichTextBlocksSource.ts +75 -0
- package/src/hooks/useRichTextFieldSource.ts +26 -0
- package/src/index.ts +6 -0
- package/src/internal/components/ElementRenderer.tsx +48 -0
- package/src/internal/components/LeafRenderer.tsx +36 -0
- package/src/internal/components/RenderElementFallback.tsx +153 -0
- package/src/internal/components/RenderLeafFallback.tsx +43 -0
- package/src/internal/defaultDeserialize.ts +19 -0
- package/src/internal/renderChildren.tsx +37 -0
- package/src/internal/useReferenceMetadata.ts +62 -0
- package/src/tsconfig.json +6 -0
- package/src/types/RenderChildren.ts +16 -0
- package/src/types/RichTextBlock.ts +11 -0
- package/src/types/RichTextBlockSource.ts +10 -0
- package/src/types/RichTextFieldSource.ts +6 -0
- package/src/types/RichTextReference.ts +6 -0
- package/src/types/RichTextReferenceMetadata.ts +27 -0
- package/src/types/RichTextRenderingOptions.ts +23 -0
- package/src/types/builtin/BuiltinElements.ts +111 -0
- package/src/types/builtin/BuiltinLeaves.ts +33 -0
- package/src/types/builtin/index.ts +2 -0
- package/src/types/custom/ReferenceRenderer.ts +33 -0
- package/src/types/custom/RenderBlock.ts +8 -0
- package/src/types/custom/RenderElement.ts +37 -0
- package/src/types/custom/RenderLeaf.ts +14 -0
- package/src/types/custom/index.ts +4 -0
- package/src/types/index.ts +11 -0
- package/src/types/structure/RichTextChild.ts +11 -0
- package/src/types/structure/RichTextElement.ts +11 -0
- package/src/types/structure/RichTextLeaf.ts +3 -0
- package/src/types/structure/RootEditorNode.ts +11 -0
- package/src/types/structure/index.ts +4 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElementRenderer.js","sources":["../../../../src/internal/components/ElementRenderer.tsx"],"sourcesContent":["import type { ReactElement } from 'react'\nimport { createElement } from 'react'\nimport type { BuiltinElements } from '../../types/builtin/BuiltinElements'\nimport { renderChildren } from '../renderChildren'\nimport { RenderElementFallback } from './RenderElementFallback'\nimport { useReferenceMetadata } from '../useReferenceMetadata'\nimport type { RichTextElement } from '../../types/structure/RichTextElement'\nimport type { RichTextLeaf } from '../../types/structure/RichTextLeaf'\nimport { RichTextBlock } from '../../types/RichTextBlock'\nimport { RichTextRenderingOptions } from '../../types/RichTextRenderingOptions'\n\n\nexport interface ElementRendererProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n> {\n\telement: CustomElements | BuiltinElements<CustomElements, CustomLeaves>\n\tchildren: ReactElement\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves>\n\tblock: RichTextBlock<CustomElements, CustomLeaves>\n}\n\nexport function ElementRenderer<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n>({ element, children, options, block }: ElementRendererProps<CustomElements, CustomLeaves>) {\n\tconst referenceMetadata = useReferenceMetadata<CustomElements, CustomLeaves>(element, options, block)\n\n\tconst fallback = (\n\t\t<RenderElementFallback<CustomElements, CustomLeaves> element={element as BuiltinElements<CustomElements, CustomLeaves>} options={options} block={block}>\n\t\t\t{children}\n\t\t</RenderElementFallback>\n\t)\n\n\treturn options.renderElement\n\t\t? createElement(options.renderElement, {\n\t\t\t...referenceMetadata,\n\t\t\tformatVersion: block.content.formatVersion,\n\t\t\tblock,\n\t\t\toptions,\n\t\t\telement,\n\t\t\tfallback,\n\t\t\tchildren,\n\t\t\trenderChildren: (children, opts = options) => renderChildren(children, opts, block),\n\t\t\trenderChildrenOptions: options,\n\t\t})\n\t\t: fallback\n}\n"],"names":["children"],"mappings":";;;;;AAsBO,SAAS,gBAGd,EAAE,SAAS,UAAU,SAAS,SAA6D;AAC5F,QAAM,oBAAoB,qBAAmD,SAAS,SAAS,KAAK;AAEpG,QAAM,WACJ,oBAAA,uBAAA,EAAoD,SAAmE,SAAkB,OACxI,SACF,CAAA;AAGD,SAAO,QAAQ,gBACZ,cAAc,QAAQ,eAAe;AAAA,IACtC,GAAG;AAAA,IACH,eAAe,MAAM,QAAQ;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,CAACA,WAAU,OAAO,YAAY,eAAeA,WAAU,MAAM,KAAK;AAAA,IAClF,uBAAuB;AAAA,EACvB,CAAA,IACC;AACJ;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const RenderLeafFallback = require("./RenderLeafFallback.cjs");
|
|
6
|
+
function LeafRenderer({
|
|
7
|
+
leaf,
|
|
8
|
+
options: { renderLeaf },
|
|
9
|
+
block: { content: { formatVersion } }
|
|
10
|
+
}) {
|
|
11
|
+
const fallback = /* @__PURE__ */ jsxRuntime.jsx(RenderLeafFallback.RenderLeafFallback, { leaf });
|
|
12
|
+
return renderLeaf ? react.createElement(
|
|
13
|
+
renderLeaf,
|
|
14
|
+
{
|
|
15
|
+
formatVersion,
|
|
16
|
+
leaf,
|
|
17
|
+
fallback,
|
|
18
|
+
children: leaf.text
|
|
19
|
+
}
|
|
20
|
+
) : fallback;
|
|
21
|
+
}
|
|
22
|
+
exports.LeafRenderer = LeafRenderer;
|
|
23
|
+
//# sourceMappingURL=LeafRenderer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LeafRenderer.cjs","sources":["../../../../src/internal/components/LeafRenderer.tsx"],"sourcesContent":["import { createElement } from 'react'\nimport type { BuiltinLeaves } from '../../types/builtin/BuiltinLeaves'\nimport { RenderLeafFallback } from './RenderLeafFallback'\nimport type { RichTextLeaf } from '../../types/structure/RichTextLeaf'\nimport { RichTextElement } from '../../types/structure/RichTextElement'\nimport { RichTextRenderingOptions } from '../../types/RichTextRenderingOptions'\nimport { RichTextBlock } from '../../types/RichTextBlock'\n\nexport interface LeafRendererProps<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = RichTextLeaf> {\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves>\n\tblock: RichTextBlock<CustomElements, CustomLeaves>\n\tleaf: CustomLeaves & BuiltinLeaves\n}\n\nexport function LeafRenderer<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n>({\n\tleaf,\n\toptions: { renderLeaf },\n\tblock: { content: { formatVersion } },\n}: LeafRendererProps<CustomElements, CustomLeaves>) {\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\tchildren: leaf.text,\n\t\t\t\t},\n\t\t )\n\t\t: fallback\n}\n"],"names":["jsx","RenderLeafFallback","createElement"],"mappings":";;;;;AAcO,SAAS,aAGd;AAAA,EACD;AAAA,EACA,SAAS,EAAE,WAAW;AAAA,EACtB,OAAO,EAAE,SAAS,EAAE,gBAAgB;AACrC,GAAoD;AAC7C,QAAA,WAAYA,2BAAA,IAAAC,mBAAA,oBAAA,EAAmB,KAAY,CAAA;AAEjD,SAAO,aACJC,MAAA;AAAA,IACA;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU,KAAK;AAAA,IAChB;AAAA,EAEA,IAAA;AACJ;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { RenderLeafFallback } from "./RenderLeafFallback.js";
|
|
4
|
+
function LeafRenderer({
|
|
5
|
+
leaf,
|
|
6
|
+
options: { renderLeaf },
|
|
7
|
+
block: { content: { formatVersion } }
|
|
8
|
+
}) {
|
|
9
|
+
const fallback = /* @__PURE__ */ jsx(RenderLeafFallback, { leaf });
|
|
10
|
+
return renderLeaf ? createElement(
|
|
11
|
+
renderLeaf,
|
|
12
|
+
{
|
|
13
|
+
formatVersion,
|
|
14
|
+
leaf,
|
|
15
|
+
fallback,
|
|
16
|
+
children: leaf.text
|
|
17
|
+
}
|
|
18
|
+
) : fallback;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
LeafRenderer
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=LeafRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LeafRenderer.js","sources":["../../../../src/internal/components/LeafRenderer.tsx"],"sourcesContent":["import { createElement } from 'react'\nimport type { BuiltinLeaves } from '../../types/builtin/BuiltinLeaves'\nimport { RenderLeafFallback } from './RenderLeafFallback'\nimport type { RichTextLeaf } from '../../types/structure/RichTextLeaf'\nimport { RichTextElement } from '../../types/structure/RichTextElement'\nimport { RichTextRenderingOptions } from '../../types/RichTextRenderingOptions'\nimport { RichTextBlock } from '../../types/RichTextBlock'\n\nexport interface LeafRendererProps<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = RichTextLeaf> {\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves>\n\tblock: RichTextBlock<CustomElements, CustomLeaves>\n\tleaf: CustomLeaves & BuiltinLeaves\n}\n\nexport function LeafRenderer<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n>({\n\tleaf,\n\toptions: { renderLeaf },\n\tblock: { content: { formatVersion } },\n}: LeafRendererProps<CustomElements, CustomLeaves>) {\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\tchildren: leaf.text,\n\t\t\t\t},\n\t\t )\n\t\t: fallback\n}\n"],"names":[],"mappings":";;;AAcO,SAAS,aAGd;AAAA,EACD;AAAA,EACA,SAAS,EAAE,WAAW;AAAA,EACtB,OAAO,EAAE,SAAS,EAAE,gBAAgB;AACrC,GAAoD;AAC7C,QAAA,WAAY,oBAAA,oBAAA,EAAmB,KAAY,CAAA;AAEjD,SAAO,aACJ;AAAA,IACA;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU,KAAK;AAAA,IAChB;AAAA,EAEA,IAAA;AACJ;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const renderChildren = require("../renderChildren.cjs");
|
|
6
|
+
const useReferenceMetadata = require("../useReferenceMetadata.cjs");
|
|
7
|
+
const getElementDataAttributes = (element, attributeNamePrefix = "contember-") => {
|
|
8
|
+
const { children, referenceId, ...extendedSpecifics } = element;
|
|
9
|
+
return Object.fromEntries(
|
|
10
|
+
Object.entries(extendedSpecifics).filter(([, value]) => {
|
|
11
|
+
const t = typeof value;
|
|
12
|
+
return t === "string" || t === "number" || t === "boolean";
|
|
13
|
+
}).map(([attribute, value]) => [`data-${attributeNamePrefix}${attribute.toLowerCase()}`, value])
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
function RenderElementFallback({ element, children, options, block }) {
|
|
17
|
+
const attributes = getElementDataAttributes(element, options.attributeNamePrefix);
|
|
18
|
+
switch (element.type) {
|
|
19
|
+
case "anchor":
|
|
20
|
+
return /* @__PURE__ */ jsxRuntime.jsx("a", { ...attributes, href: element.href, children });
|
|
21
|
+
case "heading":
|
|
22
|
+
return react.createElement(`h${element.level}`, attributes, children);
|
|
23
|
+
case "horizontalRule":
|
|
24
|
+
return /* @__PURE__ */ jsxRuntime.jsx("hr", { ...attributes });
|
|
25
|
+
case "listItem":
|
|
26
|
+
return /* @__PURE__ */ jsxRuntime.jsx("li", { ...attributes, children });
|
|
27
|
+
case "orderedList":
|
|
28
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ol", { ...attributes, children });
|
|
29
|
+
case "paragraph":
|
|
30
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { ...attributes, children });
|
|
31
|
+
case "reference": {
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ReferenceElementFallback, { element, children, options, block });
|
|
33
|
+
}
|
|
34
|
+
case "scrollTarget":
|
|
35
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, id: element.identifier, children });
|
|
36
|
+
case "table": {
|
|
37
|
+
const firstRow = element.children[0];
|
|
38
|
+
if (!firstRow || firstRow.headerScope !== "table") {
|
|
39
|
+
return /* @__PURE__ */ jsxRuntime.jsx("table", { ...attributes, children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children }) });
|
|
40
|
+
}
|
|
41
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("table", { ...attributes, children: [
|
|
42
|
+
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: renderChildren.renderChildren([firstRow], options, block) }),
|
|
43
|
+
/* @__PURE__ */ jsxRuntime.jsx("tbody", { children: renderChildren.renderChildren(element.children.slice(1), options, block) })
|
|
44
|
+
] });
|
|
45
|
+
}
|
|
46
|
+
case "tableRow":
|
|
47
|
+
return /* @__PURE__ */ jsxRuntime.jsx("tr", { ...attributes, children });
|
|
48
|
+
case "tableCell": {
|
|
49
|
+
if (element.headerScope) {
|
|
50
|
+
return /* @__PURE__ */ jsxRuntime.jsx("th", { ...attributes, scope: element.headerScope, children });
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ jsxRuntime.jsx("td", { ...attributes, children });
|
|
53
|
+
}
|
|
54
|
+
case "unorderedList":
|
|
55
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ul", { ...attributes, children });
|
|
56
|
+
default: {
|
|
57
|
+
{
|
|
58
|
+
return children;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function ReferenceElementFallback({ element, children, options, block }) {
|
|
64
|
+
const elementMetadata = useReferenceMetadata.useReferenceMetadata(element, options, block, true);
|
|
65
|
+
if (elementMetadata.referenceRenderer === void 0 || elementMetadata.referenceType === void 0 || elementMetadata.reference === void 0) {
|
|
66
|
+
return children;
|
|
67
|
+
}
|
|
68
|
+
let Renderer = elementMetadata.referenceRenderer;
|
|
69
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
70
|
+
Renderer,
|
|
71
|
+
{
|
|
72
|
+
referenceType: elementMetadata.referenceType,
|
|
73
|
+
referenceRenderer: elementMetadata.referenceRenderer,
|
|
74
|
+
reference: elementMetadata.reference,
|
|
75
|
+
formatVersion: block.content.formatVersion,
|
|
76
|
+
block,
|
|
77
|
+
options,
|
|
78
|
+
element,
|
|
79
|
+
children
|
|
80
|
+
}
|
|
81
|
+
) });
|
|
82
|
+
}
|
|
83
|
+
exports.RenderElementFallback = RenderElementFallback;
|
|
84
|
+
//# sourceMappingURL=RenderElementFallback.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderElementFallback.cjs","sources":["../../../../src/internal/components/RenderElementFallback.tsx"],"sourcesContent":["import { createElement, ReactElement } from 'react'\nimport type { BuiltinElements, RichTextReferenceElement, RichTextTableRowElement } from '../../types/builtin/BuiltinElements'\nimport { renderChildren } from '../renderChildren'\nimport { useReferenceMetadata } from '../useReferenceMetadata'\nimport type { RichTextElement } from '../../types/structure/RichTextElement'\nimport type { RichTextLeaf } from '../../types/structure/RichTextLeaf'\nimport { RichTextRendererError } from '../../RichTextRendererError'\nimport { RichTextBlock } from '../../types/RichTextBlock'\nimport { RichTextRenderingOptions } from '../../types/RichTextRenderingOptions'\n\nexport interface RenderElementFallbackProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n> {\n\telement: BuiltinElements<CustomElements, CustomLeaves>\n\tchildren: ReactElement\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves>\n\tblock: RichTextBlock<CustomElements, CustomLeaves>\n}\n\nconst getElementDataAttributes = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\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 = RichTextLeaf,\n>({ element, children, options, block }: 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} options={options} block={block} />\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, block)}</thead>\n\t\t\t\t\t<tbody>{renderChildren<CustomElements, CustomLeaves>(element.children.slice(1) as any, options, block)}</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\ntype ReferenceElementFallbackProps<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = RichTextLeaf> = {\n\telement: RichTextReferenceElement<CustomElements, CustomLeaves>;\n\tchildren: ReactElement\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves>\n\tblock: RichTextBlock<CustomElements, CustomLeaves>\n}\n\nfunction ReferenceElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n>({ element, children, options, block }: ReferenceElementFallbackProps<CustomElements, CustomLeaves>) {\n\tconst elementMetadata = useReferenceMetadata<CustomElements, CustomLeaves>(element, options, block, true)\n\n\tif (\n\t\telementMetadata.referenceRenderer === undefined ||\n\t\telementMetadata.referenceType === undefined ||\n\t\telementMetadata.reference === undefined\n\t) {\n\t\treturn children // At least render the text contents\n\t}\n\n\tlet Renderer = elementMetadata.referenceRenderer\n\treturn (\n\t\t<>\n\t\t\t<Renderer\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={block.content.formatVersion}\n\t\t\t\tblock={block}\n\t\t\t\toptions={options}\n\t\t\t\telement={element}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</Renderer>\n\t\t</>\n\t)\n}\n"],"names":["createElement","jsx","jsxs","renderChildren","useReferenceMetadata","Fragment"],"mappings":"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"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { renderChildren } from "../renderChildren.js";
|
|
4
|
+
import { useReferenceMetadata } from "../useReferenceMetadata.js";
|
|
5
|
+
const getElementDataAttributes = (element, attributeNamePrefix = "contember-") => {
|
|
6
|
+
const { children, referenceId, ...extendedSpecifics } = element;
|
|
7
|
+
return Object.fromEntries(
|
|
8
|
+
Object.entries(extendedSpecifics).filter(([, value]) => {
|
|
9
|
+
const t = typeof value;
|
|
10
|
+
return t === "string" || t === "number" || t === "boolean";
|
|
11
|
+
}).map(([attribute, value]) => [`data-${attributeNamePrefix}${attribute.toLowerCase()}`, value])
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
function RenderElementFallback({ element, children, options, block }) {
|
|
15
|
+
const attributes = getElementDataAttributes(element, options.attributeNamePrefix);
|
|
16
|
+
switch (element.type) {
|
|
17
|
+
case "anchor":
|
|
18
|
+
return /* @__PURE__ */ jsx("a", { ...attributes, href: element.href, children });
|
|
19
|
+
case "heading":
|
|
20
|
+
return createElement(`h${element.level}`, attributes, children);
|
|
21
|
+
case "horizontalRule":
|
|
22
|
+
return /* @__PURE__ */ jsx("hr", { ...attributes });
|
|
23
|
+
case "listItem":
|
|
24
|
+
return /* @__PURE__ */ jsx("li", { ...attributes, children });
|
|
25
|
+
case "orderedList":
|
|
26
|
+
return /* @__PURE__ */ jsx("ol", { ...attributes, children });
|
|
27
|
+
case "paragraph":
|
|
28
|
+
return /* @__PURE__ */ jsx("p", { ...attributes, children });
|
|
29
|
+
case "reference": {
|
|
30
|
+
return /* @__PURE__ */ jsx(ReferenceElementFallback, { element, children, options, block });
|
|
31
|
+
}
|
|
32
|
+
case "scrollTarget":
|
|
33
|
+
return /* @__PURE__ */ jsx("span", { ...attributes, id: element.identifier, children });
|
|
34
|
+
case "table": {
|
|
35
|
+
const firstRow = element.children[0];
|
|
36
|
+
if (!firstRow || firstRow.headerScope !== "table") {
|
|
37
|
+
return /* @__PURE__ */ jsx("table", { ...attributes, children: /* @__PURE__ */ jsx("tbody", { children }) });
|
|
38
|
+
}
|
|
39
|
+
return /* @__PURE__ */ jsxs("table", { ...attributes, children: [
|
|
40
|
+
/* @__PURE__ */ jsx("thead", { children: renderChildren([firstRow], options, block) }),
|
|
41
|
+
/* @__PURE__ */ jsx("tbody", { children: renderChildren(element.children.slice(1), options, block) })
|
|
42
|
+
] });
|
|
43
|
+
}
|
|
44
|
+
case "tableRow":
|
|
45
|
+
return /* @__PURE__ */ jsx("tr", { ...attributes, children });
|
|
46
|
+
case "tableCell": {
|
|
47
|
+
if (element.headerScope) {
|
|
48
|
+
return /* @__PURE__ */ jsx("th", { ...attributes, scope: element.headerScope, children });
|
|
49
|
+
}
|
|
50
|
+
return /* @__PURE__ */ jsx("td", { ...attributes, children });
|
|
51
|
+
}
|
|
52
|
+
case "unorderedList":
|
|
53
|
+
return /* @__PURE__ */ jsx("ul", { ...attributes, children });
|
|
54
|
+
default: {
|
|
55
|
+
{
|
|
56
|
+
return children;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function ReferenceElementFallback({ element, children, options, block }) {
|
|
62
|
+
const elementMetadata = useReferenceMetadata(element, options, block, true);
|
|
63
|
+
if (elementMetadata.referenceRenderer === void 0 || elementMetadata.referenceType === void 0 || elementMetadata.reference === void 0) {
|
|
64
|
+
return children;
|
|
65
|
+
}
|
|
66
|
+
let Renderer = elementMetadata.referenceRenderer;
|
|
67
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
68
|
+
Renderer,
|
|
69
|
+
{
|
|
70
|
+
referenceType: elementMetadata.referenceType,
|
|
71
|
+
referenceRenderer: elementMetadata.referenceRenderer,
|
|
72
|
+
reference: elementMetadata.reference,
|
|
73
|
+
formatVersion: block.content.formatVersion,
|
|
74
|
+
block,
|
|
75
|
+
options,
|
|
76
|
+
element,
|
|
77
|
+
children
|
|
78
|
+
}
|
|
79
|
+
) });
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
RenderElementFallback
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=RenderElementFallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderElementFallback.js","sources":["../../../../src/internal/components/RenderElementFallback.tsx"],"sourcesContent":["import { createElement, ReactElement } from 'react'\nimport type { BuiltinElements, RichTextReferenceElement, RichTextTableRowElement } from '../../types/builtin/BuiltinElements'\nimport { renderChildren } from '../renderChildren'\nimport { useReferenceMetadata } from '../useReferenceMetadata'\nimport type { RichTextElement } from '../../types/structure/RichTextElement'\nimport type { RichTextLeaf } from '../../types/structure/RichTextLeaf'\nimport { RichTextRendererError } from '../../RichTextRendererError'\nimport { RichTextBlock } from '../../types/RichTextBlock'\nimport { RichTextRenderingOptions } from '../../types/RichTextRenderingOptions'\n\nexport interface RenderElementFallbackProps<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n> {\n\telement: BuiltinElements<CustomElements, CustomLeaves>\n\tchildren: ReactElement\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves>\n\tblock: RichTextBlock<CustomElements, CustomLeaves>\n}\n\nconst getElementDataAttributes = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\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 = RichTextLeaf,\n>({ element, children, options, block }: 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} options={options} block={block} />\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, block)}</thead>\n\t\t\t\t\t<tbody>{renderChildren<CustomElements, CustomLeaves>(element.children.slice(1) as any, options, block)}</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\ntype ReferenceElementFallbackProps<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = RichTextLeaf> = {\n\telement: RichTextReferenceElement<CustomElements, CustomLeaves>;\n\tchildren: ReactElement\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves>\n\tblock: RichTextBlock<CustomElements, CustomLeaves>\n}\n\nfunction ReferenceElementFallback<\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n>({ element, children, options, block }: ReferenceElementFallbackProps<CustomElements, CustomLeaves>) {\n\tconst elementMetadata = useReferenceMetadata<CustomElements, CustomLeaves>(element, options, block, true)\n\n\tif (\n\t\telementMetadata.referenceRenderer === undefined ||\n\t\telementMetadata.referenceType === undefined ||\n\t\telementMetadata.reference === undefined\n\t) {\n\t\treturn children // At least render the text contents\n\t}\n\n\tlet Renderer = elementMetadata.referenceRenderer\n\treturn (\n\t\t<>\n\t\t\t<Renderer\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={block.content.formatVersion}\n\t\t\t\tblock={block}\n\t\t\t\toptions={options}\n\t\t\t\telement={element}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</Renderer>\n\t\t</>\n\t)\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
function jsxN2br(text) {
|
|
6
|
+
const lines = text.split("\n");
|
|
7
|
+
if (lines.length <= 1) {
|
|
8
|
+
return text;
|
|
9
|
+
}
|
|
10
|
+
return lines.map((line, i) => /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
|
|
11
|
+
!!i && /* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
12
|
+
line
|
|
13
|
+
] }, i));
|
|
14
|
+
}
|
|
15
|
+
function RenderLeafFallback({ leaf }) {
|
|
16
|
+
let element = jsxN2br(leaf.text);
|
|
17
|
+
if ("isCode" in leaf && leaf.isCode === true) {
|
|
18
|
+
element = /* @__PURE__ */ jsxRuntime.jsx("code", { children: element });
|
|
19
|
+
}
|
|
20
|
+
if ("isStruckThrough" in leaf && leaf.isStruckThrough === true) {
|
|
21
|
+
element = /* @__PURE__ */ jsxRuntime.jsx("s", { children: element });
|
|
22
|
+
}
|
|
23
|
+
if ("isHighlighted" in leaf && leaf.isHighlighted === true) {
|
|
24
|
+
element = /* @__PURE__ */ jsxRuntime.jsx("em", { children: element });
|
|
25
|
+
}
|
|
26
|
+
if ("isUnderlined" in leaf && leaf.isUnderlined === true) {
|
|
27
|
+
element = /* @__PURE__ */ jsxRuntime.jsx("u", { children: element });
|
|
28
|
+
}
|
|
29
|
+
if ("isItalic" in leaf && leaf.isItalic === true) {
|
|
30
|
+
element = /* @__PURE__ */ jsxRuntime.jsx("i", { children: element });
|
|
31
|
+
}
|
|
32
|
+
if ("isBold" in leaf && leaf.isBold === true) {
|
|
33
|
+
element = /* @__PURE__ */ jsxRuntime.jsx("b", { children: element });
|
|
34
|
+
}
|
|
35
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: element });
|
|
36
|
+
}
|
|
37
|
+
exports.RenderLeafFallback = RenderLeafFallback;
|
|
38
|
+
//# sourceMappingURL=RenderLeafFallback.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderLeafFallback.cjs","sources":["../../../../src/internal/components/RenderLeafFallback.tsx"],"sourcesContent":["import { Fragment, ReactNode } from 'react'\nimport type { BuiltinLeaves } from '../../types/builtin/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":["jsxs","Fragment","jsx"],"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,MACvBA,gCAACC,MAAAA,UAAA,EACC,UAAA;AAAA,IAAC,CAAA,CAAC,KAAKC,+BAAC,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,cAAAA,2BAAA,IAAC,UAAM,UAAQ,QAAA,CAAA;AAAA,EAC1B;AACA,MAAI,qBAAqB,QAAQ,KAAK,oBAAoB,MAAM;AACrD,cAAAA,2BAAA,IAAC,OAAG,UAAQ,QAAA,CAAA;AAAA,EACvB;AACA,MAAI,mBAAmB,QAAQ,KAAK,kBAAkB,MAAM;AACjD,cAAAA,2BAAA,IAAC,QAAI,UAAQ,QAAA,CAAA;AAAA,EACxB;AACA,MAAI,kBAAkB,QAAQ,KAAK,iBAAiB,MAAM;AAC/C,cAAAA,2BAAA,IAAC,OAAG,UAAQ,QAAA,CAAA;AAAA,EACvB;AACA,MAAI,cAAc,QAAQ,KAAK,aAAa,MAAM;AACvC,cAAAA,2BAAA,IAAC,OAAG,UAAQ,QAAA,CAAA;AAAA,EACvB;AACA,MAAI,YAAY,QAAQ,KAAK,WAAW,MAAM;AACnC,cAAAA,2BAAA,IAAC,OAAG,UAAQ,QAAA,CAAA;AAAA,EACvB;AACA,+DAAU,UAAQ,QAAA,CAAA;AACnB;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment as Fragment$1 } from "react";
|
|
3
|
+
function jsxN2br(text) {
|
|
4
|
+
const lines = text.split("\n");
|
|
5
|
+
if (lines.length <= 1) {
|
|
6
|
+
return text;
|
|
7
|
+
}
|
|
8
|
+
return lines.map((line, i) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
9
|
+
!!i && /* @__PURE__ */ jsx("br", {}),
|
|
10
|
+
line
|
|
11
|
+
] }, i));
|
|
12
|
+
}
|
|
13
|
+
function RenderLeafFallback({ leaf }) {
|
|
14
|
+
let element = jsxN2br(leaf.text);
|
|
15
|
+
if ("isCode" in leaf && leaf.isCode === true) {
|
|
16
|
+
element = /* @__PURE__ */ jsx("code", { children: element });
|
|
17
|
+
}
|
|
18
|
+
if ("isStruckThrough" in leaf && leaf.isStruckThrough === true) {
|
|
19
|
+
element = /* @__PURE__ */ jsx("s", { children: element });
|
|
20
|
+
}
|
|
21
|
+
if ("isHighlighted" in leaf && leaf.isHighlighted === true) {
|
|
22
|
+
element = /* @__PURE__ */ jsx("em", { children: element });
|
|
23
|
+
}
|
|
24
|
+
if ("isUnderlined" in leaf && leaf.isUnderlined === true) {
|
|
25
|
+
element = /* @__PURE__ */ jsx("u", { children: element });
|
|
26
|
+
}
|
|
27
|
+
if ("isItalic" in leaf && leaf.isItalic === true) {
|
|
28
|
+
element = /* @__PURE__ */ jsx("i", { children: element });
|
|
29
|
+
}
|
|
30
|
+
if ("isBold" in leaf && leaf.isBold === true) {
|
|
31
|
+
element = /* @__PURE__ */ jsx("b", { children: element });
|
|
32
|
+
}
|
|
33
|
+
return /* @__PURE__ */ jsx(Fragment, { children: element });
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
RenderLeafFallback
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=RenderLeafFallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenderLeafFallback.js","sources":["../../../../src/internal/components/RenderLeafFallback.tsx"],"sourcesContent":["import { Fragment, ReactNode } from 'react'\nimport type { BuiltinLeaves } from '../../types/builtin/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;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const defaultDeserialize = (source) => {
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(source);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
return {
|
|
8
|
+
formatVersion: 0,
|
|
9
|
+
children: []
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
exports.defaultDeserialize = defaultDeserialize;
|
|
14
|
+
//# sourceMappingURL=defaultDeserialize.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultDeserialize.cjs","sources":["../../../src/internal/defaultDeserialize.ts"],"sourcesContent":["import type { RichTextElement } from '../types/structure/RichTextElement'\nimport type { RichTextLeaf } from '../types/structure/RichTextLeaf'\nimport type { RootEditorNode } from '../types/structure/RootEditorNode'\n\nexport const defaultDeserialize = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n>(\n\tsource: string,\n): RootEditorNode<CustomElements, CustomLeaves> => {\n\ttry {\n\t\treturn JSON.parse(source)\n\t} catch (e) {\n\t\treturn {\n\t\t\tformatVersion: 0,\n\t\t\tchildren: [],\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAIa,MAAA,qBAAqB,CAIjC,WACkD;AAC9C,MAAA;AACI,WAAA,KAAK,MAAM,MAAM;AAAA,WAChB,GAAG;AACJ,WAAA;AAAA,MACN,eAAe;AAAA,MACf,UAAU,CAAC;AAAA,IAAA;AAAA,EAEb;AACD;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultDeserialize.js","sources":["../../../src/internal/defaultDeserialize.ts"],"sourcesContent":["import type { RichTextElement } from '../types/structure/RichTextElement'\nimport type { RichTextLeaf } from '../types/structure/RichTextLeaf'\nimport type { RootEditorNode } from '../types/structure/RootEditorNode'\n\nexport const defaultDeserialize = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n>(\n\tsource: string,\n): RootEditorNode<CustomElements, CustomLeaves> => {\n\ttry {\n\t\treturn JSON.parse(source)\n\t} catch (e) {\n\t\treturn {\n\t\t\tformatVersion: 0,\n\t\t\tchildren: [],\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAIa,MAAA,qBAAqB,CAIjC,WACkD;AAC9C,MAAA;AACI,WAAA,KAAK,MAAM,MAAM;AAAA,WAChB,GAAG;AACJ,WAAA;AAAA,MACN,eAAe;AAAA,MACf,UAAU,CAAC;AAAA,IAAA;AAAA,EAEb;AACD;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const ElementRenderer = require("./components/ElementRenderer.cjs");
|
|
5
|
+
const LeafRenderer = require("./components/LeafRenderer.cjs");
|
|
6
|
+
const renderChildren = (children, options, block) => {
|
|
7
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: (Array.isArray(children) ? children : [children]).map((child, i) => {
|
|
8
|
+
if ("text" in child) {
|
|
9
|
+
return /* @__PURE__ */ jsxRuntime.jsx(LeafRenderer.LeafRenderer, { leaf: child, options, block }, i);
|
|
10
|
+
}
|
|
11
|
+
if ("children" in child) {
|
|
12
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ElementRenderer.ElementRenderer, { element: child, options, block, children: renderChildren(child.children, options, block) }, i);
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}) });
|
|
16
|
+
};
|
|
17
|
+
exports.renderChildren = renderChildren;
|
|
18
|
+
//# sourceMappingURL=renderChildren.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderChildren.cjs","sources":["../../../src/internal/renderChildren.tsx"],"sourcesContent":["import type { ReactElement } from 'react'\nimport { ElementRenderer } from './components/ElementRenderer'\nimport { LeafRenderer } from './components/LeafRenderer'\nimport type { RichTextElement } from '../types/structure/RichTextElement'\nimport type { RichTextLeaf } from '../types/structure/RichTextLeaf'\nimport { RichTextRenderingOptions } from '../types/RichTextRenderingOptions'\nimport { RichTextBlock } from '../types/RichTextBlock'\nimport { RichTextChild } from '../types/structure/RichTextChild'\n\nexport const renderChildren = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n>(\n\tchildren:\n\t\t| RichTextChild<CustomElements, CustomLeaves>\n\t\t| readonly RichTextChild<CustomElements, CustomLeaves>[],\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves>,\n\tblock: RichTextBlock<CustomElements, CustomLeaves>,\n): ReactElement => {\n\treturn (\n\t\t<>\n\t\t\t{(Array.isArray(children) ? children : [children]).map((child, i) => {\n\t\t\t\tif ('text' in child) {\n\t\t\t\t\treturn <LeafRenderer<CustomElements, CustomLeaves> key={i} leaf={child} options={options} block={block} />\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} block={block}>\n\t\t\t\t\t\t\t{renderChildren<CustomElements, CustomLeaves>(child.children as typeof children, options, block)}\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":["jsx","Fragment","LeafRenderer","ElementRenderer"],"mappings":";;;;;AASO,MAAM,iBAAiB,CAI7B,UAGA,SACA,UACkB;AAClB,SAEIA,2BAAAA,IAAAC,WAAAA,UAAA,EAAA,WAAA,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,MAAM;AACpE,QAAI,UAAU,OAAO;AACpB,4CAAQC,aAAmD,cAAA,EAAA,MAAM,OAAO,SAAkB,SAAlC,CAAgD;AAAA,IACzG;AACA,QAAI,cAAc,OAAO;AACxB,aACEF,2BAAAA,IAAAG,gBAAAA,iBAAA,EAAsD,SAAS,OAAO,SAAkB,OACvF,UAA6C,eAAA,MAAM,UAA6B,SAAS,KAAK,EAAA,GAD5C,CAEpD;AAAA,IAEF;AACO,WAAA;AAAA,EACP,CAAA,EACF,CAAA;AAEF;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { ElementRenderer } from "./components/ElementRenderer.js";
|
|
3
|
+
import { LeafRenderer } from "./components/LeafRenderer.js";
|
|
4
|
+
const renderChildren = (children, options, block) => {
|
|
5
|
+
return /* @__PURE__ */ jsx(Fragment, { children: (Array.isArray(children) ? children : [children]).map((child, i) => {
|
|
6
|
+
if ("text" in child) {
|
|
7
|
+
return /* @__PURE__ */ jsx(LeafRenderer, { leaf: child, options, block }, i);
|
|
8
|
+
}
|
|
9
|
+
if ("children" in child) {
|
|
10
|
+
return /* @__PURE__ */ jsx(ElementRenderer, { element: child, options, block, children: renderChildren(child.children, options, block) }, i);
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}) });
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
renderChildren
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=renderChildren.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderChildren.js","sources":["../../../src/internal/renderChildren.tsx"],"sourcesContent":["import type { ReactElement } from 'react'\nimport { ElementRenderer } from './components/ElementRenderer'\nimport { LeafRenderer } from './components/LeafRenderer'\nimport type { RichTextElement } from '../types/structure/RichTextElement'\nimport type { RichTextLeaf } from '../types/structure/RichTextLeaf'\nimport { RichTextRenderingOptions } from '../types/RichTextRenderingOptions'\nimport { RichTextBlock } from '../types/RichTextBlock'\nimport { RichTextChild } from '../types/structure/RichTextChild'\n\nexport const renderChildren = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n>(\n\tchildren:\n\t\t| RichTextChild<CustomElements, CustomLeaves>\n\t\t| readonly RichTextChild<CustomElements, CustomLeaves>[],\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves>,\n\tblock: RichTextBlock<CustomElements, CustomLeaves>,\n): ReactElement => {\n\treturn (\n\t\t<>\n\t\t\t{(Array.isArray(children) ? children : [children]).map((child, i) => {\n\t\t\t\tif ('text' in child) {\n\t\t\t\t\treturn <LeafRenderer<CustomElements, CustomLeaves> key={i} leaf={child} options={options} block={block} />\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} block={block}>\n\t\t\t\t\t\t\t{renderChildren<CustomElements, CustomLeaves>(child.children as typeof children, options, block)}\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":";;;AASO,MAAM,iBAAiB,CAI7B,UAGA,SACA,UACkB;AAClB,SAEI,oBAAA,UAAA,EAAA,WAAA,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,MAAM;AACpE,QAAI,UAAU,OAAO;AACpB,iCAAQ,cAAmD,EAAA,MAAM,OAAO,SAAkB,SAAlC,CAAgD;AAAA,IACzG;AACA,QAAI,cAAc,OAAO;AACxB,aACE,oBAAA,iBAAA,EAAsD,SAAS,OAAO,SAAkB,OACvF,UAA6C,eAAA,MAAM,UAA6B,SAAS,KAAK,EAAA,GAD5C,CAEpD;AAAA,IAEF;AACO,WAAA;AAAA,EACP,CAAA,EACF,CAAA;AAEF;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const RichTextRendererError = require("../RichTextRendererError.cjs");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const emptyReference = {
|
|
6
|
+
reference: void 0,
|
|
7
|
+
referenceType: void 0,
|
|
8
|
+
referenceRenderer: void 0
|
|
9
|
+
};
|
|
10
|
+
const useReferenceMetadata = (element, options, block, expectReference = false) => {
|
|
11
|
+
const undefinedReferenceHandler = options.undefinedReferenceHandler;
|
|
12
|
+
const referenceRenderers = options.referenceRenderers;
|
|
13
|
+
return react.useMemo(() => {
|
|
14
|
+
const id = element["referenceId"];
|
|
15
|
+
if (typeof id !== "string") {
|
|
16
|
+
return emptyReference;
|
|
17
|
+
}
|
|
18
|
+
const reference = block.references?.[id];
|
|
19
|
+
if (reference === void 0) {
|
|
20
|
+
if (undefinedReferenceHandler) {
|
|
21
|
+
return undefinedReferenceHandler(id) ?? emptyReference;
|
|
22
|
+
} else {
|
|
23
|
+
throw new RichTextRendererError.RichTextRendererError(
|
|
24
|
+
`RichTextRenderer: Cannot find reference id '${id}'`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const referenceRenderer = referenceRenderers?.[reference.type];
|
|
29
|
+
return {
|
|
30
|
+
reference,
|
|
31
|
+
referenceType: reference.type,
|
|
32
|
+
referenceRenderer
|
|
33
|
+
};
|
|
34
|
+
}, [block.references, element, expectReference, referenceRenderers, undefinedReferenceHandler]);
|
|
35
|
+
};
|
|
36
|
+
exports.useReferenceMetadata = useReferenceMetadata;
|
|
37
|
+
//# sourceMappingURL=useReferenceMetadata.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReferenceMetadata.cjs","sources":["../../../src/internal/useReferenceMetadata.ts"],"sourcesContent":["import type { BuiltinElements } from '../types/builtin/BuiltinElements'\nimport type { RichTextElement } from '../types/structure/RichTextElement'\nimport type { RichTextReferenceMetadata } from '../types/RichTextReferenceMetadata'\nimport { RichTextReferenceEmptyMetadata } from '../types/RichTextReferenceMetadata'\nimport type { RichTextLeaf } from '../types/structure/RichTextLeaf'\nimport type { RichTextReference } from '../types/RichTextReference'\nimport { RichTextRendererError } from '../RichTextRendererError'\nimport { RichTextBlock } from '../types/RichTextBlock'\nimport { RichTextRenderingOptions } from '../types/RichTextRenderingOptions'\nimport { useMemo } from 'react'\n\nconst emptyReference: RichTextReferenceEmptyMetadata = {\n\treference: undefined,\n\treferenceType: undefined,\n\treferenceRenderer: undefined,\n}\nexport const useReferenceMetadata = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n\tReference extends RichTextReference = RichTextReference,\n>(\n\telement: CustomElements | BuiltinElements<CustomElements, CustomLeaves>,\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves, Reference>,\n\tblock: RichTextBlock<CustomElements, CustomLeaves>,\n\texpectReference: boolean = false,\n): RichTextReferenceMetadata<CustomElements, CustomLeaves, Reference> => {\n\tconst undefinedReferenceHandler = options.undefinedReferenceHandler\n\tconst referenceRenderers = options.referenceRenderers\n\n\treturn useMemo(() => {\n\t\tconst id = element['referenceId']\n\n\t\tif (typeof id !== 'string') {\n\t\t\tif (import.meta.env.DEV && expectReference) {\n\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t`RichTextRenderer: Expected element to have a referenceId.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn emptyReference\n\t\t}\n\n\t\tconst reference: Reference | undefined = block.references?.[id] as Reference | undefined\n\n\t\tif (reference === undefined) {\n\t\t\tif (undefinedReferenceHandler) {\n\t\t\t\treturn undefinedReferenceHandler(id) ?? emptyReference\n\t\t\t} else {\n\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t`RichTextRenderer: Cannot find reference id '${id}'`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tconst referenceRenderer = referenceRenderers?.[reference.type]\n\n\t\treturn {\n\t\t\treference,\n\t\t\treferenceType: reference.type,\n\t\t\treferenceRenderer,\n\t\t}\n\t}, [block.references, element, expectReference, referenceRenderers, undefinedReferenceHandler])\n}\n"],"names":["useMemo","RichTextRendererError"],"mappings":";;;;AAWA,MAAM,iBAAiD;AAAA,EACtD,WAAW;AAAA,EACX,eAAe;AAAA,EACf,mBAAmB;AACpB;AACO,MAAM,uBAAuB,CAKnC,SACA,SACA,OACA,kBAA2B,UAC6C;AACxE,QAAM,4BAA4B,QAAQ;AAC1C,QAAM,qBAAqB,QAAQ;AAEnC,SAAOA,cAAQ,MAAM;AACd,UAAA,KAAK,QAAQ,aAAa;AAE5B,QAAA,OAAO,OAAO,UAAU;AAMpB,aAAA;AAAA,IACR;AAEM,UAAA,YAAmC,MAAM,aAAa,EAAE;AAE9D,QAAI,cAAc,QAAW;AAC5B,UAAI,2BAA2B;AACvB,eAAA,0BAA0B,EAAE,KAAK;AAAA,MAAA,OAClC;AACN,cAAM,IAAIC,sBAAA;AAAA,UACT,+CAA+C,EAAE;AAAA,QAAA;AAAA,MAEnD;AAAA,IACD;AAEM,UAAA,oBAAoB,qBAAqB,UAAU,IAAI;AAEtD,WAAA;AAAA,MACN;AAAA,MACA,eAAe,UAAU;AAAA,MACzB;AAAA,IAAA;AAAA,EACD,GACE,CAAC,MAAM,YAAY,SAAS,iBAAiB,oBAAoB,yBAAyB,CAAC;AAC/F;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { RichTextRendererError } from "../RichTextRendererError.js";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
const emptyReference = {
|
|
4
|
+
reference: void 0,
|
|
5
|
+
referenceType: void 0,
|
|
6
|
+
referenceRenderer: void 0
|
|
7
|
+
};
|
|
8
|
+
const useReferenceMetadata = (element, options, block, expectReference = false) => {
|
|
9
|
+
const undefinedReferenceHandler = options.undefinedReferenceHandler;
|
|
10
|
+
const referenceRenderers = options.referenceRenderers;
|
|
11
|
+
return useMemo(() => {
|
|
12
|
+
const id = element["referenceId"];
|
|
13
|
+
if (typeof id !== "string") {
|
|
14
|
+
return emptyReference;
|
|
15
|
+
}
|
|
16
|
+
const reference = block.references?.[id];
|
|
17
|
+
if (reference === void 0) {
|
|
18
|
+
if (undefinedReferenceHandler) {
|
|
19
|
+
return undefinedReferenceHandler(id) ?? emptyReference;
|
|
20
|
+
} else {
|
|
21
|
+
throw new RichTextRendererError(
|
|
22
|
+
`RichTextRenderer: Cannot find reference id '${id}'`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const referenceRenderer = referenceRenderers?.[reference.type];
|
|
27
|
+
return {
|
|
28
|
+
reference,
|
|
29
|
+
referenceType: reference.type,
|
|
30
|
+
referenceRenderer
|
|
31
|
+
};
|
|
32
|
+
}, [block.references, element, expectReference, referenceRenderers, undefinedReferenceHandler]);
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
useReferenceMetadata
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=useReferenceMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReferenceMetadata.js","sources":["../../../src/internal/useReferenceMetadata.ts"],"sourcesContent":["import type { BuiltinElements } from '../types/builtin/BuiltinElements'\nimport type { RichTextElement } from '../types/structure/RichTextElement'\nimport type { RichTextReferenceMetadata } from '../types/RichTextReferenceMetadata'\nimport { RichTextReferenceEmptyMetadata } from '../types/RichTextReferenceMetadata'\nimport type { RichTextLeaf } from '../types/structure/RichTextLeaf'\nimport type { RichTextReference } from '../types/RichTextReference'\nimport { RichTextRendererError } from '../RichTextRendererError'\nimport { RichTextBlock } from '../types/RichTextBlock'\nimport { RichTextRenderingOptions } from '../types/RichTextRenderingOptions'\nimport { useMemo } from 'react'\n\nconst emptyReference: RichTextReferenceEmptyMetadata = {\n\treference: undefined,\n\treferenceType: undefined,\n\treferenceRenderer: undefined,\n}\nexport const useReferenceMetadata = <\n\tCustomElements extends RichTextElement = never,\n\tCustomLeaves extends RichTextLeaf = RichTextLeaf,\n\tReference extends RichTextReference = RichTextReference,\n>(\n\telement: CustomElements | BuiltinElements<CustomElements, CustomLeaves>,\n\toptions: RichTextRenderingOptions<CustomElements, CustomLeaves, Reference>,\n\tblock: RichTextBlock<CustomElements, CustomLeaves>,\n\texpectReference: boolean = false,\n): RichTextReferenceMetadata<CustomElements, CustomLeaves, Reference> => {\n\tconst undefinedReferenceHandler = options.undefinedReferenceHandler\n\tconst referenceRenderers = options.referenceRenderers\n\n\treturn useMemo(() => {\n\t\tconst id = element['referenceId']\n\n\t\tif (typeof id !== 'string') {\n\t\t\tif (import.meta.env.DEV && expectReference) {\n\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t`RichTextRenderer: Expected element to have a referenceId.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn emptyReference\n\t\t}\n\n\t\tconst reference: Reference | undefined = block.references?.[id] as Reference | undefined\n\n\t\tif (reference === undefined) {\n\t\t\tif (undefinedReferenceHandler) {\n\t\t\t\treturn undefinedReferenceHandler(id) ?? emptyReference\n\t\t\t} else {\n\t\t\t\tthrow new RichTextRendererError(\n\t\t\t\t\t`RichTextRenderer: Cannot find reference id '${id}'`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tconst referenceRenderer = referenceRenderers?.[reference.type]\n\n\t\treturn {\n\t\t\treference,\n\t\t\treferenceType: reference.type,\n\t\t\treferenceRenderer,\n\t\t}\n\t}, [block.references, element, expectReference, referenceRenderers, undefinedReferenceHandler])\n}\n"],"names":[],"mappings":";;AAWA,MAAM,iBAAiD;AAAA,EACtD,WAAW;AAAA,EACX,eAAe;AAAA,EACf,mBAAmB;AACpB;AACO,MAAM,uBAAuB,CAKnC,SACA,SACA,OACA,kBAA2B,UAC6C;AACxE,QAAM,4BAA4B,QAAQ;AAC1C,QAAM,qBAAqB,QAAQ;AAEnC,SAAO,QAAQ,MAAM;AACd,UAAA,KAAK,QAAQ,aAAa;AAE5B,QAAA,OAAO,OAAO,UAAU;AAMpB,aAAA;AAAA,IACR;AAEM,UAAA,YAAmC,MAAM,aAAa,EAAE;AAE9D,QAAI,cAAc,QAAW;AAC5B,UAAI,2BAA2B;AACvB,eAAA,0BAA0B,EAAE,KAAK;AAAA,MAAA,OAClC;AACN,cAAM,IAAI;AAAA,UACT,+CAA+C,EAAE;AAAA,QAAA;AAAA,MAEnD;AAAA,IACD;AAEM,UAAA,oBAAoB,qBAAqB,UAAU,IAAI;AAEtD,WAAA;AAAA,MACN;AAAA,MACA,eAAe,UAAU;AAAA,MACzB;AAAA,IAAA;AAAA,EACD,GACE,CAAC,MAAM,YAAY,SAAS,iBAAiB,oBAAoB,yBAAyB,CAAC;AAC/F;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichTextRendererError.cjs","sources":["../../src/RichTextRendererError.ts"],"sourcesContent":["export class RichTextRendererError extends Error {}\n"],"names":[],"mappings":";;AAAO,MAAM,8BAA8B,MAAM;AAAC;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichTextRendererError.js","sources":["../../src/RichTextRendererError.ts"],"sourcesContent":["export class RichTextRendererError extends Error {}\n"],"names":[],"mappings":"AAAO,MAAM,8BAA8B,MAAM;AAAC;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const renderChildren = require("../internal/renderChildren.cjs");
|
|
6
|
+
const RichText = ({
|
|
7
|
+
blocks,
|
|
8
|
+
renderElement,
|
|
9
|
+
renderLeaf,
|
|
10
|
+
renderBlock = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }),
|
|
11
|
+
attributeNamePrefix,
|
|
12
|
+
referenceRenderers,
|
|
13
|
+
undefinedReferenceHandler
|
|
14
|
+
}) => {
|
|
15
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: blocks.map((block, i) => react.createElement(
|
|
16
|
+
renderBlock,
|
|
17
|
+
{
|
|
18
|
+
block,
|
|
19
|
+
key: block.id ?? i
|
|
20
|
+
},
|
|
21
|
+
renderChildren.renderChildren(block.content.children, {
|
|
22
|
+
referenceRenderers,
|
|
23
|
+
renderBlock,
|
|
24
|
+
renderLeaf,
|
|
25
|
+
renderElement,
|
|
26
|
+
attributeNamePrefix,
|
|
27
|
+
undefinedReferenceHandler
|
|
28
|
+
}, block)
|
|
29
|
+
)) });
|
|
30
|
+
};
|
|
31
|
+
exports.RichText = RichText;
|
|
32
|
+
//# sourceMappingURL=RichText.cjs.map
|