@ckeditor/ckeditor5-list 33.0.0 → 34.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 (44) hide show
  1. package/README.md +2 -1
  2. package/build/list.js +1 -1
  3. package/build/list.js.map +1 -1
  4. package/build/translations/de.js +1 -1
  5. package/build/translations/en-au.js +1 -1
  6. package/build/translations/gl.js +1 -1
  7. package/build/translations/jv.js +1 -0
  8. package/build/translations/pt-br.js +1 -1
  9. package/build/translations/sk.js +1 -1
  10. package/lang/translations/de.po +4 -4
  11. package/lang/translations/en-au.po +4 -4
  12. package/lang/translations/gl.po +4 -4
  13. package/lang/translations/jv.po +125 -0
  14. package/lang/translations/pt-br.po +4 -4
  15. package/lang/translations/sk.po +4 -4
  16. package/package.json +36 -24
  17. package/src/documentlist/converters.js +470 -0
  18. package/src/documentlist/documentlistcommand.js +216 -0
  19. package/src/documentlist/documentlistediting.js +676 -0
  20. package/src/documentlist/documentlistindentcommand.js +182 -0
  21. package/src/documentlist/documentlistmergecommand.js +235 -0
  22. package/src/documentlist/documentlistsplitcommand.js +114 -0
  23. package/src/documentlist/utils/listwalker.js +260 -0
  24. package/src/documentlist/utils/model.js +534 -0
  25. package/src/documentlist/utils/postfixers.js +138 -0
  26. package/src/documentlist/utils/view.js +148 -0
  27. package/src/documentlist.js +36 -0
  28. package/src/documentlistproperties/converters.js +57 -0
  29. package/src/documentlistproperties/documentlistpropertiesediting.js +338 -0
  30. package/src/documentlistproperties/documentlistreversedcommand.js +76 -0
  31. package/src/documentlistproperties/documentliststartcommand.js +76 -0
  32. package/src/documentlistproperties/documentliststylecommand.js +140 -0
  33. package/src/documentlistproperties/utils/style.js +41 -0
  34. package/src/documentlistproperties.js +37 -0
  35. package/src/list/converters.js +4 -0
  36. package/src/list/listediting.js +12 -13
  37. package/src/list.js +3 -2
  38. package/src/listproperties/listpropertiesediting.js +1 -1
  39. package/src/listproperties/listreversedcommand.js +1 -1
  40. package/src/listproperties/liststartcommand.js +1 -1
  41. package/src/listproperties/liststylecommand.js +1 -1
  42. package/src/listproperties.js +11 -6
  43. package/theme/documentlist.css +8 -0
  44. package/src/listproperties/ui/inputnumberview.js +0 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2022, 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
+ /**
7
+ * @module list/documentlistproperties/documentliststartcommand
8
+ */
9
+
10
+ import { Command } from 'ckeditor5/src/core';
11
+ import { first } from 'ckeditor5/src/utils';
12
+ import {
13
+ expandListBlocksToCompleteList,
14
+ isListItemBlock
15
+ } from '../documentlist/utils/model';
16
+
17
+ /**
18
+ * The list start index command. It changes the `listStart` attribute of the selected list items,
19
+ * letting the user to choose the starting point of an ordered list.
20
+ * It is used by the {@link module:list/documentlistproperties~DocumentListProperties list properties feature}.
21
+ *
22
+ * @extends module:core/command~Command
23
+ */
24
+ 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 || 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
+ }
76
+ }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2022, 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
+ /**
7
+ * @module list/documentlistproperties/documentliststylecommand
8
+ */
9
+
10
+ import { Command } from 'ckeditor5/src/core';
11
+ import { first } from 'ckeditor5/src/utils';
12
+ import {
13
+ expandListBlocksToCompleteList,
14
+ isListItemBlock
15
+ } from '../documentlist/utils/model';
16
+ import { getListTypeFromListStyleType } from './utils/style';
17
+
18
+ /**
19
+ * The list style command. It changes `listStyle` attribute of the selected list items,
20
+ * letting the user choose styles for the list item markers.
21
+ * It is used by the {@link module:list/documentlistproperties~DocumentListProperties list properties feature}.
22
+ *
23
+ * @extends module:core/command~Command
24
+ */
25
+ 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
+ */
33
+ constructor( editor, defaultType ) {
34
+ super( editor );
35
+
36
+ /**
37
+ * The default type of the list style.
38
+ *
39
+ * @protected
40
+ * @member {String}
41
+ */
42
+ this._defaultType = defaultType;
43
+ }
44
+
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ refresh() {
49
+ this.value = this._getValue();
50
+ this.isEnabled = this._checkEnabled();
51
+ }
52
+
53
+ /**
54
+ * Executes the command.
55
+ *
56
+ * @fires execute
57
+ * @param {Object} options
58
+ * @param {String|null} [options.type] The type of the list style, e.g. `'disc'` or `'square'`. If `null` is specified, the default
59
+ * style will be applied.
60
+ */
61
+ execute( options = {} ) {
62
+ const model = this.editor.model;
63
+ const document = model.document;
64
+
65
+ model.change( writer => {
66
+ this._tryToConvertItemsToList( options );
67
+
68
+ let blocks = Array.from( document.selection.getSelectedBlocks() )
69
+ .filter( block => block.hasAttribute( 'listType' ) );
70
+
71
+ if ( !blocks.length ) {
72
+ return;
73
+ }
74
+
75
+ blocks = expandListBlocksToCompleteList( blocks );
76
+
77
+ for ( const block of blocks ) {
78
+ writer.setAttribute( 'listStyle', options.type || this._defaultType, block );
79
+ }
80
+ } );
81
+ }
82
+
83
+ /**
84
+ * Checks the command's {@link #value}.
85
+ *
86
+ * @private
87
+ * @returns {String|null} The current value.
88
+ */
89
+ _getValue() {
90
+ const listItem = first( this.editor.model.document.selection.getSelectedBlocks() );
91
+
92
+ if ( isListItemBlock( listItem ) ) {
93
+ return listItem.getAttribute( 'listStyle' );
94
+ }
95
+
96
+ return null;
97
+ }
98
+
99
+ /**
100
+ * Checks whether the command can be enabled in the current context.
101
+ *
102
+ * @private
103
+ * @returns {Boolean} Whether the command should be enabled.
104
+ */
105
+ _checkEnabled() {
106
+ const editor = this.editor;
107
+
108
+ const numberedList = editor.commands.get( 'numberedList' );
109
+ const bulletedList = editor.commands.get( 'bulletedList' );
110
+
111
+ return numberedList.isEnabled || bulletedList.isEnabled;
112
+ }
113
+
114
+ /**
115
+ * Check if the provided list style is valid. Also change the selection to a list if it's not set yet.
116
+ *
117
+ * @private
118
+ * @param {Object} options
119
+ * @param {String|null} [options.type] The type of the list style. If `null` is specified, the function does nothing.
120
+ */
121
+ _tryToConvertItemsToList( options ) {
122
+ if ( !options.type ) {
123
+ return;
124
+ }
125
+
126
+ const listType = getListTypeFromListStyleType( options.type );
127
+
128
+ if ( !listType ) {
129
+ return;
130
+ }
131
+
132
+ const editor = this.editor;
133
+ const commandName = listType + 'List';
134
+ const command = editor.commands.get( commandName );
135
+
136
+ if ( !command.value ) {
137
+ editor.execute( commandName );
138
+ }
139
+ }
140
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2022, 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
+ /**
7
+ * @module list/documentlistproperties/utils/style
8
+ */
9
+
10
+ const BULLETED_LIST_STYLE_TYPES = [ 'disc', 'circle', 'square' ];
11
+
12
+ // There's a lot of them (https://www.w3.org/TR/css-counter-styles-3/#typedef-counter-style).
13
+ // Let's support only those that can be selected by ListPropertiesUI.
14
+ const NUMBERED_LIST_STYLE_TYPES = [
15
+ 'decimal',
16
+ 'decimal-leading-zero',
17
+ 'lower-roman',
18
+ 'upper-roman',
19
+ 'lower-latin',
20
+ 'upper-latin',
21
+ 'lower-alpha',
22
+ 'upper-alpha'
23
+ ];
24
+
25
+ /**
26
+ * Checks whether the given list-style-type is supported by numbered or bulleted list.
27
+ *
28
+ * @param {String} listStyleType
29
+ * @returns {'bulleted'|'numbered'|null}
30
+ */
31
+ export function getListTypeFromListStyleType( listStyleType ) {
32
+ if ( BULLETED_LIST_STYLE_TYPES.includes( listStyleType ) ) {
33
+ return 'bulleted';
34
+ }
35
+
36
+ if ( NUMBERED_LIST_STYLE_TYPES.includes( listStyleType ) ) {
37
+ return 'numbered';
38
+ }
39
+
40
+ return null;
41
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2022, 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
+ /**
7
+ * @module list/documentlistproperties
8
+ */
9
+
10
+ import { Plugin } from 'ckeditor5/src/core';
11
+ import DocumentListPropertiesEditing from './documentlistproperties/documentlistpropertiesediting';
12
+ import ListPropertiesUI from './listproperties/listpropertiesui';
13
+
14
+ /**
15
+ * The document list properties feature.
16
+ *
17
+ * This is a "glue" plugin that loads the
18
+ * {@link module:list/documentlistproperties/documentlistpropertiesediting~DocumentListPropertiesEditing document list properties
19
+ * editing feature} and the {@link module:list/listproperties/listpropertiesui~ListPropertiesUI list properties UI feature}.
20
+ *
21
+ * @extends module:core/plugin~Plugin
22
+ */
23
+ export default class DocumentListProperties extends Plugin {
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get requires() {
28
+ return [ DocumentListPropertiesEditing, ListPropertiesUI ];
29
+ }
30
+
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ static get pluginName() {
35
+ return 'DocumentListProperties';
36
+ }
37
+ }
@@ -218,6 +218,10 @@ export function modelViewChangeIndent( model ) {
218
218
  * @param {module:engine/conversion/downcastdispatcher~DowncastConversionApi} conversionApi Conversion interface.
219
219
  */
220
220
  export function modelViewSplitOnInsert( evt, data, conversionApi ) {
221
+ if ( !conversionApi.consumable.test( data.item, evt.name ) ) {
222
+ return;
223
+ }
224
+
221
225
  if ( data.item.name != 'listItem' ) {
222
226
  let viewPosition = conversionApi.mapper.toViewPosition( data.range.start );
223
227
 
@@ -171,19 +171,18 @@ export default class ListEditing extends Plugin {
171
171
  evt.stop();
172
172
  }, { context: 'li' } );
173
173
 
174
- const getCommandExecuter = commandName => {
175
- return ( data, cancel ) => {
176
- const command = this.editor.commands.get( commandName );
177
-
178
- if ( command.isEnabled ) {
179
- this.editor.execute( commandName );
180
- cancel();
181
- }
182
- };
183
- };
184
-
185
- editor.keystrokes.set( 'Tab', getCommandExecuter( 'indentList' ) );
186
- editor.keystrokes.set( 'Shift+Tab', getCommandExecuter( 'outdentList' ) );
174
+ this.listenTo( editor.editing.view.document, 'tab', ( evt, data ) => {
175
+ const commandName = data.shiftKey ? 'outdentList' : 'indentList';
176
+ const command = this.editor.commands.get( commandName );
177
+
178
+ if ( command.isEnabled ) {
179
+ editor.execute( commandName );
180
+
181
+ data.stopPropagation();
182
+ data.preventDefault();
183
+ evt.stop();
184
+ }
185
+ }, { context: 'li' } );
187
186
  }
188
187
 
189
188
  /**
package/src/list.js CHANGED
@@ -37,7 +37,8 @@ export default class List extends Plugin {
37
37
  }
38
38
 
39
39
  /**
40
- * The configuration of the {@link module:list/list~List list} feature.
40
+ * The configuration of the {@link module:list/list~List list} feature
41
+ * and the {@link module:list/documentlist~DocumentList document list} feature.
41
42
  *
42
43
  * ClassicEditor
43
44
  * .create( editorElement, {
@@ -52,7 +53,7 @@ export default class List extends Plugin {
52
53
  */
53
54
 
54
55
  /**
55
- * The configuration of the {@link module:list/list~List} feature.
56
+ * The configuration of the {@link module:list/list~List} feature and the {@link module:list/documentlist~DocumentList} feature.
56
57
  *
57
58
  * Read more in {@link module:list/list~ListConfig}.
58
59
  *
@@ -626,7 +626,7 @@ function fixListAttributesOnListItemElements( editor, attributeStrategies ) {
626
626
  // ■ List item 1.
627
627
  // ■ Paragraph[] // <-- The inserted item.
628
628
  if ( !existingListItem || !existingListItem.is( 'element', 'listItem' ) ) {
629
- existingListItem = insertedListItems[ insertedListItems.length - 1 ].previousSibling;
629
+ existingListItem = insertedListItems[ 0 ].previousSibling;
630
630
 
631
631
  if ( existingListItem ) {
632
632
  const indent = insertedListItems[ 0 ].getAttribute( 'listIndent' );
@@ -30,9 +30,9 @@ export default class ListReversedCommand extends Command {
30
30
  /**
31
31
  * Executes the command.
32
32
  *
33
+ * @fires execute
33
34
  * @param {Object} options
34
35
  * @param {Boolean} [options.reversed=false] Whether the list should be reversed.
35
- * @protected
36
36
  */
37
37
  execute( options = {} ) {
38
38
  const model = this.editor.model;
@@ -29,9 +29,9 @@ export default class ListStartCommand extends Command {
29
29
  /**
30
30
  * Executes the command.
31
31
  *
32
+ * @fires execute
32
33
  * @param {Object} options
33
34
  * @param {Number} [options.startIndex=1] The list start index.
34
- * @protected
35
35
  */
36
36
  execute( options = {} ) {
37
37
  const model = this.editor.model;
@@ -50,10 +50,10 @@ export default class ListStyleCommand extends Command {
50
50
  /**
51
51
  * Executes the command.
52
52
  *
53
+ * @fires execute
53
54
  * @param {Object} options
54
55
  * @param {String|null} [options.type] The type of the list style, e.g. `'disc'` or `'square'`. If `null` is specified, the default
55
56
  * style will be applied.
56
- * @protected
57
57
  */
58
58
  execute( options = {} ) {
59
59
  this._tryToConvertItemsToList( options );
@@ -36,13 +36,17 @@ export default class ListProperties extends Plugin {
36
36
  }
37
37
 
38
38
  /**
39
- * The configuration of the {@link module:list/listproperties~ListProperties list properties} feature.
39
+ * The configuration of the {@link module:list/listproperties~ListProperties list properties} feature and the
40
+ * {@link module:list/documentlistproperties~DocumentListProperties document list properties} feature.
40
41
  *
41
42
  * This configuration controls the individual list properties. For instance, it enables or disables specific editor commands
42
- * operating on lists ({@link module:list/listproperties/liststylecommand~ListStyleCommand `listStyle`},
43
- * {@link module:list/listproperties/liststartcommand~ListStartCommand `listStart`},
44
- * {@link module:list/listproperties/listreversedcommand~ListReversedCommand `listReversed`}), the look of the UI
45
- * (`numberedList` and `bulletedList` dropdowns), and the editor data pipeline (allowed HTML attributes).
43
+ * operating on lists ({@link module:list/listproperties/liststylecommand~ListStyleCommand `'listStyle'`},
44
+ * {@link module:list/listproperties/liststartcommand~ListStartCommand `'listStart'`},
45
+ * {@link module:list/listproperties/listreversedcommand~ListReversedCommand `'listReversed'`}, or on the document lists
46
+ * {@link module:list/documentlistproperties/documentliststylecommand~DocumentListStyleCommand `'listStyle'`},
47
+ * {@link module:list/documentlistproperties/documentliststartcommand~DocumentListStartCommand `'listStart'`},
48
+ * {@link module:list/documentlistproperties/documentlistreversedcommand~DocumentListReversedCommand `'listReversed'`}), the look of the UI
49
+ * (`'numberedList'` and `'bulletedList'` dropdowns), and the editor data pipeline (allowed HTML attributes).
46
50
  *
47
51
  * ClassicEditor
48
52
  * .create( editorElement, {
@@ -88,7 +92,8 @@ export default class ListProperties extends Plugin {
88
92
  */
89
93
 
90
94
  /**
91
- * The configuration of the {@link module:list/listproperties~ListProperties} feature.
95
+ * The configuration of the {@link module:list/listproperties~ListProperties} feature and the
96
+ * {@link module:list/documentlistproperties~DocumentListProperties document list properties} feature.
92
97
  *
93
98
  * Read more in {@link module:list/listproperties~ListPropertiesConfig}.
94
99
  *
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2003-2022, 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
+ .ck-editor__editable .ck-list-bogus-paragraph {
7
+ display: block;
8
+ }
File without changes