@contello/rich-text 7.8.2-next.1738683273
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/helpers.d.ts +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +62 -0
- package/dist/index.umd.cjs +3 -0
- package/dist/types.d.ts +107 -0
- package/package.json +38 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RichTextDocument, RichTextNode } from './types';
|
|
2
|
+
export declare function richTextNodeToText(node: RichTextNode): string;
|
|
3
|
+
export declare function richTextDocumentToString(document: RichTextDocument): string;
|
|
4
|
+
export declare function isRichTextDocumentEmpty(document: RichTextDocument): boolean;
|
|
5
|
+
export declare function createRichTextDocumentFromString(text: string): RichTextDocument;
|
|
6
|
+
export declare function parseRichTextDocument(text: string): RichTextDocument;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
function n(t) {
|
|
2
|
+
if (t.type === "text")
|
|
3
|
+
return t.text;
|
|
4
|
+
switch (t.type) {
|
|
5
|
+
case "heading":
|
|
6
|
+
case "paragraph":
|
|
7
|
+
case "codeblock":
|
|
8
|
+
case "blockquote":
|
|
9
|
+
return (t.content ?? []).map(n).join("");
|
|
10
|
+
case "bulletList":
|
|
11
|
+
case "orderedList":
|
|
12
|
+
return (t.content ?? []).map((e) => (e.content ?? []).map(n).join("")).join("");
|
|
13
|
+
case "listItem":
|
|
14
|
+
return (t.content ?? []).map(n).join("");
|
|
15
|
+
case "horizontalRule":
|
|
16
|
+
return "---";
|
|
17
|
+
case "table":
|
|
18
|
+
return (t.content ?? []).map((e) => (e.content ?? []).map((r) => (r.content ?? []).map(n).join("")).join(" | ")).join(`
|
|
19
|
+
`);
|
|
20
|
+
case "tableRow":
|
|
21
|
+
return (t.content ?? []).map((e) => (e.content ?? []).map(n).join("")).join(" | ");
|
|
22
|
+
case "tableCell":
|
|
23
|
+
return (t.content ?? []).map(n).join("");
|
|
24
|
+
case "tableHeader":
|
|
25
|
+
return (t.content ?? []).map(n).join("");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function o(t) {
|
|
29
|
+
return (t.content ?? []).map(n).join(`
|
|
30
|
+
`);
|
|
31
|
+
}
|
|
32
|
+
function a(t) {
|
|
33
|
+
return (t.content ?? []).length === 0 || (t.content ?? []).every((e) => n(e).trim() === "");
|
|
34
|
+
}
|
|
35
|
+
function i(t) {
|
|
36
|
+
return {
|
|
37
|
+
type: "doc",
|
|
38
|
+
content: [{
|
|
39
|
+
type: "paragraph",
|
|
40
|
+
content: t ? [{ type: "text", text: t }] : []
|
|
41
|
+
}]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function c() {
|
|
45
|
+
return {
|
|
46
|
+
type: "doc",
|
|
47
|
+
content: []
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function p(t) {
|
|
51
|
+
if (!t)
|
|
52
|
+
return c();
|
|
53
|
+
const e = JSON.parse(t);
|
|
54
|
+
return e.type !== "doc" ? c() : e;
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
i as createRichTextDocumentFromString,
|
|
58
|
+
a as isRichTextDocumentEmpty,
|
|
59
|
+
p as parseRichTextDocument,
|
|
60
|
+
o as richTextDocumentToString,
|
|
61
|
+
n as richTextNodeToText
|
|
62
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function(n,e){typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(n=typeof globalThis<"u"?globalThis:n||self,e(n.ContelloRichText={}))})(this,function(n){"use strict";function e(t){if(t.type==="text")return t.text;switch(t.type){case"heading":case"paragraph":case"codeblock":case"blockquote":return(t.content??[]).map(e).join("");case"bulletList":case"orderedList":return(t.content??[]).map(c=>(c.content??[]).map(e).join("")).join("");case"listItem":return(t.content??[]).map(e).join("");case"horizontalRule":return"---";case"table":return(t.content??[]).map(c=>(c.content??[]).map(p=>(p.content??[]).map(e).join("")).join(" | ")).join(`
|
|
2
|
+
`);case"tableRow":return(t.content??[]).map(c=>(c.content??[]).map(e).join("")).join(" | ");case"tableCell":return(t.content??[]).map(e).join("");case"tableHeader":return(t.content??[]).map(e).join("")}}function i(t){return(t.content??[]).map(e).join(`
|
|
3
|
+
`)}function r(t){return(t.content??[]).length===0||(t.content??[]).every(c=>e(c).trim()==="")}function a(t){return{type:"doc",content:[{type:"paragraph",content:t?[{type:"text",text:t}]:[]}]}}function o(){return{type:"doc",content:[]}}function u(t){if(!t)return o();const c=JSON.parse(t);return c.type!=="doc"?o():c}n.createRichTextDocumentFromString=a,n.isRichTextDocumentEmpty=r,n.parseRichTextDocument=u,n.richTextDocumentToString=i,n.richTextNodeToText=e,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export type RichTextDocument = {
|
|
2
|
+
type: 'doc';
|
|
3
|
+
content?: Maybe<RichTextNode[]>;
|
|
4
|
+
};
|
|
5
|
+
export type RichTextNode = RichTextHeading | RichTextParagraph | RichTextCodeBlock | RichTextBlockquote | RichTextHorizontalRule | RichTextBulletList | RichTextOrderedList | RichTextListItem | RichTextTable | RichTextTableRow | RichTextTableHeader | RichTextTableCell | RichTextText;
|
|
6
|
+
export 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[]>;
|
|
13
|
+
};
|
|
14
|
+
export type RichTextParagraph = {
|
|
15
|
+
type: 'paragraph';
|
|
16
|
+
attrs?: Maybe<{
|
|
17
|
+
textAlign?: Maybe<RichTextTextAlign>;
|
|
18
|
+
}>;
|
|
19
|
+
content?: Maybe<RichTextNode[]>;
|
|
20
|
+
};
|
|
21
|
+
export type RichTextCodeBlock = {
|
|
22
|
+
type: 'codeblock';
|
|
23
|
+
content?: Maybe<RichTextText[]>;
|
|
24
|
+
};
|
|
25
|
+
export type RichTextBlockquote = {
|
|
26
|
+
type: 'blockquote';
|
|
27
|
+
content?: Maybe<RichTextText[]>;
|
|
28
|
+
};
|
|
29
|
+
export type RichTextBulletList = {
|
|
30
|
+
type: 'bulletList';
|
|
31
|
+
content?: Maybe<RichTextListItem[]>;
|
|
32
|
+
};
|
|
33
|
+
export type RichTextOrderedList = {
|
|
34
|
+
type: 'orderedList';
|
|
35
|
+
attrs?: Maybe<{
|
|
36
|
+
start?: Maybe<number>;
|
|
37
|
+
}>;
|
|
38
|
+
content?: Maybe<RichTextListItem[]>;
|
|
39
|
+
};
|
|
40
|
+
export type RichTextListItem = {
|
|
41
|
+
type: 'listItem';
|
|
42
|
+
content?: Maybe<RichTextNode[]>;
|
|
43
|
+
};
|
|
44
|
+
export type RichTextTable = {
|
|
45
|
+
type: 'table';
|
|
46
|
+
content?: Maybe<RichTextTableRow[]>;
|
|
47
|
+
};
|
|
48
|
+
export type RichTextTableRow = {
|
|
49
|
+
type: 'tableRow';
|
|
50
|
+
content?: Maybe<RichTextTableCell[]>;
|
|
51
|
+
};
|
|
52
|
+
export 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[]>;
|
|
60
|
+
};
|
|
61
|
+
export 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[]>;
|
|
69
|
+
};
|
|
70
|
+
export type RichTextHorizontalRule = {
|
|
71
|
+
type: 'horizontalRule';
|
|
72
|
+
};
|
|
73
|
+
export type RichTextText = {
|
|
74
|
+
type: 'text';
|
|
75
|
+
text: string;
|
|
76
|
+
marks?: Maybe<RichTextMark[]>;
|
|
77
|
+
};
|
|
78
|
+
export type RichTextUnderlineMark = {
|
|
79
|
+
type: 'underline';
|
|
80
|
+
};
|
|
81
|
+
export type RichTextBoldMark = {
|
|
82
|
+
type: 'bold';
|
|
83
|
+
};
|
|
84
|
+
export type RichTextItalicMark = {
|
|
85
|
+
type: 'italic';
|
|
86
|
+
};
|
|
87
|
+
export type RichTextCodeMark = {
|
|
88
|
+
type: 'code';
|
|
89
|
+
};
|
|
90
|
+
export type RichTextStrikeMark = {
|
|
91
|
+
type: 'strike';
|
|
92
|
+
};
|
|
93
|
+
export type RichTextTextStyleMark = {
|
|
94
|
+
type: 'textStyle';
|
|
95
|
+
attrs?: Maybe<{
|
|
96
|
+
color?: Maybe<string>;
|
|
97
|
+
}>;
|
|
98
|
+
};
|
|
99
|
+
export type RichTextLink<T extends Record<string, any> = Record<string, any>> = {
|
|
100
|
+
type: 'link';
|
|
101
|
+
attrs?: Maybe<{
|
|
102
|
+
data?: Maybe<T>;
|
|
103
|
+
}>;
|
|
104
|
+
};
|
|
105
|
+
export type RichTextMark = RichTextUnderlineMark | RichTextBoldMark | RichTextItalicMark | RichTextCodeMark | RichTextStrikeMark | RichTextTextStyleMark | RichTextLink;
|
|
106
|
+
export type RichTextTextAlign = 'left' | 'center' | 'right';
|
|
107
|
+
export type Maybe<T> = T | null | undefined;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contello/rich-text",
|
|
3
|
+
"description": "Contello rich text library",
|
|
4
|
+
"types": "./dist/index.d.ts",
|
|
5
|
+
"author": "admin@entwico.com",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.umd.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"start": "vite build --watch",
|
|
19
|
+
"build": "vite build",
|
|
20
|
+
"clear": "rm -rf dist",
|
|
21
|
+
"patch": "node ci/patcher.js",
|
|
22
|
+
"lint": "eslint src/**/*.ts"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
26
|
+
"@typescript-eslint/parser": "^5.53.0",
|
|
27
|
+
"eslint": "^8.21.0",
|
|
28
|
+
"npm-run-all": "^4.1.5",
|
|
29
|
+
"vite": "^4.1.4",
|
|
30
|
+
"vite-plugin-dts": "^2.0.0-beta.3",
|
|
31
|
+
"typescript": "^4.9.3"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"registry": "https://registry.npmjs.org"
|
|
36
|
+
},
|
|
37
|
+
"version": "7.8.2-next.1738683273"
|
|
38
|
+
}
|