@codingame/monaco-vscode-api 1.69.21 → 1.69.23

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/dialogs.js CHANGED
@@ -1,14 +1,908 @@
1
1
  import './polyfill.js';
2
2
  import './missing-services.js';
3
- import { g as getServiceOverride$1, D as DialogHandlerContribution } from './layout.js';
4
3
  import { _ as __decorate, a as __param, E as Emitter } from './workspace.js';
5
- import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
6
- import { DeferredPromise } from 'monaco-editor/esm/vs/base/common/async.js';
7
- import { l as IWorkbenchEnvironmentService } from './services2.js';
4
+ import { h as IProductService, l as IWorkbenchEnvironmentService } from './services2.js';
5
+ import { n, g as getServiceOverride$1, c as attachDialogStyler, B as ButtonBar, d as ButtonWithDescription } from './layout.js';
6
+ import { Widget } from 'monaco-editor/esm/vs/base/browser/ui/widget.js';
7
+ import { Codicon, CSSIcon } from 'monaco-editor/esm/vs/base/common/codicons.js';
8
+ import { Color } from 'monaco-editor/esm/vs/base/common/color.js';
9
+ import { isMacintosh, isLinux, isWindows } from 'monaco-editor/esm/vs/base/common/platform.js';
10
+ import { Disposable, DisposableStore } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
11
+ import { EventHelper, $, hide, addDisposableListener, EventType, clearNode, isAncestor, show } from 'monaco-editor/esm/vs/base/browser/dom.js';
12
+ import { localize } from 'monaco-editor/esm/vs/nls.js';
13
+ import { InputBox } from 'monaco-editor/esm/vs/base/browser/ui/inputbox/inputBox.js';
14
+ import { ActionBar } from 'monaco-editor/esm/vs/base/browser/ui/actionbar/actionbar.js';
15
+ import { Action } from 'monaco-editor/esm/vs/base/common/actions.js';
16
+ import { StandardKeyboardEvent } from 'monaco-editor/esm/vs/base/browser/keyboardEvent.js';
17
+ import { MarkdownRenderer } from 'monaco-editor/esm/vs/editor/contrib/markdownRenderer/browser/markdownRenderer.js';
18
+ import Severity from 'monaco-editor/esm/vs/base/common/severity.js';
8
19
  import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
9
- import { o as onServicesInitialized } from './tools.js';
20
+ import { ILayoutService } from 'monaco-editor/esm/vs/platform/layout/browser/layoutService.js';
21
+ import { IThemeService } from 'monaco-editor/esm/vs/platform/theme/common/themeService.js';
22
+ import { IKeybindingService } from 'monaco-editor/esm/vs/platform/keybinding/common/keybinding.js';
23
+ import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
24
+ import { IClipboardService } from 'monaco-editor/esm/vs/platform/clipboard/common/clipboardService.js';
10
25
  import { IDialogService } from 'monaco-editor/esm/vs/platform/dialogs/common/dialogs.js';
26
+ import { DeferredPromise } from 'monaco-editor/esm/vs/base/common/async.js';
27
+ import { o as onServicesInitialized } from './tools.js';
11
28
  import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/common/descriptors.js';
29
+ const defaultOpts = {
30
+ inputActiveOptionBorder: ( (Color.fromHex('#007ACC00'))),
31
+ inputActiveOptionForeground: ( (Color.fromHex('#FFFFFF'))),
32
+ inputActiveOptionBackground: ( (Color.fromHex('#0E639C50')))
33
+ };
34
+ class Toggle extends Widget {
35
+ constructor(opts) {
36
+ super();
37
+ this._onChange = this._register(( (new Emitter())));
38
+ this.onChange = this._onChange.event;
39
+ this._onKeyDown = this._register(( (new Emitter())));
40
+ this.onKeyDown = this._onKeyDown.event;
41
+ this._opts = { ...defaultOpts, ...opts };
42
+ this._checked = this._opts.isChecked;
43
+ const classes = ['monaco-custom-toggle'];
44
+ if (this._opts.icon) {
45
+ this._icon = this._opts.icon;
46
+ classes.push(...CSSIcon.asClassNameArray(this._icon));
47
+ }
48
+ if (this._opts.actionClassName) {
49
+ classes.push(...this._opts.actionClassName.split(' '));
50
+ }
51
+ if (this._checked) {
52
+ classes.push('checked');
53
+ }
54
+ this.domNode = document.createElement('div');
55
+ this.domNode.title = this._opts.title;
56
+ this.domNode.classList.add(...classes);
57
+ if (!this._opts.notFocusable) {
58
+ this.domNode.tabIndex = 0;
59
+ }
60
+ this.domNode.setAttribute('role', 'checkbox');
61
+ this.domNode.setAttribute('aria-checked', String(this._checked));
62
+ this.domNode.setAttribute('aria-label', this._opts.title);
63
+ this.applyStyles();
64
+ this.onclick(this.domNode, (ev) => {
65
+ if (this.enabled) {
66
+ this.checked = !this._checked;
67
+ this._onChange.fire(false);
68
+ ev.preventDefault();
69
+ }
70
+ });
71
+ this.ignoreGesture(this.domNode);
72
+ this.onkeydown(this.domNode, (keyboardEvent) => {
73
+ if (keyboardEvent.keyCode === 10 || keyboardEvent.keyCode === 3 ) {
74
+ this.checked = !this._checked;
75
+ this._onChange.fire(true);
76
+ keyboardEvent.preventDefault();
77
+ keyboardEvent.stopPropagation();
78
+ return;
79
+ }
80
+ this._onKeyDown.fire(keyboardEvent);
81
+ });
82
+ }
83
+ get enabled() {
84
+ return this.domNode.getAttribute('aria-disabled') !== 'true';
85
+ }
86
+ focus() {
87
+ this.domNode.focus();
88
+ }
89
+ get checked() {
90
+ return this._checked;
91
+ }
92
+ set checked(newIsChecked) {
93
+ this._checked = newIsChecked;
94
+ this.domNode.setAttribute('aria-checked', String(this._checked));
95
+ this.domNode.classList.toggle('checked', this._checked);
96
+ this.applyStyles();
97
+ }
98
+ setIcon(icon) {
99
+ if (this._icon) {
100
+ this.domNode.classList.remove(...CSSIcon.asClassNameArray(this._icon));
101
+ }
102
+ this._icon = icon;
103
+ if (this._icon) {
104
+ this.domNode.classList.add(...CSSIcon.asClassNameArray(this._icon));
105
+ }
106
+ }
107
+ width() {
108
+ return 2 + 2 + 2 + 16 ;
109
+ }
110
+ style(styles) {
111
+ if (styles.inputActiveOptionBorder) {
112
+ this._opts.inputActiveOptionBorder = styles.inputActiveOptionBorder;
113
+ }
114
+ if (styles.inputActiveOptionForeground) {
115
+ this._opts.inputActiveOptionForeground = styles.inputActiveOptionForeground;
116
+ }
117
+ if (styles.inputActiveOptionBackground) {
118
+ this._opts.inputActiveOptionBackground = styles.inputActiveOptionBackground;
119
+ }
120
+ this.applyStyles();
121
+ }
122
+ applyStyles() {
123
+ if (this.domNode) {
124
+ this.domNode.style.borderColor = this._checked && this._opts.inputActiveOptionBorder ? ( (this._opts.inputActiveOptionBorder.toString())) : '';
125
+ this.domNode.style.color = this._checked && this._opts.inputActiveOptionForeground ? ( (this._opts.inputActiveOptionForeground.toString())) : 'inherit';
126
+ this.domNode.style.backgroundColor = this._checked && this._opts.inputActiveOptionBackground ? ( (this._opts.inputActiveOptionBackground.toString())) : '';
127
+ }
128
+ }
129
+ enable() {
130
+ this.domNode.setAttribute('aria-disabled', String(false));
131
+ }
132
+ disable() {
133
+ this.domNode.setAttribute('aria-disabled', String(true));
134
+ }
135
+ setTitle(newTitle) {
136
+ this.domNode.title = newTitle;
137
+ this.domNode.setAttribute('aria-label', newTitle);
138
+ }
139
+ }
140
+ class Checkbox extends Widget {
141
+ constructor(title, isChecked) {
142
+ super();
143
+ this.title = title;
144
+ this.isChecked = isChecked;
145
+ this.checkbox = ( (new Toggle(
146
+ { title: this.title, isChecked: this.isChecked, icon: Codicon.check, actionClassName: 'monaco-checkbox' }
147
+ )));
148
+ this.domNode = this.checkbox.domNode;
149
+ this.styles = {};
150
+ this.checkbox.onChange(() => {
151
+ this.applyStyles();
152
+ });
153
+ }
154
+ get checked() {
155
+ return this.checkbox.checked;
156
+ }
157
+ set checked(newIsChecked) {
158
+ this.checkbox.checked = newIsChecked;
159
+ this.applyStyles();
160
+ }
161
+ focus() {
162
+ this.domNode.focus();
163
+ }
164
+ hasFocus() {
165
+ return this.domNode === document.activeElement;
166
+ }
167
+ style(styles) {
168
+ this.styles = styles;
169
+ this.applyStyles();
170
+ }
171
+ applyStyles() {
172
+ this.domNode.style.color = this.styles.checkboxForeground ? ( (this.styles.checkboxForeground.toString())) : '';
173
+ this.domNode.style.backgroundColor = this.styles.checkboxBackground ? ( (this.styles.checkboxBackground.toString())) : '';
174
+ this.domNode.style.borderColor = this.styles.checkboxBorder ? ( (this.styles.checkboxBorder.toString())) : '';
175
+ }
176
+ }
177
+ function mnemonicButtonLabel(label, forceDisableMnemonics) {
178
+ if (isMacintosh || forceDisableMnemonics) {
179
+ return label.replace(/\(&&\w\)|&&/g, '');
180
+ }
181
+ if (isWindows) {
182
+ return label.replace(/&&|&/g, m => m === '&' ? '&&' : '&');
183
+ }
184
+ return label.replace(/&&/g, '_');
185
+ }
186
+ var css = "/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\n/** Dialog: Modal Block */\n.monaco-dialog-modal-block {\n\tposition: fixed;\n\theight: 100%;\n\twidth: 100%;\n\tleft:0;\n\ttop:0;\n\tz-index: 2600;\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n}\n\n.monaco-dialog-modal-block.dimmed {\n\tbackground: rgba(0, 0, 0, 0.3);\n}\n\n/** Dialog: Container */\n.monaco-dialog-box {\n\tdisplay: flex;\n\tflex-direction: column-reverse;\n\twidth: min-content;\n\tmin-width: 500px;\n\tmax-width: 90vw;\n\tmin-height: 75px;\n\tpadding: 10px;\n\ttransform: translate3d(0px, 0px, 0px);\n}\n\n/** Dialog: Title Actions Row */\n.monaco-dialog-box .dialog-toolbar-row {\n\theight: 22px;\n\tpadding-bottom: 4px;\n}\n\n.monaco-dialog-box .dialog-toolbar-row .actions-container {\n\tjustify-content: flex-end;\n}\n\n/** Dialog: Message Row */\n.monaco-dialog-box .dialog-message-row {\n\tdisplay: flex;\n\tflex-grow: 1;\n\talign-items: center;\n\tpadding: 0 10px;\n}\n\n.monaco-dialog-box .dialog-message-row > .dialog-icon.codicon {\n\tflex: 0 0 48px;\n\theight: 48px;\n\talign-self: baseline;\n\tfont-size: 48px;\n}\n\n/** Dialog: Message Container */\n.monaco-dialog-box .dialog-message-row .dialog-message-container {\n\tdisplay: flex;\n\tflex-direction: column;\n\toverflow: hidden;\n\ttext-overflow: ellipsis;\n\tpadding-left: 24px;\n\tuser-select: text;\n\t-webkit-user-select: text;\n\t-ms-user-select: text;\n\tword-wrap: break-word; /* never overflow long words, but break to next line */\n\twhite-space: normal;\n}\n\n/** Dialog: Message */\n.monaco-dialog-box .dialog-message-row .dialog-message-container .dialog-message {\n\tline-height: 22px;\n\tfont-size: 18px;\n\tflex: 1; /* let the message always grow */\n\twhite-space: normal;\n\tword-wrap: break-word; /* never overflow long words, but break to next line */\n\tmin-height: 48px; /* matches icon height */\n\tmargin-bottom: 8px;\n\tdisplay: flex;\n\talign-items: center;\n}\n\n/** Dialog: Details */\n.monaco-dialog-box .dialog-message-row .dialog-message-container .dialog-message-detail {\n\tline-height: 22px;\n\tflex: 1; /* let the message always grow */\n}\n\n.monaco-dialog-box .dialog-message-row .dialog-message-container .dialog-message a:focus {\n\toutline-width: 1px;\n\toutline-style: solid;\n}\n\n/** Dialog: Checkbox */\n.monaco-dialog-box .dialog-message-row .dialog-message-container .dialog-checkbox-row {\n\tpadding: 15px 0px 0px;\n\tdisplay: flex;\n}\n\n.monaco-dialog-box .dialog-message-row .dialog-message-container .dialog-checkbox-row .dialog-checkbox-message {\n\tcursor: pointer;\n\tuser-select: none;\n\t-webkit-user-select: none;\n\t-ms-user-select: none;\n}\n\n/** Dialog: Input */\n.monaco-dialog-box .dialog-message-row .dialog-message-container .dialog-message-input {\n\tpadding: 15px 0px 0px;\n\tdisplay: flex;\n}\n\n.monaco-dialog-box .dialog-message-row .dialog-message-container .dialog-message-input .monaco-inputbox {\n\tflex: 1;\n}\n\n/** Dialog: File Path */\n.monaco-dialog-box code {\n\tfont-family: var(--monaco-monospace-font);\n}\n\n/** Dialog: Buttons Row */\n.monaco-dialog-box > .dialog-buttons-row {\n\tdisplay: flex;\n\talign-items: center;\n\tpadding-right: 1px;\n\toverflow: hidden; /* buttons row should never overflow */\n}\n\n.monaco-dialog-box > .dialog-buttons-row {\n\tdisplay: flex;\n\twhite-space: nowrap;\n\tpadding: 20px 10px 10px;\n}\n\n/** Dialog: Buttons */\n.monaco-dialog-box > .dialog-buttons-row > .dialog-buttons {\n\tdisplay: flex;\n\twidth: 100%;\n\tjustify-content: flex-end;\n\toverflow: hidden;\n\tmargin-left: 67px; /* for long buttons, force align with text */\n}\n\n.monaco-dialog-box > .dialog-buttons-row > .dialog-buttons > .monaco-button {\n\twidth: fit-content;\n\twidth: -moz-fit-content;\n\tpadding: 5px 10px;\n\toverflow: hidden;\n\ttext-overflow: ellipsis;\n\tmargin: 4px 5px; /* allows button focus outline to be visible */\n\toutline-offset: 2px !important;\n}\n";
187
+ n(css,{});
188
+ class Dialog extends Disposable {
189
+ constructor(container, message, buttons, options) {
190
+ super();
191
+ this.container = container;
192
+ this.message = message;
193
+ this.options = options;
194
+ this.modalElement = this.container.appendChild($(`.monaco-dialog-modal-block.dimmed`));
195
+ this.shadowElement = this.modalElement.appendChild($('.dialog-shadow'));
196
+ this.element = this.shadowElement.appendChild($('.monaco-dialog-box'));
197
+ this.element.setAttribute('role', 'dialog');
198
+ this.element.tabIndex = -1;
199
+ hide(this.element);
200
+ if (Array.isArray(buttons) && buttons.length > 0) {
201
+ this.buttons = buttons;
202
+ }
203
+ else if (!this.options.disableDefaultAction) {
204
+ this.buttons = [( (localize('ok', "OK")))];
205
+ }
206
+ else {
207
+ this.buttons = [];
208
+ }
209
+ const buttonsRowElement = this.element.appendChild($('.dialog-buttons-row'));
210
+ this.buttonsContainer = buttonsRowElement.appendChild($('.dialog-buttons'));
211
+ const messageRowElement = this.element.appendChild($('.dialog-message-row'));
212
+ this.iconElement = messageRowElement.appendChild($('#monaco-dialog-icon.dialog-icon'));
213
+ this.iconElement.setAttribute('aria-label', this.getIconAriaLabel());
214
+ this.messageContainer = messageRowElement.appendChild($('.dialog-message-container'));
215
+ if (this.options.detail || this.options.renderBody) {
216
+ const messageElement = this.messageContainer.appendChild($('.dialog-message'));
217
+ const messageTextElement = messageElement.appendChild($('#monaco-dialog-message-text.dialog-message-text'));
218
+ messageTextElement.innerText = this.message;
219
+ }
220
+ this.messageDetailElement = this.messageContainer.appendChild($('#monaco-dialog-message-detail.dialog-message-detail'));
221
+ if (this.options.detail || !this.options.renderBody) {
222
+ this.messageDetailElement.innerText = this.options.detail ? this.options.detail : message;
223
+ }
224
+ else {
225
+ this.messageDetailElement.style.display = 'none';
226
+ }
227
+ if (this.options.renderBody) {
228
+ const customBody = this.messageContainer.appendChild($('#monaco-dialog-message-body.dialog-message-body'));
229
+ this.options.renderBody(customBody);
230
+ for (const el of this.messageContainer.querySelectorAll('a')) {
231
+ el.tabIndex = 0;
232
+ }
233
+ }
234
+ if (this.options.inputs) {
235
+ this.inputs = this.options.inputs.map(input => {
236
+ const inputRowElement = this.messageContainer.appendChild($('.dialog-message-input'));
237
+ const inputBox = this._register(( (new InputBox(inputRowElement, undefined, {
238
+ placeholder: input.placeholder,
239
+ type: input.type ?? 'text',
240
+ }))));
241
+ if (input.value) {
242
+ inputBox.value = input.value;
243
+ }
244
+ return inputBox;
245
+ });
246
+ }
247
+ else {
248
+ this.inputs = [];
249
+ }
250
+ if (this.options.checkboxLabel) {
251
+ const checkboxRowElement = this.messageContainer.appendChild($('.dialog-checkbox-row'));
252
+ const checkbox = this.checkbox = this._register(( (new Checkbox(this.options.checkboxLabel, !!this.options.checkboxChecked))));
253
+ checkboxRowElement.appendChild(checkbox.domNode);
254
+ const checkboxMessageElement = checkboxRowElement.appendChild($('.dialog-checkbox-message'));
255
+ checkboxMessageElement.innerText = this.options.checkboxLabel;
256
+ this._register(addDisposableListener(checkboxMessageElement, EventType.CLICK, () => checkbox.checked = !checkbox.checked));
257
+ }
258
+ const toolbarRowElement = this.element.appendChild($('.dialog-toolbar-row'));
259
+ this.toolbarContainer = toolbarRowElement.appendChild($('.dialog-toolbar'));
260
+ }
261
+ getIconAriaLabel() {
262
+ const typeLabel = ( (localize('dialogInfoMessage', 'Info')));
263
+ return typeLabel;
264
+ }
265
+ updateMessage(message) {
266
+ this.messageDetailElement.innerText = message;
267
+ }
268
+ async show() {
269
+ this.focusToReturn = document.activeElement;
270
+ return (
271
+ (new Promise((resolve) => {
272
+ clearNode(this.buttonsContainer);
273
+ const buttonBar = this.buttonBar = this._register(( (new ButtonBar(this.buttonsContainer))));
274
+ const buttonMap = this.rearrangeButtons(this.buttons, this.options.cancelId);
275
+ buttonMap.forEach((entry, index) => {
276
+ const primary = buttonMap[index].index === 0;
277
+ const button = this.options.buttonDetails ? this._register(buttonBar.addButtonWithDescription({ title: true, secondary: !primary })) : this._register(buttonBar.addButton({ title: true, secondary: !primary }));
278
+ button.label = mnemonicButtonLabel(buttonMap[index].label, true);
279
+ if (button instanceof ButtonWithDescription) {
280
+ button.description = this.options.buttonDetails[buttonMap[index].index];
281
+ }
282
+ this._register(button.onDidClick(e => {
283
+ if (e) {
284
+ EventHelper.stop(e);
285
+ }
286
+ resolve({
287
+ button: buttonMap[index].index,
288
+ checkboxChecked: this.checkbox ? this.checkbox.checked : undefined,
289
+ values: this.inputs.length > 0 ? this.inputs.map(input => input.value) : undefined
290
+ });
291
+ }));
292
+ });
293
+ this._register(addDisposableListener(window, 'keydown', e => {
294
+ const evt = ( (new StandardKeyboardEvent(e)));
295
+ if (evt.equals(512 )) {
296
+ evt.preventDefault();
297
+ }
298
+ if (evt.equals(3 )) {
299
+ if (this.inputs.some(input => input.hasFocus())) {
300
+ EventHelper.stop(e);
301
+ resolve({
302
+ button: buttonMap.find(button => button.index !== this.options.cancelId)?.index ?? 0,
303
+ checkboxChecked: this.checkbox ? this.checkbox.checked : undefined,
304
+ values: this.inputs.length > 0 ? this.inputs.map(input => input.value) : undefined
305
+ });
306
+ }
307
+ return;
308
+ }
309
+ if (evt.equals(10 )) {
310
+ return;
311
+ }
312
+ let eventHandled = false;
313
+ if (evt.equals(2 ) || evt.equals(17 ) || evt.equals(1024 | 2 ) || evt.equals(15 )) {
314
+ const focusableElements = [];
315
+ let focusedIndex = -1;
316
+ if (this.messageContainer) {
317
+ const links = this.messageContainer.querySelectorAll('a');
318
+ for (const link of links) {
319
+ focusableElements.push(link);
320
+ if (link === document.activeElement) {
321
+ focusedIndex = focusableElements.length - 1;
322
+ }
323
+ }
324
+ }
325
+ for (const input of this.inputs) {
326
+ focusableElements.push(input);
327
+ if (input.hasFocus()) {
328
+ focusedIndex = focusableElements.length - 1;
329
+ }
330
+ }
331
+ if (this.checkbox) {
332
+ focusableElements.push(this.checkbox);
333
+ if (this.checkbox.hasFocus()) {
334
+ focusedIndex = focusableElements.length - 1;
335
+ }
336
+ }
337
+ if (this.buttonBar) {
338
+ for (const button of this.buttonBar.buttons) {
339
+ focusableElements.push(button);
340
+ if (button.hasFocus()) {
341
+ focusedIndex = focusableElements.length - 1;
342
+ }
343
+ }
344
+ }
345
+ if (evt.equals(2 ) || evt.equals(17 )) {
346
+ if (focusedIndex === -1) {
347
+ focusedIndex = 0;
348
+ }
349
+ const newFocusedIndex = (focusedIndex + 1) % focusableElements.length;
350
+ focusableElements[newFocusedIndex].focus();
351
+ }
352
+ else {
353
+ if (focusedIndex === -1) {
354
+ focusedIndex = focusableElements.length;
355
+ }
356
+ let newFocusedIndex = focusedIndex - 1;
357
+ if (newFocusedIndex === -1) {
358
+ newFocusedIndex = focusableElements.length - 1;
359
+ }
360
+ focusableElements[newFocusedIndex].focus();
361
+ }
362
+ eventHandled = true;
363
+ }
364
+ if (eventHandled) {
365
+ EventHelper.stop(e, true);
366
+ }
367
+ else if (this.options.keyEventProcessor) {
368
+ this.options.keyEventProcessor(evt);
369
+ }
370
+ }, true));
371
+ this._register(addDisposableListener(window, 'keyup', e => {
372
+ EventHelper.stop(e, true);
373
+ const evt = ( (new StandardKeyboardEvent(e)));
374
+ if (!this.options.disableCloseAction && evt.equals(9 )) {
375
+ resolve({
376
+ button: this.options.cancelId || 0,
377
+ checkboxChecked: this.checkbox ? this.checkbox.checked : undefined
378
+ });
379
+ }
380
+ }, true));
381
+ this._register(addDisposableListener(this.element, 'focusout', e => {
382
+ if (!!e.relatedTarget && !!this.element) {
383
+ if (!isAncestor(e.relatedTarget, this.element)) {
384
+ this.focusToReturn = e.relatedTarget;
385
+ if (e.target) {
386
+ e.target.focus();
387
+ EventHelper.stop(e, true);
388
+ }
389
+ }
390
+ }
391
+ }, false));
392
+ const spinModifierClassName = 'codicon-modifier-spin';
393
+ this.iconElement.classList.remove(...Codicon.dialogError.classNamesArray, ...Codicon.dialogWarning.classNamesArray, ...Codicon.dialogInfo.classNamesArray, ...Codicon.loading.classNamesArray, spinModifierClassName);
394
+ if (this.options.icon) {
395
+ this.iconElement.classList.add(...this.options.icon.classNamesArray);
396
+ }
397
+ else {
398
+ switch (this.options.type) {
399
+ case 'error':
400
+ this.iconElement.classList.add(...Codicon.dialogError.classNamesArray);
401
+ break;
402
+ case 'warning':
403
+ this.iconElement.classList.add(...Codicon.dialogWarning.classNamesArray);
404
+ break;
405
+ case 'pending':
406
+ this.iconElement.classList.add(...Codicon.loading.classNamesArray, spinModifierClassName);
407
+ break;
408
+ case 'none':
409
+ case 'info':
410
+ case 'question':
411
+ default:
412
+ this.iconElement.classList.add(...Codicon.dialogInfo.classNamesArray);
413
+ break;
414
+ }
415
+ }
416
+ if (!this.options.disableCloseAction) {
417
+ const actionBar = this._register(( (new ActionBar(this.toolbarContainer, {}))));
418
+ const action = this._register(( (new Action(
419
+ 'dialog.close',
420
+ (localize('dialogClose', "Close Dialog")),
421
+ Codicon.dialogClose.classNames,
422
+ true,
423
+ async () => {
424
+ resolve({
425
+ button: this.options.cancelId || 0,
426
+ checkboxChecked: this.checkbox ? this.checkbox.checked : undefined
427
+ });
428
+ }
429
+ ))));
430
+ actionBar.push(action, { icon: true, label: false, });
431
+ }
432
+ this.applyStyles();
433
+ this.element.setAttribute('aria-modal', 'true');
434
+ this.element.setAttribute('aria-labelledby', 'monaco-dialog-icon monaco-dialog-message-text');
435
+ this.element.setAttribute('aria-describedby', 'monaco-dialog-icon monaco-dialog-message-text monaco-dialog-message-detail monaco-dialog-message-body');
436
+ show(this.element);
437
+ if (this.inputs.length > 0) {
438
+ this.inputs[0].focus();
439
+ this.inputs[0].select();
440
+ }
441
+ else {
442
+ buttonMap.forEach((value, index) => {
443
+ if (value.index === 0) {
444
+ buttonBar.buttons[index].focus();
445
+ }
446
+ });
447
+ }
448
+ }))
449
+ );
450
+ }
451
+ applyStyles() {
452
+ if (this.styles) {
453
+ const style = this.styles;
454
+ const fgColor = style.dialogForeground;
455
+ const bgColor = style.dialogBackground;
456
+ const shadowColor = style.dialogShadow ? `0 0px 8px ${style.dialogShadow}` : '';
457
+ const border = style.dialogBorder ? `1px solid ${style.dialogBorder}` : '';
458
+ const linkFgColor = style.textLinkForeground;
459
+ this.shadowElement.style.boxShadow = shadowColor;
460
+ this.element.style.color = fgColor?.toString() ?? '';
461
+ this.element.style.backgroundColor = bgColor?.toString() ?? '';
462
+ this.element.style.border = border;
463
+ this.buttonBar?.buttons.forEach(button => button.style(style));
464
+ this.checkbox?.style(style);
465
+ if (fgColor && bgColor) {
466
+ const messageDetailColor = ( (fgColor.transparent(.9)));
467
+ this.messageDetailElement.style.color = ( (messageDetailColor.makeOpaque(bgColor).toString()));
468
+ }
469
+ if (linkFgColor) {
470
+ for (const el of this.messageContainer.getElementsByTagName('a')) {
471
+ el.style.color = ( (linkFgColor.toString()));
472
+ }
473
+ }
474
+ let color;
475
+ switch (this.options.type) {
476
+ case 'error':
477
+ color = style.errorIconForeground;
478
+ break;
479
+ case 'warning':
480
+ color = style.warningIconForeground;
481
+ break;
482
+ default:
483
+ color = style.infoIconForeground;
484
+ break;
485
+ }
486
+ if (color) {
487
+ this.iconElement.style.color = ( (color.toString()));
488
+ }
489
+ for (const input of this.inputs) {
490
+ input.style(style);
491
+ }
492
+ }
493
+ }
494
+ style(style) {
495
+ this.styles = style;
496
+ this.applyStyles();
497
+ }
498
+ dispose() {
499
+ super.dispose();
500
+ if (this.modalElement) {
501
+ this.modalElement.remove();
502
+ this.modalElement = undefined;
503
+ }
504
+ if (this.focusToReturn && isAncestor(this.focusToReturn, document.body)) {
505
+ this.focusToReturn.focus();
506
+ this.focusToReturn = undefined;
507
+ }
508
+ }
509
+ rearrangeButtons(buttons, cancelId) {
510
+ const buttonMap = [];
511
+ if (buttons.length === 0) {
512
+ return buttonMap;
513
+ }
514
+ buttons.forEach((button, index) => {
515
+ buttonMap.push({ label: button, index });
516
+ });
517
+ if (isMacintosh || isLinux) {
518
+ if (cancelId !== undefined && cancelId < buttons.length) {
519
+ const cancelButton = buttonMap.splice(cancelId, 1)[0];
520
+ buttonMap.reverse();
521
+ buttonMap.splice(buttonMap.length - 1, 0, cancelButton);
522
+ }
523
+ }
524
+ return buttonMap;
525
+ }
526
+ }
527
+ const minute = 60;
528
+ const hour = minute * 60;
529
+ const day = hour * 24;
530
+ const week = day * 7;
531
+ const month = day * 30;
532
+ const year = day * 365;
533
+ function fromNow(date, appendAgoLabel, useFullTimeWords) {
534
+ if (typeof date !== 'number') {
535
+ date = date.getTime();
536
+ }
537
+ const seconds = Math.round((( (new Date())).getTime() - date) / 1000);
538
+ if (seconds < -30) {
539
+ return (
540
+ (localize(
541
+ 'date.fromNow.in',
542
+ 'in {0}',
543
+ fromNow(( (new Date())).getTime() + seconds * 1000, false)
544
+ ))
545
+ );
546
+ }
547
+ if (seconds < 30) {
548
+ return (
549
+ (localize('date.fromNow.now', 'now'))
550
+ );
551
+ }
552
+ let value;
553
+ if (seconds < minute) {
554
+ value = seconds;
555
+ if (appendAgoLabel) {
556
+ if (value === 1) {
557
+ return useFullTimeWords
558
+ ? ( (localize('date.fromNow.seconds.singular.ago.fullWord', '{0} second ago', value)))
559
+ : ( (localize('date.fromNow.seconds.singular.ago', '{0} sec ago', value)));
560
+ }
561
+ else {
562
+ return useFullTimeWords
563
+ ? ( (localize('date.fromNow.seconds.plural.ago.fullWord', '{0} seconds ago', value)))
564
+ : ( (localize('date.fromNow.seconds.plural.ago', '{0} secs ago', value)));
565
+ }
566
+ }
567
+ else {
568
+ if (value === 1) {
569
+ return useFullTimeWords
570
+ ? ( (localize('date.fromNow.seconds.singular.fullWord', '{0} second', value)))
571
+ : ( (localize('date.fromNow.seconds.singular', '{0} sec', value)));
572
+ }
573
+ else {
574
+ return useFullTimeWords
575
+ ? ( (localize('date.fromNow.seconds.plural.fullWord', '{0} seconds', value)))
576
+ : ( (localize('date.fromNow.seconds.plural', '{0} secs', value)));
577
+ }
578
+ }
579
+ }
580
+ if (seconds < hour) {
581
+ value = Math.floor(seconds / minute);
582
+ if (appendAgoLabel) {
583
+ if (value === 1) {
584
+ return useFullTimeWords
585
+ ? ( (localize('date.fromNow.minutes.singular.ago.fullWord', '{0} minute ago', value)))
586
+ : ( (localize('date.fromNow.minutes.singular.ago', '{0} min ago', value)));
587
+ }
588
+ else {
589
+ return useFullTimeWords
590
+ ? ( (localize('date.fromNow.minutes.plural.ago.fullWord', '{0} minutes ago', value)))
591
+ : ( (localize('date.fromNow.minutes.plural.ago', '{0} mins ago', value)));
592
+ }
593
+ }
594
+ else {
595
+ if (value === 1) {
596
+ return useFullTimeWords
597
+ ? ( (localize('date.fromNow.minutes.singular.fullWord', '{0} minute', value)))
598
+ : ( (localize('date.fromNow.minutes.singular', '{0} min', value)));
599
+ }
600
+ else {
601
+ return useFullTimeWords
602
+ ? ( (localize('date.fromNow.minutes.plural.fullWord', '{0} minutes', value)))
603
+ : ( (localize('date.fromNow.minutes.plural', '{0} mins', value)));
604
+ }
605
+ }
606
+ }
607
+ if (seconds < day) {
608
+ value = Math.floor(seconds / hour);
609
+ if (appendAgoLabel) {
610
+ if (value === 1) {
611
+ return useFullTimeWords
612
+ ? ( (localize('date.fromNow.hours.singular.ago.fullWord', '{0} hour ago', value)))
613
+ : ( (localize('date.fromNow.hours.singular.ago', '{0} hr ago', value)));
614
+ }
615
+ else {
616
+ return useFullTimeWords
617
+ ? ( (localize('date.fromNow.hours.plural.ago.fullWord', '{0} hours ago', value)))
618
+ : ( (localize('date.fromNow.hours.plural.ago', '{0} hrs ago', value)));
619
+ }
620
+ }
621
+ else {
622
+ if (value === 1) {
623
+ return useFullTimeWords
624
+ ? ( (localize('date.fromNow.hours.singular.fullWord', '{0} hour', value)))
625
+ : ( (localize('date.fromNow.hours.singular', '{0} hr', value)));
626
+ }
627
+ else {
628
+ return useFullTimeWords
629
+ ? ( (localize('date.fromNow.hours.plural.fullWord', '{0} hours', value)))
630
+ : ( (localize('date.fromNow.hours.plural', '{0} hrs', value)));
631
+ }
632
+ }
633
+ }
634
+ if (seconds < week) {
635
+ value = Math.floor(seconds / day);
636
+ if (appendAgoLabel) {
637
+ return value === 1
638
+ ? ( (localize('date.fromNow.days.singular.ago', '{0} day ago', value)))
639
+ : ( (localize('date.fromNow.days.plural.ago', '{0} days ago', value)));
640
+ }
641
+ else {
642
+ return value === 1
643
+ ? ( (localize('date.fromNow.days.singular', '{0} day', value)))
644
+ : ( (localize('date.fromNow.days.plural', '{0} days', value)));
645
+ }
646
+ }
647
+ if (seconds < month) {
648
+ value = Math.floor(seconds / week);
649
+ if (appendAgoLabel) {
650
+ if (value === 1) {
651
+ return useFullTimeWords
652
+ ? ( (localize('date.fromNow.weeks.singular.ago.fullWord', '{0} week ago', value)))
653
+ : ( (localize('date.fromNow.weeks.singular.ago', '{0} wk ago', value)));
654
+ }
655
+ else {
656
+ return useFullTimeWords
657
+ ? ( (localize('date.fromNow.weeks.plural.ago.fullWord', '{0} weeks ago', value)))
658
+ : ( (localize('date.fromNow.weeks.plural.ago', '{0} wks ago', value)));
659
+ }
660
+ }
661
+ else {
662
+ if (value === 1) {
663
+ return useFullTimeWords
664
+ ? ( (localize('date.fromNow.weeks.singular.fullWord', '{0} week', value)))
665
+ : ( (localize('date.fromNow.weeks.singular', '{0} wk', value)));
666
+ }
667
+ else {
668
+ return useFullTimeWords
669
+ ? ( (localize('date.fromNow.weeks.plural.fullWord', '{0} weeks', value)))
670
+ : ( (localize('date.fromNow.weeks.plural', '{0} wks', value)));
671
+ }
672
+ }
673
+ }
674
+ if (seconds < year) {
675
+ value = Math.floor(seconds / month);
676
+ if (appendAgoLabel) {
677
+ if (value === 1) {
678
+ return useFullTimeWords
679
+ ? ( (localize('date.fromNow.months.singular.ago.fullWord', '{0} month ago', value)))
680
+ : ( (localize('date.fromNow.months.singular.ago', '{0} mo ago', value)));
681
+ }
682
+ else {
683
+ return useFullTimeWords
684
+ ? ( (localize('date.fromNow.months.plural.ago.fullWord', '{0} months ago', value)))
685
+ : ( (localize('date.fromNow.months.plural.ago', '{0} mos ago', value)));
686
+ }
687
+ }
688
+ else {
689
+ if (value === 1) {
690
+ return useFullTimeWords
691
+ ? ( (localize('date.fromNow.months.singular.fullWord', '{0} month', value)))
692
+ : ( (localize('date.fromNow.months.singular', '{0} mo', value)));
693
+ }
694
+ else {
695
+ return useFullTimeWords
696
+ ? ( (localize('date.fromNow.months.plural.fullWord', '{0} months', value)))
697
+ : ( (localize('date.fromNow.months.plural', '{0} mos', value)));
698
+ }
699
+ }
700
+ }
701
+ value = Math.floor(seconds / year);
702
+ if (appendAgoLabel) {
703
+ if (value === 1) {
704
+ return useFullTimeWords
705
+ ? ( (localize('date.fromNow.years.singular.ago.fullWord', '{0} year ago', value)))
706
+ : ( (localize('date.fromNow.years.singular.ago', '{0} yr ago', value)));
707
+ }
708
+ else {
709
+ return useFullTimeWords
710
+ ? ( (localize('date.fromNow.years.plural.ago.fullWord', '{0} years ago', value)))
711
+ : ( (localize('date.fromNow.years.plural.ago', '{0} yrs ago', value)));
712
+ }
713
+ }
714
+ else {
715
+ if (value === 1) {
716
+ return useFullTimeWords
717
+ ? ( (localize('date.fromNow.years.singular.fullWord', '{0} year', value)))
718
+ : ( (localize('date.fromNow.years.singular', '{0} yr', value)));
719
+ }
720
+ else {
721
+ return useFullTimeWords
722
+ ? ( (localize('date.fromNow.years.plural.fullWord', '{0} years', value)))
723
+ : ( (localize('date.fromNow.years.plural', '{0} yrs', value)));
724
+ }
725
+ }
726
+ }
727
+ let BrowserDialogHandler = class BrowserDialogHandler {
728
+ constructor(logService, layoutService, themeService, keybindingService, instantiationService, productService, clipboardService) {
729
+ this.logService = logService;
730
+ this.layoutService = layoutService;
731
+ this.themeService = themeService;
732
+ this.keybindingService = keybindingService;
733
+ this.instantiationService = instantiationService;
734
+ this.productService = productService;
735
+ this.clipboardService = clipboardService;
736
+ this.markdownRenderer = this.instantiationService.createInstance(MarkdownRenderer, {});
737
+ }
738
+ async confirm(confirmation) {
739
+ this.logService.trace('DialogService#confirm', confirmation.message);
740
+ const buttons = [];
741
+ if (confirmation.primaryButton) {
742
+ buttons.push(confirmation.primaryButton);
743
+ }
744
+ else {
745
+ buttons.push(( (localize({ key: 'yesButton', comment: ['&& denotes a mnemonic'] }, "&&Yes"))));
746
+ }
747
+ if (confirmation.secondaryButton) {
748
+ buttons.push(confirmation.secondaryButton);
749
+ }
750
+ else if (typeof confirmation.secondaryButton === 'undefined') {
751
+ buttons.push(( (localize('cancelButton', "Cancel"))));
752
+ }
753
+ const result = await this.doShow(confirmation.type, confirmation.message, buttons, confirmation.detail, 1, confirmation.checkbox);
754
+ return { confirmed: result.button === 0, checkboxChecked: result.checkboxChecked };
755
+ }
756
+ getDialogType(severity) {
757
+ return (severity === Severity.Info) ? 'question' : (severity === Severity.Error) ? 'error' : (severity === Severity.Warning) ? 'warning' : 'none';
758
+ }
759
+ async show(severity, message, buttons, options) {
760
+ this.logService.trace('DialogService#show', message);
761
+ const result = await this.doShow(this.getDialogType(severity), message, buttons, options?.detail, options?.cancelId, options?.checkbox, undefined, typeof options?.custom === 'object' ? options.custom : undefined);
762
+ return {
763
+ choice: result.button,
764
+ checkboxChecked: result.checkboxChecked
765
+ };
766
+ }
767
+ async doShow(type, message, buttons, detail, cancelId, checkbox, inputs, customOptions) {
768
+ const dialogDisposables = ( (new DisposableStore()));
769
+ const renderBody = customOptions ? (parent) => {
770
+ parent.classList.add(...(customOptions.classes || []));
771
+ customOptions.markdownDetails?.forEach(markdownDetail => {
772
+ const result = this.markdownRenderer.render(markdownDetail.markdown);
773
+ parent.appendChild(result.element);
774
+ result.element.classList.add(...(markdownDetail.classes || []));
775
+ dialogDisposables.add(result);
776
+ });
777
+ } : undefined;
778
+ const dialog = ( (new Dialog(this.layoutService.container, message, buttons, {
779
+ detail,
780
+ cancelId,
781
+ type,
782
+ keyEventProcessor: (event) => {
783
+ const resolved = this.keybindingService.softDispatch(event, this.layoutService.container);
784
+ if (resolved?.commandId) {
785
+ if (BrowserDialogHandler.ALLOWABLE_COMMANDS.indexOf(resolved.commandId) === -1) {
786
+ EventHelper.stop(event, true);
787
+ }
788
+ }
789
+ },
790
+ renderBody,
791
+ icon: customOptions?.icon,
792
+ disableCloseAction: customOptions?.disableCloseAction,
793
+ buttonDetails: customOptions?.buttonDetails,
794
+ checkboxLabel: checkbox?.label,
795
+ checkboxChecked: checkbox?.checked,
796
+ inputs
797
+ })));
798
+ dialogDisposables.add(dialog);
799
+ dialogDisposables.add(attachDialogStyler(dialog, this.themeService));
800
+ const result = await dialog.show();
801
+ dialogDisposables.dispose();
802
+ return result;
803
+ }
804
+ async input(severity, message, buttons, inputs, options) {
805
+ this.logService.trace('DialogService#input', message);
806
+ const result = await this.doShow(this.getDialogType(severity), message, buttons, options?.detail, options?.cancelId, options?.checkbox, inputs);
807
+ return {
808
+ choice: result.button,
809
+ checkboxChecked: result.checkboxChecked,
810
+ values: result.values
811
+ };
812
+ }
813
+ async about() {
814
+ const detailString = (useAgo) => {
815
+ return (
816
+ (localize(
817
+ 'aboutDetail',
818
+ "Version: {0}\nCommit: {1}\nDate: {2}\nBrowser: {3}",
819
+ this.productService.version || 'Unknown',
820
+ this.productService.commit || 'Unknown',
821
+ this.productService.date ? `${this.productService.date}${useAgo ? ' (' + fromNow(( new Date(this.productService.date)), true) + ')' : ''}` : 'Unknown',
822
+ navigator.userAgent
823
+ ))
824
+ );
825
+ };
826
+ const detail = detailString(true);
827
+ const detailToCopy = detailString(false);
828
+ const { choice } = await this.show(Severity.Info, this.productService.nameLong, [( (localize('copy', "Copy"))), ( (localize('ok', "OK")))], { detail, cancelId: 1 });
829
+ if (choice === 0) {
830
+ this.clipboardService.writeText(detailToCopy);
831
+ }
832
+ }
833
+ };
834
+ BrowserDialogHandler.ALLOWABLE_COMMANDS = [
835
+ 'copy',
836
+ 'cut',
837
+ 'editor.action.selectAll',
838
+ 'editor.action.clipboardCopyAction',
839
+ 'editor.action.clipboardCutAction',
840
+ 'editor.action.clipboardPasteAction'
841
+ ];
842
+ BrowserDialogHandler = ( (__decorate([
843
+ ( (__param(0, ILogService))),
844
+ ( (__param(1, ILayoutService))),
845
+ ( (__param(2, IThemeService))),
846
+ ( (__param(3, IKeybindingService))),
847
+ ( (__param(4, IInstantiationService))),
848
+ ( (__param(5, IProductService))),
849
+ ( (__param(6, IClipboardService)))
850
+ ], BrowserDialogHandler)));
851
+ let DialogHandlerContribution = class DialogHandlerContribution extends Disposable {
852
+ constructor(dialogService, logService, layoutService, themeService, keybindingService, instantiationService, productService, clipboardService) {
853
+ super();
854
+ this.dialogService = dialogService;
855
+ this.impl = ( (new BrowserDialogHandler(
856
+ logService,
857
+ layoutService,
858
+ themeService,
859
+ keybindingService,
860
+ instantiationService,
861
+ productService,
862
+ clipboardService
863
+ )));
864
+ this.model = this.dialogService.model;
865
+ this._register(this.model.onWillShowDialog(() => {
866
+ if (!this.currentDialog) {
867
+ this.processDialogs();
868
+ }
869
+ }));
870
+ this.processDialogs();
871
+ }
872
+ async processDialogs() {
873
+ while (this.model.dialogs.length) {
874
+ this.currentDialog = this.model.dialogs[0];
875
+ let result = undefined;
876
+ if (this.currentDialog.args.confirmArgs) {
877
+ const args = this.currentDialog.args.confirmArgs;
878
+ result = await this.impl.confirm(args.confirmation);
879
+ }
880
+ else if (this.currentDialog.args.inputArgs) {
881
+ const args = this.currentDialog.args.inputArgs;
882
+ result = await this.impl.input(args.severity, args.message, args.buttons, args.inputs, args.options);
883
+ }
884
+ else if (this.currentDialog.args.showArgs) {
885
+ const args = this.currentDialog.args.showArgs;
886
+ result = await this.impl.show(args.severity, args.message, args.buttons, args.options);
887
+ }
888
+ else {
889
+ await this.impl.about();
890
+ }
891
+ this.currentDialog.close(result);
892
+ this.currentDialog = undefined;
893
+ }
894
+ }
895
+ };
896
+ DialogHandlerContribution = ( (__decorate([
897
+ ( (__param(0, IDialogService))),
898
+ ( (__param(1, ILogService))),
899
+ ( (__param(2, ILayoutService))),
900
+ ( (__param(3, IThemeService))),
901
+ ( (__param(4, IKeybindingService))),
902
+ ( (__param(5, IInstantiationService))),
903
+ ( (__param(6, IProductService))),
904
+ ( (__param(7, IClipboardService)))
905
+ ], DialogHandlerContribution)));
12
906
  class DialogsModel extends Disposable {
13
907
  constructor() {
14
908
  super(...arguments);