@odoo/owl 2.8.1 → 3.0.0-alpha.10
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/compile_templates.mjs +92 -189
- package/dist/compiler.js +2378 -0
- package/dist/owl-devtools.zip +0 -0
- package/dist/owl.cjs.js +1371 -1261
- package/dist/owl.cjs.runtime.js +4094 -0
- package/dist/owl.es.js +1358 -1252
- package/dist/owl.es.runtime.js +4050 -0
- package/dist/owl.iife.js +1371 -1261
- package/dist/owl.iife.min.js +1 -1
- package/dist/owl.iife.runtime.js +4098 -0
- package/dist/owl.iife.runtime.min.js +1 -0
- package/dist/types/compiler/code_generator.d.ts +3 -5
- package/dist/types/compiler/index.d.ts +4 -4
- package/dist/types/compiler/inline_expressions.d.ts +1 -1
- package/dist/types/compiler/parser.d.ts +21 -28
- package/dist/types/owl.d.ts +299 -205
- package/dist/types/runtime/app.d.ts +29 -31
- package/dist/types/runtime/blockdom/block_compiler.d.ts +3 -3
- package/dist/types/runtime/blockdom/config.d.ts +1 -1
- package/dist/types/runtime/blockdom/event_catcher.d.ts +2 -2
- package/dist/types/runtime/blockdom/events.d.ts +1 -1
- package/dist/types/runtime/blockdom/index.d.ts +1 -1
- package/dist/types/runtime/cancellableContext.d.ts +15 -0
- package/dist/types/runtime/cancellablePromise.d.ts +15 -0
- package/dist/types/runtime/component.d.ts +5 -13
- package/dist/types/runtime/component_node.d.ts +15 -35
- package/dist/types/runtime/event_handling.d.ts +1 -1
- package/dist/types/runtime/executionContext.d.ts +0 -0
- package/dist/types/runtime/hooks.d.ts +7 -33
- package/dist/types/runtime/index.d.ts +15 -5
- package/dist/types/runtime/lifecycle_hooks.d.ts +1 -3
- package/dist/types/runtime/listOperation.d.ts +1 -0
- package/dist/types/runtime/plugins.d.ts +23 -0
- package/dist/types/runtime/portal.d.ts +4 -6
- package/dist/types/runtime/props.d.ts +65 -0
- package/dist/types/runtime/reactivity/computations.d.ts +31 -0
- package/dist/types/runtime/reactivity/computed.d.ts +7 -0
- package/dist/types/runtime/reactivity/derived.d.ts +7 -0
- package/dist/types/runtime/reactivity/effect.d.ts +2 -0
- package/dist/types/runtime/reactivity/proxy.d.ts +46 -0
- package/dist/types/runtime/reactivity/reactivity.d.ts +46 -0
- package/dist/types/runtime/reactivity/signal.d.ts +17 -0
- package/dist/types/runtime/reactivity/signals.d.ts +30 -0
- package/dist/types/runtime/registry.d.ts +19 -0
- package/dist/types/runtime/relationalModel/discussModel.d.ts +19 -0
- package/dist/types/runtime/relationalModel/discussModelTypes.d.ts +22 -0
- package/dist/types/runtime/relationalModel/field.d.ts +20 -0
- package/dist/types/runtime/relationalModel/model.d.ts +59 -0
- package/dist/types/runtime/relationalModel/modelData.d.ts +18 -0
- package/dist/types/runtime/relationalModel/modelRegistry.d.ts +3 -0
- package/dist/types/runtime/relationalModel/modelUtils.d.ts +4 -0
- package/dist/types/runtime/relationalModel/store.d.ts +16 -0
- package/dist/types/runtime/relationalModel/types.d.ts +83 -0
- package/dist/types/runtime/relationalModel/util.d.ts +1 -0
- package/dist/types/runtime/relationalModel/web/WebDataPoint.d.ts +25 -0
- package/dist/types/runtime/relationalModel/web/WebRecord.d.ts +131 -0
- package/dist/types/runtime/relationalModel/web/WebStaticList.d.ts +63 -0
- package/dist/types/runtime/relationalModel/web/webModel.d.ts +5 -0
- package/dist/types/runtime/relationalModel/web/webModelTypes.d.ts +139 -0
- package/dist/types/runtime/rendering/error_handling.d.ts +13 -0
- package/dist/types/runtime/rendering/fibers.d.ts +37 -0
- package/dist/types/runtime/rendering/scheduler.d.ts +21 -0
- package/dist/types/runtime/rendering/template_helpers.d.ts +50 -0
- package/dist/types/runtime/resource.d.ts +12 -0
- package/dist/types/runtime/signals.d.ts +19 -0
- package/dist/types/runtime/status.d.ts +2 -3
- package/dist/types/runtime/task.d.ts +12 -0
- package/dist/types/runtime/template_set.d.ts +3 -4
- package/dist/types/runtime/utils.d.ts +1 -2
- package/dist/types/runtime/validation.d.ts +6 -6
- package/dist/types/utils/registry.d.ts +15 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +9 -9
|
@@ -250,7 +250,7 @@ function compileExprToArray(expr) {
|
|
|
250
250
|
stack.pop();
|
|
251
251
|
}
|
|
252
252
|
let isVar = token.type === "SYMBOL" && !RESERVED_WORDS.includes(token.value);
|
|
253
|
-
if (
|
|
253
|
+
if (isVar) {
|
|
254
254
|
if (prevToken) {
|
|
255
255
|
// normalize missing tokens: {a} should be equivalent to {a:a}
|
|
256
256
|
if (groupType === "LEFT_BRACE" &&
|
|
@@ -442,7 +442,6 @@ class CodeTarget {
|
|
|
442
442
|
this.hasRoot = false;
|
|
443
443
|
this.hasCache = false;
|
|
444
444
|
this.shouldProtectScope = false;
|
|
445
|
-
this.hasRefWrapper = false;
|
|
446
445
|
this.name = name;
|
|
447
446
|
this.on = on || null;
|
|
448
447
|
}
|
|
@@ -462,9 +461,6 @@ class CodeTarget {
|
|
|
462
461
|
result.push(` ctx = Object.create(ctx);`);
|
|
463
462
|
result.push(` ctx[isBoundary] = 1`);
|
|
464
463
|
}
|
|
465
|
-
if (this.hasRefWrapper) {
|
|
466
|
-
result.push(` let refWrapper = makeRefWrapper(this.__owl__);`);
|
|
467
|
-
}
|
|
468
464
|
if (this.hasCache) {
|
|
469
465
|
result.push(` let cache = ctx.cache || {};`);
|
|
470
466
|
result.push(` let nextCache = ctx.cache = {};`);
|
|
@@ -531,7 +527,7 @@ class CodeGenerator {
|
|
|
531
527
|
}
|
|
532
528
|
generateCode() {
|
|
533
529
|
const ast = this.ast;
|
|
534
|
-
this.isDebug = ast.type ===
|
|
530
|
+
this.isDebug = ast.type === 11 /* ASTType.TDebug */;
|
|
535
531
|
BlockDescription.nextBlockId = 1;
|
|
536
532
|
nextDataIds = {};
|
|
537
533
|
this.compileAST(ast, {
|
|
@@ -687,43 +683,41 @@ class CodeGenerator {
|
|
|
687
683
|
*/
|
|
688
684
|
compileAST(ast, ctx) {
|
|
689
685
|
switch (ast.type) {
|
|
690
|
-
case 1 /* Comment */:
|
|
686
|
+
case 1 /* ASTType.Comment */:
|
|
691
687
|
return this.compileComment(ast, ctx);
|
|
692
|
-
case 0 /* Text */:
|
|
688
|
+
case 0 /* ASTType.Text */:
|
|
693
689
|
return this.compileText(ast, ctx);
|
|
694
|
-
case 2 /* DomNode */:
|
|
690
|
+
case 2 /* ASTType.DomNode */:
|
|
695
691
|
return this.compileTDomNode(ast, ctx);
|
|
696
|
-
case
|
|
697
|
-
return this.compileTEsc(ast, ctx);
|
|
698
|
-
case 8 /* TOut */:
|
|
692
|
+
case 7 /* ASTType.TOut */:
|
|
699
693
|
return this.compileTOut(ast, ctx);
|
|
700
|
-
case
|
|
694
|
+
case 4 /* ASTType.TIf */:
|
|
701
695
|
return this.compileTIf(ast, ctx);
|
|
702
|
-
case
|
|
696
|
+
case 8 /* ASTType.TForEach */:
|
|
703
697
|
return this.compileTForeach(ast, ctx);
|
|
704
|
-
case
|
|
698
|
+
case 9 /* ASTType.TKey */:
|
|
705
699
|
return this.compileTKey(ast, ctx);
|
|
706
|
-
case 3 /* Multi */:
|
|
700
|
+
case 3 /* ASTType.Multi */:
|
|
707
701
|
return this.compileMulti(ast, ctx);
|
|
708
|
-
case
|
|
702
|
+
case 6 /* ASTType.TCall */:
|
|
709
703
|
return this.compileTCall(ast, ctx);
|
|
710
|
-
case
|
|
704
|
+
case 14 /* ASTType.TCallBlock */:
|
|
711
705
|
return this.compileTCallBlock(ast, ctx);
|
|
712
|
-
case
|
|
706
|
+
case 5 /* ASTType.TSet */:
|
|
713
707
|
return this.compileTSet(ast, ctx);
|
|
714
|
-
case
|
|
708
|
+
case 10 /* ASTType.TComponent */:
|
|
715
709
|
return this.compileComponent(ast, ctx);
|
|
716
|
-
case
|
|
710
|
+
case 11 /* ASTType.TDebug */:
|
|
717
711
|
return this.compileDebug(ast, ctx);
|
|
718
|
-
case
|
|
712
|
+
case 12 /* ASTType.TLog */:
|
|
719
713
|
return this.compileLog(ast, ctx);
|
|
720
|
-
case
|
|
721
|
-
return this.
|
|
722
|
-
case
|
|
714
|
+
case 13 /* ASTType.TCallSlot */:
|
|
715
|
+
return this.compileTCallSlot(ast, ctx);
|
|
716
|
+
case 15 /* ASTType.TTranslation */:
|
|
723
717
|
return this.compileTTranslation(ast, ctx);
|
|
724
|
-
case
|
|
718
|
+
case 16 /* ASTType.TTranslationContext */:
|
|
725
719
|
return this.compileTTranslationContext(ast, ctx);
|
|
726
|
-
case
|
|
720
|
+
case 17 /* ASTType.TPortal */:
|
|
727
721
|
return this.compileTPortal(ast, ctx);
|
|
728
722
|
}
|
|
729
723
|
}
|
|
@@ -774,7 +768,7 @@ class CodeGenerator {
|
|
|
774
768
|
});
|
|
775
769
|
}
|
|
776
770
|
else {
|
|
777
|
-
const createFn = ast.type === 0 /* Text */ ? xmlDoc.createTextNode : xmlDoc.createComment;
|
|
771
|
+
const createFn = ast.type === 0 /* ASTType.Text */ ? xmlDoc.createTextNode : xmlDoc.createComment;
|
|
778
772
|
block.insert(createFn.call(xmlDoc, value));
|
|
779
773
|
}
|
|
780
774
|
return block.varName;
|
|
@@ -868,14 +862,11 @@ class CodeGenerator {
|
|
|
868
862
|
// t-model
|
|
869
863
|
let tModelSelectedExpr;
|
|
870
864
|
if (ast.model) {
|
|
871
|
-
const { hasDynamicChildren,
|
|
872
|
-
const baseExpression = compileExpr(baseExpr);
|
|
873
|
-
const bExprId = generateId("bExpr");
|
|
874
|
-
this.define(bExprId, baseExpression);
|
|
865
|
+
const { hasDynamicChildren, expr, eventType, shouldNumberize, shouldTrim, targetAttr, specialInitTargetAttr, } = ast.model;
|
|
875
866
|
const expression = compileExpr(expr);
|
|
876
867
|
const exprId = generateId("expr");
|
|
877
|
-
this.
|
|
878
|
-
|
|
868
|
+
this.helpers.add("modelExpr");
|
|
869
|
+
this.define(exprId, `modelExpr(${expression})`);
|
|
879
870
|
let idx;
|
|
880
871
|
if (specialInitTargetAttr) {
|
|
881
872
|
let targetExpr = targetAttr in attrs && `'${attrs[targetAttr]}'`;
|
|
@@ -886,23 +877,23 @@ class CodeGenerator {
|
|
|
886
877
|
targetExpr = compileExpr(dynamicTgExpr);
|
|
887
878
|
}
|
|
888
879
|
}
|
|
889
|
-
idx = block.insertData(`${
|
|
880
|
+
idx = block.insertData(`${exprId}() === ${targetExpr}`, "prop");
|
|
890
881
|
attrs[`block-property-${idx}`] = specialInitTargetAttr;
|
|
891
882
|
}
|
|
892
883
|
else if (hasDynamicChildren) {
|
|
893
884
|
const bValueId = generateId("bValue");
|
|
894
885
|
tModelSelectedExpr = `${bValueId}`;
|
|
895
|
-
this.define(tModelSelectedExpr,
|
|
886
|
+
this.define(tModelSelectedExpr, `${exprId}()`);
|
|
896
887
|
}
|
|
897
888
|
else {
|
|
898
|
-
idx = block.insertData(`${
|
|
889
|
+
idx = block.insertData(`${exprId}()`, "prop");
|
|
899
890
|
attrs[`block-property-${idx}`] = targetAttr;
|
|
900
891
|
}
|
|
901
892
|
this.helpers.add("toNumber");
|
|
902
893
|
let valueCode = `ev.target.${targetAttr}`;
|
|
903
894
|
valueCode = shouldTrim ? `${valueCode}.trim()` : valueCode;
|
|
904
895
|
valueCode = shouldNumberize ? `toNumber(${valueCode})` : valueCode;
|
|
905
|
-
const handler = `[(ev) => { ${
|
|
896
|
+
const handler = `[(ev) => { ${exprId}.set(${valueCode}); }]`;
|
|
906
897
|
idx = block.insertData(handler, "hdlr");
|
|
907
898
|
attrs[`block-handler-${idx}`] = eventType;
|
|
908
899
|
}
|
|
@@ -914,19 +905,9 @@ class CodeGenerator {
|
|
|
914
905
|
}
|
|
915
906
|
// t-ref
|
|
916
907
|
if (ast.ref) {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
}
|
|
921
|
-
const isDynamic = INTERP_REGEXP.test(ast.ref);
|
|
922
|
-
let name = `\`${ast.ref}\``;
|
|
923
|
-
if (isDynamic) {
|
|
924
|
-
name = replaceDynamicParts(ast.ref, (expr) => this.captureExpression(expr, true));
|
|
925
|
-
}
|
|
926
|
-
let setRefStr = `(el) => this.__owl__.setRef((${name}), el)`;
|
|
927
|
-
if (this.dev) {
|
|
928
|
-
setRefStr = `refWrapper(${name}, ${setRefStr})`;
|
|
929
|
-
}
|
|
908
|
+
const refExpr = compileExpr(ast.ref);
|
|
909
|
+
this.helpers.add("createRef");
|
|
910
|
+
const setRefStr = `createRef(${refExpr})`;
|
|
930
911
|
const idx = block.insertData(setRefStr, "ref");
|
|
931
912
|
attrs["block-ref"] = String(idx);
|
|
932
913
|
}
|
|
@@ -980,32 +961,6 @@ class CodeGenerator {
|
|
|
980
961
|
}
|
|
981
962
|
return block.varName;
|
|
982
963
|
}
|
|
983
|
-
compileTEsc(ast, ctx) {
|
|
984
|
-
let { block, forceNewBlock } = ctx;
|
|
985
|
-
let expr;
|
|
986
|
-
if (ast.expr === "0") {
|
|
987
|
-
this.helpers.add("zero");
|
|
988
|
-
expr = `ctx[zero]`;
|
|
989
|
-
}
|
|
990
|
-
else {
|
|
991
|
-
expr = compileExpr(ast.expr);
|
|
992
|
-
if (ast.defaultValue) {
|
|
993
|
-
this.helpers.add("withDefault");
|
|
994
|
-
// FIXME: defaultValue is not translated
|
|
995
|
-
expr = `withDefault(${expr}, ${toStringExpression(ast.defaultValue)})`;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
if (!block || forceNewBlock) {
|
|
999
|
-
block = this.createBlock(block, "text", ctx);
|
|
1000
|
-
this.insertBlock(`text(${expr})`, block, { ...ctx, forceNewBlock: forceNewBlock && !block });
|
|
1001
|
-
}
|
|
1002
|
-
else {
|
|
1003
|
-
const idx = block.insertData(expr, "txt");
|
|
1004
|
-
const text = xmlDoc.createElement(`block-text-${idx}`);
|
|
1005
|
-
block.insert(text);
|
|
1006
|
-
}
|
|
1007
|
-
return block.varName;
|
|
1008
|
-
}
|
|
1009
964
|
compileTOut(ast, ctx) {
|
|
1010
965
|
let { block } = ctx;
|
|
1011
966
|
if (block) {
|
|
@@ -1021,7 +976,7 @@ class CodeGenerator {
|
|
|
1021
976
|
let bodyValue = null;
|
|
1022
977
|
bodyValue = BlockDescription.nextBlockId;
|
|
1023
978
|
const subCtx = createContext(ctx);
|
|
1024
|
-
this.compileAST({ type: 3 /* Multi */, content: ast.body }, subCtx);
|
|
979
|
+
this.compileAST({ type: 3 /* ASTType.Multi */, content: ast.body }, subCtx);
|
|
1025
980
|
this.helpers.add("safeOutput");
|
|
1026
981
|
blockStr = `safeOutput(${compileExpr(ast.expr)}, b${bodyValue})`;
|
|
1027
982
|
}
|
|
@@ -1226,7 +1181,7 @@ class CodeGenerator {
|
|
|
1226
1181
|
let ctxVar = ctx.ctxVar || "ctx";
|
|
1227
1182
|
if (ast.context) {
|
|
1228
1183
|
ctxVar = generateId("ctx");
|
|
1229
|
-
this.addLine(`let ${ctxVar} = ${compileExpr(ast.context)};`);
|
|
1184
|
+
this.addLine(`let ${ctxVar} = {this: ${compileExpr(ast.context)}, __owl__: this.__owl__};`);
|
|
1230
1185
|
}
|
|
1231
1186
|
const isDynamic = INTERP_REGEXP.test(ast.name);
|
|
1232
1187
|
const subTemplate = isDynamic ? interpolate(ast.name) : "`" + ast.name + "`";
|
|
@@ -1239,7 +1194,7 @@ class CodeGenerator {
|
|
|
1239
1194
|
this.addLine(`${ctxVar}[isBoundary] = 1;`);
|
|
1240
1195
|
this.helpers.add("isBoundary");
|
|
1241
1196
|
const subCtx = createContext(ctx, { ctxVar });
|
|
1242
|
-
const bl = this.compileMulti({ type: 3 /* Multi */, content: ast.body }, subCtx);
|
|
1197
|
+
const bl = this.compileMulti({ type: 3 /* ASTType.Multi */, content: ast.body }, subCtx);
|
|
1243
1198
|
if (bl) {
|
|
1244
1199
|
this.helpers.add("zero");
|
|
1245
1200
|
this.addLine(`${ctxVar}[zero] = ${bl};`);
|
|
@@ -1287,7 +1242,7 @@ class CodeGenerator {
|
|
|
1287
1242
|
const expr = ast.value ? compileExpr(ast.value || "") : "null";
|
|
1288
1243
|
if (ast.body) {
|
|
1289
1244
|
this.helpers.add("LazyValue");
|
|
1290
|
-
const bodyAst = { type: 3 /* Multi */, content: ast.body };
|
|
1245
|
+
const bodyAst = { type: 3 /* ASTType.Multi */, content: ast.body };
|
|
1291
1246
|
const name = this.compileInNewTarget("value", bodyAst, ctx);
|
|
1292
1247
|
let key = this.target.currentKey(ctx);
|
|
1293
1248
|
let value = `new LazyValue(${name}, ctx, this, node, ${key})`;
|
|
@@ -1426,9 +1381,6 @@ class CodeGenerator {
|
|
|
1426
1381
|
else {
|
|
1427
1382
|
expr = `\`${ast.name}\``;
|
|
1428
1383
|
}
|
|
1429
|
-
if (this.dev) {
|
|
1430
|
-
this.addLine(`helpers.validateProps(${expr}, ${propVar}, this);`);
|
|
1431
|
-
}
|
|
1432
1384
|
if (block && (ctx.forceNewBlock === false || ctx.tKeyExpr)) {
|
|
1433
1385
|
// todo: check the forcenewblock condition
|
|
1434
1386
|
this.insertAnchor(block);
|
|
@@ -1483,7 +1435,7 @@ class CodeGenerator {
|
|
|
1483
1435
|
this.staticDefs.push({ id: name, expr: `createCatcher(${JSON.stringify(spec)})` });
|
|
1484
1436
|
return `${name}(${expr}, [${handlers.join(",")}])`;
|
|
1485
1437
|
}
|
|
1486
|
-
|
|
1438
|
+
compileTCallSlot(ast, ctx) {
|
|
1487
1439
|
this.helpers.add("callSlot");
|
|
1488
1440
|
let { block } = ctx;
|
|
1489
1441
|
let blockString;
|
|
@@ -1636,7 +1588,7 @@ function parse(xml, customDir) {
|
|
|
1636
1588
|
}
|
|
1637
1589
|
function _parse(xml, ctx) {
|
|
1638
1590
|
normalizeXML(xml);
|
|
1639
|
-
return parseNode(xml, ctx) || { type: 0 /* Text */, value: "" };
|
|
1591
|
+
return parseNode(xml, ctx) || { type: 0 /* ASTType.Text */, value: "" };
|
|
1640
1592
|
}
|
|
1641
1593
|
function parseNode(node, ctx) {
|
|
1642
1594
|
if (!(node instanceof Element)) {
|
|
@@ -1652,9 +1604,8 @@ function parseNode(node, ctx) {
|
|
|
1652
1604
|
parseTTranslation(node, ctx) ||
|
|
1653
1605
|
parseTTranslationContext(node, ctx) ||
|
|
1654
1606
|
parseTKey(node, ctx) ||
|
|
1655
|
-
parseTEscNode(node, ctx) ||
|
|
1656
1607
|
parseTOutNode(node, ctx) ||
|
|
1657
|
-
|
|
1608
|
+
parseTCallSlot(node, ctx) ||
|
|
1658
1609
|
parseComponent(node, ctx) ||
|
|
1659
1610
|
parseDOMNode(node, ctx) ||
|
|
1660
1611
|
parseTSetNode(node, ctx) ||
|
|
@@ -1679,10 +1630,10 @@ function parseTextCommentNode(node, ctx) {
|
|
|
1679
1630
|
if (!ctx.inPreTag && lineBreakRE.test(value) && !value.trim()) {
|
|
1680
1631
|
return null;
|
|
1681
1632
|
}
|
|
1682
|
-
return { type: 0 /* Text */, value };
|
|
1633
|
+
return { type: 0 /* ASTType.Text */, value };
|
|
1683
1634
|
}
|
|
1684
1635
|
else if (node.nodeType === Node.COMMENT_NODE) {
|
|
1685
|
-
return { type: 1 /* Comment */, value: node.textContent || "" };
|
|
1636
|
+
return { type: 1 /* ASTType.Comment */, value: node.textContent || "" };
|
|
1686
1637
|
}
|
|
1687
1638
|
return null;
|
|
1688
1639
|
}
|
|
@@ -1723,7 +1674,7 @@ function parseTDebugLog(node, ctx) {
|
|
|
1723
1674
|
node.removeAttribute("t-debug");
|
|
1724
1675
|
const content = parseNode(node, ctx);
|
|
1725
1676
|
const ast = {
|
|
1726
|
-
type:
|
|
1677
|
+
type: 11 /* ASTType.TDebug */,
|
|
1727
1678
|
content,
|
|
1728
1679
|
};
|
|
1729
1680
|
if (content === null || content === void 0 ? void 0 : content.hasNoRepresentation) {
|
|
@@ -1736,7 +1687,7 @@ function parseTDebugLog(node, ctx) {
|
|
|
1736
1687
|
node.removeAttribute("t-log");
|
|
1737
1688
|
const content = parseNode(node, ctx);
|
|
1738
1689
|
const ast = {
|
|
1739
|
-
type:
|
|
1690
|
+
type: 12 /* ASTType.TLog */,
|
|
1740
1691
|
expr,
|
|
1741
1692
|
content,
|
|
1742
1693
|
};
|
|
@@ -1750,8 +1701,6 @@ function parseTDebugLog(node, ctx) {
|
|
|
1750
1701
|
// -----------------------------------------------------------------------------
|
|
1751
1702
|
// Regular dom node
|
|
1752
1703
|
// -----------------------------------------------------------------------------
|
|
1753
|
-
const hasDotAtTheEnd = /\.[\w_]+\s*$/;
|
|
1754
|
-
const hasBracketsAtTheEnd = /\[[^\[]+\]\s*$/;
|
|
1755
1704
|
const ROOT_SVG_TAGS = new Set(["svg", "g", "path"]);
|
|
1756
1705
|
function parseDOMNode(node, ctx) {
|
|
1757
1706
|
const { tagName } = node;
|
|
@@ -1788,20 +1737,6 @@ function parseDOMNode(node, ctx) {
|
|
|
1788
1737
|
if (!["input", "select", "textarea"].includes(tagName)) {
|
|
1789
1738
|
throw new OwlError("The t-model directive only works with <input>, <textarea> and <select>");
|
|
1790
1739
|
}
|
|
1791
|
-
let baseExpr, expr;
|
|
1792
|
-
if (hasDotAtTheEnd.test(value)) {
|
|
1793
|
-
const index = value.lastIndexOf(".");
|
|
1794
|
-
baseExpr = value.slice(0, index);
|
|
1795
|
-
expr = `'${value.slice(index + 1)}'`;
|
|
1796
|
-
}
|
|
1797
|
-
else if (hasBracketsAtTheEnd.test(value)) {
|
|
1798
|
-
const index = value.lastIndexOf("[");
|
|
1799
|
-
baseExpr = value.slice(0, index);
|
|
1800
|
-
expr = value.slice(index + 1, -1);
|
|
1801
|
-
}
|
|
1802
|
-
else {
|
|
1803
|
-
throw new OwlError(`Invalid t-model expression: "${value}" (it should be assignable)`);
|
|
1804
|
-
}
|
|
1805
1740
|
const typeAttr = node.getAttribute("type");
|
|
1806
1741
|
const isInput = tagName === "input";
|
|
1807
1742
|
const isSelect = tagName === "select";
|
|
@@ -1812,8 +1747,7 @@ function parseDOMNode(node, ctx) {
|
|
|
1812
1747
|
const hasNumberMod = attr.includes(".number");
|
|
1813
1748
|
const eventType = isRadioInput ? "click" : isSelect || hasLazyMod ? "change" : "input";
|
|
1814
1749
|
model = {
|
|
1815
|
-
|
|
1816
|
-
expr,
|
|
1750
|
+
expr: value,
|
|
1817
1751
|
targetAttr: isCheckboxInput ? "checked" : "value",
|
|
1818
1752
|
specialInitTargetAttr: isRadioInput ? "checked" : null,
|
|
1819
1753
|
eventType,
|
|
@@ -1855,7 +1789,7 @@ function parseDOMNode(node, ctx) {
|
|
|
1855
1789
|
}
|
|
1856
1790
|
const children = parseChildren(node, ctx);
|
|
1857
1791
|
return {
|
|
1858
|
-
type: 2 /* DomNode */,
|
|
1792
|
+
type: 2 /* ASTType.DomNode */,
|
|
1859
1793
|
tag: tagName,
|
|
1860
1794
|
dynamicTag,
|
|
1861
1795
|
attrs,
|
|
@@ -1868,55 +1802,26 @@ function parseDOMNode(node, ctx) {
|
|
|
1868
1802
|
};
|
|
1869
1803
|
}
|
|
1870
1804
|
// -----------------------------------------------------------------------------
|
|
1871
|
-
// t-esc
|
|
1872
|
-
// -----------------------------------------------------------------------------
|
|
1873
|
-
function parseTEscNode(node, ctx) {
|
|
1874
|
-
if (!node.hasAttribute("t-esc")) {
|
|
1875
|
-
return null;
|
|
1876
|
-
}
|
|
1877
|
-
const escValue = node.getAttribute("t-esc");
|
|
1878
|
-
node.removeAttribute("t-esc");
|
|
1879
|
-
const tesc = {
|
|
1880
|
-
type: 4 /* TEsc */,
|
|
1881
|
-
expr: escValue,
|
|
1882
|
-
defaultValue: node.textContent || "",
|
|
1883
|
-
};
|
|
1884
|
-
let ref = node.getAttribute("t-ref");
|
|
1885
|
-
node.removeAttribute("t-ref");
|
|
1886
|
-
const ast = parseNode(node, ctx);
|
|
1887
|
-
if (!ast) {
|
|
1888
|
-
return tesc;
|
|
1889
|
-
}
|
|
1890
|
-
if (ast.type === 2 /* DomNode */) {
|
|
1891
|
-
return {
|
|
1892
|
-
...ast,
|
|
1893
|
-
ref,
|
|
1894
|
-
content: [tesc],
|
|
1895
|
-
};
|
|
1896
|
-
}
|
|
1897
|
-
return tesc;
|
|
1898
|
-
}
|
|
1899
|
-
// -----------------------------------------------------------------------------
|
|
1900
1805
|
// t-out
|
|
1901
1806
|
// -----------------------------------------------------------------------------
|
|
1902
1807
|
function parseTOutNode(node, ctx) {
|
|
1903
|
-
if (!node.hasAttribute("t-out") && !node.hasAttribute("t-
|
|
1808
|
+
if (!node.hasAttribute("t-out") && !node.hasAttribute("t-esc")) {
|
|
1904
1809
|
return null;
|
|
1905
1810
|
}
|
|
1906
|
-
if (node.hasAttribute("t-
|
|
1907
|
-
console.warn(`t-
|
|
1811
|
+
if (node.hasAttribute("t-esc")) {
|
|
1812
|
+
console.warn(`t-esc has been deprecated in favor of t-out. If the value to render is not wrapped by the "markup" function, it will be escaped`);
|
|
1908
1813
|
}
|
|
1909
|
-
const expr = (node.getAttribute("t-out") || node.getAttribute("t-
|
|
1814
|
+
const expr = (node.getAttribute("t-out") || node.getAttribute("t-esc"));
|
|
1910
1815
|
node.removeAttribute("t-out");
|
|
1911
|
-
node.removeAttribute("t-
|
|
1912
|
-
const tOut = { type:
|
|
1816
|
+
node.removeAttribute("t-esc");
|
|
1817
|
+
const tOut = { type: 7 /* ASTType.TOut */, expr, body: null };
|
|
1913
1818
|
const ref = node.getAttribute("t-ref");
|
|
1914
1819
|
node.removeAttribute("t-ref");
|
|
1915
1820
|
const ast = parseNode(node, ctx);
|
|
1916
1821
|
if (!ast) {
|
|
1917
1822
|
return tOut;
|
|
1918
1823
|
}
|
|
1919
|
-
if (ast.type === 2 /* DomNode */) {
|
|
1824
|
+
if (ast.type === 2 /* ASTType.DomNode */) {
|
|
1920
1825
|
tOut.body = ast.content.length ? ast.content : null;
|
|
1921
1826
|
return {
|
|
1922
1827
|
...ast,
|
|
@@ -1955,7 +1860,7 @@ function parseTForEach(node, ctx) {
|
|
|
1955
1860
|
const hasNoIndex = hasNoTCall && !html.includes(`${elem}_index`);
|
|
1956
1861
|
const hasNoValue = hasNoTCall && !html.includes(`${elem}_value`);
|
|
1957
1862
|
return {
|
|
1958
|
-
type:
|
|
1863
|
+
type: 8 /* ASTType.TForEach */,
|
|
1959
1864
|
collection,
|
|
1960
1865
|
elem,
|
|
1961
1866
|
body,
|
|
@@ -1978,7 +1883,7 @@ function parseTKey(node, ctx) {
|
|
|
1978
1883
|
return null;
|
|
1979
1884
|
}
|
|
1980
1885
|
const ast = {
|
|
1981
|
-
type:
|
|
1886
|
+
type: 9 /* ASTType.TKey */,
|
|
1982
1887
|
expr: key,
|
|
1983
1888
|
content,
|
|
1984
1889
|
};
|
|
@@ -2000,12 +1905,12 @@ function parseTCall(node, ctx) {
|
|
|
2000
1905
|
node.removeAttribute("t-call-context");
|
|
2001
1906
|
if (node.tagName !== "t") {
|
|
2002
1907
|
const ast = parseNode(node, ctx);
|
|
2003
|
-
const tcall = { type:
|
|
2004
|
-
if (ast && ast.type === 2 /* DomNode */) {
|
|
1908
|
+
const tcall = { type: 6 /* ASTType.TCall */, name: subTemplate, body: null, context };
|
|
1909
|
+
if (ast && ast.type === 2 /* ASTType.DomNode */) {
|
|
2005
1910
|
ast.content = [tcall];
|
|
2006
1911
|
return ast;
|
|
2007
1912
|
}
|
|
2008
|
-
if (ast && ast.type ===
|
|
1913
|
+
if (ast && ast.type === 10 /* ASTType.TComponent */) {
|
|
2009
1914
|
return {
|
|
2010
1915
|
...ast,
|
|
2011
1916
|
slots: {
|
|
@@ -2022,7 +1927,7 @@ function parseTCall(node, ctx) {
|
|
|
2022
1927
|
}
|
|
2023
1928
|
const body = parseChildren(node, ctx);
|
|
2024
1929
|
return {
|
|
2025
|
-
type:
|
|
1930
|
+
type: 6 /* ASTType.TCall */,
|
|
2026
1931
|
name: subTemplate,
|
|
2027
1932
|
body: body.length ? body : null,
|
|
2028
1933
|
context,
|
|
@@ -2037,7 +1942,7 @@ function parseTCallBlock(node, ctx) {
|
|
|
2037
1942
|
}
|
|
2038
1943
|
const name = node.getAttribute("t-call-block");
|
|
2039
1944
|
return {
|
|
2040
|
-
type:
|
|
1945
|
+
type: 14 /* ASTType.TCallBlock */,
|
|
2041
1946
|
name,
|
|
2042
1947
|
};
|
|
2043
1948
|
}
|
|
@@ -2050,7 +1955,7 @@ function parseTIf(node, ctx) {
|
|
|
2050
1955
|
}
|
|
2051
1956
|
const condition = node.getAttribute("t-if");
|
|
2052
1957
|
node.removeAttribute("t-if");
|
|
2053
|
-
const content = parseNode(node, ctx) || { type: 0 /* Text */, value: "" };
|
|
1958
|
+
const content = parseNode(node, ctx) || { type: 0 /* ASTType.Text */, value: "" };
|
|
2054
1959
|
let nextElement = node.nextElementSibling;
|
|
2055
1960
|
// t-elifs
|
|
2056
1961
|
const tElifs = [];
|
|
@@ -2073,7 +1978,7 @@ function parseTIf(node, ctx) {
|
|
|
2073
1978
|
nextElement.remove();
|
|
2074
1979
|
}
|
|
2075
1980
|
return {
|
|
2076
|
-
type:
|
|
1981
|
+
type: 4 /* ASTType.TIf */,
|
|
2077
1982
|
condition,
|
|
2078
1983
|
content,
|
|
2079
1984
|
tElif: tElifs.length ? tElifs : null,
|
|
@@ -2094,7 +1999,7 @@ function parseTSetNode(node, ctx) {
|
|
|
2094
1999
|
if (node.textContent !== node.innerHTML) {
|
|
2095
2000
|
body = parseChildren(node, ctx);
|
|
2096
2001
|
}
|
|
2097
|
-
return { type:
|
|
2002
|
+
return { type: 5 /* ASTType.TSet */, name, value, defaultValue, body, hasNoRepresentation: true };
|
|
2098
2003
|
}
|
|
2099
2004
|
// -----------------------------------------------------------------------------
|
|
2100
2005
|
// Components
|
|
@@ -2223,7 +2128,7 @@ function parseComponent(node, ctx) {
|
|
|
2223
2128
|
}
|
|
2224
2129
|
}
|
|
2225
2130
|
return {
|
|
2226
|
-
type:
|
|
2131
|
+
type: 10 /* ASTType.TComponent */,
|
|
2227
2132
|
name,
|
|
2228
2133
|
isDynamic,
|
|
2229
2134
|
dynamicProps,
|
|
@@ -2236,12 +2141,12 @@ function parseComponent(node, ctx) {
|
|
|
2236
2141
|
// -----------------------------------------------------------------------------
|
|
2237
2142
|
// Slots
|
|
2238
2143
|
// -----------------------------------------------------------------------------
|
|
2239
|
-
function
|
|
2240
|
-
if (!node.hasAttribute("t-slot")) {
|
|
2144
|
+
function parseTCallSlot(node, ctx) {
|
|
2145
|
+
if (!node.hasAttribute("t-call-slot")) {
|
|
2241
2146
|
return null;
|
|
2242
2147
|
}
|
|
2243
|
-
const name = node.getAttribute("t-slot");
|
|
2244
|
-
node.removeAttribute("t-slot");
|
|
2148
|
+
const name = node.getAttribute("t-call-slot");
|
|
2149
|
+
node.removeAttribute("t-call-slot");
|
|
2245
2150
|
let attrs = null;
|
|
2246
2151
|
let attrsTranslationCtx = null;
|
|
2247
2152
|
let on = null;
|
|
@@ -2262,7 +2167,7 @@ function parseTSlot(node, ctx) {
|
|
|
2262
2167
|
}
|
|
2263
2168
|
}
|
|
2264
2169
|
return {
|
|
2265
|
-
type:
|
|
2170
|
+
type: 13 /* ASTType.TCallSlot */,
|
|
2266
2171
|
name,
|
|
2267
2172
|
attrs,
|
|
2268
2173
|
attrsTranslationCtx,
|
|
@@ -2274,7 +2179,7 @@ function parseTSlot(node, ctx) {
|
|
|
2274
2179
|
// Translation
|
|
2275
2180
|
// -----------------------------------------------------------------------------
|
|
2276
2181
|
function wrapInTTranslationAST(r) {
|
|
2277
|
-
const ast = { type:
|
|
2182
|
+
const ast = { type: 15 /* ASTType.TTranslation */, content: r };
|
|
2278
2183
|
if (r === null || r === void 0 ? void 0 : r.hasNoRepresentation) {
|
|
2279
2184
|
ast.hasNoRepresentation = true;
|
|
2280
2185
|
}
|
|
@@ -2286,7 +2191,7 @@ function parseTTranslation(node, ctx) {
|
|
|
2286
2191
|
}
|
|
2287
2192
|
node.removeAttribute("t-translation");
|
|
2288
2193
|
const result = parseNode(node, ctx);
|
|
2289
|
-
if ((result === null || result === void 0 ? void 0 : result.type) === 3 /* Multi */) {
|
|
2194
|
+
if ((result === null || result === void 0 ? void 0 : result.type) === 3 /* ASTType.Multi */) {
|
|
2290
2195
|
const children = result.content.map(wrapInTTranslationAST);
|
|
2291
2196
|
return makeASTMulti(children);
|
|
2292
2197
|
}
|
|
@@ -2297,7 +2202,7 @@ function parseTTranslation(node, ctx) {
|
|
|
2297
2202
|
// -----------------------------------------------------------------------------
|
|
2298
2203
|
function wrapInTTranslationContextAST(r, translationCtx) {
|
|
2299
2204
|
const ast = {
|
|
2300
|
-
type:
|
|
2205
|
+
type: 16 /* ASTType.TTranslationContext */,
|
|
2301
2206
|
content: r,
|
|
2302
2207
|
translationCtx,
|
|
2303
2208
|
};
|
|
@@ -2313,7 +2218,7 @@ function parseTTranslationContext(node, ctx) {
|
|
|
2313
2218
|
}
|
|
2314
2219
|
node.removeAttribute("t-translation-context");
|
|
2315
2220
|
const result = parseNode(node, ctx);
|
|
2316
|
-
if ((result === null || result === void 0 ? void 0 : result.type) === 3 /* Multi */) {
|
|
2221
|
+
if ((result === null || result === void 0 ? void 0 : result.type) === 3 /* ASTType.Multi */) {
|
|
2317
2222
|
const children = result.content.map((c) => wrapInTTranslationContextAST(c, translationCtx));
|
|
2318
2223
|
return makeASTMulti(children);
|
|
2319
2224
|
}
|
|
@@ -2331,12 +2236,12 @@ function parseTPortal(node, ctx) {
|
|
|
2331
2236
|
const content = parseNode(node, ctx);
|
|
2332
2237
|
if (!content) {
|
|
2333
2238
|
return {
|
|
2334
|
-
type: 0 /* Text */,
|
|
2239
|
+
type: 0 /* ASTType.Text */,
|
|
2335
2240
|
value: "",
|
|
2336
2241
|
};
|
|
2337
2242
|
}
|
|
2338
2243
|
return {
|
|
2339
|
-
type:
|
|
2244
|
+
type: 17 /* ASTType.TPortal */,
|
|
2340
2245
|
target,
|
|
2341
2246
|
content,
|
|
2342
2247
|
};
|
|
@@ -2352,7 +2257,7 @@ function parseChildren(node, ctx) {
|
|
|
2352
2257
|
for (let child of node.childNodes) {
|
|
2353
2258
|
const childAst = parseNode(child, ctx);
|
|
2354
2259
|
if (childAst) {
|
|
2355
|
-
if (childAst.type === 3 /* Multi */) {
|
|
2260
|
+
if (childAst.type === 3 /* ASTType.Multi */) {
|
|
2356
2261
|
children.push(...childAst.content);
|
|
2357
2262
|
}
|
|
2358
2263
|
else {
|
|
@@ -2363,7 +2268,7 @@ function parseChildren(node, ctx) {
|
|
|
2363
2268
|
return children;
|
|
2364
2269
|
}
|
|
2365
2270
|
function makeASTMulti(children) {
|
|
2366
|
-
const ast = { type: 3 /* Multi */, content: children };
|
|
2271
|
+
const ast = { type: 3 /* ASTType.Multi */, content: children };
|
|
2367
2272
|
if (children.every((c) => c.hasNoRepresentation)) {
|
|
2368
2273
|
ast.hasNoRepresentation = true;
|
|
2369
2274
|
}
|
|
@@ -2424,28 +2329,26 @@ function normalizeTIf(el) {
|
|
|
2424
2329
|
}
|
|
2425
2330
|
}
|
|
2426
2331
|
/**
|
|
2427
|
-
* Normalizes the content of an Element so that t-
|
|
2428
|
-
* are removed and instead places a <t t-
|
|
2332
|
+
* Normalizes the content of an Element so that t-out directives on components
|
|
2333
|
+
* are removed and instead places a <t t-out=""> as the default slot of the
|
|
2429
2334
|
* component. Also throws if the component already has content. This function
|
|
2430
2335
|
* modifies the Element in place.
|
|
2431
2336
|
*
|
|
2432
2337
|
* @param el the element containing the tree that should be normalized
|
|
2433
2338
|
*/
|
|
2434
|
-
function
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
t.setAttribute(d, value);
|
|
2446
|
-
}
|
|
2447
|
-
el.appendChild(t);
|
|
2339
|
+
function normalizeTOut(el) {
|
|
2340
|
+
const elements = [...el.querySelectorAll(`[t-out]`)].filter((el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component"));
|
|
2341
|
+
for (const el of elements) {
|
|
2342
|
+
if (el.childNodes.length) {
|
|
2343
|
+
throw new OwlError(`Cannot have t-out on a component that already has content`);
|
|
2344
|
+
}
|
|
2345
|
+
const value = el.getAttribute("t-out");
|
|
2346
|
+
el.removeAttribute("t-out");
|
|
2347
|
+
const t = el.ownerDocument.createElement("t");
|
|
2348
|
+
if (value != null) {
|
|
2349
|
+
t.setAttribute("t-out", value);
|
|
2448
2350
|
}
|
|
2351
|
+
el.appendChild(t);
|
|
2449
2352
|
}
|
|
2450
2353
|
}
|
|
2451
2354
|
/**
|
|
@@ -2456,7 +2359,7 @@ function normalizeTEscTOut(el) {
|
|
|
2456
2359
|
*/
|
|
2457
2360
|
function normalizeXML(el) {
|
|
2458
2361
|
normalizeTIf(el);
|
|
2459
|
-
|
|
2362
|
+
normalizeTOut(el);
|
|
2460
2363
|
}
|
|
2461
2364
|
|
|
2462
2365
|
function compile(template, options = {
|
|
@@ -2467,7 +2370,7 @@ function compile(template, options = {
|
|
|
2467
2370
|
// some work
|
|
2468
2371
|
const hasSafeContext = template instanceof Node
|
|
2469
2372
|
? !(template instanceof Element) || template.querySelector("[t-set], [t-call]") === null
|
|
2470
|
-
: !template.includes("t-set") && !template.includes("t-call");
|
|
2373
|
+
: !template.includes("t-set=") && !template.includes("t-call=");
|
|
2471
2374
|
// code generation
|
|
2472
2375
|
const codeGenerator = new CodeGenerator(ast, { ...options, hasSafeContext });
|
|
2473
2376
|
const code = codeGenerator.generateCode();
|