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,
WillShowOverlayLocationEvent,
} from '../../dockviewGroupPanelModel';
import { getPanelData } from '../../../dnd/dataTransfer';
export interface TabDropIndexEvent {
readonly event: DragEvent;
@ -247,6 +248,10 @@ export class TabsContainer
this._onWillShowOverlay.fire(
new WillShowOverlayLocationEvent(event, {
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) => {
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';
}
get api(): DockviewApi {
return this._api;
}
constructor(options: DockviewComponentOptions) {
super({
proportionalLayout: true,
@ -579,6 +583,10 @@ export class DockviewComponent
this._onWillShowOverlay.fire(
new WillShowOverlayLocationEvent(event, {
kind: 'edge',
panel: undefined,
api: this._api,
group: undefined,
getData: getPanelData,
})
);
}),

View File

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