@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,132 @@
|
|
|
1
|
+
import type { Virtualizer } from '@tanstack/vue-virtual';
|
|
2
|
+
import type { HTMLAttributes } from 'vue';
|
|
3
|
+
import type { VirtualListProps } from '.';
|
|
4
|
+
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<{
|
|
5
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<VirtualListProps<T> & {
|
|
6
|
+
unstyled?: boolean;
|
|
7
|
+
ui?: {
|
|
8
|
+
viewport?: {
|
|
9
|
+
class?: HTMLAttributes["class"];
|
|
10
|
+
};
|
|
11
|
+
scroll?: {
|
|
12
|
+
class?: HTMLAttributes["class"];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}> & (typeof globalThis extends {
|
|
16
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
17
|
+
} ? P : {});
|
|
18
|
+
expose: (exposed: import("vue").ShallowUnwrapRef<{
|
|
19
|
+
readonly virtualizer: {
|
|
20
|
+
options: {
|
|
21
|
+
count: number;
|
|
22
|
+
getScrollElement: () => Element | null;
|
|
23
|
+
estimateSize: (index: number) => number;
|
|
24
|
+
scrollToFn: (offset: number, options: {
|
|
25
|
+
adjustments?: number;
|
|
26
|
+
behavior?: "auto" | "smooth" | "instant";
|
|
27
|
+
}, instance: Virtualizer<Element, Element>) => void;
|
|
28
|
+
observeElementRect: (instance: Virtualizer<Element, Element>, cb: (rect: import("@tanstack/vue-virtual").Rect) => void) => void | (() => void);
|
|
29
|
+
observeElementOffset: (instance: Virtualizer<Element, Element>, cb: (offset: number, isScrolling: boolean) => void) => void | (() => void);
|
|
30
|
+
debug: boolean;
|
|
31
|
+
initialRect: {
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
};
|
|
35
|
+
onChange: (instance: Virtualizer<Element, Element>, sync: boolean) => void;
|
|
36
|
+
measureElement: (element: Element, entry: ResizeObserverEntry | undefined, instance: Virtualizer<Element, Element>) => number;
|
|
37
|
+
overscan: number;
|
|
38
|
+
horizontal: boolean;
|
|
39
|
+
paddingStart: number;
|
|
40
|
+
paddingEnd: number;
|
|
41
|
+
scrollPaddingStart: number;
|
|
42
|
+
scrollPaddingEnd: number;
|
|
43
|
+
initialOffset: number | (() => number);
|
|
44
|
+
getItemKey: (index: number) => string | number | bigint;
|
|
45
|
+
rangeExtractor: (range: import("@tanstack/vue-virtual").Range) => Array<number>;
|
|
46
|
+
scrollMargin: number;
|
|
47
|
+
gap: number;
|
|
48
|
+
indexAttribute: string;
|
|
49
|
+
initialMeasurementsCache: {
|
|
50
|
+
key: string | number | bigint;
|
|
51
|
+
index: number;
|
|
52
|
+
start: number;
|
|
53
|
+
end: number;
|
|
54
|
+
size: number;
|
|
55
|
+
lane: number;
|
|
56
|
+
}[];
|
|
57
|
+
lanes: number;
|
|
58
|
+
isScrollingResetDelay: number;
|
|
59
|
+
useScrollendEvent: boolean;
|
|
60
|
+
enabled: boolean;
|
|
61
|
+
isRtl: boolean;
|
|
62
|
+
useAnimationFrameWithResizeObserver: boolean;
|
|
63
|
+
};
|
|
64
|
+
scrollElement: Element | null;
|
|
65
|
+
targetWindow: (Window & typeof globalThis) | null;
|
|
66
|
+
isScrolling: boolean;
|
|
67
|
+
measurementsCache: {
|
|
68
|
+
key: string | number | bigint;
|
|
69
|
+
index: number;
|
|
70
|
+
start: number;
|
|
71
|
+
end: number;
|
|
72
|
+
size: number;
|
|
73
|
+
lane: number;
|
|
74
|
+
}[];
|
|
75
|
+
scrollRect: {
|
|
76
|
+
width: number;
|
|
77
|
+
height: number;
|
|
78
|
+
} | null;
|
|
79
|
+
scrollOffset: number | null;
|
|
80
|
+
scrollDirection: ("forward" | "backward") | null;
|
|
81
|
+
shouldAdjustScrollPositionOnItemSizeChange: ((item: import("@tanstack/vue-virtual").VirtualItem, delta: number, instance: Virtualizer<Element, Element>) => boolean) | undefined;
|
|
82
|
+
elementsCache: Map<string | number | bigint, Element> & Omit<Map<string | number | bigint, Element>, keyof Map<any, any>>;
|
|
83
|
+
range: {
|
|
84
|
+
startIndex: number;
|
|
85
|
+
endIndex: number;
|
|
86
|
+
} | null;
|
|
87
|
+
setOptions: (opts: import("@tanstack/vue-virtual").VirtualizerOptions<Element, Element>) => void;
|
|
88
|
+
_didMount: () => () => void;
|
|
89
|
+
_willUpdate: () => void;
|
|
90
|
+
calculateRange: {
|
|
91
|
+
(): {
|
|
92
|
+
startIndex: number;
|
|
93
|
+
endIndex: number;
|
|
94
|
+
} | null;
|
|
95
|
+
updateDeps(newDeps: [import("@tanstack/vue-virtual").VirtualItem[], number, number, number]): void;
|
|
96
|
+
};
|
|
97
|
+
getVirtualIndexes: {
|
|
98
|
+
(): number[];
|
|
99
|
+
updateDeps(newDeps: [(range: import("@tanstack/vue-virtual").Range) => number[], number, number, number | null, number | null]): void;
|
|
100
|
+
};
|
|
101
|
+
indexFromElement: (node: Element) => number;
|
|
102
|
+
measureElement: (node: Element | null) => void;
|
|
103
|
+
resizeItem: (index: number, size: number) => void;
|
|
104
|
+
getVirtualItems: {
|
|
105
|
+
(): import("@tanstack/vue-virtual").VirtualItem[];
|
|
106
|
+
updateDeps(newDeps: [number[], import("@tanstack/vue-virtual").VirtualItem[]]): void;
|
|
107
|
+
};
|
|
108
|
+
getVirtualItemForOffset: (offset: number) => import("@tanstack/vue-virtual").VirtualItem | undefined;
|
|
109
|
+
getOffsetForAlignment: (toOffset: number, align: "auto" | "end" | "start" | "center", itemSize?: number) => number;
|
|
110
|
+
getOffsetForIndex: (index: number, align?: "auto" | "end" | "start" | "center") => readonly [number, "auto"] | readonly [number, "start" | "center" | "end"] | undefined;
|
|
111
|
+
scrollToOffset: (toOffset: number, { align, behavior }?: import("@tanstack/vue-virtual").ScrollToOptions) => void;
|
|
112
|
+
scrollToIndex: (index: number, { align: initialAlign, behavior, }?: import("@tanstack/vue-virtual").ScrollToOptions) => void;
|
|
113
|
+
scrollBy: (delta: number, { behavior }?: import("@tanstack/vue-virtual").ScrollToOptions) => void;
|
|
114
|
+
getTotalSize: () => number;
|
|
115
|
+
measure: () => void;
|
|
116
|
+
} | null;
|
|
117
|
+
}>) => void;
|
|
118
|
+
attrs: any;
|
|
119
|
+
slots: {
|
|
120
|
+
default: () => any;
|
|
121
|
+
};
|
|
122
|
+
emit: {};
|
|
123
|
+
}>) => import("vue").VNode & {
|
|
124
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
125
|
+
};
|
|
126
|
+
declare const _default: typeof __VLS_export;
|
|
127
|
+
export default _default;
|
|
128
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
129
|
+
[K in keyof T]: T[K];
|
|
130
|
+
} : {
|
|
131
|
+
[K in keyof T as K]: T[K];
|
|
132
|
+
}) & {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Fragment, cloneVNode, computed, createBlock, createElementBlock, createElementVNode, createPropsRestProxy, defineComponent, h, normalizeClass, normalizeStyle, openBlock, renderList, resolveDynamicComponent, unref, useTemplateRef } from "vue";
|
|
2
|
+
import { cn } from "@raxium/themes/utils";
|
|
3
|
+
import { useForwardProps } from "@raxium/vue-addons-shared";
|
|
4
|
+
import { useVirtualizer } from "@tanstack/vue-virtual";
|
|
5
|
+
import { merge } from "es-toolkit/compat";
|
|
6
|
+
import { injectVirtualContext } from "./index.js";
|
|
7
|
+
import { useDetectSlotNode } from "./useDetectSlotNode.js";
|
|
8
|
+
const _hoisted_1 = [
|
|
9
|
+
"data-horizontal"
|
|
10
|
+
];
|
|
11
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
12
|
+
__name: "VirtualListImpl",
|
|
13
|
+
props: {
|
|
14
|
+
dataSource: {},
|
|
15
|
+
estimateSize: {
|
|
16
|
+
type: Function
|
|
17
|
+
},
|
|
18
|
+
scrollToFn: {
|
|
19
|
+
type: Function
|
|
20
|
+
},
|
|
21
|
+
observeElementRect: {
|
|
22
|
+
type: Function
|
|
23
|
+
},
|
|
24
|
+
observeElementOffset: {
|
|
25
|
+
type: Function
|
|
26
|
+
},
|
|
27
|
+
debug: {
|
|
28
|
+
type: Boolean
|
|
29
|
+
},
|
|
30
|
+
initialRect: {},
|
|
31
|
+
onChange: {
|
|
32
|
+
type: Function
|
|
33
|
+
},
|
|
34
|
+
measureElement: {
|
|
35
|
+
type: Function
|
|
36
|
+
},
|
|
37
|
+
overscan: {},
|
|
38
|
+
horizontal: {
|
|
39
|
+
type: Boolean
|
|
40
|
+
},
|
|
41
|
+
paddingStart: {},
|
|
42
|
+
paddingEnd: {},
|
|
43
|
+
scrollPaddingStart: {},
|
|
44
|
+
scrollPaddingEnd: {},
|
|
45
|
+
initialOffset: {
|
|
46
|
+
type: [
|
|
47
|
+
Number,
|
|
48
|
+
Function
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
getItemKey: {
|
|
52
|
+
type: Function
|
|
53
|
+
},
|
|
54
|
+
rangeExtractor: {
|
|
55
|
+
type: Function
|
|
56
|
+
},
|
|
57
|
+
scrollMargin: {},
|
|
58
|
+
gap: {},
|
|
59
|
+
indexAttribute: {},
|
|
60
|
+
initialMeasurementsCache: {},
|
|
61
|
+
lanes: {},
|
|
62
|
+
isScrollingResetDelay: {},
|
|
63
|
+
useScrollendEvent: {
|
|
64
|
+
type: Boolean
|
|
65
|
+
},
|
|
66
|
+
isRtl: {
|
|
67
|
+
type: Boolean
|
|
68
|
+
},
|
|
69
|
+
useAnimationFrameWithResizeObserver: {
|
|
70
|
+
type: Boolean
|
|
71
|
+
},
|
|
72
|
+
class: {
|
|
73
|
+
type: [
|
|
74
|
+
Boolean,
|
|
75
|
+
null,
|
|
76
|
+
String,
|
|
77
|
+
Object,
|
|
78
|
+
Array
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
ui: {}
|
|
82
|
+
},
|
|
83
|
+
setup (__props, { expose: __expose }) {
|
|
84
|
+
const props = createPropsRestProxy(__props, [
|
|
85
|
+
"class",
|
|
86
|
+
"dataSource",
|
|
87
|
+
"ui"
|
|
88
|
+
]);
|
|
89
|
+
const virtualContext = injectVirtualContext();
|
|
90
|
+
const parentEl = useTemplateRef("parentEl");
|
|
91
|
+
virtualContext.parentEl = parentEl;
|
|
92
|
+
const forwarded = useForwardProps(props);
|
|
93
|
+
const virtualOptions = computed(()=>{
|
|
94
|
+
const _staticOptions = {
|
|
95
|
+
enabled: true,
|
|
96
|
+
count: virtualContext.enableInfinite.value ? __props.dataSource.length + 1 : __props.dataSource.length,
|
|
97
|
+
overscan: forwarded.value.overscan ?? 1,
|
|
98
|
+
getScrollElement: ()=>parentEl.value,
|
|
99
|
+
estimateSize: (index)=>forwarded.value.estimateSize?.(index) ?? 30
|
|
100
|
+
};
|
|
101
|
+
return merge({}, forwarded.value, _staticOptions);
|
|
102
|
+
});
|
|
103
|
+
const virtualizer = useVirtualizer(virtualOptions);
|
|
104
|
+
virtualContext.virtualizer = virtualizer;
|
|
105
|
+
const { itemVNode, infiniteVNode } = useDetectSlotNode();
|
|
106
|
+
const virtualizedItems = computed(()=>virtualizer.value.getVirtualItems().map((virtualItem)=>{
|
|
107
|
+
const _realIndex = virtualItem.index;
|
|
108
|
+
const renderNode = _realIndex < __props.dataSource.length ? itemVNode : infiniteVNode;
|
|
109
|
+
return {
|
|
110
|
+
vItem: virtualItem,
|
|
111
|
+
is: cloneVNode(renderNode ?? h("div"), {
|
|
112
|
+
data: __props.dataSource[_realIndex],
|
|
113
|
+
index: _realIndex,
|
|
114
|
+
key: `${virtualItem.key}`,
|
|
115
|
+
"data-index": _realIndex,
|
|
116
|
+
"aria-setsize": __props.dataSource.length,
|
|
117
|
+
"aria-posinset": _realIndex + 1,
|
|
118
|
+
style: forwarded.value.horizontal ? {
|
|
119
|
+
position: "absolute",
|
|
120
|
+
top: 0,
|
|
121
|
+
left: 0,
|
|
122
|
+
transform: `translateX(${virtualItem.start}px)`,
|
|
123
|
+
overflowAnchor: "none"
|
|
124
|
+
} : {
|
|
125
|
+
position: "absolute",
|
|
126
|
+
top: 0,
|
|
127
|
+
left: 0,
|
|
128
|
+
transform: `translateY(${virtualItem.start}px)`,
|
|
129
|
+
overflowAnchor: "none"
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
};
|
|
133
|
+
}));
|
|
134
|
+
const scrollAreaStyle = computed(()=>{
|
|
135
|
+
const totalSize = virtualizer.value.getTotalSize();
|
|
136
|
+
if (forwarded.value.horizontal) return {
|
|
137
|
+
width: `${totalSize}px`,
|
|
138
|
+
height: "100%",
|
|
139
|
+
position: "relative"
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
height: `${totalSize}px`,
|
|
143
|
+
width: "100%",
|
|
144
|
+
position: "relative"
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
__expose({
|
|
148
|
+
get virtualizer () {
|
|
149
|
+
return virtualizer.value;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return (_ctx, _cache)=>(openBlock(), createElementBlock("div", {
|
|
153
|
+
ref_key: "parentEl",
|
|
154
|
+
ref: parentEl,
|
|
155
|
+
class: normalizeClass(unref(cn)("rui-virtual-list", __props.ui?.root, __props.class)),
|
|
156
|
+
"data-horizontal": unref(forwarded).horizontal ? true : void 0,
|
|
157
|
+
"data-scope": "virtual-list",
|
|
158
|
+
"data-part": "root"
|
|
159
|
+
}, [
|
|
160
|
+
createElementVNode("div", {
|
|
161
|
+
class: normalizeClass(unref(cn)("rui-virtual-list_scroll", __props.ui?.scroll)),
|
|
162
|
+
style: normalizeStyle(scrollAreaStyle.value),
|
|
163
|
+
"data-scope": "virtual-list",
|
|
164
|
+
"data-part": "scroll"
|
|
165
|
+
}, [
|
|
166
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(virtualizedItems.value, ({ is, vItem })=>(openBlock(), createBlock(resolveDynamicComponent(is), {
|
|
167
|
+
key: vItem.key
|
|
168
|
+
}))), 128))
|
|
169
|
+
], 6)
|
|
170
|
+
], 10, _hoisted_1));
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const VirtualListImpl = _sfc_main;
|
|
174
|
+
export default VirtualListImpl;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'vue';
|
|
2
|
+
import type { VirtualListProps } 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<VirtualListProps<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: import("vue").ShallowUnwrapRef<{
|
|
14
|
+
readonly virtualizer: import("@tanstack/vue-virtual").Virtualizer<Element, Element>;
|
|
15
|
+
}>) => void;
|
|
16
|
+
attrs: any;
|
|
17
|
+
slots: {
|
|
18
|
+
default?: () => any;
|
|
19
|
+
};
|
|
20
|
+
emit: {};
|
|
21
|
+
}>) => import("vue").VNode & {
|
|
22
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
23
|
+
};
|
|
24
|
+
declare const _default: typeof __VLS_export;
|
|
25
|
+
export default _default;
|
|
26
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
27
|
+
[K in keyof T]: T[K];
|
|
28
|
+
} : {
|
|
29
|
+
[K in keyof T as K]: T[K];
|
|
30
|
+
}) & {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createElementBlock, defineComponent, mergeProps, openBlock, renderSlot, unref, useTemplateRef, watch } from "vue";
|
|
2
|
+
import { cn } from "@raxium/themes/utils";
|
|
3
|
+
import { injectVirtualContext } from "./VirtualRoot.js";
|
|
4
|
+
const _hoisted_1 = [
|
|
5
|
+
"data-index"
|
|
6
|
+
];
|
|
7
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
8
|
+
name: "VirtualListItem",
|
|
9
|
+
__name: "VirtualListItem",
|
|
10
|
+
props: {
|
|
11
|
+
class: {
|
|
12
|
+
type: [
|
|
13
|
+
Boolean,
|
|
14
|
+
null,
|
|
15
|
+
String,
|
|
16
|
+
Object,
|
|
17
|
+
Array
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
data: {},
|
|
21
|
+
dynamic: {
|
|
22
|
+
type: Boolean
|
|
23
|
+
},
|
|
24
|
+
index: {}
|
|
25
|
+
},
|
|
26
|
+
setup (__props) {
|
|
27
|
+
const { virtualizer } = injectVirtualContext();
|
|
28
|
+
const el = useTemplateRef("el");
|
|
29
|
+
watch(el, (el)=>{
|
|
30
|
+
if (virtualizer?.value && el && __props.dynamic) virtualizer.value.measureElement(el);
|
|
31
|
+
});
|
|
32
|
+
return (_ctx, _cache)=>(openBlock(), createElementBlock("div", mergeProps(_ctx.$attrs, {
|
|
33
|
+
ref_key: "el",
|
|
34
|
+
ref: el,
|
|
35
|
+
"data-index": __props.index,
|
|
36
|
+
class: unref(cn)("rui-virtual-list-item", __props.class),
|
|
37
|
+
"data-scope": "virtual-list",
|
|
38
|
+
"data-part": "item"
|
|
39
|
+
}), [
|
|
40
|
+
renderSlot(_ctx.$slots, "default", {
|
|
41
|
+
data: __props.data,
|
|
42
|
+
index: __props.index
|
|
43
|
+
})
|
|
44
|
+
], 16, _hoisted_1));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const VirtualListItem = _sfc_main;
|
|
48
|
+
export default VirtualListItem;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
class?: HTMLAttributes["class"];
|
|
5
|
+
data?: T;
|
|
6
|
+
dynamic?: boolean;
|
|
7
|
+
index?: number;
|
|
8
|
+
}> & (typeof globalThis extends {
|
|
9
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
10
|
+
} ? P : {});
|
|
11
|
+
expose: (exposed: {}) => void;
|
|
12
|
+
attrs: any;
|
|
13
|
+
slots: {
|
|
14
|
+
default: {
|
|
15
|
+
data: T;
|
|
16
|
+
index?: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
emit: {};
|
|
20
|
+
}>) => import("vue").VNode & {
|
|
21
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
22
|
+
};
|
|
23
|
+
declare const _default: typeof __VLS_export;
|
|
24
|
+
export default _default;
|
|
25
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
26
|
+
[K in keyof T]: T[K];
|
|
27
|
+
} : {
|
|
28
|
+
[K in keyof T as K]: T[K];
|
|
29
|
+
}) & {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VirtualContext } from '.';
|
|
2
|
+
declare const injectVirtualContext: <T extends VirtualContext | null | undefined = VirtualContext>(fallback?: T | undefined) => T extends null ? VirtualContext | null : VirtualContext;
|
|
3
|
+
export { injectVirtualContext };
|
|
4
|
+
declare const _default: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createContext } from "@raxium/vue-addons-shared";
|
|
2
|
+
import { defineComponent, ref } from "vue";
|
|
3
|
+
import { LOADING_STATE } from "./index.js";
|
|
4
|
+
const [injectVirtualContext, provideVirtualContext] = createContext('VirtualContext');
|
|
5
|
+
const VirtualRoot = defineComponent({
|
|
6
|
+
setup (_, { slots }) {
|
|
7
|
+
const enableInfinite = ref(false);
|
|
8
|
+
const infiniteState = ref(LOADING_STATE.IDLE);
|
|
9
|
+
provideVirtualContext({
|
|
10
|
+
enableInfinite,
|
|
11
|
+
infiniteState
|
|
12
|
+
});
|
|
13
|
+
return ()=>slots.default?.();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
export default VirtualRoot;
|
|
17
|
+
export { injectVirtualContext };
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
@layer theme {
|
|
2
|
+
@keyframes spin {
|
|
3
|
+
from {
|
|
4
|
+
transform: rotate(0deg);
|
|
5
|
+
}
|
|
6
|
+
to {
|
|
7
|
+
transform: rotate(360deg);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@layer components {
|
|
13
|
+
.rui-virtual-list, .rui-virtual-grid {
|
|
14
|
+
width: 100%;
|
|
15
|
+
height: 100%;
|
|
16
|
+
overflow: auto;
|
|
17
|
+
overflow-anchor: none;
|
|
18
|
+
overscroll-behavior: contain;
|
|
19
|
+
|
|
20
|
+
& [data-part='scroll'] {
|
|
21
|
+
position: relative;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
.rui-virtual-infinite {
|
|
27
|
+
width: 100%;
|
|
28
|
+
height: auto;
|
|
29
|
+
&[data-size='xs'] {
|
|
30
|
+
height: .75rem;
|
|
31
|
+
}
|
|
32
|
+
&[data-size='sm'] {
|
|
33
|
+
height: .875rem;
|
|
34
|
+
}
|
|
35
|
+
&[data-size='base'] {
|
|
36
|
+
height: 1rem;
|
|
37
|
+
}
|
|
38
|
+
&[data-size='lg'] {
|
|
39
|
+
height: 1.125rem;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
& [data-part='loading'] {
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
&[data-size='xs'] {
|
|
47
|
+
padding: 0 .375rem
|
|
48
|
+
}
|
|
49
|
+
&[data-size='sm'] {
|
|
50
|
+
padding: 0 .5rem;
|
|
51
|
+
}
|
|
52
|
+
&[data-size='base'] {
|
|
53
|
+
padding: 0 .625rem;
|
|
54
|
+
}
|
|
55
|
+
&[data-size='lg'] {
|
|
56
|
+
padding: 0 .75rem;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
& [data-part='spinner'] {
|
|
61
|
+
animation: spin 1s linear infinite;
|
|
62
|
+
&[data-size='xs'] {
|
|
63
|
+
width: 1.25rem;
|
|
64
|
+
height: 1.25rem;
|
|
65
|
+
}
|
|
66
|
+
&[data-size='sm'] {
|
|
67
|
+
width: 1.5rem;
|
|
68
|
+
height: 1.5rem;
|
|
69
|
+
}
|
|
70
|
+
&[data-size='base'] {
|
|
71
|
+
width: 1.75rem;
|
|
72
|
+
height: 1.75rem;
|
|
73
|
+
}
|
|
74
|
+
&[data-size='lg'] {
|
|
75
|
+
width: 2rem;
|
|
76
|
+
height: 2rem;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
& [data-part='complete'] {
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
justify-content: center;
|
|
84
|
+
&[data-size='xs'] {
|
|
85
|
+
padding: 0 .375rem;
|
|
86
|
+
}
|
|
87
|
+
&[data-size='sm'] {
|
|
88
|
+
padding: 0 .5rem;
|
|
89
|
+
}
|
|
90
|
+
&[data-size='base'] {
|
|
91
|
+
padding: 0 .625rem;
|
|
92
|
+
}
|
|
93
|
+
&[data-size='lg'] {
|
|
94
|
+
padding: 0 .75rem;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
& [data-part='error'] {
|
|
99
|
+
display: flex;
|
|
100
|
+
flex-direction: column;
|
|
101
|
+
align-items: center;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
&[data-size='xs'] {
|
|
104
|
+
padding: 0 .375rem;
|
|
105
|
+
gap: .25rem
|
|
106
|
+
}
|
|
107
|
+
&[data-size='sm'] {
|
|
108
|
+
padding: 0 .5rem;
|
|
109
|
+
gap: .375rem
|
|
110
|
+
}
|
|
111
|
+
&[data-size='base'] {
|
|
112
|
+
padding: 0 .625rem;
|
|
113
|
+
gap: .5rem
|
|
114
|
+
}
|
|
115
|
+
&[data-size='lg'] {
|
|
116
|
+
padding: 0 .75rem;
|
|
117
|
+
gap: .625rem
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './props';
|
|
2
|
+
export { default as VirtualGrid } from './VirtualGrid.vue';
|
|
3
|
+
export { default as VirtualGridItem } from './VirtualGridItem.vue';
|
|
4
|
+
export { default as VirtualInfiniteLoading } from './VirtualInfiniteLoading.vue';
|
|
5
|
+
export { default as VirtualList } from './VirtualList.vue';
|
|
6
|
+
export { default as VirtualListItem } from './VirtualListItem.vue';
|
|
7
|
+
export { injectVirtualContext, default as VirtualRoot } from './VirtualRoot.tsx';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./props.js";
|
|
2
|
+
export { default as VirtualGrid } from "./VirtualGrid.js";
|
|
3
|
+
export { default as VirtualGridItem } from "./VirtualGridItem.js";
|
|
4
|
+
export { default as VirtualInfiniteLoading } from "./VirtualInfiniteLoading.js";
|
|
5
|
+
export { default as VirtualList } from "./VirtualList.js";
|
|
6
|
+
export { default as VirtualListItem } from "./VirtualListItem.js";
|
|
7
|
+
export { default as VirtualRoot, injectVirtualContext } from "./VirtualRoot.js";
|
package/dist/props.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Virtualizer, VirtualizerOptions } from '@tanstack/vue-virtual';
|
|
2
|
+
import type { Ref, ShallowRef } from 'vue';
|
|
3
|
+
export interface VirtualContext {
|
|
4
|
+
parentEl?: Ref<Element | null | undefined>;
|
|
5
|
+
virtualizer?: ShallowRef<Virtualizer<Element, Element>>;
|
|
6
|
+
rowVirtualizer?: ShallowRef<Virtualizer<Element, Element>>;
|
|
7
|
+
columnVirtualizer?: ShallowRef<Virtualizer<Element, Element>>;
|
|
8
|
+
enableInfinite: Ref<boolean>;
|
|
9
|
+
infiniteState: Ref<LOADING_STATE>;
|
|
10
|
+
}
|
|
11
|
+
export interface VirtualListProps<T> extends Omit<VirtualizerOptions<Element, Element>, 'enabled' | 'count' | 'getScrollElement' | 'estimateSize' | 'scrollToFn' | 'observeElementRect' | 'observeElementOffset'> {
|
|
12
|
+
dataSource: Array<T>;
|
|
13
|
+
estimateSize?: VirtualizerOptions<Element, Element>['estimateSize'];
|
|
14
|
+
scrollToFn?: VirtualizerOptions<Element, Element>['scrollToFn'];
|
|
15
|
+
observeElementRect?: VirtualizerOptions<Element, Element>['observeElementRect'];
|
|
16
|
+
observeElementOffset?: VirtualizerOptions<Element, Element>['observeElementOffset'];
|
|
17
|
+
}
|
|
18
|
+
export interface VirtualGridProps<T> {
|
|
19
|
+
dataSource: Array<T>;
|
|
20
|
+
row?: number;
|
|
21
|
+
column?: number;
|
|
22
|
+
gap?: [number, number];
|
|
23
|
+
rowVirtualizerOptions?: Omit<VirtualListProps<T>, 'dataSource'>;
|
|
24
|
+
columnVirtualizerOptions?: Omit<VirtualListProps<T>, 'dataSource'>;
|
|
25
|
+
}
|
|
26
|
+
export declare enum LOADING_STATE {
|
|
27
|
+
IDLE = "idle",
|
|
28
|
+
LOADING = "loading",
|
|
29
|
+
LOADED = "loaded",
|
|
30
|
+
COMPLETE = "complete",
|
|
31
|
+
ERROR = "error"
|
|
32
|
+
}
|
|
33
|
+
export interface LoadingStateHandler {
|
|
34
|
+
loading: () => void;
|
|
35
|
+
loaded: () => void;
|
|
36
|
+
complete: () => void;
|
|
37
|
+
error: () => void;
|
|
38
|
+
}
|
package/dist/props.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var props_LOADING_STATE = /*#__PURE__*/ function(LOADING_STATE) {
|
|
2
|
+
LOADING_STATE["IDLE"] = "idle";
|
|
3
|
+
LOADING_STATE["LOADING"] = "loading";
|
|
4
|
+
LOADING_STATE["LOADED"] = "loaded";
|
|
5
|
+
LOADING_STATE["COMPLETE"] = "complete";
|
|
6
|
+
LOADING_STATE["ERROR"] = "error";
|
|
7
|
+
return LOADING_STATE;
|
|
8
|
+
}({});
|
|
9
|
+
export { props_LOADING_STATE as LOADING_STATE };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Fragment, useSlots } from "vue";
|
|
2
|
+
import { injectVirtualContext } from "./VirtualRoot.js";
|
|
3
|
+
function useDetectSlotNode() {
|
|
4
|
+
const slots = useSlots();
|
|
5
|
+
const defaultSlotNode = slots.default()[0];
|
|
6
|
+
const virtualContext = injectVirtualContext();
|
|
7
|
+
let itemVNode = null;
|
|
8
|
+
let infiniteVNode = null;
|
|
9
|
+
if (defaultSlotNode.type === Fragment && Array.isArray(defaultSlotNode.children)) defaultSlotNode.children.forEach((child)=>{
|
|
10
|
+
if (child) {
|
|
11
|
+
const _cname = child.type.name;
|
|
12
|
+
if ('VirtualInfiniteLoading' === _cname) {
|
|
13
|
+
infiniteVNode = child;
|
|
14
|
+
virtualContext.enableInfinite.value = true;
|
|
15
|
+
} else if ('VirtualListItem' === _cname || 'VirtualGridItem' === _cname) itemVNode = child;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
else itemVNode = defaultSlotNode;
|
|
19
|
+
return {
|
|
20
|
+
itemVNode,
|
|
21
|
+
infiniteVNode
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export { useDetectSlotNode };
|