From 02af66a10f6c0c116ef2bc0f3e770d055d174bd9 Mon Sep 17 00:00:00 2001 From: NaNgets Date: Sun, 21 Jan 2024 22:51:19 +0200 Subject: [PATCH] PR comments. --- .../dockview-core/src/api/component.api.ts | 5 ++- .../src/api/dockviewGroupPanelApi.ts | 9 ++---- .../src/dockview/dockviewComponent.ts | 32 +++++++++---------- .../dockview-core/src/dockview/options.ts | 7 ++-- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/packages/dockview-core/src/api/component.api.ts b/packages/dockview-core/src/api/component.api.ts index 97ddd6834..d4a8aae02 100644 --- a/packages/dockview-core/src/api/component.api.ts +++ b/packages/dockview-core/src/api/component.api.ts @@ -36,7 +36,6 @@ 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 { @@ -737,8 +736,8 @@ export class DockviewApi implements CommonApi { /** * Add a group and return the created object. */ - addGroup(groupOptions?: GroupOptions, positionOptions?: AddGroupOptions): DockviewGroupPanel { - return this.component.addGroup(groupOptions, positionOptions); + addGroup(options?: AddGroupOptions): DockviewGroupPanel { + return this.component.addGroup(options); } /** diff --git a/packages/dockview-core/src/api/dockviewGroupPanelApi.ts b/packages/dockview-core/src/api/dockviewGroupPanelApi.ts index 82a40204e..c4b349bdf 100644 --- a/packages/dockview-core/src/api/dockviewGroupPanelApi.ts +++ b/packages/dockview-core/src/api/dockviewGroupPanelApi.ts @@ -49,12 +49,9 @@ export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl { const group = options.group ?? - this.accessor.addGroup( - undefined, - { - direction: positionToDirection(options.position ?? 'right'), - } - ); + this.accessor.addGroup({ + direction: positionToDirection(options.position ?? 'right'), + }); this.accessor.moveGroupOrPanel( group, diff --git a/packages/dockview-core/src/dockview/dockviewComponent.ts b/packages/dockview-core/src/dockview/dockviewComponent.ts index ac3cfbe58..be7e1a732 100644 --- a/packages/dockview-core/src/dockview/dockviewComponent.ts +++ b/packages/dockview-core/src/dockview/dockviewComponent.ts @@ -1280,23 +1280,23 @@ export class DockviewComponent } } - addGroup(groupOptions?: GroupOptions, positionOptions?: AddGroupOptions): DockviewGroupPanel { - const group = this.createGroup(groupOptions); + addGroup(options?: AddGroupOptions): DockviewGroupPanel { + const group = this.createGroup(options); - if (positionOptions) { + if (options) { let referenceGroup: DockviewGroupPanel | undefined; - if (isGroupOptionsWithPanel(positionOptions)) { + if (isGroupOptionsWithPanel(options)) { const referencePanel = - typeof positionOptions.referencePanel === 'string' + typeof options.referencePanel === 'string' ? this.panels.find( - (panel) => panel.id === positionOptions.referencePanel + (panel) => panel.id === options.referencePanel ) - : positionOptions.referencePanel; + : options.referencePanel; if (!referencePanel) { throw new Error( - `reference panel ${positionOptions.referencePanel} does not exist` + `reference panel ${options.referencePanel} does not exist` ); } @@ -1304,28 +1304,28 @@ export class DockviewComponent if (!referenceGroup) { throw new Error( - `reference group for reference panel ${positionOptions.referencePanel} does not exist` + `reference group for reference panel ${options.referencePanel} does not exist` ); } - } else if (isGroupOptionsWithGroup(positionOptions)) { + } else if (isGroupOptionsWithGroup(options)) { referenceGroup = - typeof positionOptions.referenceGroup === 'string' - ? this._groups.get(positionOptions.referenceGroup)?.value - : positionOptions.referenceGroup; + typeof options.referenceGroup === 'string' + ? this._groups.get(options.referenceGroup)?.value + : options.referenceGroup; if (!referenceGroup) { throw new Error( - `reference group ${positionOptions.referenceGroup} does not exist` + `reference group ${options.referenceGroup} does not exist` ); } } else { const group = this.orthogonalize( - directionToPosition(positionOptions.direction) + directionToPosition(options.direction) ); return group; } - const target = toTarget(positionOptions.direction || 'within'); + const target = toTarget(options.direction || 'within'); const location = getGridLocation(referenceGroup.element); const relativeLocation = getRelativeLocation( diff --git a/packages/dockview-core/src/dockview/options.ts b/packages/dockview-core/src/dockview/options.ts index 34ab98989..60a3953e4 100644 --- a/packages/dockview-core/src/dockview/options.ts +++ b/packages/dockview-core/src/dockview/options.ts @@ -14,6 +14,7 @@ import { ISplitviewStyles, Orientation } from '../splitview/splitview'; import { PanelTransfer } from '../dnd/dataTransfer'; import { IDisposable } from '../lifecycle'; import { DroptargetOverlayModel, Position } from '../dnd/droptarget'; +import { GroupOptions } from './dockviewGroupPanelModel'; import { IDockviewPanel } from './dockviewPanel'; import { ComponentConstructor, @@ -186,10 +187,12 @@ type AddGroupOptionsWithGroup = { direction?: Omit; }; -export type AddGroupOptions = +export type AddGroupOptions = ( | AddGroupOptionsWithGroup | AddGroupOptionsWithPanel - | AbsolutePosition; + | AbsolutePosition +) & + GroupOptions; export function isGroupOptionsWithPanel( data: AddGroupOptions