dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
220 lines (219 loc) • 7.83 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TabGroup = void 0;
var events_1 = require("../events");
var lifecycle_1 = require("../lifecycle");
var TabGroup = /** @class */ (function (_super) {
__extends(TabGroup, _super);
function TabGroup(id, options) {
var _a, _b;
var _this = _super.call(this) || this;
_this.id = id;
_this._collapsed = false;
_this._panelIds = [];
_this._onDidChange = new events_1.Emitter();
_this.onDidChange = _this._onDidChange.event;
_this._onDidPanelChange = new events_1.Emitter();
_this.onDidPanelChange = _this._onDidPanelChange.event;
_this._onDidCollapseChange = new events_1.Emitter();
_this.onDidCollapseChange = _this._onDidCollapseChange.event;
_this._onDidDestroy = new events_1.Emitter();
_this.onDidDestroy = _this._onDidDestroy.event;
_this._label = (_a = options === null || options === void 0 ? void 0 : options.label) !== null && _a !== void 0 ? _a : '';
_this._color = (options === null || options === void 0 ? void 0 : options.color) === '' ? undefined : options === null || options === void 0 ? void 0 : options.color;
_this._collapsed = (_b = options === null || options === void 0 ? void 0 : options.collapsed) !== null && _b !== void 0 ? _b : false;
_this._componentParams = options === null || options === void 0 ? void 0 : options.componentParams;
_this.addDisposables(_this._onDidChange, _this._onDidPanelChange, _this._onDidCollapseChange, _this._onDidDestroy);
return _this;
}
Object.defineProperty(TabGroup.prototype, "label", {
get: function () {
return this._label;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TabGroup.prototype, "color", {
get: function () {
return this._color;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TabGroup.prototype, "componentParams", {
get: function () {
return this._componentParams;
},
enumerable: false,
configurable: true
});
TabGroup.prototype.setLabel = function (value) {
if (this.isDisposed || this._label === value) {
return;
}
this._label = value;
this._onDidChange.fire();
};
TabGroup.prototype.setColor = function (value) {
if (this.isDisposed) {
return;
}
var next = value === '' ? undefined : value;
if (this._color === next) {
return;
}
this._color = next;
this._onDidChange.fire();
};
TabGroup.prototype.setComponentParams = function (value) {
if (this.isDisposed) {
return;
}
this._componentParams = value;
this._onDidChange.fire();
};
Object.defineProperty(TabGroup.prototype, "collapsed", {
get: function () {
return this._collapsed;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TabGroup.prototype, "panelIds", {
get: function () {
return this._panelIds;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TabGroup.prototype, "size", {
get: function () {
return this._panelIds.length;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TabGroup.prototype, "isEmpty", {
get: function () {
return this._panelIds.length === 0;
},
enumerable: false,
configurable: true
});
TabGroup.prototype.addPanel = function (panelId, index) {
if (this.isDisposed) {
return;
}
if (this._panelIds.includes(panelId)) {
return;
}
var insertIndex = index !== undefined
? Math.max(0, Math.min(index, this._panelIds.length))
: this._panelIds.length;
this._panelIds.splice(insertIndex, 0, panelId);
this._onDidPanelChange.fire({ panelId: panelId, type: 'add' });
};
TabGroup.prototype.removePanel = function (panelId) {
if (this.isDisposed) {
return false;
}
var index = this._panelIds.indexOf(panelId);
if (index === -1) {
return false;
}
this._panelIds.splice(index, 1);
this._onDidPanelChange.fire({ panelId: panelId, type: 'remove' });
return true;
};
TabGroup.prototype.indexOfPanel = function (panelId) {
return this._panelIds.indexOf(panelId);
};
TabGroup.prototype.containsPanel = function (panelId) {
return this._panelIds.includes(panelId);
};
TabGroup.prototype.collapse = function () {
if (this.isDisposed || this._collapsed) {
return;
}
this._collapsed = true;
this._onDidCollapseChange.fire(true);
};
TabGroup.prototype.expand = function () {
if (this.isDisposed || !this._collapsed) {
return;
}
this._collapsed = false;
this._onDidCollapseChange.fire(false);
};
TabGroup.prototype.toggle = function () {
if (this._collapsed) {
this.expand();
}
else {
this.collapse();
}
};
TabGroup.prototype.toJSON = function () {
var result = {
id: this.id,
collapsed: this._collapsed,
panelIds: __spreadArray([], __read(this._panelIds), false),
};
if (this._label) {
result.label = this._label;
}
if (this._color !== undefined) {
result.color = this._color;
}
if (this._componentParams !== undefined) {
result.componentParams = this._componentParams;
}
return result;
};
TabGroup.prototype.dispose = function () {
this._onDidDestroy.fire();
_super.prototype.dispose.call(this);
};
return TabGroup;
}(lifecycle_1.CompositeDisposable));
exports.TabGroup = TabGroup;