@payloadcms/richtext-lexical 4.0.0-beta.2 → 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.
- package/dist/exports/client/Field-334JNLRF.js +2 -0
- package/dist/exports/client/Field-334JNLRF.js.map +7 -0
- package/dist/exports/client/{RelationshipComponent-YCPAKOL7.js → RelationshipComponent-TVK6I4W4.js} +2 -2
- package/dist/exports/client/chunk-BEKGION5.js +2 -0
- package/dist/exports/client/chunk-BEKGION5.js.map +7 -0
- package/dist/exports/client/{chunk-WSAPGI3Z.js → chunk-EA5BHQ2T.js} +1 -1
- package/dist/exports/client/{chunk-WSAPGI3Z.js.map → chunk-EA5BHQ2T.js.map} +1 -1
- package/dist/exports/client/chunk-FAJJXXCW.js +2 -0
- package/dist/exports/client/{chunk-3LRZDIIG.js.map → chunk-FAJJXXCW.js.map} +2 -2
- package/dist/exports/client/{chunk-5VIL27GI.js → chunk-IYBYNEKX.js} +1 -1
- package/dist/exports/client/{chunk-5VIL27GI.js.map → chunk-IYBYNEKX.js.map} +1 -1
- package/dist/exports/client/chunk-SE5IITBK.js +2 -0
- package/dist/exports/client/chunk-SE5IITBK.js.map +7 -0
- package/dist/exports/client/{component-6DQLENIE.js → component-QENB4QTS.js} +2 -2
- package/dist/exports/client/componentInline-AU7IBNY7.js +2 -0
- package/dist/exports/client/index.js +27 -27
- package/dist/exports/client/index.js.map +3 -3
- package/dist/features/align/client/index.js.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockCollapsible.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockEditButton.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockRemoveButton.js.map +1 -1
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +38 -16
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +5 -11
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/getCachedFormStateIfDataMatches.js.map +1 -1
- package/dist/features/blocks/client/plugin/index.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js +121 -78
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js +142 -87
- package/dist/features/blocks/premade/CodeBlock/Component/Code.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/types.js.map +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
- package/dist/features/debug/testRecorder/client/plugin/index.js.map +1 -1
- package/dist/features/debug/treeView/client/plugin/index.js.map +1 -1
- package/dist/features/heading/client/index.js.map +1 -1
- package/dist/features/horizontalRule/client/plugin/index.js.map +1 -1
- package/dist/features/indent/client/index.d.ts.map +1 -1
- package/dist/features/indent/client/index.js +0 -2
- package/dist/features/indent/client/index.js.map +1 -1
- package/dist/features/indent/server/i18n.d.ts.map +1 -1
- package/dist/features/indent/server/i18n.js.map +1 -1
- package/dist/features/link/client/plugins/autoLink/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +10 -2
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/link/client/plugins/link/index.js.map +1 -1
- package/dist/features/link/markdownTransformer.js +2 -2
- package/dist/features/link/markdownTransformer.js.map +1 -1
- package/dist/features/link/server/baseFields.js.map +1 -1
- package/dist/features/lists/shared/schema.d.ts.map +1 -1
- package/dist/features/lists/shared/schema.js.map +1 -1
- package/dist/features/relationship/client/drawer/index.js.map +1 -1
- package/dist/features/relationship/client/plugins/index.js.map +1 -1
- package/dist/features/relationship/client/utils/useEnabledRelationships.js.map +1 -1
- package/dist/features/table/client/plugins/TableActionMenuPlugin/index.css +1 -1
- package/dist/features/table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
- package/dist/features/table/client/plugins/TableCellResizerPlugin/index.js +6 -6
- package/dist/features/table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/table/client/plugins/TablePlugin/index.js +54 -18
- package/dist/features/table/client/plugins/TablePlugin/index.js.map +1 -1
- package/dist/features/table/client/utils/useDebounce.js.map +1 -1
- package/dist/features/textState/defaultColors.js +1 -1
- package/dist/features/textState/defaultColors.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/horizontalWheelScroll.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.js +126 -70
- package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js +67 -35
- package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarButton/index.d.ts.map +1 -1
- package/dist/features/toolbars/shared/ToolbarButton/index.js +26 -2
- package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +137 -72
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js +22 -6
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/features/toolbars/shared/useToolbarKeyboardNavigation.js +100 -70
- package/dist/features/toolbars/shared/useToolbarKeyboardNavigation.js.map +1 -1
- package/dist/features/upload/client/drawer/index.js.map +1 -1
- package/dist/features/upload/client/plugin/index.js.map +1 -1
- package/dist/field/RenderLexical/index.js.map +1 -1
- package/dist/field/ViewSelector.js +12 -4
- package/dist/field/ViewSelector.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/index.js.map +1 -1
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +44 -0
- package/dist/i18n.js.map +1 -1
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/plugins/ClipboardPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js.map +1 -1
- package/dist/lexical/plugins/MarkdownShortcut/index.js.map +1 -1
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +234 -87
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/useMenuTriggerMatch.js.map +1 -1
- package/dist/lexical/plugins/TextPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.css +16 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +126 -38
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.d.ts +7 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.d.ts.map +1 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.js +15 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/moveBlock.js.map +1 -0
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/useKeyboardReordering.d.ts.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/useKeyboardReordering.js +9 -12
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/useKeyboardReordering.js.map +1 -1
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/lexical/utils/nodeFormat.d.ts.map +1 -1
- package/dist/lexical/utils/nodeFormat.js +0 -2
- package/dist/lexical/utils/nodeFormat.js.map +1 -1
- package/dist/lexical/utils/url.d.ts.map +1 -1
- package/dist/lexical/utils/url.js +1 -1
- package/dist/lexical/utils/url.js.map +1 -1
- package/dist/populateGraphQL/populate.js.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/buildEditorState.d.ts.map +1 -1
- package/dist/utilities/buildEditorState.js.map +1 -1
- package/dist/utilities/fieldsDrawer/Drawer.js +36 -36
- package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.js +6 -9
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useDrawerSubmit.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDocumentDrawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDrawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalListDrawer.js.map +1 -1
- package/dist/utilities/initLexicalFeatures.d.ts.map +1 -1
- package/dist/utilities/initLexicalFeatures.js +38 -4
- package/dist/utilities/initLexicalFeatures.js.map +1 -1
- package/dist/utilities/useLexicalFeature.js +15 -6
- package/dist/utilities/useLexicalFeature.js.map +1 -1
- package/dist/utilities/useRunDeprioritized.js.map +1 -1
- package/package.json +32 -35
- package/dist/exports/client/Field-W2ABOM7M.js +0 -2
- package/dist/exports/client/Field-W2ABOM7M.js.map +0 -7
- package/dist/exports/client/chunk-3LRZDIIG.js +0 -2
- package/dist/exports/client/chunk-E6LSRRP2.js +0 -2
- package/dist/exports/client/chunk-E6LSRRP2.js.map +0 -7
- package/dist/exports/client/chunk-ZQX5HXUL.js +0 -2
- package/dist/exports/client/chunk-ZQX5HXUL.js.map +0 -7
- package/dist/exports/client/componentInline-HNE5G4TE.js +0 -2
- /package/dist/exports/client/{RelationshipComponent-YCPAKOL7.js.map → RelationshipComponent-TVK6I4W4.js.map} +0 -0
- /package/dist/exports/client/{component-6DQLENIE.js.map → component-QENB4QTS.js.map} +0 -0
- /package/dist/exports/client/{componentInline-HNE5G4TE.js.map → componentInline-AU7IBNY7.js.map} +0 -0
|
@@ -109,7 +109,7 @@ export const InlineBlockComponent = props => {
|
|
|
109
109
|
isEditor: true,
|
|
110
110
|
isJSXConverter: false,
|
|
111
111
|
nodeKey: nodeKey,
|
|
112
|
-
// eslint-disable-next-line react-
|
|
112
|
+
// eslint-disable-next-line react-hooks/hooks -- intentionally passed as a prop for custom block components to call
|
|
113
113
|
useInlineBlockComponentContext: useInlineBlockComponentContext
|
|
114
114
|
});
|
|
115
115
|
}
|
|
@@ -123,7 +123,7 @@ export const InlineBlockComponent = props => {
|
|
|
123
123
|
isEditor: true,
|
|
124
124
|
isJSXConverter: false,
|
|
125
125
|
nodeKey: nodeKey,
|
|
126
|
-
// eslint-disable-next-line react-
|
|
126
|
+
// eslint-disable-next-line react-hooks/hooks -- intentionally passed as a prop for custom block components to call
|
|
127
127
|
useInlineBlockComponentContext: useInlineBlockComponentContext
|
|
128
128
|
});
|
|
129
129
|
}
|
|
@@ -189,9 +189,7 @@ export const InlineBlockComponent = props => {
|
|
|
189
189
|
fields: true
|
|
190
190
|
},
|
|
191
191
|
docPreferences: await getDocPreferences(),
|
|
192
|
-
documentFormState:
|
|
193
|
-
excludeFiles: true
|
|
194
|
-
}),
|
|
192
|
+
documentFormState: parentDocumentFields,
|
|
195
193
|
globalSlug,
|
|
196
194
|
initialBlockData: formData,
|
|
197
195
|
operation: 'update',
|
|
@@ -244,9 +242,7 @@ export const InlineBlockComponent = props => {
|
|
|
244
242
|
abortAndIgnore(onChangeAbortControllerRef.current);
|
|
245
243
|
const controller = new AbortController();
|
|
246
244
|
onChangeAbortControllerRef.current = controller;
|
|
247
|
-
const blockData = reduceFormStateToBlockData(
|
|
248
|
-
excludeFiles: true
|
|
249
|
-
}), formDataRef.current);
|
|
245
|
+
const blockData = reduceFormStateToBlockData(prevFormState, formDataRef.current);
|
|
250
246
|
const {
|
|
251
247
|
state: state_0
|
|
252
248
|
} = await getFormState({
|
|
@@ -257,9 +253,7 @@ export const InlineBlockComponent = props => {
|
|
|
257
253
|
fields: true
|
|
258
254
|
},
|
|
259
255
|
docPreferences: await getDocPreferences(),
|
|
260
|
-
documentFormState:
|
|
261
|
-
excludeFiles: true
|
|
262
|
-
}),
|
|
256
|
+
documentFormState: parentDocumentFields,
|
|
263
257
|
formState: prevFormState,
|
|
264
258
|
globalSlug,
|
|
265
259
|
initialBlockData: blockData,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useLexicalComposerContext","useLexicalEditable","getTranslation","Button","Drawer","EditDepthProvider","Form","formatDrawerSlug","RenderFields","ShimmerEffect","useConfig","useDocumentForm","useDocumentInfo","useEditDepth","useServerFunctions","useTranslation","abortAndIgnore","$getNodeByKey","SKIP_DOM_SELECTION_TAG","deepCopyObjectSimpleWithoutReactComponents","React","createContext","useCallback","useEffect","useMemo","useRef","v4","uuid","useEditorConfigContext","RegisterFormSubmit","useDrawerSubmit","useLexicalDrawer","getCachedFormStateIfDataMatches","reduceFormStateToBlockData","$isInlineBlockNode","InlineBlockComponentContext","initialState","useInlineBlockComponentContext","use","InlineBlockComponent","props","cacheBuster","className","baseClass","CustomBlock","CustomBlockFromProps","CustomLabel","CustomLabelFromProps","formData","nodeKey","editor","isEditable","i18n","t","createdInlineBlock","fieldProps","featureClientSchemaMap","initialLexicalFormState","schemaPath","setCreatedInlineBlock","uuidFromContext","fields","parentDocumentFields","getFormState","editDepth","firstTimeDrawer","blockType","formDataRef","current","schemaFieldsPath","setInitialState","useState","cachedState","id","cachedFormState","formState","cachedSchemaPath","currentSchemaPath","hasMounted","prevCacheBuster","formUuid","setCustomLabel","undefined","customComponents","BlockLabel","setCustomBlock","Block","resolvedCustomBlock","_jsx","isEditor","isJSXConverter","resolvedCustomLabel","drawerSlug","slug","depth","toggleDrawer","inlineBlockElemElemRef","collectionSlug","getDocPreferences","globalSlug","config","componentMapRenderedBlockPath","clientSchemaMap","blocksField","blockOrSlug","blocks","clientBlock","blocksMap","clientBlockFields","getKey","length","removeInlineBlock","update","remove","blockDisplayName","labels","singular","onChangeAbortControllerRef","AbortController","abortController","awaitInitialState","state","data","docPermissions","docPreferences","documentFormState","excludeFiles","initialBlockData","operation","readOnly","renderAllFields","signal","newFormStateData","node","newData","setFields","tag","onChange","prevFormState","submit","controller","blockData","isStateOutOfSync","Object","keys","some","key","value","onFormSubmit","headerActions","submitRef","RemoveButton","buttonStyle","disabled","icon","onClick","e","preventDefault","stopPropagation","round","size","tooltip","label","EditButton","el","InlineBlockContainer","children","filter","Boolean","join","onKeyDown","role","tabIndex","ref","Label","_jsxs","beforeSubmit","disableValidationOnSubmit","onSubmit","title","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","height","width"],"sources":["../../../../../src/features/blocks/client/componentInline/index.tsx"],"sourcesContent":["'use client'\n\nimport type { BlocksFieldClient, ClientBlock, FormState } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Drawer,\n EditDepthProvider,\n Form,\n formatDrawerSlug,\n RenderFields,\n ShimmerEffect,\n useConfig,\n useDocumentForm,\n useDocumentInfo,\n useEditDepth,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { abortAndIgnore } from '@payloadcms/ui/shared'\nimport { $getNodeByKey, SKIP_DOM_SELECTION_TAG } from 'lexical'\n\nimport './index.css'\nimport '../../../../utilities/fieldsDrawer/index.css'\n\nimport { deepCopyObjectSimpleWithoutReactComponents } from 'payload/shared'\nimport React, { createContext, useCallback, useEffect, useMemo, useRef } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport type { ViewMapInlineBlockComponentProps } from '../../../../types/index.js'\nimport type { InlineBlockFields } from '../../server/schema.js'\nimport type { BlockComponentProps } from '../component/index.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport {\n RegisterFormSubmit,\n useDrawerSubmit,\n} from '../../../../utilities/fieldsDrawer/useDrawerSubmit.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport {\n getCachedFormStateIfDataMatches,\n reduceFormStateToBlockData,\n} from '../getCachedFormStateIfDataMatches.js'\nimport { $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\n\nexport type InlineBlockComponentProps<\n TFormData extends Record<string, unknown> = InlineBlockFields,\n> = {\n readonly CustomBlock?: React.FC<ViewMapInlineBlockComponentProps>\n readonly CustomLabel?: React.FC<ViewMapInlineBlockComponentProps>\n} & Pick<BlockComponentProps<TFormData>, 'cacheBuster' | 'className' | 'formData' | 'nodeKey'>\n\nexport type InlineBlockComponentContextType = {\n EditButton?: React.FC\n initialState: false | FormState | undefined\n InlineBlockContainer?: React.FC<{ children: React.ReactNode }>\n Label?: React.FC\n nodeKey?: string\n RemoveButton?: React.FC\n}\n\nconst InlineBlockComponentContext = createContext<InlineBlockComponentContextType>({\n initialState: false,\n})\n\nexport const useInlineBlockComponentContext = () => React.use(InlineBlockComponentContext)\n\nexport const InlineBlockComponent: React.FC<InlineBlockComponentProps<InlineBlockFields>> = (\n props,\n) => {\n const {\n cacheBuster,\n className: baseClass,\n CustomBlock: CustomBlockFromProps,\n CustomLabel: CustomLabelFromProps,\n formData,\n nodeKey,\n } = props\n\n const [editor] = useLexicalComposerContext()\n const isEditable = useLexicalEditable()\n const { i18n, t } = useTranslation<object, string>()\n const {\n createdInlineBlock,\n fieldProps: { featureClientSchemaMap, initialLexicalFormState, schemaPath },\n setCreatedInlineBlock,\n uuid: uuidFromContext,\n } = useEditorConfigContext()\n const { fields: parentDocumentFields } = useDocumentForm()\n\n const { getFormState } = useServerFunctions()\n const editDepth = useEditDepth()\n const firstTimeDrawer = useRef(false)\n const blockType = formData.blockType\n const formDataRef = useRef(formData)\n formDataRef.current = formData\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockType}.fields`\n\n const [initialState, setInitialState] = React.useState<false | FormState | undefined>(() => {\n // Initial form state that was calculated server-side. May have stale values\n const cachedState = initialLexicalFormState?.[formData.id]\n const cachedFormState = cachedState?.formState\n if (!cachedFormState) {\n return false\n }\n\n return getCachedFormStateIfDataMatches({\n cachedFormState,\n cachedSchemaPath: cachedState.schemaPath,\n currentSchemaPath: schemaFieldsPath,\n formData,\n })\n })\n\n const hasMounted = useRef(false)\n const prevCacheBuster = useRef(cacheBuster)\n useEffect(() => {\n if (hasMounted.current) {\n if (prevCacheBuster.current !== cacheBuster) {\n setInitialState(false)\n }\n prevCacheBuster.current = cacheBuster\n } else {\n hasMounted.current = true\n }\n }, [cacheBuster])\n\n const [formUuid] = React.useState(() => uuid())\n\n // Server-rendered custom components (from admin.components, NOT viewMap).\n // When viewMap components exist, we render them directly with formData instead.\n const [CustomLabel, setCustomLabel] = React.useState<React.ReactNode | undefined>(() => {\n if (CustomLabelFromProps) {\n return undefined\n }\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return initialState?.['_components']?.customComponents?.BlockLabel ?? undefined\n })\n\n const [CustomBlock, setCustomBlock] = React.useState<React.ReactNode | undefined>(() => {\n if (CustomBlockFromProps) {\n return undefined\n }\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return initialState?.['_components']?.customComponents?.Block ?? undefined\n })\n\n const resolvedCustomBlock = useMemo(() => {\n if (CustomBlockFromProps) {\n return (\n <CustomBlockFromProps\n className={baseClass}\n formData={formData}\n isEditor={true}\n isJSXConverter={false}\n nodeKey={nodeKey}\n // eslint-disable-next-line react-compiler/react-compiler -- intentionally passed as a prop for custom block components to call\n useInlineBlockComponentContext={useInlineBlockComponentContext}\n />\n )\n }\n return CustomBlock\n }, [CustomBlockFromProps, baseClass, formData, nodeKey, CustomBlock])\n\n const resolvedCustomLabel = useMemo(() => {\n if (CustomLabelFromProps) {\n return (\n <CustomLabelFromProps\n className={baseClass}\n formData={formData}\n isEditor={true}\n isJSXConverter={false}\n nodeKey={nodeKey}\n // eslint-disable-next-line react-compiler/react-compiler -- intentionally passed as a prop for custom block components to call\n useInlineBlockComponentContext={useInlineBlockComponentContext}\n />\n )\n }\n return CustomLabel\n }, [CustomLabelFromProps, baseClass, formData, nodeKey, CustomLabel])\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-${uuidFromContext}-${formData.id}`,\n depth: editDepth,\n })\n const { toggleDrawer } = useLexicalDrawer(drawerSlug, true)\n\n const inlineBlockElemElemRef = useRef<HTMLDivElement | null>(null)\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n const { config } = useConfig()\n\n const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockType}`\n\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient | undefined = clientSchemaMap?.[\n componentMapRenderedBlockPath\n ]?.[0] as BlocksFieldClient | undefined\n\n const blockOrSlug = blocksField?.blocks?.[0]\n const clientBlock: ClientBlock | undefined =\n typeof blockOrSlug === 'string' ? config.blocksMap[blockOrSlug] : blockOrSlug\n\n const clientBlockFields = clientBlock?.fields ?? []\n\n // Open drawer on \"mount\"\n useEffect(() => {\n if (!firstTimeDrawer.current && createdInlineBlock?.getKey() === nodeKey) {\n // > 2 because they always have \"id\" and \"blockName\" fields\n if (clientBlockFields.length > 2) {\n toggleDrawer()\n }\n setCreatedInlineBlock?.(undefined)\n firstTimeDrawer.current = true\n }\n }, [clientBlockFields.length, createdInlineBlock, nodeKey, setCreatedInlineBlock, toggleDrawer])\n\n const removeInlineBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock?.labels.singular, i18n)\n : clientBlock?.slug\n\n const onChangeAbortControllerRef = useRef(new AbortController())\n\n // Initial state for newly created blocks\n useEffect(() => {\n const abortController = new AbortController()\n\n const awaitInitialState = async () => {\n /*\n * This will only run if a new block is created. For all existing blocks that are loaded when the document is loaded, or when the form is saved,\n * this is not run, as the lexical field RSC will fetch the state server-side and pass it to the client. That way, we avoid unnecessary client-side\n * requests. Though for newly created blocks, we need to fetch the state client-side, as the server doesn't know about the block yet.\n */\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: formData,\n docPermissions: { fields: true },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields, {\n excludeFiles: true,\n }),\n globalSlug,\n initialBlockData: formData,\n operation: 'update',\n readOnly: !isEditable,\n renderAllFields: true,\n schemaPath: schemaFieldsPath,\n signal: abortController.signal,\n })\n\n if (state) {\n const newFormStateData = reduceFormStateToBlockData(\n deepCopyObjectSimpleWithoutReactComponents(state, { excludeFiles: true }),\n ) as InlineBlockFields\n\n // Things like default values may come back from the server => update the node with the new data\n editor.update(\n () => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n const newData = newFormStateData\n newData.blockType = formData.blockType\n\n node.setFields(newData, true)\n }\n },\n // Without this, the outer editor's reconciler resets DOM selection\n // back into its own root, kicking focus out of any nested richText.\n { tag: SKIP_DOM_SELECTION_TAG },\n )\n\n setInitialState(state)\n if (!CustomLabelFromProps) {\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n }\n if (!CustomBlockFromProps) {\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n }\n }\n\n if (clientBlock && formData && !initialState) {\n void awaitInitialState()\n }\n\n return () => {\n abortAndIgnore(abortController)\n }\n }, [\n getFormState,\n editor,\n nodeKey,\n isEditable,\n CustomLabelFromProps,\n CustomBlockFromProps,\n schemaFieldsPath,\n id,\n formData,\n initialState,\n collectionSlug,\n globalSlug,\n getDocPreferences,\n parentDocumentFields,\n clientBlock,\n ])\n\n /**\n * HANDLE ONCHANGE\n */\n const onChange = useCallback(\n async ({ formState: prevFormState, submit }: { formState: FormState; submit?: boolean }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n const blockData = reduceFormStateToBlockData(\n deepCopyObjectSimpleWithoutReactComponents(prevFormState, { excludeFiles: true }),\n formDataRef.current,\n )\n\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: blockData,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields, {\n excludeFiles: true,\n }),\n formState: prevFormState,\n globalSlug,\n initialBlockData: blockData,\n operation: 'update',\n readOnly: !isEditable,\n renderAllFields: submit ? true : false,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n if (!state) {\n return prevFormState\n }\n\n if (submit) {\n if (!CustomLabelFromProps) {\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n }\n if (!CustomBlockFromProps) {\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n }\n\n return state\n },\n [\n getFormState,\n id,\n collectionSlug,\n getDocPreferences,\n parentDocumentFields,\n globalSlug,\n isEditable,\n schemaFieldsPath,\n CustomBlockFromProps,\n CustomLabelFromProps,\n ],\n )\n // cleanup effect\n useEffect(() => {\n const isStateOutOfSync = (formData: InlineBlockFields, initialState: FormState) => {\n return Object.keys(initialState).some(\n (key) => initialState[key] && formData[key] !== initialState[key].value,\n )\n }\n\n return () => {\n // If the component is unmounted (either via removeInlineBlock or via lexical itself) and the form state got changed before,\n // we need to reset the initial state to force a re-fetch of the initial state when it gets mounted again (e.g. via lexical history undo).\n // Otherwise it would use an outdated initial state.\n if (initialState && isStateOutOfSync(formData, initialState)) {\n setInitialState(false)\n }\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [formData, initialState])\n\n /**\n * HANDLE FORM SUBMIT\n */\n const onFormSubmit = useCallback(\n (formState: FormState) => {\n const newData = reduceFormStateToBlockData(formState, formDataRef.current)\n newData.blockType = blockType\n\n editor.update(\n () => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n node.setFields(newData as InlineBlockFields, true)\n }\n },\n // Without this, the outer editor's reconciler resets DOM selection\n // back into its own root, kicking focus out of any nested richText.\n { tag: SKIP_DOM_SELECTION_TAG },\n )\n },\n [blockType, editor, nodeKey],\n )\n\n const { headerActions, submitRef } = useDrawerSubmit()\n\n const RemoveButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"ghost\"\n className={`${baseClass}__removeButton`}\n disabled={!isEditable}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n e.stopPropagation()\n removeInlineBlock()\n }}\n round\n size=\"medium\"\n tooltip={t('lexical:blocks:inlineBlocks:remove', { label: blockDisplayName })}\n />\n ),\n [baseClass, blockDisplayName, isEditable, removeInlineBlock, t],\n )\n\n const EditButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"ghost\"\n className={`${baseClass}__editButton`}\n disabled={!isEditable}\n el=\"button\"\n icon=\"edit\"\n onClick={() => {\n toggleDrawer()\n }}\n round\n size=\"medium\"\n tooltip={t('lexical:blocks:inlineBlocks:edit', { label: blockDisplayName })}\n />\n ),\n [baseClass, blockDisplayName, isEditable, t, toggleDrawer],\n )\n\n const InlineBlockContainer = useMemo(\n () =>\n ({ children, className }: { children: React.ReactNode; className?: string }) => (\n <div\n className={[`${baseClass}__container`, baseClass + '-' + formData.blockType, className]\n .filter(Boolean)\n .join(' ')}\n {...(isEditable\n ? {\n onClick: () => toggleDrawer(),\n onKeyDown: (e: React.KeyboardEvent) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault()\n toggleDrawer()\n }\n },\n role: 'button',\n tabIndex: 0,\n }\n : {})}\n ref={inlineBlockElemElemRef}\n >\n {children}\n </div>\n ),\n [baseClass, formData.blockType, isEditable, toggleDrawer],\n )\n\n const Label = useMemo(() => {\n if (resolvedCustomLabel) {\n return () => resolvedCustomLabel\n } else {\n return () => (\n <div>{clientBlock?.labels ? getTranslation(clientBlock?.labels.singular, i18n) : ''}</div>\n )\n }\n }, [resolvedCustomLabel, clientBlock?.labels, i18n])\n\n if (!clientBlock) {\n return (\n <InlineBlockContainer className={`${baseClass}-not-found`}>\n <span>Error: Block '{formData.blockType}' not found</span>\n {isEditable ? (\n <div className={`${baseClass}__actions`}>\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )\n }\n\n return (\n <Form\n beforeSubmit={[\n async ({ formState }) => {\n // This is only called when form is submitted from drawer\n return await onChange({ formState, submit: true })\n },\n ]}\n disableValidationOnSubmit\n el=\"div\"\n fields={clientBlock?.fields}\n initialState={initialState || {}}\n onChange={[onChange]}\n onSubmit={(formState) => {\n onFormSubmit(formState)\n toggleDrawer()\n }}\n uuid={formUuid}\n >\n <EditDepthProvider>\n <Drawer\n className={''}\n headerActions={headerActions}\n slug={drawerSlug}\n title={t(`lexical:blocks:inlineBlocks:${formData?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n >\n {initialState ? (\n <div className=\"fields-drawer\">\n <RenderFields\n fields={clientBlock?.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 </div>\n ) : null}\n </Drawer>\n </EditDepthProvider>\n {resolvedCustomBlock ? (\n <InlineBlockComponentContext\n value={{\n EditButton,\n initialState,\n InlineBlockContainer,\n Label,\n nodeKey,\n RemoveButton,\n }}\n >\n {resolvedCustomBlock}\n </InlineBlockComponentContext>\n ) : (\n <InlineBlockContainer>\n {initialState ? <Label /> : <ShimmerEffect height=\"15px\" width=\"40px\" />}\n {isEditable ? (\n <div className={`${baseClass}__actions`}>\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )}\n </Form>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,kBAAkB,QAAQ;AACnC,SAASC,cAAc,QAAQ;AAC/B,SACEC,MAAM,EACNC,MAAM,EACNC,iBAAiB,EACjBC,IAAI,EACJC,gBAAgB,EAChBC,YAAY,EACZC,aAAa,EACbC,SAAS,EACTC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,cAAc,QACT;AACP,SAASC,cAAc,QAAQ;AAC/B,SAASC,aAAa,EAAEC,sBAAsB,QAAQ;AAEtD,OAAO;AACP,OAAO;AAEP,SAASC,0CAA0C,QAAQ;AAC3D,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAC9E,SAASC,EAAA,IAAMC,IAAI,QAAQ;AAM3B,SAASC,sBAAsB,QAAQ;AACvC,SACEC,kBAAkB,EAClBC,eAAe,QACV;AACP,SAASC,gBAAgB,QAAQ;AACjC,SACEC,+BAA+B,EAC/BC,0BAA0B,QACrB;AACP,SAASC,kBAAkB,QAAQ;AAkBnC,MAAMC,2BAAA,gBAA8Bd,aAAA,CAA+C;EACjFe,YAAA,EAAc;AAChB;AAEA,OAAO,MAAMC,8BAAA,GAAiCA,CAAA,KAAMjB,KAAA,CAAMkB,GAAG,CAACH,2BAA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AAA,EAAWvG,WAAA;MACTyE,YAAA,CAAazE,WAAA;MACboB,YAAA;IACF;IACApE,IAAA,EAAMqD,QAAA;4BAENQ,IAAA,CAACnF,iBAAA;gBACC,aAAAmF,IAAA,CAACpF,MAAA;QACCsC,SAAA,EAAW;QACX2G,aAAA,EAAeA,aAAA;QACfxD,IAAA,EAAMD,UAAA;QACNuF,KAAA,EAAO9H,CAAA,CAAE,+BAA+BL,QAAA,EAAUyB,EAAA,GAAK,SAAS,UAAU,EAAE;UAC1EyF,KAAA,EAAOhD,gBAAA,IAAoB7D,CAAA,CAAE;QAC/B;kBAECjB,YAAA,gBACC2I,KAAA,CAAC;UAAIrI,SAAA,EAAU;kCACb8C,IAAA,CAAChF,YAAA;YACCqD,MAAA,EAAQ6C,WAAA,EAAa7C,MAAA;YACrBuH,WAAW;YACXC,eAAA,EAAgB;YAChBC,UAAA,EAAW;YACXC,gBAAA,EAAkBlH,gBAAA;YAClBmH,WAAA,EAAa;YACbvD,QAAA,EAAU,CAAC9E;2BAEbqC,IAAA,CAAC3D,kBAAA;YAAmByH,SAAA,EAAWA;;aAE/B;;QAGP/D,mBAAA,gBACCC,IAAA,CAACrD,2BAAA;MACCgH,KAAA,EAAO;QACLgB,UAAA;QACA/H,YAAA;QACAiI,oBAAA;QACAS,KAAA;QACA7H,OAAA;QACAsG;MACF;gBAEChE;sBAGHwF,KAAA,CAACV,oBAAA;iBACEjI,YAAA,gBAAeoD,IAAA,CAACsF,KAAA,qBAAWtF,IAAA,CAAC/E,aAAA;QAAcgL,MAAA,EAAO;QAAOC,KAAA,EAAM;UAC9DvI,UAAA,gBACCqC,IAAA,CAAC;QAAI9C,SAAA,EAAW,GAAGC,SAAA,WAAoB;kBACrC,aAAA6C,IAAA,CAAC+D,YAAA;WAED;;;AAKd","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["useLexicalComposerContext","useLexicalEditable","getTranslation","Button","Drawer","EditDepthProvider","Form","formatDrawerSlug","RenderFields","ShimmerEffect","useConfig","useDocumentForm","useDocumentInfo","useEditDepth","useServerFunctions","useTranslation","abortAndIgnore","$getNodeByKey","SKIP_DOM_SELECTION_TAG","deepCopyObjectSimpleWithoutReactComponents","React","createContext","useCallback","useEffect","useMemo","useRef","v4","uuid","useEditorConfigContext","RegisterFormSubmit","useDrawerSubmit","useLexicalDrawer","getCachedFormStateIfDataMatches","reduceFormStateToBlockData","$isInlineBlockNode","InlineBlockComponentContext","initialState","useInlineBlockComponentContext","use","InlineBlockComponent","props","cacheBuster","className","baseClass","CustomBlock","CustomBlockFromProps","CustomLabel","CustomLabelFromProps","formData","nodeKey","editor","isEditable","i18n","t","createdInlineBlock","fieldProps","featureClientSchemaMap","initialLexicalFormState","schemaPath","setCreatedInlineBlock","uuidFromContext","fields","parentDocumentFields","getFormState","editDepth","firstTimeDrawer","blockType","formDataRef","current","schemaFieldsPath","setInitialState","useState","cachedState","id","cachedFormState","formState","cachedSchemaPath","currentSchemaPath","hasMounted","prevCacheBuster","formUuid","setCustomLabel","undefined","customComponents","BlockLabel","setCustomBlock","Block","resolvedCustomBlock","_jsx","isEditor","isJSXConverter","resolvedCustomLabel","drawerSlug","slug","depth","toggleDrawer","inlineBlockElemElemRef","collectionSlug","getDocPreferences","globalSlug","config","componentMapRenderedBlockPath","clientSchemaMap","blocksField","blockOrSlug","blocks","clientBlock","blocksMap","clientBlockFields","getKey","length","removeInlineBlock","update","remove","blockDisplayName","labels","singular","onChangeAbortControllerRef","AbortController","abortController","awaitInitialState","state","data","docPermissions","docPreferences","documentFormState","initialBlockData","operation","readOnly","renderAllFields","signal","newFormStateData","excludeFiles","node","newData","setFields","tag","onChange","prevFormState","submit","controller","blockData","isStateOutOfSync","Object","keys","some","key","value","onFormSubmit","headerActions","submitRef","RemoveButton","buttonStyle","disabled","icon","onClick","e","preventDefault","stopPropagation","round","size","tooltip","label","EditButton","el","InlineBlockContainer","children","filter","Boolean","join","onKeyDown","role","tabIndex","ref","Label","_jsxs","beforeSubmit","disableValidationOnSubmit","onSubmit","title","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","height","width"],"sources":["../../../../../src/features/blocks/client/componentInline/index.tsx"],"sourcesContent":["'use client'\n\nimport type { BlocksFieldClient, ClientBlock, FormState } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Drawer,\n EditDepthProvider,\n Form,\n formatDrawerSlug,\n RenderFields,\n ShimmerEffect,\n useConfig,\n useDocumentForm,\n useDocumentInfo,\n useEditDepth,\n useServerFunctions,\n useTranslation,\n} from '@payloadcms/ui'\nimport { abortAndIgnore } from '@payloadcms/ui/shared'\nimport { $getNodeByKey, SKIP_DOM_SELECTION_TAG } from 'lexical'\n\nimport './index.css'\nimport '../../../../utilities/fieldsDrawer/index.css'\n\nimport { deepCopyObjectSimpleWithoutReactComponents } from 'payload/shared'\nimport React, { createContext, useCallback, useEffect, useMemo, useRef } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport type { ViewMapInlineBlockComponentProps } from '../../../../types/index.js'\nimport type { InlineBlockFields } from '../../server/schema.js'\nimport type { BlockComponentProps } from '../component/index.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport {\n RegisterFormSubmit,\n useDrawerSubmit,\n} from '../../../../utilities/fieldsDrawer/useDrawerSubmit.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport {\n getCachedFormStateIfDataMatches,\n reduceFormStateToBlockData,\n} from '../getCachedFormStateIfDataMatches.js'\nimport { $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\n\nexport type InlineBlockComponentProps<\n TFormData extends Record<string, unknown> = InlineBlockFields,\n> = {\n readonly CustomBlock?: React.FC<ViewMapInlineBlockComponentProps>\n readonly CustomLabel?: React.FC<ViewMapInlineBlockComponentProps>\n} & Pick<BlockComponentProps<TFormData>, 'cacheBuster' | 'className' | 'formData' | 'nodeKey'>\n\nexport type InlineBlockComponentContextType = {\n EditButton?: React.FC\n initialState: false | FormState | undefined\n InlineBlockContainer?: React.FC<{ children: React.ReactNode }>\n Label?: React.FC\n nodeKey?: string\n RemoveButton?: React.FC\n}\n\nconst InlineBlockComponentContext = createContext<InlineBlockComponentContextType>({\n initialState: false,\n})\n\nexport const useInlineBlockComponentContext = () => React.use(InlineBlockComponentContext)\n\nexport const InlineBlockComponent: React.FC<InlineBlockComponentProps<InlineBlockFields>> = (\n props,\n) => {\n const {\n cacheBuster,\n className: baseClass,\n CustomBlock: CustomBlockFromProps,\n CustomLabel: CustomLabelFromProps,\n formData,\n nodeKey,\n } = props\n\n const [editor] = useLexicalComposerContext()\n const isEditable = useLexicalEditable()\n const { i18n, t } = useTranslation<object, string>()\n const {\n createdInlineBlock,\n fieldProps: { featureClientSchemaMap, initialLexicalFormState, schemaPath },\n setCreatedInlineBlock,\n uuid: uuidFromContext,\n } = useEditorConfigContext()\n const { fields: parentDocumentFields } = useDocumentForm()\n\n const { getFormState } = useServerFunctions()\n const editDepth = useEditDepth()\n const firstTimeDrawer = useRef(false)\n const blockType = formData.blockType\n const formDataRef = useRef(formData)\n formDataRef.current = formData\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockType}.fields`\n\n const [initialState, setInitialState] = React.useState<false | FormState | undefined>(() => {\n // Initial form state that was calculated server-side. May have stale values\n const cachedState = initialLexicalFormState?.[formData.id]\n const cachedFormState = cachedState?.formState\n if (!cachedFormState) {\n return false\n }\n\n return getCachedFormStateIfDataMatches({\n cachedFormState,\n cachedSchemaPath: cachedState.schemaPath,\n currentSchemaPath: schemaFieldsPath,\n formData,\n })\n })\n\n const hasMounted = useRef(false)\n const prevCacheBuster = useRef(cacheBuster)\n useEffect(() => {\n if (hasMounted.current) {\n if (prevCacheBuster.current !== cacheBuster) {\n setInitialState(false)\n }\n prevCacheBuster.current = cacheBuster\n } else {\n hasMounted.current = true\n }\n }, [cacheBuster])\n\n const [formUuid] = React.useState(() => uuid())\n\n // Server-rendered custom components (from admin.components, NOT viewMap).\n // When viewMap components exist, we render them directly with formData instead.\n const [CustomLabel, setCustomLabel] = React.useState<React.ReactNode | undefined>(() => {\n if (CustomLabelFromProps) {\n return undefined\n }\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return initialState?.['_components']?.customComponents?.BlockLabel ?? undefined\n })\n\n const [CustomBlock, setCustomBlock] = React.useState<React.ReactNode | undefined>(() => {\n if (CustomBlockFromProps) {\n return undefined\n }\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return initialState?.['_components']?.customComponents?.Block ?? undefined\n })\n\n const resolvedCustomBlock = useMemo(() => {\n if (CustomBlockFromProps) {\n return (\n <CustomBlockFromProps\n className={baseClass}\n formData={formData}\n isEditor={true}\n isJSXConverter={false}\n nodeKey={nodeKey}\n // eslint-disable-next-line react-hooks/hooks -- intentionally passed as a prop for custom block components to call\n useInlineBlockComponentContext={useInlineBlockComponentContext}\n />\n )\n }\n return CustomBlock\n }, [CustomBlockFromProps, baseClass, formData, nodeKey, CustomBlock])\n\n const resolvedCustomLabel = useMemo(() => {\n if (CustomLabelFromProps) {\n return (\n <CustomLabelFromProps\n className={baseClass}\n formData={formData}\n isEditor={true}\n isJSXConverter={false}\n nodeKey={nodeKey}\n // eslint-disable-next-line react-hooks/hooks -- intentionally passed as a prop for custom block components to call\n useInlineBlockComponentContext={useInlineBlockComponentContext}\n />\n )\n }\n return CustomLabel\n }, [CustomLabelFromProps, baseClass, formData, nodeKey, CustomLabel])\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-${uuidFromContext}-${formData.id}`,\n depth: editDepth,\n })\n const { toggleDrawer } = useLexicalDrawer(drawerSlug, true)\n\n const inlineBlockElemElemRef = useRef<HTMLDivElement | null>(null)\n const { id, collectionSlug, getDocPreferences, globalSlug } = useDocumentInfo()\n const { config } = useConfig()\n\n const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockType}`\n\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient | undefined = clientSchemaMap?.[\n componentMapRenderedBlockPath\n ]?.[0] as BlocksFieldClient | undefined\n\n const blockOrSlug = blocksField?.blocks?.[0]\n const clientBlock: ClientBlock | undefined =\n typeof blockOrSlug === 'string' ? config.blocksMap[blockOrSlug] : blockOrSlug\n\n const clientBlockFields = clientBlock?.fields ?? []\n\n // Open drawer on \"mount\"\n useEffect(() => {\n if (!firstTimeDrawer.current && createdInlineBlock?.getKey() === nodeKey) {\n // > 2 because they always have \"id\" and \"blockName\" fields\n if (clientBlockFields.length > 2) {\n toggleDrawer()\n }\n setCreatedInlineBlock?.(undefined)\n firstTimeDrawer.current = true\n }\n }, [clientBlockFields.length, createdInlineBlock, nodeKey, setCreatedInlineBlock, toggleDrawer])\n\n const removeInlineBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock?.labels.singular, i18n)\n : clientBlock?.slug\n\n const onChangeAbortControllerRef = useRef(new AbortController())\n\n // Initial state for newly created blocks\n useEffect(() => {\n const abortController = new AbortController()\n\n const awaitInitialState = async () => {\n /*\n * This will only run if a new block is created. For all existing blocks that are loaded when the document is loaded, or when the form is saved,\n * this is not run, as the lexical field RSC will fetch the state server-side and pass it to the client. That way, we avoid unnecessary client-side\n * requests. Though for newly created blocks, we need to fetch the state client-side, as the server doesn't know about the block yet.\n */\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: formData,\n docPermissions: { fields: true },\n docPreferences: await getDocPreferences(),\n documentFormState: parentDocumentFields,\n globalSlug,\n initialBlockData: formData,\n operation: 'update',\n readOnly: !isEditable,\n renderAllFields: true,\n schemaPath: schemaFieldsPath,\n signal: abortController.signal,\n })\n\n if (state) {\n const newFormStateData = reduceFormStateToBlockData(\n deepCopyObjectSimpleWithoutReactComponents(state, { excludeFiles: true }),\n ) as InlineBlockFields\n\n // Things like default values may come back from the server => update the node with the new data\n editor.update(\n () => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n const newData = newFormStateData\n newData.blockType = formData.blockType\n\n node.setFields(newData, true)\n }\n },\n // Without this, the outer editor's reconciler resets DOM selection\n // back into its own root, kicking focus out of any nested richText.\n { tag: SKIP_DOM_SELECTION_TAG },\n )\n\n setInitialState(state)\n if (!CustomLabelFromProps) {\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n }\n if (!CustomBlockFromProps) {\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n }\n }\n\n if (clientBlock && formData && !initialState) {\n void awaitInitialState()\n }\n\n return () => {\n abortAndIgnore(abortController)\n }\n }, [\n getFormState,\n editor,\n nodeKey,\n isEditable,\n CustomLabelFromProps,\n CustomBlockFromProps,\n schemaFieldsPath,\n id,\n formData,\n initialState,\n collectionSlug,\n globalSlug,\n getDocPreferences,\n parentDocumentFields,\n clientBlock,\n ])\n\n /**\n * HANDLE ONCHANGE\n */\n const onChange = useCallback(\n async ({ formState: prevFormState, submit }: { formState: FormState; submit?: boolean }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n const blockData = reduceFormStateToBlockData(prevFormState, formDataRef.current)\n\n const { state } = await getFormState({\n id,\n collectionSlug,\n data: blockData,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: parentDocumentFields,\n formState: prevFormState,\n globalSlug,\n initialBlockData: blockData,\n operation: 'update',\n readOnly: !isEditable,\n renderAllFields: submit ? true : false,\n schemaPath: schemaFieldsPath,\n signal: controller.signal,\n })\n\n if (!state) {\n return prevFormState\n }\n\n if (submit) {\n if (!CustomLabelFromProps) {\n setCustomLabel(state['_components']?.customComponents?.BlockLabel)\n }\n if (!CustomBlockFromProps) {\n setCustomBlock(state['_components']?.customComponents?.Block)\n }\n }\n\n return state\n },\n [\n getFormState,\n id,\n collectionSlug,\n getDocPreferences,\n parentDocumentFields,\n globalSlug,\n isEditable,\n schemaFieldsPath,\n CustomBlockFromProps,\n CustomLabelFromProps,\n ],\n )\n // cleanup effect\n useEffect(() => {\n const isStateOutOfSync = (formData: InlineBlockFields, initialState: FormState) => {\n return Object.keys(initialState).some(\n (key) => initialState[key] && formData[key] !== initialState[key].value,\n )\n }\n\n return () => {\n // If the component is unmounted (either via removeInlineBlock or via lexical itself) and the form state got changed before,\n // we need to reset the initial state to force a re-fetch of the initial state when it gets mounted again (e.g. via lexical history undo).\n // Otherwise it would use an outdated initial state.\n if (initialState && isStateOutOfSync(formData, initialState)) {\n setInitialState(false)\n }\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [formData, initialState])\n\n /**\n * HANDLE FORM SUBMIT\n */\n const onFormSubmit = useCallback(\n (formState: FormState) => {\n const newData = reduceFormStateToBlockData(formState, formDataRef.current)\n newData.blockType = blockType\n\n editor.update(\n () => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isInlineBlockNode(node)) {\n node.setFields(newData as InlineBlockFields, true)\n }\n },\n // Without this, the outer editor's reconciler resets DOM selection\n // back into its own root, kicking focus out of any nested richText.\n { tag: SKIP_DOM_SELECTION_TAG },\n )\n },\n [blockType, editor, nodeKey],\n )\n\n const { headerActions, submitRef } = useDrawerSubmit()\n\n const RemoveButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"ghost\"\n className={`${baseClass}__removeButton`}\n disabled={!isEditable}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n e.stopPropagation()\n removeInlineBlock()\n }}\n round\n size=\"medium\"\n tooltip={t('lexical:blocks:inlineBlocks:remove', { label: blockDisplayName })}\n />\n ),\n [baseClass, blockDisplayName, isEditable, removeInlineBlock, t],\n )\n\n const EditButton = useMemo(\n () => () => (\n <Button\n buttonStyle=\"ghost\"\n className={`${baseClass}__editButton`}\n disabled={!isEditable}\n el=\"button\"\n icon=\"edit\"\n onClick={() => {\n toggleDrawer()\n }}\n round\n size=\"medium\"\n tooltip={t('lexical:blocks:inlineBlocks:edit', { label: blockDisplayName })}\n />\n ),\n [baseClass, blockDisplayName, isEditable, t, toggleDrawer],\n )\n\n const InlineBlockContainer = useMemo(\n () =>\n ({ children, className }: { children: React.ReactNode; className?: string }) => (\n <div\n className={[`${baseClass}__container`, baseClass + '-' + formData.blockType, className]\n .filter(Boolean)\n .join(' ')}\n {...(isEditable\n ? {\n onClick: () => toggleDrawer(),\n onKeyDown: (e: React.KeyboardEvent) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault()\n toggleDrawer()\n }\n },\n role: 'button',\n tabIndex: 0,\n }\n : {})}\n ref={inlineBlockElemElemRef}\n >\n {children}\n </div>\n ),\n [baseClass, formData.blockType, isEditable, toggleDrawer],\n )\n\n const Label = useMemo(() => {\n if (resolvedCustomLabel) {\n return () => resolvedCustomLabel\n } else {\n return () => (\n <div>{clientBlock?.labels ? getTranslation(clientBlock?.labels.singular, i18n) : ''}</div>\n )\n }\n }, [resolvedCustomLabel, clientBlock?.labels, i18n])\n\n if (!clientBlock) {\n return (\n <InlineBlockContainer className={`${baseClass}-not-found`}>\n <span>Error: Block '{formData.blockType}' not found</span>\n {isEditable ? (\n <div className={`${baseClass}__actions`}>\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )\n }\n\n return (\n <Form\n beforeSubmit={[\n async ({ formState }) => {\n // This is only called when form is submitted from drawer\n return await onChange({ formState, submit: true })\n },\n ]}\n disableValidationOnSubmit\n el=\"div\"\n fields={clientBlock?.fields}\n initialState={initialState || {}}\n onChange={[onChange]}\n onSubmit={(formState) => {\n onFormSubmit(formState)\n toggleDrawer()\n }}\n uuid={formUuid}\n >\n <EditDepthProvider>\n <Drawer\n className={''}\n headerActions={headerActions}\n slug={drawerSlug}\n title={t(`lexical:blocks:inlineBlocks:${formData?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n >\n {initialState ? (\n <div className=\"fields-drawer\">\n <RenderFields\n fields={clientBlock?.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 </div>\n ) : null}\n </Drawer>\n </EditDepthProvider>\n {resolvedCustomBlock ? (\n <InlineBlockComponentContext\n value={{\n EditButton,\n initialState,\n InlineBlockContainer,\n Label,\n nodeKey,\n RemoveButton,\n }}\n >\n {resolvedCustomBlock}\n </InlineBlockComponentContext>\n ) : (\n <InlineBlockContainer>\n {initialState ? <Label /> : <ShimmerEffect height=\"15px\" width=\"40px\" />}\n {isEditable ? (\n <div className={`${baseClass}__actions`}>\n <RemoveButton />\n </div>\n ) : null}\n </InlineBlockContainer>\n )}\n </Form>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,kBAAkB,QAAQ;AACnC,SAASC,cAAc,QAAQ;AAC/B,SACEC,MAAM,EACNC,MAAM,EACNC,iBAAiB,EACjBC,IAAI,EACJC,gBAAgB,EAChBC,YAAY,EACZC,aAAa,EACbC,SAAS,EACTC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,cAAc,QACT;AACP,SAASC,cAAc,QAAQ;AAC/B,SAASC,aAAa,EAAEC,sBAAsB,QAAQ;AAEtD,OAAO;AACP,OAAO;AAEP,SAASC,0CAA0C,QAAQ;AAC3D,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAC9E,SAASC,EAAA,IAAMC,IAAI,QAAQ;AAM3B,SAASC,sBAAsB,QAAQ;AACvC,SACEC,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d","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCachedFormStateIfDataMatches.js","names":["dequal","reduceFieldsToValues","getCachedFormStateIfDataMatches","cachedFormState","cachedSchemaPath","currentSchemaPath","formData","cachedData","reduceFormStateToBlockData","currentData","normalizeData","data","rowFieldPaths","getRowFieldPaths","withoutSystemBlockFields","formState","formStateWithoutRowCounts","Object","fromEntries","entries","map","path","fieldState","Array","isArray","rows","value","undefined","disableFormData","isModified","length","getValueAtPath","Set","split","reduce","pathSegment","filter","parentPath","normalizedData","key","normalizedValue","normalizeValue","has","item","index","getPrototypeOf","prototype","blockName","_blockName","blockType","_blockType"],"sources":["../../../../src/features/blocks/client/getCachedFormStateIfDataMatches.ts"],"sourcesContent":["import type { Data, FormState } from 'payload'\n\nimport { dequal } from 'dequal/lite'\nimport { reduceFieldsToValues } from 'payload/shared'\n\nexport const getCachedFormStateIfDataMatches = ({\n cachedFormState,\n cachedSchemaPath,\n currentSchemaPath,\n formData,\n}: {\n cachedFormState: FormState\n cachedSchemaPath?: string\n currentSchemaPath?: string\n formData: Data\n}): false | FormState => {\n if (cachedSchemaPath !== currentSchemaPath) {\n return false\n }\n\n const cachedData = reduceFormStateToBlockData(cachedFormState)\n const currentData = normalizeData({\n data: formData,\n rowFieldPaths: getRowFieldPaths(cachedFormState),\n })\n\n return dequal(withoutSystemBlockFields(cachedData), withoutSystemBlockFields(currentData))\n ? cachedFormState\n : false\n}\n\nexport const reduceFormStateToBlockData = (formState: FormState, currentData?: Data): Data => {\n const formStateWithoutRowCounts = Object.fromEntries(\n Object.entries(formState).map(([path, fieldState]) => {\n if (!fieldState || !Array.isArray(fieldState.rows)) {\n return [path, fieldState]\n }\n\n if (\n fieldState.value === undefined ||\n (fieldState.disableFormData !== false &&\n fieldState.isModified !== true &&\n fieldState.rows.length === 0 &&\n getValueAtPath(currentData, path) === null)\n ) {\n return [path, { ...fieldState, value: null }]\n }\n\n return [\n path,\n fieldState.value === null ? fieldState : { ...fieldState, disableFormData: true },\n ]\n }),\n )
|
|
1
|
+
{"version":3,"file":"getCachedFormStateIfDataMatches.js","names":["dequal","reduceFieldsToValues","getCachedFormStateIfDataMatches","cachedFormState","cachedSchemaPath","currentSchemaPath","formData","cachedData","reduceFormStateToBlockData","currentData","normalizeData","data","rowFieldPaths","getRowFieldPaths","withoutSystemBlockFields","formState","formStateWithoutRowCounts","Object","fromEntries","entries","map","path","fieldState","Array","isArray","rows","value","undefined","disableFormData","isModified","length","getValueAtPath","Set","split","reduce","pathSegment","filter","parentPath","normalizedData","key","normalizedValue","normalizeValue","has","item","index","getPrototypeOf","prototype","blockName","_blockName","blockType","_blockType"],"sources":["../../../../src/features/blocks/client/getCachedFormStateIfDataMatches.ts"],"sourcesContent":["import type { Data, FormState } from 'payload'\n\nimport { dequal } from 'dequal/lite'\nimport { reduceFieldsToValues } from 'payload/shared'\n\nexport const getCachedFormStateIfDataMatches = ({\n cachedFormState,\n cachedSchemaPath,\n currentSchemaPath,\n formData,\n}: {\n cachedFormState: FormState\n cachedSchemaPath?: string\n currentSchemaPath?: string\n formData: Data\n}): false | FormState => {\n if (cachedSchemaPath !== currentSchemaPath) {\n return false\n }\n\n const cachedData = reduceFormStateToBlockData(cachedFormState)\n const currentData = normalizeData({\n data: formData,\n rowFieldPaths: getRowFieldPaths(cachedFormState),\n })\n\n return dequal(withoutSystemBlockFields(cachedData), withoutSystemBlockFields(currentData))\n ? cachedFormState\n : false\n}\n\nexport const reduceFormStateToBlockData = (formState: FormState, currentData?: Data): Data => {\n const formStateWithoutRowCounts = Object.fromEntries(\n Object.entries(formState).map(([path, fieldState]) => {\n if (!fieldState || !Array.isArray(fieldState.rows)) {\n return [path, fieldState]\n }\n\n if (\n fieldState.value === undefined ||\n (fieldState.disableFormData !== false &&\n fieldState.isModified !== true &&\n fieldState.rows.length === 0 &&\n getValueAtPath(currentData, path) === null)\n ) {\n return [path, { ...fieldState, value: null }]\n }\n\n return [\n path,\n fieldState.value === null ? fieldState : { ...fieldState, disableFormData: true },\n ]\n }),\n )\n\n return normalizeData({\n data: reduceFieldsToValues(formStateWithoutRowCounts, true),\n rowFieldPaths: new Set(),\n })\n}\n\nconst getValueAtPath = (data: Data | undefined, path: string): unknown =>\n path.split('.').reduce<unknown>((value, pathSegment) => {\n if (!value || typeof value !== 'object') {\n return undefined\n }\n\n return (value as Record<string, unknown>)[pathSegment]\n }, data)\n\nconst getRowFieldPaths = (formState: FormState): Set<string> =>\n new Set(\n Object.entries(formState)\n .filter(\n ([, fieldState]) =>\n Array.isArray(fieldState?.rows) &&\n fieldState.value !== null &&\n fieldState.value !== undefined,\n )\n .map(([path]) => path),\n )\n\nconst normalizeData = ({\n data,\n parentPath = '',\n rowFieldPaths,\n}: {\n data: Data\n parentPath?: string\n rowFieldPaths: Set<string>\n}): Data => {\n const normalizedData: Data = {}\n\n for (const [key, value] of Object.entries(data)) {\n const path = parentPath ? `${parentPath}.${key}` : key\n const normalizedValue = normalizeValue({ parentPath: path, rowFieldPaths, value })\n\n if (normalizedValue !== undefined) {\n normalizedData[key] = normalizedValue\n }\n }\n\n return normalizedData\n}\n\nconst normalizeValue = ({\n parentPath,\n rowFieldPaths,\n value,\n}: {\n parentPath: string\n rowFieldPaths: Set<string>\n value: unknown\n}): unknown => {\n if (\n value === undefined ||\n (Array.isArray(value) && value.length === 0 && rowFieldPaths.has(parentPath))\n ) {\n return undefined\n }\n\n if (Array.isArray(value)) {\n return value.map((item, index) =>\n item && typeof item === 'object' && !Array.isArray(item)\n ? normalizeData({\n data: item as Data,\n parentPath: `${parentPath}.${index}`,\n rowFieldPaths,\n })\n : item,\n )\n }\n\n if (value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {\n return normalizeData({ data: value, parentPath, rowFieldPaths })\n }\n\n return value\n}\n\nconst withoutSystemBlockFields = ({\n blockName: _blockName,\n blockType: _blockType,\n ...data\n}: Data): Data => data\n"],"mappings":"AAEA,SAASA,MAAM,QAAQ;AACvB,SAASC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cAAA,GAAiBA,CAAC;EACtBJ,UAAU;EACVzB,aAAa;EACbc;AAAK,CAKN;EACC,IACEA,KAAA,KAAUC,SAAA,IACTJ,KAAA,CAAMC,OAAO,CAACE,KAAA,KAAUA,KAAA,CAAMI,MAAM,KAAK,KAAKlB,aAAA,CAAc8B,GAAG,CAACL,UAAA,GACjE;IACA,OAAOV,SAAA;EACT;EAEA,IAAIJ,KAAA,CAAMC,OAAO,CAACE,KAAA,GAAQ;IACxB,OAAOA,KAAA,CAAMN,GAAG,CAAC,CAACuB,IAAA,EAAMC,KAAA,KACtBD,IAAA,IAAQ,OAAOA,IAAA,KAAS,YAAY,CAACpB,KAAA,CAAMC,OAAO,CAACmB,IAAA,IAC/CjC,aAAA,CAAc;MACZC,IAAA,EAAMgC,IAAA;MACNN,UAAA,EAAY,GAAGA,UAAA,IAAcO,KAAA,EAAO;MACpChC;IACF,KACA+B,IAAA;EAER;EAEA,IAAIjB,KAAA,IAAS,OAAOA,KAAA,KAAU,YAAYT,MAAA,CAAO4B,cAAc,CAACnB,KAAA,MAAWT,MAAA,CAAO6B,SAAS,EAAE;IAC3F,OAAOpC,aAAA,CAAc;MAAEC,IAAA,EAAMe,KAAA;MAAOW,UAAA;MAAYzB;IAAc;EAChE;EAEA,OAAOc,KAAA;AACT;AAEA,MAAMZ,wBAAA,GAA2BA,CAAC;EAChCiC,SAAA,EAAWC,UAAU;EACrBC,SAAA,EAAWC,UAAU;EACrB,GAAGvC;AAAA,CACE,KAAWA,IAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$insertNodeToNearestRoot","$wrapNodeInElement","mergeRegister","formatDrawerSlug","useEditDepth","$createParagraphNode","$getNodeByKey","$getPreviousSelection","$getSelection","$insertNodes","$isParagraphNode","$isRangeSelection","$isRootOrShadowRoot","COMMAND_PRIORITY_EDITOR","useEffect","useState","useEditorConfigContext","useLexicalDrawer","$createBlockNode","BlockNode","$createInlineBlockNode","$isInlineBlockNode","INSERT_BLOCK_COMMAND","INSERT_INLINE_BLOCK_COMMAND","BlocksPlugin","$","editor","targetNodeKey","setTargetNodeKey","setCreatedInlineBlock","uuid","editDepth","t0","t1","slug","depth","drawerSlug","toggleDrawer","t2","hasNodes","Error","registerCommand","payload","update","selection","blockNode","focus","focusNode","getNode","__first","remove","fields","node","setFields","inlineBlockNode","getParentOrThrow","selectEnd","t3"],"sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@lexical/utils'\nimport { formatDrawerSlug, useEditDepth } from '@payloadcms/ui'\nimport {\n $createParagraphNode,\n $getNodeByKey,\n $getPreviousSelection,\n $getSelection,\n $insertNodes,\n $isParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n COMMAND_PRIORITY_EDITOR,\n} from 'lexical'\nimport { useEffect, useState } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { BlockFields, BlockFieldsOptionalID } from '../../server/schema.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js'\nimport { $createInlineBlockNode, $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\nimport { INSERT_BLOCK_COMMAND, INSERT_INLINE_BLOCK_COMMAND } from './commands.js'\n\nexport type InsertBlockPayload = BlockFieldsOptionalID\n\nexport const BlocksPlugin: PluginComponent = () => {\n const [editor] = useLexicalComposerContext()\n\n const [targetNodeKey, setTargetNodeKey] = useState<null | string>(null)\n\n const { setCreatedInlineBlock, uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-` + uuid,\n depth: editDepth,\n })\n\n const { toggleDrawer } = useLexicalDrawer(drawerSlug, true)\n\n useEffect(() => {\n if (!editor.hasNodes([BlockNode])) {\n throw new Error('BlocksPlugin: BlocksNode not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand<InsertBlockPayload>(\n INSERT_BLOCK_COMMAND,\n (payload: InsertBlockPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const blockNode = $createBlockNode(payload)\n\n // we need to get the focus node before inserting the block node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert blocks node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(blockNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n INSERT_INLINE_BLOCK_COMMAND,\n (fields) => {\n if (targetNodeKey) {\n const node = $getNodeByKey(targetNodeKey)\n\n if (!node || !$isInlineBlockNode(node)) {\n return false\n }\n\n node.setFields(fields as BlockFields)\n\n setTargetNodeKey(null)\n return true\n }\n\n const inlineBlockNode = $createInlineBlockNode(fields as BlockFields)\n setCreatedInlineBlock?.(inlineBlockNode)\n $insertNodes([inlineBlockNode])\n if ($isRootOrShadowRoot(inlineBlockNode.getParentOrThrow())) {\n $wrapNodeInElement(inlineBlockNode, $createParagraphNode).selectEnd()\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [editor, setCreatedInlineBlock, targetNodeKey, toggleDrawer])\n\n return null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAEA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,wBAAwB,EAAEC,kBAAkB,EAAEC,aAAa,QAAQ;AAC5E,SAASC,gBAAgB,EAAEC,YAAY,QAAQ;AAC/C,SACEC,oBAAoB,EACpBC,aAAa,EACbC,qBAAqB,EACrBC,aAAa,EACbC,YAAY,EACZC,gBAAgB,EAChBC,iBAAiB,EACjBC,mBAAmB,EACnBC,uBAAuB,QAClB;AACP,SAASC,SAAS,EAAEC,QAAQ,QAAQ;AAKpC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,gBAAgB,EAAEC,SAAS,QAAQ;AAC5C,SAASC,sBAAsB,EAAEC,kBAAkB,QAAQ;AAC3D,SAASC,oBAAoB,EAAEC,2BAA2B,QAAQ;AAIlE,OAAO,MAAMC,YAAA,GAAgCA,CAAA;EAAA,MAAAC,CAAA,GAAA3B,EAAA;EAC3C,OAAA4B,MAAA,IAAiB3B,yBAAA;EAEjB,OAAA4B,aAAA,EAAAC,gBAAA,IAA0Cb,QAAA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$insertNodeToNearestRoot","$wrapNodeInElement","mergeRegister","formatDrawerSlug","useEditDepth","$createParagraphNode","$getNodeByKey","$getPreviousSelection","$getSelection","$insertNodes","$isParagraphNode","$isRangeSelection","$isRootOrShadowRoot","COMMAND_PRIORITY_EDITOR","useEffect","useState","useEditorConfigContext","useLexicalDrawer","$createBlockNode","BlockNode","$createInlineBlockNode","$isInlineBlockNode","INSERT_BLOCK_COMMAND","INSERT_INLINE_BLOCK_COMMAND","BlocksPlugin","$","editor","targetNodeKey","setTargetNodeKey","setCreatedInlineBlock","uuid","editDepth","t0","t1","slug","depth","drawerSlug","toggleDrawer","t2","hasNodes","Error","registerCommand","payload","update","selection","blockNode","focus","focusNode","getNode","__first","remove","fields","node","setFields","inlineBlockNode","getParentOrThrow","selectEnd","t3"],"sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@lexical/utils'\nimport { formatDrawerSlug, useEditDepth } from '@payloadcms/ui'\nimport {\n $createParagraphNode,\n $getNodeByKey,\n $getPreviousSelection,\n $getSelection,\n $insertNodes,\n $isParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n COMMAND_PRIORITY_EDITOR,\n} from 'lexical'\nimport { useEffect, useState } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { BlockFields, BlockFieldsOptionalID } from '../../server/schema.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js'\nimport { $createInlineBlockNode, $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\nimport { INSERT_BLOCK_COMMAND, INSERT_INLINE_BLOCK_COMMAND } from './commands.js'\n\nexport type InsertBlockPayload = BlockFieldsOptionalID\n\nexport const BlocksPlugin: PluginComponent = () => {\n const [editor] = useLexicalComposerContext()\n\n const [targetNodeKey, setTargetNodeKey] = useState<null | string>(null)\n\n const { setCreatedInlineBlock, uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-` + uuid,\n depth: editDepth,\n })\n\n const { toggleDrawer } = useLexicalDrawer(drawerSlug, true)\n\n useEffect(() => {\n if (!editor.hasNodes([BlockNode])) {\n throw new Error('BlocksPlugin: BlocksNode not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand<InsertBlockPayload>(\n INSERT_BLOCK_COMMAND,\n (payload: InsertBlockPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const blockNode = $createBlockNode(payload)\n\n // we need to get the focus node before inserting the block node, as $insertNodeToNearestRoot can change the focus node\n const { focus } = selection\n const focusNode = focus.getNode()\n // Insert blocks node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(blockNode)\n\n // Delete the node it it's an empty paragraph\n if ($isParagraphNode(focusNode) && !focusNode.__first) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n INSERT_INLINE_BLOCK_COMMAND,\n (fields) => {\n if (targetNodeKey) {\n const node = $getNodeByKey(targetNodeKey)\n\n if (!node || !$isInlineBlockNode(node)) {\n return false\n }\n\n node.setFields(fields as BlockFields)\n\n setTargetNodeKey(null)\n return true\n }\n\n const inlineBlockNode = $createInlineBlockNode(fields as BlockFields)\n setCreatedInlineBlock?.(inlineBlockNode)\n $insertNodes([inlineBlockNode])\n if ($isRootOrShadowRoot(inlineBlockNode.getParentOrThrow())) {\n $wrapNodeInElement(inlineBlockNode, $createParagraphNode).selectEnd()\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [editor, setCreatedInlineBlock, targetNodeKey, toggleDrawer])\n\n return null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;AAEA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,wBAAwB,EAAEC,kBAAkB,EAAEC,aAAa,QAAQ;AAC5E,SAASC,gBAAgB,EAAEC,YAAY,QAAQ;AAC/C,SACEC,oBAAoB,EACpBC,aAAa,EACbC,qBAAqB,EACrBC,aAAa,EACbC,YAAY,EACZC,gBAAgB,EAChBC,iBAAiB,EACjBC,mBAAmB,EACnBC,uBAAuB,QAClB;AACP,SAASC,SAAS,EAAEC,QAAQ,QAAQ;AAKpC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,gBAAgB,EAAEC,SAAS,QAAQ;AAC5C,SAASC,sBAAsB,EAAEC,kBAAkB,QAAQ;AAC3D,SAASC,oBAAoB,EAAEC,2BAA2B,QAAQ;AAIlE,OAAO,MAAMC,YAAA,GAAgCA,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Y,YAAA;IAAAZ,CAAA,OAAAgC,EAAA;EAAA;IAAAA,EAAA,GAAAhC,CAAA;EAAA;EA5D/DX,SAAA,CAAUwB,EA4DV,EAAGmB,EAA4D;EAAA,OAExD;AAAA,CACT","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
3
4
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
5
|
import './index.css';
|
|
5
6
|
import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
|
|
@@ -12,6 +13,7 @@ import { defaultLanguages } from './defaultLanguages.js';
|
|
|
12
13
|
import { FloatingCollapse } from './FloatingCollapse/index.js';
|
|
13
14
|
const baseClass = 'payload-richtext-code-block';
|
|
14
15
|
export const CodeBlockBlockComponent = args => {
|
|
16
|
+
const $ = _c(15);
|
|
15
17
|
const {
|
|
16
18
|
languages: languagesFromProps
|
|
17
19
|
} = args;
|
|
@@ -29,90 +31,131 @@ export const CodeBlockBlockComponent = args => {
|
|
|
29
31
|
} = useTranslation();
|
|
30
32
|
const {
|
|
31
33
|
codeField
|
|
32
|
-
} = useFormFields(
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
} = useFormFields(_temp);
|
|
35
|
+
let t0;
|
|
36
|
+
if ($[0] !== setModified) {
|
|
37
|
+
t0 = t1 => {
|
|
38
|
+
const [fields_0, dispatch] = t1;
|
|
39
|
+
return {
|
|
40
|
+
selectedLanguageField: fields_0?.language,
|
|
41
|
+
setSelectedLanguage: language => {
|
|
42
|
+
dispatch({
|
|
43
|
+
type: "UPDATE",
|
|
44
|
+
path: "language",
|
|
45
|
+
value: language
|
|
46
|
+
});
|
|
47
|
+
setModified(true);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
$[0] = setModified;
|
|
52
|
+
$[1] = t0;
|
|
53
|
+
} else {
|
|
54
|
+
t0 = $[1];
|
|
55
|
+
}
|
|
35
56
|
const {
|
|
36
57
|
selectedLanguageField,
|
|
37
58
|
setSelectedLanguage
|
|
38
|
-
} = useFormFields(
|
|
39
|
-
selectedLanguageField: fields_0?.language,
|
|
40
|
-
setSelectedLanguage: language => {
|
|
41
|
-
dispatch({
|
|
42
|
-
type: 'UPDATE',
|
|
43
|
-
path: 'language',
|
|
44
|
-
value: language
|
|
45
|
-
});
|
|
46
|
-
setModified(true);
|
|
47
|
-
}
|
|
48
|
-
}));
|
|
59
|
+
} = useFormFields(t0);
|
|
49
60
|
const selectedLanguageLabel = languages[selectedLanguageField?.value];
|
|
50
61
|
const isEditable = useLexicalEditable();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
children:
|
|
62
|
+
let t1;
|
|
63
|
+
if ($[2] !== languages || $[3] !== setSelectedLanguage) {
|
|
64
|
+
t1 = Object.entries(languages).map(t2 => {
|
|
65
|
+
const [languageCode, languageLabel] = t2;
|
|
66
|
+
return {
|
|
67
|
+
name: `${languageCode} ${languageLabel}`,
|
|
68
|
+
Component: _jsx(PopupList.Button, {
|
|
69
|
+
active: false,
|
|
70
|
+
disabled: false,
|
|
71
|
+
onClick: () => {
|
|
72
|
+
setSelectedLanguage(languageCode);
|
|
73
|
+
},
|
|
74
|
+
children: _jsx("span", {
|
|
75
|
+
className: `${baseClass}__language-code`,
|
|
76
|
+
"data-language": languageCode,
|
|
77
|
+
children: languageLabel
|
|
78
|
+
})
|
|
64
79
|
})
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
$[2] = languages;
|
|
83
|
+
$[3] = setSelectedLanguage;
|
|
84
|
+
$[4] = t1;
|
|
85
|
+
} else {
|
|
86
|
+
t1 = $[4];
|
|
87
|
+
}
|
|
88
|
+
const languageEntries = t1;
|
|
89
|
+
let t2;
|
|
90
|
+
if ($[5] !== BlockCollapsible || $[6] !== RemoveButton || $[7] !== codeField?.value || $[8] !== formSchema || $[9] !== isEditable || $[10] !== languageEntries || $[11] !== selectedLanguageField?.value || $[12] !== selectedLanguageLabel || $[13] !== t) {
|
|
91
|
+
t2 = _jsx(BlockCollapsible, {
|
|
92
|
+
Actions: _jsxs("div", {
|
|
93
|
+
className: `${baseClass}__actions`,
|
|
94
|
+
children: [_jsx(Combobox, {
|
|
95
|
+
"aria-label": t("general:language"),
|
|
96
|
+
button: _jsxs("div", {
|
|
97
|
+
className: `${baseClass}__language-selector-button`,
|
|
98
|
+
"data-selected-language": selectedLanguageField?.value,
|
|
99
|
+
children: [_jsx("span", {
|
|
100
|
+
children: selectedLanguageLabel
|
|
101
|
+
}), _jsx(ChevronIcon, {
|
|
102
|
+
className: `${baseClass}__chevron`
|
|
103
|
+
})]
|
|
104
|
+
}),
|
|
105
|
+
buttonType: "custom",
|
|
106
|
+
className: `${baseClass}__language-selector`,
|
|
107
|
+
disabled: !isEditable,
|
|
108
|
+
entries: languageEntries,
|
|
109
|
+
horizontalAlign: "right",
|
|
110
|
+
minEntriesForSearch: 8,
|
|
111
|
+
searchPlaceholder: t("fields:searchForLanguage"),
|
|
112
|
+
showScrollbar: true,
|
|
113
|
+
size: "large"
|
|
114
|
+
}), _jsx(CopyToClipboard, {
|
|
115
|
+
value: codeField?.value ?? ""
|
|
116
|
+
}), _jsx(Collapse, {}), isEditable && _jsx(RemoveButton, {})]
|
|
117
|
+
}),
|
|
118
|
+
className: baseClass,
|
|
119
|
+
collapsibleProps: {
|
|
120
|
+
AfterCollapsible: _jsx(FloatingCollapse, {}),
|
|
121
|
+
disableHeaderToggle: true,
|
|
122
|
+
disableToggleIndicator: true
|
|
123
|
+
},
|
|
124
|
+
Pill: _jsx("div", {
|
|
125
|
+
className: `${baseClass}__pill`,
|
|
126
|
+
children: _jsx(CodeBlockIcon, {})
|
|
127
|
+
}),
|
|
128
|
+
showDragHandle: false,
|
|
129
|
+
showRowNumber: false,
|
|
130
|
+
children: _jsx(RenderFields, {
|
|
131
|
+
fields: formSchema,
|
|
132
|
+
forceRender: true,
|
|
133
|
+
parentIndexPath: "",
|
|
134
|
+
parentPath: "",
|
|
135
|
+
parentSchemaPath: "",
|
|
136
|
+
permissions: true,
|
|
137
|
+
readOnly: !isEditable
|
|
65
138
|
})
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}),
|
|
82
|
-
buttonType: "custom",
|
|
83
|
-
className: `${baseClass}__language-selector`,
|
|
84
|
-
disabled: !isEditable,
|
|
85
|
-
entries: languageEntries,
|
|
86
|
-
horizontalAlign: "right",
|
|
87
|
-
minEntriesForSearch: 8,
|
|
88
|
-
searchPlaceholder: t('fields:searchForLanguage'),
|
|
89
|
-
showScrollbar: true,
|
|
90
|
-
size: "large"
|
|
91
|
-
}), /*#__PURE__*/_jsx(CopyToClipboard, {
|
|
92
|
-
value: codeField?.value ?? ''
|
|
93
|
-
}), /*#__PURE__*/_jsx(Collapse, {}), isEditable && /*#__PURE__*/_jsx(RemoveButton, {})]
|
|
94
|
-
}),
|
|
95
|
-
className: baseClass,
|
|
96
|
-
collapsibleProps: {
|
|
97
|
-
AfterCollapsible: /*#__PURE__*/_jsx(FloatingCollapse, {}),
|
|
98
|
-
disableHeaderToggle: true,
|
|
99
|
-
disableToggleIndicator: true
|
|
100
|
-
},
|
|
101
|
-
Pill: /*#__PURE__*/_jsx("div", {
|
|
102
|
-
className: `${baseClass}__pill`,
|
|
103
|
-
children: /*#__PURE__*/_jsx(CodeBlockIcon, {})
|
|
104
|
-
}),
|
|
105
|
-
showDragHandle: false,
|
|
106
|
-
showRowNumber: false,
|
|
107
|
-
children: /*#__PURE__*/_jsx(RenderFields, {
|
|
108
|
-
fields: formSchema,
|
|
109
|
-
forceRender: true,
|
|
110
|
-
parentIndexPath: "",
|
|
111
|
-
parentPath: '',
|
|
112
|
-
parentSchemaPath: "",
|
|
113
|
-
permissions: true,
|
|
114
|
-
readOnly: !isEditable
|
|
115
|
-
})
|
|
116
|
-
});
|
|
139
|
+
});
|
|
140
|
+
$[5] = BlockCollapsible;
|
|
141
|
+
$[6] = RemoveButton;
|
|
142
|
+
$[7] = codeField?.value;
|
|
143
|
+
$[8] = formSchema;
|
|
144
|
+
$[9] = isEditable;
|
|
145
|
+
$[10] = languageEntries;
|
|
146
|
+
$[11] = selectedLanguageField?.value;
|
|
147
|
+
$[12] = selectedLanguageLabel;
|
|
148
|
+
$[13] = t;
|
|
149
|
+
$[14] = t2;
|
|
150
|
+
} else {
|
|
151
|
+
t2 = $[14];
|
|
152
|
+
}
|
|
153
|
+
return t2;
|
|
117
154
|
};
|
|
155
|
+
function _temp(t0) {
|
|
156
|
+
const [fields] = t0;
|
|
157
|
+
return {
|
|
158
|
+
codeField: fields?.code
|
|
159
|
+
};
|
|
160
|
+
}
|
|
118
161
|
//# sourceMappingURL=Block.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Block.js","names":["useLexicalEditable","ChevronIcon","Combobox","CopyToClipboard","PopupList","RenderFields","useForm","useFormFields","useTranslation","React","CodeBlockIcon","useBlockComponentContext","Collapse","defaultLanguages","FloatingCollapse","baseClass","CodeBlockBlockComponent","args","languages","languagesFromProps","BlockCollapsible","formSchema","RemoveButton","setModified","t","codeField","
|
|
1
|
+
{"version":3,"file":"Block.js","names":["c","_c","useLexicalEditable","ChevronIcon","Combobox","CopyToClipboard","PopupList","RenderFields","useForm","useFormFields","useTranslation","React","CodeBlockIcon","useBlockComponentContext","Collapse","defaultLanguages","FloatingCollapse","baseClass","CodeBlockBlockComponent","args","$","languages","languagesFromProps","BlockCollapsible","formSchema","RemoveButton","setModified","t","codeField","_temp","t0","t1","fields_0","dispatch","selectedLanguageField","fields","language","setSelectedLanguage","type","path","value","selectedLanguageLabel","isEditable","Object","entries","map","t2","languageCode","languageLabel","name","Component","_jsx","Button","active","disabled","onClick","children","className","languageEntries","Actions","_jsxs","button","horizontalAlign","minEntriesForSearch","searchPlaceholder","showScrollbar","size","collapsibleProps","AfterCollapsible","disableHeaderToggle","disableToggleIndicator","Pill","showRowNumber","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","readOnly","code"],"sources":["../../../../../../src/features/blocks/premade/CodeBlock/Component/Block.tsx"],"sourcesContent":["'use client'\nimport type { ComboboxEntry } from '@payloadcms/ui'\nimport type {} from 'payload'\n\nimport './index.css'\n\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport {\n ChevronIcon,\n Combobox,\n CopyToClipboard,\n PopupList,\n RenderFields,\n useForm,\n useFormFields,\n useTranslation,\n} from '@payloadcms/ui'\nimport React from 'react'\n\nimport type { AdditionalCodeComponentProps } from './Code.js'\n\nimport { CodeBlockIcon } from '../../../../../lexical/ui/icons/CodeBlock/index.js'\nimport { useBlockComponentContext } from '../../../client/component/BlockContent.js'\nimport { Collapse } from './Collapse/index.js'\nimport { defaultLanguages } from './defaultLanguages.js'\nimport { FloatingCollapse } from './FloatingCollapse/index.js'\n\nconst baseClass = 'payload-richtext-code-block'\nexport const CodeBlockBlockComponent: React.FC<Pick<AdditionalCodeComponentProps, 'languages'>> = (\n args,\n) => {\n const { languages: languagesFromProps } = args\n const languages = languagesFromProps || defaultLanguages\n\n const { BlockCollapsible, formSchema, RemoveButton } = useBlockComponentContext()\n const { setModified } = useForm()\n const { t } = useTranslation()\n\n const { codeField } = useFormFields(([fields]) => ({\n codeField: fields?.code,\n }))\n\n const { selectedLanguageField, setSelectedLanguage } = useFormFields(([fields, dispatch]) => ({\n selectedLanguageField: fields?.language,\n setSelectedLanguage: (language: string) => {\n dispatch({\n type: 'UPDATE',\n path: 'language',\n value: language,\n })\n setModified(true)\n },\n }))\n\n const selectedLanguageLabel = languages[selectedLanguageField?.value as keyof typeof languages]\n\n const isEditable = useLexicalEditable()\n\n const languageEntries = React.useMemo<ComboboxEntry[]>(() => {\n return Object.entries(languages).map(([languageCode, languageLabel]) => ({\n name: `${languageCode} ${languageLabel}`,\n Component: (\n <PopupList.Button\n active={false}\n disabled={false}\n onClick={() => {\n setSelectedLanguage(languageCode)\n }}\n >\n <span className={`${baseClass}__language-code`} data-language={languageCode}>\n {languageLabel}\n </span>\n </PopupList.Button>\n ),\n }))\n }, [languages, setSelectedLanguage])\n\n return (\n <BlockCollapsible\n Actions={\n <div className={`${baseClass}__actions`}>\n <Combobox\n aria-label={t('general:language')}\n button={\n <div\n className={`${baseClass}__language-selector-button`}\n data-selected-language={selectedLanguageField?.value}\n >\n <span>{selectedLanguageLabel}</span>\n <ChevronIcon className={`${baseClass}__chevron`} />\n </div>\n }\n buttonType=\"custom\"\n className={`${baseClass}__language-selector`}\n disabled={!isEditable}\n entries={languageEntries}\n horizontalAlign=\"right\"\n minEntriesForSearch={8}\n searchPlaceholder={t('fields:searchForLanguage')}\n showScrollbar\n size=\"large\"\n />\n <CopyToClipboard value={(codeField?.value as string) ?? ''} />\n\n <Collapse />\n\n {isEditable && <RemoveButton />}\n </div>\n }\n className={baseClass}\n collapsibleProps={{\n AfterCollapsible: <FloatingCollapse />,\n disableHeaderToggle: true,\n disableToggleIndicator: true,\n }}\n Pill={\n <div className={`${baseClass}__pill`}>\n <CodeBlockIcon />\n </div>\n }\n showDragHandle={false}\n showRowNumber={false}\n >\n <RenderFields\n fields={formSchema}\n forceRender={true}\n parentIndexPath=\"\"\n parentPath={''}\n parentSchemaPath=\"\"\n permissions={true}\n readOnly={!isEditable}\n />\n </BlockCollapsible>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,OAAO;AAEP,SAASC,kBAAkB,QAAQ;AACnC,SACEC,WAAW,EACXC,QAAQ,EACRC,eAAe,EACfC,SAAS,EACT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