@ckeditor/ckeditor5-ui 36.0.1 → 37.0.0-alpha.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 +23 -22
- package/src/bindings/addkeyboardhandlingforgrid.d.ts +27 -0
- package/src/bindings/addkeyboardhandlingforgrid.js +42 -34
- package/src/bindings/clickoutsidehandler.d.ts +28 -0
- package/src/bindings/clickoutsidehandler.js +5 -6
- package/src/bindings/csstransitiondisablermixin.d.ts +40 -0
- package/src/bindings/csstransitiondisablermixin.js +55 -0
- package/src/bindings/injectcsstransitiondisabler.d.ts +59 -0
- package/src/bindings/injectcsstransitiondisabler.js +23 -20
- package/src/bindings/preventdefault.d.ts +33 -0
- package/src/bindings/preventdefault.js +13 -15
- package/src/bindings/submithandler.d.ts +57 -0
- package/src/bindings/submithandler.js +22 -23
- package/src/button/button.d.ts +154 -0
- package/src/button/buttonview.d.ts +155 -0
- package/src/button/buttonview.js +16 -60
- package/src/button/switchbuttonview.d.ts +45 -0
- package/src/button/switchbuttonview.js +9 -18
- package/src/colorgrid/colorgridview.d.ts +132 -0
- package/src/colorgrid/colorgridview.js +8 -40
- package/src/colorgrid/colortileview.d.ts +28 -0
- package/src/colorgrid/colortileview.js +0 -13
- package/src/colorgrid/utils.d.ts +47 -0
- package/src/colorgrid/utils.js +7 -13
- package/src/componentfactory.d.ts +81 -0
- package/src/componentfactory.js +21 -35
- package/src/dropdown/button/dropdownbutton.d.ts +25 -0
- package/src/dropdown/button/dropdownbuttonview.d.ts +48 -0
- package/src/dropdown/button/dropdownbuttonview.js +11 -21
- package/src/dropdown/button/splitbuttonview.d.ts +145 -0
- package/src/dropdown/button/splitbuttonview.js +10 -51
- package/src/dropdown/dropdownpanelfocusable.d.ts +21 -0
- package/src/dropdown/dropdownpanelview.d.ts +62 -0
- package/src/dropdown/dropdownpanelview.js +2 -30
- package/src/dropdown/dropdownview.d.ts +315 -0
- package/src/dropdown/dropdownview.js +121 -222
- package/src/dropdown/utils.d.ts +219 -0
- package/src/dropdown/utils.js +112 -106
- package/src/editableui/editableuiview.d.ts +71 -0
- package/src/editableui/editableuiview.js +14 -43
- package/src/editableui/inline/inlineeditableuiview.d.ts +40 -0
- package/src/editableui/inline/inlineeditableuiview.js +5 -15
- package/src/editorui/bodycollection.d.ts +51 -0
- package/src/editorui/bodycollection.js +2 -16
- package/src/editorui/boxed/boxededitoruiview.d.ts +40 -0
- package/src/editorui/boxed/boxededitoruiview.js +1 -27
- package/src/editorui/editorui.d.ts +264 -0
- package/src/editorui/editorui.js +21 -128
- package/src/editorui/editoruiview.d.ts +39 -0
- package/src/editorui/editoruiview.js +1 -10
- package/src/focuscycler.d.ts +183 -0
- package/src/focuscycler.js +34 -90
- package/src/formheader/formheaderview.d.ts +53 -0
- package/src/formheader/formheaderview.js +3 -24
- package/src/icon/iconview.d.ts +78 -0
- package/src/icon/iconview.js +0 -50
- package/src/iframe/iframeview.d.ts +50 -0
- package/src/iframe/iframeview.js +2 -2
- package/src/index.d.ts +54 -0
- package/src/index.js +1 -0
- package/src/input/inputview.d.ts +121 -0
- package/src/input/inputview.js +0 -82
- package/src/inputnumber/inputnumberview.d.ts +49 -0
- package/src/inputnumber/inputnumberview.js +5 -28
- package/src/inputtext/inputtextview.d.ts +18 -0
- package/src/inputtext/inputtextview.js +0 -2
- package/src/label/labelview.d.ts +36 -0
- package/src/label/labelview.js +0 -20
- package/src/labeledfield/labeledfieldview.d.ts +182 -0
- package/src/labeledfield/labeledfieldview.js +20 -126
- package/src/labeledfield/utils.d.ts +93 -0
- package/src/labeledfield/utils.js +24 -18
- package/src/labeledinput/labeledinputview.d.ts +125 -0
- package/src/labeledinput/labeledinputview.js +7 -90
- package/src/list/listitemview.d.ts +35 -0
- package/src/list/listitemview.js +0 -16
- package/src/list/listseparatorview.d.ts +18 -0
- package/src/list/listseparatorview.js +0 -2
- package/src/list/listview.d.ts +59 -0
- package/src/list/listview.js +0 -33
- package/src/model.d.ts +22 -0
- package/src/model.js +2 -4
- package/src/notification/notification.d.ts +216 -0
- package/src/notification/notification.js +64 -51
- package/src/panel/balloon/balloonpanelview.d.ts +685 -0
- package/src/panel/balloon/balloonpanelview.js +146 -168
- package/src/panel/balloon/contextualballoon.d.ts +240 -0
- package/src/panel/balloon/contextualballoon.js +41 -171
- package/src/panel/sticky/stickypanelview.d.ts +132 -0
- package/src/panel/sticky/stickypanelview.js +0 -115
- package/src/template.d.ts +940 -0
- package/src/template.js +396 -460
- package/src/toolbar/balloon/balloontoolbar.d.ts +124 -0
- package/src/toolbar/balloon/balloontoolbar.js +15 -81
- package/src/toolbar/block/blockbuttonview.d.ts +35 -0
- package/src/toolbar/block/blockbuttonview.js +1 -13
- package/src/toolbar/block/blocktoolbar.d.ts +159 -0
- package/src/toolbar/block/blocktoolbar.js +32 -69
- package/src/toolbar/normalizetoolbarconfig.d.ts +39 -0
- package/src/toolbar/normalizetoolbarconfig.js +12 -8
- package/src/toolbar/toolbarlinebreakview.d.ts +18 -0
- package/src/toolbar/toolbarlinebreakview.js +0 -2
- package/src/toolbar/toolbarseparatorview.d.ts +18 -0
- package/src/toolbar/toolbarseparatorview.js +0 -2
- package/src/toolbar/toolbarview.d.ts +241 -0
- package/src/toolbar/toolbarview.js +54 -305
- package/src/tooltipmanager.d.ts +180 -0
- package/src/tooltipmanager.js +47 -94
- package/src/uiconfig.d.ts +82 -0
- package/src/uiconfig.js +5 -0
- package/src/view.d.ts +422 -0
- package/src/view.js +182 -251
- package/src/viewcollection.d.ts +139 -0
- package/src/viewcollection.js +62 -56
package/src/template.js
CHANGED
|
@@ -18,105 +18,57 @@ const xhtmlNs = 'http://www.w3.org/1999/xhtml';
|
|
|
18
18
|
*
|
|
19
19
|
* A simple template can look like this:
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const bind = Template.bind( observable, emitter );
|
|
22
23
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
24
|
+
* new Template( {
|
|
25
|
+
* tag: 'p',
|
|
26
|
+
* attributes: {
|
|
27
|
+
* class: 'foo',
|
|
28
|
+
* style: {
|
|
29
|
+
* backgroundColor: 'yellow'
|
|
30
|
+
* }
|
|
31
|
+
* },
|
|
32
|
+
* on: {
|
|
33
|
+
* click: bind.to( 'clicked' )
|
|
34
|
+
* },
|
|
35
|
+
* children: [
|
|
36
|
+
* 'A paragraph.'
|
|
37
|
+
* ]
|
|
38
|
+
* } ).render();
|
|
39
|
+
* ```
|
|
38
40
|
*
|
|
39
41
|
* and it will render the following HTML element:
|
|
40
42
|
*
|
|
41
|
-
*
|
|
43
|
+
* ```html
|
|
44
|
+
* <p class="foo" style="background-color: yellow;">A paragraph.</p>
|
|
45
|
+
* ```
|
|
42
46
|
*
|
|
43
47
|
* Additionally, the `observable` will always fire `clicked` upon clicking `<p>` in the DOM.
|
|
44
48
|
*
|
|
45
49
|
* See {@link module:ui/template~TemplateDefinition} to know more about templates and complex
|
|
46
50
|
* template definitions.
|
|
47
|
-
*
|
|
48
|
-
* @mixes module:utils/emittermixin~EmitterMixin
|
|
49
51
|
*/
|
|
50
52
|
export default class Template extends EmitterMixin() {
|
|
51
53
|
/**
|
|
52
54
|
* Creates an instance of the {@link ~Template} class.
|
|
53
55
|
*
|
|
54
|
-
* @param
|
|
56
|
+
* @param def The definition of the template.
|
|
55
57
|
*/
|
|
56
58
|
constructor(def) {
|
|
57
59
|
super();
|
|
58
60
|
Object.assign(this, normalize(clone(def)));
|
|
59
|
-
/**
|
|
60
|
-
* Indicates whether this particular Template instance has been
|
|
61
|
-
* {@link #render rendered}.
|
|
62
|
-
*
|
|
63
|
-
* @readonly
|
|
64
|
-
* @protected
|
|
65
|
-
* @member {Boolean}
|
|
66
|
-
*/
|
|
67
61
|
this._isRendered = false;
|
|
68
|
-
/**
|
|
69
|
-
* The tag (`tagName`) of this template, e.g. `div`. It also indicates that the template
|
|
70
|
-
* renders to an HTML element.
|
|
71
|
-
*
|
|
72
|
-
* @member {String} #tag
|
|
73
|
-
*/
|
|
74
|
-
/**
|
|
75
|
-
* The text of the template. It also indicates that the template renders to a DOM text node.
|
|
76
|
-
*
|
|
77
|
-
* @member {Array.<String|module:ui/template~TemplateValueSchema>} #text
|
|
78
|
-
*/
|
|
79
|
-
/**
|
|
80
|
-
* The attributes of the template, e.g. `{ id: [ 'ck-id' ] }`, corresponding with
|
|
81
|
-
* the attributes of an HTML element.
|
|
82
|
-
*
|
|
83
|
-
* **Note**: This property only makes sense when {@link #tag} is defined.
|
|
84
|
-
*
|
|
85
|
-
* @member {Object} #attributes
|
|
86
|
-
*/
|
|
87
|
-
/**
|
|
88
|
-
* The children of the template. They can be either:
|
|
89
|
-
* * independent instances of {@link ~Template} (sub–templates),
|
|
90
|
-
* * native DOM Nodes.
|
|
91
|
-
*
|
|
92
|
-
* **Note**: This property only makes sense when {@link #tag} is defined.
|
|
93
|
-
*
|
|
94
|
-
* @member {Array.<module:ui/template~Template|Node>} #children
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* The DOM event listeners of the template.
|
|
98
|
-
*
|
|
99
|
-
* @member {Object} #eventListeners
|
|
100
|
-
*/
|
|
101
|
-
/**
|
|
102
|
-
* The data used by the {@link #revert} method to restore a node to its original state.
|
|
103
|
-
*
|
|
104
|
-
* See: {@link #apply}.
|
|
105
|
-
*
|
|
106
|
-
* @readonly
|
|
107
|
-
* @protected
|
|
108
|
-
* @member {module:ui/template~RenderData}
|
|
109
|
-
*/
|
|
110
62
|
this._revertData = null;
|
|
111
63
|
}
|
|
112
64
|
/**
|
|
113
65
|
* Renders a DOM Node (an HTML element or text) out of the template.
|
|
114
66
|
*
|
|
115
|
-
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* const domNode = new Template( { ... } ).render();
|
|
69
|
+
* ```
|
|
116
70
|
*
|
|
117
71
|
* See: {@link #apply}.
|
|
118
|
-
*
|
|
119
|
-
* @returns {HTMLElement|Text}
|
|
120
72
|
*/
|
|
121
73
|
render() {
|
|
122
74
|
const node = this._renderNode({
|
|
@@ -140,29 +92,31 @@ export default class Template extends EmitterMixin() {
|
|
|
140
92
|
* **Note:** The process of applying a template can be easily reverted using the
|
|
141
93
|
* {@link module:ui/template~Template#revert} method.
|
|
142
94
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* const element = document.createElement( 'div' );
|
|
97
|
+
* const observable = new Model( { divClass: 'my-div' } );
|
|
98
|
+
* const emitter = Object.create( EmitterMixin );
|
|
99
|
+
* const bind = Template.bind( observable, emitter );
|
|
147
100
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
101
|
+
* new Template( {
|
|
102
|
+
* attributes: {
|
|
103
|
+
* id: 'first-div',
|
|
104
|
+
* class: bind.to( 'divClass' )
|
|
105
|
+
* },
|
|
106
|
+
* on: {
|
|
107
|
+
* click: bind( 'elementClicked' ) // Will be fired by the observable.
|
|
108
|
+
* },
|
|
109
|
+
* children: [
|
|
110
|
+
* 'Div text.'
|
|
111
|
+
* ]
|
|
112
|
+
* } ).apply( element );
|
|
160
113
|
*
|
|
161
|
-
*
|
|
114
|
+
* console.log( element.outerHTML ); // -> '<div id="first-div" class="my-div"></div>'
|
|
115
|
+
* ```
|
|
162
116
|
*
|
|
163
117
|
* @see module:ui/template~Template#render
|
|
164
118
|
* @see module:ui/template~Template#revert
|
|
165
|
-
* @param
|
|
119
|
+
* @param node Root node for the template to apply.
|
|
166
120
|
*/
|
|
167
121
|
apply(node) {
|
|
168
122
|
this._revertData = getEmptyRevertData();
|
|
@@ -177,7 +131,7 @@ export default class Template extends EmitterMixin() {
|
|
|
177
131
|
/**
|
|
178
132
|
* Reverts a template {@link module:ui/template~Template#apply applied} to a DOM node.
|
|
179
133
|
*
|
|
180
|
-
* @param
|
|
134
|
+
* @param node The root node for the template to revert. In most of the cases, it is the
|
|
181
135
|
* same node used by {@link module:ui/template~Template#apply}.
|
|
182
136
|
*/
|
|
183
137
|
revert(node) {
|
|
@@ -195,29 +149,29 @@ export default class Template extends EmitterMixin() {
|
|
|
195
149
|
* Returns an iterator which traverses the template in search of {@link module:ui/view~View}
|
|
196
150
|
* instances and returns them one by one.
|
|
197
151
|
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* // Logs: viewFoo, viewBar, viewBaz
|
|
216
|
-
* for ( const view of template.getViews() ) {
|
|
217
|
-
* console.log( view );
|
|
218
|
-
* }
|
|
152
|
+
* ```ts
|
|
153
|
+
* const viewFoo = new View();
|
|
154
|
+
* const viewBar = new View();
|
|
155
|
+
* const viewBaz = new View();
|
|
156
|
+
* const template = new Template( {
|
|
157
|
+
* tag: 'div',
|
|
158
|
+
* children: [
|
|
159
|
+
* viewFoo,
|
|
160
|
+
* {
|
|
161
|
+
* tag: 'div',
|
|
162
|
+
* children: [
|
|
163
|
+
* viewBar
|
|
164
|
+
* ]
|
|
165
|
+
* },
|
|
166
|
+
* viewBaz
|
|
167
|
+
* ]
|
|
168
|
+
* } );
|
|
219
169
|
*
|
|
220
|
-
*
|
|
170
|
+
* // Logs: viewFoo, viewBar, viewBaz
|
|
171
|
+
* for ( const view of template.getViews() ) {
|
|
172
|
+
* console.log( view );
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
221
175
|
*/
|
|
222
176
|
*getViews() {
|
|
223
177
|
function* search(def) {
|
|
@@ -243,33 +197,36 @@ export default class Template extends EmitterMixin() {
|
|
|
243
197
|
* {@link module:utils/observablemixin~Observable}. Learn more about {@link module:ui/template~BindChain#to}
|
|
244
198
|
* and {@link module:ui/template~BindChain#if}.
|
|
245
199
|
*
|
|
246
|
-
*
|
|
200
|
+
* ```ts
|
|
201
|
+
* const bind = Template.bind( observable, emitter );
|
|
247
202
|
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
203
|
+
* new Template( {
|
|
204
|
+
* attributes: {
|
|
205
|
+
* // Binds the element "class" attribute to observable#classAttribute.
|
|
206
|
+
* class: bind.to( 'classAttribute' )
|
|
207
|
+
* }
|
|
208
|
+
* } ).render();
|
|
209
|
+
* ```
|
|
254
210
|
*
|
|
255
211
|
* * DOM events fired on HTML element propagated through
|
|
256
212
|
* {@link module:utils/observablemixin~Observable}. Learn more about {@link module:ui/template~BindChain#to}.
|
|
257
213
|
*
|
|
258
|
-
*
|
|
214
|
+
* ```ts
|
|
215
|
+
* const bind = Template.bind( observable, emitter );
|
|
259
216
|
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
217
|
+
* new Template( {
|
|
218
|
+
* on: {
|
|
219
|
+
* // Will be fired by the observable.
|
|
220
|
+
* click: bind( 'elementClicked' )
|
|
221
|
+
* }
|
|
222
|
+
* } ).render();
|
|
223
|
+
* ```
|
|
266
224
|
*
|
|
267
225
|
* Also see {@link module:ui/view~View#bindTemplate}.
|
|
268
226
|
*
|
|
269
|
-
* @param
|
|
270
|
-
* @param
|
|
227
|
+
* @param observable An observable which provides boundable attributes.
|
|
228
|
+
* @param emitter An emitter that listens to observable attribute
|
|
271
229
|
* changes or DOM Events (depending on the kind of the binding). Usually, a {@link module:ui/view~View} instance.
|
|
272
|
-
* @returns {module:ui/template~BindChain}
|
|
273
230
|
*/
|
|
274
231
|
static bind(observable, emitter) {
|
|
275
232
|
return {
|
|
@@ -291,57 +248,61 @@ export default class Template extends EmitterMixin() {
|
|
|
291
248
|
* Extends an existing {@link module:ui/template~Template} instance with some additional content
|
|
292
249
|
* from another {@link module:ui/template~TemplateDefinition}.
|
|
293
250
|
*
|
|
294
|
-
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* const bind = Template.bind( observable, emitter );
|
|
295
253
|
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
254
|
+
* const template = new Template( {
|
|
255
|
+
* tag: 'p',
|
|
256
|
+
* attributes: {
|
|
257
|
+
* class: 'a',
|
|
258
|
+
* data-x: bind.to( 'foo' )
|
|
259
|
+
* },
|
|
260
|
+
* children: [
|
|
261
|
+
* {
|
|
262
|
+
* tag: 'span',
|
|
263
|
+
* attributes: {
|
|
264
|
+
* class: 'b'
|
|
265
|
+
* },
|
|
266
|
+
* children: [
|
|
267
|
+
* 'Span'
|
|
268
|
+
* ]
|
|
269
|
+
* }
|
|
270
|
+
* ]
|
|
271
|
+
* } );
|
|
314
272
|
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
273
|
+
* // Instance-level extension.
|
|
274
|
+
* Template.extend( template, {
|
|
275
|
+
* attributes: {
|
|
276
|
+
* class: 'b',
|
|
277
|
+
* data-x: bind.to( 'bar' )
|
|
278
|
+
* },
|
|
279
|
+
* children: [
|
|
280
|
+
* {
|
|
281
|
+
* attributes: {
|
|
282
|
+
* class: 'c'
|
|
283
|
+
* }
|
|
284
|
+
* }
|
|
285
|
+
* ]
|
|
286
|
+
* } );
|
|
329
287
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
288
|
+
* // Child extension.
|
|
289
|
+
* Template.extend( template.children[ 0 ], {
|
|
290
|
+
* attributes: {
|
|
291
|
+
* class: 'd'
|
|
292
|
+
* }
|
|
293
|
+
* } );
|
|
294
|
+
* ```
|
|
336
295
|
*
|
|
337
296
|
* the `outerHTML` of `template.render()` is:
|
|
338
297
|
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
298
|
+
* ```html
|
|
299
|
+
* <p class="a b" data-x="{ observable.foo } { observable.bar }">
|
|
300
|
+
* <span class="b c d">Span</span>
|
|
301
|
+
* </p>
|
|
302
|
+
* ```
|
|
342
303
|
*
|
|
343
|
-
* @param
|
|
344
|
-
* @param
|
|
304
|
+
* @param template An existing template instance to be extended.
|
|
305
|
+
* @param def Additional definition to be applied to a template.
|
|
345
306
|
*/
|
|
346
307
|
static extend(template, def) {
|
|
347
308
|
if (template._isRendered) {
|
|
@@ -359,8 +320,7 @@ export default class Template extends EmitterMixin() {
|
|
|
359
320
|
/**
|
|
360
321
|
* Renders a DOM Node (either an HTML element or text) out of the template.
|
|
361
322
|
*
|
|
362
|
-
* @
|
|
363
|
-
* @param {module:ui/template~RenderData} data Rendering data.
|
|
323
|
+
* @param data Rendering data.
|
|
364
324
|
*/
|
|
365
325
|
_renderNode(data) {
|
|
366
326
|
let isInvalid;
|
|
@@ -391,8 +351,7 @@ export default class Template extends EmitterMixin() {
|
|
|
391
351
|
/**
|
|
392
352
|
* Renders an HTML element out of the template.
|
|
393
353
|
*
|
|
394
|
-
* @
|
|
395
|
-
* @param {module:ui/template~RenderData} data Rendering data.
|
|
354
|
+
* @param data Rendering data.
|
|
396
355
|
*/
|
|
397
356
|
_renderElement(data) {
|
|
398
357
|
let node = data.node;
|
|
@@ -407,8 +366,7 @@ export default class Template extends EmitterMixin() {
|
|
|
407
366
|
/**
|
|
408
367
|
* Renders a text node out of {@link module:ui/template~Template#text}.
|
|
409
368
|
*
|
|
410
|
-
* @
|
|
411
|
-
* @param {module:ui/template~RenderData} data Rendering data.
|
|
369
|
+
* @param data Rendering data.
|
|
412
370
|
*/
|
|
413
371
|
_renderText(data) {
|
|
414
372
|
let node = data.node;
|
|
@@ -450,8 +408,7 @@ export default class Template extends EmitterMixin() {
|
|
|
450
408
|
/**
|
|
451
409
|
* Renders HTML element attributes out of {@link module:ui/template~Template#attributes}.
|
|
452
410
|
*
|
|
453
|
-
* @
|
|
454
|
-
* @param {module:ui/template~RenderData} data Rendering data.
|
|
411
|
+
* @param data Rendering data.
|
|
455
412
|
*/
|
|
456
413
|
_renderAttributes(data) {
|
|
457
414
|
if (!this.attributes) {
|
|
@@ -567,28 +524,31 @@ export default class Template extends EmitterMixin() {
|
|
|
567
524
|
* Renders the `style` attribute of an HTML element based on
|
|
568
525
|
* {@link module:ui/template~Template#attributes}.
|
|
569
526
|
*
|
|
570
|
-
* A style attribute is an
|
|
527
|
+
* A style attribute is an object with static values:
|
|
571
528
|
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
529
|
+
* ```ts
|
|
530
|
+
* attributes: {
|
|
531
|
+
* style: {
|
|
532
|
+
* color: 'red'
|
|
533
|
+
* }
|
|
534
|
+
* }
|
|
535
|
+
* ```
|
|
577
536
|
*
|
|
578
537
|
* or values bound to {@link module:ui/model~Model} properties:
|
|
579
538
|
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
539
|
+
* ```ts
|
|
540
|
+
* attributes: {
|
|
541
|
+
* style: {
|
|
542
|
+
* color: bind.to( ... )
|
|
543
|
+
* }
|
|
544
|
+
* }
|
|
545
|
+
* ```
|
|
585
546
|
*
|
|
586
547
|
* Note: The `style` attribute is rendered without setting the namespace. It does not seem to be
|
|
587
548
|
* needed.
|
|
588
549
|
*
|
|
589
|
-
* @
|
|
590
|
-
* @param
|
|
591
|
-
* @param {module:ui/template~RenderData} data Rendering data.
|
|
550
|
+
* @param styles Styles located in `attributes.style` of {@link module:ui/template~TemplateDefinition}.
|
|
551
|
+
* @param data Rendering data.
|
|
592
552
|
*/
|
|
593
553
|
_renderStyleAttribute(styles, data) {
|
|
594
554
|
const node = data.node;
|
|
@@ -621,8 +581,7 @@ export default class Template extends EmitterMixin() {
|
|
|
621
581
|
/**
|
|
622
582
|
* Recursively renders HTML element's children from {@link module:ui/template~Template#children}.
|
|
623
583
|
*
|
|
624
|
-
* @
|
|
625
|
-
* @param {module:ui/template~RenderData} data Rendering data.
|
|
584
|
+
* @param data Rendering data.
|
|
626
585
|
*/
|
|
627
586
|
_renderElementChildren(data) {
|
|
628
587
|
const node = data.node;
|
|
@@ -675,8 +634,7 @@ export default class Template extends EmitterMixin() {
|
|
|
675
634
|
* Activates `on` event listeners from the {@link module:ui/template~TemplateDefinition}
|
|
676
635
|
* on an HTML element.
|
|
677
636
|
*
|
|
678
|
-
* @
|
|
679
|
-
* @param {module:ui/template~RenderData} data Rendering data.
|
|
637
|
+
* @param data Rendering data.
|
|
680
638
|
*/
|
|
681
639
|
_setUpListeners(data) {
|
|
682
640
|
if (!this.eventListeners) {
|
|
@@ -699,11 +657,9 @@ export default class Template extends EmitterMixin() {
|
|
|
699
657
|
* Note: {@link module:ui/template~TemplateValueSchema} can be for HTML element attributes or
|
|
700
658
|
* text node `textContent`.
|
|
701
659
|
*
|
|
702
|
-
* @
|
|
703
|
-
* @param
|
|
704
|
-
* @param
|
|
705
|
-
* @param {Function} options.updater A function which updates the DOM (like attribute or text).
|
|
706
|
-
* @param {module:ui/template~RenderData} options.data Rendering data.
|
|
660
|
+
* @param options Binding options.
|
|
661
|
+
* @param options.updater A function which updates the DOM (like attribute or text).
|
|
662
|
+
* @param options.data Rendering data.
|
|
707
663
|
*/
|
|
708
664
|
_bindToObservable({ schema, updater, data }) {
|
|
709
665
|
const revertData = data.revertData;
|
|
@@ -726,9 +682,8 @@ export default class Template extends EmitterMixin() {
|
|
|
726
682
|
* Reverts {@link module:ui/template~RenderData#revertData template data} from a node to
|
|
727
683
|
* return it to the original state.
|
|
728
684
|
*
|
|
729
|
-
* @
|
|
730
|
-
* @param
|
|
731
|
-
* @param {Object} revertData An object that stores information about what changes have been made by
|
|
685
|
+
* @param node A node to be reverted.
|
|
686
|
+
* @param revertData An object that stores information about what changes have been made by
|
|
732
687
|
* {@link #apply} to the node. See {@link module:ui/template~RenderData#revertData} for more information.
|
|
733
688
|
*/
|
|
734
689
|
_revertTemplateFromNode(node, revertData) {
|
|
@@ -770,54 +725,27 @@ export default class Template extends EmitterMixin() {
|
|
|
770
725
|
/**
|
|
771
726
|
* Describes a binding created by the {@link module:ui/template~Template.bind} interface.
|
|
772
727
|
*
|
|
773
|
-
* @protected
|
|
774
728
|
* @internal
|
|
775
729
|
*/
|
|
776
730
|
export class TemplateBinding {
|
|
777
731
|
/**
|
|
778
732
|
* Creates an instance of the {@link module:ui/template~TemplateBinding} class.
|
|
779
733
|
*
|
|
780
|
-
* @param
|
|
734
|
+
* @param def The definition of the binding.
|
|
781
735
|
*/
|
|
782
736
|
constructor(def) {
|
|
783
737
|
this.attribute = def.attribute;
|
|
784
738
|
this.observable = def.observable;
|
|
785
739
|
this.emitter = def.emitter;
|
|
786
740
|
this.callback = def.callback;
|
|
787
|
-
/**
|
|
788
|
-
* An observable instance of the binding. It either:
|
|
789
|
-
*
|
|
790
|
-
* * provides the attribute with the value,
|
|
791
|
-
* * or passes the event when a corresponding DOM event is fired.
|
|
792
|
-
*
|
|
793
|
-
* @member {module:utils/observablemixin~ObservableMixin} module:ui/template~TemplateBinding#observable
|
|
794
|
-
*/
|
|
795
|
-
/**
|
|
796
|
-
* An {@link module:utils/emittermixin~Emitter} used by the binding to:
|
|
797
|
-
*
|
|
798
|
-
* * listen to the attribute change in the {@link module:ui/template~TemplateBinding#observable},
|
|
799
|
-
* * or listen to the event in the DOM.
|
|
800
|
-
*
|
|
801
|
-
* @member {module:utils/emittermixin~EmitterMixin} module:ui/template~TemplateBinding#emitter
|
|
802
|
-
*/
|
|
803
|
-
/**
|
|
804
|
-
* The name of the {@link module:ui/template~TemplateBinding#observable observed attribute}.
|
|
805
|
-
*
|
|
806
|
-
* @member {String} module:ui/template~TemplateBinding#attribute
|
|
807
|
-
*/
|
|
808
|
-
/**
|
|
809
|
-
* A custom function to process the value of the {@link module:ui/template~TemplateBinding#attribute}.
|
|
810
|
-
*
|
|
811
|
-
* @member {Function} [module:ui/template~TemplateBinding#callback]
|
|
812
|
-
*/
|
|
813
741
|
}
|
|
814
742
|
/**
|
|
815
743
|
* Returns the value of the binding. It is the value of the {@link module:ui/template~TemplateBinding#attribute} in
|
|
816
744
|
* {@link module:ui/template~TemplateBinding#observable}. The value may be processed by the
|
|
817
745
|
* {@link module:ui/template~TemplateBinding#callback}, if such has been passed to the binding.
|
|
818
746
|
*
|
|
819
|
-
* @param
|
|
820
|
-
* @returns
|
|
747
|
+
* @param node A native DOM node, passed to the custom {@link module:ui/template~TemplateBinding#callback}.
|
|
748
|
+
* @returns The value of {@link module:ui/template~TemplateBinding#attribute} in
|
|
821
749
|
* {@link module:ui/template~TemplateBinding#observable}.
|
|
822
750
|
*/
|
|
823
751
|
getValue(node) {
|
|
@@ -829,10 +757,10 @@ export class TemplateBinding {
|
|
|
829
757
|
* {@link module:ui/template~TemplateBinding#observable}, then updates the DOM with the aggregated
|
|
830
758
|
* value of {@link module:ui/template~TemplateValueSchema}.
|
|
831
759
|
*
|
|
832
|
-
* @param
|
|
833
|
-
* @param
|
|
834
|
-
* @param
|
|
835
|
-
* @returns
|
|
760
|
+
* @param schema A full schema to generate an attribute or text in the DOM.
|
|
761
|
+
* @param updater A DOM updater function used to update the native DOM attribute or text.
|
|
762
|
+
* @param data Rendering data.
|
|
763
|
+
* @returns A function to sever the listener binding.
|
|
836
764
|
*/
|
|
837
765
|
activateAttributeListener(schema, updater, data) {
|
|
838
766
|
const callback = () => syncValueSchemaValue(schema, updater, data);
|
|
@@ -851,7 +779,6 @@ export class TemplateBinding {
|
|
|
851
779
|
*
|
|
852
780
|
* It is created by the {@link module:ui/template~BindChain#to} method.
|
|
853
781
|
*
|
|
854
|
-
* @protected
|
|
855
782
|
* @internal
|
|
856
783
|
*/
|
|
857
784
|
export class TemplateToBinding extends TemplateBinding {
|
|
@@ -863,10 +790,10 @@ export class TemplateToBinding extends TemplateBinding {
|
|
|
863
790
|
* Activates the listener for the native DOM event, which when fired, is propagated by
|
|
864
791
|
* the {@link module:ui/template~TemplateBinding#emitter}.
|
|
865
792
|
*
|
|
866
|
-
* @param
|
|
867
|
-
* @param
|
|
868
|
-
* @param
|
|
869
|
-
* @returns
|
|
793
|
+
* @param domEvtName The name of the native DOM event.
|
|
794
|
+
* @param domSelector The selector in the DOM to filter delegated events.
|
|
795
|
+
* @param data Rendering data.
|
|
796
|
+
* @returns A function to sever the listener binding.
|
|
870
797
|
*/
|
|
871
798
|
activateDomEventListener(domEvtName, domSelector, data) {
|
|
872
799
|
const callback = (evt, domEvt) => {
|
|
@@ -890,7 +817,6 @@ export class TemplateToBinding extends TemplateBinding {
|
|
|
890
817
|
* Describes a binding to {@link module:utils/observablemixin~ObservableMixin} created by the {@link module:ui/template~BindChain#if}
|
|
891
818
|
* method.
|
|
892
819
|
*
|
|
893
|
-
* @protected
|
|
894
820
|
* @internal
|
|
895
821
|
*/
|
|
896
822
|
export class TemplateIfBinding extends TemplateBinding {
|
|
@@ -906,11 +832,10 @@ export class TemplateIfBinding extends TemplateBinding {
|
|
|
906
832
|
return isFalsy(value) ? false : (this.valueIfTrue || true);
|
|
907
833
|
}
|
|
908
834
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
// @returns {Boolean}
|
|
835
|
+
/**
|
|
836
|
+
* Checks whether given {@link module:ui/template~TemplateValueSchema} contains a
|
|
837
|
+
* {@link module:ui/template~TemplateBinding}.
|
|
838
|
+
*/
|
|
914
839
|
function hasTemplateBinding(schema) {
|
|
915
840
|
if (!schema) {
|
|
916
841
|
return false;
|
|
@@ -933,13 +858,13 @@ function hasTemplateBinding(schema) {
|
|
|
933
858
|
}
|
|
934
859
|
return false;
|
|
935
860
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
861
|
+
/**
|
|
862
|
+
* Assembles the value using {@link module:ui/template~TemplateValueSchema} and stores it in a form of
|
|
863
|
+
* an Array. Each entry of the Array corresponds to one of {@link module:ui/template~TemplateValueSchema}
|
|
864
|
+
* items.
|
|
865
|
+
*
|
|
866
|
+
* @param node DOM Node updated when {@link module:utils/observablemixin~ObservableMixin} changes.
|
|
867
|
+
*/
|
|
943
868
|
function getValueSchemaValue(schema, node) {
|
|
944
869
|
return schema.map(schemaItem => {
|
|
945
870
|
// Process {@link module:ui/template~TemplateBinding} bindings.
|
|
@@ -950,12 +875,13 @@ function getValueSchemaValue(schema, node) {
|
|
|
950
875
|
return schemaItem;
|
|
951
876
|
});
|
|
952
877
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
878
|
+
/**
|
|
879
|
+
* A function executed each time the bound Observable attribute changes, which updates the DOM with a value
|
|
880
|
+
* constructed from {@link module:ui/template~TemplateValueSchema}.
|
|
881
|
+
*
|
|
882
|
+
* @param updater A function which updates the DOM (like attribute or text).
|
|
883
|
+
* @param node DOM Node updated when {@link module:utils/observablemixin~ObservableMixin} changes.
|
|
884
|
+
*/
|
|
959
885
|
function syncValueSchemaValue(schema, updater, { node }) {
|
|
960
886
|
const values = getValueSchemaValue(schema, node);
|
|
961
887
|
let value;
|
|
@@ -976,12 +902,13 @@ function syncValueSchemaValue(schema, updater, { node }) {
|
|
|
976
902
|
updater.set(value);
|
|
977
903
|
}
|
|
978
904
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
905
|
+
/**
|
|
906
|
+
* Returns an object consisting of `set` and `remove` functions, which
|
|
907
|
+
* can be used in the context of DOM Node to set or reset `textContent`.
|
|
908
|
+
* @see module:ui/view~View#_bindToObservable
|
|
909
|
+
*
|
|
910
|
+
* @param node DOM Node to be modified.
|
|
911
|
+
*/
|
|
985
912
|
function getTextUpdater(node) {
|
|
986
913
|
return {
|
|
987
914
|
set(value) {
|
|
@@ -992,14 +919,15 @@ function getTextUpdater(node) {
|
|
|
992
919
|
}
|
|
993
920
|
};
|
|
994
921
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
922
|
+
/**
|
|
923
|
+
* Returns an object consisting of `set` and `remove` functions, which
|
|
924
|
+
* can be used in the context of DOM Node to set or reset an attribute.
|
|
925
|
+
* @see module:ui/view~View#_bindToObservable
|
|
926
|
+
*
|
|
927
|
+
* @param el DOM Node to be modified.
|
|
928
|
+
* @param attrName Name of the attribute to be modified.
|
|
929
|
+
* @param ns Namespace to use.
|
|
930
|
+
*/
|
|
1003
931
|
function getAttributeUpdater(el, attrName, ns) {
|
|
1004
932
|
return {
|
|
1005
933
|
set(value) {
|
|
@@ -1010,13 +938,14 @@ function getAttributeUpdater(el, attrName, ns) {
|
|
|
1010
938
|
}
|
|
1011
939
|
};
|
|
1012
940
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
941
|
+
/**
|
|
942
|
+
* Returns an object consisting of `set` and `remove` functions, which
|
|
943
|
+
* can be used in the context of CSSStyleDeclaration to set or remove a style.
|
|
944
|
+
* @see module:ui/view~View#_bindToObservable
|
|
945
|
+
*
|
|
946
|
+
* @param el DOM Node to be modified.
|
|
947
|
+
* @param styleName Name of the style to be modified.
|
|
948
|
+
*/
|
|
1020
949
|
function getStyleUpdater(el, styleName) {
|
|
1021
950
|
return {
|
|
1022
951
|
set(value) {
|
|
@@ -1027,10 +956,9 @@ function getStyleUpdater(el, styleName) {
|
|
|
1027
956
|
}
|
|
1028
957
|
};
|
|
1029
958
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
// @returns {module:ui/template~TemplateDefinition}
|
|
959
|
+
/**
|
|
960
|
+
* Clones definition of the template.
|
|
961
|
+
*/
|
|
1034
962
|
function clone(def) {
|
|
1035
963
|
const clone = cloneDeepWith(def, value => {
|
|
1036
964
|
// Don't clone the `Template.bind`* bindings because of the references to Observable
|
|
@@ -1050,16 +978,18 @@ function clone(def) {
|
|
|
1050
978
|
});
|
|
1051
979
|
return clone;
|
|
1052
980
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
981
|
+
/**
|
|
982
|
+
* Normalizes given {@link module:ui/template~TemplateDefinition}.
|
|
983
|
+
*
|
|
984
|
+
* See:
|
|
985
|
+
* * {@link normalizeAttributes}
|
|
986
|
+
* * {@link normalizeListeners}
|
|
987
|
+
* * {@link normalizePlainTextDefinition}
|
|
988
|
+
* * {@link normalizeTextDefinition}
|
|
989
|
+
*
|
|
990
|
+
* @param def A template definition.
|
|
991
|
+
* @returns Normalized definition.
|
|
992
|
+
*/
|
|
1063
993
|
function normalize(def) {
|
|
1064
994
|
if (typeof def == 'string') {
|
|
1065
995
|
def = normalizePlainTextDefinition(def);
|
|
@@ -1096,27 +1026,31 @@ function normalize(def) {
|
|
|
1096
1026
|
}
|
|
1097
1027
|
return def;
|
|
1098
1028
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1029
|
+
/**
|
|
1030
|
+
* Normalizes "attributes" section of {@link module:ui/template~TemplateDefinition}.
|
|
1031
|
+
*
|
|
1032
|
+
* ```
|
|
1033
|
+
* attributes: {
|
|
1034
|
+
* a: 'bar',
|
|
1035
|
+
* b: {@link module:ui/template~TemplateBinding},
|
|
1036
|
+
* c: {
|
|
1037
|
+
* value: 'bar'
|
|
1038
|
+
* }
|
|
1039
|
+
* }
|
|
1040
|
+
* ```
|
|
1041
|
+
*
|
|
1042
|
+
* becomes
|
|
1043
|
+
*
|
|
1044
|
+
* ```
|
|
1045
|
+
* attributes: {
|
|
1046
|
+
* a: [ 'bar' ],
|
|
1047
|
+
* b: [ {@link module:ui/template~TemplateBinding} ],
|
|
1048
|
+
* c: {
|
|
1049
|
+
* value: [ 'bar' ]
|
|
1050
|
+
* }
|
|
1051
|
+
* }
|
|
1052
|
+
* ```
|
|
1053
|
+
*/
|
|
1120
1054
|
function normalizeAttributes(attributes) {
|
|
1121
1055
|
for (const a in attributes) {
|
|
1122
1056
|
if (attributes[a].value) {
|
|
@@ -1125,88 +1059,103 @@ function normalizeAttributes(attributes) {
|
|
|
1125
1059
|
arrayify(attributes, a);
|
|
1126
1060
|
}
|
|
1127
1061
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1062
|
+
/**
|
|
1063
|
+
* Normalizes "on" section of {@link module:ui/template~TemplateDefinition}.
|
|
1064
|
+
*
|
|
1065
|
+
* ```
|
|
1066
|
+
* on: {
|
|
1067
|
+
* a: 'bar',
|
|
1068
|
+
* b: {@link module:ui/template~TemplateBinding},
|
|
1069
|
+
* c: [ {@link module:ui/template~TemplateBinding}, () => { ... } ]
|
|
1070
|
+
* }
|
|
1071
|
+
* ```
|
|
1072
|
+
*
|
|
1073
|
+
* becomes
|
|
1074
|
+
*
|
|
1075
|
+
* ```
|
|
1076
|
+
* on: {
|
|
1077
|
+
* a: [ 'bar' ],
|
|
1078
|
+
* b: [ {@link module:ui/template~TemplateBinding} ],
|
|
1079
|
+
* c: [ {@link module:ui/template~TemplateBinding}, () => { ... } ]
|
|
1080
|
+
* }
|
|
1081
|
+
* ```
|
|
1082
|
+
*
|
|
1083
|
+
* @returns Object containing normalized listeners.
|
|
1084
|
+
*/
|
|
1146
1085
|
function normalizeListeners(listeners) {
|
|
1147
1086
|
for (const l in listeners) {
|
|
1148
1087
|
arrayify(listeners, l);
|
|
1149
1088
|
}
|
|
1150
1089
|
return listeners;
|
|
1151
1090
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1091
|
+
/**
|
|
1092
|
+
* Normalizes "string" {@link module:ui/template~TemplateDefinition}.
|
|
1093
|
+
*
|
|
1094
|
+
* ```
|
|
1095
|
+
* "foo"
|
|
1096
|
+
* ```
|
|
1097
|
+
*
|
|
1098
|
+
* becomes
|
|
1099
|
+
*
|
|
1100
|
+
* ```
|
|
1101
|
+
* { text: [ 'foo' ] },
|
|
1102
|
+
* ```
|
|
1103
|
+
*
|
|
1104
|
+
* @returns Normalized template definition.
|
|
1105
|
+
*/
|
|
1162
1106
|
function normalizePlainTextDefinition(def) {
|
|
1163
1107
|
return {
|
|
1164
1108
|
text: [def]
|
|
1165
1109
|
};
|
|
1166
1110
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1111
|
+
/**
|
|
1112
|
+
* Normalizes text {@link module:ui/template~TemplateDefinition}.
|
|
1113
|
+
*
|
|
1114
|
+
* ```
|
|
1115
|
+
* children: [
|
|
1116
|
+
* { text: 'def' },
|
|
1117
|
+
* { text: {@link module:ui/template~TemplateBinding} }
|
|
1118
|
+
* ]
|
|
1119
|
+
* ```
|
|
1120
|
+
*
|
|
1121
|
+
* becomes
|
|
1122
|
+
*
|
|
1123
|
+
* ```
|
|
1124
|
+
* children: [
|
|
1125
|
+
* { text: [ 'def' ] },
|
|
1126
|
+
* { text: [ {@link module:ui/template~TemplateBinding} ] }
|
|
1127
|
+
* ]
|
|
1128
|
+
* ```
|
|
1129
|
+
*/
|
|
1182
1130
|
function normalizeTextDefinition(def) {
|
|
1183
1131
|
def.text = toArray(def.text);
|
|
1184
1132
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1133
|
+
/**
|
|
1134
|
+
* Wraps an entry in Object in an Array, if not already one.
|
|
1135
|
+
*
|
|
1136
|
+
* ```
|
|
1137
|
+
* {
|
|
1138
|
+
* x: 'y',
|
|
1139
|
+
* a: [ 'b' ]
|
|
1140
|
+
* }
|
|
1141
|
+
* ```
|
|
1142
|
+
*
|
|
1143
|
+
* becomes
|
|
1144
|
+
*
|
|
1145
|
+
* ```
|
|
1146
|
+
* {
|
|
1147
|
+
* x: [ 'y' ],
|
|
1148
|
+
* a: [ 'b' ]
|
|
1149
|
+
* }
|
|
1150
|
+
* ```
|
|
1151
|
+
*/
|
|
1201
1152
|
function arrayify(obj, key) {
|
|
1202
1153
|
obj[key] = toArray(obj[key]);
|
|
1203
1154
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
// @param {String} cur
|
|
1209
|
-
// @returns {String}
|
|
1155
|
+
/**
|
|
1156
|
+
* A helper which concatenates the value avoiding unwanted
|
|
1157
|
+
* leading white spaces.
|
|
1158
|
+
*/
|
|
1210
1159
|
function arrayValueReducer(prev, cur) {
|
|
1211
1160
|
if (isFalsy(cur)) {
|
|
1212
1161
|
return prev;
|
|
@@ -1218,20 +1167,23 @@ function arrayValueReducer(prev, cur) {
|
|
|
1218
1167
|
return `${prev} ${cur}`;
|
|
1219
1168
|
}
|
|
1220
1169
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1170
|
+
/**
|
|
1171
|
+
* Extends one object defined in the following format:
|
|
1172
|
+
*
|
|
1173
|
+
* ```
|
|
1174
|
+
* {
|
|
1175
|
+
* key1: [Array1],
|
|
1176
|
+
* key2: [Array2],
|
|
1177
|
+
* ...
|
|
1178
|
+
* keyN: [ArrayN]
|
|
1179
|
+
* }
|
|
1180
|
+
* ```
|
|
1181
|
+
*
|
|
1182
|
+
* with another object of the same data format.
|
|
1183
|
+
*
|
|
1184
|
+
* @param obj Base object.
|
|
1185
|
+
* @param ext Object extending base.
|
|
1186
|
+
*/
|
|
1235
1187
|
function extendObjectValueArray(obj, ext) {
|
|
1236
1188
|
for (const a in ext) {
|
|
1237
1189
|
if (obj[a]) {
|
|
@@ -1242,12 +1194,14 @@ function extendObjectValueArray(obj, ext) {
|
|
|
1242
1194
|
}
|
|
1243
1195
|
}
|
|
1244
1196
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1197
|
+
/**
|
|
1198
|
+
* A helper for {@link module:ui/template~Template#extend}. Recursively extends {@link module:ui/template~Template} instance
|
|
1199
|
+
* with content from {@link module:ui/template~TemplateDefinition}. See {@link module:ui/template~Template#extend} to learn more.
|
|
1200
|
+
*
|
|
1201
|
+
* @param def A template instance to be extended.
|
|
1202
|
+
* @param def A definition which is to extend the template instance.
|
|
1203
|
+
* @param Error context.
|
|
1204
|
+
*/
|
|
1251
1205
|
function extendTemplate(template, def) {
|
|
1252
1206
|
if (def.attributes) {
|
|
1253
1207
|
if (!template.attributes) {
|
|
@@ -1279,43 +1233,49 @@ function extendTemplate(template, def) {
|
|
|
1279
1233
|
}
|
|
1280
1234
|
}
|
|
1281
1235
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1236
|
+
/**
|
|
1237
|
+
* Checks if value is "falsy".
|
|
1238
|
+
* Note: 0 (Number) is not "falsy" in this context.
|
|
1239
|
+
*
|
|
1240
|
+
* @param value Value to be checked.
|
|
1241
|
+
*/
|
|
1287
1242
|
function isFalsy(value) {
|
|
1288
1243
|
return !value && value !== 0;
|
|
1289
1244
|
}
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1245
|
+
/**
|
|
1246
|
+
* Checks if the item is an instance of {@link module:ui/view~View}
|
|
1247
|
+
*
|
|
1248
|
+
* @param value Value to be checked.
|
|
1249
|
+
*/
|
|
1294
1250
|
function isView(item) {
|
|
1295
1251
|
return item instanceof View;
|
|
1296
1252
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1253
|
+
/**
|
|
1254
|
+
* Checks if the item is an instance of {@link module:ui/template~Template}
|
|
1255
|
+
*
|
|
1256
|
+
* @param value Value to be checked.
|
|
1257
|
+
*/
|
|
1301
1258
|
function isTemplate(item) {
|
|
1302
1259
|
return item instanceof Template;
|
|
1303
1260
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1261
|
+
/**
|
|
1262
|
+
* Checks if the item is an instance of {@link module:ui/viewcollection~ViewCollection}
|
|
1263
|
+
*
|
|
1264
|
+
* @param value Value to be checked.
|
|
1265
|
+
*/
|
|
1308
1266
|
function isViewCollection(item) {
|
|
1309
1267
|
return item instanceof ViewCollection;
|
|
1310
1268
|
}
|
|
1311
|
-
|
|
1269
|
+
/**
|
|
1270
|
+
* Checks if value array contains the one with namespace.
|
|
1271
|
+
*/
|
|
1312
1272
|
function isNamespaced(attrValue) {
|
|
1313
1273
|
return isObject(attrValue[0]) && attrValue[0].ns;
|
|
1314
1274
|
}
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1275
|
+
/**
|
|
1276
|
+
* Creates an empty skeleton for {@link module:ui/template~Template#revert}
|
|
1277
|
+
* data.
|
|
1278
|
+
*/
|
|
1319
1279
|
function getEmptyRevertData() {
|
|
1320
1280
|
return {
|
|
1321
1281
|
children: [],
|
|
@@ -1323,36 +1283,12 @@ function getEmptyRevertData() {
|
|
|
1323
1283
|
attributes: {}
|
|
1324
1284
|
};
|
|
1325
1285
|
}
|
|
1326
|
-
// Checks whether an attribute should be extended when
|
|
1327
|
-
// {@link module:ui/template~Template#apply} is called.
|
|
1328
|
-
//
|
|
1329
|
-
// @private
|
|
1330
|
-
// @param {String} attrName Attribute name to check.
|
|
1331
|
-
function shouldExtend(attrName) {
|
|
1332
|
-
return attrName == 'class' || attrName == 'style';
|
|
1333
|
-
}
|
|
1334
1286
|
/**
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1337
|
-
* to the parent element. It is a speed optimization.
|
|
1287
|
+
* Checks whether an attribute should be extended when
|
|
1288
|
+
* {@link module:ui/template~Template#apply} is called.
|
|
1338
1289
|
*
|
|
1339
|
-
* @
|
|
1340
|
-
*/
|
|
1341
|
-
/**
|
|
1342
|
-
* A node which is being rendered.
|
|
1343
|
-
*
|
|
1344
|
-
* @member {HTMLElement|Text} #node
|
|
1345
|
-
*/
|
|
1346
|
-
/**
|
|
1347
|
-
* Indicates whether the {@module:ui/template~RenderNodeOptions#node} has
|
|
1348
|
-
* been provided by {@module:ui/template~Template#apply}.
|
|
1349
|
-
*
|
|
1350
|
-
* @member {Boolean} #isApplying
|
|
1351
|
-
*/
|
|
1352
|
-
/**
|
|
1353
|
-
* An object storing the data that helps {@module:ui/template~Template#revert}
|
|
1354
|
-
* bringing back an element to its initial state, i.e. before
|
|
1355
|
-
* {@module:ui/template~Template#apply} was called.
|
|
1356
|
-
*
|
|
1357
|
-
* @member {Object} #revertData
|
|
1290
|
+
* @param attrName Attribute name to check.
|
|
1358
1291
|
*/
|
|
1292
|
+
function shouldExtend(attrName) {
|
|
1293
|
+
return attrName == 'class' || attrName == 'style';
|
|
1294
|
+
}
|