@ckeditor/ckeditor5-list 35.4.0 → 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 (54) 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 -698
  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 +31 -45
  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 -126
  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 +265 -356
  18. package/src/documentlistproperties/documentlistpropertiesutils.js +32 -57
  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 +1 -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 +141 -200
  29. package/src/list/listui.js +16 -25
  30. package/src/list/listutils.js +37 -59
  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 -803
  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 -415
  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
@@ -1,380 +1,289 @@
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/documentlistproperties/documentlistpropertiesediting
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
-
12
9
  import DocumentListEditing from '../documentlist/documentlistediting';
13
10
  import DocumentListStartCommand from './documentliststartcommand';
14
11
  import DocumentListStyleCommand from './documentliststylecommand';
15
12
  import DocumentListReversedCommand from './documentlistreversedcommand';
16
13
  import { listPropertiesUpcastConverter } from './converters';
17
- import {
18
- getAllSupportedStyleTypes,
19
- getListTypeFromListStyleType,
20
- getListStyleTypeFromTypeAttribute,
21
- getTypeAttributeFromListStyleType
22
- } from './utils/style';
14
+ import { getAllSupportedStyleTypes, getListTypeFromListStyleType, getListStyleTypeFromTypeAttribute, getTypeAttributeFromListStyleType } from './utils/style';
23
15
  import DocumentListPropertiesUtils from './documentlistpropertiesutils';
24
-
25
16
  const DEFAULT_LIST_TYPE = 'default';
26
-
27
17
  /**
28
18
  * The document list properties engine feature.
29
19
  *
30
20
  * It registers the `'listStyle'`, `'listReversed'` and `'listStart'` commands if they are enabled in the configuration.
31
- * Read more in {@link module:list/listproperties~ListPropertiesConfig}.
32
- *
33
- * @extends module:core/plugin~Plugin
21
+ * Read more in {@link module:list/listconfig~ListPropertiesConfig}.
34
22
  */
35
23
  export default class DocumentListPropertiesEditing extends Plugin {
36
- /**
37
- * @inheritDoc
38
- */
39
- static get requires() {
40
- return [ DocumentListEditing, DocumentListPropertiesUtils ];
41
- }
42
-
43
- /**
44
- * @inheritDoc
45
- */
46
- static get pluginName() {
47
- return 'DocumentListPropertiesEditing';
48
- }
49
-
50
- /**
51
- * @inheritDoc
52
- */
53
- constructor( editor ) {
54
- super( editor );
55
-
56
- editor.config.define( 'list', {
57
- properties: {
58
- styles: true,
59
- startIndex: false,
60
- reversed: false
61
- }
62
- } );
63
- }
64
-
65
- /**
66
- * @inheritDoc
67
- */
68
- init() {
69
- const editor = this.editor;
70
- const model = editor.model;
71
- const documentListEditing = editor.plugins.get( DocumentListEditing );
72
-
73
- const enabledProperties = editor.config.get( 'list.properties' );
74
- const strategies = createAttributeStrategies( enabledProperties );
75
-
76
- for ( const strategy of strategies ) {
77
- strategy.addCommand( editor );
78
-
79
- model.schema.extend( '$container', { allowAttributes: strategy.attributeName } );
80
- model.schema.extend( '$block', { allowAttributes: strategy.attributeName } );
81
- model.schema.extend( '$blockObject', { allowAttributes: strategy.attributeName } );
82
-
83
- // Register downcast strategy.
84
- documentListEditing.registerDowncastStrategy( {
85
- scope: 'list',
86
- attributeName: strategy.attributeName,
87
-
88
- setAttributeOnDowncast( writer, attributeValue, viewElement ) {
89
- strategy.setAttributeOnDowncast( writer, attributeValue, viewElement );
90
- }
91
- } );
92
- }
93
-
94
- // Set up conversion.
95
- editor.conversion.for( 'upcast' ).add( dispatcher => {
96
- for ( const strategy of strategies ) {
97
- dispatcher.on( 'element:ol', listPropertiesUpcastConverter( strategy ) );
98
- dispatcher.on( 'element:ul', listPropertiesUpcastConverter( strategy ) );
99
- }
100
- } );
101
-
102
- // Verify if the list view element (ul or ol) requires refreshing.
103
- documentListEditing.on( 'checkAttributes:list', ( evt, { viewElement, modelAttributes } ) => {
104
- for ( const strategy of strategies ) {
105
- if ( strategy.getAttributeOnUpcast( viewElement ) != modelAttributes[ strategy.attributeName ] ) {
106
- evt.return = true;
107
- evt.stop();
108
- }
109
- }
110
- } );
111
-
112
- // Reset list properties after indenting list items.
113
- this.listenTo( editor.commands.get( 'indentList' ), 'afterExecute', ( evt, changedBlocks ) => {
114
- model.change( writer => {
115
- for ( const node of changedBlocks ) {
116
- for ( const strategy of strategies ) {
117
- if ( strategy.appliesToListItem( node ) ) {
118
- // Just reset the attribute.
119
- // If there is a previous indented list that this node should be merged into,
120
- // the postfixer will unify all the attributes of both sub-lists.
121
- writer.setAttribute( strategy.attributeName, strategy.defaultValue, node );
122
- }
123
- }
124
- }
125
- } );
126
- } );
127
-
128
- // Add or remove list properties attributes depending on the list type.
129
- documentListEditing.on( 'postFixer', ( evt, { listNodes, writer } ) => {
130
- for ( const { node } of listNodes ) {
131
- for ( const strategy of strategies ) {
132
- // Check if attribute is valid.
133
- if ( strategy.hasValidAttribute( node ) ) {
134
- continue;
135
- }
136
-
137
- // Add missing default property attributes...
138
- if ( strategy.appliesToListItem( node ) ) {
139
- writer.setAttribute( strategy.attributeName, strategy.defaultValue, node );
140
- }
141
- // ...or remove invalid property attributes.
142
- else {
143
- writer.removeAttribute( strategy.attributeName, node );
144
- }
145
-
146
- evt.return = true;
147
- }
148
- }
149
- } );
150
-
151
- // Make sure that all items in a single list (items at the same level & listType) have the same properties.
152
- documentListEditing.on( 'postFixer', ( evt, { listNodes, writer } ) => {
153
- const previousNodesByIndent = []; // Last seen nodes of lower indented lists.
154
-
155
- for ( const { node, previous } of listNodes ) {
156
- // For the first list block there is nothing to compare with.
157
- if ( !previous ) {
158
- continue;
159
- }
160
-
161
- const nodeIndent = node.getAttribute( 'listIndent' );
162
- const previousNodeIndent = previous.getAttribute( 'listIndent' );
163
-
164
- let previousNodeInList = null; // It's like `previous` but has the same indent as current node.
165
-
166
- // Let's find previous node for the same indent.
167
- // We're going to need that when we get back to previous indent.
168
- if ( nodeIndent > previousNodeIndent ) {
169
- previousNodesByIndent[ previousNodeIndent ] = previous;
170
- }
171
- // Restore the one for given indent.
172
- else if ( nodeIndent < previousNodeIndent ) {
173
- previousNodeInList = previousNodesByIndent[ nodeIndent ];
174
- previousNodesByIndent.length = nodeIndent;
175
- }
176
- // Same indent.
177
- else {
178
- previousNodeInList = previous;
179
- }
180
-
181
- // This is a first item of a nested list.
182
- if ( !previousNodeInList ) {
183
- continue;
184
- }
185
-
186
- // This is a first block of a list of a different type.
187
- if ( previousNodeInList.getAttribute( 'listType' ) != node.getAttribute( 'listType' ) ) {
188
- continue;
189
- }
190
-
191
- // Copy properties from the previous one.
192
- for ( const strategy of strategies ) {
193
- const { attributeName } = strategy;
194
-
195
- if ( !strategy.appliesToListItem( node ) ) {
196
- continue;
197
- }
198
-
199
- const value = previousNodeInList.getAttribute( attributeName );
200
-
201
- if ( node.getAttribute( attributeName ) != value ) {
202
- writer.setAttribute( attributeName, value, node );
203
- evt.return = true;
204
- }
205
- }
206
- }
207
- } );
208
- }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get requires() {
28
+ return [DocumentListEditing, DocumentListPropertiesUtils];
29
+ }
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ static get pluginName() {
34
+ return 'DocumentListPropertiesEditing';
35
+ }
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ constructor(editor) {
40
+ super(editor);
41
+ editor.config.define('list', {
42
+ properties: {
43
+ styles: true,
44
+ startIndex: false,
45
+ reversed: false
46
+ }
47
+ });
48
+ }
49
+ /**
50
+ * @inheritDoc
51
+ */
52
+ init() {
53
+ const editor = this.editor;
54
+ const model = editor.model;
55
+ const documentListEditing = editor.plugins.get(DocumentListEditing);
56
+ const enabledProperties = editor.config.get('list.properties');
57
+ const strategies = createAttributeStrategies(enabledProperties);
58
+ for (const strategy of strategies) {
59
+ strategy.addCommand(editor);
60
+ model.schema.extend('$container', { allowAttributes: strategy.attributeName });
61
+ model.schema.extend('$block', { allowAttributes: strategy.attributeName });
62
+ model.schema.extend('$blockObject', { allowAttributes: strategy.attributeName });
63
+ // Register downcast strategy.
64
+ documentListEditing.registerDowncastStrategy({
65
+ scope: 'list',
66
+ attributeName: strategy.attributeName,
67
+ setAttributeOnDowncast(writer, attributeValue, viewElement) {
68
+ strategy.setAttributeOnDowncast(writer, attributeValue, viewElement);
69
+ }
70
+ });
71
+ }
72
+ // Set up conversion.
73
+ editor.conversion.for('upcast').add(dispatcher => {
74
+ for (const strategy of strategies) {
75
+ dispatcher.on('element:ol', listPropertiesUpcastConverter(strategy));
76
+ dispatcher.on('element:ul', listPropertiesUpcastConverter(strategy));
77
+ }
78
+ });
79
+ // Verify if the list view element (ul or ol) requires refreshing.
80
+ documentListEditing.on('checkAttributes:list', (evt, { viewElement, modelAttributes }) => {
81
+ for (const strategy of strategies) {
82
+ if (strategy.getAttributeOnUpcast(viewElement) != modelAttributes[strategy.attributeName]) {
83
+ evt.return = true;
84
+ evt.stop();
85
+ }
86
+ }
87
+ });
88
+ // Reset list properties after indenting list items.
89
+ this.listenTo(editor.commands.get('indentList'), 'afterExecute', (evt, changedBlocks) => {
90
+ model.change(writer => {
91
+ for (const node of changedBlocks) {
92
+ for (const strategy of strategies) {
93
+ if (strategy.appliesToListItem(node)) {
94
+ // Just reset the attribute.
95
+ // If there is a previous indented list that this node should be merged into,
96
+ // the postfixer will unify all the attributes of both sub-lists.
97
+ writer.setAttribute(strategy.attributeName, strategy.defaultValue, node);
98
+ }
99
+ }
100
+ }
101
+ });
102
+ });
103
+ // Add or remove list properties attributes depending on the list type.
104
+ documentListEditing.on('postFixer', (evt, { listNodes, writer }) => {
105
+ for (const { node } of listNodes) {
106
+ for (const strategy of strategies) {
107
+ // Check if attribute is valid.
108
+ if (strategy.hasValidAttribute(node)) {
109
+ continue;
110
+ }
111
+ // Add missing default property attributes...
112
+ if (strategy.appliesToListItem(node)) {
113
+ writer.setAttribute(strategy.attributeName, strategy.defaultValue, node);
114
+ }
115
+ // ...or remove invalid property attributes.
116
+ else {
117
+ writer.removeAttribute(strategy.attributeName, node);
118
+ }
119
+ evt.return = true;
120
+ }
121
+ }
122
+ });
123
+ // Make sure that all items in a single list (items at the same level & listType) have the same properties.
124
+ documentListEditing.on('postFixer', (evt, { listNodes, writer }) => {
125
+ const previousNodesByIndent = []; // Last seen nodes of lower indented lists.
126
+ for (const { node, previous } of listNodes) {
127
+ // For the first list block there is nothing to compare with.
128
+ if (!previous) {
129
+ continue;
130
+ }
131
+ const nodeIndent = node.getAttribute('listIndent');
132
+ const previousNodeIndent = previous.getAttribute('listIndent');
133
+ let previousNodeInList = null; // It's like `previous` but has the same indent as current node.
134
+ // Let's find previous node for the same indent.
135
+ // We're going to need that when we get back to previous indent.
136
+ if (nodeIndent > previousNodeIndent) {
137
+ previousNodesByIndent[previousNodeIndent] = previous;
138
+ }
139
+ // Restore the one for given indent.
140
+ else if (nodeIndent < previousNodeIndent) {
141
+ previousNodeInList = previousNodesByIndent[nodeIndent];
142
+ previousNodesByIndent.length = nodeIndent;
143
+ }
144
+ // Same indent.
145
+ else {
146
+ previousNodeInList = previous;
147
+ }
148
+ // This is a first item of a nested list.
149
+ if (!previousNodeInList) {
150
+ continue;
151
+ }
152
+ // This is a first block of a list of a different type.
153
+ if (previousNodeInList.getAttribute('listType') != node.getAttribute('listType')) {
154
+ continue;
155
+ }
156
+ // Copy properties from the previous one.
157
+ for (const strategy of strategies) {
158
+ const { attributeName } = strategy;
159
+ if (!strategy.appliesToListItem(node)) {
160
+ continue;
161
+ }
162
+ const value = previousNodeInList.getAttribute(attributeName);
163
+ if (node.getAttribute(attributeName) != value) {
164
+ writer.setAttribute(attributeName, value, node);
165
+ evt.return = true;
166
+ }
167
+ }
168
+ }
169
+ });
170
+ }
209
171
  }
210
-
211
172
  /**
212
- * Strategy for dealing with `listItem` attributes supported by this plugin.
213
- *
214
- * @typedef {Object} module:list/documentlistproperties/documentlistpropertiesediting~AttributeStrategy
215
- * @protected
216
- * @property {String} attributeName The model attribute name.
217
- * @property {*} defaultValue The model attribute default value.
218
- * @property {Object} viewConsumables The view consumable as expected by
219
- * {@link module:engine/conversion/viewconsumable~ViewConsumable#consume `ViewConsumable`}.
220
- * @property {Function} addCommand Registers an editor command.
221
- * @property {Function} appliesToListItem Verifies whether the strategy is applicable for the specified model element.
222
- * @property {Function} hasValidAttribute Verifies whether the model attribute value is valid.
223
- * @property {Function} setAttributeOnDowncast Sets the property on the view element.
224
- * @property {Function} getAttributeOnUpcast Retrieves the property value from the view element.
173
+ * Creates an array of strategies for dealing with enabled listItem attributes.
225
174
  */
226
-
227
- // Creates an array of strategies for dealing with enabled listItem attributes.
228
- //
229
- // @param {Object} enabledProperties
230
- // @param {Boolean|Object} enabledProperties.styles
231
- // @param {Boolean} [enabledProperties.styles.useAttribute]
232
- // @param {Boolean} enabledProperties.reversed
233
- // @param {Boolean} enabledProperties.startIndex
234
- // @returns {Array.<module:list/documentlistproperties/documentlistpropertiesediting~AttributeStrategy>}
235
- function createAttributeStrategies( enabledProperties ) {
236
- const strategies = [];
237
-
238
- if ( enabledProperties.styles ) {
239
- const useAttribute = typeof enabledProperties.styles == 'object' && enabledProperties.styles.useAttribute;
240
-
241
- strategies.push( {
242
- attributeName: 'listStyle',
243
- defaultValue: DEFAULT_LIST_TYPE,
244
- viewConsumables: { styles: 'list-style-type' },
245
-
246
- addCommand( editor ) {
247
- let supportedTypes = getAllSupportedStyleTypes();
248
-
249
- if ( useAttribute ) {
250
- supportedTypes = supportedTypes.filter( styleType => !!getTypeAttributeFromListStyleType( styleType ) );
251
- }
252
-
253
- editor.commands.add( 'listStyle', new DocumentListStyleCommand( editor, DEFAULT_LIST_TYPE, supportedTypes ) );
254
- },
255
-
256
- appliesToListItem() {
257
- return true;
258
- },
259
-
260
- hasValidAttribute( item ) {
261
- if ( !item.hasAttribute( 'listStyle' ) ) {
262
- return false;
263
- }
264
-
265
- const value = item.getAttribute( 'listStyle' );
266
-
267
- if ( value == DEFAULT_LIST_TYPE ) {
268
- return true;
269
- }
270
-
271
- return getListTypeFromListStyleType( value ) == item.getAttribute( 'listType' );
272
- },
273
-
274
- setAttributeOnDowncast( writer, listStyle, element ) {
275
- if ( listStyle && listStyle !== DEFAULT_LIST_TYPE ) {
276
- if ( useAttribute ) {
277
- const value = getTypeAttributeFromListStyleType( listStyle );
278
-
279
- if ( value ) {
280
- writer.setAttribute( 'type', value, element );
281
-
282
- return;
283
- }
284
- } else {
285
- writer.setStyle( 'list-style-type', listStyle, element );
286
-
287
- return;
288
- }
289
- }
290
-
291
- writer.removeStyle( 'list-style-type', element );
292
- writer.removeAttribute( 'type', element );
293
- },
294
-
295
- getAttributeOnUpcast( listParent ) {
296
- const style = listParent.getStyle( 'list-style-type' );
297
-
298
- if ( style ) {
299
- return style;
300
- }
301
-
302
- const attribute = listParent.getAttribute( 'type' );
303
-
304
- if ( attribute ) {
305
- return getListStyleTypeFromTypeAttribute( attribute );
306
- }
307
-
308
- return DEFAULT_LIST_TYPE;
309
- }
310
- } );
311
- }
312
-
313
- if ( enabledProperties.reversed ) {
314
- strategies.push( {
315
- attributeName: 'listReversed',
316
- defaultValue: false,
317
- viewConsumables: { attributes: 'reversed' },
318
-
319
- addCommand( editor ) {
320
- editor.commands.add( 'listReversed', new DocumentListReversedCommand( editor ) );
321
- },
322
-
323
- appliesToListItem( item ) {
324
- return item.getAttribute( 'listType' ) == 'numbered';
325
- },
326
-
327
- hasValidAttribute( item ) {
328
- return this.appliesToListItem( item ) == item.hasAttribute( 'listReversed' );
329
- },
330
-
331
- setAttributeOnDowncast( writer, listReversed, element ) {
332
- if ( listReversed ) {
333
- writer.setAttribute( 'reversed', 'reversed', element );
334
- } else {
335
- writer.removeAttribute( 'reversed', element );
336
- }
337
- },
338
-
339
- getAttributeOnUpcast( listParent ) {
340
- return listParent.hasAttribute( 'reversed' );
341
- }
342
- } );
343
- }
344
-
345
- if ( enabledProperties.startIndex ) {
346
- strategies.push( {
347
- attributeName: 'listStart',
348
- defaultValue: 1,
349
- viewConsumables: { attributes: 'start' },
350
-
351
- addCommand( editor ) {
352
- editor.commands.add( 'listStart', new DocumentListStartCommand( editor ) );
353
- },
354
-
355
- appliesToListItem( item ) {
356
- return item.getAttribute( 'listType' ) == 'numbered';
357
- },
358
-
359
- hasValidAttribute( item ) {
360
- return this.appliesToListItem( item ) == item.hasAttribute( 'listStart' );
361
- },
362
-
363
- setAttributeOnDowncast( writer, listStart, element ) {
364
- if ( listStart == 0 || listStart > 1 ) {
365
- writer.setAttribute( 'start', listStart, element );
366
- } else {
367
- writer.removeAttribute( 'start', element );
368
- }
369
- },
370
-
371
- getAttributeOnUpcast( listParent ) {
372
- const startAttributeValue = listParent.getAttribute( 'start' );
373
-
374
- return startAttributeValue >= 0 ? startAttributeValue : 1;
375
- }
376
- } );
377
- }
378
-
379
- return strategies;
175
+ function createAttributeStrategies(enabledProperties) {
176
+ const strategies = [];
177
+ if (enabledProperties.styles) {
178
+ const useAttribute = typeof enabledProperties.styles == 'object' && enabledProperties.styles.useAttribute;
179
+ strategies.push({
180
+ attributeName: 'listStyle',
181
+ defaultValue: DEFAULT_LIST_TYPE,
182
+ viewConsumables: { styles: 'list-style-type' },
183
+ addCommand(editor) {
184
+ let supportedTypes = getAllSupportedStyleTypes();
185
+ if (useAttribute) {
186
+ supportedTypes = supportedTypes.filter(styleType => !!getTypeAttributeFromListStyleType(styleType));
187
+ }
188
+ editor.commands.add('listStyle', new DocumentListStyleCommand(editor, DEFAULT_LIST_TYPE, supportedTypes));
189
+ },
190
+ appliesToListItem() {
191
+ return true;
192
+ },
193
+ hasValidAttribute(item) {
194
+ if (!item.hasAttribute('listStyle')) {
195
+ return false;
196
+ }
197
+ const value = item.getAttribute('listStyle');
198
+ if (value == DEFAULT_LIST_TYPE) {
199
+ return true;
200
+ }
201
+ return getListTypeFromListStyleType(value) == item.getAttribute('listType');
202
+ },
203
+ setAttributeOnDowncast(writer, listStyle, element) {
204
+ if (listStyle && listStyle !== DEFAULT_LIST_TYPE) {
205
+ if (useAttribute) {
206
+ const value = getTypeAttributeFromListStyleType(listStyle);
207
+ if (value) {
208
+ writer.setAttribute('type', value, element);
209
+ return;
210
+ }
211
+ }
212
+ else {
213
+ writer.setStyle('list-style-type', listStyle, element);
214
+ return;
215
+ }
216
+ }
217
+ writer.removeStyle('list-style-type', element);
218
+ writer.removeAttribute('type', element);
219
+ },
220
+ getAttributeOnUpcast(listParent) {
221
+ const style = listParent.getStyle('list-style-type');
222
+ if (style) {
223
+ return style;
224
+ }
225
+ const attribute = listParent.getAttribute('type');
226
+ if (attribute) {
227
+ return getListStyleTypeFromTypeAttribute(attribute);
228
+ }
229
+ return DEFAULT_LIST_TYPE;
230
+ }
231
+ });
232
+ }
233
+ if (enabledProperties.reversed) {
234
+ strategies.push({
235
+ attributeName: 'listReversed',
236
+ defaultValue: false,
237
+ viewConsumables: { attributes: 'reversed' },
238
+ addCommand(editor) {
239
+ editor.commands.add('listReversed', new DocumentListReversedCommand(editor));
240
+ },
241
+ appliesToListItem(item) {
242
+ return item.getAttribute('listType') == 'numbered';
243
+ },
244
+ hasValidAttribute(item) {
245
+ return this.appliesToListItem(item) == item.hasAttribute('listReversed');
246
+ },
247
+ setAttributeOnDowncast(writer, listReversed, element) {
248
+ if (listReversed) {
249
+ writer.setAttribute('reversed', 'reversed', element);
250
+ }
251
+ else {
252
+ writer.removeAttribute('reversed', element);
253
+ }
254
+ },
255
+ getAttributeOnUpcast(listParent) {
256
+ return listParent.hasAttribute('reversed');
257
+ }
258
+ });
259
+ }
260
+ if (enabledProperties.startIndex) {
261
+ strategies.push({
262
+ attributeName: 'listStart',
263
+ defaultValue: 1,
264
+ viewConsumables: { attributes: 'start' },
265
+ addCommand(editor) {
266
+ editor.commands.add('listStart', new DocumentListStartCommand(editor));
267
+ },
268
+ appliesToListItem(item) {
269
+ return item.getAttribute('listType') == 'numbered';
270
+ },
271
+ hasValidAttribute(item) {
272
+ return this.appliesToListItem(item) == item.hasAttribute('listStart');
273
+ },
274
+ setAttributeOnDowncast(writer, listStart, element) {
275
+ if (listStart == 0 || listStart > 1) {
276
+ writer.setAttribute('start', listStart, element);
277
+ }
278
+ else {
279
+ writer.removeAttribute('start', element);
280
+ }
281
+ },
282
+ getAttributeOnUpcast(listParent) {
283
+ const startAttributeValue = listParent.getAttribute('start');
284
+ return startAttributeValue >= 0 ? startAttributeValue : 1;
285
+ }
286
+ });
287
+ }
288
+ return strategies;
380
289
  }