@lexical/react 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/DEPRECATED_useLexical.dev.js +3 -38
  2. package/DEPRECATED_useLexical.prod.js +1 -2
  3. package/DEPRECATED_useLexicalAutoFormatter.dev.js +4 -4
  4. package/DEPRECATED_useLexicalAutoFormatter.prod.js +8 -7
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +2 -2
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +3 -3
  7. package/DEPRECATED_useLexicalEditor.dev.js +1 -25
  8. package/DEPRECATED_useLexicalEditor.prod.js +1 -1
  9. package/DEPRECATED_useLexicalHistory.dev.js +1 -1
  10. package/DEPRECATED_useLexicalHistory.prod.js +2 -2
  11. package/DEPRECATED_useLexicalPlainText.dev.js +15 -32
  12. package/DEPRECATED_useLexicalPlainText.prod.js +14 -15
  13. package/DEPRECATED_useLexicalRichText.dev.js +57 -209
  14. package/DEPRECATED_useLexicalRichText.prod.js +26 -29
  15. package/LexicalAutoFormatterPlugin.dev.js +4 -4
  16. package/LexicalAutoFormatterPlugin.prod.js +8 -7
  17. package/LexicalCharacterLimitPlugin.dev.js +2 -2
  18. package/LexicalCharacterLimitPlugin.prod.js +3 -3
  19. package/LexicalComposer.dev.js +1 -6
  20. package/LexicalComposer.prod.js +2 -3
  21. package/LexicalHistoryPlugin.dev.js +1 -1
  22. package/LexicalHistoryPlugin.prod.js +2 -2
  23. package/LexicalPlainTextPlugin.dev.js +12 -8
  24. package/LexicalPlainTextPlugin.prod.js +7 -7
  25. package/LexicalRichTextPlugin.dev.js +54 -185
  26. package/LexicalRichTextPlugin.prod.js +22 -25
  27. package/LexicalTablePlugin.dev.js +1 -1
  28. package/LexicalTablePlugin.prod.js +1 -1
  29. package/LexicalTreeView.dev.js +10 -2
  30. package/LexicalTreeView.prod.js +9 -8
  31. package/package.json +5 -5
  32. package/useLexicalNodeSelection.dev.js +70 -0
  33. package/useLexicalNodeSelection.js +9 -0
  34. package/useLexicalNodeSelection.prod.js +8 -0
@@ -18,35 +18,11 @@ var useLexicalCanShowPlaceholder = require('@lexical/react/DEPRECATED_useLexical
18
18
  *
19
19
  *
20
20
  */
21
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
22
-
23
- /**
24
- * Copyright (c) Meta Platforms, Inc. and affiliates.
25
- *
26
- * This source code is licensed under the MIT license found in the
27
- * LICENSE file in the root directory of this source tree.
28
- *
29
- *
30
- */
31
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
32
- var useLayoutEffect = useLayoutEffectImpl;
33
-
34
- /**
35
- * Copyright (c) Meta Platforms, Inc. and affiliates.
36
- *
37
- * This source code is licensed under the MIT license found in the
38
- * LICENSE file in the root directory of this source tree.
39
- *
40
- *
41
- */
42
- function useLexicalEditor(editor, onError) {
21
+ function useLexicalEditor(editor) {
43
22
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
44
23
  const rootElementRef = react.useCallback(rootElement => {
45
24
  editor.setRootElement(rootElement);
46
25
  }, [editor]);
47
- useLayoutEffect(() => {
48
- return editor.addListener('error', onError);
49
- }, [editor, onError]);
50
26
  return [rootElementRef, showPlaceholder];
51
27
  }
52
28
 
@@ -58,26 +34,15 @@ function useLexicalEditor(editor, onError) {
58
34
  *
59
35
  *
60
36
  */
61
-
62
- function defaultOnErrorHandler(e) {
63
- throw e;
64
- }
65
-
66
37
  function useLexical(editorConfig) {
67
- const onError = editorConfig !== undefined && editorConfig.onError || defaultOnErrorHandler;
68
38
  const editor = react.useMemo(() => {
69
39
  if (editorConfig !== undefined) {
70
- // eslint-disable-next-line no-unused-vars
71
- const {
72
- onError: _onError,
73
- ...config
74
- } = editorConfig;
75
- return lexical.createEditor(config);
40
+ return lexical.createEditor(editorConfig);
76
41
  }
77
42
 
78
43
  return lexical.createEditor(editorConfig);
79
44
  }, [editorConfig]);
80
- const [rootElementRef, showPlaceholder] = useLexicalEditor(editor, onError);
45
+ const [rootElementRef, showPlaceholder] = useLexicalEditor(editor);
81
46
  return [editor, rootElementRef, showPlaceholder];
82
47
  }
83
48
 
@@ -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 b=require("lexical"),g=require("react"),h=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function l(a,c){const d=h(a),f=g.useCallback(e=>{a.setRootElement(e)},[a]);k(()=>a.addListener("error",c),[a,c]);return[f,d]}function m(a){throw a;}
8
- module.exports=function(a){const c=void 0!==a&&a.onError||m,d=g.useMemo(()=>{if(void 0!==a){const {onError:p,...n}=a;return b.createEditor(n)}return b.createEditor(a)},[a]),[f,e]=l(d,c);return[d,f,e]};
7
+ var d=require("lexical"),e=require("react"),f=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder");function g(a){const b=f(a);return[e.useCallback(c=>{a.setRootElement(c)},[a]),b]}module.exports=function(a){const b=e.useMemo(()=>d.createEditor(a),[a]),[c,h]=g(b);return[b,c,h]};
@@ -468,7 +468,7 @@ function removeTextInCaptureGroups(regExCaptureGroupsToDelete, matchResultContex
468
468
  lexical.$setSelection(newSelection);
469
469
  const currentSelection = lexical.$getSelection();
470
470
 
471
- if (currentSelection != null) {
471
+ if (lexical.$isRangeSelection(currentSelection)) {
472
472
  currentSelection.removeText(); // Shift offsets for capture groups which are within the same node
473
473
 
474
474
  if (anchorTextNodeWithOffset.node.getKey() === focusTextNodeWithOffset.node.getKey()) {
@@ -534,7 +534,7 @@ function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResul
534
534
  lexical.$setSelection(newSelection);
535
535
  const currentSelection = lexical.$getSelection();
536
536
 
537
- if (currentSelection != null) {
537
+ if (lexical.$isRangeSelection(currentSelection)) {
538
538
  currentSelection.formatText(formatType);
539
539
  const finalSelection = lexical.$createRangeSelection();
540
540
  finalSelection.anchor.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
@@ -590,7 +590,7 @@ function getCriteriaWithMatchResultContext(autoFormatCriteriaArray, scanningCont
590
590
  }
591
591
 
592
592
  function getTextNodeForAutoFormatting(selection) {
593
- if (selection == null) {
593
+ if (!lexical.$isRangeSelection(selection)) {
594
594
  return null;
595
595
  }
596
596
 
@@ -664,7 +664,7 @@ function getTriggerState(editorState) {
664
664
  editorState.read(() => {
665
665
  const selection = lexical.$getSelection();
666
666
 
667
- if (selection == null || !selection.isCollapsed()) {
667
+ if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed()) {
668
668
  return;
669
669
  }
670
670
 
@@ -14,12 +14,13 @@ function K(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){va
14
14
  w.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=w.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=A.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=l.$createListNode("ul");c=l.$createListItemNode();c.append(...d);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<k.regExCaptureGroups.length?k.regExCaptureGroups[k.regExCaptureGroups.length-1].text:"1",10);a=l.$createListNode("ol",a);c=l.$createListItemNode();c.append(...d);
15
15
  a.append(c);break;case "paragraphCodeBlock":a=null!=f.triggerState&&f.triggerState.isCodeBlock?p.$createParagraphNode():q.$createCodeNode();a.append(...d);break;case "horizontalRule":d=v.$createHorizontalRuleNode(),c.insertBefore(d)}null!==a&&b.replace(a)}else if(a=f.autoFormatCriteria,b=f.matchResultContext,null!=a.nodeTransformationKind)switch(a.nodeTransformationKind){case "textBold":if(6===b.regExCaptureGroups.length){a=f.autoFormatCriteria;d=f.matchResultContext.regExCaptureGroups;c=d.length;
16
16
  e=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&B(62);k=f.joinedText.length;for(var n=1;n<c;n++){var h=d[n];h.anchorTextNodeWithOffset=C(e,k,h.offsetInParent,1);h.focusTextNodeWithOffset=C(e,k,h.offsetInParent+h.textLength,1);0>h.textLength&&B(63,a.nodeTransformationKind)}b.regExCaptureGroups=d;a=[1,5];d=b.regExCaptureGroups;c=d.length;for(e=a.length-1;0<=e;e--)if(e<c){k=a[e];var m=d[k];h=m.anchorTextNodeWithOffset;n=m.focusTextNodeWithOffset;null!=h&&null!=n&&0<m.textLength&&(m=
17
- p.$createRangeSelection(),m.anchor.set(h.node.getKey(),h.offset,"text"),m.focus.set(n.node.getKey(),n.offset,"text"),p.$setSelection(m),m=p.$getSelection(),null!=m&&(m.removeText(),h.node.getKey()===n.node.getKey()?(m=n.offset-h.offset,0<m||B(64),J(-m,n.offset,h.node,k,b)):(h=n.offset,0<h&&J(-h,h,n.node,k,b))))}a=b.regExCaptureGroups;3<a.length||B(65);c=a[3];d=c.anchorTextNodeWithOffset;a=c.focusTextNodeWithOffset;null!=d&&null!=a&&0<c.textLength&&(c=p.$createRangeSelection(),c.anchor.set(d.node.getKey(),
18
- d.offset,"text"),c.focus.set(a.node.getKey(),a.offset,"text"),p.$setSelection(c),d=p.$getSelection(),null!=d&&(d.formatText("bold"),d=p.$createRangeSelection(),d.anchor.set(a.node.getKey(),a.offset+1,"text"),d.focus.set(a.node.getKey(),a.offset+1,"text"),p.$setSelection(d)));a=f.textNodeWithOffset.node.getParentOrThrow();b=C(a,b.offsetInJoinedTextForCollapsedSelection+1,b.offsetInJoinedTextForCollapsedSelection,1);null!=b&&(a=p.$createRangeSelection(),a.anchor.set(b.node.getKey(),b.offset,"text"),
19
- a.focus.set(b.node.getKey(),b.offset,"text"),p.$setSelection(a))}}},{tag:"history-push"})}
20
- function L(g,f){let a=null;g.read(()=>{var b=p.$getSelection();if(null==b)b=null;else{var c=b.anchor.getNode();b=p.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}if(null!==b){b={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:b,triggerState:f};a:{c=!1===f.isParentAListItemNode?H:G;const m=b.triggerState,M=c.length;for(let x=
21
- 0;x<M;x++){const y=c[x];if(null!=m&&!1===m.isCodeBlock||"paragraphCodeBlock"===y.nodeTransformationKind){var d=y,e=b;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=I(e,!0,!1,d.regEx)):d=null;else b:{if(null==e.joinedText){var k=e.textNodeWithOffset.node.getParentOrThrow();if(p.$isElementNode(k)){if(null==e.joinedText){var n=e,h=e.textNodeWithOffset;let u="";k=k.getChildren();const N=
22
- k.length;for(let z=0;z<N;++z){const t=k[z];if(p.$isTextNode(t)){const F=t.getTextContent();if(t.is(h.node)){h.offset>F.length&&B(50,t.__key);u+=t.getTextContent().substr(0,h.offset);break}else u+=F}else u+="\u0004"}n.joinedText=u}d=I(e.joinedText,!1,!0,d.regEx);break b}B(52,k.__key)}d=null}if(null!=d){c={autoFormatCriteria:y,matchResultContext:d};break a}}}c={autoFormatCriteria:null,matchResultContext:null}}null!==c.autoFormatCriteria&&null!==c.matchResultContext&&(a=b,a.autoFormatCriteria=c.autoFormatCriteria,
23
- a.matchResultContext=c.matchResultContext)}});return a}function O(g){let f=null;g.read(()=>{const a=p.$getSelection();if(null!=a&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),d=null!==c&&l.$isListItemNode(c);f={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:q.$isCodeNode(b),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:p.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return f}
17
+ p.$createRangeSelection(),m.anchor.set(h.node.getKey(),h.offset,"text"),m.focus.set(n.node.getKey(),n.offset,"text"),p.$setSelection(m),m=p.$getSelection(),p.$isRangeSelection(m)&&(m.removeText(),h.node.getKey()===n.node.getKey()?(m=n.offset-h.offset,0<m||B(64),J(-m,n.offset,h.node,k,b)):(h=n.offset,0<h&&J(-h,h,n.node,k,b))))}a=b.regExCaptureGroups;3<a.length||B(65);c=a[3];d=c.anchorTextNodeWithOffset;a=c.focusTextNodeWithOffset;null!=d&&null!=a&&0<c.textLength&&(c=p.$createRangeSelection(),c.anchor.set(d.node.getKey(),
18
+ d.offset,"text"),c.focus.set(a.node.getKey(),a.offset,"text"),p.$setSelection(c),d=p.$getSelection(),p.$isRangeSelection(d)&&(d.formatText("bold"),d=p.$createRangeSelection(),d.anchor.set(a.node.getKey(),a.offset+1,"text"),d.focus.set(a.node.getKey(),a.offset+1,"text"),p.$setSelection(d)));a=f.textNodeWithOffset.node.getParentOrThrow();b=C(a,b.offsetInJoinedTextForCollapsedSelection+1,b.offsetInJoinedTextForCollapsedSelection,1);null!=b&&(a=p.$createRangeSelection(),a.anchor.set(b.node.getKey(),b.offset,
19
+ "text"),a.focus.set(b.node.getKey(),b.offset,"text"),p.$setSelection(a))}}},{tag:"history-push"})}
20
+ function L(g,f){let a=null;g.read(()=>{var b=p.$getSelection();if(p.$isRangeSelection(b)){var c=b.anchor.getNode();b=p.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}else b=null;if(null!==b){b={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:b,triggerState:f};a:{c=!1===f.isParentAListItemNode?H:G;const m=b.triggerState,
21
+ M=c.length;for(let x=0;x<M;x++){const y=c[x];if(null!=m&&!1===m.isCodeBlock||"paragraphCodeBlock"===y.nodeTransformationKind){var d=y,e=b;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=I(e,!0,!1,d.regEx)):d=null;else b:{if(null==e.joinedText){var k=e.textNodeWithOffset.node.getParentOrThrow();if(p.$isElementNode(k)){if(null==e.joinedText){var n=e,h=e.textNodeWithOffset;let u="";
22
+ k=k.getChildren();const N=k.length;for(let z=0;z<N;++z){const t=k[z];if(p.$isTextNode(t)){const F=t.getTextContent();if(t.is(h.node)){h.offset>F.length&&B(50,t.__key);u+=t.getTextContent().substr(0,h.offset);break}else u+=F}else u+="\u0004"}n.joinedText=u}d=I(e.joinedText,!1,!0,d.regEx);break b}B(52,k.__key)}d=null}if(null!=d){c={autoFormatCriteria:y,matchResultContext:d};break a}}}c={autoFormatCriteria:null,matchResultContext:null}}null!==c.autoFormatCriteria&&null!==c.matchResultContext&&(a=b,a.autoFormatCriteria=
23
+ c.autoFormatCriteria,a.matchResultContext=c.matchResultContext)}});return a}
24
+ function O(g){let f=null;g.read(()=>{const a=p.$getSelection();if(p.$isRangeSelection(a)&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),d=null!==c&&l.$isListItemNode(c);f={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:q.$isCodeNode(b),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:p.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return f}
24
25
  function P(g){r.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var b=g.getEditorState();a=O(b);if(null==a)b=null;else{var c=a,d=f;if(null==c||null==d)b=null;else{var e=c.textContent.length,k=c.anchorOffset-1;b=!1===(!0===c.hasParentNode&&c.isSimpleText&&c.isSelectionCollapsed&&c.nodeKey===d.nodeKey&&c.anchorOffset!==d.anchorOffset&&0<=k&&k+1<=e&&" "===c.textContent.substr(k,1)&&c.textContent!==d.textContent)?null:L(b,c)}}null!=b&&K(g,b);f=a}else f=
25
26
  null})},[g])}module.exports=function(g){P(g)};
@@ -173,7 +173,7 @@ function $wrapOverflowedNodes(offset) {
173
173
  $unwrapNode(node);
174
174
  const selection = lexical.$getSelection(); // Restore selection when the overflow children are removed
175
175
 
176
- if (selection !== null && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
176
+ if (lexical.$isRangeSelection(selection) && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
177
177
  if (lexical.$isTextNode(previousSibling)) {
178
178
  previousSibling.select();
179
179
  } else if (lexical.$isTextNode(nextSibling)) {
@@ -267,7 +267,7 @@ function mergePrevious(overflowNode) {
267
267
 
268
268
  const selection = lexical.$getSelection();
269
269
 
270
- if (selection !== null) {
270
+ if (lexical.$isRangeSelection(selection)) {
271
271
  const anchor = selection.anchor;
272
272
  const anchorNode = anchor.getNode();
273
273
  const focus = selection.focus;
@@ -6,9 +6,9 @@
6
6
  */
7
7
  var k=require("lexical"),l=require("@lexical/react/withSubscriptions"),n=require("lexical/OverflowNode"),p=require("react");function q(a,e){for(e(a);null!==a;){if(k.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let d=null;for(;null===d&&null!==a;)d=a.getNextSibling(),a=null===d?a.getParent():d}null!==a&&(a=e(a))}}function r(){return k.$getRoot().getTextContent()}
8
8
  function t(a,e,d){var g=Intl.Segmenter;let c=0;var b=0;if("function"===typeof g){a=(new g).segment(a);for(var {segment:f}of a){b+=d(f);if(b>e)break;c+=f.length}}else for(f=Array.from(a),a=f.length,g=0;g<a;g++){const h=f[g];b+=d(h);if(b>e)break;c+=h.length}return c}
9
- function u(a){const e=k.$getRoot();let d=0,g=e;q(e,c=>{if(n.$isOverflowNode(c)){var b=d;if(d+c.getTextContentSize()<=a){var f=c.getParent();b=c.getPreviousSibling();var h=c.getNextSibling();v(c);c=k.$getSelection();null===c||c.anchor.getNode().isAttached()&&c.focus.getNode().isAttached()||(k.$isTextNode(b)?b.select():k.$isTextNode(h)?h.select():null!==f&&f.select());return g}if(b<a&&(f=c.getFirstDescendant(),h=null!==f?f.getTextContentSize():0,b+=h,f=k.$isTextNode(f)&&f.isSimpleText(),b=b<=a,f||b))return v(c),
10
- g}else k.$isLeafNode(c)&&(b=d,d+=c.getTextContentSize(),d>a&&!n.$isOverflowNode(c.getParent())&&(f=k.$getSelection(),b<a&&k.$isTextNode(c)&&c.isSimpleText()?([,b]=c.splitText(a-b),b=w(b)):b=w(c),null!==f&&k.$setSelection(f),x(b)));return g=c})}function w(a){const e=n.$createOverflowNode();a.insertBefore(e);e.append(a);return e}function v(a){const e=a.getChildren(),d=e.length;for(let g=0;g<d;g++)a.insertBefore(e[g]);a.remove();return 0<d?e[d-1]:null}
11
- function x(a){const e=a.getPreviousSibling();if(n.$isOverflowNode(e)){var d=a.getFirstChild(),g=e.getChildren(),c=g.length;if(null===d)a.append(...g);else for(var b=0;b<c;b++)d.insertBefore(g[b]);b=k.$getSelection();if(null!==b){d=b.anchor;g=d.getNode();b=b.focus;const f=d.getNode();g.is(e)?d.set(a.getKey(),d.offset,"element"):g.is(a)&&d.set(a.getKey(),c+d.offset,"element");f.is(e)?b.set(a.getKey(),b.offset,"element"):f.is(a)&&b.set(a.getKey(),c+b.offset,"element")}e.remove()}}
9
+ function u(a){const e=k.$getRoot();let d=0,g=e;q(e,c=>{if(n.$isOverflowNode(c)){var b=d;if(d+c.getTextContentSize()<=a){var f=c.getParent();b=c.getPreviousSibling();var h=c.getNextSibling();v(c);c=k.$getSelection();!k.$isRangeSelection(c)||c.anchor.getNode().isAttached()&&c.focus.getNode().isAttached()||(k.$isTextNode(b)?b.select():k.$isTextNode(h)?h.select():null!==f&&f.select());return g}if(b<a&&(f=c.getFirstDescendant(),h=null!==f?f.getTextContentSize():0,b+=h,f=k.$isTextNode(f)&&f.isSimpleText(),
10
+ b=b<=a,f||b))return v(c),g}else k.$isLeafNode(c)&&(b=d,d+=c.getTextContentSize(),d>a&&!n.$isOverflowNode(c.getParent())&&(f=k.$getSelection(),b<a&&k.$isTextNode(c)&&c.isSimpleText()?([,b]=c.splitText(a-b),b=w(b)):b=w(c),null!==f&&k.$setSelection(f),x(b)));return g=c})}function w(a){const e=n.$createOverflowNode();a.insertBefore(e);e.append(a);return e}function v(a){const e=a.getChildren(),d=e.length;for(let g=0;g<d;g++)a.insertBefore(e[g]);a.remove();return 0<d?e[d-1]:null}
11
+ function x(a){const e=a.getPreviousSibling();if(n.$isOverflowNode(e)){var d=a.getFirstChild(),g=e.getChildren(),c=g.length;if(null===d)a.append(...g);else for(var b=0;b<c;b++)d.insertBefore(g[b]);b=k.$getSelection();if(k.$isRangeSelection(b)){d=b.anchor;g=d.getNode();b=b.focus;const f=d.getNode();g.is(e)?d.set(a.getKey(),d.offset,"element"):g.is(a)&&d.set(a.getKey(),c+d.offset,"element");f.is(e)?b.set(a.getKey(),b.offset,"element"):f.is(a)&&b.set(a.getKey(),c+b.offset,"element")}e.remove()}}
12
12
  exports.mergePrevious=x;
13
13
  exports.useCharacterLimit=function(a,e,d=Object.freeze({})){const {strlen:g=b=>b.length,remainingCharacters:c=()=>{}}=d;p.useEffect(()=>{if(!a.hasNodes([n.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]);p.useEffect(()=>{let b=a.getEditorState().read(r),f=0;return l(a.addListener("textcontent",h=>{b=h}),a.addListener("update",({dirtyLeaves:h})=>{var m=a.isComposing();
14
14
  h=0<h.size;if(!m&&h){m=g(b);h=m>e||null!==f&&f>e;c(e-m);if(null===f||h){const y=t(b,e,g);a.update(()=>{u(y)},{tag:"history-merge"})}f=m}}))},[a,e,c,g])};
@@ -17,35 +17,11 @@ var react = require('react');
17
17
  *
18
18
  *
19
19
  */
20
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
21
-
22
- /**
23
- * Copyright (c) Meta Platforms, Inc. and affiliates.
24
- *
25
- * This source code is licensed under the MIT license found in the
26
- * LICENSE file in the root directory of this source tree.
27
- *
28
- *
29
- */
30
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
31
- var useLayoutEffect = useLayoutEffectImpl;
32
-
33
- /**
34
- * Copyright (c) Meta Platforms, Inc. and affiliates.
35
- *
36
- * This source code is licensed under the MIT license found in the
37
- * LICENSE file in the root directory of this source tree.
38
- *
39
- *
40
- */
41
- function useLexicalEditor(editor, onError) {
20
+ function useLexicalEditor(editor) {
42
21
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
43
22
  const rootElementRef = react.useCallback(rootElement => {
44
23
  editor.setRootElement(rootElement);
45
24
  }, [editor]);
46
- useLayoutEffect(() => {
47
- return editor.addListener('error', onError);
48
- }, [editor, onError]);
49
25
  return [rootElementRef, showPlaceholder];
50
26
  }
51
27
 
@@ -4,4 +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 b=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function(a,c){const f=b(a),h=d.useCallback(g=>{a.setRootElement(g)},[a]);e(()=>a.addListener("error",c),[a,c]);return[h,f]};
7
+ var b=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),c=require("react");module.exports=function(a){const d=b(a);return[c.useCallback(e=>{a.setRootElement(e)},[a]),d]};
@@ -73,7 +73,7 @@ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyEl
73
73
  return COMPOSING_CHARACTER;
74
74
  }
75
75
 
76
- if (nextSelection === null || prevSelection === null || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
76
+ if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
77
77
  return OTHER;
78
78
  }
79
79
 
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var n=require("@lexical/react/withSubscriptions"),t=require("lexical"),v=require("react");
8
- function w(b,d,k,a,h){if(null===b||0===k.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(null===g||null===c||!c.isCollapsed()||!g.isCollapsed())return 0;var e=Array.from(k);a=Array.from(a);k=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const l=k.get(e[f]);void 0!==l&&h.push(l)}for(e=0;e<a.length;e++)a[e][1]&&(f=k.get(a[e][0]),void 0===f||t.$isRootNode(f)||h.push(f));if(0===h.length)return 0;if(1<h.length)return a=d._nodeMap,d=a.get(g.anchor.key),c=a.get(c.anchor.key),d&&
9
- c&&!b._nodeMap.has(d.__key)&&t.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!t.$isTextNode(b)||!t.$isTextNode(d)||b.__mode!==d.__mode)return 0;b=b.__text;d=d.__text;if(b===d)return 0;g=g.anchor;c=c.anchor;if(g.key!==c.key||"text"!==g.type)return 0;g=g.offset;c=c.offset;b=d.length-b.length;return 1===b&&c===g-1?2:-1===b&&c===g+1?3:-1===b&&c===g?4:0}
8
+ function w(b,d,k,a,h){if(null===b||0===k.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(!(t.$isRangeSelection(g)&&t.$isRangeSelection(c)&&c.isCollapsed()&&g.isCollapsed()))return 0;var e=Array.from(k);a=Array.from(a);k=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const l=k.get(e[f]);void 0!==l&&h.push(l)}for(e=0;e<a.length;e++)a[e][1]&&(f=k.get(a[e][0]),void 0===f||t.$isRootNode(f)||h.push(f));if(0===h.length)return 0;if(1<h.length)return a=d._nodeMap,d=a.get(g.anchor.key),
9
+ c=a.get(c.anchor.key),d&&c&&!b._nodeMap.has(d.__key)&&t.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!t.$isTextNode(b)||!t.$isTextNode(d)||b.__mode!==d.__mode)return 0;b=b.__text;d=d.__text;if(b===d)return 0;g=g.anchor;c=c.anchor;if(g.key!==c.key||"text"!==g.type)return 0;g=g.offset;c=c.offset;b=d.length-b.length;return 1===b&&c===g-1?2:-1===b&&c===g+1?3:-1===b&&c===g?4:0}
10
10
  function x(b,d){let k=Date.now(),a=0;return(h,g,c,e,f,l)=>{const p=Date.now();if(l.has("historic"))return a=0,k=p,2;const m=w(h,g,e,f,b.isComposing()),u=(()=>{const r=l.has("history-push");if(!r&&l.has("history-merge"))return 0;if(null===h)return 1;var q=g._selection;const z=h._selection;if(!(0<e.size||0<f.size))return null===z&&null!==q?0:2;q=null===c||c.editor===b;return!1===r&&0!==m&&m===a&&p<k+d&&q?0:1})();k=p;a=m;return u}}
11
11
  function y(b,d,k=1E3){const a=v.useMemo(()=>d||A(),[d]),h=v.useCallback(()=>{a.undoStack=[];a.redoStack=[];a.current=null},[a]);v.useEffect(()=>{const g=x(b,k);return n(b.addListener("command",c=>{switch(c){case "undo":c=a.redoStack;var e=a.undoStack;if(0!==e.length){var f=a.current;const l=e.pop();null!==f&&(c.push(f),b.execCommand("canRedo",!0));0===e.length&&b.execCommand("canUndo",!1);a.current=l;l.editor.setEditorState(l.editorState.clone(l.undoSelection),{tag:"historic"})}return!0;case "redo":return c=
12
12
  a.redoStack,e=a.undoStack,0!==c.length&&(f=a.current,null!==f&&(e.push(f),b.execCommand("canUndo",!0)),e=c.pop(),0===c.length&&b.execCommand("canRedo",!1),a.current=e,e.editor.setEditorState(e.editorState,{tag:"historic"})),!0;case "clearEditor":return h(),!1;case "clearHistory":return h(),!0;default:return!1}},0),b.addListener("update",({editorState:c,prevEditorState:e,dirtyLeaves:f,dirtyElements:l,tags:p})=>{const m=a.current,u=a.redoStack,r=a.undoStack,q=null===m?null:m.editorState;if(null===m||
@@ -26,7 +26,7 @@ const COMPOSING_CHARACTER = 1;
26
26
  const INSERT_CHARACTER_AFTER_SELECTION = 2;
27
27
  const DELETE_CHARACTER_BEFORE_SELECTION = 3;
28
28
  const DELETE_CHARACTER_AFTER_SELECTION = 4;
29
- const EditorPriority$1 = 0;
29
+ const EditorPriority = 0;
30
30
 
31
31
  function getDirtyNodes(editorState, dirtyLeavesSet, dirtyElementsSet) {
32
32
  const dirtyLeaves = Array.from(dirtyLeavesSet);
@@ -73,7 +73,7 @@ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyEl
73
73
  return COMPOSING_CHARACTER;
74
74
  }
75
75
 
76
- if (nextSelection === null || prevSelection === null || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
76
+ if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
77
77
  return OTHER;
78
78
  }
79
79
 
@@ -315,7 +315,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
315
315
  }
316
316
  };
317
317
 
318
- return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority$1), editor.addListener('update', applyChange));
318
+ return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority), editor.addListener('update', applyChange));
319
319
  }, [clearHistory, delay, editor, historyState]);
320
320
  }
321
321
  function createEmptyHistoryState() {
@@ -434,7 +434,7 @@ function onPasteForPlainText(event, editor) {
434
434
  const selection = lexical.$getSelection();
435
435
  const clipboardData = event.clipboardData;
436
436
 
437
- if (clipboardData != null && selection !== null) {
437
+ if (clipboardData != null && lexical.$isRangeSelection(selection)) {
438
438
  $insertDataTransferForPlainText(clipboardData, selection);
439
439
  }
440
440
  });
@@ -444,7 +444,7 @@ function onCutForPlainText(event, editor) {
444
444
  editor.update(() => {
445
445
  const selection = lexical.$getSelection();
446
446
 
447
- if (selection !== null) {
447
+ if (lexical.$isRangeSelection(selection)) {
448
448
  selection.removeText();
449
449
  }
450
450
  });
@@ -478,27 +478,6 @@ function onCopyForPlainText(event, editor) {
478
478
  });
479
479
  }
480
480
 
481
- /**
482
- * Copyright (c) Meta Platforms, Inc. and affiliates.
483
- *
484
- * This source code is licensed under the MIT license found in the
485
- * LICENSE file in the root directory of this source tree.
486
- *
487
- *
488
- */
489
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
490
-
491
- /**
492
- * Copyright (c) Meta Platforms, Inc. and affiliates.
493
- *
494
- * This source code is licensed under the MIT license found in the
495
- * LICENSE file in the root directory of this source tree.
496
- *
497
- *
498
- */
499
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
500
- var useLayoutEffect = useLayoutEffectImpl;
501
-
502
481
  /**
503
482
  * Copyright (c) Meta Platforms, Inc. and affiliates.
504
483
  *
@@ -538,7 +517,7 @@ function useLexicalDragonSupport(editor) {
538
517
  editor.update(() => {
539
518
  const selection = lexical.$getSelection();
540
519
 
541
- if (selection !== null) {
520
+ if (lexical.$isRangeSelection(selection)) {
542
521
  const anchor = selection.anchor;
543
522
  let anchorNode = anchor.getNode();
544
523
  let setSelStart = 0;
@@ -595,13 +574,12 @@ function useLexicalDragonSupport(editor) {
595
574
  *
596
575
  *
597
576
  */
598
- const EditorPriority = 0;
599
577
  function usePlainTextSetup(editor) {
600
- useLayoutEffect(() => {
578
+ react.useEffect(() => {
601
579
  const removeListener = editor.addListener('command', (type, payload) => {
602
580
  const selection = lexical.$getSelection();
603
581
 
604
- if (selection === null) {
582
+ if (!lexical.$isRangeSelection(selection)) {
605
583
  return false;
606
584
  }
607
585
 
@@ -755,8 +733,13 @@ function usePlainTextSetup(editor) {
755
733
  }
756
734
 
757
735
  return false;
758
- }, EditorPriority);
759
- editor.execCommand('bootstrapEditor');
736
+ }, 0);
737
+ const bootstrapCommandHandled = editor.execCommand('bootstrapEditor');
738
+
739
+ if (!bootstrapCommandHandled) {
740
+ console.warn('bootstrapEditor command was not handled. Did you forget to add <BootstrapPlugin />?');
741
+ }
742
+
760
743
  return removeListener;
761
744
  }, [editor]);
762
745
  useLexicalDragonSupport(editor);
@@ -4,19 +4,18 @@
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 n=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react");
8
- function w(a,d,c,b,e){if(null===a||0===c.size&&0===b.size)return 0;var g=d._selection,f=a._selection;if(e)return 1;if(null===g||null===f||!f.isCollapsed()||!g.isCollapsed())return 0;var h=Array.from(c);b=Array.from(b);c=d._nodeMap;e=[];for(var k=0;k<h.length;k++){const m=c.get(h[k]);void 0!==m&&e.push(m)}for(h=0;h<b.length;h++)b[h][1]&&(k=c.get(b[h][0]),void 0===k||u.$isRootNode(k)||e.push(k));if(0===e.length)return 0;if(1<e.length)return b=d._nodeMap,d=b.get(g.anchor.key),f=b.get(f.anchor.key),d&&
9
- f&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=e[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;g=g.anchor;f=f.anchor;if(g.key!==f.key||"text"!==g.type)return 0;g=g.offset;f=f.offset;a=d.length-a.length;return 1===a&&f===g-1?2:-1===a&&f===g+1?3:-1===a&&f===g?4:0}
10
- function x(a,d){let c=Date.now(),b=0;return(e,g,f,h,k,m)=>{const t=Date.now();if(m.has("historic"))return b=0,c=t,2;const l=w(e,g,h,k,a.isComposing()),r=(()=>{const q=m.has("history-push");if(!q&&m.has("history-merge"))return 0;if(null===e)return 1;var p=g._selection;const D=e._selection;if(!(0<h.size||0<k.size))return null===D&&null!==p?0:2;p=null===f||f.editor===a;return!1===q&&0!==l&&l===b&&t<c+d&&p?0:1})();c=t;b=l;return r}}
11
- function y(a,d,c=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),e=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const g=x(a,c);return n(a.addListener("command",f=>{switch(f){case "undo":f=b.redoStack;var h=b.undoStack;if(0!==h.length){var k=b.current;const m=h.pop();null!==k&&(f.push(k),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=m;m.editor.setEditorState(m.editorState.clone(m.undoSelection),
12
- {tag:"historic"})}return!0;case "redo":return f=b.redoStack,h=b.undoStack,0!==f.length&&(k=b.current,null!==k&&(h.push(k),a.execCommand("canUndo",!0)),h=f.pop(),0===f.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return e(),!1;case "clearHistory":return e(),!0;default:return!1}},0),a.addListener("update",({editorState:f,prevEditorState:h,dirtyLeaves:k,dirtyElements:m,tags:t})=>{const l=b.current,r=b.redoStack,q=b.undoStack,
13
- p=null===l?null:l.editorState;if(null===l||f!==p){k=g(h,f,l,k,m,t);if(1===k)0!==r.length&&(b.redoStack=[]),null!==l&&(q.push({...l,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;b.current={editor:a,editorState:f}}}))},[e,c,a,b])}function z(a,d,c=1E3){return y(a,d,c)}function A(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
7
+ var l=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react");
8
+ function w(a,d,c,b,e){if(null===a||0===c.size&&0===b.size)return 0;var g=d._selection,f=a._selection;if(e)return 1;if(!(u.$isRangeSelection(g)&&u.$isRangeSelection(f)&&f.isCollapsed()&&g.isCollapsed()))return 0;var h=Array.from(c);b=Array.from(b);c=d._nodeMap;e=[];for(var k=0;k<h.length;k++){const n=c.get(h[k]);void 0!==n&&e.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(k=c.get(b[h][0]),void 0===k||u.$isRootNode(k)||e.push(k));if(0===e.length)return 0;if(1<e.length)return b=d._nodeMap,d=b.get(g.anchor.key),
9
+ f=b.get(f.anchor.key),d&&f&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=e[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;g=g.anchor;f=f.anchor;if(g.key!==f.key||"text"!==g.type)return 0;g=g.offset;f=f.offset;a=d.length-a.length;return 1===a&&f===g-1?2:-1===a&&f===g+1?3:-1===a&&f===g?4:0}
10
+ function x(a,d){let c=Date.now(),b=0;return(e,g,f,h,k,n)=>{const t=Date.now();if(n.has("historic"))return b=0,c=t,2;const m=w(e,g,h,k,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===e)return 1;var p=g._selection;const D=e._selection;if(!(0<h.size||0<k.size))return null===D&&null!==p?0:2;p=null===f||f.editor===a;return!1===q&&0!==m&&m===b&&t<c+d&&p?0:1})();c=t;b=m;return r}}
11
+ function y(a,d,c=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),e=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const g=x(a,c);return l(a.addListener("command",f=>{switch(f){case "undo":f=b.redoStack;var h=b.undoStack;if(0!==h.length){var k=b.current;const n=h.pop();null!==k&&(f.push(k),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
12
+ {tag:"historic"})}return!0;case "redo":return f=b.redoStack,h=b.undoStack,0!==f.length&&(k=b.current,null!==k&&(h.push(k),a.execCommand("canUndo",!0)),h=f.pop(),0===f.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return e(),!1;case "clearHistory":return e(),!0;default:return!1}},0),a.addListener("update",({editorState:f,prevEditorState:h,dirtyLeaves:k,dirtyElements:n,tags:t})=>{const m=b.current,r=b.redoStack,q=b.undoStack,
13
+ p=null===m?null:m.editorState;if(null===m||f!==p){k=g(h,f,m,k,n,t);if(1===k)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;b.current={editor:a,editorState:f}}}))},[e,c,a,b])}function z(a,d,c=1E3){return y(a,d,c)}function A(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
14
14
  function B(a,d,c){const b=a.getParent();let e=c;null!==b&&(d&&0===c?(e=a.getIndexWithinParent(),a=b):d||c!==a.getChildrenSize()||(e=a.getIndexWithinParent()+1,a=b));return a.getChildAtIndex(d?e-1:e)}function C(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}
15
- function E(a,d){var c=a.focus;a=c.offset;"element"===c.type?(c=c.getNode(),d=B(c,d,a)):(c=c.getNode(),d&&0===a||!d&&a===c.getTextContentSize()?(a=d?c.getPreviousSibling():c.getNextSibling(),d=null===a?B(c.getParentOrThrow(),d,c.getIndexWithinParent()+(d?0:1)):a):d=null);return u.$isDecoratorNode(d)&&!d.isIsolated()}function F(a,d){a.preventDefault();d.update(()=>{const c=u.$getSelection(),b=a.clipboardData;null!=b&&null!==c&&C(b,c)})}
16
- function G(a,d){H(a,d);d.update(()=>{const c=u.$getSelection();null!==c&&c.removeText()})}function H(a,d){a.preventDefault();d.update(()=>{const c=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=c){var e=window.getSelection();if(!e.isCollapsed){var g=e.getRangeAt(0);g&&(e=document.createElement("div"),g=g.cloneContents(),e.appendChild(g),c.setData("text/html",e.innerHTML));c.setData("text/plain",b.getTextContent())}}})}
17
- var I="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;
18
- function J(a){v.useEffect(()=>{const d=c=>{var b=a.getRootElement();if(document.activeElement===b&&(b=c.data,"string"===typeof b)){try{var e=JSON.parse(b)}catch(g){return}if(e&&"nuanria_messaging"===e.protocol&&"request"===e.type&&(e=e.payload)&&"makeChanges"===e.functionId&&(e=e.args)){const [g,f,h,k,m]=e;a.update(()=>{const t=u.$getSelection();if(null!==t){var l=t.anchor;let r=l.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=g&&0<=f&&(q=g,p=g+f,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==h)t.insertRawText(h),
19
- r=l.getNode();u.$isTextNode(r)&&(q=k,p=k+m,l=r.getTextContentSize(),q=q>l?l:q,p=p>l?l:p,t.setTextNodeRange(r,q,r,p));c.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
20
- function K(a){I(()=>{const d=a.addListener("command",(c,b)=>{const e=u.$getSelection();if(null===e)return!1;switch(c){case "deleteCharacter":return e.deleteCharacter(b),!0;case "deleteWord":return e.deleteWord(b),!0;case "deleteLine":return e.deleteLine(b),!0;case "insertText":return"string"===typeof b?e.insertText(b):(c=b.dataTransfer,null!=c?C(c,e):(b=b.data)&&e.insertText(b)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(b),!0;case "insertParagraph":return e.insertLineBreak(),
21
- !0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(E(e,!0))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(E(e,!1))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),a.execCommand("deleteCharacter",
22
- !0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(b,a),!0;case "cut":return G(b,a),!0;case "paste":return F(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return d},[a]);J(a)}module.exports=function(a,d){K(a);z(a,d)};
15
+ function E(a,d){var c=a.focus;a=c.offset;"element"===c.type?(c=c.getNode(),d=B(c,d,a)):(c=c.getNode(),d&&0===a||!d&&a===c.getTextContentSize()?(a=d?c.getPreviousSibling():c.getNextSibling(),d=null===a?B(c.getParentOrThrow(),d,c.getIndexWithinParent()+(d?0:1)):a):d=null);return u.$isDecoratorNode(d)&&!d.isIsolated()}function F(a,d){a.preventDefault();d.update(()=>{const c=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(c)&&C(b,c)})}
16
+ function G(a,d){H(a,d);d.update(()=>{const c=u.$getSelection();u.$isRangeSelection(c)&&c.removeText()})}function H(a,d){a.preventDefault();d.update(()=>{const c=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=c){var e=window.getSelection();if(!e.isCollapsed){var g=e.getRangeAt(0);g&&(e=document.createElement("div"),g=g.cloneContents(),e.appendChild(g),c.setData("text/html",e.innerHTML));c.setData("text/plain",b.getTextContent())}}})}
17
+ function I(a){v.useEffect(()=>{const d=c=>{var b=a.getRootElement();if(document.activeElement===b&&(b=c.data,"string"===typeof b)){try{var e=JSON.parse(b)}catch(g){return}if(e&&"nuanria_messaging"===e.protocol&&"request"===e.type&&(e=e.payload)&&"makeChanges"===e.functionId&&(e=e.args)){const [g,f,h,k,n]=e;a.update(()=>{const t=u.$getSelection();if(u.$isRangeSelection(t)){var m=t.anchor;let r=m.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=g&&0<=f&&(q=g,p=g+f,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
18
+ h)t.insertRawText(h),r=m.getNode();u.$isTextNode(r)&&(q=k,p=k+n,m=r.getTextContentSize(),q=q>m?m:q,p=p>m?m:p,t.setTextNodeRange(r,q,r,p));c.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
19
+ function J(a){v.useEffect(()=>{const d=a.addListener("command",(c,b)=>{const e=u.$getSelection();if(!u.$isRangeSelection(e))return!1;switch(c){case "deleteCharacter":return e.deleteCharacter(b),!0;case "deleteWord":return e.deleteWord(b),!0;case "deleteLine":return e.deleteLine(b),!0;case "insertText":return"string"===typeof b?e.insertText(b):(c=b.dataTransfer,null!=c?C(c,e):(b=b.data)&&e.insertText(b)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(b),
20
+ !0;case "insertParagraph":return e.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(E(e,!0))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(E(e,!1))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),
21
+ a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(b,a),!0;case "cut":return G(b,a),!0;case "paste":return F(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return d},[a]);I(a)}module.exports=function(a,d){J(a);z(a,d)};