@ckeditor/ckeditor5-list 35.4.0 → 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 (54) 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 -698
  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 +31 -45
  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 -126
  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 +265 -356
  18. package/src/documentlistproperties/documentlistpropertiesutils.js +32 -57
  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 +1 -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 +141 -200
  29. package/src/list/listui.js +16 -25
  30. package/src/list/listutils.js +37 -59
  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 -803
  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 -415
  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
@@ -1,182 +1,129 @@
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
5
  /**
7
6
  * @module list/documentlist/documentlistindentcommand
8
7
  */
9
-
10
8
  import { Command } from 'ckeditor5/src/core';
11
- import {
12
- expandListBlocksToCompleteItems,
13
- indentBlocks,
14
- isFirstBlockOfListItem,
15
- isListItemBlock,
16
- isSingleListItem,
17
- outdentBlocksWithMerge,
18
- sortBlocks,
19
- splitListItemBefore
20
- } from './utils/model';
9
+ import { expandListBlocksToCompleteItems, indentBlocks, isFirstBlockOfListItem, isListItemBlock, isSingleListItem, outdentBlocksWithMerge, sortBlocks, splitListItemBefore } from './utils/model';
21
10
  import ListWalker from './utils/listwalker';
22
-
23
11
  /**
24
12
  * The document list indent command. It is used by the {@link module:list/documentlist~DocumentList list feature}.
25
- *
26
- * @extends module:core/command~Command
27
13
  */
28
14
  export default class DocumentListIndentCommand extends Command {
29
- /**
30
- * Creates an instance of the command.
31
- *
32
- * @param {module:core/editor/editor~Editor} editor The editor instance.
33
- * @param {'forward'|'backward'} indentDirection The direction of indent. If it is equal to `backward`, the command
34
- * will outdent a list item.
35
- */
36
- constructor( editor, indentDirection ) {
37
- super( editor );
38
-
39
- /**
40
- * Determines by how much the command will change the list item's indent attribute.
41
- *
42
- * @readonly
43
- * @private
44
- * @member {'forward'|'backward'}
45
- */
46
- this._direction = indentDirection;
47
- }
48
-
49
- /**
50
- * @inheritDoc
51
- */
52
- refresh() {
53
- this.isEnabled = this._checkEnabled();
54
- }
55
-
56
- /**
57
- * Indents or outdents (depending on the {@link #constructor}'s `indentDirection` parameter) selected list items.
58
- *
59
- * @fires execute
60
- * @fires afterExecute
61
- */
62
- execute() {
63
- const model = this.editor.model;
64
- const blocks = getSelectedListBlocks( model.document.selection );
65
-
66
- model.change( writer => {
67
- const changedBlocks = [];
68
-
69
- // Handle selection contained in the single list item and starting in the following blocks.
70
- if ( isSingleListItem( blocks ) && !isFirstBlockOfListItem( blocks[ 0 ] ) ) {
71
- // Allow increasing indent of following list item blocks.
72
- if ( this._direction == 'forward' ) {
73
- changedBlocks.push( ...indentBlocks( blocks, writer ) );
74
- }
75
-
76
- // For indent make sure that indented blocks have a new ID.
77
- // For outdent just split blocks from the list item (give them a new IDs).
78
- changedBlocks.push( ...splitListItemBefore( blocks[ 0 ], writer ) );
79
- }
80
- // More than a single list item is selected, or the first block of list item is selected.
81
- else {
82
- // Now just update the attributes of blocks.
83
- if ( this._direction == 'forward' ) {
84
- changedBlocks.push( ...indentBlocks( blocks, writer, { expand: true } ) );
85
- } else {
86
- changedBlocks.push( ...outdentBlocksWithMerge( blocks, writer ) );
87
- }
88
- }
89
-
90
- // Align the list item type to match the previous list item (from the same list).
91
- for ( const block of changedBlocks ) {
92
- // This block become a plain block (for example a paragraph).
93
- if ( !block.hasAttribute( 'listType' ) ) {
94
- continue;
95
- }
96
-
97
- const previousItemBlock = ListWalker.first( block, { sameIndent: true } );
98
-
99
- if ( previousItemBlock ) {
100
- writer.setAttribute( 'listType', previousItemBlock.getAttribute( 'listType' ), block );
101
- }
102
- }
103
-
104
- this._fireAfterExecute( changedBlocks );
105
- } );
106
- }
107
-
108
- /**
109
- * Fires the `afterExecute` event.
110
- *
111
- * @private
112
- * @param {Array.<module:engine/model/element~Element>} changedBlocks The changed list elements.
113
- */
114
- _fireAfterExecute( changedBlocks ) {
115
- /**
116
- * Event fired by the {@link #execute} method.
117
- *
118
- * It allows to execute an action after executing the {@link ~DocumentListIndentCommand#execute} method,
119
- * for example adjusting attributes of changed list items.
120
- *
121
- * @protected
122
- * @event afterExecute
123
- */
124
- this.fire( 'afterExecute', sortBlocks( new Set( changedBlocks ) ) );
125
- }
126
-
127
- /**
128
- * Checks whether the command can be enabled in the current context.
129
- *
130
- * @private
131
- * @returns {Boolean} Whether the command should be enabled.
132
- */
133
- _checkEnabled() {
134
- // Check whether any of position's ancestor is a list item.
135
- let blocks = getSelectedListBlocks( this.editor.model.document.selection );
136
- let firstBlock = blocks[ 0 ];
137
-
138
- // If selection is not in a list item, the command is disabled.
139
- if ( !firstBlock ) {
140
- return false;
141
- }
142
-
143
- // If we are outdenting it is enough to be in list item. Every list item can always be outdented.
144
- if ( this._direction == 'backward' ) {
145
- return true;
146
- }
147
-
148
- // A single block of a list item is selected, so it could be indented as a sublist.
149
- if ( isSingleListItem( blocks ) && !isFirstBlockOfListItem( blocks[ 0 ] ) ) {
150
- return true;
151
- }
152
-
153
- blocks = expandListBlocksToCompleteItems( blocks );
154
- firstBlock = blocks[ 0 ];
155
-
156
- // Check if there is any list item before selected items that could become a parent of selected items.
157
- const siblingItem = ListWalker.first( firstBlock, { sameIndent: true } );
158
-
159
- if ( !siblingItem ) {
160
- return false;
161
- }
162
-
163
- if ( siblingItem.getAttribute( 'listType' ) == firstBlock.getAttribute( 'listType' ) ) {
164
- return true;
165
- }
166
-
167
- return false;
168
- }
15
+ /**
16
+ * Creates an instance of the command.
17
+ *
18
+ * @param editor The editor instance.
19
+ * @param indentDirection The direction of indent. If it is equal to `backward`, the command
20
+ * will outdent a list item.
21
+ */
22
+ constructor(editor, indentDirection) {
23
+ super(editor);
24
+ this._direction = indentDirection;
25
+ }
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ refresh() {
30
+ this.isEnabled = this._checkEnabled();
31
+ }
32
+ /**
33
+ * Indents or outdents (depending on the {@link #constructor}'s `indentDirection` parameter) selected list items.
34
+ *
35
+ * @fires execute
36
+ * @fires afterExecute
37
+ */
38
+ execute() {
39
+ const model = this.editor.model;
40
+ const blocks = getSelectedListBlocks(model.document.selection);
41
+ model.change(writer => {
42
+ const changedBlocks = [];
43
+ // Handle selection contained in the single list item and starting in the following blocks.
44
+ if (isSingleListItem(blocks) && !isFirstBlockOfListItem(blocks[0])) {
45
+ // Allow increasing indent of following list item blocks.
46
+ if (this._direction == 'forward') {
47
+ changedBlocks.push(...indentBlocks(blocks, writer));
48
+ }
49
+ // For indent make sure that indented blocks have a new ID.
50
+ // For outdent just split blocks from the list item (give them a new IDs).
51
+ changedBlocks.push(...splitListItemBefore(blocks[0], writer));
52
+ }
53
+ // More than a single list item is selected, or the first block of list item is selected.
54
+ else {
55
+ // Now just update the attributes of blocks.
56
+ if (this._direction == 'forward') {
57
+ changedBlocks.push(...indentBlocks(blocks, writer, { expand: true }));
58
+ }
59
+ else {
60
+ changedBlocks.push(...outdentBlocksWithMerge(blocks, writer));
61
+ }
62
+ }
63
+ // Align the list item type to match the previous list item (from the same list).
64
+ for (const block of changedBlocks) {
65
+ // This block become a plain block (for example a paragraph).
66
+ if (!block.hasAttribute('listType')) {
67
+ continue;
68
+ }
69
+ const previousItemBlock = ListWalker.first(block, { sameIndent: true });
70
+ if (previousItemBlock) {
71
+ writer.setAttribute('listType', previousItemBlock.getAttribute('listType'), block);
72
+ }
73
+ }
74
+ this._fireAfterExecute(changedBlocks);
75
+ });
76
+ }
77
+ /**
78
+ * Fires the `afterExecute` event.
79
+ *
80
+ * @param changedBlocks The changed list elements.
81
+ */
82
+ _fireAfterExecute(changedBlocks) {
83
+ this.fire('afterExecute', sortBlocks(new Set(changedBlocks)));
84
+ }
85
+ /**
86
+ * Checks whether the command can be enabled in the current context.
87
+ *
88
+ * @returns Whether the command should be enabled.
89
+ */
90
+ _checkEnabled() {
91
+ // Check whether any of position's ancestor is a list item.
92
+ let blocks = getSelectedListBlocks(this.editor.model.document.selection);
93
+ let firstBlock = blocks[0];
94
+ // If selection is not in a list item, the command is disabled.
95
+ if (!firstBlock) {
96
+ return false;
97
+ }
98
+ // If we are outdenting it is enough to be in list item. Every list item can always be outdented.
99
+ if (this._direction == 'backward') {
100
+ return true;
101
+ }
102
+ // A single block of a list item is selected, so it could be indented as a sublist.
103
+ if (isSingleListItem(blocks) && !isFirstBlockOfListItem(blocks[0])) {
104
+ return true;
105
+ }
106
+ blocks = expandListBlocksToCompleteItems(blocks);
107
+ firstBlock = blocks[0];
108
+ // Check if there is any list item before selected items that could become a parent of selected items.
109
+ const siblingItem = ListWalker.first(firstBlock, { sameIndent: true });
110
+ if (!siblingItem) {
111
+ return false;
112
+ }
113
+ if (siblingItem.getAttribute('listType') == firstBlock.getAttribute('listType')) {
114
+ return true;
115
+ }
116
+ return false;
117
+ }
169
118
  }
170
-
171
- // Returns an array of selected blocks truncated to the first non list block element.
172
- function getSelectedListBlocks( selection ) {
173
- const blocks = Array.from( selection.getSelectedBlocks() );
174
- const firstNonListBlockIndex = blocks.findIndex( block => !isListItemBlock( block ) );
175
-
176
- if ( firstNonListBlockIndex != -1 ) {
177
- blocks.length = firstNonListBlockIndex;
178
- }
179
-
180
- return blocks;
119
+ /**
120
+ * Returns an array of selected blocks truncated to the first non list block element.
121
+ */
122
+ function getSelectedListBlocks(selection) {
123
+ const blocks = Array.from(selection.getSelectedBlocks());
124
+ const firstNonListBlockIndex = blocks.findIndex(block => !isListItemBlock(block));
125
+ if (firstNonListBlockIndex != -1) {
126
+ blocks.length = firstNonListBlockIndex;
127
+ }
128
+ return blocks;
181
129
  }
182
-