@payloadcms/ui 3.61.0 → 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/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/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
|
@@ -10,6 +10,7 @@ export { copyDataFromLocaleHandler } from '../../utilities/copyDataFromLocale.js
|
|
|
10
10
|
export { getColumns } from '../../utilities/getColumns.js';
|
|
11
11
|
export { getFolderResultsComponentAndData } from '../../utilities/getFolderResultsComponentAndData.js';
|
|
12
12
|
export { handleLivePreview } from '../../utilities/handleLivePreview.js';
|
|
13
|
+
export { handlePreview } from '../../utilities/handlePreview.js';
|
|
13
14
|
export { renderFilters, renderTable } from '../../utilities/renderTable.js';
|
|
14
15
|
export { resolveFilterOptions } from '../../utilities/resolveFilterOptions.js';
|
|
15
16
|
export { upsertPreferences } from '../../utilities/upsertPreferences.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exports/rsc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA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uC,CAAA;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC1D,OAAO,EAAE,gCAAgC,EAAE,MAAM,qDAAqD,CAAA;AACtG,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA"}
|
|
@@ -10,6 +10,7 @@ export { copyDataFromLocaleHandler } from '../../utilities/copyDataFromLocale.js
|
|
|
10
10
|
export { getColumns } from '../../utilities/getColumns.js';
|
|
11
11
|
export { getFolderResultsComponentAndData } from '../../utilities/getFolderResultsComponentAndData.js';
|
|
12
12
|
export { handleLivePreview } from '../../utilities/handleLivePreview.js';
|
|
13
|
+
export { handlePreview } from '../../utilities/handlePreview.js';
|
|
13
14
|
export { renderFilters, renderTable } from '../../utilities/renderTable.js';
|
|
14
15
|
export { resolveFilterOptions } from '../../utilities/resolveFilterOptions.js';
|
|
15
16
|
export { upsertPreferences } from '../../utilities/upsertPreferences.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["FieldDiffContainer","FieldDiffLabel","FolderTableCell","FolderField","getHTMLDiffComponents","_internal_renderFieldHandler","File","CheckIcon","copyDataFromLocaleHandler","getColumns","getFolderResultsComponentAndData","handleLivePreview","renderFilters","renderTable","resolveFilterOptions","upsertPreferences"],"sources":["../../../src/exports/rsc/index.ts"],"sourcesContent":["export { FieldDiffContainer } from '../../elements/FieldDiffContainer/index.js'\nexport { FieldDiffLabel } from '../../elements/FieldDiffLabel/index.js'\nexport { FolderTableCell } from '../../elements/FolderView/Cell/index.server.js'\nexport { FolderField } from '../../elements/FolderView/FolderField/index.server.js'\nexport { getHTMLDiffComponents } from '../../elements/HTMLDiff/index.js'\nexport { _internal_renderFieldHandler } from '../../forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js'\nexport { File } from '../../graphics/File/index.js'\nexport { CheckIcon } from '../../icons/Check/index.js'\nexport { copyDataFromLocaleHandler } from '../../utilities/copyDataFromLocale.js'\nexport { getColumns } from '../../utilities/getColumns.js'\nexport { getFolderResultsComponentAndData } from '../../utilities/getFolderResultsComponentAndData.js'\nexport { handleLivePreview } from '../../utilities/handleLivePreview.js'\nexport { renderFilters, renderTable } from '../../utilities/renderTable.js'\nexport { resolveFilterOptions } from '../../utilities/resolveFilterOptions.js'\nexport { upsertPreferences } from '../../utilities/upsertPreferences.js'\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ;AACnC,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,WAAW,QAAQ;AAC5B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,4BAA4B,QAAQ;AAC7C,SAASC,IAAI,QAAQ;AACrB,SAASC,SAAS,QAAQ;AAC1B,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,UAAU,QAAQ;AAC3B,SAASC,gCAAgC,QAAQ;AACjD,SAASC,iBAAiB,QAAQ;AAClC,SAASC,aAAa,EAAEC,WAAW,QAAQ;AAC3C,SAASC,oBAAoB,QAAQ;AACrC,SAASC,iBAAiB,QAAQ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["FieldDiffContainer","FieldDiffLabel","FolderTableCell","FolderField","getHTMLDiffComponents","_internal_renderFieldHandler","File","CheckIcon","copyDataFromLocaleHandler","getColumns","getFolderResultsComponentAndData","handleLivePreview","handlePreview","renderFilters","renderTable","resolveFilterOptions","upsertPreferences"],"sources":["../../../src/exports/rsc/index.ts"],"sourcesContent":["export { FieldDiffContainer } from '../../elements/FieldDiffContainer/index.js'\nexport { FieldDiffLabel } from '../../elements/FieldDiffLabel/index.js'\nexport { FolderTableCell } from '../../elements/FolderView/Cell/index.server.js'\nexport { FolderField } from '../../elements/FolderView/FolderField/index.server.js'\nexport { getHTMLDiffComponents } from '../../elements/HTMLDiff/index.js'\nexport { _internal_renderFieldHandler } from '../../forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js'\nexport { File } from '../../graphics/File/index.js'\nexport { CheckIcon } from '../../icons/Check/index.js'\nexport { copyDataFromLocaleHandler } from '../../utilities/copyDataFromLocale.js'\nexport { getColumns } from '../../utilities/getColumns.js'\nexport { getFolderResultsComponentAndData } from '../../utilities/getFolderResultsComponentAndData.js'\nexport { handleLivePreview } from '../../utilities/handleLivePreview.js'\nexport { handlePreview } from '../../utilities/handlePreview.js'\nexport { renderFilters, renderTable } from '../../utilities/renderTable.js'\nexport { resolveFilterOptions } from '../../utilities/resolveFilterOptions.js'\nexport { upsertPreferences } from '../../utilities/upsertPreferences.js'\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ;AACnC,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,WAAW,QAAQ;AAC5B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,4BAA4B,QAAQ;AAC7C,SAASC,IAAI,QAAQ;AACrB,SAASC,SAAS,QAAQ;AAC1B,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,UAAU,QAAQ;AAC3B,SAASC,gCAAgC,QAAQ;AACjD,SAASC,iBAAiB,QAAQ;AAClC,SAASC,aAAa,QAAQ;AAC9B,SAASC,aAAa,EAAEC,WAAW,QAAQ;AAC3C,SAASC,oBAAoB,QAAQ;AACrC,SAASC,iBAAiB,QAAQ","ignoreList":[]}
|
|
@@ -11,6 +11,7 @@ export interface LivePreviewContextType {
|
|
|
11
11
|
isLivePreviewEnabled: boolean;
|
|
12
12
|
isLivePreviewing: boolean;
|
|
13
13
|
isPopupOpen: boolean;
|
|
14
|
+
isPreviewEnabled: boolean;
|
|
14
15
|
listeningForMessages?: boolean;
|
|
15
16
|
/**
|
|
16
17
|
* The URL that has finished loading in the iframe or popup.
|
|
@@ -24,6 +25,7 @@ export interface LivePreviewContextType {
|
|
|
24
25
|
};
|
|
25
26
|
openPopupWindow: ReturnType<typeof usePopupWindow>['openPopupWindow'];
|
|
26
27
|
popupRef?: React.RefObject<null | Window>;
|
|
28
|
+
previewURL?: string;
|
|
27
29
|
previewWindowType: 'iframe' | 'popup';
|
|
28
30
|
setAppIsReady: (appIsReady: boolean) => void;
|
|
29
31
|
setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void;
|
|
@@ -34,6 +36,7 @@ export interface LivePreviewContextType {
|
|
|
34
36
|
height: number;
|
|
35
37
|
width: number;
|
|
36
38
|
}) => void;
|
|
39
|
+
setPreviewURL: (url: string) => void;
|
|
37
40
|
setPreviewWindowType: (previewWindowType: 'iframe' | 'popup') => void;
|
|
38
41
|
setSize: Dispatch<SizeReducerAction>;
|
|
39
42
|
setToolbarPosition: (position: {
|
|
@@ -65,4 +68,12 @@ export interface LivePreviewContextType {
|
|
|
65
68
|
}
|
|
66
69
|
export declare const LivePreviewContext: React.Context<LivePreviewContextType>;
|
|
67
70
|
export declare const useLivePreviewContext: () => LivePreviewContextType;
|
|
71
|
+
/**
|
|
72
|
+
* Hook to access live preview context values. Separated to prevent breaking changes. In the future this hook can be removed in favour of just using the LivePreview one.
|
|
73
|
+
*/
|
|
74
|
+
export declare const usePreviewURL: () => {
|
|
75
|
+
isPreviewEnabled: boolean;
|
|
76
|
+
previewURL: string;
|
|
77
|
+
setPreviewURL: (url: string) => void;
|
|
78
|
+
};
|
|
68
79
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CA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K,IAAI,CAAA;IAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,eAAe,EAAE;QACf,CAAC,EAAE,MAAM,CAAA;QACT,CAAC,EAAE,MAAM,CAAA;KACV,CAAA;IACD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAA;IAC5C,GAAG,EAAE,kBAAkB,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,eAAO,MAAM,kBAAkB,uCAyC7B,CAAA;AAEF,eAAO,MAAM,qBAAqB,8BAAgC,CAAA;AAElE;;GAEG;AACH,eAAO,MAAM,aAAa;;;yBA7EH,MAAM,KAAK,IAAI;CAiFrC,CAAA"}
|
|
@@ -9,12 +9,14 @@ export const LivePreviewContext = createContext({
|
|
|
9
9
|
isLivePreviewEnabled: undefined,
|
|
10
10
|
isLivePreviewing: false,
|
|
11
11
|
isPopupOpen: false,
|
|
12
|
+
isPreviewEnabled: undefined,
|
|
12
13
|
measuredDeviceSize: {
|
|
13
14
|
height: 0,
|
|
14
15
|
width: 0
|
|
15
16
|
},
|
|
16
17
|
openPopupWindow: () => {},
|
|
17
18
|
popupRef: undefined,
|
|
19
|
+
previewURL: undefined,
|
|
18
20
|
previewWindowType: 'iframe',
|
|
19
21
|
setAppIsReady: () => {},
|
|
20
22
|
setBreakpoint: () => {},
|
|
@@ -22,6 +24,7 @@ export const LivePreviewContext = createContext({
|
|
|
22
24
|
setIsLivePreviewing: () => {},
|
|
23
25
|
setLoadedURL: () => {},
|
|
24
26
|
setMeasuredDeviceSize: () => {},
|
|
27
|
+
setPreviewURL: () => {},
|
|
25
28
|
setPreviewWindowType: () => {},
|
|
26
29
|
setSize: () => {},
|
|
27
30
|
setToolbarPosition: () => {},
|
|
@@ -41,4 +44,19 @@ export const LivePreviewContext = createContext({
|
|
|
41
44
|
zoom: 1
|
|
42
45
|
});
|
|
43
46
|
export const useLivePreviewContext = () => use(LivePreviewContext);
|
|
47
|
+
/**
|
|
48
|
+
* Hook to access live preview context values. Separated to prevent breaking changes. In the future this hook can be removed in favour of just using the LivePreview one.
|
|
49
|
+
*/
|
|
50
|
+
export const usePreviewURL = () => {
|
|
51
|
+
const {
|
|
52
|
+
isPreviewEnabled,
|
|
53
|
+
previewURL,
|
|
54
|
+
setPreviewURL
|
|
55
|
+
} = use(LivePreviewContext);
|
|
56
|
+
return {
|
|
57
|
+
isPreviewEnabled,
|
|
58
|
+
previewURL,
|
|
59
|
+
setPreviewURL
|
|
60
|
+
};
|
|
61
|
+
};
|
|
44
62
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["createContext","use","LivePreviewContext","appIsReady","breakpoint","undefined","breakpoints","iframeRef","isLivePreviewEnabled","isLivePreviewing","isPopupOpen","measuredDeviceSize","height","width","openPopupWindow","popupRef","previewWindowType","setAppIsReady","setBreakpoint","setHeight","setIsLivePreviewing","setLoadedURL","setMeasuredDeviceSize","setPreviewWindowType","setSize","setToolbarPosition","setURL","setWidth","setZoom","size","toolbarPosition","x","y","typeofLivePreviewURL","url","zoom","useLivePreviewContext"],"sources":["../../../src/providers/LivePreview/context.ts"],"sourcesContent":["'use client'\nimport type { LivePreviewConfig, LivePreviewURLType } from 'payload'\nimport type { Dispatch } from 'react'\nimport type React from 'react'\n\nimport { createContext, use } from 'react'\n\nimport type { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport type { SizeReducerAction } from './sizeReducer.js'\n\nexport interface LivePreviewContextType {\n appIsReady: boolean\n breakpoint: LivePreviewConfig['breakpoints'][number]['name']\n breakpoints: LivePreviewConfig['breakpoints']\n iframeRef: React.RefObject<HTMLIFrameElement | null>\n isLivePreviewEnabled: boolean\n isLivePreviewing: boolean\n isPopupOpen: boolean\n listeningForMessages?: boolean\n /**\n * The URL that has finished loading in the iframe or popup.\n * For example, if you set the `url`, it will begin to load into the iframe,\n * but `loadedURL` will not be set until the iframe's `onLoad` event fires.\n */\n loadedURL?: string\n measuredDeviceSize: {\n height: number\n width: number\n }\n openPopupWindow: ReturnType<typeof usePopupWindow>['openPopupWindow']\n popupRef?: React.RefObject<null | Window>\n previewWindowType: 'iframe' | 'popup'\n setAppIsReady: (appIsReady: boolean) => void\n setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void\n setHeight: (height: number) => void\n setIsLivePreviewing: (isLivePreviewing: boolean) => void\n setLoadedURL: (loadedURL: string) => void\n setMeasuredDeviceSize: (size: { height: number; width: number }) => void\n setPreviewWindowType: (previewWindowType: 'iframe' | 'popup') => void\n setSize: Dispatch<SizeReducerAction>\n setToolbarPosition: (position: { x: number; y: number }) => void\n /**\n * Sets the URL of the preview (either iframe or popup).\n * Will trigger a reload of the window.\n */\n setURL: (url: string) => void\n setWidth: (width: number) => void\n setZoom: (zoom: number) => void\n size: {\n height: number\n width: number\n }\n toolbarPosition: {\n x: number\n y: number\n }\n /**\n * The live preview url property can be either a string or a function that returns a string.\n * It is important to know which one it is, so that we can opt in/out of certain behaviors, e.g. calling the server to get the URL.\n */\n typeofLivePreviewURL?: 'function' | 'string'\n url: LivePreviewURLType\n zoom: number\n}\n\nexport const LivePreviewContext = createContext<LivePreviewContextType>({\n appIsReady: false,\n breakpoint: undefined,\n breakpoints: undefined,\n iframeRef: undefined,\n isLivePreviewEnabled: undefined,\n isLivePreviewing: false,\n isPopupOpen: false,\n measuredDeviceSize: {\n height: 0,\n width: 0,\n },\n openPopupWindow: () => {},\n popupRef: undefined,\n previewWindowType: 'iframe',\n setAppIsReady: () => {},\n setBreakpoint: () => {},\n setHeight: () => {},\n setIsLivePreviewing: () => {},\n setLoadedURL: () => {},\n setMeasuredDeviceSize: () => {},\n setPreviewWindowType: () => {},\n setSize: () => {},\n setToolbarPosition: () => {},\n setURL: () => {},\n setWidth: () => {},\n setZoom: () => {},\n size: {\n height: 0,\n width: 0,\n },\n toolbarPosition: {\n x: 0,\n y: 0,\n },\n typeofLivePreviewURL: undefined,\n url: undefined,\n zoom: 1,\n})\n\nexport const useLivePreviewContext = () => use(LivePreviewContext)\n"],"mappings":"AAAA;;AAKA,SAASA,aAAa,EAAEC,GAAG,QAAQ;
|
|
1
|
+
{"version":3,"file":"context.js","names":["createContext","use","LivePreviewContext","appIsReady","breakpoint","undefined","breakpoints","iframeRef","isLivePreviewEnabled","isLivePreviewing","isPopupOpen","isPreviewEnabled","measuredDeviceSize","height","width","openPopupWindow","popupRef","previewURL","previewWindowType","setAppIsReady","setBreakpoint","setHeight","setIsLivePreviewing","setLoadedURL","setMeasuredDeviceSize","setPreviewURL","setPreviewWindowType","setSize","setToolbarPosition","setURL","setWidth","setZoom","size","toolbarPosition","x","y","typeofLivePreviewURL","url","zoom","useLivePreviewContext","usePreviewURL"],"sources":["../../../src/providers/LivePreview/context.ts"],"sourcesContent":["'use client'\nimport type { LivePreviewConfig, LivePreviewURLType } from 'payload'\nimport type { Dispatch } from 'react'\nimport type React from 'react'\n\nimport { createContext, use } from 'react'\n\nimport type { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport type { SizeReducerAction } from './sizeReducer.js'\n\nexport interface LivePreviewContextType {\n appIsReady: boolean\n breakpoint: LivePreviewConfig['breakpoints'][number]['name']\n breakpoints: LivePreviewConfig['breakpoints']\n iframeRef: React.RefObject<HTMLIFrameElement | null>\n isLivePreviewEnabled: boolean\n isLivePreviewing: boolean\n isPopupOpen: boolean\n isPreviewEnabled: boolean\n listeningForMessages?: boolean\n /**\n * The URL that has finished loading in the iframe or popup.\n * For example, if you set the `url`, it will begin to load into the iframe,\n * but `loadedURL` will not be set until the iframe's `onLoad` event fires.\n */\n loadedURL?: string\n measuredDeviceSize: {\n height: number\n width: number\n }\n openPopupWindow: ReturnType<typeof usePopupWindow>['openPopupWindow']\n popupRef?: React.RefObject<null | Window>\n previewURL?: string\n previewWindowType: 'iframe' | 'popup'\n setAppIsReady: (appIsReady: boolean) => void\n setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void\n setHeight: (height: number) => void\n setIsLivePreviewing: (isLivePreviewing: boolean) => void\n setLoadedURL: (loadedURL: string) => void\n setMeasuredDeviceSize: (size: { height: number; width: number }) => void\n setPreviewURL: (url: string) => void\n setPreviewWindowType: (previewWindowType: 'iframe' | 'popup') => void\n setSize: Dispatch<SizeReducerAction>\n setToolbarPosition: (position: { x: number; y: number }) => void\n\n /**\n * Sets the URL of the preview (either iframe or popup).\n * Will trigger a reload of the window.\n */\n setURL: (url: string) => void\n setWidth: (width: number) => void\n setZoom: (zoom: number) => void\n size: {\n height: number\n width: number\n }\n toolbarPosition: {\n x: number\n y: number\n }\n /**\n * The live preview url property can be either a string or a function that returns a string.\n * It is important to know which one it is, so that we can opt in/out of certain behaviors, e.g. calling the server to get the URL.\n */\n typeofLivePreviewURL?: 'function' | 'string'\n url: LivePreviewURLType\n zoom: number\n}\n\nexport const LivePreviewContext = createContext<LivePreviewContextType>({\n appIsReady: false,\n breakpoint: undefined,\n breakpoints: undefined,\n iframeRef: undefined,\n isLivePreviewEnabled: undefined,\n isLivePreviewing: false,\n isPopupOpen: false,\n isPreviewEnabled: undefined,\n measuredDeviceSize: {\n height: 0,\n width: 0,\n },\n openPopupWindow: () => {},\n popupRef: undefined,\n previewURL: undefined,\n previewWindowType: 'iframe',\n setAppIsReady: () => {},\n setBreakpoint: () => {},\n setHeight: () => {},\n setIsLivePreviewing: () => {},\n setLoadedURL: () => {},\n setMeasuredDeviceSize: () => {},\n setPreviewURL: () => {},\n setPreviewWindowType: () => {},\n setSize: () => {},\n setToolbarPosition: () => {},\n setURL: () => {},\n setWidth: () => {},\n setZoom: () => {},\n size: {\n height: 0,\n width: 0,\n },\n toolbarPosition: {\n x: 0,\n y: 0,\n },\n typeofLivePreviewURL: undefined,\n url: undefined,\n zoom: 1,\n})\n\nexport const useLivePreviewContext = () => use(LivePreviewContext)\n\n/**\n * Hook to access live preview context values. Separated to prevent breaking changes. In the future this hook can be removed in favour of just using the LivePreview one.\n */\nexport const usePreviewURL = () => {\n const { isPreviewEnabled, previewURL, setPreviewURL } = use(LivePreviewContext)\n\n return { isPreviewEnabled, previewURL, setPreviewURL }\n}\n"],"mappings":"AAAA;;AAKA,SAASA,aAAa,EAAEC,GAAG,QAAQ;AAgEnC,OAAO,MAAMC,kBAAA,GAAqBF,aAAA,CAAsC;EACtEG,UAAA,EAAY;EACZC,UAAA,EAAYC,SAAA;EACZC,WAAA,EAAaD,SAAA;EACbE,SAAA,EAAWF,SAAA;EACXG,oBAAA,EAAsBH,SAAA;EACtBI,gBAAA,EAAkB;EAClBC,WAAA,EAAa;EACbC,gBAAA,EAAkBN,SAAA;EAClBO,kBAAA,EAAoB;IAClBC,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAC,eAAA,EAAiBA,CAAA,MAAO;EACxBC,QAAA,EAAUX,SAAA;EACVY,UAAA,EAAYZ,SAAA;EACZa,iBAAA,EAAmB;EACnBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,SAAA,EAAWA,CAAA,MAAO;EAClBC,mBAAA,EAAqBA,CAAA,MAAO;EAC5BC,YAAA,EAAcA,CAAA,MAAO;EACrBC,qBAAA,EAAuBA,CAAA,MAAO;EAC9BC,aAAA,EAAeA,CAAA,MAAO;EACtBC,oBAAA,EAAsBA,CAAA,MAAO;EAC7BC,OAAA,EAASA,CAAA,MAAO;EAChBC,kBAAA,EAAoBA,CAAA,MAAO;EAC3BC,MAAA,EAAQA,CAAA,MAAO;EACfC,QAAA,EAAUA,CAAA,MAAO;EACjBC,OAAA,EAASA,CAAA,MAAO;EAChBC,IAAA,EAAM;IACJnB,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAmB,eAAA,EAAiB;IACfC,CAAA,EAAG;IACHC,CAAA,EAAG;EACL;EACAC,oBAAA,EAAsB/B,SAAA;EACtBgC,GAAA,EAAKhC,SAAA;EACLiC,IAAA,EAAM;AACR;AAEA,OAAO,MAAMC,qBAAA,GAAwBA,CAAA,KAAMtC,GAAA,CAAIC,kBAAA;AAE/C;;;AAGA,OAAO,MAAMsC,aAAA,GAAgBA,CAAA;EAC3B,MAAM;IAAE7B,gBAAgB;IAAEM,UAAU;IAAEQ;EAAa,CAAE,GAAGxB,GAAA,CAAIC,kBAAA;EAE5D,OAAO;IAAES,gBAAA;IAAkBM,UAAA;IAAYQ;EAAc;AACvD","ignoreList":[]}
|
|
@@ -11,6 +11,14 @@ export type LivePreviewProviderProps = {
|
|
|
11
11
|
};
|
|
12
12
|
isLivePreviewEnabled?: boolean;
|
|
13
13
|
isLivePreviewing: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* This specifically relates to `admin.preview` function in the config instead of live preview.
|
|
16
|
+
*/
|
|
17
|
+
isPreviewEnabled?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* This specifically relates to `admin.preview` function in the config instead of live preview.
|
|
20
|
+
*/
|
|
21
|
+
previewURL?: string;
|
|
14
22
|
} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>;
|
|
15
23
|
export declare const LivePreviewProvider: React.FC<LivePreviewProviderProps>;
|
|
16
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,iBAAiB,EAAsB,MAAM,SAAS,CAAA;AAG3F,OAAO,KAA4D,MAAM,OAAO,CAAA;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAU1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAC9C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,UAAU,CAAC,EAAE;QACX,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,gBAAgB,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,iBAAiB,EAAsB,MAAM,SAAS,CAAA;AAG3F,OAAO,KAA4D,MAAM,OAAO,CAAA;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAU1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAC9C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,UAAU,CAAC,EAAE;QACX,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,gBAAgB,EAAE,OAAO,CAAA;IACzB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GAAG,IAAI,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,KAAK,CAAC,CAAA;AAEhE,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAiQlE,CAAA"}
|
|
@@ -15,6 +15,8 @@ export const LivePreviewProvider = ({
|
|
|
15
15
|
children,
|
|
16
16
|
isLivePreviewEnabled,
|
|
17
17
|
isLivePreviewing: incomingIsLivePreviewing,
|
|
18
|
+
isPreviewEnabled,
|
|
19
|
+
previewURL: previewURLFromProps,
|
|
18
20
|
typeofLivePreviewURL,
|
|
19
21
|
url: urlFromProps
|
|
20
22
|
}) => {
|
|
@@ -27,6 +29,7 @@ export const LivePreviewProvider = ({
|
|
|
27
29
|
width: '100%'
|
|
28
30
|
}], [incomingBreakpoints]);
|
|
29
31
|
const [url, setURL] = useState('');
|
|
32
|
+
const [previewURL, setPreviewURL] = useState(previewURLFromProps);
|
|
30
33
|
const {
|
|
31
34
|
isPopupOpen,
|
|
32
35
|
openPopupWindow,
|
|
@@ -182,11 +185,13 @@ export const LivePreviewProvider = ({
|
|
|
182
185
|
isLivePreviewEnabled,
|
|
183
186
|
isLivePreviewing,
|
|
184
187
|
isPopupOpen,
|
|
188
|
+
isPreviewEnabled,
|
|
185
189
|
listeningForMessages,
|
|
186
190
|
loadedURL,
|
|
187
191
|
measuredDeviceSize,
|
|
188
192
|
openPopupWindow,
|
|
189
193
|
popupRef,
|
|
194
|
+
previewURL,
|
|
190
195
|
previewWindowType,
|
|
191
196
|
setAppIsReady,
|
|
192
197
|
setBreakpoint,
|
|
@@ -194,6 +199,7 @@ export const LivePreviewProvider = ({
|
|
|
194
199
|
setIsLivePreviewing,
|
|
195
200
|
setLoadedURL,
|
|
196
201
|
setMeasuredDeviceSize,
|
|
202
|
+
setPreviewURL,
|
|
197
203
|
setPreviewWindowType: handleWindowChange,
|
|
198
204
|
setSize,
|
|
199
205
|
setToolbarPosition: setPosition,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["DndContext","React","useCallback","useEffect","useMemo","useRef","useState","usePopupWindow","useDocumentInfo","usePreferences","formatAbsoluteURL","customCollisionDetection","LivePreviewContext","sizeReducer","LivePreviewProvider","breakpoints","incomingBreakpoints","children","isLivePreviewEnabled","isLivePreviewing","incomingIsLivePreviewing","typeofLivePreviewURL","url","urlFromProps","previewWindowType","setPreviewWindowType","setIsLivePreviewing","name","height","label","width","setURL","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","listeningForMessages","setListeningForMessages","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","loadedURL","setLoadedURL","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","measuredDeviceSize","setMeasuredDeviceSize","breakpoint","setBreakpoint","setLivePreviewURL","_incomingURL","incomingURL","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","handleMessage","event","startsWith","origin","data","ready","window","addEventListener","removeEventListener","handleWindowChange","newPreviewWindowType","current","editViewType","_jsx","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"sources":["../../../src/providers/LivePreview/index.tsx"],"sourcesContent":["'use client'\nimport type { CollectionPreferences, LivePreviewConfig, LivePreviewURLType } from 'payload'\n\nimport { DndContext } from '@dnd-kit/core'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { LivePreviewContextType } from './context.js'\n\nimport { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { formatAbsoluteURL } from '../../utilities/formatAbsoluteURL.js'\nimport { customCollisionDetection } from './collisionDetection.js'\nimport { LivePreviewContext } from './context.js'\nimport { sizeReducer } from './sizeReducer.js'\n\nexport type LivePreviewProviderProps = {\n appIsReady?: boolean\n breakpoints?: LivePreviewConfig['breakpoints']\n children: React.ReactNode\n deviceSize?: {\n height: number\n width: number\n }\n isLivePreviewEnabled?: boolean\n isLivePreviewing: boolean\n} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\n typeofLivePreviewURL,\n url: urlFromProps,\n}) => {\n const [previewWindowType, setPreviewWindowType] = useState<'iframe' | 'popup'>('iframe')\n const [isLivePreviewing, setIsLivePreviewing] = useState(incomingIsLivePreviewing)\n\n const breakpoints: LivePreviewConfig['breakpoints'] = useMemo(\n () => [\n ...(incomingBreakpoints || []),\n {\n name: 'responsive',\n height: '100%',\n label: 'Responsive',\n width: '100%',\n },\n ],\n [incomingBreakpoints],\n )\n\n const [url, setURL] = useState<string>('')\n\n const { isPopupOpen, openPopupWindow, popupRef } = usePopupWindow({\n eventType: 'payload-live-preview',\n url,\n })\n\n const [appIsReady, setAppIsReady] = useState(false)\n const [listeningForMessages, setListeningForMessages] = useState(false)\n\n const { collectionSlug, globalSlug } = useDocumentInfo()\n\n const isFirstRender = useRef(true)\n\n const { setPreference } = usePreferences()\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null)\n\n const [loadedURL, setLoadedURL] = useState<string>()\n\n const [zoom, setZoom] = useState(1)\n\n const [position, setPosition] = useState({ x: 0, y: 0 })\n\n const [size, setSize] = React.useReducer(sizeReducer, { height: 0, width: 0 })\n\n const [measuredDeviceSize, setMeasuredDeviceSize] = useState({\n height: 0,\n width: 0,\n })\n\n const [breakpoint, setBreakpoint] =\n React.useState<LivePreviewConfig['breakpoints'][0]['name']>('responsive')\n\n /**\n * A \"middleware\" callback fn that does some additional work before `setURL`.\n * This is what we provide through context, bc it:\n * - ensures the URL is absolute\n * - resets `appIsReady` to `false` while the new URL is loading\n */\n const setLivePreviewURL = useCallback<LivePreviewContextType['setURL']>(\n (_incomingURL) => {\n let incomingURL: LivePreviewURLType\n\n if (typeof _incomingURL === 'string') {\n incomingURL = formatAbsoluteURL(_incomingURL)\n }\n\n if (!incomingURL) {\n setIsLivePreviewing(false)\n }\n\n if (incomingURL !== url) {\n setAppIsReady(false)\n setURL(incomingURL)\n }\n },\n [url],\n )\n\n /**\n * `url` needs to be relative to the window, which cannot be done on initial render.\n */\n useEffect(() => {\n if (typeof urlFromProps === 'string') {\n setURL(formatAbsoluteURL(urlFromProps))\n }\n }, [urlFromProps])\n\n // The toolbar needs to freely drag and drop around the page\n const handleDragEnd = (ev) => {\n // only update position if the toolbar is completely within the preview area\n // otherwise reset it back to the previous position\n // TODO: reset to the nearest edge of the preview area\n if (ev.over && ev.over.id === 'live-preview-area') {\n const newPos = {\n x: position.x + ev.delta.x,\n y: position.y + ev.delta.y,\n }\n\n setPosition(newPos)\n } else {\n // reset\n }\n }\n\n const setWidth = useCallback(\n (width) => {\n setSize({ type: 'width', value: width })\n },\n [setSize],\n )\n\n const setHeight = useCallback(\n (height) => {\n setSize({ type: 'height', value: height })\n },\n [setSize],\n )\n\n // explicitly set new width and height when as new breakpoints are selected\n // exclude `custom` breakpoint as it is handled by the `setWidth` and `setHeight` directly\n useEffect(() => {\n const foundBreakpoint = breakpoints?.find((bp) => bp.name === breakpoint)\n\n if (\n foundBreakpoint &&\n breakpoint !== 'responsive' &&\n breakpoint !== 'custom' &&\n typeof foundBreakpoint?.width === 'number' &&\n typeof foundBreakpoint?.height === 'number'\n ) {\n setSize({\n type: 'reset',\n value: {\n height: foundBreakpoint.height,\n width: foundBreakpoint.width,\n },\n })\n }\n }, [breakpoint, breakpoints])\n\n /**\n * Receive the `ready` message from the popup window\n * This indicates that the app is ready to receive `window.postMessage` events\n * This is also the only cross-origin way of detecting when a popup window has loaded\n * Unlike iframe elements which have an `onLoad` handler, there is no way to access `window.open` on popups\n */\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n if (\n url?.startsWith(event.origin) &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-live-preview'\n ) {\n if (event.data.ready) {\n setAppIsReady(true)\n }\n }\n }\n\n window.addEventListener('message', handleMessage)\n\n setListeningForMessages(true)\n\n return () => {\n window.removeEventListener('message', handleMessage)\n }\n }, [url, listeningForMessages])\n\n const handleWindowChange = useCallback(\n (type: 'iframe' | 'popup') => {\n setAppIsReady(false)\n setPreviewWindowType(type)\n if (type === 'popup') {\n openPopupWindow()\n }\n },\n [openPopupWindow],\n )\n\n // when the user closes the popup window, switch back to the iframe\n // the `usePopupWindow` reports the `isPopupOpen` state for us to use here\n useEffect(() => {\n const newPreviewWindowType = isPopupOpen ? 'popup' : 'iframe'\n\n if (newPreviewWindowType !== previewWindowType) {\n handleWindowChange('iframe')\n }\n }, [previewWindowType, isPopupOpen, handleWindowChange])\n\n useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = false\n return\n }\n\n void setPreference<CollectionPreferences>(\n collectionSlug ? `collection-${collectionSlug}` : `global-${globalSlug}`,\n {\n editViewType: isLivePreviewing ? 'live-preview' : 'default',\n },\n true,\n )\n }, [isLivePreviewing, setPreference, collectionSlug, globalSlug])\n\n return (\n <LivePreviewContext\n value={{\n appIsReady,\n breakpoint,\n breakpoints,\n iframeRef,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n listeningForMessages,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\n setPreviewWindowType: handleWindowChange,\n setSize,\n setToolbarPosition: setPosition,\n setURL: setLivePreviewURL,\n setWidth,\n setZoom,\n size,\n toolbarPosition: position,\n typeofLivePreviewURL,\n url,\n zoom,\n }}\n >\n <DndContext collisionDetection={customCollisionDetection} onDragEnd={handleDragEnd}>\n {children}\n </DndContext>\n </LivePreviewContext>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,UAAU,QAAQ;AAC3B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAIzE,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,wBAAwB,QAAQ;AACzC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,WAAW,QAAQ;AAc5B,OAAO,MAAMC,mBAAA,GAA0DA,CAAC;EACtEC,WA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AAA,EAAiB1C,QAAA;MACjB5B,oBAAA;MACAC,GAAA;MACAyB;IACF;cAEA,aAAA0C,IAAA,CAACzF,UAAA;MAAW4F,kBAAA,EAAoBjF,wBAAA;MAA0BkF,SAAA,EAAW9B,aAAA;gBAClE9C;;;AAIT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["DndContext","React","useCallback","useEffect","useMemo","useRef","useState","usePopupWindow","useDocumentInfo","usePreferences","formatAbsoluteURL","customCollisionDetection","LivePreviewContext","sizeReducer","LivePreviewProvider","breakpoints","incomingBreakpoints","children","isLivePreviewEnabled","isLivePreviewing","incomingIsLivePreviewing","isPreviewEnabled","previewURL","previewURLFromProps","typeofLivePreviewURL","url","urlFromProps","previewWindowType","setPreviewWindowType","setIsLivePreviewing","name","height","label","width","setURL","setPreviewURL","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","listeningForMessages","setListeningForMessages","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","loadedURL","setLoadedURL","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","measuredDeviceSize","setMeasuredDeviceSize","breakpoint","setBreakpoint","setLivePreviewURL","_incomingURL","incomingURL","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","handleMessage","event","startsWith","origin","data","ready","window","addEventListener","removeEventListener","handleWindowChange","newPreviewWindowType","current","editViewType","_jsx","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"sources":["../../../src/providers/LivePreview/index.tsx"],"sourcesContent":["'use client'\nimport type { CollectionPreferences, LivePreviewConfig, LivePreviewURLType } from 'payload'\n\nimport { DndContext } from '@dnd-kit/core'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { LivePreviewContextType } from './context.js'\n\nimport { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { formatAbsoluteURL } from '../../utilities/formatAbsoluteURL.js'\nimport { customCollisionDetection } from './collisionDetection.js'\nimport { LivePreviewContext } from './context.js'\nimport { sizeReducer } from './sizeReducer.js'\n\nexport type LivePreviewProviderProps = {\n appIsReady?: boolean\n breakpoints?: LivePreviewConfig['breakpoints']\n children: React.ReactNode\n deviceSize?: {\n height: number\n width: number\n }\n isLivePreviewEnabled?: boolean\n isLivePreviewing: boolean\n /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n isPreviewEnabled?: boolean\n /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n previewURL?: string\n} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\n isPreviewEnabled,\n previewURL: previewURLFromProps,\n typeofLivePreviewURL,\n url: urlFromProps,\n}) => {\n const [previewWindowType, setPreviewWindowType] = useState<'iframe' | 'popup'>('iframe')\n const [isLivePreviewing, setIsLivePreviewing] = useState(incomingIsLivePreviewing)\n\n const breakpoints: LivePreviewConfig['breakpoints'] = useMemo(\n () => [\n ...(incomingBreakpoints || []),\n {\n name: 'responsive',\n height: '100%',\n label: 'Responsive',\n width: '100%',\n },\n ],\n [incomingBreakpoints],\n )\n\n const [url, setURL] = useState<string>('')\n const [previewURL, setPreviewURL] = useState<string>(previewURLFromProps)\n\n const { isPopupOpen, openPopupWindow, popupRef } = usePopupWindow({\n eventType: 'payload-live-preview',\n url,\n })\n\n const [appIsReady, setAppIsReady] = useState(false)\n const [listeningForMessages, setListeningForMessages] = useState(false)\n\n const { collectionSlug, globalSlug } = useDocumentInfo()\n\n const isFirstRender = useRef(true)\n\n const { setPreference } = usePreferences()\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null)\n\n const [loadedURL, setLoadedURL] = useState<string>()\n\n const [zoom, setZoom] = useState(1)\n\n const [position, setPosition] = useState({ x: 0, y: 0 })\n\n const [size, setSize] = React.useReducer(sizeReducer, { height: 0, width: 0 })\n\n const [measuredDeviceSize, setMeasuredDeviceSize] = useState({\n height: 0,\n width: 0,\n })\n\n const [breakpoint, setBreakpoint] =\n React.useState<LivePreviewConfig['breakpoints'][0]['name']>('responsive')\n\n /**\n * A \"middleware\" callback fn that does some additional work before `setURL`.\n * This is what we provide through context, bc it:\n * - ensures the URL is absolute\n * - resets `appIsReady` to `false` while the new URL is loading\n */\n const setLivePreviewURL = useCallback<LivePreviewContextType['setURL']>(\n (_incomingURL) => {\n let incomingURL: LivePreviewURLType\n\n if (typeof _incomingURL === 'string') {\n incomingURL = formatAbsoluteURL(_incomingURL)\n }\n\n if (!incomingURL) {\n setIsLivePreviewing(false)\n }\n\n if (incomingURL !== url) {\n setAppIsReady(false)\n setURL(incomingURL)\n }\n },\n [url],\n )\n\n /**\n * `url` needs to be relative to the window, which cannot be done on initial render.\n */\n useEffect(() => {\n if (typeof urlFromProps === 'string') {\n setURL(formatAbsoluteURL(urlFromProps))\n }\n }, [urlFromProps])\n\n // The toolbar needs to freely drag and drop around the page\n const handleDragEnd = (ev) => {\n // only update position if the toolbar is completely within the preview area\n // otherwise reset it back to the previous position\n // TODO: reset to the nearest edge of the preview area\n if (ev.over && ev.over.id === 'live-preview-area') {\n const newPos = {\n x: position.x + ev.delta.x,\n y: position.y + ev.delta.y,\n }\n\n setPosition(newPos)\n } else {\n // reset\n }\n }\n\n const setWidth = useCallback(\n (width) => {\n setSize({ type: 'width', value: width })\n },\n [setSize],\n )\n\n const setHeight = useCallback(\n (height) => {\n setSize({ type: 'height', value: height })\n },\n [setSize],\n )\n\n // explicitly set new width and height when as new breakpoints are selected\n // exclude `custom` breakpoint as it is handled by the `setWidth` and `setHeight` directly\n useEffect(() => {\n const foundBreakpoint = breakpoints?.find((bp) => bp.name === breakpoint)\n\n if (\n foundBreakpoint &&\n breakpoint !== 'responsive' &&\n breakpoint !== 'custom' &&\n typeof foundBreakpoint?.width === 'number' &&\n typeof foundBreakpoint?.height === 'number'\n ) {\n setSize({\n type: 'reset',\n value: {\n height: foundBreakpoint.height,\n width: foundBreakpoint.width,\n },\n })\n }\n }, [breakpoint, breakpoints])\n\n /**\n * Receive the `ready` message from the popup window\n * This indicates that the app is ready to receive `window.postMessage` events\n * This is also the only cross-origin way of detecting when a popup window has loaded\n * Unlike iframe elements which have an `onLoad` handler, there is no way to access `window.open` on popups\n */\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n if (\n url?.startsWith(event.origin) &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-live-preview'\n ) {\n if (event.data.ready) {\n setAppIsReady(true)\n }\n }\n }\n\n window.addEventListener('message', handleMessage)\n\n setListeningForMessages(true)\n\n return () => {\n window.removeEventListener('message', handleMessage)\n }\n }, [url, listeningForMessages])\n\n const handleWindowChange = useCallback(\n (type: 'iframe' | 'popup') => {\n setAppIsReady(false)\n setPreviewWindowType(type)\n if (type === 'popup') {\n openPopupWindow()\n }\n },\n [openPopupWindow],\n )\n\n // when the user closes the popup window, switch back to the iframe\n // the `usePopupWindow` reports the `isPopupOpen` state for us to use here\n useEffect(() => {\n const newPreviewWindowType = isPopupOpen ? 'popup' : 'iframe'\n\n if (newPreviewWindowType !== previewWindowType) {\n handleWindowChange('iframe')\n }\n }, [previewWindowType, isPopupOpen, handleWindowChange])\n\n useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = false\n return\n }\n\n void setPreference<CollectionPreferences>(\n collectionSlug ? `collection-${collectionSlug}` : `global-${globalSlug}`,\n {\n editViewType: isLivePreviewing ? 'live-preview' : 'default',\n },\n true,\n )\n }, [isLivePreviewing, setPreference, collectionSlug, globalSlug])\n\n return (\n <LivePreviewContext\n value={{\n appIsReady,\n breakpoint,\n breakpoints,\n iframeRef,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n isPreviewEnabled,\n listeningForMessages,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewURL,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\n setPreviewURL,\n setPreviewWindowType: handleWindowChange,\n setSize,\n setToolbarPosition: setPosition,\n setURL: setLivePreviewURL,\n setWidth,\n setZoom,\n size,\n toolbarPosition: position,\n typeofLivePreviewURL,\n url,\n zoom,\n }}\n >\n <DndContext collisionDetection={customCollisionDetection} onDragEnd={handleDragEnd}>\n {children}\n </DndContext>\n </LivePreviewContext>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,UAAU,QAAQ;AAC3B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAIzE,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,wBAAwB,QAAQ;AACzC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,WAAW,QAAQ;AAsB5B,OAAO,MAAMC,mBAAA,GAA0DA,CAAC;EACtEC,WAAA,EAAaC,mBAAmB;EAChCC,QAAQ;EACRC,oBAAoB;EACpBC,gBAAA,EAAkBC,wBAAwB;EAC1CC,gBAAgB;EAChBC,UAAA,EAAYC,mBAAmB;EAC/BC,oBAAoB;EACpBC,GAAA,EAAKC;AAAY,CAClB;EACC,MAAM,CAACC,iBAAA,EAAmBC,oBAAA,CAAqB,GAAGtB,QAAA,CAA6B;EAC/E,MAAM,CAACa,gBAAA,EAAkBU,mBAAA,CAAoB,GAAGvB,QAAA,CAASc,wBAAA;EAEzD,MAAML,WAAA,GAAgDX,OAAA,CACpD,MAAM,C,IACAY,mBAAA,IAAuB,EAAE,GAC7B;IACEc,IAAA,EAAM;IACNC,MAAA,EAAQ;IACRC,KAAA,EAAO;IACPC,KAAA,EAAO;EACT,EACD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,kBAAA,CAAmB;IACrB;EACF,GAAG,CAAC9D,iBAAA,EAAmBS,WAAA,EAAaqD,kBAAA,CAAmB;EAEvDtF,SAAA,CAAU;IACR,IAAI2C,aAAA,CAAc6C,OAAO,EAAE;MACzB7C,aAAA,CAAc6C,OAAO,GAAG;MACxB;IACF;IAEA,KAAK5C,aAAA,CACHH,cAAA,GAAiB,cAAcA,cAAA,EAAgB,GAAG,UAAUC,UAAA,EAAY,EACxE;MACE+C,YAAA,EAAczE,gBAAA,GAAmB,iBAAiB;IACpD,GACA;EAEJ,GAAG,CAACA,gBAAA,EAAkB4B,aAAA,EAAeH,cAAA,EAAgBC,UAAA,CAAW;EAEhE,oBACEgD,IAAA,CAACjF,kBAAA;IACC+D,KAAA,EAAO;MACLnC,UAAA;MACAsB,UAAA;MACA/C,WAAA;MACAiC,SAAA;MACA9B,oBAAA;MACAC,gBAAA;MACAiB,WAAA;MACAf,gBAAA;MACAqB,oBAAA;MACAO,SAAA;MACAW,kBAAA;MACAvB,eAAA;MACAC,QAAA;MACAhB,UAAA;MACAK,iBAAA;MACAc,aAAA;MACAsB,aAAA;MACAa,SAAA;MACA/C,mBAAA;MACAqB,YAAA;MACAW,qBAAA;MACA1B,aAAA;MACAP,oBAAA,EAAsB6D,kBAAA;MACtB/B,OAAA;MACAoC,kBAAA,EAAoBxC,WAAA;MACpBpB,MAAA,EAAQ8B,iBAAA;MACRS,QAAA;MACArB,OAAA;MACAK,IAAA;MACAsC,eAAA,EAAiB1C,QAAA;MACjB7B,oBAAA;MACAC,GAAA;MACA0B;IACF;cAEA,aAAA0C,IAAA,CAAC7F,UAAA;MAAWgG,kBAAA,EAAoBrF,wBAAA;MAA0BsF,SAAA,EAAW9B,aAAA;gBAClElD;;;AAIT","ignoreList":[]}
|
|
@@ -10,11 +10,13 @@ type BuildFormStateSuccessResult = {
|
|
|
10
10
|
indexPath?: string;
|
|
11
11
|
livePreviewURL?: string;
|
|
12
12
|
lockedState?: LockedState;
|
|
13
|
+
previewURL?: string;
|
|
13
14
|
state: FormState;
|
|
14
15
|
};
|
|
15
16
|
type BuildFormStateErrorResult = {
|
|
16
17
|
livePreviewURL?: never;
|
|
17
18
|
lockedState?: never;
|
|
19
|
+
previewURL?: never;
|
|
18
20
|
state?: never;
|
|
19
21
|
} & ({
|
|
20
22
|
message: string;
|
|
@@ -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,IAAI;IACF,MAAMZ,cAAA,CAAe;MAAEa;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,OAAOrB,YAAA,CAAae,GAAA;EACtB;AACF;AAEA,OAAO,MAAMD,cAAA,GAAiB,MAC5BH,IAAA;EAEA,MAAM;IACJW,EAAA,EAAIC,U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A+B,aAAA,EAAehE,WAAA;IACfQ,GAAA;IACA8B,UAAA;IACAC,MAAA;IACAI,UAAA;IACAF;EACF;EAEA;EACA,IAAIrB,cAAA,IAAkBM,SAAA,EAAW;IAC/B,IAAId,OAAA,CAAQqD,WAAW,CAAC7C,cAAA,CAAe,EAAEe,MAAA,EAAQ+B,MAAA,IAAUxC,SAAA,CAAUyC,IAAI,EAAE;MACzET,eAAA,CAAgBS,IAAI,GAAGzC,SAAA,CAAUyC,IAAI;IACvC;EACF;EAEA,IAAIC,iBAAA;EAEJ,IAAI/B,gBAAA,EAAkB;IACpB+B,iBAAA,GAAoB,MAAMhE,sBAAA,CAAuB;MAC/Cc,EAAA;MACAE,cAAA;MACAO,UAAA;MACAnB,GAAA;MACAkC;IACF;EACF;EAEA,MAAMjC,GAAA,GAAmC;IACvC4D,WAAA,EAAaD,iBAAA;IACbE,KAAA,EAAOZ;EACT;EAEA,IAAItB,oBAAA,EAAsB;IACxB,MAAM;MAAEmC;IAAc,CAAE,GAAG,MAAMlE,iBAAA,CAAkB;MACjDe,cAAA;MACAe,MAAA;MACAd,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 `$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MAAA,IAAUzC,SAAA,CAAU0C,IAAI,EAAE;MACzET,eAAA,CAAgBS,IAAI,GAAG1C,SAAA,CAAU0C,IAAI;IACvC;EACF;EAEA,IAAIC,iBAAA;EAEJ,IAAIhC,gBAAA,EAAkB;IACpBgC,iBAAA,GAAoB,MAAMlE,sBAAA,CAAuB;MAC/Ce,EAAA;MACAE,cAAA;MACAO,UAAA;MACAnB,GAAA;MACAmC;IACF;EACF;EAEA,MAAMlC,GAAA,GAAmC;IACvC6D,WAAA,EAAaD,iBAAA;IACbE,KAAA,EAAOZ;EACT;EAEA,IAAIvB,oBAAA,EAAsB;IACxB,MAAM;MAAEoC;IAAc,CAAE,GAAG,MAAMpE,iBAAA,CAAkB;MACjDgB,cAAA;MACAe,MAAA;MACAd,IAAA;MACAM,UAAA;MACAnB;IACF;IAEA;IACA;IACA,IAAIgE,cAAA,EAAgB;MAClB/D,GAAA,CAAI+D,cAAc,GAAGA,cAAA;IACvB;EACF;EAEA,IAAIlC,gBAAA,EAAkB;IACpB,MAAM;MAAEmC;IAAU,CAAE,GAAG,MAAMpE,aAAA,CAAc;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 ren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ACrB,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,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,OAAO,KAAK,gBAAgB;MAClC,OAAO;IACT;IAEA,OAAOnB,YAAA,CAAac,GAAA;EACtB;AACF;AAEA,MAAMD,eAAA,GAAkB,MACtBH,IAAA;EAEA,MAAM;IACJU,cAAc;IACdC,OAAA,EAASC,eAAe;IACxBC,IAAA,EAAMC,YAAY;IAClBC,mBAAmB;IACnBC,kBAAkB;IAClBC,MAAM;IACNC,KAAK;IACLC,cAA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ImB,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":[]}
|
|
@@ -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"}
|