1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __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 | };
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | exports.ContextMenuRenderer = exports.ContextMenuAccess = exports.coordinateFromAnchor = exports.toAnchor = exports.Coordinate = void 0;
|
25 |
|
26 | const inversify_1 = require("inversify");
|
27 | const disposable_1 = require("../common/disposable");
|
28 | exports.Coordinate = Symbol('Coordinate');
|
29 | function toAnchor(anchor) {
|
30 | return anchor instanceof HTMLElement ? { x: anchor.offsetLeft, y: anchor.offsetTop } : anchor;
|
31 | }
|
32 | exports.toAnchor = toAnchor;
|
33 | function coordinateFromAnchor(anchor) {
|
34 | const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor;
|
35 | return { x, y };
|
36 | }
|
37 | exports.coordinateFromAnchor = coordinateFromAnchor;
|
38 | class ContextMenuAccess {
|
39 | constructor(toClose) {
|
40 | this.toDispose = new disposable_1.DisposableCollection();
|
41 | this.onDispose = this.toDispose.onDispose;
|
42 | this.toDispose.push(toClose);
|
43 | }
|
44 | get disposed() {
|
45 | return this.toDispose.disposed;
|
46 | }
|
47 | dispose() {
|
48 | this.toDispose.dispose();
|
49 | }
|
50 | }
|
51 | exports.ContextMenuAccess = ContextMenuAccess;
|
52 | let ContextMenuRenderer = class ContextMenuRenderer {
|
53 | constructor() {
|
54 | this.toDisposeOnSetCurrent = new disposable_1.DisposableCollection();
|
55 | }
|
56 | |
57 |
|
58 |
|
59 |
|
60 | get current() {
|
61 | return this._current;
|
62 | }
|
63 | setCurrent(current) {
|
64 | if (this._current === current) {
|
65 | return;
|
66 | }
|
67 | this.toDisposeOnSetCurrent.dispose();
|
68 | this._current = current;
|
69 | if (current) {
|
70 | this.toDisposeOnSetCurrent.push(current.onDispose(() => {
|
71 | this._current = undefined;
|
72 | }));
|
73 | this.toDisposeOnSetCurrent.push(current);
|
74 | }
|
75 | }
|
76 | render(options) {
|
77 | const resolvedOptions = this.resolve(options);
|
78 | const access = this.doRender(resolvedOptions);
|
79 | this.setCurrent(access);
|
80 | return access;
|
81 | }
|
82 | resolve(options) {
|
83 | const args = options.args ? options.args.slice() : [];
|
84 | if (options.includeAnchorArg !== false) {
|
85 | args.push(options.anchor);
|
86 | }
|
87 | return {
|
88 | ...options,
|
89 | args
|
90 | };
|
91 | }
|
92 | };
|
93 | ContextMenuRenderer = __decorate([
|
94 | (0, inversify_1.injectable)()
|
95 | ], ContextMenuRenderer);
|
96 | exports.ContextMenuRenderer = ContextMenuRenderer;
|
97 |
|
\ | No newline at end of file |