@sl-material/sl-table-sheet 1.0.0-beta0

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.
File without changes
@@ -0,0 +1,117 @@
1
+ /**
2
+ * 查找替换弹窗 - 纯 TypeScript/JavaScript 实现
3
+ * 不依赖任何框架,可在任何项目中使用
4
+ */
5
+ export interface MatchPosition {
6
+ row: number;
7
+ col: number;
8
+ value: string;
9
+ }
10
+ export interface FindReplaceOptions {
11
+ container?: HTMLElement | string;
12
+ tableInstance?: any;
13
+ onSearch?: (matches: MatchPosition[]) => void;
14
+ onReplace?: (match: MatchPosition, newValue: string) => void;
15
+ selectedColumnsOnly?: boolean;
16
+ }
17
+ export declare class FindReplaceDialog {
18
+ private dialog;
19
+ private tableInstance;
20
+ private elements;
21
+ private state;
22
+ private options;
23
+ constructor(options?: FindReplaceOptions);
24
+ /**
25
+ * 初始化弹窗
26
+ */
27
+ private init;
28
+ /**
29
+ * 创建弹窗 DOM
30
+ */
31
+ private createDialog;
32
+ /**
33
+ * 绑定事件
34
+ */
35
+ private bindEvents;
36
+ /**
37
+ * 绑定拖拽事件
38
+ */
39
+ private bindDragEvents;
40
+ /**
41
+ * 注入样式
42
+ */
43
+ private injectStyles;
44
+ /**
45
+ * 解析容器
46
+ */
47
+ private resolveContainer;
48
+ /**
49
+ * 打开弹窗
50
+ */
51
+ open(): void;
52
+ /**
53
+ * 关闭弹窗
54
+ */
55
+ close(): void;
56
+ /**
57
+ * 重置状态
58
+ */
59
+ private resetState;
60
+ /**
61
+ * 清除结果显示
62
+ */
63
+ private clearResults;
64
+ /**
65
+ * 执行查找
66
+ */
67
+ private performSearch;
68
+ /**
69
+ * 高亮匹配项
70
+ */
71
+ private highlightMatch;
72
+ /**
73
+ * 查找下一个
74
+ */
75
+ findNext(): void;
76
+ /**
77
+ * 查找上一个
78
+ */
79
+ findPrevious(): void;
80
+ /**
81
+ * 替换一个
82
+ */
83
+ replaceOne(): void;
84
+ /**
85
+ * 全部替换
86
+ */
87
+ replaceAll(): void;
88
+ /**
89
+ * 显示消息
90
+ */
91
+ private showMessage;
92
+ /**
93
+ * 设置表格实例(用于表格重建后更新引用)
94
+ */
95
+ setTableInstance(tableInstance: any): void;
96
+ /**
97
+ * 设置是否只搜索选中列
98
+ */
99
+ setSelectedColumnsOnly(selectedOnly: boolean): void;
100
+ /**
101
+ * 获取是否只搜索选中列
102
+ */
103
+ getSelectedColumnsOnly(): boolean;
104
+ /**
105
+ * 设置查找文本
106
+ */
107
+ setFindText(text: string): void;
108
+ /**
109
+ * 设置替换文本
110
+ */
111
+ setReplaceText(text: string): void;
112
+ /**
113
+ * 销毁弹窗
114
+ */
115
+ destroy(): void;
116
+ }
117
+ export default FindReplaceDialog;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * 查找替换弹窗 - 纯 TypeScript/JavaScript 实现
3
+ * 不依赖任何框架,可在任何项目中使用
4
+ */
5
+ export interface MatchPosition {
6
+ row: number;
7
+ col: number;
8
+ value: string;
9
+ }
10
+ export interface FindReplaceOptions {
11
+ container?: HTMLElement | string;
12
+ tableInstance?: any;
13
+ onSearch?: (matches: MatchPosition[]) => void;
14
+ onReplace?: (match: MatchPosition, newValue: string) => void;
15
+ selectedColumnsOnly?: boolean;
16
+ }
17
+ export declare class FindReplaceDialog {
18
+ private dialog;
19
+ private tableInstance;
20
+ private elements;
21
+ private state;
22
+ private options;
23
+ constructor(options?: FindReplaceOptions);
24
+ /**
25
+ * 初始化弹窗
26
+ */
27
+ private init;
28
+ /**
29
+ * 创建弹窗 DOM
30
+ */
31
+ private createDialog;
32
+ /**
33
+ * 绑定事件
34
+ */
35
+ private bindEvents;
36
+ /**
37
+ * 绑定拖拽事件
38
+ */
39
+ private bindDragEvents;
40
+ /**
41
+ * 注入样式
42
+ */
43
+ private injectStyles;
44
+ /**
45
+ * 解析容器
46
+ */
47
+ private resolveContainer;
48
+ /**
49
+ * 打开弹窗
50
+ */
51
+ open(): void;
52
+ /**
53
+ * 关闭弹窗
54
+ */
55
+ close(): void;
56
+ /**
57
+ * 重置状态
58
+ */
59
+ private resetState;
60
+ /**
61
+ * 清除结果显示
62
+ */
63
+ private clearResults;
64
+ /**
65
+ * 执行查找
66
+ */
67
+ private performSearch;
68
+ /**
69
+ * 高亮匹配项
70
+ */
71
+ private highlightMatch;
72
+ /**
73
+ * 查找下一个
74
+ */
75
+ findNext(): void;
76
+ /**
77
+ * 查找上一个
78
+ */
79
+ findPrevious(): void;
80
+ /**
81
+ * 替换一个
82
+ */
83
+ replaceOne(): void;
84
+ /**
85
+ * 全部替换
86
+ */
87
+ replaceAll(): void;
88
+ /**
89
+ * 显示消息
90
+ */
91
+ private showMessage;
92
+ /**
93
+ * 设置表格实例(用于表格重建后更新引用)
94
+ */
95
+ setTableInstance(tableInstance: any): void;
96
+ /**
97
+ * 设置是否只搜索选中列
98
+ */
99
+ setSelectedColumnsOnly(selectedOnly: boolean): void;
100
+ /**
101
+ * 获取是否只搜索选中列
102
+ */
103
+ getSelectedColumnsOnly(): boolean;
104
+ /**
105
+ * 设置查找文本
106
+ */
107
+ setFindText(text: string): void;
108
+ /**
109
+ * 设置替换文本
110
+ */
111
+ setReplaceText(text: string): void;
112
+ /**
113
+ * 销毁弹窗
114
+ */
115
+ destroy(): void;
116
+ }
117
+ export default FindReplaceDialog;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * ExcelUtils - Excel 导入导出工具类(兼容层)
3
+ * 此文件保留用于向后兼容,新代码请使用 ./excel 模块
4
+ * @deprecated 请使用 ./excel 模块中的功能
5
+ */
6
+ export * from './excel';
@@ -0,0 +1,166 @@
1
+ import { TableSheet, TableSheetConfig } from './TableSheet';
2
+ import { FindReplaceDialog } from './Dialog';
3
+ import { Toolbar, ToolbarConfig } from './Toolbar';
4
+ import { ExcelParseOptions, ExcelParseResult } from './excel';
5
+
6
+ export interface SlTableSheetConfig extends Omit<TableSheetConfig, "container"> {
7
+ container: HTMLElement | string;
8
+ showToolbar?: boolean;
9
+ toolbar?: Partial<ToolbarConfig>;
10
+ onExport?: (format: "csv" | "excel") => void;
11
+ onRefresh?: () => void;
12
+ onExcelImport?: (data: ExcelParseResult) => void;
13
+ }
14
+ export declare class SlTableSheet {
15
+ private tableSheet;
16
+ private findReplaceDialog;
17
+ private toolbar;
18
+ private container;
19
+ private tableContainer;
20
+ private toolbarContainer;
21
+ private config;
22
+ /** Excel 单元格样式映射 */
23
+ private excelCellStyles;
24
+ constructor(config: SlTableSheetConfig);
25
+ /**
26
+ * 初始化
27
+ */
28
+ private init;
29
+ /**
30
+ * 获取容器
31
+ */
32
+ private getContainer;
33
+ /**
34
+ * 创建布局
35
+ */
36
+ private createLayout;
37
+ /**
38
+ * 创建工具栏
39
+ */
40
+ private createToolbar;
41
+ /**
42
+ * 创建表格
43
+ */
44
+ private createTable;
45
+ /**
46
+ * 创建查找替换弹窗
47
+ */
48
+ private createFindReplaceDialog;
49
+ /**
50
+ * 打开查找替换弹窗
51
+ */
52
+ openFindReplace(): void;
53
+ /**
54
+ * 冻结列
55
+ */
56
+ private freezeColumns;
57
+ /**
58
+ * 注入样式
59
+ */
60
+ private injectStyles;
61
+ /**
62
+ * 更新标题统计
63
+ */
64
+ updateTitleStats(count: number, total: number): void;
65
+ /**
66
+ * 获取 TableSheet 实例
67
+ */
68
+ getTableSheet(): TableSheet | null;
69
+ /**
70
+ * 获取表格实例
71
+ */
72
+ getTableInstance(): any;
73
+ /**
74
+ * 获取查找替换弹窗实例
75
+ */
76
+ getFindReplaceDialog(): FindReplaceDialog | null;
77
+ /**
78
+ * 设置查找替换是否只搜索选中列
79
+ */
80
+ setFindReplaceSelectedColumnsOnly(selectedOnly: boolean): void;
81
+ /**
82
+ * 更新数据
83
+ */
84
+ updateData(records: any[]): void;
85
+ /**
86
+ * 更新列配置
87
+ */
88
+ updateColumns(columns: any[]): void;
89
+ /**
90
+ * 导出数据
91
+ */
92
+ exportData(format?: "csv" | "excel"): any;
93
+ /**
94
+ * 导出数据为 Excel 流 (ArrayBuffer)
95
+ * @param options 导出选项
96
+ * @returns Excel 文件的 ArrayBuffer
97
+ */
98
+ exportToExcelStream(options?: {
99
+ filterEmptyColumns?: boolean;
100
+ }): ArrayBuffer;
101
+ /**
102
+ * 下载 Excel 文件
103
+ * @param filename 文件名(不含扩展名)
104
+ */
105
+ downloadExcel(filename?: string): void;
106
+ /**
107
+ * 解析在线 Excel 文件并显示到表格
108
+ * @param url Excel 文件的 URL 地址
109
+ * @param options 解析选项
110
+ * @returns 解析后的列配置和数据
111
+ */
112
+ loadExcelFromUrl(url: string, options?: ExcelParseOptions & {
113
+ autoDisplay?: boolean;
114
+ }): Promise<ExcelParseResult>;
115
+ /**
116
+ * 解析 Excel ArrayBuffer 并显示到表格
117
+ * @param buffer Excel 文件的 ArrayBuffer
118
+ * @param options 解析选项
119
+ * @returns 解析后的列配置和数据
120
+ */
121
+ parseExcelBuffer(buffer: ArrayBuffer, options?: ExcelParseOptions & {
122
+ autoDisplay?: boolean;
123
+ }): ExcelParseResult;
124
+ /**
125
+ * 从 File 对象解析 Excel 文件
126
+ * @param file File 对象
127
+ * @param options 解析选项
128
+ * @returns 解析后的列配置和数据
129
+ */
130
+ parseExcelFile(file: File, options?: ExcelParseOptions & {
131
+ autoDisplay?: boolean;
132
+ }): Promise<ExcelParseResult>;
133
+ /**
134
+ * 处理 Excel 导入结果
135
+ */
136
+ private handleExcelImportResult;
137
+ /**
138
+ * 重新创建表格实例
139
+ */
140
+ private recreateTable;
141
+ /**
142
+ * 更新查找替换弹窗的表格实例引用
143
+ */
144
+ private updateFindReplaceTableInstance;
145
+ /**
146
+ * 刷新表格
147
+ */
148
+ refresh(): void;
149
+ /**
150
+ * 监听事件
151
+ */
152
+ on(eventName: string, callback: Function): void;
153
+ /**
154
+ * 取消监听事件
155
+ */
156
+ off(eventName: string, callback?: Function): void;
157
+ /**
158
+ * 获取工具栏实例
159
+ */
160
+ getToolbar(): Toolbar | null;
161
+ /**
162
+ * 销毁实例
163
+ */
164
+ destroy(): void;
165
+ }
166
+ export default SlTableSheet;
@@ -0,0 +1,188 @@
1
+ /**
2
+ * 自定义组件配置接口
3
+ */
4
+ export interface CustomComponentConfig {
5
+ /** 组件渲染函数,返回 DOM 元素 */
6
+ render: (args: CustomComponentRenderArgs) => HTMLElement;
7
+ /** 组件挂载后的回调 */
8
+ onMount?: (container: HTMLElement, args: CustomComponentRenderArgs) => void;
9
+ /** 组件卸载前的回调 */
10
+ onUnmount?: (container: HTMLElement) => void;
11
+ /** 是否在点击单元格时显示组件 */
12
+ showOnClick?: boolean;
13
+ /** 组件容器样式 */
14
+ containerStyle?: Partial<CSSStyleDeclaration>;
15
+ }
16
+ /**
17
+ * 自定义组件渲染参数
18
+ */
19
+ export interface CustomComponentRenderArgs {
20
+ /** 表格实例 */
21
+ table: any;
22
+ /** 行索引 */
23
+ row: number;
24
+ /** 列索引 */
25
+ col: number;
26
+ /** 单元格值 */
27
+ value: any;
28
+ /** 原始数据 */
29
+ dataValue: any;
30
+ /** 单元格矩形区域 */
31
+ rect: {
32
+ left: number;
33
+ top: number;
34
+ width: number;
35
+ height: number;
36
+ };
37
+ /** 更新单元格值的回调 */
38
+ setValue: (newValue: any) => void;
39
+ /** 关闭组件的回调 */
40
+ close: () => void;
41
+ }
42
+ /**
43
+ * TableSheet 配置接口
44
+ */
45
+ export interface TableSheetConfig {
46
+ /** 容器元素或选择器 */
47
+ container: HTMLElement | string;
48
+ /** 列配置,支持在列中定义 customRender 实现自定义单元格渲染 */
49
+ columns?: any[];
50
+ /** 数据记录 */
51
+ records?: any[];
52
+ /** 是否显示公式栏 */
53
+ showFormulaBar?: boolean;
54
+ /** 是否显示工作表标签 */
55
+ showSheetTab?: boolean;
56
+ /** 工作表配置 */
57
+ sheets?: any[];
58
+ /** 编辑器配置 */
59
+ editors?: {
60
+ dateEditor?: any;
61
+ listEditor?: any;
62
+ customEditors?: Record<string, any>;
63
+ };
64
+ /**
65
+ * 自定义渲染器配置(保留用于扩展)
66
+ * 注意:VTable 的 customRender 应该在 columns 的每一列中配置
67
+ * 示例:columns: [{ field: 'name', customRender: (args) => ({ elements: [...] }) }]
68
+ */
69
+ customRenderers?: Record<string, any>;
70
+ /**
71
+ * 自定义交互组件配置
72
+ * 用于在单元格中渲染复杂的DOM组件(如弹出层、下拉选择等)
73
+ * 示例:customComponents: { 'store-selector': { render: (args) => createStoreSelector(args) } }
74
+ */
75
+ customComponents?: Record<string, CustomComponentConfig>;
76
+ /** 其他 VTable 选项 */
77
+ options?: any;
78
+ /** 表格就绪回调 */
79
+ onReady?: (instance: any) => void;
80
+ /** 单元格点击回调 */
81
+ onCellClick?: (args: any) => void;
82
+ /** 单元格值变化回调 */
83
+ onCellChange?: (args: any) => void;
84
+ }
85
+ export declare class TableSheet {
86
+ private sheetInstance;
87
+ private tableInstance;
88
+ private container;
89
+ private config;
90
+ private customComponentManager;
91
+ private cellMarkManager;
92
+ private eventManager;
93
+ constructor(config: TableSheetConfig, markedMap?: Map<string, {
94
+ isMarked: boolean;
95
+ comment?: string;
96
+ }>);
97
+ /**
98
+ * 初始化表格
99
+ */
100
+ private init;
101
+ /**
102
+ * 获取容器元素
103
+ */
104
+ private getContainer;
105
+ /**
106
+ * 创建表格实例
107
+ */
108
+ private createSheet;
109
+ /**
110
+ * 修改单元格值
111
+ */
112
+ changeCellValue(col: number, row: number, value: any): void;
113
+ /**
114
+ * 获取单元格值
115
+ */
116
+ getCellValue(col: number, row: number): any;
117
+ /**
118
+ * 获取选中的单元格
119
+ */
120
+ getSelectedCells(): any;
121
+ /**
122
+ * 更新数据
123
+ */
124
+ updateData(records: any[]): void;
125
+ /**
126
+ * 更新列配置
127
+ */
128
+ updateColumns(columns: any[]): void;
129
+ /**
130
+ * 添加行
131
+ */
132
+ addRow(record: any, index?: number): void;
133
+ /**
134
+ * 删除行
135
+ */
136
+ deleteRow(index: number): void;
137
+ /**
138
+ * 导出数据
139
+ */
140
+ exportData(format?: "csv" | "excel"): any;
141
+ /**
142
+ * 切换工作表
143
+ */
144
+ switchSheet(sheetKey: string): void;
145
+ /**
146
+ * 获取当前工作表
147
+ */
148
+ getActiveSheet(): any;
149
+ /**
150
+ * 获取所有工作表
151
+ */
152
+ getAllSheets(): any;
153
+ /**
154
+ * 刷新表格
155
+ */
156
+ refresh(): void;
157
+ /**
158
+ * 获取原始实例
159
+ */
160
+ getSheetInstance(): any;
161
+ getTableInstance(): any;
162
+ /**
163
+ * 为指定列设置自定义渲染函数
164
+ * @param field 列字段名
165
+ * @param customRender 自定义渲染函数
166
+ */
167
+ setColumnCustomRender(field: string, customRender: Function): void;
168
+ /**
169
+ * 获取标记映射
170
+ */
171
+ getMarkedMap(): Map<string, {
172
+ isMarked: boolean;
173
+ comment?: string;
174
+ }> | null;
175
+ /**
176
+ * 监听事件
177
+ */
178
+ on(eventName: string, callback: Function): void;
179
+ /**
180
+ * 取消监听事件
181
+ */
182
+ off(eventName: string, callback?: Function): void;
183
+ /**
184
+ * 销毁实例
185
+ */
186
+ destroy(): void;
187
+ }
188
+ export default TableSheet;
@@ -0,0 +1,110 @@
1
+
2
+ export interface ToolbarConfig {
3
+ container?: HTMLElement | string;
4
+ title?: string;
5
+ count?: number;
6
+ total?: number;
7
+ hint?: string;
8
+ freezeCount?: number;
9
+ showErrorList?: boolean;
10
+ /** 左侧自定义内容,可以是 HTMLElement 或返回 HTMLElement 的函数 */
11
+ leftSlot?: HTMLElement | (() => HTMLElement) | null;
12
+ buttons?: {
13
+ search?: boolean;
14
+ freeze?: boolean;
15
+ export?: boolean;
16
+ refresh?: boolean;
17
+ list?: boolean;
18
+ };
19
+ onSearchClick?: () => void;
20
+ onFreezeChange?: (count: number) => void;
21
+ onListChange?: (checked: boolean) => void;
22
+ }
23
+ export declare class Toolbar {
24
+ private container;
25
+ private toolbarElement;
26
+ private config;
27
+ private elements;
28
+ constructor(config: ToolbarConfig);
29
+ /**
30
+ * 初始化
31
+ */
32
+ private init;
33
+ /**
34
+ * 获取容器
35
+ */
36
+ private getContainer;
37
+ /**
38
+ * 创建工具栏
39
+ */
40
+ private createToolbar;
41
+ /**
42
+ * 创建左侧区域(空容器,内容由调用者通过 leftSlot 插入)
43
+ */
44
+ private createLeftSection;
45
+ /**
46
+ * 创建右侧区域
47
+ */
48
+ private createRightSection;
49
+ /**
50
+ * 创建按钮
51
+ */
52
+ private createButton;
53
+ /**
54
+ * 创建冻结列选择器(标题 + 数字输入框 + 上下箭头)
55
+ */
56
+ private createFreezeButton;
57
+ /**
58
+ * 格式化数字(添加千分位)
59
+ */
60
+ private formatNumber;
61
+ /**
62
+ * 注入样式
63
+ */
64
+ private injectStyles;
65
+ /**
66
+ * 更新标题
67
+ */
68
+ updateTitle(title: string): void;
69
+ /**
70
+ * 更新统计数据
71
+ */
72
+ updateStats(count: number, total: number): void;
73
+ /**
74
+ * 更新提示信息
75
+ */
76
+ updateHint(hint: string): void;
77
+ /**
78
+ * 更新冻结列数
79
+ */
80
+ updateFreezeCount(count: number): void;
81
+ /**
82
+ * 更新显示错误列状态
83
+ */
84
+ updateShowErrorList(checked: boolean): void;
85
+ /**
86
+ * 显示工具栏
87
+ */
88
+ show(): void;
89
+ /**
90
+ * 隐藏工具栏
91
+ */
92
+ hide(): void;
93
+ /**
94
+ * 获取工具栏元素
95
+ */
96
+ getElement(): HTMLElement | null;
97
+ /**
98
+ * 更新左侧插槽内容
99
+ */
100
+ setLeftSlot(content: HTMLElement | (() => HTMLElement) | null): void;
101
+ /**
102
+ * 获取左侧区域元素
103
+ */
104
+ getLeftSection(): HTMLElement | null;
105
+ /**
106
+ * 销毁工具栏
107
+ */
108
+ destroy(): void;
109
+ }
110
+ export default Toolbar;
@@ -0,0 +1,6 @@
1
+
2
+ export declare const getHighlightStyle: (_styleArg: any, _col: any) => {
3
+ bgColor: string;
4
+ color: string;
5
+ marked: any;
6
+ };