@uniformdev/richtext
Advanced tools
Comparing version 19.14.1-alpha.11 to 19.14.1-alpha.12
@@ -38,5 +38,8 @@ "use strict"; | ||
renderChildrenToHtml: () => renderChildrenToHtml, | ||
renderChildrenToText: () => renderChildrenToText, | ||
renderHtmlElement: () => renderHtmlElement, | ||
renderToHtml: () => renderToHtml, | ||
resolveDefaultRenderer: () => resolveDefaultRenderer, | ||
renderToText: () => renderToText, | ||
resolveDefaultHtmlRenderer: () => resolveDefaultRenderer, | ||
resolveDefaultTextRenderer: () => resolveDefaultRenderer2, | ||
rootHtmlRenderer: () => rootHtmlRenderer, | ||
@@ -102,2 +105,5 @@ textHtmlRenderer: () => textHtmlRenderer, | ||
}; | ||
var headingTextRenderer = ({ context, renderChildren }) => { | ||
return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : ""; | ||
}; | ||
@@ -147,2 +153,12 @@ // src/nodes/link.ts | ||
}; | ||
var listitemTextRenderer = ({ context, renderChildren }) => { | ||
if (!hasChildren(context.currentNode)) { | ||
return ""; | ||
} | ||
const childrenRendered = renderChildren(context.currentNode.children); | ||
if (childrenRendered.endsWith(" ")) { | ||
return childrenRendered; | ||
} | ||
return `${childrenRendered} `; | ||
}; | ||
@@ -165,2 +181,5 @@ // src/nodes/paragraph.ts | ||
}; | ||
var paragraphTextRenderer = ({ context, renderChildren }) => { | ||
return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : ""; | ||
}; | ||
@@ -181,2 +200,6 @@ // src/nodes/root.ts | ||
}; | ||
var textTextRenderer = ({ context }) => { | ||
const node = context.currentNode; | ||
return node.text; | ||
}; | ||
function getRichTextTagsFromTextFormat(format) { | ||
@@ -212,2 +235,5 @@ const tags = []; | ||
}; | ||
var tabTextRenderer = () => { | ||
return " "; | ||
}; | ||
@@ -276,2 +302,62 @@ // src/renderToHtml.ts | ||
// src/nodes/linebreak.ts | ||
var linebreakTextRenderer = () => { | ||
return " "; | ||
}; | ||
// src/renderToText.ts | ||
var rendererTypeMap2 = /* @__PURE__ */ new Map([ | ||
["text", textTextRenderer], | ||
["tab", tabTextRenderer], | ||
["linebreak", linebreakTextRenderer], | ||
["paragraph", paragraphTextRenderer], | ||
["listitem", listitemTextRenderer], | ||
["heading", headingTextRenderer] | ||
]); | ||
var resolveDefaultRenderer2 = (context) => { | ||
const renderer = rendererTypeMap2.get(context.currentNode.type); | ||
if (renderer) { | ||
return renderer; | ||
} | ||
return ({ context: context2, renderChildren }) => { | ||
return hasChildren(context2.currentNode) ? renderChildren(context2.currentNode.children) : ""; | ||
}; | ||
}; | ||
function initializeRenderContext2(node, parentContext) { | ||
let ancestorNodes = []; | ||
if (parentContext == null ? void 0 : parentContext.ancestorNodes) { | ||
ancestorNodes = ancestorNodes.concat(parentContext.ancestorNodes); | ||
} | ||
if (parentContext == null ? void 0 : parentContext.currentNode) { | ||
ancestorNodes.unshift(parentContext.currentNode); | ||
} | ||
return { | ||
...parentContext != null ? parentContext : {}, | ||
currentNode: node, | ||
ancestorNodes | ||
}; | ||
} | ||
function renderToText(node, parentContext) { | ||
var _a; | ||
if (!isRichTextNode(node)) | ||
return ""; | ||
const context = initializeRenderContext2(node, parentContext); | ||
let renderer = (_a = context.resolveRenderer) == null ? void 0 : _a.call(context, context); | ||
if (typeof renderer === "undefined") { | ||
renderer = resolveDefaultRenderer2(context); | ||
} else if (renderer === null) { | ||
return ""; | ||
} | ||
const renderChildren = (children) => renderChildrenToText(children, context); | ||
if (renderer) { | ||
const rendered = renderer({ context, renderChildren }); | ||
return context.ancestorNodes.length > 0 ? rendered : rendered.trim(); | ||
} else { | ||
throw new Error(`There is no renderer for node type: ${context.currentNode.type}`); | ||
} | ||
} | ||
function renderChildrenToText(children, context) { | ||
return Array.isArray(children) ? children.map((node) => renderToText(node, context)).join("") : ""; | ||
} | ||
// src/utils.ts | ||
@@ -305,5 +391,8 @@ var walkRichTextTree = (node, callback, parent) => { | ||
renderChildrenToHtml, | ||
renderChildrenToText, | ||
renderHtmlElement, | ||
renderToHtml, | ||
resolveDefaultRenderer, | ||
renderToText, | ||
resolveDefaultHtmlRenderer, | ||
resolveDefaultTextRenderer, | ||
rootHtmlRenderer, | ||
@@ -310,0 +399,0 @@ textHtmlRenderer, |
@@ -105,5 +105,5 @@ import { LinkParamValue } from '@uniformdev/canvas'; | ||
*/ | ||
declare const resolveDefaultRenderer: ResolveStringRenderer; | ||
declare const resolveDefaultRenderer$1: ResolveStringRenderer; | ||
/** | ||
* Render a node and it's children to HTML | ||
* Render a node and its children to HTML | ||
* | ||
@@ -122,4 +122,26 @@ * This could be the root node or a nested node | ||
/** | ||
* When a custom renderer has not been provided we | ||
* check to see if there is a renderer for the type | ||
* within the map above. These are for any node types | ||
* which include extra logic. | ||
*/ | ||
declare const resolveDefaultRenderer: ResolveStringRenderer; | ||
/** | ||
* Render a node and its children to text | ||
* | ||
* This could be the root node or a nested node | ||
*/ | ||
declare function renderToText(node: RichTextNode | null | undefined, parentContext?: Partial<StringRenderContext>): string; | ||
/** | ||
* Render an array of RichTextNodes to a string based | ||
* on a particular context. | ||
* | ||
* This will often be called from within a NodeRenderer | ||
* using the `renderChildren` prop. | ||
*/ | ||
declare function renderChildrenToText(children: RichTextNode[] | undefined, context: StringRenderContext): string; | ||
declare const walkRichTextTree: (node: RichTextNode, callback: (node: RichTextNode, parent: RichTextNode | undefined) => void, parent?: RichTextNode) => void; | ||
export { HeadingNode, LinkNode, ListItemNode, ListNode, NodeStringRenderer, NodeStringRendererProps, ParagraphNode, ParameterRichTextValue, ResolveStringRenderer, RichTextNode, RichTextNodeWithChildren, StringRenderContext, TextNode, getRichTextTagsFromTextFormat, hasChildren, headingHtmlRenderer, isArrayWithLength, isPureDirection, isPureTextAlign, isRichTextNode, isRichTextNodeType, linkHtmlRenderer, linkParamValueToHref, listHtmlRenderer, listitemHtmlRenderer, paragraphHtmlRenderer, purifyText, renderChildrenToHtml, renderHtmlElement, renderToHtml, resolveDefaultRenderer, rootHtmlRenderer, textHtmlRenderer, walkRichTextTree }; | ||
export { HeadingNode, LinkNode, ListItemNode, ListNode, NodeStringRenderer, NodeStringRendererProps, ParagraphNode, ParameterRichTextValue, ResolveStringRenderer, RichTextNode, RichTextNodeWithChildren, StringRenderContext, TextNode, getRichTextTagsFromTextFormat, hasChildren, headingHtmlRenderer, isArrayWithLength, isPureDirection, isPureTextAlign, isRichTextNode, isRichTextNodeType, linkHtmlRenderer, linkParamValueToHref, listHtmlRenderer, listitemHtmlRenderer, paragraphHtmlRenderer, purifyText, renderChildrenToHtml, renderChildrenToText, renderHtmlElement, renderToHtml, renderToText, resolveDefaultRenderer$1 as resolveDefaultHtmlRenderer, resolveDefaultRenderer as resolveDefaultTextRenderer, rootHtmlRenderer, textHtmlRenderer, walkRichTextTree }; |
@@ -55,2 +55,5 @@ // src/elements.ts | ||
}; | ||
var headingTextRenderer = ({ context, renderChildren }) => { | ||
return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : ""; | ||
}; | ||
@@ -100,2 +103,12 @@ // src/nodes/link.ts | ||
}; | ||
var listitemTextRenderer = ({ context, renderChildren }) => { | ||
if (!hasChildren(context.currentNode)) { | ||
return ""; | ||
} | ||
const childrenRendered = renderChildren(context.currentNode.children); | ||
if (childrenRendered.endsWith(" ")) { | ||
return childrenRendered; | ||
} | ||
return `${childrenRendered} `; | ||
}; | ||
@@ -118,2 +131,5 @@ // src/nodes/paragraph.ts | ||
}; | ||
var paragraphTextRenderer = ({ context, renderChildren }) => { | ||
return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : ""; | ||
}; | ||
@@ -134,2 +150,6 @@ // src/nodes/root.ts | ||
}; | ||
var textTextRenderer = ({ context }) => { | ||
const node = context.currentNode; | ||
return node.text; | ||
}; | ||
function getRichTextTagsFromTextFormat(format) { | ||
@@ -165,2 +185,5 @@ const tags = []; | ||
}; | ||
var tabTextRenderer = () => { | ||
return " "; | ||
}; | ||
@@ -229,2 +252,62 @@ // src/renderToHtml.ts | ||
// src/nodes/linebreak.ts | ||
var linebreakTextRenderer = () => { | ||
return " "; | ||
}; | ||
// src/renderToText.ts | ||
var rendererTypeMap2 = /* @__PURE__ */ new Map([ | ||
["text", textTextRenderer], | ||
["tab", tabTextRenderer], | ||
["linebreak", linebreakTextRenderer], | ||
["paragraph", paragraphTextRenderer], | ||
["listitem", listitemTextRenderer], | ||
["heading", headingTextRenderer] | ||
]); | ||
var resolveDefaultRenderer2 = (context) => { | ||
const renderer = rendererTypeMap2.get(context.currentNode.type); | ||
if (renderer) { | ||
return renderer; | ||
} | ||
return ({ context: context2, renderChildren }) => { | ||
return hasChildren(context2.currentNode) ? renderChildren(context2.currentNode.children) : ""; | ||
}; | ||
}; | ||
function initializeRenderContext2(node, parentContext) { | ||
let ancestorNodes = []; | ||
if (parentContext == null ? void 0 : parentContext.ancestorNodes) { | ||
ancestorNodes = ancestorNodes.concat(parentContext.ancestorNodes); | ||
} | ||
if (parentContext == null ? void 0 : parentContext.currentNode) { | ||
ancestorNodes.unshift(parentContext.currentNode); | ||
} | ||
return { | ||
...parentContext != null ? parentContext : {}, | ||
currentNode: node, | ||
ancestorNodes | ||
}; | ||
} | ||
function renderToText(node, parentContext) { | ||
var _a; | ||
if (!isRichTextNode(node)) | ||
return ""; | ||
const context = initializeRenderContext2(node, parentContext); | ||
let renderer = (_a = context.resolveRenderer) == null ? void 0 : _a.call(context, context); | ||
if (typeof renderer === "undefined") { | ||
renderer = resolveDefaultRenderer2(context); | ||
} else if (renderer === null) { | ||
return ""; | ||
} | ||
const renderChildren = (children) => renderChildrenToText(children, context); | ||
if (renderer) { | ||
const rendered = renderer({ context, renderChildren }); | ||
return context.ancestorNodes.length > 0 ? rendered : rendered.trim(); | ||
} else { | ||
throw new Error(`There is no renderer for node type: ${context.currentNode.type}`); | ||
} | ||
} | ||
function renderChildrenToText(children, context) { | ||
return Array.isArray(children) ? children.map((node) => renderToText(node, context)).join("") : ""; | ||
} | ||
// src/utils.ts | ||
@@ -257,5 +340,8 @@ var walkRichTextTree = (node, callback, parent) => { | ||
renderChildrenToHtml, | ||
renderChildrenToText, | ||
renderHtmlElement, | ||
renderToHtml, | ||
resolveDefaultRenderer, | ||
renderToText, | ||
resolveDefaultRenderer as resolveDefaultHtmlRenderer, | ||
resolveDefaultRenderer2 as resolveDefaultTextRenderer, | ||
rootHtmlRenderer, | ||
@@ -262,0 +348,0 @@ textHtmlRenderer, |
@@ -38,5 +38,8 @@ "use strict"; | ||
renderChildrenToHtml: () => renderChildrenToHtml, | ||
renderChildrenToText: () => renderChildrenToText, | ||
renderHtmlElement: () => renderHtmlElement, | ||
renderToHtml: () => renderToHtml, | ||
resolveDefaultRenderer: () => resolveDefaultRenderer, | ||
renderToText: () => renderToText, | ||
resolveDefaultHtmlRenderer: () => resolveDefaultRenderer, | ||
resolveDefaultTextRenderer: () => resolveDefaultRenderer2, | ||
rootHtmlRenderer: () => rootHtmlRenderer, | ||
@@ -102,2 +105,5 @@ textHtmlRenderer: () => textHtmlRenderer, | ||
}; | ||
var headingTextRenderer = ({ context, renderChildren }) => { | ||
return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : ""; | ||
}; | ||
@@ -147,2 +153,12 @@ // src/nodes/link.ts | ||
}; | ||
var listitemTextRenderer = ({ context, renderChildren }) => { | ||
if (!hasChildren(context.currentNode)) { | ||
return ""; | ||
} | ||
const childrenRendered = renderChildren(context.currentNode.children); | ||
if (childrenRendered.endsWith(" ")) { | ||
return childrenRendered; | ||
} | ||
return `${childrenRendered} `; | ||
}; | ||
@@ -165,2 +181,5 @@ // src/nodes/paragraph.ts | ||
}; | ||
var paragraphTextRenderer = ({ context, renderChildren }) => { | ||
return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : ""; | ||
}; | ||
@@ -181,2 +200,6 @@ // src/nodes/root.ts | ||
}; | ||
var textTextRenderer = ({ context }) => { | ||
const node = context.currentNode; | ||
return node.text; | ||
}; | ||
function getRichTextTagsFromTextFormat(format) { | ||
@@ -212,2 +235,5 @@ const tags = []; | ||
}; | ||
var tabTextRenderer = () => { | ||
return " "; | ||
}; | ||
@@ -276,2 +302,62 @@ // src/renderToHtml.ts | ||
// src/nodes/linebreak.ts | ||
var linebreakTextRenderer = () => { | ||
return " "; | ||
}; | ||
// src/renderToText.ts | ||
var rendererTypeMap2 = /* @__PURE__ */ new Map([ | ||
["text", textTextRenderer], | ||
["tab", tabTextRenderer], | ||
["linebreak", linebreakTextRenderer], | ||
["paragraph", paragraphTextRenderer], | ||
["listitem", listitemTextRenderer], | ||
["heading", headingTextRenderer] | ||
]); | ||
var resolveDefaultRenderer2 = (context) => { | ||
const renderer = rendererTypeMap2.get(context.currentNode.type); | ||
if (renderer) { | ||
return renderer; | ||
} | ||
return ({ context: context2, renderChildren }) => { | ||
return hasChildren(context2.currentNode) ? renderChildren(context2.currentNode.children) : ""; | ||
}; | ||
}; | ||
function initializeRenderContext2(node, parentContext) { | ||
let ancestorNodes = []; | ||
if (parentContext == null ? void 0 : parentContext.ancestorNodes) { | ||
ancestorNodes = ancestorNodes.concat(parentContext.ancestorNodes); | ||
} | ||
if (parentContext == null ? void 0 : parentContext.currentNode) { | ||
ancestorNodes.unshift(parentContext.currentNode); | ||
} | ||
return { | ||
...parentContext != null ? parentContext : {}, | ||
currentNode: node, | ||
ancestorNodes | ||
}; | ||
} | ||
function renderToText(node, parentContext) { | ||
var _a; | ||
if (!isRichTextNode(node)) | ||
return ""; | ||
const context = initializeRenderContext2(node, parentContext); | ||
let renderer = (_a = context.resolveRenderer) == null ? void 0 : _a.call(context, context); | ||
if (typeof renderer === "undefined") { | ||
renderer = resolveDefaultRenderer2(context); | ||
} else if (renderer === null) { | ||
return ""; | ||
} | ||
const renderChildren = (children) => renderChildrenToText(children, context); | ||
if (renderer) { | ||
const rendered = renderer({ context, renderChildren }); | ||
return context.ancestorNodes.length > 0 ? rendered : rendered.trim(); | ||
} else { | ||
throw new Error(`There is no renderer for node type: ${context.currentNode.type}`); | ||
} | ||
} | ||
function renderChildrenToText(children, context) { | ||
return Array.isArray(children) ? children.map((node) => renderToText(node, context)).join("") : ""; | ||
} | ||
// src/utils.ts | ||
@@ -305,5 +391,8 @@ var walkRichTextTree = (node, callback, parent) => { | ||
renderChildrenToHtml, | ||
renderChildrenToText, | ||
renderHtmlElement, | ||
renderToHtml, | ||
resolveDefaultRenderer, | ||
renderToText, | ||
resolveDefaultHtmlRenderer, | ||
resolveDefaultTextRenderer, | ||
rootHtmlRenderer, | ||
@@ -310,0 +399,0 @@ textHtmlRenderer, |
{ | ||
"name": "@uniformdev/richtext", | ||
"version": "19.14.1-alpha.11+89dabee14", | ||
"version": "19.14.1-alpha.12+55ed85e4b", | ||
"description": "Common functionality and types for Uniform Rich Text parameters", | ||
@@ -48,3 +48,3 @@ "license": "SEE LICENSE IN LICENSE.txt", | ||
"@lexical/rich-text": "^0.11.0", | ||
"@uniformdev/canvas": "^19.14.1-alpha.11+89dabee14", | ||
"@uniformdev/canvas": "^19.14.1-alpha.12+55ed85e4b", | ||
"lexical": "^0.11.0" | ||
@@ -58,3 +58,3 @@ }, | ||
}, | ||
"gitHead": "89dabee148728ef7f329e18b7194766a9e6b9631" | ||
"gitHead": "55ed85e4b8eb70027597dca9996d1c87985554d3" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
53839
1549