custom-electron-titlebar 3.2.5 → 3.2.9

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.
Files changed (175) hide show
  1. package/.vscode/launch.json +49 -0
  2. package/.vscode/tasks.json +34 -0
  3. package/README.md +15 -24
  4. package/_config.yml +1 -0
  5. package/{lib → build}/browser/browser.d.ts +0 -0
  6. package/{lib → build}/browser/browser.js +1 -0
  7. package/build/browser/browser.js.map +1 -0
  8. package/{lib → build}/browser/event.d.ts +0 -0
  9. package/{lib → build}/browser/event.js +3 -1
  10. package/build/browser/event.js.map +1 -0
  11. package/{lib → build}/browser/iframe.d.ts +0 -0
  12. package/{lib/base → build}/browser/iframe.js +1 -0
  13. package/build/browser/iframe.js.map +1 -0
  14. package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
  15. package/{lib → build}/browser/keyboardEvent.js +1 -0
  16. package/build/browser/keyboardEvent.js.map +1 -0
  17. package/{lib → build}/browser/mouseEvent.d.ts +0 -0
  18. package/{lib → build}/browser/mouseEvent.js +1 -0
  19. package/build/browser/mouseEvent.js.map +1 -0
  20. package/{lib → build}/common/arrays.d.ts +0 -0
  21. package/{lib → build}/common/arrays.js +1 -0
  22. package/build/common/arrays.js.map +1 -0
  23. package/{lib → build}/common/async.d.ts +0 -0
  24. package/{lib → build}/common/async.js +1 -0
  25. package/build/common/async.js.map +1 -0
  26. package/{lib → build}/common/charCode.d.ts +0 -0
  27. package/{lib/base → build}/common/charCode.js +1 -0
  28. package/build/common/charCode.js.map +1 -0
  29. package/{lib → build}/common/color.d.ts +0 -0
  30. package/{lib → build}/common/color.js +1 -0
  31. package/build/common/color.js.map +1 -0
  32. package/{lib → build}/common/dom.d.ts +0 -0
  33. package/{lib → build}/common/dom.js +17 -14
  34. package/build/common/dom.js.map +1 -0
  35. package/{lib → build}/common/event.d.ts +0 -0
  36. package/{lib → build}/common/event.js +2 -1
  37. package/build/common/event.js.map +1 -0
  38. package/{lib → build}/common/iterator.d.ts +0 -0
  39. package/{lib → build}/common/iterator.js +1 -0
  40. package/build/common/iterator.js.map +1 -0
  41. package/{lib → build}/common/keyCodes.d.ts +0 -0
  42. package/{lib → build}/common/keyCodes.js +1 -0
  43. package/build/common/keyCodes.js.map +1 -0
  44. package/{lib → build}/common/lifecycle.d.ts +0 -0
  45. package/{lib → build}/common/lifecycle.js +1 -0
  46. package/build/common/lifecycle.js.map +1 -0
  47. package/{lib → build}/common/linkedList.d.ts +0 -0
  48. package/{lib → build}/common/linkedList.js +1 -0
  49. package/build/common/linkedList.js.map +1 -0
  50. package/{lib → build}/common/platform.d.ts +0 -0
  51. package/{lib → build}/common/platform.js +1 -0
  52. package/build/common/platform.js.map +1 -0
  53. package/{lib → build}/index.d.ts +0 -0
  54. package/{lib → build}/index.js +1 -0
  55. package/build/index.js.map +1 -0
  56. package/{lib → build}/menu/menu.d.ts +0 -0
  57. package/{lib → build}/menu/menu.js +39 -38
  58. package/build/menu/menu.js.map +1 -0
  59. package/{lib → build}/menu/menuitem.d.ts +10 -2
  60. package/{lib → build}/menu/menuitem.js +71 -29
  61. package/build/menu/menuitem.js.map +1 -0
  62. package/{lib → build}/menubar.d.ts +0 -0
  63. package/{lib → build}/menubar.js +38 -34
  64. package/build/menubar.js.map +1 -0
  65. package/{lib → build}/themebar.d.ts +0 -0
  66. package/{lib → build}/themebar.js +31 -2
  67. package/build/themebar.js.map +1 -0
  68. package/{lib → build}/titlebar.d.ts +0 -0
  69. package/{lib → build}/titlebar.js +72 -59
  70. package/build/titlebar.js.map +1 -0
  71. package/package.json +13 -7
  72. package/lib/base/browser/browser.d.ts +0 -25
  73. package/lib/base/browser/browser.js +0 -117
  74. package/lib/base/browser/canIUse.d.ts +0 -18
  75. package/lib/base/browser/canIUse.js +0 -63
  76. package/lib/base/browser/dom.d.ts +0 -230
  77. package/lib/base/browser/dom.js +0 -1080
  78. package/lib/base/browser/event.d.ts +0 -12
  79. package/lib/base/browser/event.js +0 -28
  80. package/lib/base/browser/iframe.d.ts +0 -33
  81. package/lib/base/browser/keyboardEvent.d.ts +0 -40
  82. package/lib/base/browser/keyboardEvent.js +0 -256
  83. package/lib/base/browser/mouseEvent.d.ts +0 -69
  84. package/lib/base/browser/mouseEvent.js +0 -146
  85. package/lib/base/common/arrays.d.ts +0 -149
  86. package/lib/base/common/arrays.js +0 -549
  87. package/lib/base/common/async.d.ts +0 -259
  88. package/lib/base/common/async.js +0 -728
  89. package/lib/base/common/cancellation.d.ts +0 -29
  90. package/lib/base/common/cancellation.js +0 -114
  91. package/lib/base/common/charCode.d.ts +0 -415
  92. package/lib/base/common/color.d.ts +0 -163
  93. package/lib/base/common/color.js +0 -495
  94. package/lib/base/common/errors.d.ts +0 -65
  95. package/lib/base/common/errors.js +0 -164
  96. package/lib/base/common/event.d.ts +0 -248
  97. package/lib/base/common/event.js +0 -703
  98. package/lib/base/common/functional.d.ts +0 -1
  99. package/lib/base/common/functional.js +0 -21
  100. package/lib/base/common/iterator.d.ts +0 -16
  101. package/lib/base/common/iterator.js +0 -82
  102. package/lib/base/common/keyCodes.d.ts +0 -268
  103. package/lib/base/common/keyCodes.js +0 -292
  104. package/lib/base/common/lifecycle.d.ts +0 -67
  105. package/lib/base/common/lifecycle.js +0 -234
  106. package/lib/base/common/linkedList.d.ts +0 -16
  107. package/lib/base/common/linkedList.js +0 -128
  108. package/lib/base/common/network.d.ts +0 -65
  109. package/lib/base/common/network.js +0 -124
  110. package/lib/base/common/path.d.ts +0 -39
  111. package/lib/base/common/path.js +0 -1407
  112. package/lib/base/common/platform.d.ts +0 -53
  113. package/lib/base/common/platform.js +0 -176
  114. package/lib/base/common/process.d.ts +0 -5
  115. package/lib/base/common/process.js +0 -18
  116. package/lib/base/common/sequence.d.ts +0 -27
  117. package/lib/base/common/sequence.js +0 -32
  118. package/lib/base/common/uri.d.ts +0 -153
  119. package/lib/base/common/uri.js +0 -612
  120. package/lib/browser/iframe.js +0 -109
  121. package/lib/common/charCode.js +0 -6
  122. package/lib/menu.d.ts +0 -53
  123. package/lib/menu.js +0 -532
  124. package/lib/menuitem.d.ts +0 -46
  125. package/lib/menuitem.js +0 -295
  126. package/lib/vs/base/browser/browser.d.ts +0 -25
  127. package/lib/vs/base/browser/browser.js +0 -117
  128. package/lib/vs/base/browser/canIUse.d.ts +0 -18
  129. package/lib/vs/base/browser/canIUse.js +0 -63
  130. package/lib/vs/base/browser/dom.d.ts +0 -230
  131. package/lib/vs/base/browser/dom.js +0 -1080
  132. package/lib/vs/base/browser/event.d.ts +0 -12
  133. package/lib/vs/base/browser/event.js +0 -28
  134. package/lib/vs/base/browser/iframe.d.ts +0 -33
  135. package/lib/vs/base/browser/iframe.js +0 -109
  136. package/lib/vs/base/browser/keyboardEvent.d.ts +0 -40
  137. package/lib/vs/base/browser/keyboardEvent.js +0 -256
  138. package/lib/vs/base/browser/mouseEvent.d.ts +0 -69
  139. package/lib/vs/base/browser/mouseEvent.js +0 -146
  140. package/lib/vs/base/common/arrays.d.ts +0 -149
  141. package/lib/vs/base/common/arrays.js +0 -549
  142. package/lib/vs/base/common/async.d.ts +0 -259
  143. package/lib/vs/base/common/async.js +0 -728
  144. package/lib/vs/base/common/cancellation.d.ts +0 -29
  145. package/lib/vs/base/common/cancellation.js +0 -114
  146. package/lib/vs/base/common/charCode.d.ts +0 -415
  147. package/lib/vs/base/common/charCode.js +0 -6
  148. package/lib/vs/base/common/color.d.ts +0 -163
  149. package/lib/vs/base/common/color.js +0 -495
  150. package/lib/vs/base/common/errors.d.ts +0 -65
  151. package/lib/vs/base/common/errors.js +0 -164
  152. package/lib/vs/base/common/event.d.ts +0 -248
  153. package/lib/vs/base/common/event.js +0 -703
  154. package/lib/vs/base/common/functional.d.ts +0 -1
  155. package/lib/vs/base/common/functional.js +0 -21
  156. package/lib/vs/base/common/iterator.d.ts +0 -16
  157. package/lib/vs/base/common/iterator.js +0 -82
  158. package/lib/vs/base/common/keyCodes.d.ts +0 -268
  159. package/lib/vs/base/common/keyCodes.js +0 -292
  160. package/lib/vs/base/common/lifecycle.d.ts +0 -67
  161. package/lib/vs/base/common/lifecycle.js +0 -234
  162. package/lib/vs/base/common/linkedList.d.ts +0 -16
  163. package/lib/vs/base/common/linkedList.js +0 -128
  164. package/lib/vs/base/common/network.d.ts +0 -65
  165. package/lib/vs/base/common/network.js +0 -124
  166. package/lib/vs/base/common/path.d.ts +0 -39
  167. package/lib/vs/base/common/path.js +0 -1407
  168. package/lib/vs/base/common/platform.d.ts +0 -53
  169. package/lib/vs/base/common/platform.js +0 -176
  170. package/lib/vs/base/common/process.d.ts +0 -5
  171. package/lib/vs/base/common/process.js +0 -18
  172. package/lib/vs/base/common/sequence.d.ts +0 -27
  173. package/lib/vs/base/common/sequence.js +0 -32
  174. package/lib/vs/base/common/uri.d.ts +0 -153
  175. package/lib/vs/base/common/uri.js +0 -612
@@ -1,703 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.Relay = exports.EventBufferer = exports.EventMultiplexer = exports.AsyncEmitter = exports.PauseableEmitter = exports.Emitter = exports.setGlobalLeakWarningThreshold = exports.Event = void 0;
8
- const errors_1 = require("vs/base/common/errors");
9
- const functional_1 = require("vs/base/common/functional");
10
- const lifecycle_1 = require("vs/base/common/lifecycle");
11
- const linkedList_1 = require("vs/base/common/linkedList");
12
- var Event;
13
- (function (Event) {
14
- Event.None = () => lifecycle_1.Disposable.None;
15
- /**
16
- * Given an event, returns another event which only fires once.
17
- */
18
- function once(event) {
19
- return (listener, thisArgs = null, disposables) => {
20
- // we need this, in case the event fires during the listener call
21
- let didFire = false;
22
- let result;
23
- result = event(e => {
24
- if (didFire) {
25
- return;
26
- }
27
- else if (result) {
28
- result.dispose();
29
- }
30
- else {
31
- didFire = true;
32
- }
33
- return listener.call(thisArgs, e);
34
- }, null, disposables);
35
- if (didFire) {
36
- result.dispose();
37
- }
38
- return result;
39
- };
40
- }
41
- Event.once = once;
42
- /**
43
- * Given an event and a `map` function, returns another event which maps each element
44
- * through the mapping function.
45
- */
46
- function map(event, map) {
47
- return snapshot((listener, thisArgs = null, disposables) => event(i => listener.call(thisArgs, map(i)), null, disposables));
48
- }
49
- Event.map = map;
50
- /**
51
- * Given an event and an `each` function, returns another identical event and calls
52
- * the `each` function per each element.
53
- */
54
- function forEach(event, each) {
55
- return snapshot((listener, thisArgs = null, disposables) => event(i => { each(i); listener.call(thisArgs, i); }, null, disposables));
56
- }
57
- Event.forEach = forEach;
58
- function filter(event, filter) {
59
- return snapshot((listener, thisArgs = null, disposables) => event(e => filter(e) && listener.call(thisArgs, e), null, disposables));
60
- }
61
- Event.filter = filter;
62
- /**
63
- * Given an event, returns the same event but typed as `Event<void>`.
64
- */
65
- function signal(event) {
66
- return event;
67
- }
68
- Event.signal = signal;
69
- function any(...events) {
70
- return (listener, thisArgs = null, disposables) => lifecycle_1.combinedDisposable(...events.map(event => event(e => listener.call(thisArgs, e), null, disposables)));
71
- }
72
- Event.any = any;
73
- /**
74
- * Given an event and a `merge` function, returns another event which maps each element
75
- * and the cumulative result through the `merge` function. Similar to `map`, but with memory.
76
- */
77
- function reduce(event, merge, initial) {
78
- let output = initial;
79
- return map(event, e => {
80
- output = merge(output, e);
81
- return output;
82
- });
83
- }
84
- Event.reduce = reduce;
85
- /**
86
- * Given a chain of event processing functions (filter, map, etc), each
87
- * function will be invoked per event & per listener. Snapshotting an event
88
- * chain allows each function to be invoked just once per event.
89
- */
90
- function snapshot(event) {
91
- let listener;
92
- const emitter = new Emitter({
93
- onFirstListenerAdd() {
94
- listener = event(emitter.fire, emitter);
95
- },
96
- onLastListenerRemove() {
97
- listener.dispose();
98
- }
99
- });
100
- return emitter.event;
101
- }
102
- Event.snapshot = snapshot;
103
- function debounce(event, merge, delay = 100, leading = false, leakWarningThreshold) {
104
- let subscription;
105
- let output = undefined;
106
- let handle = undefined;
107
- let numDebouncedCalls = 0;
108
- const emitter = new Emitter({
109
- leakWarningThreshold,
110
- onFirstListenerAdd() {
111
- subscription = event(cur => {
112
- numDebouncedCalls++;
113
- output = merge(output, cur);
114
- if (leading && !handle) {
115
- emitter.fire(output);
116
- output = undefined;
117
- }
118
- clearTimeout(handle);
119
- handle = setTimeout(() => {
120
- const _output = output;
121
- output = undefined;
122
- handle = undefined;
123
- if (!leading || numDebouncedCalls > 1) {
124
- emitter.fire(_output);
125
- }
126
- numDebouncedCalls = 0;
127
- }, delay);
128
- });
129
- },
130
- onLastListenerRemove() {
131
- subscription.dispose();
132
- }
133
- });
134
- return emitter.event;
135
- }
136
- Event.debounce = debounce;
137
- /**
138
- * Given an event, it returns another event which fires only once and as soon as
139
- * the input event emits. The event data is the number of millis it took for the
140
- * event to fire.
141
- */
142
- function stopwatch(event) {
143
- const start = new Date().getTime();
144
- return map(once(event), _ => new Date().getTime() - start);
145
- }
146
- Event.stopwatch = stopwatch;
147
- /**
148
- * Given an event, it returns another event which fires only when the event
149
- * element changes.
150
- */
151
- function latch(event) {
152
- let firstCall = true;
153
- let cache;
154
- return filter(event, value => {
155
- const shouldEmit = firstCall || value !== cache;
156
- firstCall = false;
157
- cache = value;
158
- return shouldEmit;
159
- });
160
- }
161
- Event.latch = latch;
162
- /**
163
- * Buffers the provided event until a first listener comes
164
- * along, at which point fire all the events at once and
165
- * pipe the event from then on.
166
- *
167
- * ```typescript
168
- * const emitter = new Emitter<number>();
169
- * const event = emitter.event;
170
- * const bufferedEvent = buffer(event);
171
- *
172
- * emitter.fire(1);
173
- * emitter.fire(2);
174
- * emitter.fire(3);
175
- * // nothing...
176
- *
177
- * const listener = bufferedEvent(num => console.log(num));
178
- * // 1, 2, 3
179
- *
180
- * emitter.fire(4);
181
- * // 4
182
- * ```
183
- */
184
- function buffer(event, nextTick = false, _buffer = []) {
185
- let buffer = _buffer.slice();
186
- let listener = event(e => {
187
- if (buffer) {
188
- buffer.push(e);
189
- }
190
- else {
191
- emitter.fire(e);
192
- }
193
- });
194
- const flush = () => {
195
- if (buffer) {
196
- buffer.forEach(e => emitter.fire(e));
197
- }
198
- buffer = null;
199
- };
200
- const emitter = new Emitter({
201
- onFirstListenerAdd() {
202
- if (!listener) {
203
- listener = event(e => emitter.fire(e));
204
- }
205
- },
206
- onFirstListenerDidAdd() {
207
- if (buffer) {
208
- if (nextTick) {
209
- setTimeout(flush);
210
- }
211
- else {
212
- flush();
213
- }
214
- }
215
- },
216
- onLastListenerRemove() {
217
- if (listener) {
218
- listener.dispose();
219
- }
220
- listener = null;
221
- }
222
- });
223
- return emitter.event;
224
- }
225
- Event.buffer = buffer;
226
- class ChainableEvent {
227
- constructor(event) {
228
- this.event = event;
229
- }
230
- map(fn) {
231
- return new ChainableEvent(map(this.event, fn));
232
- }
233
- forEach(fn) {
234
- return new ChainableEvent(forEach(this.event, fn));
235
- }
236
- filter(fn) {
237
- return new ChainableEvent(filter(this.event, fn));
238
- }
239
- reduce(merge, initial) {
240
- return new ChainableEvent(reduce(this.event, merge, initial));
241
- }
242
- latch() {
243
- return new ChainableEvent(latch(this.event));
244
- }
245
- debounce(merge, delay = 100, leading = false, leakWarningThreshold) {
246
- return new ChainableEvent(debounce(this.event, merge, delay, leading, leakWarningThreshold));
247
- }
248
- on(listener, thisArgs, disposables) {
249
- return this.event(listener, thisArgs, disposables);
250
- }
251
- once(listener, thisArgs, disposables) {
252
- return once(this.event)(listener, thisArgs, disposables);
253
- }
254
- }
255
- function chain(event) {
256
- return new ChainableEvent(event);
257
- }
258
- Event.chain = chain;
259
- function fromNodeEventEmitter(emitter, eventName, map = id => id) {
260
- const fn = (...args) => result.fire(map(...args));
261
- const onFirstListenerAdd = () => emitter.on(eventName, fn);
262
- const onLastListenerRemove = () => emitter.removeListener(eventName, fn);
263
- const result = new Emitter({ onFirstListenerAdd, onLastListenerRemove });
264
- return result.event;
265
- }
266
- Event.fromNodeEventEmitter = fromNodeEventEmitter;
267
- function fromDOMEventEmitter(emitter, eventName, map = id => id) {
268
- const fn = (...args) => result.fire(map(...args));
269
- const onFirstListenerAdd = () => emitter.addEventListener(eventName, fn);
270
- const onLastListenerRemove = () => emitter.removeEventListener(eventName, fn);
271
- const result = new Emitter({ onFirstListenerAdd, onLastListenerRemove });
272
- return result.event;
273
- }
274
- Event.fromDOMEventEmitter = fromDOMEventEmitter;
275
- function fromPromise(promise) {
276
- const emitter = new Emitter();
277
- let shouldEmit = false;
278
- promise
279
- .then(undefined, () => null)
280
- .then(() => {
281
- if (!shouldEmit) {
282
- setTimeout(() => emitter.fire(undefined), 0);
283
- }
284
- else {
285
- emitter.fire(undefined);
286
- }
287
- });
288
- shouldEmit = true;
289
- return emitter.event;
290
- }
291
- Event.fromPromise = fromPromise;
292
- function toPromise(event) {
293
- return new Promise(c => once(event)(c));
294
- }
295
- Event.toPromise = toPromise;
296
- })(Event = exports.Event || (exports.Event = {}));
297
- let _globalLeakWarningThreshold = -1;
298
- function setGlobalLeakWarningThreshold(n) {
299
- const oldValue = _globalLeakWarningThreshold;
300
- _globalLeakWarningThreshold = n;
301
- return {
302
- dispose() {
303
- _globalLeakWarningThreshold = oldValue;
304
- }
305
- };
306
- }
307
- exports.setGlobalLeakWarningThreshold = setGlobalLeakWarningThreshold;
308
- class LeakageMonitor {
309
- constructor(customThreshold, name = Math.random().toString(18).slice(2, 5)) {
310
- this.customThreshold = customThreshold;
311
- this.name = name;
312
- this._warnCountdown = 0;
313
- }
314
- dispose() {
315
- if (this._stacks) {
316
- this._stacks.clear();
317
- }
318
- }
319
- check(listenerCount) {
320
- let threshold = _globalLeakWarningThreshold;
321
- if (typeof this.customThreshold === 'number') {
322
- threshold = this.customThreshold;
323
- }
324
- if (threshold <= 0 || listenerCount < threshold) {
325
- return undefined;
326
- }
327
- if (!this._stacks) {
328
- this._stacks = new Map();
329
- }
330
- const stack = new Error().stack.split('\n').slice(3).join('\n');
331
- const count = (this._stacks.get(stack) || 0);
332
- this._stacks.set(stack, count + 1);
333
- this._warnCountdown -= 1;
334
- if (this._warnCountdown <= 0) {
335
- // only warn on first exceed and then every time the limit
336
- // is exceeded by 50% again
337
- this._warnCountdown = threshold * 0.5;
338
- // find most frequent listener and print warning
339
- let topStack;
340
- let topCount = 0;
341
- for (const [stack, count] of this._stacks) {
342
- if (!topStack || topCount < count) {
343
- topStack = stack;
344
- topCount = count;
345
- }
346
- }
347
- console.warn(`[${this.name}] potential listener LEAK detected, having ${listenerCount} listeners already. MOST frequent listener (${topCount}):`);
348
- console.warn(topStack);
349
- }
350
- return () => {
351
- const count = (this._stacks.get(stack) || 0);
352
- this._stacks.set(stack, count - 1);
353
- };
354
- }
355
- }
356
- /**
357
- * The Emitter can be used to expose an Event to the public
358
- * to fire it from the insides.
359
- * Sample:
360
- class Document {
361
-
362
- private readonly _onDidChange = new Emitter<(value:string)=>any>();
363
-
364
- public onDidChange = this._onDidChange.event;
365
-
366
- // getter-style
367
- // get onDidChange(): Event<(value:string)=>any> {
368
- // return this._onDidChange.event;
369
- // }
370
-
371
- private _doIt() {
372
- //...
373
- this._onDidChange.fire(value);
374
- }
375
- }
376
- */
377
- class Emitter {
378
- constructor(options) {
379
- this._disposed = false;
380
- this._options = options;
381
- this._leakageMon = _globalLeakWarningThreshold > 0
382
- ? new LeakageMonitor(this._options && this._options.leakWarningThreshold)
383
- : undefined;
384
- }
385
- /**
386
- * For the public to allow to subscribe
387
- * to events from this Emitter
388
- */
389
- get event() {
390
- if (!this._event) {
391
- this._event = (listener, thisArgs, disposables) => {
392
- if (!this._listeners) {
393
- this._listeners = new linkedList_1.LinkedList();
394
- }
395
- const firstListener = this._listeners.isEmpty();
396
- if (firstListener && this._options && this._options.onFirstListenerAdd) {
397
- this._options.onFirstListenerAdd(this);
398
- }
399
- const remove = this._listeners.push(!thisArgs ? listener : [listener, thisArgs]);
400
- if (firstListener && this._options && this._options.onFirstListenerDidAdd) {
401
- this._options.onFirstListenerDidAdd(this);
402
- }
403
- if (this._options && this._options.onListenerDidAdd) {
404
- this._options.onListenerDidAdd(this, listener, thisArgs);
405
- }
406
- // check and record this emitter for potential leakage
407
- let removeMonitor;
408
- if (this._leakageMon) {
409
- removeMonitor = this._leakageMon.check(this._listeners.size);
410
- }
411
- let result;
412
- result = {
413
- dispose: () => {
414
- if (removeMonitor) {
415
- removeMonitor();
416
- }
417
- result.dispose = Emitter._noop;
418
- if (!this._disposed) {
419
- remove();
420
- if (this._options && this._options.onLastListenerRemove) {
421
- const hasListeners = (this._listeners && !this._listeners.isEmpty());
422
- if (!hasListeners) {
423
- this._options.onLastListenerRemove(this);
424
- }
425
- }
426
- }
427
- }
428
- };
429
- if (disposables instanceof lifecycle_1.DisposableStore) {
430
- disposables.add(result);
431
- }
432
- else if (Array.isArray(disposables)) {
433
- disposables.push(result);
434
- }
435
- return result;
436
- };
437
- }
438
- return this._event;
439
- }
440
- /**
441
- * To be kept private to fire an event to
442
- * subscribers
443
- */
444
- fire(event) {
445
- if (this._listeners) {
446
- // put all [listener,event]-pairs into delivery queue
447
- // then emit all event. an inner/nested event might be
448
- // the driver of this
449
- if (!this._deliveryQueue) {
450
- this._deliveryQueue = new linkedList_1.LinkedList();
451
- }
452
- for (let listener of this._listeners) {
453
- this._deliveryQueue.push([listener, event]);
454
- }
455
- while (this._deliveryQueue.size > 0) {
456
- const [listener, event] = this._deliveryQueue.shift();
457
- try {
458
- if (typeof listener === 'function') {
459
- listener.call(undefined, event);
460
- }
461
- else {
462
- listener[0].call(listener[1], event);
463
- }
464
- }
465
- catch (e) {
466
- errors_1.onUnexpectedError(e);
467
- }
468
- }
469
- }
470
- }
471
- dispose() {
472
- if (this._listeners) {
473
- this._listeners.clear();
474
- }
475
- if (this._deliveryQueue) {
476
- this._deliveryQueue.clear();
477
- }
478
- if (this._leakageMon) {
479
- this._leakageMon.dispose();
480
- }
481
- this._disposed = true;
482
- }
483
- }
484
- exports.Emitter = Emitter;
485
- Emitter._noop = function () { };
486
- class PauseableEmitter extends Emitter {
487
- constructor(options) {
488
- super(options);
489
- this._isPaused = 0;
490
- this._eventQueue = new linkedList_1.LinkedList();
491
- this._mergeFn = options && options.merge;
492
- }
493
- pause() {
494
- this._isPaused++;
495
- }
496
- resume() {
497
- if (this._isPaused !== 0 && --this._isPaused === 0) {
498
- if (this._mergeFn) {
499
- // use the merge function to create a single composite
500
- // event. make a copy in case firing pauses this emitter
501
- const events = this._eventQueue.toArray();
502
- this._eventQueue.clear();
503
- super.fire(this._mergeFn(events));
504
- }
505
- else {
506
- // no merging, fire each event individually and test
507
- // that this emitter isn't paused halfway through
508
- while (!this._isPaused && this._eventQueue.size !== 0) {
509
- super.fire(this._eventQueue.shift());
510
- }
511
- }
512
- }
513
- }
514
- fire(event) {
515
- if (this._listeners) {
516
- if (this._isPaused !== 0) {
517
- this._eventQueue.push(event);
518
- }
519
- else {
520
- super.fire(event);
521
- }
522
- }
523
- }
524
- }
525
- exports.PauseableEmitter = PauseableEmitter;
526
- class AsyncEmitter extends Emitter {
527
- async fireAsync(data, token, promiseJoin) {
528
- if (!this._listeners) {
529
- return;
530
- }
531
- if (!this._asyncDeliveryQueue) {
532
- this._asyncDeliveryQueue = new linkedList_1.LinkedList();
533
- }
534
- for (const listener of this._listeners) {
535
- this._asyncDeliveryQueue.push([listener, data]);
536
- }
537
- while (this._asyncDeliveryQueue.size > 0 && !token.isCancellationRequested) {
538
- const [listener, data] = this._asyncDeliveryQueue.shift();
539
- const thenables = [];
540
- const event = {
541
- ...data,
542
- waitUntil: (p) => {
543
- if (Object.isFrozen(thenables)) {
544
- throw new Error('waitUntil can NOT be called asynchronous');
545
- }
546
- if (promiseJoin) {
547
- p = promiseJoin(p, typeof listener === 'function' ? listener : listener[0]);
548
- }
549
- thenables.push(p);
550
- }
551
- };
552
- try {
553
- if (typeof listener === 'function') {
554
- listener.call(undefined, event);
555
- }
556
- else {
557
- listener[0].call(listener[1], event);
558
- }
559
- }
560
- catch (e) {
561
- errors_1.onUnexpectedError(e);
562
- continue;
563
- }
564
- // freeze thenables-collection to enforce sync-calls to
565
- // wait until and then wait for all thenables to resolve
566
- Object.freeze(thenables);
567
- await Promise.all(thenables).catch(e => errors_1.onUnexpectedError(e));
568
- }
569
- }
570
- }
571
- exports.AsyncEmitter = AsyncEmitter;
572
- class EventMultiplexer {
573
- constructor() {
574
- this.hasListeners = false;
575
- this.events = [];
576
- this.emitter = new Emitter({
577
- onFirstListenerAdd: () => this.onFirstListenerAdd(),
578
- onLastListenerRemove: () => this.onLastListenerRemove()
579
- });
580
- }
581
- get event() {
582
- return this.emitter.event;
583
- }
584
- add(event) {
585
- const e = { event: event, listener: null };
586
- this.events.push(e);
587
- if (this.hasListeners) {
588
- this.hook(e);
589
- }
590
- const dispose = () => {
591
- if (this.hasListeners) {
592
- this.unhook(e);
593
- }
594
- const idx = this.events.indexOf(e);
595
- this.events.splice(idx, 1);
596
- };
597
- return lifecycle_1.toDisposable(functional_1.once(dispose));
598
- }
599
- onFirstListenerAdd() {
600
- this.hasListeners = true;
601
- this.events.forEach(e => this.hook(e));
602
- }
603
- onLastListenerRemove() {
604
- this.hasListeners = false;
605
- this.events.forEach(e => this.unhook(e));
606
- }
607
- hook(e) {
608
- e.listener = e.event(r => this.emitter.fire(r));
609
- }
610
- unhook(e) {
611
- if (e.listener) {
612
- e.listener.dispose();
613
- }
614
- e.listener = null;
615
- }
616
- dispose() {
617
- this.emitter.dispose();
618
- }
619
- }
620
- exports.EventMultiplexer = EventMultiplexer;
621
- /**
622
- * The EventBufferer is useful in situations in which you want
623
- * to delay firing your events during some code.
624
- * You can wrap that code and be sure that the event will not
625
- * be fired during that wrap.
626
- *
627
- * ```
628
- * const emitter: Emitter;
629
- * const delayer = new EventDelayer();
630
- * const delayedEvent = delayer.wrapEvent(emitter.event);
631
- *
632
- * delayedEvent(console.log);
633
- *
634
- * delayer.bufferEvents(() => {
635
- * emitter.fire(); // event will not be fired yet
636
- * });
637
- *
638
- * // event will only be fired at this point
639
- * ```
640
- */
641
- class EventBufferer {
642
- constructor() {
643
- this.buffers = [];
644
- }
645
- wrapEvent(event) {
646
- return (listener, thisArgs, disposables) => {
647
- return event(i => {
648
- const buffer = this.buffers[this.buffers.length - 1];
649
- if (buffer) {
650
- buffer.push(() => listener.call(thisArgs, i));
651
- }
652
- else {
653
- listener.call(thisArgs, i);
654
- }
655
- }, undefined, disposables);
656
- };
657
- }
658
- bufferEvents(fn) {
659
- const buffer = [];
660
- this.buffers.push(buffer);
661
- const r = fn();
662
- this.buffers.pop();
663
- buffer.forEach(flush => flush());
664
- return r;
665
- }
666
- }
667
- exports.EventBufferer = EventBufferer;
668
- /**
669
- * A Relay is an event forwarder which functions as a replugabble event pipe.
670
- * Once created, you can connect an input event to it and it will simply forward
671
- * events from that input event through its own `event` property. The `input`
672
- * can be changed at any point in time.
673
- */
674
- class Relay {
675
- constructor() {
676
- this.listening = false;
677
- this.inputEvent = Event.None;
678
- this.inputEventListener = lifecycle_1.Disposable.None;
679
- this.emitter = new Emitter({
680
- onFirstListenerDidAdd: () => {
681
- this.listening = true;
682
- this.inputEventListener = this.inputEvent(this.emitter.fire, this.emitter);
683
- },
684
- onLastListenerRemove: () => {
685
- this.listening = false;
686
- this.inputEventListener.dispose();
687
- }
688
- });
689
- this.event = this.emitter.event;
690
- }
691
- set input(event) {
692
- this.inputEvent = event;
693
- if (this.listening) {
694
- this.inputEventListener.dispose();
695
- this.inputEventListener = event(this.emitter.fire, this.emitter);
696
- }
697
- }
698
- dispose() {
699
- this.inputEventListener.dispose();
700
- this.emitter.dispose();
701
- }
702
- }
703
- exports.Relay = Relay;
@@ -1 +0,0 @@
1
- export declare function once<T extends Function>(this: unknown, fn: T): T;