From 23b1edb0033941fb9bdd57b1104ae97993a22e1c Mon Sep 17 00:00:00 2001 From: sachnk <5503945+sachnk@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:02:53 +0000 Subject: [PATCH] add window-lifecycle callbacks --- packages/dockview-core/src/api/component.api.ts | 2 ++ .../dockview-core/src/dockview/dockviewComponent.ts | 6 ++++++ .../src/dockview/dockviewPopoutGroupPanel.ts | 4 ++++ packages/dockview-core/src/popoutWindow.ts | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/packages/dockview-core/src/api/component.api.ts b/packages/dockview-core/src/api/component.api.ts index d4a8aae02..02f4292a7 100644 --- a/packages/dockview-core/src/api/component.api.ts +++ b/packages/dockview-core/src/api/component.api.ts @@ -830,6 +830,8 @@ export class DockviewApi implements CommonApi { options?: { position?: Box; popoutUrl?: string; + onOpened?: (id: string, window: Window) => void; + onClosing?: (id: string, window: Window) => void; } ): void { this.component.addPopoutGroup(item, options); diff --git a/packages/dockview-core/src/dockview/dockviewComponent.ts b/packages/dockview-core/src/dockview/dockviewComponent.ts index 82e5283a4..0080c93a3 100644 --- a/packages/dockview-core/src/dockview/dockviewComponent.ts +++ b/packages/dockview-core/src/dockview/dockviewComponent.ts @@ -286,6 +286,8 @@ export interface IDockviewComponent extends IBaseGrid { options?: { position?: Box; popoutUrl?: string; + onOpened?: (id: string, window: Window) => void; + onClosing?: (id: string, window: Window) => void; } ): void; } @@ -513,6 +515,8 @@ export class DockviewComponent skipRemoveGroup?: boolean; position?: Box; popoutUrl?: string; + onOpened?: (id: string, window: Window) => void; + onClosing?: (id: string, window: Window) => void; } ): void { let group: DockviewGroupPanel; @@ -561,6 +565,8 @@ export class DockviewComponent width: box.width, height: box.height, }, + onOpened: options?.onOpened, + onClosing: options?.onClosing } ); diff --git a/packages/dockview-core/src/dockview/dockviewPopoutGroupPanel.ts b/packages/dockview-core/src/dockview/dockviewPopoutGroupPanel.ts index 803fa5411..6d8e7d1b0 100644 --- a/packages/dockview-core/src/dockview/dockviewPopoutGroupPanel.ts +++ b/packages/dockview-core/src/dockview/dockviewPopoutGroupPanel.ts @@ -13,6 +13,8 @@ export class DockviewPopoutGroupPanel extends CompositeDisposable { className: string; popoutUrl: string; box: Box; + onOpened?: (id: string, window: Window) => void; + onClosing?: (id: string, window: Window) => void; } ) { super(); @@ -23,6 +25,8 @@ export class DockviewPopoutGroupPanel extends CompositeDisposable { top: this.options.box.top, width: this.options.box.width, height: this.options.box.height, + onOpened: this.options.onOpened, + onClosing: this.options.onClosing, }); group.model.location = 'popout'; diff --git a/packages/dockview-core/src/popoutWindow.ts b/packages/dockview-core/src/popoutWindow.ts index c73334549..1e26e4257 100644 --- a/packages/dockview-core/src/popoutWindow.ts +++ b/packages/dockview-core/src/popoutWindow.ts @@ -5,6 +5,8 @@ import { Box } from './types'; export type PopoutWindowOptions = { url: string; + onOpened?: (id: string, window: Window) => void; + onClosing?: (id: string, window: Window) => void; } & Box; export class PopoutWindow extends CompositeDisposable { @@ -42,6 +44,10 @@ export class PopoutWindow extends CompositeDisposable { close(): void { if (this._window) { + if (this.options.onClosing) { + this.options.onClosing(this.id, this._window.value); + } + this._window.disposable.dispose(); this._window.value.close(); this._window = null; @@ -114,5 +120,9 @@ export class PopoutWindow extends CompositeDisposable { cleanUp(); }); }); + + if (this.options.onOpened) { + this.options.onOpened(this.id, externalWindow); + } } }