fix(live-preview): populates localized relationships in client-side live preview (#9617)

Fixes #5026. When using client-side Live Preview, switching locale would
not populate relationships in that locale, and would use the default
locale instead. This was because locale was simply not being handled.
Now, we pass the locale through the event, and use it to make localized
queries when populating those relationships.
This commit is contained in:
Jacob Fletcher
2024-11-29 15:41:39 -05:00
committed by GitHub
parent 9892303f1f
commit 3d1a0656d2
12 changed files with 200 additions and 93 deletions

View File

@@ -43,6 +43,7 @@ export const handleMessage = async <T>(args: {
fieldSchema: payloadLivePreviewFieldSchema, fieldSchema: payloadLivePreviewFieldSchema,
incomingData: data, incomingData: data,
initialData: payloadLivePreviewPreviousData || initialData, initialData: payloadLivePreviewPreviousData || initialData,
locale: event.data.locale,
serverURL, serverURL,
}) })

View File

@@ -15,6 +15,11 @@ const defaultRequestHandler = ({ apiPath, endpoint, serverURL }) => {
}) })
} }
// Relationships are only updated when their `id` or `relationTo` changes, by comparing the old and new values
// This needs to also happen when locale changes, except this is not not part of the API response
// Instead, we keep track of the old locale ourselves and trigger a re-population when it changes
let prevLocale: string | undefined
export const mergeData = async <T>(args: { export const mergeData = async <T>(args: {
apiRoute?: string apiRoute?: string
collectionPopulationRequestHandler?: ({ collectionPopulationRequestHandler?: ({
@@ -31,6 +36,7 @@ export const mergeData = async <T>(args: {
fieldSchema: ReturnType<typeof fieldSchemaToJSON> fieldSchema: ReturnType<typeof fieldSchemaToJSON>
incomingData: Partial<T> incomingData: Partial<T>
initialData: T initialData: T
locale?: string
returnNumberOfRequests?: boolean returnNumberOfRequests?: boolean
serverURL: string serverURL: string
}): Promise< }): Promise<
@@ -45,6 +51,7 @@ export const mergeData = async <T>(args: {
fieldSchema, fieldSchema,
incomingData, incomingData,
initialData, initialData,
locale,
returnNumberOfRequests, returnNumberOfRequests,
serverURL, serverURL,
} = args } = args
@@ -57,6 +64,7 @@ export const mergeData = async <T>(args: {
externallyUpdatedRelationship, externallyUpdatedRelationship,
fieldSchema, fieldSchema,
incomingData, incomingData,
localeChanged: prevLocale !== locale,
populationsByCollection, populationsByCollection,
result, result,
}) })
@@ -72,7 +80,7 @@ export const mergeData = async <T>(args: {
res = await requestHandler({ res = await requestHandler({
apiPath: apiRoute || '/api', apiPath: apiRoute || '/api',
endpoint: encodeURI( endpoint: encodeURI(
`${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}`, `${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}${locale ? `&locale=${locale}` : ''}`,
), ),
serverURL, serverURL,
}).then((res) => res.json()) }).then((res) => res.json())
@@ -92,6 +100,8 @@ export const mergeData = async <T>(args: {
}), }),
) )
prevLocale = locale
return { return {
...result, ...result,
...(returnNumberOfRequests ...(returnNumberOfRequests

View File

@@ -6,7 +6,7 @@ export const subscribe = <T>(args: {
depth?: number depth?: number
initialData: T initialData: T
serverURL: string serverURL: string
}): ((event: MessageEvent) => void) => { }): ((event: MessageEvent) => Promise<void> | void) => {
const { apiRoute, callback, depth, initialData, serverURL } = args const { apiRoute, callback, depth, initialData, serverURL } = args
const onMessage = async (event: MessageEvent) => { const onMessage = async (event: MessageEvent) => {

View File

@@ -8,6 +8,7 @@ export const traverseFields = <T>(args: {
externallyUpdatedRelationship?: UpdatedDocument externallyUpdatedRelationship?: UpdatedDocument
fieldSchema: ReturnType<typeof fieldSchemaToJSON> fieldSchema: ReturnType<typeof fieldSchemaToJSON>
incomingData: T incomingData: T
localeChanged: boolean
populationsByCollection: PopulationsByCollection populationsByCollection: PopulationsByCollection
result: T result: T
}): void => { }): void => {
@@ -15,6 +16,7 @@ export const traverseFields = <T>(args: {
externallyUpdatedRelationship, externallyUpdatedRelationship,
fieldSchema: fieldSchemas, fieldSchema: fieldSchemas,
incomingData, incomingData,
localeChanged,
populationsByCollection, populationsByCollection,
result, result,
} = args } = args
@@ -47,6 +49,7 @@ export const traverseFields = <T>(args: {
externallyUpdatedRelationship, externallyUpdatedRelationship,
fieldSchema: fieldSchema.fields, fieldSchema: fieldSchema.fields,
incomingData: incomingRow, incomingData: incomingRow,
localeChanged,
populationsByCollection, populationsByCollection,
result: result[fieldName][i], result: result[fieldName][i],
}) })
@@ -80,6 +83,7 @@ export const traverseFields = <T>(args: {
externallyUpdatedRelationship, externallyUpdatedRelationship,
fieldSchema: incomingBlockJSON.fields, fieldSchema: incomingBlockJSON.fields,
incomingData: incomingBlock, incomingData: incomingBlock,
localeChanged,
populationsByCollection, populationsByCollection,
result: result[fieldName][i], result: result[fieldName][i],
}) })
@@ -103,6 +107,7 @@ export const traverseFields = <T>(args: {
externallyUpdatedRelationship, externallyUpdatedRelationship,
fieldSchema: fieldSchema.fields, fieldSchema: fieldSchema.fields,
incomingData: incomingData[fieldName] || {}, incomingData: incomingData[fieldName] || {},
localeChanged,
populationsByCollection, populationsByCollection,
result: result[fieldName], result: result[fieldName],
}) })
@@ -135,11 +140,12 @@ export const traverseFields = <T>(args: {
const newRelation = incomingRelation.relationTo const newRelation = incomingRelation.relationTo
const hasChanged = newID !== oldID || newRelation !== oldRelation const hasChanged = newID !== oldID || newRelation !== oldRelation
const hasUpdated = const hasUpdated =
newRelation === externallyUpdatedRelationship?.entitySlug && newRelation === externallyUpdatedRelationship?.entitySlug &&
newID === externallyUpdatedRelationship?.id newID === externallyUpdatedRelationship?.id
if (hasChanged || hasUpdated) { if (hasChanged || hasUpdated || localeChanged) {
if (!populationsByCollection[newRelation]) { if (!populationsByCollection[newRelation]) {
populationsByCollection[newRelation] = [] populationsByCollection[newRelation] = []
} }
@@ -153,11 +159,12 @@ export const traverseFields = <T>(args: {
} else { } else {
// Handle `hasMany` monomorphic // Handle `hasMany` monomorphic
const hasChanged = incomingRelation !== result[fieldName][i]?.id const hasChanged = incomingRelation !== result[fieldName][i]?.id
const hasUpdated = const hasUpdated =
fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug && fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug &&
incomingRelation === externallyUpdatedRelationship?.id incomingRelation === externallyUpdatedRelationship?.id
if (hasChanged || hasUpdated) { if (hasChanged || hasUpdated || localeChanged) {
if (!populationsByCollection[fieldSchema.relationTo]) { if (!populationsByCollection[fieldSchema.relationTo]) {
populationsByCollection[fieldSchema.relationTo] = [] populationsByCollection[fieldSchema.relationTo] = []
} }
@@ -207,13 +214,14 @@ export const traverseFields = <T>(args: {
const oldRelation = hasOldValue ? result[fieldName].relationTo : '' const oldRelation = hasOldValue ? result[fieldName].relationTo : ''
const hasChanged = newID !== oldID || newRelation !== oldRelation const hasChanged = newID !== oldID || newRelation !== oldRelation
const hasUpdated = const hasUpdated =
newRelation === externallyUpdatedRelationship?.entitySlug && newRelation === externallyUpdatedRelationship?.entitySlug &&
newID === externallyUpdatedRelationship?.id newID === externallyUpdatedRelationship?.id
// if the new value/relation is different from the old value/relation // if the new value/relation is different from the old value/relation
// populate the new value, otherwise leave it alone // populate the new value, otherwise leave it alone
if (hasChanged || hasUpdated) { if (hasChanged || hasUpdated || localeChanged) {
// if the new value is not empty, populate it // if the new value is not empty, populate it
// otherwise set the value to null // otherwise set the value to null
if (newID) { if (newID) {
@@ -245,13 +253,14 @@ export const traverseFields = <T>(args: {
result[fieldName] result[fieldName]
const hasChanged = newID !== oldID const hasChanged = newID !== oldID
const hasUpdated = const hasUpdated =
fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug && fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug &&
newID === externallyUpdatedRelationship?.id newID === externallyUpdatedRelationship?.id
// if the new value is different from the old value // if the new value is different from the old value
// populate the new value, otherwise leave it alone // populate the new value, otherwise leave it alone
if (hasChanged || hasUpdated) { if (hasChanged || hasUpdated || localeChanged) {
// if the new value is not empty, populate it // if the new value is not empty, populate it
// otherwise set the value to null // otherwise set the value to null
if (newID) { if (newID) {

View File

@@ -2,7 +2,7 @@
import type { EditViewProps } from 'payload' import type { EditViewProps } from 'payload'
import { ShimmerEffect, useAllFormFields, useDocumentEvents } from '@payloadcms/ui' import { ShimmerEffect, useAllFormFields, useDocumentEvents, useLocale } from '@payloadcms/ui'
import { reduceFieldsToValues } from 'payload/shared' import { reduceFieldsToValues } from 'payload/shared'
import React, { useEffect } from 'react' import React, { useEffect } from 'react'
@@ -25,6 +25,8 @@ export const LivePreview: React.FC<EditViewProps> = (props) => {
url, url,
} = useLivePreviewContext() } = useLivePreviewContext()
const locale = useLocale()
const { mostRecentUpdate } = useDocumentEvents() const { mostRecentUpdate } = useDocumentEvents()
const { breakpoint, fieldSchemaJSON } = useLivePreviewContext() const { breakpoint, fieldSchemaJSON } = useLivePreviewContext()
@@ -57,6 +59,7 @@ export const LivePreview: React.FC<EditViewProps> = (props) => {
data: values, data: values,
externallyUpdatedRelationship: mostRecentUpdate, externallyUpdatedRelationship: mostRecentUpdate,
fieldSchemaJSON: shouldSendSchema ? fieldSchemaJSON : undefined, fieldSchemaJSON: shouldSendSchema ? fieldSchemaJSON : undefined,
locale: locale.code,
} }
// Post message to external popup window // Post message to external popup window
@@ -80,6 +83,7 @@ export const LivePreview: React.FC<EditViewProps> = (props) => {
setIframeHasLoaded, setIframeHasLoaded,
fieldSchemaJSON, fieldSchemaJSON,
mostRecentUpdate, mostRecentUpdate,
locale,
]) ])
// To support SSR, we transmit a `window.postMessage` event without a payload // To support SSR, we transmit a `window.postMessage` event without a payload

View File

@@ -38,6 +38,9 @@ export const PageClient: React.FC<{
/> />
<Gutter> <Gutter>
<div id={renderedPageTitleID}>{`For Testing: ${data.title}`}</div> <div id={renderedPageTitleID}>{`For Testing: ${data.title}`}</div>
<div id={renderedPageTitleID}>
{`For Testing (Localized): ${typeof data.relationToLocalized === 'string' ? data.relationToLocalized : data.relationToLocalized?.localizedTitle}`}
</div>
</Gutter> </Gutter>
</React.Fragment> </React.Fragment>
) )

View File

@@ -75,6 +75,16 @@ export const Pages: CollectionConfig = {
{ {
label: 'Test', label: 'Test',
fields: [ fields: [
{
name: 'localizedTitle',
type: 'text',
localized: true,
},
{
name: 'relationToLocalized',
type: 'relationship',
relationTo: postsSlug,
},
{ {
label: 'Rich Text — Slate', label: 'Rich Text — Slate',
type: 'richText', type: 'richText',

View File

@@ -71,6 +71,16 @@ export const Posts: CollectionConfig = {
}, },
], ],
}, },
{
label: 'Test',
fields: [
{
name: 'localizedTitle',
type: 'text',
localized: true,
},
],
},
], ],
}, },
{ {

View File

@@ -25,6 +25,10 @@ import {
import { formatLivePreviewURL } from './utilities/formatLivePreviewURL.js' import { formatLivePreviewURL } from './utilities/formatLivePreviewURL.js'
export default buildConfigWithDefaults({ export default buildConfigWithDefaults({
localization: {
defaultLocale: 'en',
locales: ['en', 'es'],
},
admin: { admin: {
importMap: { importMap: {
baseDir: path.resolve(dirname), baseDir: path.resolve(dirname),

View File

@@ -51,6 +51,7 @@ describe('Collections - Live Preview', () => {
slug: 'post-1', slug: 'post-1',
title: 'Test Post', title: 'Test Post',
tenant: tenant.id, tenant: tenant.id,
localizedTitle: 'Test Post',
}, },
}) })
@@ -60,6 +61,7 @@ describe('Collections - Live Preview', () => {
slug: 'post-2', slug: 'post-2',
title: 'Test Post 2', title: 'Test Post 2',
tenant: tenant.id, tenant: tenant.id,
localizedTitle: 'Test Post 2',
}, },
}) })
@@ -1135,6 +1137,54 @@ describe('Collections - Live Preview', () => {
]) ])
}) })
it('— relationships - populates localized relationships', async () => {
const post = await payload.create({
collection: postsSlug,
data: {
title: 'Test Post',
slug: 'test-post',
hero: {
type: 'highImpact',
media: media.id,
},
localizedTitle: 'Test Post Spanish',
},
locale: 'es',
})
await payload.update({
id: post.id,
locale: 'en',
collection: postsSlug,
data: {
localizedTitle: 'Test Post English',
},
})
const initialData: Partial<Page> = {
title: 'Test Page',
relationToLocalized: post.id,
}
// Populate the relationships
const merge1 = await mergeData({
depth: 1,
fieldSchema: schemaJSON,
incomingData: {
...initialData,
relationToLocalized: post.id,
},
initialData,
serverURL,
returnNumberOfRequests: true,
collectionPopulationRequestHandler,
locale: 'es',
})
expect(merge1._numberOfRequests).toEqual(1)
expect(merge1.relationToLocalized).toHaveProperty('localizedTitle', 'Test Post Spanish')
})
it('— rich text - merges text changes', async () => { it('— rich text - merges text changes', async () => {
// Add a relationship // Add a relationship
const merge1 = await traverseRichText({ const merge1 = await traverseRichText({

View File

@@ -38,7 +38,7 @@ export interface Config {
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>; 'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
}; };
db: { db: {
defaultIDType: string; defaultIDType: number;
}; };
globals: { globals: {
header: Header; header: Header;
@@ -48,7 +48,7 @@ export interface Config {
header: HeaderSelect<false> | HeaderSelect<true>; header: HeaderSelect<false> | HeaderSelect<true>;
footer: FooterSelect<false> | FooterSelect<true>; footer: FooterSelect<false> | FooterSelect<true>;
}; };
locale: null; locale: 'en' | 'es';
user: User & { user: User & {
collection: 'users'; collection: 'users';
}; };
@@ -80,7 +80,7 @@ export interface UserAuthOperations {
* via the `definition` "users". * via the `definition` "users".
*/ */
export interface User { export interface User {
id: string; id: number;
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
email: string; email: string;
@@ -97,9 +97,9 @@ export interface User {
* via the `definition` "pages". * via the `definition` "pages".
*/ */
export interface Page { export interface Page {
id: string; id: number;
slug: string; slug: string;
tenant?: (string | null) | Tenant; tenant?: (number | null) | Tenant;
title: string; title: string;
hero: { hero: {
type: 'none' | 'highImpact' | 'lowImpact'; type: 'none' | 'highImpact' | 'lowImpact';
@@ -108,7 +108,7 @@ export interface Page {
[k: string]: unknown; [k: string]: unknown;
}[] }[]
| null; | null;
media?: (string | null) | Media; media?: (number | null) | Media;
}; };
layout?: layout?:
| ( | (
@@ -127,11 +127,11 @@ export interface Page {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;
@@ -161,11 +161,11 @@ export interface Page {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;
@@ -181,7 +181,7 @@ export interface Page {
| { | {
invertBackground?: boolean | null; invertBackground?: boolean | null;
position?: ('default' | 'fullscreen') | null; position?: ('default' | 'fullscreen') | null;
media: string | Media; media: number | Media;
id?: string | null; id?: string | null;
blockName?: string | null; blockName?: string | null;
blockType: 'mediaBlock'; blockType: 'mediaBlock';
@@ -194,18 +194,18 @@ export interface Page {
| null; | null;
populateBy?: ('collection' | 'selection') | null; populateBy?: ('collection' | 'selection') | null;
relationTo?: 'posts' | null; relationTo?: 'posts' | null;
categories?: (string | Category)[] | null; categories?: (number | Category)[] | null;
limit?: number | null; limit?: number | null;
selectedDocs?: selectedDocs?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
populatedDocs?: populatedDocs?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
populatedDocsTotal?: number | null; populatedDocsTotal?: number | null;
@@ -215,6 +215,8 @@ export interface Page {
} }
)[] )[]
| null; | null;
localizedTitle?: string | null;
relationToLocalized?: (number | null) | Post;
richTextSlate?: richTextSlate?:
| { | {
[k: string]: unknown; [k: string]: unknown;
@@ -235,22 +237,22 @@ export interface Page {
}; };
[k: string]: unknown; [k: string]: unknown;
} | null; } | null;
relationshipAsUpload?: (string | null) | Media; relationshipAsUpload?: (number | null) | Media;
relationshipMonoHasOne?: (string | null) | Post; relationshipMonoHasOne?: (number | null) | Post;
relationshipMonoHasMany?: (string | Post)[] | null; relationshipMonoHasMany?: (number | Post)[] | null;
relationshipPolyHasOne?: { relationshipPolyHasOne?: {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null; } | null;
relationshipPolyHasMany?: relationshipPolyHasMany?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
arrayOfRelationships?: arrayOfRelationships?:
| { | {
uploadInArray?: (string | null) | Media; uploadInArray?: (number | null) | Media;
richTextInArray?: { richTextInArray?: {
root: { root: {
type: string; type: string;
@@ -266,28 +268,28 @@ export interface Page {
}; };
[k: string]: unknown; [k: string]: unknown;
} | null; } | null;
relationshipInArrayMonoHasOne?: (string | null) | Post; relationshipInArrayMonoHasOne?: (number | null) | Post;
relationshipInArrayMonoHasMany?: (string | Post)[] | null; relationshipInArrayMonoHasMany?: (number | Post)[] | null;
relationshipInArrayPolyHasOne?: { relationshipInArrayPolyHasOne?: {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null; } | null;
relationshipInArrayPolyHasMany?: relationshipInArrayPolyHasMany?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
id?: string | null; id?: string | null;
}[] }[]
| null; | null;
tab?: { tab?: {
relationshipInTab?: (string | null) | Post; relationshipInTab?: (number | null) | Post;
}; };
meta?: { meta?: {
title?: string | null; title?: string | null;
description?: string | null; description?: string | null;
image?: (string | null) | Media; image?: (number | null) | Media;
}; };
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
@@ -297,7 +299,7 @@ export interface Page {
* via the `definition` "tenants". * via the `definition` "tenants".
*/ */
export interface Tenant { export interface Tenant {
id: string; id: number;
title: string; title: string;
clientURL: string; clientURL: string;
updatedAt: string; updatedAt: string;
@@ -308,7 +310,7 @@ export interface Tenant {
* via the `definition` "media". * via the `definition` "media".
*/ */
export interface Media { export interface Media {
id: string; id: number;
alt: string; alt: string;
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
@@ -327,9 +329,9 @@ export interface Media {
* via the `definition` "posts". * via the `definition` "posts".
*/ */
export interface Post { export interface Post {
id: string; id: number;
slug: string; slug: string;
tenant?: (string | null) | Tenant; tenant?: (number | null) | Tenant;
title: string; title: string;
hero: { hero: {
type: 'none' | 'highImpact' | 'lowImpact'; type: 'none' | 'highImpact' | 'lowImpact';
@@ -338,7 +340,7 @@ export interface Post {
[k: string]: unknown; [k: string]: unknown;
}[] }[]
| null; | null;
media?: (string | null) | Media; media?: (number | null) | Media;
}; };
layout?: layout?:
| ( | (
@@ -357,11 +359,11 @@ export interface Post {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;
@@ -391,11 +393,11 @@ export interface Post {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;
@@ -411,7 +413,7 @@ export interface Post {
| { | {
invertBackground?: boolean | null; invertBackground?: boolean | null;
position?: ('default' | 'fullscreen') | null; position?: ('default' | 'fullscreen') | null;
media: string | Media; media: number | Media;
id?: string | null; id?: string | null;
blockName?: string | null; blockName?: string | null;
blockType: 'mediaBlock'; blockType: 'mediaBlock';
@@ -424,18 +426,18 @@ export interface Post {
| null; | null;
populateBy?: ('collection' | 'selection') | null; populateBy?: ('collection' | 'selection') | null;
relationTo?: 'posts' | null; relationTo?: 'posts' | null;
categories?: (string | Category)[] | null; categories?: (number | Category)[] | null;
limit?: number | null; limit?: number | null;
selectedDocs?: selectedDocs?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
populatedDocs?: populatedDocs?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
populatedDocsTotal?: number | null; populatedDocsTotal?: number | null;
@@ -445,11 +447,12 @@ export interface Post {
} }
)[] )[]
| null; | null;
relatedPosts?: (string | Post)[] | null; relatedPosts?: (number | Post)[] | null;
localizedTitle?: string | null;
meta?: { meta?: {
title?: string | null; title?: string | null;
description?: string | null; description?: string | null;
image?: (string | null) | Media; image?: (number | null) | Media;
}; };
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
@@ -459,7 +462,7 @@ export interface Post {
* via the `definition` "categories". * via the `definition` "categories".
*/ */
export interface Category { export interface Category {
id: string; id: number;
title?: string | null; title?: string | null;
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
@@ -469,9 +472,9 @@ export interface Category {
* via the `definition` "ssr". * via the `definition` "ssr".
*/ */
export interface Ssr { export interface Ssr {
id: string; id: number;
slug: string; slug: string;
tenant?: (string | null) | Tenant; tenant?: (number | null) | Tenant;
title: string; title: string;
hero: { hero: {
type: 'none' | 'highImpact' | 'lowImpact'; type: 'none' | 'highImpact' | 'lowImpact';
@@ -480,7 +483,7 @@ export interface Ssr {
[k: string]: unknown; [k: string]: unknown;
}[] }[]
| null; | null;
media?: (string | null) | Media; media?: (number | null) | Media;
}; };
layout?: layout?:
| ( | (
@@ -499,11 +502,11 @@ export interface Ssr {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;
@@ -533,11 +536,11 @@ export interface Ssr {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;
@@ -553,7 +556,7 @@ export interface Ssr {
| { | {
invertBackground?: boolean | null; invertBackground?: boolean | null;
position?: ('default' | 'fullscreen') | null; position?: ('default' | 'fullscreen') | null;
media: string | Media; media: number | Media;
id?: string | null; id?: string | null;
blockName?: string | null; blockName?: string | null;
blockType: 'mediaBlock'; blockType: 'mediaBlock';
@@ -566,18 +569,18 @@ export interface Ssr {
| null; | null;
populateBy?: ('collection' | 'selection') | null; populateBy?: ('collection' | 'selection') | null;
relationTo?: 'posts' | null; relationTo?: 'posts' | null;
categories?: (string | Category)[] | null; categories?: (number | Category)[] | null;
limit?: number | null; limit?: number | null;
selectedDocs?: selectedDocs?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
populatedDocs?: populatedDocs?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
populatedDocsTotal?: number | null; populatedDocsTotal?: number | null;
@@ -590,7 +593,7 @@ export interface Ssr {
meta?: { meta?: {
title?: string | null; title?: string | null;
description?: string | null; description?: string | null;
image?: (string | null) | Media; image?: (number | null) | Media;
}; };
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
@@ -600,9 +603,9 @@ export interface Ssr {
* via the `definition` "ssr-autosave". * via the `definition` "ssr-autosave".
*/ */
export interface SsrAutosave { export interface SsrAutosave {
id: string; id: number;
slug: string; slug: string;
tenant?: (string | null) | Tenant; tenant?: (number | null) | Tenant;
title: string; title: string;
hero: { hero: {
type: 'none' | 'highImpact' | 'lowImpact'; type: 'none' | 'highImpact' | 'lowImpact';
@@ -611,7 +614,7 @@ export interface SsrAutosave {
[k: string]: unknown; [k: string]: unknown;
}[] }[]
| null; | null;
media?: (string | null) | Media; media?: (number | null) | Media;
}; };
layout?: layout?:
| ( | (
@@ -630,11 +633,11 @@ export interface SsrAutosave {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;
@@ -664,11 +667,11 @@ export interface SsrAutosave {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;
@@ -684,7 +687,7 @@ export interface SsrAutosave {
| { | {
invertBackground?: boolean | null; invertBackground?: boolean | null;
position?: ('default' | 'fullscreen') | null; position?: ('default' | 'fullscreen') | null;
media: string | Media; media: number | Media;
id?: string | null; id?: string | null;
blockName?: string | null; blockName?: string | null;
blockType: 'mediaBlock'; blockType: 'mediaBlock';
@@ -697,18 +700,18 @@ export interface SsrAutosave {
| null; | null;
populateBy?: ('collection' | 'selection') | null; populateBy?: ('collection' | 'selection') | null;
relationTo?: 'posts' | null; relationTo?: 'posts' | null;
categories?: (string | Category)[] | null; categories?: (number | Category)[] | null;
limit?: number | null; limit?: number | null;
selectedDocs?: selectedDocs?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
populatedDocs?: populatedDocs?:
| { | {
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
}[] }[]
| null; | null;
populatedDocsTotal?: number | null; populatedDocsTotal?: number | null;
@@ -721,7 +724,7 @@ export interface SsrAutosave {
meta?: { meta?: {
title?: string | null; title?: string | null;
description?: string | null; description?: string | null;
image?: (string | null) | Media; image?: (number | null) | Media;
}; };
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
@@ -732,44 +735,44 @@ export interface SsrAutosave {
* via the `definition` "payload-locked-documents". * via the `definition` "payload-locked-documents".
*/ */
export interface PayloadLockedDocument { export interface PayloadLockedDocument {
id: string; id: number;
document?: document?:
| ({ | ({
relationTo: 'users'; relationTo: 'users';
value: string | User; value: number | User;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null) } | null)
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'ssr'; relationTo: 'ssr';
value: string | Ssr; value: number | Ssr;
} | null) } | null)
| ({ | ({
relationTo: 'ssr-autosave'; relationTo: 'ssr-autosave';
value: string | SsrAutosave; value: number | SsrAutosave;
} | null) } | null)
| ({ | ({
relationTo: 'tenants'; relationTo: 'tenants';
value: string | Tenant; value: number | Tenant;
} | null) } | null)
| ({ | ({
relationTo: 'categories'; relationTo: 'categories';
value: string | Category; value: number | Category;
} | null) } | null)
| ({ | ({
relationTo: 'media'; relationTo: 'media';
value: string | Media; value: number | Media;
} | null); } | null);
globalSlug?: string | null; globalSlug?: string | null;
user: { user: {
relationTo: 'users'; relationTo: 'users';
value: string | User; value: number | User;
}; };
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
@@ -779,10 +782,10 @@ export interface PayloadLockedDocument {
* via the `definition` "payload-preferences". * via the `definition` "payload-preferences".
*/ */
export interface PayloadPreference { export interface PayloadPreference {
id: string; id: number;
user: { user: {
relationTo: 'users'; relationTo: 'users';
value: string | User; value: number | User;
}; };
key?: string | null; key?: string | null;
value?: value?:
@@ -802,7 +805,7 @@ export interface PayloadPreference {
* via the `definition` "payload-migrations". * via the `definition` "payload-migrations".
*/ */
export interface PayloadMigration { export interface PayloadMigration {
id: string; id: number;
name?: string | null; name?: string | null;
batch?: number | null; batch?: number | null;
updatedAt: string; updatedAt: string;
@@ -913,6 +916,8 @@ export interface PagesSelect<T extends boolean = true> {
blockName?: T; blockName?: T;
}; };
}; };
localizedTitle?: T;
relationToLocalized?: T;
richTextSlate?: T; richTextSlate?: T;
richTextLexical?: T; richTextLexical?: T;
relationshipAsUpload?: T; relationshipAsUpload?: T;
@@ -1037,6 +1042,7 @@ export interface PostsSelect<T extends boolean = true> {
}; };
}; };
relatedPosts?: T; relatedPosts?: T;
localizedTitle?: T;
meta?: meta?:
| T | T
| { | {
@@ -1322,7 +1328,7 @@ export interface PayloadMigrationsSelect<T extends boolean = true> {
* via the `definition` "header". * via the `definition` "header".
*/ */
export interface Header { export interface Header {
id: string; id: number;
navItems?: navItems?:
| { | {
link: { link: {
@@ -1331,11 +1337,11 @@ export interface Header {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;
@@ -1352,7 +1358,7 @@ export interface Header {
* via the `definition` "footer". * via the `definition` "footer".
*/ */
export interface Footer { export interface Footer {
id: string; id: number;
navItems?: navItems?:
| { | {
link: { link: {
@@ -1361,11 +1367,11 @@ export interface Footer {
reference?: reference?:
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: number | Post;
} | null) } | null)
| ({ | ({
relationTo: 'pages'; relationTo: 'pages';
value: string | Page; value: number | Page;
} | null); } | null);
url?: string | null; url?: string | null;
label: string; label: string;

View File

@@ -37,7 +37,7 @@
], ],
"paths": { "paths": {
"@payload-config": [ "@payload-config": [
"./test/_community/config.ts" "./test/live-preview/config.ts"
], ],
"@payloadcms/live-preview": [ "@payloadcms/live-preview": [
"./packages/live-preview/src" "./packages/live-preview/src"