@libs-ui/components-spreadsheet 0.2.356-43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,123 @@
1
+ import { BooleanNumber } from '@univerjs/core';
2
+ /**
3
+ * Mapping Indicators — đánh dấu (highlight) header của các cột đã được "map" theo
4
+ * một nghiệp vụ bất kỳ, để người dùng nhìn thấy ngay cột nào đang gắn với field nào.
5
+ *
6
+ * Toàn bộ logic chạy trên workbook snapshot (plain JSON của Univer) — KHÔNG phụ thuộc
7
+ * vào instance Univer đang chạy. Vì vậy có thể gọi trước khi load, hoặc trên data đã save.
8
+ *
9
+ * Cách dùng: tự định nghĩa 1 `T_mappingIndicatorConfig` (style, prefix, scope…) rồi
10
+ * truyền vào cả `applyMappingIndicators` (để hiện) và `stripMappingIndicators` (để dọn
11
+ * trước khi gửi server). Không cần viết lại logic highlight cho từng nghiệp vụ.
12
+ */
13
+ /** Một cột cần đánh dấu — chỉ cần biết sheet và vị trí cột (0-indexed). */
14
+ export type T_indicatorTarget = {
15
+ sheetId: string;
16
+ colIndex: number;
17
+ };
18
+ /** Định nghĩa style highlight (đúng shape style object của Univer). */
19
+ export type T_indicatorStyle = {
20
+ /** Màu nền — vd `{ rgb: '#389E0D' }` */
21
+ bg?: {
22
+ rgb: string;
23
+ };
24
+ /** Màu chữ — vd `{ rgb: '#FFFFFF' }` */
25
+ cl?: {
26
+ rgb: string;
27
+ };
28
+ /** Bold */
29
+ bl?: BooleanNumber;
30
+ /** Horizontal align (0 left, 1 right, 2 center) */
31
+ ht?: number;
32
+ /** Vertical align (0 top, 1 bottom, 2 middle) */
33
+ vt?: number;
34
+ /** Font size */
35
+ fs?: number;
36
+ };
37
+ /**
38
+ * Cấu hình cách highlight cột đã map. MỌI field đều optional — lib có default sẵn
39
+ * (xem `defaultMappingIndicatorConfig`), consumer chỉ override phần cần. Dùng chung cho
40
+ * cả apply & strip để đảm bảo đối xứng (đánh dấu rồi gỡ đúng style/prefix đã thêm).
41
+ */
42
+ export type T_mappingIndicatorConfig = {
43
+ /** Key style đánh dấu cột đã map. Tự inject vào `styles` nếu chưa có. @default 'm' */
44
+ mappedStyleId?: string;
45
+ /** Định nghĩa style cho `mappedStyleId` — chỉ dùng khi cần inject lần đầu. @default xanh #389E0D, chữ trắng, bold */
46
+ mappedStyle?: T_indicatorStyle;
47
+ /** Key style header mặc định để revert về khi gỡ đánh dấu. @default 'h' */
48
+ defaultHeaderStyleId?: string;
49
+ /**
50
+ * Phạm vi sheet xử lý (reset trước khi đánh dấu / dọn). Bỏ trống = đọc từ dữ liệu:
51
+ * xử lý TẤT CẢ sheet có trong snapshot. Chỉ truyền khi muốn giới hạn để tối ưu.
52
+ * @default mọi sheet trong snapshot
53
+ */
54
+ scopeSheetIds?: string[];
55
+ /** Prefix icon thêm vào đầu header của cột đã map. @default '● ' */
56
+ prefix?: string;
57
+ /** Row index của header. @default 0 */
58
+ headerRowIndex?: number;
59
+ /** Tự co giãn width cột theo độ dài text (gồm prefix). @default true */
60
+ autoResize?: boolean;
61
+ /** Px trung bình mỗi ký tự khi auto-resize. @default 7.5 */
62
+ charWidth?: number;
63
+ /** Padding 2 bên (px) khi auto-resize. @default 16 */
64
+ padding?: number;
65
+ };
66
+ /**
67
+ * Config mặc định của lib — consumer có thể dùng trực tiếp hoặc spread-override:
68
+ * `{ ...defaultMappingIndicatorConfig(), prefix: '★ ' }`.
69
+ */
70
+ export declare const defaultMappingIndicatorConfig: () => T_mappingIndicatorConfig;
71
+ /**
72
+ * Đánh dấu header các cột đã map: gắn style `mappedStyleId`, thêm prefix icon và
73
+ * (tùy chọn) tự nới width. Tự reset các sheet trong scope trước để mapping cũ không sót lại.
74
+ *
75
+ * @param snapshot Workbook snapshot (plain JSON). Không bị mutate — trả về bản clone.
76
+ * @param targets Danh sách cột cần đánh dấu (`{ sheetId, colIndex }`).
77
+ * @param config Cấu hình style / prefix / scope. Bỏ trống = dùng default của lib.
78
+ */
79
+ export declare const applyMappingIndicators: (snapshot: Record<string, unknown>, targets: T_indicatorTarget[], config?: T_mappingIndicatorConfig) => Record<string, unknown>;
80
+ /**
81
+ * Gỡ toàn bộ indicator ('m' → default style, xóa prefix, khôi phục width) khỏi snapshot
82
+ * — dùng trước khi gửi workbook lên server để data sạch, không chứa style UI nội bộ.
83
+ *
84
+ * @param snapshot Workbook snapshot (plain JSON). Không bị mutate — trả về bản clone.
85
+ * @param config Dùng chung config với `applyMappingIndicators` để gỡ đúng style/prefix.
86
+ * Bỏ trống = dùng default của lib.
87
+ */
88
+ export declare const stripMappingIndicators: (snapshot: Record<string, unknown>, config?: T_mappingIndicatorConfig) => Record<string, unknown>;
89
+ /**
90
+ * Mô tả 1 thao tác cấu trúc cột (do component phát qua `outColumnStructureChange`).
91
+ * `count` đã gộp trường hợp chọn NHIỀU cột cùng lúc (range span).
92
+ */
93
+ export type T_columnStructureChange = {
94
+ /** Sheet xảy ra thao tác. */
95
+ sheetId: string;
96
+ /** Loại thao tác. */
97
+ type: 'insert' | 'remove' | 'move';
98
+ /** Cột bắt đầu bị tác động (0-indexed). Với `move` = cạnh trái khối nguồn. */
99
+ startColumn: number;
100
+ /** Số cột bị tác động (≥ 1; >1 khi chọn nhiều cột). */
101
+ count: number;
102
+ /** Cột đích (cạnh trái, toạ độ GỐC trước khi dời) — CHỈ có với `move`. */
103
+ toColumn?: number;
104
+ };
105
+ /** Chuyển colIndex (0-based) → chữ cái cột kiểu Excel: 0→'A', 25→'Z', 26→'AA'… */
106
+ export declare const toColumnLetter: (index: number) => string;
107
+ /**
108
+ * Remap colIndex của danh sách mapping theo 1 `T_columnStructureChange`.
109
+ * - Item khác `sheetId` giữ nguyên.
110
+ * - Item nằm trong vùng cột bị XÓA → loại khỏi kết quả.
111
+ * - Các item còn lại được dịch index cho khớp vị trí mới.
112
+ *
113
+ * Tự cập nhật cả `colLetter` (nếu item có field này) cho khớp `colIndex` mới — consumer
114
+ * không cần map lại thủ công.
115
+ *
116
+ * @example
117
+ * this.mappings.update((list) => remapColumnIndexes(list, change));
118
+ */
119
+ export declare const remapColumnIndexes: <T extends {
120
+ sheetId: string;
121
+ colIndex: number;
122
+ colLetter?: string;
123
+ }>(items: T[], change: T_columnStructureChange) => T[];
@@ -0,0 +1,2 @@
1
+ export declare const univerLocaleEn: any;
2
+ export declare const univerLocaleVi: any;
@@ -0,0 +1,24 @@
1
+ import type { T_rangeSnapshot } from './spreadsheet.type';
2
+ /**
3
+ * Re-assert highlight cho option đang chọn sau khi Univer re-render panel (React có thể xoá class).
4
+ * Dựa trên cờ data-numfmt-selected (do setActive đặt) — không suy diễn từ DOM label.
5
+ */
6
+ export declare const syncActiveNumfmtHighlight: () => void;
7
+ /**
8
+ * Thay danh sách định dạng ngày mặc định của Univer bằng các option custom (CUSTOM_DATE_PATTERNS),
9
+ * hiển thị dưới dạng PREVIEW trực quan. Univer render panel numfmt bằng React và không expose API
10
+ * nên phải thao tác DOM trực tiếp.
11
+ *
12
+ * @param getSnapshot Lấy vùng chọn hiện tại (để áp numfmt).
13
+ * @param executeCmd Chạy Univer command.
14
+ * @param onPatternSelected Báo component pattern vừa chọn (Confirm) hoặc null (Cancel) để đồng bộ.
15
+ * @param getActiveCellFormat Đọc pattern hiện tại của cell — dùng highlight option khớp khi mở.
16
+ * @param clearPreview Xoá live-preview overlay của Univer để canvas vẽ đúng model ngay.
17
+ * @param getSampleValue Lấy giá trị THỰC (serial) của ô đại diện để label preview khớp dữ liệu cột;
18
+ * null → dùng SAMPLE_SERIAL mặc định.
19
+ * @returns hàm cleanup (gỡ mọi listener) — gọi khi teardown hoặc trước lần inject mới.
20
+ */
21
+ export declare const injectCustomDateFormats: (getSnapshot: () => T_rangeSnapshot | null, executeCmd: (cmdId: string, params: unknown) => void, onPatternSelected?: (pattern: string | null) => void, getActiveCellFormat?: () => string, clearPreview?: () => void, getSampleValue?: () => number | null, onConfirm?: () => void) => {
22
+ cleanup: () => void;
23
+ resync: () => void;
24
+ } | undefined;
@@ -0,0 +1,43 @@
1
+ /** Ngôn ngữ hiển thị của spreadsheet (toolbar, menu, numfmt panel). */
2
+ export type T_spreadsheet_locale = 'en' | 'vi';
3
+ export type T_cellFormatResult = {
4
+ sheet: string;
5
+ col: string;
6
+ colIndex: number;
7
+ header: string;
8
+ numfmt: string;
9
+ };
10
+ export type T_rangeSnapshot = {
11
+ unitId: string;
12
+ subUnitId: string;
13
+ startRow: number;
14
+ endRow: number;
15
+ startColumn: number;
16
+ endColumn: number;
17
+ };
18
+ /**
19
+ * ID của từng toolbar item trong Univer.
20
+ * Dùng làm key trong T_toolbar_menu_config để ẩn/vô hiệu hoá item.
21
+ * Tìm ID thực tế bằng cách inspect attribute `data-u-command` trên DOM element.
22
+ */
23
+ export type T_toolbar_item_id = 'univer.command.undo' | 'univer.command.redo' | 'sheet.command.set-once-format-painter' | 'sheet.command.set-range-bold' | 'sheet.command.set-range-italic' | 'sheet.command.set-range-underline' | 'sheet.command.set-range-stroke' | 'sheet.command.set-range-font-family' | 'sheet.command.set-range-fontsize' | 'sheet.command.set-range-text-color' | 'sheet.command.set-background-color' | 'sheet.command.set-border-basic' | 'sheet.command.set-horizontal-text-align' | 'sheet.command.set-vertical-text-align' | 'sheet.command.set-text-wrap' | 'sheet.command.set-text-rotation' | 'sheet.command.add-worksheet-merge' | 'sheet.command.add-worksheet-merge-all' | 'sheet.command.add-worksheet-merge-vertical' | 'sheet.command.add-worksheet-merge-horizontal' | 'sheet.command.remove-worksheet-merge' | 'sheet.command.numfmt.set.currency' | 'sheet.command.numfmt.add.decimal.command' | 'sheet.command.numfmt.subtract.decimal.command' | 'sheet.command.numfmt.set.percent' | 'sheet.operation.open.numfmt.panel' | 'formula-ui.operation.insert-function' | 'formula-ui.operation.more-functions' | 'sheet.menu.sheets-sort' | 'sheet.command.sort-range-asc' | 'sheet.command.sort-range-asc-ext' | 'sheet.command.sort-range-desc' | 'sheet.command.sort-range-desc-ext' | 'sheet.command.sort-range-custom' | 'sheet.command.smart-toggle-filter' | 'sheet.command.clear-filter-criteria' | 'sheet.command.re-calc-filter' | 'sheet.menu.data-validation' | 'data-validation.operation.open-validation-panel' | 'data-validation.command.addRuleAndOpen' | 'sheet.operation.open.conditional.formatting.panel' | 'sheet.menu.image' | 'sheet.command.insert-float-image' | 'sheet.command.insert-cell-image' | 'sheet.menu.print' | 'sheet.operation.print-open' | 'sheet.operation.open-print-grid-sidebar' | 'sheets-exchange-client.operation.exchange' | 'exchange-client.operation.import-xlsx' | 'exchange-client.operation.export-xlsx' | 'sheet.command.add-range-protection-from-toolbar' | 'sheet.operation.toggle-comment-panel' | 'sheet.operation.insert-hyper-link-toolbar' | 'ui.operation.open-find-dialog' | 'base-ui.operation.toggle-shortcut-panel' | 'sheet.toolbar.text-to-number';
24
+ /**
25
+ * Cấu hình ẩn / vô hiệu hoá từng toolbar item.
26
+ * @example
27
+ * // Ẩn bold, italic; vô hiệu hoá sort
28
+ * const config: T_toolbar_menu_config = {
29
+ * 'sheet.command.set-range-bold': { hidden: true },
30
+ * 'sheet.command.set-range-italic': { hidden: true },
31
+ * 'sheet.menu.sheets-sort': { disabled: true },
32
+ * };
33
+ */
34
+ /**
35
+ * Compatible với Univer's MenuConfig = Record<string, MenuItemConfig>.
36
+ * Dùng T_toolbar_item_id làm reference để biết các ID hợp lệ.
37
+ */
38
+ export type T_toolbar_menu_config = Record<string, {
39
+ /** Ẩn hoàn toàn item khỏi toolbar */
40
+ hidden?: boolean;
41
+ /** Vô hiệu hoá item (hiển thị nhưng không click được) */
42
+ disabled?: boolean;
43
+ }>;