@lexical/utils
Advanced tools
Comparing version 0.6.3 to 0.6.4
@@ -390,21 +390,34 @@ /** | ||
const focusOffset = focus.offset; | ||
let splitNode; | ||
let splitOffset; | ||
if (lexical.$isTextNode(focusNode)) { | ||
splitNode = focusNode.getParentOrThrow(); | ||
splitOffset = focusNode.getIndexWithinParent(); | ||
if (lexical.$isRootOrShadowRoot(focusNode)) { | ||
const focusChild = focusNode.getChildAtIndex(focusOffset); | ||
if (focusOffset > 0) { | ||
splitOffset += 1; | ||
focusNode.splitText(focusOffset); | ||
if (focusChild == null) { | ||
focusNode.append(node); | ||
} else { | ||
focusChild.insertBefore(node); | ||
} | ||
node.selectNext(); | ||
} else { | ||
splitNode = focusNode; | ||
splitOffset = focusOffset; | ||
let splitNode; | ||
let splitOffset; | ||
if (lexical.$isTextNode(focusNode)) { | ||
splitNode = focusNode.getParentOrThrow(); | ||
splitOffset = focusNode.getIndexWithinParent(); | ||
if (focusOffset > 0) { | ||
splitOffset += 1; | ||
focusNode.splitText(focusOffset); | ||
} | ||
} else { | ||
splitNode = focusNode; | ||
splitOffset = focusOffset; | ||
} | ||
const [, rightTree] = $splitNode(splitNode, splitOffset); | ||
rightTree.insertBefore(node); | ||
rightTree.selectStart(); | ||
} | ||
const [, rightTree] = $splitNode(splitNode, splitOffset); | ||
rightTree.insertBefore(node); | ||
rightTree.selectStart(); | ||
} else { | ||
@@ -439,2 +452,6 @@ if (lexical.$isNodeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection)) { | ||
if (!!lexical.$isRootOrShadowRoot(node)) { | ||
throw Error(`Can not call $splitNode() on root element`); | ||
} | ||
const recurse = currentNode => { | ||
@@ -441,0 +458,0 @@ const parent = currentNode.getParentOrThrow(); |
@@ -11,9 +11,10 @@ /** | ||
function v(a,b){let d=b._editorState.constructor,g=new Map,f=new d(g),c=new Map(a._nodeMap),e=c.get("root");a=b._updating;try{b._updating=!1,b.update(()=>{let k=b._dirtyElements,h=b._dirtyLeaves,m=b._dirtyType;b._dirtyElements=new Map;b._dirtyLeaves=new Set;b._dirtyType=0;try{t(e,c,b,null,f)}finally{b._dirtyElements=k,b._dirtyLeaves=h,b._dirtyType=m}})}finally{b._updating=a}f._readOnly=!0;return f}function u(a,b){b="string"===typeof b?JSON.parse(b):b;return v(b,a)} | ||
function w(a,b){let d=a.getChildAtIndex(b);null==d&&(d=a);let g=e=>{const k=e.getParentOrThrow(),h=l.$isRootOrShadowRoot(k),m=e!==d||h?l.$copyNode(e):e;if(h)return e.insertAfter(m),[e,m,m];const [n,x,y]=g(k);e=e.getNextSiblings();y.append(m,...e);return[n,x,m]},[f,c]=g(d);return[f,c]} | ||
function w(a,b){let d=a.getChildAtIndex(b);null==d&&(d=a);if(l.$isRootOrShadowRoot(a))throw Error("Can not call $splitNode() on root element");let g=e=>{const k=e.getParentOrThrow(),h=l.$isRootOrShadowRoot(k),m=e!==d||h?l.$copyNode(e):e;if(h)return e.insertAfter(m),[e,m,m];const [n,x,y]=g(k);e=e.getNextSiblings();y.append(m,...e);return[n,x,m]},[f,c]=g(d);return[f,c]} | ||
exports.$dfs=function(a,b){let d=[];a=(a||l.$getRoot()).getLatest();b=b||(l.$isElementNode(a)?a.getLastDescendant():a);for(var g=a,f=0;null!==(g=g.getParent());)f++;for(g=f;null!==a&&!a.is(b);)if(d.push({depth:g,node:a}),l.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild(),g++;else for(f=null;null===f&&null!==a;)f=a.getNextSibling(),null===f?(a=a.getParent(),g--):a=f;null!==a&&a.is(b)&&d.push({depth:g,node:a});return d};exports.$findMatchingParent=r; | ||
exports.$getNearestBlockElementAncestorOrThrow=function(a){a=r(a,b=>l.$isElementNode(b)&&!b.isInline());l.$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=l.$getSelection();if(l.$isRangeSelection(b)){var {focus:d}=b;b=d.getNode();d=d.offset;let g,f;l.$isTextNode(b)?(g=b.getParentOrThrow(),f=b.getIndexWithinParent(),0<d&&(f+=1,b.splitText(d))):(g=b,f=d);[,b]=w(g,f);b.insertBefore(a);b.selectStart()}else l.$isNodeSelection(b)||l.DEPRECATED_$isGridSelection(b)?(b=b.getNodes(),b[b.length-1].getTopLevelElementOrThrow().insertAfter(a)):l.$getRoot().append(a),b=l.$createParagraphNode(),a.insertAfter(b),b.select(); | ||
return a.getLatest()};exports.$restoreEditorState=function(a,b){let d=new Map(b._nodeMap),g=a._pendingEditorState;g&&(g._nodeMap=d);a._dirtyType=2;a=b._selection;l.$setSelection(null===a?null:a.clone())};exports.$splitNode=w;exports.$wrapNodeInElement=function(a,b){b=b();a.replace(b);b.append(a);return b};exports.addClassNamesToElement=function(a,...b){b.forEach(d=>{"string"===typeof d&&(d=d.split(" ").filter(g=>""!==g),a.classList.add(...d))})};exports.isMimeType=q; | ||
exports.$insertNodeToNearestRoot=function(a){var b=l.$getSelection();if(l.$isRangeSelection(b)){var {focus:d}=b;b=d.getNode();d=d.offset;if(l.$isRootOrShadowRoot(b))d=b.getChildAtIndex(d),null==d?b.append(a):d.insertBefore(a),a.selectNext();else{let g,f;l.$isTextNode(b)?(g=b.getParentOrThrow(),f=b.getIndexWithinParent(),0<d&&(f+=1,b.splitText(d))):(g=b,f=d);[,b]=w(g,f);b.insertBefore(a);b.selectStart()}}else l.$isNodeSelection(b)||l.DEPRECATED_$isGridSelection(b)?(b=b.getNodes(),b[b.length-1].getTopLevelElementOrThrow().insertAfter(a)): | ||
l.$getRoot().append(a),b=l.$createParagraphNode(),a.insertAfter(b),b.select();return a.getLatest()};exports.$restoreEditorState=function(a,b){let d=new Map(b._nodeMap),g=a._pendingEditorState;g&&(g._nodeMap=d);a._dirtyType=2;a=b._selection;l.$setSelection(null===a?null:a.clone())};exports.$splitNode=w;exports.$wrapNodeInElement=function(a,b){b=b();a.replace(b);b.append(a);return b}; | ||
exports.addClassNamesToElement=function(a,...b){b.forEach(d=>{"string"===typeof d&&(d=d.split(" ").filter(g=>""!==g),a.classList.add(...d))})};exports.isMimeType=q; | ||
exports.mediaFileReader=function(a,b){let d=a[Symbol.iterator]();return new Promise((g,f)=>{let c=[],e=()=>{const {done:k,value:h}=d.next();if(k)return g(c);const m=new FileReader;m.addEventListener("error",f);m.addEventListener("load",()=>{const n=m.result;"string"===typeof n&&c.push({file:h,result:n});e()});q(h,b)?m.readAsDataURL(h):e()};e()})};exports.mergeRegister=function(...a){return()=>{a.forEach(b=>b())}}; | ||
exports.registerNestedElementResolver=function(a,b,d,g){return a.registerNodeTransform(b,f=>{a:{var c=f.getChildren();for(var e=0;e<c.length;e++)if(c[e]instanceof b){c=null;break a}for(c=f;null!==c;)if(e=c,c=c.getParent(),c instanceof b){c={child:e,parent:c};break a}c=null}if(null!==c){const {child:k,parent:h}=c;if(k.is(f)){g(h,f);f=k.getNextSiblings();c=f.length;h.insertAfter(k);if(0!==c){e=d(h);k.insertAfter(e);for(let m=0;m<c;m++)e.append(f[m])}h.canBeEmpty()||0!==h.getChildrenSize()||h.remove()}}})}; | ||
exports.removeClassNamesFromElement=function(a,...b){b.forEach(d=>{"string"===typeof d&&a.classList.remove(...d.split(" "))})};exports.unstable_convertLegacyJSONEditorState=u |
@@ -11,10 +11,10 @@ { | ||
"license": "MIT", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"main": "LexicalUtils.js", | ||
"peerDependencies": { | ||
"lexical": "0.6.3" | ||
"lexical": "0.6.4" | ||
}, | ||
"dependencies": { | ||
"@lexical/list": "0.6.3", | ||
"@lexical/table": "0.6.3" | ||
"@lexical/list": "0.6.4", | ||
"@lexical/table": "0.6.4" | ||
}, | ||
@@ -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
26242
489
+ Added@lexical/list@0.6.4(transitive)
+ Added@lexical/table@0.6.4(transitive)
+ Addedlexical@0.6.4(transitive)
- Removed@lexical/list@0.6.3(transitive)
- Removed@lexical/table@0.6.3(transitive)
- Removedlexical@0.6.3(transitive)
Updated@lexical/list@0.6.4
Updated@lexical/table@0.6.4