@ckeditor/ckeditor5-list 40.0.0 → 40.1.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.
- package/LICENSE.md +2 -2
- package/build/list.js +1 -1
- package/package.json +3 -3
- package/src/augmentation.d.ts +52 -52
- package/src/augmentation.js +5 -5
- package/src/documentlist/adjacentlistssupport.d.ts +15 -15
- package/src/documentlist/adjacentlistssupport.js +81 -81
- package/src/documentlist/converters.d.ts +65 -65
- package/src/documentlist/converters.js +441 -441
- package/src/documentlist/documentlistcommand.d.ts +80 -80
- package/src/documentlist/documentlistcommand.js +150 -150
- package/src/documentlist/documentlistediting.d.ts +212 -212
- package/src/documentlist/documentlistediting.js +646 -645
- package/src/documentlist/documentlistindentcommand.d.ts +62 -62
- package/src/documentlist/documentlistindentcommand.js +129 -129
- package/src/documentlist/documentlistmergecommand.d.ts +76 -76
- package/src/documentlist/documentlistmergecommand.js +174 -174
- package/src/documentlist/documentlistsplitcommand.d.ts +67 -67
- package/src/documentlist/documentlistsplitcommand.js +70 -70
- package/src/documentlist/documentlistutils.d.ts +46 -46
- package/src/documentlist/documentlistutils.js +50 -50
- package/src/documentlist/utils/listwalker.d.ts +145 -145
- package/src/documentlist/utils/listwalker.js +182 -182
- package/src/documentlist/utils/model.d.ts +202 -202
- package/src/documentlist/utils/model.js +455 -455
- package/src/documentlist/utils/postfixers.d.ts +37 -37
- package/src/documentlist/utils/postfixers.js +126 -126
- package/src/documentlist/utils/view.d.ts +81 -81
- package/src/documentlist/utils/view.js +117 -117
- package/src/documentlist.d.ts +26 -26
- package/src/documentlist.js +30 -30
- package/src/documentlistproperties/converters.d.ts +19 -19
- package/src/documentlistproperties/converters.js +43 -43
- package/src/documentlistproperties/documentlistpropertiesediting.d.ts +88 -88
- package/src/documentlistproperties/documentlistpropertiesediting.js +266 -266
- package/src/documentlistproperties/documentlistpropertiesutils.d.ts +33 -33
- package/src/documentlistproperties/documentlistpropertiesutils.js +44 -44
- package/src/documentlistproperties/documentlistreversedcommand.d.ts +36 -36
- package/src/documentlistproperties/documentlistreversedcommand.js +55 -55
- package/src/documentlistproperties/documentliststartcommand.d.ts +38 -38
- package/src/documentlistproperties/documentliststartcommand.js +57 -57
- package/src/documentlistproperties/documentliststylecommand.d.ts +72 -72
- package/src/documentlistproperties/documentliststylecommand.js +113 -113
- package/src/documentlistproperties/utils/style.d.ts +20 -20
- package/src/documentlistproperties/utils/style.js +54 -54
- package/src/documentlistproperties.d.ts +27 -27
- package/src/documentlistproperties.js +31 -31
- package/src/index.d.ts +43 -43
- package/src/index.js +29 -29
- package/src/list/converters.d.ts +196 -196
- package/src/list/converters.js +905 -905
- package/src/list/indentcommand.d.ts +37 -37
- package/src/list/indentcommand.js +107 -107
- package/src/list/listcommand.d.ts +55 -55
- package/src/list/listcommand.js +274 -274
- package/src/list/listediting.d.ts +32 -32
- package/src/list/listediting.js +161 -161
- package/src/list/listui.d.ts +19 -19
- package/src/list/listui.js +32 -32
- package/src/list/listutils.d.ts +41 -41
- package/src/list/listutils.js +46 -46
- package/src/list/utils.d.ts +112 -112
- package/src/list/utils.js +374 -374
- package/src/list.d.ts +26 -26
- package/src/list.js +30 -30
- package/src/listconfig.d.ts +132 -132
- package/src/listconfig.js +5 -5
- package/src/listproperties/listpropertiesediting.d.ts +72 -72
- package/src/listproperties/listpropertiesediting.js +696 -696
- package/src/listproperties/listpropertiesui.d.ts +23 -23
- package/src/listproperties/listpropertiesui.js +277 -277
- package/src/listproperties/listreversedcommand.d.ts +38 -38
- package/src/listproperties/listreversedcommand.js +52 -52
- package/src/listproperties/liststartcommand.d.ts +37 -37
- package/src/listproperties/liststartcommand.js +51 -51
- package/src/listproperties/liststylecommand.d.ts +67 -67
- package/src/listproperties/liststylecommand.js +99 -99
- package/src/listproperties/ui/collapsibleview.d.ts +63 -63
- package/src/listproperties/ui/collapsibleview.js +89 -89
- package/src/listproperties/ui/listpropertiesview.d.ts +157 -157
- package/src/listproperties/ui/listpropertiesview.js +299 -299
- package/src/listproperties.d.ts +26 -26
- package/src/listproperties.js +30 -30
- package/src/liststyle.d.ts +28 -28
- package/src/liststyle.js +36 -36
- package/src/tododocumentlist/checktododocumentlistcommand.d.ts +49 -49
- package/src/tododocumentlist/checktododocumentlistcommand.js +82 -82
- package/src/tododocumentlist/todocheckboxchangeobserver.d.ts +41 -41
- package/src/tododocumentlist/todocheckboxchangeobserver.js +37 -37
- package/src/tododocumentlist/tododocumentlistediting.d.ts +38 -38
- package/src/tododocumentlist/tododocumentlistediting.js +399 -399
- package/src/tododocumentlist.d.ts +27 -27
- package/src/tododocumentlist.js +31 -31
- package/src/todolist/checktodolistcommand.d.ts +52 -52
- package/src/todolist/checktodolistcommand.js +76 -76
- package/src/todolist/todolistconverters.d.ts +82 -82
- package/src/todolist/todolistconverters.js +260 -260
- package/src/todolist/todolistediting.d.ts +39 -39
- package/src/todolist/todolistediting.js +161 -161
- package/src/todolist/todolistui.d.ts +19 -19
- package/src/todolist/todolistui.js +29 -29
- package/src/todolist.d.ts +27 -27
- package/src/todolist.js +31 -31
- package/build/list.js.map +0 -1
|
@@ -1,299 +1,299 @@
|
|
|
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/ui/listpropertiesview
|
|
7
|
-
*/
|
|
8
|
-
import { View, ViewCollection, FocusCycler, SwitchButtonView, LabeledFieldView, createLabeledInputNumber, addKeyboardHandlingForGrid } from 'ckeditor5/src/ui';
|
|
9
|
-
import { FocusTracker, KeystrokeHandler, global } from 'ckeditor5/src/utils';
|
|
10
|
-
import CollapsibleView from './collapsibleview';
|
|
11
|
-
import '../../../theme/listproperties.css';
|
|
12
|
-
/**
|
|
13
|
-
* The list properties view to be displayed in the list dropdown.
|
|
14
|
-
*
|
|
15
|
-
* Contains a grid of available list styles and, for numbered list, also the list start index and reversed fields.
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export default class ListPropertiesView extends View {
|
|
20
|
-
/**
|
|
21
|
-
* Creates an instance of the list properties view.
|
|
22
|
-
*
|
|
23
|
-
* @param locale The {@link module:core/editor/editor~Editor#locale} instance.
|
|
24
|
-
* @param options Options of the view.
|
|
25
|
-
* @param options.enabledProperties An object containing the configuration of enabled list property names.
|
|
26
|
-
* Allows conditional rendering the sub-components of the properties view.
|
|
27
|
-
* @param options.styleButtonViews A list of style buttons to be rendered
|
|
28
|
-
* inside the styles grid. The grid will not be rendered when `enabledProperties` does not include the `'styles'` key.
|
|
29
|
-
* @param options.styleGridAriaLabel An assistive technologies label set on the grid of styles (if the grid is rendered).
|
|
30
|
-
*/
|
|
31
|
-
constructor(locale, { enabledProperties, styleButtonViews, styleGridAriaLabel }) {
|
|
32
|
-
super(locale);
|
|
33
|
-
/**
|
|
34
|
-
* A view that renders the grid of list styles.
|
|
35
|
-
*/
|
|
36
|
-
this.stylesView = null;
|
|
37
|
-
/**
|
|
38
|
-
* A collapsible view that hosts additional list property fields ({@link #startIndexFieldView} and
|
|
39
|
-
* {@link #reversedSwitchButtonView}) to visually separate them from the {@link #stylesView grid of styles}.
|
|
40
|
-
*
|
|
41
|
-
* **Note**: Only present when:
|
|
42
|
-
* * the view represents **numbered** list properties,
|
|
43
|
-
* * and the {@link #stylesView} is rendered,
|
|
44
|
-
* * and either {@link #startIndexFieldView} or {@link #reversedSwitchButtonView} is rendered.
|
|
45
|
-
*
|
|
46
|
-
* @readonly
|
|
47
|
-
*/
|
|
48
|
-
this.additionalPropertiesCollapsibleView = null;
|
|
49
|
-
/**
|
|
50
|
-
* A labeled number field allowing the user to set the start index of the list.
|
|
51
|
-
*
|
|
52
|
-
* **Note**: Only present when the view represents **numbered** list properties.
|
|
53
|
-
*
|
|
54
|
-
* @readonly
|
|
55
|
-
*/
|
|
56
|
-
this.startIndexFieldView = null;
|
|
57
|
-
/**
|
|
58
|
-
* A switch button allowing the user to make the edited list reversed.
|
|
59
|
-
*
|
|
60
|
-
* **Note**: Only present when the view represents **numbered** list properties.
|
|
61
|
-
*
|
|
62
|
-
* @readonly
|
|
63
|
-
*/
|
|
64
|
-
this.reversedSwitchButtonView = null;
|
|
65
|
-
/**
|
|
66
|
-
* Tracks information about the DOM focus in the view.
|
|
67
|
-
*/
|
|
68
|
-
this.focusTracker = new FocusTracker();
|
|
69
|
-
/**
|
|
70
|
-
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
|
|
71
|
-
*/
|
|
72
|
-
this.keystrokes = new KeystrokeHandler();
|
|
73
|
-
/**
|
|
74
|
-
* A collection of views that can be focused in the properties view.
|
|
75
|
-
*/
|
|
76
|
-
this.focusables = new ViewCollection();
|
|
77
|
-
const elementCssClasses = [
|
|
78
|
-
'ck',
|
|
79
|
-
'ck-list-properties'
|
|
80
|
-
];
|
|
81
|
-
this.children = this.createCollection();
|
|
82
|
-
this.focusCycler = new FocusCycler({
|
|
83
|
-
focusables: this.focusables,
|
|
84
|
-
focusTracker: this.focusTracker,
|
|
85
|
-
keystrokeHandler: this.keystrokes,
|
|
86
|
-
actions: {
|
|
87
|
-
// Navigate #children backwards using the <kbd>Shift</kbd> + <kbd>Tab</kbd> keystroke.
|
|
88
|
-
focusPrevious: 'shift + tab',
|
|
89
|
-
// Navigate #children forwards using the <kbd>Tab</kbd> key.
|
|
90
|
-
focusNext: 'tab'
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
// The rendering of the styles grid is conditional. When there is no styles grid, the view will render without collapsible
|
|
94
|
-
// for numbered list properties, hence simplifying the layout.
|
|
95
|
-
if (enabledProperties.styles) {
|
|
96
|
-
this.stylesView = this._createStylesView(styleButtonViews, styleGridAriaLabel);
|
|
97
|
-
this.children.add(this.stylesView);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
elementCssClasses.push('ck-list-properties_without-styles');
|
|
101
|
-
}
|
|
102
|
-
// The rendering of the numbered list property views is also conditional. It only makes sense for the numbered list
|
|
103
|
-
// dropdown. The unordered list does not have such properties.
|
|
104
|
-
if (enabledProperties.startIndex || enabledProperties.reversed) {
|
|
105
|
-
this._addNumberedListPropertyViews(enabledProperties);
|
|
106
|
-
elementCssClasses.push('ck-list-properties_with-numbered-properties');
|
|
107
|
-
}
|
|
108
|
-
this.setTemplate({
|
|
109
|
-
tag: 'div',
|
|
110
|
-
attributes: {
|
|
111
|
-
class: elementCssClasses
|
|
112
|
-
},
|
|
113
|
-
children: this.children
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @inheritDoc
|
|
118
|
-
*/
|
|
119
|
-
render() {
|
|
120
|
-
super.render();
|
|
121
|
-
if (this.stylesView) {
|
|
122
|
-
this.focusables.add(this.stylesView);
|
|
123
|
-
this.focusTracker.add(this.stylesView.element);
|
|
124
|
-
// Register the collapsible toggle button to the focus system.
|
|
125
|
-
if (this.startIndexFieldView || this.reversedSwitchButtonView) {
|
|
126
|
-
this.focusables.add(this.children.last.buttonView);
|
|
127
|
-
this.focusTracker.add(this.children.last.buttonView.element);
|
|
128
|
-
}
|
|
129
|
-
for (const item of this.stylesView.children) {
|
|
130
|
-
this.stylesView.focusTracker.add(item.element);
|
|
131
|
-
}
|
|
132
|
-
addKeyboardHandlingForGrid({
|
|
133
|
-
keystrokeHandler: this.stylesView.keystrokes,
|
|
134
|
-
focusTracker: this.stylesView.focusTracker,
|
|
135
|
-
gridItems: this.stylesView.children,
|
|
136
|
-
// Note: The styles view has a different number of columns depending on whether the other properties
|
|
137
|
-
// are enabled in the dropdown or not (https://github.com/ckeditor/ckeditor5/issues/12340)
|
|
138
|
-
numberOfColumns: () => global.window
|
|
139
|
-
.getComputedStyle(this.stylesView.element)
|
|
140
|
-
.getPropertyValue('grid-template-columns')
|
|
141
|
-
.split(' ')
|
|
142
|
-
.length,
|
|
143
|
-
uiLanguageDirection: this.locale && this.locale.uiLanguageDirection
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
if (this.startIndexFieldView) {
|
|
147
|
-
this.focusables.add(this.startIndexFieldView);
|
|
148
|
-
this.focusTracker.add(this.startIndexFieldView.element);
|
|
149
|
-
const stopPropagation = (data) => data.stopPropagation();
|
|
150
|
-
// Since the form is in the dropdown panel which is a child of the toolbar, the toolbar's
|
|
151
|
-
// keystroke handler would take over the key management in the input. We need to prevent
|
|
152
|
-
// this ASAP. Otherwise, the basic caret movement using the arrow keys will be impossible.
|
|
153
|
-
this.keystrokes.set('arrowright', stopPropagation);
|
|
154
|
-
this.keystrokes.set('arrowleft', stopPropagation);
|
|
155
|
-
this.keystrokes.set('arrowup', stopPropagation);
|
|
156
|
-
this.keystrokes.set('arrowdown', stopPropagation);
|
|
157
|
-
}
|
|
158
|
-
if (this.reversedSwitchButtonView) {
|
|
159
|
-
this.focusables.add(this.reversedSwitchButtonView);
|
|
160
|
-
this.focusTracker.add(this.reversedSwitchButtonView.element);
|
|
161
|
-
}
|
|
162
|
-
// Start listening for the keystrokes coming from #element.
|
|
163
|
-
this.keystrokes.listenTo(this.element);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* @inheritDoc
|
|
167
|
-
*/
|
|
168
|
-
focus() {
|
|
169
|
-
this.focusCycler.focusFirst();
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* @inheritDoc
|
|
173
|
-
*/
|
|
174
|
-
focusLast() {
|
|
175
|
-
this.focusCycler.focusLast();
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* @inheritDoc
|
|
179
|
-
*/
|
|
180
|
-
destroy() {
|
|
181
|
-
super.destroy();
|
|
182
|
-
this.focusTracker.destroy();
|
|
183
|
-
this.keystrokes.destroy();
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Creates the list styles grid.
|
|
187
|
-
*
|
|
188
|
-
* @param styleButtons Buttons to be placed in the grid.
|
|
189
|
-
* @param styleGridAriaLabel The assistive technology label of the grid.
|
|
190
|
-
*/
|
|
191
|
-
_createStylesView(styleButtons, styleGridAriaLabel) {
|
|
192
|
-
const stylesView = new View(this.locale);
|
|
193
|
-
stylesView.children = stylesView.createCollection();
|
|
194
|
-
stylesView.children.addMany(styleButtons);
|
|
195
|
-
stylesView.setTemplate({
|
|
196
|
-
tag: 'div',
|
|
197
|
-
attributes: {
|
|
198
|
-
'aria-label': styleGridAriaLabel,
|
|
199
|
-
class: [
|
|
200
|
-
'ck',
|
|
201
|
-
'ck-list-styles-list'
|
|
202
|
-
]
|
|
203
|
-
},
|
|
204
|
-
children: stylesView.children
|
|
205
|
-
});
|
|
206
|
-
stylesView.children.delegate('execute').to(this);
|
|
207
|
-
stylesView.focus = function () {
|
|
208
|
-
this.children.first.focus();
|
|
209
|
-
};
|
|
210
|
-
stylesView.focusTracker = new FocusTracker();
|
|
211
|
-
stylesView.keystrokes = new KeystrokeHandler();
|
|
212
|
-
stylesView.render();
|
|
213
|
-
stylesView.keystrokes.listenTo(stylesView.element);
|
|
214
|
-
return stylesView;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Renders {@link #startIndexFieldView} and/or {@link #reversedSwitchButtonView} depending on the configuration of the properties view.
|
|
218
|
-
*
|
|
219
|
-
* @param enabledProperties An object containing the configuration of enabled list property names
|
|
220
|
-
* (see {@link #constructor}).
|
|
221
|
-
*/
|
|
222
|
-
_addNumberedListPropertyViews(enabledProperties) {
|
|
223
|
-
const t = this.locale.t;
|
|
224
|
-
const numberedPropertyViews = [];
|
|
225
|
-
if (enabledProperties.startIndex) {
|
|
226
|
-
this.startIndexFieldView = this._createStartIndexField();
|
|
227
|
-
numberedPropertyViews.push(this.startIndexFieldView);
|
|
228
|
-
}
|
|
229
|
-
if (enabledProperties.reversed) {
|
|
230
|
-
this.reversedSwitchButtonView = this._createReversedSwitchButton();
|
|
231
|
-
numberedPropertyViews.push(this.reversedSwitchButtonView);
|
|
232
|
-
}
|
|
233
|
-
// When there are some style buttons, pack the numbered list properties into a collapsible to separate them.
|
|
234
|
-
if (enabledProperties.styles) {
|
|
235
|
-
this.additionalPropertiesCollapsibleView = new CollapsibleView(this.locale, numberedPropertyViews);
|
|
236
|
-
this.additionalPropertiesCollapsibleView.set({
|
|
237
|
-
label: t('List properties'),
|
|
238
|
-
isCollapsed: true
|
|
239
|
-
});
|
|
240
|
-
// Don't enable the collapsible view unless either start index or reversed field is enabled (e.g. when no list is selected).
|
|
241
|
-
this.additionalPropertiesCollapsibleView.buttonView.bind('isEnabled').toMany(numberedPropertyViews, 'isEnabled', (...areEnabled) => areEnabled.some(isEnabled => isEnabled));
|
|
242
|
-
// Automatically collapse the additional properties collapsible when either start index or reversed field gets disabled.
|
|
243
|
-
this.additionalPropertiesCollapsibleView.buttonView.on('change:isEnabled', (evt, data, isEnabled) => {
|
|
244
|
-
if (!isEnabled) {
|
|
245
|
-
this.additionalPropertiesCollapsibleView.isCollapsed = true;
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
this.children.add(this.additionalPropertiesCollapsibleView);
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
this.children.addMany(numberedPropertyViews);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Creates the list start index labeled field.
|
|
256
|
-
*/
|
|
257
|
-
_createStartIndexField() {
|
|
258
|
-
const t = this.locale.t;
|
|
259
|
-
const startIndexFieldView = new LabeledFieldView(this.locale, createLabeledInputNumber);
|
|
260
|
-
startIndexFieldView.set({
|
|
261
|
-
label: t('Start at'),
|
|
262
|
-
class: 'ck-numbered-list-properties__start-index'
|
|
263
|
-
});
|
|
264
|
-
startIndexFieldView.fieldView.set({
|
|
265
|
-
min: 0,
|
|
266
|
-
step: 1,
|
|
267
|
-
value: 1,
|
|
268
|
-
inputMode: 'numeric'
|
|
269
|
-
});
|
|
270
|
-
startIndexFieldView.fieldView.on('input', () => {
|
|
271
|
-
const inputElement = startIndexFieldView.fieldView.element;
|
|
272
|
-
const startIndex = inputElement.valueAsNumber;
|
|
273
|
-
if (Number.isNaN(startIndex)) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
if (!inputElement.checkValidity()) {
|
|
277
|
-
startIndexFieldView.errorText = t('Start index must be greater than 0.');
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
this.fire('listStart', { startIndex });
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
return startIndexFieldView;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Creates the reversed list switch button.
|
|
287
|
-
*/
|
|
288
|
-
_createReversedSwitchButton() {
|
|
289
|
-
const t = this.locale.t;
|
|
290
|
-
const reversedButtonView = new SwitchButtonView(this.locale);
|
|
291
|
-
reversedButtonView.set({
|
|
292
|
-
withText: true,
|
|
293
|
-
label: t('Reversed order'),
|
|
294
|
-
class: 'ck-numbered-list-properties__reversed-order'
|
|
295
|
-
});
|
|
296
|
-
reversedButtonView.delegate('execute').to(this, 'listReversed');
|
|
297
|
-
return reversedButtonView;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
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/ui/listpropertiesview
|
|
7
|
+
*/
|
|
8
|
+
import { View, ViewCollection, FocusCycler, SwitchButtonView, LabeledFieldView, createLabeledInputNumber, addKeyboardHandlingForGrid } from 'ckeditor5/src/ui';
|
|
9
|
+
import { FocusTracker, KeystrokeHandler, global } from 'ckeditor5/src/utils';
|
|
10
|
+
import CollapsibleView from './collapsibleview';
|
|
11
|
+
import '../../../theme/listproperties.css';
|
|
12
|
+
/**
|
|
13
|
+
* The list properties view to be displayed in the list dropdown.
|
|
14
|
+
*
|
|
15
|
+
* Contains a grid of available list styles and, for numbered list, also the list start index and reversed fields.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export default class ListPropertiesView extends View {
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of the list properties view.
|
|
22
|
+
*
|
|
23
|
+
* @param locale The {@link module:core/editor/editor~Editor#locale} instance.
|
|
24
|
+
* @param options Options of the view.
|
|
25
|
+
* @param options.enabledProperties An object containing the configuration of enabled list property names.
|
|
26
|
+
* Allows conditional rendering the sub-components of the properties view.
|
|
27
|
+
* @param options.styleButtonViews A list of style buttons to be rendered
|
|
28
|
+
* inside the styles grid. The grid will not be rendered when `enabledProperties` does not include the `'styles'` key.
|
|
29
|
+
* @param options.styleGridAriaLabel An assistive technologies label set on the grid of styles (if the grid is rendered).
|
|
30
|
+
*/
|
|
31
|
+
constructor(locale, { enabledProperties, styleButtonViews, styleGridAriaLabel }) {
|
|
32
|
+
super(locale);
|
|
33
|
+
/**
|
|
34
|
+
* A view that renders the grid of list styles.
|
|
35
|
+
*/
|
|
36
|
+
this.stylesView = null;
|
|
37
|
+
/**
|
|
38
|
+
* A collapsible view that hosts additional list property fields ({@link #startIndexFieldView} and
|
|
39
|
+
* {@link #reversedSwitchButtonView}) to visually separate them from the {@link #stylesView grid of styles}.
|
|
40
|
+
*
|
|
41
|
+
* **Note**: Only present when:
|
|
42
|
+
* * the view represents **numbered** list properties,
|
|
43
|
+
* * and the {@link #stylesView} is rendered,
|
|
44
|
+
* * and either {@link #startIndexFieldView} or {@link #reversedSwitchButtonView} is rendered.
|
|
45
|
+
*
|
|
46
|
+
* @readonly
|
|
47
|
+
*/
|
|
48
|
+
this.additionalPropertiesCollapsibleView = null;
|
|
49
|
+
/**
|
|
50
|
+
* A labeled number field allowing the user to set the start index of the list.
|
|
51
|
+
*
|
|
52
|
+
* **Note**: Only present when the view represents **numbered** list properties.
|
|
53
|
+
*
|
|
54
|
+
* @readonly
|
|
55
|
+
*/
|
|
56
|
+
this.startIndexFieldView = null;
|
|
57
|
+
/**
|
|
58
|
+
* A switch button allowing the user to make the edited list reversed.
|
|
59
|
+
*
|
|
60
|
+
* **Note**: Only present when the view represents **numbered** list properties.
|
|
61
|
+
*
|
|
62
|
+
* @readonly
|
|
63
|
+
*/
|
|
64
|
+
this.reversedSwitchButtonView = null;
|
|
65
|
+
/**
|
|
66
|
+
* Tracks information about the DOM focus in the view.
|
|
67
|
+
*/
|
|
68
|
+
this.focusTracker = new FocusTracker();
|
|
69
|
+
/**
|
|
70
|
+
* An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
|
|
71
|
+
*/
|
|
72
|
+
this.keystrokes = new KeystrokeHandler();
|
|
73
|
+
/**
|
|
74
|
+
* A collection of views that can be focused in the properties view.
|
|
75
|
+
*/
|
|
76
|
+
this.focusables = new ViewCollection();
|
|
77
|
+
const elementCssClasses = [
|
|
78
|
+
'ck',
|
|
79
|
+
'ck-list-properties'
|
|
80
|
+
];
|
|
81
|
+
this.children = this.createCollection();
|
|
82
|
+
this.focusCycler = new FocusCycler({
|
|
83
|
+
focusables: this.focusables,
|
|
84
|
+
focusTracker: this.focusTracker,
|
|
85
|
+
keystrokeHandler: this.keystrokes,
|
|
86
|
+
actions: {
|
|
87
|
+
// Navigate #children backwards using the <kbd>Shift</kbd> + <kbd>Tab</kbd> keystroke.
|
|
88
|
+
focusPrevious: 'shift + tab',
|
|
89
|
+
// Navigate #children forwards using the <kbd>Tab</kbd> key.
|
|
90
|
+
focusNext: 'tab'
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// The rendering of the styles grid is conditional. When there is no styles grid, the view will render without collapsible
|
|
94
|
+
// for numbered list properties, hence simplifying the layout.
|
|
95
|
+
if (enabledProperties.styles) {
|
|
96
|
+
this.stylesView = this._createStylesView(styleButtonViews, styleGridAriaLabel);
|
|
97
|
+
this.children.add(this.stylesView);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
elementCssClasses.push('ck-list-properties_without-styles');
|
|
101
|
+
}
|
|
102
|
+
// The rendering of the numbered list property views is also conditional. It only makes sense for the numbered list
|
|
103
|
+
// dropdown. The unordered list does not have such properties.
|
|
104
|
+
if (enabledProperties.startIndex || enabledProperties.reversed) {
|
|
105
|
+
this._addNumberedListPropertyViews(enabledProperties);
|
|
106
|
+
elementCssClasses.push('ck-list-properties_with-numbered-properties');
|
|
107
|
+
}
|
|
108
|
+
this.setTemplate({
|
|
109
|
+
tag: 'div',
|
|
110
|
+
attributes: {
|
|
111
|
+
class: elementCssClasses
|
|
112
|
+
},
|
|
113
|
+
children: this.children
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @inheritDoc
|
|
118
|
+
*/
|
|
119
|
+
render() {
|
|
120
|
+
super.render();
|
|
121
|
+
if (this.stylesView) {
|
|
122
|
+
this.focusables.add(this.stylesView);
|
|
123
|
+
this.focusTracker.add(this.stylesView.element);
|
|
124
|
+
// Register the collapsible toggle button to the focus system.
|
|
125
|
+
if (this.startIndexFieldView || this.reversedSwitchButtonView) {
|
|
126
|
+
this.focusables.add(this.children.last.buttonView);
|
|
127
|
+
this.focusTracker.add(this.children.last.buttonView.element);
|
|
128
|
+
}
|
|
129
|
+
for (const item of this.stylesView.children) {
|
|
130
|
+
this.stylesView.focusTracker.add(item.element);
|
|
131
|
+
}
|
|
132
|
+
addKeyboardHandlingForGrid({
|
|
133
|
+
keystrokeHandler: this.stylesView.keystrokes,
|
|
134
|
+
focusTracker: this.stylesView.focusTracker,
|
|
135
|
+
gridItems: this.stylesView.children,
|
|
136
|
+
// Note: The styles view has a different number of columns depending on whether the other properties
|
|
137
|
+
// are enabled in the dropdown or not (https://github.com/ckeditor/ckeditor5/issues/12340)
|
|
138
|
+
numberOfColumns: () => global.window
|
|
139
|
+
.getComputedStyle(this.stylesView.element)
|
|
140
|
+
.getPropertyValue('grid-template-columns')
|
|
141
|
+
.split(' ')
|
|
142
|
+
.length,
|
|
143
|
+
uiLanguageDirection: this.locale && this.locale.uiLanguageDirection
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (this.startIndexFieldView) {
|
|
147
|
+
this.focusables.add(this.startIndexFieldView);
|
|
148
|
+
this.focusTracker.add(this.startIndexFieldView.element);
|
|
149
|
+
const stopPropagation = (data) => data.stopPropagation();
|
|
150
|
+
// Since the form is in the dropdown panel which is a child of the toolbar, the toolbar's
|
|
151
|
+
// keystroke handler would take over the key management in the input. We need to prevent
|
|
152
|
+
// this ASAP. Otherwise, the basic caret movement using the arrow keys will be impossible.
|
|
153
|
+
this.keystrokes.set('arrowright', stopPropagation);
|
|
154
|
+
this.keystrokes.set('arrowleft', stopPropagation);
|
|
155
|
+
this.keystrokes.set('arrowup', stopPropagation);
|
|
156
|
+
this.keystrokes.set('arrowdown', stopPropagation);
|
|
157
|
+
}
|
|
158
|
+
if (this.reversedSwitchButtonView) {
|
|
159
|
+
this.focusables.add(this.reversedSwitchButtonView);
|
|
160
|
+
this.focusTracker.add(this.reversedSwitchButtonView.element);
|
|
161
|
+
}
|
|
162
|
+
// Start listening for the keystrokes coming from #element.
|
|
163
|
+
this.keystrokes.listenTo(this.element);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @inheritDoc
|
|
167
|
+
*/
|
|
168
|
+
focus() {
|
|
169
|
+
this.focusCycler.focusFirst();
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @inheritDoc
|
|
173
|
+
*/
|
|
174
|
+
focusLast() {
|
|
175
|
+
this.focusCycler.focusLast();
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* @inheritDoc
|
|
179
|
+
*/
|
|
180
|
+
destroy() {
|
|
181
|
+
super.destroy();
|
|
182
|
+
this.focusTracker.destroy();
|
|
183
|
+
this.keystrokes.destroy();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Creates the list styles grid.
|
|
187
|
+
*
|
|
188
|
+
* @param styleButtons Buttons to be placed in the grid.
|
|
189
|
+
* @param styleGridAriaLabel The assistive technology label of the grid.
|
|
190
|
+
*/
|
|
191
|
+
_createStylesView(styleButtons, styleGridAriaLabel) {
|
|
192
|
+
const stylesView = new View(this.locale);
|
|
193
|
+
stylesView.children = stylesView.createCollection();
|
|
194
|
+
stylesView.children.addMany(styleButtons);
|
|
195
|
+
stylesView.setTemplate({
|
|
196
|
+
tag: 'div',
|
|
197
|
+
attributes: {
|
|
198
|
+
'aria-label': styleGridAriaLabel,
|
|
199
|
+
class: [
|
|
200
|
+
'ck',
|
|
201
|
+
'ck-list-styles-list'
|
|
202
|
+
]
|
|
203
|
+
},
|
|
204
|
+
children: stylesView.children
|
|
205
|
+
});
|
|
206
|
+
stylesView.children.delegate('execute').to(this);
|
|
207
|
+
stylesView.focus = function () {
|
|
208
|
+
this.children.first.focus();
|
|
209
|
+
};
|
|
210
|
+
stylesView.focusTracker = new FocusTracker();
|
|
211
|
+
stylesView.keystrokes = new KeystrokeHandler();
|
|
212
|
+
stylesView.render();
|
|
213
|
+
stylesView.keystrokes.listenTo(stylesView.element);
|
|
214
|
+
return stylesView;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Renders {@link #startIndexFieldView} and/or {@link #reversedSwitchButtonView} depending on the configuration of the properties view.
|
|
218
|
+
*
|
|
219
|
+
* @param enabledProperties An object containing the configuration of enabled list property names
|
|
220
|
+
* (see {@link #constructor}).
|
|
221
|
+
*/
|
|
222
|
+
_addNumberedListPropertyViews(enabledProperties) {
|
|
223
|
+
const t = this.locale.t;
|
|
224
|
+
const numberedPropertyViews = [];
|
|
225
|
+
if (enabledProperties.startIndex) {
|
|
226
|
+
this.startIndexFieldView = this._createStartIndexField();
|
|
227
|
+
numberedPropertyViews.push(this.startIndexFieldView);
|
|
228
|
+
}
|
|
229
|
+
if (enabledProperties.reversed) {
|
|
230
|
+
this.reversedSwitchButtonView = this._createReversedSwitchButton();
|
|
231
|
+
numberedPropertyViews.push(this.reversedSwitchButtonView);
|
|
232
|
+
}
|
|
233
|
+
// When there are some style buttons, pack the numbered list properties into a collapsible to separate them.
|
|
234
|
+
if (enabledProperties.styles) {
|
|
235
|
+
this.additionalPropertiesCollapsibleView = new CollapsibleView(this.locale, numberedPropertyViews);
|
|
236
|
+
this.additionalPropertiesCollapsibleView.set({
|
|
237
|
+
label: t('List properties'),
|
|
238
|
+
isCollapsed: true
|
|
239
|
+
});
|
|
240
|
+
// Don't enable the collapsible view unless either start index or reversed field is enabled (e.g. when no list is selected).
|
|
241
|
+
this.additionalPropertiesCollapsibleView.buttonView.bind('isEnabled').toMany(numberedPropertyViews, 'isEnabled', (...areEnabled) => areEnabled.some(isEnabled => isEnabled));
|
|
242
|
+
// Automatically collapse the additional properties collapsible when either start index or reversed field gets disabled.
|
|
243
|
+
this.additionalPropertiesCollapsibleView.buttonView.on('change:isEnabled', (evt, data, isEnabled) => {
|
|
244
|
+
if (!isEnabled) {
|
|
245
|
+
this.additionalPropertiesCollapsibleView.isCollapsed = true;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
this.children.add(this.additionalPropertiesCollapsibleView);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
this.children.addMany(numberedPropertyViews);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Creates the list start index labeled field.
|
|
256
|
+
*/
|
|
257
|
+
_createStartIndexField() {
|
|
258
|
+
const t = this.locale.t;
|
|
259
|
+
const startIndexFieldView = new LabeledFieldView(this.locale, createLabeledInputNumber);
|
|
260
|
+
startIndexFieldView.set({
|
|
261
|
+
label: t('Start at'),
|
|
262
|
+
class: 'ck-numbered-list-properties__start-index'
|
|
263
|
+
});
|
|
264
|
+
startIndexFieldView.fieldView.set({
|
|
265
|
+
min: 0,
|
|
266
|
+
step: 1,
|
|
267
|
+
value: 1,
|
|
268
|
+
inputMode: 'numeric'
|
|
269
|
+
});
|
|
270
|
+
startIndexFieldView.fieldView.on('input', () => {
|
|
271
|
+
const inputElement = startIndexFieldView.fieldView.element;
|
|
272
|
+
const startIndex = inputElement.valueAsNumber;
|
|
273
|
+
if (Number.isNaN(startIndex)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (!inputElement.checkValidity()) {
|
|
277
|
+
startIndexFieldView.errorText = t('Start index must be greater than 0.');
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
this.fire('listStart', { startIndex });
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
return startIndexFieldView;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Creates the reversed list switch button.
|
|
287
|
+
*/
|
|
288
|
+
_createReversedSwitchButton() {
|
|
289
|
+
const t = this.locale.t;
|
|
290
|
+
const reversedButtonView = new SwitchButtonView(this.locale);
|
|
291
|
+
reversedButtonView.set({
|
|
292
|
+
withText: true,
|
|
293
|
+
label: t('Reversed order'),
|
|
294
|
+
class: 'ck-numbered-list-properties__reversed-order'
|
|
295
|
+
});
|
|
296
|
+
reversedButtonView.delegate('execute').to(this, 'listReversed');
|
|
297
|
+
return reversedButtonView;
|
|
298
|
+
}
|
|
299
|
+
}
|
package/src/listproperties.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
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
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import ListPropertiesEditing from './listproperties/listpropertiesediting';
|
|
10
|
-
import ListPropertiesUI from './listproperties/listpropertiesui';
|
|
11
|
-
/**
|
|
12
|
-
* The list properties feature.
|
|
13
|
-
*
|
|
14
|
-
* This is a "glue" plugin that loads the {@link module:list/listproperties/listpropertiesediting~ListPropertiesEditing list properties
|
|
15
|
-
* editing feature} and the {@link module:list/listproperties/listpropertiesui~ListPropertiesUI list properties UI feature}.
|
|
16
|
-
*/
|
|
17
|
-
export default class ListProperties extends Plugin {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
static get requires(): readonly [typeof ListPropertiesEditing, typeof ListPropertiesUI];
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
static get pluginName(): "ListProperties";
|
|
26
|
-
}
|
|
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
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import ListPropertiesEditing from './listproperties/listpropertiesediting';
|
|
10
|
+
import ListPropertiesUI from './listproperties/listpropertiesui';
|
|
11
|
+
/**
|
|
12
|
+
* The list properties feature.
|
|
13
|
+
*
|
|
14
|
+
* This is a "glue" plugin that loads the {@link module:list/listproperties/listpropertiesediting~ListPropertiesEditing list properties
|
|
15
|
+
* editing feature} and the {@link module:list/listproperties/listpropertiesui~ListPropertiesUI list properties UI feature}.
|
|
16
|
+
*/
|
|
17
|
+
export default class ListProperties extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
static get requires(): readonly [typeof ListPropertiesEditing, typeof ListPropertiesUI];
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
static get pluginName(): "ListProperties";
|
|
26
|
+
}
|