@payloadcms/richtext-lexical 3.61.0-internal.dd40839 → 3.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/client/Field-F2KOJLMQ.js +2 -0
- package/dist/exports/client/Field-F2KOJLMQ.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-AFXLIYGL.js +12 -0
- package/dist/exports/client/chunk-AFXLIYGL.js.map +7 -0
- package/dist/exports/client/index.js +21 -21
- package/dist/exports/client/index.js.map +3 -3
- package/dist/exports/react/index.d.ts +1 -1
- package/dist/exports/react/index.d.ts.map +1 -1
- package/dist/exports/react/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts +14 -2
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.js +2 -4
- package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.d.ts +1 -16
- package/dist/features/converters/lexicalToJSX/converter/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.js +4 -76
- package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts +10 -14
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.js.map +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
- package/dist/features/migrations/slateToLexical/feature.server.d.ts +29 -0
- package/dist/features/migrations/slateToLexical/feature.server.d.ts.map +1 -1
- package/dist/features/migrations/slateToLexical/feature.server.js +18 -0
- package/dist/features/migrations/slateToLexical/feature.server.js.map +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +38 -50
- package/dist/field/Field.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/index.d.ts.map +1 -1
- package/dist/field/index.js +11 -25
- package/dist/field/index.js.map +1 -1
- package/dist/field/rscEntry.d.ts +1 -1
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +0 -12
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +1 -2
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js +3 -12
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/nodes/index.d.ts +2 -12
- package/dist/lexical/nodes/index.d.ts.map +1 -1
- package/dist/lexical/nodes/index.js +2 -195
- package/dist/lexical/nodes/index.js.map +1 -1
- package/dist/types.d.ts +2 -132
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/generateImportMap.d.ts.map +1 -1
- package/dist/utilities/generateImportMap.js +0 -1
- package/dist/utilities/generateImportMap.js.map +1 -1
- package/dist/validate/hasText.d.ts +1 -6
- package/dist/validate/hasText.d.ts.map +1 -1
- package/dist/validate/hasText.js +4 -10
- package/dist/validate/hasText.js.map +1 -1
- package/package.json +7 -7
- package/dist/exports/client/Field-5VLZM7KJ.js +0 -2
- package/dist/exports/client/Field-5VLZM7KJ.js.map +0 -7
- package/dist/exports/client/chunk-U4AOQOHA.js +0 -12
- package/dist/exports/client/chunk-U4AOQOHA.js.map +0 -7
- package/dist/field/RichTextViewProvider.d.ts +0 -84
- package/dist/field/RichTextViewProvider.d.ts.map +0 -1
- package/dist/field/RichTextViewProvider.js +0 -92
- package/dist/field/RichTextViewProvider.js.map +0 -1
- package/dist/field/ViewSelector.d.ts +0 -4
- package/dist/field/ViewSelector.d.ts.map +0 -1
- package/dist/field/ViewSelector.js +0 -89
- package/dist/field/ViewSelector.js.map +0 -1
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts +0 -2
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts.map +0 -1
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js +0 -48
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +0 -1
package/dist/field/Field.js
CHANGED
|
@@ -9,8 +9,6 @@ import { ErrorBoundary } from 'react-error-boundary';
|
|
|
9
9
|
import './bundled.css';
|
|
10
10
|
import { LexicalProvider } from '../lexical/LexicalProvider.js';
|
|
11
11
|
import { useRunDeprioritized } from '../utilities/useRunDeprioritized.js';
|
|
12
|
-
import { RichTextViewProvider } from './RichTextViewProvider.js';
|
|
13
|
-
import { ViewSelector } from './ViewSelector.js';
|
|
14
12
|
const baseClass = 'rich-text-lexical';
|
|
15
13
|
const RichTextComponent = props => {
|
|
16
14
|
const {
|
|
@@ -86,7 +84,6 @@ const RichTextComponent = props => {
|
|
|
86
84
|
const pathWithEditDepth = `${path}.${editDepth}`;
|
|
87
85
|
const runDeprioritized = useRunDeprioritized() // defaults to 500 ms timeout
|
|
88
86
|
;
|
|
89
|
-
const [currentView, setCurrentView] = useState('default');
|
|
90
87
|
const handleChange = useCallback(editorState => {
|
|
91
88
|
// Capture `editorState` in the closure so we can safely run later.
|
|
92
89
|
const updateFieldValue = () => {
|
|
@@ -120,55 +117,46 @@ const RichTextComponent = props => {
|
|
|
120
117
|
handleInitialValueChange(initialValue);
|
|
121
118
|
}
|
|
122
119
|
}, [initialValue]);
|
|
123
|
-
return /*#__PURE__*/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
120
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
121
|
+
className: classes,
|
|
122
|
+
style: styles,
|
|
123
|
+
children: [/*#__PURE__*/_jsx(RenderCustomComponent, {
|
|
124
|
+
CustomComponent: Error,
|
|
125
|
+
Fallback: /*#__PURE__*/_jsx(FieldError, {
|
|
126
|
+
path: path,
|
|
127
|
+
showError: showError
|
|
128
|
+
})
|
|
129
|
+
}), Label || /*#__PURE__*/_jsx(FieldLabel, {
|
|
130
|
+
label: label,
|
|
131
|
+
localized: localized,
|
|
132
|
+
path: path,
|
|
133
|
+
required: required
|
|
134
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
135
|
+
className: `${baseClass}__wrap`,
|
|
136
|
+
children: [/*#__PURE__*/_jsxs(ErrorBoundary, {
|
|
137
|
+
fallbackRender: fallbackRender,
|
|
138
|
+
onReset: () => {},
|
|
139
|
+
children: [BeforeInput, /*#__PURE__*/_jsx(LexicalProvider, {
|
|
140
|
+
composerKey: pathWithEditDepth,
|
|
141
|
+
editorConfig: editorConfig,
|
|
142
|
+
fieldProps: props,
|
|
143
|
+
isSmallWidthViewport: isSmallWidthViewport,
|
|
144
|
+
onChange: handleChange,
|
|
145
|
+
readOnly: disabled,
|
|
146
|
+
value: value_0
|
|
147
|
+
}, JSON.stringify({
|
|
148
|
+
path,
|
|
149
|
+
rerenderProviderKey
|
|
150
|
+
})), AfterInput]
|
|
151
|
+
}), /*#__PURE__*/_jsx(RenderCustomComponent, {
|
|
152
|
+
CustomComponent: Description,
|
|
153
|
+
Fallback: /*#__PURE__*/_jsx(FieldDescription, {
|
|
154
|
+
description: description,
|
|
155
|
+
path: path
|
|
135
156
|
})
|
|
136
|
-
}), /*#__PURE__*/_jsxs("div", {
|
|
137
|
-
className: `${baseClass}__label-row`,
|
|
138
|
-
children: [Label || /*#__PURE__*/_jsx(FieldLabel, {
|
|
139
|
-
label: label,
|
|
140
|
-
localized: localized,
|
|
141
|
-
path: path,
|
|
142
|
-
required: required
|
|
143
|
-
}), /*#__PURE__*/_jsx(ViewSelector, {})]
|
|
144
|
-
}), /*#__PURE__*/_jsxs("div", {
|
|
145
|
-
className: `${baseClass}__wrap`,
|
|
146
|
-
children: [/*#__PURE__*/_jsxs(ErrorBoundary, {
|
|
147
|
-
fallbackRender: fallbackRender,
|
|
148
|
-
onReset: () => {},
|
|
149
|
-
children: [BeforeInput, /*#__PURE__*/_jsx(LexicalProvider, {
|
|
150
|
-
composerKey: pathWithEditDepth,
|
|
151
|
-
editorConfig: editorConfig,
|
|
152
|
-
fieldProps: props,
|
|
153
|
-
isSmallWidthViewport: isSmallWidthViewport,
|
|
154
|
-
onChange: handleChange,
|
|
155
|
-
readOnly: disabled,
|
|
156
|
-
value: value_0
|
|
157
|
-
}, JSON.stringify({
|
|
158
|
-
currentView,
|
|
159
|
-
path,
|
|
160
|
-
rerenderProviderKey
|
|
161
|
-
})), AfterInput]
|
|
162
|
-
}), /*#__PURE__*/_jsx(RenderCustomComponent, {
|
|
163
|
-
CustomComponent: Description,
|
|
164
|
-
Fallback: /*#__PURE__*/_jsx(FieldDescription, {
|
|
165
|
-
description: description,
|
|
166
|
-
path: path
|
|
167
|
-
})
|
|
168
|
-
})]
|
|
169
157
|
})]
|
|
170
|
-
}
|
|
171
|
-
});
|
|
158
|
+
})]
|
|
159
|
+
}, pathWithEditDepth);
|
|
172
160
|
};
|
|
173
161
|
function fallbackRender({
|
|
174
162
|
error
|
package/dist/field/Field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","names":["FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useEffectEvent","useField","mergeFieldStyles","dequal","React","useCallback","useEffect","useMemo","useState","ErrorBoundary","LexicalProvider","useRunDeprioritized","RichTextViewProvider","ViewSelector","baseClass","RichTextComponent","props","editorConfig","field","admin","className","description","readOnly","readOnlyFromAdmin","label","localized","required","path","pathFromProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","editDepth","memoizedValidate","value","validationOptions","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","disabledFromField","initialValue","setValue","showError","potentiallyStalePath","isSmallWidthViewport","setIsSmallWidthViewport","rerenderProviderKey","setRerenderProviderKey","prevInitialValueRef","useRef","prevValueRef","updateViewPortWidth","isNextSmallWidthViewport","window","matchMedia","matches","addEventListener","removeEventListener","classes","hideGutter","filter","Boolean","join","pathWithEditDepth","runDeprioritized","currentView","setCurrentView","handleChange","editorState","updateFieldValue","newState","toJSON","current","styles","handleInitialValueChange","JSON","parse","stringify","Date","Object","is","_jsx","views","_jsxs","style","CustomComponent","Fallback","fallbackRender","onReset","composerKey","fieldProps","onChange","error","role","color","message","RichText"],"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { EditorState, SerializedEditorState } from 'lexical'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useEditDepth,\n useEffectEvent,\n useField,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport { dequal } from 'dequal/lite'\nimport { type Validate } from 'payload'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\n\nimport '../lexical/theme/EditorTheme.scss'\nimport './bundled.css'\nimport './index.scss'\n\nimport type { LexicalRichTextFieldProps } from '../types.js'\n\nimport { LexicalProvider } from '../lexical/LexicalProvider.js'\nimport { useRunDeprioritized } from '../utilities/useRunDeprioritized.js'\nimport { RichTextViewProvider } from './RichTextViewProvider.js'\nimport { ViewSelector } from './ViewSelector.js'\n\nconst baseClass = 'rich-text-lexical'\n\nconst RichTextComponent: React.FC<\n {\n readonly editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n } & LexicalRichTextFieldProps\n> = (props) => {\n const {\n editorConfig,\n field,\n field: {\n admin: { className, description, readOnly: readOnlyFromAdmin } = {},\n label,\n localized,\n required,\n },\n path: pathFromProps,\n readOnly: readOnlyFromTopLevelProps,\n validate, // Users can pass in client side validation if they WANT to, but it's not required anymore\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const editDepth = useEditDepth()\n\n const memoizedValidate = useCallback<Validate>(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return validate(value, { ...validationOptions, required })\n }\n return true\n },\n // Important: do not add props to the dependencies array.\n // This would cause an infinite loop and endless re-rendering.\n // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled: disabledFromField,\n initialValue,\n path,\n setValue,\n showError,\n value,\n } = useField<SerializedEditorState>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || disabledFromField\n\n const [isSmallWidthViewport, setIsSmallWidthViewport] = useState<boolean>(false)\n const [rerenderProviderKey, setRerenderProviderKey] = useState<Date>()\n\n const prevInitialValueRef = React.useRef<SerializedEditorState | undefined>(initialValue)\n const prevValueRef = React.useRef<SerializedEditorState | undefined>(value)\n\n useEffect(() => {\n const updateViewPortWidth = () => {\n const isNextSmallWidthViewport = window.matchMedia('(max-width: 768px)').matches\n\n if (isNextSmallWidthViewport !== isSmallWidthViewport) {\n setIsSmallWidthViewport(isNextSmallWidthViewport)\n }\n }\n updateViewPortWidth()\n window.addEventListener('resize', updateViewPortWidth)\n\n return () => {\n window.removeEventListener('resize', updateViewPortWidth)\n }\n }, [isSmallWidthViewport])\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport\n ? `${baseClass}--show-gutter`\n : null,\n ]\n .filter(Boolean)\n .join(' ')\n\n const pathWithEditDepth = `${path}.${editDepth}`\n\n const runDeprioritized = useRunDeprioritized() // defaults to 500 ms timeout\n\n const [currentView, setCurrentView] = useState<string>('default')\n\n const handleChange = useCallback(\n (editorState: EditorState) => {\n // Capture `editorState` in the closure so we can safely run later.\n const updateFieldValue = () => {\n const newState = editorState.toJSON()\n prevValueRef.current = newState\n setValue(newState)\n }\n\n // Queue the update for the browser’s idle time (or Safari shim)\n // and let the hook handle debouncing/cancellation.\n void runDeprioritized(updateFieldValue)\n },\n [setValue, runDeprioritized], // `runDeprioritized` is stable (useCallback inside hook)\n )\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const handleInitialValueChange = useEffectEvent(\n (initialValue: SerializedEditorState | undefined) => {\n // Object deep equality check here, as re-mounting the editor if\n // the new value is the same as the old one is not necessary.\n // In postgres, the order of keys in JSON objects is not guaranteed to be preserved,\n // so we need to do a deep equality check here that does not care about key order => we use dequal.\n // If we used JSON.stringify, the editor would re-mount every time you save the document, as the order of keys changes => change detected => re-mount.\n if (\n prevValueRef.current !== value &&\n !dequal(JSON.parse(JSON.stringify(prevValueRef.current)), value)\n ) {\n prevInitialValueRef.current = initialValue\n prevValueRef.current = value\n setRerenderProviderKey(new Date())\n }\n },\n )\n\n useEffect(() => {\n // Needs to trigger for object reference changes - otherwise,\n // reacting to the same initial value change twice will cause\n // the second change to be ignored, even though the value has changed.\n // That's because initialValue is not kept up-to-date\n if (!Object.is(initialValue, prevInitialValueRef.current)) {\n handleInitialValueChange(initialValue)\n }\n }, [initialValue])\n\n return (\n <RichTextViewProvider\n currentView={currentView}\n setCurrentView={setCurrentView}\n views={props.views}\n >\n <div className={classes} key={pathWithEditDepth} style={styles}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n <div className={`${baseClass}__label-row`}>\n {Label || (\n <FieldLabel label={label} localized={localized} path={path} required={required} />\n )}\n <ViewSelector />\n </div>\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n {BeforeInput}\n <LexicalProvider\n composerKey={pathWithEditDepth}\n editorConfig={editorConfig}\n fieldProps={props}\n isSmallWidthViewport={isSmallWidthViewport}\n key={JSON.stringify({ currentView, path, rerenderProviderKey })} // makes sure lexical is completely re-rendered when initialValue changes or view changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)\n onChange={handleChange}\n readOnly={disabled}\n value={value}\n />\n {AfterInput}\n </ErrorBoundary>\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n </RichTextViewProvider>\n )\n}\n\nfunction fallbackRender({ error }: { error: Error }) {\n // Call resetErrorBoundary() to reset the error boundary and retry the render.\n\n return (\n <div className=\"errorBoundary\" role=\"alert\">\n <p>Something went wrong:</p>\n <pre style={{ color: 'red' }}>{error.message}</pre>\n </div>\n )\n}\n\nexport const RichText: typeof RichTextComponent = RichTextComponent\n"],"mappings":"AAAA;;;AAGA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,YAAY,EACZC,cAAc,EACdC,QAAQ,QACH;AACP,SAASC,gBAAgB,QAAQ;AACjC,SAASC,MAAM,QAAQ;AAEvB,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AACjE,SAASC,aAAa,QAAQ;AAK9B,OAAO;AAKP,SAASC,eAAe,QAAQ;AAChC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,YAAY,QAAQ;AAE7B,MAAMC,SAAA,GAAY;AAElB,MAAMC,iBAAA,GAIDC,KAAA;EACH,MAAM;IACJC,YAAY;IACZC,KAAK;IACLA,KAAA,EAAO;MACLC,KAAA,EAAO;QAAEC,SAAS;QAAEC,WAAW;QAAEC,QAAA,EAAUC;MAAiB,CAAE,GAAG,CAAC,CAAC;MACnEC,KAAK;MACLC,SAAS;MACTC;IAAQ,CACT;IACDC,IAAA,EAAMC,aAAa;IACnBN,QAAA,EAAUO,yBAAyB;IACnCC;EAAQ,CACT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AAA;YAEtB+C,QAAA,EAAUxB,YAAA;YACVjD,QAAA,EAAUoB,QAAA;YACVR,KAAA,EAAOA;aAHF6C,IAAA,CAAKE,SAAS,CAAC;YAAEZ,WAAA;YAAa1C,IAAA;YAAMuB;UAAoB,KAK9Db,UAAA;yBAEHgD,IAAA,CAACvF,qBAAA;UACC2F,eAAA,EAAiBlD,WAAA;UACjBmD,QAAA,eAAUL,IAAA,CAAC1F,gBAAA;YAAiB0B,WAAA,EAAaA,WAAA;YAAaM,IAAA,EAAMA;;;;OA5BpCwC,iBAAA;;AAkCpC;AAEA,SAASwB,eAAe;EAAEK;AAAK,CAAoB;EACjD;EAEA,oBACET,KAAA,CAAC;IAAInE,SAAA,EAAU;IAAgB6E,IAAA,EAAK;4BAClCZ,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAIG,KAAA,EAAO;QAAEU,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqCrF,iBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Field.js","names":["FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useEffectEvent","useField","mergeFieldStyles","dequal","React","useCallback","useEffect","useMemo","useState","ErrorBoundary","LexicalProvider","useRunDeprioritized","baseClass","RichTextComponent","props","editorConfig","field","admin","className","description","readOnly","readOnlyFromAdmin","label","localized","required","path","pathFromProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","editDepth","memoizedValidate","value","validationOptions","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","disabledFromField","initialValue","setValue","showError","potentiallyStalePath","isSmallWidthViewport","setIsSmallWidthViewport","rerenderProviderKey","setRerenderProviderKey","prevInitialValueRef","useRef","prevValueRef","updateViewPortWidth","isNextSmallWidthViewport","window","matchMedia","matches","addEventListener","removeEventListener","classes","hideGutter","filter","Boolean","join","pathWithEditDepth","runDeprioritized","handleChange","editorState","updateFieldValue","newState","toJSON","current","styles","handleInitialValueChange","JSON","parse","stringify","Date","Object","is","_jsxs","style","_jsx","CustomComponent","Fallback","fallbackRender","onReset","composerKey","fieldProps","onChange","error","role","color","message","RichText"],"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { EditorState, SerializedEditorState } from 'lexical'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useEditDepth,\n useEffectEvent,\n useField,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport { dequal } from 'dequal/lite'\nimport { type Validate } from 'payload'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\n\nimport '../lexical/theme/EditorTheme.scss'\nimport './bundled.css'\nimport './index.scss'\n\nimport type { LexicalRichTextFieldProps } from '../types.js'\n\nimport { LexicalProvider } from '../lexical/LexicalProvider.js'\nimport { useRunDeprioritized } from '../utilities/useRunDeprioritized.js'\n\nconst baseClass = 'rich-text-lexical'\n\nconst RichTextComponent: React.FC<\n {\n readonly editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n } & LexicalRichTextFieldProps\n> = (props) => {\n const {\n editorConfig,\n field,\n field: {\n admin: { className, description, readOnly: readOnlyFromAdmin } = {},\n label,\n localized,\n required,\n },\n path: pathFromProps,\n readOnly: readOnlyFromTopLevelProps,\n validate, // Users can pass in client side validation if they WANT to, but it's not required anymore\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const editDepth = useEditDepth()\n\n const memoizedValidate = useCallback<Validate>(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return validate(value, { ...validationOptions, required })\n }\n return true\n },\n // Important: do not add props to the dependencies array.\n // This would cause an infinite loop and endless re-rendering.\n // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled: disabledFromField,\n initialValue,\n path,\n setValue,\n showError,\n value,\n } = useField<SerializedEditorState>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || disabledFromField\n\n const [isSmallWidthViewport, setIsSmallWidthViewport] = useState<boolean>(false)\n const [rerenderProviderKey, setRerenderProviderKey] = useState<Date>()\n\n const prevInitialValueRef = React.useRef<SerializedEditorState | undefined>(initialValue)\n const prevValueRef = React.useRef<SerializedEditorState | undefined>(value)\n\n useEffect(() => {\n const updateViewPortWidth = () => {\n const isNextSmallWidthViewport = window.matchMedia('(max-width: 768px)').matches\n\n if (isNextSmallWidthViewport !== isSmallWidthViewport) {\n setIsSmallWidthViewport(isNextSmallWidthViewport)\n }\n }\n updateViewPortWidth()\n window.addEventListener('resize', updateViewPortWidth)\n\n return () => {\n window.removeEventListener('resize', updateViewPortWidth)\n }\n }, [isSmallWidthViewport])\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport\n ? `${baseClass}--show-gutter`\n : null,\n ]\n .filter(Boolean)\n .join(' ')\n\n const pathWithEditDepth = `${path}.${editDepth}`\n\n const runDeprioritized = useRunDeprioritized() // defaults to 500 ms timeout\n\n const handleChange = useCallback(\n (editorState: EditorState) => {\n // Capture `editorState` in the closure so we can safely run later.\n const updateFieldValue = () => {\n const newState = editorState.toJSON()\n prevValueRef.current = newState\n setValue(newState)\n }\n\n // Queue the update for the browser’s idle time (or Safari shim)\n // and let the hook handle debouncing/cancellation.\n void runDeprioritized(updateFieldValue)\n },\n [setValue, runDeprioritized], // `runDeprioritized` is stable (useCallback inside hook)\n )\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const handleInitialValueChange = useEffectEvent(\n (initialValue: SerializedEditorState | undefined) => {\n // Object deep equality check here, as re-mounting the editor if\n // the new value is the same as the old one is not necessary.\n // In postgres, the order of keys in JSON objects is not guaranteed to be preserved,\n // so we need to do a deep equality check here that does not care about key order => we use dequal.\n // If we used JSON.stringify, the editor would re-mount every time you save the document, as the order of keys changes => change detected => re-mount.\n if (\n prevValueRef.current !== value &&\n !dequal(JSON.parse(JSON.stringify(prevValueRef.current)), value)\n ) {\n prevInitialValueRef.current = initialValue\n prevValueRef.current = value\n setRerenderProviderKey(new Date())\n }\n },\n )\n\n useEffect(() => {\n // Needs to trigger for object reference changes - otherwise,\n // reacting to the same initial value change twice will cause\n // the second change to be ignored, even though the value has changed.\n // That's because initialValue is not kept up-to-date\n if (!Object.is(initialValue, prevInitialValueRef.current)) {\n handleInitialValueChange(initialValue)\n }\n }, [initialValue])\n\n return (\n <div className={classes} key={pathWithEditDepth} style={styles}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {Label || <FieldLabel label={label} localized={localized} path={path} required={required} />}\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n {BeforeInput}\n <LexicalProvider\n composerKey={pathWithEditDepth}\n editorConfig={editorConfig}\n fieldProps={props}\n isSmallWidthViewport={isSmallWidthViewport}\n key={JSON.stringify({ path, rerenderProviderKey })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)\n onChange={handleChange}\n readOnly={disabled}\n value={value}\n />\n {AfterInput}\n </ErrorBoundary>\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }: { error: Error }) {\n // Call resetErrorBoundary() to reset the error boundary and retry the render.\n\n return (\n <div className=\"errorBoundary\" role=\"alert\">\n <p>Something went wrong:</p>\n <pre style={{ color: 'red' }}>{error.message}</pre>\n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