chore: migrates from SanitizedConfig to ClientConfig types where necessary
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { ClientConfig } from 'payload/types'
|
import type { ClientCollectionConfig, ClientConfig, ClientGlobalConfig } from 'payload/types'
|
||||||
|
|
||||||
import { formatDocTitle, useDocumentInfo, useFormFields, useTranslation } from '@payloadcms/ui'
|
import { formatDocTitle, useDocumentInfo, useFormFields, useTranslation } from '@payloadcms/ui'
|
||||||
import { useEffect, useRef } from 'react'
|
import { useEffect, useRef } from 'react'
|
||||||
|
|
||||||
export const SetDocumentTitle: React.FC<{
|
export const SetDocumentTitle: React.FC<{
|
||||||
collectionConfig?: ClientConfig['collections'][0]
|
collectionConfig?: ClientCollectionConfig
|
||||||
config?: ClientConfig
|
config?: ClientConfig
|
||||||
fallback: string
|
fallback: string
|
||||||
globalConfig?: ClientConfig['globals'][0]
|
globalConfig?: ClientGlobalConfig
|
||||||
}> = (props) => {
|
}> = (props) => {
|
||||||
const { collectionConfig, config, fallback, globalConfig } = props
|
const { collectionConfig, config, fallback, globalConfig } = props
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { LivePreviewConfig } from 'payload/config'
|
import type { LivePreviewConfig } from 'payload/config'
|
||||||
import type { Field } from 'payload/types'
|
import type { ClientConfigField, Field } from 'payload/types'
|
||||||
|
|
||||||
import { DndContext } from '@dnd-kit/core'
|
import { DndContext } from '@dnd-kit/core'
|
||||||
import { fieldSchemaToJSON } from 'payload/utilities'
|
import { fieldSchemaToJSON } from 'payload/utilities'
|
||||||
@@ -20,7 +20,7 @@ export type LivePreviewProviderProps = {
|
|||||||
height: number
|
height: number
|
||||||
width: number
|
width: number
|
||||||
}
|
}
|
||||||
fieldSchema: Field[]
|
fieldSchema: ClientConfigField[]
|
||||||
isPopupOpen?: boolean
|
isPopupOpen?: boolean
|
||||||
openPopupWindow?: ReturnType<typeof usePopupWindow>['openPopupWindow']
|
openPopupWindow?: ReturnType<typeof usePopupWindow>['openPopupWindow']
|
||||||
popupRef?: React.MutableRefObject<Window>
|
popupRef?: React.MutableRefObject<Window>
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { FieldMap, FormProps } from '@payloadcms/ui'
|
import type { FieldMap, FormProps } from '@payloadcms/ui'
|
||||||
import type { LivePreviewConfig } from 'payload/config'
|
import type { LivePreviewConfig } from 'payload/config'
|
||||||
import type {
|
import type { ClientCollectionConfig, ClientConfig, ClientGlobalConfig, Data } from 'payload/types'
|
||||||
ClientConfig,
|
|
||||||
Data,
|
|
||||||
SanitizedCollectionConfig,
|
|
||||||
SanitizedGlobalConfig,
|
|
||||||
} from 'payload/types'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DocumentControls,
|
DocumentControls,
|
||||||
@@ -36,10 +31,10 @@ const baseClass = 'live-preview'
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
apiRoute: string
|
apiRoute: string
|
||||||
collectionConfig?: SanitizedCollectionConfig
|
collectionConfig?: ClientCollectionConfig
|
||||||
config: ClientConfig
|
config: ClientConfig
|
||||||
fieldMap: FieldMap
|
fieldMap: FieldMap
|
||||||
globalConfig?: SanitizedGlobalConfig
|
globalConfig?: ClientGlobalConfig
|
||||||
schemaPath: string
|
schemaPath: string
|
||||||
serverURL: string
|
serverURL: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { FieldMap, StepNavItem } from '@payloadcms/ui'
|
import type { FieldMap, StepNavItem } from '@payloadcms/ui'
|
||||||
import type { SanitizedCollectionConfig, SanitizedGlobalConfig } from 'payload/types'
|
import type { ClientCollectionConfig, ClientGlobalConfig } from 'payload/types'
|
||||||
import type React from 'react'
|
import type React from 'react'
|
||||||
|
|
||||||
import { getTranslation } from '@payloadcms/translations'
|
import { getTranslation } from '@payloadcms/translations'
|
||||||
@@ -7,11 +7,11 @@ import { formatDate, useConfig, useLocale, useStepNav, useTranslation } from '@p
|
|||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
export const SetStepNav: React.FC<{
|
export const SetStepNav: React.FC<{
|
||||||
collectionConfig?: SanitizedCollectionConfig
|
collectionConfig?: ClientCollectionConfig
|
||||||
collectionSlug?: string
|
collectionSlug?: string
|
||||||
doc: any
|
doc: any
|
||||||
fieldMap: FieldMap
|
fieldMap: FieldMap
|
||||||
globalConfig?: SanitizedGlobalConfig
|
globalConfig?: ClientGlobalConfig
|
||||||
globalSlug?: string
|
globalSlug?: string
|
||||||
id?: number | string
|
id?: number | string
|
||||||
mostRecentDoc: any
|
mostRecentDoc: any
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { ClientConfig } from 'payload/types'
|
import type { ClientCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import { getTranslation } from '@payloadcms/translations'
|
import { getTranslation } from '@payloadcms/translations'
|
||||||
import { type MappedField, useConfig } from '@payloadcms/ui'
|
import { type MappedField, useConfig } from '@payloadcms/ui'
|
||||||
@@ -21,7 +21,7 @@ const baseClass = 'relationship-diff'
|
|||||||
type RelationshipValue = Record<string, any>
|
type RelationshipValue = Record<string, any>
|
||||||
|
|
||||||
const generateLabelFromValue = (
|
const generateLabelFromValue = (
|
||||||
collections: ClientConfig['collections'],
|
collections: ClientCollectionConfig[],
|
||||||
field: MappedField,
|
field: MappedField,
|
||||||
locale: string,
|
locale: string,
|
||||||
value: { relationTo: string; value: RelationshipValue } | RelationshipValue,
|
value: { relationTo: string; value: RelationshipValue } | RelationshipValue,
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ export const sanitizeField = (f: Field) => {
|
|||||||
|
|
||||||
const sanitizeCollections = (
|
const sanitizeCollections = (
|
||||||
collections: SanitizedConfig['collections'],
|
collections: SanitizedConfig['collections'],
|
||||||
): ClientConfig['collections'] =>
|
): ClientCollectionConfig[] =>
|
||||||
collections.map((collection) => {
|
collections.map((collection) => {
|
||||||
const sanitized = { ...collection }
|
const sanitized = { ...collection }
|
||||||
sanitized.fields = sanitizeFields(sanitized.fields)
|
sanitized.fields = sanitizeFields(sanitized.fields)
|
||||||
@@ -212,7 +212,7 @@ const sanitizeCollections = (
|
|||||||
return sanitized
|
return sanitized
|
||||||
})
|
})
|
||||||
|
|
||||||
const sanitizeGlobals = (globals: SanitizedConfig['globals']): ClientConfig['globals'] =>
|
const sanitizeGlobals = (globals: SanitizedConfig['globals']): ClientGlobalConfig[] =>
|
||||||
globals.map((global) => {
|
globals.map((global) => {
|
||||||
const sanitized = { ...global }
|
const sanitized = { ...global }
|
||||||
sanitized.fields = sanitizeFields(sanitized.fields)
|
sanitized.fields = sanitizeFields(sanitized.fields)
|
||||||
|
|||||||
@@ -700,7 +700,7 @@ export type FieldWithMany = RelationshipField | SelectField
|
|||||||
|
|
||||||
export type FieldWithMaxDepth = RelationshipField | UploadField
|
export type FieldWithMaxDepth = RelationshipField | UploadField
|
||||||
|
|
||||||
export function fieldHasSubFields(field: Field): field is FieldWithSubFields {
|
export function fieldHasSubFields(field: ClientConfigField | Field): field is FieldWithSubFields {
|
||||||
return (
|
return (
|
||||||
field.type === 'group' ||
|
field.type === 'group' ||
|
||||||
field.type === 'array' ||
|
field.type === 'array' ||
|
||||||
@@ -743,11 +743,15 @@ export function fieldHasMaxDepth(field: Field): field is FieldWithMaxDepth {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fieldIsPresentationalOnly(field: Field | TabAsField): field is UIField {
|
export function fieldIsPresentationalOnly(
|
||||||
|
field: ClientConfigField | Field | TabAsField,
|
||||||
|
): field is UIField {
|
||||||
return field.type === 'ui'
|
return field.type === 'ui'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fieldAffectsData(field: Field | TabAsField): field is FieldAffectingData {
|
export function fieldAffectsData(
|
||||||
|
field: ClientConfigField | Field | TabAsField,
|
||||||
|
): field is FieldAffectingData {
|
||||||
return 'name' in field && !fieldIsPresentationalOnly(field)
|
return 'name' in field && !fieldIsPresentationalOnly(field)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { FieldTypes } from '../exports/config.js'
|
import type { FieldTypes } from '../exports/config.js'
|
||||||
import type { Field } from '../fields/config/types.js'
|
import type { ClientConfigField } from '../fields/config/types.js'
|
||||||
|
|
||||||
export type FieldSchemaJSON = {
|
export type FieldSchemaJSON = {
|
||||||
blocks?: FieldSchemaJSON // TODO: conditionally add based on `type`
|
blocks?: FieldSchemaJSON // TODO: conditionally add based on `type`
|
||||||
@@ -11,15 +11,17 @@ export type FieldSchemaJSON = {
|
|||||||
type: keyof FieldTypes
|
type: keyof FieldTypes
|
||||||
}[]
|
}[]
|
||||||
|
|
||||||
export const fieldSchemaToJSON = (fields: Field[]): FieldSchemaJSON => {
|
export const fieldSchemaToJSON = (fields: ClientConfigField[]): FieldSchemaJSON => {
|
||||||
return fields.reduce((acc, field) => {
|
return fields.reduce((acc, field) => {
|
||||||
let result = acc
|
let result = acc
|
||||||
|
|
||||||
switch (field.type) {
|
switch (field.type) {
|
||||||
case 'group':
|
case 'group':
|
||||||
acc.push({
|
acc.push({
|
||||||
|
// @ts-expect-error
|
||||||
name: field.name,
|
name: field.name,
|
||||||
type: field.type,
|
type: field.type,
|
||||||
|
// @ts-expect-error
|
||||||
fields: fieldSchemaToJSON(field.fields),
|
fields: fieldSchemaToJSON(field.fields),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -27,9 +29,11 @@ export const fieldSchemaToJSON = (fields: Field[]): FieldSchemaJSON => {
|
|||||||
|
|
||||||
case 'array':
|
case 'array':
|
||||||
acc.push({
|
acc.push({
|
||||||
|
// @ts-expect-error
|
||||||
name: field.name,
|
name: field.name,
|
||||||
type: field.type,
|
type: field.type,
|
||||||
fields: fieldSchemaToJSON([
|
fields: fieldSchemaToJSON([
|
||||||
|
// @ts-expect-error
|
||||||
...field.fields,
|
...field.fields,
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: 'id',
|
||||||
@@ -42,8 +46,10 @@ export const fieldSchemaToJSON = (fields: Field[]): FieldSchemaJSON => {
|
|||||||
|
|
||||||
case 'blocks':
|
case 'blocks':
|
||||||
acc.push({
|
acc.push({
|
||||||
|
// @ts-expect-error
|
||||||
name: field.name,
|
name: field.name,
|
||||||
type: field.type,
|
type: field.type,
|
||||||
|
// @ts-expect-error
|
||||||
blocks: field.blocks.reduce((acc, block) => {
|
blocks: field.blocks.reduce((acc, block) => {
|
||||||
acc[block.slug] = {
|
acc[block.slug] = {
|
||||||
fields: fieldSchemaToJSON([
|
fields: fieldSchemaToJSON([
|
||||||
@@ -63,12 +69,14 @@ export const fieldSchemaToJSON = (fields: Field[]): FieldSchemaJSON => {
|
|||||||
|
|
||||||
case 'row':
|
case 'row':
|
||||||
case 'collapsible':
|
case 'collapsible':
|
||||||
|
// @ts-expect-error
|
||||||
result = result.concat(fieldSchemaToJSON(field.fields))
|
result = result.concat(fieldSchemaToJSON(field.fields))
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'tabs': {
|
case 'tabs': {
|
||||||
let tabFields = []
|
let tabFields = []
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
field.tabs.forEach((tab) => {
|
field.tabs.forEach((tab) => {
|
||||||
if ('name' in tab) {
|
if ('name' in tab) {
|
||||||
tabFields.push({
|
tabFields.push({
|
||||||
@@ -90,9 +98,11 @@ export const fieldSchemaToJSON = (fields: Field[]): FieldSchemaJSON => {
|
|||||||
case 'relationship':
|
case 'relationship':
|
||||||
case 'upload':
|
case 'upload':
|
||||||
acc.push({
|
acc.push({
|
||||||
|
// @ts-expect-error
|
||||||
name: field.name,
|
name: field.name,
|
||||||
type: field.type,
|
type: field.type,
|
||||||
hasMany: 'hasMany' in field ? Boolean(field.hasMany) : false, // TODO: type this
|
hasMany: 'hasMany' in field ? Boolean(field.hasMany) : false, // TODO: type this
|
||||||
|
// @ts-expect-error
|
||||||
relationTo: field.relationTo,
|
relationTo: field.relationTo,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import type { Field, FieldAffectingData, FieldPresentationalOnly } from '../fields/config/types.js'
|
import type {
|
||||||
|
ClientConfigField,
|
||||||
|
Field,
|
||||||
|
FieldAffectingData,
|
||||||
|
FieldPresentationalOnly,
|
||||||
|
} from '../fields/config/types.js'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
fieldAffectsData,
|
fieldAffectsData,
|
||||||
fieldHasSubFields,
|
fieldHasSubFields,
|
||||||
fieldIsPresentationalOnly,
|
fieldIsPresentationalOnly,
|
||||||
tabHasName,
|
|
||||||
} from '../fields/config/types.js'
|
} from '../fields/config/types.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +19,7 @@ import {
|
|||||||
* @param keepPresentationalFields if true, will skip flattening fields that are presentational only
|
* @param keepPresentationalFields if true, will skip flattening fields that are presentational only
|
||||||
*/
|
*/
|
||||||
const flattenFields = (
|
const flattenFields = (
|
||||||
fields: Field[],
|
fields: (ClientConfigField | Field)[],
|
||||||
keepPresentationalFields?: boolean,
|
keepPresentationalFields?: boolean,
|
||||||
): (FieldAffectingData | FieldPresentationalOnly)[] => {
|
): (FieldAffectingData | FieldPresentationalOnly)[] => {
|
||||||
return fields.reduce((fieldsToUse, field) => {
|
return fields.reduce((fieldsToUse, field) => {
|
||||||
@@ -27,19 +31,6 @@ const flattenFields = (
|
|||||||
return [...fieldsToUse, ...flattenFields(field.fields, keepPresentationalFields)]
|
return [...fieldsToUse, ...flattenFields(field.fields, keepPresentationalFields)]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.type === 'tabs') {
|
|
||||||
return [
|
|
||||||
...fieldsToUse,
|
|
||||||
...field.tabs.reduce((tabFields, tab) => {
|
|
||||||
return [
|
|
||||||
...tabFields,
|
|
||||||
...(tabHasName(tab)
|
|
||||||
? [{ ...tab, type: 'tab' }]
|
|
||||||
: flattenFields(tab.fields, keepPresentationalFields)),
|
|
||||||
]
|
|
||||||
}, []),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
return fieldsToUse
|
return fieldsToUse
|
||||||
}, [])
|
}, [])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { ClientUser } from 'payload/auth'
|
import type { ClientUser } from 'payload/auth'
|
||||||
import type { SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import { useAuth, useConfig } from '@payloadcms/ui'
|
import { useAuth, useConfig } from '@payloadcms/ui'
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
@@ -10,9 +10,9 @@ type options = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FilteredCollectionsT = (
|
type FilteredCollectionsT = (
|
||||||
collections: SanitizedCollectionConfig[],
|
collections: ClientCollectionConfig[],
|
||||||
options?: options,
|
options?: options,
|
||||||
) => SanitizedCollectionConfig[]
|
) => ClientCollectionConfig[]
|
||||||
const filterRichTextCollections: FilteredCollectionsT = (collections, options) => {
|
const filterRichTextCollections: FilteredCollectionsT = (collections, options) => {
|
||||||
return collections.filter(({ admin: { enableRichTextRelationship, hidden }, upload }) => {
|
return collections.filter(({ admin: { enableRichTextRelationship, hidden }, upload }) => {
|
||||||
if (hidden === true || (typeof hidden === 'function' && hidden({ user: options.user }))) {
|
if (hidden === true || (typeof hidden === 'function' && hidden({ user: options.user }))) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { FormState, SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig, FormState } from 'payload/types'
|
||||||
|
|
||||||
import * as facelessUIImport from '@faceless-ui/modal'
|
import * as facelessUIImport from '@faceless-ui/modal'
|
||||||
import lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'
|
import lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'
|
||||||
@@ -7,7 +7,6 @@ const { useLexicalComposerContext } = lexicalComposerContextImport
|
|||||||
import { getTranslation } from '@payloadcms/translations'
|
import { getTranslation } from '@payloadcms/translations'
|
||||||
import {
|
import {
|
||||||
Drawer,
|
Drawer,
|
||||||
FieldPathProvider,
|
|
||||||
Form,
|
Form,
|
||||||
type FormProps,
|
type FormProps,
|
||||||
FormSubmit,
|
FormSubmit,
|
||||||
@@ -37,7 +36,7 @@ import { useEditorConfigContext } from '../../../../lexical/config/client/Editor
|
|||||||
export const ExtraFieldsUploadDrawer: React.FC<
|
export const ExtraFieldsUploadDrawer: React.FC<
|
||||||
ElementProps & {
|
ElementProps & {
|
||||||
drawerSlug: string
|
drawerSlug: string
|
||||||
relatedCollection: SanitizedCollectionConfig
|
relatedCollection: ClientCollectionConfig
|
||||||
}
|
}
|
||||||
> = (props) => {
|
> = (props) => {
|
||||||
const { useModal } = facelessUIImport
|
const { useModal } = facelessUIImport
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'
|
import lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'
|
||||||
const { useLexicalComposerContext } = lexicalComposerContextImport
|
const { useLexicalComposerContext } = lexicalComposerContextImport
|
||||||
@@ -61,7 +61,7 @@ const Component: React.FC<ElementProps> = (props) => {
|
|||||||
|
|
||||||
const { i18n, t } = useTranslation()
|
const { i18n, t } = useTranslation()
|
||||||
const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)
|
const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)
|
||||||
const [relatedCollection, setRelatedCollection] = useState<SanitizedCollectionConfig>(() =>
|
const [relatedCollection, setRelatedCollection] = useState<ClientCollectionConfig>(() =>
|
||||||
collections.find((coll) => coll.slug === relationTo),
|
collections.find((coll) => coll.slug === relationTo),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import type { ClientUser } from 'payload/auth'
|
import type { ClientUser } from 'payload/auth'
|
||||||
import type { SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import { useAuth, useConfig } from '@payloadcms/ui/providers'
|
import { useAuth, useConfig } from '@payloadcms/ui/providers'
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
@@ -12,9 +12,9 @@ type options = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FilteredCollectionsT = (
|
type FilteredCollectionsT = (
|
||||||
collections: SanitizedCollectionConfig[],
|
collections: ClientCollectionConfig[],
|
||||||
options?: options,
|
options?: options,
|
||||||
) => SanitizedCollectionConfig[]
|
) => ClientCollectionConfig[]
|
||||||
const filterRichTextCollections: FilteredCollectionsT = (collections, options) => {
|
const filterRichTextCollections: FilteredCollectionsT = (collections, options) => {
|
||||||
return collections.filter(({ admin: { enableRichTextRelationship, hidden }, upload }) => {
|
return collections.filter(({ admin: { enableRichTextRelationship, hidden }, upload }) => {
|
||||||
if (hidden === true || (typeof hidden === 'function' && hidden({ user: options.user }))) {
|
if (hidden === true || (typeof hidden === 'function' && hidden({ user: options.user }))) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import type { FormFieldBase } from '@payloadcms/ui/types'
|
import type { FormFieldBase } from '@payloadcms/ui/types'
|
||||||
import type { SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import * as facelessUIImport from '@faceless-ui/modal'
|
import * as facelessUIImport from '@faceless-ui/modal'
|
||||||
import { getTranslation } from '@payloadcms/translations'
|
import { getTranslation } from '@payloadcms/translations'
|
||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
useLocale,
|
useLocale,
|
||||||
useTranslation,
|
useTranslation,
|
||||||
} from '@payloadcms/ui'
|
} from '@payloadcms/ui'
|
||||||
import { FieldPathProvider } from '@payloadcms/ui/forms'
|
|
||||||
import { deepCopyObject } from 'payload/utilities'
|
import { deepCopyObject } from 'payload/utilities'
|
||||||
import React, { useCallback, useEffect, useState } from 'react'
|
import React, { useCallback, useEffect, useState } from 'react'
|
||||||
import { Transforms } from 'slate'
|
import { Transforms } from 'slate'
|
||||||
@@ -34,7 +33,7 @@ export const UploadDrawer: React.FC<{
|
|||||||
name: string
|
name: string
|
||||||
richTextComponentMap: Map<string, React.ReactNode>
|
richTextComponentMap: Map<string, React.ReactNode>
|
||||||
}
|
}
|
||||||
relatedCollection: SanitizedCollectionConfig
|
relatedCollection: ClientCollectionConfig
|
||||||
schemaPath: string
|
schemaPath: string
|
||||||
}> = (props) => {
|
}> = (props) => {
|
||||||
const { useModal } = facelessUIImport
|
const { useModal } = facelessUIImport
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import type { FormFieldBase } from '@payloadcms/ui/types'
|
import type { FormFieldBase } from '@payloadcms/ui/types'
|
||||||
import type { SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import { getTranslation } from '@payloadcms/translations'
|
import { getTranslation } from '@payloadcms/translations'
|
||||||
import {
|
import {
|
||||||
@@ -58,7 +58,7 @@ const UploadElement: React.FC<Props & { enabledCollectionSlugs?: string[] }> = (
|
|||||||
} = useConfig()
|
} = useConfig()
|
||||||
const { i18n, t } = useTranslation()
|
const { i18n, t } = useTranslation()
|
||||||
const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)
|
const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)
|
||||||
const [relatedCollection, setRelatedCollection] = useState<SanitizedCollectionConfig>(() =>
|
const [relatedCollection, setRelatedCollection] = useState<ClientCollectionConfig>(() =>
|
||||||
collections.find((coll) => coll.slug === relationTo),
|
collections.find((coll) => coll.slug === relationTo),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { SanitizedCollectionConfig, SanitizedGlobalConfig } from 'payload/types'
|
import type { ClientCollectionConfig, ClientGlobalConfig } from 'payload/types'
|
||||||
|
|
||||||
export type Props = {
|
export type Props = {
|
||||||
collection?: SanitizedCollectionConfig
|
collection?: ClientCollectionConfig
|
||||||
global?: SanitizedGlobalConfig
|
global?: ClientGlobalConfig
|
||||||
id?: number | string
|
id?: number | string
|
||||||
publishedDocUpdatedAt: string
|
publishedDocUpdatedAt: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig } from 'payload/types'
|
||||||
import type { Where } from 'payload/types'
|
import type { Where } from 'payload/types'
|
||||||
|
|
||||||
import * as facelessUIImport from '@faceless-ui/modal'
|
import * as facelessUIImport from '@faceless-ui/modal'
|
||||||
@@ -75,13 +75,14 @@ export const ListDrawerContent: React.FC<ListDrawerProps> = ({
|
|||||||
return collectionSlugs.includes(slug)
|
return collectionSlugs.includes(slug)
|
||||||
})
|
})
|
||||||
|
|
||||||
const [selectedCollectionConfig, setSelectedCollectionConfig] =
|
const [selectedCollectionConfig, setSelectedCollectionConfig] = useState<ClientCollectionConfig>(
|
||||||
useState<SanitizedCollectionConfig>(() => {
|
() => {
|
||||||
return (
|
return (
|
||||||
enabledCollectionConfigs.find(({ slug }) => slug === selectedCollection) ||
|
enabledCollectionConfigs.find(({ slug }) => slug === selectedCollection) ||
|
||||||
enabledCollectionConfigs?.[0]
|
enabledCollectionConfigs?.[0]
|
||||||
)
|
)
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
const { List } = componentMap.collections?.[selectedCollectionConfig?.slug] || {}
|
const { List } = componentMap.collections?.[selectedCollectionConfig?.slug] || {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { I18n } from '@payloadcms/translations'
|
import type { I18n } from '@payloadcms/translations'
|
||||||
import type { PaginatedDocs } from 'payload/database'
|
import type { PaginatedDocs } from 'payload/database'
|
||||||
import type { RelationshipField, SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig, RelationshipField } from 'payload/types'
|
||||||
|
|
||||||
export type Props = {
|
export type Props = {
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
@@ -22,7 +22,7 @@ type CLEAR = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ADD = {
|
type ADD = {
|
||||||
collection: SanitizedCollectionConfig
|
collection: ClientCollectionConfig
|
||||||
data: PaginatedDocs<any>
|
data: PaginatedDocs<any>
|
||||||
hasMultipleRelations: boolean
|
hasMultipleRelations: boolean
|
||||||
i18n: I18n
|
i18n: I18n
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import { getTranslation } from '@payloadcms/translations'
|
import { getTranslation } from '@payloadcms/translations'
|
||||||
import React, { Fragment, useCallback, useEffect, useState } from 'react'
|
import React, { Fragment, useCallback, useEffect, useState } from 'react'
|
||||||
@@ -34,7 +34,7 @@ export const AddNewRelation: React.FC<Props> = ({
|
|||||||
const [show, setShow] = useState(false)
|
const [show, setShow] = useState(false)
|
||||||
const [selectedCollection, setSelectedCollection] = useState<string>()
|
const [selectedCollection, setSelectedCollection] = useState<string>()
|
||||||
const relatedToMany = relatedCollections.length > 1
|
const relatedToMany = relatedCollections.length > 1
|
||||||
const [collectionConfig, setCollectionConfig] = useState<SanitizedCollectionConfig>(() =>
|
const [collectionConfig, setCollectionConfig] = useState<ClientCollectionConfig>(() =>
|
||||||
!relatedToMany ? relatedCollections[0] : undefined,
|
!relatedToMany ? relatedCollections[0] : undefined,
|
||||||
)
|
)
|
||||||
const [popupOpen, setPopupOpen] = useState(false)
|
const [popupOpen, setPopupOpen] = useState(false)
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import type { ClientConfig, SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig } from 'payload/types'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
import { useConfig } from '../../../../providers/Config/index.js'
|
import { useConfig } from '../../../../providers/Config/index.js'
|
||||||
|
|
||||||
export const useRelatedCollections = (
|
export const useRelatedCollections = (relationTo: string | string[]): ClientCollectionConfig[] => {
|
||||||
relationTo: string | string[],
|
|
||||||
): ClientConfig['collections'] => {
|
|
||||||
const config = useConfig()
|
const config = useConfig()
|
||||||
|
|
||||||
const [relatedCollections] = useState(() => {
|
const [relatedCollections] = useState(() => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { I18n } from '@payloadcms/translations'
|
import type { I18n } from '@payloadcms/translations'
|
||||||
import type { RelationshipField, SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig, RelationshipField } from 'payload/types'
|
||||||
import type { SanitizedConfig } from 'payload/types'
|
import type { SanitizedConfig } from 'payload/types'
|
||||||
|
|
||||||
import type { FormFieldBase } from '../shared.js'
|
import type { FormFieldBase } from '../shared.js'
|
||||||
@@ -38,7 +38,7 @@ type CLEAR = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UPDATE = {
|
type UPDATE = {
|
||||||
collection: SanitizedCollectionConfig
|
collection: ClientCollectionConfig
|
||||||
config: SanitizedConfig
|
config: SanitizedConfig
|
||||||
doc: any
|
doc: any
|
||||||
i18n: I18n
|
i18n: I18n
|
||||||
@@ -46,7 +46,7 @@ type UPDATE = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ADD = {
|
type ADD = {
|
||||||
collection: SanitizedCollectionConfig
|
collection: ClientCollectionConfig
|
||||||
config: SanitizedConfig
|
config: SanitizedConfig
|
||||||
docs: any[]
|
docs: any[]
|
||||||
i18n: I18n
|
i18n: I18n
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import type { FilterOptionsResult, SanitizedCollectionConfig, UploadField } from 'payload/types'
|
import type { ClientCollectionConfig, FilterOptionsResult, UploadField } from 'payload/types'
|
||||||
|
|
||||||
import { getTranslation } from '@payloadcms/translations'
|
import { getTranslation } from '@payloadcms/translations'
|
||||||
import React, { useCallback, useEffect, useState } from 'react'
|
import React, { useCallback, useEffect, useState } from 'react'
|
||||||
@@ -22,7 +22,7 @@ const baseClass = 'upload'
|
|||||||
|
|
||||||
export type UploadInputProps = Omit<UploadFieldProps, 'filterOptions'> & {
|
export type UploadInputProps = Omit<UploadFieldProps, 'filterOptions'> & {
|
||||||
api?: string
|
api?: string
|
||||||
collection?: SanitizedCollectionConfig
|
collection?: ClientCollectionConfig
|
||||||
filterOptions?: FilterOptionsResult
|
filterOptions?: FilterOptionsResult
|
||||||
onChange?: (e) => void
|
onChange?: (e) => void
|
||||||
relationTo?: UploadField['relationTo']
|
relationTo?: UploadField['relationTo']
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { FieldAffectingData, SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig, FieldAffectingData } from 'payload/types'
|
||||||
|
|
||||||
import { fieldAffectsData } from 'payload/types'
|
import { fieldAffectsData } from 'payload/types'
|
||||||
import { flattenTopLevelFields } from 'payload/utilities'
|
import { flattenTopLevelFields } from 'payload/utilities'
|
||||||
|
|
||||||
export const useUseTitleField = (collection: SanitizedCollectionConfig): FieldAffectingData => {
|
export const useUseTitleField = (collection: ClientCollectionConfig): FieldAffectingData => {
|
||||||
const {
|
const {
|
||||||
admin: { useAsTitle },
|
admin: { useAsTitle },
|
||||||
fields,
|
fields,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import type { PaginatedDocs, TypeWithVersion } from 'payload/database'
|
import type { PaginatedDocs, TypeWithVersion } from 'payload/database'
|
||||||
import type {
|
import type {
|
||||||
|
ClientCollectionConfig,
|
||||||
|
ClientGlobalConfig,
|
||||||
Data,
|
Data,
|
||||||
DocumentPermissions,
|
DocumentPermissions,
|
||||||
DocumentPreferences,
|
DocumentPreferences,
|
||||||
@@ -34,7 +36,7 @@ export type DocumentInfoProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type DocumentInfo = DocumentInfoProps & {
|
export type DocumentInfo = DocumentInfoProps & {
|
||||||
docConfig?: SanitizedCollectionConfig | SanitizedGlobalConfig
|
docConfig?: ClientCollectionConfig | ClientGlobalConfig
|
||||||
preferencesKey?: string
|
preferencesKey?: string
|
||||||
publishedDoc?: TypeWithID & TypeWithTimestamps & { _status?: string }
|
publishedDoc?: TypeWithID & TypeWithTimestamps & { _status?: string }
|
||||||
slug?: string
|
slug?: string
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { I18n } from '@payloadcms/translations'
|
import type { I18n } from '@payloadcms/translations'
|
||||||
import type {
|
import type {
|
||||||
SanitizedCollectionConfig,
|
ClientCollectionConfig,
|
||||||
|
ClientGlobalConfig,
|
||||||
SanitizedConfig,
|
SanitizedConfig,
|
||||||
SanitizedGlobalConfig,
|
|
||||||
TypeWithID,
|
TypeWithID,
|
||||||
} from 'payload/types'
|
} from 'payload/types'
|
||||||
|
|
||||||
@@ -17,11 +17,11 @@ export const formatDocTitle = ({
|
|||||||
globalConfig,
|
globalConfig,
|
||||||
i18n,
|
i18n,
|
||||||
}: {
|
}: {
|
||||||
collectionConfig?: SanitizedCollectionConfig
|
collectionConfig?: ClientCollectionConfig
|
||||||
data: TypeWithID
|
data: TypeWithID
|
||||||
dateFormat: SanitizedConfig['admin']['dateFormat']
|
dateFormat: SanitizedConfig['admin']['dateFormat']
|
||||||
fallback?: string
|
fallback?: string
|
||||||
globalConfig?: SanitizedGlobalConfig
|
globalConfig?: ClientGlobalConfig
|
||||||
i18n: I18n
|
i18n: I18n
|
||||||
}): string => {
|
}): string => {
|
||||||
let title: string
|
let title: string
|
||||||
@@ -40,7 +40,9 @@ export const formatDocTitle = ({
|
|||||||
const isDate = fieldConfig?.type === 'date'
|
const isDate = fieldConfig?.type === 'date'
|
||||||
|
|
||||||
if (isDate) {
|
if (isDate) {
|
||||||
const dateFormat = fieldConfig?.admin?.date?.displayFormat || dateFormatFromConfig
|
const dateFormat =
|
||||||
|
('date' in fieldConfig.admin && fieldConfig?.admin?.date?.displayFormat) ||
|
||||||
|
dateFormatFromConfig
|
||||||
title = formatDate(title, dateFormat, i18n.language) || title
|
title = formatDate(title, dateFormat, i18n.language) || title
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import type { I18n } from '@payloadcms/translations'
|
import type { I18n } from '@payloadcms/translations'
|
||||||
import type { Permissions } from 'payload/auth'
|
import type { Permissions } from 'payload/auth'
|
||||||
import type { SanitizedCollectionConfig } from 'payload/types'
|
import type { ClientCollectionConfig, ClientGlobalConfig } from 'payload/types'
|
||||||
import type { SanitizedGlobalConfig } from 'payload/types'
|
|
||||||
|
|
||||||
import { getTranslation } from '@payloadcms/translations'
|
import { getTranslation } from '@payloadcms/translations'
|
||||||
|
|
||||||
@@ -12,11 +11,11 @@ export enum EntityType {
|
|||||||
|
|
||||||
export type EntityToGroup =
|
export type EntityToGroup =
|
||||||
| {
|
| {
|
||||||
entity: SanitizedCollectionConfig
|
entity: ClientCollectionConfig
|
||||||
type: EntityType.collection
|
type: EntityType.collection
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
entity: SanitizedGlobalConfig
|
entity: ClientGlobalConfig
|
||||||
type: EntityType.global
|
type: EntityType.global
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user