@lexical/mark
Advanced tools
Comparing version 0.8.1 to 0.9.0
@@ -19,15 +19,18 @@ /** | ||
*/ | ||
/** @noInheritDoc */ | ||
class MarkNode extends lexical.ElementNode { | ||
/** @internal */ | ||
static getType() { | ||
return 'mark'; | ||
} | ||
static clone(node) { | ||
return new MarkNode(Array.from(node.__ids), node.__key); | ||
} | ||
static importDOM() { | ||
return null; | ||
} | ||
static importJSON(serializedNode) { | ||
@@ -40,5 +43,5 @@ const node = $createMarkNode(serializedNode.ids); | ||
} | ||
exportJSON() { | ||
return { | ||
...super.exportJSON(), | ||
return { ...super.exportJSON(), | ||
ids: this.getIDs(), | ||
@@ -49,2 +52,3 @@ type: 'mark', | ||
} | ||
constructor(ids, key) { | ||
@@ -54,10 +58,14 @@ super(key); | ||
} | ||
createDOM(config) { | ||
const element = document.createElement('mark'); | ||
utils.addClassNamesToElement(element, config.theme.mark); | ||
if (this.__ids.length > 1) { | ||
utils.addClassNamesToElement(element, config.theme.markOverlap); | ||
} | ||
return element; | ||
} | ||
updateDOM(prevNode, element, config) { | ||
@@ -69,2 +77,3 @@ const prevIDs = prevNode.__ids; | ||
const overlapTheme = config.theme.markOverlap; | ||
if (prevIDsCount !== nextIDsCount) { | ||
@@ -79,6 +88,9 @@ if (prevIDsCount === 1) { | ||
} | ||
return false; | ||
} | ||
hasID(id) { | ||
const ids = this.getIDs(); | ||
for (let i = 0; i < ids.length; i++) { | ||
@@ -89,4 +101,6 @@ if (id === ids[i]) { | ||
} | ||
return false; | ||
} | ||
getIDs() { | ||
@@ -96,7 +110,10 @@ const self = this.getLatest(); | ||
} | ||
addID(id) { | ||
const self = this.getWritable(); | ||
if ($isMarkNode(self)) { | ||
const ids = self.__ids; | ||
self.__ids = ids; | ||
for (let i = 0; i < ids.length; i++) { | ||
@@ -106,10 +123,14 @@ // If we already have it, don't add again | ||
} | ||
ids.push(id); | ||
} | ||
} | ||
deleteID(id) { | ||
const self = this.getWritable(); | ||
if ($isMarkNode(self)) { | ||
const ids = self.__ids; | ||
self.__ids = ids; | ||
for (let i = 0; i < ids.length; i++) { | ||
@@ -123,4 +144,6 @@ if (id === ids[i]) { | ||
} | ||
insertNewAfter(selection, restoreSelection = true) { | ||
const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection); | ||
if (lexical.$isElementNode(element)) { | ||
@@ -131,16 +154,22 @@ const markNode = $createMarkNode(this.__ids); | ||
} | ||
return null; | ||
} | ||
canInsertTextBefore() { | ||
return false; | ||
} | ||
canInsertTextAfter() { | ||
return false; | ||
} | ||
canBeEmpty() { | ||
return false; | ||
} | ||
isInline() { | ||
return true; | ||
} | ||
extractWithChild(child, selection, destination) { | ||
@@ -150,2 +179,3 @@ if (!lexical.$isRangeSelection(selection) || destination === 'html') { | ||
} | ||
const anchor = selection.anchor; | ||
@@ -159,5 +189,7 @@ const focus = selection.focus; | ||
} | ||
excludeFromCopy(destination) { | ||
return destination !== 'clone'; | ||
} | ||
} | ||
@@ -175,4 +207,6 @@ function $createMarkNode(ids) { | ||
let target = null; | ||
for (let i = 0; i < children.length; i++) { | ||
const child = children[i]; | ||
if (target === null) { | ||
@@ -183,4 +217,6 @@ node.insertBefore(child); | ||
} | ||
target = child; | ||
} | ||
node.remove(); | ||
@@ -196,10 +232,10 @@ } | ||
let currentNodeParent; | ||
let lastCreatedMarkNode; | ||
// 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 step out of their boundary and start | ||
// again after, if there are more nodes. | ||
for (let i = 0; i < nodesLength; i++) { | ||
const node = nodes[i]; | ||
if (lexical.$isElementNode(lastCreatedMarkNode) && lastCreatedMarkNode.isParentOf(node)) { | ||
@@ -209,5 +245,7 @@ // If the current node is a child of the last created mark node, there is nothing to do here | ||
} | ||
const isFirstNode = i === 0; | ||
const isLastNode = i === nodesLength - 1; | ||
let targetNode = null; | ||
if (lexical.$isTextNode(node)) { | ||
@@ -218,5 +256,7 @@ // Case 1: The node is a text node and we can split it | ||
const endTextOffset = isLastNode ? endOffset : textContentSize; | ||
if (startTextOffset === 0 && endTextOffset === 0) { | ||
continue; | ||
} | ||
const splitNodes = node.splitText(startTextOffset, endTextOffset); | ||
@@ -230,3 +270,2 @@ targetNode = splitNodes.length > 1 && (splitNodes.length === 3 || isFirstNode && !isLastNode || endTextOffset === textContentSize) ? splitNodes[1] : splitNodes[0]; | ||
// codebase. | ||
continue; | ||
@@ -238,2 +277,3 @@ } else if (lexical.$isElementNode(node) && node.isInline()) { | ||
} | ||
if (targetNode !== null) { | ||
@@ -247,3 +287,5 @@ // Now that we have a target node for wrapping with a mark, we can run | ||
} | ||
const parentNode = targetNode.getParent(); | ||
if (parentNode == null || !parentNode.is(currentNodeParent)) { | ||
@@ -254,3 +296,5 @@ // If the parent node is not the current node's parent node, we can | ||
} | ||
currentNodeParent = parentNode; | ||
if (lastCreatedMarkNode === undefined) { | ||
@@ -261,5 +305,5 @@ // If we don't have a created mark node, we can make one | ||
targetNode.insertBefore(lastCreatedMarkNode); | ||
} | ||
} // Add the target node to be wrapped in the latest created mark node | ||
// Add the target node to be wrapped in the latest created mark node | ||
lastCreatedMarkNode.append(targetNode); | ||
@@ -276,2 +320,3 @@ } else { | ||
let currentNode = node; | ||
while (currentNode !== null) { | ||
@@ -282,2 +327,3 @@ if ($isMarkNode(currentNode)) { | ||
const nextSibling = currentNode.getNextSibling(); | ||
if ($isMarkNode(nextSibling)) { | ||
@@ -287,4 +333,6 @@ return nextSibling.getIDs(); | ||
} | ||
currentNode = currentNode.getParent(); | ||
} | ||
return null; | ||
@@ -291,0 +339,0 @@ } |
@@ -11,9 +11,9 @@ { | ||
"license": "MIT", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"main": "LexicalMark.js", | ||
"peerDependencies": { | ||
"lexical": "0.8.1" | ||
"lexical": "0.9.0" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.8.1" | ||
"@lexical/utils": "0.9.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
17837
343
+ Added@lexical/list@0.9.0(transitive)
+ Added@lexical/selection@0.9.0(transitive)
+ Added@lexical/table@0.9.0(transitive)
+ Added@lexical/utils@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)
- Removed@lexical/utils@0.8.1(transitive)
- Removedlexical@0.8.1(transitive)
Updated@lexical/utils@0.9.0