Skip to content

Commit

Permalink
🐞 fix: flyout can not display
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Mar 17, 2024
1 parent 40676ee commit 013bcf9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/chili-ui/src/viewport/viewport.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license.

import { IView } from "chili-core";
import { IView, PubSub } from "chili-core";
import { Flyout } from "../components";

export class Viewport extends HTMLElement {
private _flyout?: Flyout;
private _flyout: Flyout;
private readonly _eventCaches: [keyof HTMLElementEventMap, (e: any) => void][] = [];

constructor(readonly view: IView) {
super();
this.initEvent();
this._flyout = new Flyout();
view.onPropertyChanged(this._onViewClosed);
this.addEventListener("mousemove", this._handleFlyoutMove);
PubSub.default.sub("activeViewChanged", this._onActiveViewChanged);
}

setActive(actived: boolean) {
this._flyout?.remove();
this._flyout = undefined;

if (actived) {
this._flyout = new Flyout();
private _onActiveViewChanged = (view: IView | undefined) => {
if (view === this.view) {
document.body.appendChild(this._flyout);
} else {
this._flyout.remove();
}
}
};

private _handleFlyoutMove(e: MouseEvent) {
if (this._flyout) {
Expand All @@ -40,6 +40,8 @@ export class Viewport extends HTMLElement {

dispose() {
this.removeEvents();
this.removeEventListener("mousemove", this._handleFlyoutMove);
PubSub.default.remove("activeViewChanged", this._onActiveViewChanged);
}

private initEvent() {
Expand Down

0 comments on commit 013bcf9

Please sign in to comment.