@ckeditor/ckeditor5-ui 35.2.0 → 35.3.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 (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,14 +2,11 @@
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/viewcollection
8
7
  */
9
-
10
8
  import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
11
9
  import Collection from '@ckeditor/ckeditor5-utils/src/collection';
12
-
13
10
  /**
14
11
  * Collects {@link module:ui/view~View} instances.
15
12
  *
@@ -48,185 +45,157 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection';
48
45
  * @mixes module:utils/observablemixin~ObservableMixin
49
46
  */
50
47
  export default class ViewCollection extends Collection {
51
- /**
52
- * Creates a new instance of the {@link module:ui/viewcollection~ViewCollection}.
53
- *
54
- * @param {Iterable.<module:ui/view~View>} [initialItems] The initial items of the collection.
55
- */
56
- constructor( initialItems = [] ) {
57
- super( initialItems, {
58
- // An #id Number attribute should be legal and not break the `ViewCollection` instance.
59
- // https://github.com/ckeditor/ckeditor5-ui/issues/93
60
- idProperty: 'viewUid'
61
- } );
62
-
63
- // Handle {@link module:ui/view~View#element} in DOM when a new view is added to the collection.
64
- this.on( 'add', ( evt, view, index ) => {
65
- this._renderViewIntoCollectionParent( view, index );
66
- } );
67
-
68
- // Handle {@link module:ui/view~View#element} in DOM when a view is removed from the collection.
69
- this.on( 'remove', ( evt, view ) => {
70
- if ( view.element && this._parentElement ) {
71
- view.element.remove();
72
- }
73
- } );
74
-
75
- /**
76
- * A parent element within which child views are rendered and managed in DOM.
77
- *
78
- * @protected
79
- * @member {HTMLElement}
80
- */
81
- this._parentElement = null;
82
- }
83
-
84
- /**
85
- * Destroys the view collection along with child views.
86
- * See the view {@link module:ui/view~View#destroy} method.
87
- */
88
- destroy() {
89
- this.map( view => view.destroy() );
90
- }
91
-
92
- /**
93
- * Sets the parent HTML element of this collection. When parent is set, {@link #add adding} and
94
- * {@link #remove removing} views in the collection synchronizes their
95
- * {@link module:ui/view~View#element elements} in the parent element.
96
- *
97
- * @param {HTMLElement} element A new parent element.
98
- */
99
- setParent( elementOrDocFragment ) {
100
- this._parentElement = elementOrDocFragment;
101
-
102
- // Take care of the initial collection items passed to the constructor.
103
- for ( const view of this ) {
104
- this._renderViewIntoCollectionParent( view );
105
- }
106
- }
107
-
108
- /**
109
- * Delegates selected events coming from within views in the collection to any
110
- * {@link module:utils/emittermixin~Emitter}.
111
- *
112
- * For the following views and collection:
113
- *
114
- * const viewA = new View();
115
- * const viewB = new View();
116
- * const viewC = new View();
117
- *
118
- * const views = parentView.createCollection();
119
- *
120
- * views.delegate( 'eventX' ).to( viewB );
121
- * views.delegate( 'eventX', 'eventY' ).to( viewC );
122
- *
123
- * views.add( viewA );
124
- *
125
- * the `eventX` is delegated (fired by) `viewB` and `viewC` along with `customData`:
126
- *
127
- * viewA.fire( 'eventX', customData );
128
- *
129
- * and `eventY` is delegated (fired by) `viewC` along with `customData`:
130
- *
131
- * viewA.fire( 'eventY', customData );
132
- *
133
- * See {@link module:utils/emittermixin~Emitter#delegate}.
134
- *
135
- * @param {...String} events {@link module:ui/view~View} event names to be delegated to another
136
- * {@link module:utils/emittermixin~Emitter}.
137
- * @returns {Object}
138
- * @returns {Function} return.to A function which accepts the destination of
139
- * {@link module:utils/emittermixin~Emitter#delegate delegated} events.
140
- */
141
- delegate( ...events ) {
142
- if ( !events.length || !isStringArray( events ) ) {
143
- /**
144
- * All event names must be strings.
145
- *
146
- * @error ui-viewcollection-delegate-wrong-events
147
- */
148
- throw new CKEditorError(
149
- 'ui-viewcollection-delegate-wrong-events',
150
- this
151
- );
152
- }
153
-
154
- return {
155
- /**
156
- * Selects destination for {@link module:utils/emittermixin~Emitter#delegate} events.
157
- *
158
- * @memberOf module:ui/viewcollection~ViewCollection#delegate
159
- * @function module:ui/viewcollection~ViewCollection#delegate.to
160
- * @param {module:utils/emittermixin~Emitter} dest An `Emitter` instance which is
161
- * the destination for delegated events.
162
- */
163
- to: dest => {
164
- // Activate delegating on existing views in this collection.
165
- for ( const view of this ) {
166
- for ( const evtName of events ) {
167
- view.delegate( evtName ).to( dest );
168
- }
169
- }
170
-
171
- // Activate delegating on future views in this collection.
172
- this.on( 'add', ( evt, view ) => {
173
- for ( const evtName of events ) {
174
- view.delegate( evtName ).to( dest );
175
- }
176
- } );
177
-
178
- // Deactivate delegating when view is removed from this collection.
179
- this.on( 'remove', ( evt, view ) => {
180
- for ( const evtName of events ) {
181
- view.stopDelegating( evtName, dest );
182
- }
183
- } );
184
- }
185
- };
186
- }
187
-
188
- /**
189
- * This method {@link module:ui/view~View#render renders} a new view added to the collection.
190
- *
191
- * If the {@link #_parentElement parent element} of the collection is set, this method also adds
192
- * the view's {@link module:ui/view~View#element} as a child of the parent in DOM at a specified index.
193
- *
194
- * **Note**: If index is not specified, the view's element is pushed as the last child
195
- * of the parent element.
196
- *
197
- * @private
198
- * @param {module:ui/view~View} view A new view added to the collection.
199
- * @param {Number} [index] An index the view holds in the collection. When not specified,
200
- * the view is added at the end.
201
- */
202
- _renderViewIntoCollectionParent( view, index ) {
203
- if ( !view.isRendered ) {
204
- view.render();
205
- }
206
-
207
- if ( view.element && this._parentElement ) {
208
- this._parentElement.insertBefore( view.element, this._parentElement.children[ index ] );
209
- }
210
- }
211
-
212
- /**
213
- * Removes a child view from the collection. If the {@link #setParent parent element} of the
214
- * collection has been set, the {@link module:ui/view~View#element element} of the view is also removed
215
- * in DOM, reflecting the order of the collection.
216
- *
217
- * See the {@link #add} method.
218
- *
219
- * @method #remove
220
- * @param {module:ui/view~View|Number|String} subject The view to remove, its id or index in the collection.
221
- * @returns {Object} The removed view.
222
- */
48
+ /**
49
+ * Creates a new instance of the {@link module:ui/viewcollection~ViewCollection}.
50
+ *
51
+ * @param {Iterable.<module:ui/view~View>} [initialItems] The initial items of the collection.
52
+ */
53
+ constructor(initialItems = []) {
54
+ super(initialItems, {
55
+ // An #id Number attribute should be legal and not break the `ViewCollection` instance.
56
+ // https://github.com/ckeditor/ckeditor5-ui/issues/93
57
+ idProperty: 'viewUid'
58
+ });
59
+ // Handle {@link module:ui/view~View#element} in DOM when a new view is added to the collection.
60
+ this.on('add', (evt, view, index) => {
61
+ this._renderViewIntoCollectionParent(view, index);
62
+ });
63
+ // Handle {@link module:ui/view~View#element} in DOM when a view is removed from the collection.
64
+ this.on('remove', (evt, view) => {
65
+ if (view.element && this._parentElement) {
66
+ view.element.remove();
67
+ }
68
+ });
69
+ /**
70
+ * A parent element within which child views are rendered and managed in DOM.
71
+ *
72
+ * @protected
73
+ * @member {HTMLElement}
74
+ */
75
+ this._parentElement = null;
76
+ }
77
+ /**
78
+ * Destroys the view collection along with child views.
79
+ * See the view {@link module:ui/view~View#destroy} method.
80
+ */
81
+ destroy() {
82
+ this.map(view => view.destroy());
83
+ }
84
+ /**
85
+ * Sets the parent HTML element of this collection. When parent is set, {@link #add adding} and
86
+ * {@link #remove removing} views in the collection synchronizes their
87
+ * {@link module:ui/view~View#element elements} in the parent element.
88
+ *
89
+ * @param {HTMLElement} element A new parent element.
90
+ */
91
+ setParent(elementOrDocFragment) {
92
+ this._parentElement = elementOrDocFragment;
93
+ // Take care of the initial collection items passed to the constructor.
94
+ for (const view of this) {
95
+ this._renderViewIntoCollectionParent(view);
96
+ }
97
+ }
98
+ /**
99
+ * Delegates selected events coming from within views in the collection to any
100
+ * {@link module:utils/emittermixin~Emitter}.
101
+ *
102
+ * For the following views and collection:
103
+ *
104
+ * const viewA = new View();
105
+ * const viewB = new View();
106
+ * const viewC = new View();
107
+ *
108
+ * const views = parentView.createCollection();
109
+ *
110
+ * views.delegate( 'eventX' ).to( viewB );
111
+ * views.delegate( 'eventX', 'eventY' ).to( viewC );
112
+ *
113
+ * views.add( viewA );
114
+ *
115
+ * the `eventX` is delegated (fired by) `viewB` and `viewC` along with `customData`:
116
+ *
117
+ * viewA.fire( 'eventX', customData );
118
+ *
119
+ * and `eventY` is delegated (fired by) `viewC` along with `customData`:
120
+ *
121
+ * viewA.fire( 'eventY', customData );
122
+ *
123
+ * See {@link module:utils/emittermixin~Emitter#delegate}.
124
+ *
125
+ * @param {...String} events {@link module:ui/view~View} event names to be delegated to another
126
+ * {@link module:utils/emittermixin~Emitter}.
127
+ * @returns {Object}
128
+ * @returns {Function} return.to A function which accepts the destination of
129
+ * {@link module:utils/emittermixin~Emitter#delegate delegated} events.
130
+ */
131
+ delegate(...events) {
132
+ if (!events.length || !isStringArray(events)) {
133
+ /**
134
+ * All event names must be strings.
135
+ *
136
+ * @error ui-viewcollection-delegate-wrong-events
137
+ */
138
+ throw new CKEditorError('ui-viewcollection-delegate-wrong-events', this);
139
+ }
140
+ return {
141
+ /**
142
+ * Selects destination for {@link module:utils/emittermixin~Emitter#delegate} events.
143
+ *
144
+ * @memberOf module:ui/viewcollection~ViewCollection#delegate
145
+ * @function module:ui/viewcollection~ViewCollection#delegate.to
146
+ * @param {module:utils/emittermixin~Emitter} dest An `Emitter` instance which is
147
+ * the destination for delegated events.
148
+ */
149
+ to: dest => {
150
+ // Activate delegating on existing views in this collection.
151
+ for (const view of this) {
152
+ for (const evtName of events) {
153
+ view.delegate(evtName).to(dest);
154
+ }
155
+ }
156
+ // Activate delegating on future views in this collection.
157
+ this.on('add', (evt, view) => {
158
+ for (const evtName of events) {
159
+ view.delegate(evtName).to(dest);
160
+ }
161
+ });
162
+ // Deactivate delegating when view is removed from this collection.
163
+ this.on('remove', (evt, view) => {
164
+ for (const evtName of events) {
165
+ view.stopDelegating(evtName, dest);
166
+ }
167
+ });
168
+ }
169
+ };
170
+ }
171
+ /**
172
+ * This method {@link module:ui/view~View#render renders} a new view added to the collection.
173
+ *
174
+ * If the {@link #_parentElement parent element} of the collection is set, this method also adds
175
+ * the view's {@link module:ui/view~View#element} as a child of the parent in DOM at a specified index.
176
+ *
177
+ * **Note**: If index is not specified, the view's element is pushed as the last child
178
+ * of the parent element.
179
+ *
180
+ * @private
181
+ * @param {module:ui/view~View} view A new view added to the collection.
182
+ * @param {Number} [index] An index the view holds in the collection. When not specified,
183
+ * the view is added at the end.
184
+ */
185
+ _renderViewIntoCollectionParent(view, index) {
186
+ if (!view.isRendered) {
187
+ view.render();
188
+ }
189
+ if (view.element && this._parentElement) {
190
+ this._parentElement.insertBefore(view.element, this._parentElement.children[index]);
191
+ }
192
+ }
223
193
  }
224
-
225
194
  // Check if all entries of the array are of `String` type.
226
195
  //
227
196
  // @private
228
197
  // @param {Array} arr An array to be checked.
229
198
  // @returns {Boolean}
230
- function isStringArray( arr ) {
231
- return arr.every( a => typeof a == 'string' );
199
+ function isStringArray(arr) {
200
+ return arr.every(a => typeof a == 'string');
232
201
  }
@@ -1,165 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module ui/button/button
8
- */
9
-
10
- /**
11
- * The button interface. Implemented by, among others, {@link module:ui/button/buttonview~ButtonView},
12
- * {@link module:ui/dropdown/button/splitbuttonview~SplitButtonView} and
13
- * {@link module:ui/dropdown/button/dropdownbuttonview~DropdownButtonView}.
14
- *
15
- * @interface module:ui/button/button~Button
16
- */
17
-
18
- /**
19
- * The label of the button view visible to the user when {@link #withText} is `true`.
20
- * It can also be used to create a {@link #tooltip}.
21
- *
22
- * @observable
23
- * @member {String} #label
24
- */
25
-
26
- /**
27
- * (Optional) The keystroke associated with the button, i.e. <kbd>CTRL+B</kbd>,
28
- * in the string format compatible with {@link module:utils/keyboard}.
29
- *
30
- * **Note**: Use {@link module:ui/button/button~Button#withKeystroke} if you want to display
31
- * the keystroke information next to the {@link module:ui/button/button~Button#label label}.
32
- *
33
- * @observable
34
- * @member {Boolean} #keystroke
35
- */
36
-
37
- /**
38
- * (Optional) Tooltip of the button, i.e. displayed when hovering the button with the mouse cursor.
39
- *
40
- * * If defined as a `Boolean` (e.g. `true`), then combination of `label` and `keystroke` will be set as a tooltip.
41
- * * If defined as a `String`, tooltip will equal the exact text of that `String`.
42
- * * If defined as a `Function`, `label` and `keystroke` will be passed to that function, which is to return
43
- * a string with the tooltip text.
44
- *
45
- * const view = new ButtonView( locale );
46
- * view.tooltip = ( label, keystroke ) => `A tooltip for ${ label } and ${ keystroke }.`
47
- *
48
- * @observable
49
- * @default false
50
- * @member {Boolean|String|Function} #tooltip
51
- */
52
-
53
- /**
54
- * (Optional) The position of the tooltip. See {@link module:ui/tooltipmanager~TooltipManager}
55
- * to learn more about the tooltip system.
56
- *
57
- * **Note:** It makes sense only when the {@link #tooltip `tooltip` attribute} is defined.
58
- *
59
- * @observable
60
- * @default 's'
61
- * @member {'s'|'n'|'e'|'w'|'sw'|'se'} #tooltipPosition
62
- */
63
-
64
- /**
65
- * The HTML type of the button. Default `button`.
66
- *
67
- * @observable
68
- * @member {'button'|'submit'|'reset'|'menu'} #type
69
- */
70
-
71
- /**
72
- * Controls whether the button view is "on". It makes sense when a feature it represents
73
- * is currently active, e.g. a bold button is "on" when the selection is in the bold text.
74
- *
75
- * To disable the button, use {@link #isEnabled} instead.
76
- *
77
- * @observable
78
- * @default true
79
- * @member {Boolean} #isOn
80
- */
81
-
82
- /**
83
- * Controls whether the button view is enabled, i.e. it can be clicked and execute an action.
84
- *
85
- * To change the "on" state of the button, use {@link #isOn} instead.
86
- *
87
- * @observable
88
- * @default true
89
- * @member {Boolean} #isEnabled
90
- */
91
-
92
- /**
93
- * Controls whether the button view is visible. Visible by default, buttons are hidden
94
- * using a CSS class.
95
- *
96
- * @observable
97
- * @default true
98
- * @member {Boolean} #isVisible
99
- */
100
-
101
- /**
102
- * Controls whether the button view is a toggle button (two–state) for assistive technologies.
103
- *
104
- * @observable
105
- * @default false
106
- * @member {Boolean} #isToggleable
107
- */
108
-
109
- /**
110
- * (Optional) Controls whether the label of the button is hidden (e.g. an icon–only button).
111
- *
112
- * @observable
113
- * @default false
114
- * @member {Boolean} #withText
115
- */
116
-
117
- /**
118
- * (Optional) Controls whether the keystroke of the button is displayed next to its
119
- * {@link module:ui/button/button~Button#label label}.
120
- *
121
- * **Note**: This property requires a {@link module:ui/button/button~Button#keystroke keystroke}
122
- * to be defined in the first place.
123
- *
124
- * @observable
125
- * @default false
126
- * @member {Boolean} #withKeystroke
127
- */
128
-
129
- /**
130
- * (Optional) An XML {@link module:ui/icon/iconview~IconView#content content} of the icon.
131
- * When defined, an `iconView` should be added to the button.
132
- *
133
- * @observable
134
- * @member {String} #icon
135
- */
136
-
137
- /**
138
- * (Optional) Controls the `tabindex` HTML attribute of the button. By default, the button is focusable
139
- * but does not included in the <kbd>Tab</kbd> order.
140
- *
141
- * @observable
142
- * @default -1
143
- * @member {String} #tabindex
144
- */
145
-
146
- /**
147
- * (Optional) The additional CSS class set on the button.
148
- *
149
- * @observable
150
- * @member {String} #class
151
- */
152
-
153
- /**
154
- * (Optional) The value of the `style` attribute of the label.
155
- *
156
- * @observable
157
- * @member {String} #labelStyle
158
- */
159
-
160
- /**
161
- * Fired when the button view is clicked. It won't be fired when the button {@link #isEnabled}
162
- * is `false`.
163
- *
164
- * @event execute
165
- */
@@ -1,22 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module ui/dropdown/button/dropdownbutton
8
- */
9
-
10
- /**
11
- * The dropdown button interface.
12
- *
13
- * @interface module:ui/dropdown/button/dropdownbutton~DropdownButton
14
- * @extends module:ui/button/button~Button
15
- */
16
-
17
- /**
18
- * Fired when the dropdown should be opened.
19
- * It will not be fired when the button {@link #isEnabled is disabled}.
20
- *
21
- * @event open
22
- */
@@ -1,27 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
-
6
- /**
7
- * @module ui/dropdown/dropdownpanelfocusable
8
- */
9
-
10
- /**
11
- * The dropdown panel interface for focusable contents. It provides two methods for managing focus of the contents
12
- * of dropdown's panel.
13
- *
14
- * @interface module:ui/dropdown/dropdownpanelfocusable~DropdownPanelFocusable
15
- */
16
-
17
- /**
18
- * Focuses the view element or first item in view collection on opening dropdown's panel.
19
- *
20
- * @method #focus
21
- */
22
-
23
- /**
24
- * Focuses the view element or last item in view collection on opening dropdown's panel.
25
- *
26
- * @method #focusLast
27
- */