@payloadcms/richtext-lexical 3.50.0-internal.f87db1c → 3.51.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/client/bundled.css +1 -1
- package/dist/features/migrations/slateToLexical/converter/index.d.ts.map +1 -1
- package/dist/features/migrations/slateToLexical/converter/index.js +37 -24
- package/dist/features/migrations/slateToLexical/converter/index.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/migrations/slateToLexical/converter/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAI/D,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,SAAS,GACV,EAAE;IACD,UAAU,EAAE,kBAAkB,EAAE,CAAA;IAChC,SAAS,EAAE,SAAS,EAAE,CAAA;CACvB,GAAG,qBAAqB,CAgBxB;AAED,wBAAgB,0BAA0B,CAAC,EACzC,oBAAoB,EACpB,UAAU,EACV,cAAc,EACd,UAAU,GACX,EAAE;IACD,oBAAoB,EAAE,OAAO,CAAA;IAC7B,UAAU,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAC5C;;OAEG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,SAAS,EAAE,CAAA;CACxB,GAAG,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/migrations/slateToLexical/converter/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAI/D,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,SAAS,GACV,EAAE;IACD,UAAU,EAAE,kBAAkB,EAAE,CAAA;IAChC,SAAS,EAAE,SAAS,EAAE,CAAA;CACvB,GAAG,qBAAqB,CAgBxB;AAED,wBAAgB,0BAA0B,CAAC,EACzC,oBAAoB,EACpB,UAAU,EACV,cAAc,EACd,UAAU,GACX,EAAE;IACD,oBAAoB,EAAE,OAAO,CAAA;IAC7B,UAAU,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAC5C;;OAEG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,SAAS,EAAE,CAAA;CACxB,GAAG,qBAAqB,EAAE,CAiD1B;AAED,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,kBAAkB,EAAE,EAChC,IAAI,EAAE,SAAS,GACd,uBAAuB,CAgBzB;AACD,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,kBAAkB,CAUnE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAwB3D"}
|
|
@@ -30,36 +30,49 @@ export function convertSlateNodesToLexical({
|
|
|
30
30
|
}
|
|
31
31
|
const unknownConverter = converters.find(converter => converter.nodeTypes.includes('unknown'));
|
|
32
32
|
// @ts-expect-error - vestiges of the migration to strict mode. Probably not important enough in this file to fix
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
return (
|
|
34
|
+
// Flatten in case we unwrap an array of child nodes
|
|
35
|
+
slateNodes.flatMap((slateNode, i) => {
|
|
36
|
+
if (!('type' in slateNode)) {
|
|
37
|
+
if (canContainParagraphs) {
|
|
38
|
+
// This is a paragraph node. They do not have a type property in Slate
|
|
39
|
+
return convertParagraphNode(converters, slateNode);
|
|
40
|
+
} else {
|
|
41
|
+
// Unwrap generic Slate nodes recursively since depth wasn't guaranteed by Slate, especially when copy + pasting rich text
|
|
42
|
+
// - If there are children and it can't be a paragraph in Lexical, assume that the generic node should be unwrapped until the text nodes, and only assume that its a text node when there are no more children
|
|
43
|
+
if (slateNode.children) {
|
|
44
|
+
return convertSlateNodesToLexical({
|
|
45
|
+
canContainParagraphs,
|
|
46
|
+
converters,
|
|
47
|
+
parentNodeType,
|
|
48
|
+
slateNodes: slateNode.children || []
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// This is a simple text node. canContainParagraphs may be false if this is nested inside a paragraph already, since paragraphs cannot contain paragraphs
|
|
52
|
+
return convertTextNode(slateNode);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (slateNode.type === 'p') {
|
|
37
56
|
return convertParagraphNode(converters, slateNode);
|
|
38
|
-
} else {
|
|
39
|
-
// This is a simple text node. canContainParagraphs may be false if this is nested inside a paragraph already, since paragraphs cannot contain paragraphs
|
|
40
|
-
return convertTextNode(slateNode);
|
|
41
57
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
const converter = converters.find(converter => converter.nodeTypes.includes(slateNode.type));
|
|
59
|
+
if (converter) {
|
|
60
|
+
return converter.converter({
|
|
61
|
+
childIndex: i,
|
|
62
|
+
converters,
|
|
63
|
+
parentNodeType,
|
|
64
|
+
slateNode
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
console.warn('slateToLexical > No converter found for node type: ' + slateNode.type);
|
|
68
|
+
return unknownConverter?.converter({
|
|
49
69
|
childIndex: i,
|
|
50
70
|
converters,
|
|
51
71
|
parentNodeType,
|
|
52
72
|
slateNode
|
|
53
73
|
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return unknownConverter?.converter({
|
|
57
|
-
childIndex: i,
|
|
58
|
-
converters,
|
|
59
|
-
parentNodeType,
|
|
60
|
-
slateNode
|
|
61
|
-
});
|
|
62
|
-
}) || [];
|
|
74
|
+
}) || []
|
|
75
|
+
);
|
|
63
76
|
}
|
|
64
77
|
export function convertParagraphNode(converters, node) {
|
|
65
78
|
return {
|
|
@@ -85,7 +98,7 @@ export function convertTextNode(node) {
|
|
|
85
98
|
format: convertNodeToFormat(node),
|
|
86
99
|
mode: 'normal',
|
|
87
100
|
style: '',
|
|
88
|
-
text: node.text,
|
|
101
|
+
text: node.text ?? "",
|
|
89
102
|
version: 1
|
|
90
103
|
};
|
|
91
104
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["NodeFormat","convertSlateToLexical","converters","slateData","root","type","children","convertSlateNodesToLexical","canContainParagraphs","parentNodeType","slateNodes","direction","format","indent","version","length","unknownConverter","find","converter","nodeTypes","includes","
|
|
1
|
+
{"version":3,"file":"index.js","names":["NodeFormat","convertSlateToLexical","converters","slateData","root","type","children","convertSlateNodesToLexical","canContainParagraphs","parentNodeType","slateNodes","direction","format","indent","version","length","unknownConverter","find","converter","nodeTypes","includes","flatMap","slateNode","i","convertParagraphNode","convertTextNode","childIndex","console","warn","node","textFormat","textStyle","detail","convertNodeToFormat","mode","style","text","bold","IS_BOLD","italic","IS_ITALIC","strikethrough","IS_STRIKETHROUGH","underline","IS_UNDERLINE","subscript","IS_SUBSCRIPT","superscript","IS_SUPERSCRIPT","code","IS_CODE"],"sources":["../../../../../src/features/migrations/slateToLexical/converter/index.ts"],"sourcesContent":["import type {\n SerializedEditorState,\n SerializedLexicalNode,\n SerializedParagraphNode,\n SerializedTextNode,\n} from 'lexical'\n\nimport type { SlateNode, SlateNodeConverter } from './types.js'\n\nimport { NodeFormat } from '../../../../lexical/utils/nodeFormat.js'\n\nexport function convertSlateToLexical({\n converters,\n slateData,\n}: {\n converters: SlateNodeConverter[]\n slateData: SlateNode[]\n}): SerializedEditorState {\n return {\n root: {\n type: 'root',\n children: convertSlateNodesToLexical({\n canContainParagraphs: true,\n converters,\n parentNodeType: 'root',\n slateNodes: slateData,\n }),\n direction: 'ltr',\n format: '',\n indent: 0,\n version: 1,\n },\n }\n}\n\nexport function convertSlateNodesToLexical({\n canContainParagraphs,\n converters,\n parentNodeType,\n slateNodes,\n}: {\n canContainParagraphs: boolean\n converters: SlateNodeConverter[] | undefined\n /**\n * Type of the parent lexical node (not the type of the original, parent slate type)\n */\n parentNodeType: string\n slateNodes: SlateNode[]\n}): SerializedLexicalNode[] {\n if (!converters?.length || !slateNodes?.length) {\n return []\n }\n const unknownConverter = converters.find((converter) => converter.nodeTypes.includes('unknown'))\n // @ts-expect-error - vestiges of the migration to strict mode. Probably not important enough in this file to fix\n return (\n // Flatten in case we unwrap an array of child nodes\n slateNodes.flatMap((slateNode, i) => {\n if (!('type' in slateNode)) {\n if (canContainParagraphs) {\n // This is a paragraph node. They do not have a type property in Slate\n return convertParagraphNode(converters, slateNode)\n } else {\n // Unwrap generic Slate nodes recursively since depth wasn't guaranteed by Slate, especially when copy + pasting rich text\n // - If there are children and it can't be a paragraph in Lexical, assume that the generic node should be unwrapped until the text nodes, and only assume that its a text node when there are no more children\n if (slateNode.children) {\n return convertSlateNodesToLexical({\n canContainParagraphs,\n converters,\n parentNodeType,\n slateNodes: slateNode.children || [],\n })\n }\n // This is a simple text node. canContainParagraphs may be false if this is nested inside a paragraph already, since paragraphs cannot contain paragraphs\n return convertTextNode(slateNode)\n }\n }\n if (slateNode.type === 'p') {\n return convertParagraphNode(converters, slateNode)\n }\n\n const converter = converters.find((converter) =>\n converter.nodeTypes.includes(slateNode.type!),\n )\n\n if (converter) {\n return converter.converter({ childIndex: i, converters, parentNodeType, slateNode })\n }\n\n console.warn('slateToLexical > No converter found for node type: ' + slateNode.type)\n return unknownConverter?.converter({\n childIndex: i,\n converters,\n parentNodeType,\n slateNode,\n })\n }) || []\n )\n}\n\nexport function convertParagraphNode(\n converters: SlateNodeConverter[],\n node: SlateNode,\n): SerializedParagraphNode {\n return {\n type: 'paragraph',\n children: convertSlateNodesToLexical({\n canContainParagraphs: false,\n converters,\n parentNodeType: 'paragraph',\n slateNodes: node.children || [],\n }),\n direction: 'ltr',\n format: '',\n indent: 0,\n textFormat: 0,\n textStyle: '',\n version: 1,\n }\n}\nexport function convertTextNode(node: SlateNode): SerializedTextNode {\n return {\n type: 'text',\n detail: 0,\n format: convertNodeToFormat(node),\n mode: 'normal',\n style: '',\n text: node.text ?? \"\",\n version: 1,\n }\n}\n\nexport function convertNodeToFormat(node: SlateNode): number {\n let format = 0\n if (node.bold) {\n format = format | NodeFormat.IS_BOLD\n }\n if (node.italic) {\n format = format | NodeFormat.IS_ITALIC\n }\n if (node.strikethrough) {\n format = format | NodeFormat.IS_STRIKETHROUGH\n }\n if (node.underline) {\n format = format | NodeFormat.IS_UNDERLINE\n }\n if (node.subscript) {\n format = format | NodeFormat.IS_SUBSCRIPT\n }\n if (node.superscript) {\n format = format | NodeFormat.IS_SUPERSCRIPT\n }\n if (node.code) {\n format = format | NodeFormat.IS_CODE\n }\n return format\n}\n"],"mappings":"AASA,SAASA,UAAU,QAAQ;AAE3B,OAAO,SAASC,sBAAsB;EACpCC,UAAU;EACVC;AAAS,CAIV;EACC,OAAO;IACLC,IAAA,EAAM;MACJC,IAAA,EAAM;MACNC,QAAA,EAAUC,0BAAA,CAA2B;QACnCC,oBAAA,EAAsB;QACtBN,UAAA;QACAO,cAAA,EAAgB;QAChBC,UAAA,EAAYP;MACd;MACAQ,SAAA,EAAW;MACXC,MAAA,EAAQ;MACRC,MAAA,EAAQ;MACRC,OAAA,EAAS;IACX;EACF;AACF;AAEA,OAAO,SAASP,2BAA2B;EACzCC,oBAAoB;EACpBN,UAAU;EACVO,cAAc;EACdC;AAAU,CASX;EACC,IAAI,CAACR,UAAA,EAAYa,MAAA,IAAU,CAACL,UAAA,EAAYK,MAAA,EAAQ;IAC9C,OAAO,EAAE;EACX;EACA,MAAMC,gBAAA,GAAmBd,UAAA,CAAWe,IAAI,CAAEC,SAAA,IAAcA,SAAA,CAAUC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