mirror of
https://github.com/mathuo/dockview
synced 2025-05-03 18:18:25 +00:00
Merge pull request #522 from mathuo/395-showdndoverlay-is-not-called-always-2
feat: simplify event
This commit is contained in:
commit
cc50199cff
@ -11,7 +11,10 @@ import { toggleClass } from '../../../dom';
|
||||
import { DockviewPanel, IDockviewPanel } from '../../dockviewPanel';
|
||||
import { DockviewComponent } from '../../dockviewComponent';
|
||||
import { WillShowOverlayEvent } from '../../../dnd/droptarget';
|
||||
import { DockviewGroupDropLocation } from '../../dockviewGroupPanelModel';
|
||||
import {
|
||||
DockviewGroupDropLocation,
|
||||
WillShowOverlayLocationEvent,
|
||||
} from '../../dockviewGroupPanelModel';
|
||||
|
||||
export interface TabDropIndexEvent {
|
||||
readonly event: DragEvent;
|
||||
@ -35,10 +38,7 @@ export interface ITabsContainer extends IDisposable {
|
||||
readonly onDrop: Event<TabDropIndexEvent>;
|
||||
readonly onTabDragStart: Event<TabDragEvent>;
|
||||
readonly onGroupDragStart: Event<GroupDragEvent>;
|
||||
readonly onWillShowOverlay: Event<{
|
||||
event: WillShowOverlayEvent;
|
||||
kind: DockviewGroupDropLocation;
|
||||
}>;
|
||||
readonly onWillShowOverlay: Event<WillShowOverlayLocationEvent>;
|
||||
hidden: boolean;
|
||||
delete(id: string): void;
|
||||
indexOf(id: string): number;
|
||||
@ -83,14 +83,10 @@ export class TabsContainer
|
||||
readonly onGroupDragStart: Event<GroupDragEvent> =
|
||||
this._onGroupDragStart.event;
|
||||
|
||||
private readonly _onWillShowOverlay = new Emitter<{
|
||||
event: WillShowOverlayEvent;
|
||||
kind: DockviewGroupDropLocation;
|
||||
}>();
|
||||
readonly onWillShowOverlay: Event<{
|
||||
event: WillShowOverlayEvent;
|
||||
kind: DockviewGroupDropLocation;
|
||||
}> = this._onWillShowOverlay.event;
|
||||
private readonly _onWillShowOverlay =
|
||||
new Emitter<WillShowOverlayLocationEvent>();
|
||||
readonly onWillShowOverlay: Event<WillShowOverlayLocationEvent> =
|
||||
this._onWillShowOverlay.event;
|
||||
|
||||
get panels(): string[] {
|
||||
return this.tabs.map((_) => _.value.panel.id);
|
||||
@ -248,7 +244,11 @@ export class TabsContainer
|
||||
});
|
||||
}),
|
||||
this.voidContainer.onWillShowOverlay((event) => {
|
||||
this._onWillShowOverlay.fire({ event, kind: 'header_space' });
|
||||
this._onWillShowOverlay.fire(
|
||||
new WillShowOverlayLocationEvent(event, {
|
||||
kind: 'header_space',
|
||||
})
|
||||
);
|
||||
}),
|
||||
addDisposableListener(
|
||||
this.voidContainer.element,
|
||||
@ -407,7 +407,9 @@ export class TabsContainer
|
||||
});
|
||||
}),
|
||||
tab.onWillShowOverlay((event) => {
|
||||
this._onWillShowOverlay.fire({ event, kind: 'tab' });
|
||||
this._onWillShowOverlay.fire(
|
||||
new WillShowOverlayLocationEvent(event, { kind: 'tab' })
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -2134,7 +2134,7 @@ export class DockviewComponent
|
||||
}),
|
||||
view.model.onWillShowOverlay((event) => {
|
||||
if (this.options.disableDnd) {
|
||||
event.event.preventDefault();
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
DockviewEvent,
|
||||
Emitter,
|
||||
Event,
|
||||
IDockviewEvent,
|
||||
} from '../events';
|
||||
import { IViewSize } from '../gridview/gridview';
|
||||
import { CompositeDisposable } from '../lifecycle';
|
||||
@ -179,9 +180,39 @@ export type DockviewGroupLocation =
|
||||
| { type: 'floating' }
|
||||
| { type: 'popout'; getWindow: () => Window };
|
||||
|
||||
export interface WillShowOverlayLocationEvent {
|
||||
event: WillShowOverlayEvent;
|
||||
kind: DockviewGroupDropLocation;
|
||||
type A = typeof WillShowOverlayEvent;
|
||||
|
||||
export class WillShowOverlayLocationEvent implements IDockviewEvent {
|
||||
private _kind: DockviewGroupDropLocation;
|
||||
|
||||
get kind(): DockviewGroupDropLocation {
|
||||
return this._kind;
|
||||
}
|
||||
|
||||
get nativeEvent(): DragEvent {
|
||||
return this.event.nativeEvent;
|
||||
}
|
||||
|
||||
get position(): Position {
|
||||
return this.event.position;
|
||||
}
|
||||
|
||||
get defaultPrevented(): boolean {
|
||||
return this.event.defaultPrevented;
|
||||
}
|
||||
|
||||
preventDefault(): void {
|
||||
this.event.preventDefault();
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly event: WillShowOverlayEvent,
|
||||
options: {
|
||||
kind: DockviewGroupDropLocation;
|
||||
}
|
||||
) {
|
||||
this._kind = options.kind;
|
||||
}
|
||||
}
|
||||
|
||||
export class DockviewGroupPanelModel
|
||||
@ -411,7 +442,11 @@ export class DockviewGroupPanelModel
|
||||
this._onWillShowOverlay.fire(event);
|
||||
}),
|
||||
this.contentContainer.dropTarget.onWillShowOverlay((event) => {
|
||||
this._onWillShowOverlay.fire({ event, kind: 'content' });
|
||||
this._onWillShowOverlay.fire(
|
||||
new WillShowOverlayLocationEvent(event, {
|
||||
kind: 'content',
|
||||
})
|
||||
);
|
||||
}),
|
||||
this._onMove,
|
||||
this._onDidChange,
|
||||
|
@ -24,7 +24,12 @@ export namespace Event {
|
||||
};
|
||||
}
|
||||
|
||||
export class DockviewEvent {
|
||||
export interface IDockviewEvent {
|
||||
readonly defaultPrevented: boolean;
|
||||
preventDefault(): void;
|
||||
}
|
||||
|
||||
export class DockviewEvent implements IDockviewEvent {
|
||||
private _defaultPrevented = false;
|
||||
|
||||
get defaultPrevented(): boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user