@lexical/react 0.1.6 → 0.1.10

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 (105) hide show
  1. package/DEPRECATED_useLexical.dev.js +49 -0
  2. package/DEPRECATED_useLexical.js +9 -2
  3. package/DEPRECATED_useLexical.prod.js +7 -0
  4. package/DEPRECATED_useLexicalAutoFormatter.dev.js +729 -0
  5. package/DEPRECATED_useLexicalAutoFormatter.js +9 -11
  6. package/DEPRECATED_useLexicalAutoFormatter.prod.js +26 -0
  7. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +136 -0
  8. package/DEPRECATED_useLexicalCanShowPlaceholder.js +9 -3
  9. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +8 -0
  10. package/DEPRECATED_useLexicalCharacterLimit.dev.js +293 -0
  11. package/DEPRECATED_useLexicalCharacterLimit.js +9 -9
  12. package/DEPRECATED_useLexicalCharacterLimit.prod.js +14 -0
  13. package/DEPRECATED_useLexicalDecorators.dev.js +82 -0
  14. package/DEPRECATED_useLexicalDecorators.js +9 -2
  15. package/DEPRECATED_useLexicalDecorators.prod.js +8 -0
  16. package/DEPRECATED_useLexicalEditor.dev.js +28 -0
  17. package/DEPRECATED_useLexicalEditor.js +9 -1
  18. package/DEPRECATED_useLexicalEditor.prod.js +7 -0
  19. package/DEPRECATED_useLexicalEditorEvents.dev.js +96 -0
  20. package/DEPRECATED_useLexicalEditorEvents.js +9 -2
  21. package/DEPRECATED_useLexicalEditorEvents.prod.js +8 -0
  22. package/DEPRECATED_useLexicalHistory.dev.js +342 -0
  23. package/DEPRECATED_useLexicalHistory.js +9 -7
  24. package/DEPRECATED_useLexicalHistory.prod.js +13 -0
  25. package/DEPRECATED_useLexicalList.dev.js +64 -0
  26. package/DEPRECATED_useLexicalList.js +9 -12
  27. package/DEPRECATED_useLexicalList.prod.js +7 -0
  28. package/DEPRECATED_useLexicalPlainText.dev.js +761 -0
  29. package/DEPRECATED_useLexicalPlainText.js +9 -17
  30. package/DEPRECATED_useLexicalPlainText.prod.js +21 -0
  31. package/DEPRECATED_useLexicalRichText.dev.js +1197 -0
  32. package/DEPRECATED_useLexicalRichText.js +9 -31
  33. package/DEPRECATED_useLexicalRichText.prod.js +32 -0
  34. package/LexicalAutoFormatterPlugin.dev.js +732 -0
  35. package/LexicalAutoFormatterPlugin.js +9 -12
  36. package/LexicalAutoFormatterPlugin.prod.js +26 -0
  37. package/LexicalAutoLinkPlugin.dev.js +227 -0
  38. package/LexicalAutoLinkPlugin.js +9 -5
  39. package/LexicalAutoLinkPlugin.prod.js +12 -0
  40. package/LexicalBootstrapPlugin.dev.js +122 -0
  41. package/LexicalBootstrapPlugin.js +9 -0
  42. package/LexicalBootstrapPlugin.prod.js +8 -0
  43. package/LexicalCharacterLimitPlugin.dev.js +351 -0
  44. package/LexicalCharacterLimitPlugin.js +9 -10
  45. package/LexicalCharacterLimitPlugin.prod.js +14 -0
  46. package/LexicalCollaborationPlugin.dev.js +220 -0
  47. package/LexicalCollaborationPlugin.js +9 -8
  48. package/LexicalCollaborationPlugin.prod.js +13 -0
  49. package/LexicalComposer.dev.js +71 -0
  50. package/LexicalComposer.js +9 -2
  51. package/LexicalComposer.prod.js +8 -0
  52. package/LexicalComposerContext.dev.js +53 -0
  53. package/LexicalComposerContext.js +9 -1
  54. package/LexicalComposerContext.prod.js +7 -0
  55. package/LexicalContentEditable.dev.js +71 -0
  56. package/LexicalContentEditable.js +9 -3
  57. package/LexicalContentEditable.prod.js +9 -0
  58. package/LexicalHashtagPlugin.dev.js +152 -0
  59. package/LexicalHashtagPlugin.js +9 -4
  60. package/LexicalHashtagPlugin.prod.js +10 -0
  61. package/LexicalHistoryPlugin.dev.js +347 -0
  62. package/LexicalHistoryPlugin.js +9 -7
  63. package/LexicalHistoryPlugin.prod.js +13 -0
  64. package/LexicalHorizontalRuleNode.dev.js +66 -0
  65. package/LexicalHorizontalRuleNode.js +9 -0
  66. package/LexicalHorizontalRuleNode.prod.js +8 -0
  67. package/LexicalLinkPlugin.dev.js +136 -0
  68. package/LexicalLinkPlugin.js +9 -3
  69. package/LexicalLinkPlugin.prod.js +9 -0
  70. package/LexicalListPlugin.dev.js +67 -0
  71. package/LexicalListPlugin.js +9 -12
  72. package/LexicalListPlugin.prod.js +8 -0
  73. package/LexicalNestedComposer.dev.js +60 -0
  74. package/LexicalNestedComposer.js +9 -1
  75. package/LexicalNestedComposer.prod.js +8 -0
  76. package/LexicalOnChangePlugin.dev.js +57 -0
  77. package/LexicalOnChangePlugin.js +9 -1
  78. package/LexicalOnChangePlugin.prod.js +7 -0
  79. package/LexicalPlainTextPlugin.dev.js +589 -0
  80. package/LexicalPlainTextPlugin.js +9 -13
  81. package/LexicalPlainTextPlugin.prod.js +18 -0
  82. package/LexicalRichTextPlugin.dev.js +1025 -0
  83. package/LexicalRichTextPlugin.js +9 -27
  84. package/LexicalRichTextPlugin.prod.js +28 -0
  85. package/LexicalTablePlugin.dev.js +77 -0
  86. package/LexicalTablePlugin.js +9 -3
  87. package/LexicalTablePlugin.prod.js +9 -0
  88. package/LexicalTreeView.dev.js +348 -0
  89. package/LexicalTreeView.js +9 -12
  90. package/LexicalTreeView.prod.js +20 -0
  91. package/README.md +10 -5
  92. package/package.json +5 -4
  93. package/useLexicalDecoratorMap.dev.js +83 -0
  94. package/useLexicalDecoratorMap.js +9 -2
  95. package/useLexicalDecoratorMap.prod.js +8 -0
  96. package/useLexicalIsTextContentEmpty.dev.js +84 -0
  97. package/useLexicalIsTextContentEmpty.js +9 -2
  98. package/useLexicalIsTextContentEmpty.prod.js +8 -0
  99. package/useLexicalNodeSelection.dev.js +70 -0
  100. package/useLexicalNodeSelection.js +9 -0
  101. package/useLexicalNodeSelection.prod.js +8 -0
  102. package/withSubscriptions.dev.js +23 -0
  103. package/withSubscriptions.js +9 -1
  104. package/withSubscriptions.prod.js +7 -0
  105. package/LexicalHorizontalRulePlugin.js +0 -1
@@ -0,0 +1,1197 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict';
8
+
9
+ var withSubscriptions = require('@lexical/react/withSubscriptions');
10
+ var lexical = require('lexical');
11
+ var react = require('react');
12
+
13
+ /**
14
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ *
20
+ */
21
+ const HISTORY_MERGE = 0;
22
+ const HISTORY_PUSH = 1;
23
+ const DISCARD_HISTORY_CANDIDATE = 2;
24
+ const OTHER = 0;
25
+ const COMPOSING_CHARACTER = 1;
26
+ const INSERT_CHARACTER_AFTER_SELECTION = 2;
27
+ const DELETE_CHARACTER_BEFORE_SELECTION = 3;
28
+ const DELETE_CHARACTER_AFTER_SELECTION = 4;
29
+ const EditorPriority = 0;
30
+
31
+ function getDirtyNodes(editorState, dirtyLeavesSet, dirtyElementsSet) {
32
+ const dirtyLeaves = Array.from(dirtyLeavesSet);
33
+ const dirtyElements = Array.from(dirtyElementsSet);
34
+ const nodeMap = editorState._nodeMap;
35
+ const nodes = [];
36
+
37
+ for (let i = 0; i < dirtyLeaves.length; i++) {
38
+ const dirtyLeafKey = dirtyLeaves[i];
39
+ const dirtyLeaf = nodeMap.get(dirtyLeafKey);
40
+
41
+ if (dirtyLeaf !== undefined) {
42
+ nodes.push(dirtyLeaf);
43
+ }
44
+ }
45
+
46
+ for (let i = 0; i < dirtyElements.length; i++) {
47
+ const intentionallyMarkedAsDirty = dirtyElements[i][1];
48
+
49
+ if (!intentionallyMarkedAsDirty) {
50
+ continue;
51
+ }
52
+
53
+ const dirtyElementKey = dirtyElements[i][0];
54
+ const dirtyElement = nodeMap.get(dirtyElementKey);
55
+
56
+ if (dirtyElement !== undefined && !lexical.$isRootNode(dirtyElement)) {
57
+ nodes.push(dirtyElement);
58
+ }
59
+ }
60
+
61
+ return nodes;
62
+ }
63
+
64
+ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyElementsSet, isComposing) {
65
+ if (prevEditorState === null || dirtyLeavesSet.size === 0 && dirtyElementsSet.size === 0) {
66
+ return OTHER;
67
+ }
68
+
69
+ const nextSelection = nextEditorState._selection;
70
+ const prevSelection = prevEditorState._selection;
71
+
72
+ if (isComposing) {
73
+ return COMPOSING_CHARACTER;
74
+ }
75
+
76
+ if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
77
+ return OTHER;
78
+ }
79
+
80
+ const dirtyNodes = getDirtyNodes(nextEditorState, dirtyLeavesSet, dirtyElementsSet);
81
+
82
+ if (dirtyNodes.length === 0) {
83
+ return OTHER;
84
+ } // Catching the case when inserting new text node into an element (e.g. first char in paragraph/list),
85
+ // or after existing node.
86
+
87
+
88
+ if (dirtyNodes.length > 1) {
89
+ const nextNodeMap = nextEditorState._nodeMap;
90
+ const nextAnchorNode = nextNodeMap.get(nextSelection.anchor.key);
91
+ const prevAnchorNode = nextNodeMap.get(prevSelection.anchor.key);
92
+
93
+ if (nextAnchorNode && prevAnchorNode && !prevEditorState._nodeMap.has(nextAnchorNode.__key) && lexical.$isTextNode(nextAnchorNode) && nextAnchorNode.__text.length === 1 && nextSelection.anchor.offset === 1) {
94
+ return INSERT_CHARACTER_AFTER_SELECTION;
95
+ }
96
+
97
+ return OTHER;
98
+ }
99
+
100
+ const nextDirtyNode = dirtyNodes[0];
101
+
102
+ const prevDirtyNode = prevEditorState._nodeMap.get(nextDirtyNode.__key);
103
+
104
+ if (!lexical.$isTextNode(prevDirtyNode) || !lexical.$isTextNode(nextDirtyNode) || prevDirtyNode.__mode !== nextDirtyNode.__mode) {
105
+ return OTHER;
106
+ }
107
+
108
+ const prevText = prevDirtyNode.__text;
109
+ const nextText = nextDirtyNode.__text;
110
+
111
+ if (prevText === nextText) {
112
+ return OTHER;
113
+ }
114
+
115
+ const nextAnchor = nextSelection.anchor;
116
+ const prevAnchor = prevSelection.anchor;
117
+
118
+ if (nextAnchor.key !== prevAnchor.key || nextAnchor.type !== 'text') {
119
+ return OTHER;
120
+ }
121
+
122
+ const nextAnchorOffset = nextAnchor.offset;
123
+ const prevAnchorOffset = prevAnchor.offset;
124
+ const textDiff = nextText.length - prevText.length;
125
+
126
+ if (textDiff === 1 && prevAnchorOffset === nextAnchorOffset - 1) {
127
+ return INSERT_CHARACTER_AFTER_SELECTION;
128
+ }
129
+
130
+ if (textDiff === -1 && prevAnchorOffset === nextAnchorOffset + 1) {
131
+ return DELETE_CHARACTER_BEFORE_SELECTION;
132
+ }
133
+
134
+ if (textDiff === -1 && prevAnchorOffset === nextAnchorOffset) {
135
+ return DELETE_CHARACTER_AFTER_SELECTION;
136
+ }
137
+
138
+ return OTHER;
139
+ }
140
+
141
+ function createMergeActionGetter(editor, delay) {
142
+ let prevChangeTime = Date.now();
143
+ let prevChangeType = OTHER;
144
+ return (prevEditorState, nextEditorState, currentHistoryEntry, dirtyLeaves, dirtyElements, tags) => {
145
+ const changeTime = Date.now(); // If applying changes from history stack there's no need
146
+ // to run history logic again, as history entries already calculated
147
+
148
+ if (tags.has('historic')) {
149
+ prevChangeType = OTHER;
150
+ prevChangeTime = changeTime;
151
+ return DISCARD_HISTORY_CANDIDATE;
152
+ }
153
+
154
+ const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
155
+
156
+ const mergeAction = (() => {
157
+ const shouldPushHistory = tags.has('history-push');
158
+ const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
159
+
160
+ if (shouldMergeHistory) {
161
+ return HISTORY_MERGE;
162
+ }
163
+
164
+ if (prevEditorState === null) {
165
+ return HISTORY_PUSH;
166
+ }
167
+
168
+ const selection = nextEditorState._selection;
169
+ const prevSelection = prevEditorState._selection;
170
+ const hasDirtyNodes = dirtyLeaves.size > 0 || dirtyElements.size > 0;
171
+
172
+ if (!hasDirtyNodes) {
173
+ if (prevSelection === null && selection !== null) {
174
+ return HISTORY_MERGE;
175
+ }
176
+
177
+ return DISCARD_HISTORY_CANDIDATE;
178
+ }
179
+
180
+ const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
181
+
182
+ if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
183
+ return HISTORY_MERGE;
184
+ }
185
+
186
+ return HISTORY_PUSH;
187
+ })();
188
+
189
+ prevChangeTime = changeTime;
190
+ prevChangeType = changeType;
191
+ return mergeAction;
192
+ };
193
+ }
194
+
195
+ function useHistory(editor, externalHistoryState, delay = 1000) {
196
+ const historyState = react.useMemo(() => externalHistoryState || createEmptyHistoryState(), [externalHistoryState]);
197
+ const clearHistory = react.useCallback(() => {
198
+ historyState.undoStack = [];
199
+ historyState.redoStack = [];
200
+ historyState.current = null;
201
+ }, [historyState]);
202
+ react.useEffect(() => {
203
+ const getMergeAction = createMergeActionGetter(editor, delay);
204
+
205
+ const applyChange = ({
206
+ editorState,
207
+ prevEditorState,
208
+ dirtyLeaves,
209
+ dirtyElements,
210
+ tags
211
+ }) => {
212
+ const current = historyState.current;
213
+ const redoStack = historyState.redoStack;
214
+ const undoStack = historyState.undoStack;
215
+ const currentEditorState = current === null ? null : current.editorState;
216
+
217
+ if (current !== null && editorState === currentEditorState) {
218
+ return;
219
+ }
220
+
221
+ const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
222
+
223
+ if (mergeAction === HISTORY_PUSH) {
224
+ if (redoStack.length !== 0) {
225
+ historyState.redoStack = [];
226
+ }
227
+
228
+ if (current !== null) {
229
+ undoStack.push({ ...current,
230
+ undoSelection: prevEditorState.read(lexical.$getSelection)
231
+ });
232
+ editor.execCommand('canUndo', true);
233
+ }
234
+ } else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
235
+ return;
236
+ } // Else we merge
237
+
238
+
239
+ historyState.current = {
240
+ editor,
241
+ editorState
242
+ };
243
+ };
244
+
245
+ const undo = () => {
246
+ const redoStack = historyState.redoStack;
247
+ const undoStack = historyState.undoStack;
248
+ const undoStackLength = undoStack.length;
249
+
250
+ if (undoStackLength !== 0) {
251
+ const current = historyState.current;
252
+ const historyStateEntry = undoStack.pop();
253
+
254
+ if (current !== null) {
255
+ redoStack.push(current);
256
+ editor.execCommand('canRedo', true);
257
+ }
258
+
259
+ if (undoStack.length === 0) {
260
+ editor.execCommand('canUndo', false);
261
+ }
262
+
263
+ historyState.current = historyStateEntry;
264
+ historyStateEntry.editor.setEditorState(historyStateEntry.editorState.clone(historyStateEntry.undoSelection), {
265
+ tag: 'historic'
266
+ });
267
+ }
268
+ };
269
+
270
+ const redo = () => {
271
+ const redoStack = historyState.redoStack;
272
+ const undoStack = historyState.undoStack;
273
+
274
+ if (redoStack.length !== 0) {
275
+ const current = historyState.current;
276
+
277
+ if (current !== null) {
278
+ undoStack.push(current);
279
+ editor.execCommand('canUndo', true);
280
+ }
281
+
282
+ const historyStateEntry = redoStack.pop();
283
+
284
+ if (redoStack.length === 0) {
285
+ editor.execCommand('canRedo', false);
286
+ }
287
+
288
+ historyState.current = historyStateEntry;
289
+ historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
290
+ tag: 'historic'
291
+ });
292
+ }
293
+ };
294
+
295
+ const applyCommand = type => {
296
+ switch (type) {
297
+ case 'undo':
298
+ undo();
299
+ return true;
300
+
301
+ case 'redo':
302
+ redo();
303
+ return true;
304
+
305
+ case 'clearEditor':
306
+ clearHistory();
307
+ return false;
308
+
309
+ case 'clearHistory':
310
+ clearHistory();
311
+ return true;
312
+
313
+ default:
314
+ return false;
315
+ }
316
+ };
317
+
318
+ return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority), editor.addListener('update', applyChange));
319
+ }, [clearHistory, delay, editor, historyState]);
320
+ }
321
+ function createEmptyHistoryState() {
322
+ return {
323
+ current: null,
324
+ redoStack: [],
325
+ undoStack: []
326
+ };
327
+ }
328
+
329
+ /**
330
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
331
+ *
332
+ * This source code is licensed under the MIT license found in the
333
+ * LICENSE file in the root directory of this source tree.
334
+ *
335
+ *
336
+ */
337
+ function useLexicalHistory(editor, externalHistoryState, delay = 1000) {
338
+ return useHistory(editor, externalHistoryState, delay);
339
+ }
340
+
341
+ /**
342
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
343
+ *
344
+ * This source code is licensed under the MIT license found in the
345
+ * LICENSE file in the root directory of this source tree.
346
+ *
347
+ *
348
+ */
349
+
350
+ function $cloneWithProperties(node) {
351
+ const latest = node.getLatest();
352
+ const constructor = latest.constructor;
353
+ const clone = constructor.clone(latest);
354
+ clone.__parent = latest.__parent;
355
+
356
+ if (lexical.$isElementNode(latest) && lexical.$isElementNode(clone)) {
357
+ clone.__children = Array.from(latest.__children);
358
+ clone.__format = latest.__format;
359
+ clone.__indent = latest.__indent;
360
+ clone.__dir = latest.__dir;
361
+ } else if (lexical.$isTextNode(latest) && lexical.$isTextNode(clone)) {
362
+ clone.__format = latest.__format;
363
+ clone.__style = latest.__style;
364
+ clone.__mode = latest.__mode;
365
+ clone.__detail = latest.__detail;
366
+ } else if (lexical.$isDecoratorNode(latest) && lexical.$isDecoratorNode(clone)) {
367
+ clone.__state = latest.__state;
368
+ } // $FlowFixMe
369
+
370
+
371
+ return clone;
372
+ }
373
+
374
+ function $getIndexFromPossibleClone(node, parent, nodeMap) {
375
+ const parentClone = nodeMap.get(parent.getKey());
376
+
377
+ if (lexical.$isElementNode(parentClone)) {
378
+ return parentClone.__children.indexOf(node.getKey());
379
+ }
380
+
381
+ return node.getIndexWithinParent();
382
+ }
383
+
384
+ function $getParentAvoidingExcludedElements(node) {
385
+ let parent = node.getParent();
386
+
387
+ while (parent !== null && parent.excludeFromCopy()) {
388
+ parent = parent.getParent();
389
+ }
390
+
391
+ return parent;
392
+ }
393
+
394
+ function $copyLeafNodeBranchToRoot(leaf, startingOffset, isLeftSide, range, nodeMap) {
395
+ let node = leaf;
396
+ let offset = startingOffset;
397
+
398
+ while (node !== null) {
399
+ const parent = $getParentAvoidingExcludedElements(node);
400
+
401
+ if (parent === null) {
402
+ break;
403
+ }
404
+
405
+ if (!lexical.$isElementNode(node) || !node.excludeFromCopy()) {
406
+ const key = node.getKey();
407
+ let clone = nodeMap.get(key);
408
+ const needsClone = clone === undefined;
409
+
410
+ if (needsClone) {
411
+ clone = $cloneWithProperties(node);
412
+ nodeMap.set(key, clone);
413
+ }
414
+
415
+ if (lexical.$isTextNode(clone) && !clone.isSegmented() && !clone.isToken()) {
416
+ clone.__text = clone.__text.slice(isLeftSide ? offset : 0, isLeftSide ? undefined : offset);
417
+ } else if (lexical.$isElementNode(clone)) {
418
+ clone.__children = clone.__children.slice(isLeftSide ? offset : 0, isLeftSide ? undefined : offset + 1);
419
+ }
420
+
421
+ if (lexical.$isRootNode(parent)) {
422
+ if (needsClone) {
423
+ // We only want to collect a range of top level nodes.
424
+ // So if the parent is the root, we know this is a top level.
425
+ range.push(key);
426
+ }
427
+
428
+ break;
429
+ }
430
+ }
431
+
432
+ offset = $getIndexFromPossibleClone(node, parent, nodeMap);
433
+ node = parent;
434
+ }
435
+ }
436
+
437
+ function $cloneContents(selection) {
438
+ if (!lexical.$isRangeSelection(selection)) {
439
+ {
440
+ throw Error(`TODO`);
441
+ }
442
+ }
443
+
444
+ const anchor = selection.anchor;
445
+ const focus = selection.focus;
446
+ const anchorOffset = anchor.getCharacterOffset();
447
+ const focusOffset = focus.getCharacterOffset();
448
+ const anchorNode = anchor.getNode();
449
+ const focusNode = focus.getNode();
450
+ const anchorNodeParent = anchorNode.getParentOrThrow(); // Handle a single text node extraction
451
+
452
+ if (anchorNode === focusNode && lexical.$isTextNode(anchorNode) && (anchorNodeParent.canBeEmpty() || anchorNodeParent.getChildrenSize() > 1)) {
453
+ const clonedFirstNode = $cloneWithProperties(anchorNode);
454
+ const isBefore = focusOffset > anchorOffset;
455
+ const startOffset = isBefore ? anchorOffset : focusOffset;
456
+ const endOffset = isBefore ? focusOffset : anchorOffset;
457
+ clonedFirstNode.__text = clonedFirstNode.__text.slice(startOffset, endOffset);
458
+ const key = clonedFirstNode.getKey();
459
+ return {
460
+ nodeMap: [[key, clonedFirstNode]],
461
+ range: [key]
462
+ };
463
+ }
464
+
465
+ const nodes = selection.getNodes();
466
+
467
+ if (nodes.length === 0) {
468
+ return {
469
+ nodeMap: [],
470
+ range: []
471
+ };
472
+ } // Check if we can use the parent of the nodes, if the
473
+ // parent can't be empty, then it's important that we
474
+ // also copy that element node along with its children.
475
+
476
+
477
+ let nodesLength = nodes.length;
478
+ const firstNode = nodes[0];
479
+ const firstNodeParent = firstNode.getParent();
480
+
481
+ if (firstNodeParent !== null && (!firstNodeParent.canBeEmpty() || lexical.$isRootNode(firstNodeParent))) {
482
+ const parentChildren = firstNodeParent.__children;
483
+ const parentChildrenLength = parentChildren.length;
484
+
485
+ if (parentChildrenLength === nodesLength) {
486
+ let areTheSame = true;
487
+
488
+ for (let i = 0; i < parentChildren.length; i++) {
489
+ if (parentChildren[i] !== nodes[i].__key) {
490
+ areTheSame = false;
491
+ break;
492
+ }
493
+ }
494
+
495
+ if (areTheSame) {
496
+ nodesLength++;
497
+ nodes.push(firstNodeParent);
498
+ }
499
+ }
500
+ }
501
+
502
+ const lastNode = nodes[nodesLength - 1];
503
+ const isBefore = anchor.isBefore(focus);
504
+ const nodeMap = new Map();
505
+ const range = []; // Do first node to root
506
+
507
+ $copyLeafNodeBranchToRoot(firstNode, isBefore ? anchorOffset : focusOffset, true, range, nodeMap); // Copy all nodes between
508
+
509
+ for (let i = 0; i < nodesLength; i++) {
510
+ const node = nodes[i];
511
+ const key = node.getKey();
512
+
513
+ if (!nodeMap.has(key) && (!lexical.$isElementNode(node) || !node.excludeFromCopy())) {
514
+ const clone = $cloneWithProperties(node);
515
+
516
+ if (lexical.$isRootNode(node.getParent())) {
517
+ range.push(node.getKey());
518
+ }
519
+
520
+ nodeMap.set(key, clone);
521
+ }
522
+ } // Do last node to root
523
+
524
+
525
+ $copyLeafNodeBranchToRoot(lastNode, isBefore ? focusOffset : anchorOffset, false, range, nodeMap);
526
+ return {
527
+ nodeMap: Array.from(nodeMap.entries()),
528
+ range
529
+ };
530
+ }
531
+
532
+ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
533
+ selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
534
+ }
535
+ function $isParentElementRTL(selection) {
536
+ const anchorNode = selection.anchor.getNode();
537
+ const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
538
+ return parent.getDirection() === 'rtl';
539
+ }
540
+ function $moveCharacter(selection, isHoldingShift, isBackward) {
541
+ const isRTL = $isParentElementRTL(selection);
542
+ $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
543
+ }
544
+
545
+ /**
546
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
547
+ *
548
+ * This source code is licensed under the MIT license found in the
549
+ * LICENSE file in the root directory of this source tree.
550
+ *
551
+ *
552
+ */
553
+ function resolveElement(element, isBackward, focusOffset) {
554
+ const parent = element.getParent();
555
+ let offset = focusOffset;
556
+ let block = element;
557
+
558
+ if (parent !== null) {
559
+ if (isBackward && focusOffset === 0) {
560
+ offset = block.getIndexWithinParent();
561
+ block = parent;
562
+ } else if (!isBackward && focusOffset === block.getChildrenSize()) {
563
+ offset = block.getIndexWithinParent() + 1;
564
+ block = parent;
565
+ }
566
+ }
567
+
568
+ return block.getChildAtIndex(isBackward ? offset - 1 : offset);
569
+ }
570
+
571
+ function getPossibleDecoratorNode(focus, isBackward) {
572
+ const focusOffset = focus.offset;
573
+
574
+ if (focus.type === 'element') {
575
+ const block = focus.getNode();
576
+ return resolveElement(block, isBackward, focusOffset);
577
+ } else {
578
+ const focusNode = focus.getNode();
579
+
580
+ if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
581
+ const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
582
+
583
+ if (possibleNode === null) {
584
+ return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
585
+ }
586
+
587
+ return possibleNode;
588
+ }
589
+ }
590
+
591
+ return null;
592
+ }
593
+
594
+ /**
595
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
596
+ *
597
+ * This source code is licensed under the MIT license found in the
598
+ * LICENSE file in the root directory of this source tree.
599
+ *
600
+ *
601
+ */
602
+
603
+ function $generateNodes(nodeRange) {
604
+ const {
605
+ range,
606
+ nodeMap
607
+ } = nodeRange;
608
+ const parsedNodeMap = new Map(nodeMap);
609
+ const nodes = [];
610
+
611
+ for (let i = 0; i < range.length; i++) {
612
+ const key = range[i];
613
+ const parsedNode = parsedNodeMap.get(key);
614
+
615
+ if (parsedNode !== undefined) {
616
+ const node = lexical.$createNodeFromParse(parsedNode, parsedNodeMap);
617
+ nodes.push(node);
618
+ }
619
+ }
620
+
621
+ return nodes;
622
+ }
623
+
624
+ function getConversionFunction(domNode, editor) {
625
+ const {
626
+ nodeName
627
+ } = domNode;
628
+
629
+ const cachedConversions = editor._htmlConversions.get(nodeName.toLowerCase());
630
+
631
+ let currentConversion = null;
632
+
633
+ if (cachedConversions !== undefined) {
634
+ cachedConversions.forEach(cachedConversion => {
635
+ const domConversion = cachedConversion(domNode);
636
+
637
+ if (domConversion !== null) {
638
+ if (currentConversion === null || currentConversion.priority < domConversion.priority) {
639
+ currentConversion = domConversion;
640
+ }
641
+ }
642
+ });
643
+ }
644
+
645
+ return currentConversion !== null ? currentConversion.conversion : null;
646
+ }
647
+
648
+ function $createNodesFromDOM(node, editor, forChildMap = new Map()) {
649
+ let lexicalNodes = [];
650
+ let currentLexicalNode = null;
651
+ const transformFunction = getConversionFunction(node, editor);
652
+ const transformOutput = transformFunction ? transformFunction(node) : null;
653
+ let postTransform = null;
654
+
655
+ if (transformOutput !== null) {
656
+ postTransform = transformOutput.after;
657
+ currentLexicalNode = transformOutput.node;
658
+
659
+ if (currentLexicalNode !== null) {
660
+ lexicalNodes.push(currentLexicalNode);
661
+ const forChildFunctions = Array.from(forChildMap.values());
662
+
663
+ for (let i = 0; i < forChildFunctions.length; i++) {
664
+ forChildFunctions[i](currentLexicalNode);
665
+ }
666
+ }
667
+
668
+ if (transformOutput.forChild != null) {
669
+ forChildMap.set(node.nodeName, transformOutput.forChild);
670
+ }
671
+ } // If the DOM node doesn't have a transformer, we don't know what
672
+ // to do with it but we still need to process any childNodes.
673
+
674
+
675
+ const children = node.childNodes;
676
+ let childLexicalNodes = [];
677
+
678
+ for (let i = 0; i < children.length; i++) {
679
+ childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, forChildMap));
680
+ }
681
+
682
+ if (postTransform != null) {
683
+ childLexicalNodes = postTransform(childLexicalNodes);
684
+ }
685
+
686
+ if (currentLexicalNode == null) {
687
+ // If it hasn't been converted to a LexicalNode, we hoist its children
688
+ // up to the same level as it.
689
+ lexicalNodes = lexicalNodes.concat(childLexicalNodes);
690
+ } else {
691
+ if (lexical.$isElementNode(currentLexicalNode)) {
692
+ // If the current node is a ElementNode after conversion,
693
+ // we can append all the children to it.
694
+ currentLexicalNode.append(...childLexicalNodes);
695
+ }
696
+ }
697
+
698
+ return lexicalNodes;
699
+ }
700
+
701
+ function $generateNodesFromDOM(dom, editor) {
702
+ let lexicalNodes = [];
703
+ const elements = dom.body ? Array.from(dom.body.childNodes) : [];
704
+ const elementsLength = elements.length;
705
+
706
+ for (let i = 0; i < elementsLength; i++) {
707
+ const lexicalNode = $createNodesFromDOM(elements[i], editor);
708
+
709
+ if (lexicalNode !== null) {
710
+ lexicalNodes = lexicalNodes.concat(lexicalNode);
711
+ }
712
+ }
713
+
714
+ return lexicalNodes;
715
+ }
716
+
717
+ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
718
+ const lexicalNodesString = dataTransfer.getData('application/x-lexical-editor');
719
+
720
+ if (lexicalNodesString) {
721
+ const namespace = editor._config.namespace;
722
+
723
+ try {
724
+ const lexicalClipboardData = JSON.parse(lexicalNodesString);
725
+
726
+ if (lexicalClipboardData.namespace === namespace) {
727
+ const nodeRange = lexicalClipboardData.state;
728
+ const nodes = $generateNodes(nodeRange);
729
+ selection.insertNodes(nodes);
730
+ return;
731
+ }
732
+ } catch (e) {// Malformed, missing nodes..
733
+ }
734
+ }
735
+
736
+ const textHtmlMimeType = 'text/html';
737
+ const htmlString = dataTransfer.getData(textHtmlMimeType);
738
+
739
+ if (htmlString) {
740
+ const parser = new DOMParser();
741
+ const dom = parser.parseFromString(htmlString, textHtmlMimeType);
742
+ const nodes = $generateNodesFromDOM(dom, editor); // Wrap text and inline nodes in paragraph nodes so we have all blocks at the top-level
743
+
744
+ const topLevelBlocks = [];
745
+ let currentBlock = null;
746
+
747
+ for (let i = 0; i < nodes.length; i++) {
748
+ const node = nodes[i];
749
+
750
+ if (!lexical.$isElementNode(node) || node.isInline()) {
751
+ if (currentBlock === null) {
752
+ currentBlock = lexical.$createParagraphNode();
753
+ topLevelBlocks.push(currentBlock);
754
+ }
755
+
756
+ if (currentBlock !== null) {
757
+ currentBlock.append(node);
758
+ }
759
+ } else {
760
+ topLevelBlocks.push(node);
761
+ currentBlock = null;
762
+ }
763
+ }
764
+
765
+ selection.insertNodes(topLevelBlocks);
766
+ return;
767
+ }
768
+
769
+ $insertDataTransferForPlainText(dataTransfer, selection);
770
+ }
771
+ function $insertDataTransferForPlainText(dataTransfer, selection) {
772
+ const text = dataTransfer.getData('text/plain');
773
+
774
+ if (text != null) {
775
+ selection.insertRawText(text);
776
+ }
777
+ }
778
+ function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
779
+ const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
780
+ return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
781
+ }
782
+ function onPasteForRichText(event, editor) {
783
+ event.preventDefault();
784
+ editor.update(() => {
785
+ const selection = lexical.$getSelection();
786
+ const clipboardData = event.clipboardData;
787
+
788
+ if (clipboardData != null && lexical.$isRangeSelection(selection)) {
789
+ $insertDataTransferForRichText(clipboardData, selection, editor);
790
+ }
791
+ });
792
+ }
793
+ function onCutForRichText(event, editor) {
794
+ onCopyForRichText(event, editor);
795
+ editor.update(() => {
796
+ const selection = lexical.$getSelection();
797
+
798
+ if (lexical.$isRangeSelection(selection)) {
799
+ selection.removeText();
800
+ }
801
+ });
802
+ }
803
+ function onCopyForRichText(event, editor) {
804
+ event.preventDefault();
805
+ editor.update(() => {
806
+ const clipboardData = event.clipboardData;
807
+ const selection = lexical.$getSelection();
808
+
809
+ if (selection !== null) {
810
+ if (clipboardData != null) {
811
+ const domSelection = window.getSelection(); // If we haven't selected a range, then don't copy anything
812
+
813
+ if (domSelection.isCollapsed) {
814
+ return;
815
+ }
816
+
817
+ const range = domSelection.getRangeAt(0);
818
+
819
+ if (range) {
820
+ const container = document.createElement('div');
821
+ const frag = range.cloneContents();
822
+ container.appendChild(frag);
823
+ clipboardData.setData('text/html', container.innerHTML);
824
+ }
825
+
826
+ clipboardData.setData('text/plain', selection.getTextContent());
827
+ const namespace = editor._config.namespace;
828
+ clipboardData.setData('application/x-lexical-editor', JSON.stringify({
829
+ namespace,
830
+ state: $cloneContents(selection)
831
+ }));
832
+ }
833
+ }
834
+ });
835
+ }
836
+
837
+ /**
838
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
839
+ *
840
+ * This source code is licensed under the MIT license found in the
841
+ * LICENSE file in the root directory of this source tree.
842
+ *
843
+ *
844
+ */
845
+ function useLexicalDragonSupport(editor) {
846
+ react.useEffect(() => {
847
+ const handler = event => {
848
+ const rootElement = editor.getRootElement();
849
+
850
+ if (document.activeElement !== rootElement) {
851
+ return;
852
+ }
853
+
854
+ const data = event.data;
855
+
856
+ if (typeof data === 'string') {
857
+ let parsedData;
858
+
859
+ try {
860
+ parsedData = JSON.parse(data);
861
+ } catch (e) {
862
+ return;
863
+ }
864
+
865
+ if (parsedData && parsedData.protocol === 'nuanria_messaging' && parsedData.type === 'request') {
866
+ const payload = parsedData.payload;
867
+
868
+ if (payload && payload.functionId === 'makeChanges') {
869
+ const args = payload.args;
870
+
871
+ if (args) {
872
+ const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
873
+ editor.update(() => {
874
+ const selection = lexical.$getSelection();
875
+
876
+ if (lexical.$isRangeSelection(selection)) {
877
+ const anchor = selection.anchor;
878
+ let anchorNode = anchor.getNode();
879
+ let setSelStart = 0;
880
+ let setSelEnd = 0;
881
+
882
+ if (lexical.$isTextNode(anchorNode)) {
883
+ // set initial selection
884
+ if (elementStart >= 0 && elementLength >= 0) {
885
+ setSelStart = elementStart;
886
+ setSelEnd = elementStart + elementLength; // If the offset is more than the end, make it the end
887
+
888
+ selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
889
+ }
890
+ }
891
+
892
+ if (setSelStart !== setSelEnd || text !== '') {
893
+ selection.insertRawText(text);
894
+ anchorNode = anchor.getNode();
895
+ }
896
+
897
+ if (lexical.$isTextNode(anchorNode)) {
898
+ // set final selection
899
+ setSelStart = selStart;
900
+ setSelEnd = selStart + selLength;
901
+ const anchorNodeTextLength = anchorNode.getTextContentSize(); // If the offset is more than the end, make it the end
902
+
903
+ setSelStart = setSelStart > anchorNodeTextLength ? anchorNodeTextLength : setSelStart;
904
+ setSelEnd = setSelEnd > anchorNodeTextLength ? anchorNodeTextLength : setSelEnd;
905
+ selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
906
+ } // block the chrome extension from handling this event
907
+
908
+
909
+ event.stopImmediatePropagation();
910
+ }
911
+ });
912
+ }
913
+ }
914
+ }
915
+ }
916
+ };
917
+
918
+ window.addEventListener('message', handler, true);
919
+ return () => {
920
+ window.removeEventListener('message', handler, true);
921
+ };
922
+ }, [editor]);
923
+ }
924
+
925
+ /**
926
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
927
+ *
928
+ * This source code is licensed under the MIT license found in the
929
+ * LICENSE file in the root directory of this source tree.
930
+ *
931
+ *
932
+ */
933
+ function useRichTextSetup(editor) {
934
+ react.useEffect(() => {
935
+ const removeListener = editor.addListener('command', (type, payload) => {
936
+ const selection = lexical.$getSelection();
937
+
938
+ if (type === 'click' && lexical.$isNodeSelection(selection)) {
939
+ selection.clear();
940
+ return true;
941
+ }
942
+
943
+ if (!lexical.$isRangeSelection(selection)) {
944
+ return false;
945
+ }
946
+
947
+ switch (type) {
948
+ case 'deleteCharacter':
949
+ {
950
+ const isBackward = payload;
951
+ selection.deleteCharacter(isBackward);
952
+ return true;
953
+ }
954
+
955
+ case 'deleteWord':
956
+ {
957
+ const isBackward = payload;
958
+ selection.deleteWord(isBackward);
959
+ return true;
960
+ }
961
+
962
+ case 'deleteLine':
963
+ {
964
+ const isBackward = payload;
965
+ selection.deleteLine(isBackward);
966
+ return true;
967
+ }
968
+
969
+ case 'insertText':
970
+ {
971
+ const eventOrText = payload;
972
+
973
+ if (typeof eventOrText === 'string') {
974
+ selection.insertText(eventOrText);
975
+ } else {
976
+ const dataTransfer = eventOrText.dataTransfer;
977
+
978
+ if (dataTransfer != null) {
979
+ $insertDataTransferForRichText(dataTransfer, selection, editor);
980
+ } else {
981
+ const data = eventOrText.data;
982
+
983
+ if (data) {
984
+ selection.insertText(data);
985
+ }
986
+ }
987
+ }
988
+
989
+ return true;
990
+ }
991
+
992
+ case 'removeText':
993
+ selection.removeText();
994
+ return true;
995
+
996
+ case 'formatText':
997
+ {
998
+ const format = payload;
999
+ selection.formatText(format);
1000
+ return true;
1001
+ }
1002
+
1003
+ case 'formatElement':
1004
+ {
1005
+ const format = payload;
1006
+ const node = selection.anchor.getNode();
1007
+ const element = lexical.$isElementNode(node) ? node : node.getParentOrThrow();
1008
+ element.setFormat(format);
1009
+ return true;
1010
+ }
1011
+
1012
+ case 'insertLineBreak':
1013
+ const selectStart = payload;
1014
+ selection.insertLineBreak(selectStart);
1015
+ return true;
1016
+
1017
+ case 'insertParagraph':
1018
+ selection.insertParagraph();
1019
+ return true;
1020
+
1021
+ case 'indentContent':
1022
+ {
1023
+ // Handle code blocks
1024
+ const anchor = selection.anchor;
1025
+ const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
1026
+
1027
+ if (parentBlock.canInsertTab()) {
1028
+ editor.execCommand('insertText', '\t');
1029
+ } else {
1030
+ if (parentBlock.getIndent() !== 10) {
1031
+ parentBlock.setIndent(parentBlock.getIndent() + 1);
1032
+ }
1033
+ }
1034
+
1035
+ return true;
1036
+ }
1037
+
1038
+ case 'outdentContent':
1039
+ {
1040
+ // Handle code blocks
1041
+ const anchor = selection.anchor;
1042
+ const anchorNode = anchor.getNode();
1043
+ const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
1044
+
1045
+ if (parentBlock.canInsertTab()) {
1046
+ const textContent = anchorNode.getTextContent();
1047
+ const character = textContent[anchor.offset - 1];
1048
+
1049
+ if (character === '\t') {
1050
+ editor.execCommand('deleteCharacter', true);
1051
+ }
1052
+ } else {
1053
+ if (parentBlock.getIndent() !== 0) {
1054
+ parentBlock.setIndent(parentBlock.getIndent() - 1);
1055
+ }
1056
+ }
1057
+
1058
+ return true;
1059
+ }
1060
+
1061
+ case 'keyArrowLeft':
1062
+ {
1063
+ const event = payload;
1064
+ const isHoldingShift = event.shiftKey;
1065
+
1066
+ if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
1067
+ event.preventDefault();
1068
+ $moveCharacter(selection, isHoldingShift, true);
1069
+ return true;
1070
+ }
1071
+
1072
+ return false;
1073
+ }
1074
+
1075
+ case 'keyArrowRight':
1076
+ {
1077
+ const event = payload;
1078
+ const isHoldingShift = event.shiftKey;
1079
+
1080
+ if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
1081
+ event.preventDefault();
1082
+ $moveCharacter(selection, isHoldingShift, false);
1083
+ return true;
1084
+ }
1085
+
1086
+ return false;
1087
+ }
1088
+
1089
+ case 'keyBackspace':
1090
+ {
1091
+ const event = payload;
1092
+ event.preventDefault();
1093
+ const {
1094
+ anchor
1095
+ } = selection;
1096
+
1097
+ if (selection.isCollapsed() && anchor.offset === 0) {
1098
+ const element = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
1099
+
1100
+ if (element.getIndent() > 0) {
1101
+ return editor.execCommand('outdentContent');
1102
+ }
1103
+ }
1104
+
1105
+ return editor.execCommand('deleteCharacter', true);
1106
+ }
1107
+
1108
+ case 'keyDelete':
1109
+ {
1110
+ const event = payload;
1111
+ event.preventDefault();
1112
+ return editor.execCommand('deleteCharacter', false);
1113
+ }
1114
+
1115
+ case 'keyEnter':
1116
+ {
1117
+ const event = payload;
1118
+ event.preventDefault();
1119
+
1120
+ if (event.shiftKey) {
1121
+ return editor.execCommand('insertLineBreak');
1122
+ }
1123
+
1124
+ return editor.execCommand('insertParagraph');
1125
+ }
1126
+
1127
+ case 'keyTab':
1128
+ {
1129
+ const event = payload;
1130
+ event.preventDefault();
1131
+ return editor.execCommand(event.shiftKey ? 'outdentContent' : 'indentContent');
1132
+ }
1133
+
1134
+ case 'keyEscape':
1135
+ {
1136
+ editor.blur();
1137
+ return true;
1138
+ }
1139
+
1140
+ case 'copy':
1141
+ {
1142
+ const event = payload;
1143
+ onCopyForRichText(event, editor);
1144
+ return true;
1145
+ }
1146
+
1147
+ case 'cut':
1148
+ {
1149
+ const event = payload;
1150
+ onCutForRichText(event, editor);
1151
+ return true;
1152
+ }
1153
+
1154
+ case 'paste':
1155
+ {
1156
+ const event = payload;
1157
+ onPasteForRichText(event, editor);
1158
+ return true;
1159
+ }
1160
+
1161
+ case 'drop':
1162
+ case 'dragstart':
1163
+ {
1164
+ // TODO: Make drag and drop work at some point.
1165
+ const event = payload;
1166
+ event.preventDefault();
1167
+ return true;
1168
+ }
1169
+ }
1170
+
1171
+ return false;
1172
+ }, 0);
1173
+ const bootstrapCommandHandled = editor.execCommand('bootstrapEditor');
1174
+
1175
+ if (!bootstrapCommandHandled) {
1176
+ console.warn('bootstrapEditor command was not handled. Did you forget to add <BootstrapPlugin />?');
1177
+ }
1178
+
1179
+ return removeListener;
1180
+ }, [editor]);
1181
+ useLexicalDragonSupport(editor);
1182
+ }
1183
+
1184
+ /**
1185
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
1186
+ *
1187
+ * This source code is licensed under the MIT license found in the
1188
+ * LICENSE file in the root directory of this source tree.
1189
+ *
1190
+ *
1191
+ */
1192
+ function useLexicalRichText(editor, externalHistoryState) {
1193
+ useRichTextSetup(editor);
1194
+ useLexicalHistory(editor, externalHistoryState);
1195
+ }
1196
+
1197
+ module.exports = useLexicalRichText;