@ckeditor/ckeditor5-list 39.0.2 → 40.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 (109) hide show
  1. package/build/list.js +1 -1
  2. package/build/list.js.map +1 -0
  3. package/build/translations/fi.js +1 -1
  4. package/build/translations/pt-br.js +1 -1
  5. package/ckeditor5-metadata.json +44 -0
  6. package/lang/translations/fi.po +1 -1
  7. package/lang/translations/pt-br.po +10 -10
  8. package/package.json +3 -3
  9. package/src/augmentation.d.ts +52 -50
  10. package/src/augmentation.js +5 -5
  11. package/src/documentlist/adjacentlistssupport.d.ts +15 -15
  12. package/src/documentlist/adjacentlistssupport.js +81 -81
  13. package/src/documentlist/converters.d.ts +65 -63
  14. package/src/documentlist/converters.js +441 -354
  15. package/src/documentlist/documentlistcommand.d.ts +80 -80
  16. package/src/documentlist/documentlistcommand.js +150 -145
  17. package/src/documentlist/documentlistediting.d.ts +212 -154
  18. package/src/documentlist/documentlistediting.js +645 -565
  19. package/src/documentlist/documentlistindentcommand.d.ts +62 -62
  20. package/src/documentlist/documentlistindentcommand.js +129 -129
  21. package/src/documentlist/documentlistmergecommand.d.ts +76 -76
  22. package/src/documentlist/documentlistmergecommand.js +174 -174
  23. package/src/documentlist/documentlistsplitcommand.d.ts +67 -67
  24. package/src/documentlist/documentlistsplitcommand.js +70 -70
  25. package/src/documentlist/documentlistutils.d.ts +46 -46
  26. package/src/documentlist/documentlistutils.js +50 -50
  27. package/src/documentlist/utils/listwalker.d.ts +145 -141
  28. package/src/documentlist/utils/listwalker.js +182 -162
  29. package/src/documentlist/utils/model.d.ts +202 -193
  30. package/src/documentlist/utils/model.js +455 -435
  31. package/src/documentlist/utils/postfixers.d.ts +37 -37
  32. package/src/documentlist/utils/postfixers.js +126 -118
  33. package/src/documentlist/utils/view.d.ts +81 -81
  34. package/src/documentlist/utils/view.js +117 -117
  35. package/src/documentlist.d.ts +26 -26
  36. package/src/documentlist.js +30 -30
  37. package/src/documentlistproperties/converters.d.ts +19 -19
  38. package/src/documentlistproperties/converters.js +43 -43
  39. package/src/documentlistproperties/documentlistpropertiesediting.d.ts +88 -88
  40. package/src/documentlistproperties/documentlistpropertiesediting.js +266 -289
  41. package/src/documentlistproperties/documentlistpropertiesutils.d.ts +33 -33
  42. package/src/documentlistproperties/documentlistpropertiesutils.js +44 -44
  43. package/src/documentlistproperties/documentlistreversedcommand.d.ts +36 -36
  44. package/src/documentlistproperties/documentlistreversedcommand.js +55 -55
  45. package/src/documentlistproperties/documentliststartcommand.d.ts +38 -38
  46. package/src/documentlistproperties/documentliststartcommand.js +57 -57
  47. package/src/documentlistproperties/documentliststylecommand.d.ts +72 -72
  48. package/src/documentlistproperties/documentliststylecommand.js +113 -113
  49. package/src/documentlistproperties/utils/style.d.ts +20 -20
  50. package/src/documentlistproperties/utils/style.js +54 -54
  51. package/src/documentlistproperties.d.ts +27 -27
  52. package/src/documentlistproperties.js +31 -31
  53. package/src/index.d.ts +43 -40
  54. package/src/index.js +29 -27
  55. package/src/list/converters.d.ts +196 -196
  56. package/src/list/converters.js +905 -905
  57. package/src/list/indentcommand.d.ts +37 -37
  58. package/src/list/indentcommand.js +107 -107
  59. package/src/list/listcommand.d.ts +55 -55
  60. package/src/list/listcommand.js +274 -274
  61. package/src/list/listediting.d.ts +32 -32
  62. package/src/list/listediting.js +161 -161
  63. package/src/list/listui.d.ts +19 -19
  64. package/src/list/listui.js +32 -32
  65. package/src/list/listutils.d.ts +41 -41
  66. package/src/list/listutils.js +46 -46
  67. package/src/list/utils.d.ts +112 -112
  68. package/src/list/utils.js +374 -374
  69. package/src/list.d.ts +26 -26
  70. package/src/list.js +30 -30
  71. package/src/listconfig.d.ts +132 -122
  72. package/src/listconfig.js +5 -5
  73. package/src/listproperties/listpropertiesediting.d.ts +72 -72
  74. package/src/listproperties/listpropertiesediting.js +696 -696
  75. package/src/listproperties/listpropertiesui.d.ts +23 -23
  76. package/src/listproperties/listpropertiesui.js +277 -277
  77. package/src/listproperties/listreversedcommand.d.ts +38 -38
  78. package/src/listproperties/listreversedcommand.js +52 -52
  79. package/src/listproperties/liststartcommand.d.ts +37 -37
  80. package/src/listproperties/liststartcommand.js +51 -51
  81. package/src/listproperties/liststylecommand.d.ts +67 -67
  82. package/src/listproperties/liststylecommand.js +99 -99
  83. package/src/listproperties/ui/collapsibleview.d.ts +63 -63
  84. package/src/listproperties/ui/collapsibleview.js +89 -89
  85. package/src/listproperties/ui/listpropertiesview.d.ts +157 -157
  86. package/src/listproperties/ui/listpropertiesview.js +299 -299
  87. package/src/listproperties.d.ts +26 -26
  88. package/src/listproperties.js +30 -30
  89. package/src/liststyle.d.ts +28 -28
  90. package/src/liststyle.js +36 -36
  91. package/src/tododocumentlist/checktododocumentlistcommand.d.ts +49 -0
  92. package/src/tododocumentlist/checktododocumentlistcommand.js +82 -0
  93. package/src/tododocumentlist/todocheckboxchangeobserver.d.ts +41 -0
  94. package/src/tododocumentlist/todocheckboxchangeobserver.js +37 -0
  95. package/src/tododocumentlist/tododocumentlistediting.d.ts +38 -0
  96. package/src/tododocumentlist/tododocumentlistediting.js +399 -0
  97. package/src/tododocumentlist.d.ts +27 -0
  98. package/src/tododocumentlist.js +31 -0
  99. package/src/todolist/checktodolistcommand.d.ts +52 -52
  100. package/src/todolist/checktodolistcommand.js +76 -76
  101. package/src/todolist/todolistconverters.d.ts +82 -82
  102. package/src/todolist/todolistconverters.js +260 -260
  103. package/src/todolist/todolistediting.d.ts +39 -39
  104. package/src/todolist/todolistediting.js +161 -161
  105. package/src/todolist/todolistui.d.ts +19 -19
  106. package/src/todolist/todolistui.js +29 -29
  107. package/src/todolist.d.ts +27 -27
  108. package/src/todolist.js +31 -31
  109. package/theme/todolist.css +101 -70
@@ -1,289 +1,266 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * @module list/documentlistproperties/documentlistpropertiesediting
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import DocumentListEditing from '../documentlist/documentlistediting';
10
- import DocumentListStartCommand from './documentliststartcommand';
11
- import DocumentListStyleCommand from './documentliststylecommand';
12
- import DocumentListReversedCommand from './documentlistreversedcommand';
13
- import { listPropertiesUpcastConverter } from './converters';
14
- import { getAllSupportedStyleTypes, getListTypeFromListStyleType, getListStyleTypeFromTypeAttribute, getTypeAttributeFromListStyleType } from './utils/style';
15
- import DocumentListPropertiesUtils from './documentlistpropertiesutils';
16
- const DEFAULT_LIST_TYPE = 'default';
17
- /**
18
- * The document list properties engine feature.
19
- *
20
- * It registers the `'listStyle'`, `'listReversed'` and `'listStart'` commands if they are enabled in the configuration.
21
- * Read more in {@link module:list/listconfig~ListPropertiesConfig}.
22
- */
23
- export default class DocumentListPropertiesEditing extends Plugin {
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
- }
171
- }
172
- /**
173
- * Creates an array of strategies for dealing with enabled listItem attributes.
174
- */
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;
289
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * @module list/documentlistproperties/documentlistpropertiesediting
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import DocumentListEditing from '../documentlist/documentlistediting';
10
+ import DocumentListStartCommand from './documentliststartcommand';
11
+ import DocumentListStyleCommand from './documentliststylecommand';
12
+ import DocumentListReversedCommand from './documentlistreversedcommand';
13
+ import { listPropertiesUpcastConverter } from './converters';
14
+ import { getAllSupportedStyleTypes, getListTypeFromListStyleType, getListStyleTypeFromTypeAttribute, getTypeAttributeFromListStyleType } from './utils/style';
15
+ import DocumentListPropertiesUtils from './documentlistpropertiesutils';
16
+ const DEFAULT_LIST_TYPE = 'default';
17
+ /**
18
+ * The document list properties engine feature.
19
+ *
20
+ * It registers the `'listStyle'`, `'listReversed'` and `'listStart'` commands if they are enabled in the configuration.
21
+ * Read more in {@link module:list/listconfig~ListPropertiesConfig}.
22
+ */
23
+ export default class DocumentListPropertiesEditing extends Plugin {
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.properties', {
42
+ styles: true,
43
+ startIndex: false,
44
+ reversed: false
45
+ });
46
+ }
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ init() {
51
+ const editor = this.editor;
52
+ const model = editor.model;
53
+ const documentListEditing = editor.plugins.get(DocumentListEditing);
54
+ const enabledProperties = editor.config.get('list.properties');
55
+ const strategies = createAttributeStrategies(enabledProperties);
56
+ for (const strategy of strategies) {
57
+ strategy.addCommand(editor);
58
+ model.schema.extend('$listItem', { allowAttributes: strategy.attributeName });
59
+ // Register downcast strategy.
60
+ documentListEditing.registerDowncastStrategy({
61
+ scope: 'list',
62
+ attributeName: strategy.attributeName,
63
+ setAttributeOnDowncast(writer, attributeValue, viewElement) {
64
+ strategy.setAttributeOnDowncast(writer, attributeValue, viewElement);
65
+ }
66
+ });
67
+ }
68
+ // Set up conversion.
69
+ editor.conversion.for('upcast').add(dispatcher => {
70
+ for (const strategy of strategies) {
71
+ dispatcher.on('element:ol', listPropertiesUpcastConverter(strategy));
72
+ dispatcher.on('element:ul', listPropertiesUpcastConverter(strategy));
73
+ }
74
+ });
75
+ // Verify if the list view element (ul or ol) requires refreshing.
76
+ documentListEditing.on('checkAttributes:list', (evt, { viewElement, modelAttributes }) => {
77
+ for (const strategy of strategies) {
78
+ if (strategy.getAttributeOnUpcast(viewElement) != modelAttributes[strategy.attributeName]) {
79
+ evt.return = true;
80
+ evt.stop();
81
+ }
82
+ }
83
+ });
84
+ // Reset list properties after indenting list items.
85
+ this.listenTo(editor.commands.get('indentList'), 'afterExecute', (evt, changedBlocks) => {
86
+ model.change(writer => {
87
+ for (const node of changedBlocks) {
88
+ for (const strategy of strategies) {
89
+ if (strategy.appliesToListItem(node)) {
90
+ // Just reset the attribute.
91
+ // If there is a previous indented list that this node should be merged into,
92
+ // the postfixer will unify all the attributes of both sub-lists.
93
+ writer.setAttribute(strategy.attributeName, strategy.defaultValue, node);
94
+ }
95
+ }
96
+ }
97
+ });
98
+ });
99
+ // Add or remove list properties attributes depending on the list type.
100
+ documentListEditing.on('postFixer', (evt, { listNodes, writer }) => {
101
+ for (const { node } of listNodes) {
102
+ for (const strategy of strategies) {
103
+ // Check if attribute is valid.
104
+ if (strategy.hasValidAttribute(node)) {
105
+ continue;
106
+ }
107
+ // Add missing default property attributes...
108
+ if (strategy.appliesToListItem(node)) {
109
+ writer.setAttribute(strategy.attributeName, strategy.defaultValue, node);
110
+ }
111
+ // ...or remove invalid property attributes.
112
+ else {
113
+ writer.removeAttribute(strategy.attributeName, node);
114
+ }
115
+ evt.return = true;
116
+ }
117
+ }
118
+ });
119
+ // Make sure that all items in a single list (items at the same level & listType) have the same properties.
120
+ documentListEditing.on('postFixer', (evt, { listNodes, writer }) => {
121
+ for (const { node, previousNodeInList } of listNodes) {
122
+ // This is a first item of a nested list.
123
+ if (!previousNodeInList) {
124
+ continue;
125
+ }
126
+ // This is a first block of a list of a different type.
127
+ if (previousNodeInList.getAttribute('listType') != node.getAttribute('listType')) {
128
+ continue;
129
+ }
130
+ // Copy properties from the previous one.
131
+ for (const strategy of strategies) {
132
+ const { attributeName } = strategy;
133
+ if (!strategy.appliesToListItem(node)) {
134
+ continue;
135
+ }
136
+ const value = previousNodeInList.getAttribute(attributeName);
137
+ if (node.getAttribute(attributeName) != value) {
138
+ writer.setAttribute(attributeName, value, node);
139
+ evt.return = true;
140
+ }
141
+ }
142
+ }
143
+ });
144
+ }
145
+ }
146
+ /**
147
+ * Creates an array of strategies for dealing with enabled listItem attributes.
148
+ */
149
+ function createAttributeStrategies(enabledProperties) {
150
+ const strategies = [];
151
+ if (enabledProperties.styles) {
152
+ const useAttribute = typeof enabledProperties.styles == 'object' && enabledProperties.styles.useAttribute;
153
+ strategies.push({
154
+ attributeName: 'listStyle',
155
+ defaultValue: DEFAULT_LIST_TYPE,
156
+ viewConsumables: { styles: 'list-style-type' },
157
+ addCommand(editor) {
158
+ let supportedTypes = getAllSupportedStyleTypes();
159
+ if (useAttribute) {
160
+ supportedTypes = supportedTypes.filter(styleType => !!getTypeAttributeFromListStyleType(styleType));
161
+ }
162
+ editor.commands.add('listStyle', new DocumentListStyleCommand(editor, DEFAULT_LIST_TYPE, supportedTypes));
163
+ },
164
+ appliesToListItem(item) {
165
+ return item.getAttribute('listType') == 'numbered' || item.getAttribute('listType') == 'bulleted';
166
+ },
167
+ hasValidAttribute(item) {
168
+ if (!this.appliesToListItem(item)) {
169
+ return !item.hasAttribute('listStyle');
170
+ }
171
+ if (!item.hasAttribute('listStyle')) {
172
+ return false;
173
+ }
174
+ const value = item.getAttribute('listStyle');
175
+ if (value == DEFAULT_LIST_TYPE) {
176
+ return true;
177
+ }
178
+ return getListTypeFromListStyleType(value) == item.getAttribute('listType');
179
+ },
180
+ setAttributeOnDowncast(writer, listStyle, element) {
181
+ if (listStyle && listStyle !== DEFAULT_LIST_TYPE) {
182
+ if (useAttribute) {
183
+ const value = getTypeAttributeFromListStyleType(listStyle);
184
+ if (value) {
185
+ writer.setAttribute('type', value, element);
186
+ return;
187
+ }
188
+ }
189
+ else {
190
+ writer.setStyle('list-style-type', listStyle, element);
191
+ return;
192
+ }
193
+ }
194
+ writer.removeStyle('list-style-type', element);
195
+ writer.removeAttribute('type', element);
196
+ },
197
+ getAttributeOnUpcast(listParent) {
198
+ const style = listParent.getStyle('list-style-type');
199
+ if (style) {
200
+ return style;
201
+ }
202
+ const attribute = listParent.getAttribute('type');
203
+ if (attribute) {
204
+ return getListStyleTypeFromTypeAttribute(attribute);
205
+ }
206
+ return DEFAULT_LIST_TYPE;
207
+ }
208
+ });
209
+ }
210
+ if (enabledProperties.reversed) {
211
+ strategies.push({
212
+ attributeName: 'listReversed',
213
+ defaultValue: false,
214
+ viewConsumables: { attributes: 'reversed' },
215
+ addCommand(editor) {
216
+ editor.commands.add('listReversed', new DocumentListReversedCommand(editor));
217
+ },
218
+ appliesToListItem(item) {
219
+ return item.getAttribute('listType') == 'numbered';
220
+ },
221
+ hasValidAttribute(item) {
222
+ return this.appliesToListItem(item) == item.hasAttribute('listReversed');
223
+ },
224
+ setAttributeOnDowncast(writer, listReversed, element) {
225
+ if (listReversed) {
226
+ writer.setAttribute('reversed', 'reversed', element);
227
+ }
228
+ else {
229
+ writer.removeAttribute('reversed', element);
230
+ }
231
+ },
232
+ getAttributeOnUpcast(listParent) {
233
+ return listParent.hasAttribute('reversed');
234
+ }
235
+ });
236
+ }
237
+ if (enabledProperties.startIndex) {
238
+ strategies.push({
239
+ attributeName: 'listStart',
240
+ defaultValue: 1,
241
+ viewConsumables: { attributes: 'start' },
242
+ addCommand(editor) {
243
+ editor.commands.add('listStart', new DocumentListStartCommand(editor));
244
+ },
245
+ appliesToListItem(item) {
246
+ return item.getAttribute('listType') == 'numbered';
247
+ },
248
+ hasValidAttribute(item) {
249
+ return this.appliesToListItem(item) == item.hasAttribute('listStart');
250
+ },
251
+ setAttributeOnDowncast(writer, listStart, element) {
252
+ if (listStart == 0 || listStart > 1) {
253
+ writer.setAttribute('start', listStart, element);
254
+ }
255
+ else {
256
+ writer.removeAttribute('start', element);
257
+ }
258
+ },
259
+ getAttributeOnUpcast(listParent) {
260
+ const startAttributeValue = listParent.getAttribute('start');
261
+ return startAttributeValue >= 0 ? startAttributeValue : 1;
262
+ }
263
+ });
264
+ }
265
+ return strategies;
266
+ }
@@ -1,33 +1,33 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * @module list/documentlistproperties/documentlistpropertiesutils
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- /**
10
- * A set of helpers related to document lists.
11
- */
12
- export default class DocumentListPropertiesUtils extends Plugin {
13
- /**
14
- * @inheritDoc
15
- */
16
- static get pluginName(): "DocumentListPropertiesUtils";
17
- /**
18
- * Gets all the style types supported by given list type.
19
- */
20
- getAllSupportedStyleTypes(): Array<string>;
21
- /**
22
- * Checks whether the given list-style-type is supported by numbered or bulleted list.
23
- */
24
- getListTypeFromListStyleType(listStyleType: string): 'bulleted' | 'numbered' | null;
25
- /**
26
- * Converts `type` attribute of `<ul>` or `<ol>` elements to `list-style-type` equivalent.
27
- */
28
- getListStyleTypeFromTypeAttribute(value: string): string | null;
29
- /**
30
- * Converts `list-style-type` style to `type` attribute of `<ul>` or `<ol>` elements.
31
- */
32
- getTypeAttributeFromListStyleType(value: string): string | null;
33
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * @module list/documentlistproperties/documentlistpropertiesutils
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ /**
10
+ * A set of helpers related to document lists.
11
+ */
12
+ export default class DocumentListPropertiesUtils extends Plugin {
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static get pluginName(): "DocumentListPropertiesUtils";
17
+ /**
18
+ * Gets all the style types supported by given list type.
19
+ */
20
+ getAllSupportedStyleTypes(): Array<string>;
21
+ /**
22
+ * Checks whether the given list-style-type is supported by numbered or bulleted list.
23
+ */
24
+ getListTypeFromListStyleType(listStyleType: string): 'bulleted' | 'numbered' | null;
25
+ /**
26
+ * Converts `type` attribute of `<ul>` or `<ol>` elements to `list-style-type` equivalent.
27
+ */
28
+ getListStyleTypeFromTypeAttribute(value: string): string | null;
29
+ /**
30
+ * Converts `list-style-type` style to `type` attribute of `<ul>` or `<ol>` elements.
31
+ */
32
+ getTypeAttributeFromListStyleType(value: string): string | null;
33
+ }