@majoo-ui/react 2.0.1 → 2.1.0-rc.1

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 (202) hide show
  1. package/charts.esm.js +3 -1453
  2. package/colors/Colors.esm.js +93 -0
  3. package/components/accordion/Accordion.esm.js +109 -0
  4. package/components/alertDialog/AlertDialog.esm.js +440 -0
  5. package/components/avatar/Avatar.esm.js +83 -0
  6. package/components/badge/Badge.esm.js +255 -0
  7. package/components/banner/Banner.esm.js +341 -0
  8. package/components/barChart/BarChart.esm.js +212 -0
  9. package/components/breadcrumb/Breadcrumb.esm.js +65 -0
  10. package/components/breadcrumb/index.esm.js +19 -0
  11. package/components/button/Button.esm.js +331 -0
  12. package/components/buttonGroup/ButtonGroup.esm.js +350 -0
  13. package/components/card/Card.esm.js +236 -0
  14. package/components/chart/assets/data_kosong.png.esm.js +3 -0
  15. package/components/chart/lineChart/LineChart.esm.js +358 -0
  16. package/components/chart/lineChart/components/Comparator.esm.js +82 -0
  17. package/components/chart/lineChart/components/ComparatorController.esm.js +112 -0
  18. package/components/chart/lineChart/components/ComparatorItem.esm.js +104 -0
  19. package/components/chart/lineChart/components/ProductList.esm.js +78 -0
  20. package/components/chart/lineChart/components/TitleLegend.esm.js +107 -0
  21. package/components/chart/lineChart/components/Tooltip.esm.js +90 -0
  22. package/components/chart/utils/index.esm.js +109 -0
  23. package/components/checkboxTable/CheckboxTable.esm.js +287 -0
  24. package/components/colorPicker/ColorPicker.esm.js +342 -0
  25. package/components/colorPicker/InputColorPicker.esm.js +120 -0
  26. package/components/colorPicker/assets/img_colormap.gif.esm.js +3 -0
  27. package/components/colorPicker/components/ColorFields.esm.js +144 -0
  28. package/components/colorPicker/components/ColorMap.esm.js +1188 -0
  29. package/components/contentEditor/ContentEditor.esm.js +251 -0
  30. package/components/contentEditor/assets/Inline-code-outline.svg.esm.js +3 -0
  31. package/components/contentEditor/assets/Link-outline.svg.esm.js +3 -0
  32. package/components/contentEditor/assets/List-bulleted-outline.svg.esm.js +3 -0
  33. package/components/contentEditor/assets/List-numbered-outline.svg.esm.js +3 -0
  34. package/components/contentEditor/assets/Redo-outline.svg.esm.js +3 -0
  35. package/components/contentEditor/assets/Text-bold-filled.svg.esm.js +3 -0
  36. package/components/contentEditor/assets/Text-clear-format-outline.svg.esm.js +3 -0
  37. package/components/contentEditor/assets/Text-italic-outline.svg.esm.js +3 -0
  38. package/components/contentEditor/assets/Text-strikethrough-outline.svg.esm.js +3 -0
  39. package/components/contentEditor/assets/Text-underline-outline.svg.esm.js +3 -0
  40. package/components/contentEditor/assets/Undo-outline.svg.esm.js +3 -0
  41. package/components/contextMenu/ContextMenu.esm.js +298 -0
  42. package/components/datePicker/AdvancedOption.esm.js +37 -0
  43. package/components/datePicker/CustomDatePicker.esm.js +121 -0
  44. package/components/datePicker/DatePicker.esm.js +244 -0
  45. package/components/datePicker/DatePickerMulti.esm.js +70 -0
  46. package/components/datePicker/InputDatePicker.esm.js +290 -0
  47. package/components/datePicker/InputDateRangePicker.esm.js +174 -0
  48. package/components/datePicker/components/Calendar.esm.js +654 -0
  49. package/components/datePicker/components/CalendarMulti.esm.js +407 -0
  50. package/components/datePicker/components/CalendarTimePicker.esm.js +104 -0
  51. package/components/datePicker/components/DateNumber.esm.js +89 -0
  52. package/components/datePicker/components/MobileCalendar.esm.js +522 -0
  53. package/components/datePicker/state/reducer.esm.js +286 -0
  54. package/components/datePicker/timePicker/InputTimePicker.esm.js +205 -0
  55. package/components/datePicker/timePicker/TimePicker.esm.js +481 -0
  56. package/components/devicePreview/DevicePreview.esm.js +631 -0
  57. package/components/devicePreview/deviceFrame/android-transparant.png.esm.js +3 -0
  58. package/components/devicePreview/deviceFrame/android-wide-transparant.png.esm.js +3 -0
  59. package/components/devicePreview/deviceFrame/bg-email.png.esm.js +3 -0
  60. package/components/devicePreview/deviceFrame/bg-notification.png.esm.js +3 -0
  61. package/components/devicePreview/deviceFrame/bg-sms.png.esm.js +3 -0
  62. package/components/devicePreview/deviceFrame/bg-whatsapp.png.esm.js +3 -0
  63. package/components/devicePreview/deviceFrame/desktop-transparant.png.esm.js +3 -0
  64. package/components/devicePreview/deviceFrame/ic-majoo-profpic.png.esm.js +3 -0
  65. package/components/devicePreview/deviceFrame/iphone-transparant.png.esm.js +3 -0
  66. package/components/dialog/Dialog.esm.js +106 -0
  67. package/components/drawer/Drawer.esm.js +294 -0
  68. package/components/dropdownMenu/DropdownMenu.esm.js +281 -0
  69. package/components/editableTable/EditableMobile.esm.js +361 -0
  70. package/components/editableTable/EditableTable.esm.js +618 -0
  71. package/components/editableTable/transition.esm.js +37 -0
  72. package/components/form/components/FormGroup/FormGroup.esm.js +142 -0
  73. package/components/form/components/FormHelper/Helper.esm.js +50 -0
  74. package/components/form/components/FormLabel/Label.esm.js +90 -0
  75. package/components/form/components/InputAddon/InputAddon.esm.js +105 -0
  76. package/components/form/components/InputCheckbox/CheckboxGroup.esm.js +60 -0
  77. package/components/form/components/InputCheckbox/InputCheckbox.esm.js +129 -0
  78. package/components/form/components/InputCheckbox/icon/CheckOutline.esm.js +33 -0
  79. package/components/form/components/InputCheckbox/icon/MinusOutline.esm.js +33 -0
  80. package/components/form/components/InputCombobox/InputCombobox.esm.js +169 -0
  81. package/components/form/components/InputCounter/InputCounter.esm.js +226 -0
  82. package/components/form/components/InputCreatable/InputCreatable.esm.js +229 -0
  83. package/components/form/components/InputDateRange/InputDateRange.esm.js +46 -0
  84. package/components/form/components/InputElement/InputElement.esm.js +35 -0
  85. package/components/form/components/InputGroup/InputGroup.esm.js +188 -0
  86. package/components/form/components/InputLetter/InputLetter.esm.js +68 -0
  87. package/components/form/components/InputNumber/InputNumber.esm.js +248 -0
  88. package/components/form/components/InputNumber/NumberFormat.esm.js +1263 -0
  89. package/components/form/components/InputOTP/InputOTP.esm.js +70 -0
  90. package/components/form/components/InputRadio/InputRadio.esm.js +273 -0
  91. package/components/form/components/InputRadio/InputRadioGroup.esm.js +35 -0
  92. package/components/form/components/InputRadio/context.esm.js +5 -0
  93. package/components/form/components/InputResourceList/InputResourceList.esm.js +429 -0
  94. package/components/form/components/InputSearchbox/CloseFilled.esm.js +34 -0
  95. package/components/form/components/InputSearchbox/InputSearchbox.esm.js +90 -0
  96. package/components/form/components/InputSearchbox/SearchOutline.esm.js +26 -0
  97. package/components/form/components/InputSelect/InputSelect.esm.js +964 -0
  98. package/components/form/components/InputSelectCheck/InputSelectCheck.esm.js +1388 -0
  99. package/components/form/components/InputSelectCheck/OptionGroupItem.esm.js +39 -0
  100. package/components/form/components/InputSelectCheck/icon/CheckOutline.esm.js +33 -0
  101. package/components/form/components/InputSelectTag/InputSelectTag.esm.js +62 -0
  102. package/components/form/components/InputSignature/InputSignature.esm.js +122 -0
  103. package/components/form/components/InputSignature/SignatureModal.esm.js +67 -0
  104. package/components/form/components/InputSwitch/InputSwitch.esm.js +96 -0
  105. package/components/form/components/InputSwitch/InputSwitchWithImage.esm.js +136 -0
  106. package/components/form/components/InputTags/InputTags.esm.js +268 -0
  107. package/components/form/components/InputText/InputText.esm.js +197 -0
  108. package/components/form/components/InputTextArea/InputTextArea.esm.js +77 -0
  109. package/components/heading/Heading.esm.js +64 -0
  110. package/components/iconButton/IconButton.esm.js +71 -0
  111. package/components/image/Image.esm.js +141 -0
  112. package/components/link/Link.esm.js +59 -0
  113. package/components/loadingBar/LoadingBar.esm.js +113 -0
  114. package/components/mapPicker/InputMapPicker.esm.js +160 -0
  115. package/components/mapPicker/MapPicker.esm.js +122 -0
  116. package/components/mapPicker/MapPicker.styles.esm.js +70 -0
  117. package/components/mapPicker/assets/images/Mapsicle.png.esm.js +3 -0
  118. package/components/mapPicker/components/AddressCard.esm.js +25 -0
  119. package/components/mapPicker/components/ButtonSelect.esm.js +46 -0
  120. package/components/mapPicker/components/ChangeView.esm.js +20 -0
  121. package/components/mapPicker/components/InputSearch.esm.js +74 -0
  122. package/components/mapPicker/components/MarkerIcon.esm.js +22 -0
  123. package/components/mapPicker/components/MarkerSvg.esm.js +62 -0
  124. package/components/mapPicker/components/ZoomControls.esm.js +36 -0
  125. package/components/mapPicker/hooks/useMapSearch.esm.js +161 -0
  126. package/components/modalDialog/ModalDialog.esm.js +247 -0
  127. package/components/notificationBadge/NotificationBadge.esm.js +149 -0
  128. package/components/pageDialog/PageDialog.esm.js +291 -0
  129. package/components/pageDialog/logo.svg.esm.js +3 -0
  130. package/components/pagination/Pagination.esm.js +94 -0
  131. package/components/pagination/PaginationButton.esm.js +346 -0
  132. package/components/pagination/PaginationInfo.esm.js +146 -0
  133. package/components/paper/Paper.esm.js +76 -0
  134. package/components/paragraph/Paragraph.esm.js +52 -0
  135. package/components/pieChart/PieChart.esm.js +287 -0
  136. package/components/popover/Popover.esm.js +142 -0
  137. package/components/progress/Progress.esm.js +170 -0
  138. package/components/progressIndicator/ProgressIndicator.esm.js +287 -0
  139. package/components/scrollSync/ScrollSync.esm.js +172 -0
  140. package/components/scrollSync/ScrollSyncNode.esm.js +87 -0
  141. package/components/scrollSync/utils.esm.js +9 -0
  142. package/components/separator/Separator.esm.js +43 -0
  143. package/components/skeleton/Skeleton.esm.js +131 -0
  144. package/components/slider/Slider.esm.js +345 -0
  145. package/components/stepWizard/StepWizard.esm.js +451 -0
  146. package/components/stepWizard/index.esm.js +14 -0
  147. package/components/table/MobileTable.esm.js +415 -0
  148. package/components/table/Table.esm.js +1472 -0
  149. package/components/table/components/columns/DateColumn.esm.js +26 -0
  150. package/components/table/components/columns/DecimalColumn.esm.js +36 -0
  151. package/components/table/components/columns/PriceColumn.esm.js +57 -0
  152. package/components/table/components/columns/RowDraggableColumn.esm.js +24 -0
  153. package/components/table/components/columns/RowExpanderColumn.esm.js +32 -0
  154. package/components/table/components/columns/RowExpanderMultipleColumn.esm.js +24 -0
  155. package/components/table/components/columns/RowMenuColumn.esm.js +101 -0
  156. package/components/table/components/columns/RowSelectionCallbackColumn.esm.js +38 -0
  157. package/components/table/components/columns/RowSelectionColumn.esm.js +34 -0
  158. package/components/table/images/img-emptydata.webp.esm.js +3 -0
  159. package/components/table/images/img-emptysearchdata.webp.esm.js +3 -0
  160. package/components/tableOfContent/TableOfContent.esm.js +267 -0
  161. package/components/tableOfContent/index.esm.js +18 -0
  162. package/components/tableOfContent/transition.esm.js +38 -0
  163. package/components/tabs/Tabs.esm.js +282 -0
  164. package/components/tag/Tag.esm.js +161 -0
  165. package/components/tagList/TagList.esm.js +90 -0
  166. package/components/tagStatus/TagStatus.esm.js +134 -0
  167. package/components/text/Text.esm.js +140 -0
  168. package/components/toast/Toast.esm.js +297 -0
  169. package/components/toast/ToastContainer.esm.js +73 -0
  170. package/components/toast/context/ToastContext.esm.js +5 -0
  171. package/components/toast/context/ToastProvider.esm.js +96 -0
  172. package/components/tooltip/Tooltip.esm.js +175 -0
  173. package/components/upload/Upload.esm.js +1103 -0
  174. package/components/upload/utils/canvasPreview.esm.js +39 -0
  175. package/components/upload/utils/imgPreview.esm.js +21 -0
  176. package/config/stitches.config.esm.js +216 -0
  177. package/editor.esm.js +1 -264
  178. package/hooks/useListOption/useListOption.esm.js +56 -0
  179. package/hooks/useToggle/useToggle.esm.js +8 -0
  180. package/index.esm.js +106 -42293
  181. package/layout/box/Box.esm.js +24 -0
  182. package/layout/flex/Flex.esm.js +135 -0
  183. package/layout/grid/Grid.esm.js +270 -0
  184. package/layout/pageContainer/PageContainer.esm.js +60 -0
  185. package/majoo-provider/MajooProvider.esm.js +42 -0
  186. package/majoo-provider/ThemeProvider.esm.js +41 -0
  187. package/majoo-provider/globalStyles.esm.js +242 -0
  188. package/majoo-provider/styles/modern-normalize.esm.js +95 -0
  189. package/map.esm.js +2 -734
  190. package/package.json +8 -4
  191. package/utils/calendar.esm.js +26 -0
  192. package/utils/element.esm.js +21 -0
  193. package/utils/object.esm.js +12 -0
  194. package/utils/request.esm.js +74 -0
  195. package/utils/strings.esm.js +6 -0
  196. package/{useMediaQuery.esm.js → utils/useMediaQuery.esm.js} +1 -1
  197. package/utils/useNavigatorOnline.esm.js +19 -0
  198. package/utils/variant.esm.js +12 -0
  199. package/wrapper/ConditionalWrapper.esm.js +9 -0
  200. package/ModalDialog.esm.js +0 -2669
  201. package/Separator.esm.js +0 -3002
  202. package/stitches.config.esm.js +0 -2284
@@ -0,0 +1,1263 @@
1
+ import 'core-js/modules/es.array.includes.js';
2
+ import 'core-js/modules/es.array.push.js';
3
+ import 'core-js/modules/es.iterator.constructor.js';
4
+ import 'core-js/modules/es.iterator.filter.js';
5
+ import 'core-js/modules/es.iterator.find.js';
6
+ import 'core-js/modules/es.iterator.for-each.js';
7
+ import 'core-js/modules/es.iterator.reduce.js';
8
+ import React__default from 'react';
9
+
10
+ //
11
+
12
+ // basic noop function
13
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
14
+ function noop() {}
15
+ function returnTrue() {
16
+ return true;
17
+ }
18
+ function charIsNumber(char) {
19
+ return !!(char || '').match(/\d/);
20
+ }
21
+ function isNil(val) {
22
+ return val === null || val === undefined;
23
+ }
24
+ function escapeRegExp(str) {
25
+ return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
26
+ }
27
+ function getThousandsGroupRegex(thousandsGroupStyle) {
28
+ switch (thousandsGroupStyle) {
29
+ case 'lakh':
30
+ return /(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/g;
31
+ case 'wan':
32
+ return /(\d)(?=(\d{4})+(?!\d))/g;
33
+ case 'thousand':
34
+ default:
35
+ return /(\d)(?=(\d{3})+(?!\d))/g;
36
+ }
37
+ }
38
+ function applyThousandSeparator(str, thousandSeparator, thousandsGroupStyle) {
39
+ var thousandsGroupRegex = getThousandsGroupRegex(thousandsGroupStyle);
40
+ var index = str.search(/[1-9]/);
41
+ index = index === -1 ? str.length : index;
42
+ return str.substring(0, index) + str.substring(index, str.length).replace(thousandsGroupRegex, '$1' + thousandSeparator);
43
+ }
44
+
45
+ //spilt a float number into different parts beforeDecimal, afterDecimal, and negation
46
+ function splitDecimal(numStr, allowNegative) {
47
+ if (allowNegative === void 0) allowNegative = true;
48
+ var hasNagation = numStr[0] === '-';
49
+ var addNegation = hasNagation && allowNegative;
50
+ numStr = numStr.replace('-', '');
51
+ var parts = numStr.split('.');
52
+ var beforeDecimal = parts[0];
53
+ var afterDecimal = parts[1] || '';
54
+ return {
55
+ beforeDecimal: beforeDecimal,
56
+ afterDecimal: afterDecimal,
57
+ hasNagation: hasNagation,
58
+ addNegation: addNegation
59
+ };
60
+ }
61
+ function fixLeadingZero(numStr) {
62
+ if (!numStr) {
63
+ return numStr;
64
+ }
65
+ var isNegative = numStr[0] === '-';
66
+ if (isNegative) {
67
+ numStr = numStr.substring(1, numStr.length);
68
+ }
69
+ var parts = numStr.split('.');
70
+ var beforeDecimal = parts[0].replace(/^0+/, '') || '0';
71
+ var afterDecimal = parts[1] || '';
72
+ return '' + (isNegative ? '-' : '') + beforeDecimal + (afterDecimal ? '.' + afterDecimal : '');
73
+ }
74
+
75
+ /**
76
+ * limit decimal numbers to given scale
77
+ * Not used .fixedTo because that will break with big numbers
78
+ */
79
+ function limitToScale(numStr, scale, fixedDecimalScale) {
80
+ var str = '';
81
+ var filler = fixedDecimalScale ? '0' : '';
82
+ for (var i = 0; i <= scale - 1; i++) {
83
+ str += numStr[i] || filler;
84
+ }
85
+ return str;
86
+ }
87
+ function repeat(str, count) {
88
+ return Array(count + 1).join(str);
89
+ }
90
+ function toNumericString(num) {
91
+ num += ''; // typecast number to string
92
+
93
+ // store the sign and remove it from the number.
94
+ var sign = num[0] === '-' ? '-' : '';
95
+ if (sign) {
96
+ num = num.substring(1);
97
+ }
98
+
99
+ // split the number into cofficient and exponent
100
+ var ref = num.split(/[eE]/g);
101
+ var coefficient = ref[0];
102
+ var exponent = ref[1];
103
+
104
+ // covert exponent to number;
105
+ exponent = Number(exponent);
106
+
107
+ // if there is no exponent part or its 0, return the coffiecient with sign
108
+ if (!exponent) {
109
+ return sign + coefficient;
110
+ }
111
+ coefficient = coefficient.replace('.', '');
112
+
113
+ /**
114
+ * for scientific notation the current decimal index will be after first number (index 0)
115
+ * So effective decimal index will always be 1 + exponent value
116
+ */
117
+ var decimalIndex = 1 + exponent;
118
+ var coffiecientLn = coefficient.length;
119
+ if (decimalIndex < 0) {
120
+ // if decimal index is less then 0 add preceding 0s
121
+ // add 1 as join will have
122
+ coefficient = '0.' + repeat('0', Math.abs(decimalIndex)) + coefficient;
123
+ } else if (decimalIndex >= coffiecientLn) {
124
+ // if decimal index is less then 0 add leading 0s
125
+ coefficient = coefficient + repeat('0', decimalIndex - coffiecientLn);
126
+ } else {
127
+ // else add decimal point at proper index
128
+ coefficient = (coefficient.substring(0, decimalIndex) || '0') + '.' + coefficient.substring(decimalIndex);
129
+ }
130
+ return sign + coefficient;
131
+ }
132
+
133
+ /**
134
+ * This method is required to round prop value to given scale.
135
+ * Not used .round or .fixedTo because that will break with big numbers
136
+ */
137
+ function roundToPrecision(numStr, scale, fixedDecimalScale) {
138
+ //if number is empty don't do anything return empty string
139
+ if (['', '-'].indexOf(numStr) !== -1) {
140
+ return numStr;
141
+ }
142
+ var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
143
+ var ref = splitDecimal(numStr);
144
+ var beforeDecimal = ref.beforeDecimal;
145
+ var afterDecimal = ref.afterDecimal;
146
+ var hasNagation = ref.hasNagation;
147
+ var floatValue = parseFloat('0.' + (afterDecimal || '0'));
148
+ var floatValueStr = afterDecimal.length <= scale ? '0.' + afterDecimal : floatValue.toFixed(scale);
149
+ var roundedDecimalParts = floatValueStr.split('.');
150
+ var intPart = beforeDecimal.split('').reverse().reduce(function (roundedStr, current, idx) {
151
+ if (roundedStr.length > idx) {
152
+ return (Number(roundedStr[0]) + Number(current)).toString() + roundedStr.substring(1, roundedStr.length);
153
+ }
154
+ return current + roundedStr;
155
+ }, roundedDecimalParts[0]);
156
+ var decimalPart = limitToScale(roundedDecimalParts[1] || '', Math.min(scale, afterDecimal.length), fixedDecimalScale);
157
+ var negation = hasNagation ? '-' : '';
158
+ var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '';
159
+ return '' + negation + intPart + decimalSeparator + decimalPart;
160
+ }
161
+
162
+ /** set the caret positon in an input field **/
163
+ function setCaretPosition(el, caretPos) {
164
+ // eslint-disable-next-line no-self-assign
165
+ el.value = el.value;
166
+ // ^ this is used to not only get 'focus', but
167
+ // to make sure we don't have it everything -selected-
168
+ // (it causes an issue in chrome, and having it doesn't hurt any other browser)
169
+ if (el !== null) {
170
+ if (el.createTextRange) {
171
+ var range = el.createTextRange();
172
+ range.move('character', caretPos);
173
+ range.select();
174
+ return true;
175
+ }
176
+ // (el.selectionStart === 0 added for Firefox bug)
177
+ if (el.selectionStart || el.selectionStart === 0) {
178
+ el.focus();
179
+ el.setSelectionRange(caretPos, caretPos);
180
+ return true;
181
+ }
182
+
183
+ // fail city, fortunately this never happens (as far as I've tested) :)
184
+ el.focus();
185
+ return false;
186
+ }
187
+ }
188
+
189
+ /**
190
+ Given previous value and newValue it returns the index
191
+ start - end to which values have changed.
192
+ This function makes assumption about only consecutive
193
+ characters are changed which is correct assumption for caret input.
194
+ */
195
+ function findChangedIndex(prevValue, newValue) {
196
+ var i = 0,
197
+ j = 0;
198
+ var prevLength = prevValue.length;
199
+ var newLength = newValue.length;
200
+ while (prevValue[i] === newValue[i] && i < prevLength) {
201
+ i++;
202
+ }
203
+
204
+ //check what has been changed from last
205
+ while (prevValue[prevLength - 1 - j] === newValue[newLength - 1 - j] && newLength - j > i && prevLength - j > i) {
206
+ j++;
207
+ }
208
+ return {
209
+ start: i,
210
+ end: prevLength - j
211
+ };
212
+ }
213
+
214
+ /*
215
+ Returns a number whose value is limited to the given range
216
+ */
217
+ function clamp(num, min, max) {
218
+ return Math.min(Math.max(num, min), max);
219
+ }
220
+ function getCurrentCaretPosition(el) {
221
+ /*Max of selectionStart and selectionEnd is taken for the patch of pixel and other mobile device caret bug*/
222
+ return Math.max(el.selectionStart, el.selectionEnd);
223
+ }
224
+ function addInputMode(format) {
225
+ return format || typeof navigator !== 'undefined' && !(navigator.platform && /iPhone|iPod/.test(navigator.platform));
226
+ }
227
+
228
+ //
229
+ function objectWithoutProperties(obj, exclude) {
230
+ var target = {};
231
+ for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k];
232
+ return target;
233
+ }
234
+ var defaultProps = {
235
+ displayType: 'input',
236
+ decimalSeparator: '.',
237
+ thousandsGroupStyle: 'thousand',
238
+ fixedDecimalScale: false,
239
+ prefix: '',
240
+ suffix: '',
241
+ allowNegative: true,
242
+ allowEmptyFormatting: false,
243
+ allowLeadingZeros: false,
244
+ isNumericString: false,
245
+ type: 'text',
246
+ onValueChange: noop,
247
+ onChange: noop,
248
+ onKeyDown: noop,
249
+ onMouseUp: noop,
250
+ onFocus: noop,
251
+ onBlur: noop,
252
+ isAllowed: returnTrue
253
+ };
254
+ var NumberFormat = /*@__PURE__*/function (superclass) {
255
+ function NumberFormat(props) {
256
+ superclass.call(this, props);
257
+ var defaultValue = props.defaultValue;
258
+
259
+ //validate props
260
+ this.validateProps();
261
+ var formattedValue = this.formatValueProp(defaultValue);
262
+ this.state = {
263
+ value: formattedValue,
264
+ numAsString: this.removeFormatting(formattedValue),
265
+ mounted: false
266
+ };
267
+ this.selectionBeforeInput = {
268
+ selectionStart: 0,
269
+ selectionEnd: 0
270
+ };
271
+ this.onChange = this.onChange.bind(this);
272
+ this.onKeyDown = this.onKeyDown.bind(this);
273
+ this.onMouseUp = this.onMouseUp.bind(this);
274
+ this.onFocus = this.onFocus.bind(this);
275
+ this.onBlur = this.onBlur.bind(this);
276
+ }
277
+ if (superclass) NumberFormat.__proto__ = superclass;
278
+ NumberFormat.prototype = Object.create(superclass && superclass.prototype);
279
+ NumberFormat.prototype.constructor = NumberFormat;
280
+ NumberFormat.prototype.componentDidMount = function componentDidMount() {
281
+ // set mounted state
282
+ // eslint-disable-next-line react/no-did-mount-set-state
283
+ this.setState({
284
+ mounted: true
285
+ });
286
+ };
287
+ NumberFormat.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
288
+ this.updateValueIfRequired(prevProps);
289
+ };
290
+ NumberFormat.prototype.componentWillUnmount = function componentWillUnmount() {
291
+ clearTimeout(this.focusTimeout);
292
+ clearTimeout(this.caretPositionTimeout);
293
+ };
294
+ NumberFormat.prototype.updateValueIfRequired = function updateValueIfRequired(prevProps) {
295
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
296
+ var ref = this;
297
+ var props = ref.props;
298
+ var state = ref.state;
299
+ var focusedElm = ref.focusedElm;
300
+ var stateValue = state.value;
301
+ var lastNumStr = state.numAsString;
302
+ if (lastNumStr === void 0) lastNumStr = '';
303
+
304
+ // If only state changed no need to do any thing
305
+ if (prevProps !== props) {
306
+ //validate props
307
+ this.validateProps();
308
+ var lastValueWithNewFormat = this.formatNumString(lastNumStr);
309
+ var formattedValue = isNil(props.value) ? lastValueWithNewFormat : this.formatValueProp();
310
+ var numAsString = this.removeFormatting(formattedValue);
311
+ var floatValue = parseFloat(numAsString);
312
+ var lastFloatValue = parseFloat(lastNumStr);
313
+ if (
314
+ //while typing set state only when float value changes
315
+ (!isNaN(floatValue) || !isNaN(lastFloatValue)) && floatValue !== lastFloatValue ||
316
+ //can also set state when float value is same and the format props changes
317
+ lastValueWithNewFormat !== stateValue ||
318
+ //set state always when not in focus and formatted value is changed
319
+ focusedElm === null && formattedValue !== stateValue) {
320
+ this.updateValue({
321
+ formattedValue: formattedValue,
322
+ numAsString: numAsString,
323
+ input: focusedElm,
324
+ source: 'prop',
325
+ event: null
326
+ });
327
+ }
328
+ }
329
+ };
330
+
331
+ /** Misc methods **/
332
+ NumberFormat.prototype.getFloatString = function getFloatString(num) {
333
+ if (num === void 0) num = '';
334
+ var ref = this.props;
335
+ var decimalScale = ref.decimalScale;
336
+ var ref$1 = this.getSeparators();
337
+ var decimalSeparator = ref$1.decimalSeparator;
338
+ var numRegex = this.getNumberRegex(true);
339
+
340
+ //remove negation for regex check
341
+ var hasNegation = num[0] === '-';
342
+ if (hasNegation) {
343
+ num = num.replace('-', '');
344
+ }
345
+
346
+ //if decimal scale is zero remove decimal and number after decimalSeparator
347
+ if (decimalSeparator && decimalScale === 0) {
348
+ num = num.split(decimalSeparator)[0];
349
+ }
350
+ num = (num.match(numRegex) || []).join('').replace(decimalSeparator, '.');
351
+
352
+ //remove extra decimals
353
+ var firstDecimalIndex = num.indexOf('.');
354
+ if (firstDecimalIndex !== -1) {
355
+ num = num.substring(0, firstDecimalIndex) + '.' + num.substring(firstDecimalIndex + 1, num.length).replace(new RegExp(escapeRegExp(decimalSeparator), 'g'), '');
356
+ }
357
+
358
+ //add negation back
359
+ if (hasNegation) {
360
+ num = '-' + num;
361
+ }
362
+ return num;
363
+ };
364
+
365
+ //returned regex assumes decimalSeparator is as per prop
366
+ NumberFormat.prototype.getNumberRegex = function getNumberRegex(g, ignoreDecimalSeparator) {
367
+ var ref = this.props;
368
+ var format = ref.format;
369
+ var decimalScale = ref.decimalScale;
370
+ var customNumerals = ref.customNumerals;
371
+ var ref$1 = this.getSeparators();
372
+ var decimalSeparator = ref$1.decimalSeparator;
373
+ return new RegExp('[0-9' + (customNumerals ? customNumerals.join('') : '') + ']' + (decimalSeparator && decimalScale !== 0 && !ignoreDecimalSeparator && !format ? '|' + escapeRegExp(decimalSeparator) : ''), g ? 'g' : undefined);
374
+ };
375
+ NumberFormat.prototype.getSeparators = function getSeparators() {
376
+ var ref = this.props;
377
+ var decimalSeparator = ref.decimalSeparator;
378
+ var ref$1 = this.props;
379
+ var thousandSeparator = ref$1.thousandSeparator;
380
+ var allowedDecimalSeparators = ref$1.allowedDecimalSeparators;
381
+ if (thousandSeparator === true) {
382
+ thousandSeparator = ',';
383
+ }
384
+ if (!allowedDecimalSeparators) {
385
+ allowedDecimalSeparators = [decimalSeparator, '.'];
386
+ }
387
+ return {
388
+ decimalSeparator: decimalSeparator,
389
+ thousandSeparator: thousandSeparator,
390
+ allowedDecimalSeparators: allowedDecimalSeparators
391
+ };
392
+ };
393
+ NumberFormat.prototype.getMaskAtIndex = function getMaskAtIndex(index) {
394
+ var ref = this.props;
395
+ var mask = ref.mask;
396
+ if (mask === void 0) mask = ' ';
397
+ if (typeof mask === 'string') {
398
+ return mask;
399
+ }
400
+ return mask[index] || ' ';
401
+ };
402
+ NumberFormat.prototype.getValueObject = function getValueObject(formattedValue, numAsString) {
403
+ var floatValue = parseFloat(numAsString);
404
+ return {
405
+ formattedValue: formattedValue,
406
+ value: numAsString,
407
+ floatValue: isNaN(floatValue) ? undefined : floatValue
408
+ };
409
+ };
410
+ NumberFormat.prototype.validateProps = function validateProps() {
411
+ var ref = this.props;
412
+ var mask = ref.mask;
413
+
414
+ //validate decimalSeparator and thousandSeparator
415
+ var ref$1 = this.getSeparators();
416
+ var decimalSeparator = ref$1.decimalSeparator;
417
+ var thousandSeparator = ref$1.thousandSeparator;
418
+ if (decimalSeparator === thousandSeparator) {
419
+ throw new Error("\n Decimal separator can't be same as thousand separator.\n thousandSeparator: " + thousandSeparator + ' (thousandSeparator = {true} is same as thousandSeparator = ",")\n decimalSeparator: ' + decimalSeparator + ' (default value for decimalSeparator is .)\n ');
420
+ }
421
+
422
+ //validate mask
423
+ if (mask) {
424
+ var maskAsStr = mask === 'string' ? mask : mask.toString();
425
+ if (maskAsStr.match(/\d/g)) {
426
+ throw new Error('\n Mask ' + mask + ' should not contain numeric character;\n ');
427
+ }
428
+ }
429
+ };
430
+ /** Misc methods end **/
431
+
432
+ /** caret specific methods **/
433
+ NumberFormat.prototype.setPatchedCaretPosition = function setPatchedCaretPosition(el, caretPos, currentValue) {
434
+ /* setting caret position within timeout of 0ms is required for mobile chrome,
435
+ otherwise browser resets the caret position after we set it
436
+ We are also setting it without timeout so that in normal browser we don't see the flickering */
437
+ setCaretPosition(el, caretPos);
438
+ this.caretPositionTimeout = setTimeout(function () {
439
+ if (el.value === currentValue) {
440
+ setCaretPosition(el, caretPos);
441
+ }
442
+ }, 0);
443
+ };
444
+
445
+ /* This keeps the caret within typing area so people can't type in between prefix or suffix */
446
+ NumberFormat.prototype.correctCaretPosition = function correctCaretPosition(value, caretPos, direction) {
447
+ var ref = this.props;
448
+ var prefix = ref.prefix;
449
+ var suffix = ref.suffix;
450
+ var format = ref.format;
451
+
452
+ //if value is empty return 0
453
+ if (value === '') {
454
+ return 0;
455
+ }
456
+
457
+ //caret position should be between 0 and value length
458
+ caretPos = clamp(caretPos, 0, value.length);
459
+
460
+ //in case of format as number limit between prefix and suffix
461
+ if (!format) {
462
+ var hasNegation = value[0] === '-';
463
+ return clamp(caretPos, prefix.length + (hasNegation ? 1 : 0), value.length - suffix.length);
464
+ }
465
+
466
+ //in case if custom format method don't do anything
467
+ if (typeof format === 'function') {
468
+ return caretPos;
469
+ }
470
+
471
+ /* in case format is string find the closest # position from the caret position */
472
+
473
+ //in case the caretPos have input value on it don't do anything
474
+ if (format[caretPos] === '#' && charIsNumber(value[caretPos])) {
475
+ return caretPos;
476
+ }
477
+
478
+ //if caretPos is just after input value don't do anything
479
+ if (format[caretPos - 1] === '#' && charIsNumber(value[caretPos - 1])) {
480
+ return caretPos;
481
+ }
482
+
483
+ //find the nearest caret position
484
+ var firstHashPosition = format.indexOf('#');
485
+ var lastHashPosition = format.lastIndexOf('#');
486
+
487
+ //limit the cursor between the first # position and the last # position
488
+ caretPos = clamp(caretPos, firstHashPosition, lastHashPosition + 1);
489
+ var nextPos = format.substring(caretPos, format.length).indexOf('#');
490
+ var caretLeftBound = caretPos;
491
+ var caretRightBound = caretPos + (nextPos === -1 ? 0 : nextPos);
492
+
493
+ //get the position where the last number is present
494
+ while (caretLeftBound > firstHashPosition && (format[caretLeftBound] !== '#' || !charIsNumber(value[caretLeftBound]))) {
495
+ caretLeftBound -= 1;
496
+ }
497
+ var goToLeft = !charIsNumber(value[caretRightBound]) || direction === 'left' && caretPos !== firstHashPosition || caretPos - caretLeftBound < caretRightBound - caretPos;
498
+ if (goToLeft) {
499
+ //check if number should be taken after the bound or after it
500
+ //if number preceding a valid number keep it after
501
+ return charIsNumber(value[caretLeftBound]) ? caretLeftBound + 1 : caretLeftBound;
502
+ }
503
+ return caretRightBound;
504
+ };
505
+ NumberFormat.prototype.getCaretPosition = function getCaretPosition(inputValue, formattedValue, caretPos) {
506
+ var ref = this.props;
507
+ var format = ref.format;
508
+ var stateValue = this.state.value;
509
+ var numRegex = this.getNumberRegex(true);
510
+ var inputNumber = (inputValue.match(numRegex) || []).join('');
511
+ var formattedNumber = (formattedValue.match(numRegex) || []).join('');
512
+ var j, i;
513
+ j = 0;
514
+ for (i = 0; i < caretPos; i++) {
515
+ var currentInputChar = inputValue[i] || '';
516
+ var currentFormatChar = formattedValue[j] || '';
517
+ //no need to increase new cursor position if formatted value does not have those characters
518
+ //case inputValue = 1a23 and formattedValue = 123
519
+ if (!currentInputChar.match(numRegex) && currentInputChar !== currentFormatChar) {
520
+ continue;
521
+ }
522
+
523
+ //When we are striping out leading zeros maintain the new cursor position
524
+ //Case inputValue = 00023 and formattedValue = 23;
525
+ if (currentInputChar === '0' && currentFormatChar.match(numRegex) && currentFormatChar !== '0' && inputNumber.length !== formattedNumber.length) {
526
+ continue;
527
+ }
528
+
529
+ //we are not using currentFormatChar because j can change here
530
+ while (currentInputChar !== formattedValue[j] && j < formattedValue.length) {
531
+ j++;
532
+ }
533
+ j++;
534
+ }
535
+ if (typeof format === 'string' && !stateValue) {
536
+ //set it to the maximum value so it goes after the last number
537
+ j = formattedValue.length;
538
+ }
539
+
540
+ //correct caret position if its outside of editable area
541
+ j = this.correctCaretPosition(formattedValue, j);
542
+ return j;
543
+ };
544
+ /** caret specific methods ends **/
545
+
546
+ /** methods to remove formattting **/
547
+ NumberFormat.prototype.removePrefixAndSuffix = function removePrefixAndSuffix(val) {
548
+ var ref = this.props;
549
+ var format = ref.format;
550
+ var prefix = ref.prefix;
551
+ var suffix = ref.suffix;
552
+
553
+ //remove prefix and suffix
554
+ if (!format && val) {
555
+ var isNegative = val[0] === '-';
556
+
557
+ //remove negation sign
558
+ if (isNegative) {
559
+ val = val.substring(1, val.length);
560
+ }
561
+
562
+ //remove prefix
563
+ val = prefix && val.indexOf(prefix) === 0 ? val.substring(prefix.length, val.length) : val;
564
+
565
+ //remove suffix
566
+ var suffixLastIndex = val.lastIndexOf(suffix);
567
+ val = suffix && suffixLastIndex !== -1 && suffixLastIndex === val.length - suffix.length ? val.substring(0, suffixLastIndex) : val;
568
+
569
+ //add negation sign back
570
+ if (isNegative) {
571
+ val = '-' + val;
572
+ }
573
+ }
574
+ return val;
575
+ };
576
+ NumberFormat.prototype.removePatternFormatting = function removePatternFormatting(val) {
577
+ var ref = this.props;
578
+ var format = ref.format;
579
+ var formatArray = format.split('#').filter(function (str) {
580
+ return str !== '';
581
+ });
582
+ var start = 0;
583
+ var numStr = '';
584
+ for (var i = 0, ln = formatArray.length; i <= ln; i++) {
585
+ var part = formatArray[i] || '';
586
+
587
+ //if i is the last fragment take the index of end of the value
588
+ //For case like +1 (911) 911 91 91 having pattern +1 (###) ### ## ##
589
+ var index = i === ln ? val.length : val.indexOf(part, start);
590
+
591
+ /* in any case if we don't find the pattern part in the value assume the val as numeric string
592
+ This will be also in case if user has started typing, in any other case it will not be -1
593
+ unless wrong prop value is provided */
594
+ if (index === -1) {
595
+ numStr = val;
596
+ break;
597
+ } else {
598
+ numStr += val.substring(start, index);
599
+ start = index + part.length;
600
+ }
601
+ }
602
+ return (numStr.match(this.getNumberRegex(true)) || []).join('');
603
+ };
604
+ NumberFormat.prototype.removeFormatting = function removeFormatting(val) {
605
+ var ref = this.props;
606
+ var format = ref.format;
607
+ var removeFormatting = ref.removeFormatting;
608
+ if (!val) {
609
+ return val;
610
+ }
611
+ if (!format) {
612
+ val = this.removePrefixAndSuffix(val);
613
+ val = this.getFloatString(val);
614
+ } else if (typeof format === 'string') {
615
+ val = this.removePatternFormatting(val);
616
+ } else if (typeof removeFormatting === 'function') {
617
+ //condition need to be handled if format method is provide,
618
+ val = removeFormatting(val);
619
+ } else {
620
+ val = (val.match(this.getNumberRegex(true)) || []).join('');
621
+ }
622
+ return val;
623
+ };
624
+ /** methods to remove formattting end **/
625
+
626
+ /*** format specific methods start ***/
627
+ /**
628
+ * Format when # based string is provided
629
+ * @param {string} numStr Numeric String
630
+ * @return {string} formatted Value
631
+ */
632
+ NumberFormat.prototype.formatWithPattern = function formatWithPattern(numStr) {
633
+ var ref = this.props;
634
+ var format = ref.format;
635
+ var hashCount = 0;
636
+ var formattedNumberAry = format.split('');
637
+ for (var i = 0, ln = format.length; i < ln; i++) {
638
+ if (format[i] === '#') {
639
+ formattedNumberAry[i] = numStr[hashCount] || this.getMaskAtIndex(hashCount);
640
+ hashCount += 1;
641
+ }
642
+ }
643
+ return formattedNumberAry.join('');
644
+ };
645
+ /**
646
+ * @param {string} numStr Numeric string/floatString] It always have decimalSeparator as .
647
+ * @return {string} formatted Value
648
+ */
649
+ NumberFormat.prototype.formatAsNumber = function formatAsNumber(numStr) {
650
+ var ref = this.props;
651
+ var decimalScale = ref.decimalScale;
652
+ var fixedDecimalScale = ref.fixedDecimalScale;
653
+ var prefix = ref.prefix;
654
+ var suffix = ref.suffix;
655
+ var allowNegative = ref.allowNegative;
656
+ var thousandsGroupStyle = ref.thousandsGroupStyle;
657
+ var ref$1 = this.getSeparators();
658
+ var thousandSeparator = ref$1.thousandSeparator;
659
+ var decimalSeparator = ref$1.decimalSeparator;
660
+ var hasDecimalSeparator = numStr.indexOf('.') !== -1 || decimalScale && fixedDecimalScale;
661
+ var ref$2 = splitDecimal(numStr, allowNegative);
662
+ var beforeDecimal = ref$2.beforeDecimal;
663
+ var afterDecimal = ref$2.afterDecimal;
664
+ var addNegation = ref$2.addNegation; // eslint-disable-line prefer-const
665
+
666
+ //apply decimal precision if its defined
667
+ if (decimalScale !== undefined) {
668
+ afterDecimal = limitToScale(afterDecimal, decimalScale, fixedDecimalScale);
669
+ }
670
+ if (thousandSeparator) {
671
+ beforeDecimal = applyThousandSeparator(beforeDecimal, thousandSeparator, thousandsGroupStyle);
672
+ }
673
+
674
+ //add prefix and suffix
675
+ if (prefix) {
676
+ beforeDecimal = prefix + beforeDecimal;
677
+ }
678
+ if (suffix) {
679
+ afterDecimal = afterDecimal + suffix;
680
+ }
681
+
682
+ //restore negation sign
683
+ if (addNegation) {
684
+ beforeDecimal = '-' + beforeDecimal;
685
+ }
686
+ numStr = beforeDecimal + (hasDecimalSeparator && decimalSeparator || '') + afterDecimal;
687
+ return numStr;
688
+ };
689
+ NumberFormat.prototype.formatNumString = function formatNumString(numStr) {
690
+ if (numStr === void 0) numStr = '';
691
+ var ref = this.props;
692
+ var format = ref.format;
693
+ var allowEmptyFormatting = ref.allowEmptyFormatting;
694
+ var customNumerals = ref.customNumerals;
695
+ var formattedValue = numStr;
696
+ if (customNumerals && customNumerals.length === 10) {
697
+ var customNumeralRegex = new RegExp('[' + customNumerals.join('') + ']', 'g');
698
+ formattedValue = numStr.replace(customNumeralRegex, function (digit) {
699
+ return customNumerals.indexOf(digit).toString();
700
+ });
701
+ }
702
+ if (numStr === '' && !allowEmptyFormatting) {
703
+ formattedValue = '';
704
+ } else if (numStr === '-' && !format) {
705
+ formattedValue = '-';
706
+ } else if (typeof format === 'string') {
707
+ formattedValue = this.formatWithPattern(formattedValue);
708
+ } else if (typeof format === 'function') {
709
+ formattedValue = format(formattedValue);
710
+ } else {
711
+ formattedValue = this.formatAsNumber(formattedValue);
712
+ }
713
+ return formattedValue;
714
+ };
715
+ NumberFormat.prototype.formatValueProp = function formatValueProp(defaultValue) {
716
+ var ref = this.props;
717
+ var format = ref.format;
718
+ var decimalScale = ref.decimalScale;
719
+ var fixedDecimalScale = ref.fixedDecimalScale;
720
+ var allowEmptyFormatting = ref.allowEmptyFormatting;
721
+ var ref$1 = this.props;
722
+ var value = ref$1.value;
723
+ var isNumericString = ref$1.isNumericString;
724
+
725
+ // if value is undefined or null, use defaultValue instead
726
+ value = isNil(value) ? defaultValue : value;
727
+ var isNonNumericFalsy = !value && value !== 0;
728
+ if (isNonNumericFalsy && allowEmptyFormatting) {
729
+ value = '';
730
+ }
731
+
732
+ // if value is not defined return empty string
733
+ if (isNonNumericFalsy && !allowEmptyFormatting) {
734
+ return '';
735
+ }
736
+ if (typeof value === 'number') {
737
+ value = toNumericString(value);
738
+ isNumericString = true;
739
+ }
740
+
741
+ //change infinity value to empty string
742
+ if (value === 'Infinity' && isNumericString) {
743
+ value = '';
744
+ }
745
+
746
+ //round the number based on decimalScale
747
+ //format only if non formatted value is provided
748
+ if (isNumericString && !format && typeof decimalScale === 'number') {
749
+ value = roundToPrecision(value, decimalScale, fixedDecimalScale);
750
+ }
751
+ var formattedValue = isNumericString ? this.formatNumString(value) : this.formatInput(value);
752
+ return formattedValue;
753
+ };
754
+ NumberFormat.prototype.formatNegation = function formatNegation(value) {
755
+ if (value === void 0) value = '';
756
+ var ref = this.props;
757
+ var allowNegative = ref.allowNegative;
758
+ var negationRegex = new RegExp('(-)');
759
+ var doubleNegationRegex = new RegExp('(-)(.)*(-)');
760
+
761
+ // Check number has '-' value
762
+ var hasNegation = negationRegex.test(value);
763
+
764
+ // Check number has 2 or more '-' values
765
+ var removeNegation = doubleNegationRegex.test(value);
766
+
767
+ //remove negation
768
+ value = value.replace(/-/g, '');
769
+ if (hasNegation && !removeNegation && allowNegative) {
770
+ value = '-' + value;
771
+ }
772
+ return value;
773
+ };
774
+ NumberFormat.prototype.formatInput = function formatInput(value) {
775
+ if (value === void 0) value = '';
776
+ var ref = this.props;
777
+ var format = ref.format;
778
+
779
+ //format negation only if we are formatting as number
780
+ if (!format) {
781
+ value = this.removePrefixAndSuffix(value);
782
+ value = this.formatNegation(value);
783
+ }
784
+
785
+ //remove formatting from number
786
+ value = this.removeFormatting(value);
787
+ return this.formatNumString(value);
788
+ };
789
+
790
+ /*** format specific methods end ***/
791
+ NumberFormat.prototype.isCharacterAFormat = function isCharacterAFormat(caretPos, value) {
792
+ var ref = this.props;
793
+ var format = ref.format;
794
+ var prefix = ref.prefix;
795
+ var suffix = ref.suffix;
796
+ var decimalScale = ref.decimalScale;
797
+ var fixedDecimalScale = ref.fixedDecimalScale;
798
+ var ref$1 = this.getSeparators();
799
+ var decimalSeparator = ref$1.decimalSeparator;
800
+
801
+ //check within format pattern
802
+ if (typeof format === 'string' && format[caretPos] !== '#') {
803
+ return true;
804
+ }
805
+
806
+ //check in number format
807
+ if (!format && (caretPos < prefix.length || caretPos >= value.length - suffix.length || decimalScale && fixedDecimalScale && value[caretPos] === decimalSeparator)) {
808
+ return true;
809
+ }
810
+ return false;
811
+ };
812
+
813
+ /**
814
+ * This will check if any formatting got removed by the delete or backspace and reset the value
815
+ * It will also work as fallback if android chome keyDown handler does not work
816
+ **/
817
+ NumberFormat.prototype.correctInputValue = function correctInputValue(caretPos, lastValue, value) {
818
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
819
+ var this$1$1 = this;
820
+ var ref = this.props;
821
+ var format = ref.format;
822
+ var allowNegative = ref.allowNegative;
823
+ var prefix = ref.prefix;
824
+ var suffix = ref.suffix;
825
+ var decimalScale = ref.decimalScale;
826
+ var ref$1 = this.getSeparators();
827
+ var allowedDecimalSeparators = ref$1.allowedDecimalSeparators;
828
+ var decimalSeparator = ref$1.decimalSeparator;
829
+ var lastNumStr = this.state.numAsString || '';
830
+ var ref$2 = this.selectionBeforeInput;
831
+ var selectionStart = ref$2.selectionStart;
832
+ var selectionEnd = ref$2.selectionEnd;
833
+ var ref$3 = findChangedIndex(lastValue, value);
834
+ var start = ref$3.start;
835
+ var end = ref$3.end;
836
+
837
+ /** Check for any allowed decimal separator is added in the numeric format and replace it with decimal separator */
838
+ if (!format && start === end && allowedDecimalSeparators.indexOf(value[selectionStart]) !== -1) {
839
+ var separator = decimalScale === 0 ? '' : decimalSeparator;
840
+ return value.substr(0, selectionStart) + separator + value.substr(selectionStart + 1, value.length);
841
+ }
842
+ var leftBound = format ? 0 : prefix.length;
843
+ var rightBound = lastValue.length - (format ? 0 : suffix.length);
844
+ if (
845
+ // don't do anything if something got added
846
+ value.length > lastValue.length ||
847
+ // or if the new value is an empty string
848
+ !value.length ||
849
+ // or if nothing has changed, in which case start will be same as end
850
+ start === end ||
851
+ // or in case if whole input is selected and new value is typed
852
+ selectionStart === 0 && selectionEnd === lastValue.length ||
853
+ // or in case if the whole content is replaced by browser, example (autocomplete)
854
+ start === 0 && end === lastValue.length ||
855
+ // or if charcters between prefix and suffix is selected.
856
+ // For numeric inputs we apply the format so, prefix and suffix can be ignored
857
+ selectionStart === leftBound && selectionEnd === rightBound) {
858
+ return value;
859
+ }
860
+
861
+ // check whether the deleted portion has a character that is part of a format
862
+ var deletedValues = lastValue.substr(start, end - start);
863
+ var formatGotDeleted = !![].concat(deletedValues).find(function (deletedVal, idx) {
864
+ return this$1$1.isCharacterAFormat(idx + start, lastValue);
865
+ });
866
+
867
+ // if it has, only remove characters that are not part of the format
868
+ if (formatGotDeleted) {
869
+ var deletedValuePortion = lastValue.substr(start);
870
+ var recordIndexOfFormatCharacters = {};
871
+ var resolvedPortion = [];
872
+ [].concat(deletedValuePortion).forEach(function (currentPortion, idx) {
873
+ if (this$1$1.isCharacterAFormat(idx + start, lastValue)) {
874
+ recordIndexOfFormatCharacters[idx] = currentPortion;
875
+ } else if (idx > deletedValues.length - 1) {
876
+ resolvedPortion.push(currentPortion);
877
+ }
878
+ });
879
+ Object.keys(recordIndexOfFormatCharacters).forEach(function (idx) {
880
+ if (resolvedPortion.length > idx) {
881
+ resolvedPortion.splice(idx, 0, recordIndexOfFormatCharacters[idx]);
882
+ } else {
883
+ resolvedPortion.push(recordIndexOfFormatCharacters[idx]);
884
+ }
885
+ });
886
+ value = lastValue.substr(0, start) + resolvedPortion.join('');
887
+ }
888
+
889
+ //for numbers check if beforeDecimal got deleted and there is nothing after decimal,
890
+ //clear all numbers in such case while keeping the - sign
891
+ if (!format) {
892
+ var numericString = this.removeFormatting(value);
893
+ var ref$4 = splitDecimal(numericString, allowNegative);
894
+ var beforeDecimal = ref$4.beforeDecimal;
895
+ var afterDecimal = ref$4.afterDecimal;
896
+ var addNegation = ref$4.addNegation; // eslint-disable-line prefer-const
897
+
898
+ //clear only if something got deleted
899
+ var isBeforeDecimalPoint = caretPos < value.indexOf(decimalSeparator) + 1;
900
+ if (numericString.length < lastNumStr.length && isBeforeDecimalPoint && beforeDecimal === '' && !parseFloat(afterDecimal)) {
901
+ return addNegation ? '-' : '';
902
+ }
903
+ }
904
+ return value;
905
+ };
906
+
907
+ /** Update value and caret position */
908
+ NumberFormat.prototype.updateValue = function updateValue(params) {
909
+ var formattedValue = params.formattedValue;
910
+ var input = params.input;
911
+ var setCaretPosition = params.setCaretPosition;
912
+ if (setCaretPosition === void 0) setCaretPosition = true;
913
+ var source = params.source;
914
+ var event = params.event;
915
+ var numAsString = params.numAsString;
916
+ var caretPos = params.caretPos;
917
+ var ref = this.props;
918
+ var onValueChange = ref.onValueChange;
919
+ var ref$1 = this.state;
920
+ var lastValue = ref$1.value;
921
+ if (input) {
922
+ //calculate caret position if not defined
923
+ if (caretPos === undefined && setCaretPosition) {
924
+ var inputValue = params.inputValue || input.value;
925
+ var currentCaretPosition = getCurrentCaretPosition(input);
926
+
927
+ /**
928
+ * set the value imperatively, this is required for IE fix
929
+ * This is also required as if new caret position is beyond the previous value.
930
+ * Caret position will not be set correctly
931
+ */
932
+ input.value = formattedValue;
933
+
934
+ //get the caret position
935
+ caretPos = this.getCaretPosition(inputValue, formattedValue, currentCaretPosition);
936
+ }
937
+
938
+ /**
939
+ * set the value imperatively, as we set the caret position as well imperatively.
940
+ * This is to keep value and caret position in sync
941
+ */
942
+ input.value = formattedValue;
943
+
944
+ //set caret position, and value imperatively when element is provided
945
+ if (setCaretPosition) {
946
+ //set caret position
947
+ this.setPatchedCaretPosition(input, caretPos, formattedValue);
948
+ }
949
+ }
950
+
951
+ //calculate numeric string if not passed
952
+ if (numAsString === undefined) {
953
+ numAsString = this.removeFormatting(formattedValue);
954
+ }
955
+
956
+ //update state if value is changed
957
+ if (formattedValue !== lastValue) {
958
+ //start adjustment
959
+ let {
960
+ prefix = '',
961
+ suffix = '',
962
+ allowLeadingZeros,
963
+ format
964
+ } = {
965
+ ...ref
966
+ };
967
+ const formattedValueStartsWithZero = formattedValue?.startsWith(`${prefix}0`);
968
+ const formattedWithZeroAndSuffix = formattedValue?.endsWith(`0${suffix}`);
969
+ const emptyFormattedValue = prefix || suffix || prefix + suffix || '';
970
+ if ((formattedValueStartsWithZero || formattedWithZeroAndSuffix) && !allowLeadingZeros && !format) {
971
+ const isSpecialChar = /^[+-]/.test(formattedValue);
972
+ if (formattedValue !== `${prefix}0${suffix}` && !formattedValue?.includes('0,')) {
973
+ formattedValue = formattedValue?.replace(new RegExp(`^${isSpecialChar ? '\\' : ''}${prefix}0+${suffix}`), emptyFormattedValue);
974
+ numAsString = numAsString?.replace(/^0+/, '');
975
+ }
976
+ if (formattedValue === emptyFormattedValue && !numAsString && [`${prefix}00${suffix}`, `${prefix}0${suffix}`].includes(input?.value)) {
977
+ formattedValue = `${prefix}0${suffix}`;
978
+ numAsString = '0';
979
+ } else if (input?.value?.includes('0,')) {
980
+ allowLeadingZeros = true;
981
+ formattedValue = input?.value;
982
+ numAsString = this.removeFormatting(input?.value);
983
+ }
984
+ }
985
+ //end adjustment
986
+ this.setState({
987
+ value: formattedValue,
988
+ numAsString: numAsString
989
+ });
990
+
991
+ // trigger onValueChange synchronously, so parent is updated along with the number format. Fix for #277, #287
992
+ onValueChange(this.getValueObject(formattedValue, numAsString), {
993
+ event: event,
994
+ source: source
995
+ });
996
+ }
997
+ };
998
+ NumberFormat.prototype.onChange = function onChange(e) {
999
+ var el = e.target;
1000
+ var inputValue = el.value;
1001
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
1002
+ var ref = this;
1003
+ var state = ref.state;
1004
+ var props = ref.props;
1005
+ var isAllowed = props.isAllowed;
1006
+ var lastValue = state.value || '';
1007
+ var currentCaretPosition = getCurrentCaretPosition(el);
1008
+ inputValue = this.correctInputValue(currentCaretPosition, lastValue, inputValue);
1009
+ var formattedValue = this.formatInput(inputValue) || '';
1010
+ var numAsString = this.removeFormatting(formattedValue);
1011
+ var valueObj = this.getValueObject(formattedValue, numAsString);
1012
+ var isChangeAllowed = isAllowed(valueObj);
1013
+ if (!isChangeAllowed) {
1014
+ formattedValue = lastValue;
1015
+ }
1016
+ this.updateValue({
1017
+ formattedValue: formattedValue,
1018
+ numAsString: numAsString,
1019
+ inputValue: inputValue,
1020
+ input: el,
1021
+ event: e,
1022
+ source: 'event'
1023
+ });
1024
+ if (isChangeAllowed) {
1025
+ props.onChange(e);
1026
+ }
1027
+ };
1028
+ NumberFormat.prototype.onBlur = function onBlur(e) {
1029
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
1030
+ var ref = this;
1031
+ var props = ref.props;
1032
+ var state = ref.state;
1033
+ var format = props.format;
1034
+ var onBlur = props.onBlur;
1035
+ var allowLeadingZeros = props.allowLeadingZeros;
1036
+ var numAsString = state.numAsString;
1037
+ var lastValue = state.value;
1038
+ this.focusedElm = null;
1039
+ clearTimeout(this.focusTimeout);
1040
+ clearTimeout(this.caretPositionTimeout);
1041
+ if (!format) {
1042
+ // if the numAsString is not a valid number reset it to empty
1043
+ if (isNaN(parseFloat(numAsString))) {
1044
+ numAsString = '';
1045
+ }
1046
+ if (!allowLeadingZeros) {
1047
+ numAsString = fixLeadingZero(numAsString);
1048
+ }
1049
+ var formattedValue = this.formatNumString(numAsString);
1050
+
1051
+ //change the state
1052
+ if (formattedValue !== lastValue) {
1053
+ // the event needs to be persisted because its properties can be accessed in an asynchronous way
1054
+ this.updateValue({
1055
+ formattedValue: formattedValue,
1056
+ numAsString: numAsString,
1057
+ input: e.target,
1058
+ setCaretPosition: false,
1059
+ event: e,
1060
+ source: 'event'
1061
+ });
1062
+ onBlur(e);
1063
+ return;
1064
+ }
1065
+ }
1066
+ onBlur(e);
1067
+ };
1068
+ NumberFormat.prototype.onKeyDown = function onKeyDown(e) {
1069
+ var el = e.target;
1070
+ var key = e.key;
1071
+ var selectionStart = el.selectionStart;
1072
+ var selectionEnd = el.selectionEnd;
1073
+ var value = el.value;
1074
+ if (value === void 0) value = '';
1075
+ var expectedCaretPosition;
1076
+ var ref = this.props;
1077
+ var decimalScale = ref.decimalScale;
1078
+ var fixedDecimalScale = ref.fixedDecimalScale;
1079
+ var prefix = ref.prefix;
1080
+ var suffix = ref.suffix;
1081
+ var format = ref.format;
1082
+ var onKeyDown = ref.onKeyDown;
1083
+ var ignoreDecimalSeparator = decimalScale !== undefined && fixedDecimalScale;
1084
+ var numRegex = this.getNumberRegex(false, ignoreDecimalSeparator);
1085
+ var negativeRegex = new RegExp('-');
1086
+ var isPatternFormat = typeof format === 'string';
1087
+ this.selectionBeforeInput = {
1088
+ selectionStart: selectionStart,
1089
+ selectionEnd: selectionEnd
1090
+ };
1091
+
1092
+ //Handle backspace and delete against non numerical/decimal characters or arrow keys
1093
+ if (key === 'ArrowLeft' || key === 'Backspace') {
1094
+ expectedCaretPosition = selectionStart - 1;
1095
+ } else if (key === 'ArrowRight') {
1096
+ expectedCaretPosition = selectionStart + 1;
1097
+ } else if (key === 'Delete') {
1098
+ expectedCaretPosition = selectionStart;
1099
+ }
1100
+
1101
+ //if expectedCaretPosition is not set it means we don't want to Handle keyDown
1102
+ //also if multiple characters are selected don't handle
1103
+ if (expectedCaretPosition === undefined || selectionStart !== selectionEnd) {
1104
+ onKeyDown(e);
1105
+ return;
1106
+ }
1107
+ var newCaretPosition = expectedCaretPosition;
1108
+ var leftBound = isPatternFormat ? format.indexOf('#') : prefix.length;
1109
+ var rightBound = isPatternFormat ? format.lastIndexOf('#') + 1 : value.length - suffix.length;
1110
+ if (key === 'ArrowLeft' || key === 'ArrowRight') {
1111
+ var direction = key === 'ArrowLeft' ? 'left' : 'right';
1112
+ newCaretPosition = this.correctCaretPosition(value, expectedCaretPosition, direction);
1113
+ } else if (key === 'Delete' && !numRegex.test(value[expectedCaretPosition]) && !negativeRegex.test(value[expectedCaretPosition])) {
1114
+ while (!numRegex.test(value[newCaretPosition]) && newCaretPosition < rightBound) {
1115
+ newCaretPosition++;
1116
+ }
1117
+ } else if (key === 'Backspace' && !numRegex.test(value[expectedCaretPosition])) {
1118
+ /* NOTE: This is special case when backspace is pressed on a
1119
+ negative value while the cursor position is after prefix. We can't handle it on onChange because
1120
+ we will not have any information of keyPress
1121
+ */
1122
+ if (selectionStart <= leftBound + 1 && value[0] === '-' && typeof format === 'undefined') {
1123
+ var newValue = value.substring(1);
1124
+ this.updateValue({
1125
+ formattedValue: newValue,
1126
+ caretPos: newCaretPosition,
1127
+ input: el,
1128
+ event: e,
1129
+ source: 'event'
1130
+ });
1131
+ } else if (!negativeRegex.test(value[expectedCaretPosition])) {
1132
+ while (!numRegex.test(value[newCaretPosition - 1]) && newCaretPosition > leftBound) {
1133
+ newCaretPosition--;
1134
+ }
1135
+ newCaretPosition = this.correctCaretPosition(value, newCaretPosition, 'left');
1136
+ }
1137
+ }
1138
+ if (newCaretPosition !== expectedCaretPosition || expectedCaretPosition < leftBound || expectedCaretPosition > rightBound) {
1139
+ e.preventDefault();
1140
+ this.setPatchedCaretPosition(el, newCaretPosition, value);
1141
+ }
1142
+
1143
+ /* NOTE: this is just required for unit test as we need to get the newCaretPosition,
1144
+ Remove this when you find different solution */
1145
+ if (e.isUnitTestRun) {
1146
+ this.setPatchedCaretPosition(el, newCaretPosition, value);
1147
+ }
1148
+ onKeyDown(e);
1149
+ };
1150
+
1151
+ /** required to handle the caret position when click anywhere within the input **/
1152
+ NumberFormat.prototype.onMouseUp = function onMouseUp(e) {
1153
+ var el = e.target;
1154
+
1155
+ /**
1156
+ * NOTE: we have to give default value for value as in case when custom input is provided
1157
+ * value can come as undefined when nothing is provided on value prop.
1158
+ */
1159
+ var selectionStart = el.selectionStart;
1160
+ var selectionEnd = el.selectionEnd;
1161
+ var value = el.value;
1162
+ if (value === void 0) value = '';
1163
+ if (selectionStart === selectionEnd) {
1164
+ var caretPosition = this.correctCaretPosition(value, selectionStart);
1165
+ if (caretPosition !== selectionStart) {
1166
+ this.setPatchedCaretPosition(el, caretPosition, value);
1167
+ }
1168
+ }
1169
+ this.props.onMouseUp(e);
1170
+ };
1171
+ NumberFormat.prototype.onFocus = function onFocus(e) {
1172
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
1173
+ var this$1$1 = this;
1174
+
1175
+ // Workaround Chrome and Safari bug https://bugs.chromium.org/p/chromium/issues/detail?id=779328
1176
+ // (onFocus event target selectionStart is always 0 before setTimeout)
1177
+ e.persist();
1178
+ this.focusedElm = e.target;
1179
+ this.focusTimeout = setTimeout(function () {
1180
+ var el = e.target;
1181
+ var selectionStart = el.selectionStart;
1182
+ var selectionEnd = el.selectionEnd;
1183
+ var value = el.value;
1184
+ if (value === void 0) value = '';
1185
+ var caretPosition = this$1$1.correctCaretPosition(value, selectionStart);
1186
+
1187
+ //setPatchedCaretPosition only when everything is not selected on focus (while tabbing into the field)
1188
+ if (caretPosition !== selectionStart && !(selectionStart === 0 && selectionEnd === value.length)) {
1189
+ this$1$1.setPatchedCaretPosition(el, caretPosition, value);
1190
+ }
1191
+ this$1$1.props.onFocus(e);
1192
+ }, 0);
1193
+ };
1194
+ NumberFormat.prototype.render = function render() {
1195
+ var ref = this.props;
1196
+ var type = ref.type;
1197
+ var displayType = ref.displayType;
1198
+ var customInput = ref.customInput;
1199
+ var renderText = ref.renderText;
1200
+ var getInputRef = ref.getInputRef;
1201
+ var format = ref.format;
1202
+ ref.thousandSeparator;
1203
+ ref.decimalSeparator;
1204
+ ref.allowedDecimalSeparators;
1205
+ ref.thousandsGroupStyle;
1206
+ ref.decimalScale;
1207
+ ref.fixedDecimalScale;
1208
+ ref.prefix;
1209
+ ref.suffix;
1210
+ ref.removeFormatting;
1211
+ ref.mask;
1212
+ ref.defaultValue;
1213
+ ref.isNumericString;
1214
+ ref.allowNegative;
1215
+ ref.allowEmptyFormatting;
1216
+ ref.allowLeadingZeros;
1217
+ ref.onValueChange;
1218
+ ref.isAllowed;
1219
+ ref.customNumerals;
1220
+ ref.onChange;
1221
+ ref.onKeyDown;
1222
+ ref.onMouseUp;
1223
+ ref.onFocus;
1224
+ ref.onBlur;
1225
+ ref.value;
1226
+ var rest = objectWithoutProperties(ref, ['type', 'displayType', 'customInput', 'renderText', 'getInputRef', 'format', 'thousandSeparator', 'decimalSeparator', 'allowedDecimalSeparators', 'thousandsGroupStyle', 'decimalScale', 'fixedDecimalScale', 'prefix', 'suffix', 'removeFormatting', 'mask', 'defaultValue', 'isNumericString', 'allowNegative', 'allowEmptyFormatting', 'allowLeadingZeros', 'onValueChange', 'isAllowed', 'customNumerals', 'onChange', 'onKeyDown', 'onMouseUp', 'onFocus', 'onBlur', 'value']);
1227
+ var otherProps = rest;
1228
+ var ref$1 = this.state;
1229
+ var value = ref$1.value;
1230
+ var mounted = ref$1.mounted;
1231
+
1232
+ // add input mode on element based on format prop and device once the component is mounted
1233
+ var inputMode = mounted && addInputMode(format) ? 'numeric' : undefined;
1234
+ var inputProps = Object.assign({
1235
+ inputMode: inputMode
1236
+ }, otherProps, {
1237
+ type: type,
1238
+ value: value,
1239
+ onChange: this.onChange,
1240
+ onKeyDown: this.onKeyDown,
1241
+ onMouseUp: this.onMouseUp,
1242
+ onFocus: this.onFocus,
1243
+ onBlur: this.onBlur
1244
+ });
1245
+ if (displayType === 'text') {
1246
+ return renderText ? renderText(value, otherProps) || null : /*#__PURE__*/React__default.createElement('span', Object.assign({}, otherProps, {
1247
+ ref: getInputRef
1248
+ }), value);
1249
+ } else if (customInput) {
1250
+ var CustomInput = customInput;
1251
+ return /*#__PURE__*/React__default.createElement(CustomInput, Object.assign({}, inputProps, {
1252
+ ref: getInputRef
1253
+ }));
1254
+ }
1255
+ return /*#__PURE__*/React__default.createElement('input', Object.assign({}, inputProps, {
1256
+ ref: getInputRef
1257
+ }));
1258
+ };
1259
+ return NumberFormat;
1260
+ }(React__default.Component);
1261
+ NumberFormat.defaultProps = defaultProps;
1262
+
1263
+ export { NumberFormat as default };