svelte-tel-input 0.4.2 → 0.6.0

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +8 -6
  3. package/assets/allCountry.d.ts +3 -0
  4. package/assets/allCountry.js +306 -0
  5. package/components/Input/TelInput.svelte +23 -0
  6. package/components/Input/TelInput.svelte.d.ts +17 -0
  7. package/components/Select/Select.svelte +41 -0
  8. package/components/Select/Select.svelte.d.ts +21 -0
  9. package/components/Select/SelectListItem.svelte +10 -0
  10. package/components/Select/SelectListItem.svelte.d.ts +18 -0
  11. package/components/Select/TelCountrySelect/TelCountrySelect.svelte +56 -0
  12. package/components/Select/TelCountrySelect/TelCountrySelect.svelte.d.ts +19 -0
  13. package/components/Select/TelRegionSelect/TelRegionSelect.svelte +12 -0
  14. package/components/Select/TelRegionSelect/TelRegionSelect.svelte.d.ts +18 -0
  15. package/components/Select/TelRegionSelect/TelRegionSelectOption.svelte +4 -0
  16. package/components/Select/TelRegionSelect/TelRegionSelectOption.svelte.d.ts +18 -0
  17. package/components/Select/TelTypeSelect/TelTypeSelect.svelte +15 -0
  18. package/components/Select/TelTypeSelect/TelTypeSelect.svelte.d.ts +20 -0
  19. package/components/Select/TelTypeSelect/TelTypeSelectOption.svelte +4 -0
  20. package/components/Select/TelTypeSelect/TelTypeSelectOption.svelte.d.ts +18 -0
  21. package/index.d.ts +8 -2
  22. package/index.js +8 -2
  23. package/models/interfaces/Country.interface.d.ts +7 -0
  24. package/models/interfaces/Country.interface.js +1 -0
  25. package/models/types/DynamicSvelteComponent.type.d.ts +4 -4
  26. package/models/types/DynamicSvelteComponent.type.js +0 -15
  27. package/package.json +49 -43
  28. package/stores/index.d.ts +8 -2
  29. package/stores/index.js +6 -0
  30. package/utils/api.d.ts +28 -0
  31. package/utils/api.js +30 -0
  32. package/utils/helpers.d.ts +2 -0
  33. package/utils/helpers.js +11 -0
  34. package/components/Input/SvelteTelInput.svelte +0 -23
  35. package/components/Input/SvelteTelInput.svelte.d.ts +0 -14
  36. package/components/Select/CountrySelect.svelte +0 -14
  37. package/components/Select/CountrySelect.svelte.d.ts +0 -14
  38. package/components/Select/RegionSelect.svelte +0 -14
  39. package/components/Select/RegionSelect.svelte.d.ts +0 -14
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # svelte-tel-input
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: example page preparations & extend functionality (part 1) ([#50](https://github.com/gyurielf/svelte-tel-input/pull/50))
8
+
9
+ ## 0.5.1
10
+
11
+ ### Patch Changes
12
+
13
+ - chore: update packages and resolve breaking changes ([#46](https://github.com/gyurielf/svelte-tel-input/pull/46))
14
+
15
+ ## 0.5.0
16
+
17
+ ### Minor Changes
18
+
19
+ - feat: prepare github pages deployment ([#43](https://github.com/gyurielf/svelte-tel-input/pull/43))
20
+
21
+ * feat: implement selects and input ([#43](https://github.com/gyurielf/svelte-tel-input/pull/43))
22
+
23
+ - feat: basic stores created ([#43](https://github.com/gyurielf/svelte-tel-input/pull/43))
24
+
3
25
  ## 0.4.2
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -6,20 +6,22 @@
6
6
 
7
7
  ## Installation
8
8
 
9
- ---
10
-
11
9
  Svelte Tel Input is distributed via [npm](https://www.npmjs.com/package/svelte-tel-input).
12
10
 
13
11
  ```sh
14
12
  yarn add svelte-tel-input
13
+ ```
15
14
 
16
- # or
17
-
15
+ ```
18
16
  npm install --save svelte-tel-input
19
17
  ```
20
18
 
21
- ---
22
-
23
19
  ## Dependencies
24
20
 
25
21
  [libphonenumber-js](https://gitlab.com/catamphetamine/libphonenumber-js)
22
+
23
+ ## Changelog
24
+
25
+ | Package | Changelog |
26
+ | ------------------------------ | ------------------------- |
27
+ | [@gyurielf/svelte-tel-input]() | [Changelog](CHANGELOG.md) |
@@ -0,0 +1,3 @@
1
+ import type { Country } from '../models/interfaces/Country.interface';
2
+ declare const restructuredCountries: Country[];
3
+ export default restructuredCountries;
@@ -0,0 +1,306 @@
1
+ // Array of country objects for the flag dropdown.
2
+ const allCountries = [
3
+ ['Afghanistan (‫افغانستان‬‎)', 'af', '93'],
4
+ ['Albania (Shqipëri)', 'al', '355'],
5
+ ['Algeria (‫الجزائر‬‎)', 'dz', '213'],
6
+ ['American Samoa', 'as', '1', 5, ['684']],
7
+ ['Andorra', 'ad', '376'],
8
+ ['Angola', 'ao', '244'],
9
+ ['Anguilla', 'ai', '1', 6, ['264']],
10
+ ['Antigua and Barbuda', 'ag', '1', 7, ['268']],
11
+ ['Argentina', 'ar', '54'],
12
+ ['Armenia (Հայաստան)', 'am', '374'],
13
+ ['Aruba', 'aw', '297'],
14
+ ['Ascension Island', 'ac', '247'],
15
+ ['Australia', 'au', '61', 0],
16
+ ['Austria (Österreich)', 'at', '43'],
17
+ ['Azerbaijan (Azərbaycan)', 'az', '994'],
18
+ ['Bahamas', 'bs', '1', 8, ['242']],
19
+ ['Bahrain (‫البحرين‬‎)', 'bh', '973'],
20
+ ['Bangladesh (বাংলাদেশ)', 'bd', '880'],
21
+ ['Barbados', 'bb', '1', 9, ['246']],
22
+ ['Belarus (Беларусь)', 'by', '375'],
23
+ ['Belgium (België)', 'be', '32'],
24
+ ['Belize', 'bz', '501'],
25
+ ['Benin (Bénin)', 'bj', '229'],
26
+ ['Bermuda', 'bm', '1', 10, ['441']],
27
+ ['Bhutan (འབྲུག)', 'bt', '975'],
28
+ ['Bolivia', 'bo', '591'],
29
+ ['Bosnia and Herzegovina (Босна и Херцеговина)', 'ba', '387'],
30
+ ['Botswana', 'bw', '267'],
31
+ ['Brazil (Brasil)', 'br', '55'],
32
+ ['British Indian Ocean Territory', 'io', '246'],
33
+ ['British Virgin Islands', 'vg', '1', 11, ['284']],
34
+ ['Brunei', 'bn', '673'],
35
+ ['Bulgaria (България)', 'bg', '359'],
36
+ ['Burkina Faso', 'bf', '226'],
37
+ ['Burundi (Uburundi)', 'bi', '257'],
38
+ ['Cambodia (កម្ពុជា)', 'kh', '855'],
39
+ ['Cameroon (Cameroun)', 'cm', '237'],
40
+ [
41
+ 'Canada',
42
+ 'ca',
43
+ '1',
44
+ 1,
45
+ [
46
+ '204',
47
+ '226',
48
+ '236',
49
+ '249',
50
+ '250',
51
+ '289',
52
+ '306',
53
+ '343',
54
+ '365',
55
+ '387',
56
+ '403',
57
+ '416',
58
+ '418',
59
+ '431',
60
+ '437',
61
+ '438',
62
+ '450',
63
+ '506',
64
+ '514',
65
+ '519',
66
+ '548',
67
+ '579',
68
+ '581',
69
+ '587',
70
+ '604',
71
+ '613',
72
+ '639',
73
+ '647',
74
+ '672',
75
+ '705',
76
+ '709',
77
+ '742',
78
+ '778',
79
+ '780',
80
+ '782',
81
+ '807',
82
+ '819',
83
+ '825',
84
+ '867',
85
+ '873',
86
+ '902',
87
+ '905'
88
+ ]
89
+ ],
90
+ ['Cape Verde (Kabu Verdi)', 'cv', '238'],
91
+ ['Caribbean Netherlands', 'bq', '599', 1, ['3', '4', '7']],
92
+ ['Cayman Islands', 'ky', '1', 12, ['345']],
93
+ ['Central African Republic (République centrafricaine)', 'cf', '236'],
94
+ ['Chad (Tchad)', 'td', '235'],
95
+ ['Chile', 'cl', '56'],
96
+ ['China (中国)', 'cn', '86'],
97
+ ['Christmas Island', 'cx', '61', 2, ['89164']],
98
+ ['Cocos (Keeling) Islands', 'cc', '61', 1, ['89162']],
99
+ ['Colombia', 'co', '57'],
100
+ ['Comoros (‫جزر القمر‬‎)', 'km', '269'],
101
+ ['Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)', 'cd', '243'],
102
+ ['Congo (Republic) (Congo-Brazzaville)', 'cg', '242'],
103
+ ['Cook Islands', 'ck', '682'],
104
+ ['Costa Rica', 'cr', '506'],
105
+ ['Côte d’Ivoire', 'ci', '225'],
106
+ ['Croatia (Hrvatska)', 'hr', '385'],
107
+ ['Cuba', 'cu', '53'],
108
+ ['Curaçao', 'cw', '599', 0],
109
+ ['Cyprus (Κύπρος)', 'cy', '357'],
110
+ ['Czech Republic (Česká republika)', 'cz', '420'],
111
+ ['Denmark (Danmark)', 'dk', '45'],
112
+ ['Djibouti', 'dj', '253'],
113
+ ['Dominica', 'dm', '1', 13, ['767']],
114
+ ['Dominican Republic (República Dominicana)', 'do', '1', 2, ['809', '829', '849']],
115
+ ['Ecuador', 'ec', '593'],
116
+ ['Egypt (‫مصر‬‎)', 'eg', '20'],
117
+ ['El Salvador', 'sv', '503'],
118
+ ['Equatorial Guinea (Guinea Ecuatorial)', 'gq', '240'],
119
+ ['Eritrea', 'er', '291'],
120
+ ['Estonia (Eesti)', 'ee', '372'],
121
+ ['Eswatini', 'sz', '268'],
122
+ ['Ethiopia', 'et', '251'],
123
+ ['Falkland Islands (Islas Malvinas)', 'fk', '500'],
124
+ ['Faroe Islands (Føroyar)', 'fo', '298'],
125
+ ['Fiji', 'fj', '679'],
126
+ ['Finland (Suomi)', 'fi', '358', 0],
127
+ ['France', 'fr', '33'],
128
+ ['French Guiana (Guyane française)', 'gf', '594'],
129
+ ['French Polynesia (Polynésie française)', 'pf', '689'],
130
+ ['Gabon', 'ga', '241'],
131
+ ['Gambia', 'gm', '220'],
132
+ ['Georgia (საქართველო)', 'ge', '995'],
133
+ ['Germany (Deutschland)', 'de', '49'],
134
+ ['Ghana (Gaana)', 'gh', '233'],
135
+ ['Gibraltar', 'gi', '350'],
136
+ ['Greece (Ελλάδα)', 'gr', '30'],
137
+ ['Greenland (Kalaallit Nunaat)', 'gl', '299'],
138
+ ['Grenada', 'gd', '1', 14, ['473']],
139
+ ['Guadeloupe', 'gp', '590', 0],
140
+ ['Guam', 'gu', '1', 15, ['671']],
141
+ ['Guatemala', 'gt', '502'],
142
+ ['Guernsey', 'gg', '44', 1, ['1481', '7781', '7839', '7911']],
143
+ ['Guinea (Guinée)', 'gn', '224'],
144
+ ['Guinea-Bissau (Guiné Bissau)', 'gw', '245'],
145
+ ['Guyana', 'gy', '592'],
146
+ ['Haiti', 'ht', '509'],
147
+ ['Honduras', 'hn', '504'],
148
+ ['Hong Kong (香港)', 'hk', '852'],
149
+ ['Hungary (Magyarország)', 'hu', '36'],
150
+ ['Iceland (Ísland)', 'is', '354'],
151
+ ['India (भारत)', 'in', '91'],
152
+ ['Indonesia', 'id', '62'],
153
+ ['Iran (‫ایران‬‎)', 'ir', '98'],
154
+ ['Iraq (‫العراق‬‎)', 'iq', '964'],
155
+ ['Ireland', 'ie', '353'],
156
+ ['Isle of Man', 'im', '44', 2, ['1624', '74576', '7524', '7924', '7624']],
157
+ ['Israel (‫ישראל‬‎)', 'il', '972'],
158
+ ['Italy (Italia)', 'it', '39', 0],
159
+ ['Jamaica', 'jm', '1', 4, ['876', '658']],
160
+ ['Japan (日本)', 'jp', '81'],
161
+ ['Jersey', 'je', '44', 3, ['1534', '7509', '7700', '7797', '7829', '7937']],
162
+ ['Jordan (‫الأردن‬‎)', 'jo', '962'],
163
+ ['Kazakhstan (Казахстан)', 'kz', '7', 1, ['33', '7']],
164
+ ['Kenya', 'ke', '254'],
165
+ ['Kiribati', 'ki', '686'],
166
+ ['Kosovo', 'xk', '383'],
167
+ ['Kuwait (‫الكويت‬‎)', 'kw', '965'],
168
+ ['Kyrgyzstan (Кыргызстан)', 'kg', '996'],
169
+ ['Laos (ລາວ)', 'la', '856'],
170
+ ['Latvia (Latvija)', 'lv', '371'],
171
+ ['Lebanon (‫لبنان‬‎)', 'lb', '961'],
172
+ ['Lesotho', 'ls', '266'],
173
+ ['Liberia', 'lr', '231'],
174
+ ['Libya (‫ليبيا‬‎)', 'ly', '218'],
175
+ ['Liechtenstein', 'li', '423'],
176
+ ['Lithuania (Lietuva)', 'lt', '370'],
177
+ ['Luxembourg', 'lu', '352'],
178
+ ['Macau (澳門)', 'mo', '853'],
179
+ ['North Macedonia (Македонија)', 'mk', '389'],
180
+ ['Madagascar (Madagasikara)', 'mg', '261'],
181
+ ['Malawi', 'mw', '265'],
182
+ ['Malaysia', 'my', '60'],
183
+ ['Maldives', 'mv', '960'],
184
+ ['Mali', 'ml', '223'],
185
+ ['Malta', 'mt', '356'],
186
+ ['Marshall Islands', 'mh', '692'],
187
+ ['Martinique', 'mq', '596'],
188
+ ['Mauritania (‫موريتانيا‬‎)', 'mr', '222'],
189
+ ['Mauritius (Moris)', 'mu', '230'],
190
+ ['Mayotte', 'yt', '262', 1, ['269', '639']],
191
+ ['Mexico (México)', 'mx', '52'],
192
+ ['Micronesia', 'fm', '691'],
193
+ ['Moldova (Republica Moldova)', 'md', '373'],
194
+ ['Monaco', 'mc', '377'],
195
+ ['Mongolia (Монгол)', 'mn', '976'],
196
+ ['Montenegro (Crna Gora)', 'me', '382'],
197
+ ['Montserrat', 'ms', '1', 16, ['664']],
198
+ ['Morocco (‫المغرب‬‎)', 'ma', '212', 0],
199
+ ['Mozambique (Moçambique)', 'mz', '258'],
200
+ ['Myanmar (Burma) (မြန်မာ)', 'mm', '95'],
201
+ ['Namibia (Namibië)', 'na', '264'],
202
+ ['Nauru', 'nr', '674'],
203
+ ['Nepal (नेपाल)', 'np', '977'],
204
+ ['Netherlands (Nederland)', 'nl', '31'],
205
+ ['New Caledonia (Nouvelle-Calédonie)', 'nc', '687'],
206
+ ['New Zealand', 'nz', '64'],
207
+ ['Nicaragua', 'ni', '505'],
208
+ ['Niger (Nijar)', 'ne', '227'],
209
+ ['Nigeria', 'ng', '234'],
210
+ ['Niue', 'nu', '683'],
211
+ ['Norfolk Island', 'nf', '672'],
212
+ ['North Korea (조선 민주주의 인민 공화국)', 'kp', '850'],
213
+ ['Northern Mariana Islands', 'mp', '1', 17, ['670']],
214
+ ['Norway (Norge)', 'no', '47', 0],
215
+ ['Oman (‫عُمان‬‎)', 'om', '968'],
216
+ ['Pakistan (‫پاکستان‬‎)', 'pk', '92'],
217
+ ['Palau', 'pw', '680'],
218
+ ['Palestine (‫فلسطين‬‎)', 'ps', '970'],
219
+ ['Panama (Panamá)', 'pa', '507'],
220
+ ['Papua New Guinea', 'pg', '675'],
221
+ ['Paraguay', 'py', '595'],
222
+ ['Peru (Perú)', 'pe', '51'],
223
+ ['Philippines', 'ph', '63'],
224
+ ['Poland (Polska)', 'pl', '48'],
225
+ ['Portugal', 'pt', '351'],
226
+ ['Puerto Rico', 'pr', '1', 3, ['787', '939']],
227
+ ['Qatar (‫قطر‬‎)', 'qa', '974'],
228
+ ['Réunion (La Réunion)', 're', '262', 0],
229
+ ['Romania (România)', 'ro', '40'],
230
+ ['Russia (Россия)', 'ru', '7', 0],
231
+ ['Rwanda', 'rw', '250'],
232
+ ['Saint Barthélemy', 'bl', '590', 1],
233
+ ['Saint Helena', 'sh', '290'],
234
+ ['Saint Kitts and Nevis', 'kn', '1', 18, ['869']],
235
+ ['Saint Lucia', 'lc', '1', 19, ['758']],
236
+ ['Saint Martin (Saint-Martin (partie française))', 'mf', '590', 2],
237
+ ['Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)', 'pm', '508'],
238
+ ['Saint Vincent and the Grenadines', 'vc', '1', 20, ['784']],
239
+ ['Samoa', 'ws', '685'],
240
+ ['San Marino', 'sm', '378'],
241
+ ['São Tomé and Príncipe (São Tomé e Príncipe)', 'st', '239'],
242
+ ['Saudi Arabia (‫المملكة العربية السعودية‬‎)', 'sa', '966'],
243
+ ['Senegal (Sénégal)', 'sn', '221'],
244
+ ['Serbia (Србија)', 'rs', '381'],
245
+ ['Seychelles', 'sc', '248'],
246
+ ['Sierra Leone', 'sl', '232'],
247
+ ['Singapore', 'sg', '65'],
248
+ ['Sint Maarten', 'sx', '1', 21, ['721']],
249
+ ['Slovakia (Slovensko)', 'sk', '421'],
250
+ ['Slovenia (Slovenija)', 'si', '386'],
251
+ ['Solomon Islands', 'sb', '677'],
252
+ ['Somalia (Soomaaliya)', 'so', '252'],
253
+ ['South Africa', 'za', '27'],
254
+ ['South Korea (대한민국)', 'kr', '82'],
255
+ ['South Sudan (‫جنوب السودان‬‎)', 'ss', '211'],
256
+ ['Spain (España)', 'es', '34'],
257
+ ['Sri Lanka (ශ්‍රී ලංකාව)', 'lk', '94'],
258
+ ['Sudan (‫السودان‬‎)', 'sd', '249'],
259
+ ['Suriname', 'sr', '597'],
260
+ ['Svalbard and Jan Mayen', 'sj', '47', 1, ['79']],
261
+ ['Sweden (Sverige)', 'se', '46'],
262
+ ['Switzerland (Schweiz)', 'ch', '41'],
263
+ ['Syria (‫سوريا‬‎)', 'sy', '963'],
264
+ ['Taiwan (台灣)', 'tw', '886'],
265
+ ['Tajikistan', 'tj', '992'],
266
+ ['Tanzania', 'tz', '255'],
267
+ ['Thailand (ไทย)', 'th', '66'],
268
+ ['Timor-Leste', 'tl', '670'],
269
+ ['Togo', 'tg', '228'],
270
+ ['Tokelau', 'tk', '690'],
271
+ ['Tonga', 'to', '676'],
272
+ ['Trinidad and Tobago', 'tt', '1', 22, ['868']],
273
+ ['Tunisia (‫تونس‬‎)', 'tn', '216'],
274
+ ['Turkey (Türkiye)', 'tr', '90'],
275
+ ['Turkmenistan', 'tm', '993'],
276
+ ['Turks and Caicos Islands', 'tc', '1', 23, ['649']],
277
+ ['Tuvalu', 'tv', '688'],
278
+ ['U.S. Virgin Islands', 'vi', '1', 24, ['340']],
279
+ ['Uganda', 'ug', '256'],
280
+ ['Ukraine (Україна)', 'ua', '380'],
281
+ ['United Arab Emirates (‫الإمارات العربية المتحدة‬‎)', 'ae', '971'],
282
+ ['United Kingdom', 'gb', '44', 0],
283
+ ['United States', 'us', '1', 0],
284
+ ['Uruguay', 'uy', '598'],
285
+ ['Uzbekistan (Oʻzbekiston)', 'uz', '998'],
286
+ ['Vanuatu', 'vu', '678'],
287
+ ['Vatican City (Città del Vaticano)', 'va', '39', 1, ['06698']],
288
+ ['Venezuela', 've', '58'],
289
+ ['Vietnam (Việt Nam)', 'vn', '84'],
290
+ ['Wallis and Futuna (Wallis-et-Futuna)', 'wf', '681'],
291
+ ['Western Sahara (‫الصحراء الغربية‬‎)', 'eh', '212', 1, ['5288', '5289']],
292
+ ['Yemen (‫اليمن‬‎)', 'ye', '967'],
293
+ ['Zambia', 'zm', '260'],
294
+ ['Zimbabwe', 'zw', '263'],
295
+ ['Åland Islands', 'ax', '358', 1, ['18']]
296
+ ];
297
+ const restructuredCountries = allCountries.map((country) => {
298
+ return {
299
+ name: country[0],
300
+ iso2: country[1],
301
+ dialCode: country[2],
302
+ priority: country[3] || 0,
303
+ areaCodes: country[4] || null
304
+ };
305
+ });
306
+ export default restructuredCountries;
@@ -0,0 +1,23 @@
1
+ <script >import { enteredTelInputStore } from '../../stores';
2
+ import { parsePhoneNumberWithError, ParseError } from 'libphonenumber-js';
3
+ export let enteredTelInput;
4
+ const handleInput = (event) => {
5
+ const inputVal = event.target.value;
6
+ enteredTelInput = inputVal;
7
+ $enteredTelInputStore = inputVal;
8
+ try {
9
+ const phoneNumber = parsePhoneNumberWithError(inputVal);
10
+ }
11
+ catch (error) {
12
+ if (error instanceof ParseError) {
13
+ // Not a phone number, non-existent country, etc.
14
+ console.log(error.message);
15
+ }
16
+ else {
17
+ throw error;
18
+ }
19
+ }
20
+ };
21
+ </script>
22
+
23
+ <input class={$$props.class} type="tel" on:input={handleInput} />
@@ -0,0 +1,17 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ enteredTelInput: string;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export declare type TelInputProps = typeof __propDef.props;
13
+ export declare type TelInputEvents = typeof __propDef.events;
14
+ export declare type TelInputSlots = typeof __propDef.slots;
15
+ export default class TelInput extends SvelteComponentTyped<TelInputProps, TelInputEvents, TelInputSlots> {
16
+ }
17
+ export {};
@@ -0,0 +1,41 @@
1
+ <script >import { clickOutsideAction } from '../../utils/directives/clickOutsideAction';
2
+ export let selectOptions = {
3
+ searchInput: false,
4
+ flags: true
5
+ };
6
+ export let items;
7
+ let isOpen = false;
8
+ let enteredSearch;
9
+ const toggleSelect = (e) => {
10
+ e === null || e === void 0 ? void 0 : e.preventDefault();
11
+ isOpen = !isOpen;
12
+ };
13
+ const closeSelect = (e) => {
14
+ e === null || e === void 0 ? void 0 : e.preventDefault();
15
+ isOpen = false;
16
+ };
17
+ </script>
18
+
19
+ <div class="select cursor-pointer" use:clickOutsideAction={closeSelect}>
20
+ <div on:click={() => toggleSelect()}>CHOOSE</div>
21
+ {#if isOpen}
22
+ <ul class="border border-gray-900 max-h-40 w-fit overflow-y-scroll">
23
+ {#if !selectOptions.searchInput}
24
+ <input
25
+ type="text"
26
+ class="px-4 py-1 text-gray-900 focus:outline-none w-full"
27
+ bind:value={enteredSearch}
28
+ />
29
+ {/if}
30
+ {#each items as item}
31
+ <li class="p-2 bg-gray-600 hover:bg-opacity-30">
32
+ <span class="mr-3">{item.name}</span> +{item.dialCode}
33
+ </li>
34
+ {:else}
35
+ <div>List is on the way..</div>
36
+ {/each}
37
+ </ul>
38
+ {/if}
39
+ </div>
40
+
41
+ <style ></style>
@@ -0,0 +1,21 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { Country } from '../../models/interfaces/Country.interface';
3
+ declare const __propDef: {
4
+ props: {
5
+ selectOptions?: {
6
+ searchInput: boolean;
7
+ flags: boolean;
8
+ } | undefined;
9
+ items: Country[];
10
+ };
11
+ events: {
12
+ [evt: string]: CustomEvent<any>;
13
+ };
14
+ slots: {};
15
+ };
16
+ export declare type SelectProps = typeof __propDef.props;
17
+ export declare type SelectEvents = typeof __propDef.events;
18
+ export declare type SelectSlots = typeof __propDef.slots;
19
+ export default class Select extends SvelteComponentTyped<SelectProps, SelectEvents, SelectSlots> {
20
+ }
21
+ export {};
@@ -0,0 +1,10 @@
1
+ <script >import { createEventDispatcher } from 'svelte';
2
+ const dispatch = createEventDispatcher();
3
+ const setSelected = (e) => {
4
+ dispatch('selectedItem');
5
+ };
6
+ </script>
7
+
8
+ <li on:click={setSelected}>
9
+ <slot />
10
+ </li>
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {};
4
+ events: {
5
+ selectedItem: CustomEvent<any>;
6
+ } & {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {
10
+ default: {};
11
+ };
12
+ };
13
+ export declare type SelectListItemProps = typeof __propDef.props;
14
+ export declare type SelectListItemEvents = typeof __propDef.events;
15
+ export declare type SelectListItemSlots = typeof __propDef.slots;
16
+ export default class SelectListItem extends SvelteComponentTyped<SelectListItemProps, SelectListItemEvents, SelectListItemSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,56 @@
1
+ <script >import { selectedCountryStore } from '../../../stores';
2
+ export let selectedCountry;
3
+ const setSelectedCountry = (value) => {
4
+ selectedCountry = value;
5
+ $selectedCountryStore = value;
6
+ };
7
+ // const getCountries = (list = []) => {
8
+ // return list.map((countryCode) => findCountry(countryCode)).filter(Boolean);
9
+ // };
10
+ // const findCountry = (iso: string) => {
11
+ // return filteredCountries.find((country) => country.iso2 === iso.toUpperCase());
12
+ // };
13
+ // const findCountryByDialCode = (dialCode: any) => {
14
+ // return filteredCountries.find((country) => Number(country.dialCode) === dialCode);
15
+ // };
16
+ // $: filteredCountries = () => {
17
+ // // List countries after filtered
18
+ // if (onlyCountries.length) {
19
+ // return allCountries.filter(({ iso2 }) =>
20
+ // onlyCountries.some((c) => c.toUpperCase() === iso2)
21
+ // );
22
+ // }
23
+ // if (ignoredCountries.length) {
24
+ // return allCountries.filter(
25
+ // ({ iso2 }) =>
26
+ // !ignoredCountries.includes(iso2.toUpperCase()) &&
27
+ // !ignoredCountries.includes(iso2.toLowerCase())
28
+ // );
29
+ // }
30
+ // return allCountries;
31
+ // };
32
+ // $: sortedCountries = () => {
33
+ // // Sort the list countries: from preferred countries to all countries
34
+ // const preferredCountries = getCountries(preferredCountries).map((country) => ({
35
+ // ...country,
36
+ // preferred: true
37
+ // }));
38
+ // return [...preferredCountries, ...filteredCountries];
39
+ // };
40
+ // const getDefault(key: string) => {
41
+ // const value = utils.options[key];
42
+ // if (typeof value === 'undefined') {
43
+ // return utils.options[key];
44
+ // }
45
+ // return value;
46
+ // }
47
+ </script>
48
+
49
+ <select
50
+ name="country_select"
51
+ class="some-class {$$props.class}"
52
+ on:change={(e) => setSelectedCountry(e.currentTarget.value)}
53
+ bind:value={selectedCountry}
54
+ >
55
+ <slot name="options" />
56
+ </select>
@@ -0,0 +1,19 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ selectedCountry: string;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {
11
+ options: {};
12
+ };
13
+ };
14
+ export declare type TelCountrySelectProps = typeof __propDef.props;
15
+ export declare type TelCountrySelectEvents = typeof __propDef.events;
16
+ export declare type TelCountrySelectSlots = typeof __propDef.slots;
17
+ export default class TelCountrySelect extends SvelteComponentTyped<TelCountrySelectProps, TelCountrySelectEvents, TelCountrySelectSlots> {
18
+ }
19
+ export {};
@@ -0,0 +1,12 @@
1
+ <script >"use strict";
2
+ let selectedTelRegion;
3
+ </script>
4
+
5
+ <select
6
+ name="region_select"
7
+ class={$$props.class}
8
+ bind:value={selectedTelRegion}
9
+ on:change={() => console.log(selectedTelRegion)}
10
+ >
11
+ <slot name="options" />
12
+ </select>
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ };
6
+ events: {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {
10
+ options: {};
11
+ };
12
+ };
13
+ export declare type TelRegionSelectProps = typeof __propDef.props;
14
+ export declare type TelRegionSelectEvents = typeof __propDef.events;
15
+ export declare type TelRegionSelectSlots = typeof __propDef.slots;
16
+ export default class TelRegionSelect extends SvelteComponentTyped<TelRegionSelectProps, TelRegionSelectEvents, TelRegionSelectSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,4 @@
1
+ <script >export let regionOption;
2
+ </script>
3
+
4
+ <option class={$$props.class} value={regionOption.value}>{regionOption.label}</option>
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { SelectObject } from '../../../models/interfaces/Select.interface';
3
+ declare const __propDef: {
4
+ props: {
5
+ [x: string]: any;
6
+ regionOption: SelectObject;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export declare type TelRegionSelectOptionProps = typeof __propDef.props;
14
+ export declare type TelRegionSelectOptionEvents = typeof __propDef.events;
15
+ export declare type TelRegionSelectOptionSlots = typeof __propDef.slots;
16
+ export default class TelRegionSelectOption extends SvelteComponentTyped<TelRegionSelectOptionProps, TelRegionSelectOptionEvents, TelRegionSelectOptionSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,15 @@
1
+ <script >import { selectedTelTypeStore } from '../../../stores';
2
+ export let selectedTelType;
3
+ const setSelectedCountry = (value) => {
4
+ selectedTelType = value;
5
+ $selectedTelTypeStore = value;
6
+ };
7
+ </script>
8
+
9
+ <select
10
+ name="type_select"
11
+ class={$$props.class}
12
+ on:change={(e) => setSelectedCountry(e.currentTarget.value)}
13
+ >
14
+ <slot name="options" />
15
+ </select>
@@ -0,0 +1,20 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { SelectType } from '../../../models/types/Select.type';
3
+ declare const __propDef: {
4
+ props: {
5
+ [x: string]: any;
6
+ selectedTelType: SelectType;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {
12
+ options: {};
13
+ };
14
+ };
15
+ export declare type TelTypeSelectProps = typeof __propDef.props;
16
+ export declare type TelTypeSelectEvents = typeof __propDef.events;
17
+ export declare type TelTypeSelectSlots = typeof __propDef.slots;
18
+ export default class TelTypeSelect extends SvelteComponentTyped<TelTypeSelectProps, TelTypeSelectEvents, TelTypeSelectSlots> {
19
+ }
20
+ export {};
@@ -0,0 +1,4 @@
1
+ <script >export let typeOption;
2
+ </script>
3
+
4
+ <option class={$$props.class} value={typeOption.value}>{typeOption.label}</option>
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { SelectObject } from '../../../models/interfaces/Select.interface';
3
+ declare const __propDef: {
4
+ props: {
5
+ [x: string]: any;
6
+ typeOption: SelectObject;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export declare type TelTypeSelectOptionProps = typeof __propDef.props;
14
+ export declare type TelTypeSelectOptionEvents = typeof __propDef.events;
15
+ export declare type TelTypeSelectOptionSlots = typeof __propDef.slots;
16
+ export default class TelTypeSelectOption extends SvelteComponentTyped<TelTypeSelectOptionProps, TelTypeSelectOptionEvents, TelTypeSelectOptionSlots> {
17
+ }
18
+ export {};
package/index.d.ts CHANGED
@@ -1,2 +1,8 @@
1
- export { default as LazyLoad } from './components/LazyLoad/LazyLoad.svelte';
2
- export { default as PhoneInput } from './components/Input/SvelteTelInput.svelte';
1
+ export { default as TelCountrySelect } from "./components/Select/TelCountrySelect/TelCountrySelect.svelte";
2
+ export { default as SelectListItem } from "./components/Select/SelectListItem.svelte";
3
+ export { default as TelTypeSelect } from "./components/Select/TelTypeSelect/TelTypeSelect.svelte";
4
+ export { default as TelTypeSelectOption } from "./components/Select/TelTypeSelect/TelTypeSelectOption.svelte";
5
+ export { default as Select } from "./components/Select/Select.svelte";
6
+ export { default as TelRegionSelect } from "./components/Select/TelRegionSelect/TelRegionSelect.svelte";
7
+ export { default as TelRegionSelectOption } from "./components/Select/TelRegionSelect/TelRegionSelectOption.svelte";
8
+ export { default as TelInput } from "./components/Input/TelInput.svelte";
package/index.js CHANGED
@@ -1,2 +1,8 @@
1
- export { default as LazyLoad } from './components/LazyLoad/LazyLoad.svelte';
2
- export { default as PhoneInput } from './components/Input/SvelteTelInput.svelte';
1
+ export { default as TelCountrySelect } from './components/Select/TelCountrySelect/TelCountrySelect.svelte';
2
+ export { default as SelectListItem } from './components/Select/SelectListItem.svelte';
3
+ export { default as TelTypeSelect } from './components/Select/TelTypeSelect/TelTypeSelect.svelte';
4
+ export { default as TelTypeSelectOption } from './components/Select/TelTypeSelect/TelTypeSelectOption.svelte';
5
+ export { default as Select } from './components/Select/Select.svelte';
6
+ export { default as TelRegionSelect } from './components/Select/TelRegionSelect/TelRegionSelect.svelte';
7
+ export { default as TelRegionSelectOption } from './components/Select/TelRegionSelect/TelRegionSelectOption.svelte';
8
+ export { default as TelInput } from './components/Input/TelInput.svelte';
@@ -0,0 +1,7 @@
1
+ export interface Country {
2
+ name: string;
3
+ iso2: string | number | string[];
4
+ dialCode: string | number | string[];
5
+ priority: string | number | string[];
6
+ areaCodes: string | number | string[] | null;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,8 @@
1
1
  import type { SvelteComponentTyped } from 'svelte';
2
2
  export declare type DynamicSvelteComponent = {
3
3
  component: typeof SvelteComponentTyped;
4
- props?: Record<string, any>;
5
- slot?: any;
6
- click?: any;
7
- input?: any;
4
+ props?: Record<string, any> | string | number | null;
5
+ slot?: SvelteComponentTyped;
6
+ click?: MouseEvent;
7
+ input?: InputEvent;
8
8
  };
@@ -1,16 +1 @@
1
1
  export {};
2
- // declare const __propDef: {
3
- // props: {};
4
- // slots: {};
5
- // events: {
6
- // [evt: string]: CustomEvent<any>;
7
- // };
8
- // };
9
- // export declare type DynamicSvelteComponentProps = typeof __propDef.props;
10
- // export declare type DynamicSvelteComponentEvents = typeof __propDef.events;
11
- // export declare type DynamicSvelteComponentSlots = typeof __propDef.slots;
12
- // export default class DynamicSvelteComponent extends SvelteComponentTyped<
13
- // DynamicSvelteComponentProps,
14
- // DynamicSvelteComponentEvents,
15
- // DynamicSvelteComponentSlots
16
- // > {}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "svelte-tel-input",
3
3
  "description": "svelte-tel-input",
4
- "version": "0.4.2",
4
+ "version": "0.6.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/gyurielf/svelte-tel-input.git"
@@ -17,57 +17,54 @@
17
17
  ],
18
18
  "engines": {
19
19
  "npm": ">= 7",
20
- "yarn": "please-use-npm",
20
+ "yarn": ">=2",
21
21
  "node": ">= 16"
22
22
  },
23
23
  "dependencies": {
24
- "libphonenumber-js": "^1.9.44"
24
+ "libphonenumber-js": "^1.9.50"
25
25
  },
26
26
  "devDependencies": {
27
- "@babel/core": "^7.16.10",
28
- "@babel/preset-env": "^7.16.10",
29
- "@changesets/cli": "^2.19.0",
27
+ "@babel/core": "^7.17.8",
28
+ "@babel/preset-env": "^7.16.11",
29
+ "@changesets/cli": "^2.21.1",
30
30
  "@changesets/get-github-info": "^0.5.0",
31
- "@changesets/types": "^4.0.2",
32
- "@sveltejs/adapter-static": "^1.0.0-next.26",
33
- "@sveltejs/kit": "^1.0.0-next.234",
34
- "@testing-library/jest-dom": "^5.16.1",
35
- "@testing-library/svelte": "^3.0.3",
36
- "@types/jest": "^27.4.0",
37
- "@typescript-eslint/eslint-plugin": "^5.10.0",
38
- "@typescript-eslint/parser": "^5.10.0",
39
- "autoprefixer": "^10.4.2",
40
- "babel-jest": "^27.4.6",
41
- "babel-loader": "^8.2.3",
42
- "commitizen": "^4.2.4",
43
- "cssnano": "^5.0.15",
44
- "dotenv": "^14.2.0",
45
- "eslint": "^8.7.0",
46
- "eslint-config-prettier": "^8.3.0",
47
- "eslint-plugin-jest": "^25.7.0",
48
- "eslint-plugin-svelte3": "^3.4.0",
31
+ "@changesets/types": "^4.1.0",
32
+ "@sveltejs/adapter-static": "^1.0.0-next.29",
33
+ "@sveltejs/kit": "^1.0.0-next.303",
34
+ "@testing-library/jest-dom": "^5.16.3",
35
+ "@testing-library/svelte": "^3.1.0",
36
+ "@types/jest": "^27.4.1",
37
+ "@typescript-eslint/eslint-plugin": "^5.16.0",
38
+ "@typescript-eslint/parser": "^5.16.0",
39
+ "autoprefixer": "^10.4.4",
40
+ "babel-jest": "^27.5.1",
41
+ "babel-loader": "^8.2.4",
42
+ "cssnano": "^5.1.5",
43
+ "dotenv": "^16.0.0",
44
+ "eslint": "^8.12.0",
45
+ "eslint-config-prettier": "^8.5.0",
46
+ "eslint-plugin-jest": "^26.1.3",
47
+ "eslint-plugin-svelte3": "^3.4.1",
49
48
  "husky": "^7.0.4",
50
- "jest": "^27.4.7",
49
+ "jest": "^27.5.1",
51
50
  "jest-matchmedia-mock": "^1.1.0",
52
- "micromatch": "^4.0.4",
53
- "postcss": "^8.4.5",
54
- "postcss-load-config": "^3.1.1",
55
- "prettier": "^2.5.1",
51
+ "micromatch": "^4.0.5",
52
+ "postcss": "^8.4.12",
53
+ "postcss-load-config": "^3.1.3",
54
+ "prettier": "^2.6.1",
56
55
  "prettier-plugin-svelte": "^2.6.0",
57
- "standard-changelog": "^2.0.27",
58
- "standard-version": "^9.3.2",
59
- "svelte": "^3.46.2",
60
- "svelte-check": "^2.3.0",
61
- "svelte-inview": "^2.1.1",
62
- "svelte-jester": "^2.1.5",
56
+ "svelte": "^3.46.4",
57
+ "svelte-check": "^2.4.6",
58
+ "svelte-inview": "^3.0.0",
59
+ "svelte-jester": "^2.3.2",
63
60
  "svelte-loader": "^3.1.2",
64
- "svelte-preprocess": "^4.10.2",
65
- "svelte2tsx": "^0.4.14",
66
- "tailwindcss": "^3.0.15",
67
- "ts-jest": "^27.1.3",
61
+ "svelte-preprocess": "^4.10.4",
62
+ "svelte2tsx": "^0.5.6",
63
+ "tailwindcss": "^3.0.23",
64
+ "ts-jest": "^27.1.4",
68
65
  "tsconfig-paths-webpack-plugin": "^3.5.2",
69
66
  "tslib": "^2.3.1",
70
- "typescript": "^4.5.4"
67
+ "typescript": "^4.6.3"
71
68
  },
72
69
  "standard-version": {
73
70
  "skip": {
@@ -141,20 +138,29 @@
141
138
  "license": "MIT",
142
139
  "exports": {
143
140
  "./package.json": "./package.json",
141
+ "./assets/allCountry": "./assets/allCountry.js",
144
142
  "./assets/countries": "./assets/countries.js",
145
143
  "./assets/regions": "./assets/regions.js",
146
- "./components/Input/SvelteTelInput.svelte": "./components/Input/SvelteTelInput.svelte",
147
- "./components/Select/CountrySelect.svelte": "./components/Select/CountrySelect.svelte",
148
- "./components/Select/RegionSelect.svelte": "./components/Select/RegionSelect.svelte",
144
+ "./components/Input/TelInput.svelte": "./components/Input/TelInput.svelte",
145
+ "./components/Select/Select.svelte": "./components/Select/Select.svelte",
146
+ "./components/Select/SelectListItem.svelte": "./components/Select/SelectListItem.svelte",
147
+ "./components/Select/TelCountrySelect/TelCountrySelect.svelte": "./components/Select/TelCountrySelect/TelCountrySelect.svelte",
148
+ "./components/Select/TelRegionSelect/TelRegionSelect.svelte": "./components/Select/TelRegionSelect/TelRegionSelect.svelte",
149
+ "./components/Select/TelRegionSelect/TelRegionSelectOption.svelte": "./components/Select/TelRegionSelect/TelRegionSelectOption.svelte",
150
+ "./components/Select/TelTypeSelect/TelTypeSelect.svelte": "./components/Select/TelTypeSelect/TelTypeSelect.svelte",
151
+ "./components/Select/TelTypeSelect/TelTypeSelectOption.svelte": "./components/Select/TelTypeSelect/TelTypeSelectOption.svelte",
149
152
  ".": "./index.js",
150
153
  "./models/enums/PhoneType.enum": "./models/enums/PhoneType.enum.js",
151
154
  "./models/enums": "./models/enums/index.js",
152
155
  "./models": "./models/index.js",
156
+ "./models/interfaces/Country.interface": "./models/interfaces/Country.interface.js",
153
157
  "./models/interfaces/Select.interface": "./models/interfaces/Select.interface.js",
154
158
  "./models/types/DynamicSvelteComponent.type": "./models/types/DynamicSvelteComponent.type.js",
155
159
  "./models/types/Select.type": "./models/types/Select.type.js",
156
160
  "./stores": "./stores/index.js",
161
+ "./utils/api": "./utils/api.js",
157
162
  "./utils/directives/clickOutsideAction": "./utils/directives/clickOutsideAction.js",
163
+ "./utils/helpers": "./utils/helpers.js",
158
164
  "./utils/simulator": "./utils/simulator.js",
159
165
  "./utils/typeCheck": "./utils/typeCheck.js"
160
166
  }
package/stores/index.d.ts CHANGED
@@ -1,11 +1,17 @@
1
+ import type { Writable } from 'svelte/store';
2
+ import type { SelectType } from '../models/types/Select.type';
1
3
  export declare const booleanStore: (initial: boolean) => {
2
- isOpen: import("svelte/store").Writable<boolean>;
4
+ isOpen: Writable<boolean>;
3
5
  open: () => void;
4
6
  close: () => void;
5
7
  toggle: () => void;
6
8
  };
7
9
  export declare const statefulSwap: (initialState: boolean | null) => {
8
- transitionState: import("svelte/store").Writable<boolean | null>;
10
+ transitionState: Writable<boolean | null>;
9
11
  transitionTo: (newState: boolean | null) => void;
10
12
  onOutro: () => void;
11
13
  };
14
+ export declare const selectedCountryStore: Writable<string>;
15
+ export declare const selectedRegionStore: Writable<string>;
16
+ export declare const selectedTelTypeStore: Writable<SelectType>;
17
+ export declare const enteredTelInputStore: Writable<string>;
package/stores/index.js CHANGED
@@ -29,3 +29,9 @@ export const statefulSwap = (initialState) => {
29
29
  onOutro
30
30
  };
31
31
  };
32
+ // SELECTS
33
+ export const selectedCountryStore = writable();
34
+ export const selectedRegionStore = writable();
35
+ export const selectedTelTypeStore = writable();
36
+ // INPUT
37
+ export const enteredTelInputStore = writable();
package/utils/api.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ export declare const get: (base: string, path: string) => Promise<{
2
+ response: Response;
3
+ json?: undefined;
4
+ } | {
5
+ response: Response;
6
+ json: Record<string, any>;
7
+ }>;
8
+ export declare const del: (base: string, path: string, data?: any) => Promise<{
9
+ response: Response;
10
+ json?: undefined;
11
+ } | {
12
+ response: Response;
13
+ json: Record<string, any>;
14
+ }>;
15
+ export declare const post: (base: string, path: string, data?: any) => Promise<{
16
+ response: Response;
17
+ json?: undefined;
18
+ } | {
19
+ response: Response;
20
+ json: Record<string, any>;
21
+ }>;
22
+ export declare const put: (base: string, path: string, data?: any) => Promise<{
23
+ response: Response;
24
+ json?: undefined;
25
+ } | {
26
+ response: Response;
27
+ json: Record<string, any>;
28
+ }>;
package/utils/api.js ADDED
@@ -0,0 +1,30 @@
1
+ const send = async ({ method, path, data, base }) => {
2
+ const opts = { method, headers: {}, credentials: 'include' };
3
+ if (data) {
4
+ opts.headers['content-type'] = 'application/json';
5
+ opts.body = JSON.stringify(data);
6
+ }
7
+ const fullPath = encodeURI(`${base}${path}`);
8
+ const response = await fetch(fullPath, opts);
9
+ if (response.status === 204) {
10
+ return { response };
11
+ }
12
+ if (response.headers.get('content-type') === 'application/json') {
13
+ const json = await response.json();
14
+ return { response, json };
15
+ }
16
+ return { response };
17
+ };
18
+ // Shortcut methods
19
+ export const get = (base, path) => {
20
+ return send({ method: 'GET', path, base });
21
+ };
22
+ export const del = (base, path, data) => {
23
+ return send({ method: 'DELETE', path, data, base });
24
+ };
25
+ export const post = (base, path, data) => {
26
+ return send({ method: 'POST', path, data, base });
27
+ };
28
+ export const put = (base, path, data) => {
29
+ return send({ method: 'PUT', path, data, base });
30
+ };
@@ -0,0 +1,2 @@
1
+ export declare const capitalize: (str: string) => string;
2
+ export declare const getCurrentCountry: () => Promise<string>;
@@ -0,0 +1,11 @@
1
+ export const capitalize = (str) => {
2
+ return (str && str[0].toUpperCase() + str.slice(1).toLowerCase()) || '';
3
+ };
4
+ export const getCurrentCountry = async () => {
5
+ const response = await (await fetch('https://ip2c.org/s')).text();
6
+ const result = (response || '').toString();
7
+ if (!result || result[0] !== '1') {
8
+ throw new Error('Unable to fetch the country');
9
+ }
10
+ return result.substring(2, 4);
11
+ };
@@ -1,23 +0,0 @@
1
- <script >import { parsePhoneNumberFromString } from 'libphonenumber-js';
2
- let telInputNumber;
3
- // const phoneNumber = parsePhoneNumber(' 8 (800) 555-35-35 ', 'RU');
4
- // if (phoneNumber) {
5
- // phoneNumber.country === 'RU';
6
- // phoneNumber.number === '+78005553535';
7
- // phoneNumber.isValid() === true;
8
- // // Note: `.getType()` requires `/max` metadata: see below for an explanation.
9
- // phoneNumber.getType() === 'TOLL_FREE';
10
- // }
11
- // const parse = parsePhoneNumber(telInputNumber);
12
- const handleInput = (event) => {
13
- let inputVal = event.target.value;
14
- console.log(parsePhoneNumberFromString(inputVal));
15
- };
16
- $: console.log(telInputNumber);
17
- </script>
18
-
19
- <input
20
- class="px-4 py-1 text-gray-900 rounded-full focus:outline-none"
21
- type="tel"
22
- on:input={handleInput}
23
- />
@@ -1,14 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {};
4
- events: {
5
- [evt: string]: CustomEvent<any>;
6
- };
7
- slots: {};
8
- };
9
- export declare type SvelteTelInputProps = typeof __propDef.props;
10
- export declare type SvelteTelInputEvents = typeof __propDef.events;
11
- export declare type SvelteTelInputSlots = typeof __propDef.slots;
12
- export default class SvelteTelInput extends SvelteComponentTyped<SvelteTelInputProps, SvelteTelInputEvents, SvelteTelInputSlots> {
13
- }
14
- export {};
@@ -1,14 +0,0 @@
1
- <script >import rawCountries from '../../assets/countries';
2
- let selectedCountry;
3
- </script>
4
-
5
- <select
6
- name="countrySelect"
7
- class="text-gray-700"
8
- bind:value={selectedCountry}
9
- on:change={() => console.log(selectedCountry)}
10
- >
11
- {#each rawCountries as country}
12
- <option value={country[2]}>{country[0]}</option>
13
- {/each}
14
- </select>
@@ -1,14 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {};
4
- events: {
5
- [evt: string]: CustomEvent<any>;
6
- };
7
- slots: {};
8
- };
9
- export declare type CountrySelectProps = typeof __propDef.props;
10
- export declare type CountrySelectEvents = typeof __propDef.events;
11
- export declare type CountrySelectSlots = typeof __propDef.slots;
12
- export default class CountrySelect extends SvelteComponentTyped<CountrySelectProps, CountrySelectEvents, CountrySelectSlots> {
13
- }
14
- export {};
@@ -1,14 +0,0 @@
1
- <script >import rawRegions from '../../assets/regions';
2
- let selectedRegion;
3
- </script>
4
-
5
- <select
6
- name="countrySelect"
7
- class="text-gray-700"
8
- bind:value={selectedRegion}
9
- on:change={() => console.log(selectedRegion)}
10
- >
11
- {#each rawRegions as region}
12
- <option value={region[2]}>{region[0]}</option>
13
- {/each}
14
- </select>
@@ -1,14 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {};
4
- events: {
5
- [evt: string]: CustomEvent<any>;
6
- };
7
- slots: {};
8
- };
9
- export declare type RegionSelectProps = typeof __propDef.props;
10
- export declare type RegionSelectEvents = typeof __propDef.events;
11
- export declare type RegionSelectSlots = typeof __propDef.slots;
12
- export default class RegionSelect extends SvelteComponentTyped<RegionSelectProps, RegionSelectEvents, RegionSelectSlots> {
13
- }
14
- export {};