1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.ContextMenuRenderer = exports.ContextMenuAccess = exports.coordinateFromAnchor = exports.Coordinate = void 0;
|
19 | const tslib_1 = require("tslib");
|
20 |
|
21 | const inversify_1 = require("inversify");
|
22 | const disposable_1 = require("../common/disposable");
|
23 | exports.Coordinate = Symbol('Coordinate');
|
24 | function coordinateFromAnchor(anchor) {
|
25 | const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor;
|
26 | return { x, y };
|
27 | }
|
28 | exports.coordinateFromAnchor = coordinateFromAnchor;
|
29 | class 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 | }
|
42 | exports.ContextMenuAccess = ContextMenuAccess;
|
43 | let ContextMenuRenderer = class ContextMenuRenderer {
|
44 | constructor() {
|
45 | this.toDisposeOnSetCurrent = new disposable_1.DisposableCollection();
|
46 | }
|
47 | |
48 |
|
49 |
|
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 | };
|
84 | ContextMenuRenderer = (0, tslib_1.__decorate)([
|
85 | (0, inversify_1.injectable)()
|
86 | ], ContextMenuRenderer);
|
87 | exports.ContextMenuRenderer = ContextMenuRenderer;
|
88 |
|
\ | No newline at end of file |