Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/tauri/src/theme/queryaTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const STORAGE_KEY = "querya.theme";
export function readStoredTheme(): QueryaThemeMode {
const raw = localStorage.getItem(STORAGE_KEY);
if (raw === "light" || raw === "dark" || raw === "system") return raw;
return "system";
// Flutter QueryaTheme.darkDefault — first launch is dark, not OS light.
return "dark";
}

export function applyTheme(mode: QueryaThemeMode): void {
Expand Down
21 changes: 19 additions & 2 deletions apps/tauri/src/ui/ResultGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { onBeforeUnmount, onMounted, ref, watch } from "vue";
import { createElement } from "react";
import { createRoot, type Root } from "react-dom/client";
import { storeToRefs } from "pinia";
import type { Theme } from "@glideapps/glide-data-grid";
import { useQueryResultStore } from "../stores/queryResult";
import { ResultDataEditor } from "./glide/ResultDataEditor";
import {
buildQueryaGlideTheme,
subscribeThemeChanges,
} from "./glide/queryaGlideTheme";
import "@glideapps/glide-data-grid/dist/index.css";

const query = useQueryResultStore();
Expand All @@ -14,6 +19,8 @@ const host = ref<HTMLDivElement | null>(null);
const size = ref({ width: 640, height: 320 });
let root: Root | null = null;
let ro: ResizeObserver | null = null;
let unsubTheme: (() => void) | null = null;
let glideTheme: Partial<Theme> = buildQueryaGlideTheme();

function render() {
if (!root || !host.value) return;
Expand All @@ -23,10 +30,16 @@ function render() {
rows: rows.value,
width: Math.max(100, size.value.width),
height: Math.max(100, size.value.height),
theme: glideTheme,
}),
);
}

function refreshTheme() {
glideTheme = buildQueryaGlideTheme();
render();
}

onMounted(() => {
if (!host.value) return;
root = createRoot(host.value);
Expand All @@ -40,12 +53,15 @@ onMounted(() => {
render();
});
ro.observe(host.value);
render();
unsubTheme = subscribeThemeChanges(refreshTheme);
refreshTheme();
});

watch([columns, rows], () => render(), { deep: true });

onBeforeUnmount(() => {
unsubTheme?.();
unsubTheme = null;
ro?.disconnect();
ro = null;
root?.unmount();
Expand All @@ -68,6 +84,7 @@ onBeforeUnmount(() => {
height: 100%;
min-height: 120px;
overflow: hidden;
background: var(--q-surface);
background: var(--q-editor-bg);
color: var(--q-foreground);
}
</style>
14 changes: 9 additions & 5 deletions apps/tauri/src/ui/glide/ResultDataEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import {
type GridCell,
type GridColumn,
type Item,
type Theme,
} from "@glideapps/glide-data-grid";

export type ResultDataEditorProps = {
columns: string[];
rows: unknown[][];
width: number;
height: number;
/** Querya workbench → Glide theme (dark/light). */
theme: Partial<Theme>;
};

function cellText(value: unknown): string {
Expand All @@ -27,7 +30,7 @@ function cellText(value: unknown): string {
}

export function ResultDataEditor(props: ResultDataEditorProps): ReactElement {
const { columns, rows, width, height } = props;
const { columns, rows, width, height, theme } = props;

const gridColumns: GridColumn[] = useMemo(
() =>
Expand All @@ -39,6 +42,8 @@ export function ResultDataEditor(props: ResultDataEditorProps): ReactElement {
[columns],
);

const muted = theme.textMedium ?? theme.textLight ?? "#94a3b8";

const getCellContent = useCallback(
([col, row]: Item): GridCell => {
const raw = rows[row]?.[col];
Expand All @@ -49,12 +54,10 @@ export function ResultDataEditor(props: ResultDataEditorProps): ReactElement {
displayData: isNull ? "NULL" : cellText(raw),
allowOverlay: true,
readonly: true,
themeOverride: isNull
? { textDark: "var(--q-muted-foreground)" }
: undefined,
themeOverride: isNull ? { textDark: muted } : undefined,
};
},
[rows],
[rows, muted],
);

return createElement(DataEditor, {
Expand All @@ -63,6 +66,7 @@ export function ResultDataEditor(props: ResultDataEditorProps): ReactElement {
getCellContent,
width,
height,
theme,
rowMarkers: "number",
smoothScrollX: true,
smoothScrollY: true,
Expand Down
95 changes: 95 additions & 0 deletions apps/tauri/src/ui/glide/queryaGlideTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { Theme } from "@glideapps/glide-data-grid";

/** Read a Querya CSS token as a concrete color (Glide paints on canvas). */
function cssVar(name: string, fallback: string): string {
if (typeof document === "undefined") return fallback;
const v = getComputedStyle(document.documentElement)
.getPropertyValue(name)
.trim();
return v || fallback;
}

function withAlpha(hexOrCss: string, alpha: number): string {
const m = /^#([0-9a-f]{6})$/i.exec(hexOrCss.trim());
if (!m) return hexOrCss;
const n = parseInt(m[1]!, 16);
const r = (n >> 16) & 255;
const g = (n >> 8) & 255;
const b = n & 255;
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}

/**
* Glide theme from Querya workbench tokens — Flutter darkDefault parity
* (near-black canvas, cyan accent) and lightDefault when `data-theme=light`.
*/
export function buildQueryaGlideTheme(): Partial<Theme> {
const fg = cssVar("--q-foreground", "#f8fafc");
const muted = cssVar("--q-muted-foreground", "#94a3b8");
const surface = cssVar("--q-editor-bg", cssVar("--q-surface", "#0c0c0c"));
const canvas = cssVar("--q-canvas", "#000000");
const border = cssVar("--q-border", "#27272a");
const primary = cssVar("--q-primary", "#22d3ee");
const primaryFg = cssVar("--q-primary-foreground", "#0a0a0a");
const accent = cssVar("--q-accent", "#27272a");
const mono = cssVar(
"--q-font-mono",
'"JetBrains Mono", "SF Mono", ui-monospace, monospace',
);
const sans = cssVar(
"--q-font-sans",
'"Segoe UI", "SF Pro Text", system-ui, sans-serif',
);

return {
accentColor: primary,
accentFg: primaryFg,
accentLight: withAlpha(primary, 0.16),
textDark: fg,
textMedium: muted,
textLight: muted,
textBubble: fg,
bgIconHeader: muted,
fgIconHeader: fg,
textHeader: muted,
textGroupHeader: muted,
textHeaderSelected: primaryFg,
bgCell: surface,
bgCellMedium: canvas,
bgHeader: canvas,
bgHeaderHasFocus: accent,
bgHeaderHovered: accent,
bgBubble: accent,
bgBubbleSelected: surface,
bgSearchResult: withAlpha(primary, 0.18),
borderColor: withAlpha(border, 0.55),
horizontalBorderColor: withAlpha(border, 0.35),
headerBottomBorderColor: withAlpha(border, 0.55),
drilldownBorder: "transparent",
linkColor: primary,
fontFamily: `${sans}, ${mono}`,
headerFontStyle: "600 12px",
baseFontStyle: "12px",
markerFontStyle: "10px",
editorFontSize: "12px",
cellHorizontalPadding: 8,
cellVerticalPadding: 4,
lineHeight: 1.35,
};
}

/** Fire when `data-theme` or OS color-scheme changes (token values update). */
export function subscribeThemeChanges(onChange: () => void): () => void {
const root = document.documentElement;
const mo = new MutationObserver((mutations) => {
if (mutations.some((m) => m.attributeName === "data-theme")) onChange();
});
mo.observe(root, { attributes: true, attributeFilter: ["data-theme"] });
const mq = window.matchMedia("(prefers-color-scheme: dark)");
const onMq = () => onChange();
mq.addEventListener("change", onMq);
return () => {
mo.disconnect();
mq.removeEventListener("change", onMq);
};
}
Loading