@lexical/list
Advanced tools
Comparing version 0.14.5 to 0.15.0
@@ -6,3 +6,5 @@ /** | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
'use strict'; | ||
@@ -21,2 +23,3 @@ | ||
/** | ||
@@ -130,3 +133,3 @@ * Checks the depth of listNode from the root node. | ||
*/ | ||
function wrapInListItem(node) { | ||
function $wrapInListItem(node) { | ||
const listItemWrapper = $createListItemNode(); | ||
@@ -143,2 +146,3 @@ return listItemWrapper.append(node); | ||
*/ | ||
function $isSelectingEmptyListItem(anchorNode, nodes) { | ||
@@ -193,3 +197,3 @@ return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0); | ||
if (lexical.$isElementNode(node) && node.isEmpty() && !$isListItemNode(node) && !handled.has(node.getKey())) { | ||
createListOrMerge(node, listType); | ||
$createListOrMerge(node, listType); | ||
continue; | ||
@@ -213,3 +217,3 @@ } | ||
handled.add(parentKey); | ||
createListOrMerge(parent, listType); | ||
$createListOrMerge(parent, listType); | ||
break; | ||
@@ -228,3 +232,3 @@ } | ||
} | ||
function createListOrMerge(node, listType) { | ||
function $createListOrMerge(node, listType) { | ||
if ($isListNode(node)) { | ||
@@ -575,2 +579,3 @@ return node; | ||
*/ | ||
/** @noInheritDoc */ | ||
@@ -632,3 +637,3 @@ class ListItemNode extends lexical.ElementNode { | ||
li: node => ({ | ||
conversion: convertListItemElement, | ||
conversion: $convertListItemElement, | ||
priority: 0 | ||
@@ -912,3 +917,3 @@ }) | ||
} | ||
function convertListItemElement(domNode) { | ||
function $convertListItemElement(domNode) { | ||
const checked = utils.isHTMLElement(domNode) && domNode.getAttribute('aria-checked') === 'true'; | ||
@@ -945,2 +950,3 @@ return { | ||
*/ | ||
/** @noInheritDoc */ | ||
@@ -993,3 +999,3 @@ class ListNode extends lexical.ElementNode { | ||
dom.__lexicalListType = this.__listType; | ||
setListThemeClassNames(dom, config.theme, this); | ||
$setListThemeClassNames(dom, config.theme, this); | ||
return dom; | ||
@@ -1001,3 +1007,3 @@ } | ||
} | ||
setListThemeClassNames(dom, config.theme, this); | ||
$setListThemeClassNames(dom, config.theme, this); | ||
return false; | ||
@@ -1017,7 +1023,7 @@ } | ||
ol: node => ({ | ||
conversion: convertListNode, | ||
conversion: $convertListNode, | ||
priority: 0 | ||
}), | ||
ul: node => ({ | ||
conversion: convertListNode, | ||
conversion: $convertListNode, | ||
priority: 0 | ||
@@ -1090,3 +1096,3 @@ }) | ||
} | ||
function setListThemeClassNames(dom, editorThemeClasses, node) { | ||
function $setListThemeClassNames(dom, editorThemeClasses, node) { | ||
const classesToAdd = []; | ||
@@ -1143,3 +1149,3 @@ const classesToRemove = []; | ||
*/ | ||
function normalizeChildren(nodes) { | ||
function $normalizeChildren(nodes) { | ||
const normalizedListItems = []; | ||
@@ -1154,3 +1160,3 @@ for (let i = 0; i < nodes.length; i++) { | ||
if ($isListNode(child)) { | ||
normalizedListItems.push(wrapInListItem(child)); | ||
normalizedListItems.push($wrapInListItem(child)); | ||
} | ||
@@ -1160,3 +1166,3 @@ }); | ||
} else { | ||
normalizedListItems.push(wrapInListItem(node)); | ||
normalizedListItems.push($wrapInListItem(node)); | ||
} | ||
@@ -1166,3 +1172,3 @@ } | ||
} | ||
function convertListNode(domNode) { | ||
function $convertListNode(domNode) { | ||
const nodeName = domNode.nodeName.toLowerCase(); | ||
@@ -1182,3 +1188,3 @@ let node = null; | ||
return { | ||
after: normalizeChildren, | ||
after: $normalizeChildren, | ||
node | ||
@@ -1218,2 +1224,3 @@ }; | ||
*/ | ||
const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand('INSERT_UNORDERED_LIST_COMMAND'); | ||
@@ -1220,0 +1227,0 @@ const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand('INSERT_ORDERED_LIST_COMMAND'); |
@@ -6,5 +6,7 @@ /** | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
'use strict' | ||
const LexicalList = process.env.NODE_ENV === 'development' ? require('./LexicalList.dev.js') : require('./LexicalList.prod.js'); | ||
module.exports = LexicalList; |
@@ -6,32 +6,34 @@ /** | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
'use strict';var g=require("lexical"),h=require("@lexical/utils");function l(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.");} | ||
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}l(40)}break}return b}function r(a){a=a.getParent();q(a)||l(40);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}function t(a){let b=[];a=a.getChildren().filter(p);for(let c=0;c<a.length;c++){let d=a[c],e=d.getFirstChild();q(e)?b=b.concat(t(e)):b.push(d)}return b}function u(a){return p(a)&&q(a.getFirstChild())} | ||
function v(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){let b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function w(a){return x().append(a)}function y(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}function z(a,b){a.splice(a.getChildrenSize(),0,b)} | ||
function C(a,b){if(q(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=x();e.setFormat(a.getFormatType());e.setIndent(a.getIndent());z(e,a.getChildren());if(q(c)&&b===c.getListType())return c.append(e),a.remove(),q(d)&&b===d.getListType()&&(z(c,d.getChildren()),d.remove()),c;if(q(d)&&b===d.getListType())return d.getFirstChildOrThrow().insertBefore(e),a.remove(),d;b=D(b);b.append(e);a.replace(b);return b} | ||
function E(a,b){var c=a.getLastChild();let d=b.getFirstChild();c&&d&&u(c)&&u(d)&&(E(c.getFirstChild(),d.getFirstChild()),d.remove());c=b.getChildren();0<c.length&&a.append(...c);b.remove()} | ||
function F(a){if(!u(a)){var b=a.getParent(),c=b?b.getParent():void 0,d=c?c.getParent():void 0;if(q(d)&&p(c)&&q(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=D(e);b.append(f);a.getPreviousSiblings().forEach(k=>f.append(k));d=x();e=D(e);d.append(e);z(e,a.getNextSiblings());c.insertBefore(b);c.insertAfter(d);c.replace(a)}}}} | ||
function G(...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 g.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=> | ||
{p(a)||l(144);if(null!=a.__checked){var b=a.getParent();q(b)&&"check"!==b.getListType()&&null!=a.getChecked()&&a.setChecked(void 0)}}}static importDOM(){return{li:()=>({conversion:K,priority:0})}}static importJSON(a){let b=x();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(g.$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&&(g.$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();q(c)||l(39);if(p(a))return super.insertAfter(a,b);let d=this.getNextSiblings();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)&&(E(b.getFirstChild(),c.getFirstChild()),c.remove())}insertNewAfter(a,b=!0){a=x(null==this.__checked?void 0:!1);this.insertAfter(a,b);return a}collapseAtStart(a){let b=g.$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||l(117);let b=this.getIndent();for(;b!==a;)if(b<a){var c=new Set;if(!u(this)&&!c.has(this.getKey())){var d=this.getParent(),e=this.getNextSibling(),f=this.getPreviousSibling();if(u(e)&&u(f))d=f.getFirstChild(),q(d)&&(d.append(this),f=e.getFirstChild(),q(f)&&(f=f.getChildren(),z(d,f),e.remove(),c.add(e.getKey())));else if(u(e))e=e.getFirstChild(),q(e)&&(e=e.getFirstChild(),null!==e&&e.insertBefore(this));else if(u(f))e=f.getFirstChild(),q(e)&&e.append(this); | ||
else if(q(d)){c=x();let k=D(d.getListType());c.append(k);k.append(this);f?f.insertAfter(c):e?e.insertBefore(c):d.append(c)}}b++}else F(this),b--;return this}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return g.$isParagraphNode(a)||p(a)}extractWithChild(a,b){if(!g.$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 k=b.nested.listitem;void 0!==f&&d.push(...G(f));if(b){f=c.getParent();f=q(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=G(k),c.getChildren().some(m=>q(m))?d.push(...k):e.push(...k));0<e.length&&h.removeClassNamesFromElement(a,...e);0<d.length&&h.addClassNamesToElement(a,...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=h.isHTMLElement(a)&&"true"===a.getAttribute("aria-checked");return{node:x(a)}}function x(a){return g.$applyNodeReplacement(new H(void 0,a))}function p(a){return a instanceof H} | ||
class L extends g.ElementNode{static getType(){return"list"}static clone(a){return new L(a.__listType||O[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=O[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;P(b,a.theme,this);return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;P(b,c.theme,this);return!1}static transform(){return a=>{if(!q(a))throw Error("node is not a ListNode");var b=a.getNextSibling();q(b)&&a.getListType()===b.getListType()&&E(a,b);b="check"!==a.getListType();let c=a.getStart();for(let d of a.getChildren())p(d)&&(d.getValue()!==c&&d.setValue(c),b&&null!=d.getChecked()&&d.setChecked(void 0),q(d.getFirstChild())||c++)}}static importDOM(){return{ol:()=> | ||
({conversion:Q,priority:0}),ul:()=>({conversion:Q,priority:0})}}static importJSON(a){let b=D(a.listType,a.start);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportDOM(a){({element:a}=super.exportDOM(a));a&&h.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(p(b))super.append(b);else{let d=x();q(b)?d.append(b):g.$isElementNode(b)?(b=g.$createTextNode(b.getTextContent()),d.append(b)):d.append(b);super.append(d)}}return this}extractWithChild(a){return p(a)}} | ||
function P(a,b,c){let d=[],e=[];var f=b.list;if(void 0!==f){let m=f[`${c.__tag}Depth`]||[];b=n(c)-1;let M=b%m.length;var k=m[M];let N=f[c.__tag],A,B=f.nested;f=f.checklist;void 0!==B&&B.list&&(A=B.list);void 0!==N&&d.push(N);void 0!==f&&"check"===c.__listType&&d.push(f);if(void 0!==k)for(d.push(...G(k)),k=0;k<m.length;k++)k!==M&&e.push(c.__tag+k);void 0!==A&&(c=G(A),1<b?d.push(...c):e.push(...c))}0<e.length&&h.removeClassNamesFromElement(a,...e);0<d.length&&h.addClassNamesToElement(a,...d)} | ||
function R(a){let b=[];for(let d=0;d<a.length;d++){var c=a[d];p(c)?(b.push(c),c=c.getChildren(),1<c.length&&c.forEach(e=>{q(e)&&b.push(w(e))})):b.push(w(c))}return b}function Q(a){let b=a.nodeName.toLowerCase(),c=null;"ol"===b?c=D("number",a.start):"ul"===b&&(c=h.isHTMLElement(a)&&"check"===a.getAttribute("__lexicallisttype")?D("check"):D("bullet"));return{after:R,node:c}}let O={ol:"number",ul:"bullet"};function D(a,b=1){return g.$applyNodeReplacement(new L(a,b))} | ||
function q(a){return a instanceof L}let S=g.createCommand("INSERT_UNORDERED_LIST_COMMAND"),T=g.createCommand("INSERT_ORDERED_LIST_COMMAND"),U=g.createCommand("INSERT_CHECK_LIST_COMMAND"),V=g.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=x;exports.$createListNode=D;exports.$getListDepth=n; | ||
exports.$handleListInsertParagraph=function(){var a=g.$getSelection();if(!g.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!p(a)||0!==a.getChildrenSize())return!1;var b=r(a),c=a.getParent();q(c)||l(40);let d=c.getParent(),e;if(g.$isRootOrShadowRoot(d))e=g.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=x(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){let f=D(c.getListType());g.$isParagraphNode(e)?e.insertAfter(f):(c=x(),c.append(f), | ||
e.insertAfter(c));b.forEach(k=>{k.remove();f.append(k)})}v(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_CHECK_LIST_COMMAND=U;exports.INSERT_ORDERED_LIST_COMMAND=T;exports.INSERT_UNORDERED_LIST_COMMAND=S;exports.ListItemNode=H;exports.ListNode=L;exports.REMOVE_LIST_COMMAND=V; | ||
exports.insertList=function(a,b){a.update(()=>{var c=g.$getSelection();if(null!==c){var d=c.getNodes();if(g.$isRangeSelection(c)){c=c.getStartEndPoints();null===c&&l(143);[c]=c;c=c.getNode();var e=c.getParent();if(y(c,d)){d=D(b);g.$isRootOrShadowRoot(e)?(c.replace(d),e=x(),g.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),d.append(e)):p(c)&&(c=c.getParentOrThrow(),z(d,c.getChildren()),c.replace(d));return}}c=new Set;for(e=0;e<d.length;e++){var f=d[e];if(g.$isElementNode(f)&& | ||
f.isEmpty()&&!p(f)&&!c.has(f.getKey()))C(f,b);else if(g.$isLeafNode(f))for(f=f.getParent();null!=f;){let m=f.getKey();if(q(f)){if(!c.has(m)){var k=D(b);z(k,f.getChildren());f.replace(k);c.add(m)}break}else{k=f.getParent();if(g.$isRootOrShadowRoot(k)&&!c.has(m)){c.add(m);C(f,b);break}f=k}}}}})}; | ||
exports.removeList=function(a){a.update(()=>{let b=g.$getSelection();if(g.$isRangeSelection(b)){var c=new Set,d=b.getNodes(),e=b.anchor.getNode();if(y(e,d))c.add(r(e));else for(e=0;e<d.length;e++){var f=d[e];g.$isLeafNode(f)&&(f=h.$getNearestNodeOfType(f,H),null!=f&&c.add(r(f)))}for(let k of c){c=k;d=t(k);for(let m of d)d=g.$createParagraphNode(),z(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"), | ||
'use strict';var g=require("lexical"),h=require("@lexical/utils"),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.splice(a.getChildrenSize(),0,b)} | ||
function D(a,b){if(r(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=y();e.setFormat(a.getFormatType());e.setIndent(a.getIndent());A(e,a.getChildren());if(r(c)&&b===c.getListType())return c.append(e),a.remove(),r(d)&&b===d.getListType()&&(A(c,d.getChildren()),d.remove()),c;if(r(d)&&b===d.getListType())return d.getFirstChildOrThrow().insertBefore(e),a.remove(),d;b=E(b);b.append(e);a.replace(b);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){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=E(e);b.append(f);a.getPreviousSiblings().forEach(k=>f.append(k));d=y();e=E(e);d.append(e);A(e,a.getNextSiblings());c.insertBefore(b);c.insertAfter(d);c.replace(a)}}}} | ||
function H(...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 g.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()&&J(b,this,null);b.value=this.__value;K(b,a.theme,this);return b}updateDOM(a,b,c){let d=this.getParent();r(d)&&"check"===d.getListType()&&J(b,this,a);b.value=this.__value;K(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:L,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(g.$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=E(c.getListType()),e=this.getNextSibling();for(;e;){let f=e;e=e.getNextSibling(); | ||
d.append(f)}c.insertAfter(a);a.insertAfter(d)}b&&(g.$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=E(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){a=y(null==this.__checked?void 0:!1);this.insertAfter(a,b);return a}collapseAtStart(a){let b=g.$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(){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(;q(a);)a=a.getParentOrThrow().getParentOrThrow(), | ||
b++;return b}setIndent(a){"number"===typeof a&&-1<a||l(117);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(),A(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=E(d.getListType());c.append(k);k.append(this);f?f.insertAfter(c):e?e.insertBefore(c):d.append(c)}}b++}else G(this),b--;return this}canInsertAfter(a){return q(a)}canReplaceWith(a){return q(a)}canMergeWith(a){return g.$isParagraphNode(a)||q(a)}extractWithChild(a,b){if(!g.$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 E("bullet")}} | ||
function K(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(...H(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=H(k),c.getChildren().some(m=>r(m))?d.push(...k):e.push(...k));0<e.length&&h.removeClassNamesFromElement(a,...e);0<d.length&&h.addClassNamesToElement(a,...d)} | ||
function J(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 L(a){a=h.isHTMLElement(a)&&"true"===a.getAttribute("aria-checked");return{node:y(a)}}function y(a){return g.$applyNodeReplacement(new I(void 0,a))}function q(a){return a instanceof I} | ||
class M extends g.ElementNode{static getType(){return"list"}static clone(a){return new M(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;Q(b,a.theme,this);return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;Q(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.getChecked()&&d.setChecked(void 0),r(d.getFirstChild())||c++)}}static importDOM(){return{ol:()=>({conversion:R, | ||
priority:0}),ul:()=>({conversion:R,priority:0})}}static importJSON(a){let b=E(a.listType,a.start);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportDOM(a){({element:a}=super.exportDOM(a));a&&h.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):g.$isElementNode(b)?(b=g.$createTextNode(b.getTextContent()),d.append(b)):d.append(b);super.append(d)}}return this}extractWithChild(a){return q(a)}} | ||
function Q(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 N=b%m.length;var k=m[N];let O=f[c.__tag],B,C=f.nested;f=f.checklist;void 0!==C&&C.list&&(B=C.list);void 0!==O&&d.push(O);void 0!==f&&"check"===c.__listType&&d.push(f);if(void 0!==k)for(d.push(...H(k)),k=0;k<m.length;k++)k!==N&&e.push(c.__tag+k);void 0!==B&&(c=H(B),1<b?d.push(...c):e.push(...c))}0<e.length&&h.removeClassNamesFromElement(a,...e);0<d.length&&h.addClassNamesToElement(a,...d)} | ||
function S(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 R(a){let b=a.nodeName.toLowerCase(),c=null;"ol"===b?c=E("number",a.start):"ul"===b&&(c=h.isHTMLElement(a)&&"check"===a.getAttribute("__lexicallisttype")?E("check"):E("bullet"));return{after:S,node:c}}let P={ol:"number",ul:"bullet"};function E(a,b=1){return g.$applyNodeReplacement(new M(a,b))} | ||
function r(a){return a instanceof M}let T=g.createCommand("INSERT_UNORDERED_LIST_COMMAND"),U=g.createCommand("INSERT_ORDERED_LIST_COMMAND"),V=g.createCommand("INSERT_CHECK_LIST_COMMAND"),W=g.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=y;exports.$createListNode=E;exports.$getListDepth=p; | ||
exports.$handleListInsertParagraph=function(){var a=g.$getSelection();if(!g.$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(g.$isRootOrShadowRoot(d))e=g.$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=E(c.getListType());g.$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};exports.$isListItemNode=q;exports.$isListNode=r;exports.INSERT_CHECK_LIST_COMMAND=V;exports.INSERT_ORDERED_LIST_COMMAND=U;exports.INSERT_UNORDERED_LIST_COMMAND=T;exports.ListItemNode=I;exports.ListNode=M;exports.REMOVE_LIST_COMMAND=W; | ||
exports.insertList=function(a,b){a.update(()=>{var c=g.$getSelection();if(null!==c){var d=c.getNodes();if(g.$isRangeSelection(c)){c=c.getStartEndPoints();null===c&&l(143);[c]=c;c=c.getNode();var e=c.getParent();if(z(c,d)){d=E(b);g.$isRootOrShadowRoot(e)?(c.replace(d),e=y(),g.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),d.append(e)):q(c)&&(c=c.getParentOrThrow(),A(d,c.getChildren()),c.replace(d));return}}c=new Set;for(e=0;e<d.length;e++){var f=d[e];if(g.$isElementNode(f)&& | ||
f.isEmpty()&&!q(f)&&!c.has(f.getKey()))D(f,b);else if(g.$isLeafNode(f))for(f=f.getParent();null!=f;){let m=f.getKey();if(r(f)){if(!c.has(m)){var k=E(b);A(k,f.getChildren());f.replace(k);c.add(m)}break}else{k=f.getParent();if(g.$isRootOrShadowRoot(k)&&!c.has(m)){c.add(m);D(f,b);break}f=k}}}}})}; | ||
exports.removeList=function(a){a.update(()=>{let b=g.$getSelection();if(g.$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];g.$isLeafNode(f)&&(f=h.$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=g.$createParagraphNode(),A(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()}}})} |
@@ -11,8 +11,8 @@ { | ||
"license": "MIT", | ||
"version": "0.14.5", | ||
"version": "0.15.0", | ||
"main": "LexicalList.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"@lexical/utils": "0.14.5", | ||
"lexical": "0.14.5" | ||
"@lexical/utils": "0.15.0", | ||
"lexical": "0.15.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "repository": { |
@@ -1,2 +0,2 @@ | ||
`@lexical/list` | ||
# `@lexical/list` | ||
@@ -3,0 +3,0 @@ [![See API Documentation](https://lexical.dev/img/see-api-documentation.svg)](https://lexical.dev/docs/api/modules/lexical_list) |
@@ -50,3 +50,3 @@ /** | ||
*/ | ||
export declare function findNearestListItemNode(node: LexicalNode): ListItemNode | null; | ||
export declare function $findNearestListItemNode(node: LexicalNode): ListItemNode | null; | ||
/** | ||
@@ -65,3 +65,3 @@ * Takes a deeply nested ListNode or ListItemNode and traverses up the branch to delete the first | ||
*/ | ||
export declare function wrapInListItem(node: LexicalNode): ListItemNode; | ||
export declare function $wrapInListItem(node: LexicalNode): ListItemNode; | ||
export {}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
133043
2781
+ Added@lexical/selection@0.15.0(transitive)
+ Added@lexical/table@0.15.0(transitive)
+ Added@lexical/utils@0.15.0(transitive)
+ Addedlexical@0.15.0(transitive)
- Removed@lexical/selection@0.14.5(transitive)
- Removed@lexical/table@0.14.5(transitive)
- Removed@lexical/utils@0.14.5(transitive)
- Removedlexical@0.14.5(transitive)
Updated@lexical/utils@0.15.0
Updatedlexical@0.15.0