@payloadcms/richtext-lexical 3.83.0-internal.ddc1147 → 3.83.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-4UEGQMIN.js +2 -0
- package/dist/exports/client/Field-4UEGQMIN.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-FTT5KJ6W.js +12 -0
- package/dist/exports/client/chunk-FTT5KJ6W.js.map +7 -0
- package/dist/exports/client/chunk-YWIZCGSY.js +2 -0
- package/dist/exports/client/chunk-YWIZCGSY.js.map +7 -0
- package/dist/exports/client/componentInline-CBBUBQ7P.js +2 -0
- package/dist/exports/client/index.d.ts +1 -0
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +23 -23
- package/dist/exports/client/index.js.map +3 -3
- package/dist/exports/client/internal-client.d.ts +3 -0
- package/dist/exports/client/internal-client.d.ts.map +1 -0
- package/dist/exports/react/index.d.ts +3 -1
- package/dist/exports/react/index.d.ts.map +1 -1
- package/dist/exports/react/index.js +1 -0
- package/dist/exports/react/index.js.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.d.ts +7 -4
- package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +9 -8
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/index.d.ts +20 -4
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +112 -55
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts +8 -14
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +67 -18
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.d.ts +4 -2
- package/dist/features/blocks/client/nodes/BlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.js +3 -1
- package/dist/features/blocks/client/nodes/BlocksNode.js.map +1 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts +4 -2
- package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js +3 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts +6 -20
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.js +7 -5
- package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.d.ts +17 -2
- package/dist/features/converters/lexicalToJSX/converter/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.js +133 -4
- package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts +14 -10
- 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/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +18 -6
- package/dist/field/Field.js.map +1 -1
- package/dist/field/RichTextViewProvider.d.ts +86 -0
- package/dist/field/RichTextViewProvider.d.ts.map +1 -0
- package/dist/field/RichTextViewProvider.js +94 -0
- package/dist/field/RichTextViewProvider.js.map +1 -0
- package/dist/field/ViewSelector.d.ts +4 -0
- package/dist/field/ViewSelector.d.ts.map +1 -0
- package/dist/field/ViewSelector.js +89 -0
- package/dist/field/ViewSelector.js.map +1 -0
- package/dist/field/bundled.css +1 -1
- package/dist/field/index.d.ts +1 -0
- package/dist/field/index.d.ts.map +1 -1
- package/dist/field/index.js +68 -36
- 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 +12 -0
- 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 +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +2 -1
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js +12 -3
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/sanitize.d.ts +1 -1
- package/dist/lexical/config/client/sanitize.d.ts.map +1 -1
- package/dist/lexical/config/client/sanitize.js +3 -2
- package/dist/lexical/config/client/sanitize.js.map +1 -1
- package/dist/lexical/config/types.d.ts +4 -0
- package/dist/lexical/config/types.d.ts.map +1 -1
- package/dist/lexical/config/types.js.map +1 -1
- package/dist/lexical/nodes/index.d.ts +12 -2
- package/dist/lexical/nodes/index.d.ts.map +1 -1
- package/dist/lexical/nodes/index.js +213 -2
- package/dist/lexical/nodes/index.js.map +1 -1
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts +2 -0
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts.map +1 -0
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js +48 -0
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +1 -0
- package/dist/lexical/plugins/SlashMenu/index.d.ts.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.js +14 -1
- package/dist/lexical/plugins/SlashMenu/index.js.map +1 -1
- package/dist/types.d.ts +350 -8
- 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 +1 -0
- package/dist/utilities/generateImportMap.js.map +1 -1
- package/dist/validate/hasText.d.ts +6 -1
- package/dist/validate/hasText.d.ts.map +1 -1
- package/dist/validate/hasText.js +10 -4
- package/dist/validate/hasText.js.map +1 -1
- package/package.json +11 -6
- package/dist/exports/client/Field-OIMYWB22.js +0 -2
- package/dist/exports/client/Field-OIMYWB22.js.map +0 -7
- package/dist/exports/client/chunk-2S5Q7QYO.js +0 -2
- package/dist/exports/client/chunk-2S5Q7QYO.js.map +0 -7
- package/dist/exports/client/chunk-EZX4YW7S.js +0 -12
- package/dist/exports/client/chunk-EZX4YW7S.js.map +0 -7
- package/dist/exports/client/componentInline-NL25DNZ5.js +0 -2
- /package/dist/exports/client/{componentInline-NL25DNZ5.js.map → componentInline-CBBUBQ7P.js.map} +0 -0
package/dist/field/Field.js
CHANGED
|
@@ -9,6 +9,8 @@ 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 { useRichTextView } from './RichTextViewProvider.js';
|
|
13
|
+
import { ViewSelector } from './ViewSelector.js';
|
|
12
14
|
const baseClass = 'rich-text-lexical';
|
|
13
15
|
const RichTextComponent = props => {
|
|
14
16
|
const {
|
|
@@ -26,6 +28,7 @@ const RichTextComponent = props => {
|
|
|
26
28
|
},
|
|
27
29
|
path: pathFromProps,
|
|
28
30
|
readOnly: readOnlyFromTopLevelProps,
|
|
31
|
+
schemaPath,
|
|
29
32
|
validate
|
|
30
33
|
} = props;
|
|
31
34
|
const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
|
|
@@ -41,6 +44,9 @@ const RichTextComponent = props => {
|
|
|
41
44
|
localizationConfig: localizationConfig || undefined
|
|
42
45
|
});
|
|
43
46
|
const editDepth = useEditDepth();
|
|
47
|
+
const {
|
|
48
|
+
isControlledByParent
|
|
49
|
+
} = useRichTextView();
|
|
44
50
|
const memoizedValidate = useCallback((value, validationOptions) => {
|
|
45
51
|
if (typeof validate === 'function') {
|
|
46
52
|
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
@@ -91,7 +97,7 @@ const RichTextComponent = props => {
|
|
|
91
97
|
window.removeEventListener('resize', updateViewPortWidth);
|
|
92
98
|
};
|
|
93
99
|
}, [isSmallWidthViewport]);
|
|
94
|
-
const classes = [
|
|
100
|
+
const classes = ['field-type', baseClass, className, showError && 'error', disabled && `${baseClass}--read-only`, editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport ? `${baseClass}--show-gutter` : null].filter(Boolean).join(' ');
|
|
95
101
|
const pathWithEditDepth = `${path}.${editDepth}`;
|
|
96
102
|
const runDeprioritized = useRunDeprioritized() // defaults to 500 ms timeout
|
|
97
103
|
;
|
|
@@ -130,6 +136,9 @@ const RichTextComponent = props => {
|
|
|
130
136
|
}, [initialValue]);
|
|
131
137
|
return /*#__PURE__*/_jsxs("div", {
|
|
132
138
|
className: classes,
|
|
139
|
+
"data-field-path": path,
|
|
140
|
+
"data-field-schemapath": schemaPath,
|
|
141
|
+
"data-lexical-view": editorConfig?.view,
|
|
133
142
|
style: styles,
|
|
134
143
|
children: [/*#__PURE__*/_jsx(RenderCustomComponent, {
|
|
135
144
|
CustomComponent: Error,
|
|
@@ -137,11 +146,14 @@ const RichTextComponent = props => {
|
|
|
137
146
|
path: path,
|
|
138
147
|
showError: showError
|
|
139
148
|
})
|
|
140
|
-
}),
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
149
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
150
|
+
className: `${baseClass}__label-row`,
|
|
151
|
+
children: [Label || /*#__PURE__*/_jsx(FieldLabel, {
|
|
152
|
+
label: label,
|
|
153
|
+
localized: localized,
|
|
154
|
+
path: path,
|
|
155
|
+
required: required
|
|
156
|
+
}), !isControlledByParent && /*#__PURE__*/_jsx(ViewSelector, {})]
|
|
145
157
|
}), /*#__PURE__*/_jsxs("div", {
|
|
146
158
|
className: `${baseClass}__wrap`,
|
|
147
159
|
children: [/*#__PURE__*/_jsxs(ErrorBoundary, {
|
package/dist/field/Field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","names":["BulkUploadProvider","FieldDescription","FieldError","FieldLabel","isFieldRTL","RenderCustomComponent","useConfig","useEditDepth","useEffectEvent","useField","useLocale","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","locale","config","localization","localizationConfig","rtl","fieldLocalized","undefined","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","drawerSlugPrefix","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 BulkUploadProvider,\n FieldDescription,\n FieldError,\n FieldLabel,\n isFieldRTL,\n RenderCustomComponent,\n useConfig,\n useEditDepth,\n useEffectEvent,\n useField,\n useLocale,\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 locale = useLocale()\n const {\n config: { localization: localizationConfig },\n } = useConfig()\n\n const rtl = isFieldRTL({\n fieldLocalized: localized,\n locale,\n localizationConfig: localizationConfig || undefined,\n })\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(\n prevValueRef.current != null\n ? JSON.parse(JSON.stringify(prevValueRef.current))\n : prevValueRef.current,\n value,\n )\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 {/* Lexical may be in a drawer. We need to define another BulkUploadProvider to ensure that the bulk upload drawer\n is rendered in the correct depth (not displayed *behind* the current drawer)*/}\n <BulkUploadProvider drawerSlugPrefix={path}>\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 rtl={rtl}\n value={value}\n />\n </BulkUploadProvider>\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 </div>\n )\n}\n\nexport const RichText: typeof RichTextComponent = RichTextComponent\n"],"mappings":"AAAA;;;AAGA,SACEA,kBAAkB,EACl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EAAU;IAAgBkF,IAAA,EAAK;4BAClCV,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAID,KAAA,EAAO;QAAEY,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqC1F,iBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Field.js","names":["BulkUploadProvider","FieldDescription","FieldError","FieldLabel","isFieldRTL","RenderCustomComponent","useConfig","useEditDepth","useEffectEvent","useField","useLocale","mergeFieldStyles","dequal","React","useCallback","useEffect","useMemo","useState","ErrorBoundary","LexicalProvider","useRunDeprioritized","useRichTextView","ViewSelector","baseClass","RichTextComponent","props","editorConfig","field","admin","className","description","readOnly","readOnlyFromAdmin","label","localized","required","path","pathFromProps","readOnlyFromTopLevelProps","schemaPath","validate","readOnlyFromProps","locale","config","localization","localizationConfig","rtl","fieldLocalized","undefined","editDepth","isControlledByParent","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","view","style","_jsx","CustomComponent","Fallback","fallbackRender","onReset","drawerSlugPrefix","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 BulkUploadProvider,\n FieldDescription,\n FieldError,\n FieldLabel,\n isFieldRTL,\n RenderCustomComponent,\n useConfig,\n useEditDepth,\n useEffectEvent,\n useField,\n useLocale,\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 { useRichTextView } 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 schemaPath,\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 locale = useLocale()\n const {\n config: { localization: localizationConfig },\n } = useConfig()\n\n const rtl = isFieldRTL({\n fieldLocalized: localized,\n locale,\n localizationConfig: localizationConfig || undefined,\n })\n\n const editDepth = useEditDepth()\n const { isControlledByParent } = useRichTextView()\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 'field-type',\n baseClass,\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(\n prevValueRef.current != null\n ? JSON.parse(JSON.stringify(prevValueRef.current))\n : prevValueRef.current,\n value,\n )\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\n className={classes}\n data-field-path={path}\n data-field-schemapath={schemaPath}\n data-lexical-view={editorConfig?.view}\n key={pathWithEditDepth}\n style={styles}\n >\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 {!isControlledByParent && <ViewSelector />}\n </div>\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n {BeforeInput}\n {/* Lexical may be in a drawer. We need to define another BulkUploadProvider to ensure that the bulk upload drawer\n is rendered in the correct depth (not displayed *behind* the current drawer)*/}\n <BulkUploadProvider drawerSlugPrefix={path}>\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 rtl={rtl}\n value={value}\n />\n </BulkUploadProvider>\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 </div>\n )\n}\n\nexport const RichText: typeof RichTextComponent = RichTextComponent\n"],"mappings":"AAAA;;;AAGA,SACEA,kBAAkB,EAClBC,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,SAAS,EACTC,YAAY,EACZC,cAAc,EACdC,QAAQ,EACRC,SAAS,QACJ;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,eAAe,QAAQ;AAChC,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,UAAU;IACVC;EAAQ,CACT,GAAGf,KAAA;EAEJ,MAAMgB,iBAAA,GAAoBH,yBAAA,IAA6BN,iBAAA;EAEvD,MAAMU,MAAA,GAAShC,SAAA;EACf,MAAM;IACJiC,MAAA,EAAQ;MAAEC,YAAA,EAA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,CAACxG,kBAAA;UAAmB6G,gBAAA,EAAkBzE,IAAA;oBACpC,aAAAoE,IAAA,CAACrF,eAAA;YACC2F,WAAA,EAAazB,iBAAA;YACb3D,YAAA,EAAcA,YAAA;YACdqF,UAAA,EAAYtF,KAAA;YACZyC,oBAAA,EAAsBA,oBAAA;YAEtB8C,QAAA,EAAUzB,YAAA;YACVxD,QAAA,EAAU6B,QAAA;YACVd,GAAA,EAAKA,GAAA;YACLM,KAAA,EAAOA;aAJF2C,IAAA,CAAKE,SAAS,CAAC;YAAE7D,IAAA;YAAMgC;UAAoB;YAOnDb,UAAA;uBAEHiD,IAAA,CAACnG,qBAAA;QACCoG,eAAA,EAAiBhD,WAAA;QACjBiD,QAAA,eAAUF,IAAA,CAACvG,gBAAA;UAAiB6B,WAAA,EAAaA,WAAA;UAAaM,IAAA,EAAMA;;;;KAnC3DiD,iBAAA;AAwCX;AAEA,SAASsB,eAAe;EAAEM;AAAK,CAAoB;EACjD;EAEA,oBACEZ,KAAA,CAAC;IAAIxE,SAAA,EAAU;IAAgBqF,IAAA,EAAK;4BAClCV,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAID,KAAA,EAAO;QAAEY,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqC7F,iBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { LexicalEditorNodeMap, LexicalEditorViewMap } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Context for managing richtext editor view state and inheritance.
|
|
5
|
+
*/
|
|
6
|
+
type RichTextViewContextType = {
|
|
7
|
+
/**
|
|
8
|
+
* The currently active view name (e.g., 'default', 'frontend', 'debug').
|
|
9
|
+
*/
|
|
10
|
+
currentView: string;
|
|
11
|
+
/**
|
|
12
|
+
* The resolved node map for the current view, containing rendering overrides for each node type.
|
|
13
|
+
*/
|
|
14
|
+
currentViewMap?: LexicalEditorNodeMap;
|
|
15
|
+
/**
|
|
16
|
+
* True if the current view was explicitly set (via prop) by this provider or an ancestor.
|
|
17
|
+
* Used to distinguish intentional view settings from automatic defaults.
|
|
18
|
+
*/
|
|
19
|
+
hasExplicitCurrentView?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* If true, nested richtext editors will inherit this provider's currentView and views.
|
|
22
|
+
*/
|
|
23
|
+
inheritable?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* True if this provider's view is controlled by an ancestor provider — either because the
|
|
26
|
+
* ancestor has a views map (view-map inheritance) or an explicit `currentView` prop.
|
|
27
|
+
* When true, the ViewSelector is hidden.
|
|
28
|
+
*/
|
|
29
|
+
isControlledByParent?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Function to programmatically change the current view.
|
|
32
|
+
*/
|
|
33
|
+
setCurrentView: (view: string) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Map of all available views for this editor. Each key is a view name, each value contains
|
|
36
|
+
* admin config, node overrides, and lexical config for that view.
|
|
37
|
+
*/
|
|
38
|
+
views?: LexicalEditorViewMap;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Provider for managing richtext editor view state and its inheritance.
|
|
42
|
+
*
|
|
43
|
+
* Handles two key scenarios:
|
|
44
|
+
* 1. **Explicit view setting**: Wrap with `currentView` and `inheritable={true}` to force nested editors to a specific view
|
|
45
|
+
* 2. **View map inheritance**: Nested editors inherit `views` from parents, allowing view switching across the hierarchy
|
|
46
|
+
*
|
|
47
|
+
* When a nested editor inherits from a parent, its ViewSelector is hidden because the view is controlled by an ancestor.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* Force all nested richtext editors to use "frontend" view:
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <RichTextViewProvider currentView="frontend" inheritable={true}>
|
|
53
|
+
* <MyForm /> {/* All richtext fields inside will use "frontend" view }
|
|
54
|
+
* </RichTextViewProvider>
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const RichTextViewProvider: React.FC<{
|
|
58
|
+
children: React.ReactNode;
|
|
59
|
+
currentView?: string;
|
|
60
|
+
inheritable?: boolean;
|
|
61
|
+
views?: LexicalEditorViewMap;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Access the current richtext editor view context.
|
|
65
|
+
*
|
|
66
|
+
* Returns the active view name, node overrides, inheritance state, and a function to switch views.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* function MyComponent() {
|
|
71
|
+
* const { currentView, currentViewMap, isControlledByParent, setCurrentView } = useRichTextView()
|
|
72
|
+
*
|
|
73
|
+
* return (
|
|
74
|
+
* <div>
|
|
75
|
+
* <p>Active view: {currentView}</p>
|
|
76
|
+
* {isControlledByParent && <p>View controlled by parent</p>}
|
|
77
|
+
* {currentViewMap?.heading && <p>Custom heading renderer active</p>}
|
|
78
|
+
* <button onClick={() => setCurrentView('frontend')}>Switch to frontend</button>
|
|
79
|
+
* </div>
|
|
80
|
+
* )
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function useRichTextView(): RichTextViewContextType;
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=RichTextViewProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichTextViewProvider.d.ts","sourceRoot":"","sources":["../../src/field/RichTextViewProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAA;AAE1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAE7E;;GAEG;AACH,KAAK,uBAAuB,GAAG;IAC7B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAA;IACrC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B;;OAEG;IACH,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC;;;OAGG;IACH,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAQD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAC7B,CA0DA,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,IAAI,uBAAuB,CAEzD"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { useControllableState } from '@payloadcms/ui';
|
|
5
|
+
import React, { createContext, use, useMemo } from 'react';
|
|
6
|
+
const RichTextViewContext = /*#__PURE__*/createContext({
|
|
7
|
+
currentView: 'default',
|
|
8
|
+
inheritable: false,
|
|
9
|
+
setCurrentView: () => {}
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Provider for managing richtext editor view state and its inheritance.
|
|
13
|
+
*
|
|
14
|
+
* Handles two key scenarios:
|
|
15
|
+
* 1. **Explicit view setting**: Wrap with `currentView` and `inheritable={true}` to force nested editors to a specific view
|
|
16
|
+
* 2. **View map inheritance**: Nested editors inherit `views` from parents, allowing view switching across the hierarchy
|
|
17
|
+
*
|
|
18
|
+
* When a nested editor inherits from a parent, its ViewSelector is hidden because the view is controlled by an ancestor.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* Force all nested richtext editors to use "frontend" view:
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <RichTextViewProvider currentView="frontend" inheritable={true}>
|
|
24
|
+
* <MyForm /> {/* All richtext fields inside will use "frontend" view }
|
|
25
|
+
* </RichTextViewProvider>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const RichTextViewProvider = args => {
|
|
29
|
+
const parentContext = useRichTextView();
|
|
30
|
+
// Track if this provider explicitly sets currentView (not just using the default)
|
|
31
|
+
const hasOwnExplicitView = args.currentView !== undefined;
|
|
32
|
+
const isControlledByParent = parentContext.inheritable && (Boolean(parentContext.views) || Boolean(parentContext.hasExplicitCurrentView));
|
|
33
|
+
// This provider has explicit currentView if it sets one OR inherits one from parent
|
|
34
|
+
const hasExplicitCurrentView = hasOwnExplicitView || parentContext.inheritable && Boolean(parentContext.hasExplicitCurrentView);
|
|
35
|
+
const {
|
|
36
|
+
children,
|
|
37
|
+
currentView: currentViewFromProps,
|
|
38
|
+
inheritable,
|
|
39
|
+
views
|
|
40
|
+
} = {
|
|
41
|
+
children: args.children,
|
|
42
|
+
currentView: isControlledByParent ? parentContext.currentView : args.currentView,
|
|
43
|
+
// Propagate inheritable flag through the hierarchy
|
|
44
|
+
inheritable: parentContext.inheritable || args.inheritable,
|
|
45
|
+
// Only inherit views if parent has a views map
|
|
46
|
+
views: isControlledByParent && parentContext.views ? parentContext.views : args.views
|
|
47
|
+
};
|
|
48
|
+
const [currentViewRaw, setCurrentView] = useControllableState(currentViewFromProps, 'default');
|
|
49
|
+
// Normalize currentView: if the requested view doesn't exist in this editor's
|
|
50
|
+
// views map, fall back to 'default'. This ensures all consumers of useRichTextView()
|
|
51
|
+
// see a consistent currentView that actually exists
|
|
52
|
+
const currentView = views && currentViewRaw !== 'default' && !views[currentViewRaw] ? 'default' : currentViewRaw;
|
|
53
|
+
const value = useMemo(() => {
|
|
54
|
+
const currentViewMap = views ? views[currentView] : undefined;
|
|
55
|
+
return {
|
|
56
|
+
currentView,
|
|
57
|
+
currentViewMap,
|
|
58
|
+
hasExplicitCurrentView,
|
|
59
|
+
inheritable,
|
|
60
|
+
isControlledByParent,
|
|
61
|
+
setCurrentView,
|
|
62
|
+
views
|
|
63
|
+
};
|
|
64
|
+
}, [currentView, inheritable, hasExplicitCurrentView, isControlledByParent, setCurrentView, views]);
|
|
65
|
+
return /*#__PURE__*/_jsx(RichTextViewContext, {
|
|
66
|
+
value: value,
|
|
67
|
+
children: children
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Access the current richtext editor view context.
|
|
72
|
+
*
|
|
73
|
+
* Returns the active view name, node overrides, inheritance state, and a function to switch views.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* function MyComponent() {
|
|
78
|
+
* const { currentView, currentViewMap, isControlledByParent, setCurrentView } = useRichTextView()
|
|
79
|
+
*
|
|
80
|
+
* return (
|
|
81
|
+
* <div>
|
|
82
|
+
* <p>Active view: {currentView}</p>
|
|
83
|
+
* {isControlledByParent && <p>View controlled by parent</p>}
|
|
84
|
+
* {currentViewMap?.heading && <p>Custom heading renderer active</p>}
|
|
85
|
+
* <button onClick={() => setCurrentView('frontend')}>Switch to frontend</button>
|
|
86
|
+
* </div>
|
|
87
|
+
* )
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export function useRichTextView() {
|
|
92
|
+
return use(RichTextViewContext);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=RichTextViewProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichTextViewProvider.js","names":["useControllableState","React","createContext","use","useMemo","RichTextViewContext","currentView","inheritable","setCurrentView","RichTextViewProvider","args","parentContext","useRichTextView","hasOwnExplicitView","undefined","isControlledByParent","Boolean","views","hasExplicitCurrentView","children","currentViewFromProps","currentViewRaw","value","currentViewMap","_jsx"],"sources":["../../src/field/RichTextViewProvider.tsx"],"sourcesContent":["'use client'\nimport { useControllableState } from '@payloadcms/ui'\nimport React, { createContext, use, useMemo } from 'react'\n\nimport type { LexicalEditorNodeMap, LexicalEditorViewMap } from '../types.js'\n\n/**\n * Context for managing richtext editor view state and inheritance.\n */\ntype RichTextViewContextType = {\n /**\n * The currently active view name (e.g., 'default', 'frontend', 'debug').\n */\n currentView: string\n /**\n * The resolved node map for the current view, containing rendering overrides for each node type.\n */\n currentViewMap?: LexicalEditorNodeMap\n /**\n * True if the current view was explicitly set (via prop) by this provider or an ancestor.\n * Used to distinguish intentional view settings from automatic defaults.\n */\n hasExplicitCurrentView?: boolean\n /**\n * If true, nested richtext editors will inherit this provider's currentView and views.\n */\n inheritable?: boolean\n /**\n * True if this provider's view is controlled by an ancestor provider — either because the\n * ancestor has a views map (view-map inheritance) or an explicit `currentView` prop.\n * When true, the ViewSelector is hidden.\n */\n isControlledByParent?: boolean\n /**\n * Function to programmatically change the current view.\n */\n setCurrentView: (view: string) => void\n /**\n * Map of all available views for this editor. Each key is a view name, each value contains\n * admin config, node overrides, and lexical config for that view.\n */\n views?: LexicalEditorViewMap\n}\n\nconst RichTextViewContext = createContext<RichTextViewContextType>({\n currentView: 'default',\n inheritable: false,\n setCurrentView: () => {},\n})\n\n/**\n * Provider for managing richtext editor view state and its inheritance.\n *\n * Handles two key scenarios:\n * 1. **Explicit view setting**: Wrap with `currentView` and `inheritable={true}` to force nested editors to a specific view\n * 2. **View map inheritance**: Nested editors inherit `views` from parents, allowing view switching across the hierarchy\n *\n * When a nested editor inherits from a parent, its ViewSelector is hidden because the view is controlled by an ancestor.\n *\n * @example\n * Force all nested richtext editors to use \"frontend\" view:\n * ```tsx\n * <RichTextViewProvider currentView=\"frontend\" inheritable={true}>\n * <MyForm /> {/* All richtext fields inside will use \"frontend\" view }\n * </RichTextViewProvider>\n * ```\n */\nexport const RichTextViewProvider: React.FC<{\n children: React.ReactNode\n currentView?: string\n inheritable?: boolean\n views?: LexicalEditorViewMap\n}> = (args) => {\n const parentContext = useRichTextView()\n\n // Track if this provider explicitly sets currentView (not just using the default)\n const hasOwnExplicitView = args.currentView !== undefined\n\n const isControlledByParent =\n parentContext.inheritable &&\n (Boolean(parentContext.views) || Boolean(parentContext.hasExplicitCurrentView))\n\n // This provider has explicit currentView if it sets one OR inherits one from parent\n const hasExplicitCurrentView =\n hasOwnExplicitView ||\n (parentContext.inheritable && Boolean(parentContext.hasExplicitCurrentView))\n\n const {\n children,\n currentView: currentViewFromProps,\n inheritable,\n views,\n } = {\n children: args.children,\n currentView: isControlledByParent ? parentContext.currentView : args.currentView,\n // Propagate inheritable flag through the hierarchy\n inheritable: parentContext.inheritable || args.inheritable,\n // Only inherit views if parent has a views map\n views: isControlledByParent && parentContext.views ? parentContext.views : args.views,\n }\n\n const [currentViewRaw, setCurrentView] = useControllableState(currentViewFromProps, 'default')\n\n // Normalize currentView: if the requested view doesn't exist in this editor's\n // views map, fall back to 'default'. This ensures all consumers of useRichTextView()\n // see a consistent currentView that actually exists\n const currentView =\n views && currentViewRaw !== 'default' && !views[currentViewRaw] ? 'default' : currentViewRaw\n\n const value = useMemo(() => {\n const currentViewMap = views ? views[currentView] : undefined\n return {\n currentView,\n currentViewMap,\n hasExplicitCurrentView,\n inheritable,\n isControlledByParent,\n setCurrentView,\n views,\n }\n }, [\n currentView,\n inheritable,\n hasExplicitCurrentView,\n isControlledByParent,\n setCurrentView,\n views,\n ])\n\n return <RichTextViewContext value={value}>{children}</RichTextViewContext>\n}\n\n/**\n * Access the current richtext editor view context.\n *\n * Returns the active view name, node overrides, inheritance state, and a function to switch views.\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { currentView, currentViewMap, isControlledByParent, setCurrentView } = useRichTextView()\n *\n * return (\n * <div>\n * <p>Active view: {currentView}</p>\n * {isControlledByParent && <p>View controlled by parent</p>}\n * {currentViewMap?.heading && <p>Custom heading renderer active</p>}\n * <button onClick={() => setCurrentView('frontend')}>Switch to frontend</button>\n * </div>\n * )\n * }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AASI,cAAA,KAAmB,aAAa,CAACJ,KAAK,CAACI,cAAA,CAAe,GAAG,YAAYA,cAAA;EAEhF,MAAMC,KAAA,GAAQlB,OAAA,CAAQ;IACpB,MAAMmB,cAAA,GAAiBN,KAAA,GAAQA,KAAK,CAACX,WAAA,CAAY,GAAGQ,SAAA;IACpD,OAAO;MACLR,WAAA;MACAiB,cAAA;MACAL,sBAAA;MACAX,WAAA;MACAQ,oBAAA;MACAP,cAAA;MACAS;IACF;EACF,GAAG,CACDX,WAAA,EACAC,WAAA,EACAW,sBAAA,EACAH,oBAAA,EACAP,cAAA,EACAS,KAAA,CACD;EAED,oBAAOO,IAAA,CAACnB,mBAAA;IAAoBiB,KAAA,EAAOA,KAAA;cAAQH;;AAC7C;AAEA;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,SAASP,gBAAA;EACd,OAAOT,GAAA,CAAIE,mBAAA;AACb","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ViewSelector.d.ts","sourceRoot":"","sources":["../../src/field/ViewSelector.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,qBAAqB,CAAA;AAE5B,wBAAgB,YAAY,IAAI,IAAI,GAAG,KAAK,CAAC,YAAY,CAyDxD"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { ChevronIcon, Popup, PopupList } from '@payloadcms/ui';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { useRichTextView } from './RichTextViewProvider.js';
|
|
8
|
+
export function ViewSelector() {
|
|
9
|
+
const $ = _c(5);
|
|
10
|
+
const {
|
|
11
|
+
currentView,
|
|
12
|
+
setCurrentView,
|
|
13
|
+
views
|
|
14
|
+
} = useRichTextView();
|
|
15
|
+
if (!views || Object.keys(views).length === 0) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
let t0;
|
|
19
|
+
let t1;
|
|
20
|
+
if ($[0] !== currentView || $[1] !== setCurrentView || $[2] !== views) {
|
|
21
|
+
t1 = Symbol.for("react.early_return_sentinel");
|
|
22
|
+
bb0: {
|
|
23
|
+
const viewKeys = Object.keys(views);
|
|
24
|
+
const hasNonDefaultViews = viewKeys.some(_temp);
|
|
25
|
+
if (!hasNonDefaultViews) {
|
|
26
|
+
t1 = null;
|
|
27
|
+
break bb0;
|
|
28
|
+
}
|
|
29
|
+
const allViews = ["default", ...viewKeys.filter(_temp2)];
|
|
30
|
+
const currentViewLabel = currentView.charAt(0).toUpperCase() + currentView.slice(1);
|
|
31
|
+
t0 = _jsx("div", {
|
|
32
|
+
className: "lexical-view-selector",
|
|
33
|
+
children: _jsx(Popup, {
|
|
34
|
+
button: _jsxs("button", {
|
|
35
|
+
className: "lexical-view-selector__button",
|
|
36
|
+
type: "button",
|
|
37
|
+
children: [_jsx("span", {
|
|
38
|
+
className: "lexical-view-selector__label",
|
|
39
|
+
children: currentViewLabel
|
|
40
|
+
}), _jsx(ChevronIcon, {
|
|
41
|
+
className: "lexical-view-selector__icon"
|
|
42
|
+
})]
|
|
43
|
+
}),
|
|
44
|
+
buttonType: "custom",
|
|
45
|
+
horizontalAlign: "left",
|
|
46
|
+
render: t2 => {
|
|
47
|
+
const {
|
|
48
|
+
close
|
|
49
|
+
} = t2;
|
|
50
|
+
return _jsx(PopupList.ButtonGroup, {
|
|
51
|
+
children: allViews.map(viewName => {
|
|
52
|
+
const viewLabel = viewName.charAt(0).toUpperCase() + viewName.slice(1);
|
|
53
|
+
return _jsx(PopupList.Button, {
|
|
54
|
+
active: viewName === currentView,
|
|
55
|
+
disabled: viewName === currentView,
|
|
56
|
+
onClick: () => {
|
|
57
|
+
setCurrentView?.(viewName);
|
|
58
|
+
close();
|
|
59
|
+
},
|
|
60
|
+
children: viewLabel
|
|
61
|
+
}, viewName);
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
size: "large"
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
$[0] = currentView;
|
|
70
|
+
$[1] = setCurrentView;
|
|
71
|
+
$[2] = views;
|
|
72
|
+
$[3] = t0;
|
|
73
|
+
$[4] = t1;
|
|
74
|
+
} else {
|
|
75
|
+
t0 = $[3];
|
|
76
|
+
t1 = $[4];
|
|
77
|
+
}
|
|
78
|
+
if (t1 !== Symbol.for("react.early_return_sentinel")) {
|
|
79
|
+
return t1;
|
|
80
|
+
}
|
|
81
|
+
return t0;
|
|
82
|
+
}
|
|
83
|
+
function _temp2(key_0) {
|
|
84
|
+
return key_0 !== "default";
|
|
85
|
+
}
|
|
86
|
+
function _temp(key) {
|
|
87
|
+
return key !== "default";
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=ViewSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ViewSelector.js","names":["c","_c","ChevronIcon","Popup","PopupList","React","useRichTextView","ViewSelector","$","currentView","setCurrentView","views","Object","keys","length","t0","t1","Symbol","for","bb0","viewKeys","hasNonDefaultViews","some","_temp","allViews","filter","_temp2","currentViewLabel","charAt","toUpperCase","slice","_jsx","className","children","button","_jsxs","type","horizontalAlign","render","t2","close","ButtonGroup","map","viewName","viewLabel","Button","active","disabled","onClick","key_0","key"],"sources":["../../src/field/ViewSelector.tsx"],"sourcesContent":["'use client'\nimport { ChevronIcon, Popup, PopupList } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { useRichTextView } from './RichTextViewProvider.js'\nimport './ViewSelector.scss'\n\nexport function ViewSelector(): null | React.ReactElement {\n const { currentView, setCurrentView, views } = useRichTextView()\n\n // Don't show if no views or only default exists\n if (!views || Object.keys(views).length === 0) {\n return null\n }\n\n const viewKeys = Object.keys(views)\n const hasNonDefaultViews = viewKeys.some((key) => key !== 'default')\n\n // If only 'default' exists, no need to show selector\n if (!hasNonDefaultViews) {\n return null\n }\n\n // Build list of available views\n const allViews = ['default', ...viewKeys.filter((key) => key !== 'default')]\n\n const currentViewLabel = currentView.charAt(0).toUpperCase() + currentView.slice(1)\n\n return (\n <div className=\"lexical-view-selector\">\n <Popup\n button={\n <button className=\"lexical-view-selector__button\" type=\"button\">\n <span className=\"lexical-view-selector__label\">{currentViewLabel}</span>\n <ChevronIcon className=\"lexical-view-selector__icon\" />\n </button>\n }\n buttonType=\"custom\"\n horizontalAlign=\"left\"\n render={({ close }) => (\n <PopupList.ButtonGroup>\n {allViews.map((viewName) => {\n const viewLabel = viewName.charAt(0).toUpperCase() + viewName.slice(1)\n\n return (\n <PopupList.Button\n active={viewName === currentView}\n disabled={viewName === currentView}\n key={viewName}\n onClick={() => {\n setCurrentView?.(viewName)\n close()\n }}\n >\n {viewLabel}\n </PopupList.Button>\n )\n })}\n </PopupList.ButtonGroup>\n )}\n size=\"large\"\n />\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,SAASC,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ;AAC9C,OAAOC,KAAA,MAAW;AAElB,SAASC,eAAe,QAAQ;AAGhC,OAAO,SAAAC,aAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EACL;IAAAQ,WAAA;IAAAC,cAAA;IAAAC;EAAA,IAA+CL,eAAA;EAAA,IAG3C,CAACK,KAAA,IAASC,MAAA,CAAAC,IAAA,CAAYF,KAAA,EAAAG,MAAA,MAAkB;IAAA;EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAR,CAAA,QAAAC,WAAA,IAAAD,CAAA,QAAAE,cAAA,IAAAF,CAAA,QAAAG,KAAA;IASnCK,EAAA,GAAAC,MAAA,CAAAC,GAAA;IAAAC,GAAA;MALT,MAAAC,QAAA,GAAiBR,MAAA,CAAAC,IAAA,CAAYF,KAAA;MAC7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