dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
62 lines (61 loc) • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WatermarkModule = exports.WatermarkService = void 0;
var lifecycle_1 = require("../lifecycle");
var dom_1 = require("../dom");
var events_1 = require("../events");
var modules_1 = require("./modules");
var WatermarkService = /** @class */ (function () {
function WatermarkService(host) {
this._watermark = null;
this._host = host;
}
WatermarkService.prototype.update = function () {
if (this._host.hasVisibleGridGroup()) {
this._unmount();
return;
}
if (this._watermark) {
return;
}
this._watermark = this._host.createWatermarkComponent();
this._watermark.init({ containerApi: this._host.api });
var container = document.createElement('div');
container.className = 'dv-watermark-container';
(0, dom_1.addTestId)(container, 'watermark-component');
container.appendChild(this._watermark.element);
this._host.mountElement.appendChild(container);
};
WatermarkService.prototype.refresh = function () {
this._unmount();
this.update();
};
WatermarkService.prototype._unmount = function () {
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;
};
WatermarkService.prototype.dispose = function () {
this._unmount();
};
return WatermarkService;
}());
exports.WatermarkService = WatermarkService;
exports.WatermarkModule = (0, modules_1.defineModule)({
name: 'Watermark',
serviceKey: 'watermarkService',
create: function (host) { return new WatermarkService(host); },
init: function (host, service) {
// Initial evaluation reflects the watermark state at construction time.
service.update();
return new lifecycle_1.CompositeDisposable(events_1.Event.any(host.onDidAdd, host.onDidRemove)(function () {
service.update();
}), host.onDidViewVisibilityChangeMicroTaskQueue(function () {
service.update();
}));
},
});