@lexical/utils
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -45,1 +45,3 @@ /** @module @lexical/utils */ | ||
export declare function $wrapNodeInElement(node: LexicalNode, createElementNode: () => ElementNode): ElementNode; | ||
export declare function isHTMLAnchorElement(x: Node): x is HTMLAnchorElement; | ||
export declare function isHTMLElement(x: Node | EventTarget): x is HTMLElement; |
@@ -289,2 +289,9 @@ /** | ||
} | ||
function isHTMLAnchorElement(x) { | ||
return isHTMLElement(x) && x.tagName === 'A'; | ||
} | ||
function isHTMLElement(x) { | ||
// @ts-ignore-next-line - strict check on nodeType here should filter out non-Element EventTarget implementors | ||
return x.nodeType === 1; | ||
} | ||
@@ -300,2 +307,4 @@ exports.$splitNode = lexical.$splitNode; | ||
exports.addClassNamesToElement = addClassNamesToElement; | ||
exports.isHTMLAnchorElement = isHTMLAnchorElement; | ||
exports.isHTMLElement = isHTMLElement; | ||
exports.isMimeType = isMimeType; | ||
@@ -302,0 +311,0 @@ exports.mediaFileReader = mediaFileReader; |
@@ -7,10 +7,10 @@ /** | ||
*/ | ||
'use strict';var g=require("@lexical/selection"),n=require("lexical");function p(a,b){for(let c of b)if(a.type.startsWith(c))return!0;return!1}function r(a,b){for(;a!==n.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null}exports.$splitNode=n.$splitNode; | ||
exports.$dfs=function(a,b){let c=[];a=(a||n.$getRoot()).getLatest();b=b||(n.$isElementNode(a)?a.getLastDescendant():a);for(var f=a,d=0;null!==(f=f.getParent());)d++;for(f=d;null!==a&&!a.is(b);)if(c.push({depth:f,node:a}),n.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),f++;else for(d=null;null===d&&null!==a;)d=a.getNextSibling(),null===d?(a=a.getParent(),f--):a=d;null!==a&&a.is(b)&&c.push({depth:f,node:a});return c};exports.$findMatchingParent=r; | ||
exports.$getNearestBlockElementAncestorOrThrow=function(a){a=r(a,b=>n.$isElementNode(b)&&!b.isInline());if(!n.$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}; | ||
'use strict';var g=require("@lexical/selection"),n=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!==n.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null}function t(a){return 1===a.nodeType}exports.$splitNode=n.$splitNode; | ||
exports.$dfs=function(a,b){let c=[];a=(a||n.$getRoot()).getLatest();b=b||(n.$isElementNode(a)?a.getLastDescendant():a);for(var f=a,d=0;null!==(f=f.getParent());)d++;for(f=d;null!==a&&!a.is(b);)if(c.push({depth:f,node:a}),n.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),f++;else for(d=null;null===d&&null!==a;)d=a.getNextSibling(),null===d?(a=a.getParent(),f--):a=d;null!==a&&a.is(b)&&c.push({depth:f,node:a});return c};exports.$findMatchingParent=q; | ||
exports.$getNearestBlockElementAncestorOrThrow=function(a){a=q(a,b=>n.$isElementNode(b)&&!b.isInline());if(!n.$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=n.$getSelection();if(n.$isRangeSelection(b)){var {focus:c}=b;b=c.getNode();c=c.offset;if(n.$isRootOrShadowRoot(b))c=b.getChildAtIndex(c),null==c?b.append(a):c.insertBefore(a),a.selectNext();else{let f,d;n.$isTextNode(b)?(f=b.getParentOrThrow(),d=b.getIndexWithinParent(),0<c&&(d+=1,b.splitText(c))):(f=b,d=c);[,b]=n.$splitNode(f,d);b.insertBefore(a);b.selectStart()}}else n.$isNodeSelection(b)||n.DEPRECATED_$isGridSelection(b)?(b=b.getNodes(),b[b.length- | ||
1].getTopLevelElementOrThrow().insertAfter(a)):n.$getRoot().append(a),b=n.$createParagraphNode(),a.insertAfter(b),b.select();return a.getLatest()};exports.$restoreEditorState=function(a,b){let c=new Map,f=a._pendingEditorState;for(let [d,e]of b._nodeMap){let h=g.$cloneWithProperties(e);n.$isTextNode(h)&&(h.__text=e.__text);c.set(d,h)}f&&(f._nodeMap=c);a._dirtyType=2;a=b._selection;n.$setSelection(null===a?null:a.clone())};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(f=>""!==f),a.classList.add(...c))})};exports.isMimeType=p; | ||
exports.mediaFileReader=function(a,b){let c=a[Symbol.iterator]();return new Promise((f,d)=>{let e=[],h=()=>{const {done:m,value:k}=c.next();if(m)return f(e);const l=new FileReader;l.addEventListener("error",d);l.addEventListener("load",()=>{const q=l.result;"string"===typeof q&&e.push({file:k,result:q});h()});p(k,b)?l.readAsDataURL(k):h()};h()})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}}; | ||
exports.addClassNamesToElement=function(a,...b){b.forEach(c=>{"string"===typeof c&&(c=c.split(" ").filter(f=>""!==f),a.classList.add(...c))})};exports.isHTMLAnchorElement=function(a){return t(a)&&"A"===a.tagName};exports.isHTMLElement=t;exports.isMimeType=p; | ||
exports.mediaFileReader=function(a,b){let c=a[Symbol.iterator]();return new Promise((f,d)=>{let e=[],h=()=>{const {done:m,value:k}=c.next();if(m)return f(e);const l=new FileReader;l.addEventListener("error",d);l.addEventListener("load",()=>{const r=l.result;"string"===typeof r&&e.push({file:k,result:r});h()});p(k,b)?l.readAsDataURL(k):h()};h()})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}}; | ||
exports.registerNestedElementResolver=function(a,b,c,f){return a.registerNodeTransform(b,d=>{a:{var e=d.getChildren();for(var h=0;h<e.length;h++)if(e[h]instanceof b){e=null;break a}for(e=d;null!==e;)if(h=e,e=e.getParent(),e instanceof b){e={child:h,parent:e};break a}e=null}if(null!==e){const {child:m,parent:k}=e;if(m.is(d)){f(k,d);d=m.getNextSiblings();e=d.length;k.insertAfter(m);if(0!==e){h=c(k);m.insertAfter(h);for(let l=0;l<e;l++)h.append(d[l])}k.canBeEmpty()||0!==k.getChildrenSize()||k.remove()}}})}; | ||
exports.removeClassNamesFromElement=function(a,...b){b.forEach(c=>{"string"===typeof c&&a.classList.remove(...c.split(" "))})} |
@@ -11,11 +11,11 @@ { | ||
"license": "MIT", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"main": "LexicalUtils.js", | ||
"peerDependencies": { | ||
"lexical": "0.8.0" | ||
"lexical": "0.8.1" | ||
}, | ||
"dependencies": { | ||
"@lexical/list": "0.8.0", | ||
"@lexical/table": "0.8.0", | ||
"@lexical/selection": "0.8.0" | ||
"@lexical/list": "0.8.1", | ||
"@lexical/table": "0.8.1", | ||
"@lexical/selection": "0.8.1" | ||
}, | ||
@@ -22,0 +22,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
20378
382
+ Added@lexical/list@0.8.1(transitive)
+ Added@lexical/selection@0.8.1(transitive)
+ Added@lexical/table@0.8.1(transitive)
+ Addedlexical@0.8.1(transitive)
- Removed@lexical/list@0.8.0(transitive)
- Removed@lexical/selection@0.8.0(transitive)
- Removed@lexical/table@0.8.0(transitive)
- Removedlexical@0.8.0(transitive)
Updated@lexical/list@0.8.1
Updated@lexical/selection@0.8.1
Updated@lexical/table@0.8.1