@payloadcms/next 3.0.0-beta.84 → 3.0.0-beta.85
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/prod/styles.css +1 -1
- package/dist/utilities/meta.js +4 -1
- package/dist/utilities/meta.js.map +1 -1
- package/dist/views/API/meta.d.ts.map +1 -1
- package/dist/views/API/meta.js +10 -6
- package/dist/views/API/meta.js.map +1 -1
- package/dist/views/Document/getCustomViewByRoute.d.ts +4 -1
- package/dist/views/Document/getCustomViewByRoute.d.ts.map +1 -1
- package/dist/views/Document/getCustomViewByRoute.js +16 -6
- package/dist/views/Document/getCustomViewByRoute.js.map +1 -1
- package/dist/views/Document/getMetaBySegment.d.ts +2 -1
- package/dist/views/Document/getMetaBySegment.d.ts.map +1 -1
- package/dist/views/Document/getMetaBySegment.js +73 -28
- package/dist/views/Document/getMetaBySegment.js.map +1 -1
- package/dist/views/Document/getViewsFromConfig.d.ts +9 -3
- package/dist/views/Document/getViewsFromConfig.d.ts.map +1 -1
- package/dist/views/Document/getViewsFromConfig.js +91 -47
- package/dist/views/Document/getViewsFromConfig.js.map +1 -1
- package/dist/views/Edit/meta.d.ts.map +1 -1
- package/dist/views/Edit/meta.js +30 -19
- package/dist/views/Edit/meta.js.map +1 -1
- package/dist/views/LivePreview/meta.d.ts.map +1 -1
- package/dist/views/LivePreview/meta.js +2 -1
- package/dist/views/LivePreview/meta.js.map +1 -1
- package/dist/views/Root/generateCustomViewMetadata.d.ts +11 -0
- package/dist/views/Root/generateCustomViewMetadata.d.ts.map +1 -0
- package/dist/views/Root/generateCustomViewMetadata.js +23 -0
- package/dist/views/Root/generateCustomViewMetadata.js.map +1 -0
- package/dist/views/Root/getCustomViewByRoute.d.ts +6 -2
- package/dist/views/Root/getCustomViewByRoute.d.ts.map +1 -1
- package/dist/views/Root/getCustomViewByRoute.js +20 -5
- package/dist/views/Root/getCustomViewByRoute.js.map +1 -1
- package/dist/views/Root/getViewFromConfig.d.ts.map +1 -1
- package/dist/views/Root/getViewFromConfig.js +7 -7
- package/dist/views/Root/getViewFromConfig.js.map +1 -1
- package/dist/views/Root/meta.d.ts.map +1 -1
- package/dist/views/Root/meta.js +19 -2
- package/dist/views/Root/meta.js.map +1 -1
- package/dist/views/Version/meta.d.ts.map +1 -1
- package/dist/views/Version/meta.js +24 -19
- package/dist/views/Version/meta.js.map +1 -1
- package/dist/views/Versions/meta.d.ts.map +1 -1
- package/dist/views/Versions/meta.js +24 -19
- package/dist/views/Versions/meta.js.map +1 -1
- package/package.json +6 -6
|
@@ -7,17 +7,18 @@ import { VersionView as DefaultVersionView } from '../Version/index.js';
|
|
|
7
7
|
import { VersionsView as DefaultVersionsView } from '../Versions/index.js';
|
|
8
8
|
import { getCustomViewByKey } from './getCustomViewByKey.js';
|
|
9
9
|
import { getCustomViewByRoute } from './getCustomViewByRoute.js';
|
|
10
|
-
export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, globalConfig, routeSegments })=>{
|
|
10
|
+
export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, globalConfig, overrideDocPermissions, routeSegments })=>{
|
|
11
11
|
// Conditionally import and lazy load the default view
|
|
12
12
|
let DefaultView = null;
|
|
13
13
|
let CustomView = null;
|
|
14
14
|
let ErrorView = null;
|
|
15
|
+
let viewKey;
|
|
15
16
|
const { routes: { admin: adminRoute } } = config;
|
|
16
17
|
const views = collectionConfig && collectionConfig?.admin?.components?.views || globalConfig && globalConfig?.admin?.components?.views;
|
|
17
18
|
const livePreviewEnabled = collectionConfig && collectionConfig?.admin?.livePreview || config?.admin?.livePreview?.collections?.includes(collectionConfig?.slug) || globalConfig && globalConfig?.admin?.livePreview || config?.admin?.livePreview?.globals?.includes(globalConfig?.slug);
|
|
18
19
|
if (collectionConfig) {
|
|
19
20
|
const [collectionEntity, collectionSlug, segment3, segment4, segment5, ...remainingSegments] = routeSegments;
|
|
20
|
-
if (!docPermissions?.read?.permission) {
|
|
21
|
+
if (!overrideDocPermissions && !docPermissions?.read?.permission) {
|
|
21
22
|
notFound();
|
|
22
23
|
} else {
|
|
23
24
|
// `../:id`, or `../create`
|
|
@@ -27,7 +28,7 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
27
28
|
switch(segment3){
|
|
28
29
|
case 'create':
|
|
29
30
|
{
|
|
30
|
-
if ('create' in docPermissions && docPermissions?.create?.permission) {
|
|
31
|
+
if (!overrideDocPermissions && 'create' in docPermissions && docPermissions?.create?.permission) {
|
|
31
32
|
CustomView = {
|
|
32
33
|
payloadComponent: getCustomViewByKey(views, 'default')
|
|
33
34
|
};
|
|
@@ -43,12 +44,37 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
43
44
|
}
|
|
44
45
|
default:
|
|
45
46
|
{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
const baseRoute = [
|
|
48
|
+
adminRoute !== '/' && adminRoute,
|
|
49
|
+
'collections',
|
|
50
|
+
collectionSlug,
|
|
51
|
+
segment3
|
|
52
|
+
].filter(Boolean).join('/');
|
|
53
|
+
const currentRoute = [
|
|
54
|
+
baseRoute,
|
|
55
|
+
segment4,
|
|
56
|
+
segment5,
|
|
57
|
+
...remainingSegments
|
|
58
|
+
].filter(Boolean).join('/');
|
|
59
|
+
const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute({
|
|
60
|
+
baseRoute,
|
|
61
|
+
currentRoute,
|
|
62
|
+
views
|
|
63
|
+
});
|
|
64
|
+
console.log('CustomViewComponent', customViewKey);
|
|
65
|
+
if (customViewKey) {
|
|
66
|
+
viewKey = customViewKey;
|
|
67
|
+
CustomView = {
|
|
68
|
+
payloadComponent: CustomViewComponent
|
|
69
|
+
};
|
|
70
|
+
} else {
|
|
71
|
+
CustomView = {
|
|
72
|
+
payloadComponent: getCustomViewByKey(views, 'default')
|
|
73
|
+
};
|
|
74
|
+
DefaultView = {
|
|
75
|
+
Component: DefaultEditView
|
|
76
|
+
};
|
|
77
|
+
}
|
|
52
78
|
break;
|
|
53
79
|
}
|
|
54
80
|
}
|
|
@@ -81,7 +107,7 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
81
107
|
}
|
|
82
108
|
case 'versions':
|
|
83
109
|
{
|
|
84
|
-
if (docPermissions?.readVersions?.permission) {
|
|
110
|
+
if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {
|
|
85
111
|
CustomView = {
|
|
86
112
|
payloadComponent: getCustomViewByKey(views, 'versions')
|
|
87
113
|
};
|
|
@@ -109,13 +135,17 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
109
135
|
segment5,
|
|
110
136
|
...remainingSegments
|
|
111
137
|
].filter(Boolean).join('/');
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute({
|
|
139
|
+
baseRoute,
|
|
140
|
+
currentRoute,
|
|
141
|
+
views
|
|
142
|
+
});
|
|
143
|
+
if (customViewKey) {
|
|
144
|
+
viewKey = customViewKey;
|
|
145
|
+
CustomView = {
|
|
146
|
+
payloadComponent: CustomViewComponent
|
|
147
|
+
};
|
|
148
|
+
}
|
|
119
149
|
break;
|
|
120
150
|
}
|
|
121
151
|
}
|
|
@@ -125,7 +155,7 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
125
155
|
default:
|
|
126
156
|
{
|
|
127
157
|
if (segment4 === 'versions') {
|
|
128
|
-
if (docPermissions?.readVersions?.permission) {
|
|
158
|
+
if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {
|
|
129
159
|
CustomView = {
|
|
130
160
|
payloadComponent: getCustomViewByKey(views, 'version')
|
|
131
161
|
};
|
|
@@ -150,13 +180,17 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
150
180
|
segment5,
|
|
151
181
|
...remainingSegments
|
|
152
182
|
].filter(Boolean).join('/');
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
183
|
+
const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute({
|
|
184
|
+
baseRoute,
|
|
185
|
+
currentRoute,
|
|
186
|
+
views
|
|
187
|
+
});
|
|
188
|
+
if (customViewKey) {
|
|
189
|
+
viewKey = customViewKey;
|
|
190
|
+
CustomView = {
|
|
191
|
+
payloadComponent: CustomViewComponent
|
|
192
|
+
};
|
|
193
|
+
}
|
|
160
194
|
}
|
|
161
195
|
break;
|
|
162
196
|
}
|
|
@@ -165,7 +199,7 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
165
199
|
}
|
|
166
200
|
if (globalConfig) {
|
|
167
201
|
const [globalEntity, globalSlug, segment3, ...remainingSegments] = routeSegments;
|
|
168
|
-
if (!docPermissions?.read?.permission) {
|
|
202
|
+
if (!overrideDocPermissions && !docPermissions?.read?.permission) {
|
|
169
203
|
notFound();
|
|
170
204
|
} else {
|
|
171
205
|
switch(routeSegments.length){
|
|
@@ -206,7 +240,7 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
206
240
|
}
|
|
207
241
|
case 'versions':
|
|
208
242
|
{
|
|
209
|
-
if (docPermissions?.readVersions?.permission) {
|
|
243
|
+
if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {
|
|
210
244
|
CustomView = {
|
|
211
245
|
payloadComponent: getCustomViewByKey(views, 'versions')
|
|
212
246
|
};
|
|
@@ -222,7 +256,7 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
222
256
|
}
|
|
223
257
|
default:
|
|
224
258
|
{
|
|
225
|
-
if (docPermissions?.read?.permission) {
|
|
259
|
+
if (!overrideDocPermissions && docPermissions?.read?.permission) {
|
|
226
260
|
const baseRoute = [
|
|
227
261
|
adminRoute,
|
|
228
262
|
globalEntity,
|
|
@@ -234,16 +268,21 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
234
268
|
segment3,
|
|
235
269
|
...remainingSegments
|
|
236
270
|
].filter(Boolean).join('/');
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
271
|
+
const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute({
|
|
272
|
+
baseRoute,
|
|
273
|
+
currentRoute,
|
|
274
|
+
views
|
|
275
|
+
});
|
|
276
|
+
if (customViewKey) {
|
|
277
|
+
viewKey = customViewKey;
|
|
278
|
+
CustomView = {
|
|
279
|
+
payloadComponent: CustomViewComponent
|
|
280
|
+
};
|
|
281
|
+
} else {
|
|
282
|
+
DefaultView = {
|
|
283
|
+
Component: DefaultEditView
|
|
284
|
+
};
|
|
285
|
+
}
|
|
247
286
|
} else {
|
|
248
287
|
ErrorView = {
|
|
249
288
|
Component: UnauthorizedView
|
|
@@ -258,7 +297,7 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
258
297
|
{
|
|
259
298
|
// `../:slug/versions/:version`, etc
|
|
260
299
|
if (segment3 === 'versions') {
|
|
261
|
-
if (docPermissions?.readVersions?.permission) {
|
|
300
|
+
if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {
|
|
262
301
|
CustomView = {
|
|
263
302
|
payloadComponent: getCustomViewByKey(views, 'version')
|
|
264
303
|
};
|
|
@@ -281,13 +320,17 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
281
320
|
segment3,
|
|
282
321
|
...remainingSegments
|
|
283
322
|
].filter(Boolean).join('/');
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
323
|
+
const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute({
|
|
324
|
+
baseRoute,
|
|
325
|
+
currentRoute,
|
|
326
|
+
views
|
|
327
|
+
});
|
|
328
|
+
if (customViewKey) {
|
|
329
|
+
viewKey = customViewKey;
|
|
330
|
+
CustomView = {
|
|
331
|
+
payloadComponent: CustomViewComponent
|
|
332
|
+
};
|
|
333
|
+
}
|
|
291
334
|
}
|
|
292
335
|
break;
|
|
293
336
|
}
|
|
@@ -297,7 +340,8 @@ export const getViewsFromConfig = ({ collectionConfig, config, docPermissions, g
|
|
|
297
340
|
return {
|
|
298
341
|
CustomView,
|
|
299
342
|
DefaultView,
|
|
300
|
-
ErrorView
|
|
343
|
+
ErrorView,
|
|
344
|
+
viewKey
|
|
301
345
|
};
|
|
302
346
|
};
|
|
303
347
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/Document/getViewsFromConfig.tsx"],"sourcesContent":["import type {\n AdminViewProps,\n CollectionPermission,\n GlobalPermission,\n PayloadComponent,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n ServerSideEditViewProps,\n} from 'payload'\nimport type React from 'react'\n\nimport { notFound } from 'next/navigation.js'\n\nimport { APIView as DefaultAPIView } from '../API/index.js'\nimport { EditView as DefaultEditView } from '../Edit/index.js'\nimport { LivePreviewView as DefaultLivePreviewView } from '../LivePreview/index.js'\nimport { UnauthorizedView } from '../Unauthorized/index.js'\nimport { VersionView as DefaultVersionView } from '../Version/index.js'\nimport { VersionsView as DefaultVersionsView } from '../Versions/index.js'\nimport { getCustomViewByKey } from './getCustomViewByKey.js'\nimport { getCustomViewByRoute } from './getCustomViewByRoute.js'\n\nexport type ViewFromConfig<TProps extends object> = {\n Component?: React.FC<TProps>\n payloadComponent?: PayloadComponent<TProps>\n}\n\nexport const getViewsFromConfig = ({\n collectionConfig,\n config,\n docPermissions,\n globalConfig,\n routeSegments,\n}: {\n collectionConfig?: SanitizedCollectionConfig\n config: SanitizedConfig\n docPermissions: CollectionPermission | GlobalPermission\n globalConfig?: SanitizedGlobalConfig\n routeSegments: string[]\n}): {\n CustomView: ViewFromConfig<ServerSideEditViewProps>\n DefaultView: ViewFromConfig<ServerSideEditViewProps>\n /**\n * The error view to display if CustomView or DefaultView do not exist (could be either due to not found, or unauthorized). Can be null\n */\n ErrorView: ViewFromConfig<AdminViewProps>\n} | null => {\n // Conditionally import and lazy load the default view\n let DefaultView: ViewFromConfig<ServerSideEditViewProps> = null\n let CustomView: ViewFromConfig<ServerSideEditViewProps> = null\n let ErrorView: ViewFromConfig<AdminViewProps> = null\n\n const {\n routes: { admin: adminRoute },\n } = config\n\n const views =\n (collectionConfig && collectionConfig?.admin?.components?.views) ||\n (globalConfig && globalConfig?.admin?.components?.views)\n\n const livePreviewEnabled =\n (collectionConfig && collectionConfig?.admin?.livePreview) ||\n config?.admin?.livePreview?.collections?.includes(collectionConfig?.slug) ||\n (globalConfig && globalConfig?.admin?.livePreview) ||\n config?.admin?.livePreview?.globals?.includes(globalConfig?.slug)\n\n if (collectionConfig) {\n const [collectionEntity, collectionSlug, segment3, segment4, segment5, ...remainingSegments] =\n routeSegments\n\n if (!docPermissions?.read?.permission) {\n notFound()\n } else {\n // `../:id`, or `../create`\n switch (routeSegments.length) {\n case 3: {\n switch (segment3) {\n case 'create': {\n if ('create' in docPermissions && docPermissions?.create?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n break\n }\n }\n break\n }\n\n // `../:id/api`, `../:id/preview`, `../:id/versions`, etc\n case 4: {\n switch (segment4) {\n case 'api': {\n if (collectionConfig?.admin?.hideAPIURL !== true) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'api'),\n }\n DefaultView = {\n Component: DefaultAPIView,\n }\n }\n break\n }\n\n case 'preview': {\n if (livePreviewEnabled) {\n DefaultView = {\n Component: DefaultLivePreviewView,\n }\n }\n break\n }\n\n case 'versions': {\n if (docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'versions'),\n }\n DefaultView = {\n Component: DefaultVersionsView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n 'collections',\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n CustomView = {\n payloadComponent: getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n }),\n }\n break\n }\n }\n break\n }\n\n // `../:id/versions/:version`, etc\n default: {\n if (segment4 === 'versions') {\n if (docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'version'),\n }\n DefaultView = {\n Component: DefaultVersionView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n } else {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n collectionEntity,\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n CustomView = {\n payloadComponent: getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n }),\n }\n }\n break\n }\n }\n }\n }\n\n if (globalConfig) {\n const [globalEntity, globalSlug, segment3, ...remainingSegments] = routeSegments\n\n if (!docPermissions?.read?.permission) {\n notFound()\n } else {\n switch (routeSegments.length) {\n case 2: {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n break\n }\n\n case 3: {\n // `../:slug/api`, `../:slug/preview`, `../:slug/versions`, etc\n switch (segment3) {\n case 'api': {\n if (globalConfig?.admin?.hideAPIURL !== true) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'api'),\n }\n DefaultView = {\n Component: DefaultAPIView,\n }\n }\n break\n }\n\n case 'preview': {\n if (livePreviewEnabled) {\n DefaultView = {\n Component: DefaultLivePreviewView,\n }\n }\n break\n }\n\n case 'versions': {\n if (docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'versions'),\n }\n DefaultView = {\n Component: DefaultVersionsView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n if (docPermissions?.read?.permission) {\n const baseRoute = [adminRoute, globalEntity, globalSlug, segment3]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment3, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n CustomView = {\n payloadComponent: getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n }),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n }\n break\n }\n\n default: {\n // `../:slug/versions/:version`, etc\n if (segment3 === 'versions') {\n if (docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'version'),\n }\n DefaultView = {\n Component: DefaultVersionView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n } else {\n const baseRoute = [adminRoute !== '/' && adminRoute, 'globals', globalSlug]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment3, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n CustomView = {\n payloadComponent: getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n }),\n }\n }\n break\n }\n }\n }\n }\n\n return {\n CustomView,\n DefaultView,\n ErrorView,\n }\n}\n"],"names":["notFound","APIView","DefaultAPIView","EditView","DefaultEditView","LivePreviewView","DefaultLivePreviewView","UnauthorizedView","VersionView","DefaultVersionView","VersionsView","DefaultVersionsView","getCustomViewByKey","getCustomViewByRoute","getViewsFromConfig","collectionConfig","config","docPermissions","globalConfig","routeSegments","DefaultView","CustomView","ErrorView","routes","admin","adminRoute","views","components","livePreviewEnabled","livePreview","collections","includes","slug","globals","collectionEntity","collectionSlug","segment3","segment4","segment5","remainingSegments","read","permission","length","create","payloadComponent","Component","hideAPIURL","readVersions","baseRoute","filter","Boolean","join","currentRoute","globalEntity","globalSlug"],"mappings":"AAYA,SAASA,QAAQ,QAAQ,qBAAoB;AAE7C,SAASC,WAAWC,cAAc,QAAQ,kBAAiB;AAC3D,SAASC,YAAYC,eAAe,QAAQ,mBAAkB;AAC9D,SAASC,mBAAmBC,sBAAsB,QAAQ,0BAAyB;AACnF,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,eAAeC,kBAAkB,QAAQ,sBAAqB;AACvE,SAASC,gBAAgBC,mBAAmB,QAAQ,uBAAsB;AAC1E,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,oBAAoB,QAAQ,4BAA2B;AAOhE,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,gBAAgB,EAChBC,MAAM,EACNC,cAAc,EACdC,YAAY,EACZC,aAAa,EAOd;IAQC,sDAAsD;IACtD,IAAIC,cAAuD;IAC3D,IAAIC,aAAsD;IAC1D,IAAIC,YAA4C;IAEhD,MAAM,EACJC,QAAQ,EAAEC,OAAOC,UAAU,EAAE,EAC9B,GAAGT;IAEJ,MAAMU,QACJ,AAACX,oBAAoBA,kBAAkBS,OAAOG,YAAYD,SACzDR,gBAAgBA,cAAcM,OAAOG,YAAYD;IAEpD,MAAME,qBACJ,AAACb,oBAAoBA,kBAAkBS,OAAOK,eAC9Cb,QAAQQ,OAAOK,aAAaC,aAAaC,SAAShB,kBAAkBiB,SACnEd,gBAAgBA,cAAcM,OAAOK,eACtCb,QAAQQ,OAAOK,aAAaI,SAASF,SAASb,cAAcc;I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EL,MAAM,CAACC,SACPC,IAAI,CAAC;4BAER,MAAMC,eAAe;gCAACJ;gCAAWZ;mCAAaG;6BAAkB,CAC7DU,MAAM,CAACC,SACPC,IAAI,CAAC;4BAER9B,aAAa;gCACXuB,kBAAkB/B,qBAAqB;oCACrCmC;oCACAI;oCACA1B;gCACF;4BACF;wBACF;wBACA;oBACF;YACF;QACF;IACF;IAEA,OAAO;QACLL;QACAD;QACAE;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/views/Document/getViewsFromConfig.tsx"],"sourcesContent":["import type {\n AdminViewProps,\n CollectionPermission,\n GlobalPermission,\n PayloadComponent,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n ServerSideEditViewProps,\n} from 'payload'\nimport type React from 'react'\n\nimport { notFound } from 'next/navigation.js'\n\nimport { APIView as DefaultAPIView } from '../API/index.js'\nimport { EditView as DefaultEditView } from '../Edit/index.js'\nimport { LivePreviewView as DefaultLivePreviewView } from '../LivePreview/index.js'\nimport { UnauthorizedView } from '../Unauthorized/index.js'\nimport { VersionView as DefaultVersionView } from '../Version/index.js'\nimport { VersionsView as DefaultVersionsView } from '../Versions/index.js'\nimport { getCustomViewByKey } from './getCustomViewByKey.js'\nimport { getCustomViewByRoute } from './getCustomViewByRoute.js'\n\nexport type ViewFromConfig<TProps extends object> = {\n Component?: React.FC<TProps>\n payloadComponent?: PayloadComponent<TProps>\n}\n\nexport const getViewsFromConfig = ({\n collectionConfig,\n config,\n docPermissions,\n globalConfig,\n overrideDocPermissions,\n routeSegments,\n}: {\n collectionConfig?: SanitizedCollectionConfig\n config: SanitizedConfig\n globalConfig?: SanitizedGlobalConfig\n routeSegments: string[]\n} & (\n | {\n docPermissions: CollectionPermission | GlobalPermission\n overrideDocPermissions?: false | undefined\n }\n | {\n docPermissions?: never\n overrideDocPermissions: true\n }\n)): {\n CustomView: ViewFromConfig<ServerSideEditViewProps>\n DefaultView: ViewFromConfig<ServerSideEditViewProps>\n /**\n * The error view to display if CustomView or DefaultView do not exist (could be either due to not found, or unauthorized). Can be null\n */\n ErrorView: ViewFromConfig<AdminViewProps>\n viewKey: string\n} | null => {\n // Conditionally import and lazy load the default view\n let DefaultView: ViewFromConfig<ServerSideEditViewProps> = null\n let CustomView: ViewFromConfig<ServerSideEditViewProps> = null\n let ErrorView: ViewFromConfig<AdminViewProps> = null\n let viewKey: string\n\n const {\n routes: { admin: adminRoute },\n } = config\n\n const views =\n (collectionConfig && collectionConfig?.admin?.components?.views) ||\n (globalConfig && globalConfig?.admin?.components?.views)\n\n const livePreviewEnabled =\n (collectionConfig && collectionConfig?.admin?.livePreview) ||\n config?.admin?.livePreview?.collections?.includes(collectionConfig?.slug) ||\n (globalConfig && globalConfig?.admin?.livePreview) ||\n config?.admin?.livePreview?.globals?.includes(globalConfig?.slug)\n\n if (collectionConfig) {\n const [collectionEntity, collectionSlug, segment3, segment4, segment5, ...remainingSegments] =\n routeSegments\n\n if (!overrideDocPermissions && !docPermissions?.read?.permission) {\n notFound()\n } else {\n // `../:id`, or `../create`\n switch (routeSegments.length) {\n case 3: {\n switch (segment3) {\n case 'create': {\n if (\n !overrideDocPermissions &&\n 'create' in docPermissions &&\n docPermissions?.create?.permission\n ) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n 'collections',\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } =\n getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n })\n\n console.log('CustomViewComponent', customViewKey)\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n } else {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n\n DefaultView = {\n Component: DefaultEditView,\n }\n }\n\n break\n }\n }\n break\n }\n\n // `../:id/api`, `../:id/preview`, `../:id/versions`, etc\n case 4: {\n switch (segment4) {\n case 'api': {\n if (collectionConfig?.admin?.hideAPIURL !== true) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'api'),\n }\n DefaultView = {\n Component: DefaultAPIView,\n }\n }\n break\n }\n\n case 'preview': {\n if (livePreviewEnabled) {\n DefaultView = {\n Component: DefaultLivePreviewView,\n }\n }\n break\n }\n\n case 'versions': {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'versions'),\n }\n DefaultView = {\n Component: DefaultVersionsView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n 'collections',\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } =\n getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n })\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n }\n\n break\n }\n }\n break\n }\n\n // `../:id/versions/:version`, etc\n default: {\n if (segment4 === 'versions') {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'version'),\n }\n DefaultView = {\n Component: DefaultVersionView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n } else {\n const baseRoute = [\n adminRoute !== '/' && adminRoute,\n collectionEntity,\n collectionSlug,\n segment3,\n ]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment4, segment5, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute(\n {\n baseRoute,\n currentRoute,\n views,\n },\n )\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n }\n }\n\n break\n }\n }\n }\n }\n\n if (globalConfig) {\n const [globalEntity, globalSlug, segment3, ...remainingSegments] = routeSegments\n\n if (!overrideDocPermissions && !docPermissions?.read?.permission) {\n notFound()\n } else {\n switch (routeSegments.length) {\n case 2: {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'default'),\n }\n DefaultView = {\n Component: DefaultEditView,\n }\n break\n }\n\n case 3: {\n // `../:slug/api`, `../:slug/preview`, `../:slug/versions`, etc\n switch (segment3) {\n case 'api': {\n if (globalConfig?.admin?.hideAPIURL !== true) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'api'),\n }\n DefaultView = {\n Component: DefaultAPIView,\n }\n }\n break\n }\n\n case 'preview': {\n if (livePreviewEnabled) {\n DefaultView = {\n Component: DefaultLivePreviewView,\n }\n }\n break\n }\n\n case 'versions': {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'versions'),\n }\n\n DefaultView = {\n Component: DefaultVersionsView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n\n default: {\n if (!overrideDocPermissions && docPermissions?.read?.permission) {\n const baseRoute = [adminRoute, globalEntity, globalSlug, segment3]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment3, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } =\n getCustomViewByRoute({\n baseRoute,\n currentRoute,\n views,\n })\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n } else {\n DefaultView = {\n Component: DefaultEditView,\n }\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n break\n }\n }\n break\n }\n\n default: {\n // `../:slug/versions/:version`, etc\n if (segment3 === 'versions') {\n if (!overrideDocPermissions && docPermissions?.readVersions?.permission) {\n CustomView = {\n payloadComponent: getCustomViewByKey(views, 'version'),\n }\n DefaultView = {\n Component: DefaultVersionView,\n }\n } else {\n ErrorView = {\n Component: UnauthorizedView,\n }\n }\n } else {\n const baseRoute = [adminRoute !== '/' && adminRoute, 'globals', globalSlug]\n .filter(Boolean)\n .join('/')\n\n const currentRoute = [baseRoute, segment3, ...remainingSegments]\n .filter(Boolean)\n .join('/')\n\n const { Component: CustomViewComponent, viewKey: customViewKey } = getCustomViewByRoute(\n {\n baseRoute,\n currentRoute,\n views,\n },\n )\n\n if (customViewKey) {\n viewKey = customViewKey\n\n CustomView = {\n payloadComponent: CustomViewComponent,\n }\n }\n }\n\n break\n }\n }\n }\n }\n\n return {\n CustomView,\n DefaultView,\n ErrorView,\n viewKey,\n }\n}\n"],"names":["notFound","APIView","DefaultAPIView","EditView","DefaultEditView","LivePreviewView","DefaultLivePreviewView","UnauthorizedView","VersionView","DefaultVersionView","VersionsView","DefaultVersionsView","getCustomViewByKey","getCustomViewByRoute","getViewsFromConfig","collectionConfig","config","docPermissions","globalConfig","overrideDocPermissions","routeSegments","DefaultView","CustomView","ErrorView","viewKey","routes","admin","adminRoute","views","components","livePreviewEnabled","livePreview","collections","includes","slug","globals","collectionEntity","collectionSlug","segment3","segment4","segment5","remainingSegments","read","permission","length","create","payloadComponent","Component","baseRoute","filter","Boolean","join","currentRoute","CustomViewComponent","customViewKey","console","log","hideAPIURL","readVersions","globalEntity","globalSlug"],"mappings":"AAYA,SAASA,QAAQ,QAAQ,qBAAoB;AAE7C,SAASC,WAAWC,cAAc,QAAQ,kBAAiB;AAC3D,SAASC,YAAYC,eAAe,QAAQ,mBAAkB;AAC9D,SAASC,mBAAmBC,sBAAsB,QAAQ,0BAAyB;AACnF,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D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DACZ0B,WAAW3C;4CACb;wCACF;oCACF,OAAO;wCACLmB,YAAY;4CACVwB,WAAWxC;wCACb;oCACF;oCACA;gCACF;wBACF;wBACA;oBACF;gBAEA;oBAAS;wBACP,oCAAoC;wBACpC,IAAI+B,aAAa,YAAY;4BAC3B,IAAI,CAACnB,0BAA0BF,gBAAgByC,cAAcf,YAAY;gCACvErB,aAAa;oCACXwB,kBAAkBlC,mBAAmBgB,OAAO;gCAC9C;gCACAP,cAAc;oCACZ0B,WAAWtC;gCACb;4BACF,OAAO;gCACLc,YAAY;oCACVwB,WAAWxC;gCACb;4BACF;wBACF,OAAO;4BACL,MAAMyC,YAAY;gCAACrB,eAAe,OAAOA;gCAAY;gCAAWiC;6BAAW,CACxEX,MAAM,CAACC,SACPC,IAAI,CAAC;4BAER,MAAMC,eAAe;gCAACJ;gCAAWV;mCAAaG;6BAAkB,CAC7DQ,MAAM,CAACC,SACPC,IAAI,CAAC;4BAER,MAAM,EAAEJ,WAAWM,mBAAmB,EAAE7B,SAAS8B,aAAa,EAAE,GAAGzC,qBACjE;gCACEmC;gCACAI;gCACAxB;4BACF;4BAGF,IAAI0B,eAAe;gCACjB9B,UAAU8B;gCAEVhC,aAAa;oCACXwB,kBAAkBO;gCACpB;4BACF;wBACF;wBAEA;oBACF;YACF;QACF;IACF;IAEA,OAAO;QACL/B;QACAD;QACAE;QACAC;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../src/views/Edit/meta.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../src/views/Edit/meta.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAI/E,eAAO,MAAM,gBAAgB,EAAE,wBAyD9B,CAAA"}
|
package/dist/views/Edit/meta.js
CHANGED
|
@@ -1,27 +1,38 @@
|
|
|
1
1
|
import { getTranslation } from '@payloadcms/translations';
|
|
2
2
|
import { meta } from '../../utilities/meta.js';
|
|
3
|
-
export const generateMetadata = async ({ collectionConfig, config, globalConfig, i18n, isEditing })=>{
|
|
3
|
+
export const generateMetadata = async ({ collectionConfig, config, globalConfig, i18n, isEditing, view = 'default' })=>{
|
|
4
4
|
const { t } = i18n;
|
|
5
5
|
const entityLabel = collectionConfig ? getTranslation(collectionConfig.labels.singular, i18n) : globalConfig ? getTranslation(globalConfig.label, i18n) : '';
|
|
6
|
-
const
|
|
7
|
-
const ogTitle = `${isEditing ? t('general:edit') : t('general:edit')} - ${entityLabel}`;
|
|
8
|
-
const description = `${isEditing ? t('general:editing') : t('general:creating')} - ${entityLabel}`;
|
|
9
|
-
const keywords = `${entityLabel}, Payload, CMS`;
|
|
10
|
-
const baseOGOverrides = config.admin.meta.openGraph || {};
|
|
11
|
-
const entityOGOverrides = collectionConfig ? collectionConfig.admin?.meta?.openGraph : globalConfig ? globalConfig.admin?.meta?.openGraph : {};
|
|
12
|
-
return meta({
|
|
6
|
+
const metaToUse = {
|
|
13
7
|
...config.admin.meta || {},
|
|
14
|
-
description
|
|
15
|
-
keywords,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
...collectionConfig
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
description: `${isEditing ? t('general:editing') : t('general:creating')} - ${entityLabel}`,
|
|
9
|
+
keywords: `${entityLabel}, Payload, CMS`,
|
|
10
|
+
title: `${isEditing ? t('general:editing') : t('general:creating')} - ${entityLabel}`
|
|
11
|
+
};
|
|
12
|
+
const ogToUse = {
|
|
13
|
+
title: `${isEditing ? t('general:edit') : t('general:edit')} - ${entityLabel}`,
|
|
14
|
+
...config.admin.meta.openGraph || {},
|
|
15
|
+
...collectionConfig ? {
|
|
16
|
+
...collectionConfig?.admin.meta?.openGraph || {},
|
|
17
|
+
...collectionConfig?.admin?.components?.views?.edit?.[view]?.meta?.openGraph || {}
|
|
18
|
+
} : {},
|
|
19
|
+
...globalConfig ? {
|
|
20
|
+
...globalConfig?.admin.meta?.openGraph || {},
|
|
21
|
+
...globalConfig?.admin?.components?.views?.edit?.[view]?.meta?.openGraph || {}
|
|
22
|
+
} : {}
|
|
23
|
+
};
|
|
24
|
+
return meta({
|
|
25
|
+
...metaToUse,
|
|
26
|
+
openGraph: ogToUse,
|
|
27
|
+
...collectionConfig ? {
|
|
28
|
+
...collectionConfig?.admin.meta || {},
|
|
29
|
+
...collectionConfig?.admin?.components?.views?.edit?.[view]?.meta || {}
|
|
30
|
+
} : {},
|
|
31
|
+
...globalConfig ? {
|
|
32
|
+
...globalConfig?.admin.meta || {},
|
|
33
|
+
...globalConfig?.admin?.components?.views?.edit?.[view]?.meta || {}
|
|
34
|
+
} : {},
|
|
35
|
+
serverURL: config.serverURL
|
|
25
36
|
});
|
|
26
37
|
};
|
|
27
38
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/Edit/meta.ts"],"sourcesContent":["import type { Metadata } from 'next'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport type { GenerateEditViewMetadata } from '../Document/getMetaBySegment.js'\n\nimport { meta } from '../../utilities/meta.js'\n\nexport const generateMetadata: GenerateEditViewMetadata = async ({\n collectionConfig,\n config,\n globalConfig,\n i18n,\n isEditing,\n}): Promise<Metadata> => {\n const { t } = i18n\n\n const entityLabel = collectionConfig\n ? getTranslation(collectionConfig.labels.singular, i18n)\n : globalConfig\n ? getTranslation(globalConfig.label, i18n)\n : ''\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/views/Edit/meta.ts"],"sourcesContent":["import type { Metadata } from 'next'\nimport type { MetaConfig } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport type { GenerateEditViewMetadata } from '../Document/getMetaBySegment.js'\n\nimport { meta } from '../../utilities/meta.js'\n\nexport const generateMetadata: GenerateEditViewMetadata = async ({\n collectionConfig,\n config,\n globalConfig,\n i18n,\n isEditing,\n view = 'default',\n}): Promise<Metadata> => {\n const { t } = i18n\n\n const entityLabel = collectionConfig\n ? getTranslation(collectionConfig.labels.singular, i18n)\n : globalConfig\n ? getTranslation(globalConfig.label, i18n)\n : ''\n\n const metaToUse: MetaConfig = {\n ...(config.admin.meta || {}),\n description: `${isEditing ? t('general:editing') : t('general:creating')} - ${entityLabel}`,\n keywords: `${entityLabel}, Payload, CMS`,\n title: `${isEditing ? t('general:editing') : t('general:creating')} - ${entityLabel}`,\n }\n\n const ogToUse: MetaConfig['openGraph'] = {\n title: `${isEditing ? t('general:edit') : t('general:edit')} - ${entityLabel}`,\n ...(config.admin.meta.openGraph || {}),\n ...(collectionConfig\n ? {\n ...(collectionConfig?.admin.meta?.openGraph || {}),\n ...(collectionConfig?.admin?.components?.views?.edit?.[view]?.meta?.openGraph || {}),\n }\n : {}),\n ...(globalConfig\n ? {\n ...(globalConfig?.admin.meta?.openGraph || {}),\n ...(globalConfig?.admin?.components?.views?.edit?.[view]?.meta?.openGraph || {}),\n }\n : {}),\n }\n\n return meta({\n ...metaToUse,\n openGraph: ogToUse,\n ...(collectionConfig\n ? {\n ...(collectionConfig?.admin.meta || {}),\n ...(collectionConfig?.admin?.components?.views?.edit?.[view]?.meta || {}),\n }\n : {}),\n ...(globalConfig\n ? {\n ...(globalConfig?.admin.meta || {}),\n ...(globalConfig?.admin?.components?.views?.edit?.[view]?.meta || {}),\n }\n : {}),\n serverURL: config.serverURL,\n })\n}\n"],"names":["getTranslation","meta","generateMetadata","collectionConfig","config","globalConfig","i18n","isEditing","view","t","entityLabel","labels","singular","label","metaToUse","admin","description","keywords","title","ogToUse","openGraph","components","views","edit","serverURL"],"mappings":"AAGA,SAASA,cAAc,QAAQ,2BAA0B;AAIzD,SAASC,IAAI,QAAQ,0BAAyB;AAE9C,OAAO,MAAMC,mBAA6C,OAAO,EAC/DC,gBAAgB,EAChBC,MAAM,EACNC,YAAY,EACZC,IA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C,OAAOC,MAAM,CAACf,KAAK,EAAEP,QAAQ,CAAC,CAAC;QAC1E,IACA,CAAC,CAAC;QACN,GAAII,eACA;YACE,GAAIA,cAAcU,MAAMd,QAAQ,CAAC,CAAC;YAClC,GAAII,cAAcU,OAAOM,YAAYC,OAAOC,MAAM,CAACf,KAAK,EAAEP,QAAQ,CAAC,CAAC;QACtE,IACA,CAAC,CAAC;QACNuB,WAAWpB,OAAOoB,SAAS;IAC7B;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../src/views/LivePreview/meta.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAI/E,eAAO,MAAM,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../../src/views/LivePreview/meta.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAI/E,eAAO,MAAM,gBAAgB,EAAE,wBAc3B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/LivePreview/meta.ts"],"sourcesContent":["import type { Metadata } from 'next'\n\nimport type { GenerateEditViewMetadata } from '../Document/getMetaBySegment.js'\n\nimport { generateMetadata as generateDocumentMetadata } from '../Edit/meta.js'\n\nexport const generateMetadata: GenerateEditViewMetadata = async ({\n collectionConfig,\n config,\n globalConfig,\n i18n,\n isEditing,\n}): Promise<Metadata> =>\n generateDocumentMetadata({\n collectionConfig,\n config,\n globalConfig,\n i18n,\n isEditing,\n })\n"],"names":["generateMetadata","generateDocumentMetadata","collectionConfig","config","globalConfig","i18n","isEditing"],"mappings":"AAIA,SAASA,oBAAoBC,wBAAwB,QAAQ,kBAAiB;AAE9E,OAAO,MAAMD,mBAA6C,OAAO,EAC/DE,gBAAgB,EAChBC,MAAM,EACNC,YAAY,EACZC,IAAI,EACJC,SAAS,EACV,GACCL,yBAAyB;QACvBC;QACAC;QACAC;QACAC;QACAC;
|
|
1
|
+
{"version":3,"sources":["../../../src/views/LivePreview/meta.ts"],"sourcesContent":["import type { Metadata } from 'next'\n\nimport type { GenerateEditViewMetadata } from '../Document/getMetaBySegment.js'\n\nimport { generateMetadata as generateDocumentMetadata } from '../Edit/meta.js'\n\nexport const generateMetadata: GenerateEditViewMetadata = async ({\n collectionConfig,\n config,\n globalConfig,\n i18n,\n isEditing,\n}): Promise<Metadata> =>\n generateDocumentMetadata({\n collectionConfig,\n config,\n globalConfig,\n i18n,\n isEditing,\n view: 'livePreview',\n })\n"],"names":["generateMetadata","generateDocumentMetadata","collectionConfig","config","globalConfig","i18n","isEditing","view"],"mappings":"AAIA,SAASA,oBAAoBC,wBAAwB,QAAQ,kBAAiB;AAE9E,OAAO,MAAMD,mBAA6C,OAAO,EAC/DE,gBAAgB,EAChBC,MAAM,EACNC,YAAY,EACZC,IAAI,EACJC,SAAS,EACV,GACCL,yBAAyB;QACvBC;QACAC;QACAC;QACAC;QACAC;QACAC,MAAM;IACR,GAAE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { I18nClient } from '@payloadcms/translations';
|
|
2
|
+
import type { Metadata } from 'next';
|
|
3
|
+
import type { AdminViewConfig, SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from 'payload';
|
|
4
|
+
export declare const generateCustomViewMetadata: (args: {
|
|
5
|
+
collectionConfig?: SanitizedCollectionConfig;
|
|
6
|
+
config: SanitizedConfig;
|
|
7
|
+
globalConfig?: SanitizedGlobalConfig;
|
|
8
|
+
i18n: I18nClient;
|
|
9
|
+
viewConfig: AdminViewConfig;
|
|
10
|
+
}) => Promise<Metadata>;
|
|
11
|
+
//# sourceMappingURL=generateCustomViewMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateCustomViewMetadata.d.ts","sourceRoot":"","sources":["../../../src/views/Root/generateCustomViewMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACpC,OAAO,KAAK,EACV,eAAe,EACf,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAIhB,eAAO,MAAM,0BAA0B,SAAgB;IACrD,gBAAgB,CAAC,EAAE,yBAAyB,CAAA;IAC5C,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,IAAI,EAAE,UAAU,CAAA;IAChB,UAAU,EAAE,eAAe,CAAA;CAC5B,KAAG,OAAO,CAAC,QAAQ,CAwBnB,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { meta } from '../../utilities/meta.js';
|
|
2
|
+
export const generateCustomViewMetadata = async (args)=>{
|
|
3
|
+
const { config, // i18n: { t },
|
|
4
|
+
viewConfig } = args;
|
|
5
|
+
if (!viewConfig) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
return meta({
|
|
9
|
+
description: `Payload`,
|
|
10
|
+
keywords: `Payload`,
|
|
11
|
+
serverURL: config.serverURL,
|
|
12
|
+
title: 'Payload',
|
|
13
|
+
...config.admin.meta || {},
|
|
14
|
+
...viewConfig.meta || {},
|
|
15
|
+
openGraph: {
|
|
16
|
+
title: 'Payload',
|
|
17
|
+
...config.admin.meta?.openGraph || {},
|
|
18
|
+
...viewConfig.meta?.openGraph || {}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=generateCustomViewMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/views/Root/generateCustomViewMetadata.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type { Metadata } from 'next'\nimport type {\n AdminViewConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport { meta } from '../../utilities/meta.js'\n\nexport const generateCustomViewMetadata = async (args: {\n collectionConfig?: SanitizedCollectionConfig\n config: SanitizedConfig\n globalConfig?: SanitizedGlobalConfig\n i18n: I18nClient\n viewConfig: AdminViewConfig\n}): Promise<Metadata> => {\n const {\n config,\n // i18n: { t },\n viewConfig,\n } = args\n\n if (!viewConfig) {\n return null\n }\n\n return meta({\n description: `Payload`,\n keywords: `Payload`,\n serverURL: config.serverURL,\n title: 'Payload',\n ...(config.admin.meta || {}),\n ...(viewConfig.meta || {}),\n openGraph: {\n title: 'Payload',\n ...(config.admin.meta?.openGraph || {}),\n ...(viewConfig.meta?.openGraph || {}),\n },\n })\n}\n"],"names":["meta","generateCustomViewMetadata","args","config","viewConfig","description","keywords","serverURL","title","admin","openGraph"],"mappings":"AASA,SAASA,IAAI,QAAQ,0BAAyB;AAE9C,OAAO,MAAMC,6BAA6B,OAAOC;IAO/C,MAAM,EACJC,MAAM,EACN,eAAe;IACfC,UAAU,EACX,GAAGF;IAEJ,IAAI,CAACE,YAAY;QACf,OAAO;IACT;IAEA,OAAOJ,KAAK;QACVK,aAAa,CAAC,OAAO,CAAC;QACtBC,UAAU,CAAC,OAAO,CAAC;QACnBC,WAAWJ,OAAOI,SAAS;QAC3BC,OAAO;QACP,GAAIL,OAAOM,KAAK,CAACT,IAAI,IAAI,CAAC,CAAC;QAC3B,GAAII,WAAWJ,IAAI,IAAI,CAAC,CAAC;QACzBU,WAAW;YACTF,OAAO;YACP,GAAIL,OAAOM,KAAK,CAACT,IAAI,EAAEU,aAAa,CAAC,CAAC;YACtC,GAAIN,WAAWJ,IAAI,EAAEU,aAAa,CAAC,CAAC;QACtC;IACF;AACF,EAAC"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { SanitizedConfig } from 'payload';
|
|
1
|
+
import type { AdminViewConfig, SanitizedConfig } from 'payload';
|
|
2
2
|
import type { ViewFromConfig } from './getViewFromConfig.js';
|
|
3
3
|
export declare const getCustomViewByRoute: ({ config, currentRoute: currentRouteWithAdmin, }: {
|
|
4
4
|
config: SanitizedConfig;
|
|
5
5
|
currentRoute: string;
|
|
6
|
-
}) =>
|
|
6
|
+
}) => {
|
|
7
|
+
view: ViewFromConfig;
|
|
8
|
+
viewConfig: AdminViewConfig;
|
|
9
|
+
viewKey: string;
|
|
10
|
+
};
|
|
7
11
|
//# sourceMappingURL=getCustomViewByRoute.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCustomViewByRoute.d.ts","sourceRoot":"","sources":["../../../src/views/Root/getCustomViewByRoute.
|
|
1
|
+
{"version":3,"file":"getCustomViewByRoute.d.ts","sourceRoot":"","sources":["../../../src/views/Root/getCustomViewByRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAI5D,eAAO,MAAM,oBAAoB,qDAG9B;IACD,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;CACrB,KAAG;IACF,IAAI,EAAE,cAAc,CAAA;IACpB,UAAU,EAAE,eAAe,CAAA;IAC3B,OAAO,EAAE,MAAM,CAAA;CAiDhB,CAAA"}
|
|
@@ -2,20 +2,35 @@ import { isPathMatchingRoute } from './isPathMatchingRoute.js';
|
|
|
2
2
|
export const getCustomViewByRoute = ({ config, currentRoute: currentRouteWithAdmin })=>{
|
|
3
3
|
const { admin: { components: { views } }, routes: { admin: adminRoute } } = config;
|
|
4
4
|
const currentRoute = currentRouteWithAdmin.replace(adminRoute, '');
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
let viewKey;
|
|
6
|
+
const foundViewConfig = views && typeof views === 'object' && Object.entries(views).find(([key, view])=>{
|
|
7
|
+
const isMatching = isPathMatchingRoute({
|
|
7
8
|
currentRoute,
|
|
8
9
|
exact: view.exact,
|
|
9
10
|
path: view.path,
|
|
10
11
|
sensitive: view.sensitive,
|
|
11
12
|
strict: view.strict
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
+
if (isMatching) {
|
|
15
|
+
viewKey = key;
|
|
16
|
+
}
|
|
17
|
+
return isMatching;
|
|
18
|
+
})?.[1] || undefined;
|
|
14
19
|
if (!foundViewConfig) {
|
|
15
|
-
return
|
|
20
|
+
return {
|
|
21
|
+
view: {
|
|
22
|
+
Component: null
|
|
23
|
+
},
|
|
24
|
+
viewConfig: null,
|
|
25
|
+
viewKey: null
|
|
26
|
+
};
|
|
16
27
|
}
|
|
17
28
|
return {
|
|
18
|
-
|
|
29
|
+
view: {
|
|
30
|
+
payloadComponent: foundViewConfig.Component
|
|
31
|
+
},
|
|
32
|
+
viewConfig: foundViewConfig,
|
|
33
|
+
viewKey
|
|
19
34
|
};
|
|
20
35
|
};
|
|
21
36
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/Root/getCustomViewByRoute.
|
|
1
|
+
{"version":3,"sources":["../../../src/views/Root/getCustomViewByRoute.ts"],"sourcesContent":["import type { AdminViewConfig, SanitizedConfig } from 'payload'\n\nimport type { ViewFromConfig } from './getViewFromConfig.js'\n\nimport { isPathMatchingRoute } from './isPathMatchingRoute.js'\n\nexport const getCustomViewByRoute = ({\n config,\n currentRoute: currentRouteWithAdmin,\n}: {\n config: SanitizedConfig\n currentRoute: string\n}): {\n view: ViewFromConfig\n viewConfig: AdminViewConfig\n viewKey: string\n} => {\n const {\n admin: {\n components: { views },\n },\n routes: { admin: adminRoute },\n } = config\n\n const currentRoute = currentRouteWithAdmin.replace(adminRoute, '')\n let viewKey: string\n\n const foundViewConfig =\n (views &&\n typeof views === 'object' &&\n Object.entries(views).find(([key, view]) => {\n const isMatching = isPathMatchingRoute({\n currentRoute,\n exact: view.exact,\n path: view.path,\n sensitive: view.sensitive,\n strict: view.strict,\n })\n\n if (isMatching) {\n viewKey = key\n }\n\n return isMatching\n })?.[1]) ||\n undefined\n\n if (!foundViewConfig) {\n return {\n view: {\n Component: null,\n },\n viewConfig: null,\n viewKey: null,\n }\n }\n\n return {\n view: {\n payloadComponent: foundViewConfig.Component,\n },\n viewConfig: foundViewConfig,\n viewKey,\n }\n}\n"],"names":["isPathMatchingRoute","getCustomViewByRoute","config","currentRoute","currentRouteWithAdmin","admin","components","views","routes","adminRoute","replace","viewKey","foundViewConfig","Object","entries","find","key","view","isMatching","exact","path","sensitive","strict","undefined","Component","viewConfig","payloadComponent"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,2BAA0B;AAE9D,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,MAAM,EACNC,cAAcC,qBAAqB,EAIpC;IAKC,MAAM,EACJC,OAAO,EACLC,YAAY,EAAEC,KAAK,EAAE,EACtB,EACDC,QAAQ,EAAEH,OAAOI,UAAU,EAAE,EAC9B,GAAGP;IAEJ,MAAMC,eAAeC,sBAAsBM,OAAO,CAACD,YAAY;IAC/D,IAAIE;IAEJ,MAAMC,kBACJ,AAACL,SACC,OAAOA,UAAU,YACjBM,OAAOC,OAAO,CAACP,OAAOQ,IAAI,CAAC,CAAC,CAACC,KAAKC,KAAK;QACrC,MAAMC,aAAalB,oBAAoB;YACrCG;YACAgB,OAAOF,KAAKE,KAAK;YACjBC,MAAMH,KAAKG,IAAI;YACfC,WAAWJ,KAAKI,SAAS;YACzBC,QAAQL,KAAKK,MAAM;QACrB;QAEA,IAAIJ,YAAY;YACdP,UAAUK;QACZ;QAEA,OAAOE;IACT,IAAI,CAAC,EAAE,IACTK;IAEF,IAAI,CAACX,iBAAiB;QACpB,OAAO;YACLK,MAAM;gBACJO,WAAW;YACb;YACAC,YAAY;YACZd,SAAS;QACX;IACF;IAEA,OAAO;QACLM,MAAM;YACJS,kBAAkBd,gBAAgBY,SAAS;QAC7C;QACAC,YAAYb;QACZD;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getViewFromConfig.d.ts","sourceRoot":"","sources":["../../../src/views/Root/getViewFromConfig.
|
|
1
|
+
{"version":3,"file":"getViewFromConfig.d.ts","sourceRoot":"","sources":["../../../src/views/Root/getViewFromConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC7F,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAA;AA4BjE,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,CAAA;IACpC,gBAAgB,CAAC,EAAE,kBAAkB,CAAA;CACtC,CAAA;AAYD,eAAO,MAAM,iBAAiB,6EAO3B;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,eAAe,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,SAAS,CAAA;IACpB,YAAY,EAAE;QACZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KACjC,CAAA;IACD,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,KAAG;IACF,WAAW,EAAE,cAAc,CAAA;IAC3B,eAAe,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/C,iBAAiB,EAAE,MAAM,CAAA;IACzB,YAAY,EAAE,SAAS,GAAG,SAAS,CAAA;CA6JpC,CAAA"}
|