@semcore/input-number 5.41.1-prerelease.8 → 16.0.0-prerelease.10

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,322 +1,450 @@
1
- import A from "@babel/runtime/helpers/esm/slicedToArray";
2
- import V from "@babel/runtime/helpers/esm/objectSpread2";
3
- import x from "@babel/runtime/helpers/esm/classCallCheck";
4
- import I from "@babel/runtime/helpers/esm/createClass";
5
- import d from "@babel/runtime/helpers/esm/assertThisInitialized";
6
- import C from "@babel/runtime/helpers/esm/inherits";
7
- import k from "@babel/runtime/helpers/esm/createSuper";
8
- import l from "@babel/runtime/helpers/esm/defineProperty";
9
- import { sstyled as M } from "@semcore/utils/lib/core/index";
10
- import z, { sstyled as D, assignProps as R, Component as $ } from "@semcore/core";
11
- import h from "react";
12
- import P from "@semcore/input";
13
- import { IncrementIcon as W, DecrementIcon as K } from "./buttons.mjs";
14
- import { localizedMessages as F } from "./translations/__intergalactic-dynamic-locales.mjs";
15
- import L from "@semcore/utils/lib/enhances/i18nEnhance";
16
- import { forkRef as B } from "@semcore/utils/lib/ref";
17
- import { callAllEventHandlers as G } from "@semcore/utils/lib/assignProps";
18
- var N = (
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 _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
7
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ import { createComponent, sstyled, assignProps, Component } from "@semcore/core";
10
+ import React from "react";
11
+ import Input from "@semcore/input";
12
+ import { IncrementIcon, DecrementIcon } from "./buttons.mjs";
13
+ import { localizedMessages } from "./translations/__intergalactic-dynamic-locales.mjs";
14
+ import i18nEnhance from "@semcore/core/lib/utils/enhances/i18nEnhance";
15
+ import { forkRef } from "@semcore/core/lib/utils/ref";
16
+ import { callAllEventHandlers } from "@semcore/core/lib/utils/assignProps";
17
+ var style = (
19
18
  /*__reshadow_css_start__*/
20
- (M.insert(
19
+ (sstyled.insert(
21
20
  /*__inner_css_start__*/
22
- ".___SValue_otw7a_gg_:focus~.___SControls_otw7a_gg_{display:flex}.___SControls_otw7a_gg_{display:none;flex-flow:column;justify-content:center;height:100%;box-sizing:border-box}.___SControls_otw7a_gg_.__showControls_otw7a_gg_{display:flex}.___SDown_otw7a_gg_,.___SUp_otw7a_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_otw7a_gg_:focus,.___SUp_otw7a_gg_:focus{outline:0}@media (hover:hover){.___SDown_otw7a_gg_:hover,.___SUp_otw7a_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active, #878992)}}.___SUp_otw7a_gg_{padding-bottom:1px}.___SDown_otw7a_gg_{padding-top:1px}.___SValue_otw7a_gg_::-webkit-inner-spin-button,.___SValue_otw7a_gg_::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.___SValue_otw7a_gg_._type_number_otw7a_gg_{-moz-appearance:textfield}.___SValue_otw7a_gg_.__disabled_otw7a_gg_~.___SControls_otw7a_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SValueHidden_otw7a_gg_{position:absolute;top:0;width:1px;height:1px;padding:0;overflow:hidden}",
23
- "otw7a_gg_"
21
+ ".___SValue_1l7h4_gg_:focus~.___SControls_1l7h4_gg_{display:flex}.___SControls_1l7h4_gg_{display:none;flex-flow:column;justify-content:center;height:100%;box-sizing:border-box}.___SControls_1l7h4_gg_.__showControls_1l7h4_gg_{display:flex}.___SDown_1l7h4_gg_,.___SUp_1l7h4_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_1l7h4_gg_:focus,.___SUp_1l7h4_gg_:focus{outline:0}@media (hover:hover){.___SDown_1l7h4_gg_:hover,.___SUp_1l7h4_gg_:hover{color:var(--intergalactic-icon-secondary-neutral-hover-active, #878992)}}.___SUp_1l7h4_gg_{padding-bottom:1px}.___SDown_1l7h4_gg_{padding-top:1px}.___SValue_1l7h4_gg_::-webkit-inner-spin-button,.___SValue_1l7h4_gg_::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.___SValue_1l7h4_gg_._type_number_1l7h4_gg_{-moz-appearance:textfield}.___SValue_1l7h4_gg_.__disabled_1l7h4_gg_~.___SControls_1l7h4_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SValueHidden_1l7h4_gg_{position:absolute;top:0;width:1px;height:1px;padding:0;overflow:hidden}",
22
+ "1l7h4_gg_"
24
23
  ), {
25
- __SValue: "___SValue_otw7a_gg_",
26
- __SControls: "___SControls_otw7a_gg_",
27
- _showControls: "__showControls_otw7a_gg_",
28
- __SUp: "___SUp_otw7a_gg_",
29
- __SDown: "___SDown_otw7a_gg_",
30
- _disabled: "__disabled_otw7a_gg_",
31
- __SValueHidden: "___SValueHidden_otw7a_gg_",
32
- _type_number: "_type_number_otw7a_gg_"
24
+ "__SValue": "___SValue_1l7h4_gg_",
25
+ "__SControls": "___SControls_1l7h4_gg_",
26
+ "_showControls": "__showControls_1l7h4_gg_",
27
+ "__SUp": "___SUp_1l7h4_gg_",
28
+ "__SDown": "___SDown_1l7h4_gg_",
29
+ "_disabled": "__disabled_1l7h4_gg_",
30
+ "__SValueHidden": "___SValueHidden_1l7h4_gg_",
31
+ "_type_number": "_type_number_1l7h4_gg_"
33
32
  })
34
33
  );
35
- function H(m) {
36
- var g = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Number.MIN_SAFE_INTEGER, c = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : Number.MAX_SAFE_INTEGER;
37
- return Math.max(g, Math.min(c, m));
34
+ function parseValueWithMinMax(value) {
35
+ var min = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Number.MIN_SAFE_INTEGER;
36
+ var max = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : Number.MAX_SAFE_INTEGER;
37
+ return Math.max(min, Math.min(max, value));
38
38
  }
39
- var b = /* @__PURE__ */ function(m) {
40
- C(c, m);
41
- var g = k(c);
42
- function c() {
43
- var t;
44
- x(this, c);
45
- for (var n = arguments.length, s = new Array(n), i = 0; i < n; i++)
46
- s[i] = arguments[i];
47
- return t = g.call.apply(g, [this].concat(s)), l(d(t), "inputRef", /* @__PURE__ */ h.createRef()), l(d(t), "increment", function(e) {
48
- var a, r;
49
- (a = t.inputRef.current) === null || a === void 0 || (r = a.stepUp) === null || r === void 0 || r.call(a, e);
50
- }), l(d(t), "decrement", function(e) {
51
- var a, r;
52
- (a = t.inputRef.current) === null || a === void 0 || (r = a.stepDown) === null || r === void 0 || r.call(a, e);
53
- }), t;
39
+ var InputNumber = /* @__PURE__ */ function(_Component) {
40
+ _inherits(InputNumber2, _Component);
41
+ var _super = _createSuper(InputNumber2);
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 = _super.call.apply(_super, [this].concat(args));
49
+ _defineProperty(_assertThisInitialized(_this), "inputRef", /* @__PURE__ */ React.createRef());
50
+ _defineProperty(_assertThisInitialized(_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 ? void 0 : (_this$inputRef$curren2 = _this$inputRef$curren.stepUp) === null || _this$inputRef$curren2 === void 0 ? void 0 : _this$inputRef$curren2.call(_this$inputRef$curren, event);
53
+ });
54
+ _defineProperty(_assertThisInitialized(_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 ? void 0 : (_this$inputRef$curren4 = _this$inputRef$curren3.stepDown) === null || _this$inputRef$curren4 === void 0 ? void 0 : _this$inputRef$curren4.call(_this$inputRef$curren3, event);
57
+ });
58
+ return _this;
54
59
  }
55
- return I(c, [{
60
+ _createClass(InputNumber2, [{
56
61
  key: "getValueProps",
57
- value: function() {
58
- var n = new Intl.NumberFormat(this.asProps.locale, {
62
+ value: function getValueProps() {
63
+ var numberFormatter = new Intl.NumberFormat(this.asProps.locale, {
59
64
  style: "decimal"
60
65
  });
61
66
  return {
62
67
  inputRef: this.inputRef,
63
68
  increment: this.increment,
64
69
  decrement: this.decrement,
65
- numberFormatter: n
70
+ numberFormatter
66
71
  };
67
72
  }
68
73
  }, {
69
74
  key: "getControlsProps",
70
- value: function() {
71
- var n = this.asProps, s = n.size, i = n.getI18nText;
75
+ value: function getControlsProps() {
76
+ var _this$asProps = this.asProps, size = _this$asProps.size, getI18nText = _this$asProps.getI18nText;
72
77
  return {
73
- size: s,
78
+ size,
74
79
  increment: this.increment,
75
80
  decrement: this.decrement,
76
- getI18nText: i
81
+ getI18nText
77
82
  };
78
83
  }
79
84
  }, {
80
85
  key: "render",
81
- value: function() {
82
- var n = this.asProps, s, i = P;
83
- return s = D(this.asProps.style), /* @__PURE__ */ h.createElement(i, s.cn("SInputNumber", V({}, R({}, n))));
86
+ value: function render() {
87
+ var _ref = this.asProps, _ref4;
88
+ var SInputNumber = Input;
89
+ return _ref4 = sstyled(this.asProps.style), /* @__PURE__ */ React.createElement(SInputNumber, _ref4.cn("SInputNumber", _objectSpread({}, assignProps({}, _ref))));
84
90
  }
85
- }]), c;
86
- }($);
87
- l(b, "displayName", "InputNumber");
88
- l(b, "style", N);
89
- l(b, "enhance", [L(F)]);
90
- l(b, "defaultProps", {
91
+ }]);
92
+ return InputNumber2;
93
+ }(Component);
94
+ _defineProperty(InputNumber, "displayName", "InputNumber");
95
+ _defineProperty(InputNumber, "style", style);
96
+ _defineProperty(InputNumber, "enhance", [i18nEnhance(localizedMessages)]);
97
+ _defineProperty(InputNumber, "defaultProps", {
91
98
  size: "m",
92
- i18n: F,
99
+ i18n: localizedMessages,
93
100
  locale: "en"
94
101
  });
95
- var E = /* @__PURE__ */ function(m) {
96
- C(c, m);
97
- var g = k(c);
98
- function c() {
99
- var t;
100
- x(this, c);
101
- for (var n = arguments.length, s = new Array(n), i = 0; i < n; i++)
102
- s[i] = arguments[i];
103
- return t = g.call.apply(g, [this].concat(s)), l(d(t), "valueInputRef", /* @__PURE__ */ h.createRef()), l(d(t), "cursorPosition", -1), l(d(t), "getFormattedValue", function(e) {
104
- return e.replace(new RegExp("[".concat(t.separatorThousands, "]"), "g"), "").replace(t.separatorDecimal, ".");
105
- }), l(d(t), "valueParser", function(e, a, r) {
106
- var u = t.props.numberFormatter, o = t.getFormattedValue(String(e));
107
- if (Number.isNaN(Number(o)))
102
+ var Value = /* @__PURE__ */ function(_Component2) {
103
+ _inherits(Value2, _Component2);
104
+ var _super2 = _createSuper(Value2);
105
+ function Value2() {
106
+ var _this2;
107
+ _classCallCheck(this, Value2);
108
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
109
+ args[_key2] = arguments[_key2];
110
+ }
111
+ _this2 = _super2.call.apply(_super2, [this].concat(args));
112
+ _defineProperty(_assertThisInitialized(_this2), "valueInputRef", /* @__PURE__ */ React.createRef());
113
+ _defineProperty(_assertThisInitialized(_this2), "cursorPosition", -1);
114
+ _defineProperty(_assertThisInitialized(_this2), "getFormattedValue", function(value) {
115
+ return value.replace(new RegExp("[".concat(_this2.separatorThousands, "]"), "g"), "").replace(_this2.separatorDecimal, ".");
116
+ });
117
+ _defineProperty(_assertThisInitialized(_this2), "valueParser", function(value, prevValue, prevDisplayValue) {
118
+ var numberFormatter = _this2.props.numberFormatter;
119
+ var stringNumber = _this2.getFormattedValue(String(value));
120
+ if (Number.isNaN(Number(stringNumber))) {
108
121
  return {
109
- parsedValue: a,
110
- displayValue: r
122
+ parsedValue: prevValue,
123
+ displayValue: prevDisplayValue
111
124
  };
112
- var f = "";
113
- if (/\.[0-9]*0$/.test(o)) {
114
- var p = o.split(t.separatorDecimal), _ = A(p, 2), v = _[0], S = _[1];
115
- f = u.format(v) + t.separatorDecimal + S;
116
- } else o !== "" && (f = u.format(o));
125
+ }
126
+ var displayValue = "";
127
+ if (/\.[0-9]*0$/.test(stringNumber)) {
128
+ var _stringNumber$split = stringNumber.split(_this2.separatorDecimal), _stringNumber$split2 = _slicedToArray(_stringNumber$split, 2), _int = _stringNumber$split2[0], decimal = _stringNumber$split2[1];
129
+ displayValue = numberFormatter.format(_int) + _this2.separatorDecimal + decimal;
130
+ } else if (stringNumber !== "") {
131
+ displayValue = numberFormatter.format(stringNumber);
132
+ }
117
133
  return {
118
- parsedValue: o,
119
- displayValue: f
134
+ parsedValue: stringNumber,
135
+ displayValue
120
136
  };
121
- }), l(d(t), "handleValidation", function(e) {
122
- var a = t.asProps, r = a.value, u = a.displayValue, o = a.min, f = a.max, p = a.step, _ = t.valueParser(e.currentTarget.value, r, u), v = _.parsedValue, S = p < 1 ? p.toString().split(".")[1].length : 1;
123
- if (Number.isNaN(r) || Number.isNaN(Number.parseFloat(v)))
124
- e.currentTarget.value = "", t.handlers.value("", e);
125
- else {
126
- var y = H(Number.parseFloat(v), o, f), w = t.round(y % p, p);
127
- w !== 0 && (w >= p / 2 ? y += p - w : Math.abs(w) < p && (y -= w));
128
- var U = Number(y.toFixed(S));
129
- t.handlers.value(String(U), e);
137
+ });
138
+ _defineProperty(_assertThisInitialized(_this2), "handleValidation", function(event) {
139
+ 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;
140
+ var _this2$valueParser = _this2.valueParser(event.currentTarget.value, value, displayValue), parsedValue = _this2$valueParser.parsedValue;
141
+ var roundCoefficient = step < 1 ? step.toString().split(".")[1].length : 1;
142
+ if (Number.isNaN(value) || Number.isNaN(Number.parseFloat(parsedValue))) {
143
+ event.currentTarget.value = "";
144
+ _this2.handlers.value("", event);
145
+ } else {
146
+ var numberValue = parseValueWithMinMax(Number.parseFloat(parsedValue), min, max);
147
+ var rounded = _this2.round(numberValue % step, step);
148
+ if (rounded !== 0) {
149
+ if (rounded >= step / 2) {
150
+ numberValue += step - rounded;
151
+ } else if (Math.abs(rounded) < step) {
152
+ numberValue -= rounded;
153
+ }
154
+ }
155
+ var numberValueRounded = Number(numberValue.toFixed(roundCoefficient));
156
+ _this2.handlers.value(String(numberValueRounded), event);
157
+ }
158
+ });
159
+ _defineProperty(_assertThisInitialized(_this2), "onWheel", function(event) {
160
+ callAllEventHandlers(_this2.asProps.onWheel, _this2.handleWheel)(event);
161
+ });
162
+ _defineProperty(_assertThisInitialized(_this2), "handleWheel", function(event) {
163
+ if (event.target !== _this2.valueInputRef.current) return;
164
+ if (document.activeElement !== _this2.valueInputRef.current) return;
165
+ event.preventDefault();
166
+ if (event.wheelDelta > 0) {
167
+ _this2.stepUp(event);
168
+ } else if (event.wheelDelta < 0) {
169
+ _this2.stepDown(event);
170
+ }
171
+ });
172
+ _defineProperty(_assertThisInitialized(_this2), "handleChange", function(event) {
173
+ var value = _this2.getFormattedValue(event.currentTarget.value);
174
+ var _this2$asProps2 = _this2.asProps, numberFormatter = _this2$asProps2.numberFormatter, prevValue = _this2$asProps2.value;
175
+ if (value === "." || value === "-") {
176
+ _this2.handlers.displayValue(value);
177
+ return false;
178
+ }
179
+ if (value.endsWith("-")) {
180
+ return false;
181
+ }
182
+ if (value.endsWith(".")) {
183
+ if (value.length > prevValue.length) {
184
+ _this2.handlers.displayValue(numberFormatter.format(value) + _this2.separatorDecimal);
185
+ return false;
186
+ } else {
187
+ _this2.handlers.value(value.slice(0, -1), event);
188
+ return false;
189
+ }
190
+ }
191
+ var digits = /[0-9.-]+/.test(value);
192
+ if (digits || value === "") {
193
+ _this2.handlers.value(value, event);
130
194
  }
131
- }), l(d(t), "onWheel", function(e) {
132
- G(t.asProps.onWheel, t.handleWheel)(e);
133
- }), l(d(t), "handleWheel", function(e) {
134
- e.target === t.valueInputRef.current && document.activeElement === t.valueInputRef.current && (e.preventDefault(), e.wheelDelta > 0 ? t.stepUp(e) : e.wheelDelta < 0 && t.stepDown(e));
135
- }), l(d(t), "handleChange", function(e) {
136
- var a = t.getFormattedValue(e.currentTarget.value), r = t.asProps, u = r.numberFormatter, o = r.value;
137
- if (a === "." || a === "-")
138
- return t.handlers.displayValue(a), !1;
139
- if (a.endsWith("-"))
140
- return !1;
141
- if (a.endsWith("."))
142
- return a.length > o.length ? (t.handlers.displayValue(u.format(a) + t.separatorDecimal), !1) : (t.handlers.value(a.slice(0, -1), e), !1);
143
- var f = /[0-9.-]+/.test(a);
144
- (f || a === "") && t.handlers.value(a, e);
145
- }), l(d(t), "handleKeyUp", function(e) {
146
- e.key === "Shift" && (t.cursorPosition = -1);
147
- }), l(d(t), "handleKeyDown", function(e) {
148
- var a = e.currentTarget, r = a.value, u = r.length, o = t.asProps.displayValue;
149
- if (e.key === "." || e.key === ",") {
150
- if (r.indexOf(t.separatorDecimal) === -1 && e.key === ",")
151
- e.currentTarget.value = r + ".";
152
- else if (r.indexOf(t.separatorDecimal) !== -1) {
153
- e.preventDefault(), e.stopPropagation();
195
+ });
196
+ _defineProperty(_assertThisInitialized(_this2), "handleKeyUp", function(event) {
197
+ if (event.key === "Shift") {
198
+ _this2.cursorPosition = -1;
199
+ }
200
+ });
201
+ _defineProperty(_assertThisInitialized(_this2), "handleKeyDown", function(event) {
202
+ var element = event.currentTarget;
203
+ var value = element.value;
204
+ var length = value.length;
205
+ var displayValue = _this2.asProps.displayValue;
206
+ if (event.key === "." || event.key === ",") {
207
+ if (value.indexOf(_this2.separatorDecimal) === -1 && event.key === ",") {
208
+ event.currentTarget.value = value + ".";
209
+ } else if (value.indexOf(_this2.separatorDecimal) !== -1) {
210
+ event.preventDefault();
211
+ event.stopPropagation();
154
212
  return;
155
213
  }
156
214
  }
157
- if (e.key === "Backspace" && r.endsWith(t.separatorDecimal))
158
- return e.preventDefault(), e.stopPropagation(), t.handlers.displayValue(o.slice(0, -1)), !1;
159
- if (a.selectionStart !== u && (e.key === "Backspace" || e.key === t.separatorDecimal || ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].includes(e.key))) {
160
- var f = r.slice(a.selectionEnd);
215
+ if (event.key === "Backspace" && value.endsWith(_this2.separatorDecimal)) {
216
+ event.preventDefault();
217
+ event.stopPropagation();
218
+ _this2.handlers.displayValue(displayValue.slice(0, -1));
219
+ return false;
220
+ }
221
+ if (element.selectionStart !== length && (event.key === "Backspace" || event.key === _this2.separatorDecimal || ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].includes(event.key))) {
222
+ var afterSelection = value.slice(element.selectionEnd);
161
223
  requestAnimationFrame(function() {
162
- var _ = t.state.displayValue, v = _.lastIndexOf(f), S = v, y = v;
163
- a.setSelectionRange(S, y);
224
+ var newValue = _this2.state.displayValue;
225
+ var index = newValue.lastIndexOf(afterSelection);
226
+ var selectionStart = index;
227
+ var selectionEnd = index;
228
+ element.setSelectionRange(selectionStart, selectionEnd);
164
229
  });
165
230
  }
166
- var p = 2;
167
- switch (e.shiftKey && t.cursorPosition === -1 && (t.cursorPosition = a.selectionStart), e.key) {
231
+ var cursorIndex = 2;
232
+ if (event.shiftKey && _this2.cursorPosition === -1) {
233
+ _this2.cursorPosition = element.selectionStart;
234
+ }
235
+ switch (event.key) {
168
236
  case "ArrowLeft": {
169
- e.preventDefault(), t.moveSelectionLeft(a, p);
237
+ event.preventDefault();
238
+ _this2.moveSelectionLeft(element, cursorIndex);
170
239
  break;
171
240
  }
172
241
  case "ArrowRight": {
173
- e.preventDefault(), t.moveSelectionRight(a, p);
242
+ event.preventDefault();
243
+ _this2.moveSelectionRight(element, cursorIndex);
174
244
  break;
175
245
  }
176
246
  case "ArrowDown": {
177
- e.preventDefault(), t.stepDown(e);
247
+ event.preventDefault();
248
+ _this2.stepDown(event);
178
249
  break;
179
250
  }
180
251
  case "ArrowUp": {
181
- e.preventDefault(), t.stepUp(e);
252
+ event.preventDefault();
253
+ _this2.stepUp(event);
182
254
  break;
183
255
  }
184
256
  }
185
- }), l(d(t), "moveSelectionLeft", function(e, a) {
186
- var r = e.value, u = e.selectionStart - 1 >= 0 ? e.selectionStart - 1 : 0, o = r[e.selectionStart - a] === t.separatorThousands ? e.selectionStart - a : u;
187
- t.cursorPosition === -1 ? e.setSelectionRange(o, o) : e.selectionStart <= t.cursorPosition && e.selectionEnd === t.cursorPosition ? e.setSelectionRange(o, e.selectionEnd) : e.setSelectionRange(e.selectionStart, r[e.selectionEnd - a] === t.separatorThousands ? e.selectionEnd - a : e.selectionEnd - 1);
188
- }), l(d(t), "moveSelectionRight", function(e, a) {
189
- var r = e.value, u = e.selectionEnd + 1, o = r[e.selectionEnd] === t.separatorThousands ? e.selectionEnd + a : u;
190
- t.cursorPosition === -1 ? e.setSelectionRange(o, o) : e.selectionEnd >= t.cursorPosition && e.selectionStart === t.cursorPosition ? e.setSelectionRange(e.selectionStart, o) : e.setSelectionRange(r[e.selectionStart] === t.separatorThousands ? e.selectionStart + a : e.selectionStart + 1, e.selectionEnd);
191
- }), l(d(t), "handleClick", function(e) {
192
- var a = e.target, r = a.value;
193
- r[a.selectionStart - 1] === t.separatorThousands && a.setSelectionRange(a.selectionStart - 1, a.selectionEnd - 1);
194
- }), l(d(t), "handleBlur", function(e) {
195
- t.cursorPosition = -1, t.handleValidation(e);
196
- }), l(d(t), "stepUp", function(e) {
197
- var a = t.asProps, r = a.max, u = r === void 0 ? Number.MAX_SAFE_INTEGER : r, o = a.min, f = a.step, p = a.value, _;
198
- if (p === "" ? _ = o ?? 0 : _ = Number.parseFloat(p), !Number.isNaN(_)) {
199
- var v = _ + f <= u ? _ + f : u;
200
- t.handlers.value(v.toString(), e);
257
+ });
258
+ _defineProperty(_assertThisInitialized(_this2), "moveSelectionLeft", function(element, cursorIndex) {
259
+ var value = element.value;
260
+ var nextPosition = element.selectionStart - 1 >= 0 ? element.selectionStart - 1 : 0;
261
+ var cursorPosition = value[element.selectionStart - cursorIndex] === _this2.separatorThousands ? element.selectionStart - cursorIndex : nextPosition;
262
+ if (_this2.cursorPosition === -1) {
263
+ element.setSelectionRange(cursorPosition, cursorPosition);
264
+ } else {
265
+ if (element.selectionStart <= _this2.cursorPosition && element.selectionEnd === _this2.cursorPosition) {
266
+ element.setSelectionRange(cursorPosition, element.selectionEnd);
267
+ } else {
268
+ element.setSelectionRange(element.selectionStart, value[element.selectionEnd - cursorIndex] === _this2.separatorThousands ? element.selectionEnd - cursorIndex : element.selectionEnd - 1);
269
+ }
270
+ }
271
+ });
272
+ _defineProperty(_assertThisInitialized(_this2), "moveSelectionRight", function(element, cursorIndex) {
273
+ var value = element.value;
274
+ var nextPosition = element.selectionEnd + 1;
275
+ var cursorPosition = value[element.selectionEnd] === _this2.separatorThousands ? element.selectionEnd + cursorIndex : nextPosition;
276
+ if (_this2.cursorPosition === -1) {
277
+ element.setSelectionRange(cursorPosition, cursorPosition);
278
+ } else {
279
+ if (element.selectionEnd >= _this2.cursorPosition && element.selectionStart === _this2.cursorPosition) {
280
+ element.setSelectionRange(element.selectionStart, cursorPosition);
281
+ } else {
282
+ element.setSelectionRange(value[element.selectionStart] === _this2.separatorThousands ? element.selectionStart + cursorIndex : element.selectionStart + 1, element.selectionEnd);
283
+ }
201
284
  }
202
- }), l(d(t), "stepDown", function(e) {
203
- var a = t.asProps, r = a.max, u = a.min, o = u === void 0 ? Number.MIN_SAFE_INTEGER : u, f = a.step, p = a.value, _;
204
- if (p === "" ? _ = r ?? 0 : _ = Number.parseFloat(p), !Number.isNaN(_)) {
205
- var v = _ - f >= o ? _ - f : o;
206
- t.handlers.value(v.toString(), e);
285
+ });
286
+ _defineProperty(_assertThisInitialized(_this2), "handleClick", function(event) {
287
+ var element = event.target;
288
+ var value = element.value;
289
+ if (value[element.selectionStart - 1] === _this2.separatorThousands) {
290
+ element.setSelectionRange(element.selectionStart - 1, element.selectionEnd - 1);
207
291
  }
208
- }), t;
292
+ });
293
+ _defineProperty(_assertThisInitialized(_this2), "handleBlur", function(event) {
294
+ _this2.cursorPosition = -1;
295
+ _this2.handleValidation(event);
296
+ });
297
+ _defineProperty(_assertThisInitialized(_this2), "stepUp", function(event) {
298
+ 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;
299
+ var numberValue;
300
+ if (value === "") {
301
+ numberValue = min !== null && min !== void 0 ? min : 0;
302
+ } else {
303
+ numberValue = Number.parseFloat(value);
304
+ }
305
+ if (!Number.isNaN(numberValue)) {
306
+ var newValue = numberValue + step <= max ? numberValue + step : max;
307
+ _this2.handlers.value(newValue.toString(), event);
308
+ }
309
+ });
310
+ _defineProperty(_assertThisInitialized(_this2), "stepDown", function(event) {
311
+ 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;
312
+ var numberValue;
313
+ if (value === "") {
314
+ numberValue = max !== null && max !== void 0 ? max : 0;
315
+ } else {
316
+ numberValue = Number.parseFloat(value);
317
+ }
318
+ if (!Number.isNaN(numberValue)) {
319
+ var newValue = numberValue - step >= min ? numberValue - step : min;
320
+ _this2.handlers.value(newValue.toString(), event);
321
+ }
322
+ });
323
+ return _this2;
209
324
  }
210
- return I(c, [{
325
+ _createClass(Value2, [{
211
326
  key: "uncontrolledProps",
212
- value: function() {
213
- var n = this;
327
+ value: function uncontrolledProps() {
328
+ var _this3 = this;
214
329
  return {
215
330
  displayValue: null,
216
- value: [null, function(s) {
217
- var i = n.asProps, e = i.value, a = i.displayValue, r = n.valueParser(s, e, a), u = r.parsedValue, o = r.displayValue;
218
- return n.handlers.displayValue(o), u;
331
+ value: [null, function(newValue) {
332
+ var _this3$asProps = _this3.asProps, prevValue = _this3$asProps.value, prevDisplayValue = _this3$asProps.displayValue;
333
+ var _this3$valueParser = _this3.valueParser(newValue, prevValue, prevDisplayValue), parsedValue = _this3$valueParser.parsedValue, displayValue = _this3$valueParser.displayValue;
334
+ _this3.handlers.displayValue(displayValue);
335
+ return parsedValue;
219
336
  }]
220
337
  };
221
338
  }
222
339
  }, {
223
340
  key: "separatorDecimal",
224
- get: function() {
225
- var n = this.props.numberFormatter;
226
- return n.format(11.11).replace(/\d/g, "");
341
+ get: function get() {
342
+ var numberFormatter = this.props.numberFormatter;
343
+ return numberFormatter.format(11.11).replace(/\d/g, "");
227
344
  }
228
345
  }, {
229
346
  key: "separatorThousands",
230
- get: function() {
231
- var n = this.props.numberFormatter;
232
- return n.format(1111).replace(/\d/g, "");
347
+ get: function get() {
348
+ var numberFormatter = this.props.numberFormatter;
349
+ return numberFormatter.format(1111).replace(/\d/g, "");
233
350
  }
234
351
  }, {
235
352
  key: "round",
236
- value: function(n, s) {
237
- var i = Math.floor(s) === s ? 0 : s.toString().split(".")[1].length || 0;
238
- return i === 0 ? Number.parseFloat(n) : Number.parseFloat(n).toPrecision(i);
353
+ value: function round(value, step) {
354
+ var countDecimals = Math.floor(step) === step ? 0 : step.toString().split(".")[1].length || 0;
355
+ return countDecimals === 0 ? Number.parseFloat(value) : Number.parseFloat(value).toPrecision(countDecimals);
239
356
  }
240
357
  }, {
241
358
  key: "componentDidMount",
242
359
  value: (
243
360
  // https://stackoverflow.com/questions/57358640/cancel-wheel-event-with-e-preventdefault-in-react-event-bubbling
244
- function() {
245
- var n;
246
- (n = this.valueInputRef.current) === null || n === void 0 || n.addEventListener("wheel", this.onWheel);
247
- var s = this.asProps, i = s.inputRef, e = s.value;
248
- if (i.current && (i.current.stepUp = this.stepUp, i.current.stepDown = this.stepDown), e !== "") {
249
- var a = this.valueParser(e, "", ""), r = a.displayValue;
250
- this.handlers.displayValue(r);
361
+ function componentDidMount() {
362
+ var _this$valueInputRef$c;
363
+ (_this$valueInputRef$c = this.valueInputRef.current) === null || _this$valueInputRef$c === void 0 ? void 0 : _this$valueInputRef$c.addEventListener("wheel", this.onWheel);
364
+ var _this$asProps2 = this.asProps, inputRef = _this$asProps2.inputRef, value = _this$asProps2.value;
365
+ if (inputRef.current) {
366
+ inputRef.current.stepUp = this.stepUp;
367
+ inputRef.current.stepDown = this.stepDown;
368
+ }
369
+ if (value !== "") {
370
+ var _this$valueParser = this.valueParser(value, "", ""), displayValue = _this$valueParser.displayValue;
371
+ this.handlers.displayValue(displayValue);
251
372
  }
252
373
  }
253
374
  )
254
375
  }, {
255
376
  key: "componentDidUpdate",
256
- value: function(n) {
257
- if (n.value !== this.props.value) {
258
- var s = this.valueParser(this.props.value, n.value, n.displayValue), i = s.displayValue;
259
- this.handlers.displayValue(i);
377
+ value: function componentDidUpdate(prevProps) {
378
+ if (prevProps.value !== this.props.value) {
379
+ var _this$valueParser2 = this.valueParser(this.props.value, prevProps.value, prevProps.displayValue), displayValue = _this$valueParser2.displayValue;
380
+ this.handlers.displayValue(displayValue);
260
381
  }
261
382
  }
262
383
  }, {
263
384
  key: "componentWillUnmount",
264
- value: function() {
265
- var n;
266
- (n = this.valueInputRef.current) === null || n === void 0 || n.removeEventListener("wheel", this.onWheel);
385
+ value: function componentWillUnmount() {
386
+ var _this$valueInputRef$c2;
387
+ (_this$valueInputRef$c2 = this.valueInputRef.current) === null || _this$valueInputRef$c2 === void 0 ? void 0 : _this$valueInputRef$c2.removeEventListener("wheel", this.onWheel);
267
388
  }
268
389
  }, {
269
390
  key: "render",
270
- value: function() {
271
- var n = this.asProps, s, i = P.Value, e = this.asProps, a = e.styles, r = e.min, u = e.max, o = e.step, f = e.forwardRef, p = e.inputRef, _ = e.displayValue;
272
- return s = D(a), /* @__PURE__ */ h.createElement(h.Fragment, null, /* @__PURE__ */ h.createElement(i, s.cn("SValue", V({}, R({
273
- autoComplete: "off",
274
- onBlur: this.handleValidation,
391
+ value: function render() {
392
+ var _ref2 = this.asProps, _ref5;
393
+ var SValue = Input.Value;
394
+ 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;
395
+ return _ref5 = sstyled(styles), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SValue, _ref5.cn("SValue", _objectSpread({}, assignProps({
396
+ "autoComplete": "off",
397
+ "onBlur": this.handleValidation,
275
398
  "use:onChange": this.handleChange,
276
- onKeyDown: this.handleKeyDown,
277
- onKeyUp: this.handleKeyUp,
278
- onClick: this.handleClick,
279
- "use:ref": B(this.valueInputRef, p, f),
280
- "use:value": _,
281
- inputMode: Number.isInteger(o) ? "numeric" : "decimal",
282
- min: r,
283
- max: u,
284
- step: o
285
- }, n)))));
399
+ "onKeyDown": this.handleKeyDown,
400
+ "onKeyUp": this.handleKeyUp,
401
+ "onClick": this.handleClick,
402
+ "use:ref": forkRef(this.valueInputRef, inputRef, forwardRef),
403
+ "use:value": displayValue,
404
+ "inputMode": Number.isInteger(step) ? "numeric" : "decimal",
405
+ "min": min,
406
+ "max": max,
407
+ "step": step
408
+ }, _ref2)))));
286
409
  }
287
- }]), c;
288
- }($);
289
- l(E, "style", N);
290
- l(E, "defaultProps", {
410
+ }]);
411
+ return Value2;
412
+ }(Component);
413
+ _defineProperty(Value, "style", style);
414
+ _defineProperty(Value, "defaultProps", {
291
415
  defaultValue: "",
292
416
  defaultDisplayValue: "",
293
417
  step: 1
294
418
  });
295
- function T(m) {
296
- var g = arguments[0], c, t = m.Children, n = m.increment, s = m.decrement, i = m.size, e = m.styles, a = m.getI18nText, r = P.Addon, u = "button", o = "button";
297
- return c = D(e), /* @__PURE__ */ h.createElement(r, c.cn("SControls", V({}, R({
419
+ function Controls(props) {
420
+ var _ref3 = arguments[0], _ref6;
421
+ var Children = props.Children, increment = props.increment, decrement = props.decrement, size = props.size, styles = props.styles, getI18nText = props.getI18nText;
422
+ var SControls = Input.Addon;
423
+ var SUp = "button";
424
+ var SDown = "button";
425
+ return _ref6 = sstyled(styles), /* @__PURE__ */ React.createElement(SControls, _ref6.cn("SControls", _objectSpread({}, assignProps({
298
426
  "aria-hidden": "true"
299
- }, g))), /* @__PURE__ */ h.createElement(u, c.cn("SUp", {
300
- onClick: n,
301
- tabIndex: -1,
302
- type: "button",
303
- size: i,
304
- "aria-label": a("increment")
305
- }), /* @__PURE__ */ h.createElement(W, c.cn("IncrementIcon", {}))), /* @__PURE__ */ h.createElement(o, c.cn("SDown", {
306
- onClick: s,
307
- tabIndex: -1,
308
- type: "button",
309
- size: i,
310
- "aria-label": a("decrement")
311
- }), /* @__PURE__ */ h.createElement(K, c.cn("DecrementIcon", {}))), /* @__PURE__ */ h.createElement(t, c.cn("Children", {})));
427
+ }, _ref3))), /* @__PURE__ */ React.createElement(SUp, _ref6.cn("SUp", {
428
+ "onClick": increment,
429
+ "tabIndex": -1,
430
+ "type": "button",
431
+ "size": size,
432
+ "aria-label": getI18nText("increment")
433
+ }), /* @__PURE__ */ React.createElement(IncrementIcon, _ref6.cn("IncrementIcon", {}))), /* @__PURE__ */ React.createElement(SDown, _ref6.cn("SDown", {
434
+ "onClick": decrement,
435
+ "tabIndex": -1,
436
+ "type": "button",
437
+ "size": size,
438
+ "aria-label": getI18nText("decrement")
439
+ }), /* @__PURE__ */ React.createElement(DecrementIcon, _ref6.cn("DecrementIcon", {}))), /* @__PURE__ */ React.createElement(Children, _ref6.cn("Children", {})));
312
440
  }
313
- T.style = N;
314
- const ue = z(b, {
315
- Value: E,
316
- Controls: T,
317
- Addon: P.Addon
441
+ Controls.style = style;
442
+ const InputNumber$1 = createComponent(InputNumber, {
443
+ Value,
444
+ Controls,
445
+ Addon: Input.Addon
318
446
  });
319
447
  export {
320
- ue as default,
321
- H as parseValueWithMinMax
448
+ InputNumber$1 as default,
449
+ parseValueWithMinMax
322
450
  };