@ckeditor/ckeditor5-list 39.0.1 → 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 (173) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/LICENSE.md +1 -1
  3. package/README.md +4 -4
  4. package/build/list.js +1 -1
  5. package/build/list.js.map +1 -0
  6. package/build/translations/fi.js +1 -1
  7. package/build/translations/pt-br.js +1 -1
  8. package/ckeditor5-metadata.json +44 -0
  9. package/lang/translations/ar.po +1 -0
  10. package/lang/translations/ast.po +1 -0
  11. package/lang/translations/az.po +1 -0
  12. package/lang/translations/bg.po +1 -0
  13. package/lang/translations/bn.po +1 -0
  14. package/lang/translations/ca.po +1 -0
  15. package/lang/translations/cs.po +1 -0
  16. package/lang/translations/da.po +1 -0
  17. package/lang/translations/de-ch.po +1 -0
  18. package/lang/translations/de.po +1 -0
  19. package/lang/translations/el.po +1 -0
  20. package/lang/translations/en-au.po +1 -0
  21. package/lang/translations/en-gb.po +1 -0
  22. package/lang/translations/en.po +1 -0
  23. package/lang/translations/eo.po +1 -0
  24. package/lang/translations/es.po +1 -0
  25. package/lang/translations/et.po +1 -0
  26. package/lang/translations/eu.po +1 -0
  27. package/lang/translations/fa.po +1 -0
  28. package/lang/translations/fi.po +2 -1
  29. package/lang/translations/fr.po +1 -0
  30. package/lang/translations/gl.po +1 -0
  31. package/lang/translations/he.po +1 -0
  32. package/lang/translations/hi.po +1 -0
  33. package/lang/translations/hr.po +1 -0
  34. package/lang/translations/hu.po +1 -0
  35. package/lang/translations/id.po +1 -0
  36. package/lang/translations/it.po +1 -0
  37. package/lang/translations/ja.po +1 -0
  38. package/lang/translations/jv.po +1 -0
  39. package/lang/translations/km.po +1 -0
  40. package/lang/translations/kn.po +1 -0
  41. package/lang/translations/ko.po +1 -0
  42. package/lang/translations/ku.po +1 -0
  43. package/lang/translations/lt.po +1 -0
  44. package/lang/translations/lv.po +1 -0
  45. package/lang/translations/ms.po +1 -0
  46. package/lang/translations/nb.po +1 -0
  47. package/lang/translations/ne.po +1 -0
  48. package/lang/translations/nl.po +1 -0
  49. package/lang/translations/no.po +1 -0
  50. package/lang/translations/pl.po +1 -0
  51. package/lang/translations/pt-br.po +11 -10
  52. package/lang/translations/pt.po +1 -0
  53. package/lang/translations/ro.po +1 -0
  54. package/lang/translations/ru.po +1 -0
  55. package/lang/translations/si.po +1 -0
  56. package/lang/translations/sk.po +1 -0
  57. package/lang/translations/sq.po +1 -0
  58. package/lang/translations/sr-latn.po +1 -0
  59. package/lang/translations/sr.po +1 -0
  60. package/lang/translations/sv.po +1 -0
  61. package/lang/translations/th.po +1 -0
  62. package/lang/translations/tk.po +1 -0
  63. package/lang/translations/tr.po +1 -0
  64. package/lang/translations/tt.po +1 -0
  65. package/lang/translations/ug.po +1 -0
  66. package/lang/translations/uk.po +1 -0
  67. package/lang/translations/ur.po +1 -0
  68. package/lang/translations/uz.po +1 -0
  69. package/lang/translations/vi.po +1 -0
  70. package/lang/translations/zh-cn.po +1 -0
  71. package/lang/translations/zh.po +1 -0
  72. package/package.json +3 -7
  73. package/src/augmentation.d.ts +52 -50
  74. package/src/augmentation.js +5 -5
  75. package/src/documentlist/adjacentlistssupport.d.ts +15 -15
  76. package/src/documentlist/adjacentlistssupport.js +81 -81
  77. package/src/documentlist/converters.d.ts +65 -63
  78. package/src/documentlist/converters.js +441 -354
  79. package/src/documentlist/documentlistcommand.d.ts +80 -80
  80. package/src/documentlist/documentlistcommand.js +150 -145
  81. package/src/documentlist/documentlistediting.d.ts +212 -154
  82. package/src/documentlist/documentlistediting.js +645 -565
  83. package/src/documentlist/documentlistindentcommand.d.ts +62 -62
  84. package/src/documentlist/documentlistindentcommand.js +129 -129
  85. package/src/documentlist/documentlistmergecommand.d.ts +76 -76
  86. package/src/documentlist/documentlistmergecommand.js +174 -174
  87. package/src/documentlist/documentlistsplitcommand.d.ts +67 -67
  88. package/src/documentlist/documentlistsplitcommand.js +70 -70
  89. package/src/documentlist/documentlistutils.d.ts +46 -46
  90. package/src/documentlist/documentlistutils.js +50 -50
  91. package/src/documentlist/utils/listwalker.d.ts +145 -141
  92. package/src/documentlist/utils/listwalker.js +182 -162
  93. package/src/documentlist/utils/model.d.ts +202 -193
  94. package/src/documentlist/utils/model.js +455 -435
  95. package/src/documentlist/utils/postfixers.d.ts +37 -37
  96. package/src/documentlist/utils/postfixers.js +126 -118
  97. package/src/documentlist/utils/view.d.ts +81 -81
  98. package/src/documentlist/utils/view.js +117 -117
  99. package/src/documentlist.d.ts +26 -26
  100. package/src/documentlist.js +30 -30
  101. package/src/documentlistproperties/converters.d.ts +19 -19
  102. package/src/documentlistproperties/converters.js +43 -43
  103. package/src/documentlistproperties/documentlistpropertiesediting.d.ts +88 -88
  104. package/src/documentlistproperties/documentlistpropertiesediting.js +266 -289
  105. package/src/documentlistproperties/documentlistpropertiesutils.d.ts +33 -33
  106. package/src/documentlistproperties/documentlistpropertiesutils.js +44 -44
  107. package/src/documentlistproperties/documentlistreversedcommand.d.ts +36 -36
  108. package/src/documentlistproperties/documentlistreversedcommand.js +55 -55
  109. package/src/documentlistproperties/documentliststartcommand.d.ts +38 -38
  110. package/src/documentlistproperties/documentliststartcommand.js +57 -57
  111. package/src/documentlistproperties/documentliststylecommand.d.ts +72 -72
  112. package/src/documentlistproperties/documentliststylecommand.js +113 -113
  113. package/src/documentlistproperties/utils/style.d.ts +20 -20
  114. package/src/documentlistproperties/utils/style.js +54 -54
  115. package/src/documentlistproperties.d.ts +27 -27
  116. package/src/documentlistproperties.js +31 -31
  117. package/src/index.d.ts +43 -40
  118. package/src/index.js +29 -27
  119. package/src/list/converters.d.ts +196 -196
  120. package/src/list/converters.js +905 -905
  121. package/src/list/indentcommand.d.ts +37 -37
  122. package/src/list/indentcommand.js +107 -107
  123. package/src/list/listcommand.d.ts +55 -55
  124. package/src/list/listcommand.js +274 -274
  125. package/src/list/listediting.d.ts +32 -32
  126. package/src/list/listediting.js +161 -161
  127. package/src/list/listui.d.ts +19 -19
  128. package/src/list/listui.js +32 -32
  129. package/src/list/listutils.d.ts +41 -41
  130. package/src/list/listutils.js +46 -46
  131. package/src/list/utils.d.ts +112 -112
  132. package/src/list/utils.js +374 -374
  133. package/src/list.d.ts +26 -26
  134. package/src/list.js +30 -30
  135. package/src/listconfig.d.ts +132 -122
  136. package/src/listconfig.js +5 -5
  137. package/src/listproperties/listpropertiesediting.d.ts +72 -72
  138. package/src/listproperties/listpropertiesediting.js +696 -696
  139. package/src/listproperties/listpropertiesui.d.ts +23 -23
  140. package/src/listproperties/listpropertiesui.js +277 -277
  141. package/src/listproperties/listreversedcommand.d.ts +38 -38
  142. package/src/listproperties/listreversedcommand.js +52 -52
  143. package/src/listproperties/liststartcommand.d.ts +37 -37
  144. package/src/listproperties/liststartcommand.js +51 -51
  145. package/src/listproperties/liststylecommand.d.ts +67 -67
  146. package/src/listproperties/liststylecommand.js +99 -99
  147. package/src/listproperties/ui/collapsibleview.d.ts +63 -63
  148. package/src/listproperties/ui/collapsibleview.js +89 -89
  149. package/src/listproperties/ui/listpropertiesview.d.ts +157 -157
  150. package/src/listproperties/ui/listpropertiesview.js +299 -299
  151. package/src/listproperties.d.ts +26 -26
  152. package/src/listproperties.js +30 -30
  153. package/src/liststyle.d.ts +28 -28
  154. package/src/liststyle.js +36 -36
  155. package/src/tododocumentlist/checktododocumentlistcommand.d.ts +49 -0
  156. package/src/tododocumentlist/checktododocumentlistcommand.js +82 -0
  157. package/src/tododocumentlist/todocheckboxchangeobserver.d.ts +41 -0
  158. package/src/tododocumentlist/todocheckboxchangeobserver.js +37 -0
  159. package/src/tododocumentlist/tododocumentlistediting.d.ts +38 -0
  160. package/src/tododocumentlist/tododocumentlistediting.js +399 -0
  161. package/src/tododocumentlist.d.ts +27 -0
  162. package/src/tododocumentlist.js +31 -0
  163. package/src/todolist/checktodolistcommand.d.ts +52 -52
  164. package/src/todolist/checktodolistcommand.js +76 -76
  165. package/src/todolist/todolistconverters.d.ts +82 -82
  166. package/src/todolist/todolistconverters.js +260 -260
  167. package/src/todolist/todolistediting.d.ts +39 -39
  168. package/src/todolist/todolistediting.js +161 -161
  169. package/src/todolist/todolistui.d.ts +19 -19
  170. package/src/todolist/todolistui.js +29 -29
  171. package/src/todolist.d.ts +27 -27
  172. package/src/todolist.js +31 -31
  173. 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
+ }