@ckeditor/ckeditor5-list 35.3.2 → 36.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 (55) hide show
  1. package/LICENSE.md +1 -1
  2. package/build/list.js +2 -2
  3. package/package.json +43 -39
  4. package/src/documentlist/converters.js +303 -419
  5. package/src/documentlist/documentlistcommand.js +136 -207
  6. package/src/documentlist/documentlistediting.js +538 -697
  7. package/src/documentlist/documentlistindentcommand.js +115 -168
  8. package/src/documentlist/documentlistmergecommand.js +161 -222
  9. package/src/documentlist/documentlistsplitcommand.js +59 -103
  10. package/src/documentlist/documentlistutils.js +41 -0
  11. package/src/documentlist/utils/listwalker.js +138 -236
  12. package/src/documentlist/utils/model.js +322 -421
  13. package/src/documentlist/utils/postfixers.js +98 -118
  14. package/src/documentlist/utils/view.js +74 -105
  15. package/src/documentlist.js +13 -19
  16. package/src/documentlistproperties/converters.js +33 -47
  17. package/src/documentlistproperties/documentlistpropertiesediting.js +266 -354
  18. package/src/documentlistproperties/documentlistpropertiesutils.js +44 -0
  19. package/src/documentlistproperties/documentlistreversedcommand.js +40 -61
  20. package/src/documentlistproperties/documentliststartcommand.js +42 -61
  21. package/src/documentlistproperties/documentliststylecommand.js +97 -147
  22. package/src/documentlistproperties/utils/style.js +27 -47
  23. package/src/documentlistproperties.js +13 -19
  24. package/src/index.js +4 -3
  25. package/src/list/converters.js +772 -929
  26. package/src/list/indentcommand.js +105 -140
  27. package/src/list/listcommand.js +262 -315
  28. package/src/list/listediting.js +142 -200
  29. package/src/list/listui.js +16 -25
  30. package/src/list/listutils.js +46 -0
  31. package/src/list/utils.js +295 -378
  32. package/src/list.js +13 -44
  33. package/src/listcommands.js +5 -0
  34. package/src/listconfig.js +5 -0
  35. package/src/listproperties/listpropertiesediting.js +656 -801
  36. package/src/listproperties/listpropertiesui.js +244 -296
  37. package/src/listproperties/listreversedcommand.js +37 -49
  38. package/src/listproperties/liststartcommand.js +37 -49
  39. package/src/listproperties/liststylecommand.js +82 -115
  40. package/src/listproperties/ui/collapsibleview.js +75 -138
  41. package/src/listproperties/ui/listpropertiesview.js +289 -414
  42. package/src/listproperties.js +13 -118
  43. package/src/liststyle.js +18 -24
  44. package/src/todolist/checktodolistcommand.js +60 -102
  45. package/src/todolist/todolistconverters.js +189 -271
  46. package/src/todolist/todolistediting.js +141 -206
  47. package/src/todolist/todolistui.js +14 -21
  48. package/src/todolist.js +13 -19
  49. package/theme/collapsible.css +1 -1
  50. package/theme/documentlist.css +1 -1
  51. package/theme/list.css +40 -0
  52. package/theme/listproperties.css +1 -1
  53. package/theme/liststyles.css +1 -37
  54. package/theme/todolist.css +1 -1
  55. package/build/list.js.map +0 -1
@@ -1,150 +1,115 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, 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
-
6
- /**
7
- * @module list/list/indentcommand
8
- */
9
-
10
5
  import { Command } from 'ckeditor5/src/core';
11
6
  import { first } from 'ckeditor5/src/utils';
12
-
13
7
  /**
14
8
  * The list indent command. It is used by the {@link module:list/list~List list feature}.
15
- *
16
- * @extends module:core/command~Command
17
9
  */
18
10
  export default class IndentCommand extends Command {
19
- /**
20
- * Creates an instance of the command.
21
- *
22
- * @param {module:core/editor/editor~Editor} editor The editor instance.
23
- * @param {'forward'|'backward'} indentDirection The direction of indent. If it is equal to `backward`, the command
24
- * will outdent a list item.
25
- */
26
- constructor( editor, indentDirection ) {
27
- super( editor );
28
-
29
- /**
30
- * Determines by how much the command will change the list item's indent attribute.
31
- *
32
- * @readonly
33
- * @private
34
- * @member {Number}
35
- */
36
- this._indentBy = indentDirection == 'forward' ? 1 : -1;
37
- }
38
-
39
- /**
40
- * @inheritDoc
41
- */
42
- refresh() {
43
- this.isEnabled = this._checkEnabled();
44
- }
45
-
46
- /**
47
- * Indents or outdents (depending on the {@link #constructor}'s `indentDirection` parameter) selected list items.
48
- *
49
- * @fires execute
50
- * @fires _executeCleanup
51
- */
52
- execute() {
53
- const model = this.editor.model;
54
- const doc = model.document;
55
- let itemsToChange = Array.from( doc.selection.getSelectedBlocks() );
56
-
57
- model.change( writer => {
58
- const lastItem = itemsToChange[ itemsToChange.length - 1 ];
59
-
60
- // Indenting a list item should also indent all the items that are already sub-items of indented item.
61
- let next = lastItem.nextSibling;
62
-
63
- // Check all items after last indented item, as long as their indent is bigger than indent of that item.
64
- while ( next && next.name == 'listItem' && next.getAttribute( 'listIndent' ) > lastItem.getAttribute( 'listIndent' ) ) {
65
- itemsToChange.push( next );
66
-
67
- next = next.nextSibling;
68
- }
69
-
70
- // We need to be sure to keep model in correct state after each small change, because converters
71
- // bases on that state and assumes that model is correct.
72
- // Because of that, if the command outdents items, we will outdent them starting from the last item, as
73
- // it is safer.
74
- if ( this._indentBy < 0 ) {
75
- itemsToChange = itemsToChange.reverse();
76
- }
77
-
78
- for ( const item of itemsToChange ) {
79
- const indent = item.getAttribute( 'listIndent' ) + this._indentBy;
80
-
81
- // If indent is lower than 0, it means that the item got outdented when it was not indented.
82
- // This means that we need to convert that list item to paragraph.
83
- if ( indent < 0 ) {
84
- // To keep the model as correct as possible, first rename listItem, then remove attributes,
85
- // as listItem without attributes is very incorrect and will cause problems in converters.
86
- // No need to remove attributes, will be removed by post fixer.
87
- writer.rename( item, 'paragraph' );
88
- }
89
- // If indent is >= 0, change the attribute value.
90
- else {
91
- writer.setAttribute( 'listIndent', indent, item );
92
- }
93
- }
94
-
95
- /**
96
- * Event fired by the {@link #execute} method.
97
- *
98
- * It allows to execute an action after executing the {@link ~IndentCommand#execute} method, for example adjusting
99
- * attributes of changed list items.
100
- *
101
- * @protected
102
- * @event _executeCleanup
103
- */
104
- this.fire( '_executeCleanup', itemsToChange );
105
- } );
106
- }
107
-
108
- /**
109
- * Checks whether the command can be enabled in the current context.
110
- *
111
- * @private
112
- * @returns {Boolean} Whether the command should be enabled.
113
- */
114
- _checkEnabled() {
115
- // Check whether any of position's ancestor is a list item.
116
- const listItem = first( this.editor.model.document.selection.getSelectedBlocks() );
117
-
118
- // If selection is not in a list item, the command is disabled.
119
- if ( !listItem || !listItem.is( 'element', 'listItem' ) ) {
120
- return false;
121
- }
122
-
123
- if ( this._indentBy > 0 ) {
124
- // Cannot indent first item in it's list. Check if before `listItem` is a list item that is in same list.
125
- // To be in the same list, the item has to have same attributes and cannot be "split" by an item with lower indent.
126
- const indent = listItem.getAttribute( 'listIndent' );
127
- const type = listItem.getAttribute( 'listType' );
128
-
129
- let prev = listItem.previousSibling;
130
-
131
- while ( prev && prev.is( 'element', 'listItem' ) && prev.getAttribute( 'listIndent' ) >= indent ) {
132
- if ( prev.getAttribute( 'listIndent' ) == indent ) {
133
- // The item is on the same level.
134
- // If it has same type, it means that we found a preceding sibling from the same list.
135
- // If it does not have same type, it means that `listItem` is on different list (this can happen only
136
- // on top level lists, though).
137
- return prev.getAttribute( 'listType' ) == type;
138
- }
139
-
140
- prev = prev.previousSibling;
141
- }
142
-
143
- // Could not find similar list item, this means that `listItem` is first in its list.
144
- return false;
145
- }
146
-
147
- // If we are outdenting it is enough to be in list item. Every list item can always be outdented.
148
- return true;
149
- }
11
+ /**
12
+ * Creates an instance of the command.
13
+ *
14
+ * @param editor The editor instance.
15
+ * @param indentDirection The direction of indent. If it is equal to `backward`, the command will outdent a list item.
16
+ */
17
+ constructor(editor, indentDirection) {
18
+ super(editor);
19
+ this._indentBy = indentDirection == 'forward' ? 1 : -1;
20
+ }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ refresh() {
25
+ this.isEnabled = this._checkEnabled();
26
+ }
27
+ /**
28
+ * Indents or outdents (depending on the {@link #constructor}'s `indentDirection` parameter) selected list items.
29
+ *
30
+ * @fires execute
31
+ * @fires _executeCleanup
32
+ */
33
+ execute() {
34
+ const model = this.editor.model;
35
+ const doc = model.document;
36
+ let itemsToChange = Array.from(doc.selection.getSelectedBlocks());
37
+ model.change(writer => {
38
+ const lastItem = itemsToChange[itemsToChange.length - 1];
39
+ // Indenting a list item should also indent all the items that are already sub-items of indented item.
40
+ let next = lastItem.nextSibling;
41
+ // Check all items after last indented item, as long as their indent is bigger than indent of that item.
42
+ while (next && next.name == 'listItem' &&
43
+ next.getAttribute('listIndent') > lastItem.getAttribute('listIndent')) {
44
+ itemsToChange.push(next);
45
+ next = next.nextSibling;
46
+ }
47
+ // We need to be sure to keep model in correct state after each small change, because converters
48
+ // bases on that state and assumes that model is correct.
49
+ // Because of that, if the command outdents items, we will outdent them starting from the last item, as
50
+ // it is safer.
51
+ if (this._indentBy < 0) {
52
+ itemsToChange = itemsToChange.reverse();
53
+ }
54
+ for (const item of itemsToChange) {
55
+ const indent = item.getAttribute('listIndent') + this._indentBy;
56
+ // If indent is lower than 0, it means that the item got outdented when it was not indented.
57
+ // This means that we need to convert that list item to paragraph.
58
+ if (indent < 0) {
59
+ // To keep the model as correct as possible, first rename listItem, then remove attributes,
60
+ // as listItem without attributes is very incorrect and will cause problems in converters.
61
+ // No need to remove attributes, will be removed by post fixer.
62
+ writer.rename(item, 'paragraph');
63
+ }
64
+ // If indent is >= 0, change the attribute value.
65
+ else {
66
+ writer.setAttribute('listIndent', indent, item);
67
+ }
68
+ }
69
+ /**
70
+ * Event fired by the {@link #execute} method.
71
+ *
72
+ * It allows to execute an action after executing the {@link ~IndentCommand#execute} method, for example adjusting
73
+ * attributes of changed list items.
74
+ *
75
+ * @protected
76
+ * @event _executeCleanup
77
+ */
78
+ this.fire('_executeCleanup', itemsToChange);
79
+ });
80
+ }
81
+ /**
82
+ * Checks whether the command can be enabled in the current context.
83
+ *
84
+ * @returns Whether the command should be enabled.
85
+ */
86
+ _checkEnabled() {
87
+ // Check whether any of position's ancestor is a list item.
88
+ const listItem = first(this.editor.model.document.selection.getSelectedBlocks());
89
+ // If selection is not in a list item, the command is disabled.
90
+ if (!listItem || !listItem.is('element', 'listItem')) {
91
+ return false;
92
+ }
93
+ if (this._indentBy > 0) {
94
+ // Cannot indent first item in it's list. Check if before `listItem` is a list item that is in same list.
95
+ // To be in the same list, the item has to have same attributes and cannot be "split" by an item with lower indent.
96
+ const indent = listItem.getAttribute('listIndent');
97
+ const type = listItem.getAttribute('listType');
98
+ let prev = listItem.previousSibling;
99
+ while (prev && prev.is('element', 'listItem') && prev.getAttribute('listIndent') >= indent) {
100
+ if (prev.getAttribute('listIndent') == indent) {
101
+ // The item is on the same level.
102
+ // If it has same type, it means that we found a preceding sibling from the same list.
103
+ // If it does not have same type, it means that `listItem` is on different list (this can happen only
104
+ // on top level lists, though).
105
+ return prev.getAttribute('listType') == type;
106
+ }
107
+ prev = prev.previousSibling;
108
+ }
109
+ // Could not find similar list item, this means that `listItem` is first in its list.
110
+ return false;
111
+ }
112
+ // If we are outdenting it is enough to be in list item. Every list item can always be outdented.
113
+ return true;
114
+ }
150
115
  }