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。

1.7 KB
Raw Blame
import type { SidebarActionTarget } from "@/lib/sidebar/sidebarActionTarget";

export interface SidebarDangerDialogOption {
  checked: boolean;
  label: string;
  hint: string;
  compact?: boolean;
  danger?: boolean;
  onChange?: (checked: boolean) => void | Promise<void>;
}

export interface SidebarDangerDialogProgress {
  completed: number;
  total: number;
  phase?: "preparing" | "executing";
}

export interface SidebarDangerDialogTextInput {
  value: string;
  label: string;
  placeholder?: string;
  inputMode?: "text" | "numeric";
  onInput?: (value: string) => void | Promise<void>;
}

export interface SidebarDangerDialogRequest {
  target: SidebarActionTarget;
  title: string;
  message: string;
  confirmLabel: string;
  sql?: string;
  copySql?: string | (() => string);
  details?: string;
  detailsText?: string;
  loading?: boolean;
  /** Keeps the confirm button held back until the request's own precondition is met (e.g. a typed target name). */
  confirmDisabled?: boolean;
  closeOnConfirm?: boolean;
  progress?: SidebarDangerDialogProgress;
  option?: SidebarDangerDialogOption;
  options?: SidebarDangerDialogOption[];
  textInput?: SidebarDangerDialogTextInput;
  cancelRunning?: () => void | Promise<void>;
  confirm: () => void | boolean | Promise<void | boolean>;
}

// One application-level host keeps requests alive when their originating tab closes.
let dialogHost: ((request: SidebarDangerDialogRequest) => void) | undefined;

export function registerSidebarDangerDialogHost(host: (request: SidebarDangerDialogRequest) => void): () => void {
  dialogHost = host;
  return () => {
    if (dialogHost === host) dialogHost = undefined;
  };
}

export function openSidebarDangerDialog(request: SidebarDangerDialogRequest): void {
  dialogHost?.(request);
}