@fluentui/react-virtualizer 9.0.0-alpha.69 → 9.0.0-alpha.70
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 +14 -2
- package/dist/index.d.ts +8 -0
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -1
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js +7 -2
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -1
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -1
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +23 -12
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -1
- package/lib/hooks/hooks.types.js.map +1 -1
- package/lib/hooks/useDynamicPagination.js +127 -0
- package/lib/hooks/useDynamicPagination.js.map +1 -0
- package/lib/hooks/useMeasureList.js +17 -2
- package/lib/hooks/useMeasureList.js.map +1 -1
- package/lib/hooks/useStaticPagination.js +103 -0
- package/lib/hooks/useStaticPagination.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js +7 -2
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +20 -10
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -1
- package/lib-commonjs/hooks/useDynamicPagination.js +131 -0
- package/lib-commonjs/hooks/useDynamicPagination.js.map +1 -0
- package/lib-commonjs/hooks/useMeasureList.js +16 -2
- package/lib-commonjs/hooks/useMeasureList.js.map +1 -1
- package/lib-commonjs/hooks/useStaticPagination.js +107 -0
- package/lib-commonjs/hooks/useStaticPagination.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useStaticVirtualizerPagination", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useStaticVirtualizerPagination;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{
|
|
14
|
+
const { itemSize, axis = 'vertical' } = virtualizerProps;
|
|
15
|
+
const timeoutRef = (0, _react.useRef)(null);
|
|
16
|
+
const lastScrollPos = (0, _react.useRef)(0);
|
|
17
|
+
const lastIndexScrolled = (0, _react.useRef)(0);
|
|
18
|
+
const scrollContainer = _react.useRef(null);
|
|
19
|
+
const clearListeners = ()=>{
|
|
20
|
+
if (scrollContainer.current) {
|
|
21
|
+
scrollContainer.current.removeEventListener('scroll', onScroll);
|
|
22
|
+
scrollContainer.current = null;
|
|
23
|
+
if (timeoutRef.current) {
|
|
24
|
+
clearTimeout(timeoutRef.current);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
_react.useEffect(()=>{
|
|
29
|
+
return ()=>{
|
|
30
|
+
clearListeners();
|
|
31
|
+
};
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, []);
|
|
34
|
+
/**
|
|
35
|
+
* Handle scroll stop event and paginate to the closest item
|
|
36
|
+
* If the closest item is the same as the previous scroll end
|
|
37
|
+
* we paginate to the next/previous one based on direction
|
|
38
|
+
*/ const onScrollEnd = _react.useCallback(()=>{
|
|
39
|
+
if (!scrollContainer.current || !paginationEnabled) {
|
|
40
|
+
// No container found
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const currentScrollPos = Math.round(axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft);
|
|
44
|
+
const closestItem = Math.round(currentScrollPos / itemSize);
|
|
45
|
+
let nextItem = 0;
|
|
46
|
+
if (Math.round(closestItem - lastIndexScrolled.current) === 0) {
|
|
47
|
+
// Special case for go to next/previous with minimum amount of scroll needed
|
|
48
|
+
const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;
|
|
49
|
+
const isSecondaryScroll = lastScrollPos.current === currentScrollPos;
|
|
50
|
+
const posMod = isSecondaryScroll ? 0 : nextTarget;
|
|
51
|
+
nextItem = closestItem + posMod;
|
|
52
|
+
} else {
|
|
53
|
+
// Pagination for anything else can just jump to the closest!
|
|
54
|
+
nextItem = closestItem;
|
|
55
|
+
}
|
|
56
|
+
const nextItemPos = nextItem * itemSize;
|
|
57
|
+
if (axis === 'vertical') {
|
|
58
|
+
scrollContainer.current.scrollTo({
|
|
59
|
+
top: nextItemPos,
|
|
60
|
+
behavior: 'smooth'
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
scrollContainer.current.scrollTo({
|
|
64
|
+
left: nextItemPos,
|
|
65
|
+
behavior: 'smooth'
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
lastScrollPos.current = nextItemPos;
|
|
69
|
+
lastIndexScrolled.current = nextItem;
|
|
70
|
+
}, [
|
|
71
|
+
paginationEnabled,
|
|
72
|
+
axis,
|
|
73
|
+
itemSize
|
|
74
|
+
]);
|
|
75
|
+
/**
|
|
76
|
+
* On scroll timer that will continuously delay callback until scrolling stops
|
|
77
|
+
*/ const onScroll = _react.useCallback((event)=>{
|
|
78
|
+
if (timeoutRef.current) {
|
|
79
|
+
clearTimeout(timeoutRef.current);
|
|
80
|
+
}
|
|
81
|
+
timeoutRef.current = setTimeout(onScrollEnd, 100);
|
|
82
|
+
}, [
|
|
83
|
+
onScrollEnd
|
|
84
|
+
]);
|
|
85
|
+
/**
|
|
86
|
+
* Pagination ref will ensure we attach listeners to containers on change
|
|
87
|
+
* It is returned from hook and merged into the scroll container externally
|
|
88
|
+
*/ const paginationRef = _react.useCallback((instance)=>{
|
|
89
|
+
if (!paginationEnabled) {
|
|
90
|
+
clearListeners();
|
|
91
|
+
scrollContainer.current = null;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (scrollContainer.current !== instance) {
|
|
95
|
+
clearListeners();
|
|
96
|
+
scrollContainer.current = instance;
|
|
97
|
+
if (scrollContainer.current) {
|
|
98
|
+
scrollContainer.current.addEventListener('scroll', onScroll);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, [
|
|
102
|
+
onScroll,
|
|
103
|
+
onScrollEnd,
|
|
104
|
+
paginationEnabled
|
|
105
|
+
]);
|
|
106
|
+
return paginationRef;
|
|
107
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useStaticPagination.js"],"sourcesContent":["import * as React from 'react';\nimport { useRef } from 'react';\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are uniform/static, we round to the nearest item on long scrolls\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerStaticPaginationProps can be grabbed from Virtualizer hooks externally and passed in\n */ export const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{\n const { itemSize, axis = 'vertical' } = virtualizerProps;\n const timeoutRef = useRef(null);\n const lastScrollPos = useRef(0);\n const lastIndexScrolled = useRef(0);\n const scrollContainer = React.useRef(null);\n const clearListeners = ()=>{\n if (scrollContainer.current) {\n scrollContainer.current.removeEventListener('scroll', onScroll);\n scrollContainer.current = null;\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n }\n };\n React.useEffect(()=>{\n return ()=>{\n clearListeners();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n /**\n * Handle scroll stop event and paginate to the closest item\n * If the closest item is the same as the previous scroll end\n * we paginate to the next/previous one based on direction\n */ const onScrollEnd = React.useCallback(()=>{\n if (!scrollContainer.current || !paginationEnabled) {\n // No container found\n return;\n }\n const currentScrollPos = Math.round(axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft);\n const closestItem = Math.round(currentScrollPos / itemSize);\n let nextItem = 0;\n if (Math.round(closestItem - lastIndexScrolled.current) === 0) {\n // Special case for go to next/previous with minimum amount of scroll needed\n const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;\n const isSecondaryScroll = lastScrollPos.current === currentScrollPos;\n const posMod = isSecondaryScroll ? 0 : nextTarget;\n nextItem = closestItem + posMod;\n } else {\n // Pagination for anything else can just jump to the closest!\n nextItem = closestItem;\n }\n const nextItemPos = nextItem * itemSize;\n if (axis === 'vertical') {\n scrollContainer.current.scrollTo({\n top: nextItemPos,\n behavior: 'smooth'\n });\n } else {\n scrollContainer.current.scrollTo({\n left: nextItemPos,\n behavior: 'smooth'\n });\n }\n lastScrollPos.current = nextItemPos;\n lastIndexScrolled.current = nextItem;\n }, [\n paginationEnabled,\n axis,\n itemSize\n ]);\n /**\n * On scroll timer that will continuously delay callback until scrolling stops\n */ const onScroll = React.useCallback((event)=>{\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n timeoutRef.current = setTimeout(onScrollEnd, 100);\n }, [\n onScrollEnd\n ]);\n /**\n * Pagination ref will ensure we attach listeners to containers on change\n * It is returned from hook and merged into the scroll container externally\n */ const paginationRef = React.useCallback((instance)=>{\n if (!paginationEnabled) {\n clearListeners();\n scrollContainer.current = null;\n return;\n }\n if (scrollContainer.current !== instance) {\n clearListeners();\n scrollContainer.current = instance;\n if (scrollContainer.current) {\n scrollContainer.current.addEventListener('scroll', onScroll);\n }\n }\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n onScroll,\n onScrollEnd,\n paginationEnabled\n ]);\n return paginationRef;\n};\n"],"names":["useStaticVirtualizerPagination","virtualizerProps","paginationEnabled","itemSize","axis","timeoutRef","useRef","lastScrollPos","lastIndexScrolled","scrollContainer","React","clearListeners","current","removeEventListener","onScroll","clearTimeout","useEffect","onScrollEnd","useCallback","currentScrollPos","Math","round","scrollTop","scrollLeft","closestItem","nextItem","nextTarget","isSecondaryScroll","posMod","nextItemPos","scrollTo","top","behavior","left","event","setTimeout","paginationRef","instance","addEventListener"],"mappings":";;;;+BAOiBA;;;eAAAA;;;;iEAPM;AAOZ,MAAMA,iCAAiC,CAACC,kBAAkBC,oBAAoB,IAAI;IACzF,MAAM,EAAEC,QAAQ,EAAEC,OAAO,UAAU,EAAE,GAAGH;IACxC,MAAMI,aAAaC,IAAAA,aAAM,EAAC;IAC1B,MAAMC,gBAAgBD,IAAAA,aAAM,EAAC;IAC7B,MAAME,oBAAoBF,IAAAA,aAAM,EAAC;IACjC,MAAMG,kBAAkBC,OAAMJ,MAAM,CAAC;IACrC,MAAMK,iBAAiB;QACnB,IAAIF,gBAAgBG,OAAO,EAAE;YACzBH,gBAAgBG,OAAO,CAACC,mBAAmB,CAAC,UAAUC;YACtDL,gBAAgBG,OAAO,GAAG;YAC1B,IAAIP,WAAWO,OAAO,EAAE;gBACpBG,aAAaV,WAAWO,OAAO;YACnC;QACJ;IACJ;IACAF,OAAMM,SAAS,CAAC;QACZ,OAAO;YACHL;QACJ;IACJ,uDAAuD;IACvD,GAAG,EAAE;IACL;;;;GAID,GAAG,MAAMM,cAAcP,OAAMQ,WAAW,CAAC;QACpC,IAAI,CAACT,gBAAgBG,OAAO,IAAI,CAACV,mBAAmB;YAChD,qBAAqB;YACrB;QACJ;QACA,MAAMiB,mBAAmBC,KAAKC,KAAK,CAACjB,SAAS,aAAaK,gBAAgBG,OAAO,CAACU,SAAS,GAAGb,gBAAgBG,OAAO,CAACW,UAAU;QAChI,MAAMC,cAAcJ,KAAKC,KAAK,CAACF,mBAAmBhB;QAClD,IAAIsB,WAAW;QACf,IAAIL,KAAKC,KAAK,CAACG,cAAchB,kBAAkBI,OAAO,MAAM,GAAG;YAC3D,4EAA4E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
|
|
3
|
+
"version": "9.0.0-alpha.70",
|
|
4
4
|
"description": "Generic and composable virtualizer framework built on browser intersection observer",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"@fluentui/scripts-tasks": "*"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@fluentui/react-jsx-runtime": "^9.0.
|
|
36
|
-
"@fluentui/react-utilities": "^9.18.
|
|
37
|
-
"@fluentui/react-shared-contexts": "^9.14.
|
|
35
|
+
"@fluentui/react-jsx-runtime": "^9.0.31",
|
|
36
|
+
"@fluentui/react-utilities": "^9.18.2",
|
|
37
|
+
"@fluentui/react-shared-contexts": "^9.14.1",
|
|
38
38
|
"@griffel/react": "^1.5.14",
|
|
39
39
|
"@swc/helpers": "^0.5.1"
|
|
40
40
|
},
|