@ckeditor/ckeditor5-ui 35.2.1 → 35.3.1

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 (59) hide show
  1. package/package.json +31 -23
  2. package/src/bindings/addkeyboardhandlingforgrid.js +45 -57
  3. package/src/bindings/clickoutsidehandler.js +15 -21
  4. package/src/bindings/injectcsstransitiondisabler.js +16 -20
  5. package/src/bindings/preventdefault.js +6 -8
  6. package/src/bindings/submithandler.js +5 -7
  7. package/src/button/button.js +5 -0
  8. package/src/button/buttonview.js +220 -259
  9. package/src/button/switchbuttonview.js +56 -71
  10. package/src/colorgrid/colorgridview.js +135 -197
  11. package/src/colorgrid/colortileview.js +37 -47
  12. package/src/colorgrid/utils.js +57 -66
  13. package/src/componentfactory.js +79 -93
  14. package/src/dropdown/button/dropdownbutton.js +5 -0
  15. package/src/dropdown/button/dropdownbuttonview.js +44 -57
  16. package/src/dropdown/button/splitbuttonview.js +159 -207
  17. package/src/dropdown/dropdownpanelfocusable.js +5 -0
  18. package/src/dropdown/dropdownpanelview.js +101 -112
  19. package/src/dropdown/dropdownview.js +396 -438
  20. package/src/dropdown/utils.js +164 -213
  21. package/src/editableui/editableuiview.js +125 -141
  22. package/src/editableui/inline/inlineeditableuiview.js +44 -54
  23. package/src/editorui/bodycollection.js +61 -75
  24. package/src/editorui/boxed/boxededitoruiview.js +91 -104
  25. package/src/editorui/editoruiview.js +30 -39
  26. package/src/focuscycler.js +214 -245
  27. package/src/formheader/formheaderview.js +58 -70
  28. package/src/icon/iconview.js +145 -111
  29. package/src/iframe/iframeview.js +37 -49
  30. package/src/index.js +0 -17
  31. package/src/input/inputview.js +170 -198
  32. package/src/inputnumber/inputnumberview.js +48 -56
  33. package/src/inputtext/inputtextview.js +14 -18
  34. package/src/label/labelview.js +44 -53
  35. package/src/labeledfield/labeledfieldview.js +212 -235
  36. package/src/labeledfield/utils.js +39 -57
  37. package/src/labeledinput/labeledinputview.js +190 -221
  38. package/src/list/listitemview.js +40 -50
  39. package/src/list/listseparatorview.js +15 -19
  40. package/src/list/listview.js +94 -115
  41. package/src/model.js +19 -25
  42. package/src/notification/notification.js +151 -202
  43. package/src/panel/balloon/balloonpanelview.js +535 -628
  44. package/src/panel/balloon/contextualballoon.js +611 -732
  45. package/src/panel/sticky/stickypanelview.js +238 -270
  46. package/src/template.js +1049 -1479
  47. package/src/toolbar/balloon/balloontoolbar.js +337 -424
  48. package/src/toolbar/block/blockbuttonview.js +32 -42
  49. package/src/toolbar/block/blocktoolbar.js +375 -477
  50. package/src/toolbar/normalizetoolbarconfig.js +17 -21
  51. package/src/toolbar/toolbarlinebreakview.js +15 -19
  52. package/src/toolbar/toolbarseparatorview.js +15 -19
  53. package/src/toolbar/toolbarview.js +866 -1053
  54. package/src/tooltipmanager.js +324 -353
  55. package/src/view.js +389 -430
  56. package/src/viewcollection.js +147 -178
  57. package/src/button/button.jsdoc +0 -165
  58. package/src/dropdown/button/dropdownbutton.jsdoc +0 -22
  59. package/src/dropdown/dropdownpanelfocusable.jsdoc +0 -27
@@ -2,20 +2,15 @@
2
2
  * @license Copyright (c) 2003-2022, 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 ui/button/buttonview
8
7
  */
9
-
10
8
  import View from '../view';
11
9
  import IconView from '../icon/iconview';
12
-
13
10
  import uid from '@ckeditor/ckeditor5-utils/src/uid';
14
11
  import { getEnvKeystrokeText } from '@ckeditor/ckeditor5-utils/src/keyboard';
15
12
  import env from '@ckeditor/ckeditor5-utils/src/env';
16
-
17
13
  import '../../theme/components/button/button.css';
18
-
19
14
  /**
20
15
  * The button view class.
21
16
  *
@@ -36,258 +31,224 @@ import '../../theme/components/button/button.css';
36
31
  * @implements module:ui/button/button~Button
37
32
  */
38
33
  export default class ButtonView extends View {
39
- /**
40
- * @inheritDoc
41
- */
42
- constructor( locale ) {
43
- super( locale );
44
-
45
- const bind = this.bindTemplate;
46
- const ariaLabelUid = uid();
47
-
48
- // Implement the Button interface.
49
- this.set( 'class' );
50
- this.set( 'labelStyle' );
51
- this.set( 'icon' );
52
- this.set( 'isEnabled', true );
53
- this.set( 'isOn', false );
54
- this.set( 'isVisible', true );
55
- this.set( 'isToggleable', false );
56
- this.set( 'keystroke' );
57
- this.set( 'label' );
58
- this.set( 'tabindex', -1 );
59
- this.set( 'tooltip' );
60
- this.set( 'tooltipPosition', 's' );
61
- this.set( 'type', 'button' );
62
- this.set( 'withText', false );
63
- this.set( 'withKeystroke', false );
64
-
65
- /**
66
- * Collection of the child views inside of the button {@link #element}.
67
- *
68
- * @readonly
69
- * @member {module:ui/viewcollection~ViewCollection}
70
- */
71
- this.children = this.createCollection();
72
-
73
- /**
74
- * Label of the button view. It is configurable using the {@link #label label attribute}.
75
- *
76
- * @readonly
77
- * @member {module:ui/view~View} #labelView
78
- */
79
- this.labelView = this._createLabelView( ariaLabelUid );
80
-
81
- /**
82
- * The icon view of the button. Will be added to {@link #children} when the
83
- * {@link #icon icon attribute} is defined.
84
- *
85
- * @readonly
86
- * @member {module:ui/icon/iconview~IconView} #iconView
87
- */
88
- this.iconView = new IconView();
89
-
90
- this.iconView.extendTemplate( {
91
- attributes: {
92
- class: 'ck-button__icon'
93
- }
94
- } );
95
-
96
- /**
97
- * A view displaying the keystroke of the button next to the {@link #labelView label}.
98
- * Added to {@link #children} when the {@link #withKeystroke `withKeystroke` attribute}
99
- * is defined.
100
- *
101
- * @readonly
102
- * @member {module:ui/view/view~View} #keystrokeView
103
- */
104
- this.keystrokeView = this._createKeystrokeView();
105
-
106
- /**
107
- * Tooltip of the button bound to the template.
108
- *
109
- * @see #tooltip
110
- * @see #_getTooltipString
111
- * @private
112
- * @observable
113
- * @member {String|undefined} #_tooltipString
114
- */
115
- this.bind( '_tooltipString' ).to(
116
- this, 'tooltip',
117
- this, 'label',
118
- this, 'keystroke',
119
- this._getTooltipString.bind( this )
120
- );
121
-
122
- const template = {
123
- tag: 'button',
124
-
125
- attributes: {
126
- class: [
127
- 'ck',
128
- 'ck-button',
129
- bind.to( 'class' ),
130
- bind.if( 'isEnabled', 'ck-disabled', value => !value ),
131
- bind.if( 'isVisible', 'ck-hidden', value => !value ),
132
- bind.to( 'isOn', value => value ? 'ck-on' : 'ck-off' ),
133
- bind.if( 'withText', 'ck-button_with-text' ),
134
- bind.if( 'withKeystroke', 'ck-button_with-keystroke' )
135
- ],
136
- type: bind.to( 'type', value => value ? value : 'button' ),
137
- tabindex: bind.to( 'tabindex' ),
138
- 'aria-labelledby': `ck-editor__aria-label_${ ariaLabelUid }`,
139
- 'aria-disabled': bind.if( 'isEnabled', true, value => !value ),
140
- 'aria-pressed': bind.to( 'isOn', value => this.isToggleable ? String( !!value ) : false ),
141
- 'data-cke-tooltip-text': bind.to( '_tooltipString' ),
142
- 'data-cke-tooltip-position': bind.to( 'tooltipPosition' )
143
- },
144
-
145
- children: this.children,
146
-
147
- on: {
148
- click: bind.to( evt => {
149
- // We can't make the button disabled using the disabled attribute, because it won't be focusable.
150
- // Though, shouldn't this condition be moved to the button controller?
151
- if ( this.isEnabled ) {
152
- this.fire( 'execute' );
153
- } else {
154
- // Prevent the default when button is disabled, to block e.g.
155
- // automatic form submitting. See ckeditor/ckeditor5-link#74.
156
- evt.preventDefault();
157
- }
158
- } )
159
- }
160
- };
161
-
162
- // On Safari we have to force the focus on a button on click as it's the only browser
163
- // that doesn't do that automatically. See #12115.
164
- if ( env.isSafari ) {
165
- template.on.mousedown = bind.to( evt => {
166
- this.focus();
167
- evt.preventDefault();
168
- } );
169
- }
170
-
171
- this.setTemplate( template );
172
- }
173
-
174
- /**
175
- * @inheritDoc
176
- */
177
- render() {
178
- super.render();
179
-
180
- if ( this.icon ) {
181
- this.iconView.bind( 'content' ).to( this, 'icon' );
182
- this.children.add( this.iconView );
183
- }
184
-
185
- this.children.add( this.labelView );
186
-
187
- if ( this.withKeystroke && this.keystroke ) {
188
- this.children.add( this.keystrokeView );
189
- }
190
- }
191
-
192
- /**
193
- * Focuses the {@link #element} of the button.
194
- */
195
- focus() {
196
- this.element.focus();
197
- }
198
-
199
- /**
200
- * Creates a label view instance and binds it with button attributes.
201
- *
202
- * @private
203
- * @param {String} ariaLabelUid The aria label UID.
204
- * @returns {module:ui/view~View}
205
- */
206
- _createLabelView( ariaLabelUid ) {
207
- const labelView = new View();
208
- const bind = this.bindTemplate;
209
-
210
- labelView.setTemplate( {
211
- tag: 'span',
212
-
213
- attributes: {
214
- class: [
215
- 'ck',
216
- 'ck-button__label'
217
- ],
218
- style: bind.to( 'labelStyle' ),
219
- id: `ck-editor__aria-label_${ ariaLabelUid }`
220
- },
221
-
222
- children: [
223
- {
224
- text: this.bindTemplate.to( 'label' )
225
- }
226
- ]
227
- } );
228
-
229
- return labelView;
230
- }
231
-
232
- /**
233
- * Creates a view that displays a keystroke next to a {@link #labelView label }
234
- * and binds it with button attributes.
235
- *
236
- * @private
237
- * @returns {module:ui/view~View}
238
- */
239
- _createKeystrokeView() {
240
- const keystrokeView = new View();
241
-
242
- keystrokeView.setTemplate( {
243
- tag: 'span',
244
-
245
- attributes: {
246
- class: [
247
- 'ck',
248
- 'ck-button__keystroke'
249
- ]
250
- },
251
-
252
- children: [
253
- {
254
- text: this.bindTemplate.to( 'keystroke', text => getEnvKeystrokeText( text ) )
255
- }
256
- ]
257
- } );
258
-
259
- return keystrokeView;
260
- }
261
-
262
- /**
263
- * Gets the text for the tooltip from the combination of
264
- * {@link #tooltip}, {@link #label} and {@link #keystroke} attributes.
265
- *
266
- * @private
267
- * @see #tooltip
268
- * @see #_tooltipString
269
- * @param {Boolean|String|Function} tooltip Button tooltip.
270
- * @param {String} label Button label.
271
- * @param {String} keystroke Button keystroke.
272
- * @returns {String}
273
- */
274
- _getTooltipString( tooltip, label, keystroke ) {
275
- if ( tooltip ) {
276
- if ( typeof tooltip == 'string' ) {
277
- return tooltip;
278
- } else {
279
- if ( keystroke ) {
280
- keystroke = getEnvKeystrokeText( keystroke );
281
- }
282
-
283
- if ( tooltip instanceof Function ) {
284
- return tooltip( label, keystroke );
285
- } else {
286
- return `${ label }${ keystroke ? ` (${ keystroke })` : '' }`;
287
- }
288
- }
289
- }
290
-
291
- return '';
292
- }
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ constructor(locale) {
38
+ super(locale);
39
+ const bind = this.bindTemplate;
40
+ const ariaLabelUid = uid();
41
+ // Implement the Button interface.
42
+ this.set('class', undefined);
43
+ this.set('labelStyle', undefined);
44
+ this.set('icon', undefined);
45
+ this.set('isEnabled', true);
46
+ this.set('isOn', false);
47
+ this.set('isVisible', true);
48
+ this.set('isToggleable', false);
49
+ this.set('keystroke', undefined);
50
+ this.set('label', undefined);
51
+ this.set('tabindex', -1);
52
+ this.set('tooltip', false);
53
+ this.set('tooltipPosition', 's');
54
+ this.set('type', 'button');
55
+ this.set('withText', false);
56
+ this.set('withKeystroke', false);
57
+ /**
58
+ * Collection of the child views inside of the button {@link #element}.
59
+ *
60
+ * @readonly
61
+ * @member {module:ui/viewcollection~ViewCollection}
62
+ */
63
+ this.children = this.createCollection();
64
+ /**
65
+ * Label of the button view. It is configurable using the {@link #label label attribute}.
66
+ *
67
+ * @readonly
68
+ * @member {module:ui/view~View} #labelView
69
+ */
70
+ this.labelView = this._createLabelView(ariaLabelUid);
71
+ /**
72
+ * The icon view of the button. Will be added to {@link #children} when the
73
+ * {@link #icon icon attribute} is defined.
74
+ *
75
+ * @readonly
76
+ * @member {module:ui/icon/iconview~IconView} #iconView
77
+ */
78
+ this.iconView = new IconView();
79
+ this.iconView.extendTemplate({
80
+ attributes: {
81
+ class: 'ck-button__icon'
82
+ }
83
+ });
84
+ /**
85
+ * A view displaying the keystroke of the button next to the {@link #labelView label}.
86
+ * Added to {@link #children} when the {@link #withKeystroke `withKeystroke` attribute}
87
+ * is defined.
88
+ *
89
+ * @readonly
90
+ * @member {module:ui/view/view~View} #keystrokeView
91
+ */
92
+ this.keystrokeView = this._createKeystrokeView();
93
+ /**
94
+ * Tooltip of the button bound to the template.
95
+ *
96
+ * @see #tooltip
97
+ * @see #_getTooltipString
98
+ * @private
99
+ * @observable
100
+ * @member {String|undefined} #_tooltipString
101
+ */
102
+ this.bind('_tooltipString').to(this, 'tooltip', this, 'label', this, 'keystroke', this._getTooltipString.bind(this));
103
+ const template = {
104
+ tag: 'button',
105
+ attributes: {
106
+ class: [
107
+ 'ck',
108
+ 'ck-button',
109
+ bind.to('class'),
110
+ bind.if('isEnabled', 'ck-disabled', value => !value),
111
+ bind.if('isVisible', 'ck-hidden', value => !value),
112
+ bind.to('isOn', value => value ? 'ck-on' : 'ck-off'),
113
+ bind.if('withText', 'ck-button_with-text'),
114
+ bind.if('withKeystroke', 'ck-button_with-keystroke')
115
+ ],
116
+ type: bind.to('type', value => value ? value : 'button'),
117
+ tabindex: bind.to('tabindex'),
118
+ 'aria-labelledby': `ck-editor__aria-label_${ariaLabelUid}`,
119
+ 'aria-disabled': bind.if('isEnabled', true, value => !value),
120
+ 'aria-pressed': bind.to('isOn', value => this.isToggleable ? String(!!value) : false),
121
+ 'data-cke-tooltip-text': bind.to('_tooltipString'),
122
+ 'data-cke-tooltip-position': bind.to('tooltipPosition')
123
+ },
124
+ children: this.children,
125
+ on: {
126
+ click: bind.to(evt => {
127
+ // We can't make the button disabled using the disabled attribute, because it won't be focusable.
128
+ // Though, shouldn't this condition be moved to the button controller?
129
+ if (this.isEnabled) {
130
+ this.fire('execute');
131
+ }
132
+ else {
133
+ // Prevent the default when button is disabled, to block e.g.
134
+ // automatic form submitting. See ckeditor/ckeditor5-link#74.
135
+ evt.preventDefault();
136
+ }
137
+ })
138
+ }
139
+ };
140
+ // On Safari we have to force the focus on a button on click as it's the only browser
141
+ // that doesn't do that automatically. See #12115.
142
+ if (env.isSafari) {
143
+ template.on.mousedown = bind.to(evt => {
144
+ this.focus();
145
+ evt.preventDefault();
146
+ });
147
+ }
148
+ this.setTemplate(template);
149
+ }
150
+ /**
151
+ * @inheritDoc
152
+ */
153
+ render() {
154
+ super.render();
155
+ if (this.icon) {
156
+ this.iconView.bind('content').to(this, 'icon');
157
+ this.children.add(this.iconView);
158
+ }
159
+ this.children.add(this.labelView);
160
+ if (this.withKeystroke && this.keystroke) {
161
+ this.children.add(this.keystrokeView);
162
+ }
163
+ }
164
+ /**
165
+ * Focuses the {@link #element} of the button.
166
+ */
167
+ focus() {
168
+ this.element.focus();
169
+ }
170
+ /**
171
+ * Creates a label view instance and binds it with button attributes.
172
+ *
173
+ * @private
174
+ * @param {String} ariaLabelUid The aria label UID.
175
+ * @returns {module:ui/view~View}
176
+ */
177
+ _createLabelView(ariaLabelUid) {
178
+ const labelView = new View();
179
+ const bind = this.bindTemplate;
180
+ labelView.setTemplate({
181
+ tag: 'span',
182
+ attributes: {
183
+ class: [
184
+ 'ck',
185
+ 'ck-button__label'
186
+ ],
187
+ style: bind.to('labelStyle'),
188
+ id: `ck-editor__aria-label_${ariaLabelUid}`
189
+ },
190
+ children: [
191
+ {
192
+ text: this.bindTemplate.to('label')
193
+ }
194
+ ]
195
+ });
196
+ return labelView;
197
+ }
198
+ /**
199
+ * Creates a view that displays a keystroke next to a {@link #labelView label }
200
+ * and binds it with button attributes.
201
+ *
202
+ * @private
203
+ * @returns {module:ui/view~View}
204
+ */
205
+ _createKeystrokeView() {
206
+ const keystrokeView = new View();
207
+ keystrokeView.setTemplate({
208
+ tag: 'span',
209
+ attributes: {
210
+ class: [
211
+ 'ck',
212
+ 'ck-button__keystroke'
213
+ ]
214
+ },
215
+ children: [
216
+ {
217
+ text: this.bindTemplate.to('keystroke', text => getEnvKeystrokeText(text))
218
+ }
219
+ ]
220
+ });
221
+ return keystrokeView;
222
+ }
223
+ /**
224
+ * Gets the text for the tooltip from the combination of
225
+ * {@link #tooltip}, {@link #label} and {@link #keystroke} attributes.
226
+ *
227
+ * @private
228
+ * @see #tooltip
229
+ * @see #_tooltipString
230
+ * @param {Boolean|String|Function} tooltip Button tooltip.
231
+ * @param {String} label Button label.
232
+ * @param {String} keystroke Button keystroke.
233
+ * @returns {String}
234
+ */
235
+ _getTooltipString(tooltip, label, keystroke) {
236
+ if (tooltip) {
237
+ if (typeof tooltip == 'string') {
238
+ return tooltip;
239
+ }
240
+ else {
241
+ if (keystroke) {
242
+ keystroke = getEnvKeystrokeText(keystroke);
243
+ }
244
+ if (tooltip instanceof Function) {
245
+ return tooltip(label, keystroke);
246
+ }
247
+ else {
248
+ return `${label}${keystroke ? ` (${keystroke})` : ''}`;
249
+ }
250
+ }
251
+ }
252
+ return '';
253
+ }
293
254
  }
@@ -2,16 +2,12 @@
2
2
  * @license Copyright (c) 2003-2022, 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 ui/button/switchbuttonview
8
7
  */
9
-
10
8
  import View from '../view';
11
9
  import ButtonView from './buttonview';
12
-
13
10
  import '../../theme/components/button/switchbutton.css';
14
-
15
11
  /**
16
12
  * The switch button view class.
17
13
  *
@@ -29,71 +25,60 @@ import '../../theme/components/button/switchbutton.css';
29
25
  * @extends module:ui/button/buttonview~ButtonView
30
26
  */
31
27
  export default class SwitchButtonView extends ButtonView {
32
- /**
33
- * @inheritDoc
34
- */
35
- constructor( locale ) {
36
- super( locale );
37
-
38
- this.isToggleable = true;
39
-
40
- /**
41
- * The toggle switch of the button.
42
- *
43
- * @readonly
44
- * @member {module:ui/view~View} #toggleSwitchView
45
- */
46
- this.toggleSwitchView = this._createToggleView();
47
-
48
- this.extendTemplate( {
49
- attributes: {
50
- class: 'ck-switchbutton'
51
- }
52
- } );
53
- }
54
-
55
- /**
56
- * @inheritDoc
57
- */
58
- render() {
59
- super.render();
60
-
61
- this.children.add( this.toggleSwitchView );
62
- }
63
-
64
- /**
65
- * Creates a toggle child view.
66
- *
67
- * @private
68
- * @returns {module:ui/view~View}
69
- */
70
- _createToggleView() {
71
- const toggleSwitchView = new View();
72
-
73
- toggleSwitchView.setTemplate( {
74
- tag: 'span',
75
-
76
- attributes: {
77
- class: [
78
- 'ck',
79
- 'ck-button__toggle'
80
- ]
81
- },
82
-
83
- children: [
84
- {
85
- tag: 'span',
86
-
87
- attributes: {
88
- class: [
89
- 'ck',
90
- 'ck-button__toggle__inner'
91
- ]
92
- }
93
- }
94
- ]
95
- } );
96
-
97
- return toggleSwitchView;
98
- }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ constructor(locale) {
32
+ super(locale);
33
+ this.isToggleable = true;
34
+ /**
35
+ * The toggle switch of the button.
36
+ *
37
+ * @readonly
38
+ * @member {module:ui/view~View} #toggleSwitchView
39
+ */
40
+ this.toggleSwitchView = this._createToggleView();
41
+ this.extendTemplate({
42
+ attributes: {
43
+ class: 'ck-switchbutton'
44
+ }
45
+ });
46
+ }
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ render() {
51
+ super.render();
52
+ this.children.add(this.toggleSwitchView);
53
+ }
54
+ /**
55
+ * Creates a toggle child view.
56
+ *
57
+ * @private
58
+ * @returns {module:ui/view~View}
59
+ */
60
+ _createToggleView() {
61
+ const toggleSwitchView = new View();
62
+ toggleSwitchView.setTemplate({
63
+ tag: 'span',
64
+ attributes: {
65
+ class: [
66
+ 'ck',
67
+ 'ck-button__toggle'
68
+ ]
69
+ },
70
+ children: [
71
+ {
72
+ tag: 'span',
73
+ attributes: {
74
+ class: [
75
+ 'ck',
76
+ 'ck-button__toggle__inner'
77
+ ]
78
+ }
79
+ }
80
+ ]
81
+ });
82
+ return toggleSwitchView;
83
+ }
99
84
  }