custom-electron-titlebar 3.2.6 → 3.2.10

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 (239) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/README.md +15 -24
  3. package/_config.yml +1 -0
  4. package/{lib → build}/browser/browser.d.ts +0 -0
  5. package/{lib → build}/browser/browser.js +0 -0
  6. package/{lib → build}/browser/browser.js.map +0 -0
  7. package/{lib → build}/browser/event.d.ts +0 -0
  8. package/{lib → build}/browser/event.js +2 -1
  9. package/{lib → build}/browser/event.js.map +1 -1
  10. package/{lib → build}/browser/iframe.d.ts +0 -0
  11. package/{lib → build}/browser/iframe.js +0 -0
  12. package/{lib → build}/browser/iframe.js.map +0 -0
  13. package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
  14. package/{lib → build}/browser/keyboardEvent.js +0 -0
  15. package/{lib → build}/browser/keyboardEvent.js.map +0 -0
  16. package/{lib → build}/browser/mouseEvent.d.ts +0 -0
  17. package/{lib → build}/browser/mouseEvent.js +0 -0
  18. package/{lib → build}/browser/mouseEvent.js.map +0 -0
  19. package/{lib → build}/common/arrays.d.ts +0 -0
  20. package/{lib → build}/common/arrays.js +0 -0
  21. package/{lib → build}/common/arrays.js.map +0 -0
  22. package/{lib → build}/common/async.d.ts +0 -0
  23. package/{lib → build}/common/async.js +0 -0
  24. package/{lib → build}/common/async.js.map +0 -0
  25. package/{lib → build}/common/charCode.d.ts +0 -0
  26. package/{lib → build}/common/charCode.js +0 -0
  27. package/{lib → build}/common/charCode.js.map +0 -0
  28. package/{lib → build}/common/color.d.ts +0 -0
  29. package/{lib → build}/common/color.js +0 -0
  30. package/{lib → build}/common/color.js.map +0 -0
  31. package/{lib → build}/common/dom.d.ts +0 -0
  32. package/{lib → build}/common/dom.js +16 -14
  33. package/build/common/dom.js.map +1 -0
  34. package/{lib → build}/common/event.d.ts +0 -0
  35. package/{lib → build}/common/event.js +1 -1
  36. package/build/common/event.js.map +1 -0
  37. package/{lib → build}/common/iterator.d.ts +0 -0
  38. package/{lib → build}/common/iterator.js +0 -0
  39. package/{lib → build}/common/iterator.js.map +0 -0
  40. package/{lib → build}/common/keyCodes.d.ts +0 -0
  41. package/{lib → build}/common/keyCodes.js +0 -0
  42. package/{lib → build}/common/keyCodes.js.map +0 -0
  43. package/{lib → build}/common/lifecycle.d.ts +0 -0
  44. package/{lib → build}/common/lifecycle.js +0 -0
  45. package/{lib → build}/common/lifecycle.js.map +0 -0
  46. package/{lib → build}/common/linkedList.d.ts +0 -0
  47. package/{lib → build}/common/linkedList.js +0 -0
  48. package/{lib → build}/common/linkedList.js.map +0 -0
  49. package/{lib → build}/common/platform.d.ts +0 -0
  50. package/{lib → build}/common/platform.js +0 -0
  51. package/{lib → build}/common/platform.js.map +0 -0
  52. package/{lib → build}/index.d.ts +0 -0
  53. package/{lib → build}/index.js +0 -0
  54. package/{lib → build}/index.js.map +0 -0
  55. package/{lib → build}/menu/menu.d.ts +0 -0
  56. package/{lib → build}/menu/menu.js +38 -38
  57. package/build/menu/menu.js.map +1 -0
  58. package/{lib → build}/menu/menuitem.d.ts +10 -2
  59. package/{lib → build}/menu/menuitem.js +70 -34
  60. package/build/menu/menuitem.js.map +1 -0
  61. package/{lib → build}/menubar.d.ts +0 -0
  62. package/{lib → build}/menubar.js +29 -30
  63. package/build/menubar.js.map +1 -0
  64. package/{lib → build}/themebar.d.ts +0 -0
  65. package/{lib → build}/themebar.js +2 -2
  66. package/build/themebar.js.map +1 -0
  67. package/{lib → build}/titlebar.d.ts +0 -0
  68. package/{lib → build}/titlebar.js +61 -58
  69. package/build/titlebar.js.map +1 -0
  70. package/package.json +13 -7
  71. package/lib/common/dom.js.map +0 -1
  72. package/lib/common/enableNativeMenuCommands.d.ts +0 -1
  73. package/lib/common/enableNativeMenuCommands.js +0 -32
  74. package/lib/common/enableNativeMenuCommands.js.map +0 -1
  75. package/lib/common/event.js.map +0 -1
  76. package/lib/main.d.ts +0 -1
  77. package/lib/main.js +0 -14
  78. package/lib/main.js.map +0 -1
  79. package/lib/menu/menu.js.map +0 -1
  80. package/lib/menu/menuitem.js.map +0 -1
  81. package/lib/menubar.js.map +0 -1
  82. package/lib/themebar.js.map +0 -1
  83. package/lib/titlebar.js.map +0 -1
  84. package/lib/vs/base/browser/browser.js +0 -150
  85. package/lib/vs/base/browser/canIUse.js +0 -58
  86. package/lib/vs/base/browser/codicons.js +0 -37
  87. package/lib/vs/base/browser/contextmenu.js +0 -9
  88. package/lib/vs/base/browser/dnd.js +0 -113
  89. package/lib/vs/base/browser/dom.js +0 -1417
  90. package/lib/vs/base/browser/event.js +0 -36
  91. package/lib/vs/base/browser/fastDomNode.js +0 -265
  92. package/lib/vs/base/browser/formattedTextRenderer.js +0 -248
  93. package/lib/vs/base/browser/globalMouseMoveMonitor.js +0 -137
  94. package/lib/vs/base/browser/history.js +0 -9
  95. package/lib/vs/base/browser/iframe.js +0 -126
  96. package/lib/vs/base/browser/keyboardEvent.js +0 -599
  97. package/lib/vs/base/browser/mouseEvent.js +0 -155
  98. package/lib/vs/base/browser/touch.js +0 -315
  99. package/lib/vs/base/browser/ui/actionbar/actionViewItems.js +0 -397
  100. package/lib/vs/base/browser/ui/actionbar/actionbar.js +0 -583
  101. package/lib/vs/base/browser/ui/checkbox/checkbox.js +0 -251
  102. package/lib/vs/base/browser/ui/codicons/codiconLabel.js +0 -31
  103. package/lib/vs/base/browser/ui/codicons/codiconStyles.js +0 -47
  104. package/lib/vs/base/browser/ui/contextview/contextview.js +0 -367
  105. package/lib/vs/base/browser/ui/dropdown/dropdown.js +0 -256
  106. package/lib/vs/base/browser/ui/dropdown/dropdownActionViewItem.js +0 -120
  107. package/lib/vs/base/browser/ui/keybindingLabel/keybindingLabel.js +0 -118
  108. package/lib/vs/base/browser/ui/list/list.js +0 -54
  109. package/lib/vs/base/browser/ui/list/listPaging.js +0 -322
  110. package/lib/vs/base/browser/ui/list/listView.js +0 -1388
  111. package/lib/vs/base/browser/ui/list/listWidget.js +0 -1709
  112. package/lib/vs/base/browser/ui/list/rangeMap.js +0 -223
  113. package/lib/vs/base/browser/ui/list/rowCache.js +0 -113
  114. package/lib/vs/base/browser/ui/list/splice.js +0 -23
  115. package/lib/vs/base/browser/ui/menu/menu.js +0 -1371
  116. package/lib/vs/base/browser/ui/menu/menubar.js +0 -1139
  117. package/lib/vs/base/browser/ui/scrollbar/abstractScrollbar.js +0 -278
  118. package/lib/vs/base/browser/ui/scrollbar/horizontalScrollbar.js +0 -115
  119. package/lib/vs/base/browser/ui/scrollbar/scrollableElement.js +0 -646
  120. package/lib/vs/base/browser/ui/scrollbar/scrollableElementOptions.js +0 -9
  121. package/lib/vs/base/browser/ui/scrollbar/scrollbarArrow.js +0 -106
  122. package/lib/vs/base/browser/ui/scrollbar/scrollbarState.js +0 -184
  123. package/lib/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.js +0 -116
  124. package/lib/vs/base/browser/ui/scrollbar/verticalScrollbar.js +0 -114
  125. package/lib/vs/base/browser/ui/selectBox/selectBox.js +0 -85
  126. package/lib/vs/base/browser/ui/selectBox/selectBoxCustom.js +0 -985
  127. package/lib/vs/base/browser/ui/selectBox/selectBoxNative.js +0 -188
  128. package/lib/vs/base/browser/ui/toolbar/toolbar.js +0 -206
  129. package/lib/vs/base/browser/ui/widget.js +0 -69
  130. package/lib/vs/base/common/actions.js +0 -224
  131. package/lib/vs/base/common/amd.js +0 -31
  132. package/lib/vs/base/common/arrays.js +0 -641
  133. package/lib/vs/base/common/assert.js +0 -21
  134. package/lib/vs/base/common/async.js +0 -966
  135. package/lib/vs/base/common/buffer.js +0 -250
  136. package/lib/vs/base/common/cache.js +0 -40
  137. package/lib/vs/base/common/cancellation.js +0 -146
  138. package/lib/vs/base/common/charCode.js +0 -9
  139. package/lib/vs/base/common/codicon.js +0 -136
  140. package/lib/vs/base/common/codicons.js +0 -1378
  141. package/lib/vs/base/common/collections.js +0 -133
  142. package/lib/vs/base/common/color.js +0 -716
  143. package/lib/vs/base/common/comparers.js +0 -280
  144. package/lib/vs/base/common/console.js +0 -142
  145. package/lib/vs/base/common/date.js +0 -113
  146. package/lib/vs/base/common/decorators.js +0 -169
  147. package/lib/vs/base/common/errorMessage.js +0 -93
  148. package/lib/vs/base/common/errors.js +0 -213
  149. package/lib/vs/base/common/errorsWithActions.js +0 -28
  150. package/lib/vs/base/common/event.js +0 -873
  151. package/lib/vs/base/common/extpath.js +0 -401
  152. package/lib/vs/base/common/filters.js +0 -948
  153. package/lib/vs/base/common/functional.js +0 -28
  154. package/lib/vs/base/common/fuzzyScorer.js +0 -811
  155. package/lib/vs/base/common/glob.js +0 -696
  156. package/lib/vs/base/common/hash.js +0 -359
  157. package/lib/vs/base/common/history.js +0 -116
  158. package/lib/vs/base/common/htmlContent.js +0 -162
  159. package/lib/vs/base/common/idGenerator.js +0 -25
  160. package/lib/vs/base/common/iterator.js +0 -118
  161. package/lib/vs/base/common/json.js +0 -1624
  162. package/lib/vs/base/common/jsonEdit.js +0 -272
  163. package/lib/vs/base/common/jsonErrorMessages.js +0 -69
  164. package/lib/vs/base/common/jsonFormatter.js +0 -316
  165. package/lib/vs/base/common/jsonSchema.js +0 -9
  166. package/lib/vs/base/common/keyCodes.js +0 -591
  167. package/lib/vs/base/common/keybindingLabels.js +0 -231
  168. package/lib/vs/base/common/keybindingParser.js +0 -142
  169. package/lib/vs/base/common/labels.js +0 -430
  170. package/lib/vs/base/common/lazy.js +0 -71
  171. package/lib/vs/base/common/lifecycle.js +0 -308
  172. package/lib/vs/base/common/linkedList.js +0 -152
  173. package/lib/vs/base/common/linkedText.js +0 -73
  174. package/lib/vs/base/common/map.js +0 -1108
  175. package/lib/vs/base/common/marshalling.js +0 -80
  176. package/lib/vs/base/common/mime.js +0 -321
  177. package/lib/vs/base/common/navigator.js +0 -50
  178. package/lib/vs/base/common/network.js +0 -160
  179. package/lib/vs/base/common/normalization.js +0 -78
  180. package/lib/vs/base/common/numbers.js +0 -55
  181. package/lib/vs/base/common/objects.js +0 -268
  182. package/lib/vs/base/common/paging.js +0 -190
  183. package/lib/vs/base/common/parsers.js +0 -78
  184. package/lib/vs/base/common/path.js +0 -1550
  185. package/lib/vs/base/common/platform.js +0 -245
  186. package/lib/vs/base/common/process.js +0 -52
  187. package/lib/vs/base/common/processes.js +0 -32
  188. package/lib/vs/base/common/range.js +0 -79
  189. package/lib/vs/base/common/resourceTree.js +0 -185
  190. package/lib/vs/base/common/resources.js +0 -421
  191. package/lib/vs/base/common/scanCode.js +0 -1472
  192. package/lib/vs/base/common/scrollable.js +0 -397
  193. package/lib/vs/base/common/search.js +0 -55
  194. package/lib/vs/base/common/sequence.js +0 -64
  195. package/lib/vs/base/common/severity.js +0 -55
  196. package/lib/vs/base/common/skipList.js +0 -234
  197. package/lib/vs/base/common/stopwatch.js +0 -45
  198. package/lib/vs/base/common/stream.js +0 -418
  199. package/lib/vs/base/common/strings.js +0 -1283
  200. package/lib/vs/base/common/styler.js +0 -9
  201. package/lib/vs/base/common/types.js +0 -296
  202. package/lib/vs/base/common/uint.js +0 -46
  203. package/lib/vs/base/common/uri.js +0 -756
  204. package/lib/vs/base/common/uriIpc.js +0 -154
  205. package/lib/vs/base/common/uuid.js +0 -70
  206. package/lib/vs/nls.mock.js +0 -31
  207. package/lib/vs/platform/actions/browser/menuEntryActionViewItem.js +0 -342
  208. package/lib/vs/platform/actions/common/actions.js +0 -456
  209. package/lib/vs/platform/actions/common/menuService.js +0 -194
  210. package/lib/vs/platform/clipboard/browser/clipboardService.js +0 -99
  211. package/lib/vs/platform/clipboard/common/clipboardService.js +0 -14
  212. package/lib/vs/platform/contextkey/common/contextkey.js +0 -1210
  213. package/lib/vs/platform/contextkey/common/contextkeys.js +0 -23
  214. package/lib/vs/platform/contextview/browser/contextView.js +0 -15
  215. package/lib/vs/platform/contextview/browser/contextViewService.js +0 -96
  216. package/lib/vs/platform/environment/common/argv.js +0 -9
  217. package/lib/vs/platform/environment/common/environment.js +0 -15
  218. package/lib/vs/platform/instantiation/common/descriptors.js +0 -25
  219. package/lib/vs/platform/instantiation/common/extensions.js +0 -26
  220. package/lib/vs/platform/instantiation/common/graph.js +0 -93
  221. package/lib/vs/platform/instantiation/common/instantiation.js +0 -84
  222. package/lib/vs/platform/instantiation/common/instantiationService.js +0 -361
  223. package/lib/vs/platform/instantiation/common/serviceCollection.js +0 -39
  224. package/lib/vs/platform/keybinding/common/baseResolvedKeybinding.js +0 -73
  225. package/lib/vs/platform/keybinding/common/keybinding.js +0 -14
  226. package/lib/vs/platform/keybinding/common/keybindingResolver.js +0 -391
  227. package/lib/vs/platform/keybinding/common/keybindingsRegistry.js +0 -229
  228. package/lib/vs/platform/keybinding/common/resolvedKeybindingItem.js +0 -47
  229. package/lib/vs/platform/keybinding/common/usLayoutResolvedKeybinding.js +0 -160
  230. package/lib/vs/platform/layout/browser/layoutService.js +0 -14
  231. package/lib/vs/platform/menubar/common/menubar.js +0 -34
  232. package/lib/vs/platform/registry/common/platform.js +0 -38
  233. package/lib/vs/platform/theme/browser/checkbox.js +0 -32
  234. package/lib/vs/platform/theme/common/colorRegistry.js +0 -1154
  235. package/lib/vs/platform/theme/common/styler.js +0 -290
  236. package/lib/vs/platform/theme/common/theme.js +0 -21
  237. package/lib/vs/platform/theme/common/themeService.js +0 -176
  238. package/lib/vs/platform/theme/common/tokenClassificationRegistry.js +0 -540
  239. package/lib/vs/platform/theme/test/common/testThemeService.js +0 -98
@@ -1,873 +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
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.Relay = exports.EventBufferer = exports.EventMultiplexer = exports.AsyncEmitter = exports.PauseableEmitter = exports.Emitter = exports.setGlobalLeakWarningThreshold = exports.Event = void 0;
11
-
12
- const errors_1 = require("./errors");
13
-
14
- const functional_1 = require("./functional");
15
-
16
- const lifecycle_1 = require("./lifecycle");
17
-
18
- const linkedList_1 = require("./linkedList");
19
-
20
- var Event;
21
-
22
- (function (Event) {
23
- Event.None = () => lifecycle_1.Disposable.None;
24
- /**
25
- * Given an event, returns another event which only fires once.
26
- */
27
-
28
-
29
- function once(event) {
30
- return (listener, thisArgs = null, disposables) => {
31
- // we need this, in case the event fires during the listener call
32
- let didFire = false;
33
- let result;
34
- result = event(e => {
35
- if (didFire) {
36
- return;
37
- } else if (result) {
38
- result.dispose();
39
- } else {
40
- didFire = true;
41
- }
42
-
43
- return listener.call(thisArgs, e);
44
- }, null, disposables);
45
-
46
- if (didFire) {
47
- result.dispose();
48
- }
49
-
50
- return result;
51
- };
52
- }
53
-
54
- Event.once = once;
55
- /**
56
- * Given an event and a `map` function, returns another event which maps each element
57
- * through the mapping function.
58
- */
59
-
60
- function map(event, map) {
61
- return snapshot((listener, thisArgs = null, disposables) => event(i => listener.call(thisArgs, map(i)), null, disposables));
62
- }
63
-
64
- Event.map = map;
65
- /**
66
- * Given an event and an `each` function, returns another identical event and calls
67
- * the `each` function per each element.
68
- */
69
-
70
- function forEach(event, each) {
71
- return snapshot((listener, thisArgs = null, disposables) => event(i => {
72
- each(i);
73
- listener.call(thisArgs, i);
74
- }, null, disposables));
75
- }
76
-
77
- Event.forEach = forEach;
78
-
79
- function filter(event, filter) {
80
- return snapshot((listener, thisArgs = null, disposables) => event(e => filter(e) && listener.call(thisArgs, e), null, disposables));
81
- }
82
-
83
- Event.filter = filter;
84
- /**
85
- * Given an event, returns the same event but typed as `Event<void>`.
86
- */
87
-
88
- function signal(event) {
89
- return event;
90
- }
91
-
92
- Event.signal = signal;
93
-
94
- function any(...events) {
95
- return (listener, thisArgs = null, disposables) => lifecycle_1.combinedDisposable(...events.map(event => event(e => listener.call(thisArgs, e), null, disposables)));
96
- }
97
-
98
- Event.any = any;
99
- /**
100
- * Given an event and a `merge` function, returns another event which maps each element
101
- * and the cumulative result through the `merge` function. Similar to `map`, but with memory.
102
- */
103
-
104
- function reduce(event, merge, initial) {
105
- let output = initial;
106
- return map(event, e => {
107
- output = merge(output, e);
108
- return output;
109
- });
110
- }
111
-
112
- Event.reduce = reduce;
113
- /**
114
- * Given a chain of event processing functions (filter, map, etc), each
115
- * function will be invoked per event & per listener. Snapshotting an event
116
- * chain allows each function to be invoked just once per event.
117
- */
118
-
119
- function snapshot(event) {
120
- let listener;
121
- const emitter = new Emitter({
122
- onFirstListenerAdd() {
123
- listener = event(emitter.fire, emitter);
124
- },
125
-
126
- onLastListenerRemove() {
127
- listener.dispose();
128
- }
129
-
130
- });
131
- return emitter.event;
132
- }
133
-
134
- Event.snapshot = snapshot;
135
-
136
- function debounce(event, merge, delay = 100, leading = false, leakWarningThreshold) {
137
- let subscription;
138
- let output = undefined;
139
- let handle = undefined;
140
- let numDebouncedCalls = 0;
141
- const emitter = new Emitter({
142
- leakWarningThreshold,
143
-
144
- onFirstListenerAdd() {
145
- subscription = event(cur => {
146
- numDebouncedCalls++;
147
- output = merge(output, cur);
148
-
149
- if (leading && !handle) {
150
- emitter.fire(output);
151
- output = undefined;
152
- }
153
-
154
- clearTimeout(handle);
155
- handle = setTimeout(() => {
156
- const _output = output;
157
- output = undefined;
158
- handle = undefined;
159
-
160
- if (!leading || numDebouncedCalls > 1) {
161
- emitter.fire(_output);
162
- }
163
-
164
- numDebouncedCalls = 0;
165
- }, delay);
166
- });
167
- },
168
-
169
- onLastListenerRemove() {
170
- subscription.dispose();
171
- }
172
-
173
- });
174
- return emitter.event;
175
- }
176
-
177
- Event.debounce = debounce;
178
- /**
179
- * Given an event, it returns another event which fires only once and as soon as
180
- * the input event emits. The event data is the number of millis it took for the
181
- * event to fire.
182
- */
183
-
184
- function stopwatch(event) {
185
- const start = new Date().getTime();
186
- return map(once(event), _ => new Date().getTime() - start);
187
- }
188
-
189
- Event.stopwatch = stopwatch;
190
- /**
191
- * Given an event, it returns another event which fires only when the event
192
- * element changes.
193
- */
194
-
195
- function latch(event) {
196
- let firstCall = true;
197
- let cache;
198
- return filter(event, value => {
199
- const shouldEmit = firstCall || value !== cache;
200
- firstCall = false;
201
- cache = value;
202
- return shouldEmit;
203
- });
204
- }
205
-
206
- Event.latch = latch;
207
- /**
208
- * Buffers the provided event until a first listener comes
209
- * along, at which point fire all the events at once and
210
- * pipe the event from then on.
211
- *
212
- * ```typescript
213
- * const emitter = new Emitter<number>();
214
- * const event = emitter.event;
215
- * const bufferedEvent = buffer(event);
216
- *
217
- * emitter.fire(1);
218
- * emitter.fire(2);
219
- * emitter.fire(3);
220
- * // nothing...
221
- *
222
- * const listener = bufferedEvent(num => console.log(num));
223
- * // 1, 2, 3
224
- *
225
- * emitter.fire(4);
226
- * // 4
227
- * ```
228
- */
229
-
230
- function buffer(event, nextTick = false, _buffer = []) {
231
- let buffer = _buffer.slice();
232
-
233
- let listener = event(e => {
234
- if (buffer) {
235
- buffer.push(e);
236
- } else {
237
- emitter.fire(e);
238
- }
239
- });
240
-
241
- const flush = () => {
242
- if (buffer) {
243
- buffer.forEach(e => emitter.fire(e));
244
- }
245
-
246
- buffer = null;
247
- };
248
-
249
- const emitter = new Emitter({
250
- onFirstListenerAdd() {
251
- if (!listener) {
252
- listener = event(e => emitter.fire(e));
253
- }
254
- },
255
-
256
- onFirstListenerDidAdd() {
257
- if (buffer) {
258
- if (nextTick) {
259
- setTimeout(flush);
260
- } else {
261
- flush();
262
- }
263
- }
264
- },
265
-
266
- onLastListenerRemove() {
267
- if (listener) {
268
- listener.dispose();
269
- }
270
-
271
- listener = null;
272
- }
273
-
274
- });
275
- return emitter.event;
276
- }
277
-
278
- Event.buffer = buffer;
279
-
280
- class ChainableEvent {
281
- constructor(event) {
282
- this.event = event;
283
- }
284
-
285
- map(fn) {
286
- return new ChainableEvent(map(this.event, fn));
287
- }
288
-
289
- forEach(fn) {
290
- return new ChainableEvent(forEach(this.event, fn));
291
- }
292
-
293
- filter(fn) {
294
- return new ChainableEvent(filter(this.event, fn));
295
- }
296
-
297
- reduce(merge, initial) {
298
- return new ChainableEvent(reduce(this.event, merge, initial));
299
- }
300
-
301
- latch() {
302
- return new ChainableEvent(latch(this.event));
303
- }
304
-
305
- debounce(merge, delay = 100, leading = false, leakWarningThreshold) {
306
- return new ChainableEvent(debounce(this.event, merge, delay, leading, leakWarningThreshold));
307
- }
308
-
309
- on(listener, thisArgs, disposables) {
310
- return this.event(listener, thisArgs, disposables);
311
- }
312
-
313
- once(listener, thisArgs, disposables) {
314
- return once(this.event)(listener, thisArgs, disposables);
315
- }
316
-
317
- }
318
-
319
- function chain(event) {
320
- return new ChainableEvent(event);
321
- }
322
-
323
- Event.chain = chain;
324
-
325
- function fromNodeEventEmitter(emitter, eventName, map = id => id) {
326
- const fn = (...args) => result.fire(map(...args));
327
-
328
- const onFirstListenerAdd = () => emitter.on(eventName, fn);
329
-
330
- const onLastListenerRemove = () => emitter.removeListener(eventName, fn);
331
-
332
- const result = new Emitter({
333
- onFirstListenerAdd,
334
- onLastListenerRemove
335
- });
336
- return result.event;
337
- }
338
-
339
- Event.fromNodeEventEmitter = fromNodeEventEmitter;
340
-
341
- function fromDOMEventEmitter(emitter, eventName, map = id => id) {
342
- const fn = (...args) => result.fire(map(...args));
343
-
344
- const onFirstListenerAdd = () => emitter.addEventListener(eventName, fn);
345
-
346
- const onLastListenerRemove = () => emitter.removeEventListener(eventName, fn);
347
-
348
- const result = new Emitter({
349
- onFirstListenerAdd,
350
- onLastListenerRemove
351
- });
352
- return result.event;
353
- }
354
-
355
- Event.fromDOMEventEmitter = fromDOMEventEmitter;
356
-
357
- function fromPromise(promise) {
358
- const emitter = new Emitter();
359
- let shouldEmit = false;
360
- promise.then(undefined, () => null).then(() => {
361
- if (!shouldEmit) {
362
- setTimeout(() => emitter.fire(undefined), 0);
363
- } else {
364
- emitter.fire(undefined);
365
- }
366
- });
367
- shouldEmit = true;
368
- return emitter.event;
369
- }
370
-
371
- Event.fromPromise = fromPromise;
372
-
373
- function toPromise(event) {
374
- return new Promise(c => once(event)(c));
375
- }
376
-
377
- Event.toPromise = toPromise;
378
- })(Event = exports.Event || (exports.Event = {}));
379
-
380
- let _globalLeakWarningThreshold = -1;
381
-
382
- function setGlobalLeakWarningThreshold(n) {
383
- const oldValue = _globalLeakWarningThreshold;
384
- _globalLeakWarningThreshold = n;
385
- return {
386
- dispose() {
387
- _globalLeakWarningThreshold = oldValue;
388
- }
389
-
390
- };
391
- }
392
-
393
- exports.setGlobalLeakWarningThreshold = setGlobalLeakWarningThreshold;
394
-
395
- class LeakageMonitor {
396
- constructor(customThreshold, name = Math.random().toString(18).slice(2, 5)) {
397
- this.customThreshold = customThreshold;
398
- this.name = name;
399
- this._warnCountdown = 0;
400
- }
401
-
402
- dispose() {
403
- if (this._stacks) {
404
- this._stacks.clear();
405
- }
406
- }
407
-
408
- check(listenerCount) {
409
- let threshold = _globalLeakWarningThreshold;
410
-
411
- if (typeof this.customThreshold === 'number') {
412
- threshold = this.customThreshold;
413
- }
414
-
415
- if (threshold <= 0 || listenerCount < threshold) {
416
- return undefined;
417
- }
418
-
419
- if (!this._stacks) {
420
- this._stacks = new Map();
421
- }
422
-
423
- const stack = new Error().stack.split('\n').slice(3).join('\n');
424
- const count = this._stacks.get(stack) || 0;
425
-
426
- this._stacks.set(stack, count + 1);
427
-
428
- this._warnCountdown -= 1;
429
-
430
- if (this._warnCountdown <= 0) {
431
- // only warn on first exceed and then every time the limit
432
- // is exceeded by 50% again
433
- this._warnCountdown = threshold * 0.5; // find most frequent listener and print warning
434
-
435
- let topStack;
436
- let topCount = 0;
437
-
438
- for (const [stack, count] of this._stacks) {
439
- if (!topStack || topCount < count) {
440
- topStack = stack;
441
- topCount = count;
442
- }
443
- }
444
-
445
- console.warn(`[${this.name}] potential listener LEAK detected, having ${listenerCount} listeners already. MOST frequent listener (${topCount}):`);
446
- console.warn(topStack);
447
- }
448
-
449
- return () => {
450
- const count = this._stacks.get(stack) || 0;
451
-
452
- this._stacks.set(stack, count - 1);
453
- };
454
- }
455
-
456
- }
457
- /**
458
- * The Emitter can be used to expose an Event to the public
459
- * to fire it from the insides.
460
- * Sample:
461
- class Document {
462
-
463
- private readonly _onDidChange = new Emitter<(value:string)=>any>();
464
-
465
- public onDidChange = this._onDidChange.event;
466
-
467
- // getter-style
468
- // get onDidChange(): Event<(value:string)=>any> {
469
- // return this._onDidChange.event;
470
- // }
471
-
472
- private _doIt() {
473
- //...
474
- this._onDidChange.fire(value);
475
- }
476
- }
477
- */
478
-
479
-
480
- class Emitter {
481
- constructor(options) {
482
- this._disposed = false;
483
- this._options = options;
484
- this._leakageMon = _globalLeakWarningThreshold > 0 ? new LeakageMonitor(this._options && this._options.leakWarningThreshold) : undefined;
485
- }
486
- /**
487
- * For the public to allow to subscribe
488
- * to events from this Emitter
489
- */
490
-
491
-
492
- get event() {
493
- if (!this._event) {
494
- this._event = (listener, thisArgs, disposables) => {
495
- if (!this._listeners) {
496
- this._listeners = new linkedList_1.LinkedList();
497
- }
498
-
499
- const firstListener = this._listeners.isEmpty();
500
-
501
- if (firstListener && this._options && this._options.onFirstListenerAdd) {
502
- this._options.onFirstListenerAdd(this);
503
- }
504
-
505
- const remove = this._listeners.push(!thisArgs ? listener : [listener, thisArgs]);
506
-
507
- if (firstListener && this._options && this._options.onFirstListenerDidAdd) {
508
- this._options.onFirstListenerDidAdd(this);
509
- }
510
-
511
- if (this._options && this._options.onListenerDidAdd) {
512
- this._options.onListenerDidAdd(this, listener, thisArgs);
513
- } // check and record this emitter for potential leakage
514
-
515
-
516
- let removeMonitor;
517
-
518
- if (this._leakageMon) {
519
- removeMonitor = this._leakageMon.check(this._listeners.size);
520
- }
521
-
522
- let result;
523
- result = {
524
- dispose: () => {
525
- if (removeMonitor) {
526
- removeMonitor();
527
- }
528
-
529
- result.dispose = Emitter._noop;
530
-
531
- if (!this._disposed) {
532
- remove();
533
-
534
- if (this._options && this._options.onLastListenerRemove) {
535
- const hasListeners = this._listeners && !this._listeners.isEmpty();
536
-
537
- if (!hasListeners) {
538
- this._options.onLastListenerRemove(this);
539
- }
540
- }
541
- }
542
- }
543
- };
544
-
545
- if (disposables instanceof lifecycle_1.DisposableStore) {
546
- disposables.add(result);
547
- } else if (Array.isArray(disposables)) {
548
- disposables.push(result);
549
- }
550
-
551
- return result;
552
- };
553
- }
554
-
555
- return this._event;
556
- }
557
- /**
558
- * To be kept private to fire an event to
559
- * subscribers
560
- */
561
-
562
-
563
- fire(event) {
564
- if (this._listeners) {
565
- // put all [listener,event]-pairs into delivery queue
566
- // then emit all event. an inner/nested event might be
567
- // the driver of this
568
- if (!this._deliveryQueue) {
569
- this._deliveryQueue = new linkedList_1.LinkedList();
570
- }
571
-
572
- for (let listener of this._listeners) {
573
- this._deliveryQueue.push([listener, event]);
574
- }
575
-
576
- while (this._deliveryQueue.size > 0) {
577
- const [listener, event] = this._deliveryQueue.shift();
578
-
579
- try {
580
- if (typeof listener === 'function') {
581
- listener.call(undefined, event);
582
- } else {
583
- listener[0].call(listener[1], event);
584
- }
585
- } catch (e) {
586
- errors_1.onUnexpectedError(e);
587
- }
588
- }
589
- }
590
- }
591
-
592
- dispose() {
593
- if (this._listeners) {
594
- this._listeners.clear();
595
- }
596
-
597
- if (this._deliveryQueue) {
598
- this._deliveryQueue.clear();
599
- }
600
-
601
- if (this._leakageMon) {
602
- this._leakageMon.dispose();
603
- }
604
-
605
- this._disposed = true;
606
- }
607
-
608
- }
609
-
610
- exports.Emitter = Emitter;
611
-
612
- Emitter._noop = function () {};
613
-
614
- class PauseableEmitter extends Emitter {
615
- constructor(options) {
616
- super(options);
617
- this._isPaused = 0;
618
- this._eventQueue = new linkedList_1.LinkedList();
619
- this._mergeFn = options && options.merge;
620
- }
621
-
622
- pause() {
623
- this._isPaused++;
624
- }
625
-
626
- resume() {
627
- if (this._isPaused !== 0 && --this._isPaused === 0) {
628
- if (this._mergeFn) {
629
- // use the merge function to create a single composite
630
- // event. make a copy in case firing pauses this emitter
631
- const events = this._eventQueue.toArray();
632
-
633
- this._eventQueue.clear();
634
-
635
- super.fire(this._mergeFn(events));
636
- } else {
637
- // no merging, fire each event individually and test
638
- // that this emitter isn't paused halfway through
639
- while (!this._isPaused && this._eventQueue.size !== 0) {
640
- super.fire(this._eventQueue.shift());
641
- }
642
- }
643
- }
644
- }
645
-
646
- fire(event) {
647
- if (this._listeners) {
648
- if (this._isPaused !== 0) {
649
- this._eventQueue.push(event);
650
- } else {
651
- super.fire(event);
652
- }
653
- }
654
- }
655
-
656
- }
657
-
658
- exports.PauseableEmitter = PauseableEmitter;
659
-
660
- class AsyncEmitter extends Emitter {
661
- async fireAsync(data, token, promiseJoin) {
662
- if (!this._listeners) {
663
- return;
664
- }
665
-
666
- if (!this._asyncDeliveryQueue) {
667
- this._asyncDeliveryQueue = new linkedList_1.LinkedList();
668
- }
669
-
670
- for (const listener of this._listeners) {
671
- this._asyncDeliveryQueue.push([listener, data]);
672
- }
673
-
674
- while (this._asyncDeliveryQueue.size > 0 && !token.isCancellationRequested) {
675
- const [listener, data] = this._asyncDeliveryQueue.shift();
676
-
677
- const thenables = [];
678
- const event = { ...data,
679
- waitUntil: p => {
680
- if (Object.isFrozen(thenables)) {
681
- throw new Error('waitUntil can NOT be called asynchronous');
682
- }
683
-
684
- if (promiseJoin) {
685
- p = promiseJoin(p, typeof listener === 'function' ? listener : listener[0]);
686
- }
687
-
688
- thenables.push(p);
689
- }
690
- };
691
-
692
- try {
693
- if (typeof listener === 'function') {
694
- listener.call(undefined, event);
695
- } else {
696
- listener[0].call(listener[1], event);
697
- }
698
- } catch (e) {
699
- errors_1.onUnexpectedError(e);
700
- continue;
701
- } // freeze thenables-collection to enforce sync-calls to
702
- // wait until and then wait for all thenables to resolve
703
-
704
-
705
- Object.freeze(thenables);
706
- await Promise.all(thenables).catch(e => errors_1.onUnexpectedError(e));
707
- }
708
- }
709
-
710
- }
711
-
712
- exports.AsyncEmitter = AsyncEmitter;
713
-
714
- class EventMultiplexer {
715
- constructor() {
716
- this.hasListeners = false;
717
- this.events = [];
718
- this.emitter = new Emitter({
719
- onFirstListenerAdd: () => this.onFirstListenerAdd(),
720
- onLastListenerRemove: () => this.onLastListenerRemove()
721
- });
722
- }
723
-
724
- get event() {
725
- return this.emitter.event;
726
- }
727
-
728
- add(event) {
729
- const e = {
730
- event: event,
731
- listener: null
732
- };
733
- this.events.push(e);
734
-
735
- if (this.hasListeners) {
736
- this.hook(e);
737
- }
738
-
739
- const dispose = () => {
740
- if (this.hasListeners) {
741
- this.unhook(e);
742
- }
743
-
744
- const idx = this.events.indexOf(e);
745
- this.events.splice(idx, 1);
746
- };
747
-
748
- return lifecycle_1.toDisposable(functional_1.once(dispose));
749
- }
750
-
751
- onFirstListenerAdd() {
752
- this.hasListeners = true;
753
- this.events.forEach(e => this.hook(e));
754
- }
755
-
756
- onLastListenerRemove() {
757
- this.hasListeners = false;
758
- this.events.forEach(e => this.unhook(e));
759
- }
760
-
761
- hook(e) {
762
- e.listener = e.event(r => this.emitter.fire(r));
763
- }
764
-
765
- unhook(e) {
766
- if (e.listener) {
767
- e.listener.dispose();
768
- }
769
-
770
- e.listener = null;
771
- }
772
-
773
- dispose() {
774
- this.emitter.dispose();
775
- }
776
-
777
- }
778
-
779
- exports.EventMultiplexer = EventMultiplexer;
780
- /**
781
- * The EventBufferer is useful in situations in which you want
782
- * to delay firing your events during some code.
783
- * You can wrap that code and be sure that the event will not
784
- * be fired during that wrap.
785
- *
786
- * ```
787
- * const emitter: Emitter;
788
- * const delayer = new EventDelayer();
789
- * const delayedEvent = delayer.wrapEvent(emitter.event);
790
- *
791
- * delayedEvent(console.log);
792
- *
793
- * delayer.bufferEvents(() => {
794
- * emitter.fire(); // event will not be fired yet
795
- * });
796
- *
797
- * // event will only be fired at this point
798
- * ```
799
- */
800
-
801
- class EventBufferer {
802
- constructor() {
803
- this.buffers = [];
804
- }
805
-
806
- wrapEvent(event) {
807
- return (listener, thisArgs, disposables) => {
808
- return event(i => {
809
- const buffer = this.buffers[this.buffers.length - 1];
810
-
811
- if (buffer) {
812
- buffer.push(() => listener.call(thisArgs, i));
813
- } else {
814
- listener.call(thisArgs, i);
815
- }
816
- }, undefined, disposables);
817
- };
818
- }
819
-
820
- bufferEvents(fn) {
821
- const buffer = [];
822
- this.buffers.push(buffer);
823
- const r = fn();
824
- this.buffers.pop();
825
- buffer.forEach(flush => flush());
826
- return r;
827
- }
828
-
829
- }
830
-
831
- exports.EventBufferer = EventBufferer;
832
- /**
833
- * A Relay is an event forwarder which functions as a replugabble event pipe.
834
- * Once created, you can connect an input event to it and it will simply forward
835
- * events from that input event through its own `event` property. The `input`
836
- * can be changed at any point in time.
837
- */
838
-
839
- class Relay {
840
- constructor() {
841
- this.listening = false;
842
- this.inputEvent = Event.None;
843
- this.inputEventListener = lifecycle_1.Disposable.None;
844
- this.emitter = new Emitter({
845
- onFirstListenerDidAdd: () => {
846
- this.listening = true;
847
- this.inputEventListener = this.inputEvent(this.emitter.fire, this.emitter);
848
- },
849
- onLastListenerRemove: () => {
850
- this.listening = false;
851
- this.inputEventListener.dispose();
852
- }
853
- });
854
- this.event = this.emitter.event;
855
- }
856
-
857
- set input(event) {
858
- this.inputEvent = event;
859
-
860
- if (this.listening) {
861
- this.inputEventListener.dispose();
862
- this.inputEventListener = event(this.emitter.fire, this.emitter);
863
- }
864
- }
865
-
866
- dispose() {
867
- this.inputEventListener.dispose();
868
- this.emitter.dispose();
869
- }
870
-
871
- }
872
-
873
- exports.Relay = Relay;