Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
pref: lazyload editor (#1655)
寻5e6a04038dda
diff --git a/frontend/src/components/MonacoEditor/AutoCompletion.ts b/frontend/src/components/MonacoEditor/AutoCompletion.tsindex cf75664328..2b5431e495 100644--- a/frontend/src/components/MonacoEditor/AutoCompletion.ts+++ b/frontend/src/components/MonacoEditor/AutoCompletion.ts@@ -1,5 +1,5 @@import { uniqBy } from "lodash-es";-import * as monaco from "monaco-editor";+import {Database,Table,@@ -40,7 +40,8 @@ export default class AutoCompletion {return range;}- getCompletionItemsForKeywords() {+ async getCompletionItemsForKeywords() {+ const monaco = await import("monaco-editor");const suggestions: CompletionItems = [];const range = this.getWordRange();@@ -59,11 +60,11 @@ export default class AutoCompletion {return uniqBy(suggestions, "label");}- getCompletionItemsForDatabaseList(): CompletionItems {+ async getCompletionItemsForDatabaseList(): Promise<CompletionItems> {const suggestions: CompletionItems = [];const range = this.getWordRange();-- this.databaseList.forEach((database) => {+ const monaco = await import("monaco-editor");+ this.databaseList.forEach(async (database) => {suggestions.push({label: database.name,kind: monaco.languages.CompletionItemKind.Struct,@@ -74,16 +75,19 @@ export default class AutoCompletion {range,});- suggestions.push(...this.getCompletionItemsForTableList(database));+ suggestions.push(+ ...(await this.getCompletionItemsForTableList(database))+ );});return uniqBy(suggestions, "label");}- getCompletionItemsForTableList(+ async getCompletionItemsForTableList(db?: Database,withDatabasePrefix = true- ): CompletionItems {+ ): Promise<CompletionItems> {+ const monaco = await import("monaco-editor");const suggestions: CompletionItems = [];const range = this.getWordRange();@@ -93,7 +97,7 @@ export default class AutoCompletion {const tableList = db ? filterTableListByDB : this.tableList;- tableList.forEach((table) => {+ tableList.forEach(async (table) => {const label =withDatabasePrefix && db ? `${db?.name}.${table.name}` : table.name;suggestions.push({@@ -106,17 +110,20 @@ export default class AutoCompletion {range,});if (table.columnList && table.columnList.length > 0) {- suggestions.push(...this.getCompletionItemsForTableColumnList(table));+ suggestions.push(+ ...(await this.getCompletionItemsForTableColumnList(table))+ );}});return uniqBy(suggestions, "label");}- getCompletionItemsForTableColumnList(+ async getCompletionItemsForTableColumnList(table: Table,withTablePrefix = true- ): CompletionItems {+ ): Promise<CompletionItems> {+ const monaco = await import("monaco-editor");const suggestions: CompletionItems = [];const range = this.getWordRange();diff --git a/frontend/src/components/MonacoEditor/MonacoEditor.vue b/frontend/src/components/MonacoEditor/MonacoEditor.vueindex 49deefbcf5..4ce7648f4b 100644--- a/frontend/src/components/MonacoEditor/MonacoEditor.vue+++ b/frontend/src/components/MonacoEditor/MonacoEditor.vue@@ -13,7 +13,7 @@ import {watch,shallowRef,} from "vue";-import { editor as Editor } from "monaco-editor";+import type { editor as Editor } from "monaco-editor";import { Database, SQLDialect, Table } from "@/types";import { useMonaco } from "./useMonaco";import { useLineDecorations } from "./lineDecorations";@@ -110,15 +110,15 @@ const getEditorInstance = () => {emit("change-selection", selectedText);});- editorInstance.onDidChangeCursorPosition((e: any) => {+ editorInstance.onDidChangeCursorPosition(async (e: any) => {const { defineLineDecorations, disposeLineDecorations } =- useLineDecorations(editorInstance, e.position);+ await useLineDecorations(editorInstance, e.position);// clear the old decorationsdisposeLineDecorations();// define the new decorations- nextTick(() => {- defineLineDecorations();+ nextTick(async () => {+ await defineLineDecorations();});});diff --git a/frontend/src/components/MonacoEditor/lineDecorations.ts b/frontend/src/components/MonacoEditor/lineDecorations.tsindex dc2042ddf4..b86116af03 100644--- a/frontend/src/components/MonacoEditor/lineDecorations.ts+++ b/frontend/src/components/MonacoEditor/lineDecorations.ts@@ -1,4 +1,4 @@-import * as monaco from "monaco-editor";+import type * as monaco from "monaco-editor";import { ref } from "vue";const DELIMITER = ";";@@ -15,9 +15,10 @@ type FragmentRange = {* @param editor monaco.editor.IStandaloneCodeEditor* @returns fragmentRangeList FragmentRange[]*/-const getSQLFragmentRangeList = (+const getSQLFragmentRangeList = async (editor: monaco.editor.IStandaloneCodeEditor-): FragmentRange[] => {+): Promise<FragmentRange[]> => {+ const monaco = await import("monaco-editor");const model = editor.getModel() as monaco.editor.ITextModel;const linesContent = model.getLinesContent();const sqlFragmentRangeList: FragmentRange[] = [];@@ -71,14 +72,15 @@ const getSQLFragmentRangeList = (const lineDecorations = ref<string[]>([]);-const useLineDecorations = (+const useLineDecorations = async (editor: monaco.editor.IStandaloneCodeEditor,position: monaco.Position) => {- const defineLineDecorations = () => {+ const monaco = await import("monaco-editor");+ const defineLineDecorations = async () => {const newDecorations: monaco.editor.IModelDeltaDecoration[] = [];- const sqlFragmentRangeList = getSQLFragmentRangeList(editor);+ const sqlFragmentRangeList = await getSQLFragmentRangeList(editor);sqlFragmentRangeList.forEach((range) => {// if the current position in the range, then highlight the rangediff --git a/frontend/src/components/MonacoEditor/useMonaco.ts b/frontend/src/components/MonacoEditor/useMonaco.tsindex a4c3278ee5..b84d413060 100644--- a/frontend/src/components/MonacoEditor/useMonaco.ts+++ b/frontend/src/components/MonacoEditor/useMonaco.ts@@ -1,24 +1,25 @@import { ref } from "vue";import { uniqBy } from "lodash-es";-import * as monaco from "monaco-editor";+import type { editor as Editor } from "monaco-editor";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) => {+export const useMonaco = async (lang: string) => {+ const monaco = await import("monaco-editor");++ 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 databaseList = ref<Database[]>([]);const tableList = ref<Table[]>([]);@@ -34,7 +35,7 @@ const useMonaco = async (lang: string) => {monaco.languages.registerCompletionItemProvider(lang, {triggerCharacters: [" ", "."],- provideCompletionItems: (model, position) => {+ provideCompletionItems: async (model, position) => {let suggestions: CompletionItems = [];const { lineNumber, column } = position;@@ -72,12 +73,12 @@ const useMonaco = async (lang: string) => {// MySQL allows to query different databases, so we provide the database name suggestion for MySQL.const suggestionsForDatabase =lang === "mysql"- ? autoCompletion.getCompletionItemsForDatabaseList()+ ? await autoCompletion.getCompletionItemsForDatabaseList(): [];const suggestionsForTable =- autoCompletion.getCompletionItemsForTableList();+ await autoCompletion.getCompletionItemsForTableList();const suggestionsForKeyword =- autoCompletion.getCompletionItemsForKeywords();+ await autoCompletion.getCompletionItemsForKeywords();// if enter a dotif (lastToken.endsWith(".")) {@@ -105,7 +106,7 @@ const useMonaco = async (lang: string) => {// if the last token is a database nameif (lang === "mysql" && dbIdx !== -1 && tokenLevel === 1) {- suggestions = autoCompletion.getCompletionItemsForTableList(+ suggestions = await autoCompletion.getCompletionItemsForTableList(databaseList.value[dbIdx],true);@@ -114,10 +115,11 @@ const useMonaco = async (lang: string) => {if (tableIdx !== -1 || tokenLevel === 2) {const table = tableList.value[tableIdx];if (table.columnList && table.columnList.length > 0) {- suggestions = autoCompletion.getCompletionItemsForTableColumnList(- tableList.value[tableIdx],- false- );+ suggestions =+ await autoCompletion.getCompletionItemsForTableColumnList(+ tableList.value[tableIdx],+ false+ );}}} else {@@ -218,5 +220,3 @@ const useMonaco = async (lang: string) => {setPositionAtEndOfLine,};};--export { useMonaco };diff --git a/frontend/src/types/sqlEditor.ts b/frontend/src/types/sqlEditor.tsindex 70835cb989..802eeed20c 100644--- a/frontend/src/types/sqlEditor.ts+++ b/frontend/src/types/sqlEditor.ts@@ -1,4 +1,4 @@-import * as monaco from "monaco-editor";+import type * as monaco from "monaco-editor";import { DropdownOption } from "naive-ui";import {diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vueindex 87b4d7bea8..eacddd5fde 100644--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue@@ -19,7 +19,7 @@<script lang="ts" setup>import { debounce } from "lodash-es";import { computed, defineEmits, ref, watch, watchEffect } from "vue";-import * as monaco from "monaco-editor";+import {useInstanceStore,useTabStore,@@ -103,7 +103,8 @@ const handleSaveSheet = () => {emit("save-sheet");};-const handleEditorReady = () => {+const handleEditorReady = async () => {+ const monaco = await import("monaco-editor");editorRef.value?.editorInstance?.addAction({id: "RunQuery",label: "Run Query",