fix(richtext-*): RichText Cell components (#5174)

* fix(richtext-*): RichText Cell components

* better code
This commit is contained in:
Alessio Gravili
2024-02-26 15:37:50 -05:00
committed by GitHub
parent 75c4b4f234
commit a0cf2ea56b
8 changed files with 53 additions and 69 deletions

View File

@@ -1,14 +1,10 @@
'use client'
import type { CellComponentProps, RichTextField } from 'payload/types'
import type { CellComponentProps } from 'payload/types'
import React from 'react'
import type { AdapterArguments } from '../types'
const RichTextCell: React.FC<
CellComponentProps<RichTextField<any[], AdapterArguments, AdapterArguments>, any>
> = ({ data }) => {
const flattenedText = data?.map((i) => i?.children?.map((c) => c.text)).join(' ')
const RichTextCell: React.FC<CellComponentProps<any[]>> = ({ cellData }) => {
const flattenedText = cellData?.map((i) => i?.children?.map((c) => c.text)).join(' ')
// Limiting the number of characters shown is done in a CSS rule
return <span>{flattenedText}</span>

View File

@@ -1,6 +1,5 @@
import type { RichTextAdapter } from 'payload/types'
import { withMergedProps } from '@payloadcms/ui/utilities'
import { withNullableJSONSchemaType } from 'payload/utilities'
import type { AdapterArguments } from './types'
@@ -14,22 +13,16 @@ import { getGenerateSchemaMap } from './generateSchemaMap'
export function slateEditor(args: AdapterArguments): RichTextAdapter<any[], AdapterArguments, any> {
return {
CellComponent: withMergedProps({
Component: RichTextCell,
toMergeIntoProps: args,
}),
FieldComponent: withMergedProps({
Component: RichTextField,
toMergeIntoProps: args,
}),
CellComponent: RichTextCell,
FieldComponent: RichTextField,
generateComponentMap: getGenerateComponentMap(args),
generateSchemaMap: getGenerateSchemaMap(args),
outputSchema: ({ isRequired }) => {
return {
type: withNullableJSONSchemaType('array', isRequired),
items: {
type: 'object',
},
type: withNullableJSONSchemaType('array', isRequired),
}
},
populationPromise({