@react-fabric/lexical 1.0.0-beta.60 → 1.0.0-beta.61

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 (127) hide show
  1. package/dist/cjs/{packages/lexical/src/components → components}/StickyComponent.js +2 -3
  2. package/dist/cjs/{packages/lexical/src/editor → editor}/LexicalEditor.js +5 -5
  3. package/dist/cjs/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +101 -95
  4. package/dist/cjs/i18n/ar.json.js +24 -0
  5. package/dist/cjs/i18n/en.json.js +24 -0
  6. package/dist/cjs/i18n/index.js +33 -0
  7. package/dist/cjs/{packages/lexical/src/index.js → index.js} +1 -0
  8. package/dist/cjs/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +5 -5
  9. package/dist/cjs/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +35 -22
  10. package/dist/esm/{packages/lexical/src/components → components}/StickyComponent.js +2 -3
  11. package/dist/esm/{packages/lexical/src/editor → editor}/LexicalEditor.js +4 -4
  12. package/dist/esm/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +43 -37
  13. package/dist/esm/i18n/ar.json.js +21 -0
  14. package/dist/esm/i18n/en.json.js +21 -0
  15. package/dist/esm/i18n/index.js +33 -0
  16. package/dist/esm/{packages/lexical/src/index.js → index.js} +1 -0
  17. package/dist/esm/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +2 -2
  18. package/dist/esm/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +36 -23
  19. package/dist/types/hooks/useFormatWatcher.d.ts +1 -0
  20. package/dist/types/i18n/index.d.ts +1 -0
  21. package/dist/types/index.d.ts +1 -0
  22. package/package.json +5 -5
  23. package/src/components/StickyComponent.tsx +2 -3
  24. package/src/hooks/useFormatWatcher.ts +3 -0
  25. package/src/i18n/ar.json +16 -0
  26. package/src/i18n/en.json +16 -0
  27. package/src/i18n/index.ts +28 -0
  28. package/src/index.ts +2 -0
  29. package/src/plugins/ToolbarPlugin.tsx +34 -23
  30. package/dist/cjs/_virtual/prism.js +0 -5
  31. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -474
  32. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
  33. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
  34. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1537
  35. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
  36. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -57
  37. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -252
  38. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
  39. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
  40. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -572
  41. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
  42. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -25
  43. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1614
  44. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
  45. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -36
  46. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -838
  47. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
  48. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
  49. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -1057
  50. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -39
  51. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -45
  52. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -4207
  53. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
  54. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -68
  55. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -1166
  56. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -47
  57. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -81
  58. package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
  59. package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
  60. package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
  61. package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
  62. package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
  63. package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
  64. package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
  65. package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
  66. package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
  67. package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
  68. package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
  69. package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
  70. package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
  71. package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
  72. package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
  73. package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
  74. package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
  75. package/dist/esm/_virtual/prism.js +0 -5
  76. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -465
  77. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
  78. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
  79. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1512
  80. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
  81. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
  82. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -251
  83. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
  84. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
  85. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -563
  86. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
  87. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
  88. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1595
  89. package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
  90. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -17
  91. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -830
  92. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
  93. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
  94. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -1028
  95. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -28
  96. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
  97. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -4156
  98. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
  99. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
  100. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -1102
  101. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -32
  102. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
  103. package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
  104. package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
  105. package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
  106. package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
  107. package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
  108. package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
  109. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
  110. package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
  111. package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
  112. package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
  113. package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
  114. package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
  115. package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
  116. package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
  117. package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
  118. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
  119. package/dist/esm/node_modules/prismjs/prism.js +0 -1951
  120. /package/dist/cjs/{packages/lexical/src/editor → editor}/theme.js +0 -0
  121. /package/dist/cjs/{packages/lexical/src/nodes → nodes}/StickyNode.js +0 -0
  122. /package/dist/cjs/{packages/lexical/src/plugins → plugins}/StickyPlugin.js +0 -0
  123. /package/dist/cjs/{packages/lexical/src/utils → utils}/index.js +0 -0
  124. /package/dist/esm/{packages/lexical/src/editor → editor}/theme.js +0 -0
  125. /package/dist/esm/{packages/lexical/src/nodes → nodes}/StickyNode.js +0 -0
  126. /package/dist/esm/{packages/lexical/src/plugins → plugins}/StickyPlugin.js +0 -0
  127. /package/dist/esm/{packages/lexical/src/utils → utils}/index.js +0 -0
@@ -1,1595 +0,0 @@
1
- 'use client';
2
-
3
- import { $getNearestNodeOfType, removeClassNamesFromElement, addClassNamesToElement, isHTMLElement, mergeRegister, $findMatchingParent, calculateZoomLevel } from '../utils/LexicalUtils.js';
4
- import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, $createParagraphNode, $isElementNode, $isLeafNode, $setPointFromCaret, $normalizeCaret, $getChildCaret, ElementNode, buildImportMap, $isParagraphNode, $applyNodeReplacement, $createTextNode, createCommand, COMMAND_PRIORITY_LOW, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_SPACE_COMMAND, $getNearestNodeFromDOMNode, KEY_ARROW_LEFT_COMMAND, $getNodeByKey, INSERT_PARAGRAPH_COMMAND, $isTextNode, TextNode, getNearestEditorFromDOMNode } from 'lexical';
5
- import { getStyleObjectFromCSS } from '../selection/LexicalSelection.js';
6
-
7
- /**
8
- * Copyright (c) Meta Platforms, Inc. and affiliates.
9
- *
10
- * This source code is licensed under the MIT license found in the
11
- * LICENSE file in the root directory of this source tree.
12
- *
13
- */
14
-
15
-
16
- /**
17
- * Copyright (c) Meta Platforms, Inc. and affiliates.
18
- *
19
- * This source code is licensed under the MIT license found in the
20
- * LICENSE file in the root directory of this source tree.
21
- *
22
- */
23
-
24
- // Do not require this module directly! Use normal `invariant` calls.
25
-
26
- function formatDevErrorMessage(message) {
27
- throw new Error(message);
28
- }
29
-
30
- /**
31
- * Checks the depth of listNode from the root node.
32
- * @param listNode - The ListNode to be checked.
33
- * @returns The depth of the ListNode.
34
- */
35
- function $getListDepth(listNode) {
36
- let depth = 1;
37
- let parent = listNode.getParent();
38
- while (parent != null) {
39
- if ($isListItemNode(parent)) {
40
- const parentList = parent.getParent();
41
- if ($isListNode(parentList)) {
42
- depth++;
43
- parent = parentList.getParent();
44
- continue;
45
- }
46
- {
47
- formatDevErrorMessage(`A ListItemNode must have a ListNode for a parent.`);
48
- }
49
- }
50
- return depth;
51
- }
52
- return depth;
53
- }
54
-
55
- /**
56
- * Finds the nearest ancestral ListNode and returns it, throws an invariant if listItem is not a ListItemNode.
57
- * @param listItem - The node to be checked.
58
- * @returns The ListNode found.
59
- */
60
- function $getTopListNode(listItem) {
61
- let list = listItem.getParent();
62
- if (!$isListNode(list)) {
63
- {
64
- formatDevErrorMessage(`A ListItemNode must have a ListNode for a parent.`);
65
- }
66
- }
67
- let parent = list;
68
- while (parent !== null) {
69
- parent = parent.getParent();
70
- if ($isListNode(parent)) {
71
- list = parent;
72
- }
73
- }
74
- return list;
75
- }
76
-
77
- /**
78
- * A recursive Depth-First Search (Postorder Traversal) that finds all of a node's children
79
- * that are of type ListItemNode and returns them in an array.
80
- * @param node - The ListNode to start the search.
81
- * @returns An array containing all nodes of type ListItemNode found.
82
- */
83
- // This should probably be $getAllChildrenOfType
84
- function $getAllListItems(node) {
85
- let listItemNodes = [];
86
- const listChildren = node.getChildren().filter($isListItemNode);
87
- for (let i = 0; i < listChildren.length; i++) {
88
- const listItemNode = listChildren[i];
89
- const firstChild = listItemNode.getFirstChild();
90
- if ($isListNode(firstChild)) {
91
- listItemNodes = listItemNodes.concat($getAllListItems(firstChild));
92
- } else {
93
- listItemNodes.push(listItemNode);
94
- }
95
- }
96
- return listItemNodes;
97
- }
98
-
99
- /**
100
- * Checks to see if the passed node is a ListItemNode and has a ListNode as a child.
101
- * @param node - The node to be checked.
102
- * @returns true if the node is a ListItemNode and has a ListNode child, false otherwise.
103
- */
104
- function isNestedListNode(node) {
105
- return $isListItemNode(node) && $isListNode(node.getFirstChild());
106
- }
107
-
108
- /**
109
- * Takes a deeply nested ListNode or ListItemNode and traverses up the branch to delete the first
110
- * ancestral ListNode (which could be the root ListNode) or ListItemNode with siblings, essentially
111
- * bringing the deeply nested node up the branch once. Would remove sublist if it has siblings.
112
- * Should not break ListItem -> List -> ListItem chain as empty List/ItemNodes should be removed on .remove().
113
- * @param sublist - The nested ListNode or ListItemNode to be brought up the branch.
114
- */
115
- function $removeHighestEmptyListParent(sublist) {
116
- // Nodes may be repeatedly indented, to create deeply nested lists that each
117
- // contain just one bullet.
118
- // Our goal is to remove these (empty) deeply nested lists. The easiest
119
- // way to do that is crawl back up the tree until we find a node that has siblings
120
- // (e.g. is actually part of the list contents) and delete that, or delete
121
- // the root of the list (if no list nodes have siblings.)
122
- let emptyListPtr = sublist;
123
- while (emptyListPtr.getNextSibling() == null && emptyListPtr.getPreviousSibling() == null) {
124
- const parent = emptyListPtr.getParent();
125
- if (parent == null || !($isListItemNode(parent) || $isListNode(parent))) {
126
- break;
127
- }
128
- emptyListPtr = parent;
129
- }
130
- emptyListPtr.remove();
131
- }
132
-
133
- /**
134
- * Wraps a node into a ListItemNode.
135
- * @param node - The node to be wrapped into a ListItemNode
136
- * @returns The ListItemNode which the passed node is wrapped in.
137
- */
138
- function $wrapInListItem(node) {
139
- const listItemWrapper = $createListItemNode();
140
- return listItemWrapper.append(node);
141
- }
142
-
143
- function $isSelectingEmptyListItem(anchorNode, nodes) {
144
- return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
145
- }
146
-
147
- /**
148
- * Inserts a new ListNode. If the selection's anchor node is an empty ListItemNode and is a child of
149
- * the root/shadow root, it will replace the ListItemNode with a ListNode and the old ListItemNode.
150
- * Otherwise it will replace its parent with a new ListNode and re-insert the ListItemNode and any previous children.
151
- * If the selection's anchor node is not an empty ListItemNode, it will add a new ListNode or merge an existing ListNode,
152
- * unless the the node is a leaf node, in which case it will attempt to find a ListNode up the branch and replace it with
153
- * a new ListNode, or create a new ListNode at the nearest root/shadow root.
154
- * @param listType - The type of list, "number" | "bullet" | "check".
155
- */
156
- function $insertList(listType) {
157
- const selection = $getSelection();
158
- if (selection !== null) {
159
- let nodes = selection.getNodes();
160
- if ($isRangeSelection(selection)) {
161
- const anchorAndFocus = selection.getStartEndPoints();
162
- if (!(anchorAndFocus !== null)) {
163
- formatDevErrorMessage(`insertList: anchor should be defined`);
164
- }
165
- const [anchor] = anchorAndFocus;
166
- const anchorNode = anchor.getNode();
167
- const anchorNodeParent = anchorNode.getParent();
168
- if ($isRootOrShadowRoot(anchorNode)) {
169
- const firstChild = anchorNode.getFirstChild();
170
- if (firstChild) {
171
- nodes = firstChild.selectStart().getNodes();
172
- } else {
173
- const paragraph = $createParagraphNode();
174
- anchorNode.append(paragraph);
175
- nodes = paragraph.select().getNodes();
176
- }
177
- } else if ($isSelectingEmptyListItem(anchorNode, nodes)) {
178
- const list = $createListNode(listType);
179
- if ($isRootOrShadowRoot(anchorNodeParent)) {
180
- anchorNode.replace(list);
181
- const listItem = $createListItemNode();
182
- if ($isElementNode(anchorNode)) {
183
- listItem.setFormat(anchorNode.getFormatType());
184
- listItem.setIndent(anchorNode.getIndent());
185
- }
186
- list.append(listItem);
187
- } else if ($isListItemNode(anchorNode)) {
188
- const parent = anchorNode.getParentOrThrow();
189
- append(list, parent.getChildren());
190
- parent.replace(list);
191
- }
192
- return;
193
- }
194
- }
195
- const handled = new Set();
196
- for (let i = 0; i < nodes.length; i++) {
197
- const node = nodes[i];
198
- if ($isElementNode(node) && node.isEmpty() && !$isListItemNode(node) && !handled.has(node.getKey())) {
199
- $createListOrMerge(node, listType);
200
- continue;
201
- }
202
- let parent = $isLeafNode(node) ? node.getParent() : $isListItemNode(node) && node.isEmpty() ? node : null;
203
- while (parent != null) {
204
- const parentKey = parent.getKey();
205
- if ($isListNode(parent)) {
206
- if (!handled.has(parentKey)) {
207
- const newListNode = $createListNode(listType);
208
- append(newListNode, parent.getChildren());
209
- parent.replace(newListNode);
210
- handled.add(parentKey);
211
- }
212
- break;
213
- } else {
214
- const nextParent = parent.getParent();
215
- if ($isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) {
216
- handled.add(parentKey);
217
- $createListOrMerge(parent, listType);
218
- break;
219
- }
220
- parent = nextParent;
221
- }
222
- }
223
- }
224
- }
225
- }
226
- function append(node, nodesToAppend) {
227
- node.splice(node.getChildrenSize(), 0, nodesToAppend);
228
- }
229
- function $createListOrMerge(node, listType) {
230
- if ($isListNode(node)) {
231
- return node;
232
- }
233
- const previousSibling = node.getPreviousSibling();
234
- const nextSibling = node.getNextSibling();
235
- const listItem = $createListItemNode();
236
- append(listItem, node.getChildren());
237
- let targetList;
238
- if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
239
- previousSibling.append(listItem);
240
- // if the same type of list is on both sides, merge them.
241
- if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
242
- append(previousSibling, nextSibling.getChildren());
243
- nextSibling.remove();
244
- }
245
- targetList = previousSibling;
246
- } else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
247
- nextSibling.getFirstChildOrThrow().insertBefore(listItem);
248
- targetList = nextSibling;
249
- } else {
250
- const list = $createListNode(listType);
251
- list.append(listItem);
252
- node.replace(list);
253
- targetList = list;
254
- }
255
- // listItem needs to be attached to root prior to setting indent
256
- listItem.setFormat(node.getFormatType());
257
- listItem.setIndent(node.getIndent());
258
- node.remove();
259
- return targetList;
260
- }
261
-
262
- /**
263
- * A recursive function that goes through each list and their children, including nested lists,
264
- * appending list2 children after list1 children and updating ListItemNode values.
265
- * @param list1 - The first list to be merged.
266
- * @param list2 - The second list to be merged.
267
- */
268
- function mergeLists(list1, list2) {
269
- const listItem1 = list1.getLastChild();
270
- const listItem2 = list2.getFirstChild();
271
- if (listItem1 && listItem2 && isNestedListNode(listItem1) && isNestedListNode(listItem2)) {
272
- mergeLists(listItem1.getFirstChild(), listItem2.getFirstChild());
273
- listItem2.remove();
274
- }
275
- const toMerge = list2.getChildren();
276
- if (toMerge.length > 0) {
277
- list1.append(...toMerge);
278
- }
279
- list2.remove();
280
- }
281
-
282
- /**
283
- * Searches for the nearest ancestral ListNode and removes it. If selection is an empty ListItemNode
284
- * it will remove the whole list, including the ListItemNode. For each ListItemNode in the ListNode,
285
- * removeList will also generate new ParagraphNodes in the removed ListNode's place. Any child node
286
- * inside a ListItemNode will be appended to the new ParagraphNodes.
287
- */
288
- function $removeList() {
289
- const selection = $getSelection();
290
- if ($isRangeSelection(selection)) {
291
- const listNodes = new Set();
292
- const nodes = selection.getNodes();
293
- const anchorNode = selection.anchor.getNode();
294
- if ($isSelectingEmptyListItem(anchorNode, nodes)) {
295
- listNodes.add($getTopListNode(anchorNode));
296
- } else {
297
- for (let i = 0; i < nodes.length; i++) {
298
- const node = nodes[i];
299
- if ($isLeafNode(node)) {
300
- const listItemNode = $getNearestNodeOfType(node, ListItemNode);
301
- if (listItemNode != null) {
302
- listNodes.add($getTopListNode(listItemNode));
303
- }
304
- }
305
- }
306
- }
307
- for (const listNode of listNodes) {
308
- let insertionPoint = listNode;
309
- const listItems = $getAllListItems(listNode);
310
- for (const listItemNode of listItems) {
311
- const paragraph = $createParagraphNode().setTextStyle(selection.style).setTextFormat(selection.format);
312
- append(paragraph, listItemNode.getChildren());
313
- insertionPoint.insertAfter(paragraph);
314
- insertionPoint = paragraph;
315
-
316
- // When the anchor and focus fall on the textNode
317
- // we don't have to change the selection because the textNode will be appended to
318
- // the newly generated paragraph.
319
- // When selection is in empty nested list item, selection is actually on the listItemNode.
320
- // When the corresponding listItemNode is deleted and replaced by the newly generated paragraph
321
- // we should manually set the selection's focus and anchor to the newly generated paragraph.
322
- if (listItemNode.__key === selection.anchor.key) {
323
- $setPointFromCaret(selection.anchor, $normalizeCaret($getChildCaret(paragraph, 'next')));
324
- }
325
- if (listItemNode.__key === selection.focus.key) {
326
- $setPointFromCaret(selection.focus, $normalizeCaret($getChildCaret(paragraph, 'next')));
327
- }
328
- listItemNode.remove();
329
- }
330
- listNode.remove();
331
- }
332
- }
333
- }
334
-
335
- /**
336
- * Takes the value of a child ListItemNode and makes it the value the ListItemNode
337
- * should be if it isn't already. Also ensures that checked is undefined if the
338
- * parent does not have a list type of 'check'.
339
- * @param list - The list whose children are updated.
340
- */
341
- function updateChildrenListItemValue(list) {
342
- const isNotChecklist = list.getListType() !== 'check';
343
- let value = list.getStart();
344
- for (const child of list.getChildren()) {
345
- if ($isListItemNode(child)) {
346
- if (child.getValue() !== value) {
347
- child.setValue(value);
348
- }
349
- if (isNotChecklist && child.getLatest().__checked != null) {
350
- child.setChecked(undefined);
351
- }
352
- if (!$isListNode(child.getFirstChild())) {
353
- value++;
354
- }
355
- }
356
- }
357
- }
358
-
359
- /**
360
- * Merge the next sibling list if same type.
361
- * <ul> will merge with <ul>, but NOT <ul> with <ol>.
362
- * @param list - The list whose next sibling should be potentially merged
363
- */
364
- function mergeNextSiblingListIfSameType(list) {
365
- const nextSibling = list.getNextSibling();
366
- if ($isListNode(nextSibling) && list.getListType() === nextSibling.getListType()) {
367
- mergeLists(list, nextSibling);
368
- }
369
- }
370
-
371
- /**
372
- * Adds an empty ListNode/ListItemNode chain at listItemNode, so as to
373
- * create an indent effect. Won't indent ListItemNodes that have a ListNode as
374
- * a child, but does merge sibling ListItemNodes if one has a nested ListNode.
375
- * @param listItemNode - The ListItemNode to be indented.
376
- */
377
- function $handleIndent(listItemNode) {
378
- // go through each node and decide where to move it.
379
- const removed = new Set();
380
- if (isNestedListNode(listItemNode) || removed.has(listItemNode.getKey())) {
381
- return;
382
- }
383
- const parent = listItemNode.getParent();
384
-
385
- // We can cast both of the below `isNestedListNode` only returns a boolean type instead of a user-defined type guards
386
- const nextSibling = listItemNode.getNextSibling();
387
- const previousSibling = listItemNode.getPreviousSibling();
388
- // if there are nested lists on either side, merge them all together.
389
-
390
- if (isNestedListNode(nextSibling) && isNestedListNode(previousSibling)) {
391
- const innerList = previousSibling.getFirstChild();
392
- if ($isListNode(innerList)) {
393
- innerList.append(listItemNode);
394
- const nextInnerList = nextSibling.getFirstChild();
395
- if ($isListNode(nextInnerList)) {
396
- const children = nextInnerList.getChildren();
397
- append(innerList, children);
398
- nextSibling.remove();
399
- removed.add(nextSibling.getKey());
400
- }
401
- }
402
- } else if (isNestedListNode(nextSibling)) {
403
- // if the ListItemNode is next to a nested ListNode, merge them
404
- const innerList = nextSibling.getFirstChild();
405
- if ($isListNode(innerList)) {
406
- const firstChild = innerList.getFirstChild();
407
- if (firstChild !== null) {
408
- firstChild.insertBefore(listItemNode);
409
- }
410
- }
411
- } else if (isNestedListNode(previousSibling)) {
412
- const innerList = previousSibling.getFirstChild();
413
- if ($isListNode(innerList)) {
414
- innerList.append(listItemNode);
415
- }
416
- } else {
417
- // otherwise, we need to create a new nested ListNode
418
-
419
- if ($isListNode(parent)) {
420
- const newListItem = $createListItemNode().setTextFormat(listItemNode.getTextFormat()).setTextStyle(listItemNode.getTextStyle());
421
- const newList = $createListNode(parent.getListType()).setTextFormat(parent.getTextFormat()).setTextStyle(parent.getTextStyle());
422
- newListItem.append(newList);
423
- newList.append(listItemNode);
424
- if (previousSibling) {
425
- previousSibling.insertAfter(newListItem);
426
- } else if (nextSibling) {
427
- nextSibling.insertBefore(newListItem);
428
- } else {
429
- parent.append(newListItem);
430
- }
431
- }
432
- }
433
- }
434
-
435
- /**
436
- * Removes an indent by removing an empty ListNode/ListItemNode chain. An indented ListItemNode
437
- * has a great grandparent node of type ListNode, which is where the ListItemNode will reside
438
- * within as a child.
439
- * @param listItemNode - The ListItemNode to remove the indent (outdent).
440
- */
441
- function $handleOutdent(listItemNode) {
442
- // go through each node and decide where to move it.
443
-
444
- if (isNestedListNode(listItemNode)) {
445
- return;
446
- }
447
- const parentList = listItemNode.getParent();
448
- const grandparentListItem = parentList ? parentList.getParent() : undefined;
449
- const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined;
450
- // If it doesn't have these ancestors, it's not indented.
451
-
452
- if ($isListNode(greatGrandparentList) && $isListItemNode(grandparentListItem) && $isListNode(parentList)) {
453
- // if it's the first child in it's parent list, insert it into the
454
- // great grandparent list before the grandparent
455
- const firstChild = parentList ? parentList.getFirstChild() : undefined;
456
- const lastChild = parentList ? parentList.getLastChild() : undefined;
457
- if (listItemNode.is(firstChild)) {
458
- grandparentListItem.insertBefore(listItemNode);
459
- if (parentList.isEmpty()) {
460
- grandparentListItem.remove();
461
- }
462
- // if it's the last child in it's parent list, insert it into the
463
- // great grandparent list after the grandparent.
464
- } else if (listItemNode.is(lastChild)) {
465
- grandparentListItem.insertAfter(listItemNode);
466
- if (parentList.isEmpty()) {
467
- grandparentListItem.remove();
468
- }
469
- } else {
470
- // otherwise, we need to split the siblings into two new nested lists
471
- const listType = parentList.getListType();
472
- const previousSiblingsListItem = $createListItemNode();
473
- const previousSiblingsList = $createListNode(listType);
474
- previousSiblingsListItem.append(previousSiblingsList);
475
- listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
476
- const nextSiblingsListItem = $createListItemNode();
477
- const nextSiblingsList = $createListNode(listType);
478
- nextSiblingsListItem.append(nextSiblingsList);
479
- append(nextSiblingsList, listItemNode.getNextSiblings());
480
- // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
481
- grandparentListItem.insertBefore(previousSiblingsListItem);
482
- grandparentListItem.insertAfter(nextSiblingsListItem);
483
- // replace the grandparent list item (now between the siblings) with the outdented list item.
484
- grandparentListItem.replace(listItemNode);
485
- }
486
- }
487
- }
488
-
489
- /**
490
- * Attempts to insert a ParagraphNode at selection and selects the new node. The selection must contain a ListItemNode
491
- * or a node that does not already contain text. If its grandparent is the root/shadow root, it will get the ListNode
492
- * (which should be the parent node) and insert the ParagraphNode as a sibling to the ListNode. If the ListNode is
493
- * nested in a ListItemNode instead, it will add the ParagraphNode after the grandparent ListItemNode.
494
- * Throws an invariant if the selection is not a child of a ListNode.
495
- * @returns true if a ParagraphNode was inserted successfully, false if there is no selection
496
- * or the selection does not contain a ListItemNode or the node already holds text.
497
- */
498
- function $handleListInsertParagraph() {
499
- const selection = $getSelection();
500
- if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
501
- return false;
502
- }
503
- // Only run this code on empty list items
504
- const anchor = selection.anchor.getNode();
505
- if (!$isListItemNode(anchor) || anchor.getChildrenSize() !== 0) {
506
- return false;
507
- }
508
- const topListNode = $getTopListNode(anchor);
509
- const parent = anchor.getParent();
510
- if (!$isListNode(parent)) {
511
- formatDevErrorMessage(`A ListItemNode must have a ListNode for a parent.`);
512
- }
513
- const grandparent = parent.getParent();
514
- let replacementNode;
515
- if ($isRootOrShadowRoot(grandparent)) {
516
- replacementNode = $createParagraphNode();
517
- topListNode.insertAfter(replacementNode);
518
- } else if ($isListItemNode(grandparent)) {
519
- replacementNode = $createListItemNode();
520
- grandparent.insertAfter(replacementNode);
521
- } else {
522
- return false;
523
- }
524
- replacementNode.setTextStyle(selection.style).setTextFormat(selection.format).select();
525
- const nextSiblings = anchor.getNextSiblings();
526
- if (nextSiblings.length > 0) {
527
- const newList = $createListNode(parent.getListType());
528
- if ($isListItemNode(replacementNode)) {
529
- const newListItem = $createListItemNode();
530
- newListItem.append(newList);
531
- replacementNode.insertAfter(newListItem);
532
- } else {
533
- replacementNode.insertAfter(newList);
534
- }
535
- newList.append(...nextSiblings);
536
- }
537
-
538
- // Don't leave hanging nested empty lists
539
- $removeHighestEmptyListParent(anchor);
540
- return true;
541
- }
542
-
543
- /**
544
- * Copyright (c) Meta Platforms, Inc. and affiliates.
545
- *
546
- * This source code is licensed under the MIT license found in the
547
- * LICENSE file in the root directory of this source tree.
548
- *
549
- */
550
-
551
- function normalizeClassNames(...classNames) {
552
- const rval = [];
553
- for (const className of classNames) {
554
- if (className && typeof className === 'string') {
555
- for (const [s] of className.matchAll(/\S+/g)) {
556
- rval.push(s);
557
- }
558
- }
559
- }
560
- return rval;
561
- }
562
-
563
- function applyMarkerStyles(dom, node, prevNode) {
564
- const styles = getStyleObjectFromCSS(node.__textStyle);
565
- for (const k in styles) {
566
- dom.style.setProperty(`--listitem-marker-${k}`, styles[k]);
567
- }
568
- if (prevNode) {
569
- for (const k in getStyleObjectFromCSS(prevNode.__textStyle)) {
570
- if (!(k in styles)) {
571
- dom.style.removeProperty(`--listitem-marker-${k}`);
572
- }
573
- }
574
- }
575
- }
576
-
577
- /** @noInheritDoc */
578
- class ListItemNode extends ElementNode {
579
- /** @internal */
580
-
581
- /** @internal */
582
-
583
- /** @internal */
584
- $config() {
585
- return this.config('listitem', {
586
- $transform: node => {
587
- if (node.__checked == null) {
588
- return;
589
- }
590
- const parent = node.getParent();
591
- if ($isListNode(parent)) {
592
- if (parent.getListType() !== 'check' && node.getChecked() != null) {
593
- node.setChecked(undefined);
594
- }
595
- }
596
- },
597
- extends: ElementNode,
598
- importDOM: buildImportMap({
599
- li: () => ({
600
- conversion: $convertListItemElement,
601
- priority: 0
602
- })
603
- })
604
- });
605
- }
606
- constructor(value = 1, checked = undefined, key) {
607
- super(key);
608
- this.__value = value === undefined ? 1 : value;
609
- this.__checked = checked;
610
- }
611
- afterCloneFrom(prevNode) {
612
- super.afterCloneFrom(prevNode);
613
- this.__value = prevNode.__value;
614
- this.__checked = prevNode.__checked;
615
- }
616
- createDOM(config) {
617
- const element = document.createElement('li');
618
- this.updateListItemDOM(null, element, config);
619
- return element;
620
- }
621
- updateListItemDOM(prevNode, dom, config) {
622
- const parent = this.getParent();
623
- if ($isListNode(parent) && parent.getListType() === 'check') {
624
- updateListItemChecked(dom, this, prevNode);
625
- }
626
- dom.value = this.__value;
627
- $setListItemThemeClassNames(dom, config.theme, this);
628
- const prevStyle = prevNode ? prevNode.__style : '';
629
- const nextStyle = this.__style;
630
- if (prevStyle !== nextStyle) {
631
- if (nextStyle === '') {
632
- dom.removeAttribute('style');
633
- } else {
634
- dom.style.cssText = nextStyle;
635
- }
636
- }
637
- applyMarkerStyles(dom, this, prevNode);
638
- }
639
- updateDOM(prevNode, dom, config) {
640
- // @ts-expect-error - this is always HTMLListItemElement
641
- const element = dom;
642
- this.updateListItemDOM(prevNode, element, config);
643
- return false;
644
- }
645
- updateFromJSON(serializedNode) {
646
- return super.updateFromJSON(serializedNode).setValue(serializedNode.value).setChecked(serializedNode.checked);
647
- }
648
- exportDOM(editor) {
649
- const element = this.createDOM(editor._config);
650
- const formatType = this.getFormatType();
651
- if (formatType) {
652
- element.style.textAlign = formatType;
653
- }
654
- const direction = this.getDirection();
655
- if (direction) {
656
- element.dir = direction;
657
- }
658
- return {
659
- element
660
- };
661
- }
662
- exportJSON() {
663
- return {
664
- ...super.exportJSON(),
665
- checked: this.getChecked(),
666
- value: this.getValue()
667
- };
668
- }
669
- append(...nodes) {
670
- for (let i = 0; i < nodes.length; i++) {
671
- const node = nodes[i];
672
- if ($isElementNode(node) && this.canMergeWith(node)) {
673
- const children = node.getChildren();
674
- this.append(...children);
675
- node.remove();
676
- } else {
677
- super.append(node);
678
- }
679
- }
680
- return this;
681
- }
682
- replace(replaceWithNode, includeChildren) {
683
- if ($isListItemNode(replaceWithNode)) {
684
- return super.replace(replaceWithNode);
685
- }
686
- this.setIndent(0);
687
- const list = this.getParentOrThrow();
688
- if (!$isListNode(list)) {
689
- return replaceWithNode;
690
- }
691
- if (list.__first === this.getKey()) {
692
- list.insertBefore(replaceWithNode);
693
- } else if (list.__last === this.getKey()) {
694
- list.insertAfter(replaceWithNode);
695
- } else {
696
- // Split the list
697
- const newList = $createListNode(list.getListType());
698
- let nextSibling = this.getNextSibling();
699
- while (nextSibling) {
700
- const nodeToAppend = nextSibling;
701
- nextSibling = nextSibling.getNextSibling();
702
- newList.append(nodeToAppend);
703
- }
704
- list.insertAfter(replaceWithNode);
705
- replaceWithNode.insertAfter(newList);
706
- }
707
- if (includeChildren) {
708
- if (!$isElementNode(replaceWithNode)) {
709
- formatDevErrorMessage(`includeChildren should only be true for ElementNodes`);
710
- }
711
- this.getChildren().forEach(child => {
712
- replaceWithNode.append(child);
713
- });
714
- }
715
- this.remove();
716
- if (list.getChildrenSize() === 0) {
717
- list.remove();
718
- }
719
- return replaceWithNode;
720
- }
721
- insertAfter(node, restoreSelection = true) {
722
- const listNode = this.getParentOrThrow();
723
- if (!$isListNode(listNode)) {
724
- {
725
- formatDevErrorMessage(`insertAfter: list node is not parent of list item node`);
726
- }
727
- }
728
- if ($isListItemNode(node)) {
729
- return super.insertAfter(node, restoreSelection);
730
- }
731
- const siblings = this.getNextSiblings();
732
-
733
- // Split the lists and insert the node in between them
734
- listNode.insertAfter(node, restoreSelection);
735
- if (siblings.length !== 0) {
736
- const newListNode = $createListNode(listNode.getListType());
737
- siblings.forEach(sibling => newListNode.append(sibling));
738
- node.insertAfter(newListNode, restoreSelection);
739
- }
740
- return node;
741
- }
742
- remove(preserveEmptyParent) {
743
- const prevSibling = this.getPreviousSibling();
744
- const nextSibling = this.getNextSibling();
745
- super.remove(preserveEmptyParent);
746
- if (prevSibling && nextSibling && isNestedListNode(prevSibling) && isNestedListNode(nextSibling)) {
747
- mergeLists(prevSibling.getFirstChild(), nextSibling.getFirstChild());
748
- nextSibling.remove();
749
- }
750
- }
751
- insertNewAfter(_, restoreSelection = true) {
752
- const newElement = $createListItemNode().updateFromJSON(this.exportJSON()).setChecked(this.getChecked() ? false : undefined);
753
- this.insertAfter(newElement, restoreSelection);
754
- return newElement;
755
- }
756
- collapseAtStart(selection) {
757
- const paragraph = $createParagraphNode();
758
- const children = this.getChildren();
759
- children.forEach(child => paragraph.append(child));
760
- const listNode = this.getParentOrThrow();
761
- const listNodeParent = listNode.getParentOrThrow();
762
- const isIndented = $isListItemNode(listNodeParent);
763
- if (listNode.getChildrenSize() === 1) {
764
- if (isIndented) {
765
- // if the list node is nested, we just want to remove it,
766
- // effectively unindenting it.
767
- listNode.remove();
768
- listNodeParent.select();
769
- } else {
770
- listNode.insertBefore(paragraph);
771
- listNode.remove();
772
- // If we have selection on the list item, we'll need to move it
773
- // to the paragraph
774
- const anchor = selection.anchor;
775
- const focus = selection.focus;
776
- const key = paragraph.getKey();
777
- if (anchor.type === 'element' && anchor.getNode().is(this)) {
778
- anchor.set(key, anchor.offset, 'element');
779
- }
780
- if (focus.type === 'element' && focus.getNode().is(this)) {
781
- focus.set(key, focus.offset, 'element');
782
- }
783
- }
784
- } else {
785
- listNode.insertBefore(paragraph);
786
- this.remove();
787
- }
788
- return true;
789
- }
790
- getValue() {
791
- const self = this.getLatest();
792
- return self.__value;
793
- }
794
- setValue(value) {
795
- const self = this.getWritable();
796
- self.__value = value;
797
- return self;
798
- }
799
- getChecked() {
800
- const self = this.getLatest();
801
- let listType;
802
- const parent = this.getParent();
803
- if ($isListNode(parent)) {
804
- listType = parent.getListType();
805
- }
806
- return listType === 'check' ? Boolean(self.__checked) : undefined;
807
- }
808
- setChecked(checked) {
809
- const self = this.getWritable();
810
- self.__checked = checked;
811
- return self;
812
- }
813
- toggleChecked() {
814
- const self = this.getWritable();
815
- return self.setChecked(!self.__checked);
816
- }
817
- getIndent() {
818
- // If we don't have a parent, we are likely serializing
819
- const parent = this.getParent();
820
- if (parent === null || !this.isAttached()) {
821
- return this.getLatest().__indent;
822
- }
823
- // ListItemNode should always have a ListNode for a parent.
824
- let listNodeParent = parent.getParentOrThrow();
825
- let indentLevel = 0;
826
- while ($isListItemNode(listNodeParent)) {
827
- listNodeParent = listNodeParent.getParentOrThrow().getParentOrThrow();
828
- indentLevel++;
829
- }
830
- return indentLevel;
831
- }
832
- setIndent(indent) {
833
- if (!(typeof indent === 'number')) {
834
- formatDevErrorMessage(`Invalid indent value.`);
835
- }
836
- indent = Math.floor(indent);
837
- if (!(indent >= 0)) {
838
- formatDevErrorMessage(`Indent value must be non-negative.`);
839
- }
840
- let currentIndent = this.getIndent();
841
- while (currentIndent !== indent) {
842
- if (currentIndent < indent) {
843
- $handleIndent(this);
844
- currentIndent++;
845
- } else {
846
- $handleOutdent(this);
847
- currentIndent--;
848
- }
849
- }
850
- return this;
851
- }
852
-
853
- /** @deprecated @internal */
854
- canInsertAfter(node) {
855
- return $isListItemNode(node);
856
- }
857
-
858
- /** @deprecated @internal */
859
- canReplaceWith(replacement) {
860
- return $isListItemNode(replacement);
861
- }
862
- canMergeWith(node) {
863
- return $isListItemNode(node) || $isParagraphNode(node);
864
- }
865
- extractWithChild(child, selection) {
866
- if (!$isRangeSelection(selection)) {
867
- return false;
868
- }
869
- const anchorNode = selection.anchor.getNode();
870
- const focusNode = selection.focus.getNode();
871
- return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && this.getTextContent().length === selection.getTextContent().length;
872
- }
873
- isParentRequired() {
874
- return true;
875
- }
876
- createParentElementNode() {
877
- return $createListNode('bullet');
878
- }
879
- canMergeWhenEmpty() {
880
- return true;
881
- }
882
- }
883
- function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
884
- const classesToAdd = [];
885
- const classesToRemove = [];
886
- const listTheme = editorThemeClasses.list;
887
- const listItemClassName = listTheme ? listTheme.listitem : undefined;
888
- let nestedListItemClassName;
889
- if (listTheme && listTheme.nested) {
890
- nestedListItemClassName = listTheme.nested.listitem;
891
- }
892
- if (listItemClassName !== undefined) {
893
- classesToAdd.push(...normalizeClassNames(listItemClassName));
894
- }
895
- if (listTheme) {
896
- const parentNode = node.getParent();
897
- const isCheckList = $isListNode(parentNode) && parentNode.getListType() === 'check';
898
- const checked = node.getChecked();
899
- if (!isCheckList || checked) {
900
- classesToRemove.push(listTheme.listitemUnchecked);
901
- }
902
- if (!isCheckList || !checked) {
903
- classesToRemove.push(listTheme.listitemChecked);
904
- }
905
- if (isCheckList) {
906
- classesToAdd.push(checked ? listTheme.listitemChecked : listTheme.listitemUnchecked);
907
- }
908
- }
909
- if (nestedListItemClassName !== undefined) {
910
- const nestedListItemClasses = normalizeClassNames(nestedListItemClassName);
911
- if (node.getChildren().some(child => $isListNode(child))) {
912
- classesToAdd.push(...nestedListItemClasses);
913
- } else {
914
- classesToRemove.push(...nestedListItemClasses);
915
- }
916
- }
917
- if (classesToRemove.length > 0) {
918
- removeClassNamesFromElement(dom, ...classesToRemove);
919
- }
920
- if (classesToAdd.length > 0) {
921
- addClassNamesToElement(dom, ...classesToAdd);
922
- }
923
- }
924
- function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
925
- // Only add attributes for leaf list items
926
- if ($isListNode(listItemNode.getFirstChild())) {
927
- dom.removeAttribute('role');
928
- dom.removeAttribute('tabIndex');
929
- dom.removeAttribute('aria-checked');
930
- } else {
931
- dom.setAttribute('role', 'checkbox');
932
- dom.setAttribute('tabIndex', '-1');
933
- if (!prevListItemNode || listItemNode.__checked !== prevListItemNode.__checked) {
934
- dom.setAttribute('aria-checked', listItemNode.getChecked() ? 'true' : 'false');
935
- }
936
- }
937
- }
938
- function $convertListItemElement(domNode) {
939
- const isGitHubCheckList = domNode.classList.contains('task-list-item');
940
- if (isGitHubCheckList) {
941
- for (const child of domNode.children) {
942
- if (child.tagName === 'INPUT') {
943
- return $convertCheckboxInput(child);
944
- }
945
- }
946
- }
947
- const ariaCheckedAttr = domNode.getAttribute('aria-checked');
948
- const checked = ariaCheckedAttr === 'true' ? true : ariaCheckedAttr === 'false' ? false : undefined;
949
- return {
950
- node: $createListItemNode(checked)
951
- };
952
- }
953
- function $convertCheckboxInput(domNode) {
954
- const isCheckboxInput = domNode.getAttribute('type') === 'checkbox';
955
- if (!isCheckboxInput) {
956
- return {
957
- node: null
958
- };
959
- }
960
- const checked = domNode.hasAttribute('checked');
961
- return {
962
- node: $createListItemNode(checked)
963
- };
964
- }
965
-
966
- /**
967
- * Creates a new List Item node, passing true/false will convert it to a checkbox input.
968
- * @param checked - Is the List Item a checkbox and, if so, is it checked? undefined/null: not a checkbox, true/false is a checkbox and checked/unchecked, respectively.
969
- * @returns The new List Item.
970
- */
971
- function $createListItemNode(checked) {
972
- return $applyNodeReplacement(new ListItemNode(undefined, checked));
973
- }
974
-
975
- /**
976
- * Checks to see if the node is a ListItemNode.
977
- * @param node - The node to be checked.
978
- * @returns true if the node is a ListItemNode, false otherwise.
979
- */
980
- function $isListItemNode(node) {
981
- return node instanceof ListItemNode;
982
- }
983
-
984
- /**
985
- * Copyright (c) Meta Platforms, Inc. and affiliates.
986
- *
987
- * This source code is licensed under the MIT license found in the
988
- * LICENSE file in the root directory of this source tree.
989
- *
990
- */
991
-
992
- /** @noInheritDoc */
993
- class ListNode extends ElementNode {
994
- /** @internal */
995
-
996
- /** @internal */
997
-
998
- /** @internal */
999
-
1000
- /** @internal */
1001
- $config() {
1002
- return this.config('list', {
1003
- $transform: node => {
1004
- mergeNextSiblingListIfSameType(node);
1005
- updateChildrenListItemValue(node);
1006
- },
1007
- extends: ElementNode,
1008
- importDOM: buildImportMap({
1009
- ol: () => ({
1010
- conversion: $convertListNode,
1011
- priority: 0
1012
- }),
1013
- ul: () => ({
1014
- conversion: $convertListNode,
1015
- priority: 0
1016
- })
1017
- })
1018
- });
1019
- }
1020
- constructor(listType = 'number', start = 1, key) {
1021
- super(key);
1022
- const _listType = TAG_TO_LIST_TYPE[listType] || listType;
1023
- this.__listType = _listType;
1024
- this.__tag = _listType === 'number' ? 'ol' : 'ul';
1025
- this.__start = start;
1026
- }
1027
- afterCloneFrom(prevNode) {
1028
- super.afterCloneFrom(prevNode);
1029
- this.__listType = prevNode.__listType;
1030
- this.__tag = prevNode.__tag;
1031
- this.__start = prevNode.__start;
1032
- }
1033
- getTag() {
1034
- return this.getLatest().__tag;
1035
- }
1036
- setListType(type) {
1037
- const writable = this.getWritable();
1038
- writable.__listType = type;
1039
- writable.__tag = type === 'number' ? 'ol' : 'ul';
1040
- return writable;
1041
- }
1042
- getListType() {
1043
- return this.getLatest().__listType;
1044
- }
1045
- getStart() {
1046
- return this.getLatest().__start;
1047
- }
1048
- setStart(start) {
1049
- const self = this.getWritable();
1050
- self.__start = start;
1051
- return self;
1052
- }
1053
-
1054
- // View
1055
-
1056
- createDOM(config, _editor) {
1057
- const tag = this.__tag;
1058
- const dom = document.createElement(tag);
1059
- if (this.__start !== 1) {
1060
- dom.setAttribute('start', String(this.__start));
1061
- }
1062
- // @ts-expect-error Internal field.
1063
- dom.__lexicalListType = this.__listType;
1064
- $setListThemeClassNames(dom, config.theme, this);
1065
- return dom;
1066
- }
1067
- updateDOM(prevNode, dom, config) {
1068
- if (prevNode.__tag !== this.__tag) {
1069
- return true;
1070
- }
1071
- $setListThemeClassNames(dom, config.theme, this);
1072
- return false;
1073
- }
1074
- updateFromJSON(serializedNode) {
1075
- return super.updateFromJSON(serializedNode).setListType(serializedNode.listType).setStart(serializedNode.start);
1076
- }
1077
- exportDOM(editor) {
1078
- const element = this.createDOM(editor._config, editor);
1079
- if (isHTMLElement(element)) {
1080
- if (this.__start !== 1) {
1081
- element.setAttribute('start', String(this.__start));
1082
- }
1083
- if (this.__listType === 'check') {
1084
- element.setAttribute('__lexicalListType', 'check');
1085
- }
1086
- }
1087
- return {
1088
- element
1089
- };
1090
- }
1091
- exportJSON() {
1092
- return {
1093
- ...super.exportJSON(),
1094
- listType: this.getListType(),
1095
- start: this.getStart(),
1096
- tag: this.getTag()
1097
- };
1098
- }
1099
- canBeEmpty() {
1100
- return false;
1101
- }
1102
- canIndent() {
1103
- return false;
1104
- }
1105
- splice(start, deleteCount, nodesToInsert) {
1106
- let listItemNodesToInsert = nodesToInsert;
1107
- for (let i = 0; i < nodesToInsert.length; i++) {
1108
- const node = nodesToInsert[i];
1109
- if (!$isListItemNode(node)) {
1110
- if (listItemNodesToInsert === nodesToInsert) {
1111
- listItemNodesToInsert = [...nodesToInsert];
1112
- }
1113
- listItemNodesToInsert[i] = $createListItemNode().append($isElementNode(node) && !($isListNode(node) || node.isInline()) ? $createTextNode(node.getTextContent()) : node);
1114
- }
1115
- }
1116
- return super.splice(start, deleteCount, listItemNodesToInsert);
1117
- }
1118
- extractWithChild(child) {
1119
- return $isListItemNode(child);
1120
- }
1121
- }
1122
- function $setListThemeClassNames(dom, editorThemeClasses, node) {
1123
- const classesToAdd = [];
1124
- const classesToRemove = [];
1125
- const listTheme = editorThemeClasses.list;
1126
- if (listTheme !== undefined) {
1127
- const listLevelsClassNames = listTheme[`${node.__tag}Depth`] || [];
1128
- const listDepth = $getListDepth(node) - 1;
1129
- const normalizedListDepth = listDepth % listLevelsClassNames.length;
1130
- const listLevelClassName = listLevelsClassNames[normalizedListDepth];
1131
- const listClassName = listTheme[node.__tag];
1132
- let nestedListClassName;
1133
- const nestedListTheme = listTheme.nested;
1134
- const checklistClassName = listTheme.checklist;
1135
- if (nestedListTheme !== undefined && nestedListTheme.list) {
1136
- nestedListClassName = nestedListTheme.list;
1137
- }
1138
- if (listClassName !== undefined) {
1139
- classesToAdd.push(listClassName);
1140
- }
1141
- if (checklistClassName !== undefined && node.__listType === 'check') {
1142
- classesToAdd.push(checklistClassName);
1143
- }
1144
- if (listLevelClassName !== undefined) {
1145
- classesToAdd.push(...normalizeClassNames(listLevelClassName));
1146
- for (let i = 0; i < listLevelsClassNames.length; i++) {
1147
- if (i !== normalizedListDepth) {
1148
- classesToRemove.push(node.__tag + i);
1149
- }
1150
- }
1151
- }
1152
- if (nestedListClassName !== undefined) {
1153
- const nestedListItemClasses = normalizeClassNames(nestedListClassName);
1154
- if (listDepth > 1) {
1155
- classesToAdd.push(...nestedListItemClasses);
1156
- } else {
1157
- classesToRemove.push(...nestedListItemClasses);
1158
- }
1159
- }
1160
- }
1161
- if (classesToRemove.length > 0) {
1162
- removeClassNamesFromElement(dom, ...classesToRemove);
1163
- }
1164
- if (classesToAdd.length > 0) {
1165
- addClassNamesToElement(dom, ...classesToAdd);
1166
- }
1167
- }
1168
-
1169
- /*
1170
- * This function normalizes the children of a ListNode after the conversion from HTML,
1171
- * ensuring that they are all ListItemNodes and contain either a single nested ListNode
1172
- * or some other inline content.
1173
- */
1174
- function $normalizeChildren(nodes) {
1175
- const normalizedListItems = [];
1176
- for (let i = 0; i < nodes.length; i++) {
1177
- const node = nodes[i];
1178
- if ($isListItemNode(node)) {
1179
- normalizedListItems.push(node);
1180
- const children = node.getChildren();
1181
- if (children.length > 1) {
1182
- children.forEach(child => {
1183
- if ($isListNode(child)) {
1184
- normalizedListItems.push($wrapInListItem(child));
1185
- }
1186
- });
1187
- }
1188
- } else {
1189
- normalizedListItems.push($wrapInListItem(node));
1190
- }
1191
- }
1192
- return normalizedListItems;
1193
- }
1194
- function isDomChecklist(domNode) {
1195
- if (domNode.getAttribute('__lexicallisttype') === 'check' ||
1196
- // is github checklist
1197
- domNode.classList.contains('contains-task-list')) {
1198
- return true;
1199
- }
1200
- // if children are checklist items, the node is a checklist ul. Applicable for googledoc checklist pasting.
1201
- for (const child of domNode.childNodes) {
1202
- if (isHTMLElement(child) && child.hasAttribute('aria-checked')) {
1203
- return true;
1204
- }
1205
- }
1206
- return false;
1207
- }
1208
- function $convertListNode(domNode) {
1209
- const nodeName = domNode.nodeName.toLowerCase();
1210
- let node = null;
1211
- if (nodeName === 'ol') {
1212
- // @ts-ignore
1213
- const start = domNode.start;
1214
- node = $createListNode('number', start);
1215
- } else if (nodeName === 'ul') {
1216
- if (isDomChecklist(domNode)) {
1217
- node = $createListNode('check');
1218
- } else {
1219
- node = $createListNode('bullet');
1220
- }
1221
- }
1222
- return {
1223
- after: $normalizeChildren,
1224
- node
1225
- };
1226
- }
1227
- const TAG_TO_LIST_TYPE = {
1228
- ol: 'number',
1229
- ul: 'bullet'
1230
- };
1231
-
1232
- /**
1233
- * Creates a ListNode of listType.
1234
- * @param listType - The type of list to be created. Can be 'number', 'bullet', or 'check'.
1235
- * @param start - Where an ordered list starts its count, start = 1 if left undefined.
1236
- * @returns The new ListNode
1237
- */
1238
- function $createListNode(listType = 'number', start = 1) {
1239
- return $applyNodeReplacement(new ListNode(listType, start));
1240
- }
1241
-
1242
- /**
1243
- * Checks to see if the node is a ListNode.
1244
- * @param node - The node to be checked.
1245
- * @returns true if the node is a ListNode, false otherwise.
1246
- */
1247
- function $isListNode(node) {
1248
- return node instanceof ListNode;
1249
- }
1250
-
1251
- /**
1252
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1253
- *
1254
- * This source code is licensed under the MIT license found in the
1255
- * LICENSE file in the root directory of this source tree.
1256
- *
1257
- */
1258
-
1259
- const INSERT_CHECK_LIST_COMMAND = createCommand('INSERT_CHECK_LIST_COMMAND');
1260
- function registerCheckList(editor) {
1261
- return mergeRegister(editor.registerCommand(INSERT_CHECK_LIST_COMMAND, () => {
1262
- $insertList('check');
1263
- return true;
1264
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_DOWN_COMMAND, event => {
1265
- return handleArrowUpOrDown(event, editor, false);
1266
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_UP_COMMAND, event => {
1267
- return handleArrowUpOrDown(event, editor, true);
1268
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ESCAPE_COMMAND, () => {
1269
- const activeItem = getActiveCheckListItem();
1270
- if (activeItem != null) {
1271
- const rootElement = editor.getRootElement();
1272
- if (rootElement != null) {
1273
- rootElement.focus();
1274
- }
1275
- return true;
1276
- }
1277
- return false;
1278
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_SPACE_COMMAND, event => {
1279
- const activeItem = getActiveCheckListItem();
1280
- if (activeItem != null && editor.isEditable()) {
1281
- editor.update(() => {
1282
- const listItemNode = $getNearestNodeFromDOMNode(activeItem);
1283
- if ($isListItemNode(listItemNode)) {
1284
- event.preventDefault();
1285
- listItemNode.toggleChecked();
1286
- }
1287
- });
1288
- return true;
1289
- }
1290
- return false;
1291
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_LEFT_COMMAND, event => {
1292
- return editor.getEditorState().read(() => {
1293
- const selection = $getSelection();
1294
- if ($isRangeSelection(selection) && selection.isCollapsed()) {
1295
- const {
1296
- anchor
1297
- } = selection;
1298
- const isElement = anchor.type === 'element';
1299
- if (isElement || anchor.offset === 0) {
1300
- const anchorNode = anchor.getNode();
1301
- const elementNode = $findMatchingParent(anchorNode, node => $isElementNode(node) && !node.isInline());
1302
- if ($isListItemNode(elementNode)) {
1303
- const parent = elementNode.getParent();
1304
- if ($isListNode(parent) && parent.getListType() === 'check' && (isElement || elementNode.getFirstDescendant() === anchorNode)) {
1305
- const domNode = editor.getElementByKey(elementNode.__key);
1306
- if (domNode != null && document.activeElement !== domNode) {
1307
- domNode.focus();
1308
- event.preventDefault();
1309
- return true;
1310
- }
1311
- }
1312
- }
1313
- }
1314
- }
1315
- return false;
1316
- });
1317
- }, COMMAND_PRIORITY_LOW), editor.registerRootListener((rootElement, prevElement) => {
1318
- if (rootElement !== null) {
1319
- rootElement.addEventListener('click', handleClick);
1320
- rootElement.addEventListener('pointerdown', handlePointerDown);
1321
- }
1322
- if (prevElement !== null) {
1323
- prevElement.removeEventListener('click', handleClick);
1324
- prevElement.removeEventListener('pointerdown', handlePointerDown);
1325
- }
1326
- }));
1327
- }
1328
- function handleCheckItemEvent(event, callback) {
1329
- const target = event.target;
1330
- if (!isHTMLElement(target)) {
1331
- return;
1332
- }
1333
-
1334
- // Ignore clicks on LI that have nested lists
1335
- const firstChild = target.firstChild;
1336
- if (isHTMLElement(firstChild) && (firstChild.tagName === 'UL' || firstChild.tagName === 'OL')) {
1337
- return;
1338
- }
1339
- const parentNode = target.parentNode;
1340
-
1341
- // @ts-ignore internal field
1342
- if (!parentNode || parentNode.__lexicalListType !== 'check') {
1343
- return;
1344
- }
1345
- const rect = target.getBoundingClientRect();
1346
- const zoom = calculateZoomLevel(target);
1347
- const clientX = event.clientX / zoom;
1348
-
1349
- // Use getComputedStyle if available, otherwise fallback to 0px width
1350
- const beforeStyles = window.getComputedStyle ? window.getComputedStyle(target, '::before') : {
1351
- width: '0px'
1352
- };
1353
- const beforeWidthInPixels = parseFloat(beforeStyles.width);
1354
-
1355
- // Make click area slightly larger for touch devices to improve accessibility
1356
- const isTouchEvent = event.pointerType === 'touch';
1357
- const clickAreaPadding = isTouchEvent ? 32 : 0; // Add 32px padding for touch events
1358
-
1359
- if (target.dir === 'rtl' ? clientX < rect.right + clickAreaPadding && clientX > rect.right - beforeWidthInPixels - clickAreaPadding : clientX > rect.left - clickAreaPadding && clientX < rect.left + beforeWidthInPixels + clickAreaPadding) {
1360
- callback();
1361
- }
1362
- }
1363
- function handleClick(event) {
1364
- handleCheckItemEvent(event, () => {
1365
- if (isHTMLElement(event.target)) {
1366
- const domNode = event.target;
1367
- const editor = getNearestEditorFromDOMNode(domNode);
1368
- if (editor != null && editor.isEditable()) {
1369
- editor.update(() => {
1370
- const node = $getNearestNodeFromDOMNode(domNode);
1371
- if ($isListItemNode(node)) {
1372
- domNode.focus();
1373
- node.toggleChecked();
1374
- }
1375
- });
1376
- }
1377
- }
1378
- });
1379
- }
1380
- function handlePointerDown(event) {
1381
- handleCheckItemEvent(event, () => {
1382
- // Prevents caret moving when clicking on check mark
1383
- event.preventDefault();
1384
- });
1385
- }
1386
- function getActiveCheckListItem() {
1387
- const activeElement = document.activeElement;
1388
- return isHTMLElement(activeElement) && activeElement.tagName === 'LI' && activeElement.parentNode != null &&
1389
- // @ts-ignore internal field
1390
- activeElement.parentNode.__lexicalListType === 'check' ? activeElement : null;
1391
- }
1392
- function findCheckListItemSibling(node, backward) {
1393
- let sibling = backward ? node.getPreviousSibling() : node.getNextSibling();
1394
- let parent = node;
1395
-
1396
- // Going up in a tree to get non-null sibling
1397
- while (sibling == null && $isListItemNode(parent)) {
1398
- // Get li -> parent ul/ol -> parent li
1399
- parent = parent.getParentOrThrow().getParent();
1400
- if (parent != null) {
1401
- sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling();
1402
- }
1403
- }
1404
-
1405
- // Going down in a tree to get first non-nested list item
1406
- while ($isListItemNode(sibling)) {
1407
- const firstChild = backward ? sibling.getLastChild() : sibling.getFirstChild();
1408
- if (!$isListNode(firstChild)) {
1409
- return sibling;
1410
- }
1411
- sibling = backward ? firstChild.getLastChild() : firstChild.getFirstChild();
1412
- }
1413
- return null;
1414
- }
1415
- function handleArrowUpOrDown(event, editor, backward) {
1416
- const activeItem = getActiveCheckListItem();
1417
- if (activeItem != null) {
1418
- editor.update(() => {
1419
- const listItem = $getNearestNodeFromDOMNode(activeItem);
1420
- if (!$isListItemNode(listItem)) {
1421
- return;
1422
- }
1423
- const nextListItem = findCheckListItemSibling(listItem, backward);
1424
- if (nextListItem != null) {
1425
- nextListItem.selectStart();
1426
- const dom = editor.getElementByKey(nextListItem.__key);
1427
- if (dom != null) {
1428
- event.preventDefault();
1429
- setTimeout(() => {
1430
- dom.focus();
1431
- }, 0);
1432
- }
1433
- }
1434
- });
1435
- }
1436
- return false;
1437
- }
1438
-
1439
- /**
1440
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1441
- *
1442
- * This source code is licensed under the MIT license found in the
1443
- * LICENSE file in the root directory of this source tree.
1444
- *
1445
- */
1446
-
1447
- const UPDATE_LIST_START_COMMAND = createCommand('UPDATE_LIST_START_COMMAND');
1448
- const INSERT_UNORDERED_LIST_COMMAND = createCommand('INSERT_UNORDERED_LIST_COMMAND');
1449
- const INSERT_ORDERED_LIST_COMMAND = createCommand('INSERT_ORDERED_LIST_COMMAND');
1450
- const REMOVE_LIST_COMMAND = createCommand('REMOVE_LIST_COMMAND');
1451
- function registerList(editor) {
1452
- const removeListener = mergeRegister(editor.registerCommand(INSERT_ORDERED_LIST_COMMAND, () => {
1453
- $insertList('number');
1454
- return true;
1455
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(UPDATE_LIST_START_COMMAND, payload => {
1456
- const {
1457
- listNodeKey,
1458
- newStart
1459
- } = payload;
1460
- const listNode = $getNodeByKey(listNodeKey);
1461
- if (!$isListNode(listNode)) {
1462
- return false;
1463
- }
1464
- if (listNode.getListType() === 'number') {
1465
- listNode.setStart(newStart);
1466
- updateChildrenListItemValue(listNode);
1467
- }
1468
- return true;
1469
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(INSERT_UNORDERED_LIST_COMMAND, () => {
1470
- $insertList('bullet');
1471
- return true;
1472
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(REMOVE_LIST_COMMAND, () => {
1473
- $removeList();
1474
- return true;
1475
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(INSERT_PARAGRAPH_COMMAND, () => $handleListInsertParagraph(), COMMAND_PRIORITY_LOW), editor.registerNodeTransform(ListItemNode, node => {
1476
- const firstChild = node.getFirstChild();
1477
- if (firstChild) {
1478
- if ($isTextNode(firstChild)) {
1479
- const style = firstChild.getStyle();
1480
- const format = firstChild.getFormat();
1481
- if (node.getTextStyle() !== style) {
1482
- node.setTextStyle(style);
1483
- }
1484
- if (node.getTextFormat() !== format) {
1485
- node.setTextFormat(format);
1486
- }
1487
- }
1488
- } else {
1489
- // If it's empty, check the selection
1490
- const selection = $getSelection();
1491
- if ($isRangeSelection(selection) && (selection.style !== node.getTextStyle() || selection.format !== node.getTextFormat()) && selection.isCollapsed() && node.is(selection.anchor.getNode())) {
1492
- node.setTextStyle(selection.style).setTextFormat(selection.format);
1493
- }
1494
- }
1495
- }), editor.registerNodeTransform(TextNode, node => {
1496
- const listItemParentNode = node.getParent();
1497
- if ($isListItemNode(listItemParentNode) && node.is(listItemParentNode.getFirstChild())) {
1498
- const style = node.getStyle();
1499
- const format = node.getFormat();
1500
- if (style !== listItemParentNode.getTextStyle() || format !== listItemParentNode.getTextFormat()) {
1501
- listItemParentNode.setTextStyle(style).setTextFormat(format);
1502
- }
1503
- }
1504
- }));
1505
- return removeListener;
1506
- }
1507
- function registerListStrictIndentTransform(editor) {
1508
- const $formatListIndentStrict = listItemNode => {
1509
- const listNode = listItemNode.getParent();
1510
- if ($isListNode(listItemNode.getFirstChild()) || !$isListNode(listNode)) {
1511
- return;
1512
- }
1513
- const startingListItemNode = $findMatchingParent(listItemNode, node => $isListItemNode(node) && $isListNode(node.getParent()) && $isListItemNode(node.getPreviousSibling()));
1514
- if (startingListItemNode === null && listItemNode.getIndent() > 0) {
1515
- listItemNode.setIndent(0);
1516
- } else if ($isListItemNode(startingListItemNode)) {
1517
- const prevListItemNode = startingListItemNode.getPreviousSibling();
1518
- if ($isListItemNode(prevListItemNode)) {
1519
- const endListItemNode = $findChildrenEndListItemNode(prevListItemNode);
1520
- const endListNode = endListItemNode.getParent();
1521
- if ($isListNode(endListNode)) {
1522
- const prevDepth = $getListDepth(endListNode);
1523
- const depth = $getListDepth(listNode);
1524
- if (prevDepth + 1 < depth) {
1525
- listItemNode.setIndent(prevDepth);
1526
- }
1527
- }
1528
- }
1529
- }
1530
- };
1531
- const $processListWithStrictIndent = listNode => {
1532
- const queue = [listNode];
1533
- while (queue.length > 0) {
1534
- const node = queue.shift();
1535
- if (!$isListNode(node)) {
1536
- continue;
1537
- }
1538
- for (const child of node.getChildren()) {
1539
- if ($isListItemNode(child)) {
1540
- $formatListIndentStrict(child);
1541
- const firstChild = child.getFirstChild();
1542
- if ($isListNode(firstChild)) {
1543
- queue.push(firstChild);
1544
- }
1545
- }
1546
- }
1547
- }
1548
- };
1549
- return editor.registerNodeTransform(ListNode, $processListWithStrictIndent);
1550
- }
1551
- function $findChildrenEndListItemNode(listItemNode) {
1552
- let current = listItemNode;
1553
- let firstChild = current.getFirstChild();
1554
- while ($isListNode(firstChild)) {
1555
- const lastChild = firstChild.getLastChild();
1556
- if ($isListItemNode(lastChild)) {
1557
- current = lastChild;
1558
- firstChild = current.getFirstChild();
1559
- } else {
1560
- break;
1561
- }
1562
- }
1563
- return current;
1564
- }
1565
-
1566
- /**
1567
- * @deprecated use {@link $insertList} from an update or command listener.
1568
- *
1569
- * Inserts a new ListNode. If the selection's anchor node is an empty ListItemNode and is a child of
1570
- * the root/shadow root, it will replace the ListItemNode with a ListNode and the old ListItemNode.
1571
- * Otherwise it will replace its parent with a new ListNode and re-insert the ListItemNode and any previous children.
1572
- * If the selection's anchor node is not an empty ListItemNode, it will add a new ListNode or merge an existing ListNode,
1573
- * unless the the node is a leaf node, in which case it will attempt to find a ListNode up the branch and replace it with
1574
- * a new ListNode, or create a new ListNode at the nearest root/shadow root.
1575
- * @param editor - The lexical editor.
1576
- * @param listType - The type of list, "number" | "bullet" | "check".
1577
- */
1578
- function insertList(editor, listType) {
1579
- editor.update(() => $insertList(listType));
1580
- }
1581
-
1582
- /**
1583
- * @deprecated use {@link $removeList} from an update or command listener.
1584
- *
1585
- * Searches for the nearest ancestral ListNode and removes it. If selection is an empty ListItemNode
1586
- * it will remove the whole list, including the ListItemNode. For each ListItemNode in the ListNode,
1587
- * removeList will also generate new ParagraphNodes in the removed ListNode's place. Any child node
1588
- * inside a ListItemNode will be appended to the new ParagraphNodes.
1589
- * @param editor - The lexical editor.
1590
- */
1591
- function removeList(editor) {
1592
- editor.update(() => $removeList());
1593
- }
1594
-
1595
- export { $createListItemNode, $createListNode, $getListDepth, $handleListInsertParagraph, $insertList, $isListItemNode, $isListNode, $removeList, INSERT_CHECK_LIST_COMMAND, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, ListItemNode, ListNode, REMOVE_LIST_COMMAND, UPDATE_LIST_START_COMMAND, insertList, registerCheckList, registerList, registerListStrictIndentTransform, removeList };