@payloadcms/richtext-lexical 4.0.0-internal.cd47d20 → 4.0.0-internal.ce66a41
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-MT4FK3IP.js +2 -0
- package/dist/exports/client/Field-MT4FK3IP.js.map +7 -0
- package/dist/exports/client/chunk-3LRZDIIG.js +2 -0
- package/dist/exports/client/{chunk-LN6VX25I.js.map → chunk-3LRZDIIG.js.map} +2 -2
- package/dist/exports/client/chunk-ATPSL6IX.js +2 -0
- package/dist/exports/client/chunk-ATPSL6IX.js.map +7 -0
- package/dist/exports/client/componentInline-ZEP5JPTC.js +2 -0
- package/dist/exports/client/index.js +27 -27
- package/dist/exports/client/index.js.map +4 -4
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +43 -33
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/component/useBlockReordering.js +3 -3
- package/dist/features/blocks/client/component/useBlockReordering.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.css +0 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +30 -22
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/getCachedFormStateIfDataMatches.d.ts +9 -0
- package/dist/features/blocks/client/getCachedFormStateIfDataMatches.d.ts.map +1 -0
- package/dist/features/blocks/client/getCachedFormStateIfDataMatches.js +95 -0
- package/dist/features/blocks/client/getCachedFormStateIfDataMatches.js.map +1 -0
- package/dist/features/converters/lexicalToHtml/async/converters/upload.js +3 -3
- package/dist/features/converters/lexicalToHtml/async/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/upload.js +3 -3
- package/dist/features/converters/lexicalToHtml/sync/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/upload.js +4 -4
- package/dist/features/converters/lexicalToJSX/converter/converters/upload.js.map +1 -1
- package/dist/features/indent/client/IndentPlugin.d.ts.map +1 -1
- package/dist/features/indent/client/IndentPlugin.js +122 -1
- package/dist/features/indent/client/IndentPlugin.js.map +1 -1
- package/dist/features/indent/server/i18n.d.ts.map +1 -1
- package/dist/features/indent/server/i18n.js +74 -37
- package/dist/features/indent/server/i18n.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 +7 -5
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/index.css +0 -1
- package/dist/features/relationship/client/components/index.css +3 -6
- package/dist/features/table/client/plugins/TableActionMenuPlugin/index.css +0 -1
- package/dist/features/table/client/plugins/TablePlugin/TableGridPopup/index.css +0 -3
- package/dist/features/toolbars/inline/client/Toolbar/index.d.ts.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js +2 -2
- package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.css +0 -1
- package/dist/features/typesServer.d.ts +13 -8
- package/dist/features/typesServer.d.ts.map +1 -1
- package/dist/features/typesServer.js.map +1 -1
- package/dist/features/upload/client/component/index.css +0 -2
- package/dist/features/upload/client/plugin/index.d.ts.map +1 -1
- package/dist/features/upload/client/plugin/index.js +3 -1
- package/dist/features/upload/client/plugin/index.js.map +1 -1
- package/dist/field/Diff/converters/relationship/index.css +0 -1
- package/dist/field/Diff/converters/unknown/index.css +0 -1
- package/dist/field/Diff/converters/upload/index.css +0 -1
- package/dist/field/Diff/index.css +0 -2
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +8 -1
- package/dist/field/Field.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/index.css +0 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.css +21 -10
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +61 -64
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.d.ts.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.js +24 -21
- package/dist/lexical/plugins/DecoratorPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.css +2 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.css +0 -1
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.css +1 -0
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js +2 -2
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.css +1 -0
- package/dist/lexical/plugins/handles/utils/setHandlePosition.d.ts.map +1 -1
- package/dist/lexical/plugins/handles/utils/setHandlePosition.js +2 -0
- package/dist/lexical/plugins/handles/utils/setHandlePosition.js.map +1 -1
- package/dist/lexical/theme/EditorTheme.css +0 -2
- package/dist/lexical/ui/ContentEditable.d.ts +2 -1
- package/dist/lexical/ui/ContentEditable.d.ts.map +1 -1
- package/dist/lexical/ui/ContentEditable.js +21 -7
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/presets/llmInstructions.d.ts +2 -0
- package/dist/presets/llmInstructions.d.ts.map +1 -0
- package/dist/presets/llmInstructions.js +13 -0
- package/dist/presets/llmInstructions.js.map +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/buildInitialState.d.ts +1 -0
- package/dist/utilities/buildInitialState.d.ts.map +1 -1
- package/dist/utilities/buildInitialState.js +1 -0
- package/dist/utilities/buildInitialState.js.map +1 -1
- package/dist/validate/hasText.d.ts +2 -2
- package/dist/validate/hasText.d.ts.map +1 -1
- package/dist/validate/hasText.js.map +1 -1
- package/dist/validate/index.d.ts +1 -1
- package/dist/validate/index.d.ts.map +1 -1
- package/package.json +22 -22
- package/dist/exports/client/Field-BPLEYPXV.js +0 -2
- package/dist/exports/client/Field-BPLEYPXV.js.map +0 -7
- package/dist/exports/client/bundled.css +0 -1
- package/dist/exports/client/chunk-ESITTE3C.js +0 -2
- package/dist/exports/client/chunk-ESITTE3C.js.map +0 -7
- package/dist/exports/client/chunk-LN6VX25I.js +0 -2
- package/dist/exports/client/componentInline-H24N7GUG.js +0 -2
- package/dist/features/blocks/client/component/removeEmptyArrayValues.d.ts +0 -11
- package/dist/features/blocks/client/component/removeEmptyArrayValues.d.ts.map +0 -1
- package/dist/features/blocks/client/component/removeEmptyArrayValues.js +0 -20
- package/dist/features/blocks/client/component/removeEmptyArrayValues.js.map +0 -1
- /package/dist/exports/client/{componentInline-H24N7GUG.js.map → componentInline-ZEP5JPTC.js.map} +0 -0
|
@@ -9,12 +9,13 @@ import { abortAndIgnore } from '@payloadcms/ui/shared';
|
|
|
9
9
|
import { $getNodeByKey, SKIP_DOM_SELECTION_TAG } from 'lexical';
|
|
10
10
|
import './index.css';
|
|
11
11
|
import '../../../../utilities/fieldsDrawer/index.css';
|
|
12
|
-
import { deepCopyObjectSimpleWithoutReactComponents
|
|
12
|
+
import { deepCopyObjectSimpleWithoutReactComponents } from 'payload/shared';
|
|
13
13
|
import React, { createContext, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
14
14
|
import { v4 as uuid } from 'uuid';
|
|
15
15
|
import { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js';
|
|
16
16
|
import { RegisterFormSubmit, useDrawerSubmit } from '../../../../utilities/fieldsDrawer/useDrawerSubmit.js';
|
|
17
17
|
import { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js';
|
|
18
|
+
import { getCachedFormStateIfDataMatches, reduceFormStateToBlockData } from '../getCachedFormStateIfDataMatches.js';
|
|
18
19
|
import { $isInlineBlockNode } from '../nodes/InlineBlocksNode.js';
|
|
19
20
|
const InlineBlockComponentContext = /*#__PURE__*/createContext({
|
|
20
21
|
initialState: false
|
|
@@ -53,19 +54,23 @@ export const InlineBlockComponent = props => {
|
|
|
53
54
|
} = useServerFunctions();
|
|
54
55
|
const editDepth = useEditDepth();
|
|
55
56
|
const firstTimeDrawer = useRef(false);
|
|
57
|
+
const blockType = formData.blockType;
|
|
58
|
+
const formDataRef = useRef(formData);
|
|
59
|
+
formDataRef.current = formData;
|
|
60
|
+
const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockType}.fields`;
|
|
56
61
|
const [initialState, setInitialState] = React.useState(() => {
|
|
57
62
|
// Initial form state that was calculated server-side. May have stale values
|
|
58
|
-
const
|
|
63
|
+
const cachedState = initialLexicalFormState?.[formData.id];
|
|
64
|
+
const cachedFormState = cachedState?.formState;
|
|
59
65
|
if (!cachedFormState) {
|
|
60
66
|
return false;
|
|
61
67
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
} : fieldState]));
|
|
68
|
+
return getCachedFormStateIfDataMatches({
|
|
69
|
+
cachedFormState,
|
|
70
|
+
cachedSchemaPath: cachedState.schemaPath,
|
|
71
|
+
currentSchemaPath: schemaFieldsPath,
|
|
72
|
+
formData
|
|
73
|
+
});
|
|
69
74
|
});
|
|
70
75
|
const hasMounted = useRef(false);
|
|
71
76
|
const prevCacheBuster = useRef(cacheBuster);
|
|
@@ -141,7 +146,7 @@ export const InlineBlockComponent = props => {
|
|
|
141
146
|
const {
|
|
142
147
|
config
|
|
143
148
|
} = useConfig();
|
|
144
|
-
const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${
|
|
149
|
+
const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockType}`;
|
|
145
150
|
const clientSchemaMap = featureClientSchemaMap['blocks'];
|
|
146
151
|
const blocksField = clientSchemaMap?.[componentMapRenderedBlockPath]?.[0];
|
|
147
152
|
const blockOrSlug = blocksField?.blocks?.[0];
|
|
@@ -165,7 +170,6 @@ export const InlineBlockComponent = props => {
|
|
|
165
170
|
}, [editor, nodeKey]);
|
|
166
171
|
const blockDisplayName = clientBlock?.labels?.singular ? getTranslation(clientBlock?.labels.singular, i18n) : clientBlock?.slug;
|
|
167
172
|
const onChangeAbortControllerRef = useRef(new AbortController());
|
|
168
|
-
const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${clientBlock?.slug}.fields`;
|
|
169
173
|
// Initial state for newly created blocks
|
|
170
174
|
useEffect(() => {
|
|
171
175
|
const abortController = new AbortController();
|
|
@@ -190,7 +194,6 @@ export const InlineBlockComponent = props => {
|
|
|
190
194
|
}),
|
|
191
195
|
globalSlug,
|
|
192
196
|
initialBlockData: formData,
|
|
193
|
-
initialBlockFormState: formData,
|
|
194
197
|
operation: 'update',
|
|
195
198
|
readOnly: !isEditable,
|
|
196
199
|
renderAllFields: true,
|
|
@@ -198,9 +201,9 @@ export const InlineBlockComponent = props => {
|
|
|
198
201
|
signal: abortController.signal
|
|
199
202
|
});
|
|
200
203
|
if (state) {
|
|
201
|
-
const newFormStateData =
|
|
204
|
+
const newFormStateData = reduceFormStateToBlockData(deepCopyObjectSimpleWithoutReactComponents(state, {
|
|
202
205
|
excludeFiles: true
|
|
203
|
-
})
|
|
206
|
+
}));
|
|
204
207
|
// Things like default values may come back from the server => update the node with the new data
|
|
205
208
|
editor.update(() => {
|
|
206
209
|
const node = $getNodeByKey(nodeKey);
|
|
@@ -224,13 +227,13 @@ export const InlineBlockComponent = props => {
|
|
|
224
227
|
}
|
|
225
228
|
}
|
|
226
229
|
};
|
|
227
|
-
if (formData && !initialState) {
|
|
230
|
+
if (clientBlock && formData && !initialState) {
|
|
228
231
|
void awaitInitialState();
|
|
229
232
|
}
|
|
230
233
|
return () => {
|
|
231
234
|
abortAndIgnore(abortController);
|
|
232
235
|
};
|
|
233
|
-
}, [getFormState, editor, nodeKey, isEditable, CustomLabelFromProps, CustomBlockFromProps, schemaFieldsPath, id, formData, initialState, collectionSlug, globalSlug, getDocPreferences, parentDocumentFields]);
|
|
236
|
+
}, [getFormState, editor, nodeKey, isEditable, CustomLabelFromProps, CustomBlockFromProps, schemaFieldsPath, id, formData, initialState, collectionSlug, globalSlug, getDocPreferences, parentDocumentFields, clientBlock]);
|
|
234
237
|
/**
|
|
235
238
|
* HANDLE ONCHANGE
|
|
236
239
|
*/
|
|
@@ -241,11 +244,15 @@ export const InlineBlockComponent = props => {
|
|
|
241
244
|
abortAndIgnore(onChangeAbortControllerRef.current);
|
|
242
245
|
const controller = new AbortController();
|
|
243
246
|
onChangeAbortControllerRef.current = controller;
|
|
247
|
+
const blockData = reduceFormStateToBlockData(deepCopyObjectSimpleWithoutReactComponents(prevFormState, {
|
|
248
|
+
excludeFiles: true
|
|
249
|
+
}), formDataRef.current);
|
|
244
250
|
const {
|
|
245
251
|
state: state_0
|
|
246
252
|
} = await getFormState({
|
|
247
253
|
id,
|
|
248
254
|
collectionSlug,
|
|
255
|
+
data: blockData,
|
|
249
256
|
docPermissions: {
|
|
250
257
|
fields: true
|
|
251
258
|
},
|
|
@@ -255,7 +262,7 @@ export const InlineBlockComponent = props => {
|
|
|
255
262
|
}),
|
|
256
263
|
formState: prevFormState,
|
|
257
264
|
globalSlug,
|
|
258
|
-
|
|
265
|
+
initialBlockData: blockData,
|
|
259
266
|
operation: 'update',
|
|
260
267
|
readOnly: !isEditable,
|
|
261
268
|
renderAllFields: submit ? true : false,
|
|
@@ -293,8 +300,9 @@ export const InlineBlockComponent = props => {
|
|
|
293
300
|
/**
|
|
294
301
|
* HANDLE FORM SUBMIT
|
|
295
302
|
*/
|
|
296
|
-
const onFormSubmit = useCallback(
|
|
297
|
-
newData_0
|
|
303
|
+
const onFormSubmit = useCallback(formState => {
|
|
304
|
+
const newData_0 = reduceFormStateToBlockData(formState, formDataRef.current);
|
|
305
|
+
newData_0.blockType = blockType;
|
|
298
306
|
editor.update(() => {
|
|
299
307
|
const node_0 = $getNodeByKey(nodeKey);
|
|
300
308
|
if (node_0 && $isInlineBlockNode(node_0)) {
|
|
@@ -306,7 +314,7 @@ export const InlineBlockComponent = props => {
|
|
|
306
314
|
{
|
|
307
315
|
tag: SKIP_DOM_SELECTION_TAG
|
|
308
316
|
});
|
|
309
|
-
}, [editor, nodeKey
|
|
317
|
+
}, [blockType, editor, nodeKey]);
|
|
310
318
|
const {
|
|
311
319
|
headerActions,
|
|
312
320
|
submitRef
|
|
@@ -396,8 +404,8 @@ export const InlineBlockComponent = props => {
|
|
|
396
404
|
fields: clientBlock?.fields,
|
|
397
405
|
initialState: initialState || {},
|
|
398
406
|
onChange: [onChange],
|
|
399
|
-
onSubmit:
|
|
400
|
-
onFormSubmit(formState_1
|
|
407
|
+
onSubmit: formState_1 => {
|
|
408
|
+
onFormSubmit(formState_1);
|
|
401
409
|
toggleDrawer();
|
|
402
410
|
},
|
|
403
411
|
uuid: formUuid,
|
|
@@ -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","reduceFieldsToValues","React","createContext","useCallback","useEffect","useMemo","useRef","v4","uuid","useEditorConfigContext","RegisterFormSubmit","useDrawerSubmit","useLexicalDrawer","$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","setInitialState","useState","cachedFormState","id","formState","Object","fromEntries","entries","map","fieldName","fieldState","initialValue","value","hasMounted","prevCacheBuster","current","formUuid","setCustomLabel","undefined","customComponents","BlockLabel","setCustomBlock","Block","resolvedCustomBlock","_jsx","isEditor","isJSXConverter","resolvedCustomLabel","drawerSlug","slug","depth","toggleDrawer","inlineBlockElemElemRef","collectionSlug","getDocPreferences","globalSlug","config","componentMapRenderedBlockPath","blockType","clientSchemaMap","blocksField","blockOrSlug","blocks","clientBlock","blocksMap","clientBlockFields","getKey","length","removeInlineBlock","update","remove","blockDisplayName","labels","singular","onChangeAbortControllerRef","AbortController","schemaFieldsPath","abortController","awaitInitialState","state","data","docPermissions","docPreferences","documentFormState","excludeFiles","initialBlockData","initialBlockFormState","operation","readOnly","renderAllFields","signal","newFormStateData","node","newData","setFields","tag","onChange","prevFormState","submit","controller","isStateOutOfSync","keys","some","key","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, Data, 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, reduceFieldsToValues } 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 { $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\n const [initialState, setInitialState] = React.useState<false | FormState | undefined>(() => {\n // Initial form state that was calculated server-side. May have stale values\n const cachedFormState = initialLexicalFormState?.[formData.id]?.formState\n if (!cachedFormState) {\n return false\n }\n\n // Merge current formData values into the cached form state\n // This ensures that when the component remounts (e.g., due to view changes), we don't lose user edits\n return Object.fromEntries(\n Object.entries(cachedFormState).map(([fieldName, fieldState]) => [\n fieldName,\n fieldName in formData\n ? {\n ...fieldState,\n initialValue: formData[fieldName],\n value: formData[fieldName],\n }\n : fieldState,\n ]),\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.${formData.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 const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${clientBlock?.slug}.fields`\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 initialBlockFormState: 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: InlineBlockFields = reduceFieldsToValues(\n deepCopyObjectSimpleWithoutReactComponents(state, { excludeFiles: true }),\n 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 (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 ])\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\n const { state } = await getFormState({\n id,\n collectionSlug,\n docPermissions: {\n fields: true,\n },\n docPreferences: await getDocPreferences(),\n documentFormState: deepCopyObjectSimpleWithoutReactComponents(parentDocumentFields, {\n excludeFiles: true,\n }),\n formState: prevFormState,\n globalSlug,\n initialBlockFormState: prevFormState,\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, newData: Data) => {\n newData.blockType = formData.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 [editor, nodeKey, formData],\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, data) => {\n onFormSubmit(formState, data)\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,EAAEC,oBAAoB,QAAQ;AACjF,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,SAASC,kBAAkB,QAAQ;AAkBnC,MAAMC,2BAAA,gBAA8BZ,aAAA,CAA+C;EACjFa,YAAA,EAAc;AAChB;AAEA,OAAO,MAAMC,8BAAA,GAAiCA,CAAA,KAAMf,KAAA,CAAMgB,GAAG,CAACH,2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AA;gBACC,aAAAoF,IAAA,CAACrF,MAAA;QACCqC,SAAA,EAAW;QACX6G,aAAA,EAAeA,aAAA;QACfxD,IAAA,EAAMD,UAAA;QACNuF,KAAA,EAAOhI,CAAA,CAAE,+BAA+BL,QAAA,EAAUqB,EAAA,GAAK,SAAS,UAAU,EAAE;UAC1E+F,KAAA,EAAO/C,gBAAA,IAAoBhE,CAAA,CAAE;QAC/B;kBAECjB,YAAA,gBACC6I,KAAA,CAAC;UAAIvI,SAAA,EAAU;kCACbgD,IAAA,CAACjF,YAAA;YACCoD,MAAA,EAAQgD,WAAA,EAAahD,MAAA;YACrByH,WAAW;YACXC,eAAA,EAAgB;YAChBC,UAAA,EAAW;YACXC,gBAAA,EAAkB/D,gBAAA;YAClBgE,WAAA,EAAa;YACbpD,QAAA,EAAU,CAACnF;2BAEbuC,IAAA,CAAC3D,kBAAA;YAAmByH,SAAA,EAAWA;;aAE/B;;QAGP/D,mBAAA,gBACCC,IAAA,CAACvD,2BAAA;MACC2C,KAAA,EAAO;QACLuF,UAAA;QACAjI,YAAA;QACAmI,oBAAA;QACAS,KAAA;QACA/H,OAAA;QACAwG;MACF;gBAEChE;sBAGHwF,KAAA,CAACV,oBAAA;iBACEnI,YAAA,gBAAesD,IAAA,CAACsF,KAAA,qBAAWtF,IAAA,CAAChF,aAAA;QAAciL,MAAA,EAAO;QAAOC,KAAA,EAAM;UAC9DzI,UAAA,gBACCuC,IAAA,CAAC;QAAIhD,SAAA,EAAW,GAAGC,SAAA,WAAoB;kBACrC,aAAA+C,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","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,sBAAs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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":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Data, FormState } from 'payload';
|
|
2
|
+
export declare const getCachedFormStateIfDataMatches: ({ cachedFormState, cachedSchemaPath, currentSchemaPath, formData, }: {
|
|
3
|
+
cachedFormState: FormState;
|
|
4
|
+
cachedSchemaPath?: string;
|
|
5
|
+
currentSchemaPath?: string;
|
|
6
|
+
formData: Data;
|
|
7
|
+
}) => false | FormState;
|
|
8
|
+
export declare const reduceFormStateToBlockData: (formState: FormState, currentData?: Data) => Data;
|
|
9
|
+
//# sourceMappingURL=getCachedFormStateIfDataMatches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCachedFormStateIfDataMatches.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/client/getCachedFormStateIfDataMatches.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAK9C,eAAO,MAAM,+BAA+B,wEAKzC;IACD,eAAe,EAAE,SAAS,CAAA;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,EAAE,IAAI,CAAA;CACf,KAAG,KAAK,GAAG,SAcX,CAAA;AAED,eAAO,MAAM,0BAA0B,cAAe,SAAS,gBAAgB,IAAI,KAAG,IA4BrF,CAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { dequal } from 'dequal/lite';
|
|
2
|
+
import { reduceFieldsToValues } from 'payload/shared';
|
|
3
|
+
export const getCachedFormStateIfDataMatches = ({
|
|
4
|
+
cachedFormState,
|
|
5
|
+
cachedSchemaPath,
|
|
6
|
+
currentSchemaPath,
|
|
7
|
+
formData
|
|
8
|
+
}) => {
|
|
9
|
+
if (cachedSchemaPath !== currentSchemaPath) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const cachedData = reduceFormStateToBlockData(cachedFormState);
|
|
13
|
+
const currentData = normalizeData({
|
|
14
|
+
data: formData,
|
|
15
|
+
rowFieldPaths: getRowFieldPaths(cachedFormState)
|
|
16
|
+
});
|
|
17
|
+
return dequal(withoutSystemBlockFields(cachedData), withoutSystemBlockFields(currentData)) ? cachedFormState : false;
|
|
18
|
+
};
|
|
19
|
+
export const reduceFormStateToBlockData = (formState, currentData) => {
|
|
20
|
+
const formStateWithoutRowCounts = Object.fromEntries(Object.entries(formState).map(([path, fieldState]) => {
|
|
21
|
+
if (!fieldState || !Array.isArray(fieldState.rows)) {
|
|
22
|
+
return [path, fieldState];
|
|
23
|
+
}
|
|
24
|
+
if (fieldState.value === undefined || fieldState.disableFormData !== false && fieldState.isModified !== true && fieldState.rows.length === 0 && getValueAtPath(currentData, path) === null) {
|
|
25
|
+
return [path, {
|
|
26
|
+
...fieldState,
|
|
27
|
+
value: null
|
|
28
|
+
}];
|
|
29
|
+
}
|
|
30
|
+
return [path, fieldState.value === null ? fieldState : {
|
|
31
|
+
...fieldState,
|
|
32
|
+
disableFormData: true
|
|
33
|
+
}];
|
|
34
|
+
}));
|
|
35
|
+
return normalizeData({
|
|
36
|
+
data: reduceFieldsToValues(formStateWithoutRowCounts, true),
|
|
37
|
+
rowFieldPaths: new Set()
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const getValueAtPath = (data, path) => path.split('.').reduce((value, pathSegment) => {
|
|
41
|
+
if (!value || typeof value !== 'object') {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return value[pathSegment];
|
|
45
|
+
}, data);
|
|
46
|
+
const getRowFieldPaths = formState => new Set(Object.entries(formState).filter(([, fieldState]) => Array.isArray(fieldState?.rows) && fieldState.value !== null && fieldState.value !== undefined).map(([path]) => path));
|
|
47
|
+
const normalizeData = ({
|
|
48
|
+
data,
|
|
49
|
+
parentPath = '',
|
|
50
|
+
rowFieldPaths
|
|
51
|
+
}) => {
|
|
52
|
+
const normalizedData = {};
|
|
53
|
+
for (const [key, value] of Object.entries(data)) {
|
|
54
|
+
const path = parentPath ? `${parentPath}.${key}` : key;
|
|
55
|
+
const normalizedValue = normalizeValue({
|
|
56
|
+
parentPath: path,
|
|
57
|
+
rowFieldPaths,
|
|
58
|
+
value
|
|
59
|
+
});
|
|
60
|
+
if (normalizedValue !== undefined) {
|
|
61
|
+
normalizedData[key] = normalizedValue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return normalizedData;
|
|
65
|
+
};
|
|
66
|
+
const normalizeValue = ({
|
|
67
|
+
parentPath,
|
|
68
|
+
rowFieldPaths,
|
|
69
|
+
value
|
|
70
|
+
}) => {
|
|
71
|
+
if (value === undefined || Array.isArray(value) && value.length === 0 && rowFieldPaths.has(parentPath)) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
return value.map((item, index) => item && typeof item === 'object' && !Array.isArray(item) ? normalizeData({
|
|
76
|
+
data: item,
|
|
77
|
+
parentPath: `${parentPath}.${index}`,
|
|
78
|
+
rowFieldPaths
|
|
79
|
+
}) : item);
|
|
80
|
+
}
|
|
81
|
+
if (value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
|
|
82
|
+
return normalizeData({
|
|
83
|
+
data: value,
|
|
84
|
+
parentPath,
|
|
85
|
+
rowFieldPaths
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
};
|
|
90
|
+
const withoutSystemBlockFields = ({
|
|
91
|
+
blockName: _blockName,
|
|
92
|
+
blockType: _blockType,
|
|
93
|
+
...data
|
|
94
|
+
}) => data;
|
|
95
|
+
//# sourceMappingURL=getCachedFormStateIfDataMatches.js.map
|
|
@@ -0,0 +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 ) as FormState\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 as Data, 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;AACv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MAAMG,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;MAAeW,UAAA;MAAYzB;IAAc;EACxE;EAEA,OAAOc,KAAA;AACT;AAEA,MAAMZ,wBAAA,GAA2BA,CAAC;EAChCiC,SAAA,EAAWC,UAAU;EACrBC,SAAA,EAAWC,UAAU;EACrB,GAAGvC;AAAA,CACE,KAAWA,IAAA","ignoreList":[]}
|
|
@@ -29,7 +29,7 @@ export const UploadHTMLConverterAsync = {
|
|
|
29
29
|
return `<a${providedStyleTag} href="${url}" rel="noopener noreferrer">${escapeHTML(uploadDoc.filename ?? '')}</a>`;
|
|
30
30
|
}
|
|
31
31
|
// 2) If image has no different sizes, return a simple <img />
|
|
32
|
-
if (!uploadDoc.
|
|
32
|
+
if (!uploadDoc.variants || !Object.keys(uploadDoc.variants).length) {
|
|
33
33
|
return `
|
|
34
34
|
<img${providedStyleTag}
|
|
35
35
|
alt="${alt}"
|
|
@@ -41,8 +41,8 @@ export const UploadHTMLConverterAsync = {
|
|
|
41
41
|
}
|
|
42
42
|
// 3) If image has different sizes, build a <picture> element with <source> tags
|
|
43
43
|
let pictureHTML = '';
|
|
44
|
-
for (const size in uploadDoc.
|
|
45
|
-
const imageSize = uploadDoc.
|
|
44
|
+
for (const size in uploadDoc.variants) {
|
|
45
|
+
const imageSize = uploadDoc.variants[size];
|
|
46
46
|
if (!imageSize || !imageSize.width || !imageSize.height || !imageSize.mimeType || !imageSize.filesize || !imageSize.filename || !imageSize.url) {
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","names":["escapeHTML","UploadHTMLConverterAsync","upload","node","populate","providedStyleTag","uploadNode","uploadDoc","undefined","value","id","collectionSlug","relationTo","alt","fields","url","mimeType","startsWith","filename","
|
|
1
|
+
{"version":3,"file":"upload.js","names":["escapeHTML","UploadHTMLConverterAsync","upload","node","populate","providedStyleTag","uploadNode","uploadDoc","undefined","value","id","collectionSlug","relationTo","alt","fields","url","mimeType","startsWith","filename","variants","Object","keys","length","String","height","width","pictureHTML","size","imageSize","filesize"],"sources":["../../../../../../src/features/converters/lexicalToHtml/async/converters/upload.ts"],"sourcesContent":["import type { FileData, FileSize, TypeWithID } from 'payload'\n\nimport escapeHTML from 'escape-html'\n\nimport type { SerializedUploadNode } from '../../../../../types/nodeTypes.js'\nimport type { UploadDataImproved } from '../../../../upload/server/schema.js'\nimport type { HTMLConvertersAsync } from '../types.js'\n\nexport const UploadHTMLConverterAsync: HTMLConvertersAsync<SerializedUploadNode> = {\n upload: async ({ node, populate, providedStyleTag }) => {\n const uploadNode = node as UploadDataImproved\n\n let uploadDoc: (FileData & TypeWithID) | undefined = undefined\n\n // If there's no valid upload data, populate return an empty string\n if (typeof uploadNode.value !== 'object') {\n if (!populate) {\n return ''\n }\n uploadDoc = await populate<FileData & TypeWithID>({\n id: uploadNode.value,\n collectionSlug: uploadNode.relationTo,\n })\n } else {\n uploadDoc = uploadNode.value as unknown as FileData & TypeWithID\n }\n\n if (!uploadDoc) {\n return ''\n }\n\n const alt = escapeHTML(\n (node.fields?.alt as string) || (uploadDoc as { alt?: string })?.alt || '',\n )\n\n const url = escapeHTML(uploadDoc.url ?? '')\n\n // 1) If upload is NOT an image, return a link\n if (!uploadDoc.mimeType.startsWith('image')) {\n return `<a${providedStyleTag} href=\"${url}\" rel=\"noopener noreferrer\">${escapeHTML(uploadDoc.filename ?? '')}</a>`\n }\n\n // 2) If image has no different sizes, return a simple <img />\n if (!uploadDoc.variants || !Object.keys(uploadDoc.variants).length) {\n return `\n <img${providedStyleTag}\n alt=\"${alt}\"\n height=\"${escapeHTML(String(uploadDoc.height ?? ''))}\"\n src=\"${url}\"\n width=\"${escapeHTML(String(uploadDoc.width ?? ''))}\"\n />\n `\n }\n\n // 3) If image has different sizes, build a <picture> element with <source> tags\n let pictureHTML = ''\n\n for (const size in uploadDoc.variants) {\n const imageSize = uploadDoc.variants[size] as FileSize\n\n if (\n !imageSize ||\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n\n pictureHTML += `\n <source\n media=\"(max-width: ${escapeHTML(String(imageSize.width))}px)\"\n srcset=\"${escapeHTML(imageSize.url)}\"\n type=\"${escapeHTML(imageSize.mimeType)}\"\n />\n `\n }\n\n pictureHTML += `\n <img\n alt=\"${alt}\"\n height=\"${escapeHTML(String(uploadDoc.height ?? ''))}\"\n src=\"${url}\"\n width=\"${escapeHTML(String(uploadDoc.width ?? ''))}\"\n />\n `\n\n return `<picture${providedStyleTag}>${pictureHTML}</picture>`\n },\n}\n"],"mappings":"AAEA,OAAOA,UAAA,MAAgB;AAMvB,OAAO,MAAMC,wBAAA,GAAsE;EACjFC,MAAA,EAAQ,MAAAA,CAAO;IAAEC,IAAI;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A,CAAK;MAE1C,IACE,CAACC,SAAA,IACD,CAACA,SAAA,CAAUH,KAAK,IAChB,CAACG,SAAA,CAAUJ,MAAM,IACjB,CAACI,SAAA,CAAUZ,QAAQ,IACnB,CAACY,SAAA,CAAUC,QAAQ,IACnB,CAACD,SAAA,CAAUV,QAAQ,IACnB,CAACU,SAAA,CAAUb,GAAG,EACd;QACA;MACF;MAEAW,WAAA,IAAe;;+BAEU1B,UAAA,CAAWuB,MAAA,CAAOK,SAAA,CAAUH,KAAK;oBAC5CzB,UAAA,CAAW4B,SAAA,CAAUb,GAAG;kBAC1Bf,UAAA,CAAW4B,SAAA,CAAUZ,QAAQ;;OAExC;IACH;IAEAU,WAAA,IAAe;;eAEJb,GAAA;kBACGb,UAAA,CAAWuB,MAAA,CAAOhB,SAAA,CAAUiB,MAAM,IAAI;eACzCT,GAAA;iBACEf,UAAA,CAAWuB,MAAA,CAAOhB,SAAA,CAAUkB,KAAK,IAAI;;KAEjD;IAED,OAAO,WAAWpB,gBAAA,IAAoBqB,WAAA,YAAuB;EAC/D;AACF","ignoreList":[]}
|
|
@@ -22,7 +22,7 @@ export const UploadHTMLConverter = {
|
|
|
22
22
|
return `<a${providedStyleTag} href="${url}" rel="noopener noreferrer">${escapeHTML(uploadDoc.filename ?? '')}</a>`;
|
|
23
23
|
}
|
|
24
24
|
// 2) If image has no different sizes, return a simple <img />
|
|
25
|
-
if (!uploadDoc.
|
|
25
|
+
if (!uploadDoc.variants || !Object.keys(uploadDoc.variants).length) {
|
|
26
26
|
return `
|
|
27
27
|
<img${providedStyleTag}
|
|
28
28
|
alt="${alt}"
|
|
@@ -34,8 +34,8 @@ export const UploadHTMLConverter = {
|
|
|
34
34
|
}
|
|
35
35
|
// 3) If image has different sizes, build a <picture> element with <source> tags
|
|
36
36
|
let pictureHTML = '';
|
|
37
|
-
for (const size in uploadDoc.
|
|
38
|
-
const imageSize = uploadDoc.
|
|
37
|
+
for (const size in uploadDoc.variants) {
|
|
38
|
+
const imageSize = uploadDoc.variants[size];
|
|
39
39
|
if (!imageSize || !imageSize.width || !imageSize.height || !imageSize.mimeType || !imageSize.filesize || !imageSize.filename || !imageSize.url) {
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","names":["escapeHTML","UploadHTMLConverter","upload","node","providedStyleTag","uploadNode","uploadDoc","undefined","value","alt","fields","url","mimeType","startsWith","filename","
|
|
1
|
+
{"version":3,"file":"upload.js","names":["escapeHTML","UploadHTMLConverter","upload","node","providedStyleTag","uploadNode","uploadDoc","undefined","value","alt","fields","url","mimeType","startsWith","filename","variants","Object","keys","length","String","height","width","pictureHTML","size","imageSize","filesize"],"sources":["../../../../../../src/features/converters/lexicalToHtml/sync/converters/upload.ts"],"sourcesContent":["import type { FileData, FileSize, TypeWithID } from 'payload'\n\nimport escapeHTML from 'escape-html'\n\nimport type { SerializedUploadNode } from '../../../../../types/nodeTypes.js'\nimport type { UploadDataImproved } from '../../../../upload/server/schema.js'\nimport type { HTMLConverters } from '../types.js'\n\nexport const UploadHTMLConverter: HTMLConverters<SerializedUploadNode> = {\n upload: ({ node, providedStyleTag }) => {\n const uploadNode = node as UploadDataImproved\n\n let uploadDoc: (FileData & TypeWithID) | undefined = undefined\n\n // If there's no valid upload data, populate return an empty string\n if (typeof uploadNode.value !== 'object') {\n return ''\n } else {\n uploadDoc = uploadNode.value as unknown as FileData & TypeWithID\n }\n\n if (!uploadDoc) {\n return ''\n }\n\n const alt = escapeHTML(\n (node.fields?.alt as string) || (uploadDoc as { alt?: string })?.alt || '',\n )\n\n const url = escapeHTML(uploadDoc.url ?? '')\n\n // 1) If upload is NOT an image, return a link\n if (!uploadDoc.mimeType.startsWith('image')) {\n return `<a${providedStyleTag} href=\"${url}\" rel=\"noopener noreferrer\">${escapeHTML(uploadDoc.filename ?? '')}</a>`\n }\n\n // 2) If image has no different sizes, return a simple <img />\n if (!uploadDoc.variants || !Object.keys(uploadDoc.variants).length) {\n return `\n <img${providedStyleTag}\n alt=\"${alt}\"\n height=\"${escapeHTML(String(uploadDoc.height ?? ''))}\"\n src=\"${url}\"\n width=\"${escapeHTML(String(uploadDoc.width ?? ''))}\"\n />\n `\n }\n\n // 3) If image has different sizes, build a <picture> element with <source> tags\n let pictureHTML = ''\n\n for (const size in uploadDoc.variants) {\n const imageSize = uploadDoc.variants[size] as FileSize\n\n if (\n !imageSize ||\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n\n pictureHTML += `\n <source\n media=\"(max-width: ${escapeHTML(String(imageSize.width))}px)\"\n srcset=\"${escapeHTML(imageSize.url)}\"\n type=\"${escapeHTML(imageSize.mimeType)}\"\n />\n `\n }\n\n pictureHTML += `\n <img\n alt=\"${alt}\"\n height=\"${escapeHTML(String(uploadDoc.height ?? ''))}\"\n src=\"${url}\"\n width=\"${escapeHTML(String(uploadDoc.width ?? ''))}\"\n />\n `\n\n return `<picture${providedStyleTag}>${pictureHTML}</picture>`\n },\n}\n"],"mappings":"AAEA,OAAOA,UAAA,MAAgB;AAMvB,OAAO,MAAMC,mBAAA,GAA4D;EACvEC,MAAA,EAAQA,CAAC;IAAEC,IAAI;IAAEC;EAAgB,CAAE;IACjC,MAAMC,UAAA,GAAaF,IAAA;IAEnB,IAAIG,SAAA,GAAiDC,SAAA;IAErD;IACA,IAAI,OAAOF,UAAA,CAAWG,KAAK,KAAK,UAAU;MACxC,OAAO;IACT,OAAO;MACLF,SAAA,GAAYD,UAAA,CAAWG,KAAK;IAC9B;IAEA,IAAI,CAACF,SAAA,EAAW;MACd,OAAO;IACT;IAEA,MAAMG,GAAA,GAAMT,UAAA,CACVG,IAAC,CAAKO,MAAM,EAAED,GAAA,IAAmBH,SAAA,EAAgCG,GAAA,IAAO;IAG1E,MAAME,GAAA,GAAMX,UAAA,CAAWM,SAAA,CAAUK,GAAG,IAAI;IAExC;IACA,IAA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A,IAAoBkB,WAAA,YAAuB;EAC/D;AACF","ignoreList":[]}
|
|
@@ -24,7 +24,7 @@ export const UploadJSXConverter = {
|
|
|
24
24
|
/**
|
|
25
25
|
* If the upload is a simple image with no different sizes, return a simple img tag
|
|
26
26
|
*/
|
|
27
|
-
if (!uploadDoc.
|
|
27
|
+
if (!uploadDoc.variants || !Object.keys(uploadDoc.variants).length) {
|
|
28
28
|
return /*#__PURE__*/_jsx("img", {
|
|
29
29
|
alt: alt,
|
|
30
30
|
height: uploadDoc.height,
|
|
@@ -36,9 +36,9 @@ export const UploadJSXConverter = {
|
|
|
36
36
|
* If the upload is an image with different sizes, return a picture element
|
|
37
37
|
*/
|
|
38
38
|
const pictureJSX = [];
|
|
39
|
-
// Iterate through each size in the data.
|
|
40
|
-
for (const size in uploadDoc.
|
|
41
|
-
const imageSize = uploadDoc.
|
|
39
|
+
// Iterate through each size in the data.variants object
|
|
40
|
+
for (const size in uploadDoc.variants) {
|
|
41
|
+
const imageSize = uploadDoc.variants[size];
|
|
42
42
|
// Skip if any property of the size object is null
|
|
43
43
|
if (!imageSize || !imageSize.width || !imageSize.height || !imageSize.mimeType || !imageSize.filesize || !imageSize.filename || !imageSize.url) {
|
|
44
44
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","names":["UploadJSXConverter","upload","node","uploadNode","value","uploadDoc","alt","fields","url","mimeType","startsWith","_jsx","href","rel","filename","
|
|
1
|
+
{"version":3,"file":"upload.js","names":["UploadJSXConverter","upload","node","uploadNode","value","uploadDoc","alt","fields","url","mimeType","startsWith","_jsx","href","rel","filename","variants","Object","keys","length","height","src","width","pictureJSX","size","imageSize","filesize","imageSizeURL","push","media","srcSet","type"],"sources":["../../../../../../src/features/converters/lexicalToJSX/converter/converters/upload.tsx"],"sourcesContent":["import type { FileData, FileSize, TypeWithID } from 'payload'\n\nimport type { SerializedUploadNode } from '../../../../../types/nodeTypes.js'\nimport type { UploadDataImproved } from '../../../../upload/server/schema.js'\nimport type { JSXConverters } from '../types.js'\n\nexport const UploadJSXConverter: JSXConverters<SerializedUploadNode> = {\n upload: ({ node }) => {\n // TO-DO (v4): SerializedUploadNode should use UploadData_P4\n const uploadNode = node as UploadDataImproved\n if (typeof uploadNode.value !== 'object') {\n return null\n }\n\n const uploadDoc = uploadNode.value as FileData & TypeWithID\n\n const alt = (uploadNode.fields?.alt as string) || (uploadDoc as { alt?: string })?.alt || ''\n\n const url = uploadDoc.url\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDoc.mimeType.startsWith('image')) {\n return (\n <a href={url} rel=\"noopener noreferrer\">\n {uploadDoc.filename}\n </a>\n )\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (!uploadDoc.variants || !Object.keys(uploadDoc.variants).length) {\n return <img alt={alt} height={uploadDoc.height} src={url} width={uploadDoc.width} />\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n const pictureJSX: React.ReactNode[] = []\n\n // Iterate through each size in the data.variants object\n for (const size in uploadDoc.variants) {\n const imageSize = uploadDoc.variants[size] as FileSize\n\n // Skip if any property of the size object is null\n if (\n !imageSize ||\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue\n }\n const imageSizeURL = imageSize?.url\n\n pictureJSX.push(\n <source\n key={size}\n media={`(max-width: ${imageSize.width}px)`}\n srcSet={imageSizeURL}\n type={imageSize.mimeType}\n />,\n )\n }\n\n // Add the default img tag\n pictureJSX.push(\n <img alt={alt} height={uploadDoc?.height} key={'image'} src={url} width={uploadDoc?.width} />,\n )\n return <picture>{pictureJSX}</picture>\n },\n}\n"],"mappings":";AAMA,OAAO,MAAMA,kBAAA,GAA0D;EACrEC,MAAA,EAAQA,CAAC;IAAEC;EAAI,CAAE;IACf;IACA,MAAMC,UAAA,GAAaD,IAAA;IACnB,IAAI,OAAOC,UAAA,CAAWC,KAAK,K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C1CQ,MAAA,EAAQH,YAAA;QACRI,IAAA,EAAMN,SAAA,CAAUf;SAHXc,IAAA;IAMX;IAEA;IACAD,UAAA,CAAWK,IAAI,cACbhB,IAAA,CAAC;MAAIL,GAAA,EAAKA,GAAA;MAAKa,MAAA,EAAQd,SAAA,EAAWc,MAAA;MAAsBC,GAAA,EAAKZ,GAAA;MAAKa,KAAA,EAAOhB,SAAA,EAAWgB;OAArC;IAEjD,oBAAOV,IAAA,CAAC;gBAASW;;EACnB;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndentPlugin.d.ts","sourceRoot":"","sources":["../../../../src/features/indent/client/IndentPlugin.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IndentPlugin.d.ts","sourceRoot":"","sources":["../../../../src/features/indent/client/IndentPlugin.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAE5D,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,kBAAkB,CAmO5D,CAAA"}
|