@lexical/utils 0.16.0 → 0.16.1-nightly.20240610.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.
- package/LexicalUtils.dev.js +11 -4
- package/LexicalUtils.dev.mjs +11 -4
- package/LexicalUtils.prod.js +1 -1
- package/LexicalUtils.prod.mjs +1 -1
- package/mergeRegister.d.ts +6 -3
- package/package.json +5 -5
package/LexicalUtils.dev.js
CHANGED
|
@@ -90,14 +90,21 @@ function normalizeClassNames(...classNames) {
|
|
|
90
90
|
* In this case, useEffect is returning the function returned by mergeRegister as a cleanup
|
|
91
91
|
* function to be executed after either the useEffect runs again (due to one of its dependencies
|
|
92
92
|
* updating) or the component it resides in unmounts.
|
|
93
|
-
* Note the functions don't neccesarily need to be in an array as all
|
|
93
|
+
* Note the functions don't neccesarily need to be in an array as all arguments
|
|
94
94
|
* are considered to be the func argument and spread from there.
|
|
95
|
-
*
|
|
96
|
-
*
|
|
95
|
+
* The order of cleanup is the reverse of the argument order. Generally it is
|
|
96
|
+
* expected that the first "acquire" will be "released" last (LIFO order),
|
|
97
|
+
* because a later step may have some dependency on an earlier one.
|
|
98
|
+
* @param func - An array of cleanup functions meant to be executed by the returned function.
|
|
99
|
+
* @returns the function which executes all the passed cleanup functions.
|
|
97
100
|
*/
|
|
98
101
|
function mergeRegister(...func) {
|
|
99
102
|
return () => {
|
|
100
|
-
func.
|
|
103
|
+
for (let i = func.length - 1; i >= 0; i--) {
|
|
104
|
+
func[i]();
|
|
105
|
+
}
|
|
106
|
+
// Clean up the references and make future calls a no-op
|
|
107
|
+
func.length = 0;
|
|
101
108
|
};
|
|
102
109
|
}
|
|
103
110
|
|
package/LexicalUtils.dev.mjs
CHANGED
|
@@ -89,14 +89,21 @@ function normalizeClassNames(...classNames) {
|
|
|
89
89
|
* In this case, useEffect is returning the function returned by mergeRegister as a cleanup
|
|
90
90
|
* function to be executed after either the useEffect runs again (due to one of its dependencies
|
|
91
91
|
* updating) or the component it resides in unmounts.
|
|
92
|
-
* Note the functions don't neccesarily need to be in an array as all
|
|
92
|
+
* Note the functions don't neccesarily need to be in an array as all arguments
|
|
93
93
|
* are considered to be the func argument and spread from there.
|
|
94
|
-
*
|
|
95
|
-
*
|
|
94
|
+
* The order of cleanup is the reverse of the argument order. Generally it is
|
|
95
|
+
* expected that the first "acquire" will be "released" last (LIFO order),
|
|
96
|
+
* because a later step may have some dependency on an earlier one.
|
|
97
|
+
* @param func - An array of cleanup functions meant to be executed by the returned function.
|
|
98
|
+
* @returns the function which executes all the passed cleanup functions.
|
|
96
99
|
*/
|
|
97
100
|
function mergeRegister(...func) {
|
|
98
101
|
return () => {
|
|
99
|
-
func.
|
|
102
|
+
for (let i = func.length - 1; i >= 0; i--) {
|
|
103
|
+
func[i]();
|
|
104
|
+
}
|
|
105
|
+
// Clean up the references and make future calls a no-op
|
|
106
|
+
func.length = 0;
|
|
100
107
|
};
|
|
101
108
|
}
|
|
102
109
|
|
package/LexicalUtils.prod.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
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
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.
|
|
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()=>{for(let b=a.length-1;0<=b;b--)a[b]();a.length=0}}let Q={attributes:!0,characterData:!0,childList:!0,subtree:!0};
|
|
12
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
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
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;
|
package/LexicalUtils.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
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.
|
|
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()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}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/mergeRegister.d.ts
CHANGED
|
@@ -23,10 +23,13 @@ type Func = () => void;
|
|
|
23
23
|
* In this case, useEffect is returning the function returned by mergeRegister as a cleanup
|
|
24
24
|
* function to be executed after either the useEffect runs again (due to one of its dependencies
|
|
25
25
|
* updating) or the component it resides in unmounts.
|
|
26
|
-
* Note the functions don't neccesarily need to be in an array as all
|
|
26
|
+
* Note the functions don't neccesarily need to be in an array as all arguments
|
|
27
27
|
* are considered to be the func argument and spread from there.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* The order of cleanup is the reverse of the argument order. Generally it is
|
|
29
|
+
* expected that the first "acquire" will be "released" last (LIFO order),
|
|
30
|
+
* because a later step may have some dependency on an earlier one.
|
|
31
|
+
* @param func - An array of cleanup functions meant to be executed by the returned function.
|
|
32
|
+
* @returns the function which executes all the passed cleanup functions.
|
|
30
33
|
*/
|
|
31
34
|
export default function mergeRegister(...func: Array<Func>): () => void;
|
|
32
35
|
export {};
|
package/package.json
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.16.0",
|
|
11
|
+
"version": "0.16.1-nightly.20240610.0",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/list": "0.16.0",
|
|
16
|
-
"@lexical/selection": "0.16.0",
|
|
17
|
-
"@lexical/table": "0.16.0",
|
|
18
|
-
"lexical": "0.16.0"
|
|
15
|
+
"@lexical/list": "0.16.1-nightly.20240610.0",
|
|
16
|
+
"@lexical/selection": "0.16.1-nightly.20240610.0",
|
|
17
|
+
"@lexical/table": "0.16.1-nightly.20240610.0",
|
|
18
|
+
"lexical": "0.16.1-nightly.20240610.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|