Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uniformdev/richtext

Package Overview
Dependencies
Maintainers
10
Versions
429
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uniformdev/richtext - npm Package Compare versions

Comparing version 19.14.1-alpha.1 to 19.14.1

93

./dist/index.js

@@ -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,

6

package.json
{
"name": "@uniformdev/richtext",
"version": "19.14.1-alpha.1+597b21eaa",
"version": "19.14.1",
"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.1+597b21eaa",
"@uniformdev/canvas": "^19.14.1",
"lexical": "^0.11.0"

@@ -58,3 +58,3 @@ },

},
"gitHead": "597b21eaa0a61271b8951de1d443019868f7699c"
"gitHead": "edd5e3bb74b148c5b947109a794a3bab42384cb7"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc