@snack-uikit/utils 3.5.1-preview-53bd8747.0 → 3.5.1-preview-baf754b1.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.
Files changed (63) hide show
  1. package/README.md +85 -0
  2. package/dist/cjs/components/ThemeProvider/ThemeProvider.d.ts +15 -0
  3. package/dist/cjs/components/ThemeProvider/ThemeProvider.js +3 -0
  4. package/dist/cjs/hooks/index.d.ts +1 -1
  5. package/dist/cjs/hooks/index.js +1 -1
  6. package/dist/cjs/hooks/useDebounce.d.ts +5 -0
  7. package/dist/cjs/hooks/useDebounce.js +5 -0
  8. package/dist/cjs/hooks/useEventHandler.d.ts +5 -0
  9. package/dist/cjs/hooks/useEventHandler.js +5 -0
  10. package/dist/cjs/hooks/useIsomorphicLayoutEffect.d.ts +5 -0
  11. package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +5 -0
  12. package/dist/cjs/hooks/useSwipeable.d.ts +21 -0
  13. package/dist/cjs/hooks/useSwipeable.js +75 -0
  14. package/dist/cjs/hooks/useThemeConfig.d.ts +6 -0
  15. package/dist/cjs/hooks/useValueControl.d.ts +14 -1
  16. package/dist/cjs/hooks/useValueControl.js +4 -0
  17. package/dist/cjs/index.d.ts +1 -1
  18. package/dist/cjs/index.js +1 -1
  19. package/dist/cjs/types/index.d.ts +4 -0
  20. package/dist/cjs/utils/componentPropsProcessors.d.ts +12 -0
  21. package/dist/cjs/utils/componentPropsProcessors.js +12 -0
  22. package/dist/cjs/utils/isBrowser.d.ts +5 -0
  23. package/dist/cjs/utils/isBrowser.js +5 -0
  24. package/dist/esm/components/ThemeProvider/ThemeProvider.d.ts +15 -0
  25. package/dist/esm/components/ThemeProvider/ThemeProvider.js +3 -0
  26. package/dist/esm/hooks/index.d.ts +1 -1
  27. package/dist/esm/hooks/index.js +1 -1
  28. package/dist/esm/hooks/useDebounce.d.ts +5 -0
  29. package/dist/esm/hooks/useDebounce.js +5 -0
  30. package/dist/esm/hooks/useEventHandler.d.ts +5 -0
  31. package/dist/esm/hooks/useEventHandler.js +5 -0
  32. package/dist/esm/hooks/useIsomorphicLayoutEffect.d.ts +5 -0
  33. package/dist/esm/hooks/useIsomorphicLayoutEffect.js +5 -0
  34. package/dist/esm/hooks/useSwipeable.d.ts +21 -0
  35. package/dist/esm/hooks/useSwipeable.js +61 -0
  36. package/dist/esm/hooks/useThemeConfig.d.ts +6 -0
  37. package/dist/esm/hooks/useValueControl.d.ts +14 -1
  38. package/dist/esm/hooks/useValueControl.js +4 -0
  39. package/dist/esm/index.d.ts +1 -1
  40. package/dist/esm/index.js +1 -1
  41. package/dist/esm/types/index.d.ts +4 -0
  42. package/dist/esm/utils/componentPropsProcessors.d.ts +12 -0
  43. package/dist/esm/utils/componentPropsProcessors.js +12 -0
  44. package/dist/esm/utils/isBrowser.d.ts +5 -0
  45. package/dist/esm/utils/isBrowser.js +5 -0
  46. package/package.json +2 -2
  47. package/src/components/ThemeProvider/ThemeProvider.tsx +26 -3
  48. package/src/hooks/index.ts +1 -1
  49. package/src/hooks/useDebounce.ts +5 -0
  50. package/src/hooks/useEventHandler.ts +5 -0
  51. package/src/hooks/useIsomorphicLayoutEffect.ts +5 -0
  52. package/src/hooks/useSwipeable.ts +88 -0
  53. package/src/hooks/useThemeConfig.tsx +9 -1
  54. package/src/hooks/useValueControl.ts +14 -1
  55. package/src/index.ts +1 -1
  56. package/src/types/index.ts +4 -0
  57. package/src/utils/componentPropsProcessors.ts +20 -5
  58. package/src/utils/isBrowser.ts +5 -0
  59. package/dist/cjs/hooks/useSwipe.d.ts +0 -8
  60. package/dist/cjs/hooks/useSwipe.js +0 -15
  61. package/dist/esm/hooks/useSwipe.d.ts +0 -8
  62. package/dist/esm/hooks/useSwipe.js +0 -6
  63. package/src/hooks/useSwipe.ts +0 -27
package/README.md CHANGED
@@ -9,3 +9,88 @@
9
9
  `npm i @snack-uikit/utils`
10
10
 
11
11
  [Changelog](./CHANGELOG.md)
12
+
13
+
14
+ [//]: DOCUMENTATION_SECTION_START
15
+ [//]: THIS_SECTION_IS_AUTOGENERATED_PLEASE_DONT_EDIT_IT
16
+ ## useDebounce
17
+ `React hook`
18
+
19
+ Хук задерживает выполнение функции или обновление значения до тех пор,
20
+ пока не пройдет определенный период времени без новых вызовов.
21
+ ## useEventHandler
22
+ `React hook`
23
+
24
+ Хук для создания обработчика событий с неизменной функцией.
25
+ ## useLayoutEffect
26
+ `React hook`
27
+
28
+ Хук используется вместо стандартного useLayoutEffect-а,
29
+ нужен для корректной работы SSR
30
+ ## useSwipeable
31
+ Хук для работы с событиями свайпа
32
+ ### Props
33
+ | name | type | default value | description |
34
+ |------|------|---------------|-------------|
35
+ | enabled | `boolean` | true | Включен ли свайп |
36
+ | availableDirections | `SwipeDirections[]` | - | Направления, в которых будет работать свайп. Укажите это свойство, чтобы предотвратить конфликты и заблокировать свайп в родительских элементах по этим направлениям. |
37
+ | onSwipedDown | `SwipeCallback` | - | Called after a DOWN swipe |
38
+ | onSwipedLeft | `SwipeCallback` | - | Called after a LEFT swipe |
39
+ | onSwipedRight | `SwipeCallback` | - | Called after a RIGHT swipe |
40
+ | onSwipedUp | `SwipeCallback` | - | Called after a UP swipe |
41
+ | onSwipeStart | `SwipeCallback` | - | Called at start of a tracked swipe. |
42
+ | onSwiped | `SwipeCallback` | - | Called after any swipe. |
43
+ | onSwiping | `SwipeCallback` | - | Called for each move event during a tracked swipe. |
44
+ | onTap | `TapCallback` | - | Called after a tap. A touch under the min distance, `delta`. |
45
+ | onTouchStartOrOnMouseDown | `TapCallback` | - | Called for `touchstart` and `mousedown`. |
46
+ | onTouchEndOrOnMouseUp | `TapCallback` | - | Called for `touchend` and `mouseup`. |
47
+ | delta | `ConfigurationOptionDelta` | - | Min distance(px) before a swipe starts. **Default**: `10` |
48
+ | preventScrollOnSwipe | `boolean` | - | Prevents scroll during swipe in most cases. **Default**: `false` |
49
+ | rotationAngle | `number` | - | Set a rotation angle. **Default**: `0` |
50
+ | trackMouse | `boolean` | - | Track mouse input. **Default**: `false` |
51
+ | trackTouch | `boolean` | - | Track touch input. **Default**: `true` |
52
+ | swipeDuration | `number` | - | Allowable duration of a swipe (ms). **Default**: `Infinity` |
53
+ | touchEventOptions | `{ passive: boolean; }` | - | Options for touch event listeners |
54
+ ## useThemeConfig
55
+ Хук для работы с темами
56
+ ### Props
57
+ | name | type | default value | description |
58
+ |------|------|---------------|-------------|
59
+ | themeMap* | `Record<T, string>` | - | Объект с указанием соответсвия темы и css-класса |
60
+ ## useValueControl
61
+ Хук для работы с состоянием.
62
+ Нужен для поддержки controlled/uncontrolled поведения, в зависимости от того были ли переданы входные аргументы
63
+ ### Props
64
+ | name | type | default value | description |
65
+ |------|------|---------------|-------------|
66
+ | value | `TValue` | - | Значение состояния |
67
+ | defaultValue | `TValue` | - | Значение по умолчанию |
68
+ | onChange | `(value: TValue) => void` | - | Колбек, вызываемый на смену состояния |
69
+ ## ThemeProvider
70
+ Провайдер, предназначенный для работы с темами
71
+ ### Props
72
+ | name | type | default value | description |
73
+ |------|------|---------------|-------------|
74
+ | defaultTheme* | `string` | - | Значение темы по умолчанию |
75
+ | themeMap* | `Record<string, string>` | - | Объект с указанием соответсвия темы и css-класса |
76
+ | children* | `ReactNode` | - | Дети, которые будут обёрнуты в провайдер |
77
+ ## excludeSupportProps
78
+ `helper`
79
+
80
+ Функция для исключения вспомогательных свойств (data-test-id & aria-*)
81
+ ## extractDataTestProps
82
+ `helper`
83
+
84
+ Функция для отбора свойства data-test-id
85
+ ## extractSupportProps
86
+ `helper`
87
+
88
+ Функция для отбора вспомогательных свойств (data-test-id & aria-*)
89
+ ## isBrowser
90
+ `helper`
91
+
92
+ Функция проверки текущей среды выполнения кода,
93
+ нужна для корректной работы SSR
94
+
95
+
96
+ [//]: DOCUMENTATION_SECTION_END
@@ -1,13 +1,28 @@
1
1
  import { ReactNode } from 'react';
2
2
  type UseThemePropsWithDefaultTheme = {
3
+ /**
4
+ * Объект с указанием соответсвия темы и css-класса
5
+ */
3
6
  themeMap: Record<string, string>;
7
+ /**
8
+ * Значение темы по умолчанию
9
+ */
4
10
  defaultTheme: string;
5
11
  };
6
12
  type UseThemeProps = {
13
+ /**
14
+ * Объект с указанием соответсвия темы и css-класса
15
+ */
7
16
  themeMap: Record<string, string>;
8
17
  };
9
18
  export type ThemeProviderProps = {
19
+ /**
20
+ * Дети, которые будут обёрнуты в провайдер
21
+ */
10
22
  children: ReactNode;
11
23
  } & (UseThemePropsWithDefaultTheme | UseThemeProps);
24
+ /**
25
+ * Провайдер, предназначенный для работы с темами
26
+ */
12
27
  export declare function ThemeProvider({ children, ...props }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
13
28
  export {};
@@ -15,6 +15,9 @@ exports.ThemeProvider = ThemeProvider;
15
15
  const jsx_runtime_1 = require("react/jsx-runtime");
16
16
  const hooks_1 = require("../../hooks");
17
17
  const contexts_1 = require("./contexts");
18
+ /**
19
+ * Провайдер, предназначенный для работы с темами
20
+ */
18
21
  function ThemeProvider(_a) {
19
22
  var {
20
23
  children
@@ -1,6 +1,6 @@
1
1
  export * from './useDebounce';
2
2
  export * from './useEventHandler';
3
3
  export * from './useIsomorphicLayoutEffect';
4
- export * from './useSwipe';
4
+ export * from './useSwipeable';
5
5
  export * from './useThemeConfig';
6
6
  export * from './useValueControl';
@@ -25,6 +25,6 @@ Object.defineProperty(exports, "__esModule", {
25
25
  __exportStar(require("./useDebounce"), exports);
26
26
  __exportStar(require("./useEventHandler"), exports);
27
27
  __exportStar(require("./useIsomorphicLayoutEffect"), exports);
28
- __exportStar(require("./useSwipe"), exports);
28
+ __exportStar(require("./useSwipeable"), exports);
29
29
  __exportStar(require("./useThemeConfig"), exports);
30
30
  __exportStar(require("./useValueControl"), exports);
@@ -1 +1,6 @@
1
+ /**
2
+ * Хук задерживает выполнение функции или обновление значения до тех пор,
3
+ * пока не пройдет определенный период времени без новых вызовов.
4
+ * @function React hook
5
+ */
1
6
  export declare function useDebounce(callback: () => void, timeout?: number): () => void;
@@ -7,6 +7,11 @@ exports.useDebounce = useDebounce;
7
7
  const react_1 = require("react");
8
8
  const utils_1 = require("../utils");
9
9
  const useEventHandler_1 = require("./useEventHandler");
10
+ /**
11
+ * Хук задерживает выполнение функции или обновление значения до тех пор,
12
+ * пока не пройдет определенный период времени без новых вызовов.
13
+ * @function React hook
14
+ */
10
15
  function useDebounce(callback) {
11
16
  let timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
12
17
  const timeStampRef = (0, react_1.useRef)(0);
@@ -1 +1,6 @@
1
+ /**
2
+ * Хук для создания обработчика событий с неизменной функцией.
3
+ * @function React hook
4
+ * @param handler коллбек события, без параметров
5
+ */
1
6
  export declare function useEventHandler<T extends (...args: never[]) => unknown>(handler: T): T;
@@ -6,6 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useEventHandler = useEventHandler;
7
7
  const react_1 = require("react");
8
8
  const useIsomorphicLayoutEffect_1 = require("./useIsomorphicLayoutEffect");
9
+ /**
10
+ * Хук для создания обработчика событий с неизменной функцией.
11
+ * @function React hook
12
+ * @param handler коллбек события, без параметров
13
+ */
9
14
  function useEventHandler(handler) {
10
15
  const handlerRef = (0, react_1.useRef)(null);
11
16
  (0, useIsomorphicLayoutEffect_1.useLayoutEffect)(() => {
@@ -1,2 +1,7 @@
1
1
  import { useLayoutEffect as useLayoutEffectInternal } from 'react';
2
+ /**
3
+ * Хук используется вместо стандартного useLayoutEffect-а,
4
+ * нужен для корректной работы SSR
5
+ * @function React hook
6
+ */
2
7
  export declare const useLayoutEffect: typeof useLayoutEffectInternal;
@@ -7,4 +7,9 @@ exports.useLayoutEffect = void 0;
7
7
  // eslint-disable-next-line no-restricted-imports
8
8
  const react_1 = require("react");
9
9
  const utils_1 = require("../utils");
10
+ /**
11
+ * Хук используется вместо стандартного useLayoutEffect-а,
12
+ * нужен для корректной работы SSR
13
+ * @function React hook
14
+ */
10
15
  exports.useLayoutEffect = (0, utils_1.isBrowser)() ? react_1.useLayoutEffect : react_1.useEffect;
@@ -0,0 +1,21 @@
1
+ import { SwipeableHandlers, SwipeableProps, SwipeCallback, SwipeDirections, SwipeEventData } from 'react-swipeable';
2
+ export declare const DATA_SWIPE_DIRECTIONS_ATTRIBUTE = "data-swipe-directions";
3
+ export type UseSwipeProps = {
4
+ /**
5
+ * Включен ли свайп
6
+ */
7
+ enabled?: boolean;
8
+ /**
9
+ * Направления, в которых будет работать свайп.
10
+ * Укажите это свойство, чтобы предотвратить конфликты и заблокировать свайп в родительских элементах по этим направлениям.
11
+ */
12
+ availableDirections?: SwipeDirections[];
13
+ } & SwipeableProps;
14
+ export type UseSwipeReturnType = SwipeableHandlers & {
15
+ [DATA_SWIPE_DIRECTIONS_ATTRIBUTE]?: string;
16
+ };
17
+ /**
18
+ * Хук для работы с событиями свайпа
19
+ */
20
+ export declare function useSwipeable({ availableDirections, enabled, ...options }: UseSwipeProps): UseSwipeReturnType;
21
+ export type { SwipeCallback, SwipeDirections, SwipeEventData };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
4
+ var t = {};
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
8
+ }
9
+ return t;
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ exports.DATA_SWIPE_DIRECTIONS_ATTRIBUTE = void 0;
15
+ exports.useSwipeable = useSwipeable;
16
+ const react_1 = require("react");
17
+ const react_swipeable_1 = require("react-swipeable");
18
+ exports.DATA_SWIPE_DIRECTIONS_ATTRIBUTE = 'data-swipe-directions';
19
+ /**
20
+ * Хук для работы с событиями свайпа
21
+ */
22
+ function useSwipeable(_a) {
23
+ var {
24
+ availableDirections,
25
+ enabled = true
26
+ } = _a,
27
+ options = __rest(_a, ["availableDirections", "enabled"]);
28
+ const canSwipe = (0, react_1.useRef)(true);
29
+ const onSwipeStart = eventData => {
30
+ var _a;
31
+ if (availableDirections) {
32
+ if (!availableDirections.includes(eventData.dir)) {
33
+ canSwipe.current = false;
34
+ return;
35
+ }
36
+ if (!options.onSwipeStart) {
37
+ return;
38
+ }
39
+ eventData.event.preventDefault();
40
+ eventData.event.stopPropagation();
41
+ }
42
+ (_a = options.onSwipeStart) === null || _a === void 0 ? void 0 : _a.call(options, eventData);
43
+ };
44
+ const onSwiping = eventData => {
45
+ var _a;
46
+ if (availableDirections) {
47
+ if (!canSwipe.current) {
48
+ return;
49
+ }
50
+ eventData.event.preventDefault();
51
+ eventData.event.stopPropagation();
52
+ }
53
+ (_a = options.onSwiping) === null || _a === void 0 ? void 0 : _a.call(options, eventData);
54
+ };
55
+ const onSwiped = eventData => {
56
+ var _a;
57
+ if (availableDirections) {
58
+ if (!canSwipe.current) {
59
+ canSwipe.current = true;
60
+ return;
61
+ }
62
+ eventData.event.preventDefault();
63
+ eventData.event.stopPropagation();
64
+ }
65
+ (_a = options.onSwiped) === null || _a === void 0 ? void 0 : _a.call(options, eventData);
66
+ };
67
+ const handlers = (0, react_swipeable_1.useSwipeable)(enabled ? Object.assign(Object.assign({}, options), {
68
+ onSwipeStart,
69
+ onSwiping,
70
+ onSwiped
71
+ }) : {});
72
+ return Object.assign(Object.assign({}, handlers), {
73
+ [exports.DATA_SWIPE_DIRECTIONS_ATTRIBUTE]: enabled && availableDirections ? availableDirections.join(' ') : undefined
74
+ });
75
+ }
@@ -3,8 +3,14 @@ type UseThemePropsWithDefaultTheme<T extends string> = {
3
3
  defaultTheme: T;
4
4
  };
5
5
  type UseThemeProps<T extends string> = {
6
+ /**
7
+ * Объект с указанием соответсвия темы и css-класса
8
+ */
6
9
  themeMap: Record<T, string>;
7
10
  };
11
+ /**
12
+ * Хук для работы с темами
13
+ */
8
14
  export declare function useThemeConfig<T extends string>(props: UseThemeProps<T>): {
9
15
  theme: T | undefined;
10
16
  themeClassName: string | undefined;
@@ -1,7 +1,20 @@
1
1
  type UseValueControl<TValue> = {
2
+ /**
3
+ * Значение состояния
4
+ */
2
5
  value?: TValue;
3
- onChange?(value: TValue): void;
6
+ /**
7
+ * Значение по умолчанию
8
+ */
4
9
  defaultValue?: TValue;
10
+ /**
11
+ * Колбек, вызываемый на смену состояния
12
+ */
13
+ onChange?(value: TValue): void;
5
14
  };
15
+ /**
16
+ * Хук для работы с состоянием.
17
+ * Нужен для поддержки controlled/uncontrolled поведения, в зависимости от того были ли переданы входные аргументы
18
+ */
6
19
  export declare function useValueControl<TValue>({ value, onChange, defaultValue }: UseValueControl<TValue>): readonly [TValue | undefined, (value: any, ...args: any[]) => ReturnType<import("uncontrollable").Handler> | void];
7
20
  export {};
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useValueControl = useValueControl;
7
7
  const uncontrollable_1 = require("uncontrollable");
8
+ /**
9
+ * Хук для работы с состоянием.
10
+ * Нужен для поддержки controlled/uncontrolled поведения, в зависимости от того были ли переданы входные аргументы
11
+ */
8
12
  function useValueControl(_ref) {
9
13
  let {
10
14
  value,
@@ -1,4 +1,4 @@
1
1
  export * from './hooks';
2
- export * from './utils';
3
2
  export * from './components';
3
+ export * from './utils';
4
4
  export * from './types';
package/dist/cjs/index.js CHANGED
@@ -23,6 +23,6 @@ Object.defineProperty(exports, "__esModule", {
23
23
  value: true
24
24
  });
25
25
  __exportStar(require("./hooks"), exports);
26
- __exportStar(require("./utils"), exports);
27
26
  __exportStar(require("./components"), exports);
27
+ __exportStar(require("./utils"), exports);
28
28
  __exportStar(require("./types"), exports);
@@ -1 +1,5 @@
1
+ /**
2
+ * Utility-тип, преобразующий константные значения объекта в union
3
+ * @function type
4
+ */
1
5
  export type ValueOf<T> = T[keyof T];
@@ -2,6 +2,18 @@ import { AriaAttributes } from 'react';
2
2
  export type WithSupportProps<T> = {
3
3
  'data-test-id'?: string;
4
4
  } & AriaAttributes & T;
5
+ /**
6
+ * Функция для исключения вспомогательных свойств (data-test-id & aria-*)
7
+ * @function helper
8
+ */
5
9
  export declare function excludeSupportProps<T extends Record<string, unknown>>(props: T): {};
10
+ /**
11
+ * Функция для отбора свойства data-test-id
12
+ * @function helper
13
+ */
6
14
  export declare function extractDataTestProps<T extends Record<string, unknown>>(props: T): Record<string, unknown>;
15
+ /**
16
+ * Функция для отбора вспомогательных свойств (data-test-id & aria-*)
17
+ * @function helper
18
+ */
7
19
  export declare function extractSupportProps<T extends Record<string, unknown>>(props: T): Record<string, unknown>;
@@ -19,12 +19,24 @@ function extractProps(props, regex) {
19
19
  return nextProps;
20
20
  }, {});
21
21
  }
22
+ /**
23
+ * Функция для исключения вспомогательных свойств (data-test-id & aria-*)
24
+ * @function helper
25
+ */
22
26
  function excludeSupportProps(props) {
23
27
  return excludeProps(props, DATA_AND_ARIA_REGEXP);
24
28
  }
29
+ /**
30
+ * Функция для отбора свойства data-test-id
31
+ * @function helper
32
+ */
25
33
  function extractDataTestProps(props) {
26
34
  return extractProps(props, DATA_TEST_REGEXP);
27
35
  }
36
+ /**
37
+ * Функция для отбора вспомогательных свойств (data-test-id & aria-*)
38
+ * @function helper
39
+ */
28
40
  function extractSupportProps(props) {
29
41
  return extractProps(props, DATA_AND_ARIA_REGEXP);
30
42
  }
@@ -1 +1,6 @@
1
+ /**
2
+ * Функция проверки текущей среды выполнения кода,
3
+ * нужна для корректной работы SSR
4
+ * @function helper
5
+ */
1
6
  export declare function isBrowser(): boolean;
@@ -4,6 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isBrowser = isBrowser;
7
+ /**
8
+ * Функция проверки текущей среды выполнения кода,
9
+ * нужна для корректной работы SSR
10
+ * @function helper
11
+ */
7
12
  function isBrowser() {
8
13
  // eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi
9
14
  return Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
@@ -1,13 +1,28 @@
1
1
  import { ReactNode } from 'react';
2
2
  type UseThemePropsWithDefaultTheme = {
3
+ /**
4
+ * Объект с указанием соответсвия темы и css-класса
5
+ */
3
6
  themeMap: Record<string, string>;
7
+ /**
8
+ * Значение темы по умолчанию
9
+ */
4
10
  defaultTheme: string;
5
11
  };
6
12
  type UseThemeProps = {
13
+ /**
14
+ * Объект с указанием соответсвия темы и css-класса
15
+ */
7
16
  themeMap: Record<string, string>;
8
17
  };
9
18
  export type ThemeProviderProps = {
19
+ /**
20
+ * Дети, которые будут обёрнуты в провайдер
21
+ */
10
22
  children: ReactNode;
11
23
  } & (UseThemePropsWithDefaultTheme | UseThemeProps);
24
+ /**
25
+ * Провайдер, предназначенный для работы с темами
26
+ */
12
27
  export declare function ThemeProvider({ children, ...props }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
13
28
  export {};
@@ -12,6 +12,9 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { useThemeConfig } from '../../hooks';
14
14
  import { ThemeContext } from './contexts';
15
+ /**
16
+ * Провайдер, предназначенный для работы с темами
17
+ */
15
18
  export function ThemeProvider(_a) {
16
19
  var { children } = _a, props = __rest(_a, ["children"]);
17
20
  const themeConfig = useThemeConfig(props);
@@ -1,6 +1,6 @@
1
1
  export * from './useDebounce';
2
2
  export * from './useEventHandler';
3
3
  export * from './useIsomorphicLayoutEffect';
4
- export * from './useSwipe';
4
+ export * from './useSwipeable';
5
5
  export * from './useThemeConfig';
6
6
  export * from './useValueControl';
@@ -1,6 +1,6 @@
1
1
  export * from './useDebounce';
2
2
  export * from './useEventHandler';
3
3
  export * from './useIsomorphicLayoutEffect';
4
- export * from './useSwipe';
4
+ export * from './useSwipeable';
5
5
  export * from './useThemeConfig';
6
6
  export * from './useValueControl';
@@ -1 +1,6 @@
1
+ /**
2
+ * Хук задерживает выполнение функции или обновление значения до тех пор,
3
+ * пока не пройдет определенный период времени без новых вызовов.
4
+ * @function React hook
5
+ */
1
6
  export declare function useDebounce(callback: () => void, timeout?: number): () => void;
@@ -1,6 +1,11 @@
1
1
  import { useRef } from 'react';
2
2
  import { isBrowser } from '../utils';
3
3
  import { useEventHandler } from './useEventHandler';
4
+ /**
5
+ * Хук задерживает выполнение функции или обновление значения до тех пор,
6
+ * пока не пройдет определенный период времени без новых вызовов.
7
+ * @function React hook
8
+ */
4
9
  export function useDebounce(callback, timeout = 0) {
5
10
  const timeStampRef = useRef(0);
6
11
  let timerId = -1;
@@ -1 +1,6 @@
1
+ /**
2
+ * Хук для создания обработчика событий с неизменной функцией.
3
+ * @function React hook
4
+ * @param handler коллбек события, без параметров
5
+ */
1
6
  export declare function useEventHandler<T extends (...args: never[]) => unknown>(handler: T): T;
@@ -1,5 +1,10 @@
1
1
  import { useCallback, useRef } from 'react';
2
2
  import { useLayoutEffect } from './useIsomorphicLayoutEffect';
3
+ /**
4
+ * Хук для создания обработчика событий с неизменной функцией.
5
+ * @function React hook
6
+ * @param handler коллбек события, без параметров
7
+ */
3
8
  export function useEventHandler(handler) {
4
9
  const handlerRef = useRef(null);
5
10
  useLayoutEffect(() => {
@@ -1,2 +1,7 @@
1
1
  import { useLayoutEffect as useLayoutEffectInternal } from 'react';
2
+ /**
3
+ * Хук используется вместо стандартного useLayoutEffect-а,
4
+ * нужен для корректной работы SSR
5
+ * @function React hook
6
+ */
2
7
  export declare const useLayoutEffect: typeof useLayoutEffectInternal;
@@ -1,4 +1,9 @@
1
1
  // eslint-disable-next-line no-restricted-imports
2
2
  import { useEffect, useLayoutEffect as useLayoutEffectInternal } from 'react';
3
3
  import { isBrowser } from '../utils';
4
+ /**
5
+ * Хук используется вместо стандартного useLayoutEffect-а,
6
+ * нужен для корректной работы SSR
7
+ * @function React hook
8
+ */
4
9
  export const useLayoutEffect = isBrowser() ? useLayoutEffectInternal : useEffect;
@@ -0,0 +1,21 @@
1
+ import { SwipeableHandlers, SwipeableProps, SwipeCallback, SwipeDirections, SwipeEventData } from 'react-swipeable';
2
+ export declare const DATA_SWIPE_DIRECTIONS_ATTRIBUTE = "data-swipe-directions";
3
+ export type UseSwipeProps = {
4
+ /**
5
+ * Включен ли свайп
6
+ */
7
+ enabled?: boolean;
8
+ /**
9
+ * Направления, в которых будет работать свайп.
10
+ * Укажите это свойство, чтобы предотвратить конфликты и заблокировать свайп в родительских элементах по этим направлениям.
11
+ */
12
+ availableDirections?: SwipeDirections[];
13
+ } & SwipeableProps;
14
+ export type UseSwipeReturnType = SwipeableHandlers & {
15
+ [DATA_SWIPE_DIRECTIONS_ATTRIBUTE]?: string;
16
+ };
17
+ /**
18
+ * Хук для работы с событиями свайпа
19
+ */
20
+ export declare function useSwipeable({ availableDirections, enabled, ...options }: UseSwipeProps): UseSwipeReturnType;
21
+ export type { SwipeCallback, SwipeDirections, SwipeEventData };
@@ -0,0 +1,61 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { useRef } from 'react';
13
+ import { useSwipeable as useSwipeableInternal, } from 'react-swipeable';
14
+ export const DATA_SWIPE_DIRECTIONS_ATTRIBUTE = 'data-swipe-directions';
15
+ /**
16
+ * Хук для работы с событиями свайпа
17
+ */
18
+ export function useSwipeable(_a) {
19
+ var { availableDirections, enabled = true } = _a, options = __rest(_a, ["availableDirections", "enabled"]);
20
+ const canSwipe = useRef(true);
21
+ const onSwipeStart = eventData => {
22
+ var _a;
23
+ if (availableDirections) {
24
+ if (!availableDirections.includes(eventData.dir)) {
25
+ canSwipe.current = false;
26
+ return;
27
+ }
28
+ if (!options.onSwipeStart) {
29
+ return;
30
+ }
31
+ eventData.event.preventDefault();
32
+ eventData.event.stopPropagation();
33
+ }
34
+ (_a = options.onSwipeStart) === null || _a === void 0 ? void 0 : _a.call(options, eventData);
35
+ };
36
+ const onSwiping = eventData => {
37
+ var _a;
38
+ if (availableDirections) {
39
+ if (!canSwipe.current) {
40
+ return;
41
+ }
42
+ eventData.event.preventDefault();
43
+ eventData.event.stopPropagation();
44
+ }
45
+ (_a = options.onSwiping) === null || _a === void 0 ? void 0 : _a.call(options, eventData);
46
+ };
47
+ const onSwiped = eventData => {
48
+ var _a;
49
+ if (availableDirections) {
50
+ if (!canSwipe.current) {
51
+ canSwipe.current = true;
52
+ return;
53
+ }
54
+ eventData.event.preventDefault();
55
+ eventData.event.stopPropagation();
56
+ }
57
+ (_a = options.onSwiped) === null || _a === void 0 ? void 0 : _a.call(options, eventData);
58
+ };
59
+ const handlers = useSwipeableInternal(enabled ? Object.assign(Object.assign({}, options), { onSwipeStart, onSwiping, onSwiped }) : {});
60
+ return Object.assign(Object.assign({}, handlers), { [DATA_SWIPE_DIRECTIONS_ATTRIBUTE]: enabled && availableDirections ? availableDirections.join(' ') : undefined });
61
+ }
@@ -3,8 +3,14 @@ type UseThemePropsWithDefaultTheme<T extends string> = {
3
3
  defaultTheme: T;
4
4
  };
5
5
  type UseThemeProps<T extends string> = {
6
+ /**
7
+ * Объект с указанием соответсвия темы и css-класса
8
+ */
6
9
  themeMap: Record<T, string>;
7
10
  };
11
+ /**
12
+ * Хук для работы с темами
13
+ */
8
14
  export declare function useThemeConfig<T extends string>(props: UseThemeProps<T>): {
9
15
  theme: T | undefined;
10
16
  themeClassName: string | undefined;
@@ -1,7 +1,20 @@
1
1
  type UseValueControl<TValue> = {
2
+ /**
3
+ * Значение состояния
4
+ */
2
5
  value?: TValue;
3
- onChange?(value: TValue): void;
6
+ /**
7
+ * Значение по умолчанию
8
+ */
4
9
  defaultValue?: TValue;
10
+ /**
11
+ * Колбек, вызываемый на смену состояния
12
+ */
13
+ onChange?(value: TValue): void;
5
14
  };
15
+ /**
16
+ * Хук для работы с состоянием.
17
+ * Нужен для поддержки controlled/uncontrolled поведения, в зависимости от того были ли переданы входные аргументы
18
+ */
6
19
  export declare function useValueControl<TValue>({ value, onChange, defaultValue }: UseValueControl<TValue>): readonly [TValue | undefined, (value: any, ...args: any[]) => ReturnType<import("uncontrollable").Handler> | void];
7
20
  export {};
@@ -1,4 +1,8 @@
1
1
  import { useUncontrolledProp } from 'uncontrollable';
2
+ /**
3
+ * Хук для работы с состоянием.
4
+ * Нужен для поддержки controlled/uncontrolled поведения, в зависимости от того были ли переданы входные аргументы
5
+ */
2
6
  export function useValueControl({ value, onChange, defaultValue }) {
3
7
  return useUncontrolledProp(value, defaultValue, (newValue) => {
4
8
  const newState = typeof newValue === 'function' ? newValue(value) : newValue;
@@ -1,4 +1,4 @@
1
1
  export * from './hooks';
2
- export * from './utils';
3
2
  export * from './components';
3
+ export * from './utils';
4
4
  export * from './types';
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './hooks';
2
- export * from './utils';
3
2
  export * from './components';
3
+ export * from './utils';
4
4
  export * from './types';
@@ -1 +1,5 @@
1
+ /**
2
+ * Utility-тип, преобразующий константные значения объекта в union
3
+ * @function type
4
+ */
1
5
  export type ValueOf<T> = T[keyof T];
@@ -2,6 +2,18 @@ import { AriaAttributes } from 'react';
2
2
  export type WithSupportProps<T> = {
3
3
  'data-test-id'?: string;
4
4
  } & AriaAttributes & T;
5
+ /**
6
+ * Функция для исключения вспомогательных свойств (data-test-id & aria-*)
7
+ * @function helper
8
+ */
5
9
  export declare function excludeSupportProps<T extends Record<string, unknown>>(props: T): {};
10
+ /**
11
+ * Функция для отбора свойства data-test-id
12
+ * @function helper
13
+ */
6
14
  export declare function extractDataTestProps<T extends Record<string, unknown>>(props: T): Record<string, unknown>;
15
+ /**
16
+ * Функция для отбора вспомогательных свойств (data-test-id & aria-*)
17
+ * @function helper
18
+ */
7
19
  export declare function extractSupportProps<T extends Record<string, unknown>>(props: T): Record<string, unknown>;
@@ -12,12 +12,24 @@ function extractProps(props, regex) {
12
12
  return nextProps;
13
13
  }, {});
14
14
  }
15
+ /**
16
+ * Функция для исключения вспомогательных свойств (data-test-id & aria-*)
17
+ * @function helper
18
+ */
15
19
  export function excludeSupportProps(props) {
16
20
  return excludeProps(props, DATA_AND_ARIA_REGEXP);
17
21
  }
22
+ /**
23
+ * Функция для отбора свойства data-test-id
24
+ * @function helper
25
+ */
18
26
  export function extractDataTestProps(props) {
19
27
  return extractProps(props, DATA_TEST_REGEXP);
20
28
  }
29
+ /**
30
+ * Функция для отбора вспомогательных свойств (data-test-id & aria-*)
31
+ * @function helper
32
+ */
21
33
  export function extractSupportProps(props) {
22
34
  return extractProps(props, DATA_AND_ARIA_REGEXP);
23
35
  }
@@ -1 +1,6 @@
1
+ /**
2
+ * Функция проверки текущей среды выполнения кода,
3
+ * нужна для корректной работы SSR
4
+ * @function helper
5
+ */
1
6
  export declare function isBrowser(): boolean;
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Функция проверки текущей среды выполнения кода,
3
+ * нужна для корректной работы SSR
4
+ * @function helper
5
+ */
1
6
  export function isBrowser() {
2
7
  // eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi
3
8
  return Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Utils",
7
- "version": "3.5.1-preview-53bd8747.0",
7
+ "version": "3.5.1-preview-baf754b1.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -39,5 +39,5 @@
39
39
  "react-swipeable": "7.0.2",
40
40
  "uncontrollable": "8.0.4"
41
41
  },
42
- "gitHead": "527ea8e5660cbf949a1e84bc833f876a0802d10e"
42
+ "gitHead": "46fb98c10336c2f3dfb35c66737eca5cd3dc6e4f"
43
43
  }
@@ -3,11 +3,34 @@ import { ReactNode } from 'react';
3
3
  import { useThemeConfig } from '../../hooks';
4
4
  import { ThemeContext } from './contexts';
5
5
 
6
- type UseThemePropsWithDefaultTheme = { themeMap: Record<string, string>; defaultTheme: string };
7
- type UseThemeProps = { themeMap: Record<string, string> };
6
+ type UseThemePropsWithDefaultTheme = {
7
+ /**
8
+ * Объект с указанием соответсвия темы и css-класса
9
+ */
10
+ themeMap: Record<string, string>;
11
+ /**
12
+ * Значение темы по умолчанию
13
+ */
14
+ defaultTheme: string;
15
+ };
8
16
 
9
- export type ThemeProviderProps = { children: ReactNode } & (UseThemePropsWithDefaultTheme | UseThemeProps);
17
+ type UseThemeProps = {
18
+ /**
19
+ * Объект с указанием соответсвия темы и css-класса
20
+ */
21
+ themeMap: Record<string, string>;
22
+ };
10
23
 
24
+ export type ThemeProviderProps = {
25
+ /**
26
+ * Дети, которые будут обёрнуты в провайдер
27
+ */
28
+ children: ReactNode;
29
+ } & (UseThemePropsWithDefaultTheme | UseThemeProps);
30
+
31
+ /**
32
+ * Провайдер, предназначенный для работы с темами
33
+ */
11
34
  export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
12
35
  const themeConfig = useThemeConfig(props);
13
36
 
@@ -1,6 +1,6 @@
1
1
  export * from './useDebounce';
2
2
  export * from './useEventHandler';
3
3
  export * from './useIsomorphicLayoutEffect';
4
- export * from './useSwipe';
4
+ export * from './useSwipeable';
5
5
  export * from './useThemeConfig';
6
6
  export * from './useValueControl';
@@ -3,6 +3,11 @@ import { useRef } from 'react';
3
3
  import { isBrowser } from '../utils';
4
4
  import { useEventHandler } from './useEventHandler';
5
5
 
6
+ /**
7
+ * Хук задерживает выполнение функции или обновление значения до тех пор,
8
+ * пока не пройдет определенный период времени без новых вызовов.
9
+ * @function React hook
10
+ */
6
11
  export function useDebounce(callback: () => void, timeout = 0) {
7
12
  const timeStampRef = useRef<number>(0);
8
13
  let timerId: NodeJS.Timeout | number = -1;
@@ -2,6 +2,11 @@ import { useCallback, useRef } from 'react';
2
2
 
3
3
  import { useLayoutEffect } from './useIsomorphicLayoutEffect';
4
4
 
5
+ /**
6
+ * Хук для создания обработчика событий с неизменной функцией.
7
+ * @function React hook
8
+ * @param handler коллбек события, без параметров
9
+ */
5
10
  export function useEventHandler<T extends (...args: never[]) => unknown>(handler: T) {
6
11
  const handlerRef = useRef<T | null>(null);
7
12
 
@@ -3,4 +3,9 @@ import { useEffect, useLayoutEffect as useLayoutEffectInternal } from 'react';
3
3
 
4
4
  import { isBrowser } from '../utils';
5
5
 
6
+ /**
7
+ * Хук используется вместо стандартного useLayoutEffect-а,
8
+ * нужен для корректной работы SSR
9
+ * @function React hook
10
+ */
6
11
  export const useLayoutEffect = isBrowser() ? useLayoutEffectInternal : useEffect;
@@ -0,0 +1,88 @@
1
+ import { useRef } from 'react';
2
+ import {
3
+ SwipeableHandlers,
4
+ SwipeableProps,
5
+ SwipeCallback,
6
+ SwipeDirections,
7
+ SwipeEventData,
8
+ useSwipeable as useSwipeableInternal,
9
+ } from 'react-swipeable';
10
+
11
+ export const DATA_SWIPE_DIRECTIONS_ATTRIBUTE = 'data-swipe-directions';
12
+
13
+ export type UseSwipeProps = {
14
+ /**
15
+ * Включен ли свайп
16
+ */
17
+ enabled?: boolean;
18
+ /**
19
+ * Направления, в которых будет работать свайп.
20
+ * Укажите это свойство, чтобы предотвратить конфликты и заблокировать свайп в родительских элементах по этим направлениям.
21
+ */
22
+ availableDirections?: SwipeDirections[];
23
+ } & SwipeableProps;
24
+
25
+ export type UseSwipeReturnType = SwipeableHandlers & {
26
+ [DATA_SWIPE_DIRECTIONS_ATTRIBUTE]?: string;
27
+ };
28
+
29
+ /**
30
+ * Хук для работы с событиями свайпа
31
+ */
32
+ export function useSwipeable({ availableDirections, enabled = true, ...options }: UseSwipeProps): UseSwipeReturnType {
33
+ const canSwipe = useRef(true);
34
+
35
+ const onSwipeStart: SwipeCallback = eventData => {
36
+ if (availableDirections) {
37
+ if (!availableDirections.includes(eventData.dir)) {
38
+ canSwipe.current = false;
39
+ return;
40
+ }
41
+
42
+ if (!options.onSwipeStart) {
43
+ return;
44
+ }
45
+
46
+ eventData.event.preventDefault();
47
+ eventData.event.stopPropagation();
48
+ }
49
+
50
+ options.onSwipeStart?.(eventData);
51
+ };
52
+
53
+ const onSwiping: SwipeCallback = eventData => {
54
+ if (availableDirections) {
55
+ if (!canSwipe.current) {
56
+ return;
57
+ }
58
+
59
+ eventData.event.preventDefault();
60
+ eventData.event.stopPropagation();
61
+ }
62
+
63
+ options.onSwiping?.(eventData);
64
+ };
65
+
66
+ const onSwiped: SwipeCallback = eventData => {
67
+ if (availableDirections) {
68
+ if (!canSwipe.current) {
69
+ canSwipe.current = true;
70
+ return;
71
+ }
72
+
73
+ eventData.event.preventDefault();
74
+ eventData.event.stopPropagation();
75
+ }
76
+
77
+ options.onSwiped?.(eventData);
78
+ };
79
+
80
+ const handlers = useSwipeableInternal(enabled ? { ...options, onSwipeStart, onSwiping, onSwiped } : {});
81
+
82
+ return {
83
+ ...handlers,
84
+ [DATA_SWIPE_DIRECTIONS_ATTRIBUTE]: enabled && availableDirections ? availableDirections.join(' ') : undefined,
85
+ };
86
+ }
87
+
88
+ export type { SwipeCallback, SwipeDirections, SwipeEventData };
@@ -1,7 +1,12 @@
1
1
  import { useState } from 'react';
2
2
 
3
3
  type UseThemePropsWithDefaultTheme<T extends string> = { themeMap: Record<T, string>; defaultTheme: T };
4
- type UseThemeProps<T extends string> = { themeMap: Record<T, string> };
4
+ type UseThemeProps<T extends string> = {
5
+ /**
6
+ * Объект с указанием соответсвия темы и css-класса
7
+ */
8
+ themeMap: Record<T, string>;
9
+ };
5
10
 
6
11
  function hasDefaultTheme<T extends string>(
7
12
  props: UseThemePropsWithDefaultTheme<T> | UseThemeProps<T>,
@@ -9,6 +14,9 @@ function hasDefaultTheme<T extends string>(
9
14
  return Boolean((props as UseThemePropsWithDefaultTheme<T>).defaultTheme);
10
15
  }
11
16
 
17
+ /**
18
+ * Хук для работы с темами
19
+ */
12
20
  export function useThemeConfig<T extends string>(
13
21
  props: UseThemeProps<T>,
14
22
  ): {
@@ -1,11 +1,24 @@
1
1
  import { useUncontrolledProp } from 'uncontrollable';
2
2
 
3
3
  type UseValueControl<TValue> = {
4
+ /**
5
+ * Значение состояния
6
+ */
4
7
  value?: TValue;
5
- onChange?(value: TValue): void;
8
+ /**
9
+ * Значение по умолчанию
10
+ */
6
11
  defaultValue?: TValue;
12
+ /**
13
+ * Колбек, вызываемый на смену состояния
14
+ */
15
+ onChange?(value: TValue): void;
7
16
  };
8
17
 
18
+ /**
19
+ * Хук для работы с состоянием.
20
+ * Нужен для поддержки controlled/uncontrolled поведения, в зависимости от того были ли переданы входные аргументы
21
+ */
9
22
  export function useValueControl<TValue>({ value, onChange, defaultValue }: UseValueControl<TValue>) {
10
23
  return useUncontrolledProp<TValue>(value, defaultValue, (newValue: TValue) => {
11
24
  const newState = typeof newValue === 'function' ? newValue(value) : newValue;
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './hooks';
2
- export * from './utils';
3
2
  export * from './components';
3
+ export * from './utils';
4
4
  export * from './types';
@@ -1 +1,5 @@
1
+ /**
2
+ * Utility-тип, преобразующий константные значения объекта в union
3
+ * @function type
4
+ */
1
5
  export type ValueOf<T> = T[keyof T];
@@ -16,11 +16,14 @@ function excludeProps<T extends Record<string, unknown>>(props: T, regexp: RegEx
16
16
  }
17
17
 
18
18
  function extractProps<T extends Record<string, unknown>>(props: T, regex: RegExp) {
19
- return Object.keys(props).reduce((nextProps, prop) => {
20
- if (prop.match(regex)) nextProps[prop] = props[prop];
21
-
22
- return nextProps;
23
- }, {} as Record<string, unknown>);
19
+ return Object.keys(props).reduce(
20
+ (nextProps, prop) => {
21
+ if (prop.match(regex)) nextProps[prop] = props[prop];
22
+
23
+ return nextProps;
24
+ },
25
+ {} as Record<string, unknown>,
26
+ );
24
27
  }
25
28
 
26
29
  export type WithSupportProps<T> = {
@@ -28,14 +31,26 @@ export type WithSupportProps<T> = {
28
31
  } & AriaAttributes &
29
32
  T;
30
33
 
34
+ /**
35
+ * Функция для исключения вспомогательных свойств (data-test-id & aria-*)
36
+ * @function helper
37
+ */
31
38
  export function excludeSupportProps<T extends Record<string, unknown>>(props: T) {
32
39
  return excludeProps(props, DATA_AND_ARIA_REGEXP);
33
40
  }
34
41
 
42
+ /**
43
+ * Функция для отбора свойства data-test-id
44
+ * @function helper
45
+ */
35
46
  export function extractDataTestProps<T extends Record<string, unknown>>(props: T) {
36
47
  return extractProps(props, DATA_TEST_REGEXP);
37
48
  }
38
49
 
50
+ /**
51
+ * Функция для отбора вспомогательных свойств (data-test-id & aria-*)
52
+ * @function helper
53
+ */
39
54
  export function extractSupportProps<T extends Record<string, unknown>>(props: T) {
40
55
  return extractProps(props, DATA_AND_ARIA_REGEXP);
41
56
  }
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Функция проверки текущей среды выполнения кода,
3
+ * нужна для корректной работы SSR
4
+ * @function helper
5
+ */
1
6
  export function isBrowser() {
2
7
  // eslint-disable-next-line @cloud-ru/ssr-safe-react/domApi
3
8
  return Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
@@ -1,8 +0,0 @@
1
- import { SwipeableHandlers, SwipeableProps, SwipeCallback, SwipeDirections, SwipeEventData } from 'react-swipeable';
2
- export declare const DATA_SWIPE_ATTRIBUTE = "data-has-swipe";
3
- export type UseSwipeProps = SwipeableProps;
4
- export type UseSwipeReturnType = SwipeableHandlers & {
5
- [DATA_SWIPE_ATTRIBUTE]: string;
6
- };
7
- export declare function useSwipeable(options: UseSwipeProps): UseSwipeReturnType;
8
- export type { SwipeCallback, SwipeDirections, SwipeEventData };
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DATA_SWIPE_ATTRIBUTE = void 0;
7
- exports.useSwipeable = useSwipeable;
8
- const react_swipeable_1 = require("react-swipeable");
9
- exports.DATA_SWIPE_ATTRIBUTE = 'data-has-swipe';
10
- function useSwipeable(options) {
11
- const handlers = (0, react_swipeable_1.useSwipeable)(options);
12
- return Object.assign(Object.assign({}, handlers), {
13
- [exports.DATA_SWIPE_ATTRIBUTE]: 'true'
14
- });
15
- }
@@ -1,8 +0,0 @@
1
- import { SwipeableHandlers, SwipeableProps, SwipeCallback, SwipeDirections, SwipeEventData } from 'react-swipeable';
2
- export declare const DATA_SWIPE_ATTRIBUTE = "data-has-swipe";
3
- export type UseSwipeProps = SwipeableProps;
4
- export type UseSwipeReturnType = SwipeableHandlers & {
5
- [DATA_SWIPE_ATTRIBUTE]: string;
6
- };
7
- export declare function useSwipeable(options: UseSwipeProps): UseSwipeReturnType;
8
- export type { SwipeCallback, SwipeDirections, SwipeEventData };
@@ -1,6 +0,0 @@
1
- import { useSwipeable as useSwipeableInternal, } from 'react-swipeable';
2
- export const DATA_SWIPE_ATTRIBUTE = 'data-has-swipe';
3
- export function useSwipeable(options) {
4
- const handlers = useSwipeableInternal(options);
5
- return Object.assign(Object.assign({}, handlers), { [DATA_SWIPE_ATTRIBUTE]: 'true' });
6
- }
@@ -1,27 +0,0 @@
1
- import {
2
- SwipeableHandlers,
3
- SwipeableProps,
4
- SwipeCallback,
5
- SwipeDirections,
6
- SwipeEventData,
7
- useSwipeable as useSwipeableInternal,
8
- } from 'react-swipeable';
9
-
10
- export const DATA_SWIPE_ATTRIBUTE = 'data-has-swipe';
11
-
12
- export type UseSwipeProps = SwipeableProps;
13
-
14
- export type UseSwipeReturnType = SwipeableHandlers & {
15
- [DATA_SWIPE_ATTRIBUTE]: string;
16
- };
17
-
18
- export function useSwipeable(options: UseSwipeProps): UseSwipeReturnType {
19
- const handlers = useSwipeableInternal(options);
20
-
21
- return {
22
- ...handlers,
23
- [DATA_SWIPE_ATTRIBUTE]: 'true',
24
- };
25
- }
26
-
27
- export type { SwipeCallback, SwipeDirections, SwipeEventData };