@lexical/mark
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -217,6 +217,6 @@ /** | ||
let currentNodeParent; | ||
let currentMarkNode; // We only want wrap adjacent text nodes, line break nodes | ||
let lastCreatedMarkNode; // We only want wrap adjacent text nodes, line break nodes | ||
// and inline element nodes. For decorator nodes and block | ||
// element nodes, we stop out their boundary and start again | ||
// after, if there are more nodes. | ||
// element nodes, we step out of their boundary and start | ||
// again after, if there are more nodes. | ||
@@ -226,3 +226,4 @@ for (let i = 0; i < nodesLength; i++) { | ||
if (lexical.$isElementNode(currentMarkNode) && currentMarkNode.isParentOf(node)) { | ||
if (lexical.$isElementNode(lastCreatedMarkNode) && lastCreatedMarkNode.isParentOf(node)) { | ||
// If the current node is a child of the last created mark node, there is nothing to do here | ||
continue; | ||
@@ -236,2 +237,3 @@ } | ||
if (lexical.$isTextNode(node)) { | ||
// Case 1: The node is a text node and we can split it | ||
const textContentSize = node.getTextContentSize(); | ||
@@ -247,3 +249,12 @@ const startTextOffset = isFirstNode ? startOffset : 0; | ||
targetNode = splitNodes.length > 1 && (splitNodes.length === 3 || isFirstNode && !isLastNode || endTextOffset === textContentSize) ? splitNodes[1] : splitNodes[0]; | ||
} else if ($isMarkNode(node)) { | ||
// Case 2: the node is a mark node and we can ignore it as a target, | ||
// moving on to its children. Note that when we make a mark inside | ||
// another mark, it may utlimately be unnested by a call to | ||
// `registerNestedElementResolver<MarkNode>` somewhere else in the | ||
// codebase. | ||
continue; | ||
} else if (lexical.$isElementNode(node) && node.isInline()) { | ||
// Case 3: inline element nodes can be added in their entirety to the new | ||
// mark | ||
targetNode = node; | ||
@@ -253,3 +264,7 @@ } | ||
if (targetNode !== null) { | ||
// Now that we have a target node for wrapping with a mark, we can run | ||
// through special cases. | ||
if (targetNode && targetNode.is(currentNodeParent)) { | ||
// The current node is a child of the target node to be wrapped, there | ||
// is nothing to do here. | ||
continue; | ||
@@ -261,3 +276,5 @@ } | ||
if (parentNode == null || !parentNode.is(currentNodeParent)) { | ||
currentMarkNode = undefined; | ||
// If the parent node is not the current node's parent node, we can | ||
// clear the last created mark node. | ||
lastCreatedMarkNode = undefined; | ||
} | ||
@@ -267,11 +284,15 @@ | ||
if (currentMarkNode === undefined) { | ||
currentMarkNode = $createMarkNode([id]); | ||
targetNode.insertBefore(currentMarkNode); | ||
} | ||
if (lastCreatedMarkNode === undefined) { | ||
// If we don't have a created mark node, we can make one | ||
lastCreatedMarkNode = $createMarkNode([id]); | ||
targetNode.insertBefore(lastCreatedMarkNode); | ||
} // Add the target node to be wrapped in the latest created mark node | ||
currentMarkNode.append(targetNode); | ||
lastCreatedMarkNode.append(targetNode); | ||
} else { | ||
// If we don't have a target node to wrap we can clear our state and | ||
// continue on with the next node | ||
currentNodeParent = undefined; | ||
currentMarkNode = undefined; | ||
lastCreatedMarkNode = undefined; | ||
} | ||
@@ -278,0 +299,0 @@ } |
@@ -13,3 +13,3 @@ /** | ||
exports.$unwrapMarkNode=function(a){let b=a.getChildren(),c=null;for(let e=0;e<b.length;e++){let d=b[e];null===c?a.insertBefore(d):c.insertAfter(d);c=d}a.remove()}; | ||
exports.$wrapSelectionInMarkNode=function(a,b,c){let e=a.getNodes();var d=a.anchor.offset,h=a.focus.offset;a=e.length;let w=b?h:d;b=b?d:h;let r,k;for(d=0;d<a;d++){var f=e[d];if(l.$isElementNode(k)&&k.isParentOf(f))continue;h=0===d;let u=d===a-1;var g=null;if(l.$isTextNode(f)){g=f.getTextContentSize();let v=h?w:0,t=u?b:g;if(0===v&&0===t)continue;f=f.splitText(v,t);g=1<f.length&&(3===f.length||h&&!u||t===g)?f[1]:f[0]}else l.$isElementNode(f)&&f.isInline()&&(g=f);null!==g?g&&g.is(r)||(h=g.getParent(), | ||
null!=h&&h.is(r)||(k=void 0),r=h,void 0===k&&(k=p([c]),g.insertBefore(k)),k.append(g)):k=r=void 0}};exports.MarkNode=n | ||
exports.$wrapSelectionInMarkNode=function(a,b,c){let e=a.getNodes();var d=a.anchor.offset,h=a.focus.offset;a=e.length;let w=b?h:d;b=b?d:h;let r,k;for(d=0;d<a;d++){var f=e[d];if(l.$isElementNode(k)&&k.isParentOf(f))continue;h=0===d;let u=d===a-1;var g=null;if(l.$isTextNode(f)){g=f.getTextContentSize();let v=h?w:0,t=u?b:g;if(0===v&&0===t)continue;f=f.splitText(v,t);g=1<f.length&&(3===f.length||h&&!u||t===g)?f[1]:f[0]}else if(q(f))continue;else l.$isElementNode(f)&&f.isInline()&&(g=f);null!==g?g&&g.is(r)|| | ||
(h=g.getParent(),null!=h&&h.is(r)||(k=void 0),r=h,void 0===k&&(k=p([c]),g.insertBefore(k)),k.append(g)):k=r=void 0}};exports.MarkNode=n |
@@ -11,9 +11,9 @@ { | ||
"license": "MIT", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"main": "LexicalMark.js", | ||
"peerDependencies": { | ||
"lexical": "0.4.1" | ||
"lexical": "0.5.0" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.4.1" | ||
"@lexical/utils": "0.5.0" | ||
}, | ||
@@ -20,0 +20,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
17381
342
+ Added@lexical/list@0.5.0(transitive)
+ Added@lexical/table@0.5.0(transitive)
+ Added@lexical/utils@0.5.0(transitive)
+ Addedlexical@0.5.0(transitive)
- Removed@lexical/list@0.4.1(transitive)
- Removed@lexical/table@0.4.1(transitive)
- Removed@lexical/utils@0.4.1(transitive)
- Removedlexical@0.4.1(transitive)
Updated@lexical/utils@0.5.0