@lexical/utils
Advanced tools
Comparing version 0.1.19 to 0.1.20
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import type {LexicalNode} from 'lexical'; | ||
import type {LexicalNode, ElementNode} from 'lexical'; | ||
export type DFSNode = $ReadOnly<{ | ||
@@ -41,1 +41,4 @@ depth: number; | ||
declare function mergeRegister(...func: Array<Func>): () => void; | ||
declare function $getNearestBlockElementAncestorOrThrow( | ||
startNode: LexicalNode, | ||
): ElementNode; |
@@ -98,2 +98,13 @@ /** | ||
} | ||
function $getNearestBlockElementAncestorOrThrow(startNode) { | ||
const blockNode = $findMatchingParent(startNode, node => lexical.$isElementNode(node) && !node.isInline()); | ||
if (!lexical.$isElementNode(blockNode)) { | ||
{ | ||
throw Error(`Expected node ${startNode.__key} to have closest block element node.`); | ||
} | ||
} | ||
return blockNode; | ||
} | ||
function $findMatchingParent(startingNode, findFn) { | ||
@@ -120,2 +131,3 @@ let curr = startingNode; | ||
exports.$findMatchingParent = $findMatchingParent; | ||
exports.$getNearestBlockElementAncestorOrThrow = $getNearestBlockElementAncestorOrThrow; | ||
exports.$getNearestNodeOfType = $getNearestNodeOfType; | ||
@@ -122,0 +134,0 @@ exports.addClassNamesToElement = addClassNamesToElement; |
@@ -7,3 +7,5 @@ /** | ||
*/ | ||
var f=require("lexical");exports.$dfs=function(a,b){const c=[];a=(a||f.$getRoot()).getLatest();b=b||(f.$isElementNode(a)?a.getLastDescendant():a);for(var d=a,e=0;null!==(d=d.getParent());)e++;for(d=e;null!==a&&!a.is(b);)if(c.push({depth:d,node:a}),f.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),d++;else for(e=null;null===e&&null!==a;)e=a.getNextSibling(),null===e?(a=a.getParent(),d--):a=e;null!==a&&a.is(b)&&c.push({depth:d,node:a});return c}; | ||
exports.$findMatchingParent=function(a,b){for(;a!==f.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null};exports.$getNearestNodeOfType=function(a,b){for(;null!=a&&!(a instanceof b);)a=a.getParent();return a};exports.addClassNamesToElement=function(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}};exports.removeClassNamesFromElement=function(a,...b){b.forEach(c=>{a.classList.remove(...c.split(" "))})}; | ||
var f=require("lexical");function g(a,b){for(;a!==f.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null} | ||
exports.$dfs=function(a,b){const c=[];a=(a||f.$getRoot()).getLatest();b=b||(f.$isElementNode(a)?a.getLastDescendant():a);for(var d=a,e=0;null!==(d=d.getParent());)e++;for(d=e;null!==a&&!a.is(b);)if(c.push({depth:d,node:a}),f.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),d++;else for(e=null;null===e&&null!==a;)e=a.getNextSibling(),null===e?(a=a.getParent(),d--):a=e;null!==a&&a.is(b)&&c.push({depth:d,node:a});return c};exports.$findMatchingParent=g; | ||
exports.$getNearestBlockElementAncestorOrThrow=function(a){const b=g(a,c=>f.$isElementNode(c)&&!c.isInline());if(!f.$isElementNode(b))throw Error(`Expected node ${a.__key} to have closest block element node.`);return b};exports.$getNearestNodeOfType=function(a,b){for(;null!=a&&!(a instanceof b);)a=a.getParent();return a};exports.addClassNamesToElement=function(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})}; | ||
exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}};exports.removeClassNamesFromElement=function(a,...b){b.forEach(c=>{a.classList.remove(...c.split(" "))})}; |
@@ -11,10 +11,10 @@ { | ||
"license": "MIT", | ||
"version": "0.1.19", | ||
"version": "0.1.20", | ||
"main": "LexicalUtils.js", | ||
"peerDependencies": { | ||
"lexical": "0.1.19" | ||
"lexical": "0.1.20" | ||
}, | ||
"dependencies": { | ||
"@lexical/list": "0.1.19", | ||
"@lexical/table": "0.1.19" | ||
"@lexical/list": "0.1.20", | ||
"@lexical/table": "0.1.20" | ||
}, | ||
@@ -21,0 +21,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
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
9351
175
+ Added@lexical/list@0.1.20(transitive)
+ Added@lexical/table@0.1.20(transitive)
+ Addedlexical@0.1.20(transitive)
- Removed@lexical/list@0.1.19(transitive)
- Removed@lexical/table@0.1.19(transitive)
- Removedlexical@0.1.19(transitive)
Updated@lexical/list@0.1.20
Updated@lexical/table@0.1.20