feat: dnd edge custom dnd handles

This commit is contained in:
mathuo 2023-02-20 20:12:49 +07:00
parent fe5a882631
commit 9f504f2597
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
4 changed files with 42 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import {
directionToPosition,
Droptarget,
Position,
positionToDirection,
} from '../../dnd/droptarget';
import { fireEvent } from '@testing-library/dom';
@ -44,6 +45,17 @@ describe('droptarget', () => {
);
});
test('positionToDirection', () => {
expect(positionToDirection('top')).toBe('above');
expect(positionToDirection('bottom')).toBe('below');
expect(positionToDirection('left')).toBe('left');
expect(positionToDirection('right')).toBe('right');
expect(positionToDirection('center')).toBe('within');
expect(() => positionToDirection('bad_input' as any)).toThrow(
"invalid position 'bad_input'"
);
});
test('non-directional', () => {
let position: Position | undefined = undefined;

View File

@ -27,6 +27,23 @@ export function directionToPosition(direction: Direction): Position {
}
}
export function positionToDirection(position: Position): Direction {
switch (position) {
case 'top':
return 'above';
case 'bottom':
return 'below';
case 'left':
return 'left';
case 'right':
return 'right';
case 'center':
return 'within';
default:
throw new Error(`invalid position '${position}'`);
}
}
export interface DroptargetEvent {
readonly position: Position;
readonly nativeEvent: DragEvent;

View File

@ -80,7 +80,7 @@ export type DockviewComponentUpdateOptions = Pick<
export interface DockviewDropEvent extends GroupviewDropEvent {
api: DockviewApi;
group: GroupPanel;
group: GroupPanel | null;
}
export interface IDockviewComponent extends IBaseGrid<GroupPanel> {
@ -276,6 +276,13 @@ export class DockviewComponent
data.panelId || undefined,
'center'
);
} else {
this._onDidDrop.fire({
...event,
api: this._api,
group: null,
getData: getPanelData,
});
}
})
);

View File

@ -27,7 +27,11 @@ export * from './react'; // TODO: should be conditional on whether user wants th
export { Event } from './events';
export { IDisposable } from './lifecycle';
export { Position as DropTargetDirections } from './dnd/droptarget';
export {
Position,
positionToDirection,
directionToPosition,
} from './dnd/droptarget';
export {
FocusEvent,
PanelDimensionChangeEvent,