@lexical/list 0.1.14 → 0.1.15
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 +12 -54
- package/LexicalList.prod.js +24 -24
- package/package.json +5 -2
package/LexicalList.dev.js
CHANGED
|
@@ -7,30 +7,9 @@
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var list = require('@lexical/list');
|
|
10
|
+
var utils = require('@lexical/utils');
|
|
10
11
|
var lexical = require('lexical');
|
|
11
12
|
|
|
12
|
-
/**
|
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
function $getNearestNodeOfType(node, klass) {
|
|
21
|
-
let parent = node;
|
|
22
|
-
|
|
23
|
-
while (parent != null) {
|
|
24
|
-
if (parent instanceof klass) {
|
|
25
|
-
return parent;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
parent = parent.getParent();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return parent;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
13
|
/**
|
|
35
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
36
15
|
*
|
|
@@ -279,7 +258,7 @@ function removeList(editor) {
|
|
|
279
258
|
const node = nodes[i];
|
|
280
259
|
|
|
281
260
|
if (lexical.$isLeafNode(node)) {
|
|
282
|
-
const listItemNode =
|
|
261
|
+
const listItemNode = utils.$getNearestNodeOfType(node, list.ListItemNode);
|
|
283
262
|
|
|
284
263
|
if (listItemNode != null) {
|
|
285
264
|
listNodes.add($getTopListNode(listItemNode));
|
|
@@ -533,27 +512,6 @@ function $handleListInsertParagraph() {
|
|
|
533
512
|
return true;
|
|
534
513
|
}
|
|
535
514
|
|
|
536
|
-
/**
|
|
537
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
538
|
-
*
|
|
539
|
-
* This source code is licensed under the MIT license found in the
|
|
540
|
-
* LICENSE file in the root directory of this source tree.
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*/
|
|
544
|
-
function addClassNamesToElement(element, ...classNames) {
|
|
545
|
-
classNames.forEach(className => {
|
|
546
|
-
if (className != null && typeof className === 'string') {
|
|
547
|
-
element.classList.add(...className.split(' '));
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
function removeClassNamesFromElement(element, ...classNames) {
|
|
552
|
-
classNames.forEach(className => {
|
|
553
|
-
element.classList.remove(...className.split(' '));
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
|
|
557
515
|
/**
|
|
558
516
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
559
517
|
*
|
|
@@ -851,11 +809,11 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
851
809
|
}
|
|
852
810
|
|
|
853
811
|
if (classesToAdd.length > 0) {
|
|
854
|
-
addClassNamesToElement(dom, ...classesToAdd);
|
|
812
|
+
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
855
813
|
}
|
|
856
814
|
|
|
857
815
|
if (classesToRemove.length > 0) {
|
|
858
|
-
removeClassNamesFromElement(dom, ...classesToRemove);
|
|
816
|
+
utils.removeClassNamesFromElement(dom, ...classesToRemove);
|
|
859
817
|
}
|
|
860
818
|
}
|
|
861
819
|
|
|
@@ -969,11 +927,10 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
969
927
|
const listTheme = editorThemeClasses.list;
|
|
970
928
|
|
|
971
929
|
if (listTheme !== undefined) {
|
|
972
|
-
const
|
|
973
|
-
const
|
|
974
|
-
const
|
|
975
|
-
const
|
|
976
|
-
const listLevelClassName = listTheme[listThemeLevelClassName];
|
|
930
|
+
const listLevelsClassNames = listTheme[node.__tag + 'Depth'] || [];
|
|
931
|
+
const listDepth = $getListDepth(node) - 1;
|
|
932
|
+
const normalizedListDepth = listDepth % listLevelsClassNames.length;
|
|
933
|
+
const listLevelClassName = listLevelsClassNames[normalizedListDepth];
|
|
977
934
|
const listClassName = listTheme[node.__tag];
|
|
978
935
|
let nestedListClassName;
|
|
979
936
|
const nestedListTheme = listTheme.nested;
|
|
@@ -990,7 +947,7 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
990
947
|
const listItemClasses = listLevelClassName.split(' ');
|
|
991
948
|
classesToAdd.push(...listItemClasses);
|
|
992
949
|
|
|
993
|
-
for (let i =
|
|
950
|
+
for (let i = 0; i < listLevelsClassNames.length; i++) {
|
|
994
951
|
if (i !== normalizedListDepth) {
|
|
995
952
|
classesToRemove.push(node.__tag + i);
|
|
996
953
|
}
|
|
@@ -1009,11 +966,11 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
1009
966
|
}
|
|
1010
967
|
|
|
1011
968
|
if (classesToAdd.length > 0) {
|
|
1012
|
-
addClassNamesToElement(dom, ...classesToAdd);
|
|
969
|
+
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
1013
970
|
}
|
|
1014
971
|
|
|
1015
972
|
if (classesToRemove.length > 0) {
|
|
1016
|
-
removeClassNamesFromElement(dom, ...classesToRemove);
|
|
973
|
+
utils.removeClassNamesFromElement(dom, ...classesToRemove);
|
|
1017
974
|
}
|
|
1018
975
|
}
|
|
1019
976
|
|
|
@@ -1039,6 +996,7 @@ function $isListNode(node) {
|
|
|
1039
996
|
|
|
1040
997
|
exports.$createListItemNode = $createListItemNode;
|
|
1041
998
|
exports.$createListNode = $createListNode;
|
|
999
|
+
exports.$getListDepth = $getListDepth;
|
|
1042
1000
|
exports.$handleListInsertParagraph = $handleListInsertParagraph;
|
|
1043
1001
|
exports.$isListItemNode = $isListItemNode;
|
|
1044
1002
|
exports.$isListNode = $isListNode;
|
package/LexicalList.prod.js
CHANGED
|
@@ -4,27 +4,27 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
function w(b
|
|
10
|
-
function x(b){
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function B(b
|
|
16
|
-
class C extends
|
|
17
|
-
const a=this.getParentOrThrow();if(
|
|
18
|
-
if(
|
|
19
|
-
d.select()):(c.replace(a),c=b.anchor,b=b.focus,d=a.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===b.type&&b.getNode().is(this)&&b.set(d,b.offset,"element")):(c.insertBefore(a),this.remove());return!0}getIndent(){let b=this.getParentOrThrow().getParentOrThrow(),a=0;for(;G(b);)b=b.getParentOrThrow().getParentOrThrow(),a++;return a}setIndent(b){let a=this.getIndent();for(;a!==b;)a<b?(
|
|
20
|
-
G(b)&&a.forEach(c=>c.markDirty());return super.insertBefore(b)}canInsertAfter(b){return G(b)}canReplaceWith(b){return G(b)}canMergeWith(b){return
|
|
21
|
-
function E(b,a,c){const d=[],e=[],
|
|
22
|
-
class I extends
|
|
23
|
-
priority:0})}}canBeEmpty(){return!1}append(...b){for(let c=0;c<b.length;c++){var a=b[c];if(
|
|
24
|
-
function J(b,a,c){const d=[],e=[];
|
|
25
|
-
|
|
26
|
-
exports.$handleListInsertParagraph=function(){var b=
|
|
27
|
-
|
|
28
|
-
exports.insertList=function(b,a){b.update(()=>{var c=
|
|
29
|
-
|
|
30
|
-
exports.removeList=function(b){b.update(()=>{var a=
|
|
7
|
+
var g=require("@lexical/list"),k=require("@lexical/utils"),n=require("lexical");function p(b){throw Error(`Minified Lexical error #${b}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function q(b){let a=1;for(b=b.getParent();null!=b;){if(g.$isListItemNode(b)){b=b.getParent();if(g.$isListNode(b)){a++;b=b.getParent();continue}p(2)}break}return a}
|
|
8
|
+
function r(b){b=b.getParent();g.$isListNode(b)||p(2);let a=b;for(;null!==a;)a=a.getParent(),g.$isListNode(a)&&(b=a);return b}function u(b){let a=[];b=b.getChildren().filter(g.$isListItemNode);for(let c=0;c<b.length;c++){const d=b[c],e=d.getFirstChild();g.$isListNode(e)?a=a.concat(u(e)):a.push(d)}return a}function v(b){return g.$isListItemNode(b)&&g.$isListNode(b.getFirstChild())}
|
|
9
|
+
function w(b){for(;null==b.getNextSibling()&&null==b.getPreviousSibling();){const a=b.getParent();if(null==a||!g.$isListItemNode(b)&&!g.$isListNode(b))break;b=a}b.remove()}
|
|
10
|
+
function x(b,a){if(g.$isListNode(b))return b;const c=b.getPreviousSibling(),d=b.getNextSibling(),e=g.$createListItemNode();if(g.$isListNode(c)&&a===c.getTag())return e.append(b),c.append(e),g.$isListNode(d)&&a===d.getTag()&&(c.append(...d.getChildren()),d.remove()),c;if(g.$isListNode(d)&&a===d.getTag())return e.append(b),d.getFirstChildOrThrow().insertBefore(e),d;a=g.$createListNode(a);a.append(e);b.replace(a);e.append(b);return a}
|
|
11
|
+
function z(b){b.forEach(a=>{if(!v(a)){var c=a.getParent(),d=a.getNextSibling(),e=a.getPreviousSibling();if(v(d)&&v(e))e=e.getFirstChild(),g.$isListNode(e)&&(e.append(a),a=d.getFirstChild(),g.$isListNode(a)&&(d=a.getChildren(),e.append(...d),a.remove()),e.getChildren().forEach(f=>f.markDirty()));else if(v(d))d=d.getFirstChild(),g.$isListNode(d)&&(e=d.getFirstChild(),null!==e&&e.insertBefore(a),d.getChildren().forEach(f=>f.markDirty()));else if(v(e))d=e.getFirstChild(),g.$isListNode(d)&&(d.append(a),
|
|
12
|
+
d.getChildren().forEach(f=>f.markDirty()));else if(g.$isListNode(c)){const f=g.$createListItemNode(),h=g.$createListNode(c.getTag());f.append(h);h.append(a);e?e.insertAfter(f):d?d.insertBefore(f):c.append(f)}g.$isListNode(c)&&c.getChildren().forEach(f=>f.markDirty())}})}
|
|
13
|
+
function A(b){b.forEach(a=>{if(!v(a)){var c=a.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(g.$isListNode(e)&&g.$isListItemNode(d)&&g.$isListNode(c)){var f=c?c.getFirstChild():void 0,h=c?c.getLastChild():void 0;if(a.is(f))d.insertBefore(a),c.isEmpty()&&d.remove();else if(a.is(h))d.insertAfter(a),c.isEmpty()&&d.remove();else{var l=c.getTag();f=g.$createListItemNode();const m=g.$createListNode(l);f.append(m);a.getPreviousSiblings().forEach(t=>m.append(t));h=g.$createListItemNode();
|
|
14
|
+
l=g.$createListNode(l);h.append(l);l.append(...a.getNextSiblings());d.insertBefore(f);d.insertAfter(h);d.replace(a)}c.getChildren().forEach(m=>m.markDirty());e.getChildren().forEach(m=>m.markDirty())}}})}
|
|
15
|
+
function B(b){var a=n.$getSelection();if(!n.$isRangeSelection(a))return!1;var c=a.getNodes(),d=[];0===c.length&&c.push(a.anchor.getNode());if(1===c.length){a:{for(c=c[0];null!==c;){if(g.$isListItemNode(c))break a;c=c.getParent()}c=null}null!==c&&(d=[c])}else{d=new Set;for(a=0;a<c.length;a++){const e=c[a];g.$isListItemNode(e)&&d.add(e)}d=Array.from(d)}return 0<d.length?("indent"===b?z(d):A(d),!0):!1}
|
|
16
|
+
class C extends n.ElementNode{static getType(){return"listitem"}static clone(b){return new C(b.__key)}constructor(b){super(b)}createDOM(b){const a=document.createElement("li");a.value=D(this);E(a,b.theme,this);return a}updateDOM(b,a,c){a.value=D(this);E(a,c.theme,this);return!1}static convertDOM(){return{li:()=>({conversion:F,priority:0})}}append(...b){for(let a=0;a<b.length;a++){const c=b[a];if(n.$isElementNode(c)&&this.canMergeWith(c)){const d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(b){if(G(b))return super.replace(b);
|
|
17
|
+
const a=this.getParentOrThrow();if(g.$isListNode(a)){var c=a.__children;const e=c.length;var d=c.indexOf(this.__key);if(0===d)a.insertBefore(b);else if(d===e-1)a.insertAfter(b);else{c=g.$createListNode(a.__tag);const f=a.getChildren();for(d+=1;d<e;d++)c.append(f[d]);a.insertAfter(b);b.insertAfter(c)}this.remove();1===e&&a.remove()}return b}insertAfter(b){var a=this.getNextSiblings();if(G(b))return a.forEach(d=>d.markDirty()),super.insertAfter(b);var c=this.getParentOrThrow();g.$isListNode(c)||p(1);
|
|
18
|
+
if(g.$isListNode(b)&&b.getTag()===c.getTag()){a=b;b=b.getChildren();for(c=b.length-1;0<=c;c--)a=b[c],this.insertAfter(a);return a}c.insertAfter(b);if(0!==a.length){const d=g.$createListNode(c.getTag());a.forEach(e=>d.append(e));b.insertAfter(d)}return b}insertNewAfter(){const b=H();this.insertAfter(b);return b}collapseAtStart(b){const a=n.$createParagraphNode();this.getChildren().forEach(f=>a.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();const e=G(d);1===c.getChildrenSize()?e?(c.remove(),
|
|
19
|
+
d.select()):(c.replace(a),c=b.anchor,b=b.focus,d=a.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===b.type&&b.getNode().is(this)&&b.set(d,b.offset,"element")):(c.insertBefore(a),this.remove());return!0}getIndent(){let b=this.getParentOrThrow().getParentOrThrow(),a=0;for(;G(b);)b=b.getParentOrThrow().getParentOrThrow(),a++;return a}setIndent(b){let a=this.getIndent();for(;a!==b;)a<b?(z([this]),a++):(A([this]),a--);return this}insertBefore(b){const a=this.getNextSiblings();
|
|
20
|
+
G(b)&&a.forEach(c=>c.markDirty());return super.insertBefore(b)}canInsertAfter(b){return G(b)}canReplaceWith(b){return G(b)}canMergeWith(b){return n.$isParagraphNode(b)||G(b)}}function D(b){var a=b.getParent();let c=1;null!=a&&(g.$isListNode(a)?c=a.__start:p(47));b=b.getPreviousSiblings();for(a=0;a<b.length;a++){const d=b[a];G(d)&&!g.$isListNode(d.getFirstChild())&&c++}return c}
|
|
21
|
+
function E(b,a,c){const d=[],e=[],f=(a=a.list)?a.listitem:void 0;if(a&&a.nested)var h=a.nested.listitem;void 0!==f&&(a=f.split(" "),d.push(...a));void 0!==h&&(h=h.split(" "),c.getChildren().some(l=>g.$isListNode(l))?d.push(...h):e.push(...h));0<d.length&&k.addClassNamesToElement(b,...d);0<e.length&&k.removeClassNamesFromElement(b,...e)}function F(){return{node:H()}}function H(){return new C}function G(b){return b instanceof C}
|
|
22
|
+
class I extends n.ElementNode{static getType(){return"list"}static clone(b){return new I(b.__tag,b.__start,b.__key)}constructor(b,a,c){super(c);this.__tag=b;this.__start=a}getTag(){return this.__tag}createDOM(b){const a=document.createElement(this.__tag);1!==this.__start&&a.setAttribute("start",String(this.__start));J(a,b.theme,this);return a}updateDOM(b,a,c){if(b.__tag!==this.__tag)return!0;J(a,c.theme,this);return!1}static convertDOM(){return{ol:()=>({conversion:K,priority:0}),ul:()=>({conversion:K,
|
|
23
|
+
priority:0})}}canBeEmpty(){return!1}append(...b){for(let c=0;c<b.length;c++){var a=b[c];if(g.$isListItemNode(a))super.append(a);else{const d=g.$createListItemNode();L(a)?d.append(a):(a=n.$createTextNode(a.getTextContent()),d.append(a));super.append(d)}}return this}}
|
|
24
|
+
function J(b,a,c){const d=[],e=[];var f=a.list;if(void 0!==f){const l=f[c.__tag+"Depth"]||[];a=q(c)-1;const m=a%l.length;var h=l[m];const t=f[c.__tag];let y;f=f.nested;void 0!==f&&f.list&&(y=f.list);void 0!==t&&d.push(t);if(void 0!==h)for(h=h.split(" "),d.push(...h),h=0;h<l.length;h++)h!==m&&e.push(c.__tag+h);void 0!==y&&(c=y.split(" "),1<a?d.push(...c):e.push(...c))}0<d.length&&k.addClassNamesToElement(b,...d);0<e.length&&k.removeClassNamesFromElement(b,...e)}
|
|
25
|
+
function K(b){b=b.nodeName.toLowerCase();let a=null;if("ol"===b||"ul"===b)a=M(b);return{node:a}}function M(b,a=1){return new I(b,a)}function L(b){return b instanceof I}exports.$createListItemNode=H;exports.$createListNode=M;exports.$getListDepth=q;
|
|
26
|
+
exports.$handleListInsertParagraph=function(){var b=n.$getSelection();if(!n.$isRangeSelection(b)||!b.isCollapsed())return!1;b=b.anchor.getNode();if(!g.$isListItemNode(b)||""!==b.getTextContent())return!1;var a=r(b),c=b.getParent();g.$isListNode(c)||p(2);const d=c.getParent();let e;if(n.$isRootNode(d))e=n.$createParagraphNode(),a.insertAfter(e);else if(g.$isListItemNode(d))e=g.$createListItemNode(),d.insertAfter(e);else return!1;e.select();a=b.getNextSiblings();if(0<a.length){const f=g.$createListNode(c.getTag());
|
|
27
|
+
n.$isParagraphNode(e)?e.insertAfter(f):(c=g.$createListItemNode(),c.append(f),e.insertAfter(c));a.forEach(h=>{h.remove();f.append(h)})}w(b);return!0};exports.$isListItemNode=G;exports.$isListNode=L;exports.ListItemNode=C;exports.ListNode=I;exports.indentList=function(){return B("indent")};
|
|
28
|
+
exports.insertList=function(b,a){b.update(()=>{var c=n.$getSelection();if(n.$isRangeSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(0===d.length)d=g.$createListNode(a),n.$isRootNode(e)?(c.replace(d),c=g.$createListItemNode(),d.append(c)):g.$isListItemNode(c)&&(c=c.getParentOrThrow(),d.append(...c.getChildren()),c.replace(d));else for(c=new Set,e=0;e<d.length;e++){var f=d[e];if(n.$isElementNode(f)&&f.isEmpty()&&!c.has(f.getKey()))x(f,a);else if(n.$isLeafNode(f))for(f=f.getParent();null!=
|
|
29
|
+
f;){const l=f.getKey();if(g.$isListNode(f)){if(!c.has(l)){var h=g.$createListNode(a);h.append(...f.getChildren());f.replace(h);c.add(l)}break}else{h=f.getParent();if(n.$isRootNode(h)&&!c.has(l)){c.add(l);x(f,a);break}f=h}}}}})};exports.outdentList=function(){return B("outdent")};
|
|
30
|
+
exports.removeList=function(b){b.update(()=>{var a=n.$getSelection();if(n.$isRangeSelection(a)){const d=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&g.$isListItemNode(a))d.add(r(a));else for(a=0;a<e.length;a++){var c=e[a];n.$isLeafNode(c)&&(c=k.$getNearestNodeOfType(c,g.ListItemNode),null!=c&&d.add(r(c)))}d.forEach(f=>{let h=f;u(f).forEach(l=>{if(null!=l){const m=n.$createParagraphNode();m.append(...l.getChildren());h.insertAfter(m);h=m;l.remove()}});f.remove()})}})};
|
package/package.json
CHANGED
|
@@ -12,10 +12,13 @@
|
|
|
12
12
|
"list"
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"version": "0.1.
|
|
15
|
+
"version": "0.1.15",
|
|
16
16
|
"main": "LexicalList.js",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"lexical": "0.1.
|
|
18
|
+
"lexical": "0.1.15"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@lexical/utils": "0.1.15"
|
|
19
22
|
},
|
|
20
23
|
"repository": {
|
|
21
24
|
"type": "git",
|