@lexical/utils
Advanced tools
Comparing version 0.7.4 to 0.7.5
@@ -7,11 +7,11 @@ /** | ||
*/ | ||
'use strict';var h=require("lexical");function p(a,b){for(let c of b)if(a.type.startsWith(c))return!0;return!1}function q(a,b){for(;a!==h.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null} | ||
function r(a,b){let c=a.getChildAtIndex(b);null==c&&(c=a);if(h.$isRootOrShadowRoot(a))throw Error("Can not call $splitNode() on root element");let e=f=>{const m=f.getParentOrThrow(),l=h.$isRootOrShadowRoot(m),k=f!==c||l?h.$copyNode(f):f;if(l)return f.insertAfter(k),[f,k,k];const [n,t,u]=e(m);f=f.getNextSiblings();u.append(k,...f);return[n,t,k]},[d,g]=e(c);return[d,g]} | ||
exports.$dfs=function(a,b){let c=[];a=(a||h.$getRoot()).getLatest();b=b||(h.$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}),h.$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};exports.$findMatchingParent=q; | ||
exports.$getNearestBlockElementAncestorOrThrow=function(a){a=q(a,b=>h.$isElementNode(b)&&!b.isInline());if(!h.$isElementNode(a))throw Error("Minified Lexical error #4; visit https://lexical.dev/docs/error?code=4 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a};exports.$getNearestNodeOfType=function(a,b){for(;null!=a;){if(a instanceof b)return a;a=a.getParent()}return null}; | ||
exports.$insertNodeToNearestRoot=function(a){var b=h.$getSelection();if(h.$isRangeSelection(b)){var {focus:c}=b;b=c.getNode();c=c.offset;if(h.$isRootOrShadowRoot(b))c=b.getChildAtIndex(c),null==c?b.append(a):c.insertBefore(a),a.selectNext();else{let e,d;h.$isTextNode(b)?(e=b.getParentOrThrow(),d=b.getIndexWithinParent(),0<c&&(d+=1,b.splitText(c))):(e=b,d=c);[,b]=r(e,d);b.insertBefore(a);b.selectStart()}}else h.$isNodeSelection(b)||h.DEPRECATED_$isGridSelection(b)?(b=b.getNodes(),b[b.length-1].getTopLevelElementOrThrow().insertAfter(a)): | ||
h.$getRoot().append(a),b=h.$createParagraphNode(),a.insertAfter(b),b.select();return a.getLatest()};exports.$restoreEditorState=function(a,b){let c=new Map(b._nodeMap),e=a._pendingEditorState;e&&(e._nodeMap=c);a._dirtyType=2;a=b._selection;h.$setSelection(null===a?null:a.clone())};exports.$splitNode=r;exports.$wrapNodeInElement=function(a,b){b=b();a.replace(b);b.append(a);return b}; | ||
exports.addClassNamesToElement=function(a,...b){b.forEach(c=>{"string"===typeof c&&(c=c.split(" ").filter(e=>""!==e),a.classList.add(...c))})};exports.isMimeType=p; | ||
exports.mediaFileReader=function(a,b){let c=a[Symbol.iterator]();return new Promise((e,d)=>{let g=[],f=()=>{const {done:m,value:l}=c.next();if(m)return e(g);const k=new FileReader;k.addEventListener("error",d);k.addEventListener("load",()=>{const n=k.result;"string"===typeof n&&g.push({file:l,result:n});f()});p(l,b)?k.readAsDataURL(l):f()};f()})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}}; | ||
'use strict';var h=require("lexical");function p(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function q(a,b){for(let c of b)if(a.type.startsWith(c))return!0;return!1}function r(a,b){for(;a!==h.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null} | ||
function t(a,b){let c=a.getChildAtIndex(b);null==c&&(c=a);h.$isRootOrShadowRoot(a)&&p(102);let e=f=>{const m=f.getParentOrThrow(),l=h.$isRootOrShadowRoot(m),k=f!==c||l?h.$copyNode(f):f;if(l)return f.insertAfter(k),[f,k,k];const [n,u,v]=e(m);f=f.getNextSiblings();v.append(k,...f);return[n,u,k]},[d,g]=e(c);return[d,g]} | ||
exports.$dfs=function(a,b){let c=[];a=(a||h.$getRoot()).getLatest();b=b||(h.$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}),h.$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};exports.$findMatchingParent=r; | ||
exports.$getNearestBlockElementAncestorOrThrow=function(a){a=r(a,b=>h.$isElementNode(b)&&!b.isInline());h.$isElementNode(a)||p(4);return a};exports.$getNearestNodeOfType=function(a,b){for(;null!=a;){if(a instanceof b)return a;a=a.getParent()}return null}; | ||
exports.$insertNodeToNearestRoot=function(a){var b=h.$getSelection();if(h.$isRangeSelection(b)){var {focus:c}=b;b=c.getNode();c=c.offset;if(h.$isRootOrShadowRoot(b))c=b.getChildAtIndex(c),null==c?b.append(a):c.insertBefore(a),a.selectNext();else{let e,d;h.$isTextNode(b)?(e=b.getParentOrThrow(),d=b.getIndexWithinParent(),0<c&&(d+=1,b.splitText(c))):(e=b,d=c);[,b]=t(e,d);b.insertBefore(a);b.selectStart()}}else h.$isNodeSelection(b)||h.DEPRECATED_$isGridSelection(b)?(b=b.getNodes(),b[b.length-1].getTopLevelElementOrThrow().insertAfter(a)): | ||
h.$getRoot().append(a),b=h.$createParagraphNode(),a.insertAfter(b),b.select();return a.getLatest()};exports.$restoreEditorState=function(a,b){let c=new Map(b._nodeMap),e=a._pendingEditorState;e&&(e._nodeMap=c);a._dirtyType=2;a=b._selection;h.$setSelection(null===a?null:a.clone())};exports.$splitNode=t;exports.$wrapNodeInElement=function(a,b){b=b();a.replace(b);b.append(a);return b}; | ||
exports.addClassNamesToElement=function(a,...b){b.forEach(c=>{"string"===typeof c&&(c=c.split(" ").filter(e=>""!==e),a.classList.add(...c))})};exports.isMimeType=q; | ||
exports.mediaFileReader=function(a,b){let c=a[Symbol.iterator]();return new Promise((e,d)=>{let g=[],f=()=>{const {done:m,value:l}=c.next();if(m)return e(g);const k=new FileReader;k.addEventListener("error",d);k.addEventListener("load",()=>{const n=k.result;"string"===typeof n&&g.push({file:l,result:n});f()});q(l,b)?k.readAsDataURL(l):f()};f()})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}}; | ||
exports.registerNestedElementResolver=function(a,b,c,e){return a.registerNodeTransform(b,d=>{a:{var g=d.getChildren();for(var f=0;f<g.length;f++)if(g[f]instanceof b){g=null;break a}for(g=d;null!==g;)if(f=g,g=g.getParent(),g instanceof b){g={child:f,parent:g};break a}g=null}if(null!==g){const {child:m,parent:l}=g;if(m.is(d)){e(l,d);d=m.getNextSiblings();g=d.length;l.insertAfter(m);if(0!==g){f=c(l);m.insertAfter(f);for(let k=0;k<g;k++)f.append(d[k])}l.canBeEmpty()||0!==l.getChildrenSize()||l.remove()}}})}; | ||
exports.removeClassNamesFromElement=function(a,...b){b.forEach(c=>{"string"===typeof c&&a.classList.remove(...c.split(" "))})} |
@@ -11,10 +11,10 @@ { | ||
"license": "MIT", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"main": "LexicalUtils.js", | ||
"peerDependencies": { | ||
"lexical": "0.7.4" | ||
"lexical": "0.7.5" | ||
}, | ||
"dependencies": { | ||
"@lexical/list": "0.7.4", | ||
"@lexical/table": "0.7.4" | ||
"@lexical/list": "0.7.5", | ||
"@lexical/table": "0.7.5" | ||
}, | ||
@@ -21,0 +21,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20847
+ Added@lexical/list@0.7.5(transitive)
+ Added@lexical/table@0.7.5(transitive)
+ Addedlexical@0.7.5(transitive)
- Removed@lexical/list@0.7.4(transitive)
- Removed@lexical/table@0.7.4(transitive)
- Removedlexical@0.7.4(transitive)
Updated@lexical/list@0.7.5
Updated@lexical/table@0.7.5