@odoo/owl 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/owl.cjs.js +80 -80
- package/dist/owl.es.js +80 -80
- package/dist/owl.iife.js +80 -80
- package/dist/owl.iife.min.js +1 -1
- package/dist/types/owl.d.ts +74 -81
- package/dist/types/runtime/app.d.ts +1 -1
- package/dist/types/runtime/component_node.d.ts +2 -2
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/runtime/reactivity.d.ts +6 -12
- package/dist/types/runtime/template_helpers.d.ts +1 -1
- package/package.json +6 -6
package/dist/owl.iife.js
CHANGED
|
@@ -1743,10 +1743,6 @@
|
|
|
1743
1743
|
}
|
|
1744
1744
|
}
|
|
1745
1745
|
|
|
1746
|
-
// Allows to get the target of a Reactive (used for making a new Reactive from the underlying object)
|
|
1747
|
-
const TARGET = Symbol("Target");
|
|
1748
|
-
// Escape hatch to prevent reactivity system to turn something into a reactive
|
|
1749
|
-
const SKIP = Symbol("Skip");
|
|
1750
1746
|
// Special key to subscribe to, to be notified of key creation/deletion
|
|
1751
1747
|
const KEYCHANGES = Symbol("Key changes");
|
|
1752
1748
|
const objectToString = Object.prototype.toString;
|
|
@@ -1763,7 +1759,7 @@
|
|
|
1763
1759
|
* @returns the raw type of the object
|
|
1764
1760
|
*/
|
|
1765
1761
|
function rawType(obj) {
|
|
1766
|
-
return objectToString.call(obj).slice(8, -1);
|
|
1762
|
+
return objectToString.call(toRaw(obj)).slice(8, -1);
|
|
1767
1763
|
}
|
|
1768
1764
|
/**
|
|
1769
1765
|
* Checks whether a given value can be made into a reactive object.
|
|
@@ -1787,6 +1783,7 @@
|
|
|
1787
1783
|
function possiblyReactive(val, cb) {
|
|
1788
1784
|
return canBeMadeReactive(val) ? reactive(val, cb) : val;
|
|
1789
1785
|
}
|
|
1786
|
+
const skipped = new WeakSet();
|
|
1790
1787
|
/**
|
|
1791
1788
|
* Mark an object or array so that it is ignored by the reactivity system
|
|
1792
1789
|
*
|
|
@@ -1794,7 +1791,7 @@
|
|
|
1794
1791
|
* @returns the object itself
|
|
1795
1792
|
*/
|
|
1796
1793
|
function markRaw(value) {
|
|
1797
|
-
value
|
|
1794
|
+
skipped.add(value);
|
|
1798
1795
|
return value;
|
|
1799
1796
|
}
|
|
1800
1797
|
/**
|
|
@@ -1804,7 +1801,7 @@
|
|
|
1804
1801
|
* @returns the underlying value
|
|
1805
1802
|
*/
|
|
1806
1803
|
function toRaw(value) {
|
|
1807
|
-
return value
|
|
1804
|
+
return targets.has(value) ? targets.get(value) : value;
|
|
1808
1805
|
}
|
|
1809
1806
|
const targetToKeysToCallbacks = new WeakMap();
|
|
1810
1807
|
/**
|
|
@@ -1886,6 +1883,8 @@
|
|
|
1886
1883
|
};
|
|
1887
1884
|
});
|
|
1888
1885
|
}
|
|
1886
|
+
// Maps reactive objects to the underlying target
|
|
1887
|
+
const targets = new WeakMap();
|
|
1889
1888
|
const reactiveCache = new WeakMap();
|
|
1890
1889
|
/**
|
|
1891
1890
|
* Creates a reactive proxy for an object. Reading data on the reactive object
|
|
@@ -1901,7 +1900,7 @@
|
|
|
1901
1900
|
* Subscriptions:
|
|
1902
1901
|
* + Reading a property on an object will subscribe you to changes in the value
|
|
1903
1902
|
* of that property.
|
|
1904
|
-
* + Accessing an object keys (eg with Object.keys or with `for..in`) will
|
|
1903
|
+
* + Accessing an object's keys (eg with Object.keys or with `for..in`) will
|
|
1905
1904
|
* subscribe you to the creation/deletion of keys. Checking the presence of a
|
|
1906
1905
|
* key on the object with 'in' has the same effect.
|
|
1907
1906
|
* - getOwnPropertyDescriptor does not currently subscribe you to the property.
|
|
@@ -1918,12 +1917,12 @@
|
|
|
1918
1917
|
if (!canBeMadeReactive(target)) {
|
|
1919
1918
|
throw new OwlError(`Cannot make the given value reactive`);
|
|
1920
1919
|
}
|
|
1921
|
-
if (
|
|
1920
|
+
if (skipped.has(target)) {
|
|
1922
1921
|
return target;
|
|
1923
1922
|
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
return reactive(
|
|
1923
|
+
if (targets.has(target)) {
|
|
1924
|
+
// target is reactive, create a reactive on the underlying object instead
|
|
1925
|
+
return reactive(targets.get(target), callback);
|
|
1927
1926
|
}
|
|
1928
1927
|
if (!reactiveCache.has(target)) {
|
|
1929
1928
|
reactiveCache.set(target, new WeakMap());
|
|
@@ -1936,6 +1935,7 @@
|
|
|
1936
1935
|
: basicProxyHandler(callback);
|
|
1937
1936
|
const proxy = new Proxy(target, handler);
|
|
1938
1937
|
reactivesForTarget.set(callback, proxy);
|
|
1938
|
+
targets.set(proxy, target);
|
|
1939
1939
|
}
|
|
1940
1940
|
return reactivesForTarget.get(callback);
|
|
1941
1941
|
}
|
|
@@ -1947,29 +1947,27 @@
|
|
|
1947
1947
|
*/
|
|
1948
1948
|
function basicProxyHandler(callback) {
|
|
1949
1949
|
return {
|
|
1950
|
-
get(target, key,
|
|
1951
|
-
if (key === TARGET) {
|
|
1952
|
-
return target;
|
|
1953
|
-
}
|
|
1950
|
+
get(target, key, receiver) {
|
|
1954
1951
|
// non-writable non-configurable properties cannot be made reactive
|
|
1955
1952
|
const desc = Object.getOwnPropertyDescriptor(target, key);
|
|
1956
1953
|
if (desc && !desc.writable && !desc.configurable) {
|
|
1957
|
-
return Reflect.get(target, key,
|
|
1954
|
+
return Reflect.get(target, key, receiver);
|
|
1958
1955
|
}
|
|
1959
1956
|
observeTargetKey(target, key, callback);
|
|
1960
|
-
return possiblyReactive(Reflect.get(target, key,
|
|
1957
|
+
return possiblyReactive(Reflect.get(target, key, receiver), callback);
|
|
1961
1958
|
},
|
|
1962
|
-
set(target, key, value,
|
|
1963
|
-
const
|
|
1964
|
-
const originalValue = Reflect.get(target, key,
|
|
1965
|
-
const ret = Reflect.set(target, key, value,
|
|
1966
|
-
if (
|
|
1959
|
+
set(target, key, value, receiver) {
|
|
1960
|
+
const hadKey = objectHasOwnProperty.call(target, key);
|
|
1961
|
+
const originalValue = Reflect.get(target, key, receiver);
|
|
1962
|
+
const ret = Reflect.set(target, key, value, receiver);
|
|
1963
|
+
if (!hadKey && objectHasOwnProperty.call(target, key)) {
|
|
1967
1964
|
notifyReactives(target, KEYCHANGES);
|
|
1968
1965
|
}
|
|
1969
1966
|
// While Array length may trigger the set trap, it's not actually set by this
|
|
1970
1967
|
// method but is updated behind the scenes, and the trap is not called with the
|
|
1971
1968
|
// new value. We disable the "same-value-optimization" for it because of that.
|
|
1972
|
-
if (originalValue !==
|
|
1969
|
+
if (originalValue !== Reflect.get(target, key, receiver) ||
|
|
1970
|
+
(key === "length" && Array.isArray(target))) {
|
|
1973
1971
|
notifyReactives(target, key);
|
|
1974
1972
|
}
|
|
1975
1973
|
return ret;
|
|
@@ -2145,10 +2143,8 @@
|
|
|
2145
2143
|
// property is read.
|
|
2146
2144
|
const specialHandlers = rawTypeToFuncHandlers[targetRawType](target, callback);
|
|
2147
2145
|
return Object.assign(basicProxyHandler(callback), {
|
|
2146
|
+
// FIXME: probably broken when part of prototype chain since we ignore the receiver
|
|
2148
2147
|
get(target, key) {
|
|
2149
|
-
if (key === TARGET) {
|
|
2150
|
-
return target;
|
|
2151
|
-
}
|
|
2152
2148
|
if (objectHasOwnProperty.call(specialHandlers, key)) {
|
|
2153
2149
|
return specialHandlers[key];
|
|
2154
2150
|
}
|
|
@@ -2308,12 +2304,13 @@
|
|
|
2308
2304
|
this.childEnv = env;
|
|
2309
2305
|
for (const key in props) {
|
|
2310
2306
|
const prop = props[key];
|
|
2311
|
-
if (prop && typeof prop === "object" && prop
|
|
2307
|
+
if (prop && typeof prop === "object" && targets.has(prop)) {
|
|
2312
2308
|
props[key] = useState(prop);
|
|
2313
2309
|
}
|
|
2314
2310
|
}
|
|
2315
2311
|
this.component = new C(props, env, this);
|
|
2316
|
-
|
|
2312
|
+
const ctx = Object.assign(Object.create(this.component), { this: this.component });
|
|
2313
|
+
this.renderFn = app.getTemplate(C.template).bind(this.component, ctx, this);
|
|
2317
2314
|
this.component.setup();
|
|
2318
2315
|
currentNode = null;
|
|
2319
2316
|
}
|
|
@@ -2426,7 +2423,7 @@
|
|
|
2426
2423
|
currentNode = this;
|
|
2427
2424
|
for (const key in props) {
|
|
2428
2425
|
const prop = props[key];
|
|
2429
|
-
if (prop && typeof prop === "object" && prop
|
|
2426
|
+
if (prop && typeof prop === "object" && targets.has(prop)) {
|
|
2430
2427
|
props[key] = useState(prop);
|
|
2431
2428
|
}
|
|
2432
2429
|
}
|
|
@@ -2504,6 +2501,7 @@
|
|
|
2504
2501
|
}
|
|
2505
2502
|
_patch() {
|
|
2506
2503
|
let hasChildren = false;
|
|
2504
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2507
2505
|
for (let _k in this.children) {
|
|
2508
2506
|
hasChildren = true;
|
|
2509
2507
|
break;
|
|
@@ -2884,7 +2882,7 @@
|
|
|
2884
2882
|
if (__scope) {
|
|
2885
2883
|
slotScope[__scope] = extra;
|
|
2886
2884
|
}
|
|
2887
|
-
const slotBDom = __render ? __render
|
|
2885
|
+
const slotBDom = __render ? __render(slotScope, parent, key) : null;
|
|
2888
2886
|
if (defaultContent) {
|
|
2889
2887
|
let child1 = undefined;
|
|
2890
2888
|
let child2 = undefined;
|
|
@@ -2892,15 +2890,14 @@
|
|
|
2892
2890
|
child1 = dynamic ? toggler(name, slotBDom) : slotBDom;
|
|
2893
2891
|
}
|
|
2894
2892
|
else {
|
|
2895
|
-
child2 = defaultContent
|
|
2893
|
+
child2 = defaultContent(ctx, parent, key);
|
|
2896
2894
|
}
|
|
2897
2895
|
return multi([child1, child2]);
|
|
2898
2896
|
}
|
|
2899
2897
|
return slotBDom || text("");
|
|
2900
2898
|
}
|
|
2901
2899
|
function capture(ctx) {
|
|
2902
|
-
const
|
|
2903
|
-
const result = ObjectCreate(component);
|
|
2900
|
+
const result = ObjectCreate(ctx);
|
|
2904
2901
|
for (let k in ctx) {
|
|
2905
2902
|
result[k] = ctx[k];
|
|
2906
2903
|
}
|
|
@@ -3009,8 +3006,7 @@
|
|
|
3009
3006
|
let boundFunctions = new WeakMap();
|
|
3010
3007
|
const WeakMapGet = WeakMap.prototype.get;
|
|
3011
3008
|
const WeakMapSet = WeakMap.prototype.set;
|
|
3012
|
-
function bind(
|
|
3013
|
-
let component = ctx.__owl__.component;
|
|
3009
|
+
function bind(component, fn) {
|
|
3014
3010
|
let boundFnMap = WeakMapGet.call(boundFunctions, component);
|
|
3015
3011
|
if (!boundFnMap) {
|
|
3016
3012
|
boundFnMap = new WeakMap();
|
|
@@ -3238,7 +3234,7 @@
|
|
|
3238
3234
|
//------------------------------------------------------------------------------
|
|
3239
3235
|
// Misc types, constants and helpers
|
|
3240
3236
|
//------------------------------------------------------------------------------
|
|
3241
|
-
const RESERVED_WORDS = "true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,
|
|
3237
|
+
const RESERVED_WORDS = "true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,eval,void,Math,RegExp,Array,Object,Date".split(",");
|
|
3242
3238
|
const WORD_REPLACEMENT = Object.assign(Object.create(null), {
|
|
3243
3239
|
and: "&&",
|
|
3244
3240
|
or: "||",
|
|
@@ -3624,7 +3620,7 @@
|
|
|
3624
3620
|
let result = [];
|
|
3625
3621
|
result.push(`function ${this.name}(ctx, node, key = "") {`);
|
|
3626
3622
|
if (this.hasRef) {
|
|
3627
|
-
result.push(` const refs =
|
|
3623
|
+
result.push(` const refs = this.__owl__.refs;`);
|
|
3628
3624
|
for (let name in this.refInfo) {
|
|
3629
3625
|
const [id, expr] = this.refInfo[name];
|
|
3630
3626
|
result.push(` const ${id} = ${expr};`);
|
|
@@ -3716,7 +3712,7 @@
|
|
|
3716
3712
|
for (let block of this.blocks) {
|
|
3717
3713
|
if (block.dom) {
|
|
3718
3714
|
let xmlString = block.asXmlString();
|
|
3719
|
-
xmlString = xmlString.replace(/`/g, "\\`");
|
|
3715
|
+
xmlString = xmlString.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
|
|
3720
3716
|
if (block.dynamicTagName) {
|
|
3721
3717
|
xmlString = xmlString.replace(/^<\w+/, `<\${tag || '${block.dom.nodeName}'}`);
|
|
3722
3718
|
xmlString = xmlString.replace(/\w+>$/, `\${tag || '${block.dom.nodeName}'}>`);
|
|
@@ -4009,39 +4005,6 @@
|
|
|
4009
4005
|
attrs[`block-attribute-${selectedId}`] = "selected";
|
|
4010
4006
|
}
|
|
4011
4007
|
}
|
|
4012
|
-
// event handlers
|
|
4013
|
-
for (let ev in ast.on) {
|
|
4014
|
-
const name = this.generateHandlerCode(ev, ast.on[ev]);
|
|
4015
|
-
const idx = block.insertData(name, "hdlr");
|
|
4016
|
-
attrs[`block-handler-${idx}`] = ev;
|
|
4017
|
-
}
|
|
4018
|
-
// t-ref
|
|
4019
|
-
if (ast.ref) {
|
|
4020
|
-
this.target.hasRef = true;
|
|
4021
|
-
const isDynamic = INTERP_REGEXP.test(ast.ref);
|
|
4022
|
-
if (isDynamic) {
|
|
4023
|
-
const str = replaceDynamicParts(ast.ref, (expr) => this.captureExpression(expr, true));
|
|
4024
|
-
const idx = block.insertData(`(el) => refs[${str}] = el`, "ref");
|
|
4025
|
-
attrs["block-ref"] = String(idx);
|
|
4026
|
-
}
|
|
4027
|
-
else {
|
|
4028
|
-
let name = ast.ref;
|
|
4029
|
-
if (name in this.target.refInfo) {
|
|
4030
|
-
// ref has already been defined
|
|
4031
|
-
this.helpers.add("multiRefSetter");
|
|
4032
|
-
const info = this.target.refInfo[name];
|
|
4033
|
-
const index = block.data.push(info[0]) - 1;
|
|
4034
|
-
attrs["block-ref"] = String(index);
|
|
4035
|
-
info[1] = `multiRefSetter(refs, \`${name}\`)`;
|
|
4036
|
-
}
|
|
4037
|
-
else {
|
|
4038
|
-
let id = generateId("ref");
|
|
4039
|
-
this.target.refInfo[name] = [id, `(el) => refs[\`${name}\`] = el`];
|
|
4040
|
-
const index = block.data.push(id) - 1;
|
|
4041
|
-
attrs["block-ref"] = String(index);
|
|
4042
|
-
}
|
|
4043
|
-
}
|
|
4044
|
-
}
|
|
4045
4008
|
// t-model
|
|
4046
4009
|
let tModelSelectedExpr;
|
|
4047
4010
|
if (ast.model) {
|
|
@@ -4075,6 +4038,39 @@
|
|
|
4075
4038
|
idx = block.insertData(handler, "hdlr");
|
|
4076
4039
|
attrs[`block-handler-${idx}`] = eventType;
|
|
4077
4040
|
}
|
|
4041
|
+
// event handlers
|
|
4042
|
+
for (let ev in ast.on) {
|
|
4043
|
+
const name = this.generateHandlerCode(ev, ast.on[ev]);
|
|
4044
|
+
const idx = block.insertData(name, "hdlr");
|
|
4045
|
+
attrs[`block-handler-${idx}`] = ev;
|
|
4046
|
+
}
|
|
4047
|
+
// t-ref
|
|
4048
|
+
if (ast.ref) {
|
|
4049
|
+
this.target.hasRef = true;
|
|
4050
|
+
const isDynamic = INTERP_REGEXP.test(ast.ref);
|
|
4051
|
+
if (isDynamic) {
|
|
4052
|
+
const str = replaceDynamicParts(ast.ref, (expr) => this.captureExpression(expr, true));
|
|
4053
|
+
const idx = block.insertData(`(el) => refs[${str}] = el`, "ref");
|
|
4054
|
+
attrs["block-ref"] = String(idx);
|
|
4055
|
+
}
|
|
4056
|
+
else {
|
|
4057
|
+
let name = ast.ref;
|
|
4058
|
+
if (name in this.target.refInfo) {
|
|
4059
|
+
// ref has already been defined
|
|
4060
|
+
this.helpers.add("multiRefSetter");
|
|
4061
|
+
const info = this.target.refInfo[name];
|
|
4062
|
+
const index = block.data.push(info[0]) - 1;
|
|
4063
|
+
attrs["block-ref"] = String(index);
|
|
4064
|
+
info[1] = `multiRefSetter(refs, \`${name}\`)`;
|
|
4065
|
+
}
|
|
4066
|
+
else {
|
|
4067
|
+
let id = generateId("ref");
|
|
4068
|
+
this.target.refInfo[name] = [id, `(el) => refs[\`${name}\`] = el`];
|
|
4069
|
+
const index = block.data.push(id) - 1;
|
|
4070
|
+
attrs["block-ref"] = String(index);
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4078
4074
|
const dom = xmlDoc.createElement(ast.tag);
|
|
4079
4075
|
for (const [attr, val] of Object.entries(attrs)) {
|
|
4080
4076
|
if (!(attr === "class" && val === "")) {
|
|
@@ -4483,7 +4479,7 @@
|
|
|
4483
4479
|
if (suffix === "bind") {
|
|
4484
4480
|
this.helpers.add("bind");
|
|
4485
4481
|
name = _name;
|
|
4486
|
-
value = `bind(
|
|
4482
|
+
value = `bind(this, ${value || undefined})`;
|
|
4487
4483
|
}
|
|
4488
4484
|
else {
|
|
4489
4485
|
throw new OwlError("Invalid prop suffix");
|
|
@@ -4522,7 +4518,7 @@
|
|
|
4522
4518
|
const params = [];
|
|
4523
4519
|
if (slotAst.content) {
|
|
4524
4520
|
const name = this.compileInNewTarget("slot", slotAst.content, ctx, slotAst.on);
|
|
4525
|
-
params.push(`__render: ${name}, __ctx: ${ctxStr}`);
|
|
4521
|
+
params.push(`__render: ${name}.bind(this), __ctx: ${ctxStr}`);
|
|
4526
4522
|
}
|
|
4527
4523
|
const scope = ast.slots[slotName].scope;
|
|
4528
4524
|
if (scope) {
|
|
@@ -4633,7 +4629,7 @@
|
|
|
4633
4629
|
const scope = this.getPropString(props, dynProps);
|
|
4634
4630
|
if (ast.defaultContent) {
|
|
4635
4631
|
const name = this.compileInNewTarget("defaultContent", ast.defaultContent, ctx);
|
|
4636
|
-
blockString = `callSlot(ctx, node, ${key}, ${slotName}, ${dynamic}, ${scope}, ${name})`;
|
|
4632
|
+
blockString = `callSlot(ctx, node, ${key}, ${slotName}, ${dynamic}, ${scope}, ${name}.bind(this))`;
|
|
4637
4633
|
}
|
|
4638
4634
|
else {
|
|
4639
4635
|
if (dynamic) {
|
|
@@ -4681,7 +4677,7 @@
|
|
|
4681
4677
|
expr: `app.createComponent(null, false, true, false, false)`,
|
|
4682
4678
|
});
|
|
4683
4679
|
const target = compileExpr(ast.target);
|
|
4684
|
-
const blockString = `${id}({target: ${target},slots: {'default': {__render: ${name}, __ctx: ${ctxStr}}}}, key + \`${key}\`, node, ctx, Portal)`;
|
|
4680
|
+
const blockString = `${id}({target: ${target},slots: {'default': {__render: ${name}.bind(this), __ctx: ${ctxStr}}}}, key + \`${key}\`, node, ctx, Portal)`;
|
|
4685
4681
|
if (block) {
|
|
4686
4682
|
this.insertAnchor(block);
|
|
4687
4683
|
}
|
|
@@ -5656,7 +5652,11 @@ See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration
|
|
|
5656
5652
|
else {
|
|
5657
5653
|
// new component
|
|
5658
5654
|
if (isStatic) {
|
|
5659
|
-
|
|
5655
|
+
const components = parent.constructor.components;
|
|
5656
|
+
if (!components) {
|
|
5657
|
+
throw new OwlError(`Cannot find the definition of component "${name}", missing static components key in parent`);
|
|
5658
|
+
}
|
|
5659
|
+
C = components[name];
|
|
5660
5660
|
if (!C) {
|
|
5661
5661
|
throw new OwlError(`Cannot find the definition of component "${name}"`);
|
|
5662
5662
|
}
|
|
@@ -5858,9 +5858,9 @@ See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration
|
|
|
5858
5858
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5859
5859
|
|
|
5860
5860
|
|
|
5861
|
-
__info__.version = '2.0.
|
|
5862
|
-
__info__.date = '
|
|
5863
|
-
__info__.hash = '
|
|
5861
|
+
__info__.version = '2.0.3';
|
|
5862
|
+
__info__.date = '2023-01-20T10:27:02.171Z';
|
|
5863
|
+
__info__.hash = '316eb06';
|
|
5864
5864
|
__info__.url = 'https://github.com/odoo/owl';
|
|
5865
5865
|
|
|
5866
5866
|
|