@codingame/monaco-vscode-update-service-override 3.2.3 → 4.1.0

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.
@@ -1,520 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
- import './media/releasenoteseditor.css.js';
3
- import { CancellationToken } from 'vscode/vscode/vs/base/common/cancellation';
4
- import { onUnexpectedError } from 'vscode/vscode/vs/base/common/errors';
5
- import { escapeMarkdownSyntaxTokens } from 'vscode/vscode/vs/base/common/htmlContent';
6
- import { KeybindingParser } from 'vscode/vscode/vs/base/common/keybindingParser';
7
- import { escape } from 'vscode/vscode/vs/base/common/strings';
8
- import { URI } from 'vscode/vscode/vs/base/common/uri';
9
- import { generateUuid } from 'vscode/vscode/vs/base/common/uuid';
10
- import { TokenizationRegistry } from 'vscode/vscode/vs/editor/common/languages';
11
- import { generateTokensCSSForColorMap } from 'vscode/vscode/vs/editor/common/languages/supports/tokenization';
12
- import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
13
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
14
- import { IEnvironmentService } from 'vscode/vscode/vs/platform/environment/common/environment';
15
- import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
16
- import { IOpenerService } from 'vscode/vscode/vs/platform/opener/common/opener';
17
- import { IProductService } from 'vscode/vscode/vs/platform/product/common/productService';
18
- import { IRequestService, asTextOrError } from 'vscode/vscode/vs/platform/request/common/request';
19
- import { renderMarkdownDocument, DEFAULT_MARKDOWN_STYLES } from 'vscode/vscode/vs/workbench/contrib/markdown/browser/markdownDocumentRenderer';
20
- import { IWebviewWorkbenchService } from 'vscode/vscode/vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService';
21
- import { IEditorGroupsService } from 'vscode/vscode/vs/workbench/services/editor/common/editorGroupsService';
22
- import { ACTIVE_GROUP, IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
23
- import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions';
24
- import { supportsTelemetry, getTelemetryLevel } from 'vscode/vscode/vs/platform/telemetry/common/telemetryUtils';
25
- import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
26
- import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
27
- import { SimpleSettingRenderer } from '../../markdown/browser/markdownSettingRenderer.js';
28
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
29
- import { Schemas } from 'vscode/vscode/vs/base/common/network';
30
- import { ICodeEditorService } from 'vscode/vscode/vs/editor/browser/services/codeEditorService';
31
-
32
- let ReleaseNotesManager = class ReleaseNotesManager {
33
- constructor(_environmentService, _keybindingService, _languageService, _openerService, _requestService, _configurationService, _editorService, _editorGroupService, _codeEditorService, _webviewWorkbenchService, _extensionService, _productService, _instantiationService) {
34
- this._environmentService = _environmentService;
35
- this._keybindingService = _keybindingService;
36
- this._languageService = _languageService;
37
- this._openerService = _openerService;
38
- this._requestService = _requestService;
39
- this._configurationService = _configurationService;
40
- this._editorService = _editorService;
41
- this._editorGroupService = _editorGroupService;
42
- this._codeEditorService = _codeEditorService;
43
- this._webviewWorkbenchService = _webviewWorkbenchService;
44
- this._extensionService = _extensionService;
45
- this._productService = _productService;
46
- this._instantiationService = _instantiationService;
47
- this._releaseNotesCache = ( new Map());
48
- this._currentReleaseNotes = undefined;
49
- this.disposables = ( new DisposableStore());
50
- TokenizationRegistry.onDidChange(() => {
51
- return this.updateHtml();
52
- });
53
- _configurationService.onDidChangeConfiguration(this.onDidChangeConfiguration, this, this.disposables);
54
- _webviewWorkbenchService.onDidChangeActiveWebviewEditor(this.onDidChangeActiveWebviewEditor, this, this.disposables);
55
- this._simpleSettingRenderer = this._instantiationService.createInstance(SimpleSettingRenderer);
56
- }
57
- async updateHtml() {
58
- if (!this._currentReleaseNotes || !this._lastText) {
59
- return;
60
- }
61
- const captureScroll = this.scrollPosition;
62
- const html = await this.renderBody(this._lastText);
63
- if (this._currentReleaseNotes) {
64
- this._currentReleaseNotes.webview.setHtml(html);
65
- this._currentReleaseNotes.webview.postMessage({ type: 'setScroll', value: { scrollPosition: captureScroll } });
66
- }
67
- }
68
- async show(version, useCurrentFile) {
69
- const releaseNoteText = await this.loadReleaseNotes(version, useCurrentFile);
70
- this._lastText = releaseNoteText;
71
- const html = await this.renderBody(releaseNoteText);
72
- const title = ( localizeWithPath(
73
- 'vs/workbench/contrib/update/browser/releaseNotesEditor',
74
- 'releaseNotesInputName',
75
- "Release Notes: {0}",
76
- version
77
- ));
78
- const activeEditorPane = this._editorService.activeEditorPane;
79
- if (this._currentReleaseNotes) {
80
- this._currentReleaseNotes.setName(title);
81
- this._currentReleaseNotes.webview.setHtml(html);
82
- this._webviewWorkbenchService.revealWebview(this._currentReleaseNotes, activeEditorPane ? activeEditorPane.group : this._editorGroupService.activeGroup, false);
83
- }
84
- else {
85
- this._currentReleaseNotes = this._webviewWorkbenchService.openWebview({
86
- title,
87
- options: {
88
- tryRestoreScrollPosition: true,
89
- enableFindWidget: true,
90
- disableServiceWorker: true,
91
- },
92
- contentOptions: {
93
- localResourceRoots: [],
94
- allowScripts: true
95
- },
96
- extension: undefined
97
- }, 'releaseNotes', title, { group: ACTIVE_GROUP, preserveFocus: false });
98
- this._currentReleaseNotes.webview.onDidClickLink(uri => this.onDidClickLink(( URI.parse(uri))));
99
- const disposables = ( new DisposableStore());
100
- disposables.add(this._currentReleaseNotes.webview.onMessage(e => {
101
- if (e.message.type === 'showReleaseNotes') {
102
- this._configurationService.updateValue('update.showReleaseNotes', e.message.value);
103
- }
104
- else if (e.message.type === 'scroll') {
105
- this.scrollPosition = e.message.value.scrollPosition;
106
- }
107
- else if (e.message.type === 'clickSetting') {
108
- const x = this._currentReleaseNotes?.webview.container.offsetLeft + e.message.value.x;
109
- const y = this._currentReleaseNotes?.webview.container.offsetTop + e.message.value.y;
110
- this._simpleSettingRenderer.updateSetting(( URI.parse(e.message.value.uri)), x, y);
111
- }
112
- }));
113
- disposables.add(this._currentReleaseNotes.onWillDispose(() => {
114
- disposables.dispose();
115
- this._currentReleaseNotes = undefined;
116
- }));
117
- this._currentReleaseNotes.webview.setHtml(html);
118
- }
119
- return true;
120
- }
121
- async loadReleaseNotes(version, useCurrentFile) {
122
- const match = /^(\d+\.\d+)\./.exec(version);
123
- if (!match) {
124
- throw new Error('not found');
125
- }
126
- const versionLabel = match[1].replace(/\./g, '_');
127
- const baseUrl = 'https://code.visualstudio.com/raw';
128
- const url = `${baseUrl}/v${versionLabel}.md`;
129
- const unassigned = ( localizeWithPath(
130
- 'vs/workbench/contrib/update/browser/releaseNotesEditor',
131
- 'unassigned',
132
- "unassigned"
133
- ));
134
- const escapeMdHtml = (text) => {
135
- return escape(text).replace(/\\/g, '\\\\');
136
- };
137
- const patchKeybindings = (text) => {
138
- const kb = (match, kb) => {
139
- const keybinding = this._keybindingService.lookupKeybinding(kb);
140
- if (!keybinding) {
141
- return unassigned;
142
- }
143
- return keybinding.getLabel() || unassigned;
144
- };
145
- const kbstyle = (match, kb) => {
146
- const keybinding = KeybindingParser.parseKeybinding(kb);
147
- if (!keybinding) {
148
- return unassigned;
149
- }
150
- const resolvedKeybindings = this._keybindingService.resolveKeybinding(keybinding);
151
- if (resolvedKeybindings.length === 0) {
152
- return unassigned;
153
- }
154
- return resolvedKeybindings[0].getLabel() || unassigned;
155
- };
156
- const kbCode = (match, binding) => {
157
- const resolved = kb(match, binding);
158
- return resolved ? `<code title="${binding}">${escapeMdHtml(resolved)}</code>` : resolved;
159
- };
160
- const kbstyleCode = (match, binding) => {
161
- const resolved = kbstyle(match, binding);
162
- return resolved ? `<code title="${binding}">${escapeMdHtml(resolved)}</code>` : resolved;
163
- };
164
- return text
165
- .replace(/`kb\(([a-z.\d\-]+)\)`/gi, kbCode)
166
- .replace(/`kbstyle\(([^\)]+)\)`/gi, kbstyleCode)
167
- .replace(/kb\(([a-z.\d\-]+)\)/gi, (match, binding) => escapeMarkdownSyntaxTokens(kb(match, binding)))
168
- .replace(/kbstyle\(([^\)]+)\)/gi, (match, binding) => escapeMarkdownSyntaxTokens(kbstyle(match, binding)));
169
- };
170
- const fetchReleaseNotes = async () => {
171
- let text;
172
- try {
173
- if (useCurrentFile) {
174
- const file = this._codeEditorService.getActiveCodeEditor()?.getModel()?.getValue();
175
- text = file ? file.substring(file.indexOf('#')) : undefined;
176
- }
177
- else {
178
- text = await asTextOrError(await this._requestService.request({ url }, CancellationToken.None));
179
- }
180
- }
181
- catch {
182
- throw new Error('Failed to fetch release notes');
183
- }
184
- if (!text || !/^#\s/.test(text)) {
185
- throw new Error('Invalid release notes');
186
- }
187
- return patchKeybindings(text);
188
- };
189
- if (useCurrentFile) {
190
- return fetchReleaseNotes();
191
- }
192
- if (!( this._releaseNotesCache.has(version))) {
193
- this._releaseNotesCache.set(version, (async () => {
194
- try {
195
- return await fetchReleaseNotes();
196
- }
197
- catch (err) {
198
- this._releaseNotesCache.delete(version);
199
- throw err;
200
- }
201
- })());
202
- }
203
- return this._releaseNotesCache.get(version);
204
- }
205
- async onDidClickLink(uri) {
206
- if (uri.scheme === Schemas.codeSetting || uri.scheme === Schemas.codeFeature) ;
207
- else {
208
- this.addGAParameters(uri, 'ReleaseNotes')
209
- .then(updated => this._openerService.open(updated, { allowCommands: ['workbench.action.openSettings'] }))
210
- .then(undefined, onUnexpectedError);
211
- }
212
- }
213
- async addGAParameters(uri, origin, experiment = '1') {
214
- if (supportsTelemetry(this._productService, this._environmentService) && getTelemetryLevel(this._configurationService) === 3 ) {
215
- if (uri.scheme === 'https' && uri.authority === 'code.visualstudio.com') {
216
- return uri.with({ query: `${uri.query ? uri.query + '&' : ''}utm_source=VsCode&utm_medium=${encodeURIComponent(origin)}&utm_content=${encodeURIComponent(experiment)}` });
217
- }
218
- }
219
- return uri;
220
- }
221
- async renderBody(text) {
222
- const nonce = generateUuid();
223
- const content = await renderMarkdownDocument(text, this._extensionService, this._languageService, false, undefined, undefined, this._simpleSettingRenderer);
224
- const colorMap = TokenizationRegistry.getColorMap();
225
- const css = colorMap ? generateTokensCSSForColorMap(colorMap) : '';
226
- const showReleaseNotes = Boolean(this._configurationService.getValue('update.showReleaseNotes'));
227
- return `<!DOCTYPE html>
228
- <html>
229
- <head>
230
- <base href="https://code.visualstudio.com/raw/">
231
- <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
232
- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https: data:; media-src https:; style-src 'nonce-${nonce}' https://code.visualstudio.com; script-src 'nonce-${nonce}';">
233
- <style nonce="${nonce}">
234
- ${DEFAULT_MARKDOWN_STYLES}
235
- ${css}
236
-
237
- /* codesetting */
238
-
239
- code:has(.codesetting)+code {
240
- display: none;
241
- }
242
-
243
- code:has(.codesetting) {
244
- background-color: var(--vscode-textPreformat-background);
245
- color: var(--vscode-textPreformat-foreground);
246
- padding-left: 1px;
247
- margin-right: 3px;
248
- padding-right: 0px;
249
- }
250
-
251
- code:has(.codesetting):focus {
252
- border: 1px solid var(--vscode-button-border, transparent);
253
- }
254
-
255
- .codesetting {
256
- color: var(--vscode-textPreformat-foreground);
257
- padding: 0px 1px 1px 0px;
258
- font-size: 0px;
259
- overflow: hidden;
260
- text-overflow: ellipsis;
261
- outline-offset: 2px !important;
262
- box-sizing: border-box;
263
- text-align: center;
264
- cursor: pointer;
265
- display: inline;
266
- margin-right: 3px;
267
- }
268
- .codesetting svg {
269
- font-size: 12px;
270
- text-align: center;
271
- cursor: pointer;
272
- border: 1px solid var(--vscode-button-secondaryBorder, transparent);
273
- outline: 1px solid transparent;
274
- line-height: 9px;
275
- margin-bottom: -5px;
276
- padding-left: 0px;
277
- padding-top: 2px;
278
- padding-bottom: 2px;
279
- padding-right: 2px;
280
- display: inline-block;
281
- text-decoration: none;
282
- text-rendering: auto;
283
- text-transform: none;
284
- -webkit-font-smoothing: antialiased;
285
- -moz-osx-font-smoothing: grayscale;
286
- user-select: none;
287
- -webkit-user-select: none;
288
- }
289
- .codesetting .setting-name {
290
- font-size: 13px;
291
- padding-left: 2px;
292
- padding-right: 3px;
293
- padding-top: 1px;
294
- padding-bottom: 1px;
295
- margin-left: -5px;
296
- margin-top: -3px;
297
- }
298
- .codesetting:hover {
299
- color: var(--vscode-textPreformat-foreground) !important;
300
- text-decoration: none !important;
301
- }
302
- code:has(.codesetting):hover {
303
- filter: brightness(140%);
304
- text-decoration: none !important;
305
- }
306
- .codesetting:focus {
307
- outline: 0 !important;
308
- text-decoration: none !important;
309
- color: var(--vscode-button-hoverForeground) !important;
310
- }
311
- .codesetting .separator {
312
- width: 1px;
313
- height: 14px;
314
- margin-bottom: -3px;
315
- display: inline-block;
316
- background-color: var(--vscode-editor-background);
317
- font-size: 12px;
318
- margin-right: 8px;
319
- }
320
-
321
- /* codefeature */
322
-
323
- .codefeature-container {
324
- display: flex;
325
- }
326
-
327
- .codefeature {
328
- position: relative;
329
- display: inline-block;
330
- width: 46px;
331
- height: 24px;
332
- }
333
-
334
- .codefeature-container input {
335
- display: none;
336
- }
337
-
338
- .toggle {
339
- position: absolute;
340
- cursor: pointer;
341
- top: 0;
342
- left: 0;
343
- right: 0;
344
- bottom: 0;
345
- background-color: var(--vscode-button-background);
346
- transition: .4s;
347
- border-radius: 24px;
348
- }
349
-
350
- .toggle:before {
351
- position: absolute;
352
- content: "";
353
- height: 16px;
354
- width: 16px;
355
- left: 4px;
356
- bottom: 4px;
357
- background-color: var(--vscode-editor-foreground);
358
- transition: .4s;
359
- border-radius: 50%;
360
- }
361
-
362
- input:checked+.codefeature > .toggle:before {
363
- transform: translateX(22px);
364
- }
365
-
366
- .codefeature-container:has(input) .title {
367
- line-height: 30px;
368
- padding-left: 4px;
369
- font-weight: bold;
370
- }
371
-
372
- .codefeature-container:has(input:checked) .title:after {
373
- content: "${( localizeWithPath(
374
- 'vs/workbench/contrib/update/browser/releaseNotesEditor',
375
- 'disableFeature',
376
- "Disable this feature"
377
- ))}";
378
- }
379
- .codefeature-container:has(input:not(:checked)) .title:after {
380
- content: "${( localizeWithPath(
381
- 'vs/workbench/contrib/update/browser/releaseNotesEditor',
382
- 'enableFeature',
383
- "Enable this feature"
384
- ))}";
385
- }
386
-
387
- header { display: flex; align-items: center; padding-top: 1em; }
388
- </style>
389
- </head>
390
- <body>
391
- ${content}
392
- <script nonce="${nonce}">
393
- const vscode = acquireVsCodeApi();
394
- const container = document.createElement('p');
395
- container.style.display = 'flex';
396
- container.style.alignItems = 'center';
397
-
398
- const input = document.createElement('input');
399
- input.type = 'checkbox';
400
- input.id = 'showReleaseNotes';
401
- input.checked = ${showReleaseNotes};
402
- container.appendChild(input);
403
-
404
- const label = document.createElement('label');
405
- label.htmlFor = 'showReleaseNotes';
406
- label.textContent = '${( localizeWithPath(
407
- 'vs/workbench/contrib/update/browser/releaseNotesEditor',
408
- 'showOnUpdate',
409
- "Show release notes after an update"
410
- ))}';
411
- container.appendChild(label);
412
-
413
- const beforeElement = document.querySelector("body > h1")?.nextElementSibling;
414
- if (beforeElement) {
415
- document.body.insertBefore(container, beforeElement);
416
- } else {
417
- document.body.appendChild(container);
418
- }
419
-
420
- window.addEventListener('message', event => {
421
- if (event.data.type === 'showReleaseNotes') {
422
- input.checked = event.data.value;
423
- } else if (event.data.type === 'setScroll') {
424
- window.scrollTo(event.data.value.scrollPosition.x, event.data.value.scrollPosition.y);
425
- } else if (event.data.type === 'setFeaturedSettings') {
426
- for (const [settingId, value] of event.data.value) {
427
- const setting = document.getElementById(settingId);
428
- if (setting instanceof HTMLInputElement) {
429
- setting.checked = value;
430
- }
431
- }
432
- }
433
- });
434
-
435
- window.onscroll = () => {
436
- vscode.postMessage({
437
- type: 'scroll',
438
- value: {
439
- scrollPosition: {
440
- x: window.scrollX,
441
- y: window.scrollY
442
- }
443
- }
444
- });
445
- };
446
-
447
- window.addEventListener('click', event => {
448
- const href = event.target.href ?? event.target.parentElement.href ?? event.target.parentElement.parentElement?.href;
449
- if (href && (href.startsWith('${Schemas.codeSetting}') || href.startsWith('${Schemas.codeFeature}'))) {
450
- vscode.postMessage({ type: 'clickSetting', value: { uri: href, x: event.clientX, y: event.clientY }});
451
- if (href.startsWith('${Schemas.codeFeature}')) {
452
- const featureInput = event.target.parentElement.previousSibling;
453
- if (featureInput instanceof HTMLInputElement) {
454
- featureInput.checked = !featureInput.checked;
455
- }
456
- }
457
- }
458
- });
459
-
460
- window.addEventListener('keypress', event => {
461
- if (event.keyCode === 13) {
462
- if (event.target.children.length > 0 && event.target.children[0].href) {
463
- const clientRect = event.target.getBoundingClientRect();
464
- vscode.postMessage({ type: 'clickSetting', value: { uri: event.target.children[0].href, x: clientRect.right , y: clientRect.bottom }});
465
- }
466
- }
467
- });
468
-
469
- input.addEventListener('change', event => {
470
- vscode.postMessage({ type: 'showReleaseNotes', value: input.checked }, '*');
471
- });
472
- </script>
473
- </body>
474
- </html>`;
475
- }
476
- onDidChangeConfiguration(e) {
477
- if (e.affectsConfiguration('update.showReleaseNotes')) {
478
- this.updateCheckboxWebview();
479
- }
480
- }
481
- onDidChangeActiveWebviewEditor(input) {
482
- if (input && input === this._currentReleaseNotes) {
483
- this.updateCheckboxWebview();
484
- this.updateFeaturedSettingsWebview();
485
- }
486
- }
487
- updateCheckboxWebview() {
488
- if (this._currentReleaseNotes) {
489
- this._currentReleaseNotes.webview.postMessage({
490
- type: 'showReleaseNotes',
491
- value: this._configurationService.getValue('update.showReleaseNotes')
492
- });
493
- }
494
- }
495
- updateFeaturedSettingsWebview() {
496
- if (this._currentReleaseNotes) {
497
- this._currentReleaseNotes.webview.postMessage({
498
- type: 'setFeaturedSettings',
499
- value: this._simpleSettingRenderer.featuredSettingStates
500
- });
501
- }
502
- }
503
- };
504
- ReleaseNotesManager = ( __decorate([
505
- ( __param(0, IEnvironmentService)),
506
- ( __param(1, IKeybindingService)),
507
- ( __param(2, ILanguageService)),
508
- ( __param(3, IOpenerService)),
509
- ( __param(4, IRequestService)),
510
- ( __param(5, IConfigurationService)),
511
- ( __param(6, IEditorService)),
512
- ( __param(7, IEditorGroupsService)),
513
- ( __param(8, ICodeEditorService)),
514
- ( __param(9, IWebviewWorkbenchService)),
515
- ( __param(10, IExtensionService)),
516
- ( __param(11, IProductService)),
517
- ( __param(12, IInstantiationService))
518
- ], ReleaseNotesManager));
519
-
520
- export { ReleaseNotesManager };