chore: improves field types (#9172)

### What?
Ensures `path` is required and only present on the fields that expect it
(all fields except row).

Deprecates `useFieldComponents` and `FieldComponentsProvider` and
instead extends the RenderField component to account for all field
types. This also improves type safety within `RenderField`.

### Why?
`path` being optional just adds DX overhead and annoyance. 

### How?
Added `FieldPaths` type which is added to iterable field types. Placed
`path` back onto the ClientFieldBase type.
This commit is contained in:
Jarrod Flesch
2024-11-13 13:53:47 -05:00
committed by GitHub
parent cd95daf029
commit bcbca0e44a
68 changed files with 305 additions and 281 deletions

View File

@@ -1,13 +1,13 @@
import type {
ClientComponentProps,
ClientField,
Field,
FieldPaths,
RichTextFieldClient,
ServerComponentProps } from 'payload'
import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'
import {
type ClientComponentProps,
type ClientField,
createClientFields,
deepCopyObjectSimple,
type Field,
type RichTextFieldClient,
type ServerComponentProps,
} from 'payload'
import { createClientFields, deepCopyObjectSimple } from 'payload'
import React from 'react'
import type { AdapterArguments, RichTextCustomElement, RichTextCustomLeaf } from '../types.js'
@@ -22,15 +22,13 @@ export const RscEntrySlateField: React.FC<
{
args: AdapterArguments
} & ClientComponentProps &
Pick<FieldPaths, 'path'> &
ServerComponentProps
> = ({
args,
clientField,
forceRender,
i18n,
indexPath,
parentPath,
parentSchemaPath,
path,
payload,
readOnly,
@@ -191,9 +189,6 @@ export const RscEntrySlateField: React.FC<
componentMap={Object.fromEntries(componentMap)}
field={clientField as RichTextFieldClient}
forceRender={forceRender}
indexPath={indexPath}
parentPath={parentPath}
parentSchemaPath={parentSchemaPath}
path={path}
readOnly={readOnly}
renderedBlocks={renderedBlocks}