mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-23 02:41:39 +00:00
Fix build issues
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { Channels } from "@nteract/messaging";
|
import { Channels } from "@nteract/messaging";
|
||||||
// import * as monaco from "./monaco";
|
|
||||||
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
|
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
// import { completionProvider } from "./completions/completionItemProvider";
|
// import { completionProvider } from "./completions/completionItemProvider";
|
||||||
@@ -27,7 +26,7 @@ export interface IMonacoProps {
|
|||||||
channels: Channels | undefined;
|
channels: Channels | undefined;
|
||||||
enableCompletion: boolean;
|
enableCompletion: boolean;
|
||||||
shouldRegisterDefaultCompletion?: boolean;
|
shouldRegisterDefaultCompletion?: boolean;
|
||||||
onChange: (value: string, event?: any) => void;
|
onChange: (value: string, event?: unknown) => void;
|
||||||
onFocusChange: (focus: boolean) => void;
|
onFocusChange: (focus: boolean) => void;
|
||||||
onCursorPositionChange?: (selection: monaco.ISelection | null) => void;
|
onCursorPositionChange?: (selection: monaco.ISelection | null) => void;
|
||||||
onRegisterCompletionProvider?: (languageId: string) => void;
|
onRegisterCompletionProvider?: (languageId: string) => void;
|
||||||
@@ -82,7 +81,7 @@ function getMonacoTheme(theme: monaco.editor.IStandaloneThemeData | monaco.edito
|
|||||||
|
|
||||||
const makeMapStateToProps = (initialState: AppState, initialProps: IMonacoProps) => {
|
const makeMapStateToProps = (initialState: AppState, initialProps: IMonacoProps) => {
|
||||||
const { id, contentRef } = initialProps;
|
const { id, contentRef } = initialProps;
|
||||||
function mapStateToProps(state: any, ownProps: IMonacoProps & IMonacoStateProps) {
|
function mapStateToProps(state: AppState, ownProps: IMonacoProps & IMonacoStateProps) {
|
||||||
return {
|
return {
|
||||||
language: getCellMonacoLanguage(
|
language: getCellMonacoLanguage(
|
||||||
state,
|
state,
|
||||||
@@ -112,7 +111,7 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
this.calculateHeight = this.calculateHeight.bind(this);
|
this.calculateHeight = this.calculateHeight.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDidChangeModelContent(e: monaco.editor.IModelContentChangedEvent) {
|
onDidChangeModelContent(e: monaco.editor.IModelContentChangedEvent): void {
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
if (this.props.onChange) {
|
if (this.props.onChange) {
|
||||||
this.props.onChange(this.editor.getValue(), e);
|
this.props.onChange(this.editor.getValue(), e);
|
||||||
@@ -130,7 +129,7 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
* If numberOfLines is not set or set to 0, we adjust the height to fit the content
|
* If numberOfLines is not set or set to 0, we adjust the height to fit the content
|
||||||
* If numberOfLines is specified we respect that setting
|
* If numberOfLines is specified we respect that setting
|
||||||
*/
|
*/
|
||||||
calculateHeight() {
|
calculateHeight(): void {
|
||||||
// Make sure we have an editor
|
// Make sure we have an editor
|
||||||
if (!this.editor) {
|
if (!this.editor) {
|
||||||
return;
|
return;
|
||||||
@@ -158,7 +157,7 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount(): void {
|
||||||
if (this.editorContainerRef && this.editorContainerRef.current) {
|
if (this.editorContainerRef && this.editorContainerRef.current) {
|
||||||
// Register Jupyter completion provider if needed
|
// Register Jupyter completion provider if needed
|
||||||
this.registerCompletionProvider();
|
this.registerCompletionProvider();
|
||||||
@@ -225,9 +224,13 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
|
|
||||||
// Ignore Ctrl + Enter
|
// Ignore Ctrl + Enter
|
||||||
// tslint:disable-next-line no-bitwise
|
// tslint:disable-next-line no-bitwise
|
||||||
this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, () => {
|
this.editor.addCommand(
|
||||||
// Do nothing. This is handled elsewhere, we just don't want the editor to put the newline.
|
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
|
||||||
}, undefined);
|
() => {
|
||||||
|
// Do nothing. This is handled elsewhere, we just don't want the editor to put the newline.
|
||||||
|
},
|
||||||
|
undefined
|
||||||
|
);
|
||||||
// TODO Add right context
|
// TODO Add right context
|
||||||
|
|
||||||
this.toggleEditorOptions(this.props.editorFocused);
|
this.toggleEditorOptions(this.props.editorFocused);
|
||||||
@@ -269,13 +272,13 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addEditorTopMargin() {
|
addEditorTopMargin(): void {
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
// Monaco editor doesn't have margins
|
// Monaco editor doesn't have margins
|
||||||
// https://github.com/notable/notable/issues/551
|
// https://github.com/notable/notable/issues/551
|
||||||
// This is a workaround to add an editor area 12px padding at the top
|
// This is a workaround to add an editor area 12px padding at the top
|
||||||
// so that cursors rendered by collab decorators could be visible without being cut.
|
// so that cursors rendered by collab decorators could be visible without being cut.
|
||||||
this.editor.changeViewZones((changeAccessor) => {
|
this.editor.changeViewZones(changeAccessor => {
|
||||||
const domNode = document.createElement("div");
|
const domNode = document.createElement("div");
|
||||||
changeAccessor.addZone({
|
changeAccessor.addZone({
|
||||||
afterLineNumber: 0,
|
afterLineNumber: 0,
|
||||||
@@ -289,13 +292,13 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
/**
|
/**
|
||||||
* Tells editor to check the surrounding container size and resize itself appropriately
|
* Tells editor to check the surrounding container size and resize itself appropriately
|
||||||
*/
|
*/
|
||||||
resize() {
|
resize(): void {
|
||||||
if (this.editor && this.props.editorFocused) {
|
if (this.editor && this.props.editorFocused) {
|
||||||
this.editor.layout();
|
this.editor.layout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate(): void {
|
||||||
if (!this.editor) {
|
if (!this.editor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -361,7 +364,7 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
this.editor.layout();
|
this.editor.layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount(): void {
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
try {
|
try {
|
||||||
const model = this.editor.getModel();
|
const model = this.editor.getModel();
|
||||||
@@ -376,7 +379,7 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div className="monaco-container">
|
<div className="monaco-container">
|
||||||
<div ref={this.editorContainerRef} id={`editor-${this.props.id}`} />
|
<div ref={this.editorContainerRef} id={`editor-${this.props.id}`} />
|
||||||
@@ -388,7 +391,7 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
* Register default kernel-based completion provider.
|
* Register default kernel-based completion provider.
|
||||||
* @param language Language
|
* @param language Language
|
||||||
*/
|
*/
|
||||||
registerDefaultCompletionProvider(language: string) {
|
registerDefaultCompletionProvider(language: string): void {
|
||||||
// onLanguage event is emitted only once per language when language is first time needed.
|
// onLanguage event is emitted only once per language when language is first time needed.
|
||||||
monaco.languages.onLanguage(language, () => {
|
monaco.languages.onLanguage(language, () => {
|
||||||
// monaco.languages.registerCompletionItemProvider(language, completionProvider);
|
// monaco.languages.registerCompletionItemProvider(language, completionProvider);
|
||||||
@@ -413,7 +416,7 @@ export class MonacoEditor extends React.Component<IMonacoProps & IMonacoStatePro
|
|||||||
this.props.onCursorPositionChange(selection);
|
this.props.onCursorPositionChange(selection);
|
||||||
|
|
||||||
if (!this.cursorPositionListener) {
|
if (!this.cursorPositionListener) {
|
||||||
this.cursorPositionListener = this.editor.onDidChangeCursorSelection((event) =>
|
this.cursorPositionListener = this.editor.onDidChangeCursorSelection(event =>
|
||||||
this.props.onCursorPositionChange!(event.selection)
|
this.props.onCursorPositionChange!(event.selection)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import Immutable from "immutable";
|
import Immutable from "immutable";
|
||||||
// import * as monaco from "./monaco";
|
|
||||||
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
|
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,7 +7,8 @@ import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
|
|||||||
export enum Mode {
|
export enum Mode {
|
||||||
markdown = "markdown",
|
markdown = "markdown",
|
||||||
raw = "plaintext",
|
raw = "plaintext",
|
||||||
python = "python"
|
python = "python",
|
||||||
|
csharp = "csharp"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +17,7 @@ export enum Mode {
|
|||||||
* @param mode Code Mirror mode
|
* @param mode Code Mirror mode
|
||||||
* @returns Monaco language
|
* @returns Monaco language
|
||||||
*/
|
*/
|
||||||
export function mapCodeMirrorModeToMonaco(mode: any): string {
|
export function mapCodeMirrorModeToMonaco(mode: string | { name: string }): string {
|
||||||
let language = "";
|
let language = "";
|
||||||
|
|
||||||
// Parse codemirror mode object
|
// Parse codemirror mode object
|
||||||
@@ -36,6 +36,8 @@ export function mapCodeMirrorModeToMonaco(mode: any): string {
|
|||||||
// Need to handle "ipython" as a special case since it is not a registered language
|
// Need to handle "ipython" as a special case since it is not a registered language
|
||||||
if (language === "ipython") {
|
if (language === "ipython") {
|
||||||
return Mode.python;
|
return Mode.python;
|
||||||
|
} else if (language === "text/x-csharp") {
|
||||||
|
return Mode.csharp;
|
||||||
} else if (monaco.languages.getEncodedLanguageId(language) > 0) {
|
} else if (monaco.languages.getEncodedLanguageId(language) > 0) {
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export const getCellMonacoLanguage = (
|
|||||||
cellId: CellId,
|
cellId: CellId,
|
||||||
cellLanguageOverride?: string,
|
cellLanguageOverride?: string,
|
||||||
notebookLanguageOverride?: string
|
notebookLanguageOverride?: string
|
||||||
) => {
|
): string => {
|
||||||
const model = nteractSelectors.model(state, { contentRef });
|
const model = nteractSelectors.model(state, { contentRef });
|
||||||
if (!model || model.type !== "notebook") {
|
if (!model || model.type !== "notebook") {
|
||||||
throw new Error("Connected Editor components should not be used with non-notebook models");
|
throw new Error("Connected Editor components should not be used with non-notebook models");
|
||||||
@@ -35,7 +35,6 @@ export const getCellMonacoLanguage = (
|
|||||||
return getNotebookMonacoLanguage(state, contentRef, notebookLanguageOverride);
|
return getNotebookMonacoLanguage(state, contentRef, notebookLanguageOverride);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Mode.raw;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +44,7 @@ export const getNotebookMonacoLanguage = (
|
|||||||
state: AppState,
|
state: AppState,
|
||||||
contentRef: ContentRef,
|
contentRef: ContentRef,
|
||||||
notebookLanguageOverride?: string
|
notebookLanguageOverride?: string
|
||||||
) => {
|
): string => {
|
||||||
const model = nteractSelectors.model(state, { contentRef });
|
const model = nteractSelectors.model(state, { contentRef });
|
||||||
if (!model || model.type !== "notebook") {
|
if (!model || model.type !== "notebook") {
|
||||||
throw new Error("Connected Editor components should not be used with non-notebook models");
|
throw new Error("Connected Editor components should not be used with non-notebook models");
|
||||||
@@ -56,7 +55,7 @@ export const getNotebookMonacoLanguage = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const kernelRef = model.kernelRef;
|
const kernelRef = model.kernelRef;
|
||||||
let codeMirrorMode = null;
|
let codeMirrorMode;
|
||||||
// Try to get the CodeMirror mode from the kernel.
|
// Try to get the CodeMirror mode from the kernel.
|
||||||
if (kernelRef) {
|
if (kernelRef) {
|
||||||
codeMirrorMode = nteractSelectors.kernel(state, { kernelRef })?.info?.codemirrorMode;
|
codeMirrorMode = nteractSelectors.kernel(state, { kernelRef })?.info?.codemirrorMode;
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
.monaco-container {
|
|
||||||
padding: 0px 0px 7px 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
For the following components, we use the inherited width values from monaco-container.
|
For the following components, we use the inherited width values from monaco-container.
|
||||||
On resizing the browser, the width of monaco-container will be calculated
|
On resizing the browser, the width of monaco-container will be calculated
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class BaseNotebookRenderer extends React.Component<NotebookRendererProps> {
|
|||||||
editor: {
|
editor: {
|
||||||
codemirror: (props: PassedEditorProps) => (
|
codemirror: (props: PassedEditorProps) => (
|
||||||
// <CodeMirrorEditor {...props} lineNumbers={true} />
|
// <CodeMirrorEditor {...props} lineNumbers={true} />
|
||||||
<MonacoEditor {...props} lineNumbers={true} enableCompletion={true} />
|
<MonacoEditor {...props} lineNumbers={true} enableCompletion={true} />
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
prompt: ({ id, contentRef }: { id: CellId; contentRef: ContentRef }) => (
|
prompt: ({ id, contentRef }: { id: CellId; contentRef: ContentRef }) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user