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