@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.
- package/LICENSE.md +1 -1
- package/build/list.js +2 -2
- package/package.json +43 -39
- package/src/documentlist/converters.js +303 -419
- package/src/documentlist/documentlistcommand.js +136 -207
- package/src/documentlist/documentlistediting.js +538 -698
- package/src/documentlist/documentlistindentcommand.js +115 -168
- package/src/documentlist/documentlistmergecommand.js +161 -222
- package/src/documentlist/documentlistsplitcommand.js +59 -103
- package/src/documentlist/documentlistutils.js +31 -45
- package/src/documentlist/utils/listwalker.js +138 -236
- package/src/documentlist/utils/model.js +322 -421
- package/src/documentlist/utils/postfixers.js +98 -126
- package/src/documentlist/utils/view.js +74 -105
- package/src/documentlist.js +13 -19
- package/src/documentlistproperties/converters.js +33 -47
- package/src/documentlistproperties/documentlistpropertiesediting.js +265 -356
- package/src/documentlistproperties/documentlistpropertiesutils.js +32 -57
- package/src/documentlistproperties/documentlistreversedcommand.js +40 -61
- package/src/documentlistproperties/documentliststartcommand.js +42 -61
- package/src/documentlistproperties/documentliststylecommand.js +97 -147
- package/src/documentlistproperties/utils/style.js +27 -47
- package/src/documentlistproperties.js +13 -19
- package/src/index.js +1 -3
- package/src/list/converters.js +772 -929
- package/src/list/indentcommand.js +105 -140
- package/src/list/listcommand.js +262 -315
- package/src/list/listediting.js +141 -200
- package/src/list/listui.js +16 -25
- package/src/list/listutils.js +37 -59
- package/src/list/utils.js +295 -378
- package/src/list.js +13 -44
- package/src/listcommands.js +5 -0
- package/src/listconfig.js +5 -0
- package/src/listproperties/listpropertiesediting.js +656 -803
- package/src/listproperties/listpropertiesui.js +244 -296
- package/src/listproperties/listreversedcommand.js +37 -49
- package/src/listproperties/liststartcommand.js +37 -49
- package/src/listproperties/liststylecommand.js +82 -115
- package/src/listproperties/ui/collapsibleview.js +75 -138
- package/src/listproperties/ui/listpropertiesview.js +289 -415
- package/src/listproperties.js +13 -118
- package/src/liststyle.js +18 -24
- package/src/todolist/checktodolistcommand.js +60 -102
- package/src/todolist/todolistconverters.js +189 -271
- package/src/todolist/todolistediting.js +141 -206
- package/src/todolist/todolistui.js +14 -21
- package/src/todolist.js +13 -19
- package/theme/collapsible.css +1 -1
- package/theme/documentlist.css +1 -1
- package/theme/list.css +40 -0
- package/theme/listproperties.css +1 -1
- package/theme/liststyles.css +1 -37
- package/theme/todolist.css +1 -1
|
@@ -1,182 +1,129 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|