@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,64 +1,52 @@
|
|
|
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/listproperties/listreversedcommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
9
|
import { getSelectedListItems } from '../list/utils';
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* The reversed list command. It changes the `listReversed` attribute of the selected list items. As a result, the list order will be
|
|
15
12
|
* reversed.
|
|
16
13
|
* It is used by the {@link module:list/listproperties~ListProperties list properties feature}.
|
|
17
|
-
*
|
|
18
|
-
* @extends module:core/command~Command
|
|
19
14
|
*/
|
|
20
15
|
export default class ListReversedCommand extends Command {
|
|
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
|
-
if ( listItem && listItem.is( 'element', 'listItem' ) && listItem.getAttribute( 'listType' ) == 'numbered' ) {
|
|
59
|
-
return listItem.getAttribute( 'listReversed' );
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
refresh() {
|
|
20
|
+
const value = this._getValue();
|
|
21
|
+
this.value = value;
|
|
22
|
+
this.isEnabled = value != null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Executes the command.
|
|
26
|
+
*
|
|
27
|
+
* @fires execute
|
|
28
|
+
* @param options.reversed Whether the list should be reversed.
|
|
29
|
+
*/
|
|
30
|
+
execute(options = {}) {
|
|
31
|
+
const model = this.editor.model;
|
|
32
|
+
const listItems = getSelectedListItems(model)
|
|
33
|
+
.filter(item => item.getAttribute('listType') == 'numbered');
|
|
34
|
+
model.change(writer => {
|
|
35
|
+
for (const item of listItems) {
|
|
36
|
+
writer.setAttribute('listReversed', !!options.reversed, item);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks the command's {@link #value}.
|
|
42
|
+
*
|
|
43
|
+
* @returns The current value.
|
|
44
|
+
*/
|
|
45
|
+
_getValue() {
|
|
46
|
+
const listItem = this.editor.model.document.selection.getFirstPosition().parent;
|
|
47
|
+
if (listItem && listItem.is('element', 'listItem') && listItem.getAttribute('listType') == 'numbered') {
|
|
48
|
+
return listItem.getAttribute('listReversed');
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
64
52
|
}
|
|
@@ -1,63 +1,51 @@
|
|
|
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/listproperties/liststartcommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
9
|
import { getSelectedListItems } from '../list/utils';
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* The list start index command. It changes the `listStart` attribute of the selected list items.
|
|
15
12
|
* It is used by the {@link module:list/listproperties~ListProperties list properties feature}.
|
|
16
|
-
*
|
|
17
|
-
* @extends module:core/command~Command
|
|
18
13
|
*/
|
|
19
14
|
export default class ListStartCommand extends Command {
|
|
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
|
-
if ( listItem && listItem.is( 'element', 'listItem' ) && listItem.getAttribute( 'listType' ) == 'numbered' ) {
|
|
58
|
-
return listItem.getAttribute( 'listStart' );
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
refresh() {
|
|
19
|
+
const value = this._getValue();
|
|
20
|
+
this.value = value;
|
|
21
|
+
this.isEnabled = value != null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Executes the command.
|
|
25
|
+
*
|
|
26
|
+
* @fires execute
|
|
27
|
+
* @param options.startIndex The list start index.
|
|
28
|
+
*/
|
|
29
|
+
execute({ startIndex = 1 } = {}) {
|
|
30
|
+
const model = this.editor.model;
|
|
31
|
+
const listItems = getSelectedListItems(model)
|
|
32
|
+
.filter(item => item.getAttribute('listType') == 'numbered');
|
|
33
|
+
model.change(writer => {
|
|
34
|
+
for (const item of listItems) {
|
|
35
|
+
writer.setAttribute('listStart', startIndex >= 0 ? startIndex : 1, item);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks the command's {@link #value}.
|
|
41
|
+
*
|
|
42
|
+
* @returns The current value.
|
|
43
|
+
*/
|
|
44
|
+
_getValue() {
|
|
45
|
+
const listItem = this.editor.model.document.selection.getFirstPosition().parent;
|
|
46
|
+
if (listItem && listItem.is('element', 'listItem') && listItem.getAttribute('listType') == 'numbered') {
|
|
47
|
+
return listItem.getAttribute('listStart');
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
63
51
|
}
|
|
@@ -1,132 +1,99 @@
|
|
|
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/listproperties/liststylecommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
9
|
import { getListTypeFromListStyleType, getSelectedListItems } from '../list/utils';
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* The list style command. It changes the `listStyle` attribute of the selected list items.
|
|
15
12
|
*
|
|
16
13
|
* If the list type (numbered or bulleted) can be inferred from the passed style type,
|
|
17
14
|
* the command tries to convert selected items to a list of that type.
|
|
18
15
|
* It is used by the {@link module:list/listproperties~ListProperties list properties feature}.
|
|
19
|
-
*
|
|
20
|
-
* @extends module:core/command~Command
|
|
21
16
|
*/
|
|
22
17
|
export default class ListStyleCommand extends Command {
|
|
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
|
-
* Check if the provided list style is valid. Also change the selection to a list if it's not set yet.
|
|
108
|
-
*
|
|
109
|
-
* @param {Object} options
|
|
110
|
-
* @param {String|null} [options.type] The type of the list style. If `null` is specified, the function does nothing.
|
|
111
|
-
* @private
|
|
112
|
-
*/
|
|
113
|
-
_tryToConvertItemsToList( options ) {
|
|
114
|
-
if ( !options.type ) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const listType = getListTypeFromListStyleType( options.type );
|
|
119
|
-
|
|
120
|
-
if ( !listType ) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const editor = this.editor;
|
|
125
|
-
const commandName = listType + 'List';
|
|
126
|
-
const command = editor.commands.get( commandName );
|
|
127
|
-
|
|
128
|
-
if ( !command.value ) {
|
|
129
|
-
editor.execute( commandName );
|
|
130
|
-
}
|
|
131
|
-
}
|
|
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
|
+
*/
|
|
25
|
+
constructor(editor, defaultType) {
|
|
26
|
+
super(editor);
|
|
27
|
+
this.defaultType = defaultType;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @inheritDoc
|
|
31
|
+
*/
|
|
32
|
+
refresh() {
|
|
33
|
+
this.value = this._getValue();
|
|
34
|
+
this.isEnabled = this._checkEnabled();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Executes the command.
|
|
38
|
+
*
|
|
39
|
+
* @fires execute
|
|
40
|
+
* @param options.type The type of the list style, e.g. `'disc'` or `'square'`. If `null` is specified, the default
|
|
41
|
+
* style will be applied.
|
|
42
|
+
*/
|
|
43
|
+
execute(options = {}) {
|
|
44
|
+
this._tryToConvertItemsToList(options);
|
|
45
|
+
const model = this.editor.model;
|
|
46
|
+
const listItems = getSelectedListItems(model);
|
|
47
|
+
if (!listItems.length) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
model.change(writer => {
|
|
51
|
+
for (const item of listItems) {
|
|
52
|
+
writer.setAttribute('listStyle', options.type || this.defaultType, item);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks the command's {@link #value}.
|
|
58
|
+
*
|
|
59
|
+
* @returns The current value.
|
|
60
|
+
*/
|
|
61
|
+
_getValue() {
|
|
62
|
+
const listItem = this.editor.model.document.selection.getFirstPosition().parent;
|
|
63
|
+
if (listItem && listItem.is('element', 'listItem')) {
|
|
64
|
+
return listItem.getAttribute('listStyle');
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks whether the command can be enabled in the current context.
|
|
70
|
+
*
|
|
71
|
+
* @returns Whether the command should be enabled.
|
|
72
|
+
*/
|
|
73
|
+
_checkEnabled() {
|
|
74
|
+
const editor = this.editor;
|
|
75
|
+
const numberedList = editor.commands.get('numberedList');
|
|
76
|
+
const bulletedList = editor.commands.get('bulletedList');
|
|
77
|
+
return numberedList.isEnabled || bulletedList.isEnabled;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if the provided list style is valid. Also change the selection to a list if it's not set yet.
|
|
81
|
+
*
|
|
82
|
+
* @param The type of the list style. If `null` is specified, the function does nothing.
|
|
83
|
+
*/
|
|
84
|
+
_tryToConvertItemsToList(options) {
|
|
85
|
+
if (!options.type) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const listType = getListTypeFromListStyleType(options.type);
|
|
89
|
+
if (!listType) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const editor = this.editor;
|
|
93
|
+
const commandName = `${listType}List`;
|
|
94
|
+
const command = editor.commands.get(commandName);
|
|
95
|
+
if (!command.value) {
|
|
96
|
+
editor.execute(commandName);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
132
99
|
}
|
|
@@ -1,152 +1,89 @@
|
|
|
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/ui/collapsibleview
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
5
|
import { View, ButtonView } from 'ckeditor5/src/ui';
|
|
11
|
-
|
|
12
6
|
// eslint-disable-next-line ckeditor5-rules/ckeditor-imports
|
|
13
7
|
import dropdownArrowIcon from '@ckeditor/ckeditor5-ui/theme/icons/dropdown-arrow.svg';
|
|
14
|
-
|
|
15
8
|
import '../../../theme/collapsible.css';
|
|
16
|
-
|
|
17
9
|
/**
|
|
18
10
|
* A collapsible UI component. Consists of a labeled button and a container which can be collapsed
|
|
19
11
|
* by clicking the button. The collapsible container can be a host to other UI views.
|
|
20
12
|
*
|
|
21
|
-
* @
|
|
22
|
-
* @extends module:ui/view~View
|
|
13
|
+
* @internal
|
|
23
14
|
*/
|
|
24
15
|
export default class CollapsibleView extends View {
|
|
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
|
-
attributes: {
|
|
99
|
-
class: [
|
|
100
|
-
'ck',
|
|
101
|
-
'ck-collapsible__children'
|
|
102
|
-
],
|
|
103
|
-
role: 'region',
|
|
104
|
-
hidden: bind.if( 'isCollapsed', 'hidden' ),
|
|
105
|
-
'aria-labelledby': bind.to( '_collapsibleAriaLabelUid' )
|
|
106
|
-
},
|
|
107
|
-
children: this.children
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
} );
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @inheritDoc
|
|
115
|
-
*/
|
|
116
|
-
render() {
|
|
117
|
-
super.render();
|
|
118
|
-
|
|
119
|
-
this._collapsibleAriaLabelUid = this.buttonView.labelView.element.id;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Creates the main {@link #buttonView} of the collapsible.
|
|
124
|
-
*
|
|
125
|
-
* @private
|
|
126
|
-
* @returns {module:ui/button/buttonview~ButtonView}
|
|
127
|
-
*/
|
|
128
|
-
_createButtonView() {
|
|
129
|
-
const buttonView = new ButtonView( this.locale );
|
|
130
|
-
const bind = buttonView.bindTemplate;
|
|
131
|
-
|
|
132
|
-
buttonView.set( {
|
|
133
|
-
withText: true,
|
|
134
|
-
icon: dropdownArrowIcon
|
|
135
|
-
} );
|
|
136
|
-
|
|
137
|
-
buttonView.extendTemplate( {
|
|
138
|
-
attributes: {
|
|
139
|
-
'aria-expanded': bind.to( 'isOn', value => String( value ) )
|
|
140
|
-
}
|
|
141
|
-
} );
|
|
142
|
-
|
|
143
|
-
buttonView.bind( 'label' ).to( this );
|
|
144
|
-
buttonView.bind( 'isOn' ).to( this, 'isCollapsed', isCollapsed => !isCollapsed );
|
|
145
|
-
|
|
146
|
-
buttonView.on( 'execute', () => {
|
|
147
|
-
this.isCollapsed = !this.isCollapsed;
|
|
148
|
-
} );
|
|
149
|
-
|
|
150
|
-
return buttonView;
|
|
151
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of the collapsible view.
|
|
18
|
+
*
|
|
19
|
+
* @param locale The {@link module:core/editor/editor~Editor#locale} instance.
|
|
20
|
+
* @param childViews An optional array of initial child views to be inserted into the collapsible.
|
|
21
|
+
*/
|
|
22
|
+
constructor(locale, childViews) {
|
|
23
|
+
super(locale);
|
|
24
|
+
const bind = this.bindTemplate;
|
|
25
|
+
this.set('isCollapsed', false);
|
|
26
|
+
this.set('label', '');
|
|
27
|
+
this.buttonView = this._createButtonView();
|
|
28
|
+
this.children = this.createCollection();
|
|
29
|
+
this.set('_collapsibleAriaLabelUid', undefined);
|
|
30
|
+
if (childViews) {
|
|
31
|
+
this.children.addMany(childViews);
|
|
32
|
+
}
|
|
33
|
+
this.setTemplate({
|
|
34
|
+
tag: 'div',
|
|
35
|
+
attributes: {
|
|
36
|
+
class: [
|
|
37
|
+
'ck',
|
|
38
|
+
'ck-collapsible',
|
|
39
|
+
bind.if('isCollapsed', 'ck-collapsible_collapsed')
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
children: [
|
|
43
|
+
this.buttonView,
|
|
44
|
+
{
|
|
45
|
+
tag: 'div',
|
|
46
|
+
attributes: {
|
|
47
|
+
class: [
|
|
48
|
+
'ck',
|
|
49
|
+
'ck-collapsible__children'
|
|
50
|
+
],
|
|
51
|
+
role: 'region',
|
|
52
|
+
hidden: bind.if('isCollapsed', 'hidden'),
|
|
53
|
+
'aria-labelledby': bind.to('_collapsibleAriaLabelUid')
|
|
54
|
+
},
|
|
55
|
+
children: this.children
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @inheritDoc
|
|
62
|
+
*/
|
|
63
|
+
render() {
|
|
64
|
+
super.render();
|
|
65
|
+
this._collapsibleAriaLabelUid = this.buttonView.labelView.element.id;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates the main {@link #buttonView} of the collapsible.
|
|
69
|
+
*/
|
|
70
|
+
_createButtonView() {
|
|
71
|
+
const buttonView = new ButtonView(this.locale);
|
|
72
|
+
const bind = buttonView.bindTemplate;
|
|
73
|
+
buttonView.set({
|
|
74
|
+
withText: true,
|
|
75
|
+
icon: dropdownArrowIcon
|
|
76
|
+
});
|
|
77
|
+
buttonView.extendTemplate({
|
|
78
|
+
attributes: {
|
|
79
|
+
'aria-expanded': bind.to('isOn', value => String(value))
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
buttonView.bind('label').to(this);
|
|
83
|
+
buttonView.bind('isOn').to(this, 'isCollapsed', isCollapsed => !isCollapsed);
|
|
84
|
+
buttonView.on('execute', () => {
|
|
85
|
+
this.isCollapsed = !this.isCollapsed;
|
|
86
|
+
});
|
|
87
|
+
return buttonView;
|
|
88
|
+
}
|
|
152
89
|
}
|