feat(editor): add sql editor split panes with shared results
This commit is contained in:
1 parent
24a274bd89
commit
5a3a6e2bb0
76 files changed
+7997
-3343
No files matched your search
@@ -0,0 +1,68 @@
|
||||
import type { ContentAreaSurfaceEmits } from "@/components/layout/querySurfaces";
|
||||
|
||||
/**
|
||||
* Single source of truth for the events every content surface forwards
|
||||
* upward. Each layer (QueryEditorSurface / QueryResultSurface / EditorGroup /
|
||||
* SqlEditorWorkspace) derives its v-bind handler object from this list, so the
|
||||
* four forwarding layers cannot drift apart when the contract changes.
|
||||
*/
|
||||
export const contentSurfaceEventNames = [
|
||||
"update:activeOutputView",
|
||||
"fixWithAi",
|
||||
"sendSelectionToAi",
|
||||
"previewChangesAvailable",
|
||||
"execute",
|
||||
"executeInNewResultTab",
|
||||
"saveSql",
|
||||
"cancel",
|
||||
"explain",
|
||||
"editorUpdate",
|
||||
"editorSelectionChange",
|
||||
"editorCursorChange",
|
||||
"editorViewportChange",
|
||||
"editorSelectionStateChange",
|
||||
"formatError",
|
||||
"reload",
|
||||
"paginate",
|
||||
"sort",
|
||||
"executeSql",
|
||||
"clickTable",
|
||||
"viewTableData",
|
||||
"viewTableDdl",
|
||||
"editTableStructure",
|
||||
"openObjectSource",
|
||||
"openObjectTable",
|
||||
"objectSchemaChange",
|
||||
"objectBrowserViewportChange",
|
||||
"structureEditorSaved",
|
||||
"structureEditorClose",
|
||||
"previewStatement",
|
||||
"focusStatement",
|
||||
"openSettings",
|
||||
"openConnectionSettings",
|
||||
"toggleZenMode",
|
||||
] as const satisfies Array<keyof ContentAreaSurfaceEmits>;
|
||||
|
||||
export type ContentSurfaceEventName = (typeof contentSurfaceEventNames)[number];
|
||||
|
||||
export type ContentSurfaceEventForwarders = {
|
||||
[K in ContentSurfaceEventName as `on${Capitalize<K & string>}`]: (...args: ContentAreaSurfaceEmits[K]) => void;
|
||||
};
|
||||
|
||||
type ContentSurfaceEmit = <K extends ContentSurfaceEventName>(event: K, ...args: ContentAreaSurfaceEmits[K]) => void;
|
||||
|
||||
/**
|
||||
* Builds the v-bind event object that re-emits every shared content event.
|
||||
* Emitters stay typed through ContentAreaSurfaceEmits, so adding a new event
|
||||
* to the contract only requires extending the event list once.
|
||||
*/
|
||||
export function createContentSurfaceEventForwarders(emit: ContentSurfaceEmit): ContentSurfaceEventForwarders {
|
||||
const forwarders = {} as Record<string, (...args: unknown[]) => void>;
|
||||
for (const event of contentSurfaceEventNames) {
|
||||
const handlerName = `on${event.charAt(0).toUpperCase()}${event.slice(1)}`;
|
||||
forwarders[handlerName] = (...args: unknown[]) => {
|
||||
(emit as (event: ContentSurfaceEventName, ...args: unknown[]) => void)(event, ...args);
|
||||
};
|
||||
}
|
||||
return forwarders as ContentSurfaceEventForwarders;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Progressive condensation for the per-group SQL editor toolbar.
|
||||
*
|
||||
* The tier is NOT derived from fixed width breakpoints — the control set
|
||||
* changes per database type, transaction state, and feature flags, so any
|
||||
* static guess would over- or under-condense. Instead the toolbar measures its
|
||||
* own row: while the content overflows the available width it steps up one
|
||||
* tier (moving controls into the overflow menu); it only steps back down when
|
||||
* there is real slack AND the pane has grown meaningfully since the last
|
||||
* condensation, so a static narrow layout can never oscillate.
|
||||
*
|
||||
* - Tier 0: full layout.
|
||||
* - Tier 1: secondary edit/entry actions (compress, keyword case, semantic
|
||||
* diagnostics, open SQL, import archive, paste-in-condition, multi-execute)
|
||||
* move into the overflow menu.
|
||||
* - Tier 2: format and the database helper buttons (clear / set-default) join
|
||||
* the overflow menu.
|
||||
* - Tier 3: the explain-analyze toggle and the schema/catalog selectors leave
|
||||
* the row; the row keeps execute, explain, save, transaction controls, the
|
||||
* connection and database selectors (hard-truncated), and the overflow menu.
|
||||
*/
|
||||
export type EditorToolbarTier = 0 | 1 | 2 | 3;
|
||||
|
||||
export const EDITOR_TOOLBAR_MAX_TIER = 3;
|
||||
|
||||
/** Slack (px) required before giving a tier back — absorbs rendering jitter. */
|
||||
export const EDITOR_TOOLBAR_STEP_DOWN_SLACK_PX = 48;
|
||||
/** How much wider the pane must grow (px) vs the last condensation before stepping down. */
|
||||
export const EDITOR_TOOLBAR_STEP_DOWN_MIN_GROWTH_PX = 64;
|
||||
|
||||
export interface EditorToolbarTierInput {
|
||||
tier: EditorToolbarTier;
|
||||
/** Measured inner width of the toolbar row. */
|
||||
availableWidth: number;
|
||||
/** Measured extent of the row's content (scrollWidth), including overflow. */
|
||||
contentWidth: number;
|
||||
/** Toolbar width when the current tier was condensed into; anchors step-down hysteresis. */
|
||||
condensedAtWidth?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the next toolbar tier from real measurements. Monotonic per
|
||||
* measurement — repeated calls after a tier change converge instead of
|
||||
* oscillating, because stepping down additionally requires the pane to have
|
||||
* grown by EDITOR_TOOLBAR_STEP_DOWN_MIN_GROWTH_PX since the last step up.
|
||||
*/
|
||||
export function resolveNextEditorToolbarTier(input: EditorToolbarTierInput): EditorToolbarTier {
|
||||
const { tier, availableWidth, contentWidth, condensedAtWidth = 0 } = input;
|
||||
if (!Number.isFinite(availableWidth) || !Number.isFinite(contentWidth) || availableWidth <= 0 || contentWidth <= 0) {
|
||||
// Unmeasured (first paint, hosts without ResizeObserver) keeps the current tier.
|
||||
return tier;
|
||||
}
|
||||
if (contentWidth > availableWidth && tier < EDITOR_TOOLBAR_MAX_TIER) {
|
||||
return (tier + 1) as EditorToolbarTier;
|
||||
}
|
||||
if (tier > 0 && availableWidth - contentWidth >= EDITOR_TOOLBAR_STEP_DOWN_SLACK_PX && availableWidth - condensedAtWidth >= EDITOR_TOOLBAR_STEP_DOWN_MIN_GROWTH_PX) {
|
||||
return (tier - 1) as EditorToolbarTier;
|
||||
}
|
||||
return tier;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
export const TAB_DRAG_MIME = "application/x-dbx-tab";
|
||||
|
||||
export interface TabDragPayload {
|
||||
mime: typeof TAB_DRAG_MIME;
|
||||
tabId: string;
|
||||
sourceGroupId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the drag contract under the project's custom MIME type. The MIME
|
||||
* value travels inside the payload as a discriminator, so a drop handler can
|
||||
* reject foreign or stale payloads before touching store state.
|
||||
*/
|
||||
export function serializeTabDragPayload(payload: { tabId: string; sourceGroupId: string }): string {
|
||||
return JSON.stringify({ mime: TAB_DRAG_MIME, tabId: payload.tabId, sourceGroupId: payload.sourceGroupId });
|
||||
}
|
||||
|
||||
export function parseTabDragPayload(raw: string): TabDragPayload | null {
|
||||
try {
|
||||
const value = JSON.parse(raw) as Partial<TabDragPayload>;
|
||||
if (value.mime === TAB_DRAG_MIME && typeof value.tabId === "string" && typeof value.sourceGroupId === "string") {
|
||||
return { mime: TAB_DRAG_MIME, tabId: value.tabId, sourceGroupId: value.sourceGroupId };
|
||||
}
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { Copy, Crosshair, Pencil, Pin, X } from "@lucide/vue";
|
||||
import type { ContextMenuItem } from "@/components/ui/customContextMenuRegistry";
|
||||
import type { QueryTab } from "@/types/database";
|
||||
|
||||
export function createRenameDuplicateTabItems(options: { tab: QueryTab; t: (key: string) => string; canRename: boolean; onRename: () => void; onDuplicate: () => void }): ContextMenuItem[] {
|
||||
return [
|
||||
...(options.canRename
|
||||
? [
|
||||
{
|
||||
label: options.t("contextMenu.renameTab"),
|
||||
action: options.onRename,
|
||||
icon: Pencil,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: options.t("contextMenu.duplicateTab"),
|
||||
action: options.onDuplicate,
|
||||
icon: Copy,
|
||||
visible: options.canRename,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export function createLocateTabMenuItem(options: { t: (key: string) => string; visible: boolean; onLocate: () => void }): ContextMenuItem {
|
||||
return {
|
||||
label: options.t("sidebar.locateActiveTab"),
|
||||
action: options.onLocate,
|
||||
icon: Crosshair,
|
||||
visible: options.visible,
|
||||
};
|
||||
}
|
||||
|
||||
export function createPinTabMenuItem(options: { label: string; iconClass?: string; onToggle: () => void }): ContextMenuItem {
|
||||
return {
|
||||
label: options.label,
|
||||
action: options.onToggle,
|
||||
icon: Pin,
|
||||
...(options.iconClass ? { iconClass: options.iconClass } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function createCloseTabMenuItem(options: { label: string; onClose: () => void }): ContextMenuItem {
|
||||
return { label: options.label, action: options.onClose, icon: X };
|
||||
}
|
||||
|
||||
export function createCloseOtherTabMenuItem(options: { label: string; disabled?: boolean; shortcut?: string; onClose: () => void }): ContextMenuItem {
|
||||
return {
|
||||
label: options.label,
|
||||
action: options.onClose,
|
||||
...(options.disabled !== undefined ? { disabled: options.disabled } : {}),
|
||||
...(options.shortcut ? { shortcut: options.shortcut } : {}),
|
||||
icon: X,
|
||||
};
|
||||
}
|
||||
|
||||
export function createCloseRightTabMenuItem(options: { label: string; disabled?: boolean; onClose: () => void }): ContextMenuItem {
|
||||
return {
|
||||
label: options.label,
|
||||
action: options.onClose,
|
||||
...(options.disabled !== undefined ? { disabled: options.disabled } : {}),
|
||||
icon: X,
|
||||
};
|
||||
}
|
||||
|
||||
export function createCloseLeftTabMenuItem(options: { label: string; disabled?: boolean; onClose: () => void }): ContextMenuItem {
|
||||
return {
|
||||
label: options.label,
|
||||
action: options.onClose,
|
||||
...(options.disabled !== undefined ? { disabled: options.disabled } : {}),
|
||||
icon: X,
|
||||
};
|
||||
}
|
||||
|
||||
export function createCloseAllTabMenuItem(options: { label: string; variant?: "destructive"; onClose: () => void }): ContextMenuItem {
|
||||
return {
|
||||
label: options.label,
|
||||
action: options.onClose,
|
||||
...(options.variant ? { variant: options.variant } : {}),
|
||||
icon: X,
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { hexToRgba } from "@/lib/common/color";
|
||||
import type { CSSProperties } from "vue";
|
||||
import { findConnectionGroupPath } from "@/lib/sidebar/sidebarLayout";
|
||||
import { splitMongoCommandRanges } from "@/lib/mongo/mongoShellCommand";
|
||||
import { executableStatementRanges, splitSqlStatementRanges, type SqlTextRange } from "@/lib/sql/sqlStatementRanges";
|
||||
@@ -464,3 +466,60 @@ export function tabModeLabel(tab: QueryTab, t: Translate): string {
|
||||
if (tab.mode === "dolt-version-control") return t("doltVersionControl.title");
|
||||
return tab.mode;
|
||||
}
|
||||
|
||||
export function tabDatabaseIconType(tab: QueryTab): string {
|
||||
const connectionStore = useConnectionStore();
|
||||
const connection = connectionStore.getConfig(tab.connectionId);
|
||||
if (!connection) return "mq";
|
||||
if (connection.db_type === "mq") {
|
||||
const externalConfig = connection.external_config as { systemKind?: unknown } | undefined;
|
||||
const systemKind = typeof externalConfig?.systemKind === "string" ? externalConfig.systemKind : "";
|
||||
if (connection.driver_profile === "kafka" || systemKind === "kafka") return "kafka";
|
||||
if (connection.driver_profile === "rocketmq" || systemKind === "rocketmq") return "rocketmq";
|
||||
if (connection.driver_profile === "rabbitmq" || systemKind === "rabbitmq") return "rabbitmq";
|
||||
if (connection.driver_profile === "pulsar" || systemKind === "pulsar") return "pulsar";
|
||||
}
|
||||
return connection.driver_profile || connection.db_type;
|
||||
}
|
||||
|
||||
export function tabIconClass(tab: QueryTab): string {
|
||||
if (tab.externalSqlFileMissing) return "text-amber-600 dark:text-amber-400";
|
||||
if (tab.mode === "mq") return "";
|
||||
if (tab.mode === "databases" || tab.mode === "objects") return "text-amber-500 dark:text-amber-400";
|
||||
if (tab.mode === "data" || tab.mode === "mongo" || tab.mode === "vector" || tab.mode === "redis" || tab.mode === "hbase" || tab.mode === "structure") return "text-emerald-600 dark:text-emerald-400";
|
||||
return "text-blue-600 dark:text-blue-400";
|
||||
}
|
||||
|
||||
export function tabColorStyle(tab: QueryTab, active: boolean, isClassic: boolean): CSSProperties | undefined {
|
||||
const color = connectionColor(tab.connectionId);
|
||||
if (!color) {
|
||||
if (isClassic) {
|
||||
return active ? { boxShadow: "inset 0 -2px 0 var(--ring)" } : undefined;
|
||||
}
|
||||
return active ? { borderColor: "var(--ring)" } : undefined;
|
||||
}
|
||||
if (isClassic) {
|
||||
return {
|
||||
"--app-tab-background": hexToRgba(color, active ? 0.16 : 0.07),
|
||||
"--app-tab-hover-background": hexToRgba(color, 0.14),
|
||||
boxShadow: active ? `inset 0 -2px 0 ${color}` : undefined,
|
||||
};
|
||||
}
|
||||
return {
|
||||
"--app-tab-background": hexToRgba(color, active ? 0.16 : 0.09),
|
||||
"--app-tab-hover-background": hexToRgba(color, 0.16),
|
||||
borderColor: active ? hexToRgba(color, 0.72) : hexToRgba(color, 0.18),
|
||||
};
|
||||
}
|
||||
|
||||
export function dirtyTabTitleStyle(isDirty: boolean): CSSProperties | undefined {
|
||||
if (!isDirty) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
fontStyle: "italic",
|
||||
fontWeight: 700,
|
||||
transform: "skewX(-8deg)",
|
||||
transformOrigin: "left center",
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user