@os-design/use-auto-scroll 1.0.30 → 1.0.32
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/package.json +5 -5
- package/src/index.mdx +1 -1
- package/src/index.ts +12 -3
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAyCD;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,OAAO,EAWnE,CAAC;AAeF,QAAA,MAAM,aAAa,GAAI,QAAO,kBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAyCD;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,OAAO,EAWnE,CAAC;AAeF,QAAA,MAAM,aAAa,GAAI,QAAO,kBAAuB,SAgIpD,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -72,8 +72,8 @@ const useAutoScroll = (props = {}) => {
|
|
|
72
72
|
const cursorPositionRef = useRef(cursorPosition);
|
|
73
73
|
const propsRef = useRef(getProps(props));
|
|
74
74
|
const isScrollingRef = useRef(false);
|
|
75
|
-
const frameRef = useRef();
|
|
76
|
-
const timeoutRef = useRef();
|
|
75
|
+
const frameRef = useRef(undefined);
|
|
76
|
+
const timeoutRef = useRef(undefined);
|
|
77
77
|
|
|
78
78
|
// Update the ref to the cursor position if it changes
|
|
79
79
|
useEffect(() => {
|
|
@@ -121,6 +121,7 @@ const useAutoScroll = (props = {}) => {
|
|
|
121
121
|
el.scrollTo(options);
|
|
122
122
|
});
|
|
123
123
|
}, []);
|
|
124
|
+
const scrollRef = useRef(null);
|
|
124
125
|
const scroll = useCallback(() => {
|
|
125
126
|
const {
|
|
126
127
|
enabled
|
|
@@ -172,12 +173,15 @@ const useAutoScroll = (props = {}) => {
|
|
|
172
173
|
left,
|
|
173
174
|
top
|
|
174
175
|
});
|
|
175
|
-
timeoutRef.current = setTimeout(
|
|
176
|
+
timeoutRef.current = setTimeout(() => scrollRef.current?.(), FRAME_TIMEOUT);
|
|
176
177
|
return;
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
isScrollingRef.current = false;
|
|
180
181
|
}, [getMaxDist, getScrollStep, scrollTo]);
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
scrollRef.current = scroll;
|
|
184
|
+
}, [scroll]);
|
|
181
185
|
|
|
182
186
|
// Start auto scrolling when the cursor position changes only if it is not already running
|
|
183
187
|
useEffect(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@os-design/use-auto-scroll",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": "git@gitlab.com:os-team/libs/os-design.git",
|
|
6
6
|
"type": "module",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx --out-dir dist",
|
|
24
24
|
"build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly --declaration --declarationDir dist",
|
|
25
25
|
"build": "yarn clean && npm-run-all 'build:*'",
|
|
26
|
-
"ncu": "ncu -u
|
|
26
|
+
"ncu": "ncu -u"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@os-design/use-cursor-position": "^1.0.
|
|
32
|
+
"@os-design/use-cursor-position": "^1.0.30"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"react": "
|
|
35
|
+
"react": "19"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f333f60e39273574d2227cf0ee70b0c8897b2dde"
|
|
38
38
|
}
|
package/src/index.mdx
CHANGED
package/src/index.ts
CHANGED
|
@@ -95,8 +95,8 @@ const useAutoScroll = (props: UseAutoScrollProps = {}) => {
|
|
|
95
95
|
const cursorPositionRef = useRef(cursorPosition);
|
|
96
96
|
const propsRef = useRef<Required<UseAutoScrollProps>>(getProps(props));
|
|
97
97
|
const isScrollingRef = useRef(false);
|
|
98
|
-
const frameRef = useRef<number>();
|
|
99
|
-
const timeoutRef = useRef<NodeJS.Timeout>();
|
|
98
|
+
const frameRef = useRef<number>(undefined);
|
|
99
|
+
const timeoutRef = useRef<NodeJS.Timeout>(undefined);
|
|
100
100
|
|
|
101
101
|
// Update the ref to the cursor position if it changes
|
|
102
102
|
useEffect(() => {
|
|
@@ -141,6 +141,8 @@ const useAutoScroll = (props: UseAutoScrollProps = {}) => {
|
|
|
141
141
|
});
|
|
142
142
|
}, []);
|
|
143
143
|
|
|
144
|
+
const scrollRef = useRef<(() => void) | null>(null);
|
|
145
|
+
|
|
144
146
|
const scroll = useCallback(() => {
|
|
145
147
|
const { enabled } = propsRef.current;
|
|
146
148
|
const { x, y } = cursorPositionRef.current;
|
|
@@ -197,7 +199,10 @@ const useAutoScroll = (props: UseAutoScrollProps = {}) => {
|
|
|
197
199
|
|
|
198
200
|
if (left !== scrollLeft || top !== scrollTop) {
|
|
199
201
|
scrollTo(el, { left, top });
|
|
200
|
-
timeoutRef.current = setTimeout(
|
|
202
|
+
timeoutRef.current = setTimeout(
|
|
203
|
+
() => scrollRef.current?.(),
|
|
204
|
+
FRAME_TIMEOUT
|
|
205
|
+
);
|
|
201
206
|
return;
|
|
202
207
|
}
|
|
203
208
|
}
|
|
@@ -205,6 +210,10 @@ const useAutoScroll = (props: UseAutoScrollProps = {}) => {
|
|
|
205
210
|
isScrollingRef.current = false;
|
|
206
211
|
}, [getMaxDist, getScrollStep, scrollTo]);
|
|
207
212
|
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
scrollRef.current = scroll;
|
|
215
|
+
}, [scroll]);
|
|
216
|
+
|
|
208
217
|
// Start auto scrolling when the cursor position changes only if it is not already running
|
|
209
218
|
useEffect(() => {
|
|
210
219
|
if (!isScrollingRef.current && props.enabled) scroll();
|