virtua 0.49.2 → 0.49.3
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/lib/svelte/ListItem.svelte +12 -2
- package/lib/svelte/VList.svelte +2 -0
- package/lib/svelte/VList.type.d.ts +1 -1
- package/lib/svelte/Virtualizer.svelte +2 -0
- package/lib/svelte/Virtualizer.type.d.ts +5 -0
- package/lib/svelte/utils.d.ts +7 -0
- package/lib/svelte/utils.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" generics="T">
|
|
2
2
|
import { type Snippet, onDestroy } from "svelte";
|
|
3
3
|
import { type ItemResizeObserver } from "../core/index.js";
|
|
4
|
-
import { styleToString } from "./utils.js";
|
|
4
|
+
import { styleToString, type ItemAttrs } from "./utils.js";
|
|
5
5
|
import type { SvelteHTMLElements } from "svelte/elements";
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
hide: boolean;
|
|
14
14
|
horizontal: boolean;
|
|
15
15
|
resizer: ItemResizeObserver;
|
|
16
|
+
itemProps?: ItemAttrs | undefined;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
let {
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
hide,
|
|
25
26
|
horizontal,
|
|
26
27
|
resizer,
|
|
28
|
+
itemProps,
|
|
27
29
|
}: Props = $props();
|
|
28
30
|
|
|
29
31
|
let elementRef: HTMLDivElement;
|
|
@@ -48,6 +50,7 @@
|
|
|
48
50
|
[horizontal ? "top" : "left"]: "0px",
|
|
49
51
|
[horizontal ? "left" : "top"]: offset + "px",
|
|
50
52
|
visibility: hide ? "hidden" : undefined,
|
|
53
|
+
...itemProps?.style,
|
|
51
54
|
};
|
|
52
55
|
if (horizontal) {
|
|
53
56
|
_style["display"] = "inline-flex";
|
|
@@ -55,8 +58,15 @@
|
|
|
55
58
|
|
|
56
59
|
return styleToString(_style);
|
|
57
60
|
});
|
|
61
|
+
|
|
62
|
+
// `style` is applied separately above, the rest (e.g. `class`) is spread onto the element
|
|
63
|
+
let itemRest = $derived.by(() => {
|
|
64
|
+
if (!itemProps) return undefined;
|
|
65
|
+
const { style: _style, ...rest } = itemProps;
|
|
66
|
+
return rest;
|
|
67
|
+
});
|
|
58
68
|
</script>
|
|
59
69
|
|
|
60
|
-
<svelte:element this={as} bind:this={elementRef} {style}>
|
|
70
|
+
<svelte:element this={as} bind:this={elementRef} {style} {...itemRest}>
|
|
61
71
|
{@render children(item, index)}
|
|
62
72
|
</svelte:element>
|
package/lib/svelte/VList.svelte
CHANGED
|
@@ -3,7 +3,7 @@ import type { VirtualizerHandle, VirtualizerProps } from "./Virtualizer.type.js"
|
|
|
3
3
|
/**
|
|
4
4
|
* Props of {@link VList}.
|
|
5
5
|
*/
|
|
6
|
-
export interface VListProps<T> extends Pick<VirtualizerProps<T>, "data" | "getKey" | "bufferSize" | "itemSize" | "ssrCount" | "shift" | "horizontal" | "children" | "onscroll" | "onscrollend" | "keepMounted" | "cache">, ViewportComponentAttributes {
|
|
6
|
+
export interface VListProps<T> extends Pick<VirtualizerProps<T>, "data" | "getKey" | "bufferSize" | "itemSize" | "ssrCount" | "shift" | "horizontal" | "children" | "onscroll" | "onscrollend" | "keepMounted" | "cache" | "itemProps">, ViewportComponentAttributes {
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Methods of {@link VList}.
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
getKey = defaultGetKey,
|
|
28
28
|
as = "div",
|
|
29
29
|
item: itemAs,
|
|
30
|
+
itemProps,
|
|
30
31
|
scrollRef,
|
|
31
32
|
bufferSize,
|
|
32
33
|
itemSize,
|
|
@@ -187,6 +188,7 @@
|
|
|
187
188
|
hide={stateVersion && store.$isUnmeasuredItem(index)}
|
|
188
189
|
{horizontal}
|
|
189
190
|
resizer={resizer.$observeItem}
|
|
191
|
+
itemProps={itemProps?.({ item, index })}
|
|
190
192
|
/>
|
|
191
193
|
{/each}
|
|
192
194
|
</svelte:element>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Snippet } from "svelte";
|
|
2
2
|
import type { SvelteHTMLElements } from "svelte/elements";
|
|
3
3
|
import { type CacheSnapshot, type ScrollToIndexOpts } from "../core/index.js";
|
|
4
|
+
import { type ItemProps } from "./utils.js";
|
|
4
5
|
/**
|
|
5
6
|
* Props of {@link Virtualizer}.
|
|
6
7
|
*/
|
|
@@ -28,6 +29,10 @@ export interface VirtualizerProps<T> {
|
|
|
28
29
|
* @defaultValue "div"
|
|
29
30
|
*/
|
|
30
31
|
item?: keyof SvelteHTMLElements;
|
|
32
|
+
/**
|
|
33
|
+
* A function that provides properties/attributes for item element
|
|
34
|
+
*/
|
|
35
|
+
itemProps?: ItemProps<T>;
|
|
31
36
|
/**
|
|
32
37
|
* Extra item space in pixels to render before/after the viewport. The minimum value is 0. Lower value will give better performance but you can increase to avoid showing blank items in fast scrolling.
|
|
33
38
|
* @defaultValue 200
|
package/lib/svelte/utils.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export declare const styleToString: (obj: Record<string, string | undefined>) => string;
|
|
2
2
|
export declare const defaultGetKey: (_data: unknown, i: number) => string;
|
|
3
|
+
/**
|
|
4
|
+
* A function that provides properties/attributes for item element
|
|
5
|
+
*/
|
|
6
|
+
export type ItemProps<T = unknown> = (payload: {
|
|
7
|
+
item: T;
|
|
8
|
+
index: number;
|
|
9
|
+
}) => ItemAttrs | undefined;
|
package/lib/svelte/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/svelte/utils.ts"],"sourcesContent":["export const styleToString = (\n obj: Record<string, string | undefined>,\n): string => {\n return Object.keys(obj).reduce((acc, k) => {\n const value = obj[k];\n if (value == null) {\n return acc;\n }\n return acc + `${k}:${value};`;\n }, \"\");\n};\n\nexport const defaultGetKey = (_data: unknown, i: number) => \"_\" + i;\n"],"names":[],"mappings":"AAAO,MAAM,aAAa,GAAG,CAC3B,GAAuC,KAC7B;AACV,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,KAAI;AACxC,QAAA,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC;AACpB,QAAA,IAAI,KAAK,IAAI,IAAI,EAAE;AACjB,YAAA,OAAO,GAAG;QACZ;AACA,QAAA,OAAO,GAAG,GAAG,CAAA,EAAG,CAAC,CAAA,CAAA,EAAI,KAAK,GAAG;IAC/B,CAAC,EAAE,EAAE,CAAC;AACR;AAEO,MAAM,aAAa,GAAG,CAAC,KAAc,EAAE,CAAS,KAAK,GAAG,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/svelte/utils.ts"],"sourcesContent":["export const styleToString = (\n obj: Record<string, string | undefined>,\n): string => {\n return Object.keys(obj).reduce((acc, k) => {\n const value = obj[k];\n if (value == null) {\n return acc;\n }\n return acc + `${k}:${value};`;\n }, \"\");\n};\n\nexport const defaultGetKey = (_data: unknown, i: number) => \"_\" + i;\n\n/**\n * @internal\n */\nexport type ItemAttrs = {\n [key: string]: any;\n style?: Record<string, string | undefined>;\n class?: string;\n};\n\n/**\n * A function that provides properties/attributes for item element\n */\nexport type ItemProps<T = unknown> = (payload: {\n item: T;\n index: number;\n}) => ItemAttrs | undefined;\n"],"names":[],"mappings":"AAAO,MAAM,aAAa,GAAG,CAC3B,GAAuC,KAC7B;AACV,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,KAAI;AACxC,QAAA,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC;AACpB,QAAA,IAAI,KAAK,IAAI,IAAI,EAAE;AACjB,YAAA,OAAO,GAAG;QACZ;AACA,QAAA,OAAO,GAAG,GAAG,CAAA,EAAG,CAAC,CAAA,CAAA,EAAI,KAAK,GAAG;IAC/B,CAAC,EAAE,EAAE,CAAC;AACR;AAEO,MAAM,aAAa,GAAG,CAAC,KAAc,EAAE,CAAS,KAAK,GAAG,GAAG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "virtua",
|
|
3
|
-
"version": "0.49.
|
|
3
|
+
"version": "0.49.3",
|
|
4
4
|
"description": "A zero-config, fast and small (~3kB) virtual list (and grid) component for React, Vue, Solid and Svelte.",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
"typedoc-plugin-markdown": "^4.6.3",
|
|
141
141
|
"typescript": "^6.0.3",
|
|
142
142
|
"typescript-eslint": "^8.46.2",
|
|
143
|
-
"unplugin-vue-jsx": "^0.
|
|
143
|
+
"unplugin-vue-jsx": "^0.10.0",
|
|
144
144
|
"virtua": "^0.49.0",
|
|
145
145
|
"vite": "^8.0.13",
|
|
146
146
|
"vite-plugin-solid": "^2.11.12",
|