@lexical/list 0.3.10 → 0.4.1
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 +21 -7
- package/LexicalList.prod.js +3 -3
- package/LexicalListItemNode.d.ts +3 -0
- package/LexicalListNode.d.ts +4 -0
- package/index.d.ts +4 -2
- package/package.json +3 -3
package/LexicalList.dev.js
CHANGED
|
@@ -190,6 +190,12 @@ function insertList(editor, listType) {
|
|
|
190
190
|
if (lexical.$isRootNode(anchorNodeParent)) {
|
|
191
191
|
anchorNode.replace(list);
|
|
192
192
|
const listItem = $createListItemNode();
|
|
193
|
+
|
|
194
|
+
if (lexical.$isElementNode(anchorNode)) {
|
|
195
|
+
listItem.setFormat(anchorNode.getFormatType());
|
|
196
|
+
listItem.setIndent(anchorNode.getIndent());
|
|
197
|
+
}
|
|
198
|
+
|
|
193
199
|
list.append(listItem);
|
|
194
200
|
} else if ($isListItemNode(anchorNode)) {
|
|
195
201
|
const parent = anchorNode.getParentOrThrow();
|
|
@@ -256,6 +262,8 @@ function createListOrMerge(node, listType) {
|
|
|
256
262
|
const previousSibling = node.getPreviousSibling();
|
|
257
263
|
const nextSibling = node.getNextSibling();
|
|
258
264
|
const listItem = $createListItemNode();
|
|
265
|
+
listItem.setFormat(node.getFormatType());
|
|
266
|
+
listItem.setIndent(node.getIndent());
|
|
259
267
|
append(listItem, node.getChildren());
|
|
260
268
|
|
|
261
269
|
if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
|
|
@@ -581,7 +589,12 @@ function $handleListInsertParagraph() {
|
|
|
581
589
|
* LICENSE file in the root directory of this source tree.
|
|
582
590
|
*
|
|
583
591
|
*/
|
|
592
|
+
|
|
593
|
+
/** @noInheritDoc */
|
|
584
594
|
class ListItemNode extends lexical.ElementNode {
|
|
595
|
+
/** @internal */
|
|
596
|
+
|
|
597
|
+
/** @internal */
|
|
585
598
|
static getType() {
|
|
586
599
|
return 'listitem';
|
|
587
600
|
}
|
|
@@ -1011,7 +1024,14 @@ function $isListItemNode(node) {
|
|
|
1011
1024
|
* LICENSE file in the root directory of this source tree.
|
|
1012
1025
|
*
|
|
1013
1026
|
*/
|
|
1027
|
+
|
|
1028
|
+
/** @noInheritDoc */
|
|
1014
1029
|
class ListNode extends lexical.ElementNode {
|
|
1030
|
+
/** @internal */
|
|
1031
|
+
|
|
1032
|
+
/** @internal */
|
|
1033
|
+
|
|
1034
|
+
/** @internal */
|
|
1015
1035
|
static getType() {
|
|
1016
1036
|
return 'list';
|
|
1017
1037
|
}
|
|
@@ -1242,13 +1262,7 @@ function $isListNode(node) {
|
|
|
1242
1262
|
return node instanceof ListNode;
|
|
1243
1263
|
}
|
|
1244
1264
|
|
|
1245
|
-
/**
|
|
1246
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1247
|
-
*
|
|
1248
|
-
* This source code is licensed under the MIT license found in the
|
|
1249
|
-
* LICENSE file in the root directory of this source tree.
|
|
1250
|
-
*
|
|
1251
|
-
*/
|
|
1265
|
+
/** @module @lexical/list */
|
|
1252
1266
|
const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand();
|
|
1253
1267
|
const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand();
|
|
1254
1268
|
const INSERT_CHECK_LIST_COMMAND = lexical.createCommand();
|
package/LexicalList.prod.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
'use strict';var h=require("lexical"),l=require("@lexical/utils");function m(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} 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}
|
|
8
8
|
function r(a){a=a.getParent();q(a)||m(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 z().append(a)}
|
|
9
9
|
function A(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}function C(a,b){a.splice(a.getChildrenSize(),0,b)}
|
|
10
|
-
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 D(a,b){if(q(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=z();e.setFormat(a.getFormatType());e.setIndent(a.getIndent());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}
|
|
11
11
|
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)})}
|
|
12
12
|
function G(a){let b=new Set;a.forEach(c=>{if(!u(c)&&!b.has(c.getKey())){var d=c.getParent(),e=c.getNextSibling(),f=c.getPreviousSibling();if(u(e)&&u(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(u(e))e=e.getFirstChild(),q(e)&&(f=e.getFirstChild(),null!==f&&f.insertBefore(c),F(e));else if(u(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?
|
|
13
13
|
f.insertAfter(g):e?e.insertBefore(g):d.append(g)}q(d)&&F(d)}})}
|
|
@@ -30,7 +30,7 @@ function R(a){let b=[];for(let c=0;c<a.length;c++){let d=a[c];p(d)?(b.push(d),d.
|
|
|
30
30
|
exports.$createListNode=E;exports.$getListDepth=n;
|
|
31
31
|
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=r(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));
|
|
32
32
|
b.forEach(g=>{g.remove();f.append(g)})}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=J;exports.ListNode=N;exports.REMOVE_LIST_COMMAND=V;exports.indentList=function(){I("indent")};
|
|
33
|
-
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),
|
|
34
|
-
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")};
|
|
33
|
+
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),e=z(),h.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),d.append(e)):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=
|
|
34
|
+
f.getParent();null!=f;){let k=f.getKey();if(q(f)){if(!c.has(k)){var g=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")};
|
|
35
35
|
exports.removeList=function(a){a.update(()=>{let b=h.$getSelection();if(h.$isRangeSelection(b)){var c=new Set,d=b.getNodes(),e=b.anchor.getNode();if(A(e,d))c.add(r(e));else for(e=0;e<d.length;e++){var f=d[e];h.$isLeafNode(f)&&(f=l.$getNearestNodeOfType(f,J),null!=f&&c.add(r(f)))}for(let g of c){c=g;d=t(g);for(let k of d)d=h.$createParagraphNode(),C(d,k.getChildren()),c.insertAfter(d),c=d,k.__key===b.anchor.key&&b.anchor.set(d.getKey(),0,"element"),k.__key===b.focus.key&&b.focus.set(d.getKey(),0,"element"),
|
|
36
36
|
k.remove();g.remove()}}})}
|
package/LexicalListItemNode.d.ts
CHANGED
|
@@ -13,8 +13,11 @@ export declare type SerializedListItemNode = Spread<{
|
|
|
13
13
|
value: number;
|
|
14
14
|
version: 1;
|
|
15
15
|
}, SerializedElementNode>;
|
|
16
|
+
/** @noInheritDoc */
|
|
16
17
|
export declare class ListItemNode extends ElementNode {
|
|
18
|
+
/** @internal */
|
|
17
19
|
__value: number;
|
|
20
|
+
/** @internal */
|
|
18
21
|
__checked?: boolean;
|
|
19
22
|
static getType(): string;
|
|
20
23
|
static clone(node: ListItemNode): ListItemNode;
|
package/LexicalListNode.d.ts
CHANGED
|
@@ -16,9 +16,13 @@ export declare type SerializedListNode = Spread<{
|
|
|
16
16
|
}, SerializedElementNode>;
|
|
17
17
|
export declare type ListType = 'number' | 'bullet' | 'check';
|
|
18
18
|
export declare type ListNodeTagType = 'ul' | 'ol';
|
|
19
|
+
/** @noInheritDoc */
|
|
19
20
|
export declare class ListNode extends ElementNode {
|
|
21
|
+
/** @internal */
|
|
20
22
|
__tag: ListNodeTagType;
|
|
23
|
+
/** @internal */
|
|
21
24
|
__start: number;
|
|
25
|
+
/** @internal */
|
|
22
26
|
__listType: ListType;
|
|
23
27
|
static getType(): string;
|
|
24
28
|
static clone(node: ListNode): ListNode;
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @module @lexical/list */
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
4
|
*
|
|
@@ -5,13 +6,14 @@
|
|
|
5
6
|
* LICENSE file in the root directory of this source tree.
|
|
6
7
|
*
|
|
7
8
|
*/
|
|
8
|
-
import type {
|
|
9
|
+
import type { SerializedListItemNode } from './LexicalListItemNode';
|
|
10
|
+
import type { ListType, SerializedListNode } from './LexicalListNode';
|
|
9
11
|
import type { LexicalCommand } from 'lexical';
|
|
10
12
|
import { $handleListInsertParagraph, indentList, insertList, outdentList, removeList } from './formatList';
|
|
11
13
|
import { $createListItemNode, $isListItemNode, ListItemNode } from './LexicalListItemNode';
|
|
12
14
|
import { $createListNode, $isListNode, ListNode } from './LexicalListNode';
|
|
13
15
|
import { $getListDepth } from './utils';
|
|
14
|
-
export { $createListItemNode, $createListNode, $getListDepth, $handleListInsertParagraph, $isListItemNode, $isListNode, indentList, insertList, ListItemNode, ListNode, ListType, outdentList, removeList, };
|
|
16
|
+
export { $createListItemNode, $createListNode, $getListDepth, $handleListInsertParagraph, $isListItemNode, $isListNode, indentList, insertList, ListItemNode, ListNode, ListType, outdentList, removeList, SerializedListItemNode, SerializedListNode, };
|
|
15
17
|
export declare const INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
16
18
|
export declare const INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
17
19
|
export declare const INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.4.1",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.4.1"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.
|
|
17
|
+
"@lexical/utils": "0.4.1"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|