@lexical/utils
Advanced tools
Comparing version 0.8.1 to 0.9.0
@@ -34,5 +34,5 @@ /** | ||
} | ||
return false; | ||
} | ||
/** | ||
@@ -49,2 +49,3 @@ * Lexical File Reader with: | ||
*/ | ||
function mediaFileReader(files, acceptableMimeTypes) { | ||
@@ -54,2 +55,3 @@ const filesIterator = files[Symbol.iterator](); | ||
const processed = []; | ||
const handleNextFile = () => { | ||
@@ -60,5 +62,7 @@ const { | ||
} = filesIterator.next(); | ||
if (done) { | ||
return resolve(processed); | ||
} | ||
const fileReader = new FileReader(); | ||
@@ -68,2 +72,3 @@ fileReader.addEventListener('error', reject); | ||
const result = fileReader.result; | ||
if (typeof result === 'string') { | ||
@@ -75,4 +80,6 @@ processed.push({ | ||
} | ||
handleNextFile(); | ||
}); | ||
if (isMimeType(file, acceptableMimeTypes)) { | ||
@@ -84,2 +91,3 @@ fileReader.readAsDataURL(file); | ||
}; | ||
handleNextFile(); | ||
@@ -94,2 +102,3 @@ }); | ||
let depth = $getDepth(node); | ||
while (node !== null && !node.is(end)) { | ||
@@ -100,2 +109,3 @@ nodes.push({ | ||
}); | ||
if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) { | ||
@@ -107,4 +117,6 @@ node = node.getFirstChild(); | ||
let sibling = null; | ||
while (sibling === null && node !== null) { | ||
sibling = node.getNextSibling(); | ||
if (sibling === null) { | ||
@@ -119,2 +131,3 @@ node = node.getParent(); | ||
} | ||
if (node !== null && node.is(end)) { | ||
@@ -126,14 +139,20 @@ nodes.push({ | ||
} | ||
return nodes; | ||
} | ||
function $getDepth(node) { | ||
let innerNode = node; | ||
let depth = 0; | ||
while ((innerNode = innerNode.getParent()) !== null) { | ||
depth++; | ||
} | ||
return depth; | ||
} | ||
function $getNearestNodeOfType(node, klass) { | ||
let parent = node; | ||
while (parent != null) { | ||
@@ -143,4 +162,6 @@ if (parent instanceof klass) { | ||
} | ||
parent = parent.getParent(); | ||
} | ||
return null; | ||
@@ -150,2 +171,3 @@ } | ||
const blockNode = $findMatchingParent(startNode, node => lexical.$isElementNode(node) && !node.isInline()); | ||
if (!lexical.$isElementNode(blockNode)) { | ||
@@ -156,2 +178,3 @@ { | ||
} | ||
return blockNode; | ||
@@ -161,2 +184,3 @@ } | ||
let curr = startingNode; | ||
while (curr !== lexical.$getRoot() && curr != null) { | ||
@@ -166,4 +190,6 @@ if (findFn(curr)) { | ||
} | ||
curr = curr.getParent(); | ||
} | ||
return null; | ||
@@ -180,2 +206,3 @@ } | ||
}; | ||
const $findMatch = node => { | ||
@@ -185,4 +212,6 @@ // First validate we don't have any children that are of the target, | ||
const children = node.getChildren(); | ||
for (let i = 0; i < children.length; i++) { | ||
const child = children[i]; | ||
if ($isTargetNode(child)) { | ||
@@ -192,7 +221,10 @@ return null; | ||
} | ||
let parentNode = node; | ||
let childNode = node; | ||
while (parentNode !== null) { | ||
childNode = parentNode; | ||
parentNode = parentNode.getParent(); | ||
if ($isTargetNode(parentNode)) { | ||
@@ -205,6 +237,9 @@ return { | ||
} | ||
return null; | ||
}; | ||
const elementNodeTransform = node => { | ||
const match = $findMatch(node); | ||
if (match !== null) { | ||
@@ -214,6 +249,4 @@ const { | ||
parent | ||
} = match; | ||
} = match; // Simple path, we can move child out and siblings into a new parent. | ||
// Simple path, we can move child out and siblings into a new parent. | ||
if (child.is(node)) { | ||
@@ -224,5 +257,7 @@ handleOverlap(parent, node); | ||
parent.insertAfter(child); | ||
if (nextSiblingsLength !== 0) { | ||
const newParent = cloneNode(parent); | ||
child.insertAfter(newParent); | ||
for (let i = 0; i < nextSiblingsLength; i++) { | ||
@@ -232,2 +267,3 @@ newParent.append(nextSiblings[i]); | ||
} | ||
if (!parent.canBeEmpty() && parent.getChildrenSize() === 0) { | ||
@@ -239,2 +275,3 @@ parent.remove(); | ||
}; | ||
return editor.registerNodeTransform(targetNode, elementNodeTransform); | ||
@@ -246,12 +283,17 @@ } | ||
const activeEditorState = editor._pendingEditorState; | ||
for (const [key, node] of editorState._nodeMap) { | ||
const clone = selection.$cloneWithProperties(node); | ||
if (lexical.$isTextNode(clone)) { | ||
clone.__text = node.__text; | ||
} | ||
nodeMap.set(key, clone); | ||
} | ||
if (activeEditorState) { | ||
activeEditorState._nodeMap = nodeMap; | ||
} | ||
editor._dirtyType = FULL_RECONCILE; | ||
@@ -263,2 +305,3 @@ const selection$1 = editorState._selection; | ||
const selection = lexical.$getSelection(); | ||
if (lexical.$isRangeSelection(selection)) { | ||
@@ -270,4 +313,6 @@ const { | ||
const focusOffset = focus.offset; | ||
if (lexical.$isRootOrShadowRoot(focusNode)) { | ||
const focusChild = focusNode.getChildAtIndex(focusOffset); | ||
if (focusChild == null) { | ||
@@ -278,2 +323,3 @@ focusNode.append(node); | ||
} | ||
node.selectNext(); | ||
@@ -283,5 +329,7 @@ } else { | ||
let splitOffset; | ||
if (lexical.$isTextNode(focusNode)) { | ||
splitNode = focusNode.getParentOrThrow(); | ||
splitOffset = focusNode.getIndexWithinParent(); | ||
if (focusOffset > 0) { | ||
@@ -295,2 +343,3 @@ splitOffset += 1; | ||
} | ||
const [, rightTree] = lexical.$splitNode(splitNode, splitOffset); | ||
@@ -308,2 +357,3 @@ rightTree.insertBefore(node); | ||
} | ||
const paragraphNode = lexical.$createParagraphNode(); | ||
@@ -313,2 +363,3 @@ node.insertAfter(paragraphNode); | ||
} | ||
return node.getLatest(); | ||
@@ -315,0 +366,0 @@ } |
@@ -11,11 +11,11 @@ { | ||
"license": "MIT", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"main": "LexicalUtils.js", | ||
"peerDependencies": { | ||
"lexical": "0.8.1" | ||
"lexical": "0.9.0" | ||
}, | ||
"dependencies": { | ||
"@lexical/list": "0.8.1", | ||
"@lexical/table": "0.8.1", | ||
"@lexical/selection": "0.8.1" | ||
"@lexical/list": "0.9.0", | ||
"@lexical/table": "0.9.0", | ||
"@lexical/selection": "0.9.0" | ||
}, | ||
@@ -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
20424
381
+ Added@lexical/list@0.9.0(transitive)
+ Added@lexical/selection@0.9.0(transitive)
+ Added@lexical/table@0.9.0(transitive)
+ Addedlexical@0.9.0(transitive)
- Removed@lexical/list@0.8.1(transitive)
- Removed@lexical/selection@0.8.1(transitive)
- Removed@lexical/table@0.8.1(transitive)
- Removedlexical@0.8.1(transitive)
Updated@lexical/list@0.9.0
Updated@lexical/selection@0.9.0
Updated@lexical/table@0.9.0