UNPKG

dockview

Version:

Zero dependency layout manager supporting tabs, grids and splitviews with ReactJS support

196 lines 8.25 kB
"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 __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DockviewGroupPanel = void 0; var groupview_1 = require("../groupview/groupview"); var groupPanelApi_1 = require("../api/groupPanelApi"); var lifecycle_1 = require("../lifecycle"); var DockviewGroupPanel = /** @class */ (function (_super) { __extends(DockviewGroupPanel, _super); function DockviewGroupPanel(id, containerApi) { var _this = _super.call(this) || this; _this.id = id; _this.containerApi = containerApi; _this.mutableDisposable = new lifecycle_1.MutableDisposable(); _this._suppressClosable = false; _this._title = ''; _this.api = new groupPanelApi_1.DockviewPanelApiImpl(_this, _this._group); _this.onDidStateChange = _this.api.onDidStateChange; _this.addDisposables(_this.api.onActiveChange(function () { _this.containerApi.setActivePanel(_this); }), _this.api.onDidTitleChange(function (event) { var title = event.title; _this.update({ params: { title: title } }); })); return _this; } Object.defineProperty(DockviewGroupPanel.prototype, "title", { get: function () { return this._title; }, enumerable: false, configurable: true }); Object.defineProperty(DockviewGroupPanel.prototype, "suppressClosable", { get: function () { return this._suppressClosable; }, enumerable: false, configurable: true }); Object.defineProperty(DockviewGroupPanel.prototype, "group", { get: function () { return this._group; }, enumerable: false, configurable: true }); Object.defineProperty(DockviewGroupPanel.prototype, "view", { get: function () { return this._view; }, enumerable: false, configurable: true }); DockviewGroupPanel.prototype.init = function (params) { var _a; this._params = params.params; this._view = params.view; this.setTitle(params.title); this.setSuppressClosable(params.suppressClosable || false); if (params.state) { this.api.setState(params.state); } (_a = this.view) === null || _a === void 0 ? void 0 : _a.init(__assign(__assign({}, params), { api: this.api, containerApi: this.containerApi })); }; DockviewGroupPanel.prototype.focus = function () { this.api._onFocusEvent.fire(); }; DockviewGroupPanel.prototype.setDirty = function (isDirty) { this.api._onDidDirtyChange.fire(isDirty); }; DockviewGroupPanel.prototype.close = function () { if (this.api.tryClose) { return this.api.tryClose(); } return Promise.resolve(true); }; DockviewGroupPanel.prototype.toJSON = function () { var state = this.api.getState(); return { id: this.id, view: this.view.toJSON(), params: Object.keys(this._params || {}).length > 0 ? this._params : undefined, state: state && Object.keys(state).length > 0 ? state : undefined, suppressClosable: this.suppressClosable || undefined, title: this.title, }; }; DockviewGroupPanel.prototype.setTitle = function (title) { var _a; var didTitleChange = title !== ((_a = this._params) === null || _a === void 0 ? void 0 : _a.title); if (didTitleChange) { this._title = title; this.api._titleChanged.fire({ title: this.title }); } }; DockviewGroupPanel.prototype.setSuppressClosable = function (suppressClosable) { var _a; var didSuppressChangableClose = suppressClosable !== ((_a = this._params) === null || _a === void 0 ? void 0 : _a.suppressClosable); if (didSuppressChangableClose) { this._suppressClosable = suppressClosable; this.api._suppressClosableChanged.fire({ suppressClosable: !!this.suppressClosable, }); } }; DockviewGroupPanel.prototype.update = function (event) { var _a; var params = event.params; this._params = __assign(__assign({}, (this._params || {})), event.params.params); if (typeof params.title === 'string') { this.setTitle(params.title); } if (typeof params.suppressClosable === 'boolean') { this.setSuppressClosable(params.suppressClosable); } (_a = this.view) === null || _a === void 0 ? void 0 : _a.update({ params: { params: this._params, title: this.title, suppressClosable: this.suppressClosable, }, }); }; DockviewGroupPanel.prototype.updateParentGroup = function (group, isGroupActive) { var _this = this; var _a; this._group = group; this.api.group = group; this.mutableDisposable.value = this._group.model.onDidGroupChange(function (ev) { var _a; if (ev.kind === groupview_1.GroupChangeKind2.GROUP_ACTIVE) { var isVisible = !!((_a = _this._group) === null || _a === void 0 ? void 0 : _a.model.isPanelActive(_this)); _this.api._onDidActiveChange.fire({ isActive: isGroupActive && isVisible, }); _this.api._onDidVisibilityChange.fire({ isVisible: isVisible, }); } }); var isPanelVisible = this._group.model.isPanelActive(this); this.api._onDidActiveChange.fire({ isActive: isGroupActive && isPanelVisible, }); this.api._onDidVisibilityChange.fire({ isVisible: isPanelVisible, }); (_a = this.view) === null || _a === void 0 ? void 0 : _a.updateParentGroup(this._group, this._group.model.isPanelActive(this)); }; DockviewGroupPanel.prototype.layout = function (width, height) { var _a, _b; // the obtain the correct dimensions of the content panel we must deduct the tab height this.api._onDidPanelDimensionChange.fire({ width: width, height: height - (((_a = this.group) === null || _a === void 0 ? void 0 : _a.model.tabHeight) || 0), }); (_b = this.view) === null || _b === void 0 ? void 0 : _b.layout(width, height); }; DockviewGroupPanel.prototype.dispose = function () { var _a; this.api.dispose(); this.mutableDisposable.dispose(); (_a = this.view) === null || _a === void 0 ? void 0 : _a.dispose(); }; return DockviewGroupPanel; }(lifecycle_1.CompositeDisposable)); exports.DockviewGroupPanel = DockviewGroupPanel; //# sourceMappingURL=dockviewGroupPanel.js.map