@ckeditor/ckeditor5-list 40.2.0 → 41.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 (196) hide show
  1. package/CHANGELOG.md +25 -25
  2. package/LICENSE.md +1 -1
  3. package/build/list.js +2 -2
  4. package/build/translations/ug.js +1 -1
  5. package/ckeditor5-metadata.json +34 -34
  6. package/lang/translations/ar.po +1 -1
  7. package/lang/translations/ast.po +1 -1
  8. package/lang/translations/az.po +1 -1
  9. package/lang/translations/bg.po +1 -1
  10. package/lang/translations/bn.po +1 -1
  11. package/lang/translations/ca.po +1 -1
  12. package/lang/translations/cs.po +1 -1
  13. package/lang/translations/da.po +1 -1
  14. package/lang/translations/de-ch.po +1 -1
  15. package/lang/translations/de.po +1 -1
  16. package/lang/translations/el.po +1 -1
  17. package/lang/translations/en-au.po +1 -1
  18. package/lang/translations/en-gb.po +1 -1
  19. package/lang/translations/en.po +1 -1
  20. package/lang/translations/eo.po +1 -1
  21. package/lang/translations/es.po +1 -1
  22. package/lang/translations/et.po +1 -1
  23. package/lang/translations/eu.po +1 -1
  24. package/lang/translations/fa.po +1 -1
  25. package/lang/translations/fi.po +1 -1
  26. package/lang/translations/fr.po +1 -1
  27. package/lang/translations/gl.po +1 -1
  28. package/lang/translations/he.po +1 -1
  29. package/lang/translations/hi.po +1 -1
  30. package/lang/translations/hr.po +1 -1
  31. package/lang/translations/hu.po +1 -1
  32. package/lang/translations/id.po +1 -1
  33. package/lang/translations/it.po +1 -1
  34. package/lang/translations/ja.po +1 -1
  35. package/lang/translations/jv.po +1 -1
  36. package/lang/translations/km.po +1 -1
  37. package/lang/translations/kn.po +1 -1
  38. package/lang/translations/ko.po +1 -1
  39. package/lang/translations/ku.po +1 -1
  40. package/lang/translations/lt.po +1 -1
  41. package/lang/translations/lv.po +1 -1
  42. package/lang/translations/ms.po +1 -1
  43. package/lang/translations/nb.po +1 -1
  44. package/lang/translations/ne.po +1 -1
  45. package/lang/translations/nl.po +1 -1
  46. package/lang/translations/no.po +1 -1
  47. package/lang/translations/pl.po +1 -1
  48. package/lang/translations/pt-br.po +1 -1
  49. package/lang/translations/pt.po +1 -1
  50. package/lang/translations/ro.po +1 -1
  51. package/lang/translations/ru.po +1 -1
  52. package/lang/translations/si.po +1 -1
  53. package/lang/translations/sk.po +1 -1
  54. package/lang/translations/sq.po +1 -1
  55. package/lang/translations/sr-latn.po +1 -1
  56. package/lang/translations/sr.po +1 -1
  57. package/lang/translations/sv.po +1 -1
  58. package/lang/translations/th.po +1 -1
  59. package/lang/translations/tk.po +1 -1
  60. package/lang/translations/tr.po +1 -1
  61. package/lang/translations/tt.po +1 -1
  62. package/lang/translations/ug.po +8 -8
  63. package/lang/translations/uk.po +1 -1
  64. package/lang/translations/ur.po +1 -1
  65. package/lang/translations/uz.po +1 -1
  66. package/lang/translations/vi.po +1 -1
  67. package/lang/translations/zh-cn.po +1 -1
  68. package/lang/translations/zh.po +1 -1
  69. package/package.json +3 -2
  70. package/src/augmentation.d.ts +29 -28
  71. package/src/augmentation.js +1 -1
  72. package/src/documentlist.d.ts +9 -7
  73. package/src/documentlist.js +18 -7
  74. package/src/documentlistproperties.d.ts +9 -8
  75. package/src/documentlistproperties.js +18 -8
  76. package/src/index.d.ts +39 -37
  77. package/src/index.js +32 -23
  78. package/src/legacylist/legacyconverters.d.ts +196 -0
  79. package/src/legacylist/legacyconverters.js +905 -0
  80. package/src/{list/indentcommand.d.ts → legacylist/legacyindentcommand.d.ts} +4 -4
  81. package/src/{list/indentcommand.js → legacylist/legacyindentcommand.js} +5 -5
  82. package/src/{documentlist/documentlistcommand.d.ts → legacylist/legacylistcommand.d.ts} +5 -30
  83. package/src/legacylist/legacylistcommand.js +274 -0
  84. package/src/legacylist/legacylistediting.d.ts +32 -0
  85. package/src/legacylist/legacylistediting.js +161 -0
  86. package/src/legacylist/legacylistutils.d.ts +41 -0
  87. package/src/legacylist/legacylistutils.js +46 -0
  88. package/src/legacylist/legacyutils.d.ts +101 -0
  89. package/src/legacylist/legacyutils.js +347 -0
  90. package/src/legacylist.d.ts +26 -0
  91. package/src/legacylist.js +30 -0
  92. package/src/legacylistproperties/legacylistpropertiesediting.d.ts +72 -0
  93. package/src/legacylistproperties/legacylistpropertiesediting.js +696 -0
  94. package/src/legacylistproperties/legacylistreversedcommand.d.ts +38 -0
  95. package/src/legacylistproperties/legacylistreversedcommand.js +52 -0
  96. package/src/{documentlistproperties/documentliststartcommand.d.ts → legacylistproperties/legacyliststartcommand.d.ts} +6 -7
  97. package/src/legacylistproperties/legacyliststartcommand.js +51 -0
  98. package/src/{documentlistproperties/documentliststylecommand.d.ts → legacylistproperties/legacyliststylecommand.d.ts} +14 -19
  99. package/src/{documentlistproperties/documentliststylecommand.js → legacylistproperties/legacyliststylecommand.js} +22 -36
  100. package/src/legacylistproperties.d.ts +27 -0
  101. package/src/legacylistproperties.js +31 -0
  102. package/src/{tododocumentlist/checktododocumentlistcommand.d.ts → legacytodolist/legacychecktodolistcommand.d.ts} +17 -14
  103. package/src/{tododocumentlist/checktododocumentlistcommand.js → legacytodolist/legacychecktodolistcommand.js} +34 -40
  104. package/src/{todolist/todolistconverters.d.ts → legacytodolist/legacytodolistconverters.d.ts} +9 -8
  105. package/src/{todolist/todolistconverters.js → legacytodolist/legacytodolistconverters.js} +6 -5
  106. package/src/{tododocumentlist/tododocumentlistediting.d.ts → legacytodolist/legacytodolistediting.d.ts} +9 -8
  107. package/src/legacytodolist/legacytodolistediting.js +161 -0
  108. package/src/legacytodolist.d.ts +27 -0
  109. package/src/legacytodolist.js +31 -0
  110. package/src/{documentlist → list}/adjacentlistssupport.d.ts +2 -2
  111. package/src/{documentlist → list}/adjacentlistssupport.js +9 -9
  112. package/src/list/converters.d.ts +41 -172
  113. package/src/list/converters.js +357 -821
  114. package/src/list/listcommand.d.ts +28 -3
  115. package/src/list/listcommand.js +81 -205
  116. package/src/list/listediting.d.ts +189 -9
  117. package/src/list/listediting.js +592 -107
  118. package/src/{documentlist/documentlistindentcommand.d.ts → list/listindentcommand.d.ts} +10 -10
  119. package/src/{documentlist/documentlistindentcommand.js → list/listindentcommand.js} +7 -7
  120. package/src/{documentlist/documentlistmergecommand.d.ts → list/listmergecommand.d.ts} +10 -10
  121. package/src/{documentlist/documentlistmergecommand.js → list/listmergecommand.js} +7 -7
  122. package/src/{documentlist/documentlistsplitcommand.d.ts → list/listsplitcommand.d.ts} +10 -10
  123. package/src/{documentlist/documentlistsplitcommand.js → list/listsplitcommand.js} +5 -5
  124. package/src/list/listui.d.ts +2 -2
  125. package/src/list/listui.js +5 -7
  126. package/src/list/listutils.d.ts +22 -17
  127. package/src/list/listutils.js +24 -20
  128. package/src/{documentlist → list}/utils/listwalker.d.ts +5 -5
  129. package/src/{documentlist → list}/utils/listwalker.js +4 -4
  130. package/src/{documentlist → list}/utils/model.d.ts +4 -4
  131. package/src/{documentlist → list}/utils/model.js +3 -3
  132. package/src/{documentlist → list}/utils/postfixers.d.ts +5 -5
  133. package/src/{documentlist → list}/utils/postfixers.js +3 -3
  134. package/src/{documentlist → list}/utils/view.d.ts +3 -3
  135. package/src/{documentlist → list}/utils/view.js +1 -1
  136. package/src/list/utils.d.ts +2 -96
  137. package/src/list/utils.js +2 -342
  138. package/src/list.d.ts +6 -6
  139. package/src/list.js +6 -6
  140. package/src/listconfig.d.ts +10 -10
  141. package/src/listconfig.js +1 -1
  142. package/src/{documentlistproperties → listproperties}/converters.d.ts +5 -5
  143. package/src/{documentlistproperties → listproperties}/converters.js +1 -1
  144. package/src/listproperties/listpropertiesediting.d.ts +56 -40
  145. package/src/listproperties/listpropertiesediting.js +145 -575
  146. package/src/listproperties/listpropertiesui.d.ts +2 -2
  147. package/src/listproperties/listpropertiesui.js +6 -8
  148. package/src/{documentlistproperties/documentlistpropertiesutils.d.ts → listproperties/listpropertiesutils.d.ts} +5 -5
  149. package/src/{documentlistproperties/documentlistpropertiesutils.js → listproperties/listpropertiesutils.js} +6 -6
  150. package/src/listproperties/listreversedcommand.d.ts +4 -6
  151. package/src/listproperties/listreversedcommand.js +17 -14
  152. package/src/listproperties/liststartcommand.d.ts +4 -3
  153. package/src/listproperties/liststartcommand.js +17 -11
  154. package/src/listproperties/liststylecommand.d.ts +16 -11
  155. package/src/listproperties/liststylecommand.js +33 -19
  156. package/src/listproperties/ui/listpropertiesview.d.ts +5 -5
  157. package/src/listproperties/ui/listpropertiesview.js +3 -3
  158. package/src/{documentlistproperties → listproperties}/utils/style.d.ts +1 -1
  159. package/src/{documentlistproperties → listproperties}/utils/style.js +2 -2
  160. package/src/listproperties.d.ts +6 -5
  161. package/src/listproperties.js +6 -5
  162. package/src/tododocumentlist.d.ts +9 -8
  163. package/src/tododocumentlist.js +18 -8
  164. package/src/todolist/checktodolistcommand.d.ts +11 -14
  165. package/src/todolist/checktodolistcommand.js +37 -31
  166. package/src/{tododocumentlist → todolist}/todocheckboxchangeobserver.d.ts +6 -6
  167. package/src/{tododocumentlist → todolist}/todocheckboxchangeobserver.js +3 -3
  168. package/src/todolist/todolistediting.d.ts +5 -6
  169. package/src/todolist/todolistediting.js +314 -76
  170. package/src/todolist/todolistui.d.ts +2 -2
  171. package/src/todolist/todolistui.js +4 -5
  172. package/src/todolist.d.ts +6 -6
  173. package/src/todolist.js +6 -6
  174. package/theme/documentlist.css +1 -1
  175. package/theme/list.css +1 -1
  176. package/theme/listproperties.css +1 -1
  177. package/theme/liststyles.css +1 -1
  178. package/theme/todolist.css +1 -1
  179. package/src/documentlist/converters.d.ts +0 -65
  180. package/src/documentlist/converters.js +0 -441
  181. package/src/documentlist/documentlistcommand.js +0 -150
  182. package/src/documentlist/documentlistediting.d.ts +0 -212
  183. package/src/documentlist/documentlistediting.js +0 -646
  184. package/src/documentlist/documentlistutils.d.ts +0 -46
  185. package/src/documentlist/documentlistutils.js +0 -50
  186. package/src/documentlistproperties/documentlistpropertiesediting.d.ts +0 -88
  187. package/src/documentlistproperties/documentlistpropertiesediting.js +0 -266
  188. package/src/documentlistproperties/documentlistreversedcommand.d.ts +0 -36
  189. package/src/documentlistproperties/documentlistreversedcommand.js +0 -55
  190. package/src/documentlistproperties/documentliststartcommand.js +0 -57
  191. package/src/liststyle.d.ts +0 -28
  192. package/src/liststyle.js +0 -36
  193. package/src/tododocumentlist/tododocumentlistediting.js +0 -399
  194. package/theme/icons/bulletedlist.svg +0 -1
  195. package/theme/icons/numberedlist.svg +0 -1
  196. package/theme/icons/todolist.svg +0 -1
package/src/list/utils.js CHANGED
@@ -1,191 +1,8 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, 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
- import { TreeWalker, getFillerOffset } from 'ckeditor5/src/engine';
6
- import { ButtonView } from 'ckeditor5/src/ui';
7
- /**
8
- * Creates a list item {@link module:engine/view/containerelement~ContainerElement}.
9
- *
10
- * @param writer The writer instance.
11
- */
12
- export function createViewListItemElement(writer) {
13
- const viewItem = writer.createContainerElement('li');
14
- viewItem.getFillerOffset = getListItemFillerOffset;
15
- return viewItem;
16
- }
17
- /**
18
- * Helper function that creates a `<ul><li></li></ul>` or (`<ol>`) structure out of the given `modelItem` model `listItem` element.
19
- * Then, it binds the created view list item (`<li>`) with the model `listItem` element.
20
- * The function then returns the created view list item (`<li>`).
21
- *
22
- * @param modelItem Model list item.
23
- * @param conversionApi Conversion interface.
24
- * @returns View list element.
25
- */
26
- export function generateLiInUl(modelItem, conversionApi) {
27
- const mapper = conversionApi.mapper;
28
- const viewWriter = conversionApi.writer;
29
- const listType = modelItem.getAttribute('listType') == 'numbered' ? 'ol' : 'ul';
30
- const viewItem = createViewListItemElement(viewWriter);
31
- const viewList = viewWriter.createContainerElement(listType, null);
32
- viewWriter.insert(viewWriter.createPositionAt(viewList, 0), viewItem);
33
- mapper.bindElements(modelItem, viewItem);
34
- return viewItem;
35
- }
36
- /**
37
- * Helper function that inserts a view list at a correct place and merges it with its siblings.
38
- * It takes a model list item element (`modelItem`) and a corresponding view list item element (`injectedItem`). The view list item
39
- * should be in a view list element (`<ul>` or `<ol>`) and should be its only child.
40
- * See comments below to better understand the algorithm.
41
- *
42
- * @param modelItem Model list item.
43
- * @param injectedItem
44
- * @param conversionApi Conversion interface.
45
- * @param model The model instance.
46
- */
47
- export function injectViewList(modelItem, injectedItem, conversionApi, model) {
48
- const injectedList = injectedItem.parent;
49
- const mapper = conversionApi.mapper;
50
- const viewWriter = conversionApi.writer;
51
- // The position where the view list will be inserted.
52
- let insertPosition = mapper.toViewPosition(model.createPositionBefore(modelItem));
53
- // 1. Find the previous list item that has the same or smaller indent. Basically we are looking for the first model item
54
- // that is a "parent" or "sibling" of the injected model item.
55
- // If there is no such list item, it means that the injected list item is the first item in "its list".
56
- const refItem = getSiblingListItem(modelItem.previousSibling, {
57
- sameIndent: true,
58
- smallerIndent: true,
59
- listIndent: modelItem.getAttribute('listIndent')
60
- });
61
- const prevItem = modelItem.previousSibling;
62
- if (refItem && refItem.getAttribute('listIndent') == modelItem.getAttribute('listIndent')) {
63
- // There is a list item with the same indent - we found the same-level sibling.
64
- // Break the list after it. The inserted view item will be added in the broken space.
65
- const viewItem = mapper.toViewElement(refItem);
66
- insertPosition = viewWriter.breakContainer(viewWriter.createPositionAfter(viewItem));
67
- }
68
- else {
69
- // There is no list item with the same indent. Check the previous model item.
70
- if (prevItem && prevItem.name == 'listItem') {
71
- // If it is a list item, it has to have a lower indent.
72
- // It means that the inserted item should be added to it as its nested item.
73
- insertPosition = mapper.toViewPosition(model.createPositionAt(prevItem, 'end'));
74
- // There could be some not mapped elements (eg. span in to-do list) but we need to insert
75
- // a nested list directly inside the li element.
76
- const mappedViewAncestor = mapper.findMappedViewAncestor(insertPosition);
77
- const nestedList = findNestedList(mappedViewAncestor);
78
- // If there already is some nested list, then use it's position.
79
- if (nestedList) {
80
- insertPosition = viewWriter.createPositionBefore(nestedList);
81
- }
82
- else {
83
- // Else just put new list on the end of list item content.
84
- insertPosition = viewWriter.createPositionAt(mappedViewAncestor, 'end');
85
- }
86
- }
87
- else {
88
- // The previous item is not a list item (or does not exist at all).
89
- // Just map the position and insert the view item at the mapped position.
90
- insertPosition = mapper.toViewPosition(model.createPositionBefore(modelItem));
91
- }
92
- }
93
- insertPosition = positionAfterUiElements(insertPosition);
94
- // Insert the view item.
95
- viewWriter.insert(insertPosition, injectedList);
96
- // 2. Handle possible children of the injected model item.
97
- if (prevItem && prevItem.name == 'listItem') {
98
- const prevView = mapper.toViewElement(prevItem);
99
- const walkerBoundaries = viewWriter.createRange(viewWriter.createPositionAt(prevView, 0), insertPosition);
100
- const walker = walkerBoundaries.getWalker({ ignoreElementEnd: true });
101
- for (const value of walker) {
102
- if (value.item.is('element', 'li')) {
103
- const breakPosition = viewWriter.breakContainer(viewWriter.createPositionBefore(value.item));
104
- const viewList = value.item.parent;
105
- const targetPosition = viewWriter.createPositionAt(injectedItem, 'end');
106
- mergeViewLists(viewWriter, targetPosition.nodeBefore, targetPosition.nodeAfter);
107
- viewWriter.move(viewWriter.createRangeOn(viewList), targetPosition);
108
- // This is bad, but those lists will be removed soon anyway.
109
- walker._position = breakPosition;
110
- }
111
- }
112
- }
113
- else {
114
- const nextViewList = injectedList.nextSibling;
115
- if (nextViewList && (nextViewList.is('element', 'ul') || nextViewList.is('element', 'ol'))) {
116
- let lastSubChild = null;
117
- for (const child of nextViewList.getChildren()) {
118
- const modelChild = mapper.toModelElement(child);
119
- if (modelChild &&
120
- modelChild.getAttribute('listIndent') > modelItem.getAttribute('listIndent')) {
121
- lastSubChild = child;
122
- }
123
- else {
124
- break;
125
- }
126
- }
127
- if (lastSubChild) {
128
- viewWriter.breakContainer(viewWriter.createPositionAfter(lastSubChild));
129
- viewWriter.move(viewWriter.createRangeOn(lastSubChild.parent), viewWriter.createPositionAt(injectedItem, 'end'));
130
- }
131
- }
132
- }
133
- // Merge the inserted view list with its possible neighbor lists.
134
- mergeViewLists(viewWriter, injectedList, injectedList.nextSibling);
135
- mergeViewLists(viewWriter, injectedList.previousSibling, injectedList);
136
- }
137
- export function mergeViewLists(viewWriter, firstList, secondList) {
138
- // Check if two lists are going to be merged.
139
- if (!firstList || !secondList || (firstList.name != 'ul' && firstList.name != 'ol')) {
140
- return null;
141
- }
142
- // Both parameters are list elements, so compare types now.
143
- if (firstList.name != secondList.name || firstList.getAttribute('class') !== secondList.getAttribute('class')) {
144
- return null;
145
- }
146
- return viewWriter.mergeContainers(viewWriter.createPositionAfter(firstList));
147
- }
148
- /**
149
- * Helper function that for a given `view.Position`, returns a `view.Position` that is after all `view.UIElement`s that
150
- * are after the given position.
151
- *
152
- * For example:
153
- * `<container:p>foo^<ui:span></ui:span><ui:span></ui:span>bar</container:p>`
154
- * For position ^, the position before "bar" will be returned.
155
- *
156
- */
157
- export function positionAfterUiElements(viewPosition) {
158
- return viewPosition.getLastMatchingPosition(value => value.item.is('uiElement'));
159
- }
160
- /**
161
- * Helper function that searches for a previous list item sibling of a given model item that meets the given criteria
162
- * passed by the options object.
163
- *
164
- * @param options Search criteria.
165
- * @param options.sameIndent Whether the sought sibling should have the same indentation.
166
- * @param options.smallerIndent Whether the sought sibling should have a smaller indentation.
167
- * @param options.listIndent The reference indentation.
168
- * @param options.direction Walking direction.
169
- */
170
- export function getSiblingListItem(modelItem, options) {
171
- const sameIndent = !!options.sameIndent;
172
- const smallerIndent = !!options.smallerIndent;
173
- const indent = options.listIndent;
174
- let item = modelItem;
175
- while (item && item.name == 'listItem') {
176
- const itemIndent = item.getAttribute('listIndent');
177
- if ((sameIndent && indent == itemIndent) || (smallerIndent && indent > itemIndent)) {
178
- return item;
179
- }
180
- if (options.direction === 'forward') {
181
- item = item.nextSibling;
182
- }
183
- else {
184
- item = item.previousSibling;
185
- }
186
- }
187
- return null;
188
- }
5
+ import { ButtonView } from 'ckeditor5/src/ui.js';
189
6
  /**
190
7
  * Helper method for creating a UI button and linking it with an appropriate command.
191
8
  *
@@ -215,160 +32,3 @@ export function createUIComponent(editor, commandName, label, icon) {
215
32
  return buttonView;
216
33
  });
217
34
  }
218
- /**
219
- * Returns a first list view element that is direct child of the given view element.
220
- */
221
- export function findNestedList(viewElement) {
222
- for (const node of viewElement.getChildren()) {
223
- if (node.name == 'ul' || node.name == 'ol') {
224
- return node;
225
- }
226
- }
227
- return null;
228
- }
229
- /**
230
- * Returns an array with all `listItem` elements that represent the same list.
231
- *
232
- * It means that values of `listIndent`, `listType`, `listStyle`, `listReversed` and `listStart` for all items are equal.
233
- *
234
- * Additionally, if the `position` is inside a list item, that list item will be returned as well.
235
- *
236
- * @param position Starting position.
237
- * @param direction Walking direction.
238
- */
239
- export function getSiblingNodes(position, direction) {
240
- const items = [];
241
- const listItem = position.parent;
242
- const walkerOptions = {
243
- ignoreElementEnd: false,
244
- startPosition: position,
245
- shallow: true,
246
- direction
247
- };
248
- const limitIndent = listItem.getAttribute('listIndent');
249
- const nodes = [...new TreeWalker(walkerOptions)]
250
- .filter(value => value.item.is('element'))
251
- .map(value => value.item);
252
- for (const element of nodes) {
253
- // If found something else than `listItem`, we're out of the list scope.
254
- if (!element.is('element', 'listItem')) {
255
- break;
256
- }
257
- // If current parsed item has lower indent that element that the element that was a starting point,
258
- // it means we left a nested list. Abort searching items.
259
- //
260
- // ■ List item 1. [listIndent=0]
261
- // ○ List item 2.[] [listIndent=1], limitIndent = 1,
262
- // ○ List item 3. [listIndent=1]
263
- // ■ List item 4. [listIndent=0]
264
- //
265
- // Abort searching when leave nested list.
266
- if (element.getAttribute('listIndent') < limitIndent) {
267
- break;
268
- }
269
- // ■ List item 1.[] [listIndent=0] limitIndent = 0,
270
- // ○ List item 2. [listIndent=1]
271
- // ○ List item 3. [listIndent=1]
272
- // ■ List item 4. [listIndent=0]
273
- //
274
- // Ignore nested lists.
275
- if (element.getAttribute('listIndent') > limitIndent) {
276
- continue;
277
- }
278
- // ■ List item 1.[] [listType=bulleted]
279
- // 1. List item 2. [listType=numbered]
280
- // 2.List item 3. [listType=numbered]
281
- //
282
- // Abort searching when found a different kind of a list.
283
- if (element.getAttribute('listType') !== listItem.getAttribute('listType')) {
284
- break;
285
- }
286
- // ■ List item 1.[] [listType=bulleted]
287
- // ■ List item 2. [listType=bulleted]
288
- // ○ List item 3. [listType=bulleted]
289
- // ○ List item 4. [listType=bulleted]
290
- //
291
- // Abort searching when found a different list style,
292
- if (element.getAttribute('listStyle') !== listItem.getAttribute('listStyle')) {
293
- break;
294
- }
295
- // ... different direction
296
- if (element.getAttribute('listReversed') !== listItem.getAttribute('listReversed')) {
297
- break;
298
- }
299
- // ... and different start index
300
- if (element.getAttribute('listStart') !== listItem.getAttribute('listStart')) {
301
- break;
302
- }
303
- if (direction === 'backward') {
304
- items.unshift(element);
305
- }
306
- else {
307
- items.push(element);
308
- }
309
- }
310
- return items;
311
- }
312
- /**
313
- * Returns an array with all `listItem` elements in the model selection.
314
- *
315
- * It returns all the items even if only a part of the list is selected, including items that belong to nested lists.
316
- * If no list is selected, it returns an empty array.
317
- * The order of the elements is not specified.
318
- *
319
- * @internal
320
- */
321
- export function getSelectedListItems(model) {
322
- const document = model.document;
323
- // For all selected blocks find all list items that are being selected
324
- // and update the `listStyle` attribute in those lists.
325
- let listItems = [...document.selection.getSelectedBlocks()]
326
- .filter(element => element.is('element', 'listItem'))
327
- .map(element => {
328
- const position = model.change(writer => writer.createPositionAt(element, 0));
329
- return [
330
- ...getSiblingNodes(position, 'backward'),
331
- ...getSiblingNodes(position, 'forward')
332
- ];
333
- })
334
- .flat();
335
- // Since `getSelectedBlocks()` can return items that belong to the same list, and
336
- // `getSiblingNodes()` returns the entire list, we need to remove duplicated items.
337
- listItems = [...new Set(listItems)];
338
- return listItems;
339
- }
340
- const BULLETED_LIST_STYLE_TYPES = ['disc', 'circle', 'square'];
341
- // There's a lot of them (https://www.w3.org/TR/css-counter-styles-3/#typedef-counter-style).
342
- // Let's support only those that can be selected by ListPropertiesUI.
343
- const NUMBERED_LIST_STYLE_TYPES = [
344
- 'decimal',
345
- 'decimal-leading-zero',
346
- 'lower-roman',
347
- 'upper-roman',
348
- 'lower-latin',
349
- 'upper-latin'
350
- ];
351
- /**
352
- * Checks whether the given list-style-type is supported by numbered or bulleted list.
353
- */
354
- export function getListTypeFromListStyleType(listStyleType) {
355
- if (BULLETED_LIST_STYLE_TYPES.includes(listStyleType)) {
356
- return 'bulleted';
357
- }
358
- if (NUMBERED_LIST_STYLE_TYPES.includes(listStyleType)) {
359
- return 'numbered';
360
- }
361
- return null;
362
- }
363
- /**
364
- * Implementation of getFillerOffset for view list item element.
365
- *
366
- * @returns Block filler offset or `null` if block filler is not needed.
367
- */
368
- function getListItemFillerOffset() {
369
- const hasOnlyLists = !this.isEmpty && (this.getChild(0).name == 'ul' || this.getChild(0).name == 'ol');
370
- if (this.isEmpty || hasOnlyLists) {
371
- return 0;
372
- }
373
- return getFillerOffset.call(this);
374
- }
package/src/list.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, 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
5
  /**
6
6
  * @module list/list
7
7
  */
8
- import ListEditing from './list/listediting';
9
- import ListUI from './list/listui';
10
- import { Plugin } from 'ckeditor5/src/core';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import ListEditing from './list/listediting.js';
10
+ import ListUI from './list/listui.js';
11
11
  /**
12
12
  * The list feature.
13
13
  *
14
- * This is a "glue" plugin that loads the {@link module:list/list/listediting~ListEditing list editing feature}
15
- * and {@link module:list/list/listui~ListUI list UI feature}.
14
+ * This is a "glue" plugin that loads the {@link module:list/list/listediting~ListEditing list
15
+ * editing feature} and {@link module:list/list/listui~ListUI list UI feature}.
16
16
  */
17
17
  export default class List extends Plugin {
18
18
  /**
package/src/list.js CHANGED
@@ -1,18 +1,18 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, 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
5
  /**
6
6
  * @module list/list
7
7
  */
8
- import ListEditing from './list/listediting';
9
- import ListUI from './list/listui';
10
- import { Plugin } from 'ckeditor5/src/core';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import ListEditing from './list/listediting.js';
10
+ import ListUI from './list/listui.js';
11
11
  /**
12
12
  * The list feature.
13
13
  *
14
- * This is a "glue" plugin that loads the {@link module:list/list/listediting~ListEditing list editing feature}
15
- * and {@link module:list/list/listui~ListUI list UI feature}.
14
+ * This is a "glue" plugin that loads the {@link module:list/list/listediting~ListEditing list
15
+ * editing feature} and {@link module:list/list/listui~ListUI list UI feature}.
16
16
  */
17
17
  export default class List extends Plugin {
18
18
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, 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
5
  /**
@@ -7,7 +7,7 @@
7
7
  */
8
8
  /**
9
9
  * The configuration of the {@link module:list/list~List list} feature
10
- * and the {@link module:list/documentlist~DocumentList document list} feature.
10
+ * and the {@link module:list/legacylist~LegacyList legacy list} feature.
11
11
  *
12
12
  * ```ts
13
13
  * ClassicEditor
@@ -25,7 +25,7 @@
25
25
  export interface ListConfig {
26
26
  /**
27
27
  * The configuration of the {@link module:list/listproperties~ListProperties} feature and the
28
- * {@link module:list/documentlistproperties~DocumentListProperties document list properties} feature.
28
+ * {@link module:list/legacylistproperties~LegacyListProperties legacy list properties} feature.
29
29
  *
30
30
  * Read more in {@link module:list/listconfig~ListPropertiesConfig}.
31
31
  */
@@ -43,15 +43,15 @@ export interface ListConfig {
43
43
  }
44
44
  /**
45
45
  * The configuration of the {@link module:list/listproperties~ListProperties list properties} feature and the
46
- * {@link module:list/documentlistproperties~DocumentListProperties document list properties} feature.
46
+ * {@link module:list/legacylistproperties~LegacyListProperties legacy list properties} feature.
47
47
  *
48
48
  * This configuration controls the individual list properties. For instance, it enables or disables specific editor commands
49
49
  * operating on lists ({@link module:list/listproperties/liststylecommand~ListStyleCommand `'listStyle'`},
50
50
  * {@link module:list/listproperties/liststartcommand~ListStartCommand `'listStart'`},
51
- * {@link module:list/listproperties/listreversedcommand~ListReversedCommand `'listReversed'`}, or on the document lists
52
- * {@link module:list/documentlistproperties/documentliststylecommand~DocumentListStyleCommand `'listStyle'`},
53
- * {@link module:list/documentlistproperties/documentliststartcommand~DocumentListStartCommand `'listStart'`},
54
- * {@link module:list/documentlistproperties/documentlistreversedcommand~DocumentListReversedCommand `'listReversed'`}), the look of the UI
51
+ * {@link module:list/listproperties/listreversedcommand~ListReversedCommand `'listReversed'`}, or on the legacy lists
52
+ * {@link module:list/legacylistproperties/legacyliststylecommand~LegacyListStyleCommand `'listStyle'`},
53
+ * {@link module:list/legacylistproperties/legacyliststartcommand~LegacyListStartCommand `'listStart'`},
54
+ * {@link module:list/legacylistproperties/legacylistreversedcommand~LegacyListReversedCommand `'listReversed'`}), the look of the UI
55
55
  * (`'numberedList'` and `'bulletedList'` dropdowns), and the editor data pipeline (allowed HTML attributes).
56
56
  *
57
57
  * ```ts
@@ -75,7 +75,7 @@ export interface ListPropertiesConfig {
75
75
  * It allows changing the `list-style-type` style or the `type` HTML attribute of a list.
76
76
  *
77
77
  * **Note**: Styling using the `type` HTML attribute is only available in
78
- * {@link module:list/documentlistproperties~DocumentListProperties document list properties}
78
+ * {@link module:list/listproperties~ListProperties list properties}
79
79
  * ({@link module:list/listconfig~ListPropertiesStyleConfig learn more}).
80
80
  *
81
81
  * @default true
@@ -124,7 +124,7 @@ export interface ListPropertiesStyleConfig {
124
124
  * **Note**: Due to limitations of HTML, the "Decimal with leading zero" style is impossible to set using the `type` attribute.
125
125
  *
126
126
  * **Note**: This configuration works only with
127
- * {@link module:list/documentlistproperties~DocumentListProperties document list properties}.
127
+ * {@link module:list/listproperties~ListProperties list properties}.
128
128
  *
129
129
  * @default false
130
130
  */
package/src/listconfig.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, 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
5
  export {};
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, 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
5
  /**
6
- * @module list/documentlistproperties/converters
6
+ * @module list/listproperties/converters
7
7
  */
8
- import type { UpcastElementEvent } from 'ckeditor5/src/engine';
9
- import type { GetCallback } from 'ckeditor5/src/utils';
10
- import type { AttributeStrategy } from './documentlistpropertiesediting';
8
+ import type { UpcastElementEvent } from 'ckeditor5/src/engine.js';
9
+ import type { GetCallback } from 'ckeditor5/src/utils.js';
10
+ import type { AttributeStrategy } from './listpropertiesediting.js';
11
11
  /**
12
12
  * Returns a converter that consumes the `style`, `reversed`, and `start` attributes.
13
13
  * In `style`, it searches for the `list-style-type` definition.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, 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
5
  /**
@@ -1,17 +1,16 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, 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
5
  /**
6
6
  * @module list/listproperties/listpropertiesediting
7
7
  */
8
- import { Plugin, type Editor } from 'ckeditor5/src/core';
9
- import ListEditing from '../list/listediting';
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
9
+ import type { Consumables, DowncastWriter, Element, Item, ViewElement } from 'ckeditor5/src/engine.js';
10
+ import ListEditing, { type ListItemAttributesMap } from '../list/listediting.js';
11
+ import ListPropertiesUtils from './listpropertiesutils.js';
10
12
  /**
11
- * The engine of the list properties feature.
12
- *
13
- * It sets the value for the `listItem` attribute of the {@link module:list/list~List `<listItem>`} element that
14
- * allows modifying the list style type.
13
+ * The document list properties engine feature.
15
14
  *
16
15
  * It registers the `'listStyle'`, `'listReversed'` and `'listStart'` commands if they are enabled in the configuration.
17
16
  * Read more in {@link module:list/listconfig~ListPropertiesConfig}.
@@ -20,7 +19,7 @@ export default class ListPropertiesEditing extends Plugin {
20
19
  /**
21
20
  * @inheritDoc
22
21
  */
23
- static get requires(): readonly [typeof ListEditing];
22
+ static get requires(): readonly [typeof ListEditing, typeof ListPropertiesUtils];
24
23
  /**
25
24
  * @inheritDoc
26
25
  */
@@ -33,40 +32,57 @@ export default class ListPropertiesEditing extends Plugin {
33
32
  * @inheritDoc
34
33
  */
35
34
  init(): void;
35
+ }
36
+ /**
37
+ * Strategy for dealing with `listItem` attributes supported by this plugin.
38
+ *
39
+ * @internal
40
+ */
41
+ export interface AttributeStrategy {
36
42
  /**
37
- * @inheritDoc
43
+ * The model attribute name.
44
+ */
45
+ attributeName: keyof ListItemAttributesMap;
46
+ /**
47
+ * The model attribute default value.
48
+ */
49
+ defaultValue: unknown;
50
+ /**
51
+ * The view consumable as expected by {@link module:engine/conversion/viewconsumable~ViewConsumable#consume `ViewConsumable`}.
38
52
  */
39
- afterInit(): void;
53
+ viewConsumables: Consumables;
40
54
  /**
41
- * Starts listening to {@link module:engine/model/model~Model#deleteContent} and checks whether two lists will be merged into a single
42
- * one after deleting the content.
43
- *
44
- * The purpose of this action is to adjust the `listStyle`, `listReversed` and `listStart` values
45
- * for the list that was merged.
46
- *
47
- * Consider the following model's content:
48
- *
49
- * ```xml
50
- * <listItem listIndent="0" listType="bulleted" listStyle="square">UL List item 1</listItem>
51
- * <listItem listIndent="0" listType="bulleted" listStyle="square">UL List item 2</listItem>
52
- * <paragraph>[A paragraph.]</paragraph>
53
- * <listItem listIndent="0" listType="bulleted" listStyle="circle">UL List item 1</listItem>
54
- * <listItem listIndent="0" listType="bulleted" listStyle="circle">UL List item 2</listItem>
55
- * ```
56
- *
57
- * After removing the paragraph element, the second list will be merged into the first one.
58
- * We want to inherit the `listStyle` attribute for the second list from the first one.
59
- *
60
- * ```xml
61
- * <listItem listIndent="0" listType="bulleted" listStyle="square">UL List item 1</listItem>
62
- * <listItem listIndent="0" listType="bulleted" listStyle="square">UL List item 2</listItem>
63
- * <listItem listIndent="0" listType="bulleted" listStyle="square">UL List item 1</listItem>
64
- * <listItem listIndent="0" listType="bulleted" listStyle="square">UL List item 2</listItem>
65
- * ```
66
- *
67
- * See https://github.com/ckeditor/ckeditor5/issues/7879.
68
- *
69
- * @param attributeStrategies Strategies for the enabled attributes.
55
+ * Registers an editor command.
70
56
  */
71
- private _mergeListAttributesWhileMergingLists;
57
+ addCommand(editor: Editor): void;
58
+ /**
59
+ * Verifies whether the strategy is applicable for the specified model element.
60
+ */
61
+ appliesToListItem(element: Item): boolean;
62
+ /**
63
+ * Verifies whether the model attribute value is valid.
64
+ */
65
+ hasValidAttribute(element: Element): boolean;
66
+ /**
67
+ * Sets the property on the view element.
68
+ */
69
+ setAttributeOnDowncast(writer: DowncastWriter, value: unknown, element: ViewElement): void;
70
+ /**
71
+ * Retrieves the property value from the view element.
72
+ */
73
+ getAttributeOnUpcast(element: ViewElement): unknown;
74
+ }
75
+ declare module '../list/listediting' {
76
+ interface ListItemAttributesMap {
77
+ listStyle?: string;
78
+ listStart?: number;
79
+ listReversed?: boolean;
80
+ }
81
+ }
82
+ declare module '../list/utils/model' {
83
+ interface ListElement {
84
+ getAttribute(key: 'listStyle'): string;
85
+ getAttribute(key: 'listStart'): number;
86
+ getAttribute(key: 'listReversed'): boolean;
87
+ }
72
88
  }