@megafon/ui-core 5.4.0 → 5.4.1

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
+ ## [5.4.1](https://hq-gitlab.megafon.ru/site-portal/services/megafon-ui/compare/@megafon/ui-core@5.4.0...@megafon/ui-core@5.4.1) (2023-11-27)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **search:** change index to correct one on mouse down to item in dropdown ([363e1bc](https://hq-gitlab.megafon.ru/site-portal/services/megafon-ui/commit/363e1bc43f884fecec1057e74f071ab1e9904e24))
12
+
13
+
14
+
15
+
16
+
6
17
  # [5.4.0](https://hq-gitlab.megafon.ru/site-portal/services/megafon-ui/compare/@megafon/ui-core@5.3.0...@megafon/ui-core@5.4.0) (2023-11-22)
7
18
 
8
19
 
@@ -9,10 +9,10 @@ import "core-js/modules/es.array.map.js";
9
9
  import "core-js/modules/es.object.values.js";
10
10
  import React from 'react';
11
11
  import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
12
+ import Preloader from "../Preloader/Preloader";
12
13
  import debounce from 'lodash.debounce';
13
14
  import * as PropTypes from 'prop-types';
14
15
  import "./Search.css";
15
- import Preloader from "../Preloader/Preloader";
16
16
 
17
17
  var SearchIcon16 = function SearchIcon16(props) {
18
18
  return /*#__PURE__*/React.createElement("svg", _extends({
@@ -131,11 +131,11 @@ var Search = function Search(_ref) {
131
131
  var chosenValue = items[index].value;
132
132
  onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(chosenValue);
133
133
  }, [disabled, items, onSubmit]);
134
- var handleSelectSubmit = React.useCallback(function () {
134
+ var handleSelectSubmit = React.useCallback(function (index) {
135
135
  return function () {
136
- handleItemSubmit(activeIndex);
136
+ handleItemSubmit(index);
137
137
  };
138
- }, [handleItemSubmit, activeIndex]);
138
+ }, [handleItemSubmit]);
139
139
  var handleFocus = React.useCallback(function (e) {
140
140
  setFocus(true);
141
141
  onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
@@ -6,7 +6,7 @@ var _DEFAULT_SNACKBARS;
6
6
 
7
7
  import "core-js/modules/web.timers.js";
8
8
  import "core-js/modules/es.object.values.js";
9
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
9
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
10
10
  import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
11
11
  import * as PropTypes from 'prop-types';
12
12
  import Button from "../Button/Button";
@@ -128,7 +128,10 @@ var Snackbar = function Snackbar(_ref) {
128
128
  isOpened = _useState2[0],
129
129
  setIsOpened = _useState2[1];
130
130
 
131
- var containerRef = useRef(null);
131
+ var _useState3 = useState(null),
132
+ _useState4 = _slicedToArray(_useState3, 2),
133
+ containerRef = _useState4[0],
134
+ setContainerRef = _useState4[1];
132
135
 
133
136
  var _useSwipe = useSwipe(containerRef),
134
137
  transform = _useSwipe.transform,
@@ -142,6 +145,11 @@ var Snackbar = function Snackbar(_ref) {
142
145
  var isHiddenIcon = isTimerType || !hasIcon && isInfoType;
143
146
  var isCustomIcon = isInfoType && icon;
144
147
  var currentButtonText = buttonText && !isTimerType ? buttonText : defaultSnackbar.buttonText;
148
+
149
+ var setRef = function setRef(instance) {
150
+ return setContainerRef(instance);
151
+ };
152
+
145
153
  var handleClose = useCallback(function () {
146
154
  setIsOpened(false);
147
155
  }, []);
@@ -191,10 +199,10 @@ var Snackbar = function Snackbar(_ref) {
191
199
  className: cn({
192
200
  move: isTransitionMoveStep
193
201
  }, [className, classes.root]),
194
- ref: containerRef,
195
- style: {
202
+ ref: setRef,
203
+ style: transform !== 'none' ? {
196
204
  transform: transform
197
- }
205
+ } : undefined
198
206
  }, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root)), /*#__PURE__*/React.createElement(Tile, {
199
207
  className: cn('tile', {
200
208
  type: type,
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  export declare enum TransitionSteps {
3
2
  INITIAL_STEP = "initial-step",
4
3
  MOVE_STEP = "move-step",
@@ -10,5 +9,5 @@ declare type UseSwipeReturnType = {
10
9
  /** Текущий этап смахивания элемента */
11
10
  transitionStep: TransitionSteps;
12
11
  };
13
- declare function useSwipe(element: React.MutableRefObject<null>): UseSwipeReturnType;
12
+ declare function useSwipe(element: HTMLElement | null): UseSwipeReturnType;
14
13
  export default useSwipe;
@@ -1,4 +1,9 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import "core-js/modules/es.regexp.exec.js";
3
+ import "core-js/modules/es.string.match.js";
4
+ import "core-js/modules/es.string.split.js";
5
+ import "core-js/modules/es.number.is-nan.js";
6
+ import "core-js/modules/es.number.constructor.js";
2
7
  import * as React from 'react';
3
8
  import useResolution from "./useResolution";
4
9
  export var TransitionSteps;
@@ -31,14 +36,17 @@ function useSwipe(element) {
31
36
  setTransform = _React$useState6[1];
32
37
 
33
38
  var animationFrameId = React.useRef(0);
34
- var currentElement = element.current;
39
+ var currentElement = element;
35
40
  var isTransitionMoveStep = transitionStep === TransitionSteps.MOVE_STEP;
41
+ var currentTransform = currentElement ? getComputedStyle(currentElement).transform : '';
36
42
  var handleWindowTouchMove = React.useCallback(function (e) {
37
43
  if (animationFrameId) {
38
44
  window.cancelAnimationFrame(animationFrameId.current);
39
45
  }
40
46
 
41
47
  animationFrameId.current = window.requestAnimationFrame(function () {
48
+ var _a;
49
+
42
50
  setTransitionStep(TransitionSteps.MOVE_STEP);
43
51
 
44
52
  if (!currentElement) {
@@ -51,10 +59,12 @@ function useSwipe(element) {
51
59
  }
52
60
 
53
61
  var positionsDiff = initialTouchPosition - e.touches[0].clientX;
54
- positionsDiff !== 0 && setTransform("translateX(".concat(-positionsDiff, "px)"));
62
+ var values = !!currentTransform && currentTransform !== 'none' ? (_a = currentTransform.match(/\(((?:[0-9][,\s]*)+)\)/)) === null || _a === void 0 ? void 0 : _a[0].split(', ') : undefined;
63
+ var currentTranslateX = !values || Number.isNaN(Number(values === null || values === void 0 ? void 0 : values[4])) ? 0 : Number(values === null || values === void 0 ? void 0 : values[4]);
64
+ positionsDiff !== 0 && setTransform("translateX(".concat(currentTranslateX - positionsDiff, "px)"));
55
65
  animationFrameId.current = 0;
56
66
  });
57
- }, [currentElement, animationFrameId, initialTouchPosition]);
67
+ }, [currentElement, animationFrameId, initialTouchPosition, currentTransform]);
58
68
  var handleWindowTouchEnd = React.useCallback(function (e) {
59
69
  var _a;
60
70
 
@@ -93,16 +103,23 @@ function useSwipe(element) {
93
103
  }
94
104
  }, [currentElement, isTransitionMoveStep, initialTouchPosition, animationFrameId]);
95
105
  React.useEffect(function () {
96
- if (isMobile) {
97
- window.addEventListener('touchmove', handleWindowTouchMove);
98
- window.addEventListener('touchend', handleWindowTouchEnd);
106
+ if (!isMobile || !currentElement) {
107
+ return;
99
108
  }
100
109
 
110
+ currentElement.addEventListener('touchmove', handleWindowTouchMove);
111
+ currentElement.addEventListener('touchend', handleWindowTouchEnd);
112
+ /* eslint-disable-next-line consistent-return */
113
+
101
114
  return function () {
102
- window.removeEventListener('touchmove', handleWindowTouchMove);
103
- window.removeEventListener('touchend', handleWindowTouchEnd);
115
+ if (!currentElement) {
116
+ return;
117
+ }
118
+
119
+ currentElement.removeEventListener('touchmove', handleWindowTouchMove);
120
+ currentElement.removeEventListener('touchend', handleWindowTouchEnd);
104
121
  };
105
- }, [isMobile, handleWindowTouchMove, handleWindowTouchEnd]);
122
+ }, [isMobile, handleWindowTouchMove, handleWindowTouchEnd, currentElement]);
106
123
  return {
107
124
  transform: transform,
108
125
  transitionStep: transitionStep
@@ -29,12 +29,12 @@ var _react = _interopRequireDefault(require("react"));
29
29
 
30
30
  var _uiHelpers = require("@megafon/ui-helpers");
31
31
 
32
+ var _Preloader = _interopRequireDefault(require("../Preloader/Preloader"));
33
+
32
34
  var _lodash = _interopRequireDefault(require("lodash.debounce"));
33
35
 
34
36
  var PropTypes = _interopRequireWildcard(require("prop-types"));
35
37
 
36
- var _Preloader = _interopRequireDefault(require("../Preloader/Preloader"));
37
-
38
38
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
39
39
 
40
40
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -168,11 +168,11 @@ var Search = function Search(_ref) {
168
168
  onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(chosenValue);
169
169
  }, [disabled, items, onSubmit]);
170
170
 
171
- var handleSelectSubmit = _react["default"].useCallback(function () {
171
+ var handleSelectSubmit = _react["default"].useCallback(function (index) {
172
172
  return function () {
173
- handleItemSubmit(activeIndex);
173
+ handleItemSubmit(index);
174
174
  };
175
- }, [handleItemSubmit, activeIndex]);
175
+ }, [handleItemSubmit]);
176
176
 
177
177
  var handleFocus = _react["default"].useCallback(function (e) {
178
178
  setFocus(true);
@@ -155,7 +155,10 @@ var Snackbar = function Snackbar(_ref) {
155
155
  isOpened = _useState2[0],
156
156
  setIsOpened = _useState2[1];
157
157
 
158
- var containerRef = (0, _react.useRef)(null);
158
+ var _useState3 = (0, _react.useState)(null),
159
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
160
+ containerRef = _useState4[0],
161
+ setContainerRef = _useState4[1];
159
162
 
160
163
  var _useSwipe = (0, _useSwipe2["default"])(containerRef),
161
164
  transform = _useSwipe.transform,
@@ -169,6 +172,11 @@ var Snackbar = function Snackbar(_ref) {
169
172
  var isHiddenIcon = isTimerType || !hasIcon && isInfoType;
170
173
  var isCustomIcon = isInfoType && icon;
171
174
  var currentButtonText = buttonText && !isTimerType ? buttonText : defaultSnackbar.buttonText;
175
+
176
+ var setRef = function setRef(instance) {
177
+ return setContainerRef(instance);
178
+ };
179
+
172
180
  var handleClose = (0, _react.useCallback)(function () {
173
181
  setIsOpened(false);
174
182
  }, []);
@@ -218,10 +226,10 @@ var Snackbar = function Snackbar(_ref) {
218
226
  className: cn({
219
227
  move: isTransitionMoveStep
220
228
  }, [className, classes.root]),
221
- ref: containerRef,
222
- style: {
229
+ ref: setRef,
230
+ style: transform !== 'none' ? {
223
231
  transform: transform
224
- }
232
+ } : undefined
225
233
  }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root)), /*#__PURE__*/_react["default"].createElement(_Tile["default"], {
226
234
  className: cn('tile', {
227
235
  type: type,
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  export declare enum TransitionSteps {
3
2
  INITIAL_STEP = "initial-step",
4
3
  MOVE_STEP = "move-step",
@@ -10,5 +9,5 @@ declare type UseSwipeReturnType = {
10
9
  /** Текущий этап смахивания элемента */
11
10
  transitionStep: TransitionSteps;
12
11
  };
13
- declare function useSwipe(element: React.MutableRefObject<null>): UseSwipeReturnType;
12
+ declare function useSwipe(element: HTMLElement | null): UseSwipeReturnType;
14
13
  export default useSwipe;
@@ -9,6 +9,16 @@ exports["default"] = exports.TransitionSteps = void 0;
9
9
 
10
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
11
 
12
+ require("core-js/modules/es.regexp.exec.js");
13
+
14
+ require("core-js/modules/es.string.match.js");
15
+
16
+ require("core-js/modules/es.string.split.js");
17
+
18
+ require("core-js/modules/es.number.is-nan.js");
19
+
20
+ require("core-js/modules/es.number.constructor.js");
21
+
12
22
  var React = _interopRequireWildcard(require("react"));
13
23
 
14
24
  var _useResolution2 = _interopRequireDefault(require("./useResolution"));
@@ -50,14 +60,17 @@ function useSwipe(element) {
50
60
  setTransform = _React$useState6[1];
51
61
 
52
62
  var animationFrameId = React.useRef(0);
53
- var currentElement = element.current;
63
+ var currentElement = element;
54
64
  var isTransitionMoveStep = transitionStep === TransitionSteps.MOVE_STEP;
65
+ var currentTransform = currentElement ? getComputedStyle(currentElement).transform : '';
55
66
  var handleWindowTouchMove = React.useCallback(function (e) {
56
67
  if (animationFrameId) {
57
68
  window.cancelAnimationFrame(animationFrameId.current);
58
69
  }
59
70
 
60
71
  animationFrameId.current = window.requestAnimationFrame(function () {
72
+ var _a;
73
+
61
74
  setTransitionStep(TransitionSteps.MOVE_STEP);
62
75
 
63
76
  if (!currentElement) {
@@ -70,10 +83,12 @@ function useSwipe(element) {
70
83
  }
71
84
 
72
85
  var positionsDiff = initialTouchPosition - e.touches[0].clientX;
73
- positionsDiff !== 0 && setTransform("translateX(".concat(-positionsDiff, "px)"));
86
+ var values = !!currentTransform && currentTransform !== 'none' ? (_a = currentTransform.match(/\(((?:[0-9][,\s]*)+)\)/)) === null || _a === void 0 ? void 0 : _a[0].split(', ') : undefined;
87
+ var currentTranslateX = !values || Number.isNaN(Number(values === null || values === void 0 ? void 0 : values[4])) ? 0 : Number(values === null || values === void 0 ? void 0 : values[4]);
88
+ positionsDiff !== 0 && setTransform("translateX(".concat(currentTranslateX - positionsDiff, "px)"));
74
89
  animationFrameId.current = 0;
75
90
  });
76
- }, [currentElement, animationFrameId, initialTouchPosition]);
91
+ }, [currentElement, animationFrameId, initialTouchPosition, currentTransform]);
77
92
  var handleWindowTouchEnd = React.useCallback(function (e) {
78
93
  var _a;
79
94
 
@@ -112,16 +127,23 @@ function useSwipe(element) {
112
127
  }
113
128
  }, [currentElement, isTransitionMoveStep, initialTouchPosition, animationFrameId]);
114
129
  React.useEffect(function () {
115
- if (isMobile) {
116
- window.addEventListener('touchmove', handleWindowTouchMove);
117
- window.addEventListener('touchend', handleWindowTouchEnd);
130
+ if (!isMobile || !currentElement) {
131
+ return;
118
132
  }
119
133
 
134
+ currentElement.addEventListener('touchmove', handleWindowTouchMove);
135
+ currentElement.addEventListener('touchend', handleWindowTouchEnd);
136
+ /* eslint-disable-next-line consistent-return */
137
+
120
138
  return function () {
121
- window.removeEventListener('touchmove', handleWindowTouchMove);
122
- window.removeEventListener('touchend', handleWindowTouchEnd);
139
+ if (!currentElement) {
140
+ return;
141
+ }
142
+
143
+ currentElement.removeEventListener('touchmove', handleWindowTouchMove);
144
+ currentElement.removeEventListener('touchend', handleWindowTouchEnd);
123
145
  };
124
- }, [isMobile, handleWindowTouchMove, handleWindowTouchEnd]);
146
+ }, [isMobile, handleWindowTouchMove, handleWindowTouchEnd, currentElement]);
125
147
  return {
126
148
  transform: transform,
127
149
  transitionStep: transitionStep
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megafon/ui-core",
3
- "version": "5.4.0",
3
+ "version": "5.4.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "styles"
@@ -96,5 +96,5 @@
96
96
  "react-popper": "^2.2.3",
97
97
  "swiper": "^6.5.6"
98
98
  },
99
- "gitHead": "e78c7c397c514016ee74020939dc3807e09bf49a"
99
+ "gitHead": "d65bc4cd4de9180971e4285c2d0b5beec27d0542"
100
100
  }