@ckeditor/ckeditor5-list 35.3.2 → 36.0.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/LICENSE.md +1 -1
- package/build/list.js +2 -2
- package/package.json +43 -39
- package/src/documentlist/converters.js +303 -419
- package/src/documentlist/documentlistcommand.js +136 -207
- package/src/documentlist/documentlistediting.js +538 -697
- package/src/documentlist/documentlistindentcommand.js +115 -168
- package/src/documentlist/documentlistmergecommand.js +161 -222
- package/src/documentlist/documentlistsplitcommand.js +59 -103
- package/src/documentlist/documentlistutils.js +41 -0
- package/src/documentlist/utils/listwalker.js +138 -236
- package/src/documentlist/utils/model.js +322 -421
- package/src/documentlist/utils/postfixers.js +98 -118
- package/src/documentlist/utils/view.js +74 -105
- package/src/documentlist.js +13 -19
- package/src/documentlistproperties/converters.js +33 -47
- package/src/documentlistproperties/documentlistpropertiesediting.js +266 -354
- package/src/documentlistproperties/documentlistpropertiesutils.js +44 -0
- package/src/documentlistproperties/documentlistreversedcommand.js +40 -61
- package/src/documentlistproperties/documentliststartcommand.js +42 -61
- package/src/documentlistproperties/documentliststylecommand.js +97 -147
- package/src/documentlistproperties/utils/style.js +27 -47
- package/src/documentlistproperties.js +13 -19
- package/src/index.js +4 -3
- package/src/list/converters.js +772 -929
- package/src/list/indentcommand.js +105 -140
- package/src/list/listcommand.js +262 -315
- package/src/list/listediting.js +142 -200
- package/src/list/listui.js +16 -25
- package/src/list/listutils.js +46 -0
- package/src/list/utils.js +295 -378
- package/src/list.js +13 -44
- package/src/listcommands.js +5 -0
- package/src/listconfig.js +5 -0
- package/src/listproperties/listpropertiesediting.js +656 -801
- package/src/listproperties/listpropertiesui.js +244 -296
- package/src/listproperties/listreversedcommand.js +37 -49
- package/src/listproperties/liststartcommand.js +37 -49
- package/src/listproperties/liststylecommand.js +82 -115
- package/src/listproperties/ui/collapsibleview.js +75 -138
- package/src/listproperties/ui/listpropertiesview.js +289 -414
- package/src/listproperties.js +13 -118
- package/src/liststyle.js +18 -24
- package/src/todolist/checktodolistcommand.js +60 -102
- package/src/todolist/todolistconverters.js +189 -271
- package/src/todolist/todolistediting.js +141 -206
- package/src/todolist/todolistui.js +14 -21
- package/src/todolist.js +13 -19
- package/theme/collapsible.css +1 -1
- package/theme/documentlist.css +1 -1
- package/theme/list.css +40 -0
- package/theme/listproperties.css +1 -1
- package/theme/liststyles.css +1 -37
- package/theme/todolist.css +1 -1
- package/build/list.js.map +0 -1
|
@@ -1,260 +1,162 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module list/documentlist/utils/listwalker
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { first, toArray } from 'ckeditor5/src/utils';
|
|
11
9
|
import { isListItemBlock } from './model';
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* Document list blocks iterator.
|
|
15
12
|
*/
|
|
16
13
|
export default class ListWalker {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const nestedItems = [];
|
|
128
|
-
|
|
129
|
-
for ( const { node } of iterateSiblingListBlocks( this._getStartNode(), this._isForward ? 'forward' : 'backward' ) ) {
|
|
130
|
-
const indent = node.getAttribute( 'listIndent' );
|
|
131
|
-
|
|
132
|
-
// Leaving a nested list.
|
|
133
|
-
if ( indent < this._referenceIndent ) {
|
|
134
|
-
// Abort searching blocks.
|
|
135
|
-
if ( !this._lowerIndent ) {
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// While searching for lower indents, update the reference indent to find another parent in the next step.
|
|
140
|
-
this._referenceIndent = indent;
|
|
141
|
-
}
|
|
142
|
-
// Entering a nested list.
|
|
143
|
-
else if ( indent > this._referenceIndent ) {
|
|
144
|
-
// Ignore nested blocks.
|
|
145
|
-
if ( !this._higherIndent ) {
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Collect nested blocks to verify if they are really nested, or it's a different item.
|
|
150
|
-
if ( !this._isForward ) {
|
|
151
|
-
nestedItems.push( node );
|
|
152
|
-
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
// Same indent level block.
|
|
157
|
-
else {
|
|
158
|
-
// Ignore same indent block.
|
|
159
|
-
if ( !this._sameIndent ) {
|
|
160
|
-
// While looking for nested blocks, stop iterating while encountering first same indent block.
|
|
161
|
-
if ( this._higherIndent ) {
|
|
162
|
-
// No more nested blocks so yield nested items.
|
|
163
|
-
if ( nestedItems.length ) {
|
|
164
|
-
yield* nestedItems;
|
|
165
|
-
nestedItems.length = 0;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Abort if item has any additionally specified attribute different.
|
|
175
|
-
if ( this._sameAttributes.some( attr => node.getAttribute( attr ) !== this._startElement.getAttribute( attr ) ) ) {
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// There is another block for the same list item so the nested items were in the same list item.
|
|
181
|
-
if ( nestedItems.length ) {
|
|
182
|
-
yield* nestedItems;
|
|
183
|
-
nestedItems.length = 0;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
yield node;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Returns the model element to start iterating.
|
|
192
|
-
*
|
|
193
|
-
* @private
|
|
194
|
-
* @returns {module:engine/model/element~Element}
|
|
195
|
-
*/
|
|
196
|
-
_getStartNode() {
|
|
197
|
-
if ( this._includeSelf ) {
|
|
198
|
-
return this._startElement;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return this._isForward ?
|
|
202
|
-
this._startElement.nextSibling :
|
|
203
|
-
this._startElement.previousSibling;
|
|
204
|
-
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a document list iterator.
|
|
16
|
+
*
|
|
17
|
+
* @param startElement The start list item block element.
|
|
18
|
+
* @param options.direction The iterating direction.
|
|
19
|
+
* @param options.includeSelf Whether start block should be included in the result (if it's matching other criteria).
|
|
20
|
+
* @param options.sameAttributes Additional attributes that must be the same for each block.
|
|
21
|
+
* @param options.sameIndent Whether blocks with the same indent level as the start block should be included
|
|
22
|
+
* in the result.
|
|
23
|
+
* @param options.lowerIndent Whether blocks with a lower indent level than the start block should be included
|
|
24
|
+
* in the result.
|
|
25
|
+
* @param options.higherIndent Whether blocks with a higher indent level than the start block should be included
|
|
26
|
+
* in the result.
|
|
27
|
+
*/
|
|
28
|
+
constructor(startElement, options) {
|
|
29
|
+
this._startElement = startElement;
|
|
30
|
+
this._referenceIndent = startElement.getAttribute('listIndent');
|
|
31
|
+
this._isForward = options.direction == 'forward';
|
|
32
|
+
this._includeSelf = !!options.includeSelf;
|
|
33
|
+
this._sameAttributes = toArray(options.sameAttributes || []);
|
|
34
|
+
this._sameIndent = !!options.sameIndent;
|
|
35
|
+
this._lowerIndent = !!options.lowerIndent;
|
|
36
|
+
this._higherIndent = !!options.higherIndent;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Performs only first step of iteration and returns the result.
|
|
40
|
+
*
|
|
41
|
+
* @param startElement The start list item block element.
|
|
42
|
+
* @param options.direction The iterating direction.
|
|
43
|
+
* @param options.includeSelf Whether start block should be included in the result (if it's matching other criteria).
|
|
44
|
+
* @param options.sameAttributes Additional attributes that must be the same for each block.
|
|
45
|
+
* @param options.sameIndent Whether blocks with the same indent level as the start block should be included
|
|
46
|
+
* in the result.
|
|
47
|
+
* @param options.lowerIndent Whether blocks with a lower indent level than the start block should be included
|
|
48
|
+
* in the result.
|
|
49
|
+
* @param options.higherIndent Whether blocks with a higher indent level than the start block should be included
|
|
50
|
+
* in the result.
|
|
51
|
+
*/
|
|
52
|
+
static first(startElement, options) {
|
|
53
|
+
const walker = new this(startElement, options);
|
|
54
|
+
const iterator = walker[Symbol.iterator]();
|
|
55
|
+
return first(iterator);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Iterable interface.
|
|
59
|
+
*/
|
|
60
|
+
*[Symbol.iterator]() {
|
|
61
|
+
const nestedItems = [];
|
|
62
|
+
for (const { node } of iterateSiblingListBlocks(this._getStartNode(), this._isForward ? 'forward' : 'backward')) {
|
|
63
|
+
const indent = node.getAttribute('listIndent');
|
|
64
|
+
// Leaving a nested list.
|
|
65
|
+
if (indent < this._referenceIndent) {
|
|
66
|
+
// Abort searching blocks.
|
|
67
|
+
if (!this._lowerIndent) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
// While searching for lower indents, update the reference indent to find another parent in the next step.
|
|
71
|
+
this._referenceIndent = indent;
|
|
72
|
+
}
|
|
73
|
+
// Entering a nested list.
|
|
74
|
+
else if (indent > this._referenceIndent) {
|
|
75
|
+
// Ignore nested blocks.
|
|
76
|
+
if (!this._higherIndent) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
// Collect nested blocks to verify if they are really nested, or it's a different item.
|
|
80
|
+
if (!this._isForward) {
|
|
81
|
+
nestedItems.push(node);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Same indent level block.
|
|
86
|
+
else {
|
|
87
|
+
// Ignore same indent block.
|
|
88
|
+
if (!this._sameIndent) {
|
|
89
|
+
// While looking for nested blocks, stop iterating while encountering first same indent block.
|
|
90
|
+
if (this._higherIndent) {
|
|
91
|
+
// No more nested blocks so yield nested items.
|
|
92
|
+
if (nestedItems.length) {
|
|
93
|
+
yield* nestedItems;
|
|
94
|
+
nestedItems.length = 0;
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
// Abort if item has any additionally specified attribute different.
|
|
101
|
+
if (this._sameAttributes.some(attr => node.getAttribute(attr) !== this._startElement.getAttribute(attr))) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// There is another block for the same list item so the nested items were in the same list item.
|
|
106
|
+
if (nestedItems.length) {
|
|
107
|
+
yield* nestedItems;
|
|
108
|
+
nestedItems.length = 0;
|
|
109
|
+
}
|
|
110
|
+
yield node;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns the model element to start iterating.
|
|
115
|
+
*/
|
|
116
|
+
_getStartNode() {
|
|
117
|
+
if (this._includeSelf) {
|
|
118
|
+
return this._startElement;
|
|
119
|
+
}
|
|
120
|
+
return this._isForward ?
|
|
121
|
+
this._startElement.nextSibling :
|
|
122
|
+
this._startElement.previousSibling;
|
|
123
|
+
}
|
|
205
124
|
}
|
|
206
|
-
|
|
207
125
|
/**
|
|
208
126
|
* Iterates sibling list blocks starting from the given node.
|
|
209
127
|
*
|
|
210
|
-
* @
|
|
211
|
-
* @param
|
|
212
|
-
* @param
|
|
213
|
-
* @returns
|
|
214
|
-
* {@link module:engine/model/element~Element blocks}.
|
|
128
|
+
* @internal
|
|
129
|
+
* @param node The model node.
|
|
130
|
+
* @param direction Iteration direction.
|
|
131
|
+
* @returns The object with `node` and `previous` {@link module:engine/model/element~Element blocks}.
|
|
215
132
|
*/
|
|
216
|
-
export function* iterateSiblingListBlocks(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
node = isForward ? node.nextSibling : node.previousSibling;
|
|
225
|
-
}
|
|
133
|
+
export function* iterateSiblingListBlocks(node, direction = 'forward') {
|
|
134
|
+
const isForward = direction == 'forward';
|
|
135
|
+
let previous = null;
|
|
136
|
+
while (isListItemBlock(node)) {
|
|
137
|
+
yield { node, previous };
|
|
138
|
+
previous = node;
|
|
139
|
+
node = isForward ? node.nextSibling : node.previousSibling;
|
|
140
|
+
}
|
|
226
141
|
}
|
|
227
|
-
|
|
228
142
|
/**
|
|
229
143
|
* The iterable protocol over the list elements.
|
|
230
144
|
*
|
|
231
|
-
* @
|
|
145
|
+
* @internal
|
|
232
146
|
*/
|
|
233
147
|
export class ListBlocksIterable {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
[ Symbol.iterator ]() {
|
|
249
|
-
return iterateSiblingListBlocks( this._listHead, 'forward' );
|
|
250
|
-
}
|
|
148
|
+
/**
|
|
149
|
+
* @param listHead The head element of a list.
|
|
150
|
+
*/
|
|
151
|
+
constructor(listHead) {
|
|
152
|
+
this._listHead = listHead;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* List blocks iterator.
|
|
156
|
+
*
|
|
157
|
+
* Iterates over all blocks of a list.
|
|
158
|
+
*/
|
|
159
|
+
[Symbol.iterator]() {
|
|
160
|
+
return iterateSiblingListBlocks(this._listHead, 'forward');
|
|
161
|
+
}
|
|
251
162
|
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Object returned by `iterateSiblingListBlocks()` when traversing a list.
|
|
255
|
-
*
|
|
256
|
-
* @protected
|
|
257
|
-
* @typedef {Object} module:list/documentlist/utils/listwalker~ListIteratorValue
|
|
258
|
-
* @property {module:engine/model/node~Node} node The current list node.
|
|
259
|
-
* @property {module:engine/model/node~Node} previous The previous list node.
|
|
260
|
-
*/
|