intelicoreact 1.0.8 → 1.0.10
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.
|
@@ -98,7 +98,8 @@ function InputMask2() {
|
|
|
98
98
|
_ref$returnMaskedValu = _ref.returnMaskedValue,
|
|
99
99
|
returnMaskedValue = _ref$returnMaskedValu === void 0 ? false : _ref$returnMaskedValu,
|
|
100
100
|
name = _ref.name,
|
|
101
|
-
testId = _ref.testId
|
|
101
|
+
testId = _ref.testId,
|
|
102
|
+
disabled = _ref.disabled;
|
|
102
103
|
|
|
103
104
|
var errors = _objectSpread(_objectSpread({}, _config.DEFAULT_ERRORS), customErrors);
|
|
104
105
|
|
|
@@ -121,31 +122,28 @@ function InputMask2() {
|
|
|
121
122
|
|
|
122
123
|
var inputRef = (0, _react.useRef)(null);
|
|
123
124
|
|
|
124
|
-
var
|
|
125
|
+
var setCursor = function setCursor(cursor) {
|
|
126
|
+
var input = inputRef.current;
|
|
127
|
+
if (input) setTimeout(function () {
|
|
128
|
+
return input.setSelectionRange(cursor, cursor);
|
|
129
|
+
}, 0);
|
|
130
|
+
}; // ERRORS MANAGEMENT FUNCTIONS | START //
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
var _useState7 = (0, _react.useState)(false),
|
|
125
134
|
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
isError = _useState8[0],
|
|
136
|
+
setError = _useState8[1];
|
|
128
137
|
|
|
129
|
-
var _useState9 = (0, _react.useState)(
|
|
138
|
+
var _useState9 = (0, _react.useState)(false),
|
|
130
139
|
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
blinkError = _useState10[0],
|
|
141
|
+
setBlinkError = _useState10[1];
|
|
134
142
|
|
|
135
|
-
var _useState11 = (0, _react.useState)(
|
|
143
|
+
var _useState11 = (0, _react.useState)(errors.default),
|
|
136
144
|
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
var _useState13 = (0, _react.useState)(false),
|
|
141
|
-
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
|
142
|
-
blinkError = _useState14[0],
|
|
143
|
-
setBlinkError = _useState14[1];
|
|
144
|
-
|
|
145
|
-
var _useState15 = (0, _react.useState)(errors.default),
|
|
146
|
-
_useState16 = (0, _slicedToArray2.default)(_useState15, 2),
|
|
147
|
-
errorMessage = _useState16[0],
|
|
148
|
-
setErrorMessage = _useState16[1];
|
|
145
|
+
errorMessage = _useState12[0],
|
|
146
|
+
setErrorMessage = _useState12[1];
|
|
149
147
|
|
|
150
148
|
var clearErrorMessage = function clearErrorMessage() {
|
|
151
149
|
return setErrorMessage(errors.default);
|
|
@@ -153,10 +151,10 @@ function InputMask2() {
|
|
|
153
151
|
// INNER VALUE MANAGEMENT FUNCTIONS | START //
|
|
154
152
|
|
|
155
153
|
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
innerValue =
|
|
159
|
-
setInnerValue =
|
|
154
|
+
var _useState13 = (0, _react.useState)([]),
|
|
155
|
+
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
|
156
|
+
innerValue = _useState14[0],
|
|
157
|
+
setInnerValue = _useState14[1];
|
|
160
158
|
|
|
161
159
|
var prevValueRef = (0, _react.useRef)([]);
|
|
162
160
|
|
|
@@ -418,38 +416,55 @@ function InputMask2() {
|
|
|
418
416
|
};
|
|
419
417
|
|
|
420
418
|
var onKeyDown = function onKeyDown(e) {
|
|
421
|
-
var _getCharByIndex2,
|
|
419
|
+
var _getCharByIndex2, _getCharByIndex3, _getCharByIndex5;
|
|
422
420
|
|
|
423
|
-
onKeyDownProp(e);
|
|
421
|
+
onKeyDownProp === null || onKeyDownProp === void 0 ? void 0 : onKeyDownProp(e);
|
|
424
422
|
var keyCode = e.keyCode;
|
|
425
423
|
var cursor = e.target.selectionStart;
|
|
426
424
|
|
|
427
|
-
if (keyCode
|
|
425
|
+
if (keyCode === 36) {
|
|
426
|
+
setCursor(0);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (keyCode === 39 && (_getCharByIndex2 = getCharByIndex(cursor)) !== null && _getCharByIndex2 !== void 0 && _getCharByIndex2.isSpecialSymbol) {
|
|
431
|
+
setCursor(cursor);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (keyCode !== 8 && keyCode !== 37 && (_getCharByIndex3 = getCharByIndex(cursor)) !== null && _getCharByIndex3 !== void 0 && _getCharByIndex3.isSpecialSymbol) {
|
|
428
436
|
if (keyCode === 46) {
|
|
429
437
|
e.preventDefault();
|
|
430
438
|
e.stopPropagation();
|
|
431
439
|
}
|
|
432
440
|
|
|
433
|
-
while ((
|
|
434
|
-
var
|
|
441
|
+
while ((_getCharByIndex4 = getCharByIndex(cursor)) !== null && _getCharByIndex4 !== void 0 && _getCharByIndex4.isSpecialSymbol && cursor <= maxEditableIndex) {
|
|
442
|
+
var _getCharByIndex4;
|
|
435
443
|
|
|
436
444
|
++cursor;
|
|
437
445
|
}
|
|
438
446
|
|
|
439
447
|
setCursor(cursor);
|
|
448
|
+
return;
|
|
440
449
|
}
|
|
441
450
|
|
|
442
|
-
if (keyCode === 8 && (
|
|
451
|
+
if (keyCode === 8 && (_getCharByIndex5 = getCharByIndex(cursor - 1)) !== null && _getCharByIndex5 !== void 0 && _getCharByIndex5.isSpecialSymbol) {
|
|
443
452
|
e.preventDefault();
|
|
444
453
|
e.stopPropagation();
|
|
445
454
|
|
|
446
|
-
while ((
|
|
447
|
-
var
|
|
455
|
+
while ((_getCharByIndex6 = getCharByIndex(cursor - 1)) !== null && _getCharByIndex6 !== void 0 && _getCharByIndex6.isSpecialSymbol && cursor > 0) {
|
|
456
|
+
var _getCharByIndex6;
|
|
448
457
|
|
|
449
458
|
--cursor;
|
|
450
459
|
}
|
|
451
460
|
|
|
452
461
|
setCursor(cursor);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (keyCode === 46) {
|
|
466
|
+
setCursor(cursor);
|
|
467
|
+
return;
|
|
453
468
|
}
|
|
454
469
|
|
|
455
470
|
if (cursor > maxEditableIndex) setCursor(maxEditableIndex);
|
|
@@ -470,7 +485,9 @@ function InputMask2() {
|
|
|
470
485
|
clearErrorMessage();
|
|
471
486
|
};
|
|
472
487
|
|
|
473
|
-
var _onFocus = function onFocus() {
|
|
488
|
+
var _onFocus = function onFocus(e) {
|
|
489
|
+
var cursor = e.target.selectionStart;
|
|
490
|
+
setCursorPos(cursor);
|
|
474
491
|
setFocused(true);
|
|
475
492
|
onFocusProp();
|
|
476
493
|
};
|
|
@@ -486,28 +503,15 @@ function InputMask2() {
|
|
|
486
503
|
};
|
|
487
504
|
|
|
488
505
|
var handleChange = function handleChange(e) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
var cursor = e.target.selectionStart;
|
|
492
|
-
if ((_getCharByIndex6 = getCharByIndex(cursor)) !== null && _getCharByIndex6 !== void 0 && _getCharByIndex6.isSpecialSymbol) cursor >= prevCursor && cursor + 1 <= maxEditableIndex ? ++cursor : cursor;
|
|
493
|
-
setCursor(cursor > maxEditableIndex ? maxEditableIndex : cursor);
|
|
494
|
-
onChange && onChange(e);
|
|
506
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
495
507
|
}; // GENERAL EVENT HANDLERS | END //
|
|
496
508
|
/// --- OBSERVERS ---///
|
|
509
|
+
// Render Mask
|
|
497
510
|
|
|
498
511
|
|
|
499
512
|
(0, _react.useEffect)(function () {
|
|
500
|
-
|
|
501
|
-
var input = inputRef.current;
|
|
502
|
-
if (input) input.setSelectionRange(cursor, cursor);
|
|
503
|
-
setPrevCursor(cursor);
|
|
504
|
-
setCursor(null);
|
|
505
|
-
}
|
|
506
|
-
}, [inputRef, cursor, inputValue]); // Render Mask
|
|
507
|
-
|
|
508
|
-
(0, _react.useEffect)(function () {
|
|
513
|
+
setInnerValue([]);
|
|
509
514
|
setMaskRendered(false);
|
|
510
|
-
setValue('');
|
|
511
515
|
if (!maskPattern) maskPattern = '';
|
|
512
516
|
maskPattern.split('').map(function (char, id, i) {
|
|
513
517
|
addInnerValueChar({
|
|
@@ -570,7 +574,6 @@ function InputMask2() {
|
|
|
570
574
|
ref = obj.ref,
|
|
571
575
|
maskChar = obj.maskChar,
|
|
572
576
|
isSpecialSymbol = obj.isSpecialSymbol;
|
|
573
|
-
var prevChar = getCharByIndex(i - 1);
|
|
574
577
|
return /*#__PURE__*/_react.default.createElement("span", {
|
|
575
578
|
tabIndex: -1,
|
|
576
579
|
key: i,
|
|
@@ -644,7 +647,15 @@ function InputMask2() {
|
|
|
644
647
|
|
|
645
648
|
var render = function render() {
|
|
646
649
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
647
|
-
className:
|
|
650
|
+
className: (0, _classnames.default)('input-mask2_wrapper', className, {
|
|
651
|
+
'input-mask_error': isError
|
|
652
|
+
}, {
|
|
653
|
+
'input-mask_focus': isFocused
|
|
654
|
+
}, {
|
|
655
|
+
'input-mask_blink-error': blinkError
|
|
656
|
+
}, {
|
|
657
|
+
disabled: disabled
|
|
658
|
+
})
|
|
648
659
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
649
660
|
className: "\n input-mask\n ".concat(isError ? 'input-mask_error' : '', "\n ").concat(isFocused ? 'input-mask_focus' : '', "\n ").concat(blinkError ? 'input-mask_blink-error' : '', "\n ")
|
|
650
661
|
}, showHint && isHintLeft && /*#__PURE__*/_react.default.createElement("div", {
|