@payloadcms/richtext-lexical 3.61.0-internal.c252d14 → 3.61.0-internal.dd40839

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 (183) hide show
  1. package/dist/cell/rscEntry.d.ts +2 -10
  2. package/dist/cell/rscEntry.d.ts.map +1 -1
  3. package/dist/cell/rscEntry.js +1 -2
  4. package/dist/cell/rscEntry.js.map +1 -1
  5. package/dist/exports/client/Field-5VLZM7KJ.js +2 -0
  6. package/dist/exports/client/Field-5VLZM7KJ.js.map +7 -0
  7. package/dist/exports/client/RelationshipComponent-UCIWIEVD.js +2 -0
  8. package/dist/exports/client/RelationshipComponent-UCIWIEVD.js.map +7 -0
  9. package/dist/exports/client/bundled.css +1 -1
  10. package/dist/exports/client/chunk-52JG5GGJ.js +2 -0
  11. package/dist/exports/client/chunk-52JG5GGJ.js.map +7 -0
  12. package/dist/exports/client/chunk-U4AOQOHA.js +12 -0
  13. package/dist/exports/client/chunk-U4AOQOHA.js.map +7 -0
  14. package/dist/exports/client/component-5YLBQB5B.js +2 -0
  15. package/dist/exports/client/component-5YLBQB5B.js.map +7 -0
  16. package/dist/exports/client/componentInline-QEXUNJU4.js +2 -0
  17. package/dist/exports/client/index.js +22 -22
  18. package/dist/exports/client/index.js.map +3 -3
  19. package/dist/exports/react/index.d.ts +1 -1
  20. package/dist/exports/react/index.d.ts.map +1 -1
  21. package/dist/exports/react/index.js.map +1 -1
  22. package/dist/features/blocks/client/component/BlockContent.js +1 -1
  23. package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
  24. package/dist/features/blocks/client/component/index.d.ts +1 -0
  25. package/dist/features/blocks/client/component/index.d.ts.map +1 -1
  26. package/dist/features/blocks/client/component/index.js +23 -20
  27. package/dist/features/blocks/client/component/index.js.map +1 -1
  28. package/dist/features/blocks/client/componentInline/index.d.ts +2 -1
  29. package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
  30. package/dist/features/blocks/client/componentInline/index.js +6 -6
  31. package/dist/features/blocks/client/componentInline/index.js.map +1 -1
  32. package/dist/features/blocks/client/nodes/BlocksNode.d.ts +2 -2
  33. package/dist/features/blocks/client/nodes/BlocksNode.d.ts.map +1 -1
  34. package/dist/features/blocks/client/nodes/BlocksNode.js +5 -3
  35. package/dist/features/blocks/client/nodes/BlocksNode.js.map +1 -1
  36. package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts +2 -2
  37. package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts.map +1 -1
  38. package/dist/features/blocks/client/nodes/InlineBlocksNode.js +5 -3
  39. package/dist/features/blocks/client/nodes/InlineBlocksNode.js.map +1 -1
  40. package/dist/features/blocks/server/nodes/BlocksNode.d.ts +2 -1
  41. package/dist/features/blocks/server/nodes/BlocksNode.d.ts.map +1 -1
  42. package/dist/features/blocks/server/nodes/BlocksNode.js +9 -2
  43. package/dist/features/blocks/server/nodes/BlocksNode.js.map +1 -1
  44. package/dist/features/blocks/server/nodes/InlineBlocksNode.d.ts +1 -1
  45. package/dist/features/blocks/server/nodes/InlineBlocksNode.d.ts.map +1 -1
  46. package/dist/features/blocks/server/nodes/InlineBlocksNode.js +6 -5
  47. package/dist/features/blocks/server/nodes/InlineBlocksNode.js.map +1 -1
  48. package/dist/features/converters/lexicalToJSX/Component/index.d.ts +2 -14
  49. package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
  50. package/dist/features/converters/lexicalToJSX/Component/index.js +4 -2
  51. package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
  52. package/dist/features/converters/lexicalToJSX/converter/index.d.ts +16 -1
  53. package/dist/features/converters/lexicalToJSX/converter/index.d.ts.map +1 -1
  54. package/dist/features/converters/lexicalToJSX/converter/index.js +76 -4
  55. package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
  56. package/dist/features/converters/lexicalToJSX/converter/types.d.ts +14 -10
  57. package/dist/features/converters/lexicalToJSX/converter/types.d.ts.map +1 -1
  58. package/dist/features/converters/lexicalToJSX/converter/types.js.map +1 -1
  59. package/dist/features/debug/jsxConverter/client/plugin/index.js +1 -1
  60. package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
  61. package/dist/features/link/nodes/AutoLinkNode.js +1 -1
  62. package/dist/features/link/nodes/AutoLinkNode.js.map +1 -1
  63. package/dist/features/link/nodes/LinkNode.js +1 -1
  64. package/dist/features/link/nodes/LinkNode.js.map +1 -1
  65. package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.d.ts.map +1 -1
  66. package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js +4 -4
  67. package/dist/features/migrations/lexicalPluginToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
  68. package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.d.ts.map +1 -1
  69. package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js +4 -4
  70. package/dist/features/migrations/slateToLexical/nodes/unknownConvertedNode/index.js.map +1 -1
  71. package/dist/features/relationship/client/components/RelationshipComponent.d.ts +1 -1
  72. package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
  73. package/dist/features/relationship/client/components/RelationshipComponent.js +2 -2
  74. package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
  75. package/dist/features/relationship/client/nodes/RelationshipNode.d.ts +1 -1
  76. package/dist/features/relationship/client/nodes/RelationshipNode.d.ts.map +1 -1
  77. package/dist/features/relationship/client/nodes/RelationshipNode.js +3 -2
  78. package/dist/features/relationship/client/nodes/RelationshipNode.js.map +1 -1
  79. package/dist/features/relationship/server/nodes/RelationshipNode.d.ts +2 -1
  80. package/dist/features/relationship/server/nodes/RelationshipNode.d.ts.map +1 -1
  81. package/dist/features/relationship/server/nodes/RelationshipNode.js +9 -2
  82. package/dist/features/relationship/server/nodes/RelationshipNode.js.map +1 -1
  83. package/dist/features/typesServer.d.ts +2 -2
  84. package/dist/features/typesServer.d.ts.map +1 -1
  85. package/dist/features/typesServer.js.map +1 -1
  86. package/dist/features/upload/client/component/index.d.ts +1 -0
  87. package/dist/features/upload/client/component/index.d.ts.map +1 -1
  88. package/dist/features/upload/client/component/index.js +2 -2
  89. package/dist/features/upload/client/component/index.js.map +1 -1
  90. package/dist/features/upload/client/nodes/UploadNode.d.ts +2 -2
  91. package/dist/features/upload/client/nodes/UploadNode.d.ts.map +1 -1
  92. package/dist/features/upload/client/nodes/UploadNode.js +2 -1
  93. package/dist/features/upload/client/nodes/UploadNode.js.map +1 -1
  94. package/dist/features/upload/client/plugin/index.js +2 -2
  95. package/dist/features/upload/client/plugin/index.js.map +1 -1
  96. package/dist/features/upload/server/nodes/UploadNode.d.ts +2 -1
  97. package/dist/features/upload/server/nodes/UploadNode.d.ts.map +1 -1
  98. package/dist/features/upload/server/nodes/UploadNode.js +6 -0
  99. package/dist/features/upload/server/nodes/UploadNode.js.map +1 -1
  100. package/dist/field/Field.d.ts.map +1 -1
  101. package/dist/field/Field.js +50 -38
  102. package/dist/field/Field.js.map +1 -1
  103. package/dist/field/RichTextViewProvider.d.ts +84 -0
  104. package/dist/field/RichTextViewProvider.d.ts.map +1 -0
  105. package/dist/field/RichTextViewProvider.js +92 -0
  106. package/dist/field/RichTextViewProvider.js.map +1 -0
  107. package/dist/field/ViewSelector.d.ts +4 -0
  108. package/dist/field/ViewSelector.d.ts.map +1 -0
  109. package/dist/field/ViewSelector.js +89 -0
  110. package/dist/field/ViewSelector.js.map +1 -0
  111. package/dist/field/bundled.css +1 -1
  112. package/dist/field/index.d.ts.map +1 -1
  113. package/dist/field/index.js +63 -41
  114. package/dist/field/index.js.map +1 -1
  115. package/dist/field/rscEntry.d.ts +2 -3
  116. package/dist/field/rscEntry.d.ts.map +1 -1
  117. package/dist/field/rscEntry.js +15 -1
  118. package/dist/field/rscEntry.js.map +1 -1
  119. package/dist/index.d.ts +1 -1
  120. package/dist/index.d.ts.map +1 -1
  121. package/dist/index.js +9 -24
  122. package/dist/index.js.map +1 -1
  123. package/dist/lexical/LexicalEditor.d.ts.map +1 -1
  124. package/dist/lexical/LexicalEditor.js +2 -1
  125. package/dist/lexical/LexicalEditor.js.map +1 -1
  126. package/dist/lexical/LexicalProvider.d.ts.map +1 -1
  127. package/dist/lexical/LexicalProvider.js +12 -3
  128. package/dist/lexical/LexicalProvider.js.map +1 -1
  129. package/dist/lexical/config/client/loader.d.ts.map +1 -1
  130. package/dist/lexical/config/client/loader.js +2 -4
  131. package/dist/lexical/config/client/loader.js.map +1 -1
  132. package/dist/lexical/nodes/index.d.ts +12 -2
  133. package/dist/lexical/nodes/index.d.ts.map +1 -1
  134. package/dist/lexical/nodes/index.js +195 -2
  135. package/dist/lexical/nodes/index.js.map +1 -1
  136. package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts +2 -0
  137. package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts.map +1 -0
  138. package/dist/lexical/plugins/NodeViewOverridePlugin/index.js +48 -0
  139. package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +1 -0
  140. package/dist/lexical/plugins/handles/utils/setHandlePosition.d.ts.map +1 -1
  141. package/dist/lexical/plugins/handles/utils/setHandlePosition.js +1 -1
  142. package/dist/lexical/plugins/handles/utils/setHandlePosition.js.map +1 -1
  143. package/dist/lexical/theme/EditorTheme.d.ts.map +1 -1
  144. package/dist/lexical/theme/EditorTheme.js +3 -39
  145. package/dist/lexical/theme/EditorTheme.js.map +1 -1
  146. package/dist/lexical/ui/ContentEditable.d.ts.map +1 -1
  147. package/dist/lexical/ui/ContentEditable.js +16 -9
  148. package/dist/lexical/ui/ContentEditable.js.map +1 -1
  149. package/dist/types.d.ts +138 -4
  150. package/dist/types.d.ts.map +1 -1
  151. package/dist/types.js.map +1 -1
  152. package/dist/utilities/editorConfigFactory.js +1 -1
  153. package/dist/utilities/editorConfigFactory.js.map +1 -1
  154. package/dist/utilities/generateImportMap.d.ts +2 -0
  155. package/dist/utilities/generateImportMap.d.ts.map +1 -1
  156. package/dist/utilities/generateImportMap.js +6 -13
  157. package/dist/utilities/generateImportMap.js.map +1 -1
  158. package/dist/{getDefaultSanitizedEditorConfig.d.ts → utilities/getDefaultSanitizedEditorConfig.d.ts} +1 -1
  159. package/dist/utilities/getDefaultSanitizedEditorConfig.d.ts.map +1 -0
  160. package/dist/{getDefaultSanitizedEditorConfig.js → utilities/getDefaultSanitizedEditorConfig.js} +2 -2
  161. package/dist/utilities/getDefaultSanitizedEditorConfig.js.map +1 -0
  162. package/dist/utilities/initLexicalFeatures.d.ts.map +1 -1
  163. package/dist/utilities/initLexicalFeatures.js +12 -13
  164. package/dist/utilities/initLexicalFeatures.js.map +1 -1
  165. package/dist/validate/hasText.d.ts +6 -1
  166. package/dist/validate/hasText.d.ts.map +1 -1
  167. package/dist/validate/hasText.js +10 -4
  168. package/dist/validate/hasText.js.map +1 -1
  169. package/package.json +7 -7
  170. package/dist/exports/client/Field-YYMTSGSP.js +0 -2
  171. package/dist/exports/client/Field-YYMTSGSP.js.map +0 -7
  172. package/dist/exports/client/RelationshipComponent-JXQOFHXF.js +0 -2
  173. package/dist/exports/client/RelationshipComponent-JXQOFHXF.js.map +0 -7
  174. package/dist/exports/client/chunk-ADWHGDDR.js +0 -2
  175. package/dist/exports/client/chunk-ADWHGDDR.js.map +0 -7
  176. package/dist/exports/client/chunk-AFXLIYGL.js +0 -12
  177. package/dist/exports/client/chunk-AFXLIYGL.js.map +0 -7
  178. package/dist/exports/client/component-WT25HAJA.js +0 -2
  179. package/dist/exports/client/component-WT25HAJA.js.map +0 -7
  180. package/dist/exports/client/componentInline-MIPTDFRK.js +0 -2
  181. package/dist/getDefaultSanitizedEditorConfig.d.ts.map +0 -1
  182. package/dist/getDefaultSanitizedEditorConfig.js.map +0 -1
  183. /package/dist/exports/client/{componentInline-MIPTDFRK.js.map → componentInline-QEXUNJU4.js.map} +0 -0
@@ -46,11 +46,12 @@ export class UploadNode extends UploadServerNode {
46
46
  node.setFormat(serializedNode.format);
47
47
  return node;
48
48
  }
49
- decorate() {
49
+ decorate(editor, config) {
50
50
  if (this.__data.pending) {
51
51
  return /*#__PURE__*/_jsx(PendingUploadComponent, {});
52
52
  }
53
53
  return /*#__PURE__*/_jsx(RawUploadComponent, {
54
+ className: config?.theme?.upload ?? 'LexicalEditorTheme__upload',
54
55
  data: this.__data,
55
56
  format: this.__format,
56
57
  nodeKey: this.getKey()
@@ -1 +1 @@
1
- {"version":3,"file":"UploadNode.js","names":["ObjectID","$applyNodeReplacement","React","$convertUploadElement","UploadServerNode","PendingUploadComponent","RawUploadComponent","lazy","then","module","default","UploadComponent","UploadNode","clone","node","getType","importDOM","img","conversion","domNode","$createUploadNode","priority","importJSON","serializedNode","version","value","id","toHexString","importedData","fields","pending","relationTo","data","setFormat","format","decorate","__data","_jsx","__format","nodeKey","getKey","exportJSON","$isUploadNode"],"sources":["../../../../../src/features/upload/client/nodes/UploadNode.tsx"],"sourcesContent":["'use client'\nimport type { DOMConversionMap, LexicalNode } from 'lexical'\nimport type { JSX } from 'react'\n\nimport ObjectID from 'bson-objectid'\nimport { $applyNodeReplacement } from 'lexical'\nimport * as React from 'react'\n\nimport type {\n Internal_UploadData,\n SerializedUploadNode,\n UploadData,\n} from '../../server/nodes/UploadNode.js'\n\nimport { $convertUploadElement } from '../../server/nodes/conversions.js'\nimport { UploadServerNode } from '../../server/nodes/UploadNode.js'\nimport { PendingUploadComponent } from '../component/pending/index.js'\n\nconst RawUploadComponent = React.lazy(() =>\n import('../../client/component/index.js').then((module) => ({ default: module.UploadComponent })),\n)\n\nexport class UploadNode extends UploadServerNode {\n static override clone(node: UploadServerNode): UploadServerNode {\n return super.clone(node)\n }\n\n static override getType(): string {\n return super.getType()\n }\n\n static override importDOM(): DOMConversionMap<HTMLImageElement> {\n return {\n img: (node) => ({\n conversion: (domNode) => $convertUploadElement(domNode, $createUploadNode),\n priority: 0,\n }),\n }\n }\n\n static override importJSON(serializedNode: SerializedUploadNode): UploadNode {\n if (serializedNode.version === 1 && (serializedNode?.value as unknown as { id: string })?.id) {\n serializedNode.value = (serializedNode.value as unknown as { id: string }).id\n }\n if (serializedNode.version === 2 && !serializedNode?.id) {\n serializedNode.id = new ObjectID.default().toHexString()\n serializedNode.version = 3\n }\n\n const importedData: Internal_UploadData = {\n id: serializedNode.id,\n fields: serializedNode.fields,\n pending: (serializedNode as Internal_UploadData).pending,\n relationTo: serializedNode.relationTo,\n value: serializedNode.value,\n }\n\n const node = $createUploadNode({ data: importedData })\n node.setFormat(serializedNode.format)\n\n return node\n }\n\n override decorate(): JSX.Element {\n if ((this.__data as Internal_UploadData).pending) {\n return <PendingUploadComponent />\n }\n return <RawUploadComponent data={this.__data} format={this.__format} nodeKey={this.getKey()} />\n }\n\n override exportJSON(): SerializedUploadNode {\n return super.exportJSON()\n }\n}\n\nexport function $createUploadNode({\n data,\n}: {\n data: Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>\n}): UploadNode {\n if (!data?.id) {\n data.id = new ObjectID.default().toHexString()\n }\n\n return $applyNodeReplacement(new UploadNode({ data: data as UploadData }))\n}\n\nexport function $isUploadNode(node: LexicalNode | null | undefined): node is UploadNode {\n return node instanceof UploadNode\n}\n"],"mappings":"AAAA;;;AAIA,OAAOA,QAAA,MAAc;AACrB,SAASC,qBAAqB,QAAQ;AACtC,YAAYC,KAAA,MAAW;AAQvB,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,sBAAsB,QAAQ;AAEvC,MAAMC,kBAAA,gBAAqBJ,KAAA,CAAMK,IAAI,CAAC,MACpC,MAAM,CAAC,mCAAmCC,IAAI,CAAEC,MAAA,KAAY;EAAEC,OAAA,EAASD,MAAA,CAAOE;AAAgB;AAGhG,OAAO,MAAMC,UAAA,SAAmBR,gBAAA;EAC9B,OAAgBS,MAAMC,IAAsB,EAAoB;IAC9D,OAAO,KAAK,CAACD,KAAA,CAAMC,IAAA;EACrB;EAEA,OAAgBC,QAAA,EAAkB;IAChC,OAAO,KAA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;EAESC,WAAA,EAAmC;IAC1C,OAAO,KAAK,CAACA,UAAA;EACf;AACF;AAEA,OAAO,SAASrB,kBAAkB;EAChCY;AAAI,CAGL;EACC,IAAI,CAACA,IAAA,EAAMN,EAAA,EAAI;IACbM,IAAA,CAAKN,EAAE,GAAG,IAAI1B,QAAA,CAASU,OAAO,GAAGiB,WAAW;EAC9C;EAEA,OAAO1B,qBAAA,CAAsB,IAAIW,UAAA,CAAW;IAAEoB,IAAA,EAAMA;EAAmB;AACzE;AAEA,OAAO,SAASU,cAAc5B,IAAoC;EAChE,OAAOA,IAAA,YAAgBF,UAAA;AACzB","ignoreList":[]}
1
+ {"version":3,"file":"UploadNode.js","names":["ObjectID","$applyNodeReplacement","React","$convertUploadElement","UploadServerNode","PendingUploadComponent","RawUploadComponent","lazy","then","module","default","UploadComponent","UploadNode","clone","node","getType","importDOM","img","conversion","domNode","$createUploadNode","priority","importJSON","serializedNode","version","value","id","toHexString","importedData","fields","pending","relationTo","data","setFormat","format","decorate","editor","config","__data","_jsx","className","theme","upload","__format","nodeKey","getKey","exportJSON","$isUploadNode"],"sources":["../../../../../src/features/upload/client/nodes/UploadNode.tsx"],"sourcesContent":["'use client'\nimport type { DOMConversionMap, EditorConfig, LexicalEditor, LexicalNode } from 'lexical'\nimport type { JSX } from 'react'\n\nimport ObjectID from 'bson-objectid'\nimport { $applyNodeReplacement } from 'lexical'\nimport * as React from 'react'\n\nimport type {\n Internal_UploadData,\n SerializedUploadNode,\n UploadData,\n} from '../../server/nodes/UploadNode.js'\n\nimport { $convertUploadElement } from '../../server/nodes/conversions.js'\nimport { UploadServerNode } from '../../server/nodes/UploadNode.js'\nimport { PendingUploadComponent } from '../component/pending/index.js'\n\nconst RawUploadComponent = React.lazy(() =>\n import('../../client/component/index.js').then((module) => ({ default: module.UploadComponent })),\n)\n\nexport class UploadNode extends UploadServerNode {\n static override clone(node: UploadServerNode): UploadServerNode {\n return super.clone(node)\n }\n\n static override getType(): string {\n return super.getType()\n }\n\n static override importDOM(): DOMConversionMap<HTMLImageElement> {\n return {\n img: (node) => ({\n conversion: (domNode) => $convertUploadElement(domNode, $createUploadNode),\n priority: 0,\n }),\n }\n }\n\n static override importJSON(serializedNode: SerializedUploadNode): UploadNode {\n if (serializedNode.version === 1 && (serializedNode?.value as unknown as { id: string })?.id) {\n serializedNode.value = (serializedNode.value as unknown as { id: string }).id\n }\n if (serializedNode.version === 2 && !serializedNode?.id) {\n serializedNode.id = new ObjectID.default().toHexString()\n serializedNode.version = 3\n }\n\n const importedData: Internal_UploadData = {\n id: serializedNode.id,\n fields: serializedNode.fields,\n pending: (serializedNode as Internal_UploadData).pending,\n relationTo: serializedNode.relationTo,\n value: serializedNode.value,\n }\n\n const node = $createUploadNode({ data: importedData })\n node.setFormat(serializedNode.format)\n\n return node\n }\n\n override decorate(editor?: LexicalEditor, config?: EditorConfig): JSX.Element {\n if ((this.__data as Internal_UploadData).pending) {\n return <PendingUploadComponent />\n }\n return (\n <RawUploadComponent\n className={config?.theme?.upload ?? 'LexicalEditorTheme__upload'}\n data={this.__data}\n format={this.__format}\n nodeKey={this.getKey()}\n />\n )\n }\n\n override exportJSON(): SerializedUploadNode {\n return super.exportJSON()\n }\n}\n\nexport function $createUploadNode({\n data,\n}: {\n data: Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>\n}): UploadNode {\n if (!data?.id) {\n data.id = new ObjectID.default().toHexString()\n }\n\n return $applyNodeReplacement(new UploadNode({ data: data as UploadData }))\n}\n\nexport function $isUploadNode(node: LexicalNode | null | undefined): node is UploadNode {\n return node instanceof UploadNode\n}\n"],"mappings":"AAAA;;;AAIA,OAAOA,QAAA,MAAc;AACrB,SAASC,qBAAqB,QAAQ;AACtC,YAAYC,KAAA,MAAW;AAQvB,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,sBAAsB,QAAQ;AAEvC,MAAMC,kBAAA,gBAAqBJ,KAAA,CAAMK,IAAI,CAAC,MACpC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C,MAAsB,EAAEC,MAAqB,EAAe;IAC5E,IAAI,IAAK,CAACC,MAAM,CAAyBR,OAAO,EAAE;MAChD,oBAAOS,IAAA,CAAClC,sBAAA;IACV;IACA,oBACEkC,IAAA,CAACjC,kBAAA;MACCkC,SAAA,EAAWH,MAAA,EAAQI,KAAA,EAAOC,MAAA,IAAU;MACpCV,IAAA,EAAM,IAAI,CAACM,MAAM;MACjBJ,MAAA,EAAQ,IAAI,CAACS,QAAQ;MACrBC,OAAA,EAAS,IAAI,CAACC,MAAM;;EAG1B;EAESC,WAAA,EAAmC;IAC1C,OAAO,KAAK,CAACA,UAAA;EACf;AACF;AAEA,OAAO,SAAS1B,kBAAkB;EAChCY;AAAI,CAGL;EACC,IAAI,CAACA,IAAA,EAAMN,EAAA,EAAI;IACbM,IAAA,CAAKN,EAAE,GAAG,IAAI1B,QAAA,CAASU,OAAO,GAAGiB,WAAW;EAC9C;EAEA,OAAO1B,qBAAA,CAAsB,IAAIW,UAAA,CAAW;IAAEoB,IAAA,EAAMA;EAAmB;AACzE;AAEA,OAAO,SAASe,cAAcjC,IAAoC;EAChE,OAAOA,IAAA,YAAgBF,UAAA;AACzB","ignoreList":[]}
@@ -229,7 +229,7 @@ export const UploadPlugin = t0 => {
229
229
  const selection_0 = $getSelection() || $getPreviousSelection();
230
230
  if ($isRangeSelection(selection_0)) {
231
231
  for (const file_3 of files_0) {
232
- const pendingUploadNode = new UploadNode({
232
+ const pendingUploadNode = $createUploadNode({
233
233
  data: {
234
234
  pending: {
235
235
  formID: file_3.formID,
@@ -284,7 +284,7 @@ export const UploadPlugin = t0 => {
284
284
  }
285
285
  $setSelection(selection_1);
286
286
  for (const file_5 of files_1) {
287
- const pendingUploadNode_0 = new UploadNode({
287
+ const pendingUploadNode_0 = $createUploadNode({
288
288
  data: {
289
289
  pending: {
290
290
  formID: file_5.formID,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$dfsIterator","$insertNodeToNearestRoot","mergeRegister","useBulkUpload","useEffectEvent","useModal","ObjectID","$createRangeSelection","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","$setSelection","COMMAND_PRIORITY_EDITOR","COMMAND_PRIORITY_LOW","createCommand","DROP_COMMAND","getDOMSelectionFromTarget","isHTMLElement","PASTE_COMMAND","React","useEffect","useEnabledRelationships","UploadDrawer","$createUploadNode","$isUploadNode","UploadNode","canDropImage","event","target","closest","parentElement","getDragSelection","range","domSelection","document","caretRangeFromPoint","clientX","clientY","rangeParent","collapse","rangeOffset","getRangeAt","Error","INSERT_UPLOAD_COMMAND","UploadPlugin","t0","$","clientProps","editor","t1","disabledCollections","t2","enabledCollections","t3","collectionSlugsBlacklist","collectionSlugsWhitelist","uploads","enabledCollectionSlugs","drawerSlug","bulkUploadDrawerSlug","setCollectionSlug","setInitialForms","setOnCancel","setOnSuccess","setSelectableCollections","isModalOpen","openModal","t4","t5","files","length","initialForms","map","_temp","update","_temp2","newDocs","newDocsMap","Map","_temp3","dfsNode_0","node_0","dfsNode","node","nodeData_0","getData","nodeData","pending","newDoc","get","formID","replace","data","id","default","toHexString","fields","relationTo","collectionSlug","value","doc","openBulkUpload","hasNodes","registerNodeTransform","node_1","nodeData_1","upload","transformedImage","src","startsWith","mimeMatch","match","mimeType","base64Data","byteCharacters","atob","byteNumbers","Array","i","charCodeAt","byteArray","Uint8Array","file_0","File","split","type","file","res","fetch","blob","inferredFileName","pop","file_1","registerCommand","payload","selection","uploadNode","focus","focusNode","getNode","__first","remove","ClipboardEvent","clipboardData","types","includes","files_0","from","forEach","file_2","push","alt","selection_0","file_3","pendingUploadNode","URL","createObjectURL","focus_0","focusNode_0","event_0","DragEvent","dt","dataTransfer","files_1","file_4","preventDefault","stopPropagation","selection_1","undefined","applyDOMRange","file_5","pendingUploadNode_0","focus_1","focusNode_1","t6","t7","_jsx"],"sources":["../../../../../src/features/upload/client/plugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $dfsIterator, $insertNodeToNearestRoot, mergeRegister } from '@lexical/utils'\nimport { useBulkUpload, useEffectEvent, useModal } from '@payloadcms/ui'\nimport ObjectID from 'bson-objectid'\nimport {\n $createRangeSelection,\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n $setSelection,\n COMMAND_PRIORITY_EDITOR,\n COMMAND_PRIORITY_LOW,\n createCommand,\n DROP_COMMAND,\n getDOMSelectionFromTarget,\n isHTMLElement,\n PASTE_COMMAND,\n} from 'lexical'\nimport React, { useEffect } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { Internal_UploadData, UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../index.js'\n\nimport { useEnabledRelationships } from '../../../relationship/client/utils/useEnabledRelationships.js'\nimport { UploadDrawer } from '../drawer/index.js'\nimport { $createUploadNode, $isUploadNode, UploadNode } from '../nodes/UploadNode.js'\n\nexport type InsertUploadPayload = Readonly<Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>>\n\ndeclare global {\n interface DragEvent {\n rangeOffset?: number\n rangeParent?: Node\n }\n}\n\nfunction canDropImage(event: DragEvent): boolean {\n const target = event.target\n return !!(\n isHTMLElement(target) &&\n !target.closest('code, span.editor-image') &&\n isHTMLElement(target.parentElement) &&\n target.parentElement.closest('div.ContentEditable__root')\n )\n}\n\nfunction getDragSelection(event: DragEvent): null | Range | undefined {\n // Source: https://github.com/AlessioGr/lexical/blob/main/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx\n let range\n const domSelection = getDOMSelectionFromTarget(event.target)\n if (document.caretRangeFromPoint) {\n range = document.caretRangeFromPoint(event.clientX, event.clientY)\n } else if (event.rangeParent && domSelection !== null) {\n domSelection.collapse(event.rangeParent, event.rangeOffset || 0)\n range = domSelection.getRangeAt(0)\n } else {\n throw Error(`Cannot get the selection when dragging`)\n }\n\n return range\n}\n\nexport const INSERT_UPLOAD_COMMAND: LexicalCommand<InsertUploadPayload> =\n createCommand('INSERT_UPLOAD_COMMAND')\n\ntype FileToUpload = {\n alt?: string\n file: File\n /**\n * Bulk Upload Form ID that should be created, which can then be matched\n * against the node formID if the upload is successful\n */\n formID: string\n}\n\nexport const UploadPlugin: PluginComponent<UploadFeaturePropsClient> = ({ clientProps }) => {\n const [editor] = useLexicalComposerContext()\n\n const { enabledCollectionSlugs } = useEnabledRelationships({\n collectionSlugsBlacklist: clientProps?.disabledCollections,\n collectionSlugsWhitelist: clientProps?.enabledCollections,\n uploads: true,\n })\n\n const {\n drawerSlug: bulkUploadDrawerSlug,\n setCollectionSlug,\n setInitialForms,\n setOnCancel,\n setOnSuccess,\n setSelectableCollections,\n } = useBulkUpload()\n\n const { isModalOpen, openModal } = useModal()\n\n const openBulkUpload = useEffectEvent(({ files }: { files: FileToUpload[] }) => {\n if (files?.length === 0) {\n return\n }\n\n setInitialForms((initialForms) => [\n ...(initialForms ?? []),\n ...files.map((file) => ({\n file: file.file,\n formID: file.formID,\n })),\n ])\n\n if (!isModalOpen(bulkUploadDrawerSlug)) {\n if (!enabledCollectionSlugs.length || !enabledCollectionSlugs[0]) {\n return\n }\n\n setCollectionSlug(enabledCollectionSlugs[0])\n setSelectableCollections(enabledCollectionSlugs)\n\n setOnCancel(() => {\n // Remove all the pending upload nodes that were added but not uploaded\n editor.update(() => {\n for (const dfsNode of $dfsIterator()) {\n const node = dfsNode.node\n\n if ($isUploadNode(node)) {\n const nodeData = node.getData()\n if ((nodeData as Internal_UploadData)?.pending) {\n node.remove()\n }\n }\n }\n })\n })\n\n setOnSuccess((newDocs) => {\n const newDocsMap = new Map(newDocs.map((doc) => [doc.formID, doc]))\n editor.update(() => {\n for (const dfsNode of $dfsIterator()) {\n const node = dfsNode.node\n if ($isUploadNode(node)) {\n const nodeData: Internal_UploadData = node.getData()\n\n if (nodeData?.pending) {\n const newDoc = newDocsMap.get(nodeData.pending?.formID)\n if (newDoc) {\n node.replace(\n $createUploadNode({\n data: {\n id: new ObjectID.default().toHexString(),\n fields: {},\n relationTo: newDoc.collectionSlug,\n value: newDoc.doc.id,\n } as UploadData,\n }),\n )\n }\n }\n }\n }\n })\n })\n\n openModal(bulkUploadDrawerSlug)\n }\n })\n\n useEffect(() => {\n if (!editor.hasNodes([UploadNode])) {\n throw new Error('UploadPlugin: UploadNode not registered on editor')\n }\n\n return mergeRegister(\n /**\n * Handle auto-uploading files if you copy & paste an image dom element from the clipboard\n */\n editor.registerNodeTransform(UploadNode, (node) => {\n const nodeData: Internal_UploadData = node.getData()\n if (!nodeData?.pending) {\n return\n }\n\n async function upload() {\n let transformedImage: FileToUpload | null = null\n\n const src = nodeData?.pending?.src\n const formID = nodeData?.pending?.formID as string\n\n if (src?.startsWith('data:')) {\n // It's a base64-encoded image\n const mimeMatch = src.match(/data:(image\\/[a-zA-Z]+);base64,/)\n const mimeType = mimeMatch ? mimeMatch[1] : 'image/png' // Default to PNG if MIME type not found\n const base64Data = src.replace(/^data:image\\/[a-zA-Z]+;base64,/, '')\n const byteCharacters = atob(base64Data)\n const byteNumbers = new Array(byteCharacters.length)\n for (let i = 0; i < byteCharacters.length; i++) {\n byteNumbers[i] = byteCharacters.charCodeAt(i)\n }\n const byteArray = new Uint8Array(byteNumbers)\n const file = new File([byteArray], 'pasted-image.' + mimeType?.split('/', 2)[1], {\n type: mimeType,\n })\n transformedImage = { alt: undefined, file, formID }\n } else if (src?.startsWith('http') || src?.startsWith('https')) {\n // It's an image URL\n const res = await fetch(src)\n const blob = await res.blob()\n const inferredFileName =\n src.split('/').pop() || 'pasted-image' + blob.type.split('/', 2)[1]\n const file = new File([blob], inferredFileName, {\n type: blob.type,\n })\n\n transformedImage = { alt: undefined, file, formID }\n }\n\n if (!transformedImage) {\n return\n }\n\n openBulkUpload({ files: [transformedImage] })\n }\n void upload()\n }),\n editor.registerCommand<InsertUploadPayload>(\n INSERT_UPLOAD_COMMAND,\n (payload: InsertUploadPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const uploadNode = $createUploadNode({\n data: {\n id: payload.id,\n fields: payload.fields,\n relationTo: payload.relationTo,\n value: payload.value,\n },\n })\n // we need to get the focus node before inserting the block node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(uploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n PASTE_COMMAND,\n (event) => {\n // Pending UploadNodes are automatically created when importDOM is called. However, if you paste a file from your computer\n // directly, importDOM won't be called, as it's not a HTML dom element. So we need to handle that case here.\n\n if (!(event instanceof ClipboardEvent)) {\n return false\n }\n const clipboardData = event.clipboardData\n\n if (!clipboardData?.types?.length || clipboardData?.types?.includes('text/html')) {\n // HTML is handled through importDOM => registerNodeTransform for pending UploadNode\n return false\n }\n\n const files: FileToUpload[] = []\n if (clipboardData?.files?.length) {\n Array.from(clipboardData.files).forEach((file) => {\n files.push({\n alt: '',\n file,\n formID: new ObjectID.default().toHexString(),\n })\n })\n }\n\n if (files.length) {\n // Insert a pending UploadNode for each image\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n for (const file of files) {\n const pendingUploadNode = new UploadNode({\n data: {\n pending: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\n } as Internal_UploadData,\n })\n // we need to get the focus node before inserting the upload node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(pendingUploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n }\n })\n\n // Open the bulk drawer - the node transform will not open it for us, as it does not handle blob/file uploads\n openBulkUpload({ files })\n\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n // Handle drag & drop of files from the desktop into the editor\n editor.registerCommand(\n DROP_COMMAND,\n (event) => {\n if (!(event instanceof DragEvent)) {\n return false\n }\n\n const dt = event.dataTransfer\n\n if (!dt?.types?.length) {\n return false\n }\n\n const files: FileToUpload[] = []\n if (dt?.files?.length) {\n Array.from(dt.files).forEach((file) => {\n files.push({\n alt: '',\n file,\n formID: new ObjectID.default().toHexString(),\n })\n })\n }\n\n if (files.length) {\n // Prevent the default browser drop handling, which would open the file in the browser\n event.preventDefault()\n event.stopPropagation()\n\n // Insert a PendingUploadNode for each image\n editor.update(() => {\n if (canDropImage(event)) {\n const range = getDragSelection(event)\n const selection = $createRangeSelection()\n if (range !== null && range !== undefined) {\n selection.applyDOMRange(range)\n }\n $setSelection(selection)\n\n for (const file of files) {\n const pendingUploadNode = new UploadNode({\n data: {\n pending: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\n } as Internal_UploadData,\n })\n // we need to get the focus node before inserting the upload node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(pendingUploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n }\n })\n\n // Open the bulk drawer - the node transform will not open it for us, as it does not handle blob/file uploads\n openBulkUpload({ files })\n\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor])\n\n return <UploadDrawer enabledCollectionSlugs={enabledCollectionSlugs} />\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA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AA,EAAA,GAAAhI,CAAA;EAAA;EArOX1B,SAAA,CAAUgD,EAqOV,EAAG0G,EAAQ;EAAA,IAAAC,EAAA;EAAA,IAAAjI,CAAA,SAAAW,sBAAA;IAEJsH,EAAA,GAAAC,IAAA,CAAA1J,YAAA;MAAAmC;IAAA,C;;;;;;SAAAsH,E;CACT;AAjUuE,SAAAtG,MAAAqD,IAAA;EAAA;IAAAA,IAAA,EA4BzDA,IAAA,CAAAA,IAAA;IAAApC,MAAA,EACEoC,IAAA,CAAApC;EAAA;AAAA;AA7BuD,SAAAf,OAAA;EAAA,KA4CxD,MAAAO,OAAM,IAAWnF,YAAA;IACpB,MAAAoF,IAAA,GAAaD,OAAA,CAAAC,IAAA;IAAY,IAErB3D,aAAA,CAAc2D,IAAA;MAChB,MAAAG,QAAA,GAAiBH,IAAA,CAAAE,OAAA,CAAY;MAAA,IACxBC,QAAA,EAAAC,OAAA;QACHJ,IAAA,CAAA0D,MAAA,CAAW;MAAA;IAAA;EAAA;AAAA;AAlD4C,SAAA9D,OAAAqB,GAAA;EAAA,QA0DdA,GAAA,CAAAV,MAAA,EAAYU,GAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$dfsIterator","$insertNodeToNearestRoot","mergeRegister","useBulkUpload","useEffectEvent","useModal","ObjectID","$createRangeSelection","$getPreviousSelection","$getSelection","$isParagraphNode","$isRangeSelection","$setSelection","COMMAND_PRIORITY_EDITOR","COMMAND_PRIORITY_LOW","createCommand","DROP_COMMAND","getDOMSelectionFromTarget","isHTMLElement","PASTE_COMMAND","React","useEffect","useEnabledRelationships","UploadDrawer","$createUploadNode","$isUploadNode","UploadNode","canDropImage","event","target","closest","parentElement","getDragSelection","range","domSelection","document","caretRangeFromPoint","clientX","clientY","rangeParent","collapse","rangeOffset","getRangeAt","Error","INSERT_UPLOAD_COMMAND","UploadPlugin","t0","$","clientProps","editor","t1","disabledCollections","t2","enabledCollections","t3","collectionSlugsBlacklist","collectionSlugsWhitelist","uploads","enabledCollectionSlugs","drawerSlug","bulkUploadDrawerSlug","setCollectionSlug","setInitialForms","setOnCancel","setOnSuccess","setSelectableCollections","isModalOpen","openModal","t4","t5","files","length","initialForms","map","_temp","update","_temp2","newDocs","newDocsMap","Map","_temp3","dfsNode_0","node_0","dfsNode","node","nodeData_0","getData","nodeData","pending","newDoc","get","formID","replace","data","id","default","toHexString","fields","relationTo","collectionSlug","value","doc","openBulkUpload","hasNodes","registerNodeTransform","node_1","nodeData_1","upload","transformedImage","src","startsWith","mimeMatch","match","mimeType","base64Data","byteCharacters","atob","byteNumbers","Array","i","charCodeAt","byteArray","Uint8Array","file_0","File","split","type","file","res","fetch","blob","inferredFileName","pop","file_1","registerCommand","payload","selection","uploadNode","focus","focusNode","getNode","__first","remove","ClipboardEvent","clipboardData","types","includes","files_0","from","forEach","file_2","push","alt","selection_0","file_3","pendingUploadNode","URL","createObjectURL","focus_0","focusNode_0","event_0","DragEvent","dt","dataTransfer","files_1","file_4","preventDefault","stopPropagation","selection_1","undefined","applyDOMRange","file_5","pendingUploadNode_0","focus_1","focusNode_1","t6","t7","_jsx"],"sources":["../../../../../src/features/upload/client/plugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalCommand } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $dfsIterator, $insertNodeToNearestRoot, mergeRegister } from '@lexical/utils'\nimport { useBulkUpload, useEffectEvent, useModal } from '@payloadcms/ui'\nimport ObjectID from 'bson-objectid'\nimport {\n $createRangeSelection,\n $getPreviousSelection,\n $getSelection,\n $isParagraphNode,\n $isRangeSelection,\n $setSelection,\n COMMAND_PRIORITY_EDITOR,\n COMMAND_PRIORITY_LOW,\n createCommand,\n DROP_COMMAND,\n getDOMSelectionFromTarget,\n isHTMLElement,\n PASTE_COMMAND,\n} from 'lexical'\nimport React, { useEffect } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { Internal_UploadData, UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../index.js'\n\nimport { useEnabledRelationships } from '../../../relationship/client/utils/useEnabledRelationships.js'\nimport { UploadDrawer } from '../drawer/index.js'\nimport { $createUploadNode, $isUploadNode, UploadNode } from '../nodes/UploadNode.js'\n\nexport type InsertUploadPayload = Readonly<Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>>\n\ndeclare global {\n interface DragEvent {\n rangeOffset?: number\n rangeParent?: Node\n }\n}\n\nfunction canDropImage(event: DragEvent): boolean {\n const target = event.target\n return !!(\n isHTMLElement(target) &&\n !target.closest('code, span.editor-image') &&\n isHTMLElement(target.parentElement) &&\n target.parentElement.closest('div.ContentEditable__root')\n )\n}\n\nfunction getDragSelection(event: DragEvent): null | Range | undefined {\n // Source: https://github.com/AlessioGr/lexical/blob/main/packages/lexical-playground/src/plugins/ImagesPlugin/index.tsx\n let range\n const domSelection = getDOMSelectionFromTarget(event.target)\n if (document.caretRangeFromPoint) {\n range = document.caretRangeFromPoint(event.clientX, event.clientY)\n } else if (event.rangeParent && domSelection !== null) {\n domSelection.collapse(event.rangeParent, event.rangeOffset || 0)\n range = domSelection.getRangeAt(0)\n } else {\n throw Error(`Cannot get the selection when dragging`)\n }\n\n return range\n}\n\nexport const INSERT_UPLOAD_COMMAND: LexicalCommand<InsertUploadPayload> =\n createCommand('INSERT_UPLOAD_COMMAND')\n\ntype FileToUpload = {\n alt?: string\n file: File\n /**\n * Bulk Upload Form ID that should be created, which can then be matched\n * against the node formID if the upload is successful\n */\n formID: string\n}\n\nexport const UploadPlugin: PluginComponent<UploadFeaturePropsClient> = ({ clientProps }) => {\n const [editor] = useLexicalComposerContext()\n\n const { enabledCollectionSlugs } = useEnabledRelationships({\n collectionSlugsBlacklist: clientProps?.disabledCollections,\n collectionSlugsWhitelist: clientProps?.enabledCollections,\n uploads: true,\n })\n\n const {\n drawerSlug: bulkUploadDrawerSlug,\n setCollectionSlug,\n setInitialForms,\n setOnCancel,\n setOnSuccess,\n setSelectableCollections,\n } = useBulkUpload()\n\n const { isModalOpen, openModal } = useModal()\n\n const openBulkUpload = useEffectEvent(({ files }: { files: FileToUpload[] }) => {\n if (files?.length === 0) {\n return\n }\n\n setInitialForms((initialForms) => [\n ...(initialForms ?? []),\n ...files.map((file) => ({\n file: file.file,\n formID: file.formID,\n })),\n ])\n\n if (!isModalOpen(bulkUploadDrawerSlug)) {\n if (!enabledCollectionSlugs.length || !enabledCollectionSlugs[0]) {\n return\n }\n\n setCollectionSlug(enabledCollectionSlugs[0])\n setSelectableCollections(enabledCollectionSlugs)\n\n setOnCancel(() => {\n // Remove all the pending upload nodes that were added but not uploaded\n editor.update(() => {\n for (const dfsNode of $dfsIterator()) {\n const node = dfsNode.node\n\n if ($isUploadNode(node)) {\n const nodeData = node.getData()\n if ((nodeData as Internal_UploadData)?.pending) {\n node.remove()\n }\n }\n }\n })\n })\n\n setOnSuccess((newDocs) => {\n const newDocsMap = new Map(newDocs.map((doc) => [doc.formID, doc]))\n editor.update(() => {\n for (const dfsNode of $dfsIterator()) {\n const node = dfsNode.node\n if ($isUploadNode(node)) {\n const nodeData: Internal_UploadData = node.getData()\n\n if (nodeData?.pending) {\n const newDoc = newDocsMap.get(nodeData.pending?.formID)\n if (newDoc) {\n node.replace(\n $createUploadNode({\n data: {\n id: new ObjectID.default().toHexString(),\n fields: {},\n relationTo: newDoc.collectionSlug,\n value: newDoc.doc.id,\n } as UploadData,\n }),\n )\n }\n }\n }\n }\n })\n })\n\n openModal(bulkUploadDrawerSlug)\n }\n })\n\n useEffect(() => {\n if (!editor.hasNodes([UploadNode])) {\n throw new Error('UploadPlugin: UploadNode not registered on editor')\n }\n\n return mergeRegister(\n /**\n * Handle auto-uploading files if you copy & paste an image dom element from the clipboard\n */\n editor.registerNodeTransform(UploadNode, (node) => {\n const nodeData: Internal_UploadData = node.getData()\n if (!nodeData?.pending) {\n return\n }\n\n async function upload() {\n let transformedImage: FileToUpload | null = null\n\n const src = nodeData?.pending?.src\n const formID = nodeData?.pending?.formID as string\n\n if (src?.startsWith('data:')) {\n // It's a base64-encoded image\n const mimeMatch = src.match(/data:(image\\/[a-zA-Z]+);base64,/)\n const mimeType = mimeMatch ? mimeMatch[1] : 'image/png' // Default to PNG if MIME type not found\n const base64Data = src.replace(/^data:image\\/[a-zA-Z]+;base64,/, '')\n const byteCharacters = atob(base64Data)\n const byteNumbers = new Array(byteCharacters.length)\n for (let i = 0; i < byteCharacters.length; i++) {\n byteNumbers[i] = byteCharacters.charCodeAt(i)\n }\n const byteArray = new Uint8Array(byteNumbers)\n const file = new File([byteArray], 'pasted-image.' + mimeType?.split('/', 2)[1], {\n type: mimeType,\n })\n transformedImage = { alt: undefined, file, formID }\n } else if (src?.startsWith('http') || src?.startsWith('https')) {\n // It's an image URL\n const res = await fetch(src)\n const blob = await res.blob()\n const inferredFileName =\n src.split('/').pop() || 'pasted-image' + blob.type.split('/', 2)[1]\n const file = new File([blob], inferredFileName, {\n type: blob.type,\n })\n\n transformedImage = { alt: undefined, file, formID }\n }\n\n if (!transformedImage) {\n return\n }\n\n openBulkUpload({ files: [transformedImage] })\n }\n void upload()\n }),\n editor.registerCommand<InsertUploadPayload>(\n INSERT_UPLOAD_COMMAND,\n (payload: InsertUploadPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const uploadNode = $createUploadNode({\n data: {\n id: payload.id,\n fields: payload.fields,\n relationTo: payload.relationTo,\n value: payload.value,\n },\n })\n // we need to get the focus node before inserting the block node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(uploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n PASTE_COMMAND,\n (event) => {\n // Pending UploadNodes are automatically created when importDOM is called. However, if you paste a file from your computer\n // directly, importDOM won't be called, as it's not a HTML dom element. So we need to handle that case here.\n\n if (!(event instanceof ClipboardEvent)) {\n return false\n }\n const clipboardData = event.clipboardData\n\n if (!clipboardData?.types?.length || clipboardData?.types?.includes('text/html')) {\n // HTML is handled through importDOM => registerNodeTransform for pending UploadNode\n return false\n }\n\n const files: FileToUpload[] = []\n if (clipboardData?.files?.length) {\n Array.from(clipboardData.files).forEach((file) => {\n files.push({\n alt: '',\n file,\n formID: new ObjectID.default().toHexString(),\n })\n })\n }\n\n if (files.length) {\n // Insert a pending UploadNode for each image\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n for (const file of files) {\n const pendingUploadNode = $createUploadNode({\n data: {\n pending: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\n } as Internal_UploadData,\n })\n // we need to get the focus node before inserting the upload node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(pendingUploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n }\n })\n\n // Open the bulk drawer - the node transform will not open it for us, as it does not handle blob/file uploads\n openBulkUpload({ files })\n\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n // Handle drag & drop of files from the desktop into the editor\n editor.registerCommand(\n DROP_COMMAND,\n (event) => {\n if (!(event instanceof DragEvent)) {\n return false\n }\n\n const dt = event.dataTransfer\n\n if (!dt?.types?.length) {\n return false\n }\n\n const files: FileToUpload[] = []\n if (dt?.files?.length) {\n Array.from(dt.files).forEach((file) => {\n files.push({\n alt: '',\n file,\n formID: new ObjectID.default().toHexString(),\n })\n })\n }\n\n if (files.length) {\n // Prevent the default browser drop handling, which would open the file in the browser\n event.preventDefault()\n event.stopPropagation()\n\n // Insert a PendingUploadNode for each image\n editor.update(() => {\n if (canDropImage(event)) {\n const range = getDragSelection(event)\n const selection = $createRangeSelection()\n if (range !== null && range !== undefined) {\n selection.applyDOMRange(range)\n }\n $setSelection(selection)\n\n for (const file of files) {\n const pendingUploadNode = $createUploadNode({\n data: {\n pending: {\n formID: file.formID,\n src: URL.createObjectURL(file.file),\n },\n } as Internal_UploadData,\n })\n // we need to get the focus node before inserting the upload node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert upload node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(pendingUploadNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n }\n })\n\n // Open the bulk drawer - the node transform will not open it for us, as it does not handle blob/file uploads\n openBulkUpload({ files })\n\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor])\n\n return <UploadDrawer enabledCollectionSlugs={enabledCollectionSlugs} />\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,YAAY,EAAEC,wBAAwB,EAAEC,aAAa,QAAQ;AACtE,SAASC,aAAa,EAAEC,cAAc,EAAEC,QAAQ,QAAQ;AACxD,OAAOC,QAAA,MAAc;AACrB,SACEC,qBAAqB,EACrBC,qBAAqB,EACrBC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,aAAa,EACbC,uBAAuB,EACvBC,oBAAoB,EACpBC,aAAa,EACbC,YAAY,EACZC,yBAAyB,EACzBC,aAAa,EACbC,aAAa,QACR;AACP,OAAOC,KAAA,IAASC,SAAS,QAAQ;AAMjC,SAASC,uBAAuB,QAAQ;AACxC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aD,OAAA,CAAAC,IAAA;IAAY,IAErB3D,aAAA,CAAc2D,IAAA;MAChB,MAAAG,QAAA,GAAiBH,IAAA,CAAAE,OAAA,CAAY;MAAA,IACxBC,QAAA,EAAAC,OAAA;QACHJ,IAAA,CAAA0D,MAAA,CAAW;MAAA;IAAA;EAAA;AAAA;AAlD4C,SAAA9D,OAAAqB,GAAA;EAAA,QA0DdA,GAAA,CAAAV,MAAA,EAAYU,GAAA;AAAA","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js';
2
- import type { DOMConversionMap, DOMExportOutput, ElementFormatType, LexicalNode, NodeKey } from 'lexical';
2
+ import type { DOMConversionMap, DOMExportOutput, EditorConfig, ElementFormatType, LexicalNode, NodeKey } from 'lexical';
3
3
  import type { CollectionSlug, DataFromCollectionSlug, JsonObject, TypedUploadCollection, UploadCollectionSlug } from 'payload';
4
4
  import type { JSX } from 'react';
5
5
  import { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js';
@@ -68,6 +68,7 @@ export declare class UploadServerNode extends DecoratorBlockNode {
68
68
  static importDOM(): DOMConversionMap<HTMLImageElement>;
69
69
  static importJSON(serializedNode: SerializedUploadNode): UploadServerNode;
70
70
  static isInline(): false;
71
+ createDOM(config?: EditorConfig): HTMLElement;
71
72
  decorate(): JSX.Element;
72
73
  exportDOM(): DOMExportOutput;
73
74
  exportJSON(): SerializedUploadNode;
@@ -1 +1 @@
1
- {"version":3,"file":"UploadNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/upload/server/nodes/UploadNode.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAA;AAC/F,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,OAAO,EACR,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,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oBAAoB,GAAG,qBAAqB,CAAC,4BAA4B,EAAE,QAAQ,CAAC,GAC9F,UAAU,CAAA;AAEZ,qBAAa,gBAAiB,SAAQ,kBAAkB;IACtD,MAAM,EAAE,UAAU,CAAA;gBAEN,EACV,IAAI,EACJ,MAAM,EACN,GAAG,GACJ,EAAE;QACD,IAAI,EAAE,UAAU,CAAA;QAChB,MAAM,CAAC,EAAE,iBAAiB,CAAA;QAC1B,GAAG,CAAC,EAAE,OAAO,CAAA;KACd;WAKe,KAAK,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB;WAQ/C,OAAO,IAAI,MAAM;WAIjB,SAAS,IAAI,gBAAgB,CAAC,gBAAgB,CAAC;WAS/C,UAAU,CAAC,cAAc,EAAE,oBAAoB,GAAG,gBAAgB;IAuBlF,MAAM,CAAC,QAAQ,IAAI,KAAK;IAIf,SAAS,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,WAAW;IAM7C,QAAQ,IAAI,GAAG,CAAC,OAAO;IAIvB,SAAS,IAAI,eAAe;IAc5B,UAAU,IAAI,oBAAoB;IAS3C,OAAO,IAAI,UAAU;IAIrB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAKtB,SAAS,IAAI,KAAK;CAG5B;AAED,wBAAgB,uBAAuB,CAAC,EACtC,IAAI,GACL,EAAE;IACD,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAA;CAC/D,GAAG,gBAAgB,CAKnB;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GACnC,IAAI,IAAI,gBAAgB,CAE1B"}
@@ -1,4 +1,5 @@
1
1
  import { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js';
2
+ import { addClassNamesToElement } from '@lexical/utils';
2
3
  import ObjectID from 'bson-objectid';
3
4
  import { $applyNodeReplacement } from 'lexical';
4
5
  import { $convertUploadElement } from './conversions.js';
@@ -54,6 +55,11 @@ export class UploadServerNode extends DecoratorBlockNode {
54
55
  static isInline() {
55
56
  return false;
56
57
  }
58
+ createDOM(config) {
59
+ const element = document.createElement('div');
60
+ addClassNamesToElement(element, config?.theme?.upload);
61
+ return element;
62
+ }
57
63
  decorate() {
58
64
  return null;
59
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"UploadNode.js","names":["DecoratorBlockNode","ObjectID","$applyNodeReplacement","$convertUploadElement","UploadServerNode","__data","constructor","data","format","key","clone","node","__format","__key","getType","importDOM","img","conversion","domNode","$createUploadServerNode","priority","importJSON","serializedNode","version","value","id","default","toHexString","importedData","fields","pending","relationTo","setFormat","isInline","decorate","exportDOM","element","document","createElement","setAttribute","String","formID","src","exportJSON","getData","type","getLatest","setData","writable","getWritable","updateDOM","$isUploadServerNode"],"sources":["../../../../../src/features/upload/server/nodes/UploadNode.tsx"],"sourcesContent":["import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport type {\n DOMConversionMap,\n DOMExportOutput,\n ElementFormatType,\n LexicalNode,\n NodeKey,\n} from 'lexical'\nimport type {\n CollectionSlug,\n DataFromCollectionSlug,\n JsonObject,\n TypedUploadCollection,\n UploadCollectionSlug,\n} from 'payload'\nimport type { JSX } from 'react'\n\nimport { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport ObjectID from 'bson-objectid'\nimport { $applyNodeReplacement } from 'lexical'\n\nimport type { StronglyTypedLeafNode } from '../../../../nodeTypes.js'\n\nimport { $convertUploadElement } from './conversions.js'\n\nexport type UploadData<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n [TCollectionSlug in CollectionSlug]: {\n fields: TUploadExtraFieldsData\n /**\n * Every lexical node that has sub-fields needs to have a unique ID. This is the ID of this upload node, not the ID of the linked upload document\n */\n id: string\n relationTo: TCollectionSlug\n /**\n * Value can be just the document ID, or the full, populated document\n */\n value: DataFromCollectionSlug<TCollectionSlug> | number | string\n }\n}[CollectionSlug]\n\n/**\n * Internal use only - UploadData type that can contain a pending state\n * @internal\n */\nexport type Internal_UploadData<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n pending?: {\n /**\n * ID that corresponds to the bulk upload form ID\n */\n formID: string\n /**\n * src value of the image dom element\n */\n src: string\n }\n} & UploadData<TUploadExtraFieldsData>\n\n/**\n * UploadDataImproved is a more precise type, and will replace UploadData in Payload v4.\n * This type is for internal use only as it will be deprecated in the future.\n * @internal\n *\n * @todo Replace UploadData with UploadDataImproved in 4.0\n */\nexport type UploadDataImproved<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n [TCollectionSlug in UploadCollectionSlug]: {\n fields: TUploadExtraFieldsData\n /**\n * Every lexical node that has sub-fields needs to have a unique ID. This is the ID of this upload node, not the ID of the linked upload document\n */\n id: string\n relationTo: TCollectionSlug\n /**\n * Value can be just the document ID, or the full, populated document\n */\n value: number | string | TypedUploadCollection[TCollectionSlug]\n }\n}[UploadCollectionSlug]\n\nexport type SerializedUploadNode = StronglyTypedLeafNode<SerializedDecoratorBlockNode, 'upload'> &\n UploadData\n\nexport class UploadServerNode extends DecoratorBlockNode {\n __data: UploadData\n\n constructor({\n data,\n format,\n key,\n }: {\n data: UploadData\n format?: ElementFormatType\n key?: NodeKey\n }) {\n super(format, key)\n this.__data = data\n }\n\n static override clone(node: UploadServerNode): UploadServerNode {\n return new this({\n data: node.__data,\n format: node.__format,\n key: node.__key,\n })\n }\n\n static override getType(): string {\n return 'upload'\n }\n\n static override importDOM(): DOMConversionMap<HTMLImageElement> {\n return {\n img: (node) => ({\n conversion: (domNode) => $convertUploadElement(domNode, $createUploadServerNode),\n priority: 0,\n }),\n }\n }\n\n static override importJSON(serializedNode: SerializedUploadNode): UploadServerNode {\n if (serializedNode.version === 1 && (serializedNode?.value as unknown as { id: string })?.id) {\n serializedNode.value = (serializedNode.value as unknown as { id: string }).id\n }\n if (serializedNode.version === 2 && !serializedNode?.id) {\n serializedNode.id = new ObjectID.default().toHexString()\n serializedNode.version = 3\n }\n\n const importedData: Internal_UploadData = {\n id: serializedNode.id,\n fields: serializedNode.fields,\n pending: (serializedNode as Internal_UploadData).pending,\n relationTo: serializedNode.relationTo,\n value: serializedNode.value,\n }\n\n const node = $createUploadServerNode({ data: importedData })\n node.setFormat(serializedNode.format)\n\n return node\n }\n\n static isInline(): false {\n return false\n }\n\n override decorate(): JSX.Element {\n return null as unknown as JSX.Element\n }\n\n override exportDOM(): DOMExportOutput {\n const element = document.createElement('img')\n const data = this.__data as Internal_UploadData\n if (data.pending) {\n element.setAttribute('data-lexical-pending-upload-form-id', String(data?.pending?.formID))\n element.setAttribute('src', data?.pending?.src || '')\n } else {\n element.setAttribute('data-lexical-upload-id', String(data?.value))\n element.setAttribute('data-lexical-upload-relation-to', data?.relationTo)\n }\n\n return { element }\n }\n\n override exportJSON(): SerializedUploadNode {\n return {\n ...super.exportJSON(),\n ...this.getData(),\n type: 'upload',\n version: 3,\n }\n }\n\n getData(): UploadData {\n return this.getLatest().__data\n }\n\n setData(data: UploadData): void {\n const writable = this.getWritable()\n writable.__data = data\n }\n\n override updateDOM(): false {\n return false\n }\n}\n\nexport function $createUploadServerNode({\n data,\n}: {\n data: Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>\n}): UploadServerNode {\n if (!data?.id) {\n data.id = new ObjectID.default().toHexString()\n }\n return $applyNodeReplacement(new UploadServerNode({ data: data as UploadData }))\n}\n\nexport function $isUploadServerNode(\n node: LexicalNode | null | undefined,\n): node is UploadServerNode {\n return node instanceof UploadServerNode\n}\n"],"mappings":"AAiBA,SAASA,kBAAkB,QAAQ;AACnC,OAAOC,QAAA,MAAc;AACrB,SAASC,qBAAqB,QAAQ;AAItC,SAASC,qBAAqB,QAAQ;AA2DtC,OAAO,MAAMC,gBAAA,SAAyBJ,kBAAA;EACpCK,MAAA;EAEAC,YAAY;IACVC,IAAI;IACJC,MAAM;IAC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IAAIE,gBAAA,CAAiB;IAAEG,IAAA,EAAMA;EAAmB;AAC/E;AAEA,OAAO,SAAS4C,oBACdxC,IAAoC;EAEpC,OAAOA,IAAA,YAAgBP,gBAAA;AACzB","ignoreList":[]}
1
+ {"version":3,"file":"UploadNode.js","names":["DecoratorBlockNode","addClassNamesToElement","ObjectID","$applyNodeReplacement","$convertUploadElement","UploadServerNode","__data","constructor","data","format","key","clone","node","__format","__key","getType","importDOM","img","conversion","domNode","$createUploadServerNode","priority","importJSON","serializedNode","version","value","id","default","toHexString","importedData","fields","pending","relationTo","setFormat","isInline","createDOM","config","element","document","createElement","theme","upload","decorate","exportDOM","setAttribute","String","formID","src","exportJSON","getData","type","getLatest","setData","writable","getWritable","updateDOM","$isUploadServerNode"],"sources":["../../../../../src/features/upload/server/nodes/UploadNode.tsx"],"sourcesContent":["import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport type {\n DOMConversionMap,\n DOMExportOutput,\n EditorConfig,\n ElementFormatType,\n LexicalNode,\n NodeKey,\n} from 'lexical'\nimport type {\n CollectionSlug,\n DataFromCollectionSlug,\n JsonObject,\n TypedUploadCollection,\n UploadCollectionSlug,\n} from 'payload'\nimport type { JSX } from 'react'\n\nimport { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport { addClassNamesToElement } from '@lexical/utils'\nimport ObjectID from 'bson-objectid'\nimport { $applyNodeReplacement } from 'lexical'\n\nimport type { StronglyTypedLeafNode } from '../../../../nodeTypes.js'\n\nimport { $convertUploadElement } from './conversions.js'\n\nexport type UploadData<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n [TCollectionSlug in CollectionSlug]: {\n fields: TUploadExtraFieldsData\n /**\n * Every lexical node that has sub-fields needs to have a unique ID. This is the ID of this upload node, not the ID of the linked upload document\n */\n id: string\n relationTo: TCollectionSlug\n /**\n * Value can be just the document ID, or the full, populated document\n */\n value: DataFromCollectionSlug<TCollectionSlug> | number | string\n }\n}[CollectionSlug]\n\n/**\n * Internal use only - UploadData type that can contain a pending state\n * @internal\n */\nexport type Internal_UploadData<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n pending?: {\n /**\n * ID that corresponds to the bulk upload form ID\n */\n formID: string\n /**\n * src value of the image dom element\n */\n src: string\n }\n} & UploadData<TUploadExtraFieldsData>\n\n/**\n * UploadDataImproved is a more precise type, and will replace UploadData in Payload v4.\n * This type is for internal use only as it will be deprecated in the future.\n * @internal\n *\n * @todo Replace UploadData with UploadDataImproved in 4.0\n */\nexport type UploadDataImproved<TUploadExtraFieldsData extends JsonObject = JsonObject> = {\n [TCollectionSlug in UploadCollectionSlug]: {\n fields: TUploadExtraFieldsData\n /**\n * Every lexical node that has sub-fields needs to have a unique ID. This is the ID of this upload node, not the ID of the linked upload document\n */\n id: string\n relationTo: TCollectionSlug\n /**\n * Value can be just the document ID, or the full, populated document\n */\n value: number | string | TypedUploadCollection[TCollectionSlug]\n }\n}[UploadCollectionSlug]\n\nexport type SerializedUploadNode = StronglyTypedLeafNode<SerializedDecoratorBlockNode, 'upload'> &\n UploadData\n\nexport class UploadServerNode extends DecoratorBlockNode {\n __data: UploadData\n\n constructor({\n data,\n format,\n key,\n }: {\n data: UploadData\n format?: ElementFormatType\n key?: NodeKey\n }) {\n super(format, key)\n this.__data = data\n }\n\n static override clone(node: UploadServerNode): UploadServerNode {\n return new this({\n data: node.__data,\n format: node.__format,\n key: node.__key,\n })\n }\n\n static override getType(): string {\n return 'upload'\n }\n\n static override importDOM(): DOMConversionMap<HTMLImageElement> {\n return {\n img: (node) => ({\n conversion: (domNode) => $convertUploadElement(domNode, $createUploadServerNode),\n priority: 0,\n }),\n }\n }\n\n static override importJSON(serializedNode: SerializedUploadNode): UploadServerNode {\n if (serializedNode.version === 1 && (serializedNode?.value as unknown as { id: string })?.id) {\n serializedNode.value = (serializedNode.value as unknown as { id: string }).id\n }\n if (serializedNode.version === 2 && !serializedNode?.id) {\n serializedNode.id = new ObjectID.default().toHexString()\n serializedNode.version = 3\n }\n\n const importedData: Internal_UploadData = {\n id: serializedNode.id,\n fields: serializedNode.fields,\n pending: (serializedNode as Internal_UploadData).pending,\n relationTo: serializedNode.relationTo,\n value: serializedNode.value,\n }\n\n const node = $createUploadServerNode({ data: importedData })\n node.setFormat(serializedNode.format)\n\n return node\n }\n\n static isInline(): false {\n return false\n }\n\n override createDOM(config?: EditorConfig): HTMLElement {\n const element = document.createElement('div')\n addClassNamesToElement(element, config?.theme?.upload)\n return element\n }\n\n override decorate(): JSX.Element {\n return null as unknown as JSX.Element\n }\n\n override exportDOM(): DOMExportOutput {\n const element = document.createElement('img')\n const data = this.__data as Internal_UploadData\n if (data.pending) {\n element.setAttribute('data-lexical-pending-upload-form-id', String(data?.pending?.formID))\n element.setAttribute('src', data?.pending?.src || '')\n } else {\n element.setAttribute('data-lexical-upload-id', String(data?.value))\n element.setAttribute('data-lexical-upload-relation-to', data?.relationTo)\n }\n\n return { element }\n }\n\n override exportJSON(): SerializedUploadNode {\n return {\n ...super.exportJSON(),\n ...this.getData(),\n type: 'upload',\n version: 3,\n }\n }\n\n getData(): UploadData {\n return this.getLatest().__data\n }\n\n setData(data: UploadData): void {\n const writable = this.getWritable()\n writable.__data = data\n }\n\n override updateDOM(): false {\n return false\n }\n}\n\nexport function $createUploadServerNode({\n data,\n}: {\n data: Omit<UploadData, 'id'> & Partial<Pick<UploadData, 'id'>>\n}): UploadServerNode {\n if (!data?.id) {\n data.id = new ObjectID.default().toHexString()\n }\n return $applyNodeReplacement(new UploadServerNode({ data: data as UploadData }))\n}\n\nexport function $isUploadServerNode(\n node: LexicalNode | null | undefined,\n): node is UploadServerNode {\n return node instanceof UploadServerNode\n}\n"],"mappings":"AAkBA,SAASA,kBAAkB,QAAQ;AACnC,SAASC,sBAAsB,QAAQ;AACvC,OAAOC,QAAA,MAAc;AACrB,SAASC,qBAAqB,QAAQ;AAItC,SAASC,qBAAqB,QAAQ;AA2DtC,OAAO,MAAMC,gBAAA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B;EAES+C,UAAA,EAAmB;IAC1B,OAAO;EACT;AACF;AAEA,OAAO,SAASnC,wBAAwB;EACtCZ;AAAI,CAGL;EACC,IAAI,CAACA,IAAA,EAAMkB,EAAA,EAAI;IACblB,IAAA,CAAKkB,EAAE,GAAG,IAAIxB,QAAA,CAASyB,OAAO,GAAGC,WAAW;EAC9C;EACA,OAAOzB,qBAAA,CAAsB,IAAIE,gBAAA,CAAiB;IAAEG,IAAA,EAAMA;EAAmB;AAC/E;AAEA,OAAO,SAASgD,oBACd5C,IAAoC;EAEpC,OAAOA,IAAA,YAAgBP,gBAAA;AACzB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAeA,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;AAO5D,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAC/B;IACE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;CACnD,GAAG,yBAAyB,CAmK9B,CAAA;AAaD,eAAO,MAAM,QAAQ,EAAE,OAAO,iBAAqC,CAAA"}
1
+ {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAeA,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,CAgL9B,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 { RichTextViewProvider } from './RichTextViewProvider.js';
13
+ import { ViewSelector } from './ViewSelector.js';
12
14
  const baseClass = 'rich-text-lexical';
13
15
  const RichTextComponent = props => {
14
16
  const {
@@ -84,6 +86,7 @@ const RichTextComponent = props => {
84
86
  const pathWithEditDepth = `${path}.${editDepth}`;
85
87
  const runDeprioritized = useRunDeprioritized() // defaults to 500 ms timeout
86
88
  ;
89
+ const [currentView, setCurrentView] = useState('default');
87
90
  const handleChange = useCallback(editorState => {
88
91
  // Capture `editorState` in the closure so we can safely run later.
89
92
  const updateFieldValue = () => {
@@ -117,46 +120,55 @@ const RichTextComponent = props => {
117
120
  handleInitialValueChange(initialValue);
118
121
  }
119
122
  }, [initialValue]);
120
- return /*#__PURE__*/_jsxs("div", {
121
- className: classes,
122
- style: styles,
123
- children: [/*#__PURE__*/_jsx(RenderCustomComponent, {
124
- CustomComponent: Error,
125
- Fallback: /*#__PURE__*/_jsx(FieldError, {
126
- path: path,
127
- showError: showError
128
- })
129
- }), Label || /*#__PURE__*/_jsx(FieldLabel, {
130
- label: label,
131
- localized: localized,
132
- path: path,
133
- required: required
134
- }), /*#__PURE__*/_jsxs("div", {
135
- className: `${baseClass}__wrap`,
136
- children: [/*#__PURE__*/_jsxs(ErrorBoundary, {
137
- fallbackRender: fallbackRender,
138
- onReset: () => {},
139
- children: [BeforeInput, /*#__PURE__*/_jsx(LexicalProvider, {
140
- composerKey: pathWithEditDepth,
141
- editorConfig: editorConfig,
142
- fieldProps: props,
143
- isSmallWidthViewport: isSmallWidthViewport,
144
- onChange: handleChange,
145
- readOnly: disabled,
146
- value: value_0
147
- }, JSON.stringify({
148
- path,
149
- rerenderProviderKey
150
- })), AfterInput]
151
- }), /*#__PURE__*/_jsx(RenderCustomComponent, {
152
- CustomComponent: Description,
153
- Fallback: /*#__PURE__*/_jsx(FieldDescription, {
154
- description: description,
155
- path: path
123
+ return /*#__PURE__*/_jsx(RichTextViewProvider, {
124
+ currentView: currentView,
125
+ setCurrentView: setCurrentView,
126
+ views: props.views,
127
+ children: /*#__PURE__*/_jsxs("div", {
128
+ className: classes,
129
+ style: styles,
130
+ children: [/*#__PURE__*/_jsx(RenderCustomComponent, {
131
+ CustomComponent: Error,
132
+ Fallback: /*#__PURE__*/_jsx(FieldError, {
133
+ path: path,
134
+ showError: showError
156
135
  })
136
+ }), /*#__PURE__*/_jsxs("div", {
137
+ className: `${baseClass}__label-row`,
138
+ children: [Label || /*#__PURE__*/_jsx(FieldLabel, {
139
+ label: label,
140
+ localized: localized,
141
+ path: path,
142
+ required: required
143
+ }), /*#__PURE__*/_jsx(ViewSelector, {})]
144
+ }), /*#__PURE__*/_jsxs("div", {
145
+ className: `${baseClass}__wrap`,
146
+ children: [/*#__PURE__*/_jsxs(ErrorBoundary, {
147
+ fallbackRender: fallbackRender,
148
+ onReset: () => {},
149
+ children: [BeforeInput, /*#__PURE__*/_jsx(LexicalProvider, {
150
+ composerKey: pathWithEditDepth,
151
+ editorConfig: editorConfig,
152
+ fieldProps: props,
153
+ isSmallWidthViewport: isSmallWidthViewport,
154
+ onChange: handleChange,
155
+ readOnly: disabled,
156
+ value: value_0
157
+ }, JSON.stringify({
158
+ currentView,
159
+ path,
160
+ rerenderProviderKey
161
+ })), AfterInput]
162
+ }), /*#__PURE__*/_jsx(RenderCustomComponent, {
163
+ CustomComponent: Description,
164
+ Fallback: /*#__PURE__*/_jsx(FieldDescription, {
165
+ description: description,
166
+ path: path
167
+ })
168
+ })]
157
169
  })]
158
- })]
159
- }, pathWithEditDepth);
170
+ }, pathWithEditDepth)
171
+ });
160
172
  };
161
173
  function fallbackRender({
162
174
  error
@@ -1 +1 @@
1
- {"version":3,"file":"Field.js","names":["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","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 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(JSON.parse(JSON.stringify(prevValueRef.current)), value)\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 <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 {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,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,MAAM;IACJC,YAAY;IACZC,KAAK;IACLA,KAAA,EAAO;MACLC,KAAA,EAAO;QAAEC,SAAS;QAAEC,WAAW;Q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,IAAA;UAAMuB;QAAoB,KAKjDb,UAAA;uBAEHgD,IAAA,CAACrF,qBAAA;QACCsF,eAAA,EAAiB/C,WAAA;QACjBgD,QAAA,eAAUF,IAAA,CAACxF,gBAAA;UAAiBwB,WAAA,EAAaA,WAAA;UAAaM,IAAA,EAAMA;;;;KAvBpCwC,iBAAA;AA4BlC;AAEA,SAASqB,eAAe;EAAEK;AAAK,CAAoB;EACjD;EAEA,oBACEV,KAAA,CAAC;IAAI/D,SAAA,EAAU;IAAgB0E,IAAA,EAAK;4BAClCT,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAID,KAAA,EAAO;QAAEW,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqClF,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"Field.js","names":["FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useEffectEvent","useField","mergeFieldStyles","dequal","React","useCallback","useEffect","useMemo","useState","ErrorBoundary","LexicalProvider","useRunDeprioritized","RichTextViewProvider","ViewSelector","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","currentView","setCurrentView","handleChange","editorState","updateFieldValue","newState","toJSON","current","styles","handleInitialValueChange","JSON","parse","stringify","Date","Object","is","_jsx","views","_jsxs","style","CustomComponent","Fallback","fallbackRender","onReset","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 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 { RichTextViewProvider } 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\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 [currentView, setCurrentView] = useState<string>('default')\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(JSON.parse(JSON.stringify(prevValueRef.current)), value)\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 <RichTextViewProvider\n currentView={currentView}\n setCurrentView={setCurrentView}\n views={props.views}\n >\n <div className={classes} key={pathWithEditDepth} style={styles}>\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 <ViewSelector />\n </div>\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n {BeforeInput}\n <LexicalProvider\n composerKey={pathWithEditDepth}\n editorConfig={editorConfig}\n fieldProps={props}\n isSmallWidthViewport={isSmallWidthViewport}\n key={JSON.stringify({ currentView, path, rerenderProviderKey })} // makes sure lexical is completely re-rendered when initialValue changes or view 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 {AfterInput}\n </ErrorBoundary>\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n </RichTextViewProvider>\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,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,oBAAoB,QAAQ;AACrC,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,EAAMC,aAAa;IACnBN,QAAA,EAAUO,yBAAyB;IACnCC;EAAQ,CACT,GAAGd,KAAA;EAEJ,MAAMe,iBAAA,GAAoBF,yBAAA,IAA6BN,iBAAA;EAEvD,MAAMS,SAAA,GAAYjC,YAAA;EAElB,MAAMkC,gBAAA,GAAmB5B,WAAA,CACvB,CAAC6B,KAAA,EAAOC,iBAAA;IACN,IAAI,OAAOL,QAAA,KAAa,YAAY;MAClC;MACA,OAAOA,QAAA,CAASI,KAAA,EAAO;QAAE,GAAGC,iBAAiB;QAAET;MAAS;IAC1D;IACA,OAAO;EACT;EACA;EACA;EACA;EACA,CAACI,QAAA,EAAU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A;;AAkCpC;AAEA,SAASwB,eAAe;EAAEK;AAAK,CAAoB;EACjD;EAEA,oBACET,KAAA,CAAC;IAAInE,SAAA,EAAU;IAAgB6E,IAAA,EAAK;4BAClCZ,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAIG,KAAA,EAAO;QAAEU,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqCrF,iBAAA","ignoreList":[]}
@@ -0,0 +1,84 @@
1
+ import React from 'react';
2
+ import type { LexicalEditorNodeMap, LexicalEditorViewMap } from '../types.js';
3
+ /**
4
+ * Context type for rich text view management.
5
+ */
6
+ type RichTextViewContextType = {
7
+ /**
8
+ * The name of the currently active view (e.g., 'default', 'frontend', 'debug')
9
+ */
10
+ currentView: string;
11
+ /**
12
+ * The node map for the currently active view, containing rendering overrides for each node type.
13
+ * This is the resolved view from the views map based on currentView.
14
+ */
15
+ currentViewMap?: LexicalEditorNodeMap;
16
+ /**
17
+ * Optional function to change the current view. Only available in contexts where view switching is enabled (e.g., admin panel).
18
+ */
19
+ setCurrentView?: (view: string) => void;
20
+ /**
21
+ * The complete map of all available views for this field.
22
+ */
23
+ views?: LexicalEditorViewMap;
24
+ };
25
+ /**
26
+ * Provider component for rich text view context.
27
+ *
28
+ * This provider manages the current view state and makes it accessible to child components
29
+ * via the useRichTextView hook. It automatically resolves the current view's node map
30
+ * based on the active view name.
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * <RichTextViewProvider
35
+ * currentView="frontend"
36
+ * setCurrentView={setView}
37
+ * views={myViews}
38
+ * >
39
+ * <MyEditor />
40
+ * </RichTextViewProvider>
41
+ * ```
42
+ */
43
+ export declare const RichTextViewProvider: React.FC<{
44
+ children: React.ReactNode;
45
+ currentView?: string;
46
+ setCurrentView?: (view: string) => void;
47
+ views?: LexicalEditorViewMap;
48
+ }>;
49
+ /**
50
+ * Hook to access the current rich text view context.
51
+ *
52
+ * Use this hook to access the currently active view and its node map,
53
+ * or to programmatically switch between views.
54
+ *
55
+ * @returns An object containing:
56
+ * - `currentView`: The name of the active view
57
+ * - `currentViewMap`: The node overrides for the current view
58
+ * - `setCurrentView`: Function to change views (if available)
59
+ * - `views`: All available views
60
+ *
61
+ * @throws Error if used outside of a RichTextViewProvider
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * function MyComponent() {
66
+ * const { currentView, currentViewMap, setCurrentView } = useRichTextView()
67
+ *
68
+ * return (
69
+ * <div>
70
+ * <p>Current view: {currentView}</p>
71
+ * {currentViewMap?.heading && <p>Heading overrides are active</p>}
72
+ * {setCurrentView && (
73
+ * <button onClick={() => setCurrentView('frontend')}>
74
+ * Switch to frontend view
75
+ * </button>
76
+ * )}
77
+ * </div>
78
+ * )
79
+ * }
80
+ * ```
81
+ */
82
+ export declare function useRichTextView(): RichTextViewContextType;
83
+ export {};
84
+ //# sourceMappingURL=RichTextViewProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextViewProvider.d.ts","sourceRoot":"","sources":["../../src/field/RichTextViewProvider.tsx"],"names":[],"mappings":"AACA,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;;;OAGG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAA;IACrC;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC;;OAEG;IACH,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AASD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAC7B,CAmBA,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,IAAI,uBAAuB,CAQzD"}