@ckeditor/ckeditor5-ui 35.2.1 → 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.
- package/package.json +31 -23
- package/src/bindings/addkeyboardhandlingforgrid.js +45 -57
- package/src/bindings/clickoutsidehandler.js +15 -21
- package/src/bindings/injectcsstransitiondisabler.js +16 -20
- package/src/bindings/preventdefault.js +6 -8
- package/src/bindings/submithandler.js +5 -7
- package/src/button/button.js +5 -0
- package/src/button/buttonview.js +220 -259
- package/src/button/switchbuttonview.js +56 -71
- package/src/colorgrid/colorgridview.js +135 -197
- package/src/colorgrid/colortileview.js +37 -47
- package/src/colorgrid/utils.js +57 -66
- package/src/componentfactory.js +79 -93
- package/src/dropdown/button/dropdownbutton.js +5 -0
- package/src/dropdown/button/dropdownbuttonview.js +44 -57
- package/src/dropdown/button/splitbuttonview.js +159 -207
- package/src/dropdown/dropdownpanelfocusable.js +5 -0
- package/src/dropdown/dropdownpanelview.js +101 -112
- package/src/dropdown/dropdownview.js +396 -438
- package/src/dropdown/utils.js +164 -213
- package/src/editableui/editableuiview.js +125 -141
- package/src/editableui/inline/inlineeditableuiview.js +44 -54
- package/src/editorui/bodycollection.js +61 -75
- package/src/editorui/boxed/boxededitoruiview.js +91 -104
- package/src/editorui/editoruiview.js +30 -39
- package/src/focuscycler.js +214 -245
- package/src/formheader/formheaderview.js +58 -70
- package/src/icon/iconview.js +145 -111
- package/src/iframe/iframeview.js +37 -49
- package/src/index.js +0 -17
- package/src/input/inputview.js +170 -198
- package/src/inputnumber/inputnumberview.js +48 -56
- package/src/inputtext/inputtextview.js +14 -18
- package/src/label/labelview.js +44 -53
- package/src/labeledfield/labeledfieldview.js +212 -235
- package/src/labeledfield/utils.js +39 -57
- package/src/labeledinput/labeledinputview.js +190 -221
- package/src/list/listitemview.js +40 -50
- package/src/list/listseparatorview.js +15 -19
- package/src/list/listview.js +94 -115
- package/src/model.js +19 -25
- package/src/notification/notification.js +151 -202
- package/src/panel/balloon/balloonpanelview.js +535 -628
- package/src/panel/balloon/contextualballoon.js +611 -732
- package/src/panel/sticky/stickypanelview.js +238 -270
- package/src/template.js +1049 -1479
- package/src/toolbar/balloon/balloontoolbar.js +337 -424
- package/src/toolbar/block/blockbuttonview.js +32 -42
- package/src/toolbar/block/blocktoolbar.js +375 -477
- package/src/toolbar/normalizetoolbarconfig.js +17 -21
- package/src/toolbar/toolbarlinebreakview.js +15 -19
- package/src/toolbar/toolbarseparatorview.js +15 -19
- package/src/toolbar/toolbarview.js +866 -1053
- package/src/tooltipmanager.js +324 -353
- package/src/view.js +389 -430
- package/src/viewcollection.js +147 -178
- package/src/button/button.jsdoc +0 -165
- package/src/dropdown/button/dropdownbutton.jsdoc +0 -22
- package/src/dropdown/dropdownpanelfocusable.jsdoc +0 -27
package/src/view.js
CHANGED
|
@@ -2,22 +2,18 @@
|
|
|
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
|
-
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-invalid-void-type, new-cap */
|
|
6
6
|
/**
|
|
7
7
|
* @module ui/view
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
9
|
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
11
10
|
import ViewCollection from './viewcollection';
|
|
12
11
|
import Template from './template';
|
|
13
12
|
import DomEmitterMixin from '@ckeditor/ckeditor5-utils/src/dom/emittermixin';
|
|
14
|
-
import
|
|
13
|
+
import { Observable } from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
|
15
14
|
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
|
|
16
|
-
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
17
15
|
import isIterable from '@ckeditor/ckeditor5-utils/src/isiterable';
|
|
18
|
-
|
|
19
16
|
import '../theme/globals/globals.css';
|
|
20
|
-
|
|
21
17
|
/**
|
|
22
18
|
* The basic view class, which represents an HTML element created out of a
|
|
23
19
|
* {@link module:ui/view~View#template}. Views are building blocks of the user interface and handle
|
|
@@ -83,428 +79,391 @@ import '../theme/globals/globals.css';
|
|
|
83
79
|
*
|
|
84
80
|
* @mixes module:utils/observablemixin~ObservableMixin
|
|
85
81
|
*/
|
|
86
|
-
export default class View {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
// Auto–register view children from #template.
|
|
474
|
-
this.registerChild( this.template.getViews() );
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
this.isRendered = true;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Recursively destroys the view instance and child views added by {@link #registerChild} and
|
|
482
|
-
* residing in collections created by the {@link #createCollection}.
|
|
483
|
-
*
|
|
484
|
-
* Destruction disables all event listeners:
|
|
485
|
-
* * created on the view, e.g. `view.on( 'event', () => {} )`,
|
|
486
|
-
* * defined in the {@link #template} for DOM events.
|
|
487
|
-
*/
|
|
488
|
-
destroy() {
|
|
489
|
-
this.stopListening();
|
|
490
|
-
|
|
491
|
-
this._viewCollections.map( c => c.destroy() );
|
|
492
|
-
|
|
493
|
-
// Template isn't obligatory for views.
|
|
494
|
-
if ( this.template && this.template._revertData ) {
|
|
495
|
-
this.template.revert( this.element );
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Event fired by the {@link #render} method. Actual rendering is executed as a listener to
|
|
501
|
-
* this event with the default priority.
|
|
502
|
-
*
|
|
503
|
-
* See {@link module:utils/observablemixin~ObservableMixin#decorate} for more information and samples.
|
|
504
|
-
*
|
|
505
|
-
* @event render
|
|
506
|
-
*/
|
|
82
|
+
export default class View extends DomEmitterMixin(Observable) {
|
|
83
|
+
/**
|
|
84
|
+
* Creates an instance of the {@link module:ui/view~View} class.
|
|
85
|
+
*
|
|
86
|
+
* Also see {@link #render}.
|
|
87
|
+
*
|
|
88
|
+
* @param {module:utils/locale~Locale} [locale] The localization services instance.
|
|
89
|
+
*/
|
|
90
|
+
constructor(locale) {
|
|
91
|
+
super();
|
|
92
|
+
/**
|
|
93
|
+
* An HTML element of the view. `null` until {@link #render rendered}
|
|
94
|
+
* from the {@link #template}.
|
|
95
|
+
*
|
|
96
|
+
* class SampleView extends View {
|
|
97
|
+
* constructor() {
|
|
98
|
+
* super();
|
|
99
|
+
*
|
|
100
|
+
* // A template instance the #element will be created from.
|
|
101
|
+
* this.setTemplate( {
|
|
102
|
+
* tag: 'p'
|
|
103
|
+
*
|
|
104
|
+
* // ...
|
|
105
|
+
* } );
|
|
106
|
+
* }
|
|
107
|
+
* }
|
|
108
|
+
*
|
|
109
|
+
* const view = new SampleView();
|
|
110
|
+
*
|
|
111
|
+
* // Renders the #template.
|
|
112
|
+
* view.render();
|
|
113
|
+
*
|
|
114
|
+
* // Append the HTML element of the view to <body>.
|
|
115
|
+
* document.body.appendChild( view.element );
|
|
116
|
+
*
|
|
117
|
+
* **Note**: The element of the view can also be assigned directly:
|
|
118
|
+
*
|
|
119
|
+
* view.element = document.querySelector( '#my-container' );
|
|
120
|
+
*
|
|
121
|
+
* @member {HTMLElement}
|
|
122
|
+
*/
|
|
123
|
+
this.element = null;
|
|
124
|
+
/**
|
|
125
|
+
* Set `true` when the view has already been {@link module:ui/view~View#render rendered}.
|
|
126
|
+
*
|
|
127
|
+
* @readonly
|
|
128
|
+
* @member {Boolean} #isRendered
|
|
129
|
+
*/
|
|
130
|
+
this.isRendered = false;
|
|
131
|
+
/**
|
|
132
|
+
* A set of tools to localize the user interface.
|
|
133
|
+
*
|
|
134
|
+
* Also see {@link module:core/editor/editor~Editor#locale}.
|
|
135
|
+
*
|
|
136
|
+
* @readonly
|
|
137
|
+
* @member {module:utils/locale~Locale}
|
|
138
|
+
*/
|
|
139
|
+
this.locale = locale;
|
|
140
|
+
/**
|
|
141
|
+
* Shorthand for {@link module:utils/locale~Locale#t}.
|
|
142
|
+
*
|
|
143
|
+
* Note: If {@link #locale} instance hasn't been passed to the view this method may not
|
|
144
|
+
* be available.
|
|
145
|
+
*
|
|
146
|
+
* @see module:utils/locale~Locale#t
|
|
147
|
+
* @method
|
|
148
|
+
*/
|
|
149
|
+
this.t = locale && locale.t;
|
|
150
|
+
/**
|
|
151
|
+
* Collections registered with {@link #createCollection}.
|
|
152
|
+
*
|
|
153
|
+
* @protected
|
|
154
|
+
* @member {Set.<module:ui/viewcollection~ViewCollection>}
|
|
155
|
+
*/
|
|
156
|
+
this._viewCollections = new Collection();
|
|
157
|
+
/**
|
|
158
|
+
* A collection of view instances, which have been added directly
|
|
159
|
+
* into the {@link module:ui/template~Template#children}.
|
|
160
|
+
*
|
|
161
|
+
* @protected
|
|
162
|
+
* @member {module:ui/viewcollection~ViewCollection}
|
|
163
|
+
*/
|
|
164
|
+
this._unboundChildren = this.createCollection();
|
|
165
|
+
// Pass parent locale to its children.
|
|
166
|
+
this._viewCollections.on('add', (evt, collection) => {
|
|
167
|
+
collection.locale = locale;
|
|
168
|
+
collection.t = locale && locale.t;
|
|
169
|
+
});
|
|
170
|
+
/**
|
|
171
|
+
* Template of this view. It provides the {@link #element} representing
|
|
172
|
+
* the view in DOM, which is {@link #render rendered}.
|
|
173
|
+
*
|
|
174
|
+
* @member {module:ui/template~Template} #template
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Cached {@link module:ui/template~BindChain bind chain} object created by the
|
|
178
|
+
* {@link #template}. See {@link #bindTemplate}.
|
|
179
|
+
*
|
|
180
|
+
* @private
|
|
181
|
+
* @member {Object} #_bindTemplate
|
|
182
|
+
*/
|
|
183
|
+
this.decorate('render');
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Shorthand for {@link module:ui/template~Template.bind}, a binding
|
|
187
|
+
* {@link module:ui/template~BindChain interface} pre–configured for the view instance.
|
|
188
|
+
*
|
|
189
|
+
* It provides {@link module:ui/template~BindChain#to `to()`} and
|
|
190
|
+
* {@link module:ui/template~BindChain#if `if()`} methods that initialize bindings with
|
|
191
|
+
* observable attributes and attach DOM listeners.
|
|
192
|
+
*
|
|
193
|
+
* class SampleView extends View {
|
|
194
|
+
* constructor( locale ) {
|
|
195
|
+
* super( locale );
|
|
196
|
+
*
|
|
197
|
+
* const bind = this.bindTemplate;
|
|
198
|
+
*
|
|
199
|
+
* // These {@link module:utils/observablemixin~Observable observable} attributes will control
|
|
200
|
+
* // the state of the view in DOM.
|
|
201
|
+
* this.set( {
|
|
202
|
+
* elementClass: 'foo',
|
|
203
|
+
* isEnabled: true
|
|
204
|
+
* } );
|
|
205
|
+
*
|
|
206
|
+
* this.setTemplate( {
|
|
207
|
+
* tag: 'p',
|
|
208
|
+
*
|
|
209
|
+
* attributes: {
|
|
210
|
+
* // The class HTML attribute will follow elementClass
|
|
211
|
+
* // and isEnabled view attributes.
|
|
212
|
+
* class: [
|
|
213
|
+
* bind.to( 'elementClass' )
|
|
214
|
+
* bind.if( 'isEnabled', 'present-when-enabled' )
|
|
215
|
+
* ]
|
|
216
|
+
* },
|
|
217
|
+
*
|
|
218
|
+
* on: {
|
|
219
|
+
* // The view will fire the "clicked" event upon clicking <p> in DOM.
|
|
220
|
+
* click: bind.to( 'clicked' )
|
|
221
|
+
* }
|
|
222
|
+
* } );
|
|
223
|
+
* }
|
|
224
|
+
* }
|
|
225
|
+
*
|
|
226
|
+
* @method #bindTemplate
|
|
227
|
+
*/
|
|
228
|
+
get bindTemplate() {
|
|
229
|
+
if (this._bindTemplate) {
|
|
230
|
+
return this._bindTemplate;
|
|
231
|
+
}
|
|
232
|
+
return (this._bindTemplate = Template.bind(this, this));
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Creates a new collection of views, which can be used as
|
|
236
|
+
* {@link module:ui/template~Template#children} of this view.
|
|
237
|
+
*
|
|
238
|
+
* class SampleView extends View {
|
|
239
|
+
* constructor( locale ) {
|
|
240
|
+
* super( locale );
|
|
241
|
+
*
|
|
242
|
+
* const child = new ChildView( locale );
|
|
243
|
+
* this.items = this.createCollection( [ child ] );
|
|
244
|
+
*
|
|
245
|
+
* this.setTemplate( {
|
|
246
|
+
* tag: 'p',
|
|
247
|
+
*
|
|
248
|
+
* // `items` collection will render here.
|
|
249
|
+
* children: this.items
|
|
250
|
+
* } );
|
|
251
|
+
* }
|
|
252
|
+
* }
|
|
253
|
+
*
|
|
254
|
+
* const view = new SampleView( locale );
|
|
255
|
+
* view.render();
|
|
256
|
+
*
|
|
257
|
+
* // It will append <p><child#element></p> to the <body>.
|
|
258
|
+
* document.body.appendChild( view.element );
|
|
259
|
+
*
|
|
260
|
+
* @param {Iterable.<module:ui/view~View>} [views] Initial views of the collection.
|
|
261
|
+
* @returns {module:ui/viewcollection~ViewCollection} A new collection of view instances.
|
|
262
|
+
*/
|
|
263
|
+
createCollection(views) {
|
|
264
|
+
const collection = new ViewCollection(views);
|
|
265
|
+
this._viewCollections.add(collection);
|
|
266
|
+
return collection;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Registers a new child view under the view instance. Once registered, a child
|
|
270
|
+
* view is managed by its parent, including {@link #render rendering}
|
|
271
|
+
* and {@link #destroy destruction}.
|
|
272
|
+
*
|
|
273
|
+
* To revert this, use {@link #deregisterChild}.
|
|
274
|
+
*
|
|
275
|
+
* class SampleView extends View {
|
|
276
|
+
* constructor( locale ) {
|
|
277
|
+
* super( locale );
|
|
278
|
+
*
|
|
279
|
+
* this.childA = new SomeChildView( locale );
|
|
280
|
+
* this.childB = new SomeChildView( locale );
|
|
281
|
+
*
|
|
282
|
+
* this.setTemplate( { tag: 'p' } );
|
|
283
|
+
*
|
|
284
|
+
* // Register the children.
|
|
285
|
+
* this.registerChild( [ this.childA, this.childB ] );
|
|
286
|
+
* }
|
|
287
|
+
*
|
|
288
|
+
* render() {
|
|
289
|
+
* super.render();
|
|
290
|
+
*
|
|
291
|
+
* this.element.appendChild( this.childA.element );
|
|
292
|
+
* this.element.appendChild( this.childB.element );
|
|
293
|
+
* }
|
|
294
|
+
* }
|
|
295
|
+
*
|
|
296
|
+
* const view = new SampleView( locale );
|
|
297
|
+
*
|
|
298
|
+
* view.render();
|
|
299
|
+
*
|
|
300
|
+
* // Will append <p><childA#element><b></b><childB#element></p>.
|
|
301
|
+
* document.body.appendChild( view.element );
|
|
302
|
+
*
|
|
303
|
+
* **Note**: There's no need to add child views if they're already referenced in the
|
|
304
|
+
* {@link #template}:
|
|
305
|
+
*
|
|
306
|
+
* class SampleView extends View {
|
|
307
|
+
* constructor( locale ) {
|
|
308
|
+
* super( locale );
|
|
309
|
+
*
|
|
310
|
+
* this.childA = new SomeChildView( locale );
|
|
311
|
+
* this.childB = new SomeChildView( locale );
|
|
312
|
+
*
|
|
313
|
+
* this.setTemplate( {
|
|
314
|
+
* tag: 'p',
|
|
315
|
+
*
|
|
316
|
+
* // These children will be added automatically. There's no
|
|
317
|
+
* // need to call {@link #registerChild} for any of them.
|
|
318
|
+
* children: [ this.childA, this.childB ]
|
|
319
|
+
* } );
|
|
320
|
+
* }
|
|
321
|
+
*
|
|
322
|
+
* // ...
|
|
323
|
+
* }
|
|
324
|
+
*
|
|
325
|
+
* @param {module:ui/view~View|Iterable.<module:ui/view~View>} children Children views to be registered.
|
|
326
|
+
*/
|
|
327
|
+
registerChild(children) {
|
|
328
|
+
if (!isIterable(children)) {
|
|
329
|
+
children = [children];
|
|
330
|
+
}
|
|
331
|
+
for (const child of children) {
|
|
332
|
+
this._unboundChildren.add(child);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The opposite of {@link #registerChild}. Removes a child view from this view instance.
|
|
337
|
+
* Once removed, the child is no longer managed by its parent, e.g. it can safely
|
|
338
|
+
* become a child of another parent view.
|
|
339
|
+
*
|
|
340
|
+
* @see #registerChild
|
|
341
|
+
* @param {module:ui/view~View|Iterable.<module:ui/view~View>} children Child views to be removed.
|
|
342
|
+
*/
|
|
343
|
+
deregisterChild(children) {
|
|
344
|
+
if (!isIterable(children)) {
|
|
345
|
+
children = [children];
|
|
346
|
+
}
|
|
347
|
+
for (const child of children) {
|
|
348
|
+
this._unboundChildren.remove(child);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Sets the {@link #template} of the view with with given definition.
|
|
353
|
+
*
|
|
354
|
+
* A shorthand for:
|
|
355
|
+
*
|
|
356
|
+
* view.setTemplate( definition );
|
|
357
|
+
*
|
|
358
|
+
* @param {module:ui/template~TemplateDefinition} definition Definition of view's template.
|
|
359
|
+
*/
|
|
360
|
+
setTemplate(definition) {
|
|
361
|
+
this.template = new Template(definition);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* {@link module:ui/template~Template.extend Extends} the {@link #template} of the view with
|
|
365
|
+
* with given definition.
|
|
366
|
+
*
|
|
367
|
+
* A shorthand for:
|
|
368
|
+
*
|
|
369
|
+
* Template.extend( view.template, definition );
|
|
370
|
+
*
|
|
371
|
+
* **Note**: Is requires the {@link #template} to be already set. See {@link #setTemplate}.
|
|
372
|
+
*
|
|
373
|
+
* @param {module:ui/template~TemplateDefinition} definition Definition which
|
|
374
|
+
* extends the {@link #template}.
|
|
375
|
+
*/
|
|
376
|
+
extendTemplate(definition) {
|
|
377
|
+
Template.extend(this.template, definition);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Recursively renders the view.
|
|
381
|
+
*
|
|
382
|
+
* Once the view is rendered:
|
|
383
|
+
* * the {@link #element} becomes an HTML element out of {@link #template},
|
|
384
|
+
* * the {@link #isRendered} flag is set `true`.
|
|
385
|
+
*
|
|
386
|
+
* **Note**: The children of the view:
|
|
387
|
+
* * defined directly in the {@link #template}
|
|
388
|
+
* * residing in collections created by the {@link #createCollection} method,
|
|
389
|
+
* * and added by {@link #registerChild}
|
|
390
|
+
* are also rendered in the process.
|
|
391
|
+
*
|
|
392
|
+
* In general, `render()` method is the right place to keep the code which refers to the
|
|
393
|
+
* {@link #element} and should be executed at the very beginning of the view's life cycle.
|
|
394
|
+
*
|
|
395
|
+
* It is possible to {@link module:ui/template~Template.extend} the {@link #template} before
|
|
396
|
+
* the view is rendered. To allow an early customization of the view (e.g. by its parent),
|
|
397
|
+
* such references should be done in `render()`.
|
|
398
|
+
*
|
|
399
|
+
* class SampleView extends View {
|
|
400
|
+
* constructor() {
|
|
401
|
+
* this.setTemplate( {
|
|
402
|
+
* // ...
|
|
403
|
+
* } );
|
|
404
|
+
* },
|
|
405
|
+
*
|
|
406
|
+
* render() {
|
|
407
|
+
* // View#element becomes available.
|
|
408
|
+
* super.render();
|
|
409
|
+
*
|
|
410
|
+
* // The "scroll" listener depends on #element.
|
|
411
|
+
* this.listenTo( window, 'scroll', () => {
|
|
412
|
+
* // A reference to #element would render the #template and make it non-extendable.
|
|
413
|
+
* if ( window.scrollY > 0 ) {
|
|
414
|
+
* this.element.scrollLeft = 100;
|
|
415
|
+
* } else {
|
|
416
|
+
* this.element.scrollLeft = 0;
|
|
417
|
+
* }
|
|
418
|
+
* } );
|
|
419
|
+
* }
|
|
420
|
+
* }
|
|
421
|
+
*
|
|
422
|
+
* const view = new SampleView();
|
|
423
|
+
*
|
|
424
|
+
* // Let's customize the view before it gets rendered.
|
|
425
|
+
* view.extendTemplate( {
|
|
426
|
+
* attributes: {
|
|
427
|
+
* class: [
|
|
428
|
+
* 'additional-class'
|
|
429
|
+
* ]
|
|
430
|
+
* }
|
|
431
|
+
* } );
|
|
432
|
+
*
|
|
433
|
+
* // Late rendering allows customization of the view.
|
|
434
|
+
* view.render();
|
|
435
|
+
*/
|
|
436
|
+
render() {
|
|
437
|
+
if (this.isRendered) {
|
|
438
|
+
/**
|
|
439
|
+
* This View has already been rendered.
|
|
440
|
+
*
|
|
441
|
+
* @error ui-view-render-already-rendered
|
|
442
|
+
*/
|
|
443
|
+
throw new CKEditorError('ui-view-render-already-rendered', this);
|
|
444
|
+
}
|
|
445
|
+
// Render #element of the view.
|
|
446
|
+
if (this.template) {
|
|
447
|
+
this.element = this.template.render();
|
|
448
|
+
// Auto–register view children from #template.
|
|
449
|
+
this.registerChild(this.template.getViews());
|
|
450
|
+
}
|
|
451
|
+
this.isRendered = true;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Recursively destroys the view instance and child views added by {@link #registerChild} and
|
|
455
|
+
* residing in collections created by the {@link #createCollection}.
|
|
456
|
+
*
|
|
457
|
+
* Destruction disables all event listeners:
|
|
458
|
+
* * created on the view, e.g. `view.on( 'event', () => {} )`,
|
|
459
|
+
* * defined in the {@link #template} for DOM events.
|
|
460
|
+
*/
|
|
461
|
+
destroy() {
|
|
462
|
+
this.stopListening();
|
|
463
|
+
this._viewCollections.map(c => c.destroy());
|
|
464
|
+
// Template isn't obligatory for views.
|
|
465
|
+
if (this.template && this.template._revertData) {
|
|
466
|
+
this.template.revert(this.element);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
507
469
|
}
|
|
508
|
-
|
|
509
|
-
mix( View, DomEmitterMixin );
|
|
510
|
-
mix( View, ObservableMixin );
|