@salutejs/plasma-new-hope 0.336.0-canary.2210.17488241312.0 → 0.336.0-canary.2211.17491564625.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.
- package/cjs/components/CodeField/CodeField.css +6 -7
- package/cjs/components/CodeField/CodeField.js +24 -60
- package/cjs/components/CodeField/CodeField.js.map +1 -1
- package/cjs/components/CodeField/CodeField.styles.js +1 -7
- package/cjs/components/CodeField/CodeField.styles.js.map +1 -1
- package/cjs/components/CodeField/{CodeField.styles_14p25hi.css → CodeField.styles_ebdpd0.css} +0 -1
- package/cjs/components/CodeField/utils/handleCodeError.js +2 -2
- package/cjs/components/CodeField/utils/handleCodeError.js.map +1 -1
- package/cjs/components/CodeField/utils/handleItemError.js +4 -14
- package/cjs/components/CodeField/utils/handleItemError.js.map +1 -1
- package/cjs/components/Pagination/Pagination.js +2 -1
- package/cjs/components/Pagination/Pagination.js.map +1 -1
- package/cjs/index.css +6 -7
- package/emotion/cjs/components/CodeField/CodeField.js +20 -50
- package/emotion/cjs/components/CodeField/CodeField.styles.js +11 -18
- package/emotion/cjs/components/CodeField/utils/handleCodeError.js +2 -2
- package/emotion/cjs/components/CodeField/utils/handleItemError.js +3 -12
- package/emotion/cjs/components/CodeField/utils/index.js +0 -4
- package/emotion/cjs/components/Pagination/Pagination.js +1 -1
- package/emotion/es/components/CodeField/CodeField.js +22 -52
- package/emotion/es/components/CodeField/CodeField.styles.js +11 -15
- package/emotion/es/components/CodeField/utils/handleCodeError.js +2 -2
- package/emotion/es/components/CodeField/utils/handleItemError.js +3 -12
- package/emotion/es/components/CodeField/utils/index.js +0 -1
- package/emotion/es/components/Pagination/Pagination.js +1 -1
- package/es/components/CodeField/CodeField.css +6 -7
- package/es/components/CodeField/CodeField.js +26 -62
- package/es/components/CodeField/CodeField.js.map +1 -1
- package/es/components/CodeField/CodeField.styles.js +2 -7
- package/es/components/CodeField/CodeField.styles.js.map +1 -1
- package/es/components/CodeField/{CodeField.styles_14p25hi.css → CodeField.styles_ebdpd0.css} +0 -1
- package/es/components/CodeField/utils/handleCodeError.js +2 -2
- package/es/components/CodeField/utils/handleCodeError.js.map +1 -1
- package/es/components/CodeField/utils/handleItemError.js +4 -14
- package/es/components/CodeField/utils/handleItemError.js.map +1 -1
- package/es/components/Pagination/Pagination.js +2 -1
- package/es/components/Pagination/Pagination.js.map +1 -1
- package/es/index.css +6 -7
- package/package.json +2 -2
- package/styled-components/cjs/components/CodeField/CodeField.js +20 -50
- package/styled-components/cjs/components/CodeField/CodeField.styles.js +5 -14
- package/styled-components/cjs/components/CodeField/utils/handleCodeError.js +2 -2
- package/styled-components/cjs/components/CodeField/utils/handleItemError.js +3 -12
- package/styled-components/cjs/components/CodeField/utils/index.js +0 -4
- package/styled-components/cjs/components/Pagination/Pagination.js +1 -1
- package/styled-components/cjs/examples/components/Combobox/Combobox.js +15 -0
- package/styled-components/es/components/CodeField/CodeField.js +22 -52
- package/styled-components/es/components/CodeField/CodeField.styles.js +5 -11
- package/styled-components/es/components/CodeField/utils/handleCodeError.js +2 -2
- package/styled-components/es/components/CodeField/utils/handleItemError.js +3 -12
- package/styled-components/es/components/CodeField/utils/index.js +0 -1
- package/styled-components/es/components/Pagination/Pagination.js +1 -1
- package/types/components/Autocomplete/Autocomplete.types.d.ts +6 -6
- package/types/components/Autocomplete/Autocomplete.types.d.ts.map +1 -1
- package/types/components/CodeField/CodeField.d.ts.map +1 -1
- package/types/components/CodeField/CodeField.styles.d.ts +0 -1
- package/types/components/CodeField/CodeField.styles.d.ts.map +1 -1
- package/types/components/CodeField/utils/handleCodeError.d.ts +2 -2
- package/types/components/CodeField/utils/handleCodeError.d.ts.map +1 -1
- package/types/components/CodeField/utils/handleItemError.d.ts +2 -3
- package/types/components/CodeField/utils/handleItemError.d.ts.map +1 -1
- package/types/components/CodeField/utils/index.d.ts +0 -1
- package/types/components/CodeField/utils/index.d.ts.map +1 -1
- package/types/components/Pagination/Pagination.types.d.ts +75 -0
- package/types/components/Pagination/Pagination.types.d.ts.map +1 -1
- package/types/examples/components/Autocomplete/Autocomplete.d.ts +40 -40
- package/types/examples/components/Autocomplete/Autocomplete.d.ts.map +1 -1
- package/cjs/components/CodeField/hooks/useWebOTP.js +0 -107
- package/cjs/components/CodeField/hooks/useWebOTP.js.map +0 -1
- package/cjs/components/CodeField/utils/isWebOTPSupported.js +0 -10
- package/cjs/components/CodeField/utils/isWebOTPSupported.js.map +0 -1
- package/emotion/cjs/components/CodeField/hooks/useWebOTP.js +0 -256
- package/emotion/cjs/components/CodeField/utils/isWebOTPSupported.js +0 -13
- package/emotion/es/components/CodeField/hooks/useWebOTP.js +0 -246
- package/emotion/es/components/CodeField/utils/isWebOTPSupported.js +0 -3
- package/es/components/CodeField/hooks/useWebOTP.js +0 -103
- package/es/components/CodeField/hooks/useWebOTP.js.map +0 -1
- package/es/components/CodeField/utils/isWebOTPSupported.js +0 -6
- package/es/components/CodeField/utils/isWebOTPSupported.js.map +0 -1
- package/styled-components/cjs/components/CodeField/hooks/useWebOTP.js +0 -256
- package/styled-components/cjs/components/CodeField/utils/isWebOTPSupported.js +0 -13
- package/styled-components/es/components/CodeField/hooks/useWebOTP.js +0 -246
- package/styled-components/es/components/CodeField/utils/isWebOTPSupported.js +0 -3
- package/types/components/CodeField/hooks/useWebOTP.d.ts +0 -24
- package/types/components/CodeField/hooks/useWebOTP.d.ts.map +0 -1
- package/types/components/CodeField/utils/isWebOTPSupported.d.ts +0 -2
- package/types/components/CodeField/utils/isWebOTPSupported.d.ts.map +0 -1
@@ -1,256 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
3
|
-
value: true
|
4
|
-
});
|
5
|
-
Object.defineProperty(exports, "useWebOTP", {
|
6
|
-
enumerable: true,
|
7
|
-
get: function() {
|
8
|
-
return useWebOTP;
|
9
|
-
}
|
10
|
-
});
|
11
|
-
var _react = require("react");
|
12
|
-
var _utils = require("../utils");
|
13
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
14
|
-
try {
|
15
|
-
var info = gen[key](arg);
|
16
|
-
var value = info.value;
|
17
|
-
} catch (error) {
|
18
|
-
reject(error);
|
19
|
-
return;
|
20
|
-
}
|
21
|
-
if (info.done) {
|
22
|
-
resolve(value);
|
23
|
-
} else {
|
24
|
-
Promise.resolve(value).then(_next, _throw);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
function _async_to_generator(fn) {
|
28
|
-
return function() {
|
29
|
-
var self = this, args = arguments;
|
30
|
-
return new Promise(function(resolve, reject) {
|
31
|
-
var gen = fn.apply(self, args);
|
32
|
-
function _next(value) {
|
33
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
34
|
-
}
|
35
|
-
function _throw(err) {
|
36
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
37
|
-
}
|
38
|
-
_next(undefined);
|
39
|
-
});
|
40
|
-
};
|
41
|
-
}
|
42
|
-
function _instanceof(left, right) {
|
43
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
44
|
-
return !!right[Symbol.hasInstance](left);
|
45
|
-
} else {
|
46
|
-
return left instanceof right;
|
47
|
-
}
|
48
|
-
}
|
49
|
-
function _ts_generator(thisArg, body) {
|
50
|
-
var f, y, t, _ = {
|
51
|
-
label: 0,
|
52
|
-
sent: function() {
|
53
|
-
if (t[0] & 1) throw t[1];
|
54
|
-
return t[1];
|
55
|
-
},
|
56
|
-
trys: [],
|
57
|
-
ops: []
|
58
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
59
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
60
|
-
return this;
|
61
|
-
}), g;
|
62
|
-
function verb(n) {
|
63
|
-
return function(v) {
|
64
|
-
return step([
|
65
|
-
n,
|
66
|
-
v
|
67
|
-
]);
|
68
|
-
};
|
69
|
-
}
|
70
|
-
function step(op) {
|
71
|
-
if (f) throw new TypeError("Generator is already executing.");
|
72
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
73
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
74
|
-
if (y = 0, t) op = [
|
75
|
-
op[0] & 2,
|
76
|
-
t.value
|
77
|
-
];
|
78
|
-
switch(op[0]){
|
79
|
-
case 0:
|
80
|
-
case 1:
|
81
|
-
t = op;
|
82
|
-
break;
|
83
|
-
case 4:
|
84
|
-
_.label++;
|
85
|
-
return {
|
86
|
-
value: op[1],
|
87
|
-
done: false
|
88
|
-
};
|
89
|
-
case 5:
|
90
|
-
_.label++;
|
91
|
-
y = op[1];
|
92
|
-
op = [
|
93
|
-
0
|
94
|
-
];
|
95
|
-
continue;
|
96
|
-
case 7:
|
97
|
-
op = _.ops.pop();
|
98
|
-
_.trys.pop();
|
99
|
-
continue;
|
100
|
-
default:
|
101
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
102
|
-
_ = 0;
|
103
|
-
continue;
|
104
|
-
}
|
105
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
106
|
-
_.label = op[1];
|
107
|
-
break;
|
108
|
-
}
|
109
|
-
if (op[0] === 6 && _.label < t[1]) {
|
110
|
-
_.label = t[1];
|
111
|
-
t = op;
|
112
|
-
break;
|
113
|
-
}
|
114
|
-
if (t && _.label < t[2]) {
|
115
|
-
_.label = t[2];
|
116
|
-
_.ops.push(op);
|
117
|
-
break;
|
118
|
-
}
|
119
|
-
if (t[2]) _.ops.pop();
|
120
|
-
_.trys.pop();
|
121
|
-
continue;
|
122
|
-
}
|
123
|
-
op = body.call(thisArg, _);
|
124
|
-
} catch (e) {
|
125
|
-
op = [
|
126
|
-
6,
|
127
|
-
e
|
128
|
-
];
|
129
|
-
y = 0;
|
130
|
-
} finally{
|
131
|
-
f = t = 0;
|
132
|
-
}
|
133
|
-
if (op[0] & 5) throw op[1];
|
134
|
-
return {
|
135
|
-
value: op[0] ? op[1] : void 0,
|
136
|
-
done: true
|
137
|
-
};
|
138
|
-
}
|
139
|
-
}
|
140
|
-
// Type guard function to check if credential is OTPCredential
|
141
|
-
var isOTPCredential = function(credential) {
|
142
|
-
return credential !== null && 'code' in credential;
|
143
|
-
};
|
144
|
-
var useWebOTP = function(param) {
|
145
|
-
var codeString = param.codeString, enableSMSAutoRead = param.enableSMSAutoRead, disabled = param.disabled, codeLength = param.codeLength, codeSetter = param.codeSetter, onFullCodeEnter = param.onFullCodeEnter, setOtpVal = param.setOtpVal;
|
146
|
-
var abortControllerRef = (0, _react.useRef)(null);
|
147
|
-
var startWebOTPListener = (0, _react.useCallback)(function() {
|
148
|
-
return _async_to_generator(function() {
|
149
|
-
var otp, otpCode, newCode, err;
|
150
|
-
return _ts_generator(this, function(_state) {
|
151
|
-
switch(_state.label){
|
152
|
-
case 0:
|
153
|
-
if (!enableSMSAutoRead || disabled || !(0, _utils.isWebOTPSupported)()) {
|
154
|
-
return [
|
155
|
-
2
|
156
|
-
];
|
157
|
-
}
|
158
|
-
if (abortControllerRef.current) {
|
159
|
-
abortControllerRef.current.abort();
|
160
|
-
}
|
161
|
-
abortControllerRef.current = new AbortController();
|
162
|
-
_state.label = 1;
|
163
|
-
case 1:
|
164
|
-
_state.trys.push([
|
165
|
-
1,
|
166
|
-
3,
|
167
|
-
,
|
168
|
-
4
|
169
|
-
]);
|
170
|
-
return [
|
171
|
-
4,
|
172
|
-
navigator.credentials.get({
|
173
|
-
otp: {
|
174
|
-
transport: [
|
175
|
-
'sms'
|
176
|
-
]
|
177
|
-
},
|
178
|
-
signal: abortControllerRef.current.signal
|
179
|
-
})
|
180
|
-
];
|
181
|
-
case 2:
|
182
|
-
otp = _state.sent();
|
183
|
-
console.log('otp received', otp);
|
184
|
-
setOtpVal(otp);
|
185
|
-
// Type guard to check if it's an OTP credential
|
186
|
-
if (otp && isOTPCredential(otp) && otp.code) {
|
187
|
-
otpCode = otp.code;
|
188
|
-
// Validate the OTP code length matches our expected length
|
189
|
-
if (otpCode.length === codeLength) {
|
190
|
-
newCode = (0, _utils.getCodeValue)(codeLength, otpCode);
|
191
|
-
codeSetter(newCode);
|
192
|
-
// Trigger full code enter callback
|
193
|
-
if (onFullCodeEnter) {
|
194
|
-
onFullCodeEnter(otpCode);
|
195
|
-
}
|
196
|
-
}
|
197
|
-
}
|
198
|
-
return [
|
199
|
-
3,
|
200
|
-
4
|
201
|
-
];
|
202
|
-
case 3:
|
203
|
-
err = _state.sent();
|
204
|
-
if (_instanceof(err, DOMException)) {
|
205
|
-
if (err.name !== 'AbortError' && err.name !== 'NotAllowedError') {
|
206
|
-
console.warn('Web OTP API error:', err);
|
207
|
-
}
|
208
|
-
} else if (_instanceof(err, Error)) {
|
209
|
-
console.warn('Web OTP API error:', err);
|
210
|
-
} else {
|
211
|
-
console.warn('Unknown Web OTP API error:', err);
|
212
|
-
}
|
213
|
-
return [
|
214
|
-
3,
|
215
|
-
4
|
216
|
-
];
|
217
|
-
case 4:
|
218
|
-
return [
|
219
|
-
2
|
220
|
-
];
|
221
|
-
}
|
222
|
-
});
|
223
|
-
})();
|
224
|
-
}, [
|
225
|
-
enableSMSAutoRead,
|
226
|
-
disabled,
|
227
|
-
codeLength,
|
228
|
-
onFullCodeEnter
|
229
|
-
]);
|
230
|
-
var stopWebOTPListener = (0, _react.useCallback)(function() {
|
231
|
-
if (abortControllerRef.current) {
|
232
|
-
abortControllerRef.current.abort();
|
233
|
-
abortControllerRef.current = null;
|
234
|
-
}
|
235
|
-
}, []);
|
236
|
-
(0, _react.useEffect)(function() {
|
237
|
-
if ((0, _utils.isWebOTPSupported)() && codeString === '' && enableSMSAutoRead && !disabled) {
|
238
|
-
startWebOTPListener();
|
239
|
-
} else {
|
240
|
-
stopWebOTPListener();
|
241
|
-
}
|
242
|
-
return function() {
|
243
|
-
stopWebOTPListener();
|
244
|
-
};
|
245
|
-
}, [
|
246
|
-
codeString,
|
247
|
-
enableSMSAutoRead,
|
248
|
-
disabled,
|
249
|
-
startWebOTPListener,
|
250
|
-
stopWebOTPListener
|
251
|
-
]);
|
252
|
-
return {
|
253
|
-
startWebOTPListener: startWebOTPListener,
|
254
|
-
stopWebOTPListener: stopWebOTPListener
|
255
|
-
};
|
256
|
-
};
|
@@ -1,13 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
3
|
-
value: true
|
4
|
-
});
|
5
|
-
Object.defineProperty(exports, "isWebOTPSupported", {
|
6
|
-
enumerable: true,
|
7
|
-
get: function() {
|
8
|
-
return isWebOTPSupported;
|
9
|
-
}
|
10
|
-
});
|
11
|
-
var isWebOTPSupported = function() {
|
12
|
-
return typeof window !== 'undefined' && 'OTPCredential' in window && navigator.credentials && typeof navigator.credentials.get === 'function';
|
13
|
-
};
|
@@ -1,246 +0,0 @@
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
2
|
-
try {
|
3
|
-
var info = gen[key](arg);
|
4
|
-
var value = info.value;
|
5
|
-
} catch (error) {
|
6
|
-
reject(error);
|
7
|
-
return;
|
8
|
-
}
|
9
|
-
if (info.done) {
|
10
|
-
resolve(value);
|
11
|
-
} else {
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
13
|
-
}
|
14
|
-
}
|
15
|
-
function _async_to_generator(fn) {
|
16
|
-
return function() {
|
17
|
-
var self = this, args = arguments;
|
18
|
-
return new Promise(function(resolve, reject) {
|
19
|
-
var gen = fn.apply(self, args);
|
20
|
-
function _next(value) {
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
22
|
-
}
|
23
|
-
function _throw(err) {
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
25
|
-
}
|
26
|
-
_next(undefined);
|
27
|
-
});
|
28
|
-
};
|
29
|
-
}
|
30
|
-
function _instanceof(left, right) {
|
31
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
32
|
-
return !!right[Symbol.hasInstance](left);
|
33
|
-
} else {
|
34
|
-
return left instanceof right;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
function _ts_generator(thisArg, body) {
|
38
|
-
var f, y, t, _ = {
|
39
|
-
label: 0,
|
40
|
-
sent: function() {
|
41
|
-
if (t[0] & 1) throw t[1];
|
42
|
-
return t[1];
|
43
|
-
},
|
44
|
-
trys: [],
|
45
|
-
ops: []
|
46
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
47
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
48
|
-
return this;
|
49
|
-
}), g;
|
50
|
-
function verb(n) {
|
51
|
-
return function(v) {
|
52
|
-
return step([
|
53
|
-
n,
|
54
|
-
v
|
55
|
-
]);
|
56
|
-
};
|
57
|
-
}
|
58
|
-
function step(op) {
|
59
|
-
if (f) throw new TypeError("Generator is already executing.");
|
60
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
61
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
62
|
-
if (y = 0, t) op = [
|
63
|
-
op[0] & 2,
|
64
|
-
t.value
|
65
|
-
];
|
66
|
-
switch(op[0]){
|
67
|
-
case 0:
|
68
|
-
case 1:
|
69
|
-
t = op;
|
70
|
-
break;
|
71
|
-
case 4:
|
72
|
-
_.label++;
|
73
|
-
return {
|
74
|
-
value: op[1],
|
75
|
-
done: false
|
76
|
-
};
|
77
|
-
case 5:
|
78
|
-
_.label++;
|
79
|
-
y = op[1];
|
80
|
-
op = [
|
81
|
-
0
|
82
|
-
];
|
83
|
-
continue;
|
84
|
-
case 7:
|
85
|
-
op = _.ops.pop();
|
86
|
-
_.trys.pop();
|
87
|
-
continue;
|
88
|
-
default:
|
89
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
90
|
-
_ = 0;
|
91
|
-
continue;
|
92
|
-
}
|
93
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
94
|
-
_.label = op[1];
|
95
|
-
break;
|
96
|
-
}
|
97
|
-
if (op[0] === 6 && _.label < t[1]) {
|
98
|
-
_.label = t[1];
|
99
|
-
t = op;
|
100
|
-
break;
|
101
|
-
}
|
102
|
-
if (t && _.label < t[2]) {
|
103
|
-
_.label = t[2];
|
104
|
-
_.ops.push(op);
|
105
|
-
break;
|
106
|
-
}
|
107
|
-
if (t[2]) _.ops.pop();
|
108
|
-
_.trys.pop();
|
109
|
-
continue;
|
110
|
-
}
|
111
|
-
op = body.call(thisArg, _);
|
112
|
-
} catch (e) {
|
113
|
-
op = [
|
114
|
-
6,
|
115
|
-
e
|
116
|
-
];
|
117
|
-
y = 0;
|
118
|
-
} finally{
|
119
|
-
f = t = 0;
|
120
|
-
}
|
121
|
-
if (op[0] & 5) throw op[1];
|
122
|
-
return {
|
123
|
-
value: op[0] ? op[1] : void 0,
|
124
|
-
done: true
|
125
|
-
};
|
126
|
-
}
|
127
|
-
}
|
128
|
-
import { useCallback, useEffect, useRef } from "react";
|
129
|
-
import { getCodeValue, isWebOTPSupported } from "../utils";
|
130
|
-
// Type guard function to check if credential is OTPCredential
|
131
|
-
var isOTPCredential = function(credential) {
|
132
|
-
return credential !== null && 'code' in credential;
|
133
|
-
};
|
134
|
-
export var useWebOTP = function(param) {
|
135
|
-
var codeString = param.codeString, enableSMSAutoRead = param.enableSMSAutoRead, disabled = param.disabled, codeLength = param.codeLength, codeSetter = param.codeSetter, onFullCodeEnter = param.onFullCodeEnter, setOtpVal = param.setOtpVal;
|
136
|
-
var abortControllerRef = useRef(null);
|
137
|
-
var startWebOTPListener = useCallback(function() {
|
138
|
-
return _async_to_generator(function() {
|
139
|
-
var otp, otpCode, newCode, err;
|
140
|
-
return _ts_generator(this, function(_state) {
|
141
|
-
switch(_state.label){
|
142
|
-
case 0:
|
143
|
-
if (!enableSMSAutoRead || disabled || !isWebOTPSupported()) {
|
144
|
-
return [
|
145
|
-
2
|
146
|
-
];
|
147
|
-
}
|
148
|
-
if (abortControllerRef.current) {
|
149
|
-
abortControllerRef.current.abort();
|
150
|
-
}
|
151
|
-
abortControllerRef.current = new AbortController();
|
152
|
-
_state.label = 1;
|
153
|
-
case 1:
|
154
|
-
_state.trys.push([
|
155
|
-
1,
|
156
|
-
3,
|
157
|
-
,
|
158
|
-
4
|
159
|
-
]);
|
160
|
-
return [
|
161
|
-
4,
|
162
|
-
navigator.credentials.get({
|
163
|
-
otp: {
|
164
|
-
transport: [
|
165
|
-
'sms'
|
166
|
-
]
|
167
|
-
},
|
168
|
-
signal: abortControllerRef.current.signal
|
169
|
-
})
|
170
|
-
];
|
171
|
-
case 2:
|
172
|
-
otp = _state.sent();
|
173
|
-
console.log('otp received', otp);
|
174
|
-
setOtpVal(otp);
|
175
|
-
// Type guard to check if it's an OTP credential
|
176
|
-
if (otp && isOTPCredential(otp) && otp.code) {
|
177
|
-
otpCode = otp.code;
|
178
|
-
// Validate the OTP code length matches our expected length
|
179
|
-
if (otpCode.length === codeLength) {
|
180
|
-
newCode = getCodeValue(codeLength, otpCode);
|
181
|
-
codeSetter(newCode);
|
182
|
-
// Trigger full code enter callback
|
183
|
-
if (onFullCodeEnter) {
|
184
|
-
onFullCodeEnter(otpCode);
|
185
|
-
}
|
186
|
-
}
|
187
|
-
}
|
188
|
-
return [
|
189
|
-
3,
|
190
|
-
4
|
191
|
-
];
|
192
|
-
case 3:
|
193
|
-
err = _state.sent();
|
194
|
-
if (_instanceof(err, DOMException)) {
|
195
|
-
if (err.name !== 'AbortError' && err.name !== 'NotAllowedError') {
|
196
|
-
console.warn('Web OTP API error:', err);
|
197
|
-
}
|
198
|
-
} else if (_instanceof(err, Error)) {
|
199
|
-
console.warn('Web OTP API error:', err);
|
200
|
-
} else {
|
201
|
-
console.warn('Unknown Web OTP API error:', err);
|
202
|
-
}
|
203
|
-
return [
|
204
|
-
3,
|
205
|
-
4
|
206
|
-
];
|
207
|
-
case 4:
|
208
|
-
return [
|
209
|
-
2
|
210
|
-
];
|
211
|
-
}
|
212
|
-
});
|
213
|
-
})();
|
214
|
-
}, [
|
215
|
-
enableSMSAutoRead,
|
216
|
-
disabled,
|
217
|
-
codeLength,
|
218
|
-
onFullCodeEnter
|
219
|
-
]);
|
220
|
-
var stopWebOTPListener = useCallback(function() {
|
221
|
-
if (abortControllerRef.current) {
|
222
|
-
abortControllerRef.current.abort();
|
223
|
-
abortControllerRef.current = null;
|
224
|
-
}
|
225
|
-
}, []);
|
226
|
-
useEffect(function() {
|
227
|
-
if (isWebOTPSupported() && codeString === '' && enableSMSAutoRead && !disabled) {
|
228
|
-
startWebOTPListener();
|
229
|
-
} else {
|
230
|
-
stopWebOTPListener();
|
231
|
-
}
|
232
|
-
return function() {
|
233
|
-
stopWebOTPListener();
|
234
|
-
};
|
235
|
-
}, [
|
236
|
-
codeString,
|
237
|
-
enableSMSAutoRead,
|
238
|
-
disabled,
|
239
|
-
startWebOTPListener,
|
240
|
-
stopWebOTPListener
|
241
|
-
]);
|
242
|
-
return {
|
243
|
-
startWebOTPListener: startWebOTPListener,
|
244
|
-
stopWebOTPListener: stopWebOTPListener
|
245
|
-
};
|
246
|
-
};
|
@@ -1,24 +0,0 @@
|
|
1
|
-
type UseWebOTPProps = {
|
2
|
-
codeString: string;
|
3
|
-
enableSMSAutoRead: boolean;
|
4
|
-
disabled: boolean;
|
5
|
-
codeLength: number;
|
6
|
-
codeSetter: (newCode: Array<string>) => void;
|
7
|
-
onFullCodeEnter?: (code: string) => void;
|
8
|
-
setOtpVal: React.Dispatch<React.SetStateAction<Credential | null>>;
|
9
|
-
};
|
10
|
-
type OTPTransport = 'sms';
|
11
|
-
declare global {
|
12
|
-
interface CredentialRequestOptions {
|
13
|
-
otp?: {
|
14
|
-
transport: OTPTransport[];
|
15
|
-
};
|
16
|
-
signal?: AbortSignal;
|
17
|
-
}
|
18
|
-
}
|
19
|
-
export declare const useWebOTP: ({ codeString, enableSMSAutoRead, disabled, codeLength, codeSetter, onFullCodeEnter, setOtpVal, }: UseWebOTPProps) => {
|
20
|
-
startWebOTPListener: () => Promise<void>;
|
21
|
-
stopWebOTPListener: () => void;
|
22
|
-
};
|
23
|
-
export {};
|
24
|
-
//# sourceMappingURL=useWebOTP.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useWebOTP.d.ts","sourceRoot":"","sources":["../../../../src/components/CodeField/hooks/useWebOTP.ts"],"names":[],"mappings":"AAIA,KAAK,cAAc,GAAG;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAC7C,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC;CACtE,CAAC;AAEF,KAAK,YAAY,GAAG,KAAK,CAAC;AAM1B,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,wBAAwB;QAC9B,GAAG,CAAC,EAAE;YACF,SAAS,EAAE,YAAY,EAAE,CAAC;SAC7B,CAAC;QACF,MAAM,CAAC,EAAE,WAAW,CAAC;KACxB;CACJ;AAOD,eAAO,MAAM,SAAS,qGAQnB,cAAc;;;CAwEhB,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"isWebOTPSupported.d.ts","sourceRoot":"","sources":["../../../../src/components/CodeField/utils/isWebOTPSupported.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,eAO7B,CAAC"}
|