Merge branch 'main' of github.com:payloadcms/payload
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
'use client'
|
||||
import type { SerializedEditorState } from 'lexical'
|
||||
import type { CellComponentProps, RichTextField } from 'payload/types'
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ const RichText: React.FC<FieldProps> = (props) => {
|
||||
validate: memoizedValidate,
|
||||
})
|
||||
|
||||
const { errorMessage, initialValue, setValue, showError, value } = fieldType
|
||||
const { errorMessage, setValue, showError, value } = fieldType
|
||||
|
||||
let valueToUse = value
|
||||
|
||||
@@ -87,7 +87,6 @@ const RichText: React.FC<FieldProps> = (props) => {
|
||||
<LexicalProvider
|
||||
editorConfig={editorConfig}
|
||||
fieldProps={props}
|
||||
initialState={initialValue}
|
||||
onChange={(editorState, editor, tags) => {
|
||||
let serializedEditorState = editorState.toJSON()
|
||||
|
||||
@@ -101,7 +100,6 @@ const RichText: React.FC<FieldProps> = (props) => {
|
||||
setValue(serializedEditorState)
|
||||
}}
|
||||
readOnly={readOnly}
|
||||
setValue={setValue}
|
||||
value={value}
|
||||
/>
|
||||
<FieldDescription description={description} value={value} />
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
'use client'
|
||||
import { ShimmerEffect } from 'payload/components'
|
||||
import React, { Suspense, lazy } from 'react'
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ import { AddBlockHandlePlugin } from './plugins/handles/AddBlockHandlePlugin'
|
||||
import { DraggableBlockPlugin } from './plugins/handles/DraggableBlockPlugin'
|
||||
import { LexicalContentEditable } from './ui/ContentEditable'
|
||||
|
||||
export const LexicalEditor: React.FC<LexicalProviderProps> = (props) => {
|
||||
export const LexicalEditor: React.FC<Pick<LexicalProviderProps, 'editorConfig' | 'onChange'>> = (
|
||||
props,
|
||||
) => {
|
||||
const { editorConfig, onChange } = props
|
||||
const [editor] = useLexicalComposerContext()
|
||||
|
||||
|
||||
@@ -14,28 +14,21 @@ import { getEnabledNodes } from './nodes'
|
||||
export type LexicalProviderProps = {
|
||||
editorConfig: SanitizedEditorConfig
|
||||
fieldProps: FieldProps
|
||||
initialState: SerializedEditorState
|
||||
onChange: (editorState: EditorState, editor: LexicalEditor, tags: Set<string>) => void
|
||||
readOnly: boolean
|
||||
setValue: (value: SerializedEditorState) => void
|
||||
value: SerializedEditorState
|
||||
}
|
||||
export const LexicalProvider: React.FC<LexicalProviderProps> = (props) => {
|
||||
const { editorConfig, fieldProps, onChange, readOnly, setValue } = props
|
||||
let { initialState, value } = props
|
||||
const { editorConfig, fieldProps, onChange, readOnly } = props
|
||||
let { value } = props
|
||||
|
||||
// Transform initialState through load hooks
|
||||
if (editorConfig?.features?.hooks?.load?.length) {
|
||||
editorConfig.features.hooks.load.forEach((hook) => {
|
||||
initialState = hook({ incomingEditorState: initialState })
|
||||
value = hook({ incomingEditorState: value })
|
||||
})
|
||||
}
|
||||
|
||||
if (
|
||||
(value && Array.isArray(value) && !('root' in value)) ||
|
||||
(initialState && Array.isArray(initialState) && !('root' in initialState))
|
||||
) {
|
||||
if (value && Array.isArray(value) && !('root' in value)) {
|
||||
throw new Error(
|
||||
'You have tried to pass in data from the old, Slate editor, to the new, Lexical editor. This is not supported. There is no automatic conversion from Slate to Lexical data available yet (coming soon). Please remove the data from the field and start again.',
|
||||
)
|
||||
@@ -49,7 +42,7 @@ export const LexicalProvider: React.FC<LexicalProviderProps> = (props) => {
|
||||
|
||||
const initialConfig: InitialConfigType = {
|
||||
editable: readOnly === true ? false : true,
|
||||
editorState: initialState != null ? JSON.stringify(initialState) : undefined,
|
||||
editorState: value != null ? JSON.stringify(value) : undefined,
|
||||
namespace: editorConfig.lexical.namespace,
|
||||
nodes: [...getEnabledNodes({ editorConfig })],
|
||||
onError: (error: Error) => {
|
||||
@@ -62,15 +55,7 @@ export const LexicalProvider: React.FC<LexicalProviderProps> = (props) => {
|
||||
<LexicalComposer initialConfig={initialConfig}>
|
||||
<EditorConfigProvider editorConfig={editorConfig} fieldProps={fieldProps}>
|
||||
<div className="editor-shell">
|
||||
<LexicalEditorComponent
|
||||
editorConfig={editorConfig}
|
||||
fieldProps={fieldProps}
|
||||
initialState={initialState}
|
||||
onChange={onChange}
|
||||
readOnly={readOnly}
|
||||
setValue={setValue}
|
||||
value={value}
|
||||
/>
|
||||
<LexicalEditorComponent editorConfig={editorConfig} onChange={onChange} />
|
||||
</div>
|
||||
</EditorConfigProvider>
|
||||
</LexicalComposer>
|
||||
|
||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -418,9 +418,6 @@ importers:
|
||||
'@libsql/client':
|
||||
specifier: ^0.3.1
|
||||
version: 0.3.4
|
||||
better-sqlite3:
|
||||
specifier: ^8.5.0
|
||||
version: 8.6.0
|
||||
console-table-printer:
|
||||
specifier: 2.11.2
|
||||
version: 2.11.2
|
||||
@@ -429,7 +426,7 @@ importers:
|
||||
version: 0.19.13-e99bac1
|
||||
drizzle-orm:
|
||||
specifier: 0.28.5
|
||||
version: 0.28.5(@libsql/client@0.3.4)(@types/pg@8.10.2)(better-sqlite3@8.6.0)(pg@8.11.3)
|
||||
version: 0.28.5(@libsql/client@0.3.4)(@types/pg@8.10.2)(pg@8.11.3)
|
||||
pg:
|
||||
specifier: 8.11.3
|
||||
version: 8.11.3
|
||||
@@ -8447,7 +8444,7 @@ packages:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/drizzle-orm@0.28.5(@libsql/client@0.3.4)(@types/pg@8.10.2)(better-sqlite3@8.6.0)(pg@8.11.3):
|
||||
/drizzle-orm@0.28.5(@libsql/client@0.3.4)(@types/pg@8.10.2)(pg@8.11.3):
|
||||
resolution: {integrity: sha512-6r6Iw4c38NAmW6TiKH3TUpGUQ1YdlEoLJOQptn8XPx3Z63+vFNKfAiANqrIiYZiMjKR9+NYAL219nFrmo1duXA==}
|
||||
peerDependencies:
|
||||
'@aws-sdk/client-rds-data': '>=3'
|
||||
@@ -8511,7 +8508,6 @@ packages:
|
||||
dependencies:
|
||||
'@libsql/client': 0.3.4
|
||||
'@types/pg': 8.10.2
|
||||
better-sqlite3: 8.6.0
|
||||
pg: 8.11.3
|
||||
dev: false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user