@invoicebox/ui 0.1.0-alpha.72 → 0.1.0-alpha.74

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.
@@ -0,0 +1,6 @@
1
+ import { TSupportedCountries } from './types';
2
+ declare class ExternalPhoneLogic {
3
+ getIsValidPhone(value: string, countries?: Array<TSupportedCountries>): boolean;
4
+ }
5
+ export declare const phoneLogic: ExternalPhoneLogic;
6
+ 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 supportedCountries = _phoneInputLogic.phoneInputLogic.getSupportedCountriesByCountryNames(countries);
24
+ var currentCountriesPhoneRules = _phoneInputLogic.phoneInputLogic.getCountriesPhoneRulesByCountryNames(supportedCountries);
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();
@@ -45,7 +45,7 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
45
45
  return _phoneInputLogic.phoneInputLogic.getIsHaveCountriesSelectOptions(countrySelectOptions);
46
46
  }, [countrySelectOptions]);
47
47
  var currentCountriesPhoneRules = (0, _react.useMemo)(function () {
48
- return _phoneInputLogic.phoneInputLogic.getCountriesPhoneRules(countrySelectOptions);
48
+ return _phoneInputLogic.phoneInputLogic.getCountriesPhoneRulesBySelectOptions(countrySelectOptions);
49
49
  }, [countrySelectOptions]);
50
50
  var _useInputFocus = (0, _useInputFocus2.useInputFocus)({
51
51
  onFocus: onFocus,
@@ -3,10 +3,7 @@ import { ChangeEvent } from 'react';
3
3
  declare class PhoneInputLogic {
4
4
  private getCaretPositionByRusValue;
5
5
  getIsValidPhoneInputByCountry(value: string, country: TCountryRule): boolean;
6
- getIsValidPhone(value: string, countries?: Array<{
7
- label: string;
8
- value: TSupportedCountries;
9
- }>): boolean;
6
+ getSupportedCountriesByCountryNames(countries?: Array<TSupportedCountries>): ("RUS" | "BLR" | "KAZ" | "AZE" | "ARM" | "KGZ" | "TJK" | "UZB" | "UNKNOWN")[] | undefined;
10
7
  getCountriesSelectOptions(countries?: Array<{
11
8
  label: string;
12
9
  value: TSupportedCountries;
@@ -16,8 +13,11 @@ declare class PhoneInputLogic {
16
13
  label: string;
17
14
  value: TSupportedCountries;
18
15
  }[] | undefined;
19
- getIsHaveCountriesSelectOptions(countrySelectOptions?: Array<TCountrySelectOption>): boolean;
20
- getCountriesPhoneRules(countrySelectOptions?: Array<TCountrySelectOption>): {
16
+ getIsHaveCountriesSelectOptions(countrySelectOptions?: Array<TCountrySelectOption | TSupportedCountries>): boolean;
17
+ getCountriesPhoneRulesBySelectOptions(countrySelectOptions?: Array<TCountrySelectOption>): {
18
+ [k: string]: TCountryRule;
19
+ };
20
+ getCountriesPhoneRulesByCountryNames(countrySelectOptions?: Array<TSupportedCountries>): {
21
21
  [k: string]: TCountryRule;
22
22
  };
23
23
  getIsHaveStartSequenceInString(value: string, subsequence: string): boolean;
@@ -27,8 +27,4 @@ declare class PhoneInputLogic {
27
27
  getIsNeedChangeCountry(inputValue: string, currentCountry: TCountryRule, newCountry?: [string, TCountryRule]): boolean | "" | undefined;
28
28
  }
29
29
  export declare const phoneInputLogic: PhoneInputLogic;
30
- export declare const getIsValidPhone: (value: string, countries?: {
31
- label: string;
32
- value: TSupportedCountries;
33
- }[] | undefined) => boolean;
34
30
  export {};
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.phoneInputLogic = exports.getIsValidPhone = void 0;
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); }
@@ -41,15 +41,11 @@ var PhoneInputLogic = /*#__PURE__*/function () {
41
41
  return !!value.match(country.regexp);
42
42
  }
43
43
  }, {
44
- key: "getIsValidPhone",
45
- value: function getIsValidPhone(value, countries) {
46
- var notFormattedValue = this.getOnlyNumbersFromString(value);
47
- var countrySelectOptions = this.getCountriesSelectOptions(countries);
48
- var currentCountriesPhoneRules = this.getCountriesPhoneRules(countrySelectOptions);
49
- var country = Object.entries(currentCountriesPhoneRules).find(function (item) {
50
- return phoneInputLogic.getIsHaveStartSequenceInString(notFormattedValue, item[1].startSubsequence);
44
+ key: "getSupportedCountriesByCountryNames",
45
+ value: function getSupportedCountriesByCountryNames(countries) {
46
+ return countries === null || countries === void 0 ? void 0 : countries.filter(function (country) {
47
+ return _constants.allCountriesPhoneRules[country];
51
48
  });
52
- return this.getIsValidPhoneInputByCountry(notFormattedValue, country ? country[1] : _constants.allCountriesPhoneRules.RUS);
53
49
  }
54
50
  }, {
55
51
  key: "getCountriesSelectOptions",
@@ -71,8 +67,8 @@ var PhoneInputLogic = /*#__PURE__*/function () {
71
67
  return !!(countrySelectOptions !== null && countrySelectOptions !== void 0 && countrySelectOptions.length);
72
68
  }
73
69
  }, {
74
- key: "getCountriesPhoneRules",
75
- value: function getCountriesPhoneRules(countrySelectOptions) {
70
+ key: "getCountriesPhoneRulesBySelectOptions",
71
+ value: function getCountriesPhoneRulesBySelectOptions(countrySelectOptions) {
76
72
  return this.getIsHaveCountriesSelectOptions(countrySelectOptions) ? Object.fromEntries(Object.entries(_constants.allCountriesPhoneRules).filter(function (ruleItem) {
77
73
  return countrySelectOptions === null || countrySelectOptions === void 0 ? void 0 : countrySelectOptions.find(function (countrySelectOption) {
78
74
  return countrySelectOption.value === ruleItem[0];
@@ -81,6 +77,17 @@ var PhoneInputLogic = /*#__PURE__*/function () {
81
77
  RUS: _constants.allCountriesPhoneRules.RUS
82
78
  };
83
79
  }
80
+ }, {
81
+ key: "getCountriesPhoneRulesByCountryNames",
82
+ value: function getCountriesPhoneRulesByCountryNames(countrySelectOptions) {
83
+ return this.getIsHaveCountriesSelectOptions(countrySelectOptions) ? Object.fromEntries(Object.entries(_constants.allCountriesPhoneRules).filter(function (ruleItem) {
84
+ return countrySelectOptions === null || countrySelectOptions === void 0 ? void 0 : countrySelectOptions.find(function (countrySelectOption) {
85
+ return countrySelectOption === ruleItem[0];
86
+ });
87
+ })) : {
88
+ RUS: _constants.allCountriesPhoneRules.RUS
89
+ };
90
+ }
84
91
  }, {
85
92
  key: "getIsHaveStartSequenceInString",
86
93
  value: function getIsHaveStartSequenceInString(value, subsequence) {
@@ -130,5 +137,4 @@ var PhoneInputLogic = /*#__PURE__*/function () {
130
137
  }]);
131
138
  return PhoneInputLogic;
132
139
  }();
133
- var phoneInputLogic = exports.phoneInputLogic = new PhoneInputLogic();
134
- var getIsValidPhone = exports.getIsValidPhone = phoneInputLogic.getIsValidPhone;
140
+ var phoneInputLogic = exports.phoneInputLogic = new PhoneInputLogic();
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, "getIsValidPhone", {
132
+ Object.defineProperty(exports, "phoneLogic", {
133
133
  enumerable: true,
134
134
  get: function get() {
135
- return _phoneInputLogic.getIsValidPhone;
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 _phoneInputLogic = require("./components/form/PhoneInput/phoneInputLogic");
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");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@invoicebox/ui",
3
- "version": "0.1.0-alpha.72",
3
+ "version": "0.1.0-alpha.74",
4
4
  "description": "Invoicebox UI",
5
5
  "license": "Apache License 2.0",
6
6
  "scripts": {