@lexical/utils 0.14.3 → 0.14.5
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 +23 -7
- package/LexicalUtils.dev.mjs +14 -8
- package/LexicalUtils.mjs +10 -0
- package/LexicalUtils.node.mjs +10 -0
- package/LexicalUtils.prod.js +18 -17
- package/LexicalUtils.prod.mjs +1 -1
- package/index.d.ts +2 -1
- package/package.json +9 -5
package/LexicalUtils.dev.js
CHANGED
|
@@ -27,11 +27,11 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
29
|
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
30
|
-
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
30
|
+
const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
31
31
|
const IS_FIREFOX = CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
32
|
-
CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
|
|
33
|
-
CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
34
|
-
CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
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
35
|
const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
|
|
36
36
|
|
|
37
37
|
// Keep these in case we need to use them in the future.
|
|
@@ -39,8 +39,8 @@ const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
|
|
|
39
39
|
const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
40
40
|
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
41
41
|
|
|
42
|
-
CAN_USE_DOM && IS_ANDROID && IS_CHROME;
|
|
43
|
-
CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
|
|
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
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -354,7 +354,13 @@ function markSelection(editor, onReposition) {
|
|
|
354
354
|
});
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
/**
|
|
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
|
+
*/
|
|
358
364
|
/**
|
|
359
365
|
* Takes an HTML element and adds the classNames passed within an array,
|
|
360
366
|
* ignoring any non-string types. A space can be used to add multiple classes
|
|
@@ -790,6 +796,16 @@ exports.$insertFirst = $insertFirst;
|
|
|
790
796
|
exports.$insertNodeToNearestRoot = $insertNodeToNearestRoot;
|
|
791
797
|
exports.$restoreEditorState = $restoreEditorState;
|
|
792
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;
|
|
793
809
|
exports.addClassNamesToElement = addClassNamesToElement;
|
|
794
810
|
exports.calculateZoomLevel = calculateZoomLevel;
|
|
795
811
|
exports.isMimeType = isMimeType;
|
package/LexicalUtils.dev.mjs
CHANGED
|
@@ -26,11 +26,11 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
28
|
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
29
|
-
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
29
|
+
const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
30
30
|
const IS_FIREFOX = CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
31
|
-
CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
|
|
32
|
-
CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
33
|
-
CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
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
34
|
const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
|
|
35
35
|
|
|
36
36
|
// Keep these in case we need to use them in the future.
|
|
@@ -38,8 +38,8 @@ const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
|
|
|
38
38
|
const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
39
39
|
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
40
40
|
|
|
41
|
-
CAN_USE_DOM && IS_ANDROID && IS_CHROME;
|
|
42
|
-
CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
|
|
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
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -353,7 +353,13 @@ function markSelection(editor, onReposition) {
|
|
|
353
353
|
});
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
/**
|
|
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
|
+
*/
|
|
357
363
|
/**
|
|
358
364
|
* Takes an HTML element and adds the classNames passed within an array,
|
|
359
365
|
* ignoring any non-string types. A space can be used to add multiple classes
|
|
@@ -777,4 +783,4 @@ function calculateZoomLevel(element) {
|
|
|
777
783
|
return zoom;
|
|
778
784
|
}
|
|
779
785
|
|
|
780
|
-
export { $dfs, $filter, $findMatchingParent, $getNearestBlockElementAncestorOrThrow, $getNearestNodeOfType, $insertFirst, $insertNodeToNearestRoot, $restoreEditorState, $wrapNodeInElement, addClassNamesToElement, calculateZoomLevel, isMimeType, markSelection, mediaFileReader, mergeRegister, objectKlassEquals, positionNodeOnRange, registerNestedElementResolver, removeClassNamesFromElement };
|
|
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 };
|
package/LexicalUtils.mjs
CHANGED
|
@@ -17,6 +17,16 @@ 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;
|
|
21
31
|
export const calculateZoomLevel = mod.calculateZoomLevel;
|
|
22
32
|
export const isHTMLAnchorElement = mod.isHTMLAnchorElement;
|
package/LexicalUtils.node.mjs
CHANGED
|
@@ -15,6 +15,16 @@ export const $insertNodeToNearestRoot = mod.$insertNodeToNearestRoot;
|
|
|
15
15
|
export const $restoreEditorState = mod.$restoreEditorState;
|
|
16
16
|
export const $splitNode = mod.$splitNode;
|
|
17
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;
|
|
18
28
|
export const addClassNamesToElement = mod.addClassNamesToElement;
|
|
19
29
|
export const calculateZoomLevel = mod.calculateZoomLevel;
|
|
20
30
|
export const isHTMLAnchorElement = mod.isHTMLAnchorElement;
|
package/LexicalUtils.prod.js
CHANGED
|
@@ -4,21 +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
|
-
let D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,E=D&&"documentMode"in document?document.documentMode:null
|
|
9
|
-
|
|
10
|
-
function
|
|
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[
|
|
12
|
-
if(r!==g||w!==n)return f();for(let l of q)if(!t.contains(l.target))return e()});m.observe(A,
|
|
13
|
-
exports.$dfs=function(a,b){let c=[];a=(a||
|
|
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=
|
|
15
|
-
exports.$insertNodeToNearestRoot=function(a){var b=
|
|
16
|
-
|
|
17
|
-
exports.$wrapNodeInElement=function(a,b){b=b();a.replace(b);b.append(a);return b};exports.addClassNamesToElement=function(a,...b){b=
|
|
18
|
-
exports.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
exports.
|
|
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;
|
|
23
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()}}})};
|
|
24
|
-
exports.removeClassNamesFromElement=function(a,...b){b=
|
|
25
|
+
exports.removeClassNamesFromElement=function(a,...b){b=O(...b);0<b.length&&a.classList.remove(...b)}
|
package/LexicalUtils.prod.mjs
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
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
|
|
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;
|
package/package.json
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.14.
|
|
11
|
+
"version": "0.14.5",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/list": "0.14.
|
|
16
|
-
"@lexical/selection": "0.14.
|
|
17
|
-
"@lexical/table": "0.14.
|
|
18
|
-
"lexical": "0.14.
|
|
15
|
+
"@lexical/list": "0.14.5",
|
|
16
|
+
"@lexical/selection": "0.14.5",
|
|
17
|
+
"@lexical/table": "0.14.5",
|
|
18
|
+
"lexical": "0.14.5"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
@@ -28,11 +28,15 @@
|
|
|
28
28
|
".": {
|
|
29
29
|
"import": {
|
|
30
30
|
"types": "./index.d.ts",
|
|
31
|
+
"development": "./LexicalUtils.dev.mjs",
|
|
32
|
+
"production": "./LexicalUtils.prod.mjs",
|
|
31
33
|
"node": "./LexicalUtils.node.mjs",
|
|
32
34
|
"default": "./LexicalUtils.mjs"
|
|
33
35
|
},
|
|
34
36
|
"require": {
|
|
35
37
|
"types": "./index.d.ts",
|
|
38
|
+
"development": "./LexicalUtils.dev.js",
|
|
39
|
+
"production": "./LexicalUtils.prod.js",
|
|
36
40
|
"default": "./LexicalUtils.js"
|
|
37
41
|
}
|
|
38
42
|
}
|