@payloadcms/richtext-lexical 3.77.0-canary.3 → 3.77.0-internal.0b6b4e4

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.
Files changed (118) hide show
  1. package/dist/exports/client/Field-4IVB5SEE.js +2 -0
  2. package/dist/exports/client/Field-4IVB5SEE.js.map +7 -0
  3. package/dist/exports/client/bundled.css +1 -1
  4. package/dist/exports/client/chunk-CRVQNLN7.js +2 -0
  5. package/dist/exports/client/chunk-CRVQNLN7.js.map +7 -0
  6. package/dist/exports/client/chunk-UOYS7JHZ.js +12 -0
  7. package/dist/exports/client/chunk-UOYS7JHZ.js.map +7 -0
  8. package/dist/exports/client/componentInline-22F6QL2B.js +2 -0
  9. package/dist/exports/client/index.d.ts +1 -0
  10. package/dist/exports/client/index.d.ts.map +1 -1
  11. package/dist/exports/client/index.js +23 -23
  12. package/dist/exports/client/index.js.map +3 -3
  13. package/dist/exports/client/internal-client.d.ts +3 -0
  14. package/dist/exports/client/internal-client.d.ts.map +1 -0
  15. package/dist/exports/react/index.d.ts +3 -1
  16. package/dist/exports/react/index.d.ts.map +1 -1
  17. package/dist/exports/react/index.js +1 -0
  18. package/dist/exports/react/index.js.map +1 -1
  19. package/dist/features/blocks/client/component/BlockContent.d.ts +7 -4
  20. package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
  21. package/dist/features/blocks/client/component/BlockContent.js +9 -8
  22. package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
  23. package/dist/features/blocks/client/component/index.d.ts +20 -4
  24. package/dist/features/blocks/client/component/index.d.ts.map +1 -1
  25. package/dist/features/blocks/client/component/index.js +40 -11
  26. package/dist/features/blocks/client/component/index.js.map +1 -1
  27. package/dist/features/blocks/client/componentInline/index.d.ts +8 -14
  28. package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
  29. package/dist/features/blocks/client/componentInline/index.js +38 -9
  30. package/dist/features/blocks/client/componentInline/index.js.map +1 -1
  31. package/dist/features/blocks/client/nodes/BlocksNode.d.ts +4 -2
  32. package/dist/features/blocks/client/nodes/BlocksNode.d.ts.map +1 -1
  33. package/dist/features/blocks/client/nodes/BlocksNode.js +3 -1
  34. package/dist/features/blocks/client/nodes/BlocksNode.js.map +1 -1
  35. package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts +4 -2
  36. package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts.map +1 -1
  37. package/dist/features/blocks/client/nodes/InlineBlocksNode.js +3 -1
  38. package/dist/features/blocks/client/nodes/InlineBlocksNode.js.map +1 -1
  39. package/dist/features/converters/lexicalToJSX/Component/index.d.ts +6 -20
  40. package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
  41. package/dist/features/converters/lexicalToJSX/Component/index.js +7 -5
  42. package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
  43. package/dist/features/converters/lexicalToJSX/converter/index.d.ts +17 -2
  44. package/dist/features/converters/lexicalToJSX/converter/index.d.ts.map +1 -1
  45. package/dist/features/converters/lexicalToJSX/converter/index.js +124 -4
  46. package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
  47. package/dist/features/converters/lexicalToJSX/converter/types.d.ts +14 -10
  48. package/dist/features/converters/lexicalToJSX/converter/types.d.ts.map +1 -1
  49. package/dist/features/converters/lexicalToJSX/converter/types.js.map +1 -1
  50. package/dist/features/debug/jsxConverter/client/plugin/index.js +1 -1
  51. package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
  52. package/dist/field/Field.d.ts.map +1 -1
  53. package/dist/field/Field.js +15 -6
  54. package/dist/field/Field.js.map +1 -1
  55. package/dist/field/RichTextViewProvider.d.ts +85 -0
  56. package/dist/field/RichTextViewProvider.d.ts.map +1 -0
  57. package/dist/field/RichTextViewProvider.js +91 -0
  58. package/dist/field/RichTextViewProvider.js.map +1 -0
  59. package/dist/field/ViewSelector.d.ts +4 -0
  60. package/dist/field/ViewSelector.d.ts.map +1 -0
  61. package/dist/field/ViewSelector.js +89 -0
  62. package/dist/field/ViewSelector.js.map +1 -0
  63. package/dist/field/bundled.css +1 -1
  64. package/dist/field/index.d.ts +1 -0
  65. package/dist/field/index.d.ts.map +1 -1
  66. package/dist/field/index.js +64 -35
  67. package/dist/field/index.js.map +1 -1
  68. package/dist/field/rscEntry.d.ts +1 -1
  69. package/dist/field/rscEntry.d.ts.map +1 -1
  70. package/dist/field/rscEntry.js +12 -0
  71. package/dist/field/rscEntry.js.map +1 -1
  72. package/dist/index.d.ts +1 -1
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +3 -1
  75. package/dist/index.js.map +1 -1
  76. package/dist/lexical/LexicalEditor.d.ts.map +1 -1
  77. package/dist/lexical/LexicalEditor.js +2 -1
  78. package/dist/lexical/LexicalEditor.js.map +1 -1
  79. package/dist/lexical/LexicalProvider.d.ts.map +1 -1
  80. package/dist/lexical/LexicalProvider.js +12 -3
  81. package/dist/lexical/LexicalProvider.js.map +1 -1
  82. package/dist/lexical/config/client/sanitize.d.ts +1 -1
  83. package/dist/lexical/config/client/sanitize.d.ts.map +1 -1
  84. package/dist/lexical/config/client/sanitize.js +3 -2
  85. package/dist/lexical/config/client/sanitize.js.map +1 -1
  86. package/dist/lexical/config/types.d.ts +4 -0
  87. package/dist/lexical/config/types.d.ts.map +1 -1
  88. package/dist/lexical/config/types.js.map +1 -1
  89. package/dist/lexical/nodes/index.d.ts +12 -2
  90. package/dist/lexical/nodes/index.d.ts.map +1 -1
  91. package/dist/lexical/nodes/index.js +213 -2
  92. package/dist/lexical/nodes/index.js.map +1 -1
  93. package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts +2 -0
  94. package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts.map +1 -0
  95. package/dist/lexical/plugins/NodeViewOverridePlugin/index.js +48 -0
  96. package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +1 -0
  97. package/dist/lexical/plugins/SlashMenu/index.d.ts.map +1 -1
  98. package/dist/lexical/plugins/SlashMenu/index.js +14 -1
  99. package/dist/lexical/plugins/SlashMenu/index.js.map +1 -1
  100. package/dist/types.d.ts +329 -2
  101. package/dist/types.d.ts.map +1 -1
  102. package/dist/types.js.map +1 -1
  103. package/dist/utilities/generateImportMap.d.ts.map +1 -1
  104. package/dist/utilities/generateImportMap.js +1 -0
  105. package/dist/utilities/generateImportMap.js.map +1 -1
  106. package/dist/validate/hasText.d.ts +6 -1
  107. package/dist/validate/hasText.d.ts.map +1 -1
  108. package/dist/validate/hasText.js +10 -4
  109. package/dist/validate/hasText.js.map +1 -1
  110. package/package.json +11 -6
  111. package/dist/exports/client/Field-HJGV32KA.js +0 -2
  112. package/dist/exports/client/Field-HJGV32KA.js.map +0 -7
  113. package/dist/exports/client/chunk-2S5Q7QYO.js +0 -2
  114. package/dist/exports/client/chunk-2S5Q7QYO.js.map +0 -7
  115. package/dist/exports/client/chunk-EZX4YW7S.js +0 -12
  116. package/dist/exports/client/chunk-EZX4YW7S.js.map +0 -7
  117. package/dist/exports/client/componentInline-NL25DNZ5.js +0 -2
  118. /package/dist/exports/client/{componentInline-NL25DNZ5.js.map → componentInline-22F6QL2B.js.map} +0 -0
@@ -1,19 +1,139 @@
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
+ }
4
117
  export function convertLexicalToJSX({
5
118
  converters,
6
119
  data,
7
120
  disableIndent,
8
- disableTextAlign
121
+ disableTextAlign,
122
+ nodeMap
9
123
  }) {
10
124
  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;
11
131
  return convertLexicalNodesToJSX({
12
- converters,
132
+ converters: mergedConverters,
13
133
  disableIndent,
14
134
  disableTextAlign,
15
- nodes: data?.root?.children,
16
- parent: data?.root
135
+ nodes: data.root.children,
136
+ parent: data.root
17
137
  });
18
138
  }
19
139
  return /*#__PURE__*/_jsx(_Fragment, {});
@@ -1 +1 @@
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;AAAgB,CACQ;EACxB,IAAIL,OAAA,CAAQG,IAAA,GAAO;IACjB,OAAOG,wBAAA,CAAyB;MAC9BJ,UAAA;MACAE,aAAA;MACAC,gBAAA;MACAE,KAAA,EAAOJ,IAAA,EAAMK,IAAA,EAAMC,QAAA;MACnBC,MAAA,EAAQP,IAAA,EAAMK;IAChB;EACF;EACA,oBAAOZ,IAAA,CAAAE,SAAA;AACT;AAEA,OAAO,SAASQ,yBAAyB;EACvCJ,UAAU;EACVE,aAAa;EACbC,gBAAgB;EAChBE,KAAK;EACLG;AAAM,CAOP;EACC,MAAMC,gBAAA,GAAsCT,UAAA,CAAWU,OAAO;EAE9D,MAAMC,QAAA,GAA8BN,KAAA,CAAMO,GAAG,CAAC,CAACC,IAAA,EAAMC,CAAA;IACnD,IAAIC,gBAAA;IACJ,IAAIF,IAAA,CAAKG,IAAI,KAAK,SAAS;MACzBD,gBAAA,GAAmBf,UAAA,EAAYiB,MAAA,GAAUJ,IAAA,EAA8BK,MAAA,EAAQC,SAAA,CAAU;MACzF,IAAI,CAACJ,gBAAA,IAAoB,CAACN,gBAAA,EAAkB;QAC1CW,OAAA,CAAQC,KAAK,CACX,qDAAsDR,IAAA,EAA8BK,MAAA,EAAQC,SAAA,sCAA+C;MAE/I;IACF,OAAO,IAAIN,IAAA,CAAKG,IAAI,KAAK,eAAe;MACtCD,gBAAA,GACEf,UAAA,EAAYsB,YAA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AA,EAAO,SAASR,IAAA;MACvE,OAAO;IACT;EACF;EAEA,OAAOF,QAAA,CAAS+B,MAAM,CAACC,OAAA;AACzB","ignoreList":[]}
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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K;cACHL,KAAA,CAAMK,SAAS,GAAG;cAClB;YACF,KAAK;cAGH;YACF,KAAK;cACHL,KAAA,CAAMK,SAAS,GAAG;cAClB;YACF,KAAK;cACHL,KAAA,CAAMK,SAAS,GAAG;cAClB;UACJ;QACF;MACF;MAEA,IACE,CAACvB,aAAA,KACA,CAACmB,KAAA,CAAMC,OAAO,CAACpB,aAAA,KAAkB,CAACA,aAAA,EAAeqB,QAAA,CAAS1C,IAAA,CAAKkC,IAAI,IACpE;QACA,IAAI,YAAYlC,IAAA,IAAQA,IAAA,CAAK6C,MAAM,IAAI7C,IAAA,CAAKkC,IAAI,KAAK,YAAY;UAC/D;UACA;UACA;UACA;UACAK,KAAA,CAAMO,kBAAkB,GAAG,GAAGC,MAAA,CAAO/C,IAAA,CAAK6C,MAAM,IAAI,MAAM;QAC5D;MACF;MAEA,iBAAI7D,KAAA,CAAMgE,cAAc,CAACX,SAAA,GAAY;QACnC;QACA,IAAIE,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,12 +1,12 @@
1
1
  import type { SerializedLexicalNode } from 'lexical';
2
2
  import type { DefaultNodeTypes, SerializedBlockNode, SerializedInlineBlockNode } from '../../../../nodeTypes.js';
3
- export type JSXConverter<T extends {
3
+ export type JSXConverterArgs<TNode extends {
4
4
  [key: string]: any;
5
5
  type?: string;
6
- } = SerializedLexicalNode> = ((args: {
6
+ } = SerializedLexicalNode> = {
7
7
  childIndex: number;
8
8
  converters: JSXConverters;
9
- node: T;
9
+ node: TNode;
10
10
  nodesToJSX: (args: {
11
11
  converters?: JSXConverters;
12
12
  disableIndent?: boolean | string[];
@@ -15,8 +15,12 @@ export type JSXConverter<T extends {
15
15
  parent?: SerializedLexicalNodeWithParent;
16
16
  }) => React.ReactNode[];
17
17
  parent: SerializedLexicalNodeWithParent;
18
- }) => React.ReactNode) | React.ReactNode;
19
- export type JSXConverters<T extends {
18
+ };
19
+ export type JSXConverter<TNode extends {
20
+ [key: string]: any;
21
+ type?: string;
22
+ } = SerializedLexicalNode> = ((args: JSXConverterArgs<TNode>) => React.ReactNode) | React.ReactNode;
23
+ export type JSXConverters<TNodes extends {
20
24
  [key: string]: any;
21
25
  type?: string;
22
26
  } = DefaultNodeTypes | SerializedBlockNode<{
@@ -30,27 +34,27 @@ export type JSXConverters<T extends {
30
34
  [blockSlug: string]: JSXConverter<any>;
31
35
  } | JSXConverter<any> | undefined;
32
36
  } & {
33
- [nodeType in Exclude<NonNullable<T['type']>, 'block' | 'inlineBlock'>]?: JSXConverter<Extract<T, {
37
+ [nodeType in Exclude<NonNullable<TNodes['type']>, 'block' | 'inlineBlock'>]?: JSXConverter<Extract<TNodes, {
34
38
  type: nodeType;
35
39
  }>>;
36
40
  } & {
37
41
  blocks?: {
38
- [K in Extract<Extract<T, {
42
+ [K in Extract<Extract<TNodes, {
39
43
  type: 'block';
40
44
  }> extends SerializedBlockNode<infer B> ? B extends {
41
45
  blockType: string;
42
- } ? B['blockType'] : never : never, string>]?: JSXConverter<Extract<T, {
46
+ } ? B['blockType'] : never : never, string>]?: JSXConverter<Extract<TNodes, {
43
47
  type: 'block';
44
48
  }> extends SerializedBlockNode<infer B> ? SerializedBlockNode<Extract<B, {
45
49
  blockType: K;
46
50
  }>> : SerializedBlockNode>;
47
51
  };
48
52
  inlineBlocks?: {
49
- [K in Extract<Extract<T, {
53
+ [K in Extract<Extract<TNodes, {
50
54
  type: 'inlineBlock';
51
55
  }> extends SerializedInlineBlockNode<infer B> ? B extends {
52
56
  blockType: string;
53
- } ? B['blockType'] : never : never, string>]?: JSXConverter<Extract<T, {
57
+ } ? B['blockType'] : never : never, string>]?: JSXConverter<Extract<TNodes, {
54
58
  type: 'inlineBlock';
55
59
  }> extends SerializedInlineBlockNode<infer B> ? SerializedInlineBlockNode<Extract<B, {
56
60
  blockType: K;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/lexicalToJSX/converter/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,0BAA0B,CAAA;AACjC,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,qBAAqB,IAC5F,CAAC,CAAC,IAAI,EAAE;IACN,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,aAAa,CAAA;IACzB,IAAI,EAAE,CAAC,CAAA;IACP,UAAU,EAAE,CAAC,IAAI,EAAE;QACjB,UAAU,CAAC,EAAE,aAAa,CAAA;QAC1B,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;QAClC,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;QACrC,KAAK,EAAE,qBAAqB,EAAE,CAAA;QAC9B,MAAM,CAAC,EAAE,+BAA+B,CAAA;KACzC,KAAK,KAAK,CAAC,SA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A;SAAE,CAAC,SAAS,mBAAmB,CAAC,MAAM,CAAC,CAAC,GAC9D,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE;YAAE,SAAS,EAAE,CAAC,CAAA;SAAE,CAAC,CAAC,GACjD,mBAAmB,CACxB;KACF,CAAA;IACD,YAAY,CAAC,EAAE;SACZ,CAAC,IAAI,OAAO,CACX,OAAO,CAAC,CAAC,EAAE;YAAE,IAAI,EAAE,aAAa,CAAA;SAAE,CAAC,SAAS,yBAAyB,CAAC,MAAM,CAAC,CAAC,GAC1E,CAAC,SAAS;YAAE,SAAS,EAAE,MAAM,CAAA;SAAE,GAC7B,CAAC,CAAC,WAAW,CAAC,GACd,KAAK,GACP,KAAK,EACT,MAAM,CACP,CAAC,CAAC,EAAE,YAAY,CACf,OAAO,CAAC,CAAC,EAAE;YAAE,IAAI,EAAE,aAAa,CAAA;SAAE,CAAC,SAAS,yBAAyB,CAAC,MAAM,CAAC,CAAC,GAC1E,yBAAyB,CAAC,OAAO,CAAC,CAAC,EAAE;YAAE,SAAS,EAAE,CAAC,CAAA;SAAE,CAAC,CAAC,GACvD,yBAAyB,CAC9B;KACF,CAAA;IACD,OAAO,CAAC,EAAE,YAAY,CAAC,qBAAqB,CAAC,CAAA;CAC9C,CAAA;AACD,MAAM,MAAM,+BAA+B,GAAG;IAC5C,MAAM,CAAC,EAAE,qBAAqB,CAAA;CAC/B,GAAG,qBAAqB,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/lexicalToJSX/converter/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,0BAA0B,CAAA;AAEjC,MAAM,MAAM,gBAAgB,CAC1B,KAAK,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAAC,IAAI,C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AyB,CAAC,OAAO,CAAC,CAAC,EAAE;YAAE,SAAS,EAAE,CAAC,CAAA;SAAE,CAAC,CAAC,GACvD,yBAAyB,CAC9B;KACF,CAAA;IACD,OAAO,CAAC,EAAE,YAAY,CAAC,qBAAqB,CAAC,CAAA;CAC9C,CAAA;AACD,MAAM,MAAM,+BAA+B,GAAG;IAC5C,MAAM,CAAC,EAAE,qBAAqB,CAAA;CAC/B,GAAG,qBAAqB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/features/converters/lexicalToJSX/converter/types.ts"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\n\nimport type {\n DefaultNodeTypes,\n SerializedBlockNode,\n SerializedInlineBlockNode,\n} from '../../../../nodeTypes.js'\nexport type JSXConverter<T extends { [key: string]: any; type?: string } = SerializedLexicalNode> =\n | ((args: {\n childIndex: number\n converters: JSXConverters\n node: T\n nodesToJSX: (args: {\n converters?: JSXConverters\n disableIndent?: boolean | string[]\n disableTextAlign?: boolean | string[]\n nodes: SerializedLexicalNode[]\n parent?: SerializedLexicalNodeWithParent\n }) => React.ReactNode[]\n parent: SerializedLexicalNodeWithParent\n }) => React.ReactNode)\n | React.ReactNode\n\nexport type JSXConverters<\n T extends { [key: string]: any; type?: string } =\n | DefaultNodeTypes\n | SerializedBlockNode<{ blockName?: null | string; blockType: string }> // need these to ensure types for blocks and inlineBlocks work if no generics are provided\n | SerializedInlineBlockNode<{ blockName?: null | string; blockType: string }>, // need these to ensure types for blocks and inlineBlocks work if no generics are provided\n> = {\n [key: string]:\n | {\n [blockSlug: string]: JSXConverter<any>\n }\n | JSXConverter<any>\n | undefined\n} & {\n [nodeType in Exclude<NonNullable<T['type']>, 'block' | 'inlineBlock'>]?: JSXConverter<\n Extract<T, { type: nodeType }>\n >\n} & {\n blocks?: {\n [K in Extract<\n Extract<T, { type: 'block' }> extends SerializedBlockNode<infer B>\n ? B extends { blockType: string }\n ? B['blockType']\n : never\n : never,\n string\n >]?: JSXConverter<\n Extract<T, { type: 'block' }> extends SerializedBlockNode<infer B>\n ? SerializedBlockNode<Extract<B, { blockType: K }>>\n : SerializedBlockNode\n >\n }\n inlineBlocks?: {\n [K in Extract<\n Extract<T, { type: 'inlineBlock' }> extends SerializedInlineBlockNode<infer B>\n ? B extends { blockType: string }\n ? B['blockType']\n : never\n : never,\n string\n >]?: JSXConverter<\n Extract<T, { type: 'inlineBlock' }> extends SerializedInlineBlockNode<infer B>\n ? SerializedInlineBlockNode<Extract<B, { blockType: K }>>\n : SerializedInlineBlockNode\n >\n }\n unknown?: JSXConverter<SerializedLexicalNode>\n}\nexport type SerializedLexicalNodeWithParent = {\n parent?: SerializedLexicalNode\n} & SerializedLexicalNode\n"],"mappings":"AAsEA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/features/converters/lexicalToJSX/converter/types.ts"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\n\nimport type {\n DefaultNodeTypes,\n SerializedBlockNode,\n SerializedInlineBlockNode,\n} from '../../../../nodeTypes.js'\n\nexport type JSXConverterArgs<\n TNode extends { [key: string]: any; type?: string } = SerializedLexicalNode,\n> = {\n childIndex: number\n converters: JSXConverters\n node: TNode\n nodesToJSX: (args: {\n converters?: JSXConverters\n disableIndent?: boolean | string[]\n disableTextAlign?: boolean | string[]\n nodes: SerializedLexicalNode[]\n parent?: SerializedLexicalNodeWithParent\n }) => React.ReactNode[]\n parent: SerializedLexicalNodeWithParent\n}\nexport type JSXConverter<\n TNode extends { [key: string]: any; type?: string } = SerializedLexicalNode,\n> = ((args: JSXConverterArgs<TNode>) => React.ReactNode) | React.ReactNode\n\nexport type JSXConverters<\n TNodes extends { [key: string]: any; type?: string } =\n | DefaultNodeTypes\n | SerializedBlockNode<{ blockName?: null | string; blockType: string }> // need these to ensure types for blocks and inlineBlocks work if no generics are provided\n | SerializedInlineBlockNode<{ blockName?: null | string; blockType: string }>, // need these to ensure types for blocks and inlineBlocks work if no generics are provided\n> = {\n [key: string]:\n | {\n [blockSlug: string]: JSXConverter<any>\n }\n | JSXConverter<any>\n | undefined\n} & {\n [nodeType in Exclude<NonNullable<TNodes['type']>, 'block' | 'inlineBlock'>]?: JSXConverter<\n Extract<TNodes, { type: nodeType }>\n >\n} & {\n blocks?: {\n [K in Extract<\n Extract<TNodes, { type: 'block' }> extends SerializedBlockNode<infer B>\n ? B extends { blockType: string }\n ? B['blockType']\n : never\n : never,\n string\n >]?: JSXConverter<\n Extract<TNodes, { type: 'block' }> extends SerializedBlockNode<infer B>\n ? SerializedBlockNode<Extract<B, { blockType: K }>>\n : SerializedBlockNode\n >\n }\n inlineBlocks?: {\n [K in Extract<\n Extract<TNodes, { type: 'inlineBlock' }> extends SerializedInlineBlockNode<infer B>\n ? B extends { blockType: string }\n ? B['blockType']\n : never\n : never,\n string\n >]?: JSXConverter<\n Extract<TNodes, { type: 'inlineBlock' }> extends SerializedInlineBlockNode<infer B>\n ? SerializedInlineBlockNode<Extract<B, { blockType: K }>>\n : SerializedInlineBlockNode\n >\n }\n unknown?: JSXConverter<SerializedLexicalNode>\n}\nexport type SerializedLexicalNodeWithParent = {\n parent?: SerializedLexicalNode\n} & SerializedLexicalNode\n"],"mappings":"AA0EA","ignoreList":[]}
@@ -11,7 +11,7 @@ export function RichTextPlugin() {
11
11
  const [editor] = useLexicalComposerContext();
12
12
  let t0;
13
13
  if ($[0] !== editor) {
14
- t0 = editor.getEditorState().toJSON();
14
+ t0 = () => editor.getEditorState().toJSON();
15
15
  $[0] = editor;
16
16
  $[1] = t0;
17
17
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","useEffect","useState","defaultJSXConverters","RichText","RichTextPlugin","$","editor","t0","getEditorState","toJSON","editorState","setEditorState","t1","t2","registerUpdateListener","t3","editorState_0","_jsx","className","children","converters","data"],"sources":["../../../../../../src/features/debug/jsxConverter/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useEffect, useState } from 'react'\n\n// eslint-disable-next-line payload/no-imports-from-exports-dir\nimport { defaultJSXConverters, RichText } from '../../../../../exports/react/index.js'\nimport './style.scss'\n\nexport function RichTextPlugin() {\n const [editor] = useLexicalComposerContext()\n const [editorState, setEditorState] = useState(editor.getEditorState().toJSON())\n\n useEffect(() => {\n return editor.registerUpdateListener(({ editorState }) => {\n setEditorState(editorState.toJSON())\n })\n }, [editor])\n\n return (\n <div className=\"debug-jsx-converter\">\n <RichText converters={defaultJSXConverters} data={editorState} />\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAEA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,SAAS,EAAEC,QAAQ,QAAQ;AAEpC;AACA,SAASC,oBAAoB,EAAEC,QAAQ,QAAQ;AAG/C,OAAO,SAAAC,eAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EACL,OAAAQ,MAAA,IAAiBP,yBAAA;EAAA,IAAAQ,EAAA;EAAA,IAAAF,CAAA,QAAAC,MAAA;IAC8BC,EAAA,GAAAD,MAAA,CAAAE,cAAA,CAAqB,EAAAC,MAAA,CAAS;IAAAJ,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAE,EAAA;EAAA;IAAAA,EAAA,GAAAF,CAAA;EAAA;EAA7E,OAAAK,WAAA,EAAAC,cAAA,IAAsCV,QAAA,CAASM,EAA8B;EAAA,IAAAK,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAR,CAAA,QAAAC,MAAA;IAEnEM,EAAA,GAAAA,CAAA,KACDN,MAAA,CAAAQ,sBAAA,CAAAC,EAAA;MAA+B;QAAAL,WAAA,EAAAM;MAAA,IAAAD,EAAe;MACnDJ,cAAA,CAAeD,aAAA,CAAAD,MAAA,CAAkB;IAAA,CACnC;IACCI,EAAA,IAACP,MAAA;IAAOD,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAO,EAAA;IAAAP,CAAA,MAAAQ,EAAA;EAAA;IAAAD,EAAA,GAAAP,CAAA;IAAAQ,EAAA,GAAAR,CAAA;EAAA;EAJXL,SAAA,CAAUY,EAIV,EAAGC,EAAQ;EAAA,IAAAE,EAAA;EAAA,IAAAV,CAAA,QAAAK,WAAA;IAGTK,EAAA,GAAAE,IAAA,CAAC;MAAAC,SAAA,EAAc;MAAAC,QAAA,EACbF,IAAA,CAAAd,QAAA;QAAAiB,UAAA,EAAAlB,oBAAA;QAAAmB,IAAA,EAAkDX;MAAA,C;;;;;;;SADpDK,E","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","useEffect","useState","defaultJSXConverters","RichText","RichTextPlugin","$","editor","t0","getEditorState","toJSON","editorState","setEditorState","t1","t2","registerUpdateListener","t3","editorState_0","_jsx","className","children","converters","data"],"sources":["../../../../../../src/features/debug/jsxConverter/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useEffect, useState } from 'react'\n\n// eslint-disable-next-line payload/no-imports-from-exports-dir\nimport { defaultJSXConverters, RichText } from '../../../../../exports/react/index.js'\nimport './style.scss'\n\nexport function RichTextPlugin() {\n const [editor] = useLexicalComposerContext()\n const [editorState, setEditorState] = useState(() => editor.getEditorState().toJSON())\n\n useEffect(() => {\n return editor.registerUpdateListener(({ editorState }) => {\n setEditorState(editorState.toJSON())\n })\n }, [editor])\n\n return (\n <div className=\"debug-jsx-converter\">\n <RichText converters={defaultJSXConverters} data={editorState} />\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAEA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,SAAS,EAAEC,QAAQ,QAAQ;AAEpC;AACA,SAASC,oBAAoB,EAAEC,QAAQ,QAAQ;AAG/C,OAAO,SAAAC,eAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EACL,OAA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Ae,CAAA;AACtB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAO5D,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAC/B;IACE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;CACnD,GAAG,yBAAyB,CA4K9B,CAAA;AAaD,eAAO,MAAM,QAAQ,EAAE,OAAO,iBAAqC,CAAA"}
1
+ {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAGxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAE7E,OAAO,mCAAmC,CAAA;AAC1C,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAS5D,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAC/B;IACE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;CACnD,GAAG,yBAAyB,CAuL9B,CAAA;AAaD,eAAO,MAAM,QAAQ,EAAE,OAAO,iBAAqC,CAAA"}
@@ -9,6 +9,8 @@ import { ErrorBoundary } from 'react-error-boundary';
9
9
  import './bundled.css';
10
10
  import { LexicalProvider } from '../lexical/LexicalProvider.js';
11
11
  import { useRunDeprioritized } from '../utilities/useRunDeprioritized.js';
12
+ import { useRichTextView } from './RichTextViewProvider.js';
13
+ import { ViewSelector } from './ViewSelector.js';
12
14
  const baseClass = 'rich-text-lexical';
13
15
  const RichTextComponent = props => {
14
16
  const {
@@ -30,6 +32,9 @@ const RichTextComponent = props => {
30
32
  } = props;
31
33
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
32
34
  const editDepth = useEditDepth();
35
+ const {
36
+ hasInheritedViews
37
+ } = useRichTextView();
33
38
  const memoizedValidate = useCallback((value, validationOptions) => {
34
39
  if (typeof validate === 'function') {
35
40
  // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
@@ -80,7 +85,7 @@ const RichTextComponent = props => {
80
85
  window.removeEventListener('resize', updateViewPortWidth);
81
86
  };
82
87
  }, [isSmallWidthViewport]);
83
- const classes = [baseClass, 'field-type', className, showError && 'error', disabled && `${baseClass}--read-only`, editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport ? `${baseClass}--show-gutter` : null].filter(Boolean).join(' ');
88
+ const classes = ['field-type', baseClass, className, showError && 'error', disabled && `${baseClass}--read-only`, editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport ? `${baseClass}--show-gutter` : null].filter(Boolean).join(' ');
84
89
  const pathWithEditDepth = `${path}.${editDepth}`;
85
90
  const runDeprioritized = useRunDeprioritized() // defaults to 500 ms timeout
86
91
  ;
@@ -119,6 +124,7 @@ const RichTextComponent = props => {
119
124
  }, [initialValue]);
120
125
  return /*#__PURE__*/_jsxs("div", {
121
126
  className: classes,
127
+ "data-lexical-view": editorConfig?.view,
122
128
  style: styles,
123
129
  children: [/*#__PURE__*/_jsx(RenderCustomComponent, {
124
130
  CustomComponent: Error,
@@ -126,11 +132,14 @@ const RichTextComponent = props => {
126
132
  path: path,
127
133
  showError: showError
128
134
  })
129
- }), Label || /*#__PURE__*/_jsx(FieldLabel, {
130
- label: label,
131
- localized: localized,
132
- path: path,
133
- required: required
135
+ }), /*#__PURE__*/_jsxs("div", {
136
+ className: `${baseClass}__label-row`,
137
+ children: [Label || /*#__PURE__*/_jsx(FieldLabel, {
138
+ label: label,
139
+ localized: localized,
140
+ path: path,
141
+ required: required
142
+ }), !hasInheritedViews && /*#__PURE__*/_jsx(ViewSelector, {})]
134
143
  }), /*#__PURE__*/_jsxs("div", {
135
144
  className: `${baseClass}__wrap`,
136
145
  children: [/*#__PURE__*/_jsxs(ErrorBoundary, {
@@ -1 +1 @@
1
- {"version":3,"file":"Field.js","names":["BulkUploadProvider","FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useEffectEvent","useField","mergeFieldStyles","dequal","React","useCallback","useEffect","useMemo","useState","ErrorBoundary","LexicalProvider","useRunDeprioritized","baseClass","RichTextComponent","props","editorConfig","field","admin","className","description","readOnly","readOnlyFromAdmin","label","localized","required","path","pathFromProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","editDepth","memoizedValidate","value","validationOptions","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","disabledFromField","initialValue","setValue","showError","potentiallyStalePath","isSmallWidthViewport","setIsSmallWidthViewport","rerenderProviderKey","setRerenderProviderKey","prevInitialValueRef","useRef","prevValueRef","updateViewPortWidth","isNextSmallWidthViewport","window","matchMedia","matches","addEventListener","removeEventListener","classes","hideGutter","filter","Boolean","join","pathWithEditDepth","runDeprioritized","handleChange","editorState","updateFieldValue","newState","toJSON","current","styles","handleInitialValueChange","JSON","parse","stringify","Date","Object","is","_jsxs","style","_jsx","CustomComponent","Fallback","fallbackRender","onReset","drawerSlugPrefix","composerKey","fieldProps","onChange","error","role","color","message","RichText"],"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { EditorState, SerializedEditorState } from 'lexical'\n\nimport {\n BulkUploadProvider,\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useEditDepth,\n useEffectEvent,\n useField,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport { dequal } from 'dequal/lite'\nimport { type Validate } from 'payload'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\n\nimport '../lexical/theme/EditorTheme.scss'\nimport './bundled.css'\nimport './index.scss'\n\nimport type { LexicalRichTextFieldProps } from '../types.js'\n\nimport { LexicalProvider } from '../lexical/LexicalProvider.js'\nimport { useRunDeprioritized } from '../utilities/useRunDeprioritized.js'\n\nconst baseClass = 'rich-text-lexical'\n\nconst RichTextComponent: React.FC<\n {\n readonly editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n } & LexicalRichTextFieldProps\n> = (props) => {\n const {\n editorConfig,\n field,\n field: {\n admin: { className, description, readOnly: readOnlyFromAdmin } = {},\n label,\n localized,\n required,\n },\n path: pathFromProps,\n readOnly: readOnlyFromTopLevelProps,\n validate, // Users can pass in client side validation if they WANT to, but it's not required anymore\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const editDepth = useEditDepth()\n\n const memoizedValidate = useCallback<Validate>(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return validate(value, { ...validationOptions, required })\n }\n return true\n },\n // Important: do not add props to the dependencies array.\n // This would cause an infinite loop and endless re-rendering.\n // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled: disabledFromField,\n initialValue,\n path,\n setValue,\n showError,\n value,\n } = useField<SerializedEditorState>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || disabledFromField\n\n const [isSmallWidthViewport, setIsSmallWidthViewport] = useState<boolean>(false)\n const [rerenderProviderKey, setRerenderProviderKey] = useState<Date>()\n\n const prevInitialValueRef = React.useRef<SerializedEditorState | undefined>(initialValue)\n const prevValueRef = React.useRef<SerializedEditorState | undefined>(value)\n\n useEffect(() => {\n const updateViewPortWidth = () => {\n const isNextSmallWidthViewport = window.matchMedia('(max-width: 768px)').matches\n\n if (isNextSmallWidthViewport !== isSmallWidthViewport) {\n setIsSmallWidthViewport(isNextSmallWidthViewport)\n }\n }\n updateViewPortWidth()\n window.addEventListener('resize', updateViewPortWidth)\n\n return () => {\n window.removeEventListener('resize', updateViewPortWidth)\n }\n }, [isSmallWidthViewport])\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport\n ? `${baseClass}--show-gutter`\n : null,\n ]\n .filter(Boolean)\n .join(' ')\n\n const pathWithEditDepth = `${path}.${editDepth}`\n\n const runDeprioritized = useRunDeprioritized() // defaults to 500 ms timeout\n\n const handleChange = useCallback(\n (editorState: EditorState) => {\n // Capture `editorState` in the closure so we can safely run later.\n const updateFieldValue = () => {\n const newState = editorState.toJSON()\n prevValueRef.current = newState\n setValue(newState)\n }\n\n // Queue the update for the browser’s idle time (or Safari shim)\n // and let the hook handle debouncing/cancellation.\n void runDeprioritized(updateFieldValue)\n },\n [setValue, runDeprioritized], // `runDeprioritized` is stable (useCallback inside hook)\n )\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const handleInitialValueChange = useEffectEvent(\n (initialValue: SerializedEditorState | undefined) => {\n // Object deep equality check here, as re-mounting the editor if\n // the new value is the same as the old one is not necessary.\n // In postgres, the order of keys in JSON objects is not guaranteed to be preserved,\n // so we need to do a deep equality check here that does not care about key order => we use dequal.\n // If we used JSON.stringify, the editor would re-mount every time you save the document, as the order of keys changes => change detected => re-mount.\n if (\n prevValueRef.current !== value &&\n !dequal(\n prevValueRef.current != null\n ? JSON.parse(JSON.stringify(prevValueRef.current))\n : prevValueRef.current,\n value,\n )\n ) {\n prevInitialValueRef.current = initialValue\n prevValueRef.current = value\n setRerenderProviderKey(new Date())\n }\n },\n )\n\n useEffect(() => {\n // Needs to trigger for object reference changes - otherwise,\n // reacting to the same initial value change twice will cause\n // the second change to be ignored, even though the value has changed.\n // That's because initialValue is not kept up-to-date\n if (!Object.is(initialValue, prevInitialValueRef.current)) {\n handleInitialValueChange(initialValue)\n }\n }, [initialValue])\n\n return (\n <div className={classes} key={pathWithEditDepth} style={styles}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {Label || <FieldLabel label={label} localized={localized} path={path} required={required} />}\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n {BeforeInput}\n {/* Lexical may be in a drawer. We need to define another BulkUploadProvider to ensure that the bulk upload drawer\n is rendered in the correct depth (not displayed *behind* the current drawer)*/}\n <BulkUploadProvider drawerSlugPrefix={path}>\n <LexicalProvider\n composerKey={pathWithEditDepth}\n editorConfig={editorConfig}\n fieldProps={props}\n isSmallWidthViewport={isSmallWidthViewport}\n key={JSON.stringify({ path, rerenderProviderKey })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)\n onChange={handleChange}\n readOnly={disabled}\n value={value}\n />\n </BulkUploadProvider>\n {AfterInput}\n </ErrorBoundary>\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }: { error: Error }) {\n // Call resetErrorBoundary() to reset the error boundary and retry the render.\n\n return (\n <div className=\"errorBoundary\" role=\"alert\">\n <p>Something went wrong:</p>\n <pre style={{ color: 'red' }}>{error.message}</pre>\n </div>\n )\n}\n\nexport const RichText: typeof RichTextComponent = RichTextComponent\n"],"mappings":"AAAA;;;AAGA,SACEA,kBAAkB,EAClBC,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,YAAY,EACZC,cAAc,EACdC,QAAQ,QACH;AACP,SAASC,gBAAgB,QAAQ;AACjC,SAASC,MAAM,QAAQ;AAEvB,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AACjE,SAASC,aAAa,QAAQ;AAK9B,OAAO;AAKP,SAASC,eAAe,QAAQ;AAChC,SAASC,mBAAmB,QAAQ;AAEpC,MAAMC,SAAA,GAAY;AAElB,MAAMC,iBAAA,GAIDC,KAAA;EACH,M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E,WAAA,EAAaxB,iBAAA;YACblD,YAAA,EAAcA,YAAA;YACd2E,UAAA,EAAY5E,KAAA;YACZgC,oBAAA,EAAsBA,oBAAA;YAEtB6C,QAAA,EAAUxB,YAAA;YACV/C,QAAA,EAAUoB,QAAA;YACVR,KAAA,EAAOA;aAHF2C,IAAA,CAAKE,SAAS,CAAC;YAAEpD,IAAA;YAAMuB;UAAoB;YAMnDb,UAAA;uBAEHgD,IAAA,CAACrF,qBAAA;QACCsF,eAAA,EAAiB/C,WAAA;QACjBgD,QAAA,eAAUF,IAAA,CAACxF,gBAAA;UAAiBwB,WAAA,EAAaA,WAAA;UAAaM,IAAA,EAAMA;;;;KA3BpCwC,iBAAA;AAgClC;AAEA,SAASqB,eAAe;EAAEM;AAAK,CAAoB;EACjD;EAEA,oBACEX,KAAA,CAAC;IAAI/D,SAAA,EAAU;IAAgB2E,IAAA,EAAK;4BAClCV,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAID,KAAA,EAAO;QAAEY,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqCnF,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"Field.js","names":["BulkUploadProvider","FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useEffectEvent","useField","mergeFieldStyles","dequal","React","useCallback","useEffect","useMemo","useState","ErrorBoundary","LexicalProvider","useRunDeprioritized","useRichTextView","ViewSelector","baseClass","RichTextComponent","props","editorConfig","field","admin","className","description","readOnly","readOnlyFromAdmin","label","localized","required","path","pathFromProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","editDepth","hasInheritedViews","memoizedValidate","value","validationOptions","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","disabledFromField","initialValue","setValue","showError","potentiallyStalePath","isSmallWidthViewport","setIsSmallWidthViewport","rerenderProviderKey","setRerenderProviderKey","prevInitialValueRef","useRef","prevValueRef","updateViewPortWidth","isNextSmallWidthViewport","window","matchMedia","matches","addEventListener","removeEventListener","classes","hideGutter","filter","Boolean","join","pathWithEditDepth","runDeprioritized","handleChange","editorState","updateFieldValue","newState","toJSON","current","styles","handleInitialValueChange","JSON","parse","stringify","Date","Object","is","_jsxs","view","style","_jsx","CustomComponent","Fallback","fallbackRender","onReset","drawerSlugPrefix","composerKey","fieldProps","onChange","error","role","color","message","RichText"],"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { EditorState, SerializedEditorState } from 'lexical'\n\nimport {\n BulkUploadProvider,\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useEditDepth,\n useEffectEvent,\n useField,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport { dequal } from 'dequal/lite'\nimport { type Validate } from 'payload'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\n\nimport '../lexical/theme/EditorTheme.scss'\nimport './bundled.css'\nimport './index.scss'\n\nimport type { LexicalRichTextFieldProps } from '../types.js'\n\nimport { LexicalProvider } from '../lexical/LexicalProvider.js'\nimport { useRunDeprioritized } from '../utilities/useRunDeprioritized.js'\nimport { useRichTextView } from './RichTextViewProvider.js'\nimport { ViewSelector } from './ViewSelector.js'\n\nconst baseClass = 'rich-text-lexical'\n\nconst RichTextComponent: React.FC<\n {\n readonly editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n } & LexicalRichTextFieldProps\n> = (props) => {\n const {\n editorConfig,\n field,\n field: {\n admin: { className, description, readOnly: readOnlyFromAdmin } = {},\n label,\n localized,\n required,\n },\n path: pathFromProps,\n readOnly: readOnlyFromTopLevelProps,\n validate, // Users can pass in client side validation if they WANT to, but it's not required anymore\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const editDepth = useEditDepth()\n const { hasInheritedViews } = useRichTextView()\n\n const memoizedValidate = useCallback<Validate>(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return validate(value, { ...validationOptions, required })\n }\n return true\n },\n // Important: do not add props to the dependencies array.\n // This would cause an infinite loop and endless re-rendering.\n // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled: disabledFromField,\n initialValue,\n path,\n setValue,\n showError,\n value,\n } = useField<SerializedEditorState>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || disabledFromField\n\n const [isSmallWidthViewport, setIsSmallWidthViewport] = useState<boolean>(false)\n const [rerenderProviderKey, setRerenderProviderKey] = useState<Date>()\n\n const prevInitialValueRef = React.useRef<SerializedEditorState | undefined>(initialValue)\n const prevValueRef = React.useRef<SerializedEditorState | undefined>(value)\n\n useEffect(() => {\n const updateViewPortWidth = () => {\n const isNextSmallWidthViewport = window.matchMedia('(max-width: 768px)').matches\n\n if (isNextSmallWidthViewport !== isSmallWidthViewport) {\n setIsSmallWidthViewport(isNextSmallWidthViewport)\n }\n }\n updateViewPortWidth()\n window.addEventListener('resize', updateViewPortWidth)\n\n return () => {\n window.removeEventListener('resize', updateViewPortWidth)\n }\n }, [isSmallWidthViewport])\n\n const classes = [\n 'field-type',\n baseClass,\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport\n ? `${baseClass}--show-gutter`\n : null,\n ]\n .filter(Boolean)\n .join(' ')\n\n const pathWithEditDepth = `${path}.${editDepth}`\n\n const runDeprioritized = useRunDeprioritized() // defaults to 500 ms timeout\n\n const handleChange = useCallback(\n (editorState: EditorState) => {\n // Capture `editorState` in the closure so we can safely run later.\n const updateFieldValue = () => {\n const newState = editorState.toJSON()\n prevValueRef.current = newState\n setValue(newState)\n }\n\n // Queue the update for the browser’s idle time (or Safari shim)\n // and let the hook handle debouncing/cancellation.\n void runDeprioritized(updateFieldValue)\n },\n [setValue, runDeprioritized], // `runDeprioritized` is stable (useCallback inside hook)\n )\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const handleInitialValueChange = useEffectEvent(\n (initialValue: SerializedEditorState | undefined) => {\n // Object deep equality check here, as re-mounting the editor if\n // the new value is the same as the old one is not necessary.\n // In postgres, the order of keys in JSON objects is not guaranteed to be preserved,\n // so we need to do a deep equality check here that does not care about key order => we use dequal.\n // If we used JSON.stringify, the editor would re-mount every time you save the document, as the order of keys changes => change detected => re-mount.\n if (\n prevValueRef.current !== value &&\n !dequal(\n prevValueRef.current != null\n ? JSON.parse(JSON.stringify(prevValueRef.current))\n : prevValueRef.current,\n value,\n )\n ) {\n prevInitialValueRef.current = initialValue\n prevValueRef.current = value\n setRerenderProviderKey(new Date())\n }\n },\n )\n\n useEffect(() => {\n // Needs to trigger for object reference changes - otherwise,\n // reacting to the same initial value change twice will cause\n // the second change to be ignored, even though the value has changed.\n // That's because initialValue is not kept up-to-date\n if (!Object.is(initialValue, prevInitialValueRef.current)) {\n handleInitialValueChange(initialValue)\n }\n }, [initialValue])\n\n return (\n <div\n className={classes}\n data-lexical-view={editorConfig?.view}\n key={pathWithEditDepth}\n style={styles}\n >\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n <div className={`${baseClass}__label-row`}>\n {Label || (\n <FieldLabel label={label} localized={localized} path={path} required={required} />\n )}\n {!hasInheritedViews && <ViewSelector />}\n </div>\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n {BeforeInput}\n {/* Lexical may be in a drawer. We need to define another BulkUploadProvider to ensure that the bulk upload drawer\n is rendered in the correct depth (not displayed *behind* the current drawer)*/}\n <BulkUploadProvider drawerSlugPrefix={path}>\n <LexicalProvider\n composerKey={pathWithEditDepth}\n editorConfig={editorConfig}\n fieldProps={props}\n isSmallWidthViewport={isSmallWidthViewport}\n key={JSON.stringify({ path, rerenderProviderKey })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)\n onChange={handleChange}\n readOnly={disabled}\n value={value}\n />\n </BulkUploadProvider>\n {AfterInput}\n </ErrorBoundary>\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }: { error: Error }) {\n // Call resetErrorBoundary() to reset the error boundary and retry the render.\n\n return (\n <div className=\"errorBoundary\" role=\"alert\">\n <p>Something went wrong:</p>\n <pre style={{ color: 'red' }}>{error.message}</pre>\n </div>\n )\n}\n\nexport const RichText: typeof RichTextComponent = RichTextComponent\n"],"mappings":"AAAA;;;AAGA,SACEA,kBAAkB,EAClBC,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,YAAY,EACZC,cAAc,EACdC,QAAQ,QACH;AACP,SAASC,gBAAgB,QAAQ;AACjC,SAASC,MAAM,QAAQ;AAEvB,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AACjE,SAASC,aAAa,QAAQ;AAK9B,OAAO;AAKP,SAASC,eAAe,QAAQ;AAChC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,eAAe,QAAQ;AAChC,SAASC,YAAY,QAAQ;AAE7B,MAAMC,SAAA,GAAY;AAElB,MAAMC,iBAAA,GAIDC,KAAA;EACH,MAAM;IACJC,YAAY;IACZC,KAAK;IACLA,KAAA,EAAO;MACLC,KAAA,EAAO;QAAEC,SAAS;QAAEC,WAAW;QAAEC,QAAA,EAAUC;MAAiB,CAAE,GAAG,CAAC,CAAC;MACnEC,KAAK;MACLC,SAAS;MACTC;IAAQ,CACT;IACDC,IAAA,EAAM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CmF,WAAA,EAAazB,iBAAA;YACbnD,YAAA,EAAcA,YAAA;YACd6E,UAAA,EAAY9E,KAAA;YACZiC,oBAAA,EAAsBA,oBAAA;YAEtB8C,QAAA,EAAUzB,YAAA;YACVhD,QAAA,EAAUqB,QAAA;YACVR,KAAA,EAAOA;aAHF2C,IAAA,CAAKE,SAAS,CAAC;YAAErD,IAAA;YAAMwB;UAAoB;YAMnDb,UAAA;uBAEHiD,IAAA,CAACzF,qBAAA;QACC0F,eAAA,EAAiBhD,WAAA;QACjBiD,QAAA,eAAUF,IAAA,CAAC5F,gBAAA;UAAiB0B,WAAA,EAAaA,WAAA;UAAaM,IAAA,EAAMA;;;;KAlC3DyC,iBAAA;AAuCX;AAEA,SAASsB,eAAe;EAAEM;AAAK,CAAoB;EACjD;EAEA,oBACEZ,KAAA,CAAC;IAAIhE,SAAA,EAAU;IAAgB6E,IAAA,EAAK;4BAClCV,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAID,KAAA,EAAO;QAAEY,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqCrF,iBAAA","ignoreList":[]}
@@ -0,0 +1,85 @@
1
+ import React from 'react';
2
+ import type { LexicalEditorNodeMap, LexicalEditorViewMap } from '../types.js';
3
+ /**
4
+ * Context for managing richtext editor view state and inheritance.
5
+ */
6
+ type RichTextViewContextType = {
7
+ /**
8
+ * The currently active view name (e.g., 'default', 'frontend', 'debug').
9
+ */
10
+ currentView: string;
11
+ /**
12
+ * The resolved node map for the current view, containing rendering overrides for each node type.
13
+ */
14
+ currentViewMap?: LexicalEditorNodeMap;
15
+ /**
16
+ * True if the current view was explicitly set (via prop) by this provider or an ancestor.
17
+ * Used to distinguish intentional view settings from automatic defaults.
18
+ */
19
+ hasExplicitCurrentView?: boolean;
20
+ /**
21
+ * True if this provider inherited its view from a parent provider.
22
+ * When true, the ViewSelector is hidden because the view is controlled by an ancestor.
23
+ */
24
+ hasInheritedViews?: boolean;
25
+ /**
26
+ * If true, nested richtext editors will inherit this provider's currentView and views.
27
+ */
28
+ inheritable?: boolean;
29
+ /**
30
+ * Function to programmatically change the current view.
31
+ */
32
+ setCurrentView: (view: string) => void;
33
+ /**
34
+ * Map of all available views for this editor. Each key is a view name, each value contains
35
+ * admin config, node overrides, and lexical config for that view.
36
+ */
37
+ views?: LexicalEditorViewMap;
38
+ };
39
+ /**
40
+ * Provider for managing richtext editor view state and its inheritance.
41
+ *
42
+ * Handles two key scenarios:
43
+ * 1. **Explicit view setting**: Wrap with `currentView` and `inheritable={true}` to force nested editors to a specific view
44
+ * 2. **View map inheritance**: Nested editors inherit `views` from parents, allowing view switching across the hierarchy
45
+ *
46
+ * When a nested editor inherits from a parent, its ViewSelector is hidden because the view is controlled by an ancestor.
47
+ *
48
+ * @example
49
+ * Force all nested richtext editors to use "frontend" view:
50
+ * ```tsx
51
+ * <RichTextViewProvider currentView="frontend" inheritable={true}>
52
+ * <MyForm /> {/* All richtext fields inside will use "frontend" view }
53
+ * </RichTextViewProvider>
54
+ * ```
55
+ */
56
+ export declare const RichTextViewProvider: React.FC<{
57
+ children: React.ReactNode;
58
+ currentView?: string;
59
+ inheritable?: boolean;
60
+ views?: LexicalEditorViewMap;
61
+ }>;
62
+ /**
63
+ * Access the current richtext editor view context.
64
+ *
65
+ * Returns the active view name, node overrides, inheritance state, and a function to switch views.
66
+ *
67
+ * @example
68
+ * ```tsx
69
+ * function MyComponent() {
70
+ * const { currentView, currentViewMap, hasInheritedViews, setCurrentView } = useRichTextView()
71
+ *
72
+ * return (
73
+ * <div>
74
+ * <p>Active view: {currentView}</p>
75
+ * {hasInheritedViews && <p>View inherited from parent</p>}
76
+ * {currentViewMap?.heading && <p>Custom heading renderer active</p>}
77
+ * <button onClick={() => setCurrentView('frontend')}>Switch to frontend</button>
78
+ * </div>
79
+ * )
80
+ * }
81
+ * ```
82
+ */
83
+ export declare function useRichTextView(): RichTextViewContextType;
84
+ export {};
85
+ //# sourceMappingURL=RichTextViewProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextViewProvider.d.ts","sourceRoot":"","sources":["../../src/field/RichTextViewProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAA;AAE1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAE7E;;GAEG;AACH,KAAK,uBAAuB,GAAG;IAC7B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAA;IACrC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC;;;OAGG;IACH,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAQD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAC7B,CAgDA,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,IAAI,uBAAuB,CAEzD"}