stk-table-vue 0.8.1 → 0.8.3

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
@@ -44,6 +44,7 @@
44
44
  * [x] 行展开。(`v0.5.0`)
45
45
  * [x] 行拖动。(`v0.5.0`)
46
46
  * [x] 树形。(`v0.7.0`)
47
+ * [x] 单元格合并。(`v0.8.0`)
47
48
  * [] 列筛选。
48
49
  * [x] 斑马纹。
49
50
  * [x] 拖动更改列顺序。
@@ -77,7 +78,7 @@ const stkTableRef = useTemplateRef('stkTableRef');
77
78
 
78
79
  // highlight row
79
80
  stkTableRef.value.setHighlightDimRow([rowKey],{
80
- method: 'css'|'js'|'animation',// 默认 animation。
81
+ method: 'css'|'animation',// 默认 animation。
81
82
  className: 'custom-class-name', // method css 时生效。
82
83
  keyframe: [{backgroundColor:'#aaa'}, {backgroundColor: '#222'}],//same as https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API/Keyframe_Formats
83
84
  duration: 2000,// 动画时长。
@@ -136,7 +136,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
136
136
  * 给行附加className<br>
137
137
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
138
138
  */
139
- rowClassName?: (row: DT, i: number) => string;
139
+ rowClassName?: (row: DT, i: number) => string | undefined;
140
140
  /**
141
141
  * 列宽是否可拖动(需要设置v-model:columns)<br>
142
142
  * **不要设置**列minWidth,**必须**设置width<br>
@@ -347,7 +347,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
347
347
  * en: Set expanded rows
348
348
  * @see {@link setRowExpand}
349
349
  */
350
- setRowExpand: (rowKeyOrRow: string | undefined | PrivateRowDT, expand?: boolean, data?: {
350
+ setRowExpand: (rowKeyOrRow: string | undefined | PrivateRowDT, expand?: boolean | null, data?: {
351
351
  col?: StkTableColumn<PrivateRowDT>;
352
352
  silent?: boolean;
353
353
  }) => void;
@@ -502,7 +502,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
502
502
  * 给行附加className<br>
503
503
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
504
504
  */
505
- rowClassName?: (row: DT, i: number) => string;
505
+ rowClassName?: (row: DT, i: number) => string | undefined;
506
506
  /**
507
507
  * 列宽是否可拖动(需要设置v-model:columns)<br>
508
508
  * **不要设置**列minWidth,**必须**设置width<br>
@@ -703,7 +703,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
703
703
  cellActive: boolean;
704
704
  selectedCellRevokable: boolean;
705
705
  headerDrag: boolean | HeaderDragConfig;
706
- rowClassName: (row: DT, i: number) => string;
706
+ rowClassName: (row: DT, i: number) => string | undefined;
707
707
  colResizable: boolean | ColResizableConfig<DT>;
708
708
  colMinWidth: number;
709
709
  bordered: boolean | "h" | "v" | "body-v";
@@ -9,7 +9,7 @@ type Option<DT extends Record<string, any>> = {
9
9
  };
10
10
  export declare function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>): {
11
11
  toggleExpandRow: (row: DT, col: StkTableColumn<DT>) => void;
12
- setRowExpand: (rowKeyOrRow: string | undefined | DT, expand?: boolean, data?: {
12
+ setRowExpand: (rowKeyOrRow: string | undefined | DT, expand?: boolean | null, data?: {
13
13
  col?: StkTableColumn<DT>;
14
14
  silent?: boolean;
15
15
  }) => void;
@@ -296,7 +296,7 @@ function getColWidth(col) {
296
296
  return parseInt(val);
297
297
  }
298
298
  function getCalculatedColWidth(col) {
299
- return (col && col.__WIDTH__) ?? 100;
299
+ return (col && col.__WIDTH__) ?? +DEFAULT_COL_WIDTH;
300
300
  }
301
301
  function createStkTableId() {
302
302
  let id = window.__STK_TB_ID_COUNT__;
@@ -854,8 +854,12 @@ function useKeyboardArrowScroll(targetElement, { props, scrollTo, virtualScroll,
854
854
  }
855
855
  }
856
856
  function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
857
+ const expandedKey = "__EXPANDED__";
858
+ function isExpanded(row, col) {
859
+ return (row == null ? void 0 : row[expandedKey]) === col ? !(row == null ? void 0 : row[expandedKey]) : true;
860
+ }
857
861
  function toggleExpandRow(row, col) {
858
- const isExpand = (row == null ? void 0 : row.__EXPANDED__) === col ? !(row == null ? void 0 : row.__EXPANDED__) : true;
862
+ const isExpand = isExpanded(row, col);
859
863
  setRowExpand(row, isExpand, { col });
860
864
  }
861
865
  function setRowExpand(rowKeyOrRow, expand, data) {
@@ -883,6 +887,9 @@ function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
883
887
  }
884
888
  const row = tempData[index];
885
889
  const col = (data == null ? void 0 : data.col) || null;
890
+ if (expand == null) {
891
+ expand = isExpanded(row, col);
892
+ }
886
893
  if (expand) {
887
894
  const newExpandRow = {
888
895
  __ROW_KEY__: EXPANDED_ROW_KEY_PREFIX + rowKey,
@@ -2419,10 +2426,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2419
2426
  headless: _ctx.headless,
2420
2427
  "is-col-resizing": unref(isColResizing),
2421
2428
  "col-resizable": props.colResizable,
2422
- border: props.bordered,
2423
- "border-h": props.bordered === "h",
2424
- "border-v": props.bordered === "v",
2425
- "border-body-v": props.bordered === "body-v",
2429
+ bordered: props.bordered,
2430
+ "bordered-h": props.bordered === "h",
2431
+ "bordered-v": props.bordered === "v",
2432
+ "bordered-body-v": props.bordered === "body-v",
2426
2433
  stripe: props.stripe,
2427
2434
  "cell-hover": props.cellHover,
2428
2435
  "cell-active": props.cellActive,
@@ -2575,7 +2582,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2575
2582
  class: normalizeClass({
2576
2583
  active: _ctx.rowKey ? rowKeyGen(row) === currentRowKey.value : row === currentRow.value,
2577
2584
  hover: props.showTrHoverClass && (_ctx.rowKey ? rowKeyGen(row) === currentHoverRowKey.value : row === currentHoverRowKey.value),
2578
- [_ctx.rowClassName(row, getRowIndex(rowIndex))]: true,
2585
+ [_ctx.rowClassName(row, getRowIndex(rowIndex)) || ""]: true,
2579
2586
  expanded: row == null ? void 0 : row.__EXPANDED__,
2580
2587
  "expanded-row": row && row.__EXPANDED_ROW__
2581
2588
  }),
@@ -2624,9 +2631,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2624
2631
  "tree-expanded": col.type === "tree-node" && row.__T_EXPANDED__,
2625
2632
  "drag-row-cell": col.type === "dragRow"
2626
2633
  }
2627
- ],
2628
- ref_for: true
2629
- }, unref(mergeCellsWrapper)(row, col, rowIndex, colIndex), {
2634
+ ]
2635
+ }, { ref_for: true }, unref(mergeCellsWrapper)(row, col, rowIndex, colIndex), {
2630
2636
  onClick: ($event) => onCellClick($event, row, col, getRowIndex(rowIndex)),
2631
2637
  onMousedown: ($event) => onCellMouseDown($event, row, col, getRowIndex(rowIndex)),
2632
2638
  onMouseenter: ($event) => onCellMouseEnter($event, row, col),
@@ -2649,7 +2655,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2649
2655
  expanded: row && row.__EXPANDED__ || null,
2650
2656
  "tree-expanded": row && row.__T_EXPANDED__ || null
2651
2657
  }, {
2652
- foldIcon: withCtx(() => [
2658
+ stkFoldIcon: withCtx(() => [
2653
2659
  createVNode(TriangleIcon)
2654
2660
  ]),
2655
2661
  _: 2
@@ -2671,7 +2677,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2671
2677
  rowIndex: getRowIndex(rowIndex),
2672
2678
  colIndex,
2673
2679
  cellValue: row && row[col.dataIndex]
2674
- }, null, 8, ["col", "row", "rowIndex", "colIndex", "cellValue"])) : (openBlock(), createElementBlock("div", {
2680
+ }, {
2681
+ stkFoldIcon: withCtx(() => [
2682
+ createVNode(TriangleIcon)
2683
+ ]),
2684
+ stkDragIcon: withCtx(() => [
2685
+ createVNode(DragHandle, {
2686
+ onDragstart: ($event) => unref(onTrDragStart)($event, getRowIndex(rowIndex))
2687
+ }, null, 8, ["onDragstart"])
2688
+ ]),
2689
+ _: 2
2690
+ }, 1032, ["col", "row", "rowIndex", "colIndex", "cellValue"])) : (openBlock(), createElementBlock("div", {
2675
2691
  key: 1,
2676
2692
  class: "table-cell-wrapper",
2677
2693
  title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : ""
package/lib/style.css CHANGED
@@ -66,7 +66,7 @@
66
66
  --drag-handle-hover-color:#5d6064;
67
67
  color:#d1d1e0;
68
68
  }
69
- .stk-table.headless.border{
69
+ .stk-table.headless.bordered{
70
70
  border-top:1px solid var(--border-color);
71
71
  background-image:var(--bg-border-right), var(--bg-border-bottom);
72
72
  }
@@ -79,27 +79,27 @@
79
79
  .stk-table.is-col-resizing th{
80
80
  pointer-events:none;
81
81
  }
82
- .stk-table.border{
82
+ .stk-table.bordered{
83
83
  border-left:1px solid var(--border-color);
84
84
  background-image:var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom);
85
85
  }
86
- .stk-table.border th,
87
- .stk-table.border td{
86
+ .stk-table.bordered th,
87
+ .stk-table.bordered td{
88
88
  background-image:var(--bg-border-right), var(--bg-border-bottom);
89
89
  }
90
- .stk-table.border thead tr:first-child th{
90
+ .stk-table.bordered thead tr:first-child th{
91
91
  background-image:var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom);
92
92
  }
93
- .stk-table.border-h{
93
+ .stk-table.bordered-h{
94
94
  border-left:none;
95
95
  --bg-border-right:linear-gradient(transparent, transparent);
96
96
  --bg-border-left:linear-gradient(transparent, transparent);
97
97
  }
98
- .stk-table.border-v{
98
+ .stk-table.bordered-v{
99
99
  --bg-border-bottom:linear-gradient(transparent, transparent);
100
100
  --bg-border-top:linear-gradient(transparent, transparent);
101
101
  }
102
- .stk-table.border-body-v tbody{
102
+ .stk-table.bordered-body-v tbody{
103
103
  --bg-border-bottom:linear-gradient(transparent, transparent);
104
104
  }
105
105
  .stk-table.stripe:not(.vt-on) .stk-tbody-main tr:nth-child(even){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stk-table-vue",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "description": "Simple realtime virtual table for vue3 and vue2.7",
5
5
  "main": "./lib/stk-table-vue.js",
6
6
  "types": "./lib/src/StkTable/index.d.ts",
@@ -44,14 +44,14 @@
44
44
  "@types/node": "^20.12.10",
45
45
  "@typescript-eslint/eslint-plugin": "^7.7.0",
46
46
  "@typescript-eslint/parser": "^7.7.0",
47
- "@vitejs/plugin-vue": "^5.1.4",
48
- "@vue/test-utils": "2.4.4",
47
+ "@vitejs/plugin-vue": "^6.0.0",
48
+ "@vue/test-utils": "^2.4.6",
49
49
  "eslint": "^8.57.0",
50
50
  "eslint-config-prettier": "^9.1.0",
51
51
  "eslint-plugin-html": "^8.1.0",
52
52
  "eslint-plugin-prettier": "^5.1.3",
53
53
  "eslint-plugin-vue": "^9.25.0",
54
- "happy-dom": "^12.10.3",
54
+ "happy-dom": "^18.0.1",
55
55
  "less": "^4.2.0",
56
56
  "mitt": "^3.0.1",
57
57
  "mockjs": "^1.1.0",
@@ -59,17 +59,15 @@
59
59
  "postcss-discard-comments": "^6.0.2",
60
60
  "postcss-preset-env": "^9.5.11",
61
61
  "prettier": "^3.2.5",
62
- "stk-table-vue": "^0.7.1",
63
- "typescript": "^5.4.5",
64
- "vite": "^6.3.5",
62
+ "stk-table-vue": "^0.8.1",
63
+ "typescript": "^5.8.3",
64
+ "vite": "^7.0.2",
65
65
  "vite-plugin-dts": "3.9.1",
66
66
  "vitepress": "^1.6.3",
67
67
  "vitepress-demo-plugin": "^1.4.5",
68
- "vitepress-plugin-llms": "^1.5.1",
69
- "vitest": "^2.1.3",
70
- "vue": "^3.5.12",
68
+ "vitepress-plugin-llms": "^1.7.0",
69
+ "vitest": "^3.2.4",
70
+ "vue": "^3.5.17",
71
71
  "vue-eslint-parser": "^9.4.2"
72
- },
73
- "dependencies": {
74
72
  }
75
73
  }
@@ -12,10 +12,10 @@
12
12
  headless,
13
13
  'is-col-resizing': isColResizing,
14
14
  'col-resizable': props.colResizable,
15
- border: props.bordered,
16
- 'border-h': props.bordered === 'h',
17
- 'border-v': props.bordered === 'v',
18
- 'border-body-v': props.bordered === 'body-v',
15
+ bordered: props.bordered,
16
+ 'bordered-h': props.bordered === 'h',
17
+ 'bordered-v': props.bordered === 'v',
18
+ 'bordered-body-v': props.bordered === 'body-v',
19
19
  stripe: props.stripe,
20
20
  'cell-hover': props.cellHover,
21
21
  'cell-active': props.cellActive,
@@ -126,7 +126,7 @@
126
126
  :class="{
127
127
  active: rowKey ? rowKeyGen(row) === currentRowKey : row === currentRow,
128
128
  hover: props.showTrHoverClass && (rowKey ? rowKeyGen(row) === currentHoverRowKey : row === currentHoverRowKey),
129
- [rowClassName(row, getRowIndex(rowIndex))]: true,
129
+ [rowClassName(row, getRowIndex(rowIndex)) || '']: true,
130
130
  expanded: row?.__EXPANDED__,
131
131
  'expanded-row': row && row.__EXPANDED_ROW__,
132
132
  }"
@@ -196,7 +196,7 @@
196
196
  :expanded="(row && row.__EXPANDED__) || null"
197
197
  :tree-expanded="(row && row.__T_EXPANDED__) || null"
198
198
  >
199
- <template #foldIcon>
199
+ <template #stkFoldIcon>
200
200
  <TriangleIcon></TriangleIcon>
201
201
  </template>
202
202
  </component>
@@ -221,7 +221,14 @@
221
221
  :rowIndex="getRowIndex(rowIndex)"
222
222
  :colIndex="colIndex"
223
223
  :cellValue="row && row[col.dataIndex]"
224
- />
224
+ >
225
+ <template #stkFoldIcon>
226
+ <TriangleIcon></TriangleIcon>
227
+ </template>
228
+ <template #stkDragIcon>
229
+ <DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
230
+ </template>
231
+ </component>
225
232
  <div v-else class="table-cell-wrapper" :title="col.type !== 'seq' ? row?.[col.dataIndex] : ''">
226
233
  <template v-if="col.type === 'seq'">
227
234
  {{ (props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1 }}
@@ -376,7 +383,7 @@ const props = withDefaults(
376
383
  * 给行附加className<br>
377
384
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
378
385
  */
379
- rowClassName?: (row: DT, i: number) => string;
386
+ rowClassName?: (row: DT, i: number) => string | undefined;
380
387
  /**
381
388
  * 列宽是否可拖动(需要设置v-model:columns)<br>
382
389
  * **不要设置**列minWidth,**必须**设置width<br>
@@ -91,7 +91,7 @@
91
91
  }
92
92
 
93
93
  &.headless {
94
- &.border {
94
+ &.bordered {
95
95
  border-top: 1px solid var(--border-color);
96
96
  background-image: var(--bg-border-right), var(--bg-border-bottom);
97
97
  }
@@ -112,7 +112,7 @@
112
112
  }
113
113
  }
114
114
 
115
- &.border {
115
+ &.bordered {
116
116
  /**
117
117
  * border-left: 此方案用于减少cell 中border-left 的css选择。同时利于多级表头border-left问题。利于横向滚动border-left
118
118
  * - box-shadow inset 方案不生效,且占用属性。
@@ -134,18 +134,18 @@
134
134
  }
135
135
  }
136
136
 
137
- &.border-h {
137
+ &.bordered-h {
138
138
  border-left: none;
139
139
  --bg-border-right: linear-gradient(transparent, transparent);
140
140
  --bg-border-left: linear-gradient(transparent, transparent);
141
141
  }
142
142
 
143
- &.border-v {
143
+ &.bordered-v {
144
144
  --bg-border-bottom: linear-gradient(transparent, transparent);
145
145
  --bg-border-top: linear-gradient(transparent, transparent);
146
146
  }
147
147
 
148
- &.border-body-v {
148
+ &.bordered-body-v {
149
149
  tbody {
150
150
  --bg-border-bottom: linear-gradient(transparent, transparent);
151
151
  }
@@ -378,13 +378,12 @@
378
378
 
379
379
  .fixed-cell {
380
380
  background-color: inherit;
381
- /* 防止横向滚动后透明*/
382
381
  }
383
382
 
384
383
  .highlight-cell {
385
384
  animation: stk-table-dim var(--highlight-duration);
386
385
  animation-timing-function: var(--highlight-timing-function);
387
- /* 必须分开些,否则var(step(x))不兼容旧浏览器*/
386
+ /* 必须分开写,否则var(step(x))不兼容旧浏览器*/
388
387
  }
389
388
 
390
389
  .seq-column {
@@ -9,26 +9,32 @@ type Option<DT extends Record<string, any>> = {
9
9
  };
10
10
 
11
11
  export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
12
+ const expandedKey = '__EXPANDED__';
13
+
14
+ function isExpanded(row: DT, col?: StkTableColumn<DT> | null) {
15
+ return row?.[expandedKey] === col ? !row?.[expandedKey] : true;
16
+ }
12
17
  /** click expended icon to toggle expand row */
13
18
  function toggleExpandRow(row: DT, col: StkTableColumn<DT>) {
14
- const isExpand = row?.__EXPANDED__ === col ? !row?.__EXPANDED__ : true;
19
+ const isExpand = isExpanded(row, col);
15
20
  setRowExpand(row, isExpand, { col });
16
21
  }
17
22
 
18
23
  /**
19
24
  *
20
25
  * @param rowKeyOrRow rowKey or row
21
- * @param expand expand or collapse
26
+ * @param expand expand or collapse, if set null, toggle expand
22
27
  * @param data { col?: StkTableColumn<DT> }
23
28
  * @param data.silent if set true, not emit `toggle-row-expand`, default:false
24
29
  */
25
- function setRowExpand(rowKeyOrRow: string | undefined | DT, expand?: boolean, data?: { col?: StkTableColumn<DT>; silent?: boolean }) {
30
+ function setRowExpand(rowKeyOrRow: string | undefined | DT, expand?: boolean | null, data?: { col?: StkTableColumn<DT>; silent?: boolean }) {
26
31
  let rowKey: UniqKey;
27
32
  if (typeof rowKeyOrRow === 'string') {
28
33
  rowKey = rowKeyOrRow;
29
34
  } else {
30
35
  rowKey = rowKeyGen(rowKeyOrRow);
31
36
  }
37
+
32
38
  const tempData = dataSourceCopy.value.slice();
33
39
  const index = tempData.findIndex(it => rowKeyGen(it) === rowKey);
34
40
  if (index === -1) {
@@ -51,6 +57,10 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
51
57
  const row = tempData[index];
52
58
  const col = data?.col || null;
53
59
 
60
+ if (expand == null) {
61
+ expand = isExpanded(row, col);
62
+ }
63
+
54
64
  if (expand) {
55
65
  // insert new expanded row
56
66
  const newExpandRow: ExpandedRow = {
@@ -124,7 +124,7 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
124
124
  function expandNode(row: DT, level: number) {
125
125
  let result: DT[] = [];
126
126
  row.children &&
127
- row.children.forEach(child => {
127
+ row.children.forEach((child: DT) => {
128
128
  result.push(child);
129
129
  const childLv = level + 1;
130
130
  if (child.__T_EXPANDED__ && child.children) {