feat(grid): 新增原始数据复制模式并设为默认
* ✨ feat(grid): 新增原始数据复制模式并设为默认 - 原样输出单元格内容,不对引号、制表符和换行进行 DSV 转义 - 支持原始数据复制后的网格粘贴还原 - 补充多语言复制选项文案及前后端提取器实现与测试 * ✨ feat(grid): 优化新增智能复制选项 - 单个单元格复制保留原始单元格文本,多单元格自动使用转义 TSV - 默认复制设置由格式选择升级为复制行为选择,并支持预览 - 限制原始文本格式仅用于单单元格复制 - 更新多语言文案及相关测试
This commit is contained in:
24 files changed
+333
-91
No files matched your search
@@ -1,7 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS, normalizeDataGridExtractorOptions, validateDataGridExtractorOptions } from "@/lib/dataGrid/dataGridCopyExtractor";
|
||||
import { DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS, normalizeDataGridCopyPreference, normalizeDataGridExtractorOptions, resolveDataGridCopyPreference, validateDataGridExtractorOptions } from "@/lib/dataGrid/dataGridCopyExtractor";
|
||||
|
||||
describe("data-grid extractor options", () => {
|
||||
it("resolves smart copy to raw for one cell and TSV otherwise", () => {
|
||||
expect(normalizeDataGridCopyPreference(undefined)).toBe("smart");
|
||||
expect(normalizeDataGridCopyPreference("smart")).toBe("smart");
|
||||
expect(resolveDataGridCopyPreference("smart", 1)).toBe("raw");
|
||||
expect(resolveDataGridCopyPreference("smart", 2)).toBe("tsv");
|
||||
expect(resolveDataGridCopyPreference("csv", 1)).toBe("csv");
|
||||
});
|
||||
|
||||
it("normalizes persisted values without sharing the default object", () => {
|
||||
const normalized = normalizeDataGridExtractorOptions(DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS);
|
||||
|
||||
|
||||
@@ -1,14 +1,37 @@
|
||||
import type { DatabaseType } from "@/types/database";
|
||||
import type { DataGridCopyInsertMode, DataGridTableMeta } from "@/lib/dataGrid/dataGridSql";
|
||||
|
||||
export const DATA_GRID_COPY_EXTRACTOR_IDS = ["tsv", "tsv-with-headers", "csv", "csv-with-headers", "pipe-separated", "dsv", "json", "json-lines", "one-row", "sql-in-list", "sql-inserts", "sql-updates", "where-clause", "markdown", "html", "xml", "pretty"] as const;
|
||||
export const DATA_GRID_COPY_EXTRACTOR_IDS = ["raw", "tsv", "tsv-with-headers", "csv", "csv-with-headers", "pipe-separated", "dsv", "json", "json-lines", "one-row", "sql-in-list", "sql-inserts", "sql-updates", "where-clause", "markdown", "html", "xml", "pretty"] as const;
|
||||
|
||||
export type DataGridCopyExtractorId = (typeof DATA_GRID_COPY_EXTRACTOR_IDS)[number];
|
||||
export type DataGridExtractorCategory = "delimited" | "json" | "sql" | "document";
|
||||
export type DataGridCopyPreference = "smart" | Exclude<DataGridCopyExtractorId, "raw">;
|
||||
export type DataGridExtractorCategory = "raw" | "delimited" | "json" | "sql" | "document";
|
||||
|
||||
export const DATA_GRID_DEFAULT_COPY_PREFERENCES: readonly DataGridCopyPreference[] = [
|
||||
"smart",
|
||||
"tsv",
|
||||
"tsv-with-headers",
|
||||
"csv",
|
||||
"csv-with-headers",
|
||||
"pipe-separated",
|
||||
"dsv",
|
||||
"json",
|
||||
"json-lines",
|
||||
"one-row",
|
||||
"sql-in-list",
|
||||
"sql-inserts",
|
||||
"sql-updates",
|
||||
"where-clause",
|
||||
"markdown",
|
||||
"html",
|
||||
"xml",
|
||||
"pretty",
|
||||
];
|
||||
|
||||
export const DATA_GRID_EXTRACTOR_CONTRACT_VERSION = 1 as const;
|
||||
|
||||
export const DATA_GRID_COPY_EXTRACTOR_DESCRIPTORS: Record<DataGridCopyExtractorId, { category: DataGridExtractorCategory; separatorBefore?: boolean }> = {
|
||||
raw: { category: "raw" },
|
||||
tsv: { category: "delimited" },
|
||||
"tsv-with-headers": { category: "delimited" },
|
||||
csv: { category: "delimited" },
|
||||
@@ -154,10 +177,15 @@ export function normalizeDataGridExtractorOptions(value: unknown): DataGridExtra
|
||||
};
|
||||
}
|
||||
|
||||
const DATA_GRID_COPY_EXTRACTOR_ID_SET = new Set<string>(DATA_GRID_COPY_EXTRACTOR_IDS);
|
||||
const DATA_GRID_COPY_PREFERENCE_SET = new Set<string>(DATA_GRID_DEFAULT_COPY_PREFERENCES);
|
||||
|
||||
export function normalizeDataGridCopyExtractorId(value: unknown): DataGridCopyExtractorId {
|
||||
return typeof value === "string" && DATA_GRID_COPY_EXTRACTOR_ID_SET.has(value) ? (value as DataGridCopyExtractorId) : "tsv";
|
||||
export function normalizeDataGridCopyPreference(value: unknown): DataGridCopyPreference {
|
||||
return typeof value === "string" && DATA_GRID_COPY_PREFERENCE_SET.has(value) ? (value as DataGridCopyPreference) : "smart";
|
||||
}
|
||||
|
||||
export function resolveDataGridCopyPreference(preference: DataGridCopyPreference, selectedCellCount: number): DataGridCopyExtractorId {
|
||||
if (preference !== "smart") return preference;
|
||||
return selectedCellCount === 1 ? "raw" : "tsv";
|
||||
}
|
||||
|
||||
export function validateDataGridExtractorOptions(extractor: DataGridCopyExtractorId, options: DataGridExtractorOptions): DataGridExtractorOptionsError | null {
|
||||
|
||||
Reference in new issue
Block a user