@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.
Files changed (62) hide show
  1. package/README.md +100 -110
  2. package/dist/compile_templates.mjs +84 -80
  3. package/dist/owl-devtools.zip +0 -0
  4. package/dist/owl.cjs.js +1612 -1473
  5. package/dist/owl.es.js +1612 -1473
  6. package/dist/owl.iife.js +1612 -1473
  7. package/dist/owl.iife.min.js +1 -1
  8. package/dist/types/compiler/code_generator.d.ts +1 -2
  9. package/dist/types/compiler/inline_expressions.d.ts +7 -24
  10. package/dist/types/compiler/parser.d.ts +3 -8
  11. package/dist/types/owl.d.ts +33 -27
  12. package/dist/types/runtime/blockdom/attributes.d.ts +2 -0
  13. package/dist/types/runtime/component_node.d.ts +2 -0
  14. package/dist/types/runtime/plugin_manager.d.ts +2 -0
  15. package/dist/types/runtime/reactivity/computations.d.ts +1 -0
  16. package/dist/types/runtime/rendering/scheduler.d.ts +1 -1
  17. package/dist/types/runtime/rendering/template_helpers.d.ts +2 -2
  18. package/dist/types/runtime/types.d.ts +3 -0
  19. package/dist/types/version.d.ts +1 -1
  20. package/package.json +25 -2
  21. package/dist/compiler.js +0 -2371
  22. package/dist/owl.cjs.runtime.js +0 -4070
  23. package/dist/owl.es.runtime.js +0 -4026
  24. package/dist/owl.iife.runtime.js +0 -4074
  25. package/dist/owl.iife.runtime.min.js +0 -1
  26. package/dist/types/common/types.d.ts +0 -1
  27. package/dist/types/runtime/cancellableContext.d.ts +0 -15
  28. package/dist/types/runtime/cancellablePromise.d.ts +0 -15
  29. package/dist/types/runtime/error_handling.d.ts +0 -13
  30. package/dist/types/runtime/executionContext.d.ts +0 -0
  31. package/dist/types/runtime/fibers.d.ts +0 -37
  32. package/dist/types/runtime/listOperation.d.ts +0 -1
  33. package/dist/types/runtime/model.d.ts +0 -48
  34. package/dist/types/runtime/plugins.d.ts +0 -36
  35. package/dist/types/runtime/portal.d.ts +0 -12
  36. package/dist/types/runtime/reactivity/async_computed.d.ts +0 -1
  37. package/dist/types/runtime/reactivity/derived.d.ts +0 -7
  38. package/dist/types/runtime/reactivity/reactivity.d.ts +0 -46
  39. package/dist/types/runtime/reactivity/signals.d.ts +0 -30
  40. package/dist/types/runtime/reactivity/state.d.ts +0 -48
  41. package/dist/types/runtime/reactivity.d.ts +0 -57
  42. package/dist/types/runtime/relationalModel/discussModel.d.ts +0 -19
  43. package/dist/types/runtime/relationalModel/discussModelTypes.d.ts +0 -22
  44. package/dist/types/runtime/relationalModel/field.d.ts +0 -20
  45. package/dist/types/runtime/relationalModel/model.d.ts +0 -59
  46. package/dist/types/runtime/relationalModel/modelData.d.ts +0 -18
  47. package/dist/types/runtime/relationalModel/modelRegistry.d.ts +0 -3
  48. package/dist/types/runtime/relationalModel/modelUtils.d.ts +0 -4
  49. package/dist/types/runtime/relationalModel/store.d.ts +0 -16
  50. package/dist/types/runtime/relationalModel/types.d.ts +0 -83
  51. package/dist/types/runtime/relationalModel/util.d.ts +0 -1
  52. package/dist/types/runtime/relationalModel/web/WebDataPoint.d.ts +0 -25
  53. package/dist/types/runtime/relationalModel/web/WebRecord.d.ts +0 -131
  54. package/dist/types/runtime/relationalModel/web/WebStaticList.d.ts +0 -63
  55. package/dist/types/runtime/relationalModel/web/webModel.d.ts +0 -5
  56. package/dist/types/runtime/relationalModel/web/webModelTypes.d.ts +0 -139
  57. package/dist/types/runtime/scheduler.d.ts +0 -21
  58. package/dist/types/runtime/signals.d.ts +0 -19
  59. package/dist/types/runtime/suspense.d.ts +0 -5
  60. package/dist/types/runtime/task.d.ts +0 -12
  61. package/dist/types/runtime/template_helpers.d.ts +0 -58
  62. package/dist/types/utils/registry.d.ts +0 -15
@@ -1,4070 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- // Custom error class that wraps error that happen in the owl lifecycle
6
- class OwlError extends Error {
7
- }
8
-
9
- // do not modify manually. This file is generated by the release script.
10
- const version = "3.0.0-alpha";
11
-
12
- class Component {
13
- constructor(node) {
14
- this.__owl__ = node;
15
- }
16
- setup() { }
17
- render(deep = false) {
18
- this.__owl__.render(deep === true);
19
- }
20
- }
21
- Component.template = "";
22
-
23
- /**
24
- * Creates a batched version of a callback so that all calls to it in the same
25
- * microtick will only call the original callback once.
26
- *
27
- * @param callback the callback to batch
28
- * @returns a batched version of the original callback
29
- */
30
- function batched(callback) {
31
- let scheduled = false;
32
- return async (...args) => {
33
- if (!scheduled) {
34
- scheduled = true;
35
- await Promise.resolve();
36
- scheduled = false;
37
- callback(...args);
38
- }
39
- };
40
- }
41
- /**
42
- * Determine whether the given element is contained in its ownerDocument:
43
- * either directly or with a shadow root in between.
44
- */
45
- function inOwnerDocument(el) {
46
- if (!el) {
47
- return false;
48
- }
49
- if (el.ownerDocument.contains(el)) {
50
- return true;
51
- }
52
- const rootNode = el.getRootNode();
53
- return rootNode instanceof ShadowRoot && el.ownerDocument.contains(rootNode.host);
54
- }
55
- /**
56
- * Determine whether the given element is contained in a specific root documnet:
57
- * either directly or with a shadow root in between or in an iframe.
58
- */
59
- function isAttachedToDocument(element, documentElement) {
60
- let current = element;
61
- const shadowRoot = documentElement.defaultView.ShadowRoot;
62
- while (current) {
63
- if (current === documentElement) {
64
- return true;
65
- }
66
- if (current.parentNode) {
67
- current = current.parentNode;
68
- }
69
- else if (current instanceof shadowRoot && current.host) {
70
- current = current.host;
71
- }
72
- else {
73
- return false;
74
- }
75
- }
76
- return false;
77
- }
78
- function validateTarget(target) {
79
- // Get the document and HTMLElement corresponding to the target to allow mounting in iframes
80
- const document = target && target.ownerDocument;
81
- if (document) {
82
- if (!document.defaultView) {
83
- throw new OwlError("Cannot mount a component: the target document is not attached to a window (defaultView is missing)");
84
- }
85
- const HTMLElement = document.defaultView.HTMLElement;
86
- if (target instanceof HTMLElement || target instanceof ShadowRoot) {
87
- if (!isAttachedToDocument(target, document)) {
88
- throw new OwlError("Cannot mount a component on a detached dom node");
89
- }
90
- return;
91
- }
92
- }
93
- throw new OwlError("Cannot mount component: the target is not a valid DOM element");
94
- }
95
- class EventBus extends EventTarget {
96
- trigger(name, payload) {
97
- this.dispatchEvent(new CustomEvent(name, { detail: payload }));
98
- }
99
- }
100
- function whenReady(fn) {
101
- return new Promise(function (resolve) {
102
- if (document.readyState !== "loading") {
103
- resolve(true);
104
- }
105
- else {
106
- document.addEventListener("DOMContentLoaded", resolve, false);
107
- }
108
- }).then(fn || function () { });
109
- }
110
- /*
111
- * This class just transports the fact that a string is safe
112
- * to be injected as HTML. Overriding a JS primitive is quite painful though
113
- * so we need to redfine toString and valueOf.
114
- */
115
- class Markup extends String {
116
- }
117
- function htmlEscape(str) {
118
- if (str instanceof Markup) {
119
- return str;
120
- }
121
- if (str === undefined) {
122
- return markup("");
123
- }
124
- if (typeof str === "number") {
125
- return markup(String(str));
126
- }
127
- [
128
- ["&", "&"],
129
- ["<", "&lt;"],
130
- [">", "&gt;"],
131
- ["'", "&#x27;"],
132
- ['"', "&quot;"],
133
- ["`", "&#x60;"],
134
- ].forEach((pairs) => {
135
- str = String(str).replace(new RegExp(pairs[0], "g"), pairs[1]);
136
- });
137
- return markup(str);
138
- }
139
- function markup(valueOrStrings, ...placeholders) {
140
- if (!Array.isArray(valueOrStrings)) {
141
- return new Markup(valueOrStrings);
142
- }
143
- const strings = valueOrStrings;
144
- let acc = "";
145
- let i = 0;
146
- for (; i < placeholders.length; ++i) {
147
- acc += strings[i] + htmlEscape(placeholders[i]);
148
- }
149
- acc += strings[i];
150
- return new Markup(acc);
151
- }
152
-
153
- var ComputationState;
154
- (function (ComputationState) {
155
- ComputationState[ComputationState["EXECUTED"] = 0] = "EXECUTED";
156
- ComputationState[ComputationState["STALE"] = 1] = "STALE";
157
- ComputationState[ComputationState["PENDING"] = 2] = "PENDING";
158
- })(ComputationState || (ComputationState = {}));
159
- let Effects;
160
- let CurrentComputation;
161
- // export function computed<T>(fn: () => T, opts?: Opts) {
162
- // // todo: handle cleanup
163
- // let computedComputation: Computation = {
164
- // state: ComputationState.STALE,
165
- // sources: new Set(),
166
- // isEager: true,
167
- // compute: () => {
168
- // return fn();
169
- // },
170
- // value: undefined,
171
- // name: opts?.name,
172
- // };
173
- // updateComputation(computedComputation);
174
- // }
175
- function onReadAtom(atom) {
176
- if (!CurrentComputation)
177
- return;
178
- CurrentComputation.sources.add(atom);
179
- atom.observers.add(CurrentComputation);
180
- }
181
- function onWriteAtom(atom) {
182
- collectEffects(() => {
183
- for (const ctx of atom.observers) {
184
- if (ctx.state === ComputationState.EXECUTED) {
185
- if (ctx.isDerived)
186
- markDownstream(ctx);
187
- else
188
- Effects.push(ctx);
189
- }
190
- ctx.state = ComputationState.STALE;
191
- }
192
- });
193
- batchProcessEffects();
194
- }
195
- function collectEffects(fn) {
196
- if (Effects)
197
- return fn();
198
- Effects = [];
199
- try {
200
- return fn();
201
- }
202
- finally {
203
- }
204
- }
205
- const batchProcessEffects = batched(processEffects);
206
- function processEffects() {
207
- if (!Effects)
208
- return;
209
- for (const computation of Effects) {
210
- updateComputation(computation);
211
- }
212
- Effects = undefined;
213
- }
214
- function untrack(fn) {
215
- return runWithComputation(undefined, fn);
216
- }
217
- function getCurrentComputation() {
218
- return CurrentComputation;
219
- }
220
- function setComputation(computation) {
221
- CurrentComputation = computation;
222
- }
223
- // todo: should probably use updateComputation instead.
224
- function runWithComputation(computation, fn) {
225
- const previousComputation = CurrentComputation;
226
- CurrentComputation = computation;
227
- let result;
228
- try {
229
- result = fn();
230
- }
231
- finally {
232
- CurrentComputation = previousComputation;
233
- }
234
- return result;
235
- }
236
- function updateComputation(computation) {
237
- var _a;
238
- const state = computation.state;
239
- if (state === ComputationState.EXECUTED)
240
- return;
241
- if (state === ComputationState.PENDING) {
242
- computeSources(computation);
243
- // If the state is still not stale after processing the sources, it means
244
- // none of the dependencies have changed.
245
- // todo: test it
246
- if (computation.state !== ComputationState.STALE) {
247
- computation.state = ComputationState.EXECUTED;
248
- return;
249
- }
250
- }
251
- // todo: test performance. We might want to avoid removing the atoms to
252
- // directly re-add them at compute. Especially as we are making them stale.
253
- removeSources(computation);
254
- const previousComputation = CurrentComputation;
255
- CurrentComputation = computation;
256
- computation.value = (_a = computation.compute) === null || _a === void 0 ? void 0 : _a.call(computation);
257
- computation.state = ComputationState.EXECUTED;
258
- CurrentComputation = previousComputation;
259
- }
260
- function removeSources(computation) {
261
- const sources = computation.sources;
262
- for (const source of sources) {
263
- const observers = source.observers;
264
- observers.delete(computation);
265
- // todo: if source has no effect observer anymore, remove its sources too
266
- // todo: test it
267
- }
268
- sources.clear();
269
- }
270
- function markDownstream(derived) {
271
- for (const observer of derived.observers) {
272
- // if the state has already been marked, skip it
273
- if (observer.state)
274
- continue;
275
- observer.state = ComputationState.PENDING;
276
- if (observer.isDerived)
277
- markDownstream(observer);
278
- else
279
- Effects.push(observer);
280
- }
281
- }
282
- function computeSources(derived) {
283
- for (const source of derived.sources) {
284
- if (!("compute" in source))
285
- continue;
286
- updateComputation(source);
287
- }
288
- }
289
-
290
- // Maps fibers to thrown errors
291
- const fibersInError = new WeakMap();
292
- const nodeErrorHandlers = new WeakMap();
293
- function destroyApp(app, error) {
294
- try {
295
- app.destroy();
296
- }
297
- catch (e) {
298
- // mute all errors here because we are in a corrupted state anyway
299
- }
300
- const e = Object.assign(new OwlError(`[Owl] Unhandled error. Destroying the root component`), {
301
- cause: error,
302
- });
303
- return e;
304
- }
305
- function _handleError(node, error) {
306
- if (!node) {
307
- return false;
308
- }
309
- const fiber = node.fiber;
310
- if (fiber) {
311
- fibersInError.set(fiber, error);
312
- }
313
- const errorHandlers = nodeErrorHandlers.get(node);
314
- if (errorHandlers) {
315
- let handled = false;
316
- // execute in the opposite order
317
- const finalize = () => destroyApp(node.app, error);
318
- for (let i = errorHandlers.length - 1; i >= 0; i--) {
319
- try {
320
- errorHandlers[i](error, finalize);
321
- handled = true;
322
- break;
323
- }
324
- catch (e) {
325
- error = e;
326
- }
327
- }
328
- if (handled) {
329
- return true;
330
- }
331
- }
332
- return _handleError(node.parent, error);
333
- }
334
- function handleError(params) {
335
- let { error } = params;
336
- const node = "node" in params ? params.node : params.fiber.node;
337
- const fiber = "fiber" in params ? params.fiber : node.fiber;
338
- if (fiber) {
339
- // resets the fibers on components if possible. This is important so that
340
- // new renderings can be properly included in the initial one, if any.
341
- let current = fiber;
342
- do {
343
- current.node.fiber = current;
344
- current = current.parent;
345
- } while (current);
346
- fibersInError.set(fiber.root, error);
347
- }
348
- const handled = _handleError(node, error);
349
- if (!handled) {
350
- throw destroyApp(node.app, error);
351
- }
352
- }
353
-
354
- function filterOutModifiersFromData(dataList) {
355
- dataList = dataList.slice();
356
- const modifiers = [];
357
- let elm;
358
- while ((elm = dataList[0]) && typeof elm === "string") {
359
- modifiers.push(dataList.shift());
360
- }
361
- return { modifiers, data: dataList };
362
- }
363
- const config = {
364
- // whether or not blockdom should normalize DOM whenever a block is created.
365
- // Normalizing dom mean removing empty text nodes (or containing only spaces)
366
- shouldNormalizeDom: true,
367
- // this is the main event handler. Every event handler registered with blockdom
368
- // will go through this function, giving it the data registered in the block
369
- // and the event
370
- mainEventHandler: (data, ev, currentTarget) => {
371
- if (typeof data === "function") {
372
- data(ev);
373
- }
374
- else if (Array.isArray(data)) {
375
- data = filterOutModifiersFromData(data).data;
376
- data[0](data[1], ev);
377
- }
378
- return false;
379
- },
380
- };
381
-
382
- // -----------------------------------------------------------------------------
383
- // Toggler node
384
- // -----------------------------------------------------------------------------
385
- const txt = document.createTextNode("");
386
- class VToggler {
387
- constructor(key, child) {
388
- this.key = key;
389
- this.child = child;
390
- }
391
- mount(parent, afterNode) {
392
- this.parentEl = parent;
393
- this.child.mount(parent, afterNode);
394
- }
395
- moveBeforeDOMNode(node, parent) {
396
- this.child.moveBeforeDOMNode(node, parent);
397
- }
398
- moveBeforeVNode(other, afterNode) {
399
- this.moveBeforeDOMNode((other && other.firstNode()) || afterNode);
400
- }
401
- patch(other, withBeforeRemove) {
402
- if (this === other) {
403
- return;
404
- }
405
- let child1 = this.child;
406
- let child2 = other.child;
407
- if (this.key === other.key) {
408
- child1.patch(child2, withBeforeRemove);
409
- }
410
- else {
411
- const firstNode = child1.firstNode();
412
- firstNode.parentElement.insertBefore(txt, firstNode);
413
- if (withBeforeRemove) {
414
- child1.beforeRemove();
415
- }
416
- child1.remove();
417
- child2.mount(this.parentEl, txt);
418
- this.child = child2;
419
- this.key = other.key;
420
- }
421
- }
422
- beforeRemove() {
423
- this.child.beforeRemove();
424
- }
425
- remove() {
426
- this.child.remove();
427
- }
428
- firstNode() {
429
- return this.child.firstNode();
430
- }
431
- toString() {
432
- return this.child.toString();
433
- }
434
- }
435
- function toggler(key, child) {
436
- return new VToggler(key, child);
437
- }
438
-
439
- const { setAttribute: elemSetAttribute, removeAttribute } = Element.prototype;
440
- const tokenList = DOMTokenList.prototype;
441
- const tokenListAdd = tokenList.add;
442
- const tokenListRemove = tokenList.remove;
443
- const isArray = Array.isArray;
444
- const { split, trim } = String.prototype;
445
- const wordRegexp = /\s+/;
446
- /**
447
- * We regroup here all code related to updating attributes in a very loose sense:
448
- * attributes, properties and classs are all managed by the functions in this
449
- * file.
450
- */
451
- function setAttribute(key, value) {
452
- switch (value) {
453
- case false:
454
- case undefined:
455
- removeAttribute.call(this, key);
456
- break;
457
- case true:
458
- elemSetAttribute.call(this, key, "");
459
- break;
460
- default:
461
- elemSetAttribute.call(this, key, value);
462
- }
463
- }
464
- function createAttrUpdater(attr) {
465
- return function (value) {
466
- setAttribute.call(this, attr, value);
467
- };
468
- }
469
- function attrsSetter(attrs) {
470
- if (isArray(attrs)) {
471
- if (attrs[0] === "class") {
472
- setClass.call(this, attrs[1]);
473
- }
474
- else {
475
- setAttribute.call(this, attrs[0], attrs[1]);
476
- }
477
- }
478
- else {
479
- for (let k in attrs) {
480
- if (k === "class") {
481
- setClass.call(this, attrs[k]);
482
- }
483
- else {
484
- setAttribute.call(this, k, attrs[k]);
485
- }
486
- }
487
- }
488
- }
489
- function attrsUpdater(attrs, oldAttrs) {
490
- if (isArray(attrs)) {
491
- const name = attrs[0];
492
- const val = attrs[1];
493
- if (name === oldAttrs[0]) {
494
- if (val === oldAttrs[1]) {
495
- return;
496
- }
497
- if (name === "class") {
498
- updateClass.call(this, val, oldAttrs[1]);
499
- }
500
- else {
501
- setAttribute.call(this, name, val);
502
- }
503
- }
504
- else {
505
- removeAttribute.call(this, oldAttrs[0]);
506
- setAttribute.call(this, name, val);
507
- }
508
- }
509
- else {
510
- for (let k in oldAttrs) {
511
- if (!(k in attrs)) {
512
- if (k === "class") {
513
- updateClass.call(this, "", oldAttrs[k]);
514
- }
515
- else {
516
- removeAttribute.call(this, k);
517
- }
518
- }
519
- }
520
- for (let k in attrs) {
521
- const val = attrs[k];
522
- if (val !== oldAttrs[k]) {
523
- if (k === "class") {
524
- updateClass.call(this, val, oldAttrs[k]);
525
- }
526
- else {
527
- setAttribute.call(this, k, val);
528
- }
529
- }
530
- }
531
- }
532
- }
533
- function toClassObj(expr) {
534
- const result = {};
535
- switch (typeof expr) {
536
- case "string":
537
- // we transform here a list of classes into an object:
538
- // 'hey you' becomes {hey: true, you: true}
539
- const str = trim.call(expr);
540
- if (!str) {
541
- return {};
542
- }
543
- let words = split.call(str, wordRegexp);
544
- for (let i = 0, l = words.length; i < l; i++) {
545
- result[words[i]] = true;
546
- }
547
- return result;
548
- case "object":
549
- // this is already an object but we may need to split keys:
550
- // {'a': true, 'b c': true} should become {a: true, b: true, c: true}
551
- for (let key in expr) {
552
- const value = expr[key];
553
- if (value) {
554
- key = trim.call(key);
555
- if (!key) {
556
- continue;
557
- }
558
- const words = split.call(key, wordRegexp);
559
- for (let word of words) {
560
- result[word] = value;
561
- }
562
- }
563
- }
564
- return result;
565
- case "undefined":
566
- return {};
567
- case "number":
568
- return { [expr]: true };
569
- default:
570
- return { [expr]: true };
571
- }
572
- }
573
- function setClass(val) {
574
- val = val === "" ? {} : toClassObj(val);
575
- // add classes
576
- const cl = this.classList;
577
- for (let c in val) {
578
- tokenListAdd.call(cl, c);
579
- }
580
- }
581
- function updateClass(val, oldVal) {
582
- oldVal = oldVal === "" ? {} : toClassObj(oldVal);
583
- val = val === "" ? {} : toClassObj(val);
584
- const cl = this.classList;
585
- // remove classes
586
- for (let c in oldVal) {
587
- if (!(c in val)) {
588
- tokenListRemove.call(cl, c);
589
- }
590
- }
591
- // add classes
592
- for (let c in val) {
593
- if (!(c in oldVal)) {
594
- tokenListAdd.call(cl, c);
595
- }
596
- }
597
- }
598
-
599
- function createEventHandler(rawEvent) {
600
- const eventName = rawEvent.split(".")[0];
601
- const capture = rawEvent.includes(".capture");
602
- if (rawEvent.includes(".synthetic")) {
603
- return createSyntheticHandler(eventName, capture);
604
- }
605
- else {
606
- return createElementHandler(eventName, capture);
607
- }
608
- }
609
- // Native listener
610
- let nextNativeEventId = 1;
611
- function createElementHandler(evName, capture = false) {
612
- let eventKey = `__event__${evName}_${nextNativeEventId++}`;
613
- if (capture) {
614
- eventKey = `${eventKey}_capture`;
615
- }
616
- function listener(ev) {
617
- const currentTarget = ev.currentTarget;
618
- if (!currentTarget || !inOwnerDocument(currentTarget))
619
- return;
620
- const data = currentTarget[eventKey];
621
- if (!data)
622
- return;
623
- config.mainEventHandler(data, ev, currentTarget);
624
- }
625
- function setup(data) {
626
- this[eventKey] = data;
627
- this.addEventListener(evName, listener, { capture });
628
- }
629
- function remove() {
630
- delete this[eventKey];
631
- this.removeEventListener(evName, listener, { capture });
632
- }
633
- function update(data) {
634
- this[eventKey] = data;
635
- }
636
- return { setup, update, remove };
637
- }
638
- // Synthetic handler: a form of event delegation that allows placing only one
639
- // listener per event type.
640
- let nextSyntheticEventId = 1;
641
- function createSyntheticHandler(evName, capture = false) {
642
- let eventKey = `__event__synthetic_${evName}`;
643
- if (capture) {
644
- eventKey = `${eventKey}_capture`;
645
- }
646
- setupSyntheticEvent(evName, eventKey, capture);
647
- const currentId = nextSyntheticEventId++;
648
- function setup(data) {
649
- const _data = this[eventKey] || {};
650
- _data[currentId] = data;
651
- this[eventKey] = _data;
652
- }
653
- function remove() {
654
- delete this[eventKey];
655
- }
656
- return { setup, update: setup, remove };
657
- }
658
- function nativeToSyntheticEvent(eventKey, event) {
659
- let dom = event.target;
660
- while (dom !== null) {
661
- const _data = dom[eventKey];
662
- if (_data) {
663
- for (const data of Object.values(_data)) {
664
- const stopped = config.mainEventHandler(data, event, dom);
665
- if (stopped)
666
- return;
667
- }
668
- }
669
- dom = dom.parentNode;
670
- }
671
- }
672
- const CONFIGURED_SYNTHETIC_EVENTS = {};
673
- function setupSyntheticEvent(evName, eventKey, capture = false) {
674
- if (CONFIGURED_SYNTHETIC_EVENTS[eventKey]) {
675
- return;
676
- }
677
- document.addEventListener(evName, (event) => nativeToSyntheticEvent(eventKey, event), {
678
- capture,
679
- });
680
- CONFIGURED_SYNTHETIC_EVENTS[eventKey] = true;
681
- }
682
-
683
- const getDescriptor$3 = (o, p) => Object.getOwnPropertyDescriptor(o, p);
684
- const nodeProto$4 = Node.prototype;
685
- const nodeInsertBefore$3 = nodeProto$4.insertBefore;
686
- const nodeSetTextContent$1 = getDescriptor$3(nodeProto$4, "textContent").set;
687
- const nodeRemoveChild$3 = nodeProto$4.removeChild;
688
- // -----------------------------------------------------------------------------
689
- // Multi NODE
690
- // -----------------------------------------------------------------------------
691
- class VMulti {
692
- constructor(children) {
693
- this.children = children;
694
- }
695
- mount(parent, afterNode) {
696
- const children = this.children;
697
- const l = children.length;
698
- const anchors = new Array(l);
699
- for (let i = 0; i < l; i++) {
700
- let child = children[i];
701
- if (child) {
702
- child.mount(parent, afterNode);
703
- }
704
- else {
705
- const childAnchor = document.createTextNode("");
706
- anchors[i] = childAnchor;
707
- nodeInsertBefore$3.call(parent, childAnchor, afterNode);
708
- }
709
- }
710
- this.anchors = anchors;
711
- this.parentEl = parent;
712
- }
713
- moveBeforeDOMNode(node, parent = this.parentEl) {
714
- this.parentEl = parent;
715
- const children = this.children;
716
- const anchors = this.anchors;
717
- for (let i = 0, l = children.length; i < l; i++) {
718
- let child = children[i];
719
- if (child) {
720
- child.moveBeforeDOMNode(node, parent);
721
- }
722
- else {
723
- const anchor = anchors[i];
724
- nodeInsertBefore$3.call(parent, anchor, node);
725
- }
726
- }
727
- }
728
- moveBeforeVNode(other, afterNode) {
729
- if (other) {
730
- const next = other.children[0];
731
- afterNode = (next ? next.firstNode() : other.anchors[0]) || null;
732
- }
733
- const children = this.children;
734
- const parent = this.parentEl;
735
- const anchors = this.anchors;
736
- for (let i = 0, l = children.length; i < l; i++) {
737
- let child = children[i];
738
- if (child) {
739
- child.moveBeforeVNode(null, afterNode);
740
- }
741
- else {
742
- const anchor = anchors[i];
743
- nodeInsertBefore$3.call(parent, anchor, afterNode);
744
- }
745
- }
746
- }
747
- patch(other, withBeforeRemove) {
748
- if (this === other) {
749
- return;
750
- }
751
- const children1 = this.children;
752
- const children2 = other.children;
753
- const anchors = this.anchors;
754
- const parentEl = this.parentEl;
755
- for (let i = 0, l = children1.length; i < l; i++) {
756
- const vn1 = children1[i];
757
- const vn2 = children2[i];
758
- if (vn1) {
759
- if (vn2) {
760
- vn1.patch(vn2, withBeforeRemove);
761
- }
762
- else {
763
- const afterNode = vn1.firstNode();
764
- const anchor = document.createTextNode("");
765
- anchors[i] = anchor;
766
- nodeInsertBefore$3.call(parentEl, anchor, afterNode);
767
- if (withBeforeRemove) {
768
- vn1.beforeRemove();
769
- }
770
- vn1.remove();
771
- children1[i] = undefined;
772
- }
773
- }
774
- else if (vn2) {
775
- children1[i] = vn2;
776
- const anchor = anchors[i];
777
- vn2.mount(parentEl, anchor);
778
- nodeRemoveChild$3.call(parentEl, anchor);
779
- }
780
- }
781
- }
782
- beforeRemove() {
783
- const children = this.children;
784
- for (let i = 0, l = children.length; i < l; i++) {
785
- const child = children[i];
786
- if (child) {
787
- child.beforeRemove();
788
- }
789
- }
790
- }
791
- remove() {
792
- const parentEl = this.parentEl;
793
- if (this.isOnlyChild) {
794
- nodeSetTextContent$1.call(parentEl, "");
795
- }
796
- else {
797
- const children = this.children;
798
- const anchors = this.anchors;
799
- for (let i = 0, l = children.length; i < l; i++) {
800
- const child = children[i];
801
- if (child) {
802
- child.remove();
803
- }
804
- else {
805
- nodeRemoveChild$3.call(parentEl, anchors[i]);
806
- }
807
- }
808
- }
809
- }
810
- firstNode() {
811
- const child = this.children[0];
812
- return child ? child.firstNode() : this.anchors[0];
813
- }
814
- toString() {
815
- return this.children.map((c) => (c ? c.toString() : "")).join("");
816
- }
817
- }
818
- function multi(children) {
819
- return new VMulti(children);
820
- }
821
-
822
- const getDescriptor$2 = (o, p) => Object.getOwnPropertyDescriptor(o, p);
823
- const nodeProto$3 = Node.prototype;
824
- const characterDataProto$1 = CharacterData.prototype;
825
- const nodeInsertBefore$2 = nodeProto$3.insertBefore;
826
- const characterDataSetData$1 = getDescriptor$2(characterDataProto$1, "data").set;
827
- const nodeRemoveChild$2 = nodeProto$3.removeChild;
828
- class VSimpleNode {
829
- constructor(text) {
830
- this.text = text;
831
- }
832
- mountNode(node, parent, afterNode) {
833
- this.parentEl = parent;
834
- nodeInsertBefore$2.call(parent, node, afterNode);
835
- this.el = node;
836
- }
837
- moveBeforeDOMNode(node, parent = this.parentEl) {
838
- this.parentEl = parent;
839
- nodeInsertBefore$2.call(parent, this.el, node);
840
- }
841
- moveBeforeVNode(other, afterNode) {
842
- nodeInsertBefore$2.call(this.parentEl, this.el, other ? other.el : afterNode);
843
- }
844
- beforeRemove() { }
845
- remove() {
846
- nodeRemoveChild$2.call(this.parentEl, this.el);
847
- }
848
- firstNode() {
849
- return this.el;
850
- }
851
- toString() {
852
- return this.text;
853
- }
854
- }
855
- class VText$1 extends VSimpleNode {
856
- mount(parent, afterNode) {
857
- this.mountNode(document.createTextNode(toText(this.text)), parent, afterNode);
858
- }
859
- patch(other) {
860
- const text2 = other.text;
861
- if (this.text !== text2) {
862
- characterDataSetData$1.call(this.el, toText(text2));
863
- this.text = text2;
864
- }
865
- }
866
- }
867
- class VComment extends VSimpleNode {
868
- mount(parent, afterNode) {
869
- this.mountNode(document.createComment(toText(this.text)), parent, afterNode);
870
- }
871
- patch() { }
872
- }
873
- function text(str) {
874
- return new VText$1(str);
875
- }
876
- function comment(str) {
877
- return new VComment(str);
878
- }
879
- function toText(value) {
880
- switch (typeof value) {
881
- case "string":
882
- return value;
883
- case "number":
884
- return String(value);
885
- case "boolean":
886
- return value ? "true" : "false";
887
- default:
888
- return value || "";
889
- }
890
- }
891
-
892
- const getDescriptor$1 = (o, p) => Object.getOwnPropertyDescriptor(o, p);
893
- const nodeProto$2 = Node.prototype;
894
- const elementProto = Element.prototype;
895
- const characterDataProto = CharacterData.prototype;
896
- const characterDataSetData = getDescriptor$1(characterDataProto, "data").set;
897
- const nodeGetFirstChild = getDescriptor$1(nodeProto$2, "firstChild").get;
898
- const nodeGetNextSibling = getDescriptor$1(nodeProto$2, "nextSibling").get;
899
- const NO_OP = () => { };
900
- function makePropSetter(name) {
901
- return function setProp(value) {
902
- // support 0, fallback to empty string for other falsy values
903
- this[name] = value === 0 ? 0 : value ? value.valueOf() : "";
904
- };
905
- }
906
- const cache = {};
907
- /**
908
- * Compiling blocks is a multi-step process:
909
- *
910
- * 1. build an IntermediateTree from the HTML element. This intermediate tree
911
- * is a binary tree structure that encode dynamic info sub nodes, and the
912
- * path required to reach them
913
- * 2. process the tree to build a block context, which is an object that aggregate
914
- * all dynamic info in a list, and also, all ref indexes.
915
- * 3. process the context to build appropriate builder/setter functions
916
- * 4. make a dynamic block class, which will efficiently collect references and
917
- * create/update dynamic locations/children
918
- *
919
- * @param str
920
- * @returns a new block type, that can build concrete blocks
921
- */
922
- function createBlock(str) {
923
- if (str in cache) {
924
- return cache[str];
925
- }
926
- // step 0: prepare html base element
927
- const doc = new DOMParser().parseFromString(`<t>${str}</t>`, "text/xml");
928
- const node = doc.firstChild.firstChild;
929
- if (config.shouldNormalizeDom) {
930
- normalizeNode(node);
931
- }
932
- // step 1: prepare intermediate tree
933
- const tree = buildTree(node);
934
- // step 2: prepare block context
935
- const context = buildContext(tree);
936
- // step 3: build the final block class
937
- const template = tree.el;
938
- const Block = buildBlock(template, context);
939
- cache[str] = Block;
940
- return Block;
941
- }
942
- // -----------------------------------------------------------------------------
943
- // Helper
944
- // -----------------------------------------------------------------------------
945
- function normalizeNode(node) {
946
- if (node.nodeType === Node.TEXT_NODE) {
947
- if (!/\S/.test(node.textContent)) {
948
- node.remove();
949
- return;
950
- }
951
- }
952
- if (node.nodeType === Node.ELEMENT_NODE) {
953
- if (node.tagName === "pre") {
954
- return;
955
- }
956
- }
957
- for (let i = node.childNodes.length - 1; i >= 0; --i) {
958
- normalizeNode(node.childNodes.item(i));
959
- }
960
- }
961
- function buildTree(node, parent = null, domParentTree = null) {
962
- switch (node.nodeType) {
963
- case Node.ELEMENT_NODE: {
964
- // HTMLElement
965
- let currentNS = domParentTree && domParentTree.currentNS;
966
- const tagName = node.tagName;
967
- let el = undefined;
968
- const info = [];
969
- if (tagName.startsWith("block-text-")) {
970
- const index = parseInt(tagName.slice(11), 10);
971
- info.push({ type: "text", idx: index });
972
- el = document.createTextNode("");
973
- }
974
- if (tagName.startsWith("block-child-")) {
975
- if (!domParentTree.isRef) {
976
- addRef(domParentTree);
977
- }
978
- const index = parseInt(tagName.slice(12), 10);
979
- info.push({ type: "child", idx: index });
980
- el = document.createTextNode("");
981
- }
982
- currentNS || (currentNS = node.namespaceURI);
983
- if (!el) {
984
- el = currentNS
985
- ? document.createElementNS(currentNS, tagName)
986
- : document.createElement(tagName);
987
- }
988
- if (el instanceof Element) {
989
- if (!domParentTree) {
990
- // some html elements may have side effects when setting their attributes.
991
- // For example, setting the src attribute of an <img/> will trigger a
992
- // request to get the corresponding image. This is something that we
993
- // don't want at compile time. We avoid that by putting the content of
994
- // the block in a <template/> element
995
- const fragment = document.createElement("template").content;
996
- fragment.appendChild(el);
997
- }
998
- const attrs = node.attributes;
999
- for (let i = 0; i < attrs.length; i++) {
1000
- const attrName = attrs[i].name;
1001
- const attrValue = attrs[i].value;
1002
- if (attrName.startsWith("block-handler-")) {
1003
- const idx = parseInt(attrName.slice(14), 10);
1004
- info.push({
1005
- type: "handler",
1006
- idx,
1007
- event: attrValue,
1008
- });
1009
- }
1010
- else if (attrName.startsWith("block-attribute-")) {
1011
- const idx = parseInt(attrName.slice(16), 10);
1012
- info.push({
1013
- type: "attribute",
1014
- idx,
1015
- name: attrValue,
1016
- tag: tagName,
1017
- });
1018
- }
1019
- else if (attrName.startsWith("block-property-")) {
1020
- const idx = parseInt(attrName.slice(15), 10);
1021
- info.push({
1022
- type: "property",
1023
- idx,
1024
- name: attrValue,
1025
- tag: tagName,
1026
- });
1027
- }
1028
- else if (attrName === "block-attributes") {
1029
- info.push({
1030
- type: "attributes",
1031
- idx: parseInt(attrValue, 10),
1032
- });
1033
- }
1034
- else if (attrName === "block-ref") {
1035
- info.push({
1036
- type: "ref",
1037
- idx: parseInt(attrValue, 10),
1038
- });
1039
- }
1040
- else {
1041
- el.setAttribute(attrs[i].name, attrValue);
1042
- }
1043
- }
1044
- }
1045
- const tree = {
1046
- parent,
1047
- firstChild: null,
1048
- nextSibling: null,
1049
- el,
1050
- info,
1051
- refN: 0,
1052
- currentNS,
1053
- };
1054
- if (node.firstChild) {
1055
- const childNode = node.childNodes[0];
1056
- if (node.childNodes.length === 1 &&
1057
- childNode.nodeType === Node.ELEMENT_NODE &&
1058
- childNode.tagName.startsWith("block-child-")) {
1059
- const tagName = childNode.tagName;
1060
- const index = parseInt(tagName.slice(12), 10);
1061
- info.push({ idx: index, type: "child", isOnlyChild: true });
1062
- }
1063
- else {
1064
- tree.firstChild = buildTree(node.firstChild, tree, tree);
1065
- el.appendChild(tree.firstChild.el);
1066
- let curNode = node.firstChild;
1067
- let curTree = tree.firstChild;
1068
- while ((curNode = curNode.nextSibling)) {
1069
- curTree.nextSibling = buildTree(curNode, curTree, tree);
1070
- el.appendChild(curTree.nextSibling.el);
1071
- curTree = curTree.nextSibling;
1072
- }
1073
- }
1074
- }
1075
- if (tree.info.length) {
1076
- addRef(tree);
1077
- }
1078
- return tree;
1079
- }
1080
- case Node.TEXT_NODE:
1081
- case Node.COMMENT_NODE: {
1082
- // text node or comment node
1083
- const el = node.nodeType === Node.TEXT_NODE
1084
- ? document.createTextNode(node.textContent)
1085
- : document.createComment(node.textContent);
1086
- return {
1087
- parent: parent,
1088
- firstChild: null,
1089
- nextSibling: null,
1090
- el,
1091
- info: [],
1092
- refN: 0,
1093
- currentNS: null,
1094
- };
1095
- }
1096
- }
1097
- throw new OwlError("boom");
1098
- }
1099
- function addRef(tree) {
1100
- tree.isRef = true;
1101
- do {
1102
- tree.refN++;
1103
- } while ((tree = tree.parent));
1104
- }
1105
- function parentTree(tree) {
1106
- let parent = tree.parent;
1107
- while (parent && parent.nextSibling === tree) {
1108
- tree = parent;
1109
- parent = parent.parent;
1110
- }
1111
- return parent;
1112
- }
1113
- function buildContext(tree, ctx, fromIdx) {
1114
- if (!ctx) {
1115
- const children = new Array(tree.info.filter((v) => v.type === "child").length);
1116
- ctx = { collectors: [], locations: [], children, cbRefs: [], refN: tree.refN };
1117
- fromIdx = 0;
1118
- }
1119
- if (tree.refN) {
1120
- const initialIdx = fromIdx;
1121
- const isRef = tree.isRef;
1122
- const firstChild = tree.firstChild ? tree.firstChild.refN : 0;
1123
- const nextSibling = tree.nextSibling ? tree.nextSibling.refN : 0;
1124
- //node
1125
- if (isRef) {
1126
- for (let info of tree.info) {
1127
- info.refIdx = initialIdx;
1128
- }
1129
- tree.refIdx = initialIdx;
1130
- updateCtx(ctx, tree);
1131
- fromIdx++;
1132
- }
1133
- // right
1134
- if (nextSibling) {
1135
- const idx = fromIdx + firstChild;
1136
- ctx.collectors.push({ idx, prevIdx: initialIdx, getVal: nodeGetNextSibling });
1137
- buildContext(tree.nextSibling, ctx, idx);
1138
- }
1139
- // left
1140
- if (firstChild) {
1141
- ctx.collectors.push({ idx: fromIdx, prevIdx: initialIdx, getVal: nodeGetFirstChild });
1142
- buildContext(tree.firstChild, ctx, fromIdx);
1143
- }
1144
- }
1145
- return ctx;
1146
- }
1147
- function updateCtx(ctx, tree) {
1148
- for (let info of tree.info) {
1149
- switch (info.type) {
1150
- case "text":
1151
- ctx.locations.push({
1152
- idx: info.idx,
1153
- refIdx: info.refIdx,
1154
- setData: setText,
1155
- updateData: setText,
1156
- });
1157
- break;
1158
- case "child":
1159
- if (info.isOnlyChild) {
1160
- // tree is the parentnode here
1161
- ctx.children[info.idx] = {
1162
- parentRefIdx: info.refIdx,
1163
- isOnlyChild: true,
1164
- };
1165
- }
1166
- else {
1167
- // tree is the anchor text node
1168
- ctx.children[info.idx] = {
1169
- parentRefIdx: parentTree(tree).refIdx,
1170
- afterRefIdx: info.refIdx,
1171
- };
1172
- }
1173
- break;
1174
- case "property": {
1175
- const refIdx = info.refIdx;
1176
- const setProp = makePropSetter(info.name);
1177
- ctx.locations.push({
1178
- idx: info.idx,
1179
- refIdx,
1180
- setData: setProp,
1181
- updateData: setProp,
1182
- });
1183
- break;
1184
- }
1185
- case "attribute": {
1186
- const refIdx = info.refIdx;
1187
- let updater;
1188
- let setter;
1189
- if (info.name === "class") {
1190
- setter = setClass;
1191
- updater = updateClass;
1192
- }
1193
- else {
1194
- setter = createAttrUpdater(info.name);
1195
- updater = setter;
1196
- }
1197
- ctx.locations.push({
1198
- idx: info.idx,
1199
- refIdx,
1200
- setData: setter,
1201
- updateData: updater,
1202
- });
1203
- break;
1204
- }
1205
- case "attributes":
1206
- ctx.locations.push({
1207
- idx: info.idx,
1208
- refIdx: info.refIdx,
1209
- setData: attrsSetter,
1210
- updateData: attrsUpdater,
1211
- });
1212
- break;
1213
- case "handler": {
1214
- const { setup, update } = createEventHandler(info.event);
1215
- ctx.locations.push({
1216
- idx: info.idx,
1217
- refIdx: info.refIdx,
1218
- setData: setup,
1219
- updateData: update,
1220
- });
1221
- break;
1222
- }
1223
- case "ref": {
1224
- ctx.locations.push({
1225
- idx: info.idx,
1226
- refIdx: info.refIdx,
1227
- setData: NO_OP,
1228
- updateData: NO_OP,
1229
- });
1230
- ctx.cbRefs.push(info.idx);
1231
- break;
1232
- }
1233
- }
1234
- }
1235
- }
1236
- // -----------------------------------------------------------------------------
1237
- // building the concrete block class
1238
- // -----------------------------------------------------------------------------
1239
- function buildBlock(template, ctx) {
1240
- let B = createBlockClass(template, ctx);
1241
- if (ctx.children.length) {
1242
- B = class extends B {
1243
- constructor(data, children) {
1244
- super(data);
1245
- this.children = children;
1246
- }
1247
- };
1248
- B.prototype.beforeRemove = VMulti.prototype.beforeRemove;
1249
- return (data, children = []) => new B(data, children);
1250
- }
1251
- return (data) => new B(data);
1252
- }
1253
- function createBlockClass(template, ctx) {
1254
- const { refN, collectors, children, locations, cbRefs } = ctx;
1255
- const colN = collectors.length;
1256
- locations.sort((a, b) => a.idx - b.idx);
1257
- const locN = locations.length;
1258
- const childN = children.length;
1259
- const childrenLocs = children;
1260
- const isDynamic = refN > 0;
1261
- // these values are defined here to make them faster to lookup in the class
1262
- // block scope
1263
- const nodeCloneNode = nodeProto$2.cloneNode;
1264
- const nodeInsertBefore = nodeProto$2.insertBefore;
1265
- const elementRemove = elementProto.remove;
1266
- class Block {
1267
- constructor(data) {
1268
- this.data = data;
1269
- }
1270
- beforeRemove() { }
1271
- remove() {
1272
- elementRemove.call(this.el);
1273
- }
1274
- firstNode() {
1275
- return this.el;
1276
- }
1277
- moveBeforeDOMNode(node, parent = this.parentEl) {
1278
- this.parentEl = parent;
1279
- nodeInsertBefore.call(parent, this.el, node);
1280
- }
1281
- moveBeforeVNode(other, afterNode) {
1282
- nodeInsertBefore.call(this.parentEl, this.el, other ? other.el : afterNode);
1283
- }
1284
- toString() {
1285
- const div = document.createElement("div");
1286
- this.mount(div, null);
1287
- return div.innerHTML;
1288
- }
1289
- mount(parent, afterNode) {
1290
- const el = nodeCloneNode.call(template, true);
1291
- nodeInsertBefore.call(parent, el, afterNode);
1292
- this.el = el;
1293
- this.parentEl = parent;
1294
- }
1295
- patch(other, withBeforeRemove) { }
1296
- }
1297
- if (isDynamic) {
1298
- Block.prototype.mount = function mount(parent, afterNode) {
1299
- const el = nodeCloneNode.call(template, true);
1300
- // collecting references
1301
- const refs = new Array(refN);
1302
- this.refs = refs;
1303
- refs[0] = el;
1304
- for (let i = 0; i < colN; i++) {
1305
- const w = collectors[i];
1306
- refs[w.idx] = w.getVal.call(refs[w.prevIdx]);
1307
- }
1308
- // applying data to all update points
1309
- if (locN) {
1310
- const data = this.data;
1311
- for (let i = 0; i < locN; i++) {
1312
- const loc = locations[i];
1313
- loc.setData.call(refs[loc.refIdx], data[i]);
1314
- }
1315
- }
1316
- nodeInsertBefore.call(parent, el, afterNode);
1317
- // preparing all children
1318
- if (childN) {
1319
- const children = this.children;
1320
- for (let i = 0; i < childN; i++) {
1321
- const child = children[i];
1322
- if (child) {
1323
- const loc = childrenLocs[i];
1324
- const afterNode = loc.afterRefIdx ? refs[loc.afterRefIdx] : null;
1325
- child.isOnlyChild = loc.isOnlyChild;
1326
- child.mount(refs[loc.parentRefIdx], afterNode);
1327
- }
1328
- }
1329
- }
1330
- this.el = el;
1331
- this.parentEl = parent;
1332
- if (cbRefs.length) {
1333
- const data = this.data;
1334
- const refs = this.refs;
1335
- for (let cbRef of cbRefs) {
1336
- const { idx, refIdx } = locations[cbRef];
1337
- const fn = data[idx];
1338
- fn(refs[refIdx], null);
1339
- }
1340
- }
1341
- };
1342
- Block.prototype.patch = function patch(other, withBeforeRemove) {
1343
- if (this === other) {
1344
- return;
1345
- }
1346
- const refs = this.refs;
1347
- // update texts/attributes/
1348
- if (locN) {
1349
- const data1 = this.data;
1350
- const data2 = other.data;
1351
- for (let i = 0; i < locN; i++) {
1352
- const val1 = data1[i];
1353
- const val2 = data2[i];
1354
- if (val1 !== val2) {
1355
- const loc = locations[i];
1356
- loc.updateData.call(refs[loc.refIdx], val2, val1);
1357
- }
1358
- }
1359
- this.data = data2;
1360
- }
1361
- // update children
1362
- if (childN) {
1363
- let children1 = this.children;
1364
- const children2 = other.children;
1365
- for (let i = 0; i < childN; i++) {
1366
- const child1 = children1[i];
1367
- const child2 = children2[i];
1368
- if (child1) {
1369
- if (child2) {
1370
- child1.patch(child2, withBeforeRemove);
1371
- }
1372
- else {
1373
- if (withBeforeRemove) {
1374
- child1.beforeRemove();
1375
- }
1376
- child1.remove();
1377
- children1[i] = undefined;
1378
- }
1379
- }
1380
- else if (child2) {
1381
- const loc = childrenLocs[i];
1382
- const afterNode = loc.afterRefIdx ? refs[loc.afterRefIdx] : null;
1383
- child2.mount(refs[loc.parentRefIdx], afterNode);
1384
- children1[i] = child2;
1385
- }
1386
- }
1387
- }
1388
- };
1389
- Block.prototype.remove = function remove() {
1390
- if (cbRefs.length) {
1391
- const data = this.data;
1392
- const refs = this.refs;
1393
- for (let cbRef of cbRefs) {
1394
- const { idx, refIdx } = locations[cbRef];
1395
- const fn = data[idx];
1396
- fn(null, refs[refIdx]);
1397
- }
1398
- }
1399
- elementRemove.call(this.el);
1400
- };
1401
- }
1402
- return Block;
1403
- }
1404
- function setText(value) {
1405
- characterDataSetData.call(this, toText(value));
1406
- }
1407
-
1408
- const getDescriptor = (o, p) => Object.getOwnPropertyDescriptor(o, p);
1409
- const nodeProto$1 = Node.prototype;
1410
- const nodeInsertBefore$1 = nodeProto$1.insertBefore;
1411
- const nodeAppendChild = nodeProto$1.appendChild;
1412
- const nodeRemoveChild$1 = nodeProto$1.removeChild;
1413
- const nodeSetTextContent = getDescriptor(nodeProto$1, "textContent").set;
1414
- // -----------------------------------------------------------------------------
1415
- // List Node
1416
- // -----------------------------------------------------------------------------
1417
- class VList {
1418
- constructor(children) {
1419
- this.children = children;
1420
- }
1421
- mount(parent, afterNode) {
1422
- const children = this.children;
1423
- const _anchor = document.createTextNode("");
1424
- this.anchor = _anchor;
1425
- nodeInsertBefore$1.call(parent, _anchor, afterNode);
1426
- const l = children.length;
1427
- if (l) {
1428
- const mount = children[0].mount;
1429
- for (let i = 0; i < l; i++) {
1430
- mount.call(children[i], parent, _anchor);
1431
- }
1432
- }
1433
- this.parentEl = parent;
1434
- }
1435
- moveBeforeDOMNode(node, parent = this.parentEl) {
1436
- this.parentEl = parent;
1437
- const children = this.children;
1438
- for (let i = 0, l = children.length; i < l; i++) {
1439
- children[i].moveBeforeDOMNode(node, parent);
1440
- }
1441
- parent.insertBefore(this.anchor, node);
1442
- }
1443
- moveBeforeVNode(other, afterNode) {
1444
- if (other) {
1445
- const next = other.children[0];
1446
- afterNode = (next ? next.firstNode() : other.anchor) || null;
1447
- }
1448
- const children = this.children;
1449
- for (let i = 0, l = children.length; i < l; i++) {
1450
- children[i].moveBeforeVNode(null, afterNode);
1451
- }
1452
- this.parentEl.insertBefore(this.anchor, afterNode);
1453
- }
1454
- patch(other, withBeforeRemove) {
1455
- if (this === other) {
1456
- return;
1457
- }
1458
- const ch1 = this.children;
1459
- const ch2 = other.children;
1460
- if (ch2.length === 0 && ch1.length === 0) {
1461
- return;
1462
- }
1463
- this.children = ch2;
1464
- const proto = ch2[0] || ch1[0];
1465
- const { mount: cMount, patch: cPatch, remove: cRemove, beforeRemove, moveBeforeVNode: cMoveBefore, firstNode: cFirstNode, } = proto;
1466
- const _anchor = this.anchor;
1467
- const isOnlyChild = this.isOnlyChild;
1468
- const parent = this.parentEl;
1469
- // fast path: no new child => only remove
1470
- if (ch2.length === 0 && isOnlyChild) {
1471
- if (withBeforeRemove) {
1472
- for (let i = 0, l = ch1.length; i < l; i++) {
1473
- beforeRemove.call(ch1[i]);
1474
- }
1475
- }
1476
- nodeSetTextContent.call(parent, "");
1477
- nodeAppendChild.call(parent, _anchor);
1478
- return;
1479
- }
1480
- let startIdx1 = 0;
1481
- let startIdx2 = 0;
1482
- let startVn1 = ch1[0];
1483
- let startVn2 = ch2[0];
1484
- let endIdx1 = ch1.length - 1;
1485
- let endIdx2 = ch2.length - 1;
1486
- let endVn1 = ch1[endIdx1];
1487
- let endVn2 = ch2[endIdx2];
1488
- let mapping = undefined;
1489
- while (startIdx1 <= endIdx1 && startIdx2 <= endIdx2) {
1490
- // -------------------------------------------------------------------
1491
- if (startVn1 === null) {
1492
- startVn1 = ch1[++startIdx1];
1493
- continue;
1494
- }
1495
- // -------------------------------------------------------------------
1496
- if (endVn1 === null) {
1497
- endVn1 = ch1[--endIdx1];
1498
- continue;
1499
- }
1500
- // -------------------------------------------------------------------
1501
- let startKey1 = startVn1.key;
1502
- let startKey2 = startVn2.key;
1503
- if (startKey1 === startKey2) {
1504
- cPatch.call(startVn1, startVn2, withBeforeRemove);
1505
- ch2[startIdx2] = startVn1;
1506
- startVn1 = ch1[++startIdx1];
1507
- startVn2 = ch2[++startIdx2];
1508
- continue;
1509
- }
1510
- // -------------------------------------------------------------------
1511
- let endKey1 = endVn1.key;
1512
- let endKey2 = endVn2.key;
1513
- if (endKey1 === endKey2) {
1514
- cPatch.call(endVn1, endVn2, withBeforeRemove);
1515
- ch2[endIdx2] = endVn1;
1516
- endVn1 = ch1[--endIdx1];
1517
- endVn2 = ch2[--endIdx2];
1518
- continue;
1519
- }
1520
- // -------------------------------------------------------------------
1521
- if (startKey1 === endKey2) {
1522
- // bnode moved right
1523
- cPatch.call(startVn1, endVn2, withBeforeRemove);
1524
- ch2[endIdx2] = startVn1;
1525
- const nextChild = ch2[endIdx2 + 1];
1526
- cMoveBefore.call(startVn1, nextChild, _anchor);
1527
- startVn1 = ch1[++startIdx1];
1528
- endVn2 = ch2[--endIdx2];
1529
- continue;
1530
- }
1531
- // -------------------------------------------------------------------
1532
- if (endKey1 === startKey2) {
1533
- // bnode moved left
1534
- cPatch.call(endVn1, startVn2, withBeforeRemove);
1535
- ch2[startIdx2] = endVn1;
1536
- const nextChild = ch1[startIdx1];
1537
- cMoveBefore.call(endVn1, nextChild, _anchor);
1538
- endVn1 = ch1[--endIdx1];
1539
- startVn2 = ch2[++startIdx2];
1540
- continue;
1541
- }
1542
- // -------------------------------------------------------------------
1543
- mapping = mapping || createMapping(ch1, startIdx1, endIdx1);
1544
- let idxInOld = mapping[startKey2];
1545
- if (idxInOld === undefined) {
1546
- cMount.call(startVn2, parent, cFirstNode.call(startVn1) || null);
1547
- }
1548
- else {
1549
- const elmToMove = ch1[idxInOld];
1550
- cMoveBefore.call(elmToMove, startVn1, null);
1551
- cPatch.call(elmToMove, startVn2, withBeforeRemove);
1552
- ch2[startIdx2] = elmToMove;
1553
- ch1[idxInOld] = null;
1554
- }
1555
- startVn2 = ch2[++startIdx2];
1556
- }
1557
- // ---------------------------------------------------------------------
1558
- if (startIdx1 <= endIdx1 || startIdx2 <= endIdx2) {
1559
- if (startIdx1 > endIdx1) {
1560
- const nextChild = ch2[endIdx2 + 1];
1561
- const anchor = nextChild ? cFirstNode.call(nextChild) || null : _anchor;
1562
- for (let i = startIdx2; i <= endIdx2; i++) {
1563
- cMount.call(ch2[i], parent, anchor);
1564
- }
1565
- }
1566
- else {
1567
- for (let i = startIdx1; i <= endIdx1; i++) {
1568
- let ch = ch1[i];
1569
- if (ch) {
1570
- if (withBeforeRemove) {
1571
- beforeRemove.call(ch);
1572
- }
1573
- cRemove.call(ch);
1574
- }
1575
- }
1576
- }
1577
- }
1578
- }
1579
- beforeRemove() {
1580
- const children = this.children;
1581
- const l = children.length;
1582
- if (l) {
1583
- const beforeRemove = children[0].beforeRemove;
1584
- for (let i = 0; i < l; i++) {
1585
- beforeRemove.call(children[i]);
1586
- }
1587
- }
1588
- }
1589
- remove() {
1590
- const { parentEl, anchor } = this;
1591
- if (this.isOnlyChild) {
1592
- nodeSetTextContent.call(parentEl, "");
1593
- }
1594
- else {
1595
- const children = this.children;
1596
- const l = children.length;
1597
- if (l) {
1598
- const remove = children[0].remove;
1599
- for (let i = 0; i < l; i++) {
1600
- remove.call(children[i]);
1601
- }
1602
- }
1603
- nodeRemoveChild$1.call(parentEl, anchor);
1604
- }
1605
- }
1606
- firstNode() {
1607
- const child = this.children[0];
1608
- return child ? child.firstNode() : undefined;
1609
- }
1610
- toString() {
1611
- return this.children.map((c) => c.toString()).join("");
1612
- }
1613
- }
1614
- function list(children) {
1615
- return new VList(children);
1616
- }
1617
- function createMapping(ch1, startIdx1, endIdx2) {
1618
- let mapping = {};
1619
- for (let i = startIdx1; i <= endIdx2; i++) {
1620
- mapping[ch1[i].key] = i;
1621
- }
1622
- return mapping;
1623
- }
1624
-
1625
- const nodeProto = Node.prototype;
1626
- const nodeInsertBefore = nodeProto.insertBefore;
1627
- const nodeRemoveChild = nodeProto.removeChild;
1628
- class VHtml {
1629
- constructor(html) {
1630
- this.content = [];
1631
- this.html = html;
1632
- }
1633
- mount(parent, afterNode) {
1634
- this.parentEl = parent;
1635
- const template = document.createElement("template");
1636
- template.innerHTML = this.html;
1637
- this.content = [...template.content.childNodes];
1638
- for (let elem of this.content) {
1639
- nodeInsertBefore.call(parent, elem, afterNode);
1640
- }
1641
- if (!this.content.length) {
1642
- const textNode = document.createTextNode("");
1643
- this.content.push(textNode);
1644
- nodeInsertBefore.call(parent, textNode, afterNode);
1645
- }
1646
- }
1647
- moveBeforeDOMNode(node, parent = this.parentEl) {
1648
- this.parentEl = parent;
1649
- for (let elem of this.content) {
1650
- nodeInsertBefore.call(parent, elem, node);
1651
- }
1652
- }
1653
- moveBeforeVNode(other, afterNode) {
1654
- const target = other ? other.content[0] : afterNode;
1655
- this.moveBeforeDOMNode(target);
1656
- }
1657
- patch(other) {
1658
- if (this === other) {
1659
- return;
1660
- }
1661
- const html2 = other.html;
1662
- if (this.html !== html2) {
1663
- const parent = this.parentEl;
1664
- // insert new html in front of current
1665
- const afterNode = this.content[0];
1666
- const template = document.createElement("template");
1667
- template.innerHTML = html2;
1668
- const content = [...template.content.childNodes];
1669
- for (let elem of content) {
1670
- nodeInsertBefore.call(parent, elem, afterNode);
1671
- }
1672
- if (!content.length) {
1673
- const textNode = document.createTextNode("");
1674
- content.push(textNode);
1675
- nodeInsertBefore.call(parent, textNode, afterNode);
1676
- }
1677
- // remove current content
1678
- this.remove();
1679
- this.content = content;
1680
- this.html = other.html;
1681
- }
1682
- }
1683
- beforeRemove() { }
1684
- remove() {
1685
- const parent = this.parentEl;
1686
- for (let elem of this.content) {
1687
- nodeRemoveChild.call(parent, elem);
1688
- }
1689
- }
1690
- firstNode() {
1691
- return this.content[0];
1692
- }
1693
- toString() {
1694
- return this.html;
1695
- }
1696
- }
1697
- function html(str) {
1698
- return new VHtml(str);
1699
- }
1700
-
1701
- function createCatcher(eventsSpec) {
1702
- const n = Object.keys(eventsSpec).length;
1703
- class VCatcher {
1704
- constructor(child, handlers) {
1705
- this.handlerFns = [];
1706
- this.afterNode = null;
1707
- this.child = child;
1708
- this.handlerData = handlers;
1709
- }
1710
- mount(parent, afterNode) {
1711
- this.parentEl = parent;
1712
- this.child.mount(parent, afterNode);
1713
- this.afterNode = document.createTextNode("");
1714
- parent.insertBefore(this.afterNode, afterNode);
1715
- this.wrapHandlerData();
1716
- for (let name in eventsSpec) {
1717
- const index = eventsSpec[name];
1718
- const handler = createEventHandler(name);
1719
- this.handlerFns[index] = handler;
1720
- handler.setup.call(parent, this.handlerData[index]);
1721
- }
1722
- }
1723
- wrapHandlerData() {
1724
- for (let i = 0; i < n; i++) {
1725
- let handler = this.handlerData[i];
1726
- // handler = [...mods, fn, comp], so we need to replace second to last elem
1727
- let idx = handler.length - 2;
1728
- let origFn = handler[idx];
1729
- const self = this;
1730
- handler[idx] = function (ev) {
1731
- const target = ev.target;
1732
- let currentNode = self.child.firstNode();
1733
- const afterNode = self.afterNode;
1734
- while (currentNode && currentNode !== afterNode) {
1735
- if (currentNode.contains(target)) {
1736
- return origFn.call(this, ev);
1737
- }
1738
- currentNode = currentNode.nextSibling;
1739
- }
1740
- };
1741
- }
1742
- }
1743
- moveBeforeDOMNode(node, parent = this.parentEl) {
1744
- this.parentEl = parent;
1745
- this.child.moveBeforeDOMNode(node, parent);
1746
- parent.insertBefore(this.afterNode, node);
1747
- }
1748
- moveBeforeVNode(other, afterNode) {
1749
- if (other) {
1750
- // check this with @ged-odoo for use in foreach
1751
- afterNode = other.firstNode() || afterNode;
1752
- }
1753
- this.child.moveBeforeVNode(other ? other.child : null, afterNode);
1754
- this.parentEl.insertBefore(this.afterNode, afterNode);
1755
- }
1756
- patch(other, withBeforeRemove) {
1757
- if (this === other) {
1758
- return;
1759
- }
1760
- this.handlerData = other.handlerData;
1761
- this.wrapHandlerData();
1762
- for (let i = 0; i < n; i++) {
1763
- this.handlerFns[i].update.call(this.parentEl, this.handlerData[i]);
1764
- }
1765
- this.child.patch(other.child, withBeforeRemove);
1766
- }
1767
- beforeRemove() {
1768
- this.child.beforeRemove();
1769
- }
1770
- remove() {
1771
- for (let i = 0; i < n; i++) {
1772
- this.handlerFns[i].remove.call(this.parentEl);
1773
- }
1774
- this.child.remove();
1775
- this.afterNode.remove();
1776
- }
1777
- firstNode() {
1778
- return this.child.firstNode();
1779
- }
1780
- toString() {
1781
- return this.child.toString();
1782
- }
1783
- }
1784
- return function (child, handlers) {
1785
- return new VCatcher(child, handlers);
1786
- };
1787
- }
1788
-
1789
- function mount$1(vnode, fixture, afterNode = null) {
1790
- vnode.mount(fixture, afterNode);
1791
- }
1792
- function patch(vnode1, vnode2, withBeforeRemove = false) {
1793
- vnode1.patch(vnode2, withBeforeRemove);
1794
- }
1795
- function remove(vnode, withBeforeRemove = false) {
1796
- if (withBeforeRemove) {
1797
- vnode.beforeRemove();
1798
- }
1799
- vnode.remove();
1800
- }
1801
-
1802
- function makeRootFiber(node) {
1803
- let current = node.fiber;
1804
- if (current) {
1805
- let root = current.root;
1806
- // lock root fiber because canceling children fibers may destroy components,
1807
- // which means any arbitrary code can be run in onWillDestroy, which may
1808
- // trigger new renderings
1809
- root.locked = true;
1810
- root.setCounter(root.counter + 1 - cancelFibers(current.children));
1811
- root.locked = false;
1812
- current.children = [];
1813
- current.childrenMap = {};
1814
- current.bdom = null;
1815
- if (fibersInError.has(current)) {
1816
- fibersInError.delete(current);
1817
- fibersInError.delete(root);
1818
- current.appliedToDom = false;
1819
- if (current instanceof RootFiber) {
1820
- // it is possible that this fiber is a fiber that crashed while being
1821
- // mounted, so the mounted list is possibly corrupted. We restore it to
1822
- // its normal initial state (which is empty list or a list with a mount
1823
- // fiber.
1824
- current.mounted = current instanceof MountFiber ? [current] : [];
1825
- }
1826
- }
1827
- return current;
1828
- }
1829
- const fiber = new RootFiber(node, null);
1830
- if (node.willPatch.length) {
1831
- fiber.willPatch.push(fiber);
1832
- }
1833
- if (node.patched.length) {
1834
- fiber.patched.push(fiber);
1835
- }
1836
- return fiber;
1837
- }
1838
- function throwOnRender() {
1839
- throw new OwlError("Attempted to render cancelled fiber");
1840
- }
1841
- /**
1842
- * @returns number of not-yet rendered fibers cancelled
1843
- */
1844
- function cancelFibers(fibers) {
1845
- let result = 0;
1846
- for (let fiber of fibers) {
1847
- let node = fiber.node;
1848
- fiber.render = throwOnRender;
1849
- if (node.status === 0 /* STATUS.NEW */) {
1850
- node.cancel();
1851
- }
1852
- node.fiber = null;
1853
- if (fiber.bdom) {
1854
- // if fiber has been rendered, this means that the component props have
1855
- // been updated. however, this fiber will not be patched to the dom, so
1856
- // it could happen that the next render compare the current props with
1857
- // the same props, and skip the render completely. With the next line,
1858
- // we kindly request the component code to force a render, so it works as
1859
- // expected.
1860
- node.forceNextRender = true;
1861
- }
1862
- else {
1863
- result++;
1864
- }
1865
- result += cancelFibers(fiber.children);
1866
- }
1867
- return result;
1868
- }
1869
- class Fiber {
1870
- constructor(node, parent) {
1871
- this.bdom = null;
1872
- this.children = [];
1873
- this.appliedToDom = false;
1874
- this.childrenMap = {};
1875
- this.node = node;
1876
- this.parent = parent;
1877
- if (parent) {
1878
- const root = parent.root;
1879
- root.setCounter(root.counter + 1);
1880
- this.root = root;
1881
- parent.children.push(this);
1882
- }
1883
- else {
1884
- this.root = this;
1885
- }
1886
- }
1887
- render() {
1888
- // if some parent has a fiber => register in followup
1889
- let prev = this.root.node;
1890
- let scheduler = prev.app.scheduler;
1891
- let current = prev.parent;
1892
- while (current) {
1893
- if (current.fiber) {
1894
- let root = current.fiber.root;
1895
- if (root.counter === 0 && prev.parentKey in current.fiber.childrenMap) {
1896
- current = root.node;
1897
- }
1898
- else {
1899
- scheduler.delayedRenders.push(this);
1900
- return;
1901
- }
1902
- }
1903
- prev = current;
1904
- current = current.parent;
1905
- }
1906
- // there are no current rendering from above => we can render
1907
- this._render();
1908
- }
1909
- _render() {
1910
- const node = this.node;
1911
- const root = this.root;
1912
- if (root) {
1913
- // todo: should use updateComputation somewhere else.
1914
- runWithComputation(node.signalComputation, () => {
1915
- try {
1916
- this.bdom = true;
1917
- this.bdom = node.renderFn();
1918
- }
1919
- catch (e) {
1920
- node.app.handleError({ node, error: e });
1921
- }
1922
- });
1923
- root.setCounter(root.counter - 1);
1924
- }
1925
- }
1926
- }
1927
- class RootFiber extends Fiber {
1928
- constructor() {
1929
- super(...arguments);
1930
- this.counter = 1;
1931
- // only add stuff in this if they have registered some hooks
1932
- this.willPatch = [];
1933
- this.patched = [];
1934
- this.mounted = [];
1935
- // A fiber is typically locked when it is completing and the patch has not, or is being applied.
1936
- // i.e.: render triggered in onWillUnmount or in willPatch will be delayed
1937
- this.locked = false;
1938
- }
1939
- complete() {
1940
- const node = this.node;
1941
- this.locked = true;
1942
- let current = undefined;
1943
- let mountedFibers = this.mounted;
1944
- try {
1945
- // Step 1: calling all willPatch lifecycle hooks
1946
- for (current of this.willPatch) {
1947
- // because of the asynchronous nature of the rendering, some parts of the
1948
- // UI may have been rendered, then deleted in a followup rendering, and we
1949
- // do not want to call onWillPatch in that case.
1950
- let node = current.node;
1951
- if (node.fiber === current) {
1952
- const component = node.component;
1953
- for (let cb of node.willPatch) {
1954
- cb.call(component);
1955
- }
1956
- }
1957
- }
1958
- current = undefined;
1959
- // Step 2: patching the dom
1960
- node._patch();
1961
- this.locked = false;
1962
- // Step 4: calling all mounted lifecycle hooks
1963
- while ((current = mountedFibers.pop())) {
1964
- current = current;
1965
- if (current.appliedToDom) {
1966
- for (let cb of current.node.mounted) {
1967
- cb();
1968
- }
1969
- }
1970
- }
1971
- // Step 5: calling all patched hooks
1972
- let patchedFibers = this.patched;
1973
- while ((current = patchedFibers.pop())) {
1974
- current = current;
1975
- if (current.appliedToDom) {
1976
- for (let cb of current.node.patched) {
1977
- cb();
1978
- }
1979
- }
1980
- }
1981
- }
1982
- catch (e) {
1983
- // if mountedFibers is not empty, this means that a crash occured while
1984
- // calling the mounted hooks of some component. So, there may still be
1985
- // some component that have been mounted, but for which the mounted hooks
1986
- // have not been called. Here, we remove the willUnmount hooks for these
1987
- // specific component to prevent a worse situation (willUnmount being
1988
- // called even though mounted has not been called)
1989
- for (let fiber of mountedFibers) {
1990
- fiber.node.willUnmount = [];
1991
- }
1992
- this.locked = false;
1993
- node.app.handleError({ fiber: current || this, error: e });
1994
- }
1995
- }
1996
- setCounter(newValue) {
1997
- this.counter = newValue;
1998
- if (newValue === 0) {
1999
- this.node.app.scheduler.flush();
2000
- }
2001
- }
2002
- }
2003
- class MountFiber extends RootFiber {
2004
- constructor(node, target, options = {}) {
2005
- super(node, null);
2006
- this.target = target;
2007
- this.position = options.position || "last-child";
2008
- }
2009
- complete() {
2010
- let current = this;
2011
- try {
2012
- const node = this.node;
2013
- node.children = this.childrenMap;
2014
- node.app.constructor.validateTarget(this.target);
2015
- if (node.bdom) {
2016
- // this is a complicated situation: if we mount a fiber with an existing
2017
- // bdom, this means that this same fiber was already completed, mounted,
2018
- // but a crash occurred in some mounted hook. Then, it was handled and
2019
- // the new rendering is being applied.
2020
- node.updateDom();
2021
- }
2022
- else {
2023
- node.bdom = this.bdom;
2024
- if (this.position === "last-child" || this.target.childNodes.length === 0) {
2025
- mount$1(node.bdom, this.target);
2026
- }
2027
- else {
2028
- const firstChild = this.target.childNodes[0];
2029
- mount$1(node.bdom, this.target, firstChild);
2030
- }
2031
- }
2032
- // unregistering the fiber before mounted since it can do another render
2033
- // and that the current rendering is obviously completed
2034
- node.fiber = null;
2035
- node.status = 1 /* STATUS.MOUNTED */;
2036
- this.appliedToDom = true;
2037
- let mountedFibers = this.mounted;
2038
- while ((current = mountedFibers.pop())) {
2039
- if (current.appliedToDom) {
2040
- for (let cb of current.node.mounted) {
2041
- cb();
2042
- }
2043
- }
2044
- }
2045
- }
2046
- catch (e) {
2047
- this.node.app.handleError({ fiber: current, error: e });
2048
- }
2049
- }
2050
- }
2051
-
2052
- let currentNode = null;
2053
- function saveCurrent() {
2054
- let n = currentNode;
2055
- return () => {
2056
- currentNode = n;
2057
- };
2058
- }
2059
- function getCurrent() {
2060
- if (!currentNode) {
2061
- throw new OwlError("No active component (a hook function should only be called in 'setup')");
2062
- }
2063
- return currentNode;
2064
- }
2065
- function useComponent() {
2066
- return currentNode.component;
2067
- }
2068
- class ComponentNode {
2069
- constructor(C, props, app, parent, parentKey) {
2070
- this.fiber = null;
2071
- this.bdom = null;
2072
- this.status = 0 /* STATUS.NEW */;
2073
- this.forceNextRender = false;
2074
- this.children = Object.create(null);
2075
- this.willStart = [];
2076
- this.willUnmount = [];
2077
- this.mounted = [];
2078
- this.willPatch = [];
2079
- this.patched = [];
2080
- this.willDestroy = [];
2081
- this.name = C.name;
2082
- currentNode = this;
2083
- this.app = app;
2084
- this.parent = parent;
2085
- this.parentKey = parentKey;
2086
- this.pluginManager = parent ? parent.pluginManager : app.pluginManager;
2087
- this.signalComputation = {
2088
- value: undefined,
2089
- compute: () => this.render(false),
2090
- sources: new Set(),
2091
- state: ComputationState.EXECUTED,
2092
- };
2093
- this.props = Object.assign({}, props);
2094
- const previousComputation = getCurrentComputation();
2095
- setComputation(undefined);
2096
- this.component = new C(this);
2097
- const ctx = { this: this.component, __owl__: this };
2098
- this.renderFn = app.getTemplate(C.template).bind(this.component, ctx, this);
2099
- this.component.setup();
2100
- setComputation(previousComputation);
2101
- currentNode = null;
2102
- }
2103
- mountComponent(target, options) {
2104
- const fiber = new MountFiber(this, target, options);
2105
- this.app.scheduler.addFiber(fiber);
2106
- this.initiateRender(fiber);
2107
- }
2108
- async initiateRender(fiber) {
2109
- this.fiber = fiber;
2110
- if (this.mounted.length) {
2111
- fiber.root.mounted.push(fiber);
2112
- }
2113
- const component = this.component;
2114
- try {
2115
- let promises;
2116
- runWithComputation(undefined, () => {
2117
- promises = this.willStart.map((f) => f.call(component));
2118
- });
2119
- await Promise.all(promises);
2120
- }
2121
- catch (e) {
2122
- this.app.handleError({ node: this, error: e });
2123
- return;
2124
- }
2125
- if (this.status === 0 /* STATUS.NEW */ && this.fiber === fiber) {
2126
- fiber.render();
2127
- }
2128
- }
2129
- async render(deep) {
2130
- if (this.status >= 2 /* STATUS.CANCELLED */) {
2131
- return;
2132
- }
2133
- let current = this.fiber;
2134
- if (current && (current.root.locked || current.bdom === true)) {
2135
- await Promise.resolve();
2136
- // situation may have changed after the microtask tick
2137
- current = this.fiber;
2138
- }
2139
- if ((current && !current.bdom && !fibersInError.has(current)) || (!current && !this.bdom)) {
2140
- return;
2141
- }
2142
- const fiber = makeRootFiber(this);
2143
- this.fiber = fiber;
2144
- this.app.scheduler.addFiber(fiber);
2145
- await Promise.resolve();
2146
- if (this.status >= 2 /* STATUS.CANCELLED */) {
2147
- return;
2148
- }
2149
- // We only want to actually render the component if the following two
2150
- // conditions are true:
2151
- // * this.fiber: it could be null, in which case the render has been cancelled
2152
- // * (current || !fiber.parent): if current is not null, this means that the
2153
- // render function was called when a render was already occurring. In this
2154
- // case, the pending rendering was cancelled, and the fiber needs to be
2155
- // rendered to complete the work. If current is null, we check that the
2156
- // fiber has no parent. If that is the case, the fiber was downgraded from
2157
- // a root fiber to a child fiber in the previous microtick, because it was
2158
- // embedded in a rendering coming from above, so the fiber will be rendered
2159
- // in the next microtick anyway, so we should not render it again.
2160
- if (this.fiber === fiber && (current || !fiber.parent)) {
2161
- fiber.render();
2162
- }
2163
- }
2164
- cancel() {
2165
- this._cancel();
2166
- delete this.parent.children[this.parentKey];
2167
- this.app.scheduler.scheduleDestroy(this);
2168
- }
2169
- _cancel() {
2170
- this.status = 2 /* STATUS.CANCELLED */;
2171
- const children = this.children;
2172
- for (let childKey in children) {
2173
- children[childKey]._cancel();
2174
- }
2175
- }
2176
- destroy() {
2177
- let shouldRemove = this.status === 1 /* STATUS.MOUNTED */;
2178
- this._destroy();
2179
- if (shouldRemove) {
2180
- this.bdom.remove();
2181
- }
2182
- }
2183
- _destroy() {
2184
- const component = this.component;
2185
- if (this.status === 1 /* STATUS.MOUNTED */) {
2186
- for (let cb of this.willUnmount) {
2187
- cb.call(component);
2188
- }
2189
- }
2190
- for (let child of Object.values(this.children)) {
2191
- child._destroy();
2192
- }
2193
- if (this.willDestroy.length) {
2194
- try {
2195
- for (let cb of this.willDestroy) {
2196
- cb.call(component);
2197
- }
2198
- }
2199
- catch (e) {
2200
- this.app.handleError({ error: e, node: this });
2201
- }
2202
- }
2203
- this.status = 3 /* STATUS.DESTROYED */;
2204
- }
2205
- /**
2206
- * Finds a child that has dom that is not yet updated, and update it. This
2207
- * method is meant to be used only in the context of repatching the dom after
2208
- * a mounted hook failed and was handled.
2209
- */
2210
- updateDom() {
2211
- if (!this.fiber) {
2212
- return;
2213
- }
2214
- if (this.bdom === this.fiber.bdom) {
2215
- // If the error was handled by some child component, we need to find it to
2216
- // apply its change
2217
- for (let k in this.children) {
2218
- const child = this.children[k];
2219
- child.updateDom();
2220
- }
2221
- }
2222
- else {
2223
- // if we get here, this is the component that handled the error and rerendered
2224
- // itself, so we can simply patch the dom
2225
- this.bdom.patch(this.fiber.bdom, false);
2226
- this.fiber.appliedToDom = true;
2227
- this.fiber = null;
2228
- }
2229
- }
2230
- // ---------------------------------------------------------------------------
2231
- // Block DOM methods
2232
- // ---------------------------------------------------------------------------
2233
- firstNode() {
2234
- const bdom = this.bdom;
2235
- return bdom ? bdom.firstNode() : undefined;
2236
- }
2237
- mount(parent, anchor) {
2238
- const bdom = this.fiber.bdom;
2239
- this.bdom = bdom;
2240
- bdom.mount(parent, anchor);
2241
- this.status = 1 /* STATUS.MOUNTED */;
2242
- this.fiber.appliedToDom = true;
2243
- this.children = this.fiber.childrenMap;
2244
- this.fiber = null;
2245
- }
2246
- moveBeforeDOMNode(node, parent) {
2247
- this.bdom.moveBeforeDOMNode(node, parent);
2248
- }
2249
- moveBeforeVNode(other, afterNode) {
2250
- this.bdom.moveBeforeVNode(other ? other.bdom : null, afterNode);
2251
- }
2252
- patch() {
2253
- if (this.fiber && this.fiber.parent) {
2254
- // we only patch here renderings coming from above. renderings initiated
2255
- // by the component will be patched independently in the appropriate
2256
- // fiber.complete
2257
- this._patch();
2258
- }
2259
- }
2260
- _patch() {
2261
- let hasChildren = false;
2262
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2263
- for (let _k in this.children) {
2264
- hasChildren = true;
2265
- break;
2266
- }
2267
- const fiber = this.fiber;
2268
- this.children = fiber.childrenMap;
2269
- this.bdom.patch(fiber.bdom, hasChildren);
2270
- fiber.appliedToDom = true;
2271
- this.fiber = null;
2272
- }
2273
- beforeRemove() {
2274
- this._destroy();
2275
- }
2276
- remove() {
2277
- this.bdom.remove();
2278
- }
2279
- }
2280
-
2281
- function assertType(value, validation) {
2282
- const issues = validateType(value, validation);
2283
- if (issues.length) {
2284
- const issueStrings = JSON.stringify(issues, (key, value) => {
2285
- if (typeof value === "function") {
2286
- return value.name;
2287
- }
2288
- return value;
2289
- }, 2);
2290
- throw new OwlError(`Value does not match the type\n${issueStrings}`);
2291
- }
2292
- }
2293
- function validateType(value, validation) {
2294
- return validation(value);
2295
- }
2296
-
2297
- const any = function () {
2298
- return [];
2299
- };
2300
- const boolean = function validateBoolean(value) {
2301
- if (typeof value !== "boolean") {
2302
- return [{ type: "type", expected: Boolean, received: value }];
2303
- }
2304
- return [];
2305
- };
2306
- const number = function validateNumber(value) {
2307
- if (typeof value !== "number") {
2308
- return [{ type: "type", expected: Number, received: value }];
2309
- }
2310
- return [];
2311
- };
2312
- const string = function validateString(value) {
2313
- if (typeof value !== "string") {
2314
- return [{ type: "type", expected: String, received: value }];
2315
- }
2316
- return [];
2317
- };
2318
- function array(type) {
2319
- return function validateArray(value) {
2320
- if (!Array.isArray(value)) {
2321
- return [{ type: "type", expected: Array, received: value }];
2322
- }
2323
- if (type) {
2324
- return value.flatMap((element) => validateType(element, type));
2325
- }
2326
- return [];
2327
- };
2328
- }
2329
- function func(parameters, result) {
2330
- return function validateFunction(value) {
2331
- if (typeof value !== "function") {
2332
- return [{ type: "type", expected: Function, received: value }];
2333
- }
2334
- return [];
2335
- };
2336
- }
2337
- function instanceOf(type) {
2338
- return function validateInstanceOf(value) {
2339
- if (!(value instanceof type)) {
2340
- return [{ type: "type", expected: type, received: value }];
2341
- }
2342
- return [];
2343
- };
2344
- }
2345
- function keys(...keys) {
2346
- return function validateKeys(value) {
2347
- if (typeof value !== "object") {
2348
- return [{ type: "type", expected: Object, received: value }];
2349
- }
2350
- const valueKeys = Object.keys(value);
2351
- const missingKeys = keys.filter((key) => {
2352
- if (key.endsWith("?")) {
2353
- return true;
2354
- }
2355
- return !valueKeys.includes(key);
2356
- });
2357
- if (missingKeys.length) {
2358
- return [{ type: "missing keys", value, missingKeys }];
2359
- }
2360
- return [];
2361
- };
2362
- }
2363
- function literal(literal) {
2364
- return function validateLiteral(value) {
2365
- if (value !== literal) {
2366
- return [{ type: "exact value", expected: literal, received: value }];
2367
- }
2368
- return [];
2369
- };
2370
- }
2371
- function object(shape) {
2372
- return function validateObject(value) {
2373
- if (typeof value !== "object") {
2374
- return [{ type: "type", expected: Object, received: value }];
2375
- }
2376
- if (shape) {
2377
- const missingKeys = [];
2378
- const issues = [];
2379
- for (let key in shape) {
2380
- const subIssues = validateType(value[key], shape[key]);
2381
- if (key in value) {
2382
- issues.push(...subIssues);
2383
- }
2384
- else {
2385
- missingKeys.push(key);
2386
- }
2387
- }
2388
- if (missingKeys.length) {
2389
- issues.push({ type: "missing keys", value, missingKeys });
2390
- }
2391
- return issues;
2392
- }
2393
- return [];
2394
- };
2395
- }
2396
- function optional(type) {
2397
- return function validateOptional(value) {
2398
- if (value === undefined) {
2399
- return [];
2400
- }
2401
- return validateType(value, type);
2402
- };
2403
- }
2404
- function record(valueType) {
2405
- return function validateRecord(value) {
2406
- if (typeof value !== "object") {
2407
- return [{ type: "type", expected: Object, received: value }];
2408
- }
2409
- const issues = [];
2410
- for (let key in value) {
2411
- issues.push(...validateType(value[key], valueType));
2412
- }
2413
- return issues;
2414
- };
2415
- }
2416
- function tuple(...types) {
2417
- return function validateTuple(value) {
2418
- if (!Array.isArray(value)) {
2419
- return [{ type: "type", expected: Array, received: value }];
2420
- }
2421
- if (value.length !== types.length) {
2422
- return [{ type: "length", expected: types.length, received: value.length }];
2423
- }
2424
- return types.flatMap((type, index) => validateType(value[index], type));
2425
- };
2426
- }
2427
- function constructor(type) {
2428
- return function validateClass(value) {
2429
- if (!(typeof value === "function") || !(value === type || value.prototype instanceof type)) {
2430
- return [{ type: "type" }];
2431
- }
2432
- return [];
2433
- };
2434
- }
2435
- function union(...types) {
2436
- return function validateUnion(value) {
2437
- const validations = types.filter((type) => validateType(value, type).length);
2438
- if (validations.length) {
2439
- return [{ type: "union" }];
2440
- }
2441
- return [];
2442
- };
2443
- }
2444
- function signal$1(type) {
2445
- return function validateSignal(value) {
2446
- if (typeof value !== "function") {
2447
- return [{ type: "type", expected: Function, received: value }];
2448
- }
2449
- if (typeof value.set !== "function") {
2450
- return [{ type: "type", expected: Function, received: value.set }];
2451
- }
2452
- return [];
2453
- };
2454
- }
2455
- function reactiveValue(type) {
2456
- return function validateReactiveValue(value) {
2457
- if (typeof value !== "function") {
2458
- return [{ type: "type", expected: Function, received: value }];
2459
- }
2460
- return [];
2461
- };
2462
- }
2463
-
2464
- var types = {
2465
- __proto__: null,
2466
- any: any,
2467
- boolean: boolean,
2468
- number: number,
2469
- string: string,
2470
- array: array,
2471
- func: func,
2472
- instanceOf: instanceOf,
2473
- keys: keys,
2474
- literal: literal,
2475
- object: object,
2476
- optional: optional,
2477
- record: record,
2478
- tuple: tuple,
2479
- constructor: constructor,
2480
- union: union,
2481
- signal: signal$1,
2482
- reactiveValue: reactiveValue
2483
- };
2484
-
2485
- let currentProps = {};
2486
- class Plugin {
2487
- static get id() {
2488
- var _a;
2489
- return (_a = this._shadowId) !== null && _a !== void 0 ? _a : this.name;
2490
- }
2491
- static set id(shadowId) {
2492
- this._shadowId = shadowId;
2493
- }
2494
- setup() { }
2495
- }
2496
- class PluginManager {
2497
- constructor(parent) {
2498
- var _a;
2499
- this.children = [];
2500
- this.onDestroyCb = [];
2501
- this.status = 0 /* STATUS.NEW */;
2502
- this.parent = parent || null;
2503
- (_a = this.parent) === null || _a === void 0 ? void 0 : _a.children.push(this);
2504
- this.plugins = this.parent ? Object.create(this.parent.plugins) : {};
2505
- }
2506
- destroy() {
2507
- for (let children of this.children) {
2508
- children.destroy();
2509
- }
2510
- const cbs = this.onDestroyCb;
2511
- while (cbs.length) {
2512
- cbs.pop()();
2513
- }
2514
- this.status = 3 /* STATUS.DESTROYED */;
2515
- }
2516
- getPluginById(id) {
2517
- return this.plugins[id] || null;
2518
- }
2519
- getPlugin(pluginType) {
2520
- return this.getPluginById(pluginType.id);
2521
- }
2522
- startPlugins(pluginTypes, pluginProps = {}) {
2523
- const previousManager = PluginManager.current;
2524
- PluginManager.current = this;
2525
- const plugins = [];
2526
- // instantiate plugins
2527
- for (const pluginType of pluginTypes) {
2528
- if (!pluginType.id) {
2529
- PluginManager.current = previousManager;
2530
- throw new OwlError(`Plugin "${pluginType.name}" has no id`);
2531
- }
2532
- if (this.plugins.hasOwnProperty(pluginType.id)) {
2533
- const existingPluginType = this.getPluginById(pluginType.id).constructor;
2534
- if (existingPluginType !== pluginType) {
2535
- PluginManager.current = previousManager;
2536
- throw new OwlError(`Trying to start a plugin with the same id as an other plugin (id: '${pluginType.id}', existing plugin: '${existingPluginType.name}', starting plugin: '${pluginType.name}')`);
2537
- }
2538
- continue;
2539
- }
2540
- currentProps = pluginProps[pluginType.id] || {};
2541
- const plugin = new pluginType();
2542
- this.plugins[pluginType.id] = plugin;
2543
- plugins.push(plugin);
2544
- }
2545
- currentProps = {};
2546
- // setup phase
2547
- for (let p of plugins) {
2548
- p.setup();
2549
- }
2550
- PluginManager.current = previousManager;
2551
- if (!PluginManager.current) {
2552
- this.status = 1 /* STATUS.MOUNTED */;
2553
- }
2554
- return plugins;
2555
- }
2556
- }
2557
- // kind of public to make it possible to manipulate from the outside
2558
- PluginManager.current = null;
2559
- function plugin(pluginType) {
2560
- // getCurrent will throw if we're not in a component
2561
- const manager = PluginManager.current || getCurrent().pluginManager;
2562
- let plugin = manager.getPluginById(pluginType.id);
2563
- if (!plugin) {
2564
- if (manager === PluginManager.current) {
2565
- manager.startPlugins([pluginType]);
2566
- plugin = manager.getPluginById(pluginType.id);
2567
- }
2568
- else {
2569
- throw new OwlError(`Unknown plugin "${pluginType.id}"`);
2570
- }
2571
- }
2572
- return plugin;
2573
- }
2574
- // todo: remove duplication with the actual props function
2575
- plugin.props = function props(type, defaults = {}) {
2576
- function getProp(key) {
2577
- if (currentProps[key] === undefined) {
2578
- return defaults[key];
2579
- }
2580
- return currentProps[key];
2581
- }
2582
- const result = Object.create(null);
2583
- function applyPropGetters(keys) {
2584
- for (const key of keys) {
2585
- Reflect.defineProperty(result, key, {
2586
- enumerable: true,
2587
- get: getProp.bind(null, key),
2588
- });
2589
- }
2590
- }
2591
- if (type) {
2592
- const isSchemaValidated = type && !Array.isArray(type);
2593
- applyPropGetters((isSchemaValidated ? Object.keys(type) : type).map((key) => key.endsWith("?") ? key.slice(0, -1) : key));
2594
- const app = getCurrent().app;
2595
- if (app.dev) {
2596
- const validation = isSchemaValidated ? object(type) : keys(...type);
2597
- assertType(currentProps, validation);
2598
- }
2599
- }
2600
- else {
2601
- applyPropGetters(Object.keys(currentProps));
2602
- }
2603
- return currentProps;
2604
- };
2605
-
2606
- // Special key to subscribe to, to be notified of key creation/deletion
2607
- const KEYCHANGES = Symbol("Key changes");
2608
- const objectToString = Object.prototype.toString;
2609
- const objectHasOwnProperty = Object.prototype.hasOwnProperty;
2610
- // Use arrays because Array.includes is faster than Set.has for small arrays
2611
- const SUPPORTED_RAW_TYPES = ["Object", "Array", "Set", "Map", "WeakMap"];
2612
- const COLLECTION_RAW_TYPES = ["Set", "Map", "WeakMap"];
2613
- /**
2614
- * extract "RawType" from strings like "[object RawType]" => this lets us ignore
2615
- * many native objects such as Promise (whose toString is [object Promise])
2616
- * or Date ([object Date]), while also supporting collections without using
2617
- * instanceof in a loop
2618
- *
2619
- * @param obj the object to check
2620
- * @returns the raw type of the object
2621
- */
2622
- function rawType(obj) {
2623
- return objectToString.call(toRaw(obj)).slice(8, -1);
2624
- }
2625
- /**
2626
- * Checks whether a given value can be made into a proxy object.
2627
- *
2628
- * @param value the value to check
2629
- * @returns whether the value can be made proxy
2630
- */
2631
- function canBeMadeReactive(value) {
2632
- if (typeof value !== "object") {
2633
- return false;
2634
- }
2635
- return SUPPORTED_RAW_TYPES.includes(rawType(value));
2636
- }
2637
- /**
2638
- * Creates a proxy from the given object/callback if possible and returns it,
2639
- * returns the original object otherwise.
2640
- *
2641
- * @param value the value make proxy
2642
- * @returns a proxy for the given object when possible, the original otherwise
2643
- */
2644
- function possiblyReactive(val, atom) {
2645
- return !atom && canBeMadeReactive(val) ? proxy(val) : val;
2646
- }
2647
- const skipped = new WeakSet();
2648
- /**
2649
- * Mark an object or array so that it is ignored by the reactivity system
2650
- *
2651
- * @param value the value to mark
2652
- * @returns the object itself
2653
- */
2654
- function markRaw(value) {
2655
- skipped.add(value);
2656
- return value;
2657
- }
2658
- /**
2659
- * Given a proxy objet, return the raw (non proxy) underlying object
2660
- *
2661
- * @param value a proxy value
2662
- * @returns the underlying value
2663
- */
2664
- function toRaw(value) {
2665
- return targets.has(value) ? targets.get(value) : value;
2666
- }
2667
- const targetToKeysToAtomItem = new WeakMap();
2668
- function getTargetKeyAtom(target, key) {
2669
- let keyToAtomItem = targetToKeysToAtomItem.get(target);
2670
- if (!keyToAtomItem) {
2671
- keyToAtomItem = new Map();
2672
- targetToKeysToAtomItem.set(target, keyToAtomItem);
2673
- }
2674
- let atom = keyToAtomItem.get(key);
2675
- if (!atom) {
2676
- atom = {
2677
- value: undefined,
2678
- observers: new Set(),
2679
- };
2680
- keyToAtomItem.set(key, atom);
2681
- }
2682
- return atom;
2683
- }
2684
- /**
2685
- * Observes a given key on a target with an callback. The callback will be
2686
- * called when the given key changes on the target.
2687
- *
2688
- * @param target the target whose key should be observed
2689
- * @param key the key to observe (or Symbol(KEYCHANGES) for key creation
2690
- * or deletion)
2691
- * @param callback the function to call when the key changes
2692
- */
2693
- function onReadTargetKey(target, key, atom) {
2694
- onReadAtom(atom !== null && atom !== void 0 ? atom : getTargetKeyAtom(target, key));
2695
- }
2696
- /**
2697
- * Notify Reactives that are observing a given target that a key has changed on
2698
- * the target.
2699
- *
2700
- * @param target target whose Reactives should be notified that the target was
2701
- * changed.
2702
- * @param key the key that changed (or Symbol `KEYCHANGES` if a key was created
2703
- * or deleted)
2704
- */
2705
- function onWriteTargetKey(target, key, atom) {
2706
- if (!atom) {
2707
- const keyToAtomItem = targetToKeysToAtomItem.get(target);
2708
- if (!keyToAtomItem) {
2709
- return;
2710
- }
2711
- if (!keyToAtomItem.has(key)) {
2712
- return;
2713
- }
2714
- atom = keyToAtomItem.get(key);
2715
- }
2716
- onWriteAtom(atom);
2717
- }
2718
- // Maps proxy objects to the underlying target
2719
- const targets = new WeakMap();
2720
- const proxyCache = new WeakMap();
2721
- function proxifyTarget(target, atom) {
2722
- if (!canBeMadeReactive(target)) {
2723
- throw new OwlError(`Cannot make the given value reactive`);
2724
- }
2725
- if (skipped.has(target)) {
2726
- return target;
2727
- }
2728
- if (targets.has(target)) {
2729
- // target is reactive, create a reactive on the underlying object instead
2730
- return target;
2731
- }
2732
- const reactive = proxyCache.get(target);
2733
- if (reactive) {
2734
- return reactive;
2735
- }
2736
- const targetRawType = rawType(target);
2737
- const handler = COLLECTION_RAW_TYPES.includes(targetRawType)
2738
- ? collectionsProxyHandler(target, targetRawType, atom)
2739
- : basicProxyHandler(atom);
2740
- const proxy = new Proxy(target, handler);
2741
- proxyCache.set(target, proxy);
2742
- targets.set(proxy, target);
2743
- return proxy;
2744
- }
2745
- /**
2746
- * Creates a reactive proxy for an object. Reading data on the proxy object
2747
- * subscribes to changes to the data. Writing data on the object will cause the
2748
- * notify callback to be called if there are suscriptions to that data. Nested
2749
- * objects and arrays are automatically made reactive as well.
2750
- *
2751
- * Whenever you are notified of a change, all subscriptions are cleared, and if
2752
- * you would like to be notified of any further changes, you should go read
2753
- * the underlying data again. We assume that if you don't go read it again after
2754
- * being notified, it means that you are no longer interested in that data.
2755
- *
2756
- * Subscriptions:
2757
- * + Reading a property on an object will subscribe you to changes in the value
2758
- * of that property.
2759
- * + Accessing an object's keys (eg with Object.keys or with `for..in`) will
2760
- * subscribe you to the creation/deletion of keys. Checking the presence of a
2761
- * key on the object with 'in' has the same effect.
2762
- * - getOwnPropertyDescriptor does not currently subscribe you to the property.
2763
- * This is a choice that was made because changing a key's value will trigger
2764
- * this trap and we do not want to subscribe by writes. This also means that
2765
- * Object.hasOwnProperty doesn't subscribe as it goes through this trap.
2766
- *
2767
- * @param target the object for which to create a proxy proxy
2768
- * @param callback the function to call when an observed property of the
2769
- * proxy has changed
2770
- * @returns a proxy that tracks changes to it
2771
- */
2772
- function proxy(target) {
2773
- return proxifyTarget(target, null);
2774
- }
2775
- /**
2776
- * Creates a basic proxy handler for regular objects and arrays.
2777
- *
2778
- * @param callback @see proxy
2779
- * @returns a proxy handler object
2780
- */
2781
- function basicProxyHandler(atom) {
2782
- return {
2783
- get(target, key, receiver) {
2784
- // non-writable non-configurable properties cannot be made proxy
2785
- const desc = Object.getOwnPropertyDescriptor(target, key);
2786
- if (desc && !desc.writable && !desc.configurable) {
2787
- return Reflect.get(target, key, receiver);
2788
- }
2789
- onReadTargetKey(target, key, atom);
2790
- return possiblyReactive(Reflect.get(target, key, receiver), atom);
2791
- },
2792
- set(target, key, value, receiver) {
2793
- const hadKey = objectHasOwnProperty.call(target, key);
2794
- const originalValue = Reflect.get(target, key, receiver);
2795
- const ret = Reflect.set(target, key, toRaw(value), receiver);
2796
- if (!hadKey && objectHasOwnProperty.call(target, key)) {
2797
- onWriteTargetKey(target, KEYCHANGES, atom);
2798
- }
2799
- // While Array length may trigger the set trap, it's not actually set by this
2800
- // method but is updated behind the scenes, and the trap is not called with the
2801
- // new value. We disable the "same-value-optimization" for it because of that.
2802
- if (originalValue !== Reflect.get(target, key, receiver) ||
2803
- (key === "length" && Array.isArray(target))) {
2804
- onWriteTargetKey(target, key, atom);
2805
- }
2806
- return ret;
2807
- },
2808
- deleteProperty(target, key) {
2809
- const ret = Reflect.deleteProperty(target, key);
2810
- // TODO: only notify when something was actually deleted
2811
- onWriteTargetKey(target, KEYCHANGES, atom);
2812
- onWriteTargetKey(target, key, atom);
2813
- return ret;
2814
- },
2815
- ownKeys(target) {
2816
- onReadTargetKey(target, KEYCHANGES, atom);
2817
- return Reflect.ownKeys(target);
2818
- },
2819
- has(target, key) {
2820
- // TODO: this observes all key changes instead of only the presence of the argument key
2821
- // observing the key itself would observe value changes instead of presence changes
2822
- // so we may need a finer grained system to distinguish observing value vs presence.
2823
- onReadTargetKey(target, KEYCHANGES, atom);
2824
- return Reflect.has(target, key);
2825
- },
2826
- };
2827
- }
2828
- /**
2829
- * Creates a function that will observe the key that is passed to it when called
2830
- * and delegates to the underlying method.
2831
- *
2832
- * @param methodName name of the method to delegate to
2833
- * @param target @see proxy
2834
- * @param callback @see proxy
2835
- */
2836
- function makeKeyObserver(methodName, target, atom) {
2837
- return (key) => {
2838
- key = toRaw(key);
2839
- onReadTargetKey(target, key, atom);
2840
- return possiblyReactive(target[methodName](key), atom);
2841
- };
2842
- }
2843
- /**
2844
- * Creates an iterable that will delegate to the underlying iteration method and
2845
- * observe keys as necessary.
2846
- *
2847
- * @param methodName name of the method to delegate to
2848
- * @param target @see proxy
2849
- * @param callback @see proxy
2850
- */
2851
- function makeIteratorObserver(methodName, target, atom) {
2852
- return function* () {
2853
- onReadTargetKey(target, KEYCHANGES, atom);
2854
- const keys = target.keys();
2855
- for (const item of target[methodName]()) {
2856
- const key = keys.next().value;
2857
- onReadTargetKey(target, key, atom);
2858
- yield possiblyReactive(item, atom);
2859
- }
2860
- };
2861
- }
2862
- /**
2863
- * Creates a forEach function that will delegate to forEach on the underlying
2864
- * collection while observing key changes, and keys as they're iterated over,
2865
- * and making the passed keys/values proxy.
2866
- *
2867
- * @param target @see proxy
2868
- * @param callback @see proxy
2869
- */
2870
- function makeForEachObserver(target, atom) {
2871
- return function forEach(forEachCb, thisArg) {
2872
- onReadTargetKey(target, KEYCHANGES, atom);
2873
- target.forEach(function (val, key, targetObj) {
2874
- onReadTargetKey(target, key, atom);
2875
- forEachCb.call(thisArg, possiblyReactive(val, atom), possiblyReactive(key, atom), possiblyReactive(targetObj, atom));
2876
- }, thisArg);
2877
- };
2878
- }
2879
- /**
2880
- * Creates a function that will delegate to an underlying method, and check if
2881
- * that method has modified the presence or value of a key, and notify the
2882
- * proxys appropriately.
2883
- *
2884
- * @param setterName name of the method to delegate to
2885
- * @param getterName name of the method which should be used to retrieve the
2886
- * value before calling the delegate method for comparison purposes
2887
- * @param target @see proxy
2888
- */
2889
- function delegateAndNotify(setterName, getterName, target, atom) {
2890
- return (key, value) => {
2891
- key = toRaw(key);
2892
- const hadKey = target.has(key);
2893
- const originalValue = target[getterName](key);
2894
- const ret = target[setterName](key, value);
2895
- const hasKey = target.has(key);
2896
- if (hadKey !== hasKey) {
2897
- onWriteTargetKey(target, KEYCHANGES, atom);
2898
- }
2899
- if (originalValue !== target[getterName](key)) {
2900
- onWriteTargetKey(target, key, atom);
2901
- }
2902
- return ret;
2903
- };
2904
- }
2905
- /**
2906
- * Creates a function that will clear the underlying collection and notify that
2907
- * the keys of the collection have changed.
2908
- *
2909
- * @param target @see proxy
2910
- */
2911
- function makeClearNotifier(target, atom) {
2912
- return () => {
2913
- const allKeys = [...target.keys()];
2914
- target.clear();
2915
- onWriteTargetKey(target, KEYCHANGES, atom);
2916
- for (const key of allKeys) {
2917
- onWriteTargetKey(target, key, atom);
2918
- }
2919
- };
2920
- }
2921
- /**
2922
- * Maps raw type of an object to an object containing functions that can be used
2923
- * to build an appropritate proxy handler for that raw type. Eg: when making a
2924
- * proxy set, calling the has method should mark the key that is being
2925
- * retrieved as observed, and calling the add or delete method should notify the
2926
- * proxys that the key which is being added or deleted has been modified.
2927
- */
2928
- const rawTypeToFuncHandlers = {
2929
- Set: (target, atom) => ({
2930
- has: makeKeyObserver("has", target, atom),
2931
- add: delegateAndNotify("add", "has", target, atom),
2932
- delete: delegateAndNotify("delete", "has", target, atom),
2933
- keys: makeIteratorObserver("keys", target, atom),
2934
- values: makeIteratorObserver("values", target, atom),
2935
- entries: makeIteratorObserver("entries", target, atom),
2936
- [Symbol.iterator]: makeIteratorObserver(Symbol.iterator, target, atom),
2937
- forEach: makeForEachObserver(target, atom),
2938
- clear: makeClearNotifier(target, atom),
2939
- get size() {
2940
- onReadTargetKey(target, KEYCHANGES, atom);
2941
- return target.size;
2942
- },
2943
- }),
2944
- Map: (target, atom) => ({
2945
- has: makeKeyObserver("has", target, atom),
2946
- get: makeKeyObserver("get", target, atom),
2947
- set: delegateAndNotify("set", "get", target, atom),
2948
- delete: delegateAndNotify("delete", "has", target, atom),
2949
- keys: makeIteratorObserver("keys", target, atom),
2950
- values: makeIteratorObserver("values", target, atom),
2951
- entries: makeIteratorObserver("entries", target, atom),
2952
- [Symbol.iterator]: makeIteratorObserver(Symbol.iterator, target, atom),
2953
- forEach: makeForEachObserver(target, atom),
2954
- clear: makeClearNotifier(target, atom),
2955
- get size() {
2956
- onReadTargetKey(target, KEYCHANGES, atom);
2957
- return target.size;
2958
- },
2959
- }),
2960
- WeakMap: (target, atom) => ({
2961
- has: makeKeyObserver("has", target, atom),
2962
- get: makeKeyObserver("get", target, atom),
2963
- set: delegateAndNotify("set", "get", target, atom),
2964
- delete: delegateAndNotify("delete", "has", target, atom),
2965
- }),
2966
- };
2967
- /**
2968
- * Creates a proxy handler for collections (Set/Map/WeakMap)
2969
- *
2970
- * @param callback @see proxy
2971
- * @param target @see proxy
2972
- * @returns a proxy handler object
2973
- */
2974
- function collectionsProxyHandler(target, targetRawType, atom) {
2975
- // TODO: if performance is an issue we can create the special handlers lazily when each
2976
- // property is read.
2977
- const specialHandlers = rawTypeToFuncHandlers[targetRawType](target, atom);
2978
- return Object.assign(basicProxyHandler(atom), {
2979
- // FIXME: probably broken when part of prototype chain since we ignore the receiver
2980
- get(target, key) {
2981
- if (objectHasOwnProperty.call(specialHandlers, key)) {
2982
- return specialHandlers[key];
2983
- }
2984
- onReadTargetKey(target, key, atom);
2985
- return possiblyReactive(target[key], atom);
2986
- },
2987
- });
2988
- }
2989
-
2990
- // -----------------------------------------------------------------------------
2991
- // Scheduler
2992
- // -----------------------------------------------------------------------------
2993
- class Scheduler {
2994
- constructor() {
2995
- this.tasks = new Set();
2996
- this.frame = 0;
2997
- this.delayedRenders = [];
2998
- this.cancelledNodes = new Set();
2999
- this.processing = false;
3000
- this.requestAnimationFrame = Scheduler.requestAnimationFrame;
3001
- }
3002
- addFiber(fiber) {
3003
- this.tasks.add(fiber.root);
3004
- }
3005
- scheduleDestroy(node) {
3006
- this.cancelledNodes.add(node);
3007
- if (this.frame === 0) {
3008
- this.frame = this.requestAnimationFrame(() => this.processTasks());
3009
- }
3010
- }
3011
- /**
3012
- * Process all current tasks. This only applies to the fibers that are ready.
3013
- * Other tasks are left unchanged.
3014
- */
3015
- flush() {
3016
- if (this.delayedRenders.length) {
3017
- let renders = this.delayedRenders;
3018
- this.delayedRenders = [];
3019
- for (let f of renders) {
3020
- if (f.root && f.node.status !== 3 /* STATUS.DESTROYED */ && f.node.fiber === f) {
3021
- f.render();
3022
- }
3023
- }
3024
- }
3025
- if (this.frame === 0) {
3026
- this.frame = this.requestAnimationFrame(() => this.processTasks());
3027
- }
3028
- }
3029
- processTasks() {
3030
- if (this.processing) {
3031
- return;
3032
- }
3033
- this.processing = true;
3034
- this.frame = 0;
3035
- for (let node of this.cancelledNodes) {
3036
- node._destroy();
3037
- }
3038
- this.cancelledNodes.clear();
3039
- for (let task of this.tasks) {
3040
- this.processFiber(task);
3041
- }
3042
- for (let task of this.tasks) {
3043
- if (task.node.status === 3 /* STATUS.DESTROYED */) {
3044
- this.tasks.delete(task);
3045
- }
3046
- }
3047
- this.processing = false;
3048
- }
3049
- processFiber(fiber) {
3050
- if (fiber.root !== fiber) {
3051
- this.tasks.delete(fiber);
3052
- return;
3053
- }
3054
- const hasError = fibersInError.has(fiber);
3055
- if (hasError && fiber.counter !== 0) {
3056
- this.tasks.delete(fiber);
3057
- return;
3058
- }
3059
- if (fiber.node.status === 3 /* STATUS.DESTROYED */) {
3060
- this.tasks.delete(fiber);
3061
- return;
3062
- }
3063
- if (fiber.counter === 0) {
3064
- if (!hasError) {
3065
- fiber.complete();
3066
- }
3067
- // at this point, the fiber should have been applied to the DOM, so we can
3068
- // remove it from the task list. If it is not the case, it means that there
3069
- // was an error and an error handler triggered a new rendering that recycled
3070
- // the fiber, so in that case, we actually want to keep the fiber around,
3071
- // otherwise it will just be ignored.
3072
- if (fiber.appliedToDom) {
3073
- this.tasks.delete(fiber);
3074
- }
3075
- }
3076
- }
3077
- }
3078
- // capture the value of requestAnimationFrame as soon as possible, to avoid
3079
- // interactions with other code, such as test frameworks that override them
3080
- Scheduler.requestAnimationFrame = window.requestAnimationFrame.bind(window);
3081
-
3082
- // -----------------------------------------------------------------------------
3083
- // hooks
3084
- // -----------------------------------------------------------------------------
3085
- function decorate(node, f, hookName) {
3086
- const result = f.bind(node.component);
3087
- if (node.app.dev) {
3088
- const suffix = f.name ? ` <${f.name}>` : "";
3089
- Reflect.defineProperty(result, "name", {
3090
- value: hookName + suffix,
3091
- });
3092
- }
3093
- return result;
3094
- }
3095
- function onWillStart(fn) {
3096
- const node = getCurrent();
3097
- node.willStart.push(decorate(node, fn, "onWillStart"));
3098
- }
3099
- function onMounted(fn) {
3100
- const node = getCurrent();
3101
- node.mounted.push(decorate(node, fn, "onMounted"));
3102
- }
3103
- function onWillPatch(fn) {
3104
- const node = getCurrent();
3105
- node.willPatch.unshift(decorate(node, fn, "onWillPatch"));
3106
- }
3107
- function onPatched(fn) {
3108
- const node = getCurrent();
3109
- node.patched.push(decorate(node, fn, "onPatched"));
3110
- }
3111
- function onWillUnmount(fn) {
3112
- const node = getCurrent();
3113
- node.willUnmount.unshift(decorate(node, fn, "onWillUnmount"));
3114
- }
3115
- function onWillDestroy(fn) {
3116
- const pm = PluginManager.current;
3117
- if (pm) {
3118
- pm.onDestroyCb.push(fn);
3119
- }
3120
- else {
3121
- const node = getCurrent();
3122
- node.willDestroy.unshift(decorate(node, fn, "onWillDestroy"));
3123
- }
3124
- }
3125
- function onError(callback) {
3126
- const node = getCurrent();
3127
- let handlers = nodeErrorHandlers.get(node);
3128
- if (!handlers) {
3129
- handlers = [];
3130
- nodeErrorHandlers.set(node, handlers);
3131
- }
3132
- handlers.push(callback.bind(node.component));
3133
- }
3134
-
3135
- function props(type, defaults = {}) {
3136
- const node = getCurrent();
3137
- const result = Object.create(null);
3138
- function applyProps(keys) {
3139
- for (const key of keys) {
3140
- result[key] = node.props === undefined ? defaults[key] : node.props[key];
3141
- }
3142
- }
3143
- if (type) {
3144
- const isSchemaValidated = type && !Array.isArray(type);
3145
- const keys$1 = (isSchemaValidated ? Object.keys(type) : type).map((key) => key.endsWith("?") ? key.slice(0, -1) : key);
3146
- applyProps(keys$1);
3147
- if (node.app.dev) {
3148
- const validation = isSchemaValidated ? object(type) : keys(...type);
3149
- assertType(node.props, validation);
3150
- }
3151
- }
3152
- else {
3153
- applyProps(Object.keys(node.props));
3154
- }
3155
- return result;
3156
- }
3157
-
3158
- const VText = text("").constructor;
3159
- class VPortal extends VText {
3160
- constructor(selector, content) {
3161
- super("");
3162
- this.target = null;
3163
- this.selector = selector;
3164
- this.content = content;
3165
- }
3166
- mount(parent, anchor) {
3167
- super.mount(parent, anchor);
3168
- this.target = document.querySelector(this.selector);
3169
- if (this.target) {
3170
- this.content.mount(this.target, null);
3171
- }
3172
- else {
3173
- this.content.mount(parent, anchor);
3174
- }
3175
- }
3176
- beforeRemove() {
3177
- this.content.beforeRemove();
3178
- }
3179
- remove() {
3180
- if (this.content) {
3181
- super.remove();
3182
- this.content.remove();
3183
- this.content = null;
3184
- }
3185
- }
3186
- patch(other) {
3187
- super.patch(other);
3188
- if (this.content) {
3189
- this.content.patch(other.content, true);
3190
- }
3191
- else {
3192
- this.content = other.content;
3193
- this.content.mount(this.target, null);
3194
- }
3195
- }
3196
- }
3197
- /**
3198
- * kind of similar to <t t-slot="default"/>, but it wraps it around a VPortal
3199
- */
3200
- function portalTemplate(app, bdom, helpers) {
3201
- let { callSlot } = helpers;
3202
- return function template(ctx, node, key = "") {
3203
- return new VPortal(ctx.this.props.target, callSlot(ctx, node, key, "default", false, null));
3204
- };
3205
- }
3206
- class Portal extends Component {
3207
- constructor() {
3208
- super(...arguments);
3209
- this.props = props({
3210
- target: string,
3211
- });
3212
- }
3213
- setup() {
3214
- const node = this.__owl__;
3215
- onMounted(() => {
3216
- const portal = node.bdom;
3217
- if (!portal.target) {
3218
- const target = document.querySelector(node.props.target);
3219
- if (target) {
3220
- portal.content.moveBeforeDOMNode(target.firstChild, target);
3221
- }
3222
- else {
3223
- throw new OwlError("invalid portal target");
3224
- }
3225
- }
3226
- });
3227
- onWillUnmount(() => {
3228
- const portal = node.bdom;
3229
- portal.remove();
3230
- });
3231
- }
3232
- }
3233
- Portal.template = "__portal__";
3234
-
3235
- const ObjectCreate = Object.create;
3236
- /**
3237
- * This file contains utility functions that will be injected in each template,
3238
- * to perform various useful tasks in the compiled code.
3239
- */
3240
- function withDefault(value, defaultValue) {
3241
- return value === undefined || value === null || value === false ? defaultValue : value;
3242
- }
3243
- function callSlot(ctx, parent, key, name, dynamic, extra, defaultContent) {
3244
- key = key + "__slot_" + name;
3245
- const slots = ctx.__owl__.props.slots || {};
3246
- const { __render, __ctx, __scope } = slots[name] || {};
3247
- const slotScope = ObjectCreate(__ctx || {});
3248
- if (__scope) {
3249
- slotScope[__scope] = extra;
3250
- }
3251
- const slotBDom = __render ? __render(slotScope, parent, key) : null;
3252
- if (defaultContent) {
3253
- let child1 = undefined;
3254
- let child2 = undefined;
3255
- if (slotBDom) {
3256
- child1 = dynamic ? toggler(name, slotBDom) : slotBDom;
3257
- }
3258
- else {
3259
- child2 = defaultContent(ctx, parent, key);
3260
- }
3261
- return multi([child1, child2]);
3262
- }
3263
- return slotBDom || text("");
3264
- }
3265
- function capture(ctx) {
3266
- const result = ObjectCreate(ctx);
3267
- for (let k in ctx) {
3268
- result[k] = ctx[k];
3269
- }
3270
- return result;
3271
- }
3272
- function withKey(elem, k) {
3273
- elem.key = k;
3274
- return elem;
3275
- }
3276
- function prepareList(collection) {
3277
- let keys;
3278
- let values;
3279
- if (Array.isArray(collection)) {
3280
- keys = collection;
3281
- values = collection;
3282
- }
3283
- else if (collection instanceof Map) {
3284
- keys = [...collection.keys()];
3285
- values = [...collection.values()];
3286
- }
3287
- else if (Symbol.iterator in Object(collection)) {
3288
- keys = [...collection];
3289
- values = keys;
3290
- }
3291
- else if (collection && typeof collection === "object") {
3292
- values = Object.values(collection);
3293
- keys = Object.keys(collection);
3294
- }
3295
- else {
3296
- throw new OwlError(`Invalid loop expression: "${collection}" is not iterable`);
3297
- }
3298
- const n = values.length;
3299
- return [keys, values, n, new Array(n)];
3300
- }
3301
- const isBoundary = Symbol("isBoundary");
3302
- function setContextValue(ctx, key, value) {
3303
- const ctx0 = ctx;
3304
- while (!ctx.hasOwnProperty(key) && !ctx.hasOwnProperty(isBoundary)) {
3305
- const newCtx = ctx.__proto__;
3306
- if (!newCtx) {
3307
- ctx = ctx0;
3308
- break;
3309
- }
3310
- ctx = newCtx;
3311
- }
3312
- ctx[key] = value;
3313
- }
3314
- function toNumber(val) {
3315
- const n = parseFloat(val);
3316
- return isNaN(n) ? val : n;
3317
- }
3318
- function shallowEqual(l1, l2) {
3319
- for (let i = 0, l = l1.length; i < l; i++) {
3320
- if (l1[i] !== l2[i]) {
3321
- return false;
3322
- }
3323
- }
3324
- return true;
3325
- }
3326
- class LazyValue {
3327
- constructor(fn, ctx, component, node, key) {
3328
- this.fn = fn;
3329
- this.ctx = capture(ctx);
3330
- this.component = component;
3331
- this.node = node;
3332
- this.key = key;
3333
- }
3334
- evaluate() {
3335
- return this.fn.call(this.component, this.ctx, this.node, this.key);
3336
- }
3337
- toString() {
3338
- return this.evaluate().toString();
3339
- }
3340
- }
3341
- /*
3342
- * Safely outputs `value` as a block depending on the nature of `value`
3343
- */
3344
- function safeOutput(value, defaultValue) {
3345
- if (value === undefined || value === null) {
3346
- return defaultValue ? toggler("default", defaultValue) : toggler("undefined", text(""));
3347
- }
3348
- let safeKey;
3349
- let block;
3350
- if (value instanceof Markup) {
3351
- safeKey = `string_safe`;
3352
- block = html(value);
3353
- }
3354
- else if (value instanceof LazyValue) {
3355
- safeKey = `lazy_value`;
3356
- block = value.evaluate();
3357
- }
3358
- else {
3359
- safeKey = "string_unsafe";
3360
- block = text(value);
3361
- }
3362
- return toggler(safeKey, block);
3363
- }
3364
- function createRef(ref) {
3365
- if (!ref) {
3366
- throw new OwlError(`Ref is undefined or null`);
3367
- }
3368
- let add;
3369
- let remove;
3370
- if (ref.add && ref.remove) {
3371
- add = ref.add.bind(ref);
3372
- remove = ref.remove.bind(ref);
3373
- }
3374
- else if (ref.set) {
3375
- add = ref.set.bind(ref);
3376
- remove = () => ref.set(null);
3377
- }
3378
- else {
3379
- throw new OwlError(`Ref should implement either a 'set' function or 'add' and 'remove' functions`);
3380
- }
3381
- return (el, previousEl) => {
3382
- if (previousEl) {
3383
- remove(previousEl);
3384
- }
3385
- if (el) {
3386
- add(el);
3387
- }
3388
- };
3389
- }
3390
- function modelExpr(value) {
3391
- if (!value.set || typeof value !== "function") {
3392
- throw new OwlError(`Invalid t-model expression: expression should evaluate to a function with a 'set' method defined on it`);
3393
- }
3394
- return value;
3395
- }
3396
- const helpers = {
3397
- withDefault,
3398
- zero: Symbol("zero"),
3399
- isBoundary,
3400
- callSlot,
3401
- capture,
3402
- withKey,
3403
- prepareList,
3404
- setContextValue,
3405
- shallowEqual,
3406
- toNumber,
3407
- LazyValue,
3408
- safeOutput,
3409
- createCatcher,
3410
- markRaw,
3411
- OwlError,
3412
- createRef,
3413
- modelExpr,
3414
- };
3415
-
3416
- /**
3417
- * Parses an XML string into an XML document, throwing errors on parser errors
3418
- * instead of returning an XML document containing the parseerror.
3419
- *
3420
- * @param xml the string to parse
3421
- * @returns an XML document corresponding to the content of the string
3422
- */
3423
- function parseXML(xml) {
3424
- const parser = new DOMParser();
3425
- const doc = parser.parseFromString(xml, "text/xml");
3426
- if (doc.getElementsByTagName("parsererror").length) {
3427
- let msg = "Invalid XML in template.";
3428
- const parsererrorText = doc.getElementsByTagName("parsererror")[0].textContent;
3429
- if (parsererrorText) {
3430
- msg += "\nThe parser has produced the following error message:\n" + parsererrorText;
3431
- const re = /\d+/g;
3432
- const firstMatch = re.exec(parsererrorText);
3433
- if (firstMatch) {
3434
- const lineNumber = Number(firstMatch[0]);
3435
- const line = xml.split("\n")[lineNumber - 1];
3436
- const secondMatch = re.exec(parsererrorText);
3437
- if (line && secondMatch) {
3438
- const columnIndex = Number(secondMatch[0]) - 1;
3439
- if (line[columnIndex]) {
3440
- msg +=
3441
- `\nThe error might be located at xml line ${lineNumber} column ${columnIndex}\n` +
3442
- `${line}\n${"-".repeat(columnIndex - 1)}^`;
3443
- }
3444
- }
3445
- }
3446
- }
3447
- throw new OwlError(msg);
3448
- }
3449
- return doc;
3450
- }
3451
-
3452
- const bdom = { text, createBlock, list, multi, html, toggler, comment };
3453
- class TemplateSet {
3454
- static registerTemplate(name, fn) {
3455
- globalTemplates[name] = fn;
3456
- }
3457
- constructor(config = {}) {
3458
- this.rawTemplates = Object.create(globalTemplates);
3459
- this.templates = {};
3460
- this.Portal = Portal;
3461
- this.dev = config.dev || false;
3462
- this.translateFn = config.translateFn;
3463
- this.translatableAttributes = config.translatableAttributes;
3464
- if (config.templates) {
3465
- if (config.templates instanceof Document || typeof config.templates === "string") {
3466
- this.addTemplates(config.templates);
3467
- }
3468
- else {
3469
- for (const name in config.templates) {
3470
- this.addTemplate(name, config.templates[name]);
3471
- }
3472
- }
3473
- }
3474
- this.getRawTemplate = config.getTemplate;
3475
- this.customDirectives = config.customDirectives || {};
3476
- this.runtimeUtils = { ...helpers, __globals__: config.globalValues || {} };
3477
- this.hasGlobalValues = Boolean(config.globalValues && Object.keys(config.globalValues).length);
3478
- }
3479
- addTemplate(name, template) {
3480
- if (name in this.rawTemplates) {
3481
- // this check can be expensive, just silently ignore double definitions outside dev mode
3482
- if (!this.dev) {
3483
- return;
3484
- }
3485
- const rawTemplate = this.rawTemplates[name];
3486
- const currentAsString = typeof rawTemplate === "string"
3487
- ? rawTemplate
3488
- : rawTemplate instanceof Element
3489
- ? rawTemplate.outerHTML
3490
- : rawTemplate.toString();
3491
- const newAsString = typeof template === "string" ? template : template.outerHTML;
3492
- if (currentAsString === newAsString) {
3493
- return;
3494
- }
3495
- throw new OwlError(`Template ${name} already defined with different content`);
3496
- }
3497
- this.rawTemplates[name] = template;
3498
- }
3499
- addTemplates(xml) {
3500
- if (!xml) {
3501
- // empty string
3502
- return;
3503
- }
3504
- xml = xml instanceof Document ? xml : parseXML(xml);
3505
- for (const template of xml.querySelectorAll("[t-name]")) {
3506
- const name = template.getAttribute("t-name");
3507
- this.addTemplate(name, template);
3508
- }
3509
- }
3510
- getTemplate(name) {
3511
- var _a;
3512
- if (!(name in this.templates)) {
3513
- const rawTemplate = ((_a = this.getRawTemplate) === null || _a === void 0 ? void 0 : _a.call(this, name)) || this.rawTemplates[name];
3514
- if (rawTemplate === undefined) {
3515
- let extraInfo = "";
3516
- try {
3517
- const componentName = getCurrent().component.constructor.name;
3518
- extraInfo = ` (for component "${componentName}")`;
3519
- }
3520
- catch { }
3521
- throw new OwlError(`Missing template: "${name}"${extraInfo}`);
3522
- }
3523
- const isFn = typeof rawTemplate === "function" && !(rawTemplate instanceof Element);
3524
- const templateFn = isFn ? rawTemplate : this._compileTemplate(name, rawTemplate);
3525
- // first add a function to lazily get the template, in case there is a
3526
- // recursive call to the template name
3527
- const templates = this.templates;
3528
- this.templates[name] = function (context, parent) {
3529
- return templates[name].call(this, context, parent);
3530
- };
3531
- const template = templateFn(this, bdom, this.runtimeUtils);
3532
- this.templates[name] = template;
3533
- }
3534
- return this.templates[name];
3535
- }
3536
- _compileTemplate(name, template) {
3537
- throw new OwlError(`Unable to compile a template. Please use owl full build instead`);
3538
- }
3539
- callTemplate(owner, subTemplate, ctx, parent, key) {
3540
- const template = this.getTemplate(subTemplate);
3541
- return toggler(subTemplate, template.call(owner, ctx, parent, key + subTemplate));
3542
- }
3543
- }
3544
- // -----------------------------------------------------------------------------
3545
- // xml tag helper
3546
- // -----------------------------------------------------------------------------
3547
- const globalTemplates = {};
3548
- function xml(...args) {
3549
- const name = `__template__${xml.nextId++}`;
3550
- const value = String.raw(...args);
3551
- globalTemplates[name] = value;
3552
- return name;
3553
- }
3554
- xml.nextId = 1;
3555
- TemplateSet.registerTemplate("__portal__", portalTemplate);
3556
-
3557
- let hasBeenLogged = false;
3558
- const apps = new Set();
3559
- window.__OWL_DEVTOOLS__ || (window.__OWL_DEVTOOLS__ = { apps, Fiber, RootFiber, toRaw, proxy });
3560
- class App extends TemplateSet {
3561
- constructor(config = {}) {
3562
- super(config);
3563
- this.scheduler = new Scheduler();
3564
- this.roots = new Set();
3565
- this.name = config.name || "";
3566
- apps.add(this);
3567
- this.pluginManager = config.pluginManager || new PluginManager(null);
3568
- if (config.plugins) {
3569
- this.pluginManager.startPlugins(config.plugins);
3570
- }
3571
- if (config.test) {
3572
- this.dev = true;
3573
- }
3574
- if (this.dev && !config.test && !hasBeenLogged) {
3575
- console.info(`Owl is running in 'dev' mode.`);
3576
- hasBeenLogged = true;
3577
- }
3578
- }
3579
- createRoot(Root, config = {}) {
3580
- const props = config.props || {};
3581
- let resolve;
3582
- let reject;
3583
- const promise = new Promise((res, rej) => {
3584
- resolve = res;
3585
- reject = rej;
3586
- });
3587
- const restore = saveCurrent();
3588
- let node;
3589
- let error = null;
3590
- try {
3591
- node = this.makeNode(Root, props);
3592
- }
3593
- catch (e) {
3594
- error = e;
3595
- reject(e);
3596
- }
3597
- finally {
3598
- restore();
3599
- }
3600
- const root = {
3601
- node: node,
3602
- promise,
3603
- mount: (target, options) => {
3604
- if (error) {
3605
- return promise;
3606
- }
3607
- App.validateTarget(target);
3608
- this.mountNode(node, target, resolve, reject, options);
3609
- return promise;
3610
- },
3611
- destroy: () => {
3612
- this.roots.delete(root);
3613
- node.destroy();
3614
- this.scheduler.processTasks();
3615
- },
3616
- };
3617
- this.roots.add(root);
3618
- return root;
3619
- }
3620
- makeNode(Component, props) {
3621
- return new ComponentNode(Component, props, this, null, null);
3622
- }
3623
- mountNode(node, target, resolve, reject, options) {
3624
- // Manually add the last resort error handler on the node
3625
- let handlers = nodeErrorHandlers.get(node);
3626
- if (!handlers) {
3627
- handlers = [];
3628
- nodeErrorHandlers.set(node, handlers);
3629
- }
3630
- handlers.unshift((e, finalize) => {
3631
- const finalError = finalize();
3632
- reject(finalError);
3633
- });
3634
- // manually set a onMounted callback.
3635
- // that way, we are independant from the current node.
3636
- node.mounted.push(() => {
3637
- resolve(node.component);
3638
- handlers.shift();
3639
- });
3640
- node.mountComponent(target, options);
3641
- }
3642
- destroy() {
3643
- for (let root of this.roots) {
3644
- root.destroy();
3645
- }
3646
- this.scheduler.processTasks();
3647
- apps.delete(this);
3648
- }
3649
- createComponent(name, isStatic) {
3650
- const isDynamic = !isStatic;
3651
- const initiateRender = ComponentNode.prototype.initiateRender;
3652
- return (props, key, ctx, parent, C) => {
3653
- let children = ctx.children;
3654
- let node = children[key];
3655
- if (isDynamic && node && node.component.constructor !== C) {
3656
- node = undefined;
3657
- }
3658
- const parentFiber = ctx.fiber;
3659
- if (!node) {
3660
- // new component
3661
- if (isStatic) {
3662
- const components = parent.constructor.components;
3663
- if (!components) {
3664
- throw new OwlError(`Cannot find the definition of component "${name}", missing static components key in parent`);
3665
- }
3666
- C = components[name];
3667
- if (!C) {
3668
- throw new OwlError(`Cannot find the definition of component "${name}"`);
3669
- }
3670
- else if (!(C.prototype instanceof Component)) {
3671
- throw new OwlError(`"${name}" is not a Component. It must inherit from the Component class`);
3672
- }
3673
- }
3674
- node = new ComponentNode(C, props, this, ctx, key);
3675
- children[key] = node;
3676
- initiateRender.call(node, new Fiber(node, parentFiber));
3677
- }
3678
- parentFiber.childrenMap[key] = node;
3679
- return node;
3680
- };
3681
- }
3682
- handleError(...args) {
3683
- return handleError(...args);
3684
- }
3685
- }
3686
- App.validateTarget = validateTarget;
3687
- App.apps = apps;
3688
- App.version = version;
3689
- async function mount(C, target, config = {}) {
3690
- const app = new App(config);
3691
- const root = app.createRoot(C, config);
3692
- return root.mount(target, config);
3693
- }
3694
-
3695
- const mainEventHandler = (data, ev, currentTarget) => {
3696
- const { data: _data, modifiers } = filterOutModifiersFromData(data);
3697
- data = _data;
3698
- let stopped = false;
3699
- if (modifiers.length) {
3700
- let selfMode = false;
3701
- const isSelf = ev.target === currentTarget;
3702
- for (const mod of modifiers) {
3703
- switch (mod) {
3704
- case "self":
3705
- selfMode = true;
3706
- if (isSelf) {
3707
- continue;
3708
- }
3709
- else {
3710
- return stopped;
3711
- }
3712
- case "prevent":
3713
- if ((selfMode && isSelf) || !selfMode)
3714
- ev.preventDefault();
3715
- continue;
3716
- case "stop":
3717
- if ((selfMode && isSelf) || !selfMode)
3718
- ev.stopPropagation();
3719
- stopped = true;
3720
- continue;
3721
- }
3722
- }
3723
- }
3724
- // If handler is empty, the array slot 0 will also be empty, and data will not have the property 0
3725
- // We check this rather than data[0] being truthy (or typeof function) so that it crashes
3726
- // as expected when there is a handler expression that evaluates to a falsy value
3727
- if (Object.hasOwnProperty.call(data, 0)) {
3728
- const handler = data[0];
3729
- if (typeof handler !== "function") {
3730
- throw new OwlError(`Invalid handler (expected a function, received: '${handler}')`);
3731
- }
3732
- let node = data[1] ? data[1].__owl__ : null;
3733
- if (node ? node.status === 1 /* STATUS.MOUNTED */ : true) {
3734
- handler.call(node ? node.component : null, ev);
3735
- }
3736
- }
3737
- return stopped;
3738
- };
3739
-
3740
- function computed(fn, opts) {
3741
- // todo: handle cleanup
3742
- let derivedComputation;
3743
- return () => {
3744
- derivedComputation !== null && derivedComputation !== void 0 ? derivedComputation : (derivedComputation = {
3745
- state: ComputationState.STALE,
3746
- sources: new Set(),
3747
- compute: () => {
3748
- onWriteAtom(derivedComputation);
3749
- return fn();
3750
- },
3751
- isDerived: true,
3752
- value: undefined,
3753
- observers: new Set(),
3754
- name: opts === null || opts === void 0 ? void 0 : opts.name,
3755
- });
3756
- updateComputation(derivedComputation);
3757
- onReadAtom(derivedComputation);
3758
- return derivedComputation.value;
3759
- };
3760
- }
3761
-
3762
- const signalSymbol = Symbol("Signal");
3763
- function buildSignal(value, set, opts) {
3764
- const atom = {
3765
- value,
3766
- observers: new Set(),
3767
- name: opts === null || opts === void 0 ? void 0 : opts.name,
3768
- };
3769
- let readValue = set(atom);
3770
- const read = () => {
3771
- onReadAtom(atom);
3772
- return readValue;
3773
- };
3774
- read[signalSymbol] = atom;
3775
- read.set = (newValue) => {
3776
- if (Object.is(atom.value, newValue)) {
3777
- return;
3778
- }
3779
- atom.value = newValue;
3780
- readValue = set(atom);
3781
- onWriteAtom(atom);
3782
- };
3783
- return read;
3784
- }
3785
- function signal(value, opts) {
3786
- return buildSignal(value, (atom) => atom.value, opts);
3787
- }
3788
- signal.invalidate = function (signal) {
3789
- if (!(signalSymbol in signal)) {
3790
- throw new OwlError(`Value is not a signal (${signal})`);
3791
- }
3792
- const atom = signal[signalSymbol];
3793
- onWriteAtom(atom);
3794
- };
3795
- signal.Array = function (initialValue, opts) {
3796
- return buildSignal(initialValue, (atom) => proxifyTarget(atom.value, atom), opts);
3797
- };
3798
- signal.Object = function (initialValue, opts) {
3799
- return buildSignal(initialValue, (atom) => proxifyTarget(atom.value, atom), opts);
3800
- };
3801
- signal.Map = function (initialValue, opts) {
3802
- return buildSignal(initialValue, (atom) => proxifyTarget(atom.value, atom), opts);
3803
- };
3804
- signal.Set = function (initialValue, opts) {
3805
- return buildSignal(initialValue, (atom) => proxifyTarget(atom.value, atom), opts);
3806
- };
3807
-
3808
- class Resource {
3809
- constructor(options = {}) {
3810
- this._items = signal.Array([]);
3811
- this.items = computed(() => {
3812
- return this._items()
3813
- .sort((el1, el2) => el1[0] - el2[0])
3814
- .map((elem) => elem[1]);
3815
- });
3816
- // this._name = options.name || "resource";
3817
- this._validation = options.validation;
3818
- }
3819
- add(item, sequence = 50) {
3820
- if (this._validation) {
3821
- assertType(item, this._validation);
3822
- }
3823
- this._items().push([sequence, item]);
3824
- return this;
3825
- }
3826
- remove(item) {
3827
- const items = this._items().filter(([seq, val]) => val !== item);
3828
- this._items.set(items);
3829
- return this;
3830
- }
3831
- has(item) {
3832
- return this._items().some(([s, value]) => value === item);
3833
- }
3834
- }
3835
- function useResource(r, elements) {
3836
- for (let elem of elements) {
3837
- r.add(elem);
3838
- }
3839
- onWillDestroy(() => {
3840
- for (let elem of elements) {
3841
- r.remove(elem);
3842
- }
3843
- });
3844
- }
3845
-
3846
- class Registry {
3847
- constructor(options = {}) {
3848
- this._map = signal.Object(Object.create(null));
3849
- this.entries = computed(() => {
3850
- const entries = Object.entries(this._map())
3851
- .sort((el1, el2) => el1[1][0] - el2[1][0])
3852
- .map(([str, elem]) => [str, elem[1]]);
3853
- return entries;
3854
- });
3855
- this.items = computed(() => this.entries().map((e) => e[1]));
3856
- this._name = options.name || "registry";
3857
- this._validation = options.validation;
3858
- }
3859
- addById(item, sequence = 50) {
3860
- if (!item.id) {
3861
- throw new OwlError(`Item should have an id key (registry '${this._name}')`);
3862
- }
3863
- return this.add(item.id, item, sequence);
3864
- }
3865
- add(key, value, sequence = 50) {
3866
- if (this._validation) {
3867
- assertType(value, this._validation);
3868
- }
3869
- this._map()[key] = [sequence, value];
3870
- return this;
3871
- }
3872
- get(key, defaultValue) {
3873
- const hasKey = key in this._map();
3874
- if (!hasKey && arguments.length < 2) {
3875
- throw new Error(`KeyNotFoundError: Cannot find key "${key}" (registry '${this._name}')`);
3876
- }
3877
- return hasKey ? this._map()[key][1] : defaultValue;
3878
- }
3879
- remove(key) {
3880
- delete this._map()[key];
3881
- }
3882
- has(key) {
3883
- return key in this._map();
3884
- }
3885
- }
3886
-
3887
- function status() {
3888
- const pm = PluginManager.current;
3889
- const node = pm || getCurrent();
3890
- return () => {
3891
- switch (node.status) {
3892
- case 0 /* STATUS.NEW */:
3893
- return "new";
3894
- case 2 /* STATUS.CANCELLED */:
3895
- return "cancelled";
3896
- case 1 /* STATUS.MOUNTED */:
3897
- return pm ? "started" : "mounted";
3898
- case 3 /* STATUS.DESTROYED */:
3899
- return "destroyed";
3900
- }
3901
- };
3902
- }
3903
-
3904
- function effect(fn, opts) {
3905
- var _a, _b, _c;
3906
- const effectComputation = {
3907
- state: ComputationState.STALE,
3908
- value: undefined,
3909
- compute() {
3910
- // In case the cleanup read an atom.
3911
- // todo: test it
3912
- setComputation(undefined);
3913
- // CurrentComputation = undefined!;
3914
- // `removeSources` is made by `runComputation`.
3915
- unsubscribeEffect(effectComputation);
3916
- setComputation(effectComputation);
3917
- // CurrentComputation = effectComputation;
3918
- return fn();
3919
- },
3920
- sources: new Set(),
3921
- childrenEffect: [],
3922
- name: opts === null || opts === void 0 ? void 0 : opts.name,
3923
- };
3924
- (_c = (_b = (_a = getCurrentComputation()) === null || _a === void 0 ? void 0 : _a.childrenEffect) === null || _b === void 0 ? void 0 : _b.push) === null || _c === void 0 ? void 0 : _c.call(_b, effectComputation);
3925
- updateComputation(effectComputation);
3926
- // Remove sources and unsubscribe
3927
- return () => {
3928
- // In case the cleanup read an atom.
3929
- // todo: test it
3930
- const previousComputation = getCurrentComputation();
3931
- setComputation(undefined);
3932
- unsubscribeEffect(effectComputation);
3933
- setComputation(previousComputation);
3934
- };
3935
- }
3936
- function unsubscribeEffect(effectComputation) {
3937
- removeSources(effectComputation);
3938
- cleanupEffect(effectComputation);
3939
- for (const children of effectComputation.childrenEffect) {
3940
- // Consider it executed to avoid it's re-execution
3941
- // todo: make a test for it
3942
- children.state = ComputationState.EXECUTED;
3943
- removeSources(children);
3944
- unsubscribeEffect(children);
3945
- }
3946
- effectComputation.childrenEffect.length = 0;
3947
- }
3948
- function cleanupEffect(computation) {
3949
- // the computation.value of an effect is a cleanup function
3950
- const cleanupFn = computation.value;
3951
- if (cleanupFn && typeof cleanupFn === "function") {
3952
- cleanupFn();
3953
- computation.value = undefined;
3954
- }
3955
- }
3956
-
3957
- // -----------------------------------------------------------------------------
3958
- // useEffect
3959
- // -----------------------------------------------------------------------------
3960
- /**
3961
- * This hook will run a callback when a component is mounted and patched, and
3962
- * will run a cleanup function before patching and before unmounting the
3963
- * the component.
3964
- *
3965
- * @template T
3966
- * @param {Effect<T>} effect the effect to run on component mount and/or patch
3967
- * @param {()=>[...T]} [computeDependencies=()=>[NaN]] a callback to compute
3968
- * dependencies that will decide if the effect needs to be cleaned up and
3969
- * run again. If the dependencies did not change, the effect will not run
3970
- * again. The default value returns an array containing only NaN because
3971
- * NaN !== NaN, which will cause the effect to rerun on every patch.
3972
- */
3973
- function useEffect(fn) {
3974
- onWillDestroy(effect(fn));
3975
- }
3976
- // -----------------------------------------------------------------------------
3977
- // useListener
3978
- // -----------------------------------------------------------------------------
3979
- /**
3980
- * When a component needs to listen to DOM Events on element(s) that are not
3981
- * part of his hierarchy, we can use the `useListener` hook.
3982
- * It will immediately add the listener, and remove it whenever the plugin or
3983
- * component is destroyed.
3984
- *
3985
- * Example:
3986
- * a menu needs to listen to the click on window to be closed automatically
3987
- *
3988
- * Usage:
3989
- * in the constructor of the OWL component that needs to be notified,
3990
- * `useListener(window, 'click', () => this._doSomething());`
3991
- * */
3992
- function useListener(target, eventName, handler, eventParams) {
3993
- target.addEventListener(eventName, handler, eventParams);
3994
- onWillDestroy(() => target.removeEventListener(eventName, handler, eventParams));
3995
- }
3996
- function providePlugins(Plugins, pluginProps) {
3997
- const node = getCurrent();
3998
- const manager = new PluginManager(node.pluginManager);
3999
- node.pluginManager = manager;
4000
- onWillDestroy(() => manager.destroy());
4001
- return manager.startPlugins(Plugins, pluginProps);
4002
- }
4003
-
4004
- config.shouldNormalizeDom = false;
4005
- config.mainEventHandler = mainEventHandler;
4006
- const blockDom = {
4007
- config,
4008
- // bdom entry points
4009
- mount: mount$1,
4010
- patch,
4011
- remove,
4012
- // bdom block types
4013
- list,
4014
- multi,
4015
- text,
4016
- toggler,
4017
- createBlock,
4018
- html,
4019
- comment,
4020
- };
4021
- const __info__ = {
4022
- version: App.version,
4023
- };
4024
-
4025
- exports.App = App;
4026
- exports.Component = Component;
4027
- exports.EventBus = EventBus;
4028
- exports.OwlError = OwlError;
4029
- exports.Plugin = Plugin;
4030
- exports.PluginManager = PluginManager;
4031
- exports.Registry = Registry;
4032
- exports.Resource = Resource;
4033
- exports.__info__ = __info__;
4034
- exports.assertType = assertType;
4035
- exports.batched = batched;
4036
- exports.blockDom = blockDom;
4037
- exports.computed = computed;
4038
- exports.effect = effect;
4039
- exports.htmlEscape = htmlEscape;
4040
- exports.markRaw = markRaw;
4041
- exports.markup = markup;
4042
- exports.mount = mount;
4043
- exports.onError = onError;
4044
- exports.onMounted = onMounted;
4045
- exports.onPatched = onPatched;
4046
- exports.onWillDestroy = onWillDestroy;
4047
- exports.onWillPatch = onWillPatch;
4048
- exports.onWillStart = onWillStart;
4049
- exports.onWillUnmount = onWillUnmount;
4050
- exports.plugin = plugin;
4051
- exports.props = props;
4052
- exports.providePlugins = providePlugins;
4053
- exports.proxy = proxy;
4054
- exports.signal = signal;
4055
- exports.status = status;
4056
- exports.toRaw = toRaw;
4057
- exports.types = types;
4058
- exports.untrack = untrack;
4059
- exports.useComponent = useComponent;
4060
- exports.useEffect = useEffect;
4061
- exports.useListener = useListener;
4062
- exports.useResource = useResource;
4063
- exports.validateType = validateType;
4064
- exports.whenReady = whenReady;
4065
- exports.xml = xml;
4066
-
4067
-
4068
- __info__.date = '2026-01-14T19:21:38.789Z';
4069
- __info__.hash = '2278017';
4070
- __info__.url = 'https://github.com/odoo/owl';