@descope/web-components-ui 2.2.34 → 2.2.35

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/index.esm.js CHANGED
@@ -15,7 +15,7 @@ import '@vaadin/email-field';
15
15
  import '@vaadin/number-field';
16
16
  import '@vaadin/password-field';
17
17
  import '@vaadin/text-area';
18
- import parsePhoneNumberFromString$1, { parsePhoneNumberFromString, AsYouType } from 'libphonenumber-js/min';
18
+ import parsePhoneNumberFromString$1, { AsYouType, parsePhoneNumberFromString } from 'libphonenumber-js/min';
19
19
  import '@vaadin/grid';
20
20
  import { GridSortColumn } from '@vaadin/grid/vaadin-grid-sort-column';
21
21
  import { GridSelectionColumn } from '@vaadin/grid/vaadin-grid-selection-column';
@@ -11020,32 +11020,6 @@ const comboBoxItem = ({ code, dialCode, name: country }) => `
11020
11020
  </div>
11021
11021
  `;
11022
11022
 
11023
- const parsePhoneNumber = (val) => {
11024
- const value = val || '';
11025
- let countryCode = '';
11026
- let phoneNumber = '';
11027
-
11028
- // Attempt to parse the value using libphonenumber-js
11029
- const parsed = parsePhoneNumberFromString(value);
11030
-
11031
- if (parsed) {
11032
- if (parsed.countryCallingCode) {
11033
- countryCode = `+${parsed.countryCallingCode}`;
11034
- }
11035
-
11036
- if (parsed.nationalNumber) {
11037
- phoneNumber = parsed.nationalNumber;
11038
- }
11039
- } else {
11040
- // Fallback: assume a dash separates country code and phone number
11041
- const [country, phone] = value.split('-');
11042
- countryCode = country || '';
11043
- phoneNumber = phone || '';
11044
- }
11045
-
11046
- return [countryCode, phoneNumber];
11047
- };
11048
-
11049
11023
  const componentName$Y = getComponentName('phone-field-internal');
11050
11024
 
11051
11025
  const commonAttrs$1 = ['disabled', 'size', 'bordered', 'readonly'];
@@ -11154,18 +11128,24 @@ let PhoneFieldInternal$1 = class PhoneFieldInternal extends BaseInputClass$9 {
11154
11128
  return '';
11155
11129
  }
11156
11130
 
11157
- const [countryCode, phoneNumber] = parsePhoneNumber(
11158
- `${this.comboBox.value}-${this.textField.value}`
11159
- );
11131
+ if (this.allowAlphanumericInput) {
11132
+ return `${this.comboBox.value}-${this.textField.value}`;
11133
+ }
11160
11134
 
11161
- return `${countryCode || this.comboBox.value}-${phoneNumber || this.textField.value}`;
11135
+ return `${this.comboBox.value}-${this.textField.value.replace(/\D+/g, '')}`;
11162
11136
  }
11163
11137
 
11164
11138
  set value(val) {
11165
- const [countryCode, nationalNumber] = parsePhoneNumber(val);
11139
+ const nationalNumber = val.replace(
11140
+ new RegExp(`^\\+?${this.comboBox.value.replace('+', '')}-?`),
11141
+ ''
11142
+ );
11166
11143
 
11167
- this.#setCountryCode(countryCode);
11168
- this.#setNationalNumber(nationalNumber);
11144
+ if (this.isFormatValue) {
11145
+ this.textField.value = this.#formatNationalNumber(nationalNumber);
11146
+ } else {
11147
+ this.textField.value = nationalNumber;
11148
+ }
11169
11149
  }
11170
11150
 
11171
11151
  init() {
@@ -11254,41 +11234,6 @@ let PhoneFieldInternal$1 = class PhoneFieldInternal extends BaseInputClass$9 {
11254
11234
 
11255
11235
  this.handleFocusEventsDispatching(this.inputs);
11256
11236
  this.handleInputEventDispatching();
11257
-
11258
- // verify country code item against phone number pattern and replace if needed and country is allowed
11259
- // (e.g. +1 can be US or CA, depending on the pattern)
11260
- this.addEventListener('input', this.#handleSameCountryCodes.bind(this));
11261
- }
11262
-
11263
- #setCountryCode(val) {
11264
- if (!val || val === this.selectedCountryCode) return;
11265
-
11266
- let countryCodeItem = undefined;
11267
-
11268
- if (this.value) {
11269
- // try to parse the phone number, and set country code item according to actual dial code (e.g. `+1` can be `US` or `CA`)
11270
- const code = this.#getCountryCodeByPhoneNumber(`${val}-${this.textField.value}`);
11271
- countryCodeItem = this.#getCountryByCodeId(code);
11272
- }
11273
-
11274
- // in case country code item does not exist (for example: Parsed code is CA for +1 - but Canada is not allowed)
11275
- // then use the first option with same dial code (e.g. in that case - `US` for +1)
11276
- if (!countryCodeItem) {
11277
- countryCodeItem = this.#getCountryByDialCode(val);
11278
- }
11279
-
11280
- // set country code item; in it doesn't exist in list - set `undefined`
11281
- this.comboBox.selectedItem = countryCodeItem;
11282
- }
11283
-
11284
- #setNationalNumber(val) {
11285
- if (this.isFormatValue) {
11286
- val = this.#formatNationalNumber(val);
11287
- }
11288
-
11289
- if (this.textField.value !== val) {
11290
- this.textField.value = val;
11291
- }
11292
11237
  }
11293
11238
 
11294
11239
  #formatNationalNumber(nationalNumber = '') {
@@ -11301,7 +11246,6 @@ let PhoneFieldInternal$1 = class PhoneFieldInternal extends BaseInputClass$9 {
11301
11246
  this.#ayt.reset();
11302
11247
 
11303
11248
  const formattedVal = this.#ayt.input(nationalNumber);
11304
-
11305
11249
  return formattedVal || nationalNumber;
11306
11250
  }
11307
11251
 
@@ -11324,24 +11268,11 @@ let PhoneFieldInternal$1 = class PhoneFieldInternal extends BaseInputClass$9 {
11324
11268
  return this.restrictCountries.includes(countryCode);
11325
11269
  }
11326
11270
 
11327
- // return country item by dial code `data-id` (e.g. `+1`)
11328
- #getCountryByDialCode(dialCode) {
11329
- return this.comboBox.items?.find((c) => c.getAttribute('data-id') === dialCode) || undefined;
11330
- }
11331
-
11332
11271
  // return country item by country code `data-country-code` (e.g. `US`)
11333
11272
  #getCountryByCodeId(countryCode) {
11334
11273
  return this.comboBox.items?.find((c) => c.getAttribute('data-country-code') === countryCode);
11335
11274
  }
11336
11275
 
11337
- #getCountryCodeByPhoneNumber(val) {
11338
- if (!val) return undefined;
11339
- const parsed = parsePhoneNumberFromString(val);
11340
- if (!parsed?.country) return undefined;
11341
- const foundCountryItem = this.#getCountryByCodeId(parsed.country);
11342
- return foundCountryItem?.getAttribute('data-country-code');
11343
- }
11344
-
11345
11276
  #updateComboBoxItems(restrictCountries) {
11346
11277
  const items = restrictCountries.length
11347
11278
  ? CountryCodes.filter((c) => restrictCountries.includes(c.code))
@@ -11366,23 +11297,6 @@ let PhoneFieldInternal$1 = class PhoneFieldInternal extends BaseInputClass$9 {
11366
11297
  }
11367
11298
  }
11368
11299
 
11369
- #handleSameCountryCodes() {
11370
- if (!this.value) return;
11371
-
11372
- const country = this.#getCountryCodeByPhoneNumber(this.value);
11373
-
11374
- if (!country) return;
11375
-
11376
- // re-set country code if needed (same coutnry code for different countries, e.g. +1 for US or CA)
11377
- if (this.selectedCountryCode !== country) {
11378
- const foundCountryItem = this.#getCountryByCodeId(country);
11379
- // if found country is defined in country list then set it, otherwise - clear phone number
11380
- if (foundCountryItem) {
11381
- this.comboBox.selectedItem = foundCountryItem;
11382
- }
11383
- }
11384
- }
11385
-
11386
11300
  #handleLabelTypeAttrs(attrName, newValue) {
11387
11301
  // set or remove label attributes from inner text/combo components on `label-type` change
11388
11302
  const attr = mapAttrs$1[attrName] || attrName;