@grafana/ui
Version:
Grafana Components Library
1 lines • 5.62 kB
Source Map (JSON)
{"version":3,"file":"types.mjs","sources":["../../../../src/components/Monaco/types.ts"],"sourcesContent":["// We use `import type` to guarantee it'll be erased from the JS and it doesnt accidently bundle monaco\nimport type { EditorProps } from '@monaco-editor/react';\nimport type * as monacoType from 'monaco-editor/esm/vs/editor/editor.api';\n\n// we do not allow customizing the theme.\n// (theme is complicated in Monaco, right now there is\n// a limitation where all monaco editors must have\n// the same theme, see\n// https://github.com/microsoft/monaco-editor/issues/338#issuecomment-274837186\n// )\nexport type ReactMonacoEditorProps = Omit<EditorProps, 'theme'>;\n\nexport type CodeEditorChangeHandler = (value: string) => void;\nexport type CodeEditorSuggestionProvider = () => CodeEditorSuggestionItem[];\n\nexport type { monacoType as monacoTypes };\nexport type Monaco = typeof monacoType;\nexport type MonacoEditor = monacoType.editor.IStandaloneCodeEditor;\nexport type MonacoOptions = MonacoOptionsWithGrafanaDefaults;\n\nexport interface CodeEditorProps {\n value: string;\n language: string;\n width?: number | string;\n height?: number | string;\n\n readOnly?: boolean;\n showMiniMap?: boolean;\n showLineNumbers?: boolean;\n wordWrap?: boolean;\n monacoOptions?: MonacoOptions;\n\n /**\n * Callback before the editor has mounted that gives you raw access to monaco\n */\n onBeforeEditorMount?: (monaco: Monaco) => void;\n\n /**\n * Callback after the editor has mounted that gives you raw access to monaco\n */\n onEditorDidMount?: (editor: MonacoEditor, monaco: Monaco) => void;\n\n /** Callback before the edior has unmounted */\n onEditorWillUnmount?: () => void;\n\n /** Handler to be performed when editor is blurred */\n onBlur?: CodeEditorChangeHandler;\n\n /** Handler to be performed when editor is focused */\n onFocus?: CodeEditorChangeHandler;\n\n /** Handler to be performed whenever the text inside the editor changes */\n onChange?: CodeEditorChangeHandler;\n\n /** Handler to be performed when Cmd/Ctrl+S is pressed */\n onSave?: CodeEditorChangeHandler;\n\n /**\n * Language agnostic suggestion completions -- typically for template variables\n */\n getSuggestions?: CodeEditorSuggestionProvider;\n\n containerStyles?: string;\n}\n\n/**\n * @alpha\n */\nexport enum CodeEditorSuggestionItemKind {\n Method = 'method',\n Field = 'field',\n Property = 'property',\n Constant = 'constant',\n Text = 'text',\n}\n\n/**\n * @alpha\n */\nexport interface CodeEditorSuggestionItem {\n /**\n * The label of this completion item. By default\n * this is also the text that is inserted when selecting\n * this completion.\n */\n label: string;\n\n /**\n * The kind of this completion item. An icon is chosen\n * by the editor based on the kind.\n */\n kind?: CodeEditorSuggestionItemKind;\n\n /**\n * A human-readable string with additional information\n * about this item, like type or symbol information.\n */\n detail?: string;\n\n /**\n * A human-readable string that represents a doc-comment.\n */\n documentation?: string; // | IMarkdownString;\n\n /**\n * A string or snippet that should be inserted in a document when selecting\n * this completion. When `falsy` the `label` is used.\n */\n insertText?: string;\n}\n\n/**\n * This interface will extend the original Monaco editor options interface\n * but changing the code comments to contain the proper default values to\n * prevent the consumer of the CodeEditor to get incorrect documentation in editor.\n */\nexport interface MonacoOptionsWithGrafanaDefaults extends monacoType.editor.IStandaloneEditorConstructionOptions {\n /**\n * Enable custom contextmenu.\n * Defaults to false.\n */\n contextmenu?: boolean;\n /**\n * The number of spaces a tab is equal to.\n * This setting is overridden based on the file contents when `detectIndentation` is on.\n * Defaults to 4.\n */\n tabSize?: number;\n /**\n * Show code lens\n * Defaults to false.\n */\n codeLens?: boolean;\n /**\n * Control the width of line numbers, by reserving horizontal space for rendering at least an amount of digits.\n * Defaults to 4.\n */\n lineNumbersMinChars?: number;\n /**\n * The width reserved for line decorations (in px).\n * Line decorations are placed between line numbers and the editor content.\n * You can pass in a string in the format floating point followed by \"ch\". e.g. 1.3ch.\n * Defaults to 1 * theme.spacing.gridSize.\n */\n lineDecorationsWidth?: number | string;\n /**\n * Controls if a border should be drawn around the overview ruler.\n * Defaults to `false`.\n */\n overviewRulerBorder?: boolean;\n /**\n * Enable that the editor will install an interval to check if its container dom node size has changed.\n * Enabling this might have a severe performance impact.\n * Defaults to true.\n */\n automaticLayout?: boolean;\n\n /**\n * Always consume mouse wheel events (always call preventDefault() and stopPropagation() on the browser events).\n * Always consuming mouse wheel events will prevent the page from scrolling if the cursor is over the editor.\n * Defaults to `false`.\n */\n alwaysConsumeMouseWheel?: boolean;\n}\n"],"names":["CodeEditorSuggestionItemKind"],"mappings":";AAoEO,IAAK,4BAAA,qBAAAA,6BAAAA,KAAL;AACL,EAAAA,8BAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,8BAAA,OAAA,CAAA,GAAQ,OAAA;AACR,EAAAA,8BAAA,UAAA,CAAA,GAAW,UAAA;AACX,EAAAA,8BAAA,UAAA,CAAA,GAAW,UAAA;AACX,EAAAA,8BAAA,MAAA,CAAA,GAAO,MAAA;AALG,EAAA,OAAAA,6BAAAA;AAAA,CAAA,EAAA,4BAAA,IAAA,EAAA;;;;"}