@eclipse-glsp/client
Version:
A sprotty-based client for GLSP
95 lines • 4.25 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FocusTracker = void 0;
/********************************************************************************
* Copyright (c) 2021-2024 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
const sprotty_1 = require("@eclipse-glsp/sprotty");
const inversify_1 = require("inversify");
const focus_state_change_action_1 = require("./focus-state-change-action");
/**
* Tracks the focus state of the diagram by handling {@link FocusStateChangedAction}s.
* Emits a {@link FocusChange} event when the focus state changes.
* Allows querying of the current focus state and the focused root diagram element and the currently focused element within the diagram.
*/
let FocusTracker = class FocusTracker {
constructor() {
this.inActiveCssClass = 'inactive';
this._hasFocus = true;
this.onFocusChangedEmitter = new sprotty_1.Emitter();
}
/**
* Event that is fired when the focus state of the diagram changes i.e. after a {@link FocusStateChangedAction} has been handled.
*/
get onFocusChanged() {
return this.onFocusChangedEmitter.event;
}
get hasFocus() {
return this._hasFocus;
}
get focusElement() {
return this._focusElement;
}
get diagramElement() {
return this._diagramElement;
}
handle(action) {
if (!focus_state_change_action_1.FocusStateChangedAction.is(action)) {
return;
}
this._hasFocus = action.hasFocus;
this._focusElement = document.activeElement;
this._diagramElement = document.getElementById(this.options.baseDiv);
if (!this._diagramElement) {
return;
}
if (this.hasFocus) {
if (this._diagramElement.classList.contains(this.inActiveCssClass)) {
this._diagramElement.classList.remove(this.inActiveCssClass);
}
}
else {
this._diagramElement.classList.add(this.inActiveCssClass);
}
this.onFocusChangedEmitter.fire({ hasFocus: this.hasFocus, focusElement: this.focusElement, diagramElement: this.diagramElement });
}
dispose() {
this.onFocusChangedEmitter.dispose();
}
};
exports.FocusTracker = FocusTracker;
__decorate([
(0, inversify_1.inject)(sprotty_1.TYPES.ViewerOptions),
__metadata("design:type", Object)
], FocusTracker.prototype, "options", void 0);
__decorate([
(0, inversify_1.preDestroy)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], FocusTracker.prototype, "dispose", null);
exports.FocusTracker = FocusTracker = __decorate([
(0, inversify_1.injectable)()
], FocusTracker);
//# sourceMappingURL=focus-tracker.js.map