@payloadcms/richtext-lexical 3.80.0-internal.60d6f94 → 3.80.0-internal.82dcece
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/Field-OIMYWB22.js +2 -0
- package/dist/exports/client/Field-OIMYWB22.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-2S5Q7QYO.js +2 -0
- package/dist/exports/client/chunk-2S5Q7QYO.js.map +7 -0
- package/dist/exports/client/chunk-EZX4YW7S.js +12 -0
- package/dist/exports/client/chunk-EZX4YW7S.js.map +7 -0
- package/dist/exports/client/componentInline-NL25DNZ5.js +2 -0
- package/dist/exports/client/index.d.ts +0 -1
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +23 -23
- package/dist/exports/client/index.js.map +3 -3
- package/dist/exports/react/index.d.ts +1 -3
- package/dist/exports/react/index.d.ts.map +1 -1
- package/dist/exports/react/index.js +0 -1
- package/dist/exports/react/index.js.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.d.ts +4 -7
- package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +8 -9
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/index.d.ts +4 -20
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +55 -112
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts +14 -8
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +18 -67
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.d.ts +2 -4
- package/dist/features/blocks/client/nodes/BlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.js +1 -3
- package/dist/features/blocks/client/nodes/BlocksNode.js.map +1 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts +2 -4
- package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js +1 -3
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/heading.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/heading.js +3 -1
- package/dist/features/converters/lexicalToHtml/async/converters/heading.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/link.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/link.js +7 -2
- package/dist/features/converters/lexicalToHtml/async/converters/link.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/list.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/list.js +5 -1
- package/dist/features/converters/lexicalToHtml/async/converters/list.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/table.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/table.js +2 -1
- package/dist/features/converters/lexicalToHtml/async/converters/table.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/text.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/text.js +2 -1
- package/dist/features/converters/lexicalToHtml/async/converters/text.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/upload.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/upload.js +11 -10
- package/dist/features/converters/lexicalToHtml/async/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/shared/cssColors.d.ts +5 -0
- package/dist/features/converters/lexicalToHtml/shared/cssColors.d.ts.map +1 -0
- package/dist/features/converters/lexicalToHtml/shared/cssColors.js +8 -0
- package/dist/features/converters/lexicalToHtml/shared/cssColors.js.map +1 -0
- package/dist/features/converters/lexicalToHtml/sync/converters/heading.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/heading.js +3 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/heading.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/link.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/link.js +7 -2
- package/dist/features/converters/lexicalToHtml/sync/converters/link.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/list.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/list.js +5 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/list.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/table.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/table.js +2 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/table.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/text.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/text.js +2 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/text.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/upload.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/upload.js +11 -10
- package/dist/features/converters/lexicalToHtml/sync/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts +20 -6
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.js +5 -7
- package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.d.ts +2 -17
- package/dist/features/converters/lexicalToJSX/converter/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.js +4 -124
- package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts +10 -14
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.js.map +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
- package/dist/field/Diff/converters/link.d.ts.map +1 -1
- package/dist/field/Diff/converters/link.js +7 -2
- package/dist/field/Diff/converters/link.js.map +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +19 -19
- package/dist/field/Field.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/index.d.ts +0 -1
- package/dist/field/index.d.ts.map +1 -1
- package/dist/field/index.js +35 -64
- package/dist/field/index.js.map +1 -1
- package/dist/field/rscEntry.d.ts +1 -1
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +0 -12
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.d.ts +1 -1
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +9 -7
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts +1 -0
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js +6 -13
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/sanitize.d.ts +1 -1
- package/dist/lexical/config/client/sanitize.d.ts.map +1 -1
- package/dist/lexical/config/client/sanitize.js +2 -3
- package/dist/lexical/config/client/sanitize.js.map +1 -1
- package/dist/lexical/config/types.d.ts +0 -4
- package/dist/lexical/config/types.d.ts.map +1 -1
- package/dist/lexical/config/types.js.map +1 -1
- package/dist/lexical/nodes/index.d.ts +2 -12
- package/dist/lexical/nodes/index.d.ts.map +1 -1
- package/dist/lexical/nodes/index.js +2 -213
- package/dist/lexical/nodes/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.d.ts.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.js +1 -14
- package/dist/lexical/plugins/SlashMenu/index.js.map +1 -1
- package/dist/types.d.ts +2 -329
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/generateImportMap.d.ts.map +1 -1
- package/dist/utilities/generateImportMap.js +0 -1
- package/dist/utilities/generateImportMap.js.map +1 -1
- package/dist/validate/hasText.d.ts +1 -6
- package/dist/validate/hasText.d.ts.map +1 -1
- package/dist/validate/hasText.js +4 -10
- package/dist/validate/hasText.js.map +1 -1
- package/package.json +6 -11
- package/dist/exports/client/Field-ESDONIMD.js +0 -2
- package/dist/exports/client/Field-ESDONIMD.js.map +0 -7
- package/dist/exports/client/chunk-VCJQ5B3S.js +0 -12
- package/dist/exports/client/chunk-VCJQ5B3S.js.map +0 -7
- package/dist/exports/client/chunk-YWIZCGSY.js +0 -2
- package/dist/exports/client/chunk-YWIZCGSY.js.map +0 -7
- package/dist/exports/client/componentInline-CBBUBQ7P.js +0 -2
- package/dist/exports/client/internal-client.d.ts +0 -3
- package/dist/exports/client/internal-client.d.ts.map +0 -1
- package/dist/field/RichTextViewProvider.d.ts +0 -86
- package/dist/field/RichTextViewProvider.d.ts.map +0 -1
- package/dist/field/RichTextViewProvider.js +0 -90
- package/dist/field/RichTextViewProvider.js.map +0 -1
- package/dist/field/ViewSelector.d.ts +0 -4
- package/dist/field/ViewSelector.d.ts.map +0 -1
- package/dist/field/ViewSelector.js +0 -89
- package/dist/field/ViewSelector.js.map +0 -1
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts +0 -2
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts.map +0 -1
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js +0 -48
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +0 -1
- /package/dist/exports/client/{componentInline-CBBUBQ7P.js.map → componentInline-NL25DNZ5.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","names":["v4","uuidv4","ListHTMLConverter","list","node","nodesToHTML","providedStyleTag","children","nodes","join","tag","listType","listitem","parent","providedCSSString","hasSubLists","some","child","type","uuid","checked","value"],"sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/list.ts"],"sourcesContent":["import { v4 as uuidv4 } from 'uuid'\n\nimport type { SerializedListItemNode, SerializedListNode } from '../../../../../nodeTypes.js'\nimport type { HTMLConverters } from '../types.js'\n\nexport const ListHTMLConverter: HTMLConverters<SerializedListItemNode | SerializedListNode> = {\n list: ({ node, nodesToHTML, providedStyleTag }) => {\n const children = nodesToHTML({\n nodes: node.children,\n }).join('')\n\n return `<${
|
|
1
|
+
{"version":3,"file":"list.js","names":["v4","uuidv4","ALLOWED_LIST_TAGS","Set","ALLOWED_LIST_TYPES","ListHTMLConverter","list","node","nodesToHTML","providedStyleTag","children","nodes","join","tag","has","listType","listitem","parent","providedCSSString","hasSubLists","some","child","type","uuid","checked","value"],"sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/list.ts"],"sourcesContent":["import { v4 as uuidv4 } from 'uuid'\n\nimport type { SerializedListItemNode, SerializedListNode } from '../../../../../nodeTypes.js'\nimport type { HTMLConverters } from '../types.js'\n\nconst ALLOWED_LIST_TAGS = new Set(['ol', 'ul'])\nconst ALLOWED_LIST_TYPES = new Set(['bullet', 'check', 'number'])\n\nexport const ListHTMLConverter: HTMLConverters<SerializedListItemNode | SerializedListNode> = {\n list: ({ node, nodesToHTML, providedStyleTag }) => {\n const children = nodesToHTML({\n nodes: node.children,\n }).join('')\n\n const tag = ALLOWED_LIST_TAGS.has(node.tag) ? node.tag : 'ul'\n const listType = ALLOWED_LIST_TYPES.has(node.listType) ? node.listType : 'bullet'\n\n return `<${tag}${providedStyleTag} class=\"list-${listType}\">${children}</${tag}>`\n },\n listitem: ({ node, nodesToHTML, parent, providedCSSString }) => {\n const hasSubLists = node.children.some((child) => child.type === 'list')\n\n const children = nodesToHTML({\n nodes: node.children,\n }).join('')\n\n if ('listType' in parent && parent?.listType === 'check') {\n const uuid = uuidv4()\n return `<li\n aria-checked=\"${node.checked ? 'true' : 'false'}\"\n class=\"list-item-checkbox${node.checked ? ' list-item-checkbox-checked' : ' list-item-checkbox-unchecked'}${hasSubLists ? ' nestedListItem' : ''}\"\n role=\"checkbox\"\n style=\"list-style-type: none;${providedCSSString}\"\n tabIndex=\"-1\"\n value=\"${node.value}\"\n >\n ${\n hasSubLists\n ? children\n : `<input${node.checked ? ' checked' : ''} id=\"${uuid}\" readOnly=\"true\" type=\"checkbox\" />\n <label htmlFor=\"${uuid}\">${children}</label>\n <br />`\n }\n </li>`\n } else {\n return `<li\n class=\"${hasSubLists ? 'nestedListItem' : ''}\"\n style=\"${hasSubLists ? `list-style-type: none;${providedCSSString}` : providedCSSString}\"\n value=\"${node.value}\"\n >${children}</li>`\n }\n },\n}\n"],"mappings":"AAAA,SAASA,EAAA,IAAMC,MAAM,QAAQ;AAK7B,MAAMC,iBAAA,GAAoB,IAAIC,GAAA,CAAI,CAAC,MAAM,KAAK;AAC9C,MAAMC,kBAAA,GAAqB,IAAID,GAAA,CAAI,CAAC,UAAU,SAAS,SAAS;AAEhE,OAAO,MAAME,iBAAA,GAAiF;EAC5FC,IAAA,EAAMA,CAAC;IAAEC,IAAI;IAAEC,WAAW;IAAEC;EAAgB,CAAE;IAC5C,MAAMC,QAAA,GAAWF,WAAA,CAAY;MAC3BG,KAAA,EAAOJ,IAAA,CAAKG;IACd,GAAGE,IAAI,CAAC;IAER,MAAMC,GAAA,GAAMX,iBAAA,CAAkBY,GAAG,CAACP,IAAA,CAAKM,GAAG,IAAIN,IAAA,CAAKM,GAAG,GAAG;IACzD,MAAME,QAAA,GAAWX,kBAAA,CAAmBU,GAAG,CAACP,IAAA,CAAKQ,QAAQ,IAAIR,IAAA,CAAKQ,QAAQ,GAAG;IAEzE,OAAO,IAAIF,GAAA,GAAMJ,gBAAA,gBAAgCM,QAAA,KAAaL,QAAA,KAAaG,GAAA,GAAM;EACnF;EACAG,QAAA,EAAUA,CAAC;IAAET,IAAI;IAAEC,WAAW;IAAES,MAAM;IAAEC;EAAiB,CAAE;IACzD,MAAMC,WAAA,GAAcZ,IAAA,CAAKG,QAAQ,CAACU,IAAI,CAAEC,KAAA,IAAUA,KAAA,CAAMC,IAAI,KAAK;IAEjE,MAAMZ,QAAA,GAAWF,WAAA,CAAY;MAC3BG,KAAA,EAAOJ,IAAA,CAAKG;IACd,GAAGE,IAAI,CAAC;IAER,IAAI,cAAcK,MAAA,IAAUA,MAAA,EAAQF,QAAA,KAAa,SAAS;MACxD,MAAMQ,IAAA,GAAOtB,MAAA;MACb,OAAO;0BACaM,IAAA,CAAKiB,OAAO,GAAG,SAAS;qCACbjB,IAAA,CAAKiB,OAAO,GAAG,gCAAgC,kCAAkCL,WAAA,GAAc,oBAAoB;;yCAE/GD,iBAAA;;mBAEtBX,IAAA,CAAKkB,KAAK;;YAGjBN,WAAA,GACIT,QAAA,GACA,SAASH,IAAA,CAAKiB,OAAO,GAAG,aAAa,UAAUD,IAAA;8BACjCA,IAAA,KAASb,QAAA;mBACpB;cAEL;IACV,OAAO;MACL,OAAO;mBACMS,WAAA,GAAc,mBAAmB;mBACjCA,WAAA,GAAc,yBAAyBD,iBAAA,EAAmB,GAAGA,iBAAA;mBAC7DX,IAAA,CAAKkB,KAAK;WAClBf,QAAA,OAAe;IACtB;EACF;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAC7C,uBAAuB,GAAG,mBAAmB,GAAG,sBAAsB,CAkDvE,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSafeCssColor } from '../../shared/cssColors.js';
|
|
1
2
|
export const TableHTMLConverter = {
|
|
2
3
|
table: ({
|
|
3
4
|
node,
|
|
@@ -24,7 +25,7 @@ export const TableHTMLConverter = {
|
|
|
24
25
|
const TagName = node.headerState > 0 ? 'th' : 'td';
|
|
25
26
|
const headerStateClass = `lexical-table-cell-header-${node.headerState}`;
|
|
26
27
|
let style = 'border: 1px solid #ccc; padding: 8px;' + providedCSSString;
|
|
27
|
-
if (node.backgroundColor) {
|
|
28
|
+
if (node.backgroundColor && isSafeCssColor(node.backgroundColor)) {
|
|
28
29
|
style += ` background-color: ${node.backgroundColor};`;
|
|
29
30
|
}
|
|
30
31
|
const colSpanAttr = node.colSpan && node.colSpan > 1 ? ` colspan="${node.colSpan}"` : '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.js","names":["TableHTMLConverter","table","node","nodesToHTML","providedStyleTag","children","nodes","join","tablecell","providedCSSString","TagName","headerState","headerStateClass","style","backgroundColor","colSpanAttr","colSpan","rowSpanAttr","rowSpan","tablerow"],"sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/table.ts"],"sourcesContent":["import type {\n SerializedTableCellNode,\n SerializedTableNode,\n SerializedTableRowNode,\n} from '../../../../../nodeTypes.js'\nimport type { HTMLConverters } from '../types.js'\n\nexport const TableHTMLConverter: HTMLConverters<\n SerializedTableCellNode | SerializedTableNode | SerializedTableRowNode\n> = {\n table: ({ node, nodesToHTML, providedStyleTag }) => {\n const children = nodesToHTML({\n nodes: node.children,\n }).join('')\n\n return `<div${providedStyleTag} class=\"lexical-table-container\">\n <table class=\"lexical-table\" style=\"border-collapse: collapse;\">\n <tbody>${children}</tbody>\n </table>\n </div>`\n },\n\n tablecell: ({ node, nodesToHTML, providedCSSString }) => {\n const children = nodesToHTML({\n nodes: node.children,\n }).join('')\n\n const TagName = node.headerState > 0 ? 'th' : 'td'\n const headerStateClass = `lexical-table-cell-header-${node.headerState}`\n\n let style = 'border: 1px solid #ccc; padding: 8px;' + providedCSSString\n if (node.backgroundColor) {\n style += ` background-color: ${node.backgroundColor};`\n }\n\n const colSpanAttr = node.colSpan && node.colSpan > 1 ? ` colspan=\"${node.colSpan}\"` : ''\n const rowSpanAttr = node.rowSpan && node.rowSpan > 1 ? ` rowspan=\"${node.rowSpan}\"` : ''\n\n return `<${TagName}\n class=\"lexical-table-cell ${headerStateClass}\"\n ${colSpanAttr}\n ${rowSpanAttr}\n style=\"${style}\"\n >\n ${children}\n </${TagName}>\n `\n },\n\n tablerow: ({ node, nodesToHTML, providedStyleTag }) => {\n const children = nodesToHTML({\n nodes: node.children,\n }).join('')\n\n return `<tr${providedStyleTag} class=\"lexical-table-row\">\n ${children}\n </tr>`\n },\n}\n"],"mappings":"AAOA,OAAO,
|
|
1
|
+
{"version":3,"file":"table.js","names":["isSafeCssColor","TableHTMLConverter","table","node","nodesToHTML","providedStyleTag","children","nodes","join","tablecell","providedCSSString","TagName","headerState","headerStateClass","style","backgroundColor","colSpanAttr","colSpan","rowSpanAttr","rowSpan","tablerow"],"sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/table.ts"],"sourcesContent":["import type {\n SerializedTableCellNode,\n SerializedTableNode,\n SerializedTableRowNode,\n} from '../../../../../nodeTypes.js'\nimport type { HTMLConverters } from '../types.js'\n\nimport { isSafeCssColor } from '../../shared/cssColors.js'\n\nexport const TableHTMLConverter: HTMLConverters<\n SerializedTableCellNode | SerializedTableNode | SerializedTableRowNode\n> = {\n table: ({ node, nodesToHTML, providedStyleTag }) => {\n const children = nodesToHTML({\n nodes: node.children,\n }).join('')\n\n return `<div${providedStyleTag} class=\"lexical-table-container\">\n <table class=\"lexical-table\" style=\"border-collapse: collapse;\">\n <tbody>${children}</tbody>\n </table>\n </div>`\n },\n\n tablecell: ({ node, nodesToHTML, providedCSSString }) => {\n const children = nodesToHTML({\n nodes: node.children,\n }).join('')\n\n const TagName = node.headerState > 0 ? 'th' : 'td'\n const headerStateClass = `lexical-table-cell-header-${node.headerState}`\n\n let style = 'border: 1px solid #ccc; padding: 8px;' + providedCSSString\n if (node.backgroundColor && isSafeCssColor(node.backgroundColor)) {\n style += ` background-color: ${node.backgroundColor};`\n }\n\n const colSpanAttr = node.colSpan && node.colSpan > 1 ? ` colspan=\"${node.colSpan}\"` : ''\n const rowSpanAttr = node.rowSpan && node.rowSpan > 1 ? ` rowspan=\"${node.rowSpan}\"` : ''\n\n return `<${TagName}\n class=\"lexical-table-cell ${headerStateClass}\"\n ${colSpanAttr}\n ${rowSpanAttr}\n style=\"${style}\"\n >\n ${children}\n </${TagName}>\n `\n },\n\n tablerow: ({ node, nodesToHTML, providedStyleTag }) => {\n const children = nodesToHTML({\n nodes: node.children,\n }).join('')\n\n return `<tr${providedStyleTag} class=\"lexical-table-row\">\n ${children}\n </tr>`\n },\n}\n"],"mappings":"AAOA,SAASA,cAAc,QAAQ;AAE/B,OAAO,MAAMC,kBAAA,GAET;EACFC,KAAA,EAAOA,CAAC;IAAEC,IAAI;IAAEC,WAAW;IAAEC;EAAgB,CAAE;IAC7C,MAAMC,QAAA,GAAWF,WAAA,CAAY;MAC3BG,KAAA,EAAOJ,IAAA,CAAKG;IACd,GAAGE,IAAI,CAAC;IAER,OAAO,OAAOH,gBAAA;;mBAECC,QAAA;;aAEN;EACX;EAEAG,SAAA,EAAWA,CAAC;IAAEN,IAAI;IAAEC,WAAW;IAAEM;EAAiB,CAAE;IAClD,MAAMJ,QAAA,GAAWF,WAAA,CAAY;MAC3BG,KAAA,EAAOJ,IAAA,CAAKG;IACd,GAAGE,IAAI,CAAC;IAER,MAAMG,OAAA,GAAUR,IAAA,CAAKS,WAAW,GAAG,IAAI,OAAO;IAC9C,MAAMC,gBAAA,GAAmB,6BAA6BV,IAAA,CAAKS,WAAW,EAAE;IAExE,IAAIE,KAAA,GAAQ,0CAA0CJ,iBAAA;IACtD,IAAIP,IAAA,CAAKY,eAAe,IAAIf,cAAA,CAAeG,IAAA,CAAKY,eAAe,GAAG;MAChED,KAAA,IAAS,sBAAsBX,IAAA,CAAKY,eAAe,GAAG;IACxD;IAEA,MAAMC,WAAA,GAAcb,IAAA,CAAKc,OAAO,IAAId,IAAA,CAAKc,OAAO,GAAG,IAAI,aAAad,IAAA,CAAKc,OAAO,GAAG,GAAG;IACtF,MAAMC,WAAA,GAAcf,IAAA,CAAKgB,OAAO,IAAIhB,IAAA,CAAKgB,OAAO,GAAG,IAAI,aAAahB,IAAA,CAAKgB,OAAO,GAAG,GAAG;IAEtF,OAAO,IAAIR,OAAA;oCACqBE,gBAAA;UAC1BG,WAAA;UACAE,WAAA;iBACOJ,KAAA;;UAEPR,QAAA;UACAK,OAAA;KACL;EACH;EAEAS,QAAA,EAAUA,CAAC;IAAEjB,IAAI;IAAEC,WAAW;IAAEC;EAAgB,CAAE;IAChD,MAAMC,QAAA,GAAWF,WAAA,CAAY;MAC3BG,KAAA,EAAOJ,IAAA,CAAKG;IACd,GAAGE,IAAI,CAAC;IAER,OAAO,MAAMH,gBAAA;UACPC,QAAA;YACE;EACV;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/text.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/text.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,eAAO,MAAM,iBAAiB,EAAE,cAAc,CAAC,kBAAkB,CA4BhE,CAAA"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import escapeHTML from 'escape-html';
|
|
1
2
|
import { NodeFormat } from '../../../../../lexical/utils/nodeFormat.js';
|
|
2
3
|
export const TextHTMLConverter = {
|
|
3
4
|
text: ({
|
|
4
5
|
node
|
|
5
6
|
}) => {
|
|
6
|
-
let text = node.text;
|
|
7
|
+
let text = escapeHTML(node.text);
|
|
7
8
|
if (node.format & NodeFormat.IS_BOLD) {
|
|
8
9
|
text = `<strong>${text}</strong>`;
|
|
9
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":["NodeFormat","TextHTMLConverter","text","node","format","IS_BOLD","IS_ITALIC","IS_STRIKETHROUGH","IS_UNDERLINE","IS_CODE","IS_SUBSCRIPT","IS_SUPERSCRIPT"],"sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/text.ts"],"sourcesContent":["import type { SerializedTextNode } from '../../../../../nodeTypes.js'\nimport type { HTMLConverters } from '../types.js'\n\nimport { NodeFormat } from '../../../../../lexical/utils/nodeFormat.js'\n\nexport const TextHTMLConverter: HTMLConverters<SerializedTextNode> = {\n text: ({ node }) => {\n let text = node.text\n\n if (node.format & NodeFormat.IS_BOLD) {\n text = `<strong>${text}</strong>`\n }\n if (node.format & NodeFormat.IS_ITALIC) {\n text = `<em>${text}</em>`\n }\n if (node.format & NodeFormat.IS_STRIKETHROUGH) {\n text = `<span style=\"text-decoration: line-through;\">${text}</span>`\n }\n if (node.format & NodeFormat.IS_UNDERLINE) {\n text = `<span style=\"text-decoration: underline;\">${text}</span>`\n }\n if (node.format & NodeFormat.IS_CODE) {\n text = `<code>${text}</code>`\n }\n if (node.format & NodeFormat.IS_SUBSCRIPT) {\n text = `<sub>${text}</sub>`\n }\n if (node.format & NodeFormat.IS_SUPERSCRIPT) {\n text = `<sup>${text}</sup>`\n }\n\n return text\n },\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"text.js","names":["escapeHTML","NodeFormat","TextHTMLConverter","text","node","format","IS_BOLD","IS_ITALIC","IS_STRIKETHROUGH","IS_UNDERLINE","IS_CODE","IS_SUBSCRIPT","IS_SUPERSCRIPT"],"sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/text.ts"],"sourcesContent":["import escapeHTML from 'escape-html'\n\nimport type { SerializedTextNode } from '../../../../../nodeTypes.js'\nimport type { HTMLConverters } from '../types.js'\n\nimport { NodeFormat } from '../../../../../lexical/utils/nodeFormat.js'\n\nexport const TextHTMLConverter: HTMLConverters<SerializedTextNode> = {\n text: ({ node }) => {\n let text = escapeHTML(node.text)\n\n if (node.format & NodeFormat.IS_BOLD) {\n text = `<strong>${text}</strong>`\n }\n if (node.format & NodeFormat.IS_ITALIC) {\n text = `<em>${text}</em>`\n }\n if (node.format & NodeFormat.IS_STRIKETHROUGH) {\n text = `<span style=\"text-decoration: line-through;\">${text}</span>`\n }\n if (node.format & NodeFormat.IS_UNDERLINE) {\n text = `<span style=\"text-decoration: underline;\">${text}</span>`\n }\n if (node.format & NodeFormat.IS_CODE) {\n text = `<code>${text}</code>`\n }\n if (node.format & NodeFormat.IS_SUBSCRIPT) {\n text = `<sub>${text}</sub>`\n }\n if (node.format & NodeFormat.IS_SUPERSCRIPT) {\n text = `<sup>${text}</sup>`\n }\n\n return text\n },\n}\n"],"mappings":"AAAA,OAAOA,UAAA,MAAgB;AAKvB,SAASC,UAAU,QAAQ;AAE3B,OAAO,MAAMC,iBAAA,GAAwD;EACnEC,IAAA,EAAMA,CAAC;IAAEC;EAAI,CAAE;IACb,IAAID,IAAA,GAAOH,UAAA,CAAWI,IAAA,CAAKD,IAAI;IAE/B,IAAIC,IAAA,CAAKC,MAAM,GAAGJ,UAAA,CAAWK,OAAO,EAAE;MACpCH,IAAA,GAAO,WAAWA,IAAA,WAAe;IACnC;IACA,IAAIC,IAAA,CAAKC,MAAM,GAAGJ,UAAA,CAAWM,SAAS,EAAE;MACtCJ,IAAA,GAAO,OAAOA,IAAA,OAAW;IAC3B;IACA,IAAIC,IAAA,CAAKC,MAAM,GAAGJ,UAAA,CAAWO,gBAAgB,EAAE;MAC7CL,IAAA,GAAO,gDAAgDA,IAAA,SAAa;IACtE;IACA,IAAIC,IAAA,CAAKC,MAAM,GAAGJ,UAAA,CAAWQ,YAAY,EAAE;MACzCN,IAAA,GAAO,6CAA6CA,IAAA,SAAa;IACnE;IACA,IAAIC,IAAA,CAAKC,MAAM,GAAGJ,UAAA,CAAWS,OAAO,EAAE;MACpCP,IAAA,GAAO,SAASA,IAAA,SAAa;IAC/B;IACA,IAAIC,IAAA,CAAKC,MAAM,GAAGJ,UAAA,CAAWU,YAAY,EAAE;MACzCR,IAAA,GAAO,QAAQA,IAAA,QAAY;IAC7B;IACA,IAAIC,IAAA,CAAKC,MAAM,GAAGJ,UAAA,CAAWW,cAAc,EAAE;MAC3CT,IAAA,GAAO,QAAQA,IAAA,QAAY;IAC7B;IAEA,OAAOA,IAAA;EACT;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/upload.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,mBAAmB,EAAE,cAAc,CAAC,oBAAoB,CA8EpE,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import escapeHTML from 'escape-html';
|
|
1
2
|
export const UploadHTMLConverter = {
|
|
2
3
|
upload: ({
|
|
3
4
|
node,
|
|
@@ -14,20 +15,20 @@ export const UploadHTMLConverter = {
|
|
|
14
15
|
if (!uploadDoc) {
|
|
15
16
|
return '';
|
|
16
17
|
}
|
|
17
|
-
const alt = node.fields?.alt || uploadDoc?.alt || '';
|
|
18
|
-
const url = uploadDoc.url;
|
|
18
|
+
const alt = escapeHTML(node.fields?.alt || uploadDoc?.alt || '');
|
|
19
|
+
const url = escapeHTML(uploadDoc.url ?? '');
|
|
19
20
|
// 1) If upload is NOT an image, return a link
|
|
20
21
|
if (!uploadDoc.mimeType.startsWith('image')) {
|
|
21
|
-
return `<a${providedStyleTag} href="${url}" rel="noopener noreferrer">${uploadDoc.filename}</a
|
|
22
|
+
return `<a${providedStyleTag} href="${url}" rel="noopener noreferrer">${escapeHTML(uploadDoc.filename ?? '')}</a>`;
|
|
22
23
|
}
|
|
23
24
|
// 2) If image has no different sizes, return a simple <img />
|
|
24
25
|
if (!uploadDoc.sizes || !Object.keys(uploadDoc.sizes).length) {
|
|
25
26
|
return `
|
|
26
27
|
<img${providedStyleTag}
|
|
27
28
|
alt="${alt}"
|
|
28
|
-
height="${uploadDoc.height}"
|
|
29
|
+
height="${escapeHTML(String(uploadDoc.height ?? ''))}"
|
|
29
30
|
src="${url}"
|
|
30
|
-
width="${uploadDoc.width}"
|
|
31
|
+
width="${escapeHTML(String(uploadDoc.width ?? ''))}"
|
|
31
32
|
/>
|
|
32
33
|
`;
|
|
33
34
|
}
|
|
@@ -40,18 +41,18 @@ export const UploadHTMLConverter = {
|
|
|
40
41
|
}
|
|
41
42
|
pictureHTML += `
|
|
42
43
|
<source
|
|
43
|
-
media="(max-width: ${imageSize.width}px)"
|
|
44
|
-
srcset="${imageSize.url}"
|
|
45
|
-
type="${imageSize.mimeType}"
|
|
44
|
+
media="(max-width: ${escapeHTML(String(imageSize.width))}px)"
|
|
45
|
+
srcset="${escapeHTML(imageSize.url)}"
|
|
46
|
+
type="${escapeHTML(imageSize.mimeType)}"
|
|
46
47
|
/>
|
|
47
48
|
`;
|
|
48
49
|
}
|
|
49
50
|
pictureHTML += `
|
|
50
51
|
<img
|
|
51
52
|
alt="${alt}"
|
|
52
|
-
height="${uploadDoc.height}"
|
|
53
|
+
height="${escapeHTML(String(uploadDoc.height ?? ''))}"
|
|
53
54
|
src="${url}"
|
|
54
|
-
width="${uploadDoc.width}"
|
|
55
|
+
width="${escapeHTML(String(uploadDoc.width ?? ''))}"
|
|
55
56
|
/>
|
|
56
57
|
`;
|
|
57
58
|
return `<picture${providedStyleTag}>${pictureHTML}</picture>`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","names":["UploadHTMLConverter","upload","node","providedStyleTag","uploadNode","uploadDoc","undefined","value","alt","fields","url","mimeType","startsWith","filename","sizes","Object","keys","length","height","width","pictureHTML","size","imageSize","filesize"],"sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/upload.ts"],"sourcesContent":["import type { FileData, FileSizeImproved, TypeWithID } from 'payload'\n\nimport type { SerializedUploadNode } from '../../../../../nodeTypes.js'\nimport type { UploadDataImproved } from '../../../../upload/server/nodes/UploadNode.js'\nimport type { HTMLConverters } from '../types.js'\n\nexport const UploadHTMLConverter: HTMLConverters<SerializedUploadNode> = {\n upload: ({ node, providedStyleTag }) => {\n const uploadNode = node as UploadDataImproved\n\n let uploadDoc: (FileData & TypeWithID) | undefined = undefined\n\n // If there's no valid upload data, populate return an empty string\n if (typeof uploadNode.value !== 'object') {\n return ''\n } else {\n uploadDoc = uploadNode.value as unknown as FileData & TypeWithID\n }\n\n if (!uploadDoc) {\n return ''\n }\n\n const alt = (node.fields?.alt as string) || (uploadDoc as { alt?: string })?.alt || ''\n\n const url = uploadDoc.url\n\n // 1) If upload is NOT an image, return a link\n if (!uploadDoc.mimeType.startsWith('image')) {\n return `<a${providedStyleTag} href=\"${url}\" rel=\"noopener noreferrer\">${uploadDoc.filename}</a
|
|
1
|
+
{"version":3,"file":"upload.js","names":["escapeHTML","UploadHTMLConverter","upload","node","providedStyleTag","uploadNode","uploadDoc","undefined","value","alt","fields","url","mimeType","startsWith","filename","sizes","Object","keys","length","String","height","width","pictureHTML","size","imageSize","filesize"],"sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/upload.ts"],"sourcesContent":["import type { FileData, FileSizeImproved, TypeWithID } from 'payload'\n\nimport escapeHTML from 'escape-html'\n\nimport type { SerializedUploadNode } from '../../../../../nodeTypes.js'\nimport type { UploadDataImproved } from '../../../../upload/server/nodes/UploadNode.js'\nimport type { HTMLConverters } from '../types.js'\n\nexport const UploadHTMLConverter: HTMLConverters<SerializedUploadNode> = {\n upload: ({ node, providedStyleTag }) => {\n const uploadNode = node as UploadDataImproved\n\n let uploadDoc: (FileData & TypeWithID) | undefined = undefined\n\n // If there's no valid upload data, populate return an empty string\n if (typeof uploadNode.value !== 'object') {\n return ''\n } else {\n uploadDoc = uploadNode.value as unknown as FileData & TypeWithID\n }\n\n if (!uploadDoc) {\n return ''\n }\n\n const alt = escapeHTML(\n (node.fields?.alt as string) || (uploadDoc as { alt?: string })?.alt || '',\n )\n\n const url = escapeHTML(uploadDoc.url ?? '')\n\n // 1) If upload is NOT an image, return a link\n if (!uploadDoc.mimeType.startsWith('image')) {\n return `<a${providedStyleTag} href=\"${url}\" rel=\"noopener noreferrer\">${escapeHTML(uploadDoc.filename ?? '')}</a>`\n }\n\n // 2) If image has no different sizes, return a simple <img />\n if (!uploadDoc.sizes || !Object.keys(uploadDoc.sizes).length) {\n return `\n <img${providedStyleTag}\n alt=\"${alt}\"\n height=\"${escapeHTML(String(uploadDoc.height ?? ''))}\"\n src=\"${url}\"\n width=\"${escapeHTML(String(uploadDoc.width ?? ''))}\"\n />\n `\n }\n\n // 3) If image has different sizes, build a <picture> element with <source> tags\n let pictureHTML = ''\n\n for (const size in uploadDoc.sizes) {\n const imageSize = uploadDoc.sizes[size] as FileSizeImproved\n\n if (\n !imageSize ||\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n\n pictureHTML += `\n <source\n media=\"(max-width: ${escapeHTML(String(imageSize.width))}px)\"\n srcset=\"${escapeHTML(imageSize.url)}\"\n type=\"${escapeHTML(imageSize.mimeType)}\"\n />\n `\n }\n\n pictureHTML += `\n <img\n alt=\"${alt}\"\n height=\"${escapeHTML(String(uploadDoc.height ?? ''))}\"\n src=\"${url}\"\n width=\"${escapeHTML(String(uploadDoc.width ?? ''))}\"\n />\n `\n\n return `<picture${providedStyleTag}>${pictureHTML}</picture>`\n },\n}\n"],"mappings":"AAEA,OAAOA,UAAA,MAAgB;AAMvB,OAAO,MAAMC,mBAAA,GAA4D;EACvEC,MAAA,EAAQA,CAAC;IAAEC,IAAI;IAAEC;EAAgB,CAAE;IACjC,MAAMC,UAAA,GAAaF,IAAA;IAEnB,IAAIG,SAAA,GAAiDC,SAAA;IAErD;IACA,IAAI,OAAOF,UAAA,CAAWG,KAAK,KAAK,UAAU;MACxC,OAAO;IACT,OAAO;MACLF,SAAA,GAAYD,UAAA,CAAWG,KAAK;IAC9B;IAEA,IAAI,CAACF,SAAA,EAAW;MACd,OAAO;IACT;IAEA,MAAMG,GAAA,GAAMT,UAAA,CACVG,IAAC,CAAKO,MAAM,EAAED,GAAA,IAAmBH,SAAA,EAAgCG,GAAA,IAAO;IAG1E,MAAME,GAAA,GAAMX,UAAA,CAAWM,SAAA,CAAUK,GAAG,IAAI;IAExC;IACA,IAAI,CAACL,SAAA,CAAUM,QAAQ,CAACC,UAAU,CAAC,UAAU;MAC3C,OAAO,KAAKT,gBAAA,UAA0BO,GAAA,+BAAkCX,UAAA,CAAWM,SAAA,CAAUQ,QAAQ,IAAI,SAAS;IACpH;IAEA;IACA,IAAI,CAACR,SAAA,CAAUS,KAAK,IAAI,CAACC,MAAA,CAAOC,IAAI,CAACX,SAAA,CAAUS,KAAK,EAAEG,MAAM,EAAE;MAC5D,OAAO;cACCd,gBAAA;iBACGK,GAAA;oBACGT,UAAA,CAAWmB,MAAA,CAAOb,SAAA,CAAUc,MAAM,IAAI;iBACzCT,GAAA;mBACEX,UAAA,CAAWmB,MAAA,CAAOb,SAAA,CAAUe,KAAK,IAAI;;OAEjD;IACH;IAEA;IACA,IAAIC,WAAA,GAAc;IAElB,KAAK,MAAMC,IAAA,IAAQjB,SAAA,CAAUS,KAAK,EAAE;MAClC,MAAMS,SAAA,GAAYlB,SAAA,CAAUS,KAAK,CAACQ,IAAA,CAAK;MAEvC,IACE,CAACC,SAAA,IACD,CAACA,SAAA,CAAUH,KAAK,IAChB,CAACG,SAAA,CAAUJ,MAAM,IACjB,CAACI,SAAA,CAAUZ,QAAQ,IACnB,CAACY,SAAA,CAAUC,QAAQ,IACnB,CAACD,SAAA,CAAUV,QAAQ,IACnB,CAACU,SAAA,CAAUb,GAAG,EACd;QACA;MACF;MAEAW,WAAA,IAAe;;+BAEUtB,UAAA,CAAWmB,MAAA,CAAOK,SAAA,CAAUH,KAAK;oBAC5CrB,UAAA,CAAWwB,SAAA,CAAUb,GAAG;kBAC1BX,UAAA,CAAWwB,SAAA,CAAUZ,QAAQ;;OAExC;IACH;IAEAU,WAAA,IAAe;;eAEJb,GAAA;kBACGT,UAAA,CAAWmB,MAAA,CAAOb,SAAA,CAAUc,MAAM,IAAI;eACzCT,GAAA;iBACEX,UAAA,CAAWmB,MAAA,CAAOb,SAAA,CAAUe,KAAK,IAAI;;KAEjD;IAED,OAAO,WAAWjB,gBAAA,IAAoBkB,WAAA,YAAuB;EAC/D;AACF","ignoreList":[]}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
import type { SerializedEditorState } from 'lexical';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import type { DefaultNodeTypes, SerializedBlockNode, SerializedInlineBlockNode } from '../../../../nodeTypes.js';
|
|
3
|
-
import type { SerializedNodeBase } from '../../../../types.js';
|
|
4
4
|
import type { JSXConverters } from '../converter/types.js';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export type JSXConvertersFunction<T extends {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
type?: string;
|
|
8
|
+
} = DefaultNodeTypes | SerializedBlockNode<{
|
|
7
9
|
blockName?: null | string;
|
|
8
10
|
}> | SerializedInlineBlockNode<{
|
|
9
11
|
blockName?: null | string;
|
|
10
12
|
}>> = (args: {
|
|
11
13
|
defaultConverters: JSXConverters<DefaultNodeTypes>;
|
|
12
14
|
}) => JSXConverters<T>;
|
|
13
|
-
type RichTextProps
|
|
15
|
+
type RichTextProps = {
|
|
14
16
|
/**
|
|
15
17
|
* Override class names for the container.
|
|
16
18
|
*/
|
|
@@ -19,11 +21,23 @@ type RichTextProps<TNodes extends SerializedNodeBase = SerializedNodeBase> = {
|
|
|
19
21
|
* Custom converters to transform your nodes to JSX. Can be an object or a function that receives the default converters.
|
|
20
22
|
*/
|
|
21
23
|
converters?: JSXConverters | JSXConvertersFunction;
|
|
24
|
+
/**
|
|
25
|
+
* Serialized editor state to render.
|
|
26
|
+
*/
|
|
27
|
+
data: SerializedEditorState;
|
|
22
28
|
/**
|
|
23
29
|
* If true, removes the container div wrapper.
|
|
24
30
|
*/
|
|
25
31
|
disableContainer?: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
/**
|
|
33
|
+
* If true, disables indentation globally. If an array, disables for specific node `type` values.
|
|
34
|
+
*/
|
|
35
|
+
disableIndent?: boolean | string[];
|
|
36
|
+
/**
|
|
37
|
+
* If true, disables text alignment globally. If an array, disables for specific node `type` values.
|
|
38
|
+
*/
|
|
39
|
+
disableTextAlign?: boolean | string[];
|
|
40
|
+
};
|
|
41
|
+
export declare const RichText: React.FC<RichTextProps>;
|
|
28
42
|
export {};
|
|
29
43
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/lexicalToJSX/Component/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/lexicalToJSX/Component/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAK1D,MAAM,MAAM,qBAAqB,CAC/B,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,gBAAgB,GAChB,mBAAmB,CAAC;IAAE,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CAAC,GAClD,yBAAyB,CAAC;IAAE,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CAAC,IAC1D,CAAC,IAAI,EAAE;IAAE,iBAAiB,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAA;CAAE,KAAK,aAAa,CAAC,CAAC,CAAC,CAAA;AAEtF,KAAK,aAAa,GAAG;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,aAAa,GAAG,qBAAqB,CAAA;IAClD;;OAEG;IACH,IAAI,EAAE,qBAAqB,CAAA;IAC3B;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;IAClC;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;CACtC,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAwC5C,CAAA"}
|
|
@@ -2,15 +2,14 @@ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { defaultJSXConverters } from '../converter/defaultConverters.js';
|
|
4
4
|
import { convertLexicalToJSX } from '../converter/index.js';
|
|
5
|
-
export
|
|
5
|
+
export const RichText = ({
|
|
6
6
|
className,
|
|
7
7
|
converters,
|
|
8
8
|
data: editorState,
|
|
9
9
|
disableContainer,
|
|
10
10
|
disableIndent,
|
|
11
|
-
disableTextAlign
|
|
12
|
-
|
|
13
|
-
}) {
|
|
11
|
+
disableTextAlign
|
|
12
|
+
}) => {
|
|
14
13
|
if (!editorState) {
|
|
15
14
|
return null;
|
|
16
15
|
}
|
|
@@ -30,8 +29,7 @@ export function RichText({
|
|
|
30
29
|
converters: finalConverters,
|
|
31
30
|
data: editorState,
|
|
32
31
|
disableIndent,
|
|
33
|
-
disableTextAlign
|
|
34
|
-
nodeMap
|
|
32
|
+
disableTextAlign
|
|
35
33
|
});
|
|
36
34
|
if (disableContainer) {
|
|
37
35
|
return /*#__PURE__*/_jsx(_Fragment, {
|
|
@@ -42,5 +40,5 @@ export function RichText({
|
|
|
42
40
|
className: className ?? 'payload-richtext',
|
|
43
41
|
children: content
|
|
44
42
|
});
|
|
45
|
-
}
|
|
43
|
+
};
|
|
46
44
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","defaultJSXConverters","convertLexicalToJSX","RichText","className","converters","data","editorState","disableContainer","disableIndent","disableTextAlign","
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","defaultJSXConverters","convertLexicalToJSX","RichText","className","converters","data","editorState","disableContainer","disableIndent","disableTextAlign","finalConverters","defaultConverters","content","Array","isArray","_jsx","_Fragment"],"sources":["../../../../../src/features/converters/lexicalToJSX/Component/index.tsx"],"sourcesContent":["import type { SerializedEditorState } from 'lexical'\n\nimport React from 'react'\n\nimport type {\n DefaultNodeTypes,\n SerializedBlockNode,\n SerializedInlineBlockNode,\n} from '../../../../nodeTypes.js'\nimport type { JSXConverters } from '../converter/types.js'\n\nimport { defaultJSXConverters } from '../converter/defaultConverters.js'\nimport { convertLexicalToJSX } from '../converter/index.js'\n\nexport type JSXConvertersFunction<\n T extends { [key: string]: any; type?: string } =\n | DefaultNodeTypes\n | SerializedBlockNode<{ blockName?: null | string }>\n | SerializedInlineBlockNode<{ blockName?: null | string }>,\n> = (args: { defaultConverters: JSXConverters<DefaultNodeTypes> }) => JSXConverters<T>\n\ntype RichTextProps = {\n /**\n * Override class names for the container.\n */\n className?: string\n /**\n * Custom converters to transform your nodes to JSX. Can be an object or a function that receives the default converters.\n */\n converters?: JSXConverters | JSXConvertersFunction\n /**\n * Serialized editor state to render.\n */\n data: SerializedEditorState\n /**\n * If true, removes the container div wrapper.\n */\n disableContainer?: boolean\n /**\n * If true, disables indentation globally. If an array, disables for specific node `type` values.\n */\n disableIndent?: boolean | string[]\n /**\n * If true, disables text alignment globally. If an array, disables for specific node `type` values.\n */\n disableTextAlign?: boolean | string[]\n}\n\nexport const RichText: React.FC<RichTextProps> = ({\n className,\n converters,\n data: editorState,\n disableContainer,\n disableIndent,\n disableTextAlign,\n}) => {\n if (!editorState) {\n return null\n }\n\n let finalConverters: JSXConverters = {}\n if (converters) {\n if (typeof converters === 'function') {\n finalConverters = converters({ defaultConverters: defaultJSXConverters })\n } else {\n finalConverters = converters\n }\n } else {\n finalConverters = defaultJSXConverters\n }\n\n const content =\n editorState &&\n !Array.isArray(editorState) &&\n typeof editorState === 'object' &&\n 'root' in editorState &&\n convertLexicalToJSX({\n converters: finalConverters,\n data: editorState,\n disableIndent,\n disableTextAlign,\n })\n\n if (disableContainer) {\n return <>{content}</>\n }\n\n return <div className={className ?? 'payload-richtext'}>{content}</div>\n}\n"],"mappings":";AAEA,OAAOA,KAAA,MAAW;AASlB,SAASC,oBAAoB,QAAQ;AACrC,SAASC,mBAAmB,QAAQ;AAoCpC,OAAO,MAAMC,QAAA,GAAoCA,CAAC;EAChDC,SAAS;EACTC,UAAU;EACVC,IAAA,EAAMC,WAAW;EACjBC,gBAAgB;EAChBC,aAAa;EACbC;AAAgB,CACjB;EACC,IAAI,CAACH,WAAA,EAAa;IAChB,OAAO;EACT;EAEA,IAAII,eAAA,GAAiC,CAAC;EACtC,IAAIN,UAAA,EAAY;IACd,IAAI,OAAOA,UAAA,KAAe,YAAY;MACpCM,eAAA,GAAkBN,UAAA,CAAW;QAAEO,iBAAA,EAAmBX;MAAqB;IACzE,OAAO;MACLU,eAAA,GAAkBN,UAAA;IACpB;EACF,OAAO;IACLM,eAAA,GAAkBV,oBAAA;EACpB;EAEA,MAAMY,OAAA,GACJN,WAAA,IACA,CAACO,KAAA,CAAMC,OAAO,CAACR,WAAA,KACf,OAAOA,WAAA,KAAgB,YACvB,UAAUA,WAAA,IACVL,mBAAA,CAAoB;IAClBG,UAAA,EAAYM,eAAA;IACZL,IAAA,EAAMC,WAAA;IACNE,aAAA;IACAC;EACF;EAEF,IAAIF,gBAAA,EAAkB;IACpB,oBAAOQ,IAAA,CAAAC,SAAA;gBAAGJ;;EACZ;EAEA,oBAAOG,IAAA,CAAC;IAAIZ,SAAA,EAAWA,SAAA,IAAa;cAAqBS;;AAC3D","ignoreList":[]}
|
|
@@ -1,28 +1,13 @@
|
|
|
1
1
|
import type { SerializedEditorState, SerializedLexicalNode } from 'lexical';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import type { LexicalEditorNodeMap, SerializedNodeBase } from '../../../../types.js';
|
|
4
3
|
import type { JSXConverters, SerializedLexicalNodeWithParent } from './types.js';
|
|
5
|
-
export type ConvertLexicalToJSXArgs
|
|
4
|
+
export type ConvertLexicalToJSXArgs = {
|
|
6
5
|
converters: JSXConverters;
|
|
7
|
-
/**
|
|
8
|
-
* Serialized editor state to render.
|
|
9
|
-
*/
|
|
10
6
|
data: SerializedEditorState;
|
|
11
|
-
/**
|
|
12
|
-
* If true, disables indentation globally. If an array, disables for specific node `type` values.
|
|
13
|
-
*/
|
|
14
7
|
disableIndent?: boolean | string[];
|
|
15
|
-
/**
|
|
16
|
-
* If true, disables text alignment globally. If an array, disables for specific node `type` values.
|
|
17
|
-
*/
|
|
18
8
|
disableTextAlign?: boolean | string[];
|
|
19
|
-
/**
|
|
20
|
-
* You can use the lexical editor node map or view map as converters. NodeMap converters will override converters passed
|
|
21
|
-
* in the `converters` prop. If a LexicalEditorViewMap is provided, the `default` view will be used.
|
|
22
|
-
*/
|
|
23
|
-
nodeMap?: LexicalEditorNodeMap<TNodes>;
|
|
24
9
|
};
|
|
25
|
-
export declare function convertLexicalToJSX
|
|
10
|
+
export declare function convertLexicalToJSX({ converters, data, disableIndent, disableTextAlign, }: ConvertLexicalToJSXArgs): React.ReactNode;
|
|
26
11
|
export declare function convertLexicalNodesToJSX({ converters, disableIndent, disableTextAlign, nodes, parent, }: {
|
|
27
12
|
converters: JSXConverters;
|
|
28
13
|
disableIndent?: boolean | string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/lexicalToJSX/converter/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAE3E,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/lexicalToJSX/converter/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAE3E,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,EAAgB,aAAa,EAAE,+BAA+B,EAAE,MAAM,YAAY,CAAA;AAI9F,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,aAAa,CAAA;IACzB,IAAI,EAAE,qBAAqB,CAAA;IAC3B,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;IAClC,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;CACtC,CAAA;AAED,wBAAgB,mBAAmB,CAAC,EAClC,UAAU,EACV,IAAI,EACJ,aAAa,EACb,gBAAgB,GACjB,EAAE,uBAAuB,GAAG,KAAK,CAAC,SAAS,CAW3C;AAED,wBAAgB,wBAAwB,CAAC,EACvC,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,MAAM,GACP,EAAE;IACD,UAAU,EAAE,aAAa,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;IAClC,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;IACrC,KAAK,EAAE,qBAAqB,EAAE,CAAA;IAC9B,MAAM,EAAE,+BAA+B,CAAA;CACxC,GAAG,KAAK,CAAC,SAAS,EAAE,CAmIpB"}
|
|
@@ -1,139 +1,19 @@
|
|
|
1
1
|
/* eslint-disable no-console */import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { hasText } from '../../../../validate/hasText.js';
|
|
4
|
-
/**
|
|
5
|
-
* Creates a JSX converter from a NodeMapValue
|
|
6
|
-
*/
|
|
7
|
-
function createConverterFromNodeMapValue(viewDef) {
|
|
8
|
-
return args => {
|
|
9
|
-
const converterArgs = {
|
|
10
|
-
...args,
|
|
11
|
-
isEditor: false,
|
|
12
|
-
isJSXConverter: true
|
|
13
|
-
};
|
|
14
|
-
// If Component is provided, use it
|
|
15
|
-
if (viewDef.Component) {
|
|
16
|
-
return viewDef.Component(converterArgs);
|
|
17
|
-
}
|
|
18
|
-
// If html is provided (as a function or string), use it
|
|
19
|
-
// Note: Using span instead of div to avoid forcing block-level semantics
|
|
20
|
-
if (viewDef.html) {
|
|
21
|
-
const htmlContent = typeof viewDef.html === 'function' ? viewDef.html(converterArgs) : viewDef.html;
|
|
22
|
-
return /*#__PURE__*/_jsx("span", {
|
|
23
|
-
dangerouslySetInnerHTML: {
|
|
24
|
-
__html: htmlContent
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Creates a JSX converter from a NodeMapBlockValue (for blocks/inlineBlocks)
|
|
33
|
-
* This also checks for Block FC as a fallback when Component is not defined.
|
|
34
|
-
*/
|
|
35
|
-
function createConverterFromBlockValue(viewDef) {
|
|
36
|
-
return args => {
|
|
37
|
-
// Priority: Component > Block > html
|
|
38
|
-
if (viewDef.Component) {
|
|
39
|
-
const converterArgs = {
|
|
40
|
-
...args,
|
|
41
|
-
isEditor: false,
|
|
42
|
-
isJSXConverter: true
|
|
43
|
-
};
|
|
44
|
-
return viewDef.Component(converterArgs);
|
|
45
|
-
}
|
|
46
|
-
// Use Block FC with JSX converter props
|
|
47
|
-
if (viewDef.Block) {
|
|
48
|
-
const blockNode = args.node;
|
|
49
|
-
const blockProps = {
|
|
50
|
-
childIndex: args.childIndex,
|
|
51
|
-
converters: args.converters,
|
|
52
|
-
formData: blockNode.fields ?? {},
|
|
53
|
-
isEditor: false,
|
|
54
|
-
isJSXConverter: true,
|
|
55
|
-
node: blockNode,
|
|
56
|
-
nodesToJSX: args.nodesToJSX,
|
|
57
|
-
parent: args.parent
|
|
58
|
-
};
|
|
59
|
-
return /*#__PURE__*/React.createElement(viewDef.Block, blockProps);
|
|
60
|
-
}
|
|
61
|
-
if (viewDef.html) {
|
|
62
|
-
const converterArgs = {
|
|
63
|
-
...args,
|
|
64
|
-
isEditor: false,
|
|
65
|
-
isJSXConverter: true
|
|
66
|
-
};
|
|
67
|
-
const htmlContent = typeof viewDef.html === 'function' ? viewDef.html(converterArgs) : viewDef.html;
|
|
68
|
-
return /*#__PURE__*/_jsx("span", {
|
|
69
|
-
dangerouslySetInnerHTML: {
|
|
70
|
-
__html: htmlContent
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Converts a LexicalEditorNodeMap into JSXConverters
|
|
79
|
-
*/
|
|
80
|
-
function nodeMapToConverters(nodeMap) {
|
|
81
|
-
const converters = {};
|
|
82
|
-
for (const [nodeType, value] of Object.entries(nodeMap)) {
|
|
83
|
-
if (!value || typeof value !== 'object') {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
// Handle special keys: blocks, inlineBlocks
|
|
87
|
-
if (nodeType === 'blocks') {
|
|
88
|
-
converters.blocks = {};
|
|
89
|
-
for (const [blockType, _viewDef] of Object.entries(value)) {
|
|
90
|
-
const viewDef = _viewDef;
|
|
91
|
-
// Check for Component, Block, or html
|
|
92
|
-
if (viewDef.Component || viewDef.Block || viewDef.html) {
|
|
93
|
-
converters.blocks[blockType] = createConverterFromBlockValue(viewDef);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (nodeType === 'inlineBlocks') {
|
|
99
|
-
converters.inlineBlocks = {};
|
|
100
|
-
for (const [blockType, _viewDef] of Object.entries(value)) {
|
|
101
|
-
const viewDef = _viewDef;
|
|
102
|
-
// Check for Component, Block, or html
|
|
103
|
-
if (viewDef.Component || viewDef.Block || viewDef.html) {
|
|
104
|
-
converters.inlineBlocks[blockType] = createConverterFromBlockValue(viewDef);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
// Handle regular node types
|
|
110
|
-
const viewDef = value;
|
|
111
|
-
if (viewDef.Component || viewDef.html) {
|
|
112
|
-
converters[nodeType] = createConverterFromNodeMapValue(viewDef);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return converters;
|
|
116
|
-
}
|
|
117
4
|
export function convertLexicalToJSX({
|
|
118
5
|
converters,
|
|
119
6
|
data,
|
|
120
7
|
disableIndent,
|
|
121
|
-
disableTextAlign
|
|
122
|
-
nodeMap
|
|
8
|
+
disableTextAlign
|
|
123
9
|
}) {
|
|
124
10
|
if (hasText(data)) {
|
|
125
|
-
// Merge nodeMap converters with existing converters
|
|
126
|
-
// NodeMap converters override existing converters
|
|
127
|
-
const mergedConverters = nodeMap ? {
|
|
128
|
-
...converters,
|
|
129
|
-
...nodeMapToConverters(nodeMap)
|
|
130
|
-
} : converters;
|
|
131
11
|
return convertLexicalNodesToJSX({
|
|
132
|
-
converters
|
|
12
|
+
converters,
|
|
133
13
|
disableIndent,
|
|
134
14
|
disableTextAlign,
|
|
135
|
-
nodes: data
|
|
136
|
-
parent: data
|
|
15
|
+
nodes: data?.root?.children,
|
|
16
|
+
parent: data?.root
|
|
137
17
|
});
|
|
138
18
|
}
|
|
139
19
|
return /*#__PURE__*/_jsx(_Fragment, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["jsx","_jsx","Fragment","_Fragment","React","hasText","createConverterFromNodeMapValue","viewDef","args","converterArgs","isEditor","isJSXConverter","Component","html","htmlContent","dangerouslySetInnerHTML","__html","createConverterFromBlockValue","Block","blockNode","node","blockProps","childIndex","converters","formData","fields","nodesToJSX","parent","createElement","nodeMapToConverters","nodeMap","nodeType","value","Object","entries","blocks","blockType","_viewDef","inlineBlocks","convertLexicalToJSX","data","disableIndent","disableTextAlign","mergedConverters","convertLexicalNodesToJSX","nodes","root","children","unknownConverter","unknown","jsxArray","map","i","converterForNode","type","console","error","reactNode","converted","style","Array","isArray","includes","format","textAlign","indent","paddingInlineStart","Number","isValidElement","newStyle","props","cloneElement","key","filter","Boolean"],"sources":["../../../../../src/features/converters/lexicalToJSX/converter/index.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport type { SerializedEditorState, SerializedLexicalNode } from 'lexical'\n\nimport React from 'react'\n\nimport type { SerializedBlockNode, SerializedInlineBlockNode } from '../../../../nodeTypes.js'\nimport type {\n LexicalEditorNodeMap,\n NodeMapBlockValue,\n NodeMapValue,\n SerializedNodeBase,\n ViewMapBlockJSXConverterProps,\n} from '../../../../types.js'\nimport type { JSXConverter, JSXConverters, SerializedLexicalNodeWithParent } from './types.js'\n\nimport { hasText } from '../../../../validate/hasText.js'\n\n/**\n * Creates a JSX converter from a NodeMapValue\n */\nfunction createConverterFromNodeMapValue(viewDef: NodeMapValue): JSXConverter {\n return (args) => {\n const converterArgs = {\n ...args,\n isEditor: false as const,\n isJSXConverter: true as const,\n }\n\n // If Component is provided, use it\n if (viewDef.Component) {\n return viewDef.Component(converterArgs)\n }\n\n // If html is provided (as a function or string), use it\n // Note: Using span instead of div to avoid forcing block-level semantics\n if (viewDef.html) {\n const htmlContent =\n typeof viewDef.html === 'function' ? viewDef.html(converterArgs) : viewDef.html\n\n return <span dangerouslySetInnerHTML={{ __html: htmlContent }} />\n }\n\n return null\n }\n}\n\n/**\n * Creates a JSX converter from a NodeMapBlockValue (for blocks/inlineBlocks)\n * This also checks for Block FC as a fallback when Component is not defined.\n */\nfunction createConverterFromBlockValue(viewDef: NodeMapBlockValue<any>): JSXConverter {\n return (args) => {\n // Priority: Component > Block > html\n if (viewDef.Component) {\n const converterArgs = {\n ...args,\n isEditor: false as const,\n isJSXConverter: true as const,\n }\n return viewDef.Component(converterArgs)\n }\n\n // Use Block FC with JSX converter props\n if (viewDef.Block) {\n const blockNode = args.node as SerializedBlockNode\n const blockProps: ViewMapBlockJSXConverterProps<any> = {\n childIndex: args.childIndex,\n converters: args.converters,\n formData: blockNode.fields ?? {},\n isEditor: false,\n isJSXConverter: true,\n node: blockNode,\n nodesToJSX: args.nodesToJSX,\n parent: args.parent,\n }\n return React.createElement(viewDef.Block, blockProps)\n }\n\n if (viewDef.html) {\n const converterArgs = {\n ...args,\n isEditor: false as const,\n isJSXConverter: true as const,\n }\n const htmlContent =\n typeof viewDef.html === 'function' ? viewDef.html(converterArgs) : viewDef.html\n\n return <span dangerouslySetInnerHTML={{ __html: htmlContent }} />\n }\n\n return null\n }\n}\n\n/**\n * Converts a LexicalEditorNodeMap into JSXConverters\n */\nfunction nodeMapToConverters<TNodes extends SerializedNodeBase = SerializedNodeBase>(\n nodeMap: LexicalEditorNodeMap<TNodes>,\n): JSXConverters {\n const converters: JSXConverters = {}\n\n for (const [nodeType, value] of Object.entries(nodeMap)) {\n if (!value || typeof value !== 'object') {\n continue\n }\n\n // Handle special keys: blocks, inlineBlocks\n if (nodeType === 'blocks') {\n converters.blocks = {}\n for (const [blockType, _viewDef] of Object.entries(value)) {\n const viewDef = _viewDef as NodeMapBlockValue<any>\n // Check for Component, Block, or html\n if (viewDef.Component || viewDef.Block || viewDef.html) {\n converters.blocks[blockType] = createConverterFromBlockValue(viewDef)\n }\n }\n continue\n }\n\n if (nodeType === 'inlineBlocks') {\n converters.inlineBlocks = {}\n for (const [blockType, _viewDef] of Object.entries(value)) {\n const viewDef = _viewDef as NodeMapBlockValue<any>\n // Check for Component, Block, or html\n if (viewDef.Component || viewDef.Block || viewDef.html) {\n converters.inlineBlocks[blockType] = createConverterFromBlockValue(viewDef)\n }\n }\n continue\n }\n\n // Handle regular node types\n const viewDef = value as NodeMapValue\n\n if (viewDef.Component || viewDef.html) {\n converters[nodeType] = createConverterFromNodeMapValue(viewDef)\n }\n }\n\n return converters\n}\n\nexport type ConvertLexicalToJSXArgs<TNodes extends SerializedNodeBase = SerializedNodeBase> = {\n converters: JSXConverters\n /**\n * Serialized editor state to render.\n */\n data: SerializedEditorState\n /**\n * If true, disables indentation globally. If an array, disables for specific node `type` values.\n */\n disableIndent?: boolean | string[]\n /**\n * If true, disables text alignment globally. If an array, disables for specific node `type` values.\n */\n disableTextAlign?: boolean | string[]\n /**\n * You can use the lexical editor node map or view map as converters. NodeMap converters will override converters passed\n * in the `converters` prop. If a LexicalEditorViewMap is provided, the `default` view will be used.\n */\n nodeMap?: LexicalEditorNodeMap<TNodes>\n}\n\nexport function convertLexicalToJSX<TNodes extends SerializedNodeBase = SerializedNodeBase>({\n converters,\n data,\n disableIndent,\n disableTextAlign,\n nodeMap,\n}: ConvertLexicalToJSXArgs<TNodes>): React.ReactNode {\n if (hasText(data)) {\n // Merge nodeMap converters with existing converters\n // NodeMap converters override existing converters\n const mergedConverters = nodeMap\n ? {\n ...converters,\n ...nodeMapToConverters(nodeMap),\n }\n : converters\n\n return convertLexicalNodesToJSX({\n converters: mergedConverters,\n disableIndent,\n disableTextAlign,\n nodes: data.root.children,\n parent: data.root,\n })\n }\n return <></>\n}\n\nexport function convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes,\n parent,\n}: {\n converters: JSXConverters\n disableIndent?: boolean | string[]\n disableTextAlign?: boolean | string[]\n nodes: SerializedLexicalNode[]\n parent: SerializedLexicalNodeWithParent\n}): React.ReactNode[] {\n const unknownConverter: JSXConverter<any> = converters.unknown as JSXConverter<any>\n\n const jsxArray: React.ReactNode[] = nodes.map((node, i) => {\n let converterForNode: JSXConverter<any> | undefined\n if (node.type === 'block') {\n converterForNode = converters?.blocks?.[(node as SerializedBlockNode)?.fields?.blockType]\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Blocks converter: found ${(node as SerializedBlockNode)?.fields?.blockType} block, but no converter is provided`,\n )\n }\n } else if (node.type === 'inlineBlock') {\n converterForNode =\n converters?.inlineBlocks?.[(node as SerializedInlineBlockNode)?.fields?.blockType]\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Inline Blocks converter: found ${(node as SerializedInlineBlockNode)?.fields?.blockType} inline block, but no converter is provided`,\n )\n }\n } else {\n converterForNode = converters[node.type] as JSXConverter<any>\n }\n\n try {\n if (!converterForNode && unknownConverter) {\n converterForNode = unknownConverter\n }\n\n let reactNode: React.ReactNode\n if (converterForNode) {\n const converted =\n typeof converterForNode === 'function'\n ? converterForNode({\n childIndex: i,\n converters,\n node,\n nodesToJSX: (args) => {\n return convertLexicalNodesToJSX({\n converters: args.converters ?? converters,\n disableIndent: args.disableIndent ?? disableIndent,\n disableTextAlign: args.disableTextAlign ?? disableTextAlign,\n nodes: args.nodes,\n parent: args.parent ?? {\n ...node,\n parent,\n },\n })\n },\n parent,\n })\n : converterForNode\n reactNode = converted\n } else {\n reactNode = <span key={i}>unknown node</span>\n }\n\n const style: React.CSSProperties = {}\n\n // Check if disableTextAlign is not true and does not include node type\n if (\n !disableTextAlign &&\n (!Array.isArray(disableTextAlign) || !disableTextAlign?.includes(node.type))\n ) {\n if ('format' in node && node.format) {\n switch (node.format) {\n case 'center':\n style.textAlign = 'center'\n break\n case 'end':\n style.textAlign = 'right'\n break\n case 'justify':\n style.textAlign = 'justify'\n break\n case 'left':\n //style.textAlign = 'left'\n // Do nothing, as left is the default\n break\n case 'right':\n style.textAlign = 'right'\n break\n case 'start':\n style.textAlign = 'left'\n break\n }\n }\n }\n\n if (\n !disableIndent &&\n (!Array.isArray(disableIndent) || !disableIndent?.includes(node.type))\n ) {\n if ('indent' in node && node.indent && node.type !== 'listitem') {\n // the unit should be px. Do not change it to rem, em, or something else.\n // The quantity should be 40px. Do not change it either.\n // See rationale in\n // https://github.com/payloadcms/payload/issues/13130#issuecomment-3058348085\n style.paddingInlineStart = `${Number(node.indent) * 40}px`\n }\n }\n\n if (React.isValidElement(reactNode)) {\n // Inject style into reactNode\n if (style.textAlign || style.paddingInlineStart) {\n const newStyle = {\n ...style,\n // @ts-expect-error type better later\n ...(reactNode?.props?.style ?? {}),\n // reactNode style comes after, thus a textAlign specified in the converter has priority over the one we inject here\n }\n\n return React.cloneElement(reactNode, {\n key: i,\n // @ts-expect-error type better later\n style: newStyle,\n })\n }\n return React.cloneElement(reactNode, {\n key: i,\n })\n }\n\n return reactNode\n } catch (error) {\n console.error('Error converting lexical node to JSX:', error, 'node:', node)\n return null\n }\n })\n\n return jsxArray.filter(Boolean)\n}\n"],"mappings":"AAAA,+BAA6B,SAAAA,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA;AAG7B,OAAOC,KAAA,MAAW;AAYlB,SAASC,OAAO,QAAQ;AAExB;;;AAGA,SAASC,gCAAgCC,OAAqB;EAC5D,OAAQC,IAAA;IACN,MAAMC,aAAA,GAAgB;MACpB,GAAGD,IAAI;MACPE,QAAA,EAAU;MACVC,cAAA,EAAgB;IAClB;IAEA;IACA,IAAIJ,OAAA,CAAQK,SAAS,EAAE;MACrB,OAAOL,OAAA,CAAQK,SAAS,CAACH,aAAA;IAC3B;IAEA;IACA;IACA,IAAIF,OAAA,CAAQM,IAAI,EAAE;MAChB,MAAMC,WAAA,GACJ,OAAOP,OAAA,CAAQM,IAAI,KAAK,aAAaN,OAAA,CAAQM,IAAI,CAACJ,aAAA,IAAiBF,OAAA,CAAQM,IAAI;MAEjF,oBAAOZ,IAAA,CAAC;QAAKc,uBAAA,EAAyB;UAAEC,MAAA,EAAQF;QAAY;;IAC9D;IAEA,OAAO;EACT;AACF;AAEA;;;;AAIA,SAASG,8BAA8BV,OAA+B;EACpE,OAAQC,IAAA;IACN;IACA,IAAID,OAAA,CAAQK,SAAS,EAAE;MACrB,MAAMH,aAAA,GAAgB;QACpB,GAAGD,IAAI;QACPE,QAAA,EAAU;QACVC,cAAA,EAAgB;MAClB;MACA,OAAOJ,OAAA,CAAQK,SAAS,CAACH,aAAA;IAC3B;IAEA;IACA,IAAIF,OAAA,CAAQW,KAAK,EAAE;MACjB,MAAMC,SAAA,GAAYX,IAAA,CAAKY,IAAI;MAC3B,MAAMC,UAAA,GAAiD;QACrDC,UAAA,EAAYd,IAAA,CAAKc,UAAU;QAC3BC,UAAA,EAAYf,IAAA,CAAKe,UAAU;QAC3BC,QAAA,EAAUL,SAAA,CAAUM,MAAM,IAAI,CAAC;QAC/Bf,QAAA,EA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KAAA,CAAMK,SAAS,IAAIL,KAAA,CAAMO,kBAAkB,EAAE;UAC/C,MAAMG,QAAA,GAAW;YACf,GAAGV,KAAK;YACR;YACA,IAAIF,SAAA,EAAWa,KAAA,EAAOX,KAAA,IAAS,CAAC,CAAC;UAEnC;UAEA,oBAAOvD,KAAA,CAAMmE,YAAY,CAACd,SAAA,EAAW;YACnCe,GAAA,EAAKpB,CAAA;YACL;YACAO,KAAA,EAAOU;UACT;QACF;QACA,oBAAOjE,KAAA,CAAMmE,YAAY,CAACd,SAAA,EAAW;UACnCe,GAAA,EAAKpB;QACP;MACF;MAEA,OAAOK,SAAA;IACT,EAAE,OAAOD,KAAA,EAAO;MACdD,OAAA,CAAQC,KAAK,CAAC,yCAAyCA,KAAA,EAAO,SAASpC,IAAA;MACvE,OAAO;IACT;EACF;EAEA,OAAO8B,QAAA,CAASuB,MAAM,CAACC,OAAA;AACzB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["jsx","_jsx","Fragment","_Fragment","React","hasText","convertLexicalToJSX","converters","data","disableIndent","disableTextAlign","convertLexicalNodesToJSX","nodes","root","children","parent","unknownConverter","unknown","jsxArray","map","node","i","converterForNode","type","blocks","fields","blockType","console","error","inlineBlocks","reactNode","converted","childIndex","nodesToJSX","args","style","Array","isArray","includes","format","textAlign","indent","paddingInlineStart","Number","isValidElement","newStyle","props","cloneElement","key","filter","Boolean"],"sources":["../../../../../src/features/converters/lexicalToJSX/converter/index.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport type { SerializedEditorState, SerializedLexicalNode } from 'lexical'\n\nimport React from 'react'\n\nimport type { SerializedBlockNode, SerializedInlineBlockNode } from '../../../../nodeTypes.js'\nimport type { JSXConverter, JSXConverters, SerializedLexicalNodeWithParent } from './types.js'\n\nimport { hasText } from '../../../../validate/hasText.js'\n\nexport type ConvertLexicalToJSXArgs = {\n converters: JSXConverters\n data: SerializedEditorState\n disableIndent?: boolean | string[]\n disableTextAlign?: boolean | string[]\n}\n\nexport function convertLexicalToJSX({\n converters,\n data,\n disableIndent,\n disableTextAlign,\n}: ConvertLexicalToJSXArgs): React.ReactNode {\n if (hasText(data)) {\n return convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes: data?.root?.children,\n parent: data?.root,\n })\n }\n return <></>\n}\n\nexport function convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes,\n parent,\n}: {\n converters: JSXConverters\n disableIndent?: boolean | string[]\n disableTextAlign?: boolean | string[]\n nodes: SerializedLexicalNode[]\n parent: SerializedLexicalNodeWithParent\n}): React.ReactNode[] {\n const unknownConverter: JSXConverter<any> = converters.unknown as JSXConverter<any>\n\n const jsxArray: React.ReactNode[] = nodes.map((node, i) => {\n let converterForNode: JSXConverter<any> | undefined\n if (node.type === 'block') {\n converterForNode = converters?.blocks?.[(node as SerializedBlockNode)?.fields?.blockType]\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Blocks converter: found ${(node as SerializedBlockNode)?.fields?.blockType} block, but no converter is provided`,\n )\n }\n } else if (node.type === 'inlineBlock') {\n converterForNode =\n converters?.inlineBlocks?.[(node as SerializedInlineBlockNode)?.fields?.blockType]\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Inline Blocks converter: found ${(node as SerializedInlineBlockNode)?.fields?.blockType} inline block, but no converter is provided`,\n )\n }\n } else {\n converterForNode = converters[node.type] as JSXConverter<any>\n }\n\n try {\n if (!converterForNode && unknownConverter) {\n converterForNode = unknownConverter\n }\n\n let reactNode: React.ReactNode\n if (converterForNode) {\n const converted =\n typeof converterForNode === 'function'\n ? converterForNode({\n childIndex: i,\n converters,\n node,\n nodesToJSX: (args) => {\n return convertLexicalNodesToJSX({\n converters: args.converters ?? converters,\n disableIndent: args.disableIndent ?? disableIndent,\n disableTextAlign: args.disableTextAlign ?? disableTextAlign,\n nodes: args.nodes,\n parent: args.parent ?? {\n ...node,\n parent,\n },\n })\n },\n parent,\n })\n : converterForNode\n reactNode = converted\n } else {\n reactNode = <span key={i}>unknown node</span>\n }\n\n const style: React.CSSProperties = {}\n\n // Check if disableTextAlign is not true and does not include node type\n if (\n !disableTextAlign &&\n (!Array.isArray(disableTextAlign) || !disableTextAlign?.includes(node.type))\n ) {\n if ('format' in node && node.format) {\n switch (node.format) {\n case 'center':\n style.textAlign = 'center'\n break\n case 'end':\n style.textAlign = 'right'\n break\n case 'justify':\n style.textAlign = 'justify'\n break\n case 'left':\n //style.textAlign = 'left'\n // Do nothing, as left is the default\n break\n case 'right':\n style.textAlign = 'right'\n break\n case 'start':\n style.textAlign = 'left'\n break\n }\n }\n }\n\n if (\n !disableIndent &&\n (!Array.isArray(disableIndent) || !disableIndent?.includes(node.type))\n ) {\n if ('indent' in node && node.indent && node.type !== 'listitem') {\n // the unit should be px. Do not change it to rem, em, or something else.\n // The quantity should be 40px. Do not change it either.\n // See rationale in\n // https://github.com/payloadcms/payload/issues/13130#issuecomment-3058348085\n style.paddingInlineStart = `${Number(node.indent) * 40}px`\n }\n }\n\n if (React.isValidElement(reactNode)) {\n // Inject style into reactNode\n if (style.textAlign || style.paddingInlineStart) {\n const newStyle = {\n ...style,\n // @ts-expect-error type better later\n ...(reactNode?.props?.style ?? {}),\n // reactNode style comes after, thus a textAlign specified in the converter has priority over the one we inject here\n }\n\n return React.cloneElement(reactNode, {\n key: i,\n // @ts-expect-error type better later\n style: newStyle,\n })\n }\n return React.cloneElement(reactNode, {\n key: i,\n })\n }\n\n return reactNode\n } catch (error) {\n console.error('Error converting lexical node to JSX:', error, 'node:', node)\n return null\n }\n })\n\n return jsxArray.filter(Boolean)\n}\n"],"mappings":"AAAA,+BAA6B,SAAAA,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA;AAG7B,OAAOC,KAAA,MAAW;AAKlB,SAASC,OAAO,QAAQ;AASxB,OAAO,SAASC,oBAAoB;EAClCC,UAAU;EACVC,IAAI;EACJC,aAAa;EACbC;AAA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