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.9 KB
Raw Blame
import { ref } from "vue";

/**
 * Global "a panel divider is being dragged" state.
 *
 * Resizing side panels or splitter panes changes the width of the CodeMirror
 * editor and the DataGrid on every frame. Both subtrees react to that with
 * expensive per-frame work (CodeMirror's requestMeasure walking every visible
 * line, ResizeObserver chains reading clientWidth/scrollWidth, which forces
 * synchronous layout for the whole document). Heavy components subscribe to
 * this flag to freeze measurement while a drag is in flight and re-sync once
 * it finishes, turning hundreds of forced reflows into a single relayout.
 */
const isPanelResizing = ref(false);
const pendingAfterResize = new Set<() => void>();

function setPanelResizingResyncClass(resizing: boolean) {
  if (typeof document === "undefined") return;
  document.body.classList.toggle("dbx-is-resizing", resizing);
}

/** Marks a drag as in flight. Idempotent: safe to call on every move event. */
export function beginPanelResize() {
  if (isPanelResizing.value) return;
  isPanelResizing.value = true;
  setPanelResizingResyncClass(true);
}

/** Ends the current drag (if any) and flushes registered re-sync callbacks. */
export function endPanelResize() {
  if (!isPanelResizing.value) return;
  isPanelResizing.value = false;
  setPanelResizingResyncClass(false);
  const callbacks = [...pendingAfterResize];
  pendingAfterResize.clear();
  for (const callback of callbacks) {
    try {
      callback();
    } catch {
      // A failed re-sync must not block the other subscribers.
    }
  }
}

/**
 * Registers a measurement callback to run when the in-flight drag ends.
 * Returns whether the caller should skip its own work right now — i.e.
 * `true` means "a drag is active, your callback was queued".
 */
export function deferUntilPanelResizeEnd(callback: () => void): boolean {
  if (!isPanelResizing.value) return false;
  pendingAfterResize.add(callback);
  return true;
}

export { isPanelResizing };