@contensis/canvas-react
Version:
Render canvas content with React
576 lines (574 loc) • 33.9 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
Anchor: () => Anchor,
Code: () => Code,
Component: () => Component,
Delete: () => Delete,
Divider: () => Divider,
Emphasis: () => Emphasis,
FormContentType: () => FormContentType,
Fragment: () => Fragment,
Heading: () => Heading,
Image: () => Image,
InlineCode: () => InlineCode,
InlineEntry: () => InlineEntry,
Insert: () => Insert,
Keyboard: () => Keyboard,
LineBreak: () => LineBreak,
Link: () => Link,
Liquid: () => Liquid,
List: () => List,
ListItem: () => ListItem,
Mark: () => Mark,
Panel: () => Panel,
Paragraph: () => Paragraph,
Quote: () => Quote,
RenderChildren: () => RenderChildren,
RenderContextProvider: () => RenderContextProvider,
Renderer: () => Renderer,
RendererContext: () => RendererContext,
Strikethrough: () => Strikethrough,
Strong: () => Strong,
Subscript: () => Subscript,
Superscript: () => Superscript,
Table: () => Table,
TableBody: () => TableBody,
TableCaption: () => TableCaption,
TableCell: () => TableCell,
TableFooter: () => TableFooter,
TableHeader: () => TableHeader,
TableHeaderCell: () => TableHeaderCell,
TableRow: () => TableRow,
Underline: () => Underline,
Variable: () => Variable
});
module.exports = __toCommonJS(src_exports);
// src/renderer.tsx
var import_react = __toESM(require("react"));
var RendererContext = (0, import_react.createContext)({});
function RenderContextProvider(props) {
const overrideBlocks = props.blocks;
const blocks = Object.keys(BLOCK_RENDERERS).reduce((prev, type) => {
const blockType = type;
const renderer = (overrideBlocks == null ? void 0 : overrideBlocks[blockType]) || BLOCK_RENDERERS[blockType];
prev[blockType] = renderer;
return prev;
}, {});
const overrideDecorators = props.decorators;
const decorators = Object.keys(DECORATOR_RENDERERS).reduce((prev, type) => {
const decoratorType = type;
prev[decoratorType] = (overrideDecorators == null ? void 0 : overrideDecorators[decoratorType]) || DECORATOR_RENDERERS[decoratorType];
return prev;
}, {});
const value = { blocks, decorators, components: props.components };
return /* @__PURE__ */ import_react.default.createElement(RendererContext.Provider, { value }, props.children);
}
function useBlocks() {
const value = (0, import_react.useContext)(RendererContext);
return value.blocks || BLOCK_RENDERERS;
}
function useDecorators() {
const value = (0, import_react.useContext)(RendererContext);
return value.decorators || DECORATOR_RENDERERS;
}
function useComponents() {
const value = (0, import_react.useContext)(RendererContext);
return value.components || {};
}
function RenderBlock(props) {
const blocks = useBlocks();
const Component2 = blocks[props.block.type];
return !!Component2 ? /* @__PURE__ */ import_react.default.createElement(Component2, { block: props.block }) : null;
}
function RenderBlocks(props) {
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.blocks.map((block) => /* @__PURE__ */ import_react.default.createElement(RenderBlock, { block, key: block.id })));
}
function RenderContents(props) {
return props.contents ? props.contents : props.fallback;
}
function RenderChildren(props) {
var _a, _b;
const isArray = Array.isArray((_a = props.block) == null ? void 0 : _a.value);
const isString = typeof ((_b = props.block) == null ? void 0 : _b.value) === "string";
const render = () => {
if (isArray) {
return /* @__PURE__ */ import_react.default.createElement(RenderBlocks, { blocks: props.block.value });
} else if (isString) {
return /* @__PURE__ */ import_react.default.createElement(RenderText, { text: props.block.value });
} else {
return /* @__PURE__ */ import_react.default.createElement(RenderText, { text: "" });
}
};
return render();
}
function RenderText(props) {
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.text);
}
function Renderer(props) {
return /* @__PURE__ */ import_react.default.createElement(RenderBlocks, { blocks: props.data });
}
function getAttributes(props, extra = {}) {
var _c;
const _a = props, { block } = _a, rest = __objRest(_a, ["block"]);
let _b = rest, { children, decorator, otherDecorators } = _b, attributes = __objRest(_b, ["children", "decorator", "otherDecorators"]);
attributes = __spreadValues(__spreadValues({
id: (_c = block == null ? void 0 : block.properties) == null ? void 0 : _c.id
}, extra), attributes);
return attributes;
}
function WithCaption(props) {
return !!props.caption ? /* @__PURE__ */ import_react.default.createElement("figure", null, props.children, /* @__PURE__ */ import_react.default.createElement("figcaption", null, props.caption)) : props.children || null;
}
function RenderBlockChildrenFactory() {
return function(props) {
return /* @__PURE__ */ import_react.default.createElement(RenderChildren, { block: props.block });
};
}
function EmptyChildrenFactory() {
return function(props) {
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
};
}
function Anchor(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("a", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Anchor.Children, { block: props.block }) }));
}
Anchor.Children = RenderBlockChildrenFactory();
function Code(props) {
var _a, _b, _c, _d;
const attributes = getAttributes(props, {
"data-language": (_b = (_a = props.block) == null ? void 0 : _a.value) == null ? void 0 : _b.language
});
const codeAttributes = getAttributes(props, {
className: `language-${(_d = (_c = props.block) == null ? void 0 : _c.value) == null ? void 0 : _d.language}`
});
return /* @__PURE__ */ import_react.default.createElement("pre", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement("code", __spreadValues({}, codeAttributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Code.Children, { block: props.block }) })));
}
Code.Children = function(props) {
var _a, _b;
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, (_b = (_a = props.block) == null ? void 0 : _a.value) == null ? void 0 : _b.code);
};
function CodeWithCaption(props) {
var _a, _b;
return /* @__PURE__ */ import_react.default.createElement(WithCaption, { caption: (_b = (_a = props.block) == null ? void 0 : _a.value) == null ? void 0 : _b.caption }, /* @__PURE__ */ import_react.default.createElement(Code, __spreadValues({}, props)));
}
function Component(props) {
var _a, _b;
const component = (_a = props == null ? void 0 : props.block.properties) == null ? void 0 : _a.component;
const components = useComponents();
const ComponentElement = !!component ? components == null ? void 0 : components[component] : void 0;
const value = props.block.value ? JSON.stringify(props.block.value) : "";
const attributes = getAttributes(props, {
className: "component",
"data-component": (_b = props.block.properties) == null ? void 0 : _b.component,
"data-component-value": value
});
return !!ComponentElement ? /* @__PURE__ */ import_react.default.createElement(ComponentElement, __spreadValues({}, props)) : /* @__PURE__ */ import_react.default.createElement("div", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Component.Children, { block: props.block }) }));
}
Component.Children = function(props) {
var _a, _b;
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, "Component: ", (_b = (_a = props.block) == null ? void 0 : _a.properties) == null ? void 0 : _b.component);
};
function Divider(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("hr", __spreadValues({}, attributes));
}
Divider.Children = EmptyChildrenFactory();
function FormContentType(_props) {
return null;
}
FormContentType.Children = function(_props) {
return null;
};
function Fragment(props) {
var _a, _b, _c, _d, _e;
const hasDecorators = !!((_c = (_b = (_a = props.block) == null ? void 0 : _a.properties) == null ? void 0 : _b.decorators) == null ? void 0 : _c.length);
const decorators = (_e = (_d = props.block) == null ? void 0 : _d.properties) == null ? void 0 : _e.decorators;
return hasDecorators ? /* @__PURE__ */ import_react.default.createElement(Decorators, { block: props.block, decorators }) : /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Fragment.Children, { block: props.block }) });
}
Fragment.Children = RenderBlockChildrenFactory();
function Heading(props) {
const attributes = getAttributes(props);
const render = () => {
var _a, _b;
switch ((_b = (_a = props == null ? void 0 : props.block) == null ? void 0 : _a.properties) == null ? void 0 : _b.level) {
case 2: {
return /* @__PURE__ */ import_react.default.createElement("h2", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Heading.Children, { block: props.block }) }));
}
case 3: {
return /* @__PURE__ */ import_react.default.createElement("h3", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Heading.Children, { block: props.block }) }));
}
case 4: {
return /* @__PURE__ */ import_react.default.createElement("h4", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Heading.Children, { block: props.block }) }));
}
case 5: {
return /* @__PURE__ */ import_react.default.createElement("h5", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Heading.Children, { block: props.block }) }));
}
case 6: {
return /* @__PURE__ */ import_react.default.createElement("h6", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Heading.Children, { block: props.block }) }));
}
default: {
return /* @__PURE__ */ import_react.default.createElement("h1", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Heading.Children, { block: props.block }) }));
}
}
};
return render();
}
Heading.Children = RenderBlockChildrenFactory();
function Image(props) {
var _a, _b, _c, _d, _e, _f, _g, _h;
const src = (_d = (_c = (_b = (_a = props.block) == null ? void 0 : _a.value) == null ? void 0 : _b.asset) == null ? void 0 : _c.sys) == null ? void 0 : _d.uri;
const attributes = getAttributes(props, {
src,
alt: (_f = (_e = props.block) == null ? void 0 : _e.value) == null ? void 0 : _f.altText,
title: (_h = (_g = props == null ? void 0 : props.block) == null ? void 0 : _g.value) == null ? void 0 : _h.caption
});
return /* @__PURE__ */ import_react.default.createElement("img", __spreadValues({}, attributes));
}
Image.Children = EmptyChildrenFactory();
function ImageWithCaption(props) {
var _a, _b;
return /* @__PURE__ */ import_react.default.createElement(WithCaption, { caption: (_b = (_a = props.block) == null ? void 0 : _a.value) == null ? void 0 : _b.caption }, /* @__PURE__ */ import_react.default.createElement(Image, __spreadValues({}, props)));
}
function InlineEntry(props) {
var _a, _b, _c;
const href = (_c = (_b = (_a = props == null ? void 0 : props.block) == null ? void 0 : _a.value) == null ? void 0 : _b.sys) == null ? void 0 : _c.uri;
const attributes = getAttributes(props, {
href
});
return !!attributes.href ? /* @__PURE__ */ import_react.default.createElement("a", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(InlineEntry.Children, { block: props.block }) })) : /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(InlineEntry.Children, { block: props.block }) });
}
InlineEntry.Children = function(props) {
var _a, _b;
const entryTitle = ((_b = (_a = props == null ? void 0 : props.block) == null ? void 0 : _a.value) == null ? void 0 : _b.entryTitle) || "";
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, entryTitle);
};
function Link(props) {
var _a, _b, _c, _d, _e, _f, _g;
const linkValue = (_b = (_a = props == null ? void 0 : props.block) == null ? void 0 : _a.properties) == null ? void 0 : _b.link;
const attributes = getAttributes(props, {
href: (_c = linkValue == null ? void 0 : linkValue.sys) == null ? void 0 : _c.uri,
target: ((_e = (_d = props == null ? void 0 : props.block) == null ? void 0 : _d.properties) == null ? void 0 : _e.newTab) ? "_blank" : null,
rel: ((_g = (_f = props == null ? void 0 : props.block) == null ? void 0 : _f.properties) == null ? void 0 : _g.newTab) ? "noopener noreferrer" : null
});
return !!attributes.href ? /* @__PURE__ */ import_react.default.createElement("a", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Link.Children, { block: props.block }) })) : /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Link.Children, { block: props.block }) });
}
Link.Children = RenderBlockChildrenFactory();
function Liquid(props) {
return /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Liquid.Children, { block: props.block }) });
}
Liquid.Children = function(props) {
var _a;
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, (_a = props.block) == null ? void 0 : _a.value);
};
function List(props) {
var _a, _b, _c, _d;
const isOrdered = ((_b = (_a = props.block) == null ? void 0 : _a.properties) == null ? void 0 : _b.listType) === "ordered";
const attributes = getAttributes(props, {
start: isOrdered ? (_d = (_c = props.block) == null ? void 0 : _c.properties) == null ? void 0 : _d.start : null
});
return isOrdered ? /* @__PURE__ */ import_react.default.createElement("ol", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(List.Children, { block: props.block }) })) : /* @__PURE__ */ import_react.default.createElement("ul", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(List.Children, { block: props.block }) }));
}
List.Children = RenderBlockChildrenFactory();
function ListItem(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("li", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(ListItem.Children, { block: props.block }) }));
}
ListItem.Children = RenderBlockChildrenFactory();
function Panel(props) {
var _a, _b;
const attributes = getAttributes(props, {
className: ["panel", ((_b = (_a = props.block) == null ? void 0 : _a.properties) == null ? void 0 : _b.panelType) || "info"].join(" ")
});
return /* @__PURE__ */ import_react.default.createElement("aside", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Panel.Children, { block: props.block }) }));
}
Panel.Children = RenderBlockChildrenFactory();
function Paragraph(props) {
var _a, _b;
const attributes = getAttributes(props, {
className: (_b = (_a = props.block) == null ? void 0 : _a.properties) == null ? void 0 : _b.paragraphType
});
return /* @__PURE__ */ import_react.default.createElement("p", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Paragraph.Children, { block: props.block }) }));
}
Paragraph.Children = RenderBlockChildrenFactory();
function Quote(props) {
var _a, _b;
const attributes = getAttributes(props, {
"cite": (_b = (_a = props.block) == null ? void 0 : _a.properties) == null ? void 0 : _b.url
});
return /* @__PURE__ */ import_react.default.createElement("blockquote", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Quote.Children, { block: props.block }) }));
}
Quote.Children = function(props) {
var _a, _b, _c, _d;
const source = (_b = (_a = props.block) == null ? void 0 : _a.properties) == null ? void 0 : _b.source;
const citation = (_d = (_c = props.block) == null ? void 0 : _c.properties) == null ? void 0 : _d.citation;
const hasChildren = !!source || !!citation;
return hasChildren ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("p", null, /* @__PURE__ */ import_react.default.createElement(RenderChildren, { block: props.block })), /* @__PURE__ */ import_react.default.createElement("footer", null, source, " ", !!citation ? /* @__PURE__ */ import_react.default.createElement("cite", null, citation) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null))) : /* @__PURE__ */ import_react.default.createElement(RenderChildren, { block: props.block });
};
function Table(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("table", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Table.Children, { block: props.block }) }));
}
Table.Children = RenderBlockChildrenFactory();
function TableBody(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("tbody", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(TableBody.Children, { block: props.block }) }));
}
TableBody.Children = RenderBlockChildrenFactory();
function TableCaption(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("caption", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(TableCaption.Children, { block: props.block }) }));
}
TableCaption.Children = RenderBlockChildrenFactory();
function TableCell(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("td", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(TableCell.Children, { block: props.block }) }));
}
TableCell.Children = RenderBlockChildrenFactory();
function TableFooter(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("tfoot", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(TableFooter.Children, { block: props.block }) }));
}
TableFooter.Children = RenderBlockChildrenFactory();
function TableHeader(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("thead", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(TableHeader.Children, { block: props.block }) }));
}
TableHeader.Children = RenderBlockChildrenFactory();
function TableHeaderCell(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("th", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(TableHeaderCell.Children, { block: props.block }) }));
}
TableHeaderCell.Children = RenderBlockChildrenFactory();
function TableRow(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("tr", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(TableRow.Children, { block: props.block }) }));
}
TableRow.Children = RenderBlockChildrenFactory();
function Decorators(props) {
const decorators = useDecorators();
const remainingDecorators = !!props.decorators ? [...props.decorators] : void 0;
const firstDecorator = !!remainingDecorators ? remainingDecorators.shift() : void 0;
const DecoratorComponent = !!firstDecorator ? decorators[firstDecorator] : void 0;
const render = () => {
if (!!DecoratorComponent) {
return /* @__PURE__ */ import_react.default.createElement(DecoratorComponent, { block: props.block, decorator: firstDecorator, otherDecorators: remainingDecorators });
} else if (firstDecorator) {
return /* @__PURE__ */ import_react.default.createElement(Decorators, { block: props.block, decorators: remainingDecorators });
} else {
return /* @__PURE__ */ import_react.default.createElement(Fragment.Children, { block: props.block });
}
};
return render();
}
function DecoratorChildren(props) {
return /* @__PURE__ */ import_react.default.createElement(Decorators, { block: props.block, decorators: props.otherDecorators });
}
function InlineCode(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("code", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(InlineCode.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
InlineCode.Children = DecoratorChildren;
function Delete(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("del", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Delete.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Delete.Children = DecoratorChildren;
function Emphasis(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("em", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Emphasis.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Emphasis.Children = DecoratorChildren;
function Insert(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("ins", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Insert.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Insert.Children = DecoratorChildren;
function Keyboard(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("kbd", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Keyboard.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Keyboard.Children = DecoratorChildren;
function LineBreak(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("br", __spreadValues({}, attributes));
}
LineBreak.Children = function(props) {
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
};
function Mark(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("mark", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Mark.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Mark.Children = DecoratorChildren;
function Strong(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("strong", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Strong.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Strong.Children = DecoratorChildren;
function Strikethrough(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("s", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Strikethrough.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Strikethrough.Children = DecoratorChildren;
function Subscript(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("sub", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Subscript.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Subscript.Children = DecoratorChildren;
function Superscript(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("sup", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Superscript.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Superscript.Children = DecoratorChildren;
function Underline(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("u", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Underline.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Underline.Children = DecoratorChildren;
function Variable(props) {
const attributes = getAttributes(props);
return /* @__PURE__ */ import_react.default.createElement("var", __spreadValues({}, attributes), /* @__PURE__ */ import_react.default.createElement(RenderContents, { contents: props.children, fallback: /* @__PURE__ */ import_react.default.createElement(Variable.Children, { block: props.block, decorator: props.decorator, otherDecorators: props.otherDecorators }) }));
}
Variable.Children = DecoratorChildren;
var BLOCK_RENDERERS = {
"_anchor": Anchor,
"_code": CodeWithCaption,
"_component": Component,
"_divider": Divider,
"_formContentType": FormContentType,
"_fragment": Fragment,
"_heading": Heading,
"_image": ImageWithCaption,
"_inlineEntry": InlineEntry,
"_link": Link,
"_liquid": Liquid,
"_list": List,
"_listItem": ListItem,
"_panel": Panel,
"_paragraph": Paragraph,
"_quote": Quote,
"_table": Table,
"_tableBody": TableBody,
"_tableCaption": TableCaption,
"_tableCell": TableCell,
"_tableFooter": TableFooter,
"_tableHeader": TableHeader,
"_tableHeaderCell": TableHeaderCell,
"_tableRow": TableRow
};
var DECORATOR_RENDERERS = {
"code": InlineCode,
"delete": Delete,
"emphasis": Emphasis,
"insert": Insert,
"keyboard": Keyboard,
"linebreak": LineBreak,
"mark": Mark,
"strikethrough": Strikethrough,
"strong": Strong,
"subscript": Subscript,
"superscript": Superscript,
"underline": Underline,
"variable": Variable
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Anchor,
Code,
Component,
Delete,
Divider,
Emphasis,
FormContentType,
Fragment,
Heading,
Image,
InlineCode,
InlineEntry,
Insert,
Keyboard,
LineBreak,
Link,
Liquid,
List,
ListItem,
Mark,
Panel,
Paragraph,
Quote,
RenderChildren,
RenderContextProvider,
Renderer,
RendererContext,
Strikethrough,
Strong,
Subscript,
Superscript,
Table,
TableBody,
TableCaption,
TableCell,
TableFooter,
TableHeader,
TableHeaderCell,
TableRow,
Underline,
Variable
});
//# sourceMappingURL=canvas-react.js.map