fix(richtext-*): RichText Cell components (#5174)
* fix(richtext-*): RichText Cell components * better code
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user