@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.
- 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 -697
- 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 +41 -0
- package/src/documentlist/utils/listwalker.js +138 -236
- package/src/documentlist/utils/model.js +322 -421
- package/src/documentlist/utils/postfixers.js +98 -118
- 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 +266 -354
- package/src/documentlistproperties/documentlistpropertiesutils.js +44 -0
- 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 +4 -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 +142 -200
- package/src/list/listui.js +16 -25
- package/src/list/listutils.js +46 -0
- 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 -801
- 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 -414
- 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
- package/build/list.js.map +0 -1
|
@@ -1,150 +1,115 @@
|
|
|
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
|
-
/**
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
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
|
}
|