use-mask-input 3.9.0 → 3.10.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.
@@ -3776,6 +3776,48 @@ function interopDefaultSync(module) {
3776
3776
  return module;
3777
3777
  }
3778
3778
 
3779
+ // src/core/elementResolver.ts
3780
+ function isHTMLElement(element) {
3781
+ return element !== null && typeof element === "object" && "nodeType" in element && "querySelector" in element && typeof element.querySelector === "function";
3782
+ }
3783
+ function findInputElement(element) {
3784
+ if (!element) return null;
3785
+ if (!isHTMLElement(element)) {
3786
+ return null;
3787
+ }
3788
+ if (element.nodeName === "INPUT" || element.nodeName === "TEXTAREA") {
3789
+ return element;
3790
+ }
3791
+ if (!("querySelector" in element) || typeof element.querySelector !== "function") {
3792
+ return null;
3793
+ }
3794
+ try {
3795
+ const inputElement = element.querySelector("input, textarea");
3796
+ if (inputElement && isHTMLElement(inputElement)) {
3797
+ return inputElement;
3798
+ }
3799
+ } catch {
3800
+ return null;
3801
+ }
3802
+ return null;
3803
+ }
3804
+ function resolveInputRef(input) {
3805
+ if (!input) {
3806
+ return null;
3807
+ }
3808
+ if (typeof input === "object" && "current" in input) {
3809
+ const refValue = input.current;
3810
+ if (isHTMLElement(refValue)) {
3811
+ return refValue;
3812
+ }
3813
+ return null;
3814
+ }
3815
+ if (isHTMLElement(input)) {
3816
+ return input;
3817
+ }
3818
+ return null;
3819
+ }
3820
+
3779
3821
  // src/utils/maskHelpers.ts
3780
3822
  function makeMaskCacheKey(fieldName, mask) {
3781
3823
  return `${fieldName}:${Array.isArray(mask) ? mask.join(",") : String(mask)}`;
@@ -3788,6 +3830,33 @@ function setPrevRef(result, ref) {
3788
3830
  configurable: true
3789
3831
  });
3790
3832
  }
3833
+ function resolveUnmaskedInput(input) {
3834
+ const resolved = resolveInputRef(input);
3835
+ if (!resolved) return null;
3836
+ const inputElement = findInputElement(resolved);
3837
+ if (inputElement) {
3838
+ return inputElement;
3839
+ }
3840
+ return resolved;
3841
+ }
3842
+ function getUnmaskedValue(input) {
3843
+ const element = resolveUnmaskedInput(input);
3844
+ if (!element) return "";
3845
+ const inputmask3 = element.inputmask;
3846
+ if (inputmask3 && typeof inputmask3.unmaskedvalue === "function") {
3847
+ return inputmask3.unmaskedvalue();
3848
+ }
3849
+ return "value" in element ? element.value : "";
3850
+ }
3851
+ function setUnmaskedValue(result, getter) {
3852
+ Object.defineProperty(result, "unmaskedValue", {
3853
+ value: getter,
3854
+ enumerable: false,
3855
+ writable: true,
3856
+ configurable: true
3857
+ });
3858
+ return result;
3859
+ }
3791
3860
 
3792
3861
  // src/api/withMask.ts
3793
3862
  var callbackCache = /* @__PURE__ */ new Map();
@@ -3798,37 +3867,18 @@ function withMask(mask, options) {
3798
3867
  return callbackCache.get(cacheKey);
3799
3868
  }
3800
3869
  }
3801
- const callback = (input) => {
3870
+ let currentInput = null;
3871
+ const callback = ((input) => {
3802
3872
  if (isServer_default || mask === null || !input) return;
3873
+ currentInput = input;
3803
3874
  const maskInput = interopDefaultSync(import_inputmask.default)(getMaskOptions(mask, options));
3804
3875
  maskInput.mask(input);
3805
- };
3876
+ });
3806
3877
  if (!options) {
3807
3878
  const cacheKey = makeMaskCacheKey("", mask);
3808
3879
  callbackCache.set(cacheKey, callback);
3809
3880
  }
3810
- return callback;
3811
- }
3812
-
3813
- // src/core/elementResolver.ts
3814
- function isHTMLElement(element) {
3815
- return element !== null && typeof element === "object" && "nodeType" in element && "querySelector" in element && typeof element.querySelector === "function";
3816
- }
3817
- function resolveInputRef(input) {
3818
- if (!input) {
3819
- return null;
3820
- }
3821
- if (typeof input === "object" && "current" in input) {
3822
- const refValue = input.current;
3823
- if (isHTMLElement(refValue)) {
3824
- return refValue;
3825
- }
3826
- return null;
3827
- }
3828
- if (isHTMLElement(input)) {
3829
- return input;
3830
- }
3831
- return null;
3881
+ return setUnmaskedValue(callback, () => getUnmaskedValue(currentInput));
3832
3882
  }
3833
3883
 
3834
3884
  // src/core/maskEngine.ts
@@ -3860,6 +3910,6 @@ inputmask/dist/inputmask.js:
3860
3910
  (*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE *)
3861
3911
  */
3862
3912
 
3863
- export { applyMaskToElement, flow, isServer_default, makeMaskCacheKey, resolveInputRef, setPrevRef, withMask };
3864
- //# sourceMappingURL=chunk-ICLWBMH4.js.map
3865
- //# sourceMappingURL=chunk-ICLWBMH4.js.map
3913
+ export { applyMaskToElement, flow, getUnmaskedValue, isServer_default, makeMaskCacheKey, resolveInputRef, setPrevRef, setUnmaskedValue, withMask };
3914
+ //# sourceMappingURL=chunk-TVCNC3TP.js.map
3915
+ //# sourceMappingURL=chunk-TVCNC3TP.js.map