@raxium/vue-addons-virtual 0.1.1
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/VirtualGrid.js +34 -0
- package/dist/VirtualGrid.vue.d.ts +31 -0
- package/dist/VirtualGridImpl.js +164 -0
- package/dist/VirtualGridImpl.vue.d.ts +26 -0
- package/dist/VirtualGridItem.js +49 -0
- package/dist/VirtualGridItem.vue.d.ts +32 -0
- package/dist/VirtualInfiniteLoading.js +150 -0
- package/dist/VirtualInfiniteLoading.vue.d.ts +36 -0
- package/dist/VirtualList.js +102 -0
- package/dist/VirtualList.vue.d.ts +132 -0
- package/dist/VirtualListImpl.js +174 -0
- package/dist/VirtualListImpl.vue.d.ts +30 -0
- package/dist/VirtualListItem.js +48 -0
- package/dist/VirtualListItem.vue.d.ts +29 -0
- package/dist/VirtualRoot.d.ts +7 -0
- package/dist/VirtualRoot.js +17 -0
- package/dist/index.css +122 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/props.d.ts +38 -0
- package/dist/props.js +9 -0
- package/dist/useDetectSlotNode.d.ts +7 -0
- package/dist/useDetectSlotNode.js +24 -0
- package/dist/virtual.ai.js +13 -0
- package/package.json +55 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createBlock, createVNode, defineComponent, guardReactiveProps, normalizeProps, openBlock, renderSlot, unref, withCtx } from "vue";
|
|
2
|
+
import { VirtualRoot } from "./index.js";
|
|
3
|
+
import VirtualGridImpl from "./VirtualGridImpl.js";
|
|
4
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
5
|
+
__name: "VirtualGrid",
|
|
6
|
+
props: {
|
|
7
|
+
dataSource: {},
|
|
8
|
+
row: {},
|
|
9
|
+
column: {},
|
|
10
|
+
gap: {},
|
|
11
|
+
rowVirtualizerOptions: {},
|
|
12
|
+
columnVirtualizerOptions: {},
|
|
13
|
+
ui: {}
|
|
14
|
+
},
|
|
15
|
+
setup (__props) {
|
|
16
|
+
const props = __props;
|
|
17
|
+
return (_ctx, _cache)=>(openBlock(), createBlock(unref(VirtualRoot), null, {
|
|
18
|
+
default: withCtx(()=>[
|
|
19
|
+
createVNode(VirtualGridImpl, normalizeProps(guardReactiveProps({
|
|
20
|
+
...props,
|
|
21
|
+
..._ctx.$attrs
|
|
22
|
+
})), {
|
|
23
|
+
default: withCtx(()=>[
|
|
24
|
+
renderSlot(_ctx.$slots, "default")
|
|
25
|
+
]),
|
|
26
|
+
_: 3
|
|
27
|
+
}, 16)
|
|
28
|
+
]),
|
|
29
|
+
_: 3
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const VirtualGrid = _sfc_main;
|
|
34
|
+
export default VirtualGrid;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'vue';
|
|
2
|
+
import type { VirtualGridProps } from '.';
|
|
3
|
+
declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
4
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<VirtualGridProps<T> & {
|
|
5
|
+
ui?: {
|
|
6
|
+
viewport?: {
|
|
7
|
+
class?: HTMLAttributes["class"];
|
|
8
|
+
};
|
|
9
|
+
scroll?: {
|
|
10
|
+
class?: HTMLAttributes["class"];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}> & (typeof globalThis extends {
|
|
14
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
15
|
+
} ? P : {});
|
|
16
|
+
expose: (exposed: {}) => void;
|
|
17
|
+
attrs: any;
|
|
18
|
+
slots: {
|
|
19
|
+
default: () => any;
|
|
20
|
+
};
|
|
21
|
+
emit: {};
|
|
22
|
+
}>) => import("vue").VNode & {
|
|
23
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
24
|
+
};
|
|
25
|
+
declare const _default: typeof __VLS_export;
|
|
26
|
+
export default _default;
|
|
27
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
28
|
+
[K in keyof T]: T[K];
|
|
29
|
+
} : {
|
|
30
|
+
[K in keyof T as K]: T[K];
|
|
31
|
+
}) & {};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Fragment, cloneVNode, computed, createBlock, createElementBlock, createElementVNode, defineComponent, h, normalizeClass, normalizeStyle, openBlock, renderList, resolveDynamicComponent, unref, useTemplateRef } from "vue";
|
|
2
|
+
import { cn } from "@raxium/themes/utils";
|
|
3
|
+
import { useVirtualizer } from "@tanstack/vue-virtual";
|
|
4
|
+
import { merge } from "es-toolkit/compat";
|
|
5
|
+
import { injectVirtualContext } from "./index.js";
|
|
6
|
+
import { useDetectSlotNode } from "./useDetectSlotNode.js";
|
|
7
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
8
|
+
__name: "VirtualGridImpl",
|
|
9
|
+
props: {
|
|
10
|
+
dataSource: {},
|
|
11
|
+
row: {},
|
|
12
|
+
column: {},
|
|
13
|
+
gap: {
|
|
14
|
+
default: ()=>[
|
|
15
|
+
0,
|
|
16
|
+
0
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
rowVirtualizerOptions: {},
|
|
20
|
+
columnVirtualizerOptions: {},
|
|
21
|
+
class: {
|
|
22
|
+
type: [
|
|
23
|
+
Boolean,
|
|
24
|
+
null,
|
|
25
|
+
String,
|
|
26
|
+
Object,
|
|
27
|
+
Array
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
ui: {}
|
|
31
|
+
},
|
|
32
|
+
setup (__props) {
|
|
33
|
+
const virtualContext = injectVirtualContext();
|
|
34
|
+
const parentEl = useTemplateRef("parentEl");
|
|
35
|
+
virtualContext.parentEl = parentEl;
|
|
36
|
+
const grid = computed(()=>{
|
|
37
|
+
const isInfiniteEnable = virtualContext.enableInfinite.value;
|
|
38
|
+
if (__props.row && !__props.column) return [
|
|
39
|
+
isInfiniteEnable ? __props.row + 1 : __props.row,
|
|
40
|
+
Math.ceil(__props.dataSource.length / __props.row)
|
|
41
|
+
];
|
|
42
|
+
if (!__props.row && __props.column) return [
|
|
43
|
+
isInfiniteEnable ? Math.ceil(__props.dataSource.length / __props.column) + 1 : Math.ceil(__props.dataSource.length / __props.column),
|
|
44
|
+
__props.column
|
|
45
|
+
];
|
|
46
|
+
return [
|
|
47
|
+
isInfiniteEnable ? (__props.row ?? 1) + 1 : __props.row ?? 1,
|
|
48
|
+
__props.column ?? __props.dataSource.length
|
|
49
|
+
];
|
|
50
|
+
});
|
|
51
|
+
const rowVirtualOptions = computed(()=>{
|
|
52
|
+
const _staticOptions = {
|
|
53
|
+
enabled: true,
|
|
54
|
+
count: grid.value[0],
|
|
55
|
+
gap: __props.gap[0],
|
|
56
|
+
overscan: __props.rowVirtualizerOptions?.overscan ?? 1,
|
|
57
|
+
getScrollElement: ()=>parentEl.value,
|
|
58
|
+
estimateSize: (index)=>__props.rowVirtualizerOptions?.estimateSize?.(index) ?? 30
|
|
59
|
+
};
|
|
60
|
+
return merge({}, __props.rowVirtualizerOptions, _staticOptions);
|
|
61
|
+
});
|
|
62
|
+
const rowVirtualizer = useVirtualizer(rowVirtualOptions);
|
|
63
|
+
virtualContext.rowVirtualizer = rowVirtualizer;
|
|
64
|
+
const virtualRows = computed(()=>rowVirtualizer.value.getVirtualItems());
|
|
65
|
+
const colVirtualOptions = computed(()=>{
|
|
66
|
+
const _staticOptions = {
|
|
67
|
+
enabled: true,
|
|
68
|
+
count: grid.value[1],
|
|
69
|
+
gap: __props.gap[1],
|
|
70
|
+
overscan: __props.columnVirtualizerOptions?.overscan ?? 2,
|
|
71
|
+
horizontal: true,
|
|
72
|
+
getScrollElement: ()=>parentEl.value,
|
|
73
|
+
estimateSize: (index)=>__props.columnVirtualizerOptions?.estimateSize?.(index) ?? 30
|
|
74
|
+
};
|
|
75
|
+
return merge({}, __props.columnVirtualizerOptions, _staticOptions);
|
|
76
|
+
});
|
|
77
|
+
const colVirtualizer = useVirtualizer(colVirtualOptions);
|
|
78
|
+
virtualContext.columnVirtualizer = colVirtualizer;
|
|
79
|
+
const virtualColumns = computed(()=>colVirtualizer.value.getVirtualItems());
|
|
80
|
+
const totalSizeRows = computed(()=>rowVirtualizer.value.getTotalSize());
|
|
81
|
+
const totalSizeColumns = computed(()=>colVirtualizer.value.getTotalSize());
|
|
82
|
+
const { itemVNode, infiniteVNode } = useDetectSlotNode();
|
|
83
|
+
const virtualizedRows = computed(()=>virtualRows.value.map((virtualRow)=>{
|
|
84
|
+
const rowIndex = virtualRow.index;
|
|
85
|
+
const colVNodes = virtualColumns.value.map((virtualColumn)=>{
|
|
86
|
+
const colIndex = virtualColumn.index;
|
|
87
|
+
const realIndex = rowIndex * grid.value[1] + colIndex;
|
|
88
|
+
const data = __props.dataSource[realIndex];
|
|
89
|
+
return {
|
|
90
|
+
vItem: virtualColumn,
|
|
91
|
+
is: cloneVNode(itemVNode ?? h("div"), {
|
|
92
|
+
key: `col-${virtualColumn.key}`,
|
|
93
|
+
data,
|
|
94
|
+
index: realIndex,
|
|
95
|
+
rowIndex,
|
|
96
|
+
colIndex
|
|
97
|
+
})
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
const rowVNode = rowIndex < (virtualContext.enableInfinite.value ? grid.value[0] - 1 : grid.value[0]) ? h("div", {
|
|
101
|
+
"data-index": rowIndex,
|
|
102
|
+
key: `row-${virtualRow.key}`,
|
|
103
|
+
style: {
|
|
104
|
+
position: "absolute",
|
|
105
|
+
display: "flex",
|
|
106
|
+
top: 0,
|
|
107
|
+
left: 0,
|
|
108
|
+
gap: `${__props.gap[1]}px`,
|
|
109
|
+
transform: `
|
|
110
|
+
translateX(${colVNodes[0].vItem.start}px)
|
|
111
|
+
translateY(${virtualRow.start - rowVirtualizer.value.options.scrollMargin}px)
|
|
112
|
+
`
|
|
113
|
+
}
|
|
114
|
+
}, colVNodes.map((colVNode)=>colVNode.is)) : cloneVNode(infiniteVNode ?? h("div"), {
|
|
115
|
+
"data-index": rowIndex,
|
|
116
|
+
style: {
|
|
117
|
+
position: "absolute",
|
|
118
|
+
top: 0,
|
|
119
|
+
left: 0,
|
|
120
|
+
width: `${parentEl.value?.clientWidth ?? 0}px`,
|
|
121
|
+
transform: `
|
|
122
|
+
translateX(${Math.ceil(parentEl.value?.scrollLeft ?? 0)}px)
|
|
123
|
+
translateY(${virtualRow.start - rowVirtualizer.value.options.scrollMargin}px)
|
|
124
|
+
`
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
vItem: virtualRow,
|
|
129
|
+
is: rowVNode
|
|
130
|
+
};
|
|
131
|
+
}));
|
|
132
|
+
function measureElement(el) {
|
|
133
|
+
if (rowVirtualizer.value && el) {
|
|
134
|
+
if (el instanceof Element) rowVirtualizer.value.measureElement(el);
|
|
135
|
+
else if (el.$el) rowVirtualizer.value.measureElement(el.$el);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return (_ctx, _cache)=>(openBlock(), createElementBlock("div", {
|
|
139
|
+
ref_key: "parentEl",
|
|
140
|
+
ref: parentEl,
|
|
141
|
+
class: normalizeClass(unref(cn)("rui-virtual-grid", __props.ui?.root, __props.class)),
|
|
142
|
+
"data-scope": "virtual-grid",
|
|
143
|
+
"data-part": "root"
|
|
144
|
+
}, [
|
|
145
|
+
createElementVNode("div", {
|
|
146
|
+
class: normalizeClass(unref(cn)("rui-virtual-grid_scroll", __props.ui?.scroll)),
|
|
147
|
+
style: normalizeStyle({
|
|
148
|
+
width: `${totalSizeColumns.value}px`,
|
|
149
|
+
height: `${totalSizeRows.value}px`
|
|
150
|
+
}),
|
|
151
|
+
"data-scope": "virtual-grid",
|
|
152
|
+
"data-part": "scroll"
|
|
153
|
+
}, [
|
|
154
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(virtualizedRows.value, ({ vItem, is })=>(openBlock(), createBlock(resolveDynamicComponent(is), {
|
|
155
|
+
key: vItem.key,
|
|
156
|
+
ref_for: true,
|
|
157
|
+
ref: measureElement
|
|
158
|
+
}))), 128))
|
|
159
|
+
], 6)
|
|
160
|
+
], 2));
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
const VirtualGridImpl = _sfc_main;
|
|
164
|
+
export default VirtualGridImpl;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'vue';
|
|
2
|
+
import type { VirtualGridProps } from '.';
|
|
3
|
+
declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
4
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<VirtualGridProps<T> & {
|
|
5
|
+
class?: HTMLAttributes["class"];
|
|
6
|
+
ui?: {
|
|
7
|
+
root?: HTMLAttributes["class"];
|
|
8
|
+
scroll?: HTMLAttributes["class"];
|
|
9
|
+
};
|
|
10
|
+
}> & (typeof globalThis extends {
|
|
11
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
12
|
+
} ? P : {});
|
|
13
|
+
expose: (exposed: {}) => void;
|
|
14
|
+
attrs: any;
|
|
15
|
+
slots: {};
|
|
16
|
+
emit: {};
|
|
17
|
+
}>) => import("vue").VNode & {
|
|
18
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
19
|
+
};
|
|
20
|
+
declare const _default: typeof __VLS_export;
|
|
21
|
+
export default _default;
|
|
22
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
23
|
+
[K in keyof T]: T[K];
|
|
24
|
+
} : {
|
|
25
|
+
[K in keyof T as K]: T[K];
|
|
26
|
+
}) & {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createElementBlock, defineComponent, mergeProps, openBlock, renderSlot, unref, useTemplateRef, watch } from "vue";
|
|
2
|
+
import { cn } from "@raxium/themes/utils";
|
|
3
|
+
import { injectVirtualContext } from "./index.js";
|
|
4
|
+
const _hoisted_1 = [
|
|
5
|
+
"data-index"
|
|
6
|
+
];
|
|
7
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
8
|
+
name: "VirtualGridItem",
|
|
9
|
+
__name: "VirtualGridItem",
|
|
10
|
+
props: {
|
|
11
|
+
data: {},
|
|
12
|
+
class: {
|
|
13
|
+
type: [
|
|
14
|
+
Boolean,
|
|
15
|
+
null,
|
|
16
|
+
String,
|
|
17
|
+
Object,
|
|
18
|
+
Array
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
index: {},
|
|
22
|
+
rowIndex: {},
|
|
23
|
+
colIndex: {}
|
|
24
|
+
},
|
|
25
|
+
setup (__props) {
|
|
26
|
+
const { columnVirtualizer } = injectVirtualContext();
|
|
27
|
+
const el = useTemplateRef("el");
|
|
28
|
+
watch(el, (el)=>{
|
|
29
|
+
if (columnVirtualizer?.value && el) columnVirtualizer.value.measureElement(el);
|
|
30
|
+
});
|
|
31
|
+
return (_ctx, _cache)=>(openBlock(), createElementBlock("div", mergeProps(_ctx.$attrs, {
|
|
32
|
+
ref_key: "el",
|
|
33
|
+
ref: el,
|
|
34
|
+
class: unref(cn)("rui-virtual-grid-item", __props.class),
|
|
35
|
+
"data-index": __props.index,
|
|
36
|
+
"data-scope": "virtual-grid",
|
|
37
|
+
"data-part": "item"
|
|
38
|
+
}), [
|
|
39
|
+
renderSlot(_ctx.$slots, "default", {
|
|
40
|
+
data: __props.data,
|
|
41
|
+
index: __props.index,
|
|
42
|
+
rowIndex: __props.rowIndex,
|
|
43
|
+
colIndex: __props.colIndex
|
|
44
|
+
})
|
|
45
|
+
], 16, _hoisted_1));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const VirtualGridItem = _sfc_main;
|
|
49
|
+
export default VirtualGridItem;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'vue';
|
|
2
|
+
declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
3
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<{
|
|
4
|
+
data?: T;
|
|
5
|
+
class?: HTMLAttributes["class"];
|
|
6
|
+
index?: number;
|
|
7
|
+
rowIndex?: number;
|
|
8
|
+
colIndex?: number;
|
|
9
|
+
}> & (typeof globalThis extends {
|
|
10
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
11
|
+
} ? P : {});
|
|
12
|
+
expose: (exposed: {}) => void;
|
|
13
|
+
attrs: any;
|
|
14
|
+
slots: {
|
|
15
|
+
default: {
|
|
16
|
+
data: T;
|
|
17
|
+
index?: number;
|
|
18
|
+
rowIndex?: number;
|
|
19
|
+
colIndex?: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
emit: {};
|
|
23
|
+
}>) => import("vue").VNode & {
|
|
24
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
25
|
+
};
|
|
26
|
+
declare const _default: typeof __VLS_export;
|
|
27
|
+
export default _default;
|
|
28
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
29
|
+
[K in keyof T]: T[K];
|
|
30
|
+
} : {
|
|
31
|
+
[K in keyof T as K]: T[K];
|
|
32
|
+
}) & {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, onMounted, onUnmounted, openBlock, renderSlot, shallowRef, unref } from "vue";
|
|
2
|
+
import { cn } from "@raxium/themes/utils";
|
|
3
|
+
import { useForwardExpose } from "@raxium/vue-addons-shared";
|
|
4
|
+
import { LoaderCircle } from "lucide-vue-next";
|
|
5
|
+
import { LOADING_STATE, injectVirtualContext } from "./index.js";
|
|
6
|
+
const _hoisted_1 = [
|
|
7
|
+
"data-size"
|
|
8
|
+
];
|
|
9
|
+
const _hoisted_2 = [
|
|
10
|
+
"data-size"
|
|
11
|
+
];
|
|
12
|
+
const _hoisted_3 = [
|
|
13
|
+
"data-size"
|
|
14
|
+
];
|
|
15
|
+
const _hoisted_4 = [
|
|
16
|
+
"data-size"
|
|
17
|
+
];
|
|
18
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
19
|
+
name: "VirtualInfiniteLoading",
|
|
20
|
+
__name: "VirtualInfiniteLoading",
|
|
21
|
+
props: {
|
|
22
|
+
class: {
|
|
23
|
+
type: [
|
|
24
|
+
Boolean,
|
|
25
|
+
null,
|
|
26
|
+
String,
|
|
27
|
+
Object,
|
|
28
|
+
Array
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
enableFirstLoad: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: true
|
|
34
|
+
},
|
|
35
|
+
enableRetry: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
default: true
|
|
38
|
+
},
|
|
39
|
+
size: {
|
|
40
|
+
default: "base"
|
|
41
|
+
},
|
|
42
|
+
ui: {}
|
|
43
|
+
},
|
|
44
|
+
emits: [
|
|
45
|
+
"infinite"
|
|
46
|
+
],
|
|
47
|
+
setup (__props, { emit: __emit }) {
|
|
48
|
+
const emit = __emit;
|
|
49
|
+
const context = injectVirtualContext();
|
|
50
|
+
const { infiniteState: state } = context;
|
|
51
|
+
const stateHandler = {
|
|
52
|
+
loading () {
|
|
53
|
+
state.value = LOADING_STATE.LOADING;
|
|
54
|
+
},
|
|
55
|
+
loaded () {
|
|
56
|
+
state.value = LOADING_STATE.LOADED;
|
|
57
|
+
},
|
|
58
|
+
complete () {
|
|
59
|
+
state.value = LOADING_STATE.COMPLETE;
|
|
60
|
+
},
|
|
61
|
+
error () {
|
|
62
|
+
state.value = LOADING_STATE.ERROR;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
function doInfinite() {
|
|
66
|
+
stateHandler.loading();
|
|
67
|
+
emit("infinite", stateHandler);
|
|
68
|
+
}
|
|
69
|
+
const { virtualizer } = injectVirtualContext();
|
|
70
|
+
const { forwardRef, currentRef } = useForwardExpose();
|
|
71
|
+
const observer = shallowRef(null);
|
|
72
|
+
onMounted(()=>{
|
|
73
|
+
if (state.value === LOADING_STATE.IDLE && __props.enableFirstLoad) return void doInfinite();
|
|
74
|
+
if (state.value === LOADING_STATE.LOADED) stateHandler.loading();
|
|
75
|
+
observer.value = new IntersectionObserver((entries)=>{
|
|
76
|
+
const entry = entries[0];
|
|
77
|
+
if (entry.isIntersecting && state.value === LOADING_STATE.LOADING) doInfinite();
|
|
78
|
+
}, {
|
|
79
|
+
root: context.parentEl?.value,
|
|
80
|
+
rootMargin: "0px 0px 0px 0px"
|
|
81
|
+
});
|
|
82
|
+
if (currentRef.value) observer.value?.observe(currentRef.value);
|
|
83
|
+
});
|
|
84
|
+
onUnmounted(()=>{
|
|
85
|
+
observer.value?.disconnect();
|
|
86
|
+
observer.value = null;
|
|
87
|
+
});
|
|
88
|
+
return (_ctx, _cache)=>(openBlock(), createElementBlock("div", {
|
|
89
|
+
ref: (el)=>{
|
|
90
|
+
if (unref(virtualizer) && el) unref(virtualizer).measureElement(el);
|
|
91
|
+
unref(forwardRef)(el);
|
|
92
|
+
},
|
|
93
|
+
class: normalizeClass(unref(cn)("rui-virtual-infinite", __props.ui?.root, __props.class)),
|
|
94
|
+
"data-scope": "virtual-infinite",
|
|
95
|
+
"data-part": "root",
|
|
96
|
+
"data-size": __props.size
|
|
97
|
+
}, [
|
|
98
|
+
"loading" === unref(state) ? renderSlot(_ctx.$slots, "loading", {
|
|
99
|
+
key: 0
|
|
100
|
+
}, ()=>[
|
|
101
|
+
createElementVNode("div", {
|
|
102
|
+
class: normalizeClass(unref(cn)("rui-virtual-infinite_loading", __props.ui?.loading)),
|
|
103
|
+
"data-scope": "virtual-infinite",
|
|
104
|
+
"data-part": "loading",
|
|
105
|
+
"data-size": __props.size
|
|
106
|
+
}, [
|
|
107
|
+
renderSlot(_ctx.$slots, "spinner", {}, ()=>[
|
|
108
|
+
createVNode(unref(LoaderCircle), {
|
|
109
|
+
class: normalizeClass(unref(cn)("rui-virtual-infinite_spinner", __props.ui?.spinner)),
|
|
110
|
+
"data-scope": "virtual-infinite",
|
|
111
|
+
"data-part": "spinner",
|
|
112
|
+
"data-size": __props.size
|
|
113
|
+
}, null, 8, [
|
|
114
|
+
"class",
|
|
115
|
+
"data-size"
|
|
116
|
+
])
|
|
117
|
+
])
|
|
118
|
+
], 10, _hoisted_2)
|
|
119
|
+
]) : "complete" === unref(state) ? renderSlot(_ctx.$slots, "complete", {
|
|
120
|
+
key: 1
|
|
121
|
+
}, ()=>[
|
|
122
|
+
createElementVNode("div", {
|
|
123
|
+
class: normalizeClass(unref(cn)("rui-virtual-infinite_complete", __props.ui?.complete)),
|
|
124
|
+
"data-scope": "virtual-infinite",
|
|
125
|
+
"data-part": "complete",
|
|
126
|
+
"data-size": __props.size
|
|
127
|
+
}, " No more results! ", 10, _hoisted_3)
|
|
128
|
+
]) : "error" === unref(state) ? renderSlot(_ctx.$slots, "error", {
|
|
129
|
+
key: 2,
|
|
130
|
+
retry: doInfinite
|
|
131
|
+
}, ()=>[
|
|
132
|
+
createElementVNode("div", {
|
|
133
|
+
class: normalizeClass(unref(cn)("rui-virtual-infinite_error", __props.ui?.error)),
|
|
134
|
+
"data-scope": "virtual-infinite",
|
|
135
|
+
"data-part": "error",
|
|
136
|
+
"data-size": __props.size
|
|
137
|
+
}, [
|
|
138
|
+
_cache[0] || (_cache[0] = createElementVNode("span", null, "Oops something went wrong!", -1)),
|
|
139
|
+
__props.enableRetry ? (openBlock(), createElementBlock("button", {
|
|
140
|
+
key: 0,
|
|
141
|
+
class: "retry",
|
|
142
|
+
onClick: doInfinite
|
|
143
|
+
}, " retry ")) : createCommentVNode("", true)
|
|
144
|
+
], 10, _hoisted_4)
|
|
145
|
+
]) : createCommentVNode("", true)
|
|
146
|
+
], 10, _hoisted_1));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const VirtualInfiniteLoading = _sfc_main;
|
|
150
|
+
export default VirtualInfiniteLoading;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'vue';
|
|
2
|
+
import type { LoadingStateHandler } from '.';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
class?: HTMLAttributes['class'];
|
|
5
|
+
enableFirstLoad?: boolean;
|
|
6
|
+
enableRetry?: boolean;
|
|
7
|
+
size?: 'xs' | 'sm' | 'base' | 'lg';
|
|
8
|
+
ui?: {
|
|
9
|
+
root?: HTMLAttributes['class'];
|
|
10
|
+
loading?: HTMLAttributes['class'];
|
|
11
|
+
spinner?: HTMLAttributes['class'];
|
|
12
|
+
complete?: HTMLAttributes['class'];
|
|
13
|
+
error?: HTMLAttributes['class'];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
type __VLS_Slots = {
|
|
17
|
+
loading: (props: {}) => any;
|
|
18
|
+
spinner: (props: {}) => any;
|
|
19
|
+
complete: (props: {}) => any;
|
|
20
|
+
error: (props: {
|
|
21
|
+
retry: () => void;
|
|
22
|
+
}) => any;
|
|
23
|
+
};
|
|
24
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
25
|
+
infinite: ($state: LoadingStateHandler) => any;
|
|
26
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
27
|
+
onInfinite?: (($state: LoadingStateHandler) => any) | undefined;
|
|
28
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
29
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
30
|
+
declare const _default: typeof __VLS_export;
|
|
31
|
+
export default _default;
|
|
32
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
33
|
+
new (): {
|
|
34
|
+
$slots: S;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createBlock, createVNode, defineComponent, mergeProps, openBlock, ref, renderSlot, unref, withCtx } from "vue";
|
|
2
|
+
import { useForwardExpose } from "@raxium/vue-addons-shared";
|
|
3
|
+
import { VirtualRoot } from "./index.js";
|
|
4
|
+
import VirtualListImpl from "./VirtualListImpl.js";
|
|
5
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
6
|
+
__name: "VirtualList",
|
|
7
|
+
props: {
|
|
8
|
+
dataSource: {},
|
|
9
|
+
estimateSize: {
|
|
10
|
+
type: Function
|
|
11
|
+
},
|
|
12
|
+
scrollToFn: {
|
|
13
|
+
type: Function
|
|
14
|
+
},
|
|
15
|
+
observeElementRect: {
|
|
16
|
+
type: Function
|
|
17
|
+
},
|
|
18
|
+
observeElementOffset: {
|
|
19
|
+
type: Function
|
|
20
|
+
},
|
|
21
|
+
debug: {
|
|
22
|
+
type: Boolean
|
|
23
|
+
},
|
|
24
|
+
initialRect: {},
|
|
25
|
+
onChange: {
|
|
26
|
+
type: Function
|
|
27
|
+
},
|
|
28
|
+
measureElement: {
|
|
29
|
+
type: Function
|
|
30
|
+
},
|
|
31
|
+
overscan: {},
|
|
32
|
+
horizontal: {
|
|
33
|
+
type: Boolean
|
|
34
|
+
},
|
|
35
|
+
paddingStart: {},
|
|
36
|
+
paddingEnd: {},
|
|
37
|
+
scrollPaddingStart: {},
|
|
38
|
+
scrollPaddingEnd: {},
|
|
39
|
+
initialOffset: {
|
|
40
|
+
type: [
|
|
41
|
+
Number,
|
|
42
|
+
Function
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
getItemKey: {
|
|
46
|
+
type: Function
|
|
47
|
+
},
|
|
48
|
+
rangeExtractor: {
|
|
49
|
+
type: Function
|
|
50
|
+
},
|
|
51
|
+
scrollMargin: {},
|
|
52
|
+
gap: {},
|
|
53
|
+
indexAttribute: {},
|
|
54
|
+
initialMeasurementsCache: {},
|
|
55
|
+
lanes: {},
|
|
56
|
+
isScrollingResetDelay: {},
|
|
57
|
+
useScrollendEvent: {
|
|
58
|
+
type: Boolean
|
|
59
|
+
},
|
|
60
|
+
isRtl: {
|
|
61
|
+
type: Boolean
|
|
62
|
+
},
|
|
63
|
+
useAnimationFrameWithResizeObserver: {
|
|
64
|
+
type: Boolean
|
|
65
|
+
},
|
|
66
|
+
unstyled: {
|
|
67
|
+
type: Boolean
|
|
68
|
+
},
|
|
69
|
+
ui: {}
|
|
70
|
+
},
|
|
71
|
+
setup (__props, { expose: __expose }) {
|
|
72
|
+
const props = __props;
|
|
73
|
+
const virtualizer = ref(null);
|
|
74
|
+
__expose({
|
|
75
|
+
get virtualizer () {
|
|
76
|
+
return virtualizer.value;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const { forwardRef } = useForwardExpose();
|
|
80
|
+
return (_ctx, _cache)=>(openBlock(), createBlock(unref(VirtualRoot), null, {
|
|
81
|
+
default: withCtx(()=>[
|
|
82
|
+
createVNode(VirtualListImpl, mergeProps({
|
|
83
|
+
...props,
|
|
84
|
+
..._ctx.$attrs
|
|
85
|
+
}, {
|
|
86
|
+
ref: (innerExpose)=>{
|
|
87
|
+
virtualizer.value = innerExpose?.virtualizer ?? null;
|
|
88
|
+
unref(forwardRef)(innerExpose);
|
|
89
|
+
}
|
|
90
|
+
}), {
|
|
91
|
+
default: withCtx(()=>[
|
|
92
|
+
renderSlot(_ctx.$slots, "default")
|
|
93
|
+
]),
|
|
94
|
+
_: 3
|
|
95
|
+
}, 16)
|
|
96
|
+
]),
|
|
97
|
+
_: 3
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const VirtualList = _sfc_main;
|
|
102
|
+
export default VirtualList;
|