@canvas-components/list-table 0.2.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 canvas-components contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,198 @@
1
+ # @canvas-components/list-table
2
+
3
+ `@canvas-components/list-table` 是整个项目的纯原生 Canvas 表格核心包,不依赖 React,可直接在 DOM 容器中创建高性能表格实例,也可作为适配层的底层引擎使用。
4
+
5
+ ## 功能作用
6
+
7
+ - 原生 Canvas 表格渲染
8
+ - 大数据量虚拟滚动
9
+ - 多级表头、固定列、汇总行
10
+ - 排序、过滤、自动合并单元格
11
+ - 行选择、展开树表、右键菜单
12
+ - 单元格编辑、校验、tooltip、图片预览
13
+ - 列宽调整、列拖拽、行拖拽、轮播滚动
14
+ - 内建二维码、条形码、进度、图表、评分、按钮等单元格内容
15
+
16
+ ## 安装方法
17
+
18
+ ```bash
19
+ pnpm add @canvas-components/list-table
20
+ ```
21
+
22
+ 最低环境要求:
23
+
24
+ - `Node.js >= 18.12.0`
25
+ - `pnpm >= 9.0.0`
26
+
27
+ ## 使用方法
28
+
29
+ ```ts
30
+ import { ListTable } from "@canvas-components/list-table";
31
+
32
+ const container = document.querySelector("#table") as HTMLElement;
33
+
34
+ const table = new ListTable(container, {
35
+ type: "list",
36
+ width: "100%",
37
+ height: 480,
38
+ rowKey: "id",
39
+ columns: [
40
+ { key: "name", title: "姓名", dataIndex: "name", width: 180 },
41
+ { key: "age", title: "年龄", dataIndex: "age", width: 120, align: "right" },
42
+ ],
43
+ dataSource: [
44
+ { id: 1, name: "张三", age: 28 },
45
+ { id: 2, name: "李四", age: 31 },
46
+ ],
47
+ });
48
+
49
+ table.mount();
50
+ ```
51
+
52
+ ## 属性说明
53
+
54
+ ### 实例配置 `ListTableOptions`
55
+
56
+ | 属性 | 类型 | 说明 |
57
+ | --- | --- | --- |
58
+ | `type` | `"list"` | 表格类型,当前稳定支持列表表格 |
59
+ | `rowKey` | `string \| number \| Array<string \| number> \| ((record, index) => string \| number)` | 行主键解析规则 |
60
+ | `columns` | `ListTableColumn[]` | 列配置集合 |
61
+ | `width` | `number \| string` | 表格宽度 |
62
+ | `height` | `number \| string` | 表格高度 |
63
+ | `dataSource` | `RecordType[]` | 表格数据源 |
64
+ | `emptyText` | `string` | 空状态文案 |
65
+ | `theme` | `Partial<ListTableTheme>` | 主题覆盖 |
66
+ | `striped` | `boolean` | 是否开启斑马纹 |
67
+ | `highlightMode` | `"cell" \| "row" \| "column" \| "cross"` | 点击高亮模式 |
68
+ | `contextMenu` | `false \| ListTableContextMenuOptions` | 右键菜单配置 |
69
+ | `rowHeight` | `number \| "auto"` | 行高 |
70
+ | `headerRowHeight` | `number` | 表头单行高度 |
71
+ | `summaryRowHeight` | `number` | 汇总行高度 |
72
+ | `overscanRowCount` | `number` | 虚拟滚动预渲染行数 |
73
+ | `query` | `ListTableQueryOptions` | 排序、过滤、合并单元格配置 |
74
+ | `rowSelection` | `ListTableRowSelectionOptions` | 行选择配置 |
75
+ | `expandable` | `ListTableExpandableOptions` | 树表 / 展开行配置 |
76
+ | `pagination` | `false \| ListTablePaginationOptions` | 分页或滚动加载配置 |
77
+ | `scrollbar` | `ListTableScrollbarOptions` | 滚动条配置 |
78
+ | `carouselScroll` | `ListTableCarouselScrollOptions` | 自动轮播滚动配置 |
79
+ | `stretchColumns` | `boolean` | 列总宽不足时是否拉伸补齐 |
80
+ | `resizable` | `boolean` | 是否开启列宽拖拽 |
81
+ | `storageKey` | `string` | 持久化键 |
82
+ | `draggable` | `boolean` | 是否开启列拖拽排序 |
83
+ | `tableId` | `string` | 表格唯一标识 |
84
+ | `rowDrag` | `ListTableRowDragOptions` | 行拖拽配置 |
85
+ | `debug` | `ListTableDebugOptions` | 调试配置 |
86
+
87
+ ### 列配置 `ListTableColumn`
88
+
89
+ | 属性 | 类型 | 说明 |
90
+ | --- | --- | --- |
91
+ | `key` | `string` | 列唯一标识 |
92
+ | `title` | `string` | 列标题 |
93
+ | `dataIndex` | `string \| number \| Array<string \| number>` | 取值路径 |
94
+ | `children` | `ListTableColumn[]` | 子列,用于多级表头 |
95
+ | `width` | `number` | 列宽 |
96
+ | `minWidth` / `maxWidth` | `number` | 允许调整的最小 / 最大列宽 |
97
+ | `align` | `"left" \| "center" \| "right"` | 内容对齐 |
98
+ | `fixed` | `"left" \| "right"` | 固定列 |
99
+ | `hidden` | `boolean` | 是否隐藏 |
100
+ | `ellipsis` | `boolean` | 超出是否省略 |
101
+ | `editable` | `boolean \| (text, record, index) => boolean` | 是否允许编辑 |
102
+ | `formItemProps` | `ListTableFormItemPropsConfig` | 编辑器配置 |
103
+ | `resizable` | `boolean` | 单列是否允许调整宽度 |
104
+ | `draggable` | `boolean` | 单列是否允许拖拽 |
105
+ | `allowSort` | `boolean` | 是否开启排序 |
106
+ | `allowFilter` | `boolean` | 是否开启过滤 |
107
+ | `filterOptions` | `ListTableFilterOption[]` | 精确过滤选项 |
108
+ | `cellType` | `ListTableCellContent["type"]` | 内建单元格类型 |
109
+ | `moneyFormat` | `ListTableMoneyFormatOptions` | 金额格式配置,仅在 `cellType: "money"` 时生效 |
110
+ | `render` | `(value, record, rowIndex, column) => ...` | 自定义渲染 |
111
+ | `onCell` | `(value, record, rowIndex, column) => { rowSpan?: number; colSpan?: number }` | 单元格跨度控制 |
112
+ | `summary` | `boolean \| ListTableSummaryConfig` | 汇总配置 |
113
+ | `summaryTitle` | `string` | 汇总标题文本 |
114
+
115
+ ### 常见嵌套能力
116
+
117
+ | 配置 | 说明 |
118
+ | --- | --- |
119
+ | `query` | 排序、筛选、远程查询、自动合并单元格 |
120
+ | `rowSelection` | checkbox / radio 行选择 |
121
+ | `expandable` | 树形数据、详情展开、展开列 |
122
+ | `pagination` | 按钮分页或滚动加载 |
123
+ | `rowDrag` | 行拖拽、跨表拖拽、拖放回调 |
124
+ | `contextMenu` | 复制、导出、冻结、列显示、密度、缩放等菜单能力 |
125
+
126
+ ## 方法说明
127
+
128
+ | 方法 | 签名 | 说明 |
129
+ | --- | --- | --- |
130
+ | `constructor` | `new ListTable(container, options)` | 创建实例 |
131
+ | `mount` | `() => void` | 挂载表格 |
132
+ | `updateOptions` | `(options) => void` | 更新配置并刷新 |
133
+ | `getDebugSnapshot` | `() => ListTableDebugSnapshot \| null` | 获取调试快照 |
134
+ | `validate` | `() => Promise<RecordType[]>` | 手动触发校验,失败时抛出 `ListTableValidationFailure` |
135
+ | `exportXlsx` | `() => void` | 异步导出全部原始数据为 XLSX |
136
+ | `scrollTo` | `(options: ListTableScrollToOptions) => void` | 滚动到指定行 |
137
+ | `destroy` | `() => void` | 销毁实例 |
138
+
139
+ ## 内建单元格内容
140
+
141
+ `render` 支持直接返回结构化内容,内建类型包括:
142
+
143
+ - `text`
144
+ - `money`
145
+ - `image`
146
+ - `qrcode`
147
+ - `barcode`
148
+ - `progress`
149
+ - `chart`
150
+ - `rate`
151
+ - `button`
152
+ - `tag`
153
+ - `color`
154
+ - `icon`
155
+ - `checkbox`
156
+ - `radio`
157
+ - `switch`
158
+ - `link`
159
+
160
+ ### 金额单元格示例
161
+
162
+ ```ts
163
+ const columns = [
164
+ {
165
+ title: "金额",
166
+ dataIndex: "amount",
167
+ width: 140,
168
+ align: "right",
169
+ cellType: "money",
170
+ moneyFormat: {
171
+ symbol: "¥",
172
+ thousandsSeparator: true,
173
+ decimalPlaces: 2,
174
+ },
175
+ },
176
+ {
177
+ title: "结算金额",
178
+ dataIndex: "settlementAmount",
179
+ width: 160,
180
+ align: "right",
181
+ render(value) {
182
+ return {
183
+ type: "money",
184
+ value: value as number,
185
+ symbol: "$",
186
+ thousandsSeparator: ",",
187
+ decimalPlaces: 1,
188
+ };
189
+ },
190
+ },
191
+ ];
192
+ ```
193
+
194
+ ## 推荐搭配
195
+
196
+ - 原生 DOM 场景:直接使用 `ListTable`
197
+ - React 场景:优先使用 `@canvas-components/react-list-table`
198
+ - 二维码 / 条形码 / 图表单元格:配合 `@canvas-components/qrcode`、`@canvas-components/barcode`、`@canvas-components/chart`