@lexical/list
Advanced tools
Comparing version 0.21.1-nightly.20241210.0 to 0.21.1-nightly.20241211.0
@@ -504,2 +504,3 @@ /** | ||
// Only run this code on empty list items | ||
const anchor = selection.anchor.getNode(); | ||
@@ -518,2 +519,4 @@ if (!$isListItemNode(anchor) || anchor.getChildrenSize() !== 0) { | ||
replacementNode = lexical.$createParagraphNode(); | ||
replacementNode.setTextStyle(selection.style); | ||
replacementNode.setTextFormat(selection.format); | ||
topListNode.insertAfter(replacementNode); | ||
@@ -530,15 +533,11 @@ } else if ($isListItemNode(grandparent)) { | ||
const newList = $createListNode(parent.getListType()); | ||
if (lexical.$isParagraphNode(replacementNode)) { | ||
replacementNode.insertAfter(newList); | ||
} else { | ||
if ($isListItemNode(replacementNode)) { | ||
const newListItem = $createListItemNode(); | ||
newListItem.append(newList); | ||
replacementNode.insertAfter(newListItem); | ||
} else { | ||
replacementNode.insertAfter(newList); | ||
} | ||
nextSiblings.forEach(sibling => { | ||
sibling.remove(); | ||
newList.append(sibling); | ||
}); | ||
newList.append(...nextSiblings); | ||
} | ||
// Don't leave hanging nested empty lists | ||
@@ -578,3 +577,3 @@ $removeHighestEmptyListParent(anchor); | ||
/** @noInheritDoc */ | ||
class ListItemNode extends lexical.ElementNode { | ||
class ListItemNode extends lexical.ParagraphNode { | ||
/** @internal */ | ||
@@ -606,2 +605,5 @@ | ||
updateDOM(prevNode, dom, config) { | ||
if (super.updateDOM(prevNode, dom, config)) { | ||
return true; | ||
} | ||
const parent = this.getParent(); | ||
@@ -646,2 +648,8 @@ if ($isListNode(parent) && parent.getListType() === 'check') { | ||
node.setDirection(serializedNode.direction); | ||
if (typeof serializedNode.textFormat === 'number') { | ||
node.setTextFormat(serializedNode.textFormat); | ||
} | ||
if (typeof serializedNode.textStyle === 'string') { | ||
node.setTextStyle(serializedNode.textStyle); | ||
} | ||
return node; | ||
@@ -728,4 +736,2 @@ } | ||
const siblings = this.getNextSiblings(); | ||
// Split the lists and insert the node in between them | ||
listNode.insertAfter(node, restoreSelection); | ||
@@ -748,8 +754,15 @@ if (siblings.length !== 0) { | ||
} | ||
insertNewAfter(_, restoreSelection = true) { | ||
insertNewAfter(selection, restoreSelection = true) { | ||
const newElement = $createListItemNode(this.__checked == null ? undefined : false); | ||
const format = selection.format; | ||
newElement.setTextFormat(format); | ||
newElement.setFormat(this.getFormatType()); | ||
this.insertAfter(newElement, restoreSelection); | ||
return newElement; | ||
} | ||
collapseAtStart(selection) { | ||
collapseAtStart() { | ||
const selection = lexical.$getSelection(); | ||
if (!lexical.$isRangeSelection(selection)) { | ||
return false; | ||
} | ||
const paragraph = lexical.$createParagraphNode(); | ||
@@ -759,8 +772,8 @@ const children = this.getChildren(); | ||
const listNode = this.getParentOrThrow(); | ||
const listNodeParent = listNode.getParentOrThrow(); | ||
const isIndented = $isListItemNode(listNodeParent); | ||
const listNodeParent = listNode.getParent(); | ||
if (!$isListNode(listNode)) { | ||
return false; | ||
} | ||
if (listNode.getChildrenSize() === 1) { | ||
if (isIndented) { | ||
// if the list node is nested, we just want to remove it, | ||
// effectively unindenting it. | ||
if ($isListItemNode(listNodeParent)) { | ||
listNode.remove(); | ||
@@ -771,17 +784,4 @@ listNodeParent.select(); | ||
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)) { | ||
focus.set(key, focus.offset, 'element'); | ||
} | ||
paragraph.select(); | ||
} | ||
} else { | ||
listNode.insertBefore(paragraph); | ||
this.remove(); | ||
} | ||
@@ -860,3 +860,3 @@ return true; | ||
canMergeWith(node) { | ||
return lexical.$isParagraphNode(node) || $isListItemNode(node); | ||
return $isListItemNode(node) || lexical.$isParagraphNode(node); | ||
} | ||
@@ -863,0 +863,0 @@ extractWithChild(child, selection) { |
@@ -10,33 +10,33 @@ /** | ||
'use strict';var g=require("@lexical/utils"),h=require("lexical"),l;function n(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}l=n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n["default"]:n; | ||
function p(a){let b=1;for(a=a.getParent();null!=a;){if(q(a)){a=a.getParent();if(r(a)){b++;a=a.getParent();continue}l(40)}break}return b}function t(a){a=a.getParent();r(a)||l(40);let b=a;for(;null!==b;)b=b.getParent(),r(b)&&(a=b);return a}function u(a){let b=[];a=a.getChildren().filter(q);for(let c=0;c<a.length;c++){let d=a[c],e=d.getFirstChild();r(e)?b=b.concat(u(e)):b.push(d)}return b}function v(a){return q(a)&&r(a.getFirstChild())} | ||
function w(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){let b=a.getParent();if(null==b||!q(a)&&!r(a))break;a=b}a.remove()}function x(a){return y().append(a)}function z(a,b){return q(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())} | ||
function A(a,b){a.update(()=>{var c=h.$getSelection();if(null!==c){var d=c.getNodes();if(h.$isRangeSelection(c)){c=c.getStartEndPoints();null===c&&l(143);[c]=c;c=c.getNode();var e=c.getParent();if(z(c,d)){d=B(b);h.$isRootOrShadowRoot(e)?(c.replace(d),e=y(),h.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),d.append(e)):q(c)&&(c=c.getParentOrThrow(),E(d,c.getChildren()),c.replace(d));return}}c=new Set;for(e=0;e<d.length;e++){var f=d[e];if(h.$isElementNode(f)&&f.isEmpty()&& | ||
!q(f)&&!c.has(f.getKey()))F(f,b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){let m=f.getKey();if(r(f)){if(!c.has(m)){var k=B(b);E(k,f.getChildren());f.replace(k);c.add(m)}break}else{k=f.getParent();if(h.$isRootOrShadowRoot(k)&&!c.has(m)){c.add(m);F(f,b);break}f=k}}}}})}function E(a,b){a.splice(a.getChildrenSize(),0,b)} | ||
function F(a,b){if(r(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=y();E(e,a.getChildren());r(c)&&b===c.getListType()?(c.append(e),r(d)&&b===d.getListType()&&(E(c,d.getChildren()),d.remove()),b=c):r(d)&&b===d.getListType()?(d.getFirstChildOrThrow().insertBefore(e),b=d):(b=B(b),b.append(e),a.replace(b));e.setFormat(a.getFormatType());e.setIndent(a.getIndent());a.remove();return b} | ||
function G(a,b){var c=a.getLastChild();let d=b.getFirstChild();c&&d&&v(c)&&v(d)&&(G(c.getFirstChild(),d.getFirstChild()),d.remove());c=b.getChildren();0<c.length&&a.append(...c);b.remove()} | ||
function H(a){a.update(()=>{let b=h.$getSelection();if(h.$isRangeSelection(b)){var c=new Set,d=b.getNodes(),e=b.anchor.getNode();if(z(e,d))c.add(t(e));else for(e=0;e<d.length;e++){var f=d[e];h.$isLeafNode(f)&&(f=g.$getNearestNodeOfType(f,I),null!=f&&c.add(t(f)))}for(let k of c){c=k;d=u(k);for(let m of d)d=h.$createParagraphNode(),E(d,m.getChildren()),c.insertAfter(d),c=d,m.__key===b.anchor.key&&b.anchor.set(d.getKey(),0,"element"),m.__key===b.focus.key&&b.focus.set(d.getKey(),0,"element"),m.remove(); | ||
function p(a){let b=1;for(a=a.getParent();null!=a;){if(q(a)){a=a.getParent();if(r(a)){b++;a=a.getParent();continue}l(40)}break}return b}function t(a){a=a.getParent();r(a)||l(40);let b=a;for(;null!==b;)b=b.getParent(),r(b)&&(a=b);return a}function u(a){let b=[];a=a.getChildren().filter(q);for(let c=0;c<a.length;c++){let d=a[c],e=d.getFirstChild();r(e)?b=b.concat(u(e)):b.push(d)}return b}function v(a){return q(a)&&r(a.getFirstChild())}function w(a){return x().append(a)} | ||
function y(a,b){return q(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())} | ||
function z(a,b){a.update(()=>{var c=h.$getSelection();if(null!==c){var d=c.getNodes();if(h.$isRangeSelection(c)){c=c.getStartEndPoints();null===c&&l(143);[c]=c;c=c.getNode();var e=c.getParent();if(y(c,d)){d=A(b);h.$isRootOrShadowRoot(e)?(c.replace(d),e=x(),h.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),d.append(e)):q(c)&&(c=c.getParentOrThrow(),B(d,c.getChildren()),c.replace(d));return}}c=new Set;for(e=0;e<d.length;e++){var f=d[e];if(h.$isElementNode(f)&&f.isEmpty()&& | ||
!q(f)&&!c.has(f.getKey()))E(f,b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){let m=f.getKey();if(r(f)){if(!c.has(m)){var k=A(b);B(k,f.getChildren());f.replace(k);c.add(m)}break}else{k=f.getParent();if(h.$isRootOrShadowRoot(k)&&!c.has(m)){c.add(m);E(f,b);break}f=k}}}}})}function B(a,b){a.splice(a.getChildrenSize(),0,b)} | ||
function E(a,b){if(r(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=x();B(e,a.getChildren());r(c)&&b===c.getListType()?(c.append(e),r(d)&&b===d.getListType()&&(B(c,d.getChildren()),d.remove()),b=c):r(d)&&b===d.getListType()?(d.getFirstChildOrThrow().insertBefore(e),b=d):(b=A(b),b.append(e),a.replace(b));e.setFormat(a.getFormatType());e.setIndent(a.getIndent());a.remove();return b} | ||
function F(a,b){var c=a.getLastChild();let d=b.getFirstChild();c&&d&&v(c)&&v(d)&&(F(c.getFirstChild(),d.getFirstChild()),d.remove());c=b.getChildren();0<c.length&&a.append(...c);b.remove()} | ||
function G(a){a.update(()=>{let b=h.$getSelection();if(h.$isRangeSelection(b)){var c=new Set,d=b.getNodes(),e=b.anchor.getNode();if(y(e,d))c.add(t(e));else for(e=0;e<d.length;e++){var f=d[e];h.$isLeafNode(f)&&(f=g.$getNearestNodeOfType(f,H),null!=f&&c.add(t(f)))}for(let k of c){c=k;d=u(k);for(let m of d)d=h.$createParagraphNode(),B(d,m.getChildren()),c.insertAfter(d),c=d,m.__key===b.anchor.key&&b.anchor.set(d.getKey(),0,"element"),m.__key===b.focus.key&&b.focus.set(d.getKey(),0,"element"),m.remove(); | ||
k.remove()}}})} | ||
function J(a){if(!v(a)){var b=a.getParent(),c=b?b.getParent():void 0,d=c?c.getParent():void 0;if(r(d)&&q(c)&&r(b)){d=b?b.getFirstChild():void 0;var e=b?b.getLastChild():void 0;if(a.is(d))c.insertBefore(a),b.isEmpty()&&c.remove();else if(a.is(e))c.insertAfter(a),b.isEmpty()&&c.remove();else{e=b.getListType();b=y();let f=B(e);b.append(f);a.getPreviousSiblings().forEach(k=>f.append(k));d=y();e=B(e);d.append(e);E(e,a.getNextSiblings());c.insertBefore(b);c.insertAfter(d);c.replace(a)}}}} | ||
function K(){var a=h.$getSelection();if(!h.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!q(a)||0!==a.getChildrenSize())return!1;var b=t(a),c=a.getParent();r(c)||l(40);let d=c.getParent(),e;if(h.$isRootOrShadowRoot(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(q(d))e=y(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){let f=B(c.getListType());h.$isParagraphNode(e)?e.insertAfter(f):(c=y(),c.append(f),e.insertAfter(c));b.forEach(k=>{k.remove(); | ||
f.append(k)})}w(a);return!0}function L(...a){let b=[];for(let c of a)if(c&&"string"===typeof c)for(let [d]of c.matchAll(/\S+/g))b.push(d);return b} | ||
class I extends h.ElementNode{static getType(){return"listitem"}static clone(a){return new I(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();r(c)&&"check"===c.getListType()&&M(b,this,null);b.value=this.__value;N(b,a.theme,this);return b}updateDOM(a,b,c){let d=this.getParent();r(d)&&"check"===d.getListType()&&M(b,this,a);b.value=this.__value;N(b,c.theme,this);return!1}static transform(){return a=> | ||
{q(a)||l(144);if(null!=a.__checked){var b=a.getParent();r(b)&&"check"!==b.getListType()&&null!=a.getChecked()&&a.setChecked(void 0)}}}static importDOM(){return{li:()=>({conversion:O,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(q(a))return super.replace(a);this.setIndent(0);let c=this.getParentOrThrow();if(!r(c))return a;if(c.__first===this.getKey())c.insertBefore(a);else if(c.__last===this.getKey())c.insertAfter(a);else{let d=B(c.getListType()),e=this.getNextSibling();for(;e;){let f=e;e=e.getNextSibling(); | ||
d.append(f)}c.insertAfter(a);a.insertAfter(d)}b&&(h.$isElementNode(a)||l(139),this.getChildren().forEach(d=>{a.append(d)}));this.remove();0===c.getChildrenSize()&&c.remove();return a}insertAfter(a,b=!0){let c=this.getParentOrThrow();r(c)||l(39);if(q(a))return super.insertAfter(a,b);let d=this.getNextSiblings();c.insertAfter(a,b);if(0!==d.length){let e=B(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&&v(b)&&v(c)&&(G(b.getFirstChild(),c.getFirstChild()),c.remove())}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=q(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(){let a=this.getLatest(),b,c=this.getParent();r(c)&&(b=c.getListType());return"check"===b?!!a.__checked:void 0}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(;q(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){"number"!==typeof a&&l(117);a=Math.floor(a);0<=a||l(199);let b=this.getIndent();for(;b!==a;)if(b<a){var c=new Set;if(!v(this)&&!c.has(this.getKey())){var d=this.getParent(),e=this.getNextSibling(),f=this.getPreviousSibling();if(v(e)&&v(f))d=f.getFirstChild(),r(d)&&(d.append(this),f=e.getFirstChild(),r(f)&&(f=f.getChildren(),E(d,f),e.remove(),c.add(e.getKey())));else if(v(e))e=e.getFirstChild(),r(e)&&(e=e.getFirstChild(), | ||
null!==e&&e.insertBefore(this));else if(v(f))e=f.getFirstChild(),r(e)&&e.append(this);else if(r(d)){c=y();let k=B(d.getListType());c.append(k);k.append(this);f?f.insertAfter(c):e?e.insertBefore(c):d.append(c)}}b++}else J(this),b--;return this}canInsertAfter(a){return q(a)}canReplaceWith(a){return q(a)}canMergeWith(a){return h.$isParagraphNode(a)||q(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 B("bullet")}canMergeWhenEmpty(){return!0}} | ||
function N(a,b,c){let d=[],e=[];var f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var k=b.nested.listitem;void 0!==f&&d.push(...L(f));if(b){f=c.getParent();f=r(f)&&"check"===f.getListType();let m=c.getChecked();f&&!m||e.push(b.listitemUnchecked);f&&m||e.push(b.listitemChecked);f&&d.push(m?b.listitemChecked:b.listitemUnchecked)}void 0!==k&&(k=L(k),c.getChildren().some(m=>r(m))?d.push(...k):e.push(...k));0<e.length&&g.removeClassNamesFromElement(a,...e);0<d.length&&g.addClassNamesToElement(a,...d)} | ||
function M(a,b,c){r(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 O(a){if(a.classList.contains("task-list-item"))for(let b of a.children)if("INPUT"===b.tagName)return a=b,"checkbox"!==a.getAttribute("type")?a={node:null}:(a=a.hasAttribute("checked"),a={node:y(a)}),a;a=a.getAttribute("aria-checked");return{node:y("true"===a?!0:"false"===a?!1:void 0)}}function y(a){return h.$applyNodeReplacement(new I(void 0,a))}function q(a){return a instanceof I} | ||
class P extends h.ElementNode{static getType(){return"list"}static clone(a){return new P(a.__listType||S[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=S[a]||a;this.__tag="number"===a?"ol":"ul";this.__start=b}getTag(){return this.__tag}setListType(a){let b=this.getWritable();b.__listType=a;b.__tag="number"===a?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(a){let b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start", | ||
String(this.__start));b.__lexicalListType=this.__listType;T(b,a.theme,this);return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;T(b,c.theme,this);return!1}static transform(){return a=>{r(a)||l(163);var b=a.getNextSibling();r(b)&&a.getListType()===b.getListType()&&G(a,b);b="check"!==a.getListType();let c=a.getStart();for(let d of a.getChildren())q(d)&&(d.getValue()!==c&&d.setValue(c),b&&null!=d.getLatest().__checked&&d.setChecked(void 0),r(d.getFirstChild())||c++)}}static importDOM(){return{ol:()=> | ||
({conversion:U,priority:0}),ul:()=>({conversion:U,priority:0})}}static importJSON(a){let b=B(a.listType,a.start);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportDOM(a){(a=this.createDOM(a._config,a))&&g.isHTMLElement(a)&&(1!==this.__start&&a.setAttribute("start",String(this.__start)),"check"===this.__listType&&a.setAttribute("__lexicalListType","check"));return{element:a}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(), | ||
tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=0;c<a.length;c++){var b=a[c];if(q(b))super.append(b);else{let d=y();r(b)?d.append(b):h.$isElementNode(b)?b.isInline()?d.append(b):(b=h.$createTextNode(b.getTextContent()),d.append(b)):d.append(b);super.append(d)}}return this}extractWithChild(a){return q(a)}} | ||
function T(a,b,c){let d=[],e=[];var f=b.list;if(void 0!==f){let m=f[`${c.__tag}Depth`]||[];b=p(c)-1;let Q=b%m.length;var k=m[Q];let R=f[c.__tag],C,D=f.nested;f=f.checklist;void 0!==D&&D.list&&(C=D.list);void 0!==R&&d.push(R);void 0!==f&&"check"===c.__listType&&d.push(f);if(void 0!==k)for(d.push(...L(k)),k=0;k<m.length;k++)k!==Q&&e.push(c.__tag+k);void 0!==C&&(c=L(C),1<b?d.push(...c):e.push(...c))}0<e.length&&g.removeClassNamesFromElement(a,...e);0<d.length&&g.addClassNamesToElement(a,...d)} | ||
function V(a){let b=[];for(let d=0;d<a.length;d++){var c=a[d];q(c)?(b.push(c),c=c.getChildren(),1<c.length&&c.forEach(e=>{r(e)&&b.push(x(e))})):b.push(x(c))}return b} | ||
function U(a){let b=a.nodeName.toLowerCase(),c=null;if("ol"===b)c=B("number",a.start);else if("ul"===b){a:if("check"===a.getAttribute("__lexicallisttype")||a.classList.contains("contains-task-list"))a=!0;else{for(let d of a.childNodes)if(g.isHTMLElement(d)&&d.hasAttribute("aria-checked")){a=!0;break a}a=!1}c=a?B("check"):B("bullet")}return{after:V,node:c}}let S={ol:"number",ul:"bullet"};function B(a,b=1){return h.$applyNodeReplacement(new P(a,b))}function r(a){return a instanceof P} | ||
let W=h.createCommand("INSERT_UNORDERED_LIST_COMMAND"),X=h.createCommand("INSERT_ORDERED_LIST_COMMAND"),Y=h.createCommand("INSERT_CHECK_LIST_COMMAND"),Z=h.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=y;exports.$createListNode=B;exports.$getListDepth=p;exports.$handleListInsertParagraph=K;exports.$isListItemNode=q;exports.$isListNode=r;exports.INSERT_CHECK_LIST_COMMAND=Y;exports.INSERT_ORDERED_LIST_COMMAND=X;exports.INSERT_UNORDERED_LIST_COMMAND=W;exports.ListItemNode=I; | ||
exports.ListNode=P;exports.REMOVE_LIST_COMMAND=Z;exports.insertList=A;exports.registerList=function(a){return g.mergeRegister(a.registerCommand(X,()=>{A(a,"number");return!0},h.COMMAND_PRIORITY_LOW),a.registerCommand(W,()=>{A(a,"bullet");return!0},h.COMMAND_PRIORITY_LOW),a.registerCommand(Z,()=>{H(a);return!0},h.COMMAND_PRIORITY_LOW),a.registerCommand(h.INSERT_PARAGRAPH_COMMAND,()=>K()?!0:!1,h.COMMAND_PRIORITY_LOW))};exports.removeList=H | ||
function I(a){if(!v(a)){var b=a.getParent(),c=b?b.getParent():void 0,d=c?c.getParent():void 0;if(r(d)&&q(c)&&r(b)){d=b?b.getFirstChild():void 0;var e=b?b.getLastChild():void 0;if(a.is(d))c.insertBefore(a),b.isEmpty()&&c.remove();else if(a.is(e))c.insertAfter(a),b.isEmpty()&&c.remove();else{e=b.getListType();b=x();let f=A(e);b.append(f);a.getPreviousSiblings().forEach(k=>f.append(k));d=x();e=A(e);d.append(e);B(e,a.getNextSiblings());c.insertBefore(b);c.insertAfter(d);c.replace(a)}}}} | ||
function J(){var a=h.$getSelection();if(!h.$isRangeSelection(a)||!a.isCollapsed())return!1;var b=a.anchor.getNode();if(!q(b)||0!==b.getChildrenSize())return!1;var c=t(b),d=b.getParent();r(d)||l(40);let e=d.getParent();if(h.$isRootOrShadowRoot(e)){var f=h.$createParagraphNode();f.setTextStyle(a.style);f.setTextFormat(a.format);c.insertAfter(f)}else if(q(e))f=x(),e.insertAfter(f);else return!1;f.select();a=b.getNextSiblings();0<a.length&&(d=A(d.getListType()),q(f)?(c=x(),c.append(d),f.insertAfter(c)): | ||
f.insertAfter(d),d.append(...a));for(;null==b.getNextSibling()&&null==b.getPreviousSibling();){f=b.getParent();if(null==f||!q(b)&&!r(b))break;b=f}b.remove();return!0}function K(...a){let b=[];for(let c of a)if(c&&"string"===typeof c)for(let [d]of c.matchAll(/\S+/g))b.push(d);return b} | ||
class H extends h.ParagraphNode{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();r(c)&&"check"===c.getListType()&&L(b,this,null);b.value=this.__value;M(b,a.theme,this);return b}updateDOM(a,b,c){if(super.updateDOM(a,b,c))return!0;let d=this.getParent();r(d)&&"check"===d.getListType()&&L(b,this,a);b.value=this.__value; | ||
M(b,c.theme,this);return!1}static transform(){return a=>{q(a)||l(144);if(null!=a.__checked){var b=a.getParent();r(b)&&"check"!==b.getListType()&&null!=a.getChecked()&&a.setChecked(void 0)}}}static importDOM(){return{li:()=>({conversion:N,priority:0})}}static importJSON(a){let b=x();b.setChecked(a.checked);b.setValue(a.value);b.setFormat(a.format);b.setDirection(a.direction);"number"===typeof a.textFormat&&b.setTextFormat(a.textFormat);"string"===typeof a.textStyle&&b.setTextStyle(a.textStyle);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(q(a))return super.replace(a);this.setIndent(0);let c=this.getParentOrThrow();if(!r(c))return a;if(c.__first=== | ||
this.getKey())c.insertBefore(a);else if(c.__last===this.getKey())c.insertAfter(a);else{let d=A(c.getListType()),e=this.getNextSibling();for(;e;){let f=e;e=e.getNextSibling();d.append(f)}c.insertAfter(a);a.insertAfter(d)}b&&(h.$isElementNode(a)||l(139),this.getChildren().forEach(d=>{a.append(d)}));this.remove();0===c.getChildrenSize()&&c.remove();return a}insertAfter(a,b=!0){let c=this.getParentOrThrow();r(c)||l(39);if(q(a))return super.insertAfter(a,b);let d=this.getNextSiblings();c.insertAfter(a, | ||
b);if(0!==d.length){let e=A(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&&v(b)&&v(c)&&(F(b.getFirstChild(),c.getFirstChild()),c.remove())}insertNewAfter(a,b=!0){let c=x(null==this.__checked?void 0:!1);c.setTextFormat(a.format);c.setFormat(this.getFormatType());this.insertAfter(c,b);return c}collapseAtStart(){var a=h.$getSelection();if(!h.$isRangeSelection(a))return!1;let b=h.$createParagraphNode(); | ||
this.getChildren().forEach(d=>b.append(d));a=this.getParentOrThrow();let c=a.getParent();if(!r(a))return!1;1===a.getChildrenSize()&&(q(c)?(a.remove(),c.select()):(a.insertBefore(b),a.remove(),b.select()));return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=a}getChecked(){let a=this.getLatest(),b,c=this.getParent();r(c)&&(b=c.getListType());return"check"===b?!!a.__checked:void 0}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(;q(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){"number"!==typeof a&&l(117);a=Math.floor(a);0<=a||l(199);let b=this.getIndent();for(;b!==a;)if(b<a){var c=new Set;if(!v(this)&&!c.has(this.getKey())){var d=this.getParent(),e=this.getNextSibling(),f=this.getPreviousSibling();if(v(e)&&v(f))d=f.getFirstChild(),r(d)&&(d.append(this),f=e.getFirstChild(),r(f)&&(f=f.getChildren(),B(d, | ||
f),e.remove(),c.add(e.getKey())));else if(v(e))e=e.getFirstChild(),r(e)&&(e=e.getFirstChild(),null!==e&&e.insertBefore(this));else if(v(f))e=f.getFirstChild(),r(e)&&e.append(this);else if(r(d)){c=x();let k=A(d.getListType());c.append(k);k.append(this);f?f.insertAfter(c):e?e.insertBefore(c):d.append(c)}}b++}else I(this),b--;return this}canInsertAfter(a){return q(a)}canReplaceWith(a){return q(a)}canMergeWith(a){return q(a)||h.$isParagraphNode(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 A("bullet")}canMergeWhenEmpty(){return!0}} | ||
function M(a,b,c){let d=[],e=[];var f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var k=b.nested.listitem;void 0!==f&&d.push(...K(f));if(b){f=c.getParent();f=r(f)&&"check"===f.getListType();let m=c.getChecked();f&&!m||e.push(b.listitemUnchecked);f&&m||e.push(b.listitemChecked);f&&d.push(m?b.listitemChecked:b.listitemUnchecked)}void 0!==k&&(k=K(k),c.getChildren().some(m=>r(m))?d.push(...k):e.push(...k));0<e.length&&g.removeClassNamesFromElement(a,...e);0<d.length&&g.addClassNamesToElement(a,...d)} | ||
function L(a,b,c){r(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 N(a){if(a.classList.contains("task-list-item"))for(let b of a.children)if("INPUT"===b.tagName)return a=b,"checkbox"!==a.getAttribute("type")?a={node:null}:(a=a.hasAttribute("checked"),a={node:x(a)}),a;a=a.getAttribute("aria-checked");return{node:x("true"===a?!0:"false"===a?!1:void 0)}}function x(a){return h.$applyNodeReplacement(new H(void 0,a))}function q(a){return a instanceof H} | ||
class O extends h.ElementNode{static getType(){return"list"}static clone(a){return new O(a.__listType||P[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=P[a]||a;this.__tag="number"===a?"ol":"ul";this.__start=b}getTag(){return this.__tag}setListType(a){let b=this.getWritable();b.__listType=a;b.__tag="number"===a?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(a){let b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start", | ||
String(this.__start));b.__lexicalListType=this.__listType;S(b,a.theme,this);return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;S(b,c.theme,this);return!1}static transform(){return a=>{r(a)||l(163);var b=a.getNextSibling();r(b)&&a.getListType()===b.getListType()&&F(a,b);b="check"!==a.getListType();let c=a.getStart();for(let d of a.getChildren())q(d)&&(d.getValue()!==c&&d.setValue(c),b&&null!=d.getLatest().__checked&&d.setChecked(void 0),r(d.getFirstChild())||c++)}}static importDOM(){return{ol:()=> | ||
({conversion:T,priority:0}),ul:()=>({conversion:T,priority:0})}}static importJSON(a){let b=A(a.listType,a.start);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportDOM(a){(a=this.createDOM(a._config,a))&&g.isHTMLElement(a)&&(1!==this.__start&&a.setAttribute("start",String(this.__start)),"check"===this.__listType&&a.setAttribute("__lexicalListType","check"));return{element:a}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(), | ||
tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=0;c<a.length;c++){var b=a[c];if(q(b))super.append(b);else{let d=x();r(b)?d.append(b):h.$isElementNode(b)?b.isInline()?d.append(b):(b=h.$createTextNode(b.getTextContent()),d.append(b)):d.append(b);super.append(d)}}return this}extractWithChild(a){return q(a)}} | ||
function S(a,b,c){let d=[],e=[];var f=b.list;if(void 0!==f){let m=f[`${c.__tag}Depth`]||[];b=p(c)-1;let Q=b%m.length;var k=m[Q];let R=f[c.__tag],C,D=f.nested;f=f.checklist;void 0!==D&&D.list&&(C=D.list);void 0!==R&&d.push(R);void 0!==f&&"check"===c.__listType&&d.push(f);if(void 0!==k)for(d.push(...K(k)),k=0;k<m.length;k++)k!==Q&&e.push(c.__tag+k);void 0!==C&&(c=K(C),1<b?d.push(...c):e.push(...c))}0<e.length&&g.removeClassNamesFromElement(a,...e);0<d.length&&g.addClassNamesToElement(a,...d)} | ||
function U(a){let b=[];for(let d=0;d<a.length;d++){var c=a[d];q(c)?(b.push(c),c=c.getChildren(),1<c.length&&c.forEach(e=>{r(e)&&b.push(w(e))})):b.push(w(c))}return b} | ||
function T(a){let b=a.nodeName.toLowerCase(),c=null;if("ol"===b)c=A("number",a.start);else if("ul"===b){a:if("check"===a.getAttribute("__lexicallisttype")||a.classList.contains("contains-task-list"))a=!0;else{for(let d of a.childNodes)if(g.isHTMLElement(d)&&d.hasAttribute("aria-checked")){a=!0;break a}a=!1}c=a?A("check"):A("bullet")}return{after:U,node:c}}let P={ol:"number",ul:"bullet"};function A(a,b=1){return h.$applyNodeReplacement(new O(a,b))}function r(a){return a instanceof O} | ||
let V=h.createCommand("INSERT_UNORDERED_LIST_COMMAND"),W=h.createCommand("INSERT_ORDERED_LIST_COMMAND"),X=h.createCommand("INSERT_CHECK_LIST_COMMAND"),Y=h.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=x;exports.$createListNode=A;exports.$getListDepth=p;exports.$handleListInsertParagraph=J;exports.$isListItemNode=q;exports.$isListNode=r;exports.INSERT_CHECK_LIST_COMMAND=X;exports.INSERT_ORDERED_LIST_COMMAND=W;exports.INSERT_UNORDERED_LIST_COMMAND=V;exports.ListItemNode=H; | ||
exports.ListNode=O;exports.REMOVE_LIST_COMMAND=Y;exports.insertList=z;exports.registerList=function(a){return g.mergeRegister(a.registerCommand(W,()=>{z(a,"number");return!0},h.COMMAND_PRIORITY_LOW),a.registerCommand(V,()=>{z(a,"bullet");return!0},h.COMMAND_PRIORITY_LOW),a.registerCommand(Y,()=>{G(a);return!0},h.COMMAND_PRIORITY_LOW),a.registerCommand(h.INSERT_PARAGRAPH_COMMAND,()=>J()?!0:!1,h.COMMAND_PRIORITY_LOW))};exports.removeList=G |
@@ -8,10 +8,9 @@ /** | ||
*/ | ||
import type { BaseSelection, DOMConversionMap, DOMExportOutput, EditorConfig, LexicalNode, NodeKey, ParagraphNode, RangeSelection, SerializedElementNode, Spread } from 'lexical'; | ||
import { ElementNode, LexicalEditor } from 'lexical'; | ||
import { BaseSelection, DOMConversionMap, DOMExportOutput, EditorConfig, ElementNode, LexicalEditor, LexicalNode, NodeKey, ParagraphNode, RangeSelection, SerializedParagraphNode, Spread } from 'lexical'; | ||
export type SerializedListItemNode = Spread<{ | ||
checked: boolean | undefined; | ||
value: number; | ||
}, SerializedElementNode>; | ||
}, SerializedParagraphNode>; | ||
/** @noInheritDoc */ | ||
export declare class ListItemNode extends ElementNode { | ||
export declare class ListItemNode extends ParagraphNode { | ||
/** @internal */ | ||
@@ -25,3 +24,3 @@ __value: number; | ||
createDOM(config: EditorConfig): HTMLElement; | ||
updateDOM(prevNode: ListItemNode, dom: HTMLElement, config: EditorConfig): boolean; | ||
updateDOM(prevNode: this, dom: HTMLElement, config: EditorConfig): boolean; | ||
static transform(): (node: LexicalNode) => void; | ||
@@ -36,4 +35,4 @@ static importDOM(): DOMConversionMap | null; | ||
remove(preserveEmptyParent?: boolean): void; | ||
insertNewAfter(_: RangeSelection, restoreSelection?: boolean): ListItemNode | ParagraphNode; | ||
collapseAtStart(selection: RangeSelection): true; | ||
insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): ListItemNode | ParagraphNode; | ||
collapseAtStart(): boolean; | ||
getValue(): number; | ||
@@ -40,0 +39,0 @@ setValue(value: number): void; |
@@ -11,8 +11,8 @@ { | ||
"license": "MIT", | ||
"version": "0.21.1-nightly.20241210.0", | ||
"version": "0.21.1-nightly.20241211.0", | ||
"main": "LexicalList.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"@lexical/utils": "0.21.1-nightly.20241210.0", | ||
"lexical": "0.21.1-nightly.20241210.0" | ||
"@lexical/utils": "0.21.1-nightly.20241211.0", | ||
"lexical": "0.21.1-nightly.20241211.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "repository": { |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import type { LexicalNode, Spread } from 'lexical'; | ||
import { type LexicalNode, type Spread } from 'lexical'; | ||
import { ListItemNode, ListNode } from './'; | ||
@@ -11,0 +11,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
2941
139935
+ Added@lexical/clipboard@0.21.1-nightly.20241211.0(transitive)
+ Added@lexical/html@0.21.1-nightly.20241211.0(transitive)
+ Added@lexical/selection@0.21.1-nightly.20241211.0(transitive)
+ Added@lexical/table@0.21.1-nightly.20241211.0(transitive)
+ Added@lexical/utils@0.21.1-nightly.20241211.0(transitive)
+ Addedlexical@0.21.1-nightly.20241211.0(transitive)
- Removed@lexical/clipboard@0.21.1-nightly.20241210.0(transitive)
- Removed@lexical/html@0.21.1-nightly.20241210.0(transitive)
- Removed@lexical/selection@0.21.1-nightly.20241210.0(transitive)
- Removed@lexical/table@0.21.1-nightly.20241210.0(transitive)
- Removed@lexical/utils@0.21.1-nightly.20241210.0(transitive)
- Removedlexical@0.21.1-nightly.20241210.0(transitive)