@webiny/lexical-nodes 6.3.0-beta.4 → 6.4.0-beta.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/FontColorNode.js +94 -119
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.js +160 -183
- package/HeadingNode.js.map +1 -1
- package/ImageNode.js +101 -131
- package/ImageNode.js.map +1 -1
- package/LinkNode.js +228 -315
- package/LinkNode.js.map +1 -1
- package/ListItemNode.js +249 -320
- package/ListItemNode.js.map +1 -1
- package/ListNode.js +174 -223
- package/ListNode.js.map +1 -1
- package/ParagraphNode.js +119 -148
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.js +97 -102
- package/QuoteNode.js.map +1 -1
- package/components/ImageNode/ImageComponent.js +117 -147
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.js +167 -194
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/generateInitialLexicalValue.js +20 -23
- package/generateInitialLexicalValue.js.map +1 -1
- package/index.js +38 -26
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/prepareLexicalState.js +30 -43
- package/prepareLexicalState.js.map +1 -1
- package/types.js +0 -3
- package/utils/clearNodeFormating.js +14 -15
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.js +277 -368
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.js +6 -13
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.js +6 -7
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.js +6 -13
- package/utils/formatToQuote.js.map +1 -1
- package/utils/getStyleId.js +6 -11
- package/utils/getStyleId.js.map +1 -1
- package/utils/listNode.js +60 -84
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.js +67 -118
- package/utils/toggleLink.js.map +1 -1
- package/types.js.map +0 -1
package/ListItemNode.js
CHANGED
|
@@ -3,360 +3,289 @@ import { $createListNode, $isListNode } from "./ListNode.js";
|
|
|
3
3
|
import { $handleIndent, $handleOutdent, mergeLists, updateChildrenListItemValue } from "./utils/formatList.js";
|
|
4
4
|
import { $createParagraphNode, $isParagraphNode } from "./ParagraphNode.js";
|
|
5
5
|
import { isNestedListNode } from "./utils/listNode.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/** @internal */
|
|
12
|
-
|
|
13
|
-
static getType() {
|
|
14
|
-
return LIST_ITEM_TYPE;
|
|
15
|
-
}
|
|
16
|
-
static clone(node) {
|
|
17
|
-
return new ListItemNode(node.__value, node.__checked, node.__key);
|
|
18
|
-
}
|
|
19
|
-
constructor(value, checked, key) {
|
|
20
|
-
super(key);
|
|
21
|
-
this.__value = value === undefined ? 1 : value;
|
|
22
|
-
this.__checked = checked;
|
|
23
|
-
}
|
|
24
|
-
createDOM(config) {
|
|
25
|
-
const element = document.createElement("li");
|
|
26
|
-
const parent = this.getParent();
|
|
27
|
-
if ($isListNode(parent) && parent.getListType() === "check") {
|
|
28
|
-
updateListItemChecked(element, this, null, parent);
|
|
6
|
+
const LIST_ITEM_TYPE = "wby-list-item";
|
|
7
|
+
class ListItemNode extends ElementNode {
|
|
8
|
+
static getType() {
|
|
9
|
+
return LIST_ITEM_TYPE;
|
|
29
10
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return element;
|
|
33
|
-
}
|
|
34
|
-
updateDOM(prevNode, dom, config) {
|
|
35
|
-
const parent = this.getParent();
|
|
36
|
-
if ($isListNode(parent) && parent.getListType() === "check") {
|
|
37
|
-
updateListItemChecked(dom, this, prevNode, parent);
|
|
11
|
+
static clone(node) {
|
|
12
|
+
return new ListItemNode(node.__value, node.__checked, node.__key);
|
|
38
13
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
static importDOM() {
|
|
45
|
-
return {
|
|
46
|
-
li: () => ({
|
|
47
|
-
conversion: convertListItemElement,
|
|
48
|
-
priority: 0
|
|
49
|
-
})
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
static importJSON(serializedNode) {
|
|
53
|
-
const node = new ListItemNode(serializedNode.value, serializedNode.checked);
|
|
54
|
-
node.setFormat(serializedNode.format);
|
|
55
|
-
node.setIndent(serializedNode.indent);
|
|
56
|
-
node.setDirection(serializedNode.direction);
|
|
57
|
-
return node;
|
|
58
|
-
}
|
|
59
|
-
exportJSON() {
|
|
60
|
-
return {
|
|
61
|
-
...super.exportJSON(),
|
|
62
|
-
checked: this.getChecked(),
|
|
63
|
-
type: LIST_ITEM_TYPE,
|
|
64
|
-
value: this.getValue()
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
append(...nodes) {
|
|
68
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
69
|
-
const node = nodes[i];
|
|
70
|
-
if ($isElementNode(node) && this.canMergeWith(node)) {
|
|
71
|
-
const children = node.getChildren();
|
|
72
|
-
this.append(...children);
|
|
73
|
-
node.remove();
|
|
74
|
-
} else {
|
|
75
|
-
super.append(node);
|
|
76
|
-
}
|
|
14
|
+
constructor(value, checked, key){
|
|
15
|
+
super(key);
|
|
16
|
+
this.__value = void 0 === value ? 1 : value;
|
|
17
|
+
this.__checked = checked;
|
|
77
18
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
19
|
+
createDOM(config) {
|
|
20
|
+
const element = document.createElement("li");
|
|
21
|
+
const parent = this.getParent();
|
|
22
|
+
if ($isListNode(parent) && "check" === parent.getListType()) updateListItemChecked(element, this, null, parent);
|
|
23
|
+
element.value = this.__value;
|
|
24
|
+
$setListItemThemeClassNames(element, config.theme, this);
|
|
25
|
+
return element;
|
|
83
26
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
27
|
+
updateDOM(prevNode, dom, config) {
|
|
28
|
+
const parent = this.getParent();
|
|
29
|
+
if ($isListNode(parent) && "check" === parent.getListType()) updateListItemChecked(dom, this, prevNode, parent);
|
|
30
|
+
dom.value = this.__value;
|
|
31
|
+
$setListItemThemeClassNames(dom, config.theme, this);
|
|
32
|
+
return false;
|
|
88
33
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
let nextSibling = this.getNextSibling();
|
|
97
|
-
while (nextSibling) {
|
|
98
|
-
const nodeToAppend = nextSibling;
|
|
99
|
-
nextSibling = nextSibling.getNextSibling();
|
|
100
|
-
newList.append(nodeToAppend);
|
|
101
|
-
}
|
|
102
|
-
list.insertAfter(replaceWithNode);
|
|
103
|
-
replaceWithNode.insertAfter(newList);
|
|
34
|
+
static importDOM() {
|
|
35
|
+
return {
|
|
36
|
+
li: ()=>({
|
|
37
|
+
conversion: convertListItemElement,
|
|
38
|
+
priority: 0
|
|
39
|
+
})
|
|
40
|
+
};
|
|
104
41
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
});
|
|
42
|
+
static importJSON(serializedNode) {
|
|
43
|
+
const node = new ListItemNode(serializedNode.value, serializedNode.checked);
|
|
44
|
+
node.setFormat(serializedNode.format);
|
|
45
|
+
node.setIndent(serializedNode.indent);
|
|
46
|
+
node.setDirection(serializedNode.direction);
|
|
47
|
+
return node;
|
|
112
48
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
49
|
+
exportJSON() {
|
|
50
|
+
return {
|
|
51
|
+
...super.exportJSON(),
|
|
52
|
+
checked: this.getChecked(),
|
|
53
|
+
type: LIST_ITEM_TYPE,
|
|
54
|
+
value: this.getValue()
|
|
55
|
+
};
|
|
116
56
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
57
|
+
append(...nodes) {
|
|
58
|
+
for(let i = 0; i < nodes.length; i++){
|
|
59
|
+
const node = nodes[i];
|
|
60
|
+
if ($isElementNode(node) && this.canMergeWith(node)) {
|
|
61
|
+
const children = node.getChildren();
|
|
62
|
+
this.append(...children);
|
|
63
|
+
node.remove();
|
|
64
|
+
} else super.append(node);
|
|
65
|
+
}
|
|
66
|
+
return this;
|
|
124
67
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
68
|
+
replace(replaceWithNode, includeChildren) {
|
|
69
|
+
if ($isListItemNode(replaceWithNode)) return super.replace(replaceWithNode);
|
|
70
|
+
this.setIndent(0);
|
|
71
|
+
const list = this.getParentOrThrow();
|
|
72
|
+
if (!$isListNode(list)) return replaceWithNode;
|
|
73
|
+
if (list.__first === this.getKey()) list.insertBefore(replaceWithNode);
|
|
74
|
+
else if (list.__last === this.getKey()) list.insertAfter(replaceWithNode);
|
|
75
|
+
else {
|
|
76
|
+
const newList = $createListNode(list.getListType());
|
|
77
|
+
let nextSibling = this.getNextSibling();
|
|
78
|
+
while(nextSibling){
|
|
79
|
+
const nodeToAppend = nextSibling;
|
|
80
|
+
nextSibling = nextSibling.getNextSibling();
|
|
81
|
+
newList.append(nodeToAppend);
|
|
82
|
+
}
|
|
83
|
+
list.insertAfter(replaceWithNode);
|
|
84
|
+
replaceWithNode.insertAfter(newList);
|
|
85
|
+
}
|
|
86
|
+
if (includeChildren) {
|
|
87
|
+
if (!$isElementNode(replaceWithNode)) throw Error("includeChildren should only be true for ElementNodes");
|
|
88
|
+
this.getChildren().forEach((child)=>{
|
|
89
|
+
replaceWithNode.append(child);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
this.remove();
|
|
93
|
+
if (0 === list.getChildrenSize()) list.remove();
|
|
94
|
+
return replaceWithNode;
|
|
133
95
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
96
|
+
insertAfter(node) {
|
|
97
|
+
const listNode = this.getParentOrThrow();
|
|
98
|
+
if (!$isListNode(listNode)) {
|
|
99
|
+
console.log("insertAfter: webiny list node is not parent of list item node");
|
|
100
|
+
return listNode;
|
|
101
|
+
}
|
|
102
|
+
const siblings = this.getNextSiblings();
|
|
103
|
+
if ($isListItemNode(node)) {
|
|
104
|
+
const after = super.insertAfter(node);
|
|
105
|
+
const afterListNode = node.getParentOrThrow();
|
|
106
|
+
if ($isListNode(afterListNode)) updateChildrenListItemValue(afterListNode);
|
|
107
|
+
return after;
|
|
108
|
+
}
|
|
109
|
+
if ($isListNode(node) && node.getListType() === listNode.getListType()) {
|
|
110
|
+
let child = node;
|
|
111
|
+
const children = node.getChildren();
|
|
112
|
+
for(let i = children.length - 1; i >= 0; i--){
|
|
113
|
+
child = children[i];
|
|
114
|
+
this.insertAfter(child);
|
|
115
|
+
}
|
|
116
|
+
return child;
|
|
117
|
+
}
|
|
118
|
+
listNode.insertAfter(node);
|
|
119
|
+
if (0 !== siblings.length) {
|
|
120
|
+
const newListNode = $createListNode(listNode.getListType());
|
|
121
|
+
siblings.forEach((sibling)=>newListNode.append(sibling));
|
|
122
|
+
node.insertAfter(newListNode);
|
|
123
|
+
}
|
|
124
|
+
return node;
|
|
145
125
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
126
|
+
remove(preserveEmptyParent) {
|
|
127
|
+
const prevSibling = this.getPreviousSibling();
|
|
128
|
+
const nextSibling = this.getNextSibling();
|
|
129
|
+
super.remove(preserveEmptyParent);
|
|
130
|
+
if (prevSibling && nextSibling && isNestedListNode(prevSibling) && isNestedListNode(nextSibling)) {
|
|
131
|
+
mergeLists(prevSibling.getFirstChild(), nextSibling.getFirstChild());
|
|
132
|
+
nextSibling.remove();
|
|
133
|
+
} else if (nextSibling) {
|
|
134
|
+
const parent = nextSibling.getParent();
|
|
135
|
+
if ($isListNode(parent)) updateChildrenListItemValue(parent);
|
|
136
|
+
}
|
|
154
137
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const nextSibling = this.getNextSibling();
|
|
160
|
-
super.remove(preserveEmptyParent);
|
|
161
|
-
if (prevSibling && nextSibling && isNestedListNode(prevSibling) && isNestedListNode(nextSibling)) {
|
|
162
|
-
mergeLists(prevSibling.getFirstChild(), nextSibling.getFirstChild());
|
|
163
|
-
nextSibling.remove();
|
|
164
|
-
} else if (nextSibling) {
|
|
165
|
-
const parent = nextSibling.getParent();
|
|
166
|
-
if ($isListNode(parent)) {
|
|
167
|
-
updateChildrenListItemValue(parent);
|
|
168
|
-
}
|
|
138
|
+
insertNewAfter() {
|
|
139
|
+
const newElement = $createListItemNode(null == this.__checked ? void 0 : false);
|
|
140
|
+
this.insertAfter(newElement);
|
|
141
|
+
return newElement;
|
|
169
142
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
listNode.remove();
|
|
188
|
-
listNodeParent.select();
|
|
189
|
-
} else {
|
|
190
|
-
listNode.replace(paragraph);
|
|
191
|
-
// If we have selection on the list item, we'll need to move it
|
|
192
|
-
// to the paragraph
|
|
193
|
-
const anchor = selection.anchor;
|
|
194
|
-
const focus = selection.focus;
|
|
195
|
-
const key = paragraph.getKey();
|
|
196
|
-
if (anchor.type === "element" && anchor.getNode().is(this)) {
|
|
197
|
-
anchor.set(key, anchor.offset, "element");
|
|
143
|
+
collapseAtStart(selection) {
|
|
144
|
+
const paragraph = $createParagraphNode();
|
|
145
|
+
const children = this.getChildren();
|
|
146
|
+
children.forEach((child)=>paragraph.append(child));
|
|
147
|
+
const listNode = this.getParentOrThrow();
|
|
148
|
+
const listNodeParent = listNode.getParentOrThrow();
|
|
149
|
+
const isIndented = $isListItemNode(listNodeParent);
|
|
150
|
+
if (1 === listNode.getChildrenSize()) if (isIndented) {
|
|
151
|
+
listNode.remove();
|
|
152
|
+
listNodeParent.select();
|
|
153
|
+
} else {
|
|
154
|
+
listNode.replace(paragraph);
|
|
155
|
+
const anchor = selection.anchor;
|
|
156
|
+
const focus = selection.focus;
|
|
157
|
+
const key = paragraph.getKey();
|
|
158
|
+
if ("element" === anchor.type && anchor.getNode().is(this)) anchor.set(key, anchor.offset, "element");
|
|
159
|
+
if ("element" === focus.type && focus.getNode().is(this)) focus.set(key, focus.offset, "element");
|
|
198
160
|
}
|
|
199
|
-
|
|
200
|
-
|
|
161
|
+
else {
|
|
162
|
+
listNode.insertBefore(paragraph);
|
|
163
|
+
this.remove();
|
|
201
164
|
}
|
|
202
|
-
|
|
203
|
-
} else {
|
|
204
|
-
listNode.insertBefore(paragraph);
|
|
205
|
-
this.remove();
|
|
165
|
+
return true;
|
|
206
166
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const self = this.getLatest();
|
|
211
|
-
return self.__value;
|
|
212
|
-
}
|
|
213
|
-
setValue(value) {
|
|
214
|
-
const self = this.getWritable();
|
|
215
|
-
self.__value = value;
|
|
216
|
-
}
|
|
217
|
-
getChecked() {
|
|
218
|
-
const self = this.getLatest();
|
|
219
|
-
return self.__checked;
|
|
220
|
-
}
|
|
221
|
-
setChecked(checked) {
|
|
222
|
-
const self = this.getWritable();
|
|
223
|
-
self.__checked = checked;
|
|
224
|
-
}
|
|
225
|
-
getIndent() {
|
|
226
|
-
// If we don't have a parent, we are likely serializing
|
|
227
|
-
const parent = this.getParent();
|
|
228
|
-
if (parent === null) {
|
|
229
|
-
return this.getLatest().__indent;
|
|
167
|
+
getValue() {
|
|
168
|
+
const self = this.getLatest();
|
|
169
|
+
return self.__value;
|
|
230
170
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
while ($isListItemNode(listNodeParent)) {
|
|
235
|
-
listNodeParent = listNodeParent.getParentOrThrow().getParentOrThrow();
|
|
236
|
-
indentLevel++;
|
|
171
|
+
setValue(value) {
|
|
172
|
+
const self = this.getWritable();
|
|
173
|
+
self.__value = value;
|
|
237
174
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
let currentIndent = this.getIndent();
|
|
242
|
-
while (currentIndent !== indent) {
|
|
243
|
-
if (currentIndent < indent) {
|
|
244
|
-
$handleIndent([this]);
|
|
245
|
-
currentIndent++;
|
|
246
|
-
} else {
|
|
247
|
-
$handleOutdent([this]);
|
|
248
|
-
currentIndent--;
|
|
249
|
-
}
|
|
175
|
+
getChecked() {
|
|
176
|
+
const self = this.getLatest();
|
|
177
|
+
return self.__checked;
|
|
250
178
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
179
|
+
setChecked(checked) {
|
|
180
|
+
const self = this.getWritable();
|
|
181
|
+
self.__checked = checked;
|
|
182
|
+
}
|
|
183
|
+
getIndent() {
|
|
184
|
+
const parent = this.getParent();
|
|
185
|
+
if (null === parent) return this.getLatest().__indent;
|
|
186
|
+
let listNodeParent = parent.getParentOrThrow();
|
|
187
|
+
let indentLevel = 0;
|
|
188
|
+
while($isListItemNode(listNodeParent)){
|
|
189
|
+
listNodeParent = listNodeParent.getParentOrThrow().getParentOrThrow();
|
|
190
|
+
indentLevel++;
|
|
191
|
+
}
|
|
192
|
+
return indentLevel;
|
|
193
|
+
}
|
|
194
|
+
setIndent(indent) {
|
|
195
|
+
let currentIndent = this.getIndent();
|
|
196
|
+
while(currentIndent !== indent)if (currentIndent < indent) {
|
|
197
|
+
$handleIndent([
|
|
198
|
+
this
|
|
199
|
+
]);
|
|
200
|
+
currentIndent++;
|
|
201
|
+
} else {
|
|
202
|
+
$handleOutdent([
|
|
203
|
+
this
|
|
204
|
+
]);
|
|
205
|
+
currentIndent--;
|
|
206
|
+
}
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
canIndent() {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
insertBefore(nodeToInsert) {
|
|
213
|
+
if ($isListItemNode(nodeToInsert)) {
|
|
214
|
+
const parent = this.getParentOrThrow();
|
|
215
|
+
if ($isListNode(parent)) {
|
|
216
|
+
const siblings = this.getNextSiblings();
|
|
217
|
+
updateChildrenListItemValue(parent, siblings);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return super.insertBefore(nodeToInsert);
|
|
221
|
+
}
|
|
222
|
+
canInsertAfter(node) {
|
|
223
|
+
return $isListNode(node);
|
|
224
|
+
}
|
|
225
|
+
canReplaceWith(replacement) {
|
|
226
|
+
return $isListItemNode(replacement);
|
|
265
227
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
canMergeWith(node) {
|
|
275
|
-
return $isParagraphNode(node) || $isListItemNode(node);
|
|
276
|
-
}
|
|
277
|
-
extractWithChild(child, selection) {
|
|
278
|
-
if (!$isRangeSelection(selection)) {
|
|
279
|
-
return false;
|
|
228
|
+
canMergeWith(node) {
|
|
229
|
+
return $isParagraphNode(node) || $isListItemNode(node);
|
|
230
|
+
}
|
|
231
|
+
extractWithChild(child, selection) {
|
|
232
|
+
if (!$isRangeSelection(selection)) return false;
|
|
233
|
+
const anchorNode = selection.anchor.getNode();
|
|
234
|
+
const focusNode = selection.focus.getNode();
|
|
235
|
+
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && this.getTextContent().length === selection.getTextContent().length;
|
|
280
236
|
}
|
|
281
|
-
const anchorNode = selection.anchor.getNode();
|
|
282
|
-
const focusNode = selection.focus.getNode();
|
|
283
|
-
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && this.getTextContent().length === selection.getTextContent().length;
|
|
284
|
-
}
|
|
285
237
|
}
|
|
286
238
|
function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const listItemClasses = listItemClassName.split(" ");
|
|
297
|
-
classesToAdd.push(...listItemClasses);
|
|
298
|
-
}
|
|
299
|
-
if (listTheme) {
|
|
300
|
-
const parentNode = node.getParent();
|
|
301
|
-
const isCheckList = $isListNode(parentNode) && parentNode?.getListType() === "check";
|
|
302
|
-
const checked = node.getChecked();
|
|
303
|
-
if (!isCheckList || checked) {
|
|
304
|
-
classesToRemove.push(listTheme.listitemUnchecked);
|
|
239
|
+
const classesToAdd = [];
|
|
240
|
+
const classesToRemove = [];
|
|
241
|
+
const listTheme = editorThemeClasses.list;
|
|
242
|
+
const listItemClassName = listTheme ? listTheme.listitem : void 0;
|
|
243
|
+
let nestedListItemClassName;
|
|
244
|
+
if (listTheme && listTheme.nested) nestedListItemClassName = listTheme.nested.listitem;
|
|
245
|
+
if (void 0 !== listItemClassName) {
|
|
246
|
+
const listItemClasses = listItemClassName.split(" ");
|
|
247
|
+
classesToAdd.push(...listItemClasses);
|
|
305
248
|
}
|
|
306
|
-
if (
|
|
307
|
-
|
|
249
|
+
if (listTheme) {
|
|
250
|
+
const parentNode = node.getParent();
|
|
251
|
+
const isCheckList = $isListNode(parentNode) && parentNode?.getListType() === "check";
|
|
252
|
+
const checked = node.getChecked();
|
|
253
|
+
if (!isCheckList || checked) classesToRemove.push(listTheme.listitemUnchecked);
|
|
254
|
+
if (!isCheckList || !checked) classesToRemove.push(listTheme.listitemChecked);
|
|
255
|
+
if (isCheckList) classesToAdd.push(checked ? listTheme.listitemChecked : listTheme.listitemUnchecked);
|
|
308
256
|
}
|
|
309
|
-
if (
|
|
310
|
-
|
|
257
|
+
if (void 0 !== nestedListItemClassName) {
|
|
258
|
+
const nestedListItemClasses = nestedListItemClassName.split(" ");
|
|
259
|
+
if (node.getChildren().some((child)=>$isListNode(child))) classesToAdd.push(...nestedListItemClasses);
|
|
260
|
+
else classesToRemove.push(...nestedListItemClasses);
|
|
311
261
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const nestedListItemClasses = nestedListItemClassName.split(" ");
|
|
315
|
-
if (node.getChildren().some(child => $isListNode(child))) {
|
|
316
|
-
classesToAdd.push(...nestedListItemClasses);
|
|
317
|
-
} else {
|
|
318
|
-
classesToRemove.push(...nestedListItemClasses);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
if (classesToRemove.length > 0) {
|
|
322
|
-
removeClassNamesFromElement(dom, ...classesToRemove);
|
|
323
|
-
}
|
|
324
|
-
if (classesToAdd.length > 0) {
|
|
325
|
-
addClassNamesToElement(dom, ...classesToAdd);
|
|
326
|
-
}
|
|
262
|
+
if (classesToRemove.length > 0) removeClassNamesFromElement(dom, ...classesToRemove);
|
|
263
|
+
if (classesToAdd.length > 0) addClassNamesToElement(dom, ...classesToAdd);
|
|
327
264
|
}
|
|
328
265
|
function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
dom.removeAttribute("tabIndex");
|
|
335
|
-
dom.removeAttribute("aria-checked");
|
|
266
|
+
const isCheckList = "check" === listNode.getListType();
|
|
267
|
+
if (isCheckList) if ($isListNode(listItemNode.getFirstChild())) {
|
|
268
|
+
dom.removeAttribute("role");
|
|
269
|
+
dom.removeAttribute("tabIndex");
|
|
270
|
+
dom.removeAttribute("aria-checked");
|
|
336
271
|
} else {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
dom.setAttribute("aria-checked", listItemNode.getChecked() ? "true" : "false");
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
} else {
|
|
344
|
-
// Clean up checked state
|
|
345
|
-
if (listItemNode.getChecked() != null) {
|
|
346
|
-
listItemNode.setChecked(undefined);
|
|
272
|
+
dom.setAttribute("role", "checkbox");
|
|
273
|
+
dom.setAttribute("tabIndex", "-1");
|
|
274
|
+
if (!prevListItemNode || listItemNode.__checked !== prevListItemNode.__checked) dom.setAttribute("aria-checked", listItemNode.getChecked() ? "true" : "false");
|
|
347
275
|
}
|
|
348
|
-
|
|
276
|
+
else if (null != listItemNode.getChecked()) listItemNode.setChecked(void 0);
|
|
349
277
|
}
|
|
350
278
|
function convertListItemElement() {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
279
|
+
return {
|
|
280
|
+
node: $createListItemNode()
|
|
281
|
+
};
|
|
354
282
|
}
|
|
355
|
-
|
|
356
|
-
|
|
283
|
+
function $createListItemNode(checked) {
|
|
284
|
+
return new ListItemNode(void 0, checked);
|
|
357
285
|
}
|
|
358
|
-
|
|
359
|
-
|
|
286
|
+
function $isListItemNode(node) {
|
|
287
|
+
return node instanceof ListItemNode;
|
|
360
288
|
}
|
|
289
|
+
export { $createListItemNode, $isListItemNode, LIST_ITEM_TYPE, ListItemNode };
|
|
361
290
|
|
|
362
291
|
//# sourceMappingURL=ListItemNode.js.map
|