custom-electron-titlebar 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base/browser/browser.d.ts +26 -0
- package/dist/base/browser/browser.js +317 -0
- package/dist/base/browser/event.d.ts +12 -0
- package/dist/base/browser/event.js +215 -0
- package/dist/base/browser/keyboardEvent.d.ts +38 -0
- package/dist/base/browser/keyboardEvent.js +466 -0
- package/dist/base/browser/mouseEvent.d.ts +61 -0
- package/dist/base/browser/mouseEvent.js +327 -0
- package/dist/base/browser/touch.d.ts +39 -0
- package/dist/base/browser/touch.js +454 -0
- package/dist/base/common/arrays.d.ts +10 -0
- package/dist/base/common/arrays.js +210 -0
- package/dist/base/common/async.d.ts +35 -0
- package/dist/base/common/async.js +280 -0
- package/dist/base/common/charCode.d.ts +405 -0
- package/dist/base/common/charCode.js +9 -0
- package/dist/base/common/color.d.ts +159 -0
- package/dist/base/common/color.js +709 -0
- package/dist/base/common/decorators.d.ts +6 -0
- package/dist/base/common/decorators.js +300 -0
- package/dist/base/common/dom.d.ts +221 -0
- package/dist/base/common/dom.js +1478 -0
- package/dist/base/common/event.d.ts +213 -0
- package/dist/base/common/event.js +804 -0
- package/dist/base/common/iterator.d.ts +69 -0
- package/dist/base/common/iterator.js +381 -0
- package/dist/base/common/keyCodes.d.ts +478 -0
- package/dist/base/common/keyCodes.js +479 -0
- package/dist/base/common/lifecycle.d.ts +17 -0
- package/dist/base/common/lifecycle.js +258 -0
- package/dist/base/common/linkedList.d.ts +17 -0
- package/dist/base/common/linkedList.js +319 -0
- package/dist/base/common/platform.d.ts +33 -0
- package/dist/base/common/platform.js +302 -0
- package/dist/base/common/strings.d.ts +23 -0
- package/dist/base/common/strings.js +273 -0
- package/dist/consts.d.ts +49 -0
- package/dist/consts.js +303 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +211 -0
- package/dist/main/attach-titlebar-to-window.d.ts +3 -0
- package/dist/main/attach-titlebar-to-window.js +207 -0
- package/dist/main/index.d.ts +3 -0
- package/dist/main/index.js +202 -0
- package/dist/main/setup-titlebar.d.ts +2 -0
- package/dist/main/setup-titlebar.js +242 -0
- package/dist/menubar/index.d.ts +86 -0
- package/dist/menubar/index.js +1118 -0
- package/dist/menubar/menu/index.d.ts +46 -0
- package/dist/menubar/menu/index.js +556 -0
- package/dist/menubar/menu/item.d.ts +67 -0
- package/dist/menubar/menu/item.js +575 -0
- package/dist/menubar/menu/separator.d.ts +11 -0
- package/dist/menubar/menu/separator.js +213 -0
- package/dist/menubar/menu/submenu.d.ts +32 -0
- package/dist/menubar/menu/submenu.js +372 -0
- package/dist/menubar/menubar-options.d.ts +55 -0
- package/dist/menubar/menubar-options.js +9 -0
- package/dist/titlebar/index.d.ts +99 -0
- package/dist/titlebar/index.js +663 -0
- package/dist/titlebar/options.d.ts +84 -0
- package/dist/titlebar/options.js +9 -0
- package/dist/titlebar/themebar.d.ts +20 -0
- package/dist/titlebar/themebar.js +267 -0
- package/package.json +1 -1
|
@@ -0,0 +1,804 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* ---------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
6
|
+
*-------------------------------------------------------------------------------------------- */
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.Relay = exports.EventBufferer = exports.AsyncEmitter = exports.Emitter = exports.setGlobalLeakWarningThreshold = exports.Event = void 0;
|
|
11
|
+
const lifecycle_1 = require("../common/lifecycle");
|
|
12
|
+
const linkedList_1 = require("../common/linkedList");
|
|
13
|
+
var Event;
|
|
14
|
+
(function (Event) {
|
|
15
|
+
const _disposable = {
|
|
16
|
+
dispose() {}
|
|
17
|
+
};
|
|
18
|
+
Event.None = function () {
|
|
19
|
+
return _disposable;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Given an event, returns another event which only fires once.
|
|
23
|
+
*/
|
|
24
|
+
function once(event) {
|
|
25
|
+
return (listener, thisArgs = null, disposables) => {
|
|
26
|
+
// we need this, in case the event fires during the listener call
|
|
27
|
+
let didFire = false;
|
|
28
|
+
const result = event(e => {
|
|
29
|
+
if (didFire) {
|
|
30
|
+
return;
|
|
31
|
+
} else if (result) {
|
|
32
|
+
result.dispose();
|
|
33
|
+
} else {
|
|
34
|
+
didFire = true;
|
|
35
|
+
}
|
|
36
|
+
return listener.call(thisArgs, e);
|
|
37
|
+
}, null, disposables);
|
|
38
|
+
if (didFire) {
|
|
39
|
+
result.dispose();
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
Event.once = once;
|
|
45
|
+
/**
|
|
46
|
+
* Given an event and a `map` function, returns another event which maps each element
|
|
47
|
+
* throught the mapping function.
|
|
48
|
+
*/
|
|
49
|
+
function map(event, map) {
|
|
50
|
+
return (listener, thisArgs = null, disposables) => event(i => listener.call(thisArgs, map(i)), null, disposables);
|
|
51
|
+
}
|
|
52
|
+
Event.map = map;
|
|
53
|
+
/**
|
|
54
|
+
* Given an event and an `each` function, returns another identical event and calls
|
|
55
|
+
* the `each` function per each element.
|
|
56
|
+
*/
|
|
57
|
+
function forEach(event, each) {
|
|
58
|
+
return (listener, thisArgs = null, disposables) => event(i => {
|
|
59
|
+
each(i);
|
|
60
|
+
listener.call(thisArgs, i);
|
|
61
|
+
}, null, disposables);
|
|
62
|
+
}
|
|
63
|
+
Event.forEach = forEach;
|
|
64
|
+
function filter(event, filter) {
|
|
65
|
+
return (listener, thisArgs = null, disposables) => event(e => filter(e) && listener.call(thisArgs, e), null, disposables);
|
|
66
|
+
}
|
|
67
|
+
Event.filter = filter;
|
|
68
|
+
/**
|
|
69
|
+
* Given an event, returns the same event but typed as `Event<void>`.
|
|
70
|
+
*/
|
|
71
|
+
function signal(event) {
|
|
72
|
+
return event;
|
|
73
|
+
}
|
|
74
|
+
Event.signal = signal;
|
|
75
|
+
/**
|
|
76
|
+
* Given a collection of events, returns a single event which emits
|
|
77
|
+
* whenever any of the provided events emit.
|
|
78
|
+
*/
|
|
79
|
+
function any(...events) {
|
|
80
|
+
return (listener, thisArgs = null, disposables) => (0, _get__("lifecycle_1").combinedDisposable)(events.map(event => event(e => listener.call(thisArgs, e), null, disposables)));
|
|
81
|
+
}
|
|
82
|
+
Event.any = any;
|
|
83
|
+
/**
|
|
84
|
+
* Given an event and a `merge` function, returns another event which maps each element
|
|
85
|
+
* and the cummulative result throught the `merge` function. Similar to `map`, but with memory.
|
|
86
|
+
*/
|
|
87
|
+
function reduce(event, merge, initial) {
|
|
88
|
+
let output = initial;
|
|
89
|
+
return map(event, e => {
|
|
90
|
+
output = merge(output, e);
|
|
91
|
+
return output;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
Event.reduce = reduce;
|
|
95
|
+
function debounce(event, merge, delay = 100, leading = false, leakWarningThreshold) {
|
|
96
|
+
let subscription;
|
|
97
|
+
let output;
|
|
98
|
+
let handle;
|
|
99
|
+
let numDebouncedCalls = 0;
|
|
100
|
+
const emitter = new (_get__("Emitter"))({
|
|
101
|
+
leakWarningThreshold,
|
|
102
|
+
onFirstListenerAdd() {
|
|
103
|
+
subscription = event(cur => {
|
|
104
|
+
numDebouncedCalls++;
|
|
105
|
+
output = merge(output, cur);
|
|
106
|
+
if (leading && !handle) {
|
|
107
|
+
emitter.fire(output);
|
|
108
|
+
}
|
|
109
|
+
clearTimeout(handle);
|
|
110
|
+
handle = setTimeout(() => {
|
|
111
|
+
const _output = output;
|
|
112
|
+
output = undefined;
|
|
113
|
+
handle = undefined;
|
|
114
|
+
if (!leading || numDebouncedCalls > 1) {
|
|
115
|
+
emitter.fire(_output);
|
|
116
|
+
}
|
|
117
|
+
numDebouncedCalls = 0;
|
|
118
|
+
}, delay);
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
onLastListenerRemove() {
|
|
122
|
+
subscription.dispose();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return emitter.event;
|
|
126
|
+
}
|
|
127
|
+
Event.debounce = debounce;
|
|
128
|
+
/**
|
|
129
|
+
* Given an event, it returns another event which fires only once and as soon as
|
|
130
|
+
* the input event emits. The event data is the number of millis it took for the
|
|
131
|
+
* event to fire.
|
|
132
|
+
*/
|
|
133
|
+
function stopwatch(event) {
|
|
134
|
+
const start = new Date().getTime();
|
|
135
|
+
return map(once(event), _ => new Date().getTime() - start);
|
|
136
|
+
}
|
|
137
|
+
Event.stopwatch = stopwatch;
|
|
138
|
+
/**
|
|
139
|
+
* Given an event, it returns another event which fires only when the event
|
|
140
|
+
* element changes.
|
|
141
|
+
*/
|
|
142
|
+
function latch(event) {
|
|
143
|
+
let firstCall = true;
|
|
144
|
+
let cache;
|
|
145
|
+
return filter(event, value => {
|
|
146
|
+
const shouldEmit = firstCall || value !== cache;
|
|
147
|
+
firstCall = false;
|
|
148
|
+
cache = value;
|
|
149
|
+
return shouldEmit;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
Event.latch = latch;
|
|
153
|
+
/**
|
|
154
|
+
* Buffers the provided event until a first listener comes
|
|
155
|
+
* along, at which point fire all the events at once and
|
|
156
|
+
* pipe the event from then on.
|
|
157
|
+
*
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const emitter = new Emitter<number>();
|
|
160
|
+
* const event = emitter.event;
|
|
161
|
+
* const bufferedEvent = buffer(event);
|
|
162
|
+
*
|
|
163
|
+
* emitter.fire(1);
|
|
164
|
+
* emitter.fire(2);
|
|
165
|
+
* emitter.fire(3);
|
|
166
|
+
* // nothing...
|
|
167
|
+
*
|
|
168
|
+
* const listener = bufferedEvent(num => console.log(num));
|
|
169
|
+
* // 1, 2, 3
|
|
170
|
+
*
|
|
171
|
+
* emitter.fire(4);
|
|
172
|
+
* // 4
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
function buffer(event, nextTick = false, _buffer = []) {
|
|
176
|
+
let buffer = _buffer.slice();
|
|
177
|
+
let listener = event(e => {
|
|
178
|
+
if (buffer) {
|
|
179
|
+
buffer.push(e);
|
|
180
|
+
} else {
|
|
181
|
+
emitter.fire(e);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
const flush = () => {
|
|
185
|
+
if (buffer) {
|
|
186
|
+
buffer.forEach(e => emitter.fire(e));
|
|
187
|
+
}
|
|
188
|
+
buffer = null;
|
|
189
|
+
};
|
|
190
|
+
const emitter = new (_get__("Emitter"))({
|
|
191
|
+
onFirstListenerAdd() {
|
|
192
|
+
if (!listener) {
|
|
193
|
+
listener = event(e => emitter.fire(e));
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
onFirstListenerDidAdd() {
|
|
197
|
+
if (buffer) {
|
|
198
|
+
if (nextTick) {
|
|
199
|
+
setTimeout(flush);
|
|
200
|
+
} else {
|
|
201
|
+
flush();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
onLastListenerRemove() {
|
|
206
|
+
if (listener) {
|
|
207
|
+
listener.dispose();
|
|
208
|
+
}
|
|
209
|
+
listener = null;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
return emitter.event;
|
|
213
|
+
}
|
|
214
|
+
Event.buffer = buffer;
|
|
215
|
+
/**
|
|
216
|
+
* Similar to `buffer` but it buffers indefinitely and repeats
|
|
217
|
+
* the buffered events to every new listener.
|
|
218
|
+
*/
|
|
219
|
+
function echo(event, nextTick = false, buffer = []) {
|
|
220
|
+
buffer = buffer.slice();
|
|
221
|
+
event(e => {
|
|
222
|
+
buffer.push(e);
|
|
223
|
+
emitter.fire(e);
|
|
224
|
+
});
|
|
225
|
+
const flush = (listener, thisArgs) => buffer.forEach(e => listener.call(thisArgs, e));
|
|
226
|
+
const emitter = new (_get__("Emitter"))({
|
|
227
|
+
onListenerDidAdd(emitter, listener, thisArgs) {
|
|
228
|
+
if (nextTick) {
|
|
229
|
+
setTimeout(() => flush(listener, thisArgs));
|
|
230
|
+
} else {
|
|
231
|
+
flush(listener, thisArgs);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
return emitter.event;
|
|
236
|
+
}
|
|
237
|
+
Event.echo = echo;
|
|
238
|
+
class ChainableEvent {
|
|
239
|
+
get event() {
|
|
240
|
+
return this._event;
|
|
241
|
+
}
|
|
242
|
+
constructor(_event) {
|
|
243
|
+
this._event = _event;
|
|
244
|
+
}
|
|
245
|
+
map(fn) {
|
|
246
|
+
return new ChainableEvent(map(this._event, fn));
|
|
247
|
+
}
|
|
248
|
+
forEach(fn) {
|
|
249
|
+
return new ChainableEvent(forEach(this._event, fn));
|
|
250
|
+
}
|
|
251
|
+
filter(fn) {
|
|
252
|
+
return new ChainableEvent(filter(this._event, fn));
|
|
253
|
+
}
|
|
254
|
+
reduce(merge, initial) {
|
|
255
|
+
return new ChainableEvent(reduce(this._event, merge, initial));
|
|
256
|
+
}
|
|
257
|
+
latch() {
|
|
258
|
+
return new ChainableEvent(latch(this._event));
|
|
259
|
+
}
|
|
260
|
+
on(listener, thisArgs, disposables) {
|
|
261
|
+
return this._event(listener, thisArgs, disposables);
|
|
262
|
+
}
|
|
263
|
+
once(listener, thisArgs, disposables) {
|
|
264
|
+
return once(this._event)(listener, thisArgs, disposables);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function chain(event) {
|
|
268
|
+
return new ChainableEvent(event);
|
|
269
|
+
}
|
|
270
|
+
Event.chain = chain;
|
|
271
|
+
function fromNodeEventEmitter(emitter, eventName, map = id => id) {
|
|
272
|
+
const fn = (...args) => result.fire(map(...args));
|
|
273
|
+
const onFirstListenerAdd = () => emitter.on(eventName, fn);
|
|
274
|
+
const onLastListenerRemove = () => emitter.removeListener(eventName, fn);
|
|
275
|
+
const result = new (_get__("Emitter"))({
|
|
276
|
+
onFirstListenerAdd,
|
|
277
|
+
onLastListenerRemove
|
|
278
|
+
});
|
|
279
|
+
return result.event;
|
|
280
|
+
}
|
|
281
|
+
Event.fromNodeEventEmitter = fromNodeEventEmitter;
|
|
282
|
+
function fromPromise(promise) {
|
|
283
|
+
const emitter = new (_get__("Emitter"))();
|
|
284
|
+
let shouldEmit = false;
|
|
285
|
+
promise.then(undefined, () => null).then(() => {
|
|
286
|
+
if (!shouldEmit) {
|
|
287
|
+
setTimeout(() => emitter.fire(undefined), 0);
|
|
288
|
+
} else {
|
|
289
|
+
emitter.fire(undefined);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
shouldEmit = true;
|
|
293
|
+
return emitter.event;
|
|
294
|
+
}
|
|
295
|
+
Event.fromPromise = fromPromise;
|
|
296
|
+
function toPromise(event) {
|
|
297
|
+
// eslint-disable-next-line promise/param-names
|
|
298
|
+
return new Promise(c => once(event)(c));
|
|
299
|
+
}
|
|
300
|
+
Event.toPromise = toPromise;
|
|
301
|
+
})(_assign__("Event", exports.Event || (exports.Event = {})));
|
|
302
|
+
let _globalLeakWarningThreshold = -1;
|
|
303
|
+
function setGlobalLeakWarningThreshold(n) {
|
|
304
|
+
const oldValue = _get__("_globalLeakWarningThreshold");
|
|
305
|
+
_assign__("_globalLeakWarningThreshold", n);
|
|
306
|
+
return {
|
|
307
|
+
dispose() {
|
|
308
|
+
_assign__("_globalLeakWarningThreshold", oldValue);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
exports.setGlobalLeakWarningThreshold = _get__("setGlobalLeakWarningThreshold");
|
|
313
|
+
class LeakageMonitor {
|
|
314
|
+
constructor(customThreshold, name = Math.random().toString(18).slice(2, 5)) {
|
|
315
|
+
this.customThreshold = customThreshold;
|
|
316
|
+
this.name = name;
|
|
317
|
+
this._warnCountdown = 0;
|
|
318
|
+
}
|
|
319
|
+
dispose() {
|
|
320
|
+
if (this._stacks) {
|
|
321
|
+
this._stacks.clear();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
check(listenerCount) {
|
|
325
|
+
let threshold = _get__("_globalLeakWarningThreshold");
|
|
326
|
+
if (typeof this.customThreshold === 'number') {
|
|
327
|
+
threshold = this.customThreshold;
|
|
328
|
+
}
|
|
329
|
+
if (threshold <= 0 || listenerCount < threshold) {
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
if (!this._stacks) {
|
|
333
|
+
this._stacks = new Map();
|
|
334
|
+
}
|
|
335
|
+
const stack = new Error().stack.split('\n').slice(3).join('\n');
|
|
336
|
+
const count = this._stacks.get(stack) || 0;
|
|
337
|
+
this._stacks.set(stack, count + 1);
|
|
338
|
+
this._warnCountdown -= 1;
|
|
339
|
+
if (this._warnCountdown <= 0) {
|
|
340
|
+
// only warn on first exceed and then every time the limit
|
|
341
|
+
// is exceeded by 50% again
|
|
342
|
+
this._warnCountdown = threshold * 0.5;
|
|
343
|
+
// find most frequent listener and print warning
|
|
344
|
+
let topStack;
|
|
345
|
+
let topCount = 0;
|
|
346
|
+
this._stacks.forEach((count, stack) => {
|
|
347
|
+
if (!topStack || topCount < count) {
|
|
348
|
+
topStack = stack;
|
|
349
|
+
topCount = count;
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
console.warn(`[${this.name}] potential listener LEAK detected, having ${listenerCount} listeners already. MOST frequent listener (${topCount}):`);
|
|
353
|
+
console.warn(topStack);
|
|
354
|
+
}
|
|
355
|
+
return () => {
|
|
356
|
+
const count = this._stacks.get(stack) || 0;
|
|
357
|
+
this._stacks.set(stack, count - 1);
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* The Emitter can be used to expose an Event to the public
|
|
363
|
+
* to fire it from the insides.
|
|
364
|
+
* Sample:
|
|
365
|
+
class Document {
|
|
366
|
+
|
|
367
|
+
private _onDidChange = new Emitter<(value:string)=>any>();
|
|
368
|
+
|
|
369
|
+
public onDidChange = this._onDidChange.event;
|
|
370
|
+
|
|
371
|
+
// getter-style
|
|
372
|
+
// get onDidChange(): Event<(value:string)=>any> {
|
|
373
|
+
// return this._onDidChange.event;
|
|
374
|
+
// }
|
|
375
|
+
|
|
376
|
+
private _doIt() {
|
|
377
|
+
//...
|
|
378
|
+
this._onDidChange.fire(value);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
*/
|
|
382
|
+
class Emitter {
|
|
383
|
+
constructor(options) {
|
|
384
|
+
this._disposed = false;
|
|
385
|
+
this._options = options;
|
|
386
|
+
this._leakageMon = _get__("_globalLeakWarningThreshold") > 0 ? new (_get__("LeakageMonitor"))(this._options && this._options.leakWarningThreshold) : undefined;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* For the public to allow to subscribe
|
|
390
|
+
* to events from this Emitter
|
|
391
|
+
*/
|
|
392
|
+
get event() {
|
|
393
|
+
if (!this._event) {
|
|
394
|
+
this._event = (listener, thisArgs, disposables) => {
|
|
395
|
+
if (!this._listeners) {
|
|
396
|
+
this._listeners = new (_get__("linkedList_1").LinkedList)();
|
|
397
|
+
}
|
|
398
|
+
const firstListener = this._listeners.isEmpty();
|
|
399
|
+
if (firstListener && this._options && this._options.onFirstListenerAdd) {
|
|
400
|
+
this._options.onFirstListenerAdd(this);
|
|
401
|
+
}
|
|
402
|
+
const remove = this._listeners.push(!thisArgs ? listener : [listener, thisArgs]);
|
|
403
|
+
if (firstListener && this._options && this._options.onFirstListenerDidAdd) {
|
|
404
|
+
this._options.onFirstListenerDidAdd(this);
|
|
405
|
+
}
|
|
406
|
+
if (this._options && this._options.onListenerDidAdd) {
|
|
407
|
+
this._options.onListenerDidAdd(this, listener, thisArgs);
|
|
408
|
+
}
|
|
409
|
+
// check and record this emitter for potential leakage
|
|
410
|
+
let removeMonitor;
|
|
411
|
+
if (this._leakageMon) {
|
|
412
|
+
removeMonitor = this._leakageMon.check(this._listeners.size);
|
|
413
|
+
}
|
|
414
|
+
const result = {
|
|
415
|
+
dispose: () => {
|
|
416
|
+
if (removeMonitor) {
|
|
417
|
+
removeMonitor();
|
|
418
|
+
}
|
|
419
|
+
result.dispose = _get__("Emitter")._noop;
|
|
420
|
+
if (!this._disposed) {
|
|
421
|
+
remove();
|
|
422
|
+
if (this._options && this._options.onLastListenerRemove) {
|
|
423
|
+
const hasListeners = this._listeners && !this._listeners.isEmpty();
|
|
424
|
+
if (!hasListeners) {
|
|
425
|
+
this._options.onLastListenerRemove(this);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
if (Array.isArray(disposables)) {
|
|
432
|
+
disposables.push(result);
|
|
433
|
+
}
|
|
434
|
+
return result;
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
return this._event;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* To be kept private to fire an event to
|
|
441
|
+
* subscribers
|
|
442
|
+
*/
|
|
443
|
+
fire(event) {
|
|
444
|
+
if (this._listeners) {
|
|
445
|
+
// put all [listener,event]-pairs into delivery queue
|
|
446
|
+
// then emit all event. an inner/nested event might be
|
|
447
|
+
// the driver of this
|
|
448
|
+
if (!this._deliveryQueue) {
|
|
449
|
+
this._deliveryQueue = [];
|
|
450
|
+
}
|
|
451
|
+
for (let iter = this._listeners.iterator(), e = iter.next(); !e.done; e = iter.next()) {
|
|
452
|
+
this._deliveryQueue.push([e.value, event]);
|
|
453
|
+
}
|
|
454
|
+
while (this._deliveryQueue.length > 0) {
|
|
455
|
+
const [listener, event] = this._deliveryQueue.shift();
|
|
456
|
+
try {
|
|
457
|
+
if (typeof listener === 'function') {
|
|
458
|
+
// eslint-disable-next-line no-useless-call
|
|
459
|
+
listener.call(undefined, event);
|
|
460
|
+
} else {
|
|
461
|
+
listener[0].call(listener[1], event);
|
|
462
|
+
}
|
|
463
|
+
} catch (e) {
|
|
464
|
+
console.error(e);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
dispose() {
|
|
470
|
+
if (this._listeners) {
|
|
471
|
+
this._listeners = undefined;
|
|
472
|
+
}
|
|
473
|
+
if (this._deliveryQueue) {
|
|
474
|
+
this._deliveryQueue.length = 0;
|
|
475
|
+
}
|
|
476
|
+
if (this._leakageMon) {
|
|
477
|
+
this._leakageMon.dispose();
|
|
478
|
+
}
|
|
479
|
+
this._disposed = true;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
_get__("Emitter")._noop = function () {};
|
|
483
|
+
exports.Emitter = _get__("Emitter");
|
|
484
|
+
class AsyncEmitter extends _get__("Emitter") {
|
|
485
|
+
async fireAsync(eventFn) {
|
|
486
|
+
if (!this._listeners) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
// put all [listener,event]-pairs into delivery queue
|
|
490
|
+
// then emit all event. an inner/nested event might be
|
|
491
|
+
// the driver of this
|
|
492
|
+
if (!this._asyncDeliveryQueue) {
|
|
493
|
+
this._asyncDeliveryQueue = [];
|
|
494
|
+
}
|
|
495
|
+
for (let iter = this._listeners.iterator(), e = iter.next(); !e.done; e = iter.next()) {
|
|
496
|
+
const thenables = [];
|
|
497
|
+
this._asyncDeliveryQueue.push([e.value, eventFn(thenables, typeof e.value === 'function' ? e.value : e.value[0]), thenables]);
|
|
498
|
+
}
|
|
499
|
+
while (this._asyncDeliveryQueue.length > 0) {
|
|
500
|
+
const [listener, event, thenables] = this._asyncDeliveryQueue.shift();
|
|
501
|
+
try {
|
|
502
|
+
if (typeof listener === 'function') {
|
|
503
|
+
// eslint-disable-next-line no-useless-call
|
|
504
|
+
listener.call(undefined, event);
|
|
505
|
+
} else {
|
|
506
|
+
listener[0].call(listener[1], event);
|
|
507
|
+
}
|
|
508
|
+
} catch (e) {
|
|
509
|
+
console.error(e);
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
// freeze thenables-collection to enforce sync-calls to
|
|
513
|
+
// wait until and then wait for all thenables to resolve
|
|
514
|
+
Object.freeze(thenables);
|
|
515
|
+
await Promise.all(thenables);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
exports.AsyncEmitter = _get__("AsyncEmitter");
|
|
520
|
+
/**
|
|
521
|
+
* The EventBufferer is useful in situations in which you want
|
|
522
|
+
* to delay firing your events during some code.
|
|
523
|
+
* You can wrap that code and be sure that the event will not
|
|
524
|
+
* be fired during that wrap.
|
|
525
|
+
*
|
|
526
|
+
* ```
|
|
527
|
+
* const emitter: Emitter;
|
|
528
|
+
* const delayer = new EventDelayer();
|
|
529
|
+
* const delayedEvent = delayer.wrapEvent(emitter.event);
|
|
530
|
+
*
|
|
531
|
+
* delayedEvent(console.log);
|
|
532
|
+
*
|
|
533
|
+
* delayer.bufferEvents(() => {
|
|
534
|
+
* emitter.fire(); // event will not be fired yet
|
|
535
|
+
* });
|
|
536
|
+
*
|
|
537
|
+
* // event will only be fired at this point
|
|
538
|
+
* ```
|
|
539
|
+
*/
|
|
540
|
+
class EventBufferer {
|
|
541
|
+
constructor() {
|
|
542
|
+
this.buffers = [];
|
|
543
|
+
}
|
|
544
|
+
wrapEvent(event) {
|
|
545
|
+
return (listener, thisArgs, disposables) => {
|
|
546
|
+
return event(i => {
|
|
547
|
+
const buffer = this.buffers[this.buffers.length - 1];
|
|
548
|
+
if (buffer) {
|
|
549
|
+
buffer.push(() => listener.call(thisArgs, i));
|
|
550
|
+
} else {
|
|
551
|
+
listener.call(thisArgs, i);
|
|
552
|
+
}
|
|
553
|
+
}, undefined, disposables);
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
bufferEvents(fn) {
|
|
557
|
+
const buffer = [];
|
|
558
|
+
this.buffers.push(buffer);
|
|
559
|
+
const r = fn();
|
|
560
|
+
this.buffers.pop();
|
|
561
|
+
buffer.forEach(flush => flush());
|
|
562
|
+
return r;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
exports.EventBufferer = _get__("EventBufferer");
|
|
566
|
+
/**
|
|
567
|
+
* A Relay is an event forwarder which functions as a replugabble event pipe.
|
|
568
|
+
* Once created, you can connect an input event to it and it will simply forward
|
|
569
|
+
* events from that input event through its own `event` property. The `input`
|
|
570
|
+
* can be changed at any point in time.
|
|
571
|
+
*/
|
|
572
|
+
class Relay {
|
|
573
|
+
constructor() {
|
|
574
|
+
this.listening = false;
|
|
575
|
+
this.inputEvent = _get__("Event").None;
|
|
576
|
+
this.inputEventListener = _get__("lifecycle_1").Disposable.None;
|
|
577
|
+
this.emitter = new (_get__("Emitter"))({
|
|
578
|
+
onFirstListenerDidAdd: () => {
|
|
579
|
+
this.listening = true;
|
|
580
|
+
this.inputEventListener = this.inputEvent(this.emitter.fire, this.emitter);
|
|
581
|
+
},
|
|
582
|
+
onLastListenerRemove: () => {
|
|
583
|
+
this.listening = false;
|
|
584
|
+
this.inputEventListener.dispose();
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
this.event = this.emitter.event;
|
|
588
|
+
}
|
|
589
|
+
// eslint-disable-next-line accessor-pairs
|
|
590
|
+
set input(event) {
|
|
591
|
+
this.inputEvent = event;
|
|
592
|
+
if (this.listening) {
|
|
593
|
+
this.inputEventListener.dispose();
|
|
594
|
+
this.inputEventListener = event(this.emitter.fire, this.emitter);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
dispose() {
|
|
598
|
+
this.inputEventListener.dispose();
|
|
599
|
+
this.emitter.dispose();
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
exports.Relay = _get__("Relay");
|
|
603
|
+
function _getGlobalObject() {
|
|
604
|
+
try {
|
|
605
|
+
if (!!global) {
|
|
606
|
+
return global;
|
|
607
|
+
}
|
|
608
|
+
} catch (e) {
|
|
609
|
+
try {
|
|
610
|
+
if (!!window) {
|
|
611
|
+
return window;
|
|
612
|
+
}
|
|
613
|
+
} catch (e) {
|
|
614
|
+
return this;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
;
|
|
619
|
+
var _RewireModuleId__ = null;
|
|
620
|
+
function _getRewireModuleId__() {
|
|
621
|
+
if (_RewireModuleId__ === null) {
|
|
622
|
+
let globalVariable = _getGlobalObject();
|
|
623
|
+
if (!globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__) {
|
|
624
|
+
globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__ = 0;
|
|
625
|
+
}
|
|
626
|
+
_RewireModuleId__ = __$$GLOBAL_REWIRE_NEXT_MODULE_ID__++;
|
|
627
|
+
}
|
|
628
|
+
return _RewireModuleId__;
|
|
629
|
+
}
|
|
630
|
+
function _getRewireRegistry__() {
|
|
631
|
+
let theGlobalVariable = _getGlobalObject();
|
|
632
|
+
if (!theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__) {
|
|
633
|
+
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
|
|
634
|
+
}
|
|
635
|
+
return theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__;
|
|
636
|
+
}
|
|
637
|
+
function _getRewiredData__() {
|
|
638
|
+
let moduleId = _getRewireModuleId__();
|
|
639
|
+
let registry = _getRewireRegistry__();
|
|
640
|
+
let rewireData = registry[moduleId];
|
|
641
|
+
if (!rewireData) {
|
|
642
|
+
registry[moduleId] = Object.create(null);
|
|
643
|
+
rewireData = registry[moduleId];
|
|
644
|
+
}
|
|
645
|
+
return rewireData;
|
|
646
|
+
}
|
|
647
|
+
(function registerResetAll() {
|
|
648
|
+
let theGlobalVariable = _getGlobalObject();
|
|
649
|
+
if (!theGlobalVariable['__rewire_reset_all__']) {
|
|
650
|
+
theGlobalVariable['__rewire_reset_all__'] = function () {
|
|
651
|
+
theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
})();
|
|
655
|
+
var INTENTIONAL_UNDEFINED = '__INTENTIONAL_UNDEFINED__';
|
|
656
|
+
let _RewireAPI__ = {};
|
|
657
|
+
(function () {
|
|
658
|
+
function addPropertyToAPIObject(name, value) {
|
|
659
|
+
Object.defineProperty(_RewireAPI__, name, {
|
|
660
|
+
value: value,
|
|
661
|
+
enumerable: false,
|
|
662
|
+
configurable: true
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
addPropertyToAPIObject('__get__', _get__);
|
|
666
|
+
addPropertyToAPIObject('__GetDependency__', _get__);
|
|
667
|
+
addPropertyToAPIObject('__Rewire__', _set__);
|
|
668
|
+
addPropertyToAPIObject('__set__', _set__);
|
|
669
|
+
addPropertyToAPIObject('__reset__', _reset__);
|
|
670
|
+
addPropertyToAPIObject('__ResetDependency__', _reset__);
|
|
671
|
+
addPropertyToAPIObject('__with__', _with__);
|
|
672
|
+
})();
|
|
673
|
+
function _get__(variableName) {
|
|
674
|
+
let rewireData = _getRewiredData__();
|
|
675
|
+
if (rewireData[variableName] === undefined) {
|
|
676
|
+
return _get_original__(variableName);
|
|
677
|
+
} else {
|
|
678
|
+
var value = rewireData[variableName];
|
|
679
|
+
if (value === INTENTIONAL_UNDEFINED) {
|
|
680
|
+
return undefined;
|
|
681
|
+
} else {
|
|
682
|
+
return value;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function _get_original__(variableName) {
|
|
687
|
+
switch (variableName) {
|
|
688
|
+
case "lifecycle_1":
|
|
689
|
+
return lifecycle_1;
|
|
690
|
+
case "Emitter":
|
|
691
|
+
return Emitter;
|
|
692
|
+
case "Event":
|
|
693
|
+
return Event;
|
|
694
|
+
case "_globalLeakWarningThreshold":
|
|
695
|
+
return _globalLeakWarningThreshold;
|
|
696
|
+
case "setGlobalLeakWarningThreshold":
|
|
697
|
+
return setGlobalLeakWarningThreshold;
|
|
698
|
+
case "LeakageMonitor":
|
|
699
|
+
return LeakageMonitor;
|
|
700
|
+
case "linkedList_1":
|
|
701
|
+
return linkedList_1;
|
|
702
|
+
case "AsyncEmitter":
|
|
703
|
+
return AsyncEmitter;
|
|
704
|
+
case "EventBufferer":
|
|
705
|
+
return EventBufferer;
|
|
706
|
+
case "Relay":
|
|
707
|
+
return Relay;
|
|
708
|
+
}
|
|
709
|
+
return undefined;
|
|
710
|
+
}
|
|
711
|
+
function _assign__(variableName, value) {
|
|
712
|
+
let rewireData = _getRewiredData__();
|
|
713
|
+
if (rewireData[variableName] === undefined) {
|
|
714
|
+
return _set_original__(variableName, value);
|
|
715
|
+
} else {
|
|
716
|
+
return rewireData[variableName] = value;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
function _set_original__(variableName, _value) {
|
|
720
|
+
switch (variableName) {
|
|
721
|
+
case "Event":
|
|
722
|
+
return Event = _value;
|
|
723
|
+
case "_globalLeakWarningThreshold":
|
|
724
|
+
return _globalLeakWarningThreshold = _value;
|
|
725
|
+
}
|
|
726
|
+
return undefined;
|
|
727
|
+
}
|
|
728
|
+
function _update_operation__(operation, variableName, prefix) {
|
|
729
|
+
var oldValue = _get__(variableName);
|
|
730
|
+
var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;
|
|
731
|
+
_assign__(variableName, newValue);
|
|
732
|
+
return prefix ? newValue : oldValue;
|
|
733
|
+
}
|
|
734
|
+
function _set__(variableName, value) {
|
|
735
|
+
let rewireData = _getRewiredData__();
|
|
736
|
+
if (typeof variableName === 'object') {
|
|
737
|
+
Object.keys(variableName).forEach(function (name) {
|
|
738
|
+
rewireData[name] = variableName[name];
|
|
739
|
+
});
|
|
740
|
+
return function () {
|
|
741
|
+
Object.keys(variableName).forEach(function (name) {
|
|
742
|
+
_reset__(variableName);
|
|
743
|
+
});
|
|
744
|
+
};
|
|
745
|
+
} else {
|
|
746
|
+
if (value === undefined) {
|
|
747
|
+
rewireData[variableName] = INTENTIONAL_UNDEFINED;
|
|
748
|
+
} else {
|
|
749
|
+
rewireData[variableName] = value;
|
|
750
|
+
}
|
|
751
|
+
return function () {
|
|
752
|
+
_reset__(variableName);
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function _reset__(variableName) {
|
|
757
|
+
let rewireData = _getRewiredData__();
|
|
758
|
+
delete rewireData[variableName];
|
|
759
|
+
if (Object.keys(rewireData).length == 0) {
|
|
760
|
+
delete _getRewireRegistry__()[_getRewireModuleId__];
|
|
761
|
+
}
|
|
762
|
+
;
|
|
763
|
+
}
|
|
764
|
+
function _with__(object) {
|
|
765
|
+
let rewireData = _getRewiredData__();
|
|
766
|
+
var rewiredVariableNames = Object.keys(object);
|
|
767
|
+
var previousValues = {};
|
|
768
|
+
function reset() {
|
|
769
|
+
rewiredVariableNames.forEach(function (variableName) {
|
|
770
|
+
rewireData[variableName] = previousValues[variableName];
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
return function (callback) {
|
|
774
|
+
rewiredVariableNames.forEach(function (variableName) {
|
|
775
|
+
previousValues[variableName] = rewireData[variableName];
|
|
776
|
+
rewireData[variableName] = object[variableName];
|
|
777
|
+
});
|
|
778
|
+
let result = callback();
|
|
779
|
+
if (!!result && typeof result.then == 'function') {
|
|
780
|
+
result.then(reset).catch(reset);
|
|
781
|
+
} else {
|
|
782
|
+
reset();
|
|
783
|
+
}
|
|
784
|
+
return result;
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
let _typeOfOriginalExport = typeof module.exports;
|
|
788
|
+
function addNonEnumerableProperty(name, value) {
|
|
789
|
+
Object.defineProperty(module.exports, name, {
|
|
790
|
+
value: value,
|
|
791
|
+
enumerable: false,
|
|
792
|
+
configurable: true
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
if ((_typeOfOriginalExport === 'object' || _typeOfOriginalExport === 'function') && Object.isExtensible(module.exports)) {
|
|
796
|
+
addNonEnumerableProperty('__get__', _get__);
|
|
797
|
+
addNonEnumerableProperty('__GetDependency__', _get__);
|
|
798
|
+
addNonEnumerableProperty('__Rewire__', _set__);
|
|
799
|
+
addNonEnumerableProperty('__set__', _set__);
|
|
800
|
+
addNonEnumerableProperty('__reset__', _reset__);
|
|
801
|
+
addNonEnumerableProperty('__ResetDependency__', _reset__);
|
|
802
|
+
addNonEnumerableProperty('__with__', _with__);
|
|
803
|
+
addNonEnumerableProperty('__RewireAPI__', _RewireAPI__);
|
|
804
|
+
}
|