@semcore/input-number 16.0.11-prerelease.5 → 17.0.0-prerelease.17

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.
@@ -1,9 +1,3 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _objectSpread from "@babel/runtime/helpers/objectSpread2";
3
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/createClass";
5
- import _callSuper from "@babel/runtime/helpers/callSuper";
6
- import _inherits from "@babel/runtime/helpers/inherits";
7
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
2
  import { sstyled as _sstyled } from "@semcore/core";
9
3
  import { assignProps as _assignProps3 } from "@semcore/core";
@@ -17,80 +11,65 @@ import Input from '@semcore/input';
17
11
  import React from 'react';
18
12
  import { DecrementIcon, IncrementIcon } from './buttons';
19
13
  /*!__reshadow-styles__:"./style/input-number.shadow.css"*/
20
- var style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SValue_1npkq_gg_:focus~.___SControls_1npkq_gg_{display:flex}.___SControls_1npkq_gg_{display:none;flex-flow:column;justify-content:center;height:100%;box-sizing:border-box}.___SControls_1npkq_gg_.__showControls_1npkq_gg_{display:flex}.___SDown_1npkq_gg_,.___SUp_1npkq_gg_{padding:0;width:16px;color:var(--intergalactic-icon-secondary-neutral, #a9abb6);box-sizing:border-box;display:inline-flex;justify-content:center;border:0;background:0 0;cursor:pointer}.___SDown_1npkq_gg_:focus,.___SUp_1npkq_gg_:focus{outline:0}@media (hover:hover){.___SDown_1npkq_gg_:hover,.___SUp_1npkq_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active, #878992)}}.___SUp_1npkq_gg_{padding-bottom:1px}.___SDown_1npkq_gg_{padding-top:1px}.___SValue_1npkq_gg_::-webkit-inner-spin-button,.___SValue_1npkq_gg_::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.___SValue_1npkq_gg_._type_number_1npkq_gg_{-moz-appearance:textfield}.___SValue_1npkq_gg_.__disabled_1npkq_gg_~.___SControls_1npkq_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SValueHidden_1npkq_gg_{position:absolute;top:0;width:1px;height:1px;padding:0;overflow:hidden}", /*__inner_css_end__*/"1npkq_gg_"),
14
+ const style = (/*__reshadow_css_start__*/_sstyled.insert(/*__inner_css_start__*/".___SValue_1jona_gg_:focus~.___SControls_1jona_gg_{display:flex}.___SControls_1jona_gg_{display:none;flex-flow:column;justify-content:center;height:100%;box-sizing:border-box}.___SControls_1jona_gg_.__showControls_1jona_gg_{display:flex}.___SDown_1jona_gg_,.___SUp_1jona_gg_{padding:0;width:16px;color:var(--intergalactic-icon-secondary-neutral, #a9abb6);box-sizing:border-box;display:inline-flex;justify-content:center;border:0;background:0 0;cursor:pointer}.___SDown_1jona_gg_:focus,.___SUp_1jona_gg_:focus{outline:0}@media (hover:hover){.___SDown_1jona_gg_:hover,.___SUp_1jona_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active, #878992)}}.___SUp_1jona_gg_{padding-bottom:1px}.___SDown_1jona_gg_{padding-top:1px}.___SValue_1jona_gg_::-webkit-inner-spin-button,.___SValue_1jona_gg_::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.___SValue_1jona_gg_._type_number_1jona_gg_{-moz-appearance:textfield}.___SValue_1jona_gg_.__disabled_1jona_gg_~.___SControls_1jona_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SValueHidden_1jona_gg_{position:absolute;top:0;width:1px;height:1px;padding:0;overflow:hidden}", /*__inner_css_end__*/"1jona_gg_"),
21
15
  /*__reshadow_css_end__*/
22
16
  {
23
- "__SValue": "___SValue_1npkq_gg_",
24
- "__SControls": "___SControls_1npkq_gg_",
25
- "_showControls": "__showControls_1npkq_gg_",
26
- "__SUp": "___SUp_1npkq_gg_",
27
- "__SDown": "___SDown_1npkq_gg_",
28
- "_disabled": "__disabled_1npkq_gg_",
29
- "__SValueHidden": "___SValueHidden_1npkq_gg_",
30
- "_type_number": "_type_number_1npkq_gg_"
17
+ "__SValue": "___SValue_1jona_gg_",
18
+ "__SControls": "___SControls_1jona_gg_",
19
+ "_showControls": "__showControls_1jona_gg_",
20
+ "__SUp": "___SUp_1jona_gg_",
21
+ "__SDown": "___SDown_1jona_gg_",
22
+ "_disabled": "__disabled_1jona_gg_",
23
+ "__SValueHidden": "___SValueHidden_1jona_gg_",
24
+ "_type_number": "_type_number_1jona_gg_"
31
25
  });
32
26
  import { localizedMessages } from './translations/__intergalactic-dynamic-locales';
33
- export function parseValueWithMinMax(value) {
34
- var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Number.MIN_SAFE_INTEGER;
35
- var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Number.MAX_SAFE_INTEGER;
27
+ export function parseValueWithMinMax(value, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
36
28
  return Math.max(min, Math.min(max, value));
37
29
  }
38
- var InputNumber = /*#__PURE__*/function (_Component) {
39
- function InputNumber() {
40
- var _this;
41
- _classCallCheck(this, InputNumber);
42
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
43
- args[_key] = arguments[_key];
44
- }
45
- _this = _callSuper(this, InputNumber, [].concat(args));
46
- _defineProperty(_this, "inputRef", /*#__PURE__*/React.createRef());
47
- _defineProperty(_this, "increment", function (event) {
48
- var _this$inputRef$curren, _this$inputRef$curren2;
49
- (_this$inputRef$curren = _this.inputRef.current) === null || _this$inputRef$curren === void 0 || (_this$inputRef$curren2 = _this$inputRef$curren.stepUp) === null || _this$inputRef$curren2 === void 0 || _this$inputRef$curren2.call(_this$inputRef$curren, event);
30
+ class InputNumber extends Component {
31
+ constructor(...args) {
32
+ super(...args);
33
+ _defineProperty(this, "inputRef", /*#__PURE__*/React.createRef());
34
+ _defineProperty(this, "increment", event => {
35
+ this.inputRef.current?.stepUp?.(event);
50
36
  });
51
- _defineProperty(_this, "decrement", function (event) {
52
- var _this$inputRef$curren3, _this$inputRef$curren4;
53
- (_this$inputRef$curren3 = _this.inputRef.current) === null || _this$inputRef$curren3 === void 0 || (_this$inputRef$curren4 = _this$inputRef$curren3.stepDown) === null || _this$inputRef$curren4 === void 0 || _this$inputRef$curren4.call(_this$inputRef$curren3, event);
37
+ _defineProperty(this, "decrement", event => {
38
+ this.inputRef.current?.stepDown?.(event);
54
39
  });
55
- return _this;
56
40
  }
57
- _inherits(InputNumber, _Component);
58
- return _createClass(InputNumber, [{
59
- key: "getValueProps",
60
- value: function getValueProps() {
61
- var numberFormatter = new Intl.NumberFormat(this.asProps.locale, {
62
- style: 'decimal'
63
- });
64
- return {
65
- inputRef: this.inputRef,
66
- increment: this.increment,
67
- decrement: this.decrement,
68
- numberFormatter: numberFormatter
69
- };
70
- }
71
- }, {
72
- key: "getControlsProps",
73
- value: function getControlsProps() {
74
- var _this$asProps = this.asProps,
75
- size = _this$asProps.size,
76
- getI18nText = _this$asProps.getI18nText;
77
- return {
78
- size: size,
79
- increment: this.increment,
80
- decrement: this.decrement,
81
- getI18nText: getI18nText
82
- };
83
- }
84
- }, {
85
- key: "render",
86
- value: function render() {
87
- var _ref = this.asProps,
88
- _ref4;
89
- var SInputNumber = Input;
90
- return _ref4 = sstyled(this.asProps.style), /*#__PURE__*/React.createElement(SInputNumber, _ref4.cn("SInputNumber", _objectSpread({}, _assignProps({}, _ref))));
91
- }
92
- }]);
93
- }(Component);
41
+ getValueProps() {
42
+ const numberFormatter = new Intl.NumberFormat(this.asProps.locale, {
43
+ style: 'decimal'
44
+ });
45
+ return {
46
+ inputRef: this.inputRef,
47
+ increment: this.increment,
48
+ decrement: this.decrement,
49
+ numberFormatter
50
+ };
51
+ }
52
+ getControlsProps() {
53
+ const {
54
+ size,
55
+ getI18nText
56
+ } = this.asProps;
57
+ return {
58
+ size,
59
+ increment: this.increment,
60
+ decrement: this.decrement,
61
+ getI18nText
62
+ };
63
+ }
64
+ render() {
65
+ var _ref = this.asProps,
66
+ _ref4;
67
+ const SInputNumber = Input;
68
+ return _ref4 = sstyled(this.asProps.style), /*#__PURE__*/React.createElement(SInputNumber, _ref4.cn("SInputNumber", {
69
+ ..._assignProps({}, _ref)
70
+ }));
71
+ }
72
+ }
94
73
  _defineProperty(InputNumber, "displayName", 'InputNumber');
95
74
  _defineProperty(InputNumber, "style", style);
96
75
  _defineProperty(InputNumber, "enhance", [i18nEnhance(localizedMessages)]);
@@ -99,35 +78,29 @@ _defineProperty(InputNumber, "defaultProps", {
99
78
  i18n: localizedMessages,
100
79
  locale: 'en'
101
80
  });
102
- var Value = /*#__PURE__*/function (_Component2) {
103
- function Value() {
104
- var _this2;
105
- _classCallCheck(this, Value);
106
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
107
- args[_key2] = arguments[_key2];
108
- }
109
- _this2 = _callSuper(this, Value, [].concat(args));
110
- _defineProperty(_this2, "valueInputRef", /*#__PURE__*/React.createRef());
111
- _defineProperty(_this2, "cursorPosition", -1);
112
- _defineProperty(_this2, "getFormattedValue", function (value) {
113
- return value.replace(new RegExp("[".concat(_this2.separatorThousands, "]"), 'g'), '').replace(_this2.separatorDecimal, '.');
81
+ class Value extends Component {
82
+ constructor(...args) {
83
+ super(...args);
84
+ _defineProperty(this, "valueInputRef", /*#__PURE__*/React.createRef());
85
+ _defineProperty(this, "cursorPosition", -1);
86
+ _defineProperty(this, "getFormattedValue", value => {
87
+ return value.replace(new RegExp(`[${this.separatorThousands}]`, 'g'), '').replace(this.separatorDecimal, '.');
114
88
  });
115
- _defineProperty(_this2, "valueParser", function (value, prevValue, prevDisplayValue) {
116
- var numberFormatter = _this2.props.numberFormatter;
117
- var stringNumber = _this2.getFormattedValue(String(value));
89
+ _defineProperty(this, "valueParser", (value, prevValue, prevDisplayValue) => {
90
+ const {
91
+ numberFormatter
92
+ } = this.props;
93
+ const stringNumber = this.getFormattedValue(String(value));
118
94
  if (Number.isNaN(Number(stringNumber))) {
119
95
  return {
120
96
  parsedValue: prevValue,
121
97
  displayValue: prevDisplayValue
122
98
  };
123
99
  }
124
- var displayValue = '';
100
+ let displayValue = '';
125
101
  if (/\.[0-9]*0$/.test(stringNumber)) {
126
- var _stringNumber$split = stringNumber.split(_this2.separatorDecimal),
127
- _stringNumber$split2 = _slicedToArray(_stringNumber$split, 2),
128
- _int = _stringNumber$split2[0],
129
- decimal = _stringNumber$split2[1];
130
- displayValue = numberFormatter.format(_int) + _this2.separatorDecimal + decimal;
102
+ const [int, decimal] = stringNumber.split(this.separatorDecimal);
103
+ displayValue = numberFormatter.format(int) + this.separatorDecimal + decimal;
131
104
  } else if (stringNumber !== '') {
132
105
  displayValue = numberFormatter.format(stringNumber);
133
106
  }
@@ -136,22 +109,24 @@ var Value = /*#__PURE__*/function (_Component2) {
136
109
  displayValue: displayValue
137
110
  };
138
111
  });
139
- _defineProperty(_this2, "handleValidation", function (event) {
140
- var _this2$asProps = _this2.asProps,
141
- value = _this2$asProps.value,
142
- displayValue = _this2$asProps.displayValue,
143
- min = _this2$asProps.min,
144
- max = _this2$asProps.max,
145
- step = _this2$asProps.step;
146
- var _this2$valueParser = _this2.valueParser(event.currentTarget.value, value, displayValue),
147
- parsedValue = _this2$valueParser.parsedValue;
148
- var roundCoefficient = step < 1 ? step.toString().split('.')[1].length : 1;
112
+ _defineProperty(this, "handleValidation", event => {
113
+ const {
114
+ value,
115
+ displayValue,
116
+ min,
117
+ max,
118
+ step
119
+ } = this.asProps;
120
+ const {
121
+ parsedValue
122
+ } = this.valueParser(event.currentTarget.value, value, displayValue);
123
+ const roundCoefficient = step < 1 ? step.toString().split('.')[1].length : 1;
149
124
  if (Number.isNaN(value) || Number.isNaN(Number.parseFloat(parsedValue))) {
150
125
  event.currentTarget.value = '';
151
- _this2.handlers.value('', event);
126
+ this.handlers.value('', event);
152
127
  } else {
153
- var numberValue = parseValueWithMinMax(Number.parseFloat(parsedValue), min, max);
154
- var rounded = _this2.round(numberValue % step, step);
128
+ let numberValue = parseValueWithMinMax(Number.parseFloat(parsedValue), min, max);
129
+ const rounded = this.round(numberValue % step, step);
155
130
  if (rounded !== 0) {
156
131
  if (rounded >= step / 2) {
157
132
  numberValue += step - rounded;
@@ -159,30 +134,31 @@ var Value = /*#__PURE__*/function (_Component2) {
159
134
  numberValue -= rounded;
160
135
  }
161
136
  }
162
- var numberValueRounded = Number(numberValue.toFixed(roundCoefficient));
163
- _this2.handlers.value(String(numberValueRounded), event);
137
+ const numberValueRounded = Number(numberValue.toFixed(roundCoefficient));
138
+ this.handlers.value(String(numberValueRounded), event);
164
139
  }
165
140
  });
166
- _defineProperty(_this2, "onWheel", function (event) {
167
- callAllEventHandlers(_this2.asProps.onWheel, _this2.handleWheel)(event);
141
+ _defineProperty(this, "onWheel", event => {
142
+ callAllEventHandlers(this.asProps.onWheel, this.handleWheel)(event);
168
143
  });
169
- _defineProperty(_this2, "handleWheel", function (event) {
170
- if (event.target !== _this2.valueInputRef.current) return;
171
- if (document.activeElement !== _this2.valueInputRef.current) return;
144
+ _defineProperty(this, "handleWheel", event => {
145
+ if (event.target !== this.valueInputRef.current) return;
146
+ if (document.activeElement !== this.valueInputRef.current) return;
172
147
  event.preventDefault();
173
148
  if (event.wheelDelta > 0) {
174
- _this2.stepUp(event);
149
+ this.stepUp(event);
175
150
  } else if (event.wheelDelta < 0) {
176
- _this2.stepDown(event);
151
+ this.stepDown(event);
177
152
  }
178
153
  });
179
- _defineProperty(_this2, "handleChange", function (event) {
180
- var value = _this2.getFormattedValue(event.currentTarget.value);
181
- var _this2$asProps2 = _this2.asProps,
182
- numberFormatter = _this2$asProps2.numberFormatter,
183
- prevValue = _this2$asProps2.value;
154
+ _defineProperty(this, "handleChange", event => {
155
+ const value = this.getFormattedValue(event.currentTarget.value);
156
+ const {
157
+ numberFormatter,
158
+ value: prevValue
159
+ } = this.asProps;
184
160
  if (value === '.' || value === '-') {
185
- _this2.handlers.displayValue(value);
161
+ this.handlers.displayValue(value);
186
162
  return false;
187
163
  }
188
164
  if (value.endsWith('-')) {
@@ -190,52 +166,54 @@ var Value = /*#__PURE__*/function (_Component2) {
190
166
  }
191
167
  if (value.endsWith('.')) {
192
168
  if (value.length > prevValue.length) {
193
- _this2.handlers.displayValue(numberFormatter.format(value) + _this2.separatorDecimal);
169
+ this.handlers.displayValue(numberFormatter.format(value) + this.separatorDecimal);
194
170
  return false;
195
171
  } else {
196
- _this2.handlers.value(value.slice(0, -1), event);
172
+ this.handlers.value(value.slice(0, -1), event);
197
173
  return false;
198
174
  }
199
175
  }
200
- var digits = /^[0-9.-]+$/.test(value);
176
+ const digits = /^[0-9.-]+$/.test(value);
201
177
  if (digits || value === '') {
202
- _this2.handlers.value(value, event);
178
+ this.handlers.value(value, event);
203
179
  }
204
180
  });
205
- _defineProperty(_this2, "handleKeyUp", function (event) {
181
+ _defineProperty(this, "handleKeyUp", event => {
206
182
  if (event.key === 'Shift') {
207
- _this2.cursorPosition = -1;
183
+ this.cursorPosition = -1;
208
184
  }
209
185
  });
210
- _defineProperty(_this2, "handleKeyDown", function (event) {
211
- var element = event.currentTarget;
212
- var value = element.value;
213
- var length = value.length;
214
- var displayValue = _this2.asProps.displayValue;
186
+ _defineProperty(this, "handleKeyDown", event => {
187
+ const element = event.currentTarget;
188
+ const value = element.value;
189
+ const length = value.length;
190
+ const {
191
+ displayValue
192
+ } = this.asProps;
215
193
  if (event.key === '.' || event.key === ',') {
216
194
  // for the first decimal separator we should replace both ',' and '.' to '.' because of how js convert strings to numbers (with ',' it will be Number.NaN)
217
- if (value.indexOf(_this2.separatorDecimal) === -1 && event.key === ',') {
195
+ if (value.indexOf(this.separatorDecimal) === -1 && event.key === ',') {
218
196
  event.currentTarget.value = value + '.';
219
- } else if (value.indexOf(_this2.separatorDecimal) !== -1) {
197
+ } else if (value.indexOf(this.separatorDecimal) !== -1) {
220
198
  // we could press decimal separator second time - prevent this '1.5.'
221
199
  event.preventDefault();
222
200
  event.stopPropagation();
223
201
  return;
224
202
  }
225
203
  }
226
- if (event.key === 'Backspace' && value.endsWith(_this2.separatorDecimal)) {
204
+ if (event.key === 'Backspace' && value.endsWith(this.separatorDecimal)) {
227
205
  event.preventDefault();
228
206
  event.stopPropagation();
229
- _this2.handlers.displayValue(displayValue.slice(0, -1));
207
+ this.handlers.displayValue(displayValue.slice(0, -1));
230
208
  return false;
231
209
  }
232
- if (element.selectionStart !== length && (event.key === 'Backspace' || event.key === _this2.separatorDecimal || ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(event.key))) {
233
- var afterSelection = value.slice(element.selectionEnd);
234
- requestAnimationFrame(function () {
235
- var newValue = _this2.state.displayValue;
236
- var index = newValue.lastIndexOf(afterSelection);
237
- var selectionStart = index;
238
- var selectionEnd = index;
210
+ if (element.selectionStart !== length && (event.key === 'Backspace' || event.key === this.separatorDecimal || ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(event.key))) {
211
+ const afterSelection = value.slice(element.selectionEnd);
212
+ requestAnimationFrame(() => {
213
+ const newValue = this.state.displayValue;
214
+ const index = newValue.lastIndexOf(afterSelection);
215
+ const selectionStart = index;
216
+ const selectionEnd = index;
239
217
  element.setSelectionRange(selectionStart, selectionEnd);
240
218
  });
241
219
  }
@@ -244,205 +222,194 @@ var Value = /*#__PURE__*/function (_Component2) {
244
222
  // Examples:
245
223
  // - Press ArrowLeft: `12,3|4 -> 12|,34`
246
224
  // - Press ArrowRight: `1|,55 -> 1,5|5`
247
- var cursorIndex = 2;
248
- if (event.shiftKey && _this2.cursorPosition === -1) {
249
- _this2.cursorPosition = element.selectionStart;
225
+ const cursorIndex = 2;
226
+ if (event.shiftKey && this.cursorPosition === -1) {
227
+ this.cursorPosition = element.selectionStart;
250
228
  }
251
229
  switch (event.key) {
252
230
  case 'ArrowLeft':
253
231
  {
254
232
  event.preventDefault();
255
- _this2.moveSelectionLeft(element, cursorIndex);
233
+ this.moveSelectionLeft(element, cursorIndex);
256
234
  break;
257
235
  }
258
236
  case 'ArrowRight':
259
237
  {
260
238
  event.preventDefault();
261
- _this2.moveSelectionRight(element, cursorIndex);
239
+ this.moveSelectionRight(element, cursorIndex);
262
240
  break;
263
241
  }
264
242
  case 'ArrowDown':
265
243
  {
266
244
  event.preventDefault();
267
- _this2.stepDown(event);
245
+ this.stepDown(event);
268
246
  break;
269
247
  }
270
248
  case 'ArrowUp':
271
249
  {
272
250
  event.preventDefault();
273
- _this2.stepUp(event);
251
+ this.stepUp(event);
274
252
  break;
275
253
  }
276
254
  }
277
255
  });
278
- _defineProperty(_this2, "moveSelectionLeft", function (element, cursorIndex) {
279
- var value = element.value;
280
- var nextPosition = element.selectionStart - 1 >= 0 ? element.selectionStart - 1 : 0;
281
- var cursorPosition = value[element.selectionStart - cursorIndex] === _this2.separatorThousands ? element.selectionStart - cursorIndex : nextPosition;
282
- if (_this2.cursorPosition === -1) {
256
+ _defineProperty(this, "moveSelectionLeft", (element, cursorIndex) => {
257
+ const value = element.value;
258
+ const nextPosition = element.selectionStart - 1 >= 0 ? element.selectionStart - 1 : 0;
259
+ const cursorPosition = value[element.selectionStart - cursorIndex] === this.separatorThousands ? element.selectionStart - cursorIndex : nextPosition;
260
+ if (this.cursorPosition === -1) {
283
261
  // without shift
284
262
  element.setSelectionRange(cursorPosition, cursorPosition);
285
263
  } else {
286
- if (element.selectionStart <= _this2.cursorPosition && element.selectionEnd === _this2.cursorPosition) {
264
+ if (element.selectionStart <= this.cursorPosition && element.selectionEnd === this.cursorPosition) {
287
265
  element.setSelectionRange(cursorPosition, element.selectionEnd);
288
266
  } else {
289
- element.setSelectionRange(element.selectionStart, value[element.selectionEnd - cursorIndex] === _this2.separatorThousands ? element.selectionEnd - cursorIndex : element.selectionEnd - 1);
267
+ element.setSelectionRange(element.selectionStart, value[element.selectionEnd - cursorIndex] === this.separatorThousands ? element.selectionEnd - cursorIndex : element.selectionEnd - 1);
290
268
  }
291
269
  }
292
270
  });
293
- _defineProperty(_this2, "moveSelectionRight", function (element, cursorIndex) {
294
- var value = element.value;
295
- var nextPosition = element.selectionEnd + 1;
296
- var cursorPosition = value[element.selectionEnd] === _this2.separatorThousands ? element.selectionEnd + cursorIndex : nextPosition;
297
- if (_this2.cursorPosition === -1) {
271
+ _defineProperty(this, "moveSelectionRight", (element, cursorIndex) => {
272
+ const value = element.value;
273
+ const nextPosition = element.selectionEnd + 1;
274
+ const cursorPosition = value[element.selectionEnd] === this.separatorThousands ? element.selectionEnd + cursorIndex : nextPosition;
275
+ if (this.cursorPosition === -1) {
298
276
  // without shift
299
277
  element.setSelectionRange(cursorPosition, cursorPosition);
300
278
  } else {
301
- if (element.selectionEnd >= _this2.cursorPosition && element.selectionStart === _this2.cursorPosition) {
279
+ if (element.selectionEnd >= this.cursorPosition && element.selectionStart === this.cursorPosition) {
302
280
  element.setSelectionRange(element.selectionStart, cursorPosition);
303
281
  } else {
304
- element.setSelectionRange(value[element.selectionStart] === _this2.separatorThousands ? element.selectionStart + cursorIndex : element.selectionStart + 1, element.selectionEnd);
282
+ element.setSelectionRange(value[element.selectionStart] === this.separatorThousands ? element.selectionStart + cursorIndex : element.selectionStart + 1, element.selectionEnd);
305
283
  }
306
284
  }
307
285
  });
308
- _defineProperty(_this2, "handleClick", function (event) {
309
- var element = event.target;
310
- var value = element.value;
311
- if (value[element.selectionStart - 1] === _this2.separatorThousands) {
286
+ _defineProperty(this, "handleClick", event => {
287
+ const element = event.target;
288
+ const value = element.value;
289
+ if (value[element.selectionStart - 1] === this.separatorThousands) {
312
290
  element.setSelectionRange(element.selectionStart - 1, element.selectionEnd - 1);
313
291
  }
314
292
  });
315
- _defineProperty(_this2, "handleBlur", function (event) {
316
- _this2.cursorPosition = -1;
317
- _this2.handleValidation(event);
293
+ _defineProperty(this, "handleBlur", event => {
294
+ this.cursorPosition = -1;
295
+ this.handleValidation(event);
318
296
  });
319
- _defineProperty(_this2, "stepUp", function (event) {
320
- var _this2$asProps3 = _this2.asProps,
321
- _this2$asProps3$max = _this2$asProps3.max,
322
- max = _this2$asProps3$max === void 0 ? Number.MAX_SAFE_INTEGER : _this2$asProps3$max,
323
- min = _this2$asProps3.min,
324
- step = _this2$asProps3.step,
325
- value = _this2$asProps3.value;
326
- var numberValue;
297
+ _defineProperty(this, "stepUp", event => {
298
+ const {
299
+ max = Number.MAX_SAFE_INTEGER,
300
+ min,
301
+ step,
302
+ value
303
+ } = this.asProps;
304
+ let numberValue;
327
305
 
328
306
  // https://stackoverflow.com/questions/68010124/safari-number-input-stepup-stepdown-not-functioning-with-empty-value
329
307
  if (value === '') {
330
- numberValue = min !== null && min !== void 0 ? min : 0;
308
+ numberValue = min ?? 0;
331
309
  } else {
332
310
  numberValue = Number.parseFloat(value);
333
311
  }
334
312
  if (!Number.isNaN(numberValue)) {
335
- var newValue = numberValue + step <= max ? numberValue + step : max;
336
- _this2.handlers.value(newValue.toString(), event);
313
+ const newValue = numberValue + step <= max ? numberValue + step : max;
314
+ this.handlers.value(newValue.toString(), event);
337
315
  }
338
316
  });
339
- _defineProperty(_this2, "stepDown", function (event) {
340
- var _this2$asProps4 = _this2.asProps,
341
- max = _this2$asProps4.max,
342
- _this2$asProps4$min = _this2$asProps4.min,
343
- min = _this2$asProps4$min === void 0 ? Number.MIN_SAFE_INTEGER : _this2$asProps4$min,
344
- step = _this2$asProps4.step,
345
- value = _this2$asProps4.value;
346
- var numberValue;
317
+ _defineProperty(this, "stepDown", event => {
318
+ const {
319
+ max,
320
+ min = Number.MIN_SAFE_INTEGER,
321
+ step,
322
+ value
323
+ } = this.asProps;
324
+ let numberValue;
347
325
  if (value === '') {
348
- numberValue = max !== null && max !== void 0 ? max : 0;
326
+ numberValue = max ?? 0;
349
327
  } else {
350
328
  numberValue = Number.parseFloat(value);
351
329
  }
352
330
  if (!Number.isNaN(numberValue)) {
353
- var newValue = numberValue - step >= min ? numberValue - step : min;
354
- _this2.handlers.value(newValue.toString(), event);
331
+ const newValue = numberValue - step >= min ? numberValue - step : min;
332
+ this.handlers.value(newValue.toString(), event);
355
333
  }
356
334
  });
357
- return _this2;
358
335
  }
359
- _inherits(Value, _Component2);
360
- return _createClass(Value, [{
361
- key: "uncontrolledProps",
362
- value: function uncontrolledProps() {
363
- var _this3 = this;
364
- return {
365
- displayValue: null,
366
- value: [null, function (newValue) {
367
- var _this3$asProps = _this3.asProps,
368
- prevValue = _this3$asProps.value,
369
- prevDisplayValue = _this3$asProps.displayValue;
370
- var _this3$valueParser = _this3.valueParser(newValue, prevValue, prevDisplayValue),
371
- parsedValue = _this3$valueParser.parsedValue,
372
- displayValue = _this3$valueParser.displayValue;
373
- _this3.handlers.displayValue(displayValue);
374
- return parsedValue;
375
- }]
376
- };
377
- }
378
- }, {
379
- key: "separatorDecimal",
380
- get: function get() {
381
- var numberFormatter = this.props.numberFormatter;
382
- return numberFormatter.format(11.11).replace(/\d/g, '');
383
- }
384
- }, {
385
- key: "separatorThousands",
386
- get: function get() {
387
- var numberFormatter = this.props.numberFormatter;
388
- return numberFormatter.format(1111).replace(/\d/g, '');
389
- }
390
- }, {
391
- key: "round",
392
- value: function round(value, step) {
393
- var countDecimals = Math.floor(step) === step ? 0 : step.toString().split('.')[1].length || 0;
394
- return countDecimals === 0 ? Number.parseFloat(value) : Number.parseFloat(value).toPrecision(countDecimals);
395
- }
396
- }, {
397
- key: "componentDidMount",
398
- value:
399
- // https://stackoverflow.com/questions/57358640/cancel-wheel-event-with-e-preventdefault-in-react-event-bubbling
400
- function componentDidMount() {
401
- var _this$valueInputRef$c;
402
- (_this$valueInputRef$c = this.valueInputRef.current) === null || _this$valueInputRef$c === void 0 || _this$valueInputRef$c.addEventListener('wheel', this.onWheel);
403
- var _this$asProps2 = this.asProps,
404
- inputRef = _this$asProps2.inputRef,
405
- value = _this$asProps2.value;
406
- if (inputRef.current) {
407
- inputRef.current.stepUp = this.stepUp;
408
- inputRef.current.stepDown = this.stepDown;
409
- }
410
- if (value !== '') {
411
- var _this$valueParser = this.valueParser(value, '', ''),
412
- displayValue = _this$valueParser.displayValue;
336
+ uncontrolledProps() {
337
+ return {
338
+ displayValue: null,
339
+ value: [null, newValue => {
340
+ const {
341
+ value: prevValue,
342
+ displayValue: prevDisplayValue
343
+ } = this.asProps;
344
+ const {
345
+ parsedValue,
346
+ displayValue
347
+ } = this.valueParser(newValue, prevValue, prevDisplayValue);
413
348
  this.handlers.displayValue(displayValue);
414
- }
349
+ return parsedValue;
350
+ }]
351
+ };
352
+ }
353
+ get separatorDecimal() {
354
+ const {
355
+ numberFormatter
356
+ } = this.props;
357
+ return numberFormatter.format(11.11).replace(/\d/g, '');
358
+ }
359
+ get separatorThousands() {
360
+ const {
361
+ numberFormatter
362
+ } = this.props;
363
+ return numberFormatter.format(1111).replace(/\d/g, '');
364
+ }
365
+ round(value, step) {
366
+ const countDecimals = Math.floor(step) === step ? 0 : step.toString().split('.')[1].length || 0;
367
+ return countDecimals === 0 ? Number.parseFloat(value) : Number.parseFloat(value).toPrecision(countDecimals);
368
+ }
369
+ // https://stackoverflow.com/questions/57358640/cancel-wheel-event-with-e-preventdefault-in-react-event-bubbling
370
+ componentDidMount() {
371
+ this.valueInputRef.current?.addEventListener('wheel', this.onWheel);
372
+ const {
373
+ inputRef,
374
+ value
375
+ } = this.asProps;
376
+ if (inputRef.current) {
377
+ inputRef.current.stepUp = this.stepUp;
378
+ inputRef.current.stepDown = this.stepDown;
415
379
  }
416
- }, {
417
- key: "componentDidUpdate",
418
- value: function componentDidUpdate(prevProps) {
419
- if (prevProps.value !== this.props.value) {
420
- var _this$valueParser2 = this.valueParser(this.props.value, prevProps.value, prevProps.displayValue),
421
- displayValue = _this$valueParser2.displayValue;
422
- this.handlers.displayValue(displayValue);
423
- }
380
+ if (value !== '') {
381
+ const {
382
+ displayValue
383
+ } = this.valueParser(value, '', '');
384
+ this.handlers.displayValue(displayValue);
424
385
  }
425
- }, {
426
- key: "componentWillUnmount",
427
- value: function componentWillUnmount() {
428
- var _this$valueInputRef$c2;
429
- (_this$valueInputRef$c2 = this.valueInputRef.current) === null || _this$valueInputRef$c2 === void 0 || _this$valueInputRef$c2.removeEventListener('wheel', this.onWheel);
386
+ }
387
+ componentDidUpdate(prevProps) {
388
+ if (prevProps.value !== this.props.value) {
389
+ const {
390
+ displayValue
391
+ } = this.valueParser(this.props.value, prevProps.value, prevProps.displayValue);
392
+ this.handlers.displayValue(displayValue);
430
393
  }
431
- }, {
432
- key: "render",
433
- value: function render() {
434
- var _ref2 = this.asProps,
435
- _ref5;
436
- var SValue = Input.Value;
437
- var _this$asProps3 = this.asProps,
438
- styles = _this$asProps3.styles,
439
- min = _this$asProps3.min,
440
- max = _this$asProps3.max,
441
- step = _this$asProps3.step,
442
- forwardRef = _this$asProps3.forwardRef,
443
- inputRef = _this$asProps3.inputRef,
444
- displayValue = _this$asProps3.displayValue;
445
- return _ref5 = sstyled(styles), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SValue, _ref5.cn("SValue", _objectSpread({}, _assignProps2({
394
+ }
395
+ componentWillUnmount() {
396
+ this.valueInputRef.current?.removeEventListener('wheel', this.onWheel);
397
+ }
398
+ render() {
399
+ var _ref2 = this.asProps,
400
+ _ref5;
401
+ const SValue = Input.Value;
402
+ const {
403
+ styles,
404
+ min,
405
+ max,
406
+ step,
407
+ forwardRef,
408
+ inputRef,
409
+ displayValue
410
+ } = this.asProps;
411
+ return _ref5 = sstyled(styles), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SValue, _ref5.cn("SValue", {
412
+ ..._assignProps2({
446
413
  "autoComplete": 'off',
447
414
  "onBlur": this.handleValidation,
448
415
  "use:onChange": this.handleChange,
@@ -455,10 +422,10 @@ var Value = /*#__PURE__*/function (_Component2) {
455
422
  "min": min,
456
423
  "max": max,
457
424
  "step": step
458
- }, _ref2)))));
459
- }
460
- }]);
461
- }(Component);
425
+ }, _ref2)
426
+ })));
427
+ }
428
+ }
462
429
  _defineProperty(Value, "style", style);
463
430
  _defineProperty(Value, "defaultProps", {
464
431
  defaultValue: '',
@@ -468,18 +435,22 @@ _defineProperty(Value, "defaultProps", {
468
435
  function Controls(props) {
469
436
  var _ref3 = arguments[0],
470
437
  _ref6;
471
- var Children = props.Children,
472
- increment = props.increment,
473
- decrement = props.decrement,
474
- size = props.size,
475
- styles = props.styles,
476
- getI18nText = props.getI18nText;
477
- var SControls = Input.Addon;
478
- var SUp = 'button';
479
- var SDown = 'button';
480
- return _ref6 = sstyled(styles), /*#__PURE__*/React.createElement(SControls, _ref6.cn("SControls", _objectSpread({}, _assignProps3({
481
- "aria-hidden": 'true'
482
- }, _ref3))), /*#__PURE__*/React.createElement(SUp, _ref6.cn("SUp", {
438
+ const {
439
+ Children,
440
+ increment,
441
+ decrement,
442
+ size,
443
+ styles,
444
+ getI18nText
445
+ } = props;
446
+ const SControls = Input.Addon;
447
+ const SUp = 'button';
448
+ const SDown = 'button';
449
+ return _ref6 = sstyled(styles), /*#__PURE__*/React.createElement(SControls, _ref6.cn("SControls", {
450
+ ..._assignProps3({
451
+ "aria-hidden": 'true'
452
+ }, _ref3)
453
+ }), /*#__PURE__*/React.createElement(SUp, _ref6.cn("SUp", {
483
454
  "onClick": increment,
484
455
  "tabIndex": -1,
485
456
  "type": 'button',
@@ -495,8 +466,8 @@ function Controls(props) {
495
466
  }
496
467
  Controls.style = style;
497
468
  export default createComponent(InputNumber, {
498
- Value: Value,
499
- Controls: Controls,
469
+ Value,
470
+ Controls,
500
471
  Addon: Input.Addon
501
472
  });
502
473
  //# sourceMappingURL=InputNumber.js.map