@payloadcms/richtext-lexical 3.41.0-internal.c079756 → 3.42.0-canary.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.
Files changed (31) hide show
  1. package/dist/exports/client/Field-6OZARKAL.js +2 -0
  2. package/dist/exports/client/Field-6OZARKAL.js.map +7 -0
  3. package/dist/exports/client/bundled.css +1 -1
  4. package/dist/exports/client/chunk-KZKGNMS3.js +12 -0
  5. package/dist/exports/client/chunk-KZKGNMS3.js.map +7 -0
  6. package/dist/exports/client/index.js +10 -10
  7. package/dist/exports/client/index.js.map +3 -3
  8. package/dist/features/textState/feature.server.js +1 -1
  9. package/dist/features/textState/feature.server.js.map +1 -1
  10. package/dist/features/toolbars/shared/ToolbarButton/index.d.ts.map +1 -1
  11. package/dist/features/toolbars/shared/ToolbarButton/index.js +101 -126
  12. package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
  13. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.d.ts.map +1 -1
  14. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +3 -4
  15. package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
  16. package/dist/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -1
  17. package/dist/features/toolbars/shared/ToolbarDropdown/index.js +85 -179
  18. package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
  19. package/dist/field/Field.d.ts.map +1 -1
  20. package/dist/field/Field.js +11 -22
  21. package/dist/field/Field.js.map +1 -1
  22. package/dist/field/bundled.css +1 -1
  23. package/dist/utilities/useRunDeprioritized.d.ts +26 -0
  24. package/dist/utilities/useRunDeprioritized.d.ts.map +1 -0
  25. package/dist/utilities/useRunDeprioritized.js +69 -0
  26. package/dist/utilities/useRunDeprioritized.js.map +1 -0
  27. package/package.json +6 -6
  28. package/dist/exports/client/Field-6GAC5Y2D.js +0 -2
  29. package/dist/exports/client/Field-6GAC5Y2D.js.map +0 -7
  30. package/dist/exports/client/chunk-LUNX5J6B.js +0 -12
  31. package/dist/exports/client/chunk-LUNX5J6B.js.map +0 -7
@@ -2,12 +2,13 @@
2
2
 
3
3
  import { c as _c } from "react/compiler-runtime";
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
- import React, { useCallback, useEffect } from 'react';
5
+ import React, { useCallback, useDeferredValue, useEffect, useMemo } from 'react';
6
6
  const baseClass = 'toolbar-popup__dropdown';
7
7
  import { mergeRegister } from '@lexical/utils';
8
8
  import { useTranslation } from '@payloadcms/ui';
9
9
  import { $getSelection } from 'lexical';
10
10
  import { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js';
11
+ import { useRunDeprioritized } from '../../../../utilities/useRunDeprioritized.js';
11
12
  import { DropDown, DropDownItem } from './DropDown.js';
12
13
  const ToolbarItem = t0 => {
13
14
  const $ = _c(18);
@@ -100,197 +101,102 @@ const ToolbarItem = t0 => {
100
101
  }
101
102
  return t2;
102
103
  };
103
- export const ToolbarDropdown = t0 => {
104
- const $ = _c(36);
105
- const {
106
- anchorElem,
107
- classNames,
108
- editor,
109
- group,
110
- Icon,
111
- itemsContainerClassNames,
112
- label,
113
- maxActiveItems,
114
- onActiveChange
115
- } = t0;
116
- let t1;
117
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
118
- t1 = [];
119
- $[0] = t1;
120
- } else {
121
- t1 = $[0];
122
- }
123
- const [activeItemKeys, setActiveItemKeys] = React.useState(t1);
124
- let t2;
125
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
126
- t2 = [];
127
- $[1] = t2;
128
- } else {
129
- t2 = $[1];
130
- }
131
- const [enabledItemKeys, setEnabledItemKeys] = React.useState(t2);
132
- const [enabledGroup, setEnabledGroup] = React.useState(true);
104
+ const MemoToolbarItem = /*#__PURE__*/React.memo(ToolbarItem);
105
+ export const ToolbarDropdown = ({
106
+ anchorElem,
107
+ classNames,
108
+ editor,
109
+ group,
110
+ Icon,
111
+ itemsContainerClassNames,
112
+ label,
113
+ maxActiveItems,
114
+ onActiveChange
115
+ }) => {
116
+ const [toolbarState, setToolbarState] = React.useState({
117
+ activeItemKeys: [],
118
+ enabledGroup: true,
119
+ enabledItemKeys: []
120
+ });
121
+ const deferredToolbarState = useDeferredValue(toolbarState);
133
122
  const editorConfigContext = useEditorConfigContext();
134
123
  const {
135
124
  items,
136
125
  key: groupKey
137
126
  } = group;
138
- let t3;
139
- if ($[2] !== editor || $[3] !== editorConfigContext || $[4] !== group || $[5] !== items || $[6] !== maxActiveItems || $[7] !== onActiveChange) {
140
- t3 = () => {
141
- editor.getEditorState().read(() => {
142
- const selection = $getSelection();
143
- if (!selection) {
144
- return;
145
- }
146
- const _activeItemKeys = [];
147
- const _activeItems = [];
148
- const _enabledItemKeys = [];
149
- for (const item of items) {
150
- if (item.isActive && (!maxActiveItems || _activeItemKeys.length < maxActiveItems)) {
151
- const isActive = item.isActive({
152
- editor,
153
- editorConfigContext,
154
- selection
155
- });
156
- if (isActive) {
157
- _activeItemKeys.push(item.key);
158
- _activeItems.push(item);
159
- }
160
- }
161
- if (item.isEnabled) {
162
- const isEnabled = item.isEnabled({
163
- editor,
164
- editorConfigContext,
165
- selection
166
- });
167
- if (isEnabled) {
168
- _enabledItemKeys.push(item.key);
169
- }
170
- } else {
171
- _enabledItemKeys.push(item.key);
127
+ const runDeprioritized = useRunDeprioritized();
128
+ const updateStates = useCallback(() => {
129
+ editor.getEditorState().read(() => {
130
+ const selection = $getSelection();
131
+ if (!selection) {
132
+ return;
133
+ }
134
+ const _activeItemKeys = [];
135
+ const _activeItems = [];
136
+ const _enabledItemKeys = [];
137
+ for (const item of items) {
138
+ if (item.isActive && (!maxActiveItems || _activeItemKeys.length < maxActiveItems)) {
139
+ const isActive = item.isActive({
140
+ editor,
141
+ editorConfigContext,
142
+ selection
143
+ });
144
+ if (isActive) {
145
+ _activeItemKeys.push(item.key);
146
+ _activeItems.push(item);
172
147
  }
173
148
  }
174
- if (group.isEnabled) {
175
- setEnabledGroup(group.isEnabled({
149
+ if (item.isEnabled) {
150
+ const isEnabled = item.isEnabled({
176
151
  editor,
177
152
  editorConfigContext,
178
153
  selection
179
- }));
180
- }
181
- setActiveItemKeys(_activeItemKeys);
182
- setEnabledItemKeys(_enabledItemKeys);
183
- if (onActiveChange) {
184
- onActiveChange({
185
- activeItems: _activeItems
186
154
  });
155
+ if (isEnabled) {
156
+ _enabledItemKeys.push(item.key);
157
+ }
158
+ } else {
159
+ _enabledItemKeys.push(item.key);
187
160
  }
161
+ }
162
+ setToolbarState({
163
+ activeItemKeys: _activeItemKeys,
164
+ enabledGroup: group.isEnabled ? group.isEnabled({
165
+ editor,
166
+ editorConfigContext,
167
+ selection
168
+ }) : true,
169
+ enabledItemKeys: _enabledItemKeys
188
170
  });
189
- };
190
- $[2] = editor;
191
- $[3] = editorConfigContext;
192
- $[4] = group;
193
- $[5] = items;
194
- $[6] = maxActiveItems;
195
- $[7] = onActiveChange;
196
- $[8] = t3;
197
- } else {
198
- t3 = $[8];
199
- }
200
- const updateStates = t3;
201
- let t4;
202
- let t5;
203
- if ($[9] !== updateStates) {
204
- t4 = () => {
205
- updateStates();
206
- };
207
- t5 = [updateStates];
208
- $[9] = updateStates;
209
- $[10] = t4;
210
- $[11] = t5;
211
- } else {
212
- t4 = $[10];
213
- t5 = $[11];
214
- }
215
- useEffect(t4, t5);
216
- let t6;
217
- let t7;
218
- if ($[12] !== editor || $[13] !== updateStates) {
219
- t6 = () => mergeRegister(editor.registerUpdateListener(() => {
220
- updateStates();
171
+ if (onActiveChange) {
172
+ onActiveChange({
173
+ activeItems: _activeItems
174
+ });
175
+ }
176
+ });
177
+ }, [editor, editorConfigContext, group, items, maxActiveItems, onActiveChange]);
178
+ useEffect(() => {
179
+ return mergeRegister(editor.registerUpdateListener(async () => {
180
+ await runDeprioritized(updateStates);
221
181
  }));
222
- t7 = [editor, updateStates];
223
- $[12] = editor;
224
- $[13] = updateStates;
225
- $[14] = t6;
226
- $[15] = t7;
227
- } else {
228
- t6 = $[14];
229
- t7 = $[15];
230
- }
231
- useEffect(t6, t7);
232
- const t8 = `${groupKey} dropdown`;
233
- const t9 = `${baseClass}-${groupKey}`;
234
- let t10;
235
- if ($[16] !== classNames) {
236
- t10 = classNames || [];
237
- $[16] = classNames;
238
- $[17] = t10;
239
- } else {
240
- t10 = $[17];
241
- }
242
- let t11;
243
- if ($[18] !== t10 || $[19] !== t9) {
244
- t11 = [baseClass, t9, ...t10].filter(Boolean);
245
- $[18] = t10;
246
- $[19] = t9;
247
- $[20] = t11;
248
- } else {
249
- t11 = $[20];
250
- }
251
- const t12 = t11.join(" ");
252
- const t13 = !enabledGroup;
253
- let t14;
254
- if ($[21] !== itemsContainerClassNames) {
255
- t14 = itemsContainerClassNames || [];
256
- $[21] = itemsContainerClassNames;
257
- $[22] = t14;
258
- } else {
259
- t14 = $[22];
260
- }
261
- let t15;
262
- if ($[23] !== Icon || $[24] !== activeItemKeys || $[25] !== anchorElem || $[26] !== editor || $[27] !== enabledItemKeys || $[28] !== groupKey || $[29] !== items || $[30] !== label || $[31] !== t12 || $[32] !== t13 || $[33] !== t14 || $[34] !== t8) {
263
- t15 = _jsx(DropDown, {
264
- buttonAriaLabel: t8,
265
- buttonClassName: t12,
266
- disabled: t13,
267
- Icon,
268
- itemsContainerClassNames: [`${baseClass}-items`, ...t14],
269
- label,
270
- children: items.length ? items.map(item_0 => _jsx(ToolbarItem, {
271
- active: activeItemKeys.includes(item_0.key),
272
- anchorElem,
273
- editor,
274
- enabled: enabledItemKeys.includes(item_0.key),
275
- item: item_0
276
- }, item_0.key)) : null
277
- }, groupKey);
278
- $[23] = Icon;
279
- $[24] = activeItemKeys;
280
- $[25] = anchorElem;
281
- $[26] = editor;
282
- $[27] = enabledItemKeys;
283
- $[28] = groupKey;
284
- $[29] = items;
285
- $[30] = label;
286
- $[31] = t12;
287
- $[32] = t13;
288
- $[33] = t14;
289
- $[34] = t8;
290
- $[35] = t15;
291
- } else {
292
- t15 = $[35];
293
- }
294
- return t15;
182
+ }, [editor, runDeprioritized, updateStates]);
183
+ const renderedItems = useMemo(() => {
184
+ return items?.length ? items.map(item_0 => /*#__PURE__*/_jsx(MemoToolbarItem, {
185
+ active: deferredToolbarState.activeItemKeys.includes(item_0.key),
186
+ anchorElem: anchorElem,
187
+ editor: editor,
188
+ enabled: deferredToolbarState.enabledItemKeys.includes(item_0.key),
189
+ item: item_0
190
+ }, item_0.key)) : null;
191
+ }, [items, deferredToolbarState, anchorElem, editor]);
192
+ return /*#__PURE__*/_jsx(DropDown, {
193
+ buttonAriaLabel: `${groupKey} dropdown`,
194
+ buttonClassName: [baseClass, `${baseClass}-${groupKey}`, ...(classNames || [])].filter(Boolean).join(' '),
195
+ disabled: !deferredToolbarState.enabledGroup,
196
+ Icon: Icon,
197
+ itemsContainerClassNames: [`${baseClass}-items`, ...(itemsContainerClassNames || [])],
198
+ label: label,
199
+ children: renderedItems
200
+ }, groupKey);
295
201
  };
296
202
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","React","useCallback","useEffect","baseClass","mergeRegister","useTranslation","$getSelection","useEditorConfigContext","DropDown","DropDownItem","ToolbarItem","t0","$","active","anchorElem","editor","enabled","item","i18n","fieldProps","t1","featureClientSchemaMap","schemaPath","Component","t2","_jsx","key","title","croppedTitle","label","length","substring","Icon","ChildComponent","undefined","tooltip","children","className","ToolbarDropdown","classNames","group","itemsContainerClassNames","maxActiveItems","onActiveChange","Symbol","for","activeItemKeys","setActiveItemKeys","useState","enabledItemKeys","setEnabledItemKeys","enabledGroup","setEnabledGroup","editorConfigContext","items","groupKey","t3","getEditorState","read","selection","_activeItemKeys","_activeItems","_enabledItemKeys","isActive","push","isEnabled","activeItems","updateStates","t4","t5","t6","t7","registerUpdateListener","t8","t9","t10","t11","filter","Boolean","t12","join","t13","t14","t15","buttonAriaLabel","buttonClassName","disabled","map","item_0","includes"],"sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/index.tsx"],"sourcesContent":["'use client'\nimport React, { useCallback, useEffect } from 'react'\n\nconst baseClass = 'toolbar-popup__dropdown'\n\nimport type { LexicalEditor } from 'lexical'\n\nimport { mergeRegister } from '@lexical/utils'\nimport { useTranslation } from '@payloadcms/ui'\nimport { $getSelection } from 'lexical'\n\nimport type { ToolbarDropdownGroup, ToolbarGroupItem } from '../../types.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { DropDown, DropDownItem } from './DropDown.js'\nimport './index.scss'\n\nconst ToolbarItem = ({\n active,\n anchorElem,\n editor,\n enabled,\n item,\n}: {\n active?: boolean\n anchorElem: HTMLElement\n editor: LexicalEditor\n enabled?: boolean\n item: ToolbarGroupItem\n}) => {\n const { i18n } = useTranslation<{}, string>()\n const {\n fieldProps: { featureClientSchemaMap, schemaPath },\n } = useEditorConfigContext()\n\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component\n active={active}\n anchorElem={anchorElem}\n editor={editor}\n enabled={enabled}\n item={item}\n key={item.key}\n />\n )\n )\n }\n\n let title = item.key\n let croppedTitle = item.key\n if (item.label) {\n title =\n typeof item.label === 'function'\n ? item.label({ featureClientSchemaMap, i18n, schemaPath })\n : item.label\n }\n // Crop title to max. 25 characters\n if (title.length > 25) {\n croppedTitle = title.substring(0, 25) + '...'\n } else {\n croppedTitle = title\n }\n\n return (\n <DropDownItem\n active={active}\n editor={editor}\n enabled={enabled}\n Icon={item?.ChildComponent ? <item.ChildComponent /> : undefined}\n item={item}\n key={item.key}\n tooltip={title}\n >\n <span className=\"text\">{croppedTitle}</span>\n </DropDownItem>\n )\n}\n\nexport const ToolbarDropdown = ({\n anchorElem,\n classNames,\n editor,\n group,\n Icon,\n itemsContainerClassNames,\n label,\n maxActiveItems,\n onActiveChange,\n}: {\n anchorElem: HTMLElement\n classNames?: string[]\n editor: LexicalEditor\n group: ToolbarDropdownGroup\n Icon?: React.FC\n itemsContainerClassNames?: string[]\n label?: string\n /**\n * Maximum number of active items allowed. This is a performance optimization to prevent\n * unnecessary item active checks when the maximum number of active items is reached.\n */\n maxActiveItems?: number\n onActiveChange?: ({ activeItems }: { activeItems: ToolbarGroupItem[] }) => void\n}) => {\n const [activeItemKeys, setActiveItemKeys] = React.useState<string[]>([])\n const [enabledItemKeys, setEnabledItemKeys] = React.useState<string[]>([])\n const [enabledGroup, setEnabledGroup] = React.useState<boolean>(true)\n const editorConfigContext = useEditorConfigContext()\n const { items, key: groupKey } = group\n\n const updateStates = useCallback(() => {\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if (!selection) {\n return\n }\n\n const _activeItemKeys: string[] = []\n const _activeItems: ToolbarGroupItem[] = []\n const _enabledItemKeys: string[] = []\n\n for (const item of items) {\n if (item.isActive && (!maxActiveItems || _activeItemKeys.length < maxActiveItems)) {\n const isActive = item.isActive({ editor, editorConfigContext, selection })\n if (isActive) {\n _activeItemKeys.push(item.key)\n _activeItems.push(item)\n }\n }\n if (item.isEnabled) {\n const isEnabled = item.isEnabled({ editor, editorConfigContext, selection })\n if (isEnabled) {\n _enabledItemKeys.push(item.key)\n }\n } else {\n _enabledItemKeys.push(item.key)\n }\n }\n if (group.isEnabled) {\n setEnabledGroup(group.isEnabled({ editor, editorConfigContext, selection }))\n }\n setActiveItemKeys(_activeItemKeys)\n setEnabledItemKeys(_enabledItemKeys)\n\n if (onActiveChange) {\n onActiveChange({ activeItems: _activeItems })\n }\n })\n }, [editor, editorConfigContext, group, items, maxActiveItems, onActiveChange])\n\n useEffect(() => {\n updateStates()\n }, [updateStates])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(() => {\n updateStates()\n }),\n )\n }, [editor, updateStates])\n\n return (\n <DropDown\n buttonAriaLabel={`${groupKey} dropdown`}\n buttonClassName={[baseClass, `${baseClass}-${groupKey}`, ...(classNames || [])]\n .filter(Boolean)\n .join(' ')}\n disabled={!enabledGroup}\n Icon={Icon}\n itemsContainerClassNames={[`${baseClass}-items`, ...(itemsContainerClassNames || [])]}\n key={groupKey}\n label={label}\n >\n {items.length\n ? items.map((item) => {\n return (\n <ToolbarItem\n active={activeItemKeys.includes(item.key)}\n anchorElem={anchorElem}\n editor={editor}\n enabled={enabledItemKeys.includes(item.key)}\n item={item}\n key={item.key}\n />\n )\n })\n : null}\n </DropDown>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,QAAQ;AAE9C,MAAMC,SAAA,GAAY;AAIlB,SAASC,aAAa,QAAQ;AAC9B,SAASC,cAAc,QAAQ;AAC/B,SAASC,aAAa,QAAQ;AAI9B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,QAAQ,EAAEC,YAAY,QAAQ;AAGvC,MAAMC,WAAA,GAAcC,EAAA;EAAA,MAAAC,CAAA,GAAAb,EAAA;EAAC;IAAAc,MAAA;IAAAC,UAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC;EAAA,IAAAN,EAYpB;EACC;IAAAO;EAAA,IAAiBb,cAAA;EACjB;IAAAc,UAAA,EAAAC;EAAA,IAEIb,sBAAA;EADU;IAAAc,sBAAA;IAAAC;EAAA,IAAAF,EAAsC;EAAA,IAGhDH,IAAA,CAAAM,SAAA;IAAA,IAAAC,EAAA;IAAA,IAAAZ,CAAA,QAAAC,MAAA,IAAAD,CAAA,QAAAE,UAAA,IAAAF,CAAA,QAAAG,MAAA,IAAAH,CAAA,QAAAI,OAAA,IAAAJ,CAAA,QAAAK,IAAA;MAEAO,EAAA,GAAAP,IAAA,EAAAM,SAAA,IACEE,IAAA,CAACR,IAAA,CAAAM,SAAA;QAAAV,MAAA;QAAAC,UAAA;QAAAC,MAAA;QAAAC,OAAA;QAAAC;MAAA,GAMMA,IAAA,CAAAS,GAAQ;MAAAd,CAAA,MAAAC,MAAA;MAAAD,CAAA,MAAAE,UAAA;MAAAF,CAAA,MAAAG,MAAA;MAAAH,CAAA,MAAAI,OAAA;MA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A;IAPrFU,GAAA,GAAA1D,IAAA,CAAAjB,QAAA;MAAA4E,eAAA,EACmBX,EAAsB;MAAAY,eAAA,EACtBN,GAET;MAAAO,QAAA,EACEL,GAAC;MAAAjD,IAAA;MAAAS,wBAAA,GAEgB,GAAAtC,SAAA,QAAoB,KAAM+E,GAA8B;MAAArD,KAAA;MAAAO,QAAA,EAIlFkB,KAAA,CAAAxB,MAAA,GACGwB,KAAA,CAAAiC,GAAA,CAAAC,MAAA,IAEI/D,IAAA,CAAAf,WAAA;QAAAG,MAAA,EACUiC,cAAA,CAAA2C,QAAA,CAAwBxE,MAAA,CAAAS,GAAQ;QAAAZ,UAAA;QAAAC,MAAA;QAAAC,OAAA,EAG/BiC,eAAA,CAAAwC,QAAA,CAAyBxE,MAAA,CAAAS,GAAQ;QAAAT,IAAA,EACpCA;MAAA,GACDA,MAAA,CAAAS,GAAQ,CAGnB;IACA,GAhBC6B,QAAA;IAAA3C,CAAA,OAAAoB,IAAA;IAAApB,CAAA,OAAAkC,cAAA;IAAAlC,CAAA,OAAAE,UAAA;IAAAF,CAAA,OAAAG,MAAA;IAAAH,CAAA,OAAAqC,eAAA;IAAArC,CAAA,OAAA2C,QAAA;IAAA3C,CAAA,OAAA0C,KAAA;IAAA1C,CAAA,OAAAiB,KAAA;IAAAjB,CAAA,OAAAmE,GAAA;IAAAnE,CAAA,OAAAqE,GAAA;IAAArE,CAAA,OAAAsE,GAAA;IAAAtE,CAAA,OAAA6D,EAAA;IAAA7D,CAAA,OAAAuE,GAAA;EAAA;IAAAA,GAAA,GAAAvE,CAAA;EAAA;EAAA,OARPuE,GAQO;AAAA,CAmBX","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","React","useCallback","useDeferredValue","useEffect","useMemo","baseClass","mergeRegister","useTranslation","$getSelection","useEditorConfigContext","useRunDeprioritized","DropDown","DropDownItem","ToolbarItem","t0","$","active","anchorElem","editor","enabled","item","i18n","fieldProps","t1","featureClientSchemaMap","schemaPath","Component","t2","_jsx","key","title","croppedTitle","label","length","substring","Icon","ChildComponent","undefined","tooltip","children","className","MemoToolbarItem","memo","ToolbarDropdown","classNames","group","itemsContainerClassNames","maxActiveItems","onActiveChange","toolbarState","setToolbarState","useState","activeItemKeys","enabledGroup","enabledItemKeys","deferredToolbarState","editorConfigContext","items","groupKey","runDeprioritized","updateStates","getEditorState","read","selection","_activeItemKeys","_activeItems","_enabledItemKeys","isActive","push","isEnabled","activeItems","registerUpdateListener","renderedItems","map","includes","buttonAriaLabel","buttonClassName","filter","Boolean","join","disabled"],"sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/index.tsx"],"sourcesContent":["'use client'\nimport React, { useCallback, useDeferredValue, useEffect, useMemo } from 'react'\n\nconst baseClass = 'toolbar-popup__dropdown'\n\nimport type { LexicalEditor } from 'lexical'\n\nimport { mergeRegister } from '@lexical/utils'\nimport { useTranslation } from '@payloadcms/ui'\nimport { $getSelection } from 'lexical'\n\nimport type { ToolbarDropdownGroup, ToolbarGroupItem } from '../../types.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { useRunDeprioritized } from '../../../../utilities/useRunDeprioritized.js'\nimport './index.scss'\nimport { DropDown, DropDownItem } from './DropDown.js'\n\nconst ToolbarItem = ({\n active,\n anchorElem,\n editor,\n enabled,\n item,\n}: {\n active?: boolean\n anchorElem: HTMLElement\n editor: LexicalEditor\n enabled?: boolean\n item: ToolbarGroupItem\n}) => {\n const { i18n } = useTranslation<{}, string>()\n const {\n fieldProps: { featureClientSchemaMap, schemaPath },\n } = useEditorConfigContext()\n\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component\n active={active}\n anchorElem={anchorElem}\n editor={editor}\n enabled={enabled}\n item={item}\n key={item.key}\n />\n )\n )\n }\n\n let title = item.key\n let croppedTitle = item.key\n if (item.label) {\n title =\n typeof item.label === 'function'\n ? item.label({ featureClientSchemaMap, i18n, schemaPath })\n : item.label\n }\n // Crop title to max. 25 characters\n if (title.length > 25) {\n croppedTitle = title.substring(0, 25) + '...'\n } else {\n croppedTitle = title\n }\n\n return (\n <DropDownItem\n active={active}\n editor={editor}\n enabled={enabled}\n Icon={item?.ChildComponent ? <item.ChildComponent /> : undefined}\n item={item}\n key={item.key}\n tooltip={title}\n >\n <span className=\"text\">{croppedTitle}</span>\n </DropDownItem>\n )\n}\n\nconst MemoToolbarItem = React.memo(ToolbarItem)\n\nexport const ToolbarDropdown = ({\n anchorElem,\n classNames,\n editor,\n group,\n Icon,\n itemsContainerClassNames,\n label,\n maxActiveItems,\n onActiveChange,\n}: {\n anchorElem: HTMLElement\n classNames?: string[]\n editor: LexicalEditor\n group: ToolbarDropdownGroup\n Icon?: React.FC\n itemsContainerClassNames?: string[]\n label?: string\n /**\n * Maximum number of active items allowed. This is a performance optimization to prevent\n * unnecessary item active checks when the maximum number of active items is reached.\n */\n maxActiveItems?: number\n onActiveChange?: ({ activeItems }: { activeItems: ToolbarGroupItem[] }) => void\n}) => {\n const [toolbarState, setToolbarState] = React.useState<{\n activeItemKeys: string[]\n enabledGroup: boolean\n enabledItemKeys: string[]\n }>({\n activeItemKeys: [],\n enabledGroup: true,\n enabledItemKeys: [],\n })\n const deferredToolbarState = useDeferredValue(toolbarState)\n\n const editorConfigContext = useEditorConfigContext()\n const { items, key: groupKey } = group\n\n const runDeprioritized = useRunDeprioritized()\n\n const updateStates = useCallback(() => {\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if (!selection) {\n return\n }\n\n const _activeItemKeys: string[] = []\n const _activeItems: ToolbarGroupItem[] = []\n const _enabledItemKeys: string[] = []\n\n for (const item of items) {\n if (item.isActive && (!maxActiveItems || _activeItemKeys.length < maxActiveItems)) {\n const isActive = item.isActive({ editor, editorConfigContext, selection })\n if (isActive) {\n _activeItemKeys.push(item.key)\n _activeItems.push(item)\n }\n }\n if (item.isEnabled) {\n const isEnabled = item.isEnabled({ editor, editorConfigContext, selection })\n if (isEnabled) {\n _enabledItemKeys.push(item.key)\n }\n } else {\n _enabledItemKeys.push(item.key)\n }\n }\n\n setToolbarState({\n activeItemKeys: _activeItemKeys,\n enabledGroup: group.isEnabled\n ? group.isEnabled({ editor, editorConfigContext, selection })\n : true,\n enabledItemKeys: _enabledItemKeys,\n })\n\n if (onActiveChange) {\n onActiveChange({ activeItems: _activeItems })\n }\n })\n }, [editor, editorConfigContext, group, items, maxActiveItems, onActiveChange])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(async () => {\n await runDeprioritized(updateStates)\n }),\n )\n }, [editor, runDeprioritized, updateStates])\n\n const renderedItems = useMemo(() => {\n return items?.length\n ? items.map((item) => (\n <MemoToolbarItem\n active={deferredToolbarState.activeItemKeys.includes(item.key)}\n anchorElem={anchorElem}\n editor={editor}\n enabled={deferredToolbarState.enabledItemKeys.includes(item.key)}\n item={item}\n key={item.key}\n />\n ))\n : null\n }, [items, deferredToolbarState, anchorElem, editor])\n\n return (\n <DropDown\n buttonAriaLabel={`${groupKey} dropdown`}\n buttonClassName={[baseClass, `${baseClass}-${groupKey}`, ...(classNames || [])]\n .filter(Boolean)\n .join(' ')}\n disabled={!deferredToolbarState.enabledGroup}\n Icon={Icon}\n itemsContainerClassNames={[`${baseClass}-items`, ...(itemsContainerClassNames || [])]}\n key={groupKey}\n label={label}\n >\n {renderedItems}\n </DropDown>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,IAASC,WAAW,EAAEC,gBAAgB,EAAEC,SAAS,EAAEC,OAAO,QAAQ;AAEzE,MAAMC,SAAA,GAAY;AAIlB,SAASC,aAAa,QAAQ;AAC9B,SAASC,cAAc,QAAQ;AAC/B,SAASC,aAAa,QAAQ;AAI9B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,mBAAmB,QAAQ;AAEpC,SAASC,QAAQ,EAAEC,YAAY,QAAQ;AAEvC,MAAMC,WAAA,GAAcC,EAAA;EAAA,MAAAC,CAAA,GAAAhB,EAAA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C,UAAA,EAAYC,MAAA,CAAO;EAEpD,oBACEU,IAAA,CAACjB,QAAA;IACCgE,eAAA,EAAiB,GAAGjB,QAAA,WAAmB;IACvCkB,eAAA,EAAiB,CAACvE,SAAA,EAAW,GAAGA,SAAA,IAAaqD,QAAA,EAAU,E,IAAMd,UAAA,IAAc,EAAE,EAAE,CAC5EiC,MAAM,CAACC,OAAA,EACPC,IAAI,CAAC;IACRC,QAAA,EAAU,CAACzB,oBAAA,CAAqBF,YAAY;IAC5ClB,IAAA,EAAMA,IAAA;IACNW,wBAAA,EAA0B,CAAC,GAAGzC,SAAA,QAAiB,E,IAAMyC,wBAAA,IAA4B,EAAE,EAAE;IAErFd,KAAA,EAAOA,KAAA;cAENwC;KAHId,QAAA;AAMX","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAcA,OAAO,KAA4D,MAAM,OAAO,CAAA;AAGhF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAE7E,OAAO,mCAAmC,CAAA;AAC1C,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAM5D,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAC/B;IACE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;CACnD,GAAG,yBAAyB,CA8K9B,CAAA;AAaD,eAAO,MAAM,QAAQ,EAAE,OAAO,iBAAqC,CAAA"}
1
+ {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAGxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAE7E,OAAO,mCAAmC,CAAA;AAC1C,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAO5D,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAC/B;IACE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;CACnD,GAAG,yBAAyB,CAiK9B,CAAA;AAaD,eAAO,MAAM,QAAQ,EAAE,OAAO,iBAAqC,CAAA"}
@@ -3,10 +3,11 @@
3
3
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  import { FieldDescription, FieldError, FieldLabel, RenderCustomComponent, useEditDepth, useEffectEvent, useField } from '@payloadcms/ui';
5
5
  import { mergeFieldStyles } from '@payloadcms/ui/shared';
6
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
6
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
7
7
  import { ErrorBoundary } from 'react-error-boundary';
8
8
  import './bundled.css';
9
9
  import { LexicalProvider } from '../lexical/LexicalProvider.js';
10
+ import { useRunDeprioritized } from '../utilities/useRunDeprioritized.js';
10
11
  const baseClass = 'rich-text-lexical';
11
12
  const RichTextComponent = props => {
12
13
  const {
@@ -80,31 +81,19 @@ const RichTextComponent = props => {
80
81
  }, [isSmallWidthViewport]);
81
82
  const classes = [baseClass, 'field-type', className, showError && 'error', disabled && `${baseClass}--read-only`, editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport ? `${baseClass}--show-gutter` : null].filter(Boolean).join(' ');
82
83
  const pathWithEditDepth = `${path}.${editDepth}`;
83
- const dispatchFieldUpdateTask = useRef(undefined);
84
+ const runDeprioritized = useRunDeprioritized() // defaults to 500 ms timeout
85
+ ;
84
86
  const handleChange = useCallback(editorState => {
85
- const updateFieldValue = editorState_0 => {
86
- const newState = editorState_0.toJSON();
87
+ // Capture `editorState` in the closure so we can safely run later.
88
+ const updateFieldValue = () => {
89
+ const newState = editorState.toJSON();
87
90
  prevValueRef.current = newState;
88
91
  setValue(newState);
89
92
  };
90
- if (typeof window.requestIdleCallback === 'function') {
91
- // Cancel earlier scheduled value updates,
92
- // so that a CPU-limited event loop isn't flooded with n callbacks for n keystrokes into the rich text field,
93
- // but that there's only ever the latest one state update
94
- // dispatch task, to be executed with the next idle time,
95
- // or the deadline of 500ms.
96
- if (typeof window.cancelIdleCallback === 'function' && dispatchFieldUpdateTask.current) {
97
- cancelIdleCallback(dispatchFieldUpdateTask.current);
98
- }
99
- // Schedule the state update to happen the next time the browser has sufficient resources,
100
- // or the latest after 500ms.
101
- dispatchFieldUpdateTask.current = requestIdleCallback(() => updateFieldValue(editorState), {
102
- timeout: 500
103
- });
104
- } else {
105
- updateFieldValue(editorState);
106
- }
107
- }, [setValue]);
93
+ // Queue the update for the browser’s idle time (or Safari shim)
94
+ // and let the hook handle debouncing/cancellation.
95
+ void runDeprioritized(updateFieldValue);
96
+ }, [setValue, runDeprioritized]);
108
97
  const styles = useMemo(() => mergeFieldStyles(field), [field]);
109
98
  const handleInitialValueChange = useEffectEvent(initialValue_0 => {
110
99
  // Object deep equality check here, as re-mounting the editor if
@@ -1 +1 @@
1
- {"version":3,"file":"Field.js","names":["FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useEffectEvent","useField","mergeFieldStyles","React","useCallback","useEffect","useMemo","useRef","useState","ErrorBoundary","LexicalProvider","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","prevValueRef","updateViewPortWidth","isNextSmallWidthViewport","window","matchMedia","matches","addEventListener","removeEventListener","classes","hideGutter","filter","Boolean","join","pathWithEditDepth","dispatchFieldUpdateTask","undefined","handleChange","editorState","updateFieldValue","newState","toJSON","current","requestIdleCallback","cancelIdleCallback","timeout","styles","handleInitialValueChange","JSON","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'\nimport type { Validate } from 'payload'\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 React, { useCallback, useEffect, useMemo, useRef, 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'\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 dispatchFieldUpdateTask = useRef<number>(undefined)\n\n const handleChange = useCallback(\n (editorState: EditorState) => {\n const updateFieldValue = (editorState: EditorState) => {\n const newState = editorState.toJSON()\n prevValueRef.current = newState\n setValue(newState)\n }\n\n if (typeof window.requestIdleCallback === 'function') {\n // Cancel earlier scheduled value updates,\n // so that a CPU-limited event loop isn't flooded with n callbacks for n keystrokes into the rich text field,\n // but that there's only ever the latest one state update\n // dispatch task, to be executed with the next idle time,\n // or the deadline of 500ms.\n if (typeof window.cancelIdleCallback === 'function' && dispatchFieldUpdateTask.current) {\n cancelIdleCallback(dispatchFieldUpdateTask.current)\n }\n // Schedule the state update to happen the next time the browser has sufficient resources,\n // or the latest after 500ms.\n dispatchFieldUpdateTask.current = requestIdleCallback(() => updateFieldValue(editorState), {\n timeout: 500,\n })\n } else {\n updateFieldValue(editorState)\n }\n },\n [setValue],\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 if (\n prevValueRef.current !== value &&\n JSON.stringify(prevValueRef.current) !== JSON.stringify(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 {Description}\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;;;AAIA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,YAAY,EACZC,cAAc,EACdC,QAAQ,QACH;AACP,SAASC,gBAAgB,QAAQ;AACjC,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AACzE,SAASC,aAAa,QAAQ;AAK9B,OAAO;AAKP,SAASC,eAAe,QAAQ;AAEhC,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,GAAGd,KAAA;EAEJ,MAAMe,iBAAA,GAAoBF,yBAAA,IAA6BN,iBAAA;EAEvD,MAAMS,SAAA,GAAY9B,YAAA;EAElB,MAAM+B,gBAAA,GAAmB1B,WAAA,CACvB,CAAC2B,KAAA,EAAOC,iBAAA;IACN,IAAI,OAAOL,QAAA,KAAa,YAAY;MAClC;MACA,OAAOA,QAAA,CAASI,KAAA,EAAO;QAAE,GAAGC,iBAAiB;QAAET;MAAS;IAC1D;IACA,OAAO;EACT;EACA;EACA;EACA;EACA,CAACI,QAAA,EAAUJ,QAAA,CAAS;EAGtB,MAAM;IACJU,gBAAA,EAAkB;MAAEC,UAAU;MAAEC,WAAW;MAAEC,WAAW;MAAEC,KAAK;MAAEC;IAA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AClCT,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAID,KAAA,EAAO;QAAEW,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqCpF,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"Field.js","names":["FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useEffectEvent","useField","mergeFieldStyles","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","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'\nimport type { Validate } from 'payload'\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 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 if (\n prevValueRef.current !== value &&\n JSON.stringify(prevValueRef.current) !== JSON.stringify(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 {Description}\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;;;AAIA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,YAAY,EACZC,cAAc,EACdC,QAAQ,QACH;AACP,SAASC,gBAAgB,QAAQ;AACjC,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;AAEpC,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,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