allaw-ui 2.4.1 → 2.4.3

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.
@@ -29,52 +29,9 @@ var VerificationCodeInput = function (_a) {
29
29
  onError === null || onError === void 0 ? void 0 : onError(null);
30
30
  }
31
31
  }, [testError, onError]);
32
- var validateAllInputs = function () {
33
- var _a;
34
- var fullValue = values.join("");
35
- console.log("[VerificationCodeInput] Validating inputs:", fullValue);
36
- if (fullValue.length === numInputs) {
37
- console.log("[VerificationCodeInput] All inputs filled");
38
- if (testError) {
39
- setError("Code de vérification invalide");
40
- onError === null || onError === void 0 ? void 0 : onError("Code de vérification invalide");
41
- return;
42
- }
43
- setError("");
44
- onError === null || onError === void 0 ? void 0 : onError(null);
45
- console.log("[VerificationCodeInput] Calling onComplete with:", fullValue);
46
- onComplete === null || onComplete === void 0 ? void 0 : onComplete(fullValue);
47
- (_a = inputRefs.current[numInputs - 1]) === null || _a === void 0 ? void 0 : _a.blur();
48
- }
49
- };
50
32
  var handleInputChange = function (index, value) {
51
- var _a, _b, _c, _d;
33
+ var _a;
52
34
  console.log("[VerificationCodeInput] Input ".concat(index, " changed to:"), value);
53
- if (value.length > 1) {
54
- var pastedChars = value.split("");
55
- var validChars = pastedChars
56
- .filter(function (char) { return validateInput(char, allowedChars); })
57
- .slice(0, numInputs - index);
58
- if (validChars.length > 0) {
59
- var newValues_1 = __spreadArray([], values, true);
60
- validChars.forEach(function (char, i) {
61
- if (index + i < numInputs) {
62
- newValues_1[index + i] = char;
63
- }
64
- });
65
- setValues(newValues_1);
66
- onChange === null || onChange === void 0 ? void 0 : onChange(newValues_1.join(""));
67
- var nextEmptyIndex = newValues_1.findIndex(function (val, i) { return i >= index && !val; });
68
- var focusIndex = nextEmptyIndex === -1 ? numInputs - 1 : nextEmptyIndex;
69
- (_a = inputRefs.current[focusIndex]) === null || _a === void 0 ? void 0 : _a.focus();
70
- if (nextEmptyIndex === -1) {
71
- validateAllInputs();
72
- (_b = inputRefs.current[numInputs - 1]) === null || _b === void 0 ? void 0 : _b.blur();
73
- }
74
- console.log("[VerificationCodeInput] Handling pasted value");
75
- return;
76
- }
77
- }
78
35
  if (!validateInput(value, allowedChars)) {
79
36
  console.log("[VerificationCodeInput] Invalid input value");
80
37
  return;
@@ -82,19 +39,19 @@ var VerificationCodeInput = function (_a) {
82
39
  var newValues = __spreadArray([], values, true);
83
40
  newValues[index] = value;
84
41
  setValues(newValues);
85
- console.log("[VerificationCodeInput] New values:", newValues.join(""));
86
- if (value === "")
87
- return;
88
- setError("");
89
- onError === null || onError === void 0 ? void 0 : onError(null);
90
42
  var fullValue = newValues.join("");
43
+ console.log("[VerificationCodeInput] New values:", fullValue);
91
44
  onChange === null || onChange === void 0 ? void 0 : onChange(fullValue);
92
- if (index < numInputs - 1) {
93
- (_c = inputRefs.current[index + 1]) === null || _c === void 0 ? void 0 : _c.focus();
45
+ if (index === numInputs - 1 && value !== "") {
46
+ console.log("[VerificationCodeInput] Last input filled, validating with:", fullValue);
47
+ if (fullValue.length === numInputs) {
48
+ setError("");
49
+ onError === null || onError === void 0 ? void 0 : onError(null);
50
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(fullValue);
51
+ }
94
52
  }
95
- else if (index === numInputs - 1 && value !== "") {
96
- validateAllInputs();
97
- (_d = inputRefs.current[index]) === null || _d === void 0 ? void 0 : _d.blur();
53
+ else if (index < numInputs - 1) {
54
+ (_a = inputRefs.current[index + 1]) === null || _a === void 0 ? void 0 : _a.focus();
98
55
  }
99
56
  };
100
57
  var handleKeyDown = function (index, e) {
@@ -111,7 +68,13 @@ var VerificationCodeInput = function (_a) {
111
68
  setTimeout(function () {
112
69
  var isStillFocused = inputRefs.current.some(function (ref) { return ref === document.activeElement; });
113
70
  if (!isStillFocused) {
114
- validateAllInputs();
71
+ if (values.every(function (value) { return value !== ""; })) {
72
+ var fullValue = values.join("");
73
+ console.log("[VerificationCodeInput] All inputs filled, length:", fullValue.length);
74
+ setError("");
75
+ onError === null || onError === void 0 ? void 0 : onError(null);
76
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(fullValue);
77
+ }
115
78
  }
116
79
  }, 0);
117
80
  };
@@ -124,16 +87,20 @@ var VerificationCodeInput = function (_a) {
124
87
  .filter(function (char) { return validateInput(char, allowedChars); })
125
88
  .slice(0, numInputs);
126
89
  if (validChars.length > 0) {
127
- var newValues_2 = Array(numInputs).fill("");
90
+ var newValues_1 = Array(numInputs).fill("");
128
91
  validChars.forEach(function (char, i) {
129
92
  if (i < numInputs) {
130
- newValues_2[i] = char;
93
+ newValues_1[i] = char;
131
94
  }
132
95
  });
133
- setValues(newValues_2);
134
- onChange === null || onChange === void 0 ? void 0 : onChange(newValues_2.join(""));
96
+ setValues(newValues_1);
97
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValues_1.join(""));
135
98
  if (validChars.length >= numInputs) {
136
- validateAllInputs();
99
+ var fullValue = newValues_1.join("");
100
+ console.log("[VerificationCodeInput] All inputs filled, length:", fullValue.length);
101
+ setError("");
102
+ onError === null || onError === void 0 ? void 0 : onError(null);
103
+ onComplete === null || onComplete === void 0 ? void 0 : onComplete(fullValue);
137
104
  inputRefs.current.forEach(function (input) { return input === null || input === void 0 ? void 0 : input.blur(); });
138
105
  (_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.blur();
139
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "allaw-ui",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "Composants UI pour l'application Allaw",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",