@lexical/utils 0.14.5 → 0.15.0

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.
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  'use strict';
8
10
 
9
11
  var selection = require('@lexical/selection');
@@ -17,7 +19,7 @@ var lexical = require('lexical');
17
19
  *
18
20
  */
19
21
 
20
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
22
+ const CAN_USE_DOM$1 = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
21
23
 
22
24
  /**
23
25
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -26,21 +28,22 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
26
28
  * LICENSE file in the root directory of this source tree.
27
29
  *
28
30
  */
29
- const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
30
- const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
31
- const IS_FIREFOX = CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
32
- const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
33
- const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
34
- const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
35
- const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
31
+
32
+ const documentMode = CAN_USE_DOM$1 && 'documentMode' in document ? document.documentMode : null;
33
+ const IS_APPLE$1 = CAN_USE_DOM$1 && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
34
+ const IS_FIREFOX$1 = CAN_USE_DOM$1 && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
35
+ const CAN_USE_BEFORE_INPUT$1 = CAN_USE_DOM$1 && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
36
+ const IS_SAFARI$1 = CAN_USE_DOM$1 && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
37
+ const IS_IOS$1 = CAN_USE_DOM$1 && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
38
+ const IS_ANDROID$1 = CAN_USE_DOM$1 && /Android/.test(navigator.userAgent);
36
39
 
37
40
  // Keep these in case we need to use them in the future.
38
41
  // export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
39
- const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
42
+ const IS_CHROME$1 = CAN_USE_DOM$1 && /^(?=.*Chrome).*/i.test(navigator.userAgent);
40
43
  // export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
41
44
 
42
- const IS_ANDROID_CHROME = CAN_USE_DOM && IS_ANDROID && IS_CHROME;
43
- const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
45
+ const IS_ANDROID_CHROME$1 = CAN_USE_DOM$1 && IS_ANDROID$1 && IS_CHROME$1;
46
+ const IS_APPLE_WEBKIT$1 = CAN_USE_DOM$1 && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME$1;
44
47
 
45
48
  /**
46
49
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -117,6 +120,7 @@ function px(value) {
117
120
  * LICENSE file in the root directory of this source tree.
118
121
  *
119
122
  */
123
+
120
124
  const mutationObserverConfig = {
121
125
  attributes: true,
122
126
  characterData: true,
@@ -244,6 +248,7 @@ function positionNodeOnRange(editor, range, onReposition) {
244
248
  * LICENSE file in the root directory of this source tree.
245
249
  *
246
250
  */
251
+
247
252
  function markSelection(editor, onReposition) {
248
253
  let previousAnchorNode = null;
249
254
  let previousAnchorOffset = null;
@@ -361,6 +366,18 @@ function markSelection(editor, onReposition) {
361
366
  * LICENSE file in the root directory of this source tree.
362
367
  *
363
368
  */
369
+
370
+ // Hotfix to export these with inlined types #5918
371
+ const CAN_USE_BEFORE_INPUT = CAN_USE_BEFORE_INPUT$1;
372
+ const CAN_USE_DOM = CAN_USE_DOM$1;
373
+ const IS_ANDROID = IS_ANDROID$1;
374
+ const IS_ANDROID_CHROME = IS_ANDROID_CHROME$1;
375
+ const IS_APPLE = IS_APPLE$1;
376
+ const IS_APPLE_WEBKIT = IS_APPLE_WEBKIT$1;
377
+ const IS_CHROME = IS_CHROME$1;
378
+ const IS_FIREFOX = IS_FIREFOX$1;
379
+ const IS_IOS = IS_IOS$1;
380
+ const IS_SAFARI = IS_SAFARI$1;
364
381
  /**
365
382
  * Takes an HTML element and adds the classNames passed within an array,
366
383
  * ignoring any non-string types. A space can be used to add multiple classes
@@ -466,7 +483,7 @@ function mediaFileReader(files, acceptableMimeTypes) {
466
483
  function $dfs(startingNode, endingNode) {
467
484
  const nodes = [];
468
485
  const start = (startingNode || lexical.$getRoot()).getLatest();
469
- const end = endingNode || (lexical.$isElementNode(start) ? start.getLastDescendant() : start);
486
+ const end = endingNode || (lexical.$isElementNode(start) ? start.getLastDescendant() || start : start);
470
487
  let node = start;
471
488
  let depth = $getDepth(node);
472
489
  while (node !== null && !node.is(end)) {
@@ -508,6 +525,32 @@ function $getDepth(node) {
508
525
  return depth;
509
526
  }
510
527
 
528
+ /**
529
+ * Performs a right-to-left preorder tree traversal.
530
+ * From the starting node it goes to the rightmost child, than backtracks to paret and finds new rightmost path.
531
+ * It will return the next node in traversal sequence after the startingNode.
532
+ * The traversal is similar to $dfs functions above, but the nodes are visited right-to-left, not left-to-right.
533
+ * @param startingNode - The node to start the search.
534
+ * @returns The next node in pre-order right to left traversal sequence or `null`, if the node does not exist
535
+ */
536
+ function $getNextRightPreorderNode(startingNode) {
537
+ let node = startingNode;
538
+ if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
539
+ node = node.getLastChild();
540
+ } else {
541
+ let sibling = null;
542
+ while (sibling === null && node !== null) {
543
+ sibling = node.getPreviousSibling();
544
+ if (sibling === null) {
545
+ node = node.getParent();
546
+ } else {
547
+ node = sibling;
548
+ }
549
+ }
550
+ }
551
+ return node;
552
+ }
553
+
511
554
  /**
512
555
  * Takes a node and traverses up its ancestors (toward the root node)
513
556
  * in order to find a specific type of node.
@@ -596,7 +639,7 @@ function registerNestedElementResolver(editor, targetNode, cloneNode, handleOver
596
639
  }
597
640
  return null;
598
641
  };
599
- const elementNodeTransform = node => {
642
+ const $elementNodeTransform = node => {
600
643
  const match = $findMatch(node);
601
644
  if (match !== null) {
602
645
  const {
@@ -624,7 +667,7 @@ function registerNestedElementResolver(editor, targetNode, cloneNode, handleOver
624
667
  }
625
668
  }
626
669
  };
627
- return editor.registerNodeTransform(targetNode, elementNodeTransform);
670
+ return editor.registerNodeTransform(targetNode, $elementNodeTransform);
628
671
  }
629
672
 
630
673
  /**
@@ -785,13 +828,16 @@ function calculateZoomLevel(element) {
785
828
  }
786
829
 
787
830
  exports.$splitNode = lexical.$splitNode;
831
+ exports.isBlockDomNode = lexical.isBlockDomNode;
788
832
  exports.isHTMLAnchorElement = lexical.isHTMLAnchorElement;
789
833
  exports.isHTMLElement = lexical.isHTMLElement;
834
+ exports.isInlineDomNode = lexical.isInlineDomNode;
790
835
  exports.$dfs = $dfs;
791
836
  exports.$filter = $filter;
792
837
  exports.$findMatchingParent = $findMatchingParent;
793
838
  exports.$getNearestBlockElementAncestorOrThrow = $getNearestBlockElementAncestorOrThrow;
794
839
  exports.$getNearestNodeOfType = $getNearestNodeOfType;
840
+ exports.$getNextRightPreorderNode = $getNextRightPreorderNode;
795
841
  exports.$insertFirst = $insertFirst;
796
842
  exports.$insertNodeToNearestRoot = $insertNodeToNearestRoot;
797
843
  exports.$restoreEditorState = $restoreEditorState;
@@ -3,10 +3,12 @@
3
3
  *
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
  */
8
+
7
9
  import { createRectsFromDOMRange, $cloneWithProperties } from '@lexical/selection';
8
10
  import { $getSelection, $isRangeSelection, TextNode, $getRoot, $isElementNode, $isTextNode, $setSelection, $getPreviousSelection, $isRootOrShadowRoot, $splitNode, $createParagraphNode } from 'lexical';
9
- export { $splitNode, isHTMLAnchorElement, isHTMLElement } from 'lexical';
11
+ export { $splitNode, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode } from 'lexical';
10
12
 
11
13
  /**
12
14
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -16,7 +18,7 @@ export { $splitNode, isHTMLAnchorElement, isHTMLElement } from 'lexical';
16
18
  *
17
19
  */
18
20
 
19
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
21
+ const CAN_USE_DOM$1 = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
20
22
 
21
23
  /**
22
24
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -25,21 +27,22 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
25
27
  * LICENSE file in the root directory of this source tree.
26
28
  *
27
29
  */
28
- const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
29
- const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
30
- const IS_FIREFOX = CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
31
- const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
32
- const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
33
- const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
34
- const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
30
+
31
+ const documentMode = CAN_USE_DOM$1 && 'documentMode' in document ? document.documentMode : null;
32
+ const IS_APPLE$1 = CAN_USE_DOM$1 && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
33
+ const IS_FIREFOX$1 = CAN_USE_DOM$1 && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
34
+ const CAN_USE_BEFORE_INPUT$1 = CAN_USE_DOM$1 && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
35
+ const IS_SAFARI$1 = CAN_USE_DOM$1 && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
36
+ const IS_IOS$1 = CAN_USE_DOM$1 && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
37
+ const IS_ANDROID$1 = CAN_USE_DOM$1 && /Android/.test(navigator.userAgent);
35
38
 
36
39
  // Keep these in case we need to use them in the future.
37
40
  // export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
38
- const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
41
+ const IS_CHROME$1 = CAN_USE_DOM$1 && /^(?=.*Chrome).*/i.test(navigator.userAgent);
39
42
  // export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
40
43
 
41
- const IS_ANDROID_CHROME = CAN_USE_DOM && IS_ANDROID && IS_CHROME;
42
- const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
44
+ const IS_ANDROID_CHROME$1 = CAN_USE_DOM$1 && IS_ANDROID$1 && IS_CHROME$1;
45
+ const IS_APPLE_WEBKIT$1 = CAN_USE_DOM$1 && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME$1;
43
46
 
44
47
  /**
45
48
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -116,6 +119,7 @@ function px(value) {
116
119
  * LICENSE file in the root directory of this source tree.
117
120
  *
118
121
  */
122
+
119
123
  const mutationObserverConfig = {
120
124
  attributes: true,
121
125
  characterData: true,
@@ -243,6 +247,7 @@ function positionNodeOnRange(editor, range, onReposition) {
243
247
  * LICENSE file in the root directory of this source tree.
244
248
  *
245
249
  */
250
+
246
251
  function markSelection(editor, onReposition) {
247
252
  let previousAnchorNode = null;
248
253
  let previousAnchorOffset = null;
@@ -360,6 +365,18 @@ function markSelection(editor, onReposition) {
360
365
  * LICENSE file in the root directory of this source tree.
361
366
  *
362
367
  */
368
+
369
+ // Hotfix to export these with inlined types #5918
370
+ const CAN_USE_BEFORE_INPUT = CAN_USE_BEFORE_INPUT$1;
371
+ const CAN_USE_DOM = CAN_USE_DOM$1;
372
+ const IS_ANDROID = IS_ANDROID$1;
373
+ const IS_ANDROID_CHROME = IS_ANDROID_CHROME$1;
374
+ const IS_APPLE = IS_APPLE$1;
375
+ const IS_APPLE_WEBKIT = IS_APPLE_WEBKIT$1;
376
+ const IS_CHROME = IS_CHROME$1;
377
+ const IS_FIREFOX = IS_FIREFOX$1;
378
+ const IS_IOS = IS_IOS$1;
379
+ const IS_SAFARI = IS_SAFARI$1;
363
380
  /**
364
381
  * Takes an HTML element and adds the classNames passed within an array,
365
382
  * ignoring any non-string types. A space can be used to add multiple classes
@@ -465,7 +482,7 @@ function mediaFileReader(files, acceptableMimeTypes) {
465
482
  function $dfs(startingNode, endingNode) {
466
483
  const nodes = [];
467
484
  const start = (startingNode || $getRoot()).getLatest();
468
- const end = endingNode || ($isElementNode(start) ? start.getLastDescendant() : start);
485
+ const end = endingNode || ($isElementNode(start) ? start.getLastDescendant() || start : start);
469
486
  let node = start;
470
487
  let depth = $getDepth(node);
471
488
  while (node !== null && !node.is(end)) {
@@ -507,6 +524,32 @@ function $getDepth(node) {
507
524
  return depth;
508
525
  }
509
526
 
527
+ /**
528
+ * Performs a right-to-left preorder tree traversal.
529
+ * From the starting node it goes to the rightmost child, than backtracks to paret and finds new rightmost path.
530
+ * It will return the next node in traversal sequence after the startingNode.
531
+ * The traversal is similar to $dfs functions above, but the nodes are visited right-to-left, not left-to-right.
532
+ * @param startingNode - The node to start the search.
533
+ * @returns The next node in pre-order right to left traversal sequence or `null`, if the node does not exist
534
+ */
535
+ function $getNextRightPreorderNode(startingNode) {
536
+ let node = startingNode;
537
+ if ($isElementNode(node) && node.getChildrenSize() > 0) {
538
+ node = node.getLastChild();
539
+ } else {
540
+ let sibling = null;
541
+ while (sibling === null && node !== null) {
542
+ sibling = node.getPreviousSibling();
543
+ if (sibling === null) {
544
+ node = node.getParent();
545
+ } else {
546
+ node = sibling;
547
+ }
548
+ }
549
+ }
550
+ return node;
551
+ }
552
+
510
553
  /**
511
554
  * Takes a node and traverses up its ancestors (toward the root node)
512
555
  * in order to find a specific type of node.
@@ -595,7 +638,7 @@ function registerNestedElementResolver(editor, targetNode, cloneNode, handleOver
595
638
  }
596
639
  return null;
597
640
  };
598
- const elementNodeTransform = node => {
641
+ const $elementNodeTransform = node => {
599
642
  const match = $findMatch(node);
600
643
  if (match !== null) {
601
644
  const {
@@ -623,7 +666,7 @@ function registerNestedElementResolver(editor, targetNode, cloneNode, handleOver
623
666
  }
624
667
  }
625
668
  };
626
- return editor.registerNodeTransform(targetNode, elementNodeTransform);
669
+ return editor.registerNodeTransform(targetNode, $elementNodeTransform);
627
670
  }
628
671
 
629
672
  /**
@@ -783,4 +826,4 @@ function calculateZoomLevel(element) {
783
826
  return zoom;
784
827
  }
785
828
 
786
- export { $dfs, $filter, $findMatchingParent, $getNearestBlockElementAncestorOrThrow, $getNearestNodeOfType, $insertFirst, $insertNodeToNearestRoot, $restoreEditorState, $wrapNodeInElement, CAN_USE_BEFORE_INPUT, CAN_USE_DOM, IS_ANDROID, IS_ANDROID_CHROME, IS_APPLE, IS_APPLE_WEBKIT, IS_CHROME, IS_FIREFOX, IS_IOS, IS_SAFARI, addClassNamesToElement, calculateZoomLevel, isMimeType, markSelection, mediaFileReader, mergeRegister, objectKlassEquals, positionNodeOnRange, registerNestedElementResolver, removeClassNamesFromElement };
829
+ export { $dfs, $filter, $findMatchingParent, $getNearestBlockElementAncestorOrThrow, $getNearestNodeOfType, $getNextRightPreorderNode, $insertFirst, $insertNodeToNearestRoot, $restoreEditorState, $wrapNodeInElement, CAN_USE_BEFORE_INPUT, CAN_USE_DOM, IS_ANDROID, IS_ANDROID_CHROME, IS_APPLE, IS_APPLE_WEBKIT, IS_CHROME, IS_FIREFOX, IS_IOS, IS_SAFARI, addClassNamesToElement, calculateZoomLevel, isMimeType, markSelection, mediaFileReader, mergeRegister, objectKlassEquals, positionNodeOnRange, registerNestedElementResolver, removeClassNamesFromElement };
package/LexicalUtils.js CHANGED
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  'use strict'
8
10
  const LexicalUtils = process.env.NODE_ENV === 'development' ? require('./LexicalUtils.dev.js') : require('./LexicalUtils.prod.js');
9
11
  module.exports = LexicalUtils;
package/LexicalUtils.mjs CHANGED
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  import * as modDev from './LexicalUtils.dev.mjs';
8
10
  import * as modProd from './LexicalUtils.prod.mjs';
9
11
  const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
@@ -12,6 +14,7 @@ export const $filter = mod.$filter;
12
14
  export const $findMatchingParent = mod.$findMatchingParent;
13
15
  export const $getNearestBlockElementAncestorOrThrow = mod.$getNearestBlockElementAncestorOrThrow;
14
16
  export const $getNearestNodeOfType = mod.$getNearestNodeOfType;
17
+ export const $getNextRightPreorderNode = mod.$getNextRightPreorderNode;
15
18
  export const $insertFirst = mod.$insertFirst;
16
19
  export const $insertNodeToNearestRoot = mod.$insertNodeToNearestRoot;
17
20
  export const $restoreEditorState = mod.$restoreEditorState;
@@ -29,8 +32,10 @@ export const IS_IOS = mod.IS_IOS;
29
32
  export const IS_SAFARI = mod.IS_SAFARI;
30
33
  export const addClassNamesToElement = mod.addClassNamesToElement;
31
34
  export const calculateZoomLevel = mod.calculateZoomLevel;
35
+ export const isBlockDomNode = mod.isBlockDomNode;
32
36
  export const isHTMLAnchorElement = mod.isHTMLAnchorElement;
33
37
  export const isHTMLElement = mod.isHTMLElement;
38
+ export const isInlineDomNode = mod.isInlineDomNode;
34
39
  export const isMimeType = mod.isMimeType;
35
40
  export const markSelection = mod.markSelection;
36
41
  export const mediaFileReader = mod.mediaFileReader;
@@ -3,13 +3,16 @@
3
3
  *
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
  */
8
+
7
9
  const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalUtils.dev.mjs') : import('./LexicalUtils.prod.mjs'));
8
10
  export const $dfs = mod.$dfs;
9
11
  export const $filter = mod.$filter;
10
12
  export const $findMatchingParent = mod.$findMatchingParent;
11
13
  export const $getNearestBlockElementAncestorOrThrow = mod.$getNearestBlockElementAncestorOrThrow;
12
14
  export const $getNearestNodeOfType = mod.$getNearestNodeOfType;
15
+ export const $getNextRightPreorderNode = mod.$getNextRightPreorderNode;
13
16
  export const $insertFirst = mod.$insertFirst;
14
17
  export const $insertNodeToNearestRoot = mod.$insertNodeToNearestRoot;
15
18
  export const $restoreEditorState = mod.$restoreEditorState;
@@ -27,8 +30,10 @@ export const IS_IOS = mod.IS_IOS;
27
30
  export const IS_SAFARI = mod.IS_SAFARI;
28
31
  export const addClassNamesToElement = mod.addClassNamesToElement;
29
32
  export const calculateZoomLevel = mod.calculateZoomLevel;
33
+ export const isBlockDomNode = mod.isBlockDomNode;
30
34
  export const isHTMLAnchorElement = mod.isHTMLAnchorElement;
31
35
  export const isHTMLElement = mod.isHTMLElement;
36
+ export const isInlineDomNode = mod.isInlineDomNode;
32
37
  export const isMimeType = mod.isMimeType;
33
38
  export const markSelection = mod.markSelection;
34
39
  export const mediaFileReader = mod.mediaFileReader;
@@ -3,23 +3,25 @@
3
3
  *
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
  */
7
- 'use strict';var h=require("@lexical/selection"),x=require("lexical");function C(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- let D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,E=D&&"documentMode"in document?document.documentMode:null,F=D&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),G=D&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),H=D&&"InputEvent"in window&&!E?"getTargetRanges"in new window.InputEvent("input"):!1,I=D&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),J=D&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,
9
- K=D&&/Android/.test(navigator.userAgent),L=D&&/^(?=.*Chrome).*/i.test(navigator.userAgent),M=D&&K&&L,N=D&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!L;function O(...a){let b=[];for(let c of a)if(c&&"string"===typeof c)for(let [e]of c.matchAll(/\S+/g))b.push(e);return b}function P(...a){return()=>{a.forEach(b=>b())}}let Q={attributes:!0,characterData:!0,childList:!0,subtree:!0};
10
- function R(a,b,c){function e(){if(null===g)throw Error("Unexpected null rootDOMNode");if(null===n)throw Error("Unexpected null parentDOMNode");let {left:p,top:A}=g.getBoundingClientRect();var q=n;let r=h.createRectsFromDOMRange(a,b);t.isConnected||q.append(t);q=!1;for(let y=0;y<r.length;y++){var w=r[y];let u=k[y]||document.createElement("div"),z=u.style;"absolute"!==z.position&&(z.position="absolute",q=!0);var l=`${w.left-p}px`;z.left!==l&&(z.left=l,q=!0);l=`${w.top-A}px`;z.top!==l&&(u.style.top=
11
- l,q=!0);l=`${w.width}px`;z.width!==l&&(u.style.width=l,q=!0);w=`${w.height}px`;z.height!==w&&(u.style.height=w,q=!0);u.parentNode!==t&&(t.append(u),q=!0);k[y]=u}for(;k.length>r.length;)k.pop();q&&c(k)}function d(){g=n=null;null!==m&&m.disconnect();m=null;t.remove();for(let p of k)p.remove();k=[]}function f(){let p=a.getRootElement();if(null===p)return d();let A=p.parentElement;if(!(A instanceof HTMLElement))return d();d();g=p;n=A;m=new MutationObserver(q=>{let r=a.getRootElement(),w=r&&r.parentElement;
12
- if(r!==g||w!==n)return f();for(let l of q)if(!t.contains(l.target))return e()});m.observe(A,Q);e()}let g=null,n=null,m=null,k=[],t=document.createElement("div"),B=a.registerRootListener(f);return()=>{B();d()}}function S(a,b){for(let c of b)if(a.type.startsWith(c))return!0;return!1}let T=(a,b)=>{for(;a!==x.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null};exports.$splitNode=x.$splitNode;exports.isHTMLAnchorElement=x.isHTMLAnchorElement;exports.isHTMLElement=x.isHTMLElement;
13
- exports.$dfs=function(a,b){let c=[];a=(a||x.$getRoot()).getLatest();b=b||(x.$isElementNode(a)?a.getLastDescendant():a);for(var e=a,d=0;null!==(e=e.getParent());)d++;for(e=d;null!==a&&!a.is(b);)if(c.push({depth:e,node:a}),x.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),e++;else for(d=null;null===d&&null!==a;)d=a.getNextSibling(),null===d?(a=a.getParent(),e--):a=d;null!==a&&a.is(b)&&c.push({depth:e,node:a});return c};
14
- exports.$filter=function(a,b){let c=[];for(let e=0;e<a.length;e++){let d=b(a[e]);null!==d&&c.push(d)}return c};exports.$findMatchingParent=T;exports.$getNearestBlockElementAncestorOrThrow=function(a){let b=T(a,c=>x.$isElementNode(c)&&!c.isInline());x.$isElementNode(b)||C(4,a.__key);return b};exports.$getNearestNodeOfType=function(a,b){for(;null!=a;){if(a instanceof b)return a;a=a.getParent()}return null};exports.$insertFirst=function(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)};
8
+
9
+ 'use strict';var g=require("@lexical/selection"),x=require("lexical"),C;function D(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}C=D&&D.__esModule&&Object.prototype.hasOwnProperty.call(D,"default")?D["default"]:D;
10
+ let E="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,F=E&&"documentMode"in document?document.documentMode:null,G=E&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),H=E&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),I=E&&"InputEvent"in window&&!F?"getTargetRanges"in new window.InputEvent("input"):!1,J=E&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),K=E&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,
11
+ L=E&&/Android/.test(navigator.userAgent),M=E&&/^(?=.*Chrome).*/i.test(navigator.userAgent),N=E&&L&&M;function O(...a){let b=[];for(let c of a)if(c&&"string"===typeof c)for(let [e]of c.matchAll(/\S+/g))b.push(e);return b}function P(...a){return()=>{a.forEach(b=>b())}}let Q={attributes:!0,characterData:!0,childList:!0,subtree:!0};
12
+ function R(a,b,c){function e(){null===h&&C(182);null===n&&C(183);let {left:p,top:A}=h.getBoundingClientRect();var q=n;let r=g.createRectsFromDOMRange(a,b);t.isConnected||q.append(t);q=!1;for(let y=0;y<r.length;y++){var w=r[y];let u=k[y]||document.createElement("div"),z=u.style;"absolute"!==z.position&&(z.position="absolute",q=!0);var l=`${w.left-p}px`;z.left!==l&&(z.left=l,q=!0);l=`${w.top-A}px`;z.top!==l&&(u.style.top=l,q=!0);l=`${w.width}px`;z.width!==l&&(u.style.width=l,q=!0);w=`${w.height}px`;
13
+ z.height!==w&&(u.style.height=w,q=!0);u.parentNode!==t&&(t.append(u),q=!0);k[y]=u}for(;k.length>r.length;)k.pop();q&&c(k)}function d(){h=n=null;null!==m&&m.disconnect();m=null;t.remove();for(let p of k)p.remove();k=[]}function f(){let p=a.getRootElement();if(null===p)return d();let A=p.parentElement;if(!(A instanceof HTMLElement))return d();d();h=p;n=A;m=new MutationObserver(q=>{let r=a.getRootElement(),w=r&&r.parentElement;if(r!==h||w!==n)return f();for(let l of q)if(!t.contains(l.target))return e()});
14
+ m.observe(A,Q);e()}let h=null,n=null,m=null,k=[],t=document.createElement("div"),B=a.registerRootListener(f);return()=>{B();d()}}let S=E&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!M;function T(a,b){for(let c of b)if(a.type.startsWith(c))return!0;return!1}let U=(a,b)=>{for(;a!==x.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null};exports.$splitNode=x.$splitNode;exports.isBlockDomNode=x.isBlockDomNode;exports.isHTMLAnchorElement=x.isHTMLAnchorElement;exports.isHTMLElement=x.isHTMLElement;
15
+ exports.isInlineDomNode=x.isInlineDomNode;exports.$dfs=function(a,b){let c=[];a=(a||x.$getRoot()).getLatest();b=b||(x.$isElementNode(a)?a.getLastDescendant()||a:a);for(var e=a,d=0;null!==(e=e.getParent());)d++;for(e=d;null!==a&&!a.is(b);)if(c.push({depth:e,node:a}),x.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),e++;else for(d=null;null===d&&null!==a;)d=a.getNextSibling(),null===d?(a=a.getParent(),e--):a=d;null!==a&&a.is(b)&&c.push({depth:e,node:a});return c};
16
+ exports.$filter=function(a,b){let c=[];for(let e=0;e<a.length;e++){let d=b(a[e]);null!==d&&c.push(d)}return c};exports.$findMatchingParent=U;exports.$getNearestBlockElementAncestorOrThrow=function(a){let b=U(a,c=>x.$isElementNode(c)&&!c.isInline());x.$isElementNode(b)||C(4,a.__key);return b};exports.$getNearestNodeOfType=function(a,b){for(;null!=a;){if(a instanceof b)return a;a=a.getParent()}return null};
17
+ exports.$getNextRightPreorderNode=function(a){if(x.$isElementNode(a)&&0<a.getChildrenSize())a=a.getLastChild();else{let b=null;for(;null===b&&null!==a;)b=a.getPreviousSibling(),a=null===b?a.getParent():b}return a};exports.$insertFirst=function(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)};
15
18
  exports.$insertNodeToNearestRoot=function(a){var b=x.$getSelection()||x.$getPreviousSelection();if(x.$isRangeSelection(b)){var {focus:c}=b;b=c.getNode();c=c.offset;if(x.$isRootOrShadowRoot(b))c=b.getChildAtIndex(c),null==c?b.append(a):c.insertBefore(a),a.selectNext();else{let e,d;x.$isTextNode(b)?(e=b.getParentOrThrow(),d=b.getIndexWithinParent(),0<c&&(d+=1,b.splitText(c))):(e=b,d=c);[,b]=x.$splitNode(e,d);b.insertBefore(a);b.selectStart()}}else null!=b?(b=b.getNodes(),b[b.length-1].getTopLevelElementOrThrow().insertAfter(a)):
16
- x.$getRoot().append(a),b=x.$createParagraphNode(),a.insertAfter(b),b.select();return a.getLatest()};exports.$restoreEditorState=function(a,b){let c=new Map,e=a._pendingEditorState;for(let [d,f]of b._nodeMap){let g=h.$cloneWithProperties(f);if(x.$isTextNode(g)){if(!x.$isTextNode(f))throw Error("Expected node be a TextNode");g.__text=f.__text}c.set(d,g)}e&&(e._nodeMap=c);a._dirtyType=2;a=b._selection;x.$setSelection(null===a?null:a.clone())};
17
- exports.$wrapNodeInElement=function(a,b){b=b();a.replace(b);b.append(a);return b};exports.CAN_USE_BEFORE_INPUT=H;exports.CAN_USE_DOM=D;exports.IS_ANDROID=K;exports.IS_ANDROID_CHROME=M;exports.IS_APPLE=F;exports.IS_APPLE_WEBKIT=N;exports.IS_CHROME=L;exports.IS_FIREFOX=G;exports.IS_IOS=J;exports.IS_SAFARI=I;exports.addClassNamesToElement=function(a,...b){b=O(...b);0<b.length&&a.classList.add(...b)};
18
- exports.calculateZoomLevel=function(a){if(G)return 1;let b=1;for(;a;)b*=Number(window.getComputedStyle(a).getPropertyValue("zoom")),a=a.parentElement;return b};exports.isMimeType=S;
19
- exports.markSelection=function(a,b){function c(m){m.read(()=>{var k=x.$getSelection();if(x.$isRangeSelection(k)){var {anchor:t,focus:B}=k;k=t.getNode();var p=k.getKey(),A=t.offset,q=B.getNode(),r=q.getKey(),w=B.offset,l=a.getElementByKey(p),y=a.getElementByKey(r);p=null===e||null===l||A!==d||p!==e.getKey()||k!==e&&(!(e instanceof x.TextNode)||k.updateDOM(e,l,a._config));r=null===f||null===y||w!==g||r!==f.getKey()||q!==f&&(!(f instanceof x.TextNode)||q.updateDOM(f,y,a._config));if(p||r){l=a.getElementByKey(t.getNode().getKey());
20
- var u=a.getElementByKey(B.getNode().getKey());if(null!==l&&null!==u&&"SPAN"===l.tagName&&"SPAN"===u.tagName){r=document.createRange();B.isBefore(t)?(p=u,y=B.offset,u=l,l=t.offset):(p=l,y=t.offset,l=B.offset);p=p.firstChild;if(null===p)throw Error("Expected text node to be first child of span");u=u.firstChild;if(null===u)throw Error("Expected text node to be first child of span");r.setStart(p,y);r.setEnd(u,l);n();n=R(a,r,z=>{for(let U of z){let v=U.style;"Highlight"!==v.background&&(v.background="Highlight");
21
- "HighlightText"!==v.color&&(v.color="HighlightText");"-1"!==v.zIndex&&(v.zIndex="-1");"none"!==v.pointerEvents&&(v.pointerEvents="none");"-1.5px"!==v.marginTop&&(v.marginTop="-1.5px");"4px"!==v.paddingTop&&(v.paddingTop="4px");"0px"!==v.paddingBottom&&(v.paddingBottom="0px")}void 0!==b&&b(z)})}}e=k;d=A;f=q;g=w}else g=f=d=e=null,n(),n=()=>{}})}let e=null,d=null,f=null,g=null,n=()=>{};c(a.getEditorState());return P(a.registerUpdateListener(({editorState:m})=>c(m)),n,()=>{n()})};
22
- exports.mediaFileReader=function(a,b){let c=a[Symbol.iterator]();return new Promise((e,d)=>{let f=[],g=()=>{const {done:n,value:m}=c.next();if(n)return e(f);const k=new FileReader;k.addEventListener("error",d);k.addEventListener("load",()=>{const t=k.result;"string"===typeof t&&f.push({file:m,result:t});g()});S(m,b)?k.readAsDataURL(m):g()};g()})};exports.mergeRegister=P;exports.objectKlassEquals=function(a,b){return null!==a?Object.getPrototypeOf(a).constructor.name===b.name:!1};
19
+ x.$getRoot().append(a),b=x.$createParagraphNode(),a.insertAfter(b),b.select();return a.getLatest()};exports.$restoreEditorState=function(a,b){let c=new Map,e=a._pendingEditorState;for(let [d,f]of b._nodeMap){let h=g.$cloneWithProperties(f);x.$isTextNode(h)&&(x.$isTextNode(f)||C(180),h.__text=f.__text);c.set(d,h)}e&&(e._nodeMap=c);a._dirtyType=2;a=b._selection;x.$setSelection(null===a?null:a.clone())};exports.$wrapNodeInElement=function(a,b){b=b();a.replace(b);b.append(a);return b};
20
+ exports.CAN_USE_BEFORE_INPUT=I;exports.CAN_USE_DOM=E;exports.IS_ANDROID=L;exports.IS_ANDROID_CHROME=N;exports.IS_APPLE=G;exports.IS_APPLE_WEBKIT=S;exports.IS_CHROME=M;exports.IS_FIREFOX=H;exports.IS_IOS=K;exports.IS_SAFARI=J;exports.addClassNamesToElement=function(a,...b){b=O(...b);0<b.length&&a.classList.add(...b)};exports.calculateZoomLevel=function(a){if(H)return 1;let b=1;for(;a;)b*=Number(window.getComputedStyle(a).getPropertyValue("zoom")),a=a.parentElement;return b};exports.isMimeType=T;
21
+ exports.markSelection=function(a,b){function c(m){m.read(()=>{var k=x.$getSelection();if(x.$isRangeSelection(k)){var {anchor:t,focus:B}=k;k=t.getNode();var p=k.getKey(),A=t.offset,q=B.getNode(),r=q.getKey(),w=B.offset,l=a.getElementByKey(p),y=a.getElementByKey(r);p=null===e||null===l||A!==d||p!==e.getKey()||k!==e&&(!(e instanceof x.TextNode)||k.updateDOM(e,l,a._config));r=null===f||null===y||w!==h||r!==f.getKey()||q!==f&&(!(f instanceof x.TextNode)||q.updateDOM(f,y,a._config));if(p||r){l=a.getElementByKey(t.getNode().getKey());
22
+ var u=a.getElementByKey(B.getNode().getKey());null!==l&&null!==u&&"SPAN"===l.tagName&&"SPAN"===u.tagName&&(r=document.createRange(),B.isBefore(t)?(p=u,y=B.offset,u=l,l=t.offset):(p=l,y=t.offset,l=B.offset),p=p.firstChild,null===p&&C(181),u=u.firstChild,null===u&&C(181),r.setStart(p,y),r.setEnd(u,l),n(),n=R(a,r,z=>{for(let V of z){let v=V.style;"Highlight"!==v.background&&(v.background="Highlight");"HighlightText"!==v.color&&(v.color="HighlightText");"-1"!==v.zIndex&&(v.zIndex="-1");"none"!==v.pointerEvents&&
23
+ (v.pointerEvents="none");"-1.5px"!==v.marginTop&&(v.marginTop="-1.5px");"4px"!==v.paddingTop&&(v.paddingTop="4px");"0px"!==v.paddingBottom&&(v.paddingBottom="0px")}void 0!==b&&b(z)}))}e=k;d=A;f=q;h=w}else h=f=d=e=null,n(),n=()=>{}})}let e=null,d=null,f=null,h=null,n=()=>{};c(a.getEditorState());return P(a.registerUpdateListener(({editorState:m})=>c(m)),n,()=>{n()})};
24
+ exports.mediaFileReader=function(a,b){let c=a[Symbol.iterator]();return new Promise((e,d)=>{let f=[],h=()=>{const {done:n,value:m}=c.next();if(n)return e(f);const k=new FileReader;k.addEventListener("error",d);k.addEventListener("load",()=>{const t=k.result;"string"===typeof t&&f.push({file:m,result:t});h()});T(m,b)?k.readAsDataURL(m):h()};h()})};exports.mergeRegister=P;exports.objectKlassEquals=function(a,b){return null!==a?Object.getPrototypeOf(a).constructor.name===b.name:!1};
23
25
  exports.positionNodeOnRange=R;
24
- exports.registerNestedElementResolver=function(a,b,c,e){return a.registerNodeTransform(b,d=>{a:{var f=d.getChildren();for(var g=0;g<f.length;g++)if(f[g]instanceof b){f=null;break a}for(f=d;null!==f;)if(g=f,f=f.getParent(),f instanceof b){f={child:g,parent:f};break a}f=null}if(null!==f){const {child:n,parent:m}=f;if(n.is(d)){e(m,d);d=n.getNextSiblings();f=d.length;m.insertAfter(n);if(0!==f){g=c(m);n.insertAfter(g);for(let k=0;k<f;k++)g.append(d[k])}m.canBeEmpty()||0!==m.getChildrenSize()||m.remove()}}})};
26
+ exports.registerNestedElementResolver=function(a,b,c,e){return a.registerNodeTransform(b,d=>{a:{var f=d.getChildren();for(var h=0;h<f.length;h++)if(f[h]instanceof b){f=null;break a}for(f=d;null!==f;)if(h=f,f=f.getParent(),f instanceof b){f={child:h,parent:f};break a}f=null}if(null!==f){const {child:n,parent:m}=f;if(n.is(d)){e(m,d);d=n.getNextSiblings();f=d.length;m.insertAfter(n);if(0!==f){h=c(m);n.insertAfter(h);for(let k=0;k<f;k++)h.append(d[k])}m.canBeEmpty()||0!==m.getChildrenSize()||m.remove()}}})};
25
27
  exports.removeClassNamesFromElement=function(a,...b){b=O(...b);0<b.length&&a.classList.remove(...b)}
@@ -3,5 +3,7 @@
3
3
  *
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
  */
7
- import{createRectsFromDOMRange as e,$cloneWithProperties as t}from"@lexical/selection";import{$getSelection as n,$isRangeSelection as o,TextNode as r,$getRoot as l,$isElementNode as i,$isTextNode as s,$setSelection as c,$getPreviousSelection as u,$isRootOrShadowRoot as f,$splitNode as a,$createParagraphNode as d}from"lexical";export{$splitNode,isHTMLAnchorElement,isHTMLElement}from"lexical";var g=function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,h=p&&"documentMode"in document?document.documentMode:null,m=p&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),E=p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),v=!(!p||!("InputEvent"in window)||h)&&"getTargetRanges"in new window.InputEvent("input"),w=p&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),y=p&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,x=p&&/Android/.test(navigator.userAgent),N=p&&/^(?=.*Chrome).*/i.test(navigator.userAgent),P=p&&x&&N,S=p&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!N;function A(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}function b(...e){return()=>{e.forEach((e=>e()))}}function L(e){return`${e}px`}const T={attributes:!0,characterData:!0,childList:!0,subtree:!0};function M(t,n,o){let r=null,l=null,i=null,s=[];const c=document.createElement("div");function u(){if(null===r)throw Error("Unexpected null rootDOMNode");if(null===l)throw Error("Unexpected null parentDOMNode");const{left:i,top:u}=r.getBoundingClientRect(),f=l,a=e(t,n);c.isConnected||f.append(c);let d=!1;for(let e=0;e<a.length;e++){const t=a[e],n=s[e]||document.createElement("div"),o=n.style;"absolute"!==o.position&&(o.position="absolute",d=!0);const r=L(t.left-i);o.left!==r&&(o.left=r,d=!0);const l=L(t.top-u);o.top!==l&&(n.style.top=l,d=!0);const f=L(t.width);o.width!==f&&(n.style.width=f,d=!0);const g=L(t.height);o.height!==g&&(n.style.height=g,d=!0),n.parentNode!==c&&(c.append(n),d=!0),s[e]=n}for(;s.length>a.length;)s.pop();d&&o(s)}function f(){l=null,r=null,null!==i&&i.disconnect(),i=null,c.remove();for(const e of s)e.remove();s=[]}const a=t.registerRootListener((function e(){const n=t.getRootElement();if(null===n)return f();const o=n.parentElement;if(!(o instanceof HTMLElement))return f();f(),r=n,l=o,i=new MutationObserver((n=>{const o=t.getRootElement(),i=o&&o.parentElement;if(o!==r||i!==l)return e();for(const e of n)if(!c.contains(e.target))return u()})),i.observe(o,T),u()}));return()=>{a(),f()}}function _(e,t){let l=null,i=null,s=null,c=null,u=()=>{};function f(f){f.read((()=>{const f=n();if(!o(f))return l=null,i=null,s=null,c=null,u(),void(u=()=>{});const{anchor:a,focus:d}=f,g=a.getNode(),p=g.getKey(),h=a.offset,m=d.getNode(),E=m.getKey(),v=d.offset,w=e.getElementByKey(p),y=e.getElementByKey(E),x=null===l||null===w||h!==i||p!==l.getKey()||g!==l&&(!(l instanceof r)||g.updateDOM(l,w,e._config)),N=null===s||null===y||v!==c||E!==s.getKey()||m!==s&&(!(s instanceof r)||m.updateDOM(s,y,e._config));if(x||N){const n=e.getElementByKey(a.getNode().getKey()),o=e.getElementByKey(d.getNode().getKey());if(null!==n&&null!==o&&"SPAN"===n.tagName&&"SPAN"===o.tagName){const r=document.createRange();let l,i,s,c;d.isBefore(a)?(l=o,i=d.offset,s=n,c=a.offset):(l=n,i=a.offset,s=o,c=d.offset);const f=l.firstChild;if(null===f)throw Error("Expected text node to be first child of span");const g=s.firstChild;if(null===g)throw Error("Expected text node to be first child of span");r.setStart(f,i),r.setEnd(g,c),u(),u=M(e,r,(e=>{for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),"-1"!==e.zIndex&&(e.zIndex="-1"),"none"!==e.pointerEvents&&(e.pointerEvents="none"),e.marginTop!==L(-1.5)&&(e.marginTop=L(-1.5)),e.paddingTop!==L(4)&&(e.paddingTop=L(4)),e.paddingBottom!==L(0)&&(e.paddingBottom=L(0))}void 0!==t&&t(e)}))}}l=g,i=h,s=m,c=v}))}return f(e.getEditorState()),b(e.registerUpdateListener((({editorState:e})=>f(e))),u,(()=>{u()}))}function B(e,...t){const n=A(...t);n.length>0&&e.classList.add(...n)}function C(e,...t){const n=A(...t);n.length>0&&e.classList.remove(...n)}function K(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function O(e,t){const n=e[Symbol.iterator]();return new Promise(((e,o)=>{const r=[],l=()=>{const{done:i,value:s}=n.next();if(i)return e(r);const c=new FileReader;c.addEventListener("error",o),c.addEventListener("load",(()=>{const e=c.result;"string"==typeof e&&r.push({file:s,result:e}),l()})),K(s,t)?c.readAsDataURL(s):l()};l()}))}function R(e,t){const n=[],o=(e||l()).getLatest(),r=t||(i(o)?o.getLastDescendant():o);let s=o,c=function(e){let t=e,n=0;for(;null!==(t=t.getParent());)n++;return n}(s);for(;null!==s&&!s.is(r);)if(n.push({depth:c,node:s}),i(s)&&s.getChildrenSize()>0)s=s.getFirstChild(),c++;else{let e=null;for(;null===e&&null!==s;)e=s.getNextSibling(),null===e?(s=s.getParent(),c--):s=e}return null!==s&&s.is(r)&&n.push({depth:c,node:s}),n}function D(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}function H(e){const t=I(e,(e=>i(e)&&!e.isInline()));return i(t)||g(4,e.__key),t}const I=(e,t)=>{let n=e;for(;n!==l()&&null!=n;){if(t(n))return n;n=n.getParent()}return null};function z(e,t,n,o){const r=e=>e instanceof t;return e.registerNodeTransform(t,(e=>{const t=(e=>{const t=e.getChildren();for(let e=0;e<t.length;e++){const n=t[e];if(r(n))return null}let n=e,o=e;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return{child:o,parent:n};return null})(e);if(null!==t){const{child:r,parent:l}=t;if(r.is(e)){o(l,e);const t=r.getNextSiblings(),i=t.length;if(l.insertAfter(r),0!==i){const e=n(l);r.insertAfter(e);for(let n=0;n<i;n++)e.append(t[n])}l.canBeEmpty()||0!==l.getChildrenSize()||l.remove()}}}))}function U(e,n){const o=new Map,r=e._pendingEditorState;for(const[e,r]of n._nodeMap){const n=t(r);if(s(n)){if(!s(r))throw Error("Expected node be a TextNode");n.__text=r.__text}o.set(e,n)}r&&(r._nodeMap=o),e._dirtyType=2;const l=n._selection;c(null===l?null:l.clone())}function k(e){const t=n()||u();if(o(t)){const{focus:n}=t,o=n.getNode(),r=n.offset;if(f(o)){const t=o.getChildAtIndex(r);null==t?o.append(e):t.insertBefore(e),e.selectNext()}else{let t,n;s(o)?(t=o.getParentOrThrow(),n=o.getIndexWithinParent(),r>0&&(n+=1,o.splitText(r))):(t=o,n=r);const[,l]=a(t,n);l.insertBefore(e),l.selectStart()}}else{if(null!=t){const n=t.getNodes();n[n.length-1].getTopLevelElementOrThrow().insertAfter(e)}else{l().append(e)}const n=d();e.insertAfter(n),n.select()}return e.getLatest()}function F(e,t){const n=t();return e.replace(n),n.append(e),n}function $(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name}function W(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o]);null!==r&&n.push(r)}return n}function V(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function j(e){if(E)return 1;let t=1;for(;e;)t*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return t}export{R as $dfs,W as $filter,I as $findMatchingParent,H as $getNearestBlockElementAncestorOrThrow,D as $getNearestNodeOfType,V as $insertFirst,k as $insertNodeToNearestRoot,U as $restoreEditorState,F as $wrapNodeInElement,v as CAN_USE_BEFORE_INPUT,p as CAN_USE_DOM,x as IS_ANDROID,P as IS_ANDROID_CHROME,m as IS_APPLE,S as IS_APPLE_WEBKIT,N as IS_CHROME,E as IS_FIREFOX,y as IS_IOS,w as IS_SAFARI,B as addClassNamesToElement,j as calculateZoomLevel,K as isMimeType,_ as markSelection,O as mediaFileReader,b as mergeRegister,$ as objectKlassEquals,M as positionNodeOnRange,z as registerNestedElementResolver,C as removeClassNamesFromElement};
8
+
9
+ import{createRectsFromDOMRange as e,$cloneWithProperties as t}from"@lexical/selection";import{$getSelection as n,$isRangeSelection as o,TextNode as r,$getRoot as l,$isElementNode as i,$isTextNode as s,$setSelection as u,$getPreviousSelection as c,$isRootOrShadowRoot as f,$splitNode as a,$createParagraphNode as d}from"lexical";export{$splitNode,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode}from"lexical";function g(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var p=g((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const h="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,m=h&&"documentMode"in document?document.documentMode:null,v=h&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),y=h&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),w=!(!h||!("InputEvent"in window)||m)&&"getTargetRanges"in new window.InputEvent("input"),E=h&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),x=h&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,P=h&&/Android/.test(navigator.userAgent),S=h&&/^(?=.*Chrome).*/i.test(navigator.userAgent),N=h&&P&&S,A=h&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!S;function L(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}function b(...e){return()=>{e.forEach((e=>e()))}}function T(e){return`${e}px`}const M={attributes:!0,characterData:!0,childList:!0,subtree:!0};function _(t,n,o){let r=null,l=null,i=null,s=[];const u=document.createElement("div");function c(){null===r&&p(182),null===l&&p(183);const{left:i,top:c}=r.getBoundingClientRect(),f=l,a=e(t,n);u.isConnected||f.append(u);let d=!1;for(let e=0;e<a.length;e++){const t=a[e],n=s[e]||document.createElement("div"),o=n.style;"absolute"!==o.position&&(o.position="absolute",d=!0);const r=T(t.left-i);o.left!==r&&(o.left=r,d=!0);const l=T(t.top-c);o.top!==l&&(n.style.top=l,d=!0);const f=T(t.width);o.width!==f&&(n.style.width=f,d=!0);const g=T(t.height);o.height!==g&&(n.style.height=g,d=!0),n.parentNode!==u&&(u.append(n),d=!0),s[e]=n}for(;s.length>a.length;)s.pop();d&&o(s)}function f(){l=null,r=null,null!==i&&i.disconnect(),i=null,u.remove();for(const e of s)e.remove();s=[]}const a=t.registerRootListener((function e(){const n=t.getRootElement();if(null===n)return f();const o=n.parentElement;if(!(o instanceof HTMLElement))return f();f(),r=n,l=o,i=new MutationObserver((n=>{const o=t.getRootElement(),i=o&&o.parentElement;if(o!==r||i!==l)return e();for(const e of n)if(!u.contains(e.target))return c()})),i.observe(o,M),c()}));return()=>{a(),f()}}function C(e,t){let l=null,i=null,s=null,u=null,c=()=>{};function f(f){f.read((()=>{const f=n();if(!o(f))return l=null,i=null,s=null,u=null,c(),void(c=()=>{});const{anchor:a,focus:d}=f,g=a.getNode(),h=g.getKey(),m=a.offset,v=d.getNode(),y=v.getKey(),w=d.offset,E=e.getElementByKey(h),x=e.getElementByKey(y),P=null===l||null===E||m!==i||h!==l.getKey()||g!==l&&(!(l instanceof r)||g.updateDOM(l,E,e._config)),S=null===s||null===x||w!==u||y!==s.getKey()||v!==s&&(!(s instanceof r)||v.updateDOM(s,x,e._config));if(P||S){const n=e.getElementByKey(a.getNode().getKey()),o=e.getElementByKey(d.getNode().getKey());if(null!==n&&null!==o&&"SPAN"===n.tagName&&"SPAN"===o.tagName){const r=document.createRange();let l,i,s,u;d.isBefore(a)?(l=o,i=d.offset,s=n,u=a.offset):(l=n,i=a.offset,s=o,u=d.offset);const f=l.firstChild;null===f&&p(181);const g=s.firstChild;null===g&&p(181),r.setStart(f,i),r.setEnd(g,u),c(),c=_(e,r,(e=>{for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),"-1"!==e.zIndex&&(e.zIndex="-1"),"none"!==e.pointerEvents&&(e.pointerEvents="none"),e.marginTop!==T(-1.5)&&(e.marginTop=T(-1.5)),e.paddingTop!==T(4)&&(e.paddingTop=T(4)),e.paddingBottom!==T(0)&&(e.paddingBottom=T(0))}void 0!==t&&t(e)}))}}l=g,i=m,s=v,u=w}))}return f(e.getEditorState()),b(e.registerUpdateListener((({editorState:e})=>f(e))),c,(()=>{c()}))}const B=w,K=h,O=P,R=N,I=v,D=A,H=S,z=y,k=x,F=E;function $(e,...t){const n=L(...t);n.length>0&&e.classList.add(...n)}function U(e,...t){const n=L(...t);n.length>0&&e.classList.remove(...n)}function W(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function j(e,t){const n=e[Symbol.iterator]();return new Promise(((e,o)=>{const r=[],l=()=>{const{done:i,value:s}=n.next();if(i)return e(r);const u=new FileReader;u.addEventListener("error",o),u.addEventListener("load",(()=>{const e=u.result;"string"==typeof e&&r.push({file:s,result:e}),l()})),W(s,t)?u.readAsDataURL(s):l()};l()}))}function V(e,t){const n=[],o=(e||l()).getLatest(),r=t||i(o)&&o.getLastDescendant()||o;let s=o,u=function(e){let t=e,n=0;for(;null!==(t=t.getParent());)n++;return n}(s);for(;null!==s&&!s.is(r);)if(n.push({depth:u,node:s}),i(s)&&s.getChildrenSize()>0)s=s.getFirstChild(),u++;else{let e=null;for(;null===e&&null!==s;)e=s.getNextSibling(),null===e?(s=s.getParent(),u--):s=e}return null!==s&&s.is(r)&&n.push({depth:u,node:s}),n}function q(e){let t=e;if(i(t)&&t.getChildrenSize()>0)t=t.getLastChild();else{let e=null;for(;null===e&&null!==t;)e=t.getPreviousSibling(),t=null===e?t.getParent():e}return t}function G(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null}function J(e){const t=Q(e,(e=>i(e)&&!e.isInline()));return i(t)||p(4,e.__key),t}const Q=(e,t)=>{let n=e;for(;n!==l()&&null!=n;){if(t(n))return n;n=n.getParent()}return null};function X(e,t,n,o){const r=e=>e instanceof t;return e.registerNodeTransform(t,(e=>{const t=(e=>{const t=e.getChildren();for(let e=0;e<t.length;e++){const n=t[e];if(r(n))return null}let n=e,o=e;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return{child:o,parent:n};return null})(e);if(null!==t){const{child:r,parent:l}=t;if(r.is(e)){o(l,e);const t=r.getNextSiblings(),i=t.length;if(l.insertAfter(r),0!==i){const e=n(l);r.insertAfter(e);for(let n=0;n<i;n++)e.append(t[n])}l.canBeEmpty()||0!==l.getChildrenSize()||l.remove()}}}))}function Y(e,n){const o=new Map,r=e._pendingEditorState;for(const[e,r]of n._nodeMap){const n=t(r);s(n)&&(s(r)||p(180),n.__text=r.__text),o.set(e,n)}r&&(r._nodeMap=o),e._dirtyType=2;const l=n._selection;u(null===l?null:l.clone())}function Z(e){const t=n()||c();if(o(t)){const{focus:n}=t,o=n.getNode(),r=n.offset;if(f(o)){const t=o.getChildAtIndex(r);null==t?o.append(e):t.insertBefore(e),e.selectNext()}else{let t,n;s(o)?(t=o.getParentOrThrow(),n=o.getIndexWithinParent(),r>0&&(n+=1,o.splitText(r))):(t=o,n=r);const[,l]=a(t,n);l.insertBefore(e),l.selectStart()}}else{if(null!=t){const n=t.getNodes();n[n.length-1].getTopLevelElementOrThrow().insertAfter(e)}else{l().append(e)}const n=d();e.insertAfter(n),n.select()}return e.getLatest()}function ee(e,t){const n=t();return e.replace(n),n.append(e),n}function te(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name}function ne(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o]);null!==r&&n.push(r)}return n}function oe(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function re(e){if(z)return 1;let t=1;for(;e;)t*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return t}export{V as $dfs,ne as $filter,Q as $findMatchingParent,J as $getNearestBlockElementAncestorOrThrow,G as $getNearestNodeOfType,q as $getNextRightPreorderNode,oe as $insertFirst,Z as $insertNodeToNearestRoot,Y as $restoreEditorState,ee as $wrapNodeInElement,B as CAN_USE_BEFORE_INPUT,K as CAN_USE_DOM,O as IS_ANDROID,R as IS_ANDROID_CHROME,I as IS_APPLE,D as IS_APPLE_WEBKIT,H as IS_CHROME,z as IS_FIREFOX,k as IS_IOS,F as IS_SAFARI,$ as addClassNamesToElement,re as calculateZoomLevel,W as isMimeType,C as markSelection,j as mediaFileReader,b as mergeRegister,te as objectKlassEquals,_ as positionNodeOnRange,X as registerNestedElementResolver,U as removeClassNamesFromElement};
package/index.d.ts CHANGED
@@ -9,9 +9,17 @@ import { EditorState, ElementNode, Klass, LexicalEditor, LexicalNode } from 'lex
9
9
  export { default as markSelection } from './markSelection';
10
10
  export { default as mergeRegister } from './mergeRegister';
11
11
  export { default as positionNodeOnRange } from './positionNodeOnRange';
12
- export { $splitNode, isHTMLAnchorElement, isHTMLElement } from 'lexical';
13
- export { CAN_USE_DOM } from 'shared/canUseDOM';
14
- export { CAN_USE_BEFORE_INPUT, IS_ANDROID, IS_ANDROID_CHROME, IS_APPLE, IS_APPLE_WEBKIT, IS_CHROME, IS_FIREFOX, IS_IOS, IS_SAFARI, } from 'shared/environment';
12
+ export { $splitNode, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, } from 'lexical';
13
+ export declare const CAN_USE_BEFORE_INPUT: boolean;
14
+ export declare const CAN_USE_DOM: boolean;
15
+ export declare const IS_ANDROID: boolean;
16
+ export declare const IS_ANDROID_CHROME: boolean;
17
+ export declare const IS_APPLE: boolean;
18
+ export declare const IS_APPLE_WEBKIT: boolean;
19
+ export declare const IS_CHROME: boolean;
20
+ export declare const IS_FIREFOX: boolean;
21
+ export declare const IS_IOS: boolean;
22
+ export declare const IS_SAFARI: boolean;
15
23
  export type DFSNode = Readonly<{
16
24
  depth: number;
17
25
  node: LexicalNode;
@@ -69,6 +77,15 @@ export declare function mediaFileReader(files: Array<File>, acceptableMimeTypes:
69
77
  * {depth: number, node: LexicalNode} It will always return at least 1 node (the ending node) so long as it exists
70
78
  */
71
79
  export declare function $dfs(startingNode?: LexicalNode, endingNode?: LexicalNode): Array<DFSNode>;
80
+ /**
81
+ * Performs a right-to-left preorder tree traversal.
82
+ * From the starting node it goes to the rightmost child, than backtracks to paret and finds new rightmost path.
83
+ * It will return the next node in traversal sequence after the startingNode.
84
+ * The traversal is similar to $dfs functions above, but the nodes are visited right-to-left, not left-to-right.
85
+ * @param startingNode - The node to start the search.
86
+ * @returns The next node in pre-order right to left traversal sequence or `null`, if the node does not exist
87
+ */
88
+ export declare function $getNextRightPreorderNode(startingNode: LexicalNode): LexicalNode | null;
72
89
  /**
73
90
  * Takes a node and traverses up its ancestors (toward the root node)
74
91
  * in order to find a specific type of node.
package/package.json CHANGED
@@ -8,14 +8,14 @@
8
8
  "utils"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.14.5",
11
+ "version": "0.15.0",
12
12
  "main": "LexicalUtils.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/list": "0.14.5",
16
- "@lexical/selection": "0.14.5",
17
- "@lexical/table": "0.14.5",
18
- "lexical": "0.14.5"
15
+ "@lexical/list": "0.15.0",
16
+ "@lexical/selection": "0.15.0",
17
+ "@lexical/table": "0.15.0",
18
+ "lexical": "0.15.0"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",