@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,69 +1,44 @@
|
|
|
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/documentlistpropertiesutils
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
-
import {
|
|
12
|
-
getAllSupportedStyleTypes,
|
|
13
|
-
getListStyleTypeFromTypeAttribute,
|
|
14
|
-
getListTypeFromListStyleType,
|
|
15
|
-
getTypeAttributeFromListStyleType
|
|
16
|
-
} from './utils/style';
|
|
17
|
-
|
|
9
|
+
import { getAllSupportedStyleTypes, getListStyleTypeFromTypeAttribute, getListTypeFromListStyleType, getTypeAttributeFromListStyleType } from './utils/style';
|
|
18
10
|
/**
|
|
19
11
|
* A set of helpers related to document lists.
|
|
20
|
-
*
|
|
21
|
-
* @extends module:core/plugin~Plugin
|
|
22
12
|
*/
|
|
23
13
|
export default class DocumentListPropertiesUtils extends Plugin {
|
|
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
|
-
* @returns {String|null}
|
|
55
|
-
*/
|
|
56
|
-
getListStyleTypeFromTypeAttribute( value ) {
|
|
57
|
-
return getListStyleTypeFromTypeAttribute( value );
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Converts `list-style-type` style to `type` attribute of `<ul>` or `<ol>` elements.
|
|
62
|
-
*
|
|
63
|
-
* @param {String} value
|
|
64
|
-
* @returns {String|null}
|
|
65
|
-
*/
|
|
66
|
-
getTypeAttributeFromListStyleType( value ) {
|
|
67
|
-
return getTypeAttributeFromListStyleType( value );
|
|
68
|
-
}
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
static get pluginName() {
|
|
18
|
+
return 'DocumentListPropertiesUtils';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets all the style types supported by given list type.
|
|
22
|
+
*/
|
|
23
|
+
getAllSupportedStyleTypes() {
|
|
24
|
+
return getAllSupportedStyleTypes();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks whether the given list-style-type is supported by numbered or bulleted list.
|
|
28
|
+
*/
|
|
29
|
+
getListTypeFromListStyleType(listStyleType) {
|
|
30
|
+
return getListTypeFromListStyleType(listStyleType);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Converts `type` attribute of `<ul>` or `<ol>` elements to `list-style-type` equivalent.
|
|
34
|
+
*/
|
|
35
|
+
getListStyleTypeFromTypeAttribute(value) {
|
|
36
|
+
return getListStyleTypeFromTypeAttribute(value);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts `list-style-type` style to `type` attribute of `<ul>` or `<ol>` elements.
|
|
40
|
+
*/
|
|
41
|
+
getTypeAttributeFromListStyleType(value) {
|
|
42
|
+
return getTypeAttributeFromListStyleType(value);
|
|
43
|
+
}
|
|
69
44
|
}
|
|
@@ -1,76 +1,55 @@
|
|
|
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/documentlistproperties/documentlistreversedcommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
9
|
import { first } from 'ckeditor5/src/utils';
|
|
12
|
-
import {
|
|
13
|
-
expandListBlocksToCompleteList,
|
|
14
|
-
isListItemBlock
|
|
15
|
-
} from '../documentlist/utils/model';
|
|
16
|
-
|
|
10
|
+
import { expandListBlocksToCompleteList, isListItemBlock } from '../documentlist/utils/model';
|
|
17
11
|
/**
|
|
18
12
|
* The list reversed command. It changes the `listReversed` attribute of the selected list items,
|
|
19
13
|
* letting the user to choose the order of an ordered list.
|
|
20
14
|
* It is used by the {@link module:list/documentlistproperties~DocumentListProperties list properties feature}.
|
|
21
|
-
*
|
|
22
|
-
* @extends module:core/command~Command
|
|
23
15
|
*/
|
|
24
16
|
export default class DocumentListReversedCommand extends Command {
|
|
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
|
-
_getValue() {
|
|
65
|
-
const model = this.editor.model;
|
|
66
|
-
const document = model.document;
|
|
67
|
-
|
|
68
|
-
const block = first( document.selection.getSelectedBlocks() );
|
|
69
|
-
|
|
70
|
-
if ( isListItemBlock( block ) && block.getAttribute( 'listType' ) == 'numbered' ) {
|
|
71
|
-
return block.getAttribute( 'listReversed' );
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
refresh() {
|
|
21
|
+
const value = this._getValue();
|
|
22
|
+
this.value = value;
|
|
23
|
+
this.isEnabled = value != null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Executes the command.
|
|
27
|
+
*
|
|
28
|
+
* @fires execute
|
|
29
|
+
* @param options.reversed Whether the list should be reversed.
|
|
30
|
+
*/
|
|
31
|
+
execute(options = {}) {
|
|
32
|
+
const model = this.editor.model;
|
|
33
|
+
const document = model.document;
|
|
34
|
+
let blocks = Array.from(document.selection.getSelectedBlocks())
|
|
35
|
+
.filter(block => isListItemBlock(block) && block.getAttribute('listType') == 'numbered');
|
|
36
|
+
blocks = expandListBlocksToCompleteList(blocks);
|
|
37
|
+
model.change(writer => {
|
|
38
|
+
for (const block of blocks) {
|
|
39
|
+
writer.setAttribute('listReversed', !!options.reversed, block);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks the command's {@link #value}.
|
|
45
|
+
*/
|
|
46
|
+
_getValue() {
|
|
47
|
+
const model = this.editor.model;
|
|
48
|
+
const document = model.document;
|
|
49
|
+
const block = first(document.selection.getSelectedBlocks());
|
|
50
|
+
if (isListItemBlock(block) && block.getAttribute('listType') == 'numbered') {
|
|
51
|
+
return block.getAttribute('listReversed');
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
76
55
|
}
|
|
@@ -1,76 +1,57 @@
|
|
|
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/documentlistproperties/documentliststartcommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
9
|
import { first } from 'ckeditor5/src/utils';
|
|
12
|
-
import {
|
|
13
|
-
expandListBlocksToCompleteList,
|
|
14
|
-
isListItemBlock
|
|
15
|
-
} from '../documentlist/utils/model';
|
|
16
|
-
|
|
10
|
+
import { expandListBlocksToCompleteList, isListItemBlock } from '../documentlist/utils/model';
|
|
17
11
|
/**
|
|
18
12
|
* The list start index command. It changes the `listStart` attribute of the selected list items,
|
|
19
13
|
* letting the user to choose the starting point of an ordered list.
|
|
20
14
|
* It is used by the {@link module:list/documentlistproperties~DocumentListProperties list properties feature}.
|
|
21
|
-
*
|
|
22
|
-
* @extends module:core/command~Command
|
|
23
15
|
*/
|
|
24
16
|
export default class DocumentListStartCommand extends Command {
|
|
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
|
-
const model = this.editor.model;
|
|
66
|
-
const document = model.document;
|
|
67
|
-
|
|
68
|
-
const block = first( document.selection.getSelectedBlocks() );
|
|
69
|
-
|
|
70
|
-
if ( block && isListItemBlock( block ) && block.getAttribute( 'listType' ) == 'numbered' ) {
|
|
71
|
-
return block.getAttribute( 'listStart' );
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
refresh() {
|
|
21
|
+
const value = this._getValue();
|
|
22
|
+
this.value = value;
|
|
23
|
+
this.isEnabled = value != null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Executes the command.
|
|
27
|
+
*
|
|
28
|
+
* @fires execute
|
|
29
|
+
* @param options.startIndex The list start index.
|
|
30
|
+
*/
|
|
31
|
+
execute({ startIndex = 1 } = {}) {
|
|
32
|
+
const model = this.editor.model;
|
|
33
|
+
const document = model.document;
|
|
34
|
+
let blocks = Array.from(document.selection.getSelectedBlocks())
|
|
35
|
+
.filter(block => isListItemBlock(block) && block.getAttribute('listType') == 'numbered');
|
|
36
|
+
blocks = expandListBlocksToCompleteList(blocks);
|
|
37
|
+
model.change(writer => {
|
|
38
|
+
for (const block of blocks) {
|
|
39
|
+
writer.setAttribute('listStart', startIndex >= 0 ? startIndex : 1, block);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks the command's {@link #value}.
|
|
45
|
+
*
|
|
46
|
+
* @returns The current value.
|
|
47
|
+
*/
|
|
48
|
+
_getValue() {
|
|
49
|
+
const model = this.editor.model;
|
|
50
|
+
const document = model.document;
|
|
51
|
+
const block = first(document.selection.getSelectedBlocks());
|
|
52
|
+
if (block && isListItemBlock(block) && block.getAttribute('listType') == 'numbered') {
|
|
53
|
+
return block.getAttribute('listStart');
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
76
57
|
}
|
|
@@ -1,163 +1,113 @@
|
|
|
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/documentlistproperties/documentliststylecommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
9
|
import { first } from 'ckeditor5/src/utils';
|
|
12
|
-
import {
|
|
13
|
-
expandListBlocksToCompleteList,
|
|
14
|
-
isListItemBlock
|
|
15
|
-
} from '../documentlist/utils/model';
|
|
10
|
+
import { expandListBlocksToCompleteList, isListItemBlock } from '../documentlist/utils/model';
|
|
16
11
|
import { getListTypeFromListStyleType } from './utils/style';
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* The list style command. It changes `listStyle` attribute of the selected list items,
|
|
20
14
|
* letting the user choose styles for the list item markers.
|
|
21
15
|
* It is used by the {@link module:list/documentlistproperties~DocumentListProperties list properties feature}.
|
|
22
|
-
*
|
|
23
|
-
* @extends module:core/command~Command
|
|
24
16
|
*/
|
|
25
17
|
export default class DocumentListStyleCommand extends Command {
|
|
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
|
-
* Checks whether the command can be enabled in the current context.
|
|
124
|
-
*
|
|
125
|
-
* @private
|
|
126
|
-
* @returns {Boolean} Whether the command should be enabled.
|
|
127
|
-
*/
|
|
128
|
-
_checkEnabled() {
|
|
129
|
-
const editor = this.editor;
|
|
130
|
-
|
|
131
|
-
const numberedList = editor.commands.get( 'numberedList' );
|
|
132
|
-
const bulletedList = editor.commands.get( 'bulletedList' );
|
|
133
|
-
|
|
134
|
-
return numberedList.isEnabled || bulletedList.isEnabled;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Check if the provided list style is valid. Also change the selection to a list if it's not set yet.
|
|
139
|
-
*
|
|
140
|
-
* @private
|
|
141
|
-
* @param {Object} options
|
|
142
|
-
* @param {String|null} [options.type] The type of the list style. If `null` is specified, the function does nothing.
|
|
143
|
-
*/
|
|
144
|
-
_tryToConvertItemsToList( options ) {
|
|
145
|
-
if ( !options.type ) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const listType = getListTypeFromListStyleType( options.type );
|
|
150
|
-
|
|
151
|
-
if ( !listType ) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const editor = this.editor;
|
|
156
|
-
const commandName = listType + 'List';
|
|
157
|
-
const command = editor.commands.get( commandName );
|
|
158
|
-
|
|
159
|
-
if ( !command.value ) {
|
|
160
|
-
editor.execute( commandName );
|
|
161
|
-
}
|
|
162
|
-
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of the command.
|
|
20
|
+
*
|
|
21
|
+
* @param editor The editor instance.
|
|
22
|
+
* @param defaultType The list type that will be used by default if the value was not specified during
|
|
23
|
+
* the command execution.
|
|
24
|
+
* @param supportedTypes The list of supported style types by this command.
|
|
25
|
+
*/
|
|
26
|
+
constructor(editor, defaultType, supportedTypes) {
|
|
27
|
+
super(editor);
|
|
28
|
+
this.defaultType = defaultType;
|
|
29
|
+
this._supportedTypes = supportedTypes;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
refresh() {
|
|
35
|
+
this.value = this._getValue();
|
|
36
|
+
this.isEnabled = this._checkEnabled();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Executes the command.
|
|
40
|
+
*
|
|
41
|
+
* @fires execute
|
|
42
|
+
* @param options.type The type of the list style, e.g. `'disc'` or `'square'`. If `null` is specified, the default
|
|
43
|
+
* style will be applied.
|
|
44
|
+
*/
|
|
45
|
+
execute(options = {}) {
|
|
46
|
+
const model = this.editor.model;
|
|
47
|
+
const document = model.document;
|
|
48
|
+
model.change(writer => {
|
|
49
|
+
this._tryToConvertItemsToList(options);
|
|
50
|
+
let blocks = Array.from(document.selection.getSelectedBlocks())
|
|
51
|
+
.filter(block => block.hasAttribute('listType'));
|
|
52
|
+
if (!blocks.length) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
blocks = expandListBlocksToCompleteList(blocks);
|
|
56
|
+
for (const block of blocks) {
|
|
57
|
+
writer.setAttribute('listStyle', options.type || this.defaultType, block);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks if the given style type is supported by this plugin.
|
|
63
|
+
*/
|
|
64
|
+
isStyleTypeSupported(value) {
|
|
65
|
+
if (!this._supportedTypes) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return this._supportedTypes.includes(value);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Checks the command's {@link #value}.
|
|
72
|
+
*
|
|
73
|
+
* @returns The current value.
|
|
74
|
+
*/
|
|
75
|
+
_getValue() {
|
|
76
|
+
const listItem = first(this.editor.model.document.selection.getSelectedBlocks());
|
|
77
|
+
if (isListItemBlock(listItem)) {
|
|
78
|
+
return listItem.getAttribute('listStyle');
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Checks whether the command can be enabled in the current context.
|
|
84
|
+
*
|
|
85
|
+
* @returns Whether the command should be enabled.
|
|
86
|
+
*/
|
|
87
|
+
_checkEnabled() {
|
|
88
|
+
const editor = this.editor;
|
|
89
|
+
const numberedList = editor.commands.get('numberedList');
|
|
90
|
+
const bulletedList = editor.commands.get('bulletedList');
|
|
91
|
+
return numberedList.isEnabled || bulletedList.isEnabled;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if the provided list style is valid. Also change the selection to a list if it's not set yet.
|
|
95
|
+
*
|
|
96
|
+
* @param options.type The type of the list style. If `null` is specified, the function does nothing.
|
|
97
|
+
*/
|
|
98
|
+
_tryToConvertItemsToList(options) {
|
|
99
|
+
if (!options.type) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const listType = getListTypeFromListStyleType(options.type);
|
|
103
|
+
if (!listType) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const editor = this.editor;
|
|
107
|
+
const commandName = `${listType}List`;
|
|
108
|
+
const command = editor.commands.get(commandName);
|
|
109
|
+
if (!command.value) {
|
|
110
|
+
editor.execute(commandName);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
163
113
|
}
|