@lexical/react 0.1.16 → 0.1.17

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 (87) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +5 -729
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +1 -19
  3. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +1 -1
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +9 -10
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +7 -7
  7. package/DEPRECATED_useLexicalDecorators.dev.js +1 -1
  8. package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
  9. package/DEPRECATED_useLexicalEditorEvents.dev.js +1 -1
  10. package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
  11. package/DEPRECATED_useLexicalHistory.dev.js +5 -307
  12. package/DEPRECATED_useLexicalHistory.prod.js +1 -7
  13. package/DEPRECATED_useLexicalList.dev.js +29 -25
  14. package/DEPRECATED_useLexicalList.prod.js +3 -1
  15. package/DEPRECATED_useLexicalPlainText.dev.js +8 -662
  16. package/DEPRECATED_useLexicalPlainText.prod.js +2 -14
  17. package/DEPRECATED_useLexicalRichText.dev.js +8 -747
  18. package/DEPRECATED_useLexicalRichText.prod.js +2 -17
  19. package/LICENSE +1 -1
  20. package/{withSubscriptions.prod.js → LexicalAutoFocusPlugin.d.ts} +3 -1
  21. package/{withSubscriptions.dev.js → LexicalAutoFocusPlugin.dev.js} +10 -5
  22. package/LexicalAutoFocusPlugin.js +9 -0
  23. package/{LexicalAutoFormatterPlugin.js.flow → LexicalAutoFocusPlugin.js.flow} +1 -1
  24. package/LexicalAutoFocusPlugin.prod.js +7 -0
  25. package/LexicalAutoLinkPlugin.dev.js +12 -15
  26. package/LexicalAutoLinkPlugin.prod.js +6 -6
  27. package/LexicalAutoScrollPlugin.d.ts +13 -0
  28. package/LexicalAutoScrollPlugin.dev.js +82 -0
  29. package/LexicalAutoScrollPlugin.js +9 -0
  30. package/{withSubscriptions.d.ts → LexicalAutoScrollPlugin.js.flow} +5 -5
  31. package/LexicalAutoScrollPlugin.prod.js +8 -0
  32. package/LexicalCharacterLimitPlugin.dev.js +9 -10
  33. package/LexicalCharacterLimitPlugin.prod.js +7 -7
  34. package/LexicalClearEditorPlugin.dev.js +15 -19
  35. package/LexicalClearEditorPlugin.prod.js +1 -1
  36. package/LexicalCollaborationPlugin.d.ts +6 -3
  37. package/LexicalCollaborationPlugin.dev.js +30 -41
  38. package/LexicalCollaborationPlugin.js.flow +7 -4
  39. package/LexicalCollaborationPlugin.prod.js +10 -9
  40. package/LexicalComposer.d.ts +2 -2
  41. package/LexicalComposer.dev.js +3 -19
  42. package/LexicalComposer.js.flow +2 -2
  43. package/LexicalComposer.prod.js +2 -3
  44. package/LexicalContentEditable.dev.js +3 -1
  45. package/LexicalContentEditable.prod.js +2 -2
  46. package/LexicalHashtagPlugin.dev.js +20 -94
  47. package/LexicalHashtagPlugin.prod.js +4 -7
  48. package/LexicalHistoryPlugin.dev.js +5 -307
  49. package/LexicalHistoryPlugin.prod.js +1 -7
  50. package/LexicalHorizontalRuleNode.d.ts +3 -1
  51. package/LexicalHorizontalRuleNode.dev.js +2 -0
  52. package/LexicalHorizontalRuleNode.js.flow +6 -2
  53. package/LexicalHorizontalRuleNode.prod.js +2 -2
  54. package/LexicalLinkPlugin.dev.js +19 -20
  55. package/LexicalLinkPlugin.prod.js +4 -3
  56. package/LexicalListPlugin.dev.js +29 -25
  57. package/LexicalListPlugin.prod.js +3 -2
  58. package/{LexicalAutoFormatterPlugin.d.ts → LexicalMarkdownShortcutPlugin.d.ts} +1 -1
  59. package/LexicalMarkdownShortcutPlugin.dev.js +42 -0
  60. package/LexicalMarkdownShortcutPlugin.js +9 -0
  61. package/{withSubscriptions.js.flow → LexicalMarkdownShortcutPlugin.js.flow} +1 -4
  62. package/LexicalMarkdownShortcutPlugin.prod.js +7 -0
  63. package/LexicalNestedComposer.dev.js +20 -15
  64. package/LexicalNestedComposer.prod.js +3 -3
  65. package/LexicalOnChangePlugin.dev.js +1 -1
  66. package/LexicalOnChangePlugin.prod.js +1 -1
  67. package/LexicalPlainTextPlugin.dev.js +6 -359
  68. package/LexicalPlainTextPlugin.prod.js +4 -11
  69. package/LexicalRichTextPlugin.dev.js +6 -444
  70. package/LexicalRichTextPlugin.prod.js +4 -12
  71. package/LexicalTablePlugin.dev.js +27 -30
  72. package/LexicalTablePlugin.prod.js +3 -3
  73. package/LexicalTreeView.dev.js +1 -1
  74. package/LexicalTreeView.prod.js +1 -1
  75. package/package.json +17 -14
  76. package/useLexicalIsTextContentEmpty.dev.js +1 -1
  77. package/useLexicalIsTextContentEmpty.prod.js +1 -1
  78. package/useLexicalNodeSelection.dev.js +1 -1
  79. package/useLexicalNodeSelection.prod.js +1 -1
  80. package/useLexicalTextEntity.d.ts +19 -0
  81. package/useLexicalTextEntity.dev.js +29 -0
  82. package/{withSubscriptions.js → useLexicalTextEntity.js} +2 -2
  83. package/useLexicalTextEntity.js.flow +18 -0
  84. package/useLexicalTextEntity.prod.js +7 -0
  85. package/LexicalAutoFormatterPlugin.dev.js +0 -766
  86. package/LexicalAutoFormatterPlugin.js +0 -9
  87. package/LexicalAutoFormatterPlugin.prod.js +0 -25
@@ -10,9 +10,9 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
11
  var text = require('@lexical/text');
12
12
  var reactDom = require('react-dom');
13
- var clipboard = require('@lexical/clipboard');
14
- var selection = require('@lexical/selection');
15
- var lexical = require('lexical');
13
+ var dragon = require('@lexical/dragon');
14
+ var richText = require('@lexical/rich-text');
15
+ var utils = require('@lexical/utils');
16
16
 
17
17
  /**
18
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -46,7 +46,7 @@ var useLayoutEffect = useLayoutEffectImpl;
46
46
  function useLexicalCanShowPlaceholder(editor) {
47
47
  const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
48
48
  useLayoutEffect(() => {
49
- return editor.addListener('update', ({
49
+ return editor.registerUpdateListener(({
50
50
  editorState
51
51
  }) => {
52
52
  const isComposing = editor.isComposing();
@@ -69,7 +69,7 @@ function useDecorators(editor) {
69
69
  const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
70
70
 
71
71
  useLayoutEffect(() => {
72
- return editor.addListener('decorator', nextDecorators => {
72
+ return editor.registerDecoratorListener(nextDecorators => {
73
73
  reactDom.flushSync(() => {
74
74
  setDecorators(nextDecorators);
75
75
  });
@@ -94,204 +94,6 @@ function useDecorators(editor) {
94
94
  }, [decorators, editor]);
95
95
  }
96
96
 
97
- /**
98
- * Copyright (c) Meta Platforms, Inc. and affiliates.
99
- *
100
- * This source code is licensed under the MIT license found in the
101
- * LICENSE file in the root directory of this source tree.
102
- *
103
- *
104
- */
105
- function onCutForRichText(event, editor) {
106
- onCopyForRichText(event, editor);
107
- editor.update(() => {
108
- const selection = lexical.$getSelection();
109
-
110
- if (lexical.$isRangeSelection(selection)) {
111
- selection.removeText();
112
- }
113
- });
114
- }
115
- function onCopyForRichText(event, editor) {
116
- event.preventDefault();
117
- editor.update(() => {
118
- const clipboardData = event.clipboardData;
119
- const selection = lexical.$getSelection();
120
-
121
- if (selection !== null) {
122
- if (clipboardData != null) {
123
- const htmlString = clipboard.getHtmlContent(editor);
124
- const lexicalString = clipboard.$getLexicalContent(editor);
125
-
126
- if (htmlString !== null) {
127
- clipboardData.setData('text/html', htmlString);
128
- }
129
-
130
- if (lexicalString !== null) {
131
- clipboardData.setData('application/x-lexical-editor', lexicalString);
132
- }
133
-
134
- clipboardData.setData('text/plain', selection.getTextContent());
135
- }
136
- }
137
- });
138
- }
139
- function onPasteForRichText(event, editor) {
140
- event.preventDefault();
141
- editor.update(() => {
142
- const selection = lexical.$getSelection();
143
- const clipboardData = event.clipboardData;
144
-
145
- if (clipboardData != null && lexical.$isRangeSelection(selection)) {
146
- clipboard.$insertDataTransferForRichText(clipboardData, selection, editor);
147
- }
148
- });
149
- }
150
-
151
- /**
152
- * Copyright (c) Meta Platforms, Inc. and affiliates.
153
- *
154
- * This source code is licensed under the MIT license found in the
155
- * LICENSE file in the root directory of this source tree.
156
- *
157
- *
158
- */
159
- // Convoluted logic to make this work with Flow. Order matters.
160
- const options = {
161
- tag: 'history-merge'
162
- };
163
- const setEditorOptions = options;
164
- const updateOptions = options;
165
- function initializeEditor(editor, initialEditorState) {
166
- if (initialEditorState === null) {
167
- return;
168
- } else if (initialEditorState === undefined) {
169
- editor.update(() => {
170
- const root = lexical.$getRoot();
171
- const firstChild = root.getFirstChild();
172
-
173
- if (firstChild === null) {
174
- const paragraph = lexical.$createParagraphNode();
175
- root.append(paragraph);
176
- const activeElement = document.activeElement;
177
-
178
- if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
179
- paragraph.select();
180
- }
181
- }
182
- }, updateOptions);
183
- } else if (initialEditorState !== null) {
184
- switch (typeof initialEditorState) {
185
- case 'string':
186
- {
187
- const parsedEditorState = editor.parseEditorState(initialEditorState);
188
- editor.setEditorState(parsedEditorState, setEditorOptions);
189
- break;
190
- }
191
-
192
- case 'object':
193
- {
194
- editor.setEditorState(initialEditorState, setEditorOptions);
195
- break;
196
- }
197
-
198
- case 'function':
199
- {
200
- editor.update(initialEditorState, updateOptions);
201
- break;
202
- }
203
- }
204
- }
205
- }
206
-
207
- /**
208
- * Copyright (c) Meta Platforms, Inc. and affiliates.
209
- *
210
- * This source code is licensed under the MIT license found in the
211
- * LICENSE file in the root directory of this source tree.
212
- *
213
- *
214
- */
215
- function useLexicalDragonSupport(editor) {
216
- React.useEffect(() => {
217
- const handler = event => {
218
- const rootElement = editor.getRootElement();
219
-
220
- if (document.activeElement !== rootElement) {
221
- return;
222
- }
223
-
224
- const data = event.data;
225
-
226
- if (typeof data === 'string') {
227
- let parsedData;
228
-
229
- try {
230
- parsedData = JSON.parse(data);
231
- } catch (e) {
232
- return;
233
- }
234
-
235
- if (parsedData && parsedData.protocol === 'nuanria_messaging' && parsedData.type === 'request') {
236
- const payload = parsedData.payload;
237
-
238
- if (payload && payload.functionId === 'makeChanges') {
239
- const args = payload.args;
240
-
241
- if (args) {
242
- const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
243
- editor.update(() => {
244
- const selection = lexical.$getSelection();
245
-
246
- if (lexical.$isRangeSelection(selection)) {
247
- const anchor = selection.anchor;
248
- let anchorNode = anchor.getNode();
249
- let setSelStart = 0;
250
- let setSelEnd = 0;
251
-
252
- if (lexical.$isTextNode(anchorNode)) {
253
- // set initial selection
254
- if (elementStart >= 0 && elementLength >= 0) {
255
- setSelStart = elementStart;
256
- setSelEnd = elementStart + elementLength; // If the offset is more than the end, make it the end
257
-
258
- selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
259
- }
260
- }
261
-
262
- if (setSelStart !== setSelEnd || text !== '') {
263
- selection.insertRawText(text);
264
- anchorNode = anchor.getNode();
265
- }
266
-
267
- if (lexical.$isTextNode(anchorNode)) {
268
- // set final selection
269
- setSelStart = selStart;
270
- setSelEnd = selStart + selLength;
271
- const anchorNodeTextLength = anchorNode.getTextContentSize(); // If the offset is more than the end, make it the end
272
-
273
- setSelStart = setSelStart > anchorNodeTextLength ? anchorNodeTextLength : setSelStart;
274
- setSelEnd = setSelEnd > anchorNodeTextLength ? anchorNodeTextLength : setSelEnd;
275
- selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
276
- } // block the chrome extension from handling this event
277
-
278
-
279
- event.stopImmediatePropagation();
280
- }
281
- });
282
- }
283
- }
284
- }
285
- }
286
- };
287
-
288
- window.addEventListener('message', handler, true);
289
- return () => {
290
- window.removeEventListener('message', handler, true);
291
- };
292
- }, [editor]);
293
- }
294
-
295
97
  /**
296
98
  * Copyright (c) Meta Platforms, Inc. and affiliates.
297
99
  *
@@ -302,249 +104,9 @@ function useLexicalDragonSupport(editor) {
302
104
  */
303
105
  function useRichTextSetup(editor, initialEditorState) {
304
106
  useLayoutEffect(() => {
305
- const removeListener = editor.addListener('command', (type, payload) => {
306
- const selection$1 = lexical.$getSelection();
307
-
308
- if (type === 'click' && lexical.$isNodeSelection(selection$1)) {
309
- selection$1.clear();
310
- return true;
311
- }
312
-
313
- if (!lexical.$isRangeSelection(selection$1)) {
314
- return false;
315
- }
316
-
317
- switch (type) {
318
- case 'deleteCharacter':
319
- {
320
- const isBackward = payload;
321
- selection$1.deleteCharacter(isBackward);
322
- return true;
323
- }
324
-
325
- case 'deleteWord':
326
- {
327
- const isBackward = payload;
328
- selection$1.deleteWord(isBackward);
329
- return true;
330
- }
331
-
332
- case 'deleteLine':
333
- {
334
- const isBackward = payload;
335
- selection$1.deleteLine(isBackward);
336
- return true;
337
- }
338
-
339
- case 'insertText':
340
- {
341
- const eventOrText = payload;
342
-
343
- if (typeof eventOrText === 'string') {
344
- selection$1.insertText(eventOrText);
345
- } else {
346
- const dataTransfer = eventOrText.dataTransfer;
347
-
348
- if (dataTransfer != null) {
349
- clipboard.$insertDataTransferForRichText(dataTransfer, selection$1, editor);
350
- } else {
351
- const data = eventOrText.data;
352
-
353
- if (data) {
354
- selection$1.insertText(data);
355
- }
356
- }
357
- }
358
-
359
- return true;
360
- }
361
-
362
- case 'removeText':
363
- selection$1.removeText();
364
- return true;
365
-
366
- case 'formatText':
367
- {
368
- const format = payload;
369
- selection$1.formatText(format);
370
- return true;
371
- }
372
-
373
- case 'formatElement':
374
- {
375
- const format = payload;
376
- const node = selection$1.anchor.getNode();
377
- const element = lexical.$isElementNode(node) ? node : node.getParentOrThrow();
378
- element.setFormat(format);
379
- return true;
380
- }
381
-
382
- case 'insertLineBreak':
383
- const selectStart = payload;
384
- selection$1.insertLineBreak(selectStart);
385
- return true;
386
-
387
- case 'insertParagraph':
388
- selection$1.insertParagraph();
389
- return true;
390
-
391
- case 'indentContent':
392
- {
393
- // Handle code blocks
394
- const anchor = selection$1.anchor;
395
- const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
396
-
397
- if (parentBlock.canInsertTab()) {
398
- editor.execCommand('insertText', '\t');
399
- } else {
400
- if (parentBlock.getIndent() !== 10) {
401
- parentBlock.setIndent(parentBlock.getIndent() + 1);
402
- }
403
- }
404
-
405
- return true;
406
- }
407
-
408
- case 'outdentContent':
409
- {
410
- // Handle code blocks
411
- const anchor = selection$1.anchor;
412
- const anchorNode = anchor.getNode();
413
- const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
414
-
415
- if (parentBlock.canInsertTab()) {
416
- const textContent = anchorNode.getTextContent();
417
- const character = textContent[anchor.offset - 1];
418
-
419
- if (character === '\t') {
420
- editor.execCommand('deleteCharacter', true);
421
- }
422
- } else {
423
- if (parentBlock.getIndent() !== 0) {
424
- parentBlock.setIndent(parentBlock.getIndent() - 1);
425
- }
426
- }
427
-
428
- return true;
429
- }
430
-
431
- case 'keyArrowLeft':
432
- {
433
- const event = payload;
434
- const isHoldingShift = event.shiftKey;
435
-
436
- if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
437
- event.preventDefault();
438
- selection.$moveCharacter(selection$1, isHoldingShift, true);
439
- return true;
440
- }
441
-
442
- return false;
443
- }
444
-
445
- case 'keyArrowRight':
446
- {
447
- const event = payload;
448
- const isHoldingShift = event.shiftKey;
449
-
450
- if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
451
- event.preventDefault();
452
- selection.$moveCharacter(selection$1, isHoldingShift, false);
453
- return true;
454
- }
455
-
456
- return false;
457
- }
458
-
459
- case 'keyBackspace':
460
- {
461
- const event = payload;
462
- event.preventDefault();
463
- const {
464
- anchor
465
- } = selection$1;
466
-
467
- if (selection$1.isCollapsed() && anchor.offset === 0) {
468
- const element = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
469
-
470
- if (element.getIndent() > 0) {
471
- return editor.execCommand('outdentContent');
472
- }
473
- }
474
-
475
- return editor.execCommand('deleteCharacter', true);
476
- }
477
-
478
- case 'keyDelete':
479
- {
480
- const event = payload;
481
- event.preventDefault();
482
- return editor.execCommand('deleteCharacter', false);
483
- }
484
-
485
- case 'keyEnter':
486
- {
487
- const event = payload;
488
- event.preventDefault();
489
-
490
- if (event.shiftKey) {
491
- return editor.execCommand('insertLineBreak');
492
- }
493
-
494
- return editor.execCommand('insertParagraph');
495
- }
496
-
497
- case 'keyTab':
498
- {
499
- const event = payload;
500
- event.preventDefault();
501
- return editor.execCommand(event.shiftKey ? 'outdentContent' : 'indentContent');
502
- }
503
-
504
- case 'keyEscape':
505
- {
506
- editor.blur();
507
- return true;
508
- }
509
-
510
- case 'copy':
511
- {
512
- const event = payload;
513
- onCopyForRichText(event, editor);
514
- return true;
515
- }
516
-
517
- case 'cut':
518
- {
519
- const event = payload;
520
- onCutForRichText(event, editor);
521
- return true;
522
- }
523
-
524
- case 'paste':
525
- {
526
- const event = payload;
527
- onPasteForRichText(event, editor);
528
- return true;
529
- }
530
-
531
- case 'drop':
532
- case 'dragstart':
533
- {
534
- // TODO: Make drag and drop work at some point.
535
- const event = payload;
536
- event.preventDefault();
537
- return true;
538
- }
539
- }
540
-
541
- return false;
542
- }, 0);
543
- initializeEditor(editor, initialEditorState);
544
- return removeListener; // We only do this for init
107
+ return utils.mergeRegister(richText.registerRichText(editor, initialEditorState), dragon.registerDragonSupport(editor)); // We only do this for init
545
108
  // eslint-disable-next-line react-hooks/exhaustive-deps
546
109
  }, [editor]);
547
- useLexicalDragonSupport(editor);
548
110
  }
549
111
 
550
112
  /**
@@ -4,15 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),r=require("@lexical/text"),t=require("react-dom"),v=require("@lexical/clipboard"),w=require("@lexical/selection"),x=require("lexical"),y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
- function z(c){const [e,f]=h.useState(c.getEditorState().read(r.$canShowPlaceholderCurry(c.isComposing())));y(()=>c.addListener("update",({editorState:d})=>{const b=c.isComposing();d=d.read(r.$canShowPlaceholderCurry(b));f(d)}),[c]);return e}
9
- function B(c){const [e,f]=h.useState(()=>c.getDecorators());y(()=>c.addListener("decorator",d=>{t.flushSync(()=>{f(d)})}),[c]);return h.useMemo(()=>{const d=[],b=Object.keys(e);for(let p=0;p<b.length;p++){var a=b[p];const u=e[a];a=c.getElementByKey(a);null!==a&&d.push(t.createPortal(u,a))}return d},[e,c])}function C(c,e){D(c,e);e.update(()=>{const f=x.$getSelection();x.$isRangeSelection(f)&&f.removeText()})}
10
- function D(c,e){c.preventDefault();e.update(()=>{const f=c.clipboardData,d=x.$getSelection();if(null!==d&&null!=f){const b=v.getHtmlContent(e),a=v.$getLexicalContent(e);null!==b&&f.setData("text/html",b);null!==a&&f.setData("application/x-lexical-editor",a);f.setData("text/plain",d.getTextContent())}})}function E(c,e){c.preventDefault();e.update(()=>{const f=x.$getSelection(),d=c.clipboardData;null!=d&&x.$isRangeSelection(f)&&v.$insertDataTransferForRichText(d,f,e)})}const F={tag:"history-merge"};
11
- function G(c,e){if(null!==e)if(void 0===e)c.update(()=>{var f=x.$getRoot();if(null===f.getFirstChild()){const d=x.$createParagraphNode();f.append(d);f=document.activeElement;(null!==x.$getSelection()||null!==f&&f===c.getRootElement())&&d.select()}},F);else if(null!==e)switch(typeof e){case "string":e=c.parseEditorState(e);c.setEditorState(e,F);break;case "object":c.setEditorState(e,F);break;case "function":c.update(e,F)}}
12
- function H(c){h.useEffect(()=>{const e=f=>{var d=c.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var b=JSON.parse(d)}catch(a){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [a,p,u,A,I]=b;c.update(()=>{const q=x.$getSelection();if(x.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;x.$isTextNode(k)&&0<=a&&0<=p&&(l=a,m=a+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
13
- u)q.insertRawText(u),k=n.getNode();x.$isTextNode(k)&&(l=A,m=A+I,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[c])}
14
- function J(c,e){y(()=>{const f=c.addListener("command",(d,b)=>{var a=x.$getSelection();if("click"===d&&x.$isNodeSelection(a))return a.clear(),!0;if(!x.$isRangeSelection(a))return!1;switch(d){case "deleteCharacter":return a.deleteCharacter(b),!0;case "deleteWord":return a.deleteWord(b),!0;case "deleteLine":return a.deleteLine(b),!0;case "insertText":return"string"===typeof b?a.insertText(b):(d=b.dataTransfer,null!=d?v.$insertDataTransferForRichText(d,a,c):(b=b.data)&&a.insertText(b)),!0;case "removeText":return a.removeText(),
15
- !0;case "formatText":return a.formatText(b),!0;case "formatElement":return a=a.anchor.getNode(),(x.$isElementNode(a)?a:a.getParentOrThrow()).setFormat(b),!0;case "insertLineBreak":return a.insertLineBreak(b),!0;case "insertParagraph":return a.insertParagraph(),!0;case "indentContent":return a=a.anchor,a="element"===a.type?a.getNode():a.getNode().getParentOrThrow(),a.canInsertTab()?c.execCommand("insertText","\t"):10!==a.getIndent()&&a.setIndent(a.getIndent()+1),!0;case "outdentContent":return a=a.anchor,
16
- b=a.getNode(),d="element"===a.type?a.getNode():a.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===b.getTextContent()[a.offset-1]&&c.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(a,!0))return b.preventDefault(),w.$moveCharacter(a,d,!0),!0;break;case "keyArrowRight":d=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(a,!1))return b.preventDefault(),w.$moveCharacter(a,d,!1),
17
- !0;break;case "keyBackspace":return b.preventDefault(),{anchor:b}=a,a.isCollapsed()&&0===b.offset&&0<("element"===b.type?b.getNode():b.getNode().getParentOrThrow()).getIndent()?c.execCommand("outdentContent"):c.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),c.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),b.shiftKey?c.execCommand("insertLineBreak"):c.execCommand("insertParagraph");case "keyTab":return b.preventDefault(),c.execCommand(b.shiftKey?
18
- "outdentContent":"indentContent");case "keyEscape":return c.blur(),!0;case "copy":return D(b,c),!0;case "cut":return C(b,c),!0;case "paste":return E(b,c),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);G(c,e);return f},[c]);H(c)}module.exports=function({contentEditable:c,placeholder:e,initialEditorState:f}){const [d]=g.useLexicalComposerContext(),b=z(d);J(d,f);f=B(d);return h.createElement(h.Fragment,null,c,b&&e,f)};
7
+ var d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("react-dom"),n=require("@lexical/dragon"),p=require("@lexical/rich-text"),q=require("@lexical/utils"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
+ function t(a){const [c,e]=h.useState(a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing())));r(()=>a.registerUpdateListener(({editorState:b})=>{const f=a.isComposing();b=b.read(l.$canShowPlaceholderCurry(f));e(b)}),[a]);return c}
9
+ function u(a){const [c,e]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{m.flushSync(()=>{e(b)})}),[a]);return h.useMemo(()=>{const b=[],f=Object.keys(c);for(let k=0;k<f.length;k++){var g=f[k];const v=c[g];g=a.getElementByKey(g);null!==g&&b.push(m.createPortal(v,g))}return b},[c,a])}function w(a,c){r(()=>q.mergeRegister(p.registerRichText(a,c),n.registerDragonSupport(a)),[a])}
10
+ module.exports=function({contentEditable:a,placeholder:c,initialEditorState:e}){const [b]=d.useLexicalComposerContext(),f=t(b);w(b,e);e=u(b);return h.createElement(h.Fragment,null,a,f&&c,e)};
@@ -29,52 +29,49 @@ function TablePlugin() {
29
29
  }
30
30
  }
31
31
 
32
- return editor.addListener('command', (type, payload) => {
33
- if (type === 'insertTable') {
34
- const {
35
- columns,
36
- rows
37
- } = payload;
38
- const selection = lexical.$getSelection();
32
+ return editor.registerCommand(table.INSERT_TABLE_COMMAND, payload => {
33
+ const {
34
+ columns,
35
+ rows
36
+ } = payload;
37
+ const selection = lexical.$getSelection();
39
38
 
40
- if (!lexical.$isRangeSelection(selection)) {
41
- return true;
42
- }
39
+ if (!lexical.$isRangeSelection(selection)) {
40
+ return true;
41
+ }
43
42
 
44
- const focus = selection.focus;
45
- const focusNode = focus.getNode();
43
+ const focus = selection.focus;
44
+ const focusNode = focus.getNode();
46
45
 
47
- if (focusNode !== null) {
48
- const tableNode = table.$createTableNodeWithDimensions(rows, columns);
46
+ if (focusNode !== null) {
47
+ const tableNode = table.$createTableNodeWithDimensions(Number(rows), Number(columns));
49
48
 
50
- if (lexical.$isRootNode(focusNode)) {
51
- const target = focusNode.getChildAtIndex(focus.offset);
49
+ if (lexical.$isRootNode(focusNode)) {
50
+ const target = focusNode.getChildAtIndex(focus.offset);
52
51
 
53
- if (target !== null) {
54
- target.insertBefore(tableNode);
55
- } else {
56
- focusNode.append(tableNode);
57
- }
52
+ if (target !== null) {
53
+ target.insertBefore(tableNode);
58
54
  } else {
59
- const topLevelNode = focusNode.getTopLevelElementOrThrow();
60
- topLevelNode.insertAfter(tableNode);
55
+ focusNode.append(tableNode);
61
56
  }
62
57
 
63
- tableNode.insertAfter(lexical.$createParagraphNode());
64
- const firstCell = tableNode.getFirstChildOrThrow().getFirstChildOrThrow();
65
- firstCell.select();
58
+ tableNode.insertBefore(lexical.$createParagraphNode());
59
+ } else {
60
+ const topLevelNode = focusNode.getTopLevelElementOrThrow();
61
+ topLevelNode.insertAfter(tableNode);
66
62
  }
67
63
 
68
- return true;
64
+ tableNode.insertAfter(lexical.$createParagraphNode());
65
+ const firstCell = tableNode.getFirstChildOrThrow().getFirstChildOrThrow();
66
+ firstCell.select();
69
67
  }
70
68
 
71
- return false;
69
+ return true;
72
70
  }, EditorPriority);
73
71
  }, [editor]);
74
72
  react.useEffect(() => {
75
73
  const tableSelections = new Map();
76
- return editor.addListener('mutation', table.TableNode, nodeMutations => {
77
- // eslint-disable-next-line no-for-of-loops/no-for-of-loops
74
+ return editor.registerMutationListener(table.TableNode, nodeMutations => {
78
75
  for (const [nodeKey, mutation] of nodeMutations) {
79
76
  if (mutation === 'created') {
80
77
  editor.update(() => {
@@ -5,6 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/table"),k=require("lexical"),m=require("react");
8
- module.exports=function(){const [d]=e.useLexicalComposerContext();m.useEffect(()=>{if(!d.hasNodes([g.TableNode,g.TableCellNode,g.TableRowNode]))throw Error("Minified Lexical error #54; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return d.addListener("command",(a,b)=>{if("insertTable"===a){const {columns:h,rows:f}=b;a=k.$getSelection();if(!k.$isRangeSelection(a))return!0;var c=a.focus;a=c.getNode();null!==a&&(b=g.$createTableNodeWithDimensions(f,
9
- h),k.$isRootNode(a)?(c=a.getChildAtIndex(c.offset),null!==c?c.insertBefore(b):a.append(b)):a.getTopLevelElementOrThrow().insertAfter(b),b.insertAfter(k.$createParagraphNode()),b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0}return!1},0)},[d]);m.useEffect(()=>{const a=new Map;return d.addListener("mutation",g.TableNode,b=>{for(const [c,h]of b)"created"===h?d.update(()=>{var f=d.getElementByKey(c);const l=k.$getNodeByKey(c);f&&l&&(f=g.applyTableHandlers(l,f,d),a.set(c,f))}):"destroyed"===
10
- h&&(b=a.get(c))&&(b.removeListeners(),a.delete(c))})},[d]);return null};
8
+ module.exports=function(){const [c]=e.useLexicalComposerContext();m.useEffect(()=>{if(!c.hasNodes([g.TableNode,g.TableCellNode,g.TableRowNode]))throw Error("Minified Lexical error #54; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return c.registerCommand(g.INSERT_TABLE_COMMAND,a=>{const {columns:h,rows:f}=a;a=k.$getSelection();if(!k.$isRangeSelection(a))return!0;var d=a.focus;a=d.getNode();if(null!==a){const b=g.$createTableNodeWithDimensions(Number(f),
9
+ Number(h));k.$isRootNode(a)?(d=a.getChildAtIndex(d.offset),null!==d?d.insertBefore(b):a.append(b),b.insertBefore(k.$createParagraphNode())):a.getTopLevelElementOrThrow().insertAfter(b);b.insertAfter(k.$createParagraphNode());b.getFirstChildOrThrow().getFirstChildOrThrow().select()}return!0},0)},[c]);m.useEffect(()=>{const a=new Map;return c.registerMutationListener(g.TableNode,h=>{for(const [f,d]of h)"created"===d?c.update(()=>{var b=c.getElementByKey(f);const l=k.$getNodeByKey(f);b&&l&&(b=g.applyTableHandlers(l,
10
+ b,c),a.set(f,b))}):"destroyed"===d&&(h=a.get(f))&&(h.removeListeners(),a.delete(f))})},[c]);return null};
@@ -47,7 +47,7 @@ function TreeView({
47
47
  const [isPlaying, setIsPlaying] = React.useState(false);
48
48
  React.useEffect(() => {
49
49
  setContent(generateContent(editor.getEditorState()));
50
- return editor.addListener('update', ({
50
+ return editor.registerUpdateListener(({
51
51
  editorState
52
52
  }) => {
53
53
  const compositionKey = editor._compositionKey;
@@ -14,7 +14,7 @@ function M(a){let b=Q.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase(
14
14
  function N({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!k.$isTextNode(c)||!k.$isRangeSelection(d)||!b||k.$isElementNode(c))return"";b=d.anchor;var g=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===g.offset)return"";g=d.anchor;const m=d.focus,v=c.getTextContent(!0),u=v.length;b=d=-1;if("text"===g.type&&"text"===m.type){const n=g.getNode(),w=m.getNode();n===w&&c===n&&g.offset!==m.offset?[d,b]=g.offset<m.offset?[g.offset,m.offset]:[m.offset,
15
15
  g.offset]:c===n?[d,b]=n.isBefore(w)?[g.offset,u]:[0,g.offset]:c===w?[d,b]=w.isBefore(n)?[m.offset,u]:[0,m.offset]:[d,b]=[0,u]}c=(v.slice(0,d).match(D)||[]).length;g=(v.slice(d,b).match(D)||[]).length;const [r,l]=[d+c,b+c+g];if(r===l)return"";c=a[a.length-1]===E.hasNextSibling?E.ancestorHasNextSibling:E.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(r).fill(" ");d=Array(l-r).fill(E.selectedChar);e=Array(e.length+(f.length+3)).fill(" ");return[E.selectedLine,a.join(" "),[...e,...c,...d].join("")].join(" ")+
16
16
  "\n"}
17
- module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=q.useState([]),[v,u]=q.useState(""),[r,l]=q.useState(!1),n=q.useRef(0),w=q.useRef(null),B=q.useRef(null),[z,C]=q.useState(!1);q.useEffect(()=>{u(H(f.getEditorState()));return f.addListener("update",({editorState:h})=>{const p=f._compositionKey,x=H(f.getEditorState());u([x,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
17
+ module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=q.useState([]),[v,u]=q.useState(""),[r,l]=q.useState(!1),n=q.useRef(0),w=q.useRef(null),B=q.useRef(null),[z,C]=q.useState(!1);q.useEffect(()=>{u(H(f.getEditorState()));return f.registerUpdateListener(({editorState:h})=>{const p=f._compositionKey,x=H(f.getEditorState());u([x,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
18
18
  m(A=>[...A,[Date.now(),h]])})},[r,f]);const y=g.length;q.useEffect(()=>{if(z){let h;const p=()=>{const x=n.current;x===y-1?C(!1):h=setTimeout(()=>{n.current++;const A=n.current,I=B.current;null!==I&&(I.value=String(A));f.setEditorState(g[A][1]);p()},g[x+1][0]-g[x][0])};p();return()=>{window.clearTimeout(h)}}},[g,z,f,y]);q.useEffect(()=>{const h=w.current;if(null!==h)return h.__lexicalEditor=f,()=>{h.__lexicalEditor=null}},[f]);return q.createElement("div",{className:e},!r&&2<y&&q.createElement("button",
19
19
  {onClick:()=>{const h=f.getRootElement();null!==h&&(h.contentEditable="false",n.current=y-1,l(!0))},className:a},"Time Travel"),q.createElement("pre",{ref:w},v),r&&q.createElement("div",{className:d},q.createElement("button",{className:c,onClick:()=>{C(!z)}},z?"Pause":"Play"),q.createElement("input",{className:b,ref:B,onChange:h=>{h=Number(h.target.value);const p=g[h];p&&(n.current=h,f.setEditorState(p[1]))},type:"range",min:"1",max:y-1}),q.createElement("button",{className:c,onClick:()=>{var h=f.getRootElement();
20
20
  if(null!==h){h.contentEditable="true";h=g.length-1;f.setEditorState(g[h][1]);const p=B.current;null!==p&&(p.value=String(h));l(!1);C(!1)}}},"Exit")))};