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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(grid): add binary data hex viewer
Scarse679113231e8
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex 2b7f808432..9813f65c33 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -105,7 +105,8 @@ import { matchesRowStatusFilter, type RowStatus, type RowStatusFilter } from "@/import { displayCellValue, type CellValue } from "@/lib/cellValue";import { getApplicablePreviewActions } from "@/lib/resultPreviewRegistry";import "@/lib/previewHandlers/geometryMapPreview";-import { BINARY_CELL_DOWNLOAD_MODES, binaryCellDisplayText, binaryCellDownloadFileName, binaryCellDownloadPayload, canDownloadBinaryCellValue, downloadBinaryCellPayload, type BinaryCellDownloadMode } from "@/lib/binaryCellDownload";+import { BINARY_CELL_DOWNLOAD_MODES, binaryCellDisplayText, binaryCellDownloadFileName, binaryCellDownloadPayload, canDownloadBinaryCellValue, downloadBinaryCellPayload, isBinaryCellColumnType, parseBinaryCellBytes, type BinaryCellDownloadMode } from "@/lib/binaryCellDownload";+import { buildBinaryHexViewRows } from "@/lib/binaryHexViewer";import { canFormatCellDetailJson, cellDetailEditorText, defaultCellDetailTab, formatJsonText, isGeometryColumnType, linkedCellDetailTarget, valueEditorActions, visibleCellDetailTabs, type CellDetailTab } from "@/lib/cellDetailPresentation";import { renderWktOnCanvas, isHexGeometry } from "@/lib/geometryPreview";import { buildDataGridCellDetail, buildDataGridColumnDetail, buildDataGridRowDetail, dataGridColumnDetailJson, dataGridColumnDetailTsv, dataGridRowDetailJson, dataGridRowDetailTsv, filterDataGridDetailFields, type DataGridCellDetail } from "@/lib/dataGridDetail";@@ -3134,7 +3135,26 @@ watch(dialogGeometryPreviewOpen, async (open) => {const activeCellDetailTabs = computed(() => {const detail = activeCellDetail.value;- return visibleCellDetailTabs({ isEditable: !!detail?.isEditable });+ return visibleCellDetailTabs({+ isEditable: !!detail?.isEditable,+ hasBinaryHexViewer: isBinaryCellColumnType(detail?.type),+ });+});++const activeBinaryHexBytes = computed(() => {+ if (activeCellDetailTab.value !== "hexViewer") return null;+ const detail = activeCellDetail.value;+ return detail ? parseBinaryCellBytes(detail.value, detail.type) : null;+});++const activeBinaryHexRows = computed(() => (activeBinaryHexBytes.value ? buildBinaryHexViewRows(activeBinaryHexBytes.value) : []));+const activeBinaryHexByteCount = computed(() => activeBinaryHexBytes.value?.length ?? 0);++const activeCellDetailTabsGridClass = computed(() => {+ const count = activeCellDetailTabs.value.length;+ if (count >= 3) return "grid-cols-3";+ if (count === 2) return "grid-cols-2";+ return "grid-cols-1";});watch(activeCellDetailTabs, (tabs) => {@@ -7466,8 +7486,11 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {<Tabs v-model="activeCellDetailTab" class="flex-1 min-h-0 gap-0"><div class="shrink-0 border-b px-3 py-2">- <TabsList class="grid h-7 w-full p-0.5" :class="activeCellDetailTabs.length > 1 ? 'grid-cols-2' : 'grid-cols-1'">+ <TabsList class="grid h-7 w-full p-0.5" :class="activeCellDetailTabsGridClass"><TabsTrigger value="details" class="h-6 text-xs">{{ t("grid.cellDetails") }}</TabsTrigger>+ <TabsTrigger v-if="activeCellDetailTabs.includes('hexViewer')" value="hexViewer" class="h-6 text-xs">+ {{ t("grid.hexViewer") }}+ </TabsTrigger><TabsTrigger v-if="activeCellDetailTabs.includes('valueEditor')" value="valueEditor" class="h-6 text-xs">{{ t("grid.valueEditor") }}</TabsTrigger>@@ -7617,6 +7640,28 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {</div></TabsContent>+ <TabsContent v-if="activeCellDetailTabs.includes('hexViewer')" value="hexViewer" class="m-0 min-h-0 flex-1 flex flex-col p-3 text-xs">+ <div class="mb-2 min-w-0 shrink-0">+ <div class="font-medium">{{ t("grid.hexViewer") }}</div>+ <div class="text-[11px] text-muted-foreground">{{ t("grid.hexViewerByteCount", { count: activeBinaryHexByteCount }) }}</div>+ </div>+ <div class="min-h-0 flex-1 overflow-auto rounded border bg-muted/20 font-mono text-[11px]">+ <div class="sticky top-0 grid grid-cols-[5.5rem_minmax(24rem,1fr)_8rem] gap-3 border-b bg-muted px-2 py-1 font-semibold text-muted-foreground">+ <div>{{ t("grid.hexViewerOffset") }}</div>+ <div>{{ t("grid.hexViewerHex") }}</div>+ <div>{{ t("grid.hexViewerAscii") }}</div>+ </div>+ <div v-for="row in activeBinaryHexRows" :key="row.offset" class="grid grid-cols-[5.5rem_minmax(24rem,1fr)_8rem] gap-3 border-b border-border/50 px-2 py-1 last:border-b-0">+ <div class="select-all text-muted-foreground">{{ row.offset }}</div>+ <div class="select-all whitespace-pre">{{ row.hex }}</div>+ <div class="select-all whitespace-pre">{{ row.ascii }}</div>+ </div>+ <div v-if="activeBinaryHexRows.length === 0" class="px-2 py-6 text-center font-sans text-muted-foreground">+ {{ t("grid.hexViewerEmpty") }}+ </div>+ </div>+ </TabsContent>+<TabsContent v-if="activeCellDetailTabs.includes('valueEditor')" value="valueEditor" class="m-0 min-h-0 flex-1 flex flex-col p-3 text-xs"><div class="flex min-h-0 flex-1 flex-col"><TemporalCellEditor v-if="detailTemporalEditorKind" v-model="detailEditValue" :kind="detailTemporalEditorKind" variant="inline" :commit-on-close="false" @cancel="cancelValueEditorEdit" @commit="commitValueEditorEdit" />diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex db523dab6c..c634480cd7 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -687,6 +687,12 @@ export default {fieldIndex: "No.",cellValue: "Value",valueEditor: "Value Editor",+ hexViewer: "Hex Viewer",+ hexViewerByteCount: "{count} bytes",+ hexViewerOffset: "Offset",+ hexViewerHex: "Hex",+ hexViewerAscii: "ASCII",+ hexViewerEmpty: "No binary bytes to display.",imagePreview: "Image Preview",imageLoadFailed: "Image failed to load",geometryPreview: "Geometry Preview",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex de1bb18b27..56059a3c03 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -602,6 +602,12 @@ export default {fieldIndex: "N.º",cellValue: "Valor",valueEditor: "Editor de valor",+ hexViewer: "Visor hexadecimal",+ hexViewerByteCount: "{count} bytes",+ hexViewerOffset: "Desplazamiento",+ hexViewerHex: "Hex",+ hexViewerAscii: "ASCII",+ hexViewerEmpty: "No hay bytes binarios para mostrar.",imagePreview: "Vista previa de imagen",imageLoadFailed: "No se pudo cargar la imagen",geometryPreview: "Vista previa de geometría",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex 8a089a02c4..69f0718f9c 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -633,6 +633,12 @@ export default {fieldIndex: "N.",cellValue: "Valore",valueEditor: "Editor dei Valori",+ hexViewer: "Visualizzatore Hex",+ hexViewerByteCount: "{count} byte",+ hexViewerOffset: "Offset",+ hexViewerHex: "Hex",+ hexViewerAscii: "ASCII",+ hexViewerEmpty: "Nessun byte binario da visualizzare.",imagePreview: "Anteprima Immagine",imageLoadFailed: "Caricamento immagine non riuscito",geometryPreview: "Anteprima Geometria",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex 2eeda678a0..3a5931b596 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -683,6 +683,12 @@ export default {fieldIndex: "No.",cellValue: "値",valueEditor: "値エディタ",+ hexViewer: "Hex ビューア",+ hexViewerByteCount: "{count} バイト",+ hexViewerOffset: "オフセット",+ hexViewerHex: "Hex",+ hexViewerAscii: "ASCII",+ hexViewerEmpty: "表示できるバイナリバイトがありません。",imagePreview: "画像プレビュー",imageLoadFailed: "画像の読み込みに失敗しました",geometryPreview: "ジオメトリプレビュー",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex 4421a64ec5..3ad1c9327a 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -633,6 +633,12 @@ export default {fieldIndex: "Nº",cellValue: "Valor",valueEditor: "Editor de Valor",+ hexViewer: "Visualizador Hex",+ hexViewerByteCount: "{count} bytes",+ hexViewerOffset: "Offset",+ hexViewerHex: "Hex",+ hexViewerAscii: "ASCII",+ hexViewerEmpty: "Nenhum byte binário para exibir.",imagePreview: "Visualização de Imagem",imageLoadFailed: "Falha ao carregar a imagem",geometryPreview: "Visualização de Geometria",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex 6ad3e66ea6..677d3519b7 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -688,6 +688,12 @@ export default {fieldIndex: "序号",cellValue: "值",valueEditor: "值编辑器",+ hexViewer: "Hex 查看器",+ hexViewerByteCount: "{count} 字节",+ hexViewerOffset: "偏移",+ hexViewerHex: "Hex",+ hexViewerAscii: "ASCII",+ hexViewerEmpty: "没有可显示的二进制字节。",imagePreview: "图片预览",imageLoadFailed: "图片加载失败",geometryPreview: "图形预览",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex e465c0e30e..2ba30d731b 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -634,6 +634,12 @@ export default {fieldIndex: "序號",cellValue: "值",valueEditor: "儲存格編輯器",+ hexViewer: "Hex 檢視器",+ hexViewerByteCount: "{count} 位元組",+ hexViewerOffset: "偏移",+ hexViewerHex: "Hex",+ hexViewerAscii: "ASCII",+ hexViewerEmpty: "沒有可顯示的二進位位元組。",imagePreview: "圖片預覽",imageLoadFailed: "圖片載入失敗",geometryPreview: "圖形預覽",diff --git a/apps/desktop/src/lib/binaryHexViewer.ts b/apps/desktop/src/lib/binaryHexViewer.tsnew file mode 100644index 0000000000..8081f4db95--- /dev/null+++ b/apps/desktop/src/lib/binaryHexViewer.ts@@ -0,0 +1,28 @@+export interface BinaryHexViewRow {+ offset: string;+ hex: string;+ ascii: string;+}++const BYTES_PER_ROW = 16;++function formatHexByte(value: number): string {+ return value.toString(16).toUpperCase().padStart(2, "0");+}++function formatAsciiByte(value: number): string {+ return value >= 0x20 && value <= 0x7e ? String.fromCharCode(value) : ".";+}++export function buildBinaryHexViewRows(bytes: Uint8Array): BinaryHexViewRow[] {+ const rows: BinaryHexViewRow[] = [];+ for (let offset = 0; offset < bytes.length; offset += BYTES_PER_ROW) {+ const slice = bytes.slice(offset, offset + BYTES_PER_ROW);+ rows.push({+ offset: offset.toString(16).toUpperCase().padStart(8, "0"),+ hex: Array.from(slice, formatHexByte).join(" "),+ ascii: Array.from(slice, formatAsciiByte).join(""),+ });+ }+ return rows;+}diff --git a/apps/desktop/src/lib/cellDetailPresentation.ts b/apps/desktop/src/lib/cellDetailPresentation.tsindex 90817872d3..e90e39edca 100644--- a/apps/desktop/src/lib/cellDetailPresentation.ts+++ b/apps/desktop/src/lib/cellDetailPresentation.ts@@ -1,10 +1,11 @@-export type CellDetailTab = "details" | "valueEditor";+export type CellDetailTab = "details" | "hexViewer" | "valueEditor";export type ValueEditorAction = "formatJson" | "setNull" | "restoreOriginal";export const CELL_DETAIL_JSON_FORMAT_MAX_LENGTH = 50_000;export interface CellDetailPresentationOptions {isEditable: boolean;+ hasBinaryHexViewer?: boolean;}export interface LinkedCellDetailOptions {@@ -25,6 +26,9 @@ export function defaultCellDetailTab(): CellDetailTab {export function visibleCellDetailTabs(options: CellDetailPresentationOptions): CellDetailTab[] {const tabs: CellDetailTab[] = ["details"];+ if (options.hasBinaryHexViewer) {+ tabs.push("hexViewer");+ }if (options.isEditable) {tabs.push("valueEditor");}diff --git a/packages/app-tests/binaryHexViewer.test.ts b/packages/app-tests/binaryHexViewer.test.tsnew file mode 100644index 0000000000..d3c7a3f26a--- /dev/null+++ b/packages/app-tests/binaryHexViewer.test.ts@@ -0,0 +1,24 @@+import assert from "node:assert/strict";+import { test } from "vitest";+import { buildBinaryHexViewRows } from "../../apps/desktop/src/lib/binaryHexViewer.ts";++test("buildBinaryHexViewRows formats offsets, hex bytes, and ascii preview", () => {+ const bytes = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x20, 0x41, 0x7e, 0x7f, 0x00, 0x01, 0x02, 0xff, 0x48]);++ assert.deepEqual(buildBinaryHexViewRows(bytes), [+ {+ offset: "00000000",+ hex: "89 50 4E 47 0D 0A 1A 0A 20 41 7E 7F 00 01 02 FF",+ ascii: ".PNG.... A~.....",+ },+ {+ offset: "00000010",+ hex: "48",+ ascii: "H",+ },+ ]);+});++test("buildBinaryHexViewRows handles empty binary values", () => {+ assert.deepEqual(buildBinaryHexViewRows(new Uint8Array()), []);+});diff --git a/packages/app-tests/cellDetailPresentation.test.ts b/packages/app-tests/cellDetailPresentation.test.tsnew file mode 100644index 0000000000..7859e0c9c0--- /dev/null+++ b/packages/app-tests/cellDetailPresentation.test.ts@@ -0,0 +1,12 @@+import assert from "node:assert/strict";+import { test } from "vitest";+import { visibleCellDetailTabs } from "../../apps/desktop/src/lib/cellDetailPresentation.ts";++test("visibleCellDetailTabs exposes hex viewer only for binary details", () => {+ assert.deepEqual(visibleCellDetailTabs({ isEditable: false }), ["details"]);+ assert.deepEqual(visibleCellDetailTabs({ isEditable: false, hasBinaryHexViewer: true }), ["details", "hexViewer"]);+});++test("visibleCellDetailTabs preserves value editor ordering", () => {+ assert.deepEqual(visibleCellDetailTabs({ isEditable: true, hasBinaryHexViewer: true }), ["details", "hexViewer", "valueEditor"]);+});