@tanstack/solid-virtual 3.0.0-beta.10
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/cjs/solid-virtual/src/index.js +94 -0
- package/build/cjs/solid-virtual/src/index.js.map +1 -0
- package/build/cjs/virtual-core/build/esm/index.js +615 -0
- package/build/cjs/virtual-core/build/esm/index.js.map +1 -0
- package/build/esm/index.js +666 -0
- package/build/esm/index.js.map +1 -0
- package/build/stats-html.html +2689 -0
- package/build/umd/index.development.js +685 -0
- package/build/umd/index.development.js.map +1 -0
- package/build/umd/index.production.js +22 -0
- package/build/umd/index.production.js.map +1 -0
- package/package.json +43 -0
- package/src/index.tsx +104 -0
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
+
|
|
15
|
+
var index = require('../../virtual-core/build/esm/index.js');
|
|
16
|
+
var solidJs = require('solid-js');
|
|
17
|
+
var store = require('solid-js/store');
|
|
18
|
+
|
|
19
|
+
function createVirtualizerBase(options) {
|
|
20
|
+
const resolvedOptions = solidJs.mergeProps(options);
|
|
21
|
+
const instance = new index.Virtualizer(resolvedOptions);
|
|
22
|
+
const [virtualItems, setVirtualItems] = store.createStore(instance.getVirtualItems());
|
|
23
|
+
const [totalSize, setTotalSize] = solidJs.createSignal(instance.getTotalSize());
|
|
24
|
+
const handler = {
|
|
25
|
+
get(target, prop) {
|
|
26
|
+
switch (prop) {
|
|
27
|
+
case 'getVirtualItems':
|
|
28
|
+
return () => virtualItems;
|
|
29
|
+
|
|
30
|
+
case 'getTotalSize':
|
|
31
|
+
return () => totalSize();
|
|
32
|
+
|
|
33
|
+
default:
|
|
34
|
+
return Reflect.get(target, prop);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
};
|
|
39
|
+
const virtualizer = new Proxy(instance, handler);
|
|
40
|
+
virtualizer.setOptions(resolvedOptions);
|
|
41
|
+
solidJs.onMount(() => {
|
|
42
|
+
const cleanup = virtualizer._didMount();
|
|
43
|
+
|
|
44
|
+
virtualizer._willUpdate();
|
|
45
|
+
|
|
46
|
+
solidJs.onCleanup(cleanup);
|
|
47
|
+
});
|
|
48
|
+
solidJs.createComputed(() => {
|
|
49
|
+
virtualizer.setOptions(solidJs.mergeProps(resolvedOptions, options, {
|
|
50
|
+
onChange: instance => {
|
|
51
|
+
instance._willUpdate();
|
|
52
|
+
|
|
53
|
+
setVirtualItems(store.reconcile(instance.getVirtualItems(), {
|
|
54
|
+
key: 'index'
|
|
55
|
+
}));
|
|
56
|
+
setTotalSize(instance.getTotalSize());
|
|
57
|
+
options.onChange == null ? void 0 : options.onChange(instance);
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
virtualizer.measure();
|
|
61
|
+
});
|
|
62
|
+
return virtualizer;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function createVirtualizer(options) {
|
|
66
|
+
return createVirtualizerBase(solidJs.mergeProps({
|
|
67
|
+
observeElementRect: index.observeElementRect,
|
|
68
|
+
observeElementOffset: index.observeElementOffset,
|
|
69
|
+
scrollToFn: index.elementScroll
|
|
70
|
+
}, options));
|
|
71
|
+
}
|
|
72
|
+
function createWindowVirtualizer(options) {
|
|
73
|
+
return createVirtualizerBase(solidJs.mergeProps({
|
|
74
|
+
getScrollElement: () => typeof window !== 'undefined' ? window : null,
|
|
75
|
+
observeElementRect: index.observeWindowRect,
|
|
76
|
+
observeElementOffset: index.observeWindowOffset,
|
|
77
|
+
scrollToFn: index.windowScroll
|
|
78
|
+
}, options));
|
|
79
|
+
}
|
|
80
|
+
|
|
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
|
+
exports.createVirtualizer = createVirtualizer;
|
|
93
|
+
exports.createWindowVirtualizer = createWindowVirtualizer;
|
|
94
|
+
//# 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 { createSignal, onMount, onCleanup, createComputed, mergeProps } from 'solid-js';\nimport { createStore, reconcile } from 'solid-js/store';\n\nfunction createVirtualizerBase<TScrollElement, TItemElement = unknown>(\n options: VirtualizerOptions<TScrollElement, TItemElement>\n): Virtualizer<TScrollElement, TItemElement> {\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = 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(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 virtualizer.measure()\n })\n\n return virtualizer;\n}\n\nexport function createVirtualizer<TScrollElement, TItemElement = unknown>(\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >\n): Virtualizer<TScrollElement, TItemElement> {\n \n return createVirtualizerBase<TScrollElement, TItemElement>(mergeProps({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll\n }, options));\n}\n\nexport function createWindowVirtualizer<TItemElement = unknown>(\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>(mergeProps({\n getScrollElement: () => (typeof window !== 'undefined' ? window : null!),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n },options,\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":";;;;;;;;;;;;;;;;;;AAgBA,SAASA,qBAAT,CACEC,OADF,EAE6C;AAC3C,EAAA,MAAMC,eAAiE,GAAGC,kBAAU,CAACF,OAAD,CAApF,CAAA;AAEA,EAAA,MAAMG,QAAQ,GAAG,IAAIC,iBAAJ,CACfH,eADe,CAAjB,CAAA;EAIA,MAAM,CAACI,YAAD,EAAeC,eAAf,CAAA,GAAkCC,iBAAW,CACjDJ,QAAQ,CAACK,eAAT,EADiD,CAAnD,CAAA;EAGA,MAAM,CAACC,SAAD,EAAYC,YAAZ,CAAA,GAA4BC,oBAAY,CAACR,QAAQ,CAACS,YAAT,EAAD,CAA9C,CAAA;AAEA,EAAA,MAAMC,OAAO,GAAG;AACdC,IAAAA,GAAG,CACDC,MADC,EAEDC,IAFC,EAGD;AACA,MAAA,QAAQA,IAAR;AACE,QAAA,KAAK,iBAAL;AACE,UAAA,OAAO,MAAMX,YAAb,CAAA;;AACF,QAAA,KAAK,cAAL;UACE,OAAO,MAAMI,SAAS,EAAtB,CAAA;;AACF,QAAA;AACE,UAAA,OAAOQ,OAAO,CAACH,GAAR,CAAYC,MAAZ,EAAoBC,IAApB,CAAP,CAAA;AANJ,OAAA;AAQD,KAAA;;GAbH,CAAA;EAgBA,MAAME,WAAW,GAAG,IAAIC,KAAJ,CAAUhB,QAAV,EAAoBU,OAApB,CAApB,CAAA;EACAK,WAAW,CAACE,UAAZ,CAAuBnB,eAAvB,CAAA,CAAA;AAEAoB,EAAAA,eAAO,CAAC,MAAM;AACZ,IAAA,MAAMC,OAAO,GAAGJ,WAAW,CAACK,SAAZ,EAAhB,CAAA;;AACAL,IAAAA,WAAW,CAACM,WAAZ,EAAA,CAAA;;IACAC,iBAAS,CAACH,OAAD,CAAT,CAAA;AACD,GAJM,CAAP,CAAA;AAMAI,EAAAA,s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