@oxog/scrollex 1.0.0 → 1.0.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/CHANGELOG.md +66 -5
- package/README.md +30 -22
- package/dist/index.cjs +796 -363
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -15
- package/dist/index.d.ts +39 -15
- package/dist/index.js +797 -364
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.cjs +381 -180
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +74 -49
- package/dist/plugins/index.d.ts +74 -49
- package/dist/plugins/index.js +381 -180
- package/dist/plugins/index.js.map +1 -1
- package/package.json +13 -10
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React$1, { CSSProperties, RefCallback,
|
|
1
|
+
import React$1, { CSSProperties, RefCallback, RefObject, ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents a virtualized item with position and size information.
|
|
@@ -224,10 +224,10 @@ interface Plugin {
|
|
|
224
224
|
version: string;
|
|
225
225
|
/** Plugin type (core or optional) */
|
|
226
226
|
type: PluginType;
|
|
227
|
-
/** Install plugin into kernel */
|
|
228
|
-
install
|
|
229
|
-
/** Uninstall plugin */
|
|
230
|
-
uninstall
|
|
227
|
+
/** Install plugin into kernel (required: the registry rejects a plugin without it) */
|
|
228
|
+
install(kernel: Kernel): void;
|
|
229
|
+
/** Uninstall plugin (required: the registry rejects a plugin without it) */
|
|
230
|
+
uninstall(): void;
|
|
231
231
|
/** Plugin hooks */
|
|
232
232
|
hooks?: PluginHooks;
|
|
233
233
|
/** Public API exposed by the plugin */
|
|
@@ -259,6 +259,8 @@ interface KernelOptions {
|
|
|
259
259
|
direction: 'vertical' | 'horizontal';
|
|
260
260
|
/** Function to get item key */
|
|
261
261
|
getItemKey?: (index: number) => string | number;
|
|
262
|
+
/** Space before the first item (px): item offsets, the total size and scrollToIndex include it (default 0) */
|
|
263
|
+
paddingStart?: number;
|
|
262
264
|
}
|
|
263
265
|
/**
|
|
264
266
|
* Kernel interface - the core of the virtualization engine.
|
|
@@ -275,7 +277,7 @@ interface Kernel {
|
|
|
275
277
|
/** Get current scroll position */
|
|
276
278
|
getScrollPosition(): ScrollPosition;
|
|
277
279
|
/** Set scroll position directly */
|
|
278
|
-
setScrollPosition(position: ScrollPosition): void;
|
|
280
|
+
setScrollPosition(position: Partial<ScrollPosition>): void;
|
|
279
281
|
/** Scroll to offset */
|
|
280
282
|
scrollTo(offset: number, options?: ScrollOptions): void;
|
|
281
283
|
/** Scroll to item index */
|
|
@@ -300,9 +302,15 @@ interface Kernel {
|
|
|
300
302
|
getItemOffset(index: number): number;
|
|
301
303
|
/** Emit an event */
|
|
302
304
|
emit(event: KernelEvent): void;
|
|
303
|
-
/** Subscribe to an event type */
|
|
305
|
+
/** Subscribe to an event type; the handler receives that event's payload */
|
|
306
|
+
on<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
|
|
307
|
+
type: K;
|
|
308
|
+
}>>): Unsubscribe;
|
|
304
309
|
on<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): Unsubscribe;
|
|
305
310
|
/** Unsubscribe from an event type */
|
|
311
|
+
off<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
|
|
312
|
+
type: K;
|
|
313
|
+
}>>): void;
|
|
306
314
|
off<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): void;
|
|
307
315
|
/** Update kernel configuration */
|
|
308
316
|
configure(options: Partial<KernelOptions>): void;
|
|
@@ -435,8 +443,9 @@ interface GridGap {
|
|
|
435
443
|
}
|
|
436
444
|
/**
|
|
437
445
|
* VirtualGrid component props.
|
|
446
|
+
* Vertical only, with a fixed row height: `direction` and `estimatedItemHeight` are not part of the props.
|
|
438
447
|
*/
|
|
439
|
-
interface VirtualGridProps<T> extends Omit<VirtualListProps<T>, 'itemHeight' | 'renderItem'> {
|
|
448
|
+
interface VirtualGridProps<T> extends Omit<VirtualListProps<T>, 'itemHeight' | 'renderItem' | 'direction' | 'estimatedItemHeight'> {
|
|
440
449
|
/** Render function for grid items */
|
|
441
450
|
renderItem: (props: GridRenderItemProps<T>) => ReactNode;
|
|
442
451
|
/** Fixed row height */
|
|
@@ -510,13 +519,19 @@ interface UseVirtualListReturn {
|
|
|
510
519
|
invalidateMeasurement: (index: number) => void;
|
|
511
520
|
/** Invalidate all measurements */
|
|
512
521
|
invalidateAllMeasurements: () => void;
|
|
522
|
+
/** Kernel instance driving this virtualizer */
|
|
523
|
+
kernel: Kernel;
|
|
513
524
|
}
|
|
514
525
|
/**
|
|
515
526
|
* Options for useVirtualGrid hook.
|
|
527
|
+
* (Not the list hook's `estimatedItemHeight`, `horizontal`, `paddingStart`, `paddingEnd`, `scrollMargin` or
|
|
528
|
+
* `getItemHeight`: the grid hook reads none of them.)
|
|
516
529
|
*/
|
|
517
|
-
interface UseVirtualGridOptions extends Omit<UseVirtualListOptions, 'getItemHeight'> {
|
|
518
|
-
/** Number of columns */
|
|
519
|
-
columns: number;
|
|
530
|
+
interface UseVirtualGridOptions extends Omit<UseVirtualListOptions, 'getItemHeight' | 'estimatedItemHeight' | 'horizontal' | 'paddingStart' | 'paddingEnd' | 'scrollMargin'> {
|
|
531
|
+
/** Number of columns, or 'auto' to fit as many columns of minColumnWidth as possible */
|
|
532
|
+
columns: number | 'auto';
|
|
533
|
+
/** Minimum column width for auto columns */
|
|
534
|
+
minColumnWidth?: number;
|
|
520
535
|
/** Row height */
|
|
521
536
|
rowHeight: number;
|
|
522
537
|
/** Gap between items */
|
|
@@ -539,12 +554,18 @@ interface UseVirtualGridReturn extends UseVirtualListReturn {
|
|
|
539
554
|
interface UseVirtualMasonryOptions {
|
|
540
555
|
/** Total number of items */
|
|
541
556
|
count: number;
|
|
542
|
-
/** Number of columns */
|
|
543
|
-
columns: number;
|
|
557
|
+
/** Number of columns, or 'auto' to fit as many as `minColumnWidth` allows */
|
|
558
|
+
columns: number | 'auto';
|
|
559
|
+
/** Minimum column width for 'auto' columns (default 200) */
|
|
560
|
+
minColumnWidth?: number;
|
|
561
|
+
/** Initial scroll offset */
|
|
562
|
+
initialOffset?: number;
|
|
563
|
+
/** Function to get item key */
|
|
564
|
+
getItemKey?: (index: number) => string | number;
|
|
544
565
|
/** Function to get item height given index and column width */
|
|
545
566
|
getItemHeight: (index: number, columnWidth: number) => number;
|
|
546
567
|
/** Gap between items */
|
|
547
|
-
gap?: number;
|
|
568
|
+
gap?: number | GridGap;
|
|
548
569
|
/** Container ref */
|
|
549
570
|
containerRef: RefObject<HTMLElement>;
|
|
550
571
|
/** Number of extra items to render */
|
|
@@ -923,6 +944,8 @@ interface GridRendererOptions {
|
|
|
923
944
|
gap?: number | GridGap;
|
|
924
945
|
/** Get item key for React reconciliation */
|
|
925
946
|
getItemKey?: (index: number) => string | number;
|
|
947
|
+
/** Width the columns share, when it is not the viewport width (the content box of a padded container) */
|
|
948
|
+
getContainerWidth?: () => number | undefined;
|
|
926
949
|
}
|
|
927
950
|
/**
|
|
928
951
|
* Grid renderer plugin API.
|
|
@@ -1081,4 +1104,5 @@ interface ScrollControllerAPI {
|
|
|
1081
1104
|
*/
|
|
1082
1105
|
declare function scrollControllerPlugin(options?: ScrollControllerOptions): Plugin;
|
|
1083
1106
|
|
|
1084
|
-
export {
|
|
1107
|
+
export { VirtualGrid, VirtualList, VirtualMasonry, autoMeasurerPlugin, createKernel, createPlugin, easings, gridRendererPlugin, infiniteLoaderPlugin, listRendererPlugin, scrollControllerPlugin, useMeasure, useMeasureMany, useScrollex, useScrollexRequired, useVirtualGrid, useVirtualList, useVirtualMasonry };
|
|
1108
|
+
export type { AutoMeasurerAPI, AutoMeasurerOptions, EasingFunction, EventHandler, EventType, GridGap, GridRenderItemProps, GridRendererAPI, GridRendererOptions, InfiniteLoaderAPI, InfiniteLoaderOptions, ItemMeasuredEvent, ItemsChangeEvent, ItemsRenderedInfo, Kernel, KernelEvent, KernelOptions, ListRendererAPI, ListRendererOptions, LoadDirection, LoadMoreEvent, MasonryRenderItemProps, Plugin, PluginConfig, PluginHooks, PluginInfo, PluginType, Range, RenderItemProps, ResizeEvent, ScrollAlignment, ScrollBehavior, ScrollControllerAPI, ScrollControllerOptions, ScrollDirection, ScrollEndEvent, ScrollEvent, ScrollOptions, ScrollPosition, ScrollStartEvent, ScrollToIndexOptions, Unsubscribe, UseMeasureOptions, UseMeasureReturn, UseVirtualGridOptions, UseVirtualGridReturn, UseVirtualListOptions, UseVirtualListReturn, UseVirtualMasonryOptions, UseVirtualMasonryReturn, Viewport, VirtualGridProps, VirtualItem, VirtualListHandle, VirtualListProps, VirtualMasonryProps, VisibleRangeChangeEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React$1, { CSSProperties, RefCallback,
|
|
1
|
+
import React$1, { CSSProperties, RefCallback, RefObject, ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents a virtualized item with position and size information.
|
|
@@ -224,10 +224,10 @@ interface Plugin {
|
|
|
224
224
|
version: string;
|
|
225
225
|
/** Plugin type (core or optional) */
|
|
226
226
|
type: PluginType;
|
|
227
|
-
/** Install plugin into kernel */
|
|
228
|
-
install
|
|
229
|
-
/** Uninstall plugin */
|
|
230
|
-
uninstall
|
|
227
|
+
/** Install plugin into kernel (required: the registry rejects a plugin without it) */
|
|
228
|
+
install(kernel: Kernel): void;
|
|
229
|
+
/** Uninstall plugin (required: the registry rejects a plugin without it) */
|
|
230
|
+
uninstall(): void;
|
|
231
231
|
/** Plugin hooks */
|
|
232
232
|
hooks?: PluginHooks;
|
|
233
233
|
/** Public API exposed by the plugin */
|
|
@@ -259,6 +259,8 @@ interface KernelOptions {
|
|
|
259
259
|
direction: 'vertical' | 'horizontal';
|
|
260
260
|
/** Function to get item key */
|
|
261
261
|
getItemKey?: (index: number) => string | number;
|
|
262
|
+
/** Space before the first item (px): item offsets, the total size and scrollToIndex include it (default 0) */
|
|
263
|
+
paddingStart?: number;
|
|
262
264
|
}
|
|
263
265
|
/**
|
|
264
266
|
* Kernel interface - the core of the virtualization engine.
|
|
@@ -275,7 +277,7 @@ interface Kernel {
|
|
|
275
277
|
/** Get current scroll position */
|
|
276
278
|
getScrollPosition(): ScrollPosition;
|
|
277
279
|
/** Set scroll position directly */
|
|
278
|
-
setScrollPosition(position: ScrollPosition): void;
|
|
280
|
+
setScrollPosition(position: Partial<ScrollPosition>): void;
|
|
279
281
|
/** Scroll to offset */
|
|
280
282
|
scrollTo(offset: number, options?: ScrollOptions): void;
|
|
281
283
|
/** Scroll to item index */
|
|
@@ -300,9 +302,15 @@ interface Kernel {
|
|
|
300
302
|
getItemOffset(index: number): number;
|
|
301
303
|
/** Emit an event */
|
|
302
304
|
emit(event: KernelEvent): void;
|
|
303
|
-
/** Subscribe to an event type */
|
|
305
|
+
/** Subscribe to an event type; the handler receives that event's payload */
|
|
306
|
+
on<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
|
|
307
|
+
type: K;
|
|
308
|
+
}>>): Unsubscribe;
|
|
304
309
|
on<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): Unsubscribe;
|
|
305
310
|
/** Unsubscribe from an event type */
|
|
311
|
+
off<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
|
|
312
|
+
type: K;
|
|
313
|
+
}>>): void;
|
|
306
314
|
off<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): void;
|
|
307
315
|
/** Update kernel configuration */
|
|
308
316
|
configure(options: Partial<KernelOptions>): void;
|
|
@@ -435,8 +443,9 @@ interface GridGap {
|
|
|
435
443
|
}
|
|
436
444
|
/**
|
|
437
445
|
* VirtualGrid component props.
|
|
446
|
+
* Vertical only, with a fixed row height: `direction` and `estimatedItemHeight` are not part of the props.
|
|
438
447
|
*/
|
|
439
|
-
interface VirtualGridProps<T> extends Omit<VirtualListProps<T>, 'itemHeight' | 'renderItem'> {
|
|
448
|
+
interface VirtualGridProps<T> extends Omit<VirtualListProps<T>, 'itemHeight' | 'renderItem' | 'direction' | 'estimatedItemHeight'> {
|
|
440
449
|
/** Render function for grid items */
|
|
441
450
|
renderItem: (props: GridRenderItemProps<T>) => ReactNode;
|
|
442
451
|
/** Fixed row height */
|
|
@@ -510,13 +519,19 @@ interface UseVirtualListReturn {
|
|
|
510
519
|
invalidateMeasurement: (index: number) => void;
|
|
511
520
|
/** Invalidate all measurements */
|
|
512
521
|
invalidateAllMeasurements: () => void;
|
|
522
|
+
/** Kernel instance driving this virtualizer */
|
|
523
|
+
kernel: Kernel;
|
|
513
524
|
}
|
|
514
525
|
/**
|
|
515
526
|
* Options for useVirtualGrid hook.
|
|
527
|
+
* (Not the list hook's `estimatedItemHeight`, `horizontal`, `paddingStart`, `paddingEnd`, `scrollMargin` or
|
|
528
|
+
* `getItemHeight`: the grid hook reads none of them.)
|
|
516
529
|
*/
|
|
517
|
-
interface UseVirtualGridOptions extends Omit<UseVirtualListOptions, 'getItemHeight'> {
|
|
518
|
-
/** Number of columns */
|
|
519
|
-
columns: number;
|
|
530
|
+
interface UseVirtualGridOptions extends Omit<UseVirtualListOptions, 'getItemHeight' | 'estimatedItemHeight' | 'horizontal' | 'paddingStart' | 'paddingEnd' | 'scrollMargin'> {
|
|
531
|
+
/** Number of columns, or 'auto' to fit as many columns of minColumnWidth as possible */
|
|
532
|
+
columns: number | 'auto';
|
|
533
|
+
/** Minimum column width for auto columns */
|
|
534
|
+
minColumnWidth?: number;
|
|
520
535
|
/** Row height */
|
|
521
536
|
rowHeight: number;
|
|
522
537
|
/** Gap between items */
|
|
@@ -539,12 +554,18 @@ interface UseVirtualGridReturn extends UseVirtualListReturn {
|
|
|
539
554
|
interface UseVirtualMasonryOptions {
|
|
540
555
|
/** Total number of items */
|
|
541
556
|
count: number;
|
|
542
|
-
/** Number of columns */
|
|
543
|
-
columns: number;
|
|
557
|
+
/** Number of columns, or 'auto' to fit as many as `minColumnWidth` allows */
|
|
558
|
+
columns: number | 'auto';
|
|
559
|
+
/** Minimum column width for 'auto' columns (default 200) */
|
|
560
|
+
minColumnWidth?: number;
|
|
561
|
+
/** Initial scroll offset */
|
|
562
|
+
initialOffset?: number;
|
|
563
|
+
/** Function to get item key */
|
|
564
|
+
getItemKey?: (index: number) => string | number;
|
|
544
565
|
/** Function to get item height given index and column width */
|
|
545
566
|
getItemHeight: (index: number, columnWidth: number) => number;
|
|
546
567
|
/** Gap between items */
|
|
547
|
-
gap?: number;
|
|
568
|
+
gap?: number | GridGap;
|
|
548
569
|
/** Container ref */
|
|
549
570
|
containerRef: RefObject<HTMLElement>;
|
|
550
571
|
/** Number of extra items to render */
|
|
@@ -923,6 +944,8 @@ interface GridRendererOptions {
|
|
|
923
944
|
gap?: number | GridGap;
|
|
924
945
|
/** Get item key for React reconciliation */
|
|
925
946
|
getItemKey?: (index: number) => string | number;
|
|
947
|
+
/** Width the columns share, when it is not the viewport width (the content box of a padded container) */
|
|
948
|
+
getContainerWidth?: () => number | undefined;
|
|
926
949
|
}
|
|
927
950
|
/**
|
|
928
951
|
* Grid renderer plugin API.
|
|
@@ -1081,4 +1104,5 @@ interface ScrollControllerAPI {
|
|
|
1081
1104
|
*/
|
|
1082
1105
|
declare function scrollControllerPlugin(options?: ScrollControllerOptions): Plugin;
|
|
1083
1106
|
|
|
1084
|
-
export {
|
|
1107
|
+
export { VirtualGrid, VirtualList, VirtualMasonry, autoMeasurerPlugin, createKernel, createPlugin, easings, gridRendererPlugin, infiniteLoaderPlugin, listRendererPlugin, scrollControllerPlugin, useMeasure, useMeasureMany, useScrollex, useScrollexRequired, useVirtualGrid, useVirtualList, useVirtualMasonry };
|
|
1108
|
+
export type { AutoMeasurerAPI, AutoMeasurerOptions, EasingFunction, EventHandler, EventType, GridGap, GridRenderItemProps, GridRendererAPI, GridRendererOptions, InfiniteLoaderAPI, InfiniteLoaderOptions, ItemMeasuredEvent, ItemsChangeEvent, ItemsRenderedInfo, Kernel, KernelEvent, KernelOptions, ListRendererAPI, ListRendererOptions, LoadDirection, LoadMoreEvent, MasonryRenderItemProps, Plugin, PluginConfig, PluginHooks, PluginInfo, PluginType, Range, RenderItemProps, ResizeEvent, ScrollAlignment, ScrollBehavior, ScrollControllerAPI, ScrollControllerOptions, ScrollDirection, ScrollEndEvent, ScrollEvent, ScrollOptions, ScrollPosition, ScrollStartEvent, ScrollToIndexOptions, Unsubscribe, UseMeasureOptions, UseMeasureReturn, UseVirtualGridOptions, UseVirtualGridReturn, UseVirtualListOptions, UseVirtualListReturn, UseVirtualMasonryOptions, UseVirtualMasonryReturn, Viewport, VirtualGridProps, VirtualItem, VirtualListHandle, VirtualListProps, VirtualMasonryProps, VisibleRangeChangeEvent };
|