[IMP] portal: compile t-portal in an internal Component Portal

This commit also clean-up the deepRemove for the Portal that is not
needed any more.
This commit is contained in:
Jorge Pinna Puissant
2022-01-17 15:40:43 +01:00
committed by Aaron Bohy
parent 42a140a8e3
commit 41ad5db2e3
11 changed files with 496 additions and 240 deletions
+26 -1
View File
@@ -1,8 +1,11 @@
import { onWillUnmount } from ".";
import { xml } from "./app/template_set";
import { BDom, text, VNode } from "./blockdom";
import { Component } from "./component/component";
const VText: any = text("").constructor;
export class VPortal extends VText implements Partial<VNode<VPortal>> {
class VPortal extends VText implements Partial<VNode<VPortal>> {
// selector: string;
realBDom: BDom | null;
target: HTMLElement | null = null;
@@ -47,3 +50,25 @@ export class VPortal extends VText implements Partial<VNode<VPortal>> {
}
}
}
export class Portal extends Component {
static template = xml`<t t-slot="default"/>`;
static props = {
target: {
type: String,
},
slots: true,
};
setup() {
const node = this.__owl__;
const renderFn = node.renderFn;
node.renderFn = () => new VPortal(this.props.target, renderFn());
onWillUnmount(async () => {
await Promise.resolve();
if (node.bdom && (node.bdom as any).realBDom) {
(node.bdom as any).realBDom.remove();
}
});
}
}