@lexical/react 0.1.12 → 0.1.15

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 (41) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +283 -295
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -21
  3. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +3 -72
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +11 -63
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +6 -7
  7. package/DEPRECATED_useLexicalPlainText.dev.js +16 -41
  8. package/DEPRECATED_useLexicalPlainText.prod.js +13 -14
  9. package/DEPRECATED_useLexicalRichText.dev.js +24 -49
  10. package/DEPRECATED_useLexicalRichText.prod.js +15 -15
  11. package/LexicalAutoFormatterPlugin.dev.js +283 -295
  12. package/LexicalAutoFormatterPlugin.prod.js +19 -21
  13. package/LexicalAutoLinkPlugin.dev.js +2 -2
  14. package/LexicalAutoLinkPlugin.prod.js +2 -2
  15. package/LexicalCharacterLimitPlugin.dev.js +11 -63
  16. package/LexicalCharacterLimitPlugin.prod.js +8 -9
  17. package/LexicalCollaborationPlugin.d.ts +5 -1
  18. package/LexicalCollaborationPlugin.dev.js +77 -16
  19. package/LexicalCollaborationPlugin.js.flow +7 -2
  20. package/LexicalCollaborationPlugin.prod.js +9 -7
  21. package/LexicalComposer.d.ts +1 -1
  22. package/LexicalComposer.dev.js +1 -1
  23. package/LexicalComposer.js.flow +3 -3
  24. package/LexicalComposer.prod.js +1 -1
  25. package/LexicalHashtagPlugin.dev.js +61 -3
  26. package/LexicalHashtagPlugin.prod.js +7 -4
  27. package/LexicalNestedComposer.d.ts +4 -7
  28. package/LexicalNestedComposer.dev.js +21 -11
  29. package/LexicalNestedComposer.js.flow +3 -6
  30. package/LexicalNestedComposer.prod.js +3 -2
  31. package/LexicalOnChangePlugin.dev.js +15 -2
  32. package/LexicalOnChangePlugin.prod.js +2 -1
  33. package/LexicalPlainTextPlugin.dev.js +20 -113
  34. package/LexicalPlainTextPlugin.prod.js +11 -12
  35. package/LexicalRichTextPlugin.dev.js +28 -121
  36. package/LexicalRichTextPlugin.prod.js +12 -13
  37. package/LexicalTablePlugin.dev.js +9 -5
  38. package/LexicalTablePlugin.prod.js +2 -2
  39. package/package.json +11 -6
  40. package/useLexicalIsTextContentEmpty.dev.js +3 -32
  41. package/useLexicalIsTextContentEmpty.prod.js +1 -2
@@ -8,78 +8,11 @@
8
8
 
9
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
- var lexical = require('lexical');
11
+ var text = require('@lexical/text');
12
12
  var reactDom = require('react-dom');
13
13
  var clipboard = require('@lexical/clipboard');
14
-
15
- /**
16
- * Copyright (c) Meta Platforms, Inc. and affiliates.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- *
21
- *
22
- */
23
- function $textContent() {
24
- const root = lexical.$getRoot();
25
- return root.getTextContent();
26
- }
27
- function $isTextContentEmpty(isEditorComposing, trim = true) {
28
- if (isEditorComposing) {
29
- return false;
30
- }
31
-
32
- let text = $textContent();
33
-
34
- if (trim) {
35
- text = text.trim();
36
- }
37
-
38
- return text === '';
39
- }
40
- function $canShowPlaceholder(isComposing) {
41
- if (!$isTextContentEmpty(isComposing, false)) {
42
- return false;
43
- }
44
-
45
- const root = lexical.$getRoot();
46
- const children = root.getChildren();
47
- const childrenLength = children.length;
48
-
49
- if (childrenLength > 1) {
50
- return false;
51
- }
52
-
53
- for (let i = 0; i < childrenLength; i++) {
54
- const topBlock = children[i];
55
-
56
- if (lexical.$isElementNode(topBlock)) {
57
- if (topBlock.__type !== 'paragraph') {
58
- return false;
59
- }
60
-
61
- if (topBlock.__indent !== 0) {
62
- return false;
63
- }
64
-
65
- const topBlockChildren = topBlock.getChildren();
66
- const topBlockChildrenLength = topBlockChildren.length;
67
-
68
- for (let s = 0; s < topBlockChildrenLength; s++) {
69
- const child = topBlockChildren[i];
70
-
71
- if (!lexical.$isTextNode(child)) {
72
- return false;
73
- }
74
- }
75
- }
76
- }
77
-
78
- return true;
79
- }
80
- function $canShowPlaceholderCurry(isEditorComposing) {
81
- return () => $canShowPlaceholder(isEditorComposing);
82
- }
14
+ var selection = require('@lexical/selection');
15
+ var lexical = require('lexical');
83
16
 
84
17
  /**
85
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -111,13 +44,13 @@ var useLayoutEffect = useLayoutEffectImpl;
111
44
  *
112
45
  */
113
46
  function useLexicalCanShowPlaceholder(editor) {
114
- const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing())));
47
+ const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
115
48
  useLayoutEffect(() => {
116
49
  return editor.addListener('update', ({
117
50
  editorState
118
51
  }) => {
119
52
  const isComposing = editor.isComposing();
120
- const currentCanShowPlaceholder = editorState.read($canShowPlaceholderCurry(isComposing));
53
+ const currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
121
54
  setCanShowPlaceholder(currentCanShowPlaceholder);
122
55
  });
123
56
  }, [editor]);
@@ -161,32 +94,6 @@ function useDecorators(editor) {
161
94
  }, [decorators, editor]);
162
95
  }
163
96
 
164
- /**
165
- * Copyright (c) Meta Platforms, Inc. and affiliates.
166
- *
167
- * This source code is licensed under the MIT license found in the
168
- * LICENSE file in the root directory of this source tree.
169
- *
170
- *
171
- */
172
-
173
- function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
174
- selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
175
- }
176
- function $isParentElementRTL(selection) {
177
- const anchorNode = selection.anchor.getNode();
178
- const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
179
- return parent.getDirection() === 'rtl';
180
- }
181
- function $moveCharacter(selection, isHoldingShift, isBackward) {
182
- const isRTL = $isParentElementRTL(selection);
183
- $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
184
- }
185
- function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
186
- const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
187
- return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
188
- }
189
-
190
97
  /**
191
98
  * Copyright (c) Meta Platforms, Inc. and affiliates.
192
99
  *
@@ -396,14 +303,14 @@ function useLexicalDragonSupport(editor) {
396
303
  function useRichTextSetup(editor, initialEditorState) {
397
304
  useLayoutEffect(() => {
398
305
  const removeListener = editor.addListener('command', (type, payload) => {
399
- const selection = lexical.$getSelection();
306
+ const selection$1 = lexical.$getSelection();
400
307
 
401
- if (type === 'click' && lexical.$isNodeSelection(selection)) {
402
- selection.clear();
308
+ if (type === 'click' && lexical.$isNodeSelection(selection$1)) {
309
+ selection$1.clear();
403
310
  return true;
404
311
  }
405
312
 
406
- if (!lexical.$isRangeSelection(selection)) {
313
+ if (!lexical.$isRangeSelection(selection$1)) {
407
314
  return false;
408
315
  }
409
316
 
@@ -411,21 +318,21 @@ function useRichTextSetup(editor, initialEditorState) {
411
318
  case 'deleteCharacter':
412
319
  {
413
320
  const isBackward = payload;
414
- selection.deleteCharacter(isBackward);
321
+ selection$1.deleteCharacter(isBackward);
415
322
  return true;
416
323
  }
417
324
 
418
325
  case 'deleteWord':
419
326
  {
420
327
  const isBackward = payload;
421
- selection.deleteWord(isBackward);
328
+ selection$1.deleteWord(isBackward);
422
329
  return true;
423
330
  }
424
331
 
425
332
  case 'deleteLine':
426
333
  {
427
334
  const isBackward = payload;
428
- selection.deleteLine(isBackward);
335
+ selection$1.deleteLine(isBackward);
429
336
  return true;
430
337
  }
431
338
 
@@ -434,17 +341,17 @@ function useRichTextSetup(editor, initialEditorState) {
434
341
  const eventOrText = payload;
435
342
 
436
343
  if (typeof eventOrText === 'string') {
437
- selection.insertText(eventOrText);
344
+ selection$1.insertText(eventOrText);
438
345
  } else {
439
346
  const dataTransfer = eventOrText.dataTransfer;
440
347
 
441
348
  if (dataTransfer != null) {
442
- clipboard.$insertDataTransferForRichText(dataTransfer, selection, editor);
349
+ clipboard.$insertDataTransferForRichText(dataTransfer, selection$1, editor);
443
350
  } else {
444
351
  const data = eventOrText.data;
445
352
 
446
353
  if (data) {
447
- selection.insertText(data);
354
+ selection$1.insertText(data);
448
355
  }
449
356
  }
450
357
  }
@@ -453,20 +360,20 @@ function useRichTextSetup(editor, initialEditorState) {
453
360
  }
454
361
 
455
362
  case 'removeText':
456
- selection.removeText();
363
+ selection$1.removeText();
457
364
  return true;
458
365
 
459
366
  case 'formatText':
460
367
  {
461
368
  const format = payload;
462
- selection.formatText(format);
369
+ selection$1.formatText(format);
463
370
  return true;
464
371
  }
465
372
 
466
373
  case 'formatElement':
467
374
  {
468
375
  const format = payload;
469
- const node = selection.anchor.getNode();
376
+ const node = selection$1.anchor.getNode();
470
377
  const element = lexical.$isElementNode(node) ? node : node.getParentOrThrow();
471
378
  element.setFormat(format);
472
379
  return true;
@@ -474,17 +381,17 @@ function useRichTextSetup(editor, initialEditorState) {
474
381
 
475
382
  case 'insertLineBreak':
476
383
  const selectStart = payload;
477
- selection.insertLineBreak(selectStart);
384
+ selection$1.insertLineBreak(selectStart);
478
385
  return true;
479
386
 
480
387
  case 'insertParagraph':
481
- selection.insertParagraph();
388
+ selection$1.insertParagraph();
482
389
  return true;
483
390
 
484
391
  case 'indentContent':
485
392
  {
486
393
  // Handle code blocks
487
- const anchor = selection.anchor;
394
+ const anchor = selection$1.anchor;
488
395
  const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
489
396
 
490
397
  if (parentBlock.canInsertTab()) {
@@ -501,7 +408,7 @@ function useRichTextSetup(editor, initialEditorState) {
501
408
  case 'outdentContent':
502
409
  {
503
410
  // Handle code blocks
504
- const anchor = selection.anchor;
411
+ const anchor = selection$1.anchor;
505
412
  const anchorNode = anchor.getNode();
506
413
  const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
507
414
 
@@ -526,9 +433,9 @@ function useRichTextSetup(editor, initialEditorState) {
526
433
  const event = payload;
527
434
  const isHoldingShift = event.shiftKey;
528
435
 
529
- if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
436
+ if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
530
437
  event.preventDefault();
531
- $moveCharacter(selection, isHoldingShift, true);
438
+ selection.$moveCharacter(selection$1, isHoldingShift, true);
532
439
  return true;
533
440
  }
534
441
 
@@ -540,9 +447,9 @@ function useRichTextSetup(editor, initialEditorState) {
540
447
  const event = payload;
541
448
  const isHoldingShift = event.shiftKey;
542
449
 
543
- if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
450
+ if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
544
451
  event.preventDefault();
545
- $moveCharacter(selection, isHoldingShift, false);
452
+ selection.$moveCharacter(selection$1, isHoldingShift, false);
546
453
  return true;
547
454
  }
548
455
 
@@ -555,9 +462,9 @@ function useRichTextSetup(editor, initialEditorState) {
555
462
  event.preventDefault();
556
463
  const {
557
464
  anchor
558
- } = selection;
465
+ } = selection$1;
559
466
 
560
- if (selection.isCollapsed() && anchor.offset === 0) {
467
+ if (selection$1.isCollapsed() && anchor.offset === 0) {
561
468
  const element = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
562
469
 
563
470
  if (element.getIndent() > 0) {
@@ -4,16 +4,15 @@
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"),u=require("react-dom"),v=require("@lexical/clipboard");function w(a,e=!0){if(a)return!1;a=r.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
8
- function x(a){if(!w(a,!1))return!1;a=r.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let d=0;d<e;d++){var f=a[d];if(r.$isElementNode(f)){if("paragraph"!==f.__type||0!==f.__indent)return!1;f=f.getChildren();const c=f.length;for(let b=0;b<c;b++)if(!r.$isTextNode(f[d]))return!1}}return!0}function y(a){return()=>x(a)}var z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
9
- function A(a){const [e,f]=h.useState(a.getEditorState().read(y(a.isComposing())));z(()=>a.addListener("update",({editorState:d})=>{const c=a.isComposing();d=d.read(y(c));f(d)}),[a]);return e}function C(a){const [e,f]=h.useState(()=>a.getDecorators());z(()=>a.addListener("decorator",d=>{u.flushSync(()=>{f(d)})}),[a]);return h.useMemo(()=>{const d=[],c=Object.keys(e);for(let p=0;p<c.length;p++){var b=c[p];const t=e[b];b=a.getElementByKey(b);null!==b&&d.push(u.createPortal(t,b))}return d},[e,a])}
10
- function D(a){a=a.anchor.getNode();return"rtl"===(r.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function E(a,e){a=r.$getDecoratorNode(a.focus,e);return r.$isDecoratorNode(a)&&!a.isIsolated()}function F(a,e){G(a,e);e.update(()=>{const f=r.$getSelection();r.$isRangeSelection(f)&&f.removeText()})}
11
- function G(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData,d=r.$getSelection();if(null!==d&&null!=f){const c=v.getHtmlContent(e),b=v.$getLexicalContent(e);null!==c&&f.setData("text/html",c);null!==b&&f.setData("application/x-lexical-editor",b);f.setData("text/plain",d.getTextContent())}})}function H(a,e){a.preventDefault();e.update(()=>{const f=r.$getSelection(),d=a.clipboardData;null!=d&&r.$isRangeSelection(f)&&v.$insertDataTransferForRichText(d,f,e)})}const I={tag:"history-merge"};
12
- function J(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=r.$getRoot();if(null===f.getFirstChild()){const d=r.$createParagraphNode();f.append(d);f=document.activeElement;(null!==r.$getSelection()||null!==f&&f===a.getRootElement())&&d.select()}},I);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,I);break;case "object":a.setEditorState(e,I);break;case "function":a.update(e,I)}}
13
- function K(a){h.useEffect(()=>{const e=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var c=JSON.parse(d)}catch(b){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [b,p,t,B,L]=c;a.update(()=>{const q=r.$getSelection();if(r.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;r.$isTextNode(k)&&0<=b&&0<=p&&(l=b,m=b+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
14
- t)q.insertRawText(t),k=n.getNode();r.$isTextNode(k)&&(l=B,m=B+L,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)}},[a])}
15
- function M(a,e){z(()=>{const f=a.addListener("command",(d,c)=>{var b=r.$getSelection();if("click"===d&&r.$isNodeSelection(b))return b.clear(),!0;if(!r.$isRangeSelection(b))return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(c),!0;case "deleteWord":return b.deleteWord(c),!0;case "deleteLine":return b.deleteLine(c),!0;case "insertText":return"string"===typeof c?b.insertText(c):(d=c.dataTransfer,null!=d?v.$insertDataTransferForRichText(d,b,a):(c=c.data)&&b.insertText(c)),!0;case "removeText":return b.removeText(),
16
- !0;case "formatText":return b.formatText(c),!0;case "formatElement":return b=b.anchor.getNode(),(r.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(c),!0;case "insertLineBreak":return b.insertLineBreak(c),!0;case "insertParagraph":return b.insertParagraph(),!0;case "indentContent":return b=b.anchor,b="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),b.canInsertTab()?a.execCommand("insertText","\t"):10!==b.getIndent()&&b.setIndent(b.getIndent()+1),!0;case "outdentContent":return b=b.anchor,
17
- c=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===c.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=c.shiftKey;if(E(b,!0))return c.preventDefault(),c=d,d=D(b),b.modify(c?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=c.shiftKey;if(E(b,!1))return c.preventDefault(),c=d,d=D(b),b.modify(c?"extend":"move",d,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
18
- {anchor:c}=b,b.isCollapsed()&&0===c.offset&&0<("element"===c.type?c.getNode():c.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),c.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return c.preventDefault(),a.execCommand(c.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
19
- !0;case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return H(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,e);return f},[a]);K(a)}module.exports=function({contentEditable:a,placeholder:e,initialEditorState:f}){const [d]=g.useLexicalComposerContext(),c=A(d);M(d,f);f=C(d);return h.createElement(h.Fragment,null,a,c&&e,f)};
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)};
@@ -72,7 +72,7 @@ function TablePlugin() {
72
72
  }, EditorPriority);
73
73
  }, [editor]);
74
74
  react.useEffect(() => {
75
- const listeners = new Map();
75
+ const tableSelections = new Map();
76
76
  return editor.addListener('mutation', table.TableNode, nodeMutations => {
77
77
  // eslint-disable-next-line no-for-of-loops/no-for-of-loops
78
78
  for (const [nodeKey, mutation] of nodeMutations) {
@@ -82,13 +82,17 @@ function TablePlugin() {
82
82
  const tableNode = lexical.$getNodeByKey(nodeKey);
83
83
 
84
84
  if (tableElement && tableNode) {
85
- const removeListeners = table.$applyCustomTableHandlers(tableNode, tableElement, editor);
86
- listeners.set(nodeKey, removeListeners);
85
+ const tableSelection = table.applyTableHandlers(tableNode, tableElement, editor);
86
+ tableSelections.set(nodeKey, tableSelection);
87
87
  }
88
88
  });
89
89
  } else if (mutation === 'destroyed') {
90
- const cleanup = listeners.get(nodeKey);
91
- if (cleanup) cleanup();
90
+ const tableSelection = tableSelections.get(nodeKey);
91
+
92
+ if (tableSelection) {
93
+ tableSelection.removeListeners();
94
+ tableSelections.delete(nodeKey);
95
+ }
92
96
  }
93
97
  }
94
98
  });
@@ -6,5 +6,5 @@
6
6
  */
7
7
  var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/table"),k=require("lexical"),m=require("react");
8
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.$applyCustomTableHandlers(l,f,d),a.set(c,f))}):
10
- "destroyed"===h&&(b=a.get(c))&&b()})},[d]);return null};
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};
package/package.json CHANGED
@@ -12,13 +12,18 @@
12
12
  "rich-text"
13
13
  ],
14
14
  "license": "MIT",
15
- "version": "0.1.12",
15
+ "version": "0.1.15",
16
+ "dependencies": {
17
+ "@lexical/clipboard": "0.1.15",
18
+ "@lexical/list": "0.1.15",
19
+ "@lexical/table": "0.1.15",
20
+ "@lexical/yjs": "0.1.15",
21
+ "@lexical/hashtag": "0.1.15",
22
+ "@lexical/selection": "0.1.15",
23
+ "@lexical/utils": "0.1.15"
24
+ },
16
25
  "peerDependencies": {
17
- "lexical": "0.1.12",
18
- "@lexical/helpers": "0.1.12",
19
- "@lexical/table": "0.1.12",
20
- "@lexical/yjs": "0.1.12",
21
- "@lexical/clipboard": "0.1.12",
26
+ "lexical": "0.1.15",
22
27
  "react": ">=17.x",
23
28
  "react-dom": ">=17.x"
24
29
  },
@@ -6,38 +6,9 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var lexical = require('lexical');
9
+ var text = require('@lexical/text');
10
10
  var react = require('react');
11
11
 
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- *
19
- */
20
- function $textContent() {
21
- const root = lexical.$getRoot();
22
- return root.getTextContent();
23
- }
24
- function $isTextContentEmpty(isEditorComposing, trim = true) {
25
- if (isEditorComposing) {
26
- return false;
27
- }
28
-
29
- let text = $textContent();
30
-
31
- if (trim) {
32
- text = text.trim();
33
- }
34
-
35
- return text === '';
36
- }
37
- function $isTextContentEmptyCurry(isEditorComposing, trim) {
38
- return () => $isTextContentEmpty(isEditorComposing, trim);
39
- }
40
-
41
12
  /**
42
13
  * Copyright (c) Meta Platforms, Inc. and affiliates.
43
14
  *
@@ -68,13 +39,13 @@ var useLayoutEffect = useLayoutEffectImpl;
68
39
  *
69
40
  */
70
41
  function useLexicalIsTextContentEmpty(editor, trim) {
71
- const [isEmpty, setIsEmpty] = react.useState(editor.getEditorState().read($isTextContentEmptyCurry(editor.isComposing(), trim)));
42
+ const [isEmpty, setIsEmpty] = react.useState(editor.getEditorState().read(text.$isRootTextContentEmptyCurry(editor.isComposing(), trim)));
72
43
  useLayoutEffect(() => {
73
44
  return editor.addListener('update', ({
74
45
  editorState
75
46
  }) => {
76
47
  const isComposing = editor.isComposing();
77
- const currentIsEmpty = editorState.read($isTextContentEmptyCurry(isComposing, trim));
48
+ const currentIsEmpty = editorState.read(text.$isRootTextContentEmptyCurry(isComposing, trim));
78
49
  setIsEmpty(currentIsEmpty);
79
50
  });
80
51
  }, [editor, trim]);
@@ -4,5 +4,4 @@
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 c=require("lexical"),e=require("react");function f(a,b=!0){if(a)return!1;a=c.$getRoot().getTextContent();b&&(a=a.trim());return""===a}function g(a,b){return()=>f(a,b)}var h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;
8
- module.exports=function(a,b){const [k,l]=e.useState(a.getEditorState().read(g(a.isComposing(),b)));h(()=>a.addListener("update",({editorState:d})=>{const m=a.isComposing();d=d.read(g(m,b));l(d)}),[a,b]);return k};
7
+ var b=require("@lexical/text"),e=require("react"),f="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;module.exports=function(a,c){const [g,h]=e.useState(a.getEditorState().read(b.$isRootTextContentEmptyCurry(a.isComposing(),c)));f(()=>a.addListener("update",({editorState:d})=>{const k=a.isComposing();d=d.read(b.$isRootTextContentEmptyCurry(k,c));h(d)}),[a,c]);return g};