intelicoreact 0.2.37 → 0.2.38

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.
@@ -132,23 +132,30 @@ function InputMask() {
132
132
  var _useState7 = (0, _react.useState)(false),
133
133
  _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
134
134
  isInitValue = _useState8[0],
135
- setIsInitValue = _useState8[1]; // ERRORS MANAGEMENT FUNCTIONS | START //
135
+ setIsInitValue = _useState8[1];
136
136
 
137
+ var inputThrottlingTimeout = 20;
137
138
 
138
139
  var _useState9 = (0, _react.useState)(false),
139
140
  _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
140
- isError = _useState10[0],
141
- setError = _useState10[1];
141
+ isInputThrottled = _useState10[0],
142
+ setIsInputThrottled = _useState10[1]; // ERRORS MANAGEMENT FUNCTIONS | START //
143
+
142
144
 
143
145
  var _useState11 = (0, _react.useState)(false),
144
146
  _useState12 = (0, _slicedToArray2.default)(_useState11, 2),
145
- blinkError = _useState12[0],
146
- setBlinkError = _useState12[1];
147
+ isError = _useState12[0],
148
+ setError = _useState12[1];
147
149
 
148
- var _useState13 = (0, _react.useState)(errors.default),
150
+ var _useState13 = (0, _react.useState)(false),
149
151
  _useState14 = (0, _slicedToArray2.default)(_useState13, 2),
150
- errorMessage = _useState14[0],
151
- setErrorMessage = _useState14[1];
152
+ blinkError = _useState14[0],
153
+ setBlinkError = _useState14[1];
154
+
155
+ var _useState15 = (0, _react.useState)(errors.default),
156
+ _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
157
+ errorMessage = _useState16[0],
158
+ setErrorMessage = _useState16[1];
152
159
 
153
160
  var clearErrorMessage = function clearErrorMessage() {
154
161
  return setErrorMessage(errors.default);
@@ -156,32 +163,32 @@ function InputMask() {
156
163
  // SELECTION MANAGEMENT FUNCTIONS | START //
157
164
 
158
165
 
159
- var _useState15 = (0, _react.useState)(false),
160
- _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
161
- isSelecting = _useState16[0],
162
- setIsSelecting = _useState16[1];
163
-
164
- var _useState17 = (0, _react.useState)(''),
166
+ var _useState17 = (0, _react.useState)(false),
165
167
  _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
166
- selectedText = _useState18[0],
167
- setSelectedText = _useState18[1];
168
+ isSelecting = _useState18[0],
169
+ setIsSelecting = _useState18[1];
168
170
 
169
- var _useState19 = (0, _react.useState)(null),
171
+ var _useState19 = (0, _react.useState)(''),
170
172
  _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
171
- selectionStartX = _useState20[0],
172
- setSelectionStartX = _useState20[1];
173
+ selectedText = _useState20[0],
174
+ setSelectedText = _useState20[1];
173
175
 
174
176
  var _useState21 = (0, _react.useState)(null),
175
177
  _useState22 = (0, _slicedToArray2.default)(_useState21, 2),
176
- selectionEndX = _useState22[0],
177
- setSelectionEndX = _useState22[1]; // SELECTION MANAGEMENT FUNCTIONS | END //
178
+ selectionStartX = _useState22[0],
179
+ setSelectionStartX = _useState22[1];
180
+
181
+ var _useState23 = (0, _react.useState)(null),
182
+ _useState24 = (0, _slicedToArray2.default)(_useState23, 2),
183
+ selectionEndX = _useState24[0],
184
+ setSelectionEndX = _useState24[1]; // SELECTION MANAGEMENT FUNCTIONS | END //
178
185
  // SERVICE WATCHERS MANAGEMENT FUNCTIONS | START //
179
186
 
180
187
 
181
- var _useState23 = (0, _react.useState)([]),
182
- _useState24 = (0, _slicedToArray2.default)(_useState23, 2),
183
- serviceWatchers = _useState24[0],
184
- setServiceWatchers = _useState24[1];
188
+ var _useState25 = (0, _react.useState)([]),
189
+ _useState26 = (0, _slicedToArray2.default)(_useState25, 2),
190
+ serviceWatchers = _useState26[0],
191
+ setServiceWatchers = _useState26[1];
185
192
 
186
193
  var pushServiceWatcher = function pushServiceWatcher(fn) {
187
194
  return setServiceWatchers(function (state) {
@@ -211,10 +218,25 @@ function InputMask() {
211
218
  }, [serviceWatchers]); // SERVICE WATCHERS MANAGEMENT FUNCTIONS | END //
212
219
  // INNER VALUE MANAGEMENT FUNCTIONS | START //
213
220
 
214
- var _useState25 = (0, _react.useState)([]),
215
- _useState26 = (0, _slicedToArray2.default)(_useState25, 2),
216
- innerValue = _useState26[0],
217
- setInnerValue = _useState26[1];
221
+ var _useState27 = (0, _react.useState)([]),
222
+ _useState28 = (0, _slicedToArray2.default)(_useState27, 2),
223
+ innerValue = _useState28[0],
224
+ setInnerValue = _useState28[1];
225
+
226
+ var _useState29 = (0, _react.useState)(''),
227
+ _useState30 = (0, _slicedToArray2.default)(_useState29, 2),
228
+ undoValue = _useState30[0],
229
+ setUndoValue = _useState30[1];
230
+
231
+ var _useState31 = (0, _react.useState)(null),
232
+ _useState32 = (0, _slicedToArray2.default)(_useState31, 2),
233
+ redoValue = _useState32[0],
234
+ setRedoValue = _useState32[1];
235
+
236
+ var _useState33 = (0, _react.useState)(false),
237
+ _useState34 = (0, _slicedToArray2.default)(_useState33, 2),
238
+ isUndoValueBlocked = _useState34[0],
239
+ setIsUndoValueBlocked = _useState34[1];
218
240
 
219
241
  var addInnerValueChar = function addInnerValueChar(_ref2) {
220
242
  var char = _ref2.char,
@@ -468,13 +490,23 @@ function InputMask() {
468
490
  };
469
491
 
470
492
  var onArrowRightDown = function onArrowRightDown(e, i) {
471
- var key = (e === null || e === void 0 ? void 0 : e.key) || null; // If Current Index Equals LastTyped Index in MaskAsPlaceholder Mode
493
+ var key = (e === null || e === void 0 ? void 0 : e.key) || null;
494
+
495
+ if (maskAsPlaceholder && i > getLastTypedIndex()) {
496
+ return setFocusOnChar(getLastTypedIndex() + 1, i);
497
+ } // If Current Index Equals LastTyped Index in MaskAsPlaceholder Mode
498
+
472
499
 
473
500
  if (maskAsPlaceholder && i === getLastTypedIndex() && key === 'ArrowRight') return false;
474
501
  return setFocusOnChar(i + 1, i);
475
502
  };
476
503
 
477
504
  var onBackspaceDown = function onBackspaceDown(e, i) {
505
+ if (!isUndoValueBlocked) {
506
+ setUndoValue(getClearInnerValueAsString());
507
+ setIsUndoValueBlocked(true);
508
+ }
509
+
478
510
  if ((0, _functions.getSelectionText)().length) return deleteSelectedText();
479
511
  var prevIndex = i - 1;
480
512
  var charObj = getCharByIndex(prevIndex);
@@ -486,8 +518,7 @@ function InputMask() {
486
518
  var newText = innerValue.slice(0, prevIndex).concat(innerValue.slice(i, maxEditableLen !== -1 ? maxEditableLen : innerValue.length)).reduce(function (text, _ref12) {
487
519
  var char = _ref12.char;
488
520
  return text.concat(char);
489
- }, ''); // const newText = getInnerValueAsString().substring(0, prevIndex) + getInnerValueAsString().substring(i, maxEditableLen !== -1 ? maxEditableLen : getInnerValueAsString().length);
490
-
521
+ }, '');
491
522
  resetInnerValue();
492
523
 
493
524
  _onPaste({
@@ -504,6 +535,11 @@ function InputMask() {
504
535
  };
505
536
 
506
537
  var onDeleteDown = function onDeleteDown(e, i) {
538
+ if (!isUndoValueBlocked) {
539
+ setUndoValue(getClearInnerValueAsString());
540
+ setIsUndoValueBlocked(true);
541
+ }
542
+
507
543
  if ((0, _functions.getSelectionText)().length) return deleteSelectedText();
508
544
  var nextIndex = i + 1;
509
545
  var charObj = getCharByIndex(i);
@@ -517,8 +553,7 @@ function InputMask() {
517
553
  var newText = innerValue.slice(0, i).concat(innerValue.slice(nextIndex, maxEditableLen !== -1 ? maxEditableLen : innerValue.length)).reduce(function (text, _ref13) {
518
554
  var char = _ref13.char;
519
555
  return text.concat(char);
520
- }, ''); // const newText = getInnerValueAsString().substring(0, i) + getInnerValueAsString().substring(nextIndex, maxEditableLen !== -1 ? maxEditableLen : getInnerValueAsString().length);
521
-
556
+ }, '');
522
557
  resetInnerValue();
523
558
 
524
559
  _onPaste({
@@ -589,6 +624,8 @@ function InputMask() {
589
624
  var _ref15,
590
625
  _ref15$disableErrors,
591
626
  disableErrors,
627
+ _ref15$disableIsSelec,
628
+ disableIsSelectingCheck,
592
629
  key,
593
630
  keyCode,
594
631
  charObj,
@@ -604,24 +641,50 @@ function InputMask() {
604
641
  while (1) {
605
642
  switch (_context.prev = _context.next) {
606
643
  case 0:
607
- _ref15 = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}, _ref15$disableErrors = _ref15.disableErrors, disableErrors = _ref15$disableErrors === void 0 ? false : _ref15$disableErrors;
644
+ _ref15 = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}, _ref15$disableErrors = _ref15.disableErrors, disableErrors = _ref15$disableErrors === void 0 ? false : _ref15$disableErrors, _ref15$disableIsSelec = _ref15.disableIsSelectingCheck, disableIsSelectingCheck = _ref15$disableIsSelec === void 0 ? false : _ref15$disableIsSelec;
645
+
646
+ if (!(isSelecting && !disableIsSelectingCheck)) {
647
+ _context.next = 7;
648
+ break;
649
+ }
608
650
 
651
+ deleteSelectedText();
652
+ (0, _functions.resetSelectionText)();
653
+ setIsSelecting(false);
654
+ setTimeout(function () {
655
+ return handleKeyDown(e, getSelectStartIndex(), {
656
+ disableErrors: disableErrors,
657
+ disableIsSelectingCheck: true
658
+ });
659
+ }, 10);
660
+ return _context.abrupt("return", null);
661
+
662
+ case 7:
609
663
  try {
610
664
  e.stopPropagation();
611
665
  e.preventDefault();
612
666
  } catch (e) {}
613
667
 
668
+ if (!isInputThrottled) {
669
+ _context.next = 10;
670
+ break;
671
+ }
672
+
673
+ return _context.abrupt("return", false);
674
+
675
+ case 10:
676
+ setIsInputThrottled(true);
614
677
  key = e.key, keyCode = e.keyCode;
615
678
  charObj = getCharByIndex(i); // Android Text Typing FIX
616
679
  // eslint-disable-next-line eqeqeq
617
680
 
618
681
  if (!(keyCode == _config.ANDROID_CHROME_TEXT_CODE)) {
619
- _context.next = 9;
682
+ _context.next = 18;
620
683
  break;
621
684
  }
622
685
 
623
686
  charRef = charObj.ref;
624
- _context.next = 8;
687
+ _context.next = 17;
625
688
  return new Promise(function (resolve) {
626
689
  setTimeout(function () {
627
690
  var _charRef$current, _charRef$current$inne;
@@ -643,74 +706,74 @@ function InputMask() {
643
706
  }, 1);
644
707
  });
645
708
 
646
- case 8:
709
+ case 17:
647
710
  key = _context.sent;
648
711
 
649
- case 9:
712
+ case 18:
650
713
  if (!(!charObj || i === innerValue.length - 1)) {
651
- _context.next = 11;
714
+ _context.next = 20;
652
715
  break;
653
716
  }
654
717
 
655
718
  return _context.abrupt("return", false);
656
719
 
657
- case 11:
720
+ case 20:
658
721
  if (!(maskAsPlaceholder && i > getLastTypedIndex() + 1)) {
659
- _context.next = 15;
722
+ _context.next = 24;
660
723
  break;
661
724
  }
662
725
 
663
- _context.next = 14;
726
+ _context.next = 23;
664
727
  return handleKeyDown(e, getLastTypedIndex() === 0 ? 0 : getLastTypedIndex() + 1, {
665
728
  disableErrors: disableErrors
666
729
  });
667
730
 
668
- case 14:
731
+ case 23:
669
732
  return _context.abrupt("return", _context.sent);
670
733
 
671
- case 15:
734
+ case 24:
672
735
  isSpecialSymbol = charObj.isSpecialSymbol, maskChar = charObj.maskChar, isReadOnly = charObj.isReadOnly;
673
736
 
674
737
  if (!isReadOnly) {
675
- _context.next = 18;
738
+ _context.next = 27;
676
739
  break;
677
740
  }
678
741
 
679
742
  return _context.abrupt("return", false);
680
743
 
681
- case 18:
744
+ case 27:
682
745
  if (!(maskChar === _config.SPACE_CHAR)) {
683
- _context.next = 22;
746
+ _context.next = 31;
684
747
  break;
685
748
  }
686
749
 
687
- _context.next = 21;
750
+ _context.next = 30;
688
751
  return handleKeyDown(e, i + 1);
689
752
 
690
- case 21:
753
+ case 30:
691
754
  return _context.abrupt("return", _context.sent);
692
755
 
693
- case 22:
756
+ case 31:
694
757
  if (!(isSpecialSymbol && maskChar !== key)) {
695
- _context.next = 24;
758
+ _context.next = 33;
696
759
  break;
697
760
  }
698
761
 
699
762
  return _context.abrupt("return", false);
700
763
 
701
- case 24:
764
+ case 33:
702
765
  if (isValidChar({
703
766
  char: key,
704
767
  i: i,
705
768
  disableErrors: disableErrors
706
769
  })) {
707
- _context.next = 26;
770
+ _context.next = 35;
708
771
  break;
709
772
  }
710
773
 
711
774
  return _context.abrupt("return", false);
712
775
 
713
- case 26:
776
+ case 35:
714
777
  if (maskAsPlaceholder && ((_getClearInnerValueAs = getClearInnerValueAsString(i)) === null || _getClearInnerValueAs === void 0 ? void 0 : _getClearInnerValueAs.length) !== 0) {
715
778
  fromIndex = i + 1;
716
779
  text = innerValue.slice().filter(function (_ref16, index) {
@@ -726,13 +789,16 @@ function InputMask() {
726
789
  }, fromIndex, false);
727
790
  }
728
791
 
792
+ setIsUndoValueBlocked(false);
729
793
  updateInnerValueChar({
730
794
  char: key
731
795
  }, i);
732
- onArrowRightDown(e, i);
796
+ setTimeout(function () {
797
+ return onArrowRightDown(e, i);
798
+ }, 1);
733
799
  return _context.abrupt("return", true);
734
800
 
735
- case 30:
801
+ case 40:
736
802
  case "end":
737
803
  return _context.stop();
738
804
  }
@@ -753,6 +819,29 @@ function InputMask() {
753
819
  //Ctrl + A
754
820
  case 65:
755
821
  selectAllText(e);
822
+ break;
823
+ //Ctrl + Y
824
+
825
+ case 89:
826
+ if (redoValue) {
827
+ resetInnerValue();
828
+
829
+ _onPaste({
830
+ text: redoValue
831
+ }, 0, true);
832
+ }
833
+
834
+ break;
835
+ //Ctrl + Z
836
+
837
+ case 90:
838
+ setRedoValue(getClearInnerValueAsString());
839
+ resetInnerValue();
840
+
841
+ _onPaste({
842
+ text: undoValue
843
+ }, 0, true);
844
+
756
845
  break;
757
846
  }
758
847
  };
@@ -765,6 +854,7 @@ function InputMask() {
765
854
  key,
766
855
  ctrlKey,
767
856
  altKey,
857
+ target,
768
858
  handleResult,
769
859
  _args2 = arguments;
770
860
  return _regenerator.default.wrap(function _callee2$(_context2) {
@@ -773,7 +863,7 @@ function InputMask() {
773
863
  case 0:
774
864
  i = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : null;
775
865
 
776
- if (isFocused) {
866
+ if (!(!isFocused && !isSelecting)) {
777
867
  _context2.next = 3;
778
868
  break;
779
869
  }
@@ -782,8 +872,10 @@ function InputMask() {
782
872
 
783
873
  case 3:
784
874
  key = e.key, ctrlKey = e.ctrlKey, altKey = e.altKey;
785
- e.target = ((_innerValue$0$ref = innerValue[0].ref) === null || _innerValue$0$ref === void 0 ? void 0 : _innerValue$0$ref.current) || e.target;
786
- onKeyDownProp(e, i);
875
+ target = ((_innerValue$0$ref = innerValue[0].ref) === null || _innerValue$0$ref === void 0 ? void 0 : _innerValue$0$ref.current) || e.target;
876
+ onKeyDownProp(_objectSpread(_objectSpread({}, e), {}, {
877
+ target: target
878
+ }), i);
787
879
 
788
880
  if (!(_indexConstants.KEYBOARD_SERVICE_KEYS.includes(key) && _config.EXCLUDED_KEYS.includes(key))) {
789
881
  _context2.next = 8;
@@ -856,10 +948,16 @@ function InputMask() {
856
948
 
857
949
  if (isSelecting && (selectedText.length || (0, _functions.getSelectionText)().length) && !ignoreIsSelecting) return false;
858
950
  setFocused(true);
951
+ if (e.detail === 2) selectAllText(e);
859
952
  if (typeof cb === 'function') cb(e);
860
953
  };
861
954
 
862
955
  var onCharClick = function onCharClick(e, i) {
956
+ if (e.detail == 2) {
957
+ selectAllText(e);
958
+ return true;
959
+ }
960
+
863
961
  var _getCharByIndex2 = getCharByIndex(i),
864
962
  char = _getCharByIndex2.char,
865
963
  maskChar = _getCharByIndex2.maskChar;
@@ -1023,11 +1121,14 @@ function InputMask() {
1023
1121
  } catch (error) {}
1024
1122
 
1025
1123
  (0, _functions.copyToClipboard)((0, _functions.getSelectionText)());
1026
- setIsSelecting(false);
1027
- setFocusOnChar(i, 0);
1028
1124
  };
1029
1125
 
1030
1126
  var _onCut = function onCut(e, i) {
1127
+ if (!isUndoValueBlocked) {
1128
+ setUndoValue(getClearInnerValueAsString());
1129
+ setIsUndoValueBlocked(true);
1130
+ }
1131
+
1031
1132
  try {
1032
1133
  e.stopPropagation();
1033
1134
  e.preventDefault();
@@ -1067,7 +1168,7 @@ function InputMask() {
1067
1168
  var _getClearInnerValueAs2;
1068
1169
 
1069
1170
  var selStartInd = getSelectStartIndex();
1070
- if (selStartInd === null || selStartInd === undefined || selStartInd < 0) return false;
1171
+ if (selStartInd === null || selStartInd === undefined) return false;
1071
1172
  var selEndInd = (0, _functions.getSelectionText)().length + selStartInd;
1072
1173
  (0, _functions.resetSelectionText)();
1073
1174
 
@@ -1100,9 +1201,15 @@ function InputMask() {
1100
1201
  return true;
1101
1202
  }; // FUNCTIONS | END //
1102
1203
  ///--- OBSERVERS ---///
1103
- //Render Mask
1204
+ // Input Throttling
1104
1205
 
1105
1206
 
1207
+ (0, _react.useEffect)(function () {
1208
+ if (isInputThrottled) setTimeout(function () {
1209
+ return setIsInputThrottled(false);
1210
+ }, inputThrottlingTimeout);
1211
+ }, [isInputThrottled]); //Render Mask
1212
+
1106
1213
  (0, _react.useEffect)(function () {
1107
1214
  setInnerValue([]);
1108
1215
  setMaskRendered(false);
@@ -1161,7 +1268,11 @@ function InputMask() {
1161
1268
  }
1162
1269
 
1163
1270
  setIsInitValue(true);
1164
- }, [isMaskRendered, value, isInitValue]); // Focus Observer
1271
+ }, [isMaskRendered, value, isInitValue]);
1272
+ (0, _react.useEffect)(function () {
1273
+ if (!isInitValue) return false;
1274
+ setUndoValue(getClearInnerValueAsString());
1275
+ }, [isInitValue]); // Focus Observer
1165
1276
 
1166
1277
  (0, _react.useEffect)(function () {
1167
1278
  if (!isFocused) {
@@ -1203,9 +1314,7 @@ function InputMask() {
1203
1314
  if (!isMouseDown && isSelecting) {
1204
1315
  document.addEventListener('keydown', function (e) {
1205
1316
  return pushServiceWatcher(function () {
1206
- _onKeyDown(e);
1207
-
1208
- setIsSelecting(false);
1317
+ return _onKeyDown(e);
1209
1318
  });
1210
1319
  }, {
1211
1320
  once: true
@@ -1217,23 +1326,7 @@ function InputMask() {
1217
1326
  (0, _react.useEffect)(function () {
1218
1327
  document.addEventListener('mouseup', function () {
1219
1328
  setIsMouseDown(function (isMouseDown) {
1220
- document.addEventListener('keydown', function (e) {
1221
- return pushServiceWatcher(function () {
1222
- return _onKeyDown(e);
1223
- });
1224
- }, {
1225
- once: true
1226
- });
1227
-
1228
- if (isMouseDown) {
1229
- setSelectedText((0, _functions.getSelectionText)());
1230
- document.addEventListener('click', function () {
1231
- setIsSelecting(false);
1232
- }, {
1233
- once: true
1234
- });
1235
- }
1236
-
1329
+ if (isMouseDown) setSelectedText((0, _functions.getSelectionText)());
1237
1330
  return false;
1238
1331
  });
1239
1332
  });
@@ -1271,7 +1364,7 @@ function InputMask() {
1271
1364
  onKeyDown: function onKeyDown(e) {
1272
1365
  return _onKeyDown(e, i);
1273
1366
  },
1274
- onChange: function onChange() {},
1367
+ onChange: cancelDefaultAction,
1275
1368
  contentEditable: !isSelecting,
1276
1369
  inputMode: (0, _functions.isDigitMaskChar)(i !== innerValue.length - 1 ? maskChar : prevChar === null || prevChar === void 0 ? void 0 : prevChar.maskChar) ? 'numeric' : 'text',
1277
1370
  suppressContentEditableWarning: true,
@@ -1286,6 +1379,8 @@ function InputMask() {
1286
1379
  },
1287
1380
  ref: ref,
1288
1381
  onDoubleClick: function onDoubleClick(e) {
1382
+ e.stopPropagation();
1383
+ e.preventDefault();
1289
1384
  setIsSelecting(true);
1290
1385
  setTimeout(function () {
1291
1386
  return selectAllText(e, i);
@@ -1345,8 +1440,8 @@ function InputMask() {
1345
1440
  },
1346
1441
  onMouseMove: function onMouseMove(e) {
1347
1442
  return cancelDefaultAction(e, onMouseDownMove);
1348
- },
1349
- onMouseUp: cancelDefaultAction,
1443
+ } // onMouseUp={cancelDefaultAction}
1444
+ ,
1350
1445
  onClick: onWrapperClick,
1351
1446
  onBlur: onBlur
1352
1447
  }, showHint && isHintLeft && /*#__PURE__*/_react.default.createElement("div", {
@@ -38,11 +38,10 @@ var copyToClipboard = function copyToClipboard(str) {
38
38
  exports.copyToClipboard = copyToClipboard;
39
39
 
40
40
  var selectElementContents = function selectElementContents(el) {
41
- var range = document.createRange();
42
- range.selectNodeContents(el);
41
+ var startOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
42
+ var endOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
43
43
  var sel = window.getSelection();
44
- sel.removeAllRanges();
45
- sel.addRange(range);
44
+ sel.selectAllChildren(el);
46
45
  };
47
46
 
48
47
  exports.selectElementContents = selectElementContents;
@@ -25,12 +25,12 @@ var _helpers = require("chart.js/helpers");
25
25
 
26
26
  var ChartComponents = _interopRequireWildcard(require("react-chartjs-2"));
27
27
 
28
- var _optionsConstructor = require("./partial/optionsConstructor");
29
-
30
28
  var _utils = require("./partial/utils");
31
29
 
32
30
  var _Chart = require("./partial/Chart.constants");
33
31
 
32
+ var _utils2 = require("../../../Functions/utils");
33
+
34
34
  var _ChartTypeSwitcherIcon = _interopRequireDefault(require("./partial/ChartTypeSwitcherIcon/ChartTypeSwitcherIcon"));
35
35
 
36
36
  require("./Chart.scss");
@@ -53,15 +53,11 @@ var Chart = function Chart(_ref) {
53
53
  data = _ref.data;
54
54
  if (!data) return null;
55
55
 
56
- var correctModelKey = function correctModelKey(key) {
57
- return key && _Chart.CHART_TYPES.includes((0, _utils.getChartTypeKey)(key)) ? key : _Chart.DEFAULT_CHART_MODEL;
58
- };
59
-
60
56
  var _ref2 = description || {},
61
57
  label = _ref2.label,
62
58
  value = _ref2.value;
63
59
 
64
- var _useState = (0, _react.useState)(correctModelKey(initialModel)),
60
+ var _useState = (0, _react.useState)(_Chart.DEFAULT_CHART_MODEL),
65
61
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
66
62
  model = _useState2[0],
67
63
  setModel = _useState2[1];
@@ -72,46 +68,46 @@ var Chart = function Chart(_ref) {
72
68
  setLocalData = _useState4[1];
73
69
 
74
70
  var chartRef = (0, _react.useRef)(null);
75
-
76
- var isExcludeDescription = _optionsConstructor.componentOptions.disableDescriptionsFor.includes(model);
77
-
78
- var isExcludeChartTypeSwitcher = _optionsConstructor.componentOptions.disableChartTypeSwitcherFor.includes(model);
79
-
80
- var getChartOptions = function getChartOptions(currentModel) {
81
- return customOptions || (0, _utils.getOptions)(currentModel);
82
- };
83
-
71
+ var charContainertRef = (0, _react.useRef)(null);
72
+ var options = (0, _react.useMemo)(function () {
73
+ return customOptions || (0, _utils.getOptions)(model);
74
+ }, [customOptions, model]);
75
+ var notLibraryOptionsOptions = (0, _react.useMemo)(function () {
76
+ return customOptions ? customOptions === null || customOptions === void 0 ? void 0 : customOptions.notLibraryOptions : (0, _utils.getNotLibraryOptionsOptions)(model);
77
+ }, [customOptions, model]);
84
78
  var ChartComponent = (0, _react.useCallback)(function (props) {
85
79
  var Component = ChartComponents[(0, _utils.getChartTypeKey)(model)];
86
80
  return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({
87
81
  ref: chartRef
88
82
  }, props));
89
83
  }, [model]);
84
+
85
+ var isExcludeDescription = _Chart.COMPONENT_OPTIONS.disableDescriptionsFor.includes(model);
86
+
87
+ var isExcludeChartTypeSwitcher = _Chart.COMPONENT_OPTIONS.disableChartTypeSwitcherFor.includes(model);
88
+
90
89
  (0, _react.useLayoutEffect)(function () {
91
- setModel(correctModelKey(initialModel));
92
- }, [initialModel]);
93
- (0, _react.useLayoutEffect)(function () {
94
- if (setModelExternalValue) setModelExternalValue(correctModelKey(model));
90
+ if (setModelExternalValue && model !== 'emptyLayout') setModelExternalValue(model);
95
91
  }, [model]);
96
- (0, _react.useEffect)(function () {
97
- var _getChartOptions = getChartOptions(model),
98
- _getChartOptions$notL = _getChartOptions.notLibraryOptions;
99
-
100
- _getChartOptions$notL = _getChartOptions$notL === void 0 ? {} : _getChartOptions$notL;
101
- var setCanvasDimensions = _getChartOptions$notL.setCanvasDimensions;
92
+ (0, _react.useLayoutEffect)(function () {
93
+ var _ref3 = notLibraryOptionsOptions || {},
94
+ setCanvasDimensions = _ref3.setCanvasDimensions;
102
95
 
103
- if (chartRef.current) {
96
+ if (charContainertRef.current) {
104
97
  var _setCanvasDimensions$, _setCanvasDimensions$2;
105
98
 
106
- chartRef.current.canvas.parentNode.style.width = (_setCanvasDimensions$ = setCanvasDimensions === null || setCanvasDimensions === void 0 ? void 0 : setCanvasDimensions.width) !== null && _setCanvasDimensions$ !== void 0 ? _setCanvasDimensions$ : '';
107
- chartRef.current.canvas.parentNode.style.height = (_setCanvasDimensions$2 = setCanvasDimensions === null || setCanvasDimensions === void 0 ? void 0 : setCanvasDimensions.height) !== null && _setCanvasDimensions$2 !== void 0 ? _setCanvasDimensions$2 : '';
99
+ charContainertRef.current.style.width = (_setCanvasDimensions$ = setCanvasDimensions === null || setCanvasDimensions === void 0 ? void 0 : setCanvasDimensions.width) !== null && _setCanvasDimensions$ !== void 0 ? _setCanvasDimensions$ : '';
100
+ charContainertRef.current.style.height = (_setCanvasDimensions$2 = setCanvasDimensions === null || setCanvasDimensions === void 0 ? void 0 : setCanvasDimensions.height) !== null && _setCanvasDimensions$2 !== void 0 ? _setCanvasDimensions$2 : '';
108
101
  }
109
- }, [model]);
102
+ }, [notLibraryOptionsOptions]);
103
+ (0, _react.useEffect)(function () {
104
+ return setModel((0, _utils.correctModelKey)(initialModel));
105
+ }, [initialModel]);
110
106
  (0, _react.useEffect)(function () {
111
- return setLocalData((0, _utils.prepareData)(model, data, chartRef.current));
112
- }, [model, data, chartRef]);
107
+ return setLocalData((0, _utils.prepareData)(model, (0, _utils2.clone)(data), chartRef.current));
108
+ }, [model, data]);
113
109
  return /*#__PURE__*/_react.default.createElement("div", {
114
- className: (0, _classnames.default)(RC, (0, _defineProperty2.default)({}, "".concat(RC, "_icon-mode"), _optionsConstructor.iconModels.includes(model)), className)
110
+ className: (0, _classnames.default)(RC, (0, _defineProperty2.default)({}, "".concat(RC, "_icon-mode"), _Chart.ICON_MODELS.includes(model)), className)
115
111
  }, /*#__PURE__*/_react.default.createElement("div", {
116
112
  className: (0, _classnames.default)("".concat(RC, "__header"), (0, _defineProperty2.default)({}, "".concat(RC, "__header_only-switcher"), !description))
117
113
  }, description && !isExcludeDescription ? /*#__PURE__*/_react.default.createElement("div", {
@@ -135,8 +131,9 @@ var Chart = function Chart(_ref) {
135
131
  return setModel((modelsForSwitch === null || modelsForSwitch === void 0 ? void 0 : modelsForSwitch[1]) || 'lineLayout');
136
132
  }
137
133
  })) : null), /*#__PURE__*/_react.default.createElement("div", {
134
+ ref: charContainertRef,
138
135
  className: (0, _classnames.default)("".concat(RC, "__chart-wrapper"))
139
- }, /*#__PURE__*/_react.default.createElement(ChartComponent, (0, _extends2.default)({}, getChartOptions(model), {
136
+ }, /*#__PURE__*/_react.default.createElement(ChartComponent, (0, _extends2.default)({}, options, {
140
137
  data: localData
141
138
  }))));
142
139
  };