@payloadcms/ui 3.61.0-internal.dd40839 → 3.61.1
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/elements/DocumentDrawer/DrawerHeader/index.d.ts.map +1 -1
- package/dist/elements/DocumentDrawer/DrawerHeader/index.js +49 -21
- package/dist/elements/DocumentDrawer/DrawerHeader/index.js.map +1 -1
- package/dist/elements/LeaveWithoutSaving/index.d.ts +8 -0
- package/dist/elements/LeaveWithoutSaving/index.d.ts.map +1 -1
- package/dist/elements/LeaveWithoutSaving/index.js +72 -46
- package/dist/elements/LeaveWithoutSaving/index.js.map +1 -1
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.d.ts.map +1 -1
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.js +4 -2
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.js.map +1 -1
- package/dist/elements/PreviewButton/index.d.ts.map +1 -1
- package/dist/elements/PreviewButton/index.js +21 -27
- package/dist/elements/PreviewButton/index.js.map +1 -1
- package/dist/elements/PublishButton/index.d.ts.map +1 -1
- package/dist/elements/PublishButton/index.js +1 -0
- package/dist/elements/PublishButton/index.js.map +1 -1
- package/dist/elements/QueryPresets/cells/WhereCell/index.d.ts.map +1 -1
- package/dist/elements/QueryPresets/cells/WhereCell/index.js +5 -1
- package/dist/elements/QueryPresets/cells/WhereCell/index.js.map +1 -1
- package/dist/elements/withMergedProps/index.d.ts +1 -1
- package/dist/elements/withMergedProps/index.js +1 -1
- package/dist/elements/withMergedProps/index.js.map +1 -1
- package/dist/exports/client/index.js +24 -24
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/rsc/index.d.ts +1 -0
- package/dist/exports/rsc/index.d.ts.map +1 -1
- package/dist/exports/rsc/index.js +1 -0
- package/dist/exports/rsc/index.js.map +1 -1
- package/dist/exports/shared/index.js.map +1 -1
- package/dist/providers/LivePreview/context.d.ts +11 -0
- package/dist/providers/LivePreview/context.d.ts.map +1 -1
- package/dist/providers/LivePreview/context.js +18 -0
- package/dist/providers/LivePreview/context.js.map +1 -1
- package/dist/providers/LivePreview/index.d.ts +8 -0
- package/dist/providers/LivePreview/index.d.ts.map +1 -1
- package/dist/providers/LivePreview/index.js +6 -0
- package/dist/providers/LivePreview/index.js.map +1 -1
- package/dist/utilities/buildFormState.d.ts +2 -0
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js +18 -0
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/buildTableState.js +6 -1
- package/dist/utilities/buildTableState.js.map +1 -1
- package/dist/utilities/handlePreview.d.ts +33 -0
- package/dist/utilities/handlePreview.d.ts.map +1 -0
- package/dist/utilities/handlePreview.js +71 -0
- package/dist/utilities/handlePreview.js.map +1 -0
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +29 -17
- package/dist/views/Edit/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/elements/PreviewButton/usePreviewURL.d.ts +0 -9
- package/dist/elements/PreviewButton/usePreviewURL.d.ts.map +0 -1
- package/dist/elements/PreviewButton/usePreviewURL.js +0 -86
- package/dist/elements/PreviewButton/usePreviewURL.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,cAAc,EACf,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,cAAc,EACf,MAAM,SAAS,CAAA;AAchB,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;CACnC,CAAA;AAED,KAAK,2BAA2B,GAAG;IACjC,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,KAAK,yBAAyB,GAAG;IAC/B,cAAc,CAAC,EAAE,KAAK,CAAA;IACtB,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,UAAU,CAAC,EAAE,KAAK,CAAA;IAClB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,GAAG,CACA;IACE,OAAO,EAAE,MAAM,CAAA;CAChB,GACD,WAAW,CACd,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,yBAAyB,GAAG,2BAA2B,CAAA;AAE1F,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAChD,kBAAkB,EAClB,OAAO,CAAC,oBAAoB,CAAC,CAwB9B,CAAA;AAED,eAAO,MAAM,cAAc,SACnB,kBAAkB,KACvB,OAAO,CAAC,2BAA2B,CAoMrC,CAAA"}
|
|
@@ -7,6 +7,7 @@ import { getClientSchemaMap } from './getClientSchemaMap.js';
|
|
|
7
7
|
import { getSchemaMap } from './getSchemaMap.js';
|
|
8
8
|
import { handleFormStateLocking } from './handleFormStateLocking.js';
|
|
9
9
|
import { handleLivePreview } from './handleLivePreview.js';
|
|
10
|
+
import { handlePreview } from './handlePreview.js';
|
|
10
11
|
export const buildFormStateHandler = async args => {
|
|
11
12
|
const {
|
|
12
13
|
req
|
|
@@ -59,6 +60,7 @@ export const buildFormState = async args => {
|
|
|
59
60
|
},
|
|
60
61
|
returnLivePreviewURL,
|
|
61
62
|
returnLockStatus,
|
|
63
|
+
returnPreviewURL,
|
|
62
64
|
schemaPath = collectionSlug || globalSlug,
|
|
63
65
|
select,
|
|
64
66
|
skipClientConfigAuth,
|
|
@@ -183,6 +185,22 @@ export const buildFormState = async args => {
|
|
|
183
185
|
res.livePreviewURL = livePreviewURL;
|
|
184
186
|
}
|
|
185
187
|
}
|
|
188
|
+
if (returnPreviewURL) {
|
|
189
|
+
const {
|
|
190
|
+
previewURL
|
|
191
|
+
} = await handlePreview({
|
|
192
|
+
collectionSlug,
|
|
193
|
+
config,
|
|
194
|
+
data,
|
|
195
|
+
globalSlug,
|
|
196
|
+
req
|
|
197
|
+
});
|
|
198
|
+
// Important: only set this when not undefined,
|
|
199
|
+
// Otherwise it will travel through the network as `$undefined`
|
|
200
|
+
if (previewURL) {
|
|
201
|
+
res.previewURL = previewURL;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
186
204
|
return res;
|
|
187
205
|
};
|
|
188
206
|
//# sourceMappingURL=buildFormState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.js","names":["canAccessAdmin","formatErrors","getSelectMode","reduceFieldsToValues","fieldSchemasToFormState","renderField","getClientConfig","getClientSchemaMap","getSchemaMap","handleFormStateLocking","handleLivePreview","buildFormStateHandler","args","req","res","buildFormState","err","payload","logger","error","msg","message","Error","id","idFromArgs","collectionSlug","data","incomingData","docPermissions","docPreferences","documentFormState","formState","globalSlug","initialBlockData","initialBlockFormState","mockRSCs","operation","readOnly","renderAllFields","i18n","config","returnLivePreviewURL","returnLockStatus","schemaPath","select","skipClientConfigAuth","skipValidation","updateLastEdited","selectMode","undefined","schemaMap","clientSchemaMap","importMap","user","fieldOrEntityConfig","get","fields","length","type","documentData","blockData","Array","isArray","formStateResult","clientFieldSchemaMap","fieldSchemaMap","permissions","preferences","previousFormState","renderFieldFn","collections","upload","file","lockedStateResult","lockedState","state","livePreviewURL"],"sources":["../../src/utilities/buildFormState.ts"],"sourcesContent":["import type {\n BuildFormStateArgs,\n ClientConfig,\n ClientUser,\n ErrorResult,\n FormState,\n ServerFunction,\n} from 'payload'\n\nimport { canAccessAdmin, formatErrors } from 'payload'\nimport { getSelectMode, reduceFieldsToValues } from 'payload/shared'\n\nimport { fieldSchemasToFormState } from '../forms/fieldSchemasToFormState/index.js'\nimport { renderField } from '../forms/fieldSchemasToFormState/renderField.js'\nimport { getClientConfig } from './getClientConfig.js'\nimport { getClientSchemaMap } from './getClientSchemaMap.js'\nimport { getSchemaMap } from './getSchemaMap.js'\nimport { handleFormStateLocking } from './handleFormStateLocking.js'\nimport { handleLivePreview } from './handleLivePreview.js'\n\nexport type LockedState = {\n isLocked: boolean\n lastEditedAt: string\n user: ClientUser | number | string\n}\n\ntype BuildFormStateSuccessResult = {\n clientConfig?: ClientConfig\n errors?: never\n indexPath?: string\n livePreviewURL?: string\n lockedState?: LockedState\n state: FormState\n}\n\ntype BuildFormStateErrorResult = {\n livePreviewURL?: never\n lockedState?: never\n state?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildFormStateResult = BuildFormStateErrorResult | BuildFormStateSuccessResult\n\nexport const buildFormStateHandler: ServerFunction<\n BuildFormStateArgs,\n Promise<BuildFormStateResult>\n> = async (args) => {\n const { req } = args\n\n try {\n await canAccessAdmin({ req })\n const res = await buildFormState(args)\n\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n throw new Error('Unauthorized')\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildFormState = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateSuccessResult> => {\n const {\n id: idFromArgs,\n collectionSlug,\n data: incomingData,\n docPermissions,\n docPreferences,\n documentFormState,\n formState,\n globalSlug,\n initialBlockData,\n initialBlockFormState,\n mockRSCs,\n operation,\n readOnly,\n renderAllFields,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n },\n returnLivePreviewURL,\n returnLockStatus,\n schemaPath = collectionSlug || globalSlug,\n select,\n skipClientConfigAuth,\n skipValidation,\n updateLastEdited,\n } = args\n\n const selectMode = select ? getSelectMode(select) : undefined\n\n if (!collectionSlug && !globalSlug) {\n throw new Error('Either collectionSlug or globalSlug must be provided')\n }\n\n const schemaMap = getSchemaMap({\n collectionSlug,\n config,\n globalSlug,\n i18n,\n })\n\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug,\n config: getClientConfig({\n config,\n i18n,\n importMap: req.payload.importMap,\n user: skipClientConfigAuth ? true : req.user,\n }),\n globalSlug,\n i18n,\n payload,\n schemaMap,\n })\n\n const id = collectionSlug ? idFromArgs : undefined\n const fieldOrEntityConfig = schemaMap.get(schemaPath)\n\n if (!fieldOrEntityConfig) {\n throw new Error(`Could not find \"${schemaPath}\" in the fieldSchemaMap`)\n }\n\n if (\n (!('fields' in fieldOrEntityConfig) ||\n !fieldOrEntityConfig.fields ||\n !fieldOrEntityConfig.fields.length) &&\n 'type' in fieldOrEntityConfig &&\n fieldOrEntityConfig.type !== 'blocks'\n ) {\n throw new Error(\n `The field found in fieldSchemaMap for \"${schemaPath}\" does not contain any subfields.`,\n )\n }\n\n // If there is form state but no data, deduce data from that form state, e.g. on initial load\n // Otherwise, use the incoming data as the source of truth, e.g. on subsequent saves\n const data = incomingData || reduceFieldsToValues(formState, true)\n\n let documentData = undefined\n\n if (documentFormState) {\n documentData = reduceFieldsToValues(documentFormState, true)\n }\n\n let blockData = initialBlockData\n\n if (initialBlockFormState) {\n blockData = reduceFieldsToValues(initialBlockFormState, true)\n }\n\n /**\n * When building state for sub schemas we need to adjust:\n * - `fields`\n * - `parentSchemaPath`\n * - `parentPath`\n *\n * Type assertion is fine because we wrap sub schemas in an array\n * so we can safely map over them within `fieldSchemasToFormState`\n */\n const fields = Array.isArray(fieldOrEntityConfig)\n ? fieldOrEntityConfig\n : 'fields' in fieldOrEntityConfig\n ? fieldOrEntityConfig.fields\n : [fieldOrEntityConfig]\n\n // Ensure data.id is present during form state requests, where the data\n // is passed from the client as an argument, without the ID\n if (!data.id && id) {\n data.id = id\n }\n\n const formStateResult = await fieldSchemasToFormState({\n id,\n clientFieldSchemaMap: clientSchemaMap,\n collectionSlug,\n data,\n documentData,\n fields,\n fieldSchemaMap: schemaMap,\n initialBlockData: blockData,\n mockRSCs,\n operation,\n permissions: docPermissions?.fields || {},\n preferences: docPreferences || { fields: {} },\n previousFormState: formState,\n readOnly,\n renderAllFields,\n renderFieldFn: renderField,\n req,\n schemaPath,\n select,\n selectMode,\n skipValidation,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (payload.collections[collectionSlug]?.config?.upload && formState.file) {\n formStateResult.file = formState.file\n }\n }\n\n let lockedStateResult\n\n if (returnLockStatus) {\n lockedStateResult = await handleFormStateLocking({\n id,\n collectionSlug,\n globalSlug,\n req,\n updateLastEdited,\n })\n }\n\n const res: BuildFormStateSuccessResult = {\n lockedState: lockedStateResult,\n state: formStateResult,\n }\n\n if (returnLivePreviewURL) {\n const { livePreviewURL } = await handleLivePreview({\n collectionSlug,\n config,\n data,\n globalSlug,\n req,\n })\n\n // Important: only set this when not undefined,\n // Otherwise it will travel through the network as `$undefined`\n if (livePreviewURL) {\n res.livePreviewURL = livePreviewURL\n }\n }\n\n return res\n}\n"],"mappings":"AASA,SAASA,cAAc,EAAEC,YAAY,QAAQ;AAC7C,SAASC,aAAa,EAAEC,oBAAoB,QAAQ;AAEpD,SAASC,uBAAuB,QAAQ;AACxC,SAASC,WAAW,QAAQ;AAC5B,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,iBAAiB,QAAQ;AA8BlC,OAAO,MAAMC,qBAAA,GAGT,MAAOC,IAAA;EACT,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,IA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IAAA;MACAM,UAAA;MACAnB;IACF;IAEA;IACA;IACA,IAAI+D,cAAA,EAAgB;MAClB9D,GAAA,CAAI8D,cAAc,GAAGA,cAAA;IACvB;EACF;EAEA,OAAO9D,GAAA;AACT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"buildFormState.js","names":["canAccessAdmin","formatErrors","getSelectMode","reduceFieldsToValues","fieldSchemasToFormState","renderField","getClientConfig","getClientSchemaMap","getSchemaMap","handleFormStateLocking","handleLivePreview","handlePreview","buildFormStateHandler","args","req","res","buildFormState","err","payload","logger","error","msg","message","Error","id","idFromArgs","collectionSlug","data","incomingData","docPermissions","docPreferences","documentFormState","formState","globalSlug","initialBlockData","initialBlockFormState","mockRSCs","operation","readOnly","renderAllFields","i18n","config","returnLivePreviewURL","returnLockStatus","returnPreviewURL","schemaPath","select","skipClientConfigAuth","skipValidation","updateLastEdited","selectMode","undefined","schemaMap","clientSchemaMap","importMap","user","fieldOrEntityConfig","get","fields","length","type","documentData","blockData","Array","isArray","formStateResult","clientFieldSchemaMap","fieldSchemaMap","permissions","preferences","previousFormState","renderFieldFn","collections","upload","file","lockedStateResult","lockedState","state","livePreviewURL","previewURL"],"sources":["../../src/utilities/buildFormState.ts"],"sourcesContent":["import type {\n BuildFormStateArgs,\n ClientConfig,\n ClientUser,\n ErrorResult,\n FormState,\n ServerFunction,\n} from 'payload'\n\nimport { canAccessAdmin, formatErrors } from 'payload'\nimport { getSelectMode, reduceFieldsToValues } from 'payload/shared'\n\nimport { fieldSchemasToFormState } from '../forms/fieldSchemasToFormState/index.js'\nimport { renderField } from '../forms/fieldSchemasToFormState/renderField.js'\nimport { getClientConfig } from './getClientConfig.js'\nimport { getClientSchemaMap } from './getClientSchemaMap.js'\nimport { getSchemaMap } from './getSchemaMap.js'\nimport { handleFormStateLocking } from './handleFormStateLocking.js'\nimport { handleLivePreview } from './handleLivePreview.js'\nimport { handlePreview } from './handlePreview.js'\n\nexport type LockedState = {\n isLocked: boolean\n lastEditedAt: string\n user: ClientUser | number | string\n}\n\ntype BuildFormStateSuccessResult = {\n clientConfig?: ClientConfig\n errors?: never\n indexPath?: string\n livePreviewURL?: string\n lockedState?: LockedState\n previewURL?: string\n state: FormState\n}\n\ntype BuildFormStateErrorResult = {\n livePreviewURL?: never\n lockedState?: never\n previewURL?: never\n state?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildFormStateResult = BuildFormStateErrorResult | BuildFormStateSuccessResult\n\nexport const buildFormStateHandler: ServerFunction<\n BuildFormStateArgs,\n Promise<BuildFormStateResult>\n> = async (args) => {\n const { req } = args\n\n try {\n await canAccessAdmin({ req })\n const res = await buildFormState(args)\n\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n throw new Error('Unauthorized')\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildFormState = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateSuccessResult> => {\n const {\n id: idFromArgs,\n collectionSlug,\n data: incomingData,\n docPermissions,\n docPreferences,\n documentFormState,\n formState,\n globalSlug,\n initialBlockData,\n initialBlockFormState,\n mockRSCs,\n operation,\n readOnly,\n renderAllFields,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n },\n returnLivePreviewURL,\n returnLockStatus,\n returnPreviewURL,\n schemaPath = collectionSlug || globalSlug,\n select,\n skipClientConfigAuth,\n skipValidation,\n updateLastEdited,\n } = args\n\n const selectMode = select ? getSelectMode(select) : undefined\n\n if (!collectionSlug && !globalSlug) {\n throw new Error('Either collectionSlug or globalSlug must be provided')\n }\n\n const schemaMap = getSchemaMap({\n collectionSlug,\n config,\n globalSlug,\n i18n,\n })\n\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug,\n config: getClientConfig({\n config,\n i18n,\n importMap: req.payload.importMap,\n user: skipClientConfigAuth ? true : req.user,\n }),\n globalSlug,\n i18n,\n payload,\n schemaMap,\n })\n\n const id = collectionSlug ? idFromArgs : undefined\n const fieldOrEntityConfig = schemaMap.get(schemaPath)\n\n if (!fieldOrEntityConfig) {\n throw new Error(`Could not find \"${schemaPath}\" in the fieldSchemaMap`)\n }\n\n if (\n (!('fields' in fieldOrEntityConfig) ||\n !fieldOrEntityConfig.fields ||\n !fieldOrEntityConfig.fields.length) &&\n 'type' in fieldOrEntityConfig &&\n fieldOrEntityConfig.type !== 'blocks'\n ) {\n throw new Error(\n `The field found in fieldSchemaMap for \"${schemaPath}\" does not contain any subfields.`,\n )\n }\n\n // If there is form state but no data, deduce data from that form state, e.g. on initial load\n // Otherwise, use the incoming data as the source of truth, e.g. on subsequent saves\n const data = incomingData || reduceFieldsToValues(formState, true)\n\n let documentData = undefined\n\n if (documentFormState) {\n documentData = reduceFieldsToValues(documentFormState, true)\n }\n\n let blockData = initialBlockData\n\n if (initialBlockFormState) {\n blockData = reduceFieldsToValues(initialBlockFormState, true)\n }\n\n /**\n * When building state for sub schemas we need to adjust:\n * - `fields`\n * - `parentSchemaPath`\n * - `parentPath`\n *\n * Type assertion is fine because we wrap sub schemas in an array\n * so we can safely map over them within `fieldSchemasToFormState`\n */\n const fields = Array.isArray(fieldOrEntityConfig)\n ? fieldOrEntityConfig\n : 'fields' in fieldOrEntityConfig\n ? fieldOrEntityConfig.fields\n : [fieldOrEntityConfig]\n\n // Ensure data.id is present during form state requests, where the data\n // is passed from the client as an argument, without the ID\n if (!data.id && id) {\n data.id = id\n }\n\n const formStateResult = await fieldSchemasToFormState({\n id,\n clientFieldSchemaMap: clientSchemaMap,\n collectionSlug,\n data,\n documentData,\n fields,\n fieldSchemaMap: schemaMap,\n initialBlockData: blockData,\n mockRSCs,\n operation,\n permissions: docPermissions?.fields || {},\n preferences: docPreferences || { fields: {} },\n previousFormState: formState,\n readOnly,\n renderAllFields,\n renderFieldFn: renderField,\n req,\n schemaPath,\n select,\n selectMode,\n skipValidation,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (payload.collections[collectionSlug]?.config?.upload && formState.file) {\n formStateResult.file = formState.file\n }\n }\n\n let lockedStateResult\n\n if (returnLockStatus) {\n lockedStateResult = await handleFormStateLocking({\n id,\n collectionSlug,\n globalSlug,\n req,\n updateLastEdited,\n })\n }\n\n const res: BuildFormStateSuccessResult = {\n lockedState: lockedStateResult,\n state: formStateResult,\n }\n\n if (returnLivePreviewURL) {\n const { livePreviewURL } = await handleLivePreview({\n collectionSlug,\n config,\n data,\n globalSlug,\n req,\n })\n\n // Important: only set this when not undefined,\n // Otherwise it will travel through the network as `$undefined`\n if (livePreviewURL) {\n res.livePreviewURL = livePreviewURL\n }\n }\n\n if (returnPreviewURL) {\n const { previewURL } = await handlePreview({\n collectionSlug,\n config,\n data,\n globalSlug,\n req,\n })\n\n // Important: only set this when not undefined,\n // Otherwise it will travel through the network as `$undefined`\n if (previewURL) {\n res.previewURL = previewURL\n }\n }\n\n return res\n}\n"],"mappings":"AASA,SAASA,cAAc,EAAEC,YAAY,QAAQ;AAC7C,SAASC,aAAa,EAAEC,oBAAoB,QAAQ;AAEpD,SAASC,uBAAuB,QAAQ;AACxC,SAASC,WAAW,QAAQ;AAC5B,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,iBAAiB,QAAQ;AAClC,SAASC,aAAa,QAAQ;AAgC9B,OAAO,MAAMC,qBAAA,GAGT,MAAOC,IAAA;EACT,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,IAAI;IACF,MAAMb,cAAA,CAAe;MAAEc;IAAI;IAC3B,MAAMC,GAAA,GAAM,MAAMC,cAAA,CAAeH,IAAA;IAEjC,OAAOE,GAAA;EACT,EAAE,OAAOE,GAAA,EAAK;IACZH,GAAA,CAAII,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;MAAEH,GAAA;MAAKI,GAAA,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c;MACzCe,cAAA;MACAe,MAAA;MACAd,IAAA;MACAM,UAAA;MACAnB;IACF;IAEA;IACA;IACA,IAAIiE,UAAA,EAAY;MACdhE,GAAA,CAAIgE,UAAU,GAAGA,UAAA;IACnB;EACF;EAEA,OAAOhE,GAAA;AACT","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIError, canAccessAdmin, formatErrors, getAccessResults } from 'payload';
|
|
2
|
-
import { isNumber } from 'payload/shared';
|
|
2
|
+
import { applyLocaleFiltering, isNumber } from 'payload/shared';
|
|
3
3
|
import { getClientConfig } from './getClientConfig.js';
|
|
4
4
|
import { getColumns } from './getColumns.js';
|
|
5
5
|
import { renderFilters, renderTable } from './renderTable.js';
|
|
@@ -57,6 +57,11 @@ const buildTableState = async args => {
|
|
|
57
57
|
importMap: payload.importMap,
|
|
58
58
|
user
|
|
59
59
|
});
|
|
60
|
+
await applyLocaleFiltering({
|
|
61
|
+
clientConfig,
|
|
62
|
+
config,
|
|
63
|
+
req
|
|
64
|
+
});
|
|
60
65
|
const permissions = await getAccessResults({
|
|
61
66
|
req
|
|
62
67
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTableState.js","names":["APIError","canAccessAdmin","formatErrors","getAccessResults","isNumber","getClientConfig","getColumns","renderFilters","renderTable","upsertPreferences","buildTableStateHandler","args","req","res","buildTableState","err","payload","logger","error","msg","message","collectionSlug","columns","columnsFromArgs","data","dataFromArgs","enableRowSelections","orderableFieldName","parent","query","renderRowTypes","i18n","config","user","tableAppearance","clientConfig","importMap","permissions","collectionConfig","clientCollectionConfig","Array","isArray","collections","find","collection","slug","collectionPreferences","key","joinPath","value","limit","Number","undefined","sort","docs","select","currentSelectRef","segments","split","i","length","joinQuery","where","isNaN","page","parentDoc","findByID","id","depth","joins","overrideAccess","draft","locale","columnState","Table","fieldPermissions","fields","useAsTitle","admin","renderedFilters","preferences","state"],"sources":["../../src/utilities/buildTableState.ts"],"sourcesContent":["import type {\n BuildTableStateArgs,\n ClientCollectionConfig,\n ClientConfig,\n CollectionPreferences,\n Column,\n ErrorResult,\n PaginatedDocs,\n SanitizedCollectionConfig,\n ServerFunction,\n Where,\n} from 'payload'\n\nimport { APIError, canAccessAdmin, formatErrors, getAccessResults } from 'payload'\nimport { isNumber } from 'payload/shared'\n\nimport { getClientConfig } from './getClientConfig.js'\nimport { getColumns } from './getColumns.js'\nimport { renderFilters, renderTable } from './renderTable.js'\nimport { upsertPreferences } from './upsertPreferences.js'\n\ntype BuildTableStateSuccessResult = {\n clientConfig?: ClientConfig\n data: PaginatedDocs\n errors?: never\n preferences: CollectionPreferences\n renderedFilters: Map<string, React.ReactNode>\n state: Column[]\n Table: React.ReactNode\n}\n\ntype BuildTableStateErrorResult = {\n data?: any\n renderedFilters?: never\n state?: never\n Table?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildTableStateResult = BuildTableStateErrorResult | BuildTableStateSuccessResult\n\nexport const buildTableStateHandler: ServerFunction<\n BuildTableStateArgs,\n Promise<BuildTableStateResult>\n> = async (args) => {\n const { req } = args\n\n try {\n const res = await buildTableState(args)\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n return null\n }\n\n return formatErrors(err)\n }\n}\n\nconst buildTableState = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateSuccessResult> => {\n const {\n collectionSlug,\n columns: columnsFromArgs,\n data: dataFromArgs,\n enableRowSelections,\n orderableFieldName,\n parent,\n query,\n renderRowTypes,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n user,\n },\n tableAppearance,\n } = args\n\n await canAccessAdmin({ req })\n\n const clientConfig = getClientConfig({\n config,\n i18n,\n importMap: payload.importMap,\n user,\n })\n\n const permissions = await getAccessResults({ req })\n\n let collectionConfig: SanitizedCollectionConfig\n let clientCollectionConfig: ClientCollectionConfig\n\n if (!Array.isArray(collectionSlug)) {\n if (req.payload.collections[collectionSlug]) {\n collectionConfig = req.payload.collections[collectionSlug].config\n clientCollectionConfig = clientConfig.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n }\n }\n\n const collectionPreferences = await upsertPreferences<CollectionPreferences>({\n key: Array.isArray(collectionSlug)\n ? `${parent.collectionSlug}-${parent.joinPath}`\n : `collection-${collectionSlug}`,\n req,\n value: {\n columns: columnsFromArgs,\n limit: isNumber(query?.limit) ? Number(query.limit) : undefined,\n sort: query?.sort as string,\n },\n })\n\n let data: PaginatedDocs = dataFromArgs\n\n // lookup docs, if desired, i.e. within `join` field which initialize with `depth: 0`\n\n if (!data?.docs || query) {\n if (Array.isArray(collectionSlug)) {\n if (!parent) {\n throw new APIError('Unexpected array of collectionSlug, parent must be provided')\n }\n\n const select = {}\n let currentSelectRef = select\n\n const segments = parent.joinPath.split('.')\n\n for (let i = 0; i < segments.length; i++) {\n currentSelectRef[segments[i]] = i === segments.length - 1 ? true : {}\n currentSelectRef = currentSelectRef[segments[i]]\n }\n\n const joinQuery: { limit?: number; page?: number; sort?: string; where?: Where } = {\n sort: query?.sort as string,\n where: query?.where,\n }\n\n if (query) {\n if (!Number.isNaN(Number(query.limit))) {\n joinQuery.limit = Number(query.limit)\n }\n\n if (!Number.isNaN(Number(query.page))) {\n joinQuery.limit = Number(query.limit)\n }\n }\n\n let parentDoc = await payload.findByID({\n id: parent.id,\n collection: parent.collectionSlug,\n depth: 1,\n joins: {\n [parent.joinPath]: joinQuery,\n },\n overrideAccess: false,\n select,\n user: req.user,\n })\n\n for (let i = 0; i < segments.length; i++) {\n if (i === segments.length - 1) {\n data = parentDoc[segments[i]]\n } else {\n parentDoc = parentDoc[segments[i]]\n }\n }\n } else {\n data = await payload.find({\n collection: collectionSlug,\n depth: 0,\n draft: true,\n limit: query?.limit,\n locale: req.locale,\n overrideAccess: false,\n page: query?.page,\n sort: query?.sort,\n user: req.user,\n where: query?.where,\n })\n }\n }\n\n const { columnState, Table } = renderTable({\n clientCollectionConfig,\n clientConfig,\n collectionConfig,\n collections: Array.isArray(collectionSlug) ? collectionSlug : undefined,\n columns: getColumns({\n clientConfig,\n collectionConfig: clientCollectionConfig,\n collectionSlug,\n columns: columnsFromArgs,\n i18n: req.i18n,\n permissions,\n }),\n data,\n enableRowSelections,\n fieldPermissions: Array.isArray(collectionSlug)\n ? true\n : permissions.collections[collectionSlug].fields,\n i18n: req.i18n,\n orderableFieldName,\n payload,\n query,\n renderRowTypes,\n tableAppearance,\n useAsTitle: Array.isArray(collectionSlug)\n ? payload.collections[collectionSlug[0]]?.config?.admin?.useAsTitle\n : collectionConfig?.admin?.useAsTitle,\n })\n\n let renderedFilters\n\n if (collectionConfig) {\n renderedFilters = renderFilters(collectionConfig.fields, req.payload.importMap)\n }\n\n return {\n data,\n preferences: collectionPreferences,\n renderedFilters,\n state: columnState,\n Table,\n }\n}\n"],"mappings":"AAaA,SAASA,QAAQ,EAAEC,cAAc,EAAEC,YAAY,EAAEC,gBAAgB,QAAQ;AACzE,SAASC,QAAQ,QAAQ;AAEzB,SAASC,eAAe,QAAQ;AAChC,SAASC,UAAU,QAAQ;AAC3B,SAASC,aAAa,EAAEC,WAAW,QAAQ;AAC3C,SAASC,iBAAiB,QAAQ;AA0BlC,OAAO,MAAMC,sBAAA,GAGT,MAAOC,IAAA;EACT,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,IAAI;IACF,MAAME,GAAA,GAAM,MAAMC,eAAA,CAAgBH,IAAA;IAClC,OAAOE,GAAA;EACT,EAAE,OAAOE,GAAA,EAAK;IACZH,GAAA,CAAII,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;MAAEH,GAAA;MAAKI,GAAA,EAAK;IAAyC;IAE9E,IAAIJ,GAAA,CAAIK,OAAO,KAAK,8CAA8C;MAChE,OAAO;QACLA,OAAA,EAASL,GAAA,CAAIK;MACf;IACF;IAEA,IAAIL,GAAA,CAAIK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AACpB,cAAA,IAAkBA,cAAA,GAAiB+B,SAAA;IAC9D9B,OAAA,EAAShB,UAAA,CAAW;MAClB6B,YAAA;MACAG,gBAAA,EAAkBC,sBAAA;MAClBlB,cAAA;MACAC,OAAA,EAASC,eAAA;MACTQ,IAAA,EAAMnB,GAAA,CAAImB,IAAI;MACdM;IACF;IACAb,IAAA;IACAE,mBAAA;IACAiD,gBAAA,EAAkBnC,KAAA,CAAMC,OAAO,CAACpB,cAAA,IAC5B,OACAgB,WAAA,CAAYK,WAAW,CAACrB,cAAA,CAAe,CAACuD,MAAM;IAClD7C,IAAA,EAAMnB,GAAA,CAAImB,IAAI;IACdJ,kBAAA;IACAX,OAAA;IACAa,KAAA;IACAC,cAAA;IACAI,eAAA;IACA2C,UAAA,EAAYrC,KAAA,CAAMC,OAAO,CAACpB,cAAA,IACtBL,OAAA,CAAQ0B,WAAW,CAACrB,cAAc,CAAC,EAAE,CAAC,EAAEW,MAAA,EAAQ8C,KAAA,EAAOD,UAAA,GACvDvC,gBAAA,EAAkBwC,KAAA,EAAOD;EAC/B;EAEA,IAAIE,eAAA;EAEJ,IAAIzC,gBAAA,EAAkB;IACpByC,eAAA,GAAkBxE,aAAA,CAAc+B,gBAAA,CAAiBsC,MAAM,EAAEhE,GAAA,CAAII,OAAO,CAACoB,SAAS;EAChF;EAEA,OAAO;IACLZ,IAAA;IACAwD,WAAA,EAAalC,qBAAA;IACbiC,eAAA;IACAE,KAAA,EAAOR,WAAA;IACPC;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"buildTableState.js","names":["APIError","canAccessAdmin","formatErrors","getAccessResults","applyLocaleFiltering","isNumber","getClientConfig","getColumns","renderFilters","renderTable","upsertPreferences","buildTableStateHandler","args","req","res","buildTableState","err","payload","logger","error","msg","message","collectionSlug","columns","columnsFromArgs","data","dataFromArgs","enableRowSelections","orderableFieldName","parent","query","renderRowTypes","i18n","config","user","tableAppearance","clientConfig","importMap","permissions","collectionConfig","clientCollectionConfig","Array","isArray","collections","find","collection","slug","collectionPreferences","key","joinPath","value","limit","Number","undefined","sort","docs","select","currentSelectRef","segments","split","i","length","joinQuery","where","isNaN","page","parentDoc","findByID","id","depth","joins","overrideAccess","draft","locale","columnState","Table","fieldPermissions","fields","useAsTitle","admin","renderedFilters","preferences","state"],"sources":["../../src/utilities/buildTableState.ts"],"sourcesContent":["import type {\n BuildTableStateArgs,\n ClientCollectionConfig,\n ClientConfig,\n CollectionPreferences,\n Column,\n ErrorResult,\n PaginatedDocs,\n SanitizedCollectionConfig,\n ServerFunction,\n Where,\n} from 'payload'\n\nimport { APIError, canAccessAdmin, formatErrors, getAccessResults } from 'payload'\nimport { applyLocaleFiltering, isNumber } from 'payload/shared'\n\nimport { getClientConfig } from './getClientConfig.js'\nimport { getColumns } from './getColumns.js'\nimport { renderFilters, renderTable } from './renderTable.js'\nimport { upsertPreferences } from './upsertPreferences.js'\n\ntype BuildTableStateSuccessResult = {\n clientConfig?: ClientConfig\n data: PaginatedDocs\n errors?: never\n preferences: CollectionPreferences\n renderedFilters: Map<string, React.ReactNode>\n state: Column[]\n Table: React.ReactNode\n}\n\ntype BuildTableStateErrorResult = {\n data?: any\n renderedFilters?: never\n state?: never\n Table?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildTableStateResult = BuildTableStateErrorResult | BuildTableStateSuccessResult\n\nexport const buildTableStateHandler: ServerFunction<\n BuildTableStateArgs,\n Promise<BuildTableStateResult>\n> = async (args) => {\n const { req } = args\n\n try {\n const res = await buildTableState(args)\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n return null\n }\n\n return formatErrors(err)\n }\n}\n\nconst buildTableState = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateSuccessResult> => {\n const {\n collectionSlug,\n columns: columnsFromArgs,\n data: dataFromArgs,\n enableRowSelections,\n orderableFieldName,\n parent,\n query,\n renderRowTypes,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n user,\n },\n tableAppearance,\n } = args\n\n await canAccessAdmin({ req })\n\n const clientConfig = getClientConfig({\n config,\n i18n,\n importMap: payload.importMap,\n user,\n })\n await applyLocaleFiltering({ clientConfig, config, req })\n\n const permissions = await getAccessResults({ req })\n\n let collectionConfig: SanitizedCollectionConfig\n let clientCollectionConfig: ClientCollectionConfig\n\n if (!Array.isArray(collectionSlug)) {\n if (req.payload.collections[collectionSlug]) {\n collectionConfig = req.payload.collections[collectionSlug].config\n clientCollectionConfig = clientConfig.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n }\n }\n\n const collectionPreferences = await upsertPreferences<CollectionPreferences>({\n key: Array.isArray(collectionSlug)\n ? `${parent.collectionSlug}-${parent.joinPath}`\n : `collection-${collectionSlug}`,\n req,\n value: {\n columns: columnsFromArgs,\n limit: isNumber(query?.limit) ? Number(query.limit) : undefined,\n sort: query?.sort as string,\n },\n })\n\n let data: PaginatedDocs = dataFromArgs\n\n // lookup docs, if desired, i.e. within `join` field which initialize with `depth: 0`\n\n if (!data?.docs || query) {\n if (Array.isArray(collectionSlug)) {\n if (!parent) {\n throw new APIError('Unexpected array of collectionSlug, parent must be provided')\n }\n\n const select = {}\n let currentSelectRef = select\n\n const segments = parent.joinPath.split('.')\n\n for (let i = 0; i < segments.length; i++) {\n currentSelectRef[segments[i]] = i === segments.length - 1 ? true : {}\n currentSelectRef = currentSelectRef[segments[i]]\n }\n\n const joinQuery: { limit?: number; page?: number; sort?: string; where?: Where } = {\n sort: query?.sort as string,\n where: query?.where,\n }\n\n if (query) {\n if (!Number.isNaN(Number(query.limit))) {\n joinQuery.limit = Number(query.limit)\n }\n\n if (!Number.isNaN(Number(query.page))) {\n joinQuery.limit = Number(query.limit)\n }\n }\n\n let parentDoc = await payload.findByID({\n id: parent.id,\n collection: parent.collectionSlug,\n depth: 1,\n joins: {\n [parent.joinPath]: joinQuery,\n },\n overrideAccess: false,\n select,\n user: req.user,\n })\n\n for (let i = 0; i < segments.length; i++) {\n if (i === segments.length - 1) {\n data = parentDoc[segments[i]]\n } else {\n parentDoc = parentDoc[segments[i]]\n }\n }\n } else {\n data = await payload.find({\n collection: collectionSlug,\n depth: 0,\n draft: true,\n limit: query?.limit,\n locale: req.locale,\n overrideAccess: false,\n page: query?.page,\n sort: query?.sort,\n user: req.user,\n where: query?.where,\n })\n }\n }\n\n const { columnState, Table } = renderTable({\n clientCollectionConfig,\n clientConfig,\n collectionConfig,\n collections: Array.isArray(collectionSlug) ? collectionSlug : undefined,\n columns: getColumns({\n clientConfig,\n collectionConfig: clientCollectionConfig,\n collectionSlug,\n columns: columnsFromArgs,\n i18n: req.i18n,\n permissions,\n }),\n data,\n enableRowSelections,\n fieldPermissions: Array.isArray(collectionSlug)\n ? true\n : permissions.collections[collectionSlug].fields,\n i18n: req.i18n,\n orderableFieldName,\n payload,\n query,\n renderRowTypes,\n tableAppearance,\n useAsTitle: Array.isArray(collectionSlug)\n ? payload.collections[collectionSlug[0]]?.config?.admin?.useAsTitle\n : collectionConfig?.admin?.useAsTitle,\n })\n\n let renderedFilters\n\n if (collectionConfig) {\n renderedFilters = renderFilters(collectionConfig.fields, req.payload.importMap)\n }\n\n return {\n data,\n preferences: collectionPreferences,\n renderedFilters,\n state: columnState,\n Table,\n }\n}\n"],"mappings":"AAaA,SAASA,QAAQ,EAAEC,cAAc,EAAEC,YAAY,EAAEC,gBAAgB,QAAQ;AACzE,SAASC,oBAAoB,EAAEC,QAAQ,QAAQ;AAE/C,SAASC,eAAe,QAAQ;AAChC,SAASC,UAAU,QAAQ;AAC3B,SAASC,aAAa,EAAEC,WAAW,QAAQ;AAC3C,SAASC,iBAAiB,QAAQ;AA0BlC,OAAO,MAAMC,sBAAA,GAGT,MAAOC,IAAA;EACT,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,IAAI;IACF,MAAME,GAAA,GAAM,MAAMC,eAAA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IACbiC,eAAA;IACAE,KAAA,EAAOR,WAAA;IACPC;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type CollectionConfig, type GlobalConfig, type Operation, type PayloadRequest, type SanitizedConfig } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Multi-level check to determine whether live preview is enabled on a collection or global.
|
|
4
|
+
* For example, live preview can be enabled at both the root config level, or on the entity's config.
|
|
5
|
+
* If a collectionConfig/globalConfig is provided, checks if it is enabled at the root level,
|
|
6
|
+
* or on the entity's own config.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isPreviewEnabled: ({ collectionConfig, globalConfig, }: {
|
|
9
|
+
collectionConfig?: CollectionConfig;
|
|
10
|
+
globalConfig?: GlobalConfig;
|
|
11
|
+
}) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* 1. Looks up the relevant live preview config, which could have been enabled:
|
|
14
|
+
* a. At the root level, e.g. `collections: ['posts']`
|
|
15
|
+
* b. On the collection or global config, e.g. `admin: { livePreview: { ... } }`
|
|
16
|
+
* 2. Determines if live preview is enabled, and if not, early returns.
|
|
17
|
+
* 3. Merges the config with the root config, if necessary.
|
|
18
|
+
* 4. Executes the `url` function, if necessary.
|
|
19
|
+
*
|
|
20
|
+
* Notice: internal function only. Subject to change at any time. Use at your own risk.
|
|
21
|
+
*/
|
|
22
|
+
export declare const handlePreview: ({ collectionSlug, config, data, globalSlug, operation, req, }: {
|
|
23
|
+
collectionSlug?: string;
|
|
24
|
+
config: SanitizedConfig;
|
|
25
|
+
data: Record<string, unknown>;
|
|
26
|
+
globalSlug?: string;
|
|
27
|
+
operation?: Operation;
|
|
28
|
+
req: PayloadRequest;
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
isPreviewEnabled?: boolean;
|
|
31
|
+
previewURL?: string;
|
|
32
|
+
}>;
|
|
33
|
+
//# sourceMappingURL=handlePreview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlePreview.d.ts","sourceRoot":"","sources":["../../src/utilities/handlePreview.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,SAAS,CAAA;AAEhB;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,wCAG1B;IACD,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,KAAG,OAQH,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,kEAOvB;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,OAAO,CAAC;IACV,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAoCA,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { extractJWT } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Multi-level check to determine whether live preview is enabled on a collection or global.
|
|
4
|
+
* For example, live preview can be enabled at both the root config level, or on the entity's config.
|
|
5
|
+
* If a collectionConfig/globalConfig is provided, checks if it is enabled at the root level,
|
|
6
|
+
* or on the entity's own config.
|
|
7
|
+
*/
|
|
8
|
+
export const isPreviewEnabled = ({
|
|
9
|
+
collectionConfig,
|
|
10
|
+
globalConfig
|
|
11
|
+
}) => {
|
|
12
|
+
if (globalConfig) {
|
|
13
|
+
return Boolean(globalConfig.admin?.preview);
|
|
14
|
+
}
|
|
15
|
+
if (collectionConfig) {
|
|
16
|
+
return Boolean(collectionConfig.admin?.preview);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 1. Looks up the relevant live preview config, which could have been enabled:
|
|
21
|
+
* a. At the root level, e.g. `collections: ['posts']`
|
|
22
|
+
* b. On the collection or global config, e.g. `admin: { livePreview: { ... } }`
|
|
23
|
+
* 2. Determines if live preview is enabled, and if not, early returns.
|
|
24
|
+
* 3. Merges the config with the root config, if necessary.
|
|
25
|
+
* 4. Executes the `url` function, if necessary.
|
|
26
|
+
*
|
|
27
|
+
* Notice: internal function only. Subject to change at any time. Use at your own risk.
|
|
28
|
+
*/
|
|
29
|
+
export const handlePreview = async ({
|
|
30
|
+
collectionSlug,
|
|
31
|
+
config,
|
|
32
|
+
data,
|
|
33
|
+
globalSlug,
|
|
34
|
+
operation,
|
|
35
|
+
req
|
|
36
|
+
}) => {
|
|
37
|
+
const collectionConfig = collectionSlug ? req.payload.collections[collectionSlug]?.config : undefined;
|
|
38
|
+
const globalConfig = globalSlug ? config.globals.find(g => g.slug === globalSlug) : undefined;
|
|
39
|
+
const enabled = isPreviewEnabled({
|
|
40
|
+
collectionConfig,
|
|
41
|
+
globalConfig
|
|
42
|
+
});
|
|
43
|
+
if (!enabled) {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
const generatePreviewURL = collectionConfig?.admin?.preview || globalConfig?.admin?.preview;
|
|
47
|
+
const token = extractJWT(req);
|
|
48
|
+
let previewURL;
|
|
49
|
+
if (typeof generatePreviewURL === 'function' && operation !== 'create') {
|
|
50
|
+
try {
|
|
51
|
+
const result = await generatePreviewURL(data, {
|
|
52
|
+
locale: req.locale,
|
|
53
|
+
req,
|
|
54
|
+
token
|
|
55
|
+
});
|
|
56
|
+
if (typeof result === 'string') {
|
|
57
|
+
previewURL = result;
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
req.payload.logger.error({
|
|
61
|
+
err,
|
|
62
|
+
msg: `There was an error executing the live preview URL function for ${collectionSlug || globalSlug}`
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
isPreviewEnabled: enabled,
|
|
68
|
+
previewURL
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=handlePreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlePreview.js","names":["extractJWT","isPreviewEnabled","collectionConfig","globalConfig","Boolean","admin","preview","handlePreview","collectionSlug","config","data","globalSlug","operation","req","payload","collections","undefined","globals","find","g","slug","enabled","generatePreviewURL","token","previewURL","result","locale","err","logger","error","msg"],"sources":["../../src/utilities/handlePreview.ts"],"sourcesContent":["import {\n type CollectionConfig,\n extractJWT,\n type GlobalConfig,\n type Operation,\n type PayloadRequest,\n type SanitizedConfig,\n} from 'payload'\n\n/**\n * Multi-level check to determine whether live preview is enabled on a collection or global.\n * For example, live preview can be enabled at both the root config level, or on the entity's config.\n * If a collectionConfig/globalConfig is provided, checks if it is enabled at the root level,\n * or on the entity's own config.\n */\nexport const isPreviewEnabled = ({\n collectionConfig,\n globalConfig,\n}: {\n collectionConfig?: CollectionConfig\n globalConfig?: GlobalConfig\n}): boolean => {\n if (globalConfig) {\n return Boolean(globalConfig.admin?.preview)\n }\n\n if (collectionConfig) {\n return Boolean(collectionConfig.admin?.preview)\n }\n}\n\n/**\n * 1. Looks up the relevant live preview config, which could have been enabled:\n * a. At the root level, e.g. `collections: ['posts']`\n * b. On the collection or global config, e.g. `admin: { livePreview: { ... } }`\n * 2. Determines if live preview is enabled, and if not, early returns.\n * 3. Merges the config with the root config, if necessary.\n * 4. Executes the `url` function, if necessary.\n *\n * Notice: internal function only. Subject to change at any time. Use at your own risk.\n */\nexport const handlePreview = async ({\n collectionSlug,\n config,\n data,\n globalSlug,\n operation,\n req,\n}: {\n collectionSlug?: string\n config: SanitizedConfig\n data: Record<string, unknown>\n globalSlug?: string\n operation?: Operation\n req: PayloadRequest\n}): Promise<{\n isPreviewEnabled?: boolean\n previewURL?: string\n}> => {\n const collectionConfig = collectionSlug\n ? req.payload.collections[collectionSlug]?.config\n : undefined\n\n const globalConfig = globalSlug ? config.globals.find((g) => g.slug === globalSlug) : undefined\n\n const enabled = isPreviewEnabled({\n collectionConfig,\n globalConfig,\n })\n\n if (!enabled) {\n return {}\n }\n\n const generatePreviewURL = collectionConfig?.admin?.preview || globalConfig?.admin?.preview\n const token = extractJWT(req)\n let previewURL: string | undefined\n\n if (typeof generatePreviewURL === 'function' && operation !== 'create') {\n try {\n const result = await generatePreviewURL(data, { locale: req.locale, req, token })\n\n if (typeof result === 'string') {\n previewURL = result\n }\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `There was an error executing the live preview URL function for ${collectionSlug || globalSlug}`,\n })\n }\n }\n\n return { isPreviewEnabled: enabled, previewURL }\n}\n"],"mappings":"AAAA,SAEEA,UAAU,QAKL;AAEP;;;;;;AAMA,OAAO,MAAMC,gBAAA,GAAmBA,CAAC;EAC/BC,gBAAgB;EAChBC;AAAY,CAIb;EACC,IAAIA,YAAA,EAAc;IAChB,OAAOC,OAAA,CAAQD,YAAA,CAAaE,KAAK,EAAEC,OAAA;EACrC;EAEA,IAAIJ,gBAAA,EAAkB;IACpB,OAAOE,OAAA,CAAQF,gBAAA,CAAiBG,KAAK,EAAEC,OAAA;EACzC;AACF;AAEA;;;;;;;;;;AAUA,OAAO,MAAMC,aAAA,GAAgB,MAAAA,CAAO;EAClCC,cAAc;EACdC,MAAM;EACNC,IAAI;EACJC,UAAU;EACVC,SAAS;EACTC;AAAG,CAQJ;EAIC,MAAMX,gBAAA,GAAmBM,cAAA,GACrBK,GAAA,CAAIC,OAAO,CAACC,WAAW,CAACP,cAAA,CAAe,EAAEC,MAAA,GACzCO,SAAA;EAEJ,MAAMb,YAAA,GAAeQ,UAAA,GAAaF,MAAA,CAAOQ,OAAO,CAACC,IAAI,CAAEC,CAAA,IAAMA,CAAA,CAAEC,IAAI,KAAKT,UAAA,IAAcK,SAAA;EAEtF,MAAMK,OAAA,GAAUpB,gBAAA,CAAiB;IAC/BC,gBAAA;IACAC;EACF;EAEA,IAAI,CAACkB,OAAA,EAAS;IACZ,OAAO,CAAC;EACV;EAEA,MAAMC,kBAAA,GAAqBpB,gBAAA,EAAkBG,KAAA,EAAOC,OAAA,IAAWH,YAAA,EAAcE,KAAA,EAAOC,OAAA;EACpF,MAAMiB,KAAA,GAAQvB,UAAA,CAAWa,GAAA;EACzB,IAAIW,UAAA;EAEJ,IAAI,OAAOF,kBAAA,KAAuB,cAAcV,SAAA,KAAc,UAAU;IACtE,IAAI;MACF,MAAMa,MAAA,GAAS,MAAMH,kBAAA,CAAmBZ,IAAA,EAAM;QAAEgB,MAAA,EAAQb,GAAA,CAAIa,MAAM;QAAEb,GAAA;QAAKU;MAAM;MAE/E,IAAI,OAAOE,MAAA,KAAW,UAAU;QAC9BD,UAAA,GAAaC,MAAA;MACf;IACF,EAAE,OAAOE,GAAA,EAAK;MACZd,GAAA,CAAIC,OAAO,CAACc,MAAM,CAACC,KAAK,CAAC;QACvBF,GAAA;QACAG,GAAA,EAAK,kEAAkEtB,cAAA,IAAkBG,UAAA;MAC3F;IACF;EACF;EAEA,OAAO;IAAEV,gBAAA,EAAkBoB,OAAA;IAASG;EAAW;AACjD","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/views/Edit/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/views/Edit/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAc,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAKlE,OAAO,KAAsE,MAAM,OAAO,CAAA;AAkC1F,OAAO,cAAc,CAAA;AAKrB,MAAM,MAAM,aAAa,GAAG;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAKD,wBAAgB,eAAe,CAAC,EAC9B,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,WAAW,EAAE,iBAAiB,EAC9B,aAAa,EACb,aAAa,EACb,UAAU,EACV,eAAe,EACf,MAAM,EAAE,YAAY,EACpB,cAAc,GACf,EAAE,uBAAuB,qBAkpBzB"}
|
package/dist/views/Edit/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
4
|
+
import { useModal } from '@faceless-ui/modal';
|
|
4
5
|
import { useRouter, useSearchParams } from 'next/navigation.js';
|
|
5
6
|
import { formatAdminURL } from 'payload/shared';
|
|
6
7
|
import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -19,7 +20,7 @@ import { useConfig } from '../../providers/Config/index.js';
|
|
|
19
20
|
import { useDocumentEvents } from '../../providers/DocumentEvents/index.js';
|
|
20
21
|
import { useDocumentInfo } from '../../providers/DocumentInfo/index.js';
|
|
21
22
|
import { useEditDepth } from '../../providers/EditDepth/index.js';
|
|
22
|
-
import { useLivePreviewContext } from '../../providers/LivePreview/context.js';
|
|
23
|
+
import { useLivePreviewContext, usePreviewURL } from '../../providers/LivePreview/context.js';
|
|
23
24
|
import { OperationProvider } from '../../providers/Operation/index.js';
|
|
24
25
|
import { useRouteCache } from '../../providers/RouteCache/index.js';
|
|
25
26
|
import { useRouteTransition } from '../../providers/RouteTransition/index.js';
|
|
@@ -32,8 +33,8 @@ import { handleGoBack } from '../../utilities/handleGoBack.js';
|
|
|
32
33
|
import { handleTakeOver } from '../../utilities/handleTakeOver.js';
|
|
33
34
|
import { Auth } from './Auth/index.js';
|
|
34
35
|
import { SetDocumentStepNav } from './SetDocumentStepNav/index.js';
|
|
35
|
-
import { SetDocumentTitle } from './SetDocumentTitle/index.js';
|
|
36
36
|
import './index.scss';
|
|
37
|
+
import { SetDocumentTitle } from './SetDocumentTitle/index.js';
|
|
37
38
|
const baseClass = 'collection-edit';
|
|
38
39
|
// This component receives props only on _pages_
|
|
39
40
|
// When rendered within a drawer, props are empty
|
|
@@ -97,6 +98,9 @@ export function DefaultEditView({
|
|
|
97
98
|
onRestore,
|
|
98
99
|
onSave: onSaveFromContext
|
|
99
100
|
} = useDocumentDrawerContext();
|
|
101
|
+
const {
|
|
102
|
+
closeModal
|
|
103
|
+
} = useModal();
|
|
100
104
|
const isInDrawer = Boolean(drawerSlug);
|
|
101
105
|
const {
|
|
102
106
|
refreshCookieAsync,
|
|
@@ -146,6 +150,10 @@ export function DefaultEditView({
|
|
|
146
150
|
typeofLivePreviewURL,
|
|
147
151
|
url: livePreviewURL
|
|
148
152
|
} = useLivePreviewContext();
|
|
153
|
+
const {
|
|
154
|
+
isPreviewEnabled,
|
|
155
|
+
setPreviewURL
|
|
156
|
+
} = usePreviewURL();
|
|
149
157
|
const abortOnChangeRef = useRef(null);
|
|
150
158
|
const abortOnSaveRef = useRef(null);
|
|
151
159
|
const locale = params.get('locale');
|
|
@@ -161,12 +169,12 @@ export function DefaultEditView({
|
|
|
161
169
|
const lockDuration = typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault;
|
|
162
170
|
const lockDurationInMilliseconds = lockDuration * 1000;
|
|
163
171
|
const autosaveEnabled = Boolean(collectionConfig?.versions?.drafts && collectionConfig?.versions?.drafts?.autosave || globalConfig?.versions?.drafts && globalConfig?.versions?.drafts?.autosave);
|
|
164
|
-
const preventLeaveWithoutSaving = typeof disableLeaveWithoutSaving !== 'undefined' ? !disableLeaveWithoutSaving : !autosaveEnabled;
|
|
165
172
|
const [isReadOnlyForIncomingUser, setIsReadOnlyForIncomingUser] = useState(false);
|
|
166
173
|
const [showTakeOverModal, setShowTakeOverModal] = useState(false);
|
|
167
174
|
const [editSessionStartTime, setEditSessionStartTime] = useState(Date.now());
|
|
168
175
|
const lockExpiryTime = lastUpdateTime + lockDurationInMilliseconds;
|
|
169
176
|
const isLockExpired = Date.now() > lockExpiryTime;
|
|
177
|
+
const preventLeaveWithoutSaving = !isReadOnlyForIncomingUser && (typeof disableLeaveWithoutSaving !== 'undefined' ? !disableLeaveWithoutSaving : !autosaveEnabled);
|
|
170
178
|
const schemaPathSegments = useMemo(() => [entitySlug], [entitySlug]);
|
|
171
179
|
const [validateBeforeSubmit, setValidateBeforeSubmit] = useState(() => {
|
|
172
180
|
if (operation === 'create' && auth && !auth.disableLocalStrategy) {
|
|
@@ -208,17 +216,15 @@ export function DefaultEditView({
|
|
|
208
216
|
// Check where user is trying to go
|
|
209
217
|
const nextPath = nextHrefRef.current ? new URL(nextHrefRef.current).pathname : '';
|
|
210
218
|
const isInternalView = ['/preview', '/api', '/versions'].some(path => nextPath.includes(path));
|
|
211
|
-
//
|
|
212
|
-
if (!isInternalView) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
;
|
|
221
|
-
}
|
|
219
|
+
// Remove the lock if the user is navigating away from the document view they have locked
|
|
220
|
+
if (isLockOwnedByCurrentUser && !isInternalView) {
|
|
221
|
+
try {
|
|
222
|
+
await unlockDocument(id, collectionSlug ?? globalSlug);
|
|
223
|
+
setDocumentIsLocked(false);
|
|
224
|
+
setCurrentEditor(null);
|
|
225
|
+
} catch (err) {
|
|
226
|
+
console.error('Failed to unlock before leave', err) // eslint-disable-line no-console
|
|
227
|
+
;
|
|
222
228
|
}
|
|
223
229
|
}
|
|
224
230
|
}
|
|
@@ -270,6 +276,7 @@ export function DefaultEditView({
|
|
|
270
276
|
const docPreferences = await getDocPreferences();
|
|
271
277
|
const {
|
|
272
278
|
livePreviewURL: livePreviewURL_0,
|
|
279
|
+
previewURL,
|
|
273
280
|
state
|
|
274
281
|
} = await getFormState({
|
|
275
282
|
id,
|
|
@@ -283,6 +290,7 @@ export function DefaultEditView({
|
|
|
283
290
|
renderAllFields: false,
|
|
284
291
|
returnLivePreviewURL: isLivePreviewEnabled && typeofLivePreviewURL === 'function',
|
|
285
292
|
returnLockStatus: false,
|
|
293
|
+
returnPreviewURL: isPreviewEnabled,
|
|
286
294
|
schemaPath: schemaPathSegments.join('.'),
|
|
287
295
|
signal: controller.signal,
|
|
288
296
|
skipValidation: true
|
|
@@ -294,6 +302,9 @@ export function DefaultEditView({
|
|
|
294
302
|
if (isLivePreviewEnabled && typeofLivePreviewURL === 'function') {
|
|
295
303
|
setLivePreviewURL(livePreviewURL_0);
|
|
296
304
|
}
|
|
305
|
+
if (isPreviewEnabled) {
|
|
306
|
+
setPreviewURL(previewURL);
|
|
307
|
+
}
|
|
297
308
|
reportUpdate({
|
|
298
309
|
id,
|
|
299
310
|
entitySlug,
|
|
@@ -302,7 +313,7 @@ export function DefaultEditView({
|
|
|
302
313
|
abortOnSaveRef.current = null;
|
|
303
314
|
return state;
|
|
304
315
|
}
|
|
305
|
-
}, [reportUpdate, id, entitySlug, user, collectionSlug, userSlug, setLastUpdateTime, setData, onSaveFromContext, isEditing, depth, redirectAfterCreate, setLivePreviewURL, globalSlug, refreshCookieAsync, incrementVersionCount, adminRoute, locale, startRouteTransition, router, resetUploadEdits, getDocPermissions, getDocPreferences, getFormState, docPermissions, operation, isLivePreviewEnabled, typeofLivePreviewURL, schemaPathSegments, isLockingEnabled, setDocumentIsLocked]);
|
|
316
|
+
}, [reportUpdate, id, entitySlug, user, collectionSlug, userSlug, setLastUpdateTime, setData, onSaveFromContext, isEditing, depth, redirectAfterCreate, setLivePreviewURL, setPreviewURL, globalSlug, refreshCookieAsync, incrementVersionCount, adminRoute, locale, startRouteTransition, router, resetUploadEdits, getDocPermissions, getDocPreferences, getFormState, docPermissions, operation, isLivePreviewEnabled, isPreviewEnabled, typeofLivePreviewURL, schemaPathSegments, isLockingEnabled, setDocumentIsLocked]);
|
|
306
317
|
const onChange = useCallback(async ({
|
|
307
318
|
formState: prevFormState,
|
|
308
319
|
submitted
|
|
@@ -414,7 +425,7 @@ export function DefaultEditView({
|
|
|
414
425
|
setIsReadOnlyForIncomingUser(true);
|
|
415
426
|
setShowTakeOverModal(false);
|
|
416
427
|
}
|
|
417
|
-
}),
|
|
428
|
+
}), preventLeaveWithoutSaving && /*#__PURE__*/_jsx(LeaveWithoutSaving, {
|
|
418
429
|
onConfirm: handleLeaveConfirm,
|
|
419
430
|
onPrevent: handlePrevent
|
|
420
431
|
}), !isInDrawer && /*#__PURE__*/_jsx(SetDocumentStepNav, {
|
|
@@ -490,6 +501,7 @@ export function DefaultEditView({
|
|
|
490
501
|
readOnly: !hasSavePermission,
|
|
491
502
|
requirePassword: !id,
|
|
492
503
|
setValidateBeforeSubmit: setValidateBeforeSubmit,
|
|
504
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
493
505
|
useAPIKey: auth.useAPIKey,
|
|
494
506
|
username: data?.username,
|
|
495
507
|
verify: auth.verify
|