@semcore/input-number 16.0.11 → 17.0.0-prerelease.18

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