Merge branch 'beta' into fix/lexical-localization

This commit is contained in:
Alessio Gravili
2024-04-23 15:20:56 -04:00
committed by GitHub
411 changed files with 7941 additions and 1785 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/richtext-slate",
"version": "3.0.0-beta.10",
"version": "3.0.0-beta.13",
"description": "The officially supported Slate richtext adapter for Payload",
"repository": {
"type": "git",

View File

@@ -9,12 +9,12 @@ export const richTextValidate: Validate<
unknown,
RichTextField<any[], AdapterArguments>,
RichTextField<any[], AdapterArguments>
> = (value, { required }) => {
> = (value, { req, required }) => {
const { t } = req
if (required) {
const stringifiedDefaultValue = JSON.stringify(defaultRichTextValue)
if (value && JSON.stringify(value) !== stringifiedDefaultValue) return true
// TODO: translate this string
return 'This field is required.'
return t('validation:required')
}
return true

View File

@@ -1,7 +1,7 @@
'use client'
import type { FormFieldBase } from '@payloadcms/ui/fields/shared'
import type { FieldBase } from 'payload/types'
import type { ClientValidate, FieldBase } from 'payload/types'
import type { BaseEditor, BaseOperation } from 'slate'
import type { HistoryEditor } from 'slate-history'
import type { ReactEditor } from 'slate-react'
@@ -88,13 +88,19 @@ const RichTextField: React.FC<
const drawerDepth = useEditDepth()
const drawerIsOpen = drawerDepth > 1
const memoizedValidate = useCallback(
const memoizedValidate: ClientValidate = useCallback(
(value, validationOptions) => {
if (typeof validate === 'function') {
return validate(value, { ...validationOptions, required })
return validate(value, {
...validationOptions,
req: {
t: i18n.t,
},
required,
})
}
},
[validate, required],
[validate, required, i18n],
)
const { path: pathFromContext } = useFieldProps()