@contello/rich-text 8.21.3 → 8.22.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2026 entwico GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -1,108 +1,69 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- createRichTextDocumentFromString: () => createRichTextDocumentFromString,
24
- isRichTextDocumentEmpty: () => isRichTextDocumentEmpty,
25
- parseRichTextDocument: () => parseRichTextDocument,
26
- richTextDocumentToString: () => richTextDocumentToString,
27
- richTextNodeToString: () => richTextNodeToString,
28
- richTextNodesToString: () => richTextNodesToString
29
- });
30
- module.exports = __toCommonJS(index_exports);
31
-
32
- // src/helpers.ts
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/helpers.ts
3
+ /** Converts a single rich text node to its plain text representation. */
33
4
  function richTextNodeToString(node) {
34
- if (node.type === "text") {
35
- return node.text;
36
- }
37
- switch (node.type) {
38
- case "heading":
39
- case "paragraph":
40
- case "codeBlock":
41
- case "blockquote":
42
- return (node.content ?? []).map(richTextNodeToString).join("");
43
- case "bulletList":
44
- case "orderedList":
45
- return (node.content ?? []).map((item) => (item.content ?? []).map(richTextNodeToString).join("")).join("");
46
- case "listItem":
47
- return (node.content ?? []).map(richTextNodeToString).join("");
48
- case "horizontalRule":
49
- return "---";
50
- case "hardBreak":
51
- return "\n";
52
- case "table":
53
- return (node.content ?? []).map(
54
- (row) => (row.content ?? []).map((cell) => (cell.content ?? []).map(richTextNodeToString).join("")).join(" | ")
55
- ).join("\n");
56
- case "tableRow":
57
- return (node.content ?? []).map((cell) => (cell.content ?? []).map(richTextNodeToString).join("")).join(" | ");
58
- case "tableCell":
59
- return (node.content ?? []).map(richTextNodeToString).join("");
60
- case "tableHeader":
61
- return (node.content ?? []).map(richTextNodeToString).join("");
62
- }
5
+ if (node.type === "text") return node.text;
6
+ switch (node.type) {
7
+ case "heading":
8
+ case "paragraph":
9
+ case "codeBlock":
10
+ case "blockquote": return (node.content ?? []).map((node) => richTextNodeToString(node)).join("");
11
+ case "bulletList":
12
+ case "orderedList": return (node.content ?? []).map((item) => (item.content ?? []).map((node) => richTextNodeToString(node)).join("")).join("");
13
+ case "listItem": return (node.content ?? []).map((node) => richTextNodeToString(node)).join("");
14
+ case "horizontalRule": return "---";
15
+ case "hardBreak": return "\n";
16
+ case "table": return (node.content ?? []).map((row) => (row.content ?? []).map((cell) => (cell.content ?? []).map((node) => richTextNodeToString(node)).join("")).join(" | ")).join("\n");
17
+ case "tableRow": return (node.content ?? []).map((cell) => (cell.content ?? []).map((node) => richTextNodeToString(node)).join("")).join(" | ");
18
+ case "tableCell": return (node.content ?? []).map((node) => richTextNodeToString(node)).join("");
19
+ case "tableHeader": return (node.content ?? []).map((node) => richTextNodeToString(node)).join("");
20
+ }
63
21
  }
22
+ /** Converts an array of rich text nodes to plain text, joining them with newlines. */
64
23
  function richTextNodesToString(nodes) {
65
- return nodes.map(richTextNodeToString).join("\n");
24
+ return nodes.map((node) => richTextNodeToString(node)).join("\n");
66
25
  }
26
+ /** Converts a rich text document to its plain text representation. */
67
27
  function richTextDocumentToString(document) {
68
- return richTextNodesToString(document.content ?? []);
28
+ return richTextNodesToString(document.content ?? []);
69
29
  }
30
+ /** Returns `true` if the document has no content or only whitespace. */
70
31
  function isRichTextDocumentEmpty(document) {
71
- return (document.content ?? []).length === 0 || (document.content ?? []).every((node) => richTextNodeToString(node).trim() === "");
32
+ return (document.content ?? []).length === 0 || (document.content ?? []).every((node) => richTextNodeToString(node).trim() === "");
72
33
  }
34
+ /** Creates a rich text document containing a single paragraph with the given text. */
73
35
  function createRichTextDocumentFromString(text) {
74
- return {
75
- type: "doc",
76
- content: [
77
- {
78
- type: "paragraph",
79
- content: text ? [{ type: "text", text }] : []
80
- }
81
- ]
82
- };
36
+ return {
37
+ type: "doc",
38
+ content: [{
39
+ type: "paragraph",
40
+ content: text ? [{
41
+ type: "text",
42
+ text
43
+ }] : []
44
+ }]
45
+ };
83
46
  }
84
47
  function createEmptyRichTextDocument() {
85
- return {
86
- type: "doc",
87
- content: []
88
- };
48
+ return {
49
+ type: "doc",
50
+ content: []
51
+ };
89
52
  }
53
+ /**
54
+ * Parses a JSON string into a {@link RichTextDocument}.
55
+ * Returns an empty document if parsing fails or the input is nullish.
56
+ */
90
57
  function parseRichTextDocument(text) {
91
- if (!text) {
92
- return createEmptyRichTextDocument();
93
- }
94
- const parsed = JSON.parse(text);
95
- if (parsed.type !== "doc") {
96
- return createEmptyRichTextDocument();
97
- }
98
- return parsed;
58
+ if (!text) return createEmptyRichTextDocument();
59
+ const parsed = JSON.parse(text);
60
+ if (parsed.type !== "doc") return createEmptyRichTextDocument();
61
+ return parsed;
99
62
  }
100
- // Annotate the CommonJS export names for ESM import in node:
101
- 0 && (module.exports = {
102
- createRichTextDocumentFromString,
103
- isRichTextDocumentEmpty,
104
- parseRichTextDocument,
105
- richTextDocumentToString,
106
- richTextNodeToString,
107
- richTextNodesToString
108
- });
63
+ //#endregion
64
+ exports.createRichTextDocumentFromString = createRichTextDocumentFromString;
65
+ exports.isRichTextDocumentEmpty = isRichTextDocumentEmpty;
66
+ exports.parseRichTextDocument = parseRichTextDocument;
67
+ exports.richTextDocumentToString = richTextDocumentToString;
68
+ exports.richTextNodeToString = richTextNodeToString;
69
+ exports.richTextNodesToString = richTextNodesToString;
package/dist/index.d.cts CHANGED
@@ -1,125 +1,132 @@
1
+ //#region src/types.d.ts
1
2
  type RichTextDocument = {
2
- type: 'doc';
3
- content?: Maybe<RichTextNode[]>;
3
+ type: 'doc';
4
+ content?: Maybe<RichTextNode[]>;
4
5
  };
5
6
  type RichTextNode = RichTextHeading | RichTextParagraph | RichTextCodeBlock | RichTextBlockquote | RichTextHorizontalRule | RichTextHardBreak | RichTextBulletList | RichTextOrderedList | RichTextListItem | RichTextTable | RichTextTableRow | RichTextTableHeader | RichTextTableCell | RichTextText;
6
7
  type RichTextHeading = {
7
- type: 'heading';
8
- attrs?: Maybe<{
9
- textAlign?: Maybe<RichTextTextAlign>;
10
- level?: Maybe<1 | 2 | 3 | 4 | 5 | 6>;
11
- }>;
12
- content?: Maybe<RichTextNode[]>;
8
+ type: 'heading';
9
+ attrs?: Maybe<{
10
+ textAlign?: Maybe<RichTextTextAlign>;
11
+ level?: Maybe<1 | 2 | 3 | 4 | 5 | 6>;
12
+ }>;
13
+ content?: Maybe<RichTextNode[]>;
13
14
  };
14
15
  type RichTextParagraph = {
15
- type: 'paragraph';
16
- attrs?: Maybe<{
17
- textAlign?: Maybe<RichTextTextAlign>;
18
- }>;
19
- content?: Maybe<RichTextNode[]>;
16
+ type: 'paragraph';
17
+ attrs?: Maybe<{
18
+ textAlign?: Maybe<RichTextTextAlign>;
19
+ }>;
20
+ content?: Maybe<RichTextNode[]>;
20
21
  };
21
22
  type RichTextCodeBlock = {
22
- type: 'codeBlock';
23
- content?: Maybe<RichTextText[]>;
23
+ type: 'codeBlock';
24
+ content?: Maybe<RichTextText[]>;
24
25
  };
25
26
  type RichTextBlockquote = {
26
- type: 'blockquote';
27
- content?: Maybe<RichTextText[]>;
27
+ type: 'blockquote';
28
+ content?: Maybe<RichTextText[]>;
28
29
  };
29
30
  type RichTextBulletList = {
30
- type: 'bulletList';
31
- content?: Maybe<RichTextListItem[]>;
31
+ type: 'bulletList';
32
+ content?: Maybe<RichTextListItem[]>;
32
33
  };
33
34
  type RichTextOrderedList = {
34
- type: 'orderedList';
35
- attrs?: Maybe<{
36
- start?: Maybe<number>;
37
- }>;
38
- content?: Maybe<RichTextListItem[]>;
35
+ type: 'orderedList';
36
+ attrs?: Maybe<{
37
+ start?: Maybe<number>;
38
+ }>;
39
+ content?: Maybe<RichTextListItem[]>;
39
40
  };
40
41
  type RichTextListItem = {
41
- type: 'listItem';
42
- content?: Maybe<RichTextNode[]>;
42
+ type: 'listItem';
43
+ content?: Maybe<RichTextNode[]>;
43
44
  };
44
45
  type RichTextTable = {
45
- type: 'table';
46
- content?: Maybe<RichTextTableRow[]>;
46
+ type: 'table';
47
+ content?: Maybe<RichTextTableRow[]>;
47
48
  };
48
49
  type RichTextTableRow = {
49
- type: 'tableRow';
50
- content?: Maybe<(RichTextTableHeader | RichTextTableCell)[]>;
50
+ type: 'tableRow';
51
+ content?: Maybe<(RichTextTableHeader | RichTextTableCell)[]>;
51
52
  };
52
53
  type RichTextTableHeader = {
53
- type: 'tableHeader';
54
- attrs?: Maybe<{
55
- colspan: Maybe<number>;
56
- rowspan: Maybe<number>;
57
- colwidth: Maybe<number[]>;
58
- }>;
59
- content?: Maybe<RichTextNode[]>;
54
+ type: 'tableHeader';
55
+ attrs?: Maybe<{
56
+ colspan: Maybe<number>;
57
+ rowspan: Maybe<number>;
58
+ colwidth: Maybe<number[]>;
59
+ }>;
60
+ content?: Maybe<RichTextNode[]>;
60
61
  };
61
62
  type RichTextTableCell = {
62
- type: 'tableCell';
63
- attrs?: Maybe<{
64
- colspan: Maybe<number>;
65
- rowspan: Maybe<number>;
66
- colwidth: Maybe<number[]>;
67
- }>;
68
- content?: Maybe<RichTextNode[]>;
63
+ type: 'tableCell';
64
+ attrs?: Maybe<{
65
+ colspan: Maybe<number>;
66
+ rowspan: Maybe<number>;
67
+ colwidth: Maybe<number[]>;
68
+ }>;
69
+ content?: Maybe<RichTextNode[]>;
69
70
  };
70
71
  type RichTextHorizontalRule = {
71
- type: 'horizontalRule';
72
+ type: 'horizontalRule';
72
73
  };
73
74
  type RichTextHardBreak = {
74
- type: 'hardBreak';
75
+ type: 'hardBreak';
75
76
  };
76
77
  type RichTextText = {
77
- type: 'text';
78
- text: string;
79
- marks?: Maybe<RichTextMark[]>;
78
+ type: 'text';
79
+ text: string;
80
+ marks?: Maybe<RichTextMark[]>;
80
81
  };
81
82
  type RichTextUnderlineMark = {
82
- type: 'underline';
83
+ type: 'underline';
83
84
  };
84
85
  type RichTextBoldMark = {
85
- type: 'bold';
86
+ type: 'bold';
86
87
  };
87
88
  type RichTextItalicMark = {
88
- type: 'italic';
89
+ type: 'italic';
89
90
  };
90
91
  type RichTextCodeMark = {
91
- type: 'code';
92
+ type: 'code';
92
93
  };
93
94
  type RichTextStrikeMark = {
94
- type: 'strike';
95
+ type: 'strike';
95
96
  };
96
97
  type RichTextTextStyleMark = {
97
- type: 'textStyle';
98
- attrs?: Maybe<{
99
- color?: Maybe<string>;
100
- }>;
98
+ type: 'textStyle';
99
+ attrs?: Maybe<{
100
+ color?: Maybe<string>;
101
+ }>;
101
102
  };
102
103
  type RichTextLink<T extends Record<string, any> = Record<string, any>> = {
103
- type: 'link';
104
- attrs?: Maybe<{
105
- data?: Maybe<T>;
106
- }>;
104
+ type: 'link';
105
+ attrs?: Maybe<{
106
+ data?: Maybe<T>;
107
+ }>;
107
108
  };
108
109
  type RichTextMark = RichTextUnderlineMark | RichTextBoldMark | RichTextItalicMark | RichTextCodeMark | RichTextStrikeMark | RichTextTextStyleMark | RichTextLink;
109
110
  type RichTextTextAlign = 'left' | 'center' | 'right';
110
111
  type Maybe<T> = T | null | undefined;
111
-
112
+ type DeepReadonly<T> = T extends (infer U)[] ? readonly DeepReadonly<U>[] : T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]> } : T;
113
+ //#endregion
114
+ //#region src/helpers.d.ts
112
115
  /** Converts a single rich text node to its plain text representation. */
113
- declare function richTextNodeToString(node: RichTextNode): string;
116
+ declare function richTextNodeToString(node: DeepReadonly<RichTextNode>): string;
114
117
  /** Converts an array of rich text nodes to plain text, joining them with newlines. */
115
- declare function richTextNodesToString(nodes: RichTextNode[]): string;
118
+ declare function richTextNodesToString(nodes: readonly DeepReadonly<RichTextNode>[]): string;
116
119
  /** Converts a rich text document to its plain text representation. */
117
- declare function richTextDocumentToString(document: RichTextDocument): string;
120
+ declare function richTextDocumentToString(document: DeepReadonly<RichTextDocument>): string;
118
121
  /** Returns `true` if the document has no content or only whitespace. */
119
- declare function isRichTextDocumentEmpty(document: RichTextDocument): boolean;
122
+ declare function isRichTextDocumentEmpty(document: DeepReadonly<RichTextDocument>): boolean;
120
123
  /** Creates a rich text document containing a single paragraph with the given text. */
121
124
  declare function createRichTextDocumentFromString(text: string | null | undefined): RichTextDocument;
122
- /** Parses a JSON string into a {@link RichTextDocument}. Returns an empty document if parsing fails or the input is nullish. */
125
+ /**
126
+ * Parses a JSON string into a {@link RichTextDocument}.
127
+ * Returns an empty document if parsing fails or the input is nullish.
128
+ */
123
129
  declare function parseRichTextDocument(text: string | null | undefined): RichTextDocument;
124
-
125
- export { type Maybe, type RichTextBlockquote, type RichTextBoldMark, type RichTextBulletList, type RichTextCodeBlock, type RichTextCodeMark, type RichTextDocument, type RichTextHardBreak, type RichTextHeading, type RichTextHorizontalRule, type RichTextItalicMark, type RichTextLink, type RichTextListItem, type RichTextMark, type RichTextNode, type RichTextOrderedList, type RichTextParagraph, type RichTextStrikeMark, type RichTextTable, type RichTextTableCell, type RichTextTableHeader, type RichTextTableRow, type RichTextText, type RichTextTextAlign, type RichTextTextStyleMark, type RichTextUnderlineMark, createRichTextDocumentFromString, isRichTextDocumentEmpty, parseRichTextDocument, richTextDocumentToString, richTextNodeToString, richTextNodesToString };
130
+ //#endregion
131
+ export { DeepReadonly, Maybe, RichTextBlockquote, RichTextBoldMark, RichTextBulletList, RichTextCodeBlock, RichTextCodeMark, RichTextDocument, RichTextHardBreak, RichTextHeading, RichTextHorizontalRule, RichTextItalicMark, RichTextLink, RichTextListItem, RichTextMark, RichTextNode, RichTextOrderedList, RichTextParagraph, RichTextStrikeMark, RichTextTable, RichTextTableCell, RichTextTableHeader, RichTextTableRow, RichTextText, RichTextTextAlign, RichTextTextStyleMark, RichTextUnderlineMark, createRichTextDocumentFromString, isRichTextDocumentEmpty, parseRichTextDocument, richTextDocumentToString, richTextNodeToString, richTextNodesToString };
132
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/helpers.ts"],"mappings":";KACY,gBAAA;EACV,IAAA;EACA,OAAA,GAAU,K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AA,CAAwB,QAAA,EAAU,YAAY,CAAC,gBAAA;;iBAQ/C,gCAAA,CAAiC,IAAA,8BAAkC,gBAAgB;AD3DnG;;;;AAAA,iBCkFgB,qBAAA,CAAsB,IAAA,8BAAkC,gBAAgB"}
package/dist/index.d.ts CHANGED
@@ -1,125 +1,132 @@
1
+ //#region src/types.d.ts
1
2
  type RichTextDocument = {
2
- type: 'doc';
3
- content?: Maybe<RichTextNode[]>;
3
+ type: 'doc';
4
+ content?: Maybe<RichTextNode[]>;
4
5
  };
5
6
  type RichTextNode = RichTextHeading | RichTextParagraph | RichTextCodeBlock | RichTextBlockquote | RichTextHorizontalRule | RichTextHardBreak | RichTextBulletList | RichTextOrderedList | RichTextListItem | RichTextTable | RichTextTableRow | RichTextTableHeader | RichTextTableCell | RichTextText;
6
7
  type RichTextHeading = {
7
- type: 'heading';
8
- attrs?: Maybe<{
9
- textAlign?: Maybe<RichTextTextAlign>;
10
- level?: Maybe<1 | 2 | 3 | 4 | 5 | 6>;
11
- }>;
12
- content?: Maybe<RichTextNode[]>;
8
+ type: 'heading';
9
+ attrs?: Maybe<{
10
+ textAlign?: Maybe<RichTextTextAlign>;
11
+ level?: Maybe<1 | 2 | 3 | 4 | 5 | 6>;
12
+ }>;
13
+ content?: Maybe<RichTextNode[]>;
13
14
  };
14
15
  type RichTextParagraph = {
15
- type: 'paragraph';
16
- attrs?: Maybe<{
17
- textAlign?: Maybe<RichTextTextAlign>;
18
- }>;
19
- content?: Maybe<RichTextNode[]>;
16
+ type: 'paragraph';
17
+ attrs?: Maybe<{
18
+ textAlign?: Maybe<RichTextTextAlign>;
19
+ }>;
20
+ content?: Maybe<RichTextNode[]>;
20
21
  };
21
22
  type RichTextCodeBlock = {
22
- type: 'codeBlock';
23
- content?: Maybe<RichTextText[]>;
23
+ type: 'codeBlock';
24
+ content?: Maybe<RichTextText[]>;
24
25
  };
25
26
  type RichTextBlockquote = {
26
- type: 'blockquote';
27
- content?: Maybe<RichTextText[]>;
27
+ type: 'blockquote';
28
+ content?: Maybe<RichTextText[]>;
28
29
  };
29
30
  type RichTextBulletList = {
30
- type: 'bulletList';
31
- content?: Maybe<RichTextListItem[]>;
31
+ type: 'bulletList';
32
+ content?: Maybe<RichTextListItem[]>;
32
33
  };
33
34
  type RichTextOrderedList = {
34
- type: 'orderedList';
35
- attrs?: Maybe<{
36
- start?: Maybe<number>;
37
- }>;
38
- content?: Maybe<RichTextListItem[]>;
35
+ type: 'orderedList';
36
+ attrs?: Maybe<{
37
+ start?: Maybe<number>;
38
+ }>;
39
+ content?: Maybe<RichTextListItem[]>;
39
40
  };
40
41
  type RichTextListItem = {
41
- type: 'listItem';
42
- content?: Maybe<RichTextNode[]>;
42
+ type: 'listItem';
43
+ content?: Maybe<RichTextNode[]>;
43
44
  };
44
45
  type RichTextTable = {
45
- type: 'table';
46
- content?: Maybe<RichTextTableRow[]>;
46
+ type: 'table';
47
+ content?: Maybe<RichTextTableRow[]>;
47
48
  };
48
49
  type RichTextTableRow = {
49
- type: 'tableRow';
50
- content?: Maybe<(RichTextTableHeader | RichTextTableCell)[]>;
50
+ type: 'tableRow';
51
+ content?: Maybe<(RichTextTableHeader | RichTextTableCell)[]>;
51
52
  };
52
53
  type RichTextTableHeader = {
53
- type: 'tableHeader';
54
- attrs?: Maybe<{
55
- colspan: Maybe<number>;
56
- rowspan: Maybe<number>;
57
- colwidth: Maybe<number[]>;
58
- }>;
59
- content?: Maybe<RichTextNode[]>;
54
+ type: 'tableHeader';
55
+ attrs?: Maybe<{
56
+ colspan: Maybe<number>;
57
+ rowspan: Maybe<number>;
58
+ colwidth: Maybe<number[]>;
59
+ }>;
60
+ content?: Maybe<RichTextNode[]>;
60
61
  };
61
62
  type RichTextTableCell = {
62
- type: 'tableCell';
63
- attrs?: Maybe<{
64
- colspan: Maybe<number>;
65
- rowspan: Maybe<number>;
66
- colwidth: Maybe<number[]>;
67
- }>;
68
- content?: Maybe<RichTextNode[]>;
63
+ type: 'tableCell';
64
+ attrs?: Maybe<{
65
+ colspan: Maybe<number>;
66
+ rowspan: Maybe<number>;
67
+ colwidth: Maybe<number[]>;
68
+ }>;
69
+ content?: Maybe<RichTextNode[]>;
69
70
  };
70
71
  type RichTextHorizontalRule = {
71
- type: 'horizontalRule';
72
+ type: 'horizontalRule';
72
73
  };
73
74
  type RichTextHardBreak = {
74
- type: 'hardBreak';
75
+ type: 'hardBreak';
75
76
  };
76
77
  type RichTextText = {
77
- type: 'text';
78
- text: string;
79
- marks?: Maybe<RichTextMark[]>;
78
+ type: 'text';
79
+ text: string;
80
+ marks?: Maybe<RichTextMark[]>;
80
81
  };
81
82
  type RichTextUnderlineMark = {
82
- type: 'underline';
83
+ type: 'underline';
83
84
  };
84
85
  type RichTextBoldMark = {
85
- type: 'bold';
86
+ type: 'bold';
86
87
  };
87
88
  type RichTextItalicMark = {
88
- type: 'italic';
89
+ type: 'italic';
89
90
  };
90
91
  type RichTextCodeMark = {
91
- type: 'code';
92
+ type: 'code';
92
93
  };
93
94
  type RichTextStrikeMark = {
94
- type: 'strike';
95
+ type: 'strike';
95
96
  };
96
97
  type RichTextTextStyleMark = {
97
- type: 'textStyle';
98
- attrs?: Maybe<{
99
- color?: Maybe<string>;
100
- }>;
98
+ type: 'textStyle';
99
+ attrs?: Maybe<{
100
+ color?: Maybe<string>;
101
+ }>;
101
102
  };
102
103
  type RichTextLink<T extends Record<string, any> = Record<string, any>> = {
103
- type: 'link';
104
- attrs?: Maybe<{
105
- data?: Maybe<T>;
106
- }>;
104
+ type: 'link';
105
+ attrs?: Maybe<{
106
+ data?: Maybe<T>;
107
+ }>;
107
108
  };
108
109
  type RichTextMark = RichTextUnderlineMark | RichTextBoldMark | RichTextItalicMark | RichTextCodeMark | RichTextStrikeMark | RichTextTextStyleMark | RichTextLink;
109
110
  type RichTextTextAlign = 'left' | 'center' | 'right';
110
111
  type Maybe<T> = T | null | undefined;
111
-
112
+ type DeepReadonly<T> = T extends (infer U)[] ? readonly DeepReadonly<U>[] : T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]> } : T;
113
+ //#endregion
114
+ //#region src/helpers.d.ts
112
115
  /** Converts a single rich text node to its plain text representation. */
113
- declare function richTextNodeToString(node: RichTextNode): string;
116
+ declare function richTextNodeToString(node: DeepReadonly<RichTextNode>): string;
114
117
  /** Converts an array of rich text nodes to plain text, joining them with newlines. */
115
- declare function richTextNodesToString(nodes: RichTextNode[]): string;
118
+ declare function richTextNodesToString(nodes: readonly DeepReadonly<RichTextNode>[]): string;
116
119
  /** Converts a rich text document to its plain text representation. */
117
- declare function richTextDocumentToString(document: RichTextDocument): string;
120
+ declare function richTextDocumentToString(document: DeepReadonly<RichTextDocument>): string;
118
121
  /** Returns `true` if the document has no content or only whitespace. */
119
- declare function isRichTextDocumentEmpty(document: RichTextDocument): boolean;
122
+ declare function isRichTextDocumentEmpty(document: DeepReadonly<RichTextDocument>): boolean;
120
123
  /** Creates a rich text document containing a single paragraph with the given text. */
121
124
  declare function createRichTextDocumentFromString(text: string | null | undefined): RichTextDocument;
122
- /** Parses a JSON string into a {@link RichTextDocument}. Returns an empty document if parsing fails or the input is nullish. */
125
+ /**
126
+ * Parses a JSON string into a {@link RichTextDocument}.
127
+ * Returns an empty document if parsing fails or the input is nullish.
128
+ */
123
129
  declare function parseRichTextDocument(text: string | null | undefined): RichTextDocument;
124
-
125
- export { type Maybe, type RichTextBlockquote, type RichTextBoldMark, type RichTextBulletList, type RichTextCodeBlock, type RichTextCodeMark, type RichTextDocument, type RichTextHardBreak, type RichTextHeading, type RichTextHorizontalRule, type RichTextItalicMark, type RichTextLink, type RichTextListItem, type RichTextMark, type RichTextNode, type RichTextOrderedList, type RichTextParagraph, type RichTextStrikeMark, type RichTextTable, type RichTextTableCell, type RichTextTableHeader, type RichTextTableRow, type RichTextText, type RichTextTextAlign, type RichTextTextStyleMark, type RichTextUnderlineMark, createRichTextDocumentFromString, isRichTextDocumentEmpty, parseRichTextDocument, richTextDocumentToString, richTextNodeToString, richTextNodesToString };
130
+ //#endregion
131
+ export { DeepReadonly, Maybe, RichTextBlockquote, RichTextBoldMark, RichTextBulletList, RichTextCodeBlock, RichTextCodeMark, RichTextDocument, RichTextHardBreak, RichTextHeading, RichTextHorizontalRule, RichTextItalicMark, RichTextLink, RichTextListItem, RichTextMark, RichTextNode, RichTextOrderedList, RichTextParagraph, RichTextStrikeMark, RichTextTable, RichTextTableCell, RichTextTableHeader, RichTextTableRow, RichTextText, RichTextTextAlign, RichTextTextStyleMark, RichTextUnderlineMark, createRichTextDocumentFromString, isRichTextDocumentEmpty, parseRichTextDocument, richTextDocumentToString, richTextNodeToString, richTextNodesToString };
132
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/helpers.ts"],"mappings":";KACY,gBAAA;EACV,IAAA;EACA,OAAA,GAAU,KAAK,CAAC,YAAA;AAAA;AAAA,KAIN,YAAA,GACR,eAAA,GACA,iBAAA,GACA,iBAAA,GACA,kBAAA,GACA,sBAAA,GACA,iBAAA,GAEA,kBAAA,GACA,mBAAA,GACA,gBAAA,GAEA,aAAA,GACA,gBAAA,GACA,mBAAA,GACA,iBAAA,GAEA,YAAA;AAAA,KAGQ,eAAA;EACV,IAAA;EACA,KAAA,GAAQ,KAAA;IACN,SAAA,GAAY,KAAA,CAAM,iBAAA;IAClB,KAAA,GAAQ,KAAA;EAAA;EAEV,OAAA,GAAU,KAAA,CAAM,YAAA;AAAA;AAAA,KAGN,iBAAA;EACV,IAAA;EACA,KAAA,GAAQ,KAAA;IACN,SAAA,GAAY,KAAA,CAAM,iBAAA;EAAA;EAEpB,OAAA,GAAU,KAAA,CAAM,YAAA;AAAA;AAAA,KAGN,iBAAA;EACV,IAAA;EACA,OAAA,GAAU,KAAK,CAAC,YAAA;AAAA;AAAA,KAGN,kBAAA;EACV,IAAA;EACA,OAAA,GAAU,KAAK,CAAC,YAAA;AAAA;AAAA,KAIN,kBAAA;EACV,IAAA;EACA,O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AA,GAAQ,KAAA;IACN,IAAA,GAAO,KAAA,CAAM,CAAA;EAAA;AAAA;AAAA,KAIL,YAAA,GACR,qBAAA,GACA,gBAAA,GACA,kBAAA,GACA,gBAAA,GACA,kBAAA,GACA,qBAAA,GACA,YAAA;AAAA,KAEQ,iBAAA;AAAA,KAEA,KAAA,MAAW,CAAC;AAAA,KAIZ,YAAA,MAAkB,CAAA,gCACjB,YAAA,CAAa,CAAA,MACtB,CAAA,yCACyB,CAAA,GAAI,YAAA,CAAa,CAAA,CAAE,CAAA,OAC1C,CAAA;;;AAzKN;AAAA,iBCEgB,oBAAA,CAAqB,IAAA,EAAM,YAAY,CAAC,YAAA;;iBA6CxC,qBAAA,CAAsB,KAAA,WAAgB,YAAY,CAAC,YAAA;;iBAKnD,wBAAA,CAAyB,QAAA,EAAU,YAAY,CAAC,gBAAA;;iBAKhD,uBAAA,CAAwB,QAAA,EAAU,YAAY,CAAC,gBAAA;;iBAQ/C,gCAAA,CAAiC,IAAA,8BAAkC,gBAAgB;AD3DnG;;;;AAAA,iBCkFgB,qBAAA,CAAsB,IAAA,8BAAkC,gBAAgB"}
package/dist/index.js CHANGED
@@ -1,76 +1,65 @@
1
- // src/helpers.ts
1
+ //#region src/helpers.ts
2
+ /** Converts a single rich text node to its plain text representation. */
2
3
  function richTextNodeToString(node) {
3
- if (node.type === "text") {
4
- return node.text;
5
- }
6
- switch (node.type) {
7
- case "heading":
8
- case "paragraph":
9
- case "codeBlock":
10
- case "blockquote":
11
- return (node.content ?? []).map(richTextNodeToString).join("");
12
- case "bulletList":
13
- case "orderedList":
14
- return (node.content ?? []).map((item) => (item.content ?? []).map(richTextNodeToString).join("")).join("");
15
- case "listItem":
16
- return (node.content ?? []).map(richTextNodeToString).join("");
17
- case "horizontalRule":
18
- return "---";
19
- case "hardBreak":
20
- return "\n";
21
- case "table":
22
- return (node.content ?? []).map(
23
- (row) => (row.content ?? []).map((cell) => (cell.content ?? []).map(richTextNodeToString).join("")).join(" | ")
24
- ).join("\n");
25
- case "tableRow":
26
- return (node.content ?? []).map((cell) => (cell.content ?? []).map(richTextNodeToString).join("")).join(" | ");
27
- case "tableCell":
28
- return (node.content ?? []).map(richTextNodeToString).join("");
29
- case "tableHeader":
30
- return (node.content ?? []).map(richTextNodeToString).join("");
31
- }
4
+ if (node.type === "text") return node.text;
5
+ switch (node.type) {
6
+ case "heading":
7
+ case "paragraph":
8
+ case "codeBlock":
9
+ case "blockquote": return (node.content ?? []).map((node) => richTextNodeToString(node)).join("");
10
+ case "bulletList":
11
+ case "orderedList": return (node.content ?? []).map((item) => (item.content ?? []).map((node) => richTextNodeToString(node)).join("")).join("");
12
+ case "listItem": return (node.content ?? []).map((node) => richTextNodeToString(node)).join("");
13
+ case "horizontalRule": return "---";
14
+ case "hardBreak": return "\n";
15
+ case "table": return (node.content ?? []).map((row) => (row.content ?? []).map((cell) => (cell.content ?? []).map((node) => richTextNodeToString(node)).join("")).join(" | ")).join("\n");
16
+ case "tableRow": return (node.content ?? []).map((cell) => (cell.content ?? []).map((node) => richTextNodeToString(node)).join("")).join(" | ");
17
+ case "tableCell": return (node.content ?? []).map((node) => richTextNodeToString(node)).join("");
18
+ case "tableHeader": return (node.content ?? []).map((node) => richTextNodeToString(node)).join("");
19
+ }
32
20
  }
21
+ /** Converts an array of rich text nodes to plain text, joining them with newlines. */
33
22
  function richTextNodesToString(nodes) {
34
- return nodes.map(richTextNodeToString).join("\n");
23
+ return nodes.map((node) => richTextNodeToString(node)).join("\n");
35
24
  }
25
+ /** Converts a rich text document to its plain text representation. */
36
26
  function richTextDocumentToString(document) {
37
- return richTextNodesToString(document.content ?? []);
27
+ return richTextNodesToString(document.content ?? []);
38
28
  }
29
+ /** Returns `true` if the document has no content or only whitespace. */
39
30
  function isRichTextDocumentEmpty(document) {
40
- return (document.content ?? []).length === 0 || (document.content ?? []).every((node) => richTextNodeToString(node).trim() === "");
31
+ return (document.content ?? []).length === 0 || (document.content ?? []).every((node) => richTextNodeToString(node).trim() === "");
41
32
  }
33
+ /** Creates a rich text document containing a single paragraph with the given text. */
42
34
  function createRichTextDocumentFromString(text) {
43
- return {
44
- type: "doc",
45
- content: [
46
- {
47
- type: "paragraph",
48
- content: text ? [{ type: "text", text }] : []
49
- }
50
- ]
51
- };
35
+ return {
36
+ type: "doc",
37
+ content: [{
38
+ type: "paragraph",
39
+ content: text ? [{
40
+ type: "text",
41
+ text
42
+ }] : []
43
+ }]
44
+ };
52
45
  }
53
46
  function createEmptyRichTextDocument() {
54
- return {
55
- type: "doc",
56
- content: []
57
- };
47
+ return {
48
+ type: "doc",
49
+ content: []
50
+ };
58
51
  }
52
+ /**
53
+ * Parses a JSON string into a {@link RichTextDocument}.
54
+ * Returns an empty document if parsing fails or the input is nullish.
55
+ */
59
56
  function parseRichTextDocument(text) {
60
- if (!text) {
61
- return createEmptyRichTextDocument();
62
- }
63
- const parsed = JSON.parse(text);
64
- if (parsed.type !== "doc") {
65
- return createEmptyRichTextDocument();
66
- }
67
- return parsed;
57
+ if (!text) return createEmptyRichTextDocument();
58
+ const parsed = JSON.parse(text);
59
+ if (parsed.type !== "doc") return createEmptyRichTextDocument();
60
+ return parsed;
68
61
  }
69
- export {
70
- createRichTextDocumentFromString,
71
- isRichTextDocumentEmpty,
72
- parseRichTextDocument,
73
- richTextDocumentToString,
74
- richTextNodeToString,
75
- richTextNodesToString
76
- };
62
+ //#endregion
63
+ export { createRichTextDocumentFromString, isRichTextDocumentEmpty, parseRichTextDocument, richTextDocumentToString, richTextNodeToString, richTextNodesToString };
64
+
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import type { DeepReadonly, RichTextDocument, RichTextNode } from './types';\n\n/** Converts a single rich text node to its plain text representation. */\nexport function richTextNodeToString(node: DeepReadonly<RichTextNode>): string {\n if (node.type === 'text') {\n return node.text;\n }\n\n switch (node.type) {\n case 'heading':\n case 'paragraph':\n case 'codeBlock':\n case 'blockquote': {\n return (node.content ?? []).map((node) => richTextNodeToString(node)).join('');\n }\n case 'bulletList':\n case 'orderedList': {\n return (node.content ?? []).map((item) => (item.content ?? []).map((node) => richTextNodeToString(node)).join('')).join('');\n }\n case 'listItem': {\n return (node.content ?? []).map((node) => richTextNodeToString(node)).join('');\n }\n case 'horizontalRule': {\n return '---';\n }\n case 'hardBreak': {\n return '\\n';\n }\n case 'table': {\n return (node.content ?? [])\n .map((row) =>\n (row.content ?? []).map((cell) => (cell.content ?? []).map((node) => richTextNodeToString(node)).join('')).join(' | '),\n )\n .join('\\n');\n }\n case 'tableRow': {\n return (node.content ?? []).map((cell) => (cell.content ?? []).map((node) => richTextNodeToString(node)).join('')).join(' | ');\n }\n case 'tableCell': {\n return (node.content ?? []).map((node) => richTextNodeToString(node)).join('');\n }\n case 'tableHeader': {\n return (node.content ?? []).map((node) => richTextNodeToString(node)).join('');\n }\n }\n}\n\n/** Converts an array of rich text nodes to plain text, joining them with newlines. */\nexport function richTextNodesToString(nodes: readonly DeepReadonly<RichTextNode>[]): string {\n return nodes.map((node) => richTextNodeToString(node)).join('\\n');\n}\n\n/** Converts a rich text document to its plain text representation. */\nexport function richTextDocumentToString(document: DeepReadonly<RichTextDocument>): string {\n return richTextNodesToString(document.content ?? []);\n}\n\n/** Returns `true` if the document has no content or only whitespace. */\nexport function isRichTextDocumentEmpty(document: DeepReadonly<RichTextDocument>): boolean {\n return (\n (document.content ?? []).length === 0 ||\n (document.content ?? []).every((node) => richTextNodeToString(node).trim() === '')\n );\n}\n\n/** Creates a rich text document containing a single paragraph with the given text. */\nexport function createRichTextDocumentFromString(text: string | null | undefined): RichTextDocument {\n return {\n type: 'doc',\n content: [\n {\n type: 'paragraph',\n content: text ? [{ type: 'text', text }] : [],\n },\n ],\n };\n}\n\nfunction createEmptyRichTextDocument(): RichTextDocument {\n return {\n type: 'doc',\n content: [],\n };\n}\n\n/**\n * Parses a JSON string into a {@link RichTextDocument}.\n * Returns an empty document if parsing fails or the input is nullish.\n */\nexport function parseRichTextDocument(text: string | null | undefined): RichTextDocument {\n if (!text) {\n return createEmptyRichTextDocument();\n }\n\n const parsed = JSON.parse(text);\n\n if (parsed.type !== 'doc') {\n return createEmptyRichTextDocument();\n }\n\n return parsed;\n}\n"],"mappings":";;AAGA,SAAgB,qBAAqB,MAA0C;CAC7E,IAAI,KAAK,SAAS,QAChB,OAAO,KAAK;CAGd,QAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,cACH,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,SAAS,qBAAqB,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE;EAE/E,KAAK;EACL,KAAK,eACH,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,UAAU,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,SAAS,qBAAqB,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE;EAE5H,KAAK,YACH,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,SAAS,qBAAqB,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE;EAE/E,KAAK,kBACH,OAAO;EAET,KAAK,aACH,OAAO;EAET,KAAK,SACH,QAAQ,KAAK,WAAW,CAAC,EAAA,CACtB,KAAK,SACH,IAAI,WAAW,CAAC,EAAA,CAAG,KAAK,UAAU,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,SAAS,qBAAqB,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,CACvH,CAAC,CACA,KAAK,IAAI;EAEd,KAAK,YACH,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,UAAU,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,SAAS,qBAAqB,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK;EAE/H,KAAK,aACH,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,SAAS,qBAAqB,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE;EAE/E,KAAK,eACH,QAAQ,KAAK,WAAW,CAAC,EAAA,CAAG,KAAK,SAAS,qBAAqB,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE;CAEjF;AACF;;AAGA,SAAgB,sBAAsB,OAAsD;CAC1F,OAAO,MAAM,KAAK,SAAS,qBAAqB,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI;AAClE;;AAGA,SAAgB,yBAAyB,UAAkD;CACzF,OAAO,sBAAsB,SAAS,WAAW,CAAC,CAAC;AACrD;;AAGA,SAAgB,wBAAwB,UAAmD;CACzF,QACG,SAAS,WAAW,CAAC,EAAA,CAAG,WAAW,MACnC,SAAS,WAAW,CAAC,EAAA,CAAG,OAAO,SAAS,qBAAqB,IAAI,CAAC,CAAC,KAAK,MAAM,EAAE;AAErF;;AAGA,SAAgB,iCAAiC,MAAmD;CAClG,OAAO;EACL,MAAM;EACN,SAAS,CACP;GACE,MAAM;GACN,SAAS,OAAO,CAAC;IAAE,MAAM;IAAQ;GAAK,CAAC,IAAI,CAAC;EAC9C,CACF;CACF;AACF;AAEA,SAAS,8BAAgD;CACvD,OAAO;EACL,MAAM;EACN,SAAS,CAAC;CACZ;AACF;;;;;AAMA,SAAgB,sBAAsB,MAAmD;CACvF,IAAI,CAAC,MACH,OAAO,4BAA4B;CAGrC,MAAM,SAAS,KAAK,MAAM,IAAI;CAE9B,IAAI,OAAO,SAAS,OAClB,OAAO,4BAA4B;CAGrC,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contello/rich-text",
3
- "version": "8.21.3",
3
+ "version": "8.22.1",
4
4
  "description": "TypeScript types and helpers for working with Contello CMS rich text documents (TipTap/ProseMirror JSON format)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,12 +10,6 @@
10
10
  "url": "https://github.com/entwico/contello-js",
11
11
  "directory": "packages/rich-text"
12
12
  },
13
- "scripts": {
14
- "build": "tsup",
15
- "lint": "eslint .",
16
- "lint:fix": "eslint . --fix",
17
- "typecheck": "tsc --noEmit"
18
- },
19
13
  "files": [
20
14
  "dist"
21
15
  ],
@@ -29,5 +23,11 @@
29
23
  "publishConfig": {
30
24
  "access": "public",
31
25
  "registry": "https://registry.npmjs.org"
26
+ },
27
+ "scripts": {
28
+ "build": "tsdown",
29
+ "lint": "eslint . --cache",
30
+ "lint:fix": "eslint . --fix",
31
+ "typecheck": "tsc --noEmit"
32
32
  }
33
- }
33
+ }