@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.
- package/CHANGELOG.md +6 -0
- package/README.md +4 -4
- package/lib/cjs/InputNumber.js +277 -306
- package/lib/cjs/InputNumber.js.map +1 -1
- package/lib/cjs/buttons.js +19 -21
- package/lib/cjs/buttons.js.map +1 -1
- package/lib/cjs/index.d.js.map +1 -1
- package/lib/cjs/index.js +6 -6
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js +16 -16
- package/lib/cjs/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/es6/InputNumber.js +265 -294
- package/lib/es6/InputNumber.js.map +1 -1
- package/lib/es6/buttons.js +16 -20
- package/lib/es6/buttons.js.map +1 -1
- package/lib/es6/index.d.js.map +1 -1
- package/lib/es6/translations/__intergalactic-dynamic-locales.js +15 -15
- package/lib/es6/translations/__intergalactic-dynamic-locales.js.map +1 -1
- package/lib/esm/InputNumber.mjs +271 -254
- package/lib/esm/buttons.mjs +16 -20
- package/lib/esm/translations/__intergalactic-dynamic-locales.mjs +1 -1
- package/lib/types/index.d.ts +1 -9
- package/package.json +5 -5
package/lib/esm/InputNumber.mjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
11
|
+
const style = (
|
|
18
12
|
/*__reshadow_css_start__*/
|
|
19
13
|
(sstyled.insert(
|
|
20
14
|
/*__inner_css_start__*/
|
|
21
|
-
".
|
|
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
|
-
"
|
|
17
|
+
"1jona_gg_"
|
|
24
18
|
), /*__reshadow_css_end__*/
|
|
25
19
|
{
|
|
26
|
-
"__SValue": "
|
|
27
|
-
"__SControls": "
|
|
28
|
-
"_showControls": "
|
|
29
|
-
"__SUp": "
|
|
30
|
-
"__SDown": "
|
|
31
|
-
"_disabled": "
|
|
32
|
-
"__SValueHidden": "
|
|
33
|
-
"_type_number": "
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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(
|
|
55
|
-
var
|
|
56
|
-
(
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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(
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
104
|
+
let displayValue = "";
|
|
125
105
|
if (/\.[0-9]*0$/.test(stringNumber)) {
|
|
126
|
-
|
|
127
|
-
displayValue = numberFormatter.format(
|
|
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(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
130
|
+
this.handlers.value("", event);
|
|
143
131
|
} else {
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
154
|
-
|
|
141
|
+
const numberValueRounded = Number(numberValue.toFixed(roundCoefficient));
|
|
142
|
+
this.handlers.value(String(numberValueRounded), event);
|
|
155
143
|
}
|
|
156
144
|
});
|
|
157
|
-
_defineProperty(
|
|
158
|
-
callAllEventHandlers(
|
|
145
|
+
_defineProperty(this, "onWheel", (event) => {
|
|
146
|
+
callAllEventHandlers(this.asProps.onWheel, this.handleWheel)(event);
|
|
159
147
|
});
|
|
160
|
-
_defineProperty(
|
|
161
|
-
if (event.target !==
|
|
162
|
-
if (document.activeElement !==
|
|
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
|
-
|
|
153
|
+
this.stepUp(event);
|
|
166
154
|
} else if (event.wheelDelta < 0) {
|
|
167
|
-
|
|
155
|
+
this.stepDown(event);
|
|
168
156
|
}
|
|
169
157
|
});
|
|
170
|
-
_defineProperty(
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
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
|
-
|
|
173
|
+
this.handlers.displayValue(numberFormatter.format(value) + this.separatorDecimal);
|
|
183
174
|
return false;
|
|
184
175
|
} else {
|
|
185
|
-
|
|
176
|
+
this.handlers.value(value.slice(0, -1), event);
|
|
186
177
|
return false;
|
|
187
178
|
}
|
|
188
179
|
}
|
|
189
|
-
|
|
180
|
+
const digits = /^[0-9.-]+$/.test(value);
|
|
190
181
|
if (digits || value === "") {
|
|
191
|
-
|
|
182
|
+
this.handlers.value(value, event);
|
|
192
183
|
}
|
|
193
184
|
});
|
|
194
|
-
_defineProperty(
|
|
185
|
+
_defineProperty(this, "handleKeyUp", (event) => {
|
|
195
186
|
if (event.key === "Shift") {
|
|
196
|
-
|
|
187
|
+
this.cursorPosition = -1;
|
|
197
188
|
}
|
|
198
189
|
});
|
|
199
|
-
_defineProperty(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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(
|
|
198
|
+
if (value.indexOf(this.separatorDecimal) === -1 && event.key === ",") {
|
|
206
199
|
event.currentTarget.value = value + ".";
|
|
207
|
-
} else if (value.indexOf(
|
|
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(
|
|
206
|
+
if (event.key === "Backspace" && value.endsWith(this.separatorDecimal)) {
|
|
214
207
|
event.preventDefault();
|
|
215
208
|
event.stopPropagation();
|
|
216
|
-
|
|
209
|
+
this.handlers.displayValue(displayValue.slice(0, -1));
|
|
217
210
|
return false;
|
|
218
211
|
}
|
|
219
|
-
if (element.selectionStart !== length && (event.key === "Backspace" || event.key ===
|
|
220
|
-
|
|
221
|
-
requestAnimationFrame(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
230
|
-
if (event.shiftKey &&
|
|
231
|
-
|
|
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
|
-
|
|
229
|
+
this.moveSelectionLeft(element, cursorIndex);
|
|
237
230
|
break;
|
|
238
231
|
}
|
|
239
232
|
case "ArrowRight": {
|
|
240
233
|
event.preventDefault();
|
|
241
|
-
|
|
234
|
+
this.moveSelectionRight(element, cursorIndex);
|
|
242
235
|
break;
|
|
243
236
|
}
|
|
244
237
|
case "ArrowDown": {
|
|
245
238
|
event.preventDefault();
|
|
246
|
-
|
|
239
|
+
this.stepDown(event);
|
|
247
240
|
break;
|
|
248
241
|
}
|
|
249
242
|
case "ArrowUp": {
|
|
250
243
|
event.preventDefault();
|
|
251
|
-
|
|
244
|
+
this.stepUp(event);
|
|
252
245
|
break;
|
|
253
246
|
}
|
|
254
247
|
}
|
|
255
248
|
});
|
|
256
|
-
_defineProperty(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (
|
|
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 <=
|
|
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] ===
|
|
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(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (
|
|
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 >=
|
|
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] ===
|
|
273
|
+
element.setSelectionRange(value[element.selectionStart] === this.separatorThousands ? element.selectionStart + cursorIndex : element.selectionStart + 1, element.selectionEnd);
|
|
281
274
|
}
|
|
282
275
|
}
|
|
283
276
|
});
|
|
284
|
-
_defineProperty(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (value[element.selectionStart - 1] ===
|
|
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(
|
|
292
|
-
|
|
293
|
-
|
|
284
|
+
_defineProperty(this, "handleBlur", (event) => {
|
|
285
|
+
this.cursorPosition = -1;
|
|
286
|
+
this.handleValidation(event);
|
|
294
287
|
});
|
|
295
|
-
_defineProperty(
|
|
296
|
-
|
|
297
|
-
|
|
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
|
|
297
|
+
numberValue = min ?? 0;
|
|
300
298
|
} else {
|
|
301
299
|
numberValue = Number.parseFloat(value);
|
|
302
300
|
}
|
|
303
301
|
if (!Number.isNaN(numberValue)) {
|
|
304
|
-
|
|
305
|
-
|
|
302
|
+
const newValue = numberValue + step <= max ? numberValue + step : max;
|
|
303
|
+
this.handlers.value(newValue.toString(), event);
|
|
306
304
|
}
|
|
307
305
|
});
|
|
308
|
-
_defineProperty(
|
|
309
|
-
|
|
310
|
-
|
|
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
|
|
315
|
+
numberValue = max ?? 0;
|
|
313
316
|
} else {
|
|
314
317
|
numberValue = Number.parseFloat(value);
|
|
315
318
|
}
|
|
316
319
|
if (!Number.isNaN(numberValue)) {
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
384
|
-
value
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
|
457
|
+
const InputNumber_default = createComponent(InputNumber, {
|
|
441
458
|
Value,
|
|
442
459
|
Controls,
|
|
443
460
|
Addon: Input.Addon
|
|
444
461
|
});
|
|
445
462
|
export {
|
|
446
|
-
|
|
463
|
+
InputNumber_default as default,
|
|
447
464
|
parseValueWithMinMax
|
|
448
465
|
};
|