Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/list

Package Overview
Dependencies
Maintainers
8
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/list - npm Package Compare versions

Comparing version 0.12.2 to 0.12.3

341

LexicalList.dev.js

@@ -19,2 +19,3 @@ /**

*/
/**

@@ -25,11 +26,8 @@ * Checks the depth of listNode from the root node.

*/
function $getListDepth(listNode) {
let depth = 1;
let parent = listNode.getParent();
while (parent != null) {
if ($isListItemNode(parent)) {
const parentList = parent.getParent();
if ($isListNode(parentList)) {

@@ -40,3 +38,2 @@ depth++;

}
{

@@ -46,8 +43,7 @@ throw Error(`A ListItemNode must have a ListNode for a parent.`);

}
return depth;
}
return depth;
}
/**

@@ -58,6 +54,4 @@ * Finds the nearest ancestral ListNode and returns it, throws an invariant if listItem is not a ListItemNode.

*/
function $getTopListNode(listItem) {
let list = listItem.getParent();
if (!$isListNode(list)) {

@@ -68,8 +62,5 @@ {

}
let parent = list;
while (parent !== null) {
parent = parent.getParent();
if ($isListNode(parent)) {

@@ -79,5 +70,5 @@ list = parent;

}
return list;
}
/**

@@ -90,11 +81,8 @@ * A recursive Depth-First Search (Postorder Traversal) that finds all of a node's children

// This should probably be $getAllChildrenOfType
function $getAllListItems(node) {
let listItemNodes = [];
const listChildren = node.getChildren().filter($isListItemNode);
for (let i = 0; i < listChildren.length; i++) {
const listItemNode = listChildren[i];
const firstChild = listItemNode.getFirstChild();
if ($isListNode(firstChild)) {

@@ -106,5 +94,5 @@ listItemNodes = listItemNodes.concat($getAllListItems(firstChild));

}
return listItemNodes;
}
/**

@@ -115,6 +103,6 @@ * Checks to see if the passed node is a ListItemNode and has a ListNode as a child.

*/
function isNestedListNode(node) {
return $isListItemNode(node) && $isListNode(node.getFirstChild());
}
/**

@@ -127,3 +115,2 @@ * Takes a deeply nested ListNode or ListItemNode and traverses up the branch to delete the first

*/
function $removeHighestEmptyListParent(sublist) {

@@ -137,15 +124,12 @@ // Nodes may be repeatedly indented, to create deeply nested lists that each

let emptyListPtr = sublist;
while (emptyListPtr.getNextSibling() == null && emptyListPtr.getPreviousSibling() == null) {
const parent = emptyListPtr.getParent();
if (parent == null || !($isListItemNode(emptyListPtr) || $isListNode(emptyListPtr))) {
break;
}
emptyListPtr = parent;
}
emptyListPtr.remove();
}
/**

@@ -156,3 +140,2 @@ * Wraps a node into a ListItemNode.

*/
function wrapInListItem(node) {

@@ -170,11 +153,8 @@ const listItemWrapper = $createListItemNode();

*/
function $isSelectingEmptyListItem(anchorNode, nodes) {
return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
}
function $getListItemValue(listItem) {
const list = listItem.getParent();
let value = 1;
if (list != null) {

@@ -189,8 +169,5 @@ if (!$isListNode(list)) {

}
const siblings = listItem.getPreviousSiblings();
for (let i = 0; i < siblings.length; i++) {
const sibling = siblings[i];
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {

@@ -200,5 +177,5 @@ value++;

}
return value;
}
/**

@@ -214,8 +191,5 @@ * Inserts a new ListNode. If the selection's anchor node is an empty ListItemNode and is a child of

*/
function insertList(editor, listType) {
editor.update(() => {
const selection = lexical.$getSelection();
if (lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection)) {

@@ -226,10 +200,7 @@ const nodes = selection.getNodes();

const anchorNodeParent = anchorNode.getParent();
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
const list = $createListNode(listType);
if (lexical.$isRootOrShadowRoot(anchorNodeParent)) {
anchorNode.replace(list);
const listItem = $createListItemNode();
if (lexical.$isElementNode(anchorNode)) {

@@ -239,3 +210,2 @@ listItem.setFormat(anchorNode.getFormatType());

}
list.append(listItem);

@@ -247,10 +217,7 @@ } else if ($isListItemNode(anchorNode)) {

}
return;
} else {
const handled = new Set();
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if (lexical.$isElementNode(node) && node.isEmpty() && !handled.has(node.getKey())) {

@@ -260,9 +227,6 @@ createListOrMerge(node, listType);

}
if (lexical.$isLeafNode(node)) {
let parent = node.getParent();
while (parent != null) {
const parentKey = parent.getKey();
if ($isListNode(parent)) {

@@ -276,7 +240,5 @@ if (!handled.has(parentKey)) {

}
break;
} else {
const nextParent = parent.getParent();
if (lexical.$isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) {

@@ -287,3 +249,2 @@ handled.add(parentKey);

}
parent = nextParent;

@@ -298,7 +259,5 @@ }

}
function append(node, nodesToAppend) {
node.splice(node.getChildrenSize(), 0, nodesToAppend);
}
function createListOrMerge(node, listType) {

@@ -308,3 +267,2 @@ if ($isListNode(node)) {

}
const previousSibling = node.getPreviousSibling();

@@ -316,6 +274,6 @@ const nextSibling = node.getNextSibling();

append(listItem, node.getChildren());
if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
previousSibling.append(listItem);
node.remove(); // if the same type of list is on both sides, merge them.
node.remove();
// if the same type of list is on both sides, merge them.

@@ -326,3 +284,2 @@ if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {

}
return previousSibling;

@@ -341,2 +298,3 @@ } else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {

}
/**

@@ -348,8 +306,5 @@ * A recursive function that goes through each list and their children, including nested lists,

*/
function mergeLists(list1, list2) {
const listItem1 = list1.getLastChild();
const listItem2 = list2.getFirstChild();
if (listItem1 && listItem2 && isNestedListNode(listItem1) && isNestedListNode(listItem2)) {

@@ -359,5 +314,3 @@ mergeLists(listItem1.getFirstChild(), listItem2.getFirstChild());

}
const toMerge = list2.getChildren();
if (toMerge.length > 0) {

@@ -367,5 +320,5 @@ list1.append(...toMerge);

}
list2.remove();
}
/**

@@ -378,7 +331,5 @@ * Searches for the nearest ancestral ListNode and removes it. If selection is an empty ListItemNode

*/
function removeList(editor) {
editor.update(() => {
const selection = lexical.$getSelection();
if (lexical.$isRangeSelection(selection)) {

@@ -388,3 +339,2 @@ const listNodes = new Set();

const anchorNode = selection.anchor.getNode();
if ($isSelectingEmptyListItem(anchorNode, nodes)) {

@@ -395,6 +345,4 @@ listNodes.add($getTopListNode(anchorNode));

const node = nodes[i];
if (lexical.$isLeafNode(node)) {
const listItemNode = utils.$getNearestNodeOfType(node, ListItemNode);
if (listItemNode != null) {

@@ -406,7 +354,5 @@ listNodes.add($getTopListNode(listItemNode));

}
for (const listNode of listNodes) {
let insertionPoint = listNode;
const listItems = $getAllListItems(listNode);
for (const listItemNode of listItems) {

@@ -416,3 +362,5 @@ const paragraph = lexical.$createParagraphNode();

insertionPoint.insertAfter(paragraph);
insertionPoint = paragraph; // When the anchor and focus fall on the textNode
insertionPoint = paragraph;
// When the anchor and focus fall on the textNode
// we don't have to change the selection because the textNode will be appended to

@@ -423,14 +371,10 @@ // the newly generated paragraph.

// we should manually set the selection's focus and anchor to the newly generated paragraph.
if (listItemNode.__key === selection.anchor.key) {
selection.anchor.set(paragraph.getKey(), 0, 'element');
}
if (listItemNode.__key === selection.focus.key) {
selection.focus.set(paragraph.getKey(), 0, 'element');
}
listItemNode.remove();
}
listNode.remove();

@@ -441,2 +385,3 @@ }

}
/**

@@ -449,14 +394,10 @@ * Takes the value of a child ListItemNode and makes it the value the ListItemNode

*/
function updateChildrenListItemValue(list, children) {
const childrenOrExisting = children || list.getChildren();
if (childrenOrExisting !== undefined) {
for (let i = 0; i < childrenOrExisting.length; i++) {
const child = childrenOrExisting[i];
if ($isListItemNode(child)) {
const prevValue = child.getValue();
const nextValue = $getListItemValue(child);
if (prevValue !== nextValue) {

@@ -469,2 +410,3 @@ child.setValue(nextValue);

}
/**

@@ -476,23 +418,20 @@ * Adds an empty ListNode/ListItemNode chain at listItemNode, so as to

*/
function $handleIndent(listItemNode) {
// go through each node and decide where to move it.
const removed = new Set();
if (isNestedListNode(listItemNode) || removed.has(listItemNode.getKey())) {
return;
}
const parent = listItemNode.getParent();
const parent = listItemNode.getParent(); // We can cast both of the below `isNestedListNode` only returns a boolean type instead of a user-defined type guards
// We can cast both of the below `isNestedListNode` only returns a boolean type instead of a user-defined type guards
const nextSibling = listItemNode.getNextSibling();
const previousSibling = listItemNode.getPreviousSibling(); // if there are nested lists on either side, merge them all together.
const previousSibling = listItemNode.getPreviousSibling();
// if there are nested lists on either side, merge them all together.
if (isNestedListNode(nextSibling) && isNestedListNode(previousSibling)) {
const innerList = previousSibling.getFirstChild();
if ($isListNode(innerList)) {
innerList.append(listItemNode);
const nextInnerList = nextSibling.getFirstChild();
if ($isListNode(nextInnerList)) {

@@ -504,3 +443,2 @@ const children = nextInnerList.getChildren();

}
updateChildrenListItemValue(innerList);

@@ -511,10 +449,7 @@ }

const innerList = nextSibling.getFirstChild();
if ($isListNode(innerList)) {
const firstChild = innerList.getFirstChild();
if (firstChild !== null) {
firstChild.insertBefore(listItemNode);
}
updateChildrenListItemValue(innerList);

@@ -524,3 +459,2 @@ }

const innerList = previousSibling.getFirstChild();
if ($isListNode(innerList)) {

@@ -532,2 +466,3 @@ innerList.append(listItemNode);

// otherwise, we need to create a new nested ListNode
if ($isListNode(parent)) {

@@ -538,3 +473,2 @@ const newListItem = $createListItemNode();

newList.append(listItemNode);
if (previousSibling) {

@@ -547,7 +481,5 @@ previousSibling.insertAfter(newListItem);

}
updateChildrenListItemValue(newList);
}
}
if ($isListNode(parent)) {

@@ -557,2 +489,3 @@ updateChildrenListItemValue(parent);

}
/**

@@ -564,12 +497,12 @@ * Removes an indent by removing an empty ListNode/ListItemNode chain. An indented ListItemNode

*/
function $handleOutdent(listItemNode) {
// go through each node and decide where to move it.
if (isNestedListNode(listItemNode)) {
return;
}
const parentList = listItemNode.getParent();
const grandparentListItem = parentList ? parentList.getParent() : undefined;
const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined; // If it doesn't have these ancestors, it's not indented.
const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined;
// If it doesn't have these ancestors, it's not indented.

@@ -581,14 +514,11 @@ if ($isListNode(greatGrandparentList) && $isListItemNode(grandparentListItem) && $isListNode(parentList)) {

const lastChild = parentList ? parentList.getLastChild() : undefined;
if (listItemNode.is(firstChild)) {
grandparentListItem.insertBefore(listItemNode);
if (parentList.isEmpty()) {
grandparentListItem.remove();
} // if it's the last child in it's parent list, insert it into the
}
// if it's the last child in it's parent list, insert it into the
// great grandparent list after the grandparent.
} else if (listItemNode.is(lastChild)) {
grandparentListItem.insertAfter(listItemNode);
if (parentList.isEmpty()) {

@@ -607,10 +537,9 @@ grandparentListItem.remove();

nextSiblingsListItem.append(nextSiblingsList);
append(nextSiblingsList, listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
append(nextSiblingsList, listItemNode.getNextSiblings());
// put the sibling nested lists on either side of the grandparent list item in the great grandparent.
grandparentListItem.insertBefore(previousSiblingsListItem);
grandparentListItem.insertAfter(nextSiblingsListItem); // replace the grandparent list item (now between the siblings) with the outdented list item.
grandparentListItem.insertAfter(nextSiblingsListItem);
// replace the grandparent list item (now between the siblings) with the outdented list item.
grandparentListItem.replace(listItemNode);
}
updateChildrenListItemValue(parentList);

@@ -620,2 +549,3 @@ updateChildrenListItemValue(greatGrandparentList);

}
/**

@@ -630,27 +560,19 @@ * Attempts to insert a ParagraphNode at selection and selects the new node. The selection must contain a ListItemNode

*/
function $handleListInsertParagraph() {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed()) {
return false;
} // Only run this code on empty list items
}
// Only run this code on empty list items
const anchor = selection.anchor.getNode();
if (!$isListItemNode(anchor) || anchor.getChildrenSize() !== 0) {
return false;
}
const topListNode = $getTopListNode(anchor);
const parent = anchor.getParent();
if (!$isListNode(parent)) {
throw Error(`A ListItemNode must have a ListNode for a parent.`);
}
const grandparent = parent.getParent();
let replacementNode;
if (lexical.$isRootOrShadowRoot(grandparent)) {

@@ -665,9 +587,6 @@ replacementNode = lexical.$createParagraphNode();

}
replacementNode.select();
const nextSiblings = anchor.getNextSiblings();
if (nextSiblings.length > 0) {
const newList = $createListNode(parent.getListType());
if (lexical.$isParagraphNode(replacementNode)) {

@@ -680,3 +599,2 @@ replacementNode.insertAfter(newList);

}
nextSiblings.forEach(sibling => {

@@ -686,5 +604,5 @@ sibling.remove();

});
} // Don't leave hanging nested empty lists
}
// Don't leave hanging nested empty lists
$removeHighestEmptyListParent(anchor);

@@ -701,3 +619,2 @@ return true;

*/
/** @noInheritDoc */

@@ -708,10 +625,9 @@ class ListItemNode extends lexical.ElementNode {

/** @internal */
static getType() {
return 'listitem';
}
static clone(node) {
return new ListItemNode(node.__value, node.__checked, node.__key);
}
constructor(value, checked, key) {

@@ -722,11 +638,8 @@ super(key);

}
createDOM(config) {
const element = document.createElement('li');
const parent = this.getParent();
if ($isListNode(parent) && parent.getListType() === 'check') {
updateListItemChecked(element, this, null);
}
element.value = this.__value;

@@ -736,11 +649,8 @@ $setListItemThemeClassNames(element, config.theme, this);

}
updateDOM(prevNode, dom, config) {
const parent = this.getParent();
if ($isListNode(parent) && parent.getListType() === 'check') {
updateListItemChecked(dom, this, prevNode);
} // @ts-expect-error - this is always HTMLListItemElement
}
// @ts-expect-error - this is always HTMLListItemElement
dom.value = this.__value;

@@ -750,10 +660,7 @@ $setListItemThemeClassNames(dom, config.theme, this);

}
static transform() {
return node => {
const parent = node.getParent();
if ($isListNode(parent)) {
updateChildrenListItemValue(parent);
if (parent.getListType() !== 'check' && node.getChecked() != null) {

@@ -765,3 +672,2 @@ node.setChecked(undefined);

}
static importDOM() {

@@ -775,3 +681,2 @@ return {

}
static importJSON(serializedNode) {

@@ -785,5 +690,12 @@ const node = $createListItemNode();

}
exportDOM(editor) {
const element = this.createDOM(editor._config);
element.style.textAlign = this.getFormatType();
return {
element
};
}
exportJSON() {
return { ...super.exportJSON(),
return {
...super.exportJSON(),
checked: this.getChecked(),

@@ -795,7 +707,5 @@ type: 'listitem',

}
append(...nodes) {
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if (lexical.$isElementNode(node) && this.canMergeWith(node)) {

@@ -809,6 +719,4 @@ const children = node.getChildren();

}
return this;
}
replace(replaceWithNode, includeChildren) {

@@ -818,7 +726,5 @@ if ($isListItemNode(replaceWithNode)) {

}
this.setIndent(0);
const list = this.getParentOrThrow();
if (!$isListNode(list)) return replaceWithNode;
if (list.__first === this.getKey()) {

@@ -832,3 +738,2 @@ list.insertBefore(replaceWithNode);

let nextSibling = this.getNextSibling();
while (nextSibling) {

@@ -839,7 +744,5 @@ const nodeToAppend = nextSibling;

}
list.insertAfter(replaceWithNode);
replaceWithNode.insertAfter(newList);
}
if (includeChildren) {

@@ -850,15 +753,10 @@ this.getChildren().forEach(child => {

}
this.remove();
if (list.getChildrenSize() === 0) {
list.remove();
}
return replaceWithNode;
}
insertAfter(node, restoreSelection = true) {
const listNode = this.getParentOrThrow();
if (!$isListNode(listNode)) {

@@ -869,16 +767,13 @@ {

}
const siblings = this.getNextSiblings();
if ($isListItemNode(node)) {
const after = super.insertAfter(node, restoreSelection);
const afterListNode = node.getParentOrThrow();
if ($isListNode(afterListNode)) {
updateChildrenListItemValue(afterListNode);
}
return after;
} // Attempt to merge if the list is of the same type.
}
// Attempt to merge if the list is of the same type.

@@ -888,3 +783,2 @@ if ($isListNode(node)) {

const children = node.getChildren();
for (let i = children.length - 1; i >= 0; i--) {

@@ -894,10 +788,8 @@ child = children[i];

}
return child;
}
return child;
} // Otherwise, split the list
// Otherwise, split the list
// Split the lists and insert the node in between them
listNode.insertAfter(node, restoreSelection);
if (siblings.length !== 0) {

@@ -908,6 +800,4 @@ const newListNode = $createListNode(listNode.getListType());

}
return node;
}
remove(preserveEmptyParent) {

@@ -917,3 +807,2 @@ const prevSibling = this.getPreviousSibling();

super.remove(preserveEmptyParent);
if (prevSibling && nextSibling && isNestedListNode(prevSibling) && isNestedListNode(nextSibling)) {

@@ -924,3 +813,2 @@ mergeLists(prevSibling.getFirstChild(), nextSibling.getFirstChild());

const parent = nextSibling.getParent();
if ($isListNode(parent)) {

@@ -931,3 +819,2 @@ updateChildrenListItemValue(parent);

}
insertNewAfter(_, restoreSelection = true) {

@@ -938,3 +825,2 @@ const newElement = $createListItemNode(this.__checked == null ? undefined : false);

}
collapseAtStart(selection) {

@@ -947,3 +833,2 @@ const paragraph = lexical.$createParagraphNode();

const isIndented = $isListItemNode(listNodeParent);
if (listNode.getChildrenSize() === 1) {

@@ -957,13 +842,11 @@ if (isIndented) {

listNode.insertBefore(paragraph);
listNode.remove(); // If we have selection on the list item, we'll need to move it
listNode.remove();
// If we have selection on the list item, we'll need to move it
// to the paragraph
const anchor = selection.anchor;
const focus = selection.focus;
const key = paragraph.getKey();
if (anchor.type === 'element' && anchor.getNode().is(this)) {
anchor.set(key, anchor.offset, 'element');
}
if (focus.type === 'element' && focus.getNode().is(this)) {

@@ -977,6 +860,4 @@ focus.set(key, focus.offset, 'element');

}
return true;
}
getValue() {

@@ -986,3 +867,2 @@ const self = this.getLatest();

}
setValue(value) {

@@ -992,3 +872,2 @@ const self = this.getWritable();

}
getChecked() {

@@ -998,3 +877,2 @@ const self = this.getLatest();

}
setChecked(checked) {

@@ -1004,19 +882,14 @@ const self = this.getWritable();

}
toggleChecked() {
this.setChecked(!this.__checked);
}
getIndent() {
// If we don't have a parent, we are likely serializing
const parent = this.getParent();
if (parent === null) {
return this.getLatest().__indent;
} // ListItemNode should always have a ListNode for a parent.
}
// ListItemNode should always have a ListNode for a parent.
let listNodeParent = parent.getParentOrThrow();
let indentLevel = 0;
while ($isListItemNode(listNodeParent)) {

@@ -1026,6 +899,4 @@ listNodeParent = listNodeParent.getParentOrThrow().getParentOrThrow();

}
return indentLevel;
}
setIndent(indent) {

@@ -1035,5 +906,3 @@ if (!(typeof indent === 'number' && indent > -1)) {

}
let currentIndent = this.getIndent();
while (currentIndent !== indent) {

@@ -1048,10 +917,7 @@ if (currentIndent < indent) {

}
return this;
}
insertBefore(nodeToInsert) {
if ($isListItemNode(nodeToInsert)) {
const parent = this.getParentOrThrow();
if ($isListNode(parent)) {

@@ -1062,18 +928,13 @@ const siblings = this.getNextSiblings();

}
return super.insertBefore(nodeToInsert);
}
canInsertAfter(node) {
return $isListItemNode(node);
}
canReplaceWith(replacement) {
return $isListItemNode(replacement);
}
canMergeWith(node) {
return lexical.$isParagraphNode(node) || $isListItemNode(node);
}
extractWithChild(child, selection) {

@@ -1083,3 +944,2 @@ if (!lexical.$isRangeSelection(selection)) {

}
const anchorNode = selection.anchor.getNode();

@@ -1089,13 +949,9 @@ const focusNode = selection.focus.getNode();

}
isParentRequired() {
return true;
}
createParentElementNode() {
return $createListNode('bullet');
}
}
function $setListItemThemeClassNames(dom, editorThemeClasses, node) {

@@ -1107,7 +963,5 @@ const classesToAdd = [];

let nestedListItemClassName;
if (listTheme && listTheme.nested) {
nestedListItemClassName = listTheme.nested.listitem;
}
if (listItemClassName !== undefined) {

@@ -1117,3 +971,2 @@ const listItemClasses = listItemClassName.split(' ');

}
if (listTheme) {

@@ -1123,11 +976,8 @@ const parentNode = node.getParent();

const checked = node.getChecked();
if (!isCheckList || checked) {
classesToRemove.push(listTheme.listitemUnchecked);
}
if (!isCheckList || !checked) {
classesToRemove.push(listTheme.listitemChecked);
}
if (isCheckList) {

@@ -1137,6 +987,4 @@ classesToAdd.push(checked ? listTheme.listitemChecked : listTheme.listitemUnchecked);

}
if (nestedListItemClassName !== undefined) {
const nestedListItemClasses = nestedListItemClassName.split(' ');
if (node.getChildren().some(child => $isListNode(child))) {

@@ -1148,7 +996,5 @@ classesToAdd.push(...nestedListItemClasses);

}
if (classesToRemove.length > 0) {
utils.removeClassNamesFromElement(dom, ...classesToRemove);
}
if (classesToAdd.length > 0) {

@@ -1158,3 +1004,2 @@ utils.addClassNamesToElement(dom, ...classesToAdd);

}
function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {

@@ -1169,3 +1014,2 @@ // Only add attributes for leaf list items

dom.setAttribute('tabIndex', '-1');
if (!prevListItemNode || listItemNode.__checked !== prevListItemNode.__checked) {

@@ -1176,3 +1020,2 @@ dom.setAttribute('aria-checked', listItemNode.getChecked() ? 'true' : 'false');

}
function convertListItemElement(domNode) {

@@ -1184,2 +1027,3 @@ const checked = utils.isHTMLElement(domNode) && domNode.getAttribute('aria-checked') === 'true';

}
/**

@@ -1190,7 +1034,6 @@ * Creates a new List Item node, passing true/false will convert it to a checkbox input.

*/
function $createListItemNode(checked) {
return lexical.$applyNodeReplacement(new ListItemNode(undefined, checked));
}
/**

@@ -1201,3 +1044,2 @@ * Checks to see if the node is a ListItemNode.

*/
function $isListItemNode(node) {

@@ -1214,3 +1056,2 @@ return node instanceof ListItemNode;

*/
/** @noInheritDoc */

@@ -1223,6 +1064,6 @@ class ListNode extends lexical.ElementNode {

/** @internal */
static getType() {
return 'list';
}
static clone(node) {

@@ -1232,8 +1073,5 @@ const listType = node.__listType || TAG_TO_LIST_TYPE[node.__tag];

}
constructor(listType, start, key) {
super(key);
const _listType = TAG_TO_LIST_TYPE[listType] || listType;
this.__listType = _listType;

@@ -1243,7 +1081,5 @@ this.__tag = _listType === 'number' ? 'ol' : 'ul';

}
getTag() {
return this.__tag;
}
setListType(type) {

@@ -1254,11 +1090,10 @@ const writable = this.getWritable();

}
getListType() {
return this.__listType;
}
getStart() {
return this.__start;
} // View
}
// View

@@ -1268,8 +1103,6 @@ createDOM(config, _editor) {

const dom = document.createElement(tag);
if (this.__start !== 1) {
dom.setAttribute('start', String(this.__start));
} // @ts-expect-error Internal field.
}
// @ts-expect-error Internal field.
dom.__lexicalListType = this.__listType;

@@ -1279,3 +1112,2 @@ setListThemeClassNames(dom, config.theme, this);

}
updateDOM(prevNode, dom, config) {

@@ -1285,7 +1117,5 @@ if (prevNode.__tag !== this.__tag) {

}
setListThemeClassNames(dom, config.theme, this);
return false;
}
static importDOM() {

@@ -1303,3 +1133,2 @@ return {

}
static importJSON(serializedNode) {

@@ -1312,3 +1141,2 @@ const node = $createListNode(serializedNode.listType, serializedNode.start);

}
exportDOM(editor) {

@@ -1318,3 +1146,2 @@ const {

} = super.exportDOM(editor);
if (element && utils.isHTMLElement(element)) {

@@ -1324,3 +1151,2 @@ if (this.__start !== 1) {

}
if (this.__listType === 'check') {

@@ -1330,3 +1156,2 @@ element.setAttribute('__lexicalListType', 'check');

}
return {

@@ -1336,5 +1161,5 @@ element

}
exportJSON() {
return { ...super.exportJSON(),
return {
...super.exportJSON(),
listType: this.getListType(),

@@ -1347,15 +1172,11 @@ start: this.getStart(),

}
canBeEmpty() {
return false;
}
canIndent() {
return false;
}
append(...nodesToAppend) {
for (let i = 0; i < nodesToAppend.length; i++) {
const currentNode = nodesToAppend[i];
if ($isListItemNode(currentNode)) {

@@ -1365,3 +1186,2 @@ super.append(currentNode);

const listItemNode = $createListItemNode();
if ($isListNode(currentNode)) {

@@ -1375,17 +1195,12 @@ listItemNode.append(currentNode);

}
super.append(listItemNode);
}
}
updateChildrenListItemValue(this);
return this;
}
extractWithChild(child) {
return $isListItemNode(child);
}
}
function setListThemeClassNames(dom, editorThemeClasses, node) {

@@ -1395,3 +1210,2 @@ const classesToAdd = [];

const listTheme = editorThemeClasses.list;
if (listTheme !== undefined) {

@@ -1405,15 +1219,11 @@ const listLevelsClassNames = listTheme[`${node.__tag}Depth`] || [];

const nestedListTheme = listTheme.nested;
if (nestedListTheme !== undefined && nestedListTheme.list) {
nestedListClassName = nestedListTheme.list;
}
if (listClassName !== undefined) {
classesToAdd.push(listClassName);
}
if (listLevelClassName !== undefined) {
const listItemClasses = listLevelClassName.split(' ');
classesToAdd.push(...listItemClasses);
for (let i = 0; i < listLevelsClassNames.length; i++) {

@@ -1425,6 +1235,4 @@ if (i !== normalizedListDepth) {

}
if (nestedListClassName !== undefined) {
const nestedListItemClasses = nestedListClassName.split(' ');
if (listDepth > 1) {

@@ -1437,7 +1245,5 @@ classesToAdd.push(...nestedListItemClasses);

}
if (classesToRemove.length > 0) {
utils.removeClassNamesFromElement(dom, ...classesToRemove);
}
if (classesToAdd.length > 0) {

@@ -1447,2 +1253,3 @@ utils.addClassNamesToElement(dom, ...classesToAdd);

}
/*

@@ -1453,14 +1260,9 @@ * This function normalizes the children of a ListNode after the conversion from HTML,

*/
function normalizeChildren(nodes) {
const normalizedListItems = [];
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if ($isListItemNode(node)) {
normalizedListItems.push(node);
const children = node.getChildren();
if (children.length > 1) {

@@ -1477,10 +1279,7 @@ children.forEach(child => {

}
return normalizedListItems;
}
function convertListNode(domNode) {
const nodeName = domNode.nodeName.toLowerCase();
let node = null;
if (nodeName === 'ol') {

@@ -1497,3 +1296,2 @@ // @ts-ignore

}
return {

@@ -1504,3 +1302,2 @@ after: normalizeChildren,

}
const TAG_TO_LIST_TYPE = {

@@ -1510,2 +1307,3 @@ ol: 'number',

};
/**

@@ -1517,6 +1315,6 @@ * Creates a ListNode of listType.

*/
function $createListNode(listType, start = 1) {
return lexical.$applyNodeReplacement(new ListNode(listType, start));
}
/**

@@ -1527,3 +1325,2 @@ * Checks to see if the node is a ListNode.

*/
function $isListNode(node) {

@@ -1530,0 +1327,0 @@ return node instanceof ListNode;

@@ -14,10 +14,10 @@ /**

class H extends h.ElementNode{static getType(){return"listitem"}static clone(a){return new H(a.__value,a.__checked,a.__key)}constructor(a,b,c){super(c);this.__value=void 0===a?1:a;this.__checked=b}createDOM(a){let b=document.createElement("li"),c=this.getParent();q(c)&&"check"===c.getListType()&&I(b,this,null);b.value=this.__value;J(b,a.theme,this);return b}updateDOM(a,b,c){let d=this.getParent();q(d)&&"check"===d.getListType()&&I(b,this,a);b.value=this.__value;J(b,c.theme,this);return!1}static transform(){return a=>
{let b=a.getParent();q(b)&&(E(b),"check"!==b.getListType()&&null!=a.getChecked()&&a.setChecked(void 0))}}static importDOM(){return{li:()=>({conversion:K,priority:0})}}static importJSON(a){let b=y();b.setChecked(a.checked);b.setValue(a.value);b.setFormat(a.format);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...a){for(let b=0;b<a.length;b++){let c=a[b];if(h.$isElementNode(c)&&this.canMergeWith(c)){let d=
c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a,b){if(p(a))return super.replace(a);this.setIndent(0);let c=this.getParentOrThrow();if(!q(c))return a;if(c.__first===this.getKey())c.insertBefore(a);else if(c.__last===this.getKey())c.insertAfter(a);else{let d=D(c.getListType()),e=this.getNextSibling();for(;e;){let f=e;e=e.getNextSibling();d.append(f)}c.insertAfter(a);a.insertAfter(d)}b&&this.getChildren().forEach(d=>{a.append(d)});this.remove();0===c.getChildrenSize()&&
c.remove();return a}insertAfter(a,b=!0){var c=this.getParentOrThrow();q(c)||m(39);var d=this.getNextSiblings();if(p(a))return b=super.insertAfter(a,b),a=a.getParentOrThrow(),q(a)&&E(a),b;if(q(a)){c=a;a=a.getChildren();for(d=a.length-1;0<=d;d--)c=a[d],this.insertAfter(c,b);return c}c.insertAfter(a,b);if(0!==d.length){let e=D(c.getListType());d.forEach(f=>e.append(f));a.insertAfter(e,b)}return a}remove(a){let b=this.getPreviousSibling(),c=this.getNextSibling();super.remove(a);b&&c&&u(b)&&u(c)?(F(b.getFirstChild(),
c.getFirstChild()),c.remove()):c&&(a=c.getParent(),q(a)&&E(a))}insertNewAfter(a,b=!0){a=y(null==this.__checked?void 0:!1);this.insertAfter(a,b);return a}collapseAtStart(a){let b=h.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();let e=p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.insertBefore(b),c.remove(),c=a.anchor,a=a.focus,d=b.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===
a.type&&a.getNode().is(this)&&a.set(d,a.offset,"element")):(c.insertBefore(b),this.remove());return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=a}getChecked(){return this.getLatest().__checked}setChecked(a){this.getWritable().__checked=a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){var a=this.getParent();if(null===a)return this.getLatest().__indent;a=a.getParentOrThrow();let b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){"number"===
typeof a&&-1<a||m(117);let b=this.getIndent();for(;b!==a;)if(b<a){a:{var c=new Set;if(u(this)||c.has(this.getKey()))break a;let g=this.getParent();var d=this.getNextSibling(),e=this.getPreviousSibling();if(u(d)&&u(e)){if(e=e.getFirstChild(),q(e)){e.append(this);var f=d.getFirstChild();q(f)&&(f=f.getChildren(),B(e,f),d.remove(),c.add(d.getKey()));E(e)}}else u(d)?(d=d.getFirstChild(),q(d)&&(c=d.getFirstChild(),null!==c&&c.insertBefore(this),E(d))):u(e)?(d=e.getFirstChild(),q(d)&&(d.append(this),E(d))):
q(g)&&(c=y(),f=D(g.getListType()),c.append(f),f.append(this),e?e.insertAfter(c):d?d.insertBefore(c):g.append(c),E(f));q(g)&&E(g)}b++}else G(this),b--;return this}insertBefore(a){if(p(a)){let b=this.getParentOrThrow();if(q(b)){let c=this.getNextSiblings();E(b,c)}}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||p(a)}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();let c=b.focus.getNode();
return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return D("bullet")}}
{let b=a.getParent();q(b)&&(E(b),"check"!==b.getListType()&&null!=a.getChecked()&&a.setChecked(void 0))}}static importDOM(){return{li:()=>({conversion:K,priority:0})}}static importJSON(a){let b=y();b.setChecked(a.checked);b.setValue(a.value);b.setFormat(a.format);b.setDirection(a.direction);return b}exportDOM(a){a=this.createDOM(a._config);a.style.textAlign=this.getFormatType();return{element:a}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),
version:1}}append(...a){for(let b=0;b<a.length;b++){let c=a[b];if(h.$isElementNode(c)&&this.canMergeWith(c)){let d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a,b){if(p(a))return super.replace(a);this.setIndent(0);let c=this.getParentOrThrow();if(!q(c))return a;if(c.__first===this.getKey())c.insertBefore(a);else if(c.__last===this.getKey())c.insertAfter(a);else{let d=D(c.getListType()),e=this.getNextSibling();for(;e;){let f=e;e=e.getNextSibling();d.append(f)}c.insertAfter(a);
a.insertAfter(d)}b&&this.getChildren().forEach(d=>{a.append(d)});this.remove();0===c.getChildrenSize()&&c.remove();return a}insertAfter(a,b=!0){var c=this.getParentOrThrow();q(c)||m(39);var d=this.getNextSiblings();if(p(a))return b=super.insertAfter(a,b),a=a.getParentOrThrow(),q(a)&&E(a),b;if(q(a)){c=a;a=a.getChildren();for(d=a.length-1;0<=d;d--)c=a[d],this.insertAfter(c,b);return c}c.insertAfter(a,b);if(0!==d.length){let e=D(c.getListType());d.forEach(f=>e.append(f));a.insertAfter(e,b)}return a}remove(a){let b=
this.getPreviousSibling(),c=this.getNextSibling();super.remove(a);b&&c&&u(b)&&u(c)?(F(b.getFirstChild(),c.getFirstChild()),c.remove()):c&&(a=c.getParent(),q(a)&&E(a))}insertNewAfter(a,b=!0){a=y(null==this.__checked?void 0:!1);this.insertAfter(a,b);return a}collapseAtStart(a){let b=h.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();let e=p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.insertBefore(b),c.remove(),c=a.anchor,
a=a.focus,d=b.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===a.type&&a.getNode().is(this)&&a.set(d,a.offset,"element")):(c.insertBefore(b),this.remove());return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=a}getChecked(){return this.getLatest().__checked}setChecked(a){this.getWritable().__checked=a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){var a=this.getParent();if(null===a)return this.getLatest().__indent;
a=a.getParentOrThrow();let b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){"number"===typeof a&&-1<a||m(117);let b=this.getIndent();for(;b!==a;)if(b<a){a:{var c=new Set;if(u(this)||c.has(this.getKey()))break a;let g=this.getParent();var d=this.getNextSibling(),e=this.getPreviousSibling();if(u(d)&&u(e)){if(e=e.getFirstChild(),q(e)){e.append(this);var f=d.getFirstChild();q(f)&&(f=f.getChildren(),B(e,f),d.remove(),c.add(d.getKey()));E(e)}}else u(d)?(d=d.getFirstChild(),
q(d)&&(c=d.getFirstChild(),null!==c&&c.insertBefore(this),E(d))):u(e)?(d=e.getFirstChild(),q(d)&&(d.append(this),E(d))):q(g)&&(c=y(),f=D(g.getListType()),c.append(f),f.append(this),e?e.insertAfter(c):d?d.insertBefore(c):g.append(c),E(f));q(g)&&E(g)}b++}else G(this),b--;return this}insertBefore(a){if(p(a)){let b=this.getParentOrThrow();if(q(b)){let c=this.getNextSiblings();E(b,c)}}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||
p(a)}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return D("bullet")}}
function J(a,b,c){let d=[],e=[];var f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var g=b.nested.listitem;void 0!==f&&(f=f.split(" "),d.push(...f));if(b){f=c.getParent();f=q(f)&&"check"===f.getListType();let l=c.getChecked();f&&!l||e.push(b.listitemUnchecked);f&&l||e.push(b.listitemChecked);f&&d.push(l?b.listitemChecked:b.listitemUnchecked)}void 0!==g&&(g=g.split(" "),c.getChildren().some(l=>q(l))?d.push(...g):e.push(...g));0<e.length&&k.removeClassNamesFromElement(a,...e);0<d.length&&k.addClassNamesToElement(a,

@@ -24,0 +24,0 @@ ...d)}function I(a,b,c){q(b.getFirstChild())?(a.removeAttribute("role"),a.removeAttribute("tabIndex"),a.removeAttribute("aria-checked")):(a.setAttribute("role","checkbox"),a.setAttribute("tabIndex","-1"),c&&b.__checked===c.__checked||a.setAttribute("aria-checked",b.getChecked()?"true":"false"))}function K(a){a=k.isHTMLElement(a)&&"true"===a.getAttribute("aria-checked");return{node:y(a)}}function y(a){return h.$applyNodeReplacement(new H(void 0,a))}function p(a){return a instanceof H}

@@ -8,4 +8,4 @@ /**

*/
import type { DOMConversionMap, EditorConfig, GridSelection, LexicalNode, NodeKey, NodeSelection, ParagraphNode, RangeSelection, SerializedElementNode, Spread } from 'lexical';
import { ElementNode } from 'lexical';
import type { DOMConversionMap, DOMExportOutput, EditorConfig, GridSelection, LexicalNode, NodeKey, NodeSelection, ParagraphNode, RangeSelection, SerializedElementNode, Spread } from 'lexical';
import { ElementNode, LexicalEditor } from 'lexical';
export type SerializedListItemNode = Spread<{

@@ -29,2 +29,3 @@ checked: boolean | undefined;

static importJSON(serializedNode: SerializedListItemNode): ListItemNode;
exportDOM(editor: LexicalEditor): DOMExportOutput;
exportJSON(): SerializedListItemNode;

@@ -31,0 +32,0 @@ append(...nodes: LexicalNode[]): this;

@@ -11,9 +11,9 @@ {

"license": "MIT",
"version": "0.12.2",
"version": "0.12.3",
"main": "LexicalList.js",
"peerDependencies": {
"lexical": "0.12.2"
"lexical": "0.12.3"
},
"dependencies": {
"@lexical/utils": "0.12.2"
"@lexical/utils": "0.12.3"
},

@@ -20,0 +20,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc