dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
137 lines (136 loc) • 4.55 kB
JavaScript
import { positionToDirection } from '../dnd/droptarget';
import { Emitter } from '../events';
import { GridviewPanelApiImpl, } from './gridviewPanelApi';
const NOT_INITIALIZED_MESSAGE = 'dockview: DockviewGroupPanelApiImpl not initialized';
export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
get location() {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
return this._group.model.location;
}
get locked() {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
return this._group.locked;
}
set locked(value) {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
this._group.locked = value;
}
constructor(id, accessor) {
super(id, '__dockviewgroup__');
this.accessor = accessor;
this._onDidLocationChange = new Emitter();
this.onDidLocationChange = this._onDidLocationChange.event;
this._onDidActivePanelChange = new Emitter();
this.onDidActivePanelChange = this._onDidActivePanelChange.event;
this._onDidCollapsedChange = new Emitter();
this.onDidCollapsedChange = this._onDidCollapsedChange.event;
this.addDisposables(this._onDidLocationChange, this._onDidActivePanelChange, this._onDidCollapsedChange, this._onDidVisibilityChange.event((event) => {
// When becoming visible, apply any pending size change
if (event.isVisible && this._pendingSize) {
super.setSize(this._pendingSize);
this._pendingSize = undefined;
}
}));
}
setSize(event) {
// Always store the requested size
this._pendingSize = Object.assign({}, event);
// Apply the size change immediately
super.setSize(event);
}
close() {
if (!this._group) {
return;
}
return this.accessor.removeGroup(this._group);
}
getWindow() {
return this.location.type === 'popout'
? this.location.getWindow()
: window;
}
setHeaderPosition(position) {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
this._group.model.headerPosition = position;
}
getHeaderPosition() {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
return this._group.model.headerPosition;
}
moveTo(options) {
var _a, _b, _c, _d;
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
const group = (_a = options.group) !== null && _a !== void 0 ? _a : this.accessor.addGroup({
direction: positionToDirection((_b = options.position) !== null && _b !== void 0 ? _b : 'right'),
skipSetActive: (_c = options.skipSetActive) !== null && _c !== void 0 ? _c : false,
});
this.accessor.moveGroupOrPanel({
from: { groupId: this._group.id },
to: {
group,
position: options.group
? ((_d = options.position) !== null && _d !== void 0 ? _d : 'center')
: 'center',
index: options.index,
},
skipSetActive: options.skipSetActive,
});
}
maximize() {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
if (this.location.type !== 'grid') {
// only grid groups can be maximized
return;
}
this.accessor.maximizeGroup(this._group);
}
isMaximized() {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
return this.accessor.isMaximizedGroup(this._group);
}
exitMaximized() {
if (!this._group) {
throw new Error(NOT_INITIALIZED_MESSAGE);
}
if (this.isMaximized()) {
this.accessor.exitMaximizedGroup();
}
}
collapse() {
if (!this._group) {
return;
}
this.accessor.setEdgeGroupCollapsed(this._group, true);
}
expand() {
if (!this._group) {
return;
}
this.accessor.setEdgeGroupCollapsed(this._group, false);
}
isCollapsed() {
if (!this._group) {
return false;
}
return this.accessor.isEdgeGroupCollapsed(this._group);
}
initialize(group) {
this._group = group;
}
}