stk-table-vue 0.8.13 → 0.8.14

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.
@@ -1,4 +1,4 @@
1
- import { computed, Ref, ref, onMounted, onUnmounted, watch } from 'vue';
1
+ import { computed, customRef, onMounted, onUnmounted, Ref, watch } from 'vue';
2
2
 
3
3
  type Params = {
4
4
  props: any;
@@ -6,13 +6,43 @@ type Params = {
6
6
  };
7
7
 
8
8
  export function useScrollRowByRow({ props, tableContainerRef }: Params) {
9
- let isMouseDown = false;
9
+ // let isMouseDown = false;
10
10
  let isAddListeners = false;
11
11
  /** record the last scroll bar position */
12
- let lastScrollTop = 0;
12
+ // let lastScrollTop = 0;
13
13
 
14
- /** record is the scroll bar is dragging */
15
- const isDragScroll = ref(false);
14
+ /** record is the scroll bar is dragging.debounce true to false */
15
+ const isDragScroll = customRef((track, trigger) => {
16
+ let value = false;
17
+ let debounceTimer = 0;
18
+
19
+ return {
20
+ get() {
21
+ track();
22
+ return value;
23
+ },
24
+ set(newValue) {
25
+ // Add debounce when change from true to false
26
+ if (value && !newValue) {
27
+ if (debounceTimer) {
28
+ window.clearTimeout(debounceTimer);
29
+ }
30
+ debounceTimer = window.setTimeout(() => {
31
+ value = newValue;
32
+ trigger();
33
+ debounceTimer = 0;
34
+ }, 300);
35
+ } else {
36
+ if (debounceTimer) {
37
+ window.clearTimeout(debounceTimer);
38
+ debounceTimer = 0;
39
+ }
40
+ value = newValue;
41
+ trigger();
42
+ }
43
+ }
44
+ }
45
+ });
16
46
  const onlyDragScroll = computed(() => props.scrollRowByRow === 'scrollbar');
17
47
 
18
48
  /** is ScrollRowByRow active */
@@ -45,7 +75,7 @@ export function useScrollRowByRow({ props, tableContainerRef }: Params) {
45
75
  if (!container) return;
46
76
  container.addEventListener('mousedown', handleMouseDown);
47
77
  container.addEventListener('mouseup', handleMouseUp);
48
- container.addEventListener('scroll', handleScroll);
78
+ // container.addEventListener('scroll', handleScroll);
49
79
  isAddListeners = true;
50
80
  }
51
81
 
@@ -54,26 +84,31 @@ export function useScrollRowByRow({ props, tableContainerRef }: Params) {
54
84
  if (!container) return;
55
85
  container.removeEventListener('mousedown', handleMouseDown);
56
86
  container.removeEventListener('mouseup', handleMouseUp);
57
- container.removeEventListener('scroll', handleScroll);
87
+ // container.removeEventListener('scroll', handleScroll);
58
88
  isAddListeners = false;
59
89
  }
60
90
 
61
91
  function handleMouseDown(e: Event) {
62
- isMouseDown = true;
63
- lastScrollTop = (e.target as HTMLElement).scrollTop;
92
+ // console.log('mousedown target:', e.target)
93
+ const el = e.target as HTMLElement;
94
+ if(el.classList.contains('stk-table')){
95
+ isDragScroll.value = true;
96
+ }
97
+ // isMouseDown = true;
98
+ // lastScrollTop = (e.target as HTMLElement).scrollTop;
64
99
  }
65
100
 
66
101
  function handleMouseUp() {
67
- isMouseDown = false;
102
+ // isMouseDown = false;
68
103
  isDragScroll.value = false;
69
- lastScrollTop = 0;
104
+ // lastScrollTop = 0;
70
105
  }
71
106
 
72
- function handleScroll(e: Event) {
73
- const scrollTop = (e.target as HTMLElement).scrollTop;
74
- // if scrollTop === lastScrollTop means horizontal scroll
75
- if (!isMouseDown || scrollTop === lastScrollTop) return;
76
- isDragScroll.value = true;
77
- }
107
+ // function handleScroll(e: Event) {
108
+ // const scrollTop = (e.target as HTMLElement).scrollTop;
109
+ // // if scrollTop === lastScrollTop means horizontal scroll
110
+ // if (!isMouseDown || scrollTop === lastScrollTop) return;
111
+ // isDragScroll.value = true;
112
+ // }
78
113
  return { isSRBRActive, isDragScroll };
79
- }
114
+ }
@@ -1,5 +1,6 @@
1
1
  import { computed, ShallowRef } from 'vue';
2
2
  import { DragRowConfig } from './types';
3
+ import { getClosestTr } from './utils';
3
4
 
4
5
  type Params = {
5
6
  props: any;
@@ -22,12 +23,6 @@ export function useTrDrag({ props, emits, dataSourceCopy }: Params) {
22
23
  return { mode: 'insert', ...props.dragRowConfig };
23
24
  });
24
25
 
25
- function getClosestTr(e: DragEvent) {
26
- const target = e.target as HTMLElement;
27
- const tr = target?.closest('tr');
28
- return tr;
29
- }
30
-
31
26
  function onTrDragStart(e: DragEvent, rowIndex: number) {
32
27
  const tr = getClosestTr(e);
33
28
  if (tr) {
@@ -240,3 +240,19 @@ export function getBrowsersVersion(browserName: string) {
240
240
  export function pureCellKeyGen(rowKey: UniqKey, colKey: UniqKey) {
241
241
  return rowKey + CELL_KEY_SEPARATE + colKey;
242
242
  }
243
+
244
+ export function getClosestTr(e: MouseEvent) {
245
+ const target = e.target as HTMLElement;
246
+ const tr = target?.closest('tr');
247
+ return tr;
248
+ }
249
+
250
+ export function getClosestTrIndex(e: MouseEvent) {
251
+ const tr = getClosestTr(e);
252
+ if (!tr) return -1;
253
+ return Number(tr.dataset.rowI);
254
+ }
255
+
256
+ export function getClosestColKey(e: MouseEvent) {
257
+ return (e.target as HTMLElement)?.closest('td')?.dataset.colKey;
258
+ }