From a6df5c1f35056012d4ddfc6af888ba9336d453fa Mon Sep 17 00:00:00 2001 From: zipg Date: Thu, 2 Jul 2026 14:32:23 +0800 Subject: [PATCH] feat(grid): compact JSON action in cell detail editor Co-authored-by: staff --- apps/desktop/src/components/grid/DataGrid.vue | 32 +++++++++++++++---- apps/desktop/src/i18n/locales/en.ts | 1 + apps/desktop/src/i18n/locales/zh-CN.ts | 1 + .../desktop/src/lib/cellDetailPresentation.ts | 15 +++++++-- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index 549b4d097..d70c8e6b6 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -113,7 +113,7 @@ import { getApplicablePreviewActions } from "@/lib/resultPreviewRegistry"; import "@/lib/previewHandlers/geometryMapPreview"; 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 { canFormatCellDetailJson, cellDetailEditorText, compactJsonText, defaultCellDetailTab, formatJsonText, isGeometryColumnType, linkedCellDetailTarget, looksLikeJsonContainerText, 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"; import { applyColumnFormatter, buildColumnFormatterKey, normalizeColumnFormatter, resolveColumnFormatter, type ColumnFormatterConfig, type DateTimeFormatterUnit, DateTimePatterns } from "@/lib/columnFormatter"; @@ -4587,6 +4587,15 @@ const sideJsonPreviewText = computed(() => { if (!detail?.formattedJson) return ""; return sideDetailJsonView.value ? detail.formattedJson : detail.rawValuePreview; }); +const canCompactDetailJson = computed(() => { + const detail = activeCellDetail.value; + return !!detail && isEditingDetail.value && canFormatCellDetailJson(detailEditValue.value, detail.type); +}); +const showCompactDetailJson = computed(() => { + const detail = activeCellDetail.value; + if (!detail || !isEditingDetail.value) return false; + return !!detail.formattedJson || looksLikeJsonContainerText(detailEditValue.value); +}); // CodeMirror-based cell detail editors const detailsEditorContainer = ref(); @@ -4821,6 +4830,13 @@ function formatValueEditorJson() { warnFormattedJsonEditIfNeeded(detail, true); } +function compactDetailJson() { + const detail = activeCellDetail.value; + if (!detail || !canFormatCellDetailJson(detailEditValue.value, detail.type)) return; + detailEditValue.value = compactJsonText(detailEditValue.value) ?? detailEditValue.value; + syncEditorFromDetailEdit(); +} + function setDetailNull() { const detail = activeCellDetail.value; if (!detail || !detail.isEditable) return; @@ -9737,18 +9753,22 @@ const gridContextMenuItems = computed(() => {
{{ t("grid.cellValue") }}
-
- + - - - +