@uniformdev/richtext 19.135.1-alpha.10 → 19.135.1-alpha.11

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 CHANGED
@@ -1,4 +1,4 @@
1
- import { LinkParamValue, RichTextParamValue, RichTextBuiltInElement, RichTextBuiltInFormat } from '@uniformdev/canvas';
1
+ import { SerializedEditorState, SerializedParagraphNode } from 'lexical';
2
2
 
3
3
  declare function purifyText(text: string): string;
4
4
  declare function isPureTextAlign(format?: string): format is string;
@@ -24,9 +24,9 @@ interface NodeStringRendererProps {
24
24
  renderChildren(children?: RichTextNode[] | unknown): string;
25
25
  }
26
26
  type NodeStringRenderer = (props: NodeStringRendererProps) => string;
27
- type ParameterRichTextValue = {
28
- root: RichTextNode;
29
- } | undefined;
27
+ type ParameterRichTextValue = SerializedEditorState | undefined | null;
28
+ type RichTextBuiltInFormat = 'code' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'superscript' | 'subscript';
29
+ type RichTextBuiltInElement = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'unorderedList' | 'orderedList' | 'link' | 'quote' | 'code' | 'variable' | 'table';
30
30
 
31
31
  interface HeadingNode extends RichTextNode {
32
32
  tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
@@ -37,6 +37,19 @@ interface LinkNode extends RichTextNode {
37
37
  link: NonNullable<LinkParamValue>;
38
38
  }
39
39
  declare const linkHtmlRenderer: NodeStringRenderer;
40
+ type LinkParameterType = 'projectMapNode' | 'url' | 'tel' | 'email';
41
+ type ProjectMapLinkParamValue = {
42
+ type: 'projectMapNode';
43
+ projectMapId: string;
44
+ nodeId: string;
45
+ path: string;
46
+ dynamicInputValues?: Record<string, string>;
47
+ };
48
+ type NonProjectMapLinkParamValue = {
49
+ type: Exclude<LinkParameterType, 'projectMapNode'>;
50
+ path: string;
51
+ };
52
+ type LinkParamValue = ProjectMapLinkParamValue | NonProjectMapLinkParamValue | undefined;
40
53
  declare function linkParamValueToHref(link: LinkParamValue): string | undefined;
41
54
 
42
55
  interface ListNode extends RichTextNode {
@@ -58,6 +71,30 @@ declare const paragraphHtmlRenderer: NodeStringRenderer;
58
71
 
59
72
  declare const rootHtmlRenderer: NodeStringRenderer;
60
73
 
74
+ interface TableNode extends RichTextNode {
75
+ }
76
+ declare const tableHtmlRenderer: NodeStringRenderer;
77
+
78
+ interface TableCellNode extends RichTextNode {
79
+ /**
80
+ * headerState:
81
+ * 0: no header
82
+ * 1: row header
83
+ * 2: column header
84
+ * 3: row and column header
85
+ */
86
+ headerState: number;
87
+ }
88
+ declare const tablecellHtmlRenderer: NodeStringRenderer;
89
+ /**
90
+ * Convert headerState into relevant tag
91
+ */
92
+ declare function getRichTextTagFromTableCellHeaderState(headerState: number): "td" | "th";
93
+
94
+ interface TableRowNode extends RichTextNode {
95
+ }
96
+ declare const tablerowHtmlRenderer: NodeStringRenderer;
97
+
61
98
  interface TextNode extends RichTextNode {
62
99
  /**
63
100
  * The format is a bitflag value
@@ -82,7 +119,7 @@ declare function getRichTextTagsFromTextFormat(format: number): string[];
82
119
 
83
120
  declare function isArrayWithLength<T>(arr: T[] | unknown | undefined): arr is T[];
84
121
  declare function isRichTextNode(node: unknown): node is RichTextNode;
85
- declare function isRichTextValue(value: unknown): value is NonNullable<RichTextParamValue>;
122
+ declare function isRichTextValue(value: unknown): value is NonNullable<ParameterRichTextValue>;
86
123
  declare function isRichTextNodeType(node: unknown, type: 'heading'): node is HeadingNode;
87
124
  declare function isRichTextNodeType(node: unknown, type: 'paragraph'): node is ParagraphNode;
88
125
  declare function isRichTextNodeType(node: unknown, type: 'text'): node is TextNode;
@@ -90,7 +127,7 @@ declare function isRichTextNodeType(node: unknown, type: 'list'): node is ListNo
90
127
  declare function isRichTextNodeType(node: unknown, type: 'listitem'): node is ListItemNode;
91
128
  declare function isRichTextNodeType(node: unknown, type: 'link'): node is LinkNode;
92
129
  declare function isRichTextNodeType(node: unknown, type: string): node is RichTextNode;
93
- declare function isRichTextValueConsideredEmpty(value: RichTextParamValue): boolean;
130
+ declare function isRichTextValueConsideredEmpty(value: ParameterRichTextValue): boolean;
94
131
  declare function hasChildren<TRichTextNode extends RichTextNode>(node: TRichTextNode): node is TRichTextNode & {
95
132
  children: RichTextNode[];
96
133
  };
@@ -144,15 +181,25 @@ declare function renderToText(node: RichTextNode | null | undefined, parentConte
144
181
  declare function renderChildrenToText(children: RichTextNode[] | undefined, context: StringRenderContext): string;
145
182
 
146
183
  declare const walkRichTextTree: (node: RichTextNode, callback: (node: RichTextNode, parent: RichTextNode | undefined) => void, parent?: RichTextNode) => void;
147
- declare const richTextBuiltInElements: {
184
+ declare const richTextBuiltInElements: Array<{
148
185
  label: string;
149
186
  type: RichTextBuiltInElement;
150
- }[];
151
- declare const richTextBuiltInFormats: {
187
+ }>;
188
+ declare const richTextBuiltInFormats: Array<{
152
189
  label: string;
153
190
  type: RichTextBuiltInFormat;
154
- }[];
191
+ }>;
155
192
  declare const getLabelForElement: (type: string) => string;
156
193
  declare const getLabelForFormat: (type: string) => string;
194
+ declare const emptyRichTextValue: {
195
+ root: {
196
+ type: string;
197
+ version: number;
198
+ direction: null;
199
+ format: "";
200
+ indent: number;
201
+ children: SerializedParagraphNode[];
202
+ };
203
+ };
157
204
 
158
- export { type HeadingNode, type LinkNode, type ListItemNode, type ListNode, type NodeStringRenderer, type NodeStringRendererProps, type ParagraphNode, type ParameterRichTextValue, type ResolveStringRenderer, type RichTextNode, type RichTextNodeWithChildren, type StringRenderContext, type 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 };
205
+ export { type HeadingNode, type LinkNode, type ListItemNode, type ListNode, type NodeStringRenderer, type NodeStringRendererProps, type ParagraphNode, type ParameterRichTextValue, type ResolveStringRenderer, type RichTextBuiltInElement, type RichTextBuiltInFormat, type RichTextNode, type RichTextNodeWithChildren, type StringRenderContext, type TableCellNode, type TableNode, type TableRowNode, type TextNode, emptyRichTextValue, getLabelForElement, getLabelForFormat, getRichTextTagFromTableCellHeaderState, 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, tableHtmlRenderer, tablecellHtmlRenderer, tablerowHtmlRenderer, textHtmlRenderer, walkRichTextTree };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LinkParamValue, RichTextParamValue, RichTextBuiltInElement, RichTextBuiltInFormat } from '@uniformdev/canvas';
1
+ import { SerializedEditorState, SerializedParagraphNode } from 'lexical';
2
2
 
3
3
  declare function purifyText(text: string): string;
4
4
  declare function isPureTextAlign(format?: string): format is string;
@@ -24,9 +24,9 @@ interface NodeStringRendererProps {
24
24
  renderChildren(children?: RichTextNode[] | unknown): string;
25
25
  }
26
26
  type NodeStringRenderer = (props: NodeStringRendererProps) => string;
27
- type ParameterRichTextValue = {
28
- root: RichTextNode;
29
- } | undefined;
27
+ type ParameterRichTextValue = SerializedEditorState | undefined | null;
28
+ type RichTextBuiltInFormat = 'code' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'superscript' | 'subscript';
29
+ type RichTextBuiltInElement = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'unorderedList' | 'orderedList' | 'link' | 'quote' | 'code' | 'variable' | 'table';
30
30
 
31
31
  interface HeadingNode extends RichTextNode {
32
32
  tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
@@ -37,6 +37,19 @@ interface LinkNode extends RichTextNode {
37
37
  link: NonNullable<LinkParamValue>;
38
38
  }
39
39
  declare const linkHtmlRenderer: NodeStringRenderer;
40
+ type LinkParameterType = 'projectMapNode' | 'url' | 'tel' | 'email';
41
+ type ProjectMapLinkParamValue = {
42
+ type: 'projectMapNode';
43
+ projectMapId: string;
44
+ nodeId: string;
45
+ path: string;
46
+ dynamicInputValues?: Record<string, string>;
47
+ };
48
+ type NonProjectMapLinkParamValue = {
49
+ type: Exclude<LinkParameterType, 'projectMapNode'>;
50
+ path: string;
51
+ };
52
+ type LinkParamValue = ProjectMapLinkParamValue | NonProjectMapLinkParamValue | undefined;
40
53
  declare function linkParamValueToHref(link: LinkParamValue): string | undefined;
41
54
 
42
55
  interface ListNode extends RichTextNode {
@@ -58,6 +71,30 @@ declare const paragraphHtmlRenderer: NodeStringRenderer;
58
71
 
59
72
  declare const rootHtmlRenderer: NodeStringRenderer;
60
73
 
74
+ interface TableNode extends RichTextNode {
75
+ }
76
+ declare const tableHtmlRenderer: NodeStringRenderer;
77
+
78
+ interface TableCellNode extends RichTextNode {
79
+ /**
80
+ * headerState:
81
+ * 0: no header
82
+ * 1: row header
83
+ * 2: column header
84
+ * 3: row and column header
85
+ */
86
+ headerState: number;
87
+ }
88
+ declare const tablecellHtmlRenderer: NodeStringRenderer;
89
+ /**
90
+ * Convert headerState into relevant tag
91
+ */
92
+ declare function getRichTextTagFromTableCellHeaderState(headerState: number): "td" | "th";
93
+
94
+ interface TableRowNode extends RichTextNode {
95
+ }
96
+ declare const tablerowHtmlRenderer: NodeStringRenderer;
97
+
61
98
  interface TextNode extends RichTextNode {
62
99
  /**
63
100
  * The format is a bitflag value
@@ -82,7 +119,7 @@ declare function getRichTextTagsFromTextFormat(format: number): string[];
82
119
 
83
120
  declare function isArrayWithLength<T>(arr: T[] | unknown | undefined): arr is T[];
84
121
  declare function isRichTextNode(node: unknown): node is RichTextNode;
85
- declare function isRichTextValue(value: unknown): value is NonNullable<RichTextParamValue>;
122
+ declare function isRichTextValue(value: unknown): value is NonNullable<ParameterRichTextValue>;
86
123
  declare function isRichTextNodeType(node: unknown, type: 'heading'): node is HeadingNode;
87
124
  declare function isRichTextNodeType(node: unknown, type: 'paragraph'): node is ParagraphNode;
88
125
  declare function isRichTextNodeType(node: unknown, type: 'text'): node is TextNode;
@@ -90,7 +127,7 @@ declare function isRichTextNodeType(node: unknown, type: 'list'): node is ListNo
90
127
  declare function isRichTextNodeType(node: unknown, type: 'listitem'): node is ListItemNode;
91
128
  declare function isRichTextNodeType(node: unknown, type: 'link'): node is LinkNode;
92
129
  declare function isRichTextNodeType(node: unknown, type: string): node is RichTextNode;
93
- declare function isRichTextValueConsideredEmpty(value: RichTextParamValue): boolean;
130
+ declare function isRichTextValueConsideredEmpty(value: ParameterRichTextValue): boolean;
94
131
  declare function hasChildren<TRichTextNode extends RichTextNode>(node: TRichTextNode): node is TRichTextNode & {
95
132
  children: RichTextNode[];
96
133
  };
@@ -144,15 +181,25 @@ declare function renderToText(node: RichTextNode | null | undefined, parentConte
144
181
  declare function renderChildrenToText(children: RichTextNode[] | undefined, context: StringRenderContext): string;
145
182
 
146
183
  declare const walkRichTextTree: (node: RichTextNode, callback: (node: RichTextNode, parent: RichTextNode | undefined) => void, parent?: RichTextNode) => void;
147
- declare const richTextBuiltInElements: {
184
+ declare const richTextBuiltInElements: Array<{
148
185
  label: string;
149
186
  type: RichTextBuiltInElement;
150
- }[];
151
- declare const richTextBuiltInFormats: {
187
+ }>;
188
+ declare const richTextBuiltInFormats: Array<{
152
189
  label: string;
153
190
  type: RichTextBuiltInFormat;
154
- }[];
191
+ }>;
155
192
  declare const getLabelForElement: (type: string) => string;
156
193
  declare const getLabelForFormat: (type: string) => string;
194
+ declare const emptyRichTextValue: {
195
+ root: {
196
+ type: string;
197
+ version: number;
198
+ direction: null;
199
+ format: "";
200
+ indent: number;
201
+ children: SerializedParagraphNode[];
202
+ };
203
+ };
157
204
 
158
- export { type HeadingNode, type LinkNode, type ListItemNode, type ListNode, type NodeStringRenderer, type NodeStringRendererProps, type ParagraphNode, type ParameterRichTextValue, type ResolveStringRenderer, type RichTextNode, type RichTextNodeWithChildren, type StringRenderContext, type 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 };
205
+ export { type HeadingNode, type LinkNode, type ListItemNode, type ListNode, type NodeStringRenderer, type NodeStringRendererProps, type ParagraphNode, type ParameterRichTextValue, type ResolveStringRenderer, type RichTextBuiltInElement, type RichTextBuiltInFormat, type RichTextNode, type RichTextNodeWithChildren, type StringRenderContext, type TableCellNode, type TableNode, type TableRowNode, type TextNode, emptyRichTextValue, getLabelForElement, getLabelForFormat, getRichTextTagFromTableCellHeaderState, 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, tableHtmlRenderer, tablecellHtmlRenderer, tablerowHtmlRenderer, textHtmlRenderer, walkRichTextTree };
package/dist/index.esm.js CHANGED
@@ -155,6 +155,40 @@ var rootHtmlRenderer = ({ context, renderChildren }) => {
155
155
  return hasChildren(context.currentNode) ? renderChildren(context.currentNode.children) : "";
156
156
  };
157
157
 
158
+ // src/nodes/table.ts
159
+ var tableHtmlRenderer = ({ context, renderChildren }) => {
160
+ return ["table", "tbody"].reduceRight((children, tag) => {
161
+ return renderHtmlElement(tag, null, children);
162
+ }, renderChildren(context.currentNode.children));
163
+ };
164
+ var tableTextRenderer = ({ context, renderChildren }) => {
165
+ return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : "";
166
+ };
167
+
168
+ // src/nodes/tablecell.ts
169
+ var tablecellHtmlRenderer = ({ context, renderChildren }) => {
170
+ const node = context.currentNode;
171
+ const tag = getRichTextTagFromTableCellHeaderState(node.headerState);
172
+ return renderHtmlElement(tag, null, renderChildren(context.currentNode.children));
173
+ };
174
+ var tablecellTextRenderer = ({ context, renderChildren }) => {
175
+ return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : "";
176
+ };
177
+ function getRichTextTagFromTableCellHeaderState(headerState) {
178
+ if (headerState === 0) {
179
+ return "td";
180
+ }
181
+ return "th";
182
+ }
183
+
184
+ // src/nodes/tablerow.ts
185
+ var tablerowHtmlRenderer = ({ context, renderChildren }) => {
186
+ return renderHtmlElement("tr", null, renderChildren(context.currentNode.children));
187
+ };
188
+ var tablerowTextRenderer = ({ context, renderChildren }) => {
189
+ return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : "";
190
+ };
191
+
158
192
  // src/nodes/text.ts
159
193
  var textHtmlRenderer = ({ context }) => {
160
194
  const node = context.currentNode;
@@ -211,7 +245,10 @@ var rendererTypeMap = /* @__PURE__ */ new Map([
211
245
  ["paragraph", paragraphHtmlRenderer],
212
246
  ["root", rootHtmlRenderer],
213
247
  ["text", textHtmlRenderer],
214
- ["tab", tabHtmlRenderer]
248
+ ["tab", tabHtmlRenderer],
249
+ ["table", tableHtmlRenderer],
250
+ ["tablecell", tablecellHtmlRenderer],
251
+ ["tablerow", tablerowHtmlRenderer]
215
252
  ]);
216
253
  var resolveDefaultRenderer = (context) => {
217
254
  const renderer = rendererTypeMap.get(context.currentNode.type);
@@ -248,8 +285,7 @@ function initializeRenderContext(node, parentContext) {
248
285
  }
249
286
  function renderToHtml(node, parentContext) {
250
287
  var _a;
251
- if (!isRichTextNode(node))
252
- return "";
288
+ if (!isRichTextNode(node)) return "";
253
289
  const context = initializeRenderContext(node, parentContext);
254
290
  let renderer = (_a = context.resolveRenderer) == null ? void 0 : _a.call(context, context);
255
291
  if (typeof renderer === "undefined") {
@@ -280,7 +316,10 @@ var rendererTypeMap2 = /* @__PURE__ */ new Map([
280
316
  ["linebreak", linebreakTextRenderer],
281
317
  ["paragraph", paragraphTextRenderer],
282
318
  ["listitem", listitemTextRenderer],
283
- ["heading", headingTextRenderer]
319
+ ["heading", headingTextRenderer],
320
+ ["table", tableTextRenderer],
321
+ ["tablecell", tablecellTextRenderer],
322
+ ["tablerow", tablerowTextRenderer]
284
323
  ]);
285
324
  var resolveDefaultRenderer2 = (context) => {
286
325
  const renderer = rendererTypeMap2.get(context.currentNode.type);
@@ -307,8 +346,7 @@ function initializeRenderContext2(node, parentContext) {
307
346
  }
308
347
  function renderToText(node, parentContext) {
309
348
  var _a;
310
- if (!isRichTextNode(node))
311
- return "";
349
+ if (!isRichTextNode(node)) return "";
312
350
  const context = initializeRenderContext2(node, parentContext);
313
351
  let renderer = (_a = context.resolveRenderer) == null ? void 0 : _a.call(context, context);
314
352
  if (typeof renderer === "undefined") {
@@ -384,6 +422,10 @@ var richTextBuiltInElements = [
384
422
  label: "Code Block",
385
423
  type: "code"
386
424
  },
425
+ {
426
+ label: "Table",
427
+ type: "table"
428
+ },
387
429
  {
388
430
  label: "Dynamic Token",
389
431
  type: "variable"
@@ -432,9 +474,32 @@ var getLabelForFormat = (type) => {
432
474
  const format = richTextBuiltInFormats.find((element) => element.type === type);
433
475
  return (_a = format == null ? void 0 : format.label) != null ? _a : type;
434
476
  };
477
+ var emptyRichTextValue = {
478
+ root: {
479
+ type: "root",
480
+ version: 1,
481
+ direction: null,
482
+ format: "",
483
+ indent: 0,
484
+ children: [
485
+ {
486
+ type: "paragraph",
487
+ version: 1,
488
+ format: "start",
489
+ indent: 0,
490
+ direction: null,
491
+ children: [],
492
+ textFormat: 0,
493
+ textStyle: ""
494
+ }
495
+ ]
496
+ }
497
+ };
435
498
  export {
499
+ emptyRichTextValue,
436
500
  getLabelForElement,
437
501
  getLabelForFormat,
502
+ getRichTextTagFromTableCellHeaderState,
438
503
  getRichTextTagsFromTextFormat,
439
504
  hasChildren,
440
505
  headingHtmlRenderer,
@@ -461,6 +526,9 @@ export {
461
526
  richTextBuiltInElements,
462
527
  richTextBuiltInFormats,
463
528
  rootHtmlRenderer,
529
+ tableHtmlRenderer,
530
+ tablecellHtmlRenderer,
531
+ tablerowHtmlRenderer,
464
532
  textHtmlRenderer,
465
533
  walkRichTextTree
466
534
  };
package/dist/index.js CHANGED
@@ -20,8 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ emptyRichTextValue: () => emptyRichTextValue,
23
24
  getLabelForElement: () => getLabelForElement,
24
25
  getLabelForFormat: () => getLabelForFormat,
26
+ getRichTextTagFromTableCellHeaderState: () => getRichTextTagFromTableCellHeaderState,
25
27
  getRichTextTagsFromTextFormat: () => getRichTextTagsFromTextFormat,
26
28
  hasChildren: () => hasChildren,
27
29
  headingHtmlRenderer: () => headingHtmlRenderer,
@@ -48,6 +50,9 @@ __export(src_exports, {
48
50
  richTextBuiltInElements: () => richTextBuiltInElements,
49
51
  richTextBuiltInFormats: () => richTextBuiltInFormats,
50
52
  rootHtmlRenderer: () => rootHtmlRenderer,
53
+ tableHtmlRenderer: () => tableHtmlRenderer,
54
+ tablecellHtmlRenderer: () => tablecellHtmlRenderer,
55
+ tablerowHtmlRenderer: () => tablerowHtmlRenderer,
51
56
  textHtmlRenderer: () => textHtmlRenderer,
52
57
  walkRichTextTree: () => walkRichTextTree
53
58
  });
@@ -210,6 +215,40 @@ var rootHtmlRenderer = ({ context, renderChildren }) => {
210
215
  return hasChildren(context.currentNode) ? renderChildren(context.currentNode.children) : "";
211
216
  };
212
217
 
218
+ // src/nodes/table.ts
219
+ var tableHtmlRenderer = ({ context, renderChildren }) => {
220
+ return ["table", "tbody"].reduceRight((children, tag) => {
221
+ return renderHtmlElement(tag, null, children);
222
+ }, renderChildren(context.currentNode.children));
223
+ };
224
+ var tableTextRenderer = ({ context, renderChildren }) => {
225
+ return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : "";
226
+ };
227
+
228
+ // src/nodes/tablecell.ts
229
+ var tablecellHtmlRenderer = ({ context, renderChildren }) => {
230
+ const node = context.currentNode;
231
+ const tag = getRichTextTagFromTableCellHeaderState(node.headerState);
232
+ return renderHtmlElement(tag, null, renderChildren(context.currentNode.children));
233
+ };
234
+ var tablecellTextRenderer = ({ context, renderChildren }) => {
235
+ return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : "";
236
+ };
237
+ function getRichTextTagFromTableCellHeaderState(headerState) {
238
+ if (headerState === 0) {
239
+ return "td";
240
+ }
241
+ return "th";
242
+ }
243
+
244
+ // src/nodes/tablerow.ts
245
+ var tablerowHtmlRenderer = ({ context, renderChildren }) => {
246
+ return renderHtmlElement("tr", null, renderChildren(context.currentNode.children));
247
+ };
248
+ var tablerowTextRenderer = ({ context, renderChildren }) => {
249
+ return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : "";
250
+ };
251
+
213
252
  // src/nodes/text.ts
214
253
  var textHtmlRenderer = ({ context }) => {
215
254
  const node = context.currentNode;
@@ -266,7 +305,10 @@ var rendererTypeMap = /* @__PURE__ */ new Map([
266
305
  ["paragraph", paragraphHtmlRenderer],
267
306
  ["root", rootHtmlRenderer],
268
307
  ["text", textHtmlRenderer],
269
- ["tab", tabHtmlRenderer]
308
+ ["tab", tabHtmlRenderer],
309
+ ["table", tableHtmlRenderer],
310
+ ["tablecell", tablecellHtmlRenderer],
311
+ ["tablerow", tablerowHtmlRenderer]
270
312
  ]);
271
313
  var resolveDefaultRenderer = (context) => {
272
314
  const renderer = rendererTypeMap.get(context.currentNode.type);
@@ -303,8 +345,7 @@ function initializeRenderContext(node, parentContext) {
303
345
  }
304
346
  function renderToHtml(node, parentContext) {
305
347
  var _a;
306
- if (!isRichTextNode(node))
307
- return "";
348
+ if (!isRichTextNode(node)) return "";
308
349
  const context = initializeRenderContext(node, parentContext);
309
350
  let renderer = (_a = context.resolveRenderer) == null ? void 0 : _a.call(context, context);
310
351
  if (typeof renderer === "undefined") {
@@ -335,7 +376,10 @@ var rendererTypeMap2 = /* @__PURE__ */ new Map([
335
376
  ["linebreak", linebreakTextRenderer],
336
377
  ["paragraph", paragraphTextRenderer],
337
378
  ["listitem", listitemTextRenderer],
338
- ["heading", headingTextRenderer]
379
+ ["heading", headingTextRenderer],
380
+ ["table", tableTextRenderer],
381
+ ["tablecell", tablecellTextRenderer],
382
+ ["tablerow", tablerowTextRenderer]
339
383
  ]);
340
384
  var resolveDefaultRenderer2 = (context) => {
341
385
  const renderer = rendererTypeMap2.get(context.currentNode.type);
@@ -362,8 +406,7 @@ function initializeRenderContext2(node, parentContext) {
362
406
  }
363
407
  function renderToText(node, parentContext) {
364
408
  var _a;
365
- if (!isRichTextNode(node))
366
- return "";
409
+ if (!isRichTextNode(node)) return "";
367
410
  const context = initializeRenderContext2(node, parentContext);
368
411
  let renderer = (_a = context.resolveRenderer) == null ? void 0 : _a.call(context, context);
369
412
  if (typeof renderer === "undefined") {
@@ -439,6 +482,10 @@ var richTextBuiltInElements = [
439
482
  label: "Code Block",
440
483
  type: "code"
441
484
  },
485
+ {
486
+ label: "Table",
487
+ type: "table"
488
+ },
442
489
  {
443
490
  label: "Dynamic Token",
444
491
  type: "variable"
@@ -487,10 +534,33 @@ var getLabelForFormat = (type) => {
487
534
  const format = richTextBuiltInFormats.find((element) => element.type === type);
488
535
  return (_a = format == null ? void 0 : format.label) != null ? _a : type;
489
536
  };
537
+ var emptyRichTextValue = {
538
+ root: {
539
+ type: "root",
540
+ version: 1,
541
+ direction: null,
542
+ format: "",
543
+ indent: 0,
544
+ children: [
545
+ {
546
+ type: "paragraph",
547
+ version: 1,
548
+ format: "start",
549
+ indent: 0,
550
+ direction: null,
551
+ children: [],
552
+ textFormat: 0,
553
+ textStyle: ""
554
+ }
555
+ ]
556
+ }
557
+ };
490
558
  // Annotate the CommonJS export names for ESM import in node:
491
559
  0 && (module.exports = {
560
+ emptyRichTextValue,
492
561
  getLabelForElement,
493
562
  getLabelForFormat,
563
+ getRichTextTagFromTableCellHeaderState,
494
564
  getRichTextTagsFromTextFormat,
495
565
  hasChildren,
496
566
  headingHtmlRenderer,
@@ -517,6 +587,9 @@ var getLabelForFormat = (type) => {
517
587
  richTextBuiltInElements,
518
588
  richTextBuiltInFormats,
519
589
  rootHtmlRenderer,
590
+ tableHtmlRenderer,
591
+ tablecellHtmlRenderer,
592
+ tablerowHtmlRenderer,
520
593
  textHtmlRenderer,
521
594
  walkRichTextTree
522
595
  });
package/dist/index.mjs CHANGED
@@ -155,6 +155,40 @@ var rootHtmlRenderer = ({ context, renderChildren }) => {
155
155
  return hasChildren(context.currentNode) ? renderChildren(context.currentNode.children) : "";
156
156
  };
157
157
 
158
+ // src/nodes/table.ts
159
+ var tableHtmlRenderer = ({ context, renderChildren }) => {
160
+ return ["table", "tbody"].reduceRight((children, tag) => {
161
+ return renderHtmlElement(tag, null, children);
162
+ }, renderChildren(context.currentNode.children));
163
+ };
164
+ var tableTextRenderer = ({ context, renderChildren }) => {
165
+ return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : "";
166
+ };
167
+
168
+ // src/nodes/tablecell.ts
169
+ var tablecellHtmlRenderer = ({ context, renderChildren }) => {
170
+ const node = context.currentNode;
171
+ const tag = getRichTextTagFromTableCellHeaderState(node.headerState);
172
+ return renderHtmlElement(tag, null, renderChildren(context.currentNode.children));
173
+ };
174
+ var tablecellTextRenderer = ({ context, renderChildren }) => {
175
+ return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : "";
176
+ };
177
+ function getRichTextTagFromTableCellHeaderState(headerState) {
178
+ if (headerState === 0) {
179
+ return "td";
180
+ }
181
+ return "th";
182
+ }
183
+
184
+ // src/nodes/tablerow.ts
185
+ var tablerowHtmlRenderer = ({ context, renderChildren }) => {
186
+ return renderHtmlElement("tr", null, renderChildren(context.currentNode.children));
187
+ };
188
+ var tablerowTextRenderer = ({ context, renderChildren }) => {
189
+ return hasChildren(context.currentNode) ? `${renderChildren(context.currentNode.children)} ` : "";
190
+ };
191
+
158
192
  // src/nodes/text.ts
159
193
  var textHtmlRenderer = ({ context }) => {
160
194
  const node = context.currentNode;
@@ -211,7 +245,10 @@ var rendererTypeMap = /* @__PURE__ */ new Map([
211
245
  ["paragraph", paragraphHtmlRenderer],
212
246
  ["root", rootHtmlRenderer],
213
247
  ["text", textHtmlRenderer],
214
- ["tab", tabHtmlRenderer]
248
+ ["tab", tabHtmlRenderer],
249
+ ["table", tableHtmlRenderer],
250
+ ["tablecell", tablecellHtmlRenderer],
251
+ ["tablerow", tablerowHtmlRenderer]
215
252
  ]);
216
253
  var resolveDefaultRenderer = (context) => {
217
254
  const renderer = rendererTypeMap.get(context.currentNode.type);
@@ -248,8 +285,7 @@ function initializeRenderContext(node, parentContext) {
248
285
  }
249
286
  function renderToHtml(node, parentContext) {
250
287
  var _a;
251
- if (!isRichTextNode(node))
252
- return "";
288
+ if (!isRichTextNode(node)) return "";
253
289
  const context = initializeRenderContext(node, parentContext);
254
290
  let renderer = (_a = context.resolveRenderer) == null ? void 0 : _a.call(context, context);
255
291
  if (typeof renderer === "undefined") {
@@ -280,7 +316,10 @@ var rendererTypeMap2 = /* @__PURE__ */ new Map([
280
316
  ["linebreak", linebreakTextRenderer],
281
317
  ["paragraph", paragraphTextRenderer],
282
318
  ["listitem", listitemTextRenderer],
283
- ["heading", headingTextRenderer]
319
+ ["heading", headingTextRenderer],
320
+ ["table", tableTextRenderer],
321
+ ["tablecell", tablecellTextRenderer],
322
+ ["tablerow", tablerowTextRenderer]
284
323
  ]);
285
324
  var resolveDefaultRenderer2 = (context) => {
286
325
  const renderer = rendererTypeMap2.get(context.currentNode.type);
@@ -307,8 +346,7 @@ function initializeRenderContext2(node, parentContext) {
307
346
  }
308
347
  function renderToText(node, parentContext) {
309
348
  var _a;
310
- if (!isRichTextNode(node))
311
- return "";
349
+ if (!isRichTextNode(node)) return "";
312
350
  const context = initializeRenderContext2(node, parentContext);
313
351
  let renderer = (_a = context.resolveRenderer) == null ? void 0 : _a.call(context, context);
314
352
  if (typeof renderer === "undefined") {
@@ -384,6 +422,10 @@ var richTextBuiltInElements = [
384
422
  label: "Code Block",
385
423
  type: "code"
386
424
  },
425
+ {
426
+ label: "Table",
427
+ type: "table"
428
+ },
387
429
  {
388
430
  label: "Dynamic Token",
389
431
  type: "variable"
@@ -432,9 +474,32 @@ var getLabelForFormat = (type) => {
432
474
  const format = richTextBuiltInFormats.find((element) => element.type === type);
433
475
  return (_a = format == null ? void 0 : format.label) != null ? _a : type;
434
476
  };
477
+ var emptyRichTextValue = {
478
+ root: {
479
+ type: "root",
480
+ version: 1,
481
+ direction: null,
482
+ format: "",
483
+ indent: 0,
484
+ children: [
485
+ {
486
+ type: "paragraph",
487
+ version: 1,
488
+ format: "start",
489
+ indent: 0,
490
+ direction: null,
491
+ children: [],
492
+ textFormat: 0,
493
+ textStyle: ""
494
+ }
495
+ ]
496
+ }
497
+ };
435
498
  export {
499
+ emptyRichTextValue,
436
500
  getLabelForElement,
437
501
  getLabelForFormat,
502
+ getRichTextTagFromTableCellHeaderState,
438
503
  getRichTextTagsFromTextFormat,
439
504
  hasChildren,
440
505
  headingHtmlRenderer,
@@ -461,6 +526,9 @@ export {
461
526
  richTextBuiltInElements,
462
527
  richTextBuiltInFormats,
463
528
  rootHtmlRenderer,
529
+ tableHtmlRenderer,
530
+ tablecellHtmlRenderer,
531
+ tablerowHtmlRenderer,
464
532
  textHtmlRenderer,
465
533
  walkRichTextTree
466
534
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/richtext",
3
- "version": "19.135.1-alpha.10+261b728b6b",
3
+ "version": "19.135.1-alpha.11+9f52e6cfd6",
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",
@@ -40,13 +40,12 @@
40
40
  "document": "api-extractor run --local"
41
41
  },
42
42
  "devDependencies": {
43
- "@lexical/headless": "^0.12.0",
44
- "@lexical/html": "^0.12.0",
45
- "@lexical/link": "^0.12.0",
46
- "@lexical/list": "^0.12.0",
47
- "@lexical/rich-text": "^0.12.0",
48
- "@uniformdev/canvas": "^19.135.1-alpha.10+261b728b6b",
49
- "lexical": "^0.12.0"
43
+ "@lexical/headless": "0.17.1",
44
+ "@lexical/html": "0.17.1",
45
+ "@lexical/link": "0.17.1",
46
+ "@lexical/list": "0.17.1",
47
+ "@lexical/rich-text": "0.17.1",
48
+ "lexical": "0.17.1"
50
49
  },
51
50
  "files": [
52
51
  "/dist"
@@ -54,5 +53,5 @@
54
53
  "publishConfig": {
55
54
  "access": "public"
56
55
  },
57
- "gitHead": "261b728b6bc036ca8260861715632078b3eb27ca"
56
+ "gitHead": "9f52e6cfd6e562e9c759735ba2a44378388a2a82"
58
57
  }