@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,20 +1,15 @@
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/listpropertiesui
8
7
  */
9
-
10
8
  import { Plugin } from 'ckeditor5/src/core';
11
9
  import { ButtonView, SplitButtonView, createDropdown, focusChildOnDropdownOpen } from 'ckeditor5/src/ui';
12
-
13
10
  import ListPropertiesView from './ui/listpropertiesview';
14
-
15
11
  import bulletedListIcon from '../../theme/icons/bulletedlist.svg';
16
12
  import numberedListIcon from '../../theme/icons/numberedlist.svg';
17
-
18
13
  import listStyleDiscIcon from '../../theme/icons/liststyledisc.svg';
19
14
  import listStyleCircleIcon from '../../theme/icons/liststylecircle.svg';
20
15
  import listStyleSquareIcon from '../../theme/icons/liststylesquare.svg';
@@ -24,306 +19,259 @@ import listStyleLowerRomanIcon from '../../theme/icons/liststylelowerroman.svg';
24
19
  import listStyleUpperRomanIcon from '../../theme/icons/liststyleupperroman.svg';
25
20
  import listStyleLowerLatinIcon from '../../theme/icons/liststylelowerlatin.svg';
26
21
  import listStyleUpperLatinIcon from '../../theme/icons/liststyleupperlatin.svg';
27
-
28
22
  import '../../theme/liststyles.css';
29
-
30
23
  /**
31
24
  * The list properties UI plugin. It introduces the extended `'bulletedList'` and `'numberedList'` toolbar
32
25
  * buttons that allow users to control such aspects of list as the marker, start index or order.
33
26
  *
34
27
  * **Note**: Buttons introduced by this plugin override implementations from the {@link module:list/list/listui~ListUI}
35
28
  * (because they share the same names).
36
- *
37
- * @extends module:core/plugin~Plugin
38
29
  */
39
30
  export default class ListPropertiesUI extends Plugin {
40
- /**
41
- * @inheritDoc
42
- */
43
- static get pluginName() {
44
- return 'ListPropertiesUI';
45
- }
46
-
47
- init() {
48
- const editor = this.editor;
49
- const t = editor.locale.t;
50
- const enabledProperties = editor.config.get( 'list.properties' );
51
-
52
- // Note: When this plugin does not register the "bulletedList" dropdown due to properties configuration,
53
- // a simple button will be still registered under the same name by ListUI as a fallback. This should happen
54
- // in most editor configuration because the List plugin automatically requires ListUI.
55
- if ( enabledProperties.styles ) {
56
- editor.ui.componentFactory.add( 'bulletedList', getDropdownViewCreator( {
57
- editor,
58
- parentCommandName: 'bulletedList',
59
- buttonLabel: t( 'Bulleted List' ),
60
- buttonIcon: bulletedListIcon,
61
- styleGridAriaLabel: t( 'Bulleted list styles toolbar' ),
62
- styleDefinitions: [
63
- {
64
- label: t( 'Toggle the disc list style' ),
65
- tooltip: t( 'Disc' ),
66
- type: 'disc',
67
- icon: listStyleDiscIcon
68
- },
69
- {
70
- label: t( 'Toggle the circle list style' ),
71
- tooltip: t( 'Circle' ),
72
- type: 'circle',
73
- icon: listStyleCircleIcon
74
- },
75
- {
76
- label: t( 'Toggle the square list style' ),
77
- tooltip: t( 'Square' ),
78
- type: 'square',
79
- icon: listStyleSquareIcon
80
- }
81
- ]
82
- } ) );
83
- }
84
-
85
- // Note: When this plugin does not register the "numberedList" dropdown due to properties configuration,
86
- // a simple button will be still registered under the same name by ListUI as a fallback. This should happen
87
- // in most editor configuration because the List plugin automatically requires ListUI.
88
- if ( enabledProperties.styles || enabledProperties.startIndex || enabledProperties.reversed ) {
89
- editor.ui.componentFactory.add( 'numberedList', getDropdownViewCreator( {
90
- editor,
91
- parentCommandName: 'numberedList',
92
- buttonLabel: t( 'Numbered List' ),
93
- buttonIcon: numberedListIcon,
94
- styleGridAriaLabel: t( 'Numbered list styles toolbar' ),
95
- styleDefinitions: [
96
- {
97
- label: t( 'Toggle the decimal list style' ),
98
- tooltip: t( 'Decimal' ),
99
- type: 'decimal',
100
- icon: listStyleDecimalIcon
101
- },
102
- {
103
- label: t( 'Toggle the decimal with leading zero list style' ),
104
- tooltip: t( 'Decimal with leading zero' ),
105
- type: 'decimal-leading-zero',
106
- icon: listStyleDecimalWithLeadingZeroIcon
107
- },
108
- {
109
- label: t( 'Toggle the lower–roman list style' ),
110
- tooltip: t( 'Lower–roman' ),
111
- type: 'lower-roman',
112
- icon: listStyleLowerRomanIcon
113
- },
114
- {
115
- label: t( 'Toggle the upper–roman list style' ),
116
- tooltip: t( 'Upper-roman' ),
117
- type: 'upper-roman',
118
- icon: listStyleUpperRomanIcon
119
- },
120
- {
121
- label: t( 'Toggle the lower–latin list style' ),
122
- tooltip: t( 'Lower-latin' ),
123
- type: 'lower-latin',
124
- icon: listStyleLowerLatinIcon
125
- },
126
- {
127
- label: t( 'Toggle the upper–latin list style' ),
128
- tooltip: t( 'Upper-latin' ),
129
- type: 'upper-latin',
130
- icon: listStyleUpperLatinIcon
131
- }
132
- ]
133
- } ) );
134
- }
135
- }
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ static get pluginName() {
35
+ return 'ListPropertiesUI';
36
+ }
37
+ init() {
38
+ const editor = this.editor;
39
+ const t = editor.locale.t;
40
+ const enabledProperties = editor.config.get('list.properties');
41
+ // Note: When this plugin does not register the "bulletedList" dropdown due to properties configuration,
42
+ // a simple button will be still registered under the same name by ListUI as a fallback. This should happen
43
+ // in most editor configuration because the List plugin automatically requires ListUI.
44
+ if (enabledProperties.styles) {
45
+ editor.ui.componentFactory.add('bulletedList', getDropdownViewCreator({
46
+ editor,
47
+ parentCommandName: 'bulletedList',
48
+ buttonLabel: t('Bulleted List'),
49
+ buttonIcon: bulletedListIcon,
50
+ styleGridAriaLabel: t('Bulleted list styles toolbar'),
51
+ styleDefinitions: [
52
+ {
53
+ label: t('Toggle the disc list style'),
54
+ tooltip: t('Disc'),
55
+ type: 'disc',
56
+ icon: listStyleDiscIcon
57
+ },
58
+ {
59
+ label: t('Toggle the circle list style'),
60
+ tooltip: t('Circle'),
61
+ type: 'circle',
62
+ icon: listStyleCircleIcon
63
+ },
64
+ {
65
+ label: t('Toggle the square list style'),
66
+ tooltip: t('Square'),
67
+ type: 'square',
68
+ icon: listStyleSquareIcon
69
+ }
70
+ ]
71
+ }));
72
+ }
73
+ // Note: When this plugin does not register the "numberedList" dropdown due to properties configuration,
74
+ // a simple button will be still registered under the same name by ListUI as a fallback. This should happen
75
+ // in most editor configuration because the List plugin automatically requires ListUI.
76
+ if (enabledProperties.styles || enabledProperties.startIndex || enabledProperties.reversed) {
77
+ editor.ui.componentFactory.add('numberedList', getDropdownViewCreator({
78
+ editor,
79
+ parentCommandName: 'numberedList',
80
+ buttonLabel: t('Numbered List'),
81
+ buttonIcon: numberedListIcon,
82
+ styleGridAriaLabel: t('Numbered list styles toolbar'),
83
+ styleDefinitions: [
84
+ {
85
+ label: t('Toggle the decimal list style'),
86
+ tooltip: t('Decimal'),
87
+ type: 'decimal',
88
+ icon: listStyleDecimalIcon
89
+ },
90
+ {
91
+ label: t('Toggle the decimal with leading zero list style'),
92
+ tooltip: t('Decimal with leading zero'),
93
+ type: 'decimal-leading-zero',
94
+ icon: listStyleDecimalWithLeadingZeroIcon
95
+ },
96
+ {
97
+ label: t('Toggle the lower–roman list style'),
98
+ tooltip: t('Lower–roman'),
99
+ type: 'lower-roman',
100
+ icon: listStyleLowerRomanIcon
101
+ },
102
+ {
103
+ label: t('Toggle the upper–roman list style'),
104
+ tooltip: t('Upper-roman'),
105
+ type: 'upper-roman',
106
+ icon: listStyleUpperRomanIcon
107
+ },
108
+ {
109
+ label: t('Toggle the lower–latin list style'),
110
+ tooltip: t('Lower-latin'),
111
+ type: 'lower-latin',
112
+ icon: listStyleLowerLatinIcon
113
+ },
114
+ {
115
+ label: t('Toggle the upper–latin list style'),
116
+ tooltip: t('Upper-latin'),
117
+ type: 'upper-latin',
118
+ icon: listStyleUpperLatinIcon
119
+ }
120
+ ]
121
+ }));
122
+ }
123
+ }
136
124
  }
137
-
138
- // A helper that returns a function that creates a split button with a toolbar in the dropdown,
139
- // which in turn contains buttons allowing users to change list styles in the context of the current selection.
140
- //
141
- // @param {Object} options
142
- // @param {module:core/editor/editor~Editor} options.editor
143
- // @param {'bulletedList'|'numberedList'} options.parentCommandName The name of the higher-order editor command associated with
144
- // the set of particular list styles (e.g. "bulletedList" for "disc", "circle", and "square" styles).
145
- // @param {String} options.buttonLabel Label of the main part of the split button.
146
- // @param {String} options.buttonIcon The SVG string of an icon for the main part of the split button.
147
- // @param {String} options.styleGridAriaLabel The ARIA label for the styles grid in the split button dropdown.
148
- // @param {Object} options.styleDefinitions Definitions of the style buttons.
149
- // @returns {Function} A function that can be passed straight into {@link module:ui/componentfactory~ComponentFactory#add}.
150
- function getDropdownViewCreator( { editor, parentCommandName, buttonLabel, buttonIcon, styleGridAriaLabel, styleDefinitions } ) {
151
- const parentCommand = editor.commands.get( parentCommandName );
152
-
153
- // @param {module:utils/locale~Locale} locale
154
- // @returns {module:ui/dropdown/dropdownview~DropdownView}
155
- return locale => {
156
- const dropdownView = createDropdown( locale, SplitButtonView );
157
- const mainButtonView = dropdownView.buttonView;
158
-
159
- dropdownView.bind( 'isEnabled' ).to( parentCommand );
160
- dropdownView.class = 'ck-list-styles-dropdown';
161
-
162
- // Main button was clicked.
163
- mainButtonView.on( 'execute', () => {
164
- editor.execute( parentCommandName );
165
- editor.editing.view.focus();
166
- } );
167
-
168
- mainButtonView.set( {
169
- label: buttonLabel,
170
- icon: buttonIcon,
171
- tooltip: true,
172
- isToggleable: true
173
- } );
174
-
175
- mainButtonView.bind( 'isOn' ).to( parentCommand, 'value', value => !!value );
176
-
177
- const listPropertiesView = createListPropertiesView( {
178
- editor,
179
- dropdownView,
180
- parentCommandName,
181
- styleGridAriaLabel,
182
- styleDefinitions
183
- } );
184
-
185
- dropdownView.panelView.children.add( listPropertiesView );
186
-
187
- // Focus the editable after executing the command.
188
- // Overrides a default behaviour where the focus is moved to the dropdown button (#12125).
189
- dropdownView.on( 'execute', () => {
190
- editor.editing.view.focus();
191
- } );
192
-
193
- return dropdownView;
194
- };
125
+ /**
126
+ * A helper that returns a function that creates a split button with a toolbar in the dropdown,
127
+ * which in turn contains buttons allowing users to change list styles in the context of the current selection.
128
+ *
129
+ * @param options.editor
130
+ * @param options.parentCommandName The name of the higher-order editor command associated with
131
+ * the set of particular list styles (e.g. "bulletedList" for "disc", "circle", and "square" styles).
132
+ * @param options.buttonLabel Label of the main part of the split button.
133
+ * @param options.buttonIcon The SVG string of an icon for the main part of the split button.
134
+ * @param options.styleGridAriaLabel The ARIA label for the styles grid in the split button dropdown.
135
+ * @param options.styleDefinitions Definitions of the style buttons.
136
+ * @returns A function that can be passed straight into {@link module:ui/componentfactory~ComponentFactory#add}.
137
+ */
138
+ function getDropdownViewCreator({ editor, parentCommandName, buttonLabel, buttonIcon, styleGridAriaLabel, styleDefinitions }) {
139
+ const parentCommand = editor.commands.get(parentCommandName);
140
+ return (locale) => {
141
+ const dropdownView = createDropdown(locale, SplitButtonView);
142
+ const mainButtonView = dropdownView.buttonView;
143
+ dropdownView.bind('isEnabled').to(parentCommand);
144
+ dropdownView.class = 'ck-list-styles-dropdown';
145
+ // Main button was clicked.
146
+ mainButtonView.on('execute', () => {
147
+ editor.execute(parentCommandName);
148
+ editor.editing.view.focus();
149
+ });
150
+ mainButtonView.set({
151
+ label: buttonLabel,
152
+ icon: buttonIcon,
153
+ tooltip: true,
154
+ isToggleable: true
155
+ });
156
+ mainButtonView.bind('isOn').to(parentCommand, 'value', value => !!value);
157
+ dropdownView.once('change:isOpen', () => {
158
+ const listPropertiesView = createListPropertiesView({
159
+ editor,
160
+ dropdownView,
161
+ parentCommandName,
162
+ styleGridAriaLabel,
163
+ styleDefinitions
164
+ });
165
+ dropdownView.panelView.children.add(listPropertiesView);
166
+ });
167
+ // Focus the editable after executing the command.
168
+ // Overrides a default behaviour where the focus is moved to the dropdown button (#12125).
169
+ dropdownView.on('execute', () => {
170
+ editor.editing.view.focus();
171
+ });
172
+ return dropdownView;
173
+ };
195
174
  }
196
-
197
- // A helper that returns a function (factory) that creates individual buttons used by users to change styles
198
- // of lists.
199
- //
200
- // @param {Object} options
201
- // @param {module:core/editor/editor~Editor} options.editor
202
- // @param {module:list/liststylecommand~ListStylesCommand} options.listStyleCommand The instance of the `ListStylesCommand` class.
203
- // @param {'bulletedList'|'numberedList'} options.parentCommandName The name of the higher-order command associated with a
204
- // particular list style (e.g. "bulletedList" is associated with "square" and "numberedList" is associated with "roman").
205
- // @returns {Function} A function that can be passed straight into {@link module:ui/componentfactory~ComponentFactory#add}.
206
- function getStyleButtonCreator( { editor, listStyleCommand, parentCommandName } ) {
207
- const locale = editor.locale;
208
- const parentCommand = editor.commands.get( parentCommandName );
209
-
210
- // @param {String} label The label of the style button.
211
- // @param {String} type The type of the style button (e.g. "roman" or "circle").
212
- // @param {String} icon The SVG string of an icon of the style button.
213
- // @param {String} tooltip The tooltip text of the button (shorter than verbose label).
214
- // @returns {module:ui/button/buttonview~ButtonView}
215
- return ( { label, type, icon, tooltip } ) => {
216
- const button = new ButtonView( locale );
217
-
218
- button.set( { label, icon, tooltip } );
219
-
220
- listStyleCommand.on( 'change:value', () => {
221
- button.isOn = listStyleCommand.value === type;
222
- } );
223
-
224
- button.on( 'execute', () => {
225
- // If the content the selection is anchored to is a list, let's change its style.
226
- if ( parentCommand.value ) {
227
- // If the current list style is not set in the model or the style is different than the
228
- // one to be applied, simply apply the new style.
229
- if ( listStyleCommand.value !== type ) {
230
- editor.execute( 'listStyle', { type } );
231
- }
232
- // If the style was the same, remove it (the button works as an off toggle).
233
- else {
234
- editor.execute( 'listStyle', { type: listStyleCommand._defaultType } );
235
- }
236
- }
237
- // Otherwise, leave the creation of the styled list to the `ListStyleCommand`.
238
- else {
239
- editor.model.change( () => {
240
- editor.execute( 'listStyle', { type } );
241
- } );
242
- }
243
- } );
244
-
245
- return button;
246
- };
175
+ /**
176
+ * A helper that returns a function (factory) that creates individual buttons used by users to change styles
177
+ * of lists.
178
+ *
179
+ * @param options.editor
180
+ * @param options.listStyleCommand The instance of the `ListStylesCommand` class.
181
+ * @param options.parentCommandName The name of the higher-order command associated with a
182
+ * particular list style (e.g. "bulletedList" is associated with "square" and "numberedList" is associated with "roman").
183
+ * @returns A function that can be passed straight into {@link module:ui/componentfactory~ComponentFactory#add}.
184
+ */
185
+ function getStyleButtonCreator({ editor, listStyleCommand, parentCommandName }) {
186
+ const locale = editor.locale;
187
+ const parentCommand = editor.commands.get(parentCommandName);
188
+ return ({ label, type, icon, tooltip }) => {
189
+ const button = new ButtonView(locale);
190
+ button.set({ label, icon, tooltip });
191
+ listStyleCommand.on('change:value', () => {
192
+ button.isOn = listStyleCommand.value === type;
193
+ });
194
+ button.on('execute', () => {
195
+ // If the content the selection is anchored to is a list, let's change its style.
196
+ if (parentCommand.value) {
197
+ // If the current list style is not set in the model or the style is different than the
198
+ // one to be applied, simply apply the new style.
199
+ if (listStyleCommand.value !== type) {
200
+ editor.execute('listStyle', { type });
201
+ }
202
+ // If the style was the same, remove it (the button works as an off toggle).
203
+ else {
204
+ editor.execute('listStyle', { type: listStyleCommand.defaultType });
205
+ }
206
+ }
207
+ // Otherwise, leave the creation of the styled list to the `ListStyleCommand`.
208
+ else {
209
+ editor.model.change(() => {
210
+ editor.execute('listStyle', { type });
211
+ });
212
+ }
213
+ });
214
+ return button;
215
+ };
247
216
  }
248
-
249
- // A helper that creates the properties view for the individual style dropdown.
250
- //
251
- // @param {Object} options
252
- // @param {module:core/editor/editor~Editor} options.editor Editor instance.
253
- // @param {module:ui/dropdown/dropdownview~DropdownView} options.dropdownView Styles dropdown view that hosts the properties view.
254
- // @param {'bulletedList'|'numberedList'} options.parentCommandName The name of the higher-order editor command associated with
255
- // the set of particular list styles (e.g. "bulletedList" for "disc", "circle", and "square" styles).
256
- // @param {Object} options.styleDefinitions Definitions of the style buttons.
257
- // @param {String} options.styleGridAriaLabel An assistive technologies label set on the grid of styles (if the grid is rendered).
258
- // @returns {module:list/ui/listpropertiesview~ListPropertiesView}
259
- function createListPropertiesView( {
260
- editor,
261
- dropdownView,
262
- parentCommandName,
263
- styleDefinitions,
264
- styleGridAriaLabel
265
- } ) {
266
- const locale = editor.locale;
267
- const enabledProperties = editor.config.get( 'list.properties' );
268
- let styleButtonViews;
269
-
270
- if ( parentCommandName != 'numberedList' ) {
271
- enabledProperties.startIndex = false;
272
- enabledProperties.reversed = false;
273
- }
274
-
275
- if ( enabledProperties.styles ) {
276
- const listStyleCommand = editor.commands.get( 'listStyle' );
277
-
278
- const styleButtonCreator = getStyleButtonCreator( {
279
- editor,
280
- parentCommandName,
281
- listStyleCommand
282
- } );
283
-
284
- // The command can be ListStyleCommand or DocumentListStyleCommand.
285
- const isStyleTypeSupported = typeof listStyleCommand.isStyleTypeSupported == 'function' ?
286
- styleDefinition => listStyleCommand.isStyleTypeSupported( styleDefinition.type ) :
287
- () => true;
288
-
289
- styleButtonViews = styleDefinitions.filter( isStyleTypeSupported ).map( styleButtonCreator );
290
- }
291
-
292
- const listPropertiesView = new ListPropertiesView( locale, {
293
- styleGridAriaLabel,
294
- enabledProperties,
295
- styleButtonViews
296
- } );
297
-
298
- if ( enabledProperties.styles ) {
299
- // Accessibility: focus the first active style when opening the dropdown.
300
- focusChildOnDropdownOpen( dropdownView, () => {
301
- return listPropertiesView.stylesView.children.find( child => child.isOn );
302
- } );
303
- }
304
-
305
- if ( enabledProperties.startIndex ) {
306
- const listStartCommand = editor.commands.get( 'listStart' );
307
-
308
- listPropertiesView.startIndexFieldView.bind( 'isEnabled' ).to( listStartCommand );
309
- listPropertiesView.startIndexFieldView.fieldView.bind( 'value' ).to( listStartCommand );
310
- listPropertiesView.on( 'listStart', ( evt, data ) => editor.execute( 'listStart', data ) );
311
- }
312
-
313
- if ( enabledProperties.reversed ) {
314
- const listReversedCommand = editor.commands.get( 'listReversed' );
315
-
316
- listPropertiesView.reversedSwitchButtonView.bind( 'isEnabled' ).to( listReversedCommand );
317
- listPropertiesView.reversedSwitchButtonView.bind( 'isOn' ).to( listReversedCommand, 'value' );
318
- listPropertiesView.on( 'listReversed', () => {
319
- const isReversed = listReversedCommand.value;
320
-
321
- editor.execute( 'listReversed', { reversed: !isReversed } );
322
- } );
323
- }
324
-
325
- // Make sure applying styles closes the dropdown.
326
- listPropertiesView.delegate( 'execute' ).to( dropdownView );
327
-
328
- return listPropertiesView;
217
+ /**
218
+ * A helper that creates the properties view for the individual style dropdown.
219
+ *
220
+ * @param options.editor Editor instance.
221
+ * @param options.dropdownView Styles dropdown view that hosts the properties view.
222
+ * @param options.parentCommandName The name of the higher-order editor command associated with
223
+ * the set of particular list styles (e.g. "bulletedList" for "disc", "circle", and "square" styles).
224
+ * @param options.styleDefinitions Definitions of the style buttons.
225
+ * @param options.styleGridAriaLabel An assistive technologies label set on the grid of styles (if the grid is rendered).
226
+ */
227
+ function createListPropertiesView({ editor, dropdownView, parentCommandName, styleDefinitions, styleGridAriaLabel }) {
228
+ const locale = editor.locale;
229
+ const enabledProperties = editor.config.get('list.properties');
230
+ let styleButtonViews = null;
231
+ if (parentCommandName != 'numberedList') {
232
+ enabledProperties.startIndex = false;
233
+ enabledProperties.reversed = false;
234
+ }
235
+ if (enabledProperties.styles) {
236
+ const listStyleCommand = editor.commands.get('listStyle');
237
+ const styleButtonCreator = getStyleButtonCreator({
238
+ editor,
239
+ parentCommandName,
240
+ listStyleCommand
241
+ });
242
+ // The command can be ListStyleCommand or DocumentListStyleCommand.
243
+ const isStyleTypeSupported = typeof listStyleCommand.isStyleTypeSupported == 'function' ?
244
+ (styleDefinition) => listStyleCommand.isStyleTypeSupported(styleDefinition.type) :
245
+ () => true;
246
+ styleButtonViews = styleDefinitions.filter(isStyleTypeSupported).map(styleButtonCreator);
247
+ }
248
+ const listPropertiesView = new ListPropertiesView(locale, {
249
+ styleGridAriaLabel,
250
+ enabledProperties,
251
+ styleButtonViews
252
+ });
253
+ if (enabledProperties.styles) {
254
+ // Accessibility: focus the first active style when opening the dropdown.
255
+ focusChildOnDropdownOpen(dropdownView, () => {
256
+ return listPropertiesView.stylesView.children.find((child) => child.isOn);
257
+ });
258
+ }
259
+ if (enabledProperties.startIndex) {
260
+ const listStartCommand = editor.commands.get('listStart');
261
+ listPropertiesView.startIndexFieldView.bind('isEnabled').to(listStartCommand);
262
+ listPropertiesView.startIndexFieldView.fieldView.bind('value').to(listStartCommand);
263
+ listPropertiesView.on('listStart', (evt, data) => editor.execute('listStart', data));
264
+ }
265
+ if (enabledProperties.reversed) {
266
+ const listReversedCommand = editor.commands.get('listReversed');
267
+ listPropertiesView.reversedSwitchButtonView.bind('isEnabled').to(listReversedCommand);
268
+ listPropertiesView.reversedSwitchButtonView.bind('isOn').to(listReversedCommand, 'value', value => !!value);
269
+ listPropertiesView.on('listReversed', () => {
270
+ const isReversed = listReversedCommand.value;
271
+ editor.execute('listReversed', { reversed: !isReversed });
272
+ });
273
+ }
274
+ // Make sure applying styles closes the dropdown.
275
+ listPropertiesView.delegate('execute').to(dropdownView);
276
+ return listPropertiesView;
329
277
  }