@descope/web-components-ui 3.20.2 → 3.20.4

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
@@ -9007,25 +9007,80 @@ const DividerClass = compose(
9007
9007
 
9008
9008
  customElements.define(componentName$1i, DividerClass);
9009
9009
 
9010
+ // Kept in its own module (with no imports) so it can be unit tested without
9011
+ // pulling in the whole component / vaadin dependency chain.
9012
+
9013
+ const asciiPattern = "^[\\w\\.\\%\\+\\-']+@[\\w\\.\\-]+\\.[A-Za-z]{2,}$";
9014
+
9015
+ const unicodePattern =
9016
+ "^[\\p{L}\\p{M}\\p{N}._%+'\\-]+@[\\p{L}\\p{M}\\p{N}.\\-]+\\.[\\p{L}\\p{M}][\\p{L}\\p{M}\\p{N}\\-]+$";
9017
+
9010
9018
  const componentName$1h = getComponentName('email-field');
9011
9019
 
9012
- const defaultPattern = "^[\\w\\.\\%\\+\\-']+@[\\w\\.\\-]+\\.[A-Za-z]{2,}$";
9013
9020
  const defaultAutocomplete = 'username';
9021
+ const defaultInputMode = 'email';
9014
9022
 
9015
9023
  const customMixin$e = (superclass) =>
9016
9024
  class EmailFieldMixinClass extends superclass {
9025
+ // On by default - `accept-unicode="false"` restores the pre-unicode field:
9026
+ // native `type="email"` validation and the ASCII pattern.
9027
+ //
9028
+ // Read once, in `init`. Changing the attribute afterwards has no effect; it
9029
+ // is static configuration, which is how every consumer sets it.
9030
+ get acceptsUnicode() {
9031
+ return this.getAttribute('accept-unicode') !== 'false';
9032
+ }
9033
+
9017
9034
  init() {
9018
9035
  super.init?.();
9019
9036
 
9020
9037
  // we need to set the pattern on the base element because vaadin-email-field is overriding it
9021
- this.baseElement.setAttribute('pattern', defaultPattern);
9038
+ this.baseElement.setAttribute('pattern', asciiPattern);
9022
9039
 
9023
9040
  if (!this.getAttribute('autocomplete')) {
9024
9041
  this.setAttribute('autocomplete', defaultAutocomplete);
9025
9042
  }
9026
9043
 
9027
9044
  this.createExternalInput();
9045
+
9046
+ [this.inputElement, this.externalInput].filter(Boolean).forEach((input) => {
9047
+ input.addEventListener('change', this.stripSurroundingWhitespace);
9048
+ });
9049
+
9050
+ if (this.acceptsUnicode) {
9051
+ this.enableUnicode();
9052
+ }
9053
+ }
9054
+
9055
+ enableUnicode() {
9056
+ this.baseElement.setAttribute('pattern', unicodePattern);
9057
+
9058
+ // native `type="email"` validation is ASCII only and sets typeMismatch
9059
+ // before `pattern` is consulted, so `text` is what lets the pattern decide.
9060
+ // Through vaadin's `_setType` because `type` is a readOnly property bound
9061
+ // to the inner input - assigning `input.type` is re-applied over.
9062
+ this.baseElement._setType('text');
9063
+
9064
+ if (this.externalInput) {
9065
+ this.externalInput.type = 'text';
9066
+ }
9067
+
9068
+ // `type="text"` loses the email keyboard on mobile
9069
+ if (!this.getAttribute('inputmode')) {
9070
+ this.setAttribute('inputmode', defaultInputMode);
9071
+ }
9072
+
9073
+ this.externalInput?.setAttribute('inputmode', defaultInputMode);
9028
9074
  }
9075
+
9076
+ stripSurroundingWhitespace = (e) => {
9077
+ const trimmed = e.target.value.trim();
9078
+ if (trimmed === e.target.value) return;
9079
+ this.value = trimmed;
9080
+
9081
+ // validity is cached and was computed against the untrimmed value
9082
+ this.inputElement.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
9083
+ };
9029
9084
  };
9030
9085
 
9031
9086
  const EmailFieldClass = compose(