@lexical/utils 0.14.2 → 0.14.4
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.
- package/LexicalUtils.dev.js +68 -1
- package/{LexicalUtils.dev.esm.js → LexicalUtils.dev.mjs} +58 -2
- package/{LexicalUtils.esm.js → LexicalUtils.mjs} +13 -2
- package/LexicalUtils.node.mjs +39 -0
- package/LexicalUtils.prod.js +18 -16
- package/LexicalUtils.prod.mjs +7 -0
- package/index.d.ts +8 -1
- package/package.json +25 -9
- package/LexicalUtils.prod.esm.js +0 -7
package/LexicalUtils.dev.js
CHANGED
|
@@ -9,6 +9,39 @@
|
|
|
9
9
|
var selection = require('@lexical/selection');
|
|
10
10
|
var lexical = require('lexical');
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
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
|
+
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);
|
|
36
|
+
|
|
37
|
+
// Keep these in case we need to use them in the future.
|
|
38
|
+
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
39
|
+
const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
40
|
+
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
41
|
+
|
|
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;
|
|
44
|
+
|
|
12
45
|
/**
|
|
13
46
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
47
|
*
|
|
@@ -321,7 +354,13 @@ function markSelection(editor, onReposition) {
|
|
|
321
354
|
});
|
|
322
355
|
}
|
|
323
356
|
|
|
324
|
-
/**
|
|
357
|
+
/**
|
|
358
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
359
|
+
*
|
|
360
|
+
* This source code is licensed under the MIT license found in the
|
|
361
|
+
* LICENSE file in the root directory of this source tree.
|
|
362
|
+
*
|
|
363
|
+
*/
|
|
325
364
|
/**
|
|
326
365
|
* Takes an HTML element and adds the classNames passed within an array,
|
|
327
366
|
* ignoring any non-string types. A space can be used to add multiple classes
|
|
@@ -728,6 +767,23 @@ function $insertFirst(parent, node) {
|
|
|
728
767
|
}
|
|
729
768
|
}
|
|
730
769
|
|
|
770
|
+
/**
|
|
771
|
+
* Calculates the zoom level of an element as a result of using
|
|
772
|
+
* css zoom property.
|
|
773
|
+
* @param element
|
|
774
|
+
*/
|
|
775
|
+
function calculateZoomLevel(element) {
|
|
776
|
+
if (IS_FIREFOX) {
|
|
777
|
+
return 1;
|
|
778
|
+
}
|
|
779
|
+
let zoom = 1;
|
|
780
|
+
while (element) {
|
|
781
|
+
zoom *= Number(window.getComputedStyle(element).getPropertyValue('zoom'));
|
|
782
|
+
element = element.parentElement;
|
|
783
|
+
}
|
|
784
|
+
return zoom;
|
|
785
|
+
}
|
|
786
|
+
|
|
731
787
|
exports.$splitNode = lexical.$splitNode;
|
|
732
788
|
exports.isHTMLAnchorElement = lexical.isHTMLAnchorElement;
|
|
733
789
|
exports.isHTMLElement = lexical.isHTMLElement;
|
|
@@ -740,7 +796,18 @@ exports.$insertFirst = $insertFirst;
|
|
|
740
796
|
exports.$insertNodeToNearestRoot = $insertNodeToNearestRoot;
|
|
741
797
|
exports.$restoreEditorState = $restoreEditorState;
|
|
742
798
|
exports.$wrapNodeInElement = $wrapNodeInElement;
|
|
799
|
+
exports.CAN_USE_BEFORE_INPUT = CAN_USE_BEFORE_INPUT;
|
|
800
|
+
exports.CAN_USE_DOM = CAN_USE_DOM;
|
|
801
|
+
exports.IS_ANDROID = IS_ANDROID;
|
|
802
|
+
exports.IS_ANDROID_CHROME = IS_ANDROID_CHROME;
|
|
803
|
+
exports.IS_APPLE = IS_APPLE;
|
|
804
|
+
exports.IS_APPLE_WEBKIT = IS_APPLE_WEBKIT;
|
|
805
|
+
exports.IS_CHROME = IS_CHROME;
|
|
806
|
+
exports.IS_FIREFOX = IS_FIREFOX;
|
|
807
|
+
exports.IS_IOS = IS_IOS;
|
|
808
|
+
exports.IS_SAFARI = IS_SAFARI;
|
|
743
809
|
exports.addClassNamesToElement = addClassNamesToElement;
|
|
810
|
+
exports.calculateZoomLevel = calculateZoomLevel;
|
|
744
811
|
exports.isMimeType = isMimeType;
|
|
745
812
|
exports.markSelection = markSelection;
|
|
746
813
|
exports.mediaFileReader = mediaFileReader;
|
|
@@ -8,6 +8,39 @@ import { createRectsFromDOMRange, $cloneWithProperties } from '@lexical/selectio
|
|
|
8
8
|
import { $getSelection, $isRangeSelection, TextNode, $getRoot, $isElementNode, $isTextNode, $setSelection, $getPreviousSelection, $isRootOrShadowRoot, $splitNode, $createParagraphNode } from 'lexical';
|
|
9
9
|
export { $splitNode, isHTMLAnchorElement, isHTMLElement } from 'lexical';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the MIT license found in the
|
|
15
|
+
* LICENSE file in the root directory of this source tree.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the MIT license found in the
|
|
25
|
+
* LICENSE file in the root directory of this source tree.
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
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);
|
|
35
|
+
|
|
36
|
+
// Keep these in case we need to use them in the future.
|
|
37
|
+
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
38
|
+
const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
39
|
+
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
40
|
+
|
|
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;
|
|
43
|
+
|
|
11
44
|
/**
|
|
12
45
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
46
|
*
|
|
@@ -320,7 +353,13 @@ function markSelection(editor, onReposition) {
|
|
|
320
353
|
});
|
|
321
354
|
}
|
|
322
355
|
|
|
323
|
-
/**
|
|
356
|
+
/**
|
|
357
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
358
|
+
*
|
|
359
|
+
* This source code is licensed under the MIT license found in the
|
|
360
|
+
* LICENSE file in the root directory of this source tree.
|
|
361
|
+
*
|
|
362
|
+
*/
|
|
324
363
|
/**
|
|
325
364
|
* Takes an HTML element and adds the classNames passed within an array,
|
|
326
365
|
* ignoring any non-string types. A space can be used to add multiple classes
|
|
@@ -727,4 +766,21 @@ function $insertFirst(parent, node) {
|
|
|
727
766
|
}
|
|
728
767
|
}
|
|
729
768
|
|
|
730
|
-
|
|
769
|
+
/**
|
|
770
|
+
* Calculates the zoom level of an element as a result of using
|
|
771
|
+
* css zoom property.
|
|
772
|
+
* @param element
|
|
773
|
+
*/
|
|
774
|
+
function calculateZoomLevel(element) {
|
|
775
|
+
if (IS_FIREFOX) {
|
|
776
|
+
return 1;
|
|
777
|
+
}
|
|
778
|
+
let zoom = 1;
|
|
779
|
+
while (element) {
|
|
780
|
+
zoom *= Number(window.getComputedStyle(element).getPropertyValue('zoom'));
|
|
781
|
+
element = element.parentElement;
|
|
782
|
+
}
|
|
783
|
+
return zoom;
|
|
784
|
+
}
|
|
785
|
+
|
|
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 };
|
|
@@ -4,8 +4,8 @@
|
|
|
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
|
-
import * as modDev from './LexicalUtils.dev.
|
|
8
|
-
import * as modProd from './LexicalUtils.prod.
|
|
7
|
+
import * as modDev from './LexicalUtils.dev.mjs';
|
|
8
|
+
import * as modProd from './LexicalUtils.prod.mjs';
|
|
9
9
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
10
|
export const $dfs = mod.$dfs;
|
|
11
11
|
export const $filter = mod.$filter;
|
|
@@ -17,7 +17,18 @@ export const $insertNodeToNearestRoot = mod.$insertNodeToNearestRoot;
|
|
|
17
17
|
export const $restoreEditorState = mod.$restoreEditorState;
|
|
18
18
|
export const $splitNode = mod.$splitNode;
|
|
19
19
|
export const $wrapNodeInElement = mod.$wrapNodeInElement;
|
|
20
|
+
export const CAN_USE_BEFORE_INPUT = mod.CAN_USE_BEFORE_INPUT;
|
|
21
|
+
export const CAN_USE_DOM = mod.CAN_USE_DOM;
|
|
22
|
+
export const IS_ANDROID = mod.IS_ANDROID;
|
|
23
|
+
export const IS_ANDROID_CHROME = mod.IS_ANDROID_CHROME;
|
|
24
|
+
export const IS_APPLE = mod.IS_APPLE;
|
|
25
|
+
export const IS_APPLE_WEBKIT = mod.IS_APPLE_WEBKIT;
|
|
26
|
+
export const IS_CHROME = mod.IS_CHROME;
|
|
27
|
+
export const IS_FIREFOX = mod.IS_FIREFOX;
|
|
28
|
+
export const IS_IOS = mod.IS_IOS;
|
|
29
|
+
export const IS_SAFARI = mod.IS_SAFARI;
|
|
20
30
|
export const addClassNamesToElement = mod.addClassNamesToElement;
|
|
31
|
+
export const calculateZoomLevel = mod.calculateZoomLevel;
|
|
21
32
|
export const isHTMLAnchorElement = mod.isHTMLAnchorElement;
|
|
22
33
|
export const isHTMLElement = mod.isHTMLElement;
|
|
23
34
|
export const isMimeType = mod.isMimeType;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalUtils.dev.mjs') : import('./LexicalUtils.prod.mjs'));
|
|
8
|
+
export const $dfs = mod.$dfs;
|
|
9
|
+
export const $filter = mod.$filter;
|
|
10
|
+
export const $findMatchingParent = mod.$findMatchingParent;
|
|
11
|
+
export const $getNearestBlockElementAncestorOrThrow = mod.$getNearestBlockElementAncestorOrThrow;
|
|
12
|
+
export const $getNearestNodeOfType = mod.$getNearestNodeOfType;
|
|
13
|
+
export const $insertFirst = mod.$insertFirst;
|
|
14
|
+
export const $insertNodeToNearestRoot = mod.$insertNodeToNearestRoot;
|
|
15
|
+
export const $restoreEditorState = mod.$restoreEditorState;
|
|
16
|
+
export const $splitNode = mod.$splitNode;
|
|
17
|
+
export const $wrapNodeInElement = mod.$wrapNodeInElement;
|
|
18
|
+
export const CAN_USE_BEFORE_INPUT = mod.CAN_USE_BEFORE_INPUT;
|
|
19
|
+
export const CAN_USE_DOM = mod.CAN_USE_DOM;
|
|
20
|
+
export const IS_ANDROID = mod.IS_ANDROID;
|
|
21
|
+
export const IS_ANDROID_CHROME = mod.IS_ANDROID_CHROME;
|
|
22
|
+
export const IS_APPLE = mod.IS_APPLE;
|
|
23
|
+
export const IS_APPLE_WEBKIT = mod.IS_APPLE_WEBKIT;
|
|
24
|
+
export const IS_CHROME = mod.IS_CHROME;
|
|
25
|
+
export const IS_FIREFOX = mod.IS_FIREFOX;
|
|
26
|
+
export const IS_IOS = mod.IS_IOS;
|
|
27
|
+
export const IS_SAFARI = mod.IS_SAFARI;
|
|
28
|
+
export const addClassNamesToElement = mod.addClassNamesToElement;
|
|
29
|
+
export const calculateZoomLevel = mod.calculateZoomLevel;
|
|
30
|
+
export const isHTMLAnchorElement = mod.isHTMLAnchorElement;
|
|
31
|
+
export const isHTMLElement = mod.isHTMLElement;
|
|
32
|
+
export const isMimeType = mod.isMimeType;
|
|
33
|
+
export const markSelection = mod.markSelection;
|
|
34
|
+
export const mediaFileReader = mod.mediaFileReader;
|
|
35
|
+
export const mergeRegister = mod.mergeRegister;
|
|
36
|
+
export const objectKlassEquals = mod.objectKlassEquals;
|
|
37
|
+
export const positionNodeOnRange = mod.positionNodeOnRange;
|
|
38
|
+
export const registerNestedElementResolver = mod.registerNestedElementResolver;
|
|
39
|
+
export const removeClassNamesFromElement = mod.removeClassNamesFromElement;
|
package/LexicalUtils.prod.js
CHANGED
|
@@ -4,20 +4,22 @@
|
|
|
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
|
-
'use strict';var h=require("@lexical/selection"),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.$
|
|
14
|
-
exports.$
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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)};
|
|
15
|
+
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};
|
|
23
|
+
exports.positionNodeOnRange=R;
|
|
22
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()}}})};
|
|
23
|
-
exports.removeClassNamesFromElement=function(a,...b){b=
|
|
25
|
+
exports.removeClassNamesFromElement=function(a,...b){b=O(...b);0<b.length&&a.classList.remove(...b)}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
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};
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** @module @lexical/utils */
|
|
2
1
|
/**
|
|
3
2
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
3
|
*
|
|
@@ -11,6 +10,8 @@ export { default as markSelection } from './markSelection';
|
|
|
11
10
|
export { default as mergeRegister } from './mergeRegister';
|
|
12
11
|
export { default as positionNodeOnRange } from './positionNodeOnRange';
|
|
13
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';
|
|
14
15
|
export type DFSNode = Readonly<{
|
|
15
16
|
depth: number;
|
|
16
17
|
node: LexicalNode;
|
|
@@ -149,3 +150,9 @@ export declare function $filter<T>(nodes: Array<LexicalNode>, filterFn: (node: L
|
|
|
149
150
|
* @param node Node that needs to be appended
|
|
150
151
|
*/
|
|
151
152
|
export declare function $insertFirst(parent: ElementNode, node: LexicalNode): void;
|
|
153
|
+
/**
|
|
154
|
+
* Calculates the zoom level of an element as a result of using
|
|
155
|
+
* css zoom property.
|
|
156
|
+
* @param element
|
|
157
|
+
*/
|
|
158
|
+
export declare function calculateZoomLevel(element: Element | null): number;
|
package/package.json
CHANGED
|
@@ -8,21 +8,37 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.14.
|
|
11
|
+
"version": "0.14.4",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
|
-
"
|
|
14
|
-
"lexical": "0.14.2"
|
|
15
|
-
},
|
|
13
|
+
"types": "index.d.ts",
|
|
16
14
|
"dependencies": {
|
|
17
|
-
"@lexical/list": "0.14.
|
|
18
|
-
"@lexical/
|
|
19
|
-
"@lexical/
|
|
15
|
+
"@lexical/list": "0.14.4",
|
|
16
|
+
"@lexical/selection": "0.14.4",
|
|
17
|
+
"@lexical/table": "0.14.4",
|
|
18
|
+
"lexical": "0.14.4"
|
|
20
19
|
},
|
|
21
20
|
"repository": {
|
|
22
21
|
"type": "git",
|
|
23
22
|
"url": "https://github.com/facebook/lexical",
|
|
24
23
|
"directory": "packages/lexical-utils"
|
|
25
24
|
},
|
|
26
|
-
"module": "LexicalUtils.
|
|
27
|
-
"sideEffects": false
|
|
25
|
+
"module": "LexicalUtils.mjs",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./index.d.ts",
|
|
31
|
+
"development": "./LexicalUtils.dev.mjs",
|
|
32
|
+
"production": "./LexicalUtils.prod.mjs",
|
|
33
|
+
"node": "./LexicalUtils.node.mjs",
|
|
34
|
+
"default": "./LexicalUtils.mjs"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./index.d.ts",
|
|
38
|
+
"development": "./LexicalUtils.dev.js",
|
|
39
|
+
"production": "./LexicalUtils.prod.js",
|
|
40
|
+
"default": "./LexicalUtils.js"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
28
44
|
}
|
package/LexicalUtils.prod.esm.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import{createRectsFromDOMRange as t,$cloneWithProperties as e}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 f,$isRootOrShadowRoot as u,$splitNode as a,$createParagraphNode as d}from"lexical";export{$splitNode,isHTMLAnchorElement,isHTMLElement}from"lexical";var g=function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};function p(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}function h(...t){return()=>{t.forEach((t=>t()))}}function m(t){return`${t}px`}const E={attributes:!0,characterData:!0,childList:!0,subtree:!0};function x(e,n,o){let r=null,l=null,i=null,s=[];const c=document.createElement("div");function f(){if(null===r)throw Error("Unexpected null rootDOMNode");if(null===l)throw Error("Unexpected null parentDOMNode");const{left:i,top:f}=r.getBoundingClientRect(),u=l,a=t(e,n);c.isConnected||u.append(c);let d=!1;for(let t=0;t<a.length;t++){const e=a[t],n=s[t]||document.createElement("div"),o=n.style;"absolute"!==o.position&&(o.position="absolute",d=!0);const r=m(e.left-i);o.left!==r&&(o.left=r,d=!0);const l=m(e.top-f);o.top!==l&&(n.style.top=l,d=!0);const u=m(e.width);o.width!==u&&(n.style.width=u,d=!0);const g=m(e.height);o.height!==g&&(n.style.height=g,d=!0),n.parentNode!==c&&(c.append(n),d=!0),s[t]=n}for(;s.length>a.length;)s.pop();d&&o(s)}function u(){l=null,r=null,null!==i&&i.disconnect(),i=null,c.remove();for(const t of s)t.remove();s=[]}const a=e.registerRootListener((function t(){const n=e.getRootElement();if(null===n)return u();const o=n.parentElement;if(!(o instanceof HTMLElement))return u();u(),r=n,l=o,i=new MutationObserver((n=>{const o=e.getRootElement(),i=o&&o.parentElement;if(o!==r||i!==l)return t();for(const t of n)if(!c.contains(t.target))return f()})),i.observe(o,E),f()}));return()=>{a(),u()}}function y(t,e){let l=null,i=null,s=null,c=null,f=()=>{};function u(u){u.read((()=>{const u=n();if(!o(u))return l=null,i=null,s=null,c=null,f(),void(f=()=>{});const{anchor:a,focus:d}=u,g=a.getNode(),p=g.getKey(),h=a.offset,E=d.getNode(),y=E.getKey(),v=d.offset,N=t.getElementByKey(p),w=t.getElementByKey(y),L=null===l||null===N||h!==i||p!==l.getKey()||g!==l&&(!(l instanceof r)||g.updateDOM(l,N,t._config)),T=null===s||null===w||v!==c||y!==s.getKey()||E!==s&&(!(s instanceof r)||E.updateDOM(s,w,t._config));if(L||T){const n=t.getElementByKey(a.getNode().getKey()),o=t.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 u=l.firstChild;if(null===u)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(u,i),r.setEnd(g,c),f(),f=x(t,r,(t=>{for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),"-1"!==t.zIndex&&(t.zIndex="-1"),"none"!==t.pointerEvents&&(t.pointerEvents="none"),t.marginTop!==m(-1.5)&&(t.marginTop=m(-1.5)),t.paddingTop!==m(4)&&(t.paddingTop=m(4)),t.paddingBottom!==m(0)&&(t.paddingBottom=m(0))}void 0!==e&&e(t)}))}}l=g,i=h,s=E,c=v}))}return u(t.getEditorState()),h(t.registerUpdateListener((({editorState:t})=>u(t))),f,(()=>{f()}))}function v(t,...e){const n=p(...e);n.length>0&&t.classList.add(...n)}function N(t,...e){const n=p(...e);n.length>0&&t.classList.remove(...n)}function w(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function L(t,e){const n=t[Symbol.iterator]();return new Promise(((t,o)=>{const r=[],l=()=>{const{done:i,value:s}=n.next();if(i)return t(r);const c=new FileReader;c.addEventListener("error",o),c.addEventListener("load",(()=>{const t=c.result;"string"==typeof t&&r.push({file:s,result:t}),l()})),w(s,e)?c.readAsDataURL(s):l()};l()}))}function T(t,e){const n=[],o=(t||l()).getLatest(),r=e||(i(o)?o.getLastDescendant():o);let s=o,c=function(t){let e=t,n=0;for(;null!==(e=e.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 t=null;for(;null===t&&null!==s;)t=s.getNextSibling(),null===t?(s=s.getParent(),c--):s=t}return null!==s&&s.is(r)&&n.push({depth:c,node:s}),n}function b(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function S(t){const e=_(t,(t=>i(t)&&!t.isInline()));return i(e)||g(4,t.__key),e}const _=(t,e)=>{let n=t;for(;n!==l()&&null!=n;){if(e(n))return n;n=n.getParent()}return null};function B(t,e,n,o){const r=t=>t instanceof e;return t.registerNodeTransform(e,(t=>{const e=(t=>{const e=t.getChildren();for(let t=0;t<e.length;t++){const n=e[t];if(r(n))return null}let n=t,o=t;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return{child:o,parent:n};return null})(t);if(null!==e){const{child:r,parent:l}=e;if(r.is(t)){o(l,t);const e=r.getNextSiblings(),i=e.length;if(l.insertAfter(r),0!==i){const t=n(l);r.insertAfter(t);for(let n=0;n<i;n++)t.append(e[n])}l.canBeEmpty()||0!==l.getChildrenSize()||l.remove()}}}))}function M(t,n){const o=new Map,r=t._pendingEditorState;for(const[t,r]of n._nodeMap){const n=e(r);if(s(n)){if(!s(r))throw Error("Expected node be a TextNode");n.__text=r.__text}o.set(t,n)}r&&(r._nodeMap=o),t._dirtyType=2;const l=n._selection;c(null===l?null:l.clone())}function P(t){const e=n()||f();if(o(e)){const{focus:n}=e,o=n.getNode(),r=n.offset;if(u(o)){const e=o.getChildAtIndex(r);null==e?o.append(t):e.insertBefore(t),t.selectNext()}else{let e,n;s(o)?(e=o.getParentOrThrow(),n=o.getIndexWithinParent(),r>0&&(n+=1,o.splitText(r))):(e=o,n=r);const[,l]=a(e,n);l.insertBefore(t),l.selectStart()}}else{if(null!=e){const n=e.getNodes();n[n.length-1].getTopLevelElementOrThrow().insertAfter(t)}else{l().append(t)}const n=d();t.insertAfter(n),n.select()}return t.getLatest()}function A(t,e){const n=e();return t.replace(n),n.append(t),n}function C(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function K(t,e){const n=[];for(let o=0;o<t.length;o++){const r=e(t[o]);null!==r&&n.push(r)}return n}function O(t,e){const n=t.getFirstChild();null!==n?n.insertBefore(e):t.append(e)}export{T as $dfs,K as $filter,_ as $findMatchingParent,S as $getNearestBlockElementAncestorOrThrow,b as $getNearestNodeOfType,O as $insertFirst,P as $insertNodeToNearestRoot,M as $restoreEditorState,A as $wrapNodeInElement,v as addClassNamesToElement,w as isMimeType,y as markSelection,L as mediaFileReader,h as mergeRegister,C as objectKlassEquals,x as positionNodeOnRange,B as registerNestedElementResolver,N as removeClassNamesFromElement};
|