UNPKG

3.25 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 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.ContextMenuRenderer = exports.ContextMenuAccess = exports.coordinateFromAnchor = exports.Coordinate = void 0;
19const tslib_1 = require("tslib");
20/* eslint-disable @typescript-eslint/no-explicit-any */
21const inversify_1 = require("inversify");
22const disposable_1 = require("../common/disposable");
23exports.Coordinate = Symbol('Coordinate');
24function coordinateFromAnchor(anchor) {
25 const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor;
26 return { x, y };
27}
28exports.coordinateFromAnchor = coordinateFromAnchor;
29class ContextMenuAccess {
30 constructor(toClose) {
31 this.toDispose = new disposable_1.DisposableCollection();
32 this.onDispose = this.toDispose.onDispose;
33 this.toDispose.push(toClose);
34 }
35 get disposed() {
36 return this.toDispose.disposed;
37 }
38 dispose() {
39 this.toDispose.dispose();
40 }
41}
42exports.ContextMenuAccess = ContextMenuAccess;
43let ContextMenuRenderer = class ContextMenuRenderer {
44 constructor() {
45 this.toDisposeOnSetCurrent = new disposable_1.DisposableCollection();
46 }
47 /**
48 * Currently opened context menu.
49 * Rendering a new context menu will close the current.
50 */
51 get current() {
52 return this._current;
53 }
54 setCurrent(current) {
55 if (this._current === current) {
56 return;
57 }
58 this.toDisposeOnSetCurrent.dispose();
59 this._current = current;
60 if (current) {
61 this.toDisposeOnSetCurrent.push(current.onDispose(() => {
62 this._current = undefined;
63 }));
64 this.toDisposeOnSetCurrent.push(current);
65 }
66 }
67 render(options) {
68 const resolvedOptions = this.resolve(options);
69 const access = this.doRender(resolvedOptions);
70 this.setCurrent(access);
71 return access;
72 }
73 resolve(options) {
74 const args = options.args ? options.args.slice() : [];
75 if (options.includeAnchorArg !== false) {
76 args.push(options.anchor);
77 }
78 return {
79 ...options,
80 args
81 };
82 }
83};
84ContextMenuRenderer = (0, tslib_1.__decorate)([
85 (0, inversify_1.injectable)()
86], ContextMenuRenderer);
87exports.ContextMenuRenderer = ContextMenuRenderer;
88//# sourceMappingURL=context-menu-renderer.js.map
\No newline at end of file