[FIX] slots: allow t-call and components in slot default content

This commit is contained in:
Samuel Degueldre
2021-11-24 14:13:09 +01:00
committed by Aaron Bohy
parent 5d8141a67c
commit 3f66d9fe6c
4 changed files with 133 additions and 23 deletions
+3 -3
View File
@@ -19,7 +19,7 @@ function callSlot(
name: string,
dynamic: boolean,
extra: any,
defaultSlot?: (ctx: any, key: string) => BDom
defaultContent?: (ctx: any, node: any, key: string) => BDom
): BDom {
const slots = (ctx.props && ctx.props.slots) || {};
const { __render, __ctx, __scope } = slots[name] || {};
@@ -28,13 +28,13 @@ function callSlot(
slotScope[__scope] = extra || {};
}
const slotBDom = __render ? __render(slotScope, parent, key) : null;
if (defaultSlot) {
if (defaultContent) {
let child1: BDom | undefined = undefined;
let child2: BDom | undefined = undefined;
if (slotBDom) {
child1 = dynamic ? toggler(name, slotBDom) : slotBDom;
} else {
child2 = defaultSlot(parent, key);
child2 = defaultContent(ctx, parent, key);
}
return multi([child1, child2]);
}
+2 -2
View File
@@ -1095,9 +1095,9 @@ export class CodeGenerator {
}
if (ast.defaultContent) {
let name = this.generateId("defaultSlot");
let name = this.generateId("defaultContent");
const slot = new CodeTarget(name);
slot.signature = "ctx => {";
slot.signature = "(ctx, node, key) => {";
this.functions.push(slot);
const initialTarget = this.target;
const subCtx: Context = createContext(ctx);