@snack-uikit/utils 4.0.2 → 4.0.3-preview-fe85442f.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.
@@ -19,9 +19,7 @@ const contexts_1 = require("./contexts");
19
19
  * Провайдер, предназначенный для работы с темами
20
20
  */
21
21
  function ThemeProvider(_a) {
22
- var {
23
- children
24
- } = _a,
22
+ var children = _a.children,
25
23
  props = __rest(_a, ["children"]);
26
24
  const themeConfig = (0, hooks_1.useThemeConfig)(props);
27
25
  return (0, jsx_runtime_1.jsx)(contexts_1.ThemeContext.Provider, {
@@ -8,25 +8,21 @@ const react_1 = require("react");
8
8
  const sources_1 = require("./sources");
9
9
  const useSource_1 = require("./useSource");
10
10
  const useDataPersist = _ref => {
11
- let {
12
- options,
13
- parser,
14
- serializer
15
- } = _ref;
11
+ let options = _ref.options,
12
+ parser = _ref.parser,
13
+ serializer = _ref.serializer;
16
14
  const querySource = (0, react_1.useMemo)(() => options ? new sources_1.QueryParamSource(options.queryKey, options.validateData, parser, serializer) : undefined, [options, parser, serializer]);
17
15
  const localStorageSource = (0, react_1.useMemo)(() => options ? new sources_1.LocalStorageSource(options.localStorageKey, options.validateData) : undefined, [options]);
18
- const {
19
- getData: getLocalStorageData,
20
- setData: setLocalStorageData
21
- } = (0, useSource_1.useSource)({
22
- source: localStorageSource
23
- });
24
- const {
25
- getData: getQueryParamsData,
26
- setData: setQueryParamsData
27
- } = (0, useSource_1.useSource)({
28
- source: querySource
29
- });
16
+ const _ref2 = (0, useSource_1.useSource)({
17
+ source: localStorageSource
18
+ }),
19
+ getLocalStorageData = _ref2.getData,
20
+ setLocalStorageData = _ref2.setData;
21
+ const _ref3 = (0, useSource_1.useSource)({
22
+ source: querySource
23
+ }),
24
+ getQueryParamsData = _ref3.getData,
25
+ setQueryParamsData = _ref3.setData;
30
26
  const setDataToStorages = (0, react_1.useCallback)(data => {
31
27
  setLocalStorageData(data);
32
28
  setQueryParamsData(data);
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useSource = void 0;
7
7
  const react_1 = require("react");
8
8
  const useSource = _ref => {
9
- let {
10
- source
11
- } = _ref;
9
+ let source = _ref.source;
12
10
  const setData = (0, react_1.useCallback)(data => {
13
11
  if (!source) {
14
12
  return;
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -13,15 +15,21 @@ const useIsomorphicLayoutEffect_1 = require("./useIsomorphicLayoutEffect");
13
15
  * @function React hook
14
16
  */
15
17
  function useDynamicList(_ref) {
16
- let {
17
- parentContainerRef,
18
- resizingContainerRef = parentContainerRef,
19
- items,
20
- maxVisibleItems = Infinity
21
- } = _ref;
18
+ let parentContainerRef = _ref.parentContainerRef,
19
+ _ref$resizingContaine = _ref.resizingContainerRef,
20
+ resizingContainerRef = _ref$resizingContaine === void 0 ? parentContainerRef : _ref$resizingContaine,
21
+ items = _ref.items,
22
+ _ref$maxVisibleItems = _ref.maxVisibleItems,
23
+ maxVisibleItems = _ref$maxVisibleItems === void 0 ? Infinity : _ref$maxVisibleItems;
22
24
  const adjustAmount = value => Math.min(maxVisibleItems, value);
23
- const [visibleItemsAmount, setVisibleItemsAmount] = (0, react_1.useState)(adjustAmount(items.length));
24
- const [width, setWidth] = (0, react_1.useState)(Infinity);
25
+ const _ref2 = (0, react_1.useState)(adjustAmount(items.length)),
26
+ _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
27
+ visibleItemsAmount = _ref3[0],
28
+ setVisibleItemsAmount = _ref3[1];
29
+ const _ref4 = (0, react_1.useState)(Infinity),
30
+ _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
31
+ width = _ref5[0],
32
+ setWidth = _ref5[1];
25
33
  const widthRef = (0, react_1.useRef)(width);
26
34
  const handleVisibleItemsAmount = param => {
27
35
  if (typeof param === 'number') {
@@ -45,11 +53,9 @@ function useDynamicList(_ref) {
45
53
  handleVisibleItemsAmount(value => value + 1);
46
54
  }
47
55
  });
48
- const toggleItemWidth = (0, useEventHandler_1.useEventHandler)(_ref2 => {
49
- let {
50
- changedWidth,
51
- initialWidth
52
- } = _ref2;
56
+ const toggleItemWidth = (0, useEventHandler_1.useEventHandler)(_ref6 => {
57
+ let changedWidth = _ref6.changedWidth,
58
+ initialWidth = _ref6.initialWidth;
53
59
  if (changedWidth > initialWidth) {
54
60
  //try to add extra item
55
61
  if (visibleItemsAmount < maxVisibleItems) {
@@ -75,9 +81,8 @@ function useDynamicList(_ref) {
75
81
  if (container) {
76
82
  const observer = new ResizeObserver(entities => entities.forEach(entity => {
77
83
  if (entity.target === container) {
78
- const [{
79
- inlineSize: newWidth
80
- }] = entity.contentBoxSize;
84
+ const _entity$contentBoxSiz = (0, _slicedToArray2.default)(entity.contentBoxSize, 1),
85
+ newWidth = _entity$contentBoxSiz[0].inlineSize;
81
86
  setWidth(Math.floor(newWidth));
82
87
  }
83
88
  }));
@@ -16,10 +16,10 @@ const usePopstateSubscription_1 = require("./usePopstateSubscription");
16
16
  function useModalOpenState(/** состояние модалки */
17
17
  open, /** колбек закрытия */
18
18
  onClose, _ref) {
19
- let {
20
- closeOnPopstate = false,
21
- closeByCloseWatcher = true
22
- } = _ref;
19
+ let _ref$closeOnPopstate = _ref.closeOnPopstate,
20
+ closeOnPopstate = _ref$closeOnPopstate === void 0 ? false : _ref$closeOnPopstate,
21
+ _ref$closeByCloseWatc = _ref.closeByCloseWatcher,
22
+ closeByCloseWatcher = _ref$closeByCloseWatc === void 0 ? true : _ref$closeByCloseWatc;
23
23
  const closeHandler = (0, useEventHandler_1.useEventHandler)(onClose);
24
24
  (0, usePopstateSubscription_1.usePopstateSubscription)(() => open && closeHandler(), closeOnPopstate);
25
25
  (0, react_1.useEffect)(() => {
@@ -20,10 +20,9 @@ exports.DATA_SWIPE_DIRECTIONS_ATTRIBUTE = 'data-swipe-directions';
20
20
  * Хук для работы с событиями свайпа
21
21
  */
22
22
  function useSwipeable(_a) {
23
- var {
24
- availableDirections,
25
- enabled = true
26
- } = _a,
23
+ var availableDirections = _a.availableDirections,
24
+ _a$enabled = _a.enabled,
25
+ enabled = _a$enabled === void 0 ? true : _a$enabled,
27
26
  options = __rest(_a, ["availableDirections", "enabled"]);
28
27
  const canSwipe = (0, react_1.useRef)(true);
29
28
  const onSwipeStart = eventData => {
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -9,7 +11,10 @@ function hasDefaultTheme(props) {
9
11
  return Boolean(props.defaultTheme);
10
12
  }
11
13
  function useThemeConfig(props) {
12
- const [theme, setTheme] = (0, react_1.useState)(hasDefaultTheme(props) ? props.defaultTheme : undefined);
14
+ const _ref = (0, react_1.useState)(hasDefaultTheme(props) ? props.defaultTheme : undefined),
15
+ _ref2 = (0, _slicedToArray2.default)(_ref, 2),
16
+ theme = _ref2[0],
17
+ setTheme = _ref2[1];
13
18
  return {
14
19
  theme,
15
20
  themeClassName: theme ? props.themeMap[theme] : undefined,
@@ -10,11 +10,9 @@ const uncontrollable_1 = require("uncontrollable");
10
10
  * Нужен для поддержки controlled/uncontrolled поведения, в зависимости от того были ли переданы входные аргументы
11
11
  */
12
12
  function useValueControl(_ref) {
13
- let {
14
- value,
15
- onChange,
16
- defaultValue
17
- } = _ref;
13
+ let value = _ref.value,
14
+ onChange = _ref.onChange,
15
+ defaultValue = _ref.defaultValue;
18
16
  return (0, uncontrollable_1.useUncontrolledProp)(value, defaultValue, newValue => {
19
17
  const newState = typeof newValue === 'function' ? newValue(value) : newValue;
20
18
  onChange === null || onChange === void 0 ? void 0 : onChange(newState);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Utils",
7
- "version": "4.0.2",
7
+ "version": "4.0.3-preview-fe85442f.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -34,10 +34,9 @@
34
34
  "./LICENSE"
35
35
  ],
36
36
  "license": "Apache-2.0",
37
- "scripts": {},
38
37
  "dependencies": {
39
- "react-swipeable": "7.0.2",
40
- "uncontrollable": "8.0.4"
38
+ "react-swipeable": "^7.0.2",
39
+ "uncontrollable": "^8.0.4"
41
40
  },
42
- "gitHead": "a9f6571146845d828e00206abdedb160980cff97"
43
- }
41
+ "scripts": {}
42
+ }