@floor/vlist 0.6.2 → 0.7.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/README.md +70 -75
- package/package.json +8 -29
- package/dist/adapters/index.d.ts +0 -20
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/react.d.ts +0 -119
- package/dist/adapters/react.d.ts.map +0 -1
- package/dist/adapters/svelte.d.ts +0 -198
- package/dist/adapters/svelte.d.ts.map +0 -1
- package/dist/adapters/vue.d.ts +0 -151
- package/dist/adapters/vue.d.ts.map +0 -1
- package/dist/builder/context.d.ts.map +0 -1
- package/dist/builder/core.d.ts.map +0 -1
- package/dist/builder/data.d.ts.map +0 -1
- package/dist/builder/index.d.ts.map +0 -1
- package/dist/builder/types.d.ts.map +0 -1
- package/dist/compression/index.js +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/core/core.js +0 -1
- package/dist/core/full.d.ts.map +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/lite.d.ts +0 -129
- package/dist/core/lite.d.ts.map +0 -1
- package/dist/core/minimal.d.ts +0 -104
- package/dist/core/minimal.d.ts.map +0 -1
- package/dist/core-light.d.ts +0 -104
- package/dist/core-light.d.ts.map +0 -1
- package/dist/core-light.js +0 -1
- package/dist/core.d.ts +0 -129
- package/dist/core.d.ts.map +0 -1
- package/dist/data/index.js +0 -1
- package/dist/events/emitter.d.ts.map +0 -1
- package/dist/events/index.d.ts.map +0 -1
- package/dist/features/async/index.d.ts.map +0 -1
- package/dist/features/async/manager.d.ts.map +0 -1
- package/dist/features/async/placeholder.d.ts.map +0 -1
- package/dist/features/async/plugin.d.ts.map +0 -1
- package/dist/features/async/sparse.d.ts.map +0 -1
- package/dist/features/grid/index.d.ts.map +0 -1
- package/dist/features/grid/layout.d.ts.map +0 -1
- package/dist/features/grid/plugin.d.ts.map +0 -1
- package/dist/features/grid/renderer.d.ts.map +0 -1
- package/dist/features/grid/types.d.ts.map +0 -1
- package/dist/features/page/index.d.ts.map +0 -1
- package/dist/features/page/plugin.d.ts.map +0 -1
- package/dist/features/scale/index.d.ts.map +0 -1
- package/dist/features/scale/plugin.d.ts.map +0 -1
- package/dist/features/scrollbar/controller.d.ts.map +0 -1
- package/dist/features/scrollbar/index.d.ts.map +0 -1
- package/dist/features/scrollbar/plugin.d.ts.map +0 -1
- package/dist/features/scrollbar/scrollbar.d.ts.map +0 -1
- package/dist/features/sections/index.d.ts.map +0 -1
- package/dist/features/sections/layout.d.ts.map +0 -1
- package/dist/features/sections/plugin.d.ts.map +0 -1
- package/dist/features/sections/sticky.d.ts.map +0 -1
- package/dist/features/sections/types.d.ts.map +0 -1
- package/dist/features/selection/index.d.ts.map +0 -1
- package/dist/features/selection/plugin.d.ts.map +0 -1
- package/dist/features/selection/state.d.ts.map +0 -1
- package/dist/features/snapshots/index.d.ts.map +0 -1
- package/dist/features/snapshots/plugin.d.ts.map +0 -1
- package/dist/groups/index.js +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/plugins/compression/index.d.ts +0 -10
- package/dist/plugins/compression/index.d.ts.map +0 -1
- package/dist/plugins/compression/plugin.d.ts +0 -42
- package/dist/plugins/compression/plugin.d.ts.map +0 -1
- package/dist/plugins/data/index.d.ts +0 -9
- package/dist/plugins/data/index.d.ts.map +0 -1
- package/dist/plugins/data/manager.d.ts +0 -103
- package/dist/plugins/data/manager.d.ts.map +0 -1
- package/dist/plugins/data/placeholder.d.ts +0 -62
- package/dist/plugins/data/placeholder.d.ts.map +0 -1
- package/dist/plugins/data/plugin.d.ts +0 -60
- package/dist/plugins/data/plugin.d.ts.map +0 -1
- package/dist/plugins/data/sparse.d.ts +0 -91
- package/dist/plugins/data/sparse.d.ts.map +0 -1
- package/dist/plugins/grid/index.d.ts +0 -9
- package/dist/plugins/grid/index.d.ts.map +0 -1
- package/dist/plugins/grid/layout.d.ts +0 -29
- package/dist/plugins/grid/layout.d.ts.map +0 -1
- package/dist/plugins/grid/plugin.d.ts +0 -48
- package/dist/plugins/grid/plugin.d.ts.map +0 -1
- package/dist/plugins/grid/renderer.d.ts +0 -55
- package/dist/plugins/grid/renderer.d.ts.map +0 -1
- package/dist/plugins/grid/types.d.ts +0 -71
- package/dist/plugins/grid/types.d.ts.map +0 -1
- package/dist/plugins/groups/index.d.ts +0 -10
- package/dist/plugins/groups/index.d.ts.map +0 -1
- package/dist/plugins/groups/layout.d.ts +0 -46
- package/dist/plugins/groups/layout.d.ts.map +0 -1
- package/dist/plugins/groups/plugin.d.ts +0 -64
- package/dist/plugins/groups/plugin.d.ts.map +0 -1
- package/dist/plugins/groups/sticky.d.ts +0 -33
- package/dist/plugins/groups/sticky.d.ts.map +0 -1
- package/dist/plugins/groups/types.d.ts +0 -86
- package/dist/plugins/groups/types.d.ts.map +0 -1
- package/dist/plugins/scroll/controller.d.ts +0 -121
- package/dist/plugins/scroll/controller.d.ts.map +0 -1
- package/dist/plugins/scroll/index.d.ts +0 -8
- package/dist/plugins/scroll/index.d.ts.map +0 -1
- package/dist/plugins/scroll/plugin.d.ts +0 -60
- package/dist/plugins/scroll/plugin.d.ts.map +0 -1
- package/dist/plugins/scroll/scrollbar.d.ts +0 -73
- package/dist/plugins/scroll/scrollbar.d.ts.map +0 -1
- package/dist/plugins/selection/index.d.ts +0 -7
- package/dist/plugins/selection/index.d.ts.map +0 -1
- package/dist/plugins/selection/plugin.d.ts +0 -44
- package/dist/plugins/selection/plugin.d.ts.map +0 -1
- package/dist/plugins/selection/state.d.ts +0 -102
- package/dist/plugins/selection/state.d.ts.map +0 -1
- package/dist/plugins/snapshots/index.d.ts +0 -8
- package/dist/plugins/snapshots/index.d.ts.map +0 -1
- package/dist/plugins/snapshots/plugin.d.ts +0 -44
- package/dist/plugins/snapshots/plugin.d.ts.map +0 -1
- package/dist/plugins/window/index.d.ts +0 -8
- package/dist/plugins/window/index.d.ts.map +0 -1
- package/dist/plugins/window/plugin.d.ts +0 -53
- package/dist/plugins/window/plugin.d.ts.map +0 -1
- package/dist/react/index.js +0 -1
- package/dist/react/react.js +0 -1
- package/dist/render/compression.d.ts +0 -116
- package/dist/render/compression.d.ts.map +0 -1
- package/dist/render/heights.d.ts +0 -63
- package/dist/render/heights.d.ts.map +0 -1
- package/dist/render/index.d.ts +0 -9
- package/dist/render/index.d.ts.map +0 -1
- package/dist/render/renderer.d.ts +0 -103
- package/dist/render/renderer.d.ts.map +0 -1
- package/dist/render/virtual.d.ts +0 -139
- package/dist/render/virtual.d.ts.map +0 -1
- package/dist/rendering/heights.d.ts.map +0 -1
- package/dist/rendering/index.d.ts.map +0 -1
- package/dist/rendering/renderer.d.ts.map +0 -1
- package/dist/rendering/scale.d.ts.map +0 -1
- package/dist/rendering/viewport.d.ts.map +0 -1
- package/dist/scroll/index.js +0 -1
- package/dist/svelte/index.js +0 -1
- package/dist/svelte/svelte.js +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/vlist.d.ts +0 -22
- package/dist/vlist.d.ts.map +0 -1
- package/dist/vue/index.js +0 -1
- package/dist/vue/vue.js +0 -1
- package/dist/window/index.js +0 -1
package/README.md
CHANGED
|
@@ -764,104 +764,99 @@ const list = vlist({
|
|
|
764
764
|
|
|
765
765
|
## Framework Adapters
|
|
766
766
|
|
|
767
|
+
Framework-specific adapters are available as separate packages for easier integration and smaller bundle sizes.
|
|
768
|
+
|
|
767
769
|
### React
|
|
768
770
|
|
|
769
|
-
|
|
770
|
-
import { vlist, withSelection } from 'vlist';
|
|
771
|
-
import { useEffect, useRef } from 'react';
|
|
771
|
+
**Package:** [`vlist-react`](https://github.com/floor/vlist-react) - 1.4 KB (0.6 KB gzipped)
|
|
772
772
|
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
773
|
+
```bash
|
|
774
|
+
npm install @floor/vlist vlist-react
|
|
775
|
+
```
|
|
776
776
|
|
|
777
|
-
|
|
778
|
-
|
|
777
|
+
```tsx
|
|
778
|
+
import { useVList } from 'vlist-react';
|
|
779
|
+
import '@floor/vlist/styles';
|
|
779
780
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
781
|
+
function UserList({ users }) {
|
|
782
|
+
const { containerRef, instanceRef } = useVList({
|
|
783
|
+
item: {
|
|
784
|
+
height: 48,
|
|
785
|
+
template: (user) => `<div class="user">${user.name}</div>`,
|
|
786
|
+
},
|
|
787
|
+
items: users,
|
|
788
|
+
});
|
|
787
789
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
+
return <div ref={containerRef} style={{ height: 400 }} />;
|
|
791
|
+
}
|
|
792
|
+
```
|
|
790
793
|
|
|
791
|
-
|
|
792
|
-
listRef.current?.setItems(items);
|
|
793
|
-
}, [items]);
|
|
794
|
+
**Documentation:** [github.com/floor/vlist-react](https://github.com/floor/vlist-react)
|
|
794
795
|
|
|
795
|
-
|
|
796
|
-
|
|
796
|
+
### Vue
|
|
797
|
+
|
|
798
|
+
**Package:** [`vlist-vue`](https://github.com/floor/vlist-vue) - 1.1 KB (0.6 KB gzipped)
|
|
799
|
+
|
|
800
|
+
```bash
|
|
801
|
+
npm install @floor/vlist vlist-vue
|
|
797
802
|
```
|
|
798
803
|
|
|
799
|
-
|
|
804
|
+
```vue
|
|
805
|
+
<script setup>
|
|
806
|
+
import { useVList } from 'vlist-vue';
|
|
807
|
+
import '@floor/vlist/styles';
|
|
800
808
|
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
const container = ref(null);
|
|
808
|
-
const list = ref(null);
|
|
809
|
-
|
|
810
|
-
onMounted(() => {
|
|
811
|
-
list.value = vlist({
|
|
812
|
-
container: container.value,
|
|
813
|
-
items: items.value,
|
|
814
|
-
item: { height: 48, template: renderItem },
|
|
815
|
-
})
|
|
816
|
-
.use(withSelection({ mode: 'single' }))
|
|
817
|
-
.build();
|
|
818
|
-
});
|
|
819
|
-
|
|
820
|
-
watch(items, (newItems) => {
|
|
821
|
-
list.value?.setItems(newItems);
|
|
822
|
-
});
|
|
823
|
-
|
|
824
|
-
onUnmounted(() => {
|
|
825
|
-
list.value?.destroy();
|
|
826
|
-
});
|
|
827
|
-
|
|
828
|
-
return { container };
|
|
809
|
+
const users = ref([...]);
|
|
810
|
+
|
|
811
|
+
const { containerRef, instance } = useVList({
|
|
812
|
+
item: {
|
|
813
|
+
height: 48,
|
|
814
|
+
template: (user) => `<div class="user">${user.name}</div>`,
|
|
829
815
|
},
|
|
830
|
-
|
|
816
|
+
items: users,
|
|
817
|
+
});
|
|
818
|
+
</script>
|
|
819
|
+
|
|
820
|
+
<template>
|
|
821
|
+
<div ref="containerRef" style="height: 400px" />
|
|
822
|
+
</template>
|
|
831
823
|
```
|
|
832
824
|
|
|
825
|
+
**Documentation:** [github.com/floor/vlist-vue](https://github.com/floor/vlist-vue)
|
|
826
|
+
|
|
833
827
|
### Svelte
|
|
834
828
|
|
|
835
|
-
|
|
829
|
+
**Package:** [`vlist-svelte`](https://github.com/floor/vlist-svelte) - 0.9 KB (0.5 KB gzipped)
|
|
830
|
+
|
|
831
|
+
```bash
|
|
832
|
+
npm install @floor/vlist vlist-svelte
|
|
833
|
+
```
|
|
834
|
+
|
|
835
|
+
```svelte
|
|
836
836
|
<script>
|
|
837
|
-
import { vlist
|
|
838
|
-
import
|
|
839
|
-
|
|
840
|
-
export let items = [];
|
|
841
|
-
|
|
842
|
-
let container;
|
|
843
|
-
let list;
|
|
844
|
-
|
|
845
|
-
onMount(() => {
|
|
846
|
-
list = vlist({
|
|
847
|
-
container,
|
|
848
|
-
items,
|
|
849
|
-
item: { height: 48, template: renderItem },
|
|
850
|
-
})
|
|
851
|
-
.use(withSelection({ mode: 'single' }))
|
|
852
|
-
.build();
|
|
853
|
-
});
|
|
837
|
+
import { vlist } from 'vlist-svelte';
|
|
838
|
+
import '@floor/vlist/styles';
|
|
854
839
|
|
|
855
|
-
|
|
840
|
+
let users = [...];
|
|
841
|
+
let instance;
|
|
856
842
|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
843
|
+
const config = {
|
|
844
|
+
item: {
|
|
845
|
+
height: 48,
|
|
846
|
+
template: (user) => `<div class="user">${user.name}</div>`,
|
|
847
|
+
},
|
|
848
|
+
items: users,
|
|
849
|
+
};
|
|
860
850
|
</script>
|
|
861
851
|
|
|
862
|
-
<div
|
|
852
|
+
<div
|
|
853
|
+
use:vlist={{ config, onInstance: (i) => (instance = i) }}
|
|
854
|
+
style="height: 400px"
|
|
855
|
+
/>
|
|
863
856
|
```
|
|
864
857
|
|
|
858
|
+
**Documentation:** [github.com/floor/vlist-svelte](https://github.com/floor/vlist-svelte)
|
|
859
|
+
|
|
865
860
|
## Styling
|
|
866
861
|
|
|
867
862
|
Import the base styles:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floor/vlist",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Lightweight, high-performance virtual list with zero dependencies",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Floor IO",
|
|
@@ -34,39 +34,18 @@
|
|
|
34
34
|
"import": "./dist/index.js",
|
|
35
35
|
"default": "./dist/index.js"
|
|
36
36
|
},
|
|
37
|
-
"./react": {
|
|
38
|
-
"types": "./dist/adapters/react.d.ts",
|
|
39
|
-
"import": "./dist/react/index.js",
|
|
40
|
-
"default": "./dist/react/index.js"
|
|
41
|
-
},
|
|
42
|
-
"./vue": {
|
|
43
|
-
"types": "./dist/adapters/vue.d.ts",
|
|
44
|
-
"import": "./dist/vue/index.js",
|
|
45
|
-
"default": "./dist/vue/index.js"
|
|
46
|
-
},
|
|
47
|
-
"./svelte": {
|
|
48
|
-
"types": "./dist/adapters/svelte.d.ts",
|
|
49
|
-
"import": "./dist/svelte/index.js",
|
|
50
|
-
"default": "./dist/svelte/index.js"
|
|
51
|
-
},
|
|
52
37
|
"./styles": "./dist/vlist.css",
|
|
53
38
|
"./styles/extras": "./dist/vlist-extras.css",
|
|
54
39
|
"./package.json": "./package.json"
|
|
55
40
|
},
|
|
56
|
-
"peerDependencies": {
|
|
57
|
-
"react": ">=17.0.0",
|
|
58
|
-
"vue": ">=3.0.0"
|
|
59
|
-
},
|
|
60
|
-
"peerDependenciesMeta": {
|
|
61
|
-
"react": {
|
|
62
|
-
"optional": true
|
|
63
|
-
},
|
|
64
|
-
"vue": {
|
|
65
|
-
"optional": true
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
41
|
"files": [
|
|
69
|
-
"dist"
|
|
42
|
+
"dist/**/*.js",
|
|
43
|
+
"dist/**/*.d.ts",
|
|
44
|
+
"dist/**/*.css",
|
|
45
|
+
"!dist/**/*.d.ts.map",
|
|
46
|
+
"!dist/core/lite.d.ts",
|
|
47
|
+
"!dist/core/minimal.d.ts",
|
|
48
|
+
"!dist/adapters/**"
|
|
70
49
|
],
|
|
71
50
|
"sideEffects": [
|
|
72
51
|
"*.css"
|
package/dist/adapters/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vlist adapters — Framework integration wrappers
|
|
3
|
-
*
|
|
4
|
-
* Each adapter is exported from its own subpath for tree-shaking:
|
|
5
|
-
* - `vlist/react` — React hook
|
|
6
|
-
* - `vlist/vue` — Vue 3 composable
|
|
7
|
-
* - `vlist/svelte` — Svelte action
|
|
8
|
-
*
|
|
9
|
-
* This barrel file is NOT intended for direct import.
|
|
10
|
-
* Import from the framework-specific subpath instead.
|
|
11
|
-
*
|
|
12
|
-
* @packageDocumentation
|
|
13
|
-
*/
|
|
14
|
-
export { useVList as useVListReact, useVListEvent } from "./react";
|
|
15
|
-
export type { UseVListConfig as UseVListConfigReact, UseVListReturn as UseVListReturnReact, } from "./react";
|
|
16
|
-
export { useVList as useVListVue, useVListEvent as useVListEventVue } from "./vue";
|
|
17
|
-
export type { UseVListConfig as UseVListConfigVue, UseVListConfigInput as UseVListConfigInputVue, UseVListReturn as UseVListReturnVue, } from "./vue";
|
|
18
|
-
export { vlist, onVListEvent } from "./svelte";
|
|
19
|
-
export type { VListActionConfig, VListActionOptions, VListActionReturn, OnInstanceCallback, } from "./svelte";
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnE,YAAY,EACV,cAAc,IAAI,mBAAmB,EACrC,cAAc,IAAI,mBAAmB,GACtC,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,aAAa,IAAI,gBAAgB,EAAE,MAAM,OAAO,CAAC;AACnF,YAAY,EACV,cAAc,IAAI,iBAAiB,EACnC,mBAAmB,IAAI,sBAAsB,EAC7C,cAAc,IAAI,iBAAiB,GACpC,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC/C,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,UAAU,CAAC"}
|
package/dist/adapters/react.d.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vlist/react — Thin React wrapper for vlist
|
|
3
|
-
*
|
|
4
|
-
* Provides a `useVList` hook that manages the vlist lifecycle
|
|
5
|
-
* within React's component model. The hook creates a vlist instance
|
|
6
|
-
* on mount, syncs items reactively, and destroys on unmount.
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
import type { VListConfig, VListItem, VList, VListEvents, EventHandler } from "../types";
|
|
11
|
-
/** Configuration for useVList (VListConfig without container) */
|
|
12
|
-
export type UseVListConfig<T extends VListItem = VListItem> = Omit<VListConfig<T>, "container">;
|
|
13
|
-
/** Return value from the useVList hook */
|
|
14
|
-
export interface UseVListReturn<T extends VListItem = VListItem> {
|
|
15
|
-
/**
|
|
16
|
-
* Ref to attach to your container element.
|
|
17
|
-
*
|
|
18
|
-
* ```tsx
|
|
19
|
-
* const { containerRef } = useVList(config);
|
|
20
|
-
* return <div ref={containerRef} style={{ height: 400 }} />;
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
24
|
-
/**
|
|
25
|
-
* Ref holding the underlying vlist instance.
|
|
26
|
-
* Populated after mount, `null` before.
|
|
27
|
-
*
|
|
28
|
-
* Use `.current` to access vlist methods:
|
|
29
|
-
* ```tsx
|
|
30
|
-
* const handleJump = () => instanceRef.current?.scrollToIndex(100);
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
instanceRef: React.RefObject<VList<T> | null>;
|
|
34
|
-
/**
|
|
35
|
-
* Stable helper to get the vlist instance (or null).
|
|
36
|
-
* Convenient for inline usage without `.current`:
|
|
37
|
-
* ```tsx
|
|
38
|
-
* onClick={() => getInstance()?.scrollToIndex(0)}
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
getInstance: () => VList<T> | null;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* React hook for vlist integration.
|
|
45
|
-
*
|
|
46
|
-
* Creates a virtual list instance bound to a container ref.
|
|
47
|
-
* The instance is created on mount and destroyed on unmount.
|
|
48
|
-
* When `config.items` changes (by reference), items are synced automatically.
|
|
49
|
-
*
|
|
50
|
-
* **Usage:**
|
|
51
|
-
* ```tsx
|
|
52
|
-
* import { useVList } from 'vlist/react';
|
|
53
|
-
*
|
|
54
|
-
* function UserList({ users }) {
|
|
55
|
-
* const { containerRef, instanceRef } = useVList({
|
|
56
|
-
* item: {
|
|
57
|
-
* height: 48,
|
|
58
|
-
* template: (user) => `<div class="user">${user.name}</div>`,
|
|
59
|
-
* },
|
|
60
|
-
* items: users,
|
|
61
|
-
* selection: { mode: 'single' },
|
|
62
|
-
* });
|
|
63
|
-
*
|
|
64
|
-
* return (
|
|
65
|
-
* <div
|
|
66
|
-
* ref={containerRef}
|
|
67
|
-
* style={{ height: 400 }}
|
|
68
|
-
* onClick={() => {
|
|
69
|
-
* const selected = instanceRef.current?.getSelected();
|
|
70
|
-
* console.log('Selected:', selected);
|
|
71
|
-
* }}
|
|
72
|
-
* />
|
|
73
|
-
* );
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* **With adapter (async/infinite scroll):**
|
|
78
|
-
* ```tsx
|
|
79
|
-
* const { containerRef } = useVList({
|
|
80
|
-
* item: {
|
|
81
|
-
* height: 64,
|
|
82
|
-
* template: (item) => `<div>${item.title}</div>`,
|
|
83
|
-
* },
|
|
84
|
-
* adapter: {
|
|
85
|
-
* read: async ({ offset, limit }) => {
|
|
86
|
-
* const res = await fetch(`/api/items?offset=${offset}&limit=${limit}`);
|
|
87
|
-
* const data = await res.json();
|
|
88
|
-
* return { items: data.items, total: data.total };
|
|
89
|
-
* },
|
|
90
|
-
* },
|
|
91
|
-
* });
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @param config - VList configuration (without `container`)
|
|
95
|
-
* @returns containerRef, instanceRef, and getInstance helper
|
|
96
|
-
*/
|
|
97
|
-
export declare function useVList<T extends VListItem = VListItem>(config: UseVListConfig<T>): UseVListReturn<T>;
|
|
98
|
-
/**
|
|
99
|
-
* Subscribe to a vlist event within React's lifecycle.
|
|
100
|
-
* Automatically unsubscribes on unmount or when the handler changes.
|
|
101
|
-
*
|
|
102
|
-
* ```tsx
|
|
103
|
-
* const { instanceRef } = useVList(config);
|
|
104
|
-
*
|
|
105
|
-
* useVListEvent(instanceRef, 'selection:change', ({ selected }) => {
|
|
106
|
-
* console.log('Selected items:', selected);
|
|
107
|
-
* });
|
|
108
|
-
*
|
|
109
|
-
* useVListEvent(instanceRef, 'scroll', ({ scrollTop, direction }) => {
|
|
110
|
-
* console.log(`Scrolling ${direction} at ${scrollTop}px`);
|
|
111
|
-
* });
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
* @param instanceRef - Ref to the vlist instance (from useVList)
|
|
115
|
-
* @param event - Event name
|
|
116
|
-
* @param handler - Event handler
|
|
117
|
-
*/
|
|
118
|
-
export declare function useVListEvent<T extends VListItem, K extends keyof VListEvents<T>>(instanceRef: React.RefObject<VList<T> | null>, event: K, handler: EventHandler<VListEvents<T>[K]>): void;
|
|
119
|
-
//# sourceMappingURL=react.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/adapters/react.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,KAAK,EACL,WAAW,EACX,YAAY,EAEb,MAAM,UAAU,CAAC;AAMlB,iEAAiE;AACjE,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,IAAI,CAChE,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,CACZ,CAAC;AAEF,0CAA0C;AAC1C,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC7D;;;;;;;OAOG;IACH,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAErD;;;;;;;;OAQG;IACH,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAE9C;;;;;;OAMG;IACH,WAAW,EAAE,MAAM,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CACpC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EACtD,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GACxB,cAAc,CAAC,CAAC,CAAC,CAqDnB;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,MAAM,WAAW,CAAC,CAAC,CAAC,EAE9B,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAC7C,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACvC,IAAI,CAmBN"}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vlist/svelte — Thin Svelte wrapper for vlist
|
|
3
|
-
*
|
|
4
|
-
* Provides a `vlist` action that manages the vlist lifecycle
|
|
5
|
-
* within Svelte's component model. The action creates a vlist instance
|
|
6
|
-
* when the element mounts, syncs items on update, and destroys on unmount.
|
|
7
|
-
*
|
|
8
|
-
* Works with both Svelte 4 and Svelte 5 (actions are framework-stable).
|
|
9
|
-
* No Svelte imports needed — actions are plain functions.
|
|
10
|
-
*
|
|
11
|
-
* @packageDocumentation
|
|
12
|
-
*/
|
|
13
|
-
import type { VListConfig, VListItem, VList, VListEvents, EventHandler, Unsubscribe } from "../types";
|
|
14
|
-
/** Configuration for the vlist action (VListConfig without container) */
|
|
15
|
-
export type VListActionConfig<T extends VListItem = VListItem> = Omit<VListConfig<T>, "container">;
|
|
16
|
-
/**
|
|
17
|
-
* Callback invoked once the vlist instance is ready.
|
|
18
|
-
* Use this to subscribe to events, call methods, or store a reference.
|
|
19
|
-
*/
|
|
20
|
-
export type OnInstanceCallback<T extends VListItem = VListItem> = (instance: VList<T>) => void;
|
|
21
|
-
/** Full options passed to the vlist action */
|
|
22
|
-
export interface VListActionOptions<T extends VListItem = VListItem> {
|
|
23
|
-
/** VList configuration (without container) */
|
|
24
|
-
config: VListActionConfig<T>;
|
|
25
|
-
/**
|
|
26
|
-
* Called once the instance is created (on mount).
|
|
27
|
-
* Use this to get a reference to the vlist instance for calling methods.
|
|
28
|
-
*
|
|
29
|
-
* ```svelte
|
|
30
|
-
* <script>
|
|
31
|
-
* let vlistInstance;
|
|
32
|
-
* const options = {
|
|
33
|
-
* config: { ... },
|
|
34
|
-
* onInstance: (inst) => { vlistInstance = inst; },
|
|
35
|
-
* };
|
|
36
|
-
* </script>
|
|
37
|
-
* <div use:vlist={options} />
|
|
38
|
-
* <button on:click={() => vlistInstance?.scrollToIndex(0)}>Top</button>
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
onInstance?: OnInstanceCallback<T>;
|
|
42
|
-
}
|
|
43
|
-
/** Svelte action return type */
|
|
44
|
-
export interface VListActionReturn<T extends VListItem = VListItem> {
|
|
45
|
-
/** Called by Svelte when the action parameter changes */
|
|
46
|
-
update?: (newOptions: VListActionOptions<T>) => void;
|
|
47
|
-
/** Called by Svelte when the element is removed from the DOM */
|
|
48
|
-
destroy?: () => void;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Svelte action for vlist integration.
|
|
52
|
-
*
|
|
53
|
-
* Attaches a virtual list to the target element. The list is created
|
|
54
|
-
* when the element mounts and destroyed when it unmounts. Passing
|
|
55
|
-
* new options via Svelte's reactivity triggers an update.
|
|
56
|
-
*
|
|
57
|
-
* **Basic usage:**
|
|
58
|
-
* ```svelte
|
|
59
|
-
* <script>
|
|
60
|
-
* import { vlist } from 'vlist/svelte';
|
|
61
|
-
*
|
|
62
|
-
* const users = [
|
|
63
|
-
* { id: 1, name: 'Alice' },
|
|
64
|
-
* { id: 2, name: 'Bob' },
|
|
65
|
-
* ];
|
|
66
|
-
*
|
|
67
|
-
* const options = {
|
|
68
|
-
* config: {
|
|
69
|
-
* item: {
|
|
70
|
-
* height: 48,
|
|
71
|
-
* template: (user) => `<div class="user">${user.name}</div>`,
|
|
72
|
-
* },
|
|
73
|
-
* items: users,
|
|
74
|
-
* },
|
|
75
|
-
* };
|
|
76
|
-
* </script>
|
|
77
|
-
*
|
|
78
|
-
* <div use:vlist={options} style="height: 400px" />
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* **With instance access (for methods):**
|
|
82
|
-
* ```svelte
|
|
83
|
-
* <script>
|
|
84
|
-
* import { vlist } from 'vlist/svelte';
|
|
85
|
-
*
|
|
86
|
-
* let instance;
|
|
87
|
-
*
|
|
88
|
-
* const options = {
|
|
89
|
-
* config: {
|
|
90
|
-
* item: {
|
|
91
|
-
* height: 48,
|
|
92
|
-
* template: (item) => `<div>${item.name}</div>`,
|
|
93
|
-
* },
|
|
94
|
-
* items: users,
|
|
95
|
-
* selection: { mode: 'single' },
|
|
96
|
-
* },
|
|
97
|
-
* onInstance: (inst) => { instance = inst; },
|
|
98
|
-
* };
|
|
99
|
-
*
|
|
100
|
-
* function jumpToTop() {
|
|
101
|
-
* instance?.scrollToIndex(0);
|
|
102
|
-
* }
|
|
103
|
-
* </script>
|
|
104
|
-
*
|
|
105
|
-
* <div use:vlist={options} style="height: 400px" />
|
|
106
|
-
* <button on:click={jumpToTop}>Jump to top</button>
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* **Reactive items (Svelte 4):**
|
|
110
|
-
* ```svelte
|
|
111
|
-
* <script>
|
|
112
|
-
* import { vlist } from 'vlist/svelte';
|
|
113
|
-
*
|
|
114
|
-
* let users = [...];
|
|
115
|
-
*
|
|
116
|
-
* // Svelte re-runs the action's update when this object changes
|
|
117
|
-
* $: options = {
|
|
118
|
-
* config: {
|
|
119
|
-
* item: { height: 48, template: (u) => `<div>${u.name}</div>` },
|
|
120
|
-
* items: users,
|
|
121
|
-
* },
|
|
122
|
-
* };
|
|
123
|
-
* </script>
|
|
124
|
-
*
|
|
125
|
-
* <div use:vlist={options} style="height: 400px" />
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
|
-
* **With adapter (async/infinite scroll):**
|
|
129
|
-
* ```svelte
|
|
130
|
-
* <script>
|
|
131
|
-
* import { vlist } from 'vlist/svelte';
|
|
132
|
-
*
|
|
133
|
-
* const options = {
|
|
134
|
-
* config: {
|
|
135
|
-
* item: {
|
|
136
|
-
* height: 64,
|
|
137
|
-
* template: (item) => `<div>${item.title}</div>`,
|
|
138
|
-
* },
|
|
139
|
-
* adapter: {
|
|
140
|
-
* read: async ({ offset, limit }) => {
|
|
141
|
-
* const res = await fetch(`/api/items?offset=${offset}&limit=${limit}`);
|
|
142
|
-
* const data = await res.json();
|
|
143
|
-
* return { items: data.items, total: data.total };
|
|
144
|
-
* },
|
|
145
|
-
* },
|
|
146
|
-
* },
|
|
147
|
-
* };
|
|
148
|
-
* </script>
|
|
149
|
-
*
|
|
150
|
-
* <div use:vlist={options} style="height: 400px" />
|
|
151
|
-
* ```
|
|
152
|
-
*
|
|
153
|
-
* @param node - The DOM element Svelte binds the action to
|
|
154
|
-
* @param options - Configuration and callbacks
|
|
155
|
-
* @returns Action lifecycle object (update + destroy)
|
|
156
|
-
*/
|
|
157
|
-
export declare function vlist<T extends VListItem = VListItem>(node: HTMLElement, options: VListActionOptions<T>): VListActionReturn<T>;
|
|
158
|
-
/**
|
|
159
|
-
* Helper to subscribe to vlist events with automatic cleanup.
|
|
160
|
-
* Returns an unsubscribe function.
|
|
161
|
-
*
|
|
162
|
-
* ```svelte
|
|
163
|
-
* <script>
|
|
164
|
-
* import { vlist, onVListEvent } from 'vlist/svelte';
|
|
165
|
-
* import { onDestroy } from 'svelte';
|
|
166
|
-
*
|
|
167
|
-
* let instance;
|
|
168
|
-
* let unsubs = [];
|
|
169
|
-
*
|
|
170
|
-
* function handleInstance(inst) {
|
|
171
|
-
* instance = inst;
|
|
172
|
-
*
|
|
173
|
-
* unsubs.push(
|
|
174
|
-
* onVListEvent(inst, 'selection:change', ({ selected }) => {
|
|
175
|
-
* console.log('Selected:', selected);
|
|
176
|
-
* })
|
|
177
|
-
* );
|
|
178
|
-
*
|
|
179
|
-
* unsubs.push(
|
|
180
|
-
* onVListEvent(inst, 'scroll', ({ scrollTop, direction }) => {
|
|
181
|
-
* console.log(`Scrolling ${direction} at ${scrollTop}px`);
|
|
182
|
-
* })
|
|
183
|
-
* );
|
|
184
|
-
* }
|
|
185
|
-
*
|
|
186
|
-
* onDestroy(() => unsubs.forEach(fn => fn()));
|
|
187
|
-
* </script>
|
|
188
|
-
*
|
|
189
|
-
* <div use:vlist={{ config, onInstance: handleInstance }} />
|
|
190
|
-
* ```
|
|
191
|
-
*
|
|
192
|
-
* @param instance - The vlist instance
|
|
193
|
-
* @param event - Event name
|
|
194
|
-
* @param handler - Event handler
|
|
195
|
-
* @returns Unsubscribe function
|
|
196
|
-
*/
|
|
197
|
-
export declare function onVListEvent<T extends VListItem, K extends keyof VListEvents<T>>(instance: VList<T>, event: K, handler: EventHandler<VListEvents<T>[K]>): Unsubscribe;
|
|
198
|
-
//# sourceMappingURL=svelte.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svelte.d.ts","sourceRoot":"","sources":["../../src/adapters/svelte.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,KAAK,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACZ,MAAM,UAAU,CAAC;AAMlB,yEAAyE;AACzE,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,IAAI,CACnE,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,CACZ,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,CAChE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,KACf,IAAI,CAAC;AAEV,8CAA8C;AAC9C,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IACjE,8CAA8C;IAC9C,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAE7B;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;CACpC;AAED,gCAAgC;AAChC,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAChE,yDAAyD;IACzD,MAAM,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAErD,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0GG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EACnD,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC7B,iBAAiB,CAAC,CAAC,CAAC,CA4BtB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,YAAY,CAC1B,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,MAAM,WAAW,CAAC,CAAC,CAAC,EAE9B,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,EAClB,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACvC,WAAW,CAEb"}
|