@lexical/text
Advanced tools
Comparing version 0.7.8 to 0.7.9
@@ -15,7 +15,5 @@ /** | ||
let currentCharacters = 0; | ||
mainLoop: while (node !== null) { | ||
if (lexical.$isElementNode(node)) { | ||
const child = node.getFirstChild(); | ||
if (child !== null) { | ||
@@ -27,3 +25,2 @@ node = child; | ||
const characters = node.getTextContentSize(); | ||
if (currentCharacters + characters > targetCharacters) { | ||
@@ -35,8 +32,5 @@ return { | ||
} | ||
currentCharacters += characters; | ||
} | ||
const sibling = node.getNextSibling(); | ||
if (sibling !== null) { | ||
@@ -46,8 +40,5 @@ node = sibling; | ||
} | ||
let parent = node.getParent(); | ||
while (parent !== null) { | ||
const parentSibling = parent.getNextSibling(); | ||
if (parentSibling !== null) { | ||
@@ -57,9 +48,6 @@ node = parentSibling; | ||
} | ||
parent = parent.getParent(); | ||
} | ||
break; | ||
} | ||
return null; | ||
@@ -71,9 +59,6 @@ } | ||
} | ||
let text = $rootTextContent(); | ||
if (trim) { | ||
text = text.trim(); | ||
} | ||
return text === ''; | ||
@@ -92,14 +77,10 @@ } | ||
} | ||
const root = lexical.$getRoot(); | ||
const children = root.getChildren(); | ||
const childrenLength = children.length; | ||
if (childrenLength > 1) { | ||
return false; | ||
} | ||
for (let i = 0; i < childrenLength; i++) { | ||
const topBlock = children[i]; | ||
if (lexical.$isElementNode(topBlock)) { | ||
@@ -109,13 +90,9 @@ if (!lexical.$isParagraphNode(topBlock)) { | ||
} | ||
if (topBlock.__indent !== 0) { | ||
return false; | ||
} | ||
const topBlockChildren = topBlock.getChildren(); | ||
const topBlockChildrenLength = topBlockChildren.length; | ||
for (let s = 0; s < topBlockChildrenLength; s++) { | ||
const child = topBlockChildren[i]; | ||
if (!lexical.$isTextNode(child)) { | ||
@@ -127,3 +104,2 @@ return false; | ||
} | ||
return true; | ||
@@ -138,3 +114,2 @@ } | ||
}; | ||
const replaceWithSimpleText = node => { | ||
@@ -145,7 +120,5 @@ const textNode = lexical.$createTextNode(node.getTextContent()); | ||
}; | ||
const getMode = node => { | ||
return node.getLatest().__mode; | ||
}; | ||
const textNodeTransform = node => { | ||
@@ -155,3 +128,2 @@ if (!node.isSimpleText()) { | ||
} | ||
const prevSibling = node.getPreviousSibling(); | ||
@@ -161,3 +133,2 @@ let text = node.getTextContent(); | ||
let match; | ||
if (lexical.$isTextNode(prevSibling)) { | ||
@@ -167,3 +138,2 @@ const previousText = prevSibling.getTextContent(); | ||
const prevMatch = getMatch(combinedText); | ||
if (isTargetNode(prevSibling)) { | ||
@@ -175,3 +145,2 @@ if (prevMatch === null || getMode(prevSibling) !== 0) { | ||
const diff = prevMatch.end - previousText.length; | ||
if (diff > 0) { | ||
@@ -182,3 +151,2 @@ const concatText = text.slice(0, diff); | ||
prevSibling.setTextContent(newTextContent); | ||
if (diff === text.length) { | ||
@@ -190,3 +158,2 @@ node.remove(); | ||
} | ||
return; | ||
@@ -198,5 +165,5 @@ } | ||
} | ||
} // eslint-disable-next-line no-constant-condition | ||
} | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -206,10 +173,7 @@ match = getMatch(text); | ||
text = nextText; | ||
if (nextText === '') { | ||
const nextSibling = currentNode.getNextSibling(); | ||
if (lexical.$isTextNode(nextSibling)) { | ||
nextText = currentNode.getTextContent() + nextSibling.getTextContent(); | ||
const nextMatch = getMatch(nextText); | ||
if (nextMatch === null) { | ||
@@ -221,3 +185,2 @@ if (isTargetNode(nextSibling)) { | ||
} | ||
return; | ||
@@ -230,3 +193,2 @@ } else if (nextMatch.start !== 0) { | ||
const nextMatch = getMatch(nextText); | ||
if (nextMatch !== null && nextMatch.start === 0) { | ||
@@ -236,13 +198,9 @@ return; | ||
} | ||
if (match === null) { | ||
return; | ||
} | ||
if (match.start === 0 && lexical.$isTextNode(prevSibling) && prevSibling.isTextEntity()) { | ||
continue; | ||
} | ||
let nodeToReplace; | ||
if (match.start === 0) { | ||
@@ -253,6 +211,4 @@ [nodeToReplace, currentNode] = currentNode.splitText(match.end); | ||
} | ||
const replacementNode = createNode(nodeToReplace); | ||
nodeToReplace.replace(replacementNode); | ||
if (currentNode == null) { | ||
@@ -263,7 +219,5 @@ return; | ||
}; | ||
const reverseNodeTransform = node => { | ||
const text = node.getTextContent(); | ||
const match = getMatch(text); | ||
if (match === null || match.start !== 0) { | ||
@@ -273,3 +227,2 @@ replaceWithSimpleText(node); | ||
} | ||
if (text.length > match.end) { | ||
@@ -280,5 +233,3 @@ // This will split out the rest of the text as simple text | ||
} | ||
const prevSibling = node.getPreviousSibling(); | ||
if (lexical.$isTextNode(prevSibling) && prevSibling.isTextEntity()) { | ||
@@ -288,8 +239,7 @@ replaceWithSimpleText(prevSibling); | ||
} | ||
const nextSibling = node.getNextSibling(); | ||
if (lexical.$isTextNode(nextSibling) && nextSibling.isTextEntity()) { | ||
replaceWithSimpleText(nextSibling); // This may have already been converted in the previous block | ||
replaceWithSimpleText(nextSibling); | ||
// This may have already been converted in the previous block | ||
if (isTargetNode(node)) { | ||
@@ -300,3 +250,2 @@ replaceWithSimpleText(node); | ||
}; | ||
const removePlainTextTransform = editor.registerNodeTransform(lexical.TextNode, textNodeTransform); | ||
@@ -303,0 +252,0 @@ const removeReverseNodeTransform = editor.registerNodeTransform(targetNode, reverseNodeTransform); |
@@ -12,6 +12,6 @@ { | ||
"license": "MIT", | ||
"version": "0.7.8", | ||
"version": "0.7.9", | ||
"main": "LexicalText.js", | ||
"peerDependencies": { | ||
"lexical": "0.7.8" | ||
"lexical": "0.7.9" | ||
}, | ||
@@ -18,0 +18,0 @@ "repository": { |
282
14744