From 6274708acb8981dce02da39c16f4545676348c6d Mon Sep 17 00:00:00 2001 From: mathuo <6710312+mathuo@users.noreply.github.com> Date: Sun, 28 Jan 2024 13:43:09 +0000 Subject: [PATCH] feat: align event names --- packages/dockview-core/src/api/component.api.ts | 4 ++-- .../src/dockview/dockviewComponent.ts | 12 ++++++------ .../src/dockview/dockviewPopoutGroupPanel.ts | 8 ++++---- packages/dockview-core/src/popoutWindow.ts | 15 +++++++-------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/dockview-core/src/api/component.api.ts b/packages/dockview-core/src/api/component.api.ts index 02f4292a7..f57fa9fa4 100644 --- a/packages/dockview-core/src/api/component.api.ts +++ b/packages/dockview-core/src/api/component.api.ts @@ -830,8 +830,8 @@ export class DockviewApi implements CommonApi { options?: { position?: Box; popoutUrl?: string; - onOpened?: (id: string, window: Window) => void; - onClosing?: (id: string, window: Window) => void; + onDidOpen?: (event: { id: string; window: Window }) => void; + onWillClose?: (event: { 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 b28dde011..e808bdb79 100644 --- a/packages/dockview-core/src/dockview/dockviewComponent.ts +++ b/packages/dockview-core/src/dockview/dockviewComponent.ts @@ -287,8 +287,8 @@ export interface IDockviewComponent extends IBaseGrid { options?: { position?: Box; popoutUrl?: string; - onOpened?: (id: string, window: Window) => void; - onClosing?: (id: string, window: Window) => void; + onDidOpen?: (event: { id: string; window: Window }) => void; + onWillClose?: (event: { id: string; window: Window }) => void; } ): void; } @@ -516,8 +516,8 @@ export class DockviewComponent skipRemoveGroup?: boolean; position?: Box; popoutUrl?: string; - onOpened?: (id: string, window: Window) => void; - onClosing?: (id: string, window: Window) => void; + onDidOpen?: (event: { id: string; window: Window }) => void; + onWillClose?: (event: { id: string; window: Window }) => void; } ): void { let group: DockviewGroupPanel; @@ -566,8 +566,8 @@ export class DockviewComponent width: box.width, height: box.height, }, - onOpened: options?.onOpened, - onClosing: options?.onClosing + onDidOpen: options?.onDidOpen, + onWillClose: options?.onWillClose, } ); diff --git a/packages/dockview-core/src/dockview/dockviewPopoutGroupPanel.ts b/packages/dockview-core/src/dockview/dockviewPopoutGroupPanel.ts index 371fda793..858178280 100644 --- a/packages/dockview-core/src/dockview/dockviewPopoutGroupPanel.ts +++ b/packages/dockview-core/src/dockview/dockviewPopoutGroupPanel.ts @@ -13,8 +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; + onDidOpen?: (event: { id: string; window: Window }) => void; + onWillClose?: (event: { id: string; window: Window }) => void; } ) { super(); @@ -25,8 +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, + onDidOpen: this.options.onDidOpen, + onWillClose: this.options.onWillClose, }); group.model.location = { diff --git a/packages/dockview-core/src/popoutWindow.ts b/packages/dockview-core/src/popoutWindow.ts index 68dfc6736..3f1531cac 100644 --- a/packages/dockview-core/src/popoutWindow.ts +++ b/packages/dockview-core/src/popoutWindow.ts @@ -5,8 +5,8 @@ import { Box } from './types'; export type PopoutWindowOptions = { url: string; - onOpened?: (id: string, window: Window) => void; - onClosing?: (id: string, window: Window) => void; + onDidOpen?: (event: { id: string; window: Window }) => void; + onWillClose?: (event: { id: string; window: Window }) => void; } & Box; export class PopoutWindow extends CompositeDisposable { @@ -53,9 +53,10 @@ export class PopoutWindow extends CompositeDisposable { if (this._window) { this._onWillClose.fire(); - if (this.options.onClosing) { - this.options.onClosing(this.target, this._window.value); - } + this.options.onWillClose?.({ + id: this.target, + window: this._window.value, + }); this._window.disposable.dispose(); this._window.value.close(); @@ -132,9 +133,7 @@ export class PopoutWindow extends CompositeDisposable { }); }); - if (this.options.onOpened) { - this.options.onOpened(this.target, externalWindow); - } + this.options.onDidOpen?.({ id: this.target, window: externalWindow }); } private createPopoutWindowContainer(): HTMLElement {