@tanstack/vue-virtual 3.0.0-beta.27
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/build/lib/index.d.ts +6 -0
- package/build/lib/index.esm.js +60 -0
- package/build/lib/index.esm.js.map +1 -0
- package/build/lib/index.js +65 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.mjs +60 -0
- package/build/lib/index.mjs.map +1 -0
- package/build/umd/index.development.js +68 -0
- package/build/umd/index.development.js.map +1 -0
- package/build/umd/index.production.js +12 -0
- package/build/umd/index.production.js.map +1 -0
- package/package.json +54 -0
- package/src/index.ts +112 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PartialKeys, Virtualizer, VirtualizerOptions } from '@tanstack/virtual-core';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
|
+
type MaybeRef<T> = T | Ref<T>;
|
|
4
|
+
export declare function useVirtualizer<TScrollElement extends Element, TItemElement extends Element>(options: MaybeRef<PartialKeys<VirtualizerOptions<TScrollElement, TItemElement>, 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>>): Ref<Virtualizer<TScrollElement, TItemElement>>;
|
|
5
|
+
export declare function useWindowVirtualizer<TItemElement extends Element>(options: MaybeRef<PartialKeys<VirtualizerOptions<Window, TItemElement>, 'observeElementRect' | 'observeElementOffset' | 'scrollToFn' | 'getScrollElement'>>): Ref<Virtualizer<Window, TItemElement>>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vue-virtual
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
import { observeElementRect, observeElementOffset, elementScroll, observeWindowRect, observeWindowOffset, windowScroll, Virtualizer } from '@tanstack/virtual-core';
|
|
12
|
+
import { computed, unref, shallowRef, watch, triggerRef, onScopeDispose } from 'vue';
|
|
13
|
+
|
|
14
|
+
function useVirtualizerBase(options) {
|
|
15
|
+
const virtualizer = new Virtualizer(unref(options));
|
|
16
|
+
const state = shallowRef(virtualizer);
|
|
17
|
+
const cleanup = virtualizer._didMount();
|
|
18
|
+
watch(() => unref(options).getScrollElement(), el => {
|
|
19
|
+
if (el) {
|
|
20
|
+
virtualizer._willUpdate();
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
immediate: true
|
|
24
|
+
});
|
|
25
|
+
watch(() => unref(options), options => {
|
|
26
|
+
virtualizer.setOptions({
|
|
27
|
+
...options,
|
|
28
|
+
onChange: instance => {
|
|
29
|
+
triggerRef(state);
|
|
30
|
+
options.onChange == null ? void 0 : options.onChange(instance);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
virtualizer._willUpdate();
|
|
34
|
+
}, {
|
|
35
|
+
immediate: true
|
|
36
|
+
});
|
|
37
|
+
onScopeDispose(cleanup);
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
function useVirtualizer(options) {
|
|
41
|
+
return useVirtualizerBase(computed(() => ({
|
|
42
|
+
observeElementRect: observeElementRect,
|
|
43
|
+
observeElementOffset: observeElementOffset,
|
|
44
|
+
scrollToFn: elementScroll,
|
|
45
|
+
...unref(options)
|
|
46
|
+
})));
|
|
47
|
+
}
|
|
48
|
+
function useWindowVirtualizer(options) {
|
|
49
|
+
return useVirtualizerBase(computed(() => ({
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
51
|
+
getScrollElement: () => typeof Window !== 'undefined' ? window : null,
|
|
52
|
+
observeElementRect: observeWindowRect,
|
|
53
|
+
observeElementOffset: observeWindowOffset,
|
|
54
|
+
scrollToFn: windowScroll,
|
|
55
|
+
...unref(options)
|
|
56
|
+
})));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { useVirtualizer, useWindowVirtualizer };
|
|
60
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../src/index.ts"],"sourcesContent":["import {\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n PartialKeys,\n Virtualizer,\n VirtualizerOptions,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport {\n computed,\n onScopeDispose,\n Ref,\n shallowRef,\n triggerRef,\n unref,\n watch,\n} from 'vue'\n\ntype MaybeRef<T> = T | Ref<T>\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: MaybeRef<VirtualizerOptions<TScrollElement, TItemElement>>,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n const virtualizer = new Virtualizer(unref(options))\n const state = shallowRef(virtualizer)\n\n const cleanup = virtualizer._didMount()\n\n watch(\n () => unref(options).getScrollElement(),\n (el) => {\n if (el) {\n virtualizer._willUpdate()\n }\n },\n {\n immediate: true,\n },\n )\n\n watch(\n () => unref(options),\n (options) => {\n virtualizer.setOptions({\n ...options,\n onChange: (instance) => {\n triggerRef(state)\n options.onChange?.(instance)\n },\n })\n\n virtualizer._willUpdate()\n },\n {\n immediate: true,\n },\n )\n\n onScopeDispose(cleanup)\n\n return state\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >\n >,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n return useVirtualizerBase<TScrollElement, TItemElement>(\n computed(() => ({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...unref(options),\n })),\n )\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n | 'getScrollElement'\n >\n >,\n): Ref<Virtualizer<Window, TItemElement>> {\n return useVirtualizerBase<Window, TItemElement>(\n computed(() => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n getScrollElement: () => (typeof Window !== 'undefined' ? window : null!),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n ...unref(options),\n })),\n )\n}\n"],"names":["useVirtualizerBase","options","virtualizer","Virtualizer","unref","state","shallowRef","cleanup","_didMount","watch","getScrollElement","el","_willUpdate","immediate","setOptions","onChange","instance","triggerRef","onScopeDispose","useVirtualizer","computed","observeElementRect","observeElementOffset","scrollToFn","elementScroll","useWindowVirtualizer","Window","window","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;AAuBA,SAASA,kBAAkB,CAIzBC,OAAmE,EACnB;EAChD,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAACC,KAAK,CAACH,OAAO,CAAC,CAAC,CAAA;AACnD,EAAA,MAAMI,KAAK,GAAGC,UAAU,CAACJ,WAAW,CAAC,CAAA;AAErC,EAAA,MAAMK,OAAO,GAAGL,WAAW,CAACM,SAAS,EAAE,CAAA;EAEvCC,KAAK,CACH,MAAML,KAAK,CAACH,OAAO,CAAC,CAACS,gBAAgB,EAAE,EACtCC,EAAE,IAAK;AACN,IAAA,IAAIA,EAAE,EAAE;MACNT,WAAW,CAACU,WAAW,EAAE,CAAA;AAC3B,KAAA;AACF,GAAC,EACD;AACEC,IAAAA,SAAS,EAAE,IAAA;AACb,GAAC,CACF,CAAA;EAEDJ,KAAK,CACH,MAAML,KAAK,CAACH,OAAO,CAAC,EACnBA,OAAO,IAAK;IACXC,WAAW,CAACY,UAAU,CAAC;AACrB,MAAA,GAAGb,OAAO;MACVc,QAAQ,EAAGC,QAAQ,IAAK;QACtBC,UAAU,CAACZ,KAAK,CAAC,CAAA;QACjBJ,OAAO,CAACc,QAAQ,IAAhBd,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAACc,QAAQ,CAAGC,QAAQ,CAAC,CAAA;AAC9B,OAAA;AACF,KAAC,CAAC,CAAA;IAEFd,WAAW,CAACU,WAAW,EAAE,CAAA;AAC3B,GAAC,EACD;AACEC,IAAAA,SAAS,EAAE,IAAA;AACb,GAAC,CACF,CAAA;EAEDK,cAAc,CAACX,OAAO,CAAC,CAAA;AAEvB,EAAA,OAAOF,KAAK,CAAA;AACd,CAAA;AAEO,SAASc,cAAc,CAI5BlB,OAKC,EAC+C;AAChD,EAAA,OAAOD,kBAAkB,CACvBoB,QAAQ,CAAC,OAAO;AACdC,IAAAA,kBAAkB,EAAEA,kBAAkB;AACtCC,IAAAA,oBAAoB,EAAEA,oBAAoB;AAC1CC,IAAAA,UAAU,EAAEC,aAAa;IACzB,GAAGpB,KAAK,CAACH,OAAO,CAAA;GACjB,CAAC,CAAC,CACJ,CAAA;AACH,CAAA;AAEO,SAASwB,oBAAoB,CAClCxB,OAQC,EACuC;AACxC,EAAA,OAAOD,kBAAkB,CACvBoB,QAAQ,CAAC,OAAO;AACd;IACAV,gBAAgB,EAAE,MAAO,OAAOgB,MAAM,KAAK,WAAW,GAAGC,MAAM,GAAG,IAAM;AACxEN,IAAAA,kBAAkB,EAAEO,iBAAiB;AACrCN,IAAAA,oBAAoB,EAAEO,mBAAmB;AACzCN,IAAAA,UAAU,EAAEO,YAAY;IACxB,GAAG1B,KAAK,CAACH,OAAO,CAAA;GACjB,CAAC,CAAC,CACJ,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vue-virtual
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
+
|
|
15
|
+
var virtualCore = require('@tanstack/virtual-core');
|
|
16
|
+
var vue = require('vue');
|
|
17
|
+
|
|
18
|
+
function useVirtualizerBase(options) {
|
|
19
|
+
const virtualizer = new virtualCore.Virtualizer(vue.unref(options));
|
|
20
|
+
const state = vue.shallowRef(virtualizer);
|
|
21
|
+
const cleanup = virtualizer._didMount();
|
|
22
|
+
vue.watch(() => vue.unref(options).getScrollElement(), el => {
|
|
23
|
+
if (el) {
|
|
24
|
+
virtualizer._willUpdate();
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
immediate: true
|
|
28
|
+
});
|
|
29
|
+
vue.watch(() => vue.unref(options), options => {
|
|
30
|
+
virtualizer.setOptions({
|
|
31
|
+
...options,
|
|
32
|
+
onChange: instance => {
|
|
33
|
+
vue.triggerRef(state);
|
|
34
|
+
options.onChange == null ? void 0 : options.onChange(instance);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
virtualizer._willUpdate();
|
|
38
|
+
}, {
|
|
39
|
+
immediate: true
|
|
40
|
+
});
|
|
41
|
+
vue.onScopeDispose(cleanup);
|
|
42
|
+
return state;
|
|
43
|
+
}
|
|
44
|
+
function useVirtualizer(options) {
|
|
45
|
+
return useVirtualizerBase(vue.computed(() => ({
|
|
46
|
+
observeElementRect: virtualCore.observeElementRect,
|
|
47
|
+
observeElementOffset: virtualCore.observeElementOffset,
|
|
48
|
+
scrollToFn: virtualCore.elementScroll,
|
|
49
|
+
...vue.unref(options)
|
|
50
|
+
})));
|
|
51
|
+
}
|
|
52
|
+
function useWindowVirtualizer(options) {
|
|
53
|
+
return useVirtualizerBase(vue.computed(() => ({
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
55
|
+
getScrollElement: () => typeof Window !== 'undefined' ? window : null,
|
|
56
|
+
observeElementRect: virtualCore.observeWindowRect,
|
|
57
|
+
observeElementOffset: virtualCore.observeWindowOffset,
|
|
58
|
+
scrollToFn: virtualCore.windowScroll,
|
|
59
|
+
...vue.unref(options)
|
|
60
|
+
})));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.useVirtualizer = useVirtualizer;
|
|
64
|
+
exports.useWindowVirtualizer = useWindowVirtualizer;
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import {\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n PartialKeys,\n Virtualizer,\n VirtualizerOptions,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport {\n computed,\n onScopeDispose,\n Ref,\n shallowRef,\n triggerRef,\n unref,\n watch,\n} from 'vue'\n\ntype MaybeRef<T> = T | Ref<T>\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: MaybeRef<VirtualizerOptions<TScrollElement, TItemElement>>,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n const virtualizer = new Virtualizer(unref(options))\n const state = shallowRef(virtualizer)\n\n const cleanup = virtualizer._didMount()\n\n watch(\n () => unref(options).getScrollElement(),\n (el) => {\n if (el) {\n virtualizer._willUpdate()\n }\n },\n {\n immediate: true,\n },\n )\n\n watch(\n () => unref(options),\n (options) => {\n virtualizer.setOptions({\n ...options,\n onChange: (instance) => {\n triggerRef(state)\n options.onChange?.(instance)\n },\n })\n\n virtualizer._willUpdate()\n },\n {\n immediate: true,\n },\n )\n\n onScopeDispose(cleanup)\n\n return state\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >\n >,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n return useVirtualizerBase<TScrollElement, TItemElement>(\n computed(() => ({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...unref(options),\n })),\n )\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n | 'getScrollElement'\n >\n >,\n): Ref<Virtualizer<Window, TItemElement>> {\n return useVirtualizerBase<Window, TItemElement>(\n computed(() => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n getScrollElement: () => (typeof Window !== 'undefined' ? window : null!),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n ...unref(options),\n })),\n )\n}\n"],"names":["useVirtualizerBase","options","virtualizer","Virtualizer","unref","state","shallowRef","cleanup","_didMount","watch","getScrollElement","el","_willUpdate","immediate","setOptions","onChange","instance","triggerRef","onScopeDispose","useVirtualizer","computed","observeElementRect","observeElementOffset","scrollToFn","elementScroll","useWindowVirtualizer","Window","window","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,SAASA,kBAAkB,CAIzBC,OAAmE,EACnB;EAChD,MAAMC,WAAW,GAAG,IAAIC,uBAAW,CAACC,SAAK,CAACH,OAAO,CAAC,CAAC,CAAA;AACnD,EAAA,MAAMI,KAAK,GAAGC,cAAU,CAACJ,WAAW,CAAC,CAAA;AAErC,EAAA,MAAMK,OAAO,GAAGL,WAAW,CAACM,SAAS,EAAE,CAAA;EAEvCC,SAAK,CACH,MAAML,SAAK,CAACH,OAAO,CAAC,CAACS,gBAAgB,EAAE,EACtCC,EAAE,IAAK;AACN,IAAA,IAAIA,EAAE,EAAE;MACNT,WAAW,CAACU,WAAW,EAAE,CAAA;AAC3B,KAAA;AACF,GAAC,EACD;AACEC,IAAAA,SAAS,EAAE,IAAA;AACb,GAAC,CACF,CAAA;EAEDJ,SAAK,CACH,MAAML,SAAK,CAACH,OAAO,CAAC,EACnBA,OAAO,IAAK;IACXC,WAAW,CAACY,UAAU,CAAC;AACrB,MAAA,GAAGb,OAAO;MACVc,QAAQ,EAAGC,QAAQ,IAAK;QACtBC,cAAU,CAACZ,KAAK,CAAC,CAAA;QACjBJ,OAAO,CAACc,QAAQ,IAAhBd,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAACc,QAAQ,CAAGC,QAAQ,CAAC,CAAA;AAC9B,OAAA;AACF,KAAC,CAAC,CAAA;IAEFd,WAAW,CAACU,WAAW,EAAE,CAAA;AAC3B,GAAC,EACD;AACEC,IAAAA,SAAS,EAAE,IAAA;AACb,GAAC,CACF,CAAA;EAEDK,kBAAc,CAACX,OAAO,CAAC,CAAA;AAEvB,EAAA,OAAOF,KAAK,CAAA;AACd,CAAA;AAEO,SAASc,cAAc,CAI5BlB,OAKC,EAC+C;AAChD,EAAA,OAAOD,kBAAkB,CACvBoB,YAAQ,CAAC,OAAO;AACdC,IAAAA,kBAAkB,EAAEA,8BAAkB;AACtCC,IAAAA,oBAAoB,EAAEA,gCAAoB;AAC1CC,IAAAA,UAAU,EAAEC,yBAAa;IACzB,GAAGpB,SAAK,CAACH,OAAO,CAAA;GACjB,CAAC,CAAC,CACJ,CAAA;AACH,CAAA;AAEO,SAASwB,oBAAoB,CAClCxB,OAQC,EACuC;AACxC,EAAA,OAAOD,kBAAkB,CACvBoB,YAAQ,CAAC,OAAO;AACd;IACAV,gBAAgB,EAAE,MAAO,OAAOgB,MAAM,KAAK,WAAW,GAAGC,MAAM,GAAG,IAAM;AACxEN,IAAAA,kBAAkB,EAAEO,6BAAiB;AACrCN,IAAAA,oBAAoB,EAAEO,+BAAmB;AACzCN,IAAAA,UAAU,EAAEO,wBAAY;IACxB,GAAG1B,SAAK,CAACH,OAAO,CAAA;GACjB,CAAC,CAAC,CACJ,CAAA;AACH;;;;;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vue-virtual
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
import { observeElementRect, observeElementOffset, elementScroll, observeWindowRect, observeWindowOffset, windowScroll, Virtualizer } from '@tanstack/virtual-core';
|
|
12
|
+
import { computed, unref, shallowRef, watch, triggerRef, onScopeDispose } from 'vue';
|
|
13
|
+
|
|
14
|
+
function useVirtualizerBase(options) {
|
|
15
|
+
const virtualizer = new Virtualizer(unref(options));
|
|
16
|
+
const state = shallowRef(virtualizer);
|
|
17
|
+
const cleanup = virtualizer._didMount();
|
|
18
|
+
watch(() => unref(options).getScrollElement(), el => {
|
|
19
|
+
if (el) {
|
|
20
|
+
virtualizer._willUpdate();
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
immediate: true
|
|
24
|
+
});
|
|
25
|
+
watch(() => unref(options), options => {
|
|
26
|
+
virtualizer.setOptions({
|
|
27
|
+
...options,
|
|
28
|
+
onChange: instance => {
|
|
29
|
+
triggerRef(state);
|
|
30
|
+
options.onChange == null ? void 0 : options.onChange(instance);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
virtualizer._willUpdate();
|
|
34
|
+
}, {
|
|
35
|
+
immediate: true
|
|
36
|
+
});
|
|
37
|
+
onScopeDispose(cleanup);
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
function useVirtualizer(options) {
|
|
41
|
+
return useVirtualizerBase(computed(() => ({
|
|
42
|
+
observeElementRect: observeElementRect,
|
|
43
|
+
observeElementOffset: observeElementOffset,
|
|
44
|
+
scrollToFn: elementScroll,
|
|
45
|
+
...unref(options)
|
|
46
|
+
})));
|
|
47
|
+
}
|
|
48
|
+
function useWindowVirtualizer(options) {
|
|
49
|
+
return useVirtualizerBase(computed(() => ({
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
51
|
+
getScrollElement: () => typeof Window !== 'undefined' ? window : null,
|
|
52
|
+
observeElementRect: observeWindowRect,
|
|
53
|
+
observeElementOffset: observeWindowOffset,
|
|
54
|
+
scrollToFn: windowScroll,
|
|
55
|
+
...unref(options)
|
|
56
|
+
})));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { useVirtualizer, useWindowVirtualizer };
|
|
60
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["import {\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n PartialKeys,\n Virtualizer,\n VirtualizerOptions,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport {\n computed,\n onScopeDispose,\n Ref,\n shallowRef,\n triggerRef,\n unref,\n watch,\n} from 'vue'\n\ntype MaybeRef<T> = T | Ref<T>\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: MaybeRef<VirtualizerOptions<TScrollElement, TItemElement>>,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n const virtualizer = new Virtualizer(unref(options))\n const state = shallowRef(virtualizer)\n\n const cleanup = virtualizer._didMount()\n\n watch(\n () => unref(options).getScrollElement(),\n (el) => {\n if (el) {\n virtualizer._willUpdate()\n }\n },\n {\n immediate: true,\n },\n )\n\n watch(\n () => unref(options),\n (options) => {\n virtualizer.setOptions({\n ...options,\n onChange: (instance) => {\n triggerRef(state)\n options.onChange?.(instance)\n },\n })\n\n virtualizer._willUpdate()\n },\n {\n immediate: true,\n },\n )\n\n onScopeDispose(cleanup)\n\n return state\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >\n >,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n return useVirtualizerBase<TScrollElement, TItemElement>(\n computed(() => ({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...unref(options),\n })),\n )\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n | 'getScrollElement'\n >\n >,\n): Ref<Virtualizer<Window, TItemElement>> {\n return useVirtualizerBase<Window, TItemElement>(\n computed(() => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n getScrollElement: () => (typeof Window !== 'undefined' ? window : null!),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n ...unref(options),\n })),\n )\n}\n"],"names":["useVirtualizerBase","options","virtualizer","Virtualizer","unref","state","shallowRef","cleanup","_didMount","watch","getScrollElement","el","_willUpdate","immediate","setOptions","onChange","instance","triggerRef","onScopeDispose","useVirtualizer","computed","observeElementRect","observeElementOffset","scrollToFn","elementScroll","useWindowVirtualizer","Window","window","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;AAuBA,SAASA,kBAAkB,CAIzBC,OAAmE,EACnB;EAChD,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAACC,KAAK,CAACH,OAAO,CAAC,CAAC,CAAA;AACnD,EAAA,MAAMI,KAAK,GAAGC,UAAU,CAACJ,WAAW,CAAC,CAAA;AAErC,EAAA,MAAMK,OAAO,GAAGL,WAAW,CAACM,SAAS,EAAE,CAAA;EAEvCC,KAAK,CACH,MAAML,KAAK,CAACH,OAAO,CAAC,CAACS,gBAAgB,EAAE,EACtCC,EAAE,IAAK;AACN,IAAA,IAAIA,EAAE,EAAE;MACNT,WAAW,CAACU,WAAW,EAAE,CAAA;AAC3B,KAAA;AACF,GAAC,EACD;AACEC,IAAAA,SAAS,EAAE,IAAA;AACb,GAAC,CACF,CAAA;EAEDJ,KAAK,CACH,MAAML,KAAK,CAACH,OAAO,CAAC,EACnBA,OAAO,IAAK;IACXC,WAAW,CAACY,UAAU,CAAC;AACrB,MAAA,GAAGb,OAAO;MACVc,QAAQ,EAAGC,QAAQ,IAAK;QACtBC,UAAU,CAACZ,KAAK,CAAC,CAAA;QACjBJ,OAAO,CAACc,QAAQ,IAAhBd,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAACc,QAAQ,CAAGC,QAAQ,CAAC,CAAA;AAC9B,OAAA;AACF,KAAC,CAAC,CAAA;IAEFd,WAAW,CAACU,WAAW,EAAE,CAAA;AAC3B,GAAC,EACD;AACEC,IAAAA,SAAS,EAAE,IAAA;AACb,GAAC,CACF,CAAA;EAEDK,cAAc,CAACX,OAAO,CAAC,CAAA;AAEvB,EAAA,OAAOF,KAAK,CAAA;AACd,CAAA;AAEO,SAASc,cAAc,CAI5BlB,OAKC,EAC+C;AAChD,EAAA,OAAOD,kBAAkB,CACvBoB,QAAQ,CAAC,OAAO;AACdC,IAAAA,kBAAkB,EAAEA,kBAAkB;AACtCC,IAAAA,oBAAoB,EAAEA,oBAAoB;AAC1CC,IAAAA,UAAU,EAAEC,aAAa;IACzB,GAAGpB,KAAK,CAACH,OAAO,CAAA;GACjB,CAAC,CAAC,CACJ,CAAA;AACH,CAAA;AAEO,SAASwB,oBAAoB,CAClCxB,OAQC,EACuC;AACxC,EAAA,OAAOD,kBAAkB,CACvBoB,QAAQ,CAAC,OAAO;AACd;IACAV,gBAAgB,EAAE,MAAO,OAAOgB,MAAM,KAAK,WAAW,GAAGC,MAAM,GAAG,IAAM;AACxEN,IAAAA,kBAAkB,EAAEO,iBAAiB;AACrCN,IAAAA,oBAAoB,EAAEO,mBAAmB;AACzCN,IAAAA,UAAU,EAAEO,YAAY;IACxB,GAAG1B,KAAK,CAACH,OAAO,CAAA;GACjB,CAAC,CAAC,CACJ,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vue-virtual
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
(function (global, factory) {
|
|
12
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tanstack/virtual-core'), require('vue')) :
|
|
13
|
+
typeof define === 'function' && define.amd ? define(['exports', '@tanstack/virtual-core', 'vue'], factory) :
|
|
14
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VueVirtual = {}, global.VirtualCore, global.Vue));
|
|
15
|
+
})(this, (function (exports, virtualCore, vue) { 'use strict';
|
|
16
|
+
|
|
17
|
+
function useVirtualizerBase(options) {
|
|
18
|
+
const virtualizer = new virtualCore.Virtualizer(vue.unref(options));
|
|
19
|
+
const state = vue.shallowRef(virtualizer);
|
|
20
|
+
const cleanup = virtualizer._didMount();
|
|
21
|
+
vue.watch(() => vue.unref(options).getScrollElement(), el => {
|
|
22
|
+
if (el) {
|
|
23
|
+
virtualizer._willUpdate();
|
|
24
|
+
}
|
|
25
|
+
}, {
|
|
26
|
+
immediate: true
|
|
27
|
+
});
|
|
28
|
+
vue.watch(() => vue.unref(options), options => {
|
|
29
|
+
virtualizer.setOptions({
|
|
30
|
+
...options,
|
|
31
|
+
onChange: instance => {
|
|
32
|
+
vue.triggerRef(state);
|
|
33
|
+
options.onChange == null ? void 0 : options.onChange(instance);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
virtualizer._willUpdate();
|
|
37
|
+
}, {
|
|
38
|
+
immediate: true
|
|
39
|
+
});
|
|
40
|
+
vue.onScopeDispose(cleanup);
|
|
41
|
+
return state;
|
|
42
|
+
}
|
|
43
|
+
function useVirtualizer(options) {
|
|
44
|
+
return useVirtualizerBase(vue.computed(() => ({
|
|
45
|
+
observeElementRect: virtualCore.observeElementRect,
|
|
46
|
+
observeElementOffset: virtualCore.observeElementOffset,
|
|
47
|
+
scrollToFn: virtualCore.elementScroll,
|
|
48
|
+
...vue.unref(options)
|
|
49
|
+
})));
|
|
50
|
+
}
|
|
51
|
+
function useWindowVirtualizer(options) {
|
|
52
|
+
return useVirtualizerBase(vue.computed(() => ({
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
54
|
+
getScrollElement: () => typeof Window !== 'undefined' ? window : null,
|
|
55
|
+
observeElementRect: virtualCore.observeWindowRect,
|
|
56
|
+
observeElementOffset: virtualCore.observeWindowOffset,
|
|
57
|
+
scrollToFn: virtualCore.windowScroll,
|
|
58
|
+
...vue.unref(options)
|
|
59
|
+
})));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.useVirtualizer = useVirtualizer;
|
|
63
|
+
exports.useWindowVirtualizer = useWindowVirtualizer;
|
|
64
|
+
|
|
65
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
66
|
+
|
|
67
|
+
}));
|
|
68
|
+
//# sourceMappingURL=index.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.development.js","sources":["../../src/index.ts"],"sourcesContent":["import {\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n PartialKeys,\n Virtualizer,\n VirtualizerOptions,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport {\n computed,\n onScopeDispose,\n Ref,\n shallowRef,\n triggerRef,\n unref,\n watch,\n} from 'vue'\n\ntype MaybeRef<T> = T | Ref<T>\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: MaybeRef<VirtualizerOptions<TScrollElement, TItemElement>>,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n const virtualizer = new Virtualizer(unref(options))\n const state = shallowRef(virtualizer)\n\n const cleanup = virtualizer._didMount()\n\n watch(\n () => unref(options).getScrollElement(),\n (el) => {\n if (el) {\n virtualizer._willUpdate()\n }\n },\n {\n immediate: true,\n },\n )\n\n watch(\n () => unref(options),\n (options) => {\n virtualizer.setOptions({\n ...options,\n onChange: (instance) => {\n triggerRef(state)\n options.onChange?.(instance)\n },\n })\n\n virtualizer._willUpdate()\n },\n {\n immediate: true,\n },\n )\n\n onScopeDispose(cleanup)\n\n return state\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >\n >,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n return useVirtualizerBase<TScrollElement, TItemElement>(\n computed(() => ({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...unref(options),\n })),\n )\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n | 'getScrollElement'\n >\n >,\n): Ref<Virtualizer<Window, TItemElement>> {\n return useVirtualizerBase<Window, TItemElement>(\n computed(() => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n getScrollElement: () => (typeof Window !== 'undefined' ? window : null!),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n ...unref(options),\n })),\n )\n}\n"],"names":["useVirtualizerBase","options","virtualizer","Virtualizer","unref","state","shallowRef","cleanup","_didMount","watch","getScrollElement","el","_willUpdate","immediate","setOptions","onChange","instance","triggerRef","onScopeDispose","useVirtualizer","computed","observeElementRect","observeElementOffset","scrollToFn","elementScroll","useWindowVirtualizer","Window","window","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;;EAuBA,SAASA,kBAAkB,CAIzBC,OAAmE,EACnB;IAChD,MAAMC,WAAW,GAAG,IAAIC,uBAAW,CAACC,SAAK,CAACH,OAAO,CAAC,CAAC,CAAA;EACnD,EAAA,MAAMI,KAAK,GAAGC,cAAU,CAACJ,WAAW,CAAC,CAAA;EAErC,EAAA,MAAMK,OAAO,GAAGL,WAAW,CAACM,SAAS,EAAE,CAAA;IAEvCC,SAAK,CACH,MAAML,SAAK,CAACH,OAAO,CAAC,CAACS,gBAAgB,EAAE,EACtCC,EAAE,IAAK;EACN,IAAA,IAAIA,EAAE,EAAE;QACNT,WAAW,CAACU,WAAW,EAAE,CAAA;EAC3B,KAAA;EACF,GAAC,EACD;EACEC,IAAAA,SAAS,EAAE,IAAA;EACb,GAAC,CACF,CAAA;IAEDJ,SAAK,CACH,MAAML,SAAK,CAACH,OAAO,CAAC,EACnBA,OAAO,IAAK;MACXC,WAAW,CAACY,UAAU,CAAC;EACrB,MAAA,GAAGb,OAAO;QACVc,QAAQ,EAAGC,QAAQ,IAAK;UACtBC,cAAU,CAACZ,KAAK,CAAC,CAAA;UACjBJ,OAAO,CAACc,QAAQ,IAAhBd,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAACc,QAAQ,CAAGC,QAAQ,CAAC,CAAA;EAC9B,OAAA;EACF,KAAC,CAAC,CAAA;MAEFd,WAAW,CAACU,WAAW,EAAE,CAAA;EAC3B,GAAC,EACD;EACEC,IAAAA,SAAS,EAAE,IAAA;EACb,GAAC,CACF,CAAA;IAEDK,kBAAc,CAACX,OAAO,CAAC,CAAA;EAEvB,EAAA,OAAOF,KAAK,CAAA;EACd,CAAA;EAEO,SAASc,cAAc,CAI5BlB,OAKC,EAC+C;EAChD,EAAA,OAAOD,kBAAkB,CACvBoB,YAAQ,CAAC,OAAO;EACdC,IAAAA,kBAAkB,EAAEA,8BAAkB;EACtCC,IAAAA,oBAAoB,EAAEA,gCAAoB;EAC1CC,IAAAA,UAAU,EAAEC,yBAAa;MACzB,GAAGpB,SAAK,CAACH,OAAO,CAAA;KACjB,CAAC,CAAC,CACJ,CAAA;EACH,CAAA;EAEO,SAASwB,oBAAoB,CAClCxB,OAQC,EACuC;EACxC,EAAA,OAAOD,kBAAkB,CACvBoB,YAAQ,CAAC,OAAO;EACd;MACAV,gBAAgB,EAAE,MAAO,OAAOgB,MAAM,KAAK,WAAW,GAAGC,MAAM,GAAG,IAAM;EACxEN,IAAAA,kBAAkB,EAAEO,6BAAiB;EACrCN,IAAAA,oBAAoB,EAAEO,+BAAmB;EACzCN,IAAAA,UAAU,EAAEO,wBAAY;MACxB,GAAG1B,SAAK,CAACH,OAAO,CAAA;KACjB,CAAC,CAAC,CACJ,CAAA;EACH;;;;;;;;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vue-virtual
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@tanstack/virtual-core"),require("vue")):"function"==typeof define&&define.amd?define(["exports","@tanstack/virtual-core","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VueVirtual={},e.VirtualCore,e.Vue)}(this,(function(e,t,n){"use strict";function o(e){const o=new t.Virtualizer(n.unref(e)),r=n.shallowRef(o),l=o._didMount();return n.watch((()=>n.unref(e).getScrollElement()),(e=>{e&&o._willUpdate()}),{immediate:!0}),n.watch((()=>n.unref(e)),(e=>{o.setOptions({...e,onChange:t=>{n.triggerRef(r),null==e.onChange||e.onChange(t)}}),o._willUpdate()}),{immediate:!0}),n.onScopeDispose(l),r}e.useVirtualizer=function(e){return o(n.computed((()=>({observeElementRect:t.observeElementRect,observeElementOffset:t.observeElementOffset,scrollToFn:t.elementScroll,...n.unref(e)}))))},e.useWindowVirtualizer=function(e){return o(n.computed((()=>({getScrollElement:()=>"undefined"!=typeof Window?window:null,observeElementRect:t.observeWindowRect,observeElementOffset:t.observeWindowOffset,scrollToFn:t.windowScroll,...n.unref(e)}))))},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
12
|
+
//# sourceMappingURL=index.production.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.production.js","sources":["../../src/index.ts"],"sourcesContent":["import {\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n PartialKeys,\n Virtualizer,\n VirtualizerOptions,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport {\n computed,\n onScopeDispose,\n Ref,\n shallowRef,\n triggerRef,\n unref,\n watch,\n} from 'vue'\n\ntype MaybeRef<T> = T | Ref<T>\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: MaybeRef<VirtualizerOptions<TScrollElement, TItemElement>>,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n const virtualizer = new Virtualizer(unref(options))\n const state = shallowRef(virtualizer)\n\n const cleanup = virtualizer._didMount()\n\n watch(\n () => unref(options).getScrollElement(),\n (el) => {\n if (el) {\n virtualizer._willUpdate()\n }\n },\n {\n immediate: true,\n },\n )\n\n watch(\n () => unref(options),\n (options) => {\n virtualizer.setOptions({\n ...options,\n onChange: (instance) => {\n triggerRef(state)\n options.onChange?.(instance)\n },\n })\n\n virtualizer._willUpdate()\n },\n {\n immediate: true,\n },\n )\n\n onScopeDispose(cleanup)\n\n return state\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >\n >,\n): Ref<Virtualizer<TScrollElement, TItemElement>> {\n return useVirtualizerBase<TScrollElement, TItemElement>(\n computed(() => ({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...unref(options),\n })),\n )\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: MaybeRef<\n PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n | 'getScrollElement'\n >\n >,\n): Ref<Virtualizer<Window, TItemElement>> {\n return useVirtualizerBase<Window, TItemElement>(\n computed(() => ({\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n getScrollElement: () => (typeof Window !== 'undefined' ? window : null!),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n ...unref(options),\n })),\n )\n}\n"],"names":["useVirtualizerBase","options","virtualizer","Virtualizer","unref","state","shallowRef","cleanup","_didMount","watch","getScrollElement","el","_willUpdate","immediate","setOptions","onChange","instance","triggerRef","onScopeDispose","computed","observeElementRect","observeElementOffset","scrollToFn","elementScroll","Window","window","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;0VAuBA,SAASA,EAIPC,GAEA,MAAMC,EAAc,IAAIC,EAAAA,YAAYC,EAAAA,MAAMH,IACpCI,EAAQC,aAAWJ,GAEnBK,EAAUL,EAAYM,YAkC5B,OAhCAC,EAAKA,OACH,IAAML,EAAAA,MAAMH,GAASS,qBACpBC,IACKA,GACFT,EAAYU,aACd,GAEF,CACEC,WAAW,IAIfJ,EAAAA,OACE,IAAML,EAAAA,MAAMH,KACXA,IACCC,EAAYY,WAAW,IAClBb,EACHc,SAAWC,IACTC,EAAUA,WAACZ,GACXJ,MAAAA,EAAQc,UAARd,EAAQc,SAAWC,EAAS,IAIhCd,EAAYU,aAAa,GAE3B,CACEC,WAAW,IAIfK,EAAcA,eAACX,GAERF,CACT,kBAEO,SAILJ,GAOA,OAAOD,EACLmB,EAAAA,UAAS,KAAO,CACdC,mBAAoBA,EAAkBA,mBACtCC,qBAAsBA,EAAoBA,qBAC1CC,WAAYC,EAAaA,iBACtBnB,EAAAA,MAAMH,OAGf,yBAEO,SACLA,GAUA,OAAOD,EACLmB,EAAAA,UAAS,KAAO,CAEdT,iBAAkB,IAAyB,oBAAXc,OAAyBC,OAAS,KAClEL,mBAAoBM,EAAiBA,kBACrCL,qBAAsBM,EAAmBA,oBACzCL,WAAYM,EAAYA,gBACrBxB,EAAAA,MAAMH,OAGf"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/vue-virtual",
|
|
3
|
+
"author": "Tanner Linsley",
|
|
4
|
+
"version": "3.0.0-beta.27",
|
|
5
|
+
"description": "Headless UI for virtualizing scrollable elements in Solid",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/tanstack/virtual#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/tanstack/virtual.git"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"react",
|
|
17
|
+
"vue",
|
|
18
|
+
"solid",
|
|
19
|
+
"svelte",
|
|
20
|
+
"virtual",
|
|
21
|
+
"virtual-core",
|
|
22
|
+
"datagrid"
|
|
23
|
+
],
|
|
24
|
+
"funding": {
|
|
25
|
+
"type": "github",
|
|
26
|
+
"url": "https://github.com/sponsors/tannerlinsley"
|
|
27
|
+
},
|
|
28
|
+
"types": "build/lib/index.d.ts",
|
|
29
|
+
"main": "build/lib/index.js",
|
|
30
|
+
"module": "build/lib/index.esm.js",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./build/lib/index.d.ts",
|
|
34
|
+
"import": "./build/lib/index.mjs",
|
|
35
|
+
"default": "./build/lib/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"sideEffects": false,
|
|
40
|
+
"files": [
|
|
41
|
+
"build/lib/*",
|
|
42
|
+
"build/umd/*",
|
|
43
|
+
"src"
|
|
44
|
+
],
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"vue": "^3.2.45"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@tanstack/virtual-core": "3.0.0-beta.26"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"vue": "^3.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {
|
|
2
|
+
elementScroll,
|
|
3
|
+
observeElementOffset,
|
|
4
|
+
observeElementRect,
|
|
5
|
+
observeWindowOffset,
|
|
6
|
+
observeWindowRect,
|
|
7
|
+
PartialKeys,
|
|
8
|
+
Virtualizer,
|
|
9
|
+
VirtualizerOptions,
|
|
10
|
+
windowScroll,
|
|
11
|
+
} from '@tanstack/virtual-core'
|
|
12
|
+
import {
|
|
13
|
+
computed,
|
|
14
|
+
onScopeDispose,
|
|
15
|
+
Ref,
|
|
16
|
+
shallowRef,
|
|
17
|
+
triggerRef,
|
|
18
|
+
unref,
|
|
19
|
+
watch,
|
|
20
|
+
} from 'vue'
|
|
21
|
+
|
|
22
|
+
type MaybeRef<T> = T | Ref<T>
|
|
23
|
+
|
|
24
|
+
function useVirtualizerBase<
|
|
25
|
+
TScrollElement extends Element | Window,
|
|
26
|
+
TItemElement extends Element,
|
|
27
|
+
>(
|
|
28
|
+
options: MaybeRef<VirtualizerOptions<TScrollElement, TItemElement>>,
|
|
29
|
+
): Ref<Virtualizer<TScrollElement, TItemElement>> {
|
|
30
|
+
const virtualizer = new Virtualizer(unref(options))
|
|
31
|
+
const state = shallowRef(virtualizer)
|
|
32
|
+
|
|
33
|
+
const cleanup = virtualizer._didMount()
|
|
34
|
+
|
|
35
|
+
watch(
|
|
36
|
+
() => unref(options).getScrollElement(),
|
|
37
|
+
(el) => {
|
|
38
|
+
if (el) {
|
|
39
|
+
virtualizer._willUpdate()
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
immediate: true,
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
watch(
|
|
48
|
+
() => unref(options),
|
|
49
|
+
(options) => {
|
|
50
|
+
virtualizer.setOptions({
|
|
51
|
+
...options,
|
|
52
|
+
onChange: (instance) => {
|
|
53
|
+
triggerRef(state)
|
|
54
|
+
options.onChange?.(instance)
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
virtualizer._willUpdate()
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
immediate: true,
|
|
62
|
+
},
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
onScopeDispose(cleanup)
|
|
66
|
+
|
|
67
|
+
return state
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function useVirtualizer<
|
|
71
|
+
TScrollElement extends Element,
|
|
72
|
+
TItemElement extends Element,
|
|
73
|
+
>(
|
|
74
|
+
options: MaybeRef<
|
|
75
|
+
PartialKeys<
|
|
76
|
+
VirtualizerOptions<TScrollElement, TItemElement>,
|
|
77
|
+
'observeElementRect' | 'observeElementOffset' | 'scrollToFn'
|
|
78
|
+
>
|
|
79
|
+
>,
|
|
80
|
+
): Ref<Virtualizer<TScrollElement, TItemElement>> {
|
|
81
|
+
return useVirtualizerBase<TScrollElement, TItemElement>(
|
|
82
|
+
computed(() => ({
|
|
83
|
+
observeElementRect: observeElementRect,
|
|
84
|
+
observeElementOffset: observeElementOffset,
|
|
85
|
+
scrollToFn: elementScroll,
|
|
86
|
+
...unref(options),
|
|
87
|
+
})),
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function useWindowVirtualizer<TItemElement extends Element>(
|
|
92
|
+
options: MaybeRef<
|
|
93
|
+
PartialKeys<
|
|
94
|
+
VirtualizerOptions<Window, TItemElement>,
|
|
95
|
+
| 'observeElementRect'
|
|
96
|
+
| 'observeElementOffset'
|
|
97
|
+
| 'scrollToFn'
|
|
98
|
+
| 'getScrollElement'
|
|
99
|
+
>
|
|
100
|
+
>,
|
|
101
|
+
): Ref<Virtualizer<Window, TItemElement>> {
|
|
102
|
+
return useVirtualizerBase<Window, TItemElement>(
|
|
103
|
+
computed(() => ({
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
105
|
+
getScrollElement: () => (typeof Window !== 'undefined' ? window : null!),
|
|
106
|
+
observeElementRect: observeWindowRect,
|
|
107
|
+
observeElementOffset: observeWindowOffset,
|
|
108
|
+
scrollToFn: windowScroll,
|
|
109
|
+
...unref(options),
|
|
110
|
+
})),
|
|
111
|
+
)
|
|
112
|
+
}
|