@snack-uikit/utils 3.3.0 → 3.4.0
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 +17 -0
- package/dist/components/ThemeProvider/contexts.d.ts +0 -1
- package/dist/hooks/index.d.ts +3 -2
- package/dist/hooks/index.js +3 -2
- package/dist/hooks/useDebounce.js +9 -7
- package/dist/hooks/useEventHandler.js +2 -1
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +2 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js +4 -0
- package/dist/hooks/useValueControl.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/isBrowser.d.ts +1 -0
- package/dist/utils/isBrowser.js +4 -0
- package/package.json +2 -2
- package/src/hooks/index.ts +3 -2
- package/src/hooks/useDebounce.ts +9 -7
- package/src/hooks/useEventHandler.ts +3 -1
- package/src/hooks/useIsomorphicLayoutEffect.ts +6 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/isBrowser.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 3.4.0 (2024-09-23)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **PDS-480:** remove direct usage of browser api elements ([1231ff7](https://github.com/cloud-ru-tech/snack-uikit/commit/1231ff7ab7a1b210b579a7b694633ef23bffcf44))
|
|
12
|
+
* **PDS-480:** replace useLayoutEffect -> useIsomorphicLayoutEffect for ssr ([21aa9ad](https://github.com/cloud-ru-tech/snack-uikit/commit/21aa9ad9f113e465766339d396924357ccb1d432))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **PDS-480:** add isomorphic layoutEffect and isBrowser predicate ([057ce9d](https://github.com/cloud-ru-tech/snack-uikit/commit/057ce9d98564dc33085f031bace53f97c76d22c0))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
6
23
|
# 3.3.0 (2024-04-23)
|
|
7
24
|
|
|
8
25
|
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
|
+
import { isBrowser } from '../utils';
|
|
2
3
|
import { useEventHandler } from './useEventHandler';
|
|
3
4
|
export function useDebounce(callback, timeout = 0) {
|
|
4
5
|
const timeStampRef = useRef(0);
|
|
5
6
|
let timerId = -1;
|
|
6
7
|
return useEventHandler(() => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
isBrowser() &&
|
|
9
|
+
requestAnimationFrame(timestamp => {
|
|
10
|
+
if (timestamp < timeStampRef.current) {
|
|
11
|
+
clearTimeout(timerId);
|
|
12
|
+
}
|
|
13
|
+
timerId = setTimeout(callback, timeout);
|
|
14
|
+
timeStampRef.current = timestamp + timeout;
|
|
15
|
+
});
|
|
14
16
|
});
|
|
15
17
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
|
+
import { useLayoutEffect } from './useIsomorphicLayoutEffect';
|
|
2
3
|
export function useEventHandler(handler) {
|
|
3
4
|
const handlerRef = useRef(null);
|
|
4
5
|
useLayoutEffect(() => {
|
|
@@ -3,5 +3,5 @@ type UseValueControl<TValue> = {
|
|
|
3
3
|
onChange?(value: TValue): void;
|
|
4
4
|
defaultValue?: TValue;
|
|
5
5
|
};
|
|
6
|
-
export declare function useValueControl<TValue>({ value, onChange, defaultValue }: UseValueControl<TValue>): readonly [TValue | undefined, (value: any, ...args: any[]) =>
|
|
6
|
+
export declare function useValueControl<TValue>({ value, onChange, defaultValue }: UseValueControl<TValue>): readonly [TValue | undefined, (value: any, ...args: any[]) => ReturnType<import("uncontrollable").Handler> | void];
|
|
7
7
|
export {};
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBrowser(): boolean;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Utils",
|
|
7
|
-
"version": "3.
|
|
7
|
+
"version": "3.4.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"uncontrollable": "8.0.4"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f9212fe04b0dbba9bedea1bb3a034ab612287841"
|
|
38
38
|
}
|
package/src/hooks/index.ts
CHANGED
package/src/hooks/useDebounce.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
2
|
|
|
3
|
+
import { isBrowser } from '../utils';
|
|
3
4
|
import { useEventHandler } from './useEventHandler';
|
|
4
5
|
|
|
5
6
|
export function useDebounce(callback: () => void, timeout = 0) {
|
|
@@ -7,12 +8,13 @@ export function useDebounce(callback: () => void, timeout = 0) {
|
|
|
7
8
|
let timerId: NodeJS.Timeout | number = -1;
|
|
8
9
|
|
|
9
10
|
return useEventHandler(() => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
isBrowser() &&
|
|
12
|
+
requestAnimationFrame(timestamp => {
|
|
13
|
+
if (timestamp < timeStampRef.current) {
|
|
14
|
+
clearTimeout(timerId);
|
|
15
|
+
}
|
|
16
|
+
timerId = setTimeout(callback, timeout);
|
|
17
|
+
timeStampRef.current = timestamp + timeout;
|
|
18
|
+
});
|
|
17
19
|
});
|
|
18
20
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect } from './useIsomorphicLayoutEffect';
|
|
2
4
|
|
|
3
5
|
export function useEventHandler<T extends (...args: never[]) => unknown>(handler: T) {
|
|
4
6
|
const handlerRef = useRef<T | null>(null);
|
package/src/utils/index.ts
CHANGED