@payloadcms/next 3.0.0-beta.35 → 3.0.0-beta.37
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/cjs/withPayload.cjs +23 -0
- package/dist/cjs/withPayload.cjs.map +1 -1
- package/dist/elements/LeaveWithoutSaving/index.js +35 -15
- package/dist/elements/LeaveWithoutSaving/index.js.map +1 -1
- package/dist/layouts/Root/index.d.ts.map +1 -1
- package/dist/layouts/Root/index.js +31 -15
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/routes/rest/auth/access.d.ts.map +1 -1
- package/dist/routes/rest/auth/access.js +17 -7
- package/dist/routes/rest/auth/access.js.map +1 -1
- package/dist/routes/rest/og/image.js +64 -50
- package/dist/routes/rest/og/image.js.map +1 -1
- package/dist/routes/rest/og/index.js +2 -1
- package/dist/routes/rest/og/index.js.map +1 -1
- package/dist/utilities/getPayloadHMR.d.ts.map +1 -1
- package/dist/utilities/getPayloadHMR.js +5 -3
- package/dist/utilities/getPayloadHMR.js.map +1 -1
- package/dist/utilities/getRequestLanguage.d.ts.map +1 -1
- package/dist/utilities/getRequestLanguage.js +1 -1
- package/dist/utilities/getRequestLanguage.js.map +1 -1
- package/dist/utilities/getRequestTheme.d.ts +11 -0
- package/dist/utilities/getRequestTheme.d.ts.map +1 -0
- package/dist/utilities/getRequestTheme.js +19 -0
- package/dist/utilities/getRequestTheme.js.map +1 -0
- package/dist/utilities/initPage/index.d.ts.map +1 -1
- package/dist/utilities/initPage/index.js +1 -0
- package/dist/utilities/initPage/index.js.map +1 -1
- package/dist/views/API/RenderJSON/index.js +99 -70
- package/dist/views/API/RenderJSON/index.js.map +1 -1
- package/dist/views/API/index.client.js +128 -91
- package/dist/views/API/index.client.js.map +1 -1
- package/dist/views/API/index.js +2 -1
- package/dist/views/API/index.js.map +1 -1
- package/dist/views/Account/Settings/index.js +27 -15
- package/dist/views/Account/Settings/index.js.map +1 -1
- package/dist/views/Account/ToggleTheme/index.js +2 -1
- package/dist/views/Account/ToggleTheme/index.js.map +1 -1
- package/dist/views/Account/index.d.ts.map +1 -1
- package/dist/views/Account/index.js +54 -40
- package/dist/views/Account/index.js.map +1 -1
- package/dist/views/CreateFirstUser/index.client.js +29 -19
- package/dist/views/CreateFirstUser/index.client.js.map +1 -1
- package/dist/views/CreateFirstUser/index.js +16 -6
- package/dist/views/CreateFirstUser/index.js.map +1 -1
- package/dist/views/Dashboard/Default/index.client.js +67 -56
- package/dist/views/Dashboard/Default/index.client.js.map +1 -1
- package/dist/views/Dashboard/Default/index.js +28 -19
- package/dist/views/Dashboard/Default/index.js.map +1 -1
- package/dist/views/Dashboard/index.js +23 -17
- package/dist/views/Dashboard/index.js.map +1 -1
- package/dist/views/Document/getDocumentData.d.ts +10 -0
- package/dist/views/Document/getDocumentData.d.ts.map +1 -0
- package/dist/views/Document/getDocumentData.js +24 -0
- package/dist/views/Document/getDocumentData.js.map +1 -0
- package/dist/views/Document/getDocumentPermissions.d.ts +14 -0
- package/dist/views/Document/getDocumentPermissions.d.ts.map +1 -0
- package/dist/views/Document/getDocumentPermissions.js +83 -0
- package/dist/views/Document/getDocumentPermissions.js.map +1 -0
- package/dist/views/Document/index.d.ts.map +1 -1
- package/dist/views/Document/index.js +63 -64
- package/dist/views/Document/index.js.map +1 -1
- package/dist/views/Edit/Default/Auth/APIKey.js +41 -25
- package/dist/views/Edit/Default/Auth/APIKey.js.map +1 -1
- package/dist/views/Edit/Default/Auth/index.js +78 -50
- package/dist/views/Edit/Default/Auth/index.js.map +1 -1
- package/dist/views/Edit/Default/index.d.ts.map +1 -1
- package/dist/views/Edit/Default/index.js +84 -65
- package/dist/views/Edit/Default/index.js.map +1 -1
- package/dist/views/Edit/index.client.js +10 -4
- package/dist/views/Edit/index.client.js.map +1 -1
- package/dist/views/Edit/index.js +2 -1
- package/dist/views/Edit/index.js.map +1 -1
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js +42 -20
- package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -1
- package/dist/views/ForgotPassword/index.js +37 -17
- package/dist/views/ForgotPassword/index.js.map +1 -1
- package/dist/views/List/Default/index.js +151 -81
- package/dist/views/List/Default/index.js.map +1 -1
- package/dist/views/List/index.js +52 -43
- package/dist/views/List/index.js.map +1 -1
- package/dist/views/LivePreview/Context/context.d.ts +1 -1
- package/dist/views/LivePreview/Context/context.d.ts.map +1 -1
- package/dist/views/LivePreview/Context/context.js.map +1 -1
- package/dist/views/LivePreview/Context/index.js +9 -6
- package/dist/views/LivePreview/Context/index.js.map +1 -1
- package/dist/views/LivePreview/Device/index.js +5 -3
- package/dist/views/LivePreview/Device/index.js.map +1 -1
- package/dist/views/LivePreview/DeviceContainer/index.js +5 -3
- package/dist/views/LivePreview/DeviceContainer/index.js.map +1 -1
- package/dist/views/LivePreview/IFrame/index.js +2 -1
- package/dist/views/LivePreview/IFrame/index.js.map +1 -1
- package/dist/views/LivePreview/Preview/index.js +25 -14
- package/dist/views/LivePreview/Preview/index.js.map +1 -1
- package/dist/views/LivePreview/Toolbar/Controls/index.js +105 -57
- package/dist/views/LivePreview/Toolbar/Controls/index.js.map +1 -1
- package/dist/views/LivePreview/Toolbar/SizeInput/index.js +2 -1
- package/dist/views/LivePreview/Toolbar/SizeInput/index.js.map +1 -1
- package/dist/views/LivePreview/Toolbar/index.js +29 -14
- package/dist/views/LivePreview/Toolbar/index.js.map +1 -1
- package/dist/views/LivePreview/ToolbarArea/index.js +5 -3
- package/dist/views/LivePreview/ToolbarArea/index.js.map +1 -1
- package/dist/views/LivePreview/index.client.d.ts.map +1 -1
- package/dist/views/LivePreview/index.client.js +103 -76
- package/dist/views/LivePreview/index.client.js.map +1 -1
- package/dist/views/LivePreview/index.js +2 -1
- package/dist/views/LivePreview/index.js.map +1 -1
- package/dist/views/Login/LoginForm/index.js +62 -48
- package/dist/views/Login/LoginForm/index.js.map +1 -1
- package/dist/views/Login/index.js +26 -19
- package/dist/views/Login/index.js.map +1 -1
- package/dist/views/Logout/LogoutClient.js +21 -7
- package/dist/views/Logout/LogoutClient.js.map +1 -1
- package/dist/views/Logout/index.js +13 -10
- package/dist/views/Logout/index.js.map +1 -1
- package/dist/views/NotFound/index.client.js +22 -10
- package/dist/views/NotFound/index.client.js.map +1 -1
- package/dist/views/NotFound/index.js +21 -14
- package/dist/views/NotFound/index.js.map +1 -1
- package/dist/views/ResetPassword/index.client.js +17 -8
- package/dist/views/ResetPassword/index.client.js.map +1 -1
- package/dist/views/ResetPassword/index.js +46 -25
- package/dist/views/ResetPassword/index.js.map +1 -1
- package/dist/views/Root/index.d.ts.map +1 -1
- package/dist/views/Root/index.js +36 -16
- package/dist/views/Root/index.js.map +1 -1
- package/dist/views/Unauthorized/index.js +19 -8
- package/dist/views/Unauthorized/index.js.map +1 -1
- package/dist/views/Verify/index.js +20 -11
- package/dist/views/Verify/index.js.map +1 -1
- package/dist/views/Version/Default/index.js +83 -57
- package/dist/views/Version/Default/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/Label/index.js +5 -3
- package/dist/views/Version/RenderFieldsToDiff/Label/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js +65 -50
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.js +30 -18
- package/dist/views/Version/RenderFieldsToDiff/fields/Nested/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.js +23 -12
- package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/DiffViewer/index.js +2 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/DiffViewer/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.js +22 -11
- package/dist/views/Version/RenderFieldsToDiff/fields/Select/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.js +31 -30
- package/dist/views/Version/RenderFieldsToDiff/fields/Tabs/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/DiffViewer/index.js +2 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/DiffViewer/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.js +22 -11
- package/dist/views/Version/RenderFieldsToDiff/fields/Text/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/index.js +90 -87
- package/dist/views/Version/RenderFieldsToDiff/index.js.map +1 -1
- package/dist/views/Version/Restore/index.js +38 -18
- package/dist/views/Version/Restore/index.js.map +1 -1
- package/dist/views/Version/SelectComparison/index.js +32 -24
- package/dist/views/Version/SelectComparison/index.js.map +1 -1
- package/dist/views/Version/SelectLocales/index.js +17 -11
- package/dist/views/Version/SelectLocales/index.js.map +1 -1
- package/dist/views/Version/index.js +2 -1
- package/dist/views/Version/index.js.map +1 -1
- package/dist/views/Versions/buildColumns.js +7 -6
- package/dist/views/Versions/buildColumns.js.map +1 -1
- package/dist/views/Versions/cells/AutosaveCell/index.js +25 -3
- package/dist/views/Versions/cells/AutosaveCell/index.js.map +1 -1
- package/dist/views/Versions/cells/CreatedAt/index.js +9 -7
- package/dist/views/Versions/cells/CreatedAt/index.js.map +1 -1
- package/dist/views/Versions/cells/ID/index.js +4 -1
- package/dist/views/Versions/cells/ID/index.js.map +1 -1
- package/dist/views/Versions/index.client.js +61 -29
- package/dist/views/Versions/index.client.js.map +1 -1
- package/dist/views/Versions/index.js +31 -22
- package/dist/views/Versions/index.js.map +1 -1
- package/dist/withPayload.d.ts.map +1 -1
- package/dist/withPayload.js +23 -0
- package/dist/withPayload.js.map +1 -1
- package/package.json +15 -11
package/dist/views/List/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
2
|
import { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser';
|
|
2
3
|
import { RenderCustomComponent } from '@payloadcms/ui/elements/RenderCustomComponent';
|
|
3
4
|
import { TableColumnsProvider } from '@payloadcms/ui/elements/TableColumns';
|
|
@@ -14,7 +15,7 @@ export const ListView = async ({ initPageResult, params, searchParams })=>{
|
|
|
14
15
|
const { collectionConfig, locale: fullLocale, permissions, req: { i18n, locale, payload, payload: { config }, query, user }, visibleEntities } = initPageResult;
|
|
15
16
|
const collectionSlug = collectionConfig?.slug;
|
|
16
17
|
if (!permissions?.collections?.[collectionSlug]?.read?.permission) {
|
|
17
|
-
return /*#__PURE__*/
|
|
18
|
+
return /*#__PURE__*/ _jsx(UnauthorizedView, {
|
|
18
19
|
initPageResult: initPageResult,
|
|
19
20
|
searchParams: searchParams
|
|
20
21
|
});
|
|
@@ -73,48 +74,56 @@ export const ListView = async ({ initPageResult, params, searchParams })=>{
|
|
|
73
74
|
collectionSlug,
|
|
74
75
|
listSearchableFields: collectionConfig.admin.listSearchableFields
|
|
75
76
|
};
|
|
76
|
-
return /*#__PURE__*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
77
|
+
return /*#__PURE__*/ _jsxs(Fragment, {
|
|
78
|
+
children: [
|
|
79
|
+
/*#__PURE__*/ _jsx(HydrateClientUser, {
|
|
80
|
+
permissions: permissions,
|
|
81
|
+
user: user
|
|
82
|
+
}),
|
|
83
|
+
/*#__PURE__*/ _jsx(ListInfoProvider, {
|
|
84
|
+
collectionConfig: createClientCollectionConfig({
|
|
85
|
+
collection: collectionConfig,
|
|
86
|
+
t: initPageResult.req.i18n.t
|
|
87
|
+
}),
|
|
88
|
+
collectionSlug: collectionSlug,
|
|
89
|
+
hasCreatePermission: permissions?.collections?.[collectionSlug]?.create?.permission,
|
|
90
|
+
newDocumentURL: `${admin}/collections/${collectionSlug}/create`,
|
|
91
|
+
children: /*#__PURE__*/ _jsx(ListQueryProvider, {
|
|
92
|
+
data: data,
|
|
93
|
+
defaultLimit: limit || collectionConfig?.admin?.pagination?.defaultLimit,
|
|
94
|
+
defaultSort: sort,
|
|
95
|
+
modifySearchParams: true,
|
|
96
|
+
preferenceKey: preferenceKey,
|
|
97
|
+
children: /*#__PURE__*/ _jsx(TableColumnsProvider, {
|
|
98
|
+
collectionSlug: collectionSlug,
|
|
99
|
+
enableRowSelections: true,
|
|
100
|
+
listPreferences: listPreferences,
|
|
101
|
+
preferenceKey: preferenceKey,
|
|
102
|
+
children: /*#__PURE__*/ _jsx(RenderCustomComponent, {
|
|
103
|
+
CustomComponent: CustomListView,
|
|
104
|
+
DefaultComponent: DefaultListView,
|
|
105
|
+
componentProps: viewComponentProps,
|
|
106
|
+
serverOnlyProps: {
|
|
107
|
+
collectionConfig,
|
|
108
|
+
data,
|
|
109
|
+
hasCreatePermission: permissions?.collections?.[collectionSlug]?.create?.permission,
|
|
110
|
+
i18n,
|
|
111
|
+
limit,
|
|
112
|
+
listPreferences,
|
|
113
|
+
locale: fullLocale,
|
|
114
|
+
newDocumentURL: `${admin}/collections/${collectionSlug}/create`,
|
|
115
|
+
params,
|
|
116
|
+
payload,
|
|
117
|
+
permissions,
|
|
118
|
+
searchParams,
|
|
119
|
+
user
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
});
|
|
118
127
|
}
|
|
119
128
|
return notFound();
|
|
120
129
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/List/index.tsx"],"sourcesContent":["import type { Where } from 'payload/types'\n\nimport { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser'\nimport { RenderCustomComponent } from '@payloadcms/ui/elements/RenderCustomComponent'\nimport { TableColumnsProvider } from '@payloadcms/ui/elements/TableColumns'\nimport { ListInfoProvider } from '@payloadcms/ui/providers/ListInfo'\nimport { ListQueryProvider } from '@payloadcms/ui/providers/ListQuery'\nimport { notFound } from 'next/navigation.js'\nimport { createClientCollectionConfig } from 'payload/config'\nimport { type AdminViewProps } from 'payload/types'\nimport { isNumber, isReactComponentOrFunction, mergeListSearchAndWhere } from 'payload/utilities'\nimport React, { Fragment } from 'react'\n\nimport type { DefaultListViewProps, ListPreferences } from './Default/types.js'\n\nimport { UnauthorizedView } from '../Unauthorized/index.js'\nimport { DefaultListView } from './Default/index.js'\n\nexport { generateListMetadata } from './meta.js'\n\nexport const ListView: React.FC<AdminViewProps> = async ({\n initPageResult,\n params,\n searchParams,\n}) => {\n const {\n collectionConfig,\n locale: fullLocale,\n permissions,\n req: {\n i18n,\n locale,\n payload,\n payload: { config },\n query,\n user,\n },\n visibleEntities,\n } = initPageResult\n\n const collectionSlug = collectionConfig?.slug\n\n if (!permissions?.collections?.[collectionSlug]?.read?.permission) {\n return <UnauthorizedView initPageResult={initPageResult} searchParams={searchParams} />\n }\n\n let listPreferences: ListPreferences\n const preferenceKey = `${collectionSlug}-list`\n\n try {\n listPreferences = (await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n user,\n where: {\n key: {\n equals: preferenceKey,\n },\n },\n })\n ?.then((res) => res?.docs?.[0]?.value)) as ListPreferences\n } catch (error) {} // eslint-disable-line no-empty\n\n const {\n routes: { admin },\n } = config\n\n if (collectionConfig) {\n const {\n admin: { components: { views: { List: CustomList } = {} } = {} },\n } = collectionConfig\n\n if (!visibleEntities.collections.includes(collectionSlug)) {\n return notFound()\n }\n\n let CustomListView = null\n\n if (CustomList && typeof CustomList === 'function') {\n CustomListView = CustomList\n } else if (typeof CustomList === 'object' && isReactComponentOrFunction(CustomList.Component)) {\n CustomListView = CustomList.Component\n }\n\n const page = isNumber(query?.page) ? Number(query.page) : 0\n const whereQuery = mergeListSearchAndWhere({\n collectionConfig,\n query: {\n search: typeof query?.search === 'string' ? query.search : undefined,\n where: (query?.where as Where) || undefined,\n },\n })\n const limit = isNumber(query?.limit)\n ? Number(query.limit)\n : listPreferences?.limit || collectionConfig.admin.pagination.defaultLimit\n const sort =\n query?.sort && typeof query.sort === 'string'\n ? query.sort\n : listPreferences?.sort || undefined\n\n const data = await payload.find({\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n limit,\n locale,\n overrideAccess: false,\n page,\n sort,\n user,\n where: whereQuery || {},\n })\n\n const viewComponentProps: DefaultListViewProps = {\n collectionSlug,\n listSearchableFields: collectionConfig.admin.listSearchableFields,\n }\n\n return (\n <Fragment>\n <HydrateClientUser permissions={permissions} user={user} />\n <ListInfoProvider\n collectionConfig={createClientCollectionConfig({\n collection: collectionConfig,\n t: initPageResult.req.i18n.t,\n })}\n collectionSlug={collectionSlug}\n hasCreatePermission={permissions?.collections?.[collectionSlug]?.create?.permission}\n newDocumentURL={`${admin}/collections/${collectionSlug}/create`}\n >\n <ListQueryProvider\n data={data}\n defaultLimit={limit || collectionConfig?.admin?.pagination?.defaultLimit}\n defaultSort={sort}\n modifySearchParams\n preferenceKey={preferenceKey}\n >\n <TableColumnsProvider\n collectionSlug={collectionSlug}\n enableRowSelections\n listPreferences={listPreferences}\n preferenceKey={preferenceKey}\n >\n <RenderCustomComponent\n CustomComponent={CustomListView}\n DefaultComponent={DefaultListView}\n componentProps={viewComponentProps}\n serverOnlyProps={{\n collectionConfig,\n data,\n hasCreatePermission:\n permissions?.collections?.[collectionSlug]?.create?.permission,\n i18n,\n limit,\n listPreferences,\n locale: fullLocale,\n newDocumentURL: `${admin}/collections/${collectionSlug}/create`,\n params,\n payload,\n permissions,\n searchParams,\n user,\n }}\n />\n </TableColumnsProvider>\n </ListQueryProvider>\n </ListInfoProvider>\n </Fragment>\n )\n }\n\n return notFound()\n}\n"],"names":["HydrateClientUser","RenderCustomComponent","TableColumnsProvider","ListInfoProvider","ListQueryProvider","notFound","createClientCollectionConfig","isNumber","isReactComponentOrFunction","mergeListSearchAndWhere","React","Fragment","UnauthorizedView","DefaultListView","generateListMetadata","ListView","initPageResult","params","searchParams","collectionConfig","locale","fullLocale","permissions","req","i18n","payload","config","query","user","visibleEntities","collectionSlug","slug","collections","read","permission","listPreferences","preferenceKey","find","collection","depth","limit","where","key","equals","then","res","docs","value","error","routes","admin","components","views","List","CustomList","includes","CustomListView","Component","page","Number","whereQuery","search","undefined","pagination","defaultLimit","sort","data","draft","fallbackLocale","overrideAccess","viewComponentProps","listSearchableFields","t","hasCreatePermission","create","newDocumentURL","defaultSort","modifySearchParams","enableRowSelections","CustomComponent","DefaultComponent","componentProps","serverOnlyProps"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/views/List/index.tsx"],"sourcesContent":["import type { Where } from 'payload/types'\n\nimport { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser'\nimport { RenderCustomComponent } from '@payloadcms/ui/elements/RenderCustomComponent'\nimport { TableColumnsProvider } from '@payloadcms/ui/elements/TableColumns'\nimport { ListInfoProvider } from '@payloadcms/ui/providers/ListInfo'\nimport { ListQueryProvider } from '@payloadcms/ui/providers/ListQuery'\nimport { notFound } from 'next/navigation.js'\nimport { createClientCollectionConfig } from 'payload/config'\nimport { type AdminViewProps } from 'payload/types'\nimport { isNumber, isReactComponentOrFunction, mergeListSearchAndWhere } from 'payload/utilities'\nimport React, { Fragment } from 'react'\n\nimport type { DefaultListViewProps, ListPreferences } from './Default/types.js'\n\nimport { UnauthorizedView } from '../Unauthorized/index.js'\nimport { DefaultListView } from './Default/index.js'\n\nexport { generateListMetadata } from './meta.js'\n\nexport const ListView: React.FC<AdminViewProps> = async ({\n initPageResult,\n params,\n searchParams,\n}) => {\n const {\n collectionConfig,\n locale: fullLocale,\n permissions,\n req: {\n i18n,\n locale,\n payload,\n payload: { config },\n query,\n user,\n },\n visibleEntities,\n } = initPageResult\n\n const collectionSlug = collectionConfig?.slug\n\n if (!permissions?.collections?.[collectionSlug]?.read?.permission) {\n return <UnauthorizedView initPageResult={initPageResult} searchParams={searchParams} />\n }\n\n let listPreferences: ListPreferences\n const preferenceKey = `${collectionSlug}-list`\n\n try {\n listPreferences = (await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n user,\n where: {\n key: {\n equals: preferenceKey,\n },\n },\n })\n ?.then((res) => res?.docs?.[0]?.value)) as ListPreferences\n } catch (error) {} // eslint-disable-line no-empty\n\n const {\n routes: { admin },\n } = config\n\n if (collectionConfig) {\n const {\n admin: { components: { views: { List: CustomList } = {} } = {} },\n } = collectionConfig\n\n if (!visibleEntities.collections.includes(collectionSlug)) {\n return notFound()\n }\n\n let CustomListView = null\n\n if (CustomList && typeof CustomList === 'function') {\n CustomListView = CustomList\n } else if (typeof CustomList === 'object' && isReactComponentOrFunction(CustomList.Component)) {\n CustomListView = CustomList.Component\n }\n\n const page = isNumber(query?.page) ? Number(query.page) : 0\n const whereQuery = mergeListSearchAndWhere({\n collectionConfig,\n query: {\n search: typeof query?.search === 'string' ? query.search : undefined,\n where: (query?.where as Where) || undefined,\n },\n })\n const limit = isNumber(query?.limit)\n ? Number(query.limit)\n : listPreferences?.limit || collectionConfig.admin.pagination.defaultLimit\n const sort =\n query?.sort && typeof query.sort === 'string'\n ? query.sort\n : listPreferences?.sort || undefined\n\n const data = await payload.find({\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n limit,\n locale,\n overrideAccess: false,\n page,\n sort,\n user,\n where: whereQuery || {},\n })\n\n const viewComponentProps: DefaultListViewProps = {\n collectionSlug,\n listSearchableFields: collectionConfig.admin.listSearchableFields,\n }\n\n return (\n <Fragment>\n <HydrateClientUser permissions={permissions} user={user} />\n <ListInfoProvider\n collectionConfig={createClientCollectionConfig({\n collection: collectionConfig,\n t: initPageResult.req.i18n.t,\n })}\n collectionSlug={collectionSlug}\n hasCreatePermission={permissions?.collections?.[collectionSlug]?.create?.permission}\n newDocumentURL={`${admin}/collections/${collectionSlug}/create`}\n >\n <ListQueryProvider\n data={data}\n defaultLimit={limit || collectionConfig?.admin?.pagination?.defaultLimit}\n defaultSort={sort}\n modifySearchParams\n preferenceKey={preferenceKey}\n >\n <TableColumnsProvider\n collectionSlug={collectionSlug}\n enableRowSelections\n listPreferences={listPreferences}\n preferenceKey={preferenceKey}\n >\n <RenderCustomComponent\n CustomComponent={CustomListView}\n DefaultComponent={DefaultListView}\n componentProps={viewComponentProps}\n serverOnlyProps={{\n collectionConfig,\n data,\n hasCreatePermission:\n permissions?.collections?.[collectionSlug]?.create?.permission,\n i18n,\n limit,\n listPreferences,\n locale: fullLocale,\n newDocumentURL: `${admin}/collections/${collectionSlug}/create`,\n params,\n payload,\n permissions,\n searchParams,\n user,\n }}\n />\n </TableColumnsProvider>\n </ListQueryProvider>\n </ListInfoProvider>\n </Fragment>\n )\n }\n\n return notFound()\n}\n"],"names":["HydrateClientUser","RenderCustomComponent","TableColumnsProvider","ListInfoProvider","ListQueryProvider","notFound","createClientCollectionConfig","isNumber","isReactComponentOrFunction","mergeListSearchAndWhere","React","Fragment","UnauthorizedView","DefaultListView","generateListMetadata","ListView","initPageResult","params","searchParams","collectionConfig","locale","fullLocale","permissions","req","i18n","payload","config","query","user","visibleEntities","collectionSlug","slug","collections","read","permission","listPreferences","preferenceKey","find","collection","depth","limit","where","key","equals","then","res","docs","value","error","routes","admin","components","views","List","CustomList","includes","CustomListView","Component","page","Number","whereQuery","search","undefined","pagination","defaultLimit","sort","data","draft","fallbackLocale","overrideAccess","viewComponentProps","listSearchableFields","t","hasCreatePermission","create","newDocumentURL","defaultSort","modifySearchParams","enableRowSelections","CustomComponent","DefaultComponent","componentProps","serverOnlyProps"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAEA,SAASA,iBAAiB,QAAQ,4CAA2C;AAC7E,SAASC,qBAAqB,QAAQ,gDAA+C;AACrF,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,iBAAiB,QAAQ,qCAAoC;AACtE,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,4BAA4B,QAAQ,iBAAgB;AAE7D,SAASC,QAAQ,EAAEC,0BAA0B,EAAEC,uBAAuB,QAAQ,oBAAmB;AACjG,OAAOC,SAASC,QAAQ,QAAQ,QAAO;AAIvC,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,eAAe,QAAQ,qBAAoB;AAEpD,SAASC,oBAAoB,QAAQ,YAAW;AAEhD,OAAO,MAAMC,WAAqC,OAAO,EACvDC,cAAc,EACdC,MAAM,EACNC,YAAY,EACb;IACC,MAAM,EACJC,gBAAgB,EAChBC,QAAQC,UAAU,EAClBC,WAAW,EACXC,KAAK,EACHC,IAAI,EACJJ,MAAM,EACNK,OAAO,EACPA,SAAS,EAAEC,MAAM,EAAE,EACnBC,KAAK,EACLC,IAAI,EACL,EACDC,eAAe,EAChB,GAAGb;IAEJ,MAAMc,iBAAiBX,kBAAkBY;IAEzC,IAAI,CAACT,aAAaU,aAAa,CAACF,eAAe,EAAEG,MAAMC,YAAY;QACjE,qBAAO,KAACtB;YAAiBI,gBAAgBA;YAAgBE,cAAcA;;IACzE;IAEA,IAAIiB;IACJ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;IAOd;IAEA,OAAOvB;AACT,EAAC"}
|
|
@@ -9,7 +9,7 @@ export interface LivePreviewContextType {
|
|
|
9
9
|
breakpoints: LivePreviewConfig['breakpoints'];
|
|
10
10
|
fieldSchemaJSON?: ReturnType<typeof fieldSchemaToJSON>;
|
|
11
11
|
iframeHasLoaded: boolean;
|
|
12
|
-
iframeRef: React.RefObject<HTMLIFrameElement>;
|
|
12
|
+
iframeRef: React.RefObject<HTMLIFrameElement | null>;
|
|
13
13
|
isPopupOpen: boolean;
|
|
14
14
|
measuredDeviceSize: {
|
|
15
15
|
height: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/views/LivePreview/Context/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAIrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEzD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,OAAO,CAAA;IACnB,UAAU,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;IAC5D,WAAW,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAC7C,eAAe,CAAC,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAA;IACtD,eAAe,EAAE,OAAO,CAAA;IACxB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/views/LivePreview/Context/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA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,OAAO,KAAK,IAAI,CAAA;IAC7C,qBAAqB,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IACxE,oBAAoB,EAAE,CAAC,iBAAiB,EAAE,QAAQ,GAAG,OAAO,KAAK,IAAI,CAAA;IACrE,OAAO,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAA;IACpC,kBAAkB,EAAE,CAAC,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IAChE,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,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,eAAO,MAAM,kBAAkB,iDAmC7B,CAAA;AAEF,eAAO,MAAM,qBAAqB,8BAAuC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/views/LivePreview/Context/context.ts"],"sourcesContent":["import type { LivePreviewConfig } from 'payload/config'\nimport type { fieldSchemaToJSON } from 'payload/utilities'\nimport type { Dispatch } from 'react'\n\nimport { createContext, useContext } from 'react'\n\nimport type { usePopupWindow } from '../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 fieldSchemaJSON?: ReturnType<typeof fieldSchemaToJSON>\n iframeHasLoaded: boolean\n iframeRef: React.RefObject<HTMLIFrameElement>\n isPopupOpen: boolean\n measuredDeviceSize: {\n height: number\n width: number\n }\n openPopupWindow: ReturnType<typeof usePopupWindow>['openPopupWindow']\n popupRef?: React.MutableRefObject<Window | null>\n previewWindowType: 'iframe' | 'popup'\n setAppIsReady: (appIsReady: boolean) => void\n setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void\n setHeight: (height: number) => void\n setIframeHasLoaded: (loaded: boolean) => 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 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 url: string | undefined\n zoom: number\n}\n\nexport const LivePreviewContext = createContext<LivePreviewContextType>({\n appIsReady: false,\n breakpoint: undefined,\n breakpoints: undefined,\n fieldSchemaJSON: undefined,\n iframeHasLoaded: false,\n iframeRef: undefined,\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 setIframeHasLoaded: () => {},\n setMeasuredDeviceSize: () => {},\n setPreviewWindowType: () => {},\n setSize: () => {},\n setToolbarPosition: () => {},\n setWidth: () => {},\n setZoom: () => {},\n size: {\n height: 0,\n width: 0,\n },\n toolbarPosition: {\n x: 0,\n y: 0,\n },\n url: undefined,\n zoom: 1,\n})\n\nexport const useLivePreviewContext = () => useContext(LivePreviewContext)\n"],"names":["createContext","useContext","LivePreviewContext","appIsReady","breakpoint","undefined","breakpoints","fieldSchemaJSON","iframeHasLoaded","iframeRef","isPopupOpen","measuredDeviceSize","height","width","openPopupWindow","popupRef","previewWindowType","setAppIsReady","setBreakpoint","setHeight","setIframeHasLoaded","setMeasuredDeviceSize","setPreviewWindowType","setSize","setToolbarPosition","setWidth","setZoom","size","toolbarPosition","x","y","url","zoom","useLivePreviewContext"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAO;AA0CjD,OAAO,MAAMC,qBAAqBF,cAAsC;IACtEG,YAAY;IACZC,YAAYC;IACZC,aAAaD;IACbE,iBAAiBF;IACjBG,iBAAiB;IACjBC,WAAWJ;IACXK,aAAa;IACbC,oBAAoB;QAClBC,QAAQ;QACRC,OAAO;IACT;IACAC,iBAAiB,KAAO;IACxBC,UAAUV;IACVW,mBAAmB;IACnBC,eAAe,KAAO;IACtBC,eAAe,KAAO;IACtBC,WAAW,KAAO;IAClBC,oBAAoB,KAAO;IAC3BC,uBAAuB,KAAO;IAC9BC,sBAAsB,KAAO;IAC7BC,SAAS,KAAO;IAChBC,oBAAoB,KAAO;IAC3BC,UAAU,KAAO;IACjBC,SAAS,KAAO;IAChBC,MAAM;QACJf,QAAQ;QACRC,OAAO;IACT;IACAe,iBAAiB;QACfC,GAAG;QACHC,GAAG;IACL;IACAC,KAAK1B;IACL2B,MAAM;AACR,GAAE;AAEF,OAAO,MAAMC,wBAAwB,IAAMhC,WAAWC,oBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/views/LivePreview/Context/context.ts"],"sourcesContent":["import type { LivePreviewConfig } from 'payload/config'\nimport type { fieldSchemaToJSON } from 'payload/utilities'\nimport type { Dispatch } from 'react'\n\nimport { createContext, useContext } from 'react'\n\nimport type { usePopupWindow } from '../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 fieldSchemaJSON?: ReturnType<typeof fieldSchemaToJSON>\n iframeHasLoaded: boolean\n iframeRef: React.RefObject<HTMLIFrameElement | null>\n isPopupOpen: boolean\n measuredDeviceSize: {\n height: number\n width: number\n }\n openPopupWindow: ReturnType<typeof usePopupWindow>['openPopupWindow']\n popupRef?: React.MutableRefObject<Window | null>\n previewWindowType: 'iframe' | 'popup'\n setAppIsReady: (appIsReady: boolean) => void\n setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void\n setHeight: (height: number) => void\n setIframeHasLoaded: (loaded: boolean) => 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 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 url: string | undefined\n zoom: number\n}\n\nexport const LivePreviewContext = createContext<LivePreviewContextType>({\n appIsReady: false,\n breakpoint: undefined,\n breakpoints: undefined,\n fieldSchemaJSON: undefined,\n iframeHasLoaded: false,\n iframeRef: undefined,\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 setIframeHasLoaded: () => {},\n setMeasuredDeviceSize: () => {},\n setPreviewWindowType: () => {},\n setSize: () => {},\n setToolbarPosition: () => {},\n setWidth: () => {},\n setZoom: () => {},\n size: {\n height: 0,\n width: 0,\n },\n toolbarPosition: {\n x: 0,\n y: 0,\n },\n url: undefined,\n zoom: 1,\n})\n\nexport const useLivePreviewContext = () => useContext(LivePreviewContext)\n"],"names":["createContext","useContext","LivePreviewContext","appIsReady","breakpoint","undefined","breakpoints","fieldSchemaJSON","iframeHasLoaded","iframeRef","isPopupOpen","measuredDeviceSize","height","width","openPopupWindow","popupRef","previewWindowType","setAppIsReady","setBreakpoint","setHeight","setIframeHasLoaded","setMeasuredDeviceSize","setPreviewWindowType","setSize","setToolbarPosition","setWidth","setZoom","size","toolbarPosition","x","y","url","zoom","useLivePreviewContext"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAO;AA0CjD,OAAO,MAAMC,qBAAqBF,cAAsC;IACtEG,YAAY;IACZC,YAAYC;IACZC,aAAaD;IACbE,iBAAiBF;IACjBG,iBAAiB;IACjBC,WAAWJ;IACXK,aAAa;IACbC,oBAAoB;QAClBC,QAAQ;QACRC,OAAO;IACT;IACAC,iBAAiB,KAAO;IACxBC,UAAUV;IACVW,mBAAmB;IACnBC,eAAe,KAAO;IACtBC,eAAe,KAAO;IACtBC,WAAW,KAAO;IAClBC,oBAAoB,KAAO;IAC3BC,uBAAuB,KAAO;IAC9BC,sBAAsB,KAAO;IAC7BC,SAAS,KAAO;IAChBC,oBAAoB,KAAO;IAC3BC,UAAU,KAAO;IACjBC,SAAS,KAAO;IAChBC,MAAM;QACJf,QAAQ;QACRC,OAAO;IACT;IACAe,iBAAiB;QACfC,GAAG;QACHC,GAAG;IACL;IACAC,KAAK1B;IACL2B,MAAM;AACR,GAAE;AAEF,OAAO,MAAMC,wBAAwB,IAAMhC,WAAWC,oBAAmB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { DndContext } from '@dnd-kit/core';
|
|
3
4
|
import { fieldSchemaToJSON } from 'payload/utilities';
|
|
4
5
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
@@ -116,7 +117,7 @@ export const LivePreviewProvider = ({ breakpoints, children, fieldSchema, isPopu
|
|
|
116
117
|
isPopupOpen,
|
|
117
118
|
handleWindowChange
|
|
118
119
|
]);
|
|
119
|
-
return /*#__PURE__*/
|
|
120
|
+
return /*#__PURE__*/ _jsx(LivePreviewContext.Provider, {
|
|
120
121
|
value: {
|
|
121
122
|
appIsReady,
|
|
122
123
|
breakpoint,
|
|
@@ -143,11 +144,13 @@ export const LivePreviewProvider = ({ breakpoints, children, fieldSchema, isPopu
|
|
|
143
144
|
toolbarPosition: position,
|
|
144
145
|
url,
|
|
145
146
|
zoom
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
},
|
|
148
|
+
children: /*#__PURE__*/ _jsx(DndContext, {
|
|
149
|
+
collisionDetection: customCollisionDetection,
|
|
150
|
+
onDragEnd: handleDragEnd,
|
|
151
|
+
children: listeningForMessages && children
|
|
152
|
+
})
|
|
153
|
+
});
|
|
151
154
|
};
|
|
152
155
|
|
|
153
156
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/views/LivePreview/Context/index.tsx"],"sourcesContent":["'use client'\nimport type { LivePreviewConfig } from 'payload/config'\nimport type { ClientFieldConfig, Field } from 'payload/types'\n\nimport { DndContext } from '@dnd-kit/core'\nimport { fieldSchemaToJSON } from 'payload/utilities'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport type { usePopupWindow } from '../usePopupWindow.js'\n\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 fieldSchema: ClientFieldConfig[]\n isPopupOpen?: boolean\n openPopupWindow?: ReturnType<typeof usePopupWindow>['openPopupWindow']\n popupRef?: React.MutableRefObject<Window>\n url?: string\n}\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints,\n children,\n fieldSchema,\n isPopupOpen,\n openPopupWindow,\n popupRef,\n url,\n}) => {\n const [previewWindowType, setPreviewWindowType] = useState<'iframe' | 'popup'>('iframe')\n\n const [appIsReady, setAppIsReady] = useState(false)\n const [listeningForMessages, setListeningForMessages] = useState(false)\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null)\n\n const [iframeHasLoaded, setIframeHasLoaded] = useState(false)\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 const [fieldSchemaJSON] = useState(() => {\n return fieldSchemaToJSON(fieldSchema)\n })\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 // 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 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') openPopupWindow()\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 return (\n <LivePreviewContext.Provider\n value={{\n appIsReady,\n breakpoint,\n breakpoints,\n fieldSchemaJSON,\n iframeHasLoaded,\n iframeRef,\n isPopupOpen,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIframeHasLoaded,\n setMeasuredDeviceSize,\n setPreviewWindowType: handleWindowChange,\n setSize,\n setToolbarPosition: setPosition,\n setWidth,\n setZoom,\n size,\n toolbarPosition: position,\n url,\n zoom,\n }}\n >\n <DndContext collisionDetection={customCollisionDetection} onDragEnd={handleDragEnd}>\n {listeningForMessages && children}\n </DndContext>\n </LivePreviewContext.Provider>\n )\n}\n"],"names":["DndContext","fieldSchemaToJSON","React","useCallback","useEffect","useState","customCollisionDetection","LivePreviewContext","sizeReducer","LivePreviewProvider","breakpoints","children","fieldSchema","isPopupOpen","openPopupWindow","popupRef","url","previewWindowType","setPreviewWindowType","appIsReady","setAppIsReady","listeningForMessages","setListeningForMessages","iframeRef","useRef","iframeHasLoaded","setIframeHasLoaded","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","height","width","measuredDeviceSize","setMeasuredDeviceSize","breakpoint","setBreakpoint","fieldSchemaJSON","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","name","handleMessage","event","startsWith","origin","data","ready","window","addEventListener","removeEventListener","handleWindowChange","newPreviewWindowType","Provider","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/views/LivePreview/Context/index.tsx"],"sourcesContent":["'use client'\nimport type { LivePreviewConfig } from 'payload/config'\nimport type { ClientFieldConfig, Field } from 'payload/types'\n\nimport { DndContext } from '@dnd-kit/core'\nimport { fieldSchemaToJSON } from 'payload/utilities'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport type { usePopupWindow } from '../usePopupWindow.js'\n\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 fieldSchema: ClientFieldConfig[]\n isPopupOpen?: boolean\n openPopupWindow?: ReturnType<typeof usePopupWindow>['openPopupWindow']\n popupRef?: React.MutableRefObject<Window>\n url?: string\n}\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints,\n children,\n fieldSchema,\n isPopupOpen,\n openPopupWindow,\n popupRef,\n url,\n}) => {\n const [previewWindowType, setPreviewWindowType] = useState<'iframe' | 'popup'>('iframe')\n\n const [appIsReady, setAppIsReady] = useState(false)\n const [listeningForMessages, setListeningForMessages] = useState(false)\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null)\n\n const [iframeHasLoaded, setIframeHasLoaded] = useState(false)\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 const [fieldSchemaJSON] = useState(() => {\n return fieldSchemaToJSON(fieldSchema)\n })\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 // 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 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') openPopupWindow()\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 return (\n <LivePreviewContext.Provider\n value={{\n appIsReady,\n breakpoint,\n breakpoints,\n fieldSchemaJSON,\n iframeHasLoaded,\n iframeRef,\n isPopupOpen,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIframeHasLoaded,\n setMeasuredDeviceSize,\n setPreviewWindowType: handleWindowChange,\n setSize,\n setToolbarPosition: setPosition,\n setWidth,\n setZoom,\n size,\n toolbarPosition: position,\n url,\n zoom,\n }}\n >\n <DndContext collisionDetection={customCollisionDetection} onDragEnd={handleDragEnd}>\n {listeningForMessages && children}\n </DndContext>\n </LivePreviewContext.Provider>\n )\n}\n"],"names":["DndContext","fieldSchemaToJSON","React","useCallback","useEffect","useState","customCollisionDetection","LivePreviewContext","sizeReducer","LivePreviewProvider","breakpoints","children","fieldSchema","isPopupOpen","openPopupWindow","popupRef","url","previewWindowType","setPreviewWindowType","appIsReady","setAppIsReady","listeningForMessages","setListeningForMessages","iframeRef","useRef","iframeHasLoaded","setIframeHasLoaded","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","height","width","measuredDeviceSize","setMeasuredDeviceSize","breakpoint","setBreakpoint","fieldSchemaJSON","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","name","handleMessage","event","startsWith","origin","data","ready","window","addEventListener","removeEventListener","handleWindowChange","newPreviewWindowType","Provider","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AAIA,SAASA,UAAU,QAAQ,gBAAe;AAC1C,SAASC,iBAAiB,QAAQ,oBAAmB;AACrD,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAI/D,SAASC,wBAAwB,QAAQ,0BAAyB;AAClE,SAASC,kBAAkB,QAAQ,eAAc;AACjD,SAASC,WAAW,QAAQ,mBAAkB;AAiB9C,OAAO,MAAMC,sBAA0D,CAAC,EACtEC,WAAW,EACXC,QAAQ,EACRC,WAAW,EACXC,WAAW,EACXC,eAAe,EACfC,QAAQ,EACRC,GAAG,EACJ;IACC,MAAM,CAACC,mBAAmBC,qBAAqB,GAAGb,SAA6B;IAE/E,MAAM,CAACc,YAAYC,cAAc,GAAGf,SAAS;IAC7C,MAAM,CAACgB,sBAAsBC,wBAAwB,GAAGjB,SAAS;IAEjE,MAAMkB,YAAYrB,MAAMsB,MAAM,CAAoB;IAElD,MAAM,CAACC,iBAAiBC,mBAAmB,GAAGrB,SAAS;IAEvD,MAAM,CAACsB,MAAMC,QAAQ,GAAGvB,SAAS;IAEjC,MAAM,CAACwB,UAAUC,YAAY,GAAGzB,SAAS;QAAE0B,GAAG;QAAGC,GAAG;IAAE;IAEtD,MAAM,CAACC,MAAMC,QAAQ,GAAGhC,MAAMiC,UAAU,CAAC3B,aAAa;QAAE4B,QAAQ;QAAGC,OAAO;IAAE;IAE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G;IAC3GN,UAAU;QACR,MAAMqD,gBAAgB,CAACC;YACrB,IACE1C,KAAK2C,WAAWD,MAAME,MAAM,KAC5BF,MAAMG,IAAI,IACV,OAAOH,MAAMG,IAAI,KAAK,YACtBH,MAAMG,IAAI,CAACX,IAAI,KAAK,wBACpB;gBACA,IAAIQ,MAAMG,IAAI,CAACC,KAAK,EAAE;oBACpB1C,cAAc;gBAChB;YACF;QACF;QAEA2C,OAAOC,gBAAgB,CAAC,WAAWP;QAEnCnC,wBAAwB;QAExB,OAAO;YACLyC,OAAOE,mBAAmB,CAAC,WAAWR;QACxC;IACF,GAAG;QAACzC;QAAKK;KAAqB;IAE9B,MAAM6C,qBAAqB/D,YACzB,CAAC+C;QACC9B,cAAc;QACdF,qBAAqBgC;QACrB,IAAIA,SAAS,SAASpC;IACxB,GACA;QAACA;KAAgB;IAGnB,mEAAmE;IACnE,0EAA0E;IAC1EV,UAAU;QACR,MAAM+D,uBAAuBtD,cAAc,UAAU;QAErD,IAAIsD,yBAAyBlD,mBAAmB;YAC9CiD,mBAAmB;QACrB;IACF,GAAG;QAACjD;QAAmBJ;QAAaqD;KAAmB;IAEvD,qBACE,KAAC3D,mBAAmB6D,QAAQ;QAC1BjB,OAAO;YACLhC;YACAqB;YACA9B;YACAgC;YACAjB;YACAF;YACAV;YACAyB;YACAxB;YACAC;YACAE;YACAG;YACAqB;YACAW;YACA1B;YACAa;YACArB,sBAAsBgD;YACtBhC;YACAmC,oBAAoBvC;YACpBmB;YACArB;YACAK;YACAqC,iBAAiBzC;YACjBb;YACAW;QACF;kBAEA,cAAA,KAAC3B;YAAWuE,oBAAoBjE;YAA0BkE,WAAW7B;sBAClEtB,wBAAwBV;;;AAIjC,EAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { useResize } from '@payloadcms/ui/hooks/useResize';
|
|
3
4
|
import React, { useEffect } from 'react';
|
|
4
5
|
import { useLivePreviewContext } from '../Context/context.js';
|
|
@@ -37,15 +38,16 @@ export const DeviceContainer = (props)=>{
|
|
|
37
38
|
width = `${size?.width / (typeof zoom === 'number' ? zoom : 1)}px`;
|
|
38
39
|
height = `${size?.height / (typeof zoom === 'number' ? zoom : 1)}px`;
|
|
39
40
|
}
|
|
40
|
-
return /*#__PURE__*/
|
|
41
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
41
42
|
ref: deviceFrameRef,
|
|
42
43
|
style: {
|
|
43
44
|
height,
|
|
44
45
|
margin,
|
|
45
46
|
transform: `translate3d(${x}, 0, 0)`,
|
|
46
47
|
width
|
|
47
|
-
}
|
|
48
|
-
|
|
48
|
+
},
|
|
49
|
+
children: children
|
|
50
|
+
});
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/views/LivePreview/Device/index.tsx"],"sourcesContent":["'use client'\nimport { useResize } from '@payloadcms/ui/hooks/useResize'\nimport React, { useEffect } from 'react'\n\nimport { useLivePreviewContext } from '../Context/context.js'\n\nexport const DeviceContainer: React.FC<{\n children: React.ReactNode\n}> = (props) => {\n const { children } = props\n\n const deviceFrameRef = React.useRef<HTMLDivElement>(null)\n\n const { breakpoint, setMeasuredDeviceSize, size, zoom } = useLivePreviewContext()\n\n // Keep an accurate measurement of the actual device size as it is truly rendered\n // This is helpful when `sizes` are non-number units like percentages, etc.\n const { size: measuredDeviceSize } = useResize(deviceFrameRef)\n\n // Sync the measured device size with the context so that other components can use it\n // This happens from the bottom up so that as this component mounts and unmounts,\n // Its size is freshly populated again upon re-mounting, i.e. going from iframe->popup->iframe\n useEffect(() => {\n if (measuredDeviceSize) {\n setMeasuredDeviceSize(measuredDeviceSize)\n }\n }, [measuredDeviceSize, setMeasuredDeviceSize])\n\n let x = '0'\n let margin = '0'\n\n if (breakpoint && breakpoint !== 'responsive') {\n x = '-50%'\n\n if (\n typeof zoom === 'number' &&\n typeof size.width === 'number' &&\n typeof size.height === 'number'\n ) {\n const scaledWidth = size.width / zoom\n const difference = scaledWidth - size.width\n x = `${difference / 2}px`\n margin = '0 auto'\n }\n }\n\n let width = zoom ? `${100 / zoom}%` : '100%'\n let height = zoom ? `${100 / zoom}%` : '100%'\n\n if (breakpoint !== 'responsive') {\n width = `${size?.width / (typeof zoom === 'number' ? zoom : 1)}px`\n height = `${size?.height / (typeof zoom === 'number' ? zoom : 1)}px`\n }\n\n return (\n <div\n ref={deviceFrameRef}\n style={{\n height,\n margin,\n transform: `translate3d(${x}, 0, 0)`,\n width,\n }}\n >\n {children}\n </div>\n )\n}\n"],"names":["useResize","React","useEffect","useLivePreviewContext","DeviceContainer","props","children","deviceFrameRef","useRef","breakpoint","setMeasuredDeviceSize","size","zoom","measuredDeviceSize","x","margin","width","height","scaledWidth","difference","div","ref","style","transform"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/views/LivePreview/Device/index.tsx"],"sourcesContent":["'use client'\nimport { useResize } from '@payloadcms/ui/hooks/useResize'\nimport React, { useEffect } from 'react'\n\nimport { useLivePreviewContext } from '../Context/context.js'\n\nexport const DeviceContainer: React.FC<{\n children: React.ReactNode\n}> = (props) => {\n const { children } = props\n\n const deviceFrameRef = React.useRef<HTMLDivElement>(null)\n\n const { breakpoint, setMeasuredDeviceSize, size, zoom } = useLivePreviewContext()\n\n // Keep an accurate measurement of the actual device size as it is truly rendered\n // This is helpful when `sizes` are non-number units like percentages, etc.\n const { size: measuredDeviceSize } = useResize(deviceFrameRef)\n\n // Sync the measured device size with the context so that other components can use it\n // This happens from the bottom up so that as this component mounts and unmounts,\n // Its size is freshly populated again upon re-mounting, i.e. going from iframe->popup->iframe\n useEffect(() => {\n if (measuredDeviceSize) {\n setMeasuredDeviceSize(measuredDeviceSize)\n }\n }, [measuredDeviceSize, setMeasuredDeviceSize])\n\n let x = '0'\n let margin = '0'\n\n if (breakpoint && breakpoint !== 'responsive') {\n x = '-50%'\n\n if (\n typeof zoom === 'number' &&\n typeof size.width === 'number' &&\n typeof size.height === 'number'\n ) {\n const scaledWidth = size.width / zoom\n const difference = scaledWidth - size.width\n x = `${difference / 2}px`\n margin = '0 auto'\n }\n }\n\n let width = zoom ? `${100 / zoom}%` : '100%'\n let height = zoom ? `${100 / zoom}%` : '100%'\n\n if (breakpoint !== 'responsive') {\n width = `${size?.width / (typeof zoom === 'number' ? zoom : 1)}px`\n height = `${size?.height / (typeof zoom === 'number' ? zoom : 1)}px`\n }\n\n return (\n <div\n ref={deviceFrameRef}\n style={{\n height,\n margin,\n transform: `translate3d(${x}, 0, 0)`,\n width,\n }}\n >\n {children}\n </div>\n )\n}\n"],"names":["useResize","React","useEffect","useLivePreviewContext","DeviceContainer","props","children","deviceFrameRef","useRef","breakpoint","setMeasuredDeviceSize","size","zoom","measuredDeviceSize","x","margin","width","height","scaledWidth","difference","div","ref","style","transform"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AACA,SAASA,SAAS,QAAQ,iCAAgC;AAC1D,OAAOC,SAASC,SAAS,QAAQ,QAAO;AAExC,SAASC,qBAAqB,QAAQ,wBAAuB;AAE7D,OAAO,MAAMC,kBAER,CAACC;IACJ,MAAM,EAAEC,QAAQ,EAAE,GAAGD;IAErB,MAAME,iBAAiBN,MAAMO,MAAM,CAAiB;IAEpD,MAAM,EAAEC,UAAU,EAAEC,qBAAqB,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGT;IAE1D,iFAAiF;IACjF,2EAA2E;IAC3E,MAAM,EAAEQ,MAAME,kBAAkB,EAAE,GAAGb,UAAUO;IAE/C,qFAAqF;IACrF,iFAAiF;IACjF,8FAA8F;IAC9FL,UAAU;QACR,IAAIW,oBAAoB;YACtBH,sBAAsBG;QACxB;IACF,GAAG;QAACA;QAAoBH;KAAsB;IAE9C,IAAII,IAAI;IACR,IAAIC,SAAS;IAEb,IAAIN,cAAcA,eAAe,cAAc;QAC7CK,IAAI;QAEJ,IACE,OAAOF,SAAS,YAChB,OAAOD,KAAKK,KAAK,KAAK,YACtB,OAAOL,KAAKM,MAAM,KAAK,UACvB;YACA,MAAMC,cAAcP,KAAKK,KAAK,GAAGJ;YACjC,MAAMO,aAAaD,cAAcP,KAAKK,KAAK;YAC3CF,IAAI,CAAC,EAAEK,aAAa,EAAE,EAAE,CAAC;YACzBJ,SAAS;QACX;IACF;IAEA,IAAIC,QAAQJ,OAAO,CAAC,EAAE,MAAMA,KAAK,CAAC,CAAC,GAAG;IACtC,IAAIK,SAASL,OAAO,CAAC,EAAE,MAAMA,KAAK,CAAC,CAAC,GAAG;IAEvC,IAAIH,eAAe,cAAc;QAC/BO,QAAQ,CAAC,EAAEL,MAAMK,QAAS,CAAA,OAAOJ,SAAS,WAAWA,OAAO,CAAA,EAAG,EAAE,CAAC;QAClEK,SAAS,CAAC,EAAEN,MAAMM,SAAU,CAAA,OAAOL,SAAS,WAAWA,OAAO,CAAA,EAAG,EAAE,CAAC;IACtE;IAEA,qBACE,KAACQ;QACCC,KAAKd;QACLe,OAAO;YACLL;YACAF;YACAQ,WAAW,CAAC,YAAY,EAAET,EAAE,OAAO,CAAC;YACpCE;QACF;kBAECV;;AAGP,EAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import { useLivePreviewContext } from '../Context/context.js';
|
|
4
5
|
export const DeviceContainer = (props)=>{
|
|
@@ -16,14 +17,15 @@ export const DeviceContainer = (props)=>{
|
|
|
16
17
|
margin = '0 auto';
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
return /*#__PURE__*/
|
|
20
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
20
21
|
style: {
|
|
21
22
|
height: foundBreakpoint && foundBreakpoint?.name !== 'responsive' ? `${size?.height / (typeof zoom === 'number' ? zoom : 1)}px` : typeof zoom === 'number' ? `${100 / zoom}%` : '100%',
|
|
22
23
|
margin,
|
|
23
24
|
transform: `translate3d(${x}, 0, 0)`,
|
|
24
25
|
width: foundBreakpoint && foundBreakpoint?.name !== 'responsive' ? `${size?.width / (typeof zoom === 'number' ? zoom : 1)}px` : typeof zoom === 'number' ? `${100 / zoom}%` : '100%'
|
|
25
|
-
}
|
|
26
|
-
|
|
26
|
+
},
|
|
27
|
+
children: children
|
|
28
|
+
});
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/views/LivePreview/DeviceContainer/index.tsx"],"sourcesContent":["'use client'\nimport React from 'react'\n\nimport { useLivePreviewContext } from '../Context/context.js'\n\nexport const DeviceContainer: React.FC<{\n children: React.ReactNode\n}> = (props) => {\n const { children } = props\n\n const { breakpoint, breakpoints, size, zoom } = useLivePreviewContext()\n\n const foundBreakpoint = breakpoint && breakpoints?.find((bp) => bp.name === breakpoint)\n\n let x = '0'\n let margin = '0'\n\n if (foundBreakpoint && breakpoint !== 'responsive') {\n x = '-50%'\n\n if (\n typeof zoom === 'number' &&\n typeof size.width === 'number' &&\n typeof size.height === 'number'\n ) {\n const scaledWidth = size.width / zoom\n const difference = scaledWidth - size.width\n x = `${difference / 2}px`\n margin = '0 auto'\n }\n }\n\n return (\n <div\n style={{\n height:\n foundBreakpoint && foundBreakpoint?.name !== 'responsive'\n ? `${size?.height / (typeof zoom === 'number' ? zoom : 1)}px`\n : typeof zoom === 'number'\n ? `${100 / zoom}%`\n : '100%',\n margin,\n transform: `translate3d(${x}, 0, 0)`,\n width:\n foundBreakpoint && foundBreakpoint?.name !== 'responsive'\n ? `${size?.width / (typeof zoom === 'number' ? zoom : 1)}px`\n : typeof zoom === 'number'\n ? `${100 / zoom}%`\n : '100%',\n }}\n >\n {children}\n </div>\n )\n}\n"],"names":["React","useLivePreviewContext","DeviceContainer","props","children","breakpoint","breakpoints","size","zoom","foundBreakpoint","find","bp","name","x","margin","width","height","scaledWidth","difference","div","style","transform"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/views/LivePreview/DeviceContainer/index.tsx"],"sourcesContent":["'use client'\nimport React from 'react'\n\nimport { useLivePreviewContext } from '../Context/context.js'\n\nexport const DeviceContainer: React.FC<{\n children: React.ReactNode\n}> = (props) => {\n const { children } = props\n\n const { breakpoint, breakpoints, size, zoom } = useLivePreviewContext()\n\n const foundBreakpoint = breakpoint && breakpoints?.find((bp) => bp.name === breakpoint)\n\n let x = '0'\n let margin = '0'\n\n if (foundBreakpoint && breakpoint !== 'responsive') {\n x = '-50%'\n\n if (\n typeof zoom === 'number' &&\n typeof size.width === 'number' &&\n typeof size.height === 'number'\n ) {\n const scaledWidth = size.width / zoom\n const difference = scaledWidth - size.width\n x = `${difference / 2}px`\n margin = '0 auto'\n }\n }\n\n return (\n <div\n style={{\n height:\n foundBreakpoint && foundBreakpoint?.name !== 'responsive'\n ? `${size?.height / (typeof zoom === 'number' ? zoom : 1)}px`\n : typeof zoom === 'number'\n ? `${100 / zoom}%`\n : '100%',\n margin,\n transform: `translate3d(${x}, 0, 0)`,\n width:\n foundBreakpoint && foundBreakpoint?.name !== 'responsive'\n ? `${size?.width / (typeof zoom === 'number' ? zoom : 1)}px`\n : typeof zoom === 'number'\n ? `${100 / zoom}%`\n : '100%',\n }}\n >\n {children}\n </div>\n )\n}\n"],"names":["React","useLivePreviewContext","DeviceContainer","props","children","breakpoint","breakpoints","size","zoom","foundBreakpoint","find","bp","name","x","margin","width","height","scaledWidth","difference","div","style","transform"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AACA,OAAOA,WAAW,QAAO;AAEzB,SAASC,qBAAqB,QAAQ,wBAAuB;AAE7D,OAAO,MAAMC,kBAER,CAACC;IACJ,MAAM,EAAEC,QAAQ,EAAE,GAAGD;IAErB,MAAM,EAAEE,UAAU,EAAEC,WAAW,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGP;IAEhD,MAAMQ,kBAAkBJ,cAAcC,aAAaI,KAAK,CAACC,KAAOA,GAAGC,IAAI,KAAKP;IAE5E,IAAIQ,IAAI;IACR,IAAIC,SAAS;IAEb,IAAIL,mBAAmBJ,eAAe,cAAc;QAClDQ,IAAI;QAEJ,IACE,OAAOL,SAAS,YAChB,OAAOD,KAAKQ,KAAK,KAAK,YACtB,OAAOR,KAAKS,MAAM,KAAK,UACvB;YACA,MAAMC,cAAcV,KAAKQ,KAAK,GAAGP;YACjC,MAAMU,aAAaD,cAAcV,KAAKQ,KAAK;YAC3CF,IAAI,CAAC,EAAEK,aAAa,EAAE,EAAE,CAAC;YACzBJ,SAAS;QACX;IACF;IAEA,qBACE,KAACK;QACCC,OAAO;YACLJ,QACEP,mBAAmBA,iBAAiBG,SAAS,eACzC,CAAC,EAAEL,MAAMS,SAAU,CAAA,OAAOR,SAAS,WAAWA,OAAO,CAAA,EAAG,EAAE,CAAC,GAC3D,OAAOA,SAAS,WACd,CAAC,EAAE,MAAMA,KAAK,CAAC,CAAC,GAChB;YACRM;YACAO,WAAW,CAAC,YAAY,EAAER,EAAE,OAAO,CAAC;YACpCE,OACEN,mBAAmBA,iBAAiBG,SAAS,eACzC,CAAC,EAAEL,MAAMQ,QAAS,CAAA,OAAOP,SAAS,WAAWA,OAAO,CAAA,EAAG,EAAE,CAAC,GAC1D,OAAOA,SAAS,WACd,CAAC,EAAE,MAAMA,KAAK,CAAC,CAAC,GAChB;QACV;kBAECJ;;AAGP,EAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import React, { forwardRef } from 'react';
|
|
3
4
|
import { useLivePreviewContext } from '../Context/context.js';
|
|
4
5
|
const baseClass = 'live-preview-iframe';
|
|
5
6
|
export const IFrame = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
6
7
|
const { setIframeHasLoaded, url } = props;
|
|
7
8
|
const { zoom } = useLivePreviewContext();
|
|
8
|
-
return /*#__PURE__*/
|
|
9
|
+
return /*#__PURE__*/ _jsx("iframe", {
|
|
9
10
|
className: baseClass,
|
|
10
11
|
onLoad: ()=>{
|
|
11
12
|
setIframeHasLoaded(true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/views/LivePreview/IFrame/index.tsx"],"sourcesContent":["'use client'\nimport React, { forwardRef } from 'react'\n\nimport { useLivePreviewContext } from '../Context/context.js'\nimport './index.scss'\n\nconst baseClass = 'live-preview-iframe'\n\ntype Props = {\n setIframeHasLoaded: (value: boolean) => void\n url: string\n}\n\nexport const IFrame = forwardRef<HTMLIFrameElement, Props>((props, ref) => {\n const { setIframeHasLoaded, url } = props\n\n const { zoom } = useLivePreviewContext()\n\n return (\n <iframe\n className={baseClass}\n onLoad={() => {\n setIframeHasLoaded(true)\n }}\n ref={ref}\n src={url}\n style={{\n transform: typeof zoom === 'number' ? `scale(${zoom}) ` : undefined,\n }}\n title={url}\n />\n )\n})\n"],"names":["React","forwardRef","useLivePreviewContext","baseClass","IFrame","props","ref","setIframeHasLoaded","url","zoom","iframe","className","onLoad","src","style","transform","undefined","title"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/views/LivePreview/IFrame/index.tsx"],"sourcesContent":["'use client'\nimport React, { forwardRef } from 'react'\n\nimport { useLivePreviewContext } from '../Context/context.js'\nimport './index.scss'\n\nconst baseClass = 'live-preview-iframe'\n\ntype Props = {\n setIframeHasLoaded: (value: boolean) => void\n url: string\n}\n\nexport const IFrame = forwardRef<HTMLIFrameElement, Props>((props, ref) => {\n const { setIframeHasLoaded, url } = props\n\n const { zoom } = useLivePreviewContext()\n\n return (\n <iframe\n className={baseClass}\n onLoad={() => {\n setIframeHasLoaded(true)\n }}\n ref={ref}\n src={url}\n style={{\n transform: typeof zoom === 'number' ? `scale(${zoom}) ` : undefined,\n }}\n title={url}\n />\n )\n})\n"],"names":["React","forwardRef","useLivePreviewContext","baseClass","IFrame","props","ref","setIframeHasLoaded","url","zoom","iframe","className","onLoad","src","style","transform","undefined","title"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AACA,OAAOA,SAASC,UAAU,QAAQ,QAAO;AAEzC,SAASC,qBAAqB,QAAQ,wBAAuB;AAG7D,MAAMC,YAAY;AAOlB,OAAO,MAAMC,uBAASH,WAAqC,CAACI,OAAOC;IACjE,MAAM,EAAEC,kBAAkB,EAAEC,GAAG,EAAE,GAAGH;IAEpC,MAAM,EAAEI,IAAI,EAAE,GAAGP;IAEjB,qBACE,KAACQ;QACCC,WAAWR;QACXS,QAAQ;YACNL,mBAAmB;QACrB;QACAD,KAAKA;QACLO,KAAKL;QACLM,OAAO;YACLC,WAAW,OAAON,SAAS,WAAW,CAAC,MAAM,EAAEA,KAAK,EAAE,CAAC,GAAGO;QAC5D;QACAC,OAAOT;;AAGb,GAAE"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { ShimmerEffect } from '@payloadcms/ui/elements/ShimmerEffect';
|
|
3
4
|
import { useAllFormFields } from '@payloadcms/ui/forms/Form';
|
|
4
5
|
import { useDocumentEvents } from '@payloadcms/ui/providers/DocumentEvents';
|
|
@@ -13,7 +14,7 @@ export const LivePreview = (props)=>{
|
|
|
13
14
|
const { appIsReady, iframeHasLoaded, iframeRef, popupRef, previewWindowType, setIframeHasLoaded, url } = useLivePreviewContext();
|
|
14
15
|
const { mostRecentUpdate } = useDocumentEvents();
|
|
15
16
|
const { breakpoint, fieldSchemaJSON } = useLivePreviewContext();
|
|
16
|
-
const prevWindowType = React.useRef();
|
|
17
|
+
const prevWindowType = React.useRef(undefined);
|
|
17
18
|
const [fields] = useAllFormFields();
|
|
18
19
|
// For client-side apps, send data through `window.postMessage`
|
|
19
20
|
// The preview could either be an iframe embedded on the page
|
|
@@ -79,22 +80,32 @@ export const LivePreview = (props)=>{
|
|
|
79
80
|
url
|
|
80
81
|
]);
|
|
81
82
|
if (previewWindowType === 'iframe') {
|
|
82
|
-
return /*#__PURE__*/
|
|
83
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
83
84
|
className: [
|
|
84
85
|
baseClass,
|
|
85
86
|
breakpoint && breakpoint !== 'responsive' && `${baseClass}--has-breakpoint`
|
|
86
|
-
].filter(Boolean).join(' ')
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
].filter(Boolean).join(' '),
|
|
88
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
89
|
+
className: `${baseClass}__wrapper`,
|
|
90
|
+
children: [
|
|
91
|
+
/*#__PURE__*/ _jsx(LivePreviewToolbar, {
|
|
92
|
+
...props
|
|
93
|
+
}),
|
|
94
|
+
/*#__PURE__*/ _jsx("div", {
|
|
95
|
+
className: `${baseClass}__main`,
|
|
96
|
+
children: /*#__PURE__*/ _jsx(DeviceContainer, {
|
|
97
|
+
children: url ? /*#__PURE__*/ _jsx(IFrame, {
|
|
98
|
+
ref: iframeRef,
|
|
99
|
+
setIframeHasLoaded: setIframeHasLoaded,
|
|
100
|
+
url: url
|
|
101
|
+
}) : /*#__PURE__*/ _jsx(ShimmerEffect, {
|
|
102
|
+
height: "100%"
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
})
|
|
108
|
+
});
|
|
98
109
|
}
|
|
99
110
|
};
|
|
100
111
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/views/LivePreview/Preview/index.tsx"],"sourcesContent":["'use client'\n\nimport type { EditViewProps } from 'payload/types'\n\nimport { ShimmerEffect } from '@payloadcms/ui/elements/ShimmerEffect'\nimport { useAllFormFields } from '@payloadcms/ui/forms/Form'\nimport { useDocumentEvents } from '@payloadcms/ui/providers/DocumentEvents'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport React, { useEffect } from 'react'\n\nimport { useLivePreviewContext } from '../Context/context.js'\nimport { DeviceContainer } from '../Device/index.js'\nimport { IFrame } from '../IFrame/index.js'\nimport { LivePreviewToolbar } from '../Toolbar/index.js'\nimport './index.scss'\n\nconst baseClass = 'live-preview-window'\n\nexport const LivePreview: React.FC<EditViewProps> = (props) => {\n const {\n appIsReady,\n iframeHasLoaded,\n iframeRef,\n popupRef,\n previewWindowType,\n setIframeHasLoaded,\n url,\n } = useLivePreviewContext()\n\n const { mostRecentUpdate } = useDocumentEvents()\n\n const { breakpoint, fieldSchemaJSON } = useLivePreviewContext()\n\n const prevWindowType =\n React.useRef<ReturnType<typeof useLivePreviewContext>['previewWindowType']>()\n\n const [fields] = useAllFormFields()\n\n // For client-side apps, send data through `window.postMessage`\n // The preview could either be an iframe embedded on the page\n // Or it could be a separate popup window\n // We need to transmit data to both accordingly\n useEffect(() => {\n // For performance, do no reduce fields to values until after the iframe or popup has loaded\n if (fields && window && 'postMessage' in window && appIsReady) {\n const values = reduceFieldsToValues(fields, true)\n\n // To reduce on large `postMessage` payloads, only send `fieldSchemaToJSON` one time\n // To do this, the underlying JS function maintains a cache of this value\n // So we need to send it through each time the window type changes\n // But only once per window type change, not on every render, because this is a potentially large obj\n const shouldSendSchema =\n !prevWindowType.current || prevWindowType.current !== previewWindowType\n\n prevWindowType.current = previewWindowType\n\n const message = {\n type: 'payload-live-preview',\n data: values,\n externallyUpdatedRelationship: mostRecentUpdate,\n fieldSchemaJSON: shouldSendSchema ? fieldSchemaJSON : undefined,\n }\n\n // Post message to external popup window\n if (previewWindowType === 'popup' && popupRef.current) {\n popupRef.current.postMessage(message, url)\n }\n\n // Post message to embedded iframe\n if (previewWindowType === 'iframe' && iframeRef.current) {\n iframeRef.current.contentWindow?.postMessage(message, url)\n }\n }\n }, [\n fields,\n url,\n iframeHasLoaded,\n previewWindowType,\n popupRef,\n appIsReady,\n iframeRef,\n setIframeHasLoaded,\n fieldSchemaJSON,\n mostRecentUpdate,\n ])\n\n // To support SSR, we transmit a `window.postMessage` event without a payload\n // This is because the event will ultimately trigger a server-side roundtrip\n // i.e., save, save draft, autosave, etc. will fire `router.refresh()`\n useEffect(() => {\n const message = {\n type: 'payload-document-event',\n }\n\n // Post message to external popup window\n if (previewWindowType === 'popup' && popupRef.current) {\n popupRef.current.postMessage(message, url)\n }\n\n // Post message to embedded iframe\n if (previewWindowType === 'iframe' && iframeRef.current) {\n iframeRef.current.contentWindow?.postMessage(message, url)\n }\n }, [mostRecentUpdate, iframeRef, popupRef, previewWindowType, url])\n\n if (previewWindowType === 'iframe') {\n return (\n <div\n className={[\n baseClass,\n breakpoint && breakpoint !== 'responsive' && `${baseClass}--has-breakpoint`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <div className={`${baseClass}__wrapper`}>\n <LivePreviewToolbar {...props} />\n <div className={`${baseClass}__main`}>\n <DeviceContainer>\n {url ? (\n <IFrame ref={iframeRef} setIframeHasLoaded={setIframeHasLoaded} url={url} />\n ) : (\n <ShimmerEffect height=\"100%\" />\n )}\n </DeviceContainer>\n </div>\n </div>\n </div>\n )\n }\n}\n"],"names":["ShimmerEffect","useAllFormFields","useDocumentEvents","reduceFieldsToValues","React","useEffect","useLivePreviewContext","DeviceContainer","IFrame","LivePreviewToolbar","baseClass","LivePreview","props","appIsReady","iframeHasLoaded","iframeRef","popupRef","previewWindowType","setIframeHasLoaded","url","mostRecentUpdate","breakpoint","fieldSchemaJSON","prevWindowType","useRef","fields","window","values","shouldSendSchema","current","message","type","data","externallyUpdatedRelationship","
|
|
1
|
+
{"version":3,"sources":["../../../../src/views/LivePreview/Preview/index.tsx"],"sourcesContent":["'use client'\n\nimport type { EditViewProps } from 'payload/types'\n\nimport { ShimmerEffect } from '@payloadcms/ui/elements/ShimmerEffect'\nimport { useAllFormFields } from '@payloadcms/ui/forms/Form'\nimport { useDocumentEvents } from '@payloadcms/ui/providers/DocumentEvents'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport React, { useEffect } from 'react'\n\nimport { useLivePreviewContext } from '../Context/context.js'\nimport { DeviceContainer } from '../Device/index.js'\nimport { IFrame } from '../IFrame/index.js'\nimport { LivePreviewToolbar } from '../Toolbar/index.js'\nimport './index.scss'\n\nconst baseClass = 'live-preview-window'\n\nexport const LivePreview: React.FC<EditViewProps> = (props) => {\n const {\n appIsReady,\n iframeHasLoaded,\n iframeRef,\n popupRef,\n previewWindowType,\n setIframeHasLoaded,\n url,\n } = useLivePreviewContext()\n\n const { mostRecentUpdate } = useDocumentEvents()\n\n const { breakpoint, fieldSchemaJSON } = useLivePreviewContext()\n\n const prevWindowType =\n React.useRef<ReturnType<typeof useLivePreviewContext>['previewWindowType']>(undefined)\n\n const [fields] = useAllFormFields()\n\n // For client-side apps, send data through `window.postMessage`\n // The preview could either be an iframe embedded on the page\n // Or it could be a separate popup window\n // We need to transmit data to both accordingly\n useEffect(() => {\n // For performance, do no reduce fields to values until after the iframe or popup has loaded\n if (fields && window && 'postMessage' in window && appIsReady) {\n const values = reduceFieldsToValues(fields, true)\n\n // To reduce on large `postMessage` payloads, only send `fieldSchemaToJSON` one time\n // To do this, the underlying JS function maintains a cache of this value\n // So we need to send it through each time the window type changes\n // But only once per window type change, not on every render, because this is a potentially large obj\n const shouldSendSchema =\n !prevWindowType.current || prevWindowType.current !== previewWindowType\n\n prevWindowType.current = previewWindowType\n\n const message = {\n type: 'payload-live-preview',\n data: values,\n externallyUpdatedRelationship: mostRecentUpdate,\n fieldSchemaJSON: shouldSendSchema ? fieldSchemaJSON : undefined,\n }\n\n // Post message to external popup window\n if (previewWindowType === 'popup' && popupRef.current) {\n popupRef.current.postMessage(message, url)\n }\n\n // Post message to embedded iframe\n if (previewWindowType === 'iframe' && iframeRef.current) {\n iframeRef.current.contentWindow?.postMessage(message, url)\n }\n }\n }, [\n fields,\n url,\n iframeHasLoaded,\n previewWindowType,\n popupRef,\n appIsReady,\n iframeRef,\n setIframeHasLoaded,\n fieldSchemaJSON,\n mostRecentUpdate,\n ])\n\n // To support SSR, we transmit a `window.postMessage` event without a payload\n // This is because the event will ultimately trigger a server-side roundtrip\n // i.e., save, save draft, autosave, etc. will fire `router.refresh()`\n useEffect(() => {\n const message = {\n type: 'payload-document-event',\n }\n\n // Post message to external popup window\n if (previewWindowType === 'popup' && popupRef.current) {\n popupRef.current.postMessage(message, url)\n }\n\n // Post message to embedded iframe\n if (previewWindowType === 'iframe' && iframeRef.current) {\n iframeRef.current.contentWindow?.postMessage(message, url)\n }\n }, [mostRecentUpdate, iframeRef, popupRef, previewWindowType, url])\n\n if (previewWindowType === 'iframe') {\n return (\n <div\n className={[\n baseClass,\n breakpoint && breakpoint !== 'responsive' && `${baseClass}--has-breakpoint`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <div className={`${baseClass}__wrapper`}>\n <LivePreviewToolbar {...props} />\n <div className={`${baseClass}__main`}>\n <DeviceContainer>\n {url ? (\n <IFrame ref={iframeRef} setIframeHasLoaded={setIframeHasLoaded} url={url} />\n ) : (\n <ShimmerEffect height=\"100%\" />\n )}\n </DeviceContainer>\n </div>\n </div>\n </div>\n )\n }\n}\n"],"names":["ShimmerEffect","useAllFormFields","useDocumentEvents","reduceFieldsToValues","React","useEffect","useLivePreviewContext","DeviceContainer","IFrame","LivePreviewToolbar","baseClass","LivePreview","props","appIsReady","iframeHasLoaded","iframeRef","popupRef","previewWindowType","setIframeHasLoaded","url","mostRecentUpdate","breakpoint","fieldSchemaJSON","prevWindowType","useRef","undefined","fields","window","values","shouldSendSchema","current","message","type","data","externallyUpdatedRelationship","postMessage","contentWindow","div","className","filter","Boolean","join","ref","height"],"rangeMappings":";;;;;;;;;;;;;;;;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