@sellmate/design-system-vue 1.0.59 → 1.0.60
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.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
export interface VirtualRow<T = Record<string, any>> {
|
|
3
|
+
/** 전체 rows 기준 절대 인덱스 — sd-tr의 rowKey로 사용 */
|
|
4
|
+
index: number;
|
|
5
|
+
row: T;
|
|
6
|
+
}
|
|
7
|
+
export declare function useSdTableVirtualScroll<T extends Record<string, any>>(tableRef: Ref<any>, rows: Ref<T[]>): {
|
|
8
|
+
virtualRows: import("vue").ComputedRef<VirtualRow<T>[]>;
|
|
9
|
+
from: import("vue").ComputedRef<number>;
|
|
10
|
+
to: import("vue").ComputedRef<number>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ref, computed, onMounted, onUnmounted } from 'vue';
|
|
2
|
+
export function useSdTableVirtualScroll(tableRef, rows) {
|
|
3
|
+
const range = ref(null);
|
|
4
|
+
let targetEl = null;
|
|
5
|
+
let rafId = 0;
|
|
6
|
+
const onVirtualUpdate = (e) => {
|
|
7
|
+
const { from, to } = e.detail;
|
|
8
|
+
range.value = { from, to };
|
|
9
|
+
};
|
|
10
|
+
const syncRange = (el) => {
|
|
11
|
+
const currentRange = el.getVirtualScrollRangeSync?.();
|
|
12
|
+
if (currentRange &&
|
|
13
|
+
typeof currentRange.from === 'number' &&
|
|
14
|
+
typeof currentRange.to === 'number') {
|
|
15
|
+
range.value = { from: currentRange.from, to: currentRange.to };
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
const attachWhenReady = () => {
|
|
21
|
+
// Stencil Vue 래퍼는 expose()를 사용하지 않으므로 $el로 실제 custom element에 접근
|
|
22
|
+
const raw = tableRef.value?.$el ?? tableRef.value;
|
|
23
|
+
const el = raw instanceof HTMLElement ? raw : null;
|
|
24
|
+
if (!el) {
|
|
25
|
+
rafId = requestAnimationFrame(attachWhenReady);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
targetEl = el;
|
|
29
|
+
targetEl.addEventListener('sdVirtualUpdate', onVirtualUpdate);
|
|
30
|
+
const trySync = () => {
|
|
31
|
+
if (!targetEl)
|
|
32
|
+
return;
|
|
33
|
+
if (!syncRange(targetEl)) {
|
|
34
|
+
rafId = requestAnimationFrame(trySync);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
trySync();
|
|
38
|
+
};
|
|
39
|
+
onMounted(() => {
|
|
40
|
+
attachWhenReady();
|
|
41
|
+
});
|
|
42
|
+
onUnmounted(() => {
|
|
43
|
+
cancelAnimationFrame(rafId);
|
|
44
|
+
targetEl?.removeEventListener('sdVirtualUpdate', onVirtualUpdate);
|
|
45
|
+
targetEl = null;
|
|
46
|
+
});
|
|
47
|
+
const virtualRows = computed(() => {
|
|
48
|
+
if (!range.value)
|
|
49
|
+
return [];
|
|
50
|
+
const { from, to } = range.value;
|
|
51
|
+
return rows.value.slice(from, to).map((row, i) => ({ index: from + i, row }));
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
virtualRows,
|
|
55
|
+
from: computed(() => range.value?.from ?? 0),
|
|
56
|
+
to: computed(() => range.value?.to ?? 0),
|
|
57
|
+
};
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sellmate/design-system-vue",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.60",
|
|
4
4
|
"description": "Design System - Vue Component Wrappers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"vue": "^3.4.38"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@sellmate/design-system": "^1.0.
|
|
48
|
+
"@sellmate/design-system": "^1.0.60",
|
|
49
49
|
"@stencil/vue-output-target": "^0.11.8"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|