@payloadcms/ui 3.57.0-internal.f26caed → 3.57.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/elements/BulkUpload/FileSidebar/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FileSidebar/index.js +74 -38
- package/dist/elements/BulkUpload/FileSidebar/index.js.map +1 -1
- package/dist/elements/BulkUpload/FileSidebar/index.scss +14 -1
- package/dist/elements/BulkUpload/FormsManager/index.d.ts +6 -1
- package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.js +52 -14
- package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/reducer.d.ts +2 -2
- package/dist/elements/BulkUpload/FormsManager/reducer.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/reducer.js +5 -5
- package/dist/elements/BulkUpload/FormsManager/reducer.js.map +1 -1
- package/dist/elements/BulkUpload/index.d.ts +30 -5
- package/dist/elements/BulkUpload/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/index.js +130 -28
- package/dist/elements/BulkUpload/index.js.map +1 -1
- package/dist/elements/ConfirmationModal/index.d.ts.map +1 -1
- package/dist/elements/ConfirmationModal/index.js +1 -0
- package/dist/elements/ConfirmationModal/index.js.map +1 -1
- package/dist/elements/DocumentLocked/index.d.ts.map +1 -1
- package/dist/elements/DocumentLocked/index.js +41 -33
- package/dist/elements/DocumentLocked/index.js.map +1 -1
- package/dist/elements/DocumentTakeOver/index.d.ts.map +1 -1
- package/dist/elements/DocumentTakeOver/index.js +27 -19
- package/dist/elements/DocumentTakeOver/index.js.map +1 -1
- package/dist/elements/Drawer/index.d.ts.map +1 -1
- package/dist/elements/Drawer/index.js +1 -0
- package/dist/elements/Drawer/index.js.map +1 -1
- package/dist/elements/FullscreenModal/index.d.ts.map +1 -1
- package/dist/elements/FullscreenModal/index.js +1 -0
- package/dist/elements/FullscreenModal/index.js.map +1 -1
- package/dist/elements/LivePreview/IFrame/index.d.ts +1 -7
- package/dist/elements/LivePreview/IFrame/index.d.ts.map +1 -1
- package/dist/elements/LivePreview/IFrame/index.js +39 -18
- package/dist/elements/LivePreview/IFrame/index.js.map +1 -1
- package/dist/elements/LivePreview/Window/index.d.ts.map +1 -1
- package/dist/elements/LivePreview/Window/index.js +135 -61
- package/dist/elements/LivePreview/Window/index.js.map +1 -1
- package/dist/elements/PublishButton/index.js +1 -1
- package/dist/elements/PublishButton/index.js.map +1 -1
- package/dist/elements/SearchBar/index.scss +4 -0
- package/dist/elements/Status/index.d.ts.map +1 -1
- package/dist/elements/Status/index.js +9 -19
- package/dist/elements/Status/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/index.d.ts.map +1 -1
- package/dist/elements/Table/DefaultCell/index.js +20 -14
- package/dist/elements/Table/DefaultCell/index.js.map +1 -1
- package/dist/elements/Thumbnail/index.d.ts +4 -2
- package/dist/elements/Thumbnail/index.d.ts.map +1 -1
- package/dist/elements/Thumbnail/index.js +6 -2
- package/dist/elements/Thumbnail/index.js.map +1 -1
- package/dist/elements/Thumbnail/index.scss +11 -9
- package/dist/elements/Toasts/fieldErrors.js +1 -1
- package/dist/elements/Toasts/fieldErrors.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 +2 -2
- package/dist/exports/shared/index.js.map +3 -3
- package/dist/fields/Blocks/index.d.ts.map +1 -1
- package/dist/fields/Blocks/index.js +36 -16
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/fields/Relationship/Input.d.ts.map +1 -1
- package/dist/fields/Relationship/Input.js +1 -5
- package/dist/fields/Relationship/Input.js.map +1 -1
- package/dist/fields/Upload/Input.js +20 -20
- package/dist/fields/Upload/Input.js.map +1 -1
- package/dist/forms/Form/index.js +1 -2
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/Form/mergeServerFormState.d.ts.map +1 -1
- package/dist/forms/Form/mergeServerFormState.js +8 -0
- package/dist/forms/Form/mergeServerFormState.js.map +1 -1
- package/dist/forms/Form/types.d.ts +2 -2
- package/dist/forms/Form/types.d.ts.map +1 -1
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/forms/RenderFields/RenderField.js +223 -236
- package/dist/forms/RenderFields/RenderField.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +33 -2
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js +2 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js +2 -0
- package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.d.ts +6 -0
- package/dist/forms/fieldSchemasToFormState/types.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.js.map +1 -1
- package/dist/forms/useField/index.d.ts.map +1 -1
- package/dist/forms/useField/index.js +76 -73
- package/dist/forms/useField/index.js.map +1 -1
- package/dist/forms/useField/types.d.ts +5 -9
- package/dist/forms/useField/types.d.ts.map +1 -1
- package/dist/forms/useField/types.js.map +1 -1
- package/dist/providers/LivePreview/context.d.ts +17 -2
- package/dist/providers/LivePreview/context.d.ts.map +1 -1
- package/dist/providers/LivePreview/context.js +3 -2
- package/dist/providers/LivePreview/context.js.map +1 -1
- package/dist/providers/LivePreview/index.d.ts +2 -2
- package/dist/providers/LivePreview/index.d.ts.map +1 -1
- package/dist/providers/LivePreview/index.js +33 -19
- package/dist/providers/LivePreview/index.js.map +1 -1
- package/dist/providers/RouteCache/index.d.ts.map +1 -1
- package/dist/providers/RouteCache/index.js +62 -25
- package/dist/providers/RouteCache/index.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.d.ts +2 -1
- package/dist/providers/TableColumns/buildColumnState/index.d.ts.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.js +2 -0
- package/dist/providers/TableColumns/buildColumnState/index.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/renderCell.d.ts +3 -2
- package/dist/providers/TableColumns/buildColumnState/renderCell.d.ts.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/renderCell.js +39 -2
- package/dist/providers/TableColumns/buildColumnState/renderCell.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utilities/buildFormState.d.ts +2 -0
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js +20 -1
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/formatAbsoluteURL.d.ts +8 -0
- package/dist/utilities/formatAbsoluteURL.d.ts.map +1 -0
- package/dist/utilities/formatAbsoluteURL.js +15 -0
- package/dist/utilities/formatAbsoluteURL.js.map +1 -0
- package/dist/utilities/getFolderResultsComponentAndData.d.ts.map +1 -1
- package/dist/utilities/getFolderResultsComponentAndData.js +0 -4
- package/dist/utilities/getFolderResultsComponentAndData.js.map +1 -1
- package/dist/utilities/handleLivePreview.d.ts +58 -0
- package/dist/utilities/handleLivePreview.d.ts.map +1 -0
- package/dist/utilities/handleLivePreview.js +96 -0
- package/dist/utilities/handleLivePreview.js.map +1 -0
- package/dist/utilities/handleTakeOver.d.ts +17 -4
- package/dist/utilities/handleTakeOver.d.ts.map +1 -1
- package/dist/utilities/handleTakeOver.js +18 -2
- package/dist/utilities/handleTakeOver.js.map +1 -1
- package/dist/utilities/renderTable.d.ts +3 -2
- package/dist/utilities/renderTable.d.ts.map +1 -1
- package/dist/utilities/renderTable.js +2 -0
- package/dist/utilities/renderTable.js.map +1 -1
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +48 -13
- package/dist/views/Edit/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -8,10 +8,12 @@ type BuildFormStateSuccessResult = {
|
|
|
8
8
|
clientConfig?: ClientConfig;
|
|
9
9
|
errors?: never;
|
|
10
10
|
indexPath?: string;
|
|
11
|
+
livePreviewURL?: string;
|
|
11
12
|
lockedState?: LockedState;
|
|
12
13
|
state: FormState;
|
|
13
14
|
};
|
|
14
15
|
type BuildFormStateErrorResult = {
|
|
16
|
+
livePreviewURL?: never;
|
|
15
17
|
lockedState?: never;
|
|
16
18
|
state?: never;
|
|
17
19
|
} & ({
|
|
@@ -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;AAahB,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,KAAK,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,KAAK,yBAAyB,GAAG;IAC/B,cAAc,CAAC,EAAE,KAAK,CAAA;IACtB,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,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,CAmLrC,CAAA"}
|
|
@@ -6,6 +6,7 @@ import { getClientConfig } from './getClientConfig.js';
|
|
|
6
6
|
import { getClientSchemaMap } from './getClientSchemaMap.js';
|
|
7
7
|
import { getSchemaMap } from './getSchemaMap.js';
|
|
8
8
|
import { handleFormStateLocking } from './handleFormStateLocking.js';
|
|
9
|
+
import { handleLivePreview } from './handleLivePreview.js';
|
|
9
10
|
export const buildFormStateHandler = async args => {
|
|
10
11
|
const {
|
|
11
12
|
req
|
|
@@ -56,6 +57,7 @@ export const buildFormState = async args => {
|
|
|
56
57
|
config
|
|
57
58
|
}
|
|
58
59
|
},
|
|
60
|
+
returnLivePreviewURL,
|
|
59
61
|
returnLockStatus,
|
|
60
62
|
schemaPath = collectionSlug || globalSlug,
|
|
61
63
|
select,
|
|
@@ -161,9 +163,26 @@ export const buildFormState = async args => {
|
|
|
161
163
|
updateLastEdited
|
|
162
164
|
});
|
|
163
165
|
}
|
|
164
|
-
|
|
166
|
+
const res = {
|
|
165
167
|
lockedState: lockedStateResult,
|
|
166
168
|
state: formStateResult
|
|
167
169
|
};
|
|
170
|
+
if (returnLivePreviewURL) {
|
|
171
|
+
const {
|
|
172
|
+
livePreviewURL
|
|
173
|
+
} = await handleLivePreview({
|
|
174
|
+
collectionSlug,
|
|
175
|
+
config,
|
|
176
|
+
data,
|
|
177
|
+
globalSlug,
|
|
178
|
+
req
|
|
179
|
+
});
|
|
180
|
+
// Important: only set this when not undefined,
|
|
181
|
+
// Otherwise it will travel through the network as `$undefined`
|
|
182
|
+
if (livePreviewURL) {
|
|
183
|
+
res.livePreviewURL = livePreviewURL;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return res;
|
|
168
187
|
};
|
|
169
188
|
//# sourceMappingURL=buildFormState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.js","names":["canAccessAdmin","formatErrors","getSelectMode","reduceFieldsToValues","fieldSchemasToFormState","renderField","getClientConfig","getClientSchemaMap","getSchemaMap","handleFormStateLocking","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","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"],"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'\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 lockedState?: LockedState\n state: FormState\n}\n\ntype BuildFormStateErrorResult = {\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 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 return {\n lockedState: lockedStateResult,\n state: formStateResult,\n }\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;AA4BvC,OAAO,MAAMC,qBAAA,GAGT,MAAOC,IAAA;EACT,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,IAAI;IACF,MAAMX,cAAA,CAAe;MAAEY;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,EAAK;IAAyC;IAE9E,IAAIJ,GAAA,CAAIK,OAAO,KAAK,8CAA8C;MAChE,OAAO;QACLA,OAAA,EAASL,GAAA,CAAIK;MACf;IACF;IAEA,IAAIL,GAAA,CAAIK,OAAO,KAAK,gBAAgB;MAClC,MAAM,IAAIC,KAAA,CAAM;IAClB;IAEA,OAAOpB,YAAA,CAAac,GAAA;EACtB;AACF;AAEA,OAAO,MAAMD,cAAA,GAAiB,MAC5BH,IAAA;EAEA,MAAM;IACJW,EAAA,EAAIC,UAAU;IACdC,c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,GAAA;IACA6B,UAAA;IACAC,MAAA;IACAI,UAAA;IACAF;EACF;EAEA;EACA,IAAIpB,cAAA,IAAkBM,SAAA,EAAW;IAC/B,IAAId,OAAA,CAAQoD,WAAW,CAAC5C,cAAA,CAAe,EAAEe,MAAA,EAAQ8B,MAAA,IAAUvC,SAAA,CAAUwC,IAAI,EAAE;MACzET,eAAA,CAAgBS,IAAI,GAAGxC,SAAA,CAAUwC,IAAI;IACvC;EACF;EAEA,IAAIC,iBAAA;EAEJ,IAAI/B,gBAAA,EAAkB;IACpB+B,iBAAA,GAAoB,MAAM9D,sBAAA,CAAuB;MAC/Ca,EAAA;MACAE,cAAA;MACAO,UAAA;MACAnB,GAAA;MACAiC;IACF;EACF;EAEA,OAAO;IACL2B,WAAA,EAAaD,iBAAA;IACbE,KAAA,EAAOZ;EACT;AACF","ignoreList":[]}
|
|
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,IAAI;IACF,MAAMZ,cAAA,CAAe;MAAEa;IAAI;IAC3B,MAAMC,GAAA,GAAM,MAAMC,cAAA,CAAeH,IAAA;IAEjC,OAAOE,GAAA;EACT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;EAEA,OAAO9D,GAAA;AACT","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures the provided URL is absolute. If not, it converts it to an absolute URL based
|
|
3
|
+
* on the current window location.
|
|
4
|
+
* Note: This MUST be called within the client environment as it relies on the `window` object
|
|
5
|
+
* to determine the absolute URL.
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatAbsoluteURL: (incomingURL: string) => any;
|
|
8
|
+
//# sourceMappingURL=formatAbsoluteURL.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatAbsoluteURL.d.ts","sourceRoot":"","sources":["../../src/utilities/formatAbsoluteURL.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,gBAAiB,MAAM,QAGpB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const getAbsoluteUrl = url => {
|
|
2
|
+
try {
|
|
3
|
+
return new URL(url, window.location.origin).href;
|
|
4
|
+
} catch {
|
|
5
|
+
return url;
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Ensures the provided URL is absolute. If not, it converts it to an absolute URL based
|
|
10
|
+
* on the current window location.
|
|
11
|
+
* Note: This MUST be called within the client environment as it relies on the `window` object
|
|
12
|
+
* to determine the absolute URL.
|
|
13
|
+
*/
|
|
14
|
+
export const formatAbsoluteURL = incomingURL => incomingURL?.startsWith('http://') || incomingURL?.startsWith('https://') ? incomingURL : getAbsoluteUrl(incomingURL);
|
|
15
|
+
//# sourceMappingURL=formatAbsoluteURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatAbsoluteURL.js","names":["getAbsoluteUrl","url","URL","window","location","origin","href","formatAbsoluteURL","incomingURL","startsWith"],"sources":["../../src/utilities/formatAbsoluteURL.ts"],"sourcesContent":["const getAbsoluteUrl = (url) => {\n try {\n return new URL(url, window.location.origin).href\n } catch {\n return url\n }\n}\n\n/**\n * Ensures the provided URL is absolute. If not, it converts it to an absolute URL based\n * on the current window location.\n * Note: This MUST be called within the client environment as it relies on the `window` object\n * to determine the absolute URL.\n */\nexport const formatAbsoluteURL = (incomingURL: string) =>\n incomingURL?.startsWith('http://') || incomingURL?.startsWith('https://')\n ? incomingURL\n : getAbsoluteUrl(incomingURL)\n"],"mappings":"AAAA,MAAMA,cAAA,GAAkBC,GAAA;EACtB,IAAI;IACF,OAAO,IAAIC,GAAA,CAAID,GAAA,EAAKE,MAAA,CAAOC,QAAQ,CAACC,MAAM,EAAEC,IAAI;EAClD,EAAE,MAAM;IACN,OAAOL,GAAA;EACT;AACF;AAEA;;;;;;AAMA,OAAO,MAAMM,iBAAA,GAAqBC,WAAA,IAChCA,WAAA,EAAaC,UAAA,CAAW,cAAcD,WAAA,EAAaC,UAAA,CAAW,cAC1DD,WAAA,GACAR,cAAA,CAAeQ,WAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFolderResultsComponentAndData.d.ts","sourceRoot":"","sources":["../../src/utilities/getFolderResultsComponentAndData.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,oCAAoC,EACpC,cAAc,EAEf,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAWxE,KAAK,sCAAsC,GAAG;IAC5C,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAChC,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC9B,yBAAyB,CAAC,EAAE,cAAc,EAAE,CAAA;IAC5C,sBAAsB,EAAE,KAAK,CAAC,SAAS,CAAA;IACvC,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAChC,CAAA;AAED,KAAK,2CAA2C,GAAG;IACjD,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,SAAS,CAAC,EAAE,KAAK,CAAA;IACjB,sBAAsB,CAAC,EAAE,KAAK,CAAA;IAC9B,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB,GAAG,CACA;IACE,OAAO,EAAE,MAAM,CAAA;CAChB,GACD,WAAW,CACd,CAAA;AAED,eAAO,MAAM,uCAAuC,EAAE,cAAc,CAClE,oCAAoC,EACpC,OAAO,CAAC,2CAA2C,GAAG,sCAAsC,CAAC,CAe9F,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,gIAQ1C,oCAAoC,KAAG,OAAO,CAAC,sCAAsC,
|
|
1
|
+
{"version":3,"file":"getFolderResultsComponentAndData.d.ts","sourceRoot":"","sources":["../../src/utilities/getFolderResultsComponentAndData.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,oCAAoC,EACpC,cAAc,EAEf,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAWxE,KAAK,sCAAsC,GAAG;IAC5C,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAChC,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC9B,yBAAyB,CAAC,EAAE,cAAc,EAAE,CAAA;IAC5C,sBAAsB,EAAE,KAAK,CAAC,SAAS,CAAA;IACvC,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAChC,CAAA;AAED,KAAK,2CAA2C,GAAG;IACjD,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,SAAS,CAAC,EAAE,KAAK,CAAA;IACjB,sBAAsB,CAAC,EAAE,KAAK,CAAA;IAC9B,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB,GAAG,CACA;IACE,OAAO,EAAE,MAAM,CAAA;CAChB,GACD,WAAW,CACd,CAAA;AAED,eAAO,MAAM,uCAAuC,EAAE,cAAc,CAClE,oCAAoC,EACpC,OAAO,CAAC,2CAA2C,GAAG,sCAAsC,CAAC,CAe9F,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,gIAQ1C,oCAAoC,KAAG,OAAO,CAAC,sCAAsC,CA8HvF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFolderResultsComponentAndData.js","names":["APIError","formatErrors","getFolderData","buildFolderWhereConstraints","combineWhereConstraints","FolderFileTable","ItemCardGrid","getFolderResultsComponentAndDataHandler","args","req","res","getFolderResultsComponentAndData","err","payload","logger","error","msg","browseByFolder","collectionsToDisplay","activeCollectionSlugs","displayAs","folderAssignedCollections","folderID","undefined","sort","config","folders","emptyQuery","id","exists","collectionSlug","documentWhere","Array","isArray","length","folderWhere","activeCollectionSlug","slug","folderCollectionConstraints","collectionConfig","collections","localeCode","locale","search","query","collectionSpecific","or","folderType","in","equals","collectionConstraints","push","folderData","FolderResultsComponent","_jsxs","subfolders","_jsx","_Fragment","items","title","type","documents","subfolderCount","showRelationCell","breadcrumbs"],"sources":["../../src/utilities/getFolderResultsComponentAndData.tsx"],"sourcesContent":["import type {\n CollectionSlug,\n ErrorResult,\n GetFolderResultsComponentAndDataArgs,\n ServerFunction,\n Where,\n} from 'payload'\nimport type { FolderBreadcrumb, FolderOrDocument } from 'payload/shared'\n\nimport { APIError, formatErrors, getFolderData } from 'payload'\nimport { buildFolderWhereConstraints, combineWhereConstraints } from 'payload/shared'\n\nimport {\n FolderFileTable,\n ItemCardGrid,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- This component is returned via server functions, it must reference the exports dir\n} from '../exports/client/index.js'\n\ntype GetFolderResultsComponentAndDataResult = {\n breadcrumbs?: FolderBreadcrumb[]\n documents?: FolderOrDocument[]\n folderAssignedCollections?: CollectionSlug[]\n FolderResultsComponent: React.ReactNode\n subfolders?: FolderOrDocument[]\n}\n\ntype GetFolderResultsComponentAndDataErrorResult = {\n breadcrumbs?: never\n documents?: never\n FolderResultsComponent?: never\n subfolders?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport const getFolderResultsComponentAndDataHandler: ServerFunction<\n GetFolderResultsComponentAndDataArgs,\n Promise<GetFolderResultsComponentAndDataErrorResult | GetFolderResultsComponentAndDataResult>\n> = async (args) => {\n const { req } = args\n\n try {\n const res = await getFolderResultsComponentAndData(args)\n return res\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `There was an error getting the folder results component and data`,\n })\n\n return formatErrors(err)\n }\n}\n\n/**\n * This function is responsible for fetching folder data, building the results component\n * and returns the data and component together.\n */\nexport const getFolderResultsComponentAndData = async ({\n browseByFolder = false,\n collectionsToDisplay: activeCollectionSlugs,\n displayAs,\n folderAssignedCollections,\n folderID = undefined,\n req,\n sort,\n}: GetFolderResultsComponentAndDataArgs): Promise<GetFolderResultsComponentAndDataResult> => {\n const { payload } = req\n\n if (!payload.config.folders) {\n throw new APIError('Folders are not enabled in the configuration.')\n }\n\n const emptyQuery = {\n id: {\n exists: false,\n },\n }\n\n let collectionSlug: CollectionSlug | undefined = undefined\n let documentWhere: undefined | Where =\n Array.isArray(activeCollectionSlugs) && !activeCollectionSlugs.length ? emptyQuery : undefined\n let folderWhere: undefined | Where =\n Array.isArray(activeCollectionSlugs) && !activeCollectionSlugs.length ? emptyQuery : undefined\n\n // todo(perf): - collect promises and resolve them in parallel\n for (const activeCollectionSlug of activeCollectionSlugs) {\n if (activeCollectionSlug === payload.config.folders.slug) {\n const folderCollectionConstraints = await buildFolderWhereConstraints({\n collectionConfig: payload.collections[activeCollectionSlug].config,\n folderID,\n localeCode: req?.locale,\n req,\n search: typeof req?.query?.search === 'string' ? req.query.search : undefined,\n sort,\n })\n\n if (folderCollectionConstraints) {\n folderWhere = folderCollectionConstraints\n }\n\n folderWhere = combineWhereConstraints([\n folderWhere,\n Array.isArray(folderAssignedCollections) &&\n folderAssignedCollections.length &&\n payload.config.folders.collectionSpecific\n ? {\n or: [\n {\n folderType: {\n in: folderAssignedCollections,\n },\n },\n // if the folderType is not set, it means it accepts all collections and should appear in the results\n {\n folderType: {\n exists: false,\n },\n },\n {\n folderType: {\n equals: null,\n },\n },\n ],\n }\n : undefined,\n ])\n } else if ((browseByFolder && folderID) || !browseByFolder) {\n if (!browseByFolder) {\n collectionSlug = activeCollectionSlug\n }\n\n if (!documentWhere) {\n documentWhere = {\n or: [],\n }\n }\n\n const collectionConstraints = await buildFolderWhereConstraints({\n collectionConfig: payload.collections[activeCollectionSlug].config,\n folderID,\n localeCode: req?.locale,\n req,\n search: typeof req?.query?.search === 'string' ? req.query.search : undefined,\n sort,\n })\n\n if (collectionConstraints) {\n documentWhere.or.push(collectionConstraints)\n }\n }\n }\n\n const folderData = await getFolderData({\n collectionSlug,\n documentWhere,\n folderID,\n folderWhere,\n req,\n sort,\n })\n\n let FolderResultsComponent = null\n\n if (displayAs === 'grid') {\n FolderResultsComponent = (\n <div>\n {folderData.subfolders.length ? (\n <>\n <ItemCardGrid items={folderData.subfolders} title={'Folders'} type=\"folder\" />\n </>\n ) : null}\n\n {folderData.documents.length ? (\n <>\n <ItemCardGrid\n items={folderData.documents}\n subfolderCount={folderData.subfolders.length}\n title={'Documents'}\n type=\"file\"\n />\n </>\n ) : null}\n </div>\n )\n } else {\n FolderResultsComponent = <FolderFileTable showRelationCell={browseByFolder} />\n }\n\n return {\n breadcrumbs: folderData.breadcrumbs,\n documents: folderData.documents,\n folderAssignedCollections: folderData.folderAssignedCollections,\n FolderResultsComponent,\n subfolders: folderData.subfolders,\n }\n}\n"],"mappings":";AASA,SAASA,QAAQ,EAAEC,YAAY,EAAEC,aAAa,QAAQ;AACtD,SAASC,2BAA2B,EAAEC,uBAAuB,QAAQ;AAErE,SACEC,eAAe,EACfC,YAAY,QAEP;AAsBP,OAAO,MAAMC,uCAAA,GAGT,MAAOC,IAAA;EACT,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,IAAI;IACF,MAAME,GAAA,GAAM,MAAMC,gCAAA,CAAiCH,IAAA;IACnD,OAAOE,GAAA;EACT,EAAE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,cAAA;IACAC,aAAA;IACAT,QAAA;IACAa,WAAA;IACA1B,GAAA;IACAe;EACF;EAEA,IAAI6B,sBAAA,GAAyB;EAE7B,IAAIjC,SAAA,KAAc,QAAQ;IACxBiC,sBAAA,gBACEC,KAAA,CAAC;iBACEF,UAAA,CAAWG,UAAU,CAACrB,MAAM,gBAC3BsB,IAAA,CAAAC,SAAA;kBACE,aAAAD,IAAA,CAAClD,YAAA;UAAaoD,KAAA,EAAON,UAAA,CAAWG,UAAU;UAAEI,KAAA,EAAO;UAAWC,IAAA,EAAK;;WAEnE,MAEHR,UAAA,CAAWS,SAAS,CAAC3B,MAAM,gBAC1BsB,IAAA,CAAAC,SAAA;kBACE,aAAAD,IAAA,CAAClD,YAAA;UACCoD,KAAA,EAAON,UAAA,CAAWS,SAAS;UAC3BC,cAAA,EAAgBV,UAAA,CAAWG,UAAU,CAACrB,MAAM;UAC5CyB,KAAA,EAAO;UACPC,IAAA,EAAK;;WAGP;;EAGV,OAAO;IACLP,sBAAA,gBAAyBG,IAAA,CAACnD,eAAA;MAAgB0D,gBAAA,EAAkB9C;;EAC9D;EAEA,OAAO;IACL+C,WAAA,EAAaZ,UAAA,CAAWY,WAAW;IACnCH,SAAA,EAAWT,UAAA,CAAWS,SAAS;IAC/BxC,yBAAA,EAA2B+B,UAAA,CAAW/B,yBAAyB;IAC/DgC,sBAAA;IACAE,UAAA,EAAYH,UAAA,CAAWG;EACzB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"getFolderResultsComponentAndData.js","names":["APIError","formatErrors","getFolderData","buildFolderWhereConstraints","combineWhereConstraints","FolderFileTable","ItemCardGrid","getFolderResultsComponentAndDataHandler","args","req","res","getFolderResultsComponentAndData","err","payload","logger","error","msg","browseByFolder","collectionsToDisplay","activeCollectionSlugs","displayAs","folderAssignedCollections","folderID","undefined","sort","config","folders","emptyQuery","id","exists","collectionSlug","documentWhere","Array","isArray","length","folderWhere","activeCollectionSlug","slug","folderCollectionConstraints","collectionConfig","collections","localeCode","locale","search","query","collectionSpecific","or","folderType","in","collectionConstraints","push","folderData","FolderResultsComponent","_jsxs","subfolders","_jsx","_Fragment","items","title","type","documents","subfolderCount","showRelationCell","breadcrumbs"],"sources":["../../src/utilities/getFolderResultsComponentAndData.tsx"],"sourcesContent":["import type {\n CollectionSlug,\n ErrorResult,\n GetFolderResultsComponentAndDataArgs,\n ServerFunction,\n Where,\n} from 'payload'\nimport type { FolderBreadcrumb, FolderOrDocument } from 'payload/shared'\n\nimport { APIError, formatErrors, getFolderData } from 'payload'\nimport { buildFolderWhereConstraints, combineWhereConstraints } from 'payload/shared'\n\nimport {\n FolderFileTable,\n ItemCardGrid,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- This component is returned via server functions, it must reference the exports dir\n} from '../exports/client/index.js'\n\ntype GetFolderResultsComponentAndDataResult = {\n breadcrumbs?: FolderBreadcrumb[]\n documents?: FolderOrDocument[]\n folderAssignedCollections?: CollectionSlug[]\n FolderResultsComponent: React.ReactNode\n subfolders?: FolderOrDocument[]\n}\n\ntype GetFolderResultsComponentAndDataErrorResult = {\n breadcrumbs?: never\n documents?: never\n FolderResultsComponent?: never\n subfolders?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport const getFolderResultsComponentAndDataHandler: ServerFunction<\n GetFolderResultsComponentAndDataArgs,\n Promise<GetFolderResultsComponentAndDataErrorResult | GetFolderResultsComponentAndDataResult>\n> = async (args) => {\n const { req } = args\n\n try {\n const res = await getFolderResultsComponentAndData(args)\n return res\n } catch (err) {\n req.payload.logger.error({\n err,\n msg: `There was an error getting the folder results component and data`,\n })\n\n return formatErrors(err)\n }\n}\n\n/**\n * This function is responsible for fetching folder data, building the results component\n * and returns the data and component together.\n */\nexport const getFolderResultsComponentAndData = async ({\n browseByFolder = false,\n collectionsToDisplay: activeCollectionSlugs,\n displayAs,\n folderAssignedCollections,\n folderID = undefined,\n req,\n sort,\n}: GetFolderResultsComponentAndDataArgs): Promise<GetFolderResultsComponentAndDataResult> => {\n const { payload } = req\n\n if (!payload.config.folders) {\n throw new APIError('Folders are not enabled in the configuration.')\n }\n\n const emptyQuery = {\n id: {\n exists: false,\n },\n }\n\n let collectionSlug: CollectionSlug | undefined = undefined\n let documentWhere: undefined | Where =\n Array.isArray(activeCollectionSlugs) && !activeCollectionSlugs.length ? emptyQuery : undefined\n let folderWhere: undefined | Where =\n Array.isArray(activeCollectionSlugs) && !activeCollectionSlugs.length ? emptyQuery : undefined\n\n // todo(perf): - collect promises and resolve them in parallel\n for (const activeCollectionSlug of activeCollectionSlugs) {\n if (activeCollectionSlug === payload.config.folders.slug) {\n const folderCollectionConstraints = await buildFolderWhereConstraints({\n collectionConfig: payload.collections[activeCollectionSlug].config,\n folderID,\n localeCode: req?.locale,\n req,\n search: typeof req?.query?.search === 'string' ? req.query.search : undefined,\n sort,\n })\n\n if (folderCollectionConstraints) {\n folderWhere = folderCollectionConstraints\n }\n\n folderWhere = combineWhereConstraints([\n folderWhere,\n Array.isArray(folderAssignedCollections) &&\n folderAssignedCollections.length &&\n payload.config.folders.collectionSpecific\n ? {\n or: [\n {\n folderType: {\n in: folderAssignedCollections,\n },\n },\n // if the folderType is not set, it means it accepts all collections and should appear in the results\n {\n folderType: {\n exists: false,\n },\n },\n ],\n }\n : undefined,\n ])\n } else if ((browseByFolder && folderID) || !browseByFolder) {\n if (!browseByFolder) {\n collectionSlug = activeCollectionSlug\n }\n\n if (!documentWhere) {\n documentWhere = {\n or: [],\n }\n }\n\n const collectionConstraints = await buildFolderWhereConstraints({\n collectionConfig: payload.collections[activeCollectionSlug].config,\n folderID,\n localeCode: req?.locale,\n req,\n search: typeof req?.query?.search === 'string' ? req.query.search : undefined,\n sort,\n })\n\n if (collectionConstraints) {\n documentWhere.or.push(collectionConstraints)\n }\n }\n }\n\n const folderData = await getFolderData({\n collectionSlug,\n documentWhere,\n folderID,\n folderWhere,\n req,\n sort,\n })\n\n let FolderResultsComponent = null\n\n if (displayAs === 'grid') {\n FolderResultsComponent = (\n <div>\n {folderData.subfolders.length ? (\n <>\n <ItemCardGrid items={folderData.subfolders} title={'Folders'} type=\"folder\" />\n </>\n ) : null}\n\n {folderData.documents.length ? (\n <>\n <ItemCardGrid\n items={folderData.documents}\n subfolderCount={folderData.subfolders.length}\n title={'Documents'}\n type=\"file\"\n />\n </>\n ) : null}\n </div>\n )\n } else {\n FolderResultsComponent = <FolderFileTable showRelationCell={browseByFolder} />\n }\n\n return {\n breadcrumbs: folderData.breadcrumbs,\n documents: folderData.documents,\n folderAssignedCollections: folderData.folderAssignedCollections,\n FolderResultsComponent,\n subfolders: folderData.subfolders,\n }\n}\n"],"mappings":";AASA,SAASA,QAAQ,EAAEC,YAAY,EAAEC,aAAa,QAAQ;AACtD,SAASC,2BAA2B,EAAEC,uBAAuB,QAAQ;AAErE,SACEC,eAAe,EACfC,YAAY,QAEP;AAsBP,OAAO,MAAMC,uCAAA,GAGT,MAAOC,IAAA;EACT,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,IAAI;IACF,MAAME,GAAA,GAAM,MAAMC,gCAAA,CAAiCH,IAAA;IACnD,OAAOE,GAAA;EACT,EAAE,OAAOE,GAAA,EAAK;IACZH,GAAA,CAAII,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;MACvBH,GAAA;MACAI,GAAA,EAAK;IACP;IAEA,OAAOf,YAAA,CAAaW,GAAA;EACtB;AACF;AAEA;;;;AAIA,OAAO,MAAMD,gCAAA,GAAmC,MAAAA,CAAO;EACrDM,cAAA,GAAiB,KAAK;EACtBC,oBAAA,EAAsBC,qBAAqB;EAC3CC,SAAS;EACTC,yBAAyB;EACzBC,QAAA,GAAWC,SAAS;EACpBd,GAAG;EACHe;AAAI,CACiC;EACrC,MAAM;IAAEX;EAAO,CAAE,GAAGJ,GAAA;EAEpB,IAAI,CAACI,OAAA,CAAQY,MAAM,CAACC,OAAO,EAAE;IAC3B,MAAM,IAAI1B,QAAA,CAAS;EACrB;EAEA,MAAM2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AA,EAAO;UACPC,IAAA,EAAK;;WAGP;;EAGV,OAAO;IACLP,sBAAA,gBAAyBG,IAAA,CAAClD,eAAA;MAAgByD,gBAAA,EAAkB7C;;EAC9D;EAEA,OAAO;IACL8C,WAAA,EAAaZ,UAAA,CAAWY,WAAW;IACnCH,SAAA,EAAWT,UAAA,CAAWS,SAAS;IAC/BvC,yBAAA,EAA2B8B,UAAA,CAAW9B,yBAAyB;IAC/D+B,sBAAA;IACAE,UAAA,EAAYH,UAAA,CAAWG;EACzB;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CollectionConfig, GlobalConfig, LivePreviewConfig, Operation, PayloadRequest, SanitizedConfig } from 'payload';
|
|
2
|
+
export declare const getLivePreviewConfig: ({ collectionConfig, config, globalConfig, isLivePreviewEnabled, }: {
|
|
3
|
+
collectionConfig?: CollectionConfig;
|
|
4
|
+
config: SanitizedConfig;
|
|
5
|
+
globalConfig?: GlobalConfig;
|
|
6
|
+
isLivePreviewEnabled: boolean;
|
|
7
|
+
}) => {
|
|
8
|
+
breakpoints?: {
|
|
9
|
+
height: number | string;
|
|
10
|
+
label: string;
|
|
11
|
+
name: string;
|
|
12
|
+
width: number | string;
|
|
13
|
+
}[];
|
|
14
|
+
url?: ((args: {
|
|
15
|
+
collectionConfig?: import("payload").SanitizedCollectionConfig;
|
|
16
|
+
data: Record<string, any>;
|
|
17
|
+
globalConfig?: import("payload").SanitizedGlobalConfig;
|
|
18
|
+
locale: import("payload").Locale;
|
|
19
|
+
payload: import("payload").Payload;
|
|
20
|
+
req: PayloadRequest;
|
|
21
|
+
}) => Promise<string> | string) | string;
|
|
22
|
+
collections?: string[];
|
|
23
|
+
globals?: string[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Multi-level check to determine whether live preview is enabled on a collection or global.
|
|
27
|
+
* For example, live preview can be enabled at both the root config level, or on the entity's config.
|
|
28
|
+
* If a collectionConfig/globalConfig is provided, checks if it is enabled at the root level,
|
|
29
|
+
* or on the entity's own config.
|
|
30
|
+
*/
|
|
31
|
+
export declare const isLivePreviewEnabled: ({ collectionConfig, config, globalConfig, }: {
|
|
32
|
+
collectionConfig?: CollectionConfig;
|
|
33
|
+
config: SanitizedConfig;
|
|
34
|
+
globalConfig?: GlobalConfig;
|
|
35
|
+
}) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* 1. Looks up the relevant live preview config, which could have been enabled:
|
|
38
|
+
* a. At the root level, e.g. `collections: ['posts']`
|
|
39
|
+
* b. On the collection or global config, e.g. `admin: { livePreview: { ... } }`
|
|
40
|
+
* 2. Determines if live preview is enabled, and if not, early returns.
|
|
41
|
+
* 3. Merges the config with the root config, if necessary.
|
|
42
|
+
* 4. Executes the `url` function, if necessary.
|
|
43
|
+
*
|
|
44
|
+
* Notice: internal function only. Subject to change at any time. Use at your own discretion.
|
|
45
|
+
*/
|
|
46
|
+
export declare const handleLivePreview: ({ collectionSlug, config, data, globalSlug, operation, req, }: {
|
|
47
|
+
collectionSlug?: string;
|
|
48
|
+
config: SanitizedConfig;
|
|
49
|
+
data: Record<string, unknown>;
|
|
50
|
+
globalSlug?: string;
|
|
51
|
+
operation?: Operation;
|
|
52
|
+
req: PayloadRequest;
|
|
53
|
+
}) => Promise<{
|
|
54
|
+
isLivePreviewEnabled?: boolean;
|
|
55
|
+
livePreviewConfig?: LivePreviewConfig;
|
|
56
|
+
livePreviewURL?: string;
|
|
57
|
+
}>;
|
|
58
|
+
//# sourceMappingURL=handleLivePreview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleLivePreview.d.ts","sourceRoot":"","sources":["../../src/utilities/handleLivePreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,eAAe,EAChB,MAAM,SAAS,CAAA;AAEhB,eAAO,MAAM,oBAAoB,sEAK9B;IACD,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,oBAAoB,EAAE,OAAO,CAAA;CAC9B;;;;;;;;wBAsHk0D,CAAC;;oBAAoF,CAAC;;;;;;;CAlHv5D,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,gDAI9B;IACD,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,KAAG,OAcH,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,kEAO3B;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,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAqDA,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export const getLivePreviewConfig = ({
|
|
2
|
+
collectionConfig,
|
|
3
|
+
config,
|
|
4
|
+
globalConfig,
|
|
5
|
+
isLivePreviewEnabled
|
|
6
|
+
}) => ({
|
|
7
|
+
...(isLivePreviewEnabled ? config.admin.livePreview : {}),
|
|
8
|
+
...(collectionConfig?.admin?.livePreview || {}),
|
|
9
|
+
...(globalConfig?.admin?.livePreview || {})
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Multi-level check to determine whether live preview is enabled on a collection or global.
|
|
13
|
+
* For example, live preview can be enabled at both the root config level, or on the entity's config.
|
|
14
|
+
* If a collectionConfig/globalConfig is provided, checks if it is enabled at the root level,
|
|
15
|
+
* or on the entity's own config.
|
|
16
|
+
*/
|
|
17
|
+
export const isLivePreviewEnabled = ({
|
|
18
|
+
collectionConfig,
|
|
19
|
+
config,
|
|
20
|
+
globalConfig
|
|
21
|
+
}) => {
|
|
22
|
+
if (globalConfig) {
|
|
23
|
+
return Boolean(config.admin?.livePreview?.globals?.includes(globalConfig.slug) || globalConfig.admin?.livePreview);
|
|
24
|
+
}
|
|
25
|
+
if (collectionConfig) {
|
|
26
|
+
return Boolean(config.admin?.livePreview?.collections?.includes(collectionConfig.slug) || collectionConfig.admin?.livePreview);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 1. Looks up the relevant live preview config, which could have been enabled:
|
|
31
|
+
* a. At the root level, e.g. `collections: ['posts']`
|
|
32
|
+
* b. On the collection or global config, e.g. `admin: { livePreview: { ... } }`
|
|
33
|
+
* 2. Determines if live preview is enabled, and if not, early returns.
|
|
34
|
+
* 3. Merges the config with the root config, if necessary.
|
|
35
|
+
* 4. Executes the `url` function, if necessary.
|
|
36
|
+
*
|
|
37
|
+
* Notice: internal function only. Subject to change at any time. Use at your own discretion.
|
|
38
|
+
*/
|
|
39
|
+
export const handleLivePreview = async ({
|
|
40
|
+
collectionSlug,
|
|
41
|
+
config,
|
|
42
|
+
data,
|
|
43
|
+
globalSlug,
|
|
44
|
+
operation,
|
|
45
|
+
req
|
|
46
|
+
}) => {
|
|
47
|
+
const collectionConfig = collectionSlug ? req.payload.collections[collectionSlug]?.config : undefined;
|
|
48
|
+
const globalConfig = globalSlug ? config.globals.find(g => g.slug === globalSlug) : undefined;
|
|
49
|
+
const enabled = isLivePreviewEnabled({
|
|
50
|
+
collectionConfig,
|
|
51
|
+
config,
|
|
52
|
+
globalConfig
|
|
53
|
+
});
|
|
54
|
+
if (!enabled) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
const livePreviewConfig = getLivePreviewConfig({
|
|
58
|
+
collectionConfig,
|
|
59
|
+
config,
|
|
60
|
+
globalConfig,
|
|
61
|
+
isLivePreviewEnabled: enabled
|
|
62
|
+
});
|
|
63
|
+
let livePreviewURL;
|
|
64
|
+
if (typeof livePreviewConfig?.url === 'string') {
|
|
65
|
+
livePreviewURL = livePreviewConfig.url;
|
|
66
|
+
}
|
|
67
|
+
if (typeof livePreviewConfig?.url === 'function' && operation !== 'create') {
|
|
68
|
+
try {
|
|
69
|
+
const result = await livePreviewConfig.url({
|
|
70
|
+
collectionConfig,
|
|
71
|
+
data,
|
|
72
|
+
globalConfig,
|
|
73
|
+
locale: {
|
|
74
|
+
code: req.locale,
|
|
75
|
+
label: ''
|
|
76
|
+
},
|
|
77
|
+
payload: req.payload,
|
|
78
|
+
req
|
|
79
|
+
});
|
|
80
|
+
if (typeof result === 'string') {
|
|
81
|
+
livePreviewURL = result;
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
req.payload.logger.error({
|
|
85
|
+
err,
|
|
86
|
+
msg: `There was an error executing the live preview URL function for ${collectionSlug || globalSlug}`
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
isLivePreviewEnabled: enabled,
|
|
92
|
+
livePreviewConfig,
|
|
93
|
+
livePreviewURL
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=handleLivePreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleLivePreview.js","names":["getLivePreviewConfig","collectionConfig","config","globalConfig","isLivePreviewEnabled","admin","livePreview","Boolean","globals","includes","slug","collections","handleLivePreview","collectionSlug","data","globalSlug","operation","req","payload","undefined","find","g","enabled","livePreviewConfig","livePreviewURL","url","result","locale","code","label","err","logger","error","msg"],"sources":["../../src/utilities/handleLivePreview.ts"],"sourcesContent":["import type {\n CollectionConfig,\n GlobalConfig,\n LivePreviewConfig,\n Operation,\n PayloadRequest,\n SanitizedConfig,\n} from 'payload'\n\nexport const getLivePreviewConfig = ({\n collectionConfig,\n config,\n globalConfig,\n isLivePreviewEnabled,\n}: {\n collectionConfig?: CollectionConfig\n config: SanitizedConfig\n globalConfig?: GlobalConfig\n isLivePreviewEnabled: boolean\n}) => ({\n ...(isLivePreviewEnabled ? config.admin.livePreview : {}),\n ...(collectionConfig?.admin?.livePreview || {}),\n ...(globalConfig?.admin?.livePreview || {}),\n})\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 isLivePreviewEnabled = ({\n collectionConfig,\n config,\n globalConfig,\n}: {\n collectionConfig?: CollectionConfig\n config: SanitizedConfig\n globalConfig?: GlobalConfig\n}): boolean => {\n if (globalConfig) {\n return Boolean(\n config.admin?.livePreview?.globals?.includes(globalConfig.slug) ||\n globalConfig.admin?.livePreview,\n )\n }\n\n if (collectionConfig) {\n return Boolean(\n config.admin?.livePreview?.collections?.includes(collectionConfig.slug) ||\n collectionConfig.admin?.livePreview,\n )\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 discretion.\n */\nexport const handleLivePreview = 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 isLivePreviewEnabled?: boolean\n livePreviewConfig?: LivePreviewConfig\n livePreviewURL?: 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 = isLivePreviewEnabled({\n collectionConfig,\n config,\n globalConfig,\n })\n\n if (!enabled) {\n return {}\n }\n\n const livePreviewConfig = getLivePreviewConfig({\n collectionConfig,\n config,\n globalConfig,\n isLivePreviewEnabled: enabled,\n })\n\n let livePreviewURL: string | undefined\n\n if (typeof livePreviewConfig?.url === 'string') {\n livePreviewURL = livePreviewConfig.url\n }\n\n if (typeof livePreviewConfig?.url === 'function' && operation !== 'create') {\n try {\n const result = await livePreviewConfig.url({\n collectionConfig,\n data,\n globalConfig,\n locale: { code: req.locale, label: '' },\n payload: req.payload,\n req,\n })\n\n if (typeof result === 'string') {\n livePreviewURL = 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 { isLivePreviewEnabled: enabled, livePreviewConfig, livePreviewURL }\n}\n"],"mappings":"AASA,OAAO,MAAMA,oBAAA,GAAuBA,CAAC;EACnCC,gBAAgB;EAChBC,MAAM;EACNC,YAAY;EACZC;AAAoB,CAMrB,MAAM;EACL,IAAIA,oBAAA,GAAuBF,MAAA,CAAOG,KAAK,CAACC,WAAW,GAAG,CAAC,CAAC;EACxD,IAAIL,gBAAA,EAAkBI,KAAA,EAAOC,WAAA,IAAe,CAAC,CAAC;EAC9C,IAAIH,YAAA,EAAcE,KAAA,EAAOC,WAAA,IAAe,CAAC,CAAC;AAC5C;AAEA;;;;;;AAMA,OAAO,MAAMF,oBAAA,GAAuBA,CAAC;EACnCH,gBAAgB;EAChBC,MAAM;EACNC;AAAY,CAKb;EACC,IAAIA,YAAA,EAAc;IAChB,OAAOI,OAAA,CACLL,MAAA,CAAOG,KAAK,EAAEC,WAAA,EAAaE,OAAA,EAASC,QAAA,CAASN,YAAA,CAAaO,IAAI,KAC5DP,YAAA,CAAaE,KAAK,EAAEC,WAAA;EAE1B;EAEA,IAAIL,g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OAAA,EAASD,GAAA,CAAIC,OAAO;QACpBD;MACF;MAEA,IAAI,OAAOS,MAAA,KAAW,UAAU;QAC9BF,cAAA,GAAiBE,MAAA;MACnB;IACF,EAAE,OAAOI,GAAA,EAAK;MACZb,GAAA,CAAIC,OAAO,CAACa,MAAM,CAACC,KAAK,CAAC;QACvBF,GAAA;QACAG,GAAA,EAAK,kEAAkEpB,cAAA,IAAkBE,UAAA;MAC3F;IACF;EACF;EAEA,OAAO;IAAEX,oBAAA,EAAsBkB,OAAA;IAASC,iBAAA;IAAmBC;EAAe;AAC5E","ignoreList":[]}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import type { ClientUser } from 'payload';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export interface HandleTakeOverParams {
|
|
3
|
+
clearRouteCache?: () => void;
|
|
4
|
+
collectionSlug?: string;
|
|
5
|
+
documentLockStateRef: React.RefObject<{
|
|
6
|
+
hasShownLockedModal: boolean;
|
|
7
|
+
isLocked: boolean;
|
|
8
|
+
user: ClientUser | number | string;
|
|
9
|
+
}>;
|
|
10
|
+
globalSlug?: string;
|
|
11
|
+
id: number | string;
|
|
12
|
+
isLockingEnabled: boolean;
|
|
13
|
+
isWithinDoc: boolean;
|
|
14
|
+
setCurrentEditor: (value: React.SetStateAction<ClientUser | number | string>) => void;
|
|
15
|
+
setIsReadOnlyForIncomingUser?: (value: React.SetStateAction<boolean>) => void;
|
|
16
|
+
updateDocumentEditor: (docID: number | string, slug: string, user: ClientUser | number | string) => Promise<void>;
|
|
5
17
|
user: ClientUser | number | string;
|
|
6
|
-
}
|
|
18
|
+
}
|
|
19
|
+
export declare const handleTakeOver: ({ id, clearRouteCache, collectionSlug, documentLockStateRef, globalSlug, isLockingEnabled, isWithinDoc, setCurrentEditor, setIsReadOnlyForIncomingUser, updateDocumentEditor, user, }: HandleTakeOverParams) => Promise<void>;
|
|
7
20
|
//# sourceMappingURL=handleTakeOver.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleTakeOver.d.ts","sourceRoot":"","sources":["../../src/utilities/handleTakeOver.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,
|
|
1
|
+
{"version":3,"file":"handleTakeOver.d.ts","sourceRoot":"","sources":["../../src/utilities/handleTakeOver.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,WAAW,oBAAoB;IACnC,eAAe,CAAC,EAAE,MAAM,IAAI,CAAA;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,oBAAoB,EAAE,KAAK,CAAC,SAAS,CAAC;QACpC,mBAAmB,EAAE,OAAO,CAAA;QAC5B,QAAQ,EAAE,OAAO,CAAA;QACjB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;KACnC,CAAC,CAAA;IACF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,gBAAgB,EAAE,OAAO,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,gBAAgB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC,KAAK,IAAI,CAAA;IACrF,4BAA4B,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,IAAI,CAAA;IAC7E,oBAAoB,EAAE,CACpB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,KAC/B,OAAO,CAAC,IAAI,CAAC,CAAA;IAClB,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;CACnC;AAED,eAAO,MAAM,cAAc,0LAYxB,oBAAoB,KAAG,OAAO,CAAC,IAAI,CAkCrC,CAAA"}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
export const handleTakeOver = (
|
|
1
|
+
export const handleTakeOver = async ({
|
|
2
|
+
id,
|
|
3
|
+
clearRouteCache,
|
|
4
|
+
collectionSlug,
|
|
5
|
+
documentLockStateRef,
|
|
6
|
+
globalSlug,
|
|
7
|
+
isLockingEnabled,
|
|
8
|
+
isWithinDoc,
|
|
9
|
+
setCurrentEditor,
|
|
10
|
+
setIsReadOnlyForIncomingUser,
|
|
11
|
+
updateDocumentEditor,
|
|
12
|
+
user
|
|
13
|
+
}) => {
|
|
2
14
|
if (!isLockingEnabled) {
|
|
3
15
|
return;
|
|
4
16
|
}
|
|
5
17
|
try {
|
|
6
18
|
// Call updateDocumentEditor to update the document's owner to the current user
|
|
7
|
-
|
|
19
|
+
await updateDocumentEditor(id, collectionSlug ?? globalSlug, user);
|
|
8
20
|
if (!isWithinDoc) {
|
|
9
21
|
documentLockStateRef.current.hasShownLockedModal = true;
|
|
10
22
|
}
|
|
@@ -19,6 +31,10 @@ export const handleTakeOver = (id, collectionSlug, globalSlug, user, isWithinDoc
|
|
|
19
31
|
if (isWithinDoc && setIsReadOnlyForIncomingUser) {
|
|
20
32
|
setIsReadOnlyForIncomingUser(false);
|
|
21
33
|
}
|
|
34
|
+
// Need to clear the route cache to refresh the page and update readOnly state for server rendered components
|
|
35
|
+
if (clearRouteCache) {
|
|
36
|
+
clearRouteCache();
|
|
37
|
+
}
|
|
22
38
|
} catch (error) {
|
|
23
39
|
// eslint-disable-next-line no-console
|
|
24
40
|
console.error('Error during document takeover:', error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleTakeOver.js","names":["handleTakeOver","id","collectionSlug","
|
|
1
|
+
{"version":3,"file":"handleTakeOver.js","names":["handleTakeOver","id","clearRouteCache","collectionSlug","documentLockStateRef","globalSlug","isLockingEnabled","isWithinDoc","setCurrentEditor","setIsReadOnlyForIncomingUser","updateDocumentEditor","user","current","hasShownLockedModal","isLocked","error","console"],"sources":["../../src/utilities/handleTakeOver.tsx"],"sourcesContent":["import type { ClientUser } from 'payload'\n\nexport interface HandleTakeOverParams {\n clearRouteCache?: () => void\n collectionSlug?: string\n documentLockStateRef: React.RefObject<{\n hasShownLockedModal: boolean\n isLocked: boolean\n user: ClientUser | number | string\n }>\n globalSlug?: string\n id: number | string\n isLockingEnabled: boolean\n isWithinDoc: boolean\n setCurrentEditor: (value: React.SetStateAction<ClientUser | number | string>) => void\n setIsReadOnlyForIncomingUser?: (value: React.SetStateAction<boolean>) => void\n updateDocumentEditor: (\n docID: number | string,\n slug: string,\n user: ClientUser | number | string,\n ) => Promise<void>\n user: ClientUser | number | string\n}\n\nexport const handleTakeOver = async ({\n id,\n clearRouteCache,\n collectionSlug,\n documentLockStateRef,\n globalSlug,\n isLockingEnabled,\n isWithinDoc,\n setCurrentEditor,\n setIsReadOnlyForIncomingUser,\n updateDocumentEditor,\n user,\n}: HandleTakeOverParams): Promise<void> => {\n if (!isLockingEnabled) {\n return\n }\n\n try {\n // Call updateDocumentEditor to update the document's owner to the current user\n await updateDocumentEditor(id, collectionSlug ?? globalSlug, user)\n\n if (!isWithinDoc) {\n documentLockStateRef.current.hasShownLockedModal = true\n }\n\n // Update the locked state to reflect the current user as the owner\n documentLockStateRef.current = {\n hasShownLockedModal: documentLockStateRef.current?.hasShownLockedModal,\n isLocked: true,\n user,\n }\n setCurrentEditor(user)\n\n // If this is a takeover within the document, ensure the document is editable\n if (isWithinDoc && setIsReadOnlyForIncomingUser) {\n setIsReadOnlyForIncomingUser(false)\n }\n\n // Need to clear the route cache to refresh the page and update readOnly state for server rendered components\n if (clearRouteCache) {\n clearRouteCache()\n }\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error during document takeover:', error)\n }\n}\n"],"mappings":"AAwBA,OAAO,MAAMA,cAAA,GAAiB,MAAAA,CAAO;EACnCC,EAAE;EACFC,eAAe;EACfC,cAAc;EACdC,oBAAoB;EACpBC,UAAU;EACVC,gBAAgB;EAChBC,WAAW;EACXC,gBAAgB;EAChBC,4BAA4B;EAC5BC,oBAAoB;EACpBC;AAAI,CACiB;EACrB,IAAI,CAACL,gBAAA,EAAkB;IACrB;EACF;EAEA,IAAI;IACF;IACA,MAAMI,oBAAA,CAAqBT,EAAA,EAAIE,cAAA,IAAkBE,UAAA,EAAYM,IAAA;IAE7D,IAAI,CAACJ,WAAA,EAAa;MAChBH,oBAAA,CAAqBQ,OAAO,CAACC,mBAAmB,GAAG;IACrD;IAEA;IACAT,oBAAA,CAAqBQ,OAAO,GAAG;MAC7BC,mBAAA,EAAqBT,oBAAA,CAAqBQ,OAAO,EAAEC,mBAAA;MACnDC,QAAA,EAAU;MACVH;IACF;IACAH,gBAAA,CAAiBG,IAAA;IAEjB;IACA,IAAIJ,WAAA,IAAeE,4BAAA,EAA8B;MAC/CA,4BAAA,CAA6B;IAC/B;IAEA;IACA,IAAIP,eAAA,EAAiB;MACnBA,eAAA;IACF;EACF,EAAE,OAAOa,KAAA,EAAO;IACd;IACAC,OAAA,CAAQD,KAAK,CAAC,mCAAmCA,KAAA;EACnD;AACF","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ClientCollectionConfig, ClientConfig, CollectionConfig, Column, ColumnPreference, Field, ImportMap, ListQuery, PaginatedDocs, Payload, SanitizedCollectionConfig, ViewTypes } from 'payload';
|
|
1
|
+
import type { ClientCollectionConfig, ClientConfig, CollectionConfig, Column, ColumnPreference, Field, ImportMap, ListQuery, PaginatedDocs, Payload, PayloadRequest, SanitizedCollectionConfig, ViewTypes } from 'payload';
|
|
2
2
|
import { type I18nClient } from '@payloadcms/translations';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
export declare const renderFilters: (fields: Field[], importMap: ImportMap) => Map<string, React.ReactNode>;
|
|
5
|
-
export declare const renderTable: ({ clientCollectionConfig, clientConfig, collectionConfig, collections, columns, customCellProps, data, enableRowSelections, groupByFieldPath, groupByValue, heading, i18n, key, orderableFieldName, payload, query, renderRowTypes, tableAppearance, useAsTitle, viewType, }: {
|
|
5
|
+
export declare const renderTable: ({ clientCollectionConfig, clientConfig, collectionConfig, collections, columns, customCellProps, data, enableRowSelections, groupByFieldPath, groupByValue, heading, i18n, key, orderableFieldName, payload, query, renderRowTypes, req, tableAppearance, useAsTitle, viewType, }: {
|
|
6
6
|
clientCollectionConfig?: ClientCollectionConfig;
|
|
7
7
|
clientConfig?: ClientConfig;
|
|
8
8
|
collectionConfig?: SanitizedCollectionConfig;
|
|
@@ -21,6 +21,7 @@ export declare const renderTable: ({ clientCollectionConfig, clientConfig, colle
|
|
|
21
21
|
payload: Payload;
|
|
22
22
|
query?: ListQuery;
|
|
23
23
|
renderRowTypes?: boolean;
|
|
24
|
+
req?: PayloadRequest;
|
|
24
25
|
tableAppearance?: "condensed" | "default";
|
|
25
26
|
useAsTitle: CollectionConfig["admin"]["useAsTitle"];
|
|
26
27
|
viewType?: ViewTypes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderTable.d.ts","sourceRoot":"","sources":["../../src/utilities/renderTable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,YAAY,EAEZ,gBAAgB,EAChB,MAAM,EACN,gBAAgB,EAChB,KAAK,EACL,SAAS,EACT,SAAS,EACT,aAAa,EACb,OAAO,EACP,yBAAyB,EACzB,SAAS,EACV,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1E,OAAO,KAAK,MAAM,OAAO,CAAA;AAqBzB,eAAO,MAAM,aAAa,WAChB,KAAK,EAAE,aACJ,SAAS,KACnB,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAoB3B,CAAA;AAEH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"renderTable.d.ts","sourceRoot":"","sources":["../../src/utilities/renderTable.tsx"],"names":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S,CAAA;IACzC,UAAU,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAA;IACnD,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,KAAG;IACF,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAA;CAsMvB,CAAA"}
|
|
@@ -36,6 +36,7 @@ export const renderTable = ({
|
|
|
36
36
|
payload,
|
|
37
37
|
query,
|
|
38
38
|
renderRowTypes,
|
|
39
|
+
req,
|
|
39
40
|
tableAppearance,
|
|
40
41
|
useAsTitle,
|
|
41
42
|
viewType
|
|
@@ -78,6 +79,7 @@ export const renderTable = ({
|
|
|
78
79
|
// sortColumnProps,
|
|
79
80
|
customCellProps,
|
|
80
81
|
payload,
|
|
82
|
+
req,
|
|
81
83
|
serverFields,
|
|
82
84
|
useAsTitle,
|
|
83
85
|
viewType
|