@lexical/list 0.1.8 → 0.1.9

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.
@@ -165,7 +165,6 @@ function getUniqueListItemNodes(nodeList) {
165
165
  */
166
166
  function insertList(editor, listType) {
167
167
  editor.update(() => {
168
- lexical.$log('formatList');
169
168
  const selection = lexical.$getSelection();
170
169
 
171
170
  if (selection !== null) {
@@ -267,7 +266,6 @@ function createListOrMerge(node, listType) {
267
266
 
268
267
  function removeList(editor) {
269
268
  editor.update(() => {
270
- lexical.$log('removeList');
271
269
  const selection = lexical.$getSelection();
272
270
 
273
271
  if (selection !== null) {
@@ -4,26 +4,26 @@
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
- 'use strict';var f=require("@lexical/list"),k=require("lexical");function n(c,a){for(;null!=c&&!(c instanceof a);)c=c.getParent();return c}function p(c){throw Error(`Minified Lexical error #${c}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function r(c){c=c.getParent();f.$isListNode(c)||p(2);let a=c;for(;null!==a;)a=a.getParent(),f.$isListNode(a)&&(c=a);return c}
7
+ var f=require("@lexical/list"),l=require("lexical");function n(c,a){for(;null!=c&&!(c instanceof a);)c=c.getParent();return c}function p(c){throw Error(`Minified Lexical error #${c}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function r(c){c=c.getParent();f.$isListNode(c)||p(2);let a=c;for(;null!==a;)a=a.getParent(),f.$isListNode(a)&&(c=a);return c}
8
8
  function t(c){let a=[];c=c.getChildren().filter(f.$isListItemNode);for(let b=0;b<c.length;b++){const d=c[b],e=d.getFirstChild();f.$isListNode(e)?a=a.concat(t(e)):a.push(d)}return a}function u(c){return f.$isListItemNode(c)&&f.$isListNode(c.getFirstChild())}
9
9
  function v(c,a){if(f.$isListNode(c))return c;const b=c.getPreviousSibling(),d=c.getNextSibling(),e=f.$createListItemNode();if(f.$isListNode(b)&&a===b.getTag())return e.append(c),b.append(e),f.$isListNode(d)&&a===d.getTag()&&(b.append(...d.getChildren()),d.remove()),b;if(f.$isListNode(d)&&a===d.getTag())return e.append(c),d.getFirstChildOrThrow().insertBefore(e),d;a=f.$createListNode(a);a.append(e);c.replace(a);e.append(c);return a}
10
10
  function w(c){c.forEach(a=>{if(!u(a)){var b=a.getParent(),d=a.getNextSibling(),e=a.getPreviousSibling();if(u(d)&&u(e))e=e.getFirstChild(),f.$isListNode(e)&&(e.append(a),a=d.getFirstChild(),f.$isListNode(a)&&(d=a.getChildren(),e.append(...d),a.remove()),e.getChildren().forEach(g=>g.markDirty()));else if(u(d))d=d.getFirstChild(),f.$isListNode(d)&&(e=d.getFirstChild(),null!==e&&e.insertBefore(a),d.getChildren().forEach(g=>g.markDirty()));else if(u(e))d=e.getFirstChild(),f.$isListNode(d)&&(d.append(a),
11
11
  d.getChildren().forEach(g=>g.markDirty()));else if(f.$isListNode(b)){const g=f.$createListItemNode(),h=f.$createListNode(b.getTag());g.append(h);h.append(a);e?e.insertAfter(g):d?d.insertBefore(g):b.append(g)}f.$isListNode(b)&&b.getChildren().forEach(g=>g.markDirty())}})}
12
- function x(c){c.forEach(a=>{if(!u(a)){var b=a.getParent(),d=b?b.getParent():void 0,e=d?d.getParent():void 0;if(f.$isListNode(e)&&f.$isListItemNode(d)&&f.$isListNode(b)){var g=b?b.getFirstChild():void 0,h=b?b.getLastChild():void 0;if(a.is(g))d.insertBefore(a),b.isEmpty()&&d.remove();else if(a.is(h))d.insertAfter(a),b.isEmpty()&&d.remove();else{var l=b.getTag();g=f.$createListItemNode();const m=f.$createListNode(l);g.append(m);a.getPreviousSiblings().forEach(q=>m.append(q));h=f.$createListItemNode();
13
- l=f.$createListNode(l);h.append(l);l.append(...a.getNextSiblings());d.insertBefore(g);d.insertAfter(h);d.replace(a)}b.getChildren().forEach(m=>m.markDirty());e.getChildren().forEach(m=>m.markDirty())}}})}
14
- function y(c){var a=k.$getSelection();if(null===a)return!1;var b=a.getNodes(),d=[];0===b.length&&b.push(a.anchor.getNode());if(1===b.length){a:{for(b=b[0];null!==b;){if(f.$isListItemNode(b))break a;b=b.getParent()}b=null}null!==b&&(d=[b])}else{d=new Set;for(a=0;a<b.length;a++){const e=b[a];f.$isListItemNode(e)&&d.add(e)}d=Array.from(d)}return 0<d.length?("indent"===c?w(d):x(d),!0):!1}function z(c,...a){a.forEach(b=>{null!=b&&"string"===typeof b&&c.classList.add(...b.split(" "))})}
12
+ function x(c){c.forEach(a=>{if(!u(a)){var b=a.getParent(),d=b?b.getParent():void 0,e=d?d.getParent():void 0;if(f.$isListNode(e)&&f.$isListItemNode(d)&&f.$isListNode(b)){var g=b?b.getFirstChild():void 0,h=b?b.getLastChild():void 0;if(a.is(g))d.insertBefore(a),b.isEmpty()&&d.remove();else if(a.is(h))d.insertAfter(a),b.isEmpty()&&d.remove();else{var k=b.getTag();g=f.$createListItemNode();const m=f.$createListNode(k);g.append(m);a.getPreviousSiblings().forEach(q=>m.append(q));h=f.$createListItemNode();
13
+ k=f.$createListNode(k);h.append(k);k.append(...a.getNextSiblings());d.insertBefore(g);d.insertAfter(h);d.replace(a)}b.getChildren().forEach(m=>m.markDirty());e.getChildren().forEach(m=>m.markDirty())}}})}
14
+ function y(c){var a=l.$getSelection();if(null===a)return!1;var b=a.getNodes(),d=[];0===b.length&&b.push(a.anchor.getNode());if(1===b.length){a:{for(b=b[0];null!==b;){if(f.$isListItemNode(b))break a;b=b.getParent()}b=null}null!==b&&(d=[b])}else{d=new Set;for(a=0;a<b.length;a++){const e=b[a];f.$isListItemNode(e)&&d.add(e)}d=Array.from(d)}return 0<d.length?("indent"===c?w(d):x(d),!0):!1}function z(c,...a){a.forEach(b=>{null!=b&&"string"===typeof b&&c.classList.add(...b.split(" "))})}
15
15
  function A(c,...a){a.forEach(b=>{c.classList.remove(...b.split(" "))})}
16
- class B extends k.ElementNode{static getType(){return"listitem"}static clone(c){return new B(c.__key)}constructor(c){super(c)}createDOM(c){const a=document.createElement("li");a.value=C(this);D(a,c.theme,this);return a}updateDOM(c,a,b){a.value=C(this);D(a,b.theme,this);return!1}append(...c){for(let a=0;a<c.length;a++){const b=c[a];if(k.$isElementNode(b)&&this.canMergeWith(b)){const d=b.getChildren();this.append(...d);b.remove()}else super.append(b)}return this}replace(c){if(E(c))return super.replace(c);const a=
16
+ class B extends l.ElementNode{static getType(){return"listitem"}static clone(c){return new B(c.__key)}constructor(c){super(c)}createDOM(c){const a=document.createElement("li");a.value=C(this);D(a,c.theme,this);return a}updateDOM(c,a,b){a.value=C(this);D(a,b.theme,this);return!1}append(...c){for(let a=0;a<c.length;a++){const b=c[a];if(l.$isElementNode(b)&&this.canMergeWith(b)){const d=b.getChildren();this.append(...d);b.remove()}else super.append(b)}return this}replace(c){if(E(c))return super.replace(c);const a=
17
17
  this.getParentOrThrow();if(f.$isListNode(a)){var b=a.__children;const e=b.length;var d=b.indexOf(this.__key);if(0===d)a.insertBefore(c);else if(d===e-1)a.insertAfter(c);else{b=f.$createListNode(a.__tag);const g=a.getChildren();for(d+=1;d<e;d++)b.append(g[d]);a.insertAfter(c);c.insertAfter(b)}this.remove();1===e&&a.remove()}return c}insertAfter(c){var a=this.getNextSiblings();if(E(c))return a.forEach(d=>d.markDirty()),super.insertAfter(c);var b=this.getParentOrThrow();f.$isListNode(b)||p(1);if(f.$isListNode(c)&&
18
- c.getTag()===b.getTag()){a=c;c=c.getChildren();for(b=c.length-1;0<=b;b--)a=c[b],this.insertAfter(a);return a}b.insertAfter(c);if(0!==a.length){const d=f.$createListNode(b.getTag());a.forEach(e=>d.append(e));c.insertAfter(d)}return c}insertNewAfter(){var c=this.getNextSibling(),a=this.getPreviousSibling(),b=r(this);var d=!0;var e=this.getFirstChild();if(f.$isListNode(e))d=!1;else for(e=this;null!==e;)f.$isListItemNode(e)&&0<e.getNextSiblings().length&&(d=!1),e=e.getParent();if(k.$isElementNode(b)&&
19
- ""===this.getTextContent()&&(null===a||null===c)&&d){null===c?(c=k.$createParagraphNode(),b.insertAfter(c)):(c=k.$createParagraphNode(),b.insertBefore(c));for(b=this;null==b.getNextSibling()&&null==b.getPreviousSibling();){a=b.getParent();if(null==a||!E(b)&&!f.$isListNode(b))break;b=a}b.remove()}else c=F(),this.insertAfter(c);return c}collapseAtStart(c){const a=k.$createParagraphNode();this.getChildren().forEach(g=>a.append(g));var b=this.getParentOrThrow(),d=b.getParentOrThrow();const e=E(d);1===
18
+ c.getTag()===b.getTag()){a=c;c=c.getChildren();for(b=c.length-1;0<=b;b--)a=c[b],this.insertAfter(a);return a}b.insertAfter(c);if(0!==a.length){const d=f.$createListNode(b.getTag());a.forEach(e=>d.append(e));c.insertAfter(d)}return c}insertNewAfter(){var c=this.getNextSibling(),a=this.getPreviousSibling(),b=r(this);var d=!0;var e=this.getFirstChild();if(f.$isListNode(e))d=!1;else for(e=this;null!==e;)f.$isListItemNode(e)&&0<e.getNextSiblings().length&&(d=!1),e=e.getParent();if(l.$isElementNode(b)&&
19
+ ""===this.getTextContent()&&(null===a||null===c)&&d){null===c?(c=l.$createParagraphNode(),b.insertAfter(c)):(c=l.$createParagraphNode(),b.insertBefore(c));for(b=this;null==b.getNextSibling()&&null==b.getPreviousSibling();){a=b.getParent();if(null==a||!E(b)&&!f.$isListNode(b))break;b=a}b.remove()}else c=F(),this.insertAfter(c);return c}collapseAtStart(c){const a=l.$createParagraphNode();this.getChildren().forEach(g=>a.append(g));var b=this.getParentOrThrow(),d=b.getParentOrThrow();const e=E(d);1===
20
20
  b.getChildrenSize()?e?(b.remove(),d.select()):(b.replace(a),b=c.anchor,c=c.focus,d=a.getKey(),"element"===b.type&&b.getNode().is(this)&&b.set(d,b.offset,"element"),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element")):(b.insertBefore(a),this.remove());return!0}getIndent(){let c=this.getParentOrThrow().getParentOrThrow(),a=0;for(;E(c);)c=c.getParentOrThrow().getParentOrThrow(),a++;return a}setIndent(c){let a=this.getIndent();for(;a!==c;)a<c?(w([this]),a++):(x([this]),a--);return this}insertBefore(c){const a=
21
- this.getNextSiblings();E(c)&&a.forEach(b=>b.markDirty());return super.insertBefore(c)}canInsertAfter(c){return E(c)}canReplaceWith(c){return E(c)}canMergeWith(c){return k.$isParagraphNode(c)||E(c)}}function C(c){var a=c.getParent();let b=1;null!=a&&(f.$isListNode(a)?b=a.__start:p(47));c=c.getPreviousSiblings();for(a=0;a<c.length;a++){const d=c[a];E(d)&&!f.$isListNode(d.getFirstChild())&&b++}return b}
22
- function D(c,a,b){const d=[],e=[],g=(a=a.list)?a.listitem:void 0;if(a&&a.nested)var h=a.nested.listitem;void 0!==g&&(a=g.split(" "),d.push(...a));void 0!==h&&(h=h.split(" "),b.getChildren().some(l=>f.$isListNode(l))?d.push(...h):e.push(...h));0<d.length&&z(c,...d);0<e.length&&A(c,...e)}function F(){return new B}function E(c){return c instanceof B}
23
- class G extends k.ElementNode{static getType(){return"list"}static clone(c){return new G(c.__tag,c.__start,c.__key)}constructor(c,a,b){super(b);this.__tag=c;this.__start=a}getTag(){return this.__tag}createDOM(c){const a=document.createElement(this.__tag);1!==this.__start&&a.setAttribute("start",String(this.__start));H(a,c.theme,this);return a}updateDOM(c,a,b){if(c.__tag!==this.__tag)return!0;H(a,b.theme,this);return!1}canBeEmpty(){return!1}append(...c){for(let b=0;b<c.length;b++){var a=c[b];if(f.$isListItemNode(a))super.append(a);
24
- else{const d=f.$createListItemNode();I(a)?d.append(a):(a=k.$createTextNode(a.getTextContent()),d.append(a));super.append(d)}}return this}}
25
- function H(c,a,b){const d=[],e=[];a=a.list;if(void 0!==a){a:{var g=1;for(var h=b.getParent();null!=h;){if(f.$isListItemNode(h)){h=h.getParent();if(f.$isListNode(h)){g++;h=h.getParent();continue}p(2)}break a}}h=g%5;const l=a[b.__tag+(0===h?5:h)],m=a[b.__tag];let q;a=a.nested;void 0!==a&&a.list&&(q=a.list);void 0!==m&&d.push(m);if(void 0!==l)for(a=l.split(" "),d.push(...a),a=1;6>a;a++)a!==h&&e.push(b.__tag+a);void 0!==q&&(b=q.split(" "),1<g?d.push(...b):e.push(...b))}0<d.length&&z(c,...d);0<e.length&&
21
+ this.getNextSiblings();E(c)&&a.forEach(b=>b.markDirty());return super.insertBefore(c)}canInsertAfter(c){return E(c)}canReplaceWith(c){return E(c)}canMergeWith(c){return l.$isParagraphNode(c)||E(c)}}function C(c){var a=c.getParent();let b=1;null!=a&&(f.$isListNode(a)?b=a.__start:p(47));c=c.getPreviousSiblings();for(a=0;a<c.length;a++){const d=c[a];E(d)&&!f.$isListNode(d.getFirstChild())&&b++}return b}
22
+ function D(c,a,b){const d=[],e=[],g=(a=a.list)?a.listitem:void 0;if(a&&a.nested)var h=a.nested.listitem;void 0!==g&&(a=g.split(" "),d.push(...a));void 0!==h&&(h=h.split(" "),b.getChildren().some(k=>f.$isListNode(k))?d.push(...h):e.push(...h));0<d.length&&z(c,...d);0<e.length&&A(c,...e)}function F(){return new B}function E(c){return c instanceof B}
23
+ class G extends l.ElementNode{static getType(){return"list"}static clone(c){return new G(c.__tag,c.__start,c.__key)}constructor(c,a,b){super(b);this.__tag=c;this.__start=a}getTag(){return this.__tag}createDOM(c){const a=document.createElement(this.__tag);1!==this.__start&&a.setAttribute("start",String(this.__start));H(a,c.theme,this);return a}updateDOM(c,a,b){if(c.__tag!==this.__tag)return!0;H(a,b.theme,this);return!1}canBeEmpty(){return!1}append(...c){for(let b=0;b<c.length;b++){var a=c[b];if(f.$isListItemNode(a))super.append(a);
24
+ else{const d=f.$createListItemNode();I(a)?d.append(a):(a=l.$createTextNode(a.getTextContent()),d.append(a));super.append(d)}}return this}}
25
+ function H(c,a,b){const d=[],e=[];a=a.list;if(void 0!==a){a:{var g=1;for(var h=b.getParent();null!=h;){if(f.$isListItemNode(h)){h=h.getParent();if(f.$isListNode(h)){g++;h=h.getParent();continue}p(2)}break a}}h=g%5;const k=a[b.__tag+(0===h?5:h)],m=a[b.__tag];let q;a=a.nested;void 0!==a&&a.list&&(q=a.list);void 0!==m&&d.push(m);if(void 0!==k)for(a=k.split(" "),d.push(...a),a=1;6>a;a++)a!==h&&e.push(b.__tag+a);void 0!==q&&(b=q.split(" "),1<g?d.push(...b):e.push(...b))}0<d.length&&z(c,...d);0<e.length&&
26
26
  A(c,...e)}function I(c){return c instanceof G}exports.$createListItemNode=F;exports.$createListNode=function(c,a=1){return new G(c,a)};exports.$isListItemNode=E;exports.$isListNode=I;exports.ListItemNode=B;exports.ListNode=G;exports.indentList=function(){return y("indent")};
27
- exports.insertList=function(c,a){c.update(()=>{k.$log("formatList");var b=k.$getSelection();if(null!==b){var d=b.getNodes();b=b.anchor.getNode();var e=b.getParent();if(0===d.length)d=f.$createListNode(a),k.$isRootNode(e)?(b.replace(d),b=f.$createListItemNode(),d.append(b)):f.$isListItemNode(b)&&(b=b.getParentOrThrow(),d.append(...b.getChildren()),b.replace(d));else for(b=new Set,e=0;e<d.length;e++){var g=d[e];if(k.$isElementNode(g)&&g.isEmpty()&&!b.has(g.getKey()))v(g,a);else if(k.$isLeafNode(g))for(g=
28
- g.getParent();null!=g;){const l=g.getKey();if(f.$isListNode(g)){if(!b.has(l)){var h=f.$createListNode(a);h.append(...g.getChildren());g.replace(h);b.add(l)}break}else{h=g.getParent();if(k.$isRootNode(h)&&!b.has(l)){b.add(l);v(g,a);break}g=h}}}}})};exports.outdentList=function(){return y("outdent")};
29
- exports.removeList=function(c){c.update(()=>{k.$log("removeList");var a=k.$getSelection();if(null!==a){const d=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&f.$isListItemNode(a))d.add(r(a));else for(a=0;a<e.length;a++){var b=e[a];k.$isLeafNode(b)&&(b=n(b,f.ListItemNode),null!=b&&d.add(r(b)))}d.forEach(g=>{let h=g;t(g).forEach(l=>{if(null!=l){const m=k.$createParagraphNode();m.append(...l.getChildren());h.insertAfter(m);h=m;l.remove()}});g.remove()})}})};
27
+ exports.insertList=function(c,a){c.update(()=>{var b=l.$getSelection();if(null!==b){var d=b.getNodes();b=b.anchor.getNode();var e=b.getParent();if(0===d.length)d=f.$createListNode(a),l.$isRootNode(e)?(b.replace(d),b=f.$createListItemNode(),d.append(b)):f.$isListItemNode(b)&&(b=b.getParentOrThrow(),d.append(...b.getChildren()),b.replace(d));else for(b=new Set,e=0;e<d.length;e++){var g=d[e];if(l.$isElementNode(g)&&g.isEmpty()&&!b.has(g.getKey()))v(g,a);else if(l.$isLeafNode(g))for(g=g.getParent();null!=
28
+ g;){const k=g.getKey();if(f.$isListNode(g)){if(!b.has(k)){var h=f.$createListNode(a);h.append(...g.getChildren());g.replace(h);b.add(k)}break}else{h=g.getParent();if(l.$isRootNode(h)&&!b.has(k)){b.add(k);v(g,a);break}g=h}}}}})};exports.outdentList=function(){return y("outdent")};
29
+ exports.removeList=function(c){c.update(()=>{var a=l.$getSelection();if(null!==a){const d=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&f.$isListItemNode(a))d.add(r(a));else for(a=0;a<e.length;a++){var b=e[a];l.$isLeafNode(b)&&(b=n(b,f.ListItemNode),null!=b&&d.add(r(b)))}d.forEach(g=>{let h=g;t(g).forEach(k=>{if(null!=k){const m=l.$createParagraphNode();m.append(...k.getChildren());h.insertAfter(m);h=m;k.remove()}});g.remove()})}})};
package/package.json CHANGED
@@ -12,10 +12,10 @@
12
12
  "list"
13
13
  ],
14
14
  "license": "MIT",
15
- "version": "0.1.8",
15
+ "version": "0.1.9",
16
16
  "main": "LexicalList.js",
17
17
  "peerDependencies": {
18
- "lexical": "0.1.8"
18
+ "lexical": "0.1.9"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",