intelicoreact 0.1.67 → 0.1.68
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.
|
@@ -9,6 +9,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
9
9
|
});
|
|
10
10
|
exports.default = InputMask;
|
|
11
11
|
|
|
12
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
13
|
+
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
+
|
|
12
16
|
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
|
|
13
17
|
|
|
14
18
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
@@ -474,7 +478,11 @@ function InputMask() {
|
|
|
474
478
|
if (isSpecialSymbol) return onBackspaceDown(e, prevIndex);
|
|
475
479
|
|
|
476
480
|
if (maskAsPlaceholder) {
|
|
477
|
-
var newText =
|
|
481
|
+
var newText = innerValue.slice(0, prevIndex).concat(innerValue.slice(i, maxEditableLen !== -1 ? maxEditableLen : innerValue.length)).reduce(function (text, _ref12) {
|
|
482
|
+
var char = _ref12.char;
|
|
483
|
+
return text.concat(char);
|
|
484
|
+
}, ''); // const newText = getInnerValueAsString().substring(0, prevIndex) + getInnerValueAsString().substring(i, maxEditableLen !== -1 ? maxEditableLen : getInnerValueAsString().length);
|
|
485
|
+
|
|
478
486
|
resetInnerValue();
|
|
479
487
|
|
|
480
488
|
_onPaste({
|
|
@@ -490,34 +498,84 @@ function InputMask() {
|
|
|
490
498
|
return true;
|
|
491
499
|
};
|
|
492
500
|
|
|
493
|
-
var onDeleteDown = function
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
501
|
+
var onDeleteDown = /*#__PURE__*/function () {
|
|
502
|
+
var _ref13 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(e, i) {
|
|
503
|
+
var nextIndex, charObj, char, isSpecialSymbol, newText;
|
|
504
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
505
|
+
while (1) {
|
|
506
|
+
switch (_context.prev = _context.next) {
|
|
507
|
+
case 0:
|
|
508
|
+
if (!(0, _functions.getSelectionText)().length) {
|
|
509
|
+
_context.next = 2;
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return _context.abrupt("return", deleteSelectedText());
|
|
514
|
+
|
|
515
|
+
case 2:
|
|
516
|
+
nextIndex = i + 1;
|
|
517
|
+
charObj = getCharByIndex(i);
|
|
518
|
+
|
|
519
|
+
if (charObj) {
|
|
520
|
+
_context.next = 6;
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return _context.abrupt("return", false);
|
|
525
|
+
|
|
526
|
+
case 6:
|
|
527
|
+
char = charObj.char, isSpecialSymbol = charObj.isSpecialSymbol;
|
|
528
|
+
|
|
529
|
+
if (!isSpecialSymbol) {
|
|
530
|
+
_context.next = 9;
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return _context.abrupt("return", onDeleteDown(e, i + 1));
|
|
535
|
+
|
|
536
|
+
case 9:
|
|
537
|
+
if (!(char === '')) {
|
|
538
|
+
_context.next = 11;
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return _context.abrupt("return", false);
|
|
543
|
+
|
|
544
|
+
case 11:
|
|
545
|
+
if (maskAsPlaceholder) {
|
|
546
|
+
newText = innerValue.slice(0, i).concat(innerValue.slice(nextIndex, maxEditableLen !== -1 ? maxEditableLen : innerValue.length)).reduce(function (text, _ref14) {
|
|
547
|
+
var char = _ref14.char;
|
|
548
|
+
return text.concat(char);
|
|
549
|
+
}, ''); // const newText = getInnerValueAsString().substring(0, i) + getInnerValueAsString().substring(nextIndex, maxEditableLen !== -1 ? maxEditableLen : getInnerValueAsString().length);
|
|
550
|
+
|
|
551
|
+
resetInnerValue();
|
|
552
|
+
|
|
553
|
+
_onPaste({
|
|
554
|
+
text: newText
|
|
555
|
+
}, 0);
|
|
556
|
+
|
|
557
|
+
setFocusOnChar(i, i);
|
|
558
|
+
} else {
|
|
559
|
+
updateInnerValueChar({
|
|
560
|
+
char: ''
|
|
561
|
+
}, i);
|
|
562
|
+
setFocusOnChar(nextIndex, i);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return _context.abrupt("return", true);
|
|
566
|
+
|
|
567
|
+
case 13:
|
|
568
|
+
case "end":
|
|
569
|
+
return _context.stop();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}, _callee);
|
|
573
|
+
}));
|
|
518
574
|
|
|
519
|
-
return
|
|
520
|
-
|
|
575
|
+
return function onDeleteDown(_x, _x2) {
|
|
576
|
+
return _ref13.apply(this, arguments);
|
|
577
|
+
};
|
|
578
|
+
}();
|
|
521
579
|
|
|
522
580
|
var onHomeDown = function onHomeDown(e, i) {
|
|
523
581
|
return setFocusOnChar(0, -1);
|
|
@@ -565,58 +623,159 @@ function InputMask() {
|
|
|
565
623
|
}
|
|
566
624
|
};
|
|
567
625
|
|
|
568
|
-
var handleKeyDown = function
|
|
569
|
-
var
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
626
|
+
var handleKeyDown = /*#__PURE__*/function () {
|
|
627
|
+
var _ref15 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(e, i) {
|
|
628
|
+
var _getClearInnerValueAs;
|
|
629
|
+
|
|
630
|
+
var _ref16,
|
|
631
|
+
_ref16$disableErrors,
|
|
632
|
+
disableErrors,
|
|
633
|
+
key,
|
|
634
|
+
keyCode,
|
|
635
|
+
charObj,
|
|
636
|
+
charRef,
|
|
637
|
+
isSpecialSymbol,
|
|
638
|
+
maskChar,
|
|
639
|
+
isReadOnly,
|
|
640
|
+
fromIndex,
|
|
641
|
+
text,
|
|
642
|
+
_args2 = arguments;
|
|
643
|
+
|
|
644
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
645
|
+
while (1) {
|
|
646
|
+
switch (_context2.prev = _context2.next) {
|
|
647
|
+
case 0:
|
|
648
|
+
_ref16 = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {}, _ref16$disableErrors = _ref16.disableErrors, disableErrors = _ref16$disableErrors === void 0 ? false : _ref16$disableErrors;
|
|
649
|
+
|
|
650
|
+
try {
|
|
651
|
+
e.stopPropagation();
|
|
652
|
+
e.preventDefault();
|
|
653
|
+
} catch (e) {}
|
|
654
|
+
|
|
655
|
+
key = e.key, keyCode = e.keyCode;
|
|
656
|
+
charObj = getCharByIndex(i); // Android Text Typing FIX
|
|
657
|
+
|
|
658
|
+
if (!(keyCode == _config.ANDROID_CHROME_TEXT_CODE)) {
|
|
659
|
+
_context2.next = 9;
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
charRef = charObj.ref;
|
|
664
|
+
_context2.next = 8;
|
|
665
|
+
return new Promise(function (resolve) {
|
|
666
|
+
setTimeout(function () {
|
|
667
|
+
var _charRef$current, _charRef$current$inne;
|
|
668
|
+
|
|
669
|
+
//Typed Text
|
|
670
|
+
if ((charRef === null || charRef === void 0 ? void 0 : (_charRef$current = charRef.current) === null || _charRef$current === void 0 ? void 0 : (_charRef$current$inne = _charRef$current.innerText) === null || _charRef$current$inne === void 0 ? void 0 : _charRef$current$inne.length) >= 2) {
|
|
671
|
+
var _charRef$current2;
|
|
672
|
+
|
|
673
|
+
var _charRef$current$inne2 = charRef === null || charRef === void 0 ? void 0 : (_charRef$current2 = charRef.current) === null || _charRef$current2 === void 0 ? void 0 : _charRef$current2.innerText,
|
|
674
|
+
_charRef$current$inne3 = (0, _slicedToArray2.default)(_charRef$current$inne2, 2),
|
|
675
|
+
_key = _charRef$current$inne3[0],
|
|
676
|
+
prevChar = _charRef$current$inne3[1];
|
|
677
|
+
|
|
678
|
+
charRef.current.innerText = prevChar;
|
|
679
|
+
resolve(_key);
|
|
680
|
+
} else {
|
|
681
|
+
resolve(null);
|
|
682
|
+
}
|
|
683
|
+
}, 1);
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
case 8:
|
|
687
|
+
key = _context2.sent;
|
|
688
|
+
|
|
689
|
+
case 9:
|
|
690
|
+
if (!(!charObj || i === innerValue.length - 1)) {
|
|
691
|
+
_context2.next = 11;
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
return _context2.abrupt("return", false);
|
|
696
|
+
|
|
697
|
+
case 11:
|
|
698
|
+
if (!(maskAsPlaceholder && i > getLastTypedIndex() + 1)) {
|
|
699
|
+
_context2.next = 13;
|
|
700
|
+
break;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
return _context2.abrupt("return", handleKeyDown(e, getLastTypedIndex() === 0 ? 0 : getLastTypedIndex() + 1, {
|
|
704
|
+
disableErrors: disableErrors
|
|
705
|
+
}));
|
|
706
|
+
|
|
707
|
+
case 13:
|
|
708
|
+
isSpecialSymbol = charObj.isSpecialSymbol, maskChar = charObj.maskChar, isReadOnly = charObj.isReadOnly;
|
|
709
|
+
|
|
710
|
+
if (!isReadOnly) {
|
|
711
|
+
_context2.next = 16;
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
return _context2.abrupt("return", false);
|
|
716
|
+
|
|
717
|
+
case 16:
|
|
718
|
+
if (!(maskChar === _config.SPACE_CHAR)) {
|
|
719
|
+
_context2.next = 18;
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return _context2.abrupt("return", handleKeyDown(e, i + 1));
|
|
724
|
+
|
|
725
|
+
case 18:
|
|
726
|
+
if (!(isSpecialSymbol && maskChar !== key)) {
|
|
727
|
+
_context2.next = 20;
|
|
728
|
+
break;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
return _context2.abrupt("return", false);
|
|
732
|
+
|
|
733
|
+
case 20:
|
|
734
|
+
if (isValidChar({
|
|
735
|
+
char: key,
|
|
736
|
+
i: i,
|
|
737
|
+
disableErrors: disableErrors
|
|
738
|
+
})) {
|
|
739
|
+
_context2.next = 22;
|
|
740
|
+
break;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
return _context2.abrupt("return", false);
|
|
744
|
+
|
|
745
|
+
case 22:
|
|
746
|
+
if (maskAsPlaceholder && ((_getClearInnerValueAs = getClearInnerValueAsString(i)) === null || _getClearInnerValueAs === void 0 ? void 0 : _getClearInnerValueAs.length) !== 0) {
|
|
747
|
+
fromIndex = i + 1;
|
|
748
|
+
text = innerValue.slice().filter(function (_ref17, index) {
|
|
749
|
+
var isCharSymbol = _ref17.isCharSymbol;
|
|
750
|
+
return index >= i && !isCharSymbol;
|
|
751
|
+
}).map(function (_ref18, index) {
|
|
752
|
+
var char = _ref18.char;
|
|
753
|
+
return char;
|
|
754
|
+
}).join('');
|
|
755
|
+
|
|
756
|
+
_onPaste({
|
|
757
|
+
text: text
|
|
758
|
+
}, fromIndex, false);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
updateInnerValueChar({
|
|
762
|
+
char: key
|
|
763
|
+
}, i);
|
|
764
|
+
onArrowRightDown(e, i);
|
|
765
|
+
return _context2.abrupt("return", true);
|
|
766
|
+
|
|
767
|
+
case 26:
|
|
768
|
+
case "end":
|
|
769
|
+
return _context2.stop();
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}, _callee2);
|
|
773
|
+
}));
|
|
613
774
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
return true;
|
|
619
|
-
};
|
|
775
|
+
return function handleKeyDown(_x3, _x4) {
|
|
776
|
+
return _ref15.apply(this, arguments);
|
|
777
|
+
};
|
|
778
|
+
}();
|
|
620
779
|
|
|
621
780
|
var handleKeyCombinations = function handleKeyCombinations(e, i) {
|
|
622
781
|
var key = e.key,
|
|
@@ -655,9 +814,9 @@ function InputMask() {
|
|
|
655
814
|
};
|
|
656
815
|
|
|
657
816
|
var onClick = function onClick(e, cb) {
|
|
658
|
-
var
|
|
659
|
-
|
|
660
|
-
ignoreIsSelecting =
|
|
817
|
+
var _ref19 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
818
|
+
_ref19$ignoreIsSelect = _ref19.ignoreIsSelecting,
|
|
819
|
+
ignoreIsSelecting = _ref19$ignoreIsSelect === void 0 ? false : _ref19$ignoreIsSelect;
|
|
661
820
|
|
|
662
821
|
try {
|
|
663
822
|
e.stopPropagation();
|
|
@@ -670,9 +829,9 @@ function InputMask() {
|
|
|
670
829
|
};
|
|
671
830
|
|
|
672
831
|
var onCharClick = function onCharClick(e, i) {
|
|
673
|
-
|
|
674
|
-
e.
|
|
675
|
-
|
|
832
|
+
// ??????????????????? DON'T REMOVE !
|
|
833
|
+
// e.preventDefault();
|
|
834
|
+
// e.stopPropagation();
|
|
676
835
|
var _getCharByIndex2 = getCharByIndex(i),
|
|
677
836
|
char = _getCharByIndex2.char,
|
|
678
837
|
maskChar = _getCharByIndex2.maskChar;
|
|
@@ -741,7 +900,7 @@ function InputMask() {
|
|
|
741
900
|
};
|
|
742
901
|
|
|
743
902
|
var _onPaste = function onPaste(e, i) {
|
|
744
|
-
var
|
|
903
|
+
var _ref20, _window, _e$clipboardData;
|
|
745
904
|
|
|
746
905
|
var setFocusToEnd = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
747
906
|
|
|
@@ -752,17 +911,17 @@ function InputMask() {
|
|
|
752
911
|
|
|
753
912
|
setIsSelecting(false);
|
|
754
913
|
(0, _functions.resetSelectionText)();
|
|
755
|
-
var pastedText = ((
|
|
914
|
+
var pastedText = ((_ref20 = (e === null || e === void 0 ? void 0 : e.clipboardData) || ((_window = window) === null || _window === void 0 ? void 0 : _window.clipboardData)) === null || _ref20 === void 0 ? void 0 : _ref20.getData('text/plain')) || (e === null || e === void 0 ? void 0 : (_e$clipboardData = e.clipboardData) === null || _e$clipboardData === void 0 ? void 0 : _e$clipboardData.getData('Text')) || e.text;
|
|
756
915
|
if (!pastedText) return false;
|
|
757
916
|
var replacedIndexes = [];
|
|
758
917
|
|
|
759
918
|
if (maskAsPlaceholder && (e === null || e === void 0 ? void 0 : e.type) === 'paste') {
|
|
760
919
|
var fromIndex = i + parseInt(pastedText === null || pastedText === void 0 ? void 0 : pastedText.length);
|
|
761
|
-
var text = innerValue.slice().filter(function (
|
|
762
|
-
var isCharSymbol =
|
|
920
|
+
var text = innerValue.slice().filter(function (_ref21, index) {
|
|
921
|
+
var isCharSymbol = _ref21.isCharSymbol;
|
|
763
922
|
return index >= i && !isCharSymbol;
|
|
764
|
-
}).map(function (
|
|
765
|
-
var char =
|
|
923
|
+
}).map(function (_ref22, index) {
|
|
924
|
+
var char = _ref22.char;
|
|
766
925
|
return char;
|
|
767
926
|
}).join('');
|
|
768
927
|
|
|
@@ -885,13 +1044,13 @@ function InputMask() {
|
|
|
885
1044
|
(0, _functions.resetSelectionText)();
|
|
886
1045
|
|
|
887
1046
|
if (maskAsPlaceholder && ((_getClearInnerValueAs2 = getClearInnerValueAsString(selEndInd + 1)) === null || _getClearInnerValueAs2 === void 0 ? void 0 : _getClearInnerValueAs2.length) !== 0) {
|
|
888
|
-
var text = innerValue.slice().filter(function (
|
|
889
|
-
var isSpecialSymbol =
|
|
890
|
-
isCharSymbol =
|
|
1047
|
+
var text = innerValue.slice().filter(function (_ref23, index) {
|
|
1048
|
+
var isSpecialSymbol = _ref23.isSpecialSymbol,
|
|
1049
|
+
isCharSymbol = _ref23.isCharSymbol;
|
|
891
1050
|
if (maxEditableLen !== -1 && index > maxEditableLen - 1) return false;
|
|
892
1051
|
return (index < selStartInd || index >= selEndInd) && !isSpecialSymbol && !isCharSymbol;
|
|
893
|
-
}).map(function (
|
|
894
|
-
var char =
|
|
1052
|
+
}).map(function (_ref24, index) {
|
|
1053
|
+
var char = _ref24.char;
|
|
895
1054
|
return char;
|
|
896
1055
|
}).join('');
|
|
897
1056
|
resetInnerValue();
|
|
@@ -937,8 +1096,8 @@ function InputMask() {
|
|
|
937
1096
|
|
|
938
1097
|
if (value && value !== '' && value !== getClearInnerValueAsString()) {
|
|
939
1098
|
var valueCharIndex = 0;
|
|
940
|
-
innerValue.map(function (
|
|
941
|
-
var isSpecialSymbol =
|
|
1099
|
+
innerValue.map(function (_ref25, i) {
|
|
1100
|
+
var isSpecialSymbol = _ref25.isSpecialSymbol;
|
|
942
1101
|
if (isSpecialSymbol) return false;
|
|
943
1102
|
var char = value[valueCharIndex];
|
|
944
1103
|
|
|
@@ -962,9 +1121,7 @@ function InputMask() {
|
|
|
962
1121
|
++valueCharIndex;
|
|
963
1122
|
});
|
|
964
1123
|
}
|
|
965
|
-
}, [isMaskRendered,
|
|
966
|
-
/*value,*/
|
|
967
|
-
isInitValue]); // Focus Observer
|
|
1124
|
+
}, [isMaskRendered, value, isInitValue]); // Focus Observer
|
|
968
1125
|
|
|
969
1126
|
(0, _react.useEffect)(function () {
|
|
970
1127
|
if (!isFocused) {
|
|
@@ -981,8 +1138,7 @@ function InputMask() {
|
|
|
981
1138
|
(0, _react.useEffect)(function () {
|
|
982
1139
|
if (!isMaskRendered) return false;
|
|
983
1140
|
setError(false);
|
|
984
|
-
clearErrorMessage();
|
|
985
|
-
|
|
1141
|
+
clearErrorMessage();
|
|
986
1142
|
onChangeProp(getClearInnerValueAsString(), getInnerValueAsString({
|
|
987
1143
|
replaceSpace: true
|
|
988
1144
|
}));
|
|
@@ -1060,7 +1216,6 @@ function InputMask() {
|
|
|
1060
1216
|
return /*#__PURE__*/_react.default.createElement("span", {
|
|
1061
1217
|
tabIndex: i === 0 ? 0 : -1,
|
|
1062
1218
|
key: i,
|
|
1063
|
-
maxLength: 1,
|
|
1064
1219
|
"attr-char-id": i,
|
|
1065
1220
|
className: "\n input-mask_value_item\n ".concat(className, "\n ").concat((0, _functions.isDigitMaskChar)(obj.maskChar) ? 'input-mask_value_item--digit' : '', "\n ").concat((0, _functions.isLetterMaskChar)(obj.maskChar) ? 'input-mask_value_item--letter' : '', "\n ").concat(obj.isSpecialSymbol ? 'input-mask_value_item--spec' : '', "\n ") // ${char === '' || isSpecialSymbol ? 'unselectable' : ''}
|
|
1066
1221
|
// ${!isSelecting && (char === '' || isSpecialSymbol) ? 'unselectable' : ''}
|