vlist-svelte 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Floor IO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # vlist-svelte
2
+
3
+ Svelte action for [vlist](https://github.com/floor/vlist) - lightweight, zero-dependency virtual scrolling.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @floor/vlist vlist-svelte
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```svelte
14
+ <script>
15
+ import { vlist } from 'vlist-svelte';
16
+ import '@floor/vlist/styles';
17
+
18
+ let users = [...];
19
+ let instance;
20
+
21
+ const config = {
22
+ item: {
23
+ height: 48,
24
+ template: (user) => `<div class="user">${user.name}</div>`,
25
+ },
26
+ items: users,
27
+ };
28
+ </script>
29
+
30
+ <div
31
+ use:vlist={{ config, onInstance: (i) => (instance = i) }}
32
+ style="height: 400px"
33
+ />
34
+ ```
35
+
36
+ ## API
37
+
38
+ ### `vlist` action
39
+
40
+ **Parameters:**
41
+ - `config` - VList configuration (same as core vlist, minus `container`)
42
+ - `onInstance` - Callback to receive the vlist instance
43
+
44
+ **Example with instance access:**
45
+
46
+ ```svelte
47
+ <script>
48
+ import { vlist } from 'vlist-svelte';
49
+
50
+ let instance;
51
+
52
+ function scrollToTop() {
53
+ instance?.scrollToIndex(0);
54
+ }
55
+ </script>
56
+
57
+ <div use:vlist={{ config, onInstance: (i) => (instance = i) }} />
58
+ <button on:click={scrollToTop}>Top</button>
59
+ ```
60
+
61
+ ## Documentation
62
+
63
+ For full documentation, see [vlist.dev](https://vlist.dev)
64
+
65
+ ## License
66
+
67
+ MIT © [Floor IO](https://floor.io)
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Svelte action for vlist - lightweight virtual scrolling
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import type { VListConfig, VListItem, VList, VListEvents, EventHandler, Unsubscribe } from "@floor/vlist";
7
+ /** Configuration for vlist action (VListConfig without container) */
8
+ export type VListActionConfig<T extends VListItem = VListItem> = Omit<VListConfig<T>, "container">;
9
+ /** Options for the vlist action */
10
+ export interface VListActionOptions<T extends VListItem = VListItem> {
11
+ /** VList configuration */
12
+ config: VListActionConfig<T>;
13
+ /** Callback to receive the vlist instance */
14
+ onInstance?: (instance: VList<T>) => void;
15
+ }
16
+ /** Return value from the vlist action */
17
+ export interface VListActionReturn<T extends VListItem = VListItem> {
18
+ /** Update the configuration */
19
+ update?: (options: VListActionOptions<T>) => void;
20
+ /** Cleanup */
21
+ destroy?: () => void;
22
+ }
23
+ /**
24
+ * Svelte action for vlist integration.
25
+ *
26
+ * @example
27
+ * ```svelte
28
+ * <script>
29
+ * import { vlist } from 'vlist-svelte';
30
+ * import '@floor/vlist/styles';
31
+ *
32
+ * let users = [...];
33
+ * let instance;
34
+ *
35
+ * const config = {
36
+ * item: {
37
+ * height: 48,
38
+ * template: (user) => `<div>${user.name}</div>`,
39
+ * },
40
+ * items: users,
41
+ * };
42
+ * </script>
43
+ *
44
+ * <div
45
+ * use:vlist={{ config, onInstance: (i) => (instance = i) }}
46
+ * style="height: 400px"
47
+ * />
48
+ * ```
49
+ */
50
+ export declare function vlist<T extends VListItem = VListItem>(node: HTMLElement, options: VListActionOptions<T>): VListActionReturn<T>;
51
+ /**
52
+ * Helper to subscribe to vlist events in Svelte
53
+ *
54
+ * @example
55
+ * ```svelte
56
+ * <script>
57
+ * import { vlist, onVListEvent } from 'vlist-svelte';
58
+ *
59
+ * let instance;
60
+ *
61
+ * $: if (instance) {
62
+ * onVListEvent(instance, 'selection:change', ({ selected }) => {
63
+ * console.log('Selected:', selected);
64
+ * });
65
+ * }
66
+ * </script>
67
+ * ```
68
+ */
69
+ export declare function onVListEvent<T extends VListItem, K extends keyof VListEvents<T>>(instance: VList<T>, event: K, handler: EventHandler<VListEvents<T>[K]>): Unsubscribe;
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{vlist as J}from"@floor/vlist";import{withAsync as K,withGrid as M,withSections as N,withSelection as I,withScrollbar as Q,withScale as R,withSnapshots as T,withPage as U}from"@floor/vlist";function Z(D,q){let k=q.config,j=J({...k,container:D});if(k.scroll?.element===window)j=j.use(U());if(k.adapter)j=j.use(K({adapter:k.adapter,...k.loading&&{loading:k.loading}}));if(k.layout==="grid"&&k.grid)j=j.use(M(k.grid));if(k.groups)j=j.use(N(k.groups));if((k.selection?.mode||"none")!=="none")j=j.use(I(k.selection));else j=j.use(I({mode:"none"}));j=j.use(R());let F=k.scroll?.scrollbar||k.scrollbar;if(F!=="none"){let B=typeof F==="object"?F:{};j=j.use(Q(B))}j=j.use(T());let z=j.build();if(q.onInstance)q.onInstance(z);return{update(B){if(B.config.items&&z)z.setItems(B.config.items)},destroy(){if(z)z.destroy()}}}function _(D,q,k){return D.on(q,k)}export{Z as vlist,_ as onVListEvent};
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "vlist-svelte",
3
+ "version": "0.1.0",
4
+ "description": "Svelte action for vlist - lightweight virtual scrolling",
5
+ "author": {
6
+ "name": "Floor IO",
7
+ "url": "https://floor.io"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/floor/vlist-svelte.git"
12
+ },
13
+ "keywords": [
14
+ "vlist",
15
+ "virtual-list",
16
+ "svelte",
17
+ "action",
18
+ "virtual-scrolling",
19
+ "typescript"
20
+ ],
21
+ "license": "MIT",
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "peerDependencies": {
35
+ "@floor/vlist": "^0.6.0",
36
+ "svelte": ">=3.0.0"
37
+ },
38
+ "files": [
39
+ "dist/**/*.js",
40
+ "dist/**/*.d.ts",
41
+ "!dist/**/*.d.ts.map"
42
+ ],
43
+ "scripts": {
44
+ "build": "bun run build.ts",
45
+ "dev": "bun run build.ts --watch",
46
+ "typecheck": "tsc --noEmit",
47
+ "prepublishOnly": "bun run build"
48
+ },
49
+ "devDependencies": {
50
+ "@floor/vlist": "link:../vlist",
51
+ "@types/bun": "^1.0.0",
52
+ "bun": "^1.0.0",
53
+ "svelte": "^5.0.0",
54
+ "typescript": "^5.0.0"
55
+ }
56
+ }