@lexical/react 0.1.14 → 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 -741
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +1 -21
  3. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +4 -73
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +19 -72
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +7 -8
  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 -687
  16. package/DEPRECATED_useLexicalPlainText.prod.js +2 -15
  17. package/DEPRECATED_useLexicalRichText.dev.js +8 -772
  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 +19 -72
  33. package/LexicalCharacterLimitPlugin.prod.js +8 -9
  34. package/LexicalClearEditorPlugin.dev.js +15 -19
  35. package/LexicalClearEditorPlugin.prod.js +1 -1
  36. package/LexicalCollaborationPlugin.d.ts +8 -3
  37. package/LexicalCollaborationPlugin.dev.js +70 -47
  38. package/LexicalCollaborationPlugin.js.flow +9 -3
  39. package/LexicalCollaborationPlugin.prod.js +10 -8
  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 +21 -92
  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 +16 -3
  66. package/LexicalOnChangePlugin.prod.js +2 -1
  67. package/LexicalPlainTextPlugin.dev.js +9 -455
  68. package/LexicalPlainTextPlugin.prod.js +4 -12
  69. package/LexicalRichTextPlugin.dev.js +9 -540
  70. package/LexicalRichTextPlugin.prod.js +4 -13
  71. package/LexicalTablePlugin.dev.js +36 -35
  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 -11
  76. package/useLexicalIsTextContentEmpty.dev.js +4 -33
  77. package/useLexicalIsTextContentEmpty.prod.js +1 -2
  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 -778
  86. package/LexicalAutoFormatterPlugin.js +0 -9
  87. package/LexicalAutoFormatterPlugin.prod.js +0 -27
@@ -4,24 +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 k=require("@lexical/list"),q=require("lexical"),r=require("lexical/CodeNode"),t=require("react"),u=require("@lexical/react/LexicalHorizontalRuleNode"),x=require("lexical/HeadingNode"),y=require("lexical/QuoteNode");function C(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- function D(g,f,a,c){g=g.getChildren();const b=g.length;let d=0,e=!1;for(let p=0;p<b&&!(d>f);++p){const m=g[p],n=q.$isTextNode(m);var h=n?m.getTextContent().length:c;h=d+h;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=h)&&q.$isTextNode(m))return{node:m,offset:a-d};d=h;e=n}return null}
9
- const E={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},F={...E,requiresParagraphStart:!0},H=[{...E,nodeTransformationKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/},{...E,nodeTransformationKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/},{...E,nodeTransformationKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/},{...E,nodeTransformationKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__\s)$/},{...E,nodeTransformationKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>\s)$/},
10
- {...E,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],I=[{...F,nodeTransformationKind:"paragraphH1",regEx:/^(?:# )/},{...F,nodeTransformationKind:"paragraphH2",regEx:/^(?:## )/},{...F,nodeTransformationKind:"paragraphH2",regEx:/^(?:### )/},{...F,nodeTransformationKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...F,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...F,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:\* )/},{...F,nodeTransformationKind:"paragraphOrderedList",
11
- regEx:/^(\d+)\.\s/},{...F,nodeTransformationKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/^(?:--- )/},...H];
12
- function J(g,f,a,c){const b={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};c=g.match(c);if(null!==c&&0<c.length&&(!1===f||0===c.index)&&(!1===a||c.index+c[0].length===g.length)){b.offsetInJoinedTextForCollapsedSelection=g.length;g=c.length;f=c.index;for(a=0;a<g;a++){const d=c[a];b.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return b}return null}
13
- function K(g,f,a,c,b){b.offsetInJoinedTextForCollapsedSelection+=g;0<b.offsetInJoinedTextForCollapsedSelection||C(67);b=b.regExCaptureGroups;const d=b.length;for(c+=1;c<d;c++){const e=b[c];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
14
- function L(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,c=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var b=c;a=null;var d=b.getChildren(),e=f.autoFormatCriteria,h=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=x.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
15
- x.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=x.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=y.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=k.$createListNode("ul");b=k.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=k.$createListNode("ol",a);b=k.$createListItemNode();b.append(...d);
16
- a.append(b);break;case "paragraphCodeBlock":null!=f.triggerState&&f.triggerState.isCodeBlock?a=q.$createParagraphNode():(a=r.$createCodeNode(),b=3<=h.regExCaptureGroups.length?h.regExCaptureGroups[2].text:null,null!=b&&0<b.length&&a.setLanguage(b));a.append(...d);break;case "horizontalRule":d=u.$createHorizontalRuleNode(),b.insertBefore(d)}null!==a&&c.replace(a)}else if(a=f.autoFormatCriteria,c=f.matchResultContext,null!=a.nodeTransformationKind&&6===c.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;
17
- switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){d=[1,5];b=f.autoFormatCriteria;e=f.matchResultContext.regExCaptureGroups;h=e.length;var p=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&C(62);var m=f.joinedText.length;for(var n=1;n<h;n++){var l=e[n];l.anchorTextNodeWithOffset=D(p,m,l.offsetInParent,1);l.focusTextNodeWithOffset=D(p,m,l.offsetInParent+l.textLength,1);0>l.textLength&&
18
- C(63,b.nodeTransformationKind)}c.regExCaptureGroups=e;if(0<d.length)for(b=c.regExCaptureGroups,e=b.length,h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=b[p],n=l.anchorTextNodeWithOffset,m=l.focusTextNodeWithOffset,null!=n&&null!=m&&0<l.textLength&&(l=q.$createRangeSelection(),l.anchor.set(n.node.getKey(),n.offset,"text"),l.focus.set(m.node.getKey(),m.offset,"text"),q.$setSelection(l),l=q.$getSelection(),q.$isRangeSelection(l)&&(l.removeText(),n.node.getKey()===m.node.getKey()?(l=m.offset-n.offset,0<l||C(64),
19
- K(-l,m.offset,n.node,p,c)):(n=m.offset,0<n&&K(-n,n,m.node,p,c)))));d=c.regExCaptureGroups;3<d.length||C(65);e=d[3];b=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=b&&null!=d&&0<e.textLength&&(e=q.$createRangeSelection(),e.anchor.set(b.node.getKey(),b.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),q.$setSelection(e),b=q.$getSelection(),q.$isRangeSelection(b))){for(e=0;e<a.length;e++)b.formatText(a[e]);a=q.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+
20
- 1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");q.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();c=D(a,c.offsetInJoinedTextForCollapsedSelection+1,c.offsetInJoinedTextForCollapsedSelection,1);null!=c&&(a=q.$createRangeSelection(),a.anchor.set(c.node.getKey(),c.offset,"text"),a.focus.set(c.node.getKey(),c.offset,"text"),q.$setSelection(a))}}},{tag:"history-push"})}
21
- function M(g,f){let a=null;g.read(()=>{var c=q.$getSelection();if(q.$isRangeSelection(c)){var b=c.anchor.getNode();c=q.$isTextNode(b)?{node:b,offset:c.anchor.offset}:null}else c=null;if(null!==c){c={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:c,triggerState:f};a:{b=!1===f.isParentAListItemNode?I:H;const n=c.triggerState,
22
- l=b.length;for(let z=0;z<l;z++){const A=b[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=c;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=J(e,!0,!1,d.regEx)):d=null;else{if(null==e.joinedText){var h=e.textNodeWithOffset.node.getParentOrThrow();if(q.$isElementNode(h)){if(null==e.joinedText){var p=e,m=e.textNodeWithOffset;let w="";h=
23
- h.getChildren();const N=h.length;for(let B=0;B<N;++B){const v=h[B];if(q.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&C(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else C(52,h.__key)}d=J(e.joinedText,!1,!0,d.regEx)}if(null!=d){b={autoFormatCriteria:A,matchResultContext:d};break a}}}b={autoFormatCriteria:null,matchResultContext:null}}null!==b.autoFormatCriteria&&null!==b.matchResultContext&&(a=c,a.autoFormatCriteria=
24
- b.autoFormatCriteria,a.matchResultContext=b.matchResultContext)}});return a}
25
- function O(g){let f=null;g.read(()=>{const a=q.$getSelection();if(q.$isRangeSelection(a)&&a.isCollapsed()){var c=a.anchor.getNode(),b=c.getParent(),d=null!==b&&k.$isListItemNode(b);f={anchorOffset:a.anchor.offset,hasParentNode:null!==b,isCodeBlock:r.$isCodeNode(c),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:q.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return f}
26
- function P(g){t.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var c=g.getEditorState();a=O(c);if(null==a)c=null;else{var b=a,d=f;if(null==b||null==d)c=null;else{var e=b.textContent.length,h=b.anchorOffset-1;c=!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.nodeKey===d.nodeKey&&b.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===b.textContent.substr(h,1)&&b.textContent!==d.textContent)?null:M(c,b)}}null!=c&&L(g,c);f=a}else f=
27
- null})},[g])}module.exports=function(g){P(g)};
7
+ var b=require("@lexical/markdown"),c=require("@lexical/react/LexicalHorizontalRuleNode"),d=require("react");function e(a){d.useEffect(()=>b.registerMarkdownShortcuts(a,c.$createHorizontalRuleNode),[a])}module.exports=function(a){e(a)};
@@ -6,78 +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 $canShowPlaceholder(isComposing) {
38
- if (!$isTextContentEmpty(isComposing, false)) {
39
- return false;
40
- }
41
-
42
- const root = lexical.$getRoot();
43
- const children = root.getChildren();
44
- const childrenLength = children.length;
45
-
46
- if (childrenLength > 1) {
47
- return false;
48
- }
49
-
50
- for (let i = 0; i < childrenLength; i++) {
51
- const topBlock = children[i];
52
-
53
- if (lexical.$isElementNode(topBlock)) {
54
- if (topBlock.__type !== 'paragraph') {
55
- return false;
56
- }
57
-
58
- if (topBlock.__indent !== 0) {
59
- return false;
60
- }
61
-
62
- const topBlockChildren = topBlock.getChildren();
63
- const topBlockChildrenLength = topBlockChildren.length;
64
-
65
- for (let s = 0; s < topBlockChildrenLength; s++) {
66
- const child = topBlockChildren[i];
67
-
68
- if (!lexical.$isTextNode(child)) {
69
- return false;
70
- }
71
- }
72
- }
73
- }
74
-
75
- return true;
76
- }
77
- function $canShowPlaceholderCurry(isEditorComposing) {
78
- return () => $canShowPlaceholder(isEditorComposing);
79
- }
80
-
81
12
  /**
82
13
  * Copyright (c) Meta Platforms, Inc. and affiliates.
83
14
  *
@@ -108,13 +39,13 @@ var useLayoutEffect = useLayoutEffectImpl;
108
39
  *
109
40
  */
110
41
  function useLexicalCanShowPlaceholder$1(editor) {
111
- const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing())));
42
+ const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
112
43
  useLayoutEffect(() => {
113
- return editor.addListener('update', ({
44
+ return editor.registerUpdateListener(({
114
45
  editorState
115
46
  }) => {
116
47
  const isComposing = editor.isComposing();
117
- const currentCanShowPlaceholder = editorState.read($canShowPlaceholderCurry(isComposing));
48
+ const currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
118
49
  setCanShowPlaceholder(currentCanShowPlaceholder);
119
50
  });
120
51
  }, [editor]);
@@ -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 e=require("lexical"),f=require("react");function k(a,d=!0){if(a)return!1;a=e.$getRoot().getTextContent();d&&(a=a.trim());return""===a}function l(a){if(!k(a,!1))return!1;a=e.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let c=0;c<d;c++){var b=a[c];if(e.$isElementNode(b)){if("paragraph"!==b.__type||0!==b.__indent)return!1;b=b.getChildren();const g=b.length;for(let h=0;h<g;h++)if(!e.$isTextNode(b[c]))return!1}}return!0}function m(a){return()=>l(a)}
8
- var n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;function p(a){const [d,b]=f.useState(a.getEditorState().read(m(a.isComposing())));n(()=>a.addListener("update",({editorState:c})=>{const g=a.isComposing();c=c.read(m(g));b(c)}),[a]);return d}module.exports=function(a){return p(a)};
7
+ var b=require("@lexical/text"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;function f(a){const [g,h]=d.useState(a.getEditorState().read(b.$canShowPlaceholderCurry(a.isComposing())));e(()=>a.registerUpdateListener(({editorState:c})=>{const k=a.isComposing();c=c.read(b.$canShowPlaceholderCurry(k));h(c)}),[a]);return g}module.exports=function(a){return f(a)};
@@ -6,67 +6,12 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
+ var overflow = require('@lexical/overflow');
10
+ var text = require('@lexical/text');
11
+ var utils = require('@lexical/utils');
9
12
  var lexical = require('lexical');
10
- var withSubscriptions = require('@lexical/react/withSubscriptions');
11
- var OverflowNode = require('lexical/OverflowNode');
12
13
  var react = require('react');
13
14
 
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 $dfs(startingNode, endingNode) {
23
- const nodes = [];
24
- const start = (startingNode || lexical.$getRoot()).getLatest();
25
- const end = endingNode || (lexical.$isElementNode(start) ? start.getLastDescendant() : start);
26
- let node = start;
27
-
28
- while (node !== null && !node.is(end)) {
29
- nodes.push(node);
30
-
31
- if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
32
- node = node.getFirstChild();
33
- } else {
34
- // Find immediate sibling or nearest parent sibling
35
- let sibling = null;
36
-
37
- while (sibling === null && node !== null) {
38
- sibling = node.getNextSibling();
39
-
40
- if (sibling === null) {
41
- node = node.getParent();
42
- } else {
43
- node = sibling;
44
- }
45
- }
46
- }
47
- }
48
-
49
- if (node !== null && node.is(end)) {
50
- nodes.push(node);
51
- }
52
-
53
- return nodes;
54
- }
55
-
56
- /**
57
- * Copyright (c) Meta Platforms, Inc. and affiliates.
58
- *
59
- * This source code is licensed under the MIT license found in the
60
- * LICENSE file in the root directory of this source tree.
61
- *
62
- *
63
- */
64
- function $textContent() {
65
- const root = lexical.$getRoot();
66
- return root.getTextContent();
67
- }
68
- const $textContentCurry = $textContent;
69
-
70
15
  /**
71
16
  * Copyright (c) Meta Platforms, Inc. and affiliates.
72
17
  *
@@ -82,18 +27,18 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
82
27
  remainingCharacters = characters => {}
83
28
  } = optional;
84
29
  react.useEffect(() => {
85
- if (!editor.hasNodes([OverflowNode.OverflowNode])) {
30
+ if (!editor.hasNodes([overflow.OverflowNode])) {
86
31
  {
87
32
  throw Error(`useCharacterLimit: OverflowNode not registered on editor`);
88
33
  }
89
34
  }
90
35
  }, [editor]);
91
36
  react.useEffect(() => {
92
- let text = editor.getEditorState().read($textContentCurry);
37
+ let text$1 = editor.getEditorState().read(text.$rootTextContentCurry);
93
38
  let lastComputedTextLength = 0;
94
- return withSubscriptions(editor.addListener('textcontent', currentText => {
95
- text = currentText;
96
- }), editor.addListener('update', ({
39
+ return utils.mergeRegister(editor.registerTextContentListener(currentText => {
40
+ text$1 = currentText;
41
+ }), editor.registerUpdateListener(({
97
42
  dirtyLeaves
98
43
  }) => {
99
44
  const isComposing = editor.isComposing();
@@ -103,13 +48,13 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
103
48
  return;
104
49
  }
105
50
 
106
- const textLength = strlen(text);
51
+ const textLength = strlen(text$1);
107
52
  const textLengthAboveThreshold = textLength > maxCharacters || lastComputedTextLength !== null && lastComputedTextLength > maxCharacters;
108
53
  const diff = maxCharacters - textLength;
109
54
  remainingCharacters(diff);
110
55
 
111
56
  if (lastComputedTextLength === null || textLengthAboveThreshold) {
112
- const offset = findOffset(text, maxCharacters, strlen);
57
+ const offset = findOffset(text$1, maxCharacters, strlen);
113
58
  editor.update(() => {
114
59
  $wrapOverflowedNodes(offset);
115
60
  }, {
@@ -129,7 +74,7 @@ function findOffset(text, maxCharacters, strlen) {
129
74
 
130
75
  if (typeof Segmenter === 'function') {
131
76
  const segmenter = new Segmenter();
132
- const graphemes = segmenter.segment(text); // eslint-disable-next-line no-for-of-loops/no-for-of-loops
77
+ const graphemes = segmenter.segment(text);
133
78
 
134
79
  for (const {
135
80
  segment: grapheme
@@ -164,14 +109,16 @@ function findOffset(text, maxCharacters, strlen) {
164
109
  }
165
110
 
166
111
  function $wrapOverflowedNodes(offset) {
167
- const dfsNodes = $dfs();
112
+ const dfsNodes = utils.$dfs();
168
113
  const dfsNodesLength = dfsNodes.length;
169
114
  let accumulatedLength = 0;
170
115
 
171
116
  for (let i = 0; i < dfsNodesLength; i += 1) {
172
- const node = dfsNodes[i];
117
+ const {
118
+ node
119
+ } = dfsNodes[i];
173
120
 
174
- if (OverflowNode.$isOverflowNode(node)) {
121
+ if (overflow.$isOverflowNode(node)) {
175
122
  const previousLength = accumulatedLength;
176
123
  const nextLength = accumulatedLength + node.getTextContentSize();
177
124
 
@@ -208,7 +155,7 @@ function $wrapOverflowedNodes(offset) {
208
155
  const previousAccumulatedLength = accumulatedLength;
209
156
  accumulatedLength += node.getTextContentSize();
210
157
 
211
- if (accumulatedLength > offset && !OverflowNode.$isOverflowNode(node.getParent())) {
158
+ if (accumulatedLength > offset && !overflow.$isOverflowNode(node.getParent())) {
212
159
  const previousSelection = lexical.$getSelection();
213
160
  let overflowNode; // For simple text we can improve the limit accuracy by splitting the TextNode
214
161
  // on the split point
@@ -231,7 +178,7 @@ function $wrapOverflowedNodes(offset) {
231
178
  }
232
179
 
233
180
  function $wrapNode(node) {
234
- const overflowNode = OverflowNode.$createOverflowNode();
181
+ const overflowNode = overflow.$createOverflowNode();
235
182
  node.insertBefore(overflowNode);
236
183
  overflowNode.append(node);
237
184
  return overflowNode;
@@ -252,7 +199,7 @@ function $unwrapNode(node) {
252
199
  function mergePrevious(overflowNode) {
253
200
  const previousNode = overflowNode.getPreviousSibling();
254
201
 
255
- if (!OverflowNode.$isOverflowNode(previousNode)) {
202
+ if (!overflow.$isOverflowNode(previousNode)) {
256
203
  return;
257
204
  }
258
205
 
@@ -4,11 +4,10 @@
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 h=require("lexical"),t=require("@lexical/react/withSubscriptions"),y=require("lexical/OverflowNode"),z=require("react");function A(){return h.$getRoot().getTextContent()}function B(a,e,g){var f=Intl.Segmenter;let n=0;var c=0;if("function"===typeof f){a=(new f).segment(a);for(var {segment:k}of a){c+=g(k);if(c>e)break;n+=k.length}}else for(k=Array.from(a),a=k.length,f=0;f<a;f++){const p=k[f];c+=g(p);if(c>e)break;n+=p.length}return n}
8
- function C(a){const e=y.$createOverflowNode();a.insertBefore(e);e.append(a);return e}function D(a){const e=a.getChildren(),g=e.length;for(let f=0;f<g;f++)a.insertBefore(e[f]);a.remove();return 0<g?e[g-1]:null}
9
- function E(a){const e=a.getPreviousSibling();if(y.$isOverflowNode(e)){var g=a.getFirstChild(),f=e.getChildren(),n=f.length;if(null===g)a.append(...f);else for(var c=0;c<n;c++)g.insertBefore(f[c]);c=h.$getSelection();if(h.$isRangeSelection(c)){g=c.anchor;f=g.getNode();c=c.focus;const k=g.getNode();f.is(e)?g.set(a.getKey(),g.offset,"element"):f.is(a)&&g.set(a.getKey(),n+g.offset,"element");k.is(e)?c.set(a.getKey(),c.offset,"element"):k.is(a)&&c.set(a.getKey(),n+c.offset,"element")}e.remove()}}
10
- exports.mergePrevious=E;
11
- exports.useCharacterLimit=function(a,e,g=Object.freeze({})){const {strlen:f=c=>c.length,remainingCharacters:n=()=>{}}=g;z.useEffect(()=>{if(!a.hasNodes([y.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);z.useEffect(()=>{let c=a.getEditorState().read(A),k=0;return t(a.addListener("textcontent",p=>{c=p}),a.addListener("update",({dirtyLeaves:p})=>{var u=a.isComposing();
12
- p=0<p.size;if(!u&&p){u=f(c);p=u>e||null!==k&&k>e;n(e-u);if(null===k||p){const r=B(c,e,f);a.update(()=>{const v=[];for(var d=h.$getRoot().getLatest(),w=h.$isElementNode(d)?d.getLastDescendant():d;null!==d&&!d.is(w);)if(v.push(d),h.$isElementNode(d)&&0<d.getChildrenSize())d=d.getFirstChild();else for(var q=null;null===q&&null!==d;)q=d.getNextSibling(),d=null===q?d.getParent():q;null!==d&&d.is(w)&&v.push(d);w=v.length;d=0;for(q=0;q<w;q+=1){var b=v[q];if(y.$isOverflowNode(b)){var m=d;if(d+b.getTextContentSize()<=
13
- r){var l=b.getParent();m=b.getPreviousSibling();var x=b.getNextSibling();D(b);b=h.$getSelection();!h.$isRangeSelection(b)||b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()||(h.$isTextNode(m)?m.select():h.$isTextNode(x)?x.select():null!==l&&l.select())}else m<r&&(l=b.getFirstDescendant(),x=null!==l?l.getTextContentSize():0,m+=x,l=h.$isTextNode(l)&&l.isSimpleText(),m=m<=r,(l||m)&&D(b))}else h.$isLeafNode(b)&&(m=d,d+=b.getTextContentSize(),d>r&&!y.$isOverflowNode(b.getParent())&&(l=h.$getSelection(),
14
- m<r&&h.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(r-m),b=C(b)):b=C(b),null!==l&&h.$setSelection(l),E(b)))}},{tag:"history-merge"})}k=u}}))},[a,e,n,f])};
7
+ var k=require("@lexical/overflow"),q=require("@lexical/text"),w=require("@lexical/utils"),x=require("lexical"),y=require("react");function z(a,d,f){var e=Intl.Segmenter;let m=0;var c=0;if("function"===typeof e){a=(new e).segment(a);for(var {segment:g}of a){c+=f(g);if(c>d)break;m+=g.length}}else for(g=Array.from(a),a=g.length,e=0;e<a;e++){const n=g[e];c+=f(n);if(c>d)break;m+=n.length}return m}function A(a){const d=k.$createOverflowNode();a.insertBefore(d);d.append(a);return d}
8
+ function C(a){const d=a.getChildren(),f=d.length;for(let e=0;e<f;e++)a.insertBefore(d[e]);a.remove();return 0<f?d[f-1]:null}
9
+ function D(a){const d=a.getPreviousSibling();if(k.$isOverflowNode(d)){var f=a.getFirstChild(),e=d.getChildren(),m=e.length;if(null===f)a.append(...e);else for(var c=0;c<m;c++)f.insertBefore(e[c]);c=x.$getSelection();if(x.$isRangeSelection(c)){f=c.anchor;e=f.getNode();c=c.focus;const g=f.getNode();e.is(d)?f.set(a.getKey(),f.offset,"element"):e.is(a)&&f.set(a.getKey(),m+f.offset,"element");g.is(d)?c.set(a.getKey(),c.offset,"element"):g.is(a)&&c.set(a.getKey(),m+c.offset,"element")}d.remove()}}
10
+ exports.mergePrevious=D;
11
+ exports.useCharacterLimit=function(a,d,f=Object.freeze({})){const {strlen:e=c=>c.length,remainingCharacters:m=()=>{}}=f;y.useEffect(()=>{if(!a.hasNodes([k.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);y.useEffect(()=>{let c=a.getEditorState().read(q.$rootTextContentCurry),g=0;return w.mergeRegister(a.registerTextContentListener(n=>{c=n}),a.registerUpdateListener(({dirtyLeaves:n})=>
12
+ {var r=a.isComposing();n=0<n.size;if(!r&&n){r=e(c);n=r>d||null!==g&&g>d;m(d-r);if(null===g||n){const p=z(c,d,e);a.update(()=>{const B=w.$dfs(),E=B.length;let t=0;for(let v=0;v<E;v+=1){var {node:b}=B[v];if(k.$isOverflowNode(b)){var l=t;if(t+b.getTextContentSize()<=p){var h=b.getParent();l=b.getPreviousSibling();var u=b.getNextSibling();C(b);b=x.$getSelection();!x.$isRangeSelection(b)||b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()||(x.$isTextNode(l)?l.select():x.$isTextNode(u)?u.select():
13
+ null!==h&&h.select())}else l<p&&(h=b.getFirstDescendant(),u=null!==h?h.getTextContentSize():0,l+=u,h=x.$isTextNode(h)&&h.isSimpleText(),l=l<=p,(h||l)&&C(b))}else x.$isLeafNode(b)&&(l=t,t+=b.getTextContentSize(),t>p&&!k.$isOverflowNode(b.getParent())&&(h=x.$getSelection(),l<p&&x.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(p-l),b=A(b)):b=A(b),null!==h&&x.$setSelection(h),D(b)))}},{tag:"history-merge"})}g=r}}))},[a,d,m,e])};
@@ -42,7 +42,7 @@ function useDecorators(editor) {
42
42
  const [decorators, setDecorators] = react.useState(() => editor.getDecorators()); // Subscribe to changes
43
43
 
44
44
  useLayoutEffect(() => {
45
- return editor.addListener('decorator', nextDecorators => {
45
+ return editor.registerDecoratorListener(nextDecorators => {
46
46
  reactDom.flushSync(() => {
47
47
  setDecorators(nextDecorators);
48
48
  });
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var c=require("react"),g=require("react-dom"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?c.useLayoutEffect:c.useEffect;
8
- function l(a){const [e,m]=c.useState(()=>a.getDecorators());k(()=>a.addListener("decorator",d=>{g.flushSync(()=>{m(d)})}),[a]);return c.useMemo(()=>{const d=[],h=Object.keys(e);for(let f=0;f<h.length;f++){var b=h[f];const n=e[b];b=a.getElementByKey(b);null!==b&&d.push(g.createPortal(n,b))}return d},[e,a])}module.exports=function(a){return l(a)};
8
+ function l(a){const [e,m]=c.useState(()=>a.getDecorators());k(()=>a.registerDecoratorListener(d=>{g.flushSync(()=>{m(d)})}),[a]);return c.useMemo(()=>{const d=[],h=Object.keys(e);for(let f=0;f<h.length;f++){var b=h[f];const n=e[b];b=a.getElementByKey(b);null!==b&&d.push(g.createPortal(n,b))}return d},[e,a])}module.exports=function(a){return l(a)};
@@ -69,7 +69,7 @@ function useEditorEvents(events, editor) {
69
69
  });
70
70
  }
71
71
 
72
- return editor.addListener('root', (rootElement, prevRootElement) => {
72
+ return editor.registerRootListener((rootElement, prevRootElement) => {
73
73
  if (prevRootElement !== null) {
74
74
  destroy.forEach(fn => fn(prevRootElement));
75
75
  }
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function p(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
8
- function q(a,b){h(()=>{const k=[],l=[];for(let d=0;d<a.length;d++){const [c,e]=a[d],n=f=>{const m=b.getRootElement();null!==m&&"true"===m.contentEditable&&e(f,b)};k.push(f=>{p(c,f).addEventListener(c,n)});l.push(f=>{p(c,f).removeEventListener(c,n)})}return b.addListener("root",(d,c)=>{null!==c&&l.forEach(e=>e(c));null!==d&&k.forEach(e=>e(d))})},[b,a])}module.exports=function(a,b){q(a,b)};
8
+ function q(a,b){h(()=>{const k=[],l=[];for(let d=0;d<a.length;d++){const [c,e]=a[d],n=f=>{const m=b.getRootElement();null!==m&&"true"===m.contentEditable&&e(f,b)};k.push(f=>{p(c,f).addEventListener(c,n)});l.push(f=>{p(c,f).removeEventListener(c,n)})}return b.registerRootListener((d,c)=>{null!==c&&l.forEach(e=>e(c));null!==d&&k.forEach(e=>e(d))})},[b,a])}module.exports=function(a,b){q(a,b)};