Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

4.5 KB
Raw Blame
import type { InjectionKey, Ref } from "vue";

/**
 * App-level orchestration behind the per-group SQL editor toolbar.
 *
 * The toolbar renders inside each editor group, but execution, dialogs, and
 * format/compress requests stay App-owned. The group focuses itself on
 * pointerdown/focusin before any toolbar event fires, so handlers may resolve
 * the acting tab from the explicit tabId argument (never re-reading the global
 * active tab after an await).
 */
/** Open/active state of the App-level special pages. */
export interface SpecialPageTabsState {
  settingsOpen: boolean;
  settingsActive: boolean;
  driverStoreOpen: boolean;
  driverStoreActive: boolean;
  pluginCenterOpen: boolean;
  pluginCenterActive: boolean;
  driverUpdateCount: number;
}

export interface EditorToolbarActions {
  canNewQuery: Ref<boolean>;
  newQuery(groupId: string): void;
  explainMode: Ref<"explain" | "autotrace">;
  blockDangerousRedisCommands: Ref<boolean>;
  /** Highlights the database selector of the tab that needs a database choice. */
  databaseRequiredSignalFor(tabId: string): number;
  /** Highlights and opens the connection selector of the tab that needs a connection choice. */
  connectionRequiredSignalFor(tabId: string): number;
  /** Captures the acting editor's execution snapshot before a toolbar click. */
  captureExecutionSnapshot(tabId: string): void;
  toolbarExecute(source: "pointer" | "keyboard", tabId: string): void;
  toolbarExecuteAll(source: "pointer" | "keyboard", tabId: string): void;
  toolbarExecuteInNewResultTab(source: "pointer" | "keyboard", tabId: string): void;
  cancelExecution(tabId: string): void;
  explain(tabId: string): void;
  formatSql(tabId: string): void;
  compressSql(tabId: string): void;
  /** Flips the keyword-case preference and re-cases the acting tab's editor to match. */
  toggleSqlKeywordCase(tabId: string): void;
  saveSql(tabId: string): void;
  saveAllTabs(tabIds?: string[]): void;
  openSqlFile(): void;
  importResultArchive(): void;
  pasteSqlInCondition(): void;
  multiExecute(): void;
  previewChanges(tabId: string): void;
  changeConnection(tabId: string, connectionId: string): void;
  changeCatalog(tabId: string, catalog: string | undefined, database: string): void;
  changeDatabase(tabId: string, database: string): void;
  changeSchema(tabId: string, schema: string | undefined): void;
  setDefaultDatabase(tabId: string): void;
  clearDefaultDatabase(tabId: string): void;
  /** Special pages appended to the focused group's tab strip while open but inactive. */
  specialPageTabs: Ref<SpecialPageTabsState>;
  activateSettingsPage(): void;
  closeSettingsPage(): void;
  activateDriverStore(): void;
  closeDriverStore(): void;
  activatePluginCenter(): void;
  closePluginCenter(): void;
}

export const EDITOR_TOOLBAR_ACTIONS: InjectionKey<EditorToolbarActions> = Symbol("dbx:editor-toolbar-actions");

/**
 * No-op fallback so a group mounted outside the workspace (tests, future
 * hosts) renders a toolbar that does nothing instead of crashing. Production
 * always provides real actions from App.
 */
export function createNoopEditorToolbarActions(): EditorToolbarActions {
  const noop = () => undefined;
  const mode = { value: "explain" } as Ref<"explain" | "autotrace">;
  const flag = { value: true } as Ref<boolean>;
  const specialPageTabs = {
    value: { settingsOpen: false, settingsActive: false, driverStoreOpen: false, driverStoreActive: false, pluginCenterOpen: false, pluginCenterActive: false, driverUpdateCount: 0 },
  } as Ref<SpecialPageTabsState>;
  return {
    canNewQuery: { value: false } as Ref<boolean>,
    newQuery: noop,
    explainMode: mode,
    blockDangerousRedisCommands: flag,
    databaseRequiredSignalFor: () => 0,
    connectionRequiredSignalFor: () => 0,
    captureExecutionSnapshot: noop,
    toolbarExecute: noop,
    toolbarExecuteAll: noop,
    toolbarExecuteInNewResultTab: noop,
    cancelExecution: noop,
    explain: noop,
    formatSql: noop,
    compressSql: noop,
    toggleSqlKeywordCase: noop,
    saveSql: noop,
    saveAllTabs: noop,
    openSqlFile: noop,
    importResultArchive: noop,
    pasteSqlInCondition: noop,
    multiExecute: noop,
    previewChanges: noop,
    changeConnection: noop,
    changeCatalog: noop,
    changeDatabase: noop,
    changeSchema: noop,
    setDefaultDatabase: noop,
    clearDefaultDatabase: noop,
    specialPageTabs,
    activateSettingsPage: noop,
    closeSettingsPage: noop,
    activateDriverStore: noop,
    closeDriverStore: noop,
    activatePluginCenter: noop,
    closePluginCenter: noop,
  };
}