maquette 3.5.3 → 4.0.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/dist/cache.d.ts +9 -9
- package/dist/cache.js +31 -31
- package/dist/cache.js.map +1 -1
- package/dist/dom.d.ts +59 -59
- package/dist/dom.js +95 -95
- package/dist/dom.js.map +1 -1
- package/dist/h.d.ts +34 -34
- package/dist/h.js +55 -55
- package/dist/h.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +12 -12
- package/dist/interfaces.d.ts +474 -441
- package/dist/interfaces.js +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/mapping.d.ts +13 -13
- package/dist/mapping.js +50 -50
- package/dist/mapping.js.map +1 -1
- package/dist/maquette.cjs.js +914 -896
- package/dist/maquette.umd.js +914 -896
- package/dist/maquette.umd.min.js +1 -1
- package/dist/projection.d.ts +8 -8
- package/dist/projection.js +557 -539
- package/dist/projection.js.map +1 -1
- package/dist/projector.d.ts +26 -26
- package/dist/projector.js +134 -132
- package/dist/projector.js.map +1 -1
- package/dist/utilities/window-performance-projector-logger.d.ts +7 -7
- package/dist/utilities/window-performance-projector-logger.js +31 -31
- package/dist/utilities/window-performance-projector-logger.js.map +1 -1
- package/package.json +13 -12
package/dist/maquette.cjs.js
CHANGED
|
@@ -1,911 +1,929 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
var
|
|
137
|
-
var
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
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
|
-
vnode.
|
|
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
|
-
if (
|
|
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
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
vnode
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
if (
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
if (
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
vnode.
|
|
522
|
-
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
3
|
+
var NAMESPACE_W3 = "http://www.w3.org/";
|
|
4
|
+
var NAMESPACE_SVG = "".concat(NAMESPACE_W3, "2000/svg");
|
|
5
|
+
var NAMESPACE_XLINK = "".concat(NAMESPACE_W3, "1999/xlink");
|
|
6
|
+
var emptyArray = [];
|
|
7
|
+
var extend = function (base, overrides) {
|
|
8
|
+
var result = {};
|
|
9
|
+
Object.keys(base).forEach(function (key) {
|
|
10
|
+
result[key] = base[key];
|
|
11
|
+
});
|
|
12
|
+
if (overrides) {
|
|
13
|
+
Object.keys(overrides).forEach(function (key) {
|
|
14
|
+
result[key] = overrides[key];
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
var same = function (vnode1, vnode2) {
|
|
20
|
+
if (vnode1.vnodeSelector !== vnode2.vnodeSelector) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (vnode1.properties && vnode2.properties) {
|
|
24
|
+
if (vnode1.properties.key !== vnode2.properties.key) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return vnode1.properties.bind === vnode2.properties.bind;
|
|
28
|
+
}
|
|
29
|
+
return !vnode1.properties && !vnode2.properties;
|
|
30
|
+
};
|
|
31
|
+
var checkStyleValue = function (styleValue) {
|
|
32
|
+
if (typeof styleValue !== "string") {
|
|
33
|
+
throw new Error("Style values must be strings");
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var findIndexOfChild = function (children, sameAs, start) {
|
|
37
|
+
if (sameAs.vnodeSelector !== "") {
|
|
38
|
+
// Never scan for text-nodes
|
|
39
|
+
for (var i = start; i < children.length; i++) {
|
|
40
|
+
if (same(children[i], sameAs)) {
|
|
41
|
+
return i;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return -1;
|
|
46
|
+
};
|
|
47
|
+
var checkDistinguishable = function (childNodes, indexToCheck, parentVNode, operation) {
|
|
48
|
+
var childNode = childNodes[indexToCheck];
|
|
49
|
+
if (childNode.vnodeSelector === "") {
|
|
50
|
+
return; // Text nodes need not be distinguishable
|
|
51
|
+
}
|
|
52
|
+
var properties = childNode.properties;
|
|
53
|
+
var key = properties
|
|
54
|
+
? properties.key === undefined
|
|
55
|
+
? properties.bind
|
|
56
|
+
: properties.key
|
|
57
|
+
: undefined;
|
|
58
|
+
if (!key) {
|
|
59
|
+
// A key is just assumed to be unique
|
|
60
|
+
for (var i = 0; i < childNodes.length; i++) {
|
|
61
|
+
if (i !== indexToCheck) {
|
|
62
|
+
var node = childNodes[i];
|
|
63
|
+
if (same(node, childNode)) {
|
|
64
|
+
throw {
|
|
65
|
+
error: new Error("".concat(parentVNode.vnodeSelector, " had a ").concat(childNode.vnodeSelector, " child ").concat(operation === "added" ? operation : "removed", ", but there is now more than one. You must add unique key properties to make them distinguishable.")),
|
|
66
|
+
parentNode: parentVNode,
|
|
67
|
+
childNode: childNode,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var nodeAdded = function (vNode) {
|
|
75
|
+
if (vNode.properties) {
|
|
76
|
+
var enterAnimation = vNode.properties.enterAnimation;
|
|
77
|
+
if (enterAnimation) {
|
|
78
|
+
enterAnimation(vNode.domNode, vNode.properties);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var removedNodes = [];
|
|
83
|
+
var requestedIdleCallback = false;
|
|
84
|
+
var visitRemovedNode = function (node) {
|
|
85
|
+
(node.children || []).forEach(visitRemovedNode);
|
|
86
|
+
if (node.properties && node.properties.afterRemoved) {
|
|
87
|
+
node.properties.afterRemoved.apply(node.properties.bind || node.properties, [
|
|
88
|
+
node.domNode,
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var processPendingNodeRemovals = function () {
|
|
93
|
+
requestedIdleCallback = false;
|
|
94
|
+
removedNodes.forEach(visitRemovedNode);
|
|
95
|
+
removedNodes.length = 0;
|
|
96
|
+
};
|
|
97
|
+
var scheduleNodeRemoval = function (vNode) {
|
|
98
|
+
removedNodes.push(vNode);
|
|
99
|
+
if (!requestedIdleCallback) {
|
|
100
|
+
requestedIdleCallback = true;
|
|
101
|
+
if (typeof window !== "undefined" && "requestIdleCallback" in window) {
|
|
102
|
+
window.requestIdleCallback(processPendingNodeRemovals, { timeout: 16 });
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
setTimeout(processPendingNodeRemovals, 16);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var nodeToRemove = function (vNode) {
|
|
110
|
+
var domNode = vNode.domNode;
|
|
111
|
+
if (vNode.properties) {
|
|
112
|
+
var exitAnimation = vNode.properties.exitAnimation;
|
|
113
|
+
if (exitAnimation) {
|
|
114
|
+
domNode.style.pointerEvents = "none";
|
|
115
|
+
var removeDomNode = function () {
|
|
116
|
+
if (domNode.parentNode) {
|
|
117
|
+
domNode.parentNode.removeChild(domNode);
|
|
118
|
+
scheduleNodeRemoval(vNode);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
exitAnimation(domNode, removeDomNode, vNode.properties);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (domNode.parentNode) {
|
|
126
|
+
domNode.parentNode.removeChild(domNode);
|
|
127
|
+
scheduleNodeRemoval(vNode);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var setProperties = function (domNode, properties, projectionOptions) {
|
|
131
|
+
if (!properties) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
var eventHandlerInterceptor = projectionOptions.eventHandlerInterceptor;
|
|
135
|
+
var propNames = Object.keys(properties);
|
|
136
|
+
var propCount = propNames.length;
|
|
137
|
+
var _loop_1 = function (i) {
|
|
138
|
+
var propName = propNames[i];
|
|
139
|
+
var propValue = properties[propName];
|
|
140
|
+
if (propName === "className") {
|
|
141
|
+
throw new Error('Property "className" is not supported, use "class".');
|
|
142
|
+
}
|
|
143
|
+
else if (propName === "class") {
|
|
144
|
+
toggleClasses(domNode, propValue, true);
|
|
145
|
+
}
|
|
146
|
+
else if (propName === "classes") {
|
|
147
|
+
// object with string keys and boolean values
|
|
148
|
+
var classNames = Object.keys(propValue);
|
|
149
|
+
var classNameCount = classNames.length;
|
|
150
|
+
for (var j = 0; j < classNameCount; j++) {
|
|
151
|
+
var className = classNames[j];
|
|
152
|
+
if (propValue[className]) {
|
|
153
|
+
domNode.classList.add(className);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (propName === "styles") {
|
|
158
|
+
// object with string keys and string (!) values
|
|
159
|
+
var styleNames = Object.keys(propValue);
|
|
160
|
+
var styleCount = styleNames.length;
|
|
161
|
+
for (var j = 0; j < styleCount; j++) {
|
|
162
|
+
var styleName = styleNames[j];
|
|
163
|
+
var styleValue = propValue[styleName];
|
|
164
|
+
if (styleValue) {
|
|
165
|
+
checkStyleValue(styleValue);
|
|
166
|
+
projectionOptions.styleApplyer(domNode, styleName, styleValue);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (propName === "on" && propValue) {
|
|
171
|
+
// object with string keys and function values
|
|
172
|
+
for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
|
|
173
|
+
var _b = _a[_i], key = _b[0], handler = _b[1];
|
|
174
|
+
var listener = typeof handler === "function" ? handler : handler.listener;
|
|
175
|
+
if (eventHandlerInterceptor) {
|
|
176
|
+
listener = eventHandlerInterceptor(key, listener, domNode, properties);
|
|
177
|
+
}
|
|
178
|
+
if (listener) {
|
|
179
|
+
domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else if (propName !== "key" && propValue !== null && propValue !== undefined) {
|
|
184
|
+
var type = typeof propValue;
|
|
185
|
+
if (type === "function") {
|
|
186
|
+
if (propName.lastIndexOf("on", 0) === 0) {
|
|
187
|
+
// lastIndexOf(,0)===0 -> startsWith
|
|
188
|
+
if (eventHandlerInterceptor) {
|
|
189
|
+
propValue = eventHandlerInterceptor(propName, propValue, domNode, properties); // intercept eventhandlers
|
|
190
|
+
}
|
|
191
|
+
if (propName === "oninput") {
|
|
192
|
+
(function () {
|
|
193
|
+
// record the evt.target.value, because IE and Edge sometimes do a requestAnimationFrame between changing value and running oninput
|
|
194
|
+
var oldPropValue = propValue;
|
|
195
|
+
propValue = function (evt) {
|
|
196
|
+
oldPropValue.apply(this, [evt]);
|
|
197
|
+
evt.target["oninput-value"] = evt.target.value; // may be HTMLTextAreaElement as well
|
|
198
|
+
};
|
|
199
|
+
})();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
domNode[propName] = propValue;
|
|
203
|
+
}
|
|
204
|
+
else if (projectionOptions.namespace === NAMESPACE_SVG) {
|
|
205
|
+
if (propName === "href") {
|
|
206
|
+
domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// all SVG attributes are read-only in DOM, so...
|
|
210
|
+
domNode.setAttribute(propName, propValue);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (type === "string" && propName !== "value" && propName !== "innerHTML") {
|
|
214
|
+
domNode.setAttribute(propName, propValue);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
domNode[propName] = propValue;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
for (var i = 0; i < propCount; i++) {
|
|
222
|
+
_loop_1(i);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
var addChildren = function (domNode, children, projectionOptions) {
|
|
226
|
+
if (!children) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
|
|
230
|
+
var child = children_1[_i];
|
|
231
|
+
createDom(child, domNode, undefined, projectionOptions);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var initPropertiesAndChildren = function (domNode, vnode, projectionOptions) {
|
|
235
|
+
addChildren(domNode, vnode.children, projectionOptions); // children before properties, needed for value property of <select>.
|
|
236
|
+
if (vnode.text) {
|
|
237
|
+
domNode.textContent = vnode.text;
|
|
238
|
+
}
|
|
239
|
+
setProperties(domNode, vnode.properties, projectionOptions);
|
|
240
|
+
if (vnode.properties && vnode.properties.afterCreate) {
|
|
241
|
+
vnode.properties.afterCreate.apply(vnode.properties.bind || vnode.properties, [
|
|
242
|
+
domNode,
|
|
243
|
+
projectionOptions,
|
|
244
|
+
vnode.vnodeSelector,
|
|
245
|
+
vnode.properties,
|
|
246
|
+
vnode.children,
|
|
247
|
+
]);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
var createDom = function (vnode, parentNode, insertBefore, projectionOptions) {
|
|
251
|
+
var _a;
|
|
252
|
+
var domNode;
|
|
253
|
+
var start = 0;
|
|
254
|
+
var vnodeSelector = vnode.vnodeSelector;
|
|
255
|
+
var doc = parentNode.ownerDocument;
|
|
256
|
+
if (vnodeSelector === "") {
|
|
257
|
+
if (vnode.domNode) {
|
|
258
|
+
vnode.domNode.nodeValue = vnode.text;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
domNode = vnode.domNode = doc.createTextNode(vnode.text);
|
|
262
|
+
if (insertBefore !== undefined) {
|
|
263
|
+
parentNode.insertBefore(domNode, insertBefore);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
parentNode.appendChild(domNode);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
for (var i = 0; i <= vnodeSelector.length; ++i) {
|
|
272
|
+
var c = vnodeSelector.charAt(i);
|
|
273
|
+
if (i === vnodeSelector.length || c === "." || c === "#") {
|
|
274
|
+
var type = vnodeSelector.charAt(start - 1);
|
|
275
|
+
var found = vnodeSelector.slice(start, i);
|
|
276
|
+
if (type === ".") {
|
|
277
|
+
domNode.classList.add(found);
|
|
278
|
+
}
|
|
279
|
+
else if (type === "#") {
|
|
280
|
+
domNode.id = found;
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
if (found === "svg") {
|
|
284
|
+
projectionOptions = extend(projectionOptions, {
|
|
285
|
+
namespace: NAMESPACE_SVG,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
if (projectionOptions.namespace !== undefined) {
|
|
289
|
+
domNode = vnode.domNode = doc.createElementNS(projectionOptions.namespace, found);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
domNode = vnode.domNode =
|
|
293
|
+
vnode.domNode ||
|
|
294
|
+
(((_a = vnode.properties) === null || _a === void 0 ? void 0 : _a.is)
|
|
295
|
+
? doc.createElement(found, { is: vnode.properties.is })
|
|
296
|
+
: doc.createElement(found));
|
|
297
|
+
if (found === "input" && vnode.properties && vnode.properties.type !== undefined) {
|
|
298
|
+
// IE8 and older don't support setting input type after the DOM Node has been added to the document
|
|
299
|
+
domNode.setAttribute("type", vnode.properties.type);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (insertBefore !== undefined) {
|
|
303
|
+
parentNode.insertBefore(domNode, insertBefore);
|
|
304
|
+
}
|
|
305
|
+
else if (domNode.parentNode !== parentNode) {
|
|
306
|
+
parentNode.appendChild(domNode);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
start = i + 1;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
initPropertiesAndChildren(domNode, vnode, projectionOptions);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var updateDom;
|
|
316
|
+
/**
|
|
317
|
+
* Adds or removes classes from an Element
|
|
318
|
+
* @param domNode the element
|
|
319
|
+
* @param classes a string separated list of classes
|
|
320
|
+
* @param on true means add classes, false means remove
|
|
321
|
+
*/
|
|
322
|
+
var toggleClasses = function (domNode, classes, on) {
|
|
323
|
+
if (!classes) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
classes.split(" ").forEach(function (classToToggle) {
|
|
327
|
+
if (classToToggle) {
|
|
328
|
+
domNode.classList.toggle(classToToggle, on);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
var updateProperties = function (domNode, previousProperties, properties, projectionOptions) {
|
|
333
|
+
if (!properties) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
var propertiesUpdated = false;
|
|
337
|
+
var propNames = Object.keys(properties);
|
|
338
|
+
var propCount = propNames.length;
|
|
339
|
+
for (var i = 0; i < propCount; i++) {
|
|
340
|
+
var propName = propNames[i];
|
|
341
|
+
// assuming that properties will be nullified instead of missing is by design
|
|
342
|
+
var propValue = properties[propName];
|
|
343
|
+
var previousValue = previousProperties[propName];
|
|
344
|
+
if (propName === "class") {
|
|
345
|
+
if (previousValue !== propValue) {
|
|
346
|
+
toggleClasses(domNode, previousValue, false);
|
|
347
|
+
toggleClasses(domNode, propValue, true);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else if (propName === "classes") {
|
|
351
|
+
var classList = domNode.classList;
|
|
352
|
+
var classNames = Object.keys(propValue);
|
|
353
|
+
var classNameCount = classNames.length;
|
|
354
|
+
for (var j = 0; j < classNameCount; j++) {
|
|
355
|
+
var className = classNames[j];
|
|
356
|
+
var on = !!propValue[className];
|
|
357
|
+
var previousOn = !!previousValue[className];
|
|
358
|
+
if (on === previousOn) {
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
propertiesUpdated = true;
|
|
362
|
+
if (on) {
|
|
363
|
+
classList.add(className);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
classList.remove(className);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else if (propName === "styles") {
|
|
371
|
+
var styleNames = Object.keys(propValue);
|
|
372
|
+
var styleCount = styleNames.length;
|
|
373
|
+
for (var j = 0; j < styleCount; j++) {
|
|
374
|
+
var styleName = styleNames[j];
|
|
375
|
+
var newStyleValue = propValue[styleName];
|
|
376
|
+
var oldStyleValue = previousValue[styleName];
|
|
377
|
+
if (newStyleValue === oldStyleValue) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
propertiesUpdated = true;
|
|
381
|
+
if (newStyleValue) {
|
|
382
|
+
checkStyleValue(newStyleValue);
|
|
383
|
+
projectionOptions.styleApplyer(domNode, styleName, newStyleValue);
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
projectionOptions.styleApplyer(domNode, styleName, "");
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
if (!propValue && typeof previousValue === "string") {
|
|
392
|
+
propValue = "";
|
|
393
|
+
}
|
|
394
|
+
if (propName === "value") {
|
|
395
|
+
// value can be manipulated by the user directly and using event.preventDefault() is not an option
|
|
396
|
+
var domValue = domNode[propName];
|
|
397
|
+
if (domValue !== propValue && // The 'value' in the DOM tree !== newValue
|
|
398
|
+
(domNode["oninput-value"]
|
|
399
|
+
? domValue === domNode["oninput-value"] // If the last reported value to 'oninput' does not match domValue, do nothing and wait for oninput
|
|
400
|
+
: propValue !== previousValue) // Only update the value if the vdom changed
|
|
401
|
+
) {
|
|
402
|
+
// The edge cases are described in the tests
|
|
403
|
+
domNode[propName] = propValue; // Reset the value, even if the virtual DOM did not change
|
|
404
|
+
domNode["oninput-value"] = undefined;
|
|
405
|
+
} // else do not update the domNode, otherwise the cursor position would be changed
|
|
406
|
+
if (propValue !== previousValue) {
|
|
407
|
+
propertiesUpdated = true;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
else if (propValue !== previousValue) {
|
|
411
|
+
var type = typeof propValue;
|
|
412
|
+
if (type !== "function" || !projectionOptions.eventHandlerInterceptor) {
|
|
413
|
+
// Function updates are expected to be handled by the EventHandlerInterceptor
|
|
414
|
+
if (projectionOptions.namespace === NAMESPACE_SVG) {
|
|
415
|
+
if (propName === "href") {
|
|
416
|
+
domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
// all SVG attributes are read-only in DOM, so...
|
|
420
|
+
domNode.setAttribute(propName, propValue);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
else if (type === "string" && propName !== "innerHTML") {
|
|
424
|
+
if (propName === "role" && propValue === "") {
|
|
425
|
+
domNode.removeAttribute(propName);
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
domNode.setAttribute(propName, propValue);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else if (domNode[propName] !== propValue) {
|
|
432
|
+
// Comparison is here for side-effects in Edge with scrollLeft and scrollTop
|
|
433
|
+
domNode[propName] = propValue;
|
|
434
|
+
}
|
|
435
|
+
propertiesUpdated = true;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return propertiesUpdated;
|
|
441
|
+
};
|
|
442
|
+
var updateChildren = function (vnode, domNode, oldChildren, newChildren, projectionOptions) {
|
|
443
|
+
if (oldChildren === newChildren) {
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
oldChildren = oldChildren || emptyArray;
|
|
447
|
+
newChildren = newChildren || emptyArray;
|
|
448
|
+
var oldChildrenLength = oldChildren.length;
|
|
449
|
+
var newChildrenLength = newChildren.length;
|
|
450
|
+
var oldIndex = 0;
|
|
451
|
+
var newIndex = 0;
|
|
452
|
+
var i;
|
|
453
|
+
var textUpdated = false;
|
|
454
|
+
while (newIndex < newChildrenLength) {
|
|
455
|
+
var oldChild = oldIndex < oldChildrenLength ? oldChildren[oldIndex] : undefined;
|
|
456
|
+
var newChild = newChildren[newIndex];
|
|
457
|
+
if (oldChild !== undefined && same(oldChild, newChild)) {
|
|
458
|
+
textUpdated = updateDom(oldChild, newChild, projectionOptions) || textUpdated;
|
|
459
|
+
oldIndex++;
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
var findOldIndex = findIndexOfChild(oldChildren, newChild, oldIndex + 1);
|
|
463
|
+
if (findOldIndex >= 0) {
|
|
464
|
+
// Remove preceding missing children
|
|
465
|
+
for (i = oldIndex; i < findOldIndex; i++) {
|
|
466
|
+
nodeToRemove(oldChildren[i]);
|
|
467
|
+
checkDistinguishable(oldChildren, i, vnode, "removed");
|
|
468
|
+
}
|
|
469
|
+
textUpdated =
|
|
470
|
+
updateDom(oldChildren[findOldIndex], newChild, projectionOptions) || textUpdated;
|
|
471
|
+
oldIndex = findOldIndex + 1;
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
// New child
|
|
475
|
+
createDom(newChild, domNode, oldIndex < oldChildrenLength ? oldChildren[oldIndex].domNode : undefined, projectionOptions);
|
|
476
|
+
nodeAdded(newChild);
|
|
477
|
+
checkDistinguishable(newChildren, newIndex, vnode, "added");
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
newIndex++;
|
|
481
|
+
}
|
|
482
|
+
if (oldChildrenLength > oldIndex) {
|
|
483
|
+
// Remove child fragments
|
|
484
|
+
for (i = oldIndex; i < oldChildrenLength; i++) {
|
|
485
|
+
nodeToRemove(oldChildren[i]);
|
|
486
|
+
checkDistinguishable(oldChildren, i, vnode, "removed");
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return textUpdated;
|
|
490
|
+
};
|
|
491
|
+
updateDom = function (previous, vnode, projectionOptions) {
|
|
492
|
+
var domNode = previous.domNode;
|
|
493
|
+
var textUpdated = false;
|
|
494
|
+
if (previous === vnode) {
|
|
495
|
+
return false; // By contract, VNode objects may not be modified anymore after passing them to maquette
|
|
496
|
+
}
|
|
497
|
+
var updated = false;
|
|
498
|
+
if (vnode.vnodeSelector === "") {
|
|
499
|
+
if (vnode.text !== previous.text) {
|
|
500
|
+
var newTextNode = domNode.ownerDocument.createTextNode(vnode.text);
|
|
501
|
+
domNode.parentNode.replaceChild(newTextNode, domNode);
|
|
502
|
+
vnode.domNode = newTextNode;
|
|
503
|
+
textUpdated = true;
|
|
504
|
+
return textUpdated;
|
|
505
|
+
}
|
|
506
|
+
vnode.domNode = domNode;
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
if (vnode.vnodeSelector.lastIndexOf("svg", 0) === 0) {
|
|
510
|
+
// lastIndexOf(needle,0)===0 means StartsWith
|
|
511
|
+
projectionOptions = extend(projectionOptions, {
|
|
512
|
+
namespace: NAMESPACE_SVG,
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
if (previous.text !== vnode.text) {
|
|
516
|
+
updated = true;
|
|
517
|
+
if (vnode.text === undefined) {
|
|
518
|
+
domNode.removeChild(domNode.firstChild); // the only textnode presumably
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
domNode.textContent = vnode.text;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
vnode.domNode = domNode;
|
|
525
|
+
updated =
|
|
526
|
+
updateChildren(vnode, domNode, previous.children, vnode.children, projectionOptions) ||
|
|
527
|
+
updated;
|
|
528
|
+
updated =
|
|
529
|
+
updateProperties(domNode, previous.properties, vnode.properties, projectionOptions) ||
|
|
530
|
+
updated;
|
|
531
|
+
if (vnode.properties && vnode.properties.afterUpdate) {
|
|
532
|
+
vnode.properties.afterUpdate.apply(vnode.properties.bind || vnode.properties, [
|
|
533
|
+
domNode,
|
|
534
|
+
projectionOptions,
|
|
535
|
+
vnode.vnodeSelector,
|
|
536
|
+
vnode.properties,
|
|
537
|
+
vnode.children,
|
|
538
|
+
]);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (updated && vnode.properties && vnode.properties.updateAnimation) {
|
|
542
|
+
vnode.properties.updateAnimation(domNode, vnode.properties, previous.properties);
|
|
543
|
+
}
|
|
544
|
+
return textUpdated;
|
|
545
|
+
};
|
|
546
|
+
var createProjection = function (vnode, projectionOptions) {
|
|
547
|
+
return {
|
|
548
|
+
getLastRender: function () { return vnode; },
|
|
549
|
+
update: function (updatedVnode) {
|
|
550
|
+
if (vnode.vnodeSelector !== updatedVnode.vnodeSelector) {
|
|
551
|
+
throw new Error("The selector for the root VNode may not be changed. (consider using dom.merge and add one extra level to the virtual DOM)");
|
|
552
|
+
}
|
|
553
|
+
var previousVNode = vnode;
|
|
554
|
+
vnode = updatedVnode;
|
|
555
|
+
updateDom(previousVNode, updatedVnode, projectionOptions);
|
|
556
|
+
},
|
|
557
|
+
domNode: vnode.domNode,
|
|
558
|
+
};
|
|
543
559
|
};
|
|
544
560
|
|
|
545
|
-
var DEFAULT_PROJECTION_OPTIONS = {
|
|
546
|
-
namespace: undefined,
|
|
547
|
-
performanceLogger: function () { return undefined; },
|
|
548
|
-
eventHandlerInterceptor: undefined,
|
|
549
|
-
styleApplyer: function (domNode, styleName, value) {
|
|
550
|
-
if (styleName.charAt(0) === "-") {
|
|
551
|
-
// CSS variables must be set using setProperty
|
|
552
|
-
domNode.style.setProperty(styleName, value);
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
// properties like 'backgroundColor' must be set as a js-property
|
|
556
|
-
domNode.style[styleName] = value;
|
|
557
|
-
}
|
|
558
|
-
},
|
|
559
|
-
};
|
|
560
|
-
var applyDefaultProjectionOptions = function (projectorOptions) {
|
|
561
|
-
return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);
|
|
562
|
-
};
|
|
563
|
-
var dom = {
|
|
564
|
-
/**
|
|
565
|
-
* Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
|
|
566
|
-
* its [[Projection.domNode|domNode]] property.
|
|
567
|
-
* This is a low-level method. Users will typically use a [[Projector]] instead.
|
|
568
|
-
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
|
|
569
|
-
* objects may only be rendered once.
|
|
570
|
-
* @param projectionOptions - Options to be used to create and update the projection.
|
|
571
|
-
* @returns The [[Projection]] which also contains the DOM Node that was created.
|
|
572
|
-
*/
|
|
573
|
-
create: function (vnode, projectionOptions) {
|
|
574
|
-
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
575
|
-
createDom(vnode, document.createElement("div"), undefined, projectionOptions);
|
|
576
|
-
return createProjection(vnode, projectionOptions);
|
|
577
|
-
},
|
|
578
|
-
/**
|
|
579
|
-
* Appends a new child node to the DOM which is generated from a [[VNode]].
|
|
580
|
-
* This is a low-level method. Users will typically use a [[Projector]] instead.
|
|
581
|
-
* @param parentNode - The parent node for the new child node.
|
|
582
|
-
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
|
|
583
|
-
* objects may only be rendered once.
|
|
584
|
-
* @param projectionOptions - Options to be used to create and update the [[Projection]].
|
|
585
|
-
* @returns The [[Projection]] that was created.
|
|
586
|
-
*/
|
|
587
|
-
append: function (parentNode, vnode, projectionOptions) {
|
|
588
|
-
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
589
|
-
createDom(vnode, parentNode, undefined, projectionOptions);
|
|
590
|
-
return createProjection(vnode, projectionOptions);
|
|
591
|
-
},
|
|
592
|
-
/**
|
|
593
|
-
* Inserts a new DOM node which is generated from a [[VNode]].
|
|
594
|
-
* This is a low-level method. Users wil typically use a [[Projector]] instead.
|
|
595
|
-
* @param beforeNode - The node that the DOM Node is inserted before.
|
|
596
|
-
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
|
|
597
|
-
* NOTE: [[VNode]] objects may only be rendered once.
|
|
598
|
-
* @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
|
|
599
|
-
* @returns The [[Projection]] that was created.
|
|
600
|
-
*/
|
|
601
|
-
insertBefore: function (beforeNode, vnode, projectionOptions) {
|
|
602
|
-
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
603
|
-
createDom(vnode, beforeNode.parentNode, beforeNode, projectionOptions);
|
|
604
|
-
return createProjection(vnode, projectionOptions);
|
|
605
|
-
},
|
|
606
|
-
/**
|
|
607
|
-
* Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
|
|
608
|
-
* This means that the virtual DOM and the real DOM will have one overlapping element.
|
|
609
|
-
* Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
|
|
610
|
-
* This is a low-level method. Users wil typically use a [[Projector]] instead.
|
|
611
|
-
* @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
|
|
612
|
-
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
|
|
613
|
-
* may only be rendered once.
|
|
614
|
-
* @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
|
|
615
|
-
* @returns The [[Projection]] that was created.
|
|
616
|
-
*/
|
|
617
|
-
merge: function (element, vnode, projectionOptions) {
|
|
618
|
-
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
619
|
-
vnode.domNode = element;
|
|
620
|
-
initPropertiesAndChildren(element, vnode, projectionOptions);
|
|
621
|
-
return createProjection(vnode, projectionOptions);
|
|
622
|
-
},
|
|
623
|
-
/**
|
|
624
|
-
* Replaces an existing DOM node with a node generated from a [[VNode]].
|
|
625
|
-
* This is a low-level method. Users will typically use a [[Projector]] instead.
|
|
626
|
-
* @param element - The node for the [[VNode]] to replace.
|
|
627
|
-
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
|
|
628
|
-
* objects may only be rendered once.
|
|
629
|
-
* @param projectionOptions - Options to be used to create and update the [[Projection]].
|
|
630
|
-
* @returns The [[Projection]] that was created.
|
|
631
|
-
*/
|
|
632
|
-
replace: function (element, vnode, projectionOptions) {
|
|
633
|
-
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
634
|
-
createDom(vnode, element.parentNode, element, projectionOptions);
|
|
635
|
-
element.parentNode.removeChild(element);
|
|
636
|
-
return createProjection(vnode, projectionOptions);
|
|
637
|
-
},
|
|
561
|
+
var DEFAULT_PROJECTION_OPTIONS = {
|
|
562
|
+
namespace: undefined,
|
|
563
|
+
performanceLogger: function () { return undefined; },
|
|
564
|
+
eventHandlerInterceptor: undefined,
|
|
565
|
+
styleApplyer: function (domNode, styleName, value) {
|
|
566
|
+
if (styleName.charAt(0) === "-") {
|
|
567
|
+
// CSS variables must be set using setProperty
|
|
568
|
+
domNode.style.setProperty(styleName, value);
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
// properties like 'backgroundColor' must be set as a js-property
|
|
572
|
+
domNode.style[styleName] = value;
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
};
|
|
576
|
+
var applyDefaultProjectionOptions = function (projectorOptions) {
|
|
577
|
+
return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);
|
|
578
|
+
};
|
|
579
|
+
var dom = {
|
|
580
|
+
/**
|
|
581
|
+
* Creates a real DOM tree from `vnode`. The [[Projection]] object returned will contain the resulting DOM Node in
|
|
582
|
+
* its [[Projection.domNode|domNode]] property.
|
|
583
|
+
* This is a low-level method. Users will typically use a [[Projector]] instead.
|
|
584
|
+
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
|
|
585
|
+
* objects may only be rendered once.
|
|
586
|
+
* @param projectionOptions - Options to be used to create and update the projection.
|
|
587
|
+
* @returns The [[Projection]] which also contains the DOM Node that was created.
|
|
588
|
+
*/
|
|
589
|
+
create: function (vnode, projectionOptions) {
|
|
590
|
+
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
591
|
+
createDom(vnode, document.createElement("div"), undefined, projectionOptions);
|
|
592
|
+
return createProjection(vnode, projectionOptions);
|
|
593
|
+
},
|
|
594
|
+
/**
|
|
595
|
+
* Appends a new child node to the DOM which is generated from a [[VNode]].
|
|
596
|
+
* This is a low-level method. Users will typically use a [[Projector]] instead.
|
|
597
|
+
* @param parentNode - The parent node for the new child node.
|
|
598
|
+
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
|
|
599
|
+
* objects may only be rendered once.
|
|
600
|
+
* @param projectionOptions - Options to be used to create and update the [[Projection]].
|
|
601
|
+
* @returns The [[Projection]] that was created.
|
|
602
|
+
*/
|
|
603
|
+
append: function (parentNode, vnode, projectionOptions) {
|
|
604
|
+
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
605
|
+
createDom(vnode, parentNode, undefined, projectionOptions);
|
|
606
|
+
return createProjection(vnode, projectionOptions);
|
|
607
|
+
},
|
|
608
|
+
/**
|
|
609
|
+
* Inserts a new DOM node which is generated from a [[VNode]].
|
|
610
|
+
* This is a low-level method. Users wil typically use a [[Projector]] instead.
|
|
611
|
+
* @param beforeNode - The node that the DOM Node is inserted before.
|
|
612
|
+
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function.
|
|
613
|
+
* NOTE: [[VNode]] objects may only be rendered once.
|
|
614
|
+
* @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
|
|
615
|
+
* @returns The [[Projection]] that was created.
|
|
616
|
+
*/
|
|
617
|
+
insertBefore: function (beforeNode, vnode, projectionOptions) {
|
|
618
|
+
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
619
|
+
createDom(vnode, beforeNode.parentNode, beforeNode, projectionOptions);
|
|
620
|
+
return createProjection(vnode, projectionOptions);
|
|
621
|
+
},
|
|
622
|
+
/**
|
|
623
|
+
* Merges a new DOM node which is generated from a [[VNode]] with an existing DOM Node.
|
|
624
|
+
* This means that the virtual DOM and the real DOM will have one overlapping element.
|
|
625
|
+
* Therefore the selector for the root [[VNode]] will be ignored, but its properties and children will be applied to the Element provided.
|
|
626
|
+
* This is a low-level method. Users wil typically use a [[Projector]] instead.
|
|
627
|
+
* @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
|
|
628
|
+
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]] objects
|
|
629
|
+
* may only be rendered once.
|
|
630
|
+
* @param projectionOptions - Options to be used to create and update the projection, see [[createProjector]].
|
|
631
|
+
* @returns The [[Projection]] that was created.
|
|
632
|
+
*/
|
|
633
|
+
merge: function (element, vnode, projectionOptions) {
|
|
634
|
+
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
635
|
+
vnode.domNode = element;
|
|
636
|
+
initPropertiesAndChildren(element, vnode, projectionOptions);
|
|
637
|
+
return createProjection(vnode, projectionOptions);
|
|
638
|
+
},
|
|
639
|
+
/**
|
|
640
|
+
* Replaces an existing DOM node with a node generated from a [[VNode]].
|
|
641
|
+
* This is a low-level method. Users will typically use a [[Projector]] instead.
|
|
642
|
+
* @param element - The node for the [[VNode]] to replace.
|
|
643
|
+
* @param vnode - The root of the virtual DOM tree that was created using the [[h]] function. NOTE: [[VNode]]
|
|
644
|
+
* objects may only be rendered once.
|
|
645
|
+
* @param projectionOptions - Options to be used to create and update the [[Projection]].
|
|
646
|
+
* @returns The [[Projection]] that was created.
|
|
647
|
+
*/
|
|
648
|
+
replace: function (element, vnode, projectionOptions) {
|
|
649
|
+
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
650
|
+
createDom(vnode, element.parentNode, element, projectionOptions);
|
|
651
|
+
element.parentNode.removeChild(element);
|
|
652
|
+
return createProjection(vnode, projectionOptions);
|
|
653
|
+
},
|
|
638
654
|
};
|
|
639
655
|
|
|
640
|
-
var toTextVNode = function (data) {
|
|
641
|
-
return {
|
|
642
|
-
vnodeSelector: "",
|
|
643
|
-
properties: undefined,
|
|
644
|
-
children: undefined,
|
|
645
|
-
text: data.toString(),
|
|
646
|
-
domNode: null,
|
|
647
|
-
};
|
|
648
|
-
};
|
|
649
|
-
var appendChildren = function (parentSelector, insertions, main) {
|
|
650
|
-
for (var i = 0, length_1 = insertions.length; i < length_1; i++) {
|
|
651
|
-
var item = insertions[i];
|
|
652
|
-
if (Array.isArray(item)) {
|
|
653
|
-
appendChildren(parentSelector, item, main);
|
|
654
|
-
}
|
|
655
|
-
else {
|
|
656
|
-
if (item !== null && item !== undefined && item !== false) {
|
|
657
|
-
if (typeof item === "string") {
|
|
658
|
-
item = toTextVNode(item);
|
|
659
|
-
}
|
|
660
|
-
main.push(item);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
function h(selector, properties, children) {
|
|
666
|
-
if (Array.isArray(properties)) {
|
|
667
|
-
children = properties;
|
|
668
|
-
properties = undefined;
|
|
669
|
-
}
|
|
670
|
-
else if ((properties && (typeof properties === "string" || properties.vnodeSelector)) ||
|
|
671
|
-
(children && (typeof children === "string" || children.vnodeSelector))) {
|
|
672
|
-
throw new Error("h called with invalid arguments");
|
|
673
|
-
}
|
|
674
|
-
var text;
|
|
675
|
-
var flattenedChildren;
|
|
676
|
-
// Recognize a common special case where there is only a single text node
|
|
677
|
-
if (children && children.length === 1 && typeof children[0] === "string") {
|
|
678
|
-
text = children[0];
|
|
679
|
-
}
|
|
680
|
-
else if (children) {
|
|
681
|
-
flattenedChildren = [];
|
|
682
|
-
appendChildren(selector, children, flattenedChildren);
|
|
683
|
-
if (flattenedChildren.length === 0) {
|
|
684
|
-
flattenedChildren = undefined;
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
return {
|
|
688
|
-
vnodeSelector: selector,
|
|
689
|
-
properties: properties,
|
|
690
|
-
children: flattenedChildren,
|
|
691
|
-
text: text === "" ? undefined : text,
|
|
692
|
-
domNode: null,
|
|
693
|
-
};
|
|
656
|
+
var toTextVNode = function (data) {
|
|
657
|
+
return {
|
|
658
|
+
vnodeSelector: "",
|
|
659
|
+
properties: undefined,
|
|
660
|
+
children: undefined,
|
|
661
|
+
text: data.toString(),
|
|
662
|
+
domNode: null,
|
|
663
|
+
};
|
|
664
|
+
};
|
|
665
|
+
var appendChildren = function (parentSelector, insertions, main) {
|
|
666
|
+
for (var i = 0, length_1 = insertions.length; i < length_1; i++) {
|
|
667
|
+
var item = insertions[i];
|
|
668
|
+
if (Array.isArray(item)) {
|
|
669
|
+
appendChildren(parentSelector, item, main);
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
if (item !== null && item !== undefined && item !== false) {
|
|
673
|
+
if (typeof item === "string") {
|
|
674
|
+
item = toTextVNode(item);
|
|
675
|
+
}
|
|
676
|
+
main.push(item);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
function h(selector, properties, children) {
|
|
682
|
+
if (Array.isArray(properties)) {
|
|
683
|
+
children = properties;
|
|
684
|
+
properties = undefined;
|
|
685
|
+
}
|
|
686
|
+
else if ((properties && (typeof properties === "string" || properties.vnodeSelector)) ||
|
|
687
|
+
(children && (typeof children === "string" || children.vnodeSelector))) {
|
|
688
|
+
throw new Error("h called with invalid arguments");
|
|
689
|
+
}
|
|
690
|
+
var text;
|
|
691
|
+
var flattenedChildren;
|
|
692
|
+
// Recognize a common special case where there is only a single text node
|
|
693
|
+
if (children && children.length === 1 && typeof children[0] === "string") {
|
|
694
|
+
text = children[0];
|
|
695
|
+
}
|
|
696
|
+
else if (children) {
|
|
697
|
+
flattenedChildren = [];
|
|
698
|
+
appendChildren(selector, children, flattenedChildren);
|
|
699
|
+
if (flattenedChildren.length === 0) {
|
|
700
|
+
flattenedChildren = undefined;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return {
|
|
704
|
+
vnodeSelector: selector,
|
|
705
|
+
properties: properties,
|
|
706
|
+
children: flattenedChildren,
|
|
707
|
+
text: text === "" ? undefined : text,
|
|
708
|
+
domNode: null,
|
|
709
|
+
};
|
|
694
710
|
}
|
|
695
711
|
|
|
696
|
-
var createParentNodePath = function (node, rootNode) {
|
|
697
|
-
var parentNodePath = [];
|
|
698
|
-
while (node && node !== rootNode) {
|
|
699
|
-
parentNodePath.push(node);
|
|
700
|
-
node = node.parentNode;
|
|
701
|
-
}
|
|
702
|
-
return parentNodePath;
|
|
703
|
-
};
|
|
704
|
-
var find;
|
|
705
|
-
if (Array.prototype.find) {
|
|
706
|
-
find = function (items, predicate) { return items.find(predicate); };
|
|
707
|
-
}
|
|
708
|
-
else {
|
|
709
|
-
find = function (items, predicate) { return items.filter(predicate)[0]; };
|
|
710
|
-
}
|
|
711
|
-
var findVNodeByParentNodePath = function (vnode, parentNodePath) {
|
|
712
|
-
var result = vnode;
|
|
713
|
-
parentNodePath.forEach(function (node) {
|
|
714
|
-
result =
|
|
715
|
-
result && result.children
|
|
716
|
-
? find(result.children, function (child) { return child.domNode === node; })
|
|
717
|
-
: undefined;
|
|
718
|
-
});
|
|
719
|
-
return result;
|
|
720
|
-
};
|
|
721
|
-
var createEventHandlerInterceptor = function (projector, getProjection, performanceLogger) {
|
|
722
|
-
return function (propertyName, eventHandler, domNode, properties) { return modifiedEventHandler; };
|
|
723
|
-
function modifiedEventHandler(evt) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
var
|
|
727
|
-
parentNodePath.
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
var
|
|
751
|
-
var
|
|
752
|
-
var
|
|
753
|
-
var
|
|
754
|
-
var
|
|
755
|
-
var
|
|
756
|
-
var
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
/*
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
performanceLogger("
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
712
|
+
var createParentNodePath = function (node, rootNode) {
|
|
713
|
+
var parentNodePath = [];
|
|
714
|
+
while (node && node !== rootNode) {
|
|
715
|
+
parentNodePath.push(node);
|
|
716
|
+
node = node.parentNode;
|
|
717
|
+
}
|
|
718
|
+
return parentNodePath;
|
|
719
|
+
};
|
|
720
|
+
var find;
|
|
721
|
+
if (Array.prototype.find) {
|
|
722
|
+
find = function (items, predicate) { return items.find(predicate); };
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
find = function (items, predicate) { return items.filter(predicate)[0]; };
|
|
726
|
+
}
|
|
727
|
+
var findVNodeByParentNodePath = function (vnode, parentNodePath) {
|
|
728
|
+
var result = vnode;
|
|
729
|
+
parentNodePath.forEach(function (node) {
|
|
730
|
+
result =
|
|
731
|
+
result && result.children
|
|
732
|
+
? find(result.children, function (child) { return child.domNode === node; })
|
|
733
|
+
: undefined;
|
|
734
|
+
});
|
|
735
|
+
return result;
|
|
736
|
+
};
|
|
737
|
+
var createEventHandlerInterceptor = function (projector, getProjection, performanceLogger) {
|
|
738
|
+
return function (propertyName, eventHandler, domNode, properties) { return modifiedEventHandler; };
|
|
739
|
+
function modifiedEventHandler(evt) {
|
|
740
|
+
var _a, _b;
|
|
741
|
+
performanceLogger("domEvent", evt);
|
|
742
|
+
var projection = getProjection();
|
|
743
|
+
var parentNodePath = createParentNodePath(evt.currentTarget, projection.domNode);
|
|
744
|
+
parentNodePath.reverse();
|
|
745
|
+
var matchingVNode = findVNodeByParentNodePath(projection.getLastRender(), parentNodePath);
|
|
746
|
+
projector.scheduleRender();
|
|
747
|
+
var result;
|
|
748
|
+
if (matchingVNode) {
|
|
749
|
+
/* eslint-disable prefer-rest-params */
|
|
750
|
+
var listener = (_b = (_a = matchingVNode.properties["on".concat(evt.type)]) !== null && _a !== void 0 ? _a : matchingVNode.properties.on[evt.type].listener) !== null && _b !== void 0 ? _b : matchingVNode.properties.on[evt.type];
|
|
751
|
+
result = listener.apply(matchingVNode.properties.bind || this, arguments);
|
|
752
|
+
/* eslint-enable prefer-rest-params */
|
|
753
|
+
}
|
|
754
|
+
performanceLogger("domEventProcessed", evt);
|
|
755
|
+
return result;
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
/**
|
|
759
|
+
* Creates a [[Projector]] instance using the provided projectionOptions.
|
|
760
|
+
*
|
|
761
|
+
* For more information, see [[Projector]].
|
|
762
|
+
*
|
|
763
|
+
* @param projectorOptions Options that influence how the DOM is rendered and updated.
|
|
764
|
+
*/
|
|
765
|
+
var createProjector = function (projectorOptions) {
|
|
766
|
+
var projector;
|
|
767
|
+
var projectionOptions = applyDefaultProjectionOptions(projectorOptions);
|
|
768
|
+
var performanceLogger = projectionOptions.performanceLogger;
|
|
769
|
+
var renderCompleted = true;
|
|
770
|
+
var scheduled;
|
|
771
|
+
var stopped = false;
|
|
772
|
+
var projections = [];
|
|
773
|
+
var renderFunctions = []; // matches the projections array
|
|
774
|
+
var addProjection = function (
|
|
775
|
+
/* one of: dom.append, dom.insertBefore, dom.replace, dom.merge */
|
|
776
|
+
domFunction,
|
|
777
|
+
/* the parameter of the domFunction */
|
|
778
|
+
node, renderFunction) {
|
|
779
|
+
var projection;
|
|
780
|
+
var getProjection = function () { return projection; };
|
|
781
|
+
projectionOptions.eventHandlerInterceptor = createEventHandlerInterceptor(projector, getProjection, performanceLogger);
|
|
782
|
+
projection = domFunction(node, renderFunction(), projectionOptions);
|
|
783
|
+
projections.push(projection);
|
|
784
|
+
renderFunctions.push(renderFunction);
|
|
785
|
+
};
|
|
786
|
+
var doRender = function () {
|
|
787
|
+
scheduled = undefined;
|
|
788
|
+
if (!renderCompleted) {
|
|
789
|
+
return; // The last render threw an error, it should have been logged in the browser console.
|
|
790
|
+
}
|
|
791
|
+
renderCompleted = false;
|
|
792
|
+
performanceLogger("renderStart", undefined);
|
|
793
|
+
for (var i = 0; i < projections.length; i++) {
|
|
794
|
+
var updatedVnode = renderFunctions[i]();
|
|
795
|
+
performanceLogger("rendered", undefined);
|
|
796
|
+
projections[i].update(updatedVnode);
|
|
797
|
+
performanceLogger("patched", undefined);
|
|
798
|
+
}
|
|
799
|
+
performanceLogger("renderDone", undefined);
|
|
800
|
+
renderCompleted = true;
|
|
801
|
+
};
|
|
802
|
+
projector = {
|
|
803
|
+
renderNow: doRender,
|
|
804
|
+
scheduleRender: function () {
|
|
805
|
+
if (!scheduled && !stopped) {
|
|
806
|
+
scheduled = requestAnimationFrame(doRender);
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
stop: function () {
|
|
810
|
+
if (scheduled) {
|
|
811
|
+
cancelAnimationFrame(scheduled);
|
|
812
|
+
scheduled = undefined;
|
|
813
|
+
}
|
|
814
|
+
stopped = true;
|
|
815
|
+
},
|
|
816
|
+
resume: function () {
|
|
817
|
+
stopped = false;
|
|
818
|
+
renderCompleted = true;
|
|
819
|
+
projector.scheduleRender();
|
|
820
|
+
},
|
|
821
|
+
append: function (parentNode, renderFunction) {
|
|
822
|
+
addProjection(dom.append, parentNode, renderFunction);
|
|
823
|
+
},
|
|
824
|
+
insertBefore: function (beforeNode, renderFunction) {
|
|
825
|
+
addProjection(dom.insertBefore, beforeNode, renderFunction);
|
|
826
|
+
},
|
|
827
|
+
merge: function (domNode, renderFunction) {
|
|
828
|
+
addProjection(dom.merge, domNode, renderFunction);
|
|
829
|
+
},
|
|
830
|
+
replace: function (domNode, renderFunction) {
|
|
831
|
+
addProjection(dom.replace, domNode, renderFunction);
|
|
832
|
+
},
|
|
833
|
+
detach: function (renderFunction) {
|
|
834
|
+
for (var i = 0; i < renderFunctions.length; i++) {
|
|
835
|
+
if (renderFunctions[i] === renderFunction) {
|
|
836
|
+
renderFunctions.splice(i, 1);
|
|
837
|
+
return projections.splice(i, 1)[0];
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
throw new Error("renderFunction was not found");
|
|
841
|
+
},
|
|
842
|
+
};
|
|
843
|
+
return projector;
|
|
826
844
|
};
|
|
827
845
|
|
|
828
|
-
/**
|
|
829
|
-
* Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
|
|
830
|
-
* In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
|
|
831
|
-
* For more information, see [[CalculationCache]].
|
|
832
|
-
*
|
|
833
|
-
* @param <Result> The type of the value that is cached.
|
|
834
|
-
*/
|
|
835
|
-
var createCache = function () {
|
|
836
|
-
var cachedInputs;
|
|
837
|
-
var cachedOutcome;
|
|
838
|
-
return {
|
|
839
|
-
invalidate: function () {
|
|
840
|
-
cachedOutcome = undefined;
|
|
841
|
-
cachedInputs = undefined;
|
|
842
|
-
},
|
|
843
|
-
result: function (inputs, calculation) {
|
|
844
|
-
if (cachedInputs) {
|
|
845
|
-
for (var i = 0; i < inputs.length; i++) {
|
|
846
|
-
if (cachedInputs[i] !== inputs[i]) {
|
|
847
|
-
cachedOutcome = undefined;
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
if (!cachedOutcome) {
|
|
852
|
-
cachedOutcome = calculation();
|
|
853
|
-
cachedInputs = inputs;
|
|
854
|
-
}
|
|
855
|
-
return cachedOutcome;
|
|
856
|
-
},
|
|
857
|
-
};
|
|
846
|
+
/**
|
|
847
|
+
* Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
|
|
848
|
+
* In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
|
|
849
|
+
* For more information, see [[CalculationCache]].
|
|
850
|
+
*
|
|
851
|
+
* @param <Result> The type of the value that is cached.
|
|
852
|
+
*/
|
|
853
|
+
var createCache = function () {
|
|
854
|
+
var cachedInputs;
|
|
855
|
+
var cachedOutcome;
|
|
856
|
+
return {
|
|
857
|
+
invalidate: function () {
|
|
858
|
+
cachedOutcome = undefined;
|
|
859
|
+
cachedInputs = undefined;
|
|
860
|
+
},
|
|
861
|
+
result: function (inputs, calculation) {
|
|
862
|
+
if (cachedInputs) {
|
|
863
|
+
for (var i = 0; i < inputs.length; i++) {
|
|
864
|
+
if (cachedInputs[i] !== inputs[i]) {
|
|
865
|
+
cachedOutcome = undefined;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
if (!cachedOutcome) {
|
|
870
|
+
cachedOutcome = calculation();
|
|
871
|
+
cachedInputs = inputs;
|
|
872
|
+
}
|
|
873
|
+
return cachedOutcome;
|
|
874
|
+
},
|
|
875
|
+
};
|
|
858
876
|
};
|
|
859
877
|
|
|
860
|
-
/**
|
|
861
|
-
* Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
|
|
862
|
-
* See {@link http://maquettejs.org/docs/arrays.html
|
|
863
|
-
*
|
|
864
|
-
* @param <Source> The type of source items. A database-record for instance.
|
|
865
|
-
* @param <Target> The type of target items. A [[MaquetteComponent]] for instance.
|
|
866
|
-
* @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
|
|
867
|
-
* @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
|
|
868
|
-
* to the `callback` argument in `Array.map(callback)`.
|
|
869
|
-
* @param updateResult `function(source, target, index)` that updates a result to an updated source.
|
|
870
|
-
*/
|
|
871
|
-
var createMapping = function (getSourceKey, createResult, updateResult) {
|
|
872
|
-
var keys = [];
|
|
873
|
-
var results = [];
|
|
874
|
-
return {
|
|
875
|
-
results: results,
|
|
876
|
-
map: function (newSources) {
|
|
877
|
-
var newKeys = newSources.map(getSourceKey);
|
|
878
|
-
var oldTargets = results.slice();
|
|
879
|
-
var oldIndex = 0;
|
|
880
|
-
for (var i = 0; i < newSources.length; i++) {
|
|
881
|
-
var source = newSources[i];
|
|
882
|
-
var sourceKey = newKeys[i];
|
|
883
|
-
if (sourceKey === keys[oldIndex]) {
|
|
884
|
-
results[i] = oldTargets[oldIndex];
|
|
885
|
-
updateResult(source, oldTargets[oldIndex], i);
|
|
886
|
-
oldIndex++;
|
|
887
|
-
}
|
|
888
|
-
else {
|
|
889
|
-
var found = false;
|
|
890
|
-
for (var j = 1; j < keys.length + 1; j++) {
|
|
891
|
-
var searchIndex = (oldIndex + j) % keys.length;
|
|
892
|
-
if (keys[searchIndex] === sourceKey) {
|
|
893
|
-
results[i] = oldTargets[searchIndex];
|
|
894
|
-
updateResult(newSources[i], oldTargets[searchIndex], i);
|
|
895
|
-
oldIndex = searchIndex + 1;
|
|
896
|
-
found = true;
|
|
897
|
-
break;
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
if (!found) {
|
|
901
|
-
results[i] = createResult(source, i);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
results.length = newSources.length;
|
|
906
|
-
keys = newKeys;
|
|
907
|
-
},
|
|
908
|
-
};
|
|
878
|
+
/**
|
|
879
|
+
* Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
|
|
880
|
+
* See {@link http://maquettejs.org/docs/arrays.html Working with arrays}.
|
|
881
|
+
*
|
|
882
|
+
* @param <Source> The type of source items. A database-record for instance.
|
|
883
|
+
* @param <Target> The type of target items. A [[MaquetteComponent]] for instance.
|
|
884
|
+
* @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
|
|
885
|
+
* @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
|
|
886
|
+
* to the `callback` argument in `Array.map(callback)`.
|
|
887
|
+
* @param updateResult `function(source, target, index)` that updates a result to an updated source.
|
|
888
|
+
*/
|
|
889
|
+
var createMapping = function (getSourceKey, createResult, updateResult) {
|
|
890
|
+
var keys = [];
|
|
891
|
+
var results = [];
|
|
892
|
+
return {
|
|
893
|
+
results: results,
|
|
894
|
+
map: function (newSources) {
|
|
895
|
+
var newKeys = newSources.map(getSourceKey);
|
|
896
|
+
var oldTargets = results.slice();
|
|
897
|
+
var oldIndex = 0;
|
|
898
|
+
for (var i = 0; i < newSources.length; i++) {
|
|
899
|
+
var source = newSources[i];
|
|
900
|
+
var sourceKey = newKeys[i];
|
|
901
|
+
if (sourceKey === keys[oldIndex]) {
|
|
902
|
+
results[i] = oldTargets[oldIndex];
|
|
903
|
+
updateResult(source, oldTargets[oldIndex], i);
|
|
904
|
+
oldIndex++;
|
|
905
|
+
}
|
|
906
|
+
else {
|
|
907
|
+
var found = false;
|
|
908
|
+
for (var j = 1; j < keys.length + 1; j++) {
|
|
909
|
+
var searchIndex = (oldIndex + j) % keys.length;
|
|
910
|
+
if (keys[searchIndex] === sourceKey) {
|
|
911
|
+
results[i] = oldTargets[searchIndex];
|
|
912
|
+
updateResult(newSources[i], oldTargets[searchIndex], i);
|
|
913
|
+
oldIndex = searchIndex + 1;
|
|
914
|
+
found = true;
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
if (!found) {
|
|
919
|
+
results[i] = createResult(source, i);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
results.length = newSources.length;
|
|
924
|
+
keys = newKeys;
|
|
925
|
+
},
|
|
926
|
+
};
|
|
909
927
|
};
|
|
910
928
|
|
|
911
929
|
exports.createCache = createCache;
|