@payloadcms/richtext-lexical 3.55.0-internal.f8c92b5 → 3.56.0-canary.0
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-SOED2PIU.js +2 -0
- package/dist/exports/client/{Field-Q3PTZQ75.js.map → Field-SOED2PIU.js.map} +3 -3
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-FSKAVN4P.js +2 -0
- package/dist/exports/client/{chunk-CYLMY5ZJ.js.map → chunk-FSKAVN4P.js.map} +2 -2
- package/dist/exports/client/chunk-KZKGNMS3.js +12 -0
- package/dist/exports/client/{chunk-YCH4JNUH.js.map → chunk-KZKGNMS3.js.map} +2 -2
- package/dist/exports/client/{component-3PENNOM3.js → component-M3U253XK.js} +2 -2
- package/dist/exports/client/index.d.ts +0 -2
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +10 -10
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/server/rsc.d.ts +0 -1
- package/dist/exports/server/rsc.d.ts.map +1 -1
- package/dist/exports/server/rsc.js +0 -1
- package/dist/exports/server/rsc.js.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +10 -8
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/upload.js +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/upload.js +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/upload.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js +39 -124
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js +8 -6
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +3 -3
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/relationship/client/plugins/index.js +37 -20
- package/dist/features/relationship/client/plugins/index.js.map +1 -1
- package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js +53 -28
- package/dist/features/relationship/client/utils/EnabledRelationshipsCondition.js.map +1 -1
- package/dist/features/textState/feature.client.js +3 -1
- package/dist/features/textState/feature.client.js.map +1 -1
- package/dist/features/textState/feature.server.d.ts.map +1 -1
- package/dist/features/textState/feature.server.js +3 -1
- package/dist/features/textState/feature.server.js.map +1 -1
- package/dist/features/textState/i18n.d.ts +3 -0
- package/dist/features/textState/i18n.d.ts.map +1 -0
- package/dist/features/textState/i18n.js +108 -0
- package/dist/features/textState/i18n.js.map +1 -0
- package/dist/features/toolbars/shared/ToolbarButton/index.js +37 -35
- package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js +30 -20
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.js +35 -22
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js +15 -7
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +15 -7
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +141 -75
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +3 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
- package/dist/lexical/ui/ContentEditable.js +11 -2
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/lexical-proxy/@lexical-react/LexicalNodeContextMenuPlugin.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalNodeContextMenuPlugin.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/LexicalNodeContextMenuPlugin.js +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalNodeContextMenuPlugin.js.map +1 -0
- package/dist/nodeTypes.d.ts +1 -13
- package/dist/nodeTypes.d.ts.map +1 -1
- package/dist/nodeTypes.js +1 -4
- package/dist/nodeTypes.js.map +1 -1
- package/package.json +26 -21
- package/dist/exports/client/Field-Q3PTZQ75.js +0 -2
- package/dist/exports/client/chunk-CYLMY5ZJ.js +0 -2
- package/dist/exports/client/chunk-YCH4JNUH.js +0 -12
- package/dist/field/RenderLexical/renderLexical.d.ts +0 -38
- package/dist/field/RenderLexical/renderLexical.d.ts.map +0 -1
- package/dist/field/RenderLexical/renderLexical.js +0 -96
- package/dist/field/RenderLexical/renderLexical.js.map +0 -1
- package/dist/field/RenderLexical/useRenderEditor.d.ts +0 -15
- package/dist/field/RenderLexical/useRenderEditor.d.ts.map +0 -1
- package/dist/field/RenderLexical/useRenderEditor.js +0 -159
- package/dist/field/RenderLexical/useRenderEditor.js.map +0 -1
- package/dist/utilities/buildEditorState.d.ts +0 -11
- package/dist/utilities/buildEditorState.d.ts.map +0 -1
- package/dist/utilities/buildEditorState.js +0 -76
- package/dist/utilities/buildEditorState.js.map +0 -1
- /package/dist/exports/client/{component-3PENNOM3.js.map → component-M3U253XK.js.map} +0 -0
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent';
|
|
2
|
-
import { getClientConfig } from '@payloadcms/ui/utilities/getClientConfig';
|
|
3
|
-
import { getClientSchemaMap } from '@payloadcms/ui/utilities/getClientSchemaMap';
|
|
4
|
-
import { getSchemaMap } from '@payloadcms/ui/utilities/getSchemaMap';
|
|
5
|
-
import { createClientField } from 'payload';
|
|
6
|
-
/**
|
|
7
|
-
* @experimental - may break in minor releases
|
|
8
|
-
*/
|
|
9
|
-
export const _internal_renderLexical = async ({
|
|
10
|
-
name,
|
|
11
|
-
admin,
|
|
12
|
-
editorTarget,
|
|
13
|
-
importMap,
|
|
14
|
-
initialValue,
|
|
15
|
-
path,
|
|
16
|
-
req,
|
|
17
|
-
schemaPath
|
|
18
|
-
}) => {
|
|
19
|
-
if (!req.user) {
|
|
20
|
-
throw new Error('Unauthorized');
|
|
21
|
-
}
|
|
22
|
-
const [entityType, entitySlug, ...fieldPath] = editorTarget.split('.');
|
|
23
|
-
const schemaMap = getSchemaMap({
|
|
24
|
-
collectionSlug: entityType === 'collection' ? entitySlug : undefined,
|
|
25
|
-
config: req.payload.config,
|
|
26
|
-
globalSlug: entityType === 'global' ? entitySlug : undefined,
|
|
27
|
-
i18n: req.i18n
|
|
28
|
-
});
|
|
29
|
-
const targetField = schemaMap.get(`${entitySlug}.${fieldPath.join('.')}`);
|
|
30
|
-
if (!targetField?.editor || typeof targetField.editor === 'function') {
|
|
31
|
-
throw new Error(`No editor found for target: ${editorTarget}`);
|
|
32
|
-
}
|
|
33
|
-
const sanitizedEditor = targetField.editor;
|
|
34
|
-
if (!sanitizedEditor) {
|
|
35
|
-
throw new Error(`No editor found for target: ${editorTarget}`);
|
|
36
|
-
}
|
|
37
|
-
const field = {
|
|
38
|
-
name,
|
|
39
|
-
type: 'richText',
|
|
40
|
-
editor: sanitizedEditor
|
|
41
|
-
};
|
|
42
|
-
// Provide client schema map as it would have been provided if the target editor field would have been rendered.
|
|
43
|
-
// Only then will it contain all the lexical-internal entries
|
|
44
|
-
const clientSchemaMap = getClientSchemaMap({
|
|
45
|
-
collectionSlug: entityType === 'collection' ? entitySlug : undefined,
|
|
46
|
-
config: getClientConfig({
|
|
47
|
-
config: req.payload.config,
|
|
48
|
-
i18n: req.i18n,
|
|
49
|
-
importMap: req.payload.importMap
|
|
50
|
-
}),
|
|
51
|
-
globalSlug: entityType === 'global' ? entitySlug : undefined,
|
|
52
|
-
i18n: req.i18n,
|
|
53
|
-
payload: req.payload,
|
|
54
|
-
schemaMap
|
|
55
|
-
});
|
|
56
|
-
const FieldComponent = RenderServerComponent({
|
|
57
|
-
Component: sanitizedEditor.FieldComponent,
|
|
58
|
-
importMap,
|
|
59
|
-
serverProps: {
|
|
60
|
-
admin: admin ?? {},
|
|
61
|
-
clientField: createClientField({
|
|
62
|
-
defaultIDType: req.payload.db.defaultIDType,
|
|
63
|
-
field,
|
|
64
|
-
i18n: req.i18n,
|
|
65
|
-
importMap
|
|
66
|
-
}),
|
|
67
|
-
clientFieldSchemaMap: clientSchemaMap,
|
|
68
|
-
// collectionSlug is typed incorrectly - @todo make it accept undefined in 4.0
|
|
69
|
-
collectionSlug: entityType === 'collection' && entitySlug ? entitySlug : '-',
|
|
70
|
-
data: {},
|
|
71
|
-
field,
|
|
72
|
-
fieldSchemaMap: schemaMap,
|
|
73
|
-
forceRender: true,
|
|
74
|
-
formState: {},
|
|
75
|
-
i18n: req.i18n,
|
|
76
|
-
operation: 'create',
|
|
77
|
-
path: path ?? name,
|
|
78
|
-
payload: req.payload,
|
|
79
|
-
permissions: true,
|
|
80
|
-
preferences: {
|
|
81
|
-
fields: {}
|
|
82
|
-
},
|
|
83
|
-
req,
|
|
84
|
-
sanitizedEditorConfig: sanitizedEditor.editorConfig,
|
|
85
|
-
schemaPath: schemaPath ?? name,
|
|
86
|
-
siblingData: initialValue ? {
|
|
87
|
-
[name]: initialValue
|
|
88
|
-
} : {},
|
|
89
|
-
user: req.user
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return {
|
|
93
|
-
Component: FieldComponent
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=renderLexical.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renderLexical.js","names":["RenderServerComponent","getClientConfig","getClientSchemaMap","getSchemaMap","createClientField","_internal_renderLexical","name","admin","editorTarget","importMap","initialValue","path","req","schemaPath","user","Error","entityType","entitySlug","fieldPath","split","schemaMap","collectionSlug","undefined","config","payload","globalSlug","i18n","targetField","get","join","editor","sanitizedEditor","field","type","clientSchemaMap","FieldComponent","Component","serverProps","clientField","defaultIDType","db","clientFieldSchemaMap","data","fieldSchemaMap","forceRender","formState","operation","permissions","preferences","fields","sanitizedEditorConfig","editorConfig","siblingData"],"sources":["../../../src/field/RenderLexical/renderLexical.tsx"],"sourcesContent":["import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'\nimport { getClientConfig } from '@payloadcms/ui/utilities/getClientConfig'\nimport { getClientSchemaMap } from '@payloadcms/ui/utilities/getClientSchemaMap'\nimport { getSchemaMap } from '@payloadcms/ui/utilities/getSchemaMap'\nimport {\n createClientField,\n type RichTextField,\n type RichTextFieldClient,\n type RichTextFieldServerProps,\n type ServerFunction,\n} from 'payload'\n\nimport {\n type DefaultTypedEditorState,\n type LexicalFieldAdminProps,\n type LexicalRichTextAdapter,\n type SanitizedServerEditorConfig,\n} from '../../index.js'\n\nexport type RenderLexicalServerFunctionArgs = {\n admin?: LexicalFieldAdminProps\n /**\n * {global|collection}.entitySlug.fieldSchemaPath\n *\n * @example collection.posts.richText\n */\n editorTarget: string\n /**\n * Pass the value this richtext field will receive when rendering it on the server.\n * This helps provide initial state for sub-fields that are immediately rendered (like blocks)\n * so that we can avoid multiple waterfall requests for each block that renders on the client.\n */\n initialValue?: DefaultTypedEditorState\n /**\n * Name of the field to render\n */\n name: string\n /**\n * Path to the field to render\n * @default field name\n */\n path?: string\n /**\n * Schema path to the field to render.\n */\n schemaPath: string\n}\nexport type RenderLexicalServerFunctionReturnType = { Component: React.ReactNode }\n\n/**\n * @experimental - may break in minor releases\n */\nexport const _internal_renderLexical: ServerFunction<\n RenderLexicalServerFunctionArgs,\n Promise<RenderLexicalServerFunctionReturnType>\n // eslint-disable-next-line @typescript-eslint/require-await\n> = async ({ name, admin, editorTarget, importMap, initialValue, path, req, schemaPath }) => {\n if (!req.user) {\n throw new Error('Unauthorized')\n }\n\n const [entityType, entitySlug, ...fieldPath] = editorTarget.split('.')\n\n const schemaMap = getSchemaMap({\n collectionSlug: entityType === 'collection' ? entitySlug : undefined,\n config: req.payload.config,\n globalSlug: entityType === 'global' ? entitySlug : undefined,\n i18n: req.i18n,\n })\n\n const targetField = schemaMap.get(`${entitySlug}.${fieldPath.join('.')}`) as\n | RichTextField\n | undefined\n\n if (!targetField?.editor || typeof targetField.editor === 'function') {\n throw new Error(`No editor found for target: ${editorTarget}`)\n }\n\n const sanitizedEditor = targetField.editor as LexicalRichTextAdapter\n\n if (!sanitizedEditor) {\n throw new Error(`No editor found for target: ${editorTarget}`)\n }\n\n const field: RichTextField = {\n name,\n type: 'richText',\n editor: sanitizedEditor,\n }\n\n // Provide client schema map as it would have been provided if the target editor field would have been rendered.\n // Only then will it contain all the lexical-internal entries\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug: entityType === 'collection' ? entitySlug : undefined,\n config: getClientConfig({\n config: req.payload.config,\n i18n: req.i18n,\n importMap: req.payload.importMap,\n }),\n globalSlug: entityType === 'global' ? entitySlug : undefined,\n i18n: req.i18n,\n payload: req.payload,\n schemaMap,\n })\n\n const FieldComponent = RenderServerComponent({\n Component: sanitizedEditor.FieldComponent,\n importMap,\n serverProps: {\n admin: admin ?? {},\n clientField: createClientField({\n defaultIDType: req.payload.db.defaultIDType,\n field,\n i18n: req.i18n,\n importMap,\n }) as RichTextFieldClient,\n clientFieldSchemaMap: clientSchemaMap,\n // collectionSlug is typed incorrectly - @todo make it accept undefined in 4.0\n collectionSlug: entityType === 'collection' && entitySlug ? entitySlug : '-',\n data: {},\n field,\n fieldSchemaMap: schemaMap,\n forceRender: true,\n formState: {},\n i18n: req.i18n,\n operation: 'create',\n path: path ?? name,\n payload: req.payload,\n permissions: true,\n preferences: {\n fields: {},\n },\n req,\n sanitizedEditorConfig: sanitizedEditor.editorConfig,\n schemaPath: schemaPath ?? name,\n siblingData: initialValue\n ? {\n [name]: initialValue,\n }\n : {},\n user: req.user,\n } satisfies {\n admin: LexicalFieldAdminProps // <= new in 3.26.0\n sanitizedEditorConfig: SanitizedServerEditorConfig\n } & RichTextFieldServerProps,\n })\n\n return {\n Component: FieldComponent,\n }\n}\n"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ;AACtC,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SACEC,iBAAiB,QAKZ;AAuCP;;;AAGA,OAAO,MAAMC,uBAAA,GAIT,MAAAA,CAAO;EAAEC,IAAI;EAAEC,KAAK;EAAEC,YAAY;EAAEC,SAAS;EAAEC,YAAY;EAAEC,IAAI;EAAEC,GAAG;EAAEC;AAAU,CAAE;EACtF,IAAI,CAACD,GAAA,CAAIE,IAAI,EAAE;IACb,MAAM,IAAIC,KAAA,CAAM;EAClB;EAEA,MAAM,CAACC,UAAA,EAAYC,UAAA,EAAY,GAAGC,SAAA,CAAU,GAAGV,YAAA,CAAaW,KAAK,CAAC;EAElE,MAAMC,SAAA,GAAYjB,YAAA,CAAa;IAC7BkB,cAAA,EAAgBL,UAAA,KAAe,eAAeC,UAAA,GAAaK,SAAA;IAC3DC,MAAA,EAAQX,GAAA,CAAIY,OAAO,CAACD,MAAM;IAC1BE,UAAA,EAAYT,UAAA,KAAe,WAAWC,UAAA,GAAaK,SAAA;IACnDI,IAAA,EAAMd,GAAA,CAAIc;EACZ;EAEA,MAAMC,WAAA,GAAcP,SAAA,CAAUQ,GAAG,CAAC,GAAGX,UAAA,IAAcC,SAAA,CAAUW,IAAI,CAAC,MAAM;EAIxE,IAAI,CAACF,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ACzEyB,IAAA,EAAM,CAAC;MACPV,KAAA;MACAW,cAAA,EAAgBvB,SAAA;MAChBwB,WAAA,EAAa;MACbC,SAAA,EAAW,CAAC;MACZnB,IAAA,EAAMd,GAAA,CAAIc,IAAI;MACdoB,SAAA,EAAW;MACXnC,IAAA,EAAMA,IAAA,IAAQL,IAAA;MACdkB,OAAA,EAASZ,GAAA,CAAIY,OAAO;MACpBuB,WAAA,EAAa;MACbC,WAAA,EAAa;QACXC,MAAA,EAAQ,CAAC;MACX;MACArC,GAAA;MACAsC,qBAAA,EAAuBnB,eAAA,CAAgBoB,YAAY;MACnDtC,UAAA,EAAYA,UAAA,IAAcP,IAAA;MAC1B8C,WAAA,EAAa1C,YAAA,GACT;QACE,CAACJ,IAAA,GAAOI;MACV,IACA,CAAC;MACLI,IAAA,EAAMF,GAAA,CAAIE;IACZ;EAIF;EAEA,OAAO;IACLsB,SAAA,EAAWD;EACb;AACF","ignoreList":[]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type FieldType } from '@payloadcms/ui';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import type { DefaultTypedEditorState } from '../../nodeTypes.js';
|
|
4
|
-
import type { RenderLexicalServerFunctionArgs } from './renderLexical.js';
|
|
5
|
-
/**
|
|
6
|
-
* @experimental - may break in minor releases
|
|
7
|
-
*/
|
|
8
|
-
export declare const useRenderEditor_internal_: (args: Omit<RenderLexicalServerFunctionArgs, "initialValue" | "schemaPath">) => {
|
|
9
|
-
Component: ({ setValue, value, }: {
|
|
10
|
-
setValue?: FieldType<DefaultTypedEditorState | undefined>["setValue"];
|
|
11
|
-
value?: FieldType<DefaultTypedEditorState | undefined>["value"];
|
|
12
|
-
}) => React.JSX.Element | null;
|
|
13
|
-
renderLexical: (args?: Pick<RenderLexicalServerFunctionArgs, "initialValue">) => void;
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=useRenderEditor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRenderEditor.d.ts","sourceRoot":"","sources":["../../../src/field/RenderLexical/useRenderEditor.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,SAAS,EAIf,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAsB,MAAM,OAAO,CAAA;AAE1C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,KAAK,EACV,+BAA+B,EAEhC,MAAM,oBAAoB,CAAA;AAE3B;;GAEG;AACH,eAAO,MAAM,yBAAyB,SAC9B,IAAI,CAAC,+BAA+B,EAAE,cAAc,GAAG,YAAY,CAAC;sCAuCxE;QACE,QAAQ,CAAC,EAAE,SAAS,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAAC,UAAU,CAAC,CAAA;QAErE,KAAK,CAAC,EAAE,SAAS,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAAC,OAAO,CAAC,CAAA;KAChE;2BAjCO,IAAI,CAAC,+BAA+B,EAAE,cAAc,CAAC;CA2FhE,CAAA"}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { c as _c } from "react/compiler-runtime";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
import { FieldContext, FieldPathContext, ServerFunctionsContext, useServerFunctions } from '@payloadcms/ui';
|
|
6
|
-
import React, { useCallback } from 'react';
|
|
7
|
-
/**
|
|
8
|
-
* @experimental - may break in minor releases
|
|
9
|
-
*/
|
|
10
|
-
export const useRenderEditor_internal_ = args => {
|
|
11
|
-
const $ = _c(24);
|
|
12
|
-
const {
|
|
13
|
-
name,
|
|
14
|
-
admin,
|
|
15
|
-
editorTarget,
|
|
16
|
-
path
|
|
17
|
-
} = args;
|
|
18
|
-
const [Component, setComponent] = React.useState(null);
|
|
19
|
-
const serverFunctionContext = useServerFunctions();
|
|
20
|
-
const {
|
|
21
|
-
serverFunction
|
|
22
|
-
} = serverFunctionContext;
|
|
23
|
-
let t0;
|
|
24
|
-
if ($[0] !== editorTarget) {
|
|
25
|
-
t0 = editorTarget.split(".");
|
|
26
|
-
$[0] = editorTarget;
|
|
27
|
-
$[1] = t0;
|
|
28
|
-
} else {
|
|
29
|
-
t0 = $[1];
|
|
30
|
-
}
|
|
31
|
-
let entitySlug;
|
|
32
|
-
let entityType;
|
|
33
|
-
let fieldPath;
|
|
34
|
-
if ($[2] !== t0) {
|
|
35
|
-
[entityType, entitySlug, ...fieldPath] = t0;
|
|
36
|
-
$[2] = t0;
|
|
37
|
-
$[3] = entitySlug;
|
|
38
|
-
$[4] = entityType;
|
|
39
|
-
$[5] = fieldPath;
|
|
40
|
-
} else {
|
|
41
|
-
entitySlug = $[3];
|
|
42
|
-
entityType = $[4];
|
|
43
|
-
fieldPath = $[5];
|
|
44
|
-
}
|
|
45
|
-
let t1;
|
|
46
|
-
if ($[6] !== admin || $[7] !== editorTarget || $[8] !== entitySlug || $[9] !== fieldPath || $[10] !== name || $[11] !== path || $[12] !== serverFunction) {
|
|
47
|
-
t1 = args_0 => {
|
|
48
|
-
const render = async function render() {
|
|
49
|
-
const {
|
|
50
|
-
Component: Component_0
|
|
51
|
-
} = await serverFunction({
|
|
52
|
-
name: "render-lexical",
|
|
53
|
-
args: {
|
|
54
|
-
name,
|
|
55
|
-
admin,
|
|
56
|
-
editorTarget,
|
|
57
|
-
initialValue: args_0?.initialValue ?? undefined,
|
|
58
|
-
path,
|
|
59
|
-
schemaPath: `${entitySlug}.${fieldPath.join(".")}`
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
setComponent(Component_0);
|
|
63
|
-
};
|
|
64
|
-
render();
|
|
65
|
-
};
|
|
66
|
-
$[6] = admin;
|
|
67
|
-
$[7] = editorTarget;
|
|
68
|
-
$[8] = entitySlug;
|
|
69
|
-
$[9] = fieldPath;
|
|
70
|
-
$[10] = name;
|
|
71
|
-
$[11] = path;
|
|
72
|
-
$[12] = serverFunction;
|
|
73
|
-
$[13] = t1;
|
|
74
|
-
} else {
|
|
75
|
-
t1 = $[13];
|
|
76
|
-
}
|
|
77
|
-
const renderLexical = t1;
|
|
78
|
-
let t2;
|
|
79
|
-
if ($[14] !== Component || $[15] !== entitySlug || $[16] !== entityType || $[17] !== name || $[18] !== path || $[19] !== serverFunctionContext) {
|
|
80
|
-
t2 = function Memoized(t3) {
|
|
81
|
-
const {
|
|
82
|
-
setValue,
|
|
83
|
-
value
|
|
84
|
-
} = t3;
|
|
85
|
-
if (!Component) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
const adjustedServerFunctionContext = {
|
|
89
|
-
...serverFunctionContext,
|
|
90
|
-
getFormState: async getFormStateArgs => serverFunctionContext.getFormState({
|
|
91
|
-
...getFormStateArgs,
|
|
92
|
-
collectionSlug: entityType === "collection" ? entitySlug : undefined,
|
|
93
|
-
globalSlug: entityType === "global" ? entitySlug : undefined
|
|
94
|
-
})
|
|
95
|
-
};
|
|
96
|
-
const fieldPath_0 = path ?? name;
|
|
97
|
-
if (typeof value === "undefined" && !setValue) {
|
|
98
|
-
return _jsx(ServerFunctionsContext, {
|
|
99
|
-
value: {
|
|
100
|
-
...adjustedServerFunctionContext
|
|
101
|
-
},
|
|
102
|
-
children: _jsx(FieldPathContext, {
|
|
103
|
-
value: fieldPath_0,
|
|
104
|
-
children: Component
|
|
105
|
-
}, fieldPath_0)
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
const fieldValue = {
|
|
109
|
-
disabled: false,
|
|
110
|
-
formInitializing: false,
|
|
111
|
-
formProcessing: false,
|
|
112
|
-
formSubmitted: false,
|
|
113
|
-
initialValue: value,
|
|
114
|
-
path: fieldPath_0,
|
|
115
|
-
setValue: setValue ?? _temp,
|
|
116
|
-
showError: false,
|
|
117
|
-
value
|
|
118
|
-
};
|
|
119
|
-
return _jsx(ServerFunctionsContext, {
|
|
120
|
-
value: {
|
|
121
|
-
...adjustedServerFunctionContext
|
|
122
|
-
},
|
|
123
|
-
children: _jsx(FieldPathContext, {
|
|
124
|
-
value: fieldPath_0,
|
|
125
|
-
children: _jsx(FieldContext, {
|
|
126
|
-
value: fieldValue,
|
|
127
|
-
children: Component
|
|
128
|
-
})
|
|
129
|
-
}, fieldPath_0)
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
$[14] = Component;
|
|
133
|
-
$[15] = entitySlug;
|
|
134
|
-
$[16] = entityType;
|
|
135
|
-
$[17] = name;
|
|
136
|
-
$[18] = path;
|
|
137
|
-
$[19] = serverFunctionContext;
|
|
138
|
-
$[20] = t2;
|
|
139
|
-
} else {
|
|
140
|
-
t2 = $[20];
|
|
141
|
-
}
|
|
142
|
-
const Memoized = t2;
|
|
143
|
-
const WrappedComponent = Memoized;
|
|
144
|
-
let t3;
|
|
145
|
-
if ($[21] !== WrappedComponent || $[22] !== renderLexical) {
|
|
146
|
-
t3 = {
|
|
147
|
-
Component: WrappedComponent,
|
|
148
|
-
renderLexical
|
|
149
|
-
};
|
|
150
|
-
$[21] = WrappedComponent;
|
|
151
|
-
$[22] = renderLexical;
|
|
152
|
-
$[23] = t3;
|
|
153
|
-
} else {
|
|
154
|
-
t3 = $[23];
|
|
155
|
-
}
|
|
156
|
-
return t3;
|
|
157
|
-
};
|
|
158
|
-
function _temp() {}
|
|
159
|
-
//# sourceMappingURL=useRenderEditor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRenderEditor.js","names":["c","_c","FieldContext","FieldPathContext","ServerFunctionsContext","useServerFunctions","React","useCallback","useRenderEditor_internal_","args","$","name","admin","editorTarget","path","Component","setComponent","useState","serverFunctionContext","serverFunction","t0","split","entitySlug","entityType","fieldPath","t1","args_0","render","Component_0","initialValue","undefined","schemaPath","join","renderLexical","t2","Memoized","t3","setValue","value","adjustedServerFunctionContext","getFormState","getFormStateArgs","collectionSlug","globalSlug","fieldPath_0","_jsx","children","fieldValue","disabled","formInitializing","formProcessing","formSubmitted","_temp","showError","WrappedComponent"],"sources":["../../../src/field/RenderLexical/useRenderEditor.tsx"],"sourcesContent":["'use client'\nimport {\n FieldContext,\n FieldPathContext,\n type FieldType,\n ServerFunctionsContext,\n type ServerFunctionsContextType,\n useServerFunctions,\n} from '@payloadcms/ui'\nimport React, { useCallback } from 'react'\n\nimport type { DefaultTypedEditorState } from '../../nodeTypes.js'\nimport type {\n RenderLexicalServerFunctionArgs,\n RenderLexicalServerFunctionReturnType,\n} from './renderLexical.js'\n\n/**\n * @experimental - may break in minor releases\n */\nexport const useRenderEditor_internal_ = (\n args: Omit<RenderLexicalServerFunctionArgs, 'initialValue' | 'schemaPath'>,\n) => {\n const { name, admin, editorTarget, path } = args\n const [Component, setComponent] = React.useState<null | React.ReactNode>(null)\n const serverFunctionContext = useServerFunctions()\n const { serverFunction } = serverFunctionContext\n\n const [entityType, entitySlug, ...fieldPath] = editorTarget.split('.')\n\n const renderLexical = useCallback(\n (args?: Pick<RenderLexicalServerFunctionArgs, 'initialValue'>) => {\n async function render() {\n const { Component } = (await serverFunction({\n name: 'render-lexical',\n args: {\n name,\n admin,\n editorTarget,\n initialValue: args?.initialValue ?? undefined,\n path,\n schemaPath: `${entitySlug}.${fieldPath.join('.')}`,\n } satisfies RenderLexicalServerFunctionArgs,\n })) as RenderLexicalServerFunctionReturnType\n\n setComponent(Component)\n }\n void render()\n },\n [serverFunction, name, admin, editorTarget, path, entitySlug, fieldPath],\n )\n\n const WrappedComponent = React.useMemo(() => {\n function Memoized({\n setValue,\n value,\n }: /**\n * If value or setValue, or both, is provided, this component will manage its own value.\n * If neither is passed, it will rely on the parent form to manage the value.\n */\n {\n setValue?: FieldType<DefaultTypedEditorState | undefined>['setValue']\n\n value?: FieldType<DefaultTypedEditorState | undefined>['value']\n }) {\n if (!Component) {\n return null\n }\n\n /**\n * By default, the lexical will make form state requests (e.g. to get drawer fields), passing in the arguments\n * of the current field. However, we need to override those arguments to get it to make requests based on the\n * *target* field. The server only knows the schema map of the target field.\n */\n const adjustedServerFunctionContext: ServerFunctionsContextType = {\n ...serverFunctionContext,\n getFormState: async (getFormStateArgs) => {\n return serverFunctionContext.getFormState({\n ...getFormStateArgs,\n collectionSlug: entityType === 'collection' ? entitySlug : undefined,\n globalSlug: entityType === 'global' ? entitySlug : undefined,\n })\n },\n }\n\n const fieldPath = path ?? name\n\n if (typeof value === 'undefined' && !setValue) {\n return (\n <ServerFunctionsContext value={{ ...adjustedServerFunctionContext }}>\n <FieldPathContext key={fieldPath} value={fieldPath}>\n {Component}\n </FieldPathContext>\n </ServerFunctionsContext>\n )\n }\n\n const fieldValue: FieldType<DefaultTypedEditorState | undefined> = {\n disabled: false,\n formInitializing: false,\n formProcessing: false,\n formSubmitted: false,\n initialValue: value,\n path: fieldPath,\n setValue: setValue ?? (() => undefined),\n showError: false,\n value,\n }\n\n return (\n <ServerFunctionsContext value={{ ...adjustedServerFunctionContext }}>\n <FieldPathContext key={fieldPath} value={fieldPath}>\n <FieldContext value={fieldValue}>{Component}</FieldContext>\n </FieldPathContext>\n </ServerFunctionsContext>\n )\n }\n\n return Memoized\n }, [Component, serverFunctionContext, path, name, entityType, entitySlug])\n\n return { Component: WrappedComponent, renderLexical }\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,SACEC,YAAY,EACZC,gBAAgB,EAEhBC,sBAAsB,EAEtBC,kBAAkB,QACb;AACP,OAAOC,KAAA,IAASC,WAAW,QAAQ;AAQnC;;;AAGA,OAAO,MAAMC,yBAAA,GAA4BC,IAAA;EAAA,MAAAC,CAAA,GAAAT,EAAA;EAGvC;IAAAU,IAAA;IAAAC,KAAA;IAAAC,YAAA;IAAAC;EAAA,IAA4CL,IAAA;EAC5C,OAAAM,SAAA,EAAAC,YAAA,IAAkCV,KAAA,CAAAW,QAAA,KAAuC;EACzE,MAAAC,qBAAA,GAA8Bb,kBAAA;EAC9B;IAAAc;EAAA,IAA2BD,qBAAA;EAAA,IAAAE,EAAA;EAAA,IAAAV,CAAA,QAAAG,YA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AAA,CAAAzC,sBAAA;QAAAkC,KAAA;UAAA,GAAoCC;QAA6B;QAAAO,QAAA,EAC/DD,IAAA,CAAA1C,gBAAA;UAAAmC,KAAA,EAAyCd,WAAA;UAAAsB,QAAA,EACvCD,IAAA,CAAA3C,YAAA;YAAAoC,KAAA,EAAqBS,UAAA;YAAAD,QAAA,EAAa/B;UAAA,C;WADbS,WAAA;MAAA,C;;IAK7Bd,CAAA,OAAAK,SAAA;IAAAL,CAAA,OAAAY,UAAA;IAAAZ,CAAA,OAAAa,UAAA;IAAAb,CAAA,OAAAC,IAAA;IAAAD,CAAA,OAAAI,IAAA;IAAAJ,CAAA,OAAAQ,qBAAA;IAAAR,CAAA,OAAAwB,EAAA;EAAA;IAAAA,EAAA,GAAAxB,CAAA;EAAA;EA/DA,MAAAyB,QAAA,GAAAD,EA+DA;EAhEF,MAAAoB,gBAAA,GAkESnB,QAAA;EACgE,IAAAC,EAAA;EAAA,IAAA1B,CAAA,SAAA4C,gBAAA,IAAA5C,CAAA,SAAAuB,aAAA;IAElEG,EAAA;MAAArB,SAAA,EAAauC,gBAAA;MAAArB;IAAA;IAAgCvB,CAAA,OAAA4C,gBAAA;IAAA5C,CAAA,OAAAuB,aAAA;IAAAvB,CAAA,OAAA0B,EAAA;EAAA;IAAAA,EAAA,GAAA1B,CAAA;EAAA;EAAA,OAA7C0B,EAA6C;AAAA,CACtD;AAtGyC,SAAAgB,MAAA","ignoreList":[]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { SerializedLexicalNode } from 'lexical';
|
|
2
|
-
import type { DefaultTypedEditorState, TypedEditorState } from '../nodeTypes.js';
|
|
3
|
-
export declare function buildEditorState(args: {
|
|
4
|
-
nodes?: DefaultTypedEditorState['root']['children'];
|
|
5
|
-
text?: string;
|
|
6
|
-
}): DefaultTypedEditorState;
|
|
7
|
-
export declare function buildEditorState<T extends SerializedLexicalNode>(args: {
|
|
8
|
-
nodes?: TypedEditorState<T>['root']['children'];
|
|
9
|
-
text?: string;
|
|
10
|
-
}): TypedEditorState<T>;
|
|
11
|
-
//# sourceMappingURL=buildEditorState.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildEditorState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildEditorState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEhF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,KAAK,CAAC,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAA;IACnD,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,GAAG,uBAAuB,CAAA;AAE3B,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,qBAAqB,EAAE,IAAI,EAAE;IAEtE,KAAK,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAA;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper to build lexical editor state JSON from text and/or nodes.
|
|
3
|
-
*
|
|
4
|
-
* @param nodes - The nodes to include in the editor state. If you pass the `text` argument, this will append your nodes after the first paragraph node.
|
|
5
|
-
* @param text - The text content to include in the editor state. This will create a paragraph node with a text node for you and set that as the first node.
|
|
6
|
-
* @returns The constructed editor state JSON.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* just passing text:
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const editorState = buildEditorState({ text: 'Hello world' }) // result typed as DefaultTypedEditorState
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* passing nodes:
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* const editorState = // result typed as TypedEditorState<DefaultNodeTypes | SerializedBlockNode> (or TypedEditorState<SerializedBlockNode>)
|
|
22
|
-
* buildEditorState<DefaultNodeTypes | SerializedBlockNode>({ // or just buildEditorState<SerializedBlockNode> if you *only* want to allow block nodes
|
|
23
|
-
* nodes: [
|
|
24
|
-
* {
|
|
25
|
-
* type: 'block',
|
|
26
|
-
* fields: {
|
|
27
|
-
* id: 'id',
|
|
28
|
-
* blockName: 'Cool block',
|
|
29
|
-
* blockType: 'myBlock',
|
|
30
|
-
* },
|
|
31
|
-
* format: 'left',
|
|
32
|
-
* version: 1,
|
|
33
|
-
* }
|
|
34
|
-
* ],
|
|
35
|
-
* })
|
|
36
|
-
* ```
|
|
37
|
-
*/export function buildEditorState({
|
|
38
|
-
nodes,
|
|
39
|
-
text
|
|
40
|
-
}) {
|
|
41
|
-
const editorJSON = {
|
|
42
|
-
root: {
|
|
43
|
-
type: 'root',
|
|
44
|
-
children: [],
|
|
45
|
-
direction: 'ltr',
|
|
46
|
-
format: '',
|
|
47
|
-
indent: 0,
|
|
48
|
-
version: 1
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
if (text) {
|
|
52
|
-
editorJSON.root.children.push({
|
|
53
|
-
type: 'paragraph',
|
|
54
|
-
children: [{
|
|
55
|
-
type: 'text',
|
|
56
|
-
detail: 0,
|
|
57
|
-
format: 0,
|
|
58
|
-
mode: 'normal',
|
|
59
|
-
style: '',
|
|
60
|
-
text,
|
|
61
|
-
version: 1
|
|
62
|
-
}],
|
|
63
|
-
direction: 'ltr',
|
|
64
|
-
format: '',
|
|
65
|
-
indent: 0,
|
|
66
|
-
textFormat: 0,
|
|
67
|
-
textStyle: '',
|
|
68
|
-
version: 1
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (nodes?.length) {
|
|
72
|
-
editorJSON.root.children.push(...nodes);
|
|
73
|
-
}
|
|
74
|
-
return editorJSON;
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=buildEditorState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildEditorState.js","names":["buildEditorState","nodes","text","editorJSON","root","type","children","direction","format","indent","version","push","detail","mode","style","textFormat","textStyle","length"],"sources":["../../src/utilities/buildEditorState.ts"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\n\nimport type { DefaultTypedEditorState, TypedEditorState } from '../nodeTypes.js'\n\nexport function buildEditorState(args: {\n nodes?: DefaultTypedEditorState['root']['children']\n text?: string\n}): DefaultTypedEditorState\n\nexport function buildEditorState<T extends SerializedLexicalNode>(args: {\n // If you pass children typed for a specific schema T, the return is TypedEditorState<T>\n nodes?: TypedEditorState<T>['root']['children']\n text?: string\n}): TypedEditorState<T>\n\n/**\n * Helper to build lexical editor state JSON from text and/or nodes.\n *\n * @param nodes - The nodes to include in the editor state. If you pass the `text` argument, this will append your nodes after the first paragraph node.\n * @param text - The text content to include in the editor state. This will create a paragraph node with a text node for you and set that as the first node.\n * @returns The constructed editor state JSON.\n *\n * @example\n *\n * just passing text:\n *\n * ```ts\n * const editorState = buildEditorState({ text: 'Hello world' }) // result typed as DefaultTypedEditorState\n * ```\n *\n * @example\n *\n * passing nodes:\n *\n * ```ts\n * const editorState = // result typed as TypedEditorState<DefaultNodeTypes | SerializedBlockNode> (or TypedEditorState<SerializedBlockNode>)\n * buildEditorState<DefaultNodeTypes | SerializedBlockNode>({ // or just buildEditorState<SerializedBlockNode> if you *only* want to allow block nodes\n * nodes: [\n * {\n * type: 'block',\n * fields: {\n * id: 'id',\n * blockName: 'Cool block',\n * blockType: 'myBlock',\n * },\n * format: 'left',\n * version: 1,\n * }\n * ],\n * })\n * ```\n */\nexport function buildEditorState<T extends SerializedLexicalNode>({\n nodes,\n text,\n}: {\n nodes?: DefaultTypedEditorState['root']['children'] | TypedEditorState<T>['root']['children']\n text?: string\n}): DefaultTypedEditorState | TypedEditorState<T> {\n const editorJSON: DefaultTypedEditorState = {\n root: {\n type: 'root',\n children: [],\n direction: 'ltr',\n format: '',\n indent: 0,\n version: 1,\n },\n }\n\n if (text) {\n editorJSON.root.children.push({\n type: 'paragraph',\n children: [\n {\n type: 'text',\n detail: 0,\n format: 0,\n mode: 'normal',\n style: '',\n text,\n version: 1,\n },\n ],\n direction: 'ltr',\n format: '',\n indent: 0,\n textFormat: 0,\n textStyle: '',\n version: 1,\n })\n }\n\n if (nodes?.length) {\n editorJSON.root.children.push(...(nodes as any))\n }\n\n return editorJSON\n}\n"],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCA,OAAO,SAASA,iBAAkD;EAChEC,KAAK;EACLC;AAAI,CAIL;EACC,MAAMC,UAAA,GAAsC;IAC1CC,IAAA,EAAM;MACJC,IAAA,EAAM;MACNC,QAAA,EAAU,EAAE;MACZC,SAAA,EAAW;MACXC,MAAA,EAAQ;MACRC,MAAA,EAAQ;MACRC,OAAA,EAAS;IACX;EACF;EAEA,IAAIR,IAAA,EAAM;IACRC,UAAA,CAAWC,IAAI,CAACE,QAAQ,CAACK,IAAI,CAAC;MAC5BN,IAAA,EAAM;MACNC,QAAA,EAAU,CACR;QACED,IAAA,EAAM;QACNO,MAAA,EAAQ;QACRJ,MAAA,EAAQ;QACRK,IAAA,EAAM;QACNC,KAAA,EAAO;QACPZ,IAAA;QACAQ,OAAA,EAAS;MACX,EACD;MACDH,SAAA,EAAW;MACXC,MAAA,EAAQ;MACRC,MAAA,EAAQ;MACRM,UAAA,EAAY;MACZC,SAAA,EAAW;MACXN,OAAA,EAAS;IACX;EACF;EAEA,IAAIT,KAAA,EAAOgB,MAAA,EAAQ;IACjBd,UAAA,CAAWC,IAAI,CAACE,QAAQ,CAACK,IAAI,IAAKV,KAAA;EACpC;EAEA,OAAOE,UAAA;AACT","ignoreList":[]}
|
|
File without changes
|