stk-table-vue 0.4.15 → 0.5.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/README.md CHANGED
@@ -10,11 +10,6 @@ repo:
10
10
 
11
11
  [<span style="font-size: 16px;font-weight: bold;">Online Demo</span>](https://stackblitz.com/edit/vitejs-vite-ad91hh?file=src%2FDemo%2Findex.vue)
12
12
 
13
- ## Bug TODO:
14
- * [x] props.dataSource 为 shallowRef 时,高亮行不生效。(bug:2024.02.21)(resolved:0.2.3)
15
- * [x] 右侧固定列列宽拖动目标。(v0.4.10)
16
- * [] 惯性滚动优化。
17
-
18
13
  ## Feature TODO:
19
14
  * [x] 高亮行,单元格。
20
15
  - [x] 使用 `Web Animations API` 实现高亮。(`v0.3.4` 变更为默认值)
@@ -27,6 +22,7 @@ repo:
27
22
  - [x] 固定列阴影。
28
23
  - [x] 多级表头固定列阴影。
29
24
  - [x] sticky column 动态计算阴影位置。(`v0.4.0`)
25
+ * [x] 列展开。(`v0.5.0`)
30
26
  * [] 列筛选。
31
27
  * [x] 斑马纹。
32
28
  * [x] 拖动更改列顺序。
@@ -44,6 +40,7 @@ repo:
44
40
  - [x] `props.optimizeVue2Scroll` 优化vue2虚拟滚动流畅度。(`v0.2.0`)
45
41
  * [x] 支持配置序号列。`StkTableColumn['type']`。(`v0.3.0`)
46
42
  * [x] `props.cellHover`单元格悬浮样式。(`v0.3.2`)
43
+ * [] 惯性滚动优化。
47
44
 
48
45
 
49
46
  ## Usage
@@ -176,16 +173,29 @@ export type StkProps = {
176
173
  /** 单元格再次点击否可以取消选中 (cellActive=true)*/
177
174
  selectedCellRevokable?: boolean;
178
175
  /** 表头是否可拖动。支持回调函数。 */
179
- headerDrag?: boolean | ((col: StkTableColumn<DT>) => boolean);
176
+ headerDrag?:
177
+ | boolean
178
+ | {
179
+ /**
180
+ * 列交换模式
181
+ * - none - 不做任何事
182
+ * - insert - 插入(默认值)
183
+ * - swap - 交换
184
+ */
185
+ mode?: 'none' | 'insert' | 'swap';
186
+ /** 禁用拖动的列 */
187
+ disabled?: (col: StkTableColumn<DT>) => boolean;
188
+ };
180
189
  /**
181
190
  * 给行附加className<br>
182
191
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
183
192
  */
184
193
  rowClassName?: (row: any, i: number) => string;
185
194
  /**
186
- * 列宽是否可拖动<br>
195
+ * 列宽是否可拖动(需要设置v-model:columns)<br>
187
196
  * **不要设置**列minWidth,**必须**设置width<br>
188
197
  * 列宽拖动时,每一列都必须要有width,且minWidth/maxWidth不生效。table width会变为"fit-content"。
198
+ * - 会自动更新props.columns中的with属性
189
199
  */
190
200
  colResizable?: boolean;
191
201
  /** 可拖动至最小的列宽 */
@@ -237,6 +247,14 @@ export type StkProps = {
237
247
  /** 序号列起始下标 用于适配分页 */
238
248
  startIndex?: number;
239
249
  };
250
+ /** 展开行配置 */
251
+ expandConfig?: {
252
+ height?: number;
253
+ };
254
+ /** 列拖动配置 */
255
+ dragRowConfig?: {
256
+ mode?: 'none' | 'insert' | 'swap';
257
+ };
240
258
  /**
241
259
  * 固定头,固定列实现方式。
242
260
  * [非响应式]
@@ -349,11 +367,25 @@ export type StkProps = {
349
367
  * 列宽变动时触发
350
368
  */
351
369
  (e: 'col-resize', cols: StkTableColumn<DT>): void;
370
+ /**
371
+ * 展开行触发
372
+ * ```( data: { expanded: boolean; row: DT; col: StkTableColumn<DT> })```
373
+ */
374
+ (e: 'toggle-row-expand', data: { expanded: boolean; row: DT; col: StkTableColumn<DT> | null }): void;
352
375
  /** v-model:columns col resize 时更新宽度*/
353
376
  (e: 'update:columns', cols: StkTableColumn<DT>[]): void;
354
377
  }
355
378
  ```
356
379
 
380
+ #### Slots
381
+
382
+ | slots | props | describe |
383
+ | ---- | ---- | ---- |
384
+ | `tableHeader` | `{col}` | table header slot |
385
+ | `empty` | --| no data status |
386
+ | `expand` | `{col, row}` | expand row |
387
+
388
+
357
389
  #### Expose
358
390
  ```js
359
391
  defineExpose({
@@ -383,6 +415,8 @@ defineExpose({
383
415
  scrollTo,
384
416
  /** 获取表格数据 */
385
417
  getTableData,
418
+ /** 设置展开行*/
419
+ setRowExpand,
386
420
  });
387
421
  ```
388
422
 
@@ -390,11 +424,18 @@ defineExpose({
390
424
  ``` ts
391
425
  type Sorter<T> = boolean | ((data: T[], option: { order: Order; column: any }) => T[]);
392
426
  export type StkTableColumn<T extends Record<string, any>> = {
427
+ /**
428
+ * 用于区分相同dataIndex 的列。
429
+ * 需要自行配置colKey="(col: StkTableColumn<any>) => col.key ?? col.dataIndex"
430
+ */
431
+ key?: any;
393
432
  /**
394
433
  * 列类型
395
434
  * - seq 序号列
435
+ * - expand 展开列
436
+ * - dragRow 拖拽列(使用sktTableRef.getTableData 获取改变后的顺序)
396
437
  */
397
- type?: 'seq';
438
+ type?: 'seq' | 'expand' | 'dragRow';
398
439
  /** 取值id */
399
440
  dataIndex: keyof T & string;
400
441
  /** 表头文字 */
@@ -1,11 +1,11 @@
1
- import { HighlightConfig, Order, SeqConfig, SortConfig, SortOption, SortState, StkTableColumn, UniqKeyProp } from './types/index';
1
+ import { DragRowConfig, ExpandConfig, HeaderDragConfig, HighlightConfig, Order, PrivateRowDT, SeqConfig, SortConfig, SortOption, SortState, StkTableColumn, UniqKeyProp } from './types/index';
2
2
 
3
3
  /** Generic stands for DataType */
4
- type DT = any;
4
+ type DT = any & PrivateRowDT;
5
5
  /**
6
6
  * 选中一行
7
7
  * @param {string} rowKeyOrRow selected rowKey, undefined to unselect
8
- * @param {boolean} option.silent if emit current-change. default:false(not emit `current-change`)
8
+ * @param {boolean} option.silent if set true not emit `current-change`. default:false
9
9
  */
10
10
  declare function setCurrentRow(rowKeyOrRow: string | undefined | DT, option?: {
11
11
  silent: boolean;
@@ -34,18 +34,28 @@ declare function setSorter(dataIndex: string, order: Order, option?: {
34
34
  silent?: boolean;
35
35
  sort?: boolean;
36
36
  }): any[];
37
- /** 重置排序 */
38
37
  declare function resetSorter(): void;
39
38
  /**
40
- * 设置滚动条位置
41
- * @param top null 则不变动位置
42
- * @param left null 则不变动位置
39
+ * set scroll bar position
40
+ * @param top null to not change
41
+ * @param left null to not change
43
42
  */
44
43
  declare function scrollTo(top?: number | null, left?: number | null): void;
45
- /** 获取当前状态的表格数据 */
44
+ /** get current table data */
46
45
  declare function getTableData(): any[];
47
- /** 获取当前排序列的信息 */
46
+ /** get current sort info */
48
47
  declare function getSortColumns(): Partial<SortState<DT>>[];
48
+ /**
49
+ *
50
+ * @param rowKeyOrRow rowKey or row
51
+ * @param expand expand or collapse
52
+ * @param data { col?: StkTableColumn<DT> }
53
+ * @param data.silent if set true, not emit `toggle-row-expand`, default:false
54
+ */
55
+ declare function setRowExpand(rowKeyOrRow: string | undefined | DT, expand?: boolean, data?: {
56
+ col?: StkTableColumn<DT>;
57
+ silent?: boolean;
58
+ }): void;
49
59
  declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
50
60
  width?: string | undefined;
51
61
  /** 最小表格宽度 */
@@ -106,16 +116,17 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
106
116
  /** 单元格再次点击否可以取消选中 (cellActive=true)*/
107
117
  selectedCellRevokable?: boolean | undefined;
108
118
  /** 表头是否可拖动。支持回调函数。 */
109
- headerDrag?: boolean | ((col: StkTableColumn<any>) => boolean) | undefined;
119
+ headerDrag?: HeaderDragConfig | undefined;
110
120
  /**
111
121
  * 给行附加className<br>
112
122
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
113
123
  */
114
124
  rowClassName?: ((row: any, i: number) => string) | undefined;
115
125
  /**
116
- * 列宽是否可拖动<br>
126
+ * 列宽是否可拖动(需要设置v-model:columns)<br>
117
127
  * **不要设置**列minWidth,**必须**设置width<br>
118
128
  * 列宽拖动时,每一列都必须要有width,且minWidth/maxWidth不生效。table width会变为"fit-content"。
129
+ * - 会自动更新props.columns中的with属性
119
130
  */
120
131
  colResizable?: boolean | undefined;
121
132
  /** 可拖动至最小的列宽 */
@@ -146,6 +157,10 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
146
157
  highlightConfig?: HighlightConfig | undefined;
147
158
  /** 序号列配置 */
148
159
  seqConfig?: SeqConfig | undefined;
160
+ /** 展开行配置 */
161
+ expandConfig?: ExpandConfig | undefined;
162
+ /** 列拖动配置 */
163
+ dragRowConfig?: DragRowConfig | undefined;
149
164
  /**
150
165
  * 固定头,固定列实现方式。(非响应式)
151
166
  *
@@ -206,6 +221,8 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
206
221
  hideHeaderTitle: boolean;
207
222
  highlightConfig: () => {};
208
223
  seqConfig: () => {};
224
+ expandConfig: () => {};
225
+ dragRowConfig: () => {};
209
226
  cellFixedMode: string;
210
227
  smoothScroll: boolean;
211
228
  }>, {
@@ -246,6 +263,8 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
246
263
  scrollTo: typeof scrollTo;
247
264
  /** @see {@link getTableData} */
248
265
  getTableData: typeof getTableData;
266
+ /** @see {@link setRowExpand} */
267
+ setRowExpand: typeof setRowExpand;
249
268
  }, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
250
269
  "sort-change": (col: StkTableColumn<any> | null, order: Order, data: any[], sortConfig: SortConfig<any>) => void;
251
270
  "row-click": (ev: MouseEvent, row: any) => void;
@@ -273,7 +292,13 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
273
292
  "col-order-change": (dragStartKey: string, targetColKey: string) => void;
274
293
  "th-drag-start": (dragStartKey: string) => void;
275
294
  "th-drop": (targetColKey: string) => void;
295
+ "row-order-change": (dragStartKey: string, targetRowKey: string) => void;
276
296
  "col-resize": (cols: StkTableColumn<any>) => void;
297
+ "toggle-row-expand": (data: {
298
+ expanded: boolean;
299
+ row: any;
300
+ col: StkTableColumn<any> | null;
301
+ }) => void;
277
302
  "update:columns": (cols: StkTableColumn<any>[]) => void;
278
303
  }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
279
304
  width?: string | undefined;
@@ -335,16 +360,17 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
335
360
  /** 单元格再次点击否可以取消选中 (cellActive=true)*/
336
361
  selectedCellRevokable?: boolean | undefined;
337
362
  /** 表头是否可拖动。支持回调函数。 */
338
- headerDrag?: boolean | ((col: StkTableColumn<any>) => boolean) | undefined;
363
+ headerDrag?: HeaderDragConfig | undefined;
339
364
  /**
340
365
  * 给行附加className<br>
341
366
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
342
367
  */
343
368
  rowClassName?: ((row: any, i: number) => string) | undefined;
344
369
  /**
345
- * 列宽是否可拖动<br>
370
+ * 列宽是否可拖动(需要设置v-model:columns)<br>
346
371
  * **不要设置**列minWidth,**必须**设置width<br>
347
372
  * 列宽拖动时,每一列都必须要有width,且minWidth/maxWidth不生效。table width会变为"fit-content"。
373
+ * - 会自动更新props.columns中的with属性
348
374
  */
349
375
  colResizable?: boolean | undefined;
350
376
  /** 可拖动至最小的列宽 */
@@ -375,6 +401,10 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
375
401
  highlightConfig?: HighlightConfig | undefined;
376
402
  /** 序号列配置 */
377
403
  seqConfig?: SeqConfig | undefined;
404
+ /** 展开行配置 */
405
+ expandConfig?: ExpandConfig | undefined;
406
+ /** 列拖动配置 */
407
+ dragRowConfig?: DragRowConfig | undefined;
378
408
  /**
379
409
  * 固定头,固定列实现方式。(非响应式)
380
410
  *
@@ -435,6 +465,8 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
435
465
  hideHeaderTitle: boolean;
436
466
  highlightConfig: () => {};
437
467
  seqConfig: () => {};
468
+ expandConfig: () => {};
469
+ dragRowConfig: () => {};
438
470
  cellFixedMode: string;
439
471
  smoothScroll: boolean;
440
472
  }>>> & {
@@ -445,8 +477,9 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
445
477
  "onUpdate:columns"?: ((cols: StkTableColumn<any>[]) => any) | undefined;
446
478
  "onCol-resize"?: ((cols: StkTableColumn<any>) => any) | undefined;
447
479
  "onTh-drag-start"?: ((dragStartKey: string) => any) | undefined;
448
- "onCol-order-change"?: ((dragStartKey: string, targetColKey: string) => any) | undefined;
449
480
  "onTh-drop"?: ((targetColKey: string) => any) | undefined;
481
+ "onCol-order-change"?: ((dragStartKey: string, targetColKey: string) => any) | undefined;
482
+ "onRow-order-change"?: ((dragStartKey: string, targetRowKey: string) => any) | undefined;
450
483
  "onSort-change"?: ((col: StkTableColumn<any> | null, order: Order, data: any[], sortConfig: SortConfig<any>) => any) | undefined;
451
484
  "onRow-click"?: ((ev: MouseEvent, row: any) => any) | undefined;
452
485
  "onCurrent-change"?: ((ev: MouseEvent | null, row: any, data: {
@@ -466,6 +499,11 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
466
499
  "onCell-mouseover"?: ((ev: MouseEvent, row: any, col: StkTableColumn<any>) => any) | undefined;
467
500
  "onHeader-cell-click"?: ((ev: MouseEvent, col: StkTableColumn<any>) => any) | undefined;
468
501
  "onScroll-x"?: ((ev: Event) => any) | undefined;
502
+ "onToggle-row-expand"?: ((data: {
503
+ expanded: boolean;
504
+ row: any;
505
+ col: StkTableColumn<any> | null;
506
+ }) => any) | undefined;
469
507
  }, {
470
508
  width: string;
471
509
  minWidth: string;
@@ -473,6 +511,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
473
511
  rowHeight: number;
474
512
  headerRowHeight: number | null;
475
513
  headless: boolean;
514
+ colKey: UniqKeyProp;
476
515
  stripe: boolean;
477
516
  fixedMode: boolean;
478
517
  theme: "light" | "dark";
@@ -484,7 +523,6 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
484
523
  columns: StkTableColumn<any>[];
485
524
  dataSource: any[];
486
525
  rowKey: UniqKeyProp;
487
- colKey: UniqKeyProp;
488
526
  emptyCellText: string | ((option: {
489
527
  row: any;
490
528
  col: StkTableColumn<any>;
@@ -498,7 +536,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
498
536
  cellHover: boolean;
499
537
  cellActive: boolean;
500
538
  selectedCellRevokable: boolean;
501
- headerDrag: boolean | ((col: StkTableColumn<any>) => boolean);
539
+ headerDrag: HeaderDragConfig;
502
540
  rowClassName: (row: any, i: number) => string;
503
541
  colResizable: boolean;
504
542
  colMinWidth: number;
@@ -510,12 +548,18 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
510
548
  hideHeaderTitle: boolean | string[];
511
549
  highlightConfig: HighlightConfig;
512
550
  seqConfig: SeqConfig;
551
+ expandConfig: ExpandConfig;
552
+ dragRowConfig: DragRowConfig;
513
553
  cellFixedMode: "sticky" | "relative";
514
554
  smoothScroll: boolean;
515
555
  }, {}>, {
516
556
  tableHeader?(_: {
517
557
  col: StkTableColumn<any>;
518
558
  }): any;
559
+ expand?(_: {
560
+ row: any;
561
+ col: any;
562
+ }): any;
519
563
  empty?(_: {}): any;
520
564
  }>;
521
565
  export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -2,7 +2,7 @@ export declare const DEFAULT_COL_WIDTH = "100";
2
2
  export declare const DEFAULT_TABLE_HEIGHT = 100;
3
3
  export declare const DEFAULT_TABLE_WIDTH = 200;
4
4
  export declare const DEFAULT_ROW_HEIGHT = 28;
5
- /** 高亮背景色 */
5
+ /** highlight background */
6
6
  export declare const HIGHLIGHT_COLOR: {
7
7
  light: {
8
8
  from: string;
@@ -13,16 +13,15 @@ export declare const HIGHLIGHT_COLOR: {
13
13
  to: string;
14
14
  };
15
15
  };
16
- /** 高亮持续时间 */
17
16
  export declare const HIGHLIGHT_DURATION = 2000;
18
- /** 高亮变更频率 */
17
+ /** highlight change frequency 1000/30 -> 30FPS */
19
18
  export declare const HIGHLIGHT_FREQ: number;
20
- /** 高亮行class */
21
19
  export declare const HIGHLIGHT_ROW_CLASS = "highlight-row";
22
- /** 高连单元格class */
23
20
  export declare const HIGHLIGHT_CELL_CLASS = "highlight-cell";
24
- /** 低版本sticky兼容模式 */
21
+ /** legacy sticky compatible mode */
25
22
  export declare const IS_LEGACY_MODE: boolean;
26
- /** 默认props.smoothDefault */
23
+ /** default props.smoothDefault */
27
24
  export declare const DEFAULT_SMOOTH_SCROLL: boolean;
28
25
  export declare const STK_ID_PREFIX = "stk";
26
+ /** expanded row key prefix */
27
+ export declare const EXPANDED_ROW_KEY_PREFIX = "expanded-";
@@ -1,4 +1,4 @@
1
- import { Component, ConcreteComponent, VNode } from 'vue';
1
+ import { Component, ConcreteComponent } from 'vue';
2
2
 
3
3
  /** 排序方式,asc-正序,desc-倒序,null-默认顺序 */
4
4
  export type Order = null | 'asc' | 'desc';
@@ -13,22 +13,18 @@ export type CustomCellProps<T extends Record<string, any>> = {
13
13
  cellValue: any;
14
14
  rowIndex: number;
15
15
  colIndex: number;
16
+ /**
17
+ * 当前行是否展开
18
+ * - 不展开: null
19
+ * - 展开: 返回column配置
20
+ */
21
+ expanded?: PrivateRowDT['__EXPANDED__'];
16
22
  };
17
- /**
18
- * $*$自定义单元格渲染函数
19
- * @deprecated
20
- */
21
- export type CustomCellFunc<T extends Record<string, any>> = (props: CustomCellProps<T>) => VNode;
22
23
  export type CustomHeaderCellProps<T extends Record<string, any>> = {
23
24
  col: StkTableColumn<T>;
24
25
  rowIndex: number;
25
26
  colIndex: number;
26
27
  };
27
- /**
28
- * $*$自定义表头渲染函数
29
- * @deprecated
30
- */
31
- export type CustomHeaderCellFunc<T extends Record<string, any>> = (props: CustomHeaderCellProps<T>) => VNode;
32
28
  /**
33
29
  * 自定义渲染单元格
34
30
  *
@@ -41,11 +37,18 @@ export type CustomHeaderCellFunc<T extends Record<string, any>> = (props: Custom
41
37
  export type CustomCell<T extends CustomCellProps<U> | CustomHeaderCellProps<U>, U extends Record<string, any>> = ConcreteComponent<T> | Exclude<Component<Partial<T>>, ConcreteComponent> | string;
42
38
  /** 表格列配置 */
43
39
  export type StkTableColumn<T extends Record<string, any>> = {
40
+ /**
41
+ * 用于区分相同dataIndex 的列。
42
+ * 需要自行配置colKey="(col: StkTableColumn<any>) => col.key ?? col.dataIndex"
43
+ */
44
+ key?: any;
44
45
  /**
45
46
  * 列类型
46
47
  * - seq 序号列
48
+ * - expand 展开列
49
+ * - dragRow 拖拽列(使用sktTableRef.getTableData 获取改变后的顺序)
47
50
  */
48
- type?: 'seq';
51
+ type?: 'seq' | 'expand' | 'dragRow';
49
52
  /** 取值id */
50
53
  dataIndex: keyof T & string;
51
54
  /** 表头文字 */
@@ -96,23 +99,44 @@ export type StkTableColumn<T extends Record<string, any>> = {
96
99
  customHeaderCell?: CustomCell<CustomHeaderCellProps<T>, T>;
97
100
  /** 二级表头 */
98
101
  children?: StkTableColumn<T>[];
99
- /** private 父节点引用 */
102
+ };
103
+ /** private StkTableColumn type. Add some private key */
104
+ export type PrivateStkTableColumn<T extends Record<string, any>> = StkTableColumn<T> & {
105
+ /**
106
+ * 父节点引用
107
+ * @private
108
+ */
100
109
  __PARENT__?: StkTableColumn<T> | null;
101
- /** private 保存计算的宽度。横向虚拟滚动用。 */
110
+ /**
111
+ * 保存计算的宽度。横向虚拟滚动用。
112
+ * @private
113
+ */
102
114
  __WIDTH__?: number;
103
115
  };
116
+ /** private row keys */
117
+ export type PrivateRowDT = {
118
+ /**
119
+ * Only expanded row will add this key
120
+ *
121
+ * If user define the `__ROW_KEY__` in table data, this value will be used as the row key
122
+ * @private
123
+ */
124
+ __ROW_KEY__: string;
125
+ /**
126
+ * if row expanded
127
+ * @private
128
+ */
129
+ __EXPANDED__?: StkTableColumn<any> | null;
130
+ };
104
131
  export type SortOption<T extends Record<string, any>> = Pick<StkTableColumn<T>, 'sorter' | 'dataIndex' | 'sortField' | 'sortType'>;
105
- /** 排序状态 */
106
132
  export type SortState<T> = {
107
133
  dataIndex: keyof T;
108
134
  order: Order;
109
135
  sortType?: 'number' | 'string';
110
136
  };
111
- /** 唯一键 */
112
137
  export type UniqKey = string | number;
113
138
  export type UniqKeyFun = (param: any) => UniqKey;
114
139
  export type UniqKeyProp = UniqKey | UniqKeyFun;
115
- /** 排序配置 */
116
140
  export type SortConfig<T extends Record<string, any>> = {
117
141
  /** 空值始终排在列表末尾 */
118
142
  emptyToBottom?: boolean;
@@ -135,21 +159,46 @@ export type SortConfig<T extends Record<string, any>> = {
135
159
  */
136
160
  stringLocaleCompare?: boolean;
137
161
  };
138
- /** th td类型 */
162
+ /** th td type */
139
163
  export declare const enum TagType {
140
164
  TH = 0,
141
165
  TD = 1
142
166
  }
143
- /** 高亮配置 */
144
167
  export type HighlightConfig = {
145
- /** 高亮持续时间(s) */
168
+ /** Duration of the highlight in seconds */
146
169
  duration?: number;
147
- /** 高亮帧率 */
170
+ /** Frame rate of the highlight */
148
171
  fps?: number;
149
172
  };
150
- /** 序号列配置 */
173
+ /**
174
+ * Configuration options for the sequence column.
175
+ */
151
176
  export type SeqConfig = {
152
177
  /** 序号列起始下标 用于适配分页 */
153
178
  startIndex?: number;
154
179
  };
180
+ /** Configuration options for the expand column */
181
+ export type ExpandConfig = {
182
+ height?: number;
183
+ };
184
+ export type ExpandedRow = PrivateRowDT & {
185
+ __EXPANDED_ROW__: any;
186
+ __EXPANDED_COL__: any;
187
+ };
188
+ /** drag row config */
189
+ export type DragRowConfig = {
190
+ mode?: 'none' | 'insert' | 'swap';
191
+ };
192
+ /** header drag config */
193
+ export type HeaderDragConfig<DT extends Record<string, any> = any> = boolean | {
194
+ /**
195
+ * 列交换模式
196
+ * - none - 不做任何事
197
+ * - insert - 插入(默认值)
198
+ * - swap - 交换
199
+ */
200
+ mode?: 'none' | 'insert' | 'swap';
201
+ /** 禁用拖动的列 */
202
+ disabled?: (col: StkTableColumn<DT>) => boolean;
203
+ };
155
204
  export {};
@@ -1,18 +1,20 @@
1
- import { StkTableColumn } from './types';
1
+ import { ComputedRef } from 'vue';
2
+ import { StkTableColumn, UniqKey } from './types';
2
3
 
3
- type Params = {
4
+ type Params<T extends Record<string, any>> = {
4
5
  props: any;
5
6
  emits: any;
7
+ colKeyGen: ComputedRef<(col: StkTableColumn<T>) => UniqKey>;
6
8
  };
7
9
  /**
8
10
  * 列顺序拖动
9
- * @param param0
10
11
  * @returns
11
12
  */
12
- export declare function useThDrag<DT extends Record<string, any>>({ props, emits }: Params): {
13
- onThDragStart: (e: MouseEvent) => void;
14
- onThDragOver: (e: MouseEvent) => void;
15
- onThDrop: (e: MouseEvent) => void;
16
- isHeaderDraggable: (col: StkTableColumn<DT>) => any;
13
+ export declare function useThDrag<DT extends Record<string, any>>({ props, emits, colKeyGen }: Params<DT>): {
14
+ onThDragStart: (e: DragEvent) => void;
15
+ onThDragOver: (e: DragEvent) => void;
16
+ onThDrop: (e: DragEvent) => void;
17
+ /** 是否可拖拽 */
18
+ isHeaderDraggable: any;
17
19
  };
18
20
  export {};
@@ -0,0 +1,21 @@
1
+ import { ShallowRef } from 'vue';
2
+ import { DragRowConfig } from './types';
3
+
4
+ type Params = {
5
+ props: any;
6
+ emits: any;
7
+ dataSourceCopy: ShallowRef<any[]>;
8
+ };
9
+ /**
10
+ * 拖拽行
11
+ * TODO: 不在虚拟滚动的情况下,从上面拖拽到下面,跨页的时候,滚动条会自适应位置。没有顶上去
12
+ */
13
+ export declare function useTrDrag({ props, emits, dataSourceCopy }: Params): {
14
+ dragRowConfig: import('vue').ComputedRef<DragRowConfig>;
15
+ onTrDragStart: (e: DragEvent, rowIndex: number) => void;
16
+ onTrDragEnter: (e: DragEvent) => void;
17
+ onTrDragOver: (e: DragEvent) => void;
18
+ onTrDrop: (e: DragEvent, rowIndex: number) => void;
19
+ onTrDragEnd: (e: DragEvent) => void;
20
+ };
21
+ export {};
@@ -4,7 +4,6 @@ import { StkTableColumn } from './types';
4
4
  type Option<DT extends Record<string, any>> = {
5
5
  props: any;
6
6
  tableContainerRef: Ref<HTMLElement | undefined>;
7
- theadRef: Ref<HTMLElement | undefined>;
8
7
  dataSourceCopy: ShallowRef<DT[]>;
9
8
  tableHeaderLast: ShallowRef<StkTableColumn<DT>[]>;
10
9
  tableHeaders: ShallowRef<StkTableColumn<DT>[][]>;
@@ -48,7 +47,7 @@ export type VirtualScrollXStore = {
48
47
  * @param param0
49
48
  * @returns
50
49
  */
51
- export declare function useVirtualScroll<DT extends Record<string, any>>({ props, tableContainerRef, theadRef, dataSourceCopy, tableHeaderLast, tableHeaders, }: Option<DT>): {
50
+ export declare function useVirtualScroll<DT extends Record<string, any>>({ props, tableContainerRef, dataSourceCopy, tableHeaderLast, tableHeaders, }: Option<DT>): {
52
51
  virtualScroll: Ref<{
53
52
  containerHeight: number;
54
53
  pageSize: number;
@@ -1,4 +1,4 @@
1
- import { Order, SortConfig, SortOption, SortState, StkTableColumn } from '../types';
1
+ import { Order, PrivateStkTableColumn, SortConfig, SortOption, SortState, StkTableColumn } from '../types';
2
2
 
3
3
  /**
4
4
  * 对有序数组插入新数据
@@ -44,7 +44,7 @@ export declare function howDeepTheHeader(arr: StkTableColumn<any>[], level?: num
44
44
  */
45
45
  export declare function getColWidth(col: StkTableColumn<any> | null): number;
46
46
  /** 获取计算后的宽度 */
47
- export declare function getCalculatedColWidth(col: StkTableColumn<any> | null): number;
47
+ export declare function getCalculatedColWidth(col: PrivateStkTableColumn<any> | null): number;
48
48
  /** number列宽+px */
49
49
  export declare function transformWidthToStr(width?: string | number): string | undefined;
50
50
  /** 创建组件唯一标识 */