Skip to content

Commit

Permalink
Grafana-UI: Type onEditorDidMount (grafana#33178)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshhunt authored Apr 21, 2021
1 parent 0dcd028 commit 0463164
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions packages/grafana-ui/src/components/Monaco/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
// We use `import type` to guarentee it'll be erased from the JS and it doesnt accidently bundle monaco
import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';

export type CodeEditorChangeHandler = (value: string) => void;
export type CodeEditorSuggestionProvider = () => CodeEditorSuggestionItem[];

export type MonacoEditor = monaco.editor.IStandaloneCodeEditor;

export interface CodeEditorProps {
value: string;
language: string;
Expand All @@ -17,9 +20,9 @@ export interface CodeEditorProps {
/**
* Callback after the editor has mounted that gives you raw access to monaco
*
* @alpha -- experimental - real type is: monaco.editor.IStandaloneCodeEditor
* @alpha -- experimental
*/
onEditorDidMount?: (editor: any) => void;
onEditorDidMount?: (editor: monaco.editor.IStandaloneCodeEditor) => void;

/** Handler to be performed when editor is blurred */
onBlur?: CodeEditorChangeHandler;
Expand Down
2 changes: 1 addition & 1 deletion packages/grafana-ui/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export { QueryField } from './QueryField/QueryField';

// Code editor
export { CodeEditor } from './Monaco/CodeEditorLazy';
export { CodeEditorSuggestionItem, CodeEditorSuggestionItemKind } from './Monaco/types';
export { MonacoEditor, CodeEditorSuggestionItem, CodeEditorSuggestionItemKind } from './Monaco/types';
export { variableSuggestionToCodeEditorSuggestion } from './Monaco/utils';

// TODO: namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
LinkButton,
Segment,
CodeEditor,
MonacoEditor,
CodeEditorSuggestionItem,
CodeEditorSuggestionItemKind,
} from '@grafana/ui';
Expand Down Expand Up @@ -157,7 +158,7 @@ export class FluxQueryEditor extends PureComponent<Props> {
// For some reason in angular, when this component gets re-mounted, the width
// is not set properly. This forces the layout shortly after mount so that it
// displays OK. Note: this is not an issue when used directly in react
editorDidMountCallbackHack = (editor: any) => {
editorDidMountCallbackHack = (editor: MonacoEditor) => {
setTimeout(() => editor.layout(), 100);
};

Expand Down

0 comments on commit 0463164

Please sign in to comment.