diff --git a/packages/dockview/src/dnd/dataTransfer.ts b/packages/dockview/src/dnd/dataTransfer.ts index 88f87cf0a..2e756da5e 100644 --- a/packages/dockview/src/dnd/dataTransfer.ts +++ b/packages/dockview/src/dnd/dataTransfer.ts @@ -8,16 +8,7 @@ export class PanelTransfer extends TransferObject { constructor( public readonly viewId: string, public readonly groupId: string, - public readonly panelId: string - ) { - super(); - } -} - -export class GroupTransfer extends TransferObject { - constructor( - public readonly viewId: string, - public readonly groupId: string + public readonly panelId: string | null ) { super(); } @@ -87,17 +78,6 @@ export function getPanelData(): PanelTransfer | undefined { return panelTransfer.getData(PanelTransfer.prototype)![0]; } -export function getGroupData(): GroupTransfer | undefined { - const panelTransfer = LocalSelectionTransfer.getInstance(); - const isPanelEvent = panelTransfer.hasData(GroupTransfer.prototype); - - if (!isPanelEvent) { - return undefined; - } - - return panelTransfer.getData(GroupTransfer.prototype)![0]; -} - export function getPaneData(): PaneTransfer | undefined { const paneTransfer = LocalSelectionTransfer.getInstance(); const isPanelEvent = paneTransfer.hasData(PaneTransfer.prototype); diff --git a/packages/dockview/src/groupview/groupview.ts b/packages/dockview/src/groupview/groupview.ts index 590002b3d..789ce9157 100644 --- a/packages/dockview/src/groupview/groupview.ts +++ b/packages/dockview/src/groupview/groupview.ts @@ -1,5 +1,5 @@ import { DockviewApi } from '../api/component.api'; -import { getGroupData, getPanelData, PanelTransfer } from '../dnd/dataTransfer'; +import { getPanelData, PanelTransfer } from '../dnd/dataTransfer'; import { Droptarget, Position } from '../dnd/droptarget'; import { DockviewComponent } from '../dockview/dockviewComponent'; import { isAncestor, toggleClass } from '../dom'; @@ -247,18 +247,18 @@ export class Groupview extends CompositeDisposable implements IGroupview { return false; } - const group = getGroupData(); + const data = getPanelData(); if ( - group && - group.viewId === this.accessor.id && - group.groupId !== this.id + data && + data.panelId === null && + data.viewId === this.accessor.id && + data.groupId !== this.id ) { + // prevent dropping on self for group dnd return true; } - const data = getPanelData(); - if (data && data.viewId === this.accessor.id) { const groupHasOnePanelAndIsActiveDragElement = this._panels.length === 1 && data.groupId === this.id; @@ -700,21 +700,19 @@ export class Groupview extends CompositeDisposable implements IGroupview { position: Position, index?: number ): void { - const groupData = getGroupData(); - - if (groupData) { - const { groupId } = groupData; - this._onMove.fire({ - target: position, - groupId: groupId, - index, - }); - return; - } - const data = getPanelData(); if (data) { + if (data.panelId === null) { + const { groupId } = data; + this._onMove.fire({ + target: position, + groupId: groupId, + index, + }); + return; + } + const fromSameGroup = this.tabsContainer.indexOf(data.panelId) !== -1; diff --git a/packages/dockview/src/groupview/titlebar/voidContainer.ts b/packages/dockview/src/groupview/titlebar/voidContainer.ts index d11293d7a..5ffe1db55 100644 --- a/packages/dockview/src/groupview/titlebar/voidContainer.ts +++ b/packages/dockview/src/groupview/titlebar/voidContainer.ts @@ -2,8 +2,8 @@ import { last } from '../../array'; import { DragHandler } from '../../dnd/abstractDragHandler'; import { getPanelData, - GroupTransfer, LocalSelectionTransfer, + PanelTransfer, } from '../../dnd/dataTransfer'; import { Droptarget, DroptargetEvent } from '../../dnd/droptarget'; import { addGhostImage } from '../../dnd/ghost'; @@ -15,7 +15,7 @@ import { GroupPanel } from '../groupviewPanel'; class CustomDragHandler extends DragHandler { private readonly panelTransfer = - LocalSelectionTransfer.getInstance(); + LocalSelectionTransfer.getInstance(); constructor( element: HTMLElement, @@ -27,8 +27,8 @@ class CustomDragHandler extends DragHandler { getData(dataTransfer: DataTransfer | null): IDisposable { this.panelTransfer.setData( - [new GroupTransfer(this.accessorId, this.group.id)], - GroupTransfer.prototype + [new PanelTransfer(this.accessorId, this.group.id, null)], + PanelTransfer.prototype ); const style = window.getComputedStyle(this.el); @@ -58,7 +58,7 @@ class CustomDragHandler extends DragHandler { return { dispose: () => { - this.panelTransfer.clearData(GroupTransfer.prototype); + this.panelTransfer.clearData(PanelTransfer.prototype); }, }; }