@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.
Files changed (54) 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 -698
  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 +31 -45
  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 -126
  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 +265 -356
  18. package/src/documentlistproperties/documentlistpropertiesutils.js +32 -57
  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 +1 -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 +141 -200
  29. package/src/list/listui.js +16 -25
  30. package/src/list/listutils.js +37 -59
  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 -803
  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 -415
  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
@@ -1,69 +1,44 @@
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/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
- * @inheritDoc
26
- */
27
- static get pluginName() {
28
- return 'DocumentListPropertiesUtils';
29
- }
30
-
31
- /**
32
- * Gets all the style types supported by given list type.
33
- *
34
- * @returns {Array.<String>}
35
- */
36
- getAllSupportedStyleTypes() {
37
- return getAllSupportedStyleTypes();
38
- }
39
-
40
- /**
41
- * Checks whether the given list-style-type is supported by numbered or bulleted list.
42
- *
43
- * @param {String} listStyleType
44
- * @returns {'bulleted'|'numbered'|null}
45
- */
46
- getListTypeFromListStyleType( listStyleType ) {
47
- return getListTypeFromListStyleType( listStyleType );
48
- }
49
-
50
- /**
51
- * Converts `type` attribute of `<ul>` or `<ol>` elements to `list-style-type` equivalent.
52
- *
53
- * @param {String} value
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-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/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
- * @inheritDoc
27
- */
28
- refresh() {
29
- const value = this._getValue();
30
-
31
- this.value = value;
32
- this.isEnabled = value != null;
33
- }
34
-
35
- /**
36
- * Executes the command.
37
- *
38
- * @fires execute
39
- * @param {Object} [options]
40
- * @param {Boolean} [options.reversed=false] Whether the list should be reversed.
41
- */
42
- execute( options = {} ) {
43
- const model = this.editor.model;
44
- const document = model.document;
45
-
46
- let blocks = Array.from( document.selection.getSelectedBlocks() )
47
- .filter( block => isListItemBlock( block ) && block.getAttribute( 'listType' ) == 'numbered' );
48
-
49
- blocks = expandListBlocksToCompleteList( blocks );
50
-
51
- model.change( writer => {
52
- for ( const block of blocks ) {
53
- writer.setAttribute( 'listReversed', !!options.reversed, block );
54
- }
55
- } );
56
- }
57
-
58
- /**
59
- * Checks the command's {@link #value}.
60
- *
61
- * @private
62
- * @returns {Boolean|null} The current value.
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-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/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
- * @inheritDoc
27
- */
28
- refresh() {
29
- const value = this._getValue();
30
-
31
- this.value = value;
32
- this.isEnabled = value != null;
33
- }
34
-
35
- /**
36
- * Executes the command.
37
- *
38
- * @fires execute
39
- * @param {Object} [options]
40
- * @param {Number} [options.startIndex=1] The list start index.
41
- */
42
- execute( options = {} ) {
43
- const model = this.editor.model;
44
- const document = model.document;
45
-
46
- let blocks = Array.from( document.selection.getSelectedBlocks() )
47
- .filter( block => isListItemBlock( block ) && block.getAttribute( 'listType' ) == 'numbered' );
48
-
49
- blocks = expandListBlocksToCompleteList( blocks );
50
-
51
- model.change( writer => {
52
- for ( const block of blocks ) {
53
- writer.setAttribute( 'listStart', options.startIndex >= 0 ? options.startIndex : 1, block );
54
- }
55
- } );
56
- }
57
-
58
- /**
59
- * Checks the command's {@link #value}.
60
- *
61
- * @private
62
- * @returns {Number|null} The current value.
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 ( 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-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/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
- * Creates an instance of the command.
28
- *
29
- * @param {module:core/editor/editor~Editor} editor The editor instance.
30
- * @param {String} defaultType The list type that will be used by default if the value was not specified during
31
- * the command execution.
32
- * @param {Array.<String>} [supportedTypes] The list of supported style types by this command.
33
- */
34
- constructor( editor, defaultType, supportedTypes ) {
35
- super( editor );
36
-
37
- /**
38
- * The default type of the list style.
39
- *
40
- * @protected
41
- * @member {String}
42
- */
43
- this._defaultType = defaultType;
44
-
45
- /**
46
- * The list of supported style types by this command.
47
- *
48
- * @private
49
- * @member {Array.<String>|undefined}
50
- */
51
- this._supportedTypes = supportedTypes;
52
- }
53
-
54
- /**
55
- * @inheritDoc
56
- */
57
- refresh() {
58
- this.value = this._getValue();
59
- this.isEnabled = this._checkEnabled();
60
- }
61
-
62
- /**
63
- * Executes the command.
64
- *
65
- * @fires execute
66
- * @param {Object} options
67
- * @param {String|null} [options.type] The type of the list style, e.g. `'disc'` or `'square'`. If `null` is specified, the default
68
- * style will be applied.
69
- */
70
- execute( options = {} ) {
71
- const model = this.editor.model;
72
- const document = model.document;
73
-
74
- model.change( writer => {
75
- this._tryToConvertItemsToList( options );
76
-
77
- let blocks = Array.from( document.selection.getSelectedBlocks() )
78
- .filter( block => block.hasAttribute( 'listType' ) );
79
-
80
- if ( !blocks.length ) {
81
- return;
82
- }
83
-
84
- blocks = expandListBlocksToCompleteList( blocks );
85
-
86
- for ( const block of blocks ) {
87
- writer.setAttribute( 'listStyle', options.type || this._defaultType, block );
88
- }
89
- } );
90
- }
91
-
92
- /**
93
- * Checks if the given style type is supported by this plugin.
94
- *
95
- * @param {String} value
96
- * @returns {Boolean}
97
- */
98
- isStyleTypeSupported( value ) {
99
- if ( !this._supportedTypes ) {
100
- return true;
101
- }
102
-
103
- return this._supportedTypes.includes( value );
104
- }
105
-
106
- /**
107
- * Checks the command's {@link #value}.
108
- *
109
- * @private
110
- * @returns {String|null} The current value.
111
- */
112
- _getValue() {
113
- const listItem = first( this.editor.model.document.selection.getSelectedBlocks() );
114
-
115
- if ( isListItemBlock( listItem ) ) {
116
- return listItem.getAttribute( 'listStyle' );
117
- }
118
-
119
- return null;
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
  }