feat: use native event defaulting

This commit is contained in:
mathuo 2024-02-24 20:14:19 +00:00
parent fd2460416a
commit 063bd4adf1
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
2 changed files with 8 additions and 25 deletions

View File

@ -1,5 +1,5 @@
import { toggleClass } from '../dom'; import { toggleClass } from '../dom';
import { DockviewEvent, Emitter, Event } from '../events'; import { Emitter, Event } from '../events';
import { CompositeDisposable } from '../lifecycle'; import { CompositeDisposable } from '../lifecycle';
import { DragAndDropObserver } from './dnd'; import { DragAndDropObserver } from './dnd';
import { clamp } from '../math'; import { clamp } from '../math';
@ -10,26 +10,9 @@ export interface DroptargetEvent {
readonly nativeEvent: DragEvent; readonly nativeEvent: DragEvent;
} }
export class WillShowOverlayEvent export interface WillShowOverlayEvent extends DroptargetEvent {
extends DockviewEvent readonly nativeEvent: DragEvent;
implements DroptargetEvent readonly position: Position;
{
get nativeEvent(): DragEvent {
return this.options.nativeEvent;
}
get position(): Position {
return this.options.position;
}
constructor(
private readonly options: {
nativeEvent: DragEvent;
position: Position;
}
) {
super();
}
} }
export function directionToPosition(direction: Direction): Position { export function directionToPosition(direction: Direction): Position {
@ -170,10 +153,10 @@ export class Droptarget extends CompositeDisposable {
return; return;
} }
const willShowOverlayEvent = new WillShowOverlayEvent({ const willShowOverlayEvent: WillShowOverlayEvent = {
nativeEvent: e, nativeEvent: e,
position: quadrant, position: quadrant,
}); };
/** /**
* Provide an opportunity to prevent the overlay appearing and in turn * Provide an opportunity to prevent the overlay appearing and in turn
@ -181,7 +164,7 @@ export class Droptarget extends CompositeDisposable {
*/ */
this._onWillShowOverlay.fire(willShowOverlayEvent); this._onWillShowOverlay.fire(willShowOverlayEvent);
if (willShowOverlayEvent.defaultPrevented) { if (willShowOverlayEvent.nativeEvent.defaultPrevented) {
this.removeDropTarget(); this.removeDropTarget();
return; return;
} }

View File

@ -2134,7 +2134,7 @@ export class DockviewComponent
}), }),
view.model.onWillShowOverlay((event) => { view.model.onWillShowOverlay((event) => {
if (this.options.disableDnd) { if (this.options.disableDnd) {
event.event.preventDefault(); event.event.nativeEvent.preventDefault();
return; return;
} }