sprintify-ui 0.8.27 → 0.8.28
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/dist/sprintify-ui.es.js +2183 -2174
- package/package.json +1 -1
- package/src/components/BaseTable.vue +0 -1
- package/src/components/BaseTableRow.vue +58 -29
package/package.json
CHANGED
|
@@ -99,7 +99,6 @@ function scrollTop() {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
// Virtual Scrolling
|
|
102
|
-
|
|
103
102
|
const virtualScrollingDefaultRowHeight = ref(null) as Ref<number | null | undefined>;
|
|
104
103
|
function setVirtualScrollingDefaultRowHeight(height: number) {
|
|
105
104
|
virtualScrollingDefaultRowHeight.value = height;
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
<script lang="ts" setup>
|
|
22
22
|
import { ClassNameValue, twMerge } from 'tailwind-merge';
|
|
23
23
|
import { RouteLocationRaw } from 'vue-router';
|
|
24
|
-
import { useIntersectionObserver } from '@vueuse/core';
|
|
25
24
|
import { cellClasses } from '../services/table/classes';
|
|
26
25
|
import { CellConfig, TableProps } from '../services/table/types';
|
|
27
26
|
import { ComputedRef, Ref } from 'vue';
|
|
27
|
+
import { debounce } from 'lodash';
|
|
28
28
|
|
|
29
29
|
defineOptions({
|
|
30
30
|
inheritAttrs: false,
|
|
@@ -40,13 +40,66 @@ const isHead = computed(() => baseTableHead !== undefined);
|
|
|
40
40
|
|
|
41
41
|
// Virtual scrolling
|
|
42
42
|
|
|
43
|
+
const trRef = ref<HTMLTableRowElement | null>(null);
|
|
44
|
+
const inViewport = ref(false);
|
|
45
|
+
const trRenderedHeight = ref(undefined) as Ref<number | undefined>;
|
|
46
|
+
|
|
43
47
|
const baseTableVirtualScrollingDefaultRowHeight = inject('table:virtualScrollingDefaultRowHeight', undefined) as ComputedRef<number> | undefined;
|
|
44
48
|
const setVirtualScrollingDefaultRowHeight = inject('table:setVirtualScrollingDefaultRowHeight', undefined) as ((height: number) => void) | undefined;
|
|
45
49
|
|
|
46
|
-
const
|
|
47
|
-
const trRef = ref<HTMLTableRowElement | null>(null);
|
|
50
|
+
const onScrollDebounce = debounce(onScroll, 10);
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
window.addEventListener('scroll', onScrollDebounce);
|
|
53
|
+
|
|
54
|
+
onUnmounted(() => {
|
|
55
|
+
window.removeEventListener('scroll', onScrollDebounce);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
onMounted(() => {
|
|
59
|
+
onScroll();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
function onScroll() {
|
|
64
|
+
|
|
65
|
+
if (isHead.value) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!baseTable?.value?.virtualScrolling) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const isInViewport = isElementInViewport();
|
|
74
|
+
|
|
75
|
+
inViewport.value = isInViewport;
|
|
76
|
+
|
|
77
|
+
if (isInViewport) {
|
|
78
|
+
nextTick(() => {
|
|
79
|
+
trRenderedHeight.value = trRef.value?.offsetHeight;
|
|
80
|
+
|
|
81
|
+
if (trRenderedHeight.value && setVirtualScrollingDefaultRowHeight) {
|
|
82
|
+
setVirtualScrollingDefaultRowHeight(trRenderedHeight.value);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function isElementInViewport() {
|
|
89
|
+
|
|
90
|
+
if (!trRef.value) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const rect = trRef.value.getBoundingClientRect();
|
|
95
|
+
|
|
96
|
+
const offsetY = 500;
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
rect.top >= -offsetY &&
|
|
100
|
+
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) + offsetY
|
|
101
|
+
);
|
|
102
|
+
}
|
|
50
103
|
|
|
51
104
|
const height = computed(() => {
|
|
52
105
|
if (isHead.value) {
|
|
@@ -84,31 +137,7 @@ const cellClass = computed(() => {
|
|
|
84
137
|
return cellClasses(cellConfig.value) + ' text-white border-t border-gray-200';
|
|
85
138
|
});
|
|
86
139
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const margin = '300px';
|
|
90
|
-
|
|
91
|
-
useIntersectionObserver(
|
|
92
|
-
trRef,
|
|
93
|
-
([{ isIntersecting }]) => {
|
|
94
|
-
|
|
95
|
-
inViewport.value = isIntersecting;
|
|
96
|
-
|
|
97
|
-
if (isIntersecting) {
|
|
98
|
-
nextTick(() => {
|
|
99
|
-
trRenderedHeight.value = trRef.value?.offsetHeight;
|
|
100
|
-
|
|
101
|
-
if (trRenderedHeight.value && setVirtualScrollingDefaultRowHeight) {
|
|
102
|
-
setVirtualScrollingDefaultRowHeight(trRenderedHeight.value);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
rootMargin: margin,
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
}
|
|
140
|
+
// Emit
|
|
112
141
|
|
|
113
142
|
const emit = defineEmits(['click', 'mouseenter', 'mouseleave']);
|
|
114
143
|
|