Merge pull request #566 from mathuo/564-add-groupdata-fields-to-onwillshowoverlays-event

feat: enhance onWillShowOverlay event
This commit is contained in:
mathuo 2024-04-14 15:37:37 +01:00 committed by GitHub
commit da0270066b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 47 additions and 10 deletions

View File

@ -15,6 +15,7 @@ import {
DockviewGroupDropLocation, DockviewGroupDropLocation,
WillShowOverlayLocationEvent, WillShowOverlayLocationEvent,
} from '../../dockviewGroupPanelModel'; } from '../../dockviewGroupPanelModel';
import { getPanelData } from '../../../dnd/dataTransfer';
export interface TabDropIndexEvent { export interface TabDropIndexEvent {
readonly event: DragEvent; readonly event: DragEvent;
@ -247,6 +248,10 @@ export class TabsContainer
this._onWillShowOverlay.fire( this._onWillShowOverlay.fire(
new WillShowOverlayLocationEvent(event, { new WillShowOverlayLocationEvent(event, {
kind: 'header_space', kind: 'header_space',
panel: this.group.activePanel,
api: this.accessor.api,
group: this.group,
getData: getPanelData,
}) })
); );
}), }),
@ -408,7 +413,13 @@ export class TabsContainer
}), }),
tab.onWillShowOverlay((event) => { tab.onWillShowOverlay((event) => {
this._onWillShowOverlay.fire( this._onWillShowOverlay.fire(
new WillShowOverlayLocationEvent(event, { kind: 'tab' }) new WillShowOverlayLocationEvent(event, {
kind: 'tab',
panel: this.group.activePanel,
api: this.accessor.api,
group: this.group,
getData: getPanelData,
})
); );
}) })
); );

View File

@ -429,6 +429,10 @@ export class DockviewComponent
return this.options.defaultRenderer ?? 'onlyWhenVisible'; return this.options.defaultRenderer ?? 'onlyWhenVisible';
} }
get api(): DockviewApi {
return this._api;
}
constructor(options: DockviewComponentOptions) { constructor(options: DockviewComponentOptions) {
super({ super({
proportionalLayout: true, proportionalLayout: true,
@ -579,6 +583,10 @@ export class DockviewComponent
this._onWillShowOverlay.fire( this._onWillShowOverlay.fire(
new WillShowOverlayLocationEvent(event, { new WillShowOverlayLocationEvent(event, {
kind: 'edge', kind: 'edge',
panel: undefined,
api: this._api,
group: undefined,
getData: getPanelData,
}) })
); );
}), }),

View File

@ -190,13 +190,9 @@ export type DockviewGroupLocation =
| { type: 'floating' } | { type: 'floating' }
| { type: 'popout'; getWindow: () => Window }; | { type: 'popout'; getWindow: () => Window };
type A = typeof WillShowOverlayEvent;
export class WillShowOverlayLocationEvent implements IDockviewEvent { export class WillShowOverlayLocationEvent implements IDockviewEvent {
private _kind: DockviewGroupDropLocation;
get kind(): DockviewGroupDropLocation { get kind(): DockviewGroupDropLocation {
return this._kind; return this.options.kind;
} }
get nativeEvent(): DragEvent { get nativeEvent(): DragEvent {
@ -211,18 +207,36 @@ export class WillShowOverlayLocationEvent implements IDockviewEvent {
return this.event.defaultPrevented; return this.event.defaultPrevented;
} }
get panel(): IDockviewPanel | undefined {
return this.options.panel;
}
get api(): DockviewApi {
return this.options.api;
}
get group(): DockviewGroupPanel | undefined {
return this.options.group;
}
preventDefault(): void { preventDefault(): void {
this.event.preventDefault(); this.event.preventDefault();
} }
getData(): PanelTransfer | undefined {
return this.options.getData();
}
constructor( constructor(
private readonly event: WillShowOverlayEvent, private readonly event: WillShowOverlayEvent,
options: { private readonly options: {
kind: DockviewGroupDropLocation; kind: DockviewGroupDropLocation;
panel: IDockviewPanel | undefined;
api: DockviewApi;
group: DockviewGroupPanel | undefined;
getData: () => PanelTransfer | undefined;
} }
) { ) {}
this._kind = options.kind;
}
} }
export class DockviewGroupPanelModel export class DockviewGroupPanelModel
@ -464,6 +478,10 @@ export class DockviewGroupPanelModel
this._onWillShowOverlay.fire( this._onWillShowOverlay.fire(
new WillShowOverlayLocationEvent(event, { new WillShowOverlayLocationEvent(event, {
kind: 'content', kind: 'content',
panel: this.activePanel,
api: this._api,
group: this.groupPanel,
getData: getPanelData,
}) })
); );
}), }),