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