@webiny/lexical-nodes 6.0.0-beta.0 → 6.0.0-rc.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.
Files changed (83) hide show
  1. package/FontColorNode.d.ts +24 -22
  2. package/FontColorNode.js +114 -103
  3. package/FontColorNode.js.map +1 -1
  4. package/HeadingNode.d.ts +30 -20
  5. package/HeadingNode.js +185 -176
  6. package/HeadingNode.js.map +1 -1
  7. package/ImageNode.d.ts +2 -12
  8. package/ImageNode.js +119 -193
  9. package/ImageNode.js.map +1 -1
  10. package/LinkNode.d.ts +6 -6
  11. package/LinkNode.js +249 -347
  12. package/LinkNode.js.map +1 -1
  13. package/ListItemNode.d.ts +6 -5
  14. package/ListItemNode.js +275 -352
  15. package/ListItemNode.js.map +1 -1
  16. package/ListNode.d.ts +32 -19
  17. package/ListNode.js +170 -210
  18. package/ListNode.js.map +1 -1
  19. package/ParagraphNode.d.ts +30 -20
  20. package/ParagraphNode.js +144 -201
  21. package/ParagraphNode.js.map +1 -1
  22. package/QuoteNode.d.ts +27 -20
  23. package/QuoteNode.js +102 -208
  24. package/QuoteNode.js.map +1 -1
  25. package/README.md +9 -4
  26. package/components/ImageNode/ImageComponent.d.ts +2 -7
  27. package/components/ImageNode/ImageComponent.js +72 -166
  28. package/components/ImageNode/ImageComponent.js.map +1 -1
  29. package/components/ImageNode/ImageResizer.d.ts +1 -8
  30. package/components/ImageNode/ImageResizer.js +80 -95
  31. package/components/ImageNode/ImageResizer.js.map +1 -1
  32. package/generateInitialLexicalValue.d.ts +4 -0
  33. package/generateInitialLexicalValue.js +27 -0
  34. package/generateInitialLexicalValue.js.map +1 -0
  35. package/index.d.ts +19 -23
  36. package/index.js +50 -233
  37. package/index.js.map +1 -1
  38. package/package.json +22 -19
  39. package/prepareLexicalState.d.ts +2 -0
  40. package/prepareLexicalState.js +53 -0
  41. package/prepareLexicalState.js.map +1 -0
  42. package/types.d.ts +5 -9
  43. package/types.js +1 -5
  44. package/types.js.map +1 -1
  45. package/utils/clearNodeFormating.d.ts +2 -2
  46. package/utils/clearNodeFormating.js +12 -18
  47. package/utils/clearNodeFormating.js.map +1 -1
  48. package/utils/formatList.d.ts +4 -4
  49. package/utils/formatList.js +171 -208
  50. package/utils/formatList.js.map +1 -1
  51. package/utils/formatToHeading.d.ts +2 -2
  52. package/utils/formatToHeading.js +8 -15
  53. package/utils/formatToHeading.js.map +1 -1
  54. package/utils/formatToParagraph.d.ts +1 -1
  55. package/utils/formatToParagraph.js +8 -16
  56. package/utils/formatToParagraph.js.map +1 -1
  57. package/utils/formatToQuote.d.ts +1 -1
  58. package/utils/formatToQuote.js +10 -17
  59. package/utils/formatToQuote.js.map +1 -1
  60. package/utils/getStyleId.d.ts +11 -0
  61. package/utils/getStyleId.js +14 -0
  62. package/utils/getStyleId.js.map +1 -0
  63. package/utils/listNode.d.ts +14 -4
  64. package/utils/listNode.js +43 -49
  65. package/utils/listNode.js.map +1 -1
  66. package/utils/toggleLink.d.ts +1 -1
  67. package/utils/toggleLink.js +41 -45
  68. package/utils/toggleLink.js.map +1 -1
  69. package/TypographyNode.d.ts +0 -39
  70. package/TypographyNode.js +0 -147
  71. package/TypographyNode.js.map +0 -1
  72. package/components/ImageNode/ContentEditable.css +0 -22
  73. package/components/ImageNode/ContentEditable.d.ts +0 -12
  74. package/components/ImageNode/ContentEditable.js +0 -26
  75. package/components/ImageNode/ContentEditable.js.map +0 -1
  76. package/components/ImageNode/ImageComponent.css +0 -43
  77. package/components/ImageNode/Placeholder.css +0 -20
  78. package/components/ImageNode/Placeholder.d.ts +0 -15
  79. package/components/ImageNode/Placeholder.js +0 -30
  80. package/components/ImageNode/Placeholder.js.map +0 -1
  81. package/components/ImageNode/SharedHistoryContext.d.ts +0 -10
  82. package/components/ImageNode/SharedHistoryContext.js +0 -27
  83. package/components/ImageNode/SharedHistoryContext.js.map +0 -1
@@ -1,103 +1,86 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.$handleIndent = $handleIndent;
8
- exports.$handleListInsertParagraph = $handleListInsertParagraph;
9
- exports.$handleOutdent = $handleOutdent;
10
- exports.indentList = indentList;
11
- exports.insertList = insertList;
12
- exports.mergeLists = mergeLists;
13
- exports.outdentList = outdentList;
14
- exports.removeList = removeList;
15
- exports.updateChildrenListItemValue = updateChildrenListItemValue;
16
- var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
17
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
18
- var _lexical = require("lexical");
19
- var _ListNode = require("../ListNode");
20
- var _utils = require("@lexical/utils");
21
- var _ListItemNode = require("../ListItemNode");
22
- var _ParagraphNode = require("../ParagraphNode");
23
- var _listNode = require("./listNode");
24
- var DEFAULT_LIST_START_NUMBER = 1;
1
+ import { $getSelection, $isElementNode, $isLeafNode, $isParagraphNode, $isRangeSelection, $isRootOrShadowRoot } from "lexical";
2
+ import { $createListNode, $isListNode } from "../ListNode.js";
3
+ import { $getNearestNodeOfType } from "@lexical/utils";
4
+ import { $createListItemNode, $isListItemNode, ListItemNode } from "../ListItemNode.js";
5
+ import { $createParagraphNode } from "../ParagraphNode.js";
6
+ import { $getAllListItems, $getTopListNode, $removeHighestEmptyListParent, findNearestListItemNode, getUniqueListItemNodes, isNestedListNode } from "./listNode.js";
7
+ const DEFAULT_LIST_START_NUMBER = 1;
25
8
  function $isSelectingEmptyListItem(anchorNode, nodes) {
26
- return (0, _ListItemNode.$isListItemNode)(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
9
+ return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
27
10
  }
28
11
  function $getListItemValue(listItem) {
29
- var list = listItem.getParent();
30
- var value = 1;
12
+ const list = listItem.getParent();
13
+ let value = 1;
31
14
  if (list !== null) {
32
- if (!(0, _ListNode.$isListNode)(list)) {
15
+ if (!$isListNode(list)) {
33
16
  console.log("$getListItemValue: webiny list node is not parent of webiny list item node");
34
17
  return DEFAULT_LIST_START_NUMBER;
35
18
  } else {
36
19
  value = list.getStart();
37
20
  }
38
21
  }
39
- var siblings = listItem.getPreviousSiblings();
40
- for (var i = 0; i < siblings.length; i++) {
41
- var sibling = siblings[i];
42
- if ((0, _ListItemNode.$isListItemNode)(sibling) && !(0, _ListNode.$isListNode)(sibling.getFirstChild())) {
22
+ const siblings = listItem.getPreviousSiblings();
23
+ for (let i = 0; i < siblings.length; i++) {
24
+ const sibling = siblings[i];
25
+ if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
43
26
  value++;
44
27
  }
45
28
  }
46
29
  return value;
47
30
  }
48
- function insertList(editor, listType, styleId) {
49
- editor.update(function () {
50
- var selection = (0, _lexical.$getSelection)();
51
- if ((0, _lexical.$isRangeSelection)(selection) || (0, _lexical.DEPRECATED_$isGridSelection)(selection)) {
52
- var nodes = selection.getNodes();
53
- var anchor = selection.anchor;
54
- var anchorNode = anchor.getNode();
55
- var anchorNodeParent = anchorNode.getParent();
31
+ export function insertList(editor, listType, styleId) {
32
+ editor.update(() => {
33
+ const selection = $getSelection();
34
+ if (selection && $isRangeSelection(selection)) {
35
+ const nodes = selection.getNodes();
36
+ const anchor = selection.anchor;
37
+ const anchorNode = anchor.getNode();
38
+ const anchorNodeParent = anchorNode.getParent();
56
39
  if ($isSelectingEmptyListItem(anchorNode, nodes)) {
57
- var list = (0, _ListNode.$createListNode)(listType, styleId);
58
- if ((0, _lexical.$isRootOrShadowRoot)(anchorNodeParent)) {
40
+ const list = $createListNode(listType, styleId);
41
+ if ($isRootOrShadowRoot(anchorNodeParent)) {
59
42
  anchorNode.replace(list);
60
- var listItem = (0, _ListItemNode.$createListItemNode)();
61
- if ((0, _lexical.$isElementNode)(anchorNode)) {
43
+ const listItem = $createListItemNode();
44
+ if ($isElementNode(anchorNode)) {
62
45
  listItem.setFormat(anchorNode.getFormatType());
63
46
  listItem.setIndent(anchorNode.getIndent());
64
47
  }
65
48
  list.append(listItem);
66
- } else if ((0, _ListItemNode.$isListItemNode)(anchorNode)) {
67
- var parent = anchorNode.getParentOrThrow();
49
+ } else if ($isListItemNode(anchorNode)) {
50
+ const parent = anchorNode.getParentOrThrow();
68
51
  append(list, parent.getChildren());
69
52
  parent.replace(list);
70
53
  }
71
54
  return;
72
55
  } else {
73
- var handled = new Set();
74
- for (var i = 0; i < nodes.length; i++) {
75
- var node = nodes[i];
76
- if ((0, _lexical.$isElementNode)(node) && node.isEmpty() && !handled.has(node.getKey())) {
56
+ const handled = new Set();
57
+ for (let i = 0; i < nodes.length; i++) {
58
+ const node = nodes[i];
59
+ if ($isElementNode(node) && node.isEmpty() && !handled.has(node.getKey())) {
77
60
  createListOrMerge(node, listType, styleId);
78
61
  continue;
79
62
  }
80
- if ((0, _lexical.$isLeafNode)(node)) {
81
- var _parent = node.getParent();
82
- while (_parent != null) {
83
- var parentKey = _parent.getKey();
84
- if ((0, _ListNode.$isListNode)(_parent)) {
63
+ if ($isLeafNode(node)) {
64
+ let parent = node.getParent();
65
+ while (parent != null) {
66
+ const parentKey = parent.getKey();
67
+ if ($isListNode(parent)) {
85
68
  if (!handled.has(parentKey)) {
86
- var newListNode = (0, _ListNode.$createListNode)(listType, styleId);
87
- append(newListNode, _parent.getChildren());
88
- _parent.replace(newListNode);
69
+ const newListNode = $createListNode(listType, styleId);
70
+ append(newListNode, parent.getChildren());
71
+ parent.replace(newListNode);
89
72
  updateChildrenListItemValue(newListNode);
90
73
  handled.add(parentKey);
91
74
  }
92
75
  break;
93
76
  } else {
94
- var nextParent = _parent.getParent();
95
- if ((0, _lexical.$isRootOrShadowRoot)(nextParent) && !handled.has(parentKey)) {
77
+ const nextParent = parent.getParent();
78
+ if ($isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) {
96
79
  handled.add(parentKey);
97
- createListOrMerge(_parent, listType, styleId);
80
+ createListOrMerge(parent, listType, styleId);
98
81
  break;
99
82
  }
100
- _parent = nextParent;
83
+ parent = nextParent;
101
84
  }
102
85
  }
103
86
  }
@@ -110,31 +93,31 @@ function append(node, nodesToAppend) {
110
93
  node.splice(node.getChildrenSize(), 0, nodesToAppend);
111
94
  }
112
95
  function createListOrMerge(node, listType, styleId) {
113
- if ((0, _ListNode.$isListNode)(node)) {
96
+ if ($isListNode(node)) {
114
97
  return node;
115
98
  }
116
- var previousSibling = node.getPreviousSibling();
117
- var nextSibling = node.getNextSibling();
118
- var listItem = (0, _ListItemNode.$createListItemNode)();
99
+ const previousSibling = node.getPreviousSibling();
100
+ const nextSibling = node.getNextSibling();
101
+ const listItem = $createListItemNode();
119
102
  listItem.setFormat(node.getFormatType());
120
103
  listItem.setIndent(node.getIndent());
121
104
  append(listItem, node.getChildren());
122
- if ((0, _ListNode.$isListNode)(previousSibling) && listType === previousSibling.getListType()) {
105
+ if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
123
106
  previousSibling.append(listItem);
124
107
  node.remove();
125
108
  // if the same type of list is on both sides, merge them.
126
109
 
127
- if ((0, _ListNode.$isListNode)(nextSibling) && listType === nextSibling.getListType()) {
110
+ if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
128
111
  append(previousSibling, nextSibling.getChildren());
129
112
  nextSibling.remove();
130
113
  }
131
114
  return previousSibling;
132
- } else if ((0, _ListNode.$isListNode)(nextSibling) && listType === nextSibling.getListType()) {
115
+ } else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
133
116
  nextSibling.getFirstChildOrThrow().insertBefore(listItem);
134
117
  node.remove();
135
118
  return nextSibling;
136
119
  } else {
137
- var list = (0, _ListNode.$createListNode)(listType, styleId);
120
+ const list = $createListNode(listType, styleId);
138
121
  list.append(listItem);
139
122
  node.replace(list);
140
123
  updateChildrenListItemValue(list);
@@ -148,94 +131,76 @@ function createListOrMerge(node, listType, styleId) {
148
131
  * @param list1 - The first list to be merged.
149
132
  * @param list2 - The second list to be merged.
150
133
  */
151
- function mergeLists(list1, list2) {
152
- var listItem1 = list1.getLastChild();
153
- var listItem2 = list2.getFirstChild();
154
- if (listItem1 && listItem2 && (0, _listNode.isNestedListNode)(listItem1) && (0, _listNode.isNestedListNode)(listItem2)) {
134
+ export function mergeLists(list1, list2) {
135
+ const listItem1 = list1.getLastChild();
136
+ const listItem2 = list2.getFirstChild();
137
+ if (listItem1 && listItem2 && isNestedListNode(listItem1) && isNestedListNode(listItem2)) {
155
138
  mergeLists(listItem1.getFirstChild(), listItem2.getFirstChild());
156
139
  listItem2.remove();
157
140
  }
158
- var toMerge = list2.getChildren();
141
+ const toMerge = list2.getChildren();
159
142
  if (toMerge.length > 0) {
160
- list1.append.apply(list1, (0, _toConsumableArray2.default)(toMerge));
143
+ list1.append(...toMerge);
161
144
  updateChildrenListItemValue(list1);
162
145
  }
163
146
  list2.remove();
164
147
  }
165
- function removeList(editor) {
166
- editor.update(function () {
167
- var selection = (0, _lexical.$getSelection)();
168
- if ((0, _lexical.$isRangeSelection)(selection)) {
169
- var listNodes = new Set();
170
- var nodes = selection.getNodes();
171
- var anchorNode = selection.anchor.getNode();
148
+ export function removeList(editor) {
149
+ editor.update(() => {
150
+ const selection = $getSelection();
151
+ if ($isRangeSelection(selection)) {
152
+ const listNodes = new Set();
153
+ const nodes = selection.getNodes();
154
+ const anchorNode = selection.anchor.getNode();
172
155
  if ($isSelectingEmptyListItem(anchorNode, nodes)) {
173
- listNodes.add((0, _listNode.$getTopListNode)(anchorNode));
156
+ listNodes.add($getTopListNode(anchorNode));
174
157
  } else {
175
- for (var i = 0; i < nodes.length; i++) {
176
- var node = nodes[i];
177
- if ((0, _lexical.$isLeafNode)(node)) {
178
- var listItemNode = (0, _utils.$getNearestNodeOfType)(node, _ListItemNode.ListItemNode);
158
+ for (let i = 0; i < nodes.length; i++) {
159
+ const node = nodes[i];
160
+ if ($isLeafNode(node)) {
161
+ const listItemNode = $getNearestNodeOfType(node, ListItemNode);
179
162
  if (listItemNode != null) {
180
- listNodes.add((0, _listNode.$getTopListNode)(listItemNode));
163
+ listNodes.add($getTopListNode(listItemNode));
181
164
  }
182
165
  }
183
166
  }
184
167
  }
185
- var _iterator = (0, _createForOfIteratorHelper2.default)(listNodes),
186
- _step;
187
- try {
188
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
189
- var listNode = _step.value;
190
- var insertionPoint = listNode;
191
- var listItems = (0, _listNode.$getAllListItems)(listNode);
192
- var _iterator2 = (0, _createForOfIteratorHelper2.default)(listItems),
193
- _step2;
194
- try {
195
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
196
- var _listItemNode = _step2.value;
197
- var paragraph = (0, _ParagraphNode.$createParagraphNode)();
198
- append(paragraph, _listItemNode.getChildren());
199
- insertionPoint.insertAfter(paragraph);
200
- insertionPoint = paragraph;
168
+ for (const listNode of listNodes) {
169
+ let insertionPoint = listNode;
170
+ const listItems = $getAllListItems(listNode);
171
+ for (const listItemNode of listItems) {
172
+ const paragraph = $createParagraphNode();
173
+ append(paragraph, listItemNode.getChildren());
174
+ insertionPoint.insertAfter(paragraph);
175
+ insertionPoint = paragraph;
201
176
 
202
- // When the anchor and focus fall on the textNode
203
- // we don't have to change the selection because the textNode will be appended to
204
- // the newly generated paragraph.
205
- // When selection is in empty nested list item, selection is actually on the listItemNode.
206
- // When the corresponding listItemNode is deleted and replaced by the newly generated paragraph
207
- // we should manually set the selection's focus and anchor to the newly generated paragraph.
208
- if (_listItemNode.__key === selection.anchor.key) {
209
- selection.anchor.set(paragraph.getKey(), 0, "element");
210
- }
211
- if (_listItemNode.__key === selection.focus.key) {
212
- selection.focus.set(paragraph.getKey(), 0, "element");
213
- }
214
- _listItemNode.remove();
215
- }
216
- } catch (err) {
217
- _iterator2.e(err);
218
- } finally {
219
- _iterator2.f();
177
+ // When the anchor and focus fall on the textNode
178
+ // we don't have to change the selection because the textNode will be appended to
179
+ // the newly generated paragraph.
180
+ // When selection is in empty nested list item, selection is actually on the listItemNode.
181
+ // When the corresponding listItemNode is deleted and replaced by the newly generated paragraph
182
+ // we should manually set the selection's focus and anchor to the newly generated paragraph.
183
+ if (listItemNode.__key === selection.anchor.key) {
184
+ selection.anchor.set(paragraph.getKey(), 0, "element");
220
185
  }
221
- listNode.remove();
186
+ if (listItemNode.__key === selection.focus.key) {
187
+ selection.focus.set(paragraph.getKey(), 0, "element");
188
+ }
189
+ listItemNode.remove();
222
190
  }
223
- } catch (err) {
224
- _iterator.e(err);
225
- } finally {
226
- _iterator.f();
191
+ listNode.remove();
227
192
  }
228
193
  }
229
194
  });
230
195
  }
231
- function updateChildrenListItemValue(list, children) {
232
- var childrenOrExisting = children || list.getChildren();
196
+ export function updateChildrenListItemValue(list, children) {
197
+ const childrenOrExisting = children || list.getChildren();
233
198
  if (childrenOrExisting !== undefined) {
234
- for (var i = 0; i < childrenOrExisting.length; i++) {
235
- var child = childrenOrExisting[i];
236
- if ((0, _ListItemNode.$isListItemNode)(child)) {
237
- var prevValue = child.getValue();
238
- var nextValue = $getListItemValue(child);
199
+ for (let i = 0; i < childrenOrExisting.length; i++) {
200
+ const child = childrenOrExisting[i];
201
+ if ($isListItemNode(child)) {
202
+ const prevValue = child.getValue();
203
+ const nextValue = $getListItemValue(child);
239
204
  if (prevValue !== nextValue) {
240
205
  child.setValue(nextValue);
241
206
  }
@@ -243,55 +208,55 @@ function updateChildrenListItemValue(list, children) {
243
208
  }
244
209
  }
245
210
  }
246
- function $handleIndent(WebinyListItemNodes) {
211
+ export function $handleIndent(WebinyListItemNodes) {
247
212
  // go through each node and decide where to move it.
248
- var removed = new Set();
249
- WebinyListItemNodes.forEach(function (WebinyListItemNode) {
250
- if ((0, _listNode.isNestedListNode)(WebinyListItemNode) || removed.has(WebinyListItemNode.getKey())) {
213
+ const removed = new Set();
214
+ WebinyListItemNodes.forEach(WebinyListItemNode => {
215
+ if (isNestedListNode(WebinyListItemNode) || removed.has(WebinyListItemNode.getKey())) {
251
216
  return;
252
217
  }
253
- var parent = WebinyListItemNode.getParent();
218
+ const parent = WebinyListItemNode.getParent();
254
219
 
255
220
  // We can cast both of the below `isNestedListNode` only returns a boolean type instead of a user-defined type guards
256
- var nextSibling = WebinyListItemNode.getNextSibling();
257
- var previousSibling = WebinyListItemNode.getPreviousSibling();
221
+ const nextSibling = WebinyListItemNode.getNextSibling();
222
+ const previousSibling = WebinyListItemNode.getPreviousSibling();
258
223
  // if there are nested lists on either side, merge them all together.
259
224
 
260
- if ((0, _listNode.isNestedListNode)(nextSibling) && (0, _listNode.isNestedListNode)(previousSibling)) {
261
- var innerList = previousSibling.getFirstChild();
262
- if ((0, _ListNode.$isListNode)(innerList)) {
225
+ if (isNestedListNode(nextSibling) && isNestedListNode(previousSibling)) {
226
+ const innerList = previousSibling.getFirstChild();
227
+ if ($isListNode(innerList)) {
263
228
  innerList.append(WebinyListItemNode);
264
- var nextInnerList = nextSibling.getFirstChild();
265
- if ((0, _ListNode.$isListNode)(nextInnerList)) {
266
- var children = nextInnerList.getChildren();
229
+ const nextInnerList = nextSibling.getFirstChild();
230
+ if ($isListNode(nextInnerList)) {
231
+ const children = nextInnerList.getChildren();
267
232
  append(innerList, children);
268
233
  nextSibling.remove();
269
234
  removed.add(nextSibling.getKey());
270
235
  }
271
236
  updateChildrenListItemValue(innerList);
272
237
  }
273
- } else if ((0, _listNode.isNestedListNode)(nextSibling)) {
238
+ } else if (isNestedListNode(nextSibling)) {
274
239
  // if the WebinyListItemNode is next to a nested ListNode, merge them
275
- var _innerList = nextSibling.getFirstChild();
276
- if ((0, _ListNode.$isListNode)(_innerList)) {
277
- var firstChild = _innerList.getFirstChild();
240
+ const innerList = nextSibling.getFirstChild();
241
+ if ($isListNode(innerList)) {
242
+ const firstChild = innerList.getFirstChild();
278
243
  if (firstChild !== null) {
279
244
  firstChild.insertBefore(WebinyListItemNode);
280
245
  }
281
- updateChildrenListItemValue(_innerList);
246
+ updateChildrenListItemValue(innerList);
282
247
  }
283
- } else if ((0, _listNode.isNestedListNode)(previousSibling)) {
284
- var _innerList2 = previousSibling.getFirstChild();
285
- if ((0, _ListNode.$isListNode)(_innerList2)) {
286
- _innerList2.append(WebinyListItemNode);
287
- updateChildrenListItemValue(_innerList2);
248
+ } else if (isNestedListNode(previousSibling)) {
249
+ const innerList = previousSibling.getFirstChild();
250
+ if ($isListNode(innerList)) {
251
+ innerList.append(WebinyListItemNode);
252
+ updateChildrenListItemValue(innerList);
288
253
  }
289
254
  } else {
290
255
  // otherwise, we need to create a new nested ListNode
291
256
 
292
- if ((0, _ListNode.$isListNode)(parent)) {
293
- var newListItem = (0, _ListItemNode.$createListItemNode)();
294
- var newList = (0, _ListNode.$createListNode)(parent.getListType(), parent.getStyleId());
257
+ if ($isListNode(parent)) {
258
+ const newListItem = $createListItemNode();
259
+ const newList = $createListNode(parent.getListType(), parent.getStyleId());
295
260
  newListItem.append(newList);
296
261
  newList.append(WebinyListItemNode);
297
262
  if (previousSibling) {
@@ -303,28 +268,28 @@ function $handleIndent(WebinyListItemNodes) {
303
268
  }
304
269
  }
305
270
  }
306
- if ((0, _ListNode.$isListNode)(parent)) {
271
+ if ($isListNode(parent)) {
307
272
  updateChildrenListItemValue(parent);
308
273
  }
309
274
  });
310
275
  }
311
- function $handleOutdent(WebinyListItemNodes) {
276
+ export function $handleOutdent(WebinyListItemNodes) {
312
277
  // go through each node and decide where to move it.
313
278
 
314
- WebinyListItemNodes.forEach(function (WebinyListItemNode) {
315
- if ((0, _listNode.isNestedListNode)(WebinyListItemNode)) {
279
+ WebinyListItemNodes.forEach(WebinyListItemNode => {
280
+ if (isNestedListNode(WebinyListItemNode)) {
316
281
  return;
317
282
  }
318
- var parentList = WebinyListItemNode.getParent();
319
- var grandparentListItem = parentList ? parentList.getParent() : undefined;
320
- var greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined;
283
+ const parentList = WebinyListItemNode.getParent();
284
+ const grandparentListItem = parentList ? parentList.getParent() : undefined;
285
+ const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined;
321
286
  // If it doesn't have these ancestors, it's not indented.
322
287
 
323
- if ((0, _ListNode.$isListNode)(greatGrandparentList) && (0, _ListItemNode.$isListItemNode)(grandparentListItem) && (0, _ListNode.$isListNode)(parentList)) {
288
+ if ($isListNode(greatGrandparentList) && $isListItemNode(grandparentListItem) && $isListNode(parentList)) {
324
289
  // if it's the first child in it's parent list, insert it into the
325
290
  // great grandparent list before the grandparent
326
- var firstChild = parentList ? parentList.getFirstChild() : undefined;
327
- var lastChild = parentList ? parentList.getLastChild() : undefined;
291
+ const firstChild = parentList ? parentList.getFirstChild() : undefined;
292
+ const lastChild = parentList ? parentList.getLastChild() : undefined;
328
293
  if (WebinyListItemNode.is(firstChild)) {
329
294
  grandparentListItem.insertBefore(WebinyListItemNode);
330
295
  if (parentList.isEmpty()) {
@@ -339,16 +304,14 @@ function $handleOutdent(WebinyListItemNodes) {
339
304
  }
340
305
  } else {
341
306
  // otherwise, we need to split the siblings into two new nested lists
342
- var listType = parentList.getListType();
343
- var themeStyleId = parentList.getStyleId();
344
- var previousSiblingsListItem = (0, _ListItemNode.$createListItemNode)();
345
- var previousSiblingsList = (0, _ListNode.$createListNode)(listType, themeStyleId);
307
+ const listType = parentList.getListType();
308
+ const themeStyleId = parentList.getStyleId();
309
+ const previousSiblingsListItem = $createListItemNode();
310
+ const previousSiblingsList = $createListNode(listType, themeStyleId);
346
311
  previousSiblingsListItem.append(previousSiblingsList);
347
- WebinyListItemNode.getPreviousSiblings().forEach(function (sibling) {
348
- return previousSiblingsList.append(sibling);
349
- });
350
- var nextSiblingsListItem = (0, _ListItemNode.$createListItemNode)();
351
- var nextSiblingsList = (0, _ListNode.$createListNode)(listType, themeStyleId);
312
+ WebinyListItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
313
+ const nextSiblingsListItem = $createListItemNode();
314
+ const nextSiblingsList = $createListNode(listType, themeStyleId);
352
315
  nextSiblingsListItem.append(nextSiblingsList);
353
316
  append(nextSiblingsList, WebinyListItemNode.getNextSiblings());
354
317
  // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
@@ -363,24 +326,24 @@ function $handleOutdent(WebinyListItemNodes) {
363
326
  });
364
327
  }
365
328
  function maybeIndentOrOutdent(direction) {
366
- var selection = (0, _lexical.$getSelection)();
367
- if (!(0, _lexical.$isRangeSelection)(selection)) {
329
+ const selection = $getSelection();
330
+ if (!$isRangeSelection(selection)) {
368
331
  return;
369
332
  }
370
- var selectedNodes = selection.getNodes();
371
- var webinyListItemNodes = [];
333
+ const selectedNodes = selection.getNodes();
334
+ let webinyListItemNodes = [];
372
335
  if (selectedNodes.length === 0) {
373
336
  selectedNodes.push(selection.anchor.getNode());
374
337
  }
375
338
  if (selectedNodes.length === 1) {
376
339
  // Only 1 node selected. Selection may not contain the ListNodeItem so we traverse the tree to
377
340
  // find whether this is part of a WebinyListItemNode
378
- var nearestWebinyListItemNode = (0, _listNode.findNearestListItemNode)(selectedNodes[0]);
341
+ const nearestWebinyListItemNode = findNearestListItemNode(selectedNodes[0]);
379
342
  if (nearestWebinyListItemNode !== null) {
380
343
  webinyListItemNodes = [nearestWebinyListItemNode];
381
344
  }
382
345
  } else {
383
- webinyListItemNodes = (0, _listNode.getUniqueListItemNodes)(selectedNodes);
346
+ webinyListItemNodes = getUniqueListItemNodes(selectedNodes);
384
347
  }
385
348
  if (webinyListItemNodes.length > 0) {
386
349
  if (direction === "indent") {
@@ -390,59 +353,59 @@ function maybeIndentOrOutdent(direction) {
390
353
  }
391
354
  }
392
355
  }
393
- function indentList() {
356
+ export function indentList() {
394
357
  maybeIndentOrOutdent("indent");
395
358
  }
396
- function outdentList() {
359
+ export function outdentList() {
397
360
  maybeIndentOrOutdent("outdent");
398
361
  }
399
- function $handleListInsertParagraph() {
400
- var selection = (0, _lexical.$getSelection)();
401
- if (!(0, _lexical.$isRangeSelection)(selection) || !selection.isCollapsed()) {
362
+ export function $handleListInsertParagraph() {
363
+ const selection = $getSelection();
364
+ if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
402
365
  return false;
403
366
  }
404
367
 
405
368
  // Only run this code on empty list items
406
- var anchor = selection.anchor.getNode();
407
- if (!(0, _ListItemNode.$isListItemNode)(anchor) || anchor.getTextContent() !== "") {
369
+ const anchor = selection.anchor.getNode();
370
+ if (!$isListItemNode(anchor) || anchor.getTextContent() !== "") {
408
371
  return false;
409
372
  }
410
- var topListNode = (0, _listNode.$getTopListNode)(anchor);
411
- var parent = anchor.getParent();
412
- if (!(0, _ListNode.$isListNode)(parent)) {
373
+ const topListNode = $getTopListNode(anchor);
374
+ const parent = anchor.getParent();
375
+ if (!$isListNode(parent)) {
413
376
  console.log("A WebinyListItemNode must have a WebinyListNode for a parent.");
414
377
  return false;
415
378
  }
416
- var grandparent = parent?.getParent() || null;
417
- var replacementNode;
418
- if ((0, _lexical.$isRootOrShadowRoot)(grandparent)) {
419
- replacementNode = (0, _ParagraphNode.$createParagraphNode)();
379
+ const grandparent = parent?.getParent() || null;
380
+ let replacementNode;
381
+ if ($isRootOrShadowRoot(grandparent)) {
382
+ replacementNode = $createParagraphNode();
420
383
  topListNode.insertAfter(replacementNode);
421
- } else if ((0, _ListItemNode.$isListItemNode)(grandparent)) {
422
- replacementNode = (0, _ListItemNode.$createListItemNode)();
384
+ } else if ($isListItemNode(grandparent)) {
385
+ replacementNode = $createListItemNode();
423
386
  grandparent.insertAfter(replacementNode);
424
387
  } else {
425
388
  return false;
426
389
  }
427
390
  replacementNode.select();
428
- var nextSiblings = anchor.getNextSiblings();
391
+ const nextSiblings = anchor.getNextSiblings();
429
392
  if (nextSiblings.length > 0) {
430
- var newList = (0, _ListNode.$createListNode)(parent?.getListType(), parent?.getStyleId());
431
- if ((0, _lexical.$isParagraphNode)(replacementNode)) {
393
+ const newList = $createListNode(parent?.getListType(), parent?.getStyleId());
394
+ if ($isParagraphNode(replacementNode)) {
432
395
  replacementNode.insertAfter(newList);
433
396
  } else {
434
- var newListItem = (0, _ListItemNode.$createListItemNode)();
397
+ const newListItem = $createListItemNode();
435
398
  newListItem.append(newList);
436
399
  replacementNode.insertAfter(newListItem);
437
400
  }
438
- nextSiblings.forEach(function (sibling) {
401
+ nextSiblings.forEach(sibling => {
439
402
  sibling.remove();
440
403
  newList.append(sibling);
441
404
  });
442
405
  }
443
406
 
444
407
  // Don't leave hanging nested empty lists
445
- (0, _listNode.$removeHighestEmptyListParent)(anchor);
408
+ $removeHighestEmptyListParent(anchor);
446
409
  return true;
447
410
  }
448
411