diff --git a/packages/richtext-lexical/src/field/Field.tsx b/packages/richtext-lexical/src/field/Field.tsx index 0212719ab..dcd42996b 100644 --- a/packages/richtext-lexical/src/field/Field.tsx +++ b/packages/richtext-lexical/src/field/Field.tsx @@ -7,7 +7,6 @@ import { ErrorBoundary } from 'react-error-boundary' import type { SanitizedClientEditorConfig } from './lexical/config/types' -import { richTextValidateHOC } from '../validate' import './index.scss' import { LexicalProvider } from './lexical/LexicalProvider' @@ -22,36 +21,24 @@ const RichText: React.FC< > = (props) => { const { name, - AfterInput, - BeforeInput, Description, Error, Label, className, - docPreferences, editorConfig, - fieldMap, - initialSubfieldState, - label, - locale, - localized, - maxLength, - minLength, path: pathFromProps, - placeholder, readOnly, required, - richTextComponentMap, - rtl, style, - user, - validate = richTextValidateHOC({ editorConfig }), + validate, // Users can pass in client side validation if they WANT to, but it's not required anymore width, } = props const memoizedValidate = useCallback( (value, validationOptions) => { - return validate(value, { ...validationOptions, props, required }) + if (typeof validate === 'function') { + return validate(value, { ...validationOptions, props, required }) + } }, // Important: do not add props to the dependencies array. // This would cause an infinite loop and endless re-rendering. diff --git a/packages/richtext-lexical/src/field/features/Blocks/component/BlockContent.tsx b/packages/richtext-lexical/src/field/features/Blocks/component/BlockContent.tsx index ca7ab2b0e..64f549195 100644 --- a/packages/richtext-lexical/src/field/features/Blocks/component/BlockContent.tsx +++ b/packages/richtext-lexical/src/field/features/Blocks/component/BlockContent.tsx @@ -1,14 +1,15 @@ -import type { FormState } from '@payloadcms/ui' -import type { Block, Data, Field } from 'payload/types' +import type { SanitizedClientEditorConfig } from '@payloadcms/richtext-lexical' +import type { FormFieldBase, FormState } from '@payloadcms/ui' +import type { Data, Field } from 'payload/types' import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' import { getTranslation } from '@payloadcms/translations' +import { RenderFields } from '@payloadcms/ui' import { Button, Collapsible, ErrorPill, Pill, - RenderFields, SectionTitle, createNestedFieldPath, useDocumentInfo, @@ -19,6 +20,7 @@ import isDeepEqual from 'deep-equal' import { $getNodeByKey } from 'lexical' import React, { useCallback } from 'react' +import type { ReducedBlock } from '../../../../../../ui/src/utilities/buildComponentMap/types' import type { FieldProps } from '../../../../types' import type { BlockFields, BlockNode } from '../nodes/BlocksNode' @@ -26,11 +28,15 @@ import { FormSavePlugin } from './FormSavePlugin' type Props = { baseClass: string - block: Block - field: FieldProps + field: FormFieldBase & { + editorConfig: SanitizedClientEditorConfig // With rendered features n stuff + name: string + richTextComponentMap: Map + } formData: BlockFields formSchema: Field[] nodeKey: string + reducedBlock: ReducedBlock } /** @@ -41,12 +47,13 @@ type Props = { export const BlockContent: React.FC = (props) => { const { baseClass, - block: { labels }, field, formData, formSchema, nodeKey, + reducedBlock: { labels }, } = props + const { i18n } = useTranslation() const [editor] = useLexicalComposerContext() // Used for saving collapsed to preferences (and gettin' it from there again) @@ -92,10 +99,17 @@ export const BlockContent: React.FC = (props) => { fullFieldsWithValues: FormState newFormData: Data }) => { + newFormData = { + ...newFormData, + id: formData.id, // TODO: Why does form updatee not include theeeeem + blockName: formData.blockName, // TODO: Why does form updatee not include theeeeem + blockType: formData.blockType, // TODO: Why does form updatee not include theeeeem + } + // Recursively remove all undefined values from even being present in formData, as they will // cause isDeepEqual to return false if, for example, formData has a key that fields.data // does not have, even if it's undefined. - // Currently, this happens if a block has another sub-blocks field. Inside of formData, that sub-blocks field has an undefined blockName property. + // Currently, this happens if a block has another sub-blocks field. Inside formData, that sub-blocks field has an undefined blockName property. // Inside of fields.data however, that sub-blocks blockName property does not exist at all. function removeUndefinedAndNullRecursively(obj: object) { Object.keys(obj).forEach((key) => { @@ -109,6 +123,8 @@ export const BlockContent: React.FC = (props) => { removeUndefinedAndNullRecursively(newFormData) removeUndefinedAndNullRecursively(formData) + console.log('before saving node data...', newFormData, 'old', formData) + // Only update if the data has actually changed. Otherwise, we may be triggering an unnecessary value change, // which would trigger the "Leave without saving" dialog unnecessarily if (!isDeepEqual(formData, newFormData)) { @@ -120,6 +136,7 @@ export const BlockContent: React.FC = (props) => { editor.update(() => { const node: BlockNode = $getNodeByKey(nodeKey) if (node) { + console.log('saving node data...', newFormData) node.setFields(newFormData as BlockFields) } }) @@ -163,11 +180,6 @@ export const BlockContent: React.FC = (props) => { }) }, [editor, nodeKey]) - const fieldSchemaWithPath = formSchema.map((field) => ({ - ...field, - path: createNestedFieldPath(null, field), - })) - return ( = (props) => { : '[Singular Label]'} - {fieldHasErrors && } + {fieldHasErrors && } {editor.isEditable() && (