@via-profit/ui-kit 0.2.1-alpha.3 → 0.2.3

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 (42) hide show
  1. package/Autocomplete/AutocompleteContainer.d.ts +5 -4
  2. package/Autocomplete/AutocompleteContainer.js +146 -152
  3. package/Autocomplete/AutocompleteItem.js +1 -1
  4. package/Autocomplete/context.d.ts +3 -5
  5. package/Autocomplete/context.js +22 -14
  6. package/CountryFlags/SwiperOverview.d.ts +257 -0
  7. package/CountryFlags/SwiperOverview.js +524 -0
  8. package/Highlighted/index.js +10 -5
  9. package/Highlighted/splitTextIntoParts.d.ts +5 -0
  10. package/Highlighted/splitTextIntoParts.js +46 -0
  11. package/MaskedField/index.d.ts +1 -0
  12. package/MaskedField/index.js +44 -36
  13. package/MaskedField/useMasked.js +7 -5
  14. package/Menu/MenuContainer.d.ts +24 -2
  15. package/Menu/MenuContainer.js +194 -243
  16. package/Menu/MenuList.d.ts +1 -0
  17. package/Menu/MenuList.js +15 -16
  18. package/Popper/Popper.d.ts +3 -2
  19. package/Popper/Popper.js +9 -7
  20. package/Popper/PopperContainer.d.ts +0 -1
  21. package/Popper/PopperContainer.js +8 -3
  22. package/Popper/index.d.ts +1 -1
  23. package/Popper/index.js +1 -1
  24. package/Popper/usePopper.d.ts +111 -0
  25. package/Popper/usePopper.js +522 -0
  26. package/Selectbox/SelectboxButton.js +2 -27
  27. package/Selectbox/SelectboxMenu.d.ts +0 -2
  28. package/Selectbox/SelectboxMenu.js +13 -5
  29. package/Selectbox/index.d.ts +5 -3
  30. package/Selectbox/index.js +4 -4
  31. package/Swiper/Swiper.d.ts +28 -17
  32. package/Swiper/Swiper.js +294 -38
  33. package/Swiper/SwiperContainer.d.ts +3 -3
  34. package/Swiper/SwiperContainer.js +1 -0
  35. package/Swiper/SwiperSlide.d.ts +10 -5
  36. package/Swiper/SwiperSlide.js +6 -3
  37. package/Swiper/SwiperSlidesRenderer.d.ts +11 -0
  38. package/Swiper/SwiperSlidesRenderer.js +74 -0
  39. package/Swiper/SwiperTrack.d.ts +4 -0
  40. package/Swiper/SwiperTrack.js +4 -7
  41. package/Swiper/SwiperWrapper.d.ts +2 -0
  42. package/package.json +1 -1
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  var __rest = (this && this.__rest) || function (s, e) {
3
17
  var t = {};
4
18
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -17,61 +31,55 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
31
  const react_1 = __importDefault(require("react"));
18
32
  const useMasked_1 = require("./useMasked");
19
33
  const TextField_1 = __importDefault(require("../TextField"));
34
+ __exportStar(require("./useMasked"), exports);
20
35
  const MaskedField = (props, ref) => {
21
36
  const { value: propValue, mask, parseInput, onChange, transform } = props, nativeProps = __rest(props, ["value", "mask", "parseInput", "onChange", "transform"]);
22
- const propValueRef = react_1.default.useRef(propValue);
23
- const textInputRef = react_1.default.useRef(null);
24
- const decoratorsErrorDisplayed = react_1.default.useRef(false);
25
37
  const masked = (0, useMasked_1.useMasked)();
26
38
  const parseInputFn = parseInput || masked.parseInput;
27
- const getMask = react_1.default.useCallback((input) => {
28
- const currentMask = typeof mask === 'function' ? mask(input) : mask;
29
- if (!decoratorsErrorDisplayed.current &&
30
- currentMask.find(elem => typeof elem === 'string' &&
31
- typeof parseInput === 'undefined' &&
32
- elem.match(/[0-9a-zа-яё]/i))) {
33
- decoratorsErrorDisplayed.current = true;
34
- console.warn('[MaskedField component] You use symbols as decorators, which should be replaced with RegExp or provide the «parseInput» function instead');
35
- }
36
- return currentMask;
37
- }, [mask, parseInput]);
39
+ const inputRef = react_1.default.useRef(null);
40
+ const lastPropValue = react_1.default.useRef(propValue);
41
+ const getMask = react_1.default.useCallback((input) => (typeof mask === 'function' ? mask(input) : mask), [mask]);
38
42
  const getInputValue = react_1.default.useCallback((v) => {
39
43
  var _a;
40
- const mask = getMask(v || '');
41
- const parsed = parseInputFn(v || '', mask, ((_a = textInputRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) || 0);
42
- const { text } = masked.formatParsedInput(parsed.text, mask, parsed.caret);
43
- return text;
44
- }, [getMask, masked, parseInputFn]);
44
+ const m = getMask(v);
45
+ const parsed = parseInputFn(v, m, ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) || 0);
46
+ const formatted = masked.formatParsedInput(parsed.text, m, parsed.caret);
47
+ return formatted.text;
48
+ }, [getMask, parseInputFn, masked]);
45
49
  const [inputValue, setInputValue] = react_1.default.useState(getInputValue(propValue || ''));
50
+ // Обновление при изменении внешнего значения
46
51
  react_1.default.useEffect(() => {
47
- if (propValueRef.current !== propValue) {
48
- propValueRef.current = propValue;
52
+ if (lastPropValue.current !== propValue) {
53
+ lastPropValue.current = propValue;
49
54
  setInputValue(getInputValue(propValue || ''));
50
55
  }
51
- }, [getInputValue, getMask, parseInputFn, masked, propValue]);
56
+ }, [propValue, getInputValue]);
52
57
  const handleOnChange = react_1.default.useCallback(event => {
53
58
  var _a;
54
- const mask = getMask(event.currentTarget.value);
55
- const parsed = parseInputFn(event.currentTarget.value, mask, ((_a = textInputRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) || 0);
56
- const { caret, isValid, text } = masked.formatParsedInput(parsed.text, mask, parsed.caret);
57
- const transformedText = transform ? transform(text) : text;
58
- setInputValue(transformedText);
59
+ const raw = event.currentTarget.value;
60
+ const caret = ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) || 0;
61
+ const m = getMask(raw);
62
+ const parsed = parseInputFn(raw, m, caret);
63
+ const formatted = masked.formatParsedInput(parsed.text, m, parsed.caret);
64
+ const finalText = transform ? transform(formatted.text) : formatted.text;
65
+ setInputValue(finalText);
59
66
  onChange({
60
- caret,
61
- isValid,
62
- text: transformedText,
67
+ caret: formatted.caret,
68
+ isValid: formatted.isValid,
69
+ text: finalText,
63
70
  });
64
- setTimeout(() => {
71
+ // Устанавливаем caret после рендера
72
+ requestAnimationFrame(() => {
65
73
  var _a;
66
- (_a = textInputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(caret, caret);
67
- }, 15);
68
- }, [getMask, masked, transform, onChange, parseInputFn]);
74
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(formatted.caret, formatted.caret);
75
+ });
76
+ }, [getMask, parseInputFn, masked, transform, onChange]);
69
77
  const setInputRef = react_1.default.useCallback((elem) => {
70
- textInputRef.current = elem;
78
+ inputRef.current = elem;
71
79
  if (typeof nativeProps.inputRef === 'function') {
72
80
  nativeProps.inputRef(elem);
73
81
  }
74
- if (nativeProps.inputRef !== null && typeof nativeProps.inputRef === 'object') {
82
+ else if (nativeProps.inputRef && typeof nativeProps.inputRef === 'object') {
75
83
  nativeProps.inputRef.current = elem;
76
84
  }
77
85
  }, [nativeProps]);
@@ -12,13 +12,12 @@ const useMasked = () => {
12
12
  caret: 0,
13
13
  };
14
14
  value
15
- .replace(/\s/, '')
15
+ .replace(/\s+/g, '')
16
16
  .split('')
17
17
  .forEach((character, charIndex) => {
18
18
  const isMatch = mask.some(pattern => {
19
19
  if (typeof pattern === 'string') {
20
- return false;
21
- // return character === pattern && character;
20
+ return character === pattern && character;
22
21
  }
23
22
  if (pattern instanceof RegExp) {
24
23
  return new RegExp(pattern).test(character);
@@ -45,7 +44,9 @@ const useMasked = () => {
45
44
  if (parsedValue === '') {
46
45
  return data;
47
46
  }
48
- for (let patternIndex = 0; patternIndex < mask.length; patternIndex++) {
47
+ let patternIndex = 0;
48
+ for (patternIndex = 0; patternIndex < mask.length; patternIndex++) {
49
+ data.isValid = false;
49
50
  if (data.charIndex >= parsedValue.length) {
50
51
  break;
51
52
  }
@@ -57,6 +58,7 @@ const useMasked = () => {
57
58
  if (pattern instanceof RegExp && new RegExp(pattern).test(char)) {
58
59
  data.text = `${data.text}${char}`;
59
60
  data.charIndex += 1;
61
+ data.isValid = true;
60
62
  }
61
63
  // If char is correct (equal with pattern string)
62
64
  // then accept char into text
@@ -79,7 +81,7 @@ const useMasked = () => {
79
81
  const result = {
80
82
  text: data.text,
81
83
  caret: data.caret,
82
- isValid: data.text.length >= mask.length,
84
+ isValid: data.isValid,
83
85
  };
84
86
  return result;
85
87
  }, []);
@@ -90,6 +90,7 @@ export interface MenuProps<T, Multiple extends boolean | undefined = undefined>
90
90
  * Default: `bottom`
91
91
  */
92
92
  readonly anchorPos?: AnchorPos;
93
+ readonly alternativePlacements?: readonly AnchorPos[];
93
94
  readonly onAnchorPosChanged?: (anchorPos: AnchorPos) => void;
94
95
  /**
95
96
  * When enabled, the popper will automatically try to find the best placement
@@ -164,6 +165,28 @@ export interface MenuProps<T, Multiple extends boolean | undefined = undefined>
164
165
  * The function that will be called at the moment when you want to close the menu
165
166
  */
166
167
  readonly onRequestClose?: OnRequestClose;
168
+ /**
169
+ * List menu maximum width (px, em, etc.)\
170
+ * Using pixels:
171
+ * ```tsx
172
+ * <Menu
173
+ * maxWidth={250}
174
+ * >
175
+ * ```
176
+ * Using em:
177
+ * ```tsx
178
+ * <Menu
179
+ * maxWidth="16em"
180
+ * >
181
+ * ```
182
+ * Using pixels:
183
+ * ```tsx
184
+ * <Menu
185
+ * maxWidth="16px"
186
+ * >
187
+ * ```
188
+ */
189
+ readonly maxWidth?: number | string;
167
190
  }
168
191
  export interface MenuOverrides {
169
192
  /**
@@ -220,9 +243,8 @@ export type MenuRef = {
220
243
  * Returns the list HTML container
221
244
  */
222
245
  getListElement: () => HTMLDivElement | null;
223
- setActualPlacement: (placement: AnchorPos) => void;
224
246
  };
225
- export type Value<T, Multiple> = Multiple extends undefined | undefined ? T | null : readonly T[];
247
+ export type Value<T, Multiple> = Multiple extends undefined ? T | null : readonly T[];
226
248
  export type GetOptionSelected<T> = (payload: {
227
249
  readonly item: T;
228
250
  readonly value: T;