@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.
- package/CHANGELOG.md +35 -0
- package/dist/{component-7d88f33a.d.ts → component-fbf58e08.d.ts} +0 -0
- package/dist/{component-7d88f33a.js → component-fbf58e08.js} +1 -1
- package/dist/component.d.ts +9 -0
- package/dist/component.js +133 -64
- package/dist/components/flag-icon/component.js +1 -1
- package/dist/components/flag-icon/index.css +261 -261
- package/dist/components/index.js +1 -1
- package/dist/components/select/component.js +2 -2
- package/dist/components/select/index.css +6 -6
- package/dist/components/select/index.js +1 -1
- package/dist/components/select-field/component.js +1 -1
- package/dist/components/select-field/index.css +8 -8
- package/dist/components/select-field/index.d.ts +1 -1
- package/dist/components/select-field/index.js +1 -1
- package/dist/cssm/component.d.ts +9 -0
- package/dist/cssm/component.js +131 -62
- package/dist/cssm/index.js +1 -1
- package/dist/cssm/{libphonenumber-js.min-d3a9d490.d.ts → libphonenumber-js.min-903db150.d.ts} +0 -0
- package/dist/cssm/libphonenumber-js.min-903db150.js +2227 -0
- package/dist/cssm/useCaretAvoidCountryCode.js +24 -20
- package/dist/cssm/utils/calculateCaretPos.d.ts +7 -0
- package/dist/cssm/utils/calculateCaretPos.js +27 -0
- package/dist/esm/{component-32da0c87.d.ts → component-25b3eb47.d.ts} +0 -0
- package/dist/esm/{component-32da0c87.js → component-25b3eb47.js} +1 -1
- package/dist/esm/component.d.ts +9 -0
- package/dist/esm/component.js +134 -65
- package/dist/esm/components/flag-icon/component.js +1 -1
- package/dist/esm/components/flag-icon/index.css +261 -261
- package/dist/esm/components/index.js +1 -1
- package/dist/esm/components/select/component.js +2 -2
- package/dist/esm/components/select/index.css +6 -6
- package/dist/esm/components/select/index.js +1 -1
- package/dist/esm/components/select-field/component.js +1 -1
- package/dist/esm/components/select-field/index.css +8 -8
- package/dist/esm/components/select-field/index.d.ts +1 -1
- package/dist/esm/components/select-field/index.js +1 -1
- package/dist/esm/index.css +3 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/{libphonenumber-js.min-c49027d7.d.ts → libphonenumber-js.min-24f2609b.d.ts} +0 -0
- package/dist/esm/libphonenumber-js.min-24f2609b.js +2225 -0
- package/dist/esm/useCaretAvoidCountryCode.js +25 -21
- package/dist/esm/utils/calculateCaretPos.d.ts +7 -0
- package/dist/esm/utils/calculateCaretPos.js +23 -0
- package/dist/index.css +3 -3
- package/dist/index.js +2 -2
- package/dist/{libphonenumber-js.min-13d3dc00.d.ts → libphonenumber-js.min-6d8f77f6.d.ts} +0 -0
- package/dist/libphonenumber-js.min-6d8f77f6.js +2227 -0
- package/dist/modern/component.d.ts +9 -0
- package/dist/modern/component.js +131 -61
- package/dist/modern/components/flag-icon/component.js +1 -1
- package/dist/modern/components/flag-icon/index.css +261 -261
- package/dist/modern/components/select/component.js +1 -1
- package/dist/modern/components/select/index.css +6 -6
- package/dist/modern/components/select-field/component.js +1 -1
- package/dist/modern/components/select-field/index.css +8 -8
- package/dist/modern/index.css +3 -3
- package/dist/modern/index.js +1 -1
- package/dist/modern/{libphonenumber-js.min-c49027d7.d.ts → libphonenumber-js.min-24f2609b.d.ts} +0 -0
- package/dist/modern/libphonenumber-js.min-24f2609b.js +2225 -0
- package/dist/modern/useCaretAvoidCountryCode.js +25 -21
- package/dist/modern/utils/calculateCaretPos.d.ts +7 -0
- package/dist/modern/utils/calculateCaretPos.js +23 -0
- package/dist/useCaretAvoidCountryCode.js +24 -20
- package/dist/utils/calculateCaretPos.d.ts +7 -0
- package/dist/utils/calculateCaretPos.js +27 -0
- package/package.json +6 -6
- package/dist/cssm/libphonenumber-js.min-d3a9d490.js +0 -1569
- package/dist/cssm/usePreventCaretReset.d.ts +0 -8
- package/dist/cssm/usePreventCaretReset.js +0 -36
- package/dist/esm/libphonenumber-js.min-c49027d7.js +0 -1567
- package/dist/esm/usePreventCaretReset.d.ts +0 -8
- package/dist/esm/usePreventCaretReset.js +0 -32
- package/dist/libphonenumber-js.min-13d3dc00.js +0 -1569
- package/dist/modern/libphonenumber-js.min-c49027d7.js +0 -1567
- package/dist/modern/usePreventCaretReset.d.ts +0 -8
- package/dist/modern/usePreventCaretReset.js +0 -31
- package/dist/usePreventCaretReset.d.ts +0 -8
- package/dist/usePreventCaretReset.js +0 -36
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
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:
|
|
2
|
-
.intl-phone-
|
|
1
|
+
/* hash: qasyq */
|
|
2
|
+
.intl-phone-input__addons_rhr68 {
|
|
3
3
|
padding-left: 0;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
.intl-phone-
|
|
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-
|
|
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
|
|
|
File without changes
|