@payloadcms/richtext-lexical 3.55.0-internal.b47bfce → 3.55.0-internal.f8c92b5
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/bundled.css +1 -1
- package/dist/exports/client/index.d.ts +1 -1
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +9 -9
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/server/rsc.d.ts +1 -0
- package/dist/exports/server/rsc.d.ts.map +1 -1
- package/dist/exports/server/rsc.js +1 -0
- package/dist/exports/server/rsc.js.map +1 -1
- package/dist/field/RenderLexical/renderLexical.d.ts +38 -0
- package/dist/field/RenderLexical/renderLexical.d.ts.map +1 -0
- package/dist/field/RenderLexical/renderLexical.js +96 -0
- package/dist/field/RenderLexical/renderLexical.js.map +1 -0
- package/dist/field/RenderLexical/useRenderEditor.d.ts +15 -0
- package/dist/field/RenderLexical/useRenderEditor.d.ts.map +1 -0
- package/dist/field/RenderLexical/useRenderEditor.js +159 -0
- package/dist/field/RenderLexical/useRenderEditor.js.map +1 -0
- package/dist/field/bundled.css +1 -1
- package/package.json +6 -6
- package/dist/field/RenderLexical/index.d.ts +0 -19
- package/dist/field/RenderLexical/index.d.ts.map +0 -1
- package/dist/field/RenderLexical/index.js +0 -123
- package/dist/field/RenderLexical/index.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { RscEntryLexicalCell } from '../../cell/rscEntry.js';
|
|
2
2
|
export { LexicalDiffComponent } from '../../field/Diff/index.js';
|
|
3
|
+
export { _internal_renderLexical } from '../../field/RenderLexical/renderLexical.js';
|
|
3
4
|
export { RscEntryLexicalField } from '../../field/rscEntry.js';
|
|
4
5
|
//# sourceMappingURL=rsc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/exports/server/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/exports/server/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAA;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { RscEntryLexicalCell } from '../../cell/rscEntry.js';
|
|
2
2
|
export { LexicalDiffComponent } from '../../field/Diff/index.js';
|
|
3
|
+
export { _internal_renderLexical } from '../../field/RenderLexical/renderLexical.js';
|
|
3
4
|
export { RscEntryLexicalField } from '../../field/rscEntry.js';
|
|
4
5
|
//# sourceMappingURL=rsc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.js","names":["RscEntryLexicalCell","LexicalDiffComponent","RscEntryLexicalField"],"sources":["../../../src/exports/server/rsc.ts"],"sourcesContent":["export { RscEntryLexicalCell } from '../../cell/rscEntry.js'\nexport { LexicalDiffComponent } from '../../field/Diff/index.js'\nexport { RscEntryLexicalField } from '../../field/rscEntry.js'\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ;AACpC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,oBAAoB,QAAQ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"rsc.js","names":["RscEntryLexicalCell","LexicalDiffComponent","_internal_renderLexical","RscEntryLexicalField"],"sources":["../../../src/exports/server/rsc.ts"],"sourcesContent":["export { RscEntryLexicalCell } from '../../cell/rscEntry.js'\nexport { LexicalDiffComponent } from '../../field/Diff/index.js'\nexport { _internal_renderLexical } from '../../field/RenderLexical/renderLexical.js'\nexport { RscEntryLexicalField } from '../../field/rscEntry.js'\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ;AACpC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,oBAAoB,QAAQ","ignoreList":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ServerFunction } from 'payload';
|
|
2
|
+
import { type DefaultTypedEditorState, type LexicalFieldAdminProps } from '../../index.js';
|
|
3
|
+
export type RenderLexicalServerFunctionArgs = {
|
|
4
|
+
admin?: LexicalFieldAdminProps;
|
|
5
|
+
/**
|
|
6
|
+
* {global|collection}.entitySlug.fieldSchemaPath
|
|
7
|
+
*
|
|
8
|
+
* @example collection.posts.richText
|
|
9
|
+
*/
|
|
10
|
+
editorTarget: string;
|
|
11
|
+
/**
|
|
12
|
+
* Pass the value this richtext field will receive when rendering it on the server.
|
|
13
|
+
* This helps provide initial state for sub-fields that are immediately rendered (like blocks)
|
|
14
|
+
* so that we can avoid multiple waterfall requests for each block that renders on the client.
|
|
15
|
+
*/
|
|
16
|
+
initialValue?: DefaultTypedEditorState;
|
|
17
|
+
/**
|
|
18
|
+
* Name of the field to render
|
|
19
|
+
*/
|
|
20
|
+
name: string;
|
|
21
|
+
/**
|
|
22
|
+
* Path to the field to render
|
|
23
|
+
* @default field name
|
|
24
|
+
*/
|
|
25
|
+
path?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Schema path to the field to render.
|
|
28
|
+
*/
|
|
29
|
+
schemaPath: string;
|
|
30
|
+
};
|
|
31
|
+
export type RenderLexicalServerFunctionReturnType = {
|
|
32
|
+
Component: React.ReactNode;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @experimental - may break in minor releases
|
|
36
|
+
*/
|
|
37
|
+
export declare const _internal_renderLexical: ServerFunction<RenderLexicalServerFunctionArgs, Promise<RenderLexicalServerFunctionReturnType>>;
|
|
38
|
+
//# sourceMappingURL=renderLexical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderLexical.d.ts","sourceRoot":"","sources":["../../../src/field/RenderLexical/renderLexical.tsx"],"names":[],"mappings":"AAIA,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,SAAS,CAAA;AAEhB,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAG5B,MAAM,gBAAgB,CAAA;AAEvB,MAAM,MAAM,+BAA+B,GAAG;IAC5C,KAAK,CAAC,EAAE,sBAAsB,CAAA;IAC9B;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,uBAAuB,CAAA;IACtC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AACD,MAAM,MAAM,qCAAqC,GAAG;IAAE,SAAS,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAAA;AAElF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,cAAc,CAClD,+BAA+B,EAC/B,OAAO,CAAC,qCAAqC,CAAC,CAgG/C,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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\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X;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":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,YAAA;IAEoBO,EAAA,GAAAP,YAAA,CAAAQ,KAAA,CAAmB;IAAAX,CAAA,MAAAG,YAAA;IAAAH,CAAA,MAAAU,EAAA;EAAA;IAAAA,EAAA,GAAAV,CAAA;EAAA;EAAA,IAAAY,UAAA;EAAA,IAAAC,UAAA;EAAA,IAAAC,SAAA;EAAA,IAAAd,CAAA,QAAAU,EAAA;IAAlE,CAAAG,UAAA,EAAAD,UAAA,KAAAE,SAAA,IAA+CJ,EAAmB;IAAAV,CAAA,MA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