@invoicebox/ui 0.1.0-alpha.71 → 0.1.0-alpha.73
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/PhoneInput/constants.js +1 -1
- package/dist/components/form/PhoneInput/externalPhoneLogic.d.ts +9 -0
- package/dist/components/form/PhoneInput/externalPhoneLogic.js +33 -0
- package/dist/components/form/PhoneInput/index.js +15 -19
- package/dist/components/form/PhoneInput/phoneInputLogic.d.ts +3 -4
- package/dist/components/form/PhoneInput/phoneInputLogic.js +19 -3
- package/dist/components/form/PhoneInput/types.d.ts +1 -0
- package/dist/components/form/PhoneInput/types.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TSupportedCountries } from './types';
|
|
2
|
+
declare class ExternalPhoneLogic {
|
|
3
|
+
getIsValidPhone(value: string, countries?: Array<{
|
|
4
|
+
label: string;
|
|
5
|
+
value: TSupportedCountries;
|
|
6
|
+
}>): boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const phoneLogic: ExternalPhoneLogic;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.phoneLogic = void 0;
|
|
7
|
+
var _constants = require("./constants");
|
|
8
|
+
var _phoneInputLogic = require("./phoneInputLogic");
|
|
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
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
14
|
+
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); }
|
|
15
|
+
var ExternalPhoneLogic = /*#__PURE__*/function () {
|
|
16
|
+
function ExternalPhoneLogic() {
|
|
17
|
+
_classCallCheck(this, ExternalPhoneLogic);
|
|
18
|
+
}
|
|
19
|
+
_createClass(ExternalPhoneLogic, [{
|
|
20
|
+
key: "getIsValidPhone",
|
|
21
|
+
value: function getIsValidPhone(value, countries) {
|
|
22
|
+
var notFormattedValue = _phoneInputLogic.phoneInputLogic.getOnlyNumbersFromString(value);
|
|
23
|
+
var countrySelectOptions = _phoneInputLogic.phoneInputLogic.getCountriesSelectOptions(countries);
|
|
24
|
+
var currentCountriesPhoneRules = _phoneInputLogic.phoneInputLogic.getCountriesPhoneRules(countrySelectOptions);
|
|
25
|
+
var country = Object.entries(currentCountriesPhoneRules).find(function (item) {
|
|
26
|
+
return _phoneInputLogic.phoneInputLogic.getIsHaveStartSequenceInString(notFormattedValue, item[1].startSubsequence);
|
|
27
|
+
});
|
|
28
|
+
return _phoneInputLogic.phoneInputLogic.getIsValidPhoneInputByCountry(notFormattedValue, country ? country[1] : _constants.allCountriesPhoneRules.RUS);
|
|
29
|
+
}
|
|
30
|
+
}]);
|
|
31
|
+
return ExternalPhoneLogic;
|
|
32
|
+
}();
|
|
33
|
+
var phoneLogic = exports.phoneLogic = new ExternalPhoneLogic();
|
|
@@ -76,47 +76,42 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
|
|
|
76
76
|
onCountryChange(countryCode);
|
|
77
77
|
}
|
|
78
78
|
}, [onCountryChange]);
|
|
79
|
-
var
|
|
79
|
+
var handleInitialValid = (0, _react.useCallback)(function (currentInputValue, countryCode) {
|
|
80
80
|
onChange(currentInputValue);
|
|
81
81
|
setIsHaveInputError(false);
|
|
82
82
|
setCountry(countryCode);
|
|
83
83
|
}, [onChange]);
|
|
84
|
-
var
|
|
84
|
+
var handleInitialUnValid = (0, _react.useCallback)(function (countryCode) {
|
|
85
85
|
onChange('');
|
|
86
86
|
setIsHaveInputError(true);
|
|
87
87
|
setCountry(countryCode);
|
|
88
88
|
}, [onChange]);
|
|
89
|
-
(0, _useValidateInitialValue.useValidateInitialValue)(value, currentCountriesPhoneRules,
|
|
90
|
-
|
|
91
|
-
// хак для того чтобы сдвигать каретку в случае если при вводе "9" надо заменить на "79", каретка не двигается сама и остаётся между "7" и "9" без этой функции
|
|
92
|
-
var moveCaretByValue = (0, _react.useCallback)(function (event) {
|
|
93
|
-
return function (positionCaret) {
|
|
94
|
-
setTimeout(function () {
|
|
95
|
-
event.target.setSelectionRange(positionCaret, positionCaret);
|
|
96
|
-
}, 0);
|
|
97
|
-
};
|
|
98
|
-
}, []);
|
|
99
|
-
var getIsValidValue = (0, _react.useCallback)(function (currentValue) {
|
|
89
|
+
(0, _useValidateInitialValue.useValidateInitialValue)(value, currentCountriesPhoneRules, handleInitialValid, handleInitialUnValid);
|
|
90
|
+
var getNewCountryByInputValue = (0, _react.useCallback)(function (currentValue) {
|
|
100
91
|
var currentCountry = currentCountriesPhoneRules[country];
|
|
101
92
|
var newCountry = Object.entries(currentCountriesPhoneRules).find(function (item) {
|
|
102
|
-
return _phoneInputLogic.phoneInputLogic.getIsHaveStartSequenceInString(currentValue, item[1].startSubsequence) && currentCountry.flag !== item[1].flag
|
|
93
|
+
return _phoneInputLogic.phoneInputLogic.getIsHaveStartSequenceInString(currentValue, item[1].startSubsequence) && currentCountry.flag !== item[1].flag;
|
|
103
94
|
});
|
|
104
|
-
var isNeedChangeCountry =
|
|
95
|
+
var isNeedChangeCountry = _phoneInputLogic.phoneInputLogic.getIsNeedChangeCountry(currentValue, currentCountry, newCountry);
|
|
105
96
|
var isNeedAndCanChangeCountry = isNeedChangeCountry && !!newCountry;
|
|
106
97
|
if (isNeedAndCanChangeCountry) {
|
|
107
98
|
handleChangeCountry(newCountry[0]);
|
|
108
99
|
}
|
|
109
|
-
return
|
|
100
|
+
return isNeedAndCanChangeCountry ? newCountry[1] : currentCountry;
|
|
110
101
|
}, [country, currentCountriesPhoneRules, handleChangeCountry]);
|
|
102
|
+
var getIsValidValue = (0, _react.useCallback)(function (currentValue) {
|
|
103
|
+
var currentCountry = getNewCountryByInputValue(currentValue);
|
|
104
|
+
return _phoneInputLogic.phoneInputLogic.getIsValidPhoneInputByCountry(currentValue, currentCountry);
|
|
105
|
+
}, [getNewCountryByInputValue]);
|
|
111
106
|
var handleInputValueChange = (0, _react.useCallback)(function (currentInputValue, event) {
|
|
112
107
|
var notFormattedValue = _phoneInputLogic.phoneInputLogic.getOnlyNumbersFromString(currentInputValue);
|
|
113
|
-
var moveCaret = event ? moveCaretByValue(event) : undefined;
|
|
108
|
+
var moveCaret = event ? _phoneInputLogic.phoneInputLogic.moveCaretByValue(event) : undefined;
|
|
114
109
|
var intermediateValue = country === _types.RUS_COUNTRY_CODE ? _phoneInputLogic.phoneInputLogic.formatRusPhoneToUnifiedView(notFormattedValue, moveCaret) : notFormattedValue;
|
|
115
110
|
var isValidInputValue = getIsValidValue(intermediateValue);
|
|
116
111
|
setIsHaveInputError(!isValidInputValue);
|
|
117
112
|
onChange(isValidInputValue ? intermediateValue : '');
|
|
118
113
|
setInputValue(intermediateValue);
|
|
119
|
-
}, [country, getIsValidValue,
|
|
114
|
+
}, [country, getIsValidValue, onChange]);
|
|
120
115
|
var handleChange = (0, _react.useCallback)(function (event) {
|
|
121
116
|
handleInputValueChange(event.target.value, event);
|
|
122
117
|
}, [handleInputValueChange]);
|
|
@@ -132,11 +127,12 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
|
|
|
132
127
|
var isValidInputValue = _phoneInputLogic.phoneInputLogic.getIsValidPhoneInputByCountry(inputValue, currentCountry);
|
|
133
128
|
setIsFirstBlur(false);
|
|
134
129
|
setIsHaveInputError(!isValidInputValue);
|
|
130
|
+
onChange(isValidInputValue ? inputValue : '');
|
|
135
131
|
setTimeout(function () {
|
|
136
132
|
var _inputRef$current;
|
|
137
133
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
138
134
|
}, 0);
|
|
139
|
-
}, [currentCountriesPhoneRules, handleChangeCountry, inputValue]);
|
|
135
|
+
}, [currentCountriesPhoneRules, handleChangeCountry, inputValue, onChange]);
|
|
140
136
|
var handlePaste = (0, _react.useCallback)(function (event) {
|
|
141
137
|
event.preventDefault();
|
|
142
138
|
var pasteText = event.clipboardData.getData('Text').trim();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TCountryRule, TCountrySelectOption, TSupportedCountries } from './types';
|
|
2
|
+
import { ChangeEvent } from 'react';
|
|
2
3
|
declare class PhoneInputLogic {
|
|
3
4
|
private getCaretPositionByRusValue;
|
|
4
5
|
getIsValidPhoneInputByCountry(value: string, country: TCountryRule): boolean;
|
|
@@ -22,10 +23,8 @@ declare class PhoneInputLogic {
|
|
|
22
23
|
getIsHaveStartSequenceInString(value: string, subsequence: string): boolean;
|
|
23
24
|
formatRusPhoneToUnifiedView(value: string, moveCaret?: (positionCaret: number) => void): string;
|
|
24
25
|
getOnlyNumbersFromString(value: string): string;
|
|
26
|
+
moveCaretByValue(event: ChangeEvent<HTMLInputElement>): (positionCaret: number) => void;
|
|
27
|
+
getIsNeedChangeCountry(inputValue: string, currentCountry: TCountryRule, newCountry?: [string, TCountryRule]): boolean | "" | undefined;
|
|
25
28
|
}
|
|
26
29
|
export declare const phoneInputLogic: PhoneInputLogic;
|
|
27
|
-
export declare const getIsValidPhone: (value: string, countries?: {
|
|
28
|
-
label: string;
|
|
29
|
-
value: TSupportedCountries;
|
|
30
|
-
}[] | undefined) => boolean;
|
|
31
30
|
export {};
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.phoneInputLogic =
|
|
6
|
+
exports.phoneInputLogic = void 0;
|
|
7
|
+
var _types = require("./types");
|
|
7
8
|
var _constants = require("./constants");
|
|
8
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); }
|
|
9
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; }
|
|
@@ -110,8 +111,23 @@ var PhoneInputLogic = /*#__PURE__*/function () {
|
|
|
110
111
|
var _value$match;
|
|
111
112
|
return ((_value$match = value.match(/\d/g)) === null || _value$match === void 0 ? void 0 : _value$match.join('')) || '';
|
|
112
113
|
}
|
|
114
|
+
|
|
115
|
+
// хак для того чтобы сдвигать каретку в случае если при вводе "9" надо заменить на "79", каретка не двигается сама и остаётся между "7" и "9" без этой функции
|
|
116
|
+
}, {
|
|
117
|
+
key: "moveCaretByValue",
|
|
118
|
+
value: function moveCaretByValue(event) {
|
|
119
|
+
return function (positionCaret) {
|
|
120
|
+
setTimeout(function () {
|
|
121
|
+
event.target.setSelectionRange(positionCaret, positionCaret);
|
|
122
|
+
}, 0);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "getIsNeedChangeCountry",
|
|
127
|
+
value: function getIsNeedChangeCountry(inputValue, currentCountry, newCountry) {
|
|
128
|
+
return newCountry && currentCountry.startSubsequence !== newCountry[1].startSubsequence && inputValue && (newCountry[0] === _types.UNKNOWN_COUNTRY_CODE ? !this.getIsHaveStartSequenceInString(inputValue, currentCountry.startSubsequence) : true);
|
|
129
|
+
}
|
|
113
130
|
}]);
|
|
114
131
|
return PhoneInputLogic;
|
|
115
132
|
}();
|
|
116
|
-
var phoneInputLogic = exports.phoneInputLogic = new PhoneInputLogic();
|
|
117
|
-
var getIsValidPhone = exports.getIsValidPhone = phoneInputLogic.getIsValidPhone;
|
|
133
|
+
var phoneInputLogic = exports.phoneInputLogic = new PhoneInputLogic();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TFlagKey } from '../../common/Flag';
|
|
2
2
|
export declare const RUS_COUNTRY_CODE = "RUS";
|
|
3
|
+
export declare const UNKNOWN_COUNTRY_CODE = "UNKNOWN";
|
|
3
4
|
export declare const supportedCountries: readonly ["RUS", "BLR", "AZE", "ARM", "KAZ", "TJK", "UZB", "KGZ", "UNKNOWN"];
|
|
4
5
|
export type TSupportedCountries = (typeof supportedCountries)[number];
|
|
5
6
|
export type TCountryRule = {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.supportedCountries = exports.RUS_COUNTRY_CODE = void 0;
|
|
6
|
+
exports.supportedCountries = exports.UNKNOWN_COUNTRY_CODE = exports.RUS_COUNTRY_CODE = void 0;
|
|
7
7
|
var RUS_COUNTRY_CODE = exports.RUS_COUNTRY_CODE = 'RUS';
|
|
8
|
-
var
|
|
8
|
+
var UNKNOWN_COUNTRY_CODE = exports.UNKNOWN_COUNTRY_CODE = 'UNKNOWN';
|
|
9
|
+
var supportedCountries = exports.supportedCountries = [RUS_COUNTRY_CODE, 'BLR', 'AZE', 'ARM', 'KAZ', 'TJK', 'UZB', 'KGZ', UNKNOWN_COUNTRY_CODE];
|
package/dist/index.d.ts
CHANGED
|
@@ -28,8 +28,8 @@ export type { TProps as TFlagProps, TFlagKey } from './components/common/Flag';
|
|
|
28
28
|
export { CountrySelect } from './components/form/CountrySelect';
|
|
29
29
|
export type { TProps as TCountrySelectProps } from './components/form/CountrySelect';
|
|
30
30
|
export { PhoneInput } from './components/form/PhoneInput';
|
|
31
|
-
export { getIsValidPhone } from './components/form/PhoneInput/phoneInputLogic';
|
|
32
31
|
export type { TProps as TPhoneInputProps } from './components/form/PhoneInput';
|
|
32
|
+
export { phoneLogic } from './components/form/PhoneInput/externalPhoneLogic';
|
|
33
33
|
export { PaletteProvider } from './palette';
|
|
34
34
|
export type { TAbstractPalette } from './palette';
|
|
35
35
|
export { useOutsideClick } from './hooks/useOutsideClick';
|
package/dist/index.js
CHANGED
|
@@ -129,10 +129,10 @@ Object.defineProperty(exports, "WarningIcon", {
|
|
|
129
129
|
return _WarningIcon.WarningIcon;
|
|
130
130
|
}
|
|
131
131
|
});
|
|
132
|
-
Object.defineProperty(exports, "
|
|
132
|
+
Object.defineProperty(exports, "phoneLogic", {
|
|
133
133
|
enumerable: true,
|
|
134
134
|
get: function get() {
|
|
135
|
-
return
|
|
135
|
+
return _externalPhoneLogic.phoneLogic;
|
|
136
136
|
}
|
|
137
137
|
});
|
|
138
138
|
Object.defineProperty(exports, "useInputFocus", {
|
|
@@ -167,7 +167,7 @@ var _SearchInput = require("./components/form/SearchInput");
|
|
|
167
167
|
var _Flag = require("./components/common/Flag");
|
|
168
168
|
var _CountrySelect = require("./components/form/CountrySelect");
|
|
169
169
|
var _PhoneInput = require("./components/form/PhoneInput");
|
|
170
|
-
var
|
|
170
|
+
var _externalPhoneLogic = require("./components/form/PhoneInput/externalPhoneLogic");
|
|
171
171
|
var _palette = require("./palette");
|
|
172
172
|
var _useOutsideClick = require("./hooks/useOutsideClick");
|
|
173
173
|
var _useInputFocus = require("./hooks/useInputFocus");
|