1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = void 0;
|
7 |
|
8 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
9 |
|
10 | 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, descriptor.key, descriptor); } }
|
11 |
|
12 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
13 |
|
14 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
15 |
|
16 | var AsYouTypeState =
|
17 |
|
18 | function () {
|
19 | function AsYouTypeState(_ref) {
|
20 | var _this = this;
|
21 |
|
22 | var onCountryChange = _ref.onCountryChange,
|
23 | onCallingCodeChange = _ref.onCallingCodeChange;
|
24 |
|
25 | _classCallCheck(this, AsYouTypeState);
|
26 |
|
27 | _defineProperty(this, "update", function (properties) {
|
28 | for (var _i = 0, _Object$keys = Object.keys(properties); _i < _Object$keys.length; _i++) {
|
29 | var key = _Object$keys[_i];
|
30 | _this[key] = properties[key];
|
31 | }
|
32 | });
|
33 |
|
34 | this.onCountryChange = onCountryChange;
|
35 | this.onCallingCodeChange = onCallingCodeChange;
|
36 | }
|
37 |
|
38 | _createClass(AsYouTypeState, [{
|
39 | key: "reset",
|
40 | value: function reset(defaultCountry, defaultCallingCode) {
|
41 | this.international = false;
|
42 | this.IDDPrefix = undefined;
|
43 | this.missingPlus = undefined;
|
44 | this.callingCode = undefined;
|
45 | this.digits = '';
|
46 | this.resetNationalSignificantNumber();
|
47 | this.initCountryAndCallingCode(defaultCountry, defaultCallingCode);
|
48 | }
|
49 | }, {
|
50 | key: "resetNationalSignificantNumber",
|
51 | value: function resetNationalSignificantNumber() {
|
52 | this.nationalSignificantNumber = this.getNationalDigits();
|
53 | this.nationalSignificantNumberMatchesInput = true;
|
54 | this.nationalPrefix = undefined;
|
55 | this.carrierCode = undefined;
|
56 | this.complexPrefixBeforeNationalSignificantNumber = undefined;
|
57 | }
|
58 | }, {
|
59 | key: "initCountryAndCallingCode",
|
60 | value: function initCountryAndCallingCode(country, callingCode) {
|
61 | this.setCountry(country);
|
62 | this.setCallingCode(callingCode);
|
63 | }
|
64 | }, {
|
65 | key: "setCountry",
|
66 | value: function setCountry(country) {
|
67 | this.country = country;
|
68 | this.onCountryChange(country);
|
69 | }
|
70 | }, {
|
71 | key: "setCallingCode",
|
72 | value: function setCallingCode(callingCode) {
|
73 | this.callingCode = callingCode;
|
74 | return this.onCallingCodeChange(this.country, callingCode);
|
75 | }
|
76 | }, {
|
77 | key: "startInternationalNumber",
|
78 | value: function startInternationalNumber() {
|
79 |
|
80 | this.international = true;
|
81 |
|
82 |
|
83 |
|
84 | this.initCountryAndCallingCode();
|
85 | }
|
86 | }, {
|
87 | key: "appendDigits",
|
88 | value: function appendDigits(nextDigits) {
|
89 | this.digits += nextDigits;
|
90 | }
|
91 | }, {
|
92 | key: "appendNationalSignificantNumberDigits",
|
93 | value: function appendNationalSignificantNumberDigits(nextDigits) {
|
94 | this.nationalSignificantNumber += nextDigits;
|
95 | }
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | }, {
|
105 | key: "getNationalDigits",
|
106 | value: function getNationalDigits() {
|
107 | if (this.international) {
|
108 | return this.digits.slice((this.IDDPrefix ? this.IDDPrefix.length : 0) + (this.callingCode ? this.callingCode.length : 0));
|
109 | }
|
110 |
|
111 | return this.digits;
|
112 | }
|
113 | }, {
|
114 | key: "getDigitsWithoutInternationalPrefix",
|
115 | value: function getDigitsWithoutInternationalPrefix() {
|
116 | if (this.international) {
|
117 | if (this.IDDPrefix) {
|
118 | return this.digits.slice(this.IDDPrefix.length);
|
119 | }
|
120 | }
|
121 |
|
122 | return this.digits;
|
123 | }
|
124 | }]);
|
125 |
|
126 | return AsYouTypeState;
|
127 | }();
|
128 |
|
129 | exports["default"] = AsYouTypeState;
|
130 |
|
\ | No newline at end of file |