@tanstack/solid-virtual 3.0.0-beta.9 → 3.0.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/LICENSE +21 -0
- package/build/lib/index.d.ts +4 -0
- package/build/lib/index.esm.js +83 -0
- package/build/lib/index.esm.js.map +1 -0
- package/build/lib/index.js +93 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.mjs +83 -0
- package/build/lib/index.mjs.map +1 -0
- package/build/umd/index.development.js +649 -517
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +22 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +22 -11
- package/src/index.tsx +82 -52
- package/build/cjs/solid-virtual/src/index.js +0 -94
- package/build/cjs/solid-virtual/src/index.js.map +0 -1
- package/build/cjs/virtual-core/build/esm/index.js +0 -615
- package/build/cjs/virtual-core/build/esm/index.js.map +0 -1
- package/build/esm/index.js +0 -666
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -2689
- package/build/stats.json +0 -104
- package/build/types/index.d.ts +0 -4
package/src/index.tsx
CHANGED
|
@@ -8,97 +8,127 @@ import {
|
|
|
8
8
|
Virtualizer,
|
|
9
9
|
VirtualizerOptions,
|
|
10
10
|
windowScroll,
|
|
11
|
-
} from '@tanstack/virtual-core'
|
|
12
|
-
export * from '@tanstack/virtual-core'
|
|
11
|
+
} from '@tanstack/virtual-core'
|
|
12
|
+
export * from '@tanstack/virtual-core'
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
|
|
14
|
+
import {
|
|
15
|
+
createSignal,
|
|
16
|
+
onMount,
|
|
17
|
+
onCleanup,
|
|
18
|
+
createComputed,
|
|
19
|
+
mergeProps,
|
|
20
|
+
} from 'solid-js'
|
|
21
|
+
import { createStore, reconcile } from 'solid-js/store'
|
|
16
22
|
|
|
17
|
-
function createVirtualizerBase<
|
|
18
|
-
|
|
23
|
+
function createVirtualizerBase<
|
|
24
|
+
TScrollElement extends Element | Window,
|
|
25
|
+
TItemElement extends Element,
|
|
26
|
+
>(
|
|
27
|
+
options: VirtualizerOptions<TScrollElement, TItemElement>,
|
|
19
28
|
): Virtualizer<TScrollElement, TItemElement> {
|
|
20
|
-
const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> =
|
|
29
|
+
const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> =
|
|
30
|
+
mergeProps(options)
|
|
21
31
|
|
|
22
32
|
const instance = new Virtualizer<TScrollElement, TItemElement>(
|
|
23
|
-
resolvedOptions
|
|
24
|
-
)
|
|
33
|
+
resolvedOptions,
|
|
34
|
+
)
|
|
25
35
|
|
|
26
36
|
const [virtualItems, setVirtualItems] = createStore(
|
|
27
|
-
instance.getVirtualItems()
|
|
28
|
-
)
|
|
29
|
-
const [totalSize, setTotalSize] = createSignal(instance.getTotalSize())
|
|
37
|
+
instance.getVirtualItems(),
|
|
38
|
+
)
|
|
39
|
+
const [totalSize, setTotalSize] = createSignal(instance.getTotalSize())
|
|
30
40
|
|
|
31
41
|
const handler = {
|
|
32
42
|
get(
|
|
33
43
|
target: Virtualizer<TScrollElement, TItemElement>,
|
|
34
|
-
prop: keyof Virtualizer<TScrollElement, TItemElement
|
|
44
|
+
prop: keyof Virtualizer<TScrollElement, TItemElement>,
|
|
35
45
|
) {
|
|
36
46
|
switch (prop) {
|
|
37
47
|
case 'getVirtualItems':
|
|
38
|
-
return () => virtualItems
|
|
48
|
+
return () => virtualItems
|
|
39
49
|
case 'getTotalSize':
|
|
40
|
-
return () => totalSize()
|
|
50
|
+
return () => totalSize()
|
|
41
51
|
default:
|
|
42
|
-
return Reflect.get(target, prop)
|
|
52
|
+
return Reflect.get(target, prop)
|
|
43
53
|
}
|
|
44
54
|
},
|
|
45
|
-
}
|
|
55
|
+
}
|
|
46
56
|
|
|
47
|
-
const virtualizer = new Proxy(instance, handler)
|
|
48
|
-
virtualizer.setOptions(resolvedOptions)
|
|
57
|
+
const virtualizer = new Proxy(instance, handler)
|
|
58
|
+
virtualizer.setOptions(resolvedOptions)
|
|
49
59
|
|
|
50
60
|
onMount(() => {
|
|
51
|
-
const cleanup = virtualizer._didMount()
|
|
52
|
-
virtualizer._willUpdate()
|
|
53
|
-
onCleanup(cleanup)
|
|
54
|
-
})
|
|
61
|
+
const cleanup = virtualizer._didMount()
|
|
62
|
+
virtualizer._willUpdate()
|
|
63
|
+
onCleanup(cleanup)
|
|
64
|
+
})
|
|
55
65
|
|
|
56
66
|
createComputed(() => {
|
|
57
|
-
virtualizer.setOptions(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
virtualizer.setOptions(
|
|
68
|
+
mergeProps(resolvedOptions, options, {
|
|
69
|
+
onChange: (
|
|
70
|
+
instance: Virtualizer<TScrollElement, TItemElement>,
|
|
71
|
+
sync: boolean,
|
|
72
|
+
) => {
|
|
73
|
+
instance._willUpdate()
|
|
74
|
+
setVirtualItems(
|
|
75
|
+
reconcile(instance.getVirtualItems(), {
|
|
76
|
+
key: 'index',
|
|
77
|
+
}),
|
|
78
|
+
)
|
|
79
|
+
setTotalSize(instance.getTotalSize())
|
|
80
|
+
options.onChange?.(instance, sync)
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
)
|
|
68
84
|
virtualizer.measure()
|
|
69
85
|
})
|
|
70
86
|
|
|
71
|
-
return virtualizer
|
|
87
|
+
return virtualizer
|
|
72
88
|
}
|
|
73
89
|
|
|
74
|
-
export function createVirtualizer<
|
|
90
|
+
export function createVirtualizer<
|
|
91
|
+
TScrollElement extends Element,
|
|
92
|
+
TItemElement extends Element,
|
|
93
|
+
>(
|
|
75
94
|
options: PartialKeys<
|
|
76
95
|
VirtualizerOptions<TScrollElement, TItemElement>,
|
|
77
96
|
'observeElementRect' | 'observeElementOffset' | 'scrollToFn'
|
|
78
|
-
|
|
97
|
+
>,
|
|
79
98
|
): Virtualizer<TScrollElement, TItemElement> {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
return createVirtualizerBase<TScrollElement, TItemElement>(
|
|
100
|
+
mergeProps(
|
|
101
|
+
{
|
|
102
|
+
observeElementRect: observeElementRect,
|
|
103
|
+
observeElementOffset: observeElementOffset,
|
|
104
|
+
scrollToFn: elementScroll,
|
|
105
|
+
},
|
|
106
|
+
options,
|
|
107
|
+
),
|
|
108
|
+
)
|
|
86
109
|
}
|
|
87
110
|
|
|
88
|
-
export function createWindowVirtualizer<TItemElement
|
|
111
|
+
export function createWindowVirtualizer<TItemElement extends Element>(
|
|
89
112
|
options: PartialKeys<
|
|
90
113
|
VirtualizerOptions<Window, TItemElement>,
|
|
91
114
|
| 'getScrollElement'
|
|
92
115
|
| 'observeElementRect'
|
|
93
116
|
| 'observeElementOffset'
|
|
94
117
|
| 'scrollToFn'
|
|
95
|
-
|
|
118
|
+
>,
|
|
96
119
|
): Virtualizer<Window, TItemElement> {
|
|
97
|
-
return createVirtualizerBase<Window, TItemElement>(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
return createVirtualizerBase<Window, TItemElement>(
|
|
121
|
+
mergeProps(
|
|
122
|
+
{
|
|
123
|
+
getScrollElement: () =>
|
|
124
|
+
typeof document !== 'undefined' ? window : null,
|
|
125
|
+
observeElementRect: observeWindowRect,
|
|
126
|
+
observeElementOffset: observeWindowOffset,
|
|
127
|
+
scrollToFn: windowScroll,
|
|
128
|
+
initialOffset:
|
|
129
|
+
typeof document !== 'undefined' ? window.scrollY : undefined,
|
|
130
|
+
},
|
|
131
|
+
options,
|
|
132
|
+
),
|
|
133
|
+
)
|
|
104
134
|
}
|
|
@@ -1,94 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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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