@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
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/legacylist/legacyutils
7
+ */
8
+ import { type DowncastConversionApi, type DowncastWriter, type Element, type Item, type Model, type Position, type ViewContainerElement, type ViewElement, type ViewItem, type ViewPosition } from 'ckeditor5/src/engine.js';
9
+ /**
10
+ * Creates a list item {@link module:engine/view/containerelement~ContainerElement}.
11
+ *
12
+ * @param writer The writer instance.
13
+ */
14
+ export declare function createViewListItemElement(writer: DowncastWriter): ViewContainerElement;
15
+ /**
16
+ * Helper function that creates a `<ul><li></li></ul>` or (`<ol>`) structure out of the given `modelItem` model `listItem` element.
17
+ * Then, it binds the created view list item (`<li>`) with the model `listItem` element.
18
+ * The function then returns the created view list item (`<li>`).
19
+ *
20
+ * @param modelItem Model list item.
21
+ * @param conversionApi Conversion interface.
22
+ * @returns View list element.
23
+ */
24
+ export declare function generateLiInUl(modelItem: Item, conversionApi: DowncastConversionApi): ViewContainerElement;
25
+ /**
26
+ * Helper function that inserts a view list at a correct place and merges it with its siblings.
27
+ * It takes a model list item element (`modelItem`) and a corresponding view list item element (`injectedItem`). The view list item
28
+ * should be in a view list element (`<ul>` or `<ol>`) and should be its only child.
29
+ * See comments below to better understand the algorithm.
30
+ *
31
+ * @param modelItem Model list item.
32
+ * @param injectedItem
33
+ * @param conversionApi Conversion interface.
34
+ * @param model The model instance.
35
+ */
36
+ export declare function injectViewList(modelItem: Element, injectedItem: ViewContainerElement, conversionApi: DowncastConversionApi, model: Model): void;
37
+ /**
38
+ * Helper function that takes two parameters that are expected to be view list elements, and merges them.
39
+ * The merge happens only if both parameters are list elements of the same type (the same element name and the same class attributes).
40
+ *
41
+ * @param viewWriter The writer instance.
42
+ * @param firstList The first element to compare.
43
+ * @param secondList The second element to compare.
44
+ * @returns The position after merge or `null` when there was no merge.
45
+ */
46
+ export declare function mergeViewLists(viewWriter: DowncastWriter, firstList: ViewItem, secondList: ViewItem): ViewPosition | null;
47
+ /**
48
+ * Helper function that for a given `view.Position`, returns a `view.Position` that is after all `view.UIElement`s that
49
+ * are after the given position.
50
+ *
51
+ * For example:
52
+ * `<container:p>foo^<ui:span></ui:span><ui:span></ui:span>bar</container:p>`
53
+ * For position ^, the position before "bar" will be returned.
54
+ *
55
+ */
56
+ export declare function positionAfterUiElements(viewPosition: ViewPosition): ViewPosition;
57
+ /**
58
+ * Helper function that searches for a previous list item sibling of a given model item that meets the given criteria
59
+ * passed by the options object.
60
+ *
61
+ * @param options Search criteria.
62
+ * @param options.sameIndent Whether the sought sibling should have the same indentation.
63
+ * @param options.smallerIndent Whether the sought sibling should have a smaller indentation.
64
+ * @param options.listIndent The reference indentation.
65
+ * @param options.direction Walking direction.
66
+ */
67
+ export declare function getSiblingListItem(modelItem: Item | null, options: {
68
+ sameIndent?: boolean;
69
+ smallerIndent?: boolean;
70
+ listIndent?: number;
71
+ direction?: 'forward' | 'backward';
72
+ }): Element | null;
73
+ /**
74
+ * Returns a first list view element that is direct child of the given view element.
75
+ */
76
+ export declare function findNestedList(viewElement: ViewElement): ViewElement | null;
77
+ /**
78
+ * Returns an array with all `listItem` elements that represent the same list.
79
+ *
80
+ * It means that values of `listIndent`, `listType`, `listStyle`, `listReversed` and `listStart` for all items are equal.
81
+ *
82
+ * Additionally, if the `position` is inside a list item, that list item will be returned as well.
83
+ *
84
+ * @param position Starting position.
85
+ * @param direction Walking direction.
86
+ */
87
+ export declare function getSiblingNodes(position: Position, direction: 'forward' | 'backward'): Array<Element>;
88
+ /**
89
+ * Returns an array with all `listItem` elements in the model selection.
90
+ *
91
+ * It returns all the items even if only a part of the list is selected, including items that belong to nested lists.
92
+ * If no list is selected, it returns an empty array.
93
+ * The order of the elements is not specified.
94
+ *
95
+ * @internal
96
+ */
97
+ export declare function getSelectedListItems(model: Model): Array<Element>;
98
+ /**
99
+ * Checks whether the given list-style-type is supported by numbered or bulleted list.
100
+ */
101
+ export declare function getListTypeFromListStyleType(listStyleType: string): 'bulleted' | 'numbered' | null;
@@ -0,0 +1,347 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/legacylist/legacyutils
7
+ */
8
+ import { TreeWalker, getFillerOffset } from 'ckeditor5/src/engine.js';
9
+ /**
10
+ * Creates a list item {@link module:engine/view/containerelement~ContainerElement}.
11
+ *
12
+ * @param writer The writer instance.
13
+ */
14
+ export function createViewListItemElement(writer) {
15
+ const viewItem = writer.createContainerElement('li');
16
+ viewItem.getFillerOffset = getListItemFillerOffset;
17
+ return viewItem;
18
+ }
19
+ /**
20
+ * Helper function that creates a `<ul><li></li></ul>` or (`<ol>`) structure out of the given `modelItem` model `listItem` element.
21
+ * Then, it binds the created view list item (`<li>`) with the model `listItem` element.
22
+ * The function then returns the created view list item (`<li>`).
23
+ *
24
+ * @param modelItem Model list item.
25
+ * @param conversionApi Conversion interface.
26
+ * @returns View list element.
27
+ */
28
+ export function generateLiInUl(modelItem, conversionApi) {
29
+ const mapper = conversionApi.mapper;
30
+ const viewWriter = conversionApi.writer;
31
+ const listType = modelItem.getAttribute('listType') == 'numbered' ? 'ol' : 'ul';
32
+ const viewItem = createViewListItemElement(viewWriter);
33
+ const viewList = viewWriter.createContainerElement(listType, null);
34
+ viewWriter.insert(viewWriter.createPositionAt(viewList, 0), viewItem);
35
+ mapper.bindElements(modelItem, viewItem);
36
+ return viewItem;
37
+ }
38
+ /**
39
+ * Helper function that inserts a view list at a correct place and merges it with its siblings.
40
+ * It takes a model list item element (`modelItem`) and a corresponding view list item element (`injectedItem`). The view list item
41
+ * should be in a view list element (`<ul>` or `<ol>`) and should be its only child.
42
+ * See comments below to better understand the algorithm.
43
+ *
44
+ * @param modelItem Model list item.
45
+ * @param injectedItem
46
+ * @param conversionApi Conversion interface.
47
+ * @param model The model instance.
48
+ */
49
+ export function injectViewList(modelItem, injectedItem, conversionApi, model) {
50
+ const injectedList = injectedItem.parent;
51
+ const mapper = conversionApi.mapper;
52
+ const viewWriter = conversionApi.writer;
53
+ // The position where the view list will be inserted.
54
+ let insertPosition = mapper.toViewPosition(model.createPositionBefore(modelItem));
55
+ // 1. Find the previous list item that has the same or smaller indent. Basically we are looking for the first model item
56
+ // that is a "parent" or "sibling" of the injected model item.
57
+ // If there is no such list item, it means that the injected list item is the first item in "its list".
58
+ const refItem = getSiblingListItem(modelItem.previousSibling, {
59
+ sameIndent: true,
60
+ smallerIndent: true,
61
+ listIndent: modelItem.getAttribute('listIndent')
62
+ });
63
+ const prevItem = modelItem.previousSibling;
64
+ if (refItem && refItem.getAttribute('listIndent') == modelItem.getAttribute('listIndent')) {
65
+ // There is a list item with the same indent - we found the same-level sibling.
66
+ // Break the list after it. The inserted view item will be added in the broken space.
67
+ const viewItem = mapper.toViewElement(refItem);
68
+ insertPosition = viewWriter.breakContainer(viewWriter.createPositionAfter(viewItem));
69
+ }
70
+ else {
71
+ // There is no list item with the same indent. Check the previous model item.
72
+ if (prevItem && prevItem.name == 'listItem') {
73
+ // If it is a list item, it has to have a lower indent.
74
+ // It means that the inserted item should be added to it as its nested item.
75
+ insertPosition = mapper.toViewPosition(model.createPositionAt(prevItem, 'end'));
76
+ // There could be some not mapped elements (eg. span in to-do list) but we need to insert
77
+ // a nested list directly inside the li element.
78
+ const mappedViewAncestor = mapper.findMappedViewAncestor(insertPosition);
79
+ const nestedList = findNestedList(mappedViewAncestor);
80
+ // If there already is some nested list, then use it's position.
81
+ if (nestedList) {
82
+ insertPosition = viewWriter.createPositionBefore(nestedList);
83
+ }
84
+ else {
85
+ // Else just put new list on the end of list item content.
86
+ insertPosition = viewWriter.createPositionAt(mappedViewAncestor, 'end');
87
+ }
88
+ }
89
+ else {
90
+ // The previous item is not a list item (or does not exist at all).
91
+ // Just map the position and insert the view item at the mapped position.
92
+ insertPosition = mapper.toViewPosition(model.createPositionBefore(modelItem));
93
+ }
94
+ }
95
+ insertPosition = positionAfterUiElements(insertPosition);
96
+ // Insert the view item.
97
+ viewWriter.insert(insertPosition, injectedList);
98
+ // 2. Handle possible children of the injected model item.
99
+ if (prevItem && prevItem.name == 'listItem') {
100
+ const prevView = mapper.toViewElement(prevItem);
101
+ const walkerBoundaries = viewWriter.createRange(viewWriter.createPositionAt(prevView, 0), insertPosition);
102
+ const walker = walkerBoundaries.getWalker({ ignoreElementEnd: true });
103
+ for (const value of walker) {
104
+ if (value.item.is('element', 'li')) {
105
+ const breakPosition = viewWriter.breakContainer(viewWriter.createPositionBefore(value.item));
106
+ const viewList = value.item.parent;
107
+ const targetPosition = viewWriter.createPositionAt(injectedItem, 'end');
108
+ mergeViewLists(viewWriter, targetPosition.nodeBefore, targetPosition.nodeAfter);
109
+ viewWriter.move(viewWriter.createRangeOn(viewList), targetPosition);
110
+ // This is bad, but those lists will be removed soon anyway.
111
+ walker._position = breakPosition;
112
+ }
113
+ }
114
+ }
115
+ else {
116
+ const nextViewList = injectedList.nextSibling;
117
+ if (nextViewList && (nextViewList.is('element', 'ul') || nextViewList.is('element', 'ol'))) {
118
+ let lastSubChild = null;
119
+ for (const child of nextViewList.getChildren()) {
120
+ const modelChild = mapper.toModelElement(child);
121
+ if (modelChild &&
122
+ modelChild.getAttribute('listIndent') > modelItem.getAttribute('listIndent')) {
123
+ lastSubChild = child;
124
+ }
125
+ else {
126
+ break;
127
+ }
128
+ }
129
+ if (lastSubChild) {
130
+ viewWriter.breakContainer(viewWriter.createPositionAfter(lastSubChild));
131
+ viewWriter.move(viewWriter.createRangeOn(lastSubChild.parent), viewWriter.createPositionAt(injectedItem, 'end'));
132
+ }
133
+ }
134
+ }
135
+ // Merge the inserted view list with its possible neighbor lists.
136
+ mergeViewLists(viewWriter, injectedList, injectedList.nextSibling);
137
+ mergeViewLists(viewWriter, injectedList.previousSibling, injectedList);
138
+ }
139
+ export function mergeViewLists(viewWriter, firstList, secondList) {
140
+ // Check if two lists are going to be merged.
141
+ if (!firstList || !secondList || (firstList.name != 'ul' && firstList.name != 'ol')) {
142
+ return null;
143
+ }
144
+ // Both parameters are list elements, so compare types now.
145
+ if (firstList.name != secondList.name || firstList.getAttribute('class') !== secondList.getAttribute('class')) {
146
+ return null;
147
+ }
148
+ return viewWriter.mergeContainers(viewWriter.createPositionAfter(firstList));
149
+ }
150
+ /**
151
+ * Helper function that for a given `view.Position`, returns a `view.Position` that is after all `view.UIElement`s that
152
+ * are after the given position.
153
+ *
154
+ * For example:
155
+ * `<container:p>foo^<ui:span></ui:span><ui:span></ui:span>bar</container:p>`
156
+ * For position ^, the position before "bar" will be returned.
157
+ *
158
+ */
159
+ export function positionAfterUiElements(viewPosition) {
160
+ return viewPosition.getLastMatchingPosition(value => value.item.is('uiElement'));
161
+ }
162
+ /**
163
+ * Helper function that searches for a previous list item sibling of a given model item that meets the given criteria
164
+ * passed by the options object.
165
+ *
166
+ * @param options Search criteria.
167
+ * @param options.sameIndent Whether the sought sibling should have the same indentation.
168
+ * @param options.smallerIndent Whether the sought sibling should have a smaller indentation.
169
+ * @param options.listIndent The reference indentation.
170
+ * @param options.direction Walking direction.
171
+ */
172
+ export function getSiblingListItem(modelItem, options) {
173
+ const sameIndent = !!options.sameIndent;
174
+ const smallerIndent = !!options.smallerIndent;
175
+ const indent = options.listIndent;
176
+ let item = modelItem;
177
+ while (item && item.name == 'listItem') {
178
+ const itemIndent = item.getAttribute('listIndent');
179
+ if ((sameIndent && indent == itemIndent) || (smallerIndent && indent > itemIndent)) {
180
+ return item;
181
+ }
182
+ if (options.direction === 'forward') {
183
+ item = item.nextSibling;
184
+ }
185
+ else {
186
+ item = item.previousSibling;
187
+ }
188
+ }
189
+ return null;
190
+ }
191
+ /**
192
+ * Returns a first list view element that is direct child of the given view element.
193
+ */
194
+ export function findNestedList(viewElement) {
195
+ for (const node of viewElement.getChildren()) {
196
+ if (node.name == 'ul' || node.name == 'ol') {
197
+ return node;
198
+ }
199
+ }
200
+ return null;
201
+ }
202
+ /**
203
+ * Returns an array with all `listItem` elements that represent the same list.
204
+ *
205
+ * It means that values of `listIndent`, `listType`, `listStyle`, `listReversed` and `listStart` for all items are equal.
206
+ *
207
+ * Additionally, if the `position` is inside a list item, that list item will be returned as well.
208
+ *
209
+ * @param position Starting position.
210
+ * @param direction Walking direction.
211
+ */
212
+ export function getSiblingNodes(position, direction) {
213
+ const items = [];
214
+ const listItem = position.parent;
215
+ const walkerOptions = {
216
+ ignoreElementEnd: false,
217
+ startPosition: position,
218
+ shallow: true,
219
+ direction
220
+ };
221
+ const limitIndent = listItem.getAttribute('listIndent');
222
+ const nodes = [...new TreeWalker(walkerOptions)]
223
+ .filter(value => value.item.is('element'))
224
+ .map(value => value.item);
225
+ for (const element of nodes) {
226
+ // If found something else than `listItem`, we're out of the list scope.
227
+ if (!element.is('element', 'listItem')) {
228
+ break;
229
+ }
230
+ // If current parsed item has lower indent that element that the element that was a starting point,
231
+ // it means we left a nested list. Abort searching items.
232
+ //
233
+ // ■ List item 1. [listIndent=0]
234
+ // ○ List item 2.[] [listIndent=1], limitIndent = 1,
235
+ // ○ List item 3. [listIndent=1]
236
+ // ■ List item 4. [listIndent=0]
237
+ //
238
+ // Abort searching when leave nested list.
239
+ if (element.getAttribute('listIndent') < limitIndent) {
240
+ break;
241
+ }
242
+ // ■ List item 1.[] [listIndent=0] limitIndent = 0,
243
+ // ○ List item 2. [listIndent=1]
244
+ // ○ List item 3. [listIndent=1]
245
+ // ■ List item 4. [listIndent=0]
246
+ //
247
+ // Ignore nested lists.
248
+ if (element.getAttribute('listIndent') > limitIndent) {
249
+ continue;
250
+ }
251
+ // ■ List item 1.[] [listType=bulleted]
252
+ // 1. List item 2. [listType=numbered]
253
+ // 2.List item 3. [listType=numbered]
254
+ //
255
+ // Abort searching when found a different kind of a list.
256
+ if (element.getAttribute('listType') !== listItem.getAttribute('listType')) {
257
+ break;
258
+ }
259
+ // ■ List item 1.[] [listType=bulleted]
260
+ // ■ List item 2. [listType=bulleted]
261
+ // ○ List item 3. [listType=bulleted]
262
+ // ○ List item 4. [listType=bulleted]
263
+ //
264
+ // Abort searching when found a different list style,
265
+ if (element.getAttribute('listStyle') !== listItem.getAttribute('listStyle')) {
266
+ break;
267
+ }
268
+ // ... different direction
269
+ if (element.getAttribute('listReversed') !== listItem.getAttribute('listReversed')) {
270
+ break;
271
+ }
272
+ // ... and different start index
273
+ if (element.getAttribute('listStart') !== listItem.getAttribute('listStart')) {
274
+ break;
275
+ }
276
+ if (direction === 'backward') {
277
+ items.unshift(element);
278
+ }
279
+ else {
280
+ items.push(element);
281
+ }
282
+ }
283
+ return items;
284
+ }
285
+ /**
286
+ * Returns an array with all `listItem` elements in the model selection.
287
+ *
288
+ * It returns all the items even if only a part of the list is selected, including items that belong to nested lists.
289
+ * If no list is selected, it returns an empty array.
290
+ * The order of the elements is not specified.
291
+ *
292
+ * @internal
293
+ */
294
+ export function getSelectedListItems(model) {
295
+ const document = model.document;
296
+ // For all selected blocks find all list items that are being selected
297
+ // and update the `listStyle` attribute in those lists.
298
+ let listItems = [...document.selection.getSelectedBlocks()]
299
+ .filter(element => element.is('element', 'listItem'))
300
+ .map(element => {
301
+ const position = model.change(writer => writer.createPositionAt(element, 0));
302
+ return [
303
+ ...getSiblingNodes(position, 'backward'),
304
+ ...getSiblingNodes(position, 'forward')
305
+ ];
306
+ })
307
+ .flat();
308
+ // Since `getSelectedBlocks()` can return items that belong to the same list, and
309
+ // `getSiblingNodes()` returns the entire list, we need to remove duplicated items.
310
+ listItems = [...new Set(listItems)];
311
+ return listItems;
312
+ }
313
+ const BULLETED_LIST_STYLE_TYPES = ['disc', 'circle', 'square'];
314
+ // There's a lot of them (https://www.w3.org/TR/css-counter-styles-3/#typedef-counter-style).
315
+ // Let's support only those that can be selected by ListPropertiesUI.
316
+ const NUMBERED_LIST_STYLE_TYPES = [
317
+ 'decimal',
318
+ 'decimal-leading-zero',
319
+ 'lower-roman',
320
+ 'upper-roman',
321
+ 'lower-latin',
322
+ 'upper-latin'
323
+ ];
324
+ /**
325
+ * Checks whether the given list-style-type is supported by numbered or bulleted list.
326
+ */
327
+ export function getListTypeFromListStyleType(listStyleType) {
328
+ if (BULLETED_LIST_STYLE_TYPES.includes(listStyleType)) {
329
+ return 'bulleted';
330
+ }
331
+ if (NUMBERED_LIST_STYLE_TYPES.includes(listStyleType)) {
332
+ return 'numbered';
333
+ }
334
+ return null;
335
+ }
336
+ /**
337
+ * Implementation of getFillerOffset for view list item element.
338
+ *
339
+ * @returns Block filler offset or `null` if block filler is not needed.
340
+ */
341
+ function getListItemFillerOffset() {
342
+ const hasOnlyLists = !this.isEmpty && (this.getChild(0).name == 'ul' || this.getChild(0).name == 'ol');
343
+ if (this.isEmpty || hasOnlyLists) {
344
+ return 0;
345
+ }
346
+ return getFillerOffset.call(this);
347
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/legacylist
7
+ */
8
+ import LegacyListEditing from './legacylist/legacylistediting.js';
9
+ import ListUI from './list/listui.js';
10
+ import { Plugin } from 'ckeditor5/src/core.js';
11
+ /**
12
+ * The legacy list feature.
13
+ *
14
+ * This is a "glue" plugin that loads the {@link module:list/legacylist/legacylistediting~LegacyListEditing legacy list editing feature}
15
+ * and {@link module:list/list/listui~ListUI list UI feature}.
16
+ */
17
+ export default class LegacyList extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get requires(): readonly [typeof LegacyListEditing, typeof ListUI];
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get pluginName(): "LegacyList";
26
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/legacylist
7
+ */
8
+ import LegacyListEditing from './legacylist/legacylistediting.js';
9
+ import ListUI from './list/listui.js';
10
+ import { Plugin } from 'ckeditor5/src/core.js';
11
+ /**
12
+ * The legacy list feature.
13
+ *
14
+ * This is a "glue" plugin that loads the {@link module:list/legacylist/legacylistediting~LegacyListEditing legacy list editing feature}
15
+ * and {@link module:list/list/listui~ListUI list UI feature}.
16
+ */
17
+ export default class LegacyList extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get requires() {
22
+ return [LegacyListEditing, ListUI];
23
+ }
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName() {
28
+ return 'LegacyList';
29
+ }
30
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/legacylistproperties/legacylistpropertiesediting
7
+ */
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
9
+ import LegacyListEditing from '../legacylist/legacylistediting.js';
10
+ /**
11
+ * The engine of the list properties feature.
12
+ *
13
+ * It sets the value for the `listItem` attribute of the {@link module:list/legacylist~LegacyList `<listItem>`} element that
14
+ * allows modifying the list style type.
15
+ *
16
+ * It registers the `'listStyle'`, `'listReversed'` and `'listStart'` commands if they are enabled in the configuration.
17
+ * Read more in {@link module:list/listconfig~ListPropertiesConfig}.
18
+ */
19
+ export default class LegacyListPropertiesEditing extends Plugin {
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get requires(): readonly [typeof LegacyListEditing];
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName(): "LegacyListPropertiesEditing";
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ constructor(editor: Editor);
32
+ /**
33
+ * @inheritDoc
34
+ */
35
+ init(): void;
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ afterInit(): void;
40
+ /**
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.
70
+ */
71
+ private _mergeListAttributesWhileMergingLists;
72
+ }