@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.
Files changed (87) hide show
  1. package/cjs/components/CodeField/CodeField.css +6 -7
  2. package/cjs/components/CodeField/CodeField.js +24 -60
  3. package/cjs/components/CodeField/CodeField.js.map +1 -1
  4. package/cjs/components/CodeField/CodeField.styles.js +1 -7
  5. package/cjs/components/CodeField/CodeField.styles.js.map +1 -1
  6. package/cjs/components/CodeField/{CodeField.styles_14p25hi.css → CodeField.styles_ebdpd0.css} +0 -1
  7. package/cjs/components/CodeField/utils/handleCodeError.js +2 -2
  8. package/cjs/components/CodeField/utils/handleCodeError.js.map +1 -1
  9. package/cjs/components/CodeField/utils/handleItemError.js +4 -14
  10. package/cjs/components/CodeField/utils/handleItemError.js.map +1 -1
  11. package/cjs/components/Pagination/Pagination.js +2 -1
  12. package/cjs/components/Pagination/Pagination.js.map +1 -1
  13. package/cjs/index.css +6 -7
  14. package/emotion/cjs/components/CodeField/CodeField.js +20 -50
  15. package/emotion/cjs/components/CodeField/CodeField.styles.js +11 -18
  16. package/emotion/cjs/components/CodeField/utils/handleCodeError.js +2 -2
  17. package/emotion/cjs/components/CodeField/utils/handleItemError.js +3 -12
  18. package/emotion/cjs/components/CodeField/utils/index.js +0 -4
  19. package/emotion/cjs/components/Pagination/Pagination.js +1 -1
  20. package/emotion/es/components/CodeField/CodeField.js +22 -52
  21. package/emotion/es/components/CodeField/CodeField.styles.js +11 -15
  22. package/emotion/es/components/CodeField/utils/handleCodeError.js +2 -2
  23. package/emotion/es/components/CodeField/utils/handleItemError.js +3 -12
  24. package/emotion/es/components/CodeField/utils/index.js +0 -1
  25. package/emotion/es/components/Pagination/Pagination.js +1 -1
  26. package/es/components/CodeField/CodeField.css +6 -7
  27. package/es/components/CodeField/CodeField.js +26 -62
  28. package/es/components/CodeField/CodeField.js.map +1 -1
  29. package/es/components/CodeField/CodeField.styles.js +2 -7
  30. package/es/components/CodeField/CodeField.styles.js.map +1 -1
  31. package/es/components/CodeField/{CodeField.styles_14p25hi.css → CodeField.styles_ebdpd0.css} +0 -1
  32. package/es/components/CodeField/utils/handleCodeError.js +2 -2
  33. package/es/components/CodeField/utils/handleCodeError.js.map +1 -1
  34. package/es/components/CodeField/utils/handleItemError.js +4 -14
  35. package/es/components/CodeField/utils/handleItemError.js.map +1 -1
  36. package/es/components/Pagination/Pagination.js +2 -1
  37. package/es/components/Pagination/Pagination.js.map +1 -1
  38. package/es/index.css +6 -7
  39. package/package.json +2 -2
  40. package/styled-components/cjs/components/CodeField/CodeField.js +20 -50
  41. package/styled-components/cjs/components/CodeField/CodeField.styles.js +5 -14
  42. package/styled-components/cjs/components/CodeField/utils/handleCodeError.js +2 -2
  43. package/styled-components/cjs/components/CodeField/utils/handleItemError.js +3 -12
  44. package/styled-components/cjs/components/CodeField/utils/index.js +0 -4
  45. package/styled-components/cjs/components/Pagination/Pagination.js +1 -1
  46. package/styled-components/cjs/examples/components/Combobox/Combobox.js +15 -0
  47. package/styled-components/es/components/CodeField/CodeField.js +22 -52
  48. package/styled-components/es/components/CodeField/CodeField.styles.js +5 -11
  49. package/styled-components/es/components/CodeField/utils/handleCodeError.js +2 -2
  50. package/styled-components/es/components/CodeField/utils/handleItemError.js +3 -12
  51. package/styled-components/es/components/CodeField/utils/index.js +0 -1
  52. package/styled-components/es/components/Pagination/Pagination.js +1 -1
  53. package/types/components/Autocomplete/Autocomplete.types.d.ts +6 -6
  54. package/types/components/Autocomplete/Autocomplete.types.d.ts.map +1 -1
  55. package/types/components/CodeField/CodeField.d.ts.map +1 -1
  56. package/types/components/CodeField/CodeField.styles.d.ts +0 -1
  57. package/types/components/CodeField/CodeField.styles.d.ts.map +1 -1
  58. package/types/components/CodeField/utils/handleCodeError.d.ts +2 -2
  59. package/types/components/CodeField/utils/handleCodeError.d.ts.map +1 -1
  60. package/types/components/CodeField/utils/handleItemError.d.ts +2 -3
  61. package/types/components/CodeField/utils/handleItemError.d.ts.map +1 -1
  62. package/types/components/CodeField/utils/index.d.ts +0 -1
  63. package/types/components/CodeField/utils/index.d.ts.map +1 -1
  64. package/types/components/Pagination/Pagination.types.d.ts +75 -0
  65. package/types/components/Pagination/Pagination.types.d.ts.map +1 -1
  66. package/types/examples/components/Autocomplete/Autocomplete.d.ts +40 -40
  67. package/types/examples/components/Autocomplete/Autocomplete.d.ts.map +1 -1
  68. package/cjs/components/CodeField/hooks/useWebOTP.js +0 -107
  69. package/cjs/components/CodeField/hooks/useWebOTP.js.map +0 -1
  70. package/cjs/components/CodeField/utils/isWebOTPSupported.js +0 -10
  71. package/cjs/components/CodeField/utils/isWebOTPSupported.js.map +0 -1
  72. package/emotion/cjs/components/CodeField/hooks/useWebOTP.js +0 -256
  73. package/emotion/cjs/components/CodeField/utils/isWebOTPSupported.js +0 -13
  74. package/emotion/es/components/CodeField/hooks/useWebOTP.js +0 -246
  75. package/emotion/es/components/CodeField/utils/isWebOTPSupported.js +0 -3
  76. package/es/components/CodeField/hooks/useWebOTP.js +0 -103
  77. package/es/components/CodeField/hooks/useWebOTP.js.map +0 -1
  78. package/es/components/CodeField/utils/isWebOTPSupported.js +0 -6
  79. package/es/components/CodeField/utils/isWebOTPSupported.js.map +0 -1
  80. package/styled-components/cjs/components/CodeField/hooks/useWebOTP.js +0 -256
  81. package/styled-components/cjs/components/CodeField/utils/isWebOTPSupported.js +0 -13
  82. package/styled-components/es/components/CodeField/hooks/useWebOTP.js +0 -246
  83. package/styled-components/es/components/CodeField/utils/isWebOTPSupported.js +0 -3
  84. package/types/components/CodeField/hooks/useWebOTP.d.ts +0 -24
  85. package/types/components/CodeField/hooks/useWebOTP.d.ts.map +0 -1
  86. package/types/components/CodeField/utils/isWebOTPSupported.d.ts +0 -2
  87. 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,3 +0,0 @@
1
- export var isWebOTPSupported = function() {
2
- return typeof window !== 'undefined' && 'OTPCredential' in window && navigator.credentials && typeof navigator.credentials.get === 'function';
3
- };
@@ -1,103 +0,0 @@
1
- import { asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../../../_virtual/_rollupPluginBabelHelpers.js';
2
- import { useRef, useCallback, useEffect } from 'react';
3
- import { isWebOTPSupported } from '../utils/isWebOTPSupported.js';
4
- import { getCodeValue } from '../utils/initialValuesHelper.js';
5
-
6
- // Type guard function to check if credential is OTPCredential
7
- var isOTPCredential = function isOTPCredential(credential) {
8
- return credential !== null && 'code' in credential;
9
- };
10
- var useWebOTP = function useWebOTP(_ref) {
11
- var codeString = _ref.codeString,
12
- enableSMSAutoRead = _ref.enableSMSAutoRead,
13
- disabled = _ref.disabled,
14
- codeLength = _ref.codeLength,
15
- codeSetter = _ref.codeSetter,
16
- onFullCodeEnter = _ref.onFullCodeEnter,
17
- setOtpVal = _ref.setOtpVal;
18
- var abortControllerRef = useRef(null);
19
- var startWebOTPListener = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
20
- var otp, otpCode, newCode;
21
- return _regeneratorRuntime().wrap(function _callee$(_context) {
22
- while (1) switch (_context.prev = _context.next) {
23
- case 0:
24
- if (!(!enableSMSAutoRead || disabled || !isWebOTPSupported())) {
25
- _context.next = 2;
26
- break;
27
- }
28
- return _context.abrupt("return");
29
- case 2:
30
- if (abortControllerRef.current) {
31
- abortControllerRef.current.abort();
32
- }
33
- abortControllerRef.current = new AbortController();
34
- _context.prev = 4;
35
- _context.next = 7;
36
- return navigator.credentials.get({
37
- otp: {
38
- transport: ['sms']
39
- },
40
- signal: abortControllerRef.current.signal
41
- });
42
- case 7:
43
- otp = _context.sent;
44
- console.log('otp received', otp);
45
- setOtpVal(otp);
46
-
47
- // Type guard to check if it's an OTP credential
48
- if (otp && isOTPCredential(otp) && otp.code) {
49
- otpCode = otp.code; // Validate the OTP code length matches our expected length
50
- if (otpCode.length === codeLength) {
51
- newCode = getCodeValue(codeLength, otpCode);
52
- codeSetter(newCode);
53
-
54
- // Trigger full code enter callback
55
- if (onFullCodeEnter) {
56
- onFullCodeEnter(otpCode);
57
- }
58
- }
59
- }
60
- _context.next = 16;
61
- break;
62
- case 13:
63
- _context.prev = 13;
64
- _context.t0 = _context["catch"](4);
65
- if (_context.t0 instanceof DOMException) {
66
- if (_context.t0.name !== 'AbortError' && _context.t0.name !== 'NotAllowedError') {
67
- console.warn('Web OTP API error:', _context.t0);
68
- }
69
- } else if (_context.t0 instanceof Error) {
70
- console.warn('Web OTP API error:', _context.t0);
71
- } else {
72
- console.warn('Unknown Web OTP API error:', _context.t0);
73
- }
74
- case 16:
75
- case "end":
76
- return _context.stop();
77
- }
78
- }, _callee, null, [[4, 13]]);
79
- })), [enableSMSAutoRead, disabled, codeLength, onFullCodeEnter]);
80
- var stopWebOTPListener = useCallback(function () {
81
- if (abortControllerRef.current) {
82
- abortControllerRef.current.abort();
83
- abortControllerRef.current = null;
84
- }
85
- }, []);
86
- useEffect(function () {
87
- if (isWebOTPSupported() && codeString === '' && enableSMSAutoRead && !disabled) {
88
- startWebOTPListener();
89
- } else {
90
- stopWebOTPListener();
91
- }
92
- return function () {
93
- stopWebOTPListener();
94
- };
95
- }, [codeString, enableSMSAutoRead, disabled, startWebOTPListener, stopWebOTPListener]);
96
- return {
97
- startWebOTPListener: startWebOTPListener,
98
- stopWebOTPListener: stopWebOTPListener
99
- };
100
- };
101
-
102
- export { useWebOTP };
103
- //# sourceMappingURL=useWebOTP.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useWebOTP.js","sources":["../../../../src/components/CodeField/hooks/useWebOTP.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nimport { getCodeValue, isWebOTPSupported } from '../utils';\n\ntype UseWebOTPProps = {\n codeString: string;\n enableSMSAutoRead: boolean;\n disabled: boolean;\n codeLength: number;\n codeSetter: (newCode: Array<string>) => void;\n onFullCodeEnter?: (code: string) => void;\n setOtpVal: React.Dispatch<React.SetStateAction<Credential | null>>;\n};\n\ntype OTPTransport = 'sms';\n\ninterface OTPCredential extends Credential {\n code: string;\n}\n\ndeclare global {\n interface CredentialRequestOptions {\n otp?: {\n transport: OTPTransport[];\n };\n signal?: AbortSignal;\n }\n}\n\n// Type guard function to check if credential is OTPCredential\nconst isOTPCredential = (credential: Credential | null): credential is OTPCredential => {\n return credential !== null && 'code' in credential;\n};\n\nexport const useWebOTP = ({\n codeString,\n enableSMSAutoRead,\n disabled,\n codeLength,\n codeSetter,\n onFullCodeEnter,\n setOtpVal,\n}: UseWebOTPProps) => {\n const abortControllerRef = useRef<AbortController | null>(null);\n\n const startWebOTPListener = useCallback(async () => {\n if (!enableSMSAutoRead || disabled || !isWebOTPSupported()) {\n return;\n }\n\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n\n abortControllerRef.current = new AbortController();\n\n try {\n const otp = await navigator.credentials.get({\n otp: { transport: ['sms'] as OTPTransport[] },\n signal: abortControllerRef.current.signal,\n });\n\n console.log('otp received', otp);\n\n setOtpVal(otp);\n\n // Type guard to check if it's an OTP credential\n if (otp && isOTPCredential(otp) && otp.code) {\n const otpCode = otp.code;\n\n // Validate the OTP code length matches our expected length\n if (otpCode.length === codeLength) {\n const newCode = getCodeValue(codeLength, otpCode);\n codeSetter(newCode);\n\n // Trigger full code enter callback\n if (onFullCodeEnter) {\n onFullCodeEnter(otpCode);\n }\n }\n }\n } catch (err) {\n if (err instanceof DOMException) {\n if (err.name !== 'AbortError' && err.name !== 'NotAllowedError') {\n console.warn('Web OTP API error:', err);\n }\n } else if (err instanceof Error) {\n console.warn('Web OTP API error:', err);\n } else {\n console.warn('Unknown Web OTP API error:', err);\n }\n }\n }, [enableSMSAutoRead, disabled, codeLength, onFullCodeEnter]);\n\n const stopWebOTPListener = useCallback(() => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n abortControllerRef.current = null;\n }\n }, []);\n\n useEffect(() => {\n if (isWebOTPSupported() && codeString === '' && enableSMSAutoRead && !disabled) {\n startWebOTPListener();\n } else {\n stopWebOTPListener();\n }\n\n return () => {\n stopWebOTPListener();\n };\n }, [codeString, enableSMSAutoRead, disabled, startWebOTPListener, stopWebOTPListener]);\n\n return { startWebOTPListener, stopWebOTPListener };\n};\n"],"names":["isOTPCredential","credential","useWebOTP","_ref","codeString","enableSMSAutoRead","disabled","codeLength","codeSetter","onFullCodeEnter","setOtpVal","abortControllerRef","useRef","startWebOTPListener","useCallback","_asyncToGenerator","_regeneratorRuntime","mark","_callee","otp","otpCode","newCode","wrap","_callee$","_context","prev","next","isWebOTPSupported","abrupt","current","abort","AbortController","navigator","credentials","get","transport","signal","sent","console","log","code","length","getCodeValue","t0","DOMException","name","warn","Error","stop","stopWebOTPListener","useEffect"],"mappings":";;;;;AA6BA;AACA,IAAMA,eAAe,GAAG,SAAlBA,eAAeA,CAAIC,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EAAE;AAC5EO,MAAAA,mBAAmB,EAAE,CAAA;AACzB,KAAC,MAAM;AACHoC,MAAAA,kBAAkB,EAAE,CAAA;AACxB,KAAA;AAEA,IAAA,OAAO,YAAM;AACTA,MAAAA,kBAAkB,EAAE,CAAA;KACvB,CAAA;AACL,GAAC,EAAE,CAAC7C,UAAU,EAAEC,iBAAiB,EAAEC,QAAQ,EAAEO,mBAAmB,EAAEoC,kBAAkB,CAAC,CAAC,CAAA;EAEtF,OAAO;AAAEpC,IAAAA,mBAAmB,EAAnBA,mBAAmB;AAAEoC,IAAAA,kBAAkB,EAAlBA,kBAAAA;GAAoB,CAAA;AACtD;;;;"}
@@ -1,6 +0,0 @@
1
- var isWebOTPSupported = function isWebOTPSupported() {
2
- return typeof window !== 'undefined' && 'OTPCredential' in window && navigator.credentials && typeof navigator.credentials.get === 'function';
3
- };
4
-
5
- export { isWebOTPSupported };
6
- //# sourceMappingURL=isWebOTPSupported.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isWebOTPSupported.js","sources":["../../../../src/components/CodeField/utils/isWebOTPSupported.ts"],"sourcesContent":["export const isWebOTPSupported = () => {\n return (\n typeof window !== 'undefined' &&\n 'OTPCredential' in window &&\n navigator.credentials &&\n typeof navigator.credentials.get === 'function'\n );\n};\n"],"names":["isWebOTPSupported","window","navigator","credentials","get"],"mappings":"IAAaA,iBAAiB,GAAG,SAApBA,iBAAiBA,GAAS;EACnC,OACI,OAAOC,MAAM,KAAK,WAAW,IAC7B,eAAe,IAAIA,MAAM,IACzBC,SAAS,CAACC,WAAW,IACrB,OAAOD,SAAS,CAACC,WAAW,CAACC,GAAG,KAAK,UAAU,CAAA;AAEvD;;;;"}