@odoo/owl 2.0.0-beta-10 → 2.0.0-beta-14

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.iife.js CHANGED
@@ -170,6 +170,10 @@
170
170
  for (let key in expr) {
171
171
  const value = expr[key];
172
172
  if (value) {
173
+ key = trim.call(key);
174
+ if (!key) {
175
+ continue;
176
+ }
173
177
  const words = split.call(key, wordRegexp);
174
178
  for (let word of words) {
175
179
  result[word] = value;
@@ -213,7 +217,7 @@
213
217
  function makePropSetter(name) {
214
218
  return function setProp(value) {
215
219
  // support 0, fallback to empty string for other falsy values
216
- this[name] = value === 0 ? 0 : value || "";
220
+ this[name] = value === 0 ? 0 : value ? value.valueOf() : "";
217
221
  };
218
222
  }
219
223
  function isProp(tag, key) {
@@ -1486,6 +1490,7 @@
1486
1490
  fiber.render = throwOnRender;
1487
1491
  if (node.status === 0 /* NEW */) {
1488
1492
  node.destroy();
1493
+ delete node.parent.children[node.parentKey];
1489
1494
  }
1490
1495
  node.fiber = null;
1491
1496
  if (fiber.bdom) {
@@ -2874,13 +2879,14 @@
2874
2879
  return true;
2875
2880
  }
2876
2881
  class LazyValue {
2877
- constructor(fn, ctx, node) {
2882
+ constructor(fn, ctx, component, node) {
2878
2883
  this.fn = fn;
2879
2884
  this.ctx = capture(ctx);
2885
+ this.component = component;
2880
2886
  this.node = node;
2881
2887
  }
2882
2888
  evaluate() {
2883
- return this.fn(this.ctx, this.node);
2889
+ return this.fn.call(this.component, this.ctx, this.node);
2884
2890
  }
2885
2891
  toString() {
2886
2892
  return this.evaluate().toString();
@@ -2889,9 +2895,9 @@
2889
2895
  /*
2890
2896
  * Safely outputs `value` as a block depending on the nature of `value`
2891
2897
  */
2892
- function safeOutput(value) {
2893
- if (!value) {
2894
- return value;
2898
+ function safeOutput(value, defaultValue) {
2899
+ if (value === undefined) {
2900
+ return defaultValue ? toggler("default", defaultValue) : toggler("undefined", text(""));
2895
2901
  }
2896
2902
  let safeKey;
2897
2903
  let block;
@@ -3177,7 +3183,7 @@
3177
3183
  });
3178
3184
  // note that the space after typeof is relevant. It makes sure that the formatted
3179
3185
  // expression has a space after typeof. Currently we don't support delete and void
3180
- const OPERATORS = "...,.,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ,=>,=,;,in ,new ".split(",");
3186
+ const OPERATORS = "...,.,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ,=>,=,;,in ,new ,|,&,^,~".split(",");
3181
3187
  let tokenizeString = function (expr) {
3182
3188
  let s = expr[0];
3183
3189
  let start = s;
@@ -3671,8 +3677,8 @@
3671
3677
  define(varName, expr) {
3672
3678
  this.addLine(`const ${varName} = ${expr};`);
3673
3679
  }
3674
- insertAnchor(block) {
3675
- const tag = `block-child-${block.children.length}`;
3680
+ insertAnchor(block, index = block.children.length) {
3681
+ const tag = `block-child-${index}`;
3676
3682
  const anchor = xmlDoc.createElement(tag);
3677
3683
  block.insert(anchor);
3678
3684
  }
@@ -3900,13 +3906,18 @@
3900
3906
  attrs["block-attribute-" + idx] = attrName;
3901
3907
  }
3902
3908
  else if (key.startsWith("t-att")) {
3909
+ attrName = key === "t-att" ? null : key.slice(6);
3903
3910
  expr = compileExpr(ast.attrs[key]);
3911
+ if (attrName && isProp(ast.tag, attrName)) {
3912
+ // we force a new string or new boolean to bypass the equality check in blockdom when patching same value
3913
+ const C = attrName === "value" ? "String" : "Boolean";
3914
+ expr = `new ${C}(${expr})`;
3915
+ }
3904
3916
  const idx = block.insertData(expr, "attr");
3905
3917
  if (key === "t-att") {
3906
3918
  attrs[`block-attributes`] = String(idx);
3907
3919
  }
3908
3920
  else {
3909
- attrName = key.slice(6);
3910
3921
  attrs[`block-attribute-${idx}`] = attrName;
3911
3922
  }
3912
3923
  }
@@ -4064,20 +4075,37 @@
4064
4075
  this.insertAnchor(block);
4065
4076
  }
4066
4077
  block = this.createBlock(block, "html", ctx);
4067
- this.helpers.add(ast.expr === "0" ? "zero" : "safeOutput");
4068
- let expr = ast.expr === "0" ? "ctx[zero]" : `safeOutput(${compileExpr(ast.expr)})`;
4069
- if (ast.body) {
4070
- const nextId = BlockDescription.nextBlockId;
4078
+ let blockStr;
4079
+ if (ast.expr === "0") {
4080
+ this.helpers.add("zero");
4081
+ blockStr = `ctx[zero]`;
4082
+ }
4083
+ else if (ast.body) {
4084
+ let bodyValue = null;
4085
+ bodyValue = BlockDescription.nextBlockId;
4071
4086
  const subCtx = createContext(ctx);
4072
4087
  this.compileAST({ type: 3 /* Multi */, content: ast.body }, subCtx);
4073
- this.helpers.add("withDefault");
4074
- expr = `withDefault(${expr}, b${nextId})`;
4088
+ this.helpers.add("safeOutput");
4089
+ blockStr = `safeOutput(${compileExpr(ast.expr)}, b${bodyValue})`;
4090
+ }
4091
+ else {
4092
+ this.helpers.add("safeOutput");
4093
+ blockStr = `safeOutput(${compileExpr(ast.expr)})`;
4094
+ }
4095
+ this.insertBlock(blockStr, block, ctx);
4096
+ }
4097
+ compileTIfBranch(content, block, ctx) {
4098
+ this.target.indentLevel++;
4099
+ let childN = block.children.length;
4100
+ this.compileAST(content, createContext(ctx, { block, index: ctx.index }));
4101
+ if (block.children.length > childN) {
4102
+ // we have some content => need to insert an anchor at correct index
4103
+ this.insertAnchor(block, childN);
4075
4104
  }
4076
- this.insertBlock(`${expr}`, block, ctx);
4105
+ this.target.indentLevel--;
4077
4106
  }
4078
4107
  compileTIf(ast, ctx, nextNode) {
4079
- let { block, forceNewBlock, index } = ctx;
4080
- let currentIndex = index;
4108
+ let { block, forceNewBlock } = ctx;
4081
4109
  const codeIdx = this.target.code.length;
4082
4110
  const isNewBlock = !block || (block.type !== "multi" && forceNewBlock);
4083
4111
  if (block) {
@@ -4087,28 +4115,16 @@
4087
4115
  block = this.createBlock(block, "multi", ctx);
4088
4116
  }
4089
4117
  this.addLine(`if (${compileExpr(ast.condition)}) {`);
4090
- this.target.indentLevel++;
4091
- this.insertAnchor(block);
4092
- const subCtx = createContext(ctx, { block, index: currentIndex });
4093
- this.compileAST(ast.content, subCtx);
4094
- this.target.indentLevel--;
4118
+ this.compileTIfBranch(ast.content, block, ctx);
4095
4119
  if (ast.tElif) {
4096
4120
  for (let clause of ast.tElif) {
4097
4121
  this.addLine(`} else if (${compileExpr(clause.condition)}) {`);
4098
- this.target.indentLevel++;
4099
- this.insertAnchor(block);
4100
- const subCtx = createContext(ctx, { block, index: currentIndex });
4101
- this.compileAST(clause.content, subCtx);
4102
- this.target.indentLevel--;
4122
+ this.compileTIfBranch(clause.content, block, ctx);
4103
4123
  }
4104
4124
  }
4105
4125
  if (ast.tElse) {
4106
4126
  this.addLine(`} else {`);
4107
- this.target.indentLevel++;
4108
- this.insertAnchor(block);
4109
- const subCtx = createContext(ctx, { block, index: currentIndex });
4110
- this.compileAST(ast.tElse, subCtx);
4111
- this.target.indentLevel--;
4127
+ this.compileTIfBranch(ast.tElse, block, ctx);
4112
4128
  }
4113
4129
  this.addLine("}");
4114
4130
  if (isNewBlock) {
@@ -4266,16 +4282,21 @@
4266
4282
  }
4267
4283
  compileTCall(ast, ctx) {
4268
4284
  let { block, forceNewBlock } = ctx;
4285
+ let ctxVar = ctx.ctxVar || "ctx";
4286
+ if (ast.context) {
4287
+ ctxVar = generateId("ctx");
4288
+ this.addLine(`let ${ctxVar} = ${compileExpr(ast.context)};`);
4289
+ }
4269
4290
  if (ast.body) {
4270
- this.addLine(`ctx = Object.create(ctx);`);
4271
- this.addLine(`ctx[isBoundary] = 1;`);
4291
+ this.addLine(`${ctxVar} = Object.create(${ctxVar});`);
4292
+ this.addLine(`${ctxVar}[isBoundary] = 1;`);
4272
4293
  this.helpers.add("isBoundary");
4273
4294
  const nextId = BlockDescription.nextBlockId;
4274
- const subCtx = createContext(ctx, { preventRoot: true });
4295
+ const subCtx = createContext(ctx, { preventRoot: true, ctxVar });
4275
4296
  this.compileAST({ type: 3 /* Multi */, content: ast.body }, subCtx);
4276
4297
  if (nextId !== BlockDescription.nextBlockId) {
4277
4298
  this.helpers.add("zero");
4278
- this.addLine(`ctx[zero] = b${nextId};`);
4299
+ this.addLine(`${ctxVar}[zero] = b${nextId};`);
4279
4300
  }
4280
4301
  }
4281
4302
  const isDynamic = INTERP_REGEXP.test(ast.name);
@@ -4293,7 +4314,7 @@
4293
4314
  }
4294
4315
  this.define(templateVar, subTemplate);
4295
4316
  block = this.createBlock(block, "multi", ctx);
4296
- this.insertBlock(`call(this, ${templateVar}, ctx, node, ${key})`, block, {
4317
+ this.insertBlock(`call(this, ${templateVar}, ${ctxVar}, node, ${key})`, block, {
4297
4318
  ...ctx,
4298
4319
  forceNewBlock: !block,
4299
4320
  });
@@ -4302,13 +4323,13 @@
4302
4323
  const id = generateId(`callTemplate_`);
4303
4324
  this.staticDefs.push({ id, expr: `app.getTemplate(${subTemplate})` });
4304
4325
  block = this.createBlock(block, "multi", ctx);
4305
- this.insertBlock(`${id}.call(this, ctx, node, ${key})`, block, {
4326
+ this.insertBlock(`${id}.call(this, ${ctxVar}, node, ${key})`, block, {
4306
4327
  ...ctx,
4307
4328
  forceNewBlock: !block,
4308
4329
  });
4309
4330
  }
4310
4331
  if (ast.body && !ctx.isLast) {
4311
- this.addLine(`ctx = ctx.__proto__;`);
4332
+ this.addLine(`${ctxVar} = ${ctxVar}.__proto__;`);
4312
4333
  }
4313
4334
  }
4314
4335
  compileTCallBlock(ast, ctx) {
@@ -4329,7 +4350,7 @@
4329
4350
  this.helpers.add("LazyValue");
4330
4351
  const bodyAst = { type: 3 /* Multi */, content: ast.body };
4331
4352
  const name = this.compileInNewTarget("value", bodyAst, ctx);
4332
- let value = `new LazyValue(${name}, ctx, node)`;
4353
+ let value = `new LazyValue(${name}, ctx, this, node)`;
4333
4354
  value = ast.value ? (value ? `withDefault(${expr}, ${value})` : expr) : value;
4334
4355
  this.addLine(`ctx[\`${ast.name}\`] = ${value};`);
4335
4356
  }
@@ -4347,7 +4368,7 @@
4347
4368
  value = expr;
4348
4369
  }
4349
4370
  this.helpers.add("setContextValue");
4350
- this.addLine(`setContextValue(ctx, "${ast.name}", ${value});`);
4371
+ this.addLine(`setContextValue(${ctx.ctxVar || "ctx"}, "${ast.name}", ${value});`);
4351
4372
  }
4352
4373
  }
4353
4374
  generateComponentKey() {
@@ -4469,7 +4490,7 @@
4469
4490
  id,
4470
4491
  expr: `app.createComponent(${ast.isDynamic ? null : expr}, ${!ast.isDynamic}, ${!!ast.slots}, ${!!ast.dynamicProps}, ${!ast.props && !ast.dynamicProps})`,
4471
4492
  });
4472
- let blockExpr = `${id}(${propString}, ${keyArg}, node, ctx, ${ast.isDynamic ? expr : null})`;
4493
+ let blockExpr = `${id}(${propString}, ${keyArg}, node, this, ${ast.isDynamic ? expr : null})`;
4473
4494
  if (ast.isDynamic) {
4474
4495
  blockExpr = `toggler(${expr}, ${blockExpr})`;
4475
4496
  }
@@ -4902,10 +4923,12 @@
4902
4923
  return null;
4903
4924
  }
4904
4925
  const subTemplate = node.getAttribute("t-call");
4926
+ const context = node.getAttribute("t-call-context");
4905
4927
  node.removeAttribute("t-call");
4928
+ node.removeAttribute("t-call-context");
4906
4929
  if (node.tagName !== "t") {
4907
4930
  const ast = parseNode(node, ctx);
4908
- const tcall = { type: 7 /* TCall */, name: subTemplate, body: null };
4931
+ const tcall = { type: 7 /* TCall */, name: subTemplate, body: null, context };
4909
4932
  if (ast && ast.type === 2 /* DomNode */) {
4910
4933
  ast.content = [tcall];
4911
4934
  return ast;
@@ -4922,6 +4945,7 @@
4922
4945
  type: 7 /* TCall */,
4923
4946
  name: subTemplate,
4924
4947
  body: body.length ? body : null,
4948
+ context,
4925
4949
  };
4926
4950
  }
4927
4951
  // -----------------------------------------------------------------------------
@@ -5525,8 +5549,7 @@ See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration
5525
5549
  return (props, key, ctx, parent, C) => {
5526
5550
  let children = ctx.children;
5527
5551
  let node = children[key];
5528
- if (node &&
5529
- (node.status === 2 /* DESTROYED */ || (isDynamic && node.component.constructor !== C))) {
5552
+ if (isDynamic && node && node.component.constructor !== C) {
5530
5553
  node = undefined;
5531
5554
  }
5532
5555
  const parentFiber = ctx.fiber;
@@ -5737,9 +5760,9 @@ See https://github.com/odoo/owl/blob/${hash}/doc/reference/app.md#configuration
5737
5760
  Object.defineProperty(exports, '__esModule', { value: true });
5738
5761
 
5739
5762
 
5740
- __info__.version = '2.0.0-beta-10';
5741
- __info__.date = '2022-06-22T08:33:26.205Z';
5742
- __info__.hash = '2e03332';
5763
+ __info__.version = '2.0.0-beta-14';
5764
+ __info__.date = '2022-07-08T14:17:53.900Z';
5765
+ __info__.hash = 'd111845';
5743
5766
  __info__.url = 'https://github.com/odoo/owl';
5744
5767
 
5745
5768