@lexical/list 0.14.5 → 0.16.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.
- package/LexicalList.dev.js +67 -21
- package/LexicalList.dev.mjs +68 -22
- package/LexicalList.js +2 -0
- package/LexicalList.mjs +2 -0
- package/LexicalList.node.mjs +2 -0
- package/LexicalList.prod.js +33 -29
- package/LexicalList.prod.mjs +3 -1
- package/LexicalListItemNode.d.ts +2 -0
- package/README.md +1 -1
- package/package.json +3 -3
- package/utils.d.ts +2 -2
package/LexicalList.dev.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
9
11
|
var lexical = require('lexical');
|
|
@@ -17,6 +19,7 @@ var utils = require('@lexical/utils');
|
|
|
17
19
|
*
|
|
18
20
|
*/
|
|
19
21
|
|
|
22
|
+
|
|
20
23
|
/**
|
|
21
24
|
* Checks the depth of listNode from the root node.
|
|
22
25
|
* @param listNode - The ListNode to be checked.
|
|
@@ -125,7 +128,7 @@ function $removeHighestEmptyListParent(sublist) {
|
|
|
125
128
|
* @param node - The node to be wrapped into a ListItemNode
|
|
126
129
|
* @returns The ListItemNode which the passed node is wrapped in.
|
|
127
130
|
*/
|
|
128
|
-
function wrapInListItem(node) {
|
|
131
|
+
function $wrapInListItem(node) {
|
|
129
132
|
const listItemWrapper = $createListItemNode();
|
|
130
133
|
return listItemWrapper.append(node);
|
|
131
134
|
}
|
|
@@ -137,6 +140,7 @@ function wrapInListItem(node) {
|
|
|
137
140
|
* LICENSE file in the root directory of this source tree.
|
|
138
141
|
*
|
|
139
142
|
*/
|
|
143
|
+
|
|
140
144
|
function $isSelectingEmptyListItem(anchorNode, nodes) {
|
|
141
145
|
return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
|
|
142
146
|
}
|
|
@@ -186,7 +190,7 @@ function insertList(editor, listType) {
|
|
|
186
190
|
for (let i = 0; i < nodes.length; i++) {
|
|
187
191
|
const node = nodes[i];
|
|
188
192
|
if (lexical.$isElementNode(node) && node.isEmpty() && !$isListItemNode(node) && !handled.has(node.getKey())) {
|
|
189
|
-
createListOrMerge(node, listType);
|
|
193
|
+
$createListOrMerge(node, listType);
|
|
190
194
|
continue;
|
|
191
195
|
}
|
|
192
196
|
if (lexical.$isLeafNode(node)) {
|
|
@@ -205,7 +209,7 @@ function insertList(editor, listType) {
|
|
|
205
209
|
const nextParent = parent.getParent();
|
|
206
210
|
if (lexical.$isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) {
|
|
207
211
|
handled.add(parentKey);
|
|
208
|
-
createListOrMerge(parent, listType);
|
|
212
|
+
$createListOrMerge(parent, listType);
|
|
209
213
|
break;
|
|
210
214
|
}
|
|
211
215
|
parent = nextParent;
|
|
@@ -219,7 +223,7 @@ function insertList(editor, listType) {
|
|
|
219
223
|
function append(node, nodesToAppend) {
|
|
220
224
|
node.splice(node.getChildrenSize(), 0, nodesToAppend);
|
|
221
225
|
}
|
|
222
|
-
function createListOrMerge(node, listType) {
|
|
226
|
+
function $createListOrMerge(node, listType) {
|
|
223
227
|
if ($isListNode(node)) {
|
|
224
228
|
return node;
|
|
225
229
|
}
|
|
@@ -565,6 +569,7 @@ function normalizeClassNames(...classNames) {
|
|
|
565
569
|
* LICENSE file in the root directory of this source tree.
|
|
566
570
|
*
|
|
567
571
|
*/
|
|
572
|
+
|
|
568
573
|
/** @noInheritDoc */
|
|
569
574
|
class ListItemNode extends lexical.ElementNode {
|
|
570
575
|
/** @internal */
|
|
@@ -620,8 +625,8 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
620
625
|
}
|
|
621
626
|
static importDOM() {
|
|
622
627
|
return {
|
|
623
|
-
li:
|
|
624
|
-
conversion: convertListItemElement,
|
|
628
|
+
li: () => ({
|
|
629
|
+
conversion: $convertListItemElement,
|
|
625
630
|
priority: 0
|
|
626
631
|
})
|
|
627
632
|
};
|
|
@@ -821,9 +826,13 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
821
826
|
}
|
|
822
827
|
return this;
|
|
823
828
|
}
|
|
829
|
+
|
|
830
|
+
/** @deprecated @internal */
|
|
824
831
|
canInsertAfter(node) {
|
|
825
832
|
return $isListItemNode(node);
|
|
826
833
|
}
|
|
834
|
+
|
|
835
|
+
/** @deprecated @internal */
|
|
827
836
|
canReplaceWith(replacement) {
|
|
828
837
|
return $isListItemNode(replacement);
|
|
829
838
|
}
|
|
@@ -900,8 +909,29 @@ function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
|
|
|
900
909
|
}
|
|
901
910
|
}
|
|
902
911
|
}
|
|
903
|
-
function convertListItemElement(domNode) {
|
|
904
|
-
const
|
|
912
|
+
function $convertListItemElement(domNode) {
|
|
913
|
+
const isGitHubCheckList = domNode.classList.contains('task-list-item');
|
|
914
|
+
if (isGitHubCheckList) {
|
|
915
|
+
for (const child of domNode.children) {
|
|
916
|
+
if (child.tagName === 'INPUT') {
|
|
917
|
+
return $convertCheckboxInput(child);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const ariaCheckedAttr = domNode.getAttribute('aria-checked');
|
|
922
|
+
const checked = ariaCheckedAttr === 'true' ? true : ariaCheckedAttr === 'false' ? false : undefined;
|
|
923
|
+
return {
|
|
924
|
+
node: $createListItemNode(checked)
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
function $convertCheckboxInput(domNode) {
|
|
928
|
+
const isCheckboxInput = domNode.getAttribute('type') === 'checkbox';
|
|
929
|
+
if (!isCheckboxInput) {
|
|
930
|
+
return {
|
|
931
|
+
node: null
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
const checked = domNode.hasAttribute('checked');
|
|
905
935
|
return {
|
|
906
936
|
node: $createListItemNode(checked)
|
|
907
937
|
};
|
|
@@ -932,6 +962,7 @@ function $isListItemNode(node) {
|
|
|
932
962
|
* LICENSE file in the root directory of this source tree.
|
|
933
963
|
*
|
|
934
964
|
*/
|
|
965
|
+
|
|
935
966
|
/** @noInheritDoc */
|
|
936
967
|
class ListNode extends lexical.ElementNode {
|
|
937
968
|
/** @internal */
|
|
@@ -979,14 +1010,14 @@ class ListNode extends lexical.ElementNode {
|
|
|
979
1010
|
}
|
|
980
1011
|
// @ts-expect-error Internal field.
|
|
981
1012
|
dom.__lexicalListType = this.__listType;
|
|
982
|
-
setListThemeClassNames(dom, config.theme, this);
|
|
1013
|
+
$setListThemeClassNames(dom, config.theme, this);
|
|
983
1014
|
return dom;
|
|
984
1015
|
}
|
|
985
1016
|
updateDOM(prevNode, dom, config) {
|
|
986
1017
|
if (prevNode.__tag !== this.__tag) {
|
|
987
1018
|
return true;
|
|
988
1019
|
}
|
|
989
|
-
setListThemeClassNames(dom, config.theme, this);
|
|
1020
|
+
$setListThemeClassNames(dom, config.theme, this);
|
|
990
1021
|
return false;
|
|
991
1022
|
}
|
|
992
1023
|
static transform() {
|
|
@@ -1000,12 +1031,12 @@ class ListNode extends lexical.ElementNode {
|
|
|
1000
1031
|
}
|
|
1001
1032
|
static importDOM() {
|
|
1002
1033
|
return {
|
|
1003
|
-
ol:
|
|
1004
|
-
conversion: convertListNode,
|
|
1034
|
+
ol: () => ({
|
|
1035
|
+
conversion: $convertListNode,
|
|
1005
1036
|
priority: 0
|
|
1006
1037
|
}),
|
|
1007
|
-
ul:
|
|
1008
|
-
conversion: convertListNode,
|
|
1038
|
+
ul: () => ({
|
|
1039
|
+
conversion: $convertListNode,
|
|
1009
1040
|
priority: 0
|
|
1010
1041
|
})
|
|
1011
1042
|
};
|
|
@@ -1073,7 +1104,7 @@ class ListNode extends lexical.ElementNode {
|
|
|
1073
1104
|
return $isListItemNode(child);
|
|
1074
1105
|
}
|
|
1075
1106
|
}
|
|
1076
|
-
function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
1107
|
+
function $setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
1077
1108
|
const classesToAdd = [];
|
|
1078
1109
|
const classesToRemove = [];
|
|
1079
1110
|
const listTheme = editorThemeClasses.list;
|
|
@@ -1125,7 +1156,7 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
1125
1156
|
* ensuring that they are all ListItemNodes and contain either a single nested ListNode
|
|
1126
1157
|
* or some other inline content.
|
|
1127
1158
|
*/
|
|
1128
|
-
function normalizeChildren(nodes) {
|
|
1159
|
+
function $normalizeChildren(nodes) {
|
|
1129
1160
|
const normalizedListItems = [];
|
|
1130
1161
|
for (let i = 0; i < nodes.length; i++) {
|
|
1131
1162
|
const node = nodes[i];
|
|
@@ -1135,17 +1166,31 @@ function normalizeChildren(nodes) {
|
|
|
1135
1166
|
if (children.length > 1) {
|
|
1136
1167
|
children.forEach(child => {
|
|
1137
1168
|
if ($isListNode(child)) {
|
|
1138
|
-
normalizedListItems.push(wrapInListItem(child));
|
|
1169
|
+
normalizedListItems.push($wrapInListItem(child));
|
|
1139
1170
|
}
|
|
1140
1171
|
});
|
|
1141
1172
|
}
|
|
1142
1173
|
} else {
|
|
1143
|
-
normalizedListItems.push(wrapInListItem(node));
|
|
1174
|
+
normalizedListItems.push($wrapInListItem(node));
|
|
1144
1175
|
}
|
|
1145
1176
|
}
|
|
1146
1177
|
return normalizedListItems;
|
|
1147
1178
|
}
|
|
1148
|
-
function
|
|
1179
|
+
function isDomChecklist(domNode) {
|
|
1180
|
+
if (domNode.getAttribute('__lexicallisttype') === 'check' ||
|
|
1181
|
+
// is github checklist
|
|
1182
|
+
domNode.classList.contains('contains-task-list')) {
|
|
1183
|
+
return true;
|
|
1184
|
+
}
|
|
1185
|
+
// if children are checklist items, the node is a checklist ul. Applicable for googledoc checklist pasting.
|
|
1186
|
+
for (const child of domNode.childNodes) {
|
|
1187
|
+
if (utils.isHTMLElement(child) && child.hasAttribute('aria-checked')) {
|
|
1188
|
+
return true;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
return false;
|
|
1192
|
+
}
|
|
1193
|
+
function $convertListNode(domNode) {
|
|
1149
1194
|
const nodeName = domNode.nodeName.toLowerCase();
|
|
1150
1195
|
let node = null;
|
|
1151
1196
|
if (nodeName === 'ol') {
|
|
@@ -1153,14 +1198,14 @@ function convertListNode(domNode) {
|
|
|
1153
1198
|
const start = domNode.start;
|
|
1154
1199
|
node = $createListNode('number', start);
|
|
1155
1200
|
} else if (nodeName === 'ul') {
|
|
1156
|
-
if (
|
|
1201
|
+
if (isDomChecklist(domNode)) {
|
|
1157
1202
|
node = $createListNode('check');
|
|
1158
1203
|
} else {
|
|
1159
1204
|
node = $createListNode('bullet');
|
|
1160
1205
|
}
|
|
1161
1206
|
}
|
|
1162
1207
|
return {
|
|
1163
|
-
after: normalizeChildren,
|
|
1208
|
+
after: $normalizeChildren,
|
|
1164
1209
|
node
|
|
1165
1210
|
};
|
|
1166
1211
|
}
|
|
@@ -1195,6 +1240,7 @@ function $isListNode(node) {
|
|
|
1195
1240
|
* LICENSE file in the root directory of this source tree.
|
|
1196
1241
|
*
|
|
1197
1242
|
*/
|
|
1243
|
+
|
|
1198
1244
|
const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand('INSERT_UNORDERED_LIST_COMMAND');
|
|
1199
1245
|
const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand('INSERT_ORDERED_LIST_COMMAND');
|
|
1200
1246
|
const INSERT_CHECK_LIST_COMMAND = lexical.createCommand('INSERT_CHECK_LIST_COMMAND');
|
package/LexicalList.dev.mjs
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
import { $getSelection, $isRangeSelection, $isRootOrShadowRoot, $isElementNode, $isLeafNode, $createParagraphNode, $isParagraphNode, ElementNode, $applyNodeReplacement, $createTextNode, createCommand } from 'lexical';
|
|
8
10
|
import { $getNearestNodeOfType, removeClassNamesFromElement, addClassNamesToElement, isHTMLElement } from '@lexical/utils';
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -15,6 +17,7 @@ import { $getNearestNodeOfType, removeClassNamesFromElement, addClassNamesToElem
|
|
|
15
17
|
*
|
|
16
18
|
*/
|
|
17
19
|
|
|
20
|
+
|
|
18
21
|
/**
|
|
19
22
|
* Checks the depth of listNode from the root node.
|
|
20
23
|
* @param listNode - The ListNode to be checked.
|
|
@@ -123,7 +126,7 @@ function $removeHighestEmptyListParent(sublist) {
|
|
|
123
126
|
* @param node - The node to be wrapped into a ListItemNode
|
|
124
127
|
* @returns The ListItemNode which the passed node is wrapped in.
|
|
125
128
|
*/
|
|
126
|
-
function wrapInListItem(node) {
|
|
129
|
+
function $wrapInListItem(node) {
|
|
127
130
|
const listItemWrapper = $createListItemNode();
|
|
128
131
|
return listItemWrapper.append(node);
|
|
129
132
|
}
|
|
@@ -135,6 +138,7 @@ function wrapInListItem(node) {
|
|
|
135
138
|
* LICENSE file in the root directory of this source tree.
|
|
136
139
|
*
|
|
137
140
|
*/
|
|
141
|
+
|
|
138
142
|
function $isSelectingEmptyListItem(anchorNode, nodes) {
|
|
139
143
|
return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
|
|
140
144
|
}
|
|
@@ -184,7 +188,7 @@ function insertList(editor, listType) {
|
|
|
184
188
|
for (let i = 0; i < nodes.length; i++) {
|
|
185
189
|
const node = nodes[i];
|
|
186
190
|
if ($isElementNode(node) && node.isEmpty() && !$isListItemNode(node) && !handled.has(node.getKey())) {
|
|
187
|
-
createListOrMerge(node, listType);
|
|
191
|
+
$createListOrMerge(node, listType);
|
|
188
192
|
continue;
|
|
189
193
|
}
|
|
190
194
|
if ($isLeafNode(node)) {
|
|
@@ -203,7 +207,7 @@ function insertList(editor, listType) {
|
|
|
203
207
|
const nextParent = parent.getParent();
|
|
204
208
|
if ($isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) {
|
|
205
209
|
handled.add(parentKey);
|
|
206
|
-
createListOrMerge(parent, listType);
|
|
210
|
+
$createListOrMerge(parent, listType);
|
|
207
211
|
break;
|
|
208
212
|
}
|
|
209
213
|
parent = nextParent;
|
|
@@ -217,7 +221,7 @@ function insertList(editor, listType) {
|
|
|
217
221
|
function append(node, nodesToAppend) {
|
|
218
222
|
node.splice(node.getChildrenSize(), 0, nodesToAppend);
|
|
219
223
|
}
|
|
220
|
-
function createListOrMerge(node, listType) {
|
|
224
|
+
function $createListOrMerge(node, listType) {
|
|
221
225
|
if ($isListNode(node)) {
|
|
222
226
|
return node;
|
|
223
227
|
}
|
|
@@ -563,6 +567,7 @@ function normalizeClassNames(...classNames) {
|
|
|
563
567
|
* LICENSE file in the root directory of this source tree.
|
|
564
568
|
*
|
|
565
569
|
*/
|
|
570
|
+
|
|
566
571
|
/** @noInheritDoc */
|
|
567
572
|
class ListItemNode extends ElementNode {
|
|
568
573
|
/** @internal */
|
|
@@ -618,8 +623,8 @@ class ListItemNode extends ElementNode {
|
|
|
618
623
|
}
|
|
619
624
|
static importDOM() {
|
|
620
625
|
return {
|
|
621
|
-
li:
|
|
622
|
-
conversion: convertListItemElement,
|
|
626
|
+
li: () => ({
|
|
627
|
+
conversion: $convertListItemElement,
|
|
623
628
|
priority: 0
|
|
624
629
|
})
|
|
625
630
|
};
|
|
@@ -819,9 +824,13 @@ class ListItemNode extends ElementNode {
|
|
|
819
824
|
}
|
|
820
825
|
return this;
|
|
821
826
|
}
|
|
827
|
+
|
|
828
|
+
/** @deprecated @internal */
|
|
822
829
|
canInsertAfter(node) {
|
|
823
830
|
return $isListItemNode(node);
|
|
824
831
|
}
|
|
832
|
+
|
|
833
|
+
/** @deprecated @internal */
|
|
825
834
|
canReplaceWith(replacement) {
|
|
826
835
|
return $isListItemNode(replacement);
|
|
827
836
|
}
|
|
@@ -898,8 +907,29 @@ function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
|
|
|
898
907
|
}
|
|
899
908
|
}
|
|
900
909
|
}
|
|
901
|
-
function convertListItemElement(domNode) {
|
|
902
|
-
const
|
|
910
|
+
function $convertListItemElement(domNode) {
|
|
911
|
+
const isGitHubCheckList = domNode.classList.contains('task-list-item');
|
|
912
|
+
if (isGitHubCheckList) {
|
|
913
|
+
for (const child of domNode.children) {
|
|
914
|
+
if (child.tagName === 'INPUT') {
|
|
915
|
+
return $convertCheckboxInput(child);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
const ariaCheckedAttr = domNode.getAttribute('aria-checked');
|
|
920
|
+
const checked = ariaCheckedAttr === 'true' ? true : ariaCheckedAttr === 'false' ? false : undefined;
|
|
921
|
+
return {
|
|
922
|
+
node: $createListItemNode(checked)
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
function $convertCheckboxInput(domNode) {
|
|
926
|
+
const isCheckboxInput = domNode.getAttribute('type') === 'checkbox';
|
|
927
|
+
if (!isCheckboxInput) {
|
|
928
|
+
return {
|
|
929
|
+
node: null
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
const checked = domNode.hasAttribute('checked');
|
|
903
933
|
return {
|
|
904
934
|
node: $createListItemNode(checked)
|
|
905
935
|
};
|
|
@@ -930,6 +960,7 @@ function $isListItemNode(node) {
|
|
|
930
960
|
* LICENSE file in the root directory of this source tree.
|
|
931
961
|
*
|
|
932
962
|
*/
|
|
963
|
+
|
|
933
964
|
/** @noInheritDoc */
|
|
934
965
|
class ListNode extends ElementNode {
|
|
935
966
|
/** @internal */
|
|
@@ -977,14 +1008,14 @@ class ListNode extends ElementNode {
|
|
|
977
1008
|
}
|
|
978
1009
|
// @ts-expect-error Internal field.
|
|
979
1010
|
dom.__lexicalListType = this.__listType;
|
|
980
|
-
setListThemeClassNames(dom, config.theme, this);
|
|
1011
|
+
$setListThemeClassNames(dom, config.theme, this);
|
|
981
1012
|
return dom;
|
|
982
1013
|
}
|
|
983
1014
|
updateDOM(prevNode, dom, config) {
|
|
984
1015
|
if (prevNode.__tag !== this.__tag) {
|
|
985
1016
|
return true;
|
|
986
1017
|
}
|
|
987
|
-
setListThemeClassNames(dom, config.theme, this);
|
|
1018
|
+
$setListThemeClassNames(dom, config.theme, this);
|
|
988
1019
|
return false;
|
|
989
1020
|
}
|
|
990
1021
|
static transform() {
|
|
@@ -998,12 +1029,12 @@ class ListNode extends ElementNode {
|
|
|
998
1029
|
}
|
|
999
1030
|
static importDOM() {
|
|
1000
1031
|
return {
|
|
1001
|
-
ol:
|
|
1002
|
-
conversion: convertListNode,
|
|
1032
|
+
ol: () => ({
|
|
1033
|
+
conversion: $convertListNode,
|
|
1003
1034
|
priority: 0
|
|
1004
1035
|
}),
|
|
1005
|
-
ul:
|
|
1006
|
-
conversion: convertListNode,
|
|
1036
|
+
ul: () => ({
|
|
1037
|
+
conversion: $convertListNode,
|
|
1007
1038
|
priority: 0
|
|
1008
1039
|
})
|
|
1009
1040
|
};
|
|
@@ -1071,7 +1102,7 @@ class ListNode extends ElementNode {
|
|
|
1071
1102
|
return $isListItemNode(child);
|
|
1072
1103
|
}
|
|
1073
1104
|
}
|
|
1074
|
-
function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
1105
|
+
function $setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
1075
1106
|
const classesToAdd = [];
|
|
1076
1107
|
const classesToRemove = [];
|
|
1077
1108
|
const listTheme = editorThemeClasses.list;
|
|
@@ -1123,7 +1154,7 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
1123
1154
|
* ensuring that they are all ListItemNodes and contain either a single nested ListNode
|
|
1124
1155
|
* or some other inline content.
|
|
1125
1156
|
*/
|
|
1126
|
-
function normalizeChildren(nodes) {
|
|
1157
|
+
function $normalizeChildren(nodes) {
|
|
1127
1158
|
const normalizedListItems = [];
|
|
1128
1159
|
for (let i = 0; i < nodes.length; i++) {
|
|
1129
1160
|
const node = nodes[i];
|
|
@@ -1133,17 +1164,31 @@ function normalizeChildren(nodes) {
|
|
|
1133
1164
|
if (children.length > 1) {
|
|
1134
1165
|
children.forEach(child => {
|
|
1135
1166
|
if ($isListNode(child)) {
|
|
1136
|
-
normalizedListItems.push(wrapInListItem(child));
|
|
1167
|
+
normalizedListItems.push($wrapInListItem(child));
|
|
1137
1168
|
}
|
|
1138
1169
|
});
|
|
1139
1170
|
}
|
|
1140
1171
|
} else {
|
|
1141
|
-
normalizedListItems.push(wrapInListItem(node));
|
|
1172
|
+
normalizedListItems.push($wrapInListItem(node));
|
|
1142
1173
|
}
|
|
1143
1174
|
}
|
|
1144
1175
|
return normalizedListItems;
|
|
1145
1176
|
}
|
|
1146
|
-
function
|
|
1177
|
+
function isDomChecklist(domNode) {
|
|
1178
|
+
if (domNode.getAttribute('__lexicallisttype') === 'check' ||
|
|
1179
|
+
// is github checklist
|
|
1180
|
+
domNode.classList.contains('contains-task-list')) {
|
|
1181
|
+
return true;
|
|
1182
|
+
}
|
|
1183
|
+
// if children are checklist items, the node is a checklist ul. Applicable for googledoc checklist pasting.
|
|
1184
|
+
for (const child of domNode.childNodes) {
|
|
1185
|
+
if (isHTMLElement(child) && child.hasAttribute('aria-checked')) {
|
|
1186
|
+
return true;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
return false;
|
|
1190
|
+
}
|
|
1191
|
+
function $convertListNode(domNode) {
|
|
1147
1192
|
const nodeName = domNode.nodeName.toLowerCase();
|
|
1148
1193
|
let node = null;
|
|
1149
1194
|
if (nodeName === 'ol') {
|
|
@@ -1151,14 +1196,14 @@ function convertListNode(domNode) {
|
|
|
1151
1196
|
const start = domNode.start;
|
|
1152
1197
|
node = $createListNode('number', start);
|
|
1153
1198
|
} else if (nodeName === 'ul') {
|
|
1154
|
-
if (
|
|
1199
|
+
if (isDomChecklist(domNode)) {
|
|
1155
1200
|
node = $createListNode('check');
|
|
1156
1201
|
} else {
|
|
1157
1202
|
node = $createListNode('bullet');
|
|
1158
1203
|
}
|
|
1159
1204
|
}
|
|
1160
1205
|
return {
|
|
1161
|
-
after: normalizeChildren,
|
|
1206
|
+
after: $normalizeChildren,
|
|
1162
1207
|
node
|
|
1163
1208
|
};
|
|
1164
1209
|
}
|
|
@@ -1193,6 +1238,7 @@ function $isListNode(node) {
|
|
|
1193
1238
|
* LICENSE file in the root directory of this source tree.
|
|
1194
1239
|
*
|
|
1195
1240
|
*/
|
|
1241
|
+
|
|
1196
1242
|
const INSERT_UNORDERED_LIST_COMMAND = createCommand('INSERT_UNORDERED_LIST_COMMAND');
|
|
1197
1243
|
const INSERT_ORDERED_LIST_COMMAND = createCommand('INSERT_ORDERED_LIST_COMMAND');
|
|
1198
1244
|
const INSERT_CHECK_LIST_COMMAND = createCommand('INSERT_CHECK_LIST_COMMAND');
|
package/LexicalList.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict'
|
|
8
10
|
const LexicalList = process.env.NODE_ENV === 'development' ? require('./LexicalList.dev.js') : require('./LexicalList.prod.js');
|
|
9
11
|
module.exports = LexicalList;
|
package/LexicalList.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
8
|
+
|
|
7
9
|
import * as modDev from './LexicalList.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalList.prod.mjs';
|
|
9
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
package/LexicalList.node.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
8
|
+
|
|
7
9
|
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalList.dev.mjs') : import('./LexicalList.prod.mjs'));
|
|
8
10
|
export const $createListItemNode = mod.$createListItemNode;
|
|
9
11
|
export const $createListNode = mod.$createListNode;
|
package/LexicalList.prod.js
CHANGED
|
@@ -3,34 +3,38 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
function F(a){
|
|
13
|
-
function G(
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
|
|
9
|
+
'use strict';var g=require("lexical"),h=require("@lexical/utils"),l;function n(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}l=n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n["default"]:n;
|
|
10
|
+
function p(a){let b=1;for(a=a.getParent();null!=a;){if(q(a)){a=a.getParent();if(r(a)){b++;a=a.getParent();continue}l(40)}break}return b}function t(a){a=a.getParent();r(a)||l(40);let b=a;for(;null!==b;)b=b.getParent(),r(b)&&(a=b);return a}function u(a){let b=[];a=a.getChildren().filter(q);for(let c=0;c<a.length;c++){let d=a[c],e=d.getFirstChild();r(e)?b=b.concat(u(e)):b.push(d)}return b}function v(a){return q(a)&&r(a.getFirstChild())}
|
|
11
|
+
function w(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){let b=a.getParent();if(null==b||!q(a)&&!r(a))break;a=b}a.remove()}function x(a){return y().append(a)}function z(a,b){return q(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}function A(a,b){a.splice(a.getChildrenSize(),0,b)}
|
|
12
|
+
function D(a,b){if(r(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=y();e.setFormat(a.getFormatType());e.setIndent(a.getIndent());A(e,a.getChildren());if(r(c)&&b===c.getListType())return c.append(e),a.remove(),r(d)&&b===d.getListType()&&(A(c,d.getChildren()),d.remove()),c;if(r(d)&&b===d.getListType())return d.getFirstChildOrThrow().insertBefore(e),a.remove(),d;b=E(b);b.append(e);a.replace(b);return b}
|
|
13
|
+
function F(a,b){var c=a.getLastChild();let d=b.getFirstChild();c&&d&&v(c)&&v(d)&&(F(c.getFirstChild(),d.getFirstChild()),d.remove());c=b.getChildren();0<c.length&&a.append(...c);b.remove()}
|
|
14
|
+
function G(a){if(!v(a)){var b=a.getParent(),c=b?b.getParent():void 0,d=c?c.getParent():void 0;if(r(d)&&q(c)&&r(b)){d=b?b.getFirstChild():void 0;var e=b?b.getLastChild():void 0;if(a.is(d))c.insertBefore(a),b.isEmpty()&&c.remove();else if(a.is(e))c.insertAfter(a),b.isEmpty()&&c.remove();else{e=b.getListType();b=y();let f=E(e);b.append(f);a.getPreviousSiblings().forEach(k=>f.append(k));d=y();e=E(e);d.append(e);A(e,a.getNextSiblings());c.insertBefore(b);c.insertAfter(d);c.replace(a)}}}}
|
|
15
|
+
function H(...a){let b=[];for(let c of a)if(c&&"string"===typeof c)for(let [d]of c.matchAll(/\S+/g))b.push(d);return b}
|
|
16
|
+
class I extends g.ElementNode{static getType(){return"listitem"}static clone(a){return new I(a.__value,a.__checked,a.__key)}constructor(a,b,c){super(c);this.__value=void 0===a?1:a;this.__checked=b}createDOM(a){let b=document.createElement("li"),c=this.getParent();r(c)&&"check"===c.getListType()&&J(b,this,null);b.value=this.__value;K(b,a.theme,this);return b}updateDOM(a,b,c){let d=this.getParent();r(d)&&"check"===d.getListType()&&J(b,this,a);b.value=this.__value;K(b,c.theme,this);return!1}static transform(){return a=>
|
|
17
|
+
{q(a)||l(144);if(null!=a.__checked){var b=a.getParent();r(b)&&"check"!==b.getListType()&&null!=a.getChecked()&&a.setChecked(void 0)}}}static importDOM(){return{li:()=>({conversion:L,priority:0})}}static importJSON(a){let b=y();b.setChecked(a.checked);b.setValue(a.value);b.setFormat(a.format);b.setDirection(a.direction);return b}exportDOM(a){a=this.createDOM(a._config);a.style.textAlign=this.getFormatType();return{element:a}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",
|
|
18
|
+
value:this.getValue(),version:1}}append(...a){for(let b=0;b<a.length;b++){let c=a[b];if(g.$isElementNode(c)&&this.canMergeWith(c)){let d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a,b){if(q(a))return super.replace(a);this.setIndent(0);let c=this.getParentOrThrow();if(!r(c))return a;if(c.__first===this.getKey())c.insertBefore(a);else if(c.__last===this.getKey())c.insertAfter(a);else{let d=E(c.getListType()),e=this.getNextSibling();for(;e;){let f=e;e=e.getNextSibling();
|
|
19
|
+
d.append(f)}c.insertAfter(a);a.insertAfter(d)}b&&(g.$isElementNode(a)||l(139),this.getChildren().forEach(d=>{a.append(d)}));this.remove();0===c.getChildrenSize()&&c.remove();return a}insertAfter(a,b=!0){let c=this.getParentOrThrow();r(c)||l(39);if(q(a))return super.insertAfter(a,b);let d=this.getNextSiblings();c.insertAfter(a,b);if(0!==d.length){let e=E(c.getListType());d.forEach(f=>e.append(f));a.insertAfter(e,b)}return a}remove(a){let b=this.getPreviousSibling(),c=this.getNextSibling();super.remove(a);
|
|
20
|
+
b&&c&&v(b)&&v(c)&&(F(b.getFirstChild(),c.getFirstChild()),c.remove())}insertNewAfter(a,b=!0){a=y(null==this.__checked?void 0:!1);this.insertAfter(a,b);return a}collapseAtStart(a){let b=g.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();let e=q(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.insertBefore(b),c.remove(),c=a.anchor,a=a.focus,d=b.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),
|
|
21
|
+
"element"===a.type&&a.getNode().is(this)&&a.set(d,a.offset,"element")):(c.insertBefore(b),this.remove());return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=a}getChecked(){return this.getLatest().__checked}setChecked(a){this.getWritable().__checked=a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){var a=this.getParent();if(null===a)return this.getLatest().__indent;a=a.getParentOrThrow();let b=0;for(;q(a);)a=a.getParentOrThrow().getParentOrThrow(),
|
|
22
|
+
b++;return b}setIndent(a){"number"===typeof a&&-1<a||l(117);let b=this.getIndent();for(;b!==a;)if(b<a){var c=new Set;if(!v(this)&&!c.has(this.getKey())){var d=this.getParent(),e=this.getNextSibling(),f=this.getPreviousSibling();if(v(e)&&v(f))d=f.getFirstChild(),r(d)&&(d.append(this),f=e.getFirstChild(),r(f)&&(f=f.getChildren(),A(d,f),e.remove(),c.add(e.getKey())));else if(v(e))e=e.getFirstChild(),r(e)&&(e=e.getFirstChild(),null!==e&&e.insertBefore(this));else if(v(f))e=f.getFirstChild(),r(e)&&e.append(this);
|
|
23
|
+
else if(r(d)){c=y();let k=E(d.getListType());c.append(k);k.append(this);f?f.insertAfter(c):e?e.insertBefore(c):d.append(c)}}b++}else G(this),b--;return this}canInsertAfter(a){return q(a)}canReplaceWith(a){return q(a)}canMergeWith(a){return g.$isParagraphNode(a)||q(a)}extractWithChild(a,b){if(!g.$isRangeSelection(b))return!1;a=b.anchor.getNode();let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return E("bullet")}}
|
|
24
|
+
function K(a,b,c){let d=[],e=[];var f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var k=b.nested.listitem;void 0!==f&&d.push(...H(f));if(b){f=c.getParent();f=r(f)&&"check"===f.getListType();let m=c.getChecked();f&&!m||e.push(b.listitemUnchecked);f&&m||e.push(b.listitemChecked);f&&d.push(m?b.listitemChecked:b.listitemUnchecked)}void 0!==k&&(k=H(k),c.getChildren().some(m=>r(m))?d.push(...k):e.push(...k));0<e.length&&h.removeClassNamesFromElement(a,...e);0<d.length&&h.addClassNamesToElement(a,...d)}
|
|
25
|
+
function J(a,b,c){r(b.getFirstChild())?(a.removeAttribute("role"),a.removeAttribute("tabIndex"),a.removeAttribute("aria-checked")):(a.setAttribute("role","checkbox"),a.setAttribute("tabIndex","-1"),c&&b.__checked===c.__checked||a.setAttribute("aria-checked",b.getChecked()?"true":"false"))}
|
|
26
|
+
function L(a){if(a.classList.contains("task-list-item"))for(let b of a.children)if("INPUT"===b.tagName)return a=b,"checkbox"!==a.getAttribute("type")?a={node:null}:(a=a.hasAttribute("checked"),a={node:y(a)}),a;a=a.getAttribute("aria-checked");return{node:y("true"===a?!0:"false"===a?!1:void 0)}}function y(a){return g.$applyNodeReplacement(new I(void 0,a))}function q(a){return a instanceof I}
|
|
27
|
+
class M extends g.ElementNode{static getType(){return"list"}static clone(a){return new M(a.__listType||P[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=P[a]||a;this.__tag="number"===a?"ol":"ul";this.__start=b}getTag(){return this.__tag}setListType(a){let b=this.getWritable();b.__listType=a;b.__tag="number"===a?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(a){let b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",
|
|
28
|
+
String(this.__start));b.__lexicalListType=this.__listType;Q(b,a.theme,this);return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;Q(b,c.theme,this);return!1}static transform(){return a=>{r(a)||l(163);var b=a.getNextSibling();r(b)&&a.getListType()===b.getListType()&&F(a,b);b="check"!==a.getListType();let c=a.getStart();for(let d of a.getChildren())q(d)&&(d.getValue()!==c&&d.setValue(c),b&&null!=d.getChecked()&&d.setChecked(void 0),r(d.getFirstChild())||c++)}}static importDOM(){return{ol:()=>({conversion:R,
|
|
29
|
+
priority:0}),ul:()=>({conversion:R,priority:0})}}static importJSON(a){let b=E(a.listType,a.start);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportDOM(a){({element:a}=super.exportDOM(a));a&&h.isHTMLElement(a)&&(1!==this.__start&&a.setAttribute("start",String(this.__start)),"check"===this.__listType&&a.setAttribute("__lexicalListType","check"));return{element:a}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),
|
|
30
|
+
type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=0;c<a.length;c++){var b=a[c];if(q(b))super.append(b);else{let d=y();r(b)?d.append(b):g.$isElementNode(b)?(b=g.$createTextNode(b.getTextContent()),d.append(b)):d.append(b);super.append(d)}}return this}extractWithChild(a){return q(a)}}
|
|
31
|
+
function Q(a,b,c){let d=[],e=[];var f=b.list;if(void 0!==f){let m=f[`${c.__tag}Depth`]||[];b=p(c)-1;let N=b%m.length;var k=m[N];let O=f[c.__tag],B,C=f.nested;f=f.checklist;void 0!==C&&C.list&&(B=C.list);void 0!==O&&d.push(O);void 0!==f&&"check"===c.__listType&&d.push(f);if(void 0!==k)for(d.push(...H(k)),k=0;k<m.length;k++)k!==N&&e.push(c.__tag+k);void 0!==B&&(c=H(B),1<b?d.push(...c):e.push(...c))}0<e.length&&h.removeClassNamesFromElement(a,...e);0<d.length&&h.addClassNamesToElement(a,...d)}
|
|
32
|
+
function S(a){let b=[];for(let d=0;d<a.length;d++){var c=a[d];q(c)?(b.push(c),c=c.getChildren(),1<c.length&&c.forEach(e=>{r(e)&&b.push(x(e))})):b.push(x(c))}return b}
|
|
33
|
+
function R(a){let b=a.nodeName.toLowerCase(),c=null;if("ol"===b)c=E("number",a.start);else if("ul"===b){a:if("check"===a.getAttribute("__lexicallisttype")||a.classList.contains("contains-task-list"))a=!0;else{for(let d of a.childNodes)if(h.isHTMLElement(d)&&d.hasAttribute("aria-checked")){a=!0;break a}a=!1}c=a?E("check"):E("bullet")}return{after:S,node:c}}let P={ol:"number",ul:"bullet"};function E(a,b=1){return g.$applyNodeReplacement(new M(a,b))}function r(a){return a instanceof M}
|
|
34
|
+
let T=g.createCommand("INSERT_UNORDERED_LIST_COMMAND"),U=g.createCommand("INSERT_ORDERED_LIST_COMMAND"),V=g.createCommand("INSERT_CHECK_LIST_COMMAND"),W=g.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=y;exports.$createListNode=E;exports.$getListDepth=p;
|
|
35
|
+
exports.$handleListInsertParagraph=function(){var a=g.$getSelection();if(!g.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!q(a)||0!==a.getChildrenSize())return!1;var b=t(a),c=a.getParent();r(c)||l(40);let d=c.getParent(),e;if(g.$isRootOrShadowRoot(d))e=g.$createParagraphNode(),b.insertAfter(e);else if(q(d))e=y(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){let f=E(c.getListType());g.$isParagraphNode(e)?e.insertAfter(f):(c=y(),c.append(f),
|
|
36
|
+
e.insertAfter(c));b.forEach(k=>{k.remove();f.append(k)})}w(a);return!0};exports.$isListItemNode=q;exports.$isListNode=r;exports.INSERT_CHECK_LIST_COMMAND=V;exports.INSERT_ORDERED_LIST_COMMAND=U;exports.INSERT_UNORDERED_LIST_COMMAND=T;exports.ListItemNode=I;exports.ListNode=M;exports.REMOVE_LIST_COMMAND=W;
|
|
37
|
+
exports.insertList=function(a,b){a.update(()=>{var c=g.$getSelection();if(null!==c){var d=c.getNodes();if(g.$isRangeSelection(c)){c=c.getStartEndPoints();null===c&&l(143);[c]=c;c=c.getNode();var e=c.getParent();if(z(c,d)){d=E(b);g.$isRootOrShadowRoot(e)?(c.replace(d),e=y(),g.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),d.append(e)):q(c)&&(c=c.getParentOrThrow(),A(d,c.getChildren()),c.replace(d));return}}c=new Set;for(e=0;e<d.length;e++){var f=d[e];if(g.$isElementNode(f)&&
|
|
38
|
+
f.isEmpty()&&!q(f)&&!c.has(f.getKey()))D(f,b);else if(g.$isLeafNode(f))for(f=f.getParent();null!=f;){let m=f.getKey();if(r(f)){if(!c.has(m)){var k=E(b);A(k,f.getChildren());f.replace(k);c.add(m)}break}else{k=f.getParent();if(g.$isRootOrShadowRoot(k)&&!c.has(m)){c.add(m);D(f,b);break}f=k}}}}})};
|
|
39
|
+
exports.removeList=function(a){a.update(()=>{let b=g.$getSelection();if(g.$isRangeSelection(b)){var c=new Set,d=b.getNodes(),e=b.anchor.getNode();if(z(e,d))c.add(t(e));else for(e=0;e<d.length;e++){var f=d[e];g.$isLeafNode(f)&&(f=h.$getNearestNodeOfType(f,I),null!=f&&c.add(t(f)))}for(let k of c){c=k;d=u(k);for(let m of d)d=g.$createParagraphNode(),A(d,m.getChildren()),c.insertAfter(d),c=d,m.__key===b.anchor.key&&b.anchor.set(d.getKey(),0,"element"),m.__key===b.focus.key&&b.focus.set(d.getKey(),0,"element"),
|
|
36
40
|
m.remove();k.remove()}}})}
|
package/LexicalList.prod.mjs
CHANGED
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
7
|
-
import{$getSelection as e,$isRangeSelection as t,$isRootOrShadowRoot as n,$isElementNode as r,$isLeafNode as i,$createParagraphNode as s,$isParagraphNode as o,$applyNodeReplacement as c,ElementNode as l,$createTextNode as h,createCommand as a}from"lexical";import{$getNearestNodeOfType as u,removeClassNamesFromElement as g,addClassNamesToElement as d,isHTMLElement as f}from"@lexical/utils";var p=function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};function _(e){let t=1,n=e.getParent();for(;null!=n;){if(I(n)){const e=n.getParent();if(z(e)){t++,n=e.getParent();continue}p(40)}return t}return t}function m(e){let t=e.getParent();z(t)||p(40);let n=t;for(;null!==n;)n=n.getParent(),z(n)&&(t=n);return t}function v(e){let t=[];const n=e.getChildren().filter(I);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();z(i)?t=t.concat(v(i)):t.push(r)}return t}function y(e){return I(e)&&z(e.getFirstChild())}function C(e){return D().append(e)}function T(e,t){return I(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function k(s,o){s.update((()=>{const s=e();if(null!==s){const e=s.getNodes();if(t(s)){const t=s.getStartEndPoints();null===t&&p(143);const[i]=t,c=i.getNode(),l=c.getParent();if(T(c,e)){const e=J(o);if(n(l)){c.replace(e);const t=D();r(c)&&(t.setFormat(c.getFormatType()),t.setIndent(c.getIndent())),e.append(t)}else if(I(c)){const t=c.getParentOrThrow();S(e,t.getChildren()),t.replace(e)}return}}const c=new Set;for(let t=0;t<e.length;t++){const s=e[t];if(!r(s)||!s.isEmpty()||I(s)||c.has(s.getKey())){if(i(s)){let e=s.getParent();for(;null!=e;){const t=e.getKey();if(z(e)){if(!c.has(t)){const n=J(o);S(n,e.getChildren()),e.replace(n),c.add(t)}break}{const r=e.getParent();if(n(r)&&!c.has(t)){c.add(t),b(e,o);break}e=r}}}}else b(s,o)}}}))}function S(e,t){e.splice(e.getChildrenSize(),0,t)}function b(e,t){if(z(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=D();if(i.setFormat(e.getFormatType()),i.setIndent(e.getIndent()),S(i,e.getChildren()),z(n)&&t===n.getListType())return n.append(i),e.remove(),z(r)&&t===r.getListType()&&(S(n,r.getChildren()),r.remove()),n;if(z(r)&&t===r.getListType())return r.getFirstChildOrThrow().insertBefore(i),e.remove(),r;{const n=J(t);return n.append(i),e.replace(n),n}}function P(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&y(n)&&y(r)&&(P(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function N(n){n.update((()=>{const n=e();if(t(n)){const e=new Set,t=n.getNodes(),r=n.anchor.getNode();if(T(r,t))e.add(m(r));else for(let n=0;n<t.length;n++){const r=t[n];if(i(r)){const t=u(r,E);null!=t&&e.add(m(t))}}for(const t of e){let e=t;const r=v(t);for(const t of r){const r=s();S(r,t.getChildren()),e.insertAfter(r),e=r,t.__key===n.anchor.key&&n.anchor.set(r.getKey(),0,"element"),t.__key===n.focus.key&&n.focus.set(r.getKey(),0,"element"),t.remove()}t.remove()}}}))}function x(e){const t=new Set;if(y(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(y(r)&&y(i)){const n=i.getFirstChild();if(z(n)){n.append(e);const i=r.getFirstChild();if(z(i)){S(n,i.getChildren()),r.remove(),t.add(r.getKey())}}}else if(y(r)){const t=r.getFirstChild();if(z(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(y(i)){const t=i.getFirstChild();z(t)&&t.append(e)}else if(z(n)){const t=D(),s=J(n.getListType());t.append(s),s.append(e),i?i.insertAfter(t):r?r.insertBefore(t):n.append(t)}}function A(e){if(y(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(z(n?n.getParent():void 0)&&I(n)&&z(t)){const r=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(i))n.insertAfter(e),t.isEmpty()&&n.remove();else{const r=t.getListType(),i=D(),s=J(r);i.append(s),e.getPreviousSiblings().forEach((e=>s.append(e)));const o=D(),c=J(r);o.append(c),S(c,e.getNextSiblings()),n.insertBefore(i),n.insertAfter(o),n.replace(e)}}}function O(){const r=e();if(!t(r)||!r.isCollapsed())return!1;const i=r.anchor.getNode();if(!I(i)||0!==i.getChildrenSize())return!1;const c=m(i),l=i.getParent();z(l)||p(40);const h=l.getParent();let a;if(n(h))a=s(),c.insertAfter(a);else{if(!I(h))return!1;a=D(),h.insertAfter(a)}a.select();const u=i.getNextSiblings();if(u.length>0){const e=J(l.getListType());if(o(a))a.insertAfter(e);else{const t=D();t.append(e),a.insertAfter(t)}u.forEach((t=>{t.remove(),e.append(t)}))}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!I(t)&&!z(t))break;t=e}t.remove()}(i),!0}function L(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}class E extends l{static getType(){return"listitem"}static clone(e){return new E(e.__value,e.__checked,e.__key)}constructor(e,t,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}createDOM(e){const t=document.createElement("li"),n=this.getParent();return z(n)&&"check"===n.getListType()&&w(t,this,null),t.value=this.__value,F(t,e.theme,this),t}updateDOM(e,t,n){const r=this.getParent();return z(r)&&"check"===r.getListType()&&w(t,this,e),t.value=this.__value,F(t,n.theme,this),!1}static transform(){return e=>{if(I(e)||p(144),null==e.__checked)return;const t=e.getParent();z(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)}}static importDOM(){return{li:e=>({conversion:M,priority:0})}}static importJSON(e){const t=D();return t.setChecked(e.checked),t.setValue(e.value),t.setFormat(e.format),t.setDirection(e.direction),t}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(r(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,t){if(I(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!z(n))return e;if(n.__first===this.getKey())n.insertBefore(e);else if(n.__last===this.getKey())n.insertAfter(e);else{const t=J(n.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}n.insertAfter(e),e.insertAfter(t)}return t&&(r(e)||p(139),this.getChildren().forEach((t=>{e.append(t)}))),this.remove(),0===n.getChildrenSize()&&n.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if(z(n)||p(39),I(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const i=J(n.getListType());r.forEach((e=>i.append(e))),e.insertAfter(i,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&y(t)&&y(n)&&(P(t.getFirstChild(),n.getFirstChild()),n.remove())}insertNewAfter(e,t=!0){const n=D(null==this.__checked&&void 0);return this.insertAfter(n,t),n}collapseAtStart(e){const t=s();this.getChildren().forEach((e=>t.append(e)));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=I(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(t),n.remove();const r=e.anchor,i=e.focus,s=t.getKey();"element"===r.type&&r.getNode().is(this)&&r.set(s,r.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else n.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){this.getWritable().__value=e}getChecked(){return this.getLatest().__checked}setChecked(e){this.getWritable().__checked=e}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){const e=this.getParent();if(null===e)return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;I(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"==typeof e&&e>-1||p(117);let t=this.getIndent();for(;t!==e;)t<e?(x(this),t++):(A(this),t--);return this}canInsertAfter(e){return I(e)}canReplaceWith(e){return I(e)}canMergeWith(e){return o(e)||I(e)}extractWithChild(e,n){if(!t(n))return!1;const r=n.anchor.getNode(),i=n.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&this.getTextContent().length===n.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return J("bullet")}}function F(e,t,n){const r=[],i=[],s=t.list,o=s?s.listitem:void 0;let c;if(s&&s.nested&&(c=s.nested.listitem),void 0!==o&&r.push(...L(o)),s){const e=n.getParent(),t=z(e)&&"check"===e.getListType(),o=n.getChecked();t&&!o||i.push(s.listitemUnchecked),t&&o||i.push(s.listitemChecked),t&&r.push(o?s.listitemChecked:s.listitemUnchecked)}if(void 0!==c){const e=L(c);n.getChildren().some((e=>z(e)))?r.push(...e):i.push(...e)}i.length>0&&g(e,...i),r.length>0&&d(e,...r)}function w(e,t,n,r){z(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}function M(e){return{node:D(f(e)&&"true"===e.getAttribute("aria-checked"))}}function D(e){return c(new E(void 0,e))}function I(e){return e instanceof E}class R extends l{static getType(){return"list"}static clone(e){const t=e.__listType||V[e.__tag];return new R(t,e.__start,e.__key)}constructor(e,t,n){super(n);const r=V[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}getTag(){return this.__tag}setListType(e){const t=this.getWritable();t.__listType=e,t.__tag="number"===e?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,K(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||(K(t,n.theme,this),!1)}static transform(){return e=>{if(!z(e))throw Error("node is not a ListNode");!function(e){const t=e.getNextSibling();z(t)&&e.getListType()===t.getListType()&&P(e,t)}(e),function(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())I(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getChecked()&&r.setChecked(void 0),z(r.getFirstChild())||n++)}(e)}}static importDOM(){return{ol:e=>({conversion:W,priority:0}),ul:e=>({conversion:W,priority:0})}}static importJSON(e){const t=J(e.listType,e.start);return t.setFormat(e.format),t.setIndent(e.indent),t.setDirection(e.direction),t}exportDOM(e){const{element:t}=super.exportDOM(e);return t&&f(t)&&(1!==this.__start&&t.setAttribute("start",String(this.__start)),"check"===this.__listType&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(I(n))super.append(n);else{const e=D();if(z(n))e.append(n);else if(r(n)){const t=h(n.getTextContent());e.append(t)}else e.append(n);super.append(e)}}return this}extractWithChild(e){return I(e)}}function K(e,t,n){const r=[],i=[],s=t.list;if(void 0!==s){const e=s[`${n.__tag}Depth`]||[],t=_(n)-1,o=t%e.length,c=e[o],l=s[n.__tag];let h;const a=s.nested,u=s.checklist;if(void 0!==a&&a.list&&(h=a.list),void 0!==l&&r.push(l),void 0!==u&&"check"===n.__listType&&r.push(u),void 0!==c){r.push(...L(c));for(let t=0;t<e.length;t++)t!==o&&i.push(n.__tag+t)}if(void 0!==h){const e=L(h);t>1?r.push(...e):i.push(...e)}}i.length>0&&g(e,...i),r.length>0&&d(e,...r)}function B(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(I(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach((e=>{z(e)&&t.push(C(e))}))}else t.push(C(r))}return t}function W(e){const t=e.nodeName.toLowerCase();let n=null;if("ol"===t){n=J("number",e.start)}else"ul"===t&&(n=f(e)&&"check"===e.getAttribute("__lexicallisttype")?J("check"):J("bullet"));return{after:B,node:n}}const V={ol:"number",ul:"bullet"};function J(e,t=1){return c(new R(e,t))}function z(e){return e instanceof R}const U=a("INSERT_UNORDERED_LIST_COMMAND"),$=a("INSERT_ORDERED_LIST_COMMAND"),q=a("INSERT_CHECK_LIST_COMMAND"),H=a("REMOVE_LIST_COMMAND");export{D as $createListItemNode,J as $createListNode,_ as $getListDepth,O as $handleListInsertParagraph,I as $isListItemNode,z as $isListNode,q as INSERT_CHECK_LIST_COMMAND,$ as INSERT_ORDERED_LIST_COMMAND,U as INSERT_UNORDERED_LIST_COMMAND,E as ListItemNode,R as ListNode,H as REMOVE_LIST_COMMAND,k as insertList,N as removeList};
|
|
8
|
+
|
|
9
|
+
import{$getSelection as e,$isRangeSelection as t,$isRootOrShadowRoot as n,$isElementNode as r,$isLeafNode as i,$createParagraphNode as s,$isParagraphNode as o,ElementNode as c,$applyNodeReplacement as l,$createTextNode as a,createCommand as h}from"lexical";import{$getNearestNodeOfType as u,removeClassNamesFromElement as g,addClassNamesToElement as f,isHTMLElement as d}from"@lexical/utils";function p(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _=p((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function m(e){let t=1,n=e.getParent();for(;null!=n;){if(K(n)){const e=n.getParent();if($(e)){t++,n=e.getParent();continue}_(40)}return t}return t}function v(e){let t=e.getParent();$(t)||_(40);let n=t;for(;null!==n;)n=n.getParent(),$(n)&&(t=n);return t}function y(e){let t=[];const n=e.getChildren().filter(K);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();$(i)?t=t.concat(y(i)):t.push(r)}return t}function C(e){return K(e)&&$(e.getFirstChild())}function k(e){return R().append(e)}function T(e,t){return K(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function b(s,o){s.update((()=>{const s=e();if(null!==s){const e=s.getNodes();if(t(s)){const t=s.getStartEndPoints();null===t&&_(143);const[i]=t,c=i.getNode(),l=c.getParent();if(T(c,e)){const e=U(o);if(n(l)){c.replace(e);const t=R();r(c)&&(t.setFormat(c.getFormatType()),t.setIndent(c.getIndent())),e.append(t)}else if(K(c)){const t=c.getParentOrThrow();S(e,t.getChildren()),t.replace(e)}return}}const c=new Set;for(let t=0;t<e.length;t++){const s=e[t];if(!r(s)||!s.isEmpty()||K(s)||c.has(s.getKey())){if(i(s)){let e=s.getParent();for(;null!=e;){const t=e.getKey();if($(e)){if(!c.has(t)){const n=U(o);S(n,e.getChildren()),e.replace(n),c.add(t)}break}{const r=e.getParent();if(n(r)&&!c.has(t)){c.add(t),P(e,o);break}e=r}}}}else P(s,o)}}}))}function S(e,t){e.splice(e.getChildrenSize(),0,t)}function P(e,t){if($(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=R();if(i.setFormat(e.getFormatType()),i.setIndent(e.getIndent()),S(i,e.getChildren()),$(n)&&t===n.getListType())return n.append(i),e.remove(),$(r)&&t===r.getListType()&&(S(n,r.getChildren()),r.remove()),n;if($(r)&&t===r.getListType())return r.getFirstChildOrThrow().insertBefore(i),e.remove(),r;{const n=U(t);return n.append(i),e.replace(n),n}}function A(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&C(n)&&C(r)&&(A(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function N(n){n.update((()=>{const n=e();if(t(n)){const e=new Set,t=n.getNodes(),r=n.anchor.getNode();if(T(r,t))e.add(v(r));else for(let n=0;n<t.length;n++){const r=t[n];if(i(r)){const t=u(r,F);null!=t&&e.add(v(t))}}for(const t of e){let e=t;const r=y(t);for(const t of r){const r=s();S(r,t.getChildren()),e.insertAfter(r),e=r,t.__key===n.anchor.key&&n.anchor.set(r.getKey(),0,"element"),t.__key===n.focus.key&&n.focus.set(r.getKey(),0,"element"),t.remove()}t.remove()}}}))}function x(e){const t=new Set;if(C(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(C(r)&&C(i)){const n=i.getFirstChild();if($(n)){n.append(e);const i=r.getFirstChild();if($(i)){S(n,i.getChildren()),r.remove(),t.add(r.getKey())}}}else if(C(r)){const t=r.getFirstChild();if($(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(C(i)){const t=i.getFirstChild();$(t)&&t.append(e)}else if($(n)){const t=R(),s=U(n.getListType());t.append(s),s.append(e),i?i.insertAfter(t):r?r.insertBefore(t):n.append(t)}}function O(e){if(C(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if($(n?n.getParent():void 0)&&K(n)&&$(t)){const r=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(i))n.insertAfter(e),t.isEmpty()&&n.remove();else{const r=t.getListType(),i=R(),s=U(r);i.append(s),e.getPreviousSiblings().forEach((e=>s.append(e)));const o=R(),c=U(r);o.append(c),S(c,e.getNextSiblings()),n.insertBefore(i),n.insertAfter(o),n.replace(e)}}}function L(){const r=e();if(!t(r)||!r.isCollapsed())return!1;const i=r.anchor.getNode();if(!K(i)||0!==i.getChildrenSize())return!1;const c=v(i),l=i.getParent();$(l)||_(40);const a=l.getParent();let h;if(n(a))h=s(),c.insertAfter(h);else{if(!K(a))return!1;h=R(),a.insertAfter(h)}h.select();const u=i.getNextSiblings();if(u.length>0){const e=U(l.getListType());if(o(h))h.insertAfter(e);else{const t=R();t.append(e),h.insertAfter(t)}u.forEach((t=>{t.remove(),e.append(t)}))}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!K(t)&&!$(t))break;t=e}t.remove()}(i),!0}function E(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}class F extends c{static getType(){return"listitem"}static clone(e){return new F(e.__value,e.__checked,e.__key)}constructor(e,t,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}createDOM(e){const t=document.createElement("li"),n=this.getParent();return $(n)&&"check"===n.getListType()&&w(t,this,null),t.value=this.__value,M(t,e.theme,this),t}updateDOM(e,t,n){const r=this.getParent();return $(r)&&"check"===r.getListType()&&w(t,this,e),t.value=this.__value,M(t,n.theme,this),!1}static transform(){return e=>{if(K(e)||_(144),null==e.__checked)return;const t=e.getParent();$(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)}}static importDOM(){return{li:()=>({conversion:D,priority:0})}}static importJSON(e){const t=R();return t.setChecked(e.checked),t.setValue(e.value),t.setFormat(e.format),t.setDirection(e.direction),t}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(r(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,t){if(K(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!$(n))return e;if(n.__first===this.getKey())n.insertBefore(e);else if(n.__last===this.getKey())n.insertAfter(e);else{const t=U(n.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}n.insertAfter(e),e.insertAfter(t)}return t&&(r(e)||_(139),this.getChildren().forEach((t=>{e.append(t)}))),this.remove(),0===n.getChildrenSize()&&n.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if($(n)||_(39),K(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const i=U(n.getListType());r.forEach((e=>i.append(e))),e.insertAfter(i,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&C(t)&&C(n)&&(A(t.getFirstChild(),n.getFirstChild()),n.remove())}insertNewAfter(e,t=!0){const n=R(null==this.__checked&&void 0);return this.insertAfter(n,t),n}collapseAtStart(e){const t=s();this.getChildren().forEach((e=>t.append(e)));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=K(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(t),n.remove();const r=e.anchor,i=e.focus,s=t.getKey();"element"===r.type&&r.getNode().is(this)&&r.set(s,r.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else n.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){this.getWritable().__value=e}getChecked(){return this.getLatest().__checked}setChecked(e){this.getWritable().__checked=e}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){const e=this.getParent();if(null===e)return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;K(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"==typeof e&&e>-1||_(117);let t=this.getIndent();for(;t!==e;)t<e?(x(this),t++):(O(this),t--);return this}canInsertAfter(e){return K(e)}canReplaceWith(e){return K(e)}canMergeWith(e){return o(e)||K(e)}extractWithChild(e,n){if(!t(n))return!1;const r=n.anchor.getNode(),i=n.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&this.getTextContent().length===n.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return U("bullet")}}function M(e,t,n){const r=[],i=[],s=t.list,o=s?s.listitem:void 0;let c;if(s&&s.nested&&(c=s.nested.listitem),void 0!==o&&r.push(...E(o)),s){const e=n.getParent(),t=$(e)&&"check"===e.getListType(),o=n.getChecked();t&&!o||i.push(s.listitemUnchecked),t&&o||i.push(s.listitemChecked),t&&r.push(o?s.listitemChecked:s.listitemUnchecked)}if(void 0!==c){const e=E(c);n.getChildren().some((e=>$(e)))?r.push(...e):i.push(...e)}i.length>0&&g(e,...i),r.length>0&&f(e,...r)}function w(e,t,n,r){$(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}function D(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return I(t);const t=e.getAttribute("aria-checked");return{node:R("true"===t||"false"!==t&&void 0)}}function I(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:R(e.hasAttribute("checked"))}}function R(e){return l(new F(void 0,e))}function K(e){return e instanceof F}class B extends c{static getType(){return"list"}static clone(e){const t=e.__listType||z[e.__tag];return new B(t,e.__start,e.__key)}constructor(e,t,n){super(n);const r=z[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}getTag(){return this.__tag}setListType(e){const t=this.getWritable();t.__listType=e,t.__tag="number"===e?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,W(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||(W(t,n.theme,this),!1)}static transform(){return e=>{$(e)||_(163),function(e){const t=e.getNextSibling();$(t)&&e.getListType()===t.getListType()&&A(e,t)}(e),function(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())K(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getChecked()&&r.setChecked(void 0),$(r.getFirstChild())||n++)}(e)}}static importDOM(){return{ol:()=>({conversion:J,priority:0}),ul:()=>({conversion:J,priority:0})}}static importJSON(e){const t=U(e.listType,e.start);return t.setFormat(e.format),t.setIndent(e.indent),t.setDirection(e.direction),t}exportDOM(e){const{element:t}=super.exportDOM(e);return t&&d(t)&&(1!==this.__start&&t.setAttribute("start",String(this.__start)),"check"===this.__listType&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(K(n))super.append(n);else{const e=R();if($(n))e.append(n);else if(r(n)){const t=a(n.getTextContent());e.append(t)}else e.append(n);super.append(e)}}return this}extractWithChild(e){return K(e)}}function W(e,t,n){const r=[],i=[],s=t.list;if(void 0!==s){const e=s[`${n.__tag}Depth`]||[],t=m(n)-1,o=t%e.length,c=e[o],l=s[n.__tag];let a;const h=s.nested,u=s.checklist;if(void 0!==h&&h.list&&(a=h.list),void 0!==l&&r.push(l),void 0!==u&&"check"===n.__listType&&r.push(u),void 0!==c){r.push(...E(c));for(let t=0;t<e.length;t++)t!==o&&i.push(n.__tag+t)}if(void 0!==a){const e=E(a);t>1?r.push(...e):i.push(...e)}}i.length>0&&g(e,...i),r.length>0&&f(e,...r)}function V(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(K(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach((e=>{$(e)&&t.push(k(e))}))}else t.push(k(r))}return t}function J(e){const t=e.nodeName.toLowerCase();let n=null;if("ol"===t){n=U("number",e.start)}else"ul"===t&&(n=function(e){if("check"===e.getAttribute("__lexicallisttype")||e.classList.contains("contains-task-list"))return!0;for(const t of e.childNodes)if(d(t)&&t.hasAttribute("aria-checked"))return!0;return!1}(e)?U("check"):U("bullet"));return{after:V,node:n}}const z={ol:"number",ul:"bullet"};function U(e,t=1){return l(new B(e,t))}function $(e){return e instanceof B}const j=h("INSERT_UNORDERED_LIST_COMMAND"),q=h("INSERT_ORDERED_LIST_COMMAND"),H=h("INSERT_CHECK_LIST_COMMAND"),G=h("REMOVE_LIST_COMMAND");export{R as $createListItemNode,U as $createListNode,m as $getListDepth,L as $handleListInsertParagraph,K as $isListItemNode,$ as $isListNode,H as INSERT_CHECK_LIST_COMMAND,q as INSERT_ORDERED_LIST_COMMAND,j as INSERT_UNORDERED_LIST_COMMAND,F as ListItemNode,B as ListNode,G as REMOVE_LIST_COMMAND,b as insertList,N as removeList};
|
package/LexicalListItemNode.d.ts
CHANGED
|
@@ -40,7 +40,9 @@ export declare class ListItemNode extends ElementNode {
|
|
|
40
40
|
toggleChecked(): void;
|
|
41
41
|
getIndent(): number;
|
|
42
42
|
setIndent(indent: number): this;
|
|
43
|
+
/** @deprecated @internal */
|
|
43
44
|
canInsertAfter(node: LexicalNode): boolean;
|
|
45
|
+
/** @deprecated @internal */
|
|
44
46
|
canReplaceWith(replacement: LexicalNode): boolean;
|
|
45
47
|
canMergeWith(node: LexicalNode): boolean;
|
|
46
48
|
extractWithChild(child: LexicalNode, selection: BaseSelection): boolean;
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.16.0",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/utils": "0.
|
|
16
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/utils": "0.16.0",
|
|
16
|
+
"lexical": "0.16.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
package/utils.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export declare function isNestedListNode(node: LexicalNode | null | undefined):
|
|
|
47
47
|
* @param node - Node to start the search.
|
|
48
48
|
* @returns The first ListItemNode found, or null if none exist.
|
|
49
49
|
*/
|
|
50
|
-
export declare function findNearestListItemNode(node: LexicalNode): ListItemNode | null;
|
|
50
|
+
export declare function $findNearestListItemNode(node: LexicalNode): ListItemNode | null;
|
|
51
51
|
/**
|
|
52
52
|
* Takes a deeply nested ListNode or ListItemNode and traverses up the branch to delete the first
|
|
53
53
|
* ancestral ListNode (which could be the root ListNode) or ListItemNode with siblings, essentially
|
|
@@ -61,5 +61,5 @@ export declare function $removeHighestEmptyListParent(sublist: ListItemNode | Li
|
|
|
61
61
|
* @param node - The node to be wrapped into a ListItemNode
|
|
62
62
|
* @returns The ListItemNode which the passed node is wrapped in.
|
|
63
63
|
*/
|
|
64
|
-
export declare function wrapInListItem(node: LexicalNode): ListItemNode;
|
|
64
|
+
export declare function $wrapInListItem(node: LexicalNode): ListItemNode;
|
|
65
65
|
export {};
|