{
return (
- {
}
}
-export default withTheme2(UnthemedCodeEditor);
+export const CodeEditor = withTheme2(UnthemedCodeEditor);
const getStyles = (theme: GrafanaTheme2) => {
return {
diff --git a/packages/grafana-ui/src/components/Monaco/CodeEditorLazy.tsx b/packages/grafana-ui/src/components/Monaco/CodeEditorLazy.tsx
deleted file mode 100644
index 918416c8f27..00000000000
--- a/packages/grafana-ui/src/components/Monaco/CodeEditorLazy.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-import React from 'react';
-import { useAsyncDependency } from '../../utils/useAsyncDependency';
-import { ErrorWithStack, LoadingPlaceholder } from '..';
-import { CodeEditorProps } from './types';
-
-export const CodeEditor: React.FC = (props) => {
- const { loading, error, dependency } = useAsyncDependency(
- import(/* webpackChunkName: "code-editor" */ './CodeEditor')
- );
-
- if (loading) {
- return ;
- }
-
- if (error) {
- return (
-
- );
- }
-
- const CodeEditor = dependency.default;
- return ;
-};
diff --git a/packages/grafana-ui/src/components/Monaco/ReactMonacoEditor.tsx b/packages/grafana-ui/src/components/Monaco/ReactMonacoEditor.tsx
new file mode 100644
index 00000000000..61de48cc74e
--- /dev/null
+++ b/packages/grafana-ui/src/components/Monaco/ReactMonacoEditor.tsx
@@ -0,0 +1,21 @@
+import React from 'react';
+import MonacoEditor, { loader as monacoEditorLoader, EditorProps as MonacoEditorProps } from '@monaco-editor/react';
+
+let initalized = false;
+function initMonaco() {
+ if (initalized) {
+ return;
+ }
+
+ monacoEditorLoader.config({
+ paths: {
+ vs: (window.__grafana_public_path__ ?? 'public/') + 'lib/monaco/min/vs',
+ },
+ });
+ initalized = true;
+}
+
+export const ReactMonacoEditor = (props: MonacoEditorProps) => {
+ initMonaco();
+ return ;
+};
diff --git a/packages/grafana-ui/src/components/Monaco/ReactMonacoEditorLazy.tsx b/packages/grafana-ui/src/components/Monaco/ReactMonacoEditorLazy.tsx
new file mode 100644
index 00000000000..073b0d1d643
--- /dev/null
+++ b/packages/grafana-ui/src/components/Monaco/ReactMonacoEditorLazy.tsx
@@ -0,0 +1,32 @@
+import React from 'react';
+import { useAsyncDependency } from '../../utils/useAsyncDependency';
+import { ErrorWithStack, LoadingPlaceholder } from '..';
+// we only use import type so it will not be included in the bundle
+import type { EditorProps } from '@monaco-editor/react';
+
+/**
+ * @internal
+ * Experimental export
+ **/
+export const ReactMonacoEditorLazy = (props: EditorProps) => {
+ const { loading, error, dependency } = useAsyncDependency(
+ import(/* webpackChunkName: "react-monaco-editor" */ './ReactMonacoEditor')
+ );
+
+ if (loading) {
+ return ;
+ }
+
+ if (error) {
+ return (
+
+ );
+ }
+
+ const ReactMonacoEditor = dependency.ReactMonacoEditor;
+ return ;
+};
diff --git a/packages/grafana-ui/src/components/index.ts b/packages/grafana-ui/src/components/index.ts
index 9de67699ed4..9cd19f0741d 100644
--- a/packages/grafana-ui/src/components/index.ts
+++ b/packages/grafana-ui/src/components/index.ts
@@ -41,7 +41,10 @@ export { ConfirmModal, ConfirmModalProps } from './ConfirmModal/ConfirmModal';
export { QueryField } from './QueryField/QueryField';
// Code editor
-export { CodeEditor } from './Monaco/CodeEditorLazy';
+export { CodeEditor } from './Monaco/CodeEditor';
+
+export { ReactMonacoEditorLazy as ReactMonacoEditor } from './Monaco/ReactMonacoEditorLazy';
+
export {
Monaco,
monacoTypes,