@lexical/list 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalList.dev.js +44 -5
- package/LexicalList.dev.mjs +44 -5
- package/LexicalList.prod.js +5 -3
- package/LexicalList.prod.mjs +1 -1
- package/LexicalListItemNode.d.ts +2 -0
- package/package.json +3 -3
package/LexicalList.dev.js
CHANGED
|
@@ -625,7 +625,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
625
625
|
}
|
|
626
626
|
static importDOM() {
|
|
627
627
|
return {
|
|
628
|
-
li:
|
|
628
|
+
li: () => ({
|
|
629
629
|
conversion: $convertListItemElement,
|
|
630
630
|
priority: 0
|
|
631
631
|
})
|
|
@@ -826,9 +826,13 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
826
826
|
}
|
|
827
827
|
return this;
|
|
828
828
|
}
|
|
829
|
+
|
|
830
|
+
/** @deprecated @internal */
|
|
829
831
|
canInsertAfter(node) {
|
|
830
832
|
return $isListItemNode(node);
|
|
831
833
|
}
|
|
834
|
+
|
|
835
|
+
/** @deprecated @internal */
|
|
832
836
|
canReplaceWith(replacement) {
|
|
833
837
|
return $isListItemNode(replacement);
|
|
834
838
|
}
|
|
@@ -906,7 +910,28 @@ function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
|
|
|
906
910
|
}
|
|
907
911
|
}
|
|
908
912
|
function $convertListItemElement(domNode) {
|
|
909
|
-
const
|
|
913
|
+
const isGitHubCheckList = domNode.classList.contains('task-list-item');
|
|
914
|
+
if (isGitHubCheckList) {
|
|
915
|
+
for (const child of domNode.children) {
|
|
916
|
+
if (child.tagName === 'INPUT') {
|
|
917
|
+
return $convertCheckboxInput(child);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const ariaCheckedAttr = domNode.getAttribute('aria-checked');
|
|
922
|
+
const checked = ariaCheckedAttr === 'true' ? true : ariaCheckedAttr === 'false' ? false : undefined;
|
|
923
|
+
return {
|
|
924
|
+
node: $createListItemNode(checked)
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
function $convertCheckboxInput(domNode) {
|
|
928
|
+
const isCheckboxInput = domNode.getAttribute('type') === 'checkbox';
|
|
929
|
+
if (!isCheckboxInput) {
|
|
930
|
+
return {
|
|
931
|
+
node: null
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
const checked = domNode.hasAttribute('checked');
|
|
910
935
|
return {
|
|
911
936
|
node: $createListItemNode(checked)
|
|
912
937
|
};
|
|
@@ -1006,11 +1031,11 @@ class ListNode extends lexical.ElementNode {
|
|
|
1006
1031
|
}
|
|
1007
1032
|
static importDOM() {
|
|
1008
1033
|
return {
|
|
1009
|
-
ol:
|
|
1034
|
+
ol: () => ({
|
|
1010
1035
|
conversion: $convertListNode,
|
|
1011
1036
|
priority: 0
|
|
1012
1037
|
}),
|
|
1013
|
-
ul:
|
|
1038
|
+
ul: () => ({
|
|
1014
1039
|
conversion: $convertListNode,
|
|
1015
1040
|
priority: 0
|
|
1016
1041
|
})
|
|
@@ -1151,6 +1176,20 @@ function $normalizeChildren(nodes) {
|
|
|
1151
1176
|
}
|
|
1152
1177
|
return normalizedListItems;
|
|
1153
1178
|
}
|
|
1179
|
+
function isDomChecklist(domNode) {
|
|
1180
|
+
if (domNode.getAttribute('__lexicallisttype') === 'check' ||
|
|
1181
|
+
// is github checklist
|
|
1182
|
+
domNode.classList.contains('contains-task-list')) {
|
|
1183
|
+
return true;
|
|
1184
|
+
}
|
|
1185
|
+
// if children are checklist items, the node is a checklist ul. Applicable for googledoc checklist pasting.
|
|
1186
|
+
for (const child of domNode.childNodes) {
|
|
1187
|
+
if (utils.isHTMLElement(child) && child.hasAttribute('aria-checked')) {
|
|
1188
|
+
return true;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
return false;
|
|
1192
|
+
}
|
|
1154
1193
|
function $convertListNode(domNode) {
|
|
1155
1194
|
const nodeName = domNode.nodeName.toLowerCase();
|
|
1156
1195
|
let node = null;
|
|
@@ -1159,7 +1198,7 @@ function $convertListNode(domNode) {
|
|
|
1159
1198
|
const start = domNode.start;
|
|
1160
1199
|
node = $createListNode('number', start);
|
|
1161
1200
|
} else if (nodeName === 'ul') {
|
|
1162
|
-
if (
|
|
1201
|
+
if (isDomChecklist(domNode)) {
|
|
1163
1202
|
node = $createListNode('check');
|
|
1164
1203
|
} else {
|
|
1165
1204
|
node = $createListNode('bullet');
|
package/LexicalList.dev.mjs
CHANGED
|
@@ -623,7 +623,7 @@ class ListItemNode extends ElementNode {
|
|
|
623
623
|
}
|
|
624
624
|
static importDOM() {
|
|
625
625
|
return {
|
|
626
|
-
li:
|
|
626
|
+
li: () => ({
|
|
627
627
|
conversion: $convertListItemElement,
|
|
628
628
|
priority: 0
|
|
629
629
|
})
|
|
@@ -824,9 +824,13 @@ class ListItemNode extends ElementNode {
|
|
|
824
824
|
}
|
|
825
825
|
return this;
|
|
826
826
|
}
|
|
827
|
+
|
|
828
|
+
/** @deprecated @internal */
|
|
827
829
|
canInsertAfter(node) {
|
|
828
830
|
return $isListItemNode(node);
|
|
829
831
|
}
|
|
832
|
+
|
|
833
|
+
/** @deprecated @internal */
|
|
830
834
|
canReplaceWith(replacement) {
|
|
831
835
|
return $isListItemNode(replacement);
|
|
832
836
|
}
|
|
@@ -904,7 +908,28 @@ function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
|
|
|
904
908
|
}
|
|
905
909
|
}
|
|
906
910
|
function $convertListItemElement(domNode) {
|
|
907
|
-
const
|
|
911
|
+
const isGitHubCheckList = domNode.classList.contains('task-list-item');
|
|
912
|
+
if (isGitHubCheckList) {
|
|
913
|
+
for (const child of domNode.children) {
|
|
914
|
+
if (child.tagName === 'INPUT') {
|
|
915
|
+
return $convertCheckboxInput(child);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
const ariaCheckedAttr = domNode.getAttribute('aria-checked');
|
|
920
|
+
const checked = ariaCheckedAttr === 'true' ? true : ariaCheckedAttr === 'false' ? false : undefined;
|
|
921
|
+
return {
|
|
922
|
+
node: $createListItemNode(checked)
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
function $convertCheckboxInput(domNode) {
|
|
926
|
+
const isCheckboxInput = domNode.getAttribute('type') === 'checkbox';
|
|
927
|
+
if (!isCheckboxInput) {
|
|
928
|
+
return {
|
|
929
|
+
node: null
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
const checked = domNode.hasAttribute('checked');
|
|
908
933
|
return {
|
|
909
934
|
node: $createListItemNode(checked)
|
|
910
935
|
};
|
|
@@ -1004,11 +1029,11 @@ class ListNode extends ElementNode {
|
|
|
1004
1029
|
}
|
|
1005
1030
|
static importDOM() {
|
|
1006
1031
|
return {
|
|
1007
|
-
ol:
|
|
1032
|
+
ol: () => ({
|
|
1008
1033
|
conversion: $convertListNode,
|
|
1009
1034
|
priority: 0
|
|
1010
1035
|
}),
|
|
1011
|
-
ul:
|
|
1036
|
+
ul: () => ({
|
|
1012
1037
|
conversion: $convertListNode,
|
|
1013
1038
|
priority: 0
|
|
1014
1039
|
})
|
|
@@ -1149,6 +1174,20 @@ function $normalizeChildren(nodes) {
|
|
|
1149
1174
|
}
|
|
1150
1175
|
return normalizedListItems;
|
|
1151
1176
|
}
|
|
1177
|
+
function isDomChecklist(domNode) {
|
|
1178
|
+
if (domNode.getAttribute('__lexicallisttype') === 'check' ||
|
|
1179
|
+
// is github checklist
|
|
1180
|
+
domNode.classList.contains('contains-task-list')) {
|
|
1181
|
+
return true;
|
|
1182
|
+
}
|
|
1183
|
+
// if children are checklist items, the node is a checklist ul. Applicable for googledoc checklist pasting.
|
|
1184
|
+
for (const child of domNode.childNodes) {
|
|
1185
|
+
if (isHTMLElement(child) && child.hasAttribute('aria-checked')) {
|
|
1186
|
+
return true;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
return false;
|
|
1190
|
+
}
|
|
1152
1191
|
function $convertListNode(domNode) {
|
|
1153
1192
|
const nodeName = domNode.nodeName.toLowerCase();
|
|
1154
1193
|
let node = null;
|
|
@@ -1157,7 +1196,7 @@ function $convertListNode(domNode) {
|
|
|
1157
1196
|
const start = domNode.start;
|
|
1158
1197
|
node = $createListNode('number', start);
|
|
1159
1198
|
} else if (nodeName === 'ul') {
|
|
1160
|
-
if (
|
|
1199
|
+
if (isDomChecklist(domNode)) {
|
|
1161
1200
|
node = $createListNode('check');
|
|
1162
1201
|
} else {
|
|
1163
1202
|
node = $createListNode('bullet');
|
package/LexicalList.prod.js
CHANGED
|
@@ -22,14 +22,16 @@ b&&c&&v(b)&&v(c)&&(F(b.getFirstChild(),c.getFirstChild()),c.remove())}insertNewA
|
|
|
22
22
|
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);
|
|
23
23
|
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")}}
|
|
24
24
|
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)}
|
|
25
|
-
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"))}
|
|
25
|
+
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"))}
|
|
26
|
+
function L(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 g.$applyNodeReplacement(new I(void 0,a))}function q(a){return a instanceof I}
|
|
26
27
|
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",
|
|
27
28
|
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,
|
|
28
29
|
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(),
|
|
29
30
|
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)}}
|
|
30
31
|
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)}
|
|
31
|
-
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}
|
|
32
|
-
function
|
|
32
|
+
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}
|
|
33
|
+
function R(a){let b=a.nodeName.toLowerCase(),c=null;if("ol"===b)c=E("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(h.isHTMLElement(d)&&d.hasAttribute("aria-checked")){a=!0;break a}a=!1}c=a?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}
|
|
34
|
+
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;
|
|
33
35
|
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),
|
|
34
36
|
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;
|
|
35
37
|
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)&&
|
package/LexicalList.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$getSelection as e,$isRangeSelection as t,$isRootOrShadowRoot as n,$isElementNode as r,$isLeafNode as i,$createParagraphNode as s,$isParagraphNode as o,ElementNode as c,$applyNodeReplacement as l,$createTextNode as h,createCommand as a}from"lexical";import{$getNearestNodeOfType as u,removeClassNamesFromElement as g,addClassNamesToElement as d,isHTMLElement as f}from"@lexical/utils";function p(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _=p((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function m(e){let t=1,n=e.getParent();for(;null!=n;){if(R(n)){const e=n.getParent();if(U(e)){t++,n=e.getParent();continue}_(40)}return t}return t}function v(e){let t=e.getParent();U(t)||_(40);let n=t;for(;null!==n;)n=n.getParent(),U(n)&&(t=n);return t}function y(e){let t=[];const n=e.getChildren().filter(R);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();U(i)?t=t.concat(y(i)):t.push(r)}return t}function C(e){return R(e)&&U(e.getFirstChild())}function T(e){return I().append(e)}function k(e,t){return R(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function S(s,o){s.update((()=>{const s=e();if(null!==s){const e=s.getNodes();if(t(s)){const t=s.getStartEndPoints();null===t&&_(143);const[i]=t,c=i.getNode(),l=c.getParent();if(k(c,e)){const e=z(o);if(n(l)){c.replace(e);const t=I();r(c)&&(t.setFormat(c.getFormatType()),t.setIndent(c.getIndent())),e.append(t)}else if(R(c)){const t=c.getParentOrThrow();b(e,t.getChildren()),t.replace(e)}return}}const c=new Set;for(let t=0;t<e.length;t++){const s=e[t];if(!r(s)||!s.isEmpty()||R(s)||c.has(s.getKey())){if(i(s)){let e=s.getParent();for(;null!=e;){const t=e.getKey();if(U(e)){if(!c.has(t)){const n=z(o);b(n,e.getChildren()),e.replace(n),c.add(t)}break}{const r=e.getParent();if(n(r)&&!c.has(t)){c.add(t),P(e,o);break}e=r}}}}else P(s,o)}}}))}function b(e,t){e.splice(e.getChildrenSize(),0,t)}function P(e,t){if(U(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=I();if(i.setFormat(e.getFormatType()),i.setIndent(e.getIndent()),b(i,e.getChildren()),U(n)&&t===n.getListType())return n.append(i),e.remove(),U(r)&&t===r.getListType()&&(b(n,r.getChildren()),r.remove()),n;if(U(r)&&t===r.getListType())return r.getFirstChildOrThrow().insertBefore(i),e.remove(),r;{const n=z(t);return n.append(i),e.replace(n),n}}function x(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&C(n)&&C(r)&&(x(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function A(n){n.update((()=>{const n=e();if(t(n)){const e=new Set,t=n.getNodes(),r=n.anchor.getNode();if(k(r,t))e.add(v(r));else for(let n=0;n<t.length;n++){const r=t[n];if(i(r)){const t=u(r,F);null!=t&&e.add(v(t))}}for(const t of e){let e=t;const r=y(t);for(const t of r){const r=s();b(r,t.getChildren()),e.insertAfter(r),e=r,t.__key===n.anchor.key&&n.anchor.set(r.getKey(),0,"element"),t.__key===n.focus.key&&n.focus.set(r.getKey(),0,"element"),t.remove()}t.remove()}}}))}function N(e){const t=new Set;if(C(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(C(r)&&C(i)){const n=i.getFirstChild();if(U(n)){n.append(e);const i=r.getFirstChild();if(U(i)){b(n,i.getChildren()),r.remove(),t.add(r.getKey())}}}else if(C(r)){const t=r.getFirstChild();if(U(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(C(i)){const t=i.getFirstChild();U(t)&&t.append(e)}else if(U(n)){const t=I(),s=z(n.getListType());t.append(s),s.append(e),i?i.insertAfter(t):r?r.insertBefore(t):n.append(t)}}function O(e){if(C(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(U(n?n.getParent():void 0)&&R(n)&&U(t)){const r=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(i))n.insertAfter(e),t.isEmpty()&&n.remove();else{const r=t.getListType(),i=I(),s=z(r);i.append(s),e.getPreviousSiblings().forEach((e=>s.append(e)));const o=I(),c=z(r);o.append(c),b(c,e.getNextSiblings()),n.insertBefore(i),n.insertAfter(o),n.replace(e)}}}function L(){const r=e();if(!t(r)||!r.isCollapsed())return!1;const i=r.anchor.getNode();if(!R(i)||0!==i.getChildrenSize())return!1;const c=v(i),l=i.getParent();U(l)||_(40);const h=l.getParent();let a;if(n(h))a=s(),c.insertAfter(a);else{if(!R(h))return!1;a=I(),h.insertAfter(a)}a.select();const u=i.getNextSiblings();if(u.length>0){const e=z(l.getListType());if(o(a))a.insertAfter(e);else{const t=I();t.append(e),a.insertAfter(t)}u.forEach((t=>{t.remove(),e.append(t)}))}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!R(t)&&!U(t))break;t=e}t.remove()}(i),!0}function E(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}class F extends c{static getType(){return"listitem"}static clone(e){return new F(e.__value,e.__checked,e.__key)}constructor(e,t,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}createDOM(e){const t=document.createElement("li"),n=this.getParent();return U(n)&&"check"===n.getListType()&&w(t,this,null),t.value=this.__value,M(t,e.theme,this),t}updateDOM(e,t,n){const r=this.getParent();return U(r)&&"check"===r.getListType()&&w(t,this,e),t.value=this.__value,M(t,n.theme,this),!1}static transform(){return e=>{if(R(e)||_(144),null==e.__checked)return;const t=e.getParent();U(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)}}static importDOM(){return{li:e=>({conversion:D,priority:0})}}static importJSON(e){const t=I();return t.setChecked(e.checked),t.setValue(e.value),t.setFormat(e.format),t.setDirection(e.direction),t}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(r(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,t){if(R(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!U(n))return e;if(n.__first===this.getKey())n.insertBefore(e);else if(n.__last===this.getKey())n.insertAfter(e);else{const t=z(n.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}n.insertAfter(e),e.insertAfter(t)}return t&&(r(e)||_(139),this.getChildren().forEach((t=>{e.append(t)}))),this.remove(),0===n.getChildrenSize()&&n.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if(U(n)||_(39),R(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const i=z(n.getListType());r.forEach((e=>i.append(e))),e.insertAfter(i,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&C(t)&&C(n)&&(x(t.getFirstChild(),n.getFirstChild()),n.remove())}insertNewAfter(e,t=!0){const n=I(null==this.__checked&&void 0);return this.insertAfter(n,t),n}collapseAtStart(e){const t=s();this.getChildren().forEach((e=>t.append(e)));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=R(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(t),n.remove();const r=e.anchor,i=e.focus,s=t.getKey();"element"===r.type&&r.getNode().is(this)&&r.set(s,r.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else n.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){this.getWritable().__value=e}getChecked(){return this.getLatest().__checked}setChecked(e){this.getWritable().__checked=e}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){const e=this.getParent();if(null===e)return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;R(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"==typeof e&&e>-1||_(117);let t=this.getIndent();for(;t!==e;)t<e?(N(this),t++):(O(this),t--);return this}canInsertAfter(e){return R(e)}canReplaceWith(e){return R(e)}canMergeWith(e){return o(e)||R(e)}extractWithChild(e,n){if(!t(n))return!1;const r=n.anchor.getNode(),i=n.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&this.getTextContent().length===n.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return z("bullet")}}function M(e,t,n){const r=[],i=[],s=t.list,o=s?s.listitem:void 0;let c;if(s&&s.nested&&(c=s.nested.listitem),void 0!==o&&r.push(...E(o)),s){const e=n.getParent(),t=U(e)&&"check"===e.getListType(),o=n.getChecked();t&&!o||i.push(s.listitemUnchecked),t&&o||i.push(s.listitemChecked),t&&r.push(o?s.listitemChecked:s.listitemUnchecked)}if(void 0!==c){const e=E(c);n.getChildren().some((e=>U(e)))?r.push(...e):i.push(...e)}i.length>0&&g(e,...i),r.length>0&&d(e,...r)}function w(e,t,n,r){U(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}function D(e){return{node:I(f(e)&&"true"===e.getAttribute("aria-checked"))}}function I(e){return l(new F(void 0,e))}function R(e){return e instanceof F}class K extends c{static getType(){return"list"}static clone(e){const t=e.__listType||J[e.__tag];return new K(t,e.__start,e.__key)}constructor(e,t,n){super(n);const r=J[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}getTag(){return this.__tag}setListType(e){const t=this.getWritable();t.__listType=e,t.__tag="number"===e?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,B(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||(B(t,n.theme,this),!1)}static transform(){return e=>{U(e)||_(163),function(e){const t=e.getNextSibling();U(t)&&e.getListType()===t.getListType()&&x(e,t)}(e),function(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())R(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getChecked()&&r.setChecked(void 0),U(r.getFirstChild())||n++)}(e)}}static importDOM(){return{ol:e=>({conversion:V,priority:0}),ul:e=>({conversion:V,priority:0})}}static importJSON(e){const t=z(e.listType,e.start);return t.setFormat(e.format),t.setIndent(e.indent),t.setDirection(e.direction),t}exportDOM(e){const{element:t}=super.exportDOM(e);return t&&f(t)&&(1!==this.__start&&t.setAttribute("start",String(this.__start)),"check"===this.__listType&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(R(n))super.append(n);else{const e=I();if(U(n))e.append(n);else if(r(n)){const t=h(n.getTextContent());e.append(t)}else e.append(n);super.append(e)}}return this}extractWithChild(e){return R(e)}}function B(e,t,n){const r=[],i=[],s=t.list;if(void 0!==s){const e=s[`${n.__tag}Depth`]||[],t=m(n)-1,o=t%e.length,c=e[o],l=s[n.__tag];let h;const a=s.nested,u=s.checklist;if(void 0!==a&&a.list&&(h=a.list),void 0!==l&&r.push(l),void 0!==u&&"check"===n.__listType&&r.push(u),void 0!==c){r.push(...E(c));for(let t=0;t<e.length;t++)t!==o&&i.push(n.__tag+t)}if(void 0!==h){const e=E(h);t>1?r.push(...e):i.push(...e)}}i.length>0&&g(e,...i),r.length>0&&d(e,...r)}function W(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(R(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach((e=>{U(e)&&t.push(T(e))}))}else t.push(T(r))}return t}function V(e){const t=e.nodeName.toLowerCase();let n=null;if("ol"===t){n=z("number",e.start)}else"ul"===t&&(n=f(e)&&"check"===e.getAttribute("__lexicallisttype")?z("check"):z("bullet"));return{after:W,node:n}}const J={ol:"number",ul:"bullet"};function z(e,t=1){return l(new K(e,t))}function U(e){return e instanceof K}const $=a("INSERT_UNORDERED_LIST_COMMAND"),j=a("INSERT_ORDERED_LIST_COMMAND"),q=a("INSERT_CHECK_LIST_COMMAND"),H=a("REMOVE_LIST_COMMAND");export{I as $createListItemNode,z as $createListNode,m as $getListDepth,L as $handleListInsertParagraph,R as $isListItemNode,U as $isListNode,q as INSERT_CHECK_LIST_COMMAND,j as INSERT_ORDERED_LIST_COMMAND,$ as INSERT_UNORDERED_LIST_COMMAND,F as ListItemNode,K as ListNode,H as REMOVE_LIST_COMMAND,S as insertList,A as removeList};
|
|
9
|
+
import{$getSelection as e,$isRangeSelection as t,$isRootOrShadowRoot as n,$isElementNode as r,$isLeafNode as i,$createParagraphNode as s,$isParagraphNode as o,ElementNode as c,$applyNodeReplacement as l,$createTextNode as a,createCommand as h}from"lexical";import{$getNearestNodeOfType as u,removeClassNamesFromElement as g,addClassNamesToElement as f,isHTMLElement as d}from"@lexical/utils";function p(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _=p((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function m(e){let t=1,n=e.getParent();for(;null!=n;){if(K(n)){const e=n.getParent();if($(e)){t++,n=e.getParent();continue}_(40)}return t}return t}function v(e){let t=e.getParent();$(t)||_(40);let n=t;for(;null!==n;)n=n.getParent(),$(n)&&(t=n);return t}function y(e){let t=[];const n=e.getChildren().filter(K);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();$(i)?t=t.concat(y(i)):t.push(r)}return t}function C(e){return K(e)&&$(e.getFirstChild())}function k(e){return R().append(e)}function T(e,t){return K(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function b(s,o){s.update((()=>{const s=e();if(null!==s){const e=s.getNodes();if(t(s)){const t=s.getStartEndPoints();null===t&&_(143);const[i]=t,c=i.getNode(),l=c.getParent();if(T(c,e)){const e=U(o);if(n(l)){c.replace(e);const t=R();r(c)&&(t.setFormat(c.getFormatType()),t.setIndent(c.getIndent())),e.append(t)}else if(K(c)){const t=c.getParentOrThrow();S(e,t.getChildren()),t.replace(e)}return}}const c=new Set;for(let t=0;t<e.length;t++){const s=e[t];if(!r(s)||!s.isEmpty()||K(s)||c.has(s.getKey())){if(i(s)){let e=s.getParent();for(;null!=e;){const t=e.getKey();if($(e)){if(!c.has(t)){const n=U(o);S(n,e.getChildren()),e.replace(n),c.add(t)}break}{const r=e.getParent();if(n(r)&&!c.has(t)){c.add(t),P(e,o);break}e=r}}}}else P(s,o)}}}))}function S(e,t){e.splice(e.getChildrenSize(),0,t)}function P(e,t){if($(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=R();if(i.setFormat(e.getFormatType()),i.setIndent(e.getIndent()),S(i,e.getChildren()),$(n)&&t===n.getListType())return n.append(i),e.remove(),$(r)&&t===r.getListType()&&(S(n,r.getChildren()),r.remove()),n;if($(r)&&t===r.getListType())return r.getFirstChildOrThrow().insertBefore(i),e.remove(),r;{const n=U(t);return n.append(i),e.replace(n),n}}function A(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&C(n)&&C(r)&&(A(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function N(n){n.update((()=>{const n=e();if(t(n)){const e=new Set,t=n.getNodes(),r=n.anchor.getNode();if(T(r,t))e.add(v(r));else for(let n=0;n<t.length;n++){const r=t[n];if(i(r)){const t=u(r,F);null!=t&&e.add(v(t))}}for(const t of e){let e=t;const r=y(t);for(const t of r){const r=s();S(r,t.getChildren()),e.insertAfter(r),e=r,t.__key===n.anchor.key&&n.anchor.set(r.getKey(),0,"element"),t.__key===n.focus.key&&n.focus.set(r.getKey(),0,"element"),t.remove()}t.remove()}}}))}function x(e){const t=new Set;if(C(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(C(r)&&C(i)){const n=i.getFirstChild();if($(n)){n.append(e);const i=r.getFirstChild();if($(i)){S(n,i.getChildren()),r.remove(),t.add(r.getKey())}}}else if(C(r)){const t=r.getFirstChild();if($(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(C(i)){const t=i.getFirstChild();$(t)&&t.append(e)}else if($(n)){const t=R(),s=U(n.getListType());t.append(s),s.append(e),i?i.insertAfter(t):r?r.insertBefore(t):n.append(t)}}function O(e){if(C(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if($(n?n.getParent():void 0)&&K(n)&&$(t)){const r=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(i))n.insertAfter(e),t.isEmpty()&&n.remove();else{const r=t.getListType(),i=R(),s=U(r);i.append(s),e.getPreviousSiblings().forEach((e=>s.append(e)));const o=R(),c=U(r);o.append(c),S(c,e.getNextSiblings()),n.insertBefore(i),n.insertAfter(o),n.replace(e)}}}function L(){const r=e();if(!t(r)||!r.isCollapsed())return!1;const i=r.anchor.getNode();if(!K(i)||0!==i.getChildrenSize())return!1;const c=v(i),l=i.getParent();$(l)||_(40);const a=l.getParent();let h;if(n(a))h=s(),c.insertAfter(h);else{if(!K(a))return!1;h=R(),a.insertAfter(h)}h.select();const u=i.getNextSiblings();if(u.length>0){const e=U(l.getListType());if(o(h))h.insertAfter(e);else{const t=R();t.append(e),h.insertAfter(t)}u.forEach((t=>{t.remove(),e.append(t)}))}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!K(t)&&!$(t))break;t=e}t.remove()}(i),!0}function E(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}class F extends c{static getType(){return"listitem"}static clone(e){return new F(e.__value,e.__checked,e.__key)}constructor(e,t,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}createDOM(e){const t=document.createElement("li"),n=this.getParent();return $(n)&&"check"===n.getListType()&&w(t,this,null),t.value=this.__value,M(t,e.theme,this),t}updateDOM(e,t,n){const r=this.getParent();return $(r)&&"check"===r.getListType()&&w(t,this,e),t.value=this.__value,M(t,n.theme,this),!1}static transform(){return e=>{if(K(e)||_(144),null==e.__checked)return;const t=e.getParent();$(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)}}static importDOM(){return{li:()=>({conversion:D,priority:0})}}static importJSON(e){const t=R();return t.setChecked(e.checked),t.setValue(e.value),t.setFormat(e.format),t.setDirection(e.direction),t}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(r(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,t){if(K(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!$(n))return e;if(n.__first===this.getKey())n.insertBefore(e);else if(n.__last===this.getKey())n.insertAfter(e);else{const t=U(n.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}n.insertAfter(e),e.insertAfter(t)}return t&&(r(e)||_(139),this.getChildren().forEach((t=>{e.append(t)}))),this.remove(),0===n.getChildrenSize()&&n.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if($(n)||_(39),K(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const i=U(n.getListType());r.forEach((e=>i.append(e))),e.insertAfter(i,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&C(t)&&C(n)&&(A(t.getFirstChild(),n.getFirstChild()),n.remove())}insertNewAfter(e,t=!0){const n=R(null==this.__checked&&void 0);return this.insertAfter(n,t),n}collapseAtStart(e){const t=s();this.getChildren().forEach((e=>t.append(e)));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=K(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(t),n.remove();const r=e.anchor,i=e.focus,s=t.getKey();"element"===r.type&&r.getNode().is(this)&&r.set(s,r.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else n.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){this.getWritable().__value=e}getChecked(){return this.getLatest().__checked}setChecked(e){this.getWritable().__checked=e}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){const e=this.getParent();if(null===e)return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;K(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"==typeof e&&e>-1||_(117);let t=this.getIndent();for(;t!==e;)t<e?(x(this),t++):(O(this),t--);return this}canInsertAfter(e){return K(e)}canReplaceWith(e){return K(e)}canMergeWith(e){return o(e)||K(e)}extractWithChild(e,n){if(!t(n))return!1;const r=n.anchor.getNode(),i=n.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&this.getTextContent().length===n.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return U("bullet")}}function M(e,t,n){const r=[],i=[],s=t.list,o=s?s.listitem:void 0;let c;if(s&&s.nested&&(c=s.nested.listitem),void 0!==o&&r.push(...E(o)),s){const e=n.getParent(),t=$(e)&&"check"===e.getListType(),o=n.getChecked();t&&!o||i.push(s.listitemUnchecked),t&&o||i.push(s.listitemChecked),t&&r.push(o?s.listitemChecked:s.listitemUnchecked)}if(void 0!==c){const e=E(c);n.getChildren().some((e=>$(e)))?r.push(...e):i.push(...e)}i.length>0&&g(e,...i),r.length>0&&f(e,...r)}function w(e,t,n,r){$(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}function D(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return I(t);const t=e.getAttribute("aria-checked");return{node:R("true"===t||"false"!==t&&void 0)}}function I(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:R(e.hasAttribute("checked"))}}function R(e){return l(new F(void 0,e))}function K(e){return e instanceof F}class B extends c{static getType(){return"list"}static clone(e){const t=e.__listType||z[e.__tag];return new B(t,e.__start,e.__key)}constructor(e,t,n){super(n);const r=z[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}getTag(){return this.__tag}setListType(e){const t=this.getWritable();t.__listType=e,t.__tag="number"===e?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,W(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||(W(t,n.theme,this),!1)}static transform(){return e=>{$(e)||_(163),function(e){const t=e.getNextSibling();$(t)&&e.getListType()===t.getListType()&&A(e,t)}(e),function(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())K(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getChecked()&&r.setChecked(void 0),$(r.getFirstChild())||n++)}(e)}}static importDOM(){return{ol:()=>({conversion:J,priority:0}),ul:()=>({conversion:J,priority:0})}}static importJSON(e){const t=U(e.listType,e.start);return t.setFormat(e.format),t.setIndent(e.indent),t.setDirection(e.direction),t}exportDOM(e){const{element:t}=super.exportDOM(e);return t&&d(t)&&(1!==this.__start&&t.setAttribute("start",String(this.__start)),"check"===this.__listType&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(K(n))super.append(n);else{const e=R();if($(n))e.append(n);else if(r(n)){const t=a(n.getTextContent());e.append(t)}else e.append(n);super.append(e)}}return this}extractWithChild(e){return K(e)}}function W(e,t,n){const r=[],i=[],s=t.list;if(void 0!==s){const e=s[`${n.__tag}Depth`]||[],t=m(n)-1,o=t%e.length,c=e[o],l=s[n.__tag];let a;const h=s.nested,u=s.checklist;if(void 0!==h&&h.list&&(a=h.list),void 0!==l&&r.push(l),void 0!==u&&"check"===n.__listType&&r.push(u),void 0!==c){r.push(...E(c));for(let t=0;t<e.length;t++)t!==o&&i.push(n.__tag+t)}if(void 0!==a){const e=E(a);t>1?r.push(...e):i.push(...e)}}i.length>0&&g(e,...i),r.length>0&&f(e,...r)}function V(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(K(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach((e=>{$(e)&&t.push(k(e))}))}else t.push(k(r))}return t}function J(e){const t=e.nodeName.toLowerCase();let n=null;if("ol"===t){n=U("number",e.start)}else"ul"===t&&(n=function(e){if("check"===e.getAttribute("__lexicallisttype")||e.classList.contains("contains-task-list"))return!0;for(const t of e.childNodes)if(d(t)&&t.hasAttribute("aria-checked"))return!0;return!1}(e)?U("check"):U("bullet"));return{after:V,node:n}}const z={ol:"number",ul:"bullet"};function U(e,t=1){return l(new B(e,t))}function $(e){return e instanceof B}const j=h("INSERT_UNORDERED_LIST_COMMAND"),q=h("INSERT_ORDERED_LIST_COMMAND"),H=h("INSERT_CHECK_LIST_COMMAND"),G=h("REMOVE_LIST_COMMAND");export{R as $createListItemNode,U as $createListNode,m as $getListDepth,L as $handleListInsertParagraph,K as $isListItemNode,$ as $isListNode,H as INSERT_CHECK_LIST_COMMAND,q as INSERT_ORDERED_LIST_COMMAND,j as INSERT_UNORDERED_LIST_COMMAND,F as ListItemNode,B as ListNode,G as REMOVE_LIST_COMMAND,b as insertList,N as removeList};
|
package/LexicalListItemNode.d.ts
CHANGED
|
@@ -40,7 +40,9 @@ export declare class ListItemNode extends ElementNode {
|
|
|
40
40
|
toggleChecked(): void;
|
|
41
41
|
getIndent(): number;
|
|
42
42
|
setIndent(indent: number): this;
|
|
43
|
+
/** @deprecated @internal */
|
|
43
44
|
canInsertAfter(node: LexicalNode): boolean;
|
|
45
|
+
/** @deprecated @internal */
|
|
44
46
|
canReplaceWith(replacement: LexicalNode): boolean;
|
|
45
47
|
canMergeWith(node: LexicalNode): boolean;
|
|
46
48
|
extractWithChild(child: LexicalNode, selection: BaseSelection): boolean;
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.16.0",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/utils": "0.
|
|
16
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/utils": "0.16.0",
|
|
16
|
+
"lexical": "0.16.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|