dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
57 lines (56 loc) • 1.82 kB
JavaScript
import { CompositeDisposable } from '../lifecycle';
import { addTestId } from '../dom';
import { Event } from '../events';
import { defineModule } from './modules';
export class WatermarkService {
constructor(host) {
this._watermark = null;
this._host = host;
}
update() {
if (this._host.hasVisibleGridGroup()) {
this._unmount();
return;
}
if (this._watermark) {
return;
}
this._watermark = this._host.createWatermarkComponent();
this._watermark.init({ containerApi: this._host.api });
const container = document.createElement('div');
container.className = 'dv-watermark-container';
addTestId(container, 'watermark-component');
container.appendChild(this._watermark.element);
this._host.mountElement.appendChild(container);
}
refresh() {
this._unmount();
this.update();
}
_unmount() {
var _a, _b;
if (!this._watermark) {
return;
}
this._watermark.element.parentElement.remove();
(_b = (_a = this._watermark).dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
this._watermark = null;
}
dispose() {
this._unmount();
}
}
export const WatermarkModule = defineModule({
name: 'Watermark',
serviceKey: 'watermarkService',
create: (host) => new WatermarkService(host),
init: (host, service) => {
// Initial evaluation reflects the watermark state at construction time.
service.update();
return new CompositeDisposable(Event.any(host.onDidAdd, host.onDidRemove)(() => {
service.update();
}), host.onDidViewVisibilityChangeMicroTaskQueue(() => {
service.update();
}));
},
});