@descope/web-components-ui 1.0.78 → 1.0.79

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/dist/index.esm.js +47 -61
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/umd/878.js +1 -1
  4. package/dist/umd/988.js +1 -0
  5. package/dist/umd/descope-button-index-js.js +1 -1
  6. package/dist/umd/descope-checkbox-index-js.js +1 -1
  7. package/dist/umd/descope-combo-box-index-js.js +1 -1
  8. package/dist/umd/descope-container-index-js.js +1 -1
  9. package/dist/umd/descope-date-picker-index-js.js +1 -1
  10. package/dist/umd/descope-divider-index-js.js +1 -1
  11. package/dist/umd/descope-email-field-index-js.js +1 -1
  12. package/dist/umd/descope-image-index-js.js +1 -1
  13. package/dist/umd/descope-link-index-js.js +1 -1
  14. package/dist/umd/descope-loader-linear-index-js.js +1 -1
  15. package/dist/umd/descope-loader-radial-index-js.js +1 -1
  16. package/dist/umd/descope-logo-index-js.js +1 -1
  17. package/dist/umd/descope-number-field-index-js.js +1 -1
  18. package/dist/umd/descope-passcode-descope-passcode-internal-index-js.js +1 -1
  19. package/dist/umd/descope-passcode-index-js.js +1 -1
  20. package/dist/umd/descope-password-field-index-js.js +1 -1
  21. package/dist/umd/descope-phone-field-descope-phone-field-internal-index-js.js +1 -1
  22. package/dist/umd/descope-phone-field-index-js.js +1 -1
  23. package/dist/umd/descope-switch-toggle-index-js.js +1 -1
  24. package/dist/umd/descope-text-area-index-js.js +1 -1
  25. package/dist/umd/descope-text-field-index-js.js +1 -1
  26. package/dist/umd/descope-text-index-js.js +1 -1
  27. package/dist/umd/index.js +1 -1
  28. package/package.json +1 -1
  29. package/src/baseClasses/createBaseInputClass.js +1 -2
  30. package/src/components/descope-passcode/descope-passcode-internal/PasscodeInternal.js +0 -3
  31. package/src/components/descope-phone-field/descope-phone-field-internal/PhoneFieldInternal.js +0 -3
  32. package/src/mixins/index.js +0 -1
  33. package/src/mixins/inputEventsDispatchingMixin.js +48 -31
  34. package/dist/umd/933.js +0 -1
  35. package/src/mixins/focusMixin.js +0 -23
package/dist/index.esm.js CHANGED
@@ -902,30 +902,6 @@ const proxyInputMixin = (superclass) =>
902
902
  }
903
903
  };
904
904
 
905
- const focusMixin = (superclass) => class FocusMixinClass extends superclass {
906
- // we want to block all native events,
907
- // so the input can control when to dispatch it based on its internal behavior
908
- init() {
909
- super.init?.();
910
-
911
- this.addEventListener('blur', (e) => {
912
- e.isTrusted && e.stopImmediatePropagation();
913
- });
914
-
915
- this.addEventListener('focus', (e) => {
916
- e.isTrusted && e.stopImmediatePropagation();
917
- });
918
-
919
- this.addEventListener('focusout', (e) => {
920
- e.isTrusted && e.stopImmediatePropagation();
921
- });
922
-
923
- this.addEventListener('focusin', (e) => {
924
- e.isTrusted && e.stopImmediatePropagation();
925
- });
926
- }
927
- };
928
-
929
905
  // this is needed because we might generate the same css vars names
930
906
  // e.g. "overlayColor" attribute in style mixin's mapping,
931
907
  // will generate the same var as "color" attribute in portals's mapping
@@ -1032,53 +1008,70 @@ const readOnlyMixin = (superclass) => class ReadOnlyMixinClass extends superclas
1032
1008
  };
1033
1009
 
1034
1010
  const inputEventsDispatchingMixin = (superclass) => class InputEventsDispatchingMixinClass extends superclass {
1035
- handleFocusEventsDispatching(focusableElements = []) {
1036
- let blurTimerId;
1037
-
1038
- // in order to simulate blur on the input
1039
- // we are checking if focus on one of the other elements happened immediately after blur
1040
- // if not, the component is no longer focused and we should dispatch blur
1041
- focusableElements.forEach(ele => {
1042
- ele?.addEventListener('blur', (e) => {
1011
+ init() {
1012
+ this.#blockNativeEvents();
1013
+ this.#handleFocusEventsDispatching();
1014
+ this.#handleInputEventDispatching();
1015
+
1016
+ super.init?.();
1017
+ }
1018
+
1019
+ // we want to block the native (trusted) events and control when these events are being dispatched
1020
+ #blockNativeEvents() {
1021
+ ['blur', 'focus', 'focusin', 'focusout'].forEach(event => {
1022
+ this.addEventListener(event, (e) => {
1023
+ e.isTrusted && e.target === this && e.stopImmediatePropagation();
1024
+ });
1025
+ });
1026
+ }
1027
+
1028
+ #handleFocusEventsDispatching() {
1029
+ let timerId;
1030
+
1031
+ // in order to simulate blur & focusout on root input element
1032
+ // we are checking if focus on one of the inner elements happened immediately after blur
1033
+ // if not, the component is no longer focused and we should dispatch blur & focusout
1034
+ this.addEventListener('focusout', (e) => {
1035
+ if (e.isTrusted) {
1043
1036
  e.stopImmediatePropagation();
1044
- blurTimerId = setTimeout(() => {
1045
- blurTimerId = null;
1037
+ timerId = setTimeout(() => {
1038
+ timerId = null;
1046
1039
  createDispatchEvent.call(this, 'blur');
1047
1040
  createDispatchEvent.call(this, 'focusout', { bubbles: true });
1048
1041
  });
1049
- });
1042
+ }
1043
+ });
1050
1044
 
1051
- // in order to simulate focus on the input
1052
- // we are holding a blur timer id and clearing it on blur
1053
- // if there is a timer id, it means that there was no blur on the input, so it's still focused
1054
- // otherwise, it was not focused before, and we need to dispatch a focus event
1055
- ele?.addEventListener('focus', (e) => {
1045
+ // in order to simulate focus & focusin on the root input element
1046
+ // we are holding a timer id and clearing it on focusin
1047
+ // if there is a timer id, it means that the root input is still focused
1048
+ // otherwise, it was not focused before, and we should dispatch focus & focusin
1049
+ this.addEventListener('focusin', (e) => {
1050
+ if (e.isTrusted) {
1056
1051
  e.stopImmediatePropagation();
1057
- clearTimeout(blurTimerId);
1058
- if (!blurTimerId) {
1052
+ clearTimeout(timerId);
1053
+ if (!timerId) {
1059
1054
  createDispatchEvent.call(this, 'focus');
1060
1055
  createDispatchEvent.call(this, 'focusin', { bubbles: true });
1061
1056
  }
1062
- });
1057
+ }
1063
1058
  });
1064
1059
  }
1065
1060
 
1066
1061
  // we want to block the input events from propagating in case the value of the root input wasn't change
1067
1062
  // this can happen if we are sanitizing characters on the internal inputs and do not want it to affect the root input element value
1068
1063
  // in this case, on each input event, we are comparing the root input value to the previous one, and only if it does not match, we are allowing the input event to propagate
1069
- handleInputEventDispatching(inputElements) {
1064
+ #handleInputEventDispatching() {
1070
1065
  let previousRootComponentValue = this.value;
1071
1066
 
1072
- inputElements.forEach(input => {
1073
- input.addEventListener('input', (e) => {
1074
- // we are comparing the previous value to the new one,
1075
- // and if they have the same value, we are blocking the input event
1076
- if (previousRootComponentValue === this.value) {
1077
- e.stopImmediatePropagation();
1078
- } else {
1079
- previousRootComponentValue = this.value;
1080
- }
1081
- });
1067
+ this.addEventListener('input', (e) => {
1068
+ // we are comparing the previous value to the new one,
1069
+ // and if they have the same value, we are blocking the input event
1070
+ if (previousRootComponentValue === this.value) {
1071
+ e.stopImmediatePropagation();
1072
+ } else {
1073
+ previousRootComponentValue = this.value;
1074
+ }
1082
1075
  });
1083
1076
 
1084
1077
  }
@@ -1809,7 +1802,6 @@ overrides$4 = `
1809
1802
  customElements.define(componentName$a, NumberField);
1810
1803
 
1811
1804
  const createBaseInputClass = (...args) => compose(
1812
- focusMixin,
1813
1805
  inputValidationMixin,
1814
1806
  changeMixin,
1815
1807
  readOnlyMixin,
@@ -2000,9 +1992,6 @@ class PasscodeInternal extends BaseInputClass$1 {
2000
1992
 
2001
1993
  forwardAttrs(this, input, { includeAttrs: forwardAttributes });
2002
1994
  });
2003
-
2004
- this.handleFocusEventsDispatching(this.inputs);
2005
- this.handleInputEventDispatching(this.inputs);
2006
1995
  }
2007
1996
 
2008
1997
  attributeChangedCallback(attrName, oldValue, newValue) {
@@ -4066,9 +4055,6 @@ class PhoneFieldInternal extends BaseInputClass {
4066
4055
  .join('');
4067
4056
  e.target.value = sanitizedInput;
4068
4057
  });
4069
-
4070
- this.handleFocusEventsDispatching(this.inputs);
4071
- this.handleInputEventDispatching(this.inputs);
4072
4058
  }
4073
4059
 
4074
4060
  attributeChangedCallback(attrName, oldValue, newValue) {