@odoo/owl 3.0.0-alpha.20 → 3.0.0-alpha.22
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/README.md +100 -110
- package/dist/compile_templates.mjs +84 -80
- package/dist/owl-devtools.zip +0 -0
- package/dist/owl.cjs.js +1612 -1473
- package/dist/owl.es.js +1612 -1473
- package/dist/owl.iife.js +1612 -1473
- package/dist/owl.iife.min.js +1 -1
- package/dist/types/compiler/code_generator.d.ts +1 -2
- package/dist/types/compiler/inline_expressions.d.ts +7 -24
- package/dist/types/compiler/parser.d.ts +3 -8
- package/dist/types/owl.d.ts +33 -27
- package/dist/types/runtime/blockdom/attributes.d.ts +2 -0
- package/dist/types/runtime/component_node.d.ts +2 -0
- package/dist/types/runtime/plugin_manager.d.ts +2 -0
- package/dist/types/runtime/reactivity/computations.d.ts +1 -0
- package/dist/types/runtime/rendering/scheduler.d.ts +1 -1
- package/dist/types/runtime/rendering/template_helpers.d.ts +2 -2
- package/dist/types/runtime/types.d.ts +3 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +25 -2
- package/dist/compiler.js +0 -2371
- package/dist/owl.cjs.runtime.js +0 -4070
- package/dist/owl.es.runtime.js +0 -4026
- package/dist/owl.iife.runtime.js +0 -4074
- package/dist/owl.iife.runtime.min.js +0 -1
- package/dist/types/common/types.d.ts +0 -1
- package/dist/types/runtime/cancellableContext.d.ts +0 -15
- package/dist/types/runtime/cancellablePromise.d.ts +0 -15
- package/dist/types/runtime/error_handling.d.ts +0 -13
- package/dist/types/runtime/executionContext.d.ts +0 -0
- package/dist/types/runtime/fibers.d.ts +0 -37
- package/dist/types/runtime/listOperation.d.ts +0 -1
- package/dist/types/runtime/model.d.ts +0 -48
- package/dist/types/runtime/plugins.d.ts +0 -36
- package/dist/types/runtime/portal.d.ts +0 -12
- package/dist/types/runtime/reactivity/async_computed.d.ts +0 -1
- package/dist/types/runtime/reactivity/derived.d.ts +0 -7
- package/dist/types/runtime/reactivity/reactivity.d.ts +0 -46
- package/dist/types/runtime/reactivity/signals.d.ts +0 -30
- package/dist/types/runtime/reactivity/state.d.ts +0 -48
- package/dist/types/runtime/reactivity.d.ts +0 -57
- package/dist/types/runtime/relationalModel/discussModel.d.ts +0 -19
- package/dist/types/runtime/relationalModel/discussModelTypes.d.ts +0 -22
- package/dist/types/runtime/relationalModel/field.d.ts +0 -20
- package/dist/types/runtime/relationalModel/model.d.ts +0 -59
- package/dist/types/runtime/relationalModel/modelData.d.ts +0 -18
- package/dist/types/runtime/relationalModel/modelRegistry.d.ts +0 -3
- package/dist/types/runtime/relationalModel/modelUtils.d.ts +0 -4
- package/dist/types/runtime/relationalModel/store.d.ts +0 -16
- package/dist/types/runtime/relationalModel/types.d.ts +0 -83
- package/dist/types/runtime/relationalModel/util.d.ts +0 -1
- package/dist/types/runtime/relationalModel/web/WebDataPoint.d.ts +0 -25
- package/dist/types/runtime/relationalModel/web/WebRecord.d.ts +0 -131
- package/dist/types/runtime/relationalModel/web/WebStaticList.d.ts +0 -63
- package/dist/types/runtime/relationalModel/web/webModel.d.ts +0 -5
- package/dist/types/runtime/relationalModel/web/webModelTypes.d.ts +0 -139
- package/dist/types/runtime/scheduler.d.ts +0 -21
- package/dist/types/runtime/signals.d.ts +0 -19
- package/dist/types/runtime/suspense.d.ts +0 -5
- package/dist/types/runtime/task.d.ts +0 -12
- package/dist/types/runtime/template_helpers.d.ts +0 -58
- package/dist/types/utils/registry.d.ts +0 -15
package/dist/owl.es.js
CHANGED
|
@@ -127,10 +127,16 @@ function toggler(key, child) {
|
|
|
127
127
|
return new VToggler(key, child);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
let elemSetAttribute;
|
|
131
|
+
let removeAttribute;
|
|
132
|
+
let tokenListAdd;
|
|
133
|
+
let tokenListRemove;
|
|
134
|
+
if (typeof Element !== "undefined") {
|
|
135
|
+
({ setAttribute: elemSetAttribute, removeAttribute } = Element.prototype);
|
|
136
|
+
const tokenList = DOMTokenList.prototype;
|
|
137
|
+
tokenListAdd = tokenList.add;
|
|
138
|
+
tokenListRemove = tokenList.remove;
|
|
139
|
+
}
|
|
134
140
|
const isArray = Array.isArray;
|
|
135
141
|
const { split, trim } = String.prototype;
|
|
136
142
|
const wordRegexp = /\s+/;
|
|
@@ -162,6 +168,9 @@ function attrsSetter(attrs) {
|
|
|
162
168
|
if (attrs[0] === "class") {
|
|
163
169
|
setClass.call(this, attrs[1]);
|
|
164
170
|
}
|
|
171
|
+
else if (attrs[0] === "style") {
|
|
172
|
+
setStyle.call(this, attrs[1]);
|
|
173
|
+
}
|
|
165
174
|
else {
|
|
166
175
|
setAttribute.call(this, attrs[0], attrs[1]);
|
|
167
176
|
}
|
|
@@ -171,6 +180,9 @@ function attrsSetter(attrs) {
|
|
|
171
180
|
if (k === "class") {
|
|
172
181
|
setClass.call(this, attrs[k]);
|
|
173
182
|
}
|
|
183
|
+
else if (k === "style") {
|
|
184
|
+
setStyle.call(this, attrs[k]);
|
|
185
|
+
}
|
|
174
186
|
else {
|
|
175
187
|
setAttribute.call(this, k, attrs[k]);
|
|
176
188
|
}
|
|
@@ -188,6 +200,9 @@ function attrsUpdater(attrs, oldAttrs) {
|
|
|
188
200
|
if (name === "class") {
|
|
189
201
|
updateClass.call(this, val, oldAttrs[1]);
|
|
190
202
|
}
|
|
203
|
+
else if (name === "style") {
|
|
204
|
+
updateStyle.call(this, val, oldAttrs[1]);
|
|
205
|
+
}
|
|
191
206
|
else {
|
|
192
207
|
setAttribute.call(this, name, val);
|
|
193
208
|
}
|
|
@@ -203,6 +218,9 @@ function attrsUpdater(attrs, oldAttrs) {
|
|
|
203
218
|
if (k === "class") {
|
|
204
219
|
updateClass.call(this, "", oldAttrs[k]);
|
|
205
220
|
}
|
|
221
|
+
else if (k === "style") {
|
|
222
|
+
updateStyle.call(this, "", oldAttrs[k]);
|
|
223
|
+
}
|
|
206
224
|
else {
|
|
207
225
|
removeAttribute.call(this, k);
|
|
208
226
|
}
|
|
@@ -214,6 +232,9 @@ function attrsUpdater(attrs, oldAttrs) {
|
|
|
214
232
|
if (k === "class") {
|
|
215
233
|
updateClass.call(this, val, oldAttrs[k]);
|
|
216
234
|
}
|
|
235
|
+
else if (k === "style") {
|
|
236
|
+
updateStyle.call(this, val, oldAttrs[k]);
|
|
237
|
+
}
|
|
217
238
|
else {
|
|
218
239
|
setAttribute.call(this, k, val);
|
|
219
240
|
}
|
|
@@ -261,30 +282,106 @@ function toClassObj(expr) {
|
|
|
261
282
|
return { [expr]: true };
|
|
262
283
|
}
|
|
263
284
|
}
|
|
285
|
+
// ---------------------------------------------------------------------------
|
|
286
|
+
// Style
|
|
287
|
+
// ---------------------------------------------------------------------------
|
|
288
|
+
const CSS_PROP_CACHE = {};
|
|
289
|
+
function toKebabCase(prop) {
|
|
290
|
+
if (prop in CSS_PROP_CACHE) {
|
|
291
|
+
return CSS_PROP_CACHE[prop];
|
|
292
|
+
}
|
|
293
|
+
const result = prop.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
294
|
+
CSS_PROP_CACHE[prop] = result;
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
function toStyleObj(expr) {
|
|
298
|
+
const result = {};
|
|
299
|
+
switch (typeof expr) {
|
|
300
|
+
case "string": {
|
|
301
|
+
const str = trim.call(expr);
|
|
302
|
+
if (!str) {
|
|
303
|
+
return {};
|
|
304
|
+
}
|
|
305
|
+
const parts = str.split(";");
|
|
306
|
+
for (let part of parts) {
|
|
307
|
+
part = trim.call(part);
|
|
308
|
+
if (!part) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const colonIdx = part.indexOf(":");
|
|
312
|
+
if (colonIdx === -1) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const prop = trim.call(part.slice(0, colonIdx));
|
|
316
|
+
const value = trim.call(part.slice(colonIdx + 1));
|
|
317
|
+
if (prop && value && value !== "undefined") {
|
|
318
|
+
result[prop] = value;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
case "object":
|
|
324
|
+
for (let prop in expr) {
|
|
325
|
+
const value = expr[prop];
|
|
326
|
+
if (value || value === 0) {
|
|
327
|
+
result[toKebabCase(prop)] = String(value);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return result;
|
|
331
|
+
default:
|
|
332
|
+
return {};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// ---------------------------------------------------------------------------
|
|
336
|
+
// Class
|
|
337
|
+
// ---------------------------------------------------------------------------
|
|
264
338
|
function setClass(val) {
|
|
265
339
|
val = val === "" ? {} : toClassObj(val);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
for (let c in val) {
|
|
269
|
-
tokenListAdd.call(cl, c);
|
|
340
|
+
for (let k in val) {
|
|
341
|
+
tokenListAdd.call(this.classList, k);
|
|
270
342
|
}
|
|
271
343
|
}
|
|
272
344
|
function updateClass(val, oldVal) {
|
|
273
345
|
oldVal = oldVal === "" ? {} : toClassObj(oldVal);
|
|
274
346
|
val = val === "" ? {} : toClassObj(val);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
347
|
+
for (let k in oldVal) {
|
|
348
|
+
if (!(k in val)) {
|
|
349
|
+
tokenListRemove.call(this.classList, k);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
for (let k in val) {
|
|
353
|
+
if (val[k] !== oldVal[k]) {
|
|
354
|
+
tokenListAdd.call(this.classList, k);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
// ---------------------------------------------------------------------------
|
|
359
|
+
// Style setters
|
|
360
|
+
// ---------------------------------------------------------------------------
|
|
361
|
+
function setStyle(val) {
|
|
362
|
+
val = val === "" ? {} : toStyleObj(val);
|
|
363
|
+
const style = this.style;
|
|
364
|
+
for (let prop in val) {
|
|
365
|
+
style.setProperty(prop, val[prop]);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function updateStyle(val, oldVal) {
|
|
369
|
+
oldVal = oldVal === "" ? {} : toStyleObj(oldVal);
|
|
370
|
+
val = val === "" ? {} : toStyleObj(val);
|
|
371
|
+
const style = this.style;
|
|
372
|
+
for (let prop in oldVal) {
|
|
373
|
+
if (!(prop in val)) {
|
|
374
|
+
style.removeProperty(prop);
|
|
280
375
|
}
|
|
281
376
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
tokenListAdd.call(cl, c);
|
|
377
|
+
for (let prop in val) {
|
|
378
|
+
if (val[prop] !== oldVal[prop]) {
|
|
379
|
+
style.setProperty(prop, val[prop]);
|
|
286
380
|
}
|
|
287
381
|
}
|
|
382
|
+
if (!style.cssText) {
|
|
383
|
+
removeAttribute.call(this, "style");
|
|
384
|
+
}
|
|
288
385
|
}
|
|
289
386
|
|
|
290
387
|
/**
|
|
@@ -421,16 +518,17 @@ function markup(valueOrStrings, ...placeholders) {
|
|
|
421
518
|
function createEventHandler(rawEvent) {
|
|
422
519
|
const eventName = rawEvent.split(".")[0];
|
|
423
520
|
const capture = rawEvent.includes(".capture");
|
|
521
|
+
const passive = rawEvent.includes(".passive");
|
|
424
522
|
if (rawEvent.includes(".synthetic")) {
|
|
425
|
-
return createSyntheticHandler(eventName, capture);
|
|
523
|
+
return createSyntheticHandler(eventName, capture, passive);
|
|
426
524
|
}
|
|
427
525
|
else {
|
|
428
|
-
return createElementHandler(eventName, capture);
|
|
526
|
+
return createElementHandler(eventName, capture, passive);
|
|
429
527
|
}
|
|
430
528
|
}
|
|
431
529
|
// Native listener
|
|
432
530
|
let nextNativeEventId = 1;
|
|
433
|
-
function createElementHandler(evName, capture = false) {
|
|
531
|
+
function createElementHandler(evName, capture = false, passive = false) {
|
|
434
532
|
let eventKey = `__event__${evName}_${nextNativeEventId++}`;
|
|
435
533
|
if (capture) {
|
|
436
534
|
eventKey = `${eventKey}_capture`;
|
|
@@ -444,13 +542,14 @@ function createElementHandler(evName, capture = false) {
|
|
|
444
542
|
return;
|
|
445
543
|
config$1.mainEventHandler(data, ev, currentTarget);
|
|
446
544
|
}
|
|
545
|
+
const options = { capture, passive };
|
|
447
546
|
function setup(data) {
|
|
448
547
|
this[eventKey] = data;
|
|
449
|
-
this.addEventListener(evName, listener,
|
|
548
|
+
this.addEventListener(evName, listener, options);
|
|
450
549
|
}
|
|
451
550
|
function remove() {
|
|
452
551
|
delete this[eventKey];
|
|
453
|
-
this.removeEventListener(evName, listener,
|
|
552
|
+
this.removeEventListener(evName, listener, options);
|
|
454
553
|
}
|
|
455
554
|
function update(data) {
|
|
456
555
|
this[eventKey] = data;
|
|
@@ -460,12 +559,12 @@ function createElementHandler(evName, capture = false) {
|
|
|
460
559
|
// Synthetic handler: a form of event delegation that allows placing only one
|
|
461
560
|
// listener per event type.
|
|
462
561
|
let nextSyntheticEventId = 1;
|
|
463
|
-
function createSyntheticHandler(evName, capture = false) {
|
|
562
|
+
function createSyntheticHandler(evName, capture = false, passive = false) {
|
|
464
563
|
let eventKey = `__event__synthetic_${evName}`;
|
|
465
564
|
if (capture) {
|
|
466
565
|
eventKey = `${eventKey}_capture`;
|
|
467
566
|
}
|
|
468
|
-
setupSyntheticEvent(evName, eventKey, capture);
|
|
567
|
+
setupSyntheticEvent(evName, eventKey, capture, passive);
|
|
469
568
|
const currentId = nextSyntheticEventId++;
|
|
470
569
|
function setup(data) {
|
|
471
570
|
const _data = this[eventKey] || {};
|
|
@@ -492,21 +591,27 @@ function nativeToSyntheticEvent(eventKey, event) {
|
|
|
492
591
|
}
|
|
493
592
|
}
|
|
494
593
|
const CONFIGURED_SYNTHETIC_EVENTS = {};
|
|
495
|
-
function setupSyntheticEvent(evName, eventKey, capture = false) {
|
|
594
|
+
function setupSyntheticEvent(evName, eventKey, capture = false, passive = false) {
|
|
496
595
|
if (CONFIGURED_SYNTHETIC_EVENTS[eventKey]) {
|
|
497
596
|
return;
|
|
498
597
|
}
|
|
499
598
|
document.addEventListener(evName, (event) => nativeToSyntheticEvent(eventKey, event), {
|
|
500
599
|
capture,
|
|
600
|
+
passive,
|
|
501
601
|
});
|
|
502
602
|
CONFIGURED_SYNTHETIC_EVENTS[eventKey] = true;
|
|
503
603
|
}
|
|
504
604
|
|
|
505
605
|
const getDescriptor$3 = (o, p) => Object.getOwnPropertyDescriptor(o, p);
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
606
|
+
let nodeInsertBefore$3;
|
|
607
|
+
let nodeSetTextContent$1;
|
|
608
|
+
let nodeRemoveChild$3;
|
|
609
|
+
if (typeof Node !== "undefined") {
|
|
610
|
+
const nodeProto = Node.prototype;
|
|
611
|
+
nodeInsertBefore$3 = nodeProto.insertBefore;
|
|
612
|
+
nodeSetTextContent$1 = getDescriptor$3(nodeProto, "textContent").set;
|
|
613
|
+
nodeRemoveChild$3 = nodeProto.removeChild;
|
|
614
|
+
}
|
|
510
615
|
// -----------------------------------------------------------------------------
|
|
511
616
|
// Multi NODE
|
|
512
617
|
// -----------------------------------------------------------------------------
|
|
@@ -646,11 +751,15 @@ function multi(children) {
|
|
|
646
751
|
}
|
|
647
752
|
|
|
648
753
|
const getDescriptor$2 = (o, p) => Object.getOwnPropertyDescriptor(o, p);
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
const
|
|
754
|
+
let nodeInsertBefore$2;
|
|
755
|
+
let characterDataSetData$1;
|
|
756
|
+
let nodeRemoveChild$2;
|
|
757
|
+
if (typeof Node !== "undefined") {
|
|
758
|
+
const nodeProto = Node.prototype;
|
|
759
|
+
nodeInsertBefore$2 = nodeProto.insertBefore;
|
|
760
|
+
nodeRemoveChild$2 = nodeProto.removeChild;
|
|
761
|
+
characterDataSetData$1 = getDescriptor$2(CharacterData.prototype, "data").set;
|
|
762
|
+
}
|
|
654
763
|
class VSimpleNode {
|
|
655
764
|
text;
|
|
656
765
|
parentEl;
|
|
@@ -681,7 +790,7 @@ class VSimpleNode {
|
|
|
681
790
|
return this.text;
|
|
682
791
|
}
|
|
683
792
|
}
|
|
684
|
-
|
|
793
|
+
class VText extends VSimpleNode {
|
|
685
794
|
mount(parent, afterNode) {
|
|
686
795
|
this.mountNode(document.createTextNode(toText(this.text)), parent, afterNode);
|
|
687
796
|
}
|
|
@@ -692,7 +801,7 @@ let VText$1 = class VText extends VSimpleNode {
|
|
|
692
801
|
this.text = text2;
|
|
693
802
|
}
|
|
694
803
|
}
|
|
695
|
-
}
|
|
804
|
+
}
|
|
696
805
|
class VComment extends VSimpleNode {
|
|
697
806
|
mount(parent, afterNode) {
|
|
698
807
|
this.mountNode(document.createComment(toText(this.text)), parent, afterNode);
|
|
@@ -700,7 +809,7 @@ class VComment extends VSimpleNode {
|
|
|
700
809
|
patch() { }
|
|
701
810
|
}
|
|
702
811
|
function text(str) {
|
|
703
|
-
return new VText
|
|
812
|
+
return new VText(str);
|
|
704
813
|
}
|
|
705
814
|
function comment(str) {
|
|
706
815
|
return new VComment(str);
|
|
@@ -719,12 +828,18 @@ function toText(value) {
|
|
|
719
828
|
}
|
|
720
829
|
|
|
721
830
|
const getDescriptor$1 = (o, p) => Object.getOwnPropertyDescriptor(o, p);
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
831
|
+
let nodeProto;
|
|
832
|
+
let elementProto;
|
|
833
|
+
let characterDataSetData;
|
|
834
|
+
let nodeGetFirstChild;
|
|
835
|
+
let nodeGetNextSibling;
|
|
836
|
+
if (typeof Node !== "undefined") {
|
|
837
|
+
nodeProto = Node.prototype;
|
|
838
|
+
elementProto = Element.prototype;
|
|
839
|
+
characterDataSetData = getDescriptor$1(CharacterData.prototype, "data").set;
|
|
840
|
+
nodeGetFirstChild = getDescriptor$1(nodeProto, "firstChild").get;
|
|
841
|
+
nodeGetNextSibling = getDescriptor$1(nodeProto, "nextSibling").get;
|
|
842
|
+
}
|
|
728
843
|
const NO_OP = () => { };
|
|
729
844
|
function makePropSetter(name) {
|
|
730
845
|
return function setProp(value) {
|
|
@@ -1019,6 +1134,10 @@ function updateCtx(ctx, tree) {
|
|
|
1019
1134
|
setter = setClass;
|
|
1020
1135
|
updater = updateClass;
|
|
1021
1136
|
}
|
|
1137
|
+
else if (info.name === "style") {
|
|
1138
|
+
setter = setStyle;
|
|
1139
|
+
updater = updateStyle;
|
|
1140
|
+
}
|
|
1022
1141
|
else {
|
|
1023
1142
|
setter = createAttrUpdater(info.name);
|
|
1024
1143
|
updater = setter;
|
|
@@ -1104,8 +1223,8 @@ function createBlockClass(template, ctx) {
|
|
|
1104
1223
|
(((c.afterRefIdx ?? 0) & 0x7fff) << 16));
|
|
1105
1224
|
// these values are defined here to make them faster to lookup in the class
|
|
1106
1225
|
// block scope
|
|
1107
|
-
const nodeCloneNode = nodeProto
|
|
1108
|
-
const nodeInsertBefore = nodeProto
|
|
1226
|
+
const nodeCloneNode = nodeProto.cloneNode;
|
|
1227
|
+
const nodeInsertBefore = nodeProto.insertBefore;
|
|
1109
1228
|
const elementRemove = elementProto.remove;
|
|
1110
1229
|
class Block {
|
|
1111
1230
|
el;
|
|
@@ -1161,8 +1280,7 @@ function createBlockClass(template, ctx) {
|
|
|
1161
1280
|
locSetters[i].call(refs[locRefIdxs[i]], data[i]);
|
|
1162
1281
|
}
|
|
1163
1282
|
}
|
|
1164
|
-
|
|
1165
|
-
// preparing all children
|
|
1283
|
+
// preparing all children (off-DOM, before inserting el into the live document)
|
|
1166
1284
|
if (childN) {
|
|
1167
1285
|
const children = this.children;
|
|
1168
1286
|
for (let i = 0; i < childN; i++) {
|
|
@@ -1176,6 +1294,7 @@ function createBlockClass(template, ctx) {
|
|
|
1176
1294
|
}
|
|
1177
1295
|
}
|
|
1178
1296
|
}
|
|
1297
|
+
nodeInsertBefore.call(parent, el, afterNode);
|
|
1179
1298
|
this.el = el;
|
|
1180
1299
|
this.parentEl = parent;
|
|
1181
1300
|
if (cbRefs.length) {
|
|
@@ -1253,11 +1372,17 @@ function setText(value) {
|
|
|
1253
1372
|
}
|
|
1254
1373
|
|
|
1255
1374
|
const getDescriptor = (o, p) => Object.getOwnPropertyDescriptor(o, p);
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1375
|
+
let nodeInsertBefore$1;
|
|
1376
|
+
let nodeAppendChild;
|
|
1377
|
+
let nodeRemoveChild$1;
|
|
1378
|
+
let nodeSetTextContent;
|
|
1379
|
+
if (typeof Node !== "undefined") {
|
|
1380
|
+
const nodeProto = Node.prototype;
|
|
1381
|
+
nodeInsertBefore$1 = nodeProto.insertBefore;
|
|
1382
|
+
nodeAppendChild = nodeProto.appendChild;
|
|
1383
|
+
nodeRemoveChild$1 = nodeProto.removeChild;
|
|
1384
|
+
nodeSetTextContent = getDescriptor(nodeProto, "textContent").set;
|
|
1385
|
+
}
|
|
1261
1386
|
// -----------------------------------------------------------------------------
|
|
1262
1387
|
// List Node
|
|
1263
1388
|
// -----------------------------------------------------------------------------
|
|
@@ -1473,9 +1598,13 @@ function createMapping(ch1, startIdx1, endIdx2) {
|
|
|
1473
1598
|
return mapping;
|
|
1474
1599
|
}
|
|
1475
1600
|
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1601
|
+
let nodeInsertBefore;
|
|
1602
|
+
let nodeRemoveChild;
|
|
1603
|
+
if (typeof Node !== "undefined") {
|
|
1604
|
+
const nodeProto = Node.prototype;
|
|
1605
|
+
nodeInsertBefore = nodeProto.insertBefore;
|
|
1606
|
+
nodeRemoveChild = nodeProto.removeChild;
|
|
1607
|
+
}
|
|
1479
1608
|
class VHtml {
|
|
1480
1609
|
html;
|
|
1481
1610
|
parentEl;
|
|
@@ -1731,127 +1860,6 @@ class Component {
|
|
|
1731
1860
|
setup() { }
|
|
1732
1861
|
}
|
|
1733
1862
|
|
|
1734
|
-
// Maps fibers to thrown errors
|
|
1735
|
-
const fibersInError = new WeakMap();
|
|
1736
|
-
const nodeErrorHandlers = new WeakMap();
|
|
1737
|
-
function destroyApp(app, error) {
|
|
1738
|
-
try {
|
|
1739
|
-
app.destroy();
|
|
1740
|
-
}
|
|
1741
|
-
catch (e) {
|
|
1742
|
-
// mute all errors here because we are in a corrupted state anyway
|
|
1743
|
-
}
|
|
1744
|
-
const e = Object.assign(new OwlError(`[Owl] Unhandled error. Destroying the root component`), {
|
|
1745
|
-
cause: error,
|
|
1746
|
-
});
|
|
1747
|
-
return e;
|
|
1748
|
-
}
|
|
1749
|
-
function _handleError(node, error) {
|
|
1750
|
-
if (!node) {
|
|
1751
|
-
return false;
|
|
1752
|
-
}
|
|
1753
|
-
const fiber = node.fiber;
|
|
1754
|
-
if (fiber) {
|
|
1755
|
-
fibersInError.set(fiber, error);
|
|
1756
|
-
}
|
|
1757
|
-
const errorHandlers = nodeErrorHandlers.get(node);
|
|
1758
|
-
if (errorHandlers) {
|
|
1759
|
-
let handled = false;
|
|
1760
|
-
// execute in the opposite order
|
|
1761
|
-
const finalize = () => destroyApp(node.app, error);
|
|
1762
|
-
for (let i = errorHandlers.length - 1; i >= 0; i--) {
|
|
1763
|
-
try {
|
|
1764
|
-
errorHandlers[i](error, finalize);
|
|
1765
|
-
handled = true;
|
|
1766
|
-
break;
|
|
1767
|
-
}
|
|
1768
|
-
catch (e) {
|
|
1769
|
-
error = e;
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
if (handled) {
|
|
1773
|
-
return true;
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
return _handleError(node.parent, error);
|
|
1777
|
-
}
|
|
1778
|
-
function handleError(params) {
|
|
1779
|
-
let { error } = params;
|
|
1780
|
-
const node = "node" in params ? params.node : params.fiber.node;
|
|
1781
|
-
const fiber = "fiber" in params ? params.fiber : node.fiber;
|
|
1782
|
-
if (fiber) {
|
|
1783
|
-
// resets the fibers on components if possible. This is important so that
|
|
1784
|
-
// new renderings can be properly included in the initial one, if any.
|
|
1785
|
-
let current = fiber;
|
|
1786
|
-
do {
|
|
1787
|
-
current.node.fiber = current;
|
|
1788
|
-
fibersInError.set(current, error);
|
|
1789
|
-
current = current.parent;
|
|
1790
|
-
} while (current);
|
|
1791
|
-
fibersInError.set(fiber.root, error);
|
|
1792
|
-
}
|
|
1793
|
-
const handled = _handleError(node, error);
|
|
1794
|
-
if (!handled) {
|
|
1795
|
-
throw destroyApp(node.app, error);
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
|
-
// -----------------------------------------------------------------------------
|
|
1800
|
-
// hooks
|
|
1801
|
-
// -----------------------------------------------------------------------------
|
|
1802
|
-
function decorate(node, f, hookName) {
|
|
1803
|
-
const result = f.bind(node.component);
|
|
1804
|
-
if (node.app.dev) {
|
|
1805
|
-
const suffix = f.name ? ` <${f.name}>` : "";
|
|
1806
|
-
Reflect.defineProperty(result, "name", {
|
|
1807
|
-
value: hookName + suffix,
|
|
1808
|
-
});
|
|
1809
|
-
}
|
|
1810
|
-
return result;
|
|
1811
|
-
}
|
|
1812
|
-
function onWillStart(fn) {
|
|
1813
|
-
const { node } = getContext("component");
|
|
1814
|
-
node.willStart.push(decorate(node, fn, "onWillStart"));
|
|
1815
|
-
}
|
|
1816
|
-
function onWillUpdateProps(fn) {
|
|
1817
|
-
const { node } = getContext("component");
|
|
1818
|
-
node.willUpdateProps.push(decorate(node, fn, "onWillUpdateProps"));
|
|
1819
|
-
}
|
|
1820
|
-
function onMounted(fn) {
|
|
1821
|
-
const { node } = getContext("component");
|
|
1822
|
-
node.mounted.push(decorate(node, fn, "onMounted"));
|
|
1823
|
-
}
|
|
1824
|
-
function onWillPatch(fn) {
|
|
1825
|
-
const { node } = getContext("component");
|
|
1826
|
-
node.willPatch.unshift(decorate(node, fn, "onWillPatch"));
|
|
1827
|
-
}
|
|
1828
|
-
function onPatched(fn) {
|
|
1829
|
-
const { node } = getContext("component");
|
|
1830
|
-
node.patched.push(decorate(node, fn, "onPatched"));
|
|
1831
|
-
}
|
|
1832
|
-
function onWillUnmount(fn) {
|
|
1833
|
-
const { node } = getContext("component");
|
|
1834
|
-
node.willUnmount.unshift(decorate(node, fn, "onWillUnmount"));
|
|
1835
|
-
}
|
|
1836
|
-
function onWillDestroy(fn) {
|
|
1837
|
-
const context = getContext();
|
|
1838
|
-
if (context.type === "component") {
|
|
1839
|
-
context.node.willDestroy.unshift(decorate(context.node, fn, "onWillDestroy"));
|
|
1840
|
-
}
|
|
1841
|
-
else {
|
|
1842
|
-
context.manager.onDestroyCb.push(fn);
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
function onError(callback) {
|
|
1846
|
-
const { node } = getContext("component");
|
|
1847
|
-
let handlers = nodeErrorHandlers.get(node);
|
|
1848
|
-
if (!handlers) {
|
|
1849
|
-
handlers = [];
|
|
1850
|
-
nodeErrorHandlers.set(node, handlers);
|
|
1851
|
-
}
|
|
1852
|
-
handlers.push(callback.bind(node.component));
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
1863
|
var ComputationState;
|
|
1856
1864
|
(function (ComputationState) {
|
|
1857
1865
|
ComputationState[ComputationState["EXECUTED"] = 0] = "EXECUTED";
|
|
@@ -1944,6 +1952,20 @@ function removeSources(computation) {
|
|
|
1944
1952
|
}
|
|
1945
1953
|
sources.clear();
|
|
1946
1954
|
}
|
|
1955
|
+
function disposeComputation(computation) {
|
|
1956
|
+
for (const source of computation.sources) {
|
|
1957
|
+
source.observers.delete(computation);
|
|
1958
|
+
// Recursively dispose derived computations that lost all observers
|
|
1959
|
+
if ("compute" in source &&
|
|
1960
|
+
source.isDerived &&
|
|
1961
|
+
source.observers.size === 0) {
|
|
1962
|
+
disposeComputation(source);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
computation.sources.clear();
|
|
1966
|
+
// Mark as stale so it recomputes correctly if ever re-used (shared computed case)
|
|
1967
|
+
computation.state = ComputationState.STALE;
|
|
1968
|
+
}
|
|
1947
1969
|
function markDownstream(computation) {
|
|
1948
1970
|
const stack = [computation];
|
|
1949
1971
|
let current;
|
|
@@ -1975,668 +1997,332 @@ function untrack(fn) {
|
|
|
1975
1997
|
return result;
|
|
1976
1998
|
}
|
|
1977
1999
|
|
|
1978
|
-
|
|
1979
|
-
const
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
const numberType = function validateNumber(context) {
|
|
1985
|
-
if (typeof context.value !== "number") {
|
|
1986
|
-
context.addIssue({ message: "value is not a number" });
|
|
2000
|
+
// Maps fibers to thrown errors
|
|
2001
|
+
const fibersInError = new WeakMap();
|
|
2002
|
+
const nodeErrorHandlers = new WeakMap();
|
|
2003
|
+
function destroyApp(app, error) {
|
|
2004
|
+
try {
|
|
2005
|
+
app.destroy();
|
|
1987
2006
|
}
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
if (typeof context.value !== "string") {
|
|
1991
|
-
context.addIssue({ message: "value is not a string" });
|
|
2007
|
+
catch (e) {
|
|
2008
|
+
// mute all errors here because we are in a corrupted state anyway
|
|
1992
2009
|
}
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
context.addIssue({ message: "value is not an array" });
|
|
1998
|
-
return;
|
|
1999
|
-
}
|
|
2000
|
-
if (!elementType) {
|
|
2001
|
-
return;
|
|
2002
|
-
}
|
|
2003
|
-
for (let index = 0; index < context.value.length; index++) {
|
|
2004
|
-
context.withKey(index).validate(elementType);
|
|
2005
|
-
}
|
|
2006
|
-
};
|
|
2007
|
-
}
|
|
2008
|
-
function constructorType(constructor) {
|
|
2009
|
-
return function validateConstructor(context) {
|
|
2010
|
-
if (!(typeof context.value === "function") ||
|
|
2011
|
-
!(context.value === constructor || context.value.prototype instanceof constructor)) {
|
|
2012
|
-
context.addIssue({ message: `value is not '${constructor.name}' or an extension` });
|
|
2013
|
-
}
|
|
2014
|
-
};
|
|
2010
|
+
const e = Object.assign(new OwlError(`[Owl] Unhandled error. Destroying the root component`), {
|
|
2011
|
+
cause: error,
|
|
2012
|
+
});
|
|
2013
|
+
return e;
|
|
2015
2014
|
}
|
|
2016
|
-
function
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2015
|
+
function _handleError(node, error) {
|
|
2016
|
+
if (!node) {
|
|
2017
|
+
return false;
|
|
2018
|
+
}
|
|
2019
|
+
const fiber = node.fiber;
|
|
2020
|
+
if (fiber) {
|
|
2021
|
+
fibersInError.set(fiber, error);
|
|
2022
|
+
}
|
|
2023
|
+
const errorHandlers = nodeErrorHandlers.get(node);
|
|
2024
|
+
if (errorHandlers) {
|
|
2025
|
+
let handled = false;
|
|
2026
|
+
// execute in the opposite order
|
|
2027
|
+
const finalize = () => destroyApp(node.app, error);
|
|
2028
|
+
for (let i = errorHandlers.length - 1; i >= 0; i--) {
|
|
2029
|
+
try {
|
|
2030
|
+
errorHandlers[i](error, finalize);
|
|
2031
|
+
handled = true;
|
|
2032
|
+
break;
|
|
2033
|
+
}
|
|
2034
|
+
catch (e) {
|
|
2035
|
+
error = e;
|
|
2036
|
+
}
|
|
2021
2037
|
}
|
|
2022
|
-
if (
|
|
2023
|
-
|
|
2038
|
+
if (handled) {
|
|
2039
|
+
return true;
|
|
2024
2040
|
}
|
|
2025
|
-
}
|
|
2041
|
+
}
|
|
2042
|
+
return _handleError(node.parent, error);
|
|
2026
2043
|
}
|
|
2027
|
-
function
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
};
|
|
2047
|
-
}
|
|
2048
|
-
function literalType(literal) {
|
|
2049
|
-
return function validateLiteral(context) {
|
|
2050
|
-
if (context.value !== literal) {
|
|
2051
|
-
context.addIssue({
|
|
2052
|
-
message: `value is not equal to ${typeof literal === "string" ? `'${literal}'` : literal}`,
|
|
2053
|
-
});
|
|
2054
|
-
}
|
|
2055
|
-
};
|
|
2044
|
+
function handleError(params) {
|
|
2045
|
+
let { error } = params;
|
|
2046
|
+
const node = "node" in params ? params.node : params.fiber.node;
|
|
2047
|
+
const fiber = "fiber" in params ? params.fiber : node.fiber;
|
|
2048
|
+
if (fiber) {
|
|
2049
|
+
// resets the fibers on components if possible. This is important so that
|
|
2050
|
+
// new renderings can be properly included in the initial one, if any.
|
|
2051
|
+
let current = fiber;
|
|
2052
|
+
do {
|
|
2053
|
+
current.node.fiber = current;
|
|
2054
|
+
fibersInError.set(current, error);
|
|
2055
|
+
current = current.parent;
|
|
2056
|
+
} while (current);
|
|
2057
|
+
fibersInError.set(fiber.root, error);
|
|
2058
|
+
}
|
|
2059
|
+
const handled = _handleError(node, error);
|
|
2060
|
+
if (!handled) {
|
|
2061
|
+
throw destroyApp(node.app, error);
|
|
2062
|
+
}
|
|
2056
2063
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2064
|
+
|
|
2065
|
+
function makeChildFiber(node, parent) {
|
|
2066
|
+
let current = node.fiber;
|
|
2067
|
+
if (current) {
|
|
2068
|
+
cancelFibers(current.children);
|
|
2069
|
+
current.root = null;
|
|
2070
|
+
}
|
|
2071
|
+
return new Fiber(node, parent);
|
|
2059
2072
|
}
|
|
2060
|
-
function
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2073
|
+
function makeRootFiber(node) {
|
|
2074
|
+
let current = node.fiber;
|
|
2075
|
+
if (current) {
|
|
2076
|
+
let root = current.root;
|
|
2077
|
+
// lock root fiber because canceling children fibers may destroy components,
|
|
2078
|
+
// which means any arbitrary code can be run in onWillDestroy, which may
|
|
2079
|
+
// trigger new renderings
|
|
2080
|
+
root.locked = true;
|
|
2081
|
+
root.setCounter(root.counter + 1 - cancelFibers(current.children));
|
|
2082
|
+
root.locked = false;
|
|
2083
|
+
current.children = [];
|
|
2084
|
+
current.childrenMap = {};
|
|
2085
|
+
current.bdom = null;
|
|
2086
|
+
if (fibersInError.has(current)) {
|
|
2087
|
+
fibersInError.delete(current);
|
|
2088
|
+
fibersInError.delete(root);
|
|
2089
|
+
current.appliedToDom = false;
|
|
2090
|
+
if (current instanceof RootFiber) {
|
|
2091
|
+
// it is possible that this fiber is a fiber that crashed while being
|
|
2092
|
+
// mounted, so the mounted list is possibly corrupted. We restore it to
|
|
2093
|
+
// its normal initial state (which is empty list or a list with a mount
|
|
2094
|
+
// fiber.
|
|
2095
|
+
current.mounted = current instanceof MountFiber ? [current] : [];
|
|
2067
2096
|
}
|
|
2068
|
-
continue;
|
|
2069
2097
|
}
|
|
2070
|
-
|
|
2098
|
+
return current;
|
|
2071
2099
|
}
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
missingKeys,
|
|
2076
|
-
});
|
|
2100
|
+
const fiber = new RootFiber(node, null);
|
|
2101
|
+
if (node.willPatch.length) {
|
|
2102
|
+
fiber.willPatch.push(fiber);
|
|
2077
2103
|
}
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
const missingKeys = keys.filter((key) => {
|
|
2081
|
-
if (key.endsWith("?")) {
|
|
2082
|
-
return false;
|
|
2083
|
-
}
|
|
2084
|
-
return !(key in context.value);
|
|
2085
|
-
});
|
|
2086
|
-
if (missingKeys.length) {
|
|
2087
|
-
context.addIssue({
|
|
2088
|
-
message: "object value have missing keys",
|
|
2089
|
-
missingKeys,
|
|
2090
|
-
});
|
|
2104
|
+
if (node.patched.length) {
|
|
2105
|
+
fiber.patched.push(fiber);
|
|
2091
2106
|
}
|
|
2107
|
+
return fiber;
|
|
2092
2108
|
}
|
|
2093
|
-
function
|
|
2094
|
-
|
|
2095
|
-
if (typeof context.value !== "object" ||
|
|
2096
|
-
Array.isArray(context.value) ||
|
|
2097
|
-
context.value === null) {
|
|
2098
|
-
context.addIssue({ message: "value is not an object" });
|
|
2099
|
-
return;
|
|
2100
|
-
}
|
|
2101
|
-
if (!schema) {
|
|
2102
|
-
return;
|
|
2103
|
-
}
|
|
2104
|
-
if (Array.isArray(schema)) {
|
|
2105
|
-
validateObjectKeys(context, schema);
|
|
2106
|
-
}
|
|
2107
|
-
else {
|
|
2108
|
-
validateObjectShape(context, schema);
|
|
2109
|
-
}
|
|
2110
|
-
};
|
|
2111
|
-
}
|
|
2112
|
-
function promiseType(type) {
|
|
2113
|
-
return function validatePromise(context) {
|
|
2114
|
-
if (!(context.value instanceof Promise)) {
|
|
2115
|
-
context.addIssue({ message: "value is not a promise" });
|
|
2116
|
-
}
|
|
2117
|
-
};
|
|
2109
|
+
function throwOnRender() {
|
|
2110
|
+
throw new OwlError("Attempted to render cancelled fiber");
|
|
2118
2111
|
}
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2112
|
+
/**
|
|
2113
|
+
* @returns number of not-yet rendered fibers cancelled
|
|
2114
|
+
*/
|
|
2115
|
+
function cancelFibers(fibers) {
|
|
2116
|
+
let result = 0;
|
|
2117
|
+
for (let fiber of fibers) {
|
|
2118
|
+
let node = fiber.node;
|
|
2119
|
+
fiber.render = throwOnRender;
|
|
2120
|
+
if (node.status === 0 /* STATUS.NEW */) {
|
|
2121
|
+
node.cancel();
|
|
2126
2122
|
}
|
|
2127
|
-
|
|
2128
|
-
|
|
2123
|
+
node.fiber = null;
|
|
2124
|
+
if (fiber.bdom) {
|
|
2125
|
+
// if fiber has been rendered, this means that the component props have
|
|
2126
|
+
// been updated. however, this fiber will not be patched to the dom, so
|
|
2127
|
+
// it could happen that the next render compare the current props with
|
|
2128
|
+
// the same props, and skip the render completely. With the next line,
|
|
2129
|
+
// we kindly request the component code to force a render, so it works as
|
|
2130
|
+
// expected.
|
|
2131
|
+
node.forceNextRender = true;
|
|
2129
2132
|
}
|
|
2130
|
-
|
|
2131
|
-
|
|
2133
|
+
else {
|
|
2134
|
+
result++;
|
|
2132
2135
|
}
|
|
2133
|
-
|
|
2136
|
+
result += cancelFibers(fiber.children);
|
|
2137
|
+
}
|
|
2138
|
+
return result;
|
|
2134
2139
|
}
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2140
|
+
class Fiber {
|
|
2141
|
+
node;
|
|
2142
|
+
bdom = null;
|
|
2143
|
+
root; // A Fiber that has been replaced by another has no root
|
|
2144
|
+
parent;
|
|
2145
|
+
children = [];
|
|
2146
|
+
appliedToDom = false;
|
|
2147
|
+
deep = false;
|
|
2148
|
+
childrenMap = {};
|
|
2149
|
+
constructor(node, parent) {
|
|
2150
|
+
this.node = node;
|
|
2151
|
+
this.parent = parent;
|
|
2152
|
+
if (parent) {
|
|
2153
|
+
this.deep = parent.deep;
|
|
2154
|
+
const root = parent.root;
|
|
2155
|
+
root.setCounter(root.counter + 1);
|
|
2156
|
+
this.root = root;
|
|
2157
|
+
parent.children.push(this);
|
|
2144
2158
|
}
|
|
2145
|
-
|
|
2146
|
-
|
|
2159
|
+
else {
|
|
2160
|
+
this.root = this;
|
|
2147
2161
|
}
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
let
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2162
|
+
}
|
|
2163
|
+
render() {
|
|
2164
|
+
// if some parent has a fiber => register in followup
|
|
2165
|
+
let prev = this.root.node;
|
|
2166
|
+
let scheduler = prev.app.scheduler;
|
|
2167
|
+
let current = prev.parent;
|
|
2168
|
+
while (current) {
|
|
2169
|
+
if (current.fiber) {
|
|
2170
|
+
let root = current.fiber.root;
|
|
2171
|
+
if (root.counter === 0 && prev.parentKey in current.fiber.childrenMap) {
|
|
2172
|
+
current = root.node;
|
|
2173
|
+
}
|
|
2174
|
+
else {
|
|
2175
|
+
scheduler.delayedRenders.push(this);
|
|
2176
|
+
return;
|
|
2177
|
+
}
|
|
2160
2178
|
}
|
|
2161
|
-
|
|
2179
|
+
prev = current;
|
|
2180
|
+
current = current.parent;
|
|
2162
2181
|
}
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2182
|
+
// there are no current rendering from above => we can render
|
|
2183
|
+
this._render();
|
|
2184
|
+
}
|
|
2185
|
+
_render() {
|
|
2186
|
+
const node = this.node;
|
|
2187
|
+
const root = this.root;
|
|
2188
|
+
if (root) {
|
|
2189
|
+
// todo: should use updateComputation somewhere else.
|
|
2190
|
+
const c = getCurrentComputation();
|
|
2191
|
+
removeSources(node.signalComputation);
|
|
2192
|
+
setComputation(node.signalComputation);
|
|
2193
|
+
try {
|
|
2194
|
+
this.bdom = true;
|
|
2195
|
+
this.bdom = node.renderFn();
|
|
2196
|
+
}
|
|
2197
|
+
catch (e) {
|
|
2198
|
+
node.app.handleError({ node, error: e });
|
|
2199
|
+
}
|
|
2200
|
+
setComputation(c);
|
|
2201
|
+
root.setCounter(root.counter - 1);
|
|
2173
2202
|
}
|
|
2174
|
-
}
|
|
2203
|
+
}
|
|
2175
2204
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
if (issues.length) {
|
|
2204
|
-
const issueStrings = JSON.stringify(issues, (key, value) => {
|
|
2205
|
-
if (typeof value === "function") {
|
|
2206
|
-
return value.name;
|
|
2205
|
+
class RootFiber extends Fiber {
|
|
2206
|
+
counter = 1;
|
|
2207
|
+
// only add stuff in this if they have registered some hooks
|
|
2208
|
+
willPatch = [];
|
|
2209
|
+
patched = [];
|
|
2210
|
+
mounted = [];
|
|
2211
|
+
// A fiber is typically locked when it is completing and the patch has not, or is being applied.
|
|
2212
|
+
// i.e.: render triggered in onWillUnmount or in willPatch will be delayed
|
|
2213
|
+
locked = false;
|
|
2214
|
+
complete() {
|
|
2215
|
+
const node = this.node;
|
|
2216
|
+
this.locked = true;
|
|
2217
|
+
let current = undefined;
|
|
2218
|
+
let mountedFibers = this.mounted;
|
|
2219
|
+
try {
|
|
2220
|
+
// Step 1: calling all willPatch lifecycle hooks
|
|
2221
|
+
for (current of this.willPatch) {
|
|
2222
|
+
// because of the asynchronous nature of the rendering, some parts of the
|
|
2223
|
+
// UI may have been rendered, then deleted in a followup rendering, and we
|
|
2224
|
+
// do not want to call onWillPatch in that case.
|
|
2225
|
+
let node = current.node;
|
|
2226
|
+
if (node.fiber === current) {
|
|
2227
|
+
const component = node.component;
|
|
2228
|
+
for (let cb of node.willPatch) {
|
|
2229
|
+
cb.call(component);
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2207
2232
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
},
|
|
2221
|
-
addIssue(issue) {
|
|
2222
|
-
issues.push({
|
|
2223
|
-
received: this.value,
|
|
2224
|
-
path: this.path,
|
|
2225
|
-
...issue,
|
|
2226
|
-
});
|
|
2227
|
-
},
|
|
2228
|
-
mergeIssues(newIssues) {
|
|
2229
|
-
issues.push(...newIssues);
|
|
2230
|
-
},
|
|
2231
|
-
validate(type) {
|
|
2232
|
-
type(this);
|
|
2233
|
-
if (!this.isValid && parent) {
|
|
2234
|
-
parent.issueDepth = this.issueDepth + 1;
|
|
2233
|
+
current = undefined;
|
|
2234
|
+
// Step 2: patching the dom
|
|
2235
|
+
node._patch();
|
|
2236
|
+
this.locked = false;
|
|
2237
|
+
// Step 4: calling all mounted lifecycle hooks
|
|
2238
|
+
while ((current = mountedFibers.pop())) {
|
|
2239
|
+
current = current;
|
|
2240
|
+
if (current.appliedToDom) {
|
|
2241
|
+
for (let cb of current.node.mounted) {
|
|
2242
|
+
cb();
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2235
2245
|
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
}
|
|
2245
|
-
function validateType(value, validation) {
|
|
2246
|
-
const issues = [];
|
|
2247
|
-
validation(createContext$1(issues, value, []));
|
|
2248
|
-
return issues;
|
|
2249
|
-
}
|
|
2250
|
-
|
|
2251
|
-
function validateObjectWithDefaults(schema, defaultValues) {
|
|
2252
|
-
const keys = Array.isArray(schema) ? schema : Object.keys(schema);
|
|
2253
|
-
const mandatoryDefaultedKeys = keys.filter((key) => !key.endsWith("?") && key in defaultValues);
|
|
2254
|
-
return (context) => {
|
|
2255
|
-
if (mandatoryDefaultedKeys.length) {
|
|
2256
|
-
context.addIssue({
|
|
2257
|
-
message: "props have default values on mandatory keys",
|
|
2258
|
-
keys: mandatoryDefaultedKeys,
|
|
2259
|
-
});
|
|
2260
|
-
}
|
|
2261
|
-
context.validate(types.object(schema));
|
|
2262
|
-
};
|
|
2263
|
-
}
|
|
2264
|
-
function props(type, defaults) {
|
|
2265
|
-
const { node, app, componentName } = getContext("component");
|
|
2266
|
-
function getProp(key) {
|
|
2267
|
-
if (node.props[key] === undefined && defaults) {
|
|
2268
|
-
return defaults[key];
|
|
2269
|
-
}
|
|
2270
|
-
return node.props[key];
|
|
2271
|
-
}
|
|
2272
|
-
const result = Object.create(null);
|
|
2273
|
-
function applyPropGetters(keys) {
|
|
2274
|
-
for (const key of keys) {
|
|
2275
|
-
Reflect.defineProperty(result, key, {
|
|
2276
|
-
enumerable: true,
|
|
2277
|
-
get: getProp.bind(null, key),
|
|
2278
|
-
});
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
if (type) {
|
|
2282
|
-
const keys = (Array.isArray(type) ? type : Object.keys(type)).map((key) => key.endsWith("?") ? key.slice(0, -1) : key);
|
|
2283
|
-
applyPropGetters(keys);
|
|
2284
|
-
if (app.dev) {
|
|
2285
|
-
const validation = defaults ? validateObjectWithDefaults(type, defaults) : types.object(type);
|
|
2286
|
-
assertType(node.props, validation, `Invalid component props (${componentName})`);
|
|
2287
|
-
node.willUpdateProps.push((np) => {
|
|
2288
|
-
assertType(np, validation, `Invalid component props (${componentName})`);
|
|
2289
|
-
});
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
else {
|
|
2293
|
-
applyPropGetters(Object.keys(node.props));
|
|
2294
|
-
node.willUpdateProps.push((np) => {
|
|
2295
|
-
for (let key in result) {
|
|
2296
|
-
Reflect.deleteProperty(result, key);
|
|
2246
|
+
// Step 5: calling all patched hooks
|
|
2247
|
+
let patchedFibers = this.patched;
|
|
2248
|
+
while ((current = patchedFibers.pop())) {
|
|
2249
|
+
current = current;
|
|
2250
|
+
if (current.appliedToDom) {
|
|
2251
|
+
for (let cb of current.node.patched) {
|
|
2252
|
+
cb();
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2297
2255
|
}
|
|
2298
|
-
applyPropGetters(Object.keys(np));
|
|
2299
|
-
});
|
|
2300
|
-
}
|
|
2301
|
-
return result;
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
const VText = text("").constructor;
|
|
2305
|
-
class VPortal extends VText {
|
|
2306
|
-
content;
|
|
2307
|
-
selector;
|
|
2308
|
-
target = null;
|
|
2309
|
-
constructor(selector, content) {
|
|
2310
|
-
super("");
|
|
2311
|
-
this.selector = selector;
|
|
2312
|
-
this.content = content;
|
|
2313
|
-
}
|
|
2314
|
-
mount(parent, anchor) {
|
|
2315
|
-
super.mount(parent, anchor);
|
|
2316
|
-
this.target = document.querySelector(this.selector);
|
|
2317
|
-
if (this.target) {
|
|
2318
|
-
this.content.mount(this.target, null);
|
|
2319
2256
|
}
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
this.
|
|
2331
|
-
|
|
2257
|
+
catch (e) {
|
|
2258
|
+
// if mountedFibers is not empty, this means that a crash occured while
|
|
2259
|
+
// calling the mounted hooks of some component. So, there may still be
|
|
2260
|
+
// some component that have been mounted, but for which the mounted hooks
|
|
2261
|
+
// have not been called. Here, we remove the willUnmount hooks for these
|
|
2262
|
+
// specific component to prevent a worse situation (willUnmount being
|
|
2263
|
+
// called even though mounted has not been called)
|
|
2264
|
+
for (let fiber of mountedFibers) {
|
|
2265
|
+
fiber.node.willUnmount = [];
|
|
2266
|
+
}
|
|
2267
|
+
this.locked = false;
|
|
2268
|
+
node.app.handleError({ fiber: current || this, error: e });
|
|
2332
2269
|
}
|
|
2333
2270
|
}
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
if (
|
|
2337
|
-
this.
|
|
2338
|
-
}
|
|
2339
|
-
else {
|
|
2340
|
-
this.content = other.content;
|
|
2341
|
-
this.content.mount(this.target, null);
|
|
2271
|
+
setCounter(newValue) {
|
|
2272
|
+
this.counter = newValue;
|
|
2273
|
+
if (newValue === 0) {
|
|
2274
|
+
this.node.app.scheduler.flush();
|
|
2342
2275
|
}
|
|
2343
2276
|
}
|
|
2344
2277
|
}
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
}
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2278
|
+
class MountFiber extends RootFiber {
|
|
2279
|
+
target;
|
|
2280
|
+
position;
|
|
2281
|
+
constructor(node, target, options = {}) {
|
|
2282
|
+
super(node, null);
|
|
2283
|
+
this.target = target;
|
|
2284
|
+
this.position = options.position || "last-child";
|
|
2285
|
+
}
|
|
2286
|
+
complete() {
|
|
2287
|
+
let current = this;
|
|
2288
|
+
try {
|
|
2289
|
+
const node = this.node;
|
|
2290
|
+
node.children = this.childrenMap;
|
|
2291
|
+
node.app.constructor.validateTarget(this.target);
|
|
2292
|
+
if (node.bdom) {
|
|
2293
|
+
// this is a complicated situation: if we mount a fiber with an existing
|
|
2294
|
+
// bdom, this means that this same fiber was already completed, mounted,
|
|
2295
|
+
// but a crash occurred in some mounted hook. Then, it was handled and
|
|
2296
|
+
// the new rendering is being applied.
|
|
2297
|
+
node.updateDom();
|
|
2298
|
+
}
|
|
2299
|
+
else {
|
|
2300
|
+
node.bdom = this.bdom;
|
|
2301
|
+
if (this.position === "last-child" || this.target.childNodes.length === 0) {
|
|
2302
|
+
mount$1(node.bdom, this.target);
|
|
2367
2303
|
}
|
|
2368
2304
|
else {
|
|
2369
|
-
|
|
2305
|
+
const firstChild = this.target.childNodes[0];
|
|
2306
|
+
mount$1(node.bdom, this.target, firstChild);
|
|
2370
2307
|
}
|
|
2371
2308
|
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
let current = node.fiber;
|
|
2390
|
-
if (current) {
|
|
2391
|
-
let root = current.root;
|
|
2392
|
-
// lock root fiber because canceling children fibers may destroy components,
|
|
2393
|
-
// which means any arbitrary code can be run in onWillDestroy, which may
|
|
2394
|
-
// trigger new renderings
|
|
2395
|
-
root.locked = true;
|
|
2396
|
-
root.setCounter(root.counter + 1 - cancelFibers(current.children));
|
|
2397
|
-
root.locked = false;
|
|
2398
|
-
current.children = [];
|
|
2399
|
-
current.childrenMap = {};
|
|
2400
|
-
current.bdom = null;
|
|
2401
|
-
if (fibersInError.has(current)) {
|
|
2402
|
-
fibersInError.delete(current);
|
|
2403
|
-
fibersInError.delete(root);
|
|
2404
|
-
current.appliedToDom = false;
|
|
2405
|
-
if (current instanceof RootFiber) {
|
|
2406
|
-
// it is possible that this fiber is a fiber that crashed while being
|
|
2407
|
-
// mounted, so the mounted list is possibly corrupted. We restore it to
|
|
2408
|
-
// its normal initial state (which is empty list or a list with a mount
|
|
2409
|
-
// fiber.
|
|
2410
|
-
current.mounted = current instanceof MountFiber ? [current] : [];
|
|
2411
|
-
}
|
|
2412
|
-
}
|
|
2413
|
-
return current;
|
|
2414
|
-
}
|
|
2415
|
-
const fiber = new RootFiber(node, null);
|
|
2416
|
-
if (node.willPatch.length) {
|
|
2417
|
-
fiber.willPatch.push(fiber);
|
|
2418
|
-
}
|
|
2419
|
-
if (node.patched.length) {
|
|
2420
|
-
fiber.patched.push(fiber);
|
|
2421
|
-
}
|
|
2422
|
-
return fiber;
|
|
2423
|
-
}
|
|
2424
|
-
function throwOnRender() {
|
|
2425
|
-
throw new OwlError("Attempted to render cancelled fiber");
|
|
2426
|
-
}
|
|
2427
|
-
/**
|
|
2428
|
-
* @returns number of not-yet rendered fibers cancelled
|
|
2429
|
-
*/
|
|
2430
|
-
function cancelFibers(fibers) {
|
|
2431
|
-
let result = 0;
|
|
2432
|
-
for (let fiber of fibers) {
|
|
2433
|
-
let node = fiber.node;
|
|
2434
|
-
fiber.render = throwOnRender;
|
|
2435
|
-
if (node.status === 0 /* STATUS.NEW */) {
|
|
2436
|
-
node.cancel();
|
|
2437
|
-
}
|
|
2438
|
-
node.fiber = null;
|
|
2439
|
-
if (fiber.bdom) {
|
|
2440
|
-
// if fiber has been rendered, this means that the component props have
|
|
2441
|
-
// been updated. however, this fiber will not be patched to the dom, so
|
|
2442
|
-
// it could happen that the next render compare the current props with
|
|
2443
|
-
// the same props, and skip the render completely. With the next line,
|
|
2444
|
-
// we kindly request the component code to force a render, so it works as
|
|
2445
|
-
// expected.
|
|
2446
|
-
node.forceNextRender = true;
|
|
2447
|
-
}
|
|
2448
|
-
else {
|
|
2449
|
-
result++;
|
|
2450
|
-
}
|
|
2451
|
-
result += cancelFibers(fiber.children);
|
|
2452
|
-
}
|
|
2453
|
-
return result;
|
|
2454
|
-
}
|
|
2455
|
-
class Fiber {
|
|
2456
|
-
node;
|
|
2457
|
-
bdom = null;
|
|
2458
|
-
root; // A Fiber that has been replaced by another has no root
|
|
2459
|
-
parent;
|
|
2460
|
-
children = [];
|
|
2461
|
-
appliedToDom = false;
|
|
2462
|
-
deep = false;
|
|
2463
|
-
childrenMap = {};
|
|
2464
|
-
constructor(node, parent) {
|
|
2465
|
-
this.node = node;
|
|
2466
|
-
this.parent = parent;
|
|
2467
|
-
if (parent) {
|
|
2468
|
-
this.deep = parent.deep;
|
|
2469
|
-
const root = parent.root;
|
|
2470
|
-
root.setCounter(root.counter + 1);
|
|
2471
|
-
this.root = root;
|
|
2472
|
-
parent.children.push(this);
|
|
2473
|
-
}
|
|
2474
|
-
else {
|
|
2475
|
-
this.root = this;
|
|
2476
|
-
}
|
|
2477
|
-
}
|
|
2478
|
-
render() {
|
|
2479
|
-
// if some parent has a fiber => register in followup
|
|
2480
|
-
let prev = this.root.node;
|
|
2481
|
-
let scheduler = prev.app.scheduler;
|
|
2482
|
-
let current = prev.parent;
|
|
2483
|
-
while (current) {
|
|
2484
|
-
if (current.fiber) {
|
|
2485
|
-
let root = current.fiber.root;
|
|
2486
|
-
if (root.counter === 0 && prev.parentKey in current.fiber.childrenMap) {
|
|
2487
|
-
current = root.node;
|
|
2488
|
-
}
|
|
2489
|
-
else {
|
|
2490
|
-
scheduler.delayedRenders.push(this);
|
|
2491
|
-
return;
|
|
2492
|
-
}
|
|
2493
|
-
}
|
|
2494
|
-
prev = current;
|
|
2495
|
-
current = current.parent;
|
|
2496
|
-
}
|
|
2497
|
-
// there are no current rendering from above => we can render
|
|
2498
|
-
this._render();
|
|
2499
|
-
}
|
|
2500
|
-
_render() {
|
|
2501
|
-
const node = this.node;
|
|
2502
|
-
const root = this.root;
|
|
2503
|
-
if (root) {
|
|
2504
|
-
// todo: should use updateComputation somewhere else.
|
|
2505
|
-
const c = getCurrentComputation();
|
|
2506
|
-
setComputation(node.signalComputation);
|
|
2507
|
-
try {
|
|
2508
|
-
this.bdom = true;
|
|
2509
|
-
this.bdom = node.renderFn();
|
|
2510
|
-
}
|
|
2511
|
-
catch (e) {
|
|
2512
|
-
node.app.handleError({ node, error: e });
|
|
2513
|
-
}
|
|
2514
|
-
setComputation(c);
|
|
2515
|
-
root.setCounter(root.counter - 1);
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
}
|
|
2519
|
-
class RootFiber extends Fiber {
|
|
2520
|
-
counter = 1;
|
|
2521
|
-
// only add stuff in this if they have registered some hooks
|
|
2522
|
-
willPatch = [];
|
|
2523
|
-
patched = [];
|
|
2524
|
-
mounted = [];
|
|
2525
|
-
// A fiber is typically locked when it is completing and the patch has not, or is being applied.
|
|
2526
|
-
// i.e.: render triggered in onWillUnmount or in willPatch will be delayed
|
|
2527
|
-
locked = false;
|
|
2528
|
-
complete() {
|
|
2529
|
-
const node = this.node;
|
|
2530
|
-
this.locked = true;
|
|
2531
|
-
let current = undefined;
|
|
2532
|
-
let mountedFibers = this.mounted;
|
|
2533
|
-
try {
|
|
2534
|
-
// Step 1: calling all willPatch lifecycle hooks
|
|
2535
|
-
for (current of this.willPatch) {
|
|
2536
|
-
// because of the asynchronous nature of the rendering, some parts of the
|
|
2537
|
-
// UI may have been rendered, then deleted in a followup rendering, and we
|
|
2538
|
-
// do not want to call onWillPatch in that case.
|
|
2539
|
-
let node = current.node;
|
|
2540
|
-
if (node.fiber === current) {
|
|
2541
|
-
const component = node.component;
|
|
2542
|
-
for (let cb of node.willPatch) {
|
|
2543
|
-
cb.call(component);
|
|
2544
|
-
}
|
|
2545
|
-
}
|
|
2546
|
-
}
|
|
2547
|
-
current = undefined;
|
|
2548
|
-
// Step 2: patching the dom
|
|
2549
|
-
node._patch();
|
|
2550
|
-
this.locked = false;
|
|
2551
|
-
// Step 4: calling all mounted lifecycle hooks
|
|
2552
|
-
while ((current = mountedFibers.pop())) {
|
|
2553
|
-
current = current;
|
|
2554
|
-
if (current.appliedToDom) {
|
|
2555
|
-
for (let cb of current.node.mounted) {
|
|
2556
|
-
cb();
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
// Step 5: calling all patched hooks
|
|
2561
|
-
let patchedFibers = this.patched;
|
|
2562
|
-
while ((current = patchedFibers.pop())) {
|
|
2563
|
-
current = current;
|
|
2564
|
-
if (current.appliedToDom) {
|
|
2565
|
-
for (let cb of current.node.patched) {
|
|
2566
|
-
cb();
|
|
2567
|
-
}
|
|
2568
|
-
}
|
|
2569
|
-
}
|
|
2570
|
-
}
|
|
2571
|
-
catch (e) {
|
|
2572
|
-
// if mountedFibers is not empty, this means that a crash occured while
|
|
2573
|
-
// calling the mounted hooks of some component. So, there may still be
|
|
2574
|
-
// some component that have been mounted, but for which the mounted hooks
|
|
2575
|
-
// have not been called. Here, we remove the willUnmount hooks for these
|
|
2576
|
-
// specific component to prevent a worse situation (willUnmount being
|
|
2577
|
-
// called even though mounted has not been called)
|
|
2578
|
-
for (let fiber of mountedFibers) {
|
|
2579
|
-
fiber.node.willUnmount = [];
|
|
2580
|
-
}
|
|
2581
|
-
this.locked = false;
|
|
2582
|
-
node.app.handleError({ fiber: current || this, error: e });
|
|
2583
|
-
}
|
|
2584
|
-
}
|
|
2585
|
-
setCounter(newValue) {
|
|
2586
|
-
this.counter = newValue;
|
|
2587
|
-
if (newValue === 0) {
|
|
2588
|
-
this.node.app.scheduler.flush();
|
|
2589
|
-
}
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
class MountFiber extends RootFiber {
|
|
2593
|
-
target;
|
|
2594
|
-
position;
|
|
2595
|
-
constructor(node, target, options = {}) {
|
|
2596
|
-
super(node, null);
|
|
2597
|
-
this.target = target;
|
|
2598
|
-
this.position = options.position || "last-child";
|
|
2599
|
-
}
|
|
2600
|
-
complete() {
|
|
2601
|
-
let current = this;
|
|
2602
|
-
try {
|
|
2603
|
-
const node = this.node;
|
|
2604
|
-
node.children = this.childrenMap;
|
|
2605
|
-
node.app.constructor.validateTarget(this.target);
|
|
2606
|
-
if (node.bdom) {
|
|
2607
|
-
// this is a complicated situation: if we mount a fiber with an existing
|
|
2608
|
-
// bdom, this means that this same fiber was already completed, mounted,
|
|
2609
|
-
// but a crash occurred in some mounted hook. Then, it was handled and
|
|
2610
|
-
// the new rendering is being applied.
|
|
2611
|
-
node.updateDom();
|
|
2612
|
-
}
|
|
2613
|
-
else {
|
|
2614
|
-
node.bdom = this.bdom;
|
|
2615
|
-
if (this.position === "last-child" || this.target.childNodes.length === 0) {
|
|
2616
|
-
mount$1(node.bdom, this.target);
|
|
2617
|
-
}
|
|
2618
|
-
else {
|
|
2619
|
-
const firstChild = this.target.childNodes[0];
|
|
2620
|
-
mount$1(node.bdom, this.target, firstChild);
|
|
2621
|
-
}
|
|
2622
|
-
}
|
|
2623
|
-
// unregistering the fiber before mounted since it can do another render
|
|
2624
|
-
// and that the current rendering is obviously completed
|
|
2625
|
-
node.fiber = null;
|
|
2626
|
-
node.status = 1 /* STATUS.MOUNTED */;
|
|
2627
|
-
this.appliedToDom = true;
|
|
2628
|
-
let mountedFibers = this.mounted;
|
|
2629
|
-
while ((current = mountedFibers.pop())) {
|
|
2630
|
-
if (current.appliedToDom) {
|
|
2631
|
-
for (let cb of current.node.mounted) {
|
|
2632
|
-
cb();
|
|
2633
|
-
}
|
|
2634
|
-
}
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
catch (e) {
|
|
2638
|
-
this.node.app.handleError({ fiber: current, error: e });
|
|
2639
|
-
}
|
|
2309
|
+
// unregistering the fiber before mounted since it can do another render
|
|
2310
|
+
// and that the current rendering is obviously completed
|
|
2311
|
+
node.fiber = null;
|
|
2312
|
+
node.status = 1 /* STATUS.MOUNTED */;
|
|
2313
|
+
this.appliedToDom = true;
|
|
2314
|
+
let mountedFibers = this.mounted;
|
|
2315
|
+
while ((current = mountedFibers.pop())) {
|
|
2316
|
+
if (current.appliedToDom) {
|
|
2317
|
+
for (let cb of current.node.mounted) {
|
|
2318
|
+
cb();
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
catch (e) {
|
|
2324
|
+
this.node.app.handleError({ fiber: current, error: e });
|
|
2325
|
+
}
|
|
2640
2326
|
}
|
|
2641
2327
|
}
|
|
2642
2328
|
|
|
@@ -2650,6 +2336,7 @@ class ComponentNode {
|
|
|
2650
2336
|
forceNextRender = false;
|
|
2651
2337
|
parentKey;
|
|
2652
2338
|
props;
|
|
2339
|
+
defaultProps = {};
|
|
2653
2340
|
renderFn;
|
|
2654
2341
|
parent;
|
|
2655
2342
|
children = Object.create(null);
|
|
@@ -2661,6 +2348,7 @@ class ComponentNode {
|
|
|
2661
2348
|
patched = [];
|
|
2662
2349
|
willDestroy = [];
|
|
2663
2350
|
signalComputation;
|
|
2351
|
+
computations = [];
|
|
2664
2352
|
pluginManager;
|
|
2665
2353
|
constructor(C, props, app, parent, parentKey) {
|
|
2666
2354
|
this.app = app;
|
|
@@ -2668,7 +2356,7 @@ class ComponentNode {
|
|
|
2668
2356
|
this.parentKey = parentKey;
|
|
2669
2357
|
this.pluginManager = parent ? parent.pluginManager : app.pluginManager;
|
|
2670
2358
|
this.signalComputation = createComputation(() => this.render(false), false, ComputationState.EXECUTED);
|
|
2671
|
-
this.props =
|
|
2359
|
+
this.props = props;
|
|
2672
2360
|
contextStack.push({
|
|
2673
2361
|
type: "component",
|
|
2674
2362
|
app,
|
|
@@ -2804,10 +2492,19 @@ class ComponentNode {
|
|
|
2804
2492
|
this.app.handleError({ error: e, node: this });
|
|
2805
2493
|
}
|
|
2806
2494
|
}
|
|
2495
|
+
for (const computation of this.computations) {
|
|
2496
|
+
disposeComputation(computation);
|
|
2497
|
+
}
|
|
2498
|
+
disposeComputation(this.signalComputation);
|
|
2807
2499
|
this.status = 3 /* STATUS.DESTROYED */;
|
|
2808
2500
|
}
|
|
2809
2501
|
async updateAndRender(props, parentFiber) {
|
|
2810
2502
|
props = Object.assign({}, props);
|
|
2503
|
+
for (const key in this.defaultProps) {
|
|
2504
|
+
if (props[key] === undefined) {
|
|
2505
|
+
props[key] = this.defaultProps[key];
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2811
2508
|
// update
|
|
2812
2509
|
const fiber = makeChildFiber(this, parentFiber);
|
|
2813
2510
|
this.fiber = fiber;
|
|
@@ -3436,7 +3133,14 @@ function createRef(ref) {
|
|
|
3436
3133
|
}
|
|
3437
3134
|
};
|
|
3438
3135
|
}
|
|
3439
|
-
function
|
|
3136
|
+
function callHandler(fn, ctx, ev) {
|
|
3137
|
+
if (typeof fn !== "function") {
|
|
3138
|
+
throw new OwlError(`Invalid handler expression: the \`t-on\` expression should evaluate to a function, but got '${typeof fn}'. ` +
|
|
3139
|
+
`Did you mean to use an arrow function? (e.g. \`t-on-click="() => expr"\`)`);
|
|
3140
|
+
}
|
|
3141
|
+
fn.call(ctx["this"], ev);
|
|
3142
|
+
}
|
|
3143
|
+
function modelExpr(value) {
|
|
3440
3144
|
if (typeof value !== "function" || typeof value.set !== "function") {
|
|
3441
3145
|
throw new OwlError(`Invalid t-model expression: expression should evaluate to a function with a 'set' method defined on it`);
|
|
3442
3146
|
}
|
|
@@ -3530,8 +3234,8 @@ const helpers = {
|
|
|
3530
3234
|
createRef,
|
|
3531
3235
|
modelExpr,
|
|
3532
3236
|
createComponent,
|
|
3533
|
-
Portal,
|
|
3534
3237
|
callTemplate,
|
|
3238
|
+
callHandler,
|
|
3535
3239
|
};
|
|
3536
3240
|
|
|
3537
3241
|
const bdom = { text, createBlock, list, multi, html, toggler, comment };
|
|
@@ -3639,7 +3343,6 @@ function xml(...args) {
|
|
|
3639
3343
|
return name;
|
|
3640
3344
|
}
|
|
3641
3345
|
xml.nextId = 1;
|
|
3642
|
-
TemplateSet.registerTemplate("__portal__", portalTemplate);
|
|
3643
3346
|
|
|
3644
3347
|
/**
|
|
3645
3348
|
* Owl QWeb Expression Parser
|
|
@@ -3851,11 +3554,18 @@ const isRightSeparator = (token) => token && (token.type === "RIGHT_BRACE" || to
|
|
|
3851
3554
|
* the arrow operator, then we add the current (or some previous tokens) token to
|
|
3852
3555
|
* the list of variables so it does not get replaced by a lookup in the context
|
|
3853
3556
|
*/
|
|
3854
|
-
|
|
3557
|
+
// Leading spaces are trimmed during tokenization, so they need to be added back for some values
|
|
3558
|
+
const paddedValues = new Map([["in ", " in "]]);
|
|
3559
|
+
/**
|
|
3560
|
+
* Processes a javascript expression: compiles variable lookups and detects
|
|
3561
|
+
* top-level arrow functions with their free variables, all in a single pass.
|
|
3562
|
+
*/
|
|
3563
|
+
function processExpr(expr) {
|
|
3855
3564
|
const localVars = new Set();
|
|
3856
3565
|
const tokens = tokenize(expr);
|
|
3857
3566
|
let i = 0;
|
|
3858
3567
|
let stack = []; // to track last opening (, [ or {
|
|
3568
|
+
let topLevelArrowIndex = -1;
|
|
3859
3569
|
while (i < tokens.length) {
|
|
3860
3570
|
let token = tokens[i];
|
|
3861
3571
|
let prevToken = tokens[i - 1];
|
|
@@ -3896,18 +3606,21 @@ function compileExprToArray(expr) {
|
|
|
3896
3606
|
token.value = token.replace((expr) => compileExpr(expr));
|
|
3897
3607
|
}
|
|
3898
3608
|
if (nextToken && nextToken.type === "OPERATOR" && nextToken.value === "=>") {
|
|
3609
|
+
if (stack.length === 0) {
|
|
3610
|
+
topLevelArrowIndex = i + 1;
|
|
3611
|
+
}
|
|
3899
3612
|
if (token.type === "RIGHT_PAREN") {
|
|
3900
3613
|
let j = i - 1;
|
|
3901
3614
|
while (j > 0 && tokens[j].type !== "LEFT_PAREN") {
|
|
3902
3615
|
if (tokens[j].type === "SYMBOL" && tokens[j].originalValue) {
|
|
3903
3616
|
tokens[j].value = tokens[j].originalValue;
|
|
3904
|
-
localVars.add(tokens[j].value);
|
|
3617
|
+
localVars.add(tokens[j].value);
|
|
3905
3618
|
}
|
|
3906
3619
|
j--;
|
|
3907
3620
|
}
|
|
3908
3621
|
}
|
|
3909
3622
|
else {
|
|
3910
|
-
localVars.add(token.value);
|
|
3623
|
+
localVars.add(token.value);
|
|
3911
3624
|
}
|
|
3912
3625
|
}
|
|
3913
3626
|
if (isVar) {
|
|
@@ -3928,14 +3641,24 @@ function compileExprToArray(expr) {
|
|
|
3928
3641
|
token.isLocal = true;
|
|
3929
3642
|
}
|
|
3930
3643
|
}
|
|
3931
|
-
|
|
3644
|
+
// Collect free variables from arrow function body
|
|
3645
|
+
let freeVariables = null;
|
|
3646
|
+
if (topLevelArrowIndex !== -1) {
|
|
3647
|
+
freeVariables = [];
|
|
3648
|
+
const seen = new Set();
|
|
3649
|
+
for (let i = topLevelArrowIndex + 1; i < tokens.length; i++) {
|
|
3650
|
+
const t = tokens[i];
|
|
3651
|
+
if (t.varName && !t.isLocal && t.varName !== "this" && !seen.has(t.varName)) {
|
|
3652
|
+
seen.add(t.varName);
|
|
3653
|
+
freeVariables.push(t.varName);
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
const compiled = tokens.map((t) => paddedValues.get(t.value) || t.value).join("");
|
|
3658
|
+
return { expr: compiled, freeVariables };
|
|
3932
3659
|
}
|
|
3933
|
-
// Leading spaces are trimmed during tokenization, so they need to be added back for some values
|
|
3934
|
-
const paddedValues = new Map([["in ", " in "]]);
|
|
3935
3660
|
function compileExpr(expr) {
|
|
3936
|
-
return
|
|
3937
|
-
.map((t) => paddedValues.get(t.value) || t.value)
|
|
3938
|
-
.join("");
|
|
3661
|
+
return processExpr(expr).expr;
|
|
3939
3662
|
}
|
|
3940
3663
|
const INTERP_REGEXP = /\{\{.*?\}\}|\#\{.*?\}/g;
|
|
3941
3664
|
function replaceDynamicParts(s, replacer) {
|
|
@@ -3954,8 +3677,11 @@ const zero = Symbol("zero");
|
|
|
3954
3677
|
const whitespaceRE = /\s+/g;
|
|
3955
3678
|
// using a non-html document so that <inner/outer>HTML serializes as XML instead
|
|
3956
3679
|
// of HTML (as we will parse it as xml later)
|
|
3957
|
-
|
|
3958
|
-
|
|
3680
|
+
let xmlDoc;
|
|
3681
|
+
if (typeof document !== "undefined") {
|
|
3682
|
+
xmlDoc = document.implementation.createDocument(null, null, null);
|
|
3683
|
+
}
|
|
3684
|
+
const MODS = new Set(["stop", "capture", "prevent", "self", "synthetic", "passive"]);
|
|
3959
3685
|
let nextDataIds = {};
|
|
3960
3686
|
function generateId(prefix = "") {
|
|
3961
3687
|
nextDataIds[prefix] = (nextDataIds[prefix] || 0) + 1;
|
|
@@ -4053,7 +3779,7 @@ class BlockDescription {
|
|
|
4053
3779
|
return t.innerHTML;
|
|
4054
3780
|
}
|
|
4055
3781
|
}
|
|
4056
|
-
function createContext(parentCtx, params) {
|
|
3782
|
+
function createContext$1(parentCtx, params) {
|
|
4057
3783
|
return Object.assign({
|
|
4058
3784
|
block: null,
|
|
4059
3785
|
index: 0,
|
|
@@ -4221,7 +3947,7 @@ class CodeGenerator {
|
|
|
4221
3947
|
const target = new CodeTarget(name, on);
|
|
4222
3948
|
this.targets.push(target);
|
|
4223
3949
|
this.target = target;
|
|
4224
|
-
this.compileAST(ast, createContext(ctx));
|
|
3950
|
+
this.compileAST(ast, createContext$1(ctx));
|
|
4225
3951
|
this.target = initialTarget;
|
|
4226
3952
|
return name;
|
|
4227
3953
|
}
|
|
@@ -4315,8 +4041,6 @@ class CodeGenerator {
|
|
|
4315
4041
|
return this.compileTTranslation(ast, ctx);
|
|
4316
4042
|
case 16 /* ASTType.TTranslationContext */:
|
|
4317
4043
|
return this.compileTTranslationContext(ast, ctx);
|
|
4318
|
-
case 17 /* ASTType.TPortal */:
|
|
4319
|
-
return this.compileTPortal(ast, ctx);
|
|
4320
4044
|
}
|
|
4321
4045
|
}
|
|
4322
4046
|
compileDebug(ast, ctx) {
|
|
@@ -4402,7 +4126,8 @@ class CodeGenerator {
|
|
|
4402
4126
|
hoistedExpr = `(ctx,${bareArrowMatch[1]})=>${rest}`;
|
|
4403
4127
|
}
|
|
4404
4128
|
else {
|
|
4405
|
-
|
|
4129
|
+
this.helpers.add("callHandler");
|
|
4130
|
+
hoistedExpr = `(ctx, ev) => callHandler(${compiled}, ctx, ev)`;
|
|
4406
4131
|
}
|
|
4407
4132
|
const id = generateId("hdlr_fn");
|
|
4408
4133
|
this.staticDefs.push({ id, expr: hoistedExpr });
|
|
@@ -4480,11 +4205,22 @@ class CodeGenerator {
|
|
|
4480
4205
|
// t-model
|
|
4481
4206
|
let tModelSelectedExpr;
|
|
4482
4207
|
if (ast.model) {
|
|
4483
|
-
const { hasDynamicChildren, expr, eventType, shouldNumberize, shouldTrim, targetAttr, specialInitTargetAttr, } = ast.model;
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4208
|
+
const { hasDynamicChildren, expr, eventType, shouldNumberize, shouldTrim, targetAttr, specialInitTargetAttr, isProxy, } = ast.model;
|
|
4209
|
+
let readExpr;
|
|
4210
|
+
let writeExpr;
|
|
4211
|
+
if (isProxy) {
|
|
4212
|
+
const expression = compileExpr(expr);
|
|
4213
|
+
readExpr = expression;
|
|
4214
|
+
writeExpr = (value) => `${expression} = ${value}`;
|
|
4215
|
+
}
|
|
4216
|
+
else {
|
|
4217
|
+
const exprId = generateId("expr");
|
|
4218
|
+
const expression = compileExpr(expr);
|
|
4219
|
+
this.helpers.add("modelExpr");
|
|
4220
|
+
this.define(exprId, `modelExpr(${expression})`);
|
|
4221
|
+
readExpr = `${exprId}()`;
|
|
4222
|
+
writeExpr = (value) => `${exprId}.set(${value})`;
|
|
4223
|
+
}
|
|
4488
4224
|
let idx;
|
|
4489
4225
|
if (specialInitTargetAttr) {
|
|
4490
4226
|
let targetExpr = targetAttr in attrs && `'${attrs[targetAttr]}'`;
|
|
@@ -4495,23 +4231,23 @@ class CodeGenerator {
|
|
|
4495
4231
|
targetExpr = compileExpr(dynamicTgExpr);
|
|
4496
4232
|
}
|
|
4497
4233
|
}
|
|
4498
|
-
idx = block.insertData(`${
|
|
4234
|
+
idx = block.insertData(`${readExpr} === ${targetExpr}`, "prop");
|
|
4499
4235
|
attrs[`block-property-${idx}`] = specialInitTargetAttr;
|
|
4500
4236
|
}
|
|
4501
4237
|
else if (hasDynamicChildren) {
|
|
4502
4238
|
const bValueId = generateId("bValue");
|
|
4503
4239
|
tModelSelectedExpr = `${bValueId}`;
|
|
4504
|
-
this.define(tModelSelectedExpr,
|
|
4240
|
+
this.define(tModelSelectedExpr, readExpr);
|
|
4505
4241
|
}
|
|
4506
4242
|
else {
|
|
4507
|
-
idx = block.insertData(
|
|
4243
|
+
idx = block.insertData(readExpr, "prop");
|
|
4508
4244
|
attrs[`block-property-${idx}`] = targetAttr;
|
|
4509
4245
|
}
|
|
4510
4246
|
this.helpers.add("toNumber");
|
|
4511
4247
|
let valueCode = `ev.target.${targetAttr}`;
|
|
4512
4248
|
valueCode = shouldTrim ? `${valueCode}.trim()` : valueCode;
|
|
4513
4249
|
valueCode = shouldNumberize ? `toNumber(${valueCode})` : valueCode;
|
|
4514
|
-
const handler = `[(ctx, ev) => { ${
|
|
4250
|
+
const handler = `[(ctx, ev) => { ${writeExpr(valueCode)}; }, ctx]`;
|
|
4515
4251
|
idx = block.insertData(handler, "hdlr");
|
|
4516
4252
|
attrs[`block-handler-${idx}`] = eventType;
|
|
4517
4253
|
}
|
|
@@ -4545,7 +4281,7 @@ class CodeGenerator {
|
|
|
4545
4281
|
const children = ast.content;
|
|
4546
4282
|
for (let i = 0; i < children.length; i++) {
|
|
4547
4283
|
const child = ast.content[i];
|
|
4548
|
-
const subCtx = createContext(ctx, {
|
|
4284
|
+
const subCtx = createContext$1(ctx, {
|
|
4549
4285
|
block,
|
|
4550
4286
|
index: block.childNumber,
|
|
4551
4287
|
forceNewBlock: false,
|
|
@@ -4601,7 +4337,7 @@ class CodeGenerator {
|
|
|
4601
4337
|
else if (ast.body) {
|
|
4602
4338
|
let bodyValue = null;
|
|
4603
4339
|
bodyValue = BlockDescription.nextBlockId;
|
|
4604
|
-
const subCtx = createContext(ctx);
|
|
4340
|
+
const subCtx = createContext$1(ctx);
|
|
4605
4341
|
this.compileAST({ type: 3 /* ASTType.Multi */, content: ast.body }, subCtx);
|
|
4606
4342
|
this.helpers.add("safeOutput");
|
|
4607
4343
|
blockStr = `safeOutput(${compileExpr(ast.expr)}, b${bodyValue})`;
|
|
@@ -4616,7 +4352,7 @@ class CodeGenerator {
|
|
|
4616
4352
|
compileTIfBranch(content, block, ctx) {
|
|
4617
4353
|
this.target.indentLevel++;
|
|
4618
4354
|
let childN = block.children.length;
|
|
4619
|
-
this.compileAST(content, createContext(ctx, { block, index: ctx.index }));
|
|
4355
|
+
this.compileAST(content, createContext$1(ctx, { block, index: ctx.index }));
|
|
4620
4356
|
if (block.children.length > childN) {
|
|
4621
4357
|
// we have some content => need to insert an anchor at correct index
|
|
4622
4358
|
this.insertAnchor(block, childN);
|
|
@@ -4712,7 +4448,7 @@ class CodeGenerator {
|
|
|
4712
4448
|
this.addLine(`if (keys${block.id}.has(String(key${this.target.loopLevel}))) { throw new OwlError(\`Got duplicate key in t-foreach: \${key${this.target.loopLevel}}\`)}`);
|
|
4713
4449
|
this.addLine(`keys${block.id}.add(String(key${this.target.loopLevel}));`);
|
|
4714
4450
|
}
|
|
4715
|
-
const subCtx = createContext(ctx, { block, index: loopVar });
|
|
4451
|
+
const subCtx = createContext$1(ctx, { block, index: loopVar });
|
|
4716
4452
|
this.compileAST(ast.body, subCtx);
|
|
4717
4453
|
this.target.indentLevel--;
|
|
4718
4454
|
this.target.loopLevel--;
|
|
@@ -4724,7 +4460,7 @@ class CodeGenerator {
|
|
|
4724
4460
|
compileTKey(ast, ctx) {
|
|
4725
4461
|
const tKeyExpr = generateId("tKey_");
|
|
4726
4462
|
this.define(tKeyExpr, compileExpr(ast.expr));
|
|
4727
|
-
ctx = createContext(ctx, {
|
|
4463
|
+
ctx = createContext$1(ctx, {
|
|
4728
4464
|
tKeyExpr,
|
|
4729
4465
|
block: ctx.block,
|
|
4730
4466
|
index: ctx.index,
|
|
@@ -4751,7 +4487,7 @@ class CodeGenerator {
|
|
|
4751
4487
|
for (let i = 0, l = ast.content.length; i < l; i++) {
|
|
4752
4488
|
const child = ast.content[i];
|
|
4753
4489
|
const forceNewBlock = !child.hasNoRepresentation;
|
|
4754
|
-
const subCtx = createContext(ctx, {
|
|
4490
|
+
const subCtx = createContext$1(ctx, {
|
|
4755
4491
|
block,
|
|
4756
4492
|
index,
|
|
4757
4493
|
forceNewBlock,
|
|
@@ -4804,12 +4540,11 @@ class CodeGenerator {
|
|
|
4804
4540
|
if (ast.context) {
|
|
4805
4541
|
const dynCtxVar = generateId("ctx");
|
|
4806
4542
|
this.addLine(`const ${dynCtxVar} = ${compileExpr(ast.context)};`);
|
|
4807
|
-
if (
|
|
4808
|
-
ctxExpr = `Object.assign({
|
|
4543
|
+
if (attrs.length) {
|
|
4544
|
+
ctxExpr = `Object.assign({this: ${dynCtxVar}}, ${ctxString})`;
|
|
4809
4545
|
}
|
|
4810
4546
|
else {
|
|
4811
|
-
|
|
4812
|
-
ctxExpr = `Object.assign({}, ${dynCtxVar}, ${thisCtx}${attrs.length ? ", " + ctxString : ""})`;
|
|
4547
|
+
ctxExpr = `{this: ${dynCtxVar}}`;
|
|
4813
4548
|
}
|
|
4814
4549
|
}
|
|
4815
4550
|
else {
|
|
@@ -4954,9 +4689,29 @@ class CodeGenerator {
|
|
|
4954
4689
|
let { block } = ctx;
|
|
4955
4690
|
// props
|
|
4956
4691
|
const hasSlotsProp = "slots" in (ast.props || {});
|
|
4957
|
-
const props =
|
|
4958
|
-
|
|
4959
|
-
|
|
4692
|
+
const props = [];
|
|
4693
|
+
const propList = [];
|
|
4694
|
+
for (let p in ast.props || {}) {
|
|
4695
|
+
let [name, suffix] = p.split(".");
|
|
4696
|
+
if (suffix) {
|
|
4697
|
+
// .alike, .bind, .translate — delegate to formatProp, no propList entry
|
|
4698
|
+
props.push(this.formatProp(p, ast.props[p], ast.propsTranslationCtx, ctx.translationCtx));
|
|
4699
|
+
continue;
|
|
4700
|
+
}
|
|
4701
|
+
const { expr: compiledValue, freeVariables } = processExpr(ast.props[p]);
|
|
4702
|
+
const propName = /^[a-z_]+$/i.test(name) ? name : `'${name}'`;
|
|
4703
|
+
props.push(`${propName}: ${compiledValue || undefined}`);
|
|
4704
|
+
if (freeVariables) {
|
|
4705
|
+
for (const varName of freeVariables) {
|
|
4706
|
+
const syntheticKey = `\x01${name}.${varName}`;
|
|
4707
|
+
propList.push(`"${syntheticKey}"`);
|
|
4708
|
+
props.push(`"${syntheticKey}": ctx['${varName}']`);
|
|
4709
|
+
}
|
|
4710
|
+
}
|
|
4711
|
+
else {
|
|
4712
|
+
propList.push(`"${name}"`);
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4960
4715
|
// slots
|
|
4961
4716
|
let slotDef = "";
|
|
4962
4717
|
if (ast.slots) {
|
|
@@ -5013,13 +4768,6 @@ class CodeGenerator {
|
|
|
5013
4768
|
keyArg = `${ctx.tKeyExpr} + ${keyArg}`;
|
|
5014
4769
|
}
|
|
5015
4770
|
let id = generateId("comp");
|
|
5016
|
-
const propList = [];
|
|
5017
|
-
for (let p in ast.props || {}) {
|
|
5018
|
-
let [name, suffix] = p.split(".");
|
|
5019
|
-
if (!suffix) {
|
|
5020
|
-
propList.push(`"${name}"`);
|
|
5021
|
-
}
|
|
5022
|
-
}
|
|
5023
4771
|
this.helpers.add("createComponent");
|
|
5024
4772
|
this.staticDefs.push({
|
|
5025
4773
|
id,
|
|
@@ -5124,26 +4872,6 @@ class CodeGenerator {
|
|
|
5124
4872
|
}
|
|
5125
4873
|
return null;
|
|
5126
4874
|
}
|
|
5127
|
-
compileTPortal(ast, ctx) {
|
|
5128
|
-
this.helpers.add("Portal");
|
|
5129
|
-
let { block } = ctx;
|
|
5130
|
-
const name = this.compileInNewTarget("slot", ast.content, ctx);
|
|
5131
|
-
let id = generateId("comp");
|
|
5132
|
-
this.helpers.add("createComponent");
|
|
5133
|
-
this.staticDefs.push({
|
|
5134
|
-
id,
|
|
5135
|
-
expr: `createComponent(app, null, false, true, false, false)`,
|
|
5136
|
-
});
|
|
5137
|
-
const target = compileExpr(ast.target);
|
|
5138
|
-
const key = this.generateComponentKey();
|
|
5139
|
-
const blockString = `${id}({target: ${target},slots: {'default': {__render: ${name}.bind(this), __ctx: ctx}}}, ${key}, node, ctx, Portal)`;
|
|
5140
|
-
if (block) {
|
|
5141
|
-
this.insertAnchor(block);
|
|
5142
|
-
}
|
|
5143
|
-
block = this.createBlock(block, "multi", ctx);
|
|
5144
|
-
this.insertBlock(blockString, block, { ...ctx, forceNewBlock: false });
|
|
5145
|
-
return block.varName;
|
|
5146
|
-
}
|
|
5147
4875
|
}
|
|
5148
4876
|
|
|
5149
4877
|
// -----------------------------------------------------------------------------
|
|
@@ -5179,7 +4907,6 @@ function parseNode(node, ctx) {
|
|
|
5179
4907
|
parseTDebugLog(node, ctx) ||
|
|
5180
4908
|
parseTForEach(node, ctx) ||
|
|
5181
4909
|
parseTIf(node, ctx) ||
|
|
5182
|
-
parseTPortal(node, ctx) ||
|
|
5183
4910
|
parseTTranslation(node, ctx) ||
|
|
5184
4911
|
parseTTranslationContext(node, ctx) ||
|
|
5185
4912
|
parseTCall(node, ctx) ||
|
|
@@ -5326,6 +5053,7 @@ function parseDOMNode(node, ctx) {
|
|
|
5326
5053
|
const hasTrimMod = attr.includes(".trim");
|
|
5327
5054
|
const hasLazyMod = hasTrimMod || attr.includes(".lazy");
|
|
5328
5055
|
const hasNumberMod = attr.includes(".number");
|
|
5056
|
+
const hasProxyMod = attr.includes(".proxy");
|
|
5329
5057
|
const eventType = isRadioInput ? "click" : isSelect || hasLazyMod ? "change" : "input";
|
|
5330
5058
|
model = {
|
|
5331
5059
|
expr: value,
|
|
@@ -5335,6 +5063,7 @@ function parseDOMNode(node, ctx) {
|
|
|
5335
5063
|
hasDynamicChildren: false,
|
|
5336
5064
|
shouldTrim: hasTrimMod,
|
|
5337
5065
|
shouldNumberize: hasNumberMod,
|
|
5066
|
+
isProxy: hasProxyMod,
|
|
5338
5067
|
};
|
|
5339
5068
|
if (isSelect) {
|
|
5340
5069
|
// don't pollute the original ctx
|
|
@@ -5806,694 +5535,1104 @@ function parseTTranslationContext(node, ctx) {
|
|
|
5806
5535
|
return wrapInTTranslationContextAST(result, translationCtx);
|
|
5807
5536
|
}
|
|
5808
5537
|
// -----------------------------------------------------------------------------
|
|
5809
|
-
//
|
|
5538
|
+
// helpers
|
|
5810
5539
|
// -----------------------------------------------------------------------------
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5540
|
+
/**
|
|
5541
|
+
* Parse all the child nodes of a given node and return a list of ast elements
|
|
5542
|
+
*/
|
|
5543
|
+
function parseChildren(node, ctx) {
|
|
5544
|
+
const children = [];
|
|
5545
|
+
for (let child of node.childNodes) {
|
|
5546
|
+
const childAst = parseNode(child, ctx);
|
|
5547
|
+
if (childAst) {
|
|
5548
|
+
if (childAst.type === 3 /* ASTType.Multi */) {
|
|
5549
|
+
children.push(...childAst.content);
|
|
5550
|
+
}
|
|
5551
|
+
else {
|
|
5552
|
+
children.push(childAst);
|
|
5553
|
+
}
|
|
5554
|
+
}
|
|
5814
5555
|
}
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5556
|
+
return children;
|
|
5557
|
+
}
|
|
5558
|
+
function makeASTMulti(children) {
|
|
5559
|
+
const ast = { type: 3 /* ASTType.Multi */, content: children };
|
|
5560
|
+
if (children.every((c) => c.hasNoRepresentation)) {
|
|
5561
|
+
ast.hasNoRepresentation = true;
|
|
5562
|
+
}
|
|
5563
|
+
return ast;
|
|
5564
|
+
}
|
|
5565
|
+
/**
|
|
5566
|
+
* Parse all the child nodes of a given node and return an ast if possible.
|
|
5567
|
+
* In the case there are multiple children, they are wrapped in a astmulti.
|
|
5568
|
+
*/
|
|
5569
|
+
function parseChildNodes(node, ctx) {
|
|
5570
|
+
const children = parseChildren(node, ctx);
|
|
5571
|
+
switch (children.length) {
|
|
5572
|
+
case 0:
|
|
5573
|
+
return null;
|
|
5574
|
+
case 1:
|
|
5575
|
+
return children[0];
|
|
5576
|
+
default:
|
|
5577
|
+
return makeASTMulti(children);
|
|
5578
|
+
}
|
|
5579
|
+
}
|
|
5580
|
+
/**
|
|
5581
|
+
* Normalizes the content of an Element so that t-if/t-elif/t-else directives
|
|
5582
|
+
* immediately follow one another (by removing empty text nodes or comments).
|
|
5583
|
+
* Throws an error when a conditional branching statement is malformed. This
|
|
5584
|
+
* function modifies the Element in place.
|
|
5585
|
+
*
|
|
5586
|
+
* @param el the element containing the tree that should be normalized
|
|
5587
|
+
*/
|
|
5588
|
+
function normalizeTIf(el) {
|
|
5589
|
+
let tbranch = el.querySelectorAll("[t-elif], [t-else]");
|
|
5590
|
+
for (let i = 0, ilen = tbranch.length; i < ilen; i++) {
|
|
5591
|
+
let node = tbranch[i];
|
|
5592
|
+
let prevElem = node.previousElementSibling;
|
|
5593
|
+
let pattr = (name) => prevElem.getAttribute(name);
|
|
5594
|
+
let nattr = (name) => +!!node.getAttribute(name);
|
|
5595
|
+
if (prevElem && (pattr("t-if") || pattr("t-elif"))) {
|
|
5596
|
+
if (pattr("t-foreach")) {
|
|
5597
|
+
throw new OwlError("t-if cannot stay at the same level as t-foreach when using t-elif or t-else");
|
|
5598
|
+
}
|
|
5599
|
+
if (["t-if", "t-elif", "t-else"].map(nattr).reduce(function (a, b) {
|
|
5600
|
+
return a + b;
|
|
5601
|
+
}) > 1) {
|
|
5602
|
+
throw new OwlError("Only one conditional branching directive is allowed per node");
|
|
5603
|
+
}
|
|
5604
|
+
// All text (with only spaces) and comment nodes (nodeType 8) between
|
|
5605
|
+
// branch nodes are removed
|
|
5606
|
+
let textNode;
|
|
5607
|
+
while ((textNode = node.previousSibling) !== prevElem) {
|
|
5608
|
+
if (textNode.nodeValue.trim().length && textNode.nodeType !== 8) {
|
|
5609
|
+
throw new OwlError("text is not allowed between branching directives");
|
|
5610
|
+
}
|
|
5611
|
+
textNode.remove();
|
|
5612
|
+
}
|
|
5613
|
+
}
|
|
5614
|
+
else {
|
|
5615
|
+
throw new OwlError("t-elif and t-else directives must be preceded by a t-if or t-elif directive");
|
|
5616
|
+
}
|
|
5617
|
+
}
|
|
5618
|
+
}
|
|
5619
|
+
/**
|
|
5620
|
+
* Normalizes the content of an Element so that t-out directives on components
|
|
5621
|
+
* are removed and instead places a <t t-out=""> as the default slot of the
|
|
5622
|
+
* component. Also throws if the component already has content. This function
|
|
5623
|
+
* modifies the Element in place.
|
|
5624
|
+
*
|
|
5625
|
+
* @param el the element containing the tree that should be normalized
|
|
5626
|
+
*/
|
|
5627
|
+
function normalizeTOut(el) {
|
|
5628
|
+
const elements = [...el.querySelectorAll(`[t-out]`)].filter((el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component"));
|
|
5629
|
+
for (const el of elements) {
|
|
5630
|
+
if (el.childNodes.length) {
|
|
5631
|
+
throw new OwlError(`Cannot have t-out on a component that already has content`);
|
|
5632
|
+
}
|
|
5633
|
+
const value = el.getAttribute("t-out");
|
|
5634
|
+
el.removeAttribute("t-out");
|
|
5635
|
+
const t = el.ownerDocument.createElement("t");
|
|
5636
|
+
if (value != null) {
|
|
5637
|
+
t.setAttribute("t-out", value);
|
|
5638
|
+
}
|
|
5639
|
+
el.appendChild(t);
|
|
5640
|
+
}
|
|
5641
|
+
}
|
|
5642
|
+
/**
|
|
5643
|
+
* Normalizes the tree inside a given element and do some preliminary validation
|
|
5644
|
+
* on it. This function modifies the Element in place.
|
|
5645
|
+
*
|
|
5646
|
+
* @param el the element containing the tree that should be normalized
|
|
5647
|
+
*/
|
|
5648
|
+
function normalizeXML(el) {
|
|
5649
|
+
normalizeTIf(el);
|
|
5650
|
+
normalizeTOut(el);
|
|
5651
|
+
}
|
|
5652
|
+
|
|
5653
|
+
function compile(template, options = {
|
|
5654
|
+
hasGlobalValues: false,
|
|
5655
|
+
}) {
|
|
5656
|
+
// parsing
|
|
5657
|
+
const ast = parse(template, options.customDirectives);
|
|
5658
|
+
// code generation
|
|
5659
|
+
const codeGenerator = new CodeGenerator(ast, options);
|
|
5660
|
+
const code = codeGenerator.generateCode();
|
|
5661
|
+
// template function
|
|
5662
|
+
try {
|
|
5663
|
+
return new Function("app, bdom, helpers", code);
|
|
5664
|
+
}
|
|
5665
|
+
catch (originalError) {
|
|
5666
|
+
const { name } = options;
|
|
5667
|
+
const nameStr = name ? `template "${name}"` : "anonymous template";
|
|
5668
|
+
const err = new OwlError(`Failed to compile ${nameStr}: ${originalError.message}\n\ngenerated code:\nfunction(app, bdom, helpers) {\n${code}\n}`);
|
|
5669
|
+
err.cause = originalError;
|
|
5670
|
+
throw err;
|
|
5671
|
+
}
|
|
5672
|
+
}
|
|
5673
|
+
|
|
5674
|
+
// do not modify manually. This file is generated by the release script.
|
|
5675
|
+
const version = "3.0.0-alpha.22";
|
|
5676
|
+
|
|
5677
|
+
function effect(fn) {
|
|
5678
|
+
const computation = createComputation(() => {
|
|
5679
|
+
// In case the cleanup read an atom.
|
|
5680
|
+
// todo: test it
|
|
5681
|
+
setComputation(undefined);
|
|
5682
|
+
unsubscribeEffect(computation);
|
|
5683
|
+
setComputation(computation);
|
|
5684
|
+
return fn();
|
|
5685
|
+
}, false);
|
|
5686
|
+
getCurrentComputation()?.observers.add(computation);
|
|
5687
|
+
updateComputation(computation);
|
|
5688
|
+
// Remove sources and unsubscribe
|
|
5689
|
+
return function cleanupEffect() {
|
|
5690
|
+
// In case the cleanup read an atom.
|
|
5691
|
+
// todo: test it
|
|
5692
|
+
const previousComputation = getCurrentComputation();
|
|
5693
|
+
setComputation(undefined);
|
|
5694
|
+
unsubscribeEffect(computation);
|
|
5695
|
+
setComputation(previousComputation);
|
|
5696
|
+
};
|
|
5697
|
+
}
|
|
5698
|
+
function unsubscribeEffect(effect) {
|
|
5699
|
+
removeSources(effect);
|
|
5700
|
+
cleanupEffect(effect);
|
|
5701
|
+
for (const childEffect of effect.observers) {
|
|
5702
|
+
// Consider it executed to avoid it's re-execution
|
|
5703
|
+
// todo: make a test for it
|
|
5704
|
+
childEffect.state = ComputationState.EXECUTED;
|
|
5705
|
+
removeSources(childEffect);
|
|
5706
|
+
unsubscribeEffect(childEffect);
|
|
5707
|
+
}
|
|
5708
|
+
effect.observers.clear();
|
|
5709
|
+
}
|
|
5710
|
+
function cleanupEffect(effect) {
|
|
5711
|
+
// the computation.value of an effect is a cleanup function
|
|
5712
|
+
const cleanupFn = effect.value;
|
|
5713
|
+
if (cleanupFn && typeof cleanupFn === "function") {
|
|
5714
|
+
cleanupFn();
|
|
5715
|
+
effect.value = undefined;
|
|
5716
|
+
}
|
|
5717
|
+
}
|
|
5718
|
+
|
|
5719
|
+
class Plugin {
|
|
5720
|
+
static _shadowId;
|
|
5721
|
+
static get id() {
|
|
5722
|
+
return this._shadowId ?? this.name;
|
|
5723
|
+
}
|
|
5724
|
+
static set id(shadowId) {
|
|
5725
|
+
this._shadowId = shadowId;
|
|
5726
|
+
}
|
|
5727
|
+
__owl__;
|
|
5728
|
+
constructor(manager) {
|
|
5729
|
+
this.__owl__ = manager;
|
|
5730
|
+
}
|
|
5731
|
+
setup() { }
|
|
5732
|
+
}
|
|
5733
|
+
class PluginManager {
|
|
5734
|
+
app;
|
|
5735
|
+
config;
|
|
5736
|
+
onDestroyCb = [];
|
|
5737
|
+
computations = [];
|
|
5738
|
+
plugins;
|
|
5739
|
+
status = 0 /* STATUS.NEW */;
|
|
5740
|
+
constructor(app, options = {}) {
|
|
5741
|
+
this.app = app;
|
|
5742
|
+
this.config = options.config ?? {};
|
|
5743
|
+
if (options.parent) {
|
|
5744
|
+
const parent = options.parent;
|
|
5745
|
+
parent.onDestroyCb.push(() => this.destroy());
|
|
5746
|
+
this.plugins = Object.create(parent.plugins);
|
|
5747
|
+
}
|
|
5748
|
+
else {
|
|
5749
|
+
this.plugins = {};
|
|
5750
|
+
}
|
|
5751
|
+
}
|
|
5752
|
+
destroy() {
|
|
5753
|
+
const cbs = this.onDestroyCb;
|
|
5754
|
+
while (cbs.length) {
|
|
5755
|
+
cbs.pop()();
|
|
5756
|
+
}
|
|
5757
|
+
for (const computation of this.computations) {
|
|
5758
|
+
disposeComputation(computation);
|
|
5759
|
+
}
|
|
5760
|
+
this.status = 3 /* STATUS.DESTROYED */;
|
|
5761
|
+
}
|
|
5762
|
+
getPluginById(id) {
|
|
5763
|
+
return this.plugins[id] || null;
|
|
5764
|
+
}
|
|
5765
|
+
getPlugin(pluginConstructor) {
|
|
5766
|
+
return this.getPluginById(pluginConstructor.id);
|
|
5767
|
+
}
|
|
5768
|
+
startPlugin(pluginConstructor) {
|
|
5769
|
+
if (!pluginConstructor.id) {
|
|
5770
|
+
throw new OwlError(`Plugin "${pluginConstructor.name}" has no id`);
|
|
5771
|
+
}
|
|
5772
|
+
if (this.plugins.hasOwnProperty(pluginConstructor.id)) {
|
|
5773
|
+
const existingPluginType = this.getPluginById(pluginConstructor.id).constructor;
|
|
5774
|
+
if (existingPluginType !== pluginConstructor) {
|
|
5775
|
+
throw new OwlError(`Trying to start a plugin with the same id as an other plugin (id: '${pluginConstructor.id}', existing plugin: '${existingPluginType.name}', starting plugin: '${pluginConstructor.name}')`);
|
|
5776
|
+
}
|
|
5777
|
+
return null;
|
|
5778
|
+
}
|
|
5779
|
+
const plugin = new pluginConstructor(this);
|
|
5780
|
+
this.plugins[pluginConstructor.id] = plugin;
|
|
5781
|
+
plugin.setup();
|
|
5782
|
+
return plugin;
|
|
5783
|
+
}
|
|
5784
|
+
startPlugins(pluginConstructors) {
|
|
5785
|
+
contextStack.push({
|
|
5786
|
+
type: "plugin",
|
|
5787
|
+
app: this.app,
|
|
5788
|
+
manager: this,
|
|
5789
|
+
get status() {
|
|
5790
|
+
return this.manager.status;
|
|
5791
|
+
},
|
|
5792
|
+
});
|
|
5793
|
+
try {
|
|
5794
|
+
for (const pluginConstructor of pluginConstructors) {
|
|
5795
|
+
this.startPlugin(pluginConstructor);
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
finally {
|
|
5799
|
+
contextStack.pop();
|
|
5800
|
+
}
|
|
5801
|
+
this.status = 1 /* STATUS.MOUNTED */;
|
|
5802
|
+
}
|
|
5803
|
+
}
|
|
5804
|
+
function startPlugins(manager, plugins) {
|
|
5805
|
+
if (Array.isArray(plugins)) {
|
|
5806
|
+
manager.startPlugins(plugins);
|
|
5807
|
+
}
|
|
5808
|
+
else {
|
|
5809
|
+
manager.onDestroyCb.push(effect(() => {
|
|
5810
|
+
const pluginItems = plugins.items();
|
|
5811
|
+
untrack(() => manager.startPlugins(pluginItems));
|
|
5812
|
+
}));
|
|
5813
|
+
}
|
|
5814
|
+
}
|
|
5815
|
+
|
|
5816
|
+
// -----------------------------------------------------------------------------
|
|
5817
|
+
// Scheduler
|
|
5818
|
+
// -----------------------------------------------------------------------------
|
|
5819
|
+
let requestAnimationFrame;
|
|
5820
|
+
if (typeof window !== "undefined") {
|
|
5821
|
+
requestAnimationFrame = window.requestAnimationFrame.bind(window);
|
|
5822
|
+
}
|
|
5823
|
+
class Scheduler {
|
|
5824
|
+
// capture the value of requestAnimationFrame as soon as possible, to avoid
|
|
5825
|
+
// interactions with other code, such as test frameworks that override them
|
|
5826
|
+
static requestAnimationFrame = requestAnimationFrame;
|
|
5827
|
+
tasks = new Set();
|
|
5828
|
+
requestAnimationFrame;
|
|
5829
|
+
frame = 0;
|
|
5830
|
+
delayedRenders = [];
|
|
5831
|
+
cancelledNodes = new Set();
|
|
5832
|
+
processing = false;
|
|
5833
|
+
constructor() {
|
|
5834
|
+
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
|
5835
|
+
}
|
|
5836
|
+
addFiber(fiber) {
|
|
5837
|
+
this.tasks.add(fiber.root);
|
|
5838
|
+
}
|
|
5839
|
+
scheduleDestroy(node) {
|
|
5840
|
+
this.cancelledNodes.add(node);
|
|
5841
|
+
if (this.frame === 0) {
|
|
5842
|
+
this.frame = this.requestAnimationFrame(() => this.processTasks());
|
|
5843
|
+
}
|
|
5844
|
+
}
|
|
5845
|
+
/**
|
|
5846
|
+
* Process all current tasks. This only applies to the fibers that are ready.
|
|
5847
|
+
* Other tasks are left unchanged.
|
|
5848
|
+
*/
|
|
5849
|
+
flush() {
|
|
5850
|
+
if (this.delayedRenders.length) {
|
|
5851
|
+
let renders = this.delayedRenders;
|
|
5852
|
+
this.delayedRenders = [];
|
|
5853
|
+
for (let f of renders) {
|
|
5854
|
+
if (f.root && f.node.status !== 3 /* STATUS.DESTROYED */ && f.node.fiber === f) {
|
|
5855
|
+
f.render();
|
|
5856
|
+
}
|
|
5857
|
+
}
|
|
5858
|
+
}
|
|
5859
|
+
if (this.frame === 0) {
|
|
5860
|
+
this.frame = this.requestAnimationFrame(() => this.processTasks());
|
|
5861
|
+
}
|
|
5862
|
+
}
|
|
5863
|
+
processTasks() {
|
|
5864
|
+
if (this.processing) {
|
|
5865
|
+
return;
|
|
5866
|
+
}
|
|
5867
|
+
this.processing = true;
|
|
5868
|
+
this.frame = 0;
|
|
5869
|
+
for (let node of this.cancelledNodes) {
|
|
5870
|
+
node._destroy();
|
|
5871
|
+
}
|
|
5872
|
+
this.cancelledNodes.clear();
|
|
5873
|
+
for (let task of this.tasks) {
|
|
5874
|
+
this.processFiber(task);
|
|
5875
|
+
}
|
|
5876
|
+
for (let task of this.tasks) {
|
|
5877
|
+
if (task.node.status === 3 /* STATUS.DESTROYED */) {
|
|
5878
|
+
this.tasks.delete(task);
|
|
5879
|
+
}
|
|
5880
|
+
}
|
|
5881
|
+
this.processing = false;
|
|
5882
|
+
}
|
|
5883
|
+
processFiber(fiber) {
|
|
5884
|
+
if (fiber.root !== fiber) {
|
|
5885
|
+
this.tasks.delete(fiber);
|
|
5886
|
+
return;
|
|
5887
|
+
}
|
|
5888
|
+
const hasError = fibersInError.has(fiber);
|
|
5889
|
+
if (hasError && fiber.counter !== 0) {
|
|
5890
|
+
this.tasks.delete(fiber);
|
|
5891
|
+
return;
|
|
5892
|
+
}
|
|
5893
|
+
if (fiber.node.status === 3 /* STATUS.DESTROYED */) {
|
|
5894
|
+
this.tasks.delete(fiber);
|
|
5895
|
+
return;
|
|
5896
|
+
}
|
|
5897
|
+
if (fiber.counter === 0) {
|
|
5898
|
+
if (!hasError) {
|
|
5899
|
+
fiber.complete();
|
|
5900
|
+
}
|
|
5901
|
+
// at this point, the fiber should have been applied to the DOM, so we can
|
|
5902
|
+
// remove it from the task list. If it is not the case, it means that there
|
|
5903
|
+
// was an error and an error handler triggered a new rendering that recycled
|
|
5904
|
+
// the fiber, so in that case, we actually want to keep the fiber around,
|
|
5905
|
+
// otherwise it will just be ignored.
|
|
5906
|
+
if (fiber.appliedToDom) {
|
|
5907
|
+
this.tasks.delete(fiber);
|
|
5908
|
+
}
|
|
5909
|
+
}
|
|
5910
|
+
}
|
|
5911
|
+
}
|
|
5912
|
+
|
|
5913
|
+
let hasBeenLogged = false;
|
|
5914
|
+
const apps = new Set();
|
|
5915
|
+
if (typeof window !== "undefined") {
|
|
5916
|
+
window.__OWL_DEVTOOLS__ ||= { apps, Fiber, RootFiber, toRaw, proxy };
|
|
5917
|
+
}
|
|
5918
|
+
class App extends TemplateSet {
|
|
5919
|
+
static validateTarget = validateTarget;
|
|
5920
|
+
static apps = apps;
|
|
5921
|
+
static version = version;
|
|
5922
|
+
name;
|
|
5923
|
+
scheduler = new Scheduler();
|
|
5924
|
+
roots = new Set();
|
|
5925
|
+
pluginManager;
|
|
5926
|
+
constructor(config = {}) {
|
|
5927
|
+
super(config);
|
|
5928
|
+
this.name = config.name || "";
|
|
5929
|
+
apps.add(this);
|
|
5930
|
+
this.pluginManager = new PluginManager(this, { config: config.config });
|
|
5931
|
+
if (config.plugins) {
|
|
5932
|
+
startPlugins(this.pluginManager, config.plugins);
|
|
5933
|
+
}
|
|
5934
|
+
if (config.test) {
|
|
5935
|
+
this.dev = true;
|
|
5936
|
+
}
|
|
5937
|
+
if (this.dev && !config.test && !hasBeenLogged) {
|
|
5938
|
+
console.info(`Owl is running in 'dev' mode.`);
|
|
5939
|
+
hasBeenLogged = true;
|
|
5940
|
+
}
|
|
5941
|
+
}
|
|
5942
|
+
createRoot(Root, config = {}) {
|
|
5943
|
+
const props = config.props || {};
|
|
5944
|
+
let resolve;
|
|
5945
|
+
let reject;
|
|
5946
|
+
const promise = new Promise((res, rej) => {
|
|
5947
|
+
resolve = res;
|
|
5948
|
+
reject = rej;
|
|
5949
|
+
});
|
|
5950
|
+
const restore = saveContext();
|
|
5951
|
+
let node;
|
|
5952
|
+
let error = null;
|
|
5953
|
+
try {
|
|
5954
|
+
node = new ComponentNode(Root, props, this, null, null);
|
|
5955
|
+
}
|
|
5956
|
+
catch (e) {
|
|
5957
|
+
error = e;
|
|
5958
|
+
reject(e);
|
|
5959
|
+
}
|
|
5960
|
+
finally {
|
|
5961
|
+
restore();
|
|
5962
|
+
}
|
|
5963
|
+
const root = {
|
|
5964
|
+
node: node,
|
|
5965
|
+
promise,
|
|
5966
|
+
mount: (target, options) => {
|
|
5967
|
+
if (error) {
|
|
5968
|
+
return promise;
|
|
5969
|
+
}
|
|
5970
|
+
App.validateTarget(target);
|
|
5971
|
+
this.mountNode(node, target, resolve, reject, options);
|
|
5972
|
+
return promise;
|
|
5973
|
+
},
|
|
5974
|
+
destroy: () => {
|
|
5975
|
+
this.roots.delete(root);
|
|
5976
|
+
node.destroy();
|
|
5977
|
+
this.scheduler.processTasks();
|
|
5978
|
+
},
|
|
5979
|
+
};
|
|
5980
|
+
this.roots.add(root);
|
|
5981
|
+
return root;
|
|
5982
|
+
}
|
|
5983
|
+
mountNode(node, target, resolve, reject, options) {
|
|
5984
|
+
// Manually add the last resort error handler on the node
|
|
5985
|
+
let handlers = nodeErrorHandlers.get(node);
|
|
5986
|
+
if (!handlers) {
|
|
5987
|
+
handlers = [];
|
|
5988
|
+
nodeErrorHandlers.set(node, handlers);
|
|
5989
|
+
}
|
|
5990
|
+
handlers.unshift((e, finalize) => {
|
|
5991
|
+
const finalError = finalize();
|
|
5992
|
+
reject(finalError);
|
|
5993
|
+
});
|
|
5994
|
+
// manually set a onMounted callback.
|
|
5995
|
+
// that way, we are independant from the current node.
|
|
5996
|
+
node.mounted.push(() => {
|
|
5997
|
+
resolve(node.component);
|
|
5998
|
+
handlers.shift();
|
|
5999
|
+
});
|
|
6000
|
+
node.mountComponent(target, options);
|
|
6001
|
+
}
|
|
6002
|
+
destroy() {
|
|
6003
|
+
for (let root of this.roots) {
|
|
6004
|
+
root.destroy();
|
|
6005
|
+
}
|
|
6006
|
+
this.pluginManager.destroy();
|
|
6007
|
+
this.scheduler.processTasks();
|
|
6008
|
+
apps.delete(this);
|
|
6009
|
+
}
|
|
6010
|
+
handleError(...args) {
|
|
6011
|
+
return handleError(...args);
|
|
6012
|
+
}
|
|
6013
|
+
}
|
|
6014
|
+
async function mount(C, target, config = {}) {
|
|
6015
|
+
const app = new App(config);
|
|
6016
|
+
const root = app.createRoot(C, config);
|
|
6017
|
+
return root.mount(target, config);
|
|
6018
|
+
}
|
|
6019
|
+
|
|
6020
|
+
const mainEventHandler = (data, ev, currentTarget) => {
|
|
6021
|
+
const { data: _data, modifiers } = filterOutModifiersFromData(data);
|
|
6022
|
+
data = _data;
|
|
6023
|
+
let stopped = false;
|
|
6024
|
+
if (modifiers.length) {
|
|
6025
|
+
let selfMode = false;
|
|
6026
|
+
const isSelf = ev.target === currentTarget;
|
|
6027
|
+
for (const mod of modifiers) {
|
|
6028
|
+
switch (mod) {
|
|
6029
|
+
case "self":
|
|
6030
|
+
selfMode = true;
|
|
6031
|
+
if (isSelf) {
|
|
6032
|
+
continue;
|
|
6033
|
+
}
|
|
6034
|
+
else {
|
|
6035
|
+
return stopped;
|
|
6036
|
+
}
|
|
6037
|
+
case "prevent":
|
|
6038
|
+
if ((selfMode && isSelf) || !selfMode)
|
|
6039
|
+
ev.preventDefault();
|
|
6040
|
+
continue;
|
|
6041
|
+
case "stop":
|
|
6042
|
+
if ((selfMode && isSelf) || !selfMode)
|
|
6043
|
+
ev.stopPropagation();
|
|
6044
|
+
stopped = true;
|
|
6045
|
+
continue;
|
|
6046
|
+
}
|
|
6047
|
+
}
|
|
6048
|
+
}
|
|
6049
|
+
// If handler is empty, the array slot 0 will also be empty, and data will not have the property 0
|
|
6050
|
+
// We check this rather than data[0] being truthy (or typeof function) so that it crashes
|
|
6051
|
+
// as expected when there is a handler expression that evaluates to a falsy value
|
|
6052
|
+
if (Object.hasOwnProperty.call(data, 0)) {
|
|
6053
|
+
const handler = data[0];
|
|
6054
|
+
if (typeof handler !== "function") {
|
|
6055
|
+
throw new OwlError(`Invalid handler (expected a function, received: '${handler}')`);
|
|
6056
|
+
}
|
|
6057
|
+
let node = data[1] ? data[1].__owl__ : null;
|
|
6058
|
+
if (node ? node.status === 1 /* STATUS.MOUNTED */ : true) {
|
|
6059
|
+
handler(data[1], ev);
|
|
6060
|
+
}
|
|
5823
6061
|
}
|
|
5824
|
-
return
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
content,
|
|
5828
|
-
};
|
|
5829
|
-
}
|
|
6062
|
+
return stopped;
|
|
6063
|
+
};
|
|
6064
|
+
|
|
5830
6065
|
// -----------------------------------------------------------------------------
|
|
5831
|
-
//
|
|
6066
|
+
// hooks
|
|
5832
6067
|
// -----------------------------------------------------------------------------
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
if (childAst) {
|
|
5841
|
-
if (childAst.type === 3 /* ASTType.Multi */) {
|
|
5842
|
-
children.push(...childAst.content);
|
|
5843
|
-
}
|
|
5844
|
-
else {
|
|
5845
|
-
children.push(childAst);
|
|
5846
|
-
}
|
|
5847
|
-
}
|
|
6068
|
+
function decorate(node, f, hookName) {
|
|
6069
|
+
const result = f.bind(node.component);
|
|
6070
|
+
if (node.app.dev) {
|
|
6071
|
+
const suffix = f.name ? ` <${f.name}>` : "";
|
|
6072
|
+
Reflect.defineProperty(result, "name", {
|
|
6073
|
+
value: hookName + suffix,
|
|
6074
|
+
});
|
|
5848
6075
|
}
|
|
5849
|
-
return
|
|
6076
|
+
return result;
|
|
5850
6077
|
}
|
|
5851
|
-
function
|
|
5852
|
-
const
|
|
5853
|
-
|
|
5854
|
-
|
|
6078
|
+
function onWillStart(fn) {
|
|
6079
|
+
const { node } = getContext("component");
|
|
6080
|
+
node.willStart.push(decorate(node, fn, "onWillStart"));
|
|
6081
|
+
}
|
|
6082
|
+
function onWillUpdateProps(fn) {
|
|
6083
|
+
const { node } = getContext("component");
|
|
6084
|
+
node.willUpdateProps.push(decorate(node, fn, "onWillUpdateProps"));
|
|
6085
|
+
}
|
|
6086
|
+
function onMounted(fn) {
|
|
6087
|
+
const { node } = getContext("component");
|
|
6088
|
+
node.mounted.push(decorate(node, fn, "onMounted"));
|
|
6089
|
+
}
|
|
6090
|
+
function onWillPatch(fn) {
|
|
6091
|
+
const { node } = getContext("component");
|
|
6092
|
+
node.willPatch.unshift(decorate(node, fn, "onWillPatch"));
|
|
6093
|
+
}
|
|
6094
|
+
function onPatched(fn) {
|
|
6095
|
+
const { node } = getContext("component");
|
|
6096
|
+
node.patched.push(decorate(node, fn, "onPatched"));
|
|
6097
|
+
}
|
|
6098
|
+
function onWillUnmount(fn) {
|
|
6099
|
+
const { node } = getContext("component");
|
|
6100
|
+
node.willUnmount.unshift(decorate(node, fn, "onWillUnmount"));
|
|
6101
|
+
}
|
|
6102
|
+
function onWillDestroy(fn) {
|
|
6103
|
+
const context = getContext();
|
|
6104
|
+
if (context.type === "component") {
|
|
6105
|
+
context.node.willDestroy.unshift(decorate(context.node, fn, "onWillDestroy"));
|
|
6106
|
+
}
|
|
6107
|
+
else {
|
|
6108
|
+
context.manager.onDestroyCb.push(fn);
|
|
5855
6109
|
}
|
|
5856
|
-
return ast;
|
|
5857
6110
|
}
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
switch (children.length) {
|
|
5865
|
-
case 0:
|
|
5866
|
-
return null;
|
|
5867
|
-
case 1:
|
|
5868
|
-
return children[0];
|
|
5869
|
-
default:
|
|
5870
|
-
return makeASTMulti(children);
|
|
6111
|
+
function onError(callback) {
|
|
6112
|
+
const { node } = getContext("component");
|
|
6113
|
+
let handlers = nodeErrorHandlers.get(node);
|
|
6114
|
+
if (!handlers) {
|
|
6115
|
+
handlers = [];
|
|
6116
|
+
nodeErrorHandlers.set(node, handlers);
|
|
5871
6117
|
}
|
|
6118
|
+
handlers.push(callback.bind(node.component));
|
|
5872
6119
|
}
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
* @param el the element containing the tree that should be normalized
|
|
5880
|
-
*/
|
|
5881
|
-
function normalizeTIf(el) {
|
|
5882
|
-
let tbranch = el.querySelectorAll("[t-elif], [t-else]");
|
|
5883
|
-
for (let i = 0, ilen = tbranch.length; i < ilen; i++) {
|
|
5884
|
-
let node = tbranch[i];
|
|
5885
|
-
let prevElem = node.previousElementSibling;
|
|
5886
|
-
let pattr = (name) => prevElem.getAttribute(name);
|
|
5887
|
-
let nattr = (name) => +!!node.getAttribute(name);
|
|
5888
|
-
if (prevElem && (pattr("t-if") || pattr("t-elif"))) {
|
|
5889
|
-
if (pattr("t-foreach")) {
|
|
5890
|
-
throw new OwlError("t-if cannot stay at the same level as t-foreach when using t-elif or t-else");
|
|
5891
|
-
}
|
|
5892
|
-
if (["t-if", "t-elif", "t-else"].map(nattr).reduce(function (a, b) {
|
|
5893
|
-
return a + b;
|
|
5894
|
-
}) > 1) {
|
|
5895
|
-
throw new OwlError("Only one conditional branching directive is allowed per node");
|
|
5896
|
-
}
|
|
5897
|
-
// All text (with only spaces) and comment nodes (nodeType 8) between
|
|
5898
|
-
// branch nodes are removed
|
|
5899
|
-
let textNode;
|
|
5900
|
-
while ((textNode = node.previousSibling) !== prevElem) {
|
|
5901
|
-
if (textNode.nodeValue.trim().length && textNode.nodeType !== 8) {
|
|
5902
|
-
throw new OwlError("text is not allowed between branching directives");
|
|
5903
|
-
}
|
|
5904
|
-
textNode.remove();
|
|
5905
|
-
}
|
|
6120
|
+
|
|
6121
|
+
function computed(getter, options = {}) {
|
|
6122
|
+
const computation = createComputation(() => {
|
|
6123
|
+
const newValue = getter();
|
|
6124
|
+
if (!Object.is(computation.value, newValue)) {
|
|
6125
|
+
onWriteAtom(computation);
|
|
5906
6126
|
}
|
|
5907
|
-
|
|
5908
|
-
|
|
6127
|
+
return newValue;
|
|
6128
|
+
}, true);
|
|
6129
|
+
function readComputed() {
|
|
6130
|
+
if (computation.state !== ComputationState.EXECUTED) {
|
|
6131
|
+
updateComputation(computation);
|
|
5909
6132
|
}
|
|
6133
|
+
onReadAtom(computation);
|
|
6134
|
+
return computation.value;
|
|
5910
6135
|
}
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
*
|
|
5918
|
-
* @param el the element containing the tree that should be normalized
|
|
5919
|
-
*/
|
|
5920
|
-
function normalizeTOut(el) {
|
|
5921
|
-
const elements = [...el.querySelectorAll(`[t-out]`)].filter((el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component"));
|
|
5922
|
-
for (const el of elements) {
|
|
5923
|
-
if (el.childNodes.length) {
|
|
5924
|
-
throw new OwlError(`Cannot have t-out on a component that already has content`);
|
|
6136
|
+
readComputed[atomSymbol] = computation;
|
|
6137
|
+
readComputed.set = options.set ?? (() => { });
|
|
6138
|
+
const context = contextStack.at(-1);
|
|
6139
|
+
if (context) {
|
|
6140
|
+
if (context.type === "component") {
|
|
6141
|
+
context.node.computations.push(computation);
|
|
5925
6142
|
}
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
const t = el.ownerDocument.createElement("t");
|
|
5929
|
-
if (value != null) {
|
|
5930
|
-
t.setAttribute("t-out", value);
|
|
6143
|
+
else if (context.type === "plugin") {
|
|
6144
|
+
context.manager.computations.push(computation);
|
|
5931
6145
|
}
|
|
5932
|
-
el.appendChild(t);
|
|
5933
|
-
}
|
|
5934
|
-
}
|
|
5935
|
-
/**
|
|
5936
|
-
* Normalizes the tree inside a given element and do some preliminary validation
|
|
5937
|
-
* on it. This function modifies the Element in place.
|
|
5938
|
-
*
|
|
5939
|
-
* @param el the element containing the tree that should be normalized
|
|
5940
|
-
*/
|
|
5941
|
-
function normalizeXML(el) {
|
|
5942
|
-
normalizeTIf(el);
|
|
5943
|
-
normalizeTOut(el);
|
|
5944
|
-
}
|
|
5945
|
-
|
|
5946
|
-
function compile(template, options = {
|
|
5947
|
-
hasGlobalValues: false,
|
|
5948
|
-
}) {
|
|
5949
|
-
// parsing
|
|
5950
|
-
const ast = parse(template, options.customDirectives);
|
|
5951
|
-
// code generation
|
|
5952
|
-
const codeGenerator = new CodeGenerator(ast, options);
|
|
5953
|
-
const code = codeGenerator.generateCode();
|
|
5954
|
-
// template function
|
|
5955
|
-
try {
|
|
5956
|
-
return new Function("app, bdom, helpers", code);
|
|
5957
|
-
}
|
|
5958
|
-
catch (originalError) {
|
|
5959
|
-
const { name } = options;
|
|
5960
|
-
const nameStr = name ? `template "${name}"` : "anonymous template";
|
|
5961
|
-
const err = new OwlError(`Failed to compile ${nameStr}: ${originalError.message}\n\ngenerated code:\nfunction(app, bdom, helpers) {\n${code}\n}`);
|
|
5962
|
-
err.cause = originalError;
|
|
5963
|
-
throw err;
|
|
5964
6146
|
}
|
|
6147
|
+
return readComputed;
|
|
5965
6148
|
}
|
|
5966
6149
|
|
|
5967
|
-
|
|
5968
|
-
const
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
setComputation(undefined);
|
|
5987
|
-
unsubscribeEffect(computation);
|
|
5988
|
-
setComputation(previousComputation);
|
|
6150
|
+
function buildSignal(value, set) {
|
|
6151
|
+
const atom = {
|
|
6152
|
+
type: "signal",
|
|
6153
|
+
value,
|
|
6154
|
+
observers: new Set(),
|
|
6155
|
+
};
|
|
6156
|
+
let readValue = set(atom);
|
|
6157
|
+
const readSignal = () => {
|
|
6158
|
+
onReadAtom(atom);
|
|
6159
|
+
return readValue;
|
|
6160
|
+
};
|
|
6161
|
+
readSignal[atomSymbol] = atom;
|
|
6162
|
+
readSignal.set = function writeSignal(newValue) {
|
|
6163
|
+
if (Object.is(atom.value, newValue)) {
|
|
6164
|
+
return;
|
|
6165
|
+
}
|
|
6166
|
+
atom.value = newValue;
|
|
6167
|
+
readValue = set(atom);
|
|
6168
|
+
onWriteAtom(atom);
|
|
5989
6169
|
};
|
|
6170
|
+
return readSignal;
|
|
5990
6171
|
}
|
|
5991
|
-
function
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
for (const childEffect of effect.observers) {
|
|
5995
|
-
// Consider it executed to avoid it's re-execution
|
|
5996
|
-
// todo: make a test for it
|
|
5997
|
-
childEffect.state = ComputationState.EXECUTED;
|
|
5998
|
-
removeSources(childEffect);
|
|
5999
|
-
unsubscribeEffect(childEffect);
|
|
6172
|
+
function invalidateSignal(signal) {
|
|
6173
|
+
if (typeof signal !== "function" || signal[atomSymbol]?.type !== "signal") {
|
|
6174
|
+
throw new OwlError(`Value is not a signal (${signal})`);
|
|
6000
6175
|
}
|
|
6001
|
-
|
|
6176
|
+
onWriteAtom(signal[atomSymbol]);
|
|
6177
|
+
}
|
|
6178
|
+
function signalArray(initialValue) {
|
|
6179
|
+
return buildSignal(initialValue, (atom) => proxifyTarget(atom.value, atom));
|
|
6180
|
+
}
|
|
6181
|
+
function signalObject(initialValue) {
|
|
6182
|
+
return buildSignal(initialValue, (atom) => proxifyTarget(atom.value, atom));
|
|
6183
|
+
}
|
|
6184
|
+
function signalMap(initialValue) {
|
|
6185
|
+
return buildSignal(initialValue, (atom) => proxifyTarget(atom.value, atom));
|
|
6002
6186
|
}
|
|
6003
|
-
function
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
effect.value = undefined;
|
|
6009
|
-
}
|
|
6187
|
+
function signalSet(initialValue) {
|
|
6188
|
+
return buildSignal(initialValue, (atom) => proxifyTarget(atom.value, atom));
|
|
6189
|
+
}
|
|
6190
|
+
function signal(value) {
|
|
6191
|
+
return buildSignal(value, (atom) => atom.value);
|
|
6010
6192
|
}
|
|
6193
|
+
signal.invalidate = invalidateSignal;
|
|
6194
|
+
signal.Array = signalArray;
|
|
6195
|
+
signal.Map = signalMap;
|
|
6196
|
+
signal.Object = signalObject;
|
|
6197
|
+
signal.Set = signalSet;
|
|
6011
6198
|
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
this.__owl__ = manager;
|
|
6199
|
+
function assertType(value, validation, errorMessage = "Value does not match the type") {
|
|
6200
|
+
const issues = validateType(value, validation);
|
|
6201
|
+
if (issues.length) {
|
|
6202
|
+
const issueStrings = JSON.stringify(issues, (key, value) => {
|
|
6203
|
+
if (typeof value === "function") {
|
|
6204
|
+
return value.name;
|
|
6205
|
+
}
|
|
6206
|
+
return value;
|
|
6207
|
+
}, 2);
|
|
6208
|
+
throw new OwlError(`${errorMessage}\n${issueStrings}`);
|
|
6023
6209
|
}
|
|
6024
|
-
setup() { }
|
|
6025
6210
|
}
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6211
|
+
function createContext(issues, value, path, parent) {
|
|
6212
|
+
return {
|
|
6213
|
+
issueDepth: 0,
|
|
6214
|
+
path,
|
|
6215
|
+
value,
|
|
6216
|
+
get isValid() {
|
|
6217
|
+
return !issues.length;
|
|
6218
|
+
},
|
|
6219
|
+
addIssue(issue) {
|
|
6220
|
+
issues.push({
|
|
6221
|
+
received: this.value,
|
|
6222
|
+
path: this.path,
|
|
6223
|
+
...issue,
|
|
6224
|
+
});
|
|
6225
|
+
},
|
|
6226
|
+
mergeIssues(newIssues) {
|
|
6227
|
+
issues.push(...newIssues);
|
|
6228
|
+
},
|
|
6229
|
+
validate(type) {
|
|
6230
|
+
type(this);
|
|
6231
|
+
if (!this.isValid && parent) {
|
|
6232
|
+
parent.issueDepth = this.issueDepth + 1;
|
|
6233
|
+
}
|
|
6234
|
+
},
|
|
6235
|
+
withIssues(issues) {
|
|
6236
|
+
return createContext(issues, this.value, this.path, this);
|
|
6237
|
+
},
|
|
6238
|
+
withKey(key) {
|
|
6239
|
+
return createContext(issues, this.value[key], this.path.concat(key), this);
|
|
6240
|
+
},
|
|
6241
|
+
};
|
|
6242
|
+
}
|
|
6243
|
+
function validateType(value, validation) {
|
|
6244
|
+
const issues = [];
|
|
6245
|
+
validation(createContext(issues, value, []));
|
|
6246
|
+
return issues;
|
|
6247
|
+
}
|
|
6248
|
+
|
|
6249
|
+
class Resource {
|
|
6250
|
+
_items = signal.Array([]);
|
|
6251
|
+
_name;
|
|
6252
|
+
_validation;
|
|
6253
|
+
constructor(options = {}) {
|
|
6254
|
+
this._name = options.name;
|
|
6255
|
+
this._validation = options.validation;
|
|
6043
6256
|
}
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6257
|
+
items = computed(() => {
|
|
6258
|
+
return this._items()
|
|
6259
|
+
.sort((el1, el2) => el1[0] - el2[0])
|
|
6260
|
+
.map((elem) => elem[1]);
|
|
6261
|
+
});
|
|
6262
|
+
add(item, options = {}) {
|
|
6263
|
+
if (this._validation) {
|
|
6264
|
+
const info = this._name ? ` (resource '${this._name}')` : "";
|
|
6265
|
+
assertType(item, this._validation, `Resource item does not match the type${info}`);
|
|
6048
6266
|
}
|
|
6049
|
-
this.
|
|
6050
|
-
|
|
6051
|
-
getPluginById(id) {
|
|
6052
|
-
return this.plugins[id] || null;
|
|
6053
|
-
}
|
|
6054
|
-
getPlugin(pluginConstructor) {
|
|
6055
|
-
return this.getPluginById(pluginConstructor.id);
|
|
6267
|
+
this._items().push([options.sequence ?? 50, item]);
|
|
6268
|
+
return this;
|
|
6056
6269
|
}
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
if (this.plugins.hasOwnProperty(pluginConstructor.id)) {
|
|
6062
|
-
const existingPluginType = this.getPluginById(pluginConstructor.id).constructor;
|
|
6063
|
-
if (existingPluginType !== pluginConstructor) {
|
|
6064
|
-
throw new OwlError(`Trying to start a plugin with the same id as an other plugin (id: '${pluginConstructor.id}', existing plugin: '${existingPluginType.name}', starting plugin: '${pluginConstructor.name}')`);
|
|
6065
|
-
}
|
|
6066
|
-
return null;
|
|
6067
|
-
}
|
|
6068
|
-
const plugin = new pluginConstructor(this);
|
|
6069
|
-
this.plugins[pluginConstructor.id] = plugin;
|
|
6070
|
-
plugin.setup();
|
|
6071
|
-
return plugin;
|
|
6270
|
+
delete(item) {
|
|
6271
|
+
const items = this._items().filter(([seq, val]) => val !== item);
|
|
6272
|
+
this._items.set(items);
|
|
6273
|
+
return this;
|
|
6072
6274
|
}
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
type: "plugin",
|
|
6076
|
-
app: this.app,
|
|
6077
|
-
manager: this,
|
|
6078
|
-
get status() {
|
|
6079
|
-
return this.manager.status;
|
|
6080
|
-
},
|
|
6081
|
-
});
|
|
6082
|
-
try {
|
|
6083
|
-
for (const pluginConstructor of pluginConstructors) {
|
|
6084
|
-
this.startPlugin(pluginConstructor);
|
|
6085
|
-
}
|
|
6086
|
-
}
|
|
6087
|
-
finally {
|
|
6088
|
-
contextStack.pop();
|
|
6089
|
-
}
|
|
6090
|
-
this.status = 1 /* STATUS.MOUNTED */;
|
|
6275
|
+
has(item) {
|
|
6276
|
+
return this._items().some(([s, value]) => value === item);
|
|
6091
6277
|
}
|
|
6092
6278
|
}
|
|
6093
|
-
function
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
}
|
|
6097
|
-
else {
|
|
6098
|
-
manager.onDestroyCb.push(effect(() => {
|
|
6099
|
-
const pluginItems = plugins.items();
|
|
6100
|
-
untrack(() => manager.startPlugins(pluginItems));
|
|
6101
|
-
}));
|
|
6279
|
+
function useResource(r, elements) {
|
|
6280
|
+
for (let elem of elements) {
|
|
6281
|
+
r.add(elem);
|
|
6102
6282
|
}
|
|
6283
|
+
onWillDestroy(() => {
|
|
6284
|
+
for (let elem of elements) {
|
|
6285
|
+
r.delete(elem);
|
|
6286
|
+
}
|
|
6287
|
+
});
|
|
6103
6288
|
}
|
|
6104
6289
|
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
tasks = new Set();
|
|
6113
|
-
requestAnimationFrame;
|
|
6114
|
-
frame = 0;
|
|
6115
|
-
delayedRenders = [];
|
|
6116
|
-
cancelledNodes = new Set();
|
|
6117
|
-
processing = false;
|
|
6118
|
-
constructor() {
|
|
6119
|
-
this.requestAnimationFrame = Scheduler.requestAnimationFrame;
|
|
6120
|
-
}
|
|
6121
|
-
addFiber(fiber) {
|
|
6122
|
-
this.tasks.add(fiber.root);
|
|
6290
|
+
class Registry {
|
|
6291
|
+
_map = signal.Object(Object.create(null));
|
|
6292
|
+
_name;
|
|
6293
|
+
_validation;
|
|
6294
|
+
constructor(options = {}) {
|
|
6295
|
+
this._name = options.name || "registry";
|
|
6296
|
+
this._validation = options.validation;
|
|
6123
6297
|
}
|
|
6124
|
-
|
|
6125
|
-
this.
|
|
6126
|
-
|
|
6127
|
-
|
|
6298
|
+
entries = computed(() => {
|
|
6299
|
+
const entries = Object.entries(this._map())
|
|
6300
|
+
.sort((el1, el2) => el1[1][0] - el2[1][0])
|
|
6301
|
+
.map(([str, elem]) => [str, elem[1]]);
|
|
6302
|
+
return entries;
|
|
6303
|
+
});
|
|
6304
|
+
items = computed(() => this.entries().map((e) => e[1]));
|
|
6305
|
+
addById(item, options = {}) {
|
|
6306
|
+
if (!item.id) {
|
|
6307
|
+
throw new OwlError(`Item should have an id key (registry '${this._name}')`);
|
|
6128
6308
|
}
|
|
6309
|
+
return this.add(item.id, item, { sequence: options.sequence ?? 50 });
|
|
6129
6310
|
}
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
flush() {
|
|
6135
|
-
if (this.delayedRenders.length) {
|
|
6136
|
-
let renders = this.delayedRenders;
|
|
6137
|
-
this.delayedRenders = [];
|
|
6138
|
-
for (let f of renders) {
|
|
6139
|
-
if (f.root && f.node.status !== 3 /* STATUS.DESTROYED */ && f.node.fiber === f) {
|
|
6140
|
-
f.render();
|
|
6141
|
-
}
|
|
6142
|
-
}
|
|
6143
|
-
}
|
|
6144
|
-
if (this.frame === 0) {
|
|
6145
|
-
this.frame = this.requestAnimationFrame(() => this.processTasks());
|
|
6311
|
+
add(key, value, options = {}) {
|
|
6312
|
+
if (this._validation) {
|
|
6313
|
+
const info = this._name ? ` (registry '${this._name}', key: '${key}')` : ` (key: '${key}')`;
|
|
6314
|
+
assertType(value, this._validation, `Registry entry does not match the type${info}`);
|
|
6146
6315
|
}
|
|
6316
|
+
this._map()[key] = [options.sequence ?? 50, value];
|
|
6317
|
+
return this;
|
|
6147
6318
|
}
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
this.processing = true;
|
|
6153
|
-
this.frame = 0;
|
|
6154
|
-
for (let node of this.cancelledNodes) {
|
|
6155
|
-
node._destroy();
|
|
6156
|
-
}
|
|
6157
|
-
this.cancelledNodes.clear();
|
|
6158
|
-
for (let task of this.tasks) {
|
|
6159
|
-
this.processFiber(task);
|
|
6160
|
-
}
|
|
6161
|
-
for (let task of this.tasks) {
|
|
6162
|
-
if (task.node.status === 3 /* STATUS.DESTROYED */) {
|
|
6163
|
-
this.tasks.delete(task);
|
|
6164
|
-
}
|
|
6319
|
+
get(key, defaultValue) {
|
|
6320
|
+
const hasKey = key in this._map();
|
|
6321
|
+
if (!hasKey && arguments.length < 2) {
|
|
6322
|
+
throw new Error(`KeyNotFoundError: Cannot find key "${key}" (registry '${this._name}')`);
|
|
6165
6323
|
}
|
|
6166
|
-
this.
|
|
6324
|
+
return hasKey ? this._map()[key][1] : defaultValue;
|
|
6167
6325
|
}
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6326
|
+
delete(key) {
|
|
6327
|
+
delete this._map()[key];
|
|
6328
|
+
}
|
|
6329
|
+
has(key) {
|
|
6330
|
+
return key in this._map();
|
|
6331
|
+
}
|
|
6332
|
+
}
|
|
6333
|
+
|
|
6334
|
+
const anyType = function validateAny() { };
|
|
6335
|
+
const booleanType = function validateBoolean(context) {
|
|
6336
|
+
if (typeof context.value !== "boolean") {
|
|
6337
|
+
context.addIssue({ message: "value is not a boolean" });
|
|
6338
|
+
}
|
|
6339
|
+
};
|
|
6340
|
+
const numberType = function validateNumber(context) {
|
|
6341
|
+
if (typeof context.value !== "number") {
|
|
6342
|
+
context.addIssue({ message: "value is not a number" });
|
|
6343
|
+
}
|
|
6344
|
+
};
|
|
6345
|
+
const stringType = function validateString(context) {
|
|
6346
|
+
if (typeof context.value !== "string") {
|
|
6347
|
+
context.addIssue({ message: "value is not a string" });
|
|
6348
|
+
}
|
|
6349
|
+
};
|
|
6350
|
+
function arrayType(elementType) {
|
|
6351
|
+
return function validateArray(context) {
|
|
6352
|
+
if (!Array.isArray(context.value)) {
|
|
6353
|
+
context.addIssue({ message: "value is not an array" });
|
|
6171
6354
|
return;
|
|
6172
6355
|
}
|
|
6173
|
-
|
|
6174
|
-
if (hasError && fiber.counter !== 0) {
|
|
6175
|
-
this.tasks.delete(fiber);
|
|
6356
|
+
if (!elementType) {
|
|
6176
6357
|
return;
|
|
6177
6358
|
}
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
return;
|
|
6359
|
+
for (let index = 0; index < context.value.length; index++) {
|
|
6360
|
+
context.withKey(index).validate(elementType);
|
|
6181
6361
|
}
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
// the fiber, so in that case, we actually want to keep the fiber around,
|
|
6190
|
-
// otherwise it will just be ignored.
|
|
6191
|
-
if (fiber.appliedToDom) {
|
|
6192
|
-
this.tasks.delete(fiber);
|
|
6193
|
-
}
|
|
6362
|
+
};
|
|
6363
|
+
}
|
|
6364
|
+
function constructorType(constructor) {
|
|
6365
|
+
return function validateConstructor(context) {
|
|
6366
|
+
if (!(typeof context.value === "function") ||
|
|
6367
|
+
!(context.value === constructor || context.value.prototype instanceof constructor)) {
|
|
6368
|
+
context.addIssue({ message: `value is not '${constructor.name}' or an extension` });
|
|
6194
6369
|
}
|
|
6195
|
-
}
|
|
6370
|
+
};
|
|
6196
6371
|
}
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
static validateTarget = validateTarget;
|
|
6203
|
-
static apps = apps;
|
|
6204
|
-
static version = version;
|
|
6205
|
-
name;
|
|
6206
|
-
scheduler = new Scheduler();
|
|
6207
|
-
roots = new Set();
|
|
6208
|
-
pluginManager;
|
|
6209
|
-
constructor(config = {}) {
|
|
6210
|
-
super(config);
|
|
6211
|
-
this.name = config.name || "";
|
|
6212
|
-
apps.add(this);
|
|
6213
|
-
this.pluginManager = new PluginManager(this, { config: config.config });
|
|
6214
|
-
if (config.plugins) {
|
|
6215
|
-
startPlugins(this.pluginManager, config.plugins);
|
|
6372
|
+
function customValidator(type, validator, errorMessage = "value does not match custom validation") {
|
|
6373
|
+
return function validateCustom(context) {
|
|
6374
|
+
context.validate(type);
|
|
6375
|
+
if (!context.isValid) {
|
|
6376
|
+
return;
|
|
6216
6377
|
}
|
|
6217
|
-
if (
|
|
6218
|
-
|
|
6378
|
+
if (!validator(context.value)) {
|
|
6379
|
+
context.addIssue({ message: errorMessage });
|
|
6219
6380
|
}
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6381
|
+
};
|
|
6382
|
+
}
|
|
6383
|
+
function functionType(parameters = [], result = undefined) {
|
|
6384
|
+
return function validateFunction(context) {
|
|
6385
|
+
if (typeof context.value !== "function") {
|
|
6386
|
+
context.addIssue({ message: "value is not a function" });
|
|
6223
6387
|
}
|
|
6224
|
-
}
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
resolve = res;
|
|
6231
|
-
reject = rej;
|
|
6232
|
-
});
|
|
6233
|
-
const restore = saveContext();
|
|
6234
|
-
let node;
|
|
6235
|
-
let error = null;
|
|
6236
|
-
try {
|
|
6237
|
-
node = new ComponentNode(Root, props, this, null, null);
|
|
6388
|
+
};
|
|
6389
|
+
}
|
|
6390
|
+
function instanceType(constructor) {
|
|
6391
|
+
return function validateInstanceType(context) {
|
|
6392
|
+
if (!(context.value instanceof constructor)) {
|
|
6393
|
+
context.addIssue({ message: `value is not an instance of '${constructor.name}'` });
|
|
6238
6394
|
}
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6395
|
+
};
|
|
6396
|
+
}
|
|
6397
|
+
function intersection(types) {
|
|
6398
|
+
return function validateIntersection(context) {
|
|
6399
|
+
for (const type of types) {
|
|
6400
|
+
context.validate(type);
|
|
6242
6401
|
}
|
|
6243
|
-
|
|
6244
|
-
|
|
6402
|
+
};
|
|
6403
|
+
}
|
|
6404
|
+
function literalType(literal) {
|
|
6405
|
+
return function validateLiteral(context) {
|
|
6406
|
+
if (context.value !== literal) {
|
|
6407
|
+
context.addIssue({
|
|
6408
|
+
message: `value is not equal to ${typeof literal === "string" ? `'${literal}'` : literal}`,
|
|
6409
|
+
});
|
|
6245
6410
|
}
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
return promise;
|
|
6256
|
-
},
|
|
6257
|
-
destroy: () => {
|
|
6258
|
-
this.roots.delete(root);
|
|
6259
|
-
node.destroy();
|
|
6260
|
-
this.scheduler.processTasks();
|
|
6261
|
-
},
|
|
6262
|
-
};
|
|
6263
|
-
this.roots.add(root);
|
|
6264
|
-
return root;
|
|
6411
|
+
};
|
|
6412
|
+
}
|
|
6413
|
+
function literalSelection(literals) {
|
|
6414
|
+
return union(literals.map(literalType));
|
|
6415
|
+
}
|
|
6416
|
+
function validateObject(context, schema, isStrict) {
|
|
6417
|
+
if (typeof context.value !== "object" || Array.isArray(context.value) || context.value === null) {
|
|
6418
|
+
context.addIssue({ message: "value is not an object" });
|
|
6419
|
+
return;
|
|
6265
6420
|
}
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
let handlers = nodeErrorHandlers.get(node);
|
|
6269
|
-
if (!handlers) {
|
|
6270
|
-
handlers = [];
|
|
6271
|
-
nodeErrorHandlers.set(node, handlers);
|
|
6272
|
-
}
|
|
6273
|
-
handlers.unshift((e, finalize) => {
|
|
6274
|
-
const finalError = finalize();
|
|
6275
|
-
reject(finalError);
|
|
6276
|
-
});
|
|
6277
|
-
// manually set a onMounted callback.
|
|
6278
|
-
// that way, we are independant from the current node.
|
|
6279
|
-
node.mounted.push(() => {
|
|
6280
|
-
resolve(node.component);
|
|
6281
|
-
handlers.shift();
|
|
6282
|
-
});
|
|
6283
|
-
node.mountComponent(target, options);
|
|
6421
|
+
if (!schema) {
|
|
6422
|
+
return;
|
|
6284
6423
|
}
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6424
|
+
const isShape = !Array.isArray(schema);
|
|
6425
|
+
let shape = schema;
|
|
6426
|
+
if (Array.isArray(schema)) {
|
|
6427
|
+
shape = {};
|
|
6428
|
+
for (const key of schema) {
|
|
6429
|
+
shape[key] = null;
|
|
6288
6430
|
}
|
|
6289
|
-
this.pluginManager.destroy();
|
|
6290
|
-
this.scheduler.processTasks();
|
|
6291
|
-
apps.delete(this);
|
|
6292
|
-
}
|
|
6293
|
-
handleError(...args) {
|
|
6294
|
-
return handleError(...args);
|
|
6295
6431
|
}
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
const mainEventHandler = (data, ev, currentTarget) => {
|
|
6304
|
-
const { data: _data, modifiers } = filterOutModifiersFromData(data);
|
|
6305
|
-
data = _data;
|
|
6306
|
-
let stopped = false;
|
|
6307
|
-
if (modifiers.length) {
|
|
6308
|
-
let selfMode = false;
|
|
6309
|
-
const isSelf = ev.target === currentTarget;
|
|
6310
|
-
for (const mod of modifiers) {
|
|
6311
|
-
switch (mod) {
|
|
6312
|
-
case "self":
|
|
6313
|
-
selfMode = true;
|
|
6314
|
-
if (isSelf) {
|
|
6315
|
-
continue;
|
|
6316
|
-
}
|
|
6317
|
-
else {
|
|
6318
|
-
return stopped;
|
|
6319
|
-
}
|
|
6320
|
-
case "prevent":
|
|
6321
|
-
if ((selfMode && isSelf) || !selfMode)
|
|
6322
|
-
ev.preventDefault();
|
|
6323
|
-
continue;
|
|
6324
|
-
case "stop":
|
|
6325
|
-
if ((selfMode && isSelf) || !selfMode)
|
|
6326
|
-
ev.stopPropagation();
|
|
6327
|
-
stopped = true;
|
|
6328
|
-
continue;
|
|
6432
|
+
const missingKeys = [];
|
|
6433
|
+
for (const key in shape) {
|
|
6434
|
+
const property = key.endsWith("?") ? key.slice(0, -1) : key;
|
|
6435
|
+
if (context.value[property] === undefined) {
|
|
6436
|
+
if (!key.endsWith("?")) {
|
|
6437
|
+
missingKeys.push(property);
|
|
6329
6438
|
}
|
|
6439
|
+
continue;
|
|
6330
6440
|
}
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
// We check this rather than data[0] being truthy (or typeof function) so that it crashes
|
|
6334
|
-
// as expected when there is a handler expression that evaluates to a falsy value
|
|
6335
|
-
if (Object.hasOwnProperty.call(data, 0)) {
|
|
6336
|
-
const handler = data[0];
|
|
6337
|
-
if (typeof handler !== "function") {
|
|
6338
|
-
throw new OwlError(`Invalid handler (expected a function, received: '${handler}')`);
|
|
6339
|
-
}
|
|
6340
|
-
let node = data[1] ? data[1].__owl__ : null;
|
|
6341
|
-
if (node ? node.status === 1 /* STATUS.MOUNTED */ : true) {
|
|
6342
|
-
handler(data[1], ev);
|
|
6441
|
+
if (isShape) {
|
|
6442
|
+
context.withKey(property).validate(shape[key]);
|
|
6343
6443
|
}
|
|
6344
6444
|
}
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6445
|
+
if (missingKeys.length) {
|
|
6446
|
+
context.addIssue({
|
|
6447
|
+
message: "object value has missing keys",
|
|
6448
|
+
missingKeys,
|
|
6449
|
+
});
|
|
6450
|
+
}
|
|
6451
|
+
if (isStrict) {
|
|
6452
|
+
const unknownKeys = [];
|
|
6453
|
+
for (const key in context.value) {
|
|
6454
|
+
if (!(key in shape) && !(`${key}?` in shape)) {
|
|
6455
|
+
unknownKeys.push(key);
|
|
6456
|
+
}
|
|
6457
|
+
}
|
|
6458
|
+
if (unknownKeys.length) {
|
|
6459
|
+
context.addIssue({
|
|
6460
|
+
message: "object value has unknown keys",
|
|
6461
|
+
unknownKeys,
|
|
6462
|
+
});
|
|
6356
6463
|
}
|
|
6357
|
-
onReadAtom(computation);
|
|
6358
|
-
return computation.value;
|
|
6359
6464
|
}
|
|
6360
|
-
readComputed[atomSymbol] = computation;
|
|
6361
|
-
readComputed.set = options.set ?? (() => { });
|
|
6362
|
-
return readComputed;
|
|
6363
6465
|
}
|
|
6364
|
-
|
|
6365
|
-
function
|
|
6366
|
-
|
|
6367
|
-
type: "signal",
|
|
6368
|
-
value,
|
|
6369
|
-
observers: new Set(),
|
|
6466
|
+
function objectType(schema = {}) {
|
|
6467
|
+
return function validateLooseObject(context) {
|
|
6468
|
+
validateObject(context, schema, false);
|
|
6370
6469
|
};
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6470
|
+
}
|
|
6471
|
+
function strictObjectType(schema) {
|
|
6472
|
+
return function validateStrictObject(context) {
|
|
6473
|
+
validateObject(context, schema, true);
|
|
6375
6474
|
};
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6475
|
+
}
|
|
6476
|
+
function promiseType(type) {
|
|
6477
|
+
return function validatePromise(context) {
|
|
6478
|
+
if (!(context.value instanceof Promise)) {
|
|
6479
|
+
context.addIssue({ message: "value is not a promise" });
|
|
6380
6480
|
}
|
|
6381
|
-
atom.value = newValue;
|
|
6382
|
-
readValue = set(atom);
|
|
6383
|
-
onWriteAtom(atom);
|
|
6384
6481
|
};
|
|
6385
|
-
return readSignal;
|
|
6386
|
-
}
|
|
6387
|
-
function invalidateSignal(signal) {
|
|
6388
|
-
if (typeof signal !== "function" || signal[atomSymbol]?.type !== "signal") {
|
|
6389
|
-
throw new OwlError(`Value is not a signal (${signal})`);
|
|
6390
|
-
}
|
|
6391
|
-
onWriteAtom(signal[atomSymbol]);
|
|
6392
6482
|
}
|
|
6393
|
-
function
|
|
6394
|
-
return
|
|
6483
|
+
function recordType(valueType) {
|
|
6484
|
+
return function validateRecord(context) {
|
|
6485
|
+
if (typeof context.value !== "object" ||
|
|
6486
|
+
Array.isArray(context.value) ||
|
|
6487
|
+
context.value === null) {
|
|
6488
|
+
context.addIssue({ message: "value is not an object" });
|
|
6489
|
+
return;
|
|
6490
|
+
}
|
|
6491
|
+
if (!valueType) {
|
|
6492
|
+
return;
|
|
6493
|
+
}
|
|
6494
|
+
for (const key in context.value) {
|
|
6495
|
+
context.withKey(key).validate(valueType);
|
|
6496
|
+
}
|
|
6497
|
+
};
|
|
6395
6498
|
}
|
|
6396
|
-
function
|
|
6397
|
-
return
|
|
6499
|
+
function tuple(types) {
|
|
6500
|
+
return function validateTuple(context) {
|
|
6501
|
+
if (!Array.isArray(context.value)) {
|
|
6502
|
+
context.addIssue({ message: "value is not an array" });
|
|
6503
|
+
return;
|
|
6504
|
+
}
|
|
6505
|
+
if (context.value.length !== types.length) {
|
|
6506
|
+
context.addIssue({ message: "tuple value does not have the correct length" });
|
|
6507
|
+
return;
|
|
6508
|
+
}
|
|
6509
|
+
for (let index = 0; index < types.length; index++) {
|
|
6510
|
+
context.withKey(index).validate(types[index]);
|
|
6511
|
+
}
|
|
6512
|
+
};
|
|
6398
6513
|
}
|
|
6399
|
-
function
|
|
6400
|
-
return
|
|
6514
|
+
function union(types) {
|
|
6515
|
+
return function validateUnion(context) {
|
|
6516
|
+
let firstIssueIndex = 0;
|
|
6517
|
+
const subIssues = [];
|
|
6518
|
+
for (const type of types) {
|
|
6519
|
+
const subContext = context.withIssues(subIssues);
|
|
6520
|
+
subContext.validate(type);
|
|
6521
|
+
if (subIssues.length === firstIssueIndex || subContext.issueDepth > 0) {
|
|
6522
|
+
context.mergeIssues(subIssues.slice(firstIssueIndex));
|
|
6523
|
+
return;
|
|
6524
|
+
}
|
|
6525
|
+
firstIssueIndex = subIssues.length;
|
|
6526
|
+
}
|
|
6527
|
+
context.addIssue({
|
|
6528
|
+
message: "value does not match union type",
|
|
6529
|
+
subIssues,
|
|
6530
|
+
});
|
|
6531
|
+
};
|
|
6401
6532
|
}
|
|
6402
|
-
function
|
|
6403
|
-
return
|
|
6533
|
+
function reactiveValueType(type) {
|
|
6534
|
+
return function validateReactiveValue(context) {
|
|
6535
|
+
if (typeof context.value !== "function" || !context.value[atomSymbol]) {
|
|
6536
|
+
context.addIssue({ message: "value is not a reactive value" });
|
|
6537
|
+
}
|
|
6538
|
+
};
|
|
6404
6539
|
}
|
|
6405
|
-
function
|
|
6406
|
-
return
|
|
6540
|
+
function ref(type) {
|
|
6541
|
+
return union([literalType(null), instanceType(type)]);
|
|
6407
6542
|
}
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6543
|
+
const types = {
|
|
6544
|
+
and: intersection,
|
|
6545
|
+
any: anyType,
|
|
6546
|
+
array: arrayType,
|
|
6547
|
+
boolean: booleanType,
|
|
6548
|
+
constructor: constructorType,
|
|
6549
|
+
customValidator: customValidator,
|
|
6550
|
+
function: functionType,
|
|
6551
|
+
instanceOf: instanceType,
|
|
6552
|
+
literal: literalType,
|
|
6553
|
+
number: numberType,
|
|
6554
|
+
object: objectType,
|
|
6555
|
+
or: union,
|
|
6556
|
+
promise: promiseType,
|
|
6557
|
+
record: recordType,
|
|
6558
|
+
ref,
|
|
6559
|
+
selection: literalSelection,
|
|
6560
|
+
signal: reactiveValueType,
|
|
6561
|
+
strictObject: strictObjectType,
|
|
6562
|
+
string: stringType,
|
|
6563
|
+
tuple: tuple,
|
|
6564
|
+
};
|
|
6413
6565
|
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
return this._items()
|
|
6424
|
-
.sort((el1, el2) => el1[0] - el2[0])
|
|
6425
|
-
.map((elem) => elem[1]);
|
|
6426
|
-
});
|
|
6427
|
-
add(item, options = {}) {
|
|
6428
|
-
if (this._validation) {
|
|
6429
|
-
const info = this._name ? ` (resource '${this._name}')` : "";
|
|
6430
|
-
assertType(item, this._validation, `Resource item does not match the type${info}`);
|
|
6431
|
-
}
|
|
6432
|
-
this._items().push([options.sequence ?? 50, item]);
|
|
6433
|
-
return this;
|
|
6434
|
-
}
|
|
6435
|
-
delete(item) {
|
|
6436
|
-
const items = this._items().filter(([seq, val]) => val !== item);
|
|
6437
|
-
this._items.set(items);
|
|
6438
|
-
return this;
|
|
6439
|
-
}
|
|
6440
|
-
has(item) {
|
|
6441
|
-
return this._items().some(([s, value]) => value === item);
|
|
6442
|
-
}
|
|
6443
|
-
}
|
|
6444
|
-
function useResource(r, elements) {
|
|
6445
|
-
for (let elem of elements) {
|
|
6446
|
-
r.add(elem);
|
|
6447
|
-
}
|
|
6448
|
-
onWillDestroy(() => {
|
|
6449
|
-
for (let elem of elements) {
|
|
6450
|
-
r.delete(elem);
|
|
6566
|
+
function validateObjectWithDefaults(schema, defaultValues) {
|
|
6567
|
+
const keys = Array.isArray(schema) ? schema : Object.keys(schema);
|
|
6568
|
+
const mandatoryDefaultedKeys = keys.filter((key) => !key.endsWith("?") && key in defaultValues);
|
|
6569
|
+
return (context) => {
|
|
6570
|
+
if (mandatoryDefaultedKeys.length) {
|
|
6571
|
+
context.addIssue({
|
|
6572
|
+
message: "props have default values on mandatory keys",
|
|
6573
|
+
keys: mandatoryDefaultedKeys,
|
|
6574
|
+
});
|
|
6451
6575
|
}
|
|
6452
|
-
|
|
6576
|
+
context.validate(types.object(schema));
|
|
6577
|
+
};
|
|
6453
6578
|
}
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
this._name = options.name || "registry";
|
|
6461
|
-
this._validation = options.validation;
|
|
6462
|
-
}
|
|
6463
|
-
entries = computed(() => {
|
|
6464
|
-
const entries = Object.entries(this._map())
|
|
6465
|
-
.sort((el1, el2) => el1[1][0] - el2[1][0])
|
|
6466
|
-
.map(([str, elem]) => [str, elem[1]]);
|
|
6467
|
-
return entries;
|
|
6468
|
-
});
|
|
6469
|
-
items = computed(() => this.entries().map((e) => e[1]));
|
|
6470
|
-
addById(item, options = {}) {
|
|
6471
|
-
if (!item.id) {
|
|
6472
|
-
throw new OwlError(`Item should have an id key (registry '${this._name}')`);
|
|
6579
|
+
function props(type, defaults) {
|
|
6580
|
+
const { node, app, componentName } = getContext("component");
|
|
6581
|
+
Object.assign(node.defaultProps, defaults);
|
|
6582
|
+
function getProp(key) {
|
|
6583
|
+
if (node.props[key] === undefined && defaults) {
|
|
6584
|
+
return defaults[key];
|
|
6473
6585
|
}
|
|
6474
|
-
return
|
|
6586
|
+
return node.props[key];
|
|
6475
6587
|
}
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6588
|
+
const result = Object.create(null);
|
|
6589
|
+
function applyPropGetters(keys) {
|
|
6590
|
+
for (const key of keys) {
|
|
6591
|
+
Reflect.defineProperty(result, key, {
|
|
6592
|
+
enumerable: true,
|
|
6593
|
+
get: getProp.bind(null, key),
|
|
6594
|
+
});
|
|
6480
6595
|
}
|
|
6481
|
-
this._map()[key] = [options.sequence ?? 50, value];
|
|
6482
|
-
return this;
|
|
6483
6596
|
}
|
|
6484
|
-
|
|
6485
|
-
const
|
|
6486
|
-
|
|
6487
|
-
|
|
6597
|
+
if (type) {
|
|
6598
|
+
const keys = (Array.isArray(type) ? type : Object.keys(type)).map((key) => key.endsWith("?") ? key.slice(0, -1) : key);
|
|
6599
|
+
applyPropGetters(keys);
|
|
6600
|
+
if (app.dev) {
|
|
6601
|
+
const validation = defaults ? validateObjectWithDefaults(type, defaults) : types.object(type);
|
|
6602
|
+
assertType(node.props, validation, `Invalid component props (${componentName})`);
|
|
6603
|
+
node.willUpdateProps.push((np) => {
|
|
6604
|
+
assertType(np, validation, `Invalid component props (${componentName})`);
|
|
6605
|
+
});
|
|
6488
6606
|
}
|
|
6489
|
-
return hasKey ? this._map()[key][1] : defaultValue;
|
|
6490
|
-
}
|
|
6491
|
-
delete(key) {
|
|
6492
|
-
delete this._map()[key];
|
|
6493
6607
|
}
|
|
6494
|
-
|
|
6495
|
-
|
|
6608
|
+
else {
|
|
6609
|
+
const getKeys = (props) => {
|
|
6610
|
+
const keys = [];
|
|
6611
|
+
for (const k in props) {
|
|
6612
|
+
if (k.charCodeAt(0) !== 1) {
|
|
6613
|
+
keys.push(k);
|
|
6614
|
+
}
|
|
6615
|
+
}
|
|
6616
|
+
if (defaults) {
|
|
6617
|
+
for (const k in defaults) {
|
|
6618
|
+
if (!(k in props)) {
|
|
6619
|
+
keys.push(k);
|
|
6620
|
+
}
|
|
6621
|
+
}
|
|
6622
|
+
}
|
|
6623
|
+
return keys;
|
|
6624
|
+
};
|
|
6625
|
+
let keys = getKeys(node.props);
|
|
6626
|
+
applyPropGetters(keys);
|
|
6627
|
+
node.willUpdateProps.push((np) => {
|
|
6628
|
+
for (const key of keys) {
|
|
6629
|
+
Reflect.deleteProperty(result, key);
|
|
6630
|
+
}
|
|
6631
|
+
keys = getKeys(np);
|
|
6632
|
+
applyPropGetters(keys);
|
|
6633
|
+
});
|
|
6496
6634
|
}
|
|
6635
|
+
return result;
|
|
6497
6636
|
}
|
|
6498
6637
|
|
|
6499
6638
|
function status(entity) {
|
|
@@ -6632,6 +6771,6 @@ TemplateSet.prototype._compileTemplate = function _compileTemplate(name, templat
|
|
|
6632
6771
|
export { App, Component, EventBus, OwlError, Plugin, Registry, Resource, __info__, assertType, batched, blockDom, computed, config, effect, htmlEscape, markRaw, markup, mount, onError, onMounted, onPatched, onWillDestroy, onWillPatch, onWillStart, onWillUnmount, onWillUpdateProps, plugin, props, providePlugins, proxy, signal, status, toRaw, types, untrack, useApp, useContext, useEffect, useListener, useResource, validateType, whenReady, xml };
|
|
6633
6772
|
|
|
6634
6773
|
|
|
6635
|
-
__info__.date = '2026-
|
|
6636
|
-
__info__.hash = '
|
|
6774
|
+
__info__.date = '2026-04-08T13:31:02.500Z';
|
|
6775
|
+
__info__.hash = '2e9164e';
|
|
6637
6776
|
__info__.url = 'https://github.com/odoo/owl';
|