stk-table-vue 1.2.4 → 1.2.6

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.
Files changed (68) hide show
  1. package/README.md +194 -194
  2. package/lib/{Dropdown-D_9cB0rD.js → Dropdown-BAANgg_5.js} +2 -2
  3. package/lib/{StkTable-CVcmlZi9.js → StkTable-CGcxwpdb.js} +22 -6
  4. package/lib/src/StkTable/StkTable.vue.d.ts +18 -4
  5. package/lib/src/StkTable/types/index.d.ts +4 -1
  6. package/lib/src/StkTable/useVirtualScroll.d.ts +6 -1
  7. package/lib/stk-table-vue.js +3 -3
  8. package/lib/style.css +1 -1
  9. package/package.json +93 -93
  10. package/src/StkTable/StkTable.vue +2362 -2338
  11. package/src/StkTable/components/DragHandle.vue +9 -9
  12. package/src/StkTable/components/SortIcon.vue +6 -6
  13. package/src/StkTable/components/TreeNodeCell.vue +19 -19
  14. package/src/StkTable/components/TriangleIcon.vue +3 -3
  15. package/src/StkTable/const.ts +50 -50
  16. package/src/StkTable/custom-cells/ChangeCell/ChangeCell.less +34 -34
  17. package/src/StkTable/custom-cells/ChangeCell/createChangeCell.ts +90 -90
  18. package/src/StkTable/custom-cells/ChangeCell/index.ts +4 -4
  19. package/src/StkTable/custom-cells/CheckboxCell/CheckboxCell.less +14 -14
  20. package/src/StkTable/custom-cells/CheckboxCell/CheckboxCell.vue +56 -56
  21. package/src/StkTable/custom-cells/CheckboxCell/createCheckboxCell.ts +146 -146
  22. package/src/StkTable/custom-cells/CheckboxCell/index.ts +5 -5
  23. package/src/StkTable/custom-cells/FilterCell/Dropdown/index.ts +16 -16
  24. package/src/StkTable/custom-cells/FilterCell/Dropdown/index.vue +186 -186
  25. package/src/StkTable/custom-cells/FilterCell/Filter.less +118 -118
  26. package/src/StkTable/custom-cells/FilterCell/Filter.vue +66 -66
  27. package/src/StkTable/custom-cells/FilterCell/createFilterCell.ts +120 -120
  28. package/src/StkTable/custom-cells/FilterCell/index.ts +6 -6
  29. package/src/StkTable/custom-cells/FilterCell/types.ts +43 -43
  30. package/src/StkTable/custom-cells/NumberCell/createNumberCell.ts +43 -43
  31. package/src/StkTable/custom-cells/NumberCell/index.ts +2 -2
  32. package/src/StkTable/custom-cells/utils/formatNumber.ts +137 -137
  33. package/src/StkTable/features/const.ts +1 -1
  34. package/src/StkTable/features/index.ts +1 -1
  35. package/src/StkTable/features/useAreaSelection.ts +1240 -1239
  36. package/src/StkTable/index.ts +20 -20
  37. package/src/StkTable/mergeCellsCache.ts +69 -69
  38. package/src/StkTable/registerFeature.ts +40 -40
  39. package/src/StkTable/style.less +791 -791
  40. package/src/StkTable/types/highlightDimOptions.ts +28 -28
  41. package/src/StkTable/types/index.ts +503 -500
  42. package/src/StkTable/useAutoResize.ts +87 -87
  43. package/src/StkTable/useColResize.ts +202 -202
  44. package/src/StkTable/useFixedCol.ts +168 -168
  45. package/src/StkTable/useFixedStyle.ts +75 -75
  46. package/src/StkTable/useGetFixedColPosition.ts +63 -63
  47. package/src/StkTable/useHighlight.ts +270 -270
  48. package/src/StkTable/useIndexResolver.ts +29 -29
  49. package/src/StkTable/useKeyboardArrowScroll.ts +114 -114
  50. package/src/StkTable/useMaxRowSpan.ts +60 -60
  51. package/src/StkTable/useMergeCells.ts +541 -541
  52. package/src/StkTable/useRowExpand.ts +81 -81
  53. package/src/StkTable/useScrollRowByRow.ts +96 -96
  54. package/src/StkTable/useScrollbar.ts +177 -177
  55. package/src/StkTable/useSorter.ts +267 -267
  56. package/src/StkTable/useTableColumns.ts +142 -142
  57. package/src/StkTable/useThDrag.ts +94 -94
  58. package/src/StkTable/useTrDrag.ts +100 -100
  59. package/src/StkTable/useTree.ts +253 -253
  60. package/src/StkTable/useVirtualScroll.ts +1032 -1025
  61. package/src/StkTable/useWheeling.ts +23 -23
  62. package/src/StkTable/utils/constRefUtils.ts +29 -29
  63. package/src/StkTable/utils/index.ts +331 -331
  64. package/src/StkTable/utils/rowHeightFenwickTree.ts +74 -74
  65. package/src/StkTable/utils/useTriggerRef.ts +33 -33
  66. package/src/VirtualTree.vue +622 -622
  67. package/src/VirtualTreeSelect.vue +367 -367
  68. package/src/vite-env.d.ts +10 -10
@@ -1,81 +1,81 @@
1
- import { ShallowRef } from 'vue';
2
- import { EXPANDED_ROW_KEY_PREFIX } from './const';
3
- import { PrivateRowDT, RowKeyGen, StkTableColumn, UniqKey } from './types';
4
- type DT = PrivateRowDT;
5
-
6
- export function useRowExpand(emits: any, dataSourceCopy: ShallowRef<DT[]>, rowKeyGen: RowKeyGen, onDataSourceChange: () => void) {
7
- const expandedKey = '__EXP__';
8
-
9
- function isExpanded(row: DT, col?: StkTableColumn<DT>) {
10
- return row?.[expandedKey] === col ? !row?.[expandedKey] : true;
11
- }
12
- /** click expended icon to toggle expand row */
13
- function toggleExpandRow(row: DT, col: StkTableColumn<DT>) {
14
- const isExpand = isExpanded(row, col);
15
- setRowExpand(row, isExpand, { col });
16
- }
17
-
18
- /**
19
- *
20
- * @param rowKeyOrRow rowKey or row
21
- * @param expand expand or collapse, if set null, toggle expand
22
- * @param data { col?: StkTableColumn<DT> }
23
- * @param data.silent if set true, not emit `toggle-row-expand`, default:false
24
- */
25
- function setRowExpand(rowKeyOrRow: string | undefined | DT, expand?: boolean | null, data?: { col?: StkTableColumn<DT>; silent?: boolean }) {
26
- let rowKey: UniqKey;
27
- if (typeof rowKeyOrRow === 'string' || typeof rowKeyOrRow === 'number') {
28
- rowKey = rowKeyOrRow;
29
- } else {
30
- rowKey = rowKeyGen(rowKeyOrRow);
31
- }
32
-
33
- const tempData = dataSourceCopy.value.slice();
34
- const index = tempData.findIndex(it => rowKeyGen(it) === rowKey);
35
- if (index === -1) {
36
- console.warn('expandRow failed.rowKey:', rowKey);
37
- return;
38
- }
39
-
40
- // delete other expanded row below the target row
41
- for (let i = index + 1; i < tempData.length; i++) {
42
- const item: PrivateRowDT = tempData[i];
43
- const rowKey = item.__R_K__;
44
- if (rowKey?.startsWith(EXPANDED_ROW_KEY_PREFIX)) {
45
- tempData.splice(i, 1);
46
- i--;
47
- } else {
48
- break;
49
- }
50
- }
51
-
52
- const row = tempData[index];
53
- const col = data?.col;
54
-
55
- if (expand == null) {
56
- expand = isExpanded(row, col);
57
- }
58
-
59
- if (expand) {
60
- // insert new expanded row
61
- const newExpandRow: PrivateRowDT = {
62
- __R_K__: EXPANDED_ROW_KEY_PREFIX + rowKey,
63
- __EXP_R__: row,
64
- __EXP_C__: col,
65
- };
66
- tempData.splice(index + 1, 0, newExpandRow);
67
- }
68
-
69
- if (row) {
70
- row[expandedKey] = expand ? col : void 0;
71
- }
72
-
73
- dataSourceCopy.value = tempData;
74
- onDataSourceChange();
75
- if (!data?.silent) {
76
- emits('toggle-row-expand', { expanded: Boolean(expand), row, col });
77
- }
78
- }
79
-
80
- return [toggleExpandRow, setRowExpand] as const;
81
- }
1
+ import { ShallowRef } from 'vue';
2
+ import { EXPANDED_ROW_KEY_PREFIX } from './const';
3
+ import { PrivateRowDT, RowKeyGen, StkTableColumn, UniqKey } from './types';
4
+ type DT = PrivateRowDT;
5
+
6
+ export function useRowExpand(emits: any, dataSourceCopy: ShallowRef<DT[]>, rowKeyGen: RowKeyGen, onDataSourceChange: () => void) {
7
+ const expandedKey = '__EXP__';
8
+
9
+ function isExpanded(row: DT, col?: StkTableColumn<DT>) {
10
+ return row?.[expandedKey] === col ? !row?.[expandedKey] : true;
11
+ }
12
+ /** click expended icon to toggle expand row */
13
+ function toggleExpandRow(row: DT, col: StkTableColumn<DT>) {
14
+ const isExpand = isExpanded(row, col);
15
+ setRowExpand(row, isExpand, { col });
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @param rowKeyOrRow rowKey or row
21
+ * @param expand expand or collapse, if set null, toggle expand
22
+ * @param data { col?: StkTableColumn<DT> }
23
+ * @param data.silent if set true, not emit `toggle-row-expand`, default:false
24
+ */
25
+ function setRowExpand(rowKeyOrRow: string | undefined | DT, expand?: boolean | null, data?: { col?: StkTableColumn<DT>; silent?: boolean }) {
26
+ let rowKey: UniqKey;
27
+ if (typeof rowKeyOrRow === 'string' || typeof rowKeyOrRow === 'number') {
28
+ rowKey = rowKeyOrRow;
29
+ } else {
30
+ rowKey = rowKeyGen(rowKeyOrRow);
31
+ }
32
+
33
+ const tempData = dataSourceCopy.value.slice();
34
+ const index = tempData.findIndex(it => rowKeyGen(it) === rowKey);
35
+ if (index === -1) {
36
+ console.warn('expandRow failed.rowKey:', rowKey);
37
+ return;
38
+ }
39
+
40
+ // delete other expanded row below the target row
41
+ for (let i = index + 1; i < tempData.length; i++) {
42
+ const item: PrivateRowDT = tempData[i];
43
+ const rowKey = item.__R_K__;
44
+ if (rowKey?.startsWith(EXPANDED_ROW_KEY_PREFIX)) {
45
+ tempData.splice(i, 1);
46
+ i--;
47
+ } else {
48
+ break;
49
+ }
50
+ }
51
+
52
+ const row = tempData[index];
53
+ const col = data?.col;
54
+
55
+ if (expand == null) {
56
+ expand = isExpanded(row, col);
57
+ }
58
+
59
+ if (expand) {
60
+ // insert new expanded row
61
+ const newExpandRow: PrivateRowDT = {
62
+ __R_K__: EXPANDED_ROW_KEY_PREFIX + rowKey,
63
+ __EXP_R__: row,
64
+ __EXP_C__: col,
65
+ };
66
+ tempData.splice(index + 1, 0, newExpandRow);
67
+ }
68
+
69
+ if (row) {
70
+ row[expandedKey] = expand ? col : void 0;
71
+ }
72
+
73
+ dataSourceCopy.value = tempData;
74
+ onDataSourceChange();
75
+ if (!data?.silent) {
76
+ emits('toggle-row-expand', { expanded: Boolean(expand), row, col });
77
+ }
78
+ }
79
+
80
+ return [toggleExpandRow, setRowExpand] as const;
81
+ }
@@ -1,96 +1,96 @@
1
- import { computed, customRef, onMounted, onUnmounted, Ref, watch } from 'vue';
2
-
3
- export function useScrollRowByRow(props: any, tableContainerRef: Ref<HTMLElement | undefined>) {
4
- // let isMouseDown = false;
5
- let isAddListeners = false;
6
- /** record the last scroll bar position */
7
- // let lastScrollTop = 0;
8
-
9
- /** record is the scroll bar is dragging.debounce true to false */
10
- const isDragScroll = customRef((track, trigger) => {
11
- let value = false;
12
- let debounceTimer = 0;
13
-
14
- return {
15
- get() {
16
- track();
17
- return value;
18
- },
19
- set(newValue) {
20
- // Add debounce when change from true to false
21
- if (value && !newValue) {
22
- if (debounceTimer) {
23
- window.clearTimeout(debounceTimer);
24
- }
25
- debounceTimer = window.setTimeout(() => {
26
- value = newValue;
27
- trigger();
28
- debounceTimer = 0;
29
- }, 300);
30
- } else {
31
- if (debounceTimer) {
32
- window.clearTimeout(debounceTimer);
33
- debounceTimer = 0;
34
- }
35
- value = newValue;
36
- trigger();
37
- }
38
- },
39
- };
40
- });
41
- const onlyDragScroll = computed(() => props.scrollRowByRow === 'scrollbar');
42
-
43
- /** is ScrollRowByRow active */
44
- const isSRBRActive = computed(() => {
45
- if (onlyDragScroll.value) {
46
- return isDragScroll.value;
47
- }
48
- return props.scrollRowByRow;
49
- });
50
-
51
- watch(onlyDragScroll, v => {
52
- if (v) {
53
- addEventListener();
54
- } else {
55
- removeEventListener();
56
- }
57
- });
58
-
59
- onMounted(() => {
60
- addEventListener();
61
- });
62
-
63
- onUnmounted(() => {
64
- removeEventListener();
65
- });
66
-
67
- function addEventListener() {
68
- if (isAddListeners || !onlyDragScroll.value) return;
69
- const container = tableContainerRef.value;
70
- if (!container) return;
71
- container.addEventListener('mousedown', handleMouseDown);
72
- container.addEventListener('mouseup', handleMouseUp);
73
- isAddListeners = true;
74
- }
75
-
76
- function removeEventListener() {
77
- const container = tableContainerRef.value;
78
- if (!container) return;
79
- container.removeEventListener('mousedown', handleMouseDown);
80
- container.removeEventListener('mouseup', handleMouseUp);
81
- isAddListeners = false;
82
- }
83
-
84
- function handleMouseDown(e: Event) {
85
- const el = e.target as HTMLElement;
86
- if (el.classList.contains('stk-table')) {
87
- isDragScroll.value = true;
88
- }
89
- }
90
-
91
- function handleMouseUp() {
92
- isDragScroll.value = false;
93
- }
94
-
95
- return [isSRBRActive] as const;
96
- }
1
+ import { computed, customRef, onMounted, onUnmounted, Ref, watch } from 'vue';
2
+
3
+ export function useScrollRowByRow(props: any, tableContainerRef: Ref<HTMLElement | undefined>) {
4
+ // let isMouseDown = false;
5
+ let isAddListeners = false;
6
+ /** record the last scroll bar position */
7
+ // let lastScrollTop = 0;
8
+
9
+ /** record is the scroll bar is dragging.debounce true to false */
10
+ const isDragScroll = customRef((track, trigger) => {
11
+ let value = false;
12
+ let debounceTimer = 0;
13
+
14
+ return {
15
+ get() {
16
+ track();
17
+ return value;
18
+ },
19
+ set(newValue) {
20
+ // Add debounce when change from true to false
21
+ if (value && !newValue) {
22
+ if (debounceTimer) {
23
+ window.clearTimeout(debounceTimer);
24
+ }
25
+ debounceTimer = window.setTimeout(() => {
26
+ value = newValue;
27
+ trigger();
28
+ debounceTimer = 0;
29
+ }, 300);
30
+ } else {
31
+ if (debounceTimer) {
32
+ window.clearTimeout(debounceTimer);
33
+ debounceTimer = 0;
34
+ }
35
+ value = newValue;
36
+ trigger();
37
+ }
38
+ },
39
+ };
40
+ });
41
+ const onlyDragScroll = computed(() => props.scrollRowByRow === 'scrollbar');
42
+
43
+ /** is ScrollRowByRow active */
44
+ const isSRBRActive = computed(() => {
45
+ if (onlyDragScroll.value) {
46
+ return isDragScroll.value;
47
+ }
48
+ return props.scrollRowByRow;
49
+ });
50
+
51
+ watch(onlyDragScroll, v => {
52
+ if (v) {
53
+ addEventListener();
54
+ } else {
55
+ removeEventListener();
56
+ }
57
+ });
58
+
59
+ onMounted(() => {
60
+ addEventListener();
61
+ });
62
+
63
+ onUnmounted(() => {
64
+ removeEventListener();
65
+ });
66
+
67
+ function addEventListener() {
68
+ if (isAddListeners || !onlyDragScroll.value) return;
69
+ const container = tableContainerRef.value;
70
+ if (!container) return;
71
+ container.addEventListener('mousedown', handleMouseDown);
72
+ container.addEventListener('mouseup', handleMouseUp);
73
+ isAddListeners = true;
74
+ }
75
+
76
+ function removeEventListener() {
77
+ const container = tableContainerRef.value;
78
+ if (!container) return;
79
+ container.removeEventListener('mousedown', handleMouseDown);
80
+ container.removeEventListener('mouseup', handleMouseUp);
81
+ isAddListeners = false;
82
+ }
83
+
84
+ function handleMouseDown(e: Event) {
85
+ const el = e.target as HTMLElement;
86
+ if (el.classList.contains('stk-table')) {
87
+ isDragScroll.value = true;
88
+ }
89
+ }
90
+
91
+ function handleMouseUp() {
92
+ isDragScroll.value = false;
93
+ }
94
+
95
+ return [isSRBRActive] as const;
96
+ }