UNPKG

@theia/monaco

Version:
194 lines • 8.72 kB
"use strict"; // ***************************************************************************** // Copyright (C) 2024 1C-Soft LLC and others. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); exports.MonacoEditorPeekViewWidget = exports.peekViewTitleInfoForeground = exports.peekViewTitleForeground = exports.peekViewTitleBackground = exports.peekViewBorder = void 0; const vscode_languageserver_protocol_1 = require("@theia/core/shared/vscode-languageserver-protocol"); const core_1 = require("@theia/core"); const peekView_1 = require("@theia/monaco-editor-core/esm/vs/editor/contrib/peekView/browser/peekView"); const actions_1 = require("@theia/monaco-editor-core/esm/vs/base/common/actions"); const standaloneServices_1 = require("@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices"); const instantiation_1 = require("@theia/monaco-editor-core/esm/vs/platform/instantiation/common/instantiation"); const themeService_1 = require("@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService"); const color_1 = require("@theia/monaco-editor-core/esm/vs/base/common/color"); var peekView_2 = require("@theia/monaco-editor-core/esm/vs/editor/contrib/peekView/browser/peekView"); Object.defineProperty(exports, "peekViewBorder", { enumerable: true, get: function () { return peekView_2.peekViewBorder; } }); Object.defineProperty(exports, "peekViewTitleBackground", { enumerable: true, get: function () { return peekView_2.peekViewTitleBackground; } }); Object.defineProperty(exports, "peekViewTitleForeground", { enumerable: true, get: function () { return peekView_2.peekViewTitleForeground; } }); Object.defineProperty(exports, "peekViewTitleInfoForeground", { enumerable: true, get: function () { return peekView_2.peekViewTitleInfoForeground; } }); class MonacoEditorPeekViewWidget { constructor(editor, options = {}, styles = {}) { this.editor = editor; this.styles = styles; this.toDispose = new core_1.DisposableCollection(); this.onDidClose = this.toDispose.onDispose; this.themeService = standaloneServices_1.StandaloneServices.get(themeService_1.IThemeService); const that = this; this.toDispose.push(this.delegate = new class extends peekView_1.PeekViewWidget { get actionBar() { return this._actionbarWidget; } fillContainer(container) { super._fillContainer(container); } _fillContainer(container) { that.fillContainer(container); } fillHead(container, noCloseAction) { super._fillHead(container, noCloseAction); } _fillHead(container, noCloseAction) { that.fillHead(container, noCloseAction); } fillBody(container) { // super._fillBody is an abstract method } _fillBody(container) { that.fillBody(container); } ; doLayoutHead(heightInPixel, widthInPixel) { super._doLayoutHead(heightInPixel, widthInPixel); } _doLayoutHead(heightInPixel, widthInPixel) { that.doLayoutHead(heightInPixel, widthInPixel); } doLayoutBody(heightInPixel, widthInPixel) { super._doLayoutBody(heightInPixel, widthInPixel); } _doLayoutBody(heightInPixel, widthInPixel) { that.doLayoutBody(heightInPixel, widthInPixel); } onWidth(widthInPixel) { super._onWidth(widthInPixel); } _onWidth(widthInPixel) { that.onWidth(widthInPixel); } doRevealRange(range, isLastLine) { super.revealRange(range, isLastLine); } revealRange(range, isLastLine) { that.doRevealRange(that.editor['m2p'].asRange(range), isLastLine); } getBodyElement() { return this._bodyElement; } setBodyElement(element) { this._bodyElement = element; } getHeadElement() { return this._headElement; } setHeadElement(element) { this._headElement = element; } setCssClass(className, classToReplace) { super.setCssClass(className, classToReplace); } }(editor.getControl(), Object.assign({}, options, this.convertStyles(styles)), standaloneServices_1.StandaloneServices.get(instantiation_1.IInstantiationService))); this.toDispose.push(this.themeService.onDidColorThemeChange(() => this.style(this.styles))); } dispose() { this.toDispose.dispose(); } create() { this.delegate.create(); } setTitle(primaryHeading, secondaryHeading) { this.delegate.setTitle(primaryHeading, secondaryHeading); } style(styles) { this.delegate.style(this.convertStyles(this.styles = styles)); } show(rangeOrPos, heightInLines) { this.delegate.show(this.convertRangeOrPosition(rangeOrPos), heightInLines); } hide() { this.delegate.hide(); } clearActions() { var _a; (_a = this.delegate.actionBar) === null || _a === void 0 ? void 0 : _a.clear(); } addAction(id, label, cssClass, enabled, actionCallback, options) { options = cssClass ? { icon: true, label: false, ...options } : { icon: false, label: true, ...options }; const { actionBar } = this.delegate; if (!actionBar) { throw new Error('Action bar has not been created.'); } const action = new actions_1.Action(id, label, cssClass, enabled, actionCallback); actionBar.push(action, options); return action; } fillContainer(container) { this.delegate.fillContainer(container); } fillHead(container, noCloseAction) { this.delegate.fillHead(container, noCloseAction); } fillBody(container) { this.delegate.fillBody(container); } doLayoutHead(heightInPixel, widthInPixel) { this.delegate.doLayoutHead(heightInPixel, widthInPixel); } doLayoutBody(heightInPixel, widthInPixel) { this.delegate.doLayoutBody(heightInPixel, widthInPixel); } onWidth(widthInPixel) { this.delegate.onWidth(widthInPixel); } doRevealRange(range, isLastLine) { this.delegate.doRevealRange(this.editor['p2m'].asRange(range), isLastLine); } get bodyElement() { return this.delegate.getBodyElement(); } set bodyElement(element) { this.delegate.setBodyElement(element); } get headElement() { return this.delegate.getHeadElement(); } set headElement(element) { this.delegate.setHeadElement(element); } setCssClass(className, classToReplace) { this.delegate.setCssClass(className, classToReplace); } convertStyles(styles) { return { frameColor: this.convertColor(styles.frameColor), arrowColor: this.convertColor(styles.arrowColor), headerBackgroundColor: this.convertColor(styles.headerBackgroundColor), primaryHeadingColor: this.convertColor(styles.primaryHeadingColor), secondaryHeadingColor: this.convertColor(styles.secondaryHeadingColor), }; } convertColor(color) { if (color === undefined) { return undefined; } return this.themeService.getColorTheme().getColor(color) || color_1.Color.fromHex(color); } convertRangeOrPosition(arg) { const p2m = this.editor['p2m']; return vscode_languageserver_protocol_1.Range.is(arg) ? p2m.asRange(arg) : p2m.asPosition(arg); } } exports.MonacoEditorPeekViewWidget = MonacoEditorPeekViewWidget; //# sourceMappingURL=monaco-editor-peek-view-widget.js.map