@lexical/list 0.3.3 → 0.3.6
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 +39 -6
- package/LexicalList.prod.js +25 -24
- package/LexicalListItemNode.d.ts +48 -0
- package/LexicalListNode.d.ts +40 -0
- package/formatList.d.ts +18 -0
- package/index.d.ts +18 -0
- package/package.json +3 -3
- package/utils.d.ts +18 -0
- package/LexicalList.d.ts +0 -83
package/LexicalList.dev.js
CHANGED
|
@@ -15,7 +15,6 @@ var utils = require('@lexical/utils');
|
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
18
|
*/
|
|
20
19
|
function $getListDepth(listNode) {
|
|
21
20
|
let depth = 1;
|
|
@@ -131,6 +130,10 @@ function $removeHighestEmptyListParent(sublist) {
|
|
|
131
130
|
|
|
132
131
|
emptyListPtr.remove();
|
|
133
132
|
}
|
|
133
|
+
function wrapInListItem(node) {
|
|
134
|
+
const listItemWrapper = $createListItemNode();
|
|
135
|
+
return listItemWrapper.append(node);
|
|
136
|
+
}
|
|
134
137
|
|
|
135
138
|
/**
|
|
136
139
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -338,7 +341,8 @@ function $handleIndent(listItemNodes) {
|
|
|
338
341
|
return;
|
|
339
342
|
}
|
|
340
343
|
|
|
341
|
-
const parent = listItemNode.getParent();
|
|
344
|
+
const parent = listItemNode.getParent(); // We can cast both of the below `isNestedListNode` only returns a boolean type instead of a user-defined type guards
|
|
345
|
+
|
|
342
346
|
const nextSibling = listItemNode.getNextSibling();
|
|
343
347
|
const previousSibling = listItemNode.getPreviousSibling(); // if there are nested lists on either side, merge them all together.
|
|
344
348
|
|
|
@@ -627,7 +631,8 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
627
631
|
return { ...super.exportJSON(),
|
|
628
632
|
checked: this.getChecked(),
|
|
629
633
|
type: 'listitem',
|
|
630
|
-
value: this.getValue()
|
|
634
|
+
value: this.getValue(),
|
|
635
|
+
version: 1
|
|
631
636
|
};
|
|
632
637
|
}
|
|
633
638
|
|
|
@@ -991,7 +996,6 @@ function $isListItemNode(node) {
|
|
|
991
996
|
* This source code is licensed under the MIT license found in the
|
|
992
997
|
* LICENSE file in the root directory of this source tree.
|
|
993
998
|
*
|
|
994
|
-
*
|
|
995
999
|
*/
|
|
996
1000
|
class ListNode extends lexical.ElementNode {
|
|
997
1001
|
static getType() {
|
|
@@ -1075,7 +1079,8 @@ class ListNode extends lexical.ElementNode {
|
|
|
1075
1079
|
listType: this.getListType(),
|
|
1076
1080
|
start: this.getStart(),
|
|
1077
1081
|
tag: this.getTag(),
|
|
1078
|
-
type: 'list'
|
|
1082
|
+
type: 'list',
|
|
1083
|
+
version: 1
|
|
1079
1084
|
};
|
|
1080
1085
|
}
|
|
1081
1086
|
|
|
@@ -1122,7 +1127,7 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
1122
1127
|
const listTheme = editorThemeClasses.list;
|
|
1123
1128
|
|
|
1124
1129
|
if (listTheme !== undefined) {
|
|
1125
|
-
const listLevelsClassNames = listTheme[node.__tag
|
|
1130
|
+
const listLevelsClassNames = listTheme[`${node.__tag}Depth`] || [];
|
|
1126
1131
|
const listDepth = $getListDepth(node) - 1;
|
|
1127
1132
|
const normalizedListDepth = listDepth % listLevelsClassNames.length;
|
|
1128
1133
|
const listLevelClassName = listLevelsClassNames[normalizedListDepth];
|
|
@@ -1168,6 +1173,33 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
1168
1173
|
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
1169
1174
|
}
|
|
1170
1175
|
}
|
|
1176
|
+
/*
|
|
1177
|
+
* This function normalizes the children of a ListNode after the conversion from HTML,
|
|
1178
|
+
* ensuring that they are all ListItemNodes and contain either a single nested ListNode
|
|
1179
|
+
* or some other inline content.
|
|
1180
|
+
*/
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
function normalizeChildren(nodes) {
|
|
1184
|
+
const normalizedListItems = [];
|
|
1185
|
+
|
|
1186
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1187
|
+
const node = nodes[i];
|
|
1188
|
+
|
|
1189
|
+
if ($isListItemNode(node)) {
|
|
1190
|
+
normalizedListItems.push(node);
|
|
1191
|
+
node.getChildren().forEach(child => {
|
|
1192
|
+
if ($isListNode(child)) {
|
|
1193
|
+
normalizedListItems.push(wrapInListItem(child));
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
} else {
|
|
1197
|
+
normalizedListItems.push(wrapInListItem(node));
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
return normalizedListItems;
|
|
1202
|
+
}
|
|
1171
1203
|
|
|
1172
1204
|
function convertListNode(domNode) {
|
|
1173
1205
|
const nodeName = domNode.nodeName.toLowerCase();
|
|
@@ -1180,6 +1212,7 @@ function convertListNode(domNode) {
|
|
|
1180
1212
|
}
|
|
1181
1213
|
|
|
1182
1214
|
return {
|
|
1215
|
+
after: normalizeChildren,
|
|
1183
1216
|
node
|
|
1184
1217
|
};
|
|
1185
1218
|
}
|
package/LexicalList.prod.js
CHANGED
|
@@ -5,29 +5,30 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var h=require("lexical"),l=require("@lexical/utils");function m(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function n(a){let b=1;for(a=a.getParent();null!=a;){if(p(a)){a=a.getParent();if(q(a)){b++;a=a.getParent();continue}m(40)}break}return b}function t(a){a=a.getParent();q(a)||m(40);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}
|
|
8
|
-
function u(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(u(e)):b.push(d)}return b}function v(a){return p(a)&&q(a.getFirstChild())}function w(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){let b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function x(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
f.insertAfter(g):e?e.insertBefore(g):d.append(g)}q(d)&&
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
class
|
|
16
|
-
priority:0})}}static importJSON(a){let b=new
|
|
17
|
-
if(q(b)){var c=b.__children;let e=c.length;var d=c.indexOf(this.__key);if(0===d)b.insertBefore(a);else if(d===e-1)b.insertAfter(a);else{c=
|
|
18
|
-
for(c=a.length-1;0<=c;c--)b=a[c],this.insertAfter(b);return b}b.insertAfter(a);if(0!==c.length){let d=
|
|
8
|
+
function u(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(u(e)):b.push(d)}return b}function v(a){return p(a)&&q(a.getFirstChild())}function w(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){let b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function x(a){return z().append(a)}function A(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}
|
|
9
|
+
function C(a,b){a.splice(a.getChildrenSize(),0,b)}function D(a,b){if(q(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=z();C(e,a.getChildren());if(q(c)&&b===c.getListType())return c.append(e),a.remove(),q(d)&&b===d.getListType()&&(C(c,d.getChildren()),d.remove()),c;if(q(d)&&b===d.getListType())return d.getFirstChildOrThrow().insertBefore(e),a.remove(),d;b=E(b);b.append(e);a.replace(b);F(b);return b}
|
|
10
|
+
function F(a,b){(b||a.getChildren()).forEach(c=>{let d=c.getValue();var e=c.getParent();var f=1;null!=e&&(q(e)?f=e.getStart():m(44));e=c.getPreviousSiblings();for(let g=0;g<e.length;g++){let k=e[g];p(k)&&!q(k.getFirstChild())&&f++}d!==f&&c.setValue(f)})}
|
|
11
|
+
function G(a){let b=new Set;a.forEach(c=>{if(!v(c)&&!b.has(c.getKey())){var d=c.getParent(),e=c.getNextSibling(),f=c.getPreviousSibling();if(v(e)&&v(f))f=f.getFirstChild(),q(f)&&(f.append(c),c=e.getFirstChild(),q(c)&&(c=c.getChildren(),C(f,c),e.remove(),b.add(e.getKey())),F(f));else if(v(e))e=e.getFirstChild(),q(e)&&(f=e.getFirstChild(),null!==f&&f.insertBefore(c),F(e));else if(v(f))e=f.getFirstChild(),q(e)&&(e.append(c),F(e));else if(q(d)){let g=z(),k=E(d.getListType());g.append(k);k.append(c);f?
|
|
12
|
+
f.insertAfter(g):e?e.insertBefore(g):d.append(g)}q(d)&&F(d)}})}
|
|
13
|
+
function H(a){a.forEach(b=>{if(!v(b)){var c=b.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(q(e)&&p(d)&&q(c)){var f=c?c.getFirstChild():void 0,g=c?c.getLastChild():void 0;if(b.is(f))d.insertBefore(b),c.isEmpty()&&d.remove();else if(b.is(g))d.insertAfter(b),c.isEmpty()&&d.remove();else{var k=c.getListType();f=z();let r=E(k);f.append(r);b.getPreviousSiblings().forEach(y=>r.append(y));g=z();k=E(k);g.append(k);C(k,b.getNextSiblings());d.insertBefore(f);d.insertAfter(g);d.replace(b)}F(c);
|
|
14
|
+
F(e)}}})}function I(a){var b=h.$getSelection();if(h.$isRangeSelection(b)){var c=b.getNodes(),d=[];0===c.length&&c.push(b.anchor.getNode());if(1===c.length){a:{for(c=c[0];null!==c;){if(p(c))break a;c=c.getParent()}c=null}null!==c&&(d=[c])}else{d=new Set;for(b=0;b<c.length;b++){let e=c[b];p(e)&&d.add(e)}d=Array.from(d)}0<d.length&&("indent"===a?G(d):H(d))}}
|
|
15
|
+
class J extends h.ElementNode{static getType(){return"listitem"}static clone(a){return new J(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)&&(F(c),K(b,this,null,c));b.value=this.__value;L(b,a.theme,this);return b}updateDOM(a,b,c){let d=this.getParent();q(d)&&(F(d),K(b,this,a,d));b.value=this.__value;L(b,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:M,
|
|
16
|
+
priority:0})}}static importJSON(a){let b=new J(a.value,a.checked);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...a){for(let b=0;b<a.length;b++){let c=a[b];if(h.$isElementNode(c)&&this.canMergeWith(c)){let d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a){if(p(a))return super.replace(a);let b=this.getParentOrThrow();
|
|
17
|
+
if(q(b)){var c=b.__children;let e=c.length;var d=c.indexOf(this.__key);if(0===d)b.insertBefore(a);else if(d===e-1)b.insertAfter(a);else{c=E(b.getListType());let f=b.getChildren();for(d+=1;d<e;d++)c.append(f[d]);b.insertAfter(a);a.insertAfter(c)}this.remove();1===e&&b.remove()}return a}insertAfter(a){var b=this.getParentOrThrow();q(b)||m(39);var c=this.getNextSiblings();if(p(a))return b=super.insertAfter(a),a=a.getParentOrThrow(),q(a)&&F(a),b;if(q(a)&&a.getListType()===b.getListType()){b=a;a=a.getChildren();
|
|
18
|
+
for(c=a.length-1;0<=c;c--)b=a[c],this.insertAfter(b);return b}b.insertAfter(a);if(0!==c.length){let d=E(b.getListType());c.forEach(e=>d.append(e));a.insertAfter(d)}return a}remove(a){let b=this.getNextSibling();super.remove(a);null!==b&&(a=b.getParent(),q(a)&&F(a))}insertNewAfter(){let a=z(null==this.__checked?void 0:!1);this.insertAfter(a);return a}collapseAtStart(a){let b=h.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();let e=
|
|
19
19
|
p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.replace(b),c=a.anchor,a=a.focus,d=b.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===a.type&&a.getNode().is(this)&&a.set(d,a.offset,"element")):(c.insertBefore(b),this.remove());return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=a}getChecked(){return this.getLatest().__checked}setChecked(a){this.getWritable().__checked=a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){var a=
|
|
20
|
-
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){let b=this.getIndent();for(;b!==a;)b<a?(
|
|
20
|
+
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){let b=this.getIndent();for(;b!==a;)b<a?(G([this]),b++):(H([this]),b--);return this}canIndent(){return!1}insertBefore(a){if(p(a)){let b=this.getParentOrThrow();if(q(b)){let c=this.getNextSiblings();F(b,c)}}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||
|
|
21
21
|
p(a)}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}}
|
|
22
|
-
function
|
|
23
|
-
...d)}function
|
|
24
|
-
class
|
|
25
|
-
return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;
|
|
26
|
-
0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{let d=
|
|
27
|
-
function
|
|
28
|
-
function
|
|
29
|
-
exports.$
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
function L(a,b,c){let d=[],e=[];var f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var g=b.nested.listitem;void 0!==f&&(f=f.split(" "),d.push(...f));if(b){f=c.getParent();f=q(f)&&"check"===f.getListType();let k=c.getChecked();f&&!k||e.push(b.listitemUnchecked);f&&k||e.push(b.listitemChecked);f&&d.push(k?b.listitemChecked:b.listitemUnchecked)}void 0!==g&&(g=g.split(" "),c.getChildren().some(k=>q(k))?d.push(...g):e.push(...g));0<e.length&&l.removeClassNamesFromElement(a,...e);0<d.length&&l.addClassNamesToElement(a,
|
|
23
|
+
...d)}function K(a,b,c,d){"check"===d.getListType()?q(b.getFirstChild())?(a.removeAttribute("role"),a.removeAttribute("tabIndex"),a.removeAttribute("aria-checked")):(a.setAttribute("role","checkbox"),a.setAttribute("tabIndex","-1"),c&&b.__checked===c.__checked||a.setAttribute("aria-checked",b.getChecked()?"true":"false")):null!=b.getChecked()&&b.setChecked(void 0)}function M(){return{node:z()}}function z(a){return new J(void 0,a)}function p(a){return a instanceof J}
|
|
24
|
+
class N extends h.ElementNode{static getType(){return"list"}static clone(a){return new N(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}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);
|
|
25
|
+
return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;P(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:Q,priority:0}),ul:()=>({conversion:Q,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}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=
|
|
26
|
+
0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{let d=z();q(b)?d.append(b):(b=h.$createTextNode(b.getTextContent()),d.append(b));super.append(d)}}return this}extractWithChild(a){return p(a)}}
|
|
27
|
+
function P(a,b,c){let d=[],e=[];var f=b.list;if(void 0!==f){let k=f[`${c.__tag}Depth`]||[];b=n(c)-1;let r=b%k.length;var g=k[r];let y=f[c.__tag],B;f=f.nested;void 0!==f&&f.list&&(B=f.list);void 0!==y&&d.push(y);if(void 0!==g)for(g=g.split(" "),d.push(...g),g=0;g<k.length;g++)g!==r&&e.push(c.__tag+g);void 0!==B&&(c=B.split(" "),1<b?d.push(...c):e.push(...c))}0<e.length&&l.removeClassNamesFromElement(a,...e);0<d.length&&l.addClassNamesToElement(a,...d)}
|
|
28
|
+
function R(a){let b=[];for(let c=0;c<a.length;c++){let d=a[c];p(d)?(b.push(d),d.getChildren().forEach(e=>{q(e)&&b.push(x(e))})):b.push(x(d))}return b}function Q(a){a=a.nodeName.toLowerCase();let b=null;"ol"===a?b=E("number"):"ul"===a&&(b=E("bullet"));return{after:R,node:b}}let O={ol:"number",ul:"bullet"};function E(a,b=1){return new N(a,b)}function q(a){return a instanceof N}let S=h.createCommand(),T=h.createCommand(),U=h.createCommand(),V=h.createCommand();exports.$createListItemNode=z;
|
|
29
|
+
exports.$createListNode=E;exports.$getListDepth=n;
|
|
30
|
+
exports.$handleListInsertParagraph=function(){var a=h.$getSelection();if(!h.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!p(a)||""!==a.getTextContent())return!1;var b=t(a),c=a.getParent();q(c)||m(40);let d=c.getParent(),e;if(h.$isRootNode(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=z(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){let f=E(c.getListType());h.$isParagraphNode(e)?e.insertAfter(f):(c=z(),c.append(f),e.insertAfter(c));
|
|
31
|
+
b.forEach(g=>{g.remove();f.append(g)})}w(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=J;exports.ListNode=N;exports.REMOVE_LIST_COMMAND=V;exports.indentList=function(){I("indent")};
|
|
32
|
+
exports.insertList=function(a,b){a.update(()=>{var c=h.$getSelection();if(h.$isRangeSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(A(c,d))d=E(b),h.$isRootNode(e)?(c.replace(d),c=z(),d.append(c)):p(c)&&(c=c.getParentOrThrow(),C(d,c.getChildren()),c.replace(d));else for(c=new Set,e=0;e<d.length;e++){var f=d[e];if(h.$isElementNode(f)&&f.isEmpty()&&!c.has(f.getKey()))D(f,b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){let k=f.getKey();if(q(f)){if(!c.has(k)){var g=
|
|
33
|
+
E(b);C(g,f.getChildren());f.replace(g);F(g);c.add(k)}break}else{g=f.getParent();if(h.$isRootNode(g)&&!c.has(k)){c.add(k);D(f,b);break}f=g}}}}})};exports.outdentList=function(){I("outdent")};
|
|
34
|
+
exports.removeList=function(a){a.update(()=>{var b=h.$getSelection();if(h.$isRangeSelection(b)){let d=new Set,e=b.getNodes();b=b.anchor.getNode();if(A(b,e))d.add(t(b));else for(b=0;b<e.length;b++){var c=e[b];h.$isLeafNode(c)&&(c=l.$getNearestNodeOfType(c,J),null!=c&&d.add(t(c)))}d.forEach(f=>{let g=f;u(f).forEach(k=>{if(null!=k){let r=h.$createParagraphNode();C(r,k.getChildren());g.insertAfter(r);g=r;k.remove()}});f.remove()})}})}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { DOMConversionMap, EditorConfig, GridSelection, LexicalNode, NodeKey, NodeSelection, ParagraphNode, RangeSelection, SerializedElementNode, Spread } from 'lexical';
|
|
9
|
+
import { ElementNode } from 'lexical';
|
|
10
|
+
export declare type SerializedListItemNode = Spread<{
|
|
11
|
+
checked: boolean | undefined;
|
|
12
|
+
type: 'listitem';
|
|
13
|
+
value: number;
|
|
14
|
+
version: 1;
|
|
15
|
+
}, SerializedElementNode>;
|
|
16
|
+
export declare class ListItemNode extends ElementNode {
|
|
17
|
+
__value: number;
|
|
18
|
+
__checked?: boolean;
|
|
19
|
+
static getType(): string;
|
|
20
|
+
static clone(node: ListItemNode): ListItemNode;
|
|
21
|
+
constructor(value?: number, checked?: boolean, key?: NodeKey);
|
|
22
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
23
|
+
updateDOM(prevNode: ListItemNode, dom: HTMLElement, config: EditorConfig): boolean;
|
|
24
|
+
static importDOM(): DOMConversionMap | null;
|
|
25
|
+
static importJSON(serializedNode: SerializedListItemNode): ListItemNode;
|
|
26
|
+
exportJSON(): SerializedListItemNode;
|
|
27
|
+
append(...nodes: LexicalNode[]): this;
|
|
28
|
+
replace<N extends LexicalNode>(replaceWithNode: N): N;
|
|
29
|
+
insertAfter(node: LexicalNode): LexicalNode;
|
|
30
|
+
remove(preserveEmptyParent?: boolean): void;
|
|
31
|
+
insertNewAfter(): ListItemNode | ParagraphNode;
|
|
32
|
+
collapseAtStart(selection: RangeSelection): true;
|
|
33
|
+
getValue(): number;
|
|
34
|
+
setValue(value: number): void;
|
|
35
|
+
getChecked(): boolean | undefined;
|
|
36
|
+
setChecked(checked?: boolean): void;
|
|
37
|
+
toggleChecked(): void;
|
|
38
|
+
getIndent(): number;
|
|
39
|
+
setIndent(indent: number): this;
|
|
40
|
+
canIndent(): false;
|
|
41
|
+
insertBefore(nodeToInsert: LexicalNode): LexicalNode;
|
|
42
|
+
canInsertAfter(node: LexicalNode): boolean;
|
|
43
|
+
canReplaceWith(replacement: LexicalNode): boolean;
|
|
44
|
+
canMergeWith(node: LexicalNode): boolean;
|
|
45
|
+
extractWithChild(child: LexicalNode, selection: RangeSelection | NodeSelection | GridSelection): boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare function $createListItemNode(checked?: boolean): ListItemNode;
|
|
48
|
+
export declare function $isListItemNode(node: LexicalNode | null | undefined): node is ListItemNode;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { Spread } from 'lexical';
|
|
9
|
+
import { DOMConversionMap, EditorConfig, ElementNode, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
|
|
10
|
+
export declare type SerializedListNode = Spread<{
|
|
11
|
+
listType: ListType;
|
|
12
|
+
start: number;
|
|
13
|
+
tag: ListNodeTagType;
|
|
14
|
+
type: 'list';
|
|
15
|
+
version: 1;
|
|
16
|
+
}, SerializedElementNode>;
|
|
17
|
+
export declare type ListType = 'number' | 'bullet' | 'check';
|
|
18
|
+
export declare type ListNodeTagType = 'ul' | 'ol';
|
|
19
|
+
export declare class ListNode extends ElementNode {
|
|
20
|
+
__tag: ListNodeTagType;
|
|
21
|
+
__start: number;
|
|
22
|
+
__listType: ListType;
|
|
23
|
+
static getType(): string;
|
|
24
|
+
static clone(node: ListNode): ListNode;
|
|
25
|
+
constructor(listType: ListType, start: number, key?: NodeKey);
|
|
26
|
+
getTag(): ListNodeTagType;
|
|
27
|
+
getListType(): ListType;
|
|
28
|
+
getStart(): number;
|
|
29
|
+
createDOM(config: EditorConfig, _editor?: LexicalEditor): HTMLElement;
|
|
30
|
+
updateDOM(prevNode: ListNode, dom: HTMLElement, config: EditorConfig): boolean;
|
|
31
|
+
static importDOM(): DOMConversionMap | null;
|
|
32
|
+
static importJSON(serializedNode: SerializedListNode): ListNode;
|
|
33
|
+
exportJSON(): SerializedListNode;
|
|
34
|
+
canBeEmpty(): false;
|
|
35
|
+
canIndent(): false;
|
|
36
|
+
append(...nodesToAppend: LexicalNode[]): this;
|
|
37
|
+
extractWithChild(child: LexicalNode): boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare function $createListNode(listType: ListType, start?: number): ListNode;
|
|
40
|
+
export declare function $isListNode(node: LexicalNode | null | undefined): node is ListNode;
|
package/formatList.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { LexicalEditor } from 'lexical';
|
|
9
|
+
import { ListItemNode, ListNode } from './';
|
|
10
|
+
import { ListType } from './LexicalListNode';
|
|
11
|
+
export declare function insertList(editor: LexicalEditor, listType: ListType): void;
|
|
12
|
+
export declare function removeList(editor: LexicalEditor): void;
|
|
13
|
+
export declare function updateChildrenListItemValue(list: ListNode, children?: Array<ListItemNode>): void;
|
|
14
|
+
export declare function $handleIndent(listItemNodes: Array<ListItemNode>): void;
|
|
15
|
+
export declare function $handleOutdent(listItemNodes: Array<ListItemNode>): void;
|
|
16
|
+
export declare function indentList(): void;
|
|
17
|
+
export declare function outdentList(): void;
|
|
18
|
+
export declare function $handleListInsertParagraph(): boolean;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { ListType } from './LexicalListNode';
|
|
9
|
+
import type { LexicalCommand } from 'lexical';
|
|
10
|
+
import { $handleListInsertParagraph, indentList, insertList, outdentList, removeList } from './formatList';
|
|
11
|
+
import { $createListItemNode, $isListItemNode, ListItemNode } from './LexicalListItemNode';
|
|
12
|
+
import { $createListNode, $isListNode, ListNode } from './LexicalListNode';
|
|
13
|
+
import { $getListDepth } from './utils';
|
|
14
|
+
export { $createListItemNode, $createListNode, $getListDepth, $handleListInsertParagraph, $isListItemNode, $isListNode, indentList, insertList, ListItemNode, ListNode, ListType, outdentList, removeList, };
|
|
15
|
+
export declare const INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
16
|
+
export declare const INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
17
|
+
export declare const INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
|
|
18
|
+
export declare const REMOVE_LIST_COMMAND: LexicalCommand<void>;
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.3.
|
|
11
|
+
"version": "0.3.6",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.3.
|
|
14
|
+
"lexical": "0.3.6"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.3.
|
|
17
|
+
"@lexical/utils": "0.3.6"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { LexicalNode } from 'lexical';
|
|
9
|
+
import { ListItemNode, ListNode } from './';
|
|
10
|
+
export declare function $getListDepth(listNode: ListNode): number;
|
|
11
|
+
export declare function $getTopListNode(listItem: LexicalNode): ListNode;
|
|
12
|
+
export declare function $isLastItemInList(listItem: ListItemNode): boolean;
|
|
13
|
+
export declare function $getAllListItems(node: ListNode): Array<ListItemNode>;
|
|
14
|
+
export declare function isNestedListNode(node: LexicalNode | null | undefined): boolean;
|
|
15
|
+
export declare function findNearestListItemNode(node: LexicalNode): ListItemNode | null;
|
|
16
|
+
export declare function getUniqueListItemNodes(nodeList: Array<LexicalNode>): Array<ListItemNode>;
|
|
17
|
+
export declare function $removeHighestEmptyListParent(sublist: ListItemNode | ListNode): void;
|
|
18
|
+
export declare function wrapInListItem(node: LexicalNode): ListItemNode;
|
package/LexicalList.d.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
ElementNode,
|
|
11
|
-
LexicalNode,
|
|
12
|
-
LexicalEditor,
|
|
13
|
-
ParagraphNode,
|
|
14
|
-
RangeSelection,
|
|
15
|
-
LexicalCommand,
|
|
16
|
-
SerializedElementNode,
|
|
17
|
-
} from 'lexical';
|
|
18
|
-
import type {Spread} from 'lexical';
|
|
19
|
-
|
|
20
|
-
export type ListNodeTagType = 'ul' | 'ol';
|
|
21
|
-
export type ListType = 'number' | 'bullet' | 'check';
|
|
22
|
-
export function $createListItemNode(checked?: boolean | void): ListItemNode;
|
|
23
|
-
export function $createListNode(listType: ListType, start?: number): ListNode;
|
|
24
|
-
export function $getListDepth(listNode: ListNode): number;
|
|
25
|
-
export function $handleListInsertParagraph(): boolean;
|
|
26
|
-
export function $isListItemNode(node?: LexicalNode): node is ListItemNode;
|
|
27
|
-
export function $isListNode(node?: LexicalNode): node is ListNode;
|
|
28
|
-
export function indentList(): void;
|
|
29
|
-
export function insertList(editor: LexicalEditor, listType: ListType): void;
|
|
30
|
-
export declare class ListItemNode extends ElementNode {
|
|
31
|
-
append(...nodes: LexicalNode[]): this;
|
|
32
|
-
replace<N extends LexicalNode>(replaceWithNode: N): N;
|
|
33
|
-
insertAfter(node: LexicalNode): LexicalNode;
|
|
34
|
-
insertNewAfter(): ListItemNode | ParagraphNode;
|
|
35
|
-
collapseAtStart(selection: RangeSelection): true;
|
|
36
|
-
getIndent(): number;
|
|
37
|
-
setIndent(indent: number): this;
|
|
38
|
-
insertBefore(nodeToInsert: LexicalNode): LexicalNode;
|
|
39
|
-
canInsertAfter(node: LexicalNode): boolean;
|
|
40
|
-
canReplaceWith(replacement: LexicalNode): boolean;
|
|
41
|
-
canMergeWith(node: LexicalNode): boolean;
|
|
42
|
-
getChecked(): boolean | void;
|
|
43
|
-
setChecked(boolean: boolean): this;
|
|
44
|
-
toggleChecked(): void;
|
|
45
|
-
static importJSON(serializedNode: SerializedListItemNode): ListItemNode;
|
|
46
|
-
exportJSON(): SerializedListItemNode;
|
|
47
|
-
}
|
|
48
|
-
export declare class ListNode extends ElementNode {
|
|
49
|
-
canBeEmpty(): false;
|
|
50
|
-
append(...nodesToAppend: LexicalNode[]): this;
|
|
51
|
-
getTag(): ListNodeTagType;
|
|
52
|
-
getStart(): number;
|
|
53
|
-
getListType(): ListType;
|
|
54
|
-
static importJSON(serializedNode: SerializedListNode): ListNode;
|
|
55
|
-
exportJSON(): SerializedListNode;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function outdentList(): void;
|
|
59
|
-
export function removeList(editor: LexicalEditor): boolean;
|
|
60
|
-
|
|
61
|
-
export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
62
|
-
export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
63
|
-
export var INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
|
|
64
|
-
export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
|
|
65
|
-
|
|
66
|
-
export type SerializedListItemNode = Spread<
|
|
67
|
-
{
|
|
68
|
-
checked: boolean | void;
|
|
69
|
-
value: number;
|
|
70
|
-
type: 'listitem';
|
|
71
|
-
},
|
|
72
|
-
SerializedElementNode
|
|
73
|
-
>;
|
|
74
|
-
|
|
75
|
-
export type SerializedListNode = Spread<
|
|
76
|
-
{
|
|
77
|
-
listType: ListType;
|
|
78
|
-
start: number;
|
|
79
|
-
tag: ListNodeTagType;
|
|
80
|
-
type: 'list';
|
|
81
|
-
},
|
|
82
|
-
SerializedElementNode
|
|
83
|
-
>;
|