@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.
Files changed (55) hide show
  1. package/LICENSE.md +1 -1
  2. package/build/list.js +2 -2
  3. package/package.json +43 -39
  4. package/src/documentlist/converters.js +303 -419
  5. package/src/documentlist/documentlistcommand.js +136 -207
  6. package/src/documentlist/documentlistediting.js +538 -697
  7. package/src/documentlist/documentlistindentcommand.js +115 -168
  8. package/src/documentlist/documentlistmergecommand.js +161 -222
  9. package/src/documentlist/documentlistsplitcommand.js +59 -103
  10. package/src/documentlist/documentlistutils.js +41 -0
  11. package/src/documentlist/utils/listwalker.js +138 -236
  12. package/src/documentlist/utils/model.js +322 -421
  13. package/src/documentlist/utils/postfixers.js +98 -118
  14. package/src/documentlist/utils/view.js +74 -105
  15. package/src/documentlist.js +13 -19
  16. package/src/documentlistproperties/converters.js +33 -47
  17. package/src/documentlistproperties/documentlistpropertiesediting.js +266 -354
  18. package/src/documentlistproperties/documentlistpropertiesutils.js +44 -0
  19. package/src/documentlistproperties/documentlistreversedcommand.js +40 -61
  20. package/src/documentlistproperties/documentliststartcommand.js +42 -61
  21. package/src/documentlistproperties/documentliststylecommand.js +97 -147
  22. package/src/documentlistproperties/utils/style.js +27 -47
  23. package/src/documentlistproperties.js +13 -19
  24. package/src/index.js +4 -3
  25. package/src/list/converters.js +772 -929
  26. package/src/list/indentcommand.js +105 -140
  27. package/src/list/listcommand.js +262 -315
  28. package/src/list/listediting.js +142 -200
  29. package/src/list/listui.js +16 -25
  30. package/src/list/listutils.js +46 -0
  31. package/src/list/utils.js +295 -378
  32. package/src/list.js +13 -44
  33. package/src/listcommands.js +5 -0
  34. package/src/listconfig.js +5 -0
  35. package/src/listproperties/listpropertiesediting.js +656 -801
  36. package/src/listproperties/listpropertiesui.js +244 -296
  37. package/src/listproperties/listreversedcommand.js +37 -49
  38. package/src/listproperties/liststartcommand.js +37 -49
  39. package/src/listproperties/liststylecommand.js +82 -115
  40. package/src/listproperties/ui/collapsibleview.js +75 -138
  41. package/src/listproperties/ui/listpropertiesview.js +289 -414
  42. package/src/listproperties.js +13 -118
  43. package/src/liststyle.js +18 -24
  44. package/src/todolist/checktodolistcommand.js +60 -102
  45. package/src/todolist/todolistconverters.js +189 -271
  46. package/src/todolist/todolistediting.js +141 -206
  47. package/src/todolist/todolistui.js +14 -21
  48. package/src/todolist.js +13 -19
  49. package/theme/collapsible.css +1 -1
  50. package/theme/documentlist.css +1 -1
  51. package/theme/list.css +40 -0
  52. package/theme/listproperties.css +1 -1
  53. package/theme/liststyles.css +1 -37
  54. package/theme/todolist.css +1 -1
  55. package/build/list.js.map +0 -1
@@ -1,260 +1,162 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
- * Creates a document list iterator.
19
- *
20
- * @param {module:engine/model/element~Element} startElement The start list item block element.
21
- * @param {Object} options
22
- * @param {'forward'|'backward'} [options.direction='backward'] The iterating direction.
23
- * @param {Boolean} [options.includeSelf=false] Whether start block should be included in the result (if it's matching other criteria).
24
- * @param {Array.<String>|String} [options.sameAttributes=[]] Additional attributes that must be the same for each block.
25
- * @param {Boolean} [options.sameIndent=false] Whether blocks with the same indent level as the start block should be included
26
- * in the result.
27
- * @param {Boolean} [options.lowerIndent=false] Whether blocks with a lower indent level than the start block should be included
28
- * in the result.
29
- * @param {Boolean} [options.higherIndent=false] Whether blocks with a higher indent level than the start block should be included
30
- * in the result.
31
- */
32
- constructor( startElement, options ) {
33
- /**
34
- * The start list item block element.
35
- *
36
- * @private
37
- * @type {module:engine/model/element~Element}
38
- */
39
- this._startElement = startElement;
40
-
41
- /**
42
- * The reference indent. Initialized by the indent of the start block.
43
- *
44
- * @private
45
- * @type {Number}
46
- */
47
- this._referenceIndent = startElement.getAttribute( 'listIndent' );
48
-
49
- /**
50
- * The iterating direction.
51
- *
52
- * @private
53
- * @type {Boolean}
54
- */
55
- this._isForward = options.direction == 'forward';
56
-
57
- /**
58
- * Whether start block should be included in the result (if it's matching other criteria).
59
- *
60
- * @private
61
- * @type {Boolean}
62
- */
63
- this._includeSelf = !!options.includeSelf;
64
-
65
- /**
66
- * Additional attributes that must be the same for each block.
67
- *
68
- * @private
69
- * @type {Array.<String>}
70
- */
71
- this._sameAttributes = toArray( options.sameAttributes || [] );
72
-
73
- /**
74
- * Whether blocks with the same indent level as the start block should be included in the result.
75
- *
76
- * @private
77
- * @type {Boolean}
78
- */
79
- this._sameIndent = !!options.sameIndent;
80
-
81
- /**
82
- * Whether blocks with a lower indent level than the start block should be included in the result.
83
- *
84
- * @private
85
- * @type {Boolean}
86
- */
87
- this._lowerIndent = !!options.lowerIndent;
88
-
89
- /**
90
- * Whether blocks with a higher indent level than the start block should be included in the result.
91
- *
92
- * @private
93
- * @type {Boolean}
94
- */
95
- this._higherIndent = !!options.higherIndent;
96
- }
97
-
98
- /**
99
- * Performs only first step of iteration and returns the result.
100
- *
101
- * @param {module:engine/model/element~Element} startElement The start list item block element.
102
- * @param {Object} options
103
- * @param {'forward'|'backward'} [options.direction='backward'] The iterating direction.
104
- * @param {Boolean} [options.includeSelf=false] Whether start block should be included in the result (if it's matching other criteria).
105
- * @param {Array.<String>|String} [options.sameAttributes=[]] Additional attributes that must be the same for each block.
106
- * @param {Boolean} [options.sameIndent=false] Whether blocks with the same indent level as the start block should be included
107
- * in the result.
108
- * @param {Boolean} [options.lowerIndent=false] Whether blocks with a lower indent level than the start block should be included
109
- * in the result.
110
- * @param {Boolean} [options.higherIndent=false] Whether blocks with a higher indent level than the start block should be included
111
- * in the result.
112
- * @returns {module:engine/model/element~Element|null}
113
- */
114
- static first( startElement, options ) {
115
- const walker = new this( startElement, options );
116
- const iterator = walker[ Symbol.iterator ]();
117
-
118
- return first( iterator );
119
- }
120
-
121
- /**
122
- * Iterable interface.
123
- *
124
- * @returns {Iterable.<module:engine/model/element~Element>}
125
- */
126
- * [ Symbol.iterator ]() {
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
- * @protected
211
- * @param {module:engine/model/node~Node} node The model node.
212
- * @param {'backward'|'forward'} [direction='forward'] Iteration direction.
213
- * @returns {Iterator.<module:list/documentlist/utils/listwalker~ListIteratorValue>} The object with `node` and `previous`
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( node, direction = 'forward' ) {
217
- const isForward = direction == 'forward';
218
- let previous = null;
219
-
220
- while ( isListItemBlock( node ) ) {
221
- yield { node, previous };
222
-
223
- previous = node;
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
- * @protected
145
+ * @internal
232
146
  */
233
147
  export class ListBlocksIterable {
234
- /**
235
- * @param {module:engine/model/element~Element} listHead The head element of a list.
236
- */
237
- constructor( listHead ) {
238
- this._listHead = listHead;
239
- }
240
-
241
- /**
242
- * List blocks iterator.
243
- *
244
- * Iterates over all blocks of a list.
245
- *
246
- * @returns {Iterator.<module:list/documentlist/utils/listwalker~ListIteratorValue>}
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
- */