UNPKG

dockview

Version:

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

99 lines (98 loc) 3.17 kB
import { Emitter } from '../events'; import { CompositeDisposable } from '../lifecycle'; /** * A core api implementation that should be used across all panel-like objects */ export class PanelApiImpl extends CompositeDisposable { constructor(id) { super(); this.id = id; this._state = {}; this._isFocused = false; this._isActive = false; this._isVisible = true; this._width = 0; this._height = 0; this._onDidStateChange = new Emitter(); this.onDidStateChange = this._onDidStateChange.event; // this._onDidPanelDimensionChange = new Emitter({ replay: true, }); this.onDidDimensionsChange = this._onDidPanelDimensionChange.event; // this._onDidChangeFocus = new Emitter({ replay: true, }); this.onDidFocusChange = this._onDidChangeFocus.event; // this._onFocusEvent = new Emitter(); this.onFocusEvent = this._onFocusEvent.event; // this._onDidVisibilityChange = new Emitter({ replay: true, }); this.onDidVisibilityChange = this._onDidVisibilityChange.event; // this._onVisibilityChange = new Emitter(); this.onVisibilityChange = this._onVisibilityChange.event; // this._onDidActiveChange = new Emitter({ replay: true, }); this.onDidActiveChange = this._onDidActiveChange.event; // this._onActiveChange = new Emitter(); this.onActiveChange = this._onActiveChange.event; this.addDisposables(this._onDidStateChange, this._onDidPanelDimensionChange, this._onDidChangeFocus, this._onDidVisibilityChange, this._onDidActiveChange, this._onFocusEvent, this.onDidFocusChange((event) => { this._isFocused = event.isFocused; }), this.onDidActiveChange((event) => { this._isActive = event.isActive; }), this.onDidVisibilityChange((event) => { this._isVisible = event.isVisible; }), this.onDidDimensionsChange((event) => { this._width = event.width; this._height = event.height; })); } // get isFocused() { return this._isFocused; } get isActive() { return this._isActive; } get isVisible() { return this._isVisible; } get width() { return this._width; } get height() { return this._height; } setVisible(isVisible) { this._onVisibilityChange.fire({ isVisible }); } setActive() { this._onActiveChange.fire(); } setState(key, value) { if (typeof key === 'object') { this._state = key; } else if (typeof value !== undefined) { this._state[key] = value; } this._onDidStateChange.fire(undefined); } getState() { return this._state; } getStateKey(key) { return this._state[key]; } dispose() { super.dispose(); } }