@ckeditor/ckeditor5-list 40.2.0 → 41.1.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 +20 -20
  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
@@ -1,12 +1,12 @@
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 { Command, type Editor } from 'ckeditor5/src/core';
5
+ import { Command, type Editor } from 'ckeditor5/src/core.js';
6
6
  /**
7
- * The list indent command. It is used by the {@link module:list/list~List list feature}.
7
+ * The list indent command. It is used by the {@link module:list/legacylist~LegacyList legacy list feature}.
8
8
  */
9
- export default class IndentCommand extends Command {
9
+ export default class LegacyIndentCommand extends Command {
10
10
  /**
11
11
  * Determines by how much the command will change the list item's indent attribute.
12
12
  */
@@ -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
- import { Command } from 'ckeditor5/src/core';
6
- import { first } from 'ckeditor5/src/utils';
5
+ import { Command } from 'ckeditor5/src/core.js';
6
+ import { first } from 'ckeditor5/src/utils.js';
7
7
  /**
8
- * The list indent command. It is used by the {@link module:list/list~List list feature}.
8
+ * The list indent command. It is used by the {@link module:list/legacylist~LegacyList legacy list feature}.
9
9
  */
10
- export default class IndentCommand extends Command {
10
+ export default class LegacyIndentCommand extends Command {
11
11
  /**
12
12
  * Creates an instance of the command.
13
13
  *
@@ -1,16 +1,12 @@
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 { Command, type Editor } from 'ckeditor5/src/core.js';
5
6
  /**
6
- * @module list/documentlist/documentlistcommand
7
+ * The list command. It is used by the {@link module:list/legacylist~LegacyList legacy list feature}.
7
8
  */
8
- import type { Element } from 'ckeditor5/src/engine';
9
- import { Command, type Editor } from 'ckeditor5/src/core';
10
- /**
11
- * The list command. It is used by the {@link module:list/documentlist~DocumentList document list feature}.
12
- */
13
- export default class DocumentListCommand extends Command {
9
+ export default class LegacyListCommand extends Command {
14
10
  /**
15
11
  * The type of the list created by the command.
16
12
  */
@@ -18,7 +14,6 @@ export default class DocumentListCommand extends Command {
18
14
  /**
19
15
  * A flag indicating whether the command is active, which means that the selection starts in a list of the same type.
20
16
  *
21
- * @observable
22
17
  * @readonly
23
18
  */
24
19
  value: boolean;
@@ -37,21 +32,14 @@ export default class DocumentListCommand extends Command {
37
32
  * Executes the list command.
38
33
  *
39
34
  * @fires execute
40
- * @fires afterExecute
41
35
  * @param options Command options.
42
36
  * @param options.forceValue If set, it will force the command behavior. If `true`, the command will try to convert the
43
- * selected items and potentially the neighbor elements to the proper list items. If set to `false` it will convert selected elements
37
+ * selected items and potentially the neighbor elements to the proper list items. If set to `false`, it will convert selected elements
44
38
  * to paragraphs. If not set, the command will toggle selected elements to list items or paragraphs, depending on the selection.
45
39
  */
46
40
  execute(options?: {
47
41
  forceValue?: boolean;
48
42
  }): void;
49
- /**
50
- * Fires the `afterExecute` event.
51
- *
52
- * @param changedBlocks The changed list elements.
53
- */
54
- private _fireAfterExecute;
55
43
  /**
56
44
  * Checks the command's {@link #value}.
57
45
  *
@@ -65,16 +53,3 @@ export default class DocumentListCommand extends Command {
65
53
  */
66
54
  private _checkEnabled;
67
55
  }
68
- /**
69
- * Event fired by the {@link ~DocumentListCommand#execute} method.
70
- *
71
- * It allows to execute an action after executing the {@link ~DocumentListCommand#execute} method,
72
- * for example adjusting attributes of changed list items.
73
- *
74
- * @internal
75
- * @eventName ~DocumentListCommand#afterExecute
76
- */
77
- export type DocumentListCommandAfterExecuteEvent = {
78
- name: 'afterExecute';
79
- args: [changedBlocks: Array<Element>];
80
- };
@@ -0,0 +1,274 @@
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
+ import { Command } from 'ckeditor5/src/core.js';
6
+ import { first } from 'ckeditor5/src/utils.js';
7
+ /**
8
+ * The list command. It is used by the {@link module:list/legacylist~LegacyList legacy list feature}.
9
+ */
10
+ export default class LegacyListCommand extends Command {
11
+ /**
12
+ * Creates an instance of the command.
13
+ *
14
+ * @param editor The editor instance.
15
+ * @param type List type that will be handled by this command.
16
+ */
17
+ constructor(editor, type) {
18
+ super(editor);
19
+ this.type = type;
20
+ }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ refresh() {
25
+ this.value = this._getValue();
26
+ this.isEnabled = this._checkEnabled();
27
+ }
28
+ /**
29
+ * Executes the list command.
30
+ *
31
+ * @fires execute
32
+ * @param options Command options.
33
+ * @param options.forceValue If set, it will force the command behavior. If `true`, the command will try to convert the
34
+ * selected items and potentially the neighbor elements to the proper list items. If set to `false`, it will convert selected elements
35
+ * to paragraphs. If not set, the command will toggle selected elements to list items or paragraphs, depending on the selection.
36
+ */
37
+ execute(options = {}) {
38
+ const model = this.editor.model;
39
+ const document = model.document;
40
+ const blocks = Array.from(document.selection.getSelectedBlocks())
41
+ .filter(block => checkCanBecomeListItem(block, model.schema));
42
+ // Whether we are turning off some items.
43
+ const turnOff = options.forceValue !== undefined ? !options.forceValue : this.value;
44
+ // If we are turning off items, we are going to rename them to paragraphs.
45
+ model.change(writer => {
46
+ // If part of a list got turned off, we need to handle (outdent) all of sub-items of the last turned-off item.
47
+ // To be sure that model is all the time in a good state, we first fix items below turned-off item.
48
+ if (turnOff) {
49
+ // Start from the model item that is just after the last turned-off item.
50
+ let next = blocks[blocks.length - 1].nextSibling;
51
+ let currentIndent = Number.POSITIVE_INFINITY;
52
+ let changes = [];
53
+ // Correct indent of all items after the last turned off item.
54
+ // Rules that should be followed:
55
+ // 1. All direct sub-items of turned-off item should become indent 0, because the first item after it
56
+ // will be the first item of a new list. Other items are at the same level, so should have same 0 index.
57
+ // 2. All items with indent lower than indent of turned-off item should become indent 0, because they
58
+ // should not end up as a child of any of list items that they were not children of before.
59
+ // 3. All other items should have their indent changed relatively to it's parent.
60
+ //
61
+ // For example:
62
+ // 1 * --------
63
+ // 2 * --------
64
+ // 3 * -------- <-- this is turned off.
65
+ // 4 * -------- <-- this has to become indent = 0, because it will be first item on a new list.
66
+ // 5 * -------- <-- this should be still be a child of item above, so indent = 1.
67
+ // 6 * -------- <-- this has to become indent = 0, because it should not be a child of any of items above.
68
+ // 7 * -------- <-- this should be still be a child of item above, so indent = 1.
69
+ // 8 * -------- <-- this has to become indent = 0.
70
+ // 9 * -------- <-- this should still be a child of item above, so indent = 1.
71
+ // 10 * -------- <-- this should still be a child of item above, so indent = 2.
72
+ // 11 * -------- <-- this should still be at the same level as item above, so indent = 2.
73
+ // 12 * -------- <-- this and all below are left unchanged.
74
+ // 13 * --------
75
+ // 14 * --------
76
+ //
77
+ // After turning off 3 the list becomes:
78
+ //
79
+ // 1 * --------
80
+ // 2 * --------
81
+ //
82
+ // 3 --------
83
+ //
84
+ // 4 * --------
85
+ // 5 * --------
86
+ // 6 * --------
87
+ // 7 * --------
88
+ // 8 * --------
89
+ // 9 * --------
90
+ // 10 * --------
91
+ // 11 * --------
92
+ // 12 * --------
93
+ // 13 * --------
94
+ // 14 * --------
95
+ //
96
+ // Thanks to this algorithm no lists are mismatched and no items get unexpected children/parent, while
97
+ // those parent-child connection which are possible to maintain are still maintained. It's worth noting
98
+ // that this is the same effect that we would be get by multiple use of outdent command. However doing
99
+ // it like this is much more efficient because it's less operation (less memory usage, easier OT) and
100
+ // less conversion (faster).
101
+ while (next && next.name == 'listItem' && next.getAttribute('listIndent') !== 0) {
102
+ // Check each next list item, as long as its indent is bigger than 0.
103
+ // If the indent is 0 we are not going to change anything anyway.
104
+ const indent = next.getAttribute('listIndent');
105
+ // We check if that's item indent is lower as current relative indent.
106
+ if (indent < currentIndent) {
107
+ // If it is, current relative indent becomes that indent.
108
+ currentIndent = indent;
109
+ }
110
+ // Fix indent relatively to current relative indent.
111
+ // Note, that if we just changed the current relative indent, the newIndent will be equal to 0.
112
+ const newIndent = indent - currentIndent;
113
+ // Save the entry in changes array. We do not apply it at the moment, because we will need to
114
+ // reverse the changes so the last item is changed first.
115
+ // This is to keep model in correct state all the time.
116
+ changes.push({ element: next, listIndent: newIndent });
117
+ // Find next item.
118
+ next = next.nextSibling;
119
+ }
120
+ changes = changes.reverse();
121
+ for (const item of changes) {
122
+ writer.setAttribute('listIndent', item.listIndent, item.element);
123
+ }
124
+ }
125
+ // If we are turning on, we might change some items that are already `listItem`s but with different type.
126
+ // Changing one nested list item to other type should also trigger changing all its siblings so the
127
+ // whole nested list is of the same type.
128
+ // Example (assume changing to numbered list):
129
+ // * ------ <-- do not fix, top level item
130
+ // * ------ <-- fix, because latter list item of this item's list is changed
131
+ // * ------ <-- do not fix, item is not affected (different list)
132
+ // * ------ <-- fix, because latter list item of this item's list is changed
133
+ // * ------ <-- fix, because latter list item of this item's list is changed
134
+ // * ---[-- <-- already in selection
135
+ // * ------ <-- already in selection
136
+ // * ------ <-- already in selection
137
+ // * ------ <-- already in selection, but does not cause other list items to change because is top-level
138
+ // * ---]-- <-- already in selection
139
+ // * ------ <-- fix, because preceding list item of this item's list is changed
140
+ // * ------ <-- do not fix, item is not affected (different list)
141
+ // * ------ <-- do not fix, top level item
142
+ if (!turnOff) {
143
+ // Find lowest indent among selected items. This will be indicator what is the indent of
144
+ // top-most list affected by the command.
145
+ let lowestIndent = Number.POSITIVE_INFINITY;
146
+ for (const item of blocks) {
147
+ if (item.is('element', 'listItem') && item.getAttribute('listIndent') < lowestIndent) {
148
+ lowestIndent = item.getAttribute('listIndent');
149
+ }
150
+ }
151
+ // Do not execute the fix for top-level lists.
152
+ lowestIndent = lowestIndent === 0 ? 1 : lowestIndent;
153
+ // Fix types of list items that are "before" the selected blocks.
154
+ _fixType(blocks, true, lowestIndent);
155
+ // Fix types of list items that are "after" the selected blocks.
156
+ _fixType(blocks, false, lowestIndent);
157
+ }
158
+ // Phew! Now it will be easier :).
159
+ // For each block element that was in the selection, we will either: turn it to list item,
160
+ // turn it to paragraph, or change it's type. Or leave it as it is.
161
+ // Do it in reverse as there might be multiple blocks (same as with changing indents).
162
+ for (const element of blocks.reverse()) {
163
+ if (turnOff && element.name == 'listItem') {
164
+ // We are turning off and the element is a `listItem` - it should be converted to `paragraph`.
165
+ // List item specific attributes are removed by post fixer.
166
+ writer.rename(element, 'paragraph');
167
+ }
168
+ else if (!turnOff && element.name != 'listItem') {
169
+ // We are turning on and the element is not a `listItem` - it should be converted to `listItem`.
170
+ // The order of operations is important to keep model in correct state.
171
+ writer.setAttributes({ listType: this.type, listIndent: 0 }, element);
172
+ writer.rename(element, 'listItem');
173
+ }
174
+ else if (!turnOff && element.name == 'listItem' && element.getAttribute('listType') != this.type) {
175
+ // We are turning on and the element is a `listItem` but has different type - change it's type and
176
+ // type of it's all siblings that have same indent.
177
+ writer.setAttribute('listType', this.type, element);
178
+ }
179
+ }
180
+ /**
181
+ * Event fired by the {@link #execute} method.
182
+ *
183
+ * It allows to execute an action after executing the {@link ~ListCommand#execute} method, for example adjusting
184
+ * attributes of changed blocks.
185
+ *
186
+ * @protected
187
+ * @event _executeCleanup
188
+ */
189
+ this.fire('_executeCleanup', blocks);
190
+ });
191
+ }
192
+ /**
193
+ * Checks the command's {@link #value}.
194
+ *
195
+ * @returns The current value.
196
+ */
197
+ _getValue() {
198
+ // Check whether closest `listItem` ancestor of the position has a correct type.
199
+ const listItem = first(this.editor.model.document.selection.getSelectedBlocks());
200
+ return !!listItem && listItem.is('element', 'listItem') && listItem.getAttribute('listType') == this.type;
201
+ }
202
+ /**
203
+ * Checks whether the command can be enabled in the current context.
204
+ *
205
+ * @returns Whether the command should be enabled.
206
+ */
207
+ _checkEnabled() {
208
+ // If command value is true it means that we are in list item, so the command should be enabled.
209
+ if (this.value) {
210
+ return true;
211
+ }
212
+ const selection = this.editor.model.document.selection;
213
+ const schema = this.editor.model.schema;
214
+ const firstBlock = first(selection.getSelectedBlocks());
215
+ if (!firstBlock) {
216
+ return false;
217
+ }
218
+ // Otherwise, check if list item can be inserted at the position start.
219
+ return checkCanBecomeListItem(firstBlock, schema);
220
+ }
221
+ }
222
+ /**
223
+ * Helper function used when one or more list item have their type changed. Fixes type of other list items
224
+ * that are affected by the change (are in same lists) but are not directly in selection. The function got extracted
225
+ * not to duplicated code, as same fix has to be performed before and after selection.
226
+ *
227
+ * @param blocks Blocks that are in selection.
228
+ * @param isBackward Specified whether fix will be applied for blocks before first selected block (`true`)
229
+ * or blocks after last selected block (`false`).
230
+ * @param lowestIndent Lowest indent among selected blocks.
231
+ */
232
+ function _fixType(blocks, isBackward, lowestIndent) {
233
+ // We need to check previous sibling of first changed item and next siblings of last changed item.
234
+ const startingItem = isBackward ? blocks[0] : blocks[blocks.length - 1];
235
+ if (startingItem.is('element', 'listItem')) {
236
+ let item = startingItem[isBackward ? 'previousSibling' : 'nextSibling'];
237
+ // During processing items, keeps the lowest indent of already processed items.
238
+ // This saves us from changing too many items.
239
+ // Following example is for going forward as it is easier to read, however same applies to going backward.
240
+ // * ------
241
+ // * ------
242
+ // * --[---
243
+ // * ------ <-- `lowestIndent` should be 1
244
+ // * --]--- <-- `startingItem`, `currentIndent` = 2, `lowestIndent` == 1
245
+ // * ------ <-- should be fixed, `indent` == 2 == `currentIndent`
246
+ // * ------ <-- should be fixed, set `currentIndent` to 1, `indent` == 1 == `currentIndent`
247
+ // * ------ <-- should not be fixed, item is in different list, `indent` = 2, `indent` != `currentIndent`
248
+ // * ------ <-- should be fixed, `indent` == 1 == `currentIndent`
249
+ // * ------ <-- break loop (`indent` < `lowestIndent`)
250
+ let currentIndent = startingItem.getAttribute('listIndent');
251
+ // Look back until a list item with indent lower than reference `lowestIndent`.
252
+ // That would be the parent of nested sublist which contains item having `lowestIndent`.
253
+ while (item && item.is('element', 'listItem') && item.getAttribute('listIndent') >= lowestIndent) {
254
+ if (currentIndent > item.getAttribute('listIndent')) {
255
+ currentIndent = item.getAttribute('listIndent');
256
+ }
257
+ // Found an item that is in the same nested sublist.
258
+ if (item.getAttribute('listIndent') == currentIndent) {
259
+ // Just add the item to selected blocks like it was selected by the user.
260
+ blocks[isBackward ? 'unshift' : 'push'](item);
261
+ }
262
+ item = item[isBackward ? 'previousSibling' : 'nextSibling'];
263
+ }
264
+ }
265
+ }
266
+ /**
267
+ * Checks whether the given block can be replaced by a listItem.
268
+ *
269
+ * @param block A block to be tested.
270
+ * @param schema The schema of the document.
271
+ */
272
+ function checkCanBecomeListItem(block, schema) {
273
+ return schema.checkChild(block.parent, 'listItem') && !schema.isObject(block);
274
+ }
@@ -0,0 +1,32 @@
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
+ import LegacyListUtils from './legacylistutils.js';
6
+ import { Plugin } from 'ckeditor5/src/core.js';
7
+ import { Enter } from 'ckeditor5/src/enter.js';
8
+ import { Delete } from 'ckeditor5/src/typing.js';
9
+ import '../../theme/list.css';
10
+ /**
11
+ * The engine of the list feature. It handles creating, editing and removing lists and list items.
12
+ *
13
+ * It registers the `'numberedList'`, `'bulletedList'`, `'indentList'` and `'outdentList'` commands.
14
+ */
15
+ export default class LegacyListEditing extends Plugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName(): "LegacyListEditing";
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get requires(): readonly [typeof Enter, typeof Delete, typeof LegacyListUtils];
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ init(): void;
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ afterInit(): void;
32
+ }
@@ -0,0 +1,161 @@
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/legacylistediting
7
+ */
8
+ import LegacyListCommand from './legacylistcommand.js';
9
+ import LegacyIndentCommand from './legacyindentcommand.js';
10
+ import LegacyListUtils from './legacylistutils.js';
11
+ import { Plugin } from 'ckeditor5/src/core.js';
12
+ import { Enter } from 'ckeditor5/src/enter.js';
13
+ import { Delete } from 'ckeditor5/src/typing.js';
14
+ import { cleanList, cleanListItem, modelViewInsertion, modelViewChangeType, modelViewMergeAfterChangeType, modelViewMergeAfter, modelViewRemove, modelViewSplitOnInsert, modelViewChangeIndent, modelChangePostFixer, modelIndentPasteFixer, viewModelConverter, modelToViewPosition, viewToModelPosition } from './legacyconverters.js';
15
+ import '../../theme/list.css';
16
+ /**
17
+ * The engine of the list feature. It handles creating, editing and removing lists and list items.
18
+ *
19
+ * It registers the `'numberedList'`, `'bulletedList'`, `'indentList'` and `'outdentList'` commands.
20
+ */
21
+ export default class LegacyListEditing extends Plugin {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get pluginName() {
26
+ return 'LegacyListEditing';
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get requires() {
32
+ return [Enter, Delete, LegacyListUtils];
33
+ }
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ init() {
38
+ const editor = this.editor;
39
+ // Schema.
40
+ // Note: in case `$block` will ever be allowed in `listItem`, keep in mind that this feature
41
+ // uses `Selection#getSelectedBlocks()` without any additional processing to obtain all selected list items.
42
+ // If there are blocks allowed inside list item, algorithms using `getSelectedBlocks()` will have to be modified.
43
+ editor.model.schema.register('listItem', {
44
+ inheritAllFrom: '$block',
45
+ allowAttributes: ['listType', 'listIndent']
46
+ });
47
+ // Converters.
48
+ const data = editor.data;
49
+ const editing = editor.editing;
50
+ editor.model.document.registerPostFixer(writer => modelChangePostFixer(editor.model, writer));
51
+ editing.mapper.registerViewToModelLength('li', getViewListItemLength);
52
+ data.mapper.registerViewToModelLength('li', getViewListItemLength);
53
+ editing.mapper.on('modelToViewPosition', modelToViewPosition(editing.view));
54
+ editing.mapper.on('viewToModelPosition', viewToModelPosition(editor.model));
55
+ data.mapper.on('modelToViewPosition', modelToViewPosition(editing.view));
56
+ editor.conversion.for('editingDowncast')
57
+ .add(dispatcher => {
58
+ dispatcher.on('insert', modelViewSplitOnInsert, { priority: 'high' });
59
+ dispatcher.on('insert:listItem', modelViewInsertion(editor.model));
60
+ dispatcher.on('attribute:listType:listItem', modelViewChangeType, { priority: 'high' });
61
+ dispatcher.on('attribute:listType:listItem', modelViewMergeAfterChangeType, { priority: 'low' });
62
+ dispatcher.on('attribute:listIndent:listItem', modelViewChangeIndent(editor.model));
63
+ dispatcher.on('remove:listItem', modelViewRemove(editor.model));
64
+ dispatcher.on('remove', modelViewMergeAfter, { priority: 'low' });
65
+ });
66
+ editor.conversion.for('dataDowncast')
67
+ .add(dispatcher => {
68
+ dispatcher.on('insert', modelViewSplitOnInsert, { priority: 'high' });
69
+ dispatcher.on('insert:listItem', modelViewInsertion(editor.model));
70
+ });
71
+ editor.conversion.for('upcast')
72
+ .add(dispatcher => {
73
+ dispatcher.on('element:ul', cleanList, { priority: 'high' });
74
+ dispatcher.on('element:ol', cleanList, { priority: 'high' });
75
+ dispatcher.on('element:li', cleanListItem, { priority: 'high' });
76
+ dispatcher.on('element:li', viewModelConverter);
77
+ });
78
+ // Fix indentation of pasted items.
79
+ editor.model.on('insertContent', modelIndentPasteFixer, { priority: 'high' });
80
+ // Register commands for numbered and bulleted list.
81
+ editor.commands.add('numberedList', new LegacyListCommand(editor, 'numbered'));
82
+ editor.commands.add('bulletedList', new LegacyListCommand(editor, 'bulleted'));
83
+ // Register commands for indenting.
84
+ editor.commands.add('indentList', new LegacyIndentCommand(editor, 'forward'));
85
+ editor.commands.add('outdentList', new LegacyIndentCommand(editor, 'backward'));
86
+ const viewDocument = editing.view.document;
87
+ // Overwrite default Enter key behavior.
88
+ // If Enter key is pressed with selection collapsed in empty list item, outdent it instead of breaking it.
89
+ this.listenTo(viewDocument, 'enter', (evt, data) => {
90
+ const doc = this.editor.model.document;
91
+ const positionParent = doc.selection.getLastPosition().parent;
92
+ if (doc.selection.isCollapsed && positionParent.name == 'listItem' && positionParent.isEmpty) {
93
+ this.editor.execute('outdentList');
94
+ data.preventDefault();
95
+ evt.stop();
96
+ }
97
+ }, { context: 'li' });
98
+ // Overwrite default Backspace key behavior.
99
+ // If Backspace key is pressed with selection collapsed on first position in first list item, outdent it. #83
100
+ this.listenTo(viewDocument, 'delete', (evt, data) => {
101
+ // Check conditions from those that require less computations like those immediately available.
102
+ if (data.direction !== 'backward') {
103
+ return;
104
+ }
105
+ const selection = this.editor.model.document.selection;
106
+ if (!selection.isCollapsed) {
107
+ return;
108
+ }
109
+ const firstPosition = selection.getFirstPosition();
110
+ if (!firstPosition.isAtStart) {
111
+ return;
112
+ }
113
+ const positionParent = firstPosition.parent;
114
+ if (positionParent.name !== 'listItem') {
115
+ return;
116
+ }
117
+ const previousIsAListItem = positionParent.previousSibling && positionParent.previousSibling.name === 'listItem';
118
+ if (previousIsAListItem) {
119
+ return;
120
+ }
121
+ this.editor.execute('outdentList');
122
+ data.preventDefault();
123
+ evt.stop();
124
+ }, { context: 'li' });
125
+ this.listenTo(editor.editing.view.document, 'tab', (evt, data) => {
126
+ const commandName = data.shiftKey ? 'outdentList' : 'indentList';
127
+ const command = this.editor.commands.get(commandName);
128
+ if (command.isEnabled) {
129
+ editor.execute(commandName);
130
+ data.stopPropagation();
131
+ data.preventDefault();
132
+ evt.stop();
133
+ }
134
+ }, { context: 'li' });
135
+ }
136
+ /**
137
+ * @inheritDoc
138
+ */
139
+ afterInit() {
140
+ const commands = this.editor.commands;
141
+ const indent = commands.get('indent');
142
+ const outdent = commands.get('outdent');
143
+ if (indent) {
144
+ indent.registerChildCommand(commands.get('indentList'));
145
+ }
146
+ if (outdent) {
147
+ outdent.registerChildCommand(commands.get('outdentList'));
148
+ }
149
+ }
150
+ }
151
+ function getViewListItemLength(element) {
152
+ let length = 1;
153
+ for (const child of element.getChildren()) {
154
+ if (child.name == 'ul' || child.name == 'ol') {
155
+ for (const item of child.getChildren()) {
156
+ length += getViewListItemLength(item);
157
+ }
158
+ }
159
+ }
160
+ return length;
161
+ }
@@ -0,0 +1,41 @@
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/legacylistutils
7
+ */
8
+ import type { Element, Model, Position } from 'ckeditor5/src/engine.js';
9
+ import { Plugin } from 'ckeditor5/src/core.js';
10
+ /**
11
+ * A set of helpers related to legacy lists.
12
+ */
13
+ export default class LegacyListUtils extends Plugin {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get pluginName(): "LegacyListUtils";
18
+ /**
19
+ * Checks whether the given list-style-type is supported by numbered or bulleted list.
20
+ */
21
+ getListTypeFromListStyleType(listStyleType: string): 'bulleted' | 'numbered' | null;
22
+ /**
23
+ * Returns an array with all `listItem` elements in the model selection.
24
+ *
25
+ * It returns all the items even if only a part of the list is selected, including items that belong to nested lists.
26
+ * If no list is selected, it returns an empty array.
27
+ * The order of the elements is not specified.
28
+ */
29
+ getSelectedListItems(model: Model): Array<Element>;
30
+ /**
31
+ * Returns an array with all `listItem` elements that represent the same list.
32
+ *
33
+ * It means that values of `listIndent`, `listType`, `listStyle`, `listReversed` and `listStart` for all items are equal.
34
+ *
35
+ * Additionally, if the `position` is inside a list item, that list item will be returned as well.
36
+ *
37
+ * @param position Starting position.
38
+ * @param direction Walking direction.
39
+ */
40
+ getSiblingNodes(position: Position, direction: 'forward' | 'backward'): Array<Element>;
41
+ }
@@ -0,0 +1,46 @@
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
+ import { Plugin } from 'ckeditor5/src/core.js';
6
+ import { getListTypeFromListStyleType, getSelectedListItems, getSiblingNodes } from './legacyutils.js';
7
+ /**
8
+ * A set of helpers related to legacy lists.
9
+ */
10
+ export default class LegacyListUtils extends Plugin {
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ static get pluginName() {
15
+ return 'LegacyListUtils';
16
+ }
17
+ /**
18
+ * Checks whether the given list-style-type is supported by numbered or bulleted list.
19
+ */
20
+ getListTypeFromListStyleType(listStyleType) {
21
+ return getListTypeFromListStyleType(listStyleType);
22
+ }
23
+ /**
24
+ * Returns an array with all `listItem` elements in the model selection.
25
+ *
26
+ * It returns all the items even if only a part of the list is selected, including items that belong to nested lists.
27
+ * If no list is selected, it returns an empty array.
28
+ * The order of the elements is not specified.
29
+ */
30
+ getSelectedListItems(model) {
31
+ return getSelectedListItems(model);
32
+ }
33
+ /**
34
+ * Returns an array with all `listItem` elements that represent the same list.
35
+ *
36
+ * It means that values of `listIndent`, `listType`, `listStyle`, `listReversed` and `listStart` for all items are equal.
37
+ *
38
+ * Additionally, if the `position` is inside a list item, that list item will be returned as well.
39
+ *
40
+ * @param position Starting position.
41
+ * @param direction Walking direction.
42
+ */
43
+ getSiblingNodes(position, direction) {
44
+ return getSiblingNodes(position, direction);
45
+ }
46
+ }