@invoicebox/ui 0.1.0-alpha.197 → 0.1.0-alpha.199
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/dist/components/form/CodeInput/index.stories.js +9 -10
- package/dist/components/form/PhoneInput/constants.d.ts +1 -1
- package/dist/components/form/PhoneInput/constants.js +68 -66
- package/dist/components/form/PhoneInput/externalPhoneLogic.d.ts +2 -2
- package/dist/components/form/PhoneInput/externalPhoneLogic.js +10 -9
- package/dist/components/form/PhoneInput/hooks/useValidateInitialValue.d.ts +2 -1
- package/dist/components/form/PhoneInput/hooks/useValidateInitialValue.js +4 -6
- package/dist/components/form/PhoneInput/index.d.ts +1 -0
- package/dist/components/form/PhoneInput/index.js +24 -19
- package/dist/components/form/PhoneInput/index.stories.js +2 -1
- package/dist/components/form/PhoneInput/phoneInputLogic.d.ts +5 -3
- package/dist/components/form/PhoneInput/phoneInputLogic.js +24 -14
- package/dist/components/form/PureInput/index.stories.js +2 -1
- package/dist/components/form/TextInput/index.stories.js +2 -1
- package/package.json +1 -1
|
@@ -27,19 +27,18 @@ var meta = {
|
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
var _default = exports["default"] = meta;
|
|
30
|
+
var COMMON_ARGS = {
|
|
31
|
+
hasError: false,
|
|
32
|
+
codeLength: 4,
|
|
33
|
+
value: '12',
|
|
34
|
+
disabled: false,
|
|
35
|
+
autoFocus: true
|
|
36
|
+
};
|
|
30
37
|
var Default = exports.Default = {
|
|
31
|
-
args:
|
|
32
|
-
hasError: false,
|
|
33
|
-
codeLength: 4,
|
|
34
|
-
value: '12',
|
|
35
|
-
disabled: false
|
|
36
|
-
}
|
|
38
|
+
args: COMMON_ARGS
|
|
37
39
|
};
|
|
38
40
|
var Live = exports.Live = {
|
|
39
|
-
args:
|
|
40
|
-
hasError: false,
|
|
41
|
-
codeLength: 4
|
|
42
|
-
},
|
|
41
|
+
args: COMMON_ARGS,
|
|
43
42
|
render: function Render(args) {
|
|
44
43
|
var _useState = (0, _react.useState)(''),
|
|
45
44
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { TCountryRule, TSupportedCountries } from './types';
|
|
2
2
|
export declare const MASK_DIGIT_ITEM = "9";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const getAllCountriesPhoneRules: (isSupportCityRusPhoneNumber: boolean) => Record<TSupportedCountries, TCountryRule>;
|
|
@@ -3,71 +3,73 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.getAllCountriesPhoneRules = exports.MASK_DIGIT_ITEM = void 0;
|
|
7
7
|
var MASK_DIGIT_ITEM = exports.MASK_DIGIT_ITEM = '9';
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
8
|
+
var getAllCountriesPhoneRules = exports.getAllCountriesPhoneRules = function getAllCountriesPhoneRules(isSupportCityRusPhoneNumber) {
|
|
9
|
+
return {
|
|
10
|
+
BLR: {
|
|
11
|
+
placeholder: '+375 XX XXX-XX-XX',
|
|
12
|
+
mask: '+999 99 999-99-99',
|
|
13
|
+
startSubsequence: '375',
|
|
14
|
+
regexp: /^(\+?375)?(24|25|29|33|44)\d{7}$/,
|
|
15
|
+
flag: 'BLR'
|
|
16
|
+
},
|
|
17
|
+
AZE: {
|
|
18
|
+
placeholder: '+994 (XX) XXX-XXXX',
|
|
19
|
+
mask: '+999 (99) 999-9999',
|
|
20
|
+
startSubsequence: '994',
|
|
21
|
+
regexp: /^\+?994\d{9}$/,
|
|
22
|
+
flag: 'AZE'
|
|
23
|
+
},
|
|
24
|
+
ARM: {
|
|
25
|
+
placeholder: '+374 (XX) XXX-XXX',
|
|
26
|
+
mask: '+999 (99) 999-999',
|
|
27
|
+
startSubsequence: '374',
|
|
28
|
+
regexp: /\+?374\d{8}/,
|
|
29
|
+
flag: 'ARM'
|
|
30
|
+
},
|
|
31
|
+
KAZ: {
|
|
32
|
+
placeholder: '+7 (XXX) XXX-XX-XX',
|
|
33
|
+
mask: '+9 (999) 999-99-99',
|
|
34
|
+
startSubsequence: '77',
|
|
35
|
+
regexp: /^77\d{9}$/,
|
|
36
|
+
flag: 'KAZ'
|
|
37
|
+
},
|
|
38
|
+
RUS: {
|
|
39
|
+
placeholder: '+7 (XXX) XXX-XX-XX',
|
|
40
|
+
mask: '+9 (999) 999-99-99',
|
|
41
|
+
startSubsequence: '7',
|
|
42
|
+
regexp: isSupportCityRusPhoneNumber ? /^7\d{10}$/ : /^\+?7(9\d{9})$/,
|
|
43
|
+
flag: 'RUS'
|
|
44
|
+
},
|
|
45
|
+
KGZ: {
|
|
46
|
+
placeholder: '+996 XXX-XX-XX-XX',
|
|
47
|
+
mask: '+999 999-99-99-99',
|
|
48
|
+
startSubsequence: '996',
|
|
49
|
+
regexp: /\+?996\d{9}/,
|
|
50
|
+
flag: 'KGZ'
|
|
51
|
+
},
|
|
52
|
+
TJK: {
|
|
53
|
+
placeholder: '+992-XX-XXX-XXXX',
|
|
54
|
+
mask: '+999-99-999-9999',
|
|
55
|
+
startSubsequence: '992',
|
|
56
|
+
regexp: /^\+?992\d{9}$/,
|
|
57
|
+
flag: 'TJK'
|
|
58
|
+
},
|
|
59
|
+
UZB: {
|
|
60
|
+
placeholder: '+998 XX XXXXXXX',
|
|
61
|
+
mask: '+999 99 9999999',
|
|
62
|
+
startSubsequence: '998',
|
|
63
|
+
regexp: /\+?998\d{9}/,
|
|
64
|
+
flag: 'UZB'
|
|
65
|
+
},
|
|
66
|
+
// для всех непредусмотренных стран
|
|
67
|
+
UNKNOWN: {
|
|
68
|
+
placeholder: '',
|
|
69
|
+
mask: '+999999999999999999',
|
|
70
|
+
startSubsequence: '',
|
|
71
|
+
regexp: /^\d{7,}$/,
|
|
72
|
+
flag: 'UNKNOWN'
|
|
73
|
+
}
|
|
74
|
+
};
|
|
73
75
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TSupportedCountries } from './types';
|
|
2
2
|
declare class ExternalPhoneLogic {
|
|
3
|
-
getIsValidPhone(value: string, countries?: Array<TSupportedCountries
|
|
4
|
-
getIsValidRusPhone(phone?: string): boolean;
|
|
3
|
+
getIsValidPhone(value: string, countries?: Array<TSupportedCountries>, isSupportCityRusPhoneNumber?: boolean): boolean;
|
|
4
|
+
getIsValidRusPhone(phone?: string, isSupportCityRusPhoneNumber?: boolean): boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare const phoneLogic: ExternalPhoneLogic;
|
|
7
7
|
export {};
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.phoneLogic = void 0;
|
|
7
|
-
var _constants = require("./constants");
|
|
8
7
|
var _phoneInputLogic = require("./phoneInputLogic");
|
|
9
8
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
10
9
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
@@ -18,19 +17,21 @@ var ExternalPhoneLogic = /*#__PURE__*/function () {
|
|
|
18
17
|
}
|
|
19
18
|
return _createClass(ExternalPhoneLogic, [{
|
|
20
19
|
key: "getIsValidPhone",
|
|
21
|
-
value: function getIsValidPhone(value, countries) {
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
20
|
+
value: function getIsValidPhone(value, countries, isSupportCityRusPhoneNumber) {
|
|
21
|
+
var phoneInputLogic = new _phoneInputLogic.PhoneInputLogic(isSupportCityRusPhoneNumber || false);
|
|
22
|
+
var notFormattedValue = phoneInputLogic.getOnlyNumbersFromString(value);
|
|
23
|
+
var supportedCountries = phoneInputLogic.getSupportedCountriesByCountryNames(countries);
|
|
24
|
+
var currentCountriesPhoneRules = phoneInputLogic.getCountriesPhoneRulesByCountryNames(supportedCountries);
|
|
25
25
|
var country = Object.entries(currentCountriesPhoneRules).find(function (item) {
|
|
26
|
-
return
|
|
26
|
+
return phoneInputLogic.getIsHaveStartSequenceInString(notFormattedValue, item[1].startSubsequence);
|
|
27
27
|
});
|
|
28
|
-
return
|
|
28
|
+
return phoneInputLogic.getIsValidPhoneInputByCountry(notFormattedValue, country ? country[1] : phoneInputLogic.getRusCountry());
|
|
29
29
|
}
|
|
30
30
|
}, {
|
|
31
31
|
key: "getIsValidRusPhone",
|
|
32
|
-
value: function getIsValidRusPhone(phone) {
|
|
33
|
-
|
|
32
|
+
value: function getIsValidRusPhone(phone, isSupportCityRusPhoneNumber) {
|
|
33
|
+
var phoneInputLogic = new _phoneInputLogic.PhoneInputLogic(isSupportCityRusPhoneNumber || false);
|
|
34
|
+
return phoneInputLogic.getIsValidPhoneInputByCountry(phone || '', phoneInputLogic.getRusCountry());
|
|
34
35
|
}
|
|
35
36
|
}]);
|
|
36
37
|
}();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TCountryRule } from '../types';
|
|
2
|
-
|
|
2
|
+
import { PhoneInputLogic } from '../phoneInputLogic';
|
|
3
|
+
export declare const useValidateInitialValue: (phoneInputLogic: PhoneInputLogic, initialValue: string, currentCountriesPhoneRules: {
|
|
3
4
|
[p: string]: TCountryRule;
|
|
4
5
|
}, onValid: (currentInputValue: string, countryCode: string) => void, onUnValid: (countryCode: string) => void) => void;
|
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useValidateInitialValue = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
|
-
var _phoneInputLogic = require("../phoneInputLogic");
|
|
9
|
-
var _constants = require("../constants");
|
|
10
8
|
var _types = require("../types");
|
|
11
9
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
12
10
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -14,7 +12,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
14
12
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
13
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
14
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
17
|
-
var useValidateInitialValue = exports.useValidateInitialValue = function useValidateInitialValue(initialValue, currentCountriesPhoneRules, onValid, onUnValid) {
|
|
15
|
+
var useValidateInitialValue = exports.useValidateInitialValue = function useValidateInitialValue(phoneInputLogic, initialValue, currentCountriesPhoneRules, onValid, onUnValid) {
|
|
18
16
|
var _useState = (0, _react.useState)(false),
|
|
19
17
|
_useState2 = _slicedToArray(_useState, 2),
|
|
20
18
|
isInitialValidateDone = _useState2[0],
|
|
@@ -22,12 +20,12 @@ var useValidateInitialValue = exports.useValidateInitialValue = function useVali
|
|
|
22
20
|
(0, _react.useEffect)(function () {
|
|
23
21
|
if (isInitialValidateDone) return;
|
|
24
22
|
if (initialValue) {
|
|
25
|
-
var notFormattedValue =
|
|
23
|
+
var notFormattedValue = phoneInputLogic.getOnlyNumbersFromString(initialValue);
|
|
26
24
|
var currentCountry = Object.entries(currentCountriesPhoneRules).find(function (item) {
|
|
27
|
-
return
|
|
25
|
+
return phoneInputLogic.getIsHaveStartSequenceInString(notFormattedValue, item[1].startSubsequence);
|
|
28
26
|
});
|
|
29
27
|
var countryCode = currentCountry ? currentCountry[0] : _types.RUS_COUNTRY_CODE;
|
|
30
|
-
var isValidInputValue =
|
|
28
|
+
var isValidInputValue = phoneInputLogic.getIsValidPhoneInputByCountry(notFormattedValue, currentCountry ? currentCountry[1] : phoneInputLogic.getRusCountry());
|
|
31
29
|
if (isValidInputValue) {
|
|
32
30
|
onValid(notFormattedValue, countryCode);
|
|
33
31
|
} else {
|
|
@@ -18,6 +18,7 @@ type TControlProps = Pick<TPureInputProps, 'disabled' | 'id' | 'autoFocus'> & {
|
|
|
18
18
|
}>;
|
|
19
19
|
pureInputProps?: Pick<TPureInputProps, 'paddingTop' | 'paddingBottom' | 'autoFocus'>;
|
|
20
20
|
size?: TSizes;
|
|
21
|
+
isSupportCityRusPhoneNumber?: boolean;
|
|
21
22
|
};
|
|
22
23
|
export type TProps = TControlProps & TFieldProps;
|
|
23
24
|
export declare const PhoneInput: FC<TProps>;
|
|
@@ -43,18 +43,23 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
|
|
|
43
43
|
pureInputProps = _ref.pureInputProps,
|
|
44
44
|
_ref$size = _ref.size,
|
|
45
45
|
size = _ref$size === void 0 ? 'M' : _ref$size,
|
|
46
|
-
autoFocus = _ref.autoFocus
|
|
46
|
+
autoFocus = _ref.autoFocus,
|
|
47
|
+
_ref$isSupportCityRus = _ref.isSupportCityRusPhoneNumber,
|
|
48
|
+
isSupportCityRusPhoneNumber = _ref$isSupportCityRus === void 0 ? false : _ref$isSupportCityRus;
|
|
47
49
|
var inputRef = (0, _react.useRef)();
|
|
48
50
|
var isMobile = (0, _useMedia.useMobile)();
|
|
51
|
+
var phoneInputLogic = (0, _react.useMemo)(function () {
|
|
52
|
+
return new _phoneInputLogic.PhoneInputLogic(isSupportCityRusPhoneNumber);
|
|
53
|
+
}, [isSupportCityRusPhoneNumber]);
|
|
49
54
|
var countrySelectOptions = (0, _react.useMemo)(function () {
|
|
50
|
-
return
|
|
51
|
-
}, [countries]);
|
|
55
|
+
return phoneInputLogic.getCountriesSelectOptions(countries);
|
|
56
|
+
}, [countries, phoneInputLogic]);
|
|
52
57
|
var isHaveSelectCountries = (0, _react.useMemo)(function () {
|
|
53
|
-
return
|
|
54
|
-
}, [countrySelectOptions]);
|
|
58
|
+
return phoneInputLogic.getIsHaveCountriesSelectOptions(countrySelectOptions);
|
|
59
|
+
}, [countrySelectOptions, phoneInputLogic]);
|
|
55
60
|
var currentCountriesPhoneRules = (0, _react.useMemo)(function () {
|
|
56
|
-
return
|
|
57
|
-
}, [countrySelectOptions]);
|
|
61
|
+
return phoneInputLogic.getCountriesPhoneRulesBySelectOptions(countrySelectOptions);
|
|
62
|
+
}, [countrySelectOptions, phoneInputLogic]);
|
|
58
63
|
var _useInputFocus = (0, _useInputFocus2.useInputFocus)({
|
|
59
64
|
onFocus: onFocus,
|
|
60
65
|
onBlur: onBlur
|
|
@@ -94,32 +99,32 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
|
|
|
94
99
|
setIsHaveInputError(true);
|
|
95
100
|
setCountry(countryCode);
|
|
96
101
|
}, [onChange]);
|
|
97
|
-
(0, _useValidateInitialValue.useValidateInitialValue)(value, currentCountriesPhoneRules, handleInitialValid, handleInitialUnValid);
|
|
102
|
+
(0, _useValidateInitialValue.useValidateInitialValue)(phoneInputLogic, value, currentCountriesPhoneRules, handleInitialValid, handleInitialUnValid);
|
|
98
103
|
var getNewCountryByInputValue = (0, _react.useCallback)(function (currentValue) {
|
|
99
104
|
var currentCountry = currentCountriesPhoneRules[country];
|
|
100
105
|
var newCountry = Object.entries(currentCountriesPhoneRules).find(function (item) {
|
|
101
|
-
return
|
|
106
|
+
return phoneInputLogic.getIsHaveStartSequenceInString(currentValue, item[1].startSubsequence);
|
|
102
107
|
});
|
|
103
|
-
var isNeedChangeCountry =
|
|
108
|
+
var isNeedChangeCountry = phoneInputLogic.getIsNeedChangeCountry(currentValue, currentCountry, newCountry);
|
|
104
109
|
var isNeedAndCanChangeCountry = isNeedChangeCountry && !!newCountry;
|
|
105
110
|
if (isNeedAndCanChangeCountry) {
|
|
106
111
|
handleChangeCountry(newCountry[0]);
|
|
107
112
|
}
|
|
108
113
|
return isNeedAndCanChangeCountry ? newCountry[1] : currentCountry;
|
|
109
|
-
}, [country, currentCountriesPhoneRules, handleChangeCountry]);
|
|
114
|
+
}, [country, currentCountriesPhoneRules, handleChangeCountry, phoneInputLogic]);
|
|
110
115
|
var getIsValidValue = (0, _react.useCallback)(function (currentValue) {
|
|
111
116
|
var currentCountry = getNewCountryByInputValue(currentValue);
|
|
112
|
-
return
|
|
113
|
-
}, [getNewCountryByInputValue]);
|
|
117
|
+
return phoneInputLogic.getIsValidPhoneInputByCountry(currentValue, currentCountry);
|
|
118
|
+
}, [getNewCountryByInputValue, phoneInputLogic]);
|
|
114
119
|
var handleInputValueChange = (0, _react.useCallback)(function (currentInputValue, event) {
|
|
115
|
-
var notFormattedValue =
|
|
116
|
-
var moveCaret = event ?
|
|
117
|
-
var intermediateValue = country === _types.RUS_COUNTRY_CODE ?
|
|
120
|
+
var notFormattedValue = phoneInputLogic.getOnlyNumbersFromString(currentInputValue);
|
|
121
|
+
var moveCaret = event ? phoneInputLogic.moveCaretByValue(event) : undefined;
|
|
122
|
+
var intermediateValue = country === _types.RUS_COUNTRY_CODE ? phoneInputLogic.formatRusPhoneToUnifiedView(notFormattedValue, moveCaret) : notFormattedValue;
|
|
118
123
|
var isValidInputValue = getIsValidValue(intermediateValue);
|
|
119
124
|
setIsHaveInputError(!isValidInputValue);
|
|
120
125
|
onChange(isValidInputValue ? intermediateValue : '');
|
|
121
126
|
setInputValue(intermediateValue);
|
|
122
|
-
}, [country, getIsValidValue, onChange]);
|
|
127
|
+
}, [country, getIsValidValue, onChange, phoneInputLogic]);
|
|
123
128
|
var handleChange = (0, _react.useCallback)(function (event) {
|
|
124
129
|
handleInputValueChange(event.target.value, event);
|
|
125
130
|
}, [handleInputValueChange]);
|
|
@@ -132,7 +137,7 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
|
|
|
132
137
|
var handleCountryChange = (0, _react.useCallback)(function (countryValue) {
|
|
133
138
|
handleChangeCountry(countryValue);
|
|
134
139
|
var currentCountry = currentCountriesPhoneRules[countryValue];
|
|
135
|
-
var isValidInputValue =
|
|
140
|
+
var isValidInputValue = phoneInputLogic.getIsValidPhoneInputByCountry(inputValue, currentCountry);
|
|
136
141
|
setIsFirstBlur(false);
|
|
137
142
|
setIsHaveInputError(!isValidInputValue);
|
|
138
143
|
onChange(isValidInputValue ? inputValue : '');
|
|
@@ -140,7 +145,7 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
|
|
|
140
145
|
var _inputRef$current;
|
|
141
146
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
142
147
|
}, 0);
|
|
143
|
-
}, [currentCountriesPhoneRules, handleChangeCountry, inputValue, onChange]);
|
|
148
|
+
}, [currentCountriesPhoneRules, handleChangeCountry, inputValue, onChange, phoneInputLogic]);
|
|
144
149
|
var handlePaste = (0, _react.useCallback)(function (event) {
|
|
145
150
|
event.preventDefault();
|
|
146
151
|
var pasteText = event.clipboardData.getData('Text').trim();
|
|
@@ -55,7 +55,8 @@ var Component = function Component(props) {
|
|
|
55
55
|
var commonProps = {
|
|
56
56
|
disabled: false,
|
|
57
57
|
label: 'Телефон',
|
|
58
|
-
size: 'L'
|
|
58
|
+
size: 'L',
|
|
59
|
+
isSupportCityRusPhoneNumber: false
|
|
59
60
|
};
|
|
60
61
|
var MultiCountry = exports.MultiCountry = {
|
|
61
62
|
args: _objectSpread(_objectSpread({}, commonProps), {}, {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { TCountryRule, TCountrySelectOption, TSupportedCountries } from './types';
|
|
2
2
|
import { ChangeEvent } from 'react';
|
|
3
|
-
declare class PhoneInputLogic {
|
|
3
|
+
export declare class PhoneInputLogic {
|
|
4
|
+
private isSupportCityRusPhoneNumber;
|
|
5
|
+
private allCountriesPhoneRules;
|
|
6
|
+
constructor(isSupportCityRusPhoneNumber: boolean);
|
|
7
|
+
getRusCountry(): TCountryRule;
|
|
4
8
|
private getCaretPositionByRusValue;
|
|
5
9
|
getIsValidPhoneInputByCountry(value: string, country: TCountryRule): boolean;
|
|
6
10
|
getSupportedCountriesByCountryNames(countries?: Array<TSupportedCountries>): ("RUS" | "BLR" | "KAZ" | "AZE" | "ARM" | "KGZ" | "TJK" | "UZB" | "UNKNOWN")[] | undefined;
|
|
@@ -26,5 +30,3 @@ declare class PhoneInputLogic {
|
|
|
26
30
|
moveCaretByValue(event: ChangeEvent<HTMLInputElement>): (positionCaret: number) => void;
|
|
27
31
|
getIsNeedChangeCountry(inputValue: string, currentCountry: TCountryRule, newCountry?: [string, TCountryRule]): boolean | "" | undefined;
|
|
28
32
|
}
|
|
29
|
-
export declare const phoneInputLogic: PhoneInputLogic;
|
|
30
|
-
export {};
|
|
@@ -3,26 +3,35 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.PhoneInputLogic = void 0;
|
|
7
7
|
var _types = require("./types");
|
|
8
8
|
var _constants = require("./constants");
|
|
9
9
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
10
10
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
11
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
12
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
14
13
|
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
15
14
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
15
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
16
16
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
17
17
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
|
-
var PhoneInputLogic = /*#__PURE__*/function () {
|
|
19
|
-
function PhoneInputLogic() {
|
|
18
|
+
var PhoneInputLogic = exports.PhoneInputLogic = /*#__PURE__*/function () {
|
|
19
|
+
function PhoneInputLogic(isSupportCityRusPhoneNumber) {
|
|
20
20
|
_classCallCheck(this, PhoneInputLogic);
|
|
21
|
+
_defineProperty(this, "isSupportCityRusPhoneNumber", void 0);
|
|
22
|
+
_defineProperty(this, "allCountriesPhoneRules", void 0);
|
|
23
|
+
this.isSupportCityRusPhoneNumber = isSupportCityRusPhoneNumber;
|
|
24
|
+
this.allCountriesPhoneRules = (0, _constants.getAllCountriesPhoneRules)(isSupportCityRusPhoneNumber);
|
|
21
25
|
}
|
|
22
26
|
return _createClass(PhoneInputLogic, [{
|
|
27
|
+
key: "getRusCountry",
|
|
28
|
+
value: function getRusCountry() {
|
|
29
|
+
return this.allCountriesPhoneRules.RUS;
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
23
32
|
key: "getCaretPositionByRusValue",
|
|
24
33
|
value: function getCaretPositionByRusValue(value) {
|
|
25
|
-
var mask =
|
|
34
|
+
var mask = this.getRusCountry().mask.split('');
|
|
26
35
|
var counter = 0;
|
|
27
36
|
var position = 0;
|
|
28
37
|
mask.forEach(function (maskItem, index) {
|
|
@@ -43,18 +52,20 @@ var PhoneInputLogic = /*#__PURE__*/function () {
|
|
|
43
52
|
}, {
|
|
44
53
|
key: "getSupportedCountriesByCountryNames",
|
|
45
54
|
value: function getSupportedCountriesByCountryNames(countries) {
|
|
55
|
+
var _this = this;
|
|
46
56
|
return countries === null || countries === void 0 ? void 0 : countries.filter(function (country) {
|
|
47
|
-
return
|
|
57
|
+
return _this.allCountriesPhoneRules[country];
|
|
48
58
|
});
|
|
49
59
|
}
|
|
50
60
|
}, {
|
|
51
61
|
key: "getCountriesSelectOptions",
|
|
52
62
|
value: function getCountriesSelectOptions(countries) {
|
|
63
|
+
var _this2 = this;
|
|
53
64
|
var supportedCountries = countries === null || countries === void 0 ? void 0 : countries.filter(function (country) {
|
|
54
|
-
return
|
|
65
|
+
return _this2.allCountriesPhoneRules[country.value];
|
|
55
66
|
});
|
|
56
67
|
return supportedCountries === null || supportedCountries === void 0 ? void 0 : supportedCountries.map(function (country) {
|
|
57
|
-
var countryRules =
|
|
68
|
+
var countryRules = _this2.allCountriesPhoneRules[country.value];
|
|
58
69
|
return _objectSpread(_objectSpread({}, country), {}, {
|
|
59
70
|
description: countryRules.startSubsequence ? "+".concat(countryRules.startSubsequence) : '',
|
|
60
71
|
flag: countryRules.flag
|
|
@@ -69,23 +80,23 @@ var PhoneInputLogic = /*#__PURE__*/function () {
|
|
|
69
80
|
}, {
|
|
70
81
|
key: "getCountriesPhoneRulesBySelectOptions",
|
|
71
82
|
value: function getCountriesPhoneRulesBySelectOptions(countrySelectOptions) {
|
|
72
|
-
return this.getIsHaveCountriesSelectOptions(countrySelectOptions) ? Object.fromEntries(Object.entries(
|
|
83
|
+
return this.getIsHaveCountriesSelectOptions(countrySelectOptions) ? Object.fromEntries(Object.entries(this.allCountriesPhoneRules).filter(function (ruleItem) {
|
|
73
84
|
return countrySelectOptions === null || countrySelectOptions === void 0 ? void 0 : countrySelectOptions.find(function (countrySelectOption) {
|
|
74
85
|
return countrySelectOption.value === ruleItem[0];
|
|
75
86
|
});
|
|
76
87
|
})) : {
|
|
77
|
-
RUS:
|
|
88
|
+
RUS: this.getRusCountry()
|
|
78
89
|
};
|
|
79
90
|
}
|
|
80
91
|
}, {
|
|
81
92
|
key: "getCountriesPhoneRulesByCountryNames",
|
|
82
93
|
value: function getCountriesPhoneRulesByCountryNames(countrySelectOptions) {
|
|
83
|
-
return this.getIsHaveCountriesSelectOptions(countrySelectOptions) ? Object.fromEntries(Object.entries(
|
|
94
|
+
return this.getIsHaveCountriesSelectOptions(countrySelectOptions) ? Object.fromEntries(Object.entries(this.allCountriesPhoneRules).filter(function (ruleItem) {
|
|
84
95
|
return countrySelectOptions === null || countrySelectOptions === void 0 ? void 0 : countrySelectOptions.find(function (countrySelectOption) {
|
|
85
96
|
return countrySelectOption === ruleItem[0];
|
|
86
97
|
});
|
|
87
98
|
})) : {
|
|
88
|
-
RUS:
|
|
99
|
+
RUS: this.getRusCountry()
|
|
89
100
|
};
|
|
90
101
|
}
|
|
91
102
|
}, {
|
|
@@ -135,5 +146,4 @@ var PhoneInputLogic = /*#__PURE__*/function () {
|
|
|
135
146
|
return newCountry && currentCountry.startSubsequence !== newCountry[1].startSubsequence && inputValue && (newCountry[0] === _types.UNKNOWN_COUNTRY_CODE ? !this.getIsHaveStartSequenceInString(inputValue, currentCountry.startSubsequence) : true);
|
|
136
147
|
}
|
|
137
148
|
}]);
|
|
138
|
-
}();
|
|
139
|
-
var phoneInputLogic = exports.phoneInputLogic = new PhoneInputLogic();
|
|
149
|
+
}();
|