@floor/vlist 0.5.1
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/README.md +839 -0
- package/dist/adapters/index.d.ts +20 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/react.d.ts +119 -0
- package/dist/adapters/react.d.ts.map +1 -0
- package/dist/adapters/svelte.d.ts +198 -0
- package/dist/adapters/svelte.d.ts.map +1 -0
- package/dist/adapters/vue.d.ts +151 -0
- package/dist/adapters/vue.d.ts.map +1 -0
- package/dist/builder/context.d.ts +36 -0
- package/dist/builder/context.d.ts.map +1 -0
- package/dist/builder/core.d.ts +16 -0
- package/dist/builder/core.d.ts.map +1 -0
- package/dist/builder/data.d.ts +71 -0
- package/dist/builder/data.d.ts.map +1 -0
- package/dist/builder/index.d.ts +25 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +1 -0
- package/dist/builder/types.d.ts +269 -0
- package/dist/builder/types.d.ts.map +1 -0
- package/dist/compression/index.js +1 -0
- package/dist/constants.d.ts +65 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core-light.d.ts +104 -0
- package/dist/core-light.d.ts.map +1 -0
- package/dist/core-light.js +1 -0
- package/dist/core.d.ts +129 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/data/index.js +1 -0
- package/dist/events/emitter.d.ts +20 -0
- package/dist/events/emitter.d.ts.map +1 -0
- package/dist/events/index.d.ts +6 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/grid/index.js +1 -0
- package/dist/groups/index.js +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/plugins/compression/index.d.ts +10 -0
- package/dist/plugins/compression/index.d.ts.map +1 -0
- package/dist/plugins/compression/plugin.d.ts +42 -0
- package/dist/plugins/compression/plugin.d.ts.map +1 -0
- package/dist/plugins/data/index.d.ts +9 -0
- package/dist/plugins/data/index.d.ts.map +1 -0
- package/dist/plugins/data/manager.d.ts +103 -0
- package/dist/plugins/data/manager.d.ts.map +1 -0
- package/dist/plugins/data/placeholder.d.ts +62 -0
- package/dist/plugins/data/placeholder.d.ts.map +1 -0
- package/dist/plugins/data/plugin.d.ts +60 -0
- package/dist/plugins/data/plugin.d.ts.map +1 -0
- package/dist/plugins/data/sparse.d.ts +91 -0
- package/dist/plugins/data/sparse.d.ts.map +1 -0
- package/dist/plugins/grid/index.d.ts +9 -0
- package/dist/plugins/grid/index.d.ts.map +1 -0
- package/dist/plugins/grid/layout.d.ts +29 -0
- package/dist/plugins/grid/layout.d.ts.map +1 -0
- package/dist/plugins/grid/plugin.d.ts +48 -0
- package/dist/plugins/grid/plugin.d.ts.map +1 -0
- package/dist/plugins/grid/renderer.d.ts +55 -0
- package/dist/plugins/grid/renderer.d.ts.map +1 -0
- package/dist/plugins/grid/types.d.ts +71 -0
- package/dist/plugins/grid/types.d.ts.map +1 -0
- package/dist/plugins/groups/index.d.ts +10 -0
- package/dist/plugins/groups/index.d.ts.map +1 -0
- package/dist/plugins/groups/layout.d.ts +46 -0
- package/dist/plugins/groups/layout.d.ts.map +1 -0
- package/dist/plugins/groups/plugin.d.ts +63 -0
- package/dist/plugins/groups/plugin.d.ts.map +1 -0
- package/dist/plugins/groups/sticky.d.ts +33 -0
- package/dist/plugins/groups/sticky.d.ts.map +1 -0
- package/dist/plugins/groups/types.d.ts +86 -0
- package/dist/plugins/groups/types.d.ts.map +1 -0
- package/dist/plugins/scroll/controller.d.ts +121 -0
- package/dist/plugins/scroll/controller.d.ts.map +1 -0
- package/dist/plugins/scroll/index.d.ts +8 -0
- package/dist/plugins/scroll/index.d.ts.map +1 -0
- package/dist/plugins/scroll/plugin.d.ts +60 -0
- package/dist/plugins/scroll/plugin.d.ts.map +1 -0
- package/dist/plugins/scroll/scrollbar.d.ts +73 -0
- package/dist/plugins/scroll/scrollbar.d.ts.map +1 -0
- package/dist/plugins/selection/index.d.ts +7 -0
- package/dist/plugins/selection/index.d.ts.map +1 -0
- package/dist/plugins/selection/plugin.d.ts +44 -0
- package/dist/plugins/selection/plugin.d.ts.map +1 -0
- package/dist/plugins/selection/state.d.ts +102 -0
- package/dist/plugins/selection/state.d.ts.map +1 -0
- package/dist/plugins/snapshots/index.d.ts +8 -0
- package/dist/plugins/snapshots/index.d.ts.map +1 -0
- package/dist/plugins/snapshots/plugin.d.ts +44 -0
- package/dist/plugins/snapshots/plugin.d.ts.map +1 -0
- package/dist/plugins/window/index.d.ts +8 -0
- package/dist/plugins/window/index.d.ts.map +1 -0
- package/dist/plugins/window/plugin.d.ts +53 -0
- package/dist/plugins/window/plugin.d.ts.map +1 -0
- package/dist/react/index.js +1 -0
- package/dist/render/compression.d.ts +116 -0
- package/dist/render/compression.d.ts.map +1 -0
- package/dist/render/heights.d.ts +63 -0
- package/dist/render/heights.d.ts.map +1 -0
- package/dist/render/index.d.ts +9 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/renderer.d.ts +103 -0
- package/dist/render/renderer.d.ts.map +1 -0
- package/dist/render/virtual.d.ts +139 -0
- package/dist/render/virtual.d.ts.map +1 -0
- package/dist/scroll/index.js +1 -0
- package/dist/selection/index.js +1 -0
- package/dist/snapshots/index.js +1 -0
- package/dist/svelte/index.js +1 -0
- package/dist/types.d.ts +559 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/vlist-extras.css +1 -0
- package/dist/vlist.css +1 -0
- package/dist/vlist.d.ts +22 -0
- package/dist/vlist.d.ts.map +1 -0
- package/dist/vue/index.js +1 -0
- package/dist/window/index.js +1 -0
- package/package.json +137 -0
|
@@ -0,0 +1,20 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,119 @@
|
|
|
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 "vlist";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,OAAO,CAAC;AAMf,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"}
|
|
@@ -0,0 +1,198 @@
|
|
|
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 "vlist";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,OAAO,CAAC;AAMf,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"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist/vue — Thin Vue 3 wrapper for vlist
|
|
3
|
+
*
|
|
4
|
+
* Provides a `useVList` composable that manages the vlist lifecycle
|
|
5
|
+
* within Vue's composition API. The composable creates a vlist instance
|
|
6
|
+
* on mount, syncs items reactively, and destroys on unmount.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import { type Ref, type ShallowRef } from "vue";
|
|
11
|
+
import type { VListConfig, VListItem, VList, VListEvents, EventHandler } from "vlist";
|
|
12
|
+
/** Configuration for useVList (VListConfig without container) */
|
|
13
|
+
export type UseVListConfig<T extends VListItem = VListItem> = Omit<VListConfig<T>, "container">;
|
|
14
|
+
/** Accepted config input — plain object or reactive ref */
|
|
15
|
+
export type UseVListConfigInput<T extends VListItem = VListItem> = UseVListConfig<T> | Ref<UseVListConfig<T>>;
|
|
16
|
+
/** Return value from the useVList composable */
|
|
17
|
+
export interface UseVListReturn<T extends VListItem = VListItem> {
|
|
18
|
+
/**
|
|
19
|
+
* Template ref to bind to your container element.
|
|
20
|
+
*
|
|
21
|
+
* ```vue
|
|
22
|
+
* <template>
|
|
23
|
+
* <div ref="containerRef" style="height: 400px" />
|
|
24
|
+
* </template>
|
|
25
|
+
*
|
|
26
|
+
* <script setup>
|
|
27
|
+
* const { containerRef } = useVList(config);
|
|
28
|
+
* </script>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
containerRef: Ref<HTMLElement | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Shallow ref holding the underlying vlist instance.
|
|
34
|
+
* Populated after mount, `null` before.
|
|
35
|
+
*
|
|
36
|
+
* ```vue
|
|
37
|
+
* <script setup>
|
|
38
|
+
* const { instance } = useVList(config);
|
|
39
|
+
*
|
|
40
|
+
* function jumpToTop() {
|
|
41
|
+
* instance.value?.scrollToIndex(0);
|
|
42
|
+
* }
|
|
43
|
+
* </script>
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
instance: ShallowRef<VList<T> | null>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Vue 3 composable for vlist integration.
|
|
50
|
+
*
|
|
51
|
+
* Creates a virtual list instance bound to a template ref.
|
|
52
|
+
* The instance is created on mount and destroyed on unmount.
|
|
53
|
+
* When items change (detected via `watch`), they are synced automatically.
|
|
54
|
+
*
|
|
55
|
+
* **Basic usage:**
|
|
56
|
+
* ```vue
|
|
57
|
+
* <template>
|
|
58
|
+
* <div ref="containerRef" style="height: 400px" />
|
|
59
|
+
* </template>
|
|
60
|
+
*
|
|
61
|
+
* <script setup lang="ts">
|
|
62
|
+
* import { useVList } from 'vlist/vue';
|
|
63
|
+
* import { ref } from 'vue';
|
|
64
|
+
*
|
|
65
|
+
* const users = ref([
|
|
66
|
+
* { id: 1, name: 'Alice' },
|
|
67
|
+
* { id: 2, name: 'Bob' },
|
|
68
|
+
* ]);
|
|
69
|
+
*
|
|
70
|
+
* const { containerRef, instance } = useVList({
|
|
71
|
+
* item: {
|
|
72
|
+
* height: 48,
|
|
73
|
+
* template: (user) => `<div class="user">${user.name}</div>`,
|
|
74
|
+
* },
|
|
75
|
+
* items: users.value,
|
|
76
|
+
* });
|
|
77
|
+
* </script>
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* **With reactive config (auto-syncs items):**
|
|
81
|
+
* ```vue
|
|
82
|
+
* <script setup lang="ts">
|
|
83
|
+
* import { useVList } from 'vlist/vue';
|
|
84
|
+
* import { computed, ref } from 'vue';
|
|
85
|
+
*
|
|
86
|
+
* const filter = ref('');
|
|
87
|
+
* const allUsers = ref([...]);
|
|
88
|
+
*
|
|
89
|
+
* const config = computed(() => ({
|
|
90
|
+
* item: {
|
|
91
|
+
* height: 48,
|
|
92
|
+
* template: (user) => `<div>${user.name}</div>`,
|
|
93
|
+
* },
|
|
94
|
+
* items: allUsers.value.filter(u =>
|
|
95
|
+
* u.name.includes(filter.value)
|
|
96
|
+
* ),
|
|
97
|
+
* }));
|
|
98
|
+
*
|
|
99
|
+
* const { containerRef, instance } = useVList(config);
|
|
100
|
+
* </script>
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* **With adapter (async/infinite scroll):**
|
|
104
|
+
* ```vue
|
|
105
|
+
* <script setup lang="ts">
|
|
106
|
+
* const { containerRef } = useVList({
|
|
107
|
+
* item: {
|
|
108
|
+
* height: 64,
|
|
109
|
+
* template: (item) => `<div>${item.title}</div>`,
|
|
110
|
+
* },
|
|
111
|
+
* adapter: {
|
|
112
|
+
* read: async ({ offset, limit }) => {
|
|
113
|
+
* const res = await fetch(`/api/items?offset=${offset}&limit=${limit}`);
|
|
114
|
+
* const data = await res.json();
|
|
115
|
+
* return { items: data.items, total: data.total };
|
|
116
|
+
* },
|
|
117
|
+
* },
|
|
118
|
+
* });
|
|
119
|
+
* </script>
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @param configInput - VList configuration (without `container`), plain or reactive
|
|
123
|
+
* @returns containerRef and reactive instance ref
|
|
124
|
+
*/
|
|
125
|
+
export declare function useVList<T extends VListItem = VListItem>(configInput: UseVListConfigInput<T>): UseVListReturn<T>;
|
|
126
|
+
/**
|
|
127
|
+
* Subscribe to a vlist event within Vue's lifecycle.
|
|
128
|
+
* Automatically unsubscribes on unmount.
|
|
129
|
+
*
|
|
130
|
+
* ```vue
|
|
131
|
+
* <script setup lang="ts">
|
|
132
|
+
* import { useVList, useVListEvent } from 'vlist/vue';
|
|
133
|
+
*
|
|
134
|
+
* const { containerRef, instance } = useVList(config);
|
|
135
|
+
*
|
|
136
|
+
* useVListEvent(instance, 'selection:change', ({ selected }) => {
|
|
137
|
+
* console.log('Selected items:', selected);
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* useVListEvent(instance, 'scroll', ({ scrollTop, direction }) => {
|
|
141
|
+
* console.log(`Scrolling ${direction} at ${scrollTop}px`);
|
|
142
|
+
* });
|
|
143
|
+
* </script>
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @param instance - Shallow ref to the vlist instance (from useVList)
|
|
147
|
+
* @param event - Event name
|
|
148
|
+
* @param handler - Event handler
|
|
149
|
+
*/
|
|
150
|
+
export declare function useVListEvent<T extends VListItem, K extends keyof VListEvents<T>>(instance: ShallowRef<VList<T> | null>, event: K, handler: EventHandler<VListEvents<T>[K]>): void;
|
|
151
|
+
//# sourceMappingURL=vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../src/adapters/vue.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AAEH,OAAO,EAQL,KAAK,GAAG,EACR,KAAK,UAAU,EAChB,MAAM,KAAK,CAAC;AAEb,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,KAAK,EACL,WAAW,EACX,YAAY,EAEb,MAAM,OAAO,CAAC;AAMf,iEAAiE;AACjE,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,IAAI,CAChE,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,CACZ,CAAC;AAEF,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAC3D,cAAc,CAAC,CAAC,CAAC,GACjB,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3B,gDAAgD;AAChD,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC7D;;;;;;;;;;;;OAYG;IACH,YAAY,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAEtC;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;CACvC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EACtD,WAAW,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAClC,cAAc,CAAC,CAAC,CAAC,CAwCnB;AAMD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,MAAM,WAAW,CAAC,CAAC,CAAC,EAE9B,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EACrC,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACvC,IAAI,CA4BN"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist/builder - BuilderContext Factory
|
|
3
|
+
* Central state container that plugins receive during setup.
|
|
4
|
+
*
|
|
5
|
+
* The BuilderContext provides access to all core components plus
|
|
6
|
+
* registration points for handlers, methods, and cleanup callbacks.
|
|
7
|
+
*/
|
|
8
|
+
import type { VListItem, VListEvents } from "../types";
|
|
9
|
+
import type { HeightCache } from "../render/heights";
|
|
10
|
+
import type { Renderer, DOMStructure } from "../render/renderer";
|
|
11
|
+
import type { SimpleDataManager } from "./data";
|
|
12
|
+
import type { ScrollController } from "../scroll/controller";
|
|
13
|
+
import type { Emitter } from "../events/emitter";
|
|
14
|
+
import type { BuilderConfig, BuilderContext, BuilderState, ResolvedBuilderConfig } from "./types";
|
|
15
|
+
/** Options for creating a BuilderContext */
|
|
16
|
+
export interface CreateBuilderContextOptions<T extends VListItem = VListItem> {
|
|
17
|
+
rawConfig: BuilderConfig<T>;
|
|
18
|
+
resolvedConfig: ResolvedBuilderConfig;
|
|
19
|
+
dom: DOMStructure;
|
|
20
|
+
heightCache: HeightCache;
|
|
21
|
+
dataManager: SimpleDataManager<T>;
|
|
22
|
+
scrollController: ScrollController;
|
|
23
|
+
renderer: Renderer<T>;
|
|
24
|
+
emitter: Emitter<VListEvents<T>>;
|
|
25
|
+
initialState: BuilderState;
|
|
26
|
+
initialHeightConfig: number | ((index: number) => number);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a BuilderContext from individual components.
|
|
30
|
+
*
|
|
31
|
+
* The context acts as the central hub that plugins wire into.
|
|
32
|
+
* Unlike VListContext (used by the monolithic factory), BuilderContext
|
|
33
|
+
* exposes registration arrays and replacement methods for plugins.
|
|
34
|
+
*/
|
|
35
|
+
export declare const createBuilderContext: <T extends VListItem = VListItem>(options: CreateBuilderContextOptions<T>) => BuilderContext<T>;
|
|
36
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/builder/context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAuB,MAAM,UAAU,CAAC;AAG5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EAEb,MAAM,oBAAoB,CAAC;AAU5B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACZ,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAMjB,4CAA4C;AAC5C,MAAM,WAAW,2BAA2B,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC1E,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC5B,cAAc,EAAE,qBAAqB,CAAC;IACtC,GAAG,EAAE,YAAY,CAAC;IAClB,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,YAAY,EAAE,YAAY,CAAC;IAC3B,mBAAmB,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;CAC3D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,SAAS,GAAG,SAAS,EAClE,SAAS,2BAA2B,CAAC,CAAC,CAAC,KACtC,cAAc,CAAC,CAAC,CA+SlB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist/builder — Self-contained composable virtual list builder
|
|
3
|
+
*
|
|
4
|
+
* Everything inlined — height cache, emitter, DOM, element pool, renderer,
|
|
5
|
+
* range calculations, scroll handling. Zero module imports means the builder
|
|
6
|
+
* core is ~12 KB minified instead of ~25 KB.
|
|
7
|
+
*
|
|
8
|
+
* Plugins compose features *around* the hot path via extension points:
|
|
9
|
+
* afterScroll, clickHandlers, keydownHandlers, resizeHandlers, destroyHandlers,
|
|
10
|
+
* and the methods Map for public API extension.
|
|
11
|
+
*/
|
|
12
|
+
import type { VListItem } from "../types";
|
|
13
|
+
import type { BuilderConfig, VListBuilder } from "./types";
|
|
14
|
+
export type { CompressionState } from "../render/virtual";
|
|
15
|
+
export declare const vlist: <T extends VListItem = VListItem>(config: BuilderConfig<T>) => VListBuilder<T>;
|
|
16
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/builder/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,SAAS,EAOV,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EACV,aAAa,EAKb,YAAY,EAGb,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAqb1D,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,SAAS,GAAG,SAAS,EACnD,QAAQ,aAAa,CAAC,CAAC,CAAC,KACvB,YAAY,CAAC,CAAC,CAoEhB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist/builder - Lightweight In-Memory Data Manager
|
|
3
|
+
*
|
|
4
|
+
* A minimal data manager that stores items in a plain array.
|
|
5
|
+
* No sparse storage, no placeholders, no async adapter support.
|
|
6
|
+
*
|
|
7
|
+
* This keeps the builder core small (~12 KB). When the user installs
|
|
8
|
+
* withData(), that plugin replaces this manager with the full
|
|
9
|
+
* adapter-backed data manager from src/data/manager.ts.
|
|
10
|
+
*/
|
|
11
|
+
import type { VListItem, Range } from "../types";
|
|
12
|
+
/** Minimal data state */
|
|
13
|
+
export interface SimpleDataState<_T extends VListItem = VListItem> {
|
|
14
|
+
total: number;
|
|
15
|
+
cached: number;
|
|
16
|
+
isLoading: boolean;
|
|
17
|
+
pendingRanges: Range[];
|
|
18
|
+
error: Error | undefined;
|
|
19
|
+
hasMore: boolean;
|
|
20
|
+
cursor: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* SimpleDataManager — the same interface as the full DataManager,
|
|
24
|
+
* but backed by a plain array instead of sparse storage + placeholders.
|
|
25
|
+
*
|
|
26
|
+
* Only the methods used by the builder core and plugins are implemented.
|
|
27
|
+
* Adapter-related methods (loadRange, ensureRange, loadInitial, loadMore,
|
|
28
|
+
* reload, evictDistant) are no-ops or stubs.
|
|
29
|
+
*/
|
|
30
|
+
export interface SimpleDataManager<T extends VListItem = VListItem> {
|
|
31
|
+
getState: () => SimpleDataState<T>;
|
|
32
|
+
getTotal: () => number;
|
|
33
|
+
getCached: () => number;
|
|
34
|
+
getIsLoading: () => boolean;
|
|
35
|
+
getHasMore: () => boolean;
|
|
36
|
+
getStorage: () => unknown;
|
|
37
|
+
getPlaceholders: () => unknown;
|
|
38
|
+
getItem: (index: number) => T | undefined;
|
|
39
|
+
getItemById: (id: string | number) => T | undefined;
|
|
40
|
+
getIndexById: (id: string | number) => number;
|
|
41
|
+
isItemLoaded: (index: number) => boolean;
|
|
42
|
+
getItemsInRange: (start: number, end: number) => T[];
|
|
43
|
+
setTotal: (total: number) => void;
|
|
44
|
+
setItems: (items: T[], offset?: number, total?: number) => void;
|
|
45
|
+
updateItem: (id: string | number, updates: Partial<T>) => boolean;
|
|
46
|
+
removeItem: (id: string | number) => boolean;
|
|
47
|
+
loadRange: (start: number, end: number) => Promise<void>;
|
|
48
|
+
ensureRange: (start: number, end: number) => Promise<void>;
|
|
49
|
+
loadInitial: () => Promise<void>;
|
|
50
|
+
loadMore: () => Promise<boolean>;
|
|
51
|
+
reload: () => Promise<void>;
|
|
52
|
+
evictDistant: (visibleStart: number, visibleEnd: number) => void;
|
|
53
|
+
clear: () => void;
|
|
54
|
+
reset: () => void;
|
|
55
|
+
}
|
|
56
|
+
export interface SimpleDataManagerConfig<T extends VListItem = VListItem> {
|
|
57
|
+
initialItems?: T[];
|
|
58
|
+
initialTotal?: number;
|
|
59
|
+
onStateChange?: (state: SimpleDataState<T>) => void;
|
|
60
|
+
onItemsLoaded?: (items: T[], offset: number, total: number) => void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a lightweight in-memory data manager.
|
|
64
|
+
*
|
|
65
|
+
* Items are stored in a plain array. ID lookups use a Map.
|
|
66
|
+
* No sparse storage, no placeholders, no chunking, no eviction.
|
|
67
|
+
*
|
|
68
|
+
* ~1 KB minified vs ~8 KB for the full data manager.
|
|
69
|
+
*/
|
|
70
|
+
export declare const createSimpleDataManager: <T extends VListItem = VListItem>(config?: SimpleDataManagerConfig<T>) => SimpleDataManager<T>;
|
|
71
|
+
//# sourceMappingURL=data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/builder/data.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist/builder - Composable Virtual List Builder
|
|
3
|
+
* Pick only the features you need, pay only for what you ship.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { vlist } from 'vlist/builder'
|
|
8
|
+
* import { withSelection } from 'vlist/selection'
|
|
9
|
+
* import { withScrollbar } from 'vlist/scroll'
|
|
10
|
+
*
|
|
11
|
+
* const list = vlist({
|
|
12
|
+
* container: '#app',
|
|
13
|
+
* item: { height: 48, template: renderItem },
|
|
14
|
+
* items: data,
|
|
15
|
+
* })
|
|
16
|
+
* .use(withSelection({ mode: 'multiple' }))
|
|
17
|
+
* .use(withScrollbar())
|
|
18
|
+
* .build()
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
export { vlist } from "./core";
|
|
24
|
+
export type { VListBuilder, BuiltVList, BuilderConfig, VListPlugin, BuilderContext, ResolvedBuilderConfig, BuilderState, CachedCompression, } from "./types";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/builder/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG/B,YAAY,EAEV,YAAY,EACZ,UAAU,EACV,aAAa,EAGb,WAAW,EACX,cAAc,EAGd,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,GAClB,MAAM,SAAS,CAAC"}
|