@salutejs/plasma-new-hope 0.336.0-canary.2210.17491654160.0 → 0.336.0-canary.2210.17550717632.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.js +24 -25
- package/cjs/components/CodeField/CodeField.js.map +1 -1
- package/cjs/components/CodeField/hooks/useWebOTP.js +7 -19
- package/cjs/components/CodeField/hooks/useWebOTP.js.map +1 -1
- package/emotion/cjs/components/CodeField/CodeField.js +22 -15
- package/emotion/cjs/components/CodeField/hooks/useWebOTP.js +1 -11
- package/emotion/cjs/examples/components/Combobox/Combobox.js +15 -0
- package/emotion/es/components/CodeField/CodeField.js +23 -16
- package/emotion/es/components/CodeField/hooks/useWebOTP.js +1 -11
- package/es/components/CodeField/CodeField.js +25 -26
- package/es/components/CodeField/CodeField.js.map +1 -1
- package/es/components/CodeField/hooks/useWebOTP.js +7 -19
- package/es/components/CodeField/hooks/useWebOTP.js.map +1 -1
- package/package.json +2 -2
- package/styled-components/cjs/components/CodeField/CodeField.js +22 -15
- package/styled-components/cjs/components/CodeField/hooks/useWebOTP.js +1 -11
- package/styled-components/es/components/CodeField/CodeField.js +23 -16
- package/styled-components/es/components/CodeField/hooks/useWebOTP.js +1 -11
- package/styled-components/es/examples/components/Combobox/Combobox.js +0 -7
- package/types/components/CodeField/CodeField.d.ts.map +1 -1
- package/types/components/CodeField/hooks/useWebOTP.d.ts +1 -5
- package/types/components/CodeField/hooks/useWebOTP.d.ts.map +1 -1
@@ -213,13 +213,14 @@ var codeFieldRoot = function(Root) {
|
|
213
213
|
"onChange",
|
214
214
|
"onFullCodeEnter"
|
215
215
|
]);
|
216
|
+
var _autocompleteRef_current;
|
216
217
|
var _useState = _sliced_to_array((0, _react.useState)((0, _utils1.getCodeValue)(codeLength, '')), 2), innerValue = _useState[0], setInnerValue = _useState[1];
|
217
|
-
var code =
|
218
|
+
var code = typeof outerValue === 'string' ? (0, _utils1.getCodeValue)(codeLength, outerValue) : innerValue;
|
218
219
|
var _useState1 = _sliced_to_array((0, _react.useState)(code.join('')), 2), originalValue = _useState1[0], setOriginalValue = _useState1[1];
|
219
|
-
var _useState2 = _sliced_to_array((0, _react.useState)(null), 2), otpVal = _useState2[0], setOtpVal = _useState2[1];
|
220
220
|
var inputRefs = (0, _react.useRef)([]);
|
221
221
|
var inputContainerRef = (0, _react.useRef)(null);
|
222
222
|
var captionRef = (0, _react.useRef)(null);
|
223
|
+
var autocompleteRef = (0, _react.useRef)(null);
|
223
224
|
var fieldPattern = (0, _utils1.getFieldPattern)(allowedSymbols);
|
224
225
|
var placeholderValue = (0, _utils1.getPlaceholderValue)(codeLength, placeholder);
|
225
226
|
var parts = codeLength === 6 ? 2 : 1;
|
@@ -235,25 +236,21 @@ var codeFieldRoot = function(Root) {
|
|
235
236
|
return lastEmptyIndex >= 0 ? lastEmptyIndex : codeLength - 1;
|
236
237
|
};
|
237
238
|
var codeSetter = function(newCode) {
|
238
|
-
setInnerValue(newCode);
|
239
239
|
var originalCode = newCode.join('');
|
240
|
+
setInnerValue((0, _utils1.getCodeValue)(codeLength, originalCode));
|
240
241
|
setOriginalValue(originalCode);
|
241
242
|
if (onChange) {
|
242
243
|
onChange(originalCode);
|
243
244
|
}
|
244
|
-
if (originalCode.length > 0) {
|
245
|
-
stopWebOTPListener();
|
246
|
-
}
|
247
245
|
};
|
248
|
-
|
246
|
+
(0, _useWebOTP.useWebOTP)({
|
249
247
|
codeString: originalValue,
|
250
248
|
enableSMSAutoRead: autoComplete === 'one-time-code',
|
251
249
|
disabled: Boolean(disabled),
|
252
250
|
codeLength: codeLength,
|
253
251
|
codeSetter: codeSetter,
|
254
|
-
onFullCodeEnter: onFullCodeEnter
|
255
|
-
|
256
|
-
}), startWebOTPListener = _useWebOTP1.startWebOTPListener, stopWebOTPListener = _useWebOTP1.stopWebOTPListener;
|
252
|
+
onFullCodeEnter: onFullCodeEnter
|
253
|
+
});
|
257
254
|
var handleClick = function() {
|
258
255
|
if (disabled) {
|
259
256
|
return;
|
@@ -311,6 +308,9 @@ var codeFieldRoot = function(Root) {
|
|
311
308
|
setIsError(false);
|
312
309
|
}
|
313
310
|
}
|
311
|
+
if (!symbol) {
|
312
|
+
return;
|
313
|
+
}
|
314
314
|
if (!fieldPattern) {
|
315
315
|
newCode[index] = symbol;
|
316
316
|
codeSetter(newCode);
|
@@ -320,9 +320,6 @@ var codeFieldRoot = function(Root) {
|
|
320
320
|
}
|
321
321
|
return;
|
322
322
|
}
|
323
|
-
if (!symbol) {
|
324
|
-
return;
|
325
|
-
}
|
326
323
|
if (fieldPattern.test(symbol)) {
|
327
324
|
newCode[index] = symbol.charAt(symbol.length - 1);
|
328
325
|
codeSetter(newCode);
|
@@ -367,7 +364,6 @@ var codeFieldRoot = function(Root) {
|
|
367
364
|
if (onFullCodeEnter) {
|
368
365
|
onFullCodeEnter(fullCode);
|
369
366
|
}
|
370
|
-
startWebOTPListener();
|
371
367
|
}, []);
|
372
368
|
(0, _hooks1.useCodeHook)({
|
373
369
|
inputRefs: inputRefs,
|
@@ -394,6 +390,16 @@ var codeFieldRoot = function(Root) {
|
|
394
390
|
}, [
|
395
391
|
isError
|
396
392
|
]);
|
393
|
+
(0, _react.useEffect)(function() {
|
394
|
+
if (disabled || !autocompleteRef.current) {
|
395
|
+
return;
|
396
|
+
}
|
397
|
+
var autocompleteCode = autocompleteRef.current.value.split('');
|
398
|
+
codeSetter(autocompleteCode);
|
399
|
+
}, [
|
400
|
+
(_autocompleteRef_current = autocompleteRef.current) === null || _autocompleteRef_current === void 0 ? void 0 : _autocompleteRef_current.value,
|
401
|
+
disabled
|
402
|
+
]);
|
397
403
|
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(Root, _object_spread({
|
398
404
|
ref: ref,
|
399
405
|
view: view,
|
@@ -436,9 +442,10 @@ var codeFieldRoot = function(Root) {
|
|
436
442
|
captionAlign: captionAlign,
|
437
443
|
widthValue: widthValue
|
438
444
|
}, caption), isWebOTPEnabled && /*#__PURE__*/ _react.default.createElement(_CodeFieldstyles.HiddenInput, _object_spread({
|
445
|
+
ref: autocompleteRef,
|
439
446
|
autoComplete: autoComplete,
|
440
447
|
tabIndex: -1
|
441
|
-
}, rest)))
|
448
|
+
}, rest))));
|
442
449
|
});
|
443
450
|
};
|
444
451
|
var codeFieldConfig = {
|
@@ -137,12 +137,11 @@ function _ts_generator(thisArg, body) {
|
|
137
137
|
};
|
138
138
|
}
|
139
139
|
}
|
140
|
-
// Type guard function to check if credential is OTPCredential
|
141
140
|
var isOTPCredential = function(credential) {
|
142
141
|
return credential !== null && 'code' in credential;
|
143
142
|
};
|
144
143
|
var useWebOTP = function(param) {
|
145
|
-
var codeString = param.codeString, enableSMSAutoRead = param.enableSMSAutoRead, disabled = param.disabled, codeLength = param.codeLength, codeSetter = param.codeSetter, onFullCodeEnter = param.onFullCodeEnter
|
144
|
+
var codeString = param.codeString, enableSMSAutoRead = param.enableSMSAutoRead, disabled = param.disabled, codeLength = param.codeLength, codeSetter = param.codeSetter, onFullCodeEnter = param.onFullCodeEnter;
|
146
145
|
var abortControllerRef = (0, _react.useRef)(null);
|
147
146
|
var startWebOTPListener = (0, _react.useCallback)(function() {
|
148
147
|
return _async_to_generator(function() {
|
@@ -180,16 +179,11 @@ var useWebOTP = function(param) {
|
|
180
179
|
];
|
181
180
|
case 2:
|
182
181
|
otp = _state.sent();
|
183
|
-
console.log('otp received', otp);
|
184
|
-
setOtpVal(otp);
|
185
|
-
// Type guard to check if it's an OTP credential
|
186
182
|
if (otp && isOTPCredential(otp) && otp.code) {
|
187
183
|
otpCode = otp.code;
|
188
|
-
// Validate the OTP code length matches our expected length
|
189
184
|
if (otpCode.length === codeLength) {
|
190
185
|
newCode = (0, _utils.getCodeValue)(codeLength, otpCode);
|
191
186
|
codeSetter(newCode);
|
192
|
-
// Trigger full code enter callback
|
193
187
|
if (onFullCodeEnter) {
|
194
188
|
onFullCodeEnter(otpCode);
|
195
189
|
}
|
@@ -249,8 +243,4 @@ var useWebOTP = function(param) {
|
|
249
243
|
startWebOTPListener,
|
250
244
|
stopWebOTPListener
|
251
245
|
]);
|
252
|
-
return {
|
253
|
-
startWebOTPListener: startWebOTPListener,
|
254
|
-
stopWebOTPListener: stopWebOTPListener
|
255
|
-
};
|
256
246
|
};
|
@@ -111,7 +111,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
111
111
|
if (n === "Map" || n === "Set") return Array.from(n);
|
112
112
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
113
113
|
}
|
114
|
-
import React, { forwardRef, Fragment, useCallback, useRef, useState } from "react";
|
114
|
+
import React, { forwardRef, Fragment, useCallback, useEffect, useRef, useState } from "react";
|
115
115
|
import cls from "classnames";
|
116
116
|
import { useDidMountEffect } from "../../hooks";
|
117
117
|
import { getSizeValueFromProp } from "../../utils";
|
@@ -149,13 +149,14 @@ export var codeFieldRoot = function(Root) {
|
|
149
149
|
"onChange",
|
150
150
|
"onFullCodeEnter"
|
151
151
|
]);
|
152
|
+
var _autocompleteRef_current;
|
152
153
|
var _useState = _sliced_to_array(useState(getCodeValue(codeLength, '')), 2), innerValue = _useState[0], setInnerValue = _useState[1];
|
153
|
-
var code =
|
154
|
+
var code = typeof outerValue === 'string' ? getCodeValue(codeLength, outerValue) : innerValue;
|
154
155
|
var _useState1 = _sliced_to_array(useState(code.join('')), 2), originalValue = _useState1[0], setOriginalValue = _useState1[1];
|
155
|
-
var _useState2 = _sliced_to_array(useState(null), 2), otpVal = _useState2[0], setOtpVal = _useState2[1];
|
156
156
|
var inputRefs = useRef([]);
|
157
157
|
var inputContainerRef = useRef(null);
|
158
158
|
var captionRef = useRef(null);
|
159
|
+
var autocompleteRef = useRef(null);
|
159
160
|
var fieldPattern = getFieldPattern(allowedSymbols);
|
160
161
|
var placeholderValue = getPlaceholderValue(codeLength, placeholder);
|
161
162
|
var parts = codeLength === 6 ? 2 : 1;
|
@@ -171,25 +172,21 @@ export var codeFieldRoot = function(Root) {
|
|
171
172
|
return lastEmptyIndex >= 0 ? lastEmptyIndex : codeLength - 1;
|
172
173
|
};
|
173
174
|
var codeSetter = function(newCode) {
|
174
|
-
setInnerValue(newCode);
|
175
175
|
var originalCode = newCode.join('');
|
176
|
+
setInnerValue(getCodeValue(codeLength, originalCode));
|
176
177
|
setOriginalValue(originalCode);
|
177
178
|
if (onChange) {
|
178
179
|
onChange(originalCode);
|
179
180
|
}
|
180
|
-
if (originalCode.length > 0) {
|
181
|
-
stopWebOTPListener();
|
182
|
-
}
|
183
181
|
};
|
184
|
-
|
182
|
+
useWebOTP({
|
185
183
|
codeString: originalValue,
|
186
184
|
enableSMSAutoRead: autoComplete === 'one-time-code',
|
187
185
|
disabled: Boolean(disabled),
|
188
186
|
codeLength: codeLength,
|
189
187
|
codeSetter: codeSetter,
|
190
|
-
onFullCodeEnter: onFullCodeEnter
|
191
|
-
|
192
|
-
}), startWebOTPListener = _useWebOTP.startWebOTPListener, stopWebOTPListener = _useWebOTP.stopWebOTPListener;
|
188
|
+
onFullCodeEnter: onFullCodeEnter
|
189
|
+
});
|
193
190
|
var handleClick = function() {
|
194
191
|
if (disabled) {
|
195
192
|
return;
|
@@ -247,6 +244,9 @@ export var codeFieldRoot = function(Root) {
|
|
247
244
|
setIsError(false);
|
248
245
|
}
|
249
246
|
}
|
247
|
+
if (!symbol) {
|
248
|
+
return;
|
249
|
+
}
|
250
250
|
if (!fieldPattern) {
|
251
251
|
newCode[index] = symbol;
|
252
252
|
codeSetter(newCode);
|
@@ -256,9 +256,6 @@ export var codeFieldRoot = function(Root) {
|
|
256
256
|
}
|
257
257
|
return;
|
258
258
|
}
|
259
|
-
if (!symbol) {
|
260
|
-
return;
|
261
|
-
}
|
262
259
|
if (fieldPattern.test(symbol)) {
|
263
260
|
newCode[index] = symbol.charAt(symbol.length - 1);
|
264
261
|
codeSetter(newCode);
|
@@ -303,7 +300,6 @@ export var codeFieldRoot = function(Root) {
|
|
303
300
|
if (onFullCodeEnter) {
|
304
301
|
onFullCodeEnter(fullCode);
|
305
302
|
}
|
306
|
-
startWebOTPListener();
|
307
303
|
}, []);
|
308
304
|
useCodeHook({
|
309
305
|
inputRefs: inputRefs,
|
@@ -330,6 +326,16 @@ export var codeFieldRoot = function(Root) {
|
|
330
326
|
}, [
|
331
327
|
isError
|
332
328
|
]);
|
329
|
+
useEffect(function() {
|
330
|
+
if (disabled || !autocompleteRef.current) {
|
331
|
+
return;
|
332
|
+
}
|
333
|
+
var autocompleteCode = autocompleteRef.current.value.split('');
|
334
|
+
codeSetter(autocompleteCode);
|
335
|
+
}, [
|
336
|
+
(_autocompleteRef_current = autocompleteRef.current) === null || _autocompleteRef_current === void 0 ? void 0 : _autocompleteRef_current.value,
|
337
|
+
disabled
|
338
|
+
]);
|
333
339
|
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Root, _object_spread({
|
334
340
|
ref: ref,
|
335
341
|
view: view,
|
@@ -372,9 +378,10 @@ export var codeFieldRoot = function(Root) {
|
|
372
378
|
captionAlign: captionAlign,
|
373
379
|
widthValue: widthValue
|
374
380
|
}, caption), isWebOTPEnabled && /*#__PURE__*/ React.createElement(HiddenInput, _object_spread({
|
381
|
+
ref: autocompleteRef,
|
375
382
|
autoComplete: autoComplete,
|
376
383
|
tabIndex: -1
|
377
|
-
}, rest)))
|
384
|
+
}, rest))));
|
378
385
|
});
|
379
386
|
};
|
380
387
|
export var codeFieldConfig = {
|
@@ -127,12 +127,11 @@ function _ts_generator(thisArg, body) {
|
|
127
127
|
}
|
128
128
|
import { useCallback, useEffect, useRef } from "react";
|
129
129
|
import { getCodeValue, isWebOTPSupported } from "../utils";
|
130
|
-
// Type guard function to check if credential is OTPCredential
|
131
130
|
var isOTPCredential = function(credential) {
|
132
131
|
return credential !== null && 'code' in credential;
|
133
132
|
};
|
134
133
|
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
|
134
|
+
var codeString = param.codeString, enableSMSAutoRead = param.enableSMSAutoRead, disabled = param.disabled, codeLength = param.codeLength, codeSetter = param.codeSetter, onFullCodeEnter = param.onFullCodeEnter;
|
136
135
|
var abortControllerRef = useRef(null);
|
137
136
|
var startWebOTPListener = useCallback(function() {
|
138
137
|
return _async_to_generator(function() {
|
@@ -170,16 +169,11 @@ export var useWebOTP = function(param) {
|
|
170
169
|
];
|
171
170
|
case 2:
|
172
171
|
otp = _state.sent();
|
173
|
-
console.log('otp received', otp);
|
174
|
-
setOtpVal(otp);
|
175
|
-
// Type guard to check if it's an OTP credential
|
176
172
|
if (otp && isOTPCredential(otp) && otp.code) {
|
177
173
|
otpCode = otp.code;
|
178
|
-
// Validate the OTP code length matches our expected length
|
179
174
|
if (otpCode.length === codeLength) {
|
180
175
|
newCode = getCodeValue(codeLength, otpCode);
|
181
176
|
codeSetter(newCode);
|
182
|
-
// Trigger full code enter callback
|
183
177
|
if (onFullCodeEnter) {
|
184
178
|
onFullCodeEnter(otpCode);
|
185
179
|
}
|
@@ -239,8 +233,4 @@ export var useWebOTP = function(param) {
|
|
239
233
|
startWebOTPListener,
|
240
234
|
stopWebOTPListener
|
241
235
|
]);
|
242
|
-
return {
|
243
|
-
startWebOTPListener: startWebOTPListener,
|
244
|
-
stopWebOTPListener: stopWebOTPListener
|
245
|
-
};
|
246
236
|
};
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { component, mergeConfig } from "../../../engines";
|
2
|
-
import { comboboxNewConfig } from "../../..";
|
3
|
-
import { config } from "./Combobox.config";
|
4
|
-
var mergedConfig = mergeConfig(comboboxNewConfig, config);
|
5
|
-
var ComboboxComponent = component(mergedConfig);
|
6
|
-
var Combobox = ComboboxComponent;
|
7
|
-
export { Combobox };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CodeField.d.ts","sourceRoot":"","sources":["../../../src/components/CodeField/CodeField.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"CodeField.d.ts","sourceRoot":"","sources":["../../../src/components/CodeField/CodeField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyE,MAAM,OAAO,CAAC;AAG9F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAkBxD,eAAO,MAAM,aAAa,SAAU,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC;;;;;;;;;;;;;;;;;;;sLA6TxE,CAAC;AAEN,eAAO,MAAM,eAAe;;;mBA/TQ,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwV5E,CAAC"}
|
@@ -5,7 +5,6 @@ type UseWebOTPProps = {
|
|
5
5
|
codeLength: number;
|
6
6
|
codeSetter: (newCode: Array<string>) => void;
|
7
7
|
onFullCodeEnter?: (code: string) => void;
|
8
|
-
setOtpVal: React.Dispatch<React.SetStateAction<Credential | null>>;
|
9
8
|
};
|
10
9
|
type OTPTransport = 'sms';
|
11
10
|
declare global {
|
@@ -16,9 +15,6 @@ declare global {
|
|
16
15
|
signal?: AbortSignal;
|
17
16
|
}
|
18
17
|
}
|
19
|
-
export declare const useWebOTP: ({ codeString, enableSMSAutoRead, disabled, codeLength, codeSetter, onFullCodeEnter,
|
20
|
-
startWebOTPListener: () => Promise<void>;
|
21
|
-
stopWebOTPListener: () => void;
|
22
|
-
};
|
18
|
+
export declare const useWebOTP: ({ codeString, enableSMSAutoRead, disabled, codeLength, codeSetter, onFullCodeEnter, }: UseWebOTPProps) => void;
|
23
19
|
export {};
|
24
20
|
//# sourceMappingURL=useWebOTP.d.ts.map
|
@@ -1 +1 @@
|
|
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;
|
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;CAC5C,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;AAMD,eAAO,MAAM,SAAS,0FAOnB,cAAc,SA+DhB,CAAC"}
|