@tanstack/solid-virtual 3.0.0-beta.23 → 3.0.0-beta.26
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 +4 -0
- package/build/lib/index.esm.js +72 -0
- package/build/lib/index.esm.js.map +1 -0
- package/build/{cjs/solid-virtual/src → lib}/index.js +14 -26
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.mjs +72 -0
- package/build/lib/index.mjs.map +1 -0
- package/build/umd/index.development.js +53 -169
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +12 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +21 -10
- package/src/index.tsx +76 -51
- package/build/cjs/solid-virtual/src/index.js.map +0 -1
- package/build/cjs/virtual-core/build/esm/index.js +0 -681
- package/build/cjs/virtual-core/build/esm/index.js.map +0 -1
- package/build/esm/index.js +0 -732
- package/build/esm/index.js.map +0 -1
- package/build/stats.html +0 -2689
- package/build/stats.json +0 -104
- package/build/types/index.d.ts +0 -17
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PartialKeys, Virtualizer, VirtualizerOptions } from '@tanstack/virtual-core';
|
|
2
|
+
export * from '@tanstack/virtual-core';
|
|
3
|
+
export declare function createVirtualizer<TScrollElement extends Element, TItemElement extends Element>(options: PartialKeys<VirtualizerOptions<TScrollElement, TItemElement>, 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<TScrollElement, TItemElement>;
|
|
4
|
+
export declare function createWindowVirtualizer<TItemElement extends Element>(options: PartialKeys<VirtualizerOptions<Window, TItemElement>, 'getScrollElement' | 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'>): Virtualizer<Window, TItemElement>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* solid-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
|
+
export * from '@tanstack/virtual-core';
|
|
13
|
+
import { mergeProps, createSignal, onMount, onCleanup, createComputed } from 'solid-js';
|
|
14
|
+
import { createStore, reconcile } from 'solid-js/store';
|
|
15
|
+
|
|
16
|
+
function createVirtualizerBase(options) {
|
|
17
|
+
const resolvedOptions = mergeProps(options);
|
|
18
|
+
const instance = new Virtualizer(resolvedOptions);
|
|
19
|
+
const [virtualItems, setVirtualItems] = createStore(instance.getVirtualItems());
|
|
20
|
+
const [totalSize, setTotalSize] = createSignal(instance.getTotalSize());
|
|
21
|
+
const handler = {
|
|
22
|
+
get(target, prop) {
|
|
23
|
+
switch (prop) {
|
|
24
|
+
case 'getVirtualItems':
|
|
25
|
+
return () => virtualItems;
|
|
26
|
+
case 'getTotalSize':
|
|
27
|
+
return () => totalSize();
|
|
28
|
+
default:
|
|
29
|
+
return Reflect.get(target, prop);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const virtualizer = new Proxy(instance, handler);
|
|
34
|
+
virtualizer.setOptions(resolvedOptions);
|
|
35
|
+
onMount(() => {
|
|
36
|
+
const cleanup = virtualizer._didMount();
|
|
37
|
+
virtualizer._willUpdate();
|
|
38
|
+
onCleanup(cleanup);
|
|
39
|
+
});
|
|
40
|
+
createComputed(() => {
|
|
41
|
+
virtualizer.setOptions(mergeProps(resolvedOptions, options, {
|
|
42
|
+
onChange: instance => {
|
|
43
|
+
instance._willUpdate();
|
|
44
|
+
setVirtualItems(reconcile(instance.getVirtualItems(), {
|
|
45
|
+
key: 'index'
|
|
46
|
+
}));
|
|
47
|
+
setTotalSize(instance.getTotalSize());
|
|
48
|
+
options.onChange == null ? void 0 : options.onChange(instance);
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
virtualizer.measure();
|
|
52
|
+
});
|
|
53
|
+
return virtualizer;
|
|
54
|
+
}
|
|
55
|
+
function createVirtualizer(options) {
|
|
56
|
+
return createVirtualizerBase(mergeProps({
|
|
57
|
+
observeElementRect: observeElementRect,
|
|
58
|
+
observeElementOffset: observeElementOffset,
|
|
59
|
+
scrollToFn: elementScroll
|
|
60
|
+
}, options));
|
|
61
|
+
}
|
|
62
|
+
function createWindowVirtualizer(options) {
|
|
63
|
+
return createVirtualizerBase(mergeProps({
|
|
64
|
+
getScrollElement: () => typeof window !== 'undefined' ? window : null,
|
|
65
|
+
observeElementRect: observeWindowRect,
|
|
66
|
+
observeElementOffset: observeWindowOffset,
|
|
67
|
+
scrollToFn: windowScroll
|
|
68
|
+
}, options));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { createVirtualizer, createWindowVirtualizer };
|
|
72
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../src/index.tsx"],"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'\nexport * from '@tanstack/virtual-core'\n\nimport {\n createSignal,\n onMount,\n onCleanup,\n createComputed,\n mergeProps,\n} from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'\n\nfunction createVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n): Virtualizer<TScrollElement, TItemElement> {\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> =\n mergeProps(options)\n\n const instance = new Virtualizer<TScrollElement, TItemElement>(\n resolvedOptions,\n )\n\n const [virtualItems, setVirtualItems] = createStore(\n instance.getVirtualItems(),\n )\n const [totalSize, setTotalSize] = createSignal(instance.getTotalSize())\n\n const handler = {\n get(\n target: Virtualizer<TScrollElement, TItemElement>,\n prop: keyof Virtualizer<TScrollElement, TItemElement>,\n ) {\n switch (prop) {\n case 'getVirtualItems':\n return () => virtualItems\n case 'getTotalSize':\n return () => totalSize()\n default:\n return Reflect.get(target, prop)\n }\n },\n }\n\n const virtualizer = new Proxy(instance, handler)\n virtualizer.setOptions(resolvedOptions)\n\n onMount(() => {\n const cleanup = virtualizer._didMount()\n virtualizer._willUpdate()\n onCleanup(cleanup)\n })\n\n createComputed(() => {\n virtualizer.setOptions(\n mergeProps(resolvedOptions, options, {\n onChange: (instance: Virtualizer<TScrollElement, TItemElement>) => {\n instance._willUpdate()\n setVirtualItems(\n reconcile(instance.getVirtualItems(), {\n key: 'index',\n }),\n )\n setTotalSize(instance.getTotalSize())\n options.onChange?.(instance)\n },\n }),\n )\n virtualizer.measure()\n })\n\n return virtualizer\n}\n\nexport function createVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n): Virtualizer<TScrollElement, TItemElement> {\n return createVirtualizerBase<TScrollElement, TItemElement>(\n mergeProps(\n {\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n },\n options,\n ),\n )\n}\n\nexport function createWindowVirtualizer<TItemElement extends Element>(\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): Virtualizer<Window, TItemElement> {\n return createVirtualizerBase<Window, TItemElement>(\n mergeProps(\n {\n getScrollElement: () =>\n typeof window !== 'undefined' ? window : null!,\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n },\n options,\n ),\n )\n}\n"],"names":["createVirtualizerBase","options","resolvedOptions","mergeProps","instance","Virtualizer","virtualItems","setVirtualItems","createStore","getVirtualItems","totalSize","setTotalSize","createSignal","getTotalSize","handler","get","target","prop","Reflect","virtualizer","Proxy","setOptions","onMount","cleanup","_didMount","_willUpdate","onCleanup","createComputed","onChange","reconcile","key","measure","createVirtualizer","observeElementRect","observeElementOffset","scrollToFn","elementScroll","createWindowVirtualizer","getScrollElement","window","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;AAsBA,SAASA,qBAAqB,CAI5BC,OAAyD,EACd;AAC3C,EAAA,MAAMC,eAAiE,GACrEC,UAAU,CAACF,OAAO,CAAC,CAAA;AAErB,EAAA,MAAMG,QAAQ,GAAG,IAAIC,WAAW,CAC9BH,eAAe,CAChB,CAAA;AAED,EAAA,MAAM,CAACI,YAAY,EAAEC,eAAe,CAAC,GAAGC,WAAW,CACjDJ,QAAQ,CAACK,eAAe,EAAE,CAC3B,CAAA;AACD,EAAA,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGC,YAAY,CAACR,QAAQ,CAACS,YAAY,EAAE,CAAC,CAAA;AAEvE,EAAA,MAAMC,OAAO,GAAG;AACdC,IAAAA,GAAG,CACDC,MAAiD,EACjDC,IAAqD,EACrD;AACA,MAAA,QAAQA,IAAI;AACV,QAAA,KAAK,iBAAiB;AACpB,UAAA,OAAO,MAAMX,YAAY,CAAA;AAC3B,QAAA,KAAK,cAAc;UACjB,OAAO,MAAMI,SAAS,EAAE,CAAA;AAC1B,QAAA;AACE,UAAA,OAAOQ,OAAO,CAACH,GAAG,CAACC,MAAM,EAAEC,IAAI,CAAC,CAAA;AAAA,OAAA;AAEtC,KAAA;GACD,CAAA;EAED,MAAME,WAAW,GAAG,IAAIC,KAAK,CAAChB,QAAQ,EAAEU,OAAO,CAAC,CAAA;AAChDK,EAAAA,WAAW,CAACE,UAAU,CAACnB,eAAe,CAAC,CAAA;AAEvCoB,EAAAA,OAAO,CAAC,MAAM;AACZ,IAAA,MA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BAAiB;AACrCN,IAAAA,oBAAoB,EAAEO,mBAAmB;AACzCN,IAAAA,UAAU,EAAEO,YAAAA;GACb,EACDzC,OAAO,CACR,CACF,CAAA;AACH;;;;"}
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var virtualCore = require('@tanstack/virtual-core');
|
|
16
16
|
var solidJs = require('solid-js');
|
|
17
17
|
var store = require('solid-js/store');
|
|
18
18
|
|
|
19
19
|
function createVirtualizerBase(options) {
|
|
20
20
|
const resolvedOptions = solidJs.mergeProps(options);
|
|
21
|
-
const instance = new
|
|
21
|
+
const instance = new virtualCore.Virtualizer(resolvedOptions);
|
|
22
22
|
const [virtualItems, setVirtualItems] = store.createStore(instance.getVirtualItems());
|
|
23
23
|
const [totalSize, setTotalSize] = solidJs.createSignal(instance.getTotalSize());
|
|
24
24
|
const handler = {
|
|
@@ -26,30 +26,24 @@ function createVirtualizerBase(options) {
|
|
|
26
26
|
switch (prop) {
|
|
27
27
|
case 'getVirtualItems':
|
|
28
28
|
return () => virtualItems;
|
|
29
|
-
|
|
30
29
|
case 'getTotalSize':
|
|
31
30
|
return () => totalSize();
|
|
32
|
-
|
|
33
31
|
default:
|
|
34
32
|
return Reflect.get(target, prop);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
|
-
|
|
38
35
|
};
|
|
39
36
|
const virtualizer = new Proxy(instance, handler);
|
|
40
37
|
virtualizer.setOptions(resolvedOptions);
|
|
41
38
|
solidJs.onMount(() => {
|
|
42
39
|
const cleanup = virtualizer._didMount();
|
|
43
|
-
|
|
44
40
|
virtualizer._willUpdate();
|
|
45
|
-
|
|
46
41
|
solidJs.onCleanup(cleanup);
|
|
47
42
|
});
|
|
48
43
|
solidJs.createComputed(() => {
|
|
49
44
|
virtualizer.setOptions(solidJs.mergeProps(resolvedOptions, options, {
|
|
50
45
|
onChange: instance => {
|
|
51
46
|
instance._willUpdate();
|
|
52
|
-
|
|
53
47
|
setVirtualItems(store.reconcile(instance.getVirtualItems(), {
|
|
54
48
|
key: 'index'
|
|
55
49
|
}));
|
|
@@ -61,34 +55,28 @@ function createVirtualizerBase(options) {
|
|
|
61
55
|
});
|
|
62
56
|
return virtualizer;
|
|
63
57
|
}
|
|
64
|
-
|
|
65
58
|
function createVirtualizer(options) {
|
|
66
59
|
return createVirtualizerBase(solidJs.mergeProps({
|
|
67
|
-
observeElementRect:
|
|
68
|
-
observeElementOffset:
|
|
69
|
-
scrollToFn:
|
|
60
|
+
observeElementRect: virtualCore.observeElementRect,
|
|
61
|
+
observeElementOffset: virtualCore.observeElementOffset,
|
|
62
|
+
scrollToFn: virtualCore.elementScroll
|
|
70
63
|
}, options));
|
|
71
64
|
}
|
|
72
65
|
function createWindowVirtualizer(options) {
|
|
73
66
|
return createVirtualizerBase(solidJs.mergeProps({
|
|
74
67
|
getScrollElement: () => typeof window !== 'undefined' ? window : null,
|
|
75
|
-
observeElementRect:
|
|
76
|
-
observeElementOffset:
|
|
77
|
-
scrollToFn:
|
|
68
|
+
observeElementRect: virtualCore.observeWindowRect,
|
|
69
|
+
observeElementOffset: virtualCore.observeWindowOffset,
|
|
70
|
+
scrollToFn: virtualCore.windowScroll
|
|
78
71
|
}, options));
|
|
79
72
|
}
|
|
80
73
|
|
|
81
|
-
exports.Virtualizer = index.Virtualizer;
|
|
82
|
-
exports.defaultKeyExtractor = index.defaultKeyExtractor;
|
|
83
|
-
exports.defaultRangeExtractor = index.defaultRangeExtractor;
|
|
84
|
-
exports.elementScroll = index.elementScroll;
|
|
85
|
-
exports.measureElement = index.measureElement;
|
|
86
|
-
exports.memo = index.memo;
|
|
87
|
-
exports.observeElementOffset = index.observeElementOffset;
|
|
88
|
-
exports.observeElementRect = index.observeElementRect;
|
|
89
|
-
exports.observeWindowOffset = index.observeWindowOffset;
|
|
90
|
-
exports.observeWindowRect = index.observeWindowRect;
|
|
91
|
-
exports.windowScroll = index.windowScroll;
|
|
92
74
|
exports.createVirtualizer = createVirtualizer;
|
|
93
75
|
exports.createWindowVirtualizer = createWindowVirtualizer;
|
|
76
|
+
Object.keys(virtualCore).forEach(function (k) {
|
|
77
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () { return virtualCore[k]; }
|
|
80
|
+
});
|
|
81
|
+
});
|
|
94
82
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"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'\nexport * from '@tanstack/virtual-core'\n\nimport {\n createSignal,\n onMount,\n onCleanup,\n createComputed,\n mergeProps,\n} from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'\n\nfunction createVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n): Virtualizer<TScrollElement, TItemElement> {\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> =\n mergeProps(options)\n\n const instance = new Virtualizer<TScrollElement, TItemElement>(\n resolvedOptions,\n )\n\n const [virtualItems, setVirtualItems] = createStore(\n instance.getVirtualItems(),\n )\n const [totalSize, setTotalSize] = createSignal(instance.getTotalSize())\n\n const handler = {\n get(\n target: Virtualizer<TScrollElement, TItemElement>,\n prop: keyof Virtualizer<TScrollElement, TItemElement>,\n ) {\n switch (prop) {\n case 'getVirtualItems':\n return () => virtualItems\n case 'getTotalSize':\n return () => totalSize()\n default:\n return Reflect.get(target, prop)\n }\n },\n }\n\n const virtualizer = new Proxy(instance, handler)\n virtualizer.setOptions(resolvedOptions)\n\n onMount(() => {\n const cleanup = virtualizer._didMount()\n virtualizer._willUpdate()\n onCleanup(cleanup)\n })\n\n createComputed(() => {\n virtualizer.setOptions(\n mergeProps(resolvedOptions, options, {\n onChange: (instance: Virtualizer<TScrollElement, TItemElement>) => {\n instance._willUpdate()\n setVirtualItems(\n reconcile(instance.getVirtualItems(), {\n key: 'index',\n }),\n )\n setTotalSize(instance.getTotalSize())\n options.onChange?.(instance)\n },\n }),\n )\n virtualizer.measure()\n })\n\n return virtualizer\n}\n\nexport function createVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n): Virtualizer<TScrollElement, TItemElement> {\n return createVirtualizerBase<TScrollElement, TItemElement>(\n mergeProps(\n {\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n },\n options,\n ),\n )\n}\n\nexport function createWindowVirtualizer<TItemElement extends Element>(\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): Virtualizer<Window, TItemElement> {\n return createVirtualizerBase<Window, TItemElement>(\n mergeProps(\n {\n getScrollElement: () =>\n typeof window !== 'undefined' ? window : null!,\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n },\n options,\n ),\n )\n}\n"],"names":["createVirtualizerBase","options","resolvedOptions","mergeProps","instance","Virtualizer","virtualItems","setVirtualItems","createStore","getVirtualItems","totalSize","setTotalSize","createSignal","getTotalSize","handler","get","target","prop","Reflect","virtualizer","Proxy","setOptions","onMount","cleanup","_didMount","_willUpdate","onCleanup","createComputed","onChange","reconcile","key","measure","createVirtualizer","observeElementRect","observeElementOffset","scrollToFn","elementScroll","createWindowVirtualizer","getScrollElement","window","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,SAAS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,CAACqB,WAAW,EAAE,CAAA;AACtBlB,QAAAA,eAAe,CACbsB,eAAS,CAACzB,QAAQ,CAACK,eAAe,EAAE,EAAE;AACpCqB,UAAAA,GAAG,EAAE,OAAA;AACP,SAAC,CAAC,CACH,CAAA;AACDnB,QAAAA,YAAY,CAACP,QAAQ,CAACS,YAAY,EAAE,CAAC,CAAA;QACrCZ,OAAO,CAAC2B,QAAQ,IAAhB3B,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAC2B,QAAQ,CAAGxB,QAAQ,CAAC,CAAA;AAC9B,OAAA;AACF,KAAC,CAAC,CACH,CAAA;IACDe,WAAW,CAACY,OAAO,EAAE,CAAA;AACvB,GAAC,CAAC,CAAA;AAEF,EAAA,OAAOZ,WAAW,CAAA;AACpB,CAAA;AAEO,SAASa,iBAAiB,CAI/B/B,OAGC,EAC0C;EAC3C,OAAOD,qBAAqB,CAC1BG,kBAAU,CACR;AACE8B,IAAAA,kBAAkB,EAAEA,8BAAkB;AACtCC,IAAAA,oBAAoB,EAAEA,gCAAoB;AAC1CC,IAAAA,UAAU,EAAEC,yBAAAA;GACb,EACDnC,OAAO,CACR,CACF,CAAA;AACH,CAAA;AAEO,SAASoC,uBAAuB,CACrCpC,OAMC,EACkC;EACnC,OAAOD,qBAAqB,CAC1BG,kBAAU,CACR;IACEmC,gBAAgB,EAAE,MAChB,OAAOC,MAAM,KAAK,WAAW,GAAGA,MAAM,GAAG,IAAK;AAChDN,IAAAA,kBAAkB,EAAEO,6BAAiB;AACrCN,IAAAA,oBAAoB,EAAEO,+BAAmB;AACzCN,IAAAA,UAAU,EAAEO,wBAAAA;GACb,EACDzC,OAAO,CACR,CACF,CAAA;AACH;;;;;;;;;;;"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* solid-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
|
+
export * from '@tanstack/virtual-core';
|
|
13
|
+
import { mergeProps, createSignal, onMount, onCleanup, createComputed } from 'solid-js';
|
|
14
|
+
import { createStore, reconcile } from 'solid-js/store';
|
|
15
|
+
|
|
16
|
+
function createVirtualizerBase(options) {
|
|
17
|
+
const resolvedOptions = mergeProps(options);
|
|
18
|
+
const instance = new Virtualizer(resolvedOptions);
|
|
19
|
+
const [virtualItems, setVirtualItems] = createStore(instance.getVirtualItems());
|
|
20
|
+
const [totalSize, setTotalSize] = createSignal(instance.getTotalSize());
|
|
21
|
+
const handler = {
|
|
22
|
+
get(target, prop) {
|
|
23
|
+
switch (prop) {
|
|
24
|
+
case 'getVirtualItems':
|
|
25
|
+
return () => virtualItems;
|
|
26
|
+
case 'getTotalSize':
|
|
27
|
+
return () => totalSize();
|
|
28
|
+
default:
|
|
29
|
+
return Reflect.get(target, prop);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const virtualizer = new Proxy(instance, handler);
|
|
34
|
+
virtualizer.setOptions(resolvedOptions);
|
|
35
|
+
onMount(() => {
|
|
36
|
+
const cleanup = virtualizer._didMount();
|
|
37
|
+
virtualizer._willUpdate();
|
|
38
|
+
onCleanup(cleanup);
|
|
39
|
+
});
|
|
40
|
+
createComputed(() => {
|
|
41
|
+
virtualizer.setOptions(mergeProps(resolvedOptions, options, {
|
|
42
|
+
onChange: instance => {
|
|
43
|
+
instance._willUpdate();
|
|
44
|
+
setVirtualItems(reconcile(instance.getVirtualItems(), {
|
|
45
|
+
key: 'index'
|
|
46
|
+
}));
|
|
47
|
+
setTotalSize(instance.getTotalSize());
|
|
48
|
+
options.onChange == null ? void 0 : options.onChange(instance);
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
virtualizer.measure();
|
|
52
|
+
});
|
|
53
|
+
return virtualizer;
|
|
54
|
+
}
|
|
55
|
+
function createVirtualizer(options) {
|
|
56
|
+
return createVirtualizerBase(mergeProps({
|
|
57
|
+
observeElementRect: observeElementRect,
|
|
58
|
+
observeElementOffset: observeElementOffset,
|
|
59
|
+
scrollToFn: elementScroll
|
|
60
|
+
}, options));
|
|
61
|
+
}
|
|
62
|
+
function createWindowVirtualizer(options) {
|
|
63
|
+
return createVirtualizerBase(mergeProps({
|
|
64
|
+
getScrollElement: () => typeof window !== 'undefined' ? window : null,
|
|
65
|
+
observeElementRect: observeWindowRect,
|
|
66
|
+
observeElementOffset: observeWindowOffset,
|
|
67
|
+
scrollToFn: windowScroll
|
|
68
|
+
}, options));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { createVirtualizer, createWindowVirtualizer };
|
|
72
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/index.tsx"],"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'\nexport * from '@tanstack/virtual-core'\n\nimport {\n createSignal,\n onMount,\n onCleanup,\n createComputed,\n mergeProps,\n} from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'\n\nfunction createVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n): Virtualizer<TScrollElement, TItemElement> {\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> =\n mergeProps(options)\n\n const instance = new Virtualizer<TScrollElement, TItemElement>(\n resolvedOptions,\n )\n\n const [virtualItems, setVirtualItems] = createStore(\n instance.getVirtualItems(),\n )\n const [totalSize, setTotalSize] = createSignal(instance.getTotalSize())\n\n const handler = {\n get(\n target: Virtualizer<TScrollElement, TItemElement>,\n prop: keyof Virtualizer<TScrollElement, TItemElement>,\n ) {\n switch (prop) {\n case 'getVirtualItems':\n return () => virtualItems\n case 'getTotalSize':\n return () => totalSize()\n default:\n return Reflect.get(target, prop)\n }\n },\n }\n\n const virtualizer = new Proxy(instance, handler)\n virtualizer.setOptions(resolvedOptions)\n\n onMount(() => {\n const cleanup = virtualizer._didMount()\n virtualizer._willUpdate()\n onCleanup(cleanup)\n })\n\n createComputed(() => {\n virtualizer.setOptions(\n mergeProps(resolvedOptions, options, {\n onChange: (instance: Virtualizer<TScrollElement, TItemElement>) => {\n instance._willUpdate()\n setVirtualItems(\n reconcile(instance.getVirtualItems(), {\n key: 'index',\n }),\n )\n setTotalSize(instance.getTotalSize())\n options.onChange?.(instance)\n },\n }),\n )\n virtualizer.measure()\n })\n\n return virtualizer\n}\n\nexport function createVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n): Virtualizer<TScrollElement, TItemElement> {\n return createVirtualizerBase<TScrollElement, TItemElement>(\n mergeProps(\n {\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n },\n options,\n ),\n )\n}\n\nexport function createWindowVirtualizer<TItemElement extends Element>(\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): Virtualizer<Window, TItemElement> {\n return createVirtualizerBase<Window, TItemElement>(\n mergeProps(\n {\n getScrollElement: () =>\n typeof window !== 'undefined' ? window : null!,\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n },\n options,\n ),\n )\n}\n"],"names":["createVirtualizerBase","options","resolvedOptions","mergeProps","instance","Virtualizer","virtualItems","setVirtualItems","createStore","getVirtualItems","totalSize","setTotalSize","createSignal","getTotalSize","handler","get","target","prop","Reflect","virtualizer","Proxy","setOptions","onMount","cleanup","_didMount","_willUpdate","onCleanup","createComputed","onChange","reconcile","key","measure","createVirtualizer","observeElementRect","observeElementOffset","scrollToFn","elementScroll","createWindowVirtualizer","getScrollElement","window","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;AAsBA,SAASA,qBAAqB,CAI5BC,OAAyD,EACd;AAC3C,EAAA,MAAMC,eAAiE,GACrEC,UAAU,CAACF,OAAO,CAAC,CAAA;AAErB,EAAA,MAAMG,QAAQ,GAAG,IAAIC,WAAW,CAC9BH,eAAe,CAChB,CAAA;AAED,EAAA,MAAM,CAACI,YAAY,EAAEC,eAAe,CAAC,GAAGC,WAAW,CACjDJ,QAAQ,CAACK,eAAe,EAAE,CAC3B,CAAA;AACD,EAAA,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGC,YAAY,CAACR,QAAQ,CAACS,YAAY,EAAE,CAAC,CAAA;AAEvE,EAAA,MAAMC,OAAO,GAAG;AACdC,IAAAA,GAAG,CACDC,MAAiD,EACjDC,IAAqD,EACrD;AACA,MAAA,QAAQA,IAAI;AACV,QAAA,KAAK,iBAAiB;AACpB,UAAA,OAAO,MAAMX,YAAY,CAAA;AAC3B,QAAA,KAAK,cAAc;UACjB,OAAO,MAAMI,SAAS,EAAE,CAAA;AAC1B,QAAA;AACE,UAAA,OAAOQ,OAAO,CAACH,GAAG,CAACC,MAAM,EAAEC,IAAI,CAAC,CAAA;AAAA,OAAA;AAEtC,KAAA;GACD,CAAA;EAED,MAAME,WAAW,GAAG,IAAIC,KAAK,CAAChB,QAAQ,EAAEU,OAAO,CAAC,CAAA;AAChDK,EAAAA,WAAW,CAACE,UAAU,CAACnB,eAAe,CAAC,CAAA;AAEvCoB,EAAAA,OAAO,CAAC,MAAM;AACZ,IAAA,MAAMC,OAAO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