@ckeditor/ckeditor5-list 33.0.0 → 34.1.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 +2 -2
- package/README.md +2 -1
- package/build/list.js +1 -1
- package/build/translations/de.js +1 -1
- package/build/translations/en-au.js +1 -1
- package/build/translations/gl.js +1 -1
- package/build/translations/jv.js +1 -0
- package/build/translations/lv.js +1 -1
- package/build/translations/pt-br.js +1 -1
- package/build/translations/sk.js +1 -1
- package/build/translations/ur.js +1 -0
- package/ckeditor5-metadata.json +52 -0
- package/lang/translations/de.po +4 -4
- package/lang/translations/en-au.po +4 -4
- package/lang/translations/gl.po +4 -4
- package/lang/translations/jv.po +125 -0
- package/lang/translations/lv.po +7 -7
- package/lang/translations/pt-br.po +4 -4
- package/lang/translations/sk.po +4 -4
- package/lang/translations/ur.po +125 -0
- package/package.json +37 -24
- package/src/documentlist/converters.js +470 -0
- package/src/documentlist/documentlistcommand.js +216 -0
- package/src/documentlist/documentlistediting.js +724 -0
- package/src/documentlist/documentlistindentcommand.js +182 -0
- package/src/documentlist/documentlistmergecommand.js +235 -0
- package/src/documentlist/documentlistsplitcommand.js +114 -0
- package/src/documentlist/utils/listwalker.js +260 -0
- package/src/documentlist/utils/model.js +534 -0
- package/src/documentlist/utils/postfixers.js +138 -0
- package/src/documentlist/utils/view.js +148 -0
- package/src/documentlist.js +36 -0
- package/src/documentlistproperties/converters.js +57 -0
- package/src/documentlistproperties/documentlistpropertiesediting.js +377 -0
- package/src/documentlistproperties/documentlistreversedcommand.js +76 -0
- package/src/documentlistproperties/documentliststartcommand.js +76 -0
- package/src/documentlistproperties/documentliststylecommand.js +163 -0
- package/src/documentlistproperties/utils/style.js +74 -0
- package/src/documentlistproperties.js +37 -0
- package/src/index.js +4 -0
- package/src/list/converters.js +4 -0
- package/src/list/listediting.js +12 -13
- package/src/list.js +3 -2
- package/src/listproperties/listpropertiesediting.js +1 -1
- package/src/listproperties/listpropertiesui.js +6 -1
- package/src/listproperties/listreversedcommand.js +1 -1
- package/src/listproperties/liststartcommand.js +1 -1
- package/src/listproperties/liststylecommand.js +1 -1
- package/src/listproperties.js +47 -8
- package/theme/documentlist.css +8 -0
- package/build/list.js.map +0 -1
- package/src/listproperties/ui/inputnumberview.js +0 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module list/documentlist/utils/listwalker
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { first, toArray } from 'ckeditor5/src/utils';
|
|
11
|
+
import { isListItemBlock } from './model';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Document list blocks iterator.
|
|
15
|
+
*/
|
|
16
|
+
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
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Iterates sibling list blocks starting from the given node.
|
|
209
|
+
*
|
|
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}.
|
|
215
|
+
*/
|
|
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
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The iterable protocol over the list elements.
|
|
230
|
+
*
|
|
231
|
+
* @protected
|
|
232
|
+
*/
|
|
233
|
+
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
|
+
}
|
|
251
|
+
}
|
|
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
|
+
*/
|