@uniformdev/richtext 19.35.2 → 19.36.0
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/index.d.mts +158 -0
- package/package.json +3 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { LinkParamValue, RichTextParamValue, RichTextBuiltInElement, RichTextBuiltInFormat } from '@uniformdev/canvas';
|
|
2
|
+
|
|
3
|
+
declare function purifyText(text: string): string;
|
|
4
|
+
declare function isPureTextAlign(format?: string): format is string;
|
|
5
|
+
declare function isPureDirection(direction?: string | null): direction is string;
|
|
6
|
+
declare function renderHtmlElement(tag: string, attributes: Map<string, string> | null, children?: string): string;
|
|
7
|
+
|
|
8
|
+
interface RichTextNode extends Record<string, unknown> {
|
|
9
|
+
type: string;
|
|
10
|
+
children?: RichTextNode[];
|
|
11
|
+
version: number;
|
|
12
|
+
}
|
|
13
|
+
type RichTextNodeWithChildren = RichTextNode & {
|
|
14
|
+
children: RichTextNode[];
|
|
15
|
+
};
|
|
16
|
+
type ResolveStringRenderer = (context: StringRenderContext) => NodeStringRenderer | null | undefined;
|
|
17
|
+
interface StringRenderContext {
|
|
18
|
+
currentNode: RichTextNode;
|
|
19
|
+
ancestorNodes: RichTextNode[];
|
|
20
|
+
resolveRenderer?: ResolveStringRenderer;
|
|
21
|
+
}
|
|
22
|
+
interface NodeStringRendererProps {
|
|
23
|
+
context: StringRenderContext;
|
|
24
|
+
renderChildren(children?: RichTextNode[] | unknown): string;
|
|
25
|
+
}
|
|
26
|
+
type NodeStringRenderer = (props: NodeStringRendererProps) => string;
|
|
27
|
+
type ParameterRichTextValue = {
|
|
28
|
+
root: RichTextNode;
|
|
29
|
+
} | undefined;
|
|
30
|
+
|
|
31
|
+
interface HeadingNode extends RichTextNode {
|
|
32
|
+
tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
33
|
+
}
|
|
34
|
+
declare const headingHtmlRenderer: NodeStringRenderer;
|
|
35
|
+
|
|
36
|
+
interface LinkNode extends RichTextNode {
|
|
37
|
+
link: NonNullable<LinkParamValue>;
|
|
38
|
+
}
|
|
39
|
+
declare const linkHtmlRenderer: NodeStringRenderer;
|
|
40
|
+
declare function linkParamValueToHref(link: LinkParamValue): string | undefined;
|
|
41
|
+
|
|
42
|
+
interface ListNode extends RichTextNode {
|
|
43
|
+
tag: 'ul' | 'ol';
|
|
44
|
+
start: number;
|
|
45
|
+
}
|
|
46
|
+
declare const listHtmlRenderer: NodeStringRenderer;
|
|
47
|
+
|
|
48
|
+
interface ListItemNode extends RichTextNode {
|
|
49
|
+
value: number;
|
|
50
|
+
}
|
|
51
|
+
declare const listitemHtmlRenderer: NodeStringRenderer;
|
|
52
|
+
|
|
53
|
+
interface ParagraphNode extends RichTextNode {
|
|
54
|
+
format?: 'center' | 'end' | 'justify' | 'left' | 'match-parent' | 'right' | 'start';
|
|
55
|
+
direction?: 'ltr' | 'rtl' | null;
|
|
56
|
+
}
|
|
57
|
+
declare const paragraphHtmlRenderer: NodeStringRenderer;
|
|
58
|
+
|
|
59
|
+
declare const rootHtmlRenderer: NodeStringRenderer;
|
|
60
|
+
|
|
61
|
+
interface TextNode extends RichTextNode {
|
|
62
|
+
/**
|
|
63
|
+
* The format is a bitflag value
|
|
64
|
+
* flags:
|
|
65
|
+
* position 1: bold
|
|
66
|
+
* position 2: italic
|
|
67
|
+
* position 3: strikethrough
|
|
68
|
+
* position 4: underline
|
|
69
|
+
* position 5: code
|
|
70
|
+
* position 6: subscript
|
|
71
|
+
* position 7: superscript
|
|
72
|
+
*/
|
|
73
|
+
format: number;
|
|
74
|
+
text: string;
|
|
75
|
+
}
|
|
76
|
+
declare const textHtmlRenderer: NodeStringRenderer;
|
|
77
|
+
/**
|
|
78
|
+
* Convert format bitflag for holding text formats
|
|
79
|
+
* into relevant tags
|
|
80
|
+
*/
|
|
81
|
+
declare function getRichTextTagsFromTextFormat(format: number): string[];
|
|
82
|
+
|
|
83
|
+
declare function isArrayWithLength<T>(arr: T[] | unknown | undefined): arr is T[];
|
|
84
|
+
declare function isRichTextNode(node: unknown): node is RichTextNode;
|
|
85
|
+
declare function isRichTextValue(value: unknown): value is NonNullable<RichTextParamValue>;
|
|
86
|
+
declare function isRichTextNodeType(node: unknown, type: 'heading'): node is HeadingNode;
|
|
87
|
+
declare function isRichTextNodeType(node: unknown, type: 'paragraph'): node is ParagraphNode;
|
|
88
|
+
declare function isRichTextNodeType(node: unknown, type: 'text'): node is TextNode;
|
|
89
|
+
declare function isRichTextNodeType(node: unknown, type: 'list'): node is ListNode;
|
|
90
|
+
declare function isRichTextNodeType(node: unknown, type: 'listitem'): node is ListItemNode;
|
|
91
|
+
declare function isRichTextNodeType(node: unknown, type: 'link'): node is LinkNode;
|
|
92
|
+
declare function isRichTextNodeType(node: unknown, type: string): node is RichTextNode;
|
|
93
|
+
declare function isRichTextValueConsideredEmpty(value: RichTextParamValue): boolean;
|
|
94
|
+
declare function hasChildren<TRichTextNode extends RichTextNode>(node: TRichTextNode): node is TRichTextNode & {
|
|
95
|
+
children: RichTextNode[];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* When a custom renderer has not been provided we
|
|
100
|
+
* check to see if there is a renderer for the type
|
|
101
|
+
* within the map above. These are for any node types
|
|
102
|
+
* which include extra logic.
|
|
103
|
+
*
|
|
104
|
+
* Some node types like quote just map directly to a
|
|
105
|
+
* HTML tag (ie blockquote). For those there is a simple
|
|
106
|
+
* type -> tag Map.
|
|
107
|
+
*/
|
|
108
|
+
declare const resolveDefaultRenderer$1: ResolveStringRenderer;
|
|
109
|
+
/**
|
|
110
|
+
* Render a node and its children to HTML
|
|
111
|
+
*
|
|
112
|
+
* This could be the root node or a nested node
|
|
113
|
+
*/
|
|
114
|
+
declare function renderToHtml(node: RichTextNode | null | undefined, parentContext?: Partial<StringRenderContext>): string;
|
|
115
|
+
/**
|
|
116
|
+
* Render an array of RichTextNodes to a string based
|
|
117
|
+
* on a particular context.
|
|
118
|
+
*
|
|
119
|
+
* This will often be called from within a NodeRenderer
|
|
120
|
+
* using the `renderChildren` prop.
|
|
121
|
+
*/
|
|
122
|
+
declare function renderChildrenToHtml(children: RichTextNode[] | undefined, context: StringRenderContext): string;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* When a custom renderer has not been provided we
|
|
126
|
+
* check to see if there is a renderer for the type
|
|
127
|
+
* within the map above. These are for any node types
|
|
128
|
+
* which include extra logic.
|
|
129
|
+
*/
|
|
130
|
+
declare const resolveDefaultRenderer: ResolveStringRenderer;
|
|
131
|
+
/**
|
|
132
|
+
* Render a node and its children to text
|
|
133
|
+
*
|
|
134
|
+
* This could be the root node or a nested node
|
|
135
|
+
*/
|
|
136
|
+
declare function renderToText(node: RichTextNode | null | undefined, parentContext?: Partial<StringRenderContext>): string;
|
|
137
|
+
/**
|
|
138
|
+
* Render an array of RichTextNodes to a string based
|
|
139
|
+
* on a particular context.
|
|
140
|
+
*
|
|
141
|
+
* This will often be called from within a NodeRenderer
|
|
142
|
+
* using the `renderChildren` prop.
|
|
143
|
+
*/
|
|
144
|
+
declare function renderChildrenToText(children: RichTextNode[] | undefined, context: StringRenderContext): string;
|
|
145
|
+
|
|
146
|
+
declare const walkRichTextTree: (node: RichTextNode, callback: (node: RichTextNode, parent: RichTextNode | undefined) => void, parent?: RichTextNode) => void;
|
|
147
|
+
declare const richTextBuiltInElements: {
|
|
148
|
+
label: string;
|
|
149
|
+
type: RichTextBuiltInElement;
|
|
150
|
+
}[];
|
|
151
|
+
declare const richTextBuiltInFormats: {
|
|
152
|
+
label: string;
|
|
153
|
+
type: RichTextBuiltInFormat;
|
|
154
|
+
}[];
|
|
155
|
+
declare const getLabelForElement: (type: string) => string;
|
|
156
|
+
declare const getLabelForFormat: (type: string) => string;
|
|
157
|
+
|
|
158
|
+
export { HeadingNode, LinkNode, ListItemNode, ListNode, NodeStringRenderer, NodeStringRendererProps, ParagraphNode, ParameterRichTextValue, ResolveStringRenderer, RichTextNode, RichTextNodeWithChildren, StringRenderContext, TextNode, getLabelForElement, getLabelForFormat, getRichTextTagsFromTextFormat, hasChildren, headingHtmlRenderer, isArrayWithLength, isPureDirection, isPureTextAlign, isRichTextNode, isRichTextNodeType, isRichTextValue, isRichTextValueConsideredEmpty, linkHtmlRenderer, linkParamValueToHref, listHtmlRenderer, listitemHtmlRenderer, paragraphHtmlRenderer, purifyText, renderChildrenToHtml, renderChildrenToText, renderHtmlElement, renderToHtml, renderToText, resolveDefaultRenderer$1 as resolveDefaultHtmlRenderer, resolveDefaultRenderer as resolveDefaultTextRenderer, richTextBuiltInElements, richTextBuiltInFormats, rootHtmlRenderer, textHtmlRenderer, walkRichTextTree };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/richtext",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.36.0",
|
|
4
4
|
"description": "Common functionality and types for Uniform Rich Text parameters",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@lexical/link": "^0.11.1",
|
|
46
46
|
"@lexical/list": "^0.11.1",
|
|
47
47
|
"@lexical/rich-text": "^0.11.1",
|
|
48
|
-
"@uniformdev/canvas": "^19.
|
|
48
|
+
"@uniformdev/canvas": "^19.36.0",
|
|
49
49
|
"lexical": "^0.11.1"
|
|
50
50
|
},
|
|
51
51
|
"files": [
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "3ae246a7f0f39adeaf04ecba4c7e48c478c019ad"
|
|
58
58
|
}
|