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): increment ID zero-padding, prefix and suffix options
lxk955dab91681c97d
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex afc42b07f0..bdebd98a48 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -115,7 +115,7 @@ import { createColumnDrafts } from "@/lib/table/tableStructureEditorState";import type { BuildSingleColumnAlterSqlOptions } from "@/lib/table/tableStructureEditorSql";import { buildTableSelectSql, qualifyTableReferencesInSql, quoteTableDataIdentifier } from "@/lib/table/tableSelectSql";import { uuid } from "@/lib/common/utils";-import { generateCellValues, type CellValueGenerationKind } from "@/lib/dataGrid/cellValueGeneration";+import { generateCellValues, type CellValueGenerationKind, type CellValueGenerationOptions } from "@/lib/dataGrid/cellValueGeneration";import { MONGO_DOCUMENT_GRID_NULL, mongoDocumentGridClipboardText, mongoDocumentGridDisplayText, mongoDocumentGridEditorText, mongoDocumentGridExternalValue, mongoDocumentGridInputValue, mongoDocumentGridNumericValue, mongoDocumentRelaxedExtendedJson } from "@/lib/mongo/mongoDocumentValues";import { compactHeaderColumnType, formatMetadataColumnTypeLabel, isNumericColumnType, resolveDataGridTypeVisualKind, resolveHeaderColumnType, resolveResultColumnType } from "@/lib/dataGrid/dataGridColumnType";import { dataGridCellTextClass, dataGridTypeVisualClass } from "@/lib/dataGrid/dataGridCellTextVisual";@@ -1085,6 +1085,9 @@ const insertRowsDialogOpen = ref(false);const insertPosition = ref<GridInsertRowPosition>("below");const generateIncrementDialogOpen = ref(false);const generateIncrementStartValue = ref("1");+const generateIncrementPadLength = ref("");+const generateIncrementPrefix = ref("");+const generateIncrementSuffix = ref("");const generateIncrementTarget = ref<"selection" | "detail">("selection");const gridSnapshotOpen = ref(false);const gridSnapshotSource = ref<GridSnapshotSource | null>(null);@@ -9945,11 +9948,12 @@ function beginInlineBulkEdit(initialValue: string): boolean {return true;}-function applyGeneratedSelectionValue(kind: CellValueGenerationKind, startValue = 1n): boolean {+function applyGeneratedSelectionValue(kind: CellValueGenerationKind, generationOptions?: CellValueGenerationOptions | bigint): boolean {if (!props.editable) return false;const cells = editableSelectionCells();if (!cells.length) return false;- const values = generateCellValues(kind, cells.length, { startValue });+ const options = typeof generationOptions === "bigint" ? { startValue: generationOptions } : (generationOptions ?? {});+ const values = generateCellValues(kind, cells.length, options);const allowDraftSelectionValue = selectedRangeTargetsOnlyDraftRow();let applied = false;beginBatch();@@ -9967,10 +9971,11 @@ function applyGeneratedSelectionValue(kind: CellValueGenerationKind, startValuereturn applied;}-function applyGeneratedDetailValue(kind: CellValueGenerationKind, startValue = 1n): boolean {+function applyGeneratedDetailValue(kind: CellValueGenerationKind, generationOptions?: CellValueGenerationOptions | bigint): boolean {const detail = activeCellDetail.value;if (!detail?.isEditable) return false;- const value = generatedGridValue(kind, generateCellValues(kind, 1, { startValue })[0] ?? null);+ const options = typeof generationOptions === "bigint" ? { startValue: generationOptions } : (generationOptions ?? {});+ const value = generatedGridValue(kind, generateCellValues(kind, 1, options)[0] ?? null);applyCellValue(detail.rowId, detail.colIndex, value, {preserveEmptyString: kind === "empty",});@@ -9993,9 +9998,42 @@ function openGenerateIncrementDialog(target: "selection" | "detail") {if (target === "detail" && !activeCellDetail.value?.isEditable) return;generateIncrementTarget.value = target;generateIncrementStartValue.value = "1";+ generateIncrementPadLength.value = "";+ generateIncrementPrefix.value = "";+ generateIncrementSuffix.value = "";generateIncrementDialogOpen.value = true;}+const generateIncrementPreview = computed(() => {+ try {+ const rawStart = generateIncrementStartValue.value.trim();+ const startValue = BigInt(rawStart || "1");+ let padLength: number | undefined;+ const trimmedPad = generateIncrementPadLength.value.trim();+ if (trimmedPad) {+ const parsed = Number(trimmedPad);+ if (!Number.isInteger(parsed) || parsed < 0 || parsed > 64) {+ return "";+ }+ padLength = parsed;+ }+ const totalCount = generateIncrementTarget.value === "detail" ? 1 : editableSelectionCells().length;+ const count = Math.min(Math.max(1, totalCount), 3);+ const values = generateCellValues("increment", count, {+ startValue,+ padLength,+ prefix: generateIncrementPrefix.value,+ suffix: generateIncrementSuffix.value,+ });+ if (totalCount > 3) {+ return `${values.slice(0, 2).join(", ")}, … (${totalCount})`;+ }+ return values.join(", ");+ } catch {+ return "";+ }+});+function applyGenerateIncrementValue() {let startValue: bigint;try {@@ -10004,7 +10042,23 @@ function applyGenerateIncrementValue() {toast(t("grid.generateStartInvalid"));return;}- const applied = generateIncrementTarget.value === "detail" ? applyGeneratedDetailValue("increment", startValue) : applyGeneratedSelectionValue("increment", startValue);+ let padLength: number | undefined;+ const trimmedPad = generateIncrementPadLength.value.trim();+ if (trimmedPad) {+ const parsed = Number(trimmedPad);+ if (!Number.isInteger(parsed) || parsed < 0 || parsed > 64) {+ toast(t("grid.generatePadLengthInvalid"));+ return;+ }+ padLength = parsed;+ }+ const options: CellValueGenerationOptions = {+ startValue,+ padLength,+ prefix: generateIncrementPrefix.value,+ suffix: generateIncrementSuffix.value,+ };+ const applied = generateIncrementTarget.value === "detail" ? applyGeneratedDetailValue("increment", options) : applyGeneratedSelectionValue("increment", options);if (applied) generateIncrementDialogOpen.value = false;}@@ -15953,11 +16007,11 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val</Dialog><Dialog v-model:open="generateIncrementDialogOpen">- <DialogContent class="sm:max-w-[380px]">+ <DialogContent class="sm:max-w-[420px]"><DialogHeader><DialogTitle>{{ t("grid.generateIncrementId") }}</DialogTitle></DialogHeader>- <div class="space-y-2">+ <div class="space-y-3"><p class="text-sm text-muted-foreground">{{t("grid.generateSequenceDescription", {@@ -15965,7 +16019,28 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val})}}</p>- <Input v-model="generateIncrementStartValue" inputmode="numeric" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" placeholder="1" @keydown.enter.prevent="applyGenerateIncrementValue" />+ <div class="space-y-1.5">+ <label class="text-xs font-medium text-foreground">{{ t("grid.generateStartValue") }}</label>+ <Input v-model="generateIncrementStartValue" inputmode="numeric" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" placeholder="1" @keydown.enter.prevent="applyGenerateIncrementValue" />+ </div>+ <div class="space-y-1.5">+ <label class="text-xs font-medium text-foreground">{{ t("grid.generatePadLength") }}</label>+ <Input v-model="generateIncrementPadLength" inputmode="numeric" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" :placeholder="t('grid.generatePadLengthPlaceholder')" @keydown.enter.prevent="applyGenerateIncrementValue" />+ </div>+ <div class="grid grid-cols-2 gap-2">+ <div class="space-y-1.5">+ <label class="text-xs font-medium text-foreground">{{ t("grid.generatePrefix") }}</label>+ <Input v-model="generateIncrementPrefix" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" :placeholder="t('grid.generatePrefixPlaceholder')" @keydown.enter.prevent="applyGenerateIncrementValue" />+ </div>+ <div class="space-y-1.5">+ <label class="text-xs font-medium text-foreground">{{ t("grid.generateSuffix") }}</label>+ <Input v-model="generateIncrementSuffix" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" :placeholder="t('grid.generateSuffixPlaceholder')" @keydown.enter.prevent="applyGenerateIncrementValue" />+ </div>+ </div>+ <div v-if="generateIncrementPreview" class="rounded-md border bg-muted/50 p-2.5 text-xs">+ <span class="font-medium text-muted-foreground">{{ t("grid.generatePreview") }}: </span>+ <span class="font-mono select-all">{{ generateIncrementPreview }}</span>+ </div></div><DialogFooter><Button variant="outline" @click="generateIncrementDialogOpen = false">{{ t("dangerDialog.cancel") }}</Button>diff --git a/apps/desktop/src/components/grid/__tests__/DataGridBatchPasteFromCell.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridBatchPasteFromCell.spec.tsindex e833dfe185..7e415e05bc 100644--- a/apps/desktop/src/components/grid/__tests__/DataGridBatchPasteFromCell.spec.ts+++ b/apps/desktop/src/components/grid/__tests__/DataGridBatchPasteFromCell.spec.ts@@ -839,6 +839,47 @@ describe("selected transpose edit scope", () => {).toEqual(["1", "hidden", "2"]);});+ it("generates increment values with zero padding, prefix, and suffix in the dialog", async () => {+ const { host } = mountGrid({ result: resultWithThreeRows() });+ await openSelectedRows(host);+ transposeCells(host)[0].click();+ await settle();+ transposeCells(host)[1].dispatchEvent(new MouseEvent("click", { shiftKey: true, bubbles: true }));+ await settle();+ transposeCells(host)[1].dispatchEvent(new MouseEvent("contextmenu", { shiftKey: true, bubbles: true, cancelable: true, clientX: 12, clientY: 12 }));+ await settle();+ const menuButton = (label: string) => {+ const button = [...document.querySelectorAll<HTMLButtonElement>("[data-dbx-context-menu] button")].find((item) => item.textContent?.trim() === label);+ if (!button) throw new Error(`Context menu item not found: ${label}`);+ return button;+ };+ menuButton(i18n.global.t("grid.generateValue")).dispatchEvent(new MouseEvent("mouseenter", { bubbles: true }));+ await settle();+ menuButton(i18n.global.t("grid.generateIncrementId")).click();+ await settle();+ const dialog = document.querySelector<HTMLElement>("[role='dialog']")!;+ const inputs = dialog.querySelectorAll<HTMLInputElement>("input");+ expect(inputs).toHaveLength(4);+ inputs[1].value = "4";+ inputs[1].dispatchEvent(new Event("input"));+ inputs[2].value = "ITEM_";+ inputs[2].dispatchEvent(new Event("input"));+ inputs[3].value = "_V1";+ inputs[3].dispatchEvent(new Event("input"));+ await settle();+ expect(dialog.textContent).toContain("ITEM_0001_V1, ITEM_0002_V1");+ const apply = [...dialog.querySelectorAll<HTMLButtonElement>("button")].find((button) => button.textContent?.trim() === i18n.global.t("grid.applyBulkEdit"))!;+ apply.click();+ await settle();+ expect(useToast().message.value).toBe(i18n.global.t("grid.generatedValuesApplied", { count: 2 }));+ await toggleTranspose(host);+ expect(+ displayRows(host)+ .slice(0, 3)+ .map((row) => visibleCellTexts(row)[2]),+ ).toEqual(["ITEM_0001_V1", "hidden", "ITEM_0002_V1"]);+ });+it("maps pasted records through the transpose scope and stops at its end", async () => {const { host } = mountGrid({ result: resultWithThreeRows() });await openSelectedRows(host);diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.tsindex 9aef70614a..019e0d8d1d 100644--- a/apps/desktop/src/i18n/locales/az.ts+++ b/apps/desktop/src/i18n/locales/az.ts@@ -2351,7 +2351,16 @@ export default withEnglishFallback({generateIncrementId: "Artan ID",generateSnowflakeId: "Snowflake ID",generateSequenceDescription: "Seçilmiş {count} xana üçün ardıcıl dəyərlər yaradın. Başlanğıc dəyəri daxil edin.",+ generateStartValue: "Başlanğıc dəyəri",generateStartInvalid: "Başlanğıc dəyər tam ədəd olmalıdır",+ generatePadLength: "Sıfırla doldurma uzunluğu",+ generatePadLengthPlaceholder: "məs., 4 (istəyə bağlı)",+ generatePadLengthInvalid: "Sıfırla doldurma uzunluğu 0 ilə 64 arasında bir tam ədəd olmalıdır",+ generatePrefix: "Prefiks",+ generatePrefixPlaceholder: "məs., USER_ (istəyə bağlı)",+ generateSuffix: "Suffiks",+ generateSuffixPlaceholder: "məs., _TEST (istəyə bağlı)",+ generatePreview: "Önizləmə",generatedValuesApplied: "{count} dəyər yaradıldı",cellDetails: "Xananın təfərrüatları",cellDetailLayoutBottom: "Aşağıya köçür",diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex 7682b52f8c..cf87bb9658 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -2823,7 +2823,16 @@ export default {generateIncrementId: "Increment ID",generateSnowflakeId: "Snowflake ID",generateSequenceDescription: "Generate consecutive values for {count} selected cell(s). Enter the start value.",+ generateStartValue: "Start value",generateStartInvalid: "Start value must be an integer",+ generatePadLength: "Zero pad length",+ generatePadLengthPlaceholder: "e.g. 4 (optional)",+ generatePadLengthInvalid: "Zero pad length must be an integer between 0 and 64",+ generatePrefix: "Prefix",+ generatePrefixPlaceholder: "e.g. USER_ (optional)",+ generateSuffix: "Suffix",+ generateSuffixPlaceholder: "e.g. _TEST (optional)",+ generatePreview: "Preview",generatedValuesApplied: "Generated {count} value(s)",cellDetails: "Cell Details",cellDetailLayoutBottom: "Move to Bottom",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex b8ac3d04dd..0c9a5e66c6 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -2643,7 +2643,16 @@ export default withEnglishFallback({generateIncrementId: "ID incremental",generateSnowflakeId: "ID Snowflake",generateSequenceDescription: "Generar valores consecutivos para {count} celda(s) seleccionada(s). Introduzca el valor inicial.",+ generateStartValue: "Valor inicial",generateStartInvalid: "El valor inicial debe ser un número entero",+ generatePadLength: "Longitud de relleno con ceros",+ generatePadLengthPlaceholder: "p. ej., 4 (opcional)",+ generatePadLengthInvalid: "La longitud de relleno con ceros debe ser un número entero entre 0 y 64",+ generatePrefix: "Prefijo",+ generatePrefixPlaceholder: "p. ej., USER_ (opcional)",+ generateSuffix: "Sufijo",+ generateSuffixPlaceholder: "p. ej., _TEST (opcional)",+ generatePreview: "Vista previa",generatedValuesApplied: "Se generaron {count} valor(es)",cellDetails: "Detalles de celda",cellDetailLayoutBottom: "Mover abajo",diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.tsindex 04d61d6f46..5ecb86cf95 100644--- a/apps/desktop/src/i18n/locales/id.ts+++ b/apps/desktop/src/i18n/locales/id.ts@@ -2656,7 +2656,16 @@ export default withEnglishFallback({generateIncrementId: "ID Increment",generateSnowflakeId: "ID Snowflake",generateSequenceDescription: "Hasilkan nilai berurutan untuk {count} sel terpilih. Masukkan nilai awal.",+ generateStartValue: "Nilai awal",generateStartInvalid: "Nilai awal harus berupa bilangan bulat",+ generatePadLength: "Panjang padding nol",+ generatePadLengthPlaceholder: "contoh: 4 (opsional)",+ generatePadLengthInvalid: "Panjang padding nol harus berupa bilangan bulat antara 0 dan 64",+ generatePrefix: "Prefiks",+ generatePrefixPlaceholder: "contoh: USER_ (opsional)",+ generateSuffix: "Sufiks",+ generateSuffixPlaceholder: "contoh: _TEST (opsional)",+ generatePreview: "Pratinjau",generatedValuesApplied: "{count} nilai dihasilkan",cellDetails: "Detail Sel",cellDetailLayoutBottom: "Pindahkan ke Bawah",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex 58cf4e9c7e..9151e0b559 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -2537,7 +2537,16 @@ export default withEnglishFallback({generateIncrementId: "ID incrementale",generateSnowflakeId: "ID Snowflake",generateSequenceDescription: "Genera valori consecutivi per le {count} celle selezionate. Inserisci il valore iniziale.",+ generateStartValue: "Valore iniziale",generateStartInvalid: "Il valore iniziale deve essere un numero intero",+ generatePadLength: "Lunghezza riempimento con zeri",+ generatePadLengthPlaceholder: "es. 4 (opzionale)",+ generatePadLengthInvalid: "La lunghezza del riempimento con zeri deve essere un numero intero compreso tra 0 e 64",+ generatePrefix: "Prefisso",+ generatePrefixPlaceholder: "es. USER_ (opzionale)",+ generateSuffix: "Suffisso",+ generateSuffixPlaceholder: "es. _TEST (opzionale)",+ generatePreview: "Anteprima",generatedValuesApplied: "Generati {count} valori",cellDetails: "Dettagli Cella",cellDetailLayoutBottom: "Sposta in Basso",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex 89776468de..86a5c7569b 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -2543,7 +2543,16 @@ export default withEnglishFallback({generateIncrementId: "連番ID",generateSnowflakeId: "Snowflake ID",generateSequenceDescription: "選択した{count}セルに連続値を生成します。開始値を入力してください。",+ generateStartValue: "開始値",generateStartInvalid: "開始値は整数で入力してください",+ generatePadLength: "ゼロ埋め桁数",+ generatePadLengthPlaceholder: "例: 4(省略可能)",+ generatePadLengthInvalid: "ゼロ埋め桁数は 0 から 64 の整数である必要があります",+ generatePrefix: "プレフィックス",+ generatePrefixPlaceholder: "例: USER_(省略可能)",+ generateSuffix: "サフィックス",+ generateSuffixPlaceholder: "例: _TEST(省略可能)",+ generatePreview: "プレビュー",generatedValuesApplied: "{count}個の値を生成しました",cellDetails: "セル詳細",cellDetailLayoutBottom: "下部に表示",diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.tsindex 21551e800f..ccab4c7900 100644--- a/apps/desktop/src/i18n/locales/ko.ts+++ b/apps/desktop/src/i18n/locales/ko.ts@@ -2594,7 +2594,16 @@ export default withEnglishFallback({generateIncrementId: "증가 ID",generateSnowflakeId: "Snowflake ID",generateSequenceDescription: "선택한 {count}개 셀에 연속 값을 생성합니다. 시작 값을 입력하세요.",+ generateStartValue: "시작 값",generateStartInvalid: "시작 값은 정수여야 합니다",+ generatePadLength: "0 채우기 자릿수",+ generatePadLengthPlaceholder: "예: 4 (선택 사항)",+ generatePadLengthInvalid: "0 채우기 자릿수는 0에서 64 사이의 정수여야 합니다",+ generatePrefix: "접두사",+ generatePrefixPlaceholder: "예: USER_ (선택 사항)",+ generateSuffix: "접미사",+ generateSuffixPlaceholder: "예: _TEST (선택 사항)",+ generatePreview: "미리보기",generatedValuesApplied: "{count}개 값 생성됨",cellDetails: "셀 상세",cellDetailLayoutBottom: "아래로 이동",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex b7aabdbd97..d942fda8c3 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -2538,7 +2538,16 @@ export default withEnglishFallback({generateIncrementId: "ID incremental",generateSnowflakeId: "ID Snowflake",generateSequenceDescription: "Gere valores consecutivos para {count} célula(s) selecionada(s). Informe o valor inicial.",+ generateStartValue: "Valor inicial",generateStartInvalid: "O valor inicial deve ser um número inteiro",+ generatePadLength: "Tamanho do preenchimento com zeros",+ generatePadLengthPlaceholder: "ex.: 4 (opcional)",+ generatePadLengthInvalid: "O tamanho do preenchimento com zeros deve ser um número inteiro entre 0 e 64",+ generatePrefix: "Prefixo",+ generatePrefixPlaceholder: "ex.: USER_ (opcional)",+ generateSuffix: "Sufixo",+ generateSuffixPlaceholder: "ex.: _TEST (opcional)",+ generatePreview: "Pré-visualização",generatedValuesApplied: "Foram gerados {count} valor(es)",cellDetails: "Detalhes da Célula",cellDetailLayoutBottom: "Mover para Baixo",diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.tsindex 015730cd3c..e42b4eb0fd 100644--- a/apps/desktop/src/i18n/locales/ru.ts+++ b/apps/desktop/src/i18n/locales/ru.ts@@ -2716,7 +2716,16 @@ export default withEnglishFallback({generateIncrementId: "Инкрементный ID",generateSnowflakeId: "Snowflake ID",generateSequenceDescription: "Сгенерировать последовательные значения для {count} выбранных ячеек. Введите начальное значение.",+ generateStartValue: "Начальное значение",generateStartInvalid: "Начальное значение должно быть целым числом",+ generatePadLength: "Длина дополнения нулями",+ generatePadLengthPlaceholder: "напр., 4 (необязательно)",+ generatePadLengthInvalid: "Длина дополнения нулями должна быть целым числом от 0 до 64",+ generatePrefix: "Префикс",+ generatePrefixPlaceholder: "напр., USER_ (необязательно)",+ generateSuffix: "Суффикс",+ generateSuffixPlaceholder: "напр., _TEST (необязательно)",+ generatePreview: "Предпросмотр",generatedValuesApplied: "Сгенерировано значений: {count}",cellDetails: "Сведения о ячейке",cellDetailLayoutBottom: "Переместить вниз",diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.tsindex 210413ba18..d89fc48dca 100644--- a/apps/desktop/src/i18n/locales/tr.ts+++ b/apps/desktop/src/i18n/locales/tr.ts@@ -2344,7 +2344,16 @@ export default withEnglishFallback({generateIncrementId: "Artan Kimlik",generateSnowflakeId: "Snowflake Kimliği",generateSequenceDescription: "Seçili {count} hücre için ardışık değerler üretin. Başlangıç değerini girin.",+ generateStartValue: "Başlangıç değeri",generateStartInvalid: "Başlangıç değeri bir tam sayı olmalıdır",+ generatePadLength: "Sıfır doldurma uzunluğu",+ generatePadLengthPlaceholder: "ör. 4 (isteğe bağlı)",+ generatePadLengthInvalid: "Sıfır doldurma uzunluğu 0 ile 64 arasında bir tam sayı olmalıdır",+ generatePrefix: "Ön ek",+ generatePrefixPlaceholder: "ör. USER_ (isteğe bağlı)",+ generateSuffix: "Son ek",+ generateSuffixPlaceholder: "ör. _TEST (isteğe bağlı)",+ generatePreview: "Önizleme",generatedValuesApplied: "{count} değer üretildi",cellDetails: "Hücre Ayrıntıları",cellDetailLayoutBottom: "Alta Taşı",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex ab43f3ea84..562b2d713f 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -2758,7 +2758,16 @@ export default withEnglishFallback({generateIncrementId: "递增 ID",generateSnowflakeId: "雪花 ID",generateSequenceDescription: "为已选 {count} 个单元格生成连续值,请输入起始值。",+ generateStartValue: "起始值",generateStartInvalid: "起始值必须是整数",+ generatePadLength: "补零位数",+ generatePadLengthPlaceholder: "例如 4(可选)",+ generatePadLengthInvalid: "补零位数必须是 0 到 64 之间的整数",+ generatePrefix: "前缀",+ generatePrefixPlaceholder: "例如 USER_(可选)",+ generateSuffix: "后缀",+ generateSuffixPlaceholder: "例如 _TEST(可选)",+ generatePreview: "预览",generatedValuesApplied: "已生成 {count} 个值",cellDetails: "单元格详情",cellDetailLayoutBottom: "移动到底部",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex 3e95b19e5c..7401f1ef17 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -2539,7 +2539,16 @@ export default withEnglishFallback({generateIncrementId: "遞增 ID",generateSnowflakeId: "雪花 ID",generateSequenceDescription: "為已選 {count} 個儲存格產生連續值,請輸入起始值。",+ generateStartValue: "起始值",generateStartInvalid: "起始值必須是整數",+ generatePadLength: "補零位數",+ generatePadLengthPlaceholder: "例如 4(可選)",+ generatePadLengthInvalid: "補零位數必須是 0 到 64 之間的整數",+ generatePrefix: "前綴",+ generatePrefixPlaceholder: "例如 USER_(可選)",+ generateSuffix: "後綴",+ generateSuffixPlaceholder: "例如 _TEST(可選)",+ generatePreview: "預覽",generatedValuesApplied: "已產生 {count} 個值",cellDetails: "儲存格詳情",cellDetailLayoutBottom: "移到底部",diff --git a/apps/desktop/src/lib/__tests__/dataGrid/cellValueGeneration.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/cellValueGeneration.spec.tsindex a58c426a15..cb69c582a4 100644--- a/apps/desktop/src/lib/__tests__/dataGrid/cellValueGeneration.spec.ts+++ b/apps/desktop/src/lib/__tests__/dataGrid/cellValueGeneration.spec.ts@@ -84,6 +84,38 @@ describe("generateCellValues", () => {expect(generateCellValues("increment", 3, { startValue: 9_007_199_254_740_993n })).toEqual(["9007199254740993", "9007199254740994", "9007199254740995"]);});+ it("pads increment values with leading zeros", () => {+ expect(generateCellValues("increment", 3, { startValue: 1n, padLength: 4 })).toEqual(["0001", "0002", "0003"]);+ expect(generateCellValues("increment", 2, { startValue: 99n, padLength: 4 })).toEqual(["0099", "0100"]);+ expect(generateCellValues("increment", 2, { startValue: 1000n, padLength: 3 })).toEqual(["1000", "1001"]);+ expect(generateCellValues("increment", 2, { startValue: 1n, padLength: 0 })).toEqual(["1", "2"]);+ expect(generateCellValues("increment", 2, { startValue: 1n, padLength: -1 })).toEqual(["1", "2"]);+ });++ it("applies prefix and suffix to increment values", () => {+ expect(generateCellValues("increment", 2, { startValue: 1n, prefix: "USER_" })).toEqual(["USER_1", "USER_2"]);+ expect(generateCellValues("increment", 2, { startValue: 1n, suffix: "_TEST" })).toEqual(["1_TEST", "2_TEST"]);+ expect(+ generateCellValues("increment", 3, {+ startValue: 1n,+ padLength: 4,+ prefix: "USER_",+ suffix: "_TEST",+ }),+ ).toEqual(["USER_0001_TEST", "USER_0002_TEST", "USER_0003_TEST"]);+ });++ it("formats negative increment values with padding and affixes", () => {+ expect(+ generateCellValues("increment", 4, {+ startValue: -2n,+ padLength: 3,+ prefix: "ID:",+ suffix: "!",+ }),+ ).toEqual(["ID:-002!", "ID:-001!", "ID:000!", "ID:001!"]);+ });+it("keeps snowflake IDs unique and ordered beyond one sequence window", () => {const generator = createSnowflakeIdGenerator({ workerId: 7, now: () => 1_800_000_000_000 });const values = generateCellValues("snowflake", 5000, { now: new Date(1_800_000_000_000), snowflakeGenerator: generator }) as string[];diff --git a/apps/desktop/src/lib/dataGrid/cellValueGeneration.ts b/apps/desktop/src/lib/dataGrid/cellValueGeneration.tsindex b2c4b2c700..9d14b61d03 100644--- a/apps/desktop/src/lib/dataGrid/cellValueGeneration.ts+++ b/apps/desktop/src/lib/dataGrid/cellValueGeneration.ts@@ -38,16 +38,17 @@ export function createSnowflakeIdGenerator(options: { workerId?: number; now?: (const defaultSnowflakeIdGenerator = createSnowflakeIdGenerator();-export function generateCellValues(- kind: CellValueGenerationKind,- count: number,- options: {- now?: Date;- startValue?: bigint;- uuidFactory?: () => string;- snowflakeGenerator?: SnowflakeIdGenerator;- } = {},-): Array<string | null> {+export interface CellValueGenerationOptions {+ now?: Date;+ startValue?: bigint;+ padLength?: number;+ prefix?: string;+ suffix?: string;+ uuidFactory?: () => string;+ snowflakeGenerator?: SnowflakeIdGenerator;+}++export function generateCellValues(kind: CellValueGenerationKind, count: number, options: CellValueGenerationOptions = {}): Array<string | null> {const size = Math.max(0, Math.trunc(count));const now = options.now ?? new Date();const uuidFactory = options.uuidFactory ?? uuid;@@ -66,7 +67,18 @@ export function generateCellValues(const timestamp = now.getTime().toString(16).padStart(12, "0");return `${timestamp.slice(0, 8)}-${timestamp.slice(8)}-7${uuidFactory().slice(15)}`;}- if (kind === "increment") return String((options.startValue ?? 1n) + BigInt(index));+ if (kind === "increment") {+ const num = (options.startValue ?? 1n) + BigInt(index);+ const isNegative = num < 0n;+ const absStr = (isNegative ? -num : num).toString();+ const rawPad = options.padLength;+ const padLength = typeof rawPad === "number" && Number.isFinite(rawPad) && rawPad > 0 ? Math.min(Math.trunc(rawPad), 64) : 0;+ const padded = padLength > 0 ? absStr.padStart(padLength, "0") : absStr;+ const numStr = isNegative ? `-${padded}` : padded;+ const prefix = options.prefix ?? "";+ const suffix = options.suffix ?? "";+ return `${prefix}${numStr}${suffix}`;+ }return snowflakeGenerator.next(now.getTime());});}