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