@tanstack/vue-virtual 3.2.0 → 3.3.0
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/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -55,7 +55,7 @@ function useWindowVirtualizer(options) {
|
|
|
55
55
|
observeElementRect: virtualCore.observeWindowRect,
|
|
56
56
|
observeElementOffset: virtualCore.observeWindowOffset,
|
|
57
57
|
scrollToFn: virtualCore.windowScroll,
|
|
58
|
-
initialOffset: typeof document !== "undefined" ? window.scrollY :
|
|
58
|
+
initialOffset: () => typeof document !== "undefined" ? window.scrollY : 0,
|
|
59
59
|
...vue.unref(options)
|
|
60
60
|
}))
|
|
61
61
|
);
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","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'\nexport * from '@tanstack/virtual-core'\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, sync) => {\n triggerRef(state)\n options.onChange?.(instance, sync)\n },\n })\n\n virtualizer._willUpdate()\n triggerRef(state)\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 getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset
|
|
1
|
+
{"version":3,"file":"index.cjs","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'\nexport * from '@tanstack/virtual-core'\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, sync) => {\n triggerRef(state)\n options.onChange?.(instance, sync)\n },\n })\n\n virtualizer._willUpdate()\n triggerRef(state)\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 getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () =>\n typeof document !== 'undefined' ? window.scrollY : 0,\n ...unref(options),\n })),\n )\n}\n"],"names":["Virtualizer","unref","shallowRef","watch","options","triggerRef","onScopeDispose","computed","observeElementRect","observeElementOffset","elementScroll","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";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AA,MAAM,OAAO;AAAA,IAAA,EAChB;AAAA,EAAA;AAEN;;;;;;;;;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -54,7 +54,7 @@ function useWindowVirtualizer(options) {
|
|
|
54
54
|
observeElementRect: observeWindowRect,
|
|
55
55
|
observeElementOffset: observeWindowOffset,
|
|
56
56
|
scrollToFn: windowScroll,
|
|
57
|
-
initialOffset: typeof document !== "undefined" ? window.scrollY :
|
|
57
|
+
initialOffset: () => typeof document !== "undefined" ? window.scrollY : 0,
|
|
58
58
|
...unref(options)
|
|
59
59
|
}))
|
|
60
60
|
);
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +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'\nexport * from '@tanstack/virtual-core'\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, sync) => {\n triggerRef(state)\n options.onChange?.(instance, sync)\n },\n })\n\n virtualizer._willUpdate()\n triggerRef(state)\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 getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset
|
|
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'\nexport * from '@tanstack/virtual-core'\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, sync) => {\n triggerRef(state)\n options.onChange?.(instance, sync)\n },\n })\n\n virtualizer._willUpdate()\n triggerRef(state)\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 getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () =>\n typeof document !== 'undefined' ? window.scrollY : 0,\n ...unref(options),\n })),\n )\n}\n"],"names":["options"],"mappings":";;;AAwBA,SAAS,mBAIP,SACgD;AAChD,QAAM,cAAc,IAAI,YAAY,MAAM,OAAO,CAAC;AAC5C,QAAA,QAAQ,WAAW,WAAW;AAE9B,QAAA,UAAU,YAAY;AAE5B;AAAA,IACE,MAAM,MAAM,OAAO,EAAE,iBAAiB;AAAA,IACtC,CAAC,OAAO;AACN,UAAI,IAAI;AACN,oBAAY,YAAY;AAAA,MAC1B;AAAA,IACF;AAAA,IACA;AAAA,MACE,WAAW;AAAA,IACb;AAAA,EAAA;AAGF;AAAA,IACE,MAAM,MAAM,OAAO;AAAA,IACnB,CAACA,aAAY;AACX,kBAAY,WAAW;AAAA,QACrB,GAAGA;AAAAA,QACH,UAAU,CAAC,UAAU,SAAS;;AAC5B,qBAAW,KAAK;AAChBA,yBAAQ,aAARA,kCAAmB,UAAU;AAAA,QAC/B;AAAA,MAAA,CACD;AAED,kBAAY,YAAY;AACxB,iBAAW,KAAK;AAAA,IAClB;AAAA,IACA;AAAA,MACE,WAAW;AAAA,IACb;AAAA,EAAA;AAGF,iBAAe,OAAO;AAEf,SAAA;AACT;AAEO,SAAS,eAId,SAMgD;AACzC,SAAA;AAAA,IACL,SAAS,OAAO;AAAA,MACd;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,GAAG,MAAM,OAAO;AAAA,IAAA,EAChB;AAAA,EAAA;AAEN;AAEO,SAAS,qBACd,SASwC;AACjC,SAAA;AAAA,IACL,SAAS,OAAO;AAAA,MACd,kBAAkB,MAAO,OAAO,aAAa,cAAc,SAAS;AAAA,MACpE,oBAAoB;AAAA,MACpB,sBAAsB;AAAA,MACtB,YAAY;AAAA,MACZ,eAAe,MACb,OAAO,aAAa,cAAc,OAAO,UAAU;AAAA,MACrD,GAAG,MAAM,OAAO;AAAA,IAAA,EAChB;AAAA,EAAA;AAEN;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-virtual",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Headless UI for virtualizing scrollable elements in Vue",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"src"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@tanstack/virtual-core": "3.
|
|
51
|
+
"@tanstack/virtual-core": "3.3.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@vitejs/plugin-vue": "^5.0.4",
|
package/src/index.ts
CHANGED
|
@@ -107,8 +107,8 @@ export function useWindowVirtualizer<TItemElement extends Element>(
|
|
|
107
107
|
observeElementRect: observeWindowRect,
|
|
108
108
|
observeElementOffset: observeWindowOffset,
|
|
109
109
|
scrollToFn: windowScroll,
|
|
110
|
-
initialOffset:
|
|
111
|
-
typeof document !== 'undefined' ? window.scrollY :
|
|
110
|
+
initialOffset: () =>
|
|
111
|
+
typeof document !== 'undefined' ? window.scrollY : 0,
|
|
112
112
|
...unref(options),
|
|
113
113
|
})),
|
|
114
114
|
)
|