diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index 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(() => {
- + {{ t("grid.cellDetails") }} + + {{ t("grid.hexViewer") }} + {{ t("grid.valueEditor") }} @@ -7617,6 +7640,28 @@ const gridContextMenuItems = computed(() => {
+ +
+
{{ t("grid.hexViewer") }}
+
{{ t("grid.hexViewerByteCount", { count: activeBinaryHexByteCount }) }}
+
+
+
+
{{ t("grid.hexViewerOffset") }}
+
{{ t("grid.hexViewerHex") }}
+
{{ t("grid.hexViewerAscii") }}
+
+
+
{{ row.offset }}
+
{{ row.hex }}
+
{{ row.ascii }}
+
+
+ {{ t("grid.hexViewerEmpty") }} +
+
+
+
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts index 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.ts index 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.ts index 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.ts index 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.ts index 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.ts index 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.ts index 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.ts new file mode 100644 index 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.ts index 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.ts new file mode 100644 index 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.ts new file mode 100644 index 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"]); +});