25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(sidebar): decompose tree item runtime
t8y2666095715325
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vueindex dd177570e8..02764afa64 100644--- a/apps/desktop/src/App.vue+++ b/apps/desktop/src/App.vue@@ -11,7 +11,6 @@ import EditorToolbar from "@/components/layout/EditorToolbar.vue";import ContentArea from "@/components/layout/ContentArea.vue";import AppDialogs from "@/components/layout/AppDialogs.vue";import WelcomeScreen from "@/components/layout/WelcomeScreen.vue";-import DdlViewDialog from "@/components/objects/DdlViewDialog.vue";import type { ConfigTab } from "@/components/connection/ConnectionDialog.vue";import { useConnectionStore } from "@/stores/connectionStore";import { useQueryStore } from "@/stores/queryStore";@@ -106,6 +105,7 @@ const UpdateDialog = defineAsyncComponent(() => import("@/components/layout/Updaconst CloseActionPromptDialog = defineAsyncComponent(() => import("@/components/layout/CloseActionPromptDialog.vue"));const LoginPage = defineAsyncComponent(() => import("@/components/auth/LoginPage.vue"));const QuickOpenDialog = defineAsyncComponent(() => import("@/components/quick-open/QuickOpenDialog.vue"));+const QueryEditorDdlViewDialog = defineAsyncComponent(() => import("@/components/objects/DdlViewDialog.vue"));const QueryEditorObjectSourceDialog = defineAsyncComponent(() => import("@/components/objects/ObjectSourceDialog.vue"));type AiAssistantHandle = {@@ -2294,7 +2294,7 @@ onUnmounted(() => {</DialogFooter></DialogContent></Dialog>- <DdlViewDialog+ <QueryEditorDdlViewDialogv-if="queryEditorDdlTarget"v-model:open="showQueryEditorDdlDialog":connection-id="queryEditorDdlTarget.connectionId"diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex 29382f1b33..8acbf03d3c 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -40,6 +40,9 @@ import {WandSparkles,} from "@lucide/vue";import { Button } from "@/components/ui/button";+import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";+import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";+import { Input } from "@/components/ui/input";import QueryLoadingState from "@/components/common/QueryLoadingState.vue";import CustomContextMenu, { type ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";import LightDropdownMenu from "@/components/ui/LightDropdownMenu.vue";diff --git a/apps/desktop/src/components/layout/SqlLibraryPanel.vue b/apps/desktop/src/components/layout/SqlLibraryPanel.vueindex 296368dffa..010169ce8a 100644--- a/apps/desktop/src/components/layout/SqlLibraryPanel.vue+++ b/apps/desktop/src/components/layout/SqlLibraryPanel.vue@@ -75,7 +75,7 @@ function importConnectionIdForFolder(folder?: SavedSqlFolder) {}function sanitizeFileSystemSegment(name: string) {- return name.replace(/[<>:"/\\|?*\u0000-\u001F]/g, "_").trim() || "untitled";+ return name.replace(/[<>:"/\\|?*\p{Cc}]/gu, "_").trim() || "untitled";}function relativeImportName(baseDir: string, filePath: string) {diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vueindex c86d72dc84..79cf600cc9 100644--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue@@ -1,5 +1,5 @@<script setup lang="ts">-import { ref, computed, nextTick, watch, provide, onMounted, onUnmounted, type Component, type CSSProperties } from "vue";+import { ref, computed, nextTick, watch, provide, onMounted, onUnmounted, type Component, type ComponentPublicInstance, type CSSProperties } from "vue";import { useI18n } from "vue-i18n";import { Search, X, ListFilter, Crosshair, Server, Database, FolderTree, Table2, Eye, RotateCcw } from "@lucide/vue";import { useConnectionStore } from "@/stores/connectionStore";@@ -19,9 +19,11 @@ import { activeTabSidebarTarget, findSidebarNodeForActiveTab, findSidebarNodeForimport { findLoadedTableTargetForCandidate, queryContextTargetFromCandidate, queryCursorTableCandidate, type QueryCursorTableCandidate } from "@/lib/sql/queryCursorTableTarget";import { createFlatTreeIndex, SIDEBAR_TREE_ROW_HEIGHT, SIDEBAR_TREE_PRERENDER_COUNT, SIDEBAR_TREE_SCROLL_BUFFER, flattenTree, shouldVirtualizeFlatTree, type FlatTreeNode } from "@/composables/useFlatTree";import { sidebarTreeContextKey } from "@/lib/sidebar/sidebarTreeContext";+import { createSidebarTreeRuntime, sidebarTreeRuntimeKey, type SidebarTreeRuntimeHostInstance } from "@/lib/sidebar/sidebarTreeRuntime";import { createSidebarPasteHandlerRegistry } from "@/lib/sidebar/sidebarPasteHandlerRegistry";import { insertSidebarTableSearchControls, isSidebarTableSearchControlNode } from "@/lib/sidebar/sidebarTableSearchControl";import TreeItem from "./TreeItem.vue";+import SidebarTreeRuntimeHost from "./SidebarTreeRuntimeHost.vue";import SidebarTreeItemDialogs from "./SidebarTreeItemDialogs.vue";import InstallExtensionDialog from "@/components/objects/InstallExtensionDialog.vue";import { RecycleScroller } from "vue-virtual-scroller";@@ -58,6 +60,9 @@ const sidebarDangerDialogConfirming = ref(false);const sidebarTreeItemDialogController = ref<Record<string, any> | null>(null);const sidebarInstallExtensionTarget = ref<TreeNode | null>(null);const sidebarInstallExtensionDialogRef = ref<InstanceType<typeof InstallExtensionDialog> | null>(null);+const sidebarTreeRuntimeHostRef = ref<SidebarTreeRuntimeHostInstance | null>(null);+const sidebarTreeRuntime = createSidebarTreeRuntime();+const sidebarTreeRuntimeInitialNode: TreeNode = { id: "__sidebar-runtime__", label: "", type: "connection-group" };const sidebarDdlTarget = ref<TreeNode | null>(null);const sidebarDdlOpen = ref(false);const sidebarObjectSourceTarget = ref<{ node: TreeNode; initialEditing: boolean } | null>(null);@@ -553,6 +558,13 @@ provide(sidebarTreeContextKey, {},registerPasteHandler: pasteHandlerRegistry.register,});+provide(sidebarTreeRuntimeKey, sidebarTreeRuntime);++function bindSidebarTreeRuntimeHost(host: Element | ComponentPublicInstance | null) {+ const runtimeHost = host as SidebarTreeRuntimeHostInstance | null;+ sidebarTreeRuntimeHostRef.value = runtimeHost;+ sidebarTreeRuntime.bindHost(runtimeHost);+}const pendingRenameGroupId = ref<string | null>(null);const highlightedNodeId = ref<string | null>(null);@@ -871,7 +883,8 @@ function onSearchToggle(node: TreeNode) {searchCollapsedIds.value = next;}-function openSidebarContextMenu(event: MouseEvent, node: TreeNode, items: ContextMenuItem[], openContextMenu: (event: MouseEvent, itemsOverride?: ContextMenuItem[]) => void) {+function openSidebarContextMenu(event: MouseEvent, node: TreeNode, openContextMenu: (event: MouseEvent, itemsOverride?: ContextMenuItem[]) => void) {+ const items = sidebarTreeRuntime.buildContextMenu(node);sidebarContextMenuTarget.value = createSidebarActionTarget(node);sidebarContextMenuItems.value = items;// Pass the current row's resolved menu atomically. Waiting for the items prop@@ -1246,6 +1259,7 @@ onMounted(() => {});onUnmounted(() => {+ sidebarTreeRuntime.dispose();sidebarActionGeneration += 1;sidebarContextMenuTarget.value = null;sidebarContextMenuItems.value = [];@@ -1276,6 +1290,22 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes });<template><div ref="rootRef" class="h-full min-h-0 flex flex-col text-sm select-none" @pointerenter="pointerInsideTree = true" @pointerleave="pointerInsideTree = false">+ <SidebarTreeRuntimeHost+ :ref="bindSidebarTreeRuntimeHost"+ :node="sidebarTreeRuntimeInitialNode"+ :depth="0"+ @search-toggle="onSearchToggle"+ @open-ddl="openSidebarDdl"+ @open-object-source="openSidebarObjectSource"+ @open-procedure="openSidebarProcedure"+ @open-data="openSidebarData"+ @open-visible-databases="openSidebarVisibleDatabases"+ @open-visible-schemas="openSidebarVisibleSchemas"+ @request-group-rename="startRenamingCreatedGroup"+ @open-danger-dialog="openSidebarDangerDialog"+ @open-dialog-controller="updateSidebarTreeItemDialogController"+ @open-install-extension="openSidebarInstallExtension"+ /><div class="connection-tree-search sticky top-0 z-10 bg-background px-2 py-1"><div class="relative flex items-center gap-1"><div class="relative flex-1">@@ -1343,39 +1373,14 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes });:drag-disabled="isFiltering":pending-rename="pendingRenameGroupId === item.node.id":highlighted="highlightedNodeId === item.node.id"- @search-toggle="onSearchToggle"- @context-menu="(event, node, items) => openSidebarContextMenu(event, node, items, contextMenuSlot.onContextMenu)"- @open-ddl="openSidebarDdl"- @open-object-source="openSidebarObjectSource"- @open-procedure="openSidebarProcedure"- @open-data="openSidebarData"- @open-visible-databases="openSidebarVisibleDatabases"- @open-visible-schemas="openSidebarVisibleSchemas"- @open-danger-dialog="openSidebarDangerDialog"- @open-dialog-controller="updateSidebarTreeItemDialogController"- @open-install-extension="openSidebarInstallExtension"+ @context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"@rename-started="pendingRenameGroupId = null"@group-created="startRenamingCreatedGroup"/></template></RecycleScroller><div v-if="stickyNode" class="sticky-database-header pointer-events-auto absolute inset-x-0 top-0 z-[5] border-b border-border/60" :style="stickyHeaderStyle">- <TreeItem- :node="stickyNode.node"- :depth="stickyNode.depth"- :drag-disabled="true"- @search-toggle="onSearchToggle"- @context-menu="(event, node, items) => openSidebarContextMenu(event, node, items, contextMenuSlot.onContextMenu)"- @open-ddl="openSidebarDdl"- @open-object-source="openSidebarObjectSource"- @open-procedure="openSidebarProcedure"- @open-data="openSidebarData"- @open-visible-databases="openSidebarVisibleDatabases"- @open-visible-schemas="openSidebarVisibleSchemas"- @open-danger-dialog="openSidebarDangerDialog"- @open-dialog-controller="updateSidebarTreeItemDialogController"- @open-install-extension="openSidebarInstallExtension"- />+ <TreeItem :node="stickyNode.node" :depth="stickyNode.depth" :drag-disabled="true" @context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)" /></div><div v-if="hasSidebarVerticalOverflow" ref="sidebarScrollbarTrackRef" class="sidebar-tree-scrollbar" :class="{ 'sidebar-tree-scrollbar--scrolling': isScrollingSidebar, 'sidebar-tree-scrollbar--dragging': isDraggingSidebarScrollbar }" @pointerdown="onSidebarScrollbarTrackPointerDown"><div class="sidebar-tree-scrollbar__thumb" :style="sidebarScrollbarThumbStyle" @pointerdown.stop="onSidebarScrollbarThumbPointerDown" />@@ -1391,17 +1396,7 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes });:drag-disabled="isFiltering":pending-rename="pendingRenameGroupId === item.node.id":highlighted="highlightedNodeId === item.id"- @search-toggle="onSearchToggle"- @context-menu="(event, node, items) => openSidebarContextMenu(event, node, items, contextMenuSlot.onContextMenu)"- @open-ddl="openSidebarDdl"- @open-object-source="openSidebarObjectSource"- @open-procedure="openSidebarProcedure"- @open-data="openSidebarData"- @open-visible-databases="openSidebarVisibleDatabases"- @open-visible-schemas="openSidebarVisibleSchemas"- @open-danger-dialog="openSidebarDangerDialog"- @open-dialog-controller="updateSidebarTreeItemDialogController"- @open-install-extension="openSidebarInstallExtension"+ @context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"@rename-started="pendingRenameGroupId = null"@group-created="startRenamingCreatedGroup"/>diff --git a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vuenew file mode 100644index 0000000000..5c5294b4ed--- /dev/null+++ b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue@@ -0,0 +1,4135 @@+<script setup lang="ts">+import { computed, nextTick, watch, onBeforeUnmount, inject, reactive, shallowRef } from "vue";+import { useSqlHighlighter } from "@/composables/useSqlHighlighter";+import { useSidebarDataOpenRuntime } from "@/composables/useSidebarDataOpenRuntime";+import { useSidebarConnectionMutationRuntime } from "@/composables/useSidebarConnectionMutationRuntime";+import { useSidebarDatabaseSpecificMutationRuntime } from "@/composables/useSidebarDatabaseSpecificMutationRuntime";+import { useSidebarTableMutationRuntime } from "@/composables/useSidebarTableMutationRuntime";+import { useSidebarTreeExportRuntime } from "@/composables/useSidebarTreeExportRuntime";+import { useSidebarTreeToolRuntime } from "@/composables/useSidebarTreeToolRuntime";+import { useI18n } from "vue-i18n";+import { translateBackendError } from "@/i18n/backend-errors";+import {+ Database,+ ChevronsDown,+ FolderOpen,+ Trash2,+ TerminalSquare,+ RefreshCw,+ Copy,+ TableProperties,+ ListTree,+ Pencil,+ Play,+ Plug,+ Unplug,+ Pin,+ ArrowRightLeft,+ Download,+ Upload,+ FileCode,+ Network,+ PencilRuler,+ Search,+ FolderInput,+ FolderPlus,+ Eraser,+ Scissors,+ CopyPlus,+ Plus,+ ScrollText,+ Code2,+ ListFilter,+ Clipboard,+ UsersRound,+ Activity,+ Gauge,+ CalendarClock,+ HardDriveDownload,+ FilePlus,+ SquarePen,+ ListX,+ Info,+ X,+} from "@lucide/vue";+import type { ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";+import { CONNECTION_ATTEMPT_CANCELLED_MESSAGE, useConnectionStore } from "@/stores/connectionStore";+import { useQueryStore } from "@/stores/queryStore";+import { useSettingsStore } from "@/stores/settingsStore";+import { useSavedSqlStore } from "@/stores/savedSqlStore";+import { useToast } from "@/composables/useToast";+import { useDatabaseOptions } from "@/composables/useDatabaseOptions";+import type { ColumnInfo, DatabaseType, TreeNode, TreeNodeType } from "@/types/database";+import * as api from "@/lib/backend/api";+import { resolveDefaultDatabase } from "@/lib/database/defaultDatabase";+import { canTreeNodePin, canTreeNodeShowExpander } from "@/lib/sidebar/sidebarTreeItemLayout";+import { buildTableDeleteTemplate, buildTableInsertTemplate, buildTableSelectTemplate, buildTableUpdateTemplate } from "@/lib/table/tableSqlTemplates";+import { driverStoreFocusForInstallError } from "@/lib/connection/agentDriverInstallHint";+import {+ canCreateConnectionNamespace,+ canCreateDatabaseNodeNamespace,+ canEditDatabaseProperties as canEditDatabasePropertiesForNode,+ connectionNamespaceCreationTarget,+ editableDatabasePropertyGroups,+ supportsDatabaseCreation,+ supportsDatabaseSearch,+ supportsFieldLineage,+ supportsObjectBrowserTreeNode,+ supportsSchemaDiagram,+ supportsSqlFileExecution,+ supportsTableImport,+ supportsTableTruncate,+ supportsTableStructureEditing,+ usesTreeSchemaMode,+} from "@/lib/database/databaseCapabilities";+import { copyNameForTreeNode, isDocumentBrowserTreeNode, objectSourceKindForTreeNode, shouldRunTreeNodeRowAction, treeNodeRowAction, treeNodeRowDoubleClickAction } from "@/lib/sidebar/treeNodeClick";+import { dataTabOpenModeFromTreeClick, type DataTabOpenMode } from "@/lib/sidebar/dataTabOpenPolicy";+import { isCopySidebarSelectionShortcut, isEditSidebarConnectionShortcut, isPasteSidebarSelectionShortcut } from "@/lib/editor/keyboardShortcuts";+import { canRefreshDataTableFromSingleActivationDoubleClick, dataTableDoubleClickAction } from "@/lib/tabs/dataTabActivation";+import { buildCreateDatabaseSql, buildDuckDbAttachDatabaseSql, duckDbAttachedDatabaseNameFromPath, supportsCreateDatabaseCharset, uniqueDuckDbAttachedDatabaseName } from "@/lib/database/createDatabaseSql";+import {+ buildCreateSchemaSql,+ buildDropDatabaseSql,+ buildDropObjectSql,+ buildDropSchemaSql,+ buildGetDatabaseCommentSql,+ buildGetSchemaCommentSql,+ buildUpdateDatabasePropertiesSql,+ buildDropTableSql,+ buildDropTableChildObjectSql,+ buildDuplicateTableStructureSql,+ buildCopyTableDataSql,+ buildEmptyTableSql,+ buildTruncateTableSql,+ supportsDropTableCascade,+ supportsTruncateTableCascade,+ supportsSchemaComment,+ type DropTableChildObjectSqlOptions,+ type DropObjectSqlOptions,+ type TableChildObjectType,+} from "@/lib/database/dbAdminSql";+import { buildRenameObjectSql, supportsObjectRename, type RenameableObjectType } from "@/lib/table/objectRenameSql";+import { buildRoutineRenameObjectSourceStatements, supportsSourceBackedRoutineRename } from "@/lib/table/objectSourceEditor";+import { buildViewDdl } from "@/lib/table/viewDdl";+import { formatSqlForDisplay, sqlFormatDialectForDbType } from "@/lib/sql/sqlFormatter";+import { getTableStructureCapabilities } from "@/lib/table/tableStructureCapabilities";+import { connectionObjectTreeNodeSchema, connectionObjectTreeQuerySchema, connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection, tableStructureDatabaseTypeForConnection } from "@/lib/database/jdbcDialect";+import { hasTreeNodeDatabaseContext } from "@/lib/sidebar/treeNodeContext";+import { defaultPasteTableMode, pasteTableModeCopiesData, supportsWholeRowTableDataCopy, tableClipboardMatchesTarget, tableDataCopyColumnOptions, type TableClipboardContext } from "@/lib/table/tableClipboard";+import { selectedTreeNodesInVisibleOrder as orderSelectedTreeNodes } from "@/lib/sidebar/sidebarTreeSelection";+import { connectionPasteTargetGroupId, selectedConnectionClipboardTargets, selectedConnectionEditTarget } from "@/lib/sidebar/sidebarConnectionSelection";+import { connectionSupportsDatabaseUserAdmin, resolveDatabaseUserAdminProviderForConnection, type DatabaseUserIdentity } from "@/lib/database/databaseUserAdmin";+import { authorizationPlanSql, authorizationPlanStatus, buildCreateDatabaseAuthorizationPlan, executeAuthorizationPlan, type AuthorizationPlan, type AuthorizationStepResult } from "@/lib/database/databaseAuthorizationPlan";+import { connectionSupportsProcessList } from "@/lib/database/processListDrivers";+import { connectionSupportsServerDashboard } from "@/lib/database/mysqlServerStatus";+import { connectionSupportsServerDashboard as connectionSupportsPgServerDashboard } from "@/lib/database/postgresServerStatus";+import { sidebarTreeContextKey } from "@/lib/sidebar/sidebarTreeContext";+import { batchTableEmptyFeedback, runBatchTableEmpty } from "@/lib/sidebar/batchTableEmpty";+import { runBatchTableTruncate } from "@/lib/table/batchTableTruncate";+import { isTauriRuntime } from "@/lib/backend/tauriRuntime";+import { copyToClipboard } from "@/lib/common/clipboard";+import { rankSavedSqlHistory, type SavedSqlHistoryScope } from "@/lib/savedSql/savedSqlHistory";+import { isSqlServerLinkedNode } from "@/lib/database/sqlServerLinkedServers";+import { flattenTree } from "@/composables/useFlatTree";+import { createDatabaseCollationOptionsForCharset, nextCreateDatabaseCollation, normalizeCreateDatabaseCharset, parseCreateDatabaseCharsetMetadata } from "@/lib/database/createDatabaseCharsetOptions";+import { executeWithProductionSqlGuard } from "@/lib/database/productionExecutionGuard";+import type { SidebarDataOpenRequest } from "@/lib/sidebar/sidebarDataOpenCoordinator";+import { createSidebarActionTarget, findSidebarActionTarget, releaseRemovedSidebarActionTarget, type SidebarActionTarget } from "@/lib/sidebar/sidebarActionTarget";+import { createSidebarMenuContext, normalizeSidebarMenuDescriptors } from "@/lib/sidebar/sidebarTreeMenuDescriptors";+import type { SidebarDangerDialogRequest } from "@/lib/sidebar/sidebarDangerDialog";+import {+ fallbackCreateDatabaseCharset,+ sidebarTreeDialogOwner,+ sidebarDangerTarget,+ sidebarFormTarget,+ showDeleteConfirm,+ showDropTableConfirm,+ showDropTableChildObjectConfirm,+ showBatchDropConfirm,+ showBatchEmptyConfirm,+ showBatchTruncateConfirm,+ showStructurePreviewDialog,+ showStructureDocCopyDialog,+ structurePreviewSql,+ structurePreviewTitle,+ structurePreviewError,+ structureDocCopyText,+ structureDocCopyTitle,+ isLoadingStructurePreview,+ showEmptyTableConfirm,+ showTruncateTableConfirm,+ showRenameObjectDialog,+ renameObjectName,+ renameObjectError,+ renameObjectPreviewSql,+ dropTablePreviewSql,+ dropTableCascade,+ batchDropCascade,+ emptyTablePreviewSql,+ truncateTablePreviewSql,+ truncateTableCascade,+ dropObjectPreviewSql,+ showDropObjectConfirm,+ dropTableChildObjectPreviewSql,+ batchDropPreviewSql,+ batchEmptyPreviewSql,+ batchEmptyTargets,+ batchDropTargets,+ batchTruncateTargets,+ batchTruncatePreviewSql,+ batchTruncateCascade,+ dropDatabasePreviewSql,+ dropSchemaPreviewSql,+ showDuplicateDialog,+ duplicateTableName,+ duplicateStructureSource,+ showPasteDialog,+ pasteTableMode,+ pasteTableEntries,+ showCreateDatabaseDialog,+ createDatabaseName,+ createDatabaseCharset,+ createDatabaseCollation,+ createDatabaseUsers,+ createDatabaseSelectedUsers,+ createDatabaseUsersLoading,+ showCreateDatabasePreviewDialog,+ createDatabaseAuthorizationPlan,+ createDatabasePreviewSql,+ createDatabaseAuthorizationResults,+ createDatabaseAuthorizationApplying,+ showCreateNacosNamespaceDialog,+ createNacosNamespaceId,+ createNacosNamespaceName,+ createNacosNamespaceDesc,+ createNacosNamespaceLoading,+ showEditNacosNamespaceDialog,+ editNacosNamespaceName,+ editNacosNamespaceDesc,+ editNacosNamespaceLoading,+ createDatabaseCharsetOptions,+ createDatabaseCollationsByCharset,+ createDatabaseCharsetLoading,+ showDropDatabaseConfirm,+ dropDatabaseLoading,+ showDropMongoCollectionConfirm,+ dropMongoCollectionLoading,+ showDropMongoIndexConfirm,+ dropMongoIndexLoading,+ showDropAllMongoIndexesConfirm,+ dropAllMongoIndexesLoading,+ showFlushRedisDbConfirm,+ showCreateSchemaDialog,+ createSchemaName,+ showDropSchemaConfirm,+ showEditDatabasePropertiesDialog,+ editDatabasePropertiesLoading,+ editDatabasePropertiesPreviewSql,+ editDatabaseCharset,+ editDatabaseCollation,+ editDatabaseCommentText,+ showEditSchemaCommentDialog,+ schemaCommentText,+ schemaCommentLoading,+ schemaCommentPreviewSql,+ showDeleteGroupConfirm,+ showMoveToNewGroupDialog,+ moveToNewGroupName,+ type DuplicateStructureSource,+} from "./sidebarTreeDialogState";++const { t } = useI18n();++const connectionStore = useConnectionStore();++const queryStore = useQueryStore();++const settingsStore = useSettingsStore();++const savedSqlStore = useSavedSqlStore();++const { toast } = useToast();++const { highlight } = useSqlHighlighter();++const { openData } = useSidebarDataOpenRuntime();++const { getDatabaseOptions } = useDatabaseOptions();++const props = defineProps<{+ node: TreeNode;+ depth: number;+ dragDisabled?: boolean;+ pendingRename?: boolean;+ highlighted?: boolean;+}>();++const activeNode = shallowRef<TreeNode>(props.node);+let acceptedSelectionIds: readonly string[] | null = null;++function releaseActiveNodeReference(nodeIds: readonly string[]) {+ activeNode.value = releaseRemovedSidebarActionTarget(activeNode.value, nodeIds);+}++watch(+ () => connectionStore.treeNodes,+ (nodes) => {+ const liveNode = findSidebarActionTarget(nodes, createSidebarActionTarget(activeNode.value));+ activeNode.value = liveNode ?? releaseRemovedSidebarActionTarget(activeNode.value, [activeNode.value.id]);+ },+ { flush: "post" },+);++const { copyStructureAs, copyStructureDocText, copyStructurePreview, exportData, exportDataXlsx, exportStructure, saveStructurePreview, selectTextareaContent } = useSidebarTreeExportRuntime({+ activeNode,+ connectionStore,+ settingsStore,+ acceptedSelectionIds: () => acceptedSelectionIds,+});++const { openAllDatabasesExport, openDataCompare, openDatabaseExport, openDatabaseSearch, openDiagram, openFieldLineage, openScheduledBackups, openSchemaDiff, openSqlFileExecution, openStructureEditor, openTableImport, openTransfer } = useSidebarTreeToolRuntime({+ activeNode,+ connectionStore,+ queryStore,+ settingsStore,+ tableChildObjectName: tableChildDropObjectName,+});++const emit = defineEmits<{+ "rename-started": [];+ "group-created": [groupId: string];+ "request-group-rename": [groupId: string];+ "node-toggled": [node: TreeNode, wasExpanded: boolean];+ "search-toggle": [node: TreeNode];+ "context-menu": [event: MouseEvent, node: TreeNode, items: ContextMenuItem[]];+ "open-ddl": [node: TreeNode];+ "open-object-source": [node: TreeNode, initialEditing: boolean];+ "open-procedure": [node: TreeNode];+ "open-data": [node: TreeNode, requireSelection: boolean, openMode: DataTabOpenMode, runner: (node: TreeNode, request: SidebarDataOpenRequest) => Promise<void>];+ "open-visible-databases": [node: TreeNode];+ "open-visible-schemas": [node: TreeNode];+ "open-danger-dialog": [request: SidebarDangerDialogRequest];+ "open-dialog-controller": [controller: Record<string, any> | null];+ "open-install-extension": [node: TreeNode];+}>();++const {+ setNodeAsDefaultDatabase,+ clearNodeDefaultDatabase,+ connectionDeleteMenuLabel,+ connectionDuplicateMenuLabel,+ connectionDeleteConfirmMessage,+ deleteConnection,+ confirmDelete,+ copyFinalProxyPort,+ duplicateConnection,+ editConnection,+ revealConnectionFilePath,+ revealDatabaseFile,+ canBackupSqliteDatabase,+ backupSqliteDatabase,+ disconnectConnection,+ cancelConnectionAttempt,+ closeDatabaseConnection,+ isPinned,+ isNodeDefaultDatabase,+ isConnected,+ isConnecting,+ canCloseDatabaseConnection,+ canConfigureVisibleDatabases,+ canConfigureVisibleSchemas,+ canCopyFinalProxyPort,+ togglePin,+ openVisibleDatabasesDialog,+ openVisibleSchemasDialog,+ startRenameGroup,+ deleteConnectionGroup,+ newConnectionInGroup,+ newSubgroup,+ confirmDeleteGroup,+ moveToGroup,+} = useSidebarConnectionMutationRuntime({+ activeNode,+ releaseActiveNodeReference,+ selectedTreeNodesInVisibleOrder,+ connectionStore,+ queryStore,+ requestGroupRename: (groupId) => emit("request-group-rename", groupId),+ groupCreated: (groupId) => emit("group-created", groupId),+ openVisibleDatabases: (node) => emit("open-visible-databases", node),+ openVisibleSchemas: (node) => emit("open-visible-schemas", node),+});++const {+ canDropMongoDatabase,+ canDropMongoCollection,+ mongoIndexNameForNode,+ canDropMongoIndexNode,+ canDropMongoIndex,+ mongoIndexDropPreview,+ canDropAllMongoIndexes,+ mongoDropAllIndexesPreview,+ openCreateNacosNamespaceDialog,+ confirmCreateNacosNamespace,+ openEditNacosNamespaceDialog,+ confirmEditNacosNamespace,+ dropMongoCollection,+ dropMongoIndex,+ dropAllMongoIndexes,+ flushRedisDb,+ confirmFlushRedisDb,+ confirmDropMongoCollection,+ confirmDropMongoIndex,+ confirmDropAllMongoIndexes,+} = useSidebarDatabaseSpecificMutationRuntime({ activeNode, connectionStore });++const { isTableNotView, supportsTruncate, canDropTableCascade, canTruncateTableCascade, refreshDropTablePreviewSql, refreshTruncateTablePreviewSql, dropTable, refreshTableList, confirmDropTable, emptyTable, confirmEmptyTable, truncateTable, confirmTruncateTable } = useSidebarTableMutationRuntime({+ activeNode,+ releaseActiveNodeReference,+ connectionStore,+ currentDatabaseType,+ databaseTypeForNode,+ executeWithProductionGuard: executeTreeNodeSqlWithProductionGuard,+ closeDroppedTableObjectTabsForNode,+ refreshMutatedTableDataTabsForNode,+});++const treeItemDialogOwner = Symbol("sidebar-tree-dialog-owner");++function claimTreeItemDialogOwnership() {+ sidebarTreeDialogOwner.value = treeItemDialogOwner;+}++function routeTreeItemDialogController() {+ const controller = getTreeItemDialogController();+ const target = createSidebarActionTarget(activeNode.value);+ sidebarFormTarget.value = target;+ const routedController = reactive<Record<string, any>>({ ...controller, node: target });+ for (const [key, value] of Object.entries(controller)) {+ if (typeof value !== "function") continue;+ routedController[key] = (...args: unknown[]) => {+ activateActionTarget(target);+ return value(...args);+ };+ }+ routedController.pasteTableDataCopySupported = pasteTableDataCopySupported.value;+ routedController.canSetCreateDatabaseCharset = canSetCreateDatabaseCharset.value;+ routedController.canEditDatabaseCharsetCollation = canEditDatabaseCharsetCollation.value;+ routedController.canEditDatabaseComment = canEditDatabaseComment.value;+ emit("open-dialog-controller", routedController);+}++const sidebarTreeContext = inject(sidebarTreeContextKey, null);++function currentDatabaseType(): DatabaseType | undefined {+ return activeNode.value.connectionId ? effectiveDatabaseTypeForConnection(connectionStore.getConfig(activeNode.value.connectionId)) : undefined;+}++function currentTableStructureDatabaseType(): DatabaseType | undefined {+ return activeNode.value.connectionId ? tableStructureDatabaseTypeForConnection(connectionStore.getConfig(activeNode.value.connectionId)) : undefined;+}++function rawDatabaseType(): DatabaseType | undefined {+ return activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId)?.db_type : undefined;+}++function databaseTypeForNode(node: TreeNode): DatabaseType | undefined {+ return node.connectionId ? effectiveDatabaseTypeForConnection(connectionStore.getConfig(node.connectionId)) : undefined;+}++function tableStructureDatabaseTypeForNode(node: TreeNode): DatabaseType | undefined {+ return node.connectionId ? tableStructureDatabaseTypeForConnection(connectionStore.getConfig(node.connectionId)) : undefined;+}++function hasNodeDatabaseContext(node: TreeNode): node is TreeNode & { connectionId: string; database: string } {+ return !!node.connectionId && hasTreeNodeDatabaseContext(node);+}++const groupTypes: Set<TreeNodeType> = new Set(["group-columns", "group-indexes", "group-fkeys", "group-triggers", "group-tables", "group-views", "group-materialized-views", "group-procedures", "group-functions", "group-sequences", "group-packages", "group-partitions", "group-extensions"]);++function isGroupLabel(node: TreeNode): boolean {+ return groupTypes.has(node.type);+}++async function toggle() {+ const node = activeNode.value;+ if (node.isLoading) {+ if (!node.isExpanded) {+ node.isExpanded = true;+ emit("node-toggled", node, false);+ }+ return;+ }+ emit("search-toggle", node);+ const wasExpanded = !!node.isExpanded;++ if (node.type === "connection-group") {+ node.isExpanded = !node.isExpanded;+ connectionStore.toggleConnectionGroupCollapsed(node.id);+ emit("node-toggled", node, wasExpanded);+ return;+ }++ if (node.type === "group-partitions") {+ node.isExpanded = !node.isExpanded;+ emit("node-toggled", node, wasExpanded);+ return;+ }++ const databaseObjectGroup = node.type === "group-tables" || node.type === "group-views" || node.type === "group-materialized-views" || node.type === "group-procedures" || node.type === "group-functions" || node.type === "group-sequences" || node.type === "group-packages";+ if (databaseObjectGroup && connectionStore.isTreeNodeChildrenLoaded(node.id)) {+ node.isExpanded = !node.isExpanded;+ if (wasExpanded) connectionStore.releaseCollapsedTreeNodeChildren(node.id);+ emit("node-toggled", node, wasExpanded);+ return;+ }++ if (node.isExpanded) {+ node.isExpanded = false;+ connectionStore.releaseCollapsedTreeNodeChildren(node.id);+ emit("node-toggled", node, wasExpanded);+ return;+ }++ try {+ if (node.type === "connection" && node.connectionId) {+ const config = connectionStore.getConfig(node.connectionId);+ if (config?.db_type === "redis") {+ await connectionStore.loadRedisDatabases(node.connectionId);+ } else if (config?.db_type === "etcd") {+ await connectionStore.loadEtcdRoot(node.connectionId);+ } else if (config?.db_type === "zookeeper") {+ await connectionStore.loadZooKeeperRoot(node.connectionId);+ } else if (config?.db_type === "mongodb") {+ await connectionStore.loadMongoDatabases(node.connectionId);+ } else if (config?.db_type === "elasticsearch") {+ await connectionStore.loadElasticsearchIndices(node.connectionId);+ } else if (config?.db_type === "milvus") {+ await connectionStore.loadMilvusDatabases(node.connectionId);+ } else if (config?.db_type === "qdrant" || config?.db_type === "weaviate" || config?.db_type === "chromadb") {+ await connectionStore.loadVectorCollections(node.connectionId);+ } else if (config?.db_type === "mq") {+ await connectionStore.loadMqTenants(node.connectionId);+ } else if (config?.db_type === "nacos") {+ await connectionStore.loadNacosNamespaces(node.connectionId);+ } else {+ await connectionStore.loadDatabases(node.connectionId);+ }+ } else if (node.type === "redis-db" && node.connectionId && node.database) {+ await connectionStore.ensureConnected(node.connectionId);+ const tabTitle = `${connectionStore.getConfig(node.connectionId)?.name || "Redis"}:db${node.database}`;+ queryStore.createTab(node.connectionId, node.database, tabTitle, "redis");+ } else if (node.type === "mq-tenant" && node.connectionId) {+ await connectionStore.ensureConnected(node.connectionId);+ queryStore.openMqAdmin(node.connectionId, { tenant: node.mqTenant || node.label, initialTab: node.mqInitialTab });+ } else if (node.type === "nacos-namespace" && node.connectionId) {+ await connectionStore.ensureConnected(node.connectionId);+ queryStore.openNacosAdmin(node.connectionId, { namespace: node.nacosNamespace || "", namespaceName: node.nacosNamespaceName || node.label });+ } else if (node.type === "etcd-root" && node.connectionId) {+ await connectionStore.ensureConnected(node.connectionId);+ const tabTitle = `${connectionStore.getConfig(node.connectionId)?.name || "etcd"}:keys`;+ queryStore.createTab(node.connectionId, "", tabTitle, "etcd");+ refreshActiveKvBrowserAfterOpen("etcd", node.connectionId);+ } else if (node.type === "zookeeper-root" && node.connectionId) {+ await connectionStore.ensureConnected(node.connectionId);+ const tabTitle = `${connectionStore.getConfig(node.connectionId)?.name || "ZooKeeper"}:keys`;+ queryStore.createTab(node.connectionId, "", tabTitle, "zookeeper");+ refreshActiveKvBrowserAfterOpen("zookeeper", node.connectionId);+ } else if (node.type === "user-admin" && node.connectionId) {+ await connectionStore.ensureConnected(node.connectionId);+ queryStore.openUserAdmin(node.connectionId);+ } else if (node.type === "dameng-job-admin" && node.connectionId) {+ await connectionStore.ensureConnected(node.connectionId);+ queryStore.openDamengJobAdmin(node.connectionId);+ } else if (node.type === "mongo-db" && node.connectionId && node.database) {+ await connectionStore.loadMongoCollections(node.connectionId, node.database);+ } else if (node.type === "vector-database" && node.connectionId && node.database) {+ await connectionStore.loadVectorCollections(node.connectionId, node.database);+ } else if (node.type === "mongo-collection" && node.connectionId && node.database) {+ await connectionStore.loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id);+ } else if (node.type === "elasticsearch-index" && node.connectionId) {+ await connectionStore.ensureConnected(node.connectionId);+ const tab = queryStore.createTab(node.connectionId, node.database || "default", node.label, "mongo");+ queryStore.updateSql(tab, node.label);+ } else if (node.type === "vector-collection" && node.connectionId) {+ await connectionStore.ensureConnected(node.connectionId);+ const collectionRef = (node.meta as { collectionId?: string } | undefined)?.collectionId ?? node.label;+ const tab = queryStore.createTab(node.connectionId, node.database || "default", node.label, "vector");+ queryStore.updateSql(tab, collectionRef);+ api+ .vectorGetCollectionDetail(node.connectionId, node.database || "default", collectionRef)+ .then((info) => {+ if (info.dimension != null) {+ if (node.meta) {+ (node.meta as Record<string, unknown>).dimension = info.dimension;+ } else {+ node.meta = { dimension: info.dimension } as any;+ }+ }+ })+ .catch(() => {});+ } else if (node.type === "database" && node.connectionId && hasTreeNodeDatabaseContext(node)) {+ if (node.catalog && node.catalog !== "internal") {+ await connectionStore.loadDorisCatalogTables(node);+ } else {+ const config = connectionStore.getConfig(node.connectionId);+ const effectiveDbType = effectiveDatabaseTypeForConnection(config);+ if (config?.db_type === "sqlserver") {+ await connectionStore.loadSqlServerDatabaseObjects(node.connectionId, node.database);+ } else if (usesTreeSchemaMode(effectiveDbType) && !connectionUsesDatabaseObjectTreeMode(config)) {+ await connectionStore.loadSchemas(node.connectionId, node.database);+ } else {+ await connectionStore.loadTables(node.connectionId, node.database);+ }+ }+ } else if (node.type === "doris-catalog" && node.connectionId) {+ await connectionStore.loadDorisCatalogDatabases(node);+ } else if (node.type === "schema" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.schema) {+ await connectionStore.loadTables(node.connectionId, node.database, node.schema);+ } else if (node.type === "linked-server-root" && node.connectionId) {+ await connectionStore.loadSqlServerLinkedServers(node.connectionId);+ } else if (node.type === "linked-server" && node.connectionId) {+ await connectionStore.loadSqlServerLinkedServerCatalogs(node);+ } else if (node.type === "linked-server-catalog" && node.connectionId) {+ await connectionStore.loadSqlServerLinkedServerSchemas(node);+ } else if (node.type === "linked-server-schema" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.schema) {+ await connectionStore.loadTables(node.connectionId, node.database, node.schema);+ } else if ((node.type === "table" || node.type === "view" || node.type === "materialized_view") && node.connectionId && hasTreeNodeDatabaseContext(node)) {+ await connectionStore.loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id, node.catalog);+ } else if (node.type === "group-columns" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {+ await connectionStore.loadColumns(node.connectionId, node.database, node.tableName, node.schema, node.id, node.catalog);+ } else if (node.type === "group-indexes" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {+ await connectionStore.loadIndexes(node.connectionId, node.database, node.tableName, node.schema, node.id, node.catalog);+ } else if (node.type === "group-fkeys" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {+ await connectionStore.loadForeignKeys(node.connectionId, node.database, node.tableName, node.schema, node.id, node.catalog);+ } else if (node.type === "group-triggers" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {+ await connectionStore.loadTriggers(node.connectionId, node.database, node.tableName, node.schema, node.id, node.catalog);+ } else if (databaseObjectGroup) {+ await connectionStore.loadObjectGroupChildren(node);+ }+ emit("node-toggled", node, wasExpanded);+ } catch (e: any) {+ if (!wasExpanded) node.isExpanded = false;+ const errMsg = e?.message || String(e);+ if (errMsg.includes(CONNECTION_ATTEMPT_CANCELLED_MESSAGE)) return;+ toast(t("connection.connectFailed", { message: translateBackendError(t, errMsg) }), 5000);+ openDriverStoreForInstallError(errMsg);+ }+}++function runRowClickAction(clickDetail: number) {+ const node = activeNode.value;+ if (node.type === "load-more") {+ if (clickDetail > 1) return;+ void loadMoreObjectGroupChildren();+ return;+ }+ if (node.type === "object-browser") {+ if (clickDetail > 1) return;+ void openObjectBrowser();+ return;+ }+ if (node.type === "mongo-gridfs") {+ openMongoTreeData(node);+ return;+ }+ const action = treeNodeRowAction(node.type, canExpand.value, settingsStore.editorSettings.sidebarActivation);+ if (!shouldRunTreeNodeRowAction(action, clickDetail)) return;+ if (action === "open-data") {+ if (node.type === "table") {+ singleActivationDoubleClickRefreshAllowed = canRefreshDataTableFromSingleActivationDoubleClick(findExistingSameTableDataTab());+ }+ scheduleOpenData(node);+ } else if (isDocumentBrowserTreeNode(node.type)) {+ openMongoTreeData(node);+ } else if (node.type === "procedure" || node.type === "function" || node.type === "sequence" || node.type === "package" || node.type === "package-body") {+ openObjectSourceDialog(false);+ } else if (action === "toggle") {+ toggle();+ }+}++let singleActivationDoubleClickRefreshAllowed = false;++function refreshActiveKvBrowserAfterOpen(mode: "etcd" | "zookeeper", connectionId: string) {+ void nextTick(() => {+ window.dispatchEvent(new CustomEvent("dbx-refresh-active-kv-browser", { detail: { mode, connectionId } }));+ });+}++function openDriverStoreForInstallError(errMsg: string, node: TreeNode = activeNode.value) {+ const config = node.connectionId ? connectionStore.getConfig(node.connectionId) : undefined;+ const focus = driverStoreFocusForInstallError(errMsg, config?.db_type, config?.driver_profile);+ if (focus) window.dispatchEvent(new CustomEvent("dbx-open-driver-store", { detail: focus }));+}++async function loadMoreObjectGroupChildren() {+ const node = activeNode.value;+ try {+ await connectionStore.loadMoreObjectGroupChildren(node);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++async function loadAllObjectGroupChildren() {+ const node = activeNode.value;+ try {+ await connectionStore.loadAllObjectGroupChildren(node);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++function visibleTreeNodes(): TreeNode[] {+ if (sidebarTreeContext) return sidebarTreeContext.getVisibleNodes();+ return flattenTree(connectionStore.treeNodes).map((item) => item.node);+}++function selectedTreeNodesInVisibleOrder(): TreeNode[] {+ return orderSelectedTreeNodes(visibleTreeNodes(), acceptedSelectionIds ?? connectionStore.selectedTreeNodeIds);+}++function isEditableShortcutTarget(target: EventTarget | null): boolean {+ if (!(target instanceof HTMLElement)) return false;+ return target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target.isContentEditable || !!target.closest("[contenteditable='true']");+}++function onKeydown(event: KeyboardEvent) {+ claimTreeItemDialogOwnership();+ if ((!isSelected.value && !isMultiSelected.value) || isEditableShortcutTarget(event.target)) return;+ if (isPasteTreeClipboardShortcut(event)) {+ if (!requestPasteTreeClipboard()) return;+ event.preventDefault();+ event.stopPropagation();+ return;+ }+ if (isEditConnectionShortcut(event)) {+ if (!requestEditSelectedConnection()) return;+ event.preventDefault();+ event.stopPropagation();+ return;+ }+ if (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && event.key === "F2") {+ if (!requestRenameSelectedNode()) return;+ event.preventDefault();+ event.stopPropagation();+ return;+ }+ if (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && event.key === "F5") {+ if (!requestRefreshSelectedNode()) return;+ event.preventDefault();+ event.stopPropagation();+ return;+ }+ if (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && isDeleteTreeNodeShortcut(event)) {+ if (!requestDeleteSelectedNode()) return;+ event.preventDefault();+ event.stopPropagation();+ return;+ }+ if (!isCopyTreeSelectionShortcut(event)) return;+ event.preventDefault();+ event.stopPropagation();+ copySelectedNames();+}++function isDeleteTreeNodeShortcut(event: KeyboardEvent): boolean {+ return event.key === "Delete" || event.key === "Backspace";+}++function isPasteTreeClipboardShortcut(event: KeyboardEvent): boolean {+ return isPasteSidebarSelectionShortcut(event, settingsStore.editorSettings.shortcuts);+}++function isEditConnectionShortcut(event: KeyboardEvent): boolean {+ return isEditSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);+}++function isCopyTreeSelectionShortcut(event: KeyboardEvent): boolean {+ return isCopySidebarSelectionShortcut(event, settingsStore.editorSettings.shortcuts);+}++function pasteTableTargetContext(): TableClipboardContext | null {+ if (!activeNode.value.connectionId || !activeNode.value.database) return null;+ return {+ connectionId: activeNode.value.connectionId,+ database: activeNode.value.database,+ schema: activeNode.value.schema,+ };+}++function canPasteTreeClipboardToCurrentNode(): boolean {+ const clipboard = connectionStore.treeClipboard;+ return clipboard?.kind === "table-copy" && tableClipboardMatchesTarget(clipboard.tables, pasteTableTargetContext());+}++function requestPasteTreeClipboard(): boolean {+ claimTreeItemDialogOwnership();+ ensureDangerDialogRouting();+ routeTreeItemDialogController();+ const clipboard = connectionStore.treeClipboard;+ if (clipboard?.kind === "connection-copy") {+ const targetGroupId = connectionPasteTargetGroupId(activeNode.value, (connectionId) => connectionStore.groupIdForConnection(connectionId));+ void connectionStore+ .pasteConnectionClipboard(targetGroupId)+ .then((count) => {+ if (count > 0) toast(count > 1 ? t("connection.duplicatedSelected", { count }) : t("connection.duplicated"), 2000);+ })+ .catch((e: any) => toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000));+ return true;+ }+ if (clipboard?.kind !== "table-copy" || !canPasteTreeClipboardToCurrentNode()) return false;+ pasteTableMode.value = defaultPasteTableMode(currentDatabaseType());+ pasteTableEntries.value = clipboard.tables.map((entry) => ({+ sourceName: entry.tableName,+ targetName: `${entry.tableName}_copy`,+ connectionId: entry.connectionId,+ database: entry.database,+ schema: entry.schema,+ }));+ showPasteDialog.value = true;+ return true;+}++function requestRefreshSelectedNode(): boolean {+ if (!canRefreshTreeNodeShortcut()) return false;+ void refresh();+ return true;+}++function canRefreshTreeNodeShortcut(): boolean {+ const type = activeNode.value.type;+ if (type === "connection" || type === "database" || type === "schema" || type === "table" || type === "view") {+ return true;+ }+ return isGroupLabel(activeNode.value) && type !== "group-partitions";+}++function requestRenameSelectedNode(): boolean {+ const selected = selectedTreeNodesInVisibleOrder();+ if (selected.length > 1 && selected.some((node) => node.id === activeNode.value.id)) return false;+ const editTarget = selectedConnectionEditTarget(activeNode.value, selected);+ if (editTarget) {+ connectionStore.startEditing(editTarget.connectionId);+ return true;+ }+ if (canRenameObject.value) {+ openRenameObjectDialog();+ return true;+ }+ if (activeNode.value.type === "connection-group") {+ startRenameGroup();+ return true;+ }+ return false;+}++function requestEditSelectedConnection(): boolean {+ const editTarget = selectedConnectionEditTarget(activeNode.value, selectedTreeNodesInVisibleOrder());+ if (!editTarget) return false;+ connectionStore.startEditing(editTarget.connectionId);+ return true;+}++function requestDeleteSelectedNode(): boolean {+ claimTreeItemDialogOwnership();+ ensureDangerDialogRouting();+ routeTreeItemDialogController();+ if (requestDropSelectedNodes()) return true;+ if (activeNode.value.type === "connection") {+ deleteConnection();+ return true;+ }+ if (activeNode.value.type === "connection-group") {+ deleteConnectionGroup();+ return true;+ }+ if (canDropDatabase.value) {+ dropDatabase();+ return true;+ }+ if (canDropMongoDatabase.value) {+ dropDatabase();+ return true;+ }+ if (canDropMongoCollection.value) {+ dropMongoCollection();+ return true;+ }+ if (canDropSchema.value) {+ dropSchema();+ return true;+ }+ return false;+}++function onDoubleClick(event: MouseEvent) {+ if (dataTabOpenModeFromTreeClick(activeNode.value.type, event, settingsStore.editorSettings.shortcuts.openDataInNewTab) === "new-tab") return;+ const action = treeNodeRowDoubleClickAction(activeNode.value.type, canOpenObjectBrowser.value, settingsStore.editorSettings.sidebarActivation, canExpand.value);+ if (action === "open-object-browser") {+ void openObjectBrowser();+ } else if (action === "open-object-browser-and-expand") {+ void openObjectBrowser();+ if (!activeNode.value.isExpanded) void toggle();+ } else if (action === "open-data") {+ openDataImmediately(activeNode.value);+ } else if (action === "refresh-data") {+ void refreshData();+ } else if (action === "open-source") {+ openObjectSourceDialog(false);+ } else if (action === "open-saved-sql") {+ openSavedSqlFile();+ } else if (action === "toggle" && (activeNode.value.type === "mongo-gridfs" || isDocumentBrowserTreeNode(activeNode.value.type))) {+ openMongoTreeData(activeNode.value);+ } else if (action === "toggle") {+ toggle();+ }+}++async function refreshData() {+ const node = activeNode.value;+ if (node.type !== "table" || !hasNodeDatabaseContext(node)) return;+ const singleActivationRefreshAllowed = singleActivationDoubleClickRefreshAllowed;+ singleActivationDoubleClickRefreshAllowed = false;+ const activation = settingsStore.editorSettings.sidebarActivation;+ if (activation === "single" && !singleActivationRefreshAllowed) return;+ const existingSameTableTab = findExistingSameTableDataTab();+ const action = dataTableDoubleClickAction(existingSameTableTab, activation, singleActivationRefreshAllowed);+ if (action === "none") return;+ if (action === "open") {+ openDataImmediately(node);+ return;+ }+ if (!existingSameTableTab) return;+ queryStore.switchTab(existingSameTableTab.id);+ if (action === "activate") return;+ await queryStore.refreshDataTab(existingSameTableTab.id);+}++function findExistingSameTableDataTab() {+ const node = activeNode.value;+ if (node.type !== "table" || !hasNodeDatabaseContext(node)) return undefined;+ const config = connectionStore.getConfig(node.connectionId);+ const tableSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);+ return queryStore.tabs.find((tab) => tab.mode === "data" && tab.connectionId === node.connectionId && tab.database === node.database && (tab.tableMeta?.catalog || "") === (node.catalog || "") && (tab.schema || "") === (tableSchema || "") && (tab.tableMeta?.tableName || tab.title) === node.label);+}++function openMongoTreeData(node: TreeNode) {+ if (!node.connectionId || !node.database) return;+ if (node.type === "mongo-gridfs") {+ queryStore.openMongoGridFs(node.connectionId, node.database);+ return;+ }+ const tabTitle = `${node.database}.${node.label}`;+ if (node.type === "mongo-bucket") {+ queryStore.openMongoBucket(node.connectionId, node.database, node.label);+ return;+ }+ if (node.type !== "mongo-collection") return;+ const tab = queryStore.createTab(node.connectionId, node.database, tabTitle, "mongo");+ queryStore.updateSql(tab, node.label);+}++async function openSavedSqlFile() {+ const node = activeNode.value;+ if (node.type !== "saved-sql-file" || !node.savedSqlId) return;+ const file = await savedSqlStore.ensureFileContent(node.savedSqlId);+ if (!file) return;+ queryStore.openSavedSql(file);+ connectionStore.activeConnectionId = file.connectionId;+ void savedSqlStore.recordFileUsage(file.id);+}++async function openObjectBrowser() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ connectionStore.activeConnectionId = node.connectionId;++ if (hasTreeNodeDatabaseContext(node)) {+ queryStore.openObjectBrowser(node.connectionId, node.database, node.schema, node.catalog);+ return;+ }++ const connection = connectionStore.getConfig(node.connectionId);+ if (!connection) return;+ const options = await getDatabaseOptions(node.connectionId);+ const database = resolveDefaultDatabase(connection, options);+ if (database) {+ queryStore.openObjectBrowser(node.connectionId, database);+ } else {+ await toggle();+ }+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ openDriverStoreForInstallError(e?.message || String(e));+ }+}++async function openUserAdmin() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ connectionStore.activeConnectionId = node.connectionId;+ queryStore.openUserAdmin(node.connectionId);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++async function openProcessList() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ connectionStore.activeConnectionId = node.connectionId;+ queryStore.openProcessList(node.connectionId);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++async function openServerDashboard() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ connectionStore.activeConnectionId = node.connectionId;+ if (currentDatabaseType() === "postgres") {+ queryStore.openPostgresDashboard(node.connectionId);+ } else {+ queryStore.openMysqlDashboard(node.connectionId);+ }+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++async function openDamengJobAdmin() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ connectionStore.activeConnectionId = node.connectionId;+ queryStore.openDamengJobAdmin(node.connectionId);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++function scheduleOpenData(node: TreeNode) {+ emit("open-data", node, true, "default", openData);+}++function openDataImmediately(node: TreeNode = activeNode.value) {+ emit("open-data", node, false, "default", openData);+}++function openDataInNewTabImmediately(node: TreeNode = activeNode.value) {+ emit("open-data", node, false, "new-tab", (target, request) => openData(target, request, "new-tab"));+}++async function newQuery() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ connectionStore.activeConnectionId = node.connectionId;+ if (hasTreeNodeDatabaseContext(node)) {+ if (node.type === "table" || node.type === "view" || node.type === "materialized_view") {+ await newSelectTemplate();+ return;+ }+ queryStore.createTab(node.connectionId, node.database, undefined, "query", node.schema);+ return;+ }+ const connection = connectionStore.getConfig(node.connectionId);+ if (!connection) return;+ const options = await getDatabaseOptions(node.connectionId);+ queryStore.createTab(node.connectionId, resolveDefaultDatabase(connection, options), undefined, "query");+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ openDriverStoreForInstallError(e?.message || String(e));+ }+}++// SQL template helpers have been extracted to @/lib/tableSqlTemplates.ts+// ---- Template actions ----++function openRedisInstanceInfo() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ const config = connectionStore.getConfig(node.connectionId);+ const dbName = config?.name || "Redis";+ queryStore.createTab(node.connectionId, "0", `${dbName} - ${t("contextMenu.instanceInfo")}`, "redis-dashboard");+}++async function loadTemplateContext(allowView = false) {+ const node = activeNode.value;+ if (!node.connectionId || !hasTreeNodeDatabaseContext(node)) return null;+ const isTableNode = node.type === "table";+ const isReadableObject = isTableNode || (allowView && (node.type === "view" || node.type === "materialized_view"));+ if (!isReadableObject) return null;++ await connectionStore.ensureConnected(node.connectionId);+ connectionStore.activeConnectionId = node.connectionId;+ const config = connectionStore.getConfig(node.connectionId);+ const dbType = config ? effectiveDatabaseTypeForConnection(config) : undefined;+ const tableSchema = node.schema || node.database;+ let columns: ColumnInfo[] = [];+ try {+ const querySchema = connectionObjectTreeQuerySchema(config, node.database, tableSchema);+ columns = await api.getColumns(node.connectionId, node.database, querySchema, node.label);+ } catch (e) {+ console.warn("[DBX][tableSqlTemplate:getColumns:error]", e);+ }++ let tableType = node.tableType;+ if (dbType === "tdengine") {+ try {+ const querySchema = connectionObjectTreeQuerySchema(config, node.database, tableSchema);+ const tables = await api.listTables(node.connectionId, node.database, querySchema, node.label, 200);+ const matched = tables.find((table) => table.name.toLowerCase() === node.label.toLowerCase());+ if (matched?.table_type) tableType = matched.table_type;+ } catch (e) {+ console.warn("[DBX][tableSqlTemplate:listTables:error]", e);+ }+ }++ return { node, dbType, tableSchema, columns, tableType };+}++function openSqlTemplateTab(connectionId: string, database: string, schema: string | undefined, sql: string, title?: string) {+ const tabId = queryStore.createTab(connectionId, database, title, "query", schema);+ queryStore.updateSql(tabId, sql);+}++async function newSelectTemplate() {+ try {+ const context = await loadTemplateContext(true);+ if (!context) return;+ const sql = buildTableSelectTemplate({+ databaseType: context.dbType,+ schema: context.tableSchema,+ tableName: context.node.label,+ columns: context.columns,+ });+ openSqlTemplateTab(context.node.connectionId!, context.node.database!, context.node.schema, sql);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++async function newInsertTemplate() {+ try {+ const context = await loadTemplateContext(false);+ if (!context) return;+ const sql = buildTableInsertTemplate({+ databaseType: context.dbType,+ schema: context.tableSchema,+ tableName: context.node.label,+ columns: context.columns,+ tableType: context.tableType,+ });+ openSqlTemplateTab(context.node.connectionId!, context.node.database!, context.node.schema, sql);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++async function newUpdateTemplate() {+ try {+ const context = await loadTemplateContext(false);+ if (!context) return;+ const sql = buildTableUpdateTemplate({+ databaseType: context.dbType,+ schema: context.tableSchema,+ tableName: context.node.label,+ columns: context.columns,+ });+ openSqlTemplateTab(context.node.connectionId!, context.node.database!, context.node.schema, sql);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++async function newDeleteTemplate() {+ try {+ const context = await loadTemplateContext(false);+ if (!context) return;+ const sql = buildTableDeleteTemplate({+ databaseType: context.dbType,+ schema: context.tableSchema,+ tableName: context.node.label,+ columns: context.columns,+ });+ openSqlTemplateTab(context.node.connectionId!, context.node.database!, context.node.schema, sql);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ }+}++async function generateDdlTemplate() {+ const node = activeNode.value;+ if (!node.connectionId || !hasTreeNodeDatabaseContext(node)) return;+ if (node.type !== "table" && node.type !== "view" && node.type !== "materialized_view") return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ connectionStore.activeConnectionId = node.connectionId;+ const schema = node.schema || node.database;+ let ddl: string;+ if (node.type === "table") {+ ddl = await api.getTableDdl(node.connectionId, node.database, schema, node.label, undefined, node.catalog);+ } else if (node.type === "materialized_view") {+ ddl = await api.getTableDdl(node.connectionId, node.database, schema, node.label, "MATERIALIZED_VIEW", node.catalog);+ } else {+ const result = await api.getObjectSource(node.connectionId, node.database, schema, node.label, "VIEW");+ ddl = await buildViewDdl({+ databaseType: currentDatabaseType(),+ schema,+ name: node.label,+ source: result.source,+ });+ }+ const formatted = await formatSqlForDisplay(ddl, sqlFormatDialectForDbType(currentDatabaseType()), settingsStore.editorSettings.sqlFormatter);+ openSqlTemplateTab(node.connectionId, node.database, node.schema, formatted, `DDL - ${node.label}`);+ } catch (e: any) {+ toast(e?.message || String(e), 5000);+ }+}++async function refresh() {+ const node = activeNode.value;+ try {+ await connectionStore.refreshTreeNode(node);+ } catch (e: any) {+ toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ openDriverStoreForInstallError(e?.message || String(e), node);+ }+}++async function copyName() {+ const node = activeNode.value;+ updateTreeClipboardForNodes([node]);+ try {+ await copyToClipboard(copyNameForTreeNode(node));+ toast(t("connection.copied"), 2000);+ } catch (e: any) {+ toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);+ }+}++async function copySelectedNames() {+ const selectedNodes = selectedTreeNodesInVisibleOrder();+ const nodes = selectedNodes.length > 1 && selectedNodes.some((node) => node.id === activeNode.value.id) ? selectedNodes : [activeNode.value];+ const connectionTargets = selectedConnectionClipboardTargets(activeNode.value, nodes);+ if (connectionTargets.length > 0) {+ const copiedCount = connectionStore.copyConnectionsToTreeClipboard(connectionTargets.map((node) => node.connectionId));+ if (copiedCount > 0) toast(t("connection.copied"), 2000);+ return;+ }+ updateTreeClipboardForNodes(nodes);+ try {+ await copyToClipboard(nodes.map(copyNameForTreeNode).join("\n"));+ toast(t("connection.copied"), 2000);+ } catch (e: any) {+ toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);+ }+}++function updateTreeClipboardForNodes(nodes: TreeNode[]) {+ const tableNodes = nodes.filter((node): node is DuplicateStructureSource => node.type === "table" && !!node.connectionId && !!node.database && typeof node.label === "string");+ if (tableNodes.length === 0) {+ connectionStore.treeClipboard = null;+ return;+ }+ connectionStore.treeClipboard = {+ kind: "table-copy",+ tables: tableNodes.map((node) => ({+ connectionId: node.connectionId,+ database: node.database,+ schema: node.schema,+ tableName: node.label,+ })),+ };+}++// --- Table Management Operations ---+const pasteTableDataCopySupported = computed(() => supportsWholeRowTableDataCopy(currentDatabaseType()));++// --- Extension Management ---+function openInstallExtensionDialog(node: TreeNode) {+ emit("open-install-extension", node);+}++// --- Procedure / Function Management ---+function dropObjectSqlOptions(): DropObjectSqlOptions | null {+ return dropObjectSqlOptionsForNode(activeNode.value);+}++function dropObjectSqlOptionsForNode(node: TreeNode): DropObjectSqlOptions | null {+ if (node.type !== "view" && node.type !== "materialized_view" && node.type !== "procedure" && node.type !== "function") return null;+ return {+ databaseType: tableStructureDatabaseTypeForNode(node),+ objectType: node.type === "view" ? "VIEW" : node.type === "materialized_view" ? "MATERIALIZED_VIEW" : node.type === "procedure" ? "PROCEDURE" : "FUNCTION",+ schema: node.schema,+ name: node.objectName || node.label,+ signature: node.signature,+ };+}++function tableChildDropObjectType(type: TreeNodeType): TableChildObjectType | null {+ if (type === "column") return "COLUMN";+ if (type === "index") return "INDEX";+ if (type === "fkey") return "FOREIGN_KEY";+ if (type === "trigger") return "TRIGGER";+ return null;+}++function tableChildDropObjectName(node: TreeNode): string {+ if (node.type === "column") return node.meta && "name" in node.meta ? node.meta.name : node.label.replace(/\s+\(.+\)$/, "");+ if (node.type === "index") return node.meta && "name" in node.meta ? node.meta.name : node.label.replace(/\s+\(.+\)$/, "");+ if (node.type === "fkey") return node.meta && "name" in node.meta ? node.meta.name : node.label;+ if (node.type === "trigger") return node.meta && "name" in node.meta ? node.meta.name : node.label.replace(/\s+\(.+\)$/, "");+ return node.label;+}++function dropTableChildObjectSqlOptions(): DropTableChildObjectSqlOptions | null {+ return dropTableChildObjectSqlOptionsForNode(activeNode.value);+}++function dropTableChildObjectSqlOptionsForNode(node: TreeNode): DropTableChildObjectSqlOptions | null {+ const objectType = tableChildDropObjectType(node.type);+ if (!objectType || !node.tableName) return null;+ const name = tableChildDropObjectName(node).trim();+ if (!name) return null;+ return {+ databaseType: databaseTypeForNode(node),+ objectType,+ schema: node.schema,+ tableName: node.tableName,+ name,+ };+}++const canDropTableChildObject = computed(() => {+ return canDropTableChildObjectNode(activeNode.value);+});++function canDropTableChildObjectNode(node: TreeNode): boolean {+ const options = dropTableChildObjectSqlOptionsForNode(node);+ if (!options) return false;+ const capabilities = getTableStructureCapabilities(options.databaseType);+ if (options.objectType === "COLUMN") return capabilities.dropColumn;+ if (options.objectType === "INDEX") return capabilities.dropIndex;+ return true;+}++function dropObjectMenuLabel(): string {+ if (activeNode.value.type === "view") return t("contextMenu.dropView");+ if (activeNode.value.type === "materialized_view") return t("contextMenu.dropView");+ if (activeNode.value.type === "procedure") return t("contextMenu.dropProcedure");+ if (activeNode.value.type === "function") return t("contextMenu.dropFunction");+ return t("contextMenu.dropObject");+}++function dropObjectConfirmTitle(): string {+ if (activeNode.value.type === "view") return t("contextMenu.confirmDropViewTitle");+ if (activeNode.value.type === "materialized_view") return t("contextMenu.confirmDropViewTitle");+ if (activeNode.value.type === "procedure") return t("contextMenu.confirmDropProcedureTitle");+ if (activeNode.value.type === "function") return t("contextMenu.confirmDropFunctionTitle");+ return t("contextMenu.confirmDropObjectTitle");+}++function dropObjectConfirmMessage(): string {+ if (activeNode.value.type === "view") return t("contextMenu.confirmDropViewMessage", { name: activeNode.value.label });+ if (activeNode.value.type === "materialized_view") return t("contextMenu.confirmDropViewMessage", { name: activeNode.value.label });+ if (activeNode.value.type === "procedure") return t("contextMenu.confirmDropProcedureMessage", { name: activeNode.value.label });+ if (activeNode.value.type === "function") return t("contextMenu.confirmDropFunctionMessage", { name: activeNode.value.label });+ return t("contextMenu.confirmDropObjectMessage", { name: activeNode.value.label });+}++function dropTableChildObjectMenuLabel(): string {+ if (activeNode.value.type === "column") return t("contextMenu.dropColumn");+ if (activeNode.value.type === "index") return t("contextMenu.dropIndex");+ if (activeNode.value.type === "fkey") return t("contextMenu.dropForeignKey");+ if (activeNode.value.type === "trigger") return t("contextMenu.dropTrigger");+ return t("contextMenu.dropObject");+}++function dropTableChildObjectConfirmTitle(): string {+ if (activeNode.value.type === "column") return t("contextMenu.confirmDropColumnTitle");+ if (activeNode.value.type === "index") return t("contextMenu.confirmDropIndexTitle");+ if (activeNode.value.type === "fkey") return t("contextMenu.confirmDropForeignKeyTitle");+ if (activeNode.value.type === "trigger") return t("contextMenu.confirmDropTriggerTitle");+ return t("contextMenu.confirmDropObjectTitle");+}++function dropTableChildObjectConfirmMessage(): string {+ return t("contextMenu.confirmDropTableChildObjectMessage", {+ name: tableChildDropObjectName(activeNode.value),+ table: activeNode.value.tableName || "",+ });+}++async function refreshDropObjectPreviewSql() {+ const options = dropObjectSqlOptions();+ dropObjectPreviewSql.value = "";+ dropObjectPreviewSql.value = options ? await buildDropObjectSql(options).catch(() => "") : "";+}++async function refreshDropTableChildObjectPreviewSql() {+ const options = dropTableChildObjectSqlOptions();+ dropTableChildObjectPreviewSql.value = "";+ dropTableChildObjectPreviewSql.value = options ? await buildDropTableChildObjectSql(options).catch(() => "") : "";+}++function openObjectSourceDialog(initialEditing: boolean) {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ const objectType = objectSourceKindForTreeNode(node.type);+ if (!objectType) return;+ void connectionStore+ .ensureConnected(node.connectionId)+ .then(() => {+ connectionStore.activeConnectionId = node.connectionId!;+ emit("open-object-source", node, initialEditing);+ })+ .catch((e: any) => {+ toast(e?.message || String(e), 5000);+ });+}++function openProcedureExecution() {+ const node = activeNode.value;+ if (node.type !== "procedure" || !node.connectionId || !node.database) return;+ emit("open-procedure", node);+}++function requestDropObject() {+ void refreshDropObjectPreviewSql();+ showDropObjectConfirm.value = true;+}++function requestDropTableChildObject() {+ if (!canDropTableChildObject.value) return;+ void refreshDropTableChildObjectPreviewSql();+ showDropTableChildObjectConfirm.value = true;+}++function canDropTreeNode(node: TreeNode): boolean {+ if (isSqlServerLinkedNode(node)) return false;+ if (node.type === "table") return !!node.connectionId && !!node.database;+ if (node.type === "view" || node.type === "materialized_view" || node.type === "procedure" || node.type === "function") {+ return !!node.connectionId && !!node.database && !!dropObjectSqlOptionsForNode(node);+ }+ if (canDropMongoIndexNode(node)) return true;+ return canDropTableChildObjectNode(node);+}++function droppedTableObjectTypeForNode(node: TreeNode): "TABLE" | "VIEW" | "MATERIALIZED_VIEW" | null {+ if (node.type === "table") return "TABLE";+ if (node.type === "view") return "VIEW";+ if (node.type === "materialized_view") return "MATERIALIZED_VIEW";+ return null;+}++function closeDroppedTableObjectTabsForNode(node: TreeNode) {+ const objectType = droppedTableObjectTypeForNode(node);+ if (!objectType || !node.connectionId || !node.database) return;+ const config = connectionStore.getConfig(node.connectionId);+ const dataTabSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);+ queryStore.closeDroppedTableObjectTabs({+ connectionId: node.connectionId,+ database: node.database,+ schema: dataTabSchema,+ schemaCandidates: [node.schema, dataTabSchema],+ name: node.label,+ objectType,+ });+}++function tableDataRefreshTargetForNode(node: TreeNode) {+ if (!node.connectionId || !node.database) return null;+ const config = connectionStore.getConfig(node.connectionId);+ const dataTabSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);+ return {+ connectionId: node.connectionId,+ database: node.database,+ schema: dataTabSchema,+ schemaCandidates: [node.schema, dataTabSchema],+ catalog: node.catalog,+ name: node.label,+ };+}++async function refreshMutatedTableDataTabsForNode(node: TreeNode) {+ const target = tableDataRefreshTargetForNode(node);+ if (!target) return;+ try {+ await queryStore.refreshDataTabsForTable(target);+ } catch (error) {+ console.warn("[DBX][table-data-refresh-after-mutation:error]", { target, error });+ }+}++async function refreshMutatedTableDataTabsForNodes(nodes: readonly TreeNode[]) {+ for (const target of nodes) {+ await refreshMutatedTableDataTabsForNode(target);+ }+}++function selectedBatchDropTargets(): TreeNode[] {+ const selected = selectedTreeNodesInVisibleOrder();+ if (selected.length <= 1 || !selected.some((node) => node.id === activeNode.value.id)) return [];+ const first = selected[0];+ if (!first?.connectionId || !first.database || !selected.every((node) => node.type === first.type)) return [];+ if (!selected.every((node) => node.connectionId === first.connectionId && node.database === first.database && canDropTreeNode(node))) {+ return [];+ }+ return selected;+}++function selectedBatchTableTargets(): TreeNode[] {+ const targets = selectedBatchDropTargets();+ return targets.length > 1 && targets.every((node) => node.type === "table") ? targets : [];+}++function selectedBatchTruncateTargets(): TreeNode[] {+ const targets = selectedBatchTableTargets();+ return targets.every((node) => supportsTableTruncate(databaseTypeForNode(node))) ? targets : [];+}++function selectedBatchEmptyTargets(): TreeNode[] {+ return selectedBatchTableTargets();+}++function selectedBatchIndexTableName(targets: TreeNode[]): string | null {+ const first = targets[0];+ if (!first) return null;+ const table = first.tableName || first.label;+ return table && targets.every((node) => (node.tableName || node.label) === table) ? table : null;+}++function batchDropMenuLabel(): string {+ const targets = selectedBatchDropTargets();+ if (targets.length > 1 && targets.every((node) => node.type === "index")) {+ return t("contextMenu.batchDropIndexes", { count: targets.length });+ }+ return t("contextMenu.batchDrop", { count: targets.length });+}++function batchDropConfirmTitle(): string {+ const targets = batchDropTargets.value;+ if (targets.length > 1 && targets.every((node) => node.type === "index")) {+ return t("contextMenu.confirmDropIndexTitle");+ }+ return t("contextMenu.confirmBatchDropTitle", { count: targets.length });+}++function batchDropConfirmMessage(): string {+ const targets = batchDropTargets.value;+ const table = selectedBatchIndexTableName(targets);+ if (targets.length > 1 && targets.every((node) => node.type === "index") && table) {+ return t("contextMenu.confirmDropBatchIndexesMessage", { count: targets.length, table });+ }+ return t("contextMenu.confirmBatchDropMessage", { count: targets.length });+}++function batchTruncateMenuLabel(): string {+ return t("contextMenu.batchTruncate", { count: selectedBatchTruncateTargets().length });+}++function batchEmptyMenuLabel(): string {+ return t("contextMenu.batchEmpty", { count: selectedBatchEmptyTargets().length });+}++function batchEmptyConfirmTitle(): string {+ return t("contextMenu.confirmBatchEmptyTitle", { count: batchEmptyTargets.value.length });+}++function batchEmptyConfirmMessage(): string {+ return t("contextMenu.confirmBatchEmptyMessage", { count: batchEmptyTargets.value.length });+}++function batchEmptyConfirmLabel(): string {+ return t("contextMenu.batchEmpty", { count: batchEmptyTargets.value.length });+}++function batchTruncateConfirmTitle(): string {+ return t("contextMenu.confirmBatchTruncateTitle", { count: batchTruncateTargets.value.length });+}++function batchTruncateConfirmMessage(): string {+ return t("contextMenu.confirmBatchTruncateMessage", { count: batchTruncateTargets.value.length });+}++async function dropSqlForTreeNode(node: TreeNode, options?: { cascade?: boolean }): Promise<string | null> {+ if (node.type === "table" && node.connectionId && node.database) {+ return buildDropTableSql({+ databaseType: databaseTypeForNode(node),+ schema: node.schema,+ tableName: node.label,+ cascade: options?.cascade && supportsDropTableCascade(databaseTypeForNode(node)),+ });+ }+ const objectOptions = dropObjectSqlOptionsForNode(node);+ if (objectOptions) return buildDropObjectSql(objectOptions);+ if (canDropMongoIndexNode(node)) {+ return `db.getCollection("${(node.tableName || "").replace(/\\/g, "\\\\").replace(/"/g, '\\"')}").dropIndex(${JSON.stringify(mongoIndexNameForNode(node))})`;+ }+ const childOptions = dropTableChildObjectSqlOptionsForNode(node);+ if (childOptions && canDropTableChildObjectNode(node)) return buildDropTableChildObjectSql(childOptions);+ return null;+}++async function truncateSqlForTreeNode(node: TreeNode, options?: { cascade?: boolean }): Promise<string | null> {+ if (node.type !== "table" || !node.connectionId || !node.database || !supportsTableTruncate(databaseTypeForNode(node))) return null;+ return buildTruncateTableSql({+ databaseType: databaseTypeForNode(node),+ schema: node.schema,+ tableName: node.label,+ cascade: options?.cascade && supportsTruncateTableCascade(databaseTypeForNode(node)),+ });+}++async function emptySqlForTreeNode(node: TreeNode): Promise<string | null> {+ if (node.type !== "table" || !node.connectionId || !node.database) return null;+ return buildEmptyTableSql({+ databaseType: databaseTypeForNode(node),+ schema: node.schema,+ tableName: node.label,+ });+}++async function refreshBatchDropPreviewSql() {+ const targets = batchDropTargets.value;+ const mongoIndexTargets = targets.filter(canDropMongoIndexNode);+ if (mongoIndexTargets.length) {+ batchDropPreviewSql.value = mongoIndexTargets.map((target) => mongoIndexDropPreview(target, mongoIndexNameForNode(target))).join("\n");+ return;+ }+ const statements: string[] = [];+ const useCascade = canBatchDropCascade.value && batchDropCascade.value;+ for (const target of targets) {+ const sql = await dropSqlForTreeNode(target, { cascade: useCascade });+ if (sql) statements.push(sql);+ }+ batchDropPreviewSql.value = statements.join("\n");+}++async function refreshBatchTruncatePreviewSql() {+ const targets = batchTruncateTargets.value;+ const statements: string[] = [];+ const useCascade = canBatchTruncateCascade.value && batchTruncateCascade.value;+ for (const target of targets) {+ const sql = await truncateSqlForTreeNode(target, { cascade: useCascade });+ if (sql) statements.push(sql);+ }+ batchTruncatePreviewSql.value = statements.join("\n");+}++async function refreshBatchEmptyPreviewSql(targets: TreeNode[]) {+ const statements: string[] = [];+ for (const target of targets) {+ const sql = await emptySqlForTreeNode(target);+ if (sql) statements.push(sql);+ }+ batchEmptyPreviewSql.value = statements.join("\n");+}++function requestBatchDrop() {+ const targets = selectedBatchDropTargets();+ if (!targets.length) return;+ batchDropTargets.value = targets.slice();+ batchDropCascade.value = false;+ void refreshBatchDropPreviewSql();+ showBatchDropConfirm.value = true;+}++function requestBatchTruncate() {+ const targets = selectedBatchTruncateTargets();+ if (!targets.length) return;+ batchTruncateTargets.value = targets.slice();+ batchTruncateCascade.value = false;+ void refreshBatchTruncatePreviewSql();+ showBatchTruncateConfirm.value = true;+}++function requestBatchEmpty() {+ const targets = selectedBatchEmptyTargets();+ if (!targets.length) return;+ batchEmptyTargets.value = targets.slice();+ batchEmptyPreviewSql.value = "";+ void refreshBatchEmptyPreviewSql(batchEmptyTargets.value)+ .then(() => {+ if (!batchEmptyPreviewSql.value.trim()) throw new Error("Empty table SQL preview is unavailable");+ showBatchEmptyConfirm.value = true;+ })+ .catch((e: any) => {+ batchEmptyTargets.value = [];+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ });+}++function requestDropSelectedNodes(): boolean {+ const selected = selectedTreeNodesInVisibleOrder();+ if (selected.length > 1 && selected.some((node) => node.id === activeNode.value.id)) {+ if (!selectedBatchDropTargets().length) return false;+ requestBatchDrop();+ return true;+ }+ return requestDropSelectedNode();+}++function requestDropSelectedNode(): boolean {+ if (activeNode.value.type === "table") {+ dropTable();+ return true;+ }+ if (activeNode.value.type === "view" || activeNode.value.type === "procedure" || activeNode.value.type === "function") {+ requestDropObject();+ return true;+ }+ if (canDropMongoIndex.value) {+ dropMongoIndex();+ return true;+ }+ if (canDropTableChildObject.value) {+ requestDropTableChildObject();+ return true;+ }+ return false;+}++function nodeRenameObjectType(): RenameableObjectType | null {+ if (activeNode.value.type === "table") return "TABLE";+ if (activeNode.value.type === "view") return "VIEW";+ if (activeNode.value.type === "materialized_view") return "MATERIALIZED_VIEW";+ if (activeNode.value.type === "procedure") return "PROCEDURE";+ if (activeNode.value.type === "function") return "FUNCTION";+ return null;+}++const canRenameObject = computed(() => {+ const objectType = nodeRenameObjectType();+ return !!objectType && (supportsObjectRename(currentDatabaseType(), objectType) || supportsSourceBackedRoutineRename(currentDatabaseType(), objectType as any));+});++function openRenameObjectDialog() {+ claimTreeItemDialogOwnership();+ routeTreeItemDialogController();+ renameObjectName.value = activeNode.value.label;+ renameObjectError.value = "";+ renameObjectPreviewSql.value = "";+ showRenameObjectDialog.value = true;+}++async function executeTreeNodeSqlWithProductionGuard(node: Pick<TreeNode, "connectionId" | "database" | "schema">, sql: string, options: { database?: string; schema?: string } = {}) {+ if (!node.connectionId) return undefined;+ const database = options.database ?? node.database ?? "";+ return executeWithProductionSqlGuard({+ connection: connectionStore.getConfig(node.connectionId),+ database,+ sql,+ source: t("production.sourceSidebar"),+ execute: () => api.executeQuery(node.connectionId!, database, sql, options.schema ?? node.schema),+ });+}++let renameObjectPreviewRequestId = 0;++async function refreshRenameObjectPreviewSql() {+ const node = activeNode.value;+ const requestId = ++renameObjectPreviewRequestId;+ const objectType = nodeRenameObjectType();+ const newName = renameObjectName.value.trim();+ if (!showRenameObjectDialog.value || !objectType || !newName || newName === node.label) {+ renameObjectPreviewSql.value = "";+ return;+ }+ if (supportsSourceBackedRoutineRename(currentDatabaseType(), objectType as any)) {+ renameObjectPreviewSql.value = `-- Recreate ${objectType} from source, then drop the original object.`;+ return;+ }+ try {+ const sql = await buildRenameObjectSql({+ databaseType: currentDatabaseType(),+ objectType,+ schema: node.schema,+ oldName: node.label,+ newName,+ });+ if (requestId === renameObjectPreviewRequestId) renameObjectPreviewSql.value = sql;+ } catch {+ if (requestId === renameObjectPreviewRequestId) renameObjectPreviewSql.value = "";+ }+}++watch([showRenameObjectDialog, renameObjectName, () => activeNode.value.label, () => activeNode.value.schema, () => activeNode.value.type, () => currentDatabaseType()], () => {+ void refreshRenameObjectPreviewSql();+});++async function confirmRenameObject() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ const objectType = node.type === "table" ? "TABLE" : node.type === "view" ? "VIEW" : node.type === "materialized_view" ? "MATERIALIZED_VIEW" : node.type === "procedure" ? "PROCEDURE" : node.type === "function" ? "FUNCTION" : null;+ const newName = renameObjectName.value.trim();+ if (!objectType || !newName || newName === node.label || !node.connectionId || !node.database) return;+ renameObjectError.value = "";+ try {+ const dbType = databaseTypeForNode(node);+ await connectionStore.ensureConnected(node.connectionId);+ if (supportsSourceBackedRoutineRename(dbType, objectType as any)) {+ const schema = node.schema || node.database;+ const source = await api.getObjectSource(node.connectionId, node.database, schema, node.objectName || node.label, objectType as any, node.signature);+ const statements = await buildRoutineRenameObjectSourceStatements({+ databaseType: dbType!,+ objectType: objectType as any,+ schema,+ name: node.label,+ newName,+ source: source.source,+ });+ for (const sql of statements) {+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema });+ }+ } else {+ const sql = await buildRenameObjectSql({+ databaseType: dbType,+ objectType,+ schema: node.schema,+ oldName: node.label,+ newName,+ });+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });+ }+ toast(t("contextMenu.renameObjectSuccess", { oldName: node.label, newName }), 3000);+ showRenameObjectDialog.value = false;+ await refreshTableList(node);+ } catch (e: any) {+ renameObjectError.value = e?.message || String(e);+ }+}++async function confirmDropObject() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (!node.connectionId || !node.database) return;+ const options = dropObjectSqlOptionsForNode(node);+ if (!options) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const sql = dropObjectPreviewSql.value || (await buildDropObjectSql(options));+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });+ const msgKey = node.type === "view" ? "contextMenu.dropViewSuccess" : node.type === "materialized_view" ? "contextMenu.dropViewSuccess" : node.type === "procedure" ? "contextMenu.dropProcedureSuccess" : "contextMenu.dropFunctionSuccess";+ toast(t(msgKey, { name: node.label }), 3000);+ closeDroppedTableObjectTabsForNode(node);+ if (node.type === "view" || node.type === "materialized_view") {+ connectionStore.removeTreeNode(node.id);+ releaseActiveNodeReference([node.id]);+ } else {+ await refreshTableList(node);+ }+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ }+}++async function confirmDropTableChildObject() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (!node.connectionId || !node.database) return;+ const options = dropTableChildObjectSqlOptionsForNode(node);+ if (!options) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const sql = dropTableChildObjectPreviewSql.value || (await buildDropTableChildObjectSql(options));+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });+ toast(t("contextMenu.dropTableChildObjectSuccess", { name: options.name }), 3000);+ connectionStore.removeTreeNode(node.id);+ releaseActiveNodeReference([node.id]);+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ }+}++async function confirmBatchDrop() {+ const targets = batchDropTargets.value.slice();+ if (!targets.length) return;+ try {+ const mongoIndexTargets = targets.filter(canDropMongoIndexNode);+ if (mongoIndexTargets.length) {+ const grouped = new Map<string, TreeNode[]>();+ for (const target of mongoIndexTargets) {+ const key = `${target.connectionId}:${target.database}:${target.tableName || ""}`;+ const list = grouped.get(key) ?? [];+ list.push(target);+ grouped.set(key, list);+ }+ let droppedCount = 0;+ for (const groupTargets of grouped.values()) {+ const first = groupTargets[0];+ if (!first?.connectionId || !first.database || !first.tableName) continue;+ await connectionStore.ensureConnected(first.connectionId);+ const names = groupTargets.map((target) => mongoIndexNameForNode(target));+ const result = await api.mongoDropIndexes(first.connectionId, first.database, first.tableName, JSON.stringify(names.length === 1 ? names[0] : names), false);+ const dropped = new Set(result.dropped_names);+ droppedCount += result.dropped_names.length;+ for (const target of groupTargets) {+ if (!dropped.has(mongoIndexNameForNode(target))) continue;+ connectionStore.removeTreeNode(target.id);+ releaseActiveNodeReference([target.id]);+ }+ }+ toast(t("contextMenu.batchDropSuccess", { count: droppedCount }), 3000);+ showBatchDropConfirm.value = false;+ return;+ }+ const useCascade = batchDropCascade.value && targets.every((node) => node.type !== "table" || supportsDropTableCascade(databaseTypeForNode(node)));+ for (const target of targets) {+ if (!target.connectionId || !target.database) continue;+ await connectionStore.ensureConnected(target.connectionId);+ const sql = await dropSqlForTreeNode(target, { cascade: useCascade });+ if (!sql) continue;+ await executeTreeNodeSqlWithProductionGuard(target, sql, { database: target.database, schema: target.schema });+ closeDroppedTableObjectTabsForNode(target);+ connectionStore.removeTreeNode(target.id);+ releaseActiveNodeReference([target.id]);+ }+ toast(t("contextMenu.batchDropSuccess", { count: targets.length }), 3000);+ showBatchDropConfirm.value = false;+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ }+}++async function confirmBatchTruncate() {+ const targets = batchTruncateTargets.value.slice();+ if (!targets.length) return;+ try {+ const useCascade = batchTruncateCascade.value && targets.every((node) => supportsTruncateTableCascade(databaseTypeForNode(node)));+ await runBatchTableTruncate(+ targets,+ async (target) => {+ if (!target.connectionId || !target.database) return false;+ await connectionStore.ensureConnected(target.connectionId);+ const sql = await truncateSqlForTreeNode(target, { cascade: useCascade });+ if (!sql) return false;+ const result = await executeTreeNodeSqlWithProductionGuard(target, sql, { database: target.database, schema: target.schema });+ return result === undefined ? false : undefined;+ },+ refreshMutatedTableDataTabsForNodes,+ );+ toast(t("contextMenu.batchTruncateSuccess", { count: targets.length }), 3000);+ showBatchTruncateConfirm.value = false;+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ }+}++async function confirmBatchEmpty() {+ const targets = batchEmptyTargets.value.slice();+ if (!targets.length) return;+ const asynchronousMutation = targets.every((target) => databaseTypeForNode(target) === "clickhouse");+ const result = await runBatchTableEmpty(targets, async (target) => {+ if (!target.connectionId || !target.database) throw new Error("Missing table connection context");+ await connectionStore.ensureConnected(target.connectionId);+ const sql = await emptySqlForTreeNode(target);+ if (!sql) throw new Error("Empty table SQL is unavailable");+ await executeTreeNodeSqlWithProductionGuard(target, sql, { database: target.database, schema: target.schema });+ });+ for (const failure of result.failed) {+ console.error(`Failed to empty table "${failure.target.label}":`, failure.error);+ }+ const feedback = batchTableEmptyFeedback(result, asynchronousMutation);+ if (feedback === "success") {+ toast(t("contextMenu.batchEmptySuccess", { count: result.succeeded.length }), 3000);+ } else if (feedback === "submitted") {+ toast(t("contextMenu.batchEmptySubmitted", { count: result.succeeded.length }), 3000);+ } else if (feedback === "submitted-partial") {+ toast(t("contextMenu.batchEmptySubmittedPartial", { success: result.succeeded.length, failed: result.failed.length }), 5000);+ } else {+ toast(t("contextMenu.batchEmptyPartialFail", { success: result.succeeded.length, failed: result.failed.length }), 5000);+ }+ await refreshMutatedTableDataTabsForNodes(result.succeeded);+ batchEmptyTargets.value = [];+ showBatchEmptyConfirm.value = false;+}++const canCreateTable = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return (activeNode.value.type === "database" || activeNode.value.type === "schema" || activeNode.value.type === "group-tables") && !isSqlServerLinkedNode(activeNode.value) && !!activeNode.value.database && supportsTableStructureEditing(tableStructureDatabaseTypeForConnection(config));+});++const canCreateDatabase = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "connection" && canCreateConnectionNamespace(config);+});++const canCreateNacosNamespace = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "connection" && config?.db_type === "nacos" && !config.read_only;+});++const canEditNacosNamespace = computed(() => {+ if (activeNode.value.type !== "nacos-namespace" || !activeNode.value.connectionId || !activeNode.value.nacosNamespace) return false;+ const config = connectionStore.getConfig(activeNode.value.connectionId);+ return config?.db_type === "nacos" && !config.read_only;+});++const isDuckDbConnection = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "connection" && connectionNamespaceCreationTarget(config) === "attach";+});++const isConnectionSchemaCreation = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "connection" && connectionNamespaceCreationTarget(config) === "schema";+});++const canSetCreateDatabaseCharset = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return connectionNamespaceCreationTarget(config) === "database" && supportsCreateDatabaseCharset(config?.db_type, config?.driver_profile);+});++const canDropDatabase = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "database" && !isSqlServerLinkedNode(activeNode.value) && supportsDatabaseCreation(config?.db_type);+});++const databasePropertyGroups = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return editableDatabasePropertyGroups(config, activeNode.value);+});++const canEditDatabaseProperties = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return canEditDatabasePropertiesForNode(config, activeNode.value) && !isSqlServerLinkedNode(activeNode.value);+});++const canEditDatabaseCharsetCollation = computed(() => databasePropertyGroups.value.includes("charsetCollation"));++const canEditDatabaseComment = computed(() => databasePropertyGroups.value.includes("databaseComment"));++const canCreateSchema = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return canCreateDatabaseNodeNamespace(config, activeNode.value) && !isSqlServerLinkedNode(activeNode.value) && !connectionUsesDatabaseObjectTreeMode(config);+});++const canDropSchema = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "schema" && !isSqlServerLinkedNode(activeNode.value) && usesTreeSchemaMode(effectiveDatabaseTypeForConnection(config)) && !connectionUsesDatabaseObjectTreeMode(config);+});++const canEditSchemaComment = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "schema" && !!activeNode.value.database && !config?.read_only && supportsSchemaComment(effectiveDatabaseTypeForConnection(config));+});++const canBatchDropCascade = computed(() => {+ const targets = selectedBatchTableTargets();+ return targets.length > 1 && targets.every((node) => supportsDropTableCascade(databaseTypeForNode(node)));+});++const canBatchTruncateCascade = computed(() => {+ const targets = selectedBatchTruncateTargets();+ return targets.length > 1 && targets.every((node) => supportsTruncateTableCascade(databaseTypeForNode(node)));+});++async function refreshDropDatabasePreviewSql() {+ const node = activeNode.value;+ if (node.type === "mongo-db") {+ dropDatabasePreviewSql.value = `db.getSiblingDB(${JSON.stringify(node.label)}).dropDatabase();`;+ return;+ }+ dropDatabasePreviewSql.value = "";+ dropDatabasePreviewSql.value = await buildDropDatabaseSql({+ databaseType: currentDatabaseType(),+ name: node.label,+ }).catch(() => "");+}++async function refreshDropSchemaPreviewSql() {+ const node = activeNode.value;+ dropSchemaPreviewSql.value = "";+ dropSchemaPreviewSql.value = await buildDropSchemaSql({+ databaseType: currentDatabaseType(),+ name: node.label,+ }).catch(() => "");+}++function databasePropertyName(): string {+ return activeNode.value.database || activeNode.value.label;+}++function resultColumnValue(result: { columns?: string[]; rows?: unknown[] }, names: string[]): string {+ const firstRow = result.rows?.[0];+ if (Array.isArray(firstRow)) {+ const lowerNames = names.map((name) => name.toLowerCase());+ const index = Math.max(0, result.columns?.findIndex((column) => lowerNames.includes(column.toLowerCase())) ?? 0);+ return firstRow[index] == null ? "" : String(firstRow[index]);+ }+ if (firstRow && typeof firstRow === "object") {+ const record = firstRow as Record<string, unknown>;+ const key = Object.keys(record).find((column) => names.some((name) => name.toLowerCase() === column.toLowerCase()));+ const value = key ? record[key] : undefined;+ return value == null ? "" : String(value);+ }+ return "";+}++function databasePropertyEditOptions() {+ if (!canEditDatabaseProperties.value) return null;+ const base = {+ databaseType: currentDatabaseType(),+ driverProfile: activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId)?.driver_profile : undefined,+ target: "database" as const,+ name: databasePropertyName(),+ };+ if (canEditDatabaseCharsetCollation.value) {+ return {+ ...base,+ charset: editDatabaseCharset.value,+ collation: editDatabaseCollation.value,+ };+ }+ if (canEditDatabaseComment.value) {+ return {+ ...base,+ comment: editDatabaseCommentText.value,+ };+ }+ return null;+}++async function refreshEditDatabasePropertiesPreviewSql() {+ editDatabasePropertiesPreviewSql.value = "";+ const options = databasePropertyEditOptions();+ if (!options) return;+ editDatabasePropertiesPreviewSql.value = await buildUpdateDatabasePropertiesSql(options).catch(() => "");+}++async function loadDatabaseCharsetProperties() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ const sql = `SELECT DEFAULT_CHARACTER_SET_NAME AS charset, DEFAULT_COLLATION_NAME AS collation FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = '${databasePropertyName().replace(/'/g, "''")}';`;+ const result = await api.executeQuery(node.connectionId, databasePropertyName(), sql, undefined, undefined, { maxRows: 1 });+ const charset = resultColumnValue(result, ["charset", "DEFAULT_CHARACTER_SET_NAME"]);+ const collation = resultColumnValue(result, ["collation", "DEFAULT_COLLATION_NAME"]);+ if (charset) editDatabaseCharset.value = charset;+ if (collation) editDatabaseCollation.value = collation;+}++async function loadDatabaseCommentProperty() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ const sql = buildGetDatabaseCommentSql({+ databaseType: currentDatabaseType(),+ name: databasePropertyName(),+ });+ const result = await api.executeQuery(node.connectionId, databasePropertyName(), sql, undefined, undefined, { maxRows: 1 });+ editDatabaseCommentText.value = resultColumnValue(result, ["comment"]);+}++async function openEditDatabasePropertiesDialog() {+ const node = activeNode.value;+ if (!canEditDatabaseProperties.value || !node.connectionId) return;+ editDatabasePropertiesLoading.value = true;+ editDatabaseCharset.value = "utf8mb4";+ editDatabaseCollation.value = "utf8mb4_unicode_ci";+ editDatabaseCommentText.value = "";+ editDatabasePropertiesPreviewSql.value = "";+ createDatabaseCharsetOptions.value = fallbackCreateDatabaseCharset.charsets;+ createDatabaseCollationsByCharset.value = fallbackCreateDatabaseCharset.collationsByCharset;+ showEditDatabasePropertiesDialog.value = true;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ if (canEditDatabaseCharsetCollation.value) {+ await loadCreateDatabaseCharsetMetadata("edit");+ await loadDatabaseCharsetProperties().catch(() => undefined);+ } else if (canEditDatabaseComment.value) {+ await loadDatabaseCommentProperty().catch(() => undefined);+ }+ await refreshEditDatabasePropertiesPreviewSql();+ } finally {+ editDatabasePropertiesLoading.value = false;+ }+}++async function confirmEditDatabaseProperties() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ const config = node.connectionId ? connectionStore.getConfig(node.connectionId) : undefined;+ const propertyGroups = editableDatabasePropertyGroups(config, node);+ if (!propertyGroups.length || !node.connectionId || editDatabasePropertiesLoading.value) return;+ editDatabasePropertiesLoading.value = true;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const base = {+ databaseType: databaseTypeForNode(node),+ driverProfile: config?.driver_profile,+ target: "database" as const,+ name: node.database || node.label,+ };+ const options = propertyGroups.includes("charsetCollation") ? { ...base, charset: editDatabaseCharset.value, collation: editDatabaseCollation.value } : propertyGroups.includes("databaseComment") ? { ...base, comment: editDatabaseCommentText.value } : null;+ if (!options) return;+ const sql = await buildUpdateDatabasePropertiesSql(options);+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database || node.label });+ toast(t("contextMenu.editDatabasePropertiesSuccess", { name: node.label }), 3000);+ showEditDatabasePropertiesDialog.value = false;+ await connectionStore.loadDatabases(node.connectionId, { force: true });+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ } finally {+ editDatabasePropertiesLoading.value = false;+ }+}++watch([editDatabaseCharset, editDatabaseCollation, editDatabaseCommentText], () => {+ if (showEditDatabasePropertiesDialog.value) void refreshEditDatabasePropertiesPreviewSql();+});++async function refreshSchemaCommentPreviewSql() {+ const node = activeNode.value;+ if (!canEditSchemaComment.value) {+ schemaCommentPreviewSql.value = "";+ return;+ }+ schemaCommentPreviewSql.value = await buildUpdateDatabasePropertiesSql({+ databaseType: currentDatabaseType(),+ target: "schema",+ name: node.schema || node.label,+ comment: schemaCommentText.value,+ }).catch(() => "");+}++watch(schemaCommentText, () => {+ if (showEditSchemaCommentDialog.value) void refreshSchemaCommentPreviewSql();+});++function schemaCommentFromResult(result: { columns?: string[]; rows?: unknown[] }): string {+ return resultColumnValue(result, ["comment"]);+}++async function openEditSchemaCommentDialog() {+ const node = activeNode.value;+ if (!canEditSchemaComment.value || !node.connectionId || !node.database) return;+ schemaCommentText.value = "";+ schemaCommentLoading.value = true;+ showEditSchemaCommentDialog.value = true;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const sql = buildGetSchemaCommentSql({+ databaseType: currentDatabaseType(),+ name: node.schema || node.label,+ });+ const result = await api.executeQuery(node.connectionId, node.database, sql, node.schema, undefined, { maxRows: 1 });+ schemaCommentText.value = schemaCommentFromResult(result);+ await refreshSchemaCommentPreviewSql();+ } catch {+ schemaCommentText.value = "";+ await refreshSchemaCommentPreviewSql();+ } finally {+ schemaCommentLoading.value = false;+ }+}++async function confirmEditSchemaComment() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ if (!canEditSchemaComment.value || !node.connectionId || !node.database || schemaCommentLoading.value) return;+ schemaCommentLoading.value = true;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const sql = await buildUpdateDatabasePropertiesSql({+ databaseType: databaseTypeForNode(node),+ target: "schema",+ name: node.schema || node.label,+ comment: schemaCommentText.value,+ });+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });+ toast(t("contextMenu.editSchemaCommentSuccess", { name: node.label }), 3000);+ showEditSchemaCommentDialog.value = false;+ await connectionStore.loadSchemas(node.connectionId, node.database, { force: true });+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);+ } finally {+ schemaCommentLoading.value = false;+ }+}++async function openCreateDatabase() {+ if (isDuckDbConnection.value) {+ await createDuckDbAttachedDatabaseFile();+ return;+ }+ openCreateDatabaseDialog();+}++function openCreateDatabaseDialog() {+ createDatabaseName.value = "";+ createDatabaseCharset.value = "utf8mb4";+ createDatabaseCollation.value = "utf8mb4_unicode_ci";+ createDatabaseUsers.value = [];+ createDatabaseSelectedUsers.value = [];+ createDatabaseUsersLoading.value = false;+ createDatabaseAuthorizationPlan.value = undefined;+ createDatabasePreviewSql.value = "";+ createDatabaseAuthorizationResults.value = [];+ createDatabaseCharsetOptions.value = fallbackCreateDatabaseCharset.charsets;+ createDatabaseCollationsByCharset.value = fallbackCreateDatabaseCharset.collationsByCharset;+ showCreateDatabaseDialog.value = true;+ if (canSetCreateDatabaseCharset.value) {+ void loadCreateDatabaseCharsetMetadata();+ }+ void loadCreateDatabaseUsers();+}++let createDatabaseUsersRequestId = 0;++async function loadCreateDatabaseUsers() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ if (!node.connectionId) return;+ const connectionId = node.connectionId;+ const requestId = ++createDatabaseUsersRequestId;+ const requestOwner = sidebarTreeDialogOwner.value;+ const requestIsActive = () => requestId === createDatabaseUsersRequestId && sidebarTreeDialogOwner.value === requestOwner && sidebarFormTarget.value?.connectionId === connectionId && showCreateDatabaseDialog.value;+ const config = connectionStore.getConfig(node.connectionId);+ const userProvider = resolveDatabaseUserAdminProviderForConnection(config);+ if (!userProvider) return;+ createDatabaseUsersLoading.value = true;+ try {+ await connectionStore.ensureConnected(connectionId);+ try {+ const result = await api.executeQuery(connectionId, "", userProvider.listUsersSql(), undefined, undefined, { maxRows: 5000 });+ if (requestIsActive()) createDatabaseUsers.value = userProvider.parseUsers(result);+ } catch (error) {+ if (!userProvider.fallbackListUsersSql || !userProvider.parseFallbackUsers) throw error;+ const result = await api.executeQuery(connectionId, "", userProvider.fallbackListUsersSql(), undefined, undefined, { maxRows: 5000 });+ if (requestIsActive()) createDatabaseUsers.value = userProvider.parseFallbackUsers(result);+ }+ } catch (error: any) {+ if (requestIsActive()) {+ createDatabaseUsers.value = [];+ toast(t("contextMenu.createDatabaseUsersLoadFailed", { message: error?.message || String(error) }), 5000);+ }+ } finally {+ if (requestIsActive()) createDatabaseUsersLoading.value = false;+ }+}++function createDatabaseUserKey(user: DatabaseUserIdentity): string {+ return `${user.user}\u0000${user.host}`;+}++function createDatabaseUserLabel(user: DatabaseUserIdentity): string {+ const node = sidebarFormTarget.value ?? activeNode.value;+ const provider = resolveDatabaseUserAdminProviderForConnection(connectionStore.getConfig(node.connectionId || ""));+ return provider?.label(user) ?? user.user;+}++function createDatabaseUserSelected(user: DatabaseUserIdentity): boolean {+ const key = createDatabaseUserKey(user);+ return createDatabaseSelectedUsers.value.some((selected) => createDatabaseUserKey(selected) === key);+}++function toggleCreateDatabaseUser(user: DatabaseUserIdentity) {+ const key = createDatabaseUserKey(user);+ if (createDatabaseSelectedUsers.value.some((selected) => createDatabaseUserKey(selected) === key)) {+ createDatabaseSelectedUsers.value = createDatabaseSelectedUsers.value.filter((selected) => createDatabaseUserKey(selected) !== key);+ } else {+ createDatabaseSelectedUsers.value = [...createDatabaseSelectedUsers.value, user];+ }+}++function openConnectionNamespaceCreation() {+ if (isConnectionSchemaCreation.value) {+ openCreateSchemaDialog();+ return;+ }+ void openCreateDatabase();+}++function connectionNamespaceCreationLabel() {+ if (isDuckDbConnection.value) return t("contextMenu.createDuckDbFile");+ if (isConnectionSchemaCreation.value) return t("contextMenu.createSchema");+ return t("contextMenu.createDatabase");+}++function updateCreateDatabaseCharset(value: string) {+ const previousCharset = createDatabaseCharset.value;+ createDatabaseCharset.value = value;+ createDatabaseCollation.value = nextCreateDatabaseCollation(value, previousCharset, createDatabaseCollation.value, createDatabaseCollationsByCharset.value);+}++function updateEditDatabaseCharset(value: string) {+ const previousCharset = editDatabaseCharset.value;+ editDatabaseCharset.value = value;+ editDatabaseCollation.value = nextCreateDatabaseCollation(value, previousCharset, editDatabaseCollation.value, createDatabaseCollationsByCharset.value);+}++async function loadCreateDatabaseCharsetMetadata(target: "create" | "edit" = "create") {+ const node = activeNode.value;+ if (!node.connectionId || createDatabaseCharsetLoading.value) return;+ createDatabaseCharsetLoading.value = true;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const [charsetResult, collationResult] = await Promise.all([api.executeQuery(node.connectionId, "", "SHOW CHARACTER SET", undefined, undefined, { maxRows: 1000 }), api.executeQuery(node.connectionId, "", "SHOW COLLATION", undefined, undefined, { maxRows: 10000 })]);+ if (target === "create" && !showCreateDatabaseDialog.value) return;+ if (target === "edit" && !showEditDatabasePropertiesDialog.value) return;+ const metadata = parseCreateDatabaseCharsetMetadata(charsetResult, collationResult);+ createDatabaseCharsetOptions.value = metadata.charsets;+ createDatabaseCollationsByCharset.value = metadata.collationsByCharset;+ const selectedCharset = target === "create" ? createDatabaseCharset.value : editDatabaseCharset.value;+ if (!createDatabaseCharsetOptions.value.includes(selectedCharset) && createDatabaseCharsetOptions.value.length) {+ if (target === "create") {+ updateCreateDatabaseCharset(createDatabaseCharsetOptions.value[0]);+ } else {+ updateEditDatabaseCharset(createDatabaseCharsetOptions.value[0]);+ }+ } else {+ if (target === "create") {+ createDatabaseCollation.value = nextCreateDatabaseCollation(createDatabaseCharset.value, createDatabaseCharset.value, createDatabaseCollation.value, createDatabaseCollationsByCharset.value);+ } else {+ editDatabaseCollation.value = nextCreateDatabaseCollation(editDatabaseCharset.value, editDatabaseCharset.value, editDatabaseCollation.value, createDatabaseCollationsByCharset.value);+ }+ }+ } catch {+ createDatabaseCharsetOptions.value = fallbackCreateDatabaseCharset.charsets;+ createDatabaseCollationsByCharset.value = fallbackCreateDatabaseCharset.collationsByCharset;+ } finally {+ createDatabaseCharsetLoading.value = false;+ }+}++function ensureDuckDbFileExtension(path: string): string {+ return /\.(duckdb|db)$/i.test(path) ? path : `${path}.duckdb`;+}++async function createDuckDbAttachedDatabaseFile() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ if (!isTauriRuntime()) {+ toast(t("contextMenu.createDuckDbFileDesktopOnly"), 4000);+ return;+ }++ try {+ const { save } = await import("@tauri-apps/plugin-dialog");+ const selectedPath = await save({+ defaultPath: "database.duckdb",+ filters: [{ name: "DuckDB", extensions: ["duckdb", "db"] }],+ });+ if (!selectedPath) return;++ const path = ensureDuckDbFileExtension(selectedPath);+ await connectionStore.ensureConnected(node.connectionId);+ const existingDatabases = await api.listDatabases(node.connectionId);+ const name = uniqueDuckDbAttachedDatabaseName(+ duckDbAttachedDatabaseNameFromPath(path),+ existingDatabases.map((database) => database.name),+ );+ const sql = await buildDuckDbAttachDatabaseSql(path, name);+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: "" });++ const config = connectionStore.getConfig(node.connectionId);+ if (config) {+ await connectionStore.updateConnection({+ ...config,+ attached_databases: [...(config.attached_databases ?? []), { name, path }],+ });+ }+ await connectionStore.ensureVisibleDatabase(node.connectionId, name);+ await connectionStore.loadDatabases(node.connectionId, { force: true });+ connectionStore.selectedTreeNodeId = `${node.connectionId}:${name}`;+ toast(t("contextMenu.createDuckDbFileSuccess", { name }), 3000);+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ }+}++async function confirmCreateDatabase() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ const name = createDatabaseName.value.trim();+ if (!name || !node.connectionId) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const config = connectionStore.getConfig(node.connectionId);+ if (config?.db_type === "mongodb") {+ showCreateDatabaseDialog.value = false;+ await api.mongoCreateDatabase(node.connectionId, name);+ toast(t("contextMenu.createDatabaseSuccess", { name }), 3000);+ await connectionStore.ensureVisibleDatabase(node.connectionId, name);+ await connectionStore.loadMongoDatabases(node.connectionId);+ return;+ }+ const sql = await buildCreateDatabaseSql({+ databaseType: config?.db_type,+ driverProfile: config?.driver_profile,+ target: "database",+ name,+ charset: createDatabaseCharset.value,+ collation: createDatabaseCollation.value,+ });+ const provider = resolveDatabaseUserAdminProviderForConnection(config);+ const plan: AuthorizationPlan = provider+ ? buildCreateDatabaseAuthorizationPlan({ provider, database: name, createSql: sql, users: createDatabaseSelectedUsers.value })+ : { steps: [{ id: "create-database", label: `create database ${name}`, database: "", sql, operation: "createDatabase", targetDatabase: name }] };+ createDatabaseAuthorizationPlan.value = plan;+ createDatabasePreviewSql.value = authorizationPlanSql(plan);+ createDatabaseAuthorizationResults.value = [];+ showCreateDatabaseDialog.value = false;+ showCreateDatabasePreviewDialog.value = true;+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ }+}++async function applyCreateDatabaseAuthorizationPlan() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ const plan = createDatabaseAuthorizationPlan.value;+ const name = createDatabaseName.value.trim();+ if (!node.connectionId || !plan || createDatabaseAuthorizationApplying.value) return;+ createDatabaseAuthorizationApplying.value = true;+ try {+ const results = await executeWithProductionSqlGuard({+ connection: connectionStore.getConfig(node.connectionId),+ database: "",+ sql: createDatabasePreviewSql.value,+ source: t("production.sourceSidebar"),+ execute: () => executeAuthorizationPlan(plan, (step) => api.executeMulti(node.connectionId!, step.database, step.sql, undefined, undefined, { maxRows: 1000, continueOnError: true })),+ });+ if (!results) return;+ createDatabaseAuthorizationResults.value = results;+ const created = results.some((result) => result.step.id === "create-database" && result.status === "success");+ const status = authorizationPlanStatus(results);+ if (created) {+ await connectionStore.ensureVisibleDatabase(node.connectionId, name);+ await connectionStore.loadDatabases(node.connectionId, { force: true });+ }+ toast(t(status === "success" ? "contextMenu.createDatabaseSuccess" : status === "partial" ? "contextMenu.createDatabasePartial" : "contextMenu.createDatabaseFailed", { name }), status === "success" ? 3000 : 5000);+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);+ } finally {+ createDatabaseAuthorizationApplying.value = false;+ }+}++function createDatabaseAuthorizationStepLabel(result: AuthorizationStepResult): string {+ const step = result.step;+ if (step.operation === "createDatabase") return t("contextMenu.createDatabaseStep", { database: step.targetDatabase });+ if (step.operation === "grantDatabase") return t("contextMenu.createDatabaseGrantStep", { user: step.subject, database: step.targetDatabase });+ if (step.operation === "grantCurrentObjects") {+ return t("userAdmin.stepGrantCurrentObjects", {+ user: step.subject,+ database: step.targetDatabase,+ schema: step.schema,+ scope: createDatabaseAuthorizationScopeLabel(step.objectScope),+ });+ }+ if (step.operation === "grantFutureObjects") {+ return step.owner+ ? t("userAdmin.stepGrantFutureObjectsForOwner", { user: step.subject, database: step.targetDatabase, owner: step.owner, scope: createDatabaseAuthorizationScopeLabel(step.objectScope) })+ : t("userAdmin.stepGrantFutureObjects", { user: step.subject, database: step.targetDatabase, scope: createDatabaseAuthorizationScopeLabel(step.objectScope) });+ }+ return step.label;+}++function createDatabaseAuthorizationScopeLabel(scope: AuthorizationStepResult["step"]["objectScope"]): string {+ if (scope === "schemas") return t("userAdmin.scopeSchemas");+ if (scope === "tables") return t("userAdmin.scopeTables");+ if (scope === "sequences") return t("userAdmin.scopeSequences");+ if (scope === "functions") return t("userAdmin.scopeFunctions");+ return "";+}++function dropDatabase() {+ void refreshDropDatabasePreviewSql();+ dropDatabaseLoading.value = false;+ showDropDatabaseConfirm.value = true;+}++async function confirmDropDatabase() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (!node.connectionId || dropDatabaseLoading.value) return;+ dropDatabaseLoading.value = true;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ if (node.type === "mongo-db" && node.database) {+ await api.mongoDropDatabase(node.connectionId, node.database);+ toast(t("contextMenu.dropDatabaseSuccess", { name: node.label }), 3000);+ await connectionStore.loadMongoDatabases(node.connectionId);+ showDropDatabaseConfirm.value = false;+ return;+ }+ const sql =+ dropDatabasePreviewSql.value ||+ (await buildDropDatabaseSql({+ databaseType: databaseTypeForNode(node),+ name: node.label,+ }));+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: "" });+ toast(t("contextMenu.dropDatabaseSuccess", { name: node.label }), 3000);+ await connectionStore.loadDatabases(node.connectionId, { force: true });+ showDropDatabaseConfirm.value = false;+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ } finally {+ dropDatabaseLoading.value = false;+ }+}++function openCreateSchemaDialog() {+ createSchemaName.value = "";+ showCreateSchemaDialog.value = true;+}++async function confirmCreateSchema() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ const name = createSchemaName.value.trim();+ const config = node.connectionId ? connectionStore.getConfig(node.connectionId) : undefined;+ const isConnectionLevelSchemaCreation = node.type === "connection" && connectionNamespaceCreationTarget(config) === "schema";+ const targetDatabase = isConnectionLevelSchemaCreation ? "" : node.database;+ if (!name || !node.connectionId || (!targetDatabase && !isConnectionLevelSchemaCreation)) return;+ showCreateSchemaDialog.value = false;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const sql = await buildCreateSchemaSql({+ databaseType: effectiveDatabaseTypeForConnection(config),+ name,+ });+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: targetDatabase || "" });+ toast(t("contextMenu.createSchemaSuccess", { name }), 3000);+ if (isConnectionLevelSchemaCreation) {+ await connectionStore.loadDatabases(node.connectionId, { force: true });+ } else if (config?.db_type === "sqlserver") {+ await connectionStore.loadSqlServerDatabaseObjects(node.connectionId, targetDatabase || "", { force: true });+ } else {+ await connectionStore.loadSchemas(node.connectionId, targetDatabase || "", { force: true });+ }+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ }+}++function dropSchema() {+ void refreshDropSchemaPreviewSql();+ showDropSchemaConfirm.value = true;+}++async function confirmDropSchema() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (!node.connectionId || !node.database) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const sql =+ dropSchemaPreviewSql.value ||+ (await buildDropSchemaSql({+ databaseType: databaseTypeForNode(node),+ name: node.label,+ }));+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database });+ toast(t("contextMenu.dropSchemaSuccess", { name: node.label }), 3000);+ const config = connectionStore.getConfig(node.connectionId);+ if (config?.db_type === "sqlserver") {+ await connectionStore.loadSqlServerDatabaseObjects(node.connectionId, node.database, { force: true });+ } else {+ await connectionStore.loadSchemas(node.connectionId, node.database, { force: true });+ }+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ }+}++function duplicateStructure(source: TreeNode = activeNode.value) {+ if (!isDuplicateStructureSource(source)) return;+ duplicateStructureSource.value = source;+ duplicateTableName.value = `${source.label}_copy`;+ showDuplicateDialog.value = true;+}++function isDuplicateStructureSource(node: TreeNode): node is DuplicateStructureSource {+ return node.type === "table" && !!node.connectionId && !!node.database;+}++async function confirmDuplicateStructure() {+ const node = duplicateStructureSource.value || (isDuplicateStructureSource(activeNode.value) ? activeNode.value : null);+ const newName = duplicateTableName.value.trim();+ if (!newName || !node) return;+ showDuplicateDialog.value = false;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const databaseType = databaseTypeForNode(node);+ const sql = await buildDuplicateTableStructureSql({+ databaseType,+ schema: node.schema,+ sourceName: node.label,+ targetName: newName,+ });+ await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });+ toast(t("contextMenu.duplicateStructureSuccess", { name: newName }), 3000);+ await refreshTableList(node);+ } catch (e: any) {+ toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);+ }+}++async function confirmPasteTable() {+ const entries = pasteTableEntries.value.filter((entry) => entry.targetName.trim());+ if (entries.length === 0) return;+ const mode = pasteTableMode.value;+ const copyData = pasteTableModeCopiesData(mode) && pasteTableDataCopySupported.value;+ showPasteDialog.value = false;+ let successCount = 0;+ let failCount = 0;+ const refreshedConnections = new Set<string>();+ for (const entry of entries) {+ const targetName = entry.targetName.trim();+ try {+ await connectionStore.ensureConnected(entry.connectionId);+ const databaseType = entry.connectionId ? effectiveDatabaseTypeForConnection(connectionStore.getConfig(entry.connectionId)) : undefined;+ if (mode === "structure-and-data" || mode === "structure-only") {+ const structureSql = await buildDuplicateTableStructureSql({+ databaseType,+ schema: entry.schema,+ sourceName: entry.sourceName,+ targetName,+ });+ await executeTreeNodeSqlWithProductionGuard(entry, structureSql, { database: entry.database, schema: entry.schema });+ }+ if (copyData) {+ const sourceColumns = await api.getColumns(entry.connectionId, entry.database, entry.schema || "", entry.sourceName);+ const dataCopyColumnOptions = tableDataCopyColumnOptions(databaseType, sourceColumns);+ if (dataCopyColumnOptions.columns.length === 0) {+ throw new Error("No writable columns available for table data copy.");+ }+ const dataSql = await buildCopyTableDataSql({+ databaseType,+ schema: entry.schema,+ sourceName: entry.sourceName,+ targetName,+ ...dataCopyColumnOptions,+ });+ await executeTreeNodeSqlWithProductionGuard(entry, dataSql, { database: entry.database, schema: entry.schema });+ }+ successCount++;+ const refreshKey = `${entry.connectionId}:${entry.database}:${entry.schema || ""}`;+ if (!refreshedConnections.has(refreshKey)) {+ refreshedConnections.add(refreshKey);+ await connectionStore.refreshObjectListTreeNode(entry.connectionId, entry.database, entry.schema);+ }+ } catch (e: any) {+ failCount++;+ console.error(`Failed to paste table "${entry.sourceName}" -> "${targetName}":`, e);+ }+ }+ if (failCount === 0) {+ toast(t("contextMenu.batchPasteSuccess", { count: successCount }), 3000);+ } else {+ toast(t("contextMenu.batchPastePartialFail", { success: successCount, failed: failCount }), 5000);+ }+}++function copyTableToClipboard() {+ const node = activeNode.value;+ if (node.type !== "table" || !node.connectionId || !node.database) return;+ connectionStore.treeClipboard = {+ kind: "table-copy",+ tables: [+ {+ connectionId: node.connectionId,+ database: node.database,+ schema: node.schema,+ tableName: node.label,+ },+ ],+ };+ toast(t("contextMenu.pasteTableClipboardUpdated"), 2000);+}++function openPasteTableDialog() {+ const clipboard = connectionStore.treeClipboard;+ if (clipboard?.kind !== "table-copy" || !canPasteTreeClipboardToCurrentNode()) {+ toast(t("contextMenu.noTableToPaste"), 2000);+ return;+ }+ pasteTableMode.value = defaultPasteTableMode(currentDatabaseType());+ pasteTableEntries.value = clipboard.tables.map((entry) => ({+ sourceName: entry.tableName,+ targetName: `${entry.tableName}_copy`,+ connectionId: entry.connectionId,+ database: entry.database,+ schema: entry.schema,+ }));+ showPasteDialog.value = true;+}++function createTable() {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ queryStore.openTableStructure(node.connectionId, node.database, node.schema, "");+}++function createView() {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ connectionStore.activeConnectionId = node.connectionId;+ const viewName = "new_view";+ const effectiveDbType = effectiveDatabaseTypeForConnection(connectionStore.getConfig(node.connectionId));+ const viewSqlName = effectiveDbType === "informix" || !node.schema ? viewName : `${node.schema}.${viewName}`;+ const tabId = queryStore.createTab(node.connectionId, node.database, t("contextMenu.createView"), "query", node.schema);+ queryStore.updateSql(tabId, `CREATE VIEW ${viewSqlName} AS\nSELECT\n *\nFROM table_name;\n`);+ queryStore.setObjectSource(tabId, {+ schema: node.schema,+ name: viewName,+ objectType: "VIEW",+ });+}++const canExpand = computed(() =>+ canTreeNodeShowExpander({+ type: activeNode.value.type,+ childCount: activeNode.value.children?.length ?? 0,+ }),+);++const canPin = computed(() => canTreeNodePin(activeNode.value.type));++const canOpenSqlFileExecution = computed(() => {+ return supportsSqlFileExecution(rawDatabaseType());+});++const canExportAllDatabases = computed(() => {+ if (activeNode.value.type !== "connection" || !activeNode.value.connectionId) return false;+ const dbType = connectionStore.getConfig(activeNode.value.connectionId)?.db_type;+ return !["redis", "mongodb", "elasticsearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "nacos"].includes(dbType || "");+});++const canOpenDiagram = computed(() => {+ return !!activeNode.value.database && supportsSchemaDiagram(currentDatabaseType());+});++const canOpenDatabaseSearch = computed(() => {+ return !!activeNode.value.database && supportsDatabaseSearch(currentDatabaseType());+});++const canOpenObjectBrowser = computed(() => {+ return supportsObjectBrowserTreeNode(rawDatabaseType(), activeNode.value.type);+});++const canOpenTableImport = computed(() => {+ const node = activeNode.value;+ const supportedNode = node.type === "table" || ((node.type === "database" || node.type === "schema" || node.type === "group-tables") && canCreateTable.value);+ return supportedNode && !isSqlServerLinkedNode(node) && !!node.connectionId && !!node.database && supportsTableImport(currentDatabaseType());+});++const canOpenStructureEditor = computed(() => {+ const editableNode = activeNode.value.type === "table" || ((activeNode.value.type === "column" || activeNode.value.type === "index") && !!activeNode.value.tableName);+ return editableNode && !isSqlServerLinkedNode(activeNode.value) && !!activeNode.value.connectionId && !!activeNode.value.database && supportsTableStructureEditing(currentTableStructureDatabaseType());+});++const canOpenFieldLineage = computed(() => {+ return activeNode.value.type === "column" && !!activeNode.value.database && !!activeNode.value.tableName && supportsFieldLineage(currentDatabaseType());+});++const hasTypeMenu = computed(() => {+ const t = activeNode.value.type;+ return t === "connection" || t === "database" || t === "schema" || t === "table" || t === "view" || t === "column" || t === "procedure" || t === "function" || t === "package" || t === "package-body" || isGroupLabel(activeNode.value);+});++const isSelected = computed(() => connectionStore.selectedTreeNodeId === activeNode.value.id);++const isMultiSelected = computed(() => connectionStore.selectedTreeNodeIdsSet.has(activeNode.value.id));++const dangerDialogRoutes: Array<{ flag: { value: boolean }; createRequest: () => SidebarDangerDialogRequest }> = [];++let stopDangerDialogRouting: (() => void) | null = null;++function routeDangerDialog(flag: { value: boolean }, createRequest: () => SidebarDangerDialogRequest) {+ dangerDialogRoutes.push({ flag, createRequest });+}++function ensureDangerDialogRouting() {+ if (stopDangerDialogRouting) return;+ stopDangerDialogRouting = watch(+ dangerDialogRoutes.map((route) => route.flag),+ (openFlags) => {+ if (sidebarTreeDialogOwner.value !== treeItemDialogOwner) return;+ openFlags.forEach((open, index) => {+ if (!open) return;+ const route = dangerDialogRoutes[index];+ route.flag.value = false;+ emit("open-danger-dialog", route.createRequest());+ });+ },+ );+}++function dangerRequest(request: Omit<SidebarDangerDialogRequest, "target">): SidebarDangerDialogRequest {+ const target = createSidebarActionTarget(activeNode.value);+ const routedRequest = request as SidebarDangerDialogRequest;+ const confirm = request.confirm;+ routedRequest.confirm = async () => {+ activateActionTarget(target);+ await confirm();+ };+ if (request.option?.onChange) {+ const onChange = request.option.onChange;+ request.option.onChange = async (checked) => {+ activateActionTarget(target);+ await onChange(checked);+ };+ }+ routedRequest.target = target;+ sidebarDangerTarget.value = routedRequest.target;+ return routedRequest;+}++routeDangerDialog(showDropTableConfirm, () =>+ dangerRequest({+ title: t("contextMenu.confirmDropTableTitle"),+ message: t("contextMenu.confirmDropTableMessage", { name: activeNode.value.label }),+ get sql() {+ return dropTablePreviewSql.value;+ },+ confirmLabel: t("contextMenu.dropTable"),+ option: canDropTableCascade.value+ ? {+ checked: dropTableCascade.value,+ label: t("contextMenu.dropTableCascade"),+ hint: t("contextMenu.dropTableCascadeHint"),+ async onChange(checked) {+ dropTableCascade.value = checked;+ await refreshDropTablePreviewSql();+ },+ }+ : undefined,+ confirm: confirmDropTable,+ }),+);++routeDangerDialog(showEmptyTableConfirm, () =>+ dangerRequest({+ title: t("contextMenu.confirmEmptyTableTitle"),+ message: t("contextMenu.confirmEmptyTableMessage", { name: activeNode.value.label }),+ get sql() {+ return emptyTablePreviewSql.value;+ },+ confirmLabel: t("contextMenu.emptyTable"),+ confirm: confirmEmptyTable,+ }),+);++routeDangerDialog(showBatchEmptyConfirm, () =>+ dangerRequest({+ title: batchEmptyConfirmTitle(),+ message: batchEmptyConfirmMessage(),+ get sql() {+ return batchEmptyPreviewSql.value;+ },+ confirmLabel: batchEmptyConfirmLabel(),+ confirm: confirmBatchEmpty,+ }),+);++routeDangerDialog(showTruncateTableConfirm, () =>+ dangerRequest({+ title: t("contextMenu.confirmTruncateTableTitle"),+ message: t("contextMenu.confirmTruncateTableMessage", { name: activeNode.value.label }),+ get sql() {+ return truncateTablePreviewSql.value;+ },+ confirmLabel: t("contextMenu.truncateTable"),+ option: canTruncateTableCascade.value+ ? {+ checked: truncateTableCascade.value,+ label: t("contextMenu.truncateTableCascade"),+ hint: t("contextMenu.truncateTableCascadeHint"),+ async onChange(checked) {+ truncateTableCascade.value = checked;+ await refreshTruncateTablePreviewSql();+ },+ }+ : undefined,+ confirm: confirmTruncateTable,+ }),+);++routeDangerDialog(showDropObjectConfirm, () =>+ dangerRequest({+ title: dropObjectConfirmTitle(),+ message: dropObjectConfirmMessage(),+ get sql() {+ return dropObjectPreviewSql.value;+ },+ confirmLabel: dropObjectMenuLabel(),+ confirm: confirmDropObject,+ }),+);++routeDangerDialog(showDropTableChildObjectConfirm, () =>+ dangerRequest({+ title: dropTableChildObjectConfirmTitle(),+ message: dropTableChildObjectConfirmMessage(),+ get sql() {+ return dropTableChildObjectPreviewSql.value;+ },+ confirmLabel: dropTableChildObjectMenuLabel(),+ confirm: confirmDropTableChildObject,+ }),+);++routeDangerDialog(showBatchDropConfirm, () =>+ dangerRequest({+ title: batchDropConfirmTitle(),+ message: batchDropConfirmMessage(),+ get sql() {+ return batchDropPreviewSql.value;+ },+ confirmLabel: batchDropMenuLabel(),+ option: canBatchDropCascade.value+ ? {+ checked: batchDropCascade.value,+ label: t("contextMenu.dropTableCascade"),+ hint: t("contextMenu.dropTableCascadeHint"),+ async onChange(checked) {+ batchDropCascade.value = checked;+ await refreshBatchDropPreviewSql();+ },+ }+ : undefined,+ confirm: confirmBatchDrop,+ }),+);++routeDangerDialog(showBatchTruncateConfirm, () =>+ dangerRequest({+ title: batchTruncateConfirmTitle(),+ message: batchTruncateConfirmMessage(),+ get sql() {+ return batchTruncatePreviewSql.value;+ },+ confirmLabel: batchTruncateMenuLabel(),+ option: canBatchTruncateCascade.value+ ? {+ checked: batchTruncateCascade.value,+ label: t("contextMenu.truncateTableCascade"),+ hint: t("contextMenu.truncateTableCascadeHint"),+ async onChange(checked) {+ batchTruncateCascade.value = checked;+ await refreshBatchTruncatePreviewSql();+ },+ }+ : undefined,+ confirm: confirmBatchTruncate,+ }),+);++routeDangerDialog(showDropDatabaseConfirm, () =>+ dangerRequest({+ title: t("contextMenu.confirmDropDatabaseTitle"),+ message: t("contextMenu.confirmDropDatabaseMessage", { name: activeNode.value.label }),+ get sql() {+ return dropDatabasePreviewSql.value;+ },+ confirmLabel: t("contextMenu.dropDatabase"),+ get loading() {+ return dropDatabaseLoading.value;+ },+ closeOnConfirm: false,+ confirm: confirmDropDatabase,+ }),+);++routeDangerDialog(showDropMongoCollectionConfirm, () =>+ dangerRequest({+ title: t("contextMenu.confirmDropCollectionTitle"),+ message: t("contextMenu.confirmDropCollectionMessage", { name: activeNode.value.label }),+ confirmLabel: t("contextMenu.dropCollection"),+ get loading() {+ return dropMongoCollectionLoading.value;+ },+ closeOnConfirm: false,+ confirm: confirmDropMongoCollection,+ }),+);++routeDangerDialog(showDropMongoIndexConfirm, () =>+ dangerRequest({+ title: t("contextMenu.confirmDropIndexTitle"),+ message: t("contextMenu.confirmDropMongoIndexMessage", { name: mongoIndexNameForNode(activeNode.value), collection: activeNode.value.tableName || "" }),+ details: mongoIndexDropPreview(activeNode.value, mongoIndexNameForNode(activeNode.value)),+ confirmLabel: t("contextMenu.dropIndex"),+ get loading() {+ return dropMongoIndexLoading.value;+ },+ closeOnConfirm: false,+ confirm: confirmDropMongoIndex,+ }),+);++routeDangerDialog(showDropAllMongoIndexesConfirm, () =>+ dangerRequest({+ title: t("contextMenu.dropAllIndexes"),+ message: t("contextMenu.confirmDropMongoAllIndexesMessage", { name: activeNode.value.label }),+ detailsText: t("contextMenu.confirmDropMongoAllIndexesDetails"),+ sql: mongoDropAllIndexesPreview(activeNode.value),+ confirmLabel: t("contextMenu.dropAllIndexes"),+ get loading() {+ return dropAllMongoIndexesLoading.value;+ },+ closeOnConfirm: false,+ confirm: confirmDropAllMongoIndexes,+ }),+);++routeDangerDialog(showFlushRedisDbConfirm, () =>+ dangerRequest({+ title: t("redis.flushDb"),+ message: t("redis.flushDbMessage"),+ details: t("redis.flushDbDetails", { db: activeNode.value.database }),+ confirmLabel: t("redis.flushDbConfirm"),+ confirm: confirmFlushRedisDb,+ }),+);++routeDangerDialog(showDropSchemaConfirm, () =>+ dangerRequest({+ title: t("contextMenu.confirmDropSchemaTitle"),+ message: t("contextMenu.confirmDropSchemaMessage", { name: activeNode.value.label }),+ get sql() {+ return dropSchemaPreviewSql.value;+ },+ confirmLabel: t("contextMenu.dropSchema"),+ confirm: confirmDropSchema,+ }),+);++function moveToNewGroup() {+ moveToNewGroupName.value = "";+ showMoveToNewGroupDialog.value = true;+}++function confirmMoveToNewGroup() {+ const name = moveToNewGroupName.value.trim();+ const node = sidebarFormTarget.value ?? activeNode.value;+ if (name && node.connectionId) {+ const groupId = connectionStore.createConnectionGroup(name);+ connectionStore.moveConnectionToGroup(node.connectionId, groupId);+ }+ showMoveToNewGroupDialog.value = false;+}++let treeItemDialogController: Record<string, any> | null = null;++function connectionDialogCapabilities() {+ return {+ showDeleteConfirm,+ connectionDeleteConfirmMessage,+ confirmDelete,+ connectionDeleteMenuLabel,+ showMoveToNewGroupDialog,+ moveToNewGroupName,+ confirmMoveToNewGroup,+ showDeleteGroupConfirm,+ confirmDeleteGroup,+ };+}++function objectDialogCapabilities() {+ return {+ showRenameObjectDialog,+ renameObjectName,+ renameObjectPreviewSql,+ renameObjectError,+ confirmRenameObject,+ showStructurePreviewDialog,+ structurePreviewTitle,+ isLoadingStructurePreview,+ structurePreviewError,+ structurePreviewSql,+ copyStructurePreview,+ saveStructurePreview,+ showStructureDocCopyDialog,+ structureDocCopyTitle,+ structureDocCopyText,+ selectTextareaContent,+ copyStructureDocText,+ showDuplicateDialog,+ duplicateTableName,+ confirmDuplicateStructure,+ showPasteDialog,+ pasteTableEntries,+ pasteTableMode,+ pasteTableDataCopySupported: pasteTableDataCopySupported.value,+ confirmPasteTable,+ };+}++function databaseDialogCapabilities() {+ return {+ showCreateDatabaseDialog,+ createDatabaseName,+ canSetCreateDatabaseCharset: canSetCreateDatabaseCharset.value,+ createDatabaseCharset,+ createDatabaseCharsetOptions,+ createDatabaseCharsetLoading,+ normalizeCreateDatabaseCharset,+ createDatabaseCollation,+ createDatabaseUsers,+ createDatabaseSelectedUsers,+ createDatabaseUsersLoading,+ createDatabaseUserKey,+ createDatabaseUserLabel,+ createDatabaseUserSelected,+ toggleCreateDatabaseUser,+ showCreateDatabasePreviewDialog,+ createDatabasePreviewSql,+ createDatabaseAuthorizationResults,+ createDatabaseAuthorizationApplying,+ applyCreateDatabaseAuthorizationPlan,+ createDatabaseAuthorizationStepLabel,+ createDatabaseCollationOptionsForCharset,+ createDatabaseCollationsByCharset,+ confirmCreateDatabase,+ showEditDatabasePropertiesDialog,+ updateCreateDatabaseCharset,+ canEditDatabaseCharsetCollation: canEditDatabaseCharsetCollation.value,+ updateEditDatabaseCharset,+ editDatabasePropertiesLoading,+ editDatabaseCharset,+ editDatabaseCollation,+ canEditDatabaseComment: canEditDatabaseComment.value,+ editDatabaseCommentText,+ editDatabasePropertiesPreviewSql,+ confirmEditDatabaseProperties,+ };+}++function databaseSpecificDialogCapabilities() {+ return {+ showCreateNacosNamespaceDialog,+ createNacosNamespaceId,+ createNacosNamespaceName,+ createNacosNamespaceDesc,+ createNacosNamespaceLoading,+ confirmCreateNacosNamespace,+ showEditNacosNamespaceDialog,+ editNacosNamespaceName,+ editNacosNamespaceDesc,+ editNacosNamespaceLoading,+ confirmEditNacosNamespace,+ showCreateSchemaDialog,+ createSchemaName,+ confirmCreateSchema,+ showEditSchemaCommentDialog,+ schemaCommentText,+ schemaCommentLoading,+ schemaCommentPreviewSql,+ confirmEditSchemaComment,+ };+}++function getTreeItemDialogController(): Record<string, any> {+ if (treeItemDialogController) return treeItemDialogController;+ treeItemDialogController = reactive<Record<string, any>>({+ node: createSidebarActionTarget(activeNode.value),+ t,+ highlight,+ ...connectionDialogCapabilities(),+ ...objectDialogCapabilities(),+ ...databaseDialogCapabilities(),+ ...databaseSpecificDialogCapabilities(),+ });+ return treeItemDialogController;+}++const availableGroups = computed(() => connectionStore.sidebarLayout.groups);++const currentGroupId = computed(() => {+ if (activeNode.value.type !== "connection" || !activeNode.value.connectionId) return null;+ const find = (entries: typeof connectionStore.sidebarLayout.order): string | null => {+ for (const entry of entries) {+ if (entry.type !== "group") continue;+ if ((entry.children ?? entry.connectionIds?.map((id) => ({ type: "connection" as const, id })) ?? []).some((child) => child.type === "connection" && child.id === activeNode.value.connectionId)) {+ return entry.id;+ }+ const found = find(entry.children ?? []);+ if (found) return found;+ }+ return null;+ };+ return find(connectionStore.sidebarLayout.order);+});++onBeforeUnmount(() => {+ stopDangerDialogRouting?.();+});++const shortcutCopyName = computed(() => settingsStore.editorSettings.shortcuts.copySidebarSelection);++const shortcutOpenDataInNewTab = computed(() => settingsStore.editorSettings.shortcuts.openDataInNewTab);++const shortcutEditConnection = computed(() => settingsStore.editorSettings.shortcuts.editSidebarConnection);++const shortcutRename = "F2";++const shortcutRefresh = "F5";++const shortcutDelete = "Delete";++function exportDataSubmenu(): ContextMenuItem {+ return {+ label: t("contextMenu.exportData"),+ icon: Upload,+ children: [+ { label: "CSV", action: () => exportData("csv") },+ { label: "JSON", action: () => exportData("json") },+ { label: "SQL INSERT", action: () => exportData("sql") },+ { label: "XLSX", action: () => exportDataXlsx() },+ ],+ };+}++function copyStructureAsSubmenu(): ContextMenuItem {+ return {+ label: t("contextMenu.copyStructureAs"),+ icon: Clipboard,+ children: [+ { label: t("contextMenu.copyStructureAsTsv"), action: () => copyStructureAs("tsv") },+ { label: t("contextMenu.copyStructureAsMarkdown"), action: () => copyStructureAs("markdown") },+ ],+ };+}++function moreActionsSubmenu(children: ContextMenuItem[]): ContextMenuItem {+ return {+ label: t("common.more"),+ icon: ListTree,+ children,+ };+}++function savedSqlHistoryScopeForNode(node: TreeNode): SavedSqlHistoryScope | null {+ if (!node.connectionId) return null;+ if (node.type === "connection") {+ return { connectionId: node.connectionId };+ }+ if ((node.type === "database" || node.type === "schema") && hasTreeNodeDatabaseContext(node)) {+ return {+ connectionId: node.connectionId,+ database: node.database,+ schema: node.type === "schema" ? node.schema : undefined,+ };+ }+ if ((node.type === "table" || node.type === "view") && hasTreeNodeDatabaseContext(node)) {+ return {+ connectionId: node.connectionId,+ database: node.database,+ schema: node.schema,+ tableName: node.label,+ };+ }+ return null;+}++async function openSavedSqlHistoryFile(fileId: string) {+ const file = await savedSqlStore.ensureFileContent(fileId);+ if (!file) return;+ queryStore.openSavedSql(file);+ connectionStore.activeConnectionId = file.connectionId;+ void savedSqlStore.recordFileUsage(file.id);+}++function savedSqlHistorySubmenu(): ContextMenuItem | null {+ const scope = savedSqlHistoryScopeForNode(activeNode.value);+ if (!scope) return null;+ const files = rankSavedSqlHistory(savedSqlStore.allFiles, { ...scope, limit: 10 });+ return {+ label: t("contextMenu.sqlHistory"),+ icon: ScrollText,+ children:+ files.length > 0+ ? files.map((file) => ({+ label: file.name,+ action: () => openSavedSqlHistoryFile(file.id),+ icon: FileCode,+ }))+ : [+ {+ label: t("contextMenu.noSqlHistory"),+ disabled: true,+ },+ ],+ };+}+interface SidebarMenuFactoryContext {+ node: TreeNode;+ items: ContextMenuItem[];+ deleteMenuLabel: (singleLabel: string) => string;+ deleteMenuAction: (singleAction: () => void) => () => void;+ truncateMenuLabel: (singleLabel: string) => string;+ truncateMenuAction: (singleAction: () => void) => () => void;+ emptyMenuLabel: (singleLabel: string) => string;+ emptyMenuAction: (singleAction: () => void) => () => void;+}++type SidebarMenuFactory = (context: SidebarMenuFactoryContext) => boolean;++function buildConnectionSidebarMenu(context: SidebarMenuFactoryContext): boolean {+ const { node, items } = context;+ // 2. Connection+ if (node.type === "connection") {+ if (isConnecting.value) {+ items.push({ label: t("connection.cancelConnecting"), action: cancelConnectionAttempt, icon: X });+ } else if (!isConnected.value) {+ items.push({ label: t("contextMenu.openConnection"), action: toggle, icon: Plug });+ } else {+ items.push({ label: t("contextMenu.closeConnection"), action: disconnectConnection, icon: Unplug });+ }+ items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });+ if (currentDatabaseType() === "redis") {+ items.push({ label: t("contextMenu.instanceInfo"), action: openRedisInstanceInfo, icon: Info });+ }+ const sqlHistoryMenu = savedSqlHistorySubmenu();+ if (sqlHistoryMenu) items.push(sqlHistoryMenu);+ if (node.connectionId && connectionSupportsDatabaseUserAdmin(connectionStore.getConfig(node.connectionId))) {+ items.push({ label: t("contextMenu.userAdmin"), action: openUserAdmin, icon: UsersRound });+ }+ if (node.connectionId && connectionSupportsProcessList(connectionStore.getConfig(node.connectionId))) {+ items.push({ label: t("contextMenu.processList"), action: openProcessList, icon: Activity });+ }+ if (node.connectionId && (connectionSupportsServerDashboard(connectionStore.getConfig(node.connectionId)) || connectionSupportsPgServerDashboard(connectionStore.getConfig(node.connectionId)))) {+ items.push({ label: t("contextMenu.serverDashboard"), action: openServerDashboard, icon: Gauge });+ }+ if (currentDatabaseType() === "dameng") {+ items.push({ label: t("contextMenu.damengJobAdmin"), action: openDamengJobAdmin, icon: CalendarClock });+ }+ if (canCopyFinalProxyPort.value) {+ items.push({ label: t("contextMenu.copyFinalProxyPort"), action: copyFinalProxyPort, icon: Network });+ }+ if (canOpenSqlFileExecution.value) {+ items.push({ label: t("sqlFile.title"), action: openSqlFileExecution, icon: FileCode });+ }+ if (canExportAllDatabases.value) {+ items.push({ label: t("contextMenu.exportAllDatabases"), action: openAllDatabasesExport, icon: Upload });+ if (isTauriRuntime()) {+ items.push({ label: t("databaseBackup.title"), action: openScheduledBackups, icon: CalendarClock });+ }+ }+ if (canCreateDatabase.value) {+ items.push({+ label: connectionNamespaceCreationLabel(),+ action: openConnectionNamespaceCreation,+ icon: Plus,+ });+ }+ if (canCreateNacosNamespace.value) {+ items.push({+ label: t("nacos.createNamespace"),+ action: openCreateNacosNamespaceDialog,+ icon: FolderPlus,+ });+ }+ items.push({ label: "", separator: true });+ if (availableGroups.value.length > 0 || currentGroupId.value) {+ const groupChildren: ContextMenuItem[] = availableGroups.value.map((group: { id: string; name: string }) => ({+ label: group.name,+ action: () => moveToGroup(group.id),+ icon: FolderOpen,+ disabled: group.id === currentGroupId.value,+ }));+ if (currentGroupId.value) {+ groupChildren.push({ label: "", separator: true });+ groupChildren.push({ label: t("connectionGroup.ungrouped"), action: () => moveToGroup(null) });+ }+ groupChildren.push({ label: "", separator: true });+ groupChildren.push({ label: t("connectionGroup.newGroup"), action: moveToNewGroup, icon: FolderPlus });+ items.push({ label: t("connectionGroup.moveToGroup"), icon: FolderInput, children: groupChildren });+ } else {+ items.push({ label: t("connectionGroup.moveToNewGroup"), action: moveToNewGroup, icon: FolderPlus });+ }+ items.push({+ label: t("contextMenu.refreshChildren"),+ action: refresh,+ icon: RefreshCw,+ shortcut: shortcutRefresh,+ });+ if (canConfigureVisibleDatabases.value) {+ items.push({+ label: t("contextMenu.configureVisibleObjects"),+ action: openVisibleDatabasesDialog,+ icon: ListFilter,+ });+ } else if (canConfigureVisibleSchemas.value) {+ items.push({+ label: t("visibleSchemas.title"),+ action: openVisibleSchemasDialog,+ icon: ListFilter,+ });+ }+ if (canConfigureVisibleSchemas.value) {+ items.push({+ label: t("visibleSchemas.title"),+ action: openVisibleSchemasDialog,+ icon: ListFilter,+ });+ }+ items.push({ label: t("contextMenu.editConnection"), action: editConnection, icon: Pencil, shortcut: shortcutEditConnection.value });+ if (revealConnectionFilePath.value) {+ items.push({+ label: t("contextMenu.revealDatabaseFile"),+ action: revealDatabaseFile,+ icon: FolderOpen,+ });+ }+ if (canBackupSqliteDatabase.value) {+ items.push({+ label: t("contextMenu.backupSqliteDatabase"),+ action: backupSqliteDatabase,+ icon: HardDriveDownload,+ });+ }+ items.push({ label: connectionDuplicateMenuLabel(), action: duplicateConnection, icon: CopyPlus });+ items.push({ label: "", separator: true });+ items.push({+ label: connectionDeleteMenuLabel(),+ action: deleteConnection,+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ return true;+ }++ // 3. Connection Group+ if (node.type === "connection-group") {+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ items.push({ label: "", separator: true });+ items.push({ label: t("toolbar.newConnection"), action: newConnectionInGroup, icon: Plus });+ items.push({ label: t("connectionGroup.newGroup"), action: newSubgroup, icon: FolderPlus });+ items.push({ label: "", separator: true });+ items.push({+ label: t("connectionGroup.renameGroup"),+ action: startRenameGroup,+ icon: Pencil,+ shortcut: shortcutRename,+ });+ items.push({ label: "", separator: true });+ items.push({+ label: t("connectionGroup.deleteGroup"),+ action: deleteConnectionGroup,+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ return true;+ }+ return false;+}++function buildDatabaseSidebarMenu(context: SidebarMenuFactoryContext): boolean {+ const { node, items } = context;+ // 4. Database / Schema+ if (node.type === "database" || node.type === "schema") {+ if (canCloseDatabaseConnection.value) {+ items.push({ label: t("contextMenu.closeDatabaseConnection"), action: closeDatabaseConnection, icon: Unplug });+ items.push({ label: "", separator: true });+ }+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ items.push({ label: "", separator: true });+ if (canOpenObjectBrowser.value) {+ items.push({ label: t("contextMenu.openObjectBrowser"), action: openObjectBrowser, icon: TableProperties });+ }+ items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });+ const sqlHistoryMenu = savedSqlHistorySubmenu();+ if (sqlHistoryMenu) items.push(sqlHistoryMenu);+ if (node.type === "database" && currentDatabaseType() !== "cloudflare-d1") {+ if (!isNodeDefaultDatabase.value) {+ items.push({ label: t("contextMenu.setDefaultDatabase"), action: setNodeAsDefaultDatabase, icon: Database });+ } else {+ items.push({ label: t("contextMenu.clearDefaultDatabase"), action: clearNodeDefaultDatabase, icon: Database });+ }+ }+ if (canEditDatabaseProperties.value) {+ items.push({ label: t("contextMenu.editDatabaseProperties"), action: openEditDatabasePropertiesDialog, icon: SquarePen });+ }+ if (canCreateTable.value) {+ items.push({ label: t("contextMenu.createTable"), action: createTable, icon: Plus });+ }+ if (canOpenTableImport.value) {+ items.push({ label: t("contextMenu.importData"), action: openTableImport, icon: Download });+ }+ if (canCreateSchema.value) {+ items.push({ label: t("contextMenu.createSchema"), action: openCreateSchemaDialog, icon: Plus });+ }+ if (canEditSchemaComment.value) {+ items.push({ label: t("contextMenu.editSchemaComment"), action: openEditSchemaCommentDialog, icon: SquarePen });+ }+ if (canOpenSqlFileExecution.value) {+ items.push({ label: t("sqlFile.title"), action: openSqlFileExecution, icon: FileCode });+ }+ if (canOpenDiagram.value) {+ items.push({ label: t("diagram.open"), action: openDiagram, icon: Network });+ }+ if (canOpenDatabaseSearch.value) {+ items.push({ label: t("databaseSearch.open"), action: openDatabaseSearch, icon: Search });+ }+ items.push({+ label: t("contextMenu.refreshChildren"),+ action: refresh,+ icon: RefreshCw,+ shortcut: shortcutRefresh,+ });+ if (canConfigureVisibleSchemas.value) {+ items.push({+ label: t("visibleSchemas.title"),+ action: openVisibleSchemasDialog,+ icon: ListFilter,+ });+ }+ items.push({ label: "", separator: true });+ items.push({ label: t("transfer.dataTransfer"), action: openTransfer, icon: ArrowRightLeft });+ items.push({ label: t("diff.title"), action: openSchemaDiff, icon: ArrowRightLeft });+ items.push({ label: t("dataCompare.title"), action: openDataCompare, icon: ArrowRightLeft });+ items.push({ label: t("contextMenu.exportDatabase"), action: openDatabaseExport, icon: Upload });+ const destructiveActions: ContextMenuItem[] = [];+ if (canDropDatabase.value) {+ destructiveActions.push({+ label: t("contextMenu.dropDatabase"),+ action: dropDatabase,+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ }+ if (destructiveActions.length > 0) {+ items.push({ label: "", separator: true });+ items.push(moreActionsSubmenu(destructiveActions));+ }+ if (canDropSchema.value) {+ items.push({ label: "", separator: true });+ }+ if (canDropSchema.value) {+ items.push({+ label: t("contextMenu.dropSchema"),+ action: dropSchema,+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ }+ return true;+ }+ return false;+}++function buildSpecialSidebarMenu(context: SidebarMenuFactoryContext): boolean {+ const { node, items } = context;+ // 5. Redis DB / Mongo DB+ if (node.type === "etcd-root" || node.type === "zookeeper-root") {+ items.push({ label: t("contextMenu.openConnection"), action: toggle, icon: Database });+ return true;+ }++ if (node.type === "user-admin") {+ items.push({ label: t("contextMenu.openUserAdmin"), action: openUserAdmin, icon: UsersRound });+ return true;+ }++ if (node.type === "dameng-job-admin") {+ items.push({ label: t("contextMenu.openDamengJobAdmin"), action: openDamengJobAdmin, icon: CalendarClock });+ return true;+ }++ if (node.type === "redis-db" || node.type === "mongo-db") {+ items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });+ if (!isNodeDefaultDatabase.value) {+ items.push({ label: t("contextMenu.setDefaultDatabase"), action: setNodeAsDefaultDatabase, icon: Database });+ } else {+ items.push({ label: t("contextMenu.clearDefaultDatabase"), action: clearNodeDefaultDatabase, icon: Database });+ }+ if (node.type === "mongo-db") {+ items.push({ label: "", separator: true });+ items.push({ label: t("transfer.dataTransfer"), action: openTransfer, icon: ArrowRightLeft });+ }+ if (node.type === "redis-db") {+ items.push({ label: "", separator: true });+ items.push({ label: t("redis.flushDb"), action: flushRedisDb, icon: Eraser, variant: "destructive" as const });+ }+ if (canDropMongoDatabase.value) {+ items.push({ label: "", separator: true });+ items.push(+ moreActionsSubmenu([+ {+ label: t("contextMenu.dropDatabase"),+ action: dropDatabase,+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ },+ ]),+ );+ }+ return true;+ }++ if (node.type === "nacos-namespace") {+ items.push({ label: t("contextMenu.openConnection"), action: toggle, icon: FolderOpen });+ if (canEditNacosNamespace.value) {+ items.push({ label: t("nacos.editNamespace"), action: openEditNacosNamespaceDialog, icon: Pencil });+ }+ items.push({+ label: t("contextMenu.refreshChildren"),+ action: refresh,+ icon: RefreshCw,+ shortcut: shortcutRefresh,+ });+ items.push({ label: "", separator: true });+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ return true;+ }++ if (node.type === "mongo-collection") {+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ items.push({ label: "", separator: true });+ items.push({ label: t("contextMenu.viewData"), action: toggle, icon: TableProperties });+ items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });+ if (canDropAllMongoIndexes.value || canDropMongoCollection.value) {+ items.push({ label: "", separator: true });+ if (canDropAllMongoIndexes.value) {+ items.push({ label: t("contextMenu.dropAllIndexes"), action: dropAllMongoIndexes, icon: Trash2, variant: "destructive" as const });+ }+ if (canDropMongoCollection.value) {+ items.push({ label: t("contextMenu.dropCollection"), action: dropMongoCollection, icon: Trash2, shortcut: shortcutDelete, variant: "destructive" as const });+ }+ }+ return true;+ }++ if (node.type === "elasticsearch-index" || node.type === "vector-collection") {+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ items.push({ label: "", separator: true });+ items.push({ label: t("contextMenu.viewData"), action: toggle, icon: TableProperties });+ items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });+ return true;+ }++ // 8.5 Extension+ if (node.type === "extension") {+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ return true;+ }+ return false;+}++function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {+ const { node, items, deleteMenuLabel, deleteMenuAction, truncateMenuLabel, truncateMenuAction, emptyMenuLabel, emptyMenuAction } = context;+ // 6. Table / View / Materialized View+ if (node.type === "table" || node.type === "view" || node.type === "materialized_view") {+ const destructiveActions: ContextMenuItem[] = [];+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ items.push({ label: "", separator: true });+ items.push({ label: t("contextMenu.viewData"), action: openDataImmediately, icon: TableProperties });+ items.push({+ label: t("contextMenu.openInNewDataTab"),+ action: openDataInNewTabImmediately,+ icon: CopyPlus,+ shortcut: shortcutOpenDataInNewTab.value,+ });+ if (node.type === "table") {+ items.push({+ label: t("contextMenu.viewDdl"),+ action: () => emit("open-ddl", node),+ icon: FileCode,+ });+ }+ if (node.type === "view" || node.type === "materialized_view") {+ items.push({ label: t("contextMenu.editView"), action: () => openObjectSourceDialog(true), icon: Pencil });+ items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });+ items.push({+ label: t("contextMenu.viewDdl"),+ action: () => emit("open-ddl", node),+ icon: FileCode,+ });+ }+ if (canOpenStructureEditor.value) {+ items.push({ label: t("contextMenu.editStructure"), action: openStructureEditor, icon: PencilRuler });+ }+ if (canRenameObject.value) {+ items.push({+ label: t("contextMenu.renameObject"),+ action: openRenameObjectDialog,+ icon: Pencil,+ shortcut: shortcutRename,+ });+ }+ if (node.type === "view" || node.type === "materialized_view") {+ destructiveActions.push({+ label: deleteMenuLabel(t("contextMenu.dropView")),+ action: deleteMenuAction(requestDropObject),+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ }+ items.push({+ label: t("contextMenu.generateSql"),+ icon: FilePlus,+ children: isTableNotView.value+ ? [+ { label: "SELECT", action: newSelectTemplate, icon: TerminalSquare },+ { label: "INSERT", action: newInsertTemplate, icon: FilePlus },+ { label: "UPDATE", action: newUpdateTemplate, icon: SquarePen },+ { label: "DELETE", action: newDeleteTemplate, icon: ListX },+ { label: "DDL", action: generateDdlTemplate, icon: FileCode },+ ]+ : [+ { label: "SELECT", action: newSelectTemplate, icon: TerminalSquare },+ { label: "DDL", action: generateDdlTemplate, icon: FileCode },+ ],+ });+ const sqlHistoryMenu = savedSqlHistorySubmenu();+ if (sqlHistoryMenu) items.push(sqlHistoryMenu);+ if (canOpenDiagram.value) {+ items.push({ label: t("diagram.open"), action: openDiagram, icon: Network });+ }+ if (canOpenTableImport.value) {+ items.push({ label: t("contextMenu.importData"), action: openTableImport, icon: Download });+ }+ if (isTableNotView.value) {+ items.push({ label: t("dataCompare.title"), action: openDataCompare, icon: ArrowRightLeft });+ }+ items.push({ label: "", separator: true });+ items.push(exportDataSubmenu());+ items.push({ label: t("contextMenu.exportDatabase"), action: openDatabaseExport, icon: Upload });+ items.push({ label: t("contextMenu.exportStructure"), action: exportStructure, icon: FileCode });+ items.push(copyStructureAsSubmenu());+ if (isTableNotView.value) {+ items.push({ label: "", separator: true });+ items.push({ label: t("contextMenu.duplicateStructure"), action: duplicateStructure, icon: CopyPlus });+ items.push({ label: t("contextMenu.copyTable"), action: copyTableToClipboard, icon: Copy });+ if (supportsTruncate.value) {+ destructiveActions.push({+ label: truncateMenuLabel(t("contextMenu.truncateTable")),+ action: truncateMenuAction(truncateTable),+ icon: Scissors,+ variant: "destructive" as const,+ });+ }+ destructiveActions.push({+ label: emptyMenuLabel(t("contextMenu.emptyTable")),+ action: emptyMenuAction(emptyTable),+ icon: Eraser,+ variant: "destructive" as const,+ });+ destructiveActions.push({+ label: deleteMenuLabel(t("contextMenu.dropTable")),+ action: deleteMenuAction(dropTable),+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ }+ if (destructiveActions.length > 0) {+ items.push({ label: "", separator: true });+ items.push(moreActionsSubmenu(destructiveActions));+ }+ items.push({ label: "", separator: true });+ items.push({+ label: t("contextMenu.refreshChildren"),+ action: refresh,+ icon: RefreshCw,+ shortcut: shortcutRefresh,+ });+ return true;+ }++ // 7. Column+ if (node.type === "column") {+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ const columnActions: ContextMenuItem[] = [];+ if (canOpenStructureEditor.value) {+ columnActions.push({ label: t("contextMenu.editColumn"), action: openStructureEditor, icon: PencilRuler });+ }+ if (canOpenFieldLineage.value) {+ columnActions.push({ label: t("lineage.open"), action: openFieldLineage, icon: Network });+ }+ if (columnActions.length > 0) {+ items.push({ label: "", separator: true });+ items.push(...columnActions);+ }+ if (canDropTableChildObject.value) {+ items.push({ label: "", separator: true });+ items.push({+ label: deleteMenuLabel(dropTableChildObjectMenuLabel()),+ action: deleteMenuAction(requestDropTableChildObject),+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ }+ return true;+ }++ if (node.type === "index" || node.type === "fkey" || node.type === "trigger") {+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ if (node.type === "index" && canOpenStructureEditor.value) {+ items.push({ label: "", separator: true });+ items.push({ label: t("contextMenu.editIndex"), action: openStructureEditor, icon: PencilRuler });+ }+ if (node.type === "index" && canDropMongoIndex.value) {+ items.push({ label: "", separator: true });+ items.push({+ label: deleteMenuLabel(t("contextMenu.dropIndex")),+ action: deleteMenuAction(dropMongoIndex),+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ } else if (canDropTableChildObject.value) {+ items.push({ label: "", separator: true });+ items.push({+ label: deleteMenuLabel(dropTableChildObjectMenuLabel()),+ action: deleteMenuAction(requestDropTableChildObject),+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ }+ return true;+ }++ // 8. Procedure / Function / Package+ if (node.type === "procedure" || node.type === "function") {+ if (node.type === "procedure") {+ items.push({ label: t("contextMenu.executeProcedure"), action: openProcedureExecution, icon: Play });+ }+ items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });+ if (canRenameObject.value) {+ items.push({+ label: t("contextMenu.renameObject"),+ action: openRenameObjectDialog,+ icon: Pencil,+ shortcut: shortcutRename,+ });+ }+ items.push({ label: "", separator: true });+ items.push({+ label: deleteMenuLabel(node.type === "procedure" ? t("contextMenu.dropProcedure") : t("contextMenu.dropFunction")),+ action: deleteMenuAction(requestDropObject),+ icon: Trash2,+ shortcut: shortcutDelete,+ variant: "destructive" as const,+ });+ return true;+ }++ if (node.type === "sequence") {+ items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });+ items.push({ label: "", separator: true });+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ return true;+ }++ if (node.type === "package" || node.type === "package-body") {+ items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });+ items.push({ label: "", separator: true });+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ return true;+ }+ return false;+}++function buildObjectGroupSidebarMenu(context: SidebarMenuFactoryContext): boolean {+ const { node, items } = context;+ // 9. Group Labels (group-columns, group-tables, etc.)+ if (isGroupLabel(node)) {+ const hasGroupCreateAction = (node.type === "group-tables" && canCreateTable.value) || (node.type === "group-views" && !!node.connectionId && !!node.database);+ const canLoadAllObjectGroup = node.type === "group-tables" || node.type === "group-views" || node.type === "group-materialized-views";+ if (node.type === "group-tables" && canCreateTable.value) {+ items.push({ label: t("contextMenu.createTable"), action: createTable, icon: Plus });+ if (canOpenTableImport.value) {+ items.push({ label: t("contextMenu.importData"), action: openTableImport, icon: Upload });+ }+ if (canPasteTreeClipboardToCurrentNode()) {+ items.push({ label: t("contextMenu.pasteTable"), action: openPasteTableDialog, icon: Clipboard });+ }+ }+ if (node.type === "group-views" && node.connectionId && node.database) {+ items.push({ label: t("contextMenu.createView"), action: createView, icon: Plus });+ }+ if (hasGroupCreateAction) {+ items.push({ label: "", separator: true });+ }+ if (node.type === "group-extensions") {+ items.push({+ label: t("contextMenu.manageExtension"),+ action: () => openInstallExtensionDialog(node),+ icon: Plus,+ });+ items.push({ label: "", separator: true });+ }+ if (canLoadAllObjectGroup) {+ items.push({+ label: t("contextMenu.expandAll"),+ action: loadAllObjectGroupChildren,+ icon: ChevronsDown,+ disabled: node.isLoading,+ });+ }+ if (node.type !== "group-partitions") {+ items.push({+ label: t("contextMenu.refreshChildren"),+ action: refresh,+ icon: RefreshCw,+ shortcut: shortcutRefresh,+ });+ }+ return true;+ }+ return false;+}++const sidebarMenuFactories: readonly SidebarMenuFactory[] = [buildConnectionSidebarMenu, buildDatabaseSidebarMenu, buildSpecialSidebarMenu, buildObjectSidebarMenu, buildObjectGroupSidebarMenu];++function treeItemMenuItems(): ContextMenuItem[] {+ const node = activeNode.value;+ const items: ContextMenuItem[] = [];+ const batchDropCount = selectedBatchDropTargets().length;+ const batchEmptyCount = selectedBatchEmptyTargets().length;+ const batchTruncateCount = selectedBatchTruncateTargets().length;+ const deleteMenuLabel = (singleLabel: string) => (batchDropCount > 1 ? batchDropMenuLabel() : singleLabel);+ const deleteMenuAction = (singleAction: () => void) => (batchDropCount > 1 ? requestBatchDrop : singleAction);+ const truncateMenuLabel = (singleLabel: string) => (batchTruncateCount > 1 ? batchTruncateMenuLabel() : singleLabel);+ const truncateMenuAction = (singleAction: () => void) => (batchTruncateCount > 1 ? requestBatchTruncate : singleAction);+ const emptyMenuLabel = (singleLabel: string) => (batchEmptyCount > 1 ? batchEmptyMenuLabel() : singleLabel);+ const emptyMenuAction = (singleAction: () => void) => (batchEmptyCount > 1 ? requestBatchEmpty : singleAction);++ // 1. Pin toggle+ if (canPin.value) {+ items.push({+ label: isPinned.value ? t("contextMenu.unpin") : t("contextMenu.pin"),+ action: togglePin,+ icon: Pin,+ });+ if (hasTypeMenu.value) items.push({ label: "", separator: true });+ }+ const factoryContext: SidebarMenuFactoryContext = {+ node,+ items,+ deleteMenuLabel,+ deleteMenuAction,+ truncateMenuLabel,+ truncateMenuAction,+ emptyMenuLabel,+ emptyMenuAction,+ };+ for (const factory of sidebarMenuFactories) {+ if (factory(factoryContext)) return items;+ }++ // 10. Universal Copy Name (for all types except connection)+ if (hasTypeMenu.value) {+ items.push({ label: "", separator: true });+ items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });+ }++ return items;+}++function activateRuntimeNode(node: TreeNode) {+ activeNode.value = node;+}++function activateActionTarget(target: SidebarActionTarget) {+ activeNode.value = findSidebarActionTarget(connectionStore.treeNodes, target) ?? target;+}++let acceptedSelectionOwner: symbol | null = null;++function bindMenuTarget(items: ContextMenuItem[], target: SidebarActionTarget, selectionIds: readonly string[]): ContextMenuItem[] {+ return items.map((item) => ({+ ...item,+ action: item.action+ ? () => {+ const owner = Symbol("sidebar-menu-action");+ acceptedSelectionOwner = owner;+ acceptedSelectionIds = selectionIds;+ activateActionTarget(target);+ const result = item.action?.() as unknown;+ if (result && typeof (result as PromiseLike<unknown>).then === "function") {+ return Promise.resolve(result).finally(() => {+ if (acceptedSelectionOwner !== owner) return;+ acceptedSelectionOwner = null;+ acceptedSelectionIds = null;+ });+ }+ if (acceptedSelectionOwner === owner) {+ acceptedSelectionOwner = null;+ acceptedSelectionIds = null;+ }+ return undefined;+ }+ : undefined,+ children: item.children ? bindMenuTarget(item.children, target, selectionIds) : undefined,+ }));+}++function buildContextMenu(node: TreeNode): ContextMenuItem[] {+ const previousNode = activeNode.value;+ const menuContext = createSidebarMenuContext(node, connectionStore.selectedTreeNodeIds, databaseTypeForNode(node));+ activateRuntimeNode(node);+ claimTreeItemDialogOwnership();+ ensureDangerDialogRouting();+ routeTreeItemDialogController();+ const rawItems = treeItemMenuItems();+ // Normalization is intentionally evaluated only when a menu opens. Besides+ // parity tests, it provides deterministic action identifiers for diagnostics.+ normalizeSidebarMenuDescriptors(menuContext, rawItems);+ const items = bindMenuTarget(rawItems, menuContext.target, menuContext.selectedNodeIds);+ activateRuntimeNode(previousNode);+ return items;+}++function handleRowClick(node: TreeNode, clickDetail: number) {+ activateRuntimeNode(node);+ runRowClickAction(clickDetail);+}++function handleRowDoubleClick(node: TreeNode, event: MouseEvent) {+ activateRuntimeNode(node);+ onDoubleClick(event);+}++function handleRowKeydown(node: TreeNode, event: KeyboardEvent) {+ activateRuntimeNode(node);+ onKeydown(event);+}++function openDataInNewTab(node: TreeNode) {+ activateRuntimeNode(node);+ openDataInNewTabImmediately(node);+}++function requestPaste(node: TreeNode): boolean {+ activateRuntimeNode(node);+ return requestPasteTreeClipboard();+}++function toggleNode(node: TreeNode) {+ activateRuntimeNode(node);+ void toggle();+}++defineExpose({+ buildContextMenu,+ handleRowClick,+ handleRowDoubleClick,+ handleRowKeydown,+ openDataInNewTab,+ requestPaste,+ toggleNode,+});+</script>++<template />diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vueindex 6dfb42cead..befc8fb097 100644--- a/apps/desktop/src/components/sidebar/TreeItem.vue+++ b/apps/desktop/src/components/sidebar/TreeItem.vue@@ -1,8 +1,6 @@<script setup lang="ts">-import { ref, computed, nextTick, watch, onBeforeUnmount, inject, reactive } from "vue";-import { useSqlHighlighter } from "@/composables/useSqlHighlighter";+import { ref, computed, inject, shallowRef, watch, onBeforeUnmount } from "vue";import { useI18n } from "vue-i18n";-import { translateBackendError } from "@/i18n/backend-errors";import {Database,Table,@@ -10,280 +8,70 @@ import {Eye,ChevronRight,ChevronDown,- ChevronsDown,Loader2,FolderOpen,FolderClosed,- Trash2,- TerminalSquare,- RefreshCw,- Copy,TableProperties,Key,Link,Zap,ListTree,- Pencil,- Play,- Plug,- Unplug,- Pin,- ArrowRightLeft,- Download,- Upload,FileCode,Network,Server,- PencilRuler,+ Pin,Search,- FolderInput,- FolderPlus,- Eraser,- Scissors,- CopyPlus,Plus,ScrollText,Braces,- Code2,- ListFilter,Package,- Clipboard,Check,UsersRound,- Activity,- Gauge,CalendarClock,Lock,- HardDriveDownload,- FilePlus,- SquarePen,- ListX,- Info,Archive,Square,X,} from "@lucide/vue";-import type { ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";-import { CONNECTION_ATTEMPT_CANCELLED_MESSAGE, useConnectionStore } from "@/stores/connectionStore";+import { useConnectionStore } from "@/stores/connectionStore";import { useQueryStore } from "@/stores/queryStore";import { useSettingsStore } from "@/stores/settingsStore";-import { useSavedSqlStore } from "@/stores/savedSqlStore";import { useToast } from "@/composables/useToast";-import { useDatabaseOptions } from "@/composables/useDatabaseOptions";-import type { ColumnInfo, ConnectionConfig, DatabaseType, ObjectSourceKind, TreeNode, TreeNodeType } from "@/types/database";-import * as api from "@/lib/backend/api";-import { uuid } from "@/lib/common/utils";-import { resolveDefaultDatabase } from "@/lib/database/defaultDatabase";-import { canTreeNodePin, canTreeNodeShowExpander, treeItemPaddingLeft, treeLabelWidthClass, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";-import { buildTableSelectSql } from "@/lib/table/tableSelectSql";-import { buildTableDeleteTemplate, buildTableInsertTemplate, buildTableSelectTemplate, buildTableUpdateTemplate } from "@/lib/table/tableSqlTemplates";-import { connectionFilePath, defaultSqliteBackupFileName, isMemorySqlitePath, sqliteBackupSourcePath } from "@/lib/connection/connectionFile";-import { driverStoreFocusForInstallError } from "@/lib/connection/agentDriverInstallHint";-import { revealPathInFileManager } from "@/lib/backend/tauri";-import { appendDebugLog, isDebugLoggingEnabled } from "@/lib/backend/debugLog";-import { clearActiveTableReferencePayload, createTableReferencePayload, createTableReferenceDropEvent, setActiveTableReferencePayload, type QueryEditorTableReferencePayload } from "@/lib/editor/queryEditorTableDrop";-import { usesSyntheticRowIdKey } from "@/lib/table/tableEditing";-import { tableOpenPageLimit } from "@/lib/table/tableOpenPageLimit";-import { getCachedTableMetadata, loadTableMetadata, TABLE_METADATA_CACHE_TTL_MS, tableMetadataToDataTabMeta } from "@/lib/metadata/tableMetadataCache";-import {- canConfigureVisibleSchemasForTreeNode,- canCreateConnectionNamespace,- canCreateDatabaseNodeNamespace,- canEditDatabaseProperties as canEditDatabasePropertiesForNode,- connectionNamespaceCreationTarget,- editableDatabasePropertyGroups,- supportsDatabaseCreation,- supportsDatabaseSearch,- supportsFieldLineage,- supportsObjectBrowserTreeNode,- supportsSchemaDiagram,- supportsSqlFileExecution,- supportsTableImport,- supportsTableTruncate,- supportsTableStructureEditing,- usesTreeSchemaMode,-} from "@/lib/database/databaseCapabilities";-import { copyNameForTreeNode, isDocumentBrowserTreeNode, objectSourceKindForTreeNode, shouldRunTreeNodeRowAction, treeNodeRowAction, treeNodeRowDoubleClickAction } from "@/lib/sidebar/treeNodeClick";-import { canApplyDataTabMetadata, dataTabOpenModeFromTreeClick, findExistingDataTabCandidate, type DataTabOpenMode } from "@/lib/sidebar/dataTabOpenPolicy";-import { isCopySidebarSelectionShortcut, isEditSidebarConnectionShortcut, isPasteSidebarSelectionShortcut } from "@/lib/editor/keyboardShortcuts";-import { formatSqlInsert } from "@/lib/export/exportFormats";-import { joinExportedDdls } from "@/lib/export/ddlExport";-import { fetchTableDataForExport } from "@/lib/table/tableDataExport";-import { canActivateExistingDataTableTab, canRefreshDataTableFromSingleActivationDoubleClick, dataTableDoubleClickAction } from "@/lib/tabs/dataTabActivation";-import { buildCreateDatabaseSql, buildDuckDbAttachDatabaseSql, duckDbAttachedDatabaseNameFromPath, supportsCreateDatabaseCharset, uniqueDuckDbAttachedDatabaseName } from "@/lib/database/createDatabaseSql";-import {- buildCreateSchemaSql,- buildDropDatabaseSql,- buildDropObjectSql,- buildDropSchemaSql,- buildGetDatabaseCommentSql,- buildGetSchemaCommentSql,- buildUpdateDatabasePropertiesSql,- buildDropTableSql,- buildDropTableChildObjectSql,- buildDuplicateTableStructureSql,- buildCopyTableDataSql,- buildEmptyTableSql,- buildTruncateTableSql,- supportsDropTableCascade,- supportsTruncateTableCascade,- supportsSchemaComment,- type DropTableChildObjectSqlOptions,- type DropObjectSqlOptions,- type TableChildObjectType,- type TableAdminSqlOptions,-} from "@/lib/database/dbAdminSql";-import { buildRenameObjectSql, supportsObjectRename, type RenameableObjectType } from "@/lib/table/objectRenameSql";-import { buildRoutineRenameObjectSourceStatements, supportsSourceBackedRoutineRename } from "@/lib/table/objectSourceEditor";-import { buildViewDdl } from "@/lib/table/viewDdl";-import { formatSqlForDisplay, sqlFormatDialectForDbType } from "@/lib/sql/sqlFormatter";-import { getTableStructureCapabilities } from "@/lib/table/tableStructureCapabilities";-import { connectionObjectTreeNodeSchema, connectionObjectTreeQuerySchema, connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection, tableStructureDatabaseTypeForConnection } from "@/lib/database/jdbcDialect";-import { hexToRgba } from "@/lib/common/color";-import { focusSidebarRenameInput } from "@/lib/sidebar/sidebarRenameFocus";-import { hasTreeNodeDatabaseContext } from "@/lib/sidebar/treeNodeContext";-import { defaultPasteTableMode, pasteTableModeCopiesData, supportsWholeRowTableDataCopy, tableClipboardMatchesTarget, tableDataCopyColumnOptions, type TableClipboardContext } from "@/lib/table/tableClipboard";-import { sidebarDisplayTableName } from "@/lib/sidebar/sidebarTableNameDisplay";-import { shouldMeasureSidebarLabelOverflow } from "@/lib/sidebar/sidebarLabelTooltip";-import { selectedTreeNodesInVisibleOrder as orderSelectedTreeNodes, treeSelectionRangeIdsByIndex, treeSelectionRangeIds } from "@/lib/sidebar/sidebarTreeSelection";-import { connectionPasteTargetGroupId, selectedConnectionClipboardTargets, selectedConnectionDeleteTargets, selectedConnectionDuplicateTargets, selectedConnectionEditTarget } from "@/lib/sidebar/sidebarConnectionSelection";-import { connectionSupportsDatabaseUserAdmin, resolveDatabaseUserAdminProviderForConnection, type DatabaseUserIdentity } from "@/lib/database/databaseUserAdmin";-import { authorizationPlanSql, authorizationPlanStatus, buildCreateDatabaseAuthorizationPlan, executeAuthorizationPlan, type AuthorizationPlan, type AuthorizationStepResult } from "@/lib/database/databaseAuthorizationPlan";-import { connectionSupportsProcessList } from "@/lib/database/processListDrivers";-import { connectionSupportsServerDashboard } from "@/lib/database/mysqlServerStatus";-import { connectionSupportsServerDashboard as connectionSupportsPgServerDashboard } from "@/lib/database/postgresServerStatus";-import { canCloseSidebarDatabaseConnection, isSidebarDatabaseOpened } from "@/lib/sidebar/sidebarDatabaseOpenState";-import { sidebarTreeContextKey } from "@/lib/sidebar/sidebarTreeContext";-import { batchTableEmptyFeedback, runBatchTableEmpty } from "@/lib/sidebar/batchTableEmpty";-import { runBatchTableTruncate } from "@/lib/table/batchTableTruncate";-import { useExportTracker, type ExportTask } from "@/composables/useExportTracker";-import { isTauriRuntime } from "@/lib/backend/tauriRuntime";-import { copyToClipboard } from "@/lib/common/clipboard";-import { hasEnabledTransportLayers } from "@/lib/backend/connectionTransport";-import { isWindows } from "@/lib/backend/platform";-import { rankSavedSqlHistory, type SavedSqlHistoryScope } from "@/lib/savedSql/savedSqlHistory";-import { isSqlServerLinkedNode } from "@/lib/database/sqlServerLinkedServers";import DatabaseIcon from "@/components/icons/DatabaseIcon.vue";import ConnectionErrorIndicator from "@/components/connection/ConnectionErrorIndicator.vue";import ProductionContextBadge from "@/components/common/ProductionContextBadge.vue";import { Badge } from "@/components/ui/badge";import { Input } from "@/components/ui/input";import LightTooltip from "@/components/ui/LightTooltip.vue";+import type { ColumnInfo, ConnectionConfig, DatabaseType, TreeNode, TreeNodeType } from "@/types/database";+import { canTreeNodeShowExpander, treeItemPaddingLeft, treeLabelWidthClass, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";+import { clearActiveTableReferencePayload, createTableReferencePayload, createTableReferenceDropEvent, setActiveTableReferencePayload, type QueryEditorTableReferencePayload } from "@/lib/editor/queryEditorTableDrop";+import { dataTabOpenModeFromTreeClick } from "@/lib/sidebar/dataTabOpenPolicy";+import { effectiveDatabaseTypeForConnection } from "@/lib/database/jdbcDialect";+import { hexToRgba } from "@/lib/common/color";+import { sidebarDisplayTableName } from "@/lib/sidebar/sidebarTableNameDisplay";+import { shouldMeasureSidebarLabelOverflow } from "@/lib/sidebar/sidebarLabelTooltip";+import { treeSelectionRangeIdsByIndex, treeSelectionRangeIds } from "@/lib/sidebar/sidebarTreeSelection";+import { isSidebarDatabaseOpened } from "@/lib/sidebar/sidebarDatabaseOpenState";+import { sidebarTreeContextKey } from "@/lib/sidebar/sidebarTreeContext";+import { isWindows } from "@/lib/backend/platform";import { flattenTree } from "@/composables/useFlatTree";-import { createDatabaseCollationOptionsForCharset, nextCreateDatabaseCollation, normalizeCreateDatabaseCharset, parseCreateDatabaseCharsetMetadata } from "@/lib/database/createDatabaseCharsetOptions";import { productionContextForDatabase } from "@/lib/database/productionSafety";-import { executeWithProductionSqlGuard } from "@/lib/database/productionExecutionGuard";-import type { SidebarDataOpenRequest } from "@/lib/sidebar/sidebarDataOpenCoordinator";-import { createSidebarActionTarget, findSidebarActionTarget } from "@/lib/sidebar/sidebarActionTarget";-import type { SidebarDangerDialogRequest } from "@/lib/sidebar/sidebarDangerDialog";-import {- fallbackCreateDatabaseCharset,- sidebarTreeDialogOwner,- sidebarDangerTarget,- sidebarFormTarget,- connectionDeleteTargetSnapshot,- showDeleteConfirm,- showDropTableConfirm,- showDropTableChildObjectConfirm,- showBatchDropConfirm,- showBatchEmptyConfirm,- showBatchTruncateConfirm,- showStructurePreviewDialog,- showStructureDocCopyDialog,- structurePreviewSql,- structurePreviewTitle,- structurePreviewDefaultFileName,- structurePreviewError,- structureDocCopyText,- structureDocCopyTitle,- isLoadingStructurePreview,- showEmptyTableConfirm,- showTruncateTableConfirm,- showRenameObjectDialog,- renameObjectName,- renameObjectError,- renameObjectPreviewSql,- dropTablePreviewSql,- dropTableCascade,- batchDropCascade,- emptyTablePreviewSql,- truncateTablePreviewSql,- truncateTableCascade,- dropObjectPreviewSql,- showDropObjectConfirm,- dropTableChildObjectPreviewSql,- batchDropPreviewSql,- batchEmptyPreviewSql,- batchEmptyTargets,- batchDropTargets,- batchTruncateTargets,- batchTruncatePreviewSql,- batchTruncateCascade,- dropDatabasePreviewSql,- dropSchemaPreviewSql,- showDuplicateDialog,- duplicateTableName,- duplicateStructureSource,- showPasteDialog,- pasteTableMode,- pasteTableEntries,- showCreateDatabaseDialog,- createDatabaseName,- createDatabaseCharset,- createDatabaseCollation,- createDatabaseUsers,- createDatabaseSelectedUsers,- createDatabaseUsersLoading,- showCreateDatabasePreviewDialog,- createDatabaseAuthorizationPlan,- createDatabasePreviewSql,- createDatabaseAuthorizationResults,- createDatabaseAuthorizationApplying,- showCreateNacosNamespaceDialog,- createNacosNamespaceId,- createNacosNamespaceName,- createNacosNamespaceDesc,- createNacosNamespaceLoading,- showEditNacosNamespaceDialog,- editNacosNamespaceName,- editNacosNamespaceDesc,- editNacosNamespaceLoading,- createDatabaseCharsetOptions,- createDatabaseCollationsByCharset,- createDatabaseCharsetLoading,- showDropDatabaseConfirm,- dropDatabaseLoading,- showDropMongoCollectionConfirm,- dropMongoCollectionLoading,- showDropMongoIndexConfirm,- dropMongoIndexLoading,- showDropAllMongoIndexesConfirm,- dropAllMongoIndexesLoading,- showFlushRedisDbConfirm,- showCreateSchemaDialog,- createSchemaName,- showDropSchemaConfirm,- showEditDatabasePropertiesDialog,- editDatabasePropertiesLoading,- editDatabasePropertiesPreviewSql,- editDatabaseCharset,- editDatabaseCollation,- editDatabaseCommentText,- showEditSchemaCommentDialog,- schemaCommentText,- schemaCommentLoading,- schemaCommentPreviewSql,- showDeleteGroupConfirm,- showMoveToNewGroupDialog,- moveToNewGroupName,- type DuplicateStructureSource,-} from "./sidebarTreeDialogState";+import { focusSidebarRenameInput } from "@/lib/sidebar/sidebarRenameFocus";+// --- Drag and Drop ---+import { useDragSort } from "@/composables/useDragSort";+import { sidebarTreeRuntimeKey } from "@/lib/sidebar/sidebarTreeRuntime";const { t } = useI18n();+const labelRef = ref<HTMLElement>();+const rowRef = ref<HTMLElement>();+const labelOverflowing = ref(false);+let labelResizeObserver: ResizeObserver | null = null;+let labelMeasureFrame = 0;function cancelLabelOverflowMeasure() {@@ -335,18 +123,16 @@ function handleMouseLeave() {labelResizeObserver = null;cancelLabelOverflowMeasure();}+const connectionStore = useConnectionStore();+const queryStore = useQueryStore();+const settingsStore = useSettingsStore();-const savedSqlStore = useSavedSqlStore();+const { toast } = useToast();-const { highlight } = useSqlHighlighter();-const useWindowsSidebarCommentFont = isWindows();-type StructureCopyFormat = "tsv" | "markdown";-const DATA_TAB_METADATA_TTL_MS = TABLE_METADATA_CACHE_TTL_MS;-const { getDatabaseOptions } = useDatabaseOptions();-const { addTask: addExportTask } = useExportTracker();+const useWindowsSidebarCommentFont = isWindows();const props = defineProps<{node: TreeNode;@@ -359,68 +145,37 @@ const props = defineProps<{const emit = defineEmits<{"rename-started": [];"group-created": [groupId: string];- "node-toggled": [node: TreeNode, wasExpanded: boolean];- "search-toggle": [node: TreeNode];- "context-menu": [event: MouseEvent, node: TreeNode, items: ContextMenuItem[]];- "open-ddl": [node: TreeNode];- "open-object-source": [node: TreeNode, initialEditing: boolean];- "open-procedure": [node: TreeNode];- "open-data": [node: TreeNode, requireSelection: boolean, openMode: DataTabOpenMode, runner: (node: TreeNode, request: SidebarDataOpenRequest) => Promise<void>];- "open-visible-databases": [node: TreeNode];- "open-visible-schemas": [node: TreeNode];- "open-danger-dialog": [request: SidebarDangerDialogRequest];- "open-dialog-controller": [controller: Record<string, any> | null];- "open-install-extension": [node: TreeNode];+ "context-menu": [event: MouseEvent, node: TreeNode];}>();-const treeItemDialogOwner = Symbol("sidebar-tree-dialog-owner");-function claimTreeItemDialogOwnership() {- sidebarTreeDialogOwner.value = treeItemDialogOwner;-}--function routeTreeItemDialogController() {- const controller = getTreeItemDialogController();- const target = createSidebarActionTarget(props.node);- sidebarFormTarget.value = target;- controller.node = target;- controller.pasteTableDataCopySupported = pasteTableDataCopySupported.value;- controller.canSetCreateDatabaseCharset = canSetCreateDatabaseCharset.value;- controller.canEditDatabaseCharsetCollation = canEditDatabaseCharsetCollation.value;- controller.canEditDatabaseComment = canEditDatabaseComment.value;- emit("open-dialog-controller", controller);-}--const usesFullWidthLabel = computed(() => usesFullWidthTreeLabel(props.node.type, settingsStore.editorSettings.sidebarAllowHorizontalScroll));+const sidebarTreeRuntime = inject(sidebarTreeRuntimeKey);+if (!sidebarTreeRuntime) throw new Error("TreeItem must be rendered inside ConnectionTree");+const treeRuntime = sidebarTreeRuntime;const sidebarTreeContext = inject(sidebarTreeContextKey, null);-const rowWidthClass = computed(() => (usesFullWidthLabel.value ? "w-max min-w-full" : "w-full min-w-0"));-const nodeProductionContext = computed(() => {- const connectionId = props.node.connectionId;- return productionContextForDatabase(connectionId ? connectionStore.getConfig(connectionId) : undefined, props.node.database);-});-const showProductionBadge = computed(() => nodeProductionContext.value.active && ["connection", "database", "redis-db", "mongo-db"].includes(props.node.type));-function currentDatabaseType(): DatabaseType | undefined {- return props.node.connectionId ? effectiveDatabaseTypeForConnection(connectionStore.getConfig(props.node.connectionId)) : undefined;-}+const stopPasteHandlerRegistration = watch(+ () => props.node.id,+ (nodeId, _previousNodeId, onCleanup) => {+ const unregister = sidebarTreeContext?.registerPasteHandler?.(nodeId, () => treeRuntime.requestPaste(props.node));+ if (unregister) onCleanup(unregister);+ },+ { immediate: true },+);-function currentTableStructureDatabaseType(): DatabaseType | undefined {- return props.node.connectionId ? tableStructureDatabaseTypeForConnection(connectionStore.getConfig(props.node.connectionId)) : undefined;-}+const activeNode = shallowRef<TreeNode>(props.node);-function rawDatabaseType(): DatabaseType | undefined {- return props.node.connectionId ? connectionStore.getConfig(props.node.connectionId)?.db_type : undefined;-}+const usesFullWidthLabel = computed(() => usesFullWidthTreeLabel(activeNode.value.type, settingsStore.editorSettings.sidebarAllowHorizontalScroll));-function databaseTypeForNode(node: TreeNode): DatabaseType | undefined {- return node.connectionId ? effectiveDatabaseTypeForConnection(connectionStore.getConfig(node.connectionId)) : undefined;-}+const rowWidthClass = computed(() => (usesFullWidthLabel.value ? "w-max min-w-full" : "w-full min-w-0"));-function tableStructureDatabaseTypeForNode(node: TreeNode): DatabaseType | undefined {- return node.connectionId ? tableStructureDatabaseTypeForConnection(connectionStore.getConfig(node.connectionId)) : undefined;-}+const showProductionBadge = computed(() => {+ const connectionId = activeNode.value.connectionId;+ const context = productionContextForDatabase(connectionId ? connectionStore.getConfig(connectionId) : undefined, activeNode.value.database);+ return context.active && ["connection", "database", "redis-db", "mongo-db"].includes(activeNode.value.type);+});-function hasNodeDatabaseContext(node: TreeNode): node is TreeNode & { connectionId: string; database: string } {- return !!node.connectionId && hasTreeNodeDatabaseContext(node);+function currentDatabaseType(): DatabaseType | undefined {+ return activeNode.value.connectionId ? effectiveDatabaseTypeForConnection(connectionStore.getConfig(activeNode.value.connectionId)) : undefined;}function getIconInfo(node: TreeNode): { icon: any; colorClass: string } | null {@@ -534,6 +289,7 @@ function getIconInfo(node: TreeNode): { icon: any; colorClass: string } | null {}const groupTypes: Set<TreeNodeType> = new Set(["group-columns", "group-indexes", "group-fkeys", "group-triggers", "group-tables", "group-views", "group-materialized-views", "group-procedures", "group-functions", "group-sequences", "group-packages", "group-partitions", "group-extensions"]);+function isGroupLabel(node: TreeNode): boolean {return groupTypes.has(node.type);}@@ -630,29 +386,24 @@ function connectionTooltipUrl(config: ConnectionConfig): string {return redactedConnectionString(`${scheme}://${userInfo}${hostForDisplay(host)}${port}${path}${query}`);}-const connectionInfoTooltip = computed(() => {- const node = props.node;- if (node.type !== "connection" || !node.connectionId) return null;- const config = connectionStore.getConfig(node.connectionId);- if (!config) return null;-- const hostLabel = isLocalFileConnection(config) ? t("connection.filePath") : t("connection.host");- const rows: DetailTooltipRow[] = [- { label: t("connection.name"), value: cleanTooltipValue(config.name) },- { label: "URL", value: connectionTooltipUrl(config), multiline: true },- { label: hostLabel, value: cleanTooltipValue(config.host), multiline: isLocalFileConnection(config) },- { label: "Port", value: Number(config.port) > 0 ? String(config.port) : "" },- { label: t("connection.database"), value: cleanTooltipValue(config.database) },- { label: t("connection.user"), value: cleanTooltipValue(config.username) },- { label: t("connection.type"), value: config.driver_label || config.driver_profile || config.db_type },- { label: t("connection.databaseInfo.productVersion"), value: cleanTooltipValue(config.database_info?.productVersion) },- ].filter((row) => row.value);-- return { rows };-});--const objectCommentTooltip = computed(() => {- const node = props.node;+const detailTooltip = computed(() => {+ const node = activeNode.value;+ if (node.type === "connection" && node.connectionId) {+ const config = connectionStore.getConfig(node.connectionId);+ if (!config) return null;+ const hostLabel = isLocalFileConnection(config) ? t("connection.filePath") : t("connection.host");+ const rows: DetailTooltipRow[] = [+ { label: t("connection.name"), value: cleanTooltipValue(config.name) },+ { label: "URL", value: connectionTooltipUrl(config), multiline: true },+ { label: hostLabel, value: cleanTooltipValue(config.host), multiline: isLocalFileConnection(config) },+ { label: "Port", value: Number(config.port) > 0 ? String(config.port) : "" },+ { label: t("connection.database"), value: cleanTooltipValue(config.database) },+ { label: t("connection.user"), value: cleanTooltipValue(config.username) },+ { label: t("connection.type"), value: config.driver_label || config.driver_profile || config.db_type },+ { label: t("connection.databaseInfo.productVersion"), value: cleanTooltipValue(config.database_info?.productVersion) },+ ].filter((row) => row.value);+ return { rows };+ }const comment = node.type === "column" && node.meta && "comment" in node.meta ? (node.meta as ColumnInfo).comment : node.comment;if (!comment || (node.type !== "schema" && node.type !== "table" && node.type !== "view" && node.type !== "column")) return null;const rows: DetailTooltipRow[] = [@@ -662,262 +413,16 @@ const objectCommentTooltip = computed(() => {return { rows };});-const detailTooltip = computed(() => connectionInfoTooltip.value ?? objectCommentTooltip.value);-function isTooltipDisabled(): boolean {if (detailTooltip.value?.rows.length) return isRenamingGroup.value;return isRenamingGroup.value || !labelOverflowing.value;}-async function toggle() {- const node = props.node;- if (node.isLoading) {- if (!node.isExpanded) {- node.isExpanded = true;- emit("node-toggled", node, false);- }- return;- }- emit("search-toggle", node);- const wasExpanded = !!node.isExpanded;-- if (node.type === "connection-group") {- node.isExpanded = !node.isExpanded;- connectionStore.toggleConnectionGroupCollapsed(node.id);- emit("node-toggled", node, wasExpanded);- return;- }-- if (node.type === "group-partitions") {- node.isExpanded = !node.isExpanded;- emit("node-toggled", node, wasExpanded);- return;- }-- const databaseObjectGroup = node.type === "group-tables" || node.type === "group-views" || node.type === "group-materialized-views" || node.type === "group-procedures" || node.type === "group-functions" || node.type === "group-sequences" || node.type === "group-packages";- if (databaseObjectGroup && connectionStore.isTreeNodeChildrenLoaded(node.id)) {- node.isExpanded = !node.isExpanded;- if (wasExpanded) connectionStore.releaseCollapsedTreeNodeChildren(node.id);- emit("node-toggled", node, wasExpanded);- return;- }-- if (node.isExpanded) {- node.isExpanded = false;- connectionStore.releaseCollapsedTreeNodeChildren(node.id);- emit("node-toggled", node, wasExpanded);- return;- }-- try {- if (node.type === "connection" && node.connectionId) {- const config = connectionStore.getConfig(node.connectionId);- if (config?.db_type === "redis") {- await connectionStore.loadRedisDatabases(node.connectionId);- } else if (config?.db_type === "etcd") {- await connectionStore.loadEtcdRoot(node.connectionId);- } else if (config?.db_type === "zookeeper") {- await connectionStore.loadZooKeeperRoot(node.connectionId);- } else if (config?.db_type === "mongodb") {- await connectionStore.loadMongoDatabases(node.connectionId);- } else if (config?.db_type === "elasticsearch") {- await connectionStore.loadElasticsearchIndices(node.connectionId);- } else if (config?.db_type === "milvus") {- await connectionStore.loadMilvusDatabases(node.connectionId);- } else if (config?.db_type === "qdrant" || config?.db_type === "weaviate" || config?.db_type === "chromadb") {- await connectionStore.loadVectorCollections(node.connectionId);- } else if (config?.db_type === "mq") {- await connectionStore.loadMqTenants(node.connectionId);- } else if (config?.db_type === "nacos") {- await connectionStore.loadNacosNamespaces(node.connectionId);- } else {- await connectionStore.loadDatabases(node.connectionId);- }- } else if (node.type === "redis-db" && node.connectionId && node.database) {- await connectionStore.ensureConnected(node.connectionId);- const tabTitle = `${connectionStore.getConfig(node.connectionId)?.name || "Redis"}:db${node.database}`;- queryStore.createTab(node.connectionId, node.database, tabTitle, "redis");- } else if (node.type === "mq-tenant" && node.connectionId) {- await connectionStore.ensureConnected(node.connectionId);- queryStore.openMqAdmin(node.connectionId, { tenant: node.mqTenant || node.label, initialTab: node.mqInitialTab });- } else if (node.type === "nacos-namespace" && node.connectionId) {- await connectionStore.ensureConnected(node.connectionId);- queryStore.openNacosAdmin(node.connectionId, { namespace: node.nacosNamespace || "", namespaceName: node.nacosNamespaceName || node.label });- } else if (node.type === "etcd-root" && node.connectionId) {- await connectionStore.ensureConnected(node.connectionId);- const tabTitle = `${connectionStore.getConfig(node.connectionId)?.name || "etcd"}:keys`;- queryStore.createTab(node.connectionId, "", tabTitle, "etcd");- refreshActiveKvBrowserAfterOpen("etcd", node.connectionId);- } else if (node.type === "zookeeper-root" && node.connectionId) {- await connectionStore.ensureConnected(node.connectionId);- const tabTitle = `${connectionStore.getConfig(node.connectionId)?.name || "ZooKeeper"}:keys`;- queryStore.createTab(node.connectionId, "", tabTitle, "zookeeper");- refreshActiveKvBrowserAfterOpen("zookeeper", node.connectionId);- } else if (node.type === "user-admin" && node.connectionId) {- await connectionStore.ensureConnected(node.connectionId);- queryStore.openUserAdmin(node.connectionId);- } else if (node.type === "dameng-job-admin" && node.connectionId) {- await connectionStore.ensureConnected(node.connectionId);- queryStore.openDamengJobAdmin(node.connectionId);- } else if (node.type === "mongo-db" && node.connectionId && node.database) {- await connectionStore.loadMongoCollections(node.connectionId, node.database);- } else if (node.type === "vector-database" && node.connectionId && node.database) {- await connectionStore.loadVectorCollections(node.connectionId, node.database);- } else if (node.type === "mongo-collection" && node.connectionId && node.database) {- await connectionStore.loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id);- } else if (node.type === "elasticsearch-index" && node.connectionId) {- await connectionStore.ensureConnected(node.connectionId);- const tab = queryStore.createTab(node.connectionId, node.database || "default", node.label, "mongo");- queryStore.updateSql(tab, node.label);- } else if (node.type === "vector-collection" && node.connectionId) {- await connectionStore.ensureConnected(node.connectionId);- const collectionRef = (node.meta as { collectionId?: string } | undefined)?.collectionId ?? node.label;- const tab = queryStore.createTab(node.connectionId, node.database || "default", node.label, "vector");- queryStore.updateSql(tab, collectionRef);- api- .vectorGetCollectionDetail(node.connectionId, node.database || "default", collectionRef)- .then((info) => {- if (info.dimension != null) {- if (node.meta) {- (node.meta as Record<string, unknown>).dimension = info.dimension;- } else {- node.meta = { dimension: info.dimension } as any;- }- }- })- .catch(() => {});- } else if (node.type === "database" && node.connectionId && hasTreeNodeDatabaseContext(node)) {- if (node.catalog && node.catalog !== "internal") {- await connectionStore.loadDorisCatalogTables(node);- } else {- const config = connectionStore.getConfig(node.connectionId);- const effectiveDbType = effectiveDatabaseTypeForConnection(config);- if (config?.db_type === "sqlserver") {- await connectionStore.loadSqlServerDatabaseObjects(node.connectionId, node.database);- } else if (usesTreeSchemaMode(effectiveDbType) && !connectionUsesDatabaseObjectTreeMode(config)) {- await connectionStore.loadSchemas(node.connectionId, node.database);- } else {- await connectionStore.loadTables(node.connectionId, node.database);- }- }- } else if (node.type === "doris-catalog" && node.connectionId) {- await connectionStore.loadDorisCatalogDatabases(node);- } else if (node.type === "schema" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.schema) {- await connectionStore.loadTables(node.connectionId, node.database, node.schema);- } else if (node.type === "linked-server-root" && node.connectionId) {- await connectionStore.loadSqlServerLinkedServers(node.connectionId);- } else if (node.type === "linked-server" && node.connectionId) {- await connectionStore.loadSqlServerLinkedServerCatalogs(node);- } else if (node.type === "linked-server-catalog" && node.connectionId) {- await connectionStore.loadSqlServerLinkedServerSchemas(node);- } else if (node.type === "linked-server-schema" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.schema) {- await connectionStore.loadTables(node.connectionId, node.database, node.schema);- } else if ((node.type === "table" || node.type === "view" || node.type === "materialized_view") && node.connectionId && hasTreeNodeDatabaseContext(node)) {- await connectionStore.loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id, node.catalog);- } else if (node.type === "group-columns" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {- await connectionStore.loadColumns(node.connectionId, node.database, node.tableName, node.schema, node.id, node.catalog);- } else if (node.type === "group-indexes" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {- await connectionStore.loadIndexes(node.connectionId, node.database, node.tableName, node.schema, node.id, node.catalog);- } else if (node.type === "group-fkeys" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {- await connectionStore.loadForeignKeys(node.connectionId, node.database, node.tableName, node.schema, node.id, node.catalog);- } else if (node.type === "group-triggers" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {- await connectionStore.loadTriggers(node.connectionId, node.database, node.tableName, node.schema, node.id, node.catalog);- } else if (databaseObjectGroup) {- await connectionStore.loadObjectGroupChildren(node);- }- emit("node-toggled", node, wasExpanded);- } catch (e: any) {- if (!wasExpanded) node.isExpanded = false;- const errMsg = e?.message || String(e);- if (errMsg.includes(CONNECTION_ATTEMPT_CANCELLED_MESSAGE)) return;- toast(t("connection.connectFailed", { message: translateBackendError(t, errMsg) }), 5000);- openDriverStoreForInstallError(errMsg);- }-}--function runRowClickAction(clickDetail: number) {- const node = props.node;- if (node.type === "load-more") {- if (clickDetail > 1) return;- void loadMoreObjectGroupChildren();- return;- }- if (node.type === "object-browser") {- if (clickDetail > 1) return;- void openObjectBrowser();- return;- }- if (node.type === "mongo-gridfs") {- openMongoTreeData(node);- return;- }- const action = treeNodeRowAction(node.type, canExpand.value, settingsStore.editorSettings.sidebarActivation);- if (!shouldRunTreeNodeRowAction(action, clickDetail)) return;- if (action === "open-data") {- if (node.type === "table") {- singleActivationDoubleClickRefreshAllowed = canRefreshDataTableFromSingleActivationDoubleClick(findExistingSameTableDataTab());- }- scheduleOpenData(node);- } else if (isDocumentBrowserTreeNode(node.type)) {- openMongoTreeData(node);- } else if (node.type === "procedure" || node.type === "function" || node.type === "sequence" || node.type === "package" || node.type === "package-body") {- openObjectSourceDialog(false);- } else if (action === "toggle") {- toggle();- }-}--let singleActivationDoubleClickRefreshAllowed = false;--function refreshActiveKvBrowserAfterOpen(mode: "etcd" | "zookeeper", connectionId: string) {- void nextTick(() => {- window.dispatchEvent(new CustomEvent("dbx-refresh-active-kv-browser", { detail: { mode, connectionId } }));- });-}--function openDriverStoreForInstallError(errMsg: string) {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- const focus = driverStoreFocusForInstallError(errMsg, config?.db_type, config?.driver_profile);- if (focus) window.dispatchEvent(new CustomEvent("dbx-open-driver-store", { detail: focus }));-}--async function loadMoreObjectGroupChildren() {- try {- await connectionStore.loadMoreObjectGroupChildren(props.node);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--async function loadAllObjectGroupChildren() {- try {- await connectionStore.loadAllObjectGroupChildren(props.node);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--function onToggleClick() {- selectSingleTreeNode(props.node);- rowRef.value?.focus({ preventScroll: true });- void toggle();-}--function onToggleMouseDown(event: MouseEvent) {- if (event.button !== 0) return;- selectSingleTreeNode(props.node);- rowRef.value?.focus({ preventScroll: true });-}-function visibleTreeNodes(): TreeNode[] {if (sidebarTreeContext) return sidebarTreeContext.getVisibleNodes();return flattenTree(connectionStore.treeNodes).map((item) => item.node);}-function selectedTreeNodesInVisibleOrder(): TreeNode[] {- return orderSelectedTreeNodes(visibleTreeNodes(), connectionStore.selectedTreeNodeIds);-}-function selectSingleTreeNode(node: TreeNode) {// Re-clicking the selected row should not replace the selection array and// force visible tree rows to recompute.@@ -969,3510 +474,110 @@ function selectedConnectionIdsForAction(): string[] {}const isConnectionSelectionChecked = computed(() => {- if (!connectionStore.connectionMultiSelectActive || props.node.type !== "connection" || !props.node.connectionId) return false;- return connectionStore.selectedTreeNodeIds.includes(props.node.connectionId);+ if (!connectionStore.connectionMultiSelectActive || activeNode.value.type !== "connection" || !activeNode.value.connectionId) return false;+ return connectionStore.selectedTreeNodeIds.includes(activeNode.value.connectionId);});function toggleConnectionMultiSelection(event: MouseEvent) {event.preventDefault();event.stopPropagation();- if (props.node.type !== "connection" || !props.node.connectionId) return;+ if (activeNode.value.type !== "connection" || !activeNode.value.connectionId) return;// Keep connection-id normalization off the row render path; this handler only// runs when the checkbox is clicked, while the checked state updates often.const next = new Set(connectionStore.connectionMultiSelectActive ? selectedConnectionIdsForAction() : []);- if (next.has(props.node.connectionId)) next.delete(props.node.connectionId);- else next.add(props.node.connectionId);+ if (next.has(activeNode.value.connectionId)) next.delete(activeNode.value.connectionId);+ else next.add(activeNode.value.connectionId);const ids = [...next];connectionStore.selectedTreeNodeIds = ids;- connectionStore.selectedTreeNodeId = ids.includes(props.node.connectionId) ? props.node.connectionId : (ids[0] ?? null);- connectionStore.treeSelectionAnchorId = props.node.connectionId;+ connectionStore.selectedTreeNodeId = ids.includes(activeNode.value.connectionId) ? activeNode.value.connectionId : (ids[0] ?? null);+ connectionStore.treeSelectionAnchorId = activeNode.value.connectionId;connectionStore.connectionMultiSelectActive = ids.length > 0;rowRef.value?.focus({ preventScroll: true });}-function onClick(event: MouseEvent) {- if (props.node.type === "table" && event.detail <= 1) singleActivationDoubleClickRefreshAllowed = false;- if (suppressNextTableReferenceClick) {- suppressNextTableReferenceClick = false;- event.preventDefault();- event.stopPropagation();- return;- }- // Row clicks must not bubble to the tree container, whose click handler- // clears the selection when the blank area is clicked (issue #681).- event.stopPropagation();- const dataTabOpenMode = dataTabOpenModeFromTreeClick(props.node.type, event, settingsStore.editorSettings.shortcuts.openDataInNewTab);- if (dataTabOpenMode === "new-tab") {- event.preventDefault();- if (event.detail > 1) return;- selectSingleTreeNode(props.node);- rowRef.value?.focus({ preventScroll: true });- openDataInNewTabImmediately(props.node);- return;- }- if (event.shiftKey) {- selectTreeNodeRange(props.node);- rowRef.value?.focus({ preventScroll: true });- return;- }- if (event.metaKey || event.ctrlKey) {- toggleTreeNodeSelection(props.node);- rowRef.value?.focus({ preventScroll: true });- return;- }- selectSingleTreeNode(props.node);- rowRef.value?.focus({ preventScroll: true });- if (settingsStore.editorSettings.sidebarActivation === "double") return;- runRowClickAction(event.detail);-}--function onTreeItemContextMenu(event: MouseEvent) {- claimTreeItemDialogOwnership();- ensureDangerDialogRouting();- routeTreeItemDialogController();- if (!connectionStore.selectedTreeNodeIds.includes(props.node.id)) {- selectSingleTreeNode(props.node);- } else {- connectionStore.selectedTreeNodeId = props.node.id;+async function cancelConnectionAttempt() {+ if (!activeNode.value.connectionId) return;+ try {+ const cancelled = await connectionStore.cancelConnecting(activeNode.value.connectionId);+ if (cancelled) toast(t("connection.connectCancelled"), 2000);+ } catch (e: any) {+ toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000);}- rowRef.value?.focus({ preventScroll: true });- emit("context-menu", event, props.node, treeItemMenuItems());-}--function isEditableShortcutTarget(target: EventTarget | null): boolean {- if (!(target instanceof HTMLElement)) return false;- return target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target.isContentEditable || !!target.closest("[contenteditable='true']");}-function onKeydown(event: KeyboardEvent) {- claimTreeItemDialogOwnership();- if ((!isSelected.value && !isMultiSelected.value) || isEditableShortcutTarget(event.target)) return;- if (isPasteTreeClipboardShortcut(event)) {- if (!requestPasteTreeClipboard()) return;- event.preventDefault();- event.stopPropagation();- return;- }- if (isEditConnectionShortcut(event)) {- if (!requestEditSelectedConnection()) return;- event.preventDefault();- event.stopPropagation();- return;- }- if (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && event.key === "F2") {- if (!requestRenameSelectedNode()) return;- event.preventDefault();- event.stopPropagation();- return;- }- if (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && event.key === "F5") {- if (!requestRefreshSelectedNode()) return;- event.preventDefault();- event.stopPropagation();- return;- }- if (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && isDeleteTreeNodeShortcut(event)) {- if (!requestDeleteSelectedNode()) return;- event.preventDefault();- event.stopPropagation();- return;- }- if (!isCopyTreeSelectionShortcut(event)) return;- event.preventDefault();- event.stopPropagation();- copySelectedNames();-}+const canExpand = computed(() =>+ canTreeNodeShowExpander({+ type: activeNode.value.type,+ childCount: activeNode.value.children?.length ?? 0,+ }),+);-function isDeleteTreeNodeShortcut(event: KeyboardEvent): boolean {- return event.key === "Delete" || event.key === "Backspace";-}+const isPinned = computed(() => activeNode.value.pinned || connectionStore.isTreeNodePinned(activeNode.value));-function isPasteTreeClipboardShortcut(event: KeyboardEvent): boolean {- return isPasteSidebarSelectionShortcut(event, settingsStore.editorSettings.shortcuts);-}+const isNodeDefaultDatabase = computed(+ () => (activeNode.value.type === "database" || activeNode.value.type === "redis-db" || activeNode.value.type === "mongo-db") && !!activeNode.value.connectionId && !!activeNode.value.database && connectionStore.isDefaultDatabase(activeNode.value.connectionId, activeNode.value.database),+);-function isEditConnectionShortcut(event: KeyboardEvent): boolean {- return isEditSidebarConnectionShortcut(event, settingsStore.editorSettings.shortcuts);-}+const columnComment = computed(() => (!settingsStore.editorSettings.sidebarHideTableComments && activeNode.value.type === "column" && activeNode.value.meta && "comment" in activeNode.value.meta ? (activeNode.value.meta as any).comment : null));-function isCopyTreeSelectionShortcut(event: KeyboardEvent): boolean {- return isCopySidebarSelectionShortcut(event, settingsStore.editorSettings.shortcuts);-}+const tableComment = computed(() =>+ !settingsStore.editorSettings.sidebarHideTableComments &&+ (activeNode.value.type === "schema" || activeNode.value.type === "table" || activeNode.value.type === "view" || activeNode.value.type === "mongo-collection" || activeNode.value.type === "vector-collection" || activeNode.value.type === "elasticsearch-index") &&+ activeNode.value.comment+ ? activeNode.value.comment+ : null,+);-function pasteTableTargetContext(): TableClipboardContext | null {- if (!props.node.connectionId || !props.node.database) return null;- return {- connectionId: props.node.connectionId,- database: props.node.database,- schema: props.node.schema,- };-}+const labelWidthClass = computed(() => treeLabelWidthClass({ fullWidth: usesFullWidthLabel.value, hasTrailingComment: !!columnComment.value || !!tableComment.value }));-function canPasteTreeClipboardToCurrentNode(): boolean {- const clipboard = connectionStore.treeClipboard;- return clipboard?.kind === "table-copy" && tableClipboardMatchesTarget(clipboard.tables, pasteTableTargetContext());-}+const paddingLeft = computed(() => treeItemPaddingLeft(props.depth));-function requestPasteTreeClipboard(): boolean {- claimTreeItemDialogOwnership();- ensureDangerDialogRouting();- routeTreeItemDialogController();- const clipboard = connectionStore.treeClipboard;- if (clipboard?.kind === "connection-copy") {- const targetGroupId = connectionPasteTargetGroupId(props.node, (connectionId) => connectionStore.groupIdForConnection(connectionId));- void connectionStore- .pasteConnectionClipboard(targetGroupId)- .then((count) => {- if (count > 0) toast(count > 1 ? t("connection.duplicatedSelected", { count }) : t("connection.duplicated"), 2000);- })- .catch((e: any) => toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000));- return true;- }- if (clipboard?.kind !== "table-copy" || !canPasteTreeClipboardToCurrentNode()) return false;- pasteTableMode.value = defaultPasteTableMode(currentDatabaseType());- pasteTableEntries.value = clipboard.tables.map((entry) => ({- sourceName: entry.tableName,- targetName: `${entry.tableName}_copy`,- connectionId: entry.connectionId,- database: entry.database,- schema: entry.schema,- }));- showPasteDialog.value = true;- return true;-}+const tableSearchParentId = computed(() => activeNode.value.tableSearchParentId || "");-function requestRefreshSelectedNode(): boolean {- if (!canRefreshTreeNodeShortcut()) return false;- void refresh();- return true;-}+const tableSearchValue = computed(() => {+ const parentId = tableSearchParentId.value;+ return parentId ? connectionStore.sidebarTableSearchQueries[parentId] || "" : "";+});-function canRefreshTreeNodeShortcut(): boolean {- const type = props.node.type;- if (type === "connection" || type === "database" || type === "schema" || type === "table" || type === "view") {- return true;- }- return isGroupLabel(props.node) && type !== "group-partitions";-}+const isConnecting = computed(() => activeNode.value.type === "connection" && !!activeNode.value.connectionId && connectionStore.connectingIds.has(activeNode.value.connectionId));-function requestRenameSelectedNode(): boolean {- const selected = selectedTreeNodesInVisibleOrder();- if (selected.length > 1 && selected.some((node) => node.id === props.node.id)) return false;- const editTarget = selectedConnectionEditTarget(props.node, selected);- if (editTarget) {- connectionStore.startEditing(editTarget.connectionId);- return true;- }- if (canRenameObject.value) {- openRenameObjectDialog();- return true;- }- if (props.node.type === "connection-group") {- startRenameGroup();- return true;- }- return false;-}+const isConnectionReadonly = computed(() => activeNode.value.type === "connection" && !!activeNode.value.connectionId && (connectionStore.getConfig(activeNode.value.connectionId)?.read_only ?? false));-function requestEditSelectedConnection(): boolean {- const editTarget = selectedConnectionEditTarget(props.node, selectedTreeNodesInVisibleOrder());- if (!editTarget) return false;- connectionStore.startEditing(editTarget.connectionId);- return true;-}+const databaseOpenVisual = computed(() => {+ const opened = isSidebarDatabaseOpened(activeNode.value, connectionStore.isTreeNodeChildrenLoaded);+ const showsIndicator = activeNode.value.type === "database" && (opened || (!!activeNode.value.connectionId && activeNode.value.database != null && queryStore.openDatabaseKeys.has(`${activeNode.value.connectionId}\x00${activeNode.value.database}`)));+ const infoClass = getIconInfo(activeNode.value)?.colorClass;+ return {+ iconClass: activeNode.value.type !== "database" || opened ? infoClass : "text-muted-foreground/65",+ showsIndicator,+ };+});-function requestDeleteSelectedNode(): boolean {- claimTreeItemDialogOwnership();- ensureDangerDialogRouting();- routeTreeItemDialogController();- if (requestDropSelectedNodes()) return true;- if (props.node.type === "connection") {- deleteConnection();- return true;- }- if (props.node.type === "connection-group") {- deleteConnectionGroup();- return true;- }- if (canDropDatabase.value) {- dropDatabase();- return true;- }- if (canDropMongoDatabase.value) {- dropDatabase();- return true;- }- if (canDropMongoCollection.value) {- dropMongoCollection();- return true;- }- if (canDropSchema.value) {- dropSchema();- return true;- }- return false;+function connectionIconType(connectionId?: string) {+ const config = connectionId ? connectionStore.getConfig(connectionId) : undefined;+ return config?.driver_profile || config?.db_type || "postgres";}-function onDoubleClick(event: MouseEvent) {- if (dataTabOpenModeFromTreeClick(props.node.type, event, settingsStore.editorSettings.shortcuts.openDataInNewTab) === "new-tab") return;- const action = treeNodeRowDoubleClickAction(props.node.type, canOpenObjectBrowser.value, settingsStore.editorSettings.sidebarActivation, canExpand.value);- if (action === "open-object-browser") {- void openObjectBrowser();- } else if (action === "open-object-browser-and-expand") {- void openObjectBrowser();- if (!props.node.isExpanded) void toggle();- } else if (action === "open-data") {- openDataImmediately(props.node);- } else if (action === "refresh-data") {- void refreshData();- } else if (action === "open-source") {- openObjectSourceDialog(false);- } else if (action === "open-saved-sql") {- openSavedSqlFile();- } else if (action === "toggle" && (props.node.type === "mongo-gridfs" || isDocumentBrowserTreeNode(props.node.type))) {- openMongoTreeData(props.node);- } else if (action === "toggle") {- toggle();- }-}+const connectionColor = computed(() => {+ const connectionId = activeNode.value.connectionId;+ return connectionId ? connectionStore.getConfig(connectionId)?.color || "" : "";+});-async function refreshData() {- const node = props.node;- if (node.type !== "table" || !hasNodeDatabaseContext(node)) return;- const singleActivationRefreshAllowed = singleActivationDoubleClickRefreshAllowed;- singleActivationDoubleClickRefreshAllowed = false;- const activation = settingsStore.editorSettings.sidebarActivation;- if (activation === "single" && !singleActivationRefreshAllowed) return;- const existingSameTableTab = findExistingSameTableDataTab();- const action = dataTableDoubleClickAction(existingSameTableTab, activation, singleActivationRefreshAllowed);- if (action === "none") return;- if (action === "open") {- openDataImmediately(node);- return;- }- if (!existingSameTableTab) return;- queryStore.switchTab(existingSameTableTab.id);- if (action === "activate") return;- await queryStore.refreshDataTab(existingSameTableTab.id);-}+const isActiveConnectionScope = computed(() => !!activeNode.value.connectionId && connectionStore.activeConnectionId === activeNode.value.connectionId);-function findExistingSameTableDataTab() {- const node = props.node;- if (node.type !== "table" || !hasNodeDatabaseContext(node)) return undefined;- const config = connectionStore.getConfig(node.connectionId);- const tableSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);- return queryStore.tabs.find((tab) => tab.mode === "data" && tab.connectionId === node.connectionId && tab.database === node.database && (tab.tableMeta?.catalog || "") === (node.catalog || "") && (tab.schema || "") === (tableSchema || "") && (tab.tableMeta?.tableName || tab.title) === node.label);-}+const selectionVisual = computed(() => {+ const selected = connectionStore.selectedTreeNodeId === activeNode.value.id;+ const multiSelected = connectionStore.selectedTreeNodeIdsSet.has(activeNode.value.id);+ return {+ selected,+ multiSelected,+ rowSelected: selected || multiSelected,+ usesSelectionSetHighlight: connectionStore.connectionMultiSelectActive || connectionStore.selectedTreeNodeIds.length > 1,+ };+});-function openMongoTreeData(node: TreeNode) {- if (!node.connectionId || !node.database) return;- if (node.type === "mongo-gridfs") {- queryStore.openMongoGridFs(node.connectionId, node.database);- return;- }- const tabTitle = `${node.database}.${node.label}`;- if (node.type === "mongo-bucket") {- queryStore.openMongoBucket(node.connectionId, node.database, node.label);- return;- }- if (node.type !== "mongo-collection") return;- const tab = queryStore.createTab(node.connectionId, node.database, tabTitle, "mongo");- queryStore.updateSql(tab, node.label);-}--async function openSavedSqlFile() {- const node = props.node;- if (node.type !== "saved-sql-file" || !node.savedSqlId) return;- const file = await savedSqlStore.ensureFileContent(node.savedSqlId);- if (!file) return;- queryStore.openSavedSql(file);- connectionStore.activeConnectionId = file.connectionId;- void savedSqlStore.recordFileUsage(file.id);-}--async function openObjectBrowser() {- const node = props.node;- if (!node.connectionId) return;- try {- await connectionStore.ensureConnected(node.connectionId);- connectionStore.activeConnectionId = node.connectionId;-- if (hasTreeNodeDatabaseContext(node)) {- queryStore.openObjectBrowser(node.connectionId, node.database, node.schema, node.catalog);- return;- }-- const connection = connectionStore.getConfig(node.connectionId);- if (!connection) return;- const options = await getDatabaseOptions(node.connectionId);- const database = resolveDefaultDatabase(connection, options);- if (database) {- queryStore.openObjectBrowser(node.connectionId, database);- } else {- await toggle();- }- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- openDriverStoreForInstallError(e?.message || String(e));- }-}--async function openUserAdmin() {- const node = props.node;- if (!node.connectionId) return;- try {- await connectionStore.ensureConnected(node.connectionId);- connectionStore.activeConnectionId = node.connectionId;- queryStore.openUserAdmin(node.connectionId);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--async function openProcessList() {- const node = props.node;- if (!node.connectionId) return;- try {- await connectionStore.ensureConnected(node.connectionId);- connectionStore.activeConnectionId = node.connectionId;- queryStore.openProcessList(node.connectionId);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--async function openServerDashboard() {- const node = props.node;- if (!node.connectionId) return;- try {- await connectionStore.ensureConnected(node.connectionId);- connectionStore.activeConnectionId = node.connectionId;- if (currentDatabaseType() === "postgres") {- queryStore.openPostgresDashboard(node.connectionId);- } else {- queryStore.openMysqlDashboard(node.connectionId);- }- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--async function openDamengJobAdmin() {- const node = props.node;- if (!node.connectionId) return;- try {- await connectionStore.ensureConnected(node.connectionId);- connectionStore.activeConnectionId = node.connectionId;- queryStore.openDamengJobAdmin(node.connectionId);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--function scheduleOpenData(node: TreeNode) {- emit("open-data", node, true, "default", openData);-}--function openDataImmediately(node: TreeNode = props.node) {- emit("open-data", node, false, "default", openData);-}--function openDataInNewTabImmediately(node: TreeNode = props.node) {- emit("open-data", node, false, "new-tab", (target, request) => openData(target, request, "new-tab"));-}--async function openData(node: TreeNode, request?: SidebarDataOpenRequest, openMode: DataTabOpenMode = "default") {- if (!(node.type === "table" || node.type === "view" || node.type === "materialized_view") || !hasNodeDatabaseContext(node)) return;- const config = connectionStore.getConfig(node.connectionId);- const traceId = uuid().slice(0, 8);- const startedAt = performance.now();- let lastPhaseAt = startedAt;- const elapsed = () => `${Math.round(performance.now() - startedAt)}ms`;- const openDataLog = (level: "info" | "warn" | "error" | "debug", event: string, details: Record<string, unknown>) => {- appendDebugLog(level, `[DBX][openData:${event}]`, details);- };- const logPhase = (phase: string, extra: Record<string, unknown> = {}) => {- const now = performance.now();- openDataLog("info", "phase", {- traceId,- phase,- deltaMs: Math.round(now - lastPhaseAt),- totalMs: Math.round(now - startedAt),- ...extra,- });- lastPhaseAt = now;- };- openDataLog("info", "start", {- traceId,- type: node.type,- dbType: config?.db_type,- openMode,- });- const tableSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);- const tableType = node.type === "view" ? "VIEW" : node.type === "materialized_view" ? "MATERIALIZED_VIEW" : (node.tableType ?? "TABLE");- const querySchema = config ? connectionObjectTreeQuerySchema(config, node.database, tableSchema) : (tableSchema ?? "");- const effectiveDbType = effectiveDatabaseTypeForConnection(config);- const metadataDatabaseType = effectiveDbType || config?.db_type || "";- const dataTabTarget = {- connectionId: node.connectionId,- database: node.database,- schema: tableSchema,- catalog: node.catalog,- tableName: node.label,- };- const existingDataTabCandidate = findExistingDataTabCandidate(queryStore.tabs, dataTabTarget, { openMode, reuseDataTab: settingsStore.editorSettings.reuseDataTab });- const existingSameTableTab = existingDataTabCandidate?.match === "same-table" ? existingDataTabCandidate.tab : undefined;- const resetReusedDataTabState = (tab: (typeof queryStore.tabs)[number]) => {- tab.title = node.label;- tab.schema = tableSchema;- tab.whereInput = undefined;- tab.orderByInput = undefined;- tab.previewSql = undefined;- tab.resultSortColumn = undefined;- tab.resultSortColumnIndex = undefined;- tab.resultSortDirection = undefined;- tab.resultSortMode = undefined;- tab.resultLocalSortOriginalRows = undefined;- tab.resultLocalSortOriginalMongoDocuments = undefined;- tab.resultSortedSql = undefined;- tab.resultPageSql = undefined;- tab.resultPageLimit = undefined;- tab.resultPageOffset = undefined;- tab.resultTotalRowCount = undefined;- tab.resultTotalRowCountLoading = undefined;- tab.queryAnalysis = undefined;- tab.querySourceColumns = undefined;- tab.queryEditabilityReason = undefined;- };-- if (existingSameTableTab && canActivateExistingDataTableTab(existingSameTableTab, { activateExecuting: false })) {- queryStore.switchTab(existingSameTableTab.id);- logPhase("existing-tab-activated", { table: node.label });- return;- }-- const tabId = (() => {- if (existingDataTabCandidate) {- queryStore.switchTab(existingDataTabCandidate.tab.id);- resetReusedDataTabState(existingDataTabCandidate.tab);- return existingDataTabCandidate.tab.id;- }- return queryStore.createTab(node.connectionId, node.database, node.label, "data", tableSchema);- })();- openDataLog("info", "tab-created", { traceId, tabId, elapsed: elapsed() });- logPhase("tab-created", { tabId });-- // Cancel any previous execution on this tab before starting a new one- const existingTab = queryStore.tabs.find((t) => t.id === tabId);- if (existingTab?.isExecuting && existingTab.executionId) {- await queryStore.cancelTabExecution(tabId);- logPhase("previous-execution-cancelled", { tabId });- }-- const openDataId = uuid();- // Clear previous result so DataGrid doesn't show its internal loading overlay (without stop button)- const tab = queryStore.tabs.find((t) => t.id === tabId);- if (tab) {- tab.result = undefined;- tab.results = undefined;- }- const existingTableMeta = tab?.tableMeta;- const existingTableMetaAgeMs = tab?.tableMetaUpdatedAt ? Date.now() - tab.tableMetaUpdatedAt : Number.POSITIVE_INFINITY;- const sharedCachedTableMeta = config- ? getCachedTableMetadata({- connectionId: node.connectionId,- database: node.database,- schema: querySchema,- tableName: node.label,- tableType,- databaseType: metadataDatabaseType,- driverProfile: config.driver_profile || config.db_type,- catalog: node.catalog,- })- : undefined;- const tabCachedTableMeta =- existingTableMeta?.tableName === node.label && (existingTableMeta.catalog || "") === (node.catalog || "") && existingTableMeta.schema === tableSchema && existingTableMeta.tableType === tableType && existingTableMeta.columns.length > 0 && existingTableMetaAgeMs < DATA_TAB_METADATA_TTL_MS- ? existingTableMeta- : undefined;- const cachedTableMeta = sharedCachedTableMeta ? tableMetadataToDataTabMeta(sharedCachedTableMeta.metadata, tableSchema) : tabCachedTableMeta;- const cachedTableMetaAgeMs = sharedCachedTableMeta?.ageMs ?? existingTableMetaAgeMs;- const cachedTableMetaSource = sharedCachedTableMeta ? "shared" : tabCachedTableMeta ? "tab" : undefined;- queryStore.setTableMeta(- tabId,- cachedTableMeta ?? {- catalog: node.catalog,- database: node.database,- schema: tableSchema,- tableName: node.label,- tableType,- columns: [],- primaryKeys: [],- },- );- queryStore.setExecutingWithId(tabId, openDataId);- request?.registerCancel(async () => {- const current = queryStore.tabs.find((item) => item.id === tabId);- if (current?.isExecuting && current.executionId === openDataId) {- await queryStore.cancelTabExecution(tabId);- }- });- logPhase("state-prepared", { tabId });-- // Yield to Vue's scheduler so the new tab becomes visible in the UI (tab- // bar activates, content area switches) before the first blocking network- // call. Without this the entire openData flow runs synchronously before the- // browser paints, making the UI feel frozen on each table click.- await nextTick();-- // Helper to check if this openData call is still active (not superseded by a newer click)- const isActive = () => (request?.isCurrent() ?? true) && queryStore.tabs.find((t) => t.id === tabId)?.executionId === openDataId;- const canApplyTableMetadata = () =>- canApplyDataTabMetadata(- queryStore.tabs.find((t) => t.id === tabId),- dataTabTarget,- request?.signal,- );-- try {- openDataLog("info", "ensure-connected:start", { traceId, elapsed: elapsed() });- await connectionStore.ensureConnected(node.connectionId);- if (!isActive()) {- logPhase("superseded-after-ensure-connected", { tabId });- return;- }- openDataLog("info", "ensure-connected:done", { traceId, elapsed: elapsed() });- logPhase("ensure-connected", { tabId });- if (!config) throw new Error("Connection config not found");-- const limit = tableOpenPageLimit();- const refreshTableMetaInBackground = async () => {- const metadataStartedAt = performance.now();- openDataLog("info", "metadata:start", {- traceId,- elapsed: elapsed(),- });- try {- const loadedMetadata = await loadTableMetadata({- connectionId: node.connectionId,- database: node.database,- schema: querySchema,- tableName: node.label,- tableType,- databaseType: metadataDatabaseType,- driverProfile: config.driver_profile || config.db_type,- catalog: node.catalog,- traceLogger: isDebugLoggingEnabled() ? (event) => openDataLog("debug", "metadata:trace", { sourceTraceId: traceId, ...event }) : undefined,- });- if (!canApplyTableMetadata()) {- openDataLog("info", "metadata:stale", {- traceId,- tabId,- columnCount: loadedMetadata.metadata.columns.length,- elapsed: elapsed(),- });- return;- }- const nextTableMeta = tableMetadataToDataTabMeta(loadedMetadata.metadata, tableSchema);- queryStore.setTableMeta(tabId, nextTableMeta);- openDataLog("info", "metadata:done", {- traceId,- tabId,- columnCount: nextTableMeta.columns.length,- primaryKeyCount: nextTableMeta.primaryKeys.length,- cacheStatus: loadedMetadata.cacheStatus,- ageMs: Math.round(loadedMetadata.ageMs),- elapsed: elapsed(),- metadataMs: Math.round(performance.now() - metadataStartedAt),- });- } catch (error) {- openDataLog("warn", "metadata:error", { traceId, tabId, elapsed: elapsed(), error });- }- };- const shouldRefreshTableMeta = !cachedTableMeta;- if (cachedTableMeta) {- openDataLog("info", "metadata:cache-hit", {- traceId,- tabId,- columnCount: cachedTableMeta.columns.length,- primaryKeyCount: cachedTableMeta.primaryKeys.length,- source: cachedTableMetaSource,- ageMs: Math.round(cachedTableMetaAgeMs),- elapsed: elapsed(),- });- } else {- logPhase("metadata-deferred", { tabId });- }-- // Check if superseded by a newer openData call- if (!isActive()) {- logPhase("superseded-before-build-sql", { tabId });- return;- }-- const columns = cachedTableMeta?.columns ?? [];- const primaryKeys = cachedTableMeta?.primaryKeys ?? [];- const includeRowId = usesSyntheticRowIdKey(effectiveDbType, primaryKeys, tableType);- const sql = await buildTableSelectSql({- databaseType: effectiveDbType,- identifierQuote: connectionStore.connectionIdentifierQuote?.(node.connectionId),- schema: tableSchema,- database: node.database,- tableName: node.label,- tableType,- catalog: node.catalog,- columns: columns.map((column) => column.name),- primaryKeys,- limit,- includeRowId,- });- openDataLog("info", "sql-built", {- traceId,- primaryKeyCount: primaryKeys.length,- includeRowId,- sqlLength: sql.length,- elapsed: elapsed(),- });- logPhase("sql-built", { tabId, columnCount: columns.length, primaryKeyCount: primaryKeys.length });- queryStore.updateSql(tabId, sql);- logPhase("sql-updated", { tabId });-- openDataLog("info", "execute:start", { traceId, tabId, elapsed: elapsed() });- await queryStore.executeTabSql(tabId, sql, {- sourceTraceId: traceId,- skipEnsureConnected: true,- pagination: { limit, offset: 0 },- });- openDataLog("info", "execute:done", { traceId, tabId, elapsed: elapsed() });- logPhase("execute-tab-sql", { tabId });- if (shouldRefreshTableMeta && canApplyTableMetadata()) {- void refreshTableMetaInBackground();- logPhase("metadata-started", { tabId });- }- } catch (e: any) {- if (!isActive()) {- logPhase("superseded-after-error", { tabId });- return;- }- openDataLog("error", "error", { traceId, elapsed: elapsed(), error: e });- logPhase("error", { tabId });- queryStore.setErrorResult(tabId, e);- }-}--async function newQuery() {- const node = props.node;- if (!node.connectionId) return;- try {- await connectionStore.ensureConnected(node.connectionId);- connectionStore.activeConnectionId = node.connectionId;- if (hasTreeNodeDatabaseContext(node)) {- if (node.type === "table" || node.type === "view" || node.type === "materialized_view") {- await newSelectTemplate();- return;- }- queryStore.createTab(node.connectionId, node.database, undefined, "query", node.schema);- return;- }- const connection = connectionStore.getConfig(node.connectionId);- if (!connection) return;- const options = await getDatabaseOptions(node.connectionId);- queryStore.createTab(node.connectionId, resolveDefaultDatabase(connection, options), undefined, "query");- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- openDriverStoreForInstallError(e?.message || String(e));- }-}--// SQL template helpers have been extracted to @/lib/tableSqlTemplates.ts-// ---- Template actions ------function openRedisInstanceInfo() {- const node = props.node;- if (!node.connectionId) return;- const config = connectionStore.getConfig(node.connectionId);- const dbName = config?.name || "Redis";- queryStore.createTab(node.connectionId, "0", `${dbName} - ${t("contextMenu.instanceInfo")}`, "redis-dashboard");-}--async function loadTemplateContext(allowView = false) {- const node = props.node;- if (!node.connectionId || !hasTreeNodeDatabaseContext(node)) return null;- const isTableNode = node.type === "table";- const isReadableObject = isTableNode || (allowView && (node.type === "view" || node.type === "materialized_view"));- if (!isReadableObject) return null;-- await connectionStore.ensureConnected(node.connectionId);- connectionStore.activeConnectionId = node.connectionId;- const config = connectionStore.getConfig(node.connectionId);- const dbType = config ? effectiveDatabaseTypeForConnection(config) : undefined;- const tableSchema = node.schema || node.database;- let columns: ColumnInfo[] = [];- try {- const querySchema = connectionObjectTreeQuerySchema(config, node.database, tableSchema);- columns = await api.getColumns(node.connectionId, node.database, querySchema, node.label);- } catch (e) {- console.warn("[DBX][tableSqlTemplate:getColumns:error]", e);- }-- let tableType = node.tableType;- if (dbType === "tdengine") {- try {- const querySchema = connectionObjectTreeQuerySchema(config, node.database, tableSchema);- const tables = await api.listTables(node.connectionId, node.database, querySchema, node.label, 200);- const matched = tables.find((table) => table.name.toLowerCase() === node.label.toLowerCase());- if (matched?.table_type) tableType = matched.table_type;- } catch (e) {- console.warn("[DBX][tableSqlTemplate:listTables:error]", e);- }- }-- return { node, dbType, tableSchema, columns, tableType };-}--function openSqlTemplateTab(connectionId: string, database: string, schema: string | undefined, sql: string, title?: string) {- const tabId = queryStore.createTab(connectionId, database, title, "query", schema);- queryStore.updateSql(tabId, sql);-}--async function newSelectTemplate() {- try {- const context = await loadTemplateContext(true);- if (!context) return;- const sql = buildTableSelectTemplate({- databaseType: context.dbType,- schema: context.tableSchema,- tableName: context.node.label,- columns: context.columns,- });- openSqlTemplateTab(context.node.connectionId!, context.node.database!, context.node.schema, sql);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--async function newInsertTemplate() {- try {- const context = await loadTemplateContext(false);- if (!context) return;- const sql = buildTableInsertTemplate({- databaseType: context.dbType,- schema: context.tableSchema,- tableName: context.node.label,- columns: context.columns,- tableType: context.tableType,- });- openSqlTemplateTab(context.node.connectionId!, context.node.database!, context.node.schema, sql);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--async function newUpdateTemplate() {- try {- const context = await loadTemplateContext(false);- if (!context) return;- const sql = buildTableUpdateTemplate({- databaseType: context.dbType,- schema: context.tableSchema,- tableName: context.node.label,- columns: context.columns,- });- openSqlTemplateTab(context.node.connectionId!, context.node.database!, context.node.schema, sql);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--async function newDeleteTemplate() {- try {- const context = await loadTemplateContext(false);- if (!context) return;- const sql = buildTableDeleteTemplate({- databaseType: context.dbType,- schema: context.tableSchema,- tableName: context.node.label,- columns: context.columns,- });- openSqlTemplateTab(context.node.connectionId!, context.node.database!, context.node.schema, sql);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--async function generateDdlTemplate() {- const node = props.node;- if (!node.connectionId || !hasTreeNodeDatabaseContext(node)) return;- if (node.type !== "table" && node.type !== "view" && node.type !== "materialized_view") return;- try {- await connectionStore.ensureConnected(node.connectionId);- connectionStore.activeConnectionId = node.connectionId;- const schema = node.schema || node.database;- let ddl: string;- if (node.type === "table") {- ddl = await api.getTableDdl(node.connectionId, node.database, schema, node.label, undefined, node.catalog);- } else if (node.type === "materialized_view") {- ddl = await api.getTableDdl(node.connectionId, node.database, schema, node.label, "MATERIALIZED_VIEW", node.catalog);- } else {- const result = await api.getObjectSource(node.connectionId, node.database, schema, node.label, "VIEW");- ddl = await buildViewDdl({- databaseType: currentDatabaseType(),- schema,- name: node.label,- source: result.source,- });- }- const formatted = await formatSqlForDisplay(ddl, sqlFormatDialectForDbType(currentDatabaseType()), settingsStore.editorSettings.sqlFormatter);- openSqlTemplateTab(node.connectionId, node.database, node.schema, formatted, `DDL - ${node.label}`);- } catch (e: any) {- toast(e?.message || String(e), 5000);- }-}--async function setNodeAsDefaultDatabase() {- const node = props.node;- if (!node.connectionId || !node.database) return;- try {- await connectionStore.setDefaultDatabase(node.connectionId, node.database);- } catch (e: any) {- toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000);- }-}--async function clearNodeDefaultDatabase() {- const node = props.node;- if (!node.connectionId) return;- try {- await connectionStore.clearDefaultDatabase(node.connectionId);- } catch (e: any) {- toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000);- }-}--async function refresh() {- try {- await connectionStore.refreshTreeNode(props.node);- } catch (e: any) {- toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- openDriverStoreForInstallError(e?.message || String(e));- }-}--function connectionDeleteTargets() {- if (showDeleteConfirm.value && connectionDeleteTargetSnapshot.value.length) return connectionDeleteTargetSnapshot.value;- return selectedConnectionDeleteTargets(props.node, selectedTreeNodesInVisibleOrder());-}--function connectionDeleteMenuLabel(): string {- const count = connectionDeleteTargets().length;- return count > 1 ? t("contextMenu.deleteSelectedConnections", { count }) : t("contextMenu.deleteConnection");-}--function connectionDuplicateTargets() {- return selectedConnectionDuplicateTargets(props.node, selectedTreeNodesInVisibleOrder());-}--function connectionDuplicateMenuLabel(): string {- const count = connectionDuplicateTargets().length;- return count > 1 ? t("contextMenu.duplicateSelectedConnections", { count }) : t("contextMenu.duplicateConnection");-}--function connectionDeleteConfirmMessage(): string {- const targets = connectionDeleteTargets();- return targets.length > 1 ? t("contextMenu.confirmDeleteSelectedMessage", { count: targets.length }) : t("contextMenu.confirmDeleteMessage", { name: targets[0]?.label || sidebarFormTarget.value?.label || props.node.label });-}--function deleteConnection() {- const targets = selectedConnectionDeleteTargets(props.node, selectedTreeNodesInVisibleOrder());- if (!targets.length) return;- connectionDeleteTargetSnapshot.value = targets.slice();- showDeleteConfirm.value = true;-}--async function confirmDelete() {- const targets = connectionDeleteTargets();- if (!targets.length) return;- const connectionIds = targets.map((target) => target.connectionId);- try {- await connectionStore.removeConnections(connectionIds);- for (const connectionId of connectionIds) {- connectionStore.disconnect(connectionId).catch((error) => {- console.warn("[DBX][connection:delete:disconnect-failed]", { connectionId, error });- });- }- toast(targets.length > 1 ? t("connection.deletedSelected", { count: targets.length }) : t("connection.deleted"), 2000);- } catch (e: any) {- toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000);- }-}--async function copyName() {- updateTreeClipboardForNodes([props.node]);- try {- await copyToClipboard(copyNameForTreeNode(props.node));- toast(t("connection.copied"), 2000);- } catch (e: any) {- toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);- }-}--async function copyFinalProxyPort() {- const connectionId = props.node.connectionId;- const config = connectionId ? connectionStore.getConfig(connectionId) : undefined;- if (!config || !hasEnabledTransportLayers(config)) return;-- try {- const port = await api.connectionFinalProxyPort(config);- await copyToClipboard(String(port));- toast(t("contextMenu.finalProxyPortCopied", { port }), 2000);- } catch (e: any) {- toast(t("grid.copyFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- }-}--async function copySelectedNames() {- const selectedNodes = selectedTreeNodesInVisibleOrder();- const nodes = selectedNodes.length > 1 && selectedNodes.some((node) => node.id === props.node.id) ? selectedNodes : [props.node];- const connectionTargets = selectedConnectionClipboardTargets(props.node, nodes);- if (connectionTargets.length > 0) {- const copiedCount = connectionStore.copyConnectionsToTreeClipboard(connectionTargets.map((node) => node.connectionId));- if (copiedCount > 0) toast(t("connection.copied"), 2000);- return;- }- updateTreeClipboardForNodes(nodes);- try {- await copyToClipboard(nodes.map(copyNameForTreeNode).join("\n"));- toast(t("connection.copied"), 2000);- } catch (e: any) {- toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);- }-}--function updateTreeClipboardForNodes(nodes: TreeNode[]) {- const tableNodes = nodes.filter((node): node is DuplicateStructureSource => node.type === "table" && !!node.connectionId && !!node.database && typeof node.label === "string");- if (tableNodes.length === 0) {- connectionStore.treeClipboard = null;- return;- }- connectionStore.treeClipboard = {- kind: "table-copy",- tables: tableNodes.map((node) => ({- connectionId: node.connectionId,- database: node.database,- schema: node.schema,- tableName: node.label,- })),- };-}--async function duplicateConnection() {- const targets = connectionDuplicateTargets();- if (!targets.length) return;- let duplicatedCount = 0;- for (const target of targets) {- const config = connectionStore.getConfig(target.connectionId);- if (!config) continue;- const newConfig = { ...config, id: uuid(), name: `${config.name} (Copy)` };- await connectionStore.addConnection(newConfig, connectionStore.groupIdForConnection(target.connectionId));- duplicatedCount += 1;- }- if (!duplicatedCount) return;- toast(duplicatedCount > 1 ? t("connection.duplicatedSelected", { count: duplicatedCount }) : t("connection.duplicated"), 2000);-}--// --- Table Management Operations ----const pasteTableDataCopySupported = computed(() => supportsWholeRowTableDataCopy(currentDatabaseType()));--// --- Extension Management ----function openInstallExtensionDialog(node: TreeNode) {- emit("open-install-extension", node);-}--// --- Procedure / Function Management ----function dropObjectSqlOptions(): DropObjectSqlOptions | null {- return dropObjectSqlOptionsForNode(props.node);-}--function dropObjectSqlOptionsForNode(node: TreeNode): DropObjectSqlOptions | null {- if (node.type !== "view" && node.type !== "materialized_view" && node.type !== "procedure" && node.type !== "function") return null;- return {- databaseType: tableStructureDatabaseTypeForNode(node),- objectType: node.type === "view" ? "VIEW" : node.type === "materialized_view" ? "MATERIALIZED_VIEW" : node.type === "procedure" ? "PROCEDURE" : "FUNCTION",- schema: node.schema,- name: node.objectName || node.label,- signature: node.signature,- };-}--function tableChildDropObjectType(type: TreeNodeType): TableChildObjectType | null {- if (type === "column") return "COLUMN";- if (type === "index") return "INDEX";- if (type === "fkey") return "FOREIGN_KEY";- if (type === "trigger") return "TRIGGER";- return null;-}--function tableChildDropObjectName(node: TreeNode): string {- if (node.type === "column") return node.meta && "name" in node.meta ? node.meta.name : node.label.replace(/\s+\(.+\)$/, "");- if (node.type === "index") return node.meta && "name" in node.meta ? node.meta.name : node.label.replace(/\s+\(.+\)$/, "");- if (node.type === "fkey") return node.meta && "name" in node.meta ? node.meta.name : node.label;- if (node.type === "trigger") return node.meta && "name" in node.meta ? node.meta.name : node.label.replace(/\s+\(.+\)$/, "");- return node.label;-}--function dropTableChildObjectSqlOptions(): DropTableChildObjectSqlOptions | null {- return dropTableChildObjectSqlOptionsForNode(props.node);-}--function dropTableChildObjectSqlOptionsForNode(node: TreeNode): DropTableChildObjectSqlOptions | null {- const objectType = tableChildDropObjectType(node.type);- if (!objectType || !node.tableName) return null;- const name = tableChildDropObjectName(node).trim();- if (!name) return null;- return {- databaseType: databaseTypeForNode(node),- objectType,- schema: node.schema,- tableName: node.tableName,- name,- };-}--const canDropTableChildObject = computed(() => {- return canDropTableChildObjectNode(props.node);-});--function canDropTableChildObjectNode(node: TreeNode): boolean {- const options = dropTableChildObjectSqlOptionsForNode(node);- if (!options) return false;- const capabilities = getTableStructureCapabilities(options.databaseType);- if (options.objectType === "COLUMN") return capabilities.dropColumn;- if (options.objectType === "INDEX") return capabilities.dropIndex;- return true;-}--function dropObjectMenuLabel(): string {- if (props.node.type === "view") return t("contextMenu.dropView");- if (props.node.type === "materialized_view") return t("contextMenu.dropView");- if (props.node.type === "procedure") return t("contextMenu.dropProcedure");- if (props.node.type === "function") return t("contextMenu.dropFunction");- return t("contextMenu.dropObject");-}--function dropObjectConfirmTitle(): string {- if (props.node.type === "view") return t("contextMenu.confirmDropViewTitle");- if (props.node.type === "materialized_view") return t("contextMenu.confirmDropViewTitle");- if (props.node.type === "procedure") return t("contextMenu.confirmDropProcedureTitle");- if (props.node.type === "function") return t("contextMenu.confirmDropFunctionTitle");- return t("contextMenu.confirmDropObjectTitle");-}--function dropObjectConfirmMessage(): string {- if (props.node.type === "view") return t("contextMenu.confirmDropViewMessage", { name: props.node.label });- if (props.node.type === "materialized_view") return t("contextMenu.confirmDropViewMessage", { name: props.node.label });- if (props.node.type === "procedure") return t("contextMenu.confirmDropProcedureMessage", { name: props.node.label });- if (props.node.type === "function") return t("contextMenu.confirmDropFunctionMessage", { name: props.node.label });- return t("contextMenu.confirmDropObjectMessage", { name: props.node.label });-}--function dropTableChildObjectMenuLabel(): string {- if (props.node.type === "column") return t("contextMenu.dropColumn");- if (props.node.type === "index") return t("contextMenu.dropIndex");- if (props.node.type === "fkey") return t("contextMenu.dropForeignKey");- if (props.node.type === "trigger") return t("contextMenu.dropTrigger");- return t("contextMenu.dropObject");-}--function dropTableChildObjectConfirmTitle(): string {- if (props.node.type === "column") return t("contextMenu.confirmDropColumnTitle");- if (props.node.type === "index") return t("contextMenu.confirmDropIndexTitle");- if (props.node.type === "fkey") return t("contextMenu.confirmDropForeignKeyTitle");- if (props.node.type === "trigger") return t("contextMenu.confirmDropTriggerTitle");- return t("contextMenu.confirmDropObjectTitle");-}--function dropTableChildObjectConfirmMessage(): string {- return t("contextMenu.confirmDropTableChildObjectMessage", {- name: tableChildDropObjectName(props.node),- table: props.node.tableName || "",- });-}--async function refreshDropObjectPreviewSql() {- const options = dropObjectSqlOptions();- dropObjectPreviewSql.value = "";- dropObjectPreviewSql.value = options ? await buildDropObjectSql(options).catch(() => "") : "";-}--async function refreshDropTableChildObjectPreviewSql() {- const options = dropTableChildObjectSqlOptions();- dropTableChildObjectPreviewSql.value = "";- dropTableChildObjectPreviewSql.value = options ? await buildDropTableChildObjectSql(options).catch(() => "") : "";-}--function openObjectSourceDialog(initialEditing: boolean) {- const node = props.node;- if (!node.connectionId || !node.database) return;- const objectType = objectSourceKindForTreeNode(node.type);- if (!objectType) return;- void connectionStore- .ensureConnected(node.connectionId)- .then(() => {- connectionStore.activeConnectionId = node.connectionId!;- emit("open-object-source", node, initialEditing);- })- .catch((e: any) => {- toast(e?.message || String(e), 5000);- });-}--function openProcedureExecution() {- const node = props.node;- if (node.type !== "procedure" || !node.connectionId || !node.database) return;- emit("open-procedure", node);-}--function requestDropObject() {- void refreshDropObjectPreviewSql();- showDropObjectConfirm.value = true;-}--function requestDropTableChildObject() {- if (!canDropTableChildObject.value) return;- void refreshDropTableChildObjectPreviewSql();- showDropTableChildObjectConfirm.value = true;-}--function canDropTreeNode(node: TreeNode): boolean {- if (isSqlServerLinkedNode(node)) return false;- if (node.type === "table") return !!node.connectionId && !!node.database;- if (node.type === "view" || node.type === "materialized_view" || node.type === "procedure" || node.type === "function") {- return !!node.connectionId && !!node.database && !!dropObjectSqlOptionsForNode(node);- }- if (canDropMongoIndexNode(node)) return true;- return canDropTableChildObjectNode(node);-}--function droppedTableObjectTypeForNode(node: TreeNode): "TABLE" | "VIEW" | "MATERIALIZED_VIEW" | null {- if (node.type === "table") return "TABLE";- if (node.type === "view") return "VIEW";- if (node.type === "materialized_view") return "MATERIALIZED_VIEW";- return null;-}--function closeDroppedTableObjectTabsForNode(node: TreeNode) {- const objectType = droppedTableObjectTypeForNode(node);- if (!objectType || !node.connectionId || !node.database) return;- const config = connectionStore.getConfig(node.connectionId);- const dataTabSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);- queryStore.closeDroppedTableObjectTabs({- connectionId: node.connectionId,- database: node.database,- schema: dataTabSchema,- schemaCandidates: [node.schema, dataTabSchema],- name: node.label,- objectType,- });-}--function tableDataRefreshTargetForNode(node: TreeNode) {- if (!node.connectionId || !node.database) return null;- const config = connectionStore.getConfig(node.connectionId);- const dataTabSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);- return {- connectionId: node.connectionId,- database: node.database,- schema: dataTabSchema,- schemaCandidates: [node.schema, dataTabSchema],- catalog: node.catalog,- name: node.label,- };-}--async function refreshMutatedTableDataTabsForNode(node: TreeNode) {- const target = tableDataRefreshTargetForNode(node);- if (!target) return;- try {- await queryStore.refreshDataTabsForTable(target);- } catch (error) {- console.warn("[DBX][table-data-refresh-after-mutation:error]", { target, error });- }-}--async function refreshMutatedTableDataTabsForNodes(nodes: readonly TreeNode[]) {- for (const target of nodes) {- await refreshMutatedTableDataTabsForNode(target);- }-}--function selectedBatchDropTargets(): TreeNode[] {- const selected = selectedTreeNodesInVisibleOrder();- if (selected.length <= 1 || !selected.some((node) => node.id === props.node.id)) return [];- const first = selected[0];- if (!first?.connectionId || !first.database || !selected.every((node) => node.type === first.type)) return [];- if (!selected.every((node) => node.connectionId === first.connectionId && node.database === first.database && canDropTreeNode(node))) {- return [];- }- return selected;-}--function selectedBatchTableTargets(): TreeNode[] {- const targets = selectedBatchDropTargets();- return targets.length > 1 && targets.every((node) => node.type === "table") ? targets : [];-}--function selectedBatchTruncateTargets(): TreeNode[] {- const targets = selectedBatchTableTargets();- return targets.every((node) => supportsTableTruncate(databaseTypeForNode(node))) ? targets : [];-}--function selectedBatchEmptyTargets(): TreeNode[] {- return selectedBatchTableTargets();-}--function selectedBatchIndexTableName(targets: TreeNode[]): string | null {- const first = targets[0];- if (!first) return null;- const table = first.tableName || first.label;- return table && targets.every((node) => (node.tableName || node.label) === table) ? table : null;-}--function batchDropMenuLabel(): string {- const targets = selectedBatchDropTargets();- if (targets.length > 1 && targets.every((node) => node.type === "index")) {- return t("contextMenu.batchDropIndexes", { count: targets.length });- }- return t("contextMenu.batchDrop", { count: targets.length });-}--function batchDropConfirmTitle(): string {- const targets = batchDropTargets.value;- if (targets.length > 1 && targets.every((node) => node.type === "index")) {- return t("contextMenu.confirmDropIndexTitle");- }- return t("contextMenu.confirmBatchDropTitle", { count: targets.length });-}--function batchDropConfirmMessage(): string {- const targets = batchDropTargets.value;- const table = selectedBatchIndexTableName(targets);- if (targets.length > 1 && targets.every((node) => node.type === "index") && table) {- return t("contextMenu.confirmDropBatchIndexesMessage", { count: targets.length, table });- }- return t("contextMenu.confirmBatchDropMessage", { count: targets.length });-}--function batchTruncateMenuLabel(): string {- return t("contextMenu.batchTruncate", { count: selectedBatchTruncateTargets().length });-}--function batchEmptyMenuLabel(): string {- return t("contextMenu.batchEmpty", { count: selectedBatchEmptyTargets().length });-}--function batchEmptyConfirmTitle(): string {- return t("contextMenu.confirmBatchEmptyTitle", { count: batchEmptyTargets.value.length });-}--function batchEmptyConfirmMessage(): string {- return t("contextMenu.confirmBatchEmptyMessage", { count: batchEmptyTargets.value.length });-}--function batchEmptyConfirmLabel(): string {- return t("contextMenu.batchEmpty", { count: batchEmptyTargets.value.length });-}--function batchTruncateConfirmTitle(): string {- return t("contextMenu.confirmBatchTruncateTitle", { count: batchTruncateTargets.value.length });-}--function batchTruncateConfirmMessage(): string {- return t("contextMenu.confirmBatchTruncateMessage", { count: batchTruncateTargets.value.length });-}--async function dropSqlForTreeNode(node: TreeNode, options?: { cascade?: boolean }): Promise<string | null> {- if (node.type === "table" && node.connectionId && node.database) {- return buildDropTableSql({- databaseType: databaseTypeForNode(node),- schema: node.schema,- tableName: node.label,- cascade: options?.cascade && supportsDropTableCascade(databaseTypeForNode(node)),- });- }- const objectOptions = dropObjectSqlOptionsForNode(node);- if (objectOptions) return buildDropObjectSql(objectOptions);- if (canDropMongoIndexNode(node)) {- return `db.getCollection("${(node.tableName || "").replace(/\\/g, "\\\\").replace(/"/g, '\\"')}").dropIndex(${JSON.stringify(mongoIndexNameForNode(node))})`;- }- const childOptions = dropTableChildObjectSqlOptionsForNode(node);- if (childOptions && canDropTableChildObjectNode(node)) return buildDropTableChildObjectSql(childOptions);- return null;-}--async function truncateSqlForTreeNode(node: TreeNode, options?: { cascade?: boolean }): Promise<string | null> {- if (node.type !== "table" || !node.connectionId || !node.database || !supportsTableTruncate(databaseTypeForNode(node))) return null;- return buildTruncateTableSql({- databaseType: databaseTypeForNode(node),- schema: node.schema,- tableName: node.label,- cascade: options?.cascade && supportsTruncateTableCascade(databaseTypeForNode(node)),- });-}--async function emptySqlForTreeNode(node: TreeNode): Promise<string | null> {- if (node.type !== "table" || !node.connectionId || !node.database) return null;- return buildEmptyTableSql({- databaseType: databaseTypeForNode(node),- schema: node.schema,- tableName: node.label,- });-}--async function refreshBatchDropPreviewSql() {- const targets = batchDropTargets.value;- const mongoIndexTargets = targets.filter(canDropMongoIndexNode);- if (mongoIndexTargets.length) {- batchDropPreviewSql.value = mongoIndexTargets.map((target) => mongoIndexDropPreview(target, mongoIndexNameForNode(target))).join("\n");- return;- }- const statements: string[] = [];- const useCascade = canBatchDropCascade.value && batchDropCascade.value;- for (const target of targets) {- const sql = await dropSqlForTreeNode(target, { cascade: useCascade });- if (sql) statements.push(sql);- }- batchDropPreviewSql.value = statements.join("\n");-}--async function refreshBatchTruncatePreviewSql() {- const targets = batchTruncateTargets.value;- const statements: string[] = [];- const useCascade = canBatchTruncateCascade.value && batchTruncateCascade.value;- for (const target of targets) {- const sql = await truncateSqlForTreeNode(target, { cascade: useCascade });- if (sql) statements.push(sql);- }- batchTruncatePreviewSql.value = statements.join("\n");-}--async function refreshBatchEmptyPreviewSql(targets: TreeNode[]) {- const statements: string[] = [];- for (const target of targets) {- const sql = await emptySqlForTreeNode(target);- if (sql) statements.push(sql);- }- batchEmptyPreviewSql.value = statements.join("\n");-}--function requestBatchDrop() {- const targets = selectedBatchDropTargets();- if (!targets.length) return;- batchDropTargets.value = targets.slice();- batchDropCascade.value = false;- void refreshBatchDropPreviewSql();- showBatchDropConfirm.value = true;-}--function requestBatchTruncate() {- const targets = selectedBatchTruncateTargets();- if (!targets.length) return;- batchTruncateTargets.value = targets.slice();- batchTruncateCascade.value = false;- void refreshBatchTruncatePreviewSql();- showBatchTruncateConfirm.value = true;-}--function requestBatchEmpty() {- const targets = selectedBatchEmptyTargets();- if (!targets.length) return;- batchEmptyTargets.value = targets.slice();- batchEmptyPreviewSql.value = "";- void refreshBatchEmptyPreviewSql(batchEmptyTargets.value)- .then(() => {- if (!batchEmptyPreviewSql.value.trim()) throw new Error("Empty table SQL preview is unavailable");- showBatchEmptyConfirm.value = true;- })- .catch((e: any) => {- batchEmptyTargets.value = [];- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- });-}--function requestDropSelectedNodes(): boolean {- const selected = selectedTreeNodesInVisibleOrder();- if (selected.length > 1 && selected.some((node) => node.id === props.node.id)) {- if (!selectedBatchDropTargets().length) return false;- requestBatchDrop();- return true;- }- return requestDropSelectedNode();-}--function requestDropSelectedNode(): boolean {- if (props.node.type === "table") {- dropTable();- return true;- }- if (props.node.type === "view" || props.node.type === "procedure" || props.node.type === "function") {- requestDropObject();- return true;- }- if (canDropMongoIndex.value) {- dropMongoIndex();- return true;- }- if (canDropTableChildObject.value) {- requestDropTableChildObject();- return true;- }- return false;-}--function nodeRenameObjectType(): RenameableObjectType | null {- if (props.node.type === "table") return "TABLE";- if (props.node.type === "view") return "VIEW";- if (props.node.type === "materialized_view") return "MATERIALIZED_VIEW";- if (props.node.type === "procedure") return "PROCEDURE";- if (props.node.type === "function") return "FUNCTION";- return null;-}--const canRenameObject = computed(() => {- const objectType = nodeRenameObjectType();- return !!objectType && (supportsObjectRename(currentDatabaseType(), objectType) || supportsSourceBackedRoutineRename(currentDatabaseType(), objectType as any));-});--function openRenameObjectDialog() {- claimTreeItemDialogOwnership();- routeTreeItemDialogController();- renameObjectName.value = props.node.label;- renameObjectError.value = "";- renameObjectPreviewSql.value = "";- showRenameObjectDialog.value = true;-}--async function executeTreeNodeSqlWithProductionGuard(node: Pick<TreeNode, "connectionId" | "database" | "schema">, sql: string, options: { database?: string; schema?: string } = {}) {- if (!node.connectionId) return undefined;- const database = options.database ?? node.database ?? "";- return executeWithProductionSqlGuard({- connection: connectionStore.getConfig(node.connectionId),- database,- sql,- source: t("production.sourceSidebar"),- execute: () => api.executeQuery(node.connectionId!, database, sql, options.schema ?? node.schema),- });-}--let renameObjectPreviewRequestId = 0;--async function refreshRenameObjectPreviewSql() {- const requestId = ++renameObjectPreviewRequestId;- const objectType = nodeRenameObjectType();- const newName = renameObjectName.value.trim();- if (!showRenameObjectDialog.value || !objectType || !newName || newName === props.node.label) {- renameObjectPreviewSql.value = "";- return;- }- if (supportsSourceBackedRoutineRename(currentDatabaseType(), objectType as any)) {- renameObjectPreviewSql.value = `-- Recreate ${objectType} from source, then drop the original object.`;- return;- }- try {- const sql = await buildRenameObjectSql({- databaseType: currentDatabaseType(),- objectType,- schema: props.node.schema,- oldName: props.node.label,- newName,- });- if (requestId === renameObjectPreviewRequestId) renameObjectPreviewSql.value = sql;- } catch {- if (requestId === renameObjectPreviewRequestId) renameObjectPreviewSql.value = "";- }-}--watch([showRenameObjectDialog, renameObjectName, () => props.node.label, () => props.node.schema, () => props.node.type, () => currentDatabaseType()], () => {- void refreshRenameObjectPreviewSql();-});--async function confirmRenameObject() {- const node = sidebarFormTarget.value ?? props.node;- const objectType = node.type === "table" ? "TABLE" : node.type === "view" ? "VIEW" : node.type === "materialized_view" ? "MATERIALIZED_VIEW" : node.type === "procedure" ? "PROCEDURE" : node.type === "function" ? "FUNCTION" : null;- const newName = renameObjectName.value.trim();- if (!objectType || !newName || newName === node.label || !node.connectionId || !node.database) return;- renameObjectError.value = "";- try {- const dbType = databaseTypeForNode(node);- await connectionStore.ensureConnected(node.connectionId);- if (supportsSourceBackedRoutineRename(dbType, objectType as any)) {- const schema = node.schema || node.database;- const source = await api.getObjectSource(node.connectionId, node.database, schema, node.objectName || node.label, objectType as any, node.signature);- const statements = await buildRoutineRenameObjectSourceStatements({- databaseType: dbType!,- objectType: objectType as any,- schema,- name: node.label,- newName,- source: source.source,- });- for (const sql of statements) {- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema });- }- } else {- const sql = await buildRenameObjectSql({- databaseType: dbType,- objectType,- schema: node.schema,- oldName: node.label,- newName,- });- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });- }- toast(t("contextMenu.renameObjectSuccess", { oldName: node.label, newName }), 3000);- showRenameObjectDialog.value = false;- await refreshTableList(node);- } catch (e: any) {- renameObjectError.value = e?.message || String(e);- }-}--async function confirmDropObject() {- const node = sidebarDangerTarget.value ?? props.node;- if (!node.connectionId || !node.database) return;- const options = dropObjectSqlOptionsForNode(node);- if (!options) return;- try {- await connectionStore.ensureConnected(node.connectionId);- const sql = dropObjectPreviewSql.value || (await buildDropObjectSql(options));- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });- const msgKey = node.type === "view" ? "contextMenu.dropViewSuccess" : node.type === "materialized_view" ? "contextMenu.dropViewSuccess" : node.type === "procedure" ? "contextMenu.dropProcedureSuccess" : "contextMenu.dropFunctionSuccess";- toast(t(msgKey, { name: node.label }), 3000);- closeDroppedTableObjectTabsForNode(node);- if (node.type === "view" || node.type === "materialized_view") {- connectionStore.removeTreeNode(node.id);- } else {- await refreshTableList(node);- }- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--async function confirmDropTableChildObject() {- const node = sidebarDangerTarget.value ?? props.node;- if (!node.connectionId || !node.database) return;- const options = dropTableChildObjectSqlOptionsForNode(node);- if (!options) return;- try {- await connectionStore.ensureConnected(node.connectionId);- const sql = dropTableChildObjectPreviewSql.value || (await buildDropTableChildObjectSql(options));- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });- toast(t("contextMenu.dropTableChildObjectSuccess", { name: options.name }), 3000);- connectionStore.removeTreeNode(node.id);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--async function confirmBatchDrop() {- const targets = batchDropTargets.value.slice();- if (!targets.length) return;- try {- const mongoIndexTargets = targets.filter(canDropMongoIndexNode);- if (mongoIndexTargets.length) {- const grouped = new Map<string, TreeNode[]>();- for (const target of mongoIndexTargets) {- const key = `${target.connectionId}:${target.database}:${target.tableName || ""}`;- const list = grouped.get(key) ?? [];- list.push(target);- grouped.set(key, list);- }- let droppedCount = 0;- for (const groupTargets of grouped.values()) {- const first = groupTargets[0];- if (!first?.connectionId || !first.database || !first.tableName) continue;- await connectionStore.ensureConnected(first.connectionId);- const names = groupTargets.map((target) => mongoIndexNameForNode(target));- const result = await api.mongoDropIndexes(first.connectionId, first.database, first.tableName, JSON.stringify(names.length === 1 ? names[0] : names), false);- const dropped = new Set(result.dropped_names);- droppedCount += result.dropped_names.length;- for (const target of groupTargets) {- if (dropped.has(mongoIndexNameForNode(target))) connectionStore.removeTreeNode(target.id);- }- }- toast(t("contextMenu.batchDropSuccess", { count: droppedCount }), 3000);- showBatchDropConfirm.value = false;- return;- }- const useCascade = batchDropCascade.value && targets.every((node) => node.type !== "table" || supportsDropTableCascade(databaseTypeForNode(node)));- for (const target of targets) {- if (!target.connectionId || !target.database) continue;- await connectionStore.ensureConnected(target.connectionId);- const sql = await dropSqlForTreeNode(target, { cascade: useCascade });- if (!sql) continue;- await executeTreeNodeSqlWithProductionGuard(target, sql, { database: target.database, schema: target.schema });- closeDroppedTableObjectTabsForNode(target);- connectionStore.removeTreeNode(target.id);- }- toast(t("contextMenu.batchDropSuccess", { count: targets.length }), 3000);- showBatchDropConfirm.value = false;- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--async function confirmBatchTruncate() {- const targets = batchTruncateTargets.value.slice();- if (!targets.length) return;- try {- const useCascade = batchTruncateCascade.value && targets.every((node) => supportsTruncateTableCascade(databaseTypeForNode(node)));- await runBatchTableTruncate(- targets,- async (target) => {- if (!target.connectionId || !target.database) return false;- await connectionStore.ensureConnected(target.connectionId);- const sql = await truncateSqlForTreeNode(target, { cascade: useCascade });- if (!sql) return false;- const result = await executeTreeNodeSqlWithProductionGuard(target, sql, { database: target.database, schema: target.schema });- return result === undefined ? false : undefined;- },- refreshMutatedTableDataTabsForNodes,- );- toast(t("contextMenu.batchTruncateSuccess", { count: targets.length }), 3000);- showBatchTruncateConfirm.value = false;- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--async function confirmBatchEmpty() {- const targets = batchEmptyTargets.value.slice();- if (!targets.length) return;- const asynchronousMutation = targets.every((target) => databaseTypeForNode(target) === "clickhouse");- const result = await runBatchTableEmpty(targets, async (target) => {- if (!target.connectionId || !target.database) throw new Error("Missing table connection context");- await connectionStore.ensureConnected(target.connectionId);- const sql = await emptySqlForTreeNode(target);- if (!sql) throw new Error("Empty table SQL is unavailable");- await executeTreeNodeSqlWithProductionGuard(target, sql, { database: target.database, schema: target.schema });- });- for (const failure of result.failed) {- console.error(`Failed to empty table "${failure.target.label}":`, failure.error);- }- const feedback = batchTableEmptyFeedback(result, asynchronousMutation);- if (feedback === "success") {- toast(t("contextMenu.batchEmptySuccess", { count: result.succeeded.length }), 3000);- } else if (feedback === "submitted") {- toast(t("contextMenu.batchEmptySubmitted", { count: result.succeeded.length }), 3000);- } else if (feedback === "submitted-partial") {- toast(t("contextMenu.batchEmptySubmittedPartial", { success: result.succeeded.length, failed: result.failed.length }), 5000);- } else {- toast(t("contextMenu.batchEmptyPartialFail", { success: result.succeeded.length, failed: result.failed.length }), 5000);- }- await refreshMutatedTableDataTabsForNodes(result.succeeded);- batchEmptyTargets.value = [];- showBatchEmptyConfirm.value = false;-}--const isTableNotView = computed(() => props.node.type === "table" && !isSqlServerLinkedNode(props.node));--const supportsTruncate = computed(() => {- return supportsTableTruncate(currentDatabaseType());-});--const canCreateTable = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return (props.node.type === "database" || props.node.type === "schema" || props.node.type === "group-tables") && !isSqlServerLinkedNode(props.node) && !!props.node.database && supportsTableStructureEditing(tableStructureDatabaseTypeForConnection(config));-});--const canCreateDatabase = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "connection" && canCreateConnectionNamespace(config);-});--const canCreateNacosNamespace = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "connection" && config?.db_type === "nacos" && !config.read_only;-});--const canEditNacosNamespace = computed(() => {- if (props.node.type !== "nacos-namespace" || !props.node.connectionId || !props.node.nacosNamespace) return false;- const config = connectionStore.getConfig(props.node.connectionId);- return config?.db_type === "nacos" && !config.read_only;-});--const isDuckDbConnection = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "connection" && connectionNamespaceCreationTarget(config) === "attach";-});--const isConnectionSchemaCreation = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "connection" && connectionNamespaceCreationTarget(config) === "schema";-});--const canSetCreateDatabaseCharset = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return connectionNamespaceCreationTarget(config) === "database" && supportsCreateDatabaseCharset(config?.db_type, config?.driver_profile);-});--const canDropDatabase = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "database" && !isSqlServerLinkedNode(props.node) && supportsDatabaseCreation(config?.db_type);-});--const databasePropertyGroups = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return editableDatabasePropertyGroups(config, props.node);-});--const canEditDatabaseProperties = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return canEditDatabasePropertiesForNode(config, props.node) && !isSqlServerLinkedNode(props.node);-});--const canEditDatabaseCharsetCollation = computed(() => databasePropertyGroups.value.includes("charsetCollation"));-const canEditDatabaseComment = computed(() => databasePropertyGroups.value.includes("databaseComment"));--const canDropMongoDatabase = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "mongo-db" && !!props.node.database && config?.driver_profile !== "mongodb-legacy";-});--const canDropMongoCollection = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "mongo-collection" && !!props.node.database && config?.driver_profile !== "mongodb-legacy";-});--function mongoIndexNameForNode(node: TreeNode): string {- if (node.type !== "index") return "";- return node.meta && "name" in node.meta ? node.meta.name : node.label.replace(/\s+\(.+\)$/, "");-}--function canDropMongoIndexNode(node: TreeNode): boolean {- if (node.type !== "index" || !node.connectionId || !node.database || !node.tableName) return false;- const config = connectionStore.getConfig(node.connectionId);- return config?.db_type === "mongodb" && config.driver_profile !== "mongodb-legacy" && mongoIndexNameForNode(node) !== "_id_";-}--const canDropMongoIndex = computed(() => canDropMongoIndexNode(props.node));--function mongoIndexDropPreview(node: Pick<TreeNode, "tableName">, indexName: string): string {- return `db.getCollection(${JSON.stringify(node.tableName || "")}).dropIndex(${JSON.stringify(indexName)})`;-}--const canDropAllMongoIndexes = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "mongo-collection" && !!props.node.database && config?.db_type === "mongodb" && config.driver_profile !== "mongodb-legacy";-});--function mongoDropAllIndexesPreview(node: Pick<TreeNode, "label">): string {- return `db.getCollection(${JSON.stringify(node.label)}).dropIndexes()`;-}--const canCreateSchema = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return canCreateDatabaseNodeNamespace(config, props.node) && !isSqlServerLinkedNode(props.node) && !connectionUsesDatabaseObjectTreeMode(config);-});--const canDropSchema = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "schema" && !isSqlServerLinkedNode(props.node) && usesTreeSchemaMode(effectiveDatabaseTypeForConnection(config)) && !connectionUsesDatabaseObjectTreeMode(config);-});--const canEditSchemaComment = computed(() => {- const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;- return props.node.type === "schema" && !!props.node.database && !config?.read_only && supportsSchemaComment(effectiveDatabaseTypeForConnection(config));-});--const canDropTableCascade = computed(() => props.node.type === "table" && supportsDropTableCascade(currentDatabaseType()));-const canTruncateTableCascade = computed(() => props.node.type === "table" && supportsTruncateTableCascade(currentDatabaseType()));-const canBatchDropCascade = computed(() => {- const targets = selectedBatchTableTargets();- return targets.length > 1 && targets.every((node) => supportsDropTableCascade(databaseTypeForNode(node)));-});-const canBatchTruncateCascade = computed(() => {- const targets = selectedBatchTruncateTargets();- return targets.length > 1 && targets.every((node) => supportsTruncateTableCascade(databaseTypeForNode(node)));-});--function tableAdminSqlOptions(options?: { cascade?: boolean }): TableAdminSqlOptions {- const result: TableAdminSqlOptions = {- databaseType: currentDatabaseType(),- schema: props.node.schema,- tableName: props.node.label,- };- if (options?.cascade) result.cascade = true;- return result;-}--function tableAdminSqlOptionsForNode(node: TreeNode, options?: { cascade?: boolean }): TableAdminSqlOptions {- const result: TableAdminSqlOptions = {- databaseType: databaseTypeForNode(node),- schema: node.schema,- tableName: node.label,- };- if (options?.cascade) result.cascade = true;- return result;-}--function dropTableSqlOptions(): TableAdminSqlOptions {- return tableAdminSqlOptions({ cascade: canDropTableCascade.value && dropTableCascade.value });-}--function truncateTableSqlOptions(): TableAdminSqlOptions {- return tableAdminSqlOptions({ cascade: canTruncateTableCascade.value && truncateTableCascade.value });-}--async function refreshDropTablePreviewSql() {- dropTablePreviewSql.value = "";- dropTablePreviewSql.value = await buildDropTableSql(dropTableSqlOptions()).catch(() => "");-}--async function refreshEmptyTablePreviewSql() {- emptyTablePreviewSql.value = "";- emptyTablePreviewSql.value = await buildEmptyTableSql(tableAdminSqlOptions()).catch(() => "");-}--async function refreshTruncateTablePreviewSql() {- truncateTablePreviewSql.value = "";- truncateTablePreviewSql.value = await buildTruncateTableSql(truncateTableSqlOptions()).catch(() => "");-}--function dropTable() {- dropTableCascade.value = false;- void refreshDropTablePreviewSql();- showDropTableConfirm.value = true;-}--async function refreshTableList(node: TreeNode) {- if (!node.connectionId || !node.database) return;- await connectionStore.refreshObjectListTreeNode(node.connectionId, node.database, node.schema);-}--async function confirmDropTable() {- const node = sidebarDangerTarget.value ?? props.node;- if (!node.connectionId || !node.database) return;- try {- await connectionStore.ensureConnected(node.connectionId);- const sql = dropTablePreviewSql.value || (await buildDropTableSql(tableAdminSqlOptionsForNode(node, { cascade: dropTableCascade.value && supportsDropTableCascade(databaseTypeForNode(node)) })));- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });- toast(t("contextMenu.dropTableSuccess", { name: node.label }), 3000);- closeDroppedTableObjectTabsForNode(node);- connectionStore.removeTreeNode(node.id);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--function emptyTable() {- void refreshEmptyTablePreviewSql();- showEmptyTableConfirm.value = true;-}--async function confirmEmptyTable() {- const node = sidebarDangerTarget.value ?? props.node;- if (!node.connectionId || !node.database) return;- try {- await connectionStore.ensureConnected(node.connectionId);- const sql = emptyTablePreviewSql.value || (await buildEmptyTableSql(tableAdminSqlOptionsForNode(node)));- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });- const messageKey = databaseTypeForNode(node) === "clickhouse" ? "contextMenu.emptyTableSubmitted" : "contextMenu.emptyTableSuccess";- toast(t(messageKey, { name: node.label }), 3000);- await refreshMutatedTableDataTabsForNode(node);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--function truncateTable() {- truncateTableCascade.value = false;- void refreshTruncateTablePreviewSql();- showTruncateTableConfirm.value = true;-}--async function confirmTruncateTable() {- const node = sidebarDangerTarget.value ?? props.node;- if (!node.connectionId || !node.database) return;- try {- await connectionStore.ensureConnected(node.connectionId);- const sql = truncateTablePreviewSql.value || (await buildTruncateTableSql(tableAdminSqlOptionsForNode(node, { cascade: truncateTableCascade.value && supportsTruncateTableCascade(databaseTypeForNode(node)) })));- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });- toast(t("contextMenu.truncateTableSuccess", { name: node.label }), 3000);- await refreshMutatedTableDataTabsForNode(node);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--async function refreshDropDatabasePreviewSql() {- if (props.node.type === "mongo-db") {- dropDatabasePreviewSql.value = `db.getSiblingDB(${JSON.stringify(props.node.label)}).dropDatabase();`;- return;- }- dropDatabasePreviewSql.value = "";- dropDatabasePreviewSql.value = await buildDropDatabaseSql({- databaseType: currentDatabaseType(),- name: props.node.label,- }).catch(() => "");-}--async function refreshDropSchemaPreviewSql() {- dropSchemaPreviewSql.value = "";- dropSchemaPreviewSql.value = await buildDropSchemaSql({- databaseType: currentDatabaseType(),- name: props.node.label,- }).catch(() => "");-}--function databasePropertyName(): string {- return props.node.database || props.node.label;-}--function resultColumnValue(result: { columns?: string[]; rows?: unknown[] }, names: string[]): string {- const firstRow = result.rows?.[0];- if (Array.isArray(firstRow)) {- const lowerNames = names.map((name) => name.toLowerCase());- const index = Math.max(0, result.columns?.findIndex((column) => lowerNames.includes(column.toLowerCase())) ?? 0);- return firstRow[index] == null ? "" : String(firstRow[index]);- }- if (firstRow && typeof firstRow === "object") {- const record = firstRow as Record<string, unknown>;- const key = Object.keys(record).find((column) => names.some((name) => name.toLowerCase() === column.toLowerCase()));- const value = key ? record[key] : undefined;- return value == null ? "" : String(value);- }- return "";-}--function databasePropertyEditOptions() {- if (!canEditDatabaseProperties.value) return null;- const base = {- databaseType: currentDatabaseType(),- driverProfile: props.node.connectionId ? connectionStore.getConfig(props.node.connectionId)?.driver_profile : undefined,- target: "database" as const,- name: databasePropertyName(),- };- if (canEditDatabaseCharsetCollation.value) {- return {- ...base,- charset: editDatabaseCharset.value,- collation: editDatabaseCollation.value,- };- }- if (canEditDatabaseComment.value) {- return {- ...base,- comment: editDatabaseCommentText.value,- };- }- return null;-}--async function refreshEditDatabasePropertiesPreviewSql() {- editDatabasePropertiesPreviewSql.value = "";- const options = databasePropertyEditOptions();- if (!options) return;- editDatabasePropertiesPreviewSql.value = await buildUpdateDatabasePropertiesSql(options).catch(() => "");-}--async function loadDatabaseCharsetProperties() {- const node = props.node;- if (!node.connectionId) return;- const sql = `SELECT DEFAULT_CHARACTER_SET_NAME AS charset, DEFAULT_COLLATION_NAME AS collation FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = '${databasePropertyName().replace(/'/g, "''")}';`;- const result = await api.executeQuery(node.connectionId, databasePropertyName(), sql, undefined, undefined, { maxRows: 1 });- const charset = resultColumnValue(result, ["charset", "DEFAULT_CHARACTER_SET_NAME"]);- const collation = resultColumnValue(result, ["collation", "DEFAULT_COLLATION_NAME"]);- if (charset) editDatabaseCharset.value = charset;- if (collation) editDatabaseCollation.value = collation;-}--async function loadDatabaseCommentProperty() {- const node = props.node;- if (!node.connectionId) return;- const sql = buildGetDatabaseCommentSql({- databaseType: currentDatabaseType(),- name: databasePropertyName(),- });- const result = await api.executeQuery(node.connectionId, databasePropertyName(), sql, undefined, undefined, { maxRows: 1 });- editDatabaseCommentText.value = resultColumnValue(result, ["comment"]);-}--async function openEditDatabasePropertiesDialog() {- const node = props.node;- if (!canEditDatabaseProperties.value || !node.connectionId) return;- editDatabasePropertiesLoading.value = true;- editDatabaseCharset.value = "utf8mb4";- editDatabaseCollation.value = "utf8mb4_unicode_ci";- editDatabaseCommentText.value = "";- editDatabasePropertiesPreviewSql.value = "";- createDatabaseCharsetOptions.value = fallbackCreateDatabaseCharset.charsets;- createDatabaseCollationsByCharset.value = fallbackCreateDatabaseCharset.collationsByCharset;- showEditDatabasePropertiesDialog.value = true;- try {- await connectionStore.ensureConnected(node.connectionId);- if (canEditDatabaseCharsetCollation.value) {- await loadCreateDatabaseCharsetMetadata("edit");- await loadDatabaseCharsetProperties().catch(() => undefined);- } else if (canEditDatabaseComment.value) {- await loadDatabaseCommentProperty().catch(() => undefined);- }- await refreshEditDatabasePropertiesPreviewSql();- } finally {- editDatabasePropertiesLoading.value = false;- }-}--async function confirmEditDatabaseProperties() {- const node = sidebarFormTarget.value ?? props.node;- const config = node.connectionId ? connectionStore.getConfig(node.connectionId) : undefined;- const propertyGroups = editableDatabasePropertyGroups(config, node);- if (!propertyGroups.length || !node.connectionId || editDatabasePropertiesLoading.value) return;- editDatabasePropertiesLoading.value = true;- try {- await connectionStore.ensureConnected(node.connectionId);- const base = {- databaseType: databaseTypeForNode(node),- driverProfile: config?.driver_profile,- target: "database" as const,- name: node.database || node.label,- };- const options = propertyGroups.includes("charsetCollation") ? { ...base, charset: editDatabaseCharset.value, collation: editDatabaseCollation.value } : propertyGroups.includes("databaseComment") ? { ...base, comment: editDatabaseCommentText.value } : null;- if (!options) return;- const sql = await buildUpdateDatabasePropertiesSql(options);- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database || node.label });- toast(t("contextMenu.editDatabasePropertiesSuccess", { name: node.label }), 3000);- showEditDatabasePropertiesDialog.value = false;- await connectionStore.loadDatabases(node.connectionId, { force: true });- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- } finally {- editDatabasePropertiesLoading.value = false;- }-}--watch([editDatabaseCharset, editDatabaseCollation, editDatabaseCommentText], () => {- if (showEditDatabasePropertiesDialog.value) void refreshEditDatabasePropertiesPreviewSql();-});--async function refreshSchemaCommentPreviewSql() {- if (!canEditSchemaComment.value) {- schemaCommentPreviewSql.value = "";- return;- }- schemaCommentPreviewSql.value = await buildUpdateDatabasePropertiesSql({- databaseType: currentDatabaseType(),- target: "schema",- name: props.node.schema || props.node.label,- comment: schemaCommentText.value,- }).catch(() => "");-}--watch(schemaCommentText, () => {- if (showEditSchemaCommentDialog.value) void refreshSchemaCommentPreviewSql();-});--function schemaCommentFromResult(result: { columns?: string[]; rows?: unknown[] }): string {- return resultColumnValue(result, ["comment"]);-}--async function openEditSchemaCommentDialog() {- const node = props.node;- if (!canEditSchemaComment.value || !node.connectionId || !node.database) return;- schemaCommentText.value = "";- schemaCommentLoading.value = true;- showEditSchemaCommentDialog.value = true;- try {- await connectionStore.ensureConnected(node.connectionId);- const sql = buildGetSchemaCommentSql({- databaseType: currentDatabaseType(),- name: node.schema || node.label,- });- const result = await api.executeQuery(node.connectionId, node.database, sql, node.schema, undefined, { maxRows: 1 });- schemaCommentText.value = schemaCommentFromResult(result);- await refreshSchemaCommentPreviewSql();- } catch {- schemaCommentText.value = "";- await refreshSchemaCommentPreviewSql();- } finally {- schemaCommentLoading.value = false;- }-}--async function confirmEditSchemaComment() {- const node = sidebarFormTarget.value ?? props.node;- if (!canEditSchemaComment.value || !node.connectionId || !node.database || schemaCommentLoading.value) return;- schemaCommentLoading.value = true;- try {- await connectionStore.ensureConnected(node.connectionId);- const sql = await buildUpdateDatabasePropertiesSql({- databaseType: databaseTypeForNode(node),- target: "schema",- name: node.schema || node.label,- comment: schemaCommentText.value,- });- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });- toast(t("contextMenu.editSchemaCommentSuccess", { name: node.label }), 3000);- showEditSchemaCommentDialog.value = false;- await connectionStore.loadSchemas(node.connectionId, node.database, { force: true });- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- } finally {- schemaCommentLoading.value = false;- }-}--async function openCreateDatabase() {- if (isDuckDbConnection.value) {- await createDuckDbAttachedDatabaseFile();- return;- }- openCreateDatabaseDialog();-}--function openCreateDatabaseDialog() {- createDatabaseName.value = "";- createDatabaseCharset.value = "utf8mb4";- createDatabaseCollation.value = "utf8mb4_unicode_ci";- createDatabaseUsers.value = [];- createDatabaseSelectedUsers.value = [];- createDatabaseUsersLoading.value = false;- createDatabaseAuthorizationPlan.value = undefined;- createDatabasePreviewSql.value = "";- createDatabaseAuthorizationResults.value = [];- createDatabaseCharsetOptions.value = fallbackCreateDatabaseCharset.charsets;- createDatabaseCollationsByCharset.value = fallbackCreateDatabaseCharset.collationsByCharset;- showCreateDatabaseDialog.value = true;- if (canSetCreateDatabaseCharset.value) {- void loadCreateDatabaseCharsetMetadata();- }- void loadCreateDatabaseUsers();-}--let createDatabaseUsersRequestId = 0;--async function loadCreateDatabaseUsers() {- const node = sidebarFormTarget.value ?? props.node;- if (!node.connectionId) return;- const connectionId = node.connectionId;- const requestId = ++createDatabaseUsersRequestId;- const requestOwner = sidebarTreeDialogOwner.value;- const requestIsActive = () => requestId === createDatabaseUsersRequestId && sidebarTreeDialogOwner.value === requestOwner && sidebarFormTarget.value?.connectionId === connectionId && showCreateDatabaseDialog.value;- const config = connectionStore.getConfig(node.connectionId);- const userProvider = resolveDatabaseUserAdminProviderForConnection(config);- if (!userProvider) return;- createDatabaseUsersLoading.value = true;- try {- await connectionStore.ensureConnected(connectionId);- try {- const result = await api.executeQuery(connectionId, "", userProvider.listUsersSql(), undefined, undefined, { maxRows: 5000 });- if (requestIsActive()) createDatabaseUsers.value = userProvider.parseUsers(result);- } catch (error) {- if (!userProvider.fallbackListUsersSql || !userProvider.parseFallbackUsers) throw error;- const result = await api.executeQuery(connectionId, "", userProvider.fallbackListUsersSql(), undefined, undefined, { maxRows: 5000 });- if (requestIsActive()) createDatabaseUsers.value = userProvider.parseFallbackUsers(result);- }- } catch (error: any) {- if (requestIsActive()) {- createDatabaseUsers.value = [];- toast(t("contextMenu.createDatabaseUsersLoadFailed", { message: error?.message || String(error) }), 5000);- }- } finally {- if (requestIsActive()) createDatabaseUsersLoading.value = false;- }-}--function createDatabaseUserKey(user: DatabaseUserIdentity): string {- return `${user.user}\u0000${user.host}`;-}--function createDatabaseUserLabel(user: DatabaseUserIdentity): string {- const node = sidebarFormTarget.value ?? props.node;- const provider = resolveDatabaseUserAdminProviderForConnection(connectionStore.getConfig(node.connectionId || ""));- return provider?.label(user) ?? user.user;-}--function createDatabaseUserSelected(user: DatabaseUserIdentity): boolean {- const key = createDatabaseUserKey(user);- return createDatabaseSelectedUsers.value.some((selected) => createDatabaseUserKey(selected) === key);-}--function toggleCreateDatabaseUser(user: DatabaseUserIdentity) {- const key = createDatabaseUserKey(user);- if (createDatabaseSelectedUsers.value.some((selected) => createDatabaseUserKey(selected) === key)) {- createDatabaseSelectedUsers.value = createDatabaseSelectedUsers.value.filter((selected) => createDatabaseUserKey(selected) !== key);- } else {- createDatabaseSelectedUsers.value = [...createDatabaseSelectedUsers.value, user];- }-}--function openConnectionNamespaceCreation() {- if (isConnectionSchemaCreation.value) {- openCreateSchemaDialog();- return;- }- void openCreateDatabase();-}--function connectionNamespaceCreationLabel() {- if (isDuckDbConnection.value) return t("contextMenu.createDuckDbFile");- if (isConnectionSchemaCreation.value) return t("contextMenu.createSchema");- return t("contextMenu.createDatabase");-}--function updateCreateDatabaseCharset(value: string) {- const previousCharset = createDatabaseCharset.value;- createDatabaseCharset.value = value;- createDatabaseCollation.value = nextCreateDatabaseCollation(value, previousCharset, createDatabaseCollation.value, createDatabaseCollationsByCharset.value);-}--function updateEditDatabaseCharset(value: string) {- const previousCharset = editDatabaseCharset.value;- editDatabaseCharset.value = value;- editDatabaseCollation.value = nextCreateDatabaseCollation(value, previousCharset, editDatabaseCollation.value, createDatabaseCollationsByCharset.value);-}--async function loadCreateDatabaseCharsetMetadata(target: "create" | "edit" = "create") {- const node = props.node;- if (!node.connectionId || createDatabaseCharsetLoading.value) return;- createDatabaseCharsetLoading.value = true;- try {- await connectionStore.ensureConnected(node.connectionId);- const [charsetResult, collationResult] = await Promise.all([api.executeQuery(node.connectionId, "", "SHOW CHARACTER SET", undefined, undefined, { maxRows: 1000 }), api.executeQuery(node.connectionId, "", "SHOW COLLATION", undefined, undefined, { maxRows: 10000 })]);- if (target === "create" && !showCreateDatabaseDialog.value) return;- if (target === "edit" && !showEditDatabasePropertiesDialog.value) return;- const metadata = parseCreateDatabaseCharsetMetadata(charsetResult, collationResult);- createDatabaseCharsetOptions.value = metadata.charsets;- createDatabaseCollationsByCharset.value = metadata.collationsByCharset;- const selectedCharset = target === "create" ? createDatabaseCharset.value : editDatabaseCharset.value;- if (!createDatabaseCharsetOptions.value.includes(selectedCharset) && createDatabaseCharsetOptions.value.length) {- if (target === "create") {- updateCreateDatabaseCharset(createDatabaseCharsetOptions.value[0]);- } else {- updateEditDatabaseCharset(createDatabaseCharsetOptions.value[0]);- }- } else {- if (target === "create") {- createDatabaseCollation.value = nextCreateDatabaseCollation(createDatabaseCharset.value, createDatabaseCharset.value, createDatabaseCollation.value, createDatabaseCollationsByCharset.value);- } else {- editDatabaseCollation.value = nextCreateDatabaseCollation(editDatabaseCharset.value, editDatabaseCharset.value, editDatabaseCollation.value, createDatabaseCollationsByCharset.value);- }- }- } catch {- createDatabaseCharsetOptions.value = fallbackCreateDatabaseCharset.charsets;- createDatabaseCollationsByCharset.value = fallbackCreateDatabaseCharset.collationsByCharset;- } finally {- createDatabaseCharsetLoading.value = false;- }-}--function openCreateNacosNamespaceDialog() {- createNacosNamespaceId.value = "";- createNacosNamespaceName.value = "";- createNacosNamespaceDesc.value = "";- showCreateNacosNamespaceDialog.value = true;-}--async function confirmCreateNacosNamespace() {- const node = sidebarFormTarget.value ?? props.node;- const namespaceName = createNacosNamespaceName.value.trim();- if (!node.connectionId || !namespaceName || createNacosNamespaceLoading.value) return;- createNacosNamespaceLoading.value = true;- try {- await api.nacosCreateNamespace(node.connectionId, {- namespaceId: createNacosNamespaceId.value.trim() || undefined,- namespaceName,- namespaceDesc: createNacosNamespaceDesc.value.trim() || namespaceName,- });- showCreateNacosNamespaceDialog.value = false;- await connectionStore.loadNacosNamespaces(node.connectionId, { force: true });- const liveNode = findSidebarActionTarget(connectionStore.treeNodes, node);- if (liveNode) liveNode.isExpanded = true;- toast(t("nacos.namespaceCreated", { name: namespaceName }), 3000);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- } finally {- createNacosNamespaceLoading.value = false;- }-}--function openEditNacosNamespaceDialog() {- editNacosNamespaceName.value = props.node.nacosNamespaceName || props.node.label;- editNacosNamespaceDesc.value = props.node.comment || "";- showEditNacosNamespaceDialog.value = true;-}--async function confirmEditNacosNamespace() {- const node = sidebarFormTarget.value ?? props.node;- const namespaceId = node.nacosNamespace?.trim() || "";- const namespaceName = editNacosNamespaceName.value.trim();- if (!node.connectionId || !namespaceId || !namespaceName || editNacosNamespaceLoading.value) return;- editNacosNamespaceLoading.value = true;- try {- await api.nacosUpdateNamespace(node.connectionId, {- namespaceId,- namespaceName,- namespaceDesc: editNacosNamespaceDesc.value.trim() || namespaceName,- });- showEditNacosNamespaceDialog.value = false;- await connectionStore.loadNacosNamespaces(node.connectionId, { force: true });- toast(t("nacos.namespaceUpdated", { name: namespaceName }), 3000);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);- } finally {- editNacosNamespaceLoading.value = false;- }-}--function ensureDuckDbFileExtension(path: string): string {- return /\.(duckdb|db)$/i.test(path) ? path : `${path}.duckdb`;-}--async function createDuckDbAttachedDatabaseFile() {- const node = props.node;- if (!node.connectionId) return;- if (!isTauriRuntime()) {- toast(t("contextMenu.createDuckDbFileDesktopOnly"), 4000);- return;- }-- try {- const { save } = await import("@tauri-apps/plugin-dialog");- const selectedPath = await save({- defaultPath: "database.duckdb",- filters: [{ name: "DuckDB", extensions: ["duckdb", "db"] }],- });- if (!selectedPath) return;-- const path = ensureDuckDbFileExtension(selectedPath);- await connectionStore.ensureConnected(node.connectionId);- const existingDatabases = await api.listDatabases(node.connectionId);- const name = uniqueDuckDbAttachedDatabaseName(- duckDbAttachedDatabaseNameFromPath(path),- existingDatabases.map((database) => database.name),- );- const sql = await buildDuckDbAttachDatabaseSql(path, name);- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: "" });-- const config = connectionStore.getConfig(node.connectionId);- if (config) {- await connectionStore.updateConnection({- ...config,- attached_databases: [...(config.attached_databases ?? []), { name, path }],- });- }- await connectionStore.ensureVisibleDatabase(node.connectionId, name);- await connectionStore.loadDatabases(node.connectionId, { force: true });- connectionStore.selectedTreeNodeId = `${node.connectionId}:${name}`;- toast(t("contextMenu.createDuckDbFileSuccess", { name }), 3000);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--async function confirmCreateDatabase() {- const node = sidebarFormTarget.value ?? props.node;- const name = createDatabaseName.value.trim();- if (!name || !node.connectionId) return;- try {- await connectionStore.ensureConnected(node.connectionId);- const config = connectionStore.getConfig(node.connectionId);- if (config?.db_type === "mongodb") {- showCreateDatabaseDialog.value = false;- await api.mongoCreateDatabase(node.connectionId, name);- toast(t("contextMenu.createDatabaseSuccess", { name }), 3000);- await connectionStore.ensureVisibleDatabase(node.connectionId, name);- await connectionStore.loadMongoDatabases(node.connectionId);- return;- }- const sql = await buildCreateDatabaseSql({- databaseType: config?.db_type,- driverProfile: config?.driver_profile,- target: "database",- name,- charset: createDatabaseCharset.value,- collation: createDatabaseCollation.value,- });- const provider = resolveDatabaseUserAdminProviderForConnection(config);- const plan: AuthorizationPlan = provider- ? buildCreateDatabaseAuthorizationPlan({ provider, database: name, createSql: sql, users: createDatabaseSelectedUsers.value })- : { steps: [{ id: "create-database", label: `create database ${name}`, database: "", sql, operation: "createDatabase", targetDatabase: name }] };- createDatabaseAuthorizationPlan.value = plan;- createDatabasePreviewSql.value = authorizationPlanSql(plan);- createDatabaseAuthorizationResults.value = [];- showCreateDatabaseDialog.value = false;- showCreateDatabasePreviewDialog.value = true;- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--async function applyCreateDatabaseAuthorizationPlan() {- const node = sidebarFormTarget.value ?? props.node;- const plan = createDatabaseAuthorizationPlan.value;- const name = createDatabaseName.value.trim();- if (!node.connectionId || !plan || createDatabaseAuthorizationApplying.value) return;- createDatabaseAuthorizationApplying.value = true;- try {- const results = await executeWithProductionSqlGuard({- connection: connectionStore.getConfig(node.connectionId),- database: "",- sql: createDatabasePreviewSql.value,- source: t("production.sourceSidebar"),- execute: () => executeAuthorizationPlan(plan, (step) => api.executeMulti(node.connectionId!, step.database, step.sql, undefined, undefined, { maxRows: 1000, continueOnError: true })),- });- if (!results) return;- createDatabaseAuthorizationResults.value = results;- const created = results.some((result) => result.step.id === "create-database" && result.status === "success");- const status = authorizationPlanStatus(results);- if (created) {- await connectionStore.ensureVisibleDatabase(node.connectionId, name);- await connectionStore.loadDatabases(node.connectionId, { force: true });- }- toast(t(status === "success" ? "contextMenu.createDatabaseSuccess" : status === "partial" ? "contextMenu.createDatabasePartial" : "contextMenu.createDatabaseFailed", { name }), status === "success" ? 3000 : 5000);- } catch (error: any) {- toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);- } finally {- createDatabaseAuthorizationApplying.value = false;- }-}--function createDatabaseAuthorizationStepLabel(result: AuthorizationStepResult): string {- const step = result.step;- if (step.operation === "createDatabase") return t("contextMenu.createDatabaseStep", { database: step.targetDatabase });- if (step.operation === "grantDatabase") return t("contextMenu.createDatabaseGrantStep", { user: step.subject, database: step.targetDatabase });- if (step.operation === "grantCurrentObjects") {- return t("userAdmin.stepGrantCurrentObjects", {- user: step.subject,- database: step.targetDatabase,- schema: step.schema,- scope: createDatabaseAuthorizationScopeLabel(step.objectScope),- });- }- if (step.operation === "grantFutureObjects") {- return step.owner- ? t("userAdmin.stepGrantFutureObjectsForOwner", { user: step.subject, database: step.targetDatabase, owner: step.owner, scope: createDatabaseAuthorizationScopeLabel(step.objectScope) })- : t("userAdmin.stepGrantFutureObjects", { user: step.subject, database: step.targetDatabase, scope: createDatabaseAuthorizationScopeLabel(step.objectScope) });- }- return step.label;-}--function createDatabaseAuthorizationScopeLabel(scope: AuthorizationStepResult["step"]["objectScope"]): string {- if (scope === "schemas") return t("userAdmin.scopeSchemas");- if (scope === "tables") return t("userAdmin.scopeTables");- if (scope === "sequences") return t("userAdmin.scopeSequences");- if (scope === "functions") return t("userAdmin.scopeFunctions");- return "";-}--function dropDatabase() {- void refreshDropDatabasePreviewSql();- dropDatabaseLoading.value = false;- showDropDatabaseConfirm.value = true;-}--function dropMongoCollection() {- dropMongoCollectionLoading.value = false;- showDropMongoCollectionConfirm.value = true;-}--function dropMongoIndex() {- dropMongoIndexLoading.value = false;- showDropMongoIndexConfirm.value = true;-}--function dropAllMongoIndexes() {- dropAllMongoIndexesLoading.value = false;- showDropAllMongoIndexesConfirm.value = true;-}--function flushRedisDb() {- showFlushRedisDbConfirm.value = true;-}--async function confirmFlushRedisDb() {- const node = sidebarDangerTarget.value ?? props.node;- if (node.type !== "redis-db" || !node.connectionId || !node.database) return;- try {- await connectionStore.ensureConnected(node.connectionId);- await api.redisFlushDb(node.connectionId, Number(node.database));- connectionStore.updateRedisDbKeyStats(node.connectionId, Number(node.database), { loaded: 0, total: 0 });- window.dispatchEvent(- new CustomEvent("dbx-redis-db-flushed", {- detail: { connectionId: node.connectionId, db: Number(node.database) },- }),- );- toast(t("redis.flushDbSuccess", { db: node.database }), 3000);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--async function confirmDropDatabase() {- const node = sidebarDangerTarget.value ?? props.node;- if (!node.connectionId || dropDatabaseLoading.value) return;- dropDatabaseLoading.value = true;- try {- await connectionStore.ensureConnected(node.connectionId);- if (node.type === "mongo-db" && node.database) {- await api.mongoDropDatabase(node.connectionId, node.database);- toast(t("contextMenu.dropDatabaseSuccess", { name: node.label }), 3000);- await connectionStore.loadMongoDatabases(node.connectionId);- showDropDatabaseConfirm.value = false;- return;- }- const sql =- dropDatabasePreviewSql.value ||- (await buildDropDatabaseSql({- databaseType: databaseTypeForNode(node),- name: node.label,- }));- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: "" });- toast(t("contextMenu.dropDatabaseSuccess", { name: node.label }), 3000);- await connectionStore.loadDatabases(node.connectionId, { force: true });- showDropDatabaseConfirm.value = false;- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- } finally {- dropDatabaseLoading.value = false;- }-}--async function confirmDropMongoCollection() {- const node = sidebarDangerTarget.value ?? props.node;- if (node.type !== "mongo-collection" || !node.connectionId || !node.database || dropMongoCollectionLoading.value) return;- dropMongoCollectionLoading.value = true;- try {- await connectionStore.ensureConnected(node.connectionId);- await api.mongoDropCollection(node.connectionId, node.database, node.label);- toast(t("contextMenu.dropCollectionSuccess", { name: node.label }), 3000);- await connectionStore.loadMongoCollections(node.connectionId, node.database);- showDropMongoCollectionConfirm.value = false;- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- } finally {- dropMongoCollectionLoading.value = false;- }-}--function mongoIndexesGroupNodeId(node: Pick<TreeNode, "connectionId" | "database" | "schema" | "tableName" | "label">): string | null {- if (!node.connectionId || !node.database) return null;- const tableName = node.tableName || node.label;- return node.schema ? `${node.connectionId}:${node.database}:${node.schema}:${tableName}:__indexes` : `${node.connectionId}:${node.database}:${tableName}:__indexes`;-}--async function refreshMongoIndexTree(node: Pick<TreeNode, "connectionId" | "database" | "schema" | "tableName" | "label">) {- const nodeId = mongoIndexesGroupNodeId(node);- if (!node.connectionId || !node.database || !nodeId) return;- await connectionStore.loadIndexes(node.connectionId, node.database, node.tableName || node.label, node.schema, nodeId);-}--async function confirmDropMongoIndex() {- const node = sidebarDangerTarget.value ?? props.node;- if (!canDropMongoIndexNode(node) || !node.connectionId || !node.database || !node.tableName || dropMongoIndexLoading.value) return;- dropMongoIndexLoading.value = true;- try {- await connectionStore.ensureConnected(node.connectionId);- const indexName = mongoIndexNameForNode(node);- await api.mongoDropIndexes(node.connectionId, node.database, node.tableName, JSON.stringify(indexName), true);- toast(t("contextMenu.dropTableChildObjectSuccess", { name: indexName }), 3000);- showDropMongoIndexConfirm.value = false;- await refreshMongoIndexTree(node);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- } finally {- dropMongoIndexLoading.value = false;- }-}--async function confirmDropAllMongoIndexes() {- const node = sidebarDangerTarget.value ?? props.node;- if (node.type !== "mongo-collection" || !node.connectionId || !node.database || dropAllMongoIndexesLoading.value) return;- dropAllMongoIndexesLoading.value = true;- try {- await connectionStore.ensureConnected(node.connectionId);- const result = await api.mongoDropIndexes(node.connectionId, node.database, node.label, undefined, false);- toast(t("contextMenu.dropAllIndexesSuccess", { count: result.dropped_names.length, name: node.label }), 3000);- showDropAllMongoIndexesConfirm.value = false;- await refreshMongoIndexTree(node);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- } finally {- dropAllMongoIndexesLoading.value = false;- }-}--function openCreateSchemaDialog() {- createSchemaName.value = "";- showCreateSchemaDialog.value = true;-}--async function confirmCreateSchema() {- const node = sidebarFormTarget.value ?? props.node;- const name = createSchemaName.value.trim();- const config = node.connectionId ? connectionStore.getConfig(node.connectionId) : undefined;- const isConnectionLevelSchemaCreation = node.type === "connection" && connectionNamespaceCreationTarget(config) === "schema";- const targetDatabase = isConnectionLevelSchemaCreation ? "" : node.database;- if (!name || !node.connectionId || (!targetDatabase && !isConnectionLevelSchemaCreation)) return;- showCreateSchemaDialog.value = false;- try {- await connectionStore.ensureConnected(node.connectionId);- const sql = await buildCreateSchemaSql({- databaseType: effectiveDatabaseTypeForConnection(config),- name,- });- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: targetDatabase || "" });- toast(t("contextMenu.createSchemaSuccess", { name }), 3000);- if (isConnectionLevelSchemaCreation) {- await connectionStore.loadDatabases(node.connectionId, { force: true });- } else if (config?.db_type === "sqlserver") {- await connectionStore.loadSqlServerDatabaseObjects(node.connectionId, targetDatabase || "", { force: true });- } else {- await connectionStore.loadSchemas(node.connectionId, targetDatabase || "", { force: true });- }- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--function dropSchema() {- void refreshDropSchemaPreviewSql();- showDropSchemaConfirm.value = true;-}--async function confirmDropSchema() {- const node = sidebarDangerTarget.value ?? props.node;- if (!node.connectionId || !node.database) return;- try {- await connectionStore.ensureConnected(node.connectionId);- const sql =- dropSchemaPreviewSql.value ||- (await buildDropSchemaSql({- databaseType: databaseTypeForNode(node),- name: node.label,- }));- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database });- toast(t("contextMenu.dropSchemaSuccess", { name: node.label }), 3000);- const config = connectionStore.getConfig(node.connectionId);- if (config?.db_type === "sqlserver") {- await connectionStore.loadSqlServerDatabaseObjects(node.connectionId, node.database, { force: true });- } else {- await connectionStore.loadSchemas(node.connectionId, node.database, { force: true });- }- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--function duplicateStructure(source: TreeNode = props.node) {- if (!isDuplicateStructureSource(source)) return;- duplicateStructureSource.value = source;- duplicateTableName.value = `${source.label}_copy`;- showDuplicateDialog.value = true;-}--function isDuplicateStructureSource(node: TreeNode): node is DuplicateStructureSource {- return node.type === "table" && !!node.connectionId && !!node.database;-}--async function confirmDuplicateStructure() {- const node = duplicateStructureSource.value || (isDuplicateStructureSource(props.node) ? props.node : null);- const newName = duplicateTableName.value.trim();- if (!newName || !node) return;- showDuplicateDialog.value = false;- try {- await connectionStore.ensureConnected(node.connectionId);- const databaseType = databaseTypeForNode(node);- const sql = await buildDuplicateTableStructureSql({- databaseType,- schema: node.schema,- sourceName: node.label,- targetName: newName,- });- await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });- toast(t("contextMenu.duplicateStructureSuccess", { name: newName }), 3000);- await refreshTableList(node);- } catch (e: any) {- toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);- }-}--async function confirmPasteTable() {- const entries = pasteTableEntries.value.filter((entry) => entry.targetName.trim());- if (entries.length === 0) return;- const mode = pasteTableMode.value;- const copyData = pasteTableModeCopiesData(mode) && pasteTableDataCopySupported.value;- showPasteDialog.value = false;- let successCount = 0;- let failCount = 0;- const refreshedConnections = new Set<string>();- for (const entry of entries) {- const targetName = entry.targetName.trim();- try {- await connectionStore.ensureConnected(entry.connectionId);- const databaseType = entry.connectionId ? effectiveDatabaseTypeForConnection(connectionStore.getConfig(entry.connectionId)) : undefined;- if (mode === "structure-and-data" || mode === "structure-only") {- const structureSql = await buildDuplicateTableStructureSql({- databaseType,- schema: entry.schema,- sourceName: entry.sourceName,- targetName,- });- await executeTreeNodeSqlWithProductionGuard(entry, structureSql, { database: entry.database, schema: entry.schema });- }- if (copyData) {- const sourceColumns = await api.getColumns(entry.connectionId, entry.database, entry.schema || "", entry.sourceName);- const dataCopyColumnOptions = tableDataCopyColumnOptions(databaseType, sourceColumns);- if (dataCopyColumnOptions.columns.length === 0) {- throw new Error("No writable columns available for table data copy.");- }- const dataSql = await buildCopyTableDataSql({- databaseType,- schema: entry.schema,- sourceName: entry.sourceName,- targetName,- ...dataCopyColumnOptions,- });- await executeTreeNodeSqlWithProductionGuard(entry, dataSql, { database: entry.database, schema: entry.schema });- }- successCount++;- const refreshKey = `${entry.connectionId}:${entry.database}:${entry.schema || ""}`;- if (!refreshedConnections.has(refreshKey)) {- refreshedConnections.add(refreshKey);- await connectionStore.refreshObjectListTreeNode(entry.connectionId, entry.database, entry.schema);- }- } catch (e: any) {- failCount++;- console.error(`Failed to paste table "${entry.sourceName}" -> "${targetName}":`, e);- }- }- if (failCount === 0) {- toast(t("contextMenu.batchPasteSuccess", { count: successCount }), 3000);- } else {- toast(t("contextMenu.batchPastePartialFail", { success: successCount, failed: failCount }), 5000);- }-}--function copyTableToClipboard() {- const node = props.node;- if (node.type !== "table" || !node.connectionId || !node.database) return;- connectionStore.treeClipboard = {- kind: "table-copy",- tables: [- {- connectionId: node.connectionId,- database: node.database,- schema: node.schema,- tableName: node.label,- },- ],- };- toast(t("contextMenu.pasteTableClipboardUpdated"), 2000);-}--function openPasteTableDialog() {- const clipboard = connectionStore.treeClipboard;- if (clipboard?.kind !== "table-copy" || !canPasteTreeClipboardToCurrentNode()) {- toast(t("contextMenu.noTableToPaste"), 2000);- return;- }- pasteTableMode.value = defaultPasteTableMode(currentDatabaseType());- pasteTableEntries.value = clipboard.tables.map((entry) => ({- sourceName: entry.tableName,- targetName: `${entry.tableName}_copy`,- connectionId: entry.connectionId,- database: entry.database,- schema: entry.schema,- }));- showPasteDialog.value = true;-}--function createTable() {- const node = props.node;- if (!node.connectionId || !node.database) return;- queryStore.openTableStructure(node.connectionId, node.database, node.schema, "");-}--function createView() {- const node = props.node;- if (!node.connectionId || !node.database) return;- connectionStore.activeConnectionId = node.connectionId;- const viewName = "new_view";- const effectiveDbType = effectiveDatabaseTypeForConnection(connectionStore.getConfig(node.connectionId));- const viewSqlName = effectiveDbType === "informix" || !node.schema ? viewName : `${node.schema}.${viewName}`;- const tabId = queryStore.createTab(node.connectionId, node.database, t("contextMenu.createView"), "query", node.schema);- queryStore.updateSql(tabId, `CREATE VIEW ${viewSqlName} AS\nSELECT\n *\nFROM table_name;\n`);- queryStore.setObjectSource(tabId, {- schema: node.schema,- name: viewName,- objectType: "VIEW",- });-}--async function saveFileContent(content: string, defaultFileName: string, filterName: string, filterExt: string) {- if (isTauriRuntime()) {- const { save } = await import("@tauri-apps/plugin-dialog");- const { writeTextFile } = await import("@tauri-apps/plugin-fs");- const path = await save({- defaultPath: defaultFileName,- filters: [{ name: filterName, extensions: [filterExt] }],- });- if (path) await writeTextFile(path, content);- } else {- const blob = new Blob([content], { type: "text/plain" });- const url = URL.createObjectURL(blob);- const a = document.createElement("a");- a.href = url;- a.download = defaultFileName;- a.click();- URL.revokeObjectURL(url);- }-}--async function exportStructure() {- const targets = structureExportTargets();- if (!targets.length) return;- isLoadingStructurePreview.value = true;- structurePreviewError.value = "";- structurePreviewSql.value = "";- structurePreviewTitle.value = targets.length === 1 ? t("contextMenu.exportStructurePreviewTitle", { name: targets[0]!.label }) : t("contextMenu.exportStructurePreviewTitleMultiple", { count: targets.length });- structurePreviewDefaultFileName.value = targets.length === 1 ? `${targets[0]!.label}.sql` : "structures.sql";- showStructurePreviewDialog.value = true;- try {- const parts: string[] = [];- for (const target of targets) {- await connectionStore.ensureConnected(target.connectionId);- const ddl = await api.getTableDdl(target.connectionId, target.database, target.schema || target.database, target.label, tableDdlObjectTypeForNode(target.type), target.catalog);- parts.push(ddl.trim());- }- structurePreviewSql.value = joinExportedDdls(parts);- } catch (e: any) {- structurePreviewError.value = e?.message || String(e);- console.error("Export structure failed:", e);- } finally {- isLoadingStructurePreview.value = false;- }-}--function canExportStructureNode(node: TreeNode): node is TreeNode & { connectionId: string; database: string } {- return (node.type === "table" || node.type === "view" || node.type === "materialized_view") && !!node.connectionId && !!node.database;-}--function tableDdlObjectTypeForNode(type: TreeNodeType): ObjectSourceKind | undefined {- if (type === "view") return "VIEW";- if (type === "materialized_view") return "MATERIALIZED_VIEW";- return undefined;-}--function selectedStructureNodes(): TreeNode[] {- const selectedIds = new Set(connectionStore.selectedTreeNodeIds);- if (!selectedIds.size) return [];- const nodes: TreeNode[] = [];- const visit = (items: TreeNode[]) => {- for (const item of items) {- if (selectedIds.has(item.id) && canExportStructureNode(item)) nodes.push(item);- if (item.children) visit(item.children);- }- };- visit(connectionStore.treeNodes);- return nodes;-}--function structureExportTargets(): Array<TreeNode & { connectionId: string; database: string }> {- if (!canExportStructureNode(props.node)) return [];- const selected = selectedStructureNodes().filter((node): node is TreeNode & { connectionId: string; database: string } => canExportStructureNode(node) && node.connectionId === props.node.connectionId && node.database === props.node.database);- return selected.some((node) => node.id === props.node.id) ? selected : [props.node];-}--function structureTargetName(target: TreeNode): string {- return target.schema ? `${target.schema}.${target.label}` : target.label;-}--function columnDocValue(value: unknown): string {- return value === null || value === undefined ? "" : String(value);-}--function tsvCell(value: unknown): string {- return columnDocValue(value).replace(/\t/g, " ").replace(/\r?\n/g, " ").trim();-}--function markdownCell(value: unknown): string {- return columnDocValue(value).replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>").trim();-}--function columnDocHeaders(includeTable: boolean): string[] {- const headers = [t("contextMenu.structureDocColumn"), t("contextMenu.structureDocType"), t("contextMenu.structureDocPrimaryKey"), t("contextMenu.structureDocNullable"), t("contextMenu.structureDocDefault"), t("contextMenu.structureDocComment")];- return includeTable ? [t("contextMenu.structureDocTable"), ...headers] : headers;-}--function columnDocCells(target: TreeNode, column: ColumnInfo, includeTable: boolean): unknown[] {- const cells = [column.name, column.data_type, column.is_primary_key ? t("contextMenu.structureDocYes") : t("contextMenu.structureDocNo"), column.is_nullable ? t("contextMenu.structureDocYes") : t("contextMenu.structureDocNo"), column.column_default, column.comment];- return includeTable ? [structureTargetName(target), ...cells] : cells;-}--async function tableColumnsForStructureCopy(target: TreeNode & { connectionId: string; database: string }): Promise<ColumnInfo[]> {- await connectionStore.ensureConnected(target.connectionId);- return (await api.getColumns(target.connectionId, target.database, target.schema || target.database, target.label)) as ColumnInfo[];-}--async function buildStructureCopyText(format: StructureCopyFormat): Promise<string> {- const targets = structureExportTargets();- if (!targets.length) return "";- const includeTable = targets.length > 1;- const headers = columnDocHeaders(includeTable);-- if (format === "tsv") {- const lines = [headers.map(tsvCell).join("\t")];- for (const target of targets) {- const columns = await tableColumnsForStructureCopy(target);- for (const column of columns) {- lines.push(columnDocCells(target, column, includeTable).map(tsvCell).join("\t"));- }- }- return `${lines.join("\n")}\n`;- }-- const tables: string[] = [];- const markdownHeaders = columnDocHeaders(false);- for (const target of targets) {- const columns = await tableColumnsForStructureCopy(target);- const tableLines = [`### ${markdownCell(structureTargetName(target))}`, "", `| ${markdownHeaders.map(markdownCell).join(" | ")} |`, `| ${markdownHeaders.map(() => "---").join(" | ")} |`, ...columns.map((column) => `| ${columnDocCells(target, column, false).map(markdownCell).join(" | ")} |`)];- tables.push(tableLines.join("\n"));- }- return `${tables.join("\n\n")}\n`;-}--async function copyStructureAs(format: StructureCopyFormat) {- let text = "";- try {- text = await buildStructureCopyText(format);- if (!text) return;- await copyToClipboard(text);- toast(t("contextMenu.structureDocCopied"), 2000);- } catch (e: any) {- if (text) {- structureDocCopyText.value = text;- structureDocCopyTitle.value = format === "tsv" ? t("contextMenu.copyStructureAsTsv") : t("contextMenu.copyStructureAsMarkdown");- showStructureDocCopyDialog.value = true;- return;- }- toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);- }-}--async function copyStructureDocText() {- if (!structureDocCopyText.value) return;- try {- await copyToClipboard(structureDocCopyText.value);- toast(t("contextMenu.structureDocCopied"), 2000);- } catch (e: any) {- toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);- }-}--function selectTextareaContent(event: FocusEvent) {- if (event.target instanceof HTMLTextAreaElement) event.target.select();-}--async function copyStructurePreview() {- if (!structurePreviewSql.value) return;- try {- await copyToClipboard(structurePreviewSql.value);- toast(t("contextMenu.exportStructureCopied"), 2000);- } catch (e: any) {- toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);- }-}--async function saveStructurePreview() {- if (!structurePreviewSql.value) return;- try {- await saveFileContent(structurePreviewSql.value, structurePreviewDefaultFileName.value, "SQL", "sql");- toast(t("grid.exported"));- } catch (e: any) {- toast(t("grid.exportFailed", { message: e?.message || String(e) }), 5000);- }-}--async function exportDataLegacy(format: "csv" | "json" | "sql") {- const node = props.node;- if (!node.connectionId || !node.database) return;- const connectionId = node.connectionId;- const database = node.database;- const config = connectionStore.getConfig(node.connectionId);- if (!config) return;-- try {- await connectionStore.ensureConnected(connectionId);- const tableColumns = format === "sql" ? await api.getColumns(connectionId, database, node.schema || database, node.label) : undefined;- const queryColumns = config.db_type === "neo4j" ? (tableColumns ?? (await api.getColumns(connectionId, database, node.schema || database, node.label))).map((column) => column.name) : undefined;- const effectiveDbType = effectiveDatabaseTypeForConnection(config);- const result = await fetchTableDataForExport({- databaseType: effectiveDbType,- identifierQuote: connectionStore.connectionIdentifierQuote?.(connectionId),- schema: node.schema,- tableName: node.label,- tableType: node.tableType,- columns: queryColumns,- executePage: (sql) => api.executeQuery(connectionId, database, sql),- });-- if (format === "csv") {- let outputPath = `${node.label}.csv`;- if (isTauriRuntime()) {- const { save } = await import("@tauri-apps/plugin-dialog");- const path = await save({- defaultPath: outputPath,- filters: [{ name: "CSV", extensions: ["csv"] }],- });- if (!path) return;- outputPath = path as string;- }- await api.exportQueryResultCsv(outputPath, result.columns, result.rows);- toast(t("grid.exported"));- return;- }-- if (format === "json") {- let outputPath = `${node.label}.json`;- if (isTauriRuntime()) {- const { save } = await import("@tauri-apps/plugin-dialog");- const path = await save({- defaultPath: outputPath,- filters: [{ name: "JSON", extensions: ["json"] }],- });- if (!path) return;- outputPath = path as string;- }- await api.exportQueryResultJson(outputPath, result.columns, result.rows);- toast(t("grid.exported"));- return;- }-- const content = await formatSqlInsert({- databaseType: effectiveDbType,- schema: node.schema,- tableName: node.label,- columns: result.columns,- columnTypes: tableColumns ? columnTypesForResultColumns(result.columns, tableColumns) : undefined,- rows: result.rows,- });- await saveFileContent(content, `${node.label}.sql`, "SQL", "sql");- toast(t("grid.exported"));- } catch (e: any) {- toast(t("grid.exportFailed", { message: e?.message || String(e) }), 5000);- }-}--function columnTypesForResultColumns(columns: string[], tableColumns: ColumnInfo[]): Array<string | undefined> {- const typesByName = new Map(tableColumns.map((column) => [column.name.toLocaleLowerCase(), column.data_type]));- return columns.map((column) => typesByName.get(column.toLocaleLowerCase()));-}--async function exportData(format: "csv" | "json" | "sql") {- if (format !== "csv") {- await exportDataLegacy(format);- return;- }- await exportTableData("csv");-}--async function exportTableData(format: "csv" | "xlsx") {- const node = props.node;- if (!node.connectionId || !node.database) return;- const connectionId = node.connectionId;- const database = node.database;- const config = connectionStore.getConfig(node.connectionId);- if (!config) return;-- let task: ExportTask | null = null;- try {- await connectionStore.ensureConnected(connectionId);-- // Step 1: Open save dialog FIRST- let outputPath = `${node.label}.${format}`;- if (isTauriRuntime()) {- const { save } = await import("@tauri-apps/plugin-dialog");- const path = await save({- defaultPath: outputPath,- filters: [{ name: format === "csv" ? "CSV" : "Excel", extensions: [format] }],- });- if (!path) return;- outputPath = path as string;- }-- // Step 2: Register task in export tracker (background)- task = addExportTask(node.label, format, outputPath);- const currentTask = task;-- // Step 3: Get query columns for neo4j- const queryColumns = config.db_type === "neo4j" ? (await api.getColumns(connectionId, database, node.schema || database, node.label)).map((c) => c.name) : undefined;-- // Step 4: Start streaming export (background, non-blocking)- const rowLimit = settingsStore.editorSettings.exportRowLimitEnabled ? settingsStore.editorSettings.exportRowLimit : null;- const request: api.TableExportRequest = {- exportId: currentTask.exportId,- connectionId,- database,- schema: node.schema || undefined,- tableName: node.label,- filePath: outputPath,- format,- columns: queryColumns,- batchSize: settingsStore.editorSettings.exportBatchSize,- rowLimit,- };-- await api.startTableExport(request, (progress) => {- currentTask.rowsExported = progress.rowsExported;- currentTask.totalRows = progress.totalRows;- currentTask.status = progress.status;- currentTask.errorMessage = progress.errorMessage || null;- if (progress.status === "Done") {- toast(t("grid.exported"));- } else if (progress.status === "Error") {- toast(t("grid.exportFailed", { message: progress.errorMessage || "" }), 5000);- }- });- } catch (e: any) {- if (task) {- task.status = "Error";- task.errorMessage = e?.message || String(e);- }- toast(t("grid.exportFailed", { message: e?.message || String(e) }), 5000);- }-}--async function exportDataXlsx() {- await exportTableData("xlsx");-}--function editConnection() {- if (props.node.connectionId) {- connectionStore.startEditing(props.node.connectionId);- }-}--const revealConnectionFilePath = computed<string | null>(() => {- if (props.node.type !== "connection" || !props.node.connectionId) return null;- const config = connectionStore.getConfig(props.node.connectionId);- if (!config) return null;- return connectionFilePath(config);-});--async function revealDatabaseFile() {- const path = revealConnectionFilePath.value;- if (!path) return;- try {- await revealPathInFileManager(path);- } catch (e: any) {- const message = typeof e === "string" ? e : e?.message || String(e);- toast(message, 5000);- }-}--const sqliteBackupSource = computed<string | null>(() => {- if (props.node.type !== "connection" || !props.node.connectionId) return null;- const config = connectionStore.getConfig(props.node.connectionId);- if (!config) return null;- return sqliteBackupSourcePath(config);-});--const canBackupSqliteDatabase = computed(() => {- const source = sqliteBackupSource.value;- if (!source || !props.node.connectionId) return false;- return isTauriRuntime() && (!isMemorySqlitePath(source) || connectionStore.connectedIds.has(props.node.connectionId));-});--async function backupSqliteDatabase() {- const connId = props.node.connectionId;- const config = connId ? connectionStore.getConfig(connId) : undefined;- const sourcePath = sqliteBackupSource.value;- if (!connId || !config || !sourcePath) return;-- try {- const { save } = await import("@tauri-apps/plugin-dialog");- const destinationPath = await save({- defaultPath: defaultSqliteBackupFileName(config),- filters: [{ name: "SQLite", extensions: ["db", "sqlite", "sqlite3"] }],- });- if (!destinationPath) return;-- toast(t("contextMenu.backupSqliteDatabaseInProgress"), 2000);- if (!isMemorySqlitePath(sourcePath)) {- await connectionStore.ensureConnected(connId);- }- await api.backupSqliteDatabase(connId, destinationPath);- toast(t("contextMenu.backupSqliteDatabaseSuccess"), 3000);- } catch (e: any) {- toast(t("contextMenu.backupSqliteDatabaseFailed", { message: e?.message || String(e) }), 5000);- }-}--async function disconnectConnection() {- if (props.node.connectionId) {- try {- await connectionStore.disconnect(props.node.connectionId);- props.node.isExpanded = false;- props.node.children = [];- toast(t("connection.disconnected"), 2000);- } catch (e: any) {- toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000);- }- }-}--async function cancelConnectionAttempt() {- if (!props.node.connectionId) return;- try {- const cancelled = await connectionStore.cancelConnecting(props.node.connectionId);- if (cancelled) toast(t("connection.connectCancelled"), 2000);- } catch (e: any) {- toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000);- }-}--async function closeDatabaseConnection() {- const node = props.node;- if (node.type !== "database" || !node.connectionId || node.database == null) return;- try {- await connectionStore.closeDatabaseConnection(node.connectionId, node.database);- toast(t("connection.databaseConnectionClosed", { name: node.label }), 2000);- } catch (e: any) {- toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000);- }-}--function openTransfer() {- if (props.node.connectionId) {- connectionStore.transferSource = {- connectionId: props.node.connectionId,- database: props.node.database ?? "",- };- }-}--function openSchemaDiff() {- if (props.node.connectionId) {- connectionStore.schemaDiffSource = {- connectionId: props.node.connectionId,- database: props.node.database ?? "",- schema: props.node.schema,- };- }-}--function openDataCompare() {- if (props.node.connectionId) {- connectionStore.dataCompareSource = {- connectionId: props.node.connectionId,- database: props.node.database ?? "",- schema: props.node.schema,- tableName: props.node.type === "table" ? props.node.label : undefined,- };- }-}--function openSqlFileExecution() {- if (props.node.connectionId) {- connectionStore.sqlFileSource = {- connectionId: props.node.connectionId,- database: props.node.database ?? "",- };- }-}--function openDiagram() {- const node = props.node;- if (!node.connectionId || !node.database) return;- connectionStore.diagramSource = {- connectionId: node.connectionId,- database: node.database,- schema: node.schema,- tableName: node.type === "table" ? node.label : undefined,- };-}--function openDatabaseSearch() {- const node = props.node;- if (!node.connectionId || !node.database) return;- connectionStore.databaseSearchSource = {- connectionId: node.connectionId,- database: node.database,- schema: node.type === "schema" ? node.schema : undefined,- };-}--function openDatabaseExport() {- const node = props.node;- if (!node.connectionId || !node.database) return;- connectionStore.databaseExportSource = {- connectionId: node.connectionId,- database: node.database,- schema: node.type === "schema" || node.type === "table" || node.type === "view" || node.type === "materialized_view" ? node.schema : undefined,- tableName: node.type === "table" || node.type === "view" || node.type === "materialized_view" ? node.label : undefined,- };-}--function openAllDatabasesExport() {- const node = props.node;- if (node.type !== "connection" || !node.connectionId) return;- connectionStore.databaseExportSource = {- connectionId: node.connectionId,- database: "",- allDatabases: true,- };-}--function openScheduledBackups() {- settingsStore.requestSettingsNavigation("backups");-}--function openTableImport() {- const node = props.node;- if (!node.connectionId || !node.database) return;- connectionStore.tableImportSource = {- connectionId: node.connectionId,- database: node.database,- schema: node.schema,- tableName: node.type === "table" ? node.label : undefined,- };-}--function openStructureEditor() {- const node = props.node;- if (!node.connectionId || !node.database) return;- if (node.type === "table") {- queryStore.openTableStructure(node.connectionId, node.database, node.schema, node.label, undefined, undefined, node.catalog);- return;- }- if (node.type === "column" && node.tableName) {- const columnName = tableChildDropObjectName(node).trim();- if (!columnName) return;- queryStore.openTableStructure(node.connectionId, node.database, node.schema, node.tableName, "columns", { kind: "column", name: columnName }, node.catalog);- return;- }- if (node.type === "index" && node.tableName) {- const indexName = tableChildDropObjectName(node).trim();- if (!indexName) return;- queryStore.openTableStructure(node.connectionId, node.database, node.schema, node.tableName, "indexes", { kind: "index", name: indexName }, node.catalog);- }-}--function openFieldLineage() {- const node = props.node;- const column = node.type === "column" && node.meta && "name" in node.meta ? node.meta.name : node.label;- if (node.type !== "column" || !node.connectionId || !node.database || !node.tableName || !column) return;- connectionStore.fieldLineageSource = {- connectionId: node.connectionId,- database: node.database,- schema: node.schema,- tableName: node.tableName,- columnName: column,- };-}--const canExpand = computed(() =>- canTreeNodeShowExpander({- type: props.node.type,- childCount: props.node.children?.length ?? 0,- }),-);-const canPin = computed(() => canTreeNodePin(props.node.type));-const canOpenSqlFileExecution = computed(() => {- return supportsSqlFileExecution(rawDatabaseType());-});-const canExportAllDatabases = computed(() => {- if (props.node.type !== "connection" || !props.node.connectionId) return false;- const dbType = connectionStore.getConfig(props.node.connectionId)?.db_type;- return !["redis", "mongodb", "elasticsearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "nacos"].includes(dbType || "");-});-const canOpenDiagram = computed(() => {- return !!props.node.database && supportsSchemaDiagram(currentDatabaseType());-});-const canOpenDatabaseSearch = computed(() => {- return !!props.node.database && supportsDatabaseSearch(currentDatabaseType());-});-const canOpenObjectBrowser = computed(() => {- return supportsObjectBrowserTreeNode(rawDatabaseType(), props.node.type);-});-const canOpenTableImport = computed(() => {- const node = props.node;- const supportedNode = node.type === "table" || ((node.type === "database" || node.type === "schema" || node.type === "group-tables") && canCreateTable.value);- return supportedNode && !isSqlServerLinkedNode(node) && !!node.connectionId && !!node.database && supportsTableImport(currentDatabaseType());-});-const canOpenStructureEditor = computed(() => {- const editableNode = props.node.type === "table" || ((props.node.type === "column" || props.node.type === "index") && !!props.node.tableName);- return editableNode && !isSqlServerLinkedNode(props.node) && !!props.node.connectionId && !!props.node.database && supportsTableStructureEditing(currentTableStructureDatabaseType());-});-const canOpenFieldLineage = computed(() => {- return props.node.type === "column" && !!props.node.database && !!props.node.tableName && supportsFieldLineage(currentDatabaseType());-});-const isPinned = computed(() => props.node.pinned || connectionStore.isTreeNodePinned(props.node));-const isNodeDefaultDatabase = computed(() => (props.node.type === "database" || props.node.type === "redis-db" || props.node.type === "mongo-db") && !!props.node.connectionId && !!props.node.database && connectionStore.isDefaultDatabase(props.node.connectionId, props.node.database));-const hasTypeMenu = computed(() => {- const t = props.node.type;- return t === "connection" || t === "database" || t === "schema" || t === "table" || t === "view" || t === "column" || t === "procedure" || t === "function" || t === "package" || t === "package-body" || isGroupLabel(props.node);-});-const columnComment = computed(() => (!settingsStore.editorSettings.sidebarHideTableComments && props.node.type === "column" && props.node.meta && "comment" in props.node.meta ? (props.node.meta as any).comment : null));-const tableComment = computed(() =>- !settingsStore.editorSettings.sidebarHideTableComments &&- (props.node.type === "schema" || props.node.type === "table" || props.node.type === "view" || props.node.type === "mongo-collection" || props.node.type === "vector-collection" || props.node.type === "elasticsearch-index") &&- props.node.comment- ? props.node.comment- : null,-);-const labelWidthClass = computed(() => treeLabelWidthClass({ fullWidth: usesFullWidthLabel.value, hasTrailingComment: !!columnComment.value || !!tableComment.value }));-const paddingLeft = computed(() => treeItemPaddingLeft(props.depth));-const tableSearchParentId = computed(() => props.node.tableSearchParentId || "");-const tableSearchValue = computed(() => {- const parentId = tableSearchParentId.value;- return parentId ? connectionStore.sidebarTableSearchQueries[parentId] || "" : "";-});-const isConnected = computed(() => props.node.type === "connection" && !!props.node.connectionId && connectionStore.connectedIds.has(props.node.connectionId));-const isConnecting = computed(() => props.node.type === "connection" && !!props.node.connectionId && connectionStore.connectingIds.has(props.node.connectionId));-const isConnectionReadonly = computed(() => props.node.type === "connection" && !!props.node.connectionId && (connectionStore.getConfig(props.node.connectionId)?.read_only ?? false));-const isOpenedDatabase = computed(() => isSidebarDatabaseOpened(props.node, connectionStore.isTreeNodeChildrenLoaded));-const showsDatabaseOpenIndicator = computed(() => props.node.type === "database" && (isOpenedDatabase.value || (!!props.node.connectionId && props.node.database != null && queryStore.openDatabaseKeys.has(`${props.node.connectionId}\x00${props.node.database}`))));-const canCloseDatabaseConnection = computed(() => canCloseSidebarDatabaseConnection(props.node, connectionStore.isTreeNodeChildrenLoaded, (connectionId, database) => queryStore.openDatabaseKeys.has(`${connectionId}\x00${database}`)));-const nodeIconClass = computed(() => {- const infoClass = getIconInfo(props.node)?.colorClass;- if (props.node.type !== "database") return infoClass;- return isOpenedDatabase.value ? infoClass : "text-muted-foreground/65";-});--const canConfigureVisibleDatabases = computed(() => {- if (props.node.type !== "connection" || !props.node.connectionId) return false;- const dbType = connectionStore.getConfig(props.node.connectionId)?.db_type;- return dbType !== "elasticsearch" && dbType !== "qdrant" && dbType !== "milvus" && dbType !== "weaviate" && dbType !== "chromadb" && dbType !== "etcd" && dbType !== "mq" && dbType !== "nacos";-});--const canConfigureVisibleSchemas = computed(() => {- if (!props.node.connectionId) return false;- const dbType = connectionStore.getConfig(props.node.connectionId)?.db_type;- return canConfigureVisibleSchemasForTreeNode(dbType, props.node.type, props.node.database);-});--const canCopyFinalProxyPort = computed(() => {- if (props.node.type !== "connection" || !props.node.connectionId) return false;- return hasEnabledTransportLayers(connectionStore.getConfig(props.node.connectionId));-});--function connectionIconType(connectionId?: string) {- const config = connectionId ? connectionStore.getConfig(connectionId) : undefined;- return config?.driver_profile || config?.db_type || "postgres";-}--const connectionColor = computed(() => {- const connectionId = props.node.connectionId;- return connectionId ? connectionStore.getConfig(connectionId)?.color || "" : "";-});-const isActiveConnectionScope = computed(() => !!props.node.connectionId && connectionStore.activeConnectionId === props.node.connectionId);-const isSelected = computed(() => connectionStore.selectedTreeNodeId === props.node.id);-const isMultiSelected = computed(() => connectionStore.selectedTreeNodeIdsSet.has(props.node.id));-const isTreeRowSelected = computed(() => isSelected.value || isMultiSelected.value);-const usesSelectionSetHighlight = computed(() => connectionStore.connectionMultiSelectActive || connectionStore.selectedTreeNodeIds.length > 1);const rowStyle = computed(() => {const color = connectionColor.value;const backgroundColor = hexToRgba(color, isActiveConnectionScope.value ? 0.14 : 0.08);@@ -4484,504 +589,78 @@ const rowStyle = computed(() => {"--tree-connection-active-focus-bg": hexToRgba(color, 0.22),};});-const tableSearchStyle = computed(() => {- const color = connectionColor.value;- const rowBackgroundColor = color ? hexToRgba(color, isActiveConnectionScope.value ? 0.14 : 0.08) : "transparent";- return {- paddingLeft: paddingLeft.value,- "--tree-table-search-row-bg": rowBackgroundColor,- "--tree-table-search-input-bg": color ? hexToRgba(color, isActiveConnectionScope.value ? 0.05 : 0.03) : "hsl(var(--background) / 0.56)",- "--tree-table-search-border": color ? hexToRgba(color, isActiveConnectionScope.value ? 0.12 : 0.08) : "hsl(var(--border) / 0.36)",- };-});--function togglePin() {- connectionStore.toggleTreeNodePin(props.node);-}--function updateTableSearchQuery(value: string | number) {- const parentId = tableSearchParentId.value;- if (!parentId) return;- const query = String(value);- if (sidebarTreeContext?.setTableSearchQuery) {- sidebarTreeContext.setTableSearchQuery(parentId, query);- return;- }- connectionStore.setSidebarTableSearchQuery(parentId, query);- void connectionStore.refreshSidebarTableSearch(parentId);-}--function clearTableSearchQuery() {- updateTableSearchQuery("");-}--function openVisibleDatabasesDialog() {- emit("open-visible-databases", props.node);-}--function openVisibleSchemasDialog() {- emit("open-visible-schemas", props.node);-}--// --- Connection Group Management ----const isRenamingGroup = ref(false);-const renameInput = ref("");-const renameInputRef = ref<HTMLInputElement>();--function shouldMeasureLabelOverflow(): boolean {- return shouldMeasureSidebarLabelOverflow({- hasDetailTooltip: !!detailTooltip.value?.rows.length,- isRenaming: isRenamingGroup.value,- usesFullWidthLabel: usesFullWidthLabel.value,- });-}--function startRenameGroup() {- renameInput.value = props.node.label;- isRenamingGroup.value = true;- emit("rename-started");- nextTick(() => {- focusSidebarRenameInput(() => (isRenamingGroup.value ? renameInputRef.value : undefined));- });-}--watch(- () => props.pendingRename,- (val) => {- if (val && props.node.type === "connection-group") {- startRenameGroup();- }- },- { immediate: true },-);--function finishRenameGroup() {- // Guard against double invocation: pressing Enter sets isRenamingGroup=false- // and unmounts the input, which then fires @blur -> finishRenameGroup again.- // The first call can rebuild the tree and recycle props.node onto a different- // group, so a second run would act on the wrong group and cascade across- // groups (issue #681).- if (!isRenamingGroup.value) return;- isRenamingGroup.value = false;- const trimmed = renameInput.value.trim();- // An empty name cancels the rename and keeps the group as-is — never delete- // here. Deleting a group is done explicitly via the context menu (issue #681).- if (!trimmed || trimmed === props.node.label) return;- connectionStore.renameConnectionGroup(props.node.id, trimmed);-}--function deleteConnectionGroup() {- showDeleteGroupConfirm.value = true;-}--function newConnectionInGroup() {- connectionStore.startCreatingConnectionInGroup(props.node.id);-}--function newSubgroup() {- const groupId = connectionStore.createConnectionGroup(t("connectionGroup.newGroupDefault"), props.node.id);- connectionStore.selectedTreeNodeId = groupId;- emit("group-created", groupId);-}--function confirmDeleteGroup() {- const node = sidebarFormTarget.value ?? props.node;- connectionStore.deleteConnectionGroup(node.id);- showDeleteGroupConfirm.value = false;- toast(t("connection.groupDeleted"), 2000);-}--function moveToGroup(groupId: string | null) {- if (props.node.connectionId) {- connectionStore.moveConnectionToGroup(props.node.connectionId, groupId);- }-}--const dangerDialogRoutes: Array<{ flag: { value: boolean }; createRequest: () => SidebarDangerDialogRequest }> = [];-let stopDangerDialogRouting: (() => void) | null = null;--function routeDangerDialog(flag: { value: boolean }, createRequest: () => SidebarDangerDialogRequest) {- dangerDialogRoutes.push({ flag, createRequest });-}--function ensureDangerDialogRouting() {- if (stopDangerDialogRouting) return;- stopDangerDialogRouting = watch(- dangerDialogRoutes.map((route) => route.flag),- (openFlags) => {- if (sidebarTreeDialogOwner.value !== treeItemDialogOwner) return;- openFlags.forEach((open, index) => {- if (!open) return;- const route = dangerDialogRoutes[index];- route.flag.value = false;- emit("open-danger-dialog", route.createRequest());- });- },- );-}--function dangerRequest(request: Omit<SidebarDangerDialogRequest, "target">): SidebarDangerDialogRequest {- const routedRequest = request as SidebarDangerDialogRequest;- routedRequest.target = createSidebarActionTarget(props.node);- sidebarDangerTarget.value = routedRequest.target;- return routedRequest;-}--routeDangerDialog(showDropTableConfirm, () =>- dangerRequest({- title: t("contextMenu.confirmDropTableTitle"),- message: t("contextMenu.confirmDropTableMessage", { name: props.node.label }),- get sql() {- return dropTablePreviewSql.value;- },- confirmLabel: t("contextMenu.dropTable"),- option: canDropTableCascade.value- ? {- checked: dropTableCascade.value,- label: t("contextMenu.dropTableCascade"),- hint: t("contextMenu.dropTableCascadeHint"),- async onChange(checked) {- dropTableCascade.value = checked;- await refreshDropTablePreviewSql();- },- }- : undefined,- confirm: confirmDropTable,- }),-);--routeDangerDialog(showEmptyTableConfirm, () =>- dangerRequest({- title: t("contextMenu.confirmEmptyTableTitle"),- message: t("contextMenu.confirmEmptyTableMessage", { name: props.node.label }),- get sql() {- return emptyTablePreviewSql.value;- },- confirmLabel: t("contextMenu.emptyTable"),- confirm: confirmEmptyTable,- }),-);--routeDangerDialog(showBatchEmptyConfirm, () =>- dangerRequest({- title: batchEmptyConfirmTitle(),- message: batchEmptyConfirmMessage(),- get sql() {- return batchEmptyPreviewSql.value;- },- confirmLabel: batchEmptyConfirmLabel(),- confirm: confirmBatchEmpty,- }),-);--routeDangerDialog(showTruncateTableConfirm, () =>- dangerRequest({- title: t("contextMenu.confirmTruncateTableTitle"),- message: t("contextMenu.confirmTruncateTableMessage", { name: props.node.label }),- get sql() {- return truncateTablePreviewSql.value;- },- confirmLabel: t("contextMenu.truncateTable"),- option: canTruncateTableCascade.value- ? {- checked: truncateTableCascade.value,- label: t("contextMenu.truncateTableCascade"),- hint: t("contextMenu.truncateTableCascadeHint"),- async onChange(checked) {- truncateTableCascade.value = checked;- await refreshTruncateTablePreviewSql();- },- }- : undefined,- confirm: confirmTruncateTable,- }),-);--routeDangerDialog(showDropObjectConfirm, () =>- dangerRequest({- title: dropObjectConfirmTitle(),- message: dropObjectConfirmMessage(),- get sql() {- return dropObjectPreviewSql.value;- },- confirmLabel: dropObjectMenuLabel(),- confirm: confirmDropObject,- }),-);--routeDangerDialog(showDropTableChildObjectConfirm, () =>- dangerRequest({- title: dropTableChildObjectConfirmTitle(),- message: dropTableChildObjectConfirmMessage(),- get sql() {- return dropTableChildObjectPreviewSql.value;- },- confirmLabel: dropTableChildObjectMenuLabel(),- confirm: confirmDropTableChildObject,- }),-);--routeDangerDialog(showBatchDropConfirm, () =>- dangerRequest({- title: batchDropConfirmTitle(),- message: batchDropConfirmMessage(),- get sql() {- return batchDropPreviewSql.value;- },- confirmLabel: batchDropMenuLabel(),- option: canBatchDropCascade.value- ? {- checked: batchDropCascade.value,- label: t("contextMenu.dropTableCascade"),- hint: t("contextMenu.dropTableCascadeHint"),- async onChange(checked) {- batchDropCascade.value = checked;- await refreshBatchDropPreviewSql();- },- }- : undefined,- confirm: confirmBatchDrop,- }),-);--routeDangerDialog(showBatchTruncateConfirm, () =>- dangerRequest({- title: batchTruncateConfirmTitle(),- message: batchTruncateConfirmMessage(),- get sql() {- return batchTruncatePreviewSql.value;- },- confirmLabel: batchTruncateMenuLabel(),- option: canBatchTruncateCascade.value- ? {- checked: batchTruncateCascade.value,- label: t("contextMenu.truncateTableCascade"),- hint: t("contextMenu.truncateTableCascadeHint"),- async onChange(checked) {- batchTruncateCascade.value = checked;- await refreshBatchTruncatePreviewSql();- },- }- : undefined,- confirm: confirmBatchTruncate,- }),-);-routeDangerDialog(showDropDatabaseConfirm, () =>- dangerRequest({- title: t("contextMenu.confirmDropDatabaseTitle"),- message: t("contextMenu.confirmDropDatabaseMessage", { name: props.node.label }),- get sql() {- return dropDatabasePreviewSql.value;- },- confirmLabel: t("contextMenu.dropDatabase"),- get loading() {- return dropDatabaseLoading.value;- },- closeOnConfirm: false,- confirm: confirmDropDatabase,- }),-);+const tableSearchStyle = computed(() => {+ const color = connectionColor.value;+ const rowBackgroundColor = color ? hexToRgba(color, isActiveConnectionScope.value ? 0.14 : 0.08) : "transparent";+ return {+ paddingLeft: paddingLeft.value,+ "--tree-table-search-row-bg": rowBackgroundColor,+ "--tree-table-search-input-bg": color ? hexToRgba(color, isActiveConnectionScope.value ? 0.05 : 0.03) : "hsl(var(--background) / 0.56)",+ "--tree-table-search-border": color ? hexToRgba(color, isActiveConnectionScope.value ? 0.12 : 0.08) : "hsl(var(--border) / 0.36)",+ };+});-routeDangerDialog(showDropMongoCollectionConfirm, () =>- dangerRequest({- title: t("contextMenu.confirmDropCollectionTitle"),- message: t("contextMenu.confirmDropCollectionMessage", { name: props.node.label }),- confirmLabel: t("contextMenu.dropCollection"),- get loading() {- return dropMongoCollectionLoading.value;- },- closeOnConfirm: false,- confirm: confirmDropMongoCollection,- }),-);+function updateTableSearchQuery(value: string | number) {+ const parentId = tableSearchParentId.value;+ if (!parentId) return;+ const query = String(value);+ if (sidebarTreeContext?.setTableSearchQuery) {+ sidebarTreeContext.setTableSearchQuery(parentId, query);+ return;+ }+ connectionStore.setSidebarTableSearchQuery(parentId, query);+ void connectionStore.refreshSidebarTableSearch(parentId);+}-routeDangerDialog(showDropMongoIndexConfirm, () =>- dangerRequest({- title: t("contextMenu.confirmDropIndexTitle"),- message: t("contextMenu.confirmDropMongoIndexMessage", { name: mongoIndexNameForNode(props.node), collection: props.node.tableName || "" }),- details: mongoIndexDropPreview(props.node, mongoIndexNameForNode(props.node)),- confirmLabel: t("contextMenu.dropIndex"),- get loading() {- return dropMongoIndexLoading.value;- },- closeOnConfirm: false,- confirm: confirmDropMongoIndex,- }),-);+function clearTableSearchQuery() {+ updateTableSearchQuery("");+}-routeDangerDialog(showDropAllMongoIndexesConfirm, () =>- dangerRequest({- title: t("contextMenu.dropAllIndexes"),- message: t("contextMenu.confirmDropMongoAllIndexesMessage", { name: props.node.label }),- detailsText: t("contextMenu.confirmDropMongoAllIndexesDetails"),- sql: mongoDropAllIndexesPreview(props.node),- confirmLabel: t("contextMenu.dropAllIndexes"),- get loading() {- return dropAllMongoIndexesLoading.value;- },- closeOnConfirm: false,- confirm: confirmDropAllMongoIndexes,- }),-);+// --- Connection Group Management ---+const isRenamingGroup = ref(false);-routeDangerDialog(showFlushRedisDbConfirm, () =>- dangerRequest({- title: t("redis.flushDb"),- message: t("redis.flushDbMessage"),- details: t("redis.flushDbDetails", { db: props.node.database }),- confirmLabel: t("redis.flushDbConfirm"),- confirm: confirmFlushRedisDb,- }),-);+const renameInput = ref("");-routeDangerDialog(showDropSchemaConfirm, () =>- dangerRequest({- title: t("contextMenu.confirmDropSchemaTitle"),- message: t("contextMenu.confirmDropSchemaMessage", { name: props.node.label }),- get sql() {- return dropSchemaPreviewSql.value;- },- confirmLabel: t("contextMenu.dropSchema"),- confirm: confirmDropSchema,- }),-);+const renameInputRef = ref<HTMLInputElement>();-function moveToNewGroup() {- moveToNewGroupName.value = "";- showMoveToNewGroupDialog.value = true;+function startRenameGroup() {+ renameInput.value = activeNode.value.label;+ isRenamingGroup.value = true;+ emit("rename-started");+ focusSidebarRenameInput(() => (isRenamingGroup.value ? renameInputRef.value : undefined));}-function confirmMoveToNewGroup() {- const name = moveToNewGroupName.value.trim();- const node = sidebarFormTarget.value ?? props.node;- if (name && node.connectionId) {- const groupId = connectionStore.createConnectionGroup(name);- connectionStore.moveConnectionToGroup(node.connectionId, groupId);- }- showMoveToNewGroupDialog.value = false;-}+watch(+ () => props.pendingRename,+ (pending) => {+ if (pending && activeNode.value.type === "connection-group") startRenameGroup();+ },+ { immediate: true },+);-let treeItemDialogController: Record<string, any> | null = null;--function getTreeItemDialogController(): Record<string, any> {- if (treeItemDialogController) return treeItemDialogController;- treeItemDialogController = reactive<Record<string, any>>({- node: createSidebarActionTarget(props.node),- t,- highlight,- showDeleteConfirm,- connectionDeleteConfirmMessage,- confirmDelete,- connectionDeleteMenuLabel,- showMoveToNewGroupDialog,- moveToNewGroupName,- confirmMoveToNewGroup,- showDeleteGroupConfirm,- confirmDeleteGroup,- showRenameObjectDialog,- renameObjectName,- renameObjectPreviewSql,- renameObjectError,- confirmRenameObject,- showStructurePreviewDialog,- structurePreviewTitle,- isLoadingStructurePreview,- structurePreviewError,- structurePreviewSql,- copyStructurePreview,- saveStructurePreview,- showStructureDocCopyDialog,- structureDocCopyTitle,- structureDocCopyText,- selectTextareaContent,- copyStructureDocText,- showDuplicateDialog,- duplicateTableName,- confirmDuplicateStructure,- showPasteDialog,- pasteTableEntries,- pasteTableMode,- pasteTableDataCopySupported: pasteTableDataCopySupported.value,- confirmPasteTable,- showCreateDatabaseDialog,- createDatabaseName,- canSetCreateDatabaseCharset: canSetCreateDatabaseCharset.value,- createDatabaseCharset,- createDatabaseCharsetOptions,- createDatabaseCharsetLoading,- normalizeCreateDatabaseCharset,- createDatabaseCollation,- createDatabaseUsers,- createDatabaseSelectedUsers,- createDatabaseUsersLoading,- createDatabaseUserKey,- createDatabaseUserLabel,- createDatabaseUserSelected,- toggleCreateDatabaseUser,- showCreateDatabasePreviewDialog,- createDatabasePreviewSql,- createDatabaseAuthorizationResults,- createDatabaseAuthorizationApplying,- applyCreateDatabaseAuthorizationPlan,- createDatabaseAuthorizationStepLabel,- createDatabaseCollationOptionsForCharset,- createDatabaseCollationsByCharset,- confirmCreateDatabase,- showEditDatabasePropertiesDialog,- updateCreateDatabaseCharset,- canEditDatabaseCharsetCollation: canEditDatabaseCharsetCollation.value,- updateEditDatabaseCharset,- editDatabasePropertiesLoading,- editDatabaseCharset,- editDatabaseCollation,- canEditDatabaseComment: canEditDatabaseComment.value,- editDatabaseCommentText,- editDatabasePropertiesPreviewSql,- confirmEditDatabaseProperties,- showCreateNacosNamespaceDialog,- createNacosNamespaceId,- createNacosNamespaceName,- createNacosNamespaceDesc,- createNacosNamespaceLoading,- confirmCreateNacosNamespace,- showEditNacosNamespaceDialog,- editNacosNamespaceName,- editNacosNamespaceDesc,- editNacosNamespaceLoading,- confirmEditNacosNamespace,- showCreateSchemaDialog,- createSchemaName,- confirmCreateSchema,- showEditSchemaCommentDialog,- schemaCommentText,- schemaCommentLoading,- schemaCommentPreviewSql,- confirmEditSchemaComment,+function shouldMeasureLabelOverflow(): boolean {+ return shouldMeasureSidebarLabelOverflow({+ hasDetailTooltip: !!detailTooltip.value?.rows.length,+ isRenaming: isRenamingGroup.value,+ usesFullWidthLabel: usesFullWidthLabel.value,});- return treeItemDialogController;}-const availableGroups = computed(() => connectionStore.sidebarLayout.groups);--const currentGroupId = computed(() => {- if (props.node.type !== "connection" || !props.node.connectionId) return null;- const find = (entries: typeof connectionStore.sidebarLayout.order): string | null => {- for (const entry of entries) {- if (entry.type !== "group") continue;- if ((entry.children ?? entry.connectionIds?.map((id) => ({ type: "connection" as const, id })) ?? []).some((child) => child.type === "connection" && child.id === props.node.connectionId)) {- return entry.id;- }- const found = find(entry.children ?? []);- if (found) return found;- }- return null;- };- return find(connectionStore.sidebarLayout.order);-});--// --- Drag and Drop ----import { useDragSort } from "@/composables/useDragSort";+function finishRenameGroup() {+ // Guard against double invocation: pressing Enter sets isRenamingGroup=false+ // and unmounts the input, which then fires @blur -> finishRenameGroup again.+ // The first call can rebuild the tree and recycle activeNode.value onto a different+ // group, so a second run would act on the wrong group and cascade across+ // groups (issue #681).+ if (!isRenamingGroup.value) return;+ isRenamingGroup.value = false;+ const trimmed = renameInput.value.trim();+ // An empty name cancels the rename and keeps the group as-is — never delete+ // here. Deleting a group is done explicitly via the context menu (issue #681).+ if (!trimmed || trimmed === activeNode.value.label) return;+ connectionStore.renameConnectionGroup(activeNode.value.id, trimmed);+}const {state: dragState,@@ -4998,23 +677,27 @@ const {const isDraggable = computed(() => {if (props.dragDisabled) return false;- return props.node.type === "connection" || props.node.type === "connection-group";+ return activeNode.value.type === "connection" || activeNode.value.type === "connection-group";});-const isDropTarget = computed(() => props.node.type === "connection" || props.node.type === "connection-group");+const dragVisual = computed(() => ({+ isDropTarget: activeNode.value.type === "connection" || activeNode.value.type === "connection-group",+ showBefore: dragState.active && dragState.targetId === activeNode.value.id && dragState.dropPosition === "before",+ showAfter: dragState.active && dragState.targetId === activeNode.value.id && dragState.dropPosition === "after",+ showInside: dragState.active && dragState.targetId === activeNode.value.id && dragState.dropPosition === "inside",+ dragging: dragState.active && dragState.draggedId === activeNode.value.id,+}));-const showDropBefore = computed(() => dragState.active && dragState.targetId === props.node.id && dragState.dropPosition === "before");-const showDropAfter = computed(() => dragState.active && dragState.targetId === props.node.id && dragState.dropPosition === "after");-const showDropInside = computed(() => dragState.active && dragState.targetId === props.node.id && dragState.dropPosition === "inside");-const isDragging = computed(() => dragState.active && dragState.draggedId === props.node.id);const TABLE_REFERENCE_DRAG_THRESHOLD = 5;+const TABLE_REFERENCE_DRAGGING_CLASS = "dbx-table-reference-dragging";+const canDragTableReference = computed(() => {- if (props.dragDisabled || !props.node.connectionId) return false;- if (props.node.type === "database") return typeof props.node.database === "string" && props.node.database.trim().length > 0;- if (props.node.database == null) return false;- if (props.node.type === "table" || props.node.type === "view" || props.node.type === "materialized_view") return true;- return props.node.type === "column" && !!props.node.tableName;+ if (props.dragDisabled || !activeNode.value.connectionId) return false;+ if (activeNode.value.type === "database") return typeof activeNode.value.database === "string" && activeNode.value.database.trim().length > 0;+ if (activeNode.value.database == null) return false;+ if (activeNode.value.type === "table" || activeNode.value.type === "view" || activeNode.value.type === "materialized_view") return true;+ return activeNode.value.type === "column" && !!activeNode.value.tableName;});let pendingTableReferenceDrag: {@@ -5022,36 +705,38 @@ let pendingTableReferenceDrag: {startX: number;startY: number;} | null = null;+let draggingTableReferencePayload: QueryEditorTableReferencePayload | null = null;+let suppressNextTableReferenceClick = false;function tableReferenceDragPayload(): QueryEditorTableReferencePayload | null {if (!canDragTableReference.value) return null;- if (props.node.type === "database") {+ if (activeNode.value.type === "database") {return createTableReferencePayload({- connectionId: props.node.connectionId,- database: props.node.database,+ connectionId: activeNode.value.connectionId,+ database: activeNode.value.database,referenceType: "database",databaseType: currentDatabaseType(),});}- if (props.node.type === "column") {- const columnName = columnNameForDrag(props.node);- if (!props.node.tableName || !columnName) return null;+ if (activeNode.value.type === "column") {+ const columnName = columnNameForDrag(activeNode.value);+ if (!activeNode.value.tableName || !columnName) return null;return createTableReferencePayload({- connectionId: props.node.connectionId,- database: props.node.database,- schema: props.node.schema,- tableName: props.node.tableName,+ connectionId: activeNode.value.connectionId,+ database: activeNode.value.database,+ schema: activeNode.value.schema,+ tableName: activeNode.value.tableName,columnName,databaseType: currentDatabaseType(),});}const payload = createTableReferencePayload({- connectionId: props.node.connectionId,- database: props.node.database,- schema: props.node.schema,- tableName: props.node.label,+ connectionId: activeNode.value.connectionId,+ database: activeNode.value.database,+ schema: activeNode.value.schema,+ tableName: activeNode.value.label,databaseType: currentDatabaseType(),});return payload;@@ -5126,748 +811,95 @@ function startTableReferenceMouseDrag(event: MouseEvent) {function onRowMouseDown(event: MouseEvent) {if (isDraggable.value) {- startDrag(event, props.node.id, props.node.type);+ startDrag(event, activeNode.value.id, activeNode.value.type);} else if (canDragTableReference.value) {startTableReferenceMouseDrag(event);}}-// RecycleScroller reuses mounted TreeItem instances for different nodes, so the-// handler must follow the reactive node id rather than component mount lifetime.-const stopPasteHandlerRegistration = watch(- () => props.node.id,- (nodeId, _previousNodeId, onCleanup) => {- const unregister = sidebarTreeContext?.registerPasteHandler?.(nodeId, requestPasteTreeClipboard);- if (unregister) onCleanup(unregister);+watch(+ () => props.node,+ (node, previousNode) => {+ activeNode.value = node;+ if (node.id === previousNode.id) return;+ // Virtual rows are recycled; transient DOM and pointer state must not leak+ // from the previously rendered node into the new row.+ isRenamingGroup.value = false;+ renameInput.value = "";+ labelOverflowing.value = false;+ suppressNextTableReferenceClick = false;+ handleMouseLeave();+ finishTableReferenceDrag();},- { immediate: true },+ { flush: "sync" },);onBeforeUnmount(() => {- handleMouseLeave();stopPasteHandlerRegistration();+ handleMouseLeave();finishTableReferenceDrag();- stopDangerDialogRouting?.();});-const shortcutCopyName = computed(() => settingsStore.editorSettings.shortcuts.copySidebarSelection);-const shortcutOpenDataInNewTab = computed(() => settingsStore.editorSettings.shortcuts.openDataInNewTab);-const shortcutEditConnection = computed(() => settingsStore.editorSettings.shortcuts.editSidebarConnection);-const shortcutRename = "F2";-const shortcutRefresh = "F5";-const shortcutDelete = "Delete";--function exportDataSubmenu(): ContextMenuItem {- return {- label: t("contextMenu.exportData"),- icon: Upload,- children: [- { label: "CSV", action: () => exportData("csv") },- { label: "JSON", action: () => exportData("json") },- { label: "SQL INSERT", action: () => exportData("sql") },- { label: "XLSX", action: () => exportDataXlsx() },- ],- };-}--function copyStructureAsSubmenu(): ContextMenuItem {- return {- label: t("contextMenu.copyStructureAs"),- icon: Clipboard,- children: [- { label: t("contextMenu.copyStructureAsTsv"), action: () => copyStructureAs("tsv") },- { label: t("contextMenu.copyStructureAsMarkdown"), action: () => copyStructureAs("markdown") },- ],- };+function onToggleClick() {+ selectSingleTreeNode(props.node);+ rowRef.value?.focus({ preventScroll: true });+ treeRuntime.toggleNode(props.node);}-function moreActionsSubmenu(children: ContextMenuItem[]): ContextMenuItem {- return {- label: t("common.more"),- icon: ListTree,- children,- };+function onToggleMouseDown(event: MouseEvent) {+ if (event.button !== 0) return;+ selectSingleTreeNode(props.node);+ rowRef.value?.focus({ preventScroll: true });}-function savedSqlHistoryScopeForNode(node: TreeNode): SavedSqlHistoryScope | null {- if (!node.connectionId) return null;- if (node.type === "connection") {- return { connectionId: node.connectionId };+function onClick(event: MouseEvent) {+ if (suppressNextTableReferenceClick) {+ suppressNextTableReferenceClick = false;+ event.preventDefault();+ event.stopPropagation();+ return;+ }+ // The tree container clears selection on blank-area clicks, so row clicks+ // must remain isolated while the tree-level runtime performs the action.+ event.stopPropagation();+ const openMode = dataTabOpenModeFromTreeClick(props.node.type, event, settingsStore.editorSettings.shortcuts.openDataInNewTab);+ if (openMode === "new-tab") {+ event.preventDefault();+ if (event.detail > 1) return;+ selectSingleTreeNode(props.node);+ rowRef.value?.focus({ preventScroll: true });+ treeRuntime.openDataInNewTab(props.node);+ return;}- if ((node.type === "database" || node.type === "schema") && hasTreeNodeDatabaseContext(node)) {- return {- connectionId: node.connectionId,- database: node.database,- schema: node.type === "schema" ? node.schema : undefined,- };+ if (event.shiftKey) {+ selectTreeNodeRange(props.node);+ rowRef.value?.focus({ preventScroll: true });+ return;}- if ((node.type === "table" || node.type === "view") && hasTreeNodeDatabaseContext(node)) {- return {- connectionId: node.connectionId,- database: node.database,- schema: node.schema,- tableName: node.label,- };+ if (event.metaKey || event.ctrlKey) {+ toggleTreeNodeSelection(props.node);+ rowRef.value?.focus({ preventScroll: true });+ return;}- return null;+ selectSingleTreeNode(props.node);+ rowRef.value?.focus({ preventScroll: true });+ if (settingsStore.editorSettings.sidebarActivation === "double") return;+ treeRuntime.handleRowClick(props.node, event.detail);}-async function openSavedSqlHistoryFile(fileId: string) {- const file = await savedSqlStore.ensureFileContent(fileId);- if (!file) return;- queryStore.openSavedSql(file);- connectionStore.activeConnectionId = file.connectionId;- void savedSqlStore.recordFileUsage(file.id);+function onDoubleClick(event: MouseEvent) {+ treeRuntime.handleRowDoubleClick(props.node, event);}-function savedSqlHistorySubmenu(): ContextMenuItem | null {- const scope = savedSqlHistoryScopeForNode(props.node);- if (!scope) return null;- const files = rankSavedSqlHistory(savedSqlStore.allFiles, { ...scope, limit: 10 });- return {- label: t("contextMenu.sqlHistory"),- icon: ScrollText,- children:- files.length > 0- ? files.map((file) => ({- label: file.name,- action: () => openSavedSqlHistoryFile(file.id),- icon: FileCode,- }))- : [- {- label: t("contextMenu.noSqlHistory"),- disabled: true,- },- ],- };+function onTreeItemContextMenu(event: MouseEvent) {+ if (!connectionStore.selectedTreeNodeIds.includes(props.node.id)) selectSingleTreeNode(props.node);+ else connectionStore.selectedTreeNodeId = props.node.id;+ rowRef.value?.focus({ preventScroll: true });+ emit("context-menu", event, props.node);}-function treeItemMenuItems(): ContextMenuItem[] {- const node = props.node;- const items: ContextMenuItem[] = [];- const batchDropCount = selectedBatchDropTargets().length;- const batchEmptyCount = selectedBatchEmptyTargets().length;- const batchTruncateCount = selectedBatchTruncateTargets().length;- const deleteMenuLabel = (singleLabel: string) => (batchDropCount > 1 ? batchDropMenuLabel() : singleLabel);- const deleteMenuAction = (singleAction: () => void) => (batchDropCount > 1 ? requestBatchDrop : singleAction);- const truncateMenuLabel = (singleLabel: string) => (batchTruncateCount > 1 ? batchTruncateMenuLabel() : singleLabel);- const truncateMenuAction = (singleAction: () => void) => (batchTruncateCount > 1 ? requestBatchTruncate : singleAction);- const emptyMenuLabel = (singleLabel: string) => (batchEmptyCount > 1 ? batchEmptyMenuLabel() : singleLabel);- const emptyMenuAction = (singleAction: () => void) => (batchEmptyCount > 1 ? requestBatchEmpty : singleAction);-- // 1. Pin toggle- if (canPin.value) {- items.push({- label: isPinned.value ? t("contextMenu.unpin") : t("contextMenu.pin"),- action: togglePin,- icon: Pin,- });- if (hasTypeMenu.value) items.push({ label: "", separator: true });- }-- // 2. Connection- if (node.type === "connection") {- if (isConnecting.value) {- items.push({ label: t("connection.cancelConnecting"), action: cancelConnectionAttempt, icon: X });- } else if (!isConnected.value) {- items.push({ label: t("contextMenu.openConnection"), action: toggle, icon: Plug });- } else {- items.push({ label: t("contextMenu.closeConnection"), action: disconnectConnection, icon: Unplug });- }- items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });- if (currentDatabaseType() === "redis") {- items.push({ label: t("contextMenu.instanceInfo"), action: openRedisInstanceInfo, icon: Info });- }- const sqlHistoryMenu = savedSqlHistorySubmenu();- if (sqlHistoryMenu) items.push(sqlHistoryMenu);- if (node.connectionId && connectionSupportsDatabaseUserAdmin(connectionStore.getConfig(node.connectionId))) {- items.push({ label: t("contextMenu.userAdmin"), action: openUserAdmin, icon: UsersRound });- }- if (node.connectionId && connectionSupportsProcessList(connectionStore.getConfig(node.connectionId))) {- items.push({ label: t("contextMenu.processList"), action: openProcessList, icon: Activity });- }- if (node.connectionId && (connectionSupportsServerDashboard(connectionStore.getConfig(node.connectionId)) || connectionSupportsPgServerDashboard(connectionStore.getConfig(node.connectionId)))) {- items.push({ label: t("contextMenu.serverDashboard"), action: openServerDashboard, icon: Gauge });- }- if (currentDatabaseType() === "dameng") {- items.push({ label: t("contextMenu.damengJobAdmin"), action: openDamengJobAdmin, icon: CalendarClock });- }- if (canCopyFinalProxyPort.value) {- items.push({ label: t("contextMenu.copyFinalProxyPort"), action: copyFinalProxyPort, icon: Network });- }- if (canOpenSqlFileExecution.value) {- items.push({ label: t("sqlFile.title"), action: openSqlFileExecution, icon: FileCode });- }- if (canExportAllDatabases.value) {- items.push({ label: t("contextMenu.exportAllDatabases"), action: openAllDatabasesExport, icon: Upload });- if (isTauriRuntime()) {- items.push({ label: t("databaseBackup.title"), action: openScheduledBackups, icon: CalendarClock });- }- }- if (canCreateDatabase.value) {- items.push({- label: connectionNamespaceCreationLabel(),- action: openConnectionNamespaceCreation,- icon: Plus,- });- }- if (canCreateNacosNamespace.value) {- items.push({- label: t("nacos.createNamespace"),- action: openCreateNacosNamespaceDialog,- icon: FolderPlus,- });- }- items.push({ label: "", separator: true });- if (availableGroups.value.length > 0 || currentGroupId.value) {- const groupChildren: ContextMenuItem[] = availableGroups.value.map((group: { id: string; name: string }) => ({- label: group.name,- action: () => moveToGroup(group.id),- icon: FolderOpen,- disabled: group.id === currentGroupId.value,- }));- if (currentGroupId.value) {- groupChildren.push({ label: "", separator: true });- groupChildren.push({ label: t("connectionGroup.ungrouped"), action: () => moveToGroup(null) });- }- groupChildren.push({ label: "", separator: true });- groupChildren.push({ label: t("connectionGroup.newGroup"), action: moveToNewGroup, icon: FolderPlus });- items.push({ label: t("connectionGroup.moveToGroup"), icon: FolderInput, children: groupChildren });- } else {- items.push({ label: t("connectionGroup.moveToNewGroup"), action: moveToNewGroup, icon: FolderPlus });- }- items.push({- label: t("contextMenu.refreshChildren"),- action: refresh,- icon: RefreshCw,- shortcut: shortcutRefresh,- });- if (canConfigureVisibleDatabases.value) {- items.push({- label: t("contextMenu.configureVisibleObjects"),- action: openVisibleDatabasesDialog,- icon: ListFilter,- });- } else if (canConfigureVisibleSchemas.value) {- items.push({- label: t("visibleSchemas.title"),- action: openVisibleSchemasDialog,- icon: ListFilter,- });- }- if (canConfigureVisibleSchemas.value) {- items.push({- label: t("visibleSchemas.title"),- action: openVisibleSchemasDialog,- icon: ListFilter,- });- }- items.push({ label: t("contextMenu.editConnection"), action: editConnection, icon: Pencil, shortcut: shortcutEditConnection.value });- if (revealConnectionFilePath.value) {- items.push({- label: t("contextMenu.revealDatabaseFile"),- action: revealDatabaseFile,- icon: FolderOpen,- });- }- if (canBackupSqliteDatabase.value) {- items.push({- label: t("contextMenu.backupSqliteDatabase"),- action: backupSqliteDatabase,- icon: HardDriveDownload,- });- }- items.push({ label: connectionDuplicateMenuLabel(), action: duplicateConnection, icon: CopyPlus });- items.push({ label: "", separator: true });- items.push({- label: connectionDeleteMenuLabel(),- action: deleteConnection,- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- return items;- }-- // 3. Connection Group- if (node.type === "connection-group") {- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- items.push({ label: "", separator: true });- items.push({ label: t("toolbar.newConnection"), action: newConnectionInGroup, icon: Plus });- items.push({ label: t("connectionGroup.newGroup"), action: newSubgroup, icon: FolderPlus });- items.push({ label: "", separator: true });- items.push({- label: t("connectionGroup.renameGroup"),- action: startRenameGroup,- icon: Pencil,- shortcut: shortcutRename,- });- items.push({ label: "", separator: true });- items.push({- label: t("connectionGroup.deleteGroup"),- action: deleteConnectionGroup,- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- return items;- }-- // 4. Database / Schema- if (node.type === "database" || node.type === "schema") {- if (canCloseDatabaseConnection.value) {- items.push({ label: t("contextMenu.closeDatabaseConnection"), action: closeDatabaseConnection, icon: Unplug });- items.push({ label: "", separator: true });- }- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- items.push({ label: "", separator: true });- if (canOpenObjectBrowser.value) {- items.push({ label: t("contextMenu.openObjectBrowser"), action: openObjectBrowser, icon: TableProperties });- }- items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });- const sqlHistoryMenu = savedSqlHistorySubmenu();- if (sqlHistoryMenu) items.push(sqlHistoryMenu);- if (node.type === "database" && currentDatabaseType() !== "cloudflare-d1") {- if (!isNodeDefaultDatabase.value) {- items.push({ label: t("contextMenu.setDefaultDatabase"), action: setNodeAsDefaultDatabase, icon: Database });- } else {- items.push({ label: t("contextMenu.clearDefaultDatabase"), action: clearNodeDefaultDatabase, icon: Database });- }- }- if (canEditDatabaseProperties.value) {- items.push({ label: t("contextMenu.editDatabaseProperties"), action: openEditDatabasePropertiesDialog, icon: SquarePen });- }- if (canCreateTable.value) {- items.push({ label: t("contextMenu.createTable"), action: createTable, icon: Plus });- }- if (canOpenTableImport.value) {- items.push({ label: t("contextMenu.importData"), action: openTableImport, icon: Download });- }- if (canCreateSchema.value) {- items.push({ label: t("contextMenu.createSchema"), action: openCreateSchemaDialog, icon: Plus });- }- if (canEditSchemaComment.value) {- items.push({ label: t("contextMenu.editSchemaComment"), action: openEditSchemaCommentDialog, icon: SquarePen });- }- if (canOpenSqlFileExecution.value) {- items.push({ label: t("sqlFile.title"), action: openSqlFileExecution, icon: FileCode });- }- if (canOpenDiagram.value) {- items.push({ label: t("diagram.open"), action: openDiagram, icon: Network });- }- if (canOpenDatabaseSearch.value) {- items.push({ label: t("databaseSearch.open"), action: openDatabaseSearch, icon: Search });- }- items.push({- label: t("contextMenu.refreshChildren"),- action: refresh,- icon: RefreshCw,- shortcut: shortcutRefresh,- });- if (canConfigureVisibleSchemas.value) {- items.push({- label: t("visibleSchemas.title"),- action: openVisibleSchemasDialog,- icon: ListFilter,- });- }- items.push({ label: "", separator: true });- items.push({ label: t("transfer.dataTransfer"), action: openTransfer, icon: ArrowRightLeft });- items.push({ label: t("diff.title"), action: openSchemaDiff, icon: ArrowRightLeft });- items.push({ label: t("dataCompare.title"), action: openDataCompare, icon: ArrowRightLeft });- items.push({ label: t("contextMenu.exportDatabase"), action: openDatabaseExport, icon: Upload });- const destructiveActions: ContextMenuItem[] = [];- if (canDropDatabase.value) {- destructiveActions.push({- label: t("contextMenu.dropDatabase"),- action: dropDatabase,- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- }- if (destructiveActions.length > 0) {- items.push({ label: "", separator: true });- items.push(moreActionsSubmenu(destructiveActions));- }- if (canDropSchema.value) {- items.push({ label: "", separator: true });- }- if (canDropSchema.value) {- items.push({- label: t("contextMenu.dropSchema"),- action: dropSchema,- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- }- return items;- }-- // 5. Redis DB / Mongo DB- if (node.type === "etcd-root" || node.type === "zookeeper-root") {- items.push({ label: t("contextMenu.openConnection"), action: toggle, icon: Database });- return items;- }-- if (node.type === "user-admin") {- items.push({ label: t("contextMenu.openUserAdmin"), action: openUserAdmin, icon: UsersRound });- return items;- }-- if (node.type === "dameng-job-admin") {- items.push({ label: t("contextMenu.openDamengJobAdmin"), action: openDamengJobAdmin, icon: CalendarClock });- return items;- }-- if (node.type === "redis-db" || node.type === "mongo-db") {- items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });- if (!isNodeDefaultDatabase.value) {- items.push({ label: t("contextMenu.setDefaultDatabase"), action: setNodeAsDefaultDatabase, icon: Database });- } else {- items.push({ label: t("contextMenu.clearDefaultDatabase"), action: clearNodeDefaultDatabase, icon: Database });- }- if (node.type === "mongo-db") {- items.push({ label: "", separator: true });- items.push({ label: t("transfer.dataTransfer"), action: openTransfer, icon: ArrowRightLeft });- }- if (node.type === "redis-db") {- items.push({ label: "", separator: true });- items.push({ label: t("redis.flushDb"), action: flushRedisDb, icon: Eraser, variant: "destructive" as const });- }- if (canDropMongoDatabase.value) {- items.push({ label: "", separator: true });- items.push(- moreActionsSubmenu([- {- label: t("contextMenu.dropDatabase"),- action: dropDatabase,- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- },- ]),- );- }- return items;- }-- if (node.type === "nacos-namespace") {- items.push({ label: t("contextMenu.openConnection"), action: toggle, icon: FolderOpen });- if (canEditNacosNamespace.value) {- items.push({ label: t("nacos.editNamespace"), action: openEditNacosNamespaceDialog, icon: Pencil });- }- items.push({- label: t("contextMenu.refreshChildren"),- action: refresh,- icon: RefreshCw,- shortcut: shortcutRefresh,- });- items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- return items;- }-- if (node.type === "mongo-collection") {- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.viewData"), action: toggle, icon: TableProperties });- items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });- if (canDropAllMongoIndexes.value || canDropMongoCollection.value) {- items.push({ label: "", separator: true });- if (canDropAllMongoIndexes.value) {- items.push({ label: t("contextMenu.dropAllIndexes"), action: dropAllMongoIndexes, icon: Trash2, variant: "destructive" as const });- }- if (canDropMongoCollection.value) {- items.push({ label: t("contextMenu.dropCollection"), action: dropMongoCollection, icon: Trash2, shortcut: shortcutDelete, variant: "destructive" as const });- }- }- return items;- }-- if (node.type === "elasticsearch-index" || node.type === "vector-collection") {- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.viewData"), action: toggle, icon: TableProperties });- items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });- return items;- }-- // 6. Table / View / Materialized View- if (node.type === "table" || node.type === "view" || node.type === "materialized_view") {- const destructiveActions: ContextMenuItem[] = [];- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.viewData"), action: openDataImmediately, icon: TableProperties });- items.push({- label: t("contextMenu.openInNewDataTab"),- action: openDataInNewTabImmediately,- icon: CopyPlus,- shortcut: shortcutOpenDataInNewTab.value,- });- if (node.type === "table") {- items.push({- label: t("contextMenu.viewDdl"),- action: () => emit("open-ddl", node),- icon: FileCode,- });- }- if (node.type === "view" || node.type === "materialized_view") {- items.push({ label: t("contextMenu.editView"), action: () => openObjectSourceDialog(true), icon: Pencil });- items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });- items.push({- label: t("contextMenu.viewDdl"),- action: () => emit("open-ddl", node),- icon: FileCode,- });- }- if (canOpenStructureEditor.value) {- items.push({ label: t("contextMenu.editStructure"), action: openStructureEditor, icon: PencilRuler });- }- if (canRenameObject.value) {- items.push({- label: t("contextMenu.renameObject"),- action: openRenameObjectDialog,- icon: Pencil,- shortcut: shortcutRename,- });- }- if (node.type === "view" || node.type === "materialized_view") {- destructiveActions.push({- label: deleteMenuLabel(t("contextMenu.dropView")),- action: deleteMenuAction(requestDropObject),- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- }- items.push({- label: t("contextMenu.generateSql"),- icon: FilePlus,- children: isTableNotView.value- ? [- { label: "SELECT", action: newSelectTemplate, icon: TerminalSquare },- { label: "INSERT", action: newInsertTemplate, icon: FilePlus },- { label: "UPDATE", action: newUpdateTemplate, icon: SquarePen },- { label: "DELETE", action: newDeleteTemplate, icon: ListX },- { label: "DDL", action: generateDdlTemplate, icon: FileCode },- ]- : [- { label: "SELECT", action: newSelectTemplate, icon: TerminalSquare },- { label: "DDL", action: generateDdlTemplate, icon: FileCode },- ],- });- const sqlHistoryMenu = savedSqlHistorySubmenu();- if (sqlHistoryMenu) items.push(sqlHistoryMenu);- if (canOpenDiagram.value) {- items.push({ label: t("diagram.open"), action: openDiagram, icon: Network });- }- if (canOpenTableImport.value) {- items.push({ label: t("contextMenu.importData"), action: openTableImport, icon: Download });- }- if (isTableNotView.value) {- items.push({ label: t("dataCompare.title"), action: openDataCompare, icon: ArrowRightLeft });- }- items.push({ label: "", separator: true });- items.push(exportDataSubmenu());- items.push({ label: t("contextMenu.exportDatabase"), action: openDatabaseExport, icon: Upload });- items.push({ label: t("contextMenu.exportStructure"), action: exportStructure, icon: FileCode });- items.push(copyStructureAsSubmenu());- if (isTableNotView.value) {- items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.duplicateStructure"), action: duplicateStructure, icon: CopyPlus });- items.push({ label: t("contextMenu.copyTable"), action: copyTableToClipboard, icon: Copy });- if (supportsTruncate.value) {- destructiveActions.push({- label: truncateMenuLabel(t("contextMenu.truncateTable")),- action: truncateMenuAction(truncateTable),- icon: Scissors,- variant: "destructive" as const,- });- }- destructiveActions.push({- label: emptyMenuLabel(t("contextMenu.emptyTable")),- action: emptyMenuAction(emptyTable),- icon: Eraser,- variant: "destructive" as const,- });- destructiveActions.push({- label: deleteMenuLabel(t("contextMenu.dropTable")),- action: deleteMenuAction(dropTable),- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- }- if (destructiveActions.length > 0) {- items.push({ label: "", separator: true });- items.push(moreActionsSubmenu(destructiveActions));- }- items.push({ label: "", separator: true });- items.push({- label: t("contextMenu.refreshChildren"),- action: refresh,- icon: RefreshCw,- shortcut: shortcutRefresh,- });- return items;- }-- // 7. Column- if (node.type === "column") {- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- const columnActions: ContextMenuItem[] = [];- if (canOpenStructureEditor.value) {- columnActions.push({ label: t("contextMenu.editColumn"), action: openStructureEditor, icon: PencilRuler });- }- if (canOpenFieldLineage.value) {- columnActions.push({ label: t("lineage.open"), action: openFieldLineage, icon: Network });- }- if (columnActions.length > 0) {- items.push({ label: "", separator: true });- items.push(...columnActions);- }- if (canDropTableChildObject.value) {- items.push({ label: "", separator: true });- items.push({- label: deleteMenuLabel(dropTableChildObjectMenuLabel()),- action: deleteMenuAction(requestDropTableChildObject),- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- }- return items;- }-- if (node.type === "index" || node.type === "fkey" || node.type === "trigger") {- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- if (node.type === "index" && canOpenStructureEditor.value) {- items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.editIndex"), action: openStructureEditor, icon: PencilRuler });- }- if (node.type === "index" && canDropMongoIndex.value) {- items.push({ label: "", separator: true });- items.push({- label: deleteMenuLabel(t("contextMenu.dropIndex")),- action: deleteMenuAction(dropMongoIndex),- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- } else if (canDropTableChildObject.value) {- items.push({ label: "", separator: true });- items.push({- label: deleteMenuLabel(dropTableChildObjectMenuLabel()),- action: deleteMenuAction(requestDropTableChildObject),- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- }- return items;- }-- // 8. Procedure / Function / Package- if (node.type === "procedure" || node.type === "function") {- if (node.type === "procedure") {- items.push({ label: t("contextMenu.executeProcedure"), action: openProcedureExecution, icon: Play });- }- items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });- if (canRenameObject.value) {- items.push({- label: t("contextMenu.renameObject"),- action: openRenameObjectDialog,- icon: Pencil,- shortcut: shortcutRename,- });- }- items.push({ label: "", separator: true });- items.push({- label: deleteMenuLabel(node.type === "procedure" ? t("contextMenu.dropProcedure") : t("contextMenu.dropFunction")),- action: deleteMenuAction(requestDropObject),- icon: Trash2,- shortcut: shortcutDelete,- variant: "destructive" as const,- });- return items;- }-- if (node.type === "sequence") {- items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });- items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- return items;- }-- if (node.type === "package" || node.type === "package-body") {- items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });- items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- return items;- }-- // 8.5 Extension- if (node.type === "extension") {- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- return items;- }-- // 9. Group Labels (group-columns, group-tables, etc.)- if (isGroupLabel(node)) {- const hasGroupCreateAction = (node.type === "group-tables" && canCreateTable.value) || (node.type === "group-views" && !!node.connectionId && !!node.database);- const canLoadAllObjectGroup = node.type === "group-tables" || node.type === "group-views" || node.type === "group-materialized-views";- if (node.type === "group-tables" && canCreateTable.value) {- items.push({ label: t("contextMenu.createTable"), action: createTable, icon: Plus });- if (canOpenTableImport.value) {- items.push({ label: t("contextMenu.importData"), action: openTableImport, icon: Upload });- }- if (canPasteTreeClipboardToCurrentNode()) {- items.push({ label: t("contextMenu.pasteTable"), action: openPasteTableDialog, icon: Clipboard });- }- }- if (node.type === "group-views" && node.connectionId && node.database) {- items.push({ label: t("contextMenu.createView"), action: createView, icon: Plus });- }- if (hasGroupCreateAction) {- items.push({ label: "", separator: true });- }- if (node.type === "group-extensions") {- items.push({- label: t("contextMenu.manageExtension"),- action: () => openInstallExtensionDialog(node),- icon: Plus,- });- items.push({ label: "", separator: true });- }- if (canLoadAllObjectGroup) {- items.push({- label: t("contextMenu.expandAll"),- action: loadAllObjectGroupChildren,- icon: ChevronsDown,- disabled: node.isLoading,- });- }- if (node.type !== "group-partitions") {- items.push({- label: t("contextMenu.refreshChildren"),- action: refresh,- icon: RefreshCw,- shortcut: shortcutRefresh,- });- }- return items;- }-- // 10. Universal Copy Name (for all types except connection)- if (hasTypeMenu.value) {- items.push({ label: "", separator: true });- items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });- }-- return items;+function onKeydown(event: KeyboardEvent) {+ treeRuntime.handleRowKeydown(props.node, event);}</script>@@ -5903,32 +935,32 @@ function treeItemMenuItems(): ContextMenuItem[] {rowWidthClass,{'group/sidebar-row': true,- 'ring-1 ring-primary/50 bg-primary/5': showDropInside,- 'opacity-50': isDragging,+ 'ring-1 ring-primary/50 bg-primary/5': dragVisual.showInside,+ 'opacity-50': dragVisual.dragging,'tree-item-connection-tint': connectionColor,'hover:bg-accent': node.type !== 'connection','hover:bg-secondary/60': node.type === 'connection',- rounded: !isTreeRowSelected,- 'tree-item-active': isTreeRowSelected,- 'tree-item-active--selection-set': usesSelectionSetHighlight && isTreeRowSelected,+ rounded: !selectionVisual.rowSelected,+ 'tree-item-active': selectionVisual.rowSelected,+ 'tree-item-active--selection-set': selectionVisual.usesSelectionSetHighlight && selectionVisual.rowSelected,'tree-item-highlight': highlighted,},]"- :tabindex="isSelected || isMultiSelected ? 0 : -1"+ :tabindex="selectionVisual.selected || selectionVisual.multiSelected ? 0 : -1":style="rowStyle"@click="onClick"@dblclick="onDoubleClick"@keydown="onKeydown"@mousedown="onRowMouseDown"- @mousemove="isDropTarget ? updateTarget($event, node.id, node.type) : undefined"+ @mousemove="dragVisual.isDropTarget ? updateTarget($event, node.id, node.type) : undefined"@mouseenter="handleMouseEnter"@mouseleave="clearTarget(node.id);handleMouseLeave();">- <div v-if="showDropBefore" class="absolute right-2 top-0 h-0.5 bg-primary rounded-full pointer-events-none" :style="{ left: paddingLeft }" />- <div v-if="showDropAfter" class="absolute right-2 bottom-0 h-0.5 bg-primary rounded-full pointer-events-none" :style="{ left: paddingLeft }" />+ <div v-if="dragVisual.showBefore" class="absolute right-2 top-0 h-0.5 bg-primary rounded-full pointer-events-none" :style="{ left: paddingLeft }" />+ <div v-if="dragVisual.showAfter" class="absolute right-2 bottom-0 h-0.5 bg-primary rounded-full pointer-events-none" :style="{ left: paddingLeft }" /><template v-if="canExpand"><button type="button" class="-m-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-muted hover:text-foreground" @mousedown.stop="onToggleMouseDown" @click.stop="onToggleClick"><Loader2 v-if="node.isLoading" class="w-3.5 h-3.5 animate-spin" />@@ -5939,7 +971,7 @@ function treeItemMenuItems(): ContextMenuItem[] {<span v-else class="w-3.5 h-3.5 shrink-0" /><DatabaseIcon v-if="node.type === 'connection'" :db-type="connectionIconType(node.connectionId)" class="h-3.5 w-3.5 shrink-0" /><Loader2 v-else-if="node.type === 'load-more' && node.isLoading" class="w-3.5 h-3.5 shrink-0 animate-spin text-primary" />- <component v-else :is="getIconInfo(node)?.icon || Database" class="w-3.5 h-3.5 shrink-0" :class="nodeIconClass" />+ <component v-else :is="getIconInfo(node)?.icon || Database" class="w-3.5 h-3.5 shrink-0" :class="databaseOpenVisual.iconClass" /><inputv-if="isRenamingGroup"ref="renameInputRef"@@ -5966,7 +998,7 @@ function treeItemMenuItems(): ContextMenuItem[] {<span v-if="columnComment" class="sidebar-object-comment ml-auto max-w-[20%] shrink-0 truncate text-right" :class="{ 'sidebar-object-comment--windows': useWindowsSidebarCommentFont }">{{ columnComment }}</span><span v-if="tableComment" class="sidebar-object-comment ml-auto max-w-[20%] shrink-0 truncate text-right" :class="{ 'sidebar-object-comment--windows': useWindowsSidebarCommentFont }">{{ tableComment }}</span><span v-if="node.type === 'connection' && node.connectionId && connectionStore.connectedIds.has(node.connectionId)" class="w-1.5 h-1.5 rounded-full bg-green-500 shrink-0" />- <span v-if="showsDatabaseOpenIndicator" class="w-1.5 h-1.5 rounded-full bg-green-500 shrink-0" />+ <span v-if="databaseOpenVisual.showsIndicator" class="w-1.5 h-1.5 rounded-full bg-green-500 shrink-0" /><Badge v-if="isConnectionReadonly" variant="secondary" class="h-4 px-1.5 text-[10px] gap-0.5"><Lock class="w-2.5 h-2.5" />{{ t("connection.readOnlyBadge") }}</Badge><ConnectionErrorIndicator v-if="node.type === 'connection'" :connection-id="node.connectionId" trigger-class="h-4 w-4" /><Pin v-if="isPinned" class="w-3 h-3 shrink-0 text-primary fill-current" aria-hidden="true" />diff --git a/apps/desktop/src/composables/useSidebarConnectionMutationRuntime.ts b/apps/desktop/src/composables/useSidebarConnectionMutationRuntime.tsnew file mode 100644index 0000000000..3d55ab2b57--- /dev/null+++ b/apps/desktop/src/composables/useSidebarConnectionMutationRuntime.ts@@ -0,0 +1,328 @@+import { computed, type ShallowRef } from "vue";+import { useI18n } from "vue-i18n";+import { useToast } from "@/composables/useToast";+import { useConnectionStore } from "@/stores/connectionStore";+import { useQueryStore } from "@/stores/queryStore";+import type { TreeNode } from "@/types/database";+import * as api from "@/lib/backend/api";+import { translateBackendError } from "@/i18n/backend-errors";+import { copyToClipboard } from "@/lib/common/clipboard";+import { uuid } from "@/lib/common/utils";+import { connectionFilePath, defaultSqliteBackupFileName, isMemorySqlitePath, sqliteBackupSourcePath } from "@/lib/connection/connectionFile";+import { hasEnabledTransportLayers } from "@/lib/backend/connectionTransport";+import { isTauriRuntime } from "@/lib/backend/tauriRuntime";+import { revealPathInFileManager } from "@/lib/backend/tauri";+import { canConfigureVisibleSchemasForTreeNode } from "@/lib/database/databaseFeatureSupport";+import { canCloseSidebarDatabaseConnection } from "@/lib/sidebar/sidebarDatabaseOpenState";+import { selectedConnectionDeleteTargets, selectedConnectionDuplicateTargets } from "@/lib/sidebar/sidebarConnectionSelection";+import { connectionDeleteTargetSnapshot, showDeleteConfirm, showDeleteGroupConfirm, sidebarFormTarget } from "@/components/sidebar/sidebarTreeDialogState";++interface SidebarConnectionMutationRuntimeOptions {+ activeNode: ShallowRef<TreeNode>;+ releaseActiveNodeReference: (nodeIds: readonly string[]) => void;+ selectedTreeNodesInVisibleOrder: () => TreeNode[];+ connectionStore: ReturnType<typeof useConnectionStore>;+ queryStore: ReturnType<typeof useQueryStore>;+ requestGroupRename: (groupId: string) => void;+ groupCreated: (groupId: string) => void;+ openVisibleDatabases: (node: TreeNode) => void;+ openVisibleSchemas: (node: TreeNode) => void;+}++export function useSidebarConnectionMutationRuntime(options: SidebarConnectionMutationRuntimeOptions) {+ const { t } = useI18n();+ const { toast } = useToast();+ const { activeNode, selectedTreeNodesInVisibleOrder, connectionStore, queryStore } = options;++ async function setNodeAsDefaultDatabase() {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ try {+ await connectionStore.setDefaultDatabase(node.connectionId, node.database);+ } catch (error: any) {+ toast(t("connection.saveFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function clearNodeDefaultDatabase() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ try {+ await connectionStore.clearDefaultDatabase(node.connectionId);+ } catch (error: any) {+ toast(t("connection.saveFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ function connectionDeleteTargets() {+ if (showDeleteConfirm.value && connectionDeleteTargetSnapshot.value.length) return connectionDeleteTargetSnapshot.value;+ return selectedConnectionDeleteTargets(activeNode.value, selectedTreeNodesInVisibleOrder());+ }++ function connectionDeleteMenuLabel(): string {+ const count = connectionDeleteTargets().length;+ return count > 1 ? t("contextMenu.deleteSelectedConnections", { count }) : t("contextMenu.deleteConnection");+ }++ function connectionDuplicateTargets() {+ return selectedConnectionDuplicateTargets(activeNode.value, selectedTreeNodesInVisibleOrder());+ }++ function connectionDuplicateMenuLabel(): string {+ const count = connectionDuplicateTargets().length;+ return count > 1 ? t("contextMenu.duplicateSelectedConnections", { count }) : t("contextMenu.duplicateConnection");+ }++ function connectionDeleteConfirmMessage(): string {+ const targets = connectionDeleteTargets();+ return targets.length > 1 ? t("contextMenu.confirmDeleteSelectedMessage", { count: targets.length }) : t("contextMenu.confirmDeleteMessage", { name: targets[0]?.label || sidebarFormTarget.value?.label || activeNode.value.label });+ }++ function deleteConnection() {+ const targets = selectedConnectionDeleteTargets(activeNode.value, selectedTreeNodesInVisibleOrder());+ if (!targets.length) return;+ connectionDeleteTargetSnapshot.value = targets.slice();+ showDeleteConfirm.value = true;+ }++ async function confirmDelete() {+ const targets = connectionDeleteTargets();+ if (!targets.length) return;+ const connectionIds = targets.map((target) => target.connectionId);+ try {+ await connectionStore.removeConnections(connectionIds);+ options.releaseActiveNodeReference(targets.map((target) => target.id));+ for (const connectionId of connectionIds) {+ connectionStore.disconnect(connectionId).catch((error) => {+ // Removal has already succeeded; disconnect cleanup must not turn it into a failed delete.+ console.warn("[DBX][connection:delete:disconnect-failed]", { connectionId, error });+ });+ }+ toast(targets.length > 1 ? t("connection.deletedSelected", { count: targets.length }) : t("connection.deleted"), 2000);+ } catch (error: any) {+ toast(t("connection.saveFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function copyFinalProxyPort() {+ const connectionId = activeNode.value.connectionId;+ const config = connectionId ? connectionStore.getConfig(connectionId) : undefined;+ if (!config || !hasEnabledTransportLayers(config)) return;++ try {+ const port = await api.connectionFinalProxyPort(config);+ await copyToClipboard(String(port));+ toast(t("contextMenu.finalProxyPortCopied", { port }), 2000);+ } catch (error: any) {+ toast(t("grid.copyFailed", { message: translateBackendError(t, error?.message || String(error)) }), 5000);+ }+ }++ async function duplicateConnection() {+ const targets = connectionDuplicateTargets();+ if (!targets.length) return;+ let duplicatedCount = 0;+ for (const target of targets) {+ const config = connectionStore.getConfig(target.connectionId);+ if (!config) continue;+ const newConfig = { ...config, id: uuid(), name: `${config.name} (Copy)` };+ await connectionStore.addConnection(newConfig, connectionStore.groupIdForConnection(target.connectionId));+ duplicatedCount += 1;+ }+ if (!duplicatedCount) return;+ toast(duplicatedCount > 1 ? t("connection.duplicatedSelected", { count: duplicatedCount }) : t("connection.duplicated"), 2000);+ }++ function editConnection() {+ const connectionId = activeNode.value.connectionId;+ if (connectionId) connectionStore.startEditing(connectionId);+ }++ const revealConnectionFilePath = computed<string | null>(() => {+ if (activeNode.value.type !== "connection" || !activeNode.value.connectionId) return null;+ const config = connectionStore.getConfig(activeNode.value.connectionId);+ return config ? connectionFilePath(config) : null;+ });++ async function revealDatabaseFile() {+ const path = revealConnectionFilePath.value;+ if (!path) return;+ try {+ await revealPathInFileManager(path);+ } catch (error: any) {+ toast(typeof error === "string" ? error : error?.message || String(error), 5000);+ }+ }++ const sqliteBackupSource = computed<string | null>(() => {+ if (activeNode.value.type !== "connection" || !activeNode.value.connectionId) return null;+ const config = connectionStore.getConfig(activeNode.value.connectionId);+ return config ? sqliteBackupSourcePath(config) : null;+ });++ const canBackupSqliteDatabase = computed(() => {+ const source = sqliteBackupSource.value;+ if (!source || !activeNode.value.connectionId) return false;+ return isTauriRuntime() && (!isMemorySqlitePath(source) || connectionStore.connectedIds.has(activeNode.value.connectionId));+ });++ async function backupSqliteDatabase() {+ const connectionId = activeNode.value.connectionId;+ const config = connectionId ? connectionStore.getConfig(connectionId) : undefined;+ const sourcePath = sqliteBackupSource.value;+ if (!connectionId || !config || !sourcePath) return;++ try {+ const { save } = await import("@tauri-apps/plugin-dialog");+ const destinationPath = await save({+ defaultPath: defaultSqliteBackupFileName(config),+ filters: [{ name: "SQLite", extensions: ["db", "sqlite", "sqlite3"] }],+ });+ if (!destinationPath) return;++ toast(t("contextMenu.backupSqliteDatabaseInProgress"), 2000);+ if (!isMemorySqlitePath(sourcePath)) await connectionStore.ensureConnected(connectionId);+ await api.backupSqliteDatabase(connectionId, destinationPath);+ toast(t("contextMenu.backupSqliteDatabaseSuccess"), 3000);+ } catch (error: any) {+ toast(t("contextMenu.backupSqliteDatabaseFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function disconnectConnection() {+ const node = activeNode.value;+ if (!node.connectionId) return;+ try {+ await connectionStore.disconnect(node.connectionId);+ node.isExpanded = false;+ node.children = [];+ toast(t("connection.disconnected"), 2000);+ } catch (error: any) {+ toast(t("connection.saveFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function cancelConnectionAttempt() {+ const connectionId = activeNode.value.connectionId;+ if (!connectionId) return;+ try {+ const cancelled = await connectionStore.cancelConnecting(connectionId);+ if (cancelled) toast(t("connection.connectCancelled"), 2000);+ } catch (error: any) {+ toast(t("connection.saveFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function closeDatabaseConnection() {+ const node = activeNode.value;+ if (node.type !== "database" || !node.connectionId || node.database == null) return;+ try {+ await connectionStore.closeDatabaseConnection(node.connectionId, node.database);+ toast(t("connection.databaseConnectionClosed", { name: node.label }), 2000);+ } catch (error: any) {+ toast(t("connection.saveFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ const isPinned = computed(() => activeNode.value.pinned || connectionStore.isTreeNodePinned(activeNode.value));+ const isNodeDefaultDatabase = computed(+ () => (activeNode.value.type === "database" || activeNode.value.type === "redis-db" || activeNode.value.type === "mongo-db") && !!activeNode.value.connectionId && !!activeNode.value.database && connectionStore.isDefaultDatabase(activeNode.value.connectionId, activeNode.value.database),+ );+ const isConnected = computed(() => activeNode.value.type === "connection" && !!activeNode.value.connectionId && connectionStore.connectedIds.has(activeNode.value.connectionId));+ const isConnecting = computed(() => activeNode.value.type === "connection" && !!activeNode.value.connectionId && connectionStore.connectingIds.has(activeNode.value.connectionId));+ const canCloseDatabaseConnection = computed(() => canCloseSidebarDatabaseConnection(activeNode.value, connectionStore.isTreeNodeChildrenLoaded, (connectionId, database) => queryStore.openDatabaseKeys.has(`${connectionId}\x00${database}`)));+ const canConfigureVisibleDatabases = computed(() => {+ if (activeNode.value.type !== "connection" || !activeNode.value.connectionId) return false;+ const databaseType = connectionStore.getConfig(activeNode.value.connectionId)?.db_type;+ return databaseType !== "elasticsearch" && databaseType !== "qdrant" && databaseType !== "milvus" && databaseType !== "weaviate" && databaseType !== "chromadb" && databaseType !== "etcd" && databaseType !== "mq" && databaseType !== "nacos";+ });+ const canConfigureVisibleSchemas = computed(() => {+ if (!activeNode.value.connectionId) return false;+ const databaseType = connectionStore.getConfig(activeNode.value.connectionId)?.db_type;+ return canConfigureVisibleSchemasForTreeNode(databaseType, activeNode.value.type, activeNode.value.database);+ });+ const canCopyFinalProxyPort = computed(() => activeNode.value.type === "connection" && !!activeNode.value.connectionId && hasEnabledTransportLayers(connectionStore.getConfig(activeNode.value.connectionId)));++ function togglePin() {+ connectionStore.toggleTreeNodePin(activeNode.value);+ }++ function openVisibleDatabasesDialog() {+ options.openVisibleDatabases(activeNode.value);+ }++ function openVisibleSchemasDialog() {+ options.openVisibleSchemas(activeNode.value);+ }++ function startRenameGroup() {+ if (activeNode.value.type === "connection-group") options.requestGroupRename(activeNode.value.id);+ }++ function deleteConnectionGroup() {+ showDeleteGroupConfirm.value = true;+ }++ function newConnectionInGroup() {+ connectionStore.startCreatingConnectionInGroup(activeNode.value.id);+ }++ function newSubgroup() {+ const groupId = connectionStore.createConnectionGroup(t("connectionGroup.newGroupDefault"), activeNode.value.id);+ connectionStore.selectedTreeNodeId = groupId;+ options.groupCreated(groupId);+ }++ function confirmDeleteGroup() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ connectionStore.deleteConnectionGroup(node.id);+ options.releaseActiveNodeReference([node.id]);+ showDeleteGroupConfirm.value = false;+ toast(t("connection.groupDeleted"), 2000);+ }++ function moveToGroup(groupId: string | null) {+ const connectionId = activeNode.value.connectionId;+ if (connectionId) connectionStore.moveConnectionToGroup(connectionId, groupId);+ }++ return {+ setNodeAsDefaultDatabase,+ clearNodeDefaultDatabase,+ connectionDeleteTargets,+ connectionDeleteMenuLabel,+ connectionDuplicateTargets,+ connectionDuplicateMenuLabel,+ connectionDeleteConfirmMessage,+ deleteConnection,+ confirmDelete,+ copyFinalProxyPort,+ duplicateConnection,+ editConnection,+ revealConnectionFilePath,+ revealDatabaseFile,+ sqliteBackupSource,+ canBackupSqliteDatabase,+ backupSqliteDatabase,+ disconnectConnection,+ cancelConnectionAttempt,+ closeDatabaseConnection,+ isPinned,+ isNodeDefaultDatabase,+ isConnected,+ isConnecting,+ canCloseDatabaseConnection,+ canConfigureVisibleDatabases,+ canConfigureVisibleSchemas,+ canCopyFinalProxyPort,+ togglePin,+ openVisibleDatabasesDialog,+ openVisibleSchemasDialog,+ startRenameGroup,+ deleteConnectionGroup,+ newConnectionInGroup,+ newSubgroup,+ confirmDeleteGroup,+ moveToGroup,+ };+}diff --git a/apps/desktop/src/composables/useSidebarDataOpenRuntime.ts b/apps/desktop/src/composables/useSidebarDataOpenRuntime.tsnew file mode 100644index 0000000000..0a891f9a25--- /dev/null+++ b/apps/desktop/src/composables/useSidebarDataOpenRuntime.ts@@ -0,0 +1,308 @@+import { nextTick } from "vue";+import { useConnectionStore } from "@/stores/connectionStore";+import { useQueryStore } from "@/stores/queryStore";+import { useSettingsStore } from "@/stores/settingsStore";+import type { TreeNode } from "@/types/database";+import { uuid } from "@/lib/common/utils";+import { appendDebugLog, isDebugLoggingEnabled } from "@/lib/backend/debugLog";+import { effectiveDatabaseTypeForConnection, connectionObjectTreeNodeSchema, connectionObjectTreeQuerySchema } from "@/lib/database/jdbcDialect";+import { getCachedTableMetadata, loadTableMetadata, TABLE_METADATA_CACHE_TTL_MS, tableMetadataToDataTabMeta } from "@/lib/metadata/tableMetadataCache";+import { canApplyDataTabMetadata, findExistingDataTabCandidate, type DataTabOpenMode } from "@/lib/sidebar/dataTabOpenPolicy";+import type { SidebarDataOpenRequest } from "@/lib/sidebar/sidebarDataOpenCoordinator";+import { hasTreeNodeDatabaseContext } from "@/lib/sidebar/treeNodeContext";+import { buildTableSelectSql } from "@/lib/table/tableSelectSql";+import { usesSyntheticRowIdKey } from "@/lib/table/tableEditing";+import { tableOpenPageLimit } from "@/lib/table/tableOpenPageLimit";+import { canActivateExistingDataTableTab } from "@/lib/tabs/dataTabActivation";++const DATA_TAB_METADATA_TTL_MS = TABLE_METADATA_CACHE_TTL_MS;++function hasNodeDatabaseContext(node: TreeNode): node is TreeNode & { connectionId: string; database: string } {+ return !!node.connectionId && hasTreeNodeDatabaseContext(node);+}++export function useSidebarDataOpenRuntime() {+ const connectionStore = useConnectionStore();+ const queryStore = useQueryStore();+ const settingsStore = useSettingsStore();++ async function openData(node: TreeNode, request?: SidebarDataOpenRequest, openMode: DataTabOpenMode = "default") {+ if (!(node.type === "table" || node.type === "view" || node.type === "materialized_view") || !hasNodeDatabaseContext(node)) return;+ const config = connectionStore.getConfig(node.connectionId);+ const traceId = uuid().slice(0, 8);+ const startedAt = performance.now();+ let lastPhaseAt = startedAt;+ const elapsed = () => `${Math.round(performance.now() - startedAt)}ms`;+ const openDataLog = (level: "info" | "warn" | "error" | "debug", event: string, details: Record<string, unknown>) => {+ appendDebugLog(level, `[DBX][openData:${event}]`, details);+ };+ const logPhase = (phase: string, extra: Record<string, unknown> = {}) => {+ const now = performance.now();+ openDataLog("info", "phase", {+ traceId,+ phase,+ deltaMs: Math.round(now - lastPhaseAt),+ totalMs: Math.round(now - startedAt),+ ...extra,+ });+ lastPhaseAt = now;+ };+ openDataLog("info", "start", {+ traceId,+ type: node.type,+ dbType: config?.db_type,+ openMode,+ });+ const tableSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);+ const tableType = node.type === "view" ? "VIEW" : node.type === "materialized_view" ? "MATERIALIZED_VIEW" : (node.tableType ?? "TABLE");+ const querySchema = config ? connectionObjectTreeQuerySchema(config, node.database, tableSchema) : (tableSchema ?? "");+ const effectiveDbType = effectiveDatabaseTypeForConnection(config);+ const metadataDatabaseType = effectiveDbType || config?.db_type || "";+ const dataTabTarget = {+ connectionId: node.connectionId,+ database: node.database,+ schema: tableSchema,+ catalog: node.catalog,+ tableName: node.label,+ };+ const existingDataTabCandidate = findExistingDataTabCandidate(queryStore.tabs, dataTabTarget, { openMode, reuseDataTab: settingsStore.editorSettings.reuseDataTab });+ const existingSameTableTab = existingDataTabCandidate?.match === "same-table" ? existingDataTabCandidate.tab : undefined;+ const resetReusedDataTabState = (tab: (typeof queryStore.tabs)[number]) => {+ tab.title = node.label;+ tab.schema = tableSchema;+ tab.whereInput = undefined;+ tab.orderByInput = undefined;+ tab.previewSql = undefined;+ tab.resultSortColumn = undefined;+ tab.resultSortColumnIndex = undefined;+ tab.resultSortDirection = undefined;+ tab.resultSortMode = undefined;+ tab.resultLocalSortOriginalRows = undefined;+ tab.resultLocalSortOriginalMongoDocuments = undefined;+ tab.resultSortedSql = undefined;+ tab.resultPageSql = undefined;+ tab.resultPageLimit = undefined;+ tab.resultPageOffset = undefined;+ tab.resultTotalRowCount = undefined;+ tab.resultTotalRowCountLoading = undefined;+ tab.queryAnalysis = undefined;+ tab.querySourceColumns = undefined;+ tab.queryEditabilityReason = undefined;+ };++ if (existingSameTableTab && canActivateExistingDataTableTab(existingSameTableTab, { activateExecuting: false })) {+ queryStore.switchTab(existingSameTableTab.id);+ logPhase("existing-tab-activated", { table: node.label });+ return;+ }++ const tabId = (() => {+ if (existingDataTabCandidate) {+ queryStore.switchTab(existingDataTabCandidate.tab.id);+ resetReusedDataTabState(existingDataTabCandidate.tab);+ return existingDataTabCandidate.tab.id;+ }+ return queryStore.createTab(node.connectionId, node.database, node.label, "data", tableSchema);+ })();+ openDataLog("info", "tab-created", { traceId, tabId, elapsed: elapsed() });+ logPhase("tab-created", { tabId });++ // Cancel any previous execution on this tab before starting a new one+ const existingTab = queryStore.tabs.find((t) => t.id === tabId);+ if (existingTab?.isExecuting && existingTab.executionId) {+ await queryStore.cancelTabExecution(tabId);+ logPhase("previous-execution-cancelled", { tabId });+ }++ const openDataId = uuid();+ // Clear previous result so DataGrid doesn't show its internal loading overlay (without stop button)+ const tab = queryStore.tabs.find((t) => t.id === tabId);+ if (tab) {+ tab.result = undefined;+ tab.results = undefined;+ }+ const existingTableMeta = tab?.tableMeta;+ const existingTableMetaAgeMs = tab?.tableMetaUpdatedAt ? Date.now() - tab.tableMetaUpdatedAt : Number.POSITIVE_INFINITY;+ const sharedCachedTableMeta = config+ ? getCachedTableMetadata({+ connectionId: node.connectionId,+ database: node.database,+ schema: querySchema,+ tableName: node.label,+ tableType,+ databaseType: metadataDatabaseType,+ driverProfile: config.driver_profile || config.db_type,+ catalog: node.catalog,+ })+ : undefined;+ const tabCachedTableMeta =+ existingTableMeta?.tableName === node.label && (existingTableMeta.catalog || "") === (node.catalog || "") && existingTableMeta.schema === tableSchema && existingTableMeta.tableType === tableType && existingTableMeta.columns.length > 0 && existingTableMetaAgeMs < DATA_TAB_METADATA_TTL_MS+ ? existingTableMeta+ : undefined;+ const cachedTableMeta = sharedCachedTableMeta ? tableMetadataToDataTabMeta(sharedCachedTableMeta.metadata, tableSchema) : tabCachedTableMeta;+ const cachedTableMetaAgeMs = sharedCachedTableMeta?.ageMs ?? existingTableMetaAgeMs;+ const cachedTableMetaSource = sharedCachedTableMeta ? "shared" : tabCachedTableMeta ? "tab" : undefined;+ queryStore.setTableMeta(+ tabId,+ cachedTableMeta ?? {+ catalog: node.catalog,+ database: node.database,+ schema: tableSchema,+ tableName: node.label,+ tableType,+ columns: [],+ primaryKeys: [],+ },+ );+ queryStore.setExecutingWithId(tabId, openDataId);+ request?.registerCancel(async () => {+ const current = queryStore.tabs.find((item) => item.id === tabId);+ if (current?.isExecuting && current.executionId === openDataId) {+ await queryStore.cancelTabExecution(tabId);+ }+ });+ logPhase("state-prepared", { tabId });++ // Yield to Vue's scheduler so the new tab becomes visible in the UI (tab+ // bar activates, content area switches) before the first blocking network+ // call. Without this the entire openData flow runs synchronously before the+ // browser paints, making the UI feel frozen on each table click.+ await nextTick();++ // Helper to check if this openData call is still active (not superseded by a newer click)+ const isActive = () => (request?.isCurrent() ?? true) && queryStore.tabs.find((t) => t.id === tabId)?.executionId === openDataId;+ const canApplyTableMetadata = () =>+ canApplyDataTabMetadata(+ queryStore.tabs.find((t) => t.id === tabId),+ dataTabTarget,+ request?.signal,+ );++ try {+ openDataLog("info", "ensure-connected:start", { traceId, elapsed: elapsed() });+ await connectionStore.ensureConnected(node.connectionId);+ if (!isActive()) {+ logPhase("superseded-after-ensure-connected", { tabId });+ return;+ }+ openDataLog("info", "ensure-connected:done", { traceId, elapsed: elapsed() });+ logPhase("ensure-connected", { tabId });+ if (!config) throw new Error("Connection config not found");++ const limit = tableOpenPageLimit();+ const refreshTableMetaInBackground = async () => {+ const metadataStartedAt = performance.now();+ openDataLog("info", "metadata:start", {+ traceId,+ elapsed: elapsed(),+ });+ try {+ const loadedMetadata = await loadTableMetadata({+ connectionId: node.connectionId,+ database: node.database,+ schema: querySchema,+ tableName: node.label,+ tableType,+ databaseType: metadataDatabaseType,+ driverProfile: config.driver_profile || config.db_type,+ catalog: node.catalog,+ traceLogger: isDebugLoggingEnabled() ? (event) => openDataLog("debug", "metadata:trace", { sourceTraceId: traceId, ...event }) : undefined,+ });+ if (!canApplyTableMetadata()) {+ openDataLog("info", "metadata:stale", {+ traceId,+ tabId,+ columnCount: loadedMetadata.metadata.columns.length,+ elapsed: elapsed(),+ });+ return;+ }+ const nextTableMeta = tableMetadataToDataTabMeta(loadedMetadata.metadata, tableSchema);+ queryStore.setTableMeta(tabId, nextTableMeta);+ openDataLog("info", "metadata:done", {+ traceId,+ tabId,+ columnCount: nextTableMeta.columns.length,+ primaryKeyCount: nextTableMeta.primaryKeys.length,+ cacheStatus: loadedMetadata.cacheStatus,+ ageMs: Math.round(loadedMetadata.ageMs),+ elapsed: elapsed(),+ metadataMs: Math.round(performance.now() - metadataStartedAt),+ });+ } catch (error) {+ openDataLog("warn", "metadata:error", { traceId, tabId, elapsed: elapsed(), error });+ }+ };+ const shouldRefreshTableMeta = !cachedTableMeta;+ if (cachedTableMeta) {+ openDataLog("info", "metadata:cache-hit", {+ traceId,+ tabId,+ columnCount: cachedTableMeta.columns.length,+ primaryKeyCount: cachedTableMeta.primaryKeys.length,+ source: cachedTableMetaSource,+ ageMs: Math.round(cachedTableMetaAgeMs),+ elapsed: elapsed(),+ });+ } else {+ logPhase("metadata-deferred", { tabId });+ }++ // Check if superseded by a newer openData call+ if (!isActive()) {+ logPhase("superseded-before-build-sql", { tabId });+ return;+ }++ const columns = cachedTableMeta?.columns ?? [];+ const primaryKeys = cachedTableMeta?.primaryKeys ?? [];+ const includeRowId = usesSyntheticRowIdKey(effectiveDbType, primaryKeys, tableType);+ const sql = await buildTableSelectSql({+ databaseType: effectiveDbType,+ identifierQuote: connectionStore.connectionIdentifierQuote?.(node.connectionId),+ schema: tableSchema,+ database: node.database,+ tableName: node.label,+ tableType,+ catalog: node.catalog,+ columns: columns.map((column) => column.name),+ primaryKeys,+ limit,+ includeRowId,+ });+ openDataLog("info", "sql-built", {+ traceId,+ primaryKeyCount: primaryKeys.length,+ includeRowId,+ sqlLength: sql.length,+ elapsed: elapsed(),+ });+ logPhase("sql-built", { tabId, columnCount: columns.length, primaryKeyCount: primaryKeys.length });+ queryStore.updateSql(tabId, sql);+ logPhase("sql-updated", { tabId });++ openDataLog("info", "execute:start", { traceId, tabId, elapsed: elapsed() });+ await queryStore.executeTabSql(tabId, sql, {+ sourceTraceId: traceId,+ skipEnsureConnected: true,+ pagination: { limit, offset: 0 },+ });+ openDataLog("info", "execute:done", { traceId, tabId, elapsed: elapsed() });+ logPhase("execute-tab-sql", { tabId });+ if (shouldRefreshTableMeta && canApplyTableMetadata()) {+ void refreshTableMetaInBackground();+ logPhase("metadata-started", { tabId });+ }+ } catch (e: any) {+ if (!isActive()) {+ logPhase("superseded-after-error", { tabId });+ return;+ }+ openDataLog("error", "error", { traceId, elapsed: elapsed(), error: e });+ logPhase("error", { tabId });+ queryStore.setErrorResult(tabId, e);+ }+ }++ return { openData };+}diff --git a/apps/desktop/src/composables/useSidebarDatabaseSpecificMutationRuntime.ts b/apps/desktop/src/composables/useSidebarDatabaseSpecificMutationRuntime.tsnew file mode 100644index 0000000000..88ef5e6b0b--- /dev/null+++ b/apps/desktop/src/composables/useSidebarDatabaseSpecificMutationRuntime.ts@@ -0,0 +1,257 @@+import { computed, type ShallowRef } from "vue";+import { useI18n } from "vue-i18n";+import { useToast } from "@/composables/useToast";+import { useConnectionStore } from "@/stores/connectionStore";+import type { TreeNode } from "@/types/database";+import * as api from "@/lib/backend/api";+import { translateBackendError } from "@/i18n/backend-errors";+import { findSidebarActionTarget } from "@/lib/sidebar/sidebarActionTarget";+import {+ sidebarDangerTarget,+ sidebarFormTarget,+ showCreateNacosNamespaceDialog,+ createNacosNamespaceId,+ createNacosNamespaceName,+ createNacosNamespaceDesc,+ createNacosNamespaceLoading,+ showEditNacosNamespaceDialog,+ editNacosNamespaceName,+ editNacosNamespaceDesc,+ editNacosNamespaceLoading,+ showDropMongoCollectionConfirm,+ dropMongoCollectionLoading,+ showDropMongoIndexConfirm,+ dropMongoIndexLoading,+ showDropAllMongoIndexesConfirm,+ dropAllMongoIndexesLoading,+ showFlushRedisDbConfirm,+} from "@/components/sidebar/sidebarTreeDialogState";++interface SidebarDatabaseSpecificMutationRuntimeOptions {+ activeNode: ShallowRef<TreeNode>;+ connectionStore: ReturnType<typeof useConnectionStore>;+}++export function useSidebarDatabaseSpecificMutationRuntime(options: SidebarDatabaseSpecificMutationRuntimeOptions) {+ const { t } = useI18n();+ const { toast } = useToast();+ const { activeNode, connectionStore } = options;++ const canDropMongoDatabase = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "mongo-db" && !!activeNode.value.database && config?.driver_profile !== "mongodb-legacy";+ });++ const canDropMongoCollection = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "mongo-collection" && !!activeNode.value.database && config?.driver_profile !== "mongodb-legacy";+ });++ function mongoIndexNameForNode(node: TreeNode): string {+ if (node.type !== "index") return "";+ return node.meta && "name" in node.meta ? node.meta.name : node.label.replace(/\s+\(.+\)$/, "");+ }++ function canDropMongoIndexNode(node: TreeNode): boolean {+ if (node.type !== "index" || !node.connectionId || !node.database || !node.tableName) return false;+ const config = connectionStore.getConfig(node.connectionId);+ return config?.db_type === "mongodb" && config.driver_profile !== "mongodb-legacy" && mongoIndexNameForNode(node) !== "_id_";+ }++ const canDropMongoIndex = computed(() => canDropMongoIndexNode(activeNode.value));++ function mongoIndexDropPreview(node: Pick<TreeNode, "tableName">, indexName: string): string {+ return `db.getCollection(${JSON.stringify(node.tableName || "")}).dropIndex(${JSON.stringify(indexName)})`;+ }++ const canDropAllMongoIndexes = computed(() => {+ const config = activeNode.value.connectionId ? connectionStore.getConfig(activeNode.value.connectionId) : undefined;+ return activeNode.value.type === "mongo-collection" && !!activeNode.value.database && config?.db_type === "mongodb" && config.driver_profile !== "mongodb-legacy";+ });++ function mongoDropAllIndexesPreview(node: Pick<TreeNode, "label">): string {+ return `db.getCollection(${JSON.stringify(node.label)}).dropIndexes()`;+ }++ function openCreateNacosNamespaceDialog() {+ createNacosNamespaceId.value = "";+ createNacosNamespaceName.value = "";+ createNacosNamespaceDesc.value = "";+ showCreateNacosNamespaceDialog.value = true;+ }++ async function confirmCreateNacosNamespace() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ const namespaceName = createNacosNamespaceName.value.trim();+ if (!node.connectionId || !namespaceName || createNacosNamespaceLoading.value) return;+ createNacosNamespaceLoading.value = true;+ try {+ await api.nacosCreateNamespace(node.connectionId, {+ namespaceId: createNacosNamespaceId.value.trim() || undefined,+ namespaceName,+ namespaceDesc: createNacosNamespaceDesc.value.trim() || namespaceName,+ });+ showCreateNacosNamespaceDialog.value = false;+ await connectionStore.loadNacosNamespaces(node.connectionId, { force: true });+ const liveNode = findSidebarActionTarget(connectionStore.treeNodes, node);+ if (liveNode) liveNode.isExpanded = true;+ toast(t("nacos.namespaceCreated", { name: namespaceName }), 3000);+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: translateBackendError(t, error?.message || String(error)) }), 5000);+ } finally {+ createNacosNamespaceLoading.value = false;+ }+ }++ function openEditNacosNamespaceDialog() {+ editNacosNamespaceName.value = activeNode.value.nacosNamespaceName || activeNode.value.label;+ editNacosNamespaceDesc.value = activeNode.value.comment || "";+ showEditNacosNamespaceDialog.value = true;+ }++ async function confirmEditNacosNamespace() {+ const node = sidebarFormTarget.value ?? activeNode.value;+ const namespaceId = node.nacosNamespace?.trim() || "";+ const namespaceName = editNacosNamespaceName.value.trim();+ if (!node.connectionId || !namespaceId || !namespaceName || editNacosNamespaceLoading.value) return;+ editNacosNamespaceLoading.value = true;+ try {+ await api.nacosUpdateNamespace(node.connectionId, {+ namespaceId,+ namespaceName,+ namespaceDesc: editNacosNamespaceDesc.value.trim() || namespaceName,+ });+ showEditNacosNamespaceDialog.value = false;+ await connectionStore.loadNacosNamespaces(node.connectionId, { force: true });+ toast(t("nacos.namespaceUpdated", { name: namespaceName }), 3000);+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: translateBackendError(t, error?.message || String(error)) }), 5000);+ } finally {+ editNacosNamespaceLoading.value = false;+ }+ }++ function dropMongoCollection() {+ dropMongoCollectionLoading.value = false;+ showDropMongoCollectionConfirm.value = true;+ }++ function dropMongoIndex() {+ dropMongoIndexLoading.value = false;+ showDropMongoIndexConfirm.value = true;+ }++ function dropAllMongoIndexes() {+ dropAllMongoIndexesLoading.value = false;+ showDropAllMongoIndexesConfirm.value = true;+ }++ function flushRedisDb() {+ showFlushRedisDbConfirm.value = true;+ }++ async function confirmFlushRedisDb() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (node.type !== "redis-db" || !node.connectionId || !node.database) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ await api.redisFlushDb(node.connectionId, Number(node.database));+ connectionStore.updateRedisDbKeyStats(node.connectionId, Number(node.database), { loaded: 0, total: 0 });+ window.dispatchEvent(+ new CustomEvent("dbx-redis-db-flushed", {+ detail: { connectionId: node.connectionId, db: Number(node.database) },+ }),+ );+ toast(t("redis.flushDbSuccess", { db: node.database }), 3000);+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function confirmDropMongoCollection() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (node.type !== "mongo-collection" || !node.connectionId || !node.database || dropMongoCollectionLoading.value) return;+ dropMongoCollectionLoading.value = true;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ await api.mongoDropCollection(node.connectionId, node.database, node.label);+ toast(t("contextMenu.dropCollectionSuccess", { name: node.label }), 3000);+ await connectionStore.loadMongoCollections(node.connectionId, node.database);+ showDropMongoCollectionConfirm.value = false;+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);+ } finally {+ dropMongoCollectionLoading.value = false;+ }+ }++ function mongoIndexesGroupNodeId(node: Pick<TreeNode, "connectionId" | "database" | "schema" | "tableName" | "label">): string | null {+ if (!node.connectionId || !node.database) return null;+ const tableName = node.tableName || node.label;+ return node.schema ? `${node.connectionId}:${node.database}:${node.schema}:${tableName}:__indexes` : `${node.connectionId}:${node.database}:${tableName}:__indexes`;+ }++ async function refreshMongoIndexTree(node: Pick<TreeNode, "connectionId" | "database" | "schema" | "tableName" | "label">) {+ const nodeId = mongoIndexesGroupNodeId(node);+ if (!node.connectionId || !node.database || !nodeId) return;+ await connectionStore.loadIndexes(node.connectionId, node.database, node.tableName || node.label, node.schema, nodeId);+ }++ async function confirmDropMongoIndex() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (!canDropMongoIndexNode(node) || !node.connectionId || !node.database || !node.tableName || dropMongoIndexLoading.value) return;+ dropMongoIndexLoading.value = true;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const indexName = mongoIndexNameForNode(node);+ await api.mongoDropIndexes(node.connectionId, node.database, node.tableName, JSON.stringify(indexName), true);+ toast(t("contextMenu.dropTableChildObjectSuccess", { name: indexName }), 3000);+ showDropMongoIndexConfirm.value = false;+ await refreshMongoIndexTree(node);+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);+ } finally {+ dropMongoIndexLoading.value = false;+ }+ }++ async function confirmDropAllMongoIndexes() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (node.type !== "mongo-collection" || !node.connectionId || !node.database || dropAllMongoIndexesLoading.value) return;+ dropAllMongoIndexesLoading.value = true;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const result = await api.mongoDropIndexes(node.connectionId, node.database, node.label, undefined, false);+ toast(t("contextMenu.dropAllIndexesSuccess", { count: result.dropped_names.length, name: node.label }), 3000);+ showDropAllMongoIndexesConfirm.value = false;+ await refreshMongoIndexTree(node);+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);+ } finally {+ dropAllMongoIndexesLoading.value = false;+ }+ }++ return {+ canDropMongoDatabase,+ canDropMongoCollection,+ mongoIndexNameForNode,+ canDropMongoIndexNode,+ canDropMongoIndex,+ mongoIndexDropPreview,+ canDropAllMongoIndexes,+ mongoDropAllIndexesPreview,+ openCreateNacosNamespaceDialog,+ confirmCreateNacosNamespace,+ openEditNacosNamespaceDialog,+ confirmEditNacosNamespace,+ dropMongoCollection,+ dropMongoIndex,+ dropAllMongoIndexes,+ flushRedisDb,+ confirmFlushRedisDb,+ confirmDropMongoCollection,+ confirmDropMongoIndex,+ confirmDropAllMongoIndexes,+ };+}diff --git a/apps/desktop/src/composables/useSidebarTableMutationRuntime.ts b/apps/desktop/src/composables/useSidebarTableMutationRuntime.tsnew file mode 100644index 0000000000..0735fecd95--- /dev/null+++ b/apps/desktop/src/composables/useSidebarTableMutationRuntime.ts@@ -0,0 +1,157 @@+import { computed, type ShallowRef } from "vue";+import { useI18n } from "vue-i18n";+import { useToast } from "@/composables/useToast";+import { useConnectionStore } from "@/stores/connectionStore";+import type { DatabaseType, TreeNode } from "@/types/database";+import { supportsTableTruncate } from "@/lib/database/databaseCapabilities";+import { buildDropTableSql, buildEmptyTableSql, buildTruncateTableSql, supportsDropTableCascade, supportsTruncateTableCascade, type TableAdminSqlOptions } from "@/lib/database/dbAdminSql";+import { isSqlServerLinkedNode } from "@/lib/database/sqlServerLinkedServers";+import { sidebarDangerTarget, showDropTableConfirm, showEmptyTableConfirm, showTruncateTableConfirm, dropTablePreviewSql, dropTableCascade, emptyTablePreviewSql, truncateTablePreviewSql, truncateTableCascade } from "@/components/sidebar/sidebarTreeDialogState";++interface SidebarTableMutationRuntimeOptions {+ activeNode: ShallowRef<TreeNode>;+ releaseActiveNodeReference: (nodeIds: readonly string[]) => void;+ connectionStore: ReturnType<typeof useConnectionStore>;+ currentDatabaseType: () => DatabaseType | undefined;+ databaseTypeForNode: (node: TreeNode) => DatabaseType | undefined;+ executeWithProductionGuard: (node: Pick<TreeNode, "connectionId" | "database" | "schema">, sql: string, options?: { database?: string; schema?: string }) => Promise<unknown>;+ closeDroppedTableObjectTabsForNode: (node: TreeNode) => void;+ refreshMutatedTableDataTabsForNode: (node: TreeNode) => Promise<void>;+}++export function useSidebarTableMutationRuntime(options: SidebarTableMutationRuntimeOptions) {+ const { t } = useI18n();+ const { toast } = useToast();+ const { activeNode, connectionStore, currentDatabaseType, databaseTypeForNode } = options;++ const isTableNotView = computed(() => activeNode.value.type === "table" && !isSqlServerLinkedNode(activeNode.value));+ const supportsTruncate = computed(() => supportsTableTruncate(currentDatabaseType()));+ const canDropTableCascade = computed(() => activeNode.value.type === "table" && supportsDropTableCascade(currentDatabaseType()));+ const canTruncateTableCascade = computed(() => activeNode.value.type === "table" && supportsTruncateTableCascade(currentDatabaseType()));++ function tableAdminSqlOptions(optionsOverride?: { cascade?: boolean }): TableAdminSqlOptions {+ const result: TableAdminSqlOptions = {+ databaseType: currentDatabaseType(),+ schema: activeNode.value.schema,+ tableName: activeNode.value.label,+ };+ if (optionsOverride?.cascade) result.cascade = true;+ return result;+ }++ function tableAdminSqlOptionsForNode(node: TreeNode, optionsOverride?: { cascade?: boolean }): TableAdminSqlOptions {+ const result: TableAdminSqlOptions = {+ databaseType: databaseTypeForNode(node),+ schema: node.schema,+ tableName: node.label,+ };+ if (optionsOverride?.cascade) result.cascade = true;+ return result;+ }++ function dropTableSqlOptions(): TableAdminSqlOptions {+ return tableAdminSqlOptions({ cascade: canDropTableCascade.value && dropTableCascade.value });+ }++ function truncateTableSqlOptions(): TableAdminSqlOptions {+ return tableAdminSqlOptions({ cascade: canTruncateTableCascade.value && truncateTableCascade.value });+ }++ async function refreshDropTablePreviewSql() {+ dropTablePreviewSql.value = "";+ dropTablePreviewSql.value = await buildDropTableSql(dropTableSqlOptions()).catch(() => "");+ }++ async function refreshEmptyTablePreviewSql() {+ emptyTablePreviewSql.value = "";+ emptyTablePreviewSql.value = await buildEmptyTableSql(tableAdminSqlOptions()).catch(() => "");+ }++ async function refreshTruncateTablePreviewSql() {+ truncateTablePreviewSql.value = "";+ truncateTablePreviewSql.value = await buildTruncateTableSql(truncateTableSqlOptions()).catch(() => "");+ }++ function dropTable() {+ dropTableCascade.value = false;+ void refreshDropTablePreviewSql();+ showDropTableConfirm.value = true;+ }++ async function refreshTableList(node: TreeNode) {+ if (!node.connectionId || !node.database) return;+ await connectionStore.refreshObjectListTreeNode(node.connectionId, node.database, node.schema);+ }++ async function confirmDropTable() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (!node.connectionId || !node.database) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const sql = dropTablePreviewSql.value || (await buildDropTableSql(tableAdminSqlOptionsForNode(node, { cascade: dropTableCascade.value && supportsDropTableCascade(databaseTypeForNode(node)) })));+ await options.executeWithProductionGuard(node, sql, { database: node.database, schema: node.schema });+ toast(t("contextMenu.dropTableSuccess", { name: node.label }), 3000);+ options.closeDroppedTableObjectTabsForNode(node);+ connectionStore.removeTreeNode(node.id);+ options.releaseActiveNodeReference([node.id]);+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ function emptyTable() {+ void refreshEmptyTablePreviewSql();+ showEmptyTableConfirm.value = true;+ }++ async function confirmEmptyTable() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (!node.connectionId || !node.database) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const sql = emptyTablePreviewSql.value || (await buildEmptyTableSql(tableAdminSqlOptionsForNode(node)));+ await options.executeWithProductionGuard(node, sql, { database: node.database, schema: node.schema });+ const messageKey = databaseTypeForNode(node) === "clickhouse" ? "contextMenu.emptyTableSubmitted" : "contextMenu.emptyTableSuccess";+ toast(t(messageKey, { name: node.label }), 3000);+ await options.refreshMutatedTableDataTabsForNode(node);+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ function truncateTable() {+ truncateTableCascade.value = false;+ void refreshTruncateTablePreviewSql();+ showTruncateTableConfirm.value = true;+ }++ async function confirmTruncateTable() {+ const node = sidebarDangerTarget.value ?? activeNode.value;+ if (!node.connectionId || !node.database) return;+ try {+ await connectionStore.ensureConnected(node.connectionId);+ const sql = truncateTablePreviewSql.value || (await buildTruncateTableSql(tableAdminSqlOptionsForNode(node, { cascade: truncateTableCascade.value && supportsTruncateTableCascade(databaseTypeForNode(node)) })));+ await options.executeWithProductionGuard(node, sql, { database: node.database, schema: node.schema });+ toast(t("contextMenu.truncateTableSuccess", { name: node.label }), 3000);+ await options.refreshMutatedTableDataTabsForNode(node);+ } catch (error: any) {+ toast(t("contextMenu.tableOperationFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ return {+ isTableNotView,+ supportsTruncate,+ canDropTableCascade,+ canTruncateTableCascade,+ refreshDropTablePreviewSql,+ refreshTruncateTablePreviewSql,+ dropTable,+ refreshTableList,+ confirmDropTable,+ emptyTable,+ confirmEmptyTable,+ truncateTable,+ confirmTruncateTable,+ };+}diff --git a/apps/desktop/src/composables/useSidebarTreeExportRuntime.ts b/apps/desktop/src/composables/useSidebarTreeExportRuntime.tsnew file mode 100644index 0000000000..254a1ad458--- /dev/null+++ b/apps/desktop/src/composables/useSidebarTreeExportRuntime.ts@@ -0,0 +1,330 @@+import type { ShallowRef } from "vue";+import { useI18n } from "vue-i18n";+import { useExportTracker, type ExportTask } from "@/composables/useExportTracker";+import { useToast } from "@/composables/useToast";+import type { useConnectionStore } from "@/stores/connectionStore";+import type { useSettingsStore } from "@/stores/settingsStore";+import type { ColumnInfo, ObjectSourceKind, TreeNode, TreeNodeType } from "@/types/database";+import * as api from "@/lib/backend/api";+import { isTauriRuntime } from "@/lib/backend/tauriRuntime";+import { copyToClipboard } from "@/lib/common/clipboard";+import { effectiveDatabaseTypeForConnection } from "@/lib/database/jdbcDialect";+import { joinExportedDdls } from "@/lib/export/ddlExport";+import { formatSqlInsert } from "@/lib/export/exportFormats";+import { sidebarStructureExportTargets } from "@/lib/sidebar/sidebarExportRuntime";+import { fetchTableDataForExport } from "@/lib/table/tableDataExport";+import { isLoadingStructurePreview, showStructureDocCopyDialog, showStructurePreviewDialog, structureDocCopyText, structureDocCopyTitle, structurePreviewDefaultFileName, structurePreviewError, structurePreviewSql, structurePreviewTitle } from "@/components/sidebar/sidebarTreeDialogState";++type StructureCopyFormat = "tsv" | "markdown";++interface SidebarTreeExportRuntimeOptions {+ activeNode: ShallowRef<TreeNode>;+ connectionStore: ReturnType<typeof useConnectionStore>;+ settingsStore: ReturnType<typeof useSettingsStore>;+ acceptedSelectionIds: () => readonly string[] | null;+}++export function useSidebarTreeExportRuntime(options: SidebarTreeExportRuntimeOptions) {+ const { t } = useI18n();+ const { toast } = useToast();+ const { addTask: addExportTask } = useExportTracker();+ const { activeNode, connectionStore, settingsStore } = options;++ async function saveFileContent(content: string, defaultFileName: string, filterName: string, filterExt: string) {+ if (isTauriRuntime()) {+ const { save } = await import("@tauri-apps/plugin-dialog");+ const { writeTextFile } = await import("@tauri-apps/plugin-fs");+ const path = await save({+ defaultPath: defaultFileName,+ filters: [{ name: filterName, extensions: [filterExt] }],+ });+ if (path) await writeTextFile(path, content);+ return;+ }++ const blob = new Blob([content], { type: "text/plain" });+ const url = URL.createObjectURL(blob);+ const anchor = document.createElement("a");+ anchor.href = url;+ anchor.download = defaultFileName;+ anchor.click();+ URL.revokeObjectURL(url);+ }++ function tableDdlObjectTypeForNode(type: TreeNodeType): ObjectSourceKind | undefined {+ if (type === "view") return "VIEW";+ if (type === "materialized_view") return "MATERIALIZED_VIEW";+ return undefined;+ }++ function structureExportTargets(): Array<TreeNode & { connectionId: string; database: string }> {+ return sidebarStructureExportTargets(activeNode.value, connectionStore.treeNodes, options.acceptedSelectionIds() ?? connectionStore.selectedTreeNodeIds);+ }++ async function exportStructure() {+ const targets = structureExportTargets();+ if (!targets.length) return;+ isLoadingStructurePreview.value = true;+ structurePreviewError.value = "";+ structurePreviewSql.value = "";+ structurePreviewTitle.value = targets.length === 1 ? t("contextMenu.exportStructurePreviewTitle", { name: targets[0]!.label }) : t("contextMenu.exportStructurePreviewTitleMultiple", { count: targets.length });+ structurePreviewDefaultFileName.value = targets.length === 1 ? `${targets[0]!.label}.sql` : "structures.sql";+ showStructurePreviewDialog.value = true;+ try {+ const parts: string[] = [];+ for (const target of targets) {+ await connectionStore.ensureConnected(target.connectionId);+ const ddl = await api.getTableDdl(target.connectionId, target.database, target.schema || target.database, target.label, tableDdlObjectTypeForNode(target.type), target.catalog);+ parts.push(ddl.trim());+ }+ structurePreviewSql.value = joinExportedDdls(parts);+ } catch (error: any) {+ structurePreviewError.value = error?.message || String(error);+ console.error("Export structure failed:", error);+ } finally {+ isLoadingStructurePreview.value = false;+ }+ }++ function structureTargetName(target: TreeNode): string {+ return target.schema ? `${target.schema}.${target.label}` : target.label;+ }++ function columnDocValue(value: unknown): string {+ return value === null || value === undefined ? "" : String(value);+ }++ function tsvCell(value: unknown): string {+ return columnDocValue(value).replace(/\t/g, " ").replace(/\r?\n/g, " ").trim();+ }++ function markdownCell(value: unknown): string {+ return columnDocValue(value).replace(/\|/g, "\\|").replace(/\r?\n/g, "<br>").trim();+ }++ function columnDocHeaders(includeTable: boolean): string[] {+ const headers = [t("contextMenu.structureDocColumn"), t("contextMenu.structureDocType"), t("contextMenu.structureDocPrimaryKey"), t("contextMenu.structureDocNullable"), t("contextMenu.structureDocDefault"), t("contextMenu.structureDocComment")];+ return includeTable ? [t("contextMenu.structureDocTable"), ...headers] : headers;+ }++ function columnDocCells(target: TreeNode, column: ColumnInfo, includeTable: boolean): unknown[] {+ const cells = [column.name, column.data_type, column.is_primary_key ? t("contextMenu.structureDocYes") : t("contextMenu.structureDocNo"), column.is_nullable ? t("contextMenu.structureDocYes") : t("contextMenu.structureDocNo"), column.column_default, column.comment];+ return includeTable ? [structureTargetName(target), ...cells] : cells;+ }++ async function tableColumnsForStructureCopy(target: TreeNode & { connectionId: string; database: string }): Promise<ColumnInfo[]> {+ await connectionStore.ensureConnected(target.connectionId);+ return api.getColumns(target.connectionId, target.database, target.schema || target.database, target.label);+ }++ async function buildStructureCopyText(format: StructureCopyFormat): Promise<string> {+ const targets = structureExportTargets();+ if (!targets.length) return "";+ const includeTable = targets.length > 1;+ const headers = columnDocHeaders(includeTable);++ if (format === "tsv") {+ const lines = [headers.map(tsvCell).join("\t")];+ for (const target of targets) {+ const columns = await tableColumnsForStructureCopy(target);+ for (const column of columns) lines.push(columnDocCells(target, column, includeTable).map(tsvCell).join("\t"));+ }+ return `${lines.join("\n")}\n`;+ }++ const tables: string[] = [];+ const markdownHeaders = columnDocHeaders(false);+ for (const target of targets) {+ const columns = await tableColumnsForStructureCopy(target);+ const tableLines = [`### ${markdownCell(structureTargetName(target))}`, "", `| ${markdownHeaders.map(markdownCell).join(" | ")} |`, `| ${markdownHeaders.map(() => "---").join(" | ")} |`, ...columns.map((column) => `| ${columnDocCells(target, column, false).map(markdownCell).join(" | ")} |`)];+ tables.push(tableLines.join("\n"));+ }+ return `${tables.join("\n\n")}\n`;+ }++ async function copyStructureAs(format: StructureCopyFormat) {+ let text = "";+ try {+ text = await buildStructureCopyText(format);+ if (!text) return;+ await copyToClipboard(text);+ toast(t("contextMenu.structureDocCopied"), 2000);+ } catch (error: any) {+ if (text) {+ structureDocCopyText.value = text;+ structureDocCopyTitle.value = format === "tsv" ? t("contextMenu.copyStructureAsTsv") : t("contextMenu.copyStructureAsMarkdown");+ showStructureDocCopyDialog.value = true;+ return;+ }+ toast(t("grid.copyFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function copyStructureDocText() {+ if (!structureDocCopyText.value) return;+ try {+ await copyToClipboard(structureDocCopyText.value);+ toast(t("contextMenu.structureDocCopied"), 2000);+ } catch (error: any) {+ toast(t("grid.copyFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ function selectTextareaContent(event: FocusEvent) {+ if (event.target instanceof HTMLTextAreaElement) event.target.select();+ }++ async function copyStructurePreview() {+ if (!structurePreviewSql.value) return;+ try {+ await copyToClipboard(structurePreviewSql.value);+ toast(t("contextMenu.exportStructureCopied"), 2000);+ } catch (error: any) {+ toast(t("grid.copyFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function saveStructurePreview() {+ if (!structurePreviewSql.value) return;+ try {+ await saveFileContent(structurePreviewSql.value, structurePreviewDefaultFileName.value, "SQL", "sql");+ toast(t("grid.exported"));+ } catch (error: any) {+ toast(t("grid.exportFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ function columnTypesForResultColumns(columns: string[], tableColumns: ColumnInfo[]): Array<string | undefined> {+ const typesByName = new Map(tableColumns.map((column) => [column.name.toLocaleLowerCase(), column.data_type]));+ return columns.map((column) => typesByName.get(column.toLocaleLowerCase()));+ }++ async function exportDataLegacy(format: "json" | "sql") {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ const connectionId = node.connectionId;+ const database = node.database;+ const config = connectionStore.getConfig(connectionId);+ if (!config) return;++ try {+ await connectionStore.ensureConnected(connectionId);+ const tableColumns = format === "sql" ? await api.getColumns(connectionId, database, node.schema || database, node.label) : undefined;+ const queryColumns = config.db_type === "neo4j" ? (tableColumns ?? (await api.getColumns(connectionId, database, node.schema || database, node.label))).map((column) => column.name) : undefined;+ const effectiveDbType = effectiveDatabaseTypeForConnection(config);+ const result = await fetchTableDataForExport({+ databaseType: effectiveDbType,+ identifierQuote: connectionStore.connectionIdentifierQuote?.(connectionId),+ schema: node.schema,+ tableName: node.label,+ tableType: node.tableType,+ columns: queryColumns,+ executePage: (sql) => api.executeQuery(connectionId, database, sql),+ });++ if (format === "json") {+ let outputPath = `${node.label}.json`;+ if (isTauriRuntime()) {+ const { save } = await import("@tauri-apps/plugin-dialog");+ const path = await save({ defaultPath: outputPath, filters: [{ name: "JSON", extensions: ["json"] }] });+ if (!path) return;+ outputPath = path as string;+ }+ await api.exportQueryResultJson(outputPath, result.columns, result.rows);+ toast(t("grid.exported"));+ return;+ }++ const content = await formatSqlInsert({+ databaseType: effectiveDbType,+ schema: node.schema,+ tableName: node.label,+ columns: result.columns,+ columnTypes: tableColumns ? columnTypesForResultColumns(result.columns, tableColumns) : undefined,+ rows: result.rows,+ });+ await saveFileContent(content, `${node.label}.sql`, "SQL", "sql");+ toast(t("grid.exported"));+ } catch (error: any) {+ toast(t("grid.exportFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function exportTableData(format: "csv" | "xlsx") {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ const connectionId = node.connectionId;+ const database = node.database;+ const config = connectionStore.getConfig(connectionId);+ if (!config) return;++ let task: ExportTask | null = null;+ try {+ await connectionStore.ensureConnected(connectionId);++ // Choose the destination before registering a background task so cancellation creates no orphan tracker entry.+ let outputPath = `${node.label}.${format}`;+ if (isTauriRuntime()) {+ const { save } = await import("@tauri-apps/plugin-dialog");+ const path = await save({+ defaultPath: outputPath,+ filters: [{ name: format === "csv" ? "CSV" : "Excel", extensions: [format] }],+ });+ if (!path) return;+ outputPath = path as string;+ }++ task = addExportTask(node.label, format, outputPath);+ const currentTask = task;+ const queryColumns = config.db_type === "neo4j" ? (await api.getColumns(connectionId, database, node.schema || database, node.label)).map((column) => column.name) : undefined;+ const rowLimit = settingsStore.editorSettings.exportRowLimitEnabled ? settingsStore.editorSettings.exportRowLimit : null;+ const request: api.TableExportRequest = {+ exportId: currentTask.exportId,+ connectionId,+ database,+ schema: node.schema || undefined,+ tableName: node.label,+ filePath: outputPath,+ format,+ columns: queryColumns,+ batchSize: settingsStore.editorSettings.exportBatchSize,+ rowLimit,+ };++ await api.startTableExport(request, (progress) => {+ currentTask.rowsExported = progress.rowsExported;+ currentTask.totalRows = progress.totalRows;+ currentTask.status = progress.status;+ currentTask.errorMessage = progress.errorMessage || null;+ if (progress.status === "Done") toast(t("grid.exported"));+ else if (progress.status === "Error") toast(t("grid.exportFailed", { message: progress.errorMessage || "" }), 5000);+ });+ } catch (error: any) {+ if (task) {+ task.status = "Error";+ task.errorMessage = error?.message || String(error);+ }+ toast(t("grid.exportFailed", { message: error?.message || String(error) }), 5000);+ }+ }++ async function exportData(format: "csv" | "json" | "sql") {+ if (format === "csv") await exportTableData("csv");+ else await exportDataLegacy(format);+ }++ async function exportDataXlsx() {+ await exportTableData("xlsx");+ }++ return {+ copyStructureAs,+ copyStructureDocText,+ copyStructurePreview,+ exportData,+ exportDataXlsx,+ exportStructure,+ saveStructurePreview,+ selectTextareaContent,+ };+}diff --git a/apps/desktop/src/composables/useSidebarTreeToolRuntime.ts b/apps/desktop/src/composables/useSidebarTreeToolRuntime.tsnew file mode 100644index 0000000000..12699f98af--- /dev/null+++ b/apps/desktop/src/composables/useSidebarTreeToolRuntime.ts@@ -0,0 +1,145 @@+import type { ShallowRef } from "vue";+import type { useConnectionStore } from "@/stores/connectionStore";+import type { useQueryStore } from "@/stores/queryStore";+import type { useSettingsStore } from "@/stores/settingsStore";+import type { TreeNode } from "@/types/database";+import { allDatabasesExportSourceForNode, databaseExportSourceForNode } from "@/lib/sidebar/sidebarExportRuntime";++interface SidebarTreeToolRuntimeOptions {+ activeNode: ShallowRef<TreeNode>;+ connectionStore: ReturnType<typeof useConnectionStore>;+ queryStore: ReturnType<typeof useQueryStore>;+ settingsStore: ReturnType<typeof useSettingsStore>;+ tableChildObjectName: (node: TreeNode) => string;+}++export function useSidebarTreeToolRuntime(options: SidebarTreeToolRuntimeOptions) {+ const { activeNode, connectionStore, queryStore, settingsStore } = options;++ function openTransfer() {+ if (!activeNode.value.connectionId) return;+ connectionStore.transferSource = {+ connectionId: activeNode.value.connectionId,+ database: activeNode.value.database ?? "",+ };+ }++ function openSchemaDiff() {+ if (!activeNode.value.connectionId) return;+ connectionStore.schemaDiffSource = {+ connectionId: activeNode.value.connectionId,+ database: activeNode.value.database ?? "",+ schema: activeNode.value.schema,+ };+ }++ function openDataCompare() {+ if (!activeNode.value.connectionId) return;+ connectionStore.dataCompareSource = {+ connectionId: activeNode.value.connectionId,+ database: activeNode.value.database ?? "",+ schema: activeNode.value.schema,+ tableName: activeNode.value.type === "table" ? activeNode.value.label : undefined,+ };+ }++ function openSqlFileExecution() {+ if (!activeNode.value.connectionId) return;+ connectionStore.sqlFileSource = {+ connectionId: activeNode.value.connectionId,+ database: activeNode.value.database ?? "",+ };+ }++ function openDiagram() {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ connectionStore.diagramSource = {+ connectionId: node.connectionId,+ database: node.database,+ schema: node.schema,+ tableName: node.type === "table" ? node.label : undefined,+ };+ }++ function openDatabaseSearch() {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ connectionStore.databaseSearchSource = {+ connectionId: node.connectionId,+ database: node.database,+ schema: node.type === "schema" ? node.schema : undefined,+ };+ }++ function openDatabaseExport() {+ connectionStore.databaseExportSource = databaseExportSourceForNode(activeNode.value);+ }++ function openAllDatabasesExport() {+ connectionStore.databaseExportSource = allDatabasesExportSourceForNode(activeNode.value);+ }++ function openScheduledBackups() {+ settingsStore.requestSettingsNavigation("backups");+ }++ function openTableImport() {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ connectionStore.tableImportSource = {+ connectionId: node.connectionId,+ database: node.database,+ schema: node.schema,+ tableName: node.type === "table" ? node.label : undefined,+ };+ }++ function openStructureEditor() {+ const node = activeNode.value;+ if (!node.connectionId || !node.database) return;+ if (node.type === "table") {+ queryStore.openTableStructure(node.connectionId, node.database, node.schema, node.label, undefined, undefined, node.catalog);+ return;+ }+ if (node.type === "column" && node.tableName) {+ const columnName = options.tableChildObjectName(node).trim();+ if (!columnName) return;+ queryStore.openTableStructure(node.connectionId, node.database, node.schema, node.tableName, "columns", { kind: "column", name: columnName }, node.catalog);+ return;+ }+ if (node.type === "index" && node.tableName) {+ const indexName = options.tableChildObjectName(node).trim();+ if (!indexName) return;+ queryStore.openTableStructure(node.connectionId, node.database, node.schema, node.tableName, "indexes", { kind: "index", name: indexName }, node.catalog);+ }+ }++ function openFieldLineage() {+ const node = activeNode.value;+ const column = node.type === "column" && node.meta && "name" in node.meta ? node.meta.name : node.label;+ if (node.type !== "column" || !node.connectionId || !node.database || !node.tableName || !column) return;+ connectionStore.fieldLineageSource = {+ connectionId: node.connectionId,+ database: node.database,+ schema: node.schema,+ tableName: node.tableName,+ columnName: column,+ };+ }++ return {+ openAllDatabasesExport,+ openDataCompare,+ openDatabaseExport,+ openDatabaseSearch,+ openDiagram,+ openFieldLineage,+ openScheduledBackups,+ openSchemaDiff,+ openSqlFileExecution,+ openStructureEditor,+ openTableImport,+ openTransfer,+ };+}diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarActionTarget.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarActionTarget.spec.tsindex ef76ded575..cf659cf233 100644--- a/apps/desktop/src/lib/__tests__/sidebar/sidebarActionTarget.spec.ts+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarActionTarget.spec.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vitest";import type { TreeNode } from "@/types/database";-import { createSidebarActionRequest, createSidebarActionTarget, findSidebarActionTarget } from "@/lib/sidebar/sidebarActionTarget";+import { createSidebarActionRequest, createSidebarActionTarget, findSidebarActionTarget, releaseRemovedSidebarActionTarget } from "@/lib/sidebar/sidebarActionTarget";function tableNode(): TreeNode {return {@@ -52,6 +52,21 @@ describe("sidebar action targets", () => {expect(findSidebarActionTarget([], target)).toBeNull();});+ it("releases a removed active node's child tree", () => {+ const node = tableNode();+ const released = releaseRemovedSidebarActionTarget(node, [node.id]);++ expect(released).not.toBe(node);+ expect(released.children).toBeUndefined();+ expect(released.hiddenChildren).toBeUndefined();+ });++ it("keeps an active node that was not removed", () => {+ const node = tableNode();++ expect(releaseRemovedSidebarActionTarget(node, ["other-node"])).toBe(node);+ });+it("resolves targets stored only in hidden children", () => {const node = tableNode();const target = createSidebarActionTarget(node);diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarExportRuntime.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarExportRuntime.spec.tsnew file mode 100644index 0000000000..e55b3c58a9--- /dev/null+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarExportRuntime.spec.ts@@ -0,0 +1,29 @@+import { describe, expect, it } from "vitest";+import type { TreeNode } from "@/types/database";+import { allDatabasesExportSourceForNode, databaseExportSourceForNode, sidebarStructureExportTargets } from "@/lib/sidebar/sidebarExportRuntime";++describe("sidebar export runtime", () => {+ it("prepares database and table export sources", () => {+ expect(databaseExportSourceForNode({ id: "schema", label: "public", type: "schema", connectionId: "c1", database: "db", schema: "public" })).toEqual({+ connectionId: "c1",+ database: "db",+ schema: "public",+ });+ expect(databaseExportSourceForNode({ id: "table", label: "users", type: "table", connectionId: "c1", database: "db", schema: "public" })).toEqual({+ connectionId: "c1",+ database: "db",+ schema: "public",+ tableName: "users",+ });+ expect(allDatabasesExportSourceForNode({ id: "c1", label: "Connection", type: "connection", connectionId: "c1" })).toEqual({ connectionId: "c1", database: "", allDatabases: true });+ });++ it("freezes the accepted structure selection before export work starts", () => {+ const first: TreeNode = { id: "t1", label: "one", type: "table", connectionId: "c1", database: "db" };+ const second: TreeNode = { id: "t2", label: "two", type: "view", connectionId: "c1", database: "db" };+ const group: TreeNode = { id: "group", label: "Tables", type: "group-tables", children: [first, second] };++ expect(sidebarStructureExportTargets(first, [group], [first.id, second.id])).toEqual([first, second]);+ expect(sidebarStructureExportTargets(first, [group], [second.id])).toEqual([first]);+ });+});diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeMenuDescriptors.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeMenuDescriptors.spec.tsnew file mode 100644index 0000000000..2cdbb30a43--- /dev/null+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeMenuDescriptors.spec.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from "vitest";+import type { ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";+import type { TreeNode, TreeNodeType } from "@/types/database";+import { createSidebarMenuContext, normalizeSidebarMenuDescriptors } from "@/lib/sidebar/sidebarTreeMenuDescriptors";++const representativeTypes: TreeNodeType[] = ["connection", "database", "schema", "table", "column", "mongo-db", "mongo-collection", "redis-db", "nacos-namespace"];++describe("sidebar tree menu descriptors", () => {+ it.each(representativeTypes)("normalizes stable descriptors for %s", (type) => {+ const node: TreeNode = { id: `${type}-1`, label: type, type };+ const items: ContextMenuItem[] = [+ { label: "Open", action: () => undefined },+ { label: "", separator: true },+ { label: "More", children: [{ label: "Delete", variant: "destructive" }] },+ ];+ const descriptors = normalizeSidebarMenuDescriptors(createSidebarMenuContext(node, [node.id]), items);++ expect(descriptors).toEqual([+ expect.objectContaining({ id: `${type}:0`, label: "Open", disabled: false, separator: false, variant: "default" }),+ expect.objectContaining({ id: `${type}:1`, separator: true }),+ expect.objectContaining({ id: `${type}:2`, children: [expect.objectContaining({ id: `${type}:2.0`, label: "Delete", variant: "destructive" })] }),+ ]);+ });++ it("freezes the accepted target and selection", () => {+ const node: TreeNode = { id: "table-1", label: "before", type: "table" };+ const selection = [node.id];+ const context = createSidebarMenuContext(node, selection, "postgres");+ node.label = "after";+ selection.push("table-2");++ expect(context.target.label).toBe("before");+ expect(context.selectedNodeIds).toEqual(["table-1"]);+ expect(Object.isFrozen(context)).toBe(true);+ });+});diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeRuntime.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeRuntime.spec.tsnew file mode 100644index 0000000000..573e4305b0--- /dev/null+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarTreeRuntime.spec.ts@@ -0,0 +1,65 @@+import { describe, expect, it, vi } from "vitest";+import type { TreeNode } from "@/types/database";+import { createSidebarSelectionSnapshot, createSidebarTreeRuntime, type SidebarTreeRuntimeHost } from "@/lib/sidebar/sidebarTreeRuntime";++function node(id: string, label = id): TreeNode {+ return { id, label, type: "table", connectionId: "connection-1", database: "database-1" };+}++function host(): SidebarTreeRuntimeHost {+ return {+ buildContextMenu: vi.fn(() => []),+ handleRowClick: vi.fn(),+ handleRowDoubleClick: vi.fn(),+ handleRowKeydown: vi.fn(),+ openDataInNewTab: vi.fn(),+ requestPaste: vi.fn(() => false),+ toggleNode: vi.fn(),+ };+}++describe("sidebar tree runtime", () => {+ it("keeps target and selection snapshots immutable", () => {+ const first = node("table-1", "before");+ const second = node("table-2");+ const selectedIds = [first.id];+ const snapshot = createSidebarSelectionSnapshot([first, second], selectedIds);++ first.label = "after";+ selectedIds.push(second.id);++ expect(snapshot.ids).toEqual(["table-1"]);+ expect(snapshot.targets).toEqual([expect.objectContaining({ id: "table-1", label: "before" })]);+ expect(Object.isFrozen(snapshot)).toBe(true);+ expect(Object.isFrozen(snapshot.ids)).toBe(true);+ expect(Object.isFrozen(snapshot.targets)).toBe(true);+ });++ it("shares one host across many row consumers", () => {+ const runtime = createSidebarTreeRuntime();+ const runtimeHost = host();+ runtime.bindHost(runtimeHost);++ for (let index = 0; index < 100; index += 1) runtime.handleRowClick(node(`table-${index}`), 1);++ expect(runtime.diagnostics.hostBindings).toBe(1);+ expect(runtimeHost.handleRowClick).toHaveBeenCalledTimes(100);+ });++ it("rejects superseded and disposed generations without affecting another runtime", () => {+ const runtime = createSidebarTreeRuntime();+ const otherRuntime = createSidebarTreeRuntime();+ const first = runtime.beginAction();+ const unrelated = otherRuntime.beginAction();+ const second = runtime.beginAction();++ expect(runtime.isCurrent(first)).toBe(false);+ expect(runtime.isCurrent(second)).toBe(true);+ expect(otherRuntime.isCurrent(unrelated)).toBe(true);++ runtime.dispose();++ expect(runtime.isCurrent(second)).toBe(false);+ expect(otherRuntime.isCurrent(unrelated)).toBe(true);+ });+});diff --git a/apps/desktop/src/lib/__tests__/table/objectBrowserRowAction.spec.ts b/apps/desktop/src/lib/__tests__/table/objectBrowserRowAction.spec.tsindex 5c34f0bb87..c595ef2ecc 100644--- a/apps/desktop/src/lib/__tests__/table/objectBrowserRowAction.spec.ts+++ b/apps/desktop/src/lib/__tests__/table/objectBrowserRowAction.spec.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { doubleClickRowAction, resolveRowClickAction, shouldDeferSingleClick, singleClickRowAction, type ObjectBrowserRowAction } from "@/lib/table/objectBrowserRowAction";+import { doubleClickRowAction, resolveRowClickAction, shouldDeferSingleClick, singleClickRowAction } from "@/lib/table/objectBrowserRowAction";import type { ObjectBrowserRow } from "@/lib/table/objectBrowserRows";function row(type: ObjectBrowserRow["type"], name = "test"): ObjectBrowserRow {diff --git a/apps/desktop/src/lib/connection/connectionFile.ts b/apps/desktop/src/lib/connection/connectionFile.tsindex 843668c57b..c3af15e002 100644--- a/apps/desktop/src/lib/connection/connectionFile.ts+++ b/apps/desktop/src/lib/connection/connectionFile.ts@@ -70,7 +70,7 @@ export function defaultSqliteBackupFileName(config: Pick<ConnectionConfig, "hostfunction sanitizeFileName(fileName: string): string {return fileName- .replace(/[<>:"/\\|?*\u0000-\u001f]/g, "_")+ .replace(/[<>:"/\\|?*\p{Cc}]/gu, "_").trim().replace(/[. ]+$/g, "");}diff --git a/apps/desktop/src/lib/dataGrid/dataGenerate.ts b/apps/desktop/src/lib/dataGrid/dataGenerate.tsindex d4c929794b..c9fb878ada 100644--- a/apps/desktop/src/lib/dataGrid/dataGenerate.ts+++ b/apps/desktop/src/lib/dataGrid/dataGenerate.ts@@ -1168,7 +1168,7 @@ export function findGeneratorKey(columnName: string, dataType: string, isAutoIncconst isDateTime = type.includes("date") || type.includes("timestamp") || type === "time";const isBinary = type.includes("binary") || type.includes("blob") || type.includes("bytea");const isBoolType = type === "bool" || type === "boolean" || type === "bit" || type === "tinyint(1)";- const isBoolName = /^(is|has|had|can|did|enable|disable|allow|use|visible|deleted|active|flag)[_\-]?/i.test(columnName);+ const isBoolName = /^(is|has|had|can|did|enable|disable|allow|use|visible|deleted|active|flag)[_-]?/i.test(columnName);if (isNumeric || isDateTime || isBinary) {if (type.includes("serial")) return "sequence";if (isBoolType || (isNumeric && isBoolName)) return "enum";@@ -1388,7 +1388,7 @@ export function defaultGeneratorParams(_columnName: string, attrs: ColumnAttrs,const t = attrs.dataType.toLowerCase();const isNum = t.includes("int") || t.includes("bool") || t.includes("decimal") || t.includes("numeric") || t.includes("float") || t.includes("double") || t === "real";const isBoolType = t === "bool" || t === "boolean" || t === "bit" || t === "tinyint(1)";- const isBoolName = /^(is|has|had|can|did|enable|disable|allow|use|visible|deleted|active|flag)[_\-]?/i.test(_columnName);+ const isBoolName = /^(is|has|had|can|did|enable|disable|allow|use|visible|deleted|active|flag)[_-]?/i.test(_columnName);if (isBoolType || (isNum && isBoolName)) {params.values = "0\n1";} else if (isNum) {diff --git a/apps/desktop/src/lib/database/mysqlConnectionOptions.ts b/apps/desktop/src/lib/database/mysqlConnectionOptions.tsindex e9fae9bb8c..ab411a9aac 100644--- a/apps/desktop/src/lib/database/mysqlConnectionOptions.ts+++ b/apps/desktop/src/lib/database/mysqlConnectionOptions.ts@@ -23,7 +23,8 @@ export function mysqlCleartextPasswordAuthEnabled(params: string | undefined): bexport function setMysqlCleartextPasswordAuthEnabled(params: string | undefined, enabled: boolean): string {const parsed = new URLSearchParams((params || "").trim().replace(/^\?/, ""));- for (const key of [...parsed.keys()]) {+ // Snapshot keys because deleting from URLSearchParams during live iteration can skip duplicates.+ for (const key of Array.from(parsed.keys())) {if (isMysqlCleartextPasswordParam(key)) parsed.delete(key);}if (enabled) parsed.set(MYSQL_CLEAR_TEXT_PARAM, "true");diff --git a/apps/desktop/src/lib/document/gridfsFiles.ts b/apps/desktop/src/lib/document/gridfsFiles.tsindex fbdae0a771..82111d8572 100644--- a/apps/desktop/src/lib/document/gridfsFiles.ts+++ b/apps/desktop/src/lib/document/gridfsFiles.ts@@ -84,7 +84,7 @@ function withDuplicateSuffix(fileName: string, index: number): string {function sanitizePathStem(value: string): string {return value.trim()- .replace(/[<>:"/\\|?*\u0000-\u001f]+/g, "-")+ .replace(/[<>:"/\\|?*\p{Cc}]+/gu, "-").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^[-.\s]+|[-.\s]+$/g, "")diff --git a/apps/desktop/src/lib/nacos/nacosAdmin.ts b/apps/desktop/src/lib/nacos/nacosAdmin.tsindex 6e2a5b05f9..b412c38e63 100644--- a/apps/desktop/src/lib/nacos/nacosAdmin.ts+++ b/apps/desktop/src/lib/nacos/nacosAdmin.ts@@ -85,7 +85,7 @@ export function resolveNacosConfigCopyText(selectionText: string, editorText: stexport function sanitizeNacosConfigFileNameSegment(value: string): string {const sanitized = value.trim()- .replace(/[<>:"/\\|?*\x00-\x1f]/g, "_")+ .replace(/[<>:"/\\|?*\p{Cc}]/gu, "_").replace(/\s+/g, " ").replace(/^[._\s-]+/, "").replace(/\.+$/, "");diff --git a/apps/desktop/src/lib/sidebar/sidebarActionTarget.ts b/apps/desktop/src/lib/sidebar/sidebarActionTarget.tsindex b08b2d7391..fe16a7fcf6 100644--- a/apps/desktop/src/lib/sidebar/sidebarActionTarget.ts+++ b/apps/desktop/src/lib/sidebar/sidebarActionTarget.ts@@ -36,6 +36,11 @@ export function createSidebarActionTarget(node: TreeNode): SidebarActionTarget {return Object.freeze({ ...node, children: undefined, hiddenChildren: undefined, meta });}+export function releaseRemovedSidebarActionTarget(node: TreeNode, removedNodeIds: readonly string[]): TreeNode {+ if (!removedNodeIds.includes(node.id)) return node;+ return { ...createSidebarActionTarget(node) };+}+export function createSidebarActionRequest<TPayload>(node: TreeNode, selectedNodeIds: readonly string[], payload: TPayload): SidebarActionRequest<TPayload> {return Object.freeze({target: createSidebarActionTarget(node),diff --git a/apps/desktop/src/lib/sidebar/sidebarDataOpenCoordinator.ts b/apps/desktop/src/lib/sidebar/sidebarDataOpenCoordinator.tsindex ded24db65d..9f19ad7b0f 100644--- a/apps/desktop/src/lib/sidebar/sidebarDataOpenCoordinator.ts+++ b/apps/desktop/src/lib/sidebar/sidebarDataOpenCoordinator.ts@@ -153,7 +153,7 @@ export function runSidebarDataOpenImmediately(optionsOrRunner: SidebarDataOpenOp}export function cancelPendingSidebarDataOpen() {- for (const request of [...requests.values()]) cancelRequest(request);+ for (const request of Array.from(requests.values())) cancelRequest(request);latestSupersedingRequestId = 0;}diff --git a/apps/desktop/src/lib/sidebar/sidebarExportRuntime.ts b/apps/desktop/src/lib/sidebar/sidebarExportRuntime.tsnew file mode 100644index 0000000000..253c27a762--- /dev/null+++ b/apps/desktop/src/lib/sidebar/sidebarExportRuntime.ts@@ -0,0 +1,43 @@+import type { TreeNode } from "@/types/database";++export interface SidebarDatabaseExportSource {+ connectionId: string;+ database: string;+ schema?: string;+ tableName?: string;+ tableNames?: string[];+ allDatabases?: boolean;+}++export function databaseExportSourceForNode(node: TreeNode): SidebarDatabaseExportSource | null {+ if (!node.connectionId || !node.database) return null;+ const objectNode = node.type === "table" || node.type === "view" || node.type === "materialized_view";+ return {+ connectionId: node.connectionId,+ database: node.database,+ schema: node.type === "schema" || objectNode ? node.schema : undefined,+ tableName: objectNode ? node.label : undefined,+ };+}++export function allDatabasesExportSourceForNode(node: TreeNode): SidebarDatabaseExportSource | null {+ if (node.type !== "connection" || !node.connectionId) return null;+ return { connectionId: node.connectionId, database: "", allDatabases: true };+}++export function sidebarStructureExportTargets(activeNode: TreeNode, treeNodes: readonly TreeNode[], selectedNodeIds: readonly string[]): Array<TreeNode & { connectionId: string; database: string }> {+ const canExport = (node: TreeNode): node is TreeNode & { connectionId: string; database: string } => (node.type === "table" || node.type === "view" || node.type === "materialized_view") && !!node.connectionId && !!node.database;+ if (!canExport(activeNode)) return [];++ const selected = new Set(selectedNodeIds);+ const targets: Array<TreeNode & { connectionId: string; database: string }> = [];+ const visit = (nodes: readonly TreeNode[]) => {+ for (const node of nodes) {+ if (selected.has(node.id) && canExport(node)) targets.push(node);+ if (node.children) visit(node.children);+ if (node.hiddenChildren) visit(node.hiddenChildren);+ }+ };+ visit(treeNodes);+ return targets.length > 1 && targets.some((node) => node.id === activeNode.id) ? targets : [activeNode];+}diff --git a/apps/desktop/src/lib/sidebar/sidebarTreeMenuDescriptors.ts b/apps/desktop/src/lib/sidebar/sidebarTreeMenuDescriptors.tsnew file mode 100644index 0000000000..f11a3752e3--- /dev/null+++ b/apps/desktop/src/lib/sidebar/sidebarTreeMenuDescriptors.ts@@ -0,0 +1,44 @@+import type { ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";+import type { DatabaseType, TreeNode, TreeNodeType } from "@/types/database";+import { createSidebarActionTarget, type SidebarActionTarget } from "./sidebarActionTarget";++export type SidebarMenuActionId = `${TreeNodeType}:${string}`;++export interface SidebarMenuContext {+ readonly target: SidebarActionTarget;+ readonly selectedNodeIds: readonly string[];+ readonly databaseType?: DatabaseType;+}++export interface SidebarMenuDescriptor {+ readonly id: SidebarMenuActionId;+ readonly label: string;+ readonly disabled: boolean;+ readonly separator: boolean;+ readonly variant: "default" | "destructive";+ readonly children: readonly SidebarMenuDescriptor[];+}++export function createSidebarMenuContext(node: TreeNode, selectedNodeIds: readonly string[], databaseType?: DatabaseType): SidebarMenuContext {+ return Object.freeze({+ target: createSidebarActionTarget(node),+ selectedNodeIds: Object.freeze([...selectedNodeIds]),+ databaseType,+ });+}++export function normalizeSidebarMenuDescriptors(context: SidebarMenuContext, items: readonly ContextMenuItem[]): readonly SidebarMenuDescriptor[] {+ const normalize = (entries: readonly ContextMenuItem[], parentPath: string): SidebarMenuDescriptor[] =>+ entries.map((item, index) => {+ const path = parentPath ? `${parentPath}.${index}` : String(index);+ return Object.freeze({+ id: `${context.target.type}:${path}` as SidebarMenuActionId,+ label: item.label,+ disabled: item.disabled === true,+ separator: item.separator === true,+ variant: item.variant ?? "default",+ children: Object.freeze(normalize(item.children ?? [], path)),+ });+ });+ return Object.freeze(normalize(items, ""));+}diff --git a/apps/desktop/src/lib/sidebar/sidebarTreeRuntime.ts b/apps/desktop/src/lib/sidebar/sidebarTreeRuntime.tsnew file mode 100644index 0000000000..833abe5c22--- /dev/null+++ b/apps/desktop/src/lib/sidebar/sidebarTreeRuntime.ts@@ -0,0 +1,116 @@+import type { ComponentPublicInstance, InjectionKey } from "vue";+import type { ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";+import type { TreeNode } from "@/types/database";+import { createSidebarActionTarget, type SidebarActionTarget } from "./sidebarActionTarget";++export interface SidebarSelectionSnapshot {+ readonly ids: readonly string[];+ readonly targets: readonly SidebarActionTarget[];+}++export interface SidebarTreeRuntimeGeneration {+ readonly runtimeId: symbol;+ readonly generation: number;+}++export interface SidebarTreeRuntimeHost {+ buildContextMenu(node: TreeNode): ContextMenuItem[];+ handleRowClick(node: TreeNode, clickDetail: number): void;+ handleRowDoubleClick(node: TreeNode, event: MouseEvent): void;+ handleRowKeydown(node: TreeNode, event: KeyboardEvent): void;+ openDataInNewTab(node: TreeNode): void;+ requestPaste(node: TreeNode): boolean;+ toggleNode(node: TreeNode): void;+}++export type SidebarTreeRuntimeHostInstance = ComponentPublicInstance & SidebarTreeRuntimeHost;++export interface SidebarTreeRuntime {+ readonly runtimeId: symbol;+ readonly diagnostics: {+ readonly hostBindings: number;+ readonly menuBuilds: number;+ };+ bindHost(host: SidebarTreeRuntimeHost | null): void;+ beginAction(): SidebarTreeRuntimeGeneration;+ isCurrent(token: SidebarTreeRuntimeGeneration): boolean;+ buildContextMenu(node: TreeNode): ContextMenuItem[];+ handleRowClick(node: TreeNode, clickDetail: number): void;+ handleRowDoubleClick(node: TreeNode, event: MouseEvent): void;+ handleRowKeydown(node: TreeNode, event: KeyboardEvent): void;+ openDataInNewTab(node: TreeNode): void;+ requestPaste(node: TreeNode): boolean;+ toggleNode(node: TreeNode): void;+ dispose(): void;+}++export const sidebarTreeRuntimeKey: InjectionKey<SidebarTreeRuntime> = Symbol("sidebar-tree-runtime");++export function createSidebarSelectionSnapshot(nodes: readonly TreeNode[], selectedIds: readonly string[]): SidebarSelectionSnapshot {+ const selected = new Set(selectedIds);+ const targets = nodes.filter((node) => selected.has(node.id)).map(createSidebarActionTarget);+ return Object.freeze({+ ids: Object.freeze([...selectedIds]),+ targets: Object.freeze(targets),+ });+}++export function createSidebarTreeRuntime(): SidebarTreeRuntime {+ const runtimeId = Symbol("sidebar-tree-runtime-instance");+ let host: SidebarTreeRuntimeHost | null = null;+ let generation = 0;+ let disposed = false;+ let hostBindings = 0;+ let menuBuilds = 0;++ function currentHost(): SidebarTreeRuntimeHost | null {+ return disposed ? null : host;+ }++ return {+ runtimeId,+ get diagnostics() {+ return { hostBindings, menuBuilds };+ },+ bindHost(nextHost) {+ if (disposed) return;+ host = nextHost;+ if (nextHost) hostBindings += 1;+ },+ beginAction() {+ generation += 1;+ return Object.freeze({ runtimeId, generation });+ },+ isCurrent(token) {+ return !disposed && token.runtimeId === runtimeId && token.generation === generation;+ },+ buildContextMenu(node) {+ menuBuilds += 1;+ return currentHost()?.buildContextMenu(node) ?? [];+ },+ handleRowClick(node, clickDetail) {+ currentHost()?.handleRowClick(node, clickDetail);+ },+ handleRowDoubleClick(node, event) {+ currentHost()?.handleRowDoubleClick(node, event);+ },+ handleRowKeydown(node, event) {+ currentHost()?.handleRowKeydown(node, event);+ },+ openDataInNewTab(node) {+ currentHost()?.openDataInNewTab(node);+ },+ requestPaste(node) {+ return currentHost()?.requestPaste(node) ?? false;+ },+ toggleNode(node) {+ currentHost()?.toggleNode(node);+ },+ dispose() {+ if (disposed) return;+ disposed = true;+ generation += 1;+ host = null;+ },+ };+}diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.tsindex f194cafd99..5b18188237 100644--- a/apps/desktop/src/stores/connectionStore.ts+++ b/apps/desktop/src/stores/connectionStore.ts@@ -1935,7 +1935,7 @@ export const useConnectionStore = defineStore("connection", () => {const existing = connections.value[idx].visible_schemas;let nextSchemas: Record<string, string[]> | undefined;if (schemaNames) {- nextSchemas = { ...(existing || {}), [database]: schemaNames };+ nextSchemas = { ...existing, [database]: schemaNames };} else if (existing) {nextSchemas = { ...existing };delete nextSchemas[database];diff --git a/apps/desktop/vite.config.ts b/apps/desktop/vite.config.tsindex ea88e10cc0..c98608775c 100644--- a/apps/desktop/vite.config.ts+++ b/apps/desktop/vite.config.ts@@ -73,6 +73,8 @@ export default defineConfig(async () => ({build: {outDir: "../../dist",emptyOutDir: true,+ // Large generated syntax grammars are already isolated and loaded on demand.+ chunkSizeWarningLimit: 800,rollupOptions: {output: {manualChunks: chunkNameForModule,diff --git a/packages/app-tests/codemirrorSqlDialect.test.ts b/packages/app-tests/codemirrorSqlDialect.test.tsindex c9ef64ef9d..2e138cdae2 100644--- a/packages/app-tests/codemirrorSqlDialect.test.ts+++ b/packages/app-tests/codemirrorSqlDialect.test.ts@@ -104,5 +104,5 @@ test("propagates database type to every DDL viewer entrypoint", () => {assert.match(connectionTree, /<SidebarDdlViewDialog/);assert.match(connectionTree, /:database-type="sidebarDdlDatabaseType"/);assert.match(connectionTree, /v-model:open="sidebarDdlOpen"/);- assert.match(app, /<DdlViewDialog[^>]*:database-type="queryEditorDdlDatabaseType"[^>]*\/>/);+ assert.match(app, /<QueryEditorDdlViewDialog[^>]*:database-type="queryEditorDdlDatabaseType"[^>]*\/>/);});diff --git a/packages/app-tests/dataGridProps.test.ts b/packages/app-tests/dataGridProps.test.tsindex c571837ea0..83a2746b56 100644--- a/packages/app-tests/dataGridProps.test.ts+++ b/packages/app-tests/dataGridProps.test.ts@@ -9,6 +9,19 @@ function compiledDataGridScript(): string {return compileScript(descriptor, { id: "data-grid-props-test" }).content;}+test("DataGrid template components have local or documented global bindings", () => {+ const source = readFileSync("apps/desktop/src/components/grid/DataGrid.vue", "utf8");+ const { descriptor } = parse(source, { filename: "DataGrid.vue" });+ const bindings = compileScript(descriptor, { id: "data-grid-component-bindings" }).bindings;+ assert.ok(descriptor.template);++ const globalComponents = new Set(["RecycleScroller"]);+ const componentTags = new Set(Array.from(descriptor.template.content.matchAll(/<([A-Z][A-Za-z0-9]*)\b/g), (match) => match[1]));+ for (const tag of componentTags) {+ assert.ok(bindings[tag] || globalComponents.has(tag), `DataGrid template component ${tag} must be imported or explicitly registered globally`);+ }+});+test("row action limit props default to undefined when omitted", () => {const compiled = compiledDataGridScript();diff --git a/packages/app-tests/productionGuardEntrypoints.test.ts b/packages/app-tests/productionGuardEntrypoints.test.tsindex ce61514c49..1b7d86de2e 100644--- a/packages/app-tests/productionGuardEntrypoints.test.ts+++ b/packages/app-tests/productionGuardEntrypoints.test.ts@@ -44,7 +44,7 @@ test("secondary write entrypoints use the shared production SQL guard", () => {sourceKey: "production.sourceExtension",},{- path: "apps/desktop/src/components/sidebar/TreeItem.vue",+ path: "apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue",executor: "api.executeQuery",sourceKey: "production.sourceSidebar",},diff --git a/packages/app-tests/sidebarContextMenuHost.test.ts b/packages/app-tests/sidebarContextMenuHost.test.tsindex 9b6bdd2739..74d41209f5 100644--- a/packages/app-tests/sidebarContextMenuHost.test.ts+++ b/packages/app-tests/sidebarContextMenuHost.test.ts@@ -28,10 +28,13 @@ test("rare sidebar dialogs share module-level async wrappers with fallbacks", ()test("tree host owns sidebar data-open generations", () => {const treeItem = readFileSync("apps/desktop/src/components/sidebar/TreeItem.vue", "utf8");+ const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");const connectionTree = readFileSync("apps/desktop/src/components/sidebar/ConnectionTree.vue", "utf8");assert.doesNotMatch(treeItem, /runSidebarDataOpenImmediately/);- assert.match(treeItem, /emit\("open-data", node, true, "default", openData\)/);+ assert.doesNotMatch(treeItem, /emit\("open-data"/);+ assert.match(runtimeHost, /emit\("open-data", node, true, "default", openData\)/);+ assert.match(connectionTree, /<SidebarTreeRuntimeHost/);assert.match(connectionTree, /function openSidebarData/);assert.match(connectionTree, /runSidebarDataOpenImmediately/);assert.match(connectionTree, /createSidebarActionTarget\(node\)/);diff --git a/packages/app-tests/sidebarDialogRouting.test.ts b/packages/app-tests/sidebarDialogRouting.test.tsindex 7d76eefd0f..c9deafde21 100644--- a/packages/app-tests/sidebarDialogRouting.test.ts+++ b/packages/app-tests/sidebarDialogRouting.test.ts@@ -4,6 +4,7 @@ import { test } from "vitest";const connectionTree = readFileSync("apps/desktop/src/components/sidebar/ConnectionTree.vue", "utf8");const treeItem = readFileSync("apps/desktop/src/components/sidebar/TreeItem.vue", "utf8");+const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");const dialogHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeItemDialogs.vue", "utf8");const dialogState = readFileSync("apps/desktop/src/components/sidebar/sidebarTreeDialogState.ts", "utf8");const visibleDatabasesDialog = readFileSync("apps/desktop/src/components/sidebar/VisibleDatabasesDialog.vue", "utf8");@@ -14,7 +15,7 @@ function occurrences(source: string, value: string): number {}test("sidebar routes destructive confirmations through one tree-level host", () => {- assert.match(treeItem, /emit\("open-danger-dialog", route\.createRequest\(\)\)/);+ assert.match(runtimeHost, /emit\("open-danger-dialog", route\.createRequest\(\)\)/);assert.match(connectionTree, /function openSidebarDangerDialog\(request: SidebarDangerDialogRequest\)/);assert.equal(occurrences(connectionTree, "<SidebarDangerConfirmDialog"), 1);assert.doesNotMatch(treeItem, /<DangerConfirmDialog/);@@ -54,9 +55,10 @@ test("shared dialog state is owner-gated and confirm handlers use snapshots", ()assert.match(dialogState, /export const sidebarTreeDialogOwner = shallowRef<symbol \| null>\(null\)/);assert.match(dialogState, /export const sidebarDangerTarget = shallowRef<TreeNode \| null>\(null\)/);assert.match(dialogState, /export const sidebarFormTarget = shallowRef<TreeNode \| null>\(null\)/);- assert.match(treeItem, /sidebarTreeDialogOwner\.value !== treeItemDialogOwner/);- assert.match(treeItem, /const node = sidebarDangerTarget\.value \?\? props\.node/);- assert.match(treeItem, /const node = sidebarFormTarget\.value \?\? props\.node/);- assert.match(treeItem, /batchDropTargets\.value = targets\.slice\(\)/);- assert.match(treeItem, /batchTruncateTargets\.value = targets\.slice\(\)/);+ assert.match(runtimeHost, /sidebarTreeDialogOwner\.value !== treeItemDialogOwner/);+ assert.match(runtimeHost, /const node = sidebarDangerTarget\.value \?\? activeNode\.value/);+ assert.match(runtimeHost, /const node = sidebarFormTarget\.value \?\? activeNode\.value/);+ assert.match(runtimeHost, /batchDropTargets\.value = targets\.slice\(\)/);+ assert.match(runtimeHost, /batchTruncateTargets\.value = targets\.slice\(\)/);+ assert.match(runtimeHost, /activateActionTarget\(target\)/);});diff --git a/packages/app-tests/sidebarMutationRuntime.test.ts b/packages/app-tests/sidebarMutationRuntime.test.tsnew file mode 100644index 0000000000..0ee9272e8a--- /dev/null+++ b/packages/app-tests/sidebarMutationRuntime.test.ts@@ -0,0 +1,61 @@+import { strict as assert } from "node:assert";+import { readFileSync } from "node:fs";+import { test } from "vitest";++const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");+const connectionMutationRuntime = readFileSync("apps/desktop/src/composables/useSidebarConnectionMutationRuntime.ts", "utf8");+const databaseSpecificMutationRuntime = readFileSync("apps/desktop/src/composables/useSidebarDatabaseSpecificMutationRuntime.ts", "utf8");+const tableMutationRuntime = readFileSync("apps/desktop/src/composables/useSidebarTableMutationRuntime.ts", "utf8");++function functionBody(name: string): string {+ const source = [runtimeHost, connectionMutationRuntime, databaseSpecificMutationRuntime, tableMutationRuntime].find((candidate) => candidate.includes(`function ${name}(`));+ assert.ok(source, name);+ const signatureIndex = Math.max(source.indexOf(`async function ${name}(`), source.indexOf(`function ${name}(`));+ assert.notEqual(signatureIndex, -1, name);+ const bodyStart = source.indexOf("{", signatureIndex);+ let depth = 0;+ for (let index = bodyStart; index < source.length; index += 1) {+ if (source[index] === "{") depth += 1;+ if (source[index] === "}" && --depth === 0) return source.slice(bodyStart + 1, index);+ }+ throw new Error(`Could not parse ${name}`);+}++test("mutation families retain accepted targets, failures, and refresh work", () => {+ const rename = functionBody("confirmRenameObject");+ assert.match(rename, /sidebarFormTarget\.value \?\? activeNode\.value/);+ assert.match(rename, /try \{/);+ assert.match(rename, /catch \(e: any\)/);++ for (const name of ["confirmEmptyTable", "confirmTruncateTable"]) {+ const body = functionBody(name);+ assert.match(body, /sidebarDangerTarget\.value \?\? activeNode\.value/);+ assert.match(body, /refreshMutatedTableDataTabsForNode\(node\)/);+ assert.match(body, /tableOperationFailed/);+ }++ for (const name of ["confirmCreateNacosNamespace", "confirmEditNacosNamespace", "confirmDropDatabase", "confirmDropMongoCollection"]) {+ const body = functionBody(name);+ assert.match(body, /try \{/);+ assert.match(body, /catch \([A-Za-z]+: any\)/);+ assert.match(body, /finally \{/);+ assert.match(body, /Loading\.value = false/);+ }++ const redis = functionBody("confirmFlushRedisDb");+ assert.match(redis, /updateRedisDbKeyStats/);+ assert.match(redis, /dbx-redis-db-flushed/);++ const cancel = functionBody("cancelConnectionAttempt");+ assert.match(cancel, /cancelConnecting/);+ assert.match(cancel, /connectCancelled/);+});++test("menu and dialog mutations resolve immutable accepted targets", () => {+ assert.match(runtimeHost, /createSidebarMenuContext\(node, connectionStore\.selectedTreeNodeIds/);+ assert.match(runtimeHost, /bindMenuTarget\(rawItems, menuContext\.target, menuContext\.selectedNodeIds\)/);+ assert.match(runtimeHost, /activateActionTarget\(target\)/);+ assert.match(runtimeHost, /findSidebarActionTarget\(connectionStore\.treeNodes, target\) \?\? target/);+ assert.match(runtimeHost, /routedRequest\.confirm = async \(\) => \{[\s\S]*?activateActionTarget\(target\)/);+ assert.match(runtimeHost, /routedController\[key\] = \(\.\.\.args: unknown\[\]\) => \{[\s\S]*?activateActionTarget\(target\)/);+});diff --git a/packages/app-tests/sidebarRuntimeDecomposition.test.ts b/packages/app-tests/sidebarRuntimeDecomposition.test.tsnew file mode 100644index 0000000000..2f52693dd4--- /dev/null+++ b/packages/app-tests/sidebarRuntimeDecomposition.test.ts@@ -0,0 +1,47 @@+import { strict as assert } from "node:assert";+import { readFileSync } from "node:fs";+import { test } from "vitest";++const treeItem = readFileSync("apps/desktop/src/components/sidebar/TreeItem.vue", "utf8");+const connectionTree = readFileSync("apps/desktop/src/components/sidebar/ConnectionTree.vue", "utf8");+const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");+const dataOpenRuntime = readFileSync("apps/desktop/src/composables/useSidebarDataOpenRuntime.ts", "utf8");++function occurrences(source: string, pattern: RegExp): number {+ return source.match(pattern)?.length ?? 0;+}++test("sidebar rows stay within the hot-path source budget", () => {+ assert.ok(treeItem.split("\n").length <= 2_200, "TreeItem must stay below 2,200 lines");+ assert.ok(occurrences(treeItem, /^(?:async )?function /gm) <= 90, "TreeItem must stay below 90 top-level functions");+ assert.ok(occurrences(treeItem, /^const [A-Za-z0-9_]+ = computed\(/gm) <= 25, "TreeItem must stay below 25 computed values");+ assert.doesNotMatch(treeItem, /ContextMenuItem|emit\("open-data"|getTreeItemDialogController|executeWithProductionSqlGuard/);+});++test("one tree-level runtime serves every row renderer", () => {+ assert.equal(occurrences(connectionTree, /<SidebarTreeRuntimeHost\b/g), 1);+ assert.equal(occurrences(connectionTree, /provide\(sidebarTreeRuntimeKey, sidebarTreeRuntime\)/g), 1);+ assert.match(connectionTree, /sidebarTreeRuntime\.buildContextMenu\(node\)/);+ assert.match(runtimeHost, /<template \/>/);+ assert.match(runtimeHost, /function bindMenuTarget\(/);+ assert.match(runtimeHost, /function activateActionTarget\(/);+ assert.match(runtimeHost, /useSidebarDataOpenRuntime\(\)/);+ assert.doesNotMatch(runtimeHost, /async function openData\(/);+ assert.match(dataOpenRuntime, /async function openData\(/);+ assert.match(dataOpenRuntime, /findExistingDataTabCandidate/);+ assert.match(dataOpenRuntime, /loadTableMetadata/);+ assert.match(dataOpenRuntime, /canApplyDataTabMetadata/);+});++test("the persistent runtime releases detached tree nodes", () => {+ const actionTarget = readFileSync("apps/desktop/src/lib/sidebar/sidebarActionTarget.ts", "utf8");+ const connectionMutationRuntime = readFileSync("apps/desktop/src/composables/useSidebarConnectionMutationRuntime.ts", "utf8");+ const tableMutationRuntime = readFileSync("apps/desktop/src/composables/useSidebarTableMutationRuntime.ts", "utf8");++ assert.match(actionTarget, /function releaseRemovedSidebarActionTarget/);+ assert.match(actionTarget, /children: undefined, hiddenChildren: undefined/);+ assert.match(runtimeHost, /\(\) => connectionStore\.treeNodes/);+ assert.match(runtimeHost, /findSidebarActionTarget\(nodes, createSidebarActionTarget\(activeNode\.value\)\)/);+ assert.match(connectionMutationRuntime, /releaseActiveNodeReference\(targets\.map\(\(target\) => target\.id\)\)/);+ assert.match(tableMutationRuntime, /releaseActiveNodeReference\(\[node\.id\]\)/);+});diff --git a/packages/app-tests/sidebarTreeAffordances.test.ts b/packages/app-tests/sidebarTreeAffordances.test.tsindex 1555594e00..2d729b3187 100644--- a/packages/app-tests/sidebarTreeAffordances.test.ts+++ b/packages/app-tests/sidebarTreeAffordances.test.ts@@ -3,11 +3,13 @@ import { readFileSync } from "node:fs";import { test } from "vitest";const treeItem = readFileSync("apps/desktop/src/components/sidebar/TreeItem.vue", "utf8");+const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");const connectionTree = readFileSync("apps/desktop/src/components/sidebar/ConnectionTree.vue", "utf8");test("sidebar rows retain database-specific node affordances", () => {for (const nodeType of ["connection", "database", "schema", "table", "column", "mongo-db", "mongo-collection", "redis-db", "nacos-namespace", "mq-tenant"]) {- assert.ok(treeItem.includes(`node.type === "${nodeType}"`) || treeItem.includes(`node.type === '${nodeType}'`), nodeType);+ const sources = `${treeItem}\n${runtimeHost}`;+ assert.ok(sources.includes(`node.type === "${nodeType}"`) || sources.includes(`node.type === '${nodeType}'`), nodeType);}assert.match(treeItem, /@dblclick="onDoubleClick"/);assert.match(treeItem, /@keydown="onKeydown"/);diff --git a/packages/app-tests/sidebarTreeItemCleanup.test.ts b/packages/app-tests/sidebarTreeItemCleanup.test.tsindex 26afae80cd..d2f07b1acc 100644--- a/packages/app-tests/sidebarTreeItemCleanup.test.ts+++ b/packages/app-tests/sidebarTreeItemCleanup.test.ts@@ -1,26 +1,56 @@import { strict as assert } from "node:assert";import { readFileSync } from "node:fs";import { test } from "vitest";+import { compileScript, parse } from "vue/compiler-sfc";const treeItem = readFileSync("apps/desktop/src/components/sidebar/TreeItem.vue", "utf8");+test("sidebar row template components have script bindings", () => {+ const descriptor = parse(treeItem).descriptor;+ const bindings = compileScript(descriptor, { id: "sidebar-tree-item" }).bindings;+ const template = descriptor.template;+ assert.ok(template);++ const componentTags = new Set(Array.from(template.content.matchAll(/<([A-Z][A-Za-z0-9]*)\b/g), (match) => match[1]));++ for (const tag of componentTags) assert.ok(bindings[tag], `TreeItem template component ${tag} must be imported`);+});+test("recycled sidebar rows re-register paste handlers by node id", () => {+ assert.ok(treeItem.indexOf("const sidebarTreeContext = inject") < treeItem.indexOf("const stopPasteHandlerRegistration = watch"));assert.match(treeItem, /watch\(\s*\(\) => props\.node\.id,/);- assert.match(treeItem, /registerPasteHandler\?\.\(nodeId, requestPasteTreeClipboard\)/);+ assert.match(treeItem, /registerPasteHandler\?\.\(nodeId, \(\) => treeRuntime\.requestPaste\(props\.node\)\)/);assert.match(treeItem, /if \(unregister\) onCleanup\(unregister\)/);});+test("connection group rename requests are owned by the rendered row", () => {+ const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");+ const connectionMutationRuntime = readFileSync("apps/desktop/src/composables/useSidebarConnectionMutationRuntime.ts", "utf8");+ const connectionTree = readFileSync("apps/desktop/src/components/sidebar/ConnectionTree.vue", "utf8");++ assert.match(treeItem, /const renameInputRef = ref<HTMLInputElement>\(\)/);+ assert.match(treeItem, /watch\(\s*\(\) => props\.pendingRename,[\s\S]*?startRenameGroup\(\)/);+ assert.match(treeItem, /focusSidebarRenameInput\(\(\) => \(isRenamingGroup\.value \? renameInputRef\.value : undefined\)\)/);+ assert.match(runtimeHost, /requestGroupRename: \(groupId\) => emit\("request-group-rename", groupId\)/);+ assert.match(connectionMutationRuntime, /options\.requestGroupRename\(activeNode\.value\.id\)/);+ assert.doesNotMatch(runtimeHost, /const isRenamingGroup = ref\(/);+ assert.match(connectionTree, /@request-group-rename="startRenamingCreatedGroup"/);+});+test("sidebar row unmount clears observers, handlers and drag state", () => {assert.match(treeItem, /function handleMouseLeave\(\)[\s\S]*?labelResizeObserver\?\.disconnect\(\)/);assert.match(treeItem, /function finishTableReferenceDrag\(\)[\s\S]*?document\.removeEventListener\("mousemove"/);- assert.match(treeItem, /onBeforeUnmount\(\(\) => \{[\s\S]*?handleMouseLeave\(\)[\s\S]*?stopPasteHandlerRegistration\(\)[\s\S]*?finishTableReferenceDrag\(\)/);- assert.match(treeItem, /stopDangerDialogRouting\?\.\(\)/);+ assert.match(treeItem, /onBeforeUnmount\(\(\) => \{[\s\S]*?stopPasteHandlerRegistration\(\)[\s\S]*?handleMouseLeave\(\)[\s\S]*?finishTableReferenceDrag\(\)/);+ assert.match(treeItem, /watch\([\s\S]*?\(\) => props\.node,[\s\S]*?finishTableReferenceDrag\(\)/);});test("sidebar rows do not own dialog templates or eager dialog state", () => {+ const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");assert.doesNotMatch(treeItem, /<Dialog(?:\s|>)/);assert.doesNotMatch(treeItem, /<DangerConfirmDialog/);assert.doesNotMatch(treeItem, /const show[A-Z][A-Za-z]+(?:Dialog|Confirm) = ref\(/);- assert.match(treeItem, /function getTreeItemDialogController\(\)/);- assert.match(treeItem, /if \(treeItemDialogController\) return treeItemDialogController/);+ assert.doesNotMatch(treeItem, /function getTreeItemDialogController\(\)/);+ assert.match(treeItem, /inject\(sidebarTreeRuntimeKey\)/);+ assert.match(runtimeHost, /function getTreeItemDialogController\(\)/);+ assert.match(runtimeHost, /if \(treeItemDialogController\) return treeItemDialogController/);});