@alfalab/core-components-intl-phone-input 6.4.0 → 6.5.2

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 (79) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/{component-7d88f33a.d.ts → component-fbf58e08.d.ts} +0 -0
  3. package/dist/{component-7d88f33a.js → component-fbf58e08.js} +1 -1
  4. package/dist/component.d.ts +9 -0
  5. package/dist/component.js +133 -64
  6. package/dist/components/flag-icon/component.js +1 -1
  7. package/dist/components/flag-icon/index.css +261 -261
  8. package/dist/components/index.js +1 -1
  9. package/dist/components/select/component.js +2 -2
  10. package/dist/components/select/index.css +6 -6
  11. package/dist/components/select/index.js +1 -1
  12. package/dist/components/select-field/component.js +1 -1
  13. package/dist/components/select-field/index.css +8 -8
  14. package/dist/components/select-field/index.d.ts +1 -1
  15. package/dist/components/select-field/index.js +1 -1
  16. package/dist/cssm/component.d.ts +9 -0
  17. package/dist/cssm/component.js +131 -62
  18. package/dist/cssm/index.js +1 -1
  19. package/dist/cssm/{libphonenumber-js.min-d3a9d490.d.ts → libphonenumber-js.min-903db150.d.ts} +0 -0
  20. package/dist/cssm/libphonenumber-js.min-903db150.js +2227 -0
  21. package/dist/cssm/useCaretAvoidCountryCode.js +24 -20
  22. package/dist/cssm/utils/calculateCaretPos.d.ts +7 -0
  23. package/dist/cssm/utils/calculateCaretPos.js +27 -0
  24. package/dist/esm/{component-32da0c87.d.ts → component-25b3eb47.d.ts} +0 -0
  25. package/dist/esm/{component-32da0c87.js → component-25b3eb47.js} +1 -1
  26. package/dist/esm/component.d.ts +9 -0
  27. package/dist/esm/component.js +134 -65
  28. package/dist/esm/components/flag-icon/component.js +1 -1
  29. package/dist/esm/components/flag-icon/index.css +261 -261
  30. package/dist/esm/components/index.js +1 -1
  31. package/dist/esm/components/select/component.js +2 -2
  32. package/dist/esm/components/select/index.css +6 -6
  33. package/dist/esm/components/select/index.js +1 -1
  34. package/dist/esm/components/select-field/component.js +1 -1
  35. package/dist/esm/components/select-field/index.css +8 -8
  36. package/dist/esm/components/select-field/index.d.ts +1 -1
  37. package/dist/esm/components/select-field/index.js +1 -1
  38. package/dist/esm/index.css +3 -3
  39. package/dist/esm/index.js +2 -2
  40. package/dist/esm/{libphonenumber-js.min-c49027d7.d.ts → libphonenumber-js.min-24f2609b.d.ts} +0 -0
  41. package/dist/esm/libphonenumber-js.min-24f2609b.js +2225 -0
  42. package/dist/esm/useCaretAvoidCountryCode.js +25 -21
  43. package/dist/esm/utils/calculateCaretPos.d.ts +7 -0
  44. package/dist/esm/utils/calculateCaretPos.js +23 -0
  45. package/dist/index.css +3 -3
  46. package/dist/index.js +2 -2
  47. package/dist/{libphonenumber-js.min-13d3dc00.d.ts → libphonenumber-js.min-6d8f77f6.d.ts} +0 -0
  48. package/dist/libphonenumber-js.min-6d8f77f6.js +2227 -0
  49. package/dist/modern/component.d.ts +9 -0
  50. package/dist/modern/component.js +131 -61
  51. package/dist/modern/components/flag-icon/component.js +1 -1
  52. package/dist/modern/components/flag-icon/index.css +261 -261
  53. package/dist/modern/components/select/component.js +1 -1
  54. package/dist/modern/components/select/index.css +6 -6
  55. package/dist/modern/components/select-field/component.js +1 -1
  56. package/dist/modern/components/select-field/index.css +8 -8
  57. package/dist/modern/index.css +3 -3
  58. package/dist/modern/index.js +1 -1
  59. package/dist/modern/{libphonenumber-js.min-c49027d7.d.ts → libphonenumber-js.min-24f2609b.d.ts} +0 -0
  60. package/dist/modern/libphonenumber-js.min-24f2609b.js +2225 -0
  61. package/dist/modern/useCaretAvoidCountryCode.js +25 -21
  62. package/dist/modern/utils/calculateCaretPos.d.ts +7 -0
  63. package/dist/modern/utils/calculateCaretPos.js +23 -0
  64. package/dist/useCaretAvoidCountryCode.js +24 -20
  65. package/dist/utils/calculateCaretPos.d.ts +7 -0
  66. package/dist/utils/calculateCaretPos.js +27 -0
  67. package/package.json +6 -6
  68. package/dist/cssm/libphonenumber-js.min-d3a9d490.js +0 -1569
  69. package/dist/cssm/usePreventCaretReset.d.ts +0 -8
  70. package/dist/cssm/usePreventCaretReset.js +0 -36
  71. package/dist/esm/libphonenumber-js.min-c49027d7.js +0 -1567
  72. package/dist/esm/usePreventCaretReset.d.ts +0 -8
  73. package/dist/esm/usePreventCaretReset.js +0 -32
  74. package/dist/libphonenumber-js.min-13d3dc00.js +0 -1569
  75. package/dist/modern/libphonenumber-js.min-c49027d7.js +0 -1567
  76. package/dist/modern/usePreventCaretReset.d.ts +0 -8
  77. package/dist/modern/usePreventCaretReset.js +0 -31
  78. package/dist/usePreventCaretReset.d.ts +0 -8
  79. package/dist/usePreventCaretReset.js +0 -36
@@ -1,29 +1,33 @@
1
- import { useCallback, useEffect } from 'react';
1
+ import { useEffect } from 'react';
2
2
 
3
3
  function useCaretAvoidCountryCode(_a) {
4
4
  var inputRef = _a.inputRef, countryCodeLength = _a.countryCodeLength, clearableCountryCode = _a.clearableCountryCode;
5
- var input = inputRef.current;
6
- var moveCaretFromCountryCode = useCallback(function () {
7
- if (!input)
8
- return;
9
- var selectionStart = input.selectionStart || 0;
10
- if (selectionStart < countryCodeLength) {
11
- input.focus();
12
- input.setSelectionRange(countryCodeLength, countryCodeLength);
13
- }
14
- }, [input, countryCodeLength]);
15
- var preventCaretMovingOnCountryCode = useCallback(function (event) {
16
- if (!input)
17
- return;
18
- var selectionStart = input.selectionStart || 0;
19
- var toLeftKey = event.keyCode === 37;
20
- if (toLeftKey && selectionStart <= countryCodeLength) {
21
- event.preventDefault();
22
- }
23
- }, [input, countryCodeLength]);
24
5
  useEffect(function () {
6
+ var input = inputRef.current;
25
7
  if (!input || clearableCountryCode)
26
8
  return;
9
+ var moveCaretFromCountryCode = function () {
10
+ var selectionStart = input.selectionStart || 0;
11
+ if (selectionStart < countryCodeLength) {
12
+ input.focus();
13
+ input.setSelectionRange(countryCodeLength, countryCodeLength);
14
+ }
15
+ };
16
+ var preventCaretMovingOnCountryCode = function (event) {
17
+ var selectionStart = input.selectionStart || 0;
18
+ var toLeftKey = event.keyCode === 37;
19
+ if (toLeftKey) {
20
+ if (selectionStart <= countryCodeLength) {
21
+ event.preventDefault();
22
+ }
23
+ // Если нажали ctrl + arrowLeft, то восстанавливаем положение каретки.
24
+ if (event.metaKey || event.ctrlKey) {
25
+ requestAnimationFrame(function () {
26
+ moveCaretFromCountryCode();
27
+ });
28
+ }
29
+ }
30
+ };
27
31
  input.addEventListener('click', moveCaretFromCountryCode);
28
32
  input.addEventListener('keydown', preventCaretMovingOnCountryCode);
29
33
  // eslint-disable-next-line consistent-return
@@ -31,7 +35,7 @@ function useCaretAvoidCountryCode(_a) {
31
35
  input.removeEventListener('click', moveCaretFromCountryCode);
32
36
  input.removeEventListener('keydown', preventCaretMovingOnCountryCode);
33
37
  };
34
- }, [clearableCountryCode, input, preventCaretMovingOnCountryCode, moveCaretFromCountryCode]);
38
+ }, [clearableCountryCode, countryCodeLength, inputRef]);
35
39
  }
36
40
 
37
41
  export { useCaretAvoidCountryCode };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Расчет нового положения каретки.
3
+ * @param phonePart Шаблон с которым сравнивается новое значение. (Часть телефона без маски с учетом удаленных и добавленных цифр).
4
+ * @param newVal Новый отформатированный телефон.
5
+ */
6
+ declare function calculateCaretPos(phonePart: string, newVal: string): number;
7
+ export { calculateCaretPos };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Расчет нового положения каретки.
3
+ * @param phonePart Шаблон с которым сравнивается новое значение. (Часть телефона без маски с учетом удаленных и добавленных цифр).
4
+ * @param newVal Новый отформатированный телефон.
5
+ */
6
+ function calculateCaretPos(phonePart, newVal) {
7
+ var newCaretPosition = 0;
8
+ for (var idx = 0; idx < phonePart.length; idx++) {
9
+ var digit = phonePart.charAt(idx);
10
+ if (digit !== newVal.charAt(newCaretPosition)) {
11
+ idx -= 1;
12
+ }
13
+ newCaretPosition += 1;
14
+ // Если произошла непредвиденная ситуация, то прерываем цикл и ставим каретку в самый конец номера.
15
+ if (newCaretPosition > newVal.length) {
16
+ newCaretPosition = newVal.length;
17
+ break;
18
+ }
19
+ }
20
+ return newCaretPosition;
21
+ }
22
+
23
+ export { calculateCaretPos };
package/dist/index.css CHANGED
@@ -1,8 +1,8 @@
1
- /* hash: 1e4na */
2
- .intl-phone-input__addons_jc47s {
1
+ /* hash: qasyq */
2
+ .intl-phone-input__addons_rhr68 {
3
3
  padding-left: 0;
4
4
  }
5
5
 
6
- .intl-phone-input__l_jc47s .intl-phone-input__addons_jc47s, .intl-phone-input__xl_jc47s .intl-phone-input__addons_jc47s {
6
+ .intl-phone-input__l_rhr68 .intl-phone-input__addons_rhr68, .intl-phone-input__xl_rhr68 .intl-phone-input__addons_rhr68 {
7
7
  padding-left: 0;
8
8
  }
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('./component-7d88f33a.js');
5
+ require('./component-fbf58e08.js');
6
6
  require('react');
7
7
  require('classnames');
8
8
  require('@alfalab/utils');
@@ -13,8 +13,8 @@ require('./components/flag-icon/component.js');
13
13
  require('@alfalab/core-components-select');
14
14
  require('./components/select/component.js');
15
15
  require('./utils/format-phone-with-unclearable-country-code.js');
16
+ require('./utils/calculateCaretPos.js');
16
17
  require('./useCaretAvoidCountryCode.js');
17
- require('./usePreventCaretReset.js');
18
18
  var component = require('./component.js');
19
19
 
20
20