UNPKG

4.61 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2019 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.BreadcrumbPopupContainer = exports.BreadcrumbID = exports.BreadcrumbPopupContainerFactory = void 0;
19const tslib_1 = require("tslib");
20const inversify_1 = require("../../../shared/inversify");
21const common_1 = require("../../common");
22const disposable_1 = require("../../common/disposable");
23const context_menu_renderer_1 = require("../context-menu-renderer");
24const react_renderer_1 = require("../widgets/react-renderer");
25const breadcrumbs_constants_1 = require("./breadcrumbs-constants");
26exports.BreadcrumbPopupContainerFactory = Symbol('BreadcrumbPopupContainerFactory');
27exports.BreadcrumbID = Symbol('BreadcrumbID');
28/**
29 * This class creates a popup container at the given position
30 * so that contributions can attach their HTML elements
31 * as children of `BreadcrumbPopupContainer#container`.
32 *
33 * - `dispose()` is called on blur or on hit on escape
34 */
35let BreadcrumbPopupContainer = class BreadcrumbPopupContainer {
36 constructor() {
37 this.onDidDisposeEmitter = new common_1.Emitter();
38 this.toDispose = new disposable_1.DisposableCollection(this.onDidDisposeEmitter);
39 this.onFocusOut = (event) => {
40 if (!(event.relatedTarget instanceof Element) || !this._container.contains(event.relatedTarget)) {
41 this.dispose();
42 }
43 };
44 this.escFunction = (event) => {
45 if (event.key === 'Escape' || event.key === 'Esc') {
46 this.dispose();
47 }
48 };
49 }
50 get onDidDispose() {
51 return this.onDidDisposeEmitter.event;
52 }
53 get container() {
54 return this._container;
55 }
56 get isOpen() {
57 return this._isOpen;
58 }
59 init() {
60 this._container = this.createPopupDiv(this.position);
61 document.addEventListener('keyup', this.escFunction);
62 this._container.focus();
63 this._isOpen = true;
64 }
65 createPopupDiv(position) {
66 const result = window.document.createElement('div');
67 result.className = breadcrumbs_constants_1.Styles.BREADCRUMB_POPUP;
68 result.style.left = `${position.x}px`;
69 result.style.top = `${position.y}px`;
70 result.tabIndex = 0;
71 result.addEventListener('focusout', this.onFocusOut);
72 this.parent.appendChild(result);
73 return result;
74 }
75 dispose() {
76 if (!this.toDispose.disposed) {
77 this.onDidDisposeEmitter.fire();
78 this.toDispose.dispose();
79 this._container.remove();
80 this._isOpen = false;
81 document.removeEventListener('keyup', this.escFunction);
82 }
83 }
84};
85(0, tslib_1.__decorate)([
86 (0, inversify_1.inject)(react_renderer_1.RendererHost),
87 (0, tslib_1.__metadata)("design:type", Object)
88], BreadcrumbPopupContainer.prototype, "parent", void 0);
89(0, tslib_1.__decorate)([
90 (0, inversify_1.inject)(exports.BreadcrumbID),
91 (0, tslib_1.__metadata)("design:type", String)
92], BreadcrumbPopupContainer.prototype, "breadcrumbId", void 0);
93(0, tslib_1.__decorate)([
94 (0, inversify_1.inject)(context_menu_renderer_1.Coordinate),
95 (0, tslib_1.__metadata)("design:type", Object)
96], BreadcrumbPopupContainer.prototype, "position", void 0);
97(0, tslib_1.__decorate)([
98 (0, inversify_1.postConstruct)(),
99 (0, tslib_1.__metadata)("design:type", Function),
100 (0, tslib_1.__metadata)("design:paramtypes", []),
101 (0, tslib_1.__metadata)("design:returntype", void 0)
102], BreadcrumbPopupContainer.prototype, "init", null);
103BreadcrumbPopupContainer = (0, tslib_1.__decorate)([
104 (0, inversify_1.injectable)()
105], BreadcrumbPopupContainer);
106exports.BreadcrumbPopupContainer = BreadcrumbPopupContainer;
107//# sourceMappingURL=breadcrumb-popup-container.js.map
\No newline at end of file