@payloadcms/richtext-lexical 3.0.0-beta.126 → 3.0.0-beta.128

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 (237) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/cell/rscEntry.d.ts +12 -0
  3. package/dist/cell/rscEntry.d.ts.map +1 -0
  4. package/dist/cell/rscEntry.js +82 -0
  5. package/dist/cell/rscEntry.js.map +1 -0
  6. package/dist/exports/client/Field-SHUAQNQD.js +2 -0
  7. package/dist/exports/client/Field-SHUAQNQD.js.map +7 -0
  8. package/dist/exports/client/RelationshipComponent-IMM4CFBE.js +2 -0
  9. package/dist/exports/client/RelationshipComponent-IMM4CFBE.js.map +7 -0
  10. package/dist/exports/client/bundled.css +1 -1
  11. package/dist/exports/client/{chunk-NEO76RJK.js → chunk-352SHIZR.js} +2 -2
  12. package/dist/exports/client/chunk-75T7MDBH.js +2 -0
  13. package/dist/exports/client/chunk-75T7MDBH.js.map +7 -0
  14. package/dist/exports/client/{chunk-XY4TCSM7.js → chunk-O4IOO4EU.js} +2 -2
  15. package/dist/exports/client/chunk-OOBB5GCO.js +2 -0
  16. package/dist/exports/client/chunk-OOBB5GCO.js.map +7 -0
  17. package/dist/exports/client/chunk-PDAZFJVO.js +2 -0
  18. package/dist/exports/client/chunk-PDAZFJVO.js.map +7 -0
  19. package/dist/exports/client/{chunk-32KXGBIQ.js → chunk-ZOYGBIAN.js} +2 -2
  20. package/dist/exports/client/component-EHTN2BHZ.js +2 -0
  21. package/dist/exports/client/component-EHTN2BHZ.js.map +7 -0
  22. package/dist/exports/client/component-YE2TDR5O.js +2 -0
  23. package/dist/exports/client/component-YE2TDR5O.js.map +7 -0
  24. package/dist/exports/client/componentInline-N5LJ2LY2.js +2 -0
  25. package/dist/exports/client/componentInline-N5LJ2LY2.js.map +7 -0
  26. package/dist/exports/client/index.d.ts +0 -1
  27. package/dist/exports/client/index.d.ts.map +1 -1
  28. package/dist/exports/client/index.js +8 -8
  29. package/dist/exports/client/index.js.map +4 -4
  30. package/dist/exports/server/rsc.d.ts +3 -0
  31. package/dist/exports/server/rsc.d.ts.map +1 -0
  32. package/dist/exports/server/rsc.js +3 -0
  33. package/dist/exports/server/rsc.js.map +1 -0
  34. package/dist/features/blocks/client/component/BlockContent.d.ts +1 -0
  35. package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
  36. package/dist/features/blocks/client/component/BlockContent.js +15 -15
  37. package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
  38. package/dist/features/blocks/client/component/index.d.ts.map +1 -1
  39. package/dist/features/blocks/client/component/index.js +68 -52
  40. package/dist/features/blocks/client/component/index.js.map +1 -1
  41. package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
  42. package/dist/features/blocks/client/componentInline/index.js +14 -19
  43. package/dist/features/blocks/client/componentInline/index.js.map +1 -1
  44. package/dist/features/blocks/client/index.d.ts.map +1 -1
  45. package/dist/features/blocks/client/index.js +26 -24
  46. package/dist/features/blocks/client/index.js.map +1 -1
  47. package/dist/features/blocks/client/plugin/index.d.ts.map +1 -1
  48. package/dist/features/blocks/client/plugin/index.js +83 -75
  49. package/dist/features/blocks/client/plugin/index.js.map +1 -1
  50. package/dist/features/blocks/server/index.d.ts.map +1 -1
  51. package/dist/features/blocks/server/index.js +20 -10
  52. package/dist/features/blocks/server/index.js.map +1 -1
  53. package/dist/features/blocks/server/validate.d.ts.map +1 -1
  54. package/dist/features/blocks/server/validate.js +8 -5
  55. package/dist/features/blocks/server/validate.js.map +1 -1
  56. package/dist/features/debug/testRecorder/client/plugin/index.js +25 -14
  57. package/dist/features/debug/testRecorder/client/plugin/index.js.map +1 -1
  58. package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js +19 -7
  59. package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
  60. package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js +16 -3
  61. package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
  62. package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -1
  63. package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +58 -19
  64. package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
  65. package/dist/features/experimental_table/client/plugins/TablePlugin/index.d.ts.map +1 -1
  66. package/dist/features/experimental_table/client/plugins/TablePlugin/index.js +38 -32
  67. package/dist/features/experimental_table/client/plugins/TablePlugin/index.js.map +1 -1
  68. package/dist/features/experimental_table/server/index.d.ts.map +1 -1
  69. package/dist/features/experimental_table/server/index.js +3 -1
  70. package/dist/features/experimental_table/server/index.js.map +1 -1
  71. package/dist/features/format/bold/feature.client.d.ts.map +1 -1
  72. package/dist/features/format/bold/feature.client.js +2 -1
  73. package/dist/features/format/bold/feature.client.js.map +1 -1
  74. package/dist/features/format/inlineCode/feature.client.d.ts.map +1 -1
  75. package/dist/features/format/inlineCode/feature.client.js +2 -1
  76. package/dist/features/format/inlineCode/feature.client.js.map +1 -1
  77. package/dist/features/format/italic/feature.client.d.ts.map +1 -1
  78. package/dist/features/format/italic/feature.client.js +2 -1
  79. package/dist/features/format/italic/feature.client.js.map +1 -1
  80. package/dist/features/format/strikethrough/feature.client.d.ts.map +1 -1
  81. package/dist/features/format/strikethrough/feature.client.js +2 -1
  82. package/dist/features/format/strikethrough/feature.client.js.map +1 -1
  83. package/dist/features/format/subscript/feature.client.d.ts.map +1 -1
  84. package/dist/features/format/subscript/feature.client.js +2 -1
  85. package/dist/features/format/subscript/feature.client.js.map +1 -1
  86. package/dist/features/format/superscript/feature.client.d.ts.map +1 -1
  87. package/dist/features/format/superscript/feature.client.js +2 -1
  88. package/dist/features/format/superscript/feature.client.js.map +1 -1
  89. package/dist/features/format/underline/feature.client.d.ts.map +1 -1
  90. package/dist/features/format/underline/feature.client.js +2 -1
  91. package/dist/features/format/underline/feature.client.js.map +1 -1
  92. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
  93. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +52 -15
  94. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
  95. package/dist/features/link/client/plugins/floatingLinkEditor/index.js +1 -1
  96. package/dist/features/link/client/plugins/floatingLinkEditor/index.js.map +1 -1
  97. package/dist/features/link/server/i18n.d.ts.map +1 -1
  98. package/dist/features/link/server/i18n.js +64 -32
  99. package/dist/features/link/server/i18n.js.map +1 -1
  100. package/dist/features/link/server/index.d.ts.map +1 -1
  101. package/dist/features/link/server/index.js +3 -1
  102. package/dist/features/link/server/index.js.map +1 -1
  103. package/dist/features/link/server/validate.d.ts.map +1 -1
  104. package/dist/features/link/server/validate.js +8 -5
  105. package/dist/features/link/server/validate.js.map +1 -1
  106. package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
  107. package/dist/features/relationship/client/components/RelationshipComponent.js +6 -4
  108. package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
  109. package/dist/features/toolbars/fixed/client/Toolbar/index.d.ts.map +1 -1
  110. package/dist/features/toolbars/fixed/client/Toolbar/index.js +77 -49
  111. package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
  112. package/dist/features/toolbars/inline/client/Toolbar/index.js +93 -52
  113. package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
  114. package/dist/features/toolbars/shared/ToolbarButton/index.js +1 -1
  115. package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
  116. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +2 -2
  117. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
  118. package/dist/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -1
  119. package/dist/features/toolbars/shared/ToolbarDropdown/index.js +25 -22
  120. package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
  121. package/dist/features/toolbars/types.d.ts +3 -1
  122. package/dist/features/toolbars/types.d.ts.map +1 -1
  123. package/dist/features/toolbars/types.js.map +1 -1
  124. package/dist/features/typesServer.d.ts +4 -17
  125. package/dist/features/typesServer.d.ts.map +1 -1
  126. package/dist/features/typesServer.js.map +1 -1
  127. package/dist/features/upload/client/component/index.d.ts.map +1 -1
  128. package/dist/features/upload/client/component/index.js +8 -4
  129. package/dist/features/upload/client/component/index.js.map +1 -1
  130. package/dist/features/upload/server/feature.server.d.ts.map +1 -1
  131. package/dist/features/upload/server/feature.server.js +3 -1
  132. package/dist/features/upload/server/feature.server.js.map +1 -1
  133. package/dist/features/upload/server/validate.d.ts.map +1 -1
  134. package/dist/features/upload/server/validate.js +7 -4
  135. package/dist/features/upload/server/validate.js.map +1 -1
  136. package/dist/field/Field.d.ts.map +1 -1
  137. package/dist/field/Field.js +27 -41
  138. package/dist/field/Field.js.map +1 -1
  139. package/dist/field/bundled.css +1 -1
  140. package/dist/field/index.d.ts.map +1 -1
  141. package/dist/field/index.js +26 -27
  142. package/dist/field/index.js.map +1 -1
  143. package/dist/field/rscEntry.d.ts +9 -0
  144. package/dist/field/rscEntry.d.ts.map +1 -0
  145. package/dist/field/rscEntry.js +37 -0
  146. package/dist/field/rscEntry.js.map +1 -0
  147. package/dist/index.d.ts.map +1 -1
  148. package/dist/index.js +8 -14
  149. package/dist/index.js.map +1 -1
  150. package/dist/lexical/LexicalProvider.d.ts +1 -1
  151. package/dist/lexical/LexicalProvider.d.ts.map +1 -1
  152. package/dist/lexical/LexicalProvider.js +2 -2
  153. package/dist/lexical/LexicalProvider.js.map +1 -1
  154. package/dist/lexical/config/client/EditorConfigProvider.d.ts +4 -3
  155. package/dist/lexical/config/client/EditorConfigProvider.d.ts.map +1 -1
  156. package/dist/lexical/config/client/EditorConfigProvider.js +5 -5
  157. package/dist/lexical/config/client/EditorConfigProvider.js.map +1 -1
  158. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts +4 -4
  159. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts.map +1 -1
  160. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +14 -5
  161. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
  162. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts +2 -2
  163. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts.map +1 -1
  164. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +5 -5
  165. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
  166. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts +3 -2
  167. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts.map +1 -1
  168. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js.map +1 -1
  169. package/dist/lexical/plugins/SlashMenu/index.d.ts.map +1 -1
  170. package/dist/lexical/plugins/SlashMenu/index.js +15 -24
  171. package/dist/lexical/plugins/SlashMenu/index.js.map +1 -1
  172. package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js +6 -4
  173. package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
  174. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +6 -4
  175. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
  176. package/dist/lexical/theme/EditorTheme.d.ts.map +1 -1
  177. package/dist/lexical/theme/EditorTheme.js +0 -2
  178. package/dist/lexical/theme/EditorTheme.js.map +1 -1
  179. package/dist/types.d.ts +15 -2
  180. package/dist/types.d.ts.map +1 -1
  181. package/dist/types.js.map +1 -1
  182. package/dist/utilities/fieldsDrawer/Drawer.d.ts +1 -0
  183. package/dist/utilities/fieldsDrawer/Drawer.d.ts.map +1 -1
  184. package/dist/utilities/fieldsDrawer/Drawer.js +25 -20
  185. package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
  186. package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
  187. package/dist/utilities/fieldsDrawer/DrawerContent.js +99 -143
  188. package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
  189. package/dist/utilities/fieldsDrawer/useLexicalDrawer.js +1 -1
  190. package/dist/utilities/fieldsDrawer/useLexicalDrawer.js.map +1 -1
  191. package/dist/utilities/generateImportMap.d.ts.map +1 -1
  192. package/dist/utilities/generateImportMap.js +2 -3
  193. package/dist/utilities/generateImportMap.js.map +1 -1
  194. package/dist/utilities/generateSchemaMap.d.ts.map +1 -1
  195. package/dist/utilities/generateSchemaMap.js +13 -10
  196. package/dist/utilities/generateSchemaMap.js.map +1 -1
  197. package/dist/utilities/initLexicalFeatures.d.ts +18 -0
  198. package/dist/utilities/initLexicalFeatures.d.ts.map +1 -0
  199. package/dist/utilities/initLexicalFeatures.js +95 -0
  200. package/dist/utilities/initLexicalFeatures.js.map +1 -0
  201. package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.d.ts.map +1 -1
  202. package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js +5 -1
  203. package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js.map +1 -1
  204. package/dist/utilities/useLexicalFeature.d.ts.map +1 -1
  205. package/dist/utilities/useLexicalFeature.js +12 -4
  206. package/dist/utilities/useLexicalFeature.js.map +1 -1
  207. package/dist/validate/index.d.ts.map +1 -1
  208. package/dist/validate/index.js +1 -1
  209. package/dist/validate/index.js.map +1 -1
  210. package/package.json +43 -35
  211. package/dist/cell/index.d.ts +0 -9
  212. package/dist/cell/index.d.ts.map +0 -1
  213. package/dist/cell/index.js +0 -120
  214. package/dist/cell/index.js.map +0 -1
  215. package/dist/exports/client/Field-Y47DV2NP.js +0 -2
  216. package/dist/exports/client/Field-Y47DV2NP.js.map +0 -7
  217. package/dist/exports/client/RelationshipComponent-LBWKOBGF.js +0 -2
  218. package/dist/exports/client/RelationshipComponent-LBWKOBGF.js.map +0 -7
  219. package/dist/exports/client/chunk-7SR2HYD6.js +0 -2
  220. package/dist/exports/client/chunk-7SR2HYD6.js.map +0 -7
  221. package/dist/exports/client/chunk-GD6LBQBJ.js +0 -2
  222. package/dist/exports/client/chunk-GD6LBQBJ.js.map +0 -7
  223. package/dist/exports/client/chunk-IIWHHN4J.js +0 -2
  224. package/dist/exports/client/chunk-IIWHHN4J.js.map +0 -7
  225. package/dist/exports/client/component-4TP4L5EV.js +0 -2
  226. package/dist/exports/client/component-4TP4L5EV.js.map +0 -7
  227. package/dist/exports/client/component-XMR5NN36.js +0 -2
  228. package/dist/exports/client/component-XMR5NN36.js.map +0 -7
  229. package/dist/exports/client/componentInline-NUDJIIQ4.js +0 -2
  230. package/dist/exports/client/componentInline-NUDJIIQ4.js.map +0 -7
  231. package/dist/utilities/generateComponentMap.d.ts +0 -6
  232. package/dist/utilities/generateComponentMap.d.ts.map +0 -1
  233. package/dist/utilities/generateComponentMap.js +0 -93
  234. package/dist/utilities/generateComponentMap.js.map +0 -1
  235. /package/dist/exports/client/{chunk-NEO76RJK.js.map → chunk-352SHIZR.js.map} +0 -0
  236. /package/dist/exports/client/{chunk-XY4TCSM7.js.map → chunk-O4IOO4EU.js.map} +0 -0
  237. /package/dist/exports/client/{chunk-32KXGBIQ.js.map → chunk-ZOYGBIAN.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useLexicalComposerContext","useLexicalNodeSelection","mergeRegister","getTranslation","Button","File","formatDrawerSlug","useConfig","useEditDepth","usePayloadAPI","useTranslation","$getNodeByKey","$getSelection","$isNodeSelection","CLICK_COMMAND","COMMAND_PRIORITY_LOW","KEY_BACKSPACE_COMMAND","KEY_DELETE_COMMAND","React","useCallback","useEffect","useId","useReducer","useRef","useState","useEditorConfigContext","FieldsDrawer","useLexicalDocumentDrawer","useLexicalDrawer","EnabledRelationshipsCondition","INSERT_UPLOAD_WITH_DRAWER_COMMAND","$isUploadNode","baseClass","initialParams","depth","Component","props","data","fields","relationTo","value","nodeKey","Error","config","collections","routes","api","serverURL","uploadRef","uuid","editDepth","editor","isSelected","setSelected","clearSelection","editorConfig","field","i18n","t","cacheBust","dispatchCacheBust","state","relatedCollection","find","coll","slug","componentID","extraFieldsDrawerSlug","toggleDrawer","closeDocumentDrawer","DocumentDrawer","DocumentDrawerToggler","id","collectionSlug","setParams","thumbnailSRC","thumbnailURL","url","removeUpload","update","remove","updateUpload","$onDelete","event","deleteSelection","preventDefault","getNodes","forEach","node","registerCommand","target","current","contains","shiftKey","hasExtraFields","resolvedFeatureMap","get","sanitizedClientFeatureProps","onExtraFieldsDrawerSubmit","_","uploadNode","newData","getData","setData","_jsxs","className","filter","Boolean","join","contentEditable","ref","_jsx","alt","filename","src","labels","singular","isEditable","buttonStyle","disabled","admin","readOnly","el","icon","onClick","round","tooltip","dispatchCommand","replace","e","onSave","drawerSlug","drawerTitle","label","featureKey","handleDrawerSubmit","schemaPathSuffix","UploadComponent","uploads"],"sources":["../../../../../src/features/upload/client/component/index.tsx"],"sourcesContent":["'use client'\nimport type { BaseSelection } from 'lexical'\nimport type { ClientCollectionConfig, Data } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js'\nimport { mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n File,\n formatDrawerSlug,\n useConfig,\n useEditDepth,\n usePayloadAPI,\n useTranslation,\n} from '@payloadcms/ui'\nimport {\n $getNodeByKey,\n $getSelection,\n $isNodeSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_LOW,\n KEY_BACKSPACE_COMMAND,\n KEY_DELETE_COMMAND,\n} from 'lexical'\nimport React, { useCallback, useEffect, useId, useReducer, useRef, useState } from 'react'\n\nimport type { BaseClientFeatureProps } from '../../../typesClient.js'\nimport type { UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../feature.client.js'\nimport type { UploadNode } from '../nodes/UploadNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js'\nimport { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { EnabledRelationshipsCondition } from '../../../relationship/client/utils/EnabledRelationshipsCondition.js'\nimport { INSERT_UPLOAD_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\nimport { $isUploadNode } from '../nodes/UploadNode.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-upload'\n\nconst initialParams = {\n depth: 0,\n}\n\nexport type ElementProps = {\n data: UploadData\n nodeKey: string\n}\n\nconst Component: React.FC<ElementProps> = (props) => {\n const {\n data: { fields, relationTo, value },\n nodeKey,\n } = props\n\n if (typeof value === 'object') {\n throw new Error(\n 'Upload value should be a string or number. The Lexical Upload component should not receive the populated value object.',\n )\n }\n\n const {\n config: {\n collections,\n routes: { api },\n serverURL,\n },\n } = useConfig()\n const uploadRef = useRef<HTMLDivElement | null>(null)\n const { uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n const [editor] = useLexicalComposerContext()\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey)\n\n const { editorConfig, field } = useEditorConfigContext()\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [relatedCollection] = useState<ClientCollectionConfig>(\n () => collections.find((coll) => coll.slug === relationTo)!,\n )\n\n const componentID = useId()\n\n const extraFieldsDrawerSlug = formatDrawerSlug({\n slug: `lexical-upload-drawer-` + uuid + componentID, // There can be multiple upload components, each with their own drawer, in one single editor => separate them by componentID\n depth: editDepth,\n })\n\n // Need to use hook to initialize useEffect that restores cursor position\n const { toggleDrawer } = useLexicalDrawer(extraFieldsDrawerSlug, true)\n\n const { closeDocumentDrawer, DocumentDrawer, DocumentDrawerToggler } = useLexicalDocumentDrawer({\n id: value,\n collectionSlug: relatedCollection.slug,\n })\n\n // Get the referenced document\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value}`,\n { initialParams },\n )\n\n const thumbnailSRC = data?.thumbnailURL || data?.url\n\n const removeUpload = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const updateUpload = useCallback(\n (data: Data) => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n dispatchCacheBust()\n closeDocumentDrawer()\n },\n [setParams, cacheBust, closeDocumentDrawer],\n )\n\n const $onDelete = useCallback(\n (event: KeyboardEvent) => {\n const deleteSelection = $getSelection()\n if (isSelected && $isNodeSelection(deleteSelection)) {\n event.preventDefault()\n editor.update(() => {\n deleteSelection.getNodes().forEach((node) => {\n if ($isUploadNode(node)) {\n node.remove()\n }\n })\n })\n }\n return false\n },\n [editor, isSelected],\n )\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand<MouseEvent>(\n CLICK_COMMAND,\n (event: MouseEvent) => {\n // Check if uploadRef.target or anything WITHIN uploadRef.target was clicked\n if (\n event.target === uploadRef.current ||\n uploadRef.current?.contains(event.target as Node)\n ) {\n if (event.shiftKey) {\n setSelected(!isSelected)\n } else {\n if (!isSelected) {\n clearSelection()\n setSelected(true)\n }\n }\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n\n editor.registerCommand(KEY_DELETE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_BACKSPACE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n )\n }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected])\n\n const hasExtraFields = (\n editorConfig?.resolvedFeatureMap?.get('upload')\n ?.sanitizedClientFeatureProps as BaseClientFeatureProps<UploadFeaturePropsClient>\n ).collections?.[relatedCollection.slug]?.hasExtraFields\n\n const onExtraFieldsDrawerSubmit = useCallback(\n (_, data) => {\n // Update lexical node (with key nodeKey) with new data\n editor.update(() => {\n const uploadNode: null | UploadNode = $getNodeByKey(nodeKey)\n if (uploadNode) {\n const newData: UploadData = {\n ...uploadNode.getData(),\n fields: data,\n }\n uploadNode.setData(newData)\n }\n })\n },\n [editor, nodeKey],\n )\n\n return (\n <div\n className={[baseClass, isSelected && `${baseClass}--selected`].filter(Boolean).join(' ')}\n contentEditable={false}\n ref={uploadRef}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__topRow`}>\n {/* TODO: migrate to use @payloadcms/ui/elements/Thumbnail component */}\n <div className={`${baseClass}__thumbnail`}>\n {thumbnailSRC ? (\n <img\n alt={data?.filename}\n data-lexical-upload-id={value}\n data-lexical-upload-relation-to={relationTo}\n src={thumbnailSRC}\n />\n ) : (\n <File />\n )}\n </div>\n <div className={`${baseClass}__topRowRightPanel`}>\n <div className={`${baseClass}__collectionLabel`}>\n {getTranslation(relatedCollection.labels.singular, i18n)}\n </div>\n {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n {hasExtraFields ? (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__upload-drawer-toggler`}\n disabled={field?.admin?.readOnly}\n el=\"button\"\n icon=\"edit\"\n onClick={() => {\n toggleDrawer()\n }}\n round\n tooltip={t('fields:editRelationship')}\n />\n ) : null}\n\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swap-drawer-toggler`}\n disabled={field?.admin?.readOnly}\n el=\"button\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_UPLOAD_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n tooltip={t('fields:swapUpload')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.admin?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeUpload()\n }}\n round\n tooltip={t('fields:removeUpload')}\n />\n </div>\n )}\n </div>\n </div>\n <div className={`${baseClass}__bottomRow`}>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <strong>{data?.filename}</strong>\n </DocumentDrawerToggler>\n </div>\n </div>\n {value ? <DocumentDrawer onSave={updateUpload} /> : null}\n {hasExtraFields ? (\n <FieldsDrawer\n data={fields}\n drawerSlug={extraFieldsDrawerSlug}\n drawerTitle={t('general:editLabel', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n featureKey=\"upload\"\n handleDrawerSubmit={onExtraFieldsDrawerSubmit}\n schemaPathSuffix={relatedCollection.slug}\n />\n ) : null}\n </div>\n )\n}\n\nexport const UploadComponent = (props: ElementProps): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <Component {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,uBAAuB,QAAQ;AACxC,SAASC,aAAa,QAAQ;AAC9B,SAASC,cAAc,QAAQ;AAC/B,SACEC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,SAAS,EACTC,YAAY,EACZC,aAAa,EACbC,cAAc,QACT;AACP,SACEC,aAAa,EACbC,aAAa,EACbC,gBAAgB,EAChBC,aAAa,EACbC,oBAAoB,EACpBC,qBAAqB,EACrBC,kBAAkB,QACb;AACP,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,KAAK,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAOnF,SAASC,sBAAsB,QAAQ;AACvC,SAASC,YAAY,QAAQ;AAC7B,SAASC,wBAAwB,Q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BAAA,CAAkBG;SAEpC;;AAGV;AAEA,OAAO,MAAMwE,eAAA,GAAmBrG,KAAA;EAC9B,oBACE2E,IAAA,CAAClF,6BAAA;IAA+B,GAAGO,KAAK;IAAEsG,OAAO;cAC/C,aAAA3B,IAAA,CAAC5E,SAAA;MAAW,GAAGC;;;AAGrB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["useLexicalComposerContext","useLexicalNodeSelection","mergeRegister","getTranslation","Button","File","formatDrawerSlug","useConfig","useEditDepth","usePayloadAPI","useTranslation","$getNodeByKey","$getSelection","$isNodeSelection","CLICK_COMMAND","COMMAND_PRIORITY_LOW","KEY_BACKSPACE_COMMAND","KEY_DELETE_COMMAND","React","useCallback","useEffect","useId","useReducer","useRef","useState","useEditorConfigContext","FieldsDrawer","useLexicalDocumentDrawer","useLexicalDrawer","EnabledRelationshipsCondition","INSERT_UPLOAD_WITH_DRAWER_COMMAND","$isUploadNode","baseClass","initialParams","depth","Component","props","data","fields","relationTo","value","nodeKey","Error","config","collections","routes","api","serverURL","uploadRef","uuid","editDepth","editor","isSelected","setSelected","clearSelection","editorConfig","fieldProps","readOnly","schemaPath","i18n","t","cacheBust","dispatchCacheBust","state","relatedCollection","find","coll","slug","componentID","extraFieldsDrawerSlug","toggleDrawer","closeDocumentDrawer","DocumentDrawer","DocumentDrawerToggler","id","collectionSlug","setParams","thumbnailSRC","thumbnailURL","url","removeUpload","update","remove","updateUpload","$onDelete","event","deleteSelection","preventDefault","getNodes","forEach","node","registerCommand","target","current","contains","shiftKey","hasExtraFields","resolvedFeatureMap","get","sanitizedClientFeatureProps","onExtraFieldsDrawerSubmit","_","uploadNode","newData","getData","setData","_jsxs","className","filter","Boolean","join","contentEditable","ref","_jsx","alt","filename","src","labels","singular","isEditable","buttonStyle","disabled","el","icon","onClick","round","tooltip","dispatchCommand","replace","e","onSave","drawerSlug","drawerTitle","label","featureKey","handleDrawerSubmit","schemaPathSuffix","UploadComponent","uploads"],"sources":["../../../../../src/features/upload/client/component/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientCollectionConfig, Data } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js'\nimport { mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n File,\n formatDrawerSlug,\n useConfig,\n useEditDepth,\n usePayloadAPI,\n useTranslation,\n} from '@payloadcms/ui'\nimport {\n $getNodeByKey,\n $getSelection,\n $isNodeSelection,\n CLICK_COMMAND,\n COMMAND_PRIORITY_LOW,\n KEY_BACKSPACE_COMMAND,\n KEY_DELETE_COMMAND,\n} from 'lexical'\nimport React, { useCallback, useEffect, useId, useReducer, useRef, useState } from 'react'\n\nimport type { BaseClientFeatureProps } from '../../../typesClient.js'\nimport type { UploadData } from '../../server/nodes/UploadNode.js'\nimport type { UploadFeaturePropsClient } from '../feature.client.js'\nimport type { UploadNode } from '../nodes/UploadNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js'\nimport { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { EnabledRelationshipsCondition } from '../../../relationship/client/utils/EnabledRelationshipsCondition.js'\nimport { INSERT_UPLOAD_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\nimport { $isUploadNode } from '../nodes/UploadNode.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-upload'\n\nconst initialParams = {\n depth: 0,\n}\n\nexport type ElementProps = {\n data: UploadData\n nodeKey: string\n}\n\nconst Component: React.FC<ElementProps> = (props) => {\n const {\n data: { fields, relationTo, value },\n nodeKey,\n } = props\n\n if (typeof value === 'object') {\n throw new Error(\n 'Upload value should be a string or number. The Lexical Upload component should not receive the populated value object.',\n )\n }\n\n const {\n config: {\n collections,\n routes: { api },\n serverURL,\n },\n } = useConfig()\n const uploadRef = useRef<HTMLDivElement | null>(null)\n const { uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n const [editor] = useLexicalComposerContext()\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey)\n\n const {\n editorConfig,\n fieldProps: { readOnly, schemaPath },\n } = useEditorConfigContext()\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [relatedCollection] = useState<ClientCollectionConfig>(\n () => collections.find((coll) => coll.slug === relationTo)!,\n )\n\n const componentID = useId()\n\n const extraFieldsDrawerSlug = formatDrawerSlug({\n slug: `lexical-upload-drawer-` + uuid + componentID, // There can be multiple upload components, each with their own drawer, in one single editor => separate them by componentID\n depth: editDepth,\n })\n\n // Need to use hook to initialize useEffect that restores cursor position\n const { toggleDrawer } = useLexicalDrawer(extraFieldsDrawerSlug, true)\n\n const { closeDocumentDrawer, DocumentDrawer, DocumentDrawerToggler } = useLexicalDocumentDrawer({\n id: value,\n collectionSlug: relatedCollection.slug,\n })\n\n // Get the referenced document\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value}`,\n { initialParams },\n )\n\n const thumbnailSRC = data?.thumbnailURL || data?.url\n\n const removeUpload = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const updateUpload = useCallback(\n (data: Data) => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n dispatchCacheBust()\n closeDocumentDrawer()\n },\n [setParams, cacheBust, closeDocumentDrawer],\n )\n\n const $onDelete = useCallback(\n (event: KeyboardEvent) => {\n const deleteSelection = $getSelection()\n if (isSelected && $isNodeSelection(deleteSelection)) {\n event.preventDefault()\n editor.update(() => {\n deleteSelection.getNodes().forEach((node) => {\n if ($isUploadNode(node)) {\n node.remove()\n }\n })\n })\n }\n return false\n },\n [editor, isSelected],\n )\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand<MouseEvent>(\n CLICK_COMMAND,\n (event: MouseEvent) => {\n // Check if uploadRef.target or anything WITHIN uploadRef.target was clicked\n if (\n event.target === uploadRef.current ||\n uploadRef.current?.contains(event.target as Node)\n ) {\n if (event.shiftKey) {\n setSelected(!isSelected)\n } else {\n if (!isSelected) {\n clearSelection()\n setSelected(true)\n }\n }\n return true\n }\n\n return false\n },\n COMMAND_PRIORITY_LOW,\n ),\n\n editor.registerCommand(KEY_DELETE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n editor.registerCommand(KEY_BACKSPACE_COMMAND, $onDelete, COMMAND_PRIORITY_LOW),\n )\n }, [clearSelection, editor, isSelected, nodeKey, $onDelete, setSelected])\n\n const hasExtraFields = (\n editorConfig?.resolvedFeatureMap?.get('upload')\n ?.sanitizedClientFeatureProps as BaseClientFeatureProps<UploadFeaturePropsClient>\n ).collections?.[relatedCollection.slug]?.hasExtraFields\n\n const onExtraFieldsDrawerSubmit = useCallback(\n (_, data) => {\n // Update lexical node (with key nodeKey) with new data\n editor.update(() => {\n const uploadNode: null | UploadNode = $getNodeByKey(nodeKey)\n if (uploadNode) {\n const newData: UploadData = {\n ...uploadNode.getData(),\n fields: data,\n }\n uploadNode.setData(newData)\n }\n })\n },\n [editor, nodeKey],\n )\n\n return (\n <div\n className={[baseClass, isSelected && `${baseClass}--selected`].filter(Boolean).join(' ')}\n contentEditable={false}\n ref={uploadRef}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__topRow`}>\n {/* TODO: migrate to use @payloadcms/ui/elements/Thumbnail component */}\n <div className={`${baseClass}__thumbnail`}>\n {thumbnailSRC ? (\n <img\n alt={data?.filename}\n data-lexical-upload-id={value}\n data-lexical-upload-relation-to={relationTo}\n src={thumbnailSRC}\n />\n ) : (\n <File />\n )}\n </div>\n <div className={`${baseClass}__topRowRightPanel`}>\n <div className={`${baseClass}__collectionLabel`}>\n {getTranslation(relatedCollection.labels.singular, i18n)}\n </div>\n {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n {hasExtraFields ? (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__upload-drawer-toggler`}\n disabled={readOnly}\n el=\"button\"\n icon=\"edit\"\n onClick={() => {\n toggleDrawer()\n }}\n round\n tooltip={t('fields:editRelationship')}\n />\n ) : null}\n\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swap-drawer-toggler`}\n disabled={readOnly}\n el=\"button\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_UPLOAD_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n tooltip={t('fields:swapUpload')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeUpload()\n }}\n round\n tooltip={t('fields:removeUpload')}\n />\n </div>\n )}\n </div>\n </div>\n <div className={`${baseClass}__bottomRow`}>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <strong>{data?.filename}</strong>\n </DocumentDrawerToggler>\n </div>\n </div>\n {value ? <DocumentDrawer onSave={updateUpload} /> : null}\n {hasExtraFields ? (\n <FieldsDrawer\n data={fields}\n drawerSlug={extraFieldsDrawerSlug}\n drawerTitle={t('general:editLabel', {\n label: getTranslation(relatedCollection.labels.singular, i18n),\n })}\n featureKey=\"upload\"\n handleDrawerSubmit={onExtraFieldsDrawerSubmit}\n schemaPath={schemaPath}\n schemaPathSuffix={relatedCollection.slug}\n />\n ) : null}\n </div>\n )\n}\n\nexport const UploadComponent = (props: ElementProps): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <Component {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,yBAAyB,Q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AAiF,IAAA,CAAC;sBAAQ5E,IAAA,EAAM8E;;;;QAIpB3E,KAAA,gBAAQyE,IAAA,CAACzC,cAAA;MAAe0D,MAAA,EAAQ/C;SAAmB,MACnDa,cAAA,gBACCiB,IAAA,CAACvF,YAAA;MACCW,IAAA,EAAMC,MAAA;MACN6F,UAAA,EAAY9D,qBAAA;MACZ+D,WAAA,EAAaxE,CAAA,CAAE,qBAAqB;QAClCyE,KAAA,EAAOlI,cAAA,CAAe6D,iBAAA,CAAkBqD,MAAM,CAACC,QAAQ,EAAE3D,IAAA;MAC3D;MACA2E,UAAA,EAAW;MACXC,kBAAA,EAAoBnC,yBAAA;MACpB1C,UAAA,EAAYA,UAAA;MACZ8E,gBAAA,EAAkBxE,iBAAA,CAAkBG;SAEpC;;AAGV;AAEA,OAAO,MAAMsE,eAAA,GAAmBrG,KAAA;EAC9B,oBACE6E,IAAA,CAACpF,6BAAA;IAA+B,GAAGO,KAAK;IAAEsG,OAAO;cAC/C,aAAAzB,IAAA,CAAC9E,SAAA;MAAW,GAAGC;;;AAGrB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,KAAK,EAKN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AAU3E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,CAAC,EAAE;QACZ,CAAC,UAAU,EAAE,cAAc,GAAG;YAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;SAChB,CAAA;KACF,CAAA;IACD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AASD,eAAO,MAAM,aAAa,gIA8OxB,CAAA"}
1
+ {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,KAAK,EAMN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AAU3E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,CAAC,EAAE;QACZ,CAAC,UAAU,EAAE,cAAc,GAAG;YAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;SAChB,CAAA;KACF,CAAA;IACD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AASD,eAAO,MAAM,aAAa,gIAgPxB,CAAA"}
@@ -58,7 +58,9 @@ export const UploadFeature = createServerFeature({
58
58
  const schemaMap = new Map();
59
59
  for (const collection in props.collections) {
60
60
  if (props.collections[collection].fields?.length) {
61
- schemaMap.set(collection, props.collections[collection].fields);
61
+ schemaMap.set(collection, {
62
+ fields: props.collections[collection].fields
63
+ });
62
64
  }
63
65
  }
64
66
  return schemaMap;
@@ -1 +1 @@
1
- {"version":3,"file":"feature.server.js","names":["sanitizeFields","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","UploadServerNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","parentIsLocalized","props","collections","clientProps","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","currentDepth","depth","draft","node","overrideAccess","req","showHiddenFields","id","value","uploadDocument","collectionSlug","relationTo","data","key","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","allSubFields","concat","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populateArg","populationPromises","populateDepth","maxDepth","undefined","push","select","defaultPopulate","validations","sanitizedServerFeatureProps"],"sources":["../../../../src/features/upload/server/feature.server.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FileData,\n FileSize,\n Payload,\n TypeWithID,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from '../client/feature.client.js'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { uploadPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { UploadServerNode } from './nodes/UploadNode.js'\nimport { uploadValidation } from './validate.js'\n\nexport type UploadFeatureProps = {\n collections?: {\n [collection: CollectionSlug]: {\n fields: Field[]\n }\n }\n /**\n * Sets a maximum population depth for this upload (not the fields for this upload), regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n}\n\n/**\n * Get the absolute URL for an upload URL by potentially prepending the serverURL\n */\nfunction getAbsoluteURL(url: string, payload: Payload): string {\n return url?.startsWith('http') ? url : (payload?.config?.serverURL || '') + url\n}\n\nexport const UploadFeature = createServerFeature<\n UploadFeatureProps,\n UploadFeatureProps,\n UploadFeaturePropsClient\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n if (!props) {\n props = { collections: {} }\n }\n\n const clientProps: UploadFeaturePropsClient = {\n collections: {},\n }\n if (props.collections) {\n for (const collection in props.collections) {\n clientProps.collections[collection] = {\n hasExtraFields: props.collections[collection].fields.length >= 1,\n }\n }\n }\n\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n props.collections[collection].fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: props.collections[collection].fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#UploadFeatureClient',\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) {\n return null\n }\n\n const schemaMap = new Map<string, Field[]>()\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n schemaMap.set(collection, props.collections[collection].fields)\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n req,\n showHiddenFields,\n }) => {\n // @ts-expect-error - for backwards-compatibility\n const id = node?.value?.id || node?.value\n\n if (req?.payload) {\n const uploadDocument: {\n value?: FileData & TypeWithID\n } = {}\n\n try {\n await populate({\n id,\n collectionSlug: node.relationTo,\n currentDepth,\n data: uploadDocument,\n depth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n })\n } catch (ignored) {\n // eslint-disable-next-line no-console\n console.error(\n 'Lexical upload node HTML converter: error fetching upload file',\n ignored,\n 'Node:',\n node,\n )\n return `<img />`\n }\n\n const url = getAbsoluteURL(uploadDocument?.value?.url ?? '', req?.payload)\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDocument?.value?.mimeType?.startsWith('image')) {\n return `<a href=\"${url}\" rel=\"noopener noreferrer\">${uploadDocument.value?.filename}</a>`\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (\n !uploadDocument?.value?.sizes ||\n !Object.keys(uploadDocument?.value?.sizes).length\n ) {\n return `<img src=\"${url}\" alt=\"${uploadDocument?.value?.filename}\" width=\"${uploadDocument?.value?.width}\" height=\"${uploadDocument?.value?.height}\"/>`\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n let pictureHTML = '<picture>'\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDocument.value?.sizes) {\n const imageSize: {\n url?: string\n } & FileSize = uploadDocument.value?.sizes[size]\n\n // Skip if any property of the size object is null\n if (\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n const imageSizeURL = getAbsoluteURL(imageSize?.url, req?.payload)\n\n pictureHTML += `<source srcset=\"${imageSizeURL}\" media=\"(max-width: ${imageSize.width}px)\" type=\"${imageSize.mimeType}\">`\n }\n\n // Add the default img tag\n pictureHTML += `<img src=\"${url}\" alt=\"Image\" width=\"${uploadDocument.value?.width}\" height=\"${uploadDocument.value?.height}\">`\n pictureHTML += '</picture>'\n return pictureHTML\n } else {\n return `<img src=\"${id}\" />`\n }\n },\n nodeTypes: [UploadServerNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n if (!node) {\n let allSubFields: Field[] = []\n for (const collection in props?.collections) {\n allSubFields = allSubFields.concat(props?.collections?.[collection]?.fields)\n }\n return allSubFields\n }\n const collection = req ? req.payload.collections[node?.relationTo] : null\n\n if (collection) {\n const collectionFieldSchema = props?.collections?.[node?.relationTo]?.fields\n\n if (Array.isArray(collectionFieldSchema)) {\n if (!collectionFieldSchema?.length) {\n return null\n }\n return collectionFieldSchema\n }\n }\n return null\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [uploadPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populateArg,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth =\n props?.maxDepth !== undefined && props?.maxDepth < depth ? props?.maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n select:\n populateArg?.[collection.config.slug] ?? collection.config.defaultPopulate,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadServerNode,\n validations: [uploadValidation(props)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"mappings":"AAUA,SAASA,cAAc,QAAQ;AAI/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,IAAI,QAAQ;AACrB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,gBAAgB,QAAQ;AAiBjC;;;AAGA,SAASC,eAAeC,GAAW,EAAEC,OAAgB;EACnD,OAAOD,GAAA,EAAKE,UAAA,CAAW,UAAUF,GAAA,GAAM,CAACC,OAAA,EAASE,MAAA,EAAQC,SAAA,IAAa,EAAC,IAAKJ,GAAA;AAC9E;AAEA,OAAO,MAAMK,aAAA,GAAgBZ,mBAAA,CAI3B;EACAa,OAAA,EAAS,MAAAA,CAAO;IAAEH,MAAA,EAAQI,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAAK,CAAE;IACnE,IAAI,CAACA,KAAA,EAAO;MACVA,KAAA,GAAQ;QAAEC,WAAA,EAAa,CAAC;MAAE;IAC5B;IAEA,MAAMC,WAAA,GAAwC;MAC5CD,WAAA,EAAa,CAAC;IAChB;IACA,IAAID,KAAA,CAAMC,WAAW,EAAE;MACrB,KAAK,MAAME,UAAA,IAAcH,KAAA,CAAMC,WAAW,EAAE;QAC1CC,WAAA,CAAYD,WAAW,CAACE,UAAA,CAAW,GAAG;UACpCC,cAAA,EAAgBJ,KAAA,CAAMC,WAAW,CAACE,UAAA,CAAW,CAACE,MAAM,CAACC,MAAM,IAAI;QACjE;MACF;IACF;IAEA,MAAMC,kBAAA,GAAqBV,OAAA,CAAQI,WAAW,CAACO,GAAG,CAAEC,CAAA,IAAMA,CAAA,CAAEC,IAAI,KAAK,EAAE;IAEvE,KAAK,MAAMP,UAAA,IAAcH,KAAA,CAAMC,WAAW,EAAE;MAC1C,IAA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AA;UACT;QAEJ;QACAA,IAAA,EAAMtC,gBAAA;QACNoF,WAAA,EAAa,CAACnF,gBAAA,CAAiBY,KAAA;MACjC,GACD;MACDwE,2BAAA,EAA6BxE;IAC/B;EACF;EACAmC,GAAA,EAAK;AACP","ignoreList":[]}
1
+ {"version":3,"file":"feature.server.js","names":["sanitizeFields","populate","createServerFeature","createNode","uploadPopulationPromiseHOC","i18n","UploadServerNode","uploadValidation","getAbsoluteURL","url","payload","startsWith","config","serverURL","UploadFeature","feature","_config","isRoot","parentIsLocalized","props","collections","clientProps","collection","hasExtraFields","fields","length","validRelationships","map","c","slug","requireFieldLevelRichTextEditor","ClientFeature","clientFeatureProps","generateSchemaMap","schemaMap","Map","set","nodes","converters","html","converter","currentDepth","depth","draft","node","overrideAccess","req","showHiddenFields","id","value","uploadDocument","collectionSlug","relationTo","data","key","ignored","console","error","mimeType","filename","sizes","Object","keys","width","height","pictureHTML","size","imageSize","filesize","imageSizeURL","nodeTypes","getType","getSubFields","allSubFields","concat","collectionFieldSchema","Array","isArray","getSubFieldsData","graphQLPopulationPromises","hooks","afterRead","populateArg","populationPromises","populateDepth","maxDepth","undefined","push","select","defaultPopulate","validations","sanitizedServerFeatureProps"],"sources":["../../../../src/features/upload/server/feature.server.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FieldSchemaMap,\n FileData,\n FileSize,\n Payload,\n TypeWithID,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { UploadFeaturePropsClient } from '../client/feature.client.js'\n\nimport { populate } from '../../../populateGraphQL/populate.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { uploadPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { UploadServerNode } from './nodes/UploadNode.js'\nimport { uploadValidation } from './validate.js'\n\nexport type UploadFeatureProps = {\n collections?: {\n [collection: CollectionSlug]: {\n fields: Field[]\n }\n }\n /**\n * Sets a maximum population depth for this upload (not the fields for this upload), regardless of the remaining depth when the respective field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n}\n\n/**\n * Get the absolute URL for an upload URL by potentially prepending the serverURL\n */\nfunction getAbsoluteURL(url: string, payload: Payload): string {\n return url?.startsWith('http') ? url : (payload?.config?.serverURL || '') + url\n}\n\nexport const UploadFeature = createServerFeature<\n UploadFeatureProps,\n UploadFeatureProps,\n UploadFeaturePropsClient\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n if (!props) {\n props = { collections: {} }\n }\n\n const clientProps: UploadFeaturePropsClient = {\n collections: {},\n }\n if (props.collections) {\n for (const collection in props.collections) {\n clientProps.collections[collection] = {\n hasExtraFields: props.collections[collection].fields.length >= 1,\n }\n }\n }\n\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n props.collections[collection].fields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: props.collections[collection].fields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n }\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#UploadFeatureClient',\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n if (!props?.collections) {\n return null\n }\n\n const schemaMap: FieldSchemaMap = new Map()\n\n for (const collection in props.collections) {\n if (props.collections[collection].fields?.length) {\n schemaMap.set(collection, {\n fields: props.collections[collection].fields,\n })\n }\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n req,\n showHiddenFields,\n }) => {\n // @ts-expect-error - for backwards-compatibility\n const id = node?.value?.id || node?.value\n\n if (req?.payload) {\n const uploadDocument: {\n value?: FileData & TypeWithID\n } = {}\n\n try {\n await populate({\n id,\n collectionSlug: node.relationTo,\n currentDepth,\n data: uploadDocument,\n depth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n showHiddenFields,\n })\n } catch (ignored) {\n // eslint-disable-next-line no-console\n console.error(\n 'Lexical upload node HTML converter: error fetching upload file',\n ignored,\n 'Node:',\n node,\n )\n return `<img />`\n }\n\n const url = getAbsoluteURL(uploadDocument?.value?.url ?? '', req?.payload)\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDocument?.value?.mimeType?.startsWith('image')) {\n return `<a href=\"${url}\" rel=\"noopener noreferrer\">${uploadDocument.value?.filename}</a>`\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (\n !uploadDocument?.value?.sizes ||\n !Object.keys(uploadDocument?.value?.sizes).length\n ) {\n return `<img src=\"${url}\" alt=\"${uploadDocument?.value?.filename}\" width=\"${uploadDocument?.value?.width}\" height=\"${uploadDocument?.value?.height}\"/>`\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n let pictureHTML = '<picture>'\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDocument.value?.sizes) {\n const imageSize: {\n url?: string\n } & FileSize = uploadDocument.value?.sizes[size]\n\n // Skip if any property of the size object is null\n if (\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n const imageSizeURL = getAbsoluteURL(imageSize?.url, req?.payload)\n\n pictureHTML += `<source srcset=\"${imageSizeURL}\" media=\"(max-width: ${imageSize.width}px)\" type=\"${imageSize.mimeType}\">`\n }\n\n // Add the default img tag\n pictureHTML += `<img src=\"${url}\" alt=\"Image\" width=\"${uploadDocument.value?.width}\" height=\"${uploadDocument.value?.height}\">`\n pictureHTML += '</picture>'\n return pictureHTML\n } else {\n return `<img src=\"${id}\" />`\n }\n },\n nodeTypes: [UploadServerNode.getType()],\n },\n },\n getSubFields: ({ node, req }) => {\n if (!node) {\n let allSubFields: Field[] = []\n for (const collection in props?.collections) {\n allSubFields = allSubFields.concat(props?.collections?.[collection]?.fields)\n }\n return allSubFields\n }\n const collection = req ? req.payload.collections[node?.relationTo] : null\n\n if (collection) {\n const collectionFieldSchema = props?.collections?.[node?.relationTo]?.fields\n\n if (Array.isArray(collectionFieldSchema)) {\n if (!collectionFieldSchema?.length) {\n return null\n }\n return collectionFieldSchema\n }\n }\n return null\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [uploadPopulationPromiseHOC(props)],\n hooks: {\n afterRead: [\n ({\n currentDepth,\n depth,\n draft,\n node,\n overrideAccess,\n populateArg,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!node?.value) {\n return node\n }\n const collection = req.payload.collections[node?.relationTo]\n\n if (!collection) {\n return node\n }\n // @ts-expect-error\n const id = node?.value?.id || node?.value // for backwards-compatibility\n\n const populateDepth =\n props?.maxDepth !== undefined && props?.maxDepth < depth ? props?.maxDepth : depth\n\n populationPromises.push(\n populate({\n id,\n collectionSlug: collection.config.slug,\n currentDepth,\n data: node,\n depth: populateDepth,\n draft,\n key: 'value',\n overrideAccess,\n req,\n select:\n populateArg?.[collection.config.slug] ?? collection.config.defaultPopulate,\n showHiddenFields,\n }),\n )\n\n return node\n },\n ],\n },\n node: UploadServerNode,\n validations: [uploadValidation(props)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'upload',\n})\n"],"mappings":"AAWA,SAASA,cAAc,QAAQ;AAI/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,IAAI,QAAQ;AACrB,SAASC,gBAAgB,QAAQ;AACjC,SAASC,gBAAgB,QAAQ;AAiBjC;;;AAGA,SAASC,eAAeC,GAAW,EAAEC,OAAgB;EACnD,OAAOD,GAAA,EAAKE,UAAA,CAAW,UAAUF,GAAA,GAAM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AMK,KAAA,EAAO;cAChB,OAAOL,IAAA;YACT;YACA,MAAMtB,UAAA,GAAawB,GAAA,CAAIpC,OAAO,CAACU,WAAW,CAACwB,IAAA,EAAMQ,UAAA,CAAW;YAE5D,IAAI,CAAC9B,UAAA,EAAY;cACf,OAAOsB,IAAA;YACT;YACA;YACA,MAAMI,EAAA,GAAKJ,IAAA,EAAMK,KAAA,EAAOD,EAAA,IAAMJ,IAAA,EAAMK,KAAA,CAAM;YAAA;YAE1C,MAAMmC,aAAA,GACJjE,KAAA,EAAOkE,QAAA,KAAaC,SAAA,IAAanE,KAAA,EAAOkE,QAAA,GAAW3C,KAAA,GAAQvB,KAAA,EAAOkE,QAAA,GAAW3C,KAAA;YAE/EyC,kBAAA,CAAmBI,IAAI,CACrBtF,QAAA,CAAS;cACP+C,EAAA;cACAG,cAAA,EAAgB7B,UAAA,CAAWV,MAAM,CAACiB,IAAI;cACtCY,YAAA;cACAY,IAAA,EAAMT,IAAA;cACNF,KAAA,EAAO0C,aAAA;cACPzC,KAAA;cACAW,GAAA,EAAK;cACLT,cAAA;cACAC,GAAA;cACA0C,MAAA,EACEN,WAAA,GAAc5D,UAAA,CAAWV,MAAM,CAACiB,IAAI,CAAC,IAAIP,UAAA,CAAWV,MAAM,CAAC6E,eAAe;cAC5E1C;YACF;YAGF,OAAOH,IAAA;UACT;QAEJ;QACAA,IAAA,EAAMtC,gBAAA;QACNoF,WAAA,EAAa,CAACnF,gBAAA,CAAiBY,KAAA;MACjC,GACD;MACDwE,2BAAA,EAA6BxE;IAC/B;EACF;EACAmC,GAAA,EAAK;AACP","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/validate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,eAAO,MAAM,gBAAgB,UACpB,kBAAkB,KACxB,cAAc,CAAC,oBAAoB,CA2DrC,CAAA"}
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/validate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,eAAO,MAAM,gBAAgB,UACpB,kBAAkB,KACxB,cAAc,CAAC,oBAAoB,CA8DrC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema';
1
+ import { fieldSchemasToFormState } from '@payloadcms/ui/forms/fieldSchemasToFormState';
2
2
  import { isValidID } from 'payload';
3
3
  export const uploadValidation = props => {
4
4
  return async ({
@@ -33,15 +33,18 @@ export const uploadValidation = props => {
33
33
  if (!collection?.fields?.length) {
34
34
  return true;
35
35
  }
36
- const result = await buildStateFromSchema({
36
+ const result = await fieldSchemasToFormState({
37
37
  id,
38
38
  collectionSlug: node.relationTo,
39
39
  data: node?.fields ?? {},
40
- fieldSchema: collection.fields,
40
+ fields: collection.fields,
41
+ fieldSchemaMap: undefined,
41
42
  operation: operation === 'create' || operation === 'update' ? operation : 'update',
43
+ permissions: {},
42
44
  preferences,
45
+ renderAllFields: false,
43
46
  req,
44
- siblingData: node?.fields ?? {}
47
+ schemaPath: ''
45
48
  });
46
49
  let errorPaths = [];
47
50
  for (const fieldKey in result) {
@@ -1 +1 @@
1
- {"version":3,"file":"validate.js","names":["buildStateFromSchema","isValidID","uploadValidation","props","node","validation","options","id","operation","preferences","req","payload","t","idType","collections","relationTo","customIDType","db","defaultIDType","nodeID","value","Object","keys","length","collection","fields","result","collectionSlug","data","fieldSchema","siblingData","errorPaths","fieldKey","concat","join"],"sources":["../../../../src/features/upload/server/validate.ts"],"sourcesContent":["import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { isValidID } from 'payload'\n\nimport type { NodeValidation } from '../../typesServer.js'\nimport type { UploadFeatureProps } from './feature.server.js'\nimport type { SerializedUploadNode } from './nodes/UploadNode.js'\n\nexport const uploadValidation = (\n props: UploadFeatureProps,\n): NodeValidation<SerializedUploadNode> => {\n return async ({\n node,\n validation: {\n options: {\n id,\n operation,\n preferences,\n req,\n req: { payload, t },\n },\n },\n }) => {\n const idType = payload.collections[node.relationTo].customIDType || payload.db.defaultIDType\n // @ts-expect-error\n const nodeID = node?.value?.id || node?.value // for backwards-compatibility\n\n if (!isValidID(nodeID, idType)) {\n return t('validation:validUploadID')\n }\n\n if (!props?.collections) {\n return true\n }\n\n if (Object.keys(props?.collections).length === 0) {\n return true\n }\n\n const collection = props?.collections[node.relationTo]\n\n if (!collection?.fields?.length) {\n return true\n }\n\n const result = await buildStateFromSchema({\n id,\n collectionSlug: node.relationTo,\n data: node?.fields ?? {},\n fieldSchema: collection.fields,\n operation: operation === 'create' || operation === 'update' ? operation : 'update',\n preferences,\n req,\n siblingData: node?.fields ?? {},\n })\n\n let errorPaths: string[] = []\n for (const fieldKey in result) {\n if (result[fieldKey].errorPaths) {\n errorPaths = errorPaths.concat(result[fieldKey].errorPaths)\n }\n }\n\n if (errorPaths.length) {\n return 'The following fields are invalid: ' + errorPaths.join(', ')\n }\n\n return true\n }\n}\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ;AACrC,SAASC,SAAS,QAAQ;AAM1B,OAAO,MAAMC,gBAAA,GACXC,KAAA;EAEA,OAAO,OAAO;IACZC,IAAI;IACJC,UAAA,EAAY;MACVC,OAAA,EAAS;QACPC,EAAE;QACFC,SAAS;QACTC,WAAW;QACXC,GAAG;QACHA,GAAA,EAAK;UAAEC,OAAO;UAAEC;QAAC;MAAE;IACpB;EACF,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IAEA,IAAIA,UAAA,CAAWR,MAAM,EAAE;MACrB,OAAO,uCAAuCQ,UAAA,CAAWG,IAAI,CAAC;IAChE;IAEA,OAAO;EACT;AACF","ignoreList":[]}
1
+ {"version":3,"file":"validate.js","names":["fieldSchemasToFormState","isValidID","uploadValidation","props","node","validation","options","id","operation","preferences","req","payload","t","idType","collections","relationTo","customIDType","db","defaultIDType","nodeID","value","Object","keys","length","collection","fields","result","collectionSlug","data","fieldSchemaMap","undefined","permissions","renderAllFields","schemaPath","errorPaths","fieldKey","concat","join"],"sources":["../../../../src/features/upload/server/validate.ts"],"sourcesContent":["import { fieldSchemasToFormState } from '@payloadcms/ui/forms/fieldSchemasToFormState'\nimport { isValidID } from 'payload'\n\nimport type { NodeValidation } from '../../typesServer.js'\nimport type { UploadFeatureProps } from './feature.server.js'\nimport type { SerializedUploadNode } from './nodes/UploadNode.js'\n\nexport const uploadValidation = (\n props: UploadFeatureProps,\n): NodeValidation<SerializedUploadNode> => {\n return async ({\n node,\n validation: {\n options: {\n id,\n operation,\n preferences,\n req,\n req: { payload, t },\n },\n },\n }) => {\n const idType = payload.collections[node.relationTo].customIDType || payload.db.defaultIDType\n // @ts-expect-error\n const nodeID = node?.value?.id || node?.value // for backwards-compatibility\n\n if (!isValidID(nodeID, idType)) {\n return t('validation:validUploadID')\n }\n\n if (!props?.collections) {\n return true\n }\n\n if (Object.keys(props?.collections).length === 0) {\n return true\n }\n\n const collection = props?.collections[node.relationTo]\n\n if (!collection?.fields?.length) {\n return true\n }\n\n const result = await fieldSchemasToFormState({\n id,\n collectionSlug: node.relationTo,\n data: node?.fields ?? {},\n fields: collection.fields,\n fieldSchemaMap: undefined,\n operation: operation === 'create' || operation === 'update' ? operation : 'update',\n permissions: {},\n preferences,\n renderAllFields: false,\n req,\n schemaPath: '',\n })\n\n let errorPaths: string[] = []\n for (const fieldKey in result) {\n if (result[fieldKey].errorPaths) {\n errorPaths = errorPaths.concat(result[fieldKey].errorPaths)\n }\n }\n\n if (errorPaths.length) {\n return 'The following fields are invalid: ' + errorPaths.join(', ')\n }\n\n return true\n }\n}\n"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ;AACxC,SAASC,SAAS,QAAQ;AAM1B,OAAO,MAAMC,gBAAA,GACXC,KAAA;EAEA,OAAO,OAAO;IACZC,IAAI;IACJC,UAAA,EAAY;MACVC,OAAA,EAAS;QACPC,EAAE;QACFC,SAAS;QACTC,WAAW;QACXC,GAAG;QACHA,GAAA,EAAK;UAAEC,OAAO;UAAEC;QAAC;MAAE;IACpB;EACF,CACF;IACC,MAAMC,MAAA,GAASF,OAAA,CAAQG,WAAW,CAACV,IAAA,CAAKW,UAAU,CAAC,CAACC,YAAY,IAAIL,OAAA,CAAQM,EAAE,CAACC,aAAa;IAC5F;IACA,MAAMC,MAAA,GAASf,IAAA,EAAMgB,KAAA,EAAOb,EAAA,IAAMH,IAAA,EAAMgB,KAAA,CAAM;IAAA;IAE9C,IAAI,CAACnB,SAAA,CAAUkB,MAAA,EAAQN,MAAA,GAAS;MAC9B,OAAOD,CAAA,CAAE;IACX;IAEA,IAAI,CAACT,KAAA,EAAOW,WAAA,EAAa;MACvB,OAAO;IACT;IAEA,IAAIO,MAAA,CAAOC,IAAI,CAACnB,KAAA,EAAOW,WAAA,EAAaS,MAAM,KAAK,GAAG;MAChD,OAAO;IACT;IAEA,MAAMC,UAAA,GAAarB,KAAA,EAAOW,WAAW,CAACV,IAAA,CAAKW,UAAU,CAAC;IAEtD,IAAI,CAACS,UAAA,EAAYC,MAAA,EAAQF,MAAA,EAAQ;MAC/B,OAAO;IACT;IAEA,MAAMG,MAAA,GAAS,MAAM1B,uBAAA,CAAwB;MAC3CO,EAAA;MACAoB,cAAA,EAAgBvB,IAAA,CAAKW,UAAU;MAC/Ba,IAAA,EAAMxB,IAAA,EAAMqB,MAAA,IAAU,CAAC;MACvBA,MAAA,EAAQD,UAAA,CAAWC,MAAM;MACzBI,cAAA,EAAgBC,SAAA;MAChBtB,SAAA,EAAWA,SAAA,KAAc,YAAYA,SAAA,KAAc,WAAWA,SAAA,GAAY;MAC1EuB,WAAA,EAAa,CAAC;MACdtB,WAAA;MACAuB,eAAA,EAAiB;MACjBtB,GAAA;MACAuB,UAAA,EAAY;IACd;IAEA,IAAIC,UAAA,GAAuB,EAAE;IAC7B,KAAK,MAAMC,QAAA,IAAYT,MAAA,EAAQ;MAC7B,IAAIA,MAAM,CAACS,QAAA,CAAS,CAACD,UAAU,EAAE;QAC/BA,UAAA,GAAaA,UAAA,CAAWE,MAAM,CAACV,MAAM,CAACS,QAAA,CAAS,CAACD,UAAU;MAC5D;IACF;IAEA,IAAIA,UAAA,CAAWX,MAAM,EAAE;MACrB,OAAO,uCAAuCW,UAAA,CAAWG,IAAI,CAAC;IAChE;IAEA,OAAO;EACT;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAG1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAC7E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAG5D,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AACrB,OAAO,mCAAmC,CAAA;AAI1C,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAC/B;IACE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;CACnD,GAAG,yBAAyB,CAyG9B,CAAA;AAaD,eAAO,MAAM,QAAQ,EAAE,OAAO,iBAAoD,CAAA"}
1
+ {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAG1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAC7E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAG5D,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AACrB,OAAO,mCAAmC,CAAA;AAI1C,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAC/B;IACE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;CACnD,GAAG,yBAAyB,CAsG9B,CAAA;AAaD,eAAO,MAAM,QAAQ,EAAE,OAAO,iBAAoD,CAAA"}
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
- import { FieldDescription, FieldError, FieldLabel, useEditDepth, useField, useFieldProps, withCondition } from '@payloadcms/ui';
4
+ import { FieldLabel, useEditDepth, useField, withCondition } from '@payloadcms/ui';
5
5
  import React, { useCallback } from 'react';
6
6
  import { ErrorBoundary } from 'react-error-boundary';
7
7
  import { LexicalProvider } from '../lexical/LexicalProvider.js';
@@ -9,30 +9,25 @@ import './bundled.css';
9
9
  const baseClass = 'rich-text-lexical';
10
10
  const RichTextComponent = props => {
11
11
  const {
12
- descriptionProps,
13
12
  editorConfig,
14
- errorProps,
15
13
  field: {
16
14
  name,
17
- _path: pathFromProps,
18
15
  admin: {
19
16
  className,
20
- components,
21
17
  readOnly: readOnlyFromAdmin,
22
18
  style,
23
19
  width
24
20
  } = {},
21
+ label,
22
+ localized,
25
23
  required
26
24
  },
27
- field,
28
- labelProps,
25
+ path: pathFromProps,
29
26
  readOnly: readOnlyFromTopLevelProps,
30
27
  validate
31
28
  } = props;
32
- const Description = components?.Description;
33
- const Error = components?.Error;
34
- const Label = components?.Label;
35
29
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
30
+ const path = pathFromProps ?? name;
36
31
  const editDepth = useEditDepth();
37
32
  const memoizedValidate = useCallback((value, validationOptions) => {
38
33
  if (typeof validate === 'function') {
@@ -48,24 +43,25 @@ const RichTextComponent = props => {
48
43
  // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709
49
44
  [validate, required]);
50
45
  const {
51
- path: pathFromContext,
52
- readOnly: readOnlyFromContext
53
- } = useFieldProps();
54
- const fieldType = useField({
55
- path: pathFromContext ?? pathFromProps ?? name,
56
- // @ts-expect-error: TODO: Fix this
57
- validate: memoizedValidate
58
- });
59
- const {
46
+ customComponents: {
47
+ AfterInput,
48
+ BeforeInput,
49
+ Description,
50
+ Error,
51
+ Label
52
+ } = {},
60
53
  formInitializing,
61
54
  formProcessing,
62
55
  initialValue,
63
- path,
64
56
  setValue,
65
57
  showError,
66
58
  value: value_0
67
- } = fieldType;
68
- const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing;
59
+ } = useField({
60
+ path,
61
+ // @ts-expect-error: TODO: Fix this
62
+ validate: memoizedValidate
63
+ });
64
+ const disabled = readOnlyFromProps || formProcessing || formInitializing;
69
65
  const classes = [baseClass, 'field-type', className, showError && 'error', disabled && `${baseClass}--read-only`, editorConfig?.admin?.hideGutter !== true ? `${baseClass}--show-gutter` : null].filter(Boolean).join(' ');
70
66
  const pathWithEditDepth = `${path}.${editDepth}`;
71
67
  return /*#__PURE__*/_jsxs("div", {
@@ -74,25 +70,19 @@ const RichTextComponent = props => {
74
70
  ...style,
75
71
  width
76
72
  },
77
- children: [/*#__PURE__*/_jsx(FieldError, {
78
- CustomError: Error,
79
- path: path,
80
- ...(errorProps || {}),
81
- alignCaret: "left",
82
- field: field
83
- }), /*#__PURE__*/_jsx(FieldLabel, {
84
- Label: Label,
85
- ...(labelProps || {}),
86
- field: field
73
+ children: [Error, Label || /*#__PURE__*/_jsx(FieldLabel, {
74
+ label: label,
75
+ localized: localized,
76
+ required: required
87
77
  }), /*#__PURE__*/_jsxs("div", {
88
78
  className: `${baseClass}__wrap`,
89
- children: [/*#__PURE__*/_jsx(ErrorBoundary, {
79
+ children: [/*#__PURE__*/_jsxs(ErrorBoundary, {
90
80
  fallbackRender: fallbackRender,
91
81
  onReset: () => {},
92
- children: /*#__PURE__*/_jsx(LexicalProvider, {
82
+ children: [BeforeInput, /*#__PURE__*/_jsx(LexicalProvider, {
93
83
  composerKey: pathWithEditDepth,
94
84
  editorConfig: editorConfig,
95
- field: field,
85
+ fieldProps: props,
96
86
  onChange: editorState => {
97
87
  let serializedEditorState = editorState.toJSON();
98
88
  // Transform state through save hooks
@@ -110,12 +100,8 @@ const RichTextComponent = props => {
110
100
  }, JSON.stringify({
111
101
  initialValue,
112
102
  path
113
- }))
114
- }), /*#__PURE__*/_jsx(FieldDescription, {
115
- Description: Description,
116
- ...(descriptionProps || {}),
117
- field: field
118
- })]
103
+ })), AfterInput]
104
+ }), Description]
119
105
  })]
120
106
  }, pathWithEditDepth);
121
107
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Field.js","names":["FieldDescription","FieldError","FieldLabel","useEditDepth","useField","useFieldProps","withCondition","React","useCallback","ErrorBoundary","LexicalProvider","baseClass","RichTextComponent","props","descriptionProps","editorConfig","errorProps","field","name","_path","pathFromProps","admin","className","components","readOnly","readOnlyFromAdmin","style","width","required","labelProps","readOnlyFromTopLevelProps","validate","Description","Error","Label","readOnlyFromProps","editDepth","memoizedValidate","value","validationOptions","path","pathFromContext","readOnlyFromContext","fieldType","formInitializing","formProcessing","initialValue","setValue","showError","disabled","classes","hideGutter","filter","Boolean","join","pathWithEditDepth","_jsxs","_jsx","CustomError","alignCaret","fallbackRender","onReset","composerKey","onChange","editorState","serializedEditorState","toJSON","features","hooks","save","length","forEach","hook","incomingEditorState","JSON","stringify","error","role","color","message","RichText"],"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { SerializedEditorState } from 'lexical'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n useEditDepth,\n useField,\n useFieldProps,\n withCondition,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\nimport type { LexicalRichTextFieldProps } from '../types.js'\n\nimport { LexicalProvider } from '../lexical/LexicalProvider.js'\nimport './bundled.css'\nimport './index.scss'\nimport '../lexical/theme/EditorTheme.scss'\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 descriptionProps,\n editorConfig,\n errorProps,\n field: {\n name,\n _path: pathFromProps,\n admin: { className, components, readOnly: readOnlyFromAdmin, style, width } = {},\n required,\n },\n field,\n labelProps,\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 const Description = components?.Description\n const Error = components?.Error\n const Label = components?.Label\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const editDepth = useEditDepth()\n\n const memoizedValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n return validate(value, { ...validationOptions, props, required })\n }\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 const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps()\n\n const fieldType = useField<SerializedEditorState>({\n path: pathFromContext ?? pathFromProps ?? name,\n // @ts-expect-error: TODO: Fix this\n validate: memoizedValidate,\n })\n\n const { formInitializing, formProcessing, initialValue, path, setValue, showError, value } =\n fieldType\n\n const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true ? `${baseClass}--show-gutter` : null,\n ]\n .filter(Boolean)\n .join(' ')\n\n const pathWithEditDepth = `${path}.${editDepth}`\n\n return (\n <div\n className={classes}\n key={pathWithEditDepth}\n style={{\n ...style,\n width,\n }}\n >\n <FieldError\n CustomError={Error}\n path={path}\n {...(errorProps || {})}\n alignCaret=\"left\"\n field={field}\n />\n <FieldLabel Label={Label} {...(labelProps || {})} field={field} />\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n <LexicalProvider\n composerKey={pathWithEditDepth}\n editorConfig={editorConfig}\n field={field}\n key={JSON.stringify({ initialValue, path })} // 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={(editorState) => {\n let serializedEditorState = editorState.toJSON()\n\n // Transform state through save hooks\n if (editorConfig?.features?.hooks?.save?.length) {\n editorConfig.features.hooks.save.forEach((hook) => {\n serializedEditorState = hook({ incomingEditorState: serializedEditorState })\n })\n }\n\n setValue(serializedEditorState)\n }}\n readOnly={disabled}\n value={value}\n />\n </ErrorBoundary>\n <FieldDescription Description={Description} {...(descriptionProps || {})} field={field} />\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }): React.ReactElement {\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 = withCondition(RichTextComponent)\n"],"mappings":"AAAA;;;AAGA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,YAAY,EACZC,QAAQ,EACRC,aAAa,EACbC,aAAa,QACR;AACP,OAAOC,KAAA,IAASC,WAAW,QAAQ;AACnC,SAASC,aAAa,QAAQ;AAK9B,SAASC,eAAe,QAAQ;AAChC,OAAO;AAIP,MAAMC,SAAA,GAAY;AAElB,MAAMC,iBAAA,GAIDC,KAAA;EACH,MAAM;IACJC,gBAAgB;IAChBC,YAAY;IACZC,UAAU;IACVC,KAAA,EAAO;MACLC,IAAI;MACJC,KAAA,EAAOC,aAAa;MACpBC,KAAA,EAAO;QAAEC,SA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;UACVX,KAAA,EAAOA;WAdFoC,IAAA,CAAKC,SAAS,CAAC;UAAE7B,YAAA;UAAcN;QAAK;uBAiB7CiB,IAAA,CAACzD,gBAAA;QAAiBgC,WAAA,EAAaA,WAAA;QAAc,IAAIlB,gBAAA,IAAoB,CAAC,CAAC;QAAGG,KAAA,EAAOA;;;KArC9EsC,iBAAA;AAyCX;AAEA,SAASK,eAAe;EAAEgB;AAAK,CAAE;EAC/B;EAEA,oBACEpB,KAAA,CAAC;IAAIlC,SAAA,EAAU;IAAgBuD,IAAA,EAAK;4BAClCpB,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAI/B,KAAA,EAAO;QAAEoD,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqC1E,aAAA,CAAcM,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"Field.js","names":["FieldLabel","useEditDepth","useField","withCondition","React","useCallback","ErrorBoundary","LexicalProvider","baseClass","RichTextComponent","props","editorConfig","field","name","admin","className","readOnly","readOnlyFromAdmin","style","width","label","localized","required","path","pathFromProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","editDepth","memoizedValidate","value","validationOptions","customComponents","AfterInput","BeforeInput","Description","Error","Label","formInitializing","formProcessing","initialValue","setValue","showError","disabled","classes","hideGutter","filter","Boolean","join","pathWithEditDepth","_jsxs","_jsx","fallbackRender","onReset","composerKey","fieldProps","onChange","editorState","serializedEditorState","toJSON","features","hooks","save","length","forEach","hook","incomingEditorState","JSON","stringify","error","role","color","message","RichText"],"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { SerializedEditorState } from 'lexical'\n\nimport { FieldLabel, useEditDepth, useField, withCondition } from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\nimport type { LexicalRichTextFieldProps } from '../types.js'\n\nimport { LexicalProvider } from '../lexical/LexicalProvider.js'\nimport './bundled.css'\nimport './index.scss'\nimport '../lexical/theme/EditorTheme.scss'\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 name,\n admin: { className, readOnly: readOnlyFromAdmin, style, width } = {},\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 const path = pathFromProps ?? name\n\n const editDepth = useEditDepth()\n\n const memoizedValidate = useCallback(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n return validate(value, { ...validationOptions, props, required })\n }\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 formInitializing,\n formProcessing,\n initialValue,\n setValue,\n showError,\n value,\n } = useField<SerializedEditorState>({\n path,\n // @ts-expect-error: TODO: Fix this\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || formProcessing || formInitializing\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true ? `${baseClass}--show-gutter` : null,\n ]\n .filter(Boolean)\n .join(' ')\n\n const pathWithEditDepth = `${path}.${editDepth}`\n\n return (\n <div\n className={classes}\n key={pathWithEditDepth}\n style={{\n ...style,\n width,\n }}\n >\n {Error}\n {Label || <FieldLabel label={label} localized={localized} 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 key={JSON.stringify({ initialValue, path })} // 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={(editorState) => {\n let serializedEditorState = editorState.toJSON()\n\n // Transform state through save hooks\n if (editorConfig?.features?.hooks?.save?.length) {\n editorConfig.features.hooks.save.forEach((hook) => {\n serializedEditorState = hook({ incomingEditorState: serializedEditorState })\n })\n }\n\n setValue(serializedEditorState)\n }}\n readOnly={disabled}\n value={value}\n />\n {AfterInput}\n </ErrorBoundary>\n {Description}\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }): React.ReactElement {\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 = withCondition(RichTextComponent)\n"],"mappings":"AAAA;;;AAGA,SAASA,UAAU,EAAEC,YAAY,EAAEC,QAAQ,EAAEC,aAAa,QAAQ;AAClE,OAAOC,KAAA,IAASC,WAAW,QAAQ;AACnC,SAASC,aAAa,QAAQ;AAK9B,SAASC,eAAe,QAAQ;AAChC,OAAO;AAIP,MAAMC,SAAA,GAAY;AAElB,MAAMC,iBAAA,GAIDC,KAAA;EACH,MAAM;IACJC,YAAY;IACZC,KAAA,EAAO;MACLC,IAAI;MACJC,KAAA,EAAO;QAAEC,SAAS;QAAEC,QAAA,EAAUC,iBAAiB;QAAEC,KAAK;QAAEC;MAAK,CAAE,GAAG,CAAC,CAAC;MACpEC,KAAK;MACLC,SAAS;MACTC;IAAQ,CACT;IACDC,IAAA,EAAMC,aAAa;IACnBR,QAAA,EAAUS,yBAAyB;IACnCC;EAAQ,CACT,GAAGhB,KAAA;EAEJ,MAAMiB,iBAAA,GAAoBF,yBAAA,IAA6BR,iBA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