@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/plugins/index.d.cts
CHANGED
|
@@ -218,10 +218,10 @@ interface Plugin {
|
|
|
218
218
|
version: string;
|
|
219
219
|
/** Plugin type (core or optional) */
|
|
220
220
|
type: PluginType;
|
|
221
|
-
/** Install plugin into kernel */
|
|
222
|
-
install
|
|
223
|
-
/** Uninstall plugin */
|
|
224
|
-
uninstall
|
|
221
|
+
/** Install plugin into kernel (required: the registry rejects a plugin without it) */
|
|
222
|
+
install(kernel: Kernel): void;
|
|
223
|
+
/** Uninstall plugin (required: the registry rejects a plugin without it) */
|
|
224
|
+
uninstall(): void;
|
|
225
225
|
/** Plugin hooks */
|
|
226
226
|
hooks?: PluginHooks;
|
|
227
227
|
/** Public API exposed by the plugin */
|
|
@@ -241,6 +241,8 @@ interface KernelOptions {
|
|
|
241
241
|
direction: 'vertical' | 'horizontal';
|
|
242
242
|
/** Function to get item key */
|
|
243
243
|
getItemKey?: (index: number) => string | number;
|
|
244
|
+
/** Space before the first item (px): item offsets, the total size and scrollToIndex include it (default 0) */
|
|
245
|
+
paddingStart?: number;
|
|
244
246
|
}
|
|
245
247
|
/**
|
|
246
248
|
* Kernel interface - the core of the virtualization engine.
|
|
@@ -257,7 +259,7 @@ interface Kernel {
|
|
|
257
259
|
/** Get current scroll position */
|
|
258
260
|
getScrollPosition(): ScrollPosition;
|
|
259
261
|
/** Set scroll position directly */
|
|
260
|
-
setScrollPosition(position: ScrollPosition): void;
|
|
262
|
+
setScrollPosition(position: Partial<ScrollPosition>): void;
|
|
261
263
|
/** Scroll to offset */
|
|
262
264
|
scrollTo(offset: number, options?: ScrollOptions): void;
|
|
263
265
|
/** Scroll to item index */
|
|
@@ -282,9 +284,15 @@ interface Kernel {
|
|
|
282
284
|
getItemOffset(index: number): number;
|
|
283
285
|
/** Emit an event */
|
|
284
286
|
emit(event: KernelEvent): void;
|
|
285
|
-
/** Subscribe to an event type */
|
|
287
|
+
/** Subscribe to an event type; the handler receives that event's payload */
|
|
288
|
+
on<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
|
|
289
|
+
type: K;
|
|
290
|
+
}>>): Unsubscribe;
|
|
286
291
|
on<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): Unsubscribe;
|
|
287
292
|
/** Unsubscribe from an event type */
|
|
293
|
+
off<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
|
|
294
|
+
type: K;
|
|
295
|
+
}>>): void;
|
|
288
296
|
off<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): void;
|
|
289
297
|
/** Update kernel configuration */
|
|
290
298
|
configure(options: Partial<KernelOptions>): void;
|
|
@@ -358,6 +366,8 @@ interface GridRendererOptions {
|
|
|
358
366
|
gap?: number | GridGap;
|
|
359
367
|
/** Get item key for React reconciliation */
|
|
360
368
|
getItemKey?: (index: number) => string | number;
|
|
369
|
+
/** Width the columns share, when it is not the viewport width (the content box of a padded container) */
|
|
370
|
+
getContainerWidth?: () => number | undefined;
|
|
361
371
|
}
|
|
362
372
|
/**
|
|
363
373
|
* Grid renderer plugin API.
|
|
@@ -561,22 +571,21 @@ interface MasonryRendererAPI {
|
|
|
561
571
|
*
|
|
562
572
|
* @example
|
|
563
573
|
* ```tsx
|
|
574
|
+
* import { createKernel } from '@oxog/scrollex'
|
|
564
575
|
* import { masonryRenderer } from '@oxog/scrollex/plugins'
|
|
565
576
|
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* )}
|
|
579
|
-
* />
|
|
577
|
+
* // The plugin lays items out on a kernel; the VirtualMasonry component does this itself from its props
|
|
578
|
+
* const kernel = createKernel({ itemCount: images.length, estimatedItemHeight: 200 })
|
|
579
|
+
* const masonry = masonryRenderer({
|
|
580
|
+
* columns: 3,
|
|
581
|
+
* gap: 8,
|
|
582
|
+
* getItemHeight: (index, columnWidth) => {
|
|
583
|
+
* const item = images[index]
|
|
584
|
+
* return (item.height / item.width) * columnWidth
|
|
585
|
+
* },
|
|
586
|
+
* })
|
|
587
|
+
* kernel.register(masonry)
|
|
588
|
+
* const items = masonry.api.getVirtualItems()
|
|
580
589
|
* ```
|
|
581
590
|
*/
|
|
582
591
|
declare function masonryRenderer(options: MasonryRendererOptions): Plugin;
|
|
@@ -634,6 +643,7 @@ interface StickyHeadersAPI {
|
|
|
634
643
|
*
|
|
635
644
|
* <VirtualList
|
|
636
645
|
* data={groupedItems}
|
|
646
|
+
* itemHeight={40}
|
|
637
647
|
* plugins={[stickyHeaders({
|
|
638
648
|
* headerHeight: 40,
|
|
639
649
|
* isHeader: (index) => groupedItems[index].type === 'header',
|
|
@@ -720,6 +730,7 @@ interface KeyboardNavAPI {
|
|
|
720
730
|
*
|
|
721
731
|
* <VirtualList
|
|
722
732
|
* data={items}
|
|
733
|
+
* itemHeight={40}
|
|
723
734
|
* plugins={[keyboardNav({
|
|
724
735
|
* loop: true,
|
|
725
736
|
* orientation: 'vertical',
|
|
@@ -797,6 +808,7 @@ interface ScrollRestorationAPI {
|
|
|
797
808
|
*
|
|
798
809
|
* <VirtualList
|
|
799
810
|
* data={items}
|
|
811
|
+
* itemHeight={40}
|
|
800
812
|
* plugins={[scrollRestoration({
|
|
801
813
|
* key: 'my-list',
|
|
802
814
|
* storage: 'sessionStorage',
|
|
@@ -819,7 +831,7 @@ interface BidirectionalOptions {
|
|
|
819
831
|
stickToBottom?: boolean;
|
|
820
832
|
/** Threshold in pixels from bottom to activate stick behavior */
|
|
821
833
|
stickThreshold?: number;
|
|
822
|
-
/**
|
|
834
|
+
/** Declared, not implemented yet: call `adjustForPrepend` after prepending */
|
|
823
835
|
maintainPositionOnPrepend?: boolean;
|
|
824
836
|
/** Callback when load more is triggered */
|
|
825
837
|
onLoadMore?: (direction: 'forward' | 'backward') => void;
|
|
@@ -862,14 +874,13 @@ interface BidirectionalAPI {
|
|
|
862
874
|
* plugins={[bidirectional({
|
|
863
875
|
* stickToBottom: true,
|
|
864
876
|
* initialPosition: 'bottom',
|
|
865
|
-
*
|
|
877
|
+
* onLoadMore: (direction) => {
|
|
878
|
+
* if (direction === 'backward') loadOlderMessages()
|
|
879
|
+
* if (direction === 'forward') loadNewerMessages()
|
|
880
|
+
* },
|
|
866
881
|
* })]}
|
|
867
|
-
*
|
|
868
|
-
*
|
|
869
|
-
* if (direction === 'forward') loadNewerMessages()
|
|
870
|
-
* }}
|
|
871
|
-
* renderItem={({ item, measureRef }) => (
|
|
872
|
-
* <div ref={measureRef}>
|
|
882
|
+
* renderItem={({ item, style, measureRef }) => (
|
|
883
|
+
* <div ref={measureRef} style={style}>
|
|
873
884
|
* <Message message={item} />
|
|
874
885
|
* </div>
|
|
875
886
|
* )}
|
|
@@ -934,17 +945,28 @@ interface DragToReorderAPI {
|
|
|
934
945
|
/** Create drag handle props */
|
|
935
946
|
getDragHandleProps(index: number): DragHandleProps;
|
|
936
947
|
}
|
|
948
|
+
/**
|
|
949
|
+
* The parts of a drag event the plugin reads. The native DragEvent and React's DragEvent both satisfy it, so
|
|
950
|
+
* the handler props can be spread on a React element.
|
|
951
|
+
*/
|
|
952
|
+
interface DragEventLike {
|
|
953
|
+
clientX: number;
|
|
954
|
+
clientY: number;
|
|
955
|
+
dataTransfer: DataTransfer | null;
|
|
956
|
+
currentTarget: EventTarget | null;
|
|
957
|
+
preventDefault(): void;
|
|
958
|
+
}
|
|
937
959
|
/**
|
|
938
960
|
* Props for drag handle element.
|
|
939
961
|
*/
|
|
940
962
|
interface DragHandleProps {
|
|
941
963
|
draggable: boolean;
|
|
942
|
-
onDragStart: (event:
|
|
943
|
-
onDragEnd: (event:
|
|
944
|
-
onDragOver: (event:
|
|
945
|
-
onDragEnter: (event:
|
|
946
|
-
onDragLeave: (event:
|
|
947
|
-
onDrop: (event:
|
|
964
|
+
onDragStart: (event: DragEventLike) => void;
|
|
965
|
+
onDragEnd: (event: DragEventLike) => void;
|
|
966
|
+
onDragOver: (event: DragEventLike) => void;
|
|
967
|
+
onDragEnter: (event: DragEventLike) => void;
|
|
968
|
+
onDragLeave: (event: DragEventLike) => void;
|
|
969
|
+
onDrop: (event: DragEventLike) => void;
|
|
948
970
|
'data-drag-index': string;
|
|
949
971
|
'aria-grabbed': boolean;
|
|
950
972
|
}
|
|
@@ -961,20 +983,22 @@ interface DragHandleProps {
|
|
|
961
983
|
*
|
|
962
984
|
* const [items, setItems] = useState(initialItems)
|
|
963
985
|
*
|
|
986
|
+
* // Create the plugin once: it keeps the drag in progress, and its api hands out the props for the rows
|
|
987
|
+
* const dnd = useMemo(() => dragToReorder({
|
|
988
|
+
* onReorder: (fromIndex, toIndex) => setItems((current) => {
|
|
989
|
+
* const newItems = [...current]
|
|
990
|
+
* const [removed] = newItems.splice(fromIndex, 1)
|
|
991
|
+
* newItems.splice(toIndex, 0, removed)
|
|
992
|
+
* return newItems
|
|
993
|
+
* }),
|
|
994
|
+
* }), [])
|
|
995
|
+
*
|
|
964
996
|
* <VirtualList
|
|
965
997
|
* data={items}
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
* newItems.splice(toIndex, 0, removed)
|
|
971
|
-
* setItems(newItems)
|
|
972
|
-
* },
|
|
973
|
-
* })]}
|
|
974
|
-
* renderItem={({ item, index, dragHandleProps }) => (
|
|
975
|
-
* <Row item={item}>
|
|
976
|
-
* <DragHandle {...dragHandleProps} />
|
|
977
|
-
* </Row>
|
|
998
|
+
* itemHeight={48}
|
|
999
|
+
* plugins={[dnd]}
|
|
1000
|
+
* renderItem={({ item, index, style }) => (
|
|
1001
|
+
* <Row item={item} style={style} {...dnd.api.getDragHandleProps(index)} />
|
|
978
1002
|
* )}
|
|
979
1003
|
* />
|
|
980
1004
|
* ```
|
|
@@ -1051,9 +1075,9 @@ interface DebugPanelOptions {
|
|
|
1051
1075
|
theme?: DebugPanelTheme;
|
|
1052
1076
|
/** Show FPS counter */
|
|
1053
1077
|
showFps?: boolean;
|
|
1054
|
-
/** Show viewport overlay */
|
|
1078
|
+
/** Show viewport overlay. Declared, not implemented yet: the switch only changes a flag */
|
|
1055
1079
|
showViewportOverlay?: boolean;
|
|
1056
|
-
/** Show item boundaries */
|
|
1080
|
+
/** Show item boundaries. Declared, not implemented yet: the switch only changes a flag */
|
|
1057
1081
|
showItemBoundaries?: boolean;
|
|
1058
1082
|
/** Log events to console */
|
|
1059
1083
|
logEvents?: boolean;
|
|
@@ -1134,4 +1158,5 @@ interface DebugPanelOverlayProps {
|
|
|
1134
1158
|
*/
|
|
1135
1159
|
declare function DebugPanelOverlay({ plugin, className, style, }: DebugPanelOverlayProps): React.ReactElement | null;
|
|
1136
1160
|
|
|
1137
|
-
export {
|
|
1161
|
+
export { DebugPanelOverlay, autoMeasurerPlugin, bidirectional, debugPanel, dragToReorder, gridRendererPlugin, infiniteLoaderPlugin, keyboardNav, listRendererPlugin, masonryRenderer, scrollControllerPlugin, scrollRestoration, stickyHeaders };
|
|
1162
|
+
export type { AutoMeasurerAPI, AutoMeasurerOptions, BidirectionalAPI, BidirectionalOptions, DebugPanelAPI, DebugPanelOptions, DebugPanelOverlayProps, DebugPanelPosition, DebugPanelState, DebugPanelTab, DebugPanelTheme, DragAxis, DragEventLike, DragHandleProps, DragToReorderAPI, DragToReorderOptions, DropIndicatorStyle, EventLogEntry, GridRendererAPI, GridRendererOptions, InfiniteLoaderAPI, InfiniteLoaderOptions, KeyboardNavAPI, KeyboardNavOptions, KeyboardNavOrientation, ListRendererAPI, ListRendererOptions, LoadDirection, MasonryRendererAPI, MasonryRendererOptions, PerformanceStats, SavedScrollState, ScrollControllerAPI, ScrollControllerOptions, ScrollRestorationAPI, ScrollRestorationOptions, ScrollRestorationStorage, StickyHeadersAPI, StickyHeadersOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -218,10 +218,10 @@ interface Plugin {
|
|
|
218
218
|
version: string;
|
|
219
219
|
/** Plugin type (core or optional) */
|
|
220
220
|
type: PluginType;
|
|
221
|
-
/** Install plugin into kernel */
|
|
222
|
-
install
|
|
223
|
-
/** Uninstall plugin */
|
|
224
|
-
uninstall
|
|
221
|
+
/** Install plugin into kernel (required: the registry rejects a plugin without it) */
|
|
222
|
+
install(kernel: Kernel): void;
|
|
223
|
+
/** Uninstall plugin (required: the registry rejects a plugin without it) */
|
|
224
|
+
uninstall(): void;
|
|
225
225
|
/** Plugin hooks */
|
|
226
226
|
hooks?: PluginHooks;
|
|
227
227
|
/** Public API exposed by the plugin */
|
|
@@ -241,6 +241,8 @@ interface KernelOptions {
|
|
|
241
241
|
direction: 'vertical' | 'horizontal';
|
|
242
242
|
/** Function to get item key */
|
|
243
243
|
getItemKey?: (index: number) => string | number;
|
|
244
|
+
/** Space before the first item (px): item offsets, the total size and scrollToIndex include it (default 0) */
|
|
245
|
+
paddingStart?: number;
|
|
244
246
|
}
|
|
245
247
|
/**
|
|
246
248
|
* Kernel interface - the core of the virtualization engine.
|
|
@@ -257,7 +259,7 @@ interface Kernel {
|
|
|
257
259
|
/** Get current scroll position */
|
|
258
260
|
getScrollPosition(): ScrollPosition;
|
|
259
261
|
/** Set scroll position directly */
|
|
260
|
-
setScrollPosition(position: ScrollPosition): void;
|
|
262
|
+
setScrollPosition(position: Partial<ScrollPosition>): void;
|
|
261
263
|
/** Scroll to offset */
|
|
262
264
|
scrollTo(offset: number, options?: ScrollOptions): void;
|
|
263
265
|
/** Scroll to item index */
|
|
@@ -282,9 +284,15 @@ interface Kernel {
|
|
|
282
284
|
getItemOffset(index: number): number;
|
|
283
285
|
/** Emit an event */
|
|
284
286
|
emit(event: KernelEvent): void;
|
|
285
|
-
/** Subscribe to an event type */
|
|
287
|
+
/** Subscribe to an event type; the handler receives that event's payload */
|
|
288
|
+
on<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
|
|
289
|
+
type: K;
|
|
290
|
+
}>>): Unsubscribe;
|
|
286
291
|
on<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): Unsubscribe;
|
|
287
292
|
/** Unsubscribe from an event type */
|
|
293
|
+
off<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
|
|
294
|
+
type: K;
|
|
295
|
+
}>>): void;
|
|
288
296
|
off<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): void;
|
|
289
297
|
/** Update kernel configuration */
|
|
290
298
|
configure(options: Partial<KernelOptions>): void;
|
|
@@ -358,6 +366,8 @@ interface GridRendererOptions {
|
|
|
358
366
|
gap?: number | GridGap;
|
|
359
367
|
/** Get item key for React reconciliation */
|
|
360
368
|
getItemKey?: (index: number) => string | number;
|
|
369
|
+
/** Width the columns share, when it is not the viewport width (the content box of a padded container) */
|
|
370
|
+
getContainerWidth?: () => number | undefined;
|
|
361
371
|
}
|
|
362
372
|
/**
|
|
363
373
|
* Grid renderer plugin API.
|
|
@@ -561,22 +571,21 @@ interface MasonryRendererAPI {
|
|
|
561
571
|
*
|
|
562
572
|
* @example
|
|
563
573
|
* ```tsx
|
|
574
|
+
* import { createKernel } from '@oxog/scrollex'
|
|
564
575
|
* import { masonryRenderer } from '@oxog/scrollex/plugins'
|
|
565
576
|
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* )}
|
|
579
|
-
* />
|
|
577
|
+
* // The plugin lays items out on a kernel; the VirtualMasonry component does this itself from its props
|
|
578
|
+
* const kernel = createKernel({ itemCount: images.length, estimatedItemHeight: 200 })
|
|
579
|
+
* const masonry = masonryRenderer({
|
|
580
|
+
* columns: 3,
|
|
581
|
+
* gap: 8,
|
|
582
|
+
* getItemHeight: (index, columnWidth) => {
|
|
583
|
+
* const item = images[index]
|
|
584
|
+
* return (item.height / item.width) * columnWidth
|
|
585
|
+
* },
|
|
586
|
+
* })
|
|
587
|
+
* kernel.register(masonry)
|
|
588
|
+
* const items = masonry.api.getVirtualItems()
|
|
580
589
|
* ```
|
|
581
590
|
*/
|
|
582
591
|
declare function masonryRenderer(options: MasonryRendererOptions): Plugin;
|
|
@@ -634,6 +643,7 @@ interface StickyHeadersAPI {
|
|
|
634
643
|
*
|
|
635
644
|
* <VirtualList
|
|
636
645
|
* data={groupedItems}
|
|
646
|
+
* itemHeight={40}
|
|
637
647
|
* plugins={[stickyHeaders({
|
|
638
648
|
* headerHeight: 40,
|
|
639
649
|
* isHeader: (index) => groupedItems[index].type === 'header',
|
|
@@ -720,6 +730,7 @@ interface KeyboardNavAPI {
|
|
|
720
730
|
*
|
|
721
731
|
* <VirtualList
|
|
722
732
|
* data={items}
|
|
733
|
+
* itemHeight={40}
|
|
723
734
|
* plugins={[keyboardNav({
|
|
724
735
|
* loop: true,
|
|
725
736
|
* orientation: 'vertical',
|
|
@@ -797,6 +808,7 @@ interface ScrollRestorationAPI {
|
|
|
797
808
|
*
|
|
798
809
|
* <VirtualList
|
|
799
810
|
* data={items}
|
|
811
|
+
* itemHeight={40}
|
|
800
812
|
* plugins={[scrollRestoration({
|
|
801
813
|
* key: 'my-list',
|
|
802
814
|
* storage: 'sessionStorage',
|
|
@@ -819,7 +831,7 @@ interface BidirectionalOptions {
|
|
|
819
831
|
stickToBottom?: boolean;
|
|
820
832
|
/** Threshold in pixels from bottom to activate stick behavior */
|
|
821
833
|
stickThreshold?: number;
|
|
822
|
-
/**
|
|
834
|
+
/** Declared, not implemented yet: call `adjustForPrepend` after prepending */
|
|
823
835
|
maintainPositionOnPrepend?: boolean;
|
|
824
836
|
/** Callback when load more is triggered */
|
|
825
837
|
onLoadMore?: (direction: 'forward' | 'backward') => void;
|
|
@@ -862,14 +874,13 @@ interface BidirectionalAPI {
|
|
|
862
874
|
* plugins={[bidirectional({
|
|
863
875
|
* stickToBottom: true,
|
|
864
876
|
* initialPosition: 'bottom',
|
|
865
|
-
*
|
|
877
|
+
* onLoadMore: (direction) => {
|
|
878
|
+
* if (direction === 'backward') loadOlderMessages()
|
|
879
|
+
* if (direction === 'forward') loadNewerMessages()
|
|
880
|
+
* },
|
|
866
881
|
* })]}
|
|
867
|
-
*
|
|
868
|
-
*
|
|
869
|
-
* if (direction === 'forward') loadNewerMessages()
|
|
870
|
-
* }}
|
|
871
|
-
* renderItem={({ item, measureRef }) => (
|
|
872
|
-
* <div ref={measureRef}>
|
|
882
|
+
* renderItem={({ item, style, measureRef }) => (
|
|
883
|
+
* <div ref={measureRef} style={style}>
|
|
873
884
|
* <Message message={item} />
|
|
874
885
|
* </div>
|
|
875
886
|
* )}
|
|
@@ -934,17 +945,28 @@ interface DragToReorderAPI {
|
|
|
934
945
|
/** Create drag handle props */
|
|
935
946
|
getDragHandleProps(index: number): DragHandleProps;
|
|
936
947
|
}
|
|
948
|
+
/**
|
|
949
|
+
* The parts of a drag event the plugin reads. The native DragEvent and React's DragEvent both satisfy it, so
|
|
950
|
+
* the handler props can be spread on a React element.
|
|
951
|
+
*/
|
|
952
|
+
interface DragEventLike {
|
|
953
|
+
clientX: number;
|
|
954
|
+
clientY: number;
|
|
955
|
+
dataTransfer: DataTransfer | null;
|
|
956
|
+
currentTarget: EventTarget | null;
|
|
957
|
+
preventDefault(): void;
|
|
958
|
+
}
|
|
937
959
|
/**
|
|
938
960
|
* Props for drag handle element.
|
|
939
961
|
*/
|
|
940
962
|
interface DragHandleProps {
|
|
941
963
|
draggable: boolean;
|
|
942
|
-
onDragStart: (event:
|
|
943
|
-
onDragEnd: (event:
|
|
944
|
-
onDragOver: (event:
|
|
945
|
-
onDragEnter: (event:
|
|
946
|
-
onDragLeave: (event:
|
|
947
|
-
onDrop: (event:
|
|
964
|
+
onDragStart: (event: DragEventLike) => void;
|
|
965
|
+
onDragEnd: (event: DragEventLike) => void;
|
|
966
|
+
onDragOver: (event: DragEventLike) => void;
|
|
967
|
+
onDragEnter: (event: DragEventLike) => void;
|
|
968
|
+
onDragLeave: (event: DragEventLike) => void;
|
|
969
|
+
onDrop: (event: DragEventLike) => void;
|
|
948
970
|
'data-drag-index': string;
|
|
949
971
|
'aria-grabbed': boolean;
|
|
950
972
|
}
|
|
@@ -961,20 +983,22 @@ interface DragHandleProps {
|
|
|
961
983
|
*
|
|
962
984
|
* const [items, setItems] = useState(initialItems)
|
|
963
985
|
*
|
|
986
|
+
* // Create the plugin once: it keeps the drag in progress, and its api hands out the props for the rows
|
|
987
|
+
* const dnd = useMemo(() => dragToReorder({
|
|
988
|
+
* onReorder: (fromIndex, toIndex) => setItems((current) => {
|
|
989
|
+
* const newItems = [...current]
|
|
990
|
+
* const [removed] = newItems.splice(fromIndex, 1)
|
|
991
|
+
* newItems.splice(toIndex, 0, removed)
|
|
992
|
+
* return newItems
|
|
993
|
+
* }),
|
|
994
|
+
* }), [])
|
|
995
|
+
*
|
|
964
996
|
* <VirtualList
|
|
965
997
|
* data={items}
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
* newItems.splice(toIndex, 0, removed)
|
|
971
|
-
* setItems(newItems)
|
|
972
|
-
* },
|
|
973
|
-
* })]}
|
|
974
|
-
* renderItem={({ item, index, dragHandleProps }) => (
|
|
975
|
-
* <Row item={item}>
|
|
976
|
-
* <DragHandle {...dragHandleProps} />
|
|
977
|
-
* </Row>
|
|
998
|
+
* itemHeight={48}
|
|
999
|
+
* plugins={[dnd]}
|
|
1000
|
+
* renderItem={({ item, index, style }) => (
|
|
1001
|
+
* <Row item={item} style={style} {...dnd.api.getDragHandleProps(index)} />
|
|
978
1002
|
* )}
|
|
979
1003
|
* />
|
|
980
1004
|
* ```
|
|
@@ -1051,9 +1075,9 @@ interface DebugPanelOptions {
|
|
|
1051
1075
|
theme?: DebugPanelTheme;
|
|
1052
1076
|
/** Show FPS counter */
|
|
1053
1077
|
showFps?: boolean;
|
|
1054
|
-
/** Show viewport overlay */
|
|
1078
|
+
/** Show viewport overlay. Declared, not implemented yet: the switch only changes a flag */
|
|
1055
1079
|
showViewportOverlay?: boolean;
|
|
1056
|
-
/** Show item boundaries */
|
|
1080
|
+
/** Show item boundaries. Declared, not implemented yet: the switch only changes a flag */
|
|
1057
1081
|
showItemBoundaries?: boolean;
|
|
1058
1082
|
/** Log events to console */
|
|
1059
1083
|
logEvents?: boolean;
|
|
@@ -1134,4 +1158,5 @@ interface DebugPanelOverlayProps {
|
|
|
1134
1158
|
*/
|
|
1135
1159
|
declare function DebugPanelOverlay({ plugin, className, style, }: DebugPanelOverlayProps): React.ReactElement | null;
|
|
1136
1160
|
|
|
1137
|
-
export {
|
|
1161
|
+
export { DebugPanelOverlay, autoMeasurerPlugin, bidirectional, debugPanel, dragToReorder, gridRendererPlugin, infiniteLoaderPlugin, keyboardNav, listRendererPlugin, masonryRenderer, scrollControllerPlugin, scrollRestoration, stickyHeaders };
|
|
1162
|
+
export type { AutoMeasurerAPI, AutoMeasurerOptions, BidirectionalAPI, BidirectionalOptions, DebugPanelAPI, DebugPanelOptions, DebugPanelOverlayProps, DebugPanelPosition, DebugPanelState, DebugPanelTab, DebugPanelTheme, DragAxis, DragEventLike, DragHandleProps, DragToReorderAPI, DragToReorderOptions, DropIndicatorStyle, EventLogEntry, GridRendererAPI, GridRendererOptions, InfiniteLoaderAPI, InfiniteLoaderOptions, KeyboardNavAPI, KeyboardNavOptions, KeyboardNavOrientation, ListRendererAPI, ListRendererOptions, LoadDirection, MasonryRendererAPI, MasonryRendererOptions, PerformanceStats, SavedScrollState, ScrollControllerAPI, ScrollControllerOptions, ScrollRestorationAPI, ScrollRestorationOptions, ScrollRestorationStorage, StickyHeadersAPI, StickyHeadersOptions };
|