UNPKG

5.18 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// *****************************************************************************
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 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;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27exports.BreadcrumbPopupContainer = exports.BreadcrumbID = exports.BreadcrumbPopupContainerFactory = void 0;
28const inversify_1 = require("../../../shared/inversify");
29const common_1 = require("../../common");
30const disposable_1 = require("../../common/disposable");
31const context_menu_renderer_1 = require("../context-menu-renderer");
32const react_renderer_1 = require("../widgets/react-renderer");
33const breadcrumbs_constants_1 = require("./breadcrumbs-constants");
34exports.BreadcrumbPopupContainerFactory = Symbol('BreadcrumbPopupContainerFactory');
35exports.BreadcrumbID = Symbol('BreadcrumbID');
36/**
37 * This class creates a popup container at the given position
38 * so that contributions can attach their HTML elements
39 * as children of `BreadcrumbPopupContainer#container`.
40 *
41 * - `dispose()` is called on blur or on hit on escape
42 */
43let BreadcrumbPopupContainer = class BreadcrumbPopupContainer {
44 constructor() {
45 this.onDidDisposeEmitter = new common_1.Emitter();
46 this.toDispose = new disposable_1.DisposableCollection(this.onDidDisposeEmitter);
47 this.onFocusOut = (event) => {
48 if (!(event.relatedTarget instanceof Element) || !this._container.contains(event.relatedTarget)) {
49 this.dispose();
50 }
51 };
52 this.escFunction = (event) => {
53 if (event.key === 'Escape' || event.key === 'Esc') {
54 this.dispose();
55 }
56 };
57 }
58 get onDidDispose() {
59 return this.onDidDisposeEmitter.event;
60 }
61 get container() {
62 return this._container;
63 }
64 get isOpen() {
65 return this._isOpen;
66 }
67 init() {
68 this._container = this.createPopupDiv(this.position);
69 document.addEventListener('keyup', this.escFunction);
70 this._container.focus();
71 this._isOpen = true;
72 }
73 createPopupDiv(position) {
74 const result = window.document.createElement('div');
75 result.className = breadcrumbs_constants_1.Styles.BREADCRUMB_POPUP;
76 result.style.left = `${position.x}px`;
77 result.style.top = `${position.y}px`;
78 result.tabIndex = 0;
79 result.addEventListener('focusout', this.onFocusOut);
80 this.parent.appendChild(result);
81 return result;
82 }
83 dispose() {
84 if (!this.toDispose.disposed) {
85 this.onDidDisposeEmitter.fire();
86 this.toDispose.dispose();
87 this._container.remove();
88 this._isOpen = false;
89 document.removeEventListener('keyup', this.escFunction);
90 }
91 }
92};
93__decorate([
94 (0, inversify_1.inject)(react_renderer_1.RendererHost),
95 __metadata("design:type", Object)
96], BreadcrumbPopupContainer.prototype, "parent", void 0);
97__decorate([
98 (0, inversify_1.inject)(exports.BreadcrumbID),
99 __metadata("design:type", String)
100], BreadcrumbPopupContainer.prototype, "breadcrumbId", void 0);
101__decorate([
102 (0, inversify_1.inject)(context_menu_renderer_1.Coordinate),
103 __metadata("design:type", Object)
104], BreadcrumbPopupContainer.prototype, "position", void 0);
105__decorate([
106 (0, inversify_1.postConstruct)(),
107 __metadata("design:type", Function),
108 __metadata("design:paramtypes", []),
109 __metadata("design:returntype", void 0)
110], BreadcrumbPopupContainer.prototype, "init", null);
111BreadcrumbPopupContainer = __decorate([
112 (0, inversify_1.injectable)()
113], BreadcrumbPopupContainer);
114exports.BreadcrumbPopupContainer = BreadcrumbPopupContainer;
115//# sourceMappingURL=breadcrumb-popup-container.js.map
\No newline at end of file