@snack-uikit/utils 3.2.1-preview-cb79db34.0 → 3.3.1-preview-94780dcd.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 CHANGED
@@ -3,6 +3,17 @@
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.3.0 (2024-04-23)
7
+
8
+
9
+ ### Features
10
+
11
+ * **PDS-59:** add useValueControl hook for uncontrollable props ([596017a](https://github.com/cloud-ru-tech/snack-uikit/commit/596017a2fdd990bfb83637f6c4286b35e145e8bc))
12
+
13
+
14
+
15
+
16
+
6
17
  # 3.2.0 (2023-12-14)
7
18
 
8
19
 
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export type ThemeContextType = {
3
2
  theme: string | undefined;
4
3
  themeClassName: string | undefined;
@@ -1,4 +1,5 @@
1
- export * from './useThemeConfig';
2
- export * from './useEventHandler';
3
1
  export * from './useDebounce';
2
+ export * from './useEventHandler';
3
+ export * from './useIsomorphicLayoutEffect';
4
+ export * from './useThemeConfig';
4
5
  export * from './useValueControl';
@@ -1,4 +1,5 @@
1
- export * from './useThemeConfig';
2
- export * from './useEventHandler';
3
1
  export * from './useDebounce';
2
+ export * from './useEventHandler';
3
+ export * from './useIsomorphicLayoutEffect';
4
+ export * from './useThemeConfig';
4
5
  export * from './useValueControl';
@@ -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
- window.requestAnimationFrame(timestamp => {
8
- if (timestamp < timeStampRef.current) {
9
- clearTimeout(timerId);
10
- }
11
- timerId = setTimeout(callback, timeout);
12
- timeStampRef.current = timestamp + timeout;
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, useLayoutEffect, useRef } from 'react';
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(() => {
@@ -0,0 +1,2 @@
1
+ import { useLayoutEffect as useLayoutEffectInternal } from 'react';
2
+ export declare const useLayoutEffect: typeof useLayoutEffectInternal;
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line no-restricted-imports
2
+ import { useEffect, useLayoutEffect as useLayoutEffectInternal } from 'react';
3
+ import { isBrowser } from '../utils';
4
+ export const useLayoutEffect = isBrowser() ? useLayoutEffectInternal : useEffect;
@@ -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[]) => 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 {};
@@ -1 +1,2 @@
1
1
  export * from './componentPropsProcessors';
2
+ export * from './isBrowser';
@@ -1 +1,2 @@
1
1
  export * from './componentPropsProcessors';
2
+ export * from './isBrowser';
@@ -0,0 +1 @@
1
+ export declare function isBrowser(): boolean;
@@ -0,0 +1,4 @@
1
+ export function isBrowser() {
2
+ // eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi
3
+ return Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
4
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Utils",
7
- "version": "3.2.1-preview-cb79db34.0",
7
+ "version": "3.3.1-preview-94780dcd.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": "ec06c40c0ed64aa42d8842734a8c532f5c4603e6"
37
+ "gitHead": "0b67805c876ec8ccc1567d110a3b37b04d2f0fb6"
38
38
  }
@@ -1,4 +1,5 @@
1
- export * from './useThemeConfig';
2
- export * from './useEventHandler';
3
1
  export * from './useDebounce';
2
+ export * from './useEventHandler';
3
+ export * from './useIsomorphicLayoutEffect';
4
+ export * from './useThemeConfig';
4
5
  export * from './useValueControl';
@@ -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
- window.requestAnimationFrame(timestamp => {
11
- if (timestamp < timeStampRef.current) {
12
- clearTimeout(timerId);
13
- }
14
- timerId = setTimeout(callback, timeout);
15
- timeStampRef.current = timestamp + timeout;
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, useLayoutEffect, useRef } from 'react';
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);
@@ -0,0 +1,6 @@
1
+ // eslint-disable-next-line no-restricted-imports
2
+ import { useEffect, useLayoutEffect as useLayoutEffectInternal } from 'react';
3
+
4
+ import { isBrowser } from '../utils';
5
+
6
+ export const useLayoutEffect = isBrowser() ? useLayoutEffectInternal : useEffect;
@@ -1 +1,2 @@
1
1
  export * from './componentPropsProcessors';
2
+ export * from './isBrowser';
@@ -0,0 +1,4 @@
1
+ export function isBrowser() {
2
+ // eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi
3
+ return Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
4
+ }