@webiny/lexical-nodes 6.3.0 → 6.4.0-beta.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/FontColorNode.js +94 -119
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.js +160 -183
- package/HeadingNode.js.map +1 -1
- package/ImageNode.js +101 -131
- package/ImageNode.js.map +1 -1
- package/LinkNode.js +228 -315
- package/LinkNode.js.map +1 -1
- package/ListItemNode.js +249 -320
- package/ListItemNode.js.map +1 -1
- package/ListNode.js +174 -223
- package/ListNode.js.map +1 -1
- package/ParagraphNode.js +119 -148
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.js +97 -102
- package/QuoteNode.js.map +1 -1
- package/components/ImageNode/ImageComponent.js +117 -147
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.js +167 -194
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/generateInitialLexicalValue.js +20 -23
- package/generateInitialLexicalValue.js.map +1 -1
- package/index.js +38 -26
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/prepareLexicalState.js +30 -43
- package/prepareLexicalState.js.map +1 -1
- package/types.js +0 -3
- package/utils/clearNodeFormating.js +14 -15
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.js +277 -368
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.js +6 -13
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.js +6 -7
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.js +6 -13
- package/utils/formatToQuote.js.map +1 -1
- package/utils/getStyleId.js +6 -11
- package/utils/getStyleId.js.map +1 -1
- package/utils/listNode.js +60 -84
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.js +67 -118
- package/utils/toggleLink.js.map +1 -1
- package/types.js.map +0 -1
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import {\n type Klass,\n type LexicalNode,\n type LexicalNodeReplacement,\n ParagraphNode as BaseParagraphNode\n} from \"lexical\";\nimport { HeadingNode as BaseHeadingNode, QuoteNode as BaseQuoteNode } from \"@lexical/rich-text\";\nimport { CodeHighlightNode, CodeNode } from \"@lexical/code\";\nimport { HashtagNode } from \"@lexical/hashtag\";\nimport { MarkNode } from \"@lexical/mark\";\nimport { OverflowNode } from \"@lexical/overflow\";\n\nimport { AutoLinkNode, LinkNode } from \"./LinkNode.js\";\nimport { FontColorNode } from \"./FontColorNode.js\";\nimport { ListNode } from \"./ListNode.js\";\nimport { ListItemNode } from \"./ListItemNode.js\";\nimport { HeadingNode } from \"./HeadingNode.js\";\nimport { ParagraphNode } from \"./ParagraphNode.js\";\nimport { QuoteNode } from \"./QuoteNode.js\";\nimport { ImageNode } from \"./ImageNode.js\";\n\nexport * from \"./FontColorNode.js\";\nexport * from \"./ListNode.js\";\nexport * from \"./ListItemNode.js\";\nexport * from \"./HeadingNode.js\";\nexport * from \"./ParagraphNode.js\";\nexport * from \"./QuoteNode.js\";\nexport * from \"./ImageNode.js\";\nexport * from \"./LinkNode.js\";\n\nexport * from \"./utils/formatList.js\";\nexport * from \"./utils/listNode.js\";\nexport * from \"./utils/formatToQuote.js\";\nexport * from \"./utils/formatToHeading.js\";\nexport * from \"./utils/formatToParagraph.js\";\nexport * from \"./utils/clearNodeFormating.js\";\nexport * from \"./utils/toggleLink.js\";\nexport * from \"./prepareLexicalState.js\";\nexport * from \"./generateInitialLexicalValue.js\";\n\n// This is a list of all the nodes that our Lexical implementation supports OOTB.\nexport const allNodes: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement> = [\n ParagraphNode,\n {\n replace: BaseParagraphNode,\n with: () => {\n return new ParagraphNode();\n },\n withKlass: ParagraphNode\n },\n HeadingNode,\n {\n replace: BaseHeadingNode,\n with: (node: BaseHeadingNode) => {\n return new HeadingNode(node.getTag());\n },\n withKlass: HeadingNode\n },\n QuoteNode,\n {\n replace: BaseQuoteNode,\n with: () => {\n return new QuoteNode();\n },\n withKlass: QuoteNode\n },\n ImageNode,\n ListNode,\n ListItemNode,\n CodeNode,\n HashtagNode,\n CodeHighlightNode,\n AutoLinkNode,\n OverflowNode,\n MarkNode,\n FontColorNode,\n QuoteNode,\n LinkNode\n];\n"],"names":["allNodes","ParagraphNode","BaseParagraphNode","HeadingNode","BaseHeadingNode","node","QuoteNode","BaseQuoteNode","ImageNode","ListNode","ListItemNode","CodeNode","HashtagNode","CodeHighlightNode","AutoLinkNode","OverflowNode","MarkNode","FontColorNode","LinkNode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCO,MAAMA,WAAuE;IAChFC;IACA;QACI,SAASC;QACT,MAAM,IACK,IAAID;QAEf,WAAWA;IACf;IACAE;IACA;QACI,SAASC;QACT,MAAM,CAACC,OACI,IAAIF,oCAAYE,KAAK,MAAM;QAEtC,WAAWF;IACf;IACAG;IACA;QACI,SAASC;QACT,MAAM,IACK,IAAID;QAEf,WAAWA;IACf;IACAE;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAX;IACAY;CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/lexical-nodes",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"@lexical/selection": "0.44.0",
|
|
18
18
|
"@lexical/utils": "0.44.0",
|
|
19
19
|
"@types/prismjs": "1.26.6",
|
|
20
|
-
"@webiny/lexical-theme": "6.
|
|
20
|
+
"@webiny/lexical-theme": "6.4.0-beta.1",
|
|
21
21
|
"lexical": "0.44.0",
|
|
22
22
|
"react": "18.3.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@webiny/build-tools": "6.
|
|
25
|
+
"@webiny/build-tools": "6.4.0-beta.1"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
]
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "73237b8243693038c072bae1c0b783387448cbbe"
|
|
39
39
|
}
|
package/prepareLexicalState.js
CHANGED
|
@@ -1,53 +1,40 @@
|
|
|
1
1
|
import { generateInitialLexicalValue } from "./generateInitialLexicalValue.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Remap various node types to their latest form.
|
|
5
|
-
*/
|
|
6
2
|
const nodeTypeMap = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
"webiny-list": "wby-list",
|
|
4
|
+
list: "wby-list",
|
|
5
|
+
"webiny-listitem": "wby-list-item",
|
|
6
|
+
"list-item": "wby-list-item",
|
|
7
|
+
"font-color-node": "wby-font-color",
|
|
8
|
+
"font-color": "wby-font-color",
|
|
9
|
+
"heading-element": "wby-heading",
|
|
10
|
+
heading: "wby-heading",
|
|
11
|
+
"paragraph-element": "wby-paragraph",
|
|
12
|
+
paragraph: "wby-paragraph",
|
|
13
|
+
"webiny-quote": "wby-quote",
|
|
14
|
+
quote: "wby-quote",
|
|
15
|
+
image: "wby-image",
|
|
16
|
+
link: "wby-link"
|
|
21
17
|
};
|
|
22
|
-
|
|
23
|
-
// Migrate old node types
|
|
24
18
|
function deepReplaceType(node) {
|
|
25
|
-
|
|
26
|
-
node.
|
|
27
|
-
}
|
|
28
|
-
if (node.children) {
|
|
29
|
-
node.children.forEach(deepReplaceType);
|
|
30
|
-
}
|
|
19
|
+
if (nodeTypeMap.hasOwnProperty(node.type)) node.type = nodeTypeMap[node.type];
|
|
20
|
+
if (node.children) node.children.forEach(deepReplaceType);
|
|
31
21
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
const prepareLexicalState = (value)=>{
|
|
23
|
+
if (!value) return generateInitialLexicalValue();
|
|
24
|
+
if ("string" == typeof value) try {
|
|
25
|
+
const stateAsObject = JSON.parse(value);
|
|
26
|
+
deepReplaceType(stateAsObject.root);
|
|
27
|
+
return JSON.stringify(stateAsObject);
|
|
28
|
+
} catch {
|
|
29
|
+
return generateInitialLexicalValue();
|
|
30
|
+
}
|
|
37
31
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return generateInitialLexicalValue();
|
|
32
|
+
deepReplaceType(value.root);
|
|
33
|
+
return JSON.stringify(value);
|
|
34
|
+
} catch {
|
|
35
|
+
return generateInitialLexicalValue();
|
|
43
36
|
}
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
deepReplaceType(value.root);
|
|
47
|
-
return JSON.stringify(value);
|
|
48
|
-
} catch {
|
|
49
|
-
return generateInitialLexicalValue();
|
|
50
|
-
}
|
|
51
37
|
};
|
|
38
|
+
export { prepareLexicalState };
|
|
52
39
|
|
|
53
40
|
//# sourceMappingURL=prepareLexicalState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"prepareLexicalState.js","sources":["../src/prepareLexicalState.ts"],"sourcesContent":["import type { SerializedEditorState } from \"lexical\";\nimport { generateInitialLexicalValue } from \"./generateInitialLexicalValue.js\";\n\n/**\n * Remap various node types to their latest form.\n */\nconst nodeTypeMap: Record<string, string> = {\n \"webiny-list\": \"wby-list\",\n list: \"wby-list\",\n \"webiny-listitem\": \"wby-list-item\",\n \"list-item\": \"wby-list-item\",\n \"font-color-node\": \"wby-font-color\",\n \"font-color\": \"wby-font-color\",\n \"heading-element\": \"wby-heading\",\n heading: \"wby-heading\",\n \"paragraph-element\": \"wby-paragraph\",\n paragraph: \"wby-paragraph\",\n \"webiny-quote\": \"wby-quote\",\n quote: \"wby-quote\",\n image: \"wby-image\",\n link: \"wby-link\"\n};\n\n// Migrate old node types\nfunction deepReplaceType(node: any): void {\n if (nodeTypeMap.hasOwnProperty(node.type)) {\n node.type = nodeTypeMap[node.type];\n }\n\n if (node.children) {\n node.children.forEach(deepReplaceType);\n }\n}\n\nexport const prepareLexicalState = (\n value: string | SerializedEditorState | null | undefined\n): string => {\n if (!value) {\n return generateInitialLexicalValue();\n }\n\n if (typeof value === \"string\") {\n try {\n const stateAsObject = JSON.parse(value) as SerializedEditorState;\n deepReplaceType(stateAsObject.root);\n return JSON.stringify(stateAsObject);\n } catch {\n return generateInitialLexicalValue();\n }\n }\n\n try {\n deepReplaceType(value.root);\n return JSON.stringify(value);\n } catch {\n return generateInitialLexicalValue();\n }\n};\n"],"names":["nodeTypeMap","deepReplaceType","node","prepareLexicalState","value","generateInitialLexicalValue","stateAsObject","JSON"],"mappings":";AAMA,MAAMA,cAAsC;IACxC,eAAe;IACf,MAAM;IACN,mBAAmB;IACnB,aAAa;IACb,mBAAmB;IACnB,cAAc;IACd,mBAAmB;IACnB,SAAS;IACT,qBAAqB;IACrB,WAAW;IACX,gBAAgB;IAChB,OAAO;IACP,OAAO;IACP,MAAM;AACV;AAGA,SAASC,gBAAgBC,IAAS;IAC9B,IAAIF,YAAY,cAAc,CAACE,KAAK,IAAI,GACpCA,KAAK,IAAI,GAAGF,WAAW,CAACE,KAAK,IAAI,CAAC;IAGtC,IAAIA,KAAK,QAAQ,EACbA,KAAK,QAAQ,CAAC,OAAO,CAACD;AAE9B;AAEO,MAAME,sBAAsB,CAC/BC;IAEA,IAAI,CAACA,OACD,OAAOC;IAGX,IAAI,AAAiB,YAAjB,OAAOD,OACP,IAAI;QACA,MAAME,gBAAgBC,KAAK,KAAK,CAACH;QACjCH,gBAAgBK,cAAc,IAAI;QAClC,OAAOC,KAAK,SAAS,CAACD;IAC1B,EAAE,OAAM;QACJ,OAAOD;IACX;IAGJ,IAAI;QACAJ,gBAAgBG,MAAM,IAAI;QAC1B,OAAOG,KAAK,SAAS,CAACH;IAC1B,EAAE,OAAM;QACJ,OAAOC;IACX;AACJ"}
|
package/types.js
CHANGED
|
@@ -2,22 +2,21 @@ import { $isRangeSelection, $isTextNode } from "lexical";
|
|
|
2
2
|
import { $selectAll } from "@lexical/selection";
|
|
3
3
|
import { $getNearestBlockElementAncestorOrThrow } from "@lexical/utils";
|
|
4
4
|
import { $isDecoratorBlockNode } from "@lexical/react/LexicalDecoratorBlockNode";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
const clearNodeFormatting = (activeEditor, selection)=>{
|
|
6
|
+
activeEditor.update(()=>{
|
|
7
|
+
if ($isRangeSelection(selection)) {
|
|
8
|
+
$selectAll(selection);
|
|
9
|
+
selection.getNodes().forEach((node)=>{
|
|
10
|
+
if ($isTextNode(node)) {
|
|
11
|
+
node.setFormat(0);
|
|
12
|
+
node.setStyle("");
|
|
13
|
+
$getNearestBlockElementAncestorOrThrow(node).setFormat("");
|
|
14
|
+
}
|
|
15
|
+
if ($isDecoratorBlockNode(node)) node.setFormat("");
|
|
16
|
+
});
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
node.setFormat("");
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
18
|
+
});
|
|
21
19
|
};
|
|
20
|
+
export { clearNodeFormatting };
|
|
22
21
|
|
|
23
22
|
//# sourceMappingURL=clearNodeFormating.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/clearNodeFormating.js","sources":["../../src/utils/clearNodeFormating.ts"],"sourcesContent":["import type { LexicalEditor, RangeSelection } from \"lexical\";\nimport { $isRangeSelection, $isTextNode } from \"lexical\";\nimport { $selectAll } from \"@lexical/selection\";\nimport { $getNearestBlockElementAncestorOrThrow } from \"@lexical/utils\";\nimport { $isDecoratorBlockNode } from \"@lexical/react/LexicalDecoratorBlockNode\";\n\nexport const clearNodeFormatting = (\n activeEditor: LexicalEditor,\n selection: RangeSelection | null\n) => {\n activeEditor.update(() => {\n if ($isRangeSelection(selection)) {\n $selectAll(selection);\n selection.getNodes().forEach(node => {\n if ($isTextNode(node)) {\n node.setFormat(0);\n node.setStyle(\"\");\n $getNearestBlockElementAncestorOrThrow(node).setFormat(\"\");\n }\n if ($isDecoratorBlockNode(node)) {\n node.setFormat(\"\");\n }\n });\n }\n });\n};\n"],"names":["clearNodeFormatting","activeEditor","selection","$isRangeSelection","$selectAll","node","$isTextNode","$getNearestBlockElementAncestorOrThrow","$isDecoratorBlockNode"],"mappings":";;;;AAMO,MAAMA,sBAAsB,CAC/BC,cACAC;IAEAD,aAAa,MAAM,CAAC;QAChB,IAAIE,kBAAkBD,YAAY;YAC9BE,WAAWF;YACXA,UAAU,QAAQ,GAAG,OAAO,CAACG,CAAAA;gBACzB,IAAIC,YAAYD,OAAO;oBACnBA,KAAK,SAAS,CAAC;oBACfA,KAAK,QAAQ,CAAC;oBACdE,uCAAuCF,MAAM,SAAS,CAAC;gBAC3D;gBACA,IAAIG,sBAAsBH,OACtBA,KAAK,SAAS,CAAC;YAEvB;QACJ;IACJ;AACJ"}
|