Socket
Socket
Sign inDemoInstall

@lexical/list

Package Overview
Dependencies
Maintainers
4
Versions
163
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.2.5 to 0.2.6

12

LexicalList.d.ts

@@ -19,4 +19,5 @@ /**

export function $createListItemNode(): ListItemNode;
export function $createListNode(tag: ListNodeTagType, start?: number): ListNode;
export type ListType = 'number' | 'bullet' | 'check';
export function $createListItemNode(checked?: boolean | void): ListItemNode;
export function $createListNode(listType: ListType, start?: number): ListNode;
export function $getListDepth(listNode: ListNode): number;

@@ -27,3 +28,3 @@ export function $handleListInsertParagraph(): boolean;

export function indentList(): void;
export function insertList(editor: LexicalEditor, listType: 'ul' | 'ol'): void;
export function insertList(editor: LexicalEditor, listType: ListType): void;
export declare class ListItemNode extends ElementNode {

@@ -41,2 +42,5 @@ append(...nodes: LexicalNode[]): ListItemNode;

canMergeWith(node: LexicalNode): boolean;
getChecked(): boolean | void;
setChecked(boolean): this;
toggleChecked(): void;
}

@@ -47,2 +51,3 @@ export declare class ListNode extends ElementNode {

getTag(): ListNodeTagType;
getListType(): ListType;
}

@@ -54,2 +59,3 @@ export function outdentList(): void;

export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
export var INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
export var REMOVE_LIST_COMMAND: LexicalCommand<void>;

@@ -86,3 +86,4 @@ /**

return $isListItemNode(node) && $isListNode(node.getFirstChild());
}
} // TODO: rewrite with $findMatchingParent or *nodeOfType
function findNearestListItemNode(node) {

@@ -255,7 +256,7 @@ let currentNode = node;

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

@@ -266,3 +267,3 @@ nextSibling.remove();

return previousSibling;
} else if ($isListNode(nextSibling) && listType === nextSibling.getTag()) {
} else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
listItem.append(node);

@@ -386,3 +387,3 @@ nextSibling.getFirstChildOrThrow().insertBefore(listItem);

const newListItem = $createListItemNode();
const newList = $createListNode(parent.getTag());
const newList = $createListNode(parent.getListType());
newListItem.append(newList);

@@ -439,9 +440,9 @@ newList.append(listItemNode);

// otherwise, we need to split the siblings into two new nested lists
const tag = parentList.getTag();
const listType = parentList.getListType();
const previousSiblingsListItem = $createListItemNode();
const previousSiblingsList = $createListNode(tag);
const previousSiblingsList = $createListNode(listType);
previousSiblingsListItem.append(previousSiblingsList);
listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
const nextSiblingsListItem = $createListItemNode();
const nextSiblingsList = $createListNode(tag);
const nextSiblingsList = $createListNode(listType);
nextSiblingsListItem.append(nextSiblingsList);

@@ -541,3 +542,3 @@ nextSiblingsList.append(...listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.

if (nextSiblings.length > 0) {
const newList = $createListNode(parent.getTag());
const newList = $createListNode(parent.getListType());

@@ -577,8 +578,9 @@ if (lexical.$isParagraphNode(replacementNode)) {

static clone(node) {
return new ListItemNode(node.__value, node.__key);
return new ListItemNode(node.__value, node.__checked, node.__key);
}
constructor(value, key) {
constructor(value, checked, key) {
super(key);
this.__value = value === undefined ? 1 : value;
this.__checked = checked;
}

@@ -592,2 +594,3 @@

updateChildrenListItemValue(parent);
updateListItemChecked(element, this, null, parent);
}

@@ -605,2 +608,3 @@

updateChildrenListItemValue(parent);
updateListItemChecked(dom, this, prevNode, parent);
} // $FlowFixMe - this is always HTMLListItemElement

@@ -657,3 +661,3 @@

// Split the list
const newList = $createListNode(list.getTag());
const newList = $createListNode(list.getListType());
const children = list.getChildren();

@@ -703,3 +707,3 @@

if ($isListNode(node) && node.getTag() === listNode.getTag()) {
if ($isListNode(node) && node.getListType() === listNode.getListType()) {
let child = node;

@@ -721,3 +725,3 @@ const children = node.getChildren();

if (siblings.length !== 0) {
const newListNode = $createListNode(listNode.getTag());
const newListNode = $createListNode(listNode.getListType());
siblings.forEach(sibling => newListNode.append(sibling));

@@ -744,3 +748,3 @@ node.insertAfter(newListNode);

insertNewAfter() {
const newElement = $createListItemNode();
const newElement = $createListItemNode(this.__checked == null ? undefined : false);
this.insertAfter(newElement);

@@ -798,2 +802,16 @@ return newElement;

getChecked() {
const self = this.getLatest();
return self.__checked;
}
setChecked(checked) {
const self = this.getWritable();
self.__checked = checked;
}
toggleChecked() {
this.setChecked(!this.__checked);
}
getIndent() {

@@ -838,4 +856,4 @@ // ListItemNode should always have a ListNode for a parent.

if ($isListNode(parent)) {
// mark subsequent list items dirty so we update their value attribute.
updateChildrenListItemValue(parent);
const siblings = this.getNextSiblings();
updateChildrenListItemValue(parent, siblings);
}

@@ -859,2 +877,12 @@ }

extractWithChild(child, selection) {
if (!lexical.$isRangeSelection(selection)) {
return false;
}
const anchorNode = selection.anchor.getNode();
const focusNode = selection.focus.getNode();
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && this.getTextContent().length === selection.getTextContent().length;
}
}

@@ -878,2 +906,20 @@

if (listTheme) {
const parentNode = node.getParent();
const isCheckList = $isListNode(parentNode) && parentNode.getListType() === 'check';
const checked = node.getChecked();
if (!isCheckList || checked) {
classesToRemove.push(listTheme.listitemUnchecked);
}
if (!isCheckList || !checked) {
classesToRemove.push(listTheme.listitemChecked);
}
if (isCheckList) {
classesToAdd.push(checked ? listTheme.listitemChecked : listTheme.listitemUnchecked);
}
}
if (nestedListItemClassName !== undefined) {

@@ -889,8 +935,33 @@ const nestedListItemClasses = nestedListItemClassName.split(' ');

if (classesToRemove.length > 0) {
utils.removeClassNamesFromElement(dom, ...classesToRemove);
}
if (classesToAdd.length > 0) {
utils.addClassNamesToElement(dom, ...classesToAdd);
}
}
if (classesToRemove.length > 0) {
utils.removeClassNamesFromElement(dom, ...classesToRemove);
function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
const isCheckList = listNode.getListType() === 'check';
if (isCheckList) {
// Only add attributes for leaf list items
if ($isListNode(listItemNode.getFirstChild())) {
dom.removeAttribute('role');
dom.removeAttribute('tabIndex');
dom.removeAttribute('aria-checked');
} else {
dom.setAttribute('role', 'checkbox');
dom.setAttribute('tabIndex', '-1');
if (!prevListItemNode || listItemNode.__checked !== prevListItemNode.__checked) {
dom.setAttribute('aria-checked', listItemNode.getChecked() ? 'true' : 'false');
}
}
} else {
// Clean up checked state
if (listItemNode.getChecked() != null) {
listItemNode.setChecked(undefined);
}
}

@@ -905,4 +976,4 @@ }

function $createListItemNode() {
return new ListItemNode();
function $createListItemNode(checked) {
return new ListItemNode(undefined, checked);
}

@@ -927,8 +998,13 @@ function $isListItemNode(node) {

static clone(node) {
return new ListNode(node.__tag, node.__start, node.__key);
const listType = node.__listType || TAG_TO_LIST_TYPE[node.__tag];
return new ListNode(listType, node.__start, node.__key);
}
constructor(tag, start, key) {
super(key);
this.__tag = tag;
constructor(listType, start, key) {
super(key); // $FlowFixMe added for backward compatibility to map tags to list type
const _listType = TAG_TO_LIST_TYPE[listType] || listType;
this.__listType = _listType;
this.__tag = _listType === 'number' ? 'ol' : 'ul';
this.__start = start;

@@ -941,2 +1017,6 @@ }

getListType() {
return this.__listType;
}
getStart() {

@@ -953,4 +1033,6 @@ return this.__start;

dom.setAttribute('start', String(this.__start));
}
} // $FlowFixMe internal field
dom.__lexicalListType = this.__listType;
setListThemeClassNames(dom, config.theme, this);

@@ -1013,2 +1095,6 @@ return dom;

extractWithChild(child) {
return $isListItemNode(child);
}
}

@@ -1060,9 +1146,9 @@

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

@@ -1074,4 +1160,6 @@

if (nodeName === 'ol' || nodeName === 'ul') {
node = $createListNode(nodeName);
if (nodeName === 'ol') {
node = $createListNode('number');
} else if (nodeName === 'ul') {
node = $createListNode('bullet');
}

@@ -1084,4 +1172,8 @@

function $createListNode(tag, start = 1) {
return new ListNode(tag, start);
const TAG_TO_LIST_TYPE = {
ol: 'number',
ul: 'bullet'
};
function $createListNode(listType, start = 1) {
return new ListNode(listType, start);
}

@@ -1102,2 +1194,3 @@ function $isListNode(node) {

const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand();
const INSERT_CHECK_LIST_COMMAND = lexical.createCommand();
const REMOVE_LIST_COMMAND = lexical.createCommand();

@@ -1111,2 +1204,3 @@

exports.$isListNode = $isListNode;
exports.INSERT_CHECK_LIST_COMMAND = INSERT_CHECK_LIST_COMMAND;
exports.INSERT_ORDERED_LIST_COMMAND = INSERT_ORDERED_LIST_COMMAND;

@@ -1113,0 +1207,0 @@ exports.INSERT_UNORDERED_LIST_COMMAND = INSERT_UNORDERED_LIST_COMMAND;

@@ -7,24 +7,26 @@ /**

*/
var h=require("lexical"),k=require("@lexical/utils");function m(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function n(a){let b=1;for(a=a.getParent();null!=a;){if(p(a)){a=a.getParent();if(q(a)){b++;a=a.getParent();continue}m(2)}break}return b}function t(a){a=a.getParent();q(a)||m(2);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}
var h=require("lexical"),l=require("@lexical/utils");function m(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function n(a){let b=1;for(a=a.getParent();null!=a;){if(p(a)){a=a.getParent();if(q(a)){b++;a=a.getParent();continue}m(9)}break}return b}function t(a){a=a.getParent();q(a)||m(9);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}
function u(a){let b=[];a=a.getChildren().filter(p);for(let c=0;c<a.length;c++){const d=a[c],e=d.getFirstChild();q(e)?b=b.concat(u(e)):b.push(d)}return b}function v(a){return p(a)&&q(a.getFirstChild())}function w(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){const b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function y(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}
function z(a,b){if(q(a))return a;const c=a.getPreviousSibling(),d=a.getNextSibling(),e=B();if(q(c)&&b===c.getTag())return e.append(a),c.append(e),q(d)&&b===d.getTag()&&(c.append(...d.getChildren()),d.remove()),c;if(q(d)&&b===d.getTag())return e.append(a),d.getFirstChildOrThrow().insertBefore(e),d;b=C(b);b.append(e);a.replace(b);e.append(a);D(b);return b}
function D(a,b){(b||a.getChildren()).forEach(c=>{const d=c.getValue();var e=c.getParent();var f=1;if(null!=e)if(q(e))f=e.getStart();else throw Error("$getListItemValue: list node is not parent of list item node");e=c.getPreviousSiblings();for(let g=0;g<e.length;g++){const l=e[g];p(l)&&!q(l.getFirstChild())&&f++}d!==f&&c.setValue(f)})}
function E(a){const b=new Set;a.forEach(c=>{if(!v(c)&&!b.has(c.getKey())){var d=c.getParent(),e=c.getNextSibling(),f=c.getPreviousSibling();if(v(e)&&v(f))f=f.getFirstChild(),q(f)&&(f.append(c),c=e.getFirstChild(),q(c)&&(c=c.getChildren(),f.append(...c),e.remove(),b.add(e.getKey())),D(f));else if(v(e))e=e.getFirstChild(),q(e)&&(f=e.getFirstChild(),null!==f&&f.insertBefore(c),D(e));else if(v(f))e=f.getFirstChild(),q(e)&&(e.append(c),D(e));else if(q(d)){const g=B(),l=C(d.getTag());g.append(l);l.append(c);
function z(a,b){if(q(a))return a;const c=a.getPreviousSibling(),d=a.getNextSibling(),e=B();if(q(c)&&b===c.getListType())return e.append(a),c.append(e),q(d)&&b===d.getListType()&&(c.append(...d.getChildren()),d.remove()),c;if(q(d)&&b===d.getListType())return e.append(a),d.getFirstChildOrThrow().insertBefore(e),d;b=C(b);b.append(e);a.replace(b);e.append(a);D(b);return b}
function D(a,b){(b||a.getChildren()).forEach(c=>{const d=c.getValue();var e=c.getParent();var f=1;null!=e&&(q(e)?f=e.getStart():m(10));e=c.getPreviousSiblings();for(let g=0;g<e.length;g++){const k=e[g];p(k)&&!q(k.getFirstChild())&&f++}d!==f&&c.setValue(f)})}
function E(a){const b=new Set;a.forEach(c=>{if(!v(c)&&!b.has(c.getKey())){var d=c.getParent(),e=c.getNextSibling(),f=c.getPreviousSibling();if(v(e)&&v(f))f=f.getFirstChild(),q(f)&&(f.append(c),c=e.getFirstChild(),q(c)&&(c=c.getChildren(),f.append(...c),e.remove(),b.add(e.getKey())),D(f));else if(v(e))e=e.getFirstChild(),q(e)&&(f=e.getFirstChild(),null!==f&&f.insertBefore(c),D(e));else if(v(f))e=f.getFirstChild(),q(e)&&(e.append(c),D(e));else if(q(d)){const g=B(),k=C(d.getListType());g.append(k);k.append(c);
f?f.insertAfter(g):e?e.insertBefore(g):d.append(g)}q(d)&&D(d)}})}
function F(a){a.forEach(b=>{if(!v(b)){var c=b.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(q(e)&&p(d)&&q(c)){var f=c?c.getFirstChild():void 0,g=c?c.getLastChild():void 0;if(b.is(f))d.insertBefore(b),c.isEmpty()&&d.remove();else if(b.is(g))d.insertAfter(b),c.isEmpty()&&d.remove();else{var l=c.getTag();f=B();const r=C(l);f.append(r);b.getPreviousSiblings().forEach(x=>r.append(x));g=B();l=C(l);g.append(l);l.append(...b.getNextSiblings());d.insertBefore(f);d.insertAfter(g);d.replace(b)}D(c);
function F(a){a.forEach(b=>{if(!v(b)){var c=b.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(q(e)&&p(d)&&q(c)){var f=c?c.getFirstChild():void 0,g=c?c.getLastChild():void 0;if(b.is(f))d.insertBefore(b),c.isEmpty()&&d.remove();else if(b.is(g))d.insertAfter(b),c.isEmpty()&&d.remove();else{var k=c.getListType();f=B();const r=C(k);f.append(r);b.getPreviousSiblings().forEach(x=>r.append(x));g=B();k=C(k);g.append(k);k.append(...b.getNextSiblings());d.insertBefore(f);d.insertAfter(g);d.replace(b)}D(c);
D(e)}}})}function G(a){var b=h.$getSelection();if(h.$isRangeSelection(b)){var c=b.getNodes(),d=[];0===c.length&&c.push(b.anchor.getNode());if(1===c.length){a:{for(c=c[0];null!==c;){if(p(c))break a;c=c.getParent()}c=null}null!==c&&(d=[c])}else{d=new Set;for(b=0;b<c.length;b++){const e=c[b];p(e)&&d.add(e)}d=Array.from(d)}0<d.length&&("indent"===a?E(d):F(d))}}
class H extends h.ElementNode{static getType(){return"listitem"}static clone(a){return new H(a.__value,a.__key)}constructor(a,b){super(b);this.__value=void 0===a?1:a}createDOM(a){const b=document.createElement("li"),c=this.getParent();q(c)&&D(c);b.value=this.__value;I(b,a.theme,this);return b}updateDOM(a,b,c){a=this.getParent();q(a)&&D(a);b.value=this.__value;I(b,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:J,priority:0})}}append(...a){for(let b=0;b<a.length;b++){const c=a[b];
if(h.$isElementNode(c)&&this.canMergeWith(c)){const d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a){if(p(a))return super.replace(a);const b=this.getParentOrThrow();if(q(b)){var c=b.__children;const e=c.length;var d=c.indexOf(this.__key);if(0===d)b.insertBefore(a);else if(d===e-1)b.insertAfter(a);else{c=C(b.getTag());const f=b.getChildren();for(d+=1;d<e;d++)c.append(f[d]);b.insertAfter(a);a.insertAfter(c)}this.remove();1===e&&b.remove()}return a}insertAfter(a){var b=
this.getParentOrThrow();q(b)||m(1);var c=this.getNextSiblings();if(p(a))return b=super.insertAfter(a),a=a.getParentOrThrow(),q(a)&&D(a),b;if(q(a)&&a.getTag()===b.getTag()){b=a;a=a.getChildren();for(c=a.length-1;0<=c;c--)b=a[c],this.insertAfter(b);return b}b.insertAfter(a);if(0!==c.length){const d=C(b.getTag());c.forEach(e=>d.append(e));a.insertAfter(d)}return a}remove(a){const b=this.getNextSibling();super.remove(a);null!==b&&(a=b.getParent(),q(a)&&D(a))}insertNewAfter(){const a=B();this.insertAfter(a);
return a}collapseAtStart(a){const b=h.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();const e=p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.replace(b),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}getIndent(){let a=this.getParentOrThrow().getParentOrThrow(),b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){let b=this.getIndent();for(;b!==a;)b<a?(E([this]),b++):(F([this]),b--);return this}canIndent(){return!1}insertBefore(a){if(p(a)){const b=this.getParentOrThrow();q(b)&&D(b)}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||p(a)}}
function I(a,b,c){const d=[],e=[],f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var g=b.nested.listitem;void 0!==f&&(b=f.split(" "),d.push(...b));void 0!==g&&(g=g.split(" "),c.getChildren().some(l=>q(l))?d.push(...g):e.push(...g));0<d.length&&k.addClassNamesToElement(a,...d);0<e.length&&k.removeClassNamesFromElement(a,...e)}function J(){return{node:B()}}function B(){return new H}function p(a){return a instanceof H}
class K extends h.ElementNode{static getType(){return"list"}static clone(a){return new K(a.__tag,a.__start,a.__key)}constructor(a,b,c){super(c);this.__tag=a;this.__start=b}getTag(){return this.__tag}getStart(){return this.__start}createDOM(a){const b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",String(this.__start));L(b,a.theme,this);return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;L(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:M,
priority:0}),ul:()=>({conversion:M,priority:0})}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{const d=B();q(b)?d.append(b):(b=h.$createTextNode(b.getTextContent()),d.append(b));super.append(d)}}return this}}
function L(a,b,c){const d=[],e=[];var f=b.list;if(void 0!==f){const l=f[c.__tag+"Depth"]||[];b=n(c)-1;const r=b%l.length;var g=l[r];const x=f[c.__tag];let A;f=f.nested;void 0!==f&&f.list&&(A=f.list);void 0!==x&&d.push(x);if(void 0!==g)for(g=g.split(" "),d.push(...g),g=0;g<l.length;g++)g!==r&&e.push(c.__tag+g);void 0!==A&&(c=A.split(" "),1<b?d.push(...c):e.push(...c))}0<d.length&&k.addClassNamesToElement(a,...d);0<e.length&&k.removeClassNamesFromElement(a,...e)}
function M(a){a=a.nodeName.toLowerCase();let b=null;if("ol"===a||"ul"===a)b=C(a);return{node:b}}function C(a,b=1){return new K(a,b)}function q(a){return a instanceof K}const N=h.createCommand(),O=h.createCommand(),P=h.createCommand();exports.$createListItemNode=B;exports.$createListNode=C;exports.$getListDepth=n;
exports.$handleListInsertParagraph=function(){var a=h.$getSelection();if(!h.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!p(a)||""!==a.getTextContent())return!1;var b=t(a),c=a.getParent();q(c)||m(2);const d=c.getParent();let e;if(h.$isRootNode(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=B(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){const f=C(c.getTag());h.$isParagraphNode(e)?e.insertAfter(f):(c=B(),c.append(f),e.insertAfter(c));
b.forEach(g=>{g.remove();f.append(g)})}w(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_ORDERED_LIST_COMMAND=O;exports.INSERT_UNORDERED_LIST_COMMAND=N;exports.ListItemNode=H;exports.ListNode=K;exports.REMOVE_LIST_COMMAND=P;exports.indentList=function(){G("indent")};
exports.insertList=function(a,b){a.update(()=>{var c=h.$getSelection();if(h.$isRangeSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(y(c,d))d=C(b),h.$isRootNode(e)?(c.replace(d),c=B(),d.append(c)):p(c)&&(c=c.getParentOrThrow(),d.append(...c.getChildren()),c.replace(d));else for(c=new Set,e=0;e<d.length;e++){var f=d[e];if(h.$isElementNode(f)&&f.isEmpty()&&!c.has(f.getKey()))z(f,b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){const l=f.getKey();if(q(f)){if(!c.has(l)){var g=
C(b);g.append(...f.getChildren());f.replace(g);D(g);c.add(l)}break}else{g=f.getParent();if(h.$isRootNode(g)&&!c.has(l)){c.add(l);z(f,b);break}f=g}}}}})};exports.outdentList=function(){G("outdent")};
exports.removeList=function(a){a.update(()=>{var b=h.$getSelection();if(h.$isRangeSelection(b)){const d=new Set,e=b.getNodes();b=b.anchor.getNode();if(y(b,e))d.add(t(b));else for(b=0;b<e.length;b++){var c=e[b];h.$isLeafNode(c)&&(c=k.$getNearestNodeOfType(c,H),null!=c&&d.add(t(c)))}d.forEach(f=>{let g=f;u(f).forEach(l=>{if(null!=l){const r=h.$createParagraphNode();r.append(...l.getChildren());g.insertAfter(r);g=r;l.remove()}});f.remove()})}})};
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){const b=document.createElement("li"),c=this.getParent();q(c)&&(D(c),I(b,this,null,c));b.value=this.__value;J(b,a.theme,this);return b}updateDOM(a,b,c){const d=this.getParent();q(d)&&(D(d),I(b,this,a,d));b.value=this.__value;J(b,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:K,
priority:0})}}append(...a){for(let b=0;b<a.length;b++){const c=a[b];if(h.$isElementNode(c)&&this.canMergeWith(c)){const d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a){if(p(a))return super.replace(a);const b=this.getParentOrThrow();if(q(b)){var c=b.__children;const e=c.length;var d=c.indexOf(this.__key);if(0===d)b.insertBefore(a);else if(d===e-1)b.insertAfter(a);else{c=C(b.getListType());const f=b.getChildren();for(d+=1;d<e;d++)c.append(f[d]);b.insertAfter(a);
a.insertAfter(c)}this.remove();1===e&&b.remove()}return a}insertAfter(a){var b=this.getParentOrThrow();q(b)||m(11);var c=this.getNextSiblings();if(p(a))return b=super.insertAfter(a),a=a.getParentOrThrow(),q(a)&&D(a),b;if(q(a)&&a.getListType()===b.getListType()){b=a;a=a.getChildren();for(c=a.length-1;0<=c;c--)b=a[c],this.insertAfter(b);return b}b.insertAfter(a);if(0!==c.length){const d=C(b.getListType());c.forEach(e=>d.append(e));a.insertAfter(d)}return a}remove(a){const b=this.getNextSibling();super.remove(a);
null!==b&&(a=b.getParent(),q(a)&&D(a))}insertNewAfter(){const a=B(null==this.__checked?void 0:!1);this.insertAfter(a);return a}collapseAtStart(a){const b=h.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();const e=p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.replace(b),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(){let a=this.getParentOrThrow().getParentOrThrow(),b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){let b=this.getIndent();for(;b!==a;)b<a?(E([this]),b++):(F([this]),b--);
return this}canIndent(){return!1}insertBefore(a){if(p(a)){const b=this.getParentOrThrow();if(q(b)){const c=this.getNextSiblings();D(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();const c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}}
function J(a,b,c){const 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();const k=c.getChecked();f&&!k||e.push(b.listitemUnchecked);f&&k||e.push(b.listitemChecked);f&&d.push(k?b.listitemChecked:b.listitemUnchecked)}void 0!==g&&(g=g.split(" "),c.getChildren().some(k=>q(k))?d.push(...g):e.push(...g));0<e.length&&l.removeClassNamesFromElement(a,...e);0<d.length&&l.addClassNamesToElement(a,
...d)}function I(a,b,c,d){"check"===d.getListType()?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")):null!=b.getChecked()&&b.setChecked(void 0)}function K(){return{node:B()}}function B(a){return new H(void 0,a)}function p(a){return a instanceof H}
class L extends h.ElementNode{static getType(){return"list"}static clone(a){return new L(a.__listType||M[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=M[a]||a;this.__tag="number"===a?"ol":"ul";this.__start=b}getTag(){return this.__tag}getListType(){return this.__listType}getStart(){return this.__start}createDOM(a){const b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",String(this.__start));b.__lexicalListType=this.__listType;N(b,a.theme,this);
return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;N(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:O,priority:0}),ul:()=>({conversion:O,priority:0})}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{const d=B();q(b)?d.append(b):(b=h.$createTextNode(b.getTextContent()),d.append(b));super.append(d)}}return this}extractWithChild(a){return p(a)}}
function N(a,b,c){const d=[],e=[];var f=b.list;if(void 0!==f){const k=f[c.__tag+"Depth"]||[];b=n(c)-1;const r=b%k.length;var g=k[r];const x=f[c.__tag];let A;f=f.nested;void 0!==f&&f.list&&(A=f.list);void 0!==x&&d.push(x);if(void 0!==g)for(g=g.split(" "),d.push(...g),g=0;g<k.length;g++)g!==r&&e.push(c.__tag+g);void 0!==A&&(c=A.split(" "),1<b?d.push(...c):e.push(...c))}0<e.length&&l.removeClassNamesFromElement(a,...e);0<d.length&&l.addClassNamesToElement(a,...d)}
function O(a){a=a.nodeName.toLowerCase();let b=null;"ol"===a?b=C("number"):"ul"===a&&(b=C("bullet"));return{node:b}}const M={ol:"number",ul:"bullet"};function C(a,b=1){return new L(a,b)}function q(a){return a instanceof L}const P=h.createCommand(),Q=h.createCommand(),R=h.createCommand(),S=h.createCommand();exports.$createListItemNode=B;exports.$createListNode=C;exports.$getListDepth=n;
exports.$handleListInsertParagraph=function(){var a=h.$getSelection();if(!h.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!p(a)||""!==a.getTextContent())return!1;var b=t(a),c=a.getParent();q(c)||m(9);const d=c.getParent();let e;if(h.$isRootNode(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=B(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){const f=C(c.getListType());h.$isParagraphNode(e)?e.insertAfter(f):(c=B(),c.append(f),
e.insertAfter(c));b.forEach(g=>{g.remove();f.append(g)})}w(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_CHECK_LIST_COMMAND=R;exports.INSERT_ORDERED_LIST_COMMAND=Q;exports.INSERT_UNORDERED_LIST_COMMAND=P;exports.ListItemNode=H;exports.ListNode=L;exports.REMOVE_LIST_COMMAND=S;exports.indentList=function(){G("indent")};
exports.insertList=function(a,b){a.update(()=>{var c=h.$getSelection();if(h.$isRangeSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(y(c,d))d=C(b),h.$isRootNode(e)?(c.replace(d),c=B(),d.append(c)):p(c)&&(c=c.getParentOrThrow(),d.append(...c.getChildren()),c.replace(d));else for(c=new Set,e=0;e<d.length;e++){var f=d[e];if(h.$isElementNode(f)&&f.isEmpty()&&!c.has(f.getKey()))z(f,b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){const k=f.getKey();if(q(f)){if(!c.has(k)){var g=
C(b);g.append(...f.getChildren());f.replace(g);D(g);c.add(k)}break}else{g=f.getParent();if(h.$isRootNode(g)&&!c.has(k)){c.add(k);z(f,b);break}f=g}}}}})};exports.outdentList=function(){G("outdent")};
exports.removeList=function(a){a.update(()=>{var b=h.$getSelection();if(h.$isRangeSelection(b)){const d=new Set,e=b.getNodes();b=b.anchor.getNode();if(y(b,e))d.add(t(b));else for(b=0;b<e.length;b++){var c=e[b];h.$isLeafNode(c)&&(c=l.$getNearestNodeOfType(c,H),null!=c&&d.add(t(c)))}d.forEach(f=>{let g=f;u(f).forEach(k=>{if(null!=k){const r=h.$createParagraphNode();r.append(...k.getChildren());g.insertAfter(r);g=r;k.remove()}});f.remove()})}})};

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

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

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

Sorry, the diff of this file is not supported yet

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