@lexical/list 0.26.0 → 0.27.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.
@@ -19,6 +19,11 @@ var lexical = require('lexical');
19
19
  *
20
20
  */
21
21
 
22
+ // Do not require this module directly! Use normal `invariant` calls.
23
+
24
+ function formatDevErrorMessage(message) {
25
+ throw new Error(message);
26
+ }
22
27
 
23
28
  /**
24
29
  * Checks the depth of listNode from the root node.
@@ -37,7 +42,7 @@ function $getListDepth(listNode) {
37
42
  continue;
38
43
  }
39
44
  {
40
- throw Error(`A ListItemNode must have a ListNode for a parent.`);
45
+ formatDevErrorMessage(`A ListItemNode must have a ListNode for a parent.`);
41
46
  }
42
47
  }
43
48
  return depth;
@@ -54,7 +59,7 @@ function $getTopListNode(listItem) {
54
59
  let list = listItem.getParent();
55
60
  if (!$isListNode(list)) {
56
61
  {
57
- throw Error(`A ListItemNode must have a ListNode for a parent.`);
62
+ formatDevErrorMessage(`A ListItemNode must have a ListNode for a parent.`);
58
63
  }
59
64
  }
60
65
  let parent = list;
@@ -133,14 +138,6 @@ function $wrapInListItem(node) {
133
138
  return listItemWrapper.append(node);
134
139
  }
135
140
 
136
- /**
137
- * Copyright (c) Meta Platforms, Inc. and affiliates.
138
- *
139
- * This source code is licensed under the MIT license found in the
140
- * LICENSE file in the root directory of this source tree.
141
- *
142
- */
143
-
144
141
  function $isSelectingEmptyListItem(anchorNode, nodes) {
145
142
  return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
146
143
  }
@@ -161,7 +158,7 @@ function $insertList(listType) {
161
158
  if (lexical.$isRangeSelection(selection)) {
162
159
  const anchorAndFocus = selection.getStartEndPoints();
163
160
  if (!(anchorAndFocus !== null)) {
164
- throw Error(`insertList: anchor should be defined`);
161
+ formatDevErrorMessage(`insertList: anchor should be defined`);
165
162
  }
166
163
  const [anchor] = anchorAndFocus;
167
164
  const anchorNode = anchor.getNode();
@@ -511,7 +508,7 @@ function $handleListInsertParagraph() {
511
508
  const topListNode = $getTopListNode(anchor);
512
509
  const parent = anchor.getParent();
513
510
  if (!$isListNode(parent)) {
514
- throw Error(`A ListItemNode must have a ListNode for a parent.`);
511
+ formatDevErrorMessage(`A ListItemNode must have a ListNode for a parent.`);
515
512
  }
516
513
  const grandparent = parent.getParent();
517
514
  let replacementNode;
@@ -563,14 +560,6 @@ function normalizeClassNames(...classNames) {
563
560
  return rval;
564
561
  }
565
562
 
566
- /**
567
- * Copyright (c) Meta Platforms, Inc. and affiliates.
568
- *
569
- * This source code is licensed under the MIT license found in the
570
- * LICENSE file in the root directory of this source tree.
571
- *
572
- */
573
-
574
563
  /** @noInheritDoc */
575
564
  class ListItemNode extends lexical.ElementNode {
576
565
  /** @internal */
@@ -623,7 +612,7 @@ class ListItemNode extends lexical.ElementNode {
623
612
  static transform() {
624
613
  return node => {
625
614
  if (!$isListItemNode(node)) {
626
- throw Error(`node is not a ListItemNode`);
615
+ formatDevErrorMessage(`node is not a ListItemNode`);
627
616
  }
628
617
  if (node.__checked == null) {
629
618
  return;
@@ -704,7 +693,7 @@ class ListItemNode extends lexical.ElementNode {
704
693
  }
705
694
  if (includeChildren) {
706
695
  if (!lexical.$isElementNode(replaceWithNode)) {
707
- throw Error(`includeChildren should only be true for ElementNodes`);
696
+ formatDevErrorMessage(`includeChildren should only be true for ElementNodes`);
708
697
  }
709
698
  this.getChildren().forEach(child => {
710
699
  replaceWithNode.append(child);
@@ -720,7 +709,7 @@ class ListItemNode extends lexical.ElementNode {
720
709
  const listNode = this.getParentOrThrow();
721
710
  if (!$isListNode(listNode)) {
722
711
  {
723
- throw Error(`insertAfter: list node is not parent of list item node`);
712
+ formatDevErrorMessage(`insertAfter: list node is not parent of list item node`);
724
713
  }
725
714
  }
726
715
  if ($isListItemNode(node)) {
@@ -829,11 +818,11 @@ class ListItemNode extends lexical.ElementNode {
829
818
  }
830
819
  setIndent(indent) {
831
820
  if (!(typeof indent === 'number')) {
832
- throw Error(`Invalid indent value.`);
821
+ formatDevErrorMessage(`Invalid indent value.`);
833
822
  }
834
823
  indent = Math.floor(indent);
835
824
  if (!(indent >= 0)) {
836
- throw Error(`Indent value must be non-negative.`);
825
+ formatDevErrorMessage(`Indent value must be non-negative.`);
837
826
  }
838
827
  let currentIndent = this.getIndent();
839
828
  while (currentIndent !== indent) {
@@ -979,14 +968,6 @@ function $isListItemNode(node) {
979
968
  return node instanceof ListItemNode;
980
969
  }
981
970
 
982
- /**
983
- * Copyright (c) Meta Platforms, Inc. and affiliates.
984
- *
985
- * This source code is licensed under the MIT license found in the
986
- * LICENSE file in the root directory of this source tree.
987
- *
988
- */
989
-
990
971
  /** @noInheritDoc */
991
972
  class ListNode extends lexical.ElementNode {
992
973
  /** @internal */
@@ -1053,7 +1034,7 @@ class ListNode extends lexical.ElementNode {
1053
1034
  static transform() {
1054
1035
  return node => {
1055
1036
  if (!$isListNode(node)) {
1056
- throw Error(`node is not a ListNode`);
1037
+ formatDevErrorMessage(`node is not a ListNode`);
1057
1038
  }
1058
1039
  mergeNextSiblingListIfSameType(node);
1059
1040
  updateChildrenListItemValue(node);
@@ -17,6 +17,11 @@ import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, $createParagraph
17
17
  *
18
18
  */
19
19
 
20
+ // Do not require this module directly! Use normal `invariant` calls.
21
+
22
+ function formatDevErrorMessage(message) {
23
+ throw new Error(message);
24
+ }
20
25
 
21
26
  /**
22
27
  * Checks the depth of listNode from the root node.
@@ -35,7 +40,7 @@ function $getListDepth(listNode) {
35
40
  continue;
36
41
  }
37
42
  {
38
- throw Error(`A ListItemNode must have a ListNode for a parent.`);
43
+ formatDevErrorMessage(`A ListItemNode must have a ListNode for a parent.`);
39
44
  }
40
45
  }
41
46
  return depth;
@@ -52,7 +57,7 @@ function $getTopListNode(listItem) {
52
57
  let list = listItem.getParent();
53
58
  if (!$isListNode(list)) {
54
59
  {
55
- throw Error(`A ListItemNode must have a ListNode for a parent.`);
60
+ formatDevErrorMessage(`A ListItemNode must have a ListNode for a parent.`);
56
61
  }
57
62
  }
58
63
  let parent = list;
@@ -131,14 +136,6 @@ function $wrapInListItem(node) {
131
136
  return listItemWrapper.append(node);
132
137
  }
133
138
 
134
- /**
135
- * Copyright (c) Meta Platforms, Inc. and affiliates.
136
- *
137
- * This source code is licensed under the MIT license found in the
138
- * LICENSE file in the root directory of this source tree.
139
- *
140
- */
141
-
142
139
  function $isSelectingEmptyListItem(anchorNode, nodes) {
143
140
  return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
144
141
  }
@@ -159,7 +156,7 @@ function $insertList(listType) {
159
156
  if ($isRangeSelection(selection)) {
160
157
  const anchorAndFocus = selection.getStartEndPoints();
161
158
  if (!(anchorAndFocus !== null)) {
162
- throw Error(`insertList: anchor should be defined`);
159
+ formatDevErrorMessage(`insertList: anchor should be defined`);
163
160
  }
164
161
  const [anchor] = anchorAndFocus;
165
162
  const anchorNode = anchor.getNode();
@@ -509,7 +506,7 @@ function $handleListInsertParagraph() {
509
506
  const topListNode = $getTopListNode(anchor);
510
507
  const parent = anchor.getParent();
511
508
  if (!$isListNode(parent)) {
512
- throw Error(`A ListItemNode must have a ListNode for a parent.`);
509
+ formatDevErrorMessage(`A ListItemNode must have a ListNode for a parent.`);
513
510
  }
514
511
  const grandparent = parent.getParent();
515
512
  let replacementNode;
@@ -561,14 +558,6 @@ function normalizeClassNames(...classNames) {
561
558
  return rval;
562
559
  }
563
560
 
564
- /**
565
- * Copyright (c) Meta Platforms, Inc. and affiliates.
566
- *
567
- * This source code is licensed under the MIT license found in the
568
- * LICENSE file in the root directory of this source tree.
569
- *
570
- */
571
-
572
561
  /** @noInheritDoc */
573
562
  class ListItemNode extends ElementNode {
574
563
  /** @internal */
@@ -621,7 +610,7 @@ class ListItemNode extends ElementNode {
621
610
  static transform() {
622
611
  return node => {
623
612
  if (!$isListItemNode(node)) {
624
- throw Error(`node is not a ListItemNode`);
613
+ formatDevErrorMessage(`node is not a ListItemNode`);
625
614
  }
626
615
  if (node.__checked == null) {
627
616
  return;
@@ -702,7 +691,7 @@ class ListItemNode extends ElementNode {
702
691
  }
703
692
  if (includeChildren) {
704
693
  if (!$isElementNode(replaceWithNode)) {
705
- throw Error(`includeChildren should only be true for ElementNodes`);
694
+ formatDevErrorMessage(`includeChildren should only be true for ElementNodes`);
706
695
  }
707
696
  this.getChildren().forEach(child => {
708
697
  replaceWithNode.append(child);
@@ -718,7 +707,7 @@ class ListItemNode extends ElementNode {
718
707
  const listNode = this.getParentOrThrow();
719
708
  if (!$isListNode(listNode)) {
720
709
  {
721
- throw Error(`insertAfter: list node is not parent of list item node`);
710
+ formatDevErrorMessage(`insertAfter: list node is not parent of list item node`);
722
711
  }
723
712
  }
724
713
  if ($isListItemNode(node)) {
@@ -827,11 +816,11 @@ class ListItemNode extends ElementNode {
827
816
  }
828
817
  setIndent(indent) {
829
818
  if (!(typeof indent === 'number')) {
830
- throw Error(`Invalid indent value.`);
819
+ formatDevErrorMessage(`Invalid indent value.`);
831
820
  }
832
821
  indent = Math.floor(indent);
833
822
  if (!(indent >= 0)) {
834
- throw Error(`Indent value must be non-negative.`);
823
+ formatDevErrorMessage(`Indent value must be non-negative.`);
835
824
  }
836
825
  let currentIndent = this.getIndent();
837
826
  while (currentIndent !== indent) {
@@ -977,14 +966,6 @@ function $isListItemNode(node) {
977
966
  return node instanceof ListItemNode;
978
967
  }
979
968
 
980
- /**
981
- * Copyright (c) Meta Platforms, Inc. and affiliates.
982
- *
983
- * This source code is licensed under the MIT license found in the
984
- * LICENSE file in the root directory of this source tree.
985
- *
986
- */
987
-
988
969
  /** @noInheritDoc */
989
970
  class ListNode extends ElementNode {
990
971
  /** @internal */
@@ -1051,7 +1032,7 @@ class ListNode extends ElementNode {
1051
1032
  static transform() {
1052
1033
  return node => {
1053
1034
  if (!$isListNode(node)) {
1054
- throw Error(`node is not a ListNode`);
1035
+ formatDevErrorMessage(`node is not a ListNode`);
1055
1036
  }
1056
1037
  mergeNextSiblingListIfSameType(node);
1057
1038
  updateChildrenListItemValue(node);
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/utils"),t=require("lexical");function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n=r((function(e){const t=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(let e=1;e<arguments.length;e++)r.append("v",arguments[e]);throw t.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function s(e){let t=1,r=e.getParent();for(;null!=r;){if(O(r)){const e=r.getParent();if(F(e)){t++,r=e.getParent();continue}n(40)}return t}return t}function i(e){let t=e.getParent();F(t)||n(40);let r=t;for(;null!==r;)r=r.getParent(),F(r)&&(t=r);return t}function o(e){let t=[];const r=e.getChildren().filter(O);for(let e=0;e<r.length;e++){const n=r[e],s=n.getFirstChild();F(s)?t=t.concat(o(s)):t.push(n)}return t}function l(e){return O(e)&&F(e.getFirstChild())}function a(e){return v().append(e)}function c(e,t){return O(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function h(e){const r=t.$getSelection();if(null!==r){let s=r.getNodes();if(t.$isRangeSelection(r)){const i=r.getStartEndPoints();null===i&&n(143);const[o]=i,l=o.getNode(),a=l.getParent();if(t.$isRootOrShadowRoot(l)){const e=l.getFirstChild();if(e)s=e.selectStart().getNodes();else{const e=t.$createParagraphNode();l.append(e),s=e.select().getNodes()}}else if(c(l,s)){const r=E(e);if(t.$isRootOrShadowRoot(a)){l.replace(r);const e=v();t.$isElementNode(l)&&(e.setFormat(l.getFormatType()),e.setIndent(l.getIndent())),r.append(e)}else if(O(l)){const e=l.getParentOrThrow();g(r,e.getChildren()),e.replace(r)}return}}const i=new Set;for(let r=0;r<s.length;r++){const n=s[r];if(!t.$isElementNode(n)||!n.isEmpty()||O(n)||i.has(n.getKey())){if(t.$isLeafNode(n)){let r=n.getParent();for(;null!=r;){const n=r.getKey();if(F(r)){if(!i.has(n)){const t=E(e);g(t,r.getChildren()),r.replace(t),i.add(n)}break}{const s=r.getParent();if(t.$isRootOrShadowRoot(s)&&!i.has(n)){i.add(n),u(r,e);break}r=s}}}}else u(n,e)}}}function g(e,t){e.splice(e.getChildrenSize(),0,t)}function u(e,t){if(F(e))return e;const r=e.getPreviousSibling(),n=e.getNextSibling(),s=v();let i;if(g(s,e.getChildren()),F(r)&&t===r.getListType())r.append(s),F(n)&&t===n.getListType()&&(g(r,n.getChildren()),n.remove()),i=r;else if(F(n)&&t===n.getListType())n.getFirstChildOrThrow().insertBefore(s),i=n;else{const r=E(t);r.append(s),e.replace(r),i=r}return s.setFormat(e.getFormatType()),s.setIndent(e.getIndent()),e.remove(),i}function d(e,t){const r=e.getLastChild(),n=t.getFirstChild();r&&n&&l(r)&&l(n)&&(d(r.getFirstChild(),n.getFirstChild()),n.remove());const s=t.getChildren();s.length>0&&e.append(...s),t.remove()}function p(){const r=t.$getSelection();if(t.$isRangeSelection(r)){const n=new Set,s=r.getNodes(),l=r.anchor.getNode();if(c(l,s))n.add(i(l));else for(let r=0;r<s.length;r++){const o=s[r];if(t.$isLeafNode(o)){const t=e.$getNearestNodeOfType(o,C);null!=t&&n.add(i(t))}}for(const e of n){let n=e;const s=o(e);for(const e of s){const s=t.$createParagraphNode().setTextStyle(r.style).setTextFormat(r.format);g(s,e.getChildren()),n.insertAfter(s),n=s,e.__key===r.anchor.key&&t.$setPointFromCaret(r.anchor,t.$normalizeCaret(t.$getChildCaret(s,"next"))),e.__key===r.focus.key&&t.$setPointFromCaret(r.focus,t.$normalizeCaret(t.$getChildCaret(s,"next"))),e.remove()}e.remove()}}}function f(e){const t=new Set;if(l(e)||t.has(e.getKey()))return;const r=e.getParent(),n=e.getNextSibling(),s=e.getPreviousSibling();if(l(n)&&l(s)){const r=s.getFirstChild();if(F(r)){r.append(e);const s=n.getFirstChild();if(F(s)){g(r,s.getChildren()),n.remove(),t.add(n.getKey())}}}else if(l(n)){const t=n.getFirstChild();if(F(t)){const r=t.getFirstChild();null!==r&&r.insertBefore(e)}}else if(l(s)){const t=s.getFirstChild();F(t)&&t.append(e)}else if(F(r)){const t=v().setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle()),i=E(r.getListType()).setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle());t.append(i),i.append(e),s?s.insertAfter(t):n?n.insertBefore(t):r.append(t)}}function m(e){if(l(e))return;const t=e.getParent(),r=t?t.getParent():void 0;if(F(r?r.getParent():void 0)&&O(r)&&F(t)){const n=t?t.getFirstChild():void 0,s=t?t.getLastChild():void 0;if(e.is(n))r.insertBefore(e),t.isEmpty()&&r.remove();else if(e.is(s))r.insertAfter(e),t.isEmpty()&&r.remove();else{const n=t.getListType(),s=v(),i=E(n);s.append(i),e.getPreviousSiblings().forEach((e=>i.append(e)));const o=v(),l=E(n);o.append(l),g(l,e.getNextSiblings()),r.insertBefore(s),r.insertAfter(o),r.replace(e)}}}function _(){const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed())return!1;const r=e.anchor.getNode();if(!O(r)||0!==r.getChildrenSize())return!1;const s=i(r),o=r.getParent();F(o)||n(40);const l=o.getParent();let a;if(t.$isRootOrShadowRoot(l))a=t.$createParagraphNode(),s.insertAfter(a);else{if(!O(l))return!1;a=v(),l.insertAfter(a)}a.setTextStyle(e.style).setTextFormat(e.format).select();const c=r.getNextSiblings();if(c.length>0){const e=E(o.getListType());if(O(a)){const t=v();t.append(e),a.insertAfter(t)}else a.insertAfter(e);e.append(...c)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!O(e)&&!F(e))break;t=e}t.remove()}(r),!0}function T(...e){const t=[];for(const r of e)if(r&&"string"==typeof r)for(const[e]of r.matchAll(/\S+/g))t.push(e);return t}class C extends t.ElementNode{static getType(){return"listitem"}static clone(e){return new C(e.__value,e.__checked,e.__key)}constructor(e,t,r){super(r),this.__value=void 0===e?1:e,this.__checked=t}createDOM(e){const t=document.createElement("li"),r=this.getParent();F(r)&&"check"===r.getListType()&&y(t,this,null),t.value=this.__value,N(t,e.theme,this);const n=this.__style||this.__textStyle;return n&&(t.style.cssText=n),t}updateDOM(e,t,r){const n=this.getParent();F(n)&&"check"===n.getListType()&&y(t,this,e),t.value=this.__value,N(t,r.theme,this);const s=e.__style||e.__textStyle,i=this.__style||this.__textStyle;return s!==i&&(t.style.cssText=i,""===i&&t.removeAttribute("style")),!1}static transform(){return e=>{if(O(e)||n(144),null==e.__checked)return;const t=e.getParent();F(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)}}static importDOM(){return{li:()=>({conversion:S,priority:0})}}static importJSON(e){return v().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let r=0;r<e.length;r++){const n=e[r];if(t.$isElementNode(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,r){if(O(e))return super.replace(e);this.setIndent(0);const s=this.getParentOrThrow();if(!F(s))return e;if(s.__first===this.getKey())s.insertBefore(e);else if(s.__last===this.getKey())s.insertAfter(e);else{const t=E(s.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}s.insertAfter(e),e.insertAfter(t)}return r&&(t.$isElementNode(e)||n(139),this.getChildren().forEach((t=>{e.append(t)}))),this.remove(),0===s.getChildrenSize()&&s.remove(),e}insertAfter(e,t=!0){const r=this.getParentOrThrow();if(F(r)||n(39),O(e))return super.insertAfter(e,t);const s=this.getNextSiblings();if(r.insertAfter(e,t),0!==s.length){const n=E(r.getListType());s.forEach((e=>n.append(e))),e.insertAfter(n,t)}return e}remove(e){const t=this.getPreviousSibling(),r=this.getNextSibling();super.remove(e),t&&r&&l(t)&&l(r)&&(d(t.getFirstChild(),r.getFirstChild()),r.remove())}insertNewAfter(e,t=!0){const r=v().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(r,t),r}collapseAtStart(e){const r=t.$createParagraphNode();this.getChildren().forEach((e=>r.append(e)));const n=this.getParentOrThrow(),s=n.getParentOrThrow(),i=O(s);if(1===n.getChildrenSize())if(i)n.remove(),s.select();else{n.insertBefore(r),n.remove();const t=e.anchor,s=e.focus,i=r.getKey();"element"===t.type&&t.getNode().is(this)&&t.set(i,t.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else n.insertBefore(r),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const r=this.getParent();return F(r)&&(t=r.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),r=0;for(;O(t);)t=t.getParentOrThrow().getParentOrThrow(),r++;return r}setIndent(e){"number"!=typeof e&&n(117),(e=Math.floor(e))>=0||n(199);let t=this.getIndent();for(;t!==e;)t<e?(f(this),t++):(m(this),t--);return this}canInsertAfter(e){return O(e)}canReplaceWith(e){return O(e)}canMergeWith(e){return O(e)||t.$isParagraphNode(e)}extractWithChild(e,r){if(!t.$isRangeSelection(r))return!1;const n=r.anchor.getNode(),s=r.focus.getNode();return this.isParentOf(n)&&this.isParentOf(s)&&this.getTextContent().length===r.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return E("bullet")}canMergeWhenEmpty(){return!0}}function N(t,r,n){const s=[],i=[],o=r.list,l=o?o.listitem:void 0;let a;if(o&&o.nested&&(a=o.nested.listitem),void 0!==l&&s.push(...T(l)),o){const e=n.getParent(),t=F(e)&&"check"===e.getListType(),r=n.getChecked();t&&!r||i.push(o.listitemUnchecked),t&&r||i.push(o.listitemChecked),t&&s.push(r?o.listitemChecked:o.listitemUnchecked)}if(void 0!==a){const e=T(a);n.getChildren().some((e=>F(e)))?s.push(...e):i.push(...e)}i.length>0&&e.removeClassNamesFromElement(t,...i),s.length>0&&e.addClassNamesToElement(t,...s)}function y(e,t,r,n){F(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),r&&t.__checked===r.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}function S(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return x(t);const t=e.getAttribute("aria-checked");return{node:v("true"===t||"false"!==t&&void 0)}}function x(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:v(e.hasAttribute("checked"))}}function v(e){return t.$applyNodeReplacement(new C(void 0,e))}function O(e){return e instanceof C}class L extends t.ElementNode{static getType(){return"list"}static clone(e){const t=e.__listType||A[e.__tag];return new L(t,e.__start,e.__key)}constructor(e="number",t=1,r){super(r);const n=A[e]||e;this.__listType=n,this.__tag="number"===n?"ol":"ul",this.__start=t}getTag(){return this.__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.__listType}getStart(){return this.__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const r=this.__tag,n=document.createElement(r);return 1!==this.__start&&n.setAttribute("start",String(this.__start)),n.__lexicalListType=this.__listType,k(n,e.theme,this),n}updateDOM(e,t,r){return e.__tag!==this.__tag||(k(t,r.theme,this),!1)}static transform(){return e=>{F(e)||n(163),function(e){const t=e.getNextSibling();F(t)&&e.getListType()===t.getListType()&&d(e,t)}(e),function(e){const t="check"!==e.getListType();let r=e.getStart();for(const n of e.getChildren())O(n)&&(n.getValue()!==r&&n.setValue(r),t&&null!=n.getLatest().__checked&&n.setChecked(void 0),F(n.getFirstChild())||r++)}(e)}}static importDOM(){return{ol:()=>({conversion:b,priority:0}),ul:()=>({conversion:b,priority:0})}}static importJSON(e){return E().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(t){const r=this.createDOM(t._config,t);return e.isHTMLElement(r)&&(1!==this.__start&&r.setAttribute("start",String(this.__start)),"check"===this.__listType&&r.setAttribute("__lexicalListType","check")),{element:r}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let r=0;r<e.length;r++){const n=e[r];if(O(n))super.append(n);else{const e=v();if(F(n))e.append(n);else if(t.$isElementNode(n))if(n.isInline())e.append(n);else{const r=t.$createTextNode(n.getTextContent());e.append(r)}else e.append(n);super.append(e)}}return this}extractWithChild(e){return O(e)}}function k(t,r,n){const i=[],o=[],l=r.list;if(void 0!==l){const e=l[`${n.__tag}Depth`]||[],t=s(n)-1,r=t%e.length,a=e[r],c=l[n.__tag];let h;const g=l.nested,u=l.checklist;if(void 0!==g&&g.list&&(h=g.list),void 0!==c&&i.push(c),void 0!==u&&"check"===n.__listType&&i.push(u),void 0!==a){i.push(...T(a));for(let t=0;t<e.length;t++)t!==r&&o.push(n.__tag+t)}if(void 0!==h){const e=T(h);t>1?i.push(...e):o.push(...e)}}o.length>0&&e.removeClassNamesFromElement(t,...o),i.length>0&&e.addClassNamesToElement(t,...i)}function P(e){const t=[];for(let r=0;r<e.length;r++){const n=e[r];if(O(n)){t.push(n);const e=n.getChildren();e.length>1&&e.forEach((e=>{F(e)&&t.push(a(e))}))}else t.push(a(n))}return t}function b(t){const r=t.nodeName.toLowerCase();let n=null;if("ol"===r){n=E("number",t.start)}else"ul"===r&&(n=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list"))return!0;for(const r of t.childNodes)if(e.isHTMLElement(r)&&r.hasAttribute("aria-checked"))return!0;return!1}(t)?E("check"):E("bullet"));return{after:P,node:n}}const A={ol:"number",ul:"bullet"};function E(e="number",r=1){return t.$applyNodeReplacement(new L(e,r))}function F(e){return e instanceof L}const R=t.createCommand("INSERT_UNORDERED_LIST_COMMAND"),$=t.createCommand("INSERT_ORDERED_LIST_COMMAND"),M=t.createCommand("INSERT_CHECK_LIST_COMMAND"),I=t.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=v,exports.$createListNode=E,exports.$getListDepth=s,exports.$handleListInsertParagraph=_,exports.$insertList=h,exports.$isListItemNode=O,exports.$isListNode=F,exports.$removeList=p,exports.INSERT_CHECK_LIST_COMMAND=M,exports.INSERT_ORDERED_LIST_COMMAND=$,exports.INSERT_UNORDERED_LIST_COMMAND=R,exports.ListItemNode=C,exports.ListNode=L,exports.REMOVE_LIST_COMMAND=I,exports.insertList=function(e,t){e.update((()=>h(t)))},exports.registerList=function(r){return e.mergeRegister(r.registerCommand($,(()=>(h("number"),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(R,(()=>(h("bullet"),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(I,(()=>(p(),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INSERT_PARAGRAPH_COMMAND,(()=>_()),t.COMMAND_PRIORITY_LOW),r.registerNodeTransform(C,(e=>{const r=e.getFirstChild();if(r){if(t.$isTextNode(r)){const t=r.getStyle(),n=r.getFormat();e.getTextStyle()!==t&&e.setTextStyle(t),e.getTextFormat()!==n&&e.setTextFormat(n)}}else{const r=t.$getSelection();t.$isRangeSelection(r)&&(r.style!==e.getTextStyle()||r.format!==e.getTextFormat())&&r.isCollapsed()&&e.is(r.anchor.getNode())&&e.setTextStyle(r.style).setTextFormat(r.format)}})),r.registerNodeTransform(t.TextNode,(e=>{const t=e.getParent();if(O(t)&&e.is(t.getFirstChild())){const r=e.getStyle(),n=e.getFormat();r===t.getTextStyle()&&n===t.getTextFormat()||t.setTextStyle(r).setTextFormat(n)}})))},exports.removeList=function(e){e.update((()=>p()))};
9
+ "use strict";var e=require("@lexical/utils"),t=require("lexical");function r(e,...t){const r=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(const e of t)n.append("v",e);throw r.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function n(e){let t=1,n=e.getParent();for(;null!=n;){if(v(n)){const e=n.getParent();if(E(e)){t++,n=e.getParent();continue}r(40)}return t}return t}function s(e){let t=e.getParent();E(t)||r(40);let n=t;for(;null!==n;)n=n.getParent(),E(n)&&(t=n);return t}function i(e){let t=[];const r=e.getChildren().filter(v);for(let e=0;e<r.length;e++){const n=r[e],s=n.getFirstChild();E(s)?t=t.concat(i(s)):t.push(n)}return t}function o(e){return v(e)&&E(e.getFirstChild())}function l(e){return x().append(e)}function a(e,t){return v(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function c(e){const n=t.$getSelection();if(null!==n){let s=n.getNodes();if(t.$isRangeSelection(n)){const i=n.getStartEndPoints();null===i&&r(143);const[o]=i,l=o.getNode(),c=l.getParent();if(t.$isRootOrShadowRoot(l)){const e=l.getFirstChild();if(e)s=e.selectStart().getNodes();else{const e=t.$createParagraphNode();l.append(e),s=e.select().getNodes()}}else if(a(l,s)){const r=A(e);if(t.$isRootOrShadowRoot(c)){l.replace(r);const e=x();t.$isElementNode(l)&&(e.setFormat(l.getFormatType()),e.setIndent(l.getIndent())),r.append(e)}else if(v(l)){const e=l.getParentOrThrow();h(r,e.getChildren()),e.replace(r)}return}}const i=new Set;for(let r=0;r<s.length;r++){const n=s[r];if(!t.$isElementNode(n)||!n.isEmpty()||v(n)||i.has(n.getKey())){if(t.$isLeafNode(n)){let r=n.getParent();for(;null!=r;){const n=r.getKey();if(E(r)){if(!i.has(n)){const t=A(e);h(t,r.getChildren()),r.replace(t),i.add(n)}break}{const s=r.getParent();if(t.$isRootOrShadowRoot(s)&&!i.has(n)){i.add(n),g(r,e);break}r=s}}}}else g(n,e)}}}function h(e,t){e.splice(e.getChildrenSize(),0,t)}function g(e,t){if(E(e))return e;const r=e.getPreviousSibling(),n=e.getNextSibling(),s=x();let i;if(h(s,e.getChildren()),E(r)&&t===r.getListType())r.append(s),E(n)&&t===n.getListType()&&(h(r,n.getChildren()),n.remove()),i=r;else if(E(n)&&t===n.getListType())n.getFirstChildOrThrow().insertBefore(s),i=n;else{const r=A(t);r.append(s),e.replace(r),i=r}return s.setFormat(e.getFormatType()),s.setIndent(e.getIndent()),e.remove(),i}function d(e,t){const r=e.getLastChild(),n=t.getFirstChild();r&&n&&o(r)&&o(n)&&(d(r.getFirstChild(),n.getFirstChild()),n.remove());const s=t.getChildren();s.length>0&&e.append(...s),t.remove()}function u(){const r=t.$getSelection();if(t.$isRangeSelection(r)){const n=new Set,o=r.getNodes(),l=r.anchor.getNode();if(a(l,o))n.add(s(l));else for(let r=0;r<o.length;r++){const i=o[r];if(t.$isLeafNode(i)){const t=e.$getNearestNodeOfType(i,T);null!=t&&n.add(s(t))}}for(const e of n){let n=e;const s=i(e);for(const e of s){const s=t.$createParagraphNode().setTextStyle(r.style).setTextFormat(r.format);h(s,e.getChildren()),n.insertAfter(s),n=s,e.__key===r.anchor.key&&t.$setPointFromCaret(r.anchor,t.$normalizeCaret(t.$getChildCaret(s,"next"))),e.__key===r.focus.key&&t.$setPointFromCaret(r.focus,t.$normalizeCaret(t.$getChildCaret(s,"next"))),e.remove()}e.remove()}}}function p(e){const t=new Set;if(o(e)||t.has(e.getKey()))return;const r=e.getParent(),n=e.getNextSibling(),s=e.getPreviousSibling();if(o(n)&&o(s)){const r=s.getFirstChild();if(E(r)){r.append(e);const s=n.getFirstChild();if(E(s)){h(r,s.getChildren()),n.remove(),t.add(n.getKey())}}}else if(o(n)){const t=n.getFirstChild();if(E(t)){const r=t.getFirstChild();null!==r&&r.insertBefore(e)}}else if(o(s)){const t=s.getFirstChild();E(t)&&t.append(e)}else if(E(r)){const t=x().setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle()),i=A(r.getListType()).setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle());t.append(i),i.append(e),s?s.insertAfter(t):n?n.insertBefore(t):r.append(t)}}function f(e){if(o(e))return;const t=e.getParent(),r=t?t.getParent():void 0;if(E(r?r.getParent():void 0)&&v(r)&&E(t)){const n=t?t.getFirstChild():void 0,s=t?t.getLastChild():void 0;if(e.is(n))r.insertBefore(e),t.isEmpty()&&r.remove();else if(e.is(s))r.insertAfter(e),t.isEmpty()&&r.remove();else{const n=t.getListType(),s=x(),i=A(n);s.append(i),e.getPreviousSiblings().forEach((e=>i.append(e)));const o=x(),l=A(n);o.append(l),h(l,e.getNextSiblings()),r.insertBefore(s),r.insertAfter(o),r.replace(e)}}}function m(){const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed())return!1;const n=e.anchor.getNode();if(!v(n)||0!==n.getChildrenSize())return!1;const i=s(n),o=n.getParent();E(o)||r(40);const l=o.getParent();let a;if(t.$isRootOrShadowRoot(l))a=t.$createParagraphNode(),i.insertAfter(a);else{if(!v(l))return!1;a=x(),l.insertAfter(a)}a.setTextStyle(e.style).setTextFormat(e.format).select();const c=n.getNextSiblings();if(c.length>0){const e=A(o.getListType());if(v(a)){const t=x();t.append(e),a.insertAfter(t)}else a.insertAfter(e);e.append(...c)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!v(e)&&!E(e))break;t=e}t.remove()}(n),!0}function _(...e){const t=[];for(const r of e)if(r&&"string"==typeof r)for(const[e]of r.matchAll(/\S+/g))t.push(e);return t}class T extends t.ElementNode{static getType(){return"listitem"}static clone(e){return new T(e.__value,e.__checked,e.__key)}constructor(e,t,r){super(r),this.__value=void 0===e?1:e,this.__checked=t}createDOM(e){const t=document.createElement("li"),r=this.getParent();E(r)&&"check"===r.getListType()&&N(t,this,null),t.value=this.__value,C(t,e.theme,this);const n=this.__style||this.__textStyle;return n&&(t.style.cssText=n),t}updateDOM(e,t,r){const n=this.getParent();E(n)&&"check"===n.getListType()&&N(t,this,e),t.value=this.__value,C(t,r.theme,this);const s=e.__style||e.__textStyle,i=this.__style||this.__textStyle;return s!==i&&(t.style.cssText=i,""===i&&t.removeAttribute("style")),!1}static transform(){return e=>{if(v(e)||r(144),null==e.__checked)return;const t=e.getParent();E(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)}}static importDOM(){return{li:()=>({conversion:S,priority:0})}}static importJSON(e){return x().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let r=0;r<e.length;r++){const n=e[r];if(t.$isElementNode(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,n){if(v(e))return super.replace(e);this.setIndent(0);const s=this.getParentOrThrow();if(!E(s))return e;if(s.__first===this.getKey())s.insertBefore(e);else if(s.__last===this.getKey())s.insertAfter(e);else{const t=A(s.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}s.insertAfter(e),e.insertAfter(t)}return n&&(t.$isElementNode(e)||r(139),this.getChildren().forEach((t=>{e.append(t)}))),this.remove(),0===s.getChildrenSize()&&s.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if(E(n)||r(39),v(e))return super.insertAfter(e,t);const s=this.getNextSiblings();if(n.insertAfter(e,t),0!==s.length){const r=A(n.getListType());s.forEach((e=>r.append(e))),e.insertAfter(r,t)}return e}remove(e){const t=this.getPreviousSibling(),r=this.getNextSibling();super.remove(e),t&&r&&o(t)&&o(r)&&(d(t.getFirstChild(),r.getFirstChild()),r.remove())}insertNewAfter(e,t=!0){const r=x().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(r,t),r}collapseAtStart(e){const r=t.$createParagraphNode();this.getChildren().forEach((e=>r.append(e)));const n=this.getParentOrThrow(),s=n.getParentOrThrow(),i=v(s);if(1===n.getChildrenSize())if(i)n.remove(),s.select();else{n.insertBefore(r),n.remove();const t=e.anchor,s=e.focus,i=r.getKey();"element"===t.type&&t.getNode().is(this)&&t.set(i,t.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else n.insertBefore(r),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const r=this.getParent();return E(r)&&(t=r.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),r=0;for(;v(t);)t=t.getParentOrThrow().getParentOrThrow(),r++;return r}setIndent(e){"number"!=typeof e&&r(117),(e=Math.floor(e))>=0||r(199);let t=this.getIndent();for(;t!==e;)t<e?(p(this),t++):(f(this),t--);return this}canInsertAfter(e){return v(e)}canReplaceWith(e){return v(e)}canMergeWith(e){return v(e)||t.$isParagraphNode(e)}extractWithChild(e,r){if(!t.$isRangeSelection(r))return!1;const n=r.anchor.getNode(),s=r.focus.getNode();return this.isParentOf(n)&&this.isParentOf(s)&&this.getTextContent().length===r.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return A("bullet")}canMergeWhenEmpty(){return!0}}function C(t,r,n){const s=[],i=[],o=r.list,l=o?o.listitem:void 0;let a;if(o&&o.nested&&(a=o.nested.listitem),void 0!==l&&s.push(..._(l)),o){const e=n.getParent(),t=E(e)&&"check"===e.getListType(),r=n.getChecked();t&&!r||i.push(o.listitemUnchecked),t&&r||i.push(o.listitemChecked),t&&s.push(r?o.listitemChecked:o.listitemUnchecked)}if(void 0!==a){const e=_(a);n.getChildren().some((e=>E(e)))?s.push(...e):i.push(...e)}i.length>0&&e.removeClassNamesFromElement(t,...i),s.length>0&&e.addClassNamesToElement(t,...s)}function N(e,t,r,n){E(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),r&&t.__checked===r.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}function S(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return y(t);const t=e.getAttribute("aria-checked");return{node:x("true"===t||"false"!==t&&void 0)}}function y(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:x(e.hasAttribute("checked"))}}function x(e){return t.$applyNodeReplacement(new T(void 0,e))}function v(e){return e instanceof T}class O extends t.ElementNode{static getType(){return"list"}static clone(e){const t=e.__listType||b[e.__tag];return new O(t,e.__start,e.__key)}constructor(e="number",t=1,r){super(r);const n=b[e]||e;this.__listType=n,this.__tag="number"===n?"ol":"ul",this.__start=t}getTag(){return this.__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.__listType}getStart(){return this.__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const r=this.__tag,n=document.createElement(r);return 1!==this.__start&&n.setAttribute("start",String(this.__start)),n.__lexicalListType=this.__listType,L(n,e.theme,this),n}updateDOM(e,t,r){return e.__tag!==this.__tag||(L(t,r.theme,this),!1)}static transform(){return e=>{E(e)||r(163),function(e){const t=e.getNextSibling();E(t)&&e.getListType()===t.getListType()&&d(e,t)}(e),function(e){const t="check"!==e.getListType();let r=e.getStart();for(const n of e.getChildren())v(n)&&(n.getValue()!==r&&n.setValue(r),t&&null!=n.getLatest().__checked&&n.setChecked(void 0),E(n.getFirstChild())||r++)}(e)}}static importDOM(){return{ol:()=>({conversion:P,priority:0}),ul:()=>({conversion:P,priority:0})}}static importJSON(e){return A().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(t){const r=this.createDOM(t._config,t);return e.isHTMLElement(r)&&(1!==this.__start&&r.setAttribute("start",String(this.__start)),"check"===this.__listType&&r.setAttribute("__lexicalListType","check")),{element:r}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let r=0;r<e.length;r++){const n=e[r];if(v(n))super.append(n);else{const e=x();if(E(n))e.append(n);else if(t.$isElementNode(n))if(n.isInline())e.append(n);else{const r=t.$createTextNode(n.getTextContent());e.append(r)}else e.append(n);super.append(e)}}return this}extractWithChild(e){return v(e)}}function L(t,r,s){const i=[],o=[],l=r.list;if(void 0!==l){const e=l[`${s.__tag}Depth`]||[],t=n(s)-1,r=t%e.length,a=e[r],c=l[s.__tag];let h;const g=l.nested,d=l.checklist;if(void 0!==g&&g.list&&(h=g.list),void 0!==c&&i.push(c),void 0!==d&&"check"===s.__listType&&i.push(d),void 0!==a){i.push(..._(a));for(let t=0;t<e.length;t++)t!==r&&o.push(s.__tag+t)}if(void 0!==h){const e=_(h);t>1?i.push(...e):o.push(...e)}}o.length>0&&e.removeClassNamesFromElement(t,...o),i.length>0&&e.addClassNamesToElement(t,...i)}function k(e){const t=[];for(let r=0;r<e.length;r++){const n=e[r];if(v(n)){t.push(n);const e=n.getChildren();e.length>1&&e.forEach((e=>{E(e)&&t.push(l(e))}))}else t.push(l(n))}return t}function P(t){const r=t.nodeName.toLowerCase();let n=null;if("ol"===r){n=A("number",t.start)}else"ul"===r&&(n=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list"))return!0;for(const r of t.childNodes)if(e.isHTMLElement(r)&&r.hasAttribute("aria-checked"))return!0;return!1}(t)?A("check"):A("bullet"));return{after:k,node:n}}const b={ol:"number",ul:"bullet"};function A(e="number",r=1){return t.$applyNodeReplacement(new O(e,r))}function E(e){return e instanceof O}const F=t.createCommand("INSERT_UNORDERED_LIST_COMMAND"),R=t.createCommand("INSERT_ORDERED_LIST_COMMAND"),$=t.createCommand("INSERT_CHECK_LIST_COMMAND"),M=t.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=x,exports.$createListNode=A,exports.$getListDepth=n,exports.$handleListInsertParagraph=m,exports.$insertList=c,exports.$isListItemNode=v,exports.$isListNode=E,exports.$removeList=u,exports.INSERT_CHECK_LIST_COMMAND=$,exports.INSERT_ORDERED_LIST_COMMAND=R,exports.INSERT_UNORDERED_LIST_COMMAND=F,exports.ListItemNode=T,exports.ListNode=O,exports.REMOVE_LIST_COMMAND=M,exports.insertList=function(e,t){e.update((()=>c(t)))},exports.registerList=function(r){return e.mergeRegister(r.registerCommand(R,(()=>(c("number"),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(F,(()=>(c("bullet"),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(M,(()=>(u(),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INSERT_PARAGRAPH_COMMAND,(()=>m()),t.COMMAND_PRIORITY_LOW),r.registerNodeTransform(T,(e=>{const r=e.getFirstChild();if(r){if(t.$isTextNode(r)){const t=r.getStyle(),n=r.getFormat();e.getTextStyle()!==t&&e.setTextStyle(t),e.getTextFormat()!==n&&e.setTextFormat(n)}}else{const r=t.$getSelection();t.$isRangeSelection(r)&&(r.style!==e.getTextStyle()||r.format!==e.getTextFormat())&&r.isCollapsed()&&e.is(r.anchor.getNode())&&e.setTextStyle(r.style).setTextFormat(r.format)}})),r.registerNodeTransform(t.TextNode,(e=>{const t=e.getParent();if(v(t)&&e.is(t.getFirstChild())){const r=e.getStyle(),n=e.getFormat();r===t.getTextStyle()&&n===t.getTextFormat()||t.setTextStyle(r).setTextFormat(n)}})))},exports.removeList=function(e){e.update((()=>u()))};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{$getNearestNodeOfType as t,removeClassNamesFromElement as e,addClassNamesToElement as r,isHTMLElement as n,mergeRegister as s}from"@lexical/utils";import{$getSelection as i,$isRangeSelection as o,$isRootOrShadowRoot as l,$createParagraphNode as c,$isElementNode as a,$isLeafNode as h,$setPointFromCaret as u,$normalizeCaret as g,$getChildCaret as d,ElementNode as f,$isParagraphNode as p,$applyNodeReplacement as _,$createTextNode as m,createCommand as y,COMMAND_PRIORITY_LOW as T,INSERT_PARAGRAPH_COMMAND as S,$isTextNode as C,TextNode as x}from"lexical";function v(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var k=v((function(t){const e=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(let t=1;t<arguments.length;t++)r.append("v",arguments[t]);throw e.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${e.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function b(t){let e=1,r=t.getParent();for(;null!=r;){if(j(r)){const t=r.getParent();if(Z(t)){e++,r=t.getParent();continue}k(40)}return e}return e}function N(t){let e=t.getParent();Z(e)||k(40);let r=e;for(;null!==r;)r=r.getParent(),Z(r)&&(e=r);return e}function F(t){let e=[];const r=t.getChildren().filter(j);for(let t=0;t<r.length;t++){const n=r[t],s=n.getFirstChild();Z(s)?e=e.concat(F(s)):e.push(n)}return e}function O(t){return j(t)&&Z(t.getFirstChild())}function P(t){return $().append(t)}function A(t,e){return j(t)&&(0===e.length||1===e.length&&t.is(e[0])&&0===t.getChildrenSize())}function L(t){const e=i();if(null!==e){let r=e.getNodes();if(o(e)){const n=e.getStartEndPoints();null===n&&k(143);const[s]=n,i=s.getNode(),o=i.getParent();if(l(i)){const t=i.getFirstChild();if(t)r=t.selectStart().getNodes();else{const t=c();i.append(t),r=t.select().getNodes()}}else if(A(i,r)){const e=Y(t);if(l(o)){i.replace(e);const t=$();a(i)&&(t.setFormat(i.getFormatType()),t.setIndent(i.getIndent())),e.append(t)}else if(j(i)){const t=i.getParentOrThrow();E(e,t.getChildren()),t.replace(e)}return}}const n=new Set;for(let e=0;e<r.length;e++){const s=r[e];if(!a(s)||!s.isEmpty()||j(s)||n.has(s.getKey())){if(h(s)){let e=s.getParent();for(;null!=e;){const r=e.getKey();if(Z(e)){if(!n.has(r)){const s=Y(t);E(s,e.getChildren()),e.replace(s),n.add(r)}break}{const s=e.getParent();if(l(s)&&!n.has(r)){n.add(r),M(e,t);break}e=s}}}}else M(s,t)}}}function E(t,e){t.splice(t.getChildrenSize(),0,e)}function M(t,e){if(Z(t))return t;const r=t.getPreviousSibling(),n=t.getNextSibling(),s=$();let i;if(E(s,t.getChildren()),Z(r)&&e===r.getListType())r.append(s),Z(n)&&e===n.getListType()&&(E(r,n.getChildren()),n.remove()),i=r;else if(Z(n)&&e===n.getListType())n.getFirstChildOrThrow().insertBefore(s),i=n;else{const r=Y(e);r.append(s),t.replace(r),i=r}return s.setFormat(t.getFormatType()),s.setIndent(t.getIndent()),t.remove(),i}function w(t,e){const r=t.getLastChild(),n=e.getFirstChild();r&&n&&O(r)&&O(n)&&(w(r.getFirstChild(),n.getFirstChild()),n.remove());const s=e.getChildren();s.length>0&&t.append(...s),e.remove()}function I(){const e=i();if(o(e)){const r=new Set,n=e.getNodes(),s=e.anchor.getNode();if(A(s,n))r.add(N(s));else for(let e=0;e<n.length;e++){const s=n[e];if(h(s)){const e=t(s,B);null!=e&&r.add(N(e))}}for(const t of r){let r=t;const n=F(t);for(const t of n){const n=c().setTextStyle(e.style).setTextFormat(e.format);E(n,t.getChildren()),r.insertAfter(n),r=n,t.__key===e.anchor.key&&u(e.anchor,g(d(n,"next"))),t.__key===e.focus.key&&u(e.focus,g(d(n,"next"))),t.remove()}t.remove()}}}function D(t){const e=new Set;if(O(t)||e.has(t.getKey()))return;const r=t.getParent(),n=t.getNextSibling(),s=t.getPreviousSibling();if(O(n)&&O(s)){const r=s.getFirstChild();if(Z(r)){r.append(t);const s=n.getFirstChild();if(Z(s)){E(r,s.getChildren()),n.remove(),e.add(n.getKey())}}}else if(O(n)){const e=n.getFirstChild();if(Z(e)){const r=e.getFirstChild();null!==r&&r.insertBefore(t)}}else if(O(s)){const e=s.getFirstChild();Z(e)&&e.append(t)}else if(Z(r)){const e=$().setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle()),i=Y(r.getListType()).setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle());e.append(i),i.append(t),s?s.insertAfter(e):n?n.insertBefore(e):r.append(e)}}function J(t){if(O(t))return;const e=t.getParent(),r=e?e.getParent():void 0;if(Z(r?r.getParent():void 0)&&j(r)&&Z(e)){const n=e?e.getFirstChild():void 0,s=e?e.getLastChild():void 0;if(t.is(n))r.insertBefore(t),e.isEmpty()&&r.remove();else if(t.is(s))r.insertAfter(t),e.isEmpty()&&r.remove();else{const n=e.getListType(),s=$(),i=Y(n);s.append(i),t.getPreviousSiblings().forEach((t=>i.append(t)));const o=$(),l=Y(n);o.append(l),E(l,t.getNextSiblings()),r.insertBefore(s),r.insertAfter(o),r.replace(t)}}}function R(){const t=i();if(!o(t)||!t.isCollapsed())return!1;const e=t.anchor.getNode();if(!j(e)||0!==e.getChildrenSize())return!1;const r=N(e),n=e.getParent();Z(n)||k(40);const s=n.getParent();let a;if(l(s))a=c(),r.insertAfter(a);else{if(!j(s))return!1;a=$(),s.insertAfter(a)}a.setTextStyle(t.style).setTextFormat(t.format).select();const h=e.getNextSiblings();if(h.length>0){const t=Y(n.getListType());if(j(a)){const e=$();e.append(t),a.insertAfter(e)}else a.insertAfter(t);t.append(...h)}return function(t){let e=t;for(;null==e.getNextSibling()&&null==e.getPreviousSibling();){const t=e.getParent();if(null==t||!j(t)&&!Z(t))break;e=t}e.remove()}(e),!0}function W(...t){const e=[];for(const r of t)if(r&&"string"==typeof r)for(const[t]of r.matchAll(/\S+/g))e.push(t);return e}class B extends f{static getType(){return"listitem"}static clone(t){return new B(t.__value,t.__checked,t.__key)}constructor(t,e,r){super(r),this.__value=void 0===t?1:t,this.__checked=e}createDOM(t){const e=document.createElement("li"),r=this.getParent();Z(r)&&"check"===r.getListType()&&V(e,this,null),e.value=this.__value,K(e,t.theme,this);const n=this.__style||this.__textStyle;return n&&(e.style.cssText=n),e}updateDOM(t,e,r){const n=this.getParent();Z(n)&&"check"===n.getListType()&&V(e,this,t),e.value=this.__value,K(e,r.theme,this);const s=t.__style||t.__textStyle,i=this.__style||this.__textStyle;return s!==i&&(e.style.cssText=i,""===i&&e.removeAttribute("style")),!1}static transform(){return t=>{if(j(t)||k(144),null==t.__checked)return;const e=t.getParent();Z(e)&&"check"!==e.getListType()&&null!=t.getChecked()&&t.setChecked(void 0)}}static importDOM(){return{li:()=>({conversion:U,priority:0})}}static importJSON(t){return $().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setValue(t.value).setChecked(t.checked)}exportDOM(t){const e=this.createDOM(t._config);return e.style.textAlign=this.getFormatType(),{element:e}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...t){for(let e=0;e<t.length;e++){const r=t[e];if(a(r)&&this.canMergeWith(r)){const t=r.getChildren();this.append(...t),r.remove()}else super.append(r)}return this}replace(t,e){if(j(t))return super.replace(t);this.setIndent(0);const r=this.getParentOrThrow();if(!Z(r))return t;if(r.__first===this.getKey())r.insertBefore(t);else if(r.__last===this.getKey())r.insertAfter(t);else{const e=Y(r.getListType());let n=this.getNextSibling();for(;n;){const t=n;n=n.getNextSibling(),e.append(t)}r.insertAfter(t),t.insertAfter(e)}return e&&(a(t)||k(139),this.getChildren().forEach((e=>{t.append(e)}))),this.remove(),0===r.getChildrenSize()&&r.remove(),t}insertAfter(t,e=!0){const r=this.getParentOrThrow();if(Z(r)||k(39),j(t))return super.insertAfter(t,e);const n=this.getNextSiblings();if(r.insertAfter(t,e),0!==n.length){const s=Y(r.getListType());n.forEach((t=>s.append(t))),t.insertAfter(s,e)}return t}remove(t){const e=this.getPreviousSibling(),r=this.getNextSibling();super.remove(t),e&&r&&O(e)&&O(r)&&(w(e.getFirstChild(),r.getFirstChild()),r.remove())}insertNewAfter(t,e=!0){const r=$().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(r,e),r}collapseAtStart(t){const e=c();this.getChildren().forEach((t=>e.append(t)));const r=this.getParentOrThrow(),n=r.getParentOrThrow(),s=j(n);if(1===r.getChildrenSize())if(s)r.remove(),n.select();else{r.insertBefore(e),r.remove();const n=t.anchor,s=t.focus,i=e.getKey();"element"===n.type&&n.getNode().is(this)&&n.set(i,n.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else r.insertBefore(e),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(t){const e=this.getWritable();return e.__value=t,e}getChecked(){const t=this.getLatest();let e;const r=this.getParent();return Z(r)&&(e=r.getListType()),"check"===e?Boolean(t.__checked):void 0}setChecked(t){const e=this.getWritable();return e.__checked=t,e}toggleChecked(){const t=this.getWritable();return t.setChecked(!t.__checked)}getIndent(){const t=this.getParent();if(null===t||!this.isAttached())return this.getLatest().__indent;let e=t.getParentOrThrow(),r=0;for(;j(e);)e=e.getParentOrThrow().getParentOrThrow(),r++;return r}setIndent(t){"number"!=typeof t&&k(117),(t=Math.floor(t))>=0||k(199);let e=this.getIndent();for(;e!==t;)e<t?(D(this),e++):(J(this),e--);return this}canInsertAfter(t){return j(t)}canReplaceWith(t){return j(t)}canMergeWith(t){return j(t)||p(t)}extractWithChild(t,e){if(!o(e))return!1;const r=e.anchor.getNode(),n=e.focus.getNode();return this.isParentOf(r)&&this.isParentOf(n)&&this.getTextContent().length===e.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return Y("bullet")}canMergeWhenEmpty(){return!0}}function K(t,n,s){const i=[],o=[],l=n.list,c=l?l.listitem:void 0;let a;if(l&&l.nested&&(a=l.nested.listitem),void 0!==c&&i.push(...W(c)),l){const t=s.getParent(),e=Z(t)&&"check"===t.getListType(),r=s.getChecked();e&&!r||o.push(l.listitemUnchecked),e&&r||o.push(l.listitemChecked),e&&i.push(r?l.listitemChecked:l.listitemUnchecked)}if(void 0!==a){const t=W(a);s.getChildren().some((t=>Z(t)))?i.push(...t):o.push(...t)}o.length>0&&e(t,...o),i.length>0&&r(t,...i)}function V(t,e,r,n){Z(e.getFirstChild())?(t.removeAttribute("role"),t.removeAttribute("tabIndex"),t.removeAttribute("aria-checked")):(t.setAttribute("role","checkbox"),t.setAttribute("tabIndex","-1"),r&&e.__checked===r.__checked||t.setAttribute("aria-checked",e.getChecked()?"true":"false"))}function U(t){if(t.classList.contains("task-list-item"))for(const e of t.children)if("INPUT"===e.tagName)return z(e);const e=t.getAttribute("aria-checked");return{node:$("true"===e||"false"!==e&&void 0)}}function z(t){if(!("checkbox"===t.getAttribute("type")))return{node:null};return{node:$(t.hasAttribute("checked"))}}function $(t){return _(new B(void 0,t))}function j(t){return t instanceof B}class q extends f{static getType(){return"list"}static clone(t){const e=t.__listType||X[t.__tag];return new q(e,t.__start,t.__key)}constructor(t="number",e=1,r){super(r);const n=X[t]||t;this.__listType=n,this.__tag="number"===n?"ol":"ul",this.__start=e}getTag(){return this.__tag}setListType(t){const e=this.getWritable();return e.__listType=t,e.__tag="number"===t?"ol":"ul",e}getListType(){return this.__listType}getStart(){return this.__start}setStart(t){const e=this.getWritable();return e.__start=t,e}createDOM(t,e){const r=this.__tag,n=document.createElement(r);return 1!==this.__start&&n.setAttribute("start",String(this.__start)),n.__lexicalListType=this.__listType,H(n,t.theme,this),n}updateDOM(t,e,r){return t.__tag!==this.__tag||(H(e,r.theme,this),!1)}static transform(){return t=>{Z(t)||k(163),function(t){const e=t.getNextSibling();Z(e)&&t.getListType()===e.getListType()&&w(t,e)}(t),function(t){const e="check"!==t.getListType();let r=t.getStart();for(const n of t.getChildren())j(n)&&(n.getValue()!==r&&n.setValue(r),e&&null!=n.getLatest().__checked&&n.setChecked(void 0),Z(n.getFirstChild())||r++)}(t)}}static importDOM(){return{ol:()=>({conversion:Q,priority:0}),ul:()=>({conversion:Q,priority:0})}}static importJSON(t){return Y().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setListType(t.listType).setStart(t.start)}exportDOM(t){const e=this.createDOM(t._config,t);return n(e)&&(1!==this.__start&&e.setAttribute("start",String(this.__start)),"check"===this.__listType&&e.setAttribute("__lexicalListType","check")),{element:e}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}append(...t){for(let e=0;e<t.length;e++){const r=t[e];if(j(r))super.append(r);else{const t=$();if(Z(r))t.append(r);else if(a(r))if(r.isInline())t.append(r);else{const e=m(r.getTextContent());t.append(e)}else t.append(r);super.append(t)}}return this}extractWithChild(t){return j(t)}}function H(t,n,s){const i=[],o=[],l=n.list;if(void 0!==l){const t=l[`${s.__tag}Depth`]||[],e=b(s)-1,r=e%t.length,n=t[r],c=l[s.__tag];let a;const h=l.nested,u=l.checklist;if(void 0!==h&&h.list&&(a=h.list),void 0!==c&&i.push(c),void 0!==u&&"check"===s.__listType&&i.push(u),void 0!==n){i.push(...W(n));for(let e=0;e<t.length;e++)e!==r&&o.push(s.__tag+e)}if(void 0!==a){const t=W(a);e>1?i.push(...t):o.push(...t)}}o.length>0&&e(t,...o),i.length>0&&r(t,...i)}function G(t){const e=[];for(let r=0;r<t.length;r++){const n=t[r];if(j(n)){e.push(n);const t=n.getChildren();t.length>1&&t.forEach((t=>{Z(t)&&e.push(P(t))}))}else e.push(P(n))}return e}function Q(t){const e=t.nodeName.toLowerCase();let r=null;if("ol"===e){r=Y("number",t.start)}else"ul"===e&&(r=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list"))return!0;for(const e of t.childNodes)if(n(e)&&e.hasAttribute("aria-checked"))return!0;return!1}(t)?Y("check"):Y("bullet"));return{after:G,node:r}}const X={ol:"number",ul:"bullet"};function Y(t="number",e=1){return _(new q(t,e))}function Z(t){return t instanceof q}const tt=y("INSERT_UNORDERED_LIST_COMMAND"),et=y("INSERT_ORDERED_LIST_COMMAND"),rt=y("INSERT_CHECK_LIST_COMMAND"),nt=y("REMOVE_LIST_COMMAND");function st(t){return s(t.registerCommand(et,(()=>(L("number"),!0)),T),t.registerCommand(tt,(()=>(L("bullet"),!0)),T),t.registerCommand(nt,(()=>(I(),!0)),T),t.registerCommand(S,(()=>R()),T),t.registerNodeTransform(B,(t=>{const e=t.getFirstChild();if(e){if(C(e)){const r=e.getStyle(),n=e.getFormat();t.getTextStyle()!==r&&t.setTextStyle(r),t.getTextFormat()!==n&&t.setTextFormat(n)}}else{const e=i();o(e)&&(e.style!==t.getTextStyle()||e.format!==t.getTextFormat())&&e.isCollapsed()&&t.is(e.anchor.getNode())&&t.setTextStyle(e.style).setTextFormat(e.format)}})),t.registerNodeTransform(x,(t=>{const e=t.getParent();if(j(e)&&t.is(e.getFirstChild())){const r=t.getStyle(),n=t.getFormat();r===e.getTextStyle()&&n===e.getTextFormat()||e.setTextStyle(r).setTextFormat(n)}})))}function it(t,e){t.update((()=>L(e)))}function ot(t){t.update((()=>I()))}export{$ as $createListItemNode,Y as $createListNode,b as $getListDepth,R as $handleListInsertParagraph,L as $insertList,j as $isListItemNode,Z as $isListNode,I as $removeList,rt as INSERT_CHECK_LIST_COMMAND,et as INSERT_ORDERED_LIST_COMMAND,tt as INSERT_UNORDERED_LIST_COMMAND,B as ListItemNode,q as ListNode,nt as REMOVE_LIST_COMMAND,it as insertList,st as registerList,ot as removeList};
9
+ import{$getNearestNodeOfType as t,removeClassNamesFromElement as e,addClassNamesToElement as r,isHTMLElement as n,mergeRegister as s}from"@lexical/utils";import{$getSelection as i,$isRangeSelection as o,$isRootOrShadowRoot as l,$createParagraphNode as c,$isElementNode as a,$isLeafNode as h,$setPointFromCaret as g,$normalizeCaret as u,$getChildCaret as d,ElementNode as f,$isParagraphNode as p,$applyNodeReplacement as _,$createTextNode as m,createCommand as y,COMMAND_PRIORITY_LOW as T,INSERT_PARAGRAPH_COMMAND as S,$isTextNode as C,TextNode as x}from"lexical";function v(t,...e){const r=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(const t of e)n.append("v",t);throw r.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function k(t){let e=1,r=t.getParent();for(;null!=r;){if($(r)){const t=r.getParent();if(Y(t)){e++,r=t.getParent();continue}v(40)}return e}return e}function b(t){let e=t.getParent();Y(e)||v(40);let r=e;for(;null!==r;)r=r.getParent(),Y(r)&&(e=r);return e}function N(t){let e=[];const r=t.getChildren().filter($);for(let t=0;t<r.length;t++){const n=r[t],s=n.getFirstChild();Y(s)?e=e.concat(N(s)):e.push(n)}return e}function F(t){return $(t)&&Y(t.getFirstChild())}function O(t){return z().append(t)}function P(t,e){return $(t)&&(0===e.length||1===e.length&&t.is(e[0])&&0===t.getChildrenSize())}function A(t){const e=i();if(null!==e){let r=e.getNodes();if(o(e)){const n=e.getStartEndPoints();null===n&&v(143);const[s]=n,i=s.getNode(),o=i.getParent();if(l(i)){const t=i.getFirstChild();if(t)r=t.selectStart().getNodes();else{const t=c();i.append(t),r=t.select().getNodes()}}else if(P(i,r)){const e=X(t);if(l(o)){i.replace(e);const t=z();a(i)&&(t.setFormat(i.getFormatType()),t.setIndent(i.getIndent())),e.append(t)}else if($(i)){const t=i.getParentOrThrow();L(e,t.getChildren()),t.replace(e)}return}}const n=new Set;for(let e=0;e<r.length;e++){const s=r[e];if(!a(s)||!s.isEmpty()||$(s)||n.has(s.getKey())){if(h(s)){let e=s.getParent();for(;null!=e;){const r=e.getKey();if(Y(e)){if(!n.has(r)){const s=X(t);L(s,e.getChildren()),e.replace(s),n.add(r)}break}{const s=e.getParent();if(l(s)&&!n.has(r)){n.add(r),E(e,t);break}e=s}}}}else E(s,t)}}}function L(t,e){t.splice(t.getChildrenSize(),0,e)}function E(t,e){if(Y(t))return t;const r=t.getPreviousSibling(),n=t.getNextSibling(),s=z();let i;if(L(s,t.getChildren()),Y(r)&&e===r.getListType())r.append(s),Y(n)&&e===n.getListType()&&(L(r,n.getChildren()),n.remove()),i=r;else if(Y(n)&&e===n.getListType())n.getFirstChildOrThrow().insertBefore(s),i=n;else{const r=X(e);r.append(s),t.replace(r),i=r}return s.setFormat(t.getFormatType()),s.setIndent(t.getIndent()),t.remove(),i}function M(t,e){const r=t.getLastChild(),n=e.getFirstChild();r&&n&&F(r)&&F(n)&&(M(r.getFirstChild(),n.getFirstChild()),n.remove());const s=e.getChildren();s.length>0&&t.append(...s),e.remove()}function w(){const e=i();if(o(e)){const r=new Set,n=e.getNodes(),s=e.anchor.getNode();if(P(s,n))r.add(b(s));else for(let e=0;e<n.length;e++){const s=n[e];if(h(s)){const e=t(s,W);null!=e&&r.add(b(e))}}for(const t of r){let r=t;const n=N(t);for(const t of n){const n=c().setTextStyle(e.style).setTextFormat(e.format);L(n,t.getChildren()),r.insertAfter(n),r=n,t.__key===e.anchor.key&&g(e.anchor,u(d(n,"next"))),t.__key===e.focus.key&&g(e.focus,u(d(n,"next"))),t.remove()}t.remove()}}}function I(t){const e=new Set;if(F(t)||e.has(t.getKey()))return;const r=t.getParent(),n=t.getNextSibling(),s=t.getPreviousSibling();if(F(n)&&F(s)){const r=s.getFirstChild();if(Y(r)){r.append(t);const s=n.getFirstChild();if(Y(s)){L(r,s.getChildren()),n.remove(),e.add(n.getKey())}}}else if(F(n)){const e=n.getFirstChild();if(Y(e)){const r=e.getFirstChild();null!==r&&r.insertBefore(t)}}else if(F(s)){const e=s.getFirstChild();Y(e)&&e.append(t)}else if(Y(r)){const e=z().setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle()),i=X(r.getListType()).setTextFormat(r.getTextFormat()).setTextStyle(r.getTextStyle());e.append(i),i.append(t),s?s.insertAfter(e):n?n.insertBefore(e):r.append(e)}}function D(t){if(F(t))return;const e=t.getParent(),r=e?e.getParent():void 0;if(Y(r?r.getParent():void 0)&&$(r)&&Y(e)){const n=e?e.getFirstChild():void 0,s=e?e.getLastChild():void 0;if(t.is(n))r.insertBefore(t),e.isEmpty()&&r.remove();else if(t.is(s))r.insertAfter(t),e.isEmpty()&&r.remove();else{const n=e.getListType(),s=z(),i=X(n);s.append(i),t.getPreviousSiblings().forEach((t=>i.append(t)));const o=z(),l=X(n);o.append(l),L(l,t.getNextSiblings()),r.insertBefore(s),r.insertAfter(o),r.replace(t)}}}function J(){const t=i();if(!o(t)||!t.isCollapsed())return!1;const e=t.anchor.getNode();if(!$(e)||0!==e.getChildrenSize())return!1;const r=b(e),n=e.getParent();Y(n)||v(40);const s=n.getParent();let a;if(l(s))a=c(),r.insertAfter(a);else{if(!$(s))return!1;a=z(),s.insertAfter(a)}a.setTextStyle(t.style).setTextFormat(t.format).select();const h=e.getNextSiblings();if(h.length>0){const t=X(n.getListType());if($(a)){const e=z();e.append(t),a.insertAfter(e)}else a.insertAfter(t);t.append(...h)}return function(t){let e=t;for(;null==e.getNextSibling()&&null==e.getPreviousSibling();){const t=e.getParent();if(null==t||!$(t)&&!Y(t))break;e=t}e.remove()}(e),!0}function R(...t){const e=[];for(const r of t)if(r&&"string"==typeof r)for(const[t]of r.matchAll(/\S+/g))e.push(t);return e}class W extends f{static getType(){return"listitem"}static clone(t){return new W(t.__value,t.__checked,t.__key)}constructor(t,e,r){super(r),this.__value=void 0===t?1:t,this.__checked=e}createDOM(t){const e=document.createElement("li"),r=this.getParent();Y(r)&&"check"===r.getListType()&&K(e,this,null),e.value=this.__value,B(e,t.theme,this);const n=this.__style||this.__textStyle;return n&&(e.style.cssText=n),e}updateDOM(t,e,r){const n=this.getParent();Y(n)&&"check"===n.getListType()&&K(e,this,t),e.value=this.__value,B(e,r.theme,this);const s=t.__style||t.__textStyle,i=this.__style||this.__textStyle;return s!==i&&(e.style.cssText=i,""===i&&e.removeAttribute("style")),!1}static transform(){return t=>{if($(t)||v(144),null==t.__checked)return;const e=t.getParent();Y(e)&&"check"!==e.getListType()&&null!=t.getChecked()&&t.setChecked(void 0)}}static importDOM(){return{li:()=>({conversion:V,priority:0})}}static importJSON(t){return z().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setValue(t.value).setChecked(t.checked)}exportDOM(t){const e=this.createDOM(t._config);return e.style.textAlign=this.getFormatType(),{element:e}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...t){for(let e=0;e<t.length;e++){const r=t[e];if(a(r)&&this.canMergeWith(r)){const t=r.getChildren();this.append(...t),r.remove()}else super.append(r)}return this}replace(t,e){if($(t))return super.replace(t);this.setIndent(0);const r=this.getParentOrThrow();if(!Y(r))return t;if(r.__first===this.getKey())r.insertBefore(t);else if(r.__last===this.getKey())r.insertAfter(t);else{const e=X(r.getListType());let n=this.getNextSibling();for(;n;){const t=n;n=n.getNextSibling(),e.append(t)}r.insertAfter(t),t.insertAfter(e)}return e&&(a(t)||v(139),this.getChildren().forEach((e=>{t.append(e)}))),this.remove(),0===r.getChildrenSize()&&r.remove(),t}insertAfter(t,e=!0){const r=this.getParentOrThrow();if(Y(r)||v(39),$(t))return super.insertAfter(t,e);const n=this.getNextSiblings();if(r.insertAfter(t,e),0!==n.length){const s=X(r.getListType());n.forEach((t=>s.append(t))),t.insertAfter(s,e)}return t}remove(t){const e=this.getPreviousSibling(),r=this.getNextSibling();super.remove(t),e&&r&&F(e)&&F(r)&&(M(e.getFirstChild(),r.getFirstChild()),r.remove())}insertNewAfter(t,e=!0){const r=z().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(r,e),r}collapseAtStart(t){const e=c();this.getChildren().forEach((t=>e.append(t)));const r=this.getParentOrThrow(),n=r.getParentOrThrow(),s=$(n);if(1===r.getChildrenSize())if(s)r.remove(),n.select();else{r.insertBefore(e),r.remove();const n=t.anchor,s=t.focus,i=e.getKey();"element"===n.type&&n.getNode().is(this)&&n.set(i,n.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else r.insertBefore(e),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(t){const e=this.getWritable();return e.__value=t,e}getChecked(){const t=this.getLatest();let e;const r=this.getParent();return Y(r)&&(e=r.getListType()),"check"===e?Boolean(t.__checked):void 0}setChecked(t){const e=this.getWritable();return e.__checked=t,e}toggleChecked(){const t=this.getWritable();return t.setChecked(!t.__checked)}getIndent(){const t=this.getParent();if(null===t||!this.isAttached())return this.getLatest().__indent;let e=t.getParentOrThrow(),r=0;for(;$(e);)e=e.getParentOrThrow().getParentOrThrow(),r++;return r}setIndent(t){"number"!=typeof t&&v(117),(t=Math.floor(t))>=0||v(199);let e=this.getIndent();for(;e!==t;)e<t?(I(this),e++):(D(this),e--);return this}canInsertAfter(t){return $(t)}canReplaceWith(t){return $(t)}canMergeWith(t){return $(t)||p(t)}extractWithChild(t,e){if(!o(e))return!1;const r=e.anchor.getNode(),n=e.focus.getNode();return this.isParentOf(r)&&this.isParentOf(n)&&this.getTextContent().length===e.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return X("bullet")}canMergeWhenEmpty(){return!0}}function B(t,n,s){const i=[],o=[],l=n.list,c=l?l.listitem:void 0;let a;if(l&&l.nested&&(a=l.nested.listitem),void 0!==c&&i.push(...R(c)),l){const t=s.getParent(),e=Y(t)&&"check"===t.getListType(),r=s.getChecked();e&&!r||o.push(l.listitemUnchecked),e&&r||o.push(l.listitemChecked),e&&i.push(r?l.listitemChecked:l.listitemUnchecked)}if(void 0!==a){const t=R(a);s.getChildren().some((t=>Y(t)))?i.push(...t):o.push(...t)}o.length>0&&e(t,...o),i.length>0&&r(t,...i)}function K(t,e,r,n){Y(e.getFirstChild())?(t.removeAttribute("role"),t.removeAttribute("tabIndex"),t.removeAttribute("aria-checked")):(t.setAttribute("role","checkbox"),t.setAttribute("tabIndex","-1"),r&&e.__checked===r.__checked||t.setAttribute("aria-checked",e.getChecked()?"true":"false"))}function V(t){if(t.classList.contains("task-list-item"))for(const e of t.children)if("INPUT"===e.tagName)return U(e);const e=t.getAttribute("aria-checked");return{node:z("true"===e||"false"!==e&&void 0)}}function U(t){if(!("checkbox"===t.getAttribute("type")))return{node:null};return{node:z(t.hasAttribute("checked"))}}function z(t){return _(new W(void 0,t))}function $(t){return t instanceof W}class q extends f{static getType(){return"list"}static clone(t){const e=t.__listType||Q[t.__tag];return new q(e,t.__start,t.__key)}constructor(t="number",e=1,r){super(r);const n=Q[t]||t;this.__listType=n,this.__tag="number"===n?"ol":"ul",this.__start=e}getTag(){return this.__tag}setListType(t){const e=this.getWritable();return e.__listType=t,e.__tag="number"===t?"ol":"ul",e}getListType(){return this.__listType}getStart(){return this.__start}setStart(t){const e=this.getWritable();return e.__start=t,e}createDOM(t,e){const r=this.__tag,n=document.createElement(r);return 1!==this.__start&&n.setAttribute("start",String(this.__start)),n.__lexicalListType=this.__listType,H(n,t.theme,this),n}updateDOM(t,e,r){return t.__tag!==this.__tag||(H(e,r.theme,this),!1)}static transform(){return t=>{Y(t)||v(163),function(t){const e=t.getNextSibling();Y(e)&&t.getListType()===e.getListType()&&M(t,e)}(t),function(t){const e="check"!==t.getListType();let r=t.getStart();for(const n of t.getChildren())$(n)&&(n.getValue()!==r&&n.setValue(r),e&&null!=n.getLatest().__checked&&n.setChecked(void 0),Y(n.getFirstChild())||r++)}(t)}}static importDOM(){return{ol:()=>({conversion:G,priority:0}),ul:()=>({conversion:G,priority:0})}}static importJSON(t){return X().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setListType(t.listType).setStart(t.start)}exportDOM(t){const e=this.createDOM(t._config,t);return n(e)&&(1!==this.__start&&e.setAttribute("start",String(this.__start)),"check"===this.__listType&&e.setAttribute("__lexicalListType","check")),{element:e}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}append(...t){for(let e=0;e<t.length;e++){const r=t[e];if($(r))super.append(r);else{const t=z();if(Y(r))t.append(r);else if(a(r))if(r.isInline())t.append(r);else{const e=m(r.getTextContent());t.append(e)}else t.append(r);super.append(t)}}return this}extractWithChild(t){return $(t)}}function H(t,n,s){const i=[],o=[],l=n.list;if(void 0!==l){const t=l[`${s.__tag}Depth`]||[],e=k(s)-1,r=e%t.length,n=t[r],c=l[s.__tag];let a;const h=l.nested,g=l.checklist;if(void 0!==h&&h.list&&(a=h.list),void 0!==c&&i.push(c),void 0!==g&&"check"===s.__listType&&i.push(g),void 0!==n){i.push(...R(n));for(let e=0;e<t.length;e++)e!==r&&o.push(s.__tag+e)}if(void 0!==a){const t=R(a);e>1?i.push(...t):o.push(...t)}}o.length>0&&e(t,...o),i.length>0&&r(t,...i)}function j(t){const e=[];for(let r=0;r<t.length;r++){const n=t[r];if($(n)){e.push(n);const t=n.getChildren();t.length>1&&t.forEach((t=>{Y(t)&&e.push(O(t))}))}else e.push(O(n))}return e}function G(t){const e=t.nodeName.toLowerCase();let r=null;if("ol"===e){r=X("number",t.start)}else"ul"===e&&(r=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list"))return!0;for(const e of t.childNodes)if(n(e)&&e.hasAttribute("aria-checked"))return!0;return!1}(t)?X("check"):X("bullet"));return{after:j,node:r}}const Q={ol:"number",ul:"bullet"};function X(t="number",e=1){return _(new q(t,e))}function Y(t){return t instanceof q}const Z=y("INSERT_UNORDERED_LIST_COMMAND"),tt=y("INSERT_ORDERED_LIST_COMMAND"),et=y("INSERT_CHECK_LIST_COMMAND"),rt=y("REMOVE_LIST_COMMAND");function nt(t){return s(t.registerCommand(tt,(()=>(A("number"),!0)),T),t.registerCommand(Z,(()=>(A("bullet"),!0)),T),t.registerCommand(rt,(()=>(w(),!0)),T),t.registerCommand(S,(()=>J()),T),t.registerNodeTransform(W,(t=>{const e=t.getFirstChild();if(e){if(C(e)){const r=e.getStyle(),n=e.getFormat();t.getTextStyle()!==r&&t.setTextStyle(r),t.getTextFormat()!==n&&t.setTextFormat(n)}}else{const e=i();o(e)&&(e.style!==t.getTextStyle()||e.format!==t.getTextFormat())&&e.isCollapsed()&&t.is(e.anchor.getNode())&&t.setTextStyle(e.style).setTextFormat(e.format)}})),t.registerNodeTransform(x,(t=>{const e=t.getParent();if($(e)&&t.is(e.getFirstChild())){const r=t.getStyle(),n=t.getFormat();r===e.getTextStyle()&&n===e.getTextFormat()||e.setTextStyle(r).setTextFormat(n)}})))}function st(t,e){t.update((()=>A(e)))}function it(t){t.update((()=>w()))}export{z as $createListItemNode,X as $createListNode,k as $getListDepth,J as $handleListInsertParagraph,A as $insertList,$ as $isListItemNode,Y as $isListNode,w as $removeList,et as INSERT_CHECK_LIST_COMMAND,tt as INSERT_ORDERED_LIST_COMMAND,Z as INSERT_UNORDERED_LIST_COMMAND,W as ListItemNode,q as ListNode,rt as REMOVE_LIST_COMMAND,st as insertList,nt as registerList,it as removeList};
package/package.json CHANGED
@@ -8,12 +8,12 @@
8
8
  "list"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.26.0",
11
+ "version": "0.27.0",
12
12
  "main": "LexicalList.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/utils": "0.26.0",
16
- "lexical": "0.26.0"
15
+ "@lexical/utils": "0.27.0",
16
+ "lexical": "0.27.0"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",