@payloadcms/richtext-lexical 4.0.0-beta.3 → 4.0.0-beta.4

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 (145) hide show
  1. package/dist/exports/client/Field-334JNLRF.js +2 -0
  2. package/dist/exports/client/Field-334JNLRF.js.map +7 -0
  3. package/dist/exports/client/{RelationshipComponent-YCPAKOL7.js → RelationshipComponent-TVK6I4W4.js} +2 -2
  4. package/dist/exports/client/chunk-BEKGION5.js +2 -0
  5. package/dist/exports/client/chunk-BEKGION5.js.map +7 -0
  6. package/dist/exports/client/{chunk-WSAPGI3Z.js → chunk-EA5BHQ2T.js} +1 -1
  7. package/dist/exports/client/{chunk-WSAPGI3Z.js.map → chunk-EA5BHQ2T.js.map} +1 -1
  8. package/dist/exports/client/chunk-FAJJXXCW.js +2 -0
  9. package/dist/exports/client/{chunk-3LRZDIIG.js.map → chunk-FAJJXXCW.js.map} +2 -2
  10. package/dist/exports/client/{chunk-5VIL27GI.js → chunk-IYBYNEKX.js} +1 -1
  11. package/dist/exports/client/{chunk-5VIL27GI.js.map → chunk-IYBYNEKX.js.map} +1 -1
  12. package/dist/exports/client/{chunk-VHUGOQ3X.js → chunk-SE5IITBK.js} +2 -2
  13. package/dist/exports/client/chunk-SE5IITBK.js.map +7 -0
  14. package/dist/exports/client/{component-ELXHSW52.js → component-QENB4QTS.js} +2 -2
  15. package/dist/exports/client/componentInline-AU7IBNY7.js +2 -0
  16. package/dist/exports/client/index.js +27 -27
  17. package/dist/exports/client/index.js.map +3 -3
  18. package/dist/features/align/client/index.js.map +1 -1
  19. package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
  20. package/dist/features/blocks/client/component/components/BlockCollapsible.js.map +1 -1
  21. package/dist/features/blocks/client/component/components/BlockEditButton.js.map +1 -1
  22. package/dist/features/blocks/client/component/components/BlockRemoveButton.js.map +1 -1
  23. package/dist/features/blocks/client/component/index.d.ts.map +1 -1
  24. package/dist/features/blocks/client/component/index.js +3 -2
  25. package/dist/features/blocks/client/component/index.js.map +1 -1
  26. package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.js.map +1 -1
  27. package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.js.map +1 -1
  28. package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.js.map +1 -1
  29. package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.js.map +1 -1
  30. package/dist/features/blocks/client/componentInline/index.js +2 -2
  31. package/dist/features/blocks/client/componentInline/index.js.map +1 -1
  32. package/dist/features/blocks/client/getCachedFormStateIfDataMatches.js.map +1 -1
  33. package/dist/features/blocks/client/plugin/index.js.map +1 -1
  34. package/dist/features/blocks/premade/CodeBlock/Component/Block.js +121 -78
  35. package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -1
  36. package/dist/features/blocks/premade/CodeBlock/Component/Code.js +142 -87
  37. package/dist/features/blocks/premade/CodeBlock/Component/Code.js.map +1 -1
  38. package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
  39. package/dist/features/debug/testRecorder/client/plugin/index.js.map +1 -1
  40. package/dist/features/debug/treeView/client/plugin/index.js.map +1 -1
  41. package/dist/features/heading/client/index.js.map +1 -1
  42. package/dist/features/horizontalRule/client/plugin/index.js.map +1 -1
  43. package/dist/features/indent/client/index.d.ts.map +1 -1
  44. package/dist/features/indent/client/index.js +0 -2
  45. package/dist/features/indent/client/index.js.map +1 -1
  46. package/dist/features/link/client/plugins/autoLink/index.js.map +1 -1
  47. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
  48. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +10 -2
  49. package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
  50. package/dist/features/link/client/plugins/link/index.js.map +1 -1
  51. package/dist/features/link/markdownTransformer.js +2 -2
  52. package/dist/features/link/markdownTransformer.js.map +1 -1
  53. package/dist/features/link/server/baseFields.js.map +1 -1
  54. package/dist/features/relationship/client/drawer/index.js.map +1 -1
  55. package/dist/features/relationship/client/plugins/index.js.map +1 -1
  56. package/dist/features/relationship/client/utils/useEnabledRelationships.js.map +1 -1
  57. package/dist/features/table/client/plugins/TableActionMenuPlugin/index.css +1 -1
  58. package/dist/features/table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
  59. package/dist/features/table/client/plugins/TableCellResizerPlugin/index.js +6 -6
  60. package/dist/features/table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
  61. package/dist/features/table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
  62. package/dist/features/table/client/plugins/TablePlugin/index.js +54 -18
  63. package/dist/features/table/client/plugins/TablePlugin/index.js.map +1 -1
  64. package/dist/features/table/client/utils/useDebounce.js.map +1 -1
  65. package/dist/features/toolbars/fixed/client/Toolbar/horizontalWheelScroll.js.map +1 -1
  66. package/dist/features/toolbars/fixed/client/Toolbar/index.js +126 -70
  67. package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
  68. package/dist/features/toolbars/inline/client/Toolbar/index.js +67 -35
  69. package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
  70. package/dist/features/toolbars/shared/ToolbarButton/index.d.ts.map +1 -1
  71. package/dist/features/toolbars/shared/ToolbarButton/index.js +26 -2
  72. package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
  73. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +137 -72
  74. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
  75. package/dist/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -1
  76. package/dist/features/toolbars/shared/ToolbarDropdown/index.js +22 -6
  77. package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
  78. package/dist/features/toolbars/shared/useToolbarKeyboardNavigation.js +100 -70
  79. package/dist/features/toolbars/shared/useToolbarKeyboardNavigation.js.map +1 -1
  80. package/dist/features/upload/client/drawer/index.js.map +1 -1
  81. package/dist/features/upload/client/plugin/index.js.map +1 -1
  82. package/dist/field/RenderLexical/index.js.map +1 -1
  83. package/dist/field/ViewSelector.js +12 -4
  84. package/dist/field/ViewSelector.js.map +1 -1
  85. package/dist/field/bundled.css +1 -1
  86. package/dist/field/index.js.map +1 -1
  87. package/dist/i18n.d.ts.map +1 -1
  88. package/dist/i18n.js +44 -0
  89. package/dist/i18n.js.map +1 -1
  90. package/dist/lexical/LexicalEditor.js.map +1 -1
  91. package/dist/lexical/plugins/ClipboardPlugin/index.js.map +1 -1
  92. package/dist/lexical/plugins/DecoratorPlugin/index.js.map +1 -1
  93. package/dist/lexical/plugins/InsertParagraphAtEnd/index.js.map +1 -1
  94. package/dist/lexical/plugins/MarkdownShortcut/index.js.map +1 -1
  95. package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +1 -1
  96. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +234 -87
  97. package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
  98. package/dist/lexical/plugins/SlashMenu/useMenuTriggerMatch.js.map +1 -1
  99. package/dist/lexical/plugins/TextPlugin/index.js.map +1 -1
  100. package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
  101. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.css +16 -0
  102. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts.map +1 -1
  103. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +126 -38
  104. package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
  105. package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.d.ts +7 -0
  106. package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.d.ts.map +1 -0
  107. package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.js +15 -0
  108. package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.js.map +1 -0
  109. package/dist/lexical/plugins/handles/DraggableBlockPlugin/useKeyboardReordering.d.ts.map +1 -1
  110. package/dist/lexical/plugins/handles/DraggableBlockPlugin/useKeyboardReordering.js +9 -12
  111. package/dist/lexical/plugins/handles/DraggableBlockPlugin/useKeyboardReordering.js.map +1 -1
  112. package/dist/lexical/ui/ContentEditable.js.map +1 -1
  113. package/dist/lexical/utils/nodeFormat.d.ts.map +1 -1
  114. package/dist/lexical/utils/nodeFormat.js +0 -2
  115. package/dist/lexical/utils/nodeFormat.js.map +1 -1
  116. package/dist/lexical/utils/url.d.ts.map +1 -1
  117. package/dist/lexical/utils/url.js +1 -1
  118. package/dist/lexical/utils/url.js.map +1 -1
  119. package/dist/populateGraphQL/populate.js.map +1 -1
  120. package/dist/utilities/fieldsDrawer/Drawer.js +36 -36
  121. package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
  122. package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
  123. package/dist/utilities/fieldsDrawer/DrawerContent.js +5 -3
  124. package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
  125. package/dist/utilities/fieldsDrawer/useDrawerSubmit.js.map +1 -1
  126. package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.js.map +1 -1
  127. package/dist/utilities/fieldsDrawer/useLexicalDrawer.js.map +1 -1
  128. package/dist/utilities/fieldsDrawer/useLexicalListDrawer.js.map +1 -1
  129. package/dist/utilities/initLexicalFeatures.d.ts.map +1 -1
  130. package/dist/utilities/initLexicalFeatures.js +38 -4
  131. package/dist/utilities/initLexicalFeatures.js.map +1 -1
  132. package/dist/utilities/useLexicalFeature.js +15 -6
  133. package/dist/utilities/useLexicalFeature.js.map +1 -1
  134. package/dist/utilities/useRunDeprioritized.js.map +1 -1
  135. package/package.json +12 -15
  136. package/dist/exports/client/Field-W2ABOM7M.js +0 -2
  137. package/dist/exports/client/Field-W2ABOM7M.js.map +0 -7
  138. package/dist/exports/client/chunk-3LRZDIIG.js +0 -2
  139. package/dist/exports/client/chunk-UH7ALTP6.js +0 -2
  140. package/dist/exports/client/chunk-UH7ALTP6.js.map +0 -7
  141. package/dist/exports/client/chunk-VHUGOQ3X.js.map +0 -7
  142. package/dist/exports/client/componentInline-N7HK3HP3.js +0 -2
  143. /package/dist/exports/client/{RelationshipComponent-YCPAKOL7.js.map → RelationshipComponent-TVK6I4W4.js.map} +0 -0
  144. /package/dist/exports/client/{component-ELXHSW52.js.map → component-QENB4QTS.js.map} +0 -0
  145. /package/dist/exports/client/{componentInline-N7HK3HP3.js.map → componentInline-AU7IBNY7.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"DrawerContent.js","names":["useLexicalEditable","Form","RenderFields","useDocumentForm","useDocumentInfo","useServerFunctions","abortAndIgnore","React","useCallback","useEffect","useRef","useState","v4","uuid","useEditorConfigContext","RegisterFormSubmit","DrawerContent","data","featureKey","fieldMapOverride","handleDrawerSubmit","schemaFieldsPathOverride","schemaPath","schemaPathSuffix","submitRef","id","collectionSlug","getDocPreferences","globalSlug","fields","parentDocumentFields","isEditable","onChangeAbortControllerRef","AbortController","initialState","setInitialState","fieldProps","featureClientSchemaMap","getFormState","schemaFieldsPath","controller","awaitInitialState","state","docPermissions","docPreferences","documentFormState","initialBlockData","operation","readOnly","renderAllFields","signal","onChange","formState","prevFormState","current","initialBlockFormState","_jsxs","beforeSubmit","className","disableValidationOnSubmit","Array","isArray","onSubmit","_jsx","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions"],"sources":["../../../src/utilities/fieldsDrawer/DrawerContent.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload'\n\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport {\n Form,\n RenderFields,\n useDocumentForm,\n useDocumentInfo,\n useServerFunctions,\n} from '@payloadcms/ui'\nimport { abortAndIgnore } from '@payloadcms/ui/shared'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport type { FieldsDrawerProps } from './Drawer.js'\n\nimport { useEditorConfigContext } from '../../lexical/config/client/EditorConfigProvider.js'\nimport { RegisterFormSubmit } from './useDrawerSubmit.js'\nimport './index.css'\n\nexport const DrawerContent: React.FC<\n {\n submitRef: React.RefObject<(() => void) | null>\n } & Omit<FieldsDrawerProps, 'drawerSlug' | 'drawerTitle'>\n> = ({\n data,\n featureKey,\n fieldMapOverride,\n handleDrawerSubmit,\n schemaFieldsPathOverride,\n schemaPath,\n schemaPathSuffix,\n submitRef,\n}) => {\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n const { fields: parentDocumentFields } = useDocumentForm()\n const isEditable = useLexicalEditable()\n\n const onChangeAbortControllerRef = useRef(new AbortController())\n\n const [initialState, setInitialState] = useState<false | FormState | undefined>(false)\n\n const {\n fieldProps: { featureClientSchemaMap },\n } = useEditorConfigContext()\n\n const { getFormState } = useServerFunctions()\n\n const schemaFieldsPath =\n schemaFieldsPathOverride ??\n `${schemaPath}.lexical_internal_feature.${featureKey}${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`\n\n const fields: any = fieldMapOverride ?? featureClientSchemaMap[featureKey]?.[schemaFieldsPath] // Field Schema\n\n useEffect(() => {\n const controller = new AbortController()\n\n const awaitInitialState = async () => {\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: data ?? {},\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: parentDocumentFields,\n globalSlug,\n initialBlockData: data,\n operation: 'update',\n readOnly: !isEditable,\n renderAllFields: true,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n setInitialState(state)\n }\n\n void awaitInitialState()\n\n return () => {\n abortAndIgnore(controller)\n }\n }, [\n schemaFieldsPath,\n id,\n data,\n getFormState,\n collectionSlug,\n isEditable,\n globalSlug,\n getDocPreferences,\n parentDocumentFields,\n ])\n\n const onChange = useCallback(\n async ({ formState: prevFormState }: { formState: FormState }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n\n const { state } = await getFormState({\n id,\n collectionSlug,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: parentDocumentFields,\n formState: prevFormState,\n globalSlug,\n initialBlockFormState: prevFormState,\n operation: 'update',\n readOnly: !isEditable,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n if (!state) {\n return prevFormState\n }\n\n return state\n },\n [\n getFormState,\n id,\n isEditable,\n collectionSlug,\n getDocPreferences,\n parentDocumentFields,\n globalSlug,\n schemaFieldsPath,\n ],\n )\n\n // cleanup effect\n useEffect(() => {\n return () => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [])\n\n if (initialState === false) {\n return null\n }\n\n return (\n <Form\n beforeSubmit={[onChange]}\n className=\"fields-drawer\"\n disableValidationOnSubmit\n fields={Array.isArray(fields) ? fields : []}\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={handleDrawerSubmit}\n uuid={uuid()}\n >\n <RenderFields\n fields={Array.isArray(fields) ? fields : []}\n forceRender\n parentIndexPath=\"\"\n parentPath=\"\" // See Blocks feature path for details as for why this is empty\n parentSchemaPath={schemaFieldsPath}\n permissions={true}\n readOnly={!isEditable}\n />\n <RegisterFormSubmit submitRef={submitRef} />\n </Form>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,kBAAkB,QAAQ;AACnC,SACEC,IAAI,EACJC,YAAY,EACZC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb;AACP,SAASC,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAChE,SAASC,EAAA,IAAMC,IAAI,QAAQ;AAI3B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,kBAAkB,QAAQ;AACnC,OAAO;AAEP,OAAO,MAAMC,aAAA,GAITA,CAAC;EACHC,IAAI;EACJC,UA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BACEsB,KAAA,CAACvD,IAAA;IACCwD,YAAA,EAAc,CAACN,QAAA,CAAS;IACxBO,SAAA,EAAU;IACVC,yBAAyB;IACzB9B,MAAA,EAAQ+B,KAAA,CAAMC,OAAO,CAAChC,MAAA,IAAUA,MAAA,GAAS,EAAE;IAC3CK,YAAA,EAAcA,YAAA;IACdiB,QAAA,EAAU,CAACA,QAAA,CAAS;IACpBW,QAAA,EAAU1C,kBAAA;IACVP,IAAA,EAAMA,IAAA;4BAENkD,IAAA,CAAC7D,YAAA;MACC2B,MAAA,EAAQ+B,KAAA,CAAMC,OAAO,CAAChC,MAAA,IAAUA,MAAA,GAAS,EAAE;MAC3CmC,WAAW;MACXC,eAAA,EAAgB;MAChBC,UAAA,EAAW;MACXC,gBAAA,EAAkB5B,gBAAA;MAClB6B,WAAA,EAAa;MACbpB,QAAA,EAAU,CAACjB;qBAEbgC,IAAA,CAAChD,kBAAA;MAAmBS,SAAA,EAAWA;;;AAGrC","ignoreList":[]}
1
+ {"version":3,"file":"DrawerContent.js","names":["useLexicalEditable","Form","RenderFields","useDocumentForm","useDocumentInfo","useEffectEvent","useServerFunctions","abortAndIgnore","React","useCallback","useEffect","useRef","useState","v4","uuid","useEditorConfigContext","RegisterFormSubmit","DrawerContent","data","featureKey","fieldMapOverride","handleDrawerSubmit","schemaFieldsPathOverride","schemaPath","schemaPathSuffix","submitRef","id","collectionSlug","getDocPreferences","globalSlug","fields","parentDocumentFields","isEditable","onChangeAbortControllerRef","AbortController","initialState","setInitialState","fieldProps","featureClientSchemaMap","getFormState","schemaFieldsPath","getParentDocumentFields","controller","awaitInitialState","state","docPermissions","docPreferences","documentFormState","initialBlockData","operation","readOnly","renderAllFields","signal","onChange","formState","prevFormState","current","initialBlockFormState","_jsxs","beforeSubmit","className","disableValidationOnSubmit","Array","isArray","onSubmit","_jsx","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions"],"sources":["../../../src/utilities/fieldsDrawer/DrawerContent.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload'\n\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport {\n Form,\n RenderFields,\n useDocumentForm,\n useDocumentInfo,\n useEffectEvent,\n useServerFunctions,\n} from '@payloadcms/ui'\nimport { abortAndIgnore } from '@payloadcms/ui/shared'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport type { FieldsDrawerProps } from './Drawer.js'\n\nimport { useEditorConfigContext } from '../../lexical/config/client/EditorConfigProvider.js'\nimport { RegisterFormSubmit } from './useDrawerSubmit.js'\nimport './index.css'\n\nexport const DrawerContent: React.FC<\n {\n submitRef: React.RefObject<(() => void) | null>\n } & Omit<FieldsDrawerProps, 'drawerSlug' | 'drawerTitle'>\n> = ({\n data,\n featureKey,\n fieldMapOverride,\n handleDrawerSubmit,\n schemaFieldsPathOverride,\n schemaPath,\n schemaPathSuffix,\n submitRef,\n}) => {\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n const { fields: parentDocumentFields } = useDocumentForm()\n const isEditable = useLexicalEditable()\n\n const onChangeAbortControllerRef = useRef(new AbortController())\n\n const [initialState, setInitialState] = useState<false | FormState | undefined>(false)\n\n const {\n fieldProps: { featureClientSchemaMap },\n } = useEditorConfigContext()\n\n const { getFormState } = useServerFunctions()\n\n const schemaFieldsPath =\n schemaFieldsPathOverride ??\n `${schemaPath}.lexical_internal_feature.${featureKey}${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`\n\n const fields: any = fieldMapOverride ?? featureClientSchemaMap[featureKey]?.[schemaFieldsPath] // Field Schema\n\n // Parent autosave updates this context without starting a new drawer editing session.\n const getParentDocumentFields = useEffectEvent(() => parentDocumentFields)\n\n useEffect(() => {\n const controller = new AbortController()\n\n const awaitInitialState = async () => {\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: data ?? {},\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: getParentDocumentFields(),\n globalSlug,\n initialBlockData: data,\n operation: 'update',\n readOnly: !isEditable,\n renderAllFields: true,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n setInitialState(state)\n }\n\n void awaitInitialState()\n\n return () => {\n abortAndIgnore(controller)\n }\n }, [\n schemaFieldsPath,\n id,\n data,\n getFormState,\n collectionSlug,\n isEditable,\n globalSlug,\n getDocPreferences,\n ])\n\n const onChange = useCallback(\n async ({ formState: prevFormState }: { formState: FormState }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n\n const { state } = await getFormState({\n id,\n collectionSlug,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: parentDocumentFields,\n formState: prevFormState,\n globalSlug,\n initialBlockFormState: prevFormState,\n operation: 'update',\n readOnly: !isEditable,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n if (!state) {\n return prevFormState\n }\n\n return state\n },\n [\n getFormState,\n id,\n isEditable,\n collectionSlug,\n getDocPreferences,\n parentDocumentFields,\n globalSlug,\n schemaFieldsPath,\n ],\n )\n\n // cleanup effect\n useEffect(() => {\n return () => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [])\n\n if (initialState === false) {\n return null\n }\n\n return (\n <Form\n beforeSubmit={[onChange]}\n className=\"fields-drawer\"\n disableValidationOnSubmit\n fields={Array.isArray(fields) ? fields : []}\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={handleDrawerSubmit}\n uuid={uuid()}\n >\n <RenderFields\n fields={Array.isArray(fields) ? fields : []}\n forceRender\n parentIndexPath=\"\"\n parentPath=\"\" // See Blocks feature path for details as for why this is empty\n parentSchemaPath={schemaFieldsPath}\n permissions={true}\n readOnly={!isEditable}\n />\n <RegisterFormSubmit submitRef={submitRef} />\n </Form>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,kBAAkB,QAAQ;AACnC,SACEC,IAAI,EACJC,YAAY,EAC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QV,YAAA,CAAWU;IACrB;IAEA,IAAI,CAACR,OAAA,EAAO;MACV,OAAOW,aAAA;IACT;IAEA,OAAOX,OAAA;EACT,GACA,CACEL,YAAA,EACAb,EAAA,EACAM,UAAA,EACAL,cAAA,EACAC,iBAAA,EACAG,oBAAA,EACAF,UAAA,EACAW,gBAAA,CACD;EAGH;EACA9B,SAAA,CAAU;IACR,OAAO;MACLH,cAAA,CAAe0B,0BAAA,CAA2BuB,OAAO;IACnD;EACF,GAAG,EAAE;EAEL,IAAIrB,YAAA,KAAiB,OAAO;IAC1B,OAAO;EACT;EAEA,oBACEuB,KAAA,CAACzD,IAAA;IACC0D,YAAA,EAAc,CAACN,QAAA,CAAS;IACxBO,SAAA,EAAU;IACVC,yBAAyB;IACzB/B,MAAA,EAAQgC,KAAA,CAAMC,OAAO,CAACjC,MAAA,IAAUA,MAAA,GAAS,EAAE;IAC3CK,YAAA,EAAcA,YAAA;IACdkB,QAAA,EAAU,CAACA,QAAA,CAAS;IACpBW,QAAA,EAAU3C,kBAAA;IACVP,IAAA,EAAMA,IAAA;4BAENmD,IAAA,CAAC/D,YAAA;MACC4B,MAAA,EAAQgC,KAAA,CAAMC,OAAO,CAACjC,MAAA,IAAUA,MAAA,GAAS,EAAE;MAC3CoC,WAAW;MACXC,eAAA,EAAgB;MAChBC,UAAA,EAAW;MACXC,gBAAA,EAAkB7B,gBAAA;MAClB8B,WAAA,EAAa;MACbpB,QAAA,EAAU,CAAClB;qBAEbiC,IAAA,CAACjD,kBAAA;MAAmBS,SAAA,EAAWA;;;AAGrC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useDrawerSubmit.js","names":["c","_c","useForm","useTranslation","useEffect","useMemo","useRef","useDrawerSubmit","$","t","submitRef","t0","t1","Symbol","for","current","t2","label","onClick","style","headerActions","t3","RegisterFormSubmit","submit"],"sources":["../../../src/utilities/fieldsDrawer/useDrawerSubmit.ts"],"sourcesContent":["'use client'\nimport type { FC } from 'react'\nimport type React from 'react'\n\nimport { useForm, useTranslation } from '@payloadcms/ui'\nimport { useEffect, useMemo, useRef } from 'react'\n\n/**\n * Shared logic for drawers that render their submit button in the drawer header.\n *\n * The header's `onClick` is defined outside the `Form` provider, so it cannot call\n * `useForm().submit()` directly. This hook owns a ref to the form's `submit` function,\n * which is populated from inside the form via `<RegisterFormSubmit submitRef={submitRef} />`.\n *\n * Returns the `headerActions` array to spread onto a `Drawer` and the `submitRef`\n * to pass to `RegisterFormSubmit`.\n */\nexport const useDrawerSubmit = () => {\n const { t } = useTranslation()\n const submitRef = useRef<(() => void) | null>(null)\n\n const headerActions = useMemo(\n () => [\n {\n label: t('fields:saveChanges'),\n onClick: () => submitRef.current?.(),\n style: 'primary' as const,\n },\n ],\n [t],\n )\n\n return { headerActions, submitRef }\n}\n\n/**\n * Mounts inside a `<Form>` to populate `submitRef` (from `useDrawerSubmit`) with the form's\n * `submit` function, allowing drawer header actions rendered outside the form's React tree\n * to trigger submission.\n */\nexport const RegisterFormSubmit: FC<{\n submitRef: React.RefObject<(() => void) | null>\n}> = ({ submitRef }) => {\n const { submit } = useForm()\n\n useEffect(() => {\n submitRef.current = () => void submit()\n return () => {\n submitRef.current = null\n }\n }, [submit, submitRef])\n\n return null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAIA,SAASC,OAAO,EAAEC,cAAc,QAAQ;AACxC,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAE3C;;;;;;;;;;AAUA,OAAO,MAAMC,eAAA,GAAkBA,CAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EAC7B;IAAAQ;EAAA,IAAcN,cAAA;EACd,MAAAO,SAAA,GAAkBJ,MAAA,KAA4B;EAAA,IAAAK,EAAA;EAAA,IAAAH,CAAA,QAAAC,CAAA;IAKjCE,EAAA,GAAAF,CAAA,CAAE;IAAAD,CAAA,MAAAC,CAAA;IAAAD,CAAA,MAAAG,EAAA;EAAA;IAAAA,EAAA,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A;IAAAQ,EAAA,GAAAR,CAAA;EAAA;EALtBJ,SAAA,CAAUQ,EAKV,EAAGI,EAAmB;EAAA;AAAA,CAGxB","ignoreList":[]}
1
+ {"version":3,"file":"useDrawerSubmit.js","names":["c","_c","useForm","useTranslation","useEffect","useMemo","useRef","useDrawerSubmit","$","t","submitRef","t0","t1","Symbol","for","current","t2","label","onClick","style","headerActions","t3","RegisterFormSubmit","submit"],"sources":["../../../src/utilities/fieldsDrawer/useDrawerSubmit.ts"],"sourcesContent":["'use client'\nimport type { FC } from 'react'\nimport type React from 'react'\n\nimport { useForm, useTranslation } from '@payloadcms/ui'\nimport { useEffect, useMemo, useRef } from 'react'\n\n/**\n * Shared logic for drawers that render their submit button in the drawer header.\n *\n * The header's `onClick` is defined outside the `Form` provider, so it cannot call\n * `useForm().submit()` directly. This hook owns a ref to the form's `submit` function,\n * which is populated from inside the form via `<RegisterFormSubmit submitRef={submitRef} />`.\n *\n * Returns the `headerActions` array to spread onto a `Drawer` and the `submitRef`\n * to pass to `RegisterFormSubmit`.\n */\nexport const useDrawerSubmit = () => {\n const { t } = useTranslation()\n const submitRef = useRef<(() => void) | null>(null)\n\n const headerActions = useMemo(\n () => [\n {\n label: t('fields:saveChanges'),\n onClick: () => submitRef.current?.(),\n style: 'primary' as const,\n },\n ],\n [t],\n )\n\n return { headerActions, submitRef }\n}\n\n/**\n * Mounts inside a `<Form>` to populate `submitRef` (from `useDrawerSubmit`) with the form's\n * `submit` function, allowing drawer header actions rendered outside the form's React tree\n * to trigger submission.\n */\nexport const RegisterFormSubmit: FC<{\n submitRef: React.RefObject<(() => void) | null>\n}> = ({ submitRef }) => {\n const { submit } = useForm()\n\n useEffect(() => {\n submitRef.current = () => void submit()\n return () => {\n submitRef.current = null\n }\n }, [submit, submitRef])\n\n return null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAIA,SAASC,OAAO,EAAEC,cAAc,QAAQ;AACxC,SAASC,SAAS,EAAEC,O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EAAA;EAAA,IAAAR,CAAA,QAAAe,MAAA,IAAAf,CAAA,QAAAE,SAAA;IAETE,EAAA,GAAAA,CAAA;MACRF,SAAA,CAAAK,OAAA,GAAoB,MAAM,KAAKQ,MAAA,EAAd;MAAA,OACV;QACLb,SAAA,CAAAK,OAAA,GAAoB,IAAH;MAAA,CACnB;IAAA,CACF;IAAGC,EAAA,IAACO,MAAA,EAAQb,SAAA,CAAU;IAAAF,CAAA,MAAAe,MAAA;IAAAf,CAAA,MAAAE,SAAA;IAAAF,CAAA,MAAAI,EAAA;IAAAJ,CAAA,MAAAQ,EAAA;EAAA;IAAAJ,EAAA,GAAAJ,CAAA;IAAAQ,EAAA,GAAAR,CAAA;EAAA;EALtBJ,SAAA,CAAUQ,EAKV,EAAGI,EAAmB;EAAA,OAEf;AAAA,CACT","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useLexicalDocumentDrawer.js","names":["c","_c","useLexicalComposerContext","useDocumentDrawer","useModal","$getPreviousSelection","$getSelection","$setSelection","useCallback","useEffect","useState","useLexicalDocumentDrawer","args","$","editor","selectionState","setSelectionState","wasOpen","setWasOpen","DocumentDrawer","DocumentDrawerToggler","t0","closeDrawer","drawerSlug","documentDrawerSlug","openDrawer","modalState","t1","read","selection","storeSelection","t2","update","clone","discrete","skipTransforms","restoreSelection","t3","closeDocumentDrawer","t4","t5","thisModalState","isOpen","setTimeout","t6","openDocumentDrawer","t7","props","_jsx","onClick","t8"],"sources":["../../../src/utilities/fieldsDrawer/useLexicalDocumentDrawer.tsx"],"sourcesContent":["'use client'\nimport type { UseDocumentDrawer } from '@payloadcms/ui'\nimport type { BaseSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useDocumentDrawer, useModal } from '@payloadcms/ui'\nimport { $getPreviousSelection, $getSelection, $setSelection } from 'lexical'\nimport { useCallback, useEffect, useState } from 'react'\n\n/**\n *\n * Wrapper around useDocumentDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.\n * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.\n */\nexport const useLexicalDocumentDrawer = (\n args: Parameters<UseDocumentDrawer>[0],\n): {\n closeDocumentDrawer: () => void\n DocumentDrawer: ReturnType<UseDocumentDrawer>[0]\n documentDrawerSlug: string\n DocumentDrawerToggler: ReturnType<UseDocumentDrawer>[1]\n openDocumentDrawer: () => void\n} => {\n const [editor] = useLexicalComposerContext()\n const [selectionState, setSelectionState] = useState<BaseSelection | null>(null)\n const [wasOpen, setWasOpen] = useState<boolean>(false)\n\n const [\n DocumentDrawer,\n DocumentDrawerToggler,\n { closeDrawer: closeDrawer, drawerSlug: documentDrawerSlug, openDrawer },\n ] = useDocumentDrawer(args)\n const { modalState } = useModal()\n\n const storeSelection = useCallback(() => {\n editor.read(() => {\n const selection = $getSelection() ?? $getPreviousSelection()\n setSelectionState(selection)\n })\n setWasOpen(true)\n }, [editor])\n\n const restoreSelection = useCallback(() => {\n if (selectionState) {\n editor.update(\n () => {\n $setSelection(selectionState.clone())\n },\n { discrete: true, skipTransforms: true },\n )\n }\n }, [editor, selectionState])\n\n const closeDocumentDrawer = () => {\n //restoreSelection() // Should already be stored by the useEffect below\n closeDrawer()\n }\n\n // We need to handle drawer closing via a useEffect, as toggleDrawer / closeDrawer will not be triggered if the drawer\n // is closed by clicking outside of the drawer. This useEffect will handle everything.\n useEffect(() => {\n if (!wasOpen) {\n return\n }\n\n const thisModalState = modalState[documentDrawerSlug]\n // Exists in modalState (thus has opened at least once before) and is closed\n if (thisModalState && !thisModalState?.isOpen) {\n setWasOpen(false)\n setTimeout(() => {\n restoreSelection()\n }, 1)\n }\n }, [modalState, documentDrawerSlug, restoreSelection, wasOpen])\n\n const openDocumentDrawer = useCallback(() => {\n storeSelection()\n openDrawer()\n }, [storeSelection, openDrawer])\n\n return {\n closeDocumentDrawer,\n DocumentDrawer,\n documentDrawerSlug,\n DocumentDrawerToggler: (props) => <DocumentDrawerToggler {...props} onClick={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AY,UAAA,IAAAZ,CAAA,SAAAiB,cAAA;IAEvBc,EAAA,GAAAA,CAAA;MACrCd,cAAA;MACAL,UAAA;IAAA;IACFZ,CAAA,OAAAY,UAAA;IAAAZ,CAAA,OAAAiB,cAAA;IAAAjB,CAAA,OAAA+B,EAAA;EAAA;IAAAA,EAAA,GAAA/B,CAAA;EAAA;EAHA,MAAAgC,kBAAA,GAA2BD,EAGI;EAAA,IAAAE,EAAA;EAAA,IAAAjC,CAAA,SAAAO,qBAAA,IAAAP,CAAA,SAAAiB,cAAA;IAMNgB,EAAA,GAAAC,KAAA,IAAWC,IAAA,CAAC5B,qBAAA;MAAA,GAA0B2B,KAAK;MAAAE,OAAA,EAAWnB;IAAA,C;;;;;;;;;IAJxEoB,EAAA;MAAAZ,mBAAA;MAAAnB,cAAA;MAAAK,kBAAA;MAAAJ,qBAAA,EAIkB0B,E;;;IAEzBjC,CAAA,OAAAM,cAAA;IAAAN,CAAA,OAAAyB,mBAAA;IAAAzB,CAAA,OAAAW,kBAAA;IAAAX,CAAA,OAAAgC,kBAAA;IAAAhC,CAAA,OAAAiC,EAAA;IAAAjC,CAAA,OAAAqC,EAAA;EAAA;IAAAA,EAAA,GAAArC,CAAA;EAAA;EAAA,OANOqC,EAMP;AAAA,CACF","ignoreList":[]}
1
+ {"version":3,"file":"useLexicalDocumentDrawer.js","names":["c","_c","useLexicalComposerContext","useDocumentDrawer","useModal","$getPreviousSelection","$getSelection","$setSelection","useCallback","useEffect","useState","useLexicalDocumentDrawer","args","$","editor","selectionState","setSelectionState","wasOpen","setWasOpen","DocumentDrawer","DocumentDrawerToggler","t0","closeDrawer","drawerSlug","documentDrawerSlug","openDrawer","modalState","t1","read","selection","storeSelection","t2","update","clone","discrete","skipTransforms","restoreSelection","t3","closeDocumentDrawer","t4","t5","thisModalState","isOpen","setTimeout","t6","openDocumentDrawer","t7","props","_jsx","onClick","t8"],"sources":["../../../src/utilities/fieldsDrawer/useLexicalDocumentDrawer.tsx"],"sourcesContent":["'use client'\nimport type { UseDocumentDrawer } from '@payloadcms/ui'\nimport type { BaseSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useDocumentDrawer, useModal } from '@payloadcms/ui'\nimport { $getPreviousSelection, $getSelection, $setSelection } from 'lexical'\nimport { useCallback, useEffect, useState } from 'react'\n\n/**\n *\n * Wrapper around useDocumentDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.\n * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.\n */\nexport const useLexicalDocumentDrawer = (\n args: Parameters<UseDocumentDrawer>[0],\n): {\n closeDocumentDrawer: () => void\n DocumentDrawer: ReturnType<UseDocumentDrawer>[0]\n documentDrawerSlug: string\n DocumentDrawerToggler: ReturnType<UseDocumentDrawer>[1]\n openDocumentDrawer: () => void\n} => {\n const [editor] = useLexicalComposerContext()\n const [selectionState, setSelectionState] = useState<BaseSelection | null>(null)\n const [wasOpen, setWasOpen] = useState<boolean>(false)\n\n const [\n DocumentDrawer,\n DocumentDrawerToggler,\n { closeDrawer: closeDrawer, drawerSlug: documentDrawerSlug, openDrawer },\n ] = useDocumentDrawer(args)\n const { modalState } = useModal()\n\n const storeSelection = useCallback(() => {\n editor.read(() => {\n const selection = $getSelection() ?? $getPreviousSelection()\n setSelectionState(selection)\n })\n setWasOpen(true)\n }, [editor])\n\n const restoreSelection = useCallback(() => {\n if (selectionState) {\n editor.update(\n () => {\n $setSelection(selectionState.clone())\n },\n { discrete: true, skipTransforms: true },\n )\n }\n }, [editor, selectionState])\n\n const closeDocumentDrawer = () => {\n //restoreSelection() // Should already be stored by the useEffect below\n closeDrawer()\n }\n\n // We need to handle drawer closing via a useEffect, as toggleDrawer / closeDrawer will not be triggered if the drawer\n // is closed by clicking outside of the drawer. This useEffect will handle everything.\n useEffect(() => {\n if (!wasOpen) {\n return\n }\n\n const thisModalState = modalState[documentDrawerSlug]\n // Exists in modalState (thus has opened at least once before) and is closed\n if (thisModalState && !thisModalState?.isOpen) {\n setWasOpen(false)\n setTimeout(() => {\n restoreSelection()\n }, 1)\n }\n }, [modalState, documentDrawerSlug, restoreSelection, wasOpen])\n\n const openDocumentDrawer = useCallback(() => {\n storeSelection()\n openDrawer()\n }, [storeSelection, openDrawer])\n\n return {\n closeDocumentDrawer,\n DocumentDrawer,\n documentDrawerSlug,\n DocumentDrawerToggler: (props) => <DocumentDrawerToggler {...props} onClick={storeSelection} />,\n openDocumentDrawer,\n }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,iBAAiB,EAAEC,QAAQ,QAAQ;AAC5C,SAASC,qBAAqB,EAAEC,aAAa,EAAEC,aAAa,QAAQ;AACpE,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAEjD;;;;;AAKA,OAAO,MAAMC,wBAAA,GAA2BC,IAAA;EAAA,MAAAC,CAAA,GAAAZ,EAAA;EAStC,OAAAa,MAAA,IAAiBZ,yBAAA;EACjB,OAAAa,cAAA,EAAAC,iBAAA,IAA4CN,QAAA,CAA+B;EAC3E,OAAAO,OAAA,EAAAC,UAAA,IAA8BR,QAAA,CAAkB;EAEhD,OAAAS,cAAA,EAAAC,qBAAA,EAAAC,EAAA,IAIIlB,iBAAA,CAAkBS,IAAA;EADpB;IAAAU,WAAA;IAAAC,UAAA,EAAAC,kBAAA;IAAAC;EAAA,IAAAJ,EAAwE;EAE1E;IAAAK;EAAA,IAAuBtB,QAAA;EAAA,IAAAuB,EAAA;EAAA,IAAAd,CAAA,QAAAC,MAAA;IAEYa,EAAA,GAAAA,CAAA;MACjCb,MAAA,CAAAc,IAAW,CAAC;QACV,MAAAC,SAAA,GAAkBvB,aAAA,CAAmB,KAAAD,qBAAA;QACrCW,iBAAA,CAAkBa,SAAA;MAAA,CACpB;MACAX,UAAA,CAAW;IAAA,CACb;IAAAL,CAAA,MAAAC,MAAA;IAAAD,CAAA,M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reviousSelection","$getSelection","$setSelection","useCallback","useEffect","useState","useLexicalDrawer","slug","restoreLate","$","editor","selectionState","setSelectionState","wasOpen","setWasOpen","closeModal","closeBaseModal","modalState","toggleModal","toggleBaseModal","t0","read","selection","storeSelection","t1","update","clone","discrete","skipTransforms","restoreSelection","t2","closeDrawer","isModalOpen","isOpen","t3","toggleDrawer","t4","t5","thisModalState","setTimeout","t6"],"sources":["../../../src/utilities/fieldsDrawer/useLexicalDrawer.tsx"],"sourcesContent":["'use client'\nimport type { BaseSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useModal } from '@payloadcms/ui'\nimport { $getPreviousSelection, $getSelection, $setSelection } from 'lexical'\nimport { useCallback, useEffect, useState } from 'react'\n\n/**\n *\n * Wrapper around useModal that restores and saves selection state (cursor position) when opening and closing the drawer.\n * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.\n */\nexport const useLexicalDrawer = (slug: string, restoreLate?: boolean) => {\n const [editor] = useLexicalComposerContext()\n const [selectionState, setSelectionState] = useState<BaseSelection | null>(null)\n const [wasOpen, setWasOpen] = useState<boolean>(false)\n\n const { closeModal: closeBaseModal, modalState, toggleModal: toggleBaseModal } = useModal()\n\n const storeSelection = useCallback(() => {\n editor.read(() => {\n const selection = $getSelection() ?? $getPreviousSelection()\n setSelectionState(selection)\n })\n }, [editor])\n\n const restoreSelection = useCallback(() => {\n if (selectionState) {\n editor.update(\n () => {\n $setSelection(selectionState.clone())\n },\n { discrete: true, skipTransforms: true },\n )\n }\n }, [editor, selectionState])\n\n const closeDrawer = useCallback(() => {\n //restoreSelection() // Should already be stored by the useEffect below\n closeBaseModal(slug)\n }, [closeBaseModal, slug])\n const isModalOpen = modalState?.[slug]?.isOpen\n\n const toggleDrawer = useCallback(() => {\n if (!isModalOpen) {\n storeSelection()\n } else {\n restoreSelection()\n }\n setWasOpen(true)\n toggleBaseModal(slug)\n }, [slug, storeSelection, toggleBaseModal, restoreSelection, isModalOpen])\n\n // We need to handle drawer closing via a useEffect, as toggleDrawer / closeDrawer will not be triggered if the drawer\n // is closed by clicking outside of the drawer. This useEffect will handle everything.\n useEffect(() => {\n if (!wasOpen) {\n return\n }\n\n const thisModalState = modalState[slug]\n // Exists in modalState (thus has opened at least once before) and is closed\n if (thisModalState && !thisModalState?.isOpen) {\n setWasOpen(false)\n\n if (restoreLate) {\n // restoreLate is used for upload extra field drawers. For some reason, the selection is not restored if we call restoreSelection immediately.\n setTimeout(() => {\n restoreSelection()\n }, 0)\n } else {\n restoreSelection()\n }\n }\n }, [modalState, slug, restoreSelection, wasOpen, restoreLate])\n\n return {\n closeDrawer,\n toggleDrawer,\n }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,QAAQ,QAAQ;AACzB,SAASC,qBAAqB,EAAEC,aAAa,EAAEC,aAAa,QAAQ;AACpE,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAEjD;;;;;AAKA,OAAO,MAAMC,gBAAA,GAAmBA,CAAAC,IAAA,EAAAC,WAAA;EAAA,MAAAC,CAAA,GAAAZ,EAAA;EAC9B,OAAAa,MAAA,IAAiBZ,yBAAA;EACjB,OAAAa,cAAA,EAAAC,iBAAA,IAA4CP,QAAA,KAA+B;EAC3E,OAAAQ,OAAA,EAAAC,UAAA,IAA8BT,QAAA,MAAkB;EAEhD;IAAAU,UAAA,EAAAC,cAAA;IAAAC,UAAA;IAAAC,WAAA,EAAAC;EAAA,IAAiFpB,QAAA;EAAA,IAAAqB,EAAA;EAAA,IAAAX,CAAA,QAAAC,MAAA;IAE9CU,EAAA,GAAAA,CAAA;MACjCV,MAAA,CAAAW,IAAA;QACE,MAAAC,SAAA,GAAkBrB,aAAA,MAAmBD,qBAAA;QACrCY,iBAAA,CAAkBU,SAAA;MAAA,CACpB;IAAA;IACFb,CAAA,MAAAC,MAAA;IAAAD,CAAA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AAAA,EAAA,GAAA/B,CAAA;EAAA;EAAA,OAHO+B,EAGP;AAAA,CACF","ignoreList":[]}
1
+ {"version":3,"file":"useLexicalDrawer.js","names":["c","_c","useLexicalComposerContext","useModal","$getPreviousSelection","$getSelection","$setSelection","useCallback","useEffect","useState","useLexicalDrawer","slug","restoreLate","$","editor","selectionState","setSelectionState","wasOpen","setWasOpen","closeModal","closeBaseModal","modalState","toggleModal","toggleBaseModal","t0","read","selection","storeSelection","t1","update","clone","discrete","skipTransforms","restoreSelection","t2","closeDrawer","isModalOpen","isOpen","t3","toggleDrawer","t4","t5","thisModalState","setTimeout","t6"],"sources":["../../../src/utilities/fieldsDrawer/useLexicalDrawer.tsx"],"sourcesContent":["'use client'\nimport type { BaseSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useModal } from '@payloadcms/ui'\nimport { $getPreviousSelection, $getSelection, $setSelection } from 'lexical'\nimport { useCallback, useEffect, useState } from 'react'\n\n/**\n *\n * Wrapper around useModal that restores and saves selection state (cursor position) when opening and closing the drawer.\n * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.\n */\nexport const useLexicalDrawer = (slug: string, restoreLate?: boolean) => {\n const [editor] = useLexicalComposerContext()\n const [selectionState, setSelectionState] = useState<BaseSelection | null>(null)\n const [wasOpen, setWasOpen] = useState<boolean>(false)\n\n const { closeModal: closeBaseModal, modalState, toggleModal: toggleBaseModal } = useModal()\n\n const storeSelection = useCallback(() => {\n editor.read(() => {\n const selection = $getSelection() ?? $getPreviousSelection()\n setSelectionState(selection)\n })\n }, [editor])\n\n const restoreSelection = useCallback(() => {\n if (selectionState) {\n editor.update(\n () => {\n $setSelection(selectionState.clone())\n },\n { discrete: true, skipTransforms: true },\n )\n }\n }, [editor, selectionState])\n\n const closeDrawer = useCallback(() => {\n //restoreSelection() // Should already be stored by the useEffect below\n closeBaseModal(slug)\n }, [closeBaseModal, slug])\n const isModalOpen = modalState?.[slug]?.isOpen\n\n const toggleDrawer = useCallback(() => {\n if (!isModalOpen) {\n storeSelection()\n } else {\n restoreSelection()\n }\n setWasOpen(true)\n toggleBaseModal(slug)\n }, [slug, storeSelection, toggleBaseModal, restoreSelection, isModalOpen])\n\n // We need to handle drawer closing via a useEffect, as toggleDrawer / closeDrawer will not be triggered if the drawer\n // is closed by clicking outside of the drawer. This useEffect will handle everything.\n useEffect(() => {\n if (!wasOpen) {\n return\n }\n\n const thisModalState = modalState[slug]\n // Exists in modalState (thus has opened at least once before) and is closed\n if (thisModalState && !thisModalState?.isOpen) {\n setWasOpen(false)\n\n if (restoreLate) {\n // restoreLate is used for upload extra field drawers. For some reason, the selection is not restored if we call restoreSelection immediately.\n setTimeout(() => {\n restoreSelection()\n }, 0)\n } else {\n restoreSelection()\n }\n }\n }, [modalState, slug, restoreSelection, wasOpen, restoreLate])\n\n return {\n closeDrawer,\n toggleDrawer,\n }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAGA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,QAAQ,QAAQ;AACzB,SAASC,qBAAqB,EAAEC,aAAa,EAAEC,aAAa,QAAQ;AACpE,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAEjD;;;;;AAKA,OAAO,MAAMC,gBAAA,GAAmBA,CAAAC,IAAA,EAAAC,WAAA;EAAA,MAAAC,CAAA,GAAAZ,EAAA;EAC9B,OAAAa,MAAA,IAAiBZ,yBAAA;EACjB,OAAAa,cAAA,EAAAC,iBAAA,IAA4CP,QAAA,CAA+B;EAC3E,OAAAQ,OAAA,EAAAC,UAAA,IAA8BT,QAAA,CAAkB;EAEhD;IAAAU,UAAA,EAAAC,cAAA;IAAAC,UAAA;IAAAC,WAAA,EAAAC;EAAA,IAAiFpB,QAAA;EAAA,IAAAqB,EAAA;EAAA,IAAAX,CAAA,QAAAC,MAAA;IAE9CU,EAAA,GAAAA,CAAA;MACjCV,MAAA,CAAAW,I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mBV,EAAGC,EAA0D;EAAA,IAAAG,EAAA;EAAA,IAAA/B,CAAA,SAAAsB,WAAA,IAAAtB,CAAA,SAAA0B,YAAA;IAEtDK,EAAA;MAAAT,WAAA;MAAAI;IAGP;IAAA1B,CAAA,OAAAsB,WAAA;IAAAtB,CAAA,OAAA0B,YAAA;IAAA1B,CAAA,OAAA+B,EAAA;EAAA;IAAAA,EAAA,GAAA/B,CAAA;EAAA;EAAA,OAHO+B,EAGP;AAAA,CACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useLexicalListDrawer.js","names":["c","_c","useLexicalComposerContext","useListDrawer","useModal","$getNodeByKey","$getPreviousSelection","$getRoot","$getSelection","$isRangeSelection","$setSelection","useCallback","useEffect","useState","useLexicalListDrawer","args","$","editor","selectionState","setSelectionState","wasOpen","setWasOpen","BaseListDrawer","BaseListDrawerToggler","t0","closeDrawer","baseCloseDrawer","drawerSlug","listDrawerSlug","isDrawerOpen","openDrawer","baseOpenDrawer","modalState","t1","Symbol","for","selection","$storeSelection","t2","update","anchor","focus","key","clone","selectEnd","discrete","skipTransforms","restoreSelection","t3","closeListDrawer","t4","t5","thisModalState","isOpen","setTimeout","t6","props","_jsx","onClick","t7","t8","isListDrawerOpen","ListDrawer","ListDrawerToggler"],"sources":["../../../src/utilities/fieldsDrawer/useLexicalListDrawer.tsx"],"sourcesContent":["'use client'\nimport type { UseListDrawer } from '@payloadcms/ui'\nimport type { BaseSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useListDrawer, useModal } from '@payloadcms/ui'\nimport {\n $getNodeByKey,\n $getPreviousSelection,\n $getRoot,\n $getSelection,\n $isRangeSelection,\n $setSelection,\n} from 'lexical'\nimport { useCallback, useEffect, useState } from 'react'\n\n/**\n *\n * Wrapper around useListDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.\n * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.\n */\nexport const useLexicalListDrawer = (\n args: Parameters<UseListDrawer>[0],\n): {\n closeListDrawer: () => void\n isListDrawerOpen: boolean\n ListDrawer: ReturnType<UseListDrawer>[0]\n listDrawerSlug: string\n ListDrawerToggler: ReturnType<UseListDrawer>[1]\n openListDrawer: (selection?: BaseSelection) => void\n} => {\n const [editor] = useLexicalComposerContext()\n const [selectionState, setSelectionState] = useState<BaseSelection | null>(null)\n const [wasOpen, setWasOpen] = useState<boolean>(false)\n\n const [\n BaseListDrawer,\n BaseListDrawerToggler,\n {\n closeDrawer: baseCloseDrawer,\n drawerSlug: listDrawerSlug,\n isDrawerOpen,\n openDrawer: baseOpenDrawer,\n },\n ] = useListDrawer(args)\n const { modalState } = useModal()\n\n const $storeSelection = useCallback(() => {\n // editor.read() causes an error here when creating a new upload node from the slash menu. It seems like we can omit it here though, as all\n // invocations of that functions are wrapped in editor.read() or editor.update() somewhere in the call stack.\n const selection = $getSelection() ?? $getPreviousSelection()\n setSelectionState(selection)\n }, [])\n\n const restoreSelection = useCallback(() => {\n if (selectionState) {\n editor.update(\n () => {\n if ($isRangeSelection(selectionState)) {\n const { anchor, focus } = selectionState\n if ($getNodeByKey(anchor.key) && $getNodeByKey(focus.key)) {\n $setSelection(selectionState.clone())\n }\n } else {\n // not ideal, but better than losing the selection. Try to set the selection\n // in a valid place if you remove selected nodes!\n $getRoot().selectEnd()\n }\n },\n { discrete: true, skipTransforms: true },\n )\n }\n }, [editor, selectionState])\n\n const closeListDrawer = () => {\n //restoreSelection() // Should already be stored by the useEffect below\n baseCloseDrawer()\n }\n\n // We need to handle drawer closing via a useEffect, as toggleDrawer / closeDrawer will not be triggered if the drawer\n // is closed by clicking outside of the drawer. This useEffect will handle everything.\n useEffect(() => {\n if (!wasOpen) {\n return\n }\n\n const thisModalState = modalState[listDrawerSlug]\n // Exists in modalState (thus has opened at least once before) and is closed\n if (thisModalState && !thisModalState?.isOpen) {\n setWasOpen(false)\n setTimeout(() => {\n restoreSelection()\n }, 1)\n }\n }, [modalState, listDrawerSlug, restoreSelection, wasOpen])\n\n return {\n closeListDrawer,\n isListDrawerOpen: isDrawerOpen,\n ListDrawer: BaseListDrawer,\n listDrawerSlug,\n ListDrawerToggler: (props) => (\n <BaseListDrawerToggler\n {...props}\n onClick={() => {\n $storeSelection()\n }}\n />\n ),\n openListDrawer: () => {\n $storeSelection()\n baseOpenDrawer()\n setWasOpen(true)\n },\n }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,aAAa,EAAEC,QAAQ,QAAQ;AACxC,SACEC,aAAa,EACbC,qBAAqB,EACrBC,QAAQ,EACRC,aAAa,EACbC,iBAAiB,EACjBC,aAAa,QACR;AACP,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAEjD;;;;;AAKA,OAAO,MAAMC,oBAAA,GAAuBC,IAAA;EAAA,MAAAC,CAAA,GAAAf,EAAA;EAUlC,OAAAgB,MAAA,IAAiBf,yBAAA;EACjB,OAAAgB,cAAA,EAAAC,iBAAA,IAA4CN,QAAA,KAA+B;EAC3E,OAAAO,OAAA,EAAAC,UAAA,IAA8BR,QAAA,MAAkB;EAEhD,OAAAS,cAAA,EAAAC,qBAAA,EAAAC,EAAA,IASIrB,aAAA,CAAcY,IAAA;EANhB;IAAAU,WAAA,EAAAC,eAAA;IAAAC,UAAA,EAAAC,cAAA;IAAAC,YAAA;IAAAC,UAAA,EAAAC;EAAA,IAAAP,EAKC;EAEH;IAAAQ;EAAA,IAAuB5B,QAAA;EAAA,IAAA6B,EAAA;EAAA,IAAAjB,CAAA,QAAAkB,MAAA,CAAAC,GAAA;IAEaF,EAAA,GAAAA,CAAA;MAGlC,MAAAG,SAAA,GAAkB5B,aAAA,MAAmBF,qBAAA;MACrCa,iBAAA,CAAkBiB,SAAA;IAAA;IACpBpB,CAAA,MAAAiB,EAAA;EAAA;IAAAA,EAAA,GAAAjB,CAAA;EAAA;EALA,MAAAqB,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,CAAA,OAAAuC,EAAA;IAAAvC,CAAA,OAAA2C,EAAA;IAAA3C,CAAA,OAAA4C,EAAA;EAAA;IAAAA,EAAA,GAAA5C,CAAA;EAAA;EAAA,OAlBO4C,EAkBP;AAAA,CACF","ignoreList":[]}
1
+ {"version":3,"file":"useLexicalListDrawer.js","names":["c","_c","useLexicalComposerContext","useListDrawer","useModal","$getNodeByKey","$getPreviousSelection","$getRoot","$getSelection","$isRangeSelection","$setSelection","useCallback","useEffect","useState","useLexicalListDrawer","args","$","editor","selectionState","setSelectionState","wasOpen","setWasOpen","BaseListDrawer","BaseListDrawerToggler","t0","closeDrawer","baseCloseDrawer","drawerSlug","listDrawerSlug","isDrawerOpen","openDrawer","baseOpenDrawer","modalState","t1","Symbol","for","selection","$storeSelection","t2","update","anchor","focus","key","clone","selectEnd","discrete","skipTransforms","restoreSelection","t3","closeListDrawer","t4","t5","thisModalState","isOpen","setTimeout","t6","props","_jsx","onClick","t7","t8","isListDrawerOpen","ListDrawer","ListDrawerToggler"],"sources":["../../../src/utilities/fieldsDrawer/useLexicalListDrawer.tsx"],"sourcesContent":["'use client'\nimport type { UseListDrawer } from '@payloadcms/ui'\nimport type { BaseSelection } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useListDrawer, useModal } from '@payloadcms/ui'\nimport {\n $getNodeByKey,\n $getPreviousSelection,\n $getRoot,\n $getSelection,\n $isRangeSelection,\n $setSelection,\n} from 'lexical'\nimport { useCallback, useEffect, useState } from 'react'\n\n/**\n *\n * Wrapper around useListDrawer that restores and saves selection state (cursor position) when opening and closing the drawer.\n * By default, the lexical cursor position may be lost when opening a drawer and clicking somewhere on that drawer.\n */\nexport const useLexicalListDrawer = (\n args: Parameters<UseListDrawer>[0],\n): {\n closeListDrawer: () => void\n isListDrawerOpen: boolean\n ListDrawer: ReturnType<UseListDrawer>[0]\n listDrawerSlug: string\n ListDrawerToggler: ReturnType<UseListDrawer>[1]\n openListDrawer: (selection?: BaseSelection) => void\n} => {\n const [editor] = useLexicalComposerContext()\n const [selectionState, setSelectionState] = useState<BaseSelection | null>(null)\n const [wasOpen, setWasOpen] = useState<boolean>(false)\n\n const [\n BaseListDrawer,\n BaseListDrawerToggler,\n {\n closeDrawer: baseCloseDrawer,\n drawerSlug: listDrawerSlug,\n isDrawerOpen,\n openDrawer: baseOpenDrawer,\n },\n ] = useListDrawer(args)\n const { modalState } = useModal()\n\n const $storeSelection = useCallback(() => {\n // editor.read() causes an error here when creating a new upload node from the slash menu. It seems like we can omit it here though, as all\n // invocations of that functions are wrapped in editor.read() or editor.update() somewhere in the call stack.\n const selection = $getSelection() ?? $getPreviousSelection()\n setSelectionState(selection)\n }, [])\n\n const restoreSelection = useCallback(() => {\n if (selectionState) {\n editor.update(\n () => {\n if ($isRangeSelection(selectionState)) {\n const { anchor, focus } = selectionState\n if ($getNodeByKey(anchor.key) && $getNodeByKey(focus.key)) {\n $setSelection(selectionState.clone())\n }\n } else {\n // not ideal, but better than losing the selection. Try to set the selection\n // in a valid place if you remove selected nodes!\n $getRoot().selectEnd()\n }\n },\n { discrete: true, skipTransforms: true },\n )\n }\n }, [editor, selectionState])\n\n const closeListDrawer = () => {\n //restoreSelection() // Should already be stored by the useEffect below\n baseCloseDrawer()\n }\n\n // We need to handle drawer closing via a useEffect, as toggleDrawer / closeDrawer will not be triggered if the drawer\n // is closed by clicking outside of the drawer. This useEffect will handle everything.\n useEffect(() => {\n if (!wasOpen) {\n return\n }\n\n const thisModalState = modalState[listDrawerSlug]\n // Exists in modalState (thus has opened at least once before) and is closed\n if (thisModalState && !thisModalState?.isOpen) {\n setWasOpen(false)\n setTimeout(() => {\n restoreSelection()\n }, 1)\n }\n }, [modalState, listDrawerSlug, restoreSelection, wasOpen])\n\n return {\n closeListDrawer,\n isListDrawerOpen: isDrawerOpen,\n ListDrawer: BaseListDrawer,\n listDrawerSlug,\n ListDrawerToggler: (props) => (\n <BaseListDrawerToggler\n {...props}\n onClick={() => {\n $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,EAAA,GAAA5C,CAAA;EAAA;EAAA,OAlBO4C,EAkBP;AAAA,CACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"initLexicalFeatures.d.ts","sourceRoot":"","sources":["../../src/utilities/initLexicalFeatures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAC1F,KAAK,IAAI,GAAG;IACV,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,cAAc,EAAE,cAAc,CAAA;IAC9B,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,qBAAqB,EAAE,2BAA2B,CAAA;IAClD,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG;IAC/C,cAAc,EAAE,yBAAyB,CAAC,gBAAgB,CAAC,CAAA;IAC3D,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3C,sBAAsB,EAAE,sBAAsB,CAAA;CAC/C,CA0FA"}
1
+ {"version":3,"file":"initLexicalFeatures.d.ts","sourceRoot":"","sources":["../../src/utilities/initLexicalFeatures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAC1F,KAAK,IAAI,GAAG;IACV,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,cAAc,EAAE,cAAc,CAAA;IAC9B,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,qBAAqB,EAAE,2BAA2B,CAAA;IAClD,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG;IAC/C,cAAc,EAAE,yBAAyB,CAAC,gBAAgB,CAAC,CAAA;IAC3D,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3C,sBAAsB,EAAE,sBAAsB,CAAA;CAC/C,CA6FA"}
@@ -45,10 +45,11 @@ export function initLexicalFeatures(args) {
45
45
  const featureSchemaPath = `${args.schemaPath}.lexical_internal_feature.${featureKey}`;
46
46
  featureClientSchemaMap[featureKey] = {};
47
47
  // Like args.fieldSchemaMap, we only want to include the sub-fields of the current feature
48
- for (const [key, entry] of args.clientFieldSchemaMap.entries()) {
49
- if (key.startsWith(featureSchemaPath)) {
50
- featureClientSchemaMap[featureKey][key] = 'fields' in entry ? entry.fields : [entry];
51
- }
48
+ const featureEntries = getFeatureEntriesByPath({
49
+ clientFieldSchemaMap: args.clientFieldSchemaMap
50
+ }).get(featureSchemaPath) ?? new Map();
51
+ for (const [key, entry] of featureEntries) {
52
+ featureClientSchemaMap[featureKey][key] = 'fields' in entry ? entry.fields : [entry];
52
53
  }
53
54
  }
54
55
  if (resolvedFeature.componentImports && typeof resolvedFeature.componentImports === 'object' && !Array.isArray(resolvedFeature.componentImports)) {
@@ -69,4 +70,37 @@ export function initLexicalFeatures(args) {
69
70
  featureClientSchemaMap
70
71
  };
71
72
  }
73
+ const FEATURE_PATH_SEGMENT = '.lexical_internal_feature.';
74
+ const featureEntriesCache = new WeakMap();
75
+ /**
76
+ * Groups the client field schema map entries by the lexical feature they belong to,
77
+ * so each rich text field does not have to scan the whole client field schema map.
78
+ */
79
+ function getFeatureEntriesByPath({
80
+ clientFieldSchemaMap
81
+ }) {
82
+ const cachedEntriesByPath = featureEntriesCache.get(clientFieldSchemaMap);
83
+ if (cachedEntriesByPath) {
84
+ return cachedEntriesByPath;
85
+ }
86
+ const entriesByPath = new Map();
87
+ for (const [key, entry] of clientFieldSchemaMap) {
88
+ let segmentIndex = key.indexOf(FEATURE_PATH_SEGMENT);
89
+ // An entry of a rich text field nested in a feature also belongs to each outer feature
90
+ while (segmentIndex !== -1) {
91
+ const featureKeyStart = segmentIndex + FEATURE_PATH_SEGMENT.length;
92
+ const featureKeyEnd = key.indexOf('.', featureKeyStart);
93
+ const featurePath = featureKeyEnd === -1 ? key : key.slice(0, featureKeyEnd);
94
+ let featureEntries = entriesByPath.get(featurePath);
95
+ if (!featureEntries) {
96
+ featureEntries = new Map();
97
+ entriesByPath.set(featurePath, featureEntries);
98
+ }
99
+ featureEntries.set(key, entry);
100
+ segmentIndex = key.indexOf(FEATURE_PATH_SEGMENT, featureKeyStart);
101
+ }
102
+ }
103
+ featureEntriesCache.set(clientFieldSchemaMap, entriesByPath);
104
+ return entriesByPath;
105
+ }
72
106
  //# sourceMappingURL=initLexicalFeatures.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"initLexicalFeatures.js","names":["getFromImportMap","initLexicalFeatures","args","clientFeatures","resolvedFeatureMapArray","sanitizedEditorConfig","resolvedFeatureMap","sort","a","b","order","featureClientSchemaMap","featureClientImportMap","featureKey","resolvedFeature","ClientFeaturePayloadComponent","ClientFeature","clientFeatureProvider","importMap","payload","PayloadComponent","schemaPath","silent","clientFeatureProps","key","clientProps","generateSchemaMap","featureSchemaPath","entry","clientFieldSchemaMap","entries","startsWith","fields","componentImports","Array","isArray","payloadComponent","Object","resolvedComponent"],"sources":["../../src/utilities/initLexicalFeatures.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\n\nimport { type ClientFieldSchemaMap, type FieldSchemaMap, type Payload } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\n\nimport type {\n BaseClientFeatureProps,\n FeatureProviderProviderClient,\n} from '../features/typesClient.js'\nimport type { SanitizedServerEditorConfig } from '../lexical/config/types.js'\nimport type { FeatureClientSchemaMap, LexicalRichTextFieldProps } from '../types/index.js'\ntype Args = {\n clientFieldSchemaMap: ClientFieldSchemaMap\n fieldSchemaMap: FieldSchemaMap\n i18n: I18nClient\n path: string\n payload: Payload\n sanitizedEditorConfig: SanitizedServerEditorConfig\n schemaPath: string\n}\n\nexport function initLexicalFeatures(args: Args): {\n clientFeatures: LexicalRichTextFieldProps['clientFeatures']\n featureClientImportMap: Record<string, any>\n featureClientSchemaMap: FeatureClientSchemaMap\n} {\n const clientFeatures: LexicalRichTextFieldProps['clientFeatures'] = {}\n\n // turn args.resolvedFeatureMap into an array of [key, value] pairs, ordered by value.order, lowest order first:\n const resolvedFeatureMapArray = [...args.sanitizedEditorConfig.resolvedFeatureMap].sort(\n (a, b) => a[1].order - b[1].order,\n )\n\n const featureClientSchemaMap: FeatureClientSchemaMap = {}\n\n /**\n * All modules added to the import map, keyed by the provided key, if feature.componentImports with type object is used\n */\n const featureClientImportMap: Record<string, any> | undefined = {}\n\n for (const [featureKey, resolvedFeature] of resolvedFeatureMapArray) {\n clientFeatures[featureKey] = {}\n\n /**\n * Handle client features\n */\n const ClientFeaturePayloadComponent = resolvedFeature.ClientFeature\n\n if (ClientFeaturePayloadComponent) {\n const clientFeatureProvider = getFromImportMap<FeatureProviderProviderClient>({\n importMap: args.payload.importMap,\n PayloadComponent: ClientFeaturePayloadComponent,\n schemaPath: 'lexical-clientComponent',\n silent: true,\n })\n\n if (!clientFeatureProvider) {\n continue\n }\n\n const clientFeatureProps: BaseClientFeatureProps<Record<string, any>> =\n resolvedFeature.clientFeatureProps ?? {}\n clientFeatureProps.featureKey = resolvedFeature.key\n clientFeatureProps.order = resolvedFeature.order\n if (\n typeof ClientFeaturePayloadComponent === 'object' &&\n ClientFeaturePayloadComponent.clientProps\n ) {\n clientFeatureProps.clientProps = ClientFeaturePayloadComponent.clientProps\n }\n // As clientFeatureProvider is a client function, we cannot execute it on the server here. Thus, the client will have to execute clientFeatureProvider with its props\n clientFeatures[featureKey] = { clientFeatureProps, clientFeatureProvider }\n }\n\n /**\n * Handle sub-fields (formstate of those)\n */\n // The args.fieldSchemaMap generated before in buildFormState should contain all of lexical features' sub-field schemas\n // as well, as it already called feature.generateSchemaMap for each feature.\n // We will check for the existance resolvedFeature.generateSchemaMap to skip unnecessary loops for constructing featureSchemaMap, but we don't run it here\n if (resolvedFeature.generateSchemaMap) {\n const featureSchemaPath = `${args.schemaPath}.lexical_internal_feature.${featureKey}`\n\n featureClientSchemaMap[featureKey] = {}\n\n // Like args.fieldSchemaMap, we only want to include the sub-fields of the current feature\n for (const [key, entry] of args.clientFieldSchemaMap.entries()) {\n if (key.startsWith(featureSchemaPath)) {\n featureClientSchemaMap[featureKey][key] = 'fields' in entry ? entry.fields : [entry]\n }\n }\n }\n\n if (\n resolvedFeature.componentImports &&\n typeof resolvedFeature.componentImports === 'object' &&\n !Array.isArray(resolvedFeature.componentImports)\n ) {\n for (const [key, payloadComponent] of Object.entries(resolvedFeature.componentImports)) {\n const resolvedComponent = getFromImportMap({\n importMap: args.payload.importMap,\n PayloadComponent: payloadComponent,\n schemaPath: 'lexical-clientComponent',\n silent: true,\n })\n\n featureClientImportMap[`${resolvedFeature.key}.${key}`] = resolvedComponent\n }\n }\n }\n return {\n clientFeatures,\n featureClientImportMap,\n featureClientSchemaMap,\n }\n}\n"],"mappings":"AAGA,SAASA,gBAAgB,QAAQ;AAkBjC,OAAO,SAASC,oBAAoBC,IAAU;EAK5C,MAAMC,cAAA,GAA8D,CAAC;EAErE;EACA,MAAMC,uBAAA,GAA0B,C,GAAIF,IAAA,CAAKG,qBA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AAK,MAAM,CAACW,GAAA,EAAKI,KAAA,CAAM,IAAI1B,IAAA,CAAK2B,oBAAoB,CAACC,OAAO,IAAI;QAC9D,IAAIN,GAAA,CAAIO,UAAU,CAACJ,iBAAA,GAAoB;UACrChB,sBAAsB,CAACE,UAAA,CAAW,CAACW,GAAA,CAAI,GAAG,YAAYI,KAAA,GAAQA,KAAA,CAAMI,MAAM,GAAG,CAACJ,KAAA,CAAM;QACtF;MACF;IACF;IAEA,IACEd,eAAA,CAAgBmB,gBAAgB,IAChC,OAAOnB,eAAA,CAAgBmB,gBAAgB,KAAK,YAC5C,CAACC,KAAA,CAAMC,OAAO,CAACrB,eAAA,CAAgBmB,gBAAgB,GAC/C;MACA,KAAK,MAAM,CAACT,GAAA,EAAKY,gBAAA,CAAiB,IAAIC,MAAA,CAAOP,OAAO,CAAChB,eAAA,CAAgBmB,gBAAgB,GAAG;QACtF,MAAMK,iBAAA,GAAoBtC,gBAAA,CAAiB;UACzCkB,SAAA,EAAWhB,IAAA,CAAKiB,OAAO,CAACD,SAAS;UACjCE,gBAAA,EAAkBgB,gBAAA;UAClBf,UAAA,EAAY;UACZC,MAAA,EAAQ;QACV;QAEAV,sBAAsB,CAAC,GAAGE,eAAA,CAAgBU,GAAG,IAAIA,GAAA,EAAK,CAAC,GAAGc,iBAAA;MAC5D;IACF;EACF;EACA,OAAO;IACLnC,cAAA;IACAS,sBAAA;IACAD;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"initLexicalFeatures.js","names":["getFromImportMap","initLexicalFeatures","args","clientFeatures","resolvedFeatureMapArray","sanitizedEditorConfig","resolvedFeatureMap","sort","a","b","order","featureClientSchemaMap","featureClientImportMap","featureKey","resolvedFeature","ClientFeaturePayloadComponent","ClientFeature","clientFeatureProvider","importMap","payload","PayloadComponent","schemaPath","silent","clientFeatureProps","key","clientProps","generateSchemaMap","featureSchemaPath","featureEntries","getFeatureEntriesByPath","clientFieldSchemaMap","get","Map","entry","fields","componentImports","Array","isArray","payloadComponent","Object","entries","resolvedComponent","FEATURE_PATH_SEGMENT","featureEntriesCache","WeakMap","cachedEntriesByPath","entriesByPath","segmentIndex","indexOf","featureKeyStart","length","featureKeyEnd","featurePath","slice","set"],"sources":["../../src/utilities/initLexicalFeatures.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\n\nimport { type ClientFieldSchemaMap, type FieldSchemaMap, type Payload } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\n\nimport type {\n BaseClientFeatureProps,\n FeatureProviderProviderClient,\n} from '../features/typesClient.js'\nimport type { SanitizedServerEditorConfig } from '../lexical/config/types.js'\nimport type { FeatureClientSchemaMap, LexicalRichTextFieldProps } from '../types/index.js'\ntype Args = {\n clientFieldSchemaMap: ClientFieldSchemaMap\n fieldSchemaMap: FieldSchemaMap\n i18n: I18nClient\n path: string\n payload: Payload\n sanitizedEditorConfig: SanitizedServerEditorConfig\n schemaPath: string\n}\n\nexport function initLexicalFeatures(args: Args): {\n clientFeatures: LexicalRichTextFieldProps['clientFeatures']\n featureClientImportMap: Record<string, any>\n featureClientSchemaMap: FeatureClientSchemaMap\n} {\n const clientFeatures: LexicalRichTextFieldProps['clientFeatures'] = {}\n\n // turn args.resolvedFeatureMap into an array of [key, value] pairs, ordered by value.order, lowest order first:\n const resolvedFeatureMapArray = [...args.sanitizedEditorConfig.resolvedFeatureMap].sort(\n (a, b) => a[1].order - b[1].order,\n )\n\n const featureClientSchemaMap: FeatureClientSchemaMap = {}\n\n /**\n * All modules added to the import map, keyed by the provided key, if feature.componentImports with type object is used\n */\n const featureClientImportMap: Record<string, any> | undefined = {}\n\n for (const [featureKey, resolvedFeature] of resolvedFeatureMapArray) {\n clientFeatures[featureKey] = {}\n\n /**\n * Handle client features\n */\n const ClientFeaturePayloadComponent = resolvedFeature.ClientFeature\n\n if (ClientFeaturePayloadComponent) {\n const clientFeatureProvider = getFromImportMap<FeatureProviderProviderClient>({\n importMap: args.payload.importMap,\n PayloadComponent: ClientFeaturePayloadComponent,\n schemaPath: 'lexical-clientComponent',\n silent: true,\n })\n\n if (!clientFeatureProvider) {\n continue\n }\n\n const clientFeatureProps: BaseClientFeatureProps<Record<string, any>> =\n resolvedFeature.clientFeatureProps ?? {}\n clientFeatureProps.featureKey = resolvedFeature.key\n clientFeatureProps.order = resolvedFeature.order\n if (\n typeof ClientFeaturePayloadComponent === 'object' &&\n ClientFeaturePayloadComponent.clientProps\n ) {\n clientFeatureProps.clientProps = ClientFeaturePayloadComponent.clientProps\n }\n // As clientFeatureProvider is a client function, we cannot execute it on the server here. Thus, the client will have to execute clientFeatureProvider with its props\n clientFeatures[featureKey] = { clientFeatureProps, clientFeatureProvider }\n }\n\n /**\n * Handle sub-fields (formstate of those)\n */\n // The args.fieldSchemaMap generated before in buildFormState should contain all of lexical features' sub-field schemas\n // as well, as it already called feature.generateSchemaMap for each feature.\n // We will check for the existance resolvedFeature.generateSchemaMap to skip unnecessary loops for constructing featureSchemaMap, but we don't run it here\n if (resolvedFeature.generateSchemaMap) {\n const featureSchemaPath = `${args.schemaPath}.lexical_internal_feature.${featureKey}`\n\n featureClientSchemaMap[featureKey] = {}\n\n // Like args.fieldSchemaMap, we only want to include the sub-fields of the current feature\n const featureEntries: ClientFieldSchemaMap =\n getFeatureEntriesByPath({ clientFieldSchemaMap: args.clientFieldSchemaMap }).get(\n featureSchemaPath,\n ) ?? new Map()\n\n for (const [key, entry] of featureEntries) {\n featureClientSchemaMap[featureKey][key] = 'fields' in entry ? entry.fields : [entry]\n }\n }\n\n if (\n resolvedFeature.componentImports &&\n typeof resolvedFeature.componentImports === 'object' &&\n !Array.isArray(resolvedFeature.componentImports)\n ) {\n for (const [key, payloadComponent] of Object.entries(resolvedFeature.componentImports)) {\n const resolvedComponent = getFromImportMap({\n importMap: args.payload.importMap,\n PayloadComponent: payloadComponent,\n schemaPath: 'lexical-clientComponent',\n silent: true,\n })\n\n featureClientImportMap[`${resolvedFeature.key}.${key}`] = resolvedComponent\n }\n }\n }\n return {\n clientFeatures,\n featureClientImportMap,\n featureClientSchemaMap,\n }\n}\n\nconst FEATURE_PATH_SEGMENT = '.lexical_internal_feature.'\n\nconst featureEntriesCache = new WeakMap<ClientFieldSchemaMap, Map<string, ClientFieldSchemaMap>>()\n\n/**\n * Groups the client field schema map entries by the lexical feature they belong to,\n * so each rich text field does not have to scan the whole client field schema map.\n */\nfunction getFeatureEntriesByPath({\n clientFieldSchemaMap,\n}: {\n clientFieldSchemaMap: ClientFieldSchemaMap\n}): Map<string, ClientFieldSchemaMap> {\n const cachedEntriesByPath = featureEntriesCache.get(clientFieldSchemaMap)\n\n if (cachedEntriesByPath) {\n return cachedEntriesByPath\n }\n\n const entriesByPath = new Map<string, ClientFieldSchemaMap>()\n\n for (const [key, entry] of clientFieldSchemaMap) {\n let segmentIndex = key.indexOf(FEATURE_PATH_SEGMENT)\n\n // An entry of a rich text field nested in a feature also belongs to each outer feature\n while (segmentIndex !== -1) {\n const featureKeyStart = segmentIndex + FEATURE_PATH_SEGMENT.length\n const featureKeyEnd = key.indexOf('.', featureKeyStart)\n const featurePath = featureKeyEnd === -1 ? key : key.slice(0, featureKeyEnd)\n\n let featureEntries = entriesByPath.get(featurePath)\n\n if (!featureEntries) {\n featureEntries = new Map()\n entriesByPath.set(featurePath, featureEntries)\n }\n\n featureEntries.set(key, entry)\n\n segmentIndex = key.indexOf(FEATURE_PATH_SEGMENT, featureKeyStart)\n }\n }\n\n featureEntriesCache.set(clientFieldSchemaMap, entriesByPath)\n\n return entriesByPath\n}\n"],"mappings":"AAGA,SAASA,gBAAgB,QAAQ;AAkBjC,OAAO,SAASC,oBAAoBC,IAAU;EAK5C,MAAMC,cAAA,GAA8D,CAAC;EAErE;EACA,MAAMC,uBAAA,GAA0B,C,GAAIF,IAAA,CAAKG,qBAAqB,CAACC,kBAAkB,CAAC,CAACC,IAAI,CACrF,CAACC,CAAA,EAAGC,CAAA,KAAMD,CAAC,CAAC,EAAE,CAACE,KAAK,GAAGD,CAAC,CAAC,EAAE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OAAOK,YAAA,KAAiB,CAAC,GAAG;MAC1B,MAAME,eAAA,GAAkBF,YAAA,GAAeL,oBAAA,CAAqBQ,MAAM;MAClE,MAAMC,aAAA,GAAgB3B,GAAA,CAAIwB,OAAO,CAAC,KAAKC,eAAA;MACvC,MAAMG,WAAA,GAAcD,aAAA,KAAkB,CAAC,IAAI3B,GAAA,GAAMA,GAAA,CAAI6B,KAAK,CAAC,GAAGF,aAAA;MAE9D,IAAIvB,cAAA,GAAiBkB,aAAA,CAAcf,GAAG,CAACqB,WAAA;MAEvC,IAAI,CAACxB,cAAA,EAAgB;QACnBA,cAAA,GAAiB,IAAII,GAAA;QACrBc,aAAA,CAAcQ,GAAG,CAACF,WAAA,EAAaxB,cAAA;MACjC;MAEAA,cAAA,CAAe0B,GAAG,CAAC9B,GAAA,EAAKS,KAAA;MAExBc,YAAA,GAAevB,GAAA,CAAIwB,OAAO,CAACN,oBAAA,EAAsBO,eAAA;IACnD;EACF;EAEAN,mBAAA,CAAoBW,GAAG,CAACxB,oBAAA,EAAsBgB,aAAA;EAE9C,OAAOA,aAAA;AACT","ignoreList":[]}
@@ -1,20 +1,29 @@
1
1
  'use client';
2
2
 
3
+ import { c as _c } from "react/compiler-runtime";
3
4
  import { useAddClientFunction } from '@payloadcms/ui';
4
5
  import { useEditorConfigContext } from '../lexical/config/client/EditorConfigProvider.js';
5
6
  export const useLexicalFeature = (featureKey, feature) => {
7
+ const $ = _c(1);
6
8
  const {
7
9
  fieldProps: t0
8
10
  } = useEditorConfigContext();
9
11
  const {
10
12
  schemaPath: schemaPathFromFieldProps
11
13
  } = t0;
12
- const tableCell = {
13
- cellProps: {
14
- schemaPath: []
15
- }
16
- };
17
- const schemaPathFromCellProps = tableCell?.cellProps?.schemaPath ? tableCell?.cellProps?.schemaPath.join(".") : null;
14
+ let t1;
15
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
16
+ const tableCell = {
17
+ cellProps: {
18
+ schemaPath: []
19
+ }
20
+ };
21
+ t1 = tableCell?.cellProps?.schemaPath ? tableCell?.cellProps?.schemaPath.join(".") : null;
22
+ $[0] = t1;
23
+ } else {
24
+ t1 = $[0];
25
+ }
26
+ const schemaPathFromCellProps = t1;
18
27
  const schemaPath = schemaPathFromCellProps || schemaPathFromFieldProps;
19
28
  useAddClientFunction(`lexicalFeature.${schemaPath}.${featureKey}`, feature);
20
29
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useLexicalFeature.js","names":["useAddClientFunction","useEditorConfigContext","useLexicalFeature","featureKey","feature","fieldProps","t0","schemaPath","schemaPathFromFieldProps","tableCell","cellProps","schemaPathFromCellProps","join"],"sources":["../../src/utilities/useLexicalFeature.tsx"],"sourcesContent":["'use client'\n\nimport { useAddClientFunction } from '@payloadcms/ui'\n\nimport type { FeatureProviderClient } from '../features/typesClient.js'\n\nimport { useEditorConfigContext } from '../lexical/config/client/EditorConfigProvider.js'\n\nexport const useLexicalFeature = <ClientFeatureProps,>(\n featureKey: string,\n feature: FeatureProviderClient<ClientFeatureProps>,\n) => {\n const {\n fieldProps: { schemaPath: schemaPathFromFieldProps },\n } = useEditorConfigContext()\n const tableCell = { cellProps: { schemaPath: [] } } // TODO: get tableCell from props\n // const tableCell = useTableCell()\n\n const schemaPathFromCellProps = tableCell?.cellProps?.schemaPath\n ? tableCell?.cellProps?.schemaPath.join('.')\n : null\n\n const schemaPath = schemaPathFromCellProps || schemaPathFromFieldProps // schemaPathFromCellProps needs to have priority, as there can be cells within fields (e.g. list drawers) and the cell schemaPath needs to be used there - not the parent field schemaPath. There cannot be fields within cells.\n\n useAddClientFunction(`lexicalFeature.${schemaPath}.${featureKey}`, feature)\n}\n"],"mappings":"AAAA;;AAEA,SAASA,oBAAoB,QAAQ;AAIrC,SAASC,sBAAsB,QAAQ;AAEvC,OAAO,MAAMC,iBAAA,GAAoBA,CAAAC,UAAA,EAAAC,OAAA;EAI/B;IAAAC,UAAA,EAAAC;EAAA,IAEIL,sBAAA;EADU;IAAAM,UAAA,EAAAC;EAAA,IAAAF,EAAwC;EAEtD,MAAAG,SAAA;IAAAC,SAAA;MAAAH,UAAA;IAAA;EAAA;EAGA,MAAAI,uBAAA,GAAgCF,SAAA,EAAAC,SAAA,EAAAH,UAAA,GAC5BE,SAAA,EAAAC,SAAA,EAAAH,UAAA,CAAAK,IAAA,CAAsC,WACtC;EAEJ,MAAAL,UAAA,GAAmBI,uBAAA,IAA2BH,wBAAA;EAE9CR,oBAAA,CAAqB,kBAAkBO,UAAA,IAAcJ,UAAA,EAAY,EAAEC,OAAA;AAAA,CACrE","ignoreList":[]}
1
+ {"version":3,"file":"useLexicalFeature.js","names":["c","_c","useAddClientFunction","useEditorConfigContext","useLexicalFeature","featureKey","feature","$","fieldProps","t0","schemaPath","schemaPathFromFieldProps","t1","Symbol","for","tableCell","cellProps","join","schemaPathFromCellProps"],"sources":["../../src/utilities/useLexicalFeature.tsx"],"sourcesContent":["'use client'\n\nimport { useAddClientFunction } from '@payloadcms/ui'\n\nimport type { FeatureProviderClient } from '../features/typesClient.js'\n\nimport { useEditorConfigContext } from '../lexical/config/client/EditorConfigProvider.js'\n\nexport const useLexicalFeature = <ClientFeatureProps,>(\n featureKey: string,\n feature: FeatureProviderClient<ClientFeatureProps>,\n) => {\n const {\n fieldProps: { schemaPath: schemaPathFromFieldProps },\n } = useEditorConfigContext()\n const tableCell = { cellProps: { schemaPath: [] } } // TODO: get tableCell from props\n // const tableCell = useTableCell()\n\n const schemaPathFromCellProps = tableCell?.cellProps?.schemaPath\n ? tableCell?.cellProps?.schemaPath.join('.')\n : null\n\n const schemaPath = schemaPathFromCellProps || schemaPathFromFieldProps // schemaPathFromCellProps needs to have priority, as there can be cells within fields (e.g. list drawers) and the cell schemaPath needs to be used there - not the parent field schemaPath. There cannot be fields within cells.\n\n useAddClientFunction(`lexicalFeature.${schemaPath}.${featureKey}`, feature)\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAEA,SAASC,oBAAoB,QAAQ;AAIrC,SAASC,sBAAsB,QAAQ;AAEvC,OAAO,MAAMC,iBAAA,GAAoBA,CAAAC,UAAA,EAAAC,OAAA;EAAA,MAAAC,CAAA,GAAAN,EAAA;EAI/B;IAAAO,UAAA,EAAAC;EAAA,IAEIN,sBAAA;EADU;IAAAO,UAAA,EAAAC;EAAA,IAAAF,EAAwC;EAAA,IAAAG,EAAA;EAAA,IAAAL,CAAA,QAAAM,MAAA,CAAAC,GAAA;IAEtD,MAAAC,SAAA,GAAkB;MAAAC,SAAA,EAAa;QAAAN,UAAA,EAAc;MAAG;IAAE;IAGlBE,EAAA,GAAAG,SAAA,EAAAC,SAAsB,EAAAN,UAElD,GADAK,SAAA,EAAAC,SAAsB,EAAAN,UAAW,CAAAO,IAAK,IACtC,IAF4B,IAE5B;IAAAV,CAAA,MAAAK,EAAA;EAAA;IAAAA,EAAA,GAAAL,CAAA;EAAA;EAFJ,MAAAW,uBAAA,GAAgCN,EAE5B;EAEJ,MAAAF,UAAA,GAAmBQ,uBAA2B,IAA3BP,wBAA2B;EAE9CT,oBAAA,CAAqB,kBAAkBQ,UAAA,IAAcL,UAAA,EAAY,EAAEC,OAAA;AAAA,CACrE","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"useRunDeprioritized.js","names":["c","_c","useCallback","useRef","useRunDeprioritized","t0","$","timeout","undefined","idleHandleRef","t1","fn","Promise","resolve","exec","window","current","cancelIdleCallback","requestIdleCallback","interactionResponse","then","runDeprioritized","setTimeout","requestAnimationFrame"],"sources":["../../src/utilities/useRunDeprioritized.ts"],"sourcesContent":["'use client'\nimport { useCallback, useRef } from 'react'\n\n/**\n * Simple hook that lets you run any callback once the main thread is idle\n * (via `requestIdleCallback`) or when that API is missing (Safari) - after the\n * next animation frame (`interactionResponse`).\n *\n * This will help you to avoid blocking the main thread with heavy work.\n *\n * The latest invocation wins: if a new run is queued before the previous one\n * executes, the previous task is cancelled.\n *\n * Usage:\n * ```ts\n * const runDeprioritized = useRunDeprioritized();\n *\n * const onEditorChange = (state: EditorState) => {\n * runDeprioritized(() => {\n * // heavy work here …\n * });\n * };\n * ```\n *\n * @param timeout Optional timeout (ms) for `requestIdleCallback`; defaults to 500 ms.\n * @returns A `runDeprioritized(fn)` helper.\n */\n\nexport function useRunDeprioritized(timeout = 500) {\n const idleHandleRef = useRef<number>(undefined)\n\n /**\n * Schedule `fn` and resolve when it has executed.\n */\n const runDeprioritized = useCallback(\n (fn: () => void): Promise<void> => {\n return new Promise<void>((resolve) => {\n const exec = () => {\n fn()\n resolve()\n }\n\n if ('requestIdleCallback' in window) {\n // Cancel any previously queued task so only the latest runs.\n if ('cancelIdleCallback' in window && idleHandleRef.current !== undefined) {\n // Cancel earlier scheduled value updates,\n // so that a CPU-limited event loop isn't flooded with n callbacks for n keystrokes into the rich text field,\n // but that there's only ever the latest one state update\n // dispatch task, to be executed with the next idle time,\n // or the deadline of 500ms.\n cancelIdleCallback(idleHandleRef.current)\n }\n // Schedule the state update to happen the next time the browser has sufficient resources,\n // or the latest after 500ms.\n idleHandleRef.current = requestIdleCallback(exec, { timeout })\n } else {\n // Safari fallback: rAF + setTimeout shim.\n void interactionResponse().then(exec)\n }\n })\n },\n [timeout],\n )\n\n return runDeprioritized\n}\n\nfunction interactionResponse(): Promise<unknown> {\n // Taken from https://github.com/vercel-labs/await-interaction-response/tree/main/packages/await-interaction-response/src\n\n return new Promise((resolve) => {\n setTimeout(resolve, 100) // Fallback for the case where the animation frame never fires.\n requestAnimationFrame(() => {\n setTimeout(resolve, 0)\n })\n })\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AACA,SAASC,WAAW,EAAEC,MAAM,QAAQ;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,SAAAC,oBAAAC,EAAA;EAAA,MAAAC,CAAA,GAAAL,EAAA;EAA6B,MAAAM,OAAA,GAAAF,EAAa,KAAAG,SAAA,SAAbH,EAAa;EAC/C,MAAAI,aAAA,GAAsBN,MAAA,CAAAK,SAAe;EAAA,IAAAE,EAAA;EAAA,IAAAJ,CAAA,QAAAC,OAAA;IAMnCG,EAAA,GAAAC,EAAA,QAAAC,OAAA,CAAAC,OAAA;MAEI,MAAAC,IAAA,GAAAA,CAAA;QACEH,EAAA;QACAE,OAAA;MAAA;MACF,IAEI,yBAAAE,MAAyB;QAAA,IAEvB,wBAAAA,MAAwB,IAAUN,aAAA,CAAAO,OAAA,KAAAR,SAA0B;UAM9DS,kBAAA,CAAmBR,aAAA,CAAAO,OAAqB;QAAA;QAI1CP,aAAA,CAAAO,OAAA,GAAwBE,mBAAA,CAAoBJ,IAAA;UAAAP;QAAA,CAAgB;MAAA;QAGvDY,mBAAA,GAAAC,IAAA,CAA2BN,IAAA;MAAA;IAAA;IAGtCR,CAAA,MAAAC,OAAA;IAAAD,CAAA,MAAAI,EAAA;EAAA;IAAAA,EAAA,GAAAJ,CAAA;EAAA;EA1BF,MAAAe,gBAAA,GAAyBX,EA2Bd;EAAA,OAGJW,gBAAA;AAAA;AAGT,SAASF,oBAAA;EACP;EAEA,OAAO,IAAIP,OAAA,CAASC,OAAA;IAClBS,UAAA,CAAWT,OAAA,EAAS,MAAK;IACzBU,qBAAA,CAAsB;MACpBD,UAAA,CAAWT,OAAA,EAAS;IACtB;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"useRunDeprioritized.js","names":["c","_c","useCallback","useRef","useRunDeprioritized","t0","$","timeout","undefined","idleHandleRef","t1","fn","Promise","resolve","exec","window","current","cancelIdleCallback","requestIdleCallback","interactionResponse","then","runDeprioritized","setTimeout","requestAnimationFrame"],"sources":["../../src/utilities/useRunDeprioritized.ts"],"sourcesContent":["'use client'\nimport { useCallback, useRef } from 'react'\n\n/**\n * Simple hook that lets you run any callback once the main thread is idle\n * (via `requestIdleCallback`) or when that API is missing (Safari) - after the\n * next animation frame (`interactionResponse`).\n *\n * This will help you to avoid blocking the main thread with heavy work.\n *\n * The latest invocation wins: if a new run is queued before the previous one\n * executes, the previous task is cancelled.\n *\n * Usage:\n * ```ts\n * const runDeprioritized = useRunDeprioritized();\n *\n * const onEditorChange = (state: EditorState) => {\n * runDeprioritized(() => {\n * // heavy work here …\n * });\n * };\n * ```\n *\n * @param timeout Optional timeout (ms) for `requestIdleCallback`; defaults to 500 ms.\n * @returns A `runDeprioritized(fn)` helper.\n */\n\nexport function useRunDeprioritized(timeout = 500) {\n const idleHandleRef = useRef<number>(undefined)\n\n /**\n * Schedule `fn` and resolve when it has executed.\n */\n const runDeprioritized = useCallback(\n (fn: () => void): Promise<void> => {\n return new Promise<void>((resolve) => {\n const exec = () => {\n fn()\n resolve()\n }\n\n if ('requestIdleCallback' in window) {\n // Cancel any previously queued task so only the latest runs.\n if ('cancelIdleCallback' in window && idleHandleRef.current !== undefined) {\n // Cancel earlier scheduled value updates,\n // so that a CPU-limited event loop isn't flooded with n callbacks for n keystrokes into the rich text field,\n // but that there's only ever the latest one state update\n // dispatch task, to be executed with the next idle time,\n // or the deadline of 500ms.\n cancelIdleCallback(idleHandleRef.current)\n }\n // Schedule the state update to happen the next time the browser has sufficient resources,\n // or the latest after 500ms.\n idleHandleRef.current = requestIdleCallback(exec, { timeout })\n } else {\n // Safari fallback: rAF + setTimeout shim.\n void interactionResponse().then(exec)\n }\n })\n },\n [timeout],\n )\n\n return runDeprioritized\n}\n\nfunction interactionResponse(): Promise<unknown> {\n // Taken from https://github.com/vercel-labs/await-interaction-response/tree/main/packages/await-interaction-response/src\n\n return new Promise((resolve) => {\n setTimeout(resolve, 100) // Fallback for the case where the animation frame never fires.\n requestAnimationFrame(() => {\n setTimeout(resolve, 0)\n })\n })\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AACA,SAASC,WAAW,EAAEC,MAAM,QAAQ;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,SAAAC,oBAAAC,EAAA;EAAA,MAAAC,CAAA,GAAAL,EAAA;EAA6B,MAAAM,OAAA,GAAAF,EAAa,KAAbG,SAAa,GAAb,GAAa,GAAbH,EAAa;EAC/C,MAAAI,aAAA,GAAsBN,MAAA,CAAeK,SAAA;EAAA,IAAAE,EAAA;EAAA,IAAAJ,CAAA,QAAAC,OAAA;IAMnCG,EAAA,GAAAC,EAAA,IACS,IAAIC,OAAA,CAAcC,OAAA;MACvB,MAAAC,IAAA,GAAaA,CAAA;QACXH,EAAA;QACAE,OAAA;MAAA,CACF;MAEA,IAAI,yBAAyBE,MAAA;QAE3B,IAAI,wBAAwBA,MAAoC,IAA1BN,aAAA,CAAAO,OAAqB,KAAKR,SAAA;UAM9DS,kBAAA,CAAmBR,aAAA,CAAAO,OAAqB;QAAA;QAI1CP,aAAA,CAAAO,OAAA,GAAwBE,mBAAA,CAAoBJ,IAAA,EAAM;UAAAP;QAAU,EAAvC;MAAA;QAGhBY,mBAAA,GAAAC,IAA0B,CAACN,IAAA;MAAA;IAClC,CACF,CACF;IAAAR,CAAA,MAAAC,OAAA;IAAAD,CAAA,MAAAI,EAAA;EAAA;IAAAA,EAAA,GAAAJ,CAAA;EAAA;EA1BF,MAAAe,gBAAA,GAAyBX,EA2Bd;EAAA,OAGJW,gBAAA;AAAA;AAGT,SAASF,oBAAA;EACP;EAEA,OAAO,IAAIP,OAAA,CAASC,OAAA;IAClBS,UAAA,CAAWT,OAAA,EAAS,MAAK;IACzBU,qBAAA,CAAsB;MACpBD,UAAA,CAAWT,OAAA,EAAS;IACtB;EACF;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/richtext-lexical",
3
- "version": "4.0.0-beta.3",
3
+ "version": "4.0.0-beta.4",
4
4
  "description": "The officially supported Lexical richtext adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "license": "MIT",
@@ -424,6 +424,8 @@
424
424
  "@lexical/selection": "0.52.0",
425
425
  "@lexical/table": "0.52.0",
426
426
  "@lexical/utils": "0.52.0",
427
+ "@payloadcms/translations": "4.0.0-beta.4",
428
+ "@payloadcms/ui": "4.0.0-beta.4",
427
429
  "acorn": "8.16.0",
428
430
  "bson-objectid": "2.0.4",
429
431
  "csstype": "3.2.3",
@@ -437,9 +439,7 @@
437
439
  "qs-esm": "8.0.1",
438
440
  "react-error-boundary": "6.1.1",
439
441
  "ts-essentials": "10.0.3",
440
- "uuid": "14.0.0",
441
- "@payloadcms/translations": "4.0.0-beta.3",
442
- "@payloadcms/ui": "4.0.0-beta.3"
442
+ "uuid": "14.0.0"
443
443
  },
444
444
  "devDependencies": {
445
445
  "@babel/cli": "7.27.2",
@@ -453,31 +453,30 @@
453
453
  "@types/node": "24.12.3",
454
454
  "@types/react": "19.3.0",
455
455
  "@types/react-dom": "19.3.0",
456
- "babel-plugin-react-compiler": "19.1.0-rc.3",
456
+ "babel-plugin-react-compiler": "1.0.0",
457
457
  "babel-plugin-transform-remove-imports": "^1.8.0",
458
458
  "esbuild": "0.27.1",
459
459
  "esbuild-sass-plugin": "3.3.1",
460
- "swc-plugin-transform-remove-imports": "8.3.0",
461
- "@payloadcms/eslint-config": "3.28.0",
462
- "payload": "4.0.0-beta.3"
460
+ "payload": "4.0.0-beta.4",
461
+ "swc-plugin-transform-remove-imports": "8.3.0"
463
462
  },
464
463
  "peerDependencies": {
465
464
  "@faceless-ui/modal": "3.0.2",
466
465
  "@faceless-ui/scroll-info": "2.0.0",
466
+ "payload": "4.0.0-beta.4",
467
467
  "react": "^19.0.1 || ^19.1.2 || ^19.2.1",
468
- "react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1",
469
- "payload": "4.0.0-beta.3"
468
+ "react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1"
470
469
  },
471
470
  "lint-staged": {
472
471
  "*.{cjs,css,cts,graphql,html,json,jsonc,md,mdx,mjs,mts,scss,toml,yaml,yml}": "oxfmt --no-error-on-unmatched-pattern",
473
472
  ".swcrc": "oxfmt --no-error-on-unmatched-pattern",
474
473
  "*.{js,jsx,ts,tsx}": [
475
- "eslint --flag v10_config_lookup_from_file --cache --fix",
474
+ "oxlint -c ../../oxlint.config.ts --fix --no-error-on-unmatched-pattern",
476
475
  "oxfmt --no-error-on-unmatched-pattern"
477
476
  ]
478
477
  },
479
478
  "engines": {
480
- "node": ">=24.15.0"
479
+ "node": ">=24.22.1"
481
480
  },
482
481
  "scripts": {
483
482
  "build": "pnpm build:reactcompiler",
@@ -494,8 +493,6 @@
494
493
  "build:without_reactcompiler": "rm -rf dist && rm -rf tsconfig.tsbuildinfo && pnpm copyfiles && pnpm build:types && pnpm build:swc && pnpm build:esbuild && pnpm build:esbuild:postproces && rm -rf dist/exports/client && mv dist/exports/client_unoptimized dist/exports/client",
495
494
  "clean": "rimraf -g {dist,*.tsbuildinfo,esbuild}",
496
495
  "copyfiles": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
497
- "copyfiles:debug": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
498
- "lint": "eslint .",
499
- "lint:fix": "eslint . --fix"
496
+ "copyfiles:debug": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/"
500
497
  }
501
498
  }
@@ -1,2 +0,0 @@
1
- "use client";import{b as Ie,c as $e,e as K,f as j,h as Fe,i as Ke,j as je,k as ze,l as Pe,m as Re,n as He}from"./chunk-3LRZDIIG.js";import{a as Be,b as R}from"./chunk-RJ5MAOKZ.js";import{jsx as v,jsxs as ce}from"react/jsx-runtime";import{getTranslation as xn}from"@payloadcms/translations";import{BulkUploadProvider as Cn,FieldDescription as En,FieldError as Nn,FieldLabel as Sn,isFieldRTL as wn,RenderCustomComponent as jt,useConfig as Pn,useEditDepth as Rn,useEffectEvent as Tn,useField as _n,useLocale as Dn,useTranslation as kn}from"@payloadcms/ui";import{mergeFieldStyles as vn}from"@payloadcms/ui/shared";import{dequal as Ln}from"dequal/lite";import zt,{useCallback as Ht,useEffect as Vt,useMemo as An,useState as Wt}from"react";import{ErrorBoundary as Mn}from"react-error-boundary";import"../../field/bundled.css";import{jsx as H}from"react/jsx-runtime";import{LexicalComposer as dn}from"@lexical/react/LexicalComposer.js";import{useEditDepth as un}from"@payloadcms/ui";import*as Bt from"react";import{useMemo as fn}from"react";import{c as Yr}from"react/compiler-runtime";import{jsx as E,jsxs as ae}from"react/jsx-runtime";import{useLexicalComposerContext as Gr}from"@lexical/react/LexicalComposerContext.js";import{LexicalErrorBoundary as Ur}from"@lexical/react/LexicalErrorBoundary.js";import{HistoryPlugin as qr}from"@lexical/react/LexicalHistoryPlugin.js";import{OnChangePlugin as Jr}from"@lexical/react/LexicalOnChangePlugin.js";import{RichTextPlugin as Qr}from"@lexical/react/LexicalRichTextPlugin.js";import{useLexicalEditable as Xr}from"@lexical/react/useLexicalEditable";import{useTranslation as Zr}from"@payloadcms/ui";import{BLUR_COMMAND as en,COMMAND_PRIORITY_LOW as Mt,FOCUS_COMMAND as tn}from"lexical";import*as z from"react";import{useEffect as on,useState as rn}from"react";import{jsx as Ve}from"react/jsx-runtime";import"react";var W=({anchorElem:e,clientProps:t,plugin:o})=>o.position==="floatingAnchorElem"&&e?o.Component&&Ve(o.Component,{anchorElem:e,clientProps:t}):o.Component&&Ve(o.Component,{clientProps:t});import{c as Ut}from"react/compiler-runtime";import{copyToClipboard as We}from"@lexical/clipboard";import{useLexicalComposerContext as qt}from"@lexical/react/LexicalComposerContext.js";import{objectKlassEquals as Jt}from"@lexical/utils";import Ye from"bson-objectid";import{$getSelection as Qt,$isNodeSelection as Xt,COMMAND_PRIORITY_LOW as Zt,COPY_COMMAND as eo}from"lexical";import{useEffect as to}from"react";var Te=e=>{if("fields"in e&&typeof e.fields=="object"&&e.fields!==null&&"id"in e.fields?e.fields.id=new Ye.default().toHexString():"id"in e&&(e.id=new Ye.default().toHexString()),e.children)for(let t of e.children)Te(t)};function Ge(){let e=Ut(3),[t]=qt(),o,r;return e[0]!==t?(o=()=>t.registerCommand(eo,n=>{let i=Qt();if(Xt(i)){let l=i.getNodes()[0]?.exportJSON(),d=JSON.parse(JSON.stringify(l));Te(d);let u={namespace:t._config.namespace,nodes:[d]},m=JSON.stringify(u);return We(t,null,{"application/x-lexical-editor":m,"text/plain":""}).catch(oo),!0}return We(t,Jt(n,ClipboardEvent)?n:null).then(()=>{if(!(n instanceof ClipboardEvent)||!n.clipboardData)throw new Error("No clipboard event");let s=n.clipboardData.getData("application/x-lexical-editor");if(!s)return!0;let l=JSON.parse(s);for(let u of l.nodes)Te(u);let d=JSON.stringify(l);n.clipboardData.setData("application/x-lexical-editor",d)}).catch(s=>{throw n instanceof ClipboardEvent&&n.clipboardData?.setData("application/x-lexical-editor",""),s}),!0},Zt),r=[t],e[0]=t,e[1]=o,e[2]=r):(o=e[1],r=e[2]),to(o,r),null}function oo(e){throw e}import{c as ro}from"react/compiler-runtime";import{useLexicalComposerContext as no}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as fe,mergeRegister as io}from"@lexical/utils";import{$createNodeSelection as so,$getEditor as me,$getNearestNodeFromDOMNode as lo,$getSelection as pe,$isDecoratorNode as Y,$isElementNode as _e,$isLineBreakNode as ao,$isNodeSelection as ge,$isRangeSelection as qe,$isRootOrShadowRoot as co,$isTextNode as uo,$onUpdate as fo,$setSelection as Je,CLICK_COMMAND as mo,COMMAND_PRIORITY_LOW as Q,KEY_ARROW_DOWN_COMMAND as po,KEY_ARROW_UP_COMMAND as go,KEY_BACKSPACE_COMMAND as ho,KEY_DELETE_COMMAND as yo,SELECTION_CHANGE_COMMAND as bo}from"lexical";import{useEffect as xo}from"react";function Qe(){let e=ro(3),[t]=no(),o=Po,r,n;return e[0]!==t?(r=()=>io(t.registerCommand(mo,wo,Q),t.registerCommand(yo,o,Q),t.registerCommand(ho,o,Q),t.registerCommand(bo,(i,s)=>{if(s!==t)return!1;let l=!!Ue();return fo(()=>{s.read("latest",()=>{let d=Ue();document.querySelector(".decorator-selected")?.classList.remove("decorator-selected"),d&&s.getElementByKey(d.getKey())?.classList.add("decorator-selected")})}),l},Q),t.registerCommand(go,No,Q),t.registerCommand(po,Co,Q)),n=[t],e[0]=t,e[1]=r,e[2]=n):(r=e[1],n=e[2]),xo(r,n),null}function Co(e){let t=pe();if(ge(t)){e.preventDefault();let s=t.getNodes()[0]?.getNextSibling();if(Y(s)){let u=me().getElementByKey(s.getKey());return u&&ie({element:u,node:s}),!0}if(!_e(s))return!0;let l=s.getFirstDescendant()??s;return l&&(fe(l,he)?.selectEnd(),e.preventDefault()),!0}if(!qe(t))return!1;let r=(t.isBackward()?t.anchor:t.focus).getNode(),n=fe(r,Eo),i=n?.getNextSibling();if(!n||i!==Xe(n))return!1;if(Y(i)){let s=me().getElementByKey(i.getKey());if(s)return ie({element:s,node:i}),e.preventDefault(),!0}return!1}function Eo(e){return Xe(e)!==null}function No(e){let t=pe();if(ge(t)){let s=t.getNodes()[0]?.getPreviousSibling();if(Y(s)){let u=me().getElementByKey(s.getKey());return u?(ie({element:u,node:s}),e.preventDefault(),!0):!1}if(!_e(s))return!1;let l=s.getLastDescendant()??s;return l?(fe(l,he)?.selectStart(),e.preventDefault(),!0):!1}if(!qe(t))return!1;let r=(t.isBackward()?t.anchor:t.focus).getNode(),n=fe(r,So),i=n?.getPreviousSibling();if(!n||i!==Ze(n))return!1;if(Y(i)){let s=me().getElementByKey(i.getKey());if(s)return ie({element:s,node:i}),e.preventDefault(),!0}return!1}function So(e){return Ze(e)!==null}function wo(e){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let t=To(e);if(!t)return!0;let{target:o}=e;return!(o instanceof HTMLElement)||o.isContentEditable||o.closest('button, textarea, input, .react-select, .code-editor, .no-select-decorator, [role="button"]')?Je(null):ie(t),!0}function Po(e){let t=pe();return ge(t)?(e.preventDefault(),t.getNodes().forEach(Ro),!0):!1}function Ro(e){e.remove()}function To(e){if(!(e.target instanceof HTMLElement))return;let t=e.target.closest('[data-lexical-decorator="true"]');if(!(t instanceof HTMLElement))return;let o=lo(t);return Y(o)?{element:t,node:o}:void 0}function Ue(){let e=pe();if(!ge(e))return;let t=e.getNodes();if(t.length!==1)return;let o=t[0];return Y(o)?o:void 0}function ie({element:e,node:t}){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let o=so();o.add(t.getKey()),Je(o),e.scrollIntoView({behavior:"smooth",block:"nearest"}),e.classList.add("decorator-selected")}function he(e){if(Y(e)&&!e.isInline())return!0;if(!_e(e)||co(e))return!1;let t=e.getFirstChild(),o=t===null||ao(t)||uo(t)||t.isInline();return!e.isInline()&&e.canBeEmpty()!==!1&&o}function Xe(e){let t=e.getNextSibling();for(;t!==null;){if(he(t))return t;t=t.getNextSibling()}return null}function Ze(e){let t=e.getPreviousSibling();for(;t!==null;){if(he(t))return t;t=t.getPreviousSibling()}return null}import{jsx as De}from"react/jsx-runtime";import{useLexicalComposerContext as Ao}from"@lexical/react/LexicalComposerContext.js";import{$createParagraphNode as Mo,isHTMLElement as Oo}from"lexical";import*as rt from"react";import{useCallback as Bo,useEffect as ot,useRef as Io,useState as $o}from"react";import{createPortal as Fo}from"react-dom";var X=(e,t,o,r,n=50,i=25)=>{let s=0;if(e&&!e.contains(r)){let{bottom:l,left:d,right:u,top:m}=e.getBoundingClientRect(),a=m+window.scrollY,c=l+window.scrollY;if(o<a-i||o>c+i||t<d-n||t>u+n)return-1;(t<d||t>u)&&(s=t<d?t-d:t-u)}return s};import{$getNodeByKey as be}from"lexical";function Z(e){let t=e.getBoundingClientRect(),o=getComputedStyle(e).getPropertyValue("transform");if(!o||o==="none")return t;let r=o.split(",").pop();return t.y=t.y-Number(r?.replace(")","")),t}function ye(e){let t=(d,u)=>d?parseFloat(window.getComputedStyle(d)[u]):0,{marginBottom:o,marginTop:r}=window.getComputedStyle(e),n=t(e.previousElementSibling,"marginBottom"),i=t(e.nextElementSibling,"marginTop"),s=Math.max(parseFloat(r),n);return{marginBottom:Math.max(parseFloat(o),i),marginTop:s}}import{$getRoot as _o}from"lexical";function G(e){return e.getEditorState().read(()=>_o().getChildrenKeys())}var Do=1,ko=-1,et=0,M={props:null,result:null};function vo(e,t,o=20){let r=e.x-t.x,n=e.y-t.y;return r*r+n*n<=o*o}function ee(e){let{anchorElem:t,cache_threshold:o=20,editor:r,fuzzy:n=!1,horizontalOffset:i=0,point:{x:s,y:l},startIndex:d=0,useEdgeAsDefault:u=!1}=e;if(o>0&&M.props&&M.result&&M.props.fuzzy===e.fuzzy&&M.props.horizontalOffset===e.horizontalOffset&&M.props.useEdgeAsDefault===e.useEdgeAsDefault&&vo(M.props.point,e.point,o))return M.result;let m=t.getBoundingClientRect(),a=G(r),c={blockElem:null,blockNode:null,distance:1/0,foundAtIndex:-1,isFoundNodeEmptyParagraph:!1};return r.getEditorState().read(()=>{if(u){let f=r.getElementByKey(a[0]),p=r.getElementByKey(a[a.length-1]);if(f&&p){let[h,C]=[Z(f),Z(p)];if(l<h.top?(c.blockElem=f,c.distance=h.top-l,c.blockNode=be(a[0]),c.foundAtIndex=0):l>C.bottom&&(c.distance=l-C.bottom,c.blockNode=be(a[a.length-1]),c.blockElem=p,c.foundAtIndex=a.length-1),c?.blockElem)return{blockElem:null,isFoundNodeEmptyParagraph:!1}}}let g=d,y=et;for(;g>=0&&g<a.length;){let f=a[g],p=r.getElementByKey(f);if(p===null)break;let h=new j(s+i,l),C=ze.fromDOMRect(Z(p)),{marginBottom:x,marginTop:N}=ye(p),b=C.generateNewRect({bottom:C.bottom+x,left:m.left,right:m.right,top:C.top-N}),{distance:S,isOnBottomSide:D,isOnTopSide:_}=b.distanceFromPoint(h);if(S===0){c.blockElem=p,c.blockNode=be(f),c.foundAtIndex=g,c.distance=S,c.blockNode&&c.blockNode.getType()==="paragraph"&&c.blockNode.getTextContent()===""&&(!n&&!e.returnEmptyParagraphs&&(c.blockElem=null,c.blockNode=null),c.isFoundNodeEmptyParagraph=!0);break}else n&&S<c.distance&&(c.blockElem=p,c.blockNode=be(f),c.distance=S,c.foundAtIndex=g);y===et&&(_?y=ko:D?y=Do:y=1/0),g+=y}}),M.props=e,M.result={blockElem:c.blockElem,blockNode:c.blockNode,foundAtIndex:c.foundAtIndex,isFoundNodeEmptyParagraph:c.isFoundNodeEmptyParagraph},{blockElem:c.blockElem,blockNode:c.blockNode,foundAtIndex:c.foundAtIndex,isFoundNodeEmptyParagraph:c.isFoundNodeEmptyParagraph}}function xe(e,t){return!!e.closest(`.${t}`)}var Lo=["IMG","INPUT","TEXTAREA","SELECT","BUTTON","VIDEO","OBJECT","EMBED","IFRAME","HR"];function tt(e){if(!e||Lo.includes(e.tagName)||e.offsetHeight===0||e.offsetWidth===0)return!1;let t=window.getComputedStyle(e);return!(t.display==="table-cell"||t.position==="absolute"||t.visibility==="hidden"||t.opacity==="0")}function Ce(e,t,o,r=0){if(!e){t.style.visibility="hidden",t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)";return}let n=e.getBoundingClientRect(),i=window.getComputedStyle(e),s=t.getBoundingClientRect(),l=o.getBoundingClientRect(),d;if(["LexicalEditorTheme__block","LexicalEditorTheme__upload","LexicalEditorTheme__relationship"].some(a=>e.classList.contains(a)||e.firstElementChild?.classList.contains(a)))d=n.top+8-l.top;else{let a=tt(e)?parseInt(i.lineHeight,10):0;d=n.top+(a-s.height)/2-l.top}let m=r;t.style.opacity="1",t.style.visibility="visible",t.style.transform=`translate(${m}px, ${d}px)`}var Ko="add-block-menu",Ee=1/0;function jo(e){return e===0?1/0:Ee>=0&&Ee<e?Ee:Math.floor(e/2)}function zo(e,t,o){let r=t.parentElement,{editorConfig:n}=R(),i=n?.admin?.hideGutter?-24:12,s=Io(null),[l,d]=$o(null);ot(()=>{function m(a){let c=a.target;if(!Oo(c))return;let g=X(r,a.pageX,a.pageY,c);if(g===-1){d(null);return}if(xe(c,Ko))return;let y=G(e),{blockElem:f,blockNode:p,foundAtIndex:h}=ee({anchorElem:t,cache_threshold:0,editor:e,horizontalOffset:-g,point:new j(a.x,a.y),returnEmptyParagraphs:!0,startIndex:jo(y.length),useEdgeAsDefault:!1});Ee=h,f&&p&&(l?.node!==p||l?.elem!==f)&&d({elem:f,node:p})}return document?.addEventListener("mousemove",m),()=>{document?.removeEventListener("mousemove",m)}},[r,t,e,l]),ot(()=>{s.current&&Ce(l?.elem??null,s.current,t,i)},[t,l,i]);let u=Bo(m=>{let a=l;a?.node&&(e.update(()=>{let c=!0;if((a?.node.getType()!=="paragraph"||a.node.getTextContent()!=="")&&(c=!1),!c){let g=Mo();a?.node.insertAfter(g),setTimeout(()=>{a={elem:e.getElementByKey(g.getKey()),node:g},d(a)},0)}}),setTimeout(()=>{e.update(()=>{e.focus(),a?.node&&"select"in a.node&&typeof a.node.select=="function"&&a.node.select()})},1),setTimeout(()=>{e.dispatchCommand(Ke,{node:a?.node})},2),m.stopPropagation(),m.preventDefault())},[e,l]);return Fo(De(rt.Fragment,{children:De("button",{"aria-label":"Add block",className:"icon add-block-menu",onClick:m=>{u(m)},ref:s,type:"button",children:De("div",{className:o?"icon":""})})}),t)}function nt(e){let{anchorElem:t}=e,o=t===void 0?document.body:t,[r]=Ao();return zo(r,o,r._editable)}import{jsx as Ne,jsxs as dt}from"react/jsx-runtime";import{useLexicalComposerContext as Jo}from"@lexical/react/LexicalComposerContext.js";import{eventFiles as ut}from"@lexical/rich-text";import{useTranslation as Qo}from"@payloadcms/ui";import{$getNearestNodeFromDOMNode as ft,$getNodeByKey as Xo,isHTMLElement as ke}from"lexical";import*as yt from"react";import{useEffect as ve,useId as Zo,useRef as se,useState as mt}from"react";import{createPortal as er}from"react-dom";var it=0,Ho=-24;var U=0;function st(e,t,o,r,n,i,s,l,d,u=!1){let{height:m,top:a}=r.getBoundingClientRect(),{top:c,width:g}=s.getBoundingClientRect(),{marginBottom:y,marginTop:f}=ye(r),p=a,h=i>=a+m/2+window.scrollY,C=!1;if(n?.elem)if(r!==n?.elem)(h&&n?.elem&&n?.elem===r.nextElementSibling||!h&&n?.elem&&n?.elem===r.previousElementSibling)&&(U++,U<200&&(C=!0));else{U++;let S=n?.boundingBox?.y,D=r.getBoundingClientRect().y;(h===n?.isBelow&&S===D||U<200)&&(C=!1)}if(C)return{isBelow:h,willStayInSamePosition:C};u?p+=m/2:h?p+=m+y/2:p-=f/2;let x=0;u||(h?x=-it:x=it);let N=p-c+x,b=Ho-t;return o.style.width=`calc(${g}px - ${e} - var(--spacer-5))`,o.style.opacity=".8",o.style.transform=`translate(${b}px, calc(${N}px - 2px))`,n?.elem&&(n.elem.style.opacity="",n?.elem===r?h?n.elem.style.marginTop="":n.elem.style.marginBottom="":(n.elem.style.marginBottom="",n.elem.style.marginTop="")),U=0,{isBelow:h,willStayInSamePosition:C}}import{mergeRegister as Vo}from"@lexical/utils";import{$getSelection as Wo,$isNodeSelection as Yo,$isRangeSelection as Go,COMMAND_PRIORITY_HIGH as lt,KEY_ARROW_DOWN_COMMAND as Uo,KEY_ARROW_UP_COMMAND as qo}from"lexical";import{useEffect as at}from"react";function ct({editor:e,instructionsID:t}){at(()=>{let o=({direction:r,event:n})=>{if(!e.isEditable()||!n.altKey||!n.shiftKey||n.ctrlKey||n.metaKey)return!1;let i=Wo(),l=(Go(i)&&i.isCollapsed()?i.anchor.getNode():Yo(i)&&i.getNodes().length===1?i.getNodes()[0]:null)?.getTopLevelElement();if(!l)return!1;n.preventDefault();let d=r===-1?l.getPreviousSibling():l.getNextSibling();return d&&(r===-1?d.insertBefore(l):d.insertAfter(l)),!0};return Vo(e.registerCommand(qo,r=>o({direction:-1,event:r}),lt),e.registerCommand(Uo,r=>o({direction:1,event:r}),lt))},[e]),at(()=>{let o,r=e.registerRootListener(n=>{if(o?.(),!n)return;let i=n.getAttribute("aria-describedby");n.setAttribute("aria-describedby",[i,t].filter(Boolean).join(" ")),o=()=>{i===null?n.removeAttribute("aria-describedby"):n.setAttribute("aria-describedby",i)}});return()=>{r(),o?.()}},[e,t])}var tr="draggable-block-menu",pt="application/x-lexical-drag-block",le=1/0;function gt(e){return e===0?1/0:le>=0&&le<e?le:Math.floor(e/2)}function or(e,t){let{transform:o}=t.style;e.setDragImage(t,0,0),setTimeout(()=>{t.style.transform=o})}function ht(e,t){e&&(e.style.opacity="0"),t&&(t.style.opacity="",t.style.marginBottom="",t.style.marginTop="")}function rr(e,t,o){let r=t.parentElement,n=Zo(),{t:i}=Qo();ct({editor:e,instructionsID:n});let s=se(null),l=se(null),d=se(null),u=se(!1),m=se([]),[a,c]=mt(null),[g,y]=mt(null),{editorConfig:f}=R(),p=f?.admin?.hideGutter?-44:-8;ve(()=>{function x(N){let b=N.target;if(!ke(b))return;let S=X(r,N.pageX,N.pageY,b);if(S===-1){c(null);return}if(xe(b,tr))return;let D=G(e),{blockElem:_,foundAtIndex:B,isFoundNodeEmptyParagraph:V}=ee({anchorElem:t,cache_threshold:0,editor:e,horizontalOffset:-S,point:new j(N.x,N.y),startIndex:gt(D.length),useEdgeAsDefault:!1,verbose:!1});le=B,!(!_&&!V)&&a!==_&&c(_)}return document?.addEventListener("mousemove",x),()=>{document?.removeEventListener("mousemove",x)}},[r,t,e,a]),ve(()=>{s.current&&Ce(a,s.current,t,p)},[t,a,p]),ve(()=>{function x(b){if(!u.current)return!1;let[S]=ut(b);if(S)return!1;let{pageY:D,target:_}=b;if(!ke(_))return!1;let B=X(r,b.pageX,b.pageY,_,100,50),V=G(e),{blockElem:w,foundAtIndex:k,isFoundNodeEmptyParagraph:I}=ee({anchorElem:t,editor:e,fuzzy:!0,horizontalOffset:-B,point:new j(b.x,b.y),startIndex:gt(V.length),useEdgeAsDefault:!0,verbose:!0});le=k;let $=l.current;if(w===null||$===null)return!1;if(b.preventDefault(),b.dataTransfer.dropEffect="move",a!==w){let{isBelow:T,willStayInSamePosition:q}=st(f?.admin?.hideGutter?"0px":"var(--spacer-5)",p+(f?.admin?.hideGutter?s?.current?.getBoundingClientRect()?.width??0:-(s?.current?.getBoundingClientRect()?.width??0)),$,w,g,D,t,b,d,I);q||y({boundingBox:w.getBoundingClientRect(),elem:w,isBelow:T})}else g?.elem&&(ht($,g.elem),y({boundingBox:w.getBoundingClientRect(),elem:w,isBelow:!1}));return!0}function N(b){if(!u.current)return!1;let[S]=ut(b);if(S)return!1;let{dataTransfer:D,pageY:_,target:B}=b,V=D?.getData(pt)||"";return e.update(()=>{let w=Xo(V);if(!w||!ke(B))return!1;let k=X(r,b.pageX,b.pageY,B,100,50),{blockElem:I,isFoundNodeEmptyParagraph:$}=ee({anchorElem:t,editor:e,fuzzy:!0,horizontalOffset:-k,point:new j(b.x,b.y),useEdgeAsDefault:!0});if(!I)return!1;let T=ft(I);if(!T)return!1;if(T===w)return!0;let{height:q,top:J}=Z(I),Se=_>=J+q/2+window.scrollY;$?(T.insertBefore(w),T.remove()):Se?T.insertAfter(w):T.insertBefore(w),a!==null&&c(null),document.querySelectorAll(".lexical-block-highlighter").forEach(L=>{L.remove()});let de=e.getElementByKey(w.getKey()),F=setTimeout(()=>{let L=de?.getBoundingClientRect();if(!L)return;let P=document.createElement("div");P.className="lexical-block-highlighter",P.style.backgroundColor="var(--color-bg-inverse)",P.style.transition="opacity 0.5s ease-in-out",P.style.zIndex="1",P.style.pointerEvents="none",P.style.boxSizing="border-box",P.style.borderRadius="4px",P.style.position="absolute",document.body.appendChild(P),P.style.opacity="0.1",P.style.height=`${L.height+8}px`,P.style.width=`${L.width+8}px`,P.style.top=`${L.top+window.scrollY-4}px`,P.style.left=`${L.left-4}px`;let ue=setTimeout(()=>{P.style.opacity="0";let we=setTimeout(()=>{P.remove()},500);m.current.push(we)},1e3);m.current.push(ue)},120);m.current.push(F)}),!0}return document.addEventListener("dragover",x),document.addEventListener("drop",N),()=>{document.removeEventListener("dragover",x),document.removeEventListener("drop",N),m.current.forEach(clearTimeout),m.current=[]}},[r,p,t,e,g,a,f?.admin?.hideGutter]);function h(x){let N=x.dataTransfer;if(!N||!a)return;or(N,a),N.effectAllowed="move";let b="";e.update(()=>{let S=ft(a);S&&(b=S.getKey())}),u.current=!0,N.setData(pt,b)}function C(){u.current=!1,g?.elem&&ht(l.current,g?.elem)}return er(dt(yt.Fragment,{children:[dt("span",{className:"sr-only",id:n,children:[i("general:moveUp"),": Alt + Shift + \u2191. ",i("general:moveDown"),": Alt + Shift + \u2193."]}),Ne("button",{"aria-label":"Drag to move",className:"icon draggable-block-menu",draggable:!0,onDragEnd:C,onDragStart:h,ref:s,type:"button",children:Ne("div",{className:o?"icon":""})}),Ne("div",{className:"draggable-block-target-line",ref:l}),Ne("div",{className:"debug-highlight",ref:d})]}),t)}function bt(e){let{anchorElem:t}=e,o=t===void 0?document.body:t,[r]=Jo();return rr(r,o,r._editable)}import{c as nr}from"react/compiler-runtime";import{jsx as Le}from"react/jsx-runtime";import{useLexicalComposerContext as ir}from"@lexical/react/LexicalComposerContext";import{useTranslation as sr}from"@payloadcms/ui";import{$createParagraphNode as lr,$getRoot as ar}from"lexical";import"react";var xt="insert-paragraph-at-end",Ct=()=>{let e=nr(5),[t]=ir(),{editorConfig:o}=R(),{t:r}=sr();if(o?.admin?.hideInsertParagraphAtEnd)return null;let n;e[0]!==t?(n=()=>{t.update(cr)},e[0]=t,e[1]=n):n=e[1];let i=n,s;return e[2]!==i||e[3]!==r?(s=Le("button",{"aria-label":r("lexical:general:insertParagraph"),className:xt,onClick:i,type:"button",children:Le("span",{className:`${xt}-inside`,children:Le(Ie,{size:16})})}),e[2]=i,e[3]=r,e[4]=s):s=e[4],s};function cr(){let e=lr();ar().append(e),e.select()}import{c as dr}from"react/compiler-runtime";import{registerMarkdownShortcuts as ur}from"@lexical/markdown";import{useLexicalComposerContext as fr}from"@lexical/react/LexicalComposerContext";import*as Et from"react";var Nt=()=>{let e=dr(4),{editorConfig:t}=R(),[o]=fr(),r,n;return e[0]!==o||e[1]!==t.features.markdownTransformers?(r=()=>ur(o,t.features.markdownTransformers??[]),n=[o,t.features.markdownTransformers],e[0]=o,e[1]=t.features.markdownTransformers,e[2]=r,e[3]=n):(r=e[2],n=e[3]),Et.useEffect(r,n),null};import{c as mr}from"react/compiler-runtime";import{useLexicalComposerContext as pr}from"@lexical/react/LexicalComposerContext.js";import{$getRoot as gr}from"lexical";import{useEffect as hr}from"react";function yr(e){e.update(()=>{let t=o=>{let r=o.getType();if((r==="block"||r==="inlineBlock")&&o.markDirty(),"getChildren"in o&&typeof o.getChildren=="function")for(let n of o.getChildren())t(n)};t(gr())})}function St(){let e=mr(5),[t]=pr(),{currentView:o,views:r}=K(),n,i;return e[0]!==o||e[1]!==t||e[2]!==r?(n=()=>{r&&(o==="default"?r.default?Pe(t,r.default?.nodes):Re(t):r[o]&&(Re(t),Pe(t,r[o]?.nodes)),yr(t))},i=[t,r,o],e[0]=o,e[1]=t,e[2]=r,e[3]=n,e[4]=i):(n=e[3],i=e[4]),hr(n,i),null}import{useLexicalComposerContext as br}from"@lexical/react/LexicalComposerContext";import{$getSelection as xr,$isRangeSelection as Cr,RootNode as Er}from"lexical";import{useEffect as Nr}from"react";function wt(){let[e]=br();return Nr(()=>e.registerNodeTransform(Er,t=>{let o=xr();if(Cr(o)){let r=o.anchor.getNode(),n=o.focus.getNode();(!r.isAttached()||!n.isAttached())&&(t.selectEnd(),console.warn("updateEditor: selection has been moved to the end of the editor because the previously selected nodes have been removed and selection wasn't moved to another node. Ensure selection changes after removing/replacing a selected node."))}return!1}),[e]),null}import{useLexicalComposerContext as Sr}from"@lexical/react/LexicalComposerContext";import{$getSelection as wr,COMMAND_PRIORITY_LOW as Pr,SELECT_ALL_COMMAND as Rr}from"lexical";import{useEffect as Tr}from"react";function Pt(){let[e]=Sr();return Tr(()=>e.registerCommand(Rr,()=>{if(wr())return!1;let o=document.activeElement;return o instanceof HTMLInputElement&&o.select(),!0},Pr),[e]),null}import{jsx as te,jsxs as Tt}from"react/jsx-runtime";import{useLexicalComposerContext as Dr}from"@lexical/react/LexicalComposerContext.js";import{useTranslation as _t}from"@payloadcms/ui";import{useCallback as kr,useMemo as vr,useState as Lr}from"react";import"react";import*as Dt from"react-dom";import{c as _r}from"react/compiler-runtime";import"react";function Rt(e,t){let o=_r(4),{maxLength:r,minLength:n}=t,i=r===void 0?75:r,s=n===void 0?1:n,l;return o[0]!==i||o[1]!==s||o[2]!==e?(l=d=>{let{query:u}=d,m="[^"+e+Fe+"\\s]",c=new RegExp("(^|\\s|\\()(["+e+"]((?:"+m+"){0,"+i+"}))$").exec(u);if(c!==null){let g=c[1],y=c[3];if(y.length>=s)return{leadOffset:c.index+g.length,matchingString:y,replaceableString:c[2]}}return null},o[0]=i,o[1]=s,o[2]=e,o[3]=l):l=o[3],l}var O="slash-menu-popup";function Ar({isSelected:e,item:t,onClick:o,onMouseEnter:r,ref:n}){let{fieldProps:{featureClientSchemaMap:i,schemaPath:s}}=R(),{i18n:l}=_t(),d=`${O}__item ${O}__item-${t.key}`;e&&(d+=` ${O}__item--selected`);let u=t.key;return t.label&&(u=typeof t.label=="function"?t.label({featureClientSchemaMap:i,i18n:l,schemaPath:s}):t.label),u.length>25&&(u=u.substring(0,25)+"..."),Tt("button",{"aria-selected":e,className:d,id:O+"__item-"+t.key,onClick:o,onMouseEnter:r,ref:n,role:"option",tabIndex:-1,type:"button",children:[t?.Icon&&te(t.Icon,{}),te("span",{className:`${O}__item-text`,children:u})]},t.key)}function kt({anchorElem:e=document.body}){let[t]=Dr(),[o,r]=Lr(null),{editorConfig:n}=R(),{i18n:i}=_t(),{fieldProps:{featureClientSchemaMap:s,schemaPath:l}}=R(),d=Rt("/",{minLength:0}),u=kr(()=>{let a=[];for(let c of n.features.slashMenu.dynamicGroups)if(o){let g=c({editor:t,queryString:o});a=a.concat(g)}return a},[t,o,n?.features]),m=vr(()=>{let a=[];for(let c of n?.features.slashMenu.groups??[])a.push(c);if(o){let c=o.toLowerCase().replace(/[\s\-_]/g,"");a=a.map(y=>{let f=y.items.filter(p=>{let h=p.key;return p.label&&(h=typeof p.label=="function"?p.label({featureClientSchemaMap:s,i18n:i,schemaPath:l}):p.label),new RegExp(o,"gi").exec(h)||h.toLowerCase().replace(/[\s\-_]/g,"").includes(c)?!0:p.keywords!=null?p.keywords.some(x=>new RegExp(o,"gi").exec(x)?!0:x.toLowerCase().replace(/[\s\-_]/g,"").includes(c)):!1});return f.length?{...y,items:f}:null}),a=a.filter(y=>y!=null);let g=u();for(let y of g){let f=a.find(p=>p.key===y.key);f?a=a.filter(p=>p.key!==y.key):f={...y,items:[]},f?.items?.length&&(f.items=f.items.concat(f.items)),a.push(f)}}return a},[o,n?.features.slashMenu.groups,u,s,i,l]);return te(je,{anchorElem:e,groups:m,menuRenderFn:(a,{selectedItemKey:c,selectItemAndCleanUp:g,setSelectedItemKey:y})=>a.current&&m.length?Dt.createPortal(te("div",{className:O,"data-theme":"dark",children:m.map(f=>{let p=f.key;return f.label&&s&&(p=typeof f.label=="function"?f.label({featureClientSchemaMap:s,i18n:i,schemaPath:l}):f.label),Tt("div",{className:`${O}__group ${O}__group-${f.key}`,children:[te("div",{className:`${O}__group-title`,children:p}),f.items.map((h,C)=>te(Ar,{index:C,isSelected:c===h.key,item:h,onClick:()=>{y(h.key),g(h)},onMouseEnter:()=>{y(h.key)},ref:x=>{h.ref={current:x}}},h.key))]},f.key)})}),a.current):null,onQueryChange:r,triggerFn:d})}import{c as Mr}from"react/compiler-runtime";import{useLexicalComposerContext as Or}from"@lexical/react/LexicalComposerContext";import{TEXT_TYPE_TO_FORMAT as Br,TextNode as Ir}from"lexical";import{useEffect as $r}from"react";function vt(e){let t=Mr(6),{features:o}=e,[r]=Or(),n;t[0]!==r||t[1]!==o.enabledFormats?(n=()=>{let s=Fr(o.enabledFormats);if(s.length!==0)return r.registerNodeTransform(Ir,l=>{s.forEach(d=>{l.hasFormat(d)&&l.toggleFormat(d)})})},t[0]=r,t[1]=o.enabledFormats,t[2]=n):n=t[2];let i;return t[3]!==r||t[4]!==o?(i=[r,o],t[3]=r,t[4]=o,t[5]=i):i=t[5],$r(n,i),null}function Fr(e){let t=Object.keys(Br),o=new Set(e);return t.filter(r=>!o.has(r))}import{c as Kr}from"react/compiler-runtime";import{jsx as Lt}from"react/jsx-runtime";import{useLexicalComposerContext as jr}from"@lexical/react/LexicalComposerContext";import{ContentEditable as zr}from"@lexical/react/LexicalContentEditable.js";import{useLexicalEditable as Hr}from"@lexical/react/useLexicalEditable";import{getTranslation as Vr}from"@payloadcms/translations";import{useTranslation as Wr}from"@payloadcms/ui";import"react";function At(e){let t=Kr(10),{className:o,editorConfig:r,instructionsID:n}=e,{fieldProps:i}=R(),{i18n:s,t:l}=Wr(),[,d]=jr(),{getTheme:u}=d,m=Hr(),a;if(t[0]!==o||t[1]!==r?.admin?.placeholder||t[2]!==i.field.label||t[3]!==i.field.required||t[4]!==u||t[5]!==s||t[6]!==n||t[7]!==m||t[8]!==l){let c=u();a=Lt(zr,{"aria-describedby":n,"aria-label":Vr(i.field.label||"",s),"aria-required":i.field.required||void 0,className:o??"ContentEditable__root",...m?{"aria-placeholder":l("lexical:general:placeholder"),placeholder:Lt("p",{className:c?.placeholder,children:r?.admin?.placeholder??l("lexical:general:placeholder")})}:{placeholder:null}}),t[0]=o,t[1]=r?.admin?.placeholder,t[2]=i.field.label,t[3]=i.field.required,t[4]=u,t[5]=s,t[6]=n,t[7]=m,t[8]=l,t[9]=a}else a=t[9];return a}var Ot=e=>{let t=Yr(5),{editorConfig:o,editorContainerRef:r,isSmallWidthViewport:n,onChange:i,rtl:s}=e,l=R(),[d]=Gr(),u=Xr(),{t:m}=Zr(),a=z.useId(),c=u&&o.features.enabledFeatures.includes("indent"),[g,y]=rn(null),f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=x=>{x!==null&&y(x)},t[0]=f):f=t[0];let p=f,h,C;return t[1]!==d||t[2]!==l?(h=()=>{if(!l?.uuid){console.error("Lexical Editor must be used within an EditorConfigProvider");return}l?.parentEditor?.uuid&&l.parentEditor?.registerChild(l.uuid,l);let x=()=>{l.focusEditor(l)},N=()=>{l.blurEditor(l)},b=d.registerCommand(tn,()=>(x(),!0),Mt),S=d.registerCommand(en,()=>(N(),!0),Mt);return()=>{b(),S(),l.parentEditor?.unregisterChild?.(l.uuid)}},C=[d,l],t[1]=d,t[2]=l,t[3]=h,t[4]=C):(h=t[3],C=t[4]),on(h,C),ae(z.Fragment,{children:[o.features.plugins?.map(nn),ae("div",{className:"editor-container",dir:s?"rtl":void 0,ref:r,children:[o.features.plugins?.map(sn),E(Qr,{contentEditable:E("div",{className:"editor-scroller",children:E("div",{className:"editor",ref:p,children:E(At,{editorConfig:o,instructionsID:c?a:void 0})})}),ErrorBoundary:Ur}),E(wt,{}),u&&E(Ct,{}),E(Qe,{}),E(Ge,{}),E(vt,{features:o.features}),E(Pt,{}),E(St,{}),u&&E(Jr,{ignoreSelectionChange:!0,onChange:(x,N,b)=>{(!b.has("focus")||b.size>1)&&i?.(x,N,b)}}),g&&ae(z.Fragment,{children:[!n&&u&&ae(z.Fragment,{children:[o.admin?.hideDraggableBlockElement?null:E(bt,{anchorElem:g}),o.admin?.hideAddBlockButton?null:E(nt,{anchorElem:g})]}),o.features.plugins?.map(x=>{if(x.position==="floatingAnchorElem"&&!(x.desktopOnly===!0&&n))return E(W,{anchorElem:g,clientProps:x.clientProps,plugin:x},x.key)}),u&&E(z.Fragment,{children:E(kt,{anchorElem:g})})]}),u&&ae(z.Fragment,{children:[E(qr,{}),o?.features?.markdownTransformers?.length>0&&E(Nt,{})]}),o.features.plugins?.map(ln),o.features.plugins?.map(an)]}),c&&E("p",{className:"ContentEditable__keyboard-hint",id:a,children:m("lexical:indent:keyboardHint")}),o.features.plugins?.map(cn)]})};function nn(e){if(e.position==="aboveContainer")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function sn(e){if(e.position==="top")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function ln(e){if(e.position==="normal")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function an(e){if(e.position==="bottom")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}function cn(e){if(e.position==="belowContainer")return E(W,{clientProps:e.clientProps,plugin:e},e.key)}var It=({children:e,providers:t})=>{if(!t?.length)return e;let o=t[0];return t.length>1?H(o,{children:H(It,{providers:t.slice(1),children:e})}):H(o,{children:e})},$t=e=>{let{composerKey:t,editorConfig:o,fieldProps:r,isSmallWidthViewport:n,onChange:i,readOnly:s,rtl:l,value:d}=e,{currentView:u,views:m}=K(),a=R(),c=un(),g=Bt.useRef(null),y=fn(()=>{if(d&&typeof d!="object")throw new Error("The value passed to the Lexical editor is not an object. This is not supported. Please remove the data from the field and start again. This is the value that was passed in: "+JSON.stringify(d));if(d&&Array.isArray(d)&&!("root"in d))throw new Error("You have tried to pass in data from the old Slate editor to the new Lexical editor. The data structure is different, thus you will have to migrate your data. We offer a one-line migration script which migrates all your rich text fields: https://payloadcms.com/docs/lexical/migration#migration-via-migration-script-recommended");if(d&&"jsonContent"in d)throw new Error("You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical");let f=m?.[u]?.nodes;return{editable:s!==!0,editorState:d!=null?JSON.stringify(d):void 0,namespace:o.lexical.namespace,nodes:He({editorConfig:o,nodeViews:f}),onError:p=>{throw p},theme:o.lexical.theme}},[o,m,u]);return y?H(dn,{initialConfig:y,children:H(Be,{editorConfig:o,editorContainerRef:g,fieldProps:r,parentContext:a?.editDepth===c?a:void 0,children:H(It,{providers:o.features.providers,children:H(Ot,{editorConfig:o,editorContainerRef:g,isSmallWidthViewport:n,onChange:i,rtl:l})})})},t+y.editable+u):H("p",{children:"Loading..."})};import{c as mn}from"react/compiler-runtime";import{jsx as oe,jsxs as pn}from"react/jsx-runtime";import{ChevronIcon as gn,Popup as hn,PopupList as Ft}from"@payloadcms/ui";import"react";function Kt(){let e=mn(5),{currentView:t,setCurrentView:o,views:r}=K();if(!r||Object.keys(r).length===0)return null;let n,i;if(e[0]!==t||e[1]!==o||e[2]!==r){i=Symbol.for("react.early_return_sentinel");e:{let s=Object.keys(r);if(!s.some(bn)){i=null;break e}let d=["default",...s.filter(yn)],u=t.charAt(0).toUpperCase()+t.slice(1);n=oe("div",{className:"lexical-view-selector",children:oe(hn,{button:pn("button",{className:"lexical-view-selector__button",type:"button",children:[oe("span",{className:"lexical-view-selector__label",children:u}),oe(gn,{className:"lexical-view-selector__icon"})]}),buttonType:"custom",horizontalAlign:"left",popupType:"menu",render:m=>{let{close:a}=m;return oe(Ft.ButtonGroup,{children:d.map(c=>{let g=c.charAt(0).toUpperCase()+c.slice(1);return oe(Ft.Button,{active:c===t,disabled:c===t,onClick:()=>{o?.(c),a()},children:g},c)})})},size:"large"})})}e[0]=t,e[1]=o,e[2]=r,e[3]=n,e[4]=i}else n=e[3],i=e[4];return i!==Symbol.for("react.early_return_sentinel")?i:n}function yn(e){return e!=="default"}function bn(e){return e!=="default"}var re="rich-text-lexical",On=e=>{let{editorConfig:t,field:o,field:{admin:{className:r,description:n,readOnly:i}={},label:s,localized:l,required:d},path:u,readOnly:m,schemaPath:a,validate:c}=e,{i18n:g}=kn(),y=m||i,f=Dn(),{config:{localization:p}}=Pn(),h=wn({fieldLocalized:l,locale:f,localizationConfig:p||void 0}),C=Rn(),{isControlledByParent:x}=K(),N=Ht((A,ne)=>typeof c=="function"?c(A,{...ne,required:d}):!0,[c,d]),{customComponents:{AfterInput:b,BeforeInput:S,Description:D,Error:_,Label:B}={},disabled:V,initialValue:w,path:k,setValue:I,showError:$,value:T}=_n({potentiallyStalePath:u,validate:N}),q=y||V,[J,Ae]=Wt(!1),[Se,Me]=Wt(),de=zt.useRef(w),F=zt.useRef(T);Vt(()=>{let A=()=>{let ne=window.matchMedia("(max-width: 768px)").matches;ne!==J&&Ae(ne)};return A(),window.addEventListener("resize",A),()=>{window.removeEventListener("resize",A)}},[J]);let L=["field-type",re,r,$&&"error",q&&`${re}--read-only`,t?.admin?.hideGutter!==!0&&!J?`${re}--show-gutter`:null].filter(Boolean).join(" "),P=`${k}.${C}`,ue=$e(),we=Ht(A=>{ue(()=>{let Oe=A.toJSON();F.current=Oe,I(Oe)})},[I,ue]),Yt=An(()=>vn(o),[o]),Gt=Tn(A=>{F.current!==T&&!Ln(F.current!=null?JSON.parse(JSON.stringify(F.current)):F.current,T)&&(de.current=A,F.current=T,Me(new Date))});return Vt(()=>{Object.is(w,de.current)||Gt(w)},[w]),ce("div",{"aria-label":xn(s||"",g),className:L,"data-field-path":k,"data-field-schemapath":a,"data-lexical-view":t?.view,role:"group",style:Yt,children:[ce("div",{className:`${re}__label-row`,children:[B||v(Sn,{hasRequiredAccessibleState:!0,label:s,localized:l,path:k,required:d}),!x&&v(Kt,{})]}),ce("div",{className:`${re}__wrap`,children:[v(jt,{CustomComponent:_,Fallback:v(Nn,{path:k,showError:$})}),ce(Mn,{fallbackRender:Bn,onReset:()=>{},children:[S,v("div",{className:`${re}__editor-content`,children:v(Cn,{modalSlugPrefix:`lexical-${k}`,children:v($t,{composerKey:P,editorConfig:t,fieldProps:e,isSmallWidthViewport:J,onChange:we,readOnly:q,rtl:h,value:T},JSON.stringify({path:k,rerenderProviderKey:Se}))})}),b]}),v(jt,{CustomComponent:D,Fallback:v(En,{description:n,path:k})})]})]},P)};function Bn({error:e}){return ce("div",{className:"errorBoundary",role:"alert",children:[v("p",{children:"Something went wrong:"}),v("pre",{style:{color:"red"},children:e instanceof Error?e.message:String(e)})]})}var sa=On;export{sa as RichText};
2
- //# sourceMappingURL=Field-W2ABOM7M.js.map