@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.
Files changed (55) hide show
  1. package/LICENSE.md +1 -1
  2. package/build/list.js +2 -2
  3. package/package.json +43 -39
  4. package/src/documentlist/converters.js +303 -419
  5. package/src/documentlist/documentlistcommand.js +136 -207
  6. package/src/documentlist/documentlistediting.js +538 -697
  7. package/src/documentlist/documentlistindentcommand.js +115 -168
  8. package/src/documentlist/documentlistmergecommand.js +161 -222
  9. package/src/documentlist/documentlistsplitcommand.js +59 -103
  10. package/src/documentlist/documentlistutils.js +41 -0
  11. package/src/documentlist/utils/listwalker.js +138 -236
  12. package/src/documentlist/utils/model.js +322 -421
  13. package/src/documentlist/utils/postfixers.js +98 -118
  14. package/src/documentlist/utils/view.js +74 -105
  15. package/src/documentlist.js +13 -19
  16. package/src/documentlistproperties/converters.js +33 -47
  17. package/src/documentlistproperties/documentlistpropertiesediting.js +266 -354
  18. package/src/documentlistproperties/documentlistpropertiesutils.js +44 -0
  19. package/src/documentlistproperties/documentlistreversedcommand.js +40 -61
  20. package/src/documentlistproperties/documentliststartcommand.js +42 -61
  21. package/src/documentlistproperties/documentliststylecommand.js +97 -147
  22. package/src/documentlistproperties/utils/style.js +27 -47
  23. package/src/documentlistproperties.js +13 -19
  24. package/src/index.js +4 -3
  25. package/src/list/converters.js +772 -929
  26. package/src/list/indentcommand.js +105 -140
  27. package/src/list/listcommand.js +262 -315
  28. package/src/list/listediting.js +142 -200
  29. package/src/list/listui.js +16 -25
  30. package/src/list/listutils.js +46 -0
  31. package/src/list/utils.js +295 -378
  32. package/src/list.js +13 -44
  33. package/src/listcommands.js +5 -0
  34. package/src/listconfig.js +5 -0
  35. package/src/listproperties/listpropertiesediting.js +656 -801
  36. package/src/listproperties/listpropertiesui.js +244 -296
  37. package/src/listproperties/listreversedcommand.js +37 -49
  38. package/src/listproperties/liststartcommand.js +37 -49
  39. package/src/listproperties/liststylecommand.js +82 -115
  40. package/src/listproperties/ui/collapsibleview.js +75 -138
  41. package/src/listproperties/ui/listpropertiesview.js +289 -414
  42. package/src/listproperties.js +13 -118
  43. package/src/liststyle.js +18 -24
  44. package/src/todolist/checktodolistcommand.js +60 -102
  45. package/src/todolist/todolistconverters.js +189 -271
  46. package/src/todolist/todolistediting.js +141 -206
  47. package/src/todolist/todolistui.js +14 -21
  48. package/src/todolist.js +13 -19
  49. package/theme/collapsible.css +1 -1
  50. package/theme/documentlist.css +1 -1
  51. package/theme/list.css +40 -0
  52. package/theme/listproperties.css +1 -1
  53. package/theme/liststyles.css +1 -37
  54. package/theme/todolist.css +1 -1
  55. package/build/list.js.map +0 -1
@@ -1,64 +1,52 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
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
- * @inheritDoc
23
- */
24
- refresh() {
25
- const value = this._getValue();
26
- this.value = value;
27
- this.isEnabled = value != null;
28
- }
29
-
30
- /**
31
- * Executes the command.
32
- *
33
- * @fires execute
34
- * @param {Object} options
35
- * @param {Boolean} [options.reversed=false] Whether the list should be reversed.
36
- */
37
- execute( options = {} ) {
38
- const model = this.editor.model;
39
- const listItems = getSelectedListItems( model )
40
- .filter( item => item.getAttribute( 'listType' ) == 'numbered' );
41
-
42
- model.change( writer => {
43
- for ( const item of listItems ) {
44
- writer.setAttribute( 'listReversed', !!options.reversed, item );
45
- }
46
- } );
47
- }
48
-
49
- /**
50
- * Checks the command's {@link #value}.
51
- *
52
- * @private
53
- * @returns {Boolean|null} The current value.
54
- */
55
- _getValue() {
56
- const listItem = this.editor.model.document.selection.getFirstPosition().parent;
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-2022, CKSource Holding sp. z o.o. All rights reserved.
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
- * @inheritDoc
22
- */
23
- refresh() {
24
- const value = this._getValue();
25
- this.value = value;
26
- this.isEnabled = value != null;
27
- }
28
-
29
- /**
30
- * Executes the command.
31
- *
32
- * @fires execute
33
- * @param {Object} options
34
- * @param {Number} [options.startIndex=1] The list start index.
35
- */
36
- execute( options = {} ) {
37
- const model = this.editor.model;
38
- const listItems = getSelectedListItems( model )
39
- .filter( item => item.getAttribute( 'listType' ) == 'numbered' );
40
-
41
- model.change( writer => {
42
- for ( const item of listItems ) {
43
- writer.setAttribute( 'listStart', options.startIndex || 1, item );
44
- }
45
- } );
46
- }
47
-
48
- /**
49
- * Checks the command's {@link #value}.
50
- *
51
- * @private
52
- * @returns {Boolean|null} The current value.
53
- */
54
- _getValue() {
55
- const listItem = this.editor.model.document.selection.getFirstPosition().parent;
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-2022, CKSource Holding sp. z o.o. All rights reserved.
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
- * Creates an instance of the command.
25
- *
26
- * @param {module:core/editor/editor~Editor} editor The editor instance.
27
- * @param {String} defaultType The list type that will be used by default if the value was not specified during
28
- * the command execution.
29
- */
30
- constructor( editor, defaultType ) {
31
- super( editor );
32
-
33
- /**
34
- * The default type of the list style.
35
- *
36
- * @protected
37
- * @member {String}
38
- */
39
- this._defaultType = defaultType;
40
- }
41
-
42
- /**
43
- * @inheritDoc
44
- */
45
- refresh() {
46
- this.value = this._getValue();
47
- this.isEnabled = this._checkEnabled();
48
- }
49
-
50
- /**
51
- * Executes the command.
52
- *
53
- * @fires execute
54
- * @param {Object} options
55
- * @param {String|null} [options.type] The type of the list style, e.g. `'disc'` or `'square'`. If `null` is specified, the default
56
- * style will be applied.
57
- */
58
- execute( options = {} ) {
59
- this._tryToConvertItemsToList( options );
60
-
61
- const model = this.editor.model;
62
- const listItems = getSelectedListItems( model );
63
-
64
- if ( !listItems.length ) {
65
- return;
66
- }
67
-
68
- model.change( writer => {
69
- for ( const item of listItems ) {
70
- writer.setAttribute( 'listStyle', options.type || this._defaultType, item );
71
- }
72
- } );
73
- }
74
-
75
- /**
76
- * Checks the command's {@link #value}.
77
- *
78
- * @private
79
- * @returns {String|null} The current value.
80
- */
81
- _getValue() {
82
- const listItem = this.editor.model.document.selection.getFirstPosition().parent;
83
-
84
- if ( listItem && listItem.is( 'element', 'listItem' ) ) {
85
- return listItem.getAttribute( 'listStyle' );
86
- }
87
-
88
- return null;
89
- }
90
-
91
- /**
92
- * Checks whether the command can be enabled in the current context.
93
- *
94
- * @private
95
- * @returns {Boolean} Whether the command should be enabled.
96
- */
97
- _checkEnabled() {
98
- const editor = this.editor;
99
-
100
- const numberedList = editor.commands.get( 'numberedList' );
101
- const bulletedList = editor.commands.get( 'bulletedList' );
102
-
103
- return numberedList.isEnabled || bulletedList.isEnabled;
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-2022, CKSource Holding sp. z o.o. All rights reserved.
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
- * @protected
22
- * @extends module:ui/view~View
13
+ * @internal
23
14
  */
24
15
  export default class CollapsibleView extends View {
25
- /**
26
- * Creates an instance of the collapsible view.
27
- *
28
- * @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
29
- * @param {Array.<module:ui/view~View>} [childViews] An optional array of initial child views to be inserted
30
- * into the collapsible.
31
- */
32
- constructor( locale, childViews ) {
33
- super( locale );
34
-
35
- const bind = this.bindTemplate;
36
-
37
- /**
38
- * `true` when the container with {@link #children} is collapsed. `false` otherwise.
39
- *
40
- * @observable
41
- * @member {Boolean} #isCollapsed
42
- */
43
- this.set( 'isCollapsed', false );
44
-
45
- /**
46
- * The text label of the {@link #buttonView}.
47
- *
48
- * @observable
49
- * @member {String} #label
50
- * @default 'Show more'
51
- */
52
- this.set( 'label', '' );
53
-
54
- /**
55
- * The main button that, when clicked, collapses or expands the container with {@link #children}.
56
- *
57
- * @readonly
58
- * @member {module:ui/button/buttonview~ButtonView} #buttonView
59
- */
60
- this.buttonView = this._createButtonView();
61
-
62
- /**
63
- * A collection of the child views that can be collapsed by clicking the {@link #buttonView}.
64
- *
65
- * @readonly
66
- * @member {module:ui/viewcollection~ViewCollection} #children
67
- */
68
- this.children = this.createCollection();
69
-
70
- /**
71
- * The ID of the label inside the {@link #buttonView} that describes the collapsible
72
- * container for assistive technologies. Set after the button was {@link #render rendered}.
73
- *
74
- * @private
75
- * @readonly
76
- * @observable
77
- * @member {String} #_collapsibleAriaLabelUid
78
- */
79
- this.set( '_collapsibleAriaLabelUid' );
80
-
81
- if ( childViews ) {
82
- this.children.addMany( childViews );
83
- }
84
-
85
- this.setTemplate( {
86
- tag: 'div',
87
- attributes: {
88
- class: [
89
- 'ck',
90
- 'ck-collapsible',
91
- bind.if( 'isCollapsed', 'ck-collapsible_collapsed' )
92
- ]
93
- },
94
- children: [
95
- this.buttonView,
96
- {
97
- tag: 'div',
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
  }