mirror of
https://github.com/mathuo/dockview
synced 2025-05-02 01:28:28 +00:00
Add group with options.
This commit is contained in:
parent
502a984d2b
commit
03a39507dc
@ -36,12 +36,13 @@ import {
|
||||
IDockviewGroupPanel,
|
||||
} from '../dockview/dockviewGroupPanel';
|
||||
import { Emitter, Event } from '../events';
|
||||
import { GroupOptions } from '../dockview/dockviewGroupPanelModel';
|
||||
import { IDockviewPanel } from '../dockview/dockviewPanel';
|
||||
import { PaneviewDropEvent } from '../paneview/draggablePaneviewPanel';
|
||||
import {
|
||||
GroupDragEvent,
|
||||
TabDragEvent,
|
||||
} from '../dockview/components/titlebar/tabsContainer';
|
||||
} from '../dockview/components/titlebar/tabsContainer';
|
||||
import { Box } from '../types';
|
||||
|
||||
export interface CommonApi<T = any> {
|
||||
@ -736,8 +737,8 @@ export class DockviewApi implements CommonApi<SerializedDockview> {
|
||||
/**
|
||||
* Add a group and return the created object.
|
||||
*/
|
||||
addGroup(options?: AddGroupOptions): DockviewGroupPanel {
|
||||
return this.component.addGroup(options);
|
||||
addGroup(groupOptions?: GroupOptions, positionOptions?: AddGroupOptions): DockviewGroupPanel {
|
||||
return this.component.addGroup(groupOptions, positionOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,9 +49,12 @@ export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
|
||||
|
||||
const group =
|
||||
options.group ??
|
||||
this.accessor.addGroup({
|
||||
direction: positionToDirection(options.position ?? 'right'),
|
||||
});
|
||||
this.accessor.addGroup(
|
||||
undefined,
|
||||
{
|
||||
direction: positionToDirection(options.position ?? 'right'),
|
||||
}
|
||||
);
|
||||
|
||||
this.accessor.moveGroupOrPanel(
|
||||
group,
|
||||
|
@ -261,7 +261,7 @@ export interface IDockviewComponent extends IBaseGrid<DockviewGroupPanel> {
|
||||
getGroupPanel: (id: string) => IDockviewPanel | undefined;
|
||||
createWatermarkComponent(): IWatermarkRenderer;
|
||||
// lifecycle
|
||||
addGroup(options?: AddGroupOptions): DockviewGroupPanel;
|
||||
addGroup(groupOptions?: GroupOptions, positionOptions?: AddGroupOptions): DockviewGroupPanel;
|
||||
closeAllGroups(): void;
|
||||
// events
|
||||
moveToNext(options?: MovementOptions): void;
|
||||
@ -1280,23 +1280,23 @@ export class DockviewComponent
|
||||
}
|
||||
}
|
||||
|
||||
addGroup(options?: AddGroupOptions): DockviewGroupPanel {
|
||||
const group = this.createGroup();
|
||||
addGroup(groupOptions?: GroupOptions, positionOptions?: AddGroupOptions): DockviewGroupPanel {
|
||||
const group = this.createGroup(groupOptions);
|
||||
|
||||
if (options) {
|
||||
if (positionOptions) {
|
||||
let referenceGroup: DockviewGroupPanel | undefined;
|
||||
|
||||
if (isGroupOptionsWithPanel(options)) {
|
||||
if (isGroupOptionsWithPanel(positionOptions)) {
|
||||
const referencePanel =
|
||||
typeof options.referencePanel === 'string'
|
||||
typeof positionOptions.referencePanel === 'string'
|
||||
? this.panels.find(
|
||||
(panel) => panel.id === options.referencePanel
|
||||
(panel) => panel.id === positionOptions.referencePanel
|
||||
)
|
||||
: options.referencePanel;
|
||||
: positionOptions.referencePanel;
|
||||
|
||||
if (!referencePanel) {
|
||||
throw new Error(
|
||||
`reference panel ${options.referencePanel} does not exist`
|
||||
`reference panel ${positionOptions.referencePanel} does not exist`
|
||||
);
|
||||
}
|
||||
|
||||
@ -1304,28 +1304,28 @@ export class DockviewComponent
|
||||
|
||||
if (!referenceGroup) {
|
||||
throw new Error(
|
||||
`reference group for reference panel ${options.referencePanel} does not exist`
|
||||
`reference group for reference panel ${positionOptions.referencePanel} does not exist`
|
||||
);
|
||||
}
|
||||
} else if (isGroupOptionsWithGroup(options)) {
|
||||
} else if (isGroupOptionsWithGroup(positionOptions)) {
|
||||
referenceGroup =
|
||||
typeof options.referenceGroup === 'string'
|
||||
? this._groups.get(options.referenceGroup)?.value
|
||||
: options.referenceGroup;
|
||||
typeof positionOptions.referenceGroup === 'string'
|
||||
? this._groups.get(positionOptions.referenceGroup)?.value
|
||||
: positionOptions.referenceGroup;
|
||||
|
||||
if (!referenceGroup) {
|
||||
throw new Error(
|
||||
`reference group ${options.referenceGroup} does not exist`
|
||||
`reference group ${positionOptions.referenceGroup} does not exist`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const group = this.orthogonalize(
|
||||
directionToPosition(<Direction>options.direction)
|
||||
directionToPosition(<Direction>positionOptions.direction)
|
||||
);
|
||||
return group;
|
||||
}
|
||||
|
||||
const target = toTarget(<Direction>options.direction || 'within');
|
||||
const target = toTarget(<Direction>positionOptions.direction || 'within');
|
||||
|
||||
const location = getGridLocation(referenceGroup.element);
|
||||
const relativeLocation = getRelativeLocation(
|
||||
|
Loading…
Reference in New Issue
Block a user