From 1edbb7b9350694db557393bee8a2bf026c5a9715 Mon Sep 17 00:00:00 2001 From: lxk955 <164191365+lxk955@users.noreply.github.com> Date: Sun, 4 Oct 2026 02:09:13 +0800 Subject: [PATCH] feat(grid): allow disabling striped row background --- .../editor/EditorSettingsDialog.vue | 17 ++++++++++ apps/desktop/src/components/grid/DataGrid.vue | 11 +++++-- apps/desktop/src/i18n/locales/az.ts | 2 ++ apps/desktop/src/i18n/locales/en.ts | 2 ++ apps/desktop/src/i18n/locales/es.ts | 2 ++ apps/desktop/src/i18n/locales/id.ts | 2 ++ apps/desktop/src/i18n/locales/it.ts | 2 ++ apps/desktop/src/i18n/locales/ja.ts | 2 ++ apps/desktop/src/i18n/locales/ko.ts | 2 ++ apps/desktop/src/i18n/locales/pt-BR.ts | 2 ++ apps/desktop/src/i18n/locales/ru.ts | 2 ++ apps/desktop/src/i18n/locales/tr.ts | 2 ++ apps/desktop/src/i18n/locales/zh-CN.ts | 2 ++ apps/desktop/src/i18n/locales/zh-TW.ts | 2 ++ .../lib/dataGrid/canvasDataGridRenderer.ts | 16 +++++++++- .../__tests__/gridSnapshot.spec.ts | 12 +++++++ .../src/lib/gridSnapshot/gridSnapshot.ts | 3 +- .../src/lib/settings/editorSettingsDraft.ts | 1 + .../src/lib/settings/settingsSearch.ts | 1 + .../src/lib/settings/settingsTransfer.ts | 1 + .../stores/__tests__/settingsStore.spec.ts | 32 +++++++++++++++++++ apps/desktop/src/stores/settingsStore.ts | 4 +++ .../app-tests/canvasDataGridRenderer.test.ts | 28 +++++++++++++++- 23 files changed, 144 insertions(+), 6 deletions(-) diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vue index 6709c2b9a4..2240e99367 100644 --- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue +++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue @@ -753,6 +753,7 @@ const editMultiStatementDefaultView = ref(settingsSto const editDataGridAutoTransposeSingleRow = ref(settingsStore.editorSettings.dataGridAutoTransposeSingleRow); const editDataGridCellDetailButtonVisible = ref(settingsStore.editorSettings.dataGridCellDetailButtonVisible); const editDataGridCrosshairHighlight = ref(settingsStore.editorSettings.dataGridCrosshairHighlight); +const editDataGridStripedRows = ref(settingsStore.editorSettings.dataGridStripedRows); const editPageSize = ref(settingsStore.editorSettings.pageSize); const editTableOpenPageSize = ref(settingsStore.editorSettings.tableOpenPageSize); const editTableOpenSortMode = ref(settingsStore.editorSettings.tableOpenSortMode); @@ -1108,6 +1109,7 @@ function currentEditorSettingsDraft(): EditorSettingsDraft { dataGridAutoTransposeSingleRow: editDataGridAutoTransposeSingleRow.value, dataGridCellDetailButtonVisible: editDataGridCellDetailButtonVisible.value, dataGridCrosshairHighlight: editDataGridCrosshairHighlight.value, + dataGridStripedRows: editDataGridStripedRows.value, flatteningMultiLineText: editFlatteningMultiLineText.value, dataGridShowWhitespace: editDataGridShowWhitespace.value, pageSize: editPageSize.value, @@ -1778,6 +1780,7 @@ function syncEditorSettingsDraftFromStore() { editDataGridAutoTransposeSingleRow.value = settingsStore.editorSettings.dataGridAutoTransposeSingleRow; editDataGridCellDetailButtonVisible.value = settingsStore.editorSettings.dataGridCellDetailButtonVisible; editDataGridCrosshairHighlight.value = settingsStore.editorSettings.dataGridCrosshairHighlight; + editDataGridStripedRows.value = settingsStore.editorSettings.dataGridStripedRows; editFlatteningMultiLineText.value = settingsStore.editorSettings.flatteningMultiLineText; editDataGridShowWhitespace.value = settingsStore.editorSettings.dataGridShowWhitespace; editPageSize.value = settingsStore.editorSettings.pageSize; @@ -1923,6 +1926,7 @@ const editorSettingsDraftRefs: EditorSettingsDraftRefMap = { dataGridAutoTransposeSingleRow: editDataGridAutoTransposeSingleRow, dataGridCellDetailButtonVisible: editDataGridCellDetailButtonVisible, dataGridCrosshairHighlight: editDataGridCrosshairHighlight, + dataGridStripedRows: editDataGridStripedRows, pageSize: editPageSize, tableOpenPageSize: editTableOpenPageSize, tableOpenSortMode: editTableOpenSortMode, @@ -2503,6 +2507,7 @@ function resetDefaultsForTab(tab: SettingsCategory) { editDataGridAutoTransposeSingleRow.value = DEFAULT_EDITOR_SETTINGS.dataGridAutoTransposeSingleRow; editDataGridCellDetailButtonVisible.value = DEFAULT_EDITOR_SETTINGS.dataGridCellDetailButtonVisible; editDataGridCrosshairHighlight.value = DEFAULT_EDITOR_SETTINGS.dataGridCrosshairHighlight; + editDataGridStripedRows.value = DEFAULT_EDITOR_SETTINGS.dataGridStripedRows; editFlatteningMultiLineText.value = DEFAULT_EDITOR_SETTINGS.flatteningMultiLineText; editDataGridShowWhitespace.value = DEFAULT_EDITOR_SETTINGS.dataGridShowWhitespace; editPageSize.value = DEFAULT_EDITOR_SETTINGS.pageSize; @@ -2616,6 +2621,7 @@ function resetAllDefaults() { editDataGridAutoTransposeSingleRow.value = DEFAULT_EDITOR_SETTINGS.dataGridAutoTransposeSingleRow; editDataGridCellDetailButtonVisible.value = DEFAULT_EDITOR_SETTINGS.dataGridCellDetailButtonVisible; editDataGridCrosshairHighlight.value = DEFAULT_EDITOR_SETTINGS.dataGridCrosshairHighlight; + editDataGridStripedRows.value = DEFAULT_EDITOR_SETTINGS.dataGridStripedRows; editFlatteningMultiLineText.value = DEFAULT_EDITOR_SETTINGS.flatteningMultiLineText; editDataGridShowWhitespace.value = DEFAULT_EDITOR_SETTINGS.dataGridShowWhitespace; editPageSize.value = DEFAULT_EDITOR_SETTINGS.pageSize; @@ -8678,6 +8684,17 @@ onUnmounted(() => { +
+
+ +

+ {{ t("settings.dataGridStripedRowsDescription") }} +

+
+ +
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index 41e230f968..1f9e891993 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -839,6 +839,7 @@ const paginationMaxRows = computed(() => (isResultsContext.value ? queryResultMa const infiniteScrollMaxRows = computed(() => continuousQueryResultMaxRows(settingsStore.editorSettings.queryResultMaxRowsEnabled, settingsStore.editorSettings.queryResultMaxRows)); const showWhitespaceEnabled = computed(() => settingsStore.editorSettings.dataGridShowWhitespace); const flatteningMultiLineEnabled = computed(() => settingsStore.editorSettings.flatteningMultiLineText); +const dataGridStripedRows = computed(() => settingsStore.editorSettings.dataGridStripedRows); const expandedCellEditor = ref<{ rowId: number; col: number } | null>(null); const readonlyTextCell = ref<{ rowId: number; @@ -7025,7 +7026,7 @@ function dataGridRowStyle(item: RowItem): CSSProperties { ? dark ? "rgb(51, 51, 55)" : "rgb(243, 243, 243)" - : item.displayIndex % 2 === 1 + : dataGridStripedRows.value && item.displayIndex % 2 === 1 ? `var(--data-grid-row-muted-bg, ${dark ? DATA_GRID_DARK_STRIPED_ROW_BG : DATA_GRID_LIGHT_STRIPED_ROW_BG})` : "var(--data-grid-background)"; const rowNumberBg = @@ -7102,7 +7103,9 @@ const dataGridTypeColorKey = computed(() => { const colors = resolveActiveDataGridTypeColors(settings.dataGridTypeColorSchemes, settings.activeDataGridTypeColorSchemeId); return colors ? DATA_GRID_TYPE_COLOR_KEYS.map((key) => colors[key]).join(",") : "auto"; }); -const canvasRenderStyleKey = computed(() => `${settingsStore.editorSettings.theme}:${settingsStore.editorSettings.uiScale}:${canvasBackingPixelRatio.value}:${isDark.value}:${themePalette.value}:${tableFontFamily.value}:${tableFontSize.value}:${!!saveError.value}:${dataGridTypeColorKey.value}`); +const canvasRenderStyleKey = computed( + () => `${settingsStore.editorSettings.theme}:${settingsStore.editorSettings.uiScale}:${canvasBackingPixelRatio.value}:${isDark.value}:${themePalette.value}:${tableFontFamily.value}:${tableFontSize.value}:${!!saveError.value}:${dataGridTypeColorKey.value}:${dataGridStripedRows.value}`, +); const CANVAS_MOUSE_WHEEL_SCROLL_MULTIPLIER = 1.5; const CANVAS_TRACKPAD_DELTA_THRESHOLD = 40; let canvasPixelRatioMediaQuery: MediaQueryList | null = null; @@ -7877,6 +7880,7 @@ function drawCanvasGrid() { booleanDisplayMode: booleanDisplayMode.value, flatteningMultiLineEnabled: flatteningMultiLineEnabled.value, showWhitespace: showWhitespaceEnabled.value, + stripedRows: dataGridStripedRows.value, rowNumberMode: dataGridRowNumberMode.value, }); if (!drawn) return; @@ -7906,6 +7910,7 @@ watch(columnAligns, () => scheduleCanvasDraw()); watch(booleanDisplayMode, () => scheduleCanvasDraw()); watch(flatteningMultiLineEnabled, () => scheduleCanvasDraw()); watch(showWhitespaceEnabled, () => scheduleCanvasDraw()); +watch(dataGridStripedRows, () => scheduleCanvasDraw()); watch(colorizeDataGridCellTypes, () => scheduleCanvasDraw()); watch( [ @@ -14064,7 +14069,7 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val 'data-grid-row--deleted opacity-70': item.isDeleted, 'data-grid-row--new': item.isNew && !isRowActive(item.displayIndex), 'data-grid-row--draft': item.isDraft && !isRowActive(item.displayIndex), - 'data-grid-row--striped': !item.isNew && !item.isDraft && !item.isDeleted && !isRowActive(item.displayIndex) && item.displayIndex % 2 === 1, + 'data-grid-row--striped': dataGridStripedRows && !item.isNew && !item.isDraft && !item.isDeleted && !isRowActive(item.displayIndex) && item.displayIndex % 2 === 1, 'active-row': isRowActive(item.displayIndex) && !item.isDeleted, 'crosshair-row': !!crosshairTarget?.rowCrosshair && crosshairTarget.rowIndex === item.displayIndex && !item.isDeleted, 'relative z-20 overflow-visible': editingCell?.rowId === item.id || readonlyTextCell?.rowId === item.id, diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.ts index 7f1ae29576..ef668f37b2 100644 --- a/apps/desktop/src/i18n/locales/az.ts +++ b/apps/desktop/src/i18n/locales/az.ts @@ -7254,6 +7254,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "Aşağıya sürüşdürdükdə növbəti toplunu avtomatik yüklə.", dataGridShowWhitespace: "Boşluq simvollarını göstər", dataGridShowWhitespaceDescription: "Verilənlər xanalarında boşluqları ·, tabulyasiyaları → kimi göstərir. Kopyalanan və redaktə edilən dəyərlər dəyişmir.", + dataGridStripedRows: "Zebra zolaqları", + dataGridStripedRowsDescription: "Aktiv olduqda verilənlər cədvəlində tək və cüt sətirlər fərqli fon rənglərində göstərilir.", flatteningMultiLineText: "Çoxsətirli mətnin bir sətrə birləşdirilməsi", flatteningMultiLineTextDescription: "Çoxsətirli mətn bir sətirdə göstərilir, sətir keçidləri ¶ kimi göstərilir.", regexMaxMatchCount: "Hamısını seçmək üçün maksimum uyğunluq sayı", diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts index 7ddfb1ad0c..fdaf5f0a00 100644 --- a/apps/desktop/src/i18n/locales/en.ts +++ b/apps/desktop/src/i18n/locales/en.ts @@ -8131,6 +8131,8 @@ export default { infiniteScrollDescription: "Automatically load the next batch when scrolling to the bottom.", dataGridShowWhitespace: "Show whitespace", dataGridShowWhitespaceDescription: "Show spaces as · and tabs as → in data cells. Copied and edited values remain unchanged.", + dataGridStripedRows: "Zebra stripes", + dataGridStripedRowsDescription: "When enabled, alternating rows in the data grid display different background colors.", flatteningMultiLineText: "Flattening Multi-line Text", flatteningMultiLineTextDescription: "Multi-line text merged into single line display, with line breaks shown as ¶ .", regexMaxMatchCount: "Maximum select-all matches", diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts index e8a64e2de9..1a6b807df4 100644 --- a/apps/desktop/src/i18n/locales/es.ts +++ b/apps/desktop/src/i18n/locales/es.ts @@ -7465,6 +7465,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "Carga automáticamente el siguiente lote al desplazarse hasta el final.", dataGridShowWhitespace: "Mostrar espacios en blanco", dataGridShowWhitespaceDescription: "Mostrar espacios como · y tabulaciones como → en las celdas. Los valores copiados y editados no cambian.", + dataGridStripedRows: "Filas alternas (cebra)", + dataGridStripedRowsDescription: "Cuando esté activado, las filas pares e impares de la cuadrícula de datos muestran diferentes colores de fondo.", flatteningMultiLineText: "Aplastar texto multilínea", flatteningMultiLineTextDescription: "El texto multilínea se fusiona en una sola línea de visualización, con los saltos de línea mostrados como ¶ .", regexMaxMatchCount: "Máximo de coincidencias al seleccionar todas", diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.ts index 9422d94c11..939ea8b973 100644 --- a/apps/desktop/src/i18n/locales/id.ts +++ b/apps/desktop/src/i18n/locales/id.ts @@ -7924,6 +7924,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "Memuat batch berikutnya secara otomatis saat menggulir ke bawah.", dataGridShowWhitespace: "Tampilkan spasi putih", dataGridShowWhitespaceDescription: "Tampilkan spasi sebagai · dan tab sebagai → pada sel data. Nilai yang disalin dan diedit tetap tidak berubah.", + dataGridStripedRows: "Garis zebra", + dataGridStripedRowsDescription: "Jika diaktifkan, baris ganjil dan genap pada kisi data akan menampilkan warna latar belakang yang berbeda.", flatteningMultiLineText: "Meratakan Teks Multi-baris", flatteningMultiLineTextDescription: "Teks multi-baris digabungkan menjadi tampilan satu baris, dengan pemutus baris ditampilkan sebagai ¶.", regexMaxMatchCount: "Jumlah maksimum hasil cocok pilih-semua", diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts index 5138222558..906580c78d 100644 --- a/apps/desktop/src/i18n/locales/it.ts +++ b/apps/desktop/src/i18n/locales/it.ts @@ -7243,6 +7243,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "Carica automaticamente il blocco successivo quando scorri fino in fondo.", dataGridShowWhitespace: "Mostra spazi bianchi", dataGridShowWhitespaceDescription: "Mostra gli spazi come · e le tabulazioni come → nelle celle. I valori copiati e modificati restano invariati.", + dataGridStripedRows: "Righe alternate (zebra)", + dataGridStripedRowsDescription: "Se attivato, le righe pari e dispari nella griglia dei dati mostrano colori di sfondo diversi.", flatteningMultiLineText: "Pianifica automaticamente i testi multi-riga", flatteningMultiLineTextDescription: "Se attivo, i testi multi-riga nei risultati vengono automaticamente pianificati in una singola colonna.", regexMaxMatchCount: "Numero massimo di corrispondenze per Seleziona tutte", diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts index 47ecfb1564..d2383ce320 100644 --- a/apps/desktop/src/i18n/locales/ja.ts +++ b/apps/desktop/src/i18n/locales/ja.ts @@ -8100,6 +8100,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "末尾までスクロールしたときに、次のデータを自動的に読み込みます。", dataGridShowWhitespace: "空白文字を表示", dataGridShowWhitespaceDescription: "データセルのスペースを ·、タブを → で表示します。コピーや編集する値は変わりません。", + dataGridStripedRows: "ゼブラストライプ", + dataGridStripedRowsDescription: "有効にすると、データグリッドの奇数行と偶数行が異なる背景色で交互に表示されます。", flatteningMultiLineText: "多行テキストを展開", flatteningMultiLineTextDescription: "複数行のテキストを1行に結合して表示し、改行文字は¶として表示する。", regexMaxMatchCount: "すべての一致を選択する最大数", diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts index 9114912a65..f9fec8b9be 100644 --- a/apps/desktop/src/i18n/locales/ko.ts +++ b/apps/desktop/src/i18n/locales/ko.ts @@ -7047,6 +7047,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "목록 하단으로 스크롤할 때 다음 데이터 묶음을 자동으로 불러옵니다.", dataGridShowWhitespace: "공백 문자 표시", dataGridShowWhitespaceDescription: "데이터 셀의 공백을 ·, 탭을 →로 표시합니다. 복사하거나 편집하는 값은 변경되지 않습니다.", + dataGridStripedRows: "줄무늬 행", + dataGridStripedRowsDescription: "활성화하면 데이터 그리드의 홀수 행과 짝수 행에 교차 배경색이 표시됩니다.", flatteningMultiLineText: "멀티라인 텍스트 단순화", flatteningMultiLineTextDescription: "다중 행 텍스트를 단일 행으로 병합하여 표시하고, 개행 문자는 ¶로 표시합니다.", tableColumnTemplateFields: "새 테이블 미리 정의된 필드", diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts index 483aa24f67..5c58fa5d8f 100644 --- a/apps/desktop/src/i18n/locales/pt-BR.ts +++ b/apps/desktop/src/i18n/locales/pt-BR.ts @@ -7245,6 +7245,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "Carregar automaticamente o próximo lote ao rolar até o final.", dataGridShowWhitespace: "Mostrar espaços em branco", dataGridShowWhitespaceDescription: "Mostrar espaços como · e tabulações como → nas células. Os valores copiados e editados permanecem inalterados.", + dataGridStripedRows: "Linhas zebradas", + dataGridStripedRowsDescription: "Quando ativado, as linhas pares e ímpares na grade de dados exibem cores de fundo alternadas.", flatteningMultiLineText: "Achatar texto multilinha", flatteningMultiLineTextDescription: "Exibir texto multilinha em uma única linha.", regexMaxMatchCount: "Máximo de correspondências para selecionar todas", diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.ts index 2aeef78ab6..21fb91b2fa 100644 --- a/apps/desktop/src/i18n/locales/ru.ts +++ b/apps/desktop/src/i18n/locales/ru.ts @@ -8449,6 +8449,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "Автоматически загружать следующую порцию при прокрутке до конца.", dataGridShowWhitespace: "Показывать пробельные символы", dataGridShowWhitespaceDescription: "Показывать пробелы как ·, а табуляции как → в ячейках данных. Копируемые и редактируемые значения не меняются.", + dataGridStripedRows: "Чередование строк (зебра)", + dataGridStripedRowsDescription: "Если включено, четные и нечетные строки в таблице данных отображаются с чередующимся фоном.", flatteningMultiLineText: "Объединение многострочного текста", flatteningMultiLineTextDescription: "Многострочный текст отображается одной строкой, переносы строк показаны как ¶ .", regexMaxMatchCount: "Максимум совпадений при выборе всех", diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.ts index 1d23ffe536..ff8035bd1c 100644 --- a/apps/desktop/src/i18n/locales/tr.ts +++ b/apps/desktop/src/i18n/locales/tr.ts @@ -7138,6 +7138,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "En alta kaydırıldığında sonraki grubu otomatik yükle.", dataGridShowWhitespace: "Boşluk karakterlerini göster", dataGridShowWhitespaceDescription: "Veri hücrelerinde boşlukları ·, sekmeleri → olarak gösterir. Kopyalanan ve düzenlenen değerler değişmez.", + dataGridStripedRows: "Zebra çizgileri", + dataGridStripedRowsDescription: "Etkinleştirildiğinde veri tablosundaki tek ve çift satırlar farklı arka plan renkleriyle dönüşümlü olarak gösterilir.", flatteningMultiLineText: "Çok Satırlı Metni Düzleştirme", flatteningMultiLineTextDescription: "Çok satırlı metin, satır sonları ¶ ile gösterilerek tek satırda birleştirilir.", regexMaxMatchCount: 'En fazla "tümünü seç" eşleşmesi', diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts index 39c04adb1a..9deb30bb84 100644 --- a/apps/desktop/src/i18n/locales/zh-CN.ts +++ b/apps/desktop/src/i18n/locales/zh-CN.ts @@ -8117,6 +8117,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "滚动到底部时自动加载下一批数据,无需手动翻页或加载。", dataGridShowWhitespace: "显示空白字符", dataGridShowWhitespaceDescription: "在数据单元格中将空格显示为 ·,制表符显示为 →。复制和编辑的值保持不变。", + dataGridStripedRows: "数据表格斑马纹", + dataGridStripedRowsDescription: "开启后,数据表格奇偶行交替显示不同背景色,便于横向对齐浏览。", flatteningMultiLineText: "扁平化多行文本", flatteningMultiLineTextDescription: "多行文本合并为单行显示,换行符显示为 ¶ 。", regexMaxMatchCount: "全部选中最大数量", diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts index 8417c717c4..f760d1307b 100644 --- a/apps/desktop/src/i18n/locales/zh-TW.ts +++ b/apps/desktop/src/i18n/locales/zh-TW.ts @@ -6593,6 +6593,8 @@ export default withEnglishFallback({ infiniteScrollDescription: "滾動到底部時自動載入下一批資料,無需手動翻頁或載入。", dataGridShowWhitespace: "顯示空白字元", dataGridShowWhitespaceDescription: "在資料儲存格中將空格顯示為 ·,定位字元顯示為 →。複製和編輯的值保持不變。", + dataGridStripedRows: "資料表格斑馬紋", + dataGridStripedRowsDescription: "開啟後,資料表格奇偶列交替顯示不同背景色,便於橫向對齊瀏覽。", flatteningMultiLineText: "扁平多行文本", flatteningMultiLineTextDescription: "多行文本合併為單行顯示,換行符顯示為 ¶ 。", regexMaxMatchCount: "全部選取最大數量", diff --git a/apps/desktop/src/lib/dataGrid/canvasDataGridRenderer.ts b/apps/desktop/src/lib/dataGrid/canvasDataGridRenderer.ts index 5ccea1a845..fcef0c3516 100644 --- a/apps/desktop/src/lib/dataGrid/canvasDataGridRenderer.ts +++ b/apps/desktop/src/lib/dataGrid/canvasDataGridRenderer.ts @@ -103,6 +103,7 @@ export interface DrawCanvasDataGridOptions { booleanDisplayMode?: "checkbox" | "dropdown"; flatteningMultiLineEnabled: boolean; showWhitespace?: boolean; + stripedRows?: boolean; /** 行号栏取值:`view` = 当前视图序号(默认,与筛选前一致),`source` = 筛选前的原始行号 */ rowNumberMode?: "view" | "source"; } @@ -152,6 +153,15 @@ export function resolveCanvasBackingStoreMetrics(options: { width: number; heigh }; } +export function resolveCanvasDataGridRowBase(theme: Pick, item: Pick, options: { isActive: boolean; stripedRows?: boolean }): string { + const { isActive, stripedRows = true } = options; + if (item.isDeleted) return theme.rowDeleted; + if (item.isNew && !isActive) return theme.rowNew; + if (item.isDraft && !isActive) return theme.rowMuted; + if (stripedRows && item.displayIndex % 2 === 1 && !isActive) return theme.rowMuted; + return theme.background; +} + export function resolveCanvasDataGridRowFill(theme: Pick, rowBase: string, options: { isActive: boolean; isDeleted: boolean; isSelected: boolean }): string { if (options.isSelected) return theme.cellSelected; if (options.isActive && !options.isDeleted) return theme.cellActive; @@ -368,6 +378,7 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions): boolean booleanDisplayMode = "dropdown", flatteningMultiLineEnabled, showWhitespace = false, + stripedRows = true, rowNumberMode = "view", } = options; // 框选热路径:整次绘制只判断一次。常见情况(单矩形 / 多列且每段都是多格)可跳过逐格 kind 查询 @@ -430,7 +441,10 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions): boolean const rowIsActive = isRowActive(item.displayIndex); const rowSelectionVisual = rowCellsUseSelectionVisual(item.id); - const rowBase = item.isDeleted ? theme.rowDeleted : item.isNew && !rowIsActive ? theme.rowNew : item.isDraft && !rowIsActive ? theme.rowMuted : item.displayIndex % 2 === 1 && !rowIsActive ? theme.rowMuted : theme.background; + const rowBase = resolveCanvasDataGridRowBase(theme, item, { + isActive: rowIsActive, + stripedRows, + }); const rowFill = resolveCanvasDataGridRowFill(theme, rowBase, { isActive: rowIsActive, isDeleted: item.isDeleted, diff --git a/apps/desktop/src/lib/gridSnapshot/__tests__/gridSnapshot.spec.ts b/apps/desktop/src/lib/gridSnapshot/__tests__/gridSnapshot.spec.ts index b567a471e2..f5ddda1919 100644 --- a/apps/desktop/src/lib/gridSnapshot/__tests__/gridSnapshot.spec.ts +++ b/apps/desktop/src/lib/gridSnapshot/__tests__/gridSnapshot.spec.ts @@ -114,4 +114,16 @@ describe("grid snapshot rendering", () => { expect(regular).not.toContain("integer"); expect(regular).not.toContain("Primary key"); }); + + it("supports disabling striped row backgrounds", () => { + const source = { + columns: ["id"], + rows: [[1], [2]], + }; + const defaultHtml = renderGridSnapshotHtml(source, { appearance: "light" }); + expect(defaultHtml).toContain("background:rgb(240, 240, 240)"); + + const unstripedHtml = renderGridSnapshotHtml(source, { appearance: "light", stripedRows: false }); + expect(unstripedHtml).not.toContain("background:rgb(240, 240, 240)"); + }); }); diff --git a/apps/desktop/src/lib/gridSnapshot/gridSnapshot.ts b/apps/desktop/src/lib/gridSnapshot/gridSnapshot.ts index 079a0e949c..8ad1cb4801 100644 --- a/apps/desktop/src/lib/gridSnapshot/gridSnapshot.ts +++ b/apps/desktop/src/lib/gridSnapshot/gridSnapshot.ts @@ -20,6 +20,7 @@ export interface GridSnapshotStyleOptions { showRowNumbers?: boolean; wrapCells?: boolean; transpose?: boolean; + stripedRows?: boolean; fieldNameLabel?: string; compact?: boolean; } @@ -152,7 +153,7 @@ export function renderGridSnapshotHtml(source: GridSnapshotSource, options: Grid const body = displayRows .map( (row, rowIndex) => - `${showRowNumbers ? `${rowIndex + 1}` : ""}${transpose && showFieldNames ? renderFieldCell(source.columns[rowIndex] ?? "", rowIndex, "td") : ""}${row + `${showRowNumbers ? `${rowIndex + 1}` : ""}${transpose && showFieldNames ? renderFieldCell(source.columns[rowIndex] ?? "", rowIndex, "td") : ""}${row .map((value) => { const nullClass = value === null ? " dbx-grid-snapshot__cell--null" : ""; return `${escapeHtml(formatGridSnapshotCell(value))}`; diff --git a/apps/desktop/src/lib/settings/editorSettingsDraft.ts b/apps/desktop/src/lib/settings/editorSettingsDraft.ts index 31bb1eb5b8..b682e8adfe 100644 --- a/apps/desktop/src/lib/settings/editorSettingsDraft.ts +++ b/apps/desktop/src/lib/settings/editorSettingsDraft.ts @@ -72,6 +72,7 @@ export const EDITOR_SETTINGS_DRAFT_KEYS = [ "dataGridAutoTransposeSingleRow", "dataGridCellDetailButtonVisible", "dataGridCrosshairHighlight", + "dataGridStripedRows", "pageSize", "tableOpenPageSize", "tableOpenSortMode", diff --git a/apps/desktop/src/lib/settings/settingsSearch.ts b/apps/desktop/src/lib/settings/settingsSearch.ts index dc67970f30..77ce193922 100644 --- a/apps/desktop/src/lib/settings/settingsSearch.ts +++ b/apps/desktop/src/lib/settings/settingsSearch.ts @@ -246,6 +246,7 @@ export const SETTINGS_SEARCH_DEFINITIONS: readonly SettingsSearchDefinition[] = { id: "data-grid-filter-view", category: "data", titleKey: "settings.dataGridFilterView", descriptionKey: "settings.dataGridFilterViewDescription", targetId: "data-grid-filter-view" }, { id: "data-grid-flattening-multi-line", category: "data", titleKey: "settings.flatteningMultiLineText", descriptionKey: "settings.flatteningMultiLineTextDescription", targetId: "data" }, { id: "data-grid-show-whitespace", category: "data", titleKey: "settings.dataGridShowWhitespace", descriptionKey: "settings.dataGridShowWhitespaceDescription", targetId: "data" }, + { id: "data-grid-striped-rows", category: "data", titleKey: "settings.dataGridStripedRows", descriptionKey: "settings.dataGridStripedRowsDescription", targetId: "data" }, { id: "sql-file-editor-max-mb", category: "editor", titleKey: "settings.externalSqlEditorMaxMb", descriptionKey: "settings.externalSqlEditorMaxMbDescription", targetId: "editor-sql-file" }, { id: "sql-file-web-upload-max-mb", category: "data", titleKey: "settings.webSqlFileUploadMaxMb", descriptionKey: "settings.webSqlFileUploadMaxMbDescription", targetId: "data-sql-file-upload", visible: (context) => context.isWeb }, { id: "appearance-toolbar", category: "appearance", titleKey: "settings.toolbarTitle", descriptionKey: "settings.toolbarHiddenHint", targetId: "appearance" }, diff --git a/apps/desktop/src/lib/settings/settingsTransfer.ts b/apps/desktop/src/lib/settings/settingsTransfer.ts index f73e6a7fab..7ab3e63ab9 100644 --- a/apps/desktop/src/lib/settings/settingsTransfer.ts +++ b/apps/desktop/src/lib/settings/settingsTransfer.ts @@ -167,6 +167,7 @@ const SETTINGS_TRANSFER_CATEGORY_KEYS: Record { expect(normalizeEditorSettings({ generateSqlQuoteIdentifiers: "false" } as any).generateSqlQuoteIdentifiers).toBe(true); }); + it("enables data grid striped rows by default and permits opting out", () => { + expect(DEFAULT_EDITOR_SETTINGS.dataGridStripedRows).toBe(true); + expect(normalizeEditorSettings({}).dataGridStripedRows).toBe(true); + expect(normalizeEditorSettings({ dataGridStripedRows: true }).dataGridStripedRows).toBe(true); + expect(normalizeEditorSettings({ dataGridStripedRows: false }).dataGridStripedRows).toBe(false); + expect(normalizeEditorSettings({ dataGridStripedRows: "false" } as any).dataGridStripedRows).toBe(true); + expect(normalizeEditorSettings({ dataGridStripedRows: null } as any).dataGridStripedRows).toBe(true); + }); + it("keeps SQL-file save formatting disabled unless explicitly enabled", () => { expect(normalizeEditorSettings({}).formatSqlOnSqlFileSave).toBe(false); expect(normalizeEditorSettings({ formatSqlOnSqlFileSave: true }).formatSqlOnSqlFileSave).toBe(true); @@ -1432,6 +1441,29 @@ describe("settingsStore persisted settings initialization", () => { expect(restartedStore.editorSettings.dataGridCrosshairHighlight).toBe(true); }); + it("loads, persists, and reloads data grid striped rows preference", async () => { + let persistedSettings: Record = {}; + const loadEditorSettings = vi.fn(async () => JSON.parse(JSON.stringify(persistedSettings))); + const saveEditorSettings = vi.fn(async (settings: Record) => { + persistedSettings = JSON.parse(JSON.stringify(settings)); + }); + vi.doMock("@/lib/backend/api", () => ({ loadEditorSettings, saveEditorSettings })); + + const { useSettingsStore } = await import("@/stores/settingsStore"); + const store = useSettingsStore(); + await store.initEditorSettings(); + + expect(store.editorSettings.dataGridStripedRows).toBe(true); + + await store.updateEditorSettingsAndPersist({ dataGridStripedRows: false }); + expect(saveEditorSettings).toHaveBeenLastCalledWith(expect.objectContaining({ dataGridStripedRows: false })); + + setActivePinia(createPinia()); + const restartedStore = useSettingsStore(); + await restartedStore.initEditorSettings(); + expect(restartedStore.editorSettings.dataGridStripedRows).toBe(false); + }); + it("loads, persists, and reloads hidden query editor line numbers", async () => { let persistedSettings: Record = { showLineNumbers: true }; const loadEditorSettings = vi.fn(async () => JSON.parse(JSON.stringify(persistedSettings))); diff --git a/apps/desktop/src/stores/settingsStore.ts b/apps/desktop/src/stores/settingsStore.ts index cca81cd96b..7581787ceb 100644 --- a/apps/desktop/src/stores/settingsStore.ts +++ b/apps/desktop/src/stores/settingsStore.ts @@ -963,6 +963,7 @@ export interface EditorSettings { dataGridAutoTransposeSingleRow: boolean; dataGridCellDetailButtonVisible: boolean; dataGridCrosshairHighlight: boolean; + dataGridStripedRows: boolean; dataGridMultiRowTranspose: boolean; dataGridHideNullColumns: boolean; dataGridBooleanDisplayMode: "dropdown" | "checkbox"; @@ -1259,6 +1260,7 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = { dataGridAutoTransposeSingleRow: false, dataGridCellDetailButtonVisible: true, dataGridCrosshairHighlight: false, + dataGridStripedRows: true, dataGridMultiRowTranspose: false, dataGridHideNullColumns: false, dataGridBooleanDisplayMode: "dropdown", @@ -1847,6 +1849,7 @@ export function normalizeEditorSettings(settings: Partial, exist dataGridAutoTransposeSingleRow: settings.dataGridAutoTransposeSingleRow === true, dataGridCellDetailButtonVisible: typeof settings.dataGridCellDetailButtonVisible === "boolean" ? settings.dataGridCellDetailButtonVisible : DEFAULT_EDITOR_SETTINGS.dataGridCellDetailButtonVisible, dataGridCrosshairHighlight: typeof settings.dataGridCrosshairHighlight === "boolean" ? settings.dataGridCrosshairHighlight : DEFAULT_EDITOR_SETTINGS.dataGridCrosshairHighlight, + dataGridStripedRows: typeof settings.dataGridStripedRows === "boolean" ? settings.dataGridStripedRows : DEFAULT_EDITOR_SETTINGS.dataGridStripedRows, dataGridMultiRowTranspose: settings.dataGridMultiRowTranspose === true, dataGridHideNullColumns: settings.dataGridHideNullColumns === true, dataGridBooleanDisplayMode: settings.dataGridBooleanDisplayMode === "checkbox" ? "checkbox" : "dropdown", @@ -2702,6 +2705,7 @@ export const useSettingsStore = defineStore("settings", () => { if (partial.dataGridAutoTransposeSingleRow !== undefined) editorSettings.value.dataGridAutoTransposeSingleRow = partial.dataGridAutoTransposeSingleRow === true; if (partial.dataGridCellDetailButtonVisible !== undefined) editorSettings.value.dataGridCellDetailButtonVisible = typeof partial.dataGridCellDetailButtonVisible === "boolean" ? partial.dataGridCellDetailButtonVisible : DEFAULT_EDITOR_SETTINGS.dataGridCellDetailButtonVisible; if (partial.dataGridCrosshairHighlight !== undefined) editorSettings.value.dataGridCrosshairHighlight = typeof partial.dataGridCrosshairHighlight === "boolean" ? partial.dataGridCrosshairHighlight : DEFAULT_EDITOR_SETTINGS.dataGridCrosshairHighlight; + if (partial.dataGridStripedRows !== undefined) editorSettings.value.dataGridStripedRows = typeof partial.dataGridStripedRows === "boolean" ? partial.dataGridStripedRows : DEFAULT_EDITOR_SETTINGS.dataGridStripedRows; if (partial.dataGridMultiRowTranspose !== undefined) editorSettings.value.dataGridMultiRowTranspose = partial.dataGridMultiRowTranspose === true; if (partial.dataGridHideNullColumns !== undefined) editorSettings.value.dataGridHideNullColumns = partial.dataGridHideNullColumns === true; if (partial.dataGridBooleanDisplayMode !== undefined) editorSettings.value.dataGridBooleanDisplayMode = partial.dataGridBooleanDisplayMode === "dropdown" ? "dropdown" : "checkbox"; diff --git a/packages/app-tests/canvasDataGridRenderer.test.ts b/packages/app-tests/canvasDataGridRenderer.test.ts index 01b41ee828..c904af545f 100644 --- a/packages/app-tests/canvasDataGridRenderer.test.ts +++ b/packages/app-tests/canvasDataGridRenderer.test.ts @@ -1,6 +1,6 @@ import { strict as assert } from "node:assert"; import { test } from "vitest"; -import { canvasDataGridActionReservedWidth, fitCanvasText, resolveCanvasCellTextLayout, resolveCanvasDataGridRowFill } from "../../apps/desktop/src/lib/dataGrid/canvasDataGridRenderer.ts"; +import { canvasDataGridActionReservedWidth, fitCanvasText, resolveCanvasCellTextLayout, resolveCanvasDataGridRowBase, resolveCanvasDataGridRowFill } from "../../apps/desktop/src/lib/dataGrid/canvasDataGridRenderer.ts"; import { DATA_GRID_DARK_STRIPED_ROW_BG, DATA_GRID_LIGHT_STRIPED_ROW_BG, resolveDataGridPaintTheme } from "../../apps/desktop/src/lib/dataGrid/dataGridPaintTheme.ts"; function measureContext(charWidth = 1): CanvasRenderingContext2D { @@ -70,3 +70,29 @@ test("data grid paint theme resolves cellDirty token", () => { assert.equal(resolveDataGridPaintTheme({ getVar, isDark: false }).cellDirty, "rgb(166, 210, 255)"); }); + +test("canvas row base respects stripedRows option", () => { + const theme = { + background: "bg-base", + rowMuted: "row-muted", + rowNew: "row-new", + rowDeleted: "row-deleted", + }; + + const evenRow = { displayIndex: 0, isDeleted: false, isNew: false, isDraft: false }; + const oddRow = { displayIndex: 1, isDeleted: false, isNew: false, isDraft: false }; + const newRow = { displayIndex: 0, isDeleted: false, isNew: true, isDraft: false }; + + // With stripedRows enabled (default or explicit true) + assert.equal(resolveCanvasDataGridRowBase(theme, evenRow, { isActive: false }), "bg-base"); + assert.equal(resolveCanvasDataGridRowBase(theme, oddRow, { isActive: false }), "row-muted"); + assert.equal(resolveCanvasDataGridRowBase(theme, oddRow, { isActive: false, stripedRows: true }), "row-muted"); + + // With stripedRows disabled + assert.equal(resolveCanvasDataGridRowBase(theme, evenRow, { isActive: false, stripedRows: false }), "bg-base"); + assert.equal(resolveCanvasDataGridRowBase(theme, oddRow, { isActive: false, stripedRows: false }), "bg-base"); + + // New row takes precedence when not active + assert.equal(resolveCanvasDataGridRowBase(theme, newRow, { isActive: false, stripedRows: false }), "row-new"); + assert.equal(resolveCanvasDataGridRowBase(theme, newRow, { isActive: false, stripedRows: true }), "row-new"); +});