6100f8294d19664190db0f11e21bc35a754bf06b70e0be7509a11981662a6a3e9e4709c7ab1d3eb0b105075b2b7ef023776fb60278365d2402581ece1b17f1 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. var __param = (this && this.__param) || function (paramIndex, decorator) {
  8. return function (target, key) { decorator(target, key, paramIndex); }
  9. };
  10. /*---------------------------------------------------------------------------------------------
  11. * Copyright (c) Microsoft Corporation. All rights reserved.
  12. * Licensed under the MIT License. See License.txt in the project root for license information.
  13. *--------------------------------------------------------------------------------------------*/
  14. import './bannerController.css';
  15. import { $, append, clearNode } from '../../../../base/browser/dom.js';
  16. import { ActionBar } from '../../../../base/browser/ui/actionbar/actionbar.js';
  17. import { Action } from '../../../../base/common/actions.js';
  18. import { Disposable } from '../../../../base/common/lifecycle.js';
  19. import { MarkdownRenderer } from '../../markdownRenderer/browser/markdownRenderer.js';
  20. import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
  21. import { Link } from '../../../../platform/opener/browser/link.js';
  22. import { widgetClose } from '../../../../platform/theme/common/iconRegistry.js';
  23. import { ThemeIcon } from '../../../../platform/theme/common/themeService.js';
  24. const BANNER_ELEMENT_HEIGHT = 26;
  25. let BannerController = class BannerController extends Disposable {
  26. constructor(_editor, instantiationService) {
  27. super();
  28. this._editor = _editor;
  29. this.instantiationService = instantiationService;
  30. this.banner = this._register(this.instantiationService.createInstance(Banner));
  31. }
  32. hide() {
  33. this._editor.setBanner(null, 0);
  34. this.banner.clear();
  35. }
  36. show(item) {
  37. this.banner.show(Object.assign(Object.assign({}, item), { onClose: () => {
  38. var _a;
  39. this.hide();
  40. (_a = item.onClose) === null || _a === void 0 ? void 0 : _a.call(item);
  41. } }));
  42. this._editor.setBanner(this.banner.element, BANNER_ELEMENT_HEIGHT);
  43. }
  44. };
  45. BannerController = __decorate([
  46. __param(1, IInstantiationService)
  47. ], BannerController);
  48. export { BannerController };
  49. // TODO@hediet: Investigate if this can be reused by the workspace banner (bannerPart.ts).
  50. let Banner = class Banner extends Disposable {
  51. constructor(instantiationService) {
  52. super();
  53. this.instantiationService = instantiationService;
  54. this.markdownRenderer = this.instantiationService.createInstance(MarkdownRenderer, {});
  55. this.element = $('div.editor-banner');
  56. this.element.tabIndex = 0;
  57. }
  58. getAriaLabel(item) {
  59. if (item.ariaLabel) {
  60. return item.ariaLabel;
  61. }
  62. if (typeof item.message === 'string') {
  63. return item.message;
  64. }
  65. return undefined;
  66. }
  67. getBannerMessage(message) {
  68. if (typeof message === 'string') {
  69. const element = $('span');
  70. element.innerText = message;
  71. return element;
  72. }
  73. return this.markdownRenderer.render(message).element;
  74. }
  75. clear() {
  76. clearNode(this.element);
  77. }
  78. show(item) {
  79. // Clear previous item
  80. clearNode(this.element);
  81. // Banner aria label
  82. const ariaLabel = this.getAriaLabel(item);
  83. if (ariaLabel) {
  84. this.element.setAttribute('aria-label', ariaLabel);
  85. }
  86. // Icon
  87. const iconContainer = append(this.element, $('div.icon-container'));
  88. iconContainer.setAttribute('aria-hidden', 'true');
  89. if (item.icon) {
  90. iconContainer.appendChild($(`div${ThemeIcon.asCSSSelector(item.icon)}`));
  91. }
  92. // Message
  93. const messageContainer = append(this.element, $('div.message-container'));
  94. messageContainer.setAttribute('aria-hidden', 'true');
  95. messageContainer.appendChild(this.getBannerMessage(item.message));
  96. // Message Actions
  97. this.messageActionsContainer = append(this.element, $('div.message-actions-container'));
  98. if (item.actions) {
  99. for (const action of item.actions) {
  100. this._register(this.instantiationService.createInstance(Link, this.messageActionsContainer, Object.assign(Object.assign({}, action), { tabIndex: -1 }), {}));
  101. }
  102. }
  103. // Action
  104. const actionBarContainer = append(this.element, $('div.action-container'));
  105. this.actionBar = this._register(new ActionBar(actionBarContainer));
  106. this.actionBar.push(this._register(new Action('banner.close', 'Close Banner', ThemeIcon.asClassName(widgetClose), true, () => {
  107. if (typeof item.onClose === 'function') {
  108. item.onClose();
  109. }
  110. })), { icon: true, label: false });
  111. this.actionBar.setFocusable(false);
  112. }
  113. };
  114. Banner = __decorate([
  115. __param(0, IInstantiationService)
  116. ], Banner);