@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,589 @@
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 LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
+ var React = require('react');
11
+ var lexical = require('lexical');
12
+ var reactDom = require('react-dom');
13
+
14
+ /**
15
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ *
20
+ *
21
+ */
22
+ function $textContent() {
23
+ const root = lexical.$getRoot();
24
+ return root.getTextContent();
25
+ }
26
+ function $isTextContentEmpty(isEditorComposing, trim = true) {
27
+ if (isEditorComposing) {
28
+ return false;
29
+ }
30
+
31
+ let text = $textContent();
32
+
33
+ if (trim) {
34
+ text = text.trim();
35
+ }
36
+
37
+ return text === '';
38
+ }
39
+ function $canShowPlaceholder(isComposing) {
40
+ if (!$isTextContentEmpty(isComposing, false)) {
41
+ return false;
42
+ }
43
+
44
+ const root = lexical.$getRoot();
45
+ const children = root.getChildren();
46
+ const childrenLength = children.length;
47
+
48
+ if (childrenLength > 1) {
49
+ return false;
50
+ }
51
+
52
+ for (let i = 0; i < childrenLength; i++) {
53
+ const topBlock = children[i];
54
+
55
+ if (lexical.$isElementNode(topBlock)) {
56
+ if (topBlock.__type !== 'paragraph') {
57
+ return false;
58
+ }
59
+
60
+ if (topBlock.__indent !== 0) {
61
+ return false;
62
+ }
63
+
64
+ const topBlockChildren = topBlock.getChildren();
65
+ const topBlockChildrenLength = topBlockChildren.length;
66
+
67
+ for (let s = 0; s < topBlockChildrenLength; s++) {
68
+ const child = topBlockChildren[i];
69
+
70
+ if (!lexical.$isTextNode(child)) {
71
+ return false;
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ return true;
78
+ }
79
+ function $canShowPlaceholderCurry(isEditorComposing) {
80
+ return () => $canShowPlaceholder(isEditorComposing);
81
+ }
82
+
83
+ /**
84
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
85
+ *
86
+ * This source code is licensed under the MIT license found in the
87
+ * LICENSE file in the root directory of this source tree.
88
+ *
89
+ *
90
+ */
91
+ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
92
+
93
+ /**
94
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
95
+ *
96
+ * This source code is licensed under the MIT license found in the
97
+ * LICENSE file in the root directory of this source tree.
98
+ *
99
+ *
100
+ */
101
+ const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
102
+ var useLayoutEffect = useLayoutEffectImpl;
103
+
104
+ /**
105
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
106
+ *
107
+ * This source code is licensed under the MIT license found in the
108
+ * LICENSE file in the root directory of this source tree.
109
+ *
110
+ *
111
+ */
112
+ function useLexicalCanShowPlaceholder(editor) {
113
+ const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing())));
114
+ useLayoutEffect(() => {
115
+ return editor.addListener('update', ({
116
+ editorState
117
+ }) => {
118
+ const isComposing = editor.isComposing();
119
+ const currentCanShowPlaceholder = editorState.read($canShowPlaceholderCurry(isComposing));
120
+ setCanShowPlaceholder(currentCanShowPlaceholder);
121
+ });
122
+ }, [editor]);
123
+ return canShowPlaceholder;
124
+ }
125
+
126
+ /**
127
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
128
+ *
129
+ * This source code is licensed under the MIT license found in the
130
+ * LICENSE file in the root directory of this source tree.
131
+ *
132
+ *
133
+ */
134
+ function useDecorators(editor) {
135
+ const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
136
+
137
+ useLayoutEffect(() => {
138
+ return editor.addListener('decorator', nextDecorators => {
139
+ reactDom.flushSync(() => {
140
+ setDecorators(nextDecorators);
141
+ });
142
+ });
143
+ }, [editor]); // Return decorators defined as React Portals
144
+
145
+ return React.useMemo(() => {
146
+ const decoratedPortals = [];
147
+ const decoratorKeys = Object.keys(decorators);
148
+
149
+ for (let i = 0; i < decoratorKeys.length; i++) {
150
+ const nodeKey = decoratorKeys[i];
151
+ const reactDecorator = decorators[nodeKey];
152
+ const element = editor.getElementByKey(nodeKey);
153
+
154
+ if (element !== null) {
155
+ decoratedPortals.push( /*#__PURE__*/reactDom.createPortal(reactDecorator, element));
156
+ }
157
+ }
158
+
159
+ return decoratedPortals;
160
+ }, [decorators, editor]);
161
+ }
162
+
163
+ /**
164
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
165
+ *
166
+ * This source code is licensed under the MIT license found in the
167
+ * LICENSE file in the root directory of this source tree.
168
+ *
169
+ *
170
+ */
171
+
172
+ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
173
+ selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
174
+ }
175
+ function $isParentElementRTL(selection) {
176
+ const anchorNode = selection.anchor.getNode();
177
+ const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
178
+ return parent.getDirection() === 'rtl';
179
+ }
180
+ function $moveCharacter(selection, isHoldingShift, isBackward) {
181
+ const isRTL = $isParentElementRTL(selection);
182
+ $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
183
+ }
184
+
185
+ /**
186
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
187
+ *
188
+ * This source code is licensed under the MIT license found in the
189
+ * LICENSE file in the root directory of this source tree.
190
+ *
191
+ *
192
+ */
193
+ function resolveElement(element, isBackward, focusOffset) {
194
+ const parent = element.getParent();
195
+ let offset = focusOffset;
196
+ let block = element;
197
+
198
+ if (parent !== null) {
199
+ if (isBackward && focusOffset === 0) {
200
+ offset = block.getIndexWithinParent();
201
+ block = parent;
202
+ } else if (!isBackward && focusOffset === block.getChildrenSize()) {
203
+ offset = block.getIndexWithinParent() + 1;
204
+ block = parent;
205
+ }
206
+ }
207
+
208
+ return block.getChildAtIndex(isBackward ? offset - 1 : offset);
209
+ }
210
+
211
+ function getPossibleDecoratorNode(focus, isBackward) {
212
+ const focusOffset = focus.offset;
213
+
214
+ if (focus.type === 'element') {
215
+ const block = focus.getNode();
216
+ return resolveElement(block, isBackward, focusOffset);
217
+ } else {
218
+ const focusNode = focus.getNode();
219
+
220
+ if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
221
+ const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
222
+
223
+ if (possibleNode === null) {
224
+ return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
225
+ }
226
+
227
+ return possibleNode;
228
+ }
229
+ }
230
+
231
+ return null;
232
+ }
233
+
234
+ /**
235
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
236
+ *
237
+ * This source code is licensed under the MIT license found in the
238
+ * LICENSE file in the root directory of this source tree.
239
+ *
240
+ *
241
+ */
242
+ function $insertDataTransferForPlainText(dataTransfer, selection) {
243
+ const text = dataTransfer.getData('text/plain');
244
+
245
+ if (text != null) {
246
+ selection.insertRawText(text);
247
+ }
248
+ }
249
+ function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
250
+ const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
251
+ return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
252
+ }
253
+ function onPasteForPlainText(event, editor) {
254
+ event.preventDefault();
255
+ editor.update(() => {
256
+ const selection = lexical.$getSelection();
257
+ const clipboardData = event.clipboardData;
258
+
259
+ if (clipboardData != null && lexical.$isRangeSelection(selection)) {
260
+ $insertDataTransferForPlainText(clipboardData, selection);
261
+ }
262
+ });
263
+ }
264
+ function onCutForPlainText(event, editor) {
265
+ onCopyForPlainText(event, editor);
266
+ editor.update(() => {
267
+ const selection = lexical.$getSelection();
268
+
269
+ if (lexical.$isRangeSelection(selection)) {
270
+ selection.removeText();
271
+ }
272
+ });
273
+ }
274
+ function onCopyForPlainText(event, editor) {
275
+ event.preventDefault();
276
+ editor.update(() => {
277
+ const clipboardData = event.clipboardData;
278
+ const selection = lexical.$getSelection();
279
+
280
+ if (selection !== null) {
281
+ if (clipboardData != null) {
282
+ const domSelection = window.getSelection(); // If we haven't selected a range, then don't copy anything
283
+
284
+ if (domSelection.isCollapsed) {
285
+ return;
286
+ }
287
+
288
+ const range = domSelection.getRangeAt(0);
289
+
290
+ if (range) {
291
+ const container = document.createElement('div');
292
+ const frag = range.cloneContents();
293
+ container.appendChild(frag);
294
+ clipboardData.setData('text/html', container.innerHTML);
295
+ }
296
+
297
+ clipboardData.setData('text/plain', selection.getTextContent());
298
+ }
299
+ }
300
+ });
301
+ }
302
+
303
+ /**
304
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
305
+ *
306
+ * This source code is licensed under the MIT license found in the
307
+ * LICENSE file in the root directory of this source tree.
308
+ *
309
+ *
310
+ */
311
+ function useLexicalDragonSupport(editor) {
312
+ React.useEffect(() => {
313
+ const handler = event => {
314
+ const rootElement = editor.getRootElement();
315
+
316
+ if (document.activeElement !== rootElement) {
317
+ return;
318
+ }
319
+
320
+ const data = event.data;
321
+
322
+ if (typeof data === 'string') {
323
+ let parsedData;
324
+
325
+ try {
326
+ parsedData = JSON.parse(data);
327
+ } catch (e) {
328
+ return;
329
+ }
330
+
331
+ if (parsedData && parsedData.protocol === 'nuanria_messaging' && parsedData.type === 'request') {
332
+ const payload = parsedData.payload;
333
+
334
+ if (payload && payload.functionId === 'makeChanges') {
335
+ const args = payload.args;
336
+
337
+ if (args) {
338
+ const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
339
+ editor.update(() => {
340
+ const selection = lexical.$getSelection();
341
+
342
+ if (lexical.$isRangeSelection(selection)) {
343
+ const anchor = selection.anchor;
344
+ let anchorNode = anchor.getNode();
345
+ let setSelStart = 0;
346
+ let setSelEnd = 0;
347
+
348
+ if (lexical.$isTextNode(anchorNode)) {
349
+ // set initial selection
350
+ if (elementStart >= 0 && elementLength >= 0) {
351
+ setSelStart = elementStart;
352
+ setSelEnd = elementStart + elementLength; // If the offset is more than the end, make it the end
353
+
354
+ selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
355
+ }
356
+ }
357
+
358
+ if (setSelStart !== setSelEnd || text !== '') {
359
+ selection.insertRawText(text);
360
+ anchorNode = anchor.getNode();
361
+ }
362
+
363
+ if (lexical.$isTextNode(anchorNode)) {
364
+ // set final selection
365
+ setSelStart = selStart;
366
+ setSelEnd = selStart + selLength;
367
+ const anchorNodeTextLength = anchorNode.getTextContentSize(); // If the offset is more than the end, make it the end
368
+
369
+ setSelStart = setSelStart > anchorNodeTextLength ? anchorNodeTextLength : setSelStart;
370
+ setSelEnd = setSelEnd > anchorNodeTextLength ? anchorNodeTextLength : setSelEnd;
371
+ selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
372
+ } // block the chrome extension from handling this event
373
+
374
+
375
+ event.stopImmediatePropagation();
376
+ }
377
+ });
378
+ }
379
+ }
380
+ }
381
+ }
382
+ };
383
+
384
+ window.addEventListener('message', handler, true);
385
+ return () => {
386
+ window.removeEventListener('message', handler, true);
387
+ };
388
+ }, [editor]);
389
+ }
390
+
391
+ /**
392
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
393
+ *
394
+ * This source code is licensed under the MIT license found in the
395
+ * LICENSE file in the root directory of this source tree.
396
+ *
397
+ *
398
+ */
399
+ function usePlainTextSetup(editor) {
400
+ React.useEffect(() => {
401
+ const removeListener = editor.addListener('command', (type, payload) => {
402
+ const selection = lexical.$getSelection();
403
+
404
+ if (!lexical.$isRangeSelection(selection)) {
405
+ return false;
406
+ }
407
+
408
+ switch (type) {
409
+ case 'deleteCharacter':
410
+ {
411
+ const isBackward = payload;
412
+ selection.deleteCharacter(isBackward);
413
+ return true;
414
+ }
415
+
416
+ case 'deleteWord':
417
+ {
418
+ const isBackward = payload;
419
+ selection.deleteWord(isBackward);
420
+ return true;
421
+ }
422
+
423
+ case 'deleteLine':
424
+ {
425
+ const isBackward = payload;
426
+ selection.deleteLine(isBackward);
427
+ return true;
428
+ }
429
+
430
+ case 'insertText':
431
+ {
432
+ const eventOrText = payload;
433
+
434
+ if (typeof eventOrText === 'string') {
435
+ selection.insertText(eventOrText);
436
+ } else {
437
+ const dataTransfer = eventOrText.dataTransfer;
438
+
439
+ if (dataTransfer != null) {
440
+ $insertDataTransferForPlainText(dataTransfer, selection);
441
+ } else {
442
+ const data = eventOrText.data;
443
+
444
+ if (data) {
445
+ selection.insertText(data);
446
+ }
447
+ }
448
+ }
449
+
450
+ return true;
451
+ }
452
+
453
+ case 'removeText':
454
+ selection.removeText();
455
+ return true;
456
+
457
+ case 'insertLineBreak':
458
+ const selectStart = payload;
459
+ selection.insertLineBreak(selectStart);
460
+ return true;
461
+
462
+ case 'insertParagraph':
463
+ selection.insertLineBreak();
464
+ return true;
465
+
466
+ case 'indentContent':
467
+ case 'outdentContent':
468
+ case 'insertHorizontalRule':
469
+ case 'insertImage':
470
+ case 'insertTable':
471
+ case 'formatElement':
472
+ case 'formatText':
473
+ {
474
+ return true;
475
+ }
476
+
477
+ case 'keyArrowLeft':
478
+ {
479
+ const event = payload;
480
+ const isHoldingShift = event.shiftKey;
481
+
482
+ if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
483
+ event.preventDefault();
484
+ $moveCharacter(selection, isHoldingShift, true);
485
+ return true;
486
+ }
487
+
488
+ return false;
489
+ }
490
+
491
+ case 'keyArrowRight':
492
+ {
493
+ const event = payload;
494
+ const isHoldingShift = event.shiftKey;
495
+
496
+ if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
497
+ event.preventDefault();
498
+ $moveCharacter(selection, isHoldingShift, false);
499
+ return true;
500
+ }
501
+
502
+ return false;
503
+ }
504
+
505
+ case 'keyBackspace':
506
+ {
507
+ const event = payload;
508
+ event.preventDefault();
509
+ return editor.execCommand('deleteCharacter', true);
510
+ }
511
+
512
+ case 'keyDelete':
513
+ {
514
+ const event = payload;
515
+ event.preventDefault();
516
+ return editor.execCommand('deleteCharacter', false);
517
+ }
518
+
519
+ case 'keyEnter':
520
+ {
521
+ const event = payload;
522
+ event.preventDefault();
523
+ return editor.execCommand('insertLineBreak');
524
+ }
525
+
526
+ case 'copy':
527
+ {
528
+ const event = payload;
529
+ onCopyForPlainText(event, editor);
530
+ return true;
531
+ }
532
+
533
+ case 'cut':
534
+ {
535
+ const event = payload;
536
+ onCutForPlainText(event, editor);
537
+ return true;
538
+ }
539
+
540
+ case 'paste':
541
+ {
542
+ const event = payload;
543
+ onPasteForPlainText(event, editor);
544
+ return true;
545
+ }
546
+
547
+ case 'drop':
548
+ case 'dragstart':
549
+ {
550
+ // TODO: Make drag and drop work at some point.
551
+ const event = payload;
552
+ event.preventDefault();
553
+ return true;
554
+ }
555
+ }
556
+
557
+ return false;
558
+ }, 0);
559
+ const bootstrapCommandHandled = editor.execCommand('bootstrapEditor');
560
+
561
+ if (!bootstrapCommandHandled) {
562
+ console.warn('bootstrapEditor command was not handled. Did you forget to add <BootstrapPlugin />?');
563
+ }
564
+
565
+ return removeListener;
566
+ }, [editor]);
567
+ useLexicalDragonSupport(editor);
568
+ }
569
+
570
+ /**
571
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
572
+ *
573
+ * This source code is licensed under the MIT license found in the
574
+ * LICENSE file in the root directory of this source tree.
575
+ *
576
+ *
577
+ */
578
+ function PlainTextPlugin({
579
+ contentEditable,
580
+ placeholder
581
+ }) {
582
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
583
+ const showPlaceholder = useLexicalCanShowPlaceholder(editor);
584
+ usePlainTextSetup(editor);
585
+ const decorators = useDecorators(editor);
586
+ return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
587
+ }
588
+
589
+ module.exports = PlainTextPlugin;
@@ -1,13 +1,9 @@
1
- 'use strict';var g=require("react"),h=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),u=require("@lexical/react/withSubscriptions"),w=require("react-dom");
2
- function x(a){g.useEffect(()=>{const d=c=>{var e=a.getRootElement();if(document.activeElement===e&&(e=c.data,"string"===typeof e)){try{var b=JSON.parse(e)}catch(f){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [f,p,r,v,E]=b;a.update(()=>{t.$log("useLexicalDragonSupport");const q=t.$getSelection();if(null!==q){var n=q.anchor;let k=n.getNode(),l=0,m=0;t.$isTextNode(k)&&0<=f&&0<=p&&(l=f,m=f+p,q.setTextNodeRange(k,l,k,
3
- m));if(l!==m||""!==r)q.insertRawText(r),k=n.getNode();t.$isTextNode(k)&&(l=v,m=v+E,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));c.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}function y(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}
4
- function z(a,d){var c=a.focus;a=c.offset;"element"===c.type?d=c.getNode().getChildAtIndex(d?a-1:a):(c=c.getNode(),d=d&&0===a||!d&&a===c.getTextContentSize()?d?c.getPreviousSibling():c.getNextSibling():null);return t.$isDecoratorNode(d)}function A(a,d){a.preventDefault();d.update(()=>{t.$log("onPasteForPlainText");const c=t.$getSelection(),e=a.clipboardData;null!=e&&null!==c&&y(e,c)})}
5
- function B(a,d){C(a,d);d.update(()=>{t.$log("onCutForPlainText");const c=t.$getSelection();null!==c&&c.removeText()})}function C(a,d){a.preventDefault();d.update(()=>{t.$log("onCopyForPlainText");const c=a.clipboardData,e=t.$getSelection();if(null!==e&&null!=c){var b=window.getSelection();if(!b.isCollapsed){var f=b.getRangeAt(0);f&&(b=document.createElement("div"),f=f.cloneContents(),b.appendChild(f),c.setData("text/html",b.innerHTML));c.setData("text/plain",e.getTextContent())}}})}
6
- var D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function F(a,d){const c=t.$createParagraphNode();a.append(c);a=document.activeElement;(null!==t.$getSelection()||null!==a&&a===d.getRootElement())&&c.select()}function G(a){a.update(()=>{t.$log("initEditor");const d=t.$getRoot();null===d.getFirstChild()&&F(d,a)})}
7
- function H(a,d){a.update(()=>{t.$log("clearEditor");const c=t.$getRoot();c.clear();F(c,a)},{onUpdate:d})}
8
- function I(a,d){D(()=>{const c=u(a.addListener("command",(e,b)=>{const f=t.$getSelection();if(null===f)return!1;switch(e){case "deleteCharacter":return f.deleteCharacter(b),!0;case "deleteWord":return f.deleteWord(b),!0;case "deleteLine":return f.deleteLine(b),!0;case "insertText":return"string"===typeof b?f.insertText(b):(e=b.dataTransfer,null!=e?y(e,f):(b=b.data)&&f.insertText(b)),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(b),!0;case "insertParagraph":return f.insertLineBreak(),
9
- !0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":e=b.shiftKey;if(z(f,!0))return b.preventDefault(),b=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(b?"extend":"move",!e,"character"),!0;break;case "keyArrowRight":e=b.shiftKey;if(z(f,!1))return b.preventDefault(),b=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(b?"extend":
10
- "move",e,"character"),!0;break;case "keyBackspace":return b.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "clearEditor":H(a);break;case "copy":return C(b,a),!0;case "cut":return B(b,a),!0;case "paste":return A(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0));d&&G(a);return c},[a,d]);x(a)}
11
- function J(a){const [d,c]=g.useState(()=>a.getDecorators());D(()=>a.addListener("decorator",e=>{w.flushSync(()=>{c(e)})}),[a]);return g.useMemo(()=>{const e=[],b=Object.keys(d);for(let p=0;p<b.length;p++){var f=b[p];const r=d[f];f=a.getElementByKey(f);null!==f&&e.push(w.createPortal(r,f))}return e},[d,a])}function K(a,d=!0){if(a)return!1;a=t.$getRoot().getTextContent();d&&(a=a.trim());return""===a}
12
- function L(a){if(!K(a,!1))return!1;a=t.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let e=0;e<d;e++){var c=a[e];if(t.$isElementNode(c)){if("paragraph"!==c.__type||0!==c.__indent)return!1;c=c.getChildren();const b=c.length;for(let f=0;f<b;f++)if(!t.$isTextNode(c[e]))return!1}}return!0}function M(a){return()=>L(a)}
13
- function N(a){const [d,c]=g.useState(a.getEditorState().read(M(a.isComposing())));D(()=>a.addListener("update",({editorState:e})=>{const b=a.isComposing();e=e.read(M(b));c(e)}),[a]);return d}function O(a){throw a;}module.exports=function({contentEditable:a,placeholder:d,skipInit:c,onError:e}){const [b]=h.useLexicalComposerContext(),f=N(b);I(b,!c);c=J(b);D(()=>b.addListener("error",e||O),[b,e]);return g.createElement(g.Fragment,null,a,f&&d,c)};
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
+ const LexicalPlainTextPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalPlainTextPlugin.dev.js') : require('./LexicalPlainTextPlugin.prod.js')
9
+ module.exports = LexicalPlainTextPlugin;
@@ -0,0 +1,18 @@
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
+ var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),t=require("lexical"),u=require("react-dom");function v(a,e=!0){if(a)return!1;a=t.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
8
+ function w(a){if(!v(a,!1))return!1;a=t.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let c=0;c<e;c++){var b=a[c];if(t.$isElementNode(b)){if("paragraph"!==b.__type||0!==b.__indent)return!1;b=b.getChildren();const d=b.length;for(let f=0;f<d;f++)if(!t.$isTextNode(b[c]))return!1}}return!0}function x(a){return()=>w(a)}var y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
9
+ function z(a){const [e,b]=h.useState(a.getEditorState().read(x(a.isComposing())));y(()=>a.addListener("update",({editorState:c})=>{const d=a.isComposing();c=c.read(x(d));b(c)}),[a]);return e}function A(a){const [e,b]=h.useState(()=>a.getDecorators());y(()=>a.addListener("decorator",c=>{u.flushSync(()=>{b(c)})}),[a]);return h.useMemo(()=>{const c=[],d=Object.keys(e);for(let p=0;p<d.length;p++){var f=d[p];const r=e[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(r,f))}return c},[e,a])}
10
+ function C(a){a=a.anchor.getNode();return"rtl"===(t.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function D(a,e,b){const c=a.getParent();let d=b;null!==c&&(e&&0===b?(d=a.getIndexWithinParent(),a=c):e||b!==a.getChildrenSize()||(d=a.getIndexWithinParent()+1,a=c));return a.getChildAtIndex(e?d-1:d)}function E(a,e){a=a.getData("text/plain");null!=a&&e.insertRawText(a)}
11
+ function F(a,e){var b=a.focus;a=b.offset;"element"===b.type?(b=b.getNode(),e=D(b,e,a)):(b=b.getNode(),e&&0===a||!e&&a===b.getTextContentSize()?(a=e?b.getPreviousSibling():b.getNextSibling(),e=null===a?D(b.getParentOrThrow(),e,b.getIndexWithinParent()+(e?0:1)):a):e=null);return t.$isDecoratorNode(e)&&!e.isIsolated()}function G(a,e){a.preventDefault();e.update(()=>{const b=t.$getSelection(),c=a.clipboardData;null!=c&&t.$isRangeSelection(b)&&E(c,b)})}
12
+ function H(a,e){I(a,e);e.update(()=>{const b=t.$getSelection();t.$isRangeSelection(b)&&b.removeText()})}function I(a,e){a.preventDefault();e.update(()=>{const b=a.clipboardData,c=t.$getSelection();if(null!==c&&null!=b){var d=window.getSelection();if(!d.isCollapsed){var f=d.getRangeAt(0);f&&(d=document.createElement("div"),f=f.cloneContents(),d.appendChild(f),b.setData("text/html",d.innerHTML));b.setData("text/plain",c.getTextContent())}}})}
13
+ function J(a){h.useEffect(()=>{const e=b=>{var c=a.getRootElement();if(document.activeElement===c&&(c=b.data,"string"===typeof c)){try{var d=JSON.parse(c)}catch(f){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [f,p,r,B,K]=d;a.update(()=>{const q=t.$getSelection();if(t.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;t.$isTextNode(k)&&0<=f&&0<=p&&(l=f,m=f+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
14
+ r)q.insertRawText(r),k=n.getNode();t.$isTextNode(k)&&(l=B,m=B+K,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));b.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
15
+ function L(a){h.useEffect(()=>{const e=a.addListener("command",(b,c)=>{const d=t.$getSelection();if(!t.$isRangeSelection(d))return!1;switch(b){case "deleteCharacter":return d.deleteCharacter(c),!0;case "deleteWord":return d.deleteWord(c),!0;case "deleteLine":return d.deleteLine(c),!0;case "insertText":return"string"===typeof c?d.insertText(c):(b=c.dataTransfer,null!=b?E(b,d):(c=c.data)&&d.insertText(c)),!0;case "removeText":return d.removeText(),!0;case "insertLineBreak":return d.insertLineBreak(c),
16
+ !0;case "insertParagraph":return d.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(F(d,!0))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(F(d,!1))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
17
+ a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return I(c,a),!0;case "cut":return H(c,a),!0;case "paste":return G(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);J(a)}
18
+ module.exports=function({contentEditable:a,placeholder:e}){var [b]=g.useLexicalComposerContext();const c=z(b);L(b);b=A(b);return h.createElement(h.Fragment,null,a,c&&e,b)};