Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: update monaco editor theme (#1510)

STEVEN2ea3075f0a32
diff --git a/frontend/package.json b/frontend/package.json
index a2937d3c6b..9569db7651 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -21,7 +21,7 @@
"highlight.js": "^11.0.1",
"inter-ui": "^3.15.0",
"lodash-es": "^4.17.21",
- "monaco-editor": "^0.32.1",
+ "monaco-editor": "^0.33.0",
"naive-ui": "^2.30.0",
"node-sql-parser": "^4.0.8",
"papaparse": "^5.3.1",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index 3bc3330380..33388cffdf 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -33,7 +33,7 @@ specifiers:
highlight.js: ^11.0.1
inter-ui: ^3.15.0
lodash-es: ^4.17.21
- monaco-editor: ^0.32.1
+ monaco-editor: ^0.33.0
naive-ui: ^2.30.0
node-sql-parser: ^4.0.8
papaparse: ^5.3.1
@@ -68,7 +68,7 @@ dependencies:
highlight.js: 11.5.0
inter-ui: 3.19.3
lodash-es: 4.17.21
- monaco-editor: 0.32.1
+ monaco-editor: 0.33.0
node-sql-parser: 4.1.1
papaparse: 5.3.1
@@ -2152,8 +2152,8 @@ packages:
deprecated: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
dev: false
- /monaco-editor/0.32.1:
- resolution: {integrity: sha512-LUt2wsUvQmEi2tfTOK+tjAPvt7eQ+K5C4rZPr6SeuyzjAuAHrIvlUloTcOiGjZW3fn3a/jFQCONrEJbNOaCqbA==}
+ /monaco-editor/0.33.0:
+ resolution: {integrity: sha512-VcRWPSLIUEgQJQIE0pVT8FcGBIgFoxz7jtqctE+IiCxWugD0DwgyQBcZBhdSrdMC84eumoqMZsGl2GTreOzwqw==}
dev: false
/ms/2.1.2:
diff --git a/frontend/src/components/MonacoEditor/MonacoEditor.vue b/frontend/src/components/MonacoEditor/MonacoEditor.vue
index 5b89d584fd..39b8b3b71c 100644
--- a/frontend/src/components/MonacoEditor/MonacoEditor.vue
+++ b/frontend/src/components/MonacoEditor/MonacoEditor.vue
@@ -1,5 +1,5 @@
<template>
- <div ref="editorRef" style="height: 100%; width: 100%"></div>
+ <div ref="editorContainerRef" style="width: 100%; height: 100%"></div>
</template>
<script lang="ts" setup>
@@ -12,6 +12,7 @@ import {
onUnmounted,
watch,
defineExpose,
+ shallowRef,
} from "vue";
import { editor as Editor } from "monaco-editor";
import { SQLDialect } from "@/types";
@@ -45,14 +46,15 @@ const emit = defineEmits<{
}
): void;
(e: "save", content: string): void;
+ (e: "ready"): void;
}>();
-const editorRef = ref();
const sqlCode = toRef(props, "value");
const language = toRef(props, "language");
-const readonly = toRef(props, "readonly");
-
-let editorInstance: Editor.IStandaloneCodeEditor;
+const readOnly = toRef(props, "readonly");
+const editorContainerRef = ref();
+// use shallowRef to avoid deep conversion which will cause page crash.
+const editorInstanceRef = shallowRef<Editor.IStandaloneCodeEditor>();
const {
monaco,
@@ -62,10 +64,9 @@ const {
setPositionAtEndOfLine,
} = await useMonaco(language.value);
-const init = async () => {
+const getEditorInstance = () => {
const model = monaco.editor.createModel(sqlCode.value, toRaw(language.value));
-
- editorInstance = monaco.editor.create(editorRef.value, {
+ const editorInstance = monaco.editor.create(editorContainerRef.value, {
model,
tabSize: 2,
insertSpaces: true,
@@ -73,12 +74,21 @@ const init = async () => {
detectIndentation: false,
folding: false,
automaticLayout: true,
- theme: "vs-light",
+ readOnly: readOnly.value,
minimap: {
enabled: false,
},
wordWrap: "on",
fixedOverflowWidgets: true,
+ fontSize: 15,
+ lineHeight: 24,
+ scrollBeyondLastLine: false,
+ padding: {
+ top: 8,
+ bottom: 8,
+ },
+ renderLineHighlight: "none",
+ codeLens: false,
});
// add the run query action in context menu
@@ -92,10 +102,7 @@ const init = async () => {
const typedValue = editorInstance.getValue();
const selectedValue = editorInstance
.getModel()
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-expect-error
- ?.getValueInRange(editorInstance.getSelection()) as string;
-
+ ?.getValueInRange(editorInstance.getSelection()!) as string;
const query = selectedValue || typedValue;
emit("run-query", { explain: false, query });
},
@@ -112,9 +119,7 @@ const init = async () => {
const typedValue = editorInstance.getValue();
const selectedValue = editorInstance
.getModel()
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-expect-error
- ?.getValueInRange(editorInstance.getSelection()) as string;
+ ?.getValueInRange(editorInstance.getSelection()!) as string;
const query = selectedValue || typedValue;
emit("run-query", { explain: true, query });
@@ -131,7 +136,7 @@ const init = async () => {
contextMenuGroupId: "operation",
contextMenuOrder: 1,
run: () => {
- if (readonly.value) {
+ if (readOnly.value) {
return;
}
formatContent(editorInstance, language.value as SQLDialect);
@@ -169,28 +174,35 @@ const init = async () => {
const value = editorInstance.getValue();
emit("save", value);
});
+
+ return editorInstance;
};
onMounted(() => {
- init();
+ const editorInstance = getEditorInstance();
+ editorInstanceRef.value = editorInstance;
// set the editor focus when the tab is selected
- if (!readonly.value) {
+ if (!readOnly.value) {
editorInstance.focus();
nextTick(() => setPositionAtEndOfLine(editorInstance));
}
+
+ nextTick(() => {
+ emit("ready");
+ });
});
onUnmounted(() => {
- editorInstance.dispose();
+ editorInstanceRef.value?.dispose();
});
watch(
- () => readonly.value,
+ () => readOnly.value,
(readOnly) => {
- if (editorInstance) {
- editorInstance.updateOptions({ readOnly });
- }
+ editorInstanceRef.value?.updateOptions({
+ readOnly: readOnly,
+ });
},
{
deep: true,
@@ -198,29 +210,40 @@ watch(
}
);
+const getEditorContent = () => {
+ return editorInstanceRef.value?.getValue();
+};
+
const setEditorContent = (content: string) => {
- setContent(editorInstance, content);
+ setContent(editorInstanceRef.value!, content);
+};
+
+const getEditorContentHeight = () => {
+ return editorInstanceRef.value?.getContentHeight();
};
const formatEditorContent = () => {
- formatContent(editorInstance, language.value as SQLDialect);
+ formatContent(editorInstanceRef.value!, language.value as SQLDialect);
nextTick(() => {
- setPositionAtEndOfLine(editorInstance);
- editorInstance.focus();
+ setPositionAtEndOfLine(editorInstanceRef.value!);
+ editorInstanceRef.value?.focus();
});
};
defineExpose({
formatEditorContent,
+ getEditorContent,
setEditorContent,
+ getEditorContentHeight,
setAutoCompletionContext,
});
</script>
<style>
-.monaco-editor .cldr.sql-fragment {
- @apply bg-indigo-600;
- width: 3px !important;
- margin-left: 2px;
+.monaco-editor .monaco-mouse-cursor-text {
+ box-shadow: none !important;
+}
+.monaco-editor .scroll-decoration {
+ display: none !important;
}
</style>
diff --git a/frontend/src/components/MonacoEditor/useMonaco.ts b/frontend/src/components/MonacoEditor/useMonaco.ts
index ffe5d4f343..a4c3278ee5 100644
--- a/frontend/src/components/MonacoEditor/useMonaco.ts
+++ b/frontend/src/components/MonacoEditor/useMonaco.ts
@@ -6,6 +6,18 @@ import { Database, Table, CompletionItems, SQLDialect } from "@/types";
import AutoCompletion from "./AutoCompletion";
import sqlFormatter from "./sqlFormatter";
+monaco.editor.defineTheme("bb-sql-editor-theme", {
+ base: "vs",
+ inherit: true,
+ rules: [],
+ colors: {
+ "editorCursor.foreground": "#504de2",
+ "editorLineNumber.foreground": "#aaaaaa",
+ "editorLineNumber.activeForeground": "#111111",
+ },
+});
+monaco.editor.setTheme("bb-sql-editor-theme");
+
const useMonaco = async (lang: string) => {
const databaseList = ref<Database[]>([]);
const tableList = ref<Table[]>([]);
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue b/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue
index c068280c27..a069309de1 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue
@@ -1,5 +1,5 @@
<template>
- <div class="editor-action">
+ <div class="w-full flex justify-between items-center p-4 border-b">
<div class="action-left space-x-2 flex items-center">
<NButton
type="primary"
@@ -179,9 +179,3 @@ const handleFormatSQL = () => {
sqlEditorStore.setShouldFormatContent(true);
};
</script>
-
-<style scoped>
-.editor-action {
- @apply w-full flex justify-between items-center p-2;
-}
-</style>
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
index efd6784990..3f8af8ea0e 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
@@ -1,5 +1,5 @@
<template>
- <div class="editor-pane h-full">
+ <div class="flex h-full w-full flex-col justify-start items-start">
<EditorAction @save-sheet="handleSaveSheet" />
<template v-if="!sqlEditorStore.isDisconnected">
diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
index 736475a35d..792a2e973c 100644
--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
@@ -1,14 +1,18 @@
<template>
- <MonacoEditor
- ref="editorRef"
- v-model:value="sqlCode"
- :language="selectedLanguage"
- :readonly="readonly"
- @change="handleChange"
- @change-selection="handleChangeSelection"
- @run-query="handleRunQuery"
- @save="handleSaveSheet"
- />
+ <div
+ class="w-full h-auto flex-grow flex flex-col justify-start items-start overflow-scroll"
+ >
+ <MonacoEditor
+ ref="editorRef"
+ v-model:value="sqlCode"
+ :language="selectedLanguage"
+ :readonly="readonly"
+ @change="handleChange"
+ @change-selection="handleChangeSelection"
+ @run-query="handleRunQuery"
+ @save="handleSaveSheet"
+ />
+ </div>
</template>
<script lang="ts" setup>
diff --git a/frontend/src/views/sql-editor/SQLEditor.vue b/frontend/src/views/sql-editor/SQLEditor.vue
index dd82f50ff4..a36be2045d 100644
--- a/frontend/src/views/sql-editor/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/SQLEditor.vue
@@ -2,7 +2,7 @@
<div class="sqleditor--wrapper">
<TabListContainer />
<Splitpanes class="default-theme splitpanes-wrap">
- <Pane size="20" min-size="0" max-size="30">
+ <Pane size="20" min-size="20" max-size="30">
<AsidePanel />
</Pane>
<Pane size="80">