@ckeditor/ckeditor5-list 40.0.0 → 40.2.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/CHANGELOG.md +25 -25
- package/LICENSE.md +2 -2
- package/build/list.js +1 -1
- package/build/translations/ug.js +1 -1
- package/lang/translations/ug.po +3 -3
- package/package.json +2 -3
- package/src/augmentation.d.ts +52 -52
- package/src/augmentation.js +5 -5
- package/src/documentlist/adjacentlistssupport.d.ts +15 -15
- package/src/documentlist/adjacentlistssupport.js +81 -81
- package/src/documentlist/converters.d.ts +65 -65
- package/src/documentlist/converters.js +441 -441
- package/src/documentlist/documentlistcommand.d.ts +80 -80
- package/src/documentlist/documentlistcommand.js +150 -150
- package/src/documentlist/documentlistediting.d.ts +212 -212
- package/src/documentlist/documentlistediting.js +646 -645
- package/src/documentlist/documentlistindentcommand.d.ts +62 -62
- package/src/documentlist/documentlistindentcommand.js +129 -129
- package/src/documentlist/documentlistmergecommand.d.ts +76 -76
- package/src/documentlist/documentlistmergecommand.js +174 -174
- package/src/documentlist/documentlistsplitcommand.d.ts +67 -67
- package/src/documentlist/documentlistsplitcommand.js +70 -70
- package/src/documentlist/documentlistutils.d.ts +46 -46
- package/src/documentlist/documentlistutils.js +50 -50
- package/src/documentlist/utils/listwalker.d.ts +145 -145
- package/src/documentlist/utils/listwalker.js +182 -182
- package/src/documentlist/utils/model.d.ts +202 -202
- package/src/documentlist/utils/model.js +455 -455
- package/src/documentlist/utils/postfixers.d.ts +37 -37
- package/src/documentlist/utils/postfixers.js +126 -126
- package/src/documentlist/utils/view.d.ts +81 -81
- package/src/documentlist/utils/view.js +117 -117
- package/src/documentlist.d.ts +26 -26
- package/src/documentlist.js +30 -30
- package/src/documentlistproperties/converters.d.ts +19 -19
- package/src/documentlistproperties/converters.js +43 -43
- package/src/documentlistproperties/documentlistpropertiesediting.d.ts +88 -88
- package/src/documentlistproperties/documentlistpropertiesediting.js +266 -266
- package/src/documentlistproperties/documentlistpropertiesutils.d.ts +33 -33
- package/src/documentlistproperties/documentlistpropertiesutils.js +44 -44
- package/src/documentlistproperties/documentlistreversedcommand.d.ts +36 -36
- package/src/documentlistproperties/documentlistreversedcommand.js +55 -55
- package/src/documentlistproperties/documentliststartcommand.d.ts +38 -38
- package/src/documentlistproperties/documentliststartcommand.js +57 -57
- package/src/documentlistproperties/documentliststylecommand.d.ts +72 -72
- package/src/documentlistproperties/documentliststylecommand.js +113 -113
- package/src/documentlistproperties/utils/style.d.ts +20 -20
- package/src/documentlistproperties/utils/style.js +54 -54
- package/src/documentlistproperties.d.ts +27 -27
- package/src/documentlistproperties.js +31 -31
- package/src/index.d.ts +43 -43
- package/src/index.js +29 -29
- package/src/list/converters.d.ts +196 -196
- package/src/list/converters.js +905 -905
- package/src/list/indentcommand.d.ts +37 -37
- package/src/list/indentcommand.js +107 -107
- package/src/list/listcommand.d.ts +55 -55
- package/src/list/listcommand.js +274 -274
- package/src/list/listediting.d.ts +32 -32
- package/src/list/listediting.js +161 -161
- package/src/list/listui.d.ts +19 -19
- package/src/list/listui.js +32 -32
- package/src/list/listutils.d.ts +41 -41
- package/src/list/listutils.js +46 -46
- package/src/list/utils.d.ts +112 -112
- package/src/list/utils.js +374 -374
- package/src/list.d.ts +26 -26
- package/src/list.js +30 -30
- package/src/listconfig.d.ts +132 -132
- package/src/listconfig.js +5 -5
- package/src/listproperties/listpropertiesediting.d.ts +72 -72
- package/src/listproperties/listpropertiesediting.js +696 -696
- package/src/listproperties/listpropertiesui.d.ts +23 -23
- package/src/listproperties/listpropertiesui.js +277 -277
- package/src/listproperties/listreversedcommand.d.ts +38 -38
- package/src/listproperties/listreversedcommand.js +52 -52
- package/src/listproperties/liststartcommand.d.ts +37 -37
- package/src/listproperties/liststartcommand.js +51 -51
- package/src/listproperties/liststylecommand.d.ts +67 -67
- package/src/listproperties/liststylecommand.js +99 -99
- package/src/listproperties/ui/listpropertiesview.d.ts +156 -157
- package/src/listproperties/ui/listpropertiesview.js +298 -299
- package/src/listproperties.d.ts +26 -26
- package/src/listproperties.js +30 -30
- package/src/liststyle.d.ts +28 -28
- package/src/liststyle.js +36 -36
- package/src/tododocumentlist/checktododocumentlistcommand.d.ts +49 -49
- package/src/tododocumentlist/checktododocumentlistcommand.js +82 -82
- package/src/tododocumentlist/todocheckboxchangeobserver.d.ts +41 -41
- package/src/tododocumentlist/todocheckboxchangeobserver.js +37 -37
- package/src/tododocumentlist/tododocumentlistediting.d.ts +38 -38
- package/src/tododocumentlist/tododocumentlistediting.js +399 -399
- package/src/tododocumentlist.d.ts +27 -27
- package/src/tododocumentlist.js +31 -31
- package/src/todolist/checktodolistcommand.d.ts +52 -52
- package/src/todolist/checktodolistcommand.js +76 -76
- package/src/todolist/todolistconverters.d.ts +82 -82
- package/src/todolist/todolistconverters.js +260 -260
- package/src/todolist/todolistediting.d.ts +39 -39
- package/src/todolist/todolistediting.js +161 -161
- package/src/todolist/todolistui.d.ts +19 -19
- package/src/todolist/todolistui.js +29 -29
- package/src/todolist.d.ts +27 -27
- package/src/todolist.js +31 -31
- package/build/list.js.map +0 -1
- package/src/listproperties/ui/collapsibleview.d.ts +0 -63
- package/src/listproperties/ui/collapsibleview.js +0 -89
- package/theme/collapsible.css +0 -10
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/documentlist/documentlistcommand
|
|
7
|
-
*/
|
|
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 {
|
|
14
|
-
/**
|
|
15
|
-
* The type of the list created by the command.
|
|
16
|
-
*/
|
|
17
|
-
readonly type: 'numbered' | 'bulleted' | 'todo';
|
|
18
|
-
/**
|
|
19
|
-
* A flag indicating whether the command is active, which means that the selection starts in a list of the same type.
|
|
20
|
-
*
|
|
21
|
-
* @observable
|
|
22
|
-
* @readonly
|
|
23
|
-
*/
|
|
24
|
-
value: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Creates an instance of the command.
|
|
27
|
-
*
|
|
28
|
-
* @param editor The editor instance.
|
|
29
|
-
* @param type List type that will be handled by this command.
|
|
30
|
-
*/
|
|
31
|
-
constructor(editor: Editor, type: 'numbered' | 'bulleted' | 'todo');
|
|
32
|
-
/**
|
|
33
|
-
* @inheritDoc
|
|
34
|
-
*/
|
|
35
|
-
refresh(): void;
|
|
36
|
-
/**
|
|
37
|
-
* Executes the list command.
|
|
38
|
-
*
|
|
39
|
-
* @fires execute
|
|
40
|
-
* @fires afterExecute
|
|
41
|
-
* @param options Command options.
|
|
42
|
-
* @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
|
|
44
|
-
* to paragraphs. If not set, the command will toggle selected elements to list items or paragraphs, depending on the selection.
|
|
45
|
-
*/
|
|
46
|
-
execute(options?: {
|
|
47
|
-
forceValue?: boolean;
|
|
48
|
-
}): void;
|
|
49
|
-
/**
|
|
50
|
-
* Fires the `afterExecute` event.
|
|
51
|
-
*
|
|
52
|
-
* @param changedBlocks The changed list elements.
|
|
53
|
-
*/
|
|
54
|
-
private _fireAfterExecute;
|
|
55
|
-
/**
|
|
56
|
-
* Checks the command's {@link #value}.
|
|
57
|
-
*
|
|
58
|
-
* @returns The current value.
|
|
59
|
-
*/
|
|
60
|
-
private _getValue;
|
|
61
|
-
/**
|
|
62
|
-
* Checks whether the command can be enabled in the current context.
|
|
63
|
-
*
|
|
64
|
-
* @returns Whether the command should be enabled.
|
|
65
|
-
*/
|
|
66
|
-
private _checkEnabled;
|
|
67
|
-
}
|
|
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
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/documentlist/documentlistcommand
|
|
7
|
+
*/
|
|
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 {
|
|
14
|
+
/**
|
|
15
|
+
* The type of the list created by the command.
|
|
16
|
+
*/
|
|
17
|
+
readonly type: 'numbered' | 'bulleted' | 'todo';
|
|
18
|
+
/**
|
|
19
|
+
* A flag indicating whether the command is active, which means that the selection starts in a list of the same type.
|
|
20
|
+
*
|
|
21
|
+
* @observable
|
|
22
|
+
* @readonly
|
|
23
|
+
*/
|
|
24
|
+
value: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Creates an instance of the command.
|
|
27
|
+
*
|
|
28
|
+
* @param editor The editor instance.
|
|
29
|
+
* @param type List type that will be handled by this command.
|
|
30
|
+
*/
|
|
31
|
+
constructor(editor: Editor, type: 'numbered' | 'bulleted' | 'todo');
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
refresh(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Executes the list command.
|
|
38
|
+
*
|
|
39
|
+
* @fires execute
|
|
40
|
+
* @fires afterExecute
|
|
41
|
+
* @param options Command options.
|
|
42
|
+
* @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
|
|
44
|
+
* to paragraphs. If not set, the command will toggle selected elements to list items or paragraphs, depending on the selection.
|
|
45
|
+
*/
|
|
46
|
+
execute(options?: {
|
|
47
|
+
forceValue?: boolean;
|
|
48
|
+
}): void;
|
|
49
|
+
/**
|
|
50
|
+
* Fires the `afterExecute` event.
|
|
51
|
+
*
|
|
52
|
+
* @param changedBlocks The changed list elements.
|
|
53
|
+
*/
|
|
54
|
+
private _fireAfterExecute;
|
|
55
|
+
/**
|
|
56
|
+
* Checks the command's {@link #value}.
|
|
57
|
+
*
|
|
58
|
+
* @returns The current value.
|
|
59
|
+
*/
|
|
60
|
+
private _getValue;
|
|
61
|
+
/**
|
|
62
|
+
* Checks whether the command can be enabled in the current context.
|
|
63
|
+
*
|
|
64
|
+
* @returns Whether the command should be enabled.
|
|
65
|
+
*/
|
|
66
|
+
private _checkEnabled;
|
|
67
|
+
}
|
|
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
|
+
};
|
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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';
|
|
6
|
-
import { splitListItemBefore, expandListBlocksToCompleteItems, getListItemBlocks, getListItems, removeListAttributes, outdentFollowingItems, ListItemUid, sortBlocks, getSelectedBlockObject, isListItemBlock, canBecomeSimpleListItem } from './utils/model';
|
|
7
|
-
/**
|
|
8
|
-
* The list command. It is used by the {@link module:list/documentlist~DocumentList document list feature}.
|
|
9
|
-
*/
|
|
10
|
-
export default class DocumentListCommand 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
|
-
* @fires afterExecute
|
|
33
|
-
* @param options Command options.
|
|
34
|
-
* @param options.forceValue If set, it will force the command behavior. If `true`, the command will try to convert the
|
|
35
|
-
* selected items and potentially the neighbor elements to the proper list items. If set to `false` it will convert selected elements
|
|
36
|
-
* to paragraphs. If not set, the command will toggle selected elements to list items or paragraphs, depending on the selection.
|
|
37
|
-
*/
|
|
38
|
-
execute(options = {}) {
|
|
39
|
-
const model = this.editor.model;
|
|
40
|
-
const document = model.document;
|
|
41
|
-
const selectedBlockObject = getSelectedBlockObject(model);
|
|
42
|
-
const blocks = Array.from(document.selection.getSelectedBlocks())
|
|
43
|
-
.filter(block => model.schema.checkAttribute(block, 'listType') || canBecomeSimpleListItem(block, model.schema));
|
|
44
|
-
// Whether we are turning off some items.
|
|
45
|
-
const turnOff = options.forceValue !== undefined ? !options.forceValue : this.value;
|
|
46
|
-
model.change(writer => {
|
|
47
|
-
if (turnOff) {
|
|
48
|
-
const lastBlock = blocks[blocks.length - 1];
|
|
49
|
-
// Split the first block from the list item.
|
|
50
|
-
const itemBlocks = getListItemBlocks(lastBlock, { direction: 'forward' });
|
|
51
|
-
const changedBlocks = [];
|
|
52
|
-
if (itemBlocks.length > 1) {
|
|
53
|
-
changedBlocks.push(...splitListItemBefore(itemBlocks[1], writer));
|
|
54
|
-
}
|
|
55
|
-
// Strip list attributes.
|
|
56
|
-
changedBlocks.push(...removeListAttributes(blocks, writer));
|
|
57
|
-
// Outdent items following the selected list item.
|
|
58
|
-
changedBlocks.push(...outdentFollowingItems(lastBlock, writer));
|
|
59
|
-
this._fireAfterExecute(changedBlocks);
|
|
60
|
-
}
|
|
61
|
-
// Changing type of list items for a collapsed selection inside a list item.
|
|
62
|
-
else if ((selectedBlockObject || document.selection.isCollapsed) && isListItemBlock(blocks[0])) {
|
|
63
|
-
const changedBlocks = getListItems(selectedBlockObject || blocks[0]);
|
|
64
|
-
for (const block of changedBlocks) {
|
|
65
|
-
writer.setAttribute('listType', this.type, block);
|
|
66
|
-
}
|
|
67
|
-
this._fireAfterExecute(changedBlocks);
|
|
68
|
-
}
|
|
69
|
-
// Turning on the list items for a non-collapsed selection.
|
|
70
|
-
else {
|
|
71
|
-
const changedBlocks = [];
|
|
72
|
-
for (const block of blocks) {
|
|
73
|
-
// Promote the given block to the list item.
|
|
74
|
-
if (!block.hasAttribute('listType')) {
|
|
75
|
-
// Rename block to a simple list item if this option is enabled.
|
|
76
|
-
if (!block.is('element', 'listItem') && canBecomeSimpleListItem(block, model.schema)) {
|
|
77
|
-
writer.rename(block, 'listItem');
|
|
78
|
-
}
|
|
79
|
-
writer.setAttributes({
|
|
80
|
-
listIndent: 0,
|
|
81
|
-
listItemId: ListItemUid.next(),
|
|
82
|
-
listType: this.type
|
|
83
|
-
}, block);
|
|
84
|
-
changedBlocks.push(block);
|
|
85
|
-
}
|
|
86
|
-
// Change the type of list item.
|
|
87
|
-
else {
|
|
88
|
-
for (const node of expandListBlocksToCompleteItems(block, { withNested: false })) {
|
|
89
|
-
if (node.getAttribute('listType') != this.type) {
|
|
90
|
-
writer.setAttribute('listType', this.type, node);
|
|
91
|
-
changedBlocks.push(node);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
this._fireAfterExecute(changedBlocks);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Fires the `afterExecute` event.
|
|
102
|
-
*
|
|
103
|
-
* @param changedBlocks The changed list elements.
|
|
104
|
-
*/
|
|
105
|
-
_fireAfterExecute(changedBlocks) {
|
|
106
|
-
this.fire('afterExecute', sortBlocks(new Set(changedBlocks)));
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Checks the command's {@link #value}.
|
|
110
|
-
*
|
|
111
|
-
* @returns The current value.
|
|
112
|
-
*/
|
|
113
|
-
_getValue() {
|
|
114
|
-
const selection = this.editor.model.document.selection;
|
|
115
|
-
const blocks = Array.from(selection.getSelectedBlocks());
|
|
116
|
-
if (!blocks.length) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
for (const block of blocks) {
|
|
120
|
-
if (block.getAttribute('listType') != this.type) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Checks whether the command can be enabled in the current context.
|
|
128
|
-
*
|
|
129
|
-
* @returns Whether the command should be enabled.
|
|
130
|
-
*/
|
|
131
|
-
_checkEnabled() {
|
|
132
|
-
const model = this.editor.model;
|
|
133
|
-
const schema = model.schema;
|
|
134
|
-
const selection = model.document.selection;
|
|
135
|
-
const blocks = Array.from(selection.getSelectedBlocks());
|
|
136
|
-
if (!blocks.length) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
// If command value is true it means that we are in list item, so the command should be enabled.
|
|
140
|
-
if (this.value) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
for (const block of blocks) {
|
|
144
|
-
if (schema.checkAttribute(block, 'listType') || canBecomeSimpleListItem(block, schema)) {
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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';
|
|
6
|
+
import { splitListItemBefore, expandListBlocksToCompleteItems, getListItemBlocks, getListItems, removeListAttributes, outdentFollowingItems, ListItemUid, sortBlocks, getSelectedBlockObject, isListItemBlock, canBecomeSimpleListItem } from './utils/model';
|
|
7
|
+
/**
|
|
8
|
+
* The list command. It is used by the {@link module:list/documentlist~DocumentList document list feature}.
|
|
9
|
+
*/
|
|
10
|
+
export default class DocumentListCommand 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
|
+
* @fires afterExecute
|
|
33
|
+
* @param options Command options.
|
|
34
|
+
* @param options.forceValue If set, it will force the command behavior. If `true`, the command will try to convert the
|
|
35
|
+
* selected items and potentially the neighbor elements to the proper list items. If set to `false` it will convert selected elements
|
|
36
|
+
* to paragraphs. If not set, the command will toggle selected elements to list items or paragraphs, depending on the selection.
|
|
37
|
+
*/
|
|
38
|
+
execute(options = {}) {
|
|
39
|
+
const model = this.editor.model;
|
|
40
|
+
const document = model.document;
|
|
41
|
+
const selectedBlockObject = getSelectedBlockObject(model);
|
|
42
|
+
const blocks = Array.from(document.selection.getSelectedBlocks())
|
|
43
|
+
.filter(block => model.schema.checkAttribute(block, 'listType') || canBecomeSimpleListItem(block, model.schema));
|
|
44
|
+
// Whether we are turning off some items.
|
|
45
|
+
const turnOff = options.forceValue !== undefined ? !options.forceValue : this.value;
|
|
46
|
+
model.change(writer => {
|
|
47
|
+
if (turnOff) {
|
|
48
|
+
const lastBlock = blocks[blocks.length - 1];
|
|
49
|
+
// Split the first block from the list item.
|
|
50
|
+
const itemBlocks = getListItemBlocks(lastBlock, { direction: 'forward' });
|
|
51
|
+
const changedBlocks = [];
|
|
52
|
+
if (itemBlocks.length > 1) {
|
|
53
|
+
changedBlocks.push(...splitListItemBefore(itemBlocks[1], writer));
|
|
54
|
+
}
|
|
55
|
+
// Strip list attributes.
|
|
56
|
+
changedBlocks.push(...removeListAttributes(blocks, writer));
|
|
57
|
+
// Outdent items following the selected list item.
|
|
58
|
+
changedBlocks.push(...outdentFollowingItems(lastBlock, writer));
|
|
59
|
+
this._fireAfterExecute(changedBlocks);
|
|
60
|
+
}
|
|
61
|
+
// Changing type of list items for a collapsed selection inside a list item.
|
|
62
|
+
else if ((selectedBlockObject || document.selection.isCollapsed) && isListItemBlock(blocks[0])) {
|
|
63
|
+
const changedBlocks = getListItems(selectedBlockObject || blocks[0]);
|
|
64
|
+
for (const block of changedBlocks) {
|
|
65
|
+
writer.setAttribute('listType', this.type, block);
|
|
66
|
+
}
|
|
67
|
+
this._fireAfterExecute(changedBlocks);
|
|
68
|
+
}
|
|
69
|
+
// Turning on the list items for a non-collapsed selection.
|
|
70
|
+
else {
|
|
71
|
+
const changedBlocks = [];
|
|
72
|
+
for (const block of blocks) {
|
|
73
|
+
// Promote the given block to the list item.
|
|
74
|
+
if (!block.hasAttribute('listType')) {
|
|
75
|
+
// Rename block to a simple list item if this option is enabled.
|
|
76
|
+
if (!block.is('element', 'listItem') && canBecomeSimpleListItem(block, model.schema)) {
|
|
77
|
+
writer.rename(block, 'listItem');
|
|
78
|
+
}
|
|
79
|
+
writer.setAttributes({
|
|
80
|
+
listIndent: 0,
|
|
81
|
+
listItemId: ListItemUid.next(),
|
|
82
|
+
listType: this.type
|
|
83
|
+
}, block);
|
|
84
|
+
changedBlocks.push(block);
|
|
85
|
+
}
|
|
86
|
+
// Change the type of list item.
|
|
87
|
+
else {
|
|
88
|
+
for (const node of expandListBlocksToCompleteItems(block, { withNested: false })) {
|
|
89
|
+
if (node.getAttribute('listType') != this.type) {
|
|
90
|
+
writer.setAttribute('listType', this.type, node);
|
|
91
|
+
changedBlocks.push(node);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
this._fireAfterExecute(changedBlocks);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Fires the `afterExecute` event.
|
|
102
|
+
*
|
|
103
|
+
* @param changedBlocks The changed list elements.
|
|
104
|
+
*/
|
|
105
|
+
_fireAfterExecute(changedBlocks) {
|
|
106
|
+
this.fire('afterExecute', sortBlocks(new Set(changedBlocks)));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Checks the command's {@link #value}.
|
|
110
|
+
*
|
|
111
|
+
* @returns The current value.
|
|
112
|
+
*/
|
|
113
|
+
_getValue() {
|
|
114
|
+
const selection = this.editor.model.document.selection;
|
|
115
|
+
const blocks = Array.from(selection.getSelectedBlocks());
|
|
116
|
+
if (!blocks.length) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
for (const block of blocks) {
|
|
120
|
+
if (block.getAttribute('listType') != this.type) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks whether the command can be enabled in the current context.
|
|
128
|
+
*
|
|
129
|
+
* @returns Whether the command should be enabled.
|
|
130
|
+
*/
|
|
131
|
+
_checkEnabled() {
|
|
132
|
+
const model = this.editor.model;
|
|
133
|
+
const schema = model.schema;
|
|
134
|
+
const selection = model.document.selection;
|
|
135
|
+
const blocks = Array.from(selection.getSelectedBlocks());
|
|
136
|
+
if (!blocks.length) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
// If command value is true it means that we are in list item, so the command should be enabled.
|
|
140
|
+
if (this.value) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
for (const block of blocks) {
|
|
144
|
+
if (schema.checkAttribute(block, 'listType') || canBecomeSimpleListItem(block, schema)) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|