@odoo/owl 2.2.3 → 2.2.5

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.es.js CHANGED
@@ -82,67 +82,6 @@ function toggler(key, child) {
82
82
 
83
83
  // Custom error class that wraps error that happen in the owl lifecycle
84
84
  class OwlError extends Error {
85
- }
86
- // Maps fibers to thrown errors
87
- const fibersInError = new WeakMap();
88
- const nodeErrorHandlers = new WeakMap();
89
- function _handleError(node, error) {
90
- if (!node) {
91
- return false;
92
- }
93
- const fiber = node.fiber;
94
- if (fiber) {
95
- fibersInError.set(fiber, error);
96
- }
97
- const errorHandlers = nodeErrorHandlers.get(node);
98
- if (errorHandlers) {
99
- let handled = false;
100
- // execute in the opposite order
101
- for (let i = errorHandlers.length - 1; i >= 0; i--) {
102
- try {
103
- errorHandlers[i](error);
104
- handled = true;
105
- break;
106
- }
107
- catch (e) {
108
- error = e;
109
- }
110
- }
111
- if (handled) {
112
- return true;
113
- }
114
- }
115
- return _handleError(node.parent, error);
116
- }
117
- function handleError(params) {
118
- let { error } = params;
119
- // Wrap error if it wasn't wrapped by wrapError (ie when not in dev mode)
120
- if (!(error instanceof OwlError)) {
121
- error = Object.assign(new OwlError(`An error occured in the owl lifecycle (see this Error's "cause" property)`), { cause: error });
122
- }
123
- const node = "node" in params ? params.node : params.fiber.node;
124
- const fiber = "fiber" in params ? params.fiber : node.fiber;
125
- if (fiber) {
126
- // resets the fibers on components if possible. This is important so that
127
- // new renderings can be properly included in the initial one, if any.
128
- let current = fiber;
129
- do {
130
- current.node.fiber = current;
131
- current = current.parent;
132
- } while (current);
133
- fibersInError.set(fiber.root, error);
134
- }
135
- const handled = _handleError(node, error);
136
- if (!handled) {
137
- console.warn(`[Owl] Unhandled error. Destroying the root component`);
138
- try {
139
- node.app.destroy();
140
- }
141
- catch (e) {
142
- console.error(e);
143
- }
144
- throw error;
145
- }
146
85
  }
147
86
 
148
87
  const { setAttribute: elemSetAttribute, removeAttribute } = Element.prototype;
@@ -771,12 +710,7 @@ function buildTree(node, parent = null, domParentTree = null) {
771
710
  info.push({ type: "child", idx: index });
772
711
  el = document.createTextNode("");
773
712
  }
774
- const attrs = node.attributes;
775
- const ns = attrs.getNamedItem("block-ns");
776
- if (ns) {
777
- attrs.removeNamedItem("block-ns");
778
- currentNS = ns.value;
779
- }
713
+ currentNS || (currentNS = node.namespaceURI);
780
714
  if (!el) {
781
715
  el = currentNS
782
716
  ? document.createElementNS(currentNS, tagName)
@@ -792,6 +726,7 @@ function buildTree(node, parent = null, domParentTree = null) {
792
726
  const fragment = document.createElement("template").content;
793
727
  fragment.appendChild(el);
794
728
  }
729
+ const attrs = node.attributes;
795
730
  for (let i = 0; i < attrs.length; i++) {
796
731
  const attrName = attrs[i].name;
797
732
  const attrValue = attrs[i].value;
@@ -1603,6 +1538,68 @@ function remove(vnode, withBeforeRemove = false) {
1603
1538
  vnode.remove();
1604
1539
  }
1605
1540
 
1541
+ // Maps fibers to thrown errors
1542
+ const fibersInError = new WeakMap();
1543
+ const nodeErrorHandlers = new WeakMap();
1544
+ function _handleError(node, error) {
1545
+ if (!node) {
1546
+ return false;
1547
+ }
1548
+ const fiber = node.fiber;
1549
+ if (fiber) {
1550
+ fibersInError.set(fiber, error);
1551
+ }
1552
+ const errorHandlers = nodeErrorHandlers.get(node);
1553
+ if (errorHandlers) {
1554
+ let handled = false;
1555
+ // execute in the opposite order
1556
+ for (let i = errorHandlers.length - 1; i >= 0; i--) {
1557
+ try {
1558
+ errorHandlers[i](error);
1559
+ handled = true;
1560
+ break;
1561
+ }
1562
+ catch (e) {
1563
+ error = e;
1564
+ }
1565
+ }
1566
+ if (handled) {
1567
+ return true;
1568
+ }
1569
+ }
1570
+ return _handleError(node.parent, error);
1571
+ }
1572
+ function handleError(params) {
1573
+ let { error } = params;
1574
+ // Wrap error if it wasn't wrapped by wrapError (ie when not in dev mode)
1575
+ if (!(error instanceof OwlError)) {
1576
+ error = Object.assign(new OwlError(`An error occured in the owl lifecycle (see this Error's "cause" property)`), { cause: error });
1577
+ }
1578
+ const node = "node" in params ? params.node : params.fiber.node;
1579
+ const fiber = "fiber" in params ? params.fiber : node.fiber;
1580
+ if (fiber) {
1581
+ // resets the fibers on components if possible. This is important so that
1582
+ // new renderings can be properly included in the initial one, if any.
1583
+ let current = fiber;
1584
+ do {
1585
+ current.node.fiber = current;
1586
+ current = current.parent;
1587
+ } while (current);
1588
+ fibersInError.set(fiber.root, error);
1589
+ }
1590
+ const handled = _handleError(node, error);
1591
+ if (!handled) {
1592
+ console.warn(`[Owl] Unhandled error. Destroying the root component`);
1593
+ try {
1594
+ node.app.destroy();
1595
+ }
1596
+ catch (e) {
1597
+ console.error(e);
1598
+ }
1599
+ throw error;
1600
+ }
1601
+ }
1602
+
1606
1603
  function makeChildFiber(node, parent) {
1607
1604
  let current = node.fiber;
1608
1605
  if (current) {
@@ -3007,8 +3004,8 @@ function prepareList(collection) {
3007
3004
  values = keys;
3008
3005
  }
3009
3006
  else {
3010
- values = Object.keys(collection);
3011
- keys = Object.values(collection);
3007
+ values = Object.values(collection);
3008
+ keys = Object.keys(collection);
3012
3009
  }
3013
3010
  }
3014
3011
  else {
@@ -3853,7 +3850,7 @@ class CodeGenerator {
3853
3850
  createBlock(parentBlock, type, ctx) {
3854
3851
  const hasRoot = this.target.hasRoot;
3855
3852
  const block = new BlockDescription(this.target, type);
3856
- if (!hasRoot && !ctx.preventRoot) {
3853
+ if (!hasRoot) {
3857
3854
  this.target.hasRoot = true;
3858
3855
  block.isRoot = true;
3859
3856
  }
@@ -3876,7 +3873,7 @@ class CodeGenerator {
3876
3873
  if (ctx.tKeyExpr) {
3877
3874
  blockExpr = `toggler(${ctx.tKeyExpr}, ${blockExpr})`;
3878
3875
  }
3879
- if (block.isRoot && !ctx.preventRoot) {
3876
+ if (block.isRoot) {
3880
3877
  if (this.target.on) {
3881
3878
  blockExpr = this.wrapWithEventCatcher(blockExpr, this.target.on);
3882
3879
  }
@@ -4052,11 +4049,6 @@ class CodeGenerator {
4052
4049
  }
4053
4050
  // attributes
4054
4051
  const attrs = {};
4055
- const nameSpace = ast.ns || ctx.nameSpace;
4056
- if (nameSpace && isNewBlock) {
4057
- // specific namespace uri
4058
- attrs["block-ns"] = nameSpace;
4059
- }
4060
4052
  for (let key in ast.attrs) {
4061
4053
  let expr, attrName;
4062
4054
  if (key.startsWith("t-attf")) {
@@ -4172,7 +4164,10 @@ class CodeGenerator {
4172
4164
  const idx = block.insertData(setRefStr, "ref");
4173
4165
  attrs["block-ref"] = String(idx);
4174
4166
  }
4175
- const dom = xmlDoc.createElement(ast.tag);
4167
+ const nameSpace = ast.ns || ctx.nameSpace;
4168
+ const dom = nameSpace
4169
+ ? xmlDoc.createElementNS(nameSpace, ast.tag)
4170
+ : xmlDoc.createElement(ast.tag);
4176
4171
  for (const [attr, val] of Object.entries(attrs)) {
4177
4172
  if (!(attr === "class" && val === "")) {
4178
4173
  dom.setAttribute(attr, val);
@@ -4214,7 +4209,7 @@ class CodeGenerator {
4214
4209
  break;
4215
4210
  }
4216
4211
  }
4217
- this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx);
4212
+ this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx);
4218
4213
  }
4219
4214
  }
4220
4215
  return block.varName;
@@ -4317,7 +4312,7 @@ class CodeGenerator {
4317
4312
  break;
4318
4313
  }
4319
4314
  }
4320
- this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx);
4315
+ this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx);
4321
4316
  }
4322
4317
  // note: this part is duplicated from end of compilemulti:
4323
4318
  const args = block.children.map((c) => c.varName).join(", ");
@@ -4346,18 +4341,18 @@ class CodeGenerator {
4346
4341
  }
4347
4342
  this.addLine(`for (let ${loopVar} = 0; ${loopVar} < ${l}; ${loopVar}++) {`);
4348
4343
  this.target.indentLevel++;
4349
- this.addLine(`ctx[\`${ast.elem}\`] = ${vals}[${loopVar}];`);
4344
+ this.addLine(`ctx[\`${ast.elem}\`] = ${keys}[${loopVar}];`);
4350
4345
  if (!ast.hasNoFirst) {
4351
4346
  this.addLine(`ctx[\`${ast.elem}_first\`] = ${loopVar} === 0;`);
4352
4347
  }
4353
4348
  if (!ast.hasNoLast) {
4354
- this.addLine(`ctx[\`${ast.elem}_last\`] = ${loopVar} === ${vals}.length - 1;`);
4349
+ this.addLine(`ctx[\`${ast.elem}_last\`] = ${loopVar} === ${keys}.length - 1;`);
4355
4350
  }
4356
4351
  if (!ast.hasNoIndex) {
4357
4352
  this.addLine(`ctx[\`${ast.elem}_index\`] = ${loopVar};`);
4358
4353
  }
4359
4354
  if (!ast.hasNoValue) {
4360
- this.addLine(`ctx[\`${ast.elem}_value\`] = ${keys}[${loopVar}];`);
4355
+ this.addLine(`ctx[\`${ast.elem}_value\`] = ${vals}[${loopVar}];`);
4361
4356
  }
4362
4357
  this.define(`key${this.target.loopLevel}`, ast.key ? compileExpr(ast.key) : loopVar);
4363
4358
  if (this.dev) {
@@ -4432,7 +4427,6 @@ class CodeGenerator {
4432
4427
  block,
4433
4428
  index,
4434
4429
  forceNewBlock: !isTSet,
4435
- preventRoot: ctx.preventRoot,
4436
4430
  isLast: ctx.isLast && i === l - 1,
4437
4431
  });
4438
4432
  this.compileAST(child, subCtx);
@@ -4441,21 +4435,19 @@ class CodeGenerator {
4441
4435
  }
4442
4436
  }
4443
4437
  if (isNewBlock) {
4444
- if (block.hasDynamicChildren) {
4445
- if (block.children.length) {
4446
- const code = this.target.code;
4447
- const children = block.children.slice();
4448
- let current = children.shift();
4449
- for (let i = codeIdx; i < code.length; i++) {
4450
- if (code[i].trimStart().startsWith(`const ${current.varName} `)) {
4451
- code[i] = code[i].replace(`const ${current.varName}`, current.varName);
4452
- current = children.shift();
4453
- if (!current)
4454
- break;
4455
- }
4438
+ if (block.hasDynamicChildren && block.children.length) {
4439
+ const code = this.target.code;
4440
+ const children = block.children.slice();
4441
+ let current = children.shift();
4442
+ for (let i = codeIdx; i < code.length; i++) {
4443
+ if (code[i].trimStart().startsWith(`const ${current.varName} `)) {
4444
+ code[i] = code[i].replace(`const ${current.varName}`, current.varName);
4445
+ current = children.shift();
4446
+ if (!current)
4447
+ break;
4456
4448
  }
4457
- this.addLine(`let ${block.children.map((c) => c.varName)};`, codeIdx);
4458
4449
  }
4450
+ this.addLine(`let ${block.children.map((c) => c.varName).join(", ")};`, codeIdx);
4459
4451
  }
4460
4452
  const args = block.children.map((c) => c.varName).join(", ");
4461
4453
  this.insertBlock(`multi([${args}])`, block, ctx);
@@ -4469,24 +4461,23 @@ class CodeGenerator {
4469
4461
  ctxVar = generateId("ctx");
4470
4462
  this.addLine(`let ${ctxVar} = ${compileExpr(ast.context)};`);
4471
4463
  }
4464
+ const isDynamic = INTERP_REGEXP.test(ast.name);
4465
+ const subTemplate = isDynamic ? interpolate(ast.name) : "`" + ast.name + "`";
4466
+ if (block && !forceNewBlock) {
4467
+ this.insertAnchor(block);
4468
+ }
4469
+ block = this.createBlock(block, "multi", ctx);
4472
4470
  if (ast.body) {
4473
4471
  this.addLine(`${ctxVar} = Object.create(${ctxVar});`);
4474
4472
  this.addLine(`${ctxVar}[isBoundary] = 1;`);
4475
4473
  this.helpers.add("isBoundary");
4476
- const subCtx = createContext(ctx, { preventRoot: true, ctxVar });
4474
+ const subCtx = createContext(ctx, { ctxVar });
4477
4475
  const bl = this.compileMulti({ type: 3 /* Multi */, content: ast.body }, subCtx);
4478
4476
  if (bl) {
4479
4477
  this.helpers.add("zero");
4480
4478
  this.addLine(`${ctxVar}[zero] = ${bl};`);
4481
4479
  }
4482
4480
  }
4483
- const isDynamic = INTERP_REGEXP.test(ast.name);
4484
- const subTemplate = isDynamic ? interpolate(ast.name) : "`" + ast.name + "`";
4485
- if (block) {
4486
- if (!forceNewBlock) {
4487
- this.insertAnchor(block);
4488
- }
4489
- }
4490
4481
  const key = `key + \`${this.generateComponentKey()}\``;
4491
4482
  if (isDynamic) {
4492
4483
  const templateVar = generateId("template");
@@ -4494,7 +4485,6 @@ class CodeGenerator {
4494
4485
  this.staticDefs.push({ id: "call", expr: `app.callTemplate.bind(app)` });
4495
4486
  }
4496
4487
  this.define(templateVar, subTemplate);
4497
- block = this.createBlock(block, "multi", ctx);
4498
4488
  this.insertBlock(`call(this, ${templateVar}, ${ctxVar}, node, ${key})`, block, {
4499
4489
  ...ctx,
4500
4490
  forceNewBlock: !block,
@@ -4503,7 +4493,6 @@ class CodeGenerator {
4503
4493
  else {
4504
4494
  const id = generateId(`callTemplate_`);
4505
4495
  this.staticDefs.push({ id, expr: `app.getTemplate(${subTemplate})` });
4506
- block = this.createBlock(block, "multi", ctx);
4507
4496
  this.insertBlock(`${id}.call(this, ${ctxVar}, node, ${key})`, block, {
4508
4497
  ...ctx,
4509
4498
  forceNewBlock: !block,
@@ -4825,7 +4814,7 @@ function parse(xml) {
4825
4814
  }
4826
4815
  function _parse(xml) {
4827
4816
  normalizeXML(xml);
4828
- const ctx = { inPreTag: false, inSVG: false };
4817
+ const ctx = { inPreTag: false };
4829
4818
  return parseNode(xml, ctx) || { type: 0 /* Text */, value: "" };
4830
4819
  }
4831
4820
  function parseNode(node, ctx) {
@@ -4916,9 +4905,7 @@ function parseDOMNode(node, ctx) {
4916
4905
  if (tagName === "pre") {
4917
4906
  ctx.inPreTag = true;
4918
4907
  }
4919
- const shouldAddSVGNS = ROOT_SVG_TAGS.has(tagName) && !ctx.inSVG;
4920
- ctx.inSVG = ctx.inSVG || shouldAddSVGNS;
4921
- const ns = shouldAddSVGNS ? "http://www.w3.org/2000/svg" : null;
4908
+ let ns = !ctx.nameSpace && ROOT_SVG_TAGS.has(tagName) ? "http://www.w3.org/2000/svg" : null;
4922
4909
  const ref = node.getAttribute("t-ref");
4923
4910
  node.removeAttribute("t-ref");
4924
4911
  const nodeAttrsNames = node.getAttributeNames();
@@ -4980,6 +4967,9 @@ function parseDOMNode(node, ctx) {
4980
4967
  else if (attr.startsWith("block-")) {
4981
4968
  throw new OwlError(`Invalid attribute: '${attr}'`);
4982
4969
  }
4970
+ else if (attr === "xmlns") {
4971
+ ns = value;
4972
+ }
4983
4973
  else if (attr !== "t-name") {
4984
4974
  if (attr.startsWith("t-") && !attr.startsWith("t-att")) {
4985
4975
  throw new OwlError(`Unknown QWeb directive: '${attr}'`);
@@ -4992,6 +4982,9 @@ function parseDOMNode(node, ctx) {
4992
4982
  attrs[attr] = value;
4993
4983
  }
4994
4984
  }
4985
+ if (ns) {
4986
+ ctx.nameSpace = ns;
4987
+ }
4995
4988
  const children = parseChildren(node, ctx);
4996
4989
  return {
4997
4990
  type: 2 /* DomNode */,
@@ -5547,11 +5540,20 @@ function compile(template, options = {}) {
5547
5540
  const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext });
5548
5541
  const code = codeGenerator.generateCode();
5549
5542
  // template function
5550
- return new Function("app, bdom, helpers", code);
5543
+ try {
5544
+ return new Function("app, bdom, helpers", code);
5545
+ }
5546
+ catch (originalError) {
5547
+ const { name } = options;
5548
+ const nameStr = name ? `template "${name}"` : "anonymous template";
5549
+ const err = new OwlError(`Failed to compile ${nameStr}: ${originalError.message}\n\ngenerated code:\nfunction(app, bdom, helpers) {\n${code}\n}`);
5550
+ err.cause = originalError;
5551
+ throw err;
5552
+ }
5551
5553
  }
5552
5554
 
5553
5555
  // do not modify manually. This file is generated by the release script.
5554
- const version = "2.2.3";
5556
+ const version = "2.2.5";
5555
5557
 
5556
5558
  // -----------------------------------------------------------------------------
5557
5559
  // Scheduler
@@ -5984,6 +5986,6 @@ TemplateSet.prototype._compileTemplate = function _compileTemplate(name, templat
5984
5986
  export { App, Component, EventBus, OwlError, __info__, blockDom, loadFile, markRaw, markup, mount, onError, onMounted, onPatched, onRendered, onWillDestroy, onWillPatch, onWillRender, onWillStart, onWillUnmount, onWillUpdateProps, reactive, status, toRaw, useChildSubEnv, useComponent, useEffect, useEnv, useExternalListener, useRef, useState, useSubEnv, validate, validateType, whenReady, xml };
5985
5987
 
5986
5988
 
5987
- __info__.date = '2023-07-20T06:05:29.796Z';
5988
- __info__.hash = 'b1a3b32';
5989
+ __info__.date = '2023-08-07T10:26:30.557Z';
5990
+ __info__.hash = 'b25e988';
5989
5991
  __info__.url = 'https://github.com/odoo/owl';