@ckeditor/ckeditor5-list 39.0.1 → 40.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 (173) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/LICENSE.md +1 -1
  3. package/README.md +4 -4
  4. package/build/list.js +1 -1
  5. package/build/list.js.map +1 -0
  6. package/build/translations/fi.js +1 -1
  7. package/build/translations/pt-br.js +1 -1
  8. package/ckeditor5-metadata.json +44 -0
  9. package/lang/translations/ar.po +1 -0
  10. package/lang/translations/ast.po +1 -0
  11. package/lang/translations/az.po +1 -0
  12. package/lang/translations/bg.po +1 -0
  13. package/lang/translations/bn.po +1 -0
  14. package/lang/translations/ca.po +1 -0
  15. package/lang/translations/cs.po +1 -0
  16. package/lang/translations/da.po +1 -0
  17. package/lang/translations/de-ch.po +1 -0
  18. package/lang/translations/de.po +1 -0
  19. package/lang/translations/el.po +1 -0
  20. package/lang/translations/en-au.po +1 -0
  21. package/lang/translations/en-gb.po +1 -0
  22. package/lang/translations/en.po +1 -0
  23. package/lang/translations/eo.po +1 -0
  24. package/lang/translations/es.po +1 -0
  25. package/lang/translations/et.po +1 -0
  26. package/lang/translations/eu.po +1 -0
  27. package/lang/translations/fa.po +1 -0
  28. package/lang/translations/fi.po +2 -1
  29. package/lang/translations/fr.po +1 -0
  30. package/lang/translations/gl.po +1 -0
  31. package/lang/translations/he.po +1 -0
  32. package/lang/translations/hi.po +1 -0
  33. package/lang/translations/hr.po +1 -0
  34. package/lang/translations/hu.po +1 -0
  35. package/lang/translations/id.po +1 -0
  36. package/lang/translations/it.po +1 -0
  37. package/lang/translations/ja.po +1 -0
  38. package/lang/translations/jv.po +1 -0
  39. package/lang/translations/km.po +1 -0
  40. package/lang/translations/kn.po +1 -0
  41. package/lang/translations/ko.po +1 -0
  42. package/lang/translations/ku.po +1 -0
  43. package/lang/translations/lt.po +1 -0
  44. package/lang/translations/lv.po +1 -0
  45. package/lang/translations/ms.po +1 -0
  46. package/lang/translations/nb.po +1 -0
  47. package/lang/translations/ne.po +1 -0
  48. package/lang/translations/nl.po +1 -0
  49. package/lang/translations/no.po +1 -0
  50. package/lang/translations/pl.po +1 -0
  51. package/lang/translations/pt-br.po +11 -10
  52. package/lang/translations/pt.po +1 -0
  53. package/lang/translations/ro.po +1 -0
  54. package/lang/translations/ru.po +1 -0
  55. package/lang/translations/si.po +1 -0
  56. package/lang/translations/sk.po +1 -0
  57. package/lang/translations/sq.po +1 -0
  58. package/lang/translations/sr-latn.po +1 -0
  59. package/lang/translations/sr.po +1 -0
  60. package/lang/translations/sv.po +1 -0
  61. package/lang/translations/th.po +1 -0
  62. package/lang/translations/tk.po +1 -0
  63. package/lang/translations/tr.po +1 -0
  64. package/lang/translations/tt.po +1 -0
  65. package/lang/translations/ug.po +1 -0
  66. package/lang/translations/uk.po +1 -0
  67. package/lang/translations/ur.po +1 -0
  68. package/lang/translations/uz.po +1 -0
  69. package/lang/translations/vi.po +1 -0
  70. package/lang/translations/zh-cn.po +1 -0
  71. package/lang/translations/zh.po +1 -0
  72. package/package.json +3 -7
  73. package/src/augmentation.d.ts +52 -50
  74. package/src/augmentation.js +5 -5
  75. package/src/documentlist/adjacentlistssupport.d.ts +15 -15
  76. package/src/documentlist/adjacentlistssupport.js +81 -81
  77. package/src/documentlist/converters.d.ts +65 -63
  78. package/src/documentlist/converters.js +441 -354
  79. package/src/documentlist/documentlistcommand.d.ts +80 -80
  80. package/src/documentlist/documentlistcommand.js +150 -145
  81. package/src/documentlist/documentlistediting.d.ts +212 -154
  82. package/src/documentlist/documentlistediting.js +645 -565
  83. package/src/documentlist/documentlistindentcommand.d.ts +62 -62
  84. package/src/documentlist/documentlistindentcommand.js +129 -129
  85. package/src/documentlist/documentlistmergecommand.d.ts +76 -76
  86. package/src/documentlist/documentlistmergecommand.js +174 -174
  87. package/src/documentlist/documentlistsplitcommand.d.ts +67 -67
  88. package/src/documentlist/documentlistsplitcommand.js +70 -70
  89. package/src/documentlist/documentlistutils.d.ts +46 -46
  90. package/src/documentlist/documentlistutils.js +50 -50
  91. package/src/documentlist/utils/listwalker.d.ts +145 -141
  92. package/src/documentlist/utils/listwalker.js +182 -162
  93. package/src/documentlist/utils/model.d.ts +202 -193
  94. package/src/documentlist/utils/model.js +455 -435
  95. package/src/documentlist/utils/postfixers.d.ts +37 -37
  96. package/src/documentlist/utils/postfixers.js +126 -118
  97. package/src/documentlist/utils/view.d.ts +81 -81
  98. package/src/documentlist/utils/view.js +117 -117
  99. package/src/documentlist.d.ts +26 -26
  100. package/src/documentlist.js +30 -30
  101. package/src/documentlistproperties/converters.d.ts +19 -19
  102. package/src/documentlistproperties/converters.js +43 -43
  103. package/src/documentlistproperties/documentlistpropertiesediting.d.ts +88 -88
  104. package/src/documentlistproperties/documentlistpropertiesediting.js +266 -289
  105. package/src/documentlistproperties/documentlistpropertiesutils.d.ts +33 -33
  106. package/src/documentlistproperties/documentlistpropertiesutils.js +44 -44
  107. package/src/documentlistproperties/documentlistreversedcommand.d.ts +36 -36
  108. package/src/documentlistproperties/documentlistreversedcommand.js +55 -55
  109. package/src/documentlistproperties/documentliststartcommand.d.ts +38 -38
  110. package/src/documentlistproperties/documentliststartcommand.js +57 -57
  111. package/src/documentlistproperties/documentliststylecommand.d.ts +72 -72
  112. package/src/documentlistproperties/documentliststylecommand.js +113 -113
  113. package/src/documentlistproperties/utils/style.d.ts +20 -20
  114. package/src/documentlistproperties/utils/style.js +54 -54
  115. package/src/documentlistproperties.d.ts +27 -27
  116. package/src/documentlistproperties.js +31 -31
  117. package/src/index.d.ts +43 -40
  118. package/src/index.js +29 -27
  119. package/src/list/converters.d.ts +196 -196
  120. package/src/list/converters.js +905 -905
  121. package/src/list/indentcommand.d.ts +37 -37
  122. package/src/list/indentcommand.js +107 -107
  123. package/src/list/listcommand.d.ts +55 -55
  124. package/src/list/listcommand.js +274 -274
  125. package/src/list/listediting.d.ts +32 -32
  126. package/src/list/listediting.js +161 -161
  127. package/src/list/listui.d.ts +19 -19
  128. package/src/list/listui.js +32 -32
  129. package/src/list/listutils.d.ts +41 -41
  130. package/src/list/listutils.js +46 -46
  131. package/src/list/utils.d.ts +112 -112
  132. package/src/list/utils.js +374 -374
  133. package/src/list.d.ts +26 -26
  134. package/src/list.js +30 -30
  135. package/src/listconfig.d.ts +132 -122
  136. package/src/listconfig.js +5 -5
  137. package/src/listproperties/listpropertiesediting.d.ts +72 -72
  138. package/src/listproperties/listpropertiesediting.js +696 -696
  139. package/src/listproperties/listpropertiesui.d.ts +23 -23
  140. package/src/listproperties/listpropertiesui.js +277 -277
  141. package/src/listproperties/listreversedcommand.d.ts +38 -38
  142. package/src/listproperties/listreversedcommand.js +52 -52
  143. package/src/listproperties/liststartcommand.d.ts +37 -37
  144. package/src/listproperties/liststartcommand.js +51 -51
  145. package/src/listproperties/liststylecommand.d.ts +67 -67
  146. package/src/listproperties/liststylecommand.js +99 -99
  147. package/src/listproperties/ui/collapsibleview.d.ts +63 -63
  148. package/src/listproperties/ui/collapsibleview.js +89 -89
  149. package/src/listproperties/ui/listpropertiesview.d.ts +157 -157
  150. package/src/listproperties/ui/listpropertiesview.js +299 -299
  151. package/src/listproperties.d.ts +26 -26
  152. package/src/listproperties.js +30 -30
  153. package/src/liststyle.d.ts +28 -28
  154. package/src/liststyle.js +36 -36
  155. package/src/tododocumentlist/checktododocumentlistcommand.d.ts +49 -0
  156. package/src/tododocumentlist/checktododocumentlistcommand.js +82 -0
  157. package/src/tododocumentlist/todocheckboxchangeobserver.d.ts +41 -0
  158. package/src/tododocumentlist/todocheckboxchangeobserver.js +37 -0
  159. package/src/tododocumentlist/tododocumentlistediting.d.ts +38 -0
  160. package/src/tododocumentlist/tododocumentlistediting.js +399 -0
  161. package/src/tododocumentlist.d.ts +27 -0
  162. package/src/tododocumentlist.js +31 -0
  163. package/src/todolist/checktodolistcommand.d.ts +52 -52
  164. package/src/todolist/checktodolistcommand.js +76 -76
  165. package/src/todolist/todolistconverters.d.ts +82 -82
  166. package/src/todolist/todolistconverters.js +260 -260
  167. package/src/todolist/todolistediting.d.ts +39 -39
  168. package/src/todolist/todolistediting.js +161 -161
  169. package/src/todolist/todolistui.d.ts +19 -19
  170. package/src/todolist/todolistui.js +29 -29
  171. package/src/todolist.d.ts +27 -27
  172. package/src/todolist.js +31 -31
  173. package/theme/todolist.css +101 -70
@@ -1,23 +1,23 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * @module list/listproperties/listpropertiesui
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import '../../theme/liststyles.css';
10
- /**
11
- * The list properties UI plugin. It introduces the extended `'bulletedList'` and `'numberedList'` toolbar
12
- * buttons that allow users to control such aspects of list as the marker, start index or order.
13
- *
14
- * **Note**: Buttons introduced by this plugin override implementations from the {@link module:list/list/listui~ListUI}
15
- * (because they share the same names).
16
- */
17
- export default class ListPropertiesUI extends Plugin {
18
- /**
19
- * @inheritDoc
20
- */
21
- static get pluginName(): "ListPropertiesUI";
22
- init(): void;
23
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * @module list/listproperties/listpropertiesui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import '../../theme/liststyles.css';
10
+ /**
11
+ * The list properties UI plugin. It introduces the extended `'bulletedList'` and `'numberedList'` toolbar
12
+ * buttons that allow users to control such aspects of list as the marker, start index or order.
13
+ *
14
+ * **Note**: Buttons introduced by this plugin override implementations from the {@link module:list/list/listui~ListUI}
15
+ * (because they share the same names).
16
+ */
17
+ export default class ListPropertiesUI extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName(): "ListPropertiesUI";
22
+ init(): void;
23
+ }
@@ -1,277 +1,277 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * @module list/listproperties/listpropertiesui
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { ButtonView, SplitButtonView, createDropdown, focusChildOnDropdownOpen } from 'ckeditor5/src/ui';
10
- import ListPropertiesView from './ui/listpropertiesview';
11
- import bulletedListIcon from '../../theme/icons/bulletedlist.svg';
12
- import numberedListIcon from '../../theme/icons/numberedlist.svg';
13
- import listStyleDiscIcon from '../../theme/icons/liststyledisc.svg';
14
- import listStyleCircleIcon from '../../theme/icons/liststylecircle.svg';
15
- import listStyleSquareIcon from '../../theme/icons/liststylesquare.svg';
16
- import listStyleDecimalIcon from '../../theme/icons/liststyledecimal.svg';
17
- import listStyleDecimalWithLeadingZeroIcon from '../../theme/icons/liststyledecimalleadingzero.svg';
18
- import listStyleLowerRomanIcon from '../../theme/icons/liststylelowerroman.svg';
19
- import listStyleUpperRomanIcon from '../../theme/icons/liststyleupperroman.svg';
20
- import listStyleLowerLatinIcon from '../../theme/icons/liststylelowerlatin.svg';
21
- import listStyleUpperLatinIcon from '../../theme/icons/liststyleupperlatin.svg';
22
- import '../../theme/liststyles.css';
23
- /**
24
- * The list properties UI plugin. It introduces the extended `'bulletedList'` and `'numberedList'` toolbar
25
- * buttons that allow users to control such aspects of list as the marker, start index or order.
26
- *
27
- * **Note**: Buttons introduced by this plugin override implementations from the {@link module:list/list/listui~ListUI}
28
- * (because they share the same names).
29
- */
30
- export default class ListPropertiesUI extends Plugin {
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
- }
124
- }
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
- };
174
- }
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
- };
216
- }
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;
277
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * @module list/listproperties/listpropertiesui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import { ButtonView, SplitButtonView, createDropdown, focusChildOnDropdownOpen } from 'ckeditor5/src/ui';
10
+ import ListPropertiesView from './ui/listpropertiesview';
11
+ import bulletedListIcon from '../../theme/icons/bulletedlist.svg';
12
+ import numberedListIcon from '../../theme/icons/numberedlist.svg';
13
+ import listStyleDiscIcon from '../../theme/icons/liststyledisc.svg';
14
+ import listStyleCircleIcon from '../../theme/icons/liststylecircle.svg';
15
+ import listStyleSquareIcon from '../../theme/icons/liststylesquare.svg';
16
+ import listStyleDecimalIcon from '../../theme/icons/liststyledecimal.svg';
17
+ import listStyleDecimalWithLeadingZeroIcon from '../../theme/icons/liststyledecimalleadingzero.svg';
18
+ import listStyleLowerRomanIcon from '../../theme/icons/liststylelowerroman.svg';
19
+ import listStyleUpperRomanIcon from '../../theme/icons/liststyleupperroman.svg';
20
+ import listStyleLowerLatinIcon from '../../theme/icons/liststylelowerlatin.svg';
21
+ import listStyleUpperLatinIcon from '../../theme/icons/liststyleupperlatin.svg';
22
+ import '../../theme/liststyles.css';
23
+ /**
24
+ * The list properties UI plugin. It introduces the extended `'bulletedList'` and `'numberedList'` toolbar
25
+ * buttons that allow users to control such aspects of list as the marker, start index or order.
26
+ *
27
+ * **Note**: Buttons introduced by this plugin override implementations from the {@link module:list/list/listui~ListUI}
28
+ * (because they share the same names).
29
+ */
30
+ export default class ListPropertiesUI extends Plugin {
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
+ }
124
+ }
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
+ };
174
+ }
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
+ };
216
+ }
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;
277
+ }