tgui-core 1.2.0 → 1.3.1
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/README.md +3 -3
- package/dist/common/color.js +31 -30
- package/dist/common/events.js +5 -5
- package/dist/common/format.js +27 -27
- package/dist/common/hotkeys.d.ts +0 -1
- package/dist/common/hotkeys.js +2 -2
- package/dist/common/math.d.ts +4 -0
- package/dist/common/math.js +29 -25
- package/dist/common/random.js +14 -13
- package/dist/common/react.js +1 -1
- package/dist/common/string.js +9 -9
- package/dist/common/type-utils.d.ts +1 -1
- package/dist/components/AnimatedNumber.d.ts +6 -6
- package/dist/components/AnimatedNumber.js +14 -17
- package/dist/components/Autofocus.d.ts +0 -1
- package/dist/components/Blink.d.ts +0 -1
- package/dist/components/BlockQuote.d.ts +0 -1
- package/dist/components/BlockQuote.js +4 -7
- package/dist/components/Box.d.ts +0 -1
- package/dist/components/Box.js +4 -4
- package/dist/components/Button.d.ts +0 -1
- package/dist/components/Button.js +173 -211
- package/dist/components/ByondUi.js +3 -3
- package/dist/components/Chart.d.ts +0 -1
- package/dist/components/Chart.js +25 -22
- package/dist/components/Collapsible.d.ts +0 -1
- package/dist/components/ColorBox.d.ts +0 -1
- package/dist/components/ColorBox.js +7 -14
- package/dist/components/Dialog.js +31 -40
- package/dist/components/Dimmer.d.ts +0 -1
- package/dist/components/Dimmer.js +6 -9
- package/dist/components/Divider.js +10 -14
- package/dist/components/DmIcon.d.ts +0 -1
- package/dist/components/DraggableControl.js +57 -49
- package/dist/components/Dropdown.d.ts +0 -1
- package/dist/components/Dropdown.js +73 -67
- package/dist/components/FitText.d.ts +0 -1
- package/dist/components/Flex.d.ts +1 -1
- package/dist/components/Flex.js +39 -41
- package/dist/components/Icon.d.ts +0 -1
- package/dist/components/Icon.js +27 -34
- package/dist/components/Image.d.ts +0 -1
- package/dist/components/Image.js +7 -6
- package/dist/components/ImageButton.d.ts +0 -1
- package/dist/components/ImageButton.js +87 -170
- package/dist/components/InfinitePlane.js +1 -1
- package/dist/components/Input.d.ts +0 -1
- package/dist/components/Input.js +57 -64
- package/dist/components/KeyListener.d.ts +0 -1
- package/dist/components/Knob.d.ts +0 -1
- package/dist/components/Knob.js +91 -117
- package/dist/components/LabeledControls.d.ts +0 -1
- package/dist/components/LabeledList.d.ts +0 -1
- package/dist/components/LabeledList.js +48 -55
- package/dist/components/MenuBar.d.ts +0 -1
- package/dist/components/MenuBar.js +93 -102
- package/dist/components/Modal.d.ts +0 -1
- package/dist/components/Modal.js +11 -18
- package/dist/components/NoticeBox.d.ts +0 -1
- package/dist/components/NoticeBox.js +16 -43
- package/dist/components/NumberInput.d.ts +0 -2
- package/dist/components/NumberInput.js +99 -107
- package/dist/components/Popper.d.ts +0 -1
- package/dist/components/ProgressBar.d.ts +0 -1
- package/dist/components/ProgressBar.js +22 -27
- package/dist/components/RestrictedInput.js +64 -58
- package/dist/components/RoundGauge.d.ts +0 -1
- package/dist/components/RoundGauge.js +70 -104
- package/dist/components/Section.d.ts +1 -2
- package/dist/components/Section.js +50 -51
- package/dist/components/Slider.d.ts +0 -1
- package/dist/components/Slider.js +72 -80
- package/dist/components/Stack.d.ts +0 -1
- package/dist/components/Stack.js +37 -47
- package/dist/components/StyleableSection.d.ts +0 -1
- package/dist/components/StyleableSection.js +11 -11
- package/dist/components/Table.d.ts +0 -1
- package/dist/components/Table.js +38 -47
- package/dist/components/Tabs.d.ts +0 -1
- package/dist/components/Tabs.js +43 -75
- package/dist/components/TextArea.d.ts +0 -1
- package/dist/components/TextArea.js +74 -69
- package/dist/components/TimeDisplay.d.ts +7 -6
- package/dist/components/TimeDisplay.js +17 -17
- package/dist/components/Tooltip.d.ts +1 -2
- package/dist/components/Tooltip.js +8 -10
- package/dist/components/TrackOutsideClicks.d.ts +0 -1
- package/dist/components/VirtualList.d.ts +0 -1
- package/package.json +25 -25
- package/dist/ProgressBar.module-Jzqlebbx.js +0 -29
- package/dist/Section.module-qhQWhlUX.js +0 -18
- package/dist/assets/BlockQuote.css +0 -1
- package/dist/assets/Button.css +0 -1
- package/dist/assets/ColorBox.css +0 -1
- package/dist/assets/Dialog.css +0 -1
- package/dist/assets/Dimmer.css +0 -1
- package/dist/assets/Divider.css +0 -1
- package/dist/assets/Flex.css +0 -1
- package/dist/assets/Icon.css +0 -6
- package/dist/assets/ImageButton.css +0 -5
- package/dist/assets/Input.css +0 -1
- package/dist/assets/Knob.css +0 -1
- package/dist/assets/LabeledList.css +0 -1
- package/dist/assets/MenuBar.css +0 -1
- package/dist/assets/Modal.css +0 -1
- package/dist/assets/NoticeBox.css +0 -1
- package/dist/assets/NumberInput.css +0 -1
- package/dist/assets/ProgressBar.css +0 -1
- package/dist/assets/RoundGauge.css +0 -1
- package/dist/assets/Section.css +0 -1
- package/dist/assets/Slider.css +0 -1
- package/dist/assets/Stack.css +0 -1
- package/dist/assets/Table.css +0 -1
- package/dist/assets/Tabs.css +0 -1
- package/dist/assets/TextArea.css +0 -1
- package/dist/assets/Tooltip.css +0 -1
|
@@ -1,44 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { jsxs as
|
|
5
|
-
import { Component as
|
|
6
|
-
import { KEY as
|
|
7
|
-
import { clamp as
|
|
8
|
-
import { classes as
|
|
9
|
-
import { AnimatedNumber as
|
|
10
|
-
import { Box as
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
content: L,
|
|
15
|
-
barContainer: z,
|
|
16
|
-
bar: j,
|
|
17
|
-
inner: k
|
|
18
|
-
};
|
|
19
|
-
class J extends E {
|
|
20
|
-
constructor(e) {
|
|
21
|
-
super(e);
|
|
1
|
+
var I = Object.defineProperty;
|
|
2
|
+
var E = (m, d, e) => d in m ? I(m, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : m[d] = e;
|
|
3
|
+
var o = (m, d, e) => E(m, typeof d != "symbol" ? d + "" : d, e);
|
|
4
|
+
import { jsxs as N, jsx as f } from "react/jsx-runtime";
|
|
5
|
+
import { Component as x, createRef as D } from "react";
|
|
6
|
+
import { KEY as _, isEscape as M } from "../common/keys.js";
|
|
7
|
+
import { clamp as h, round as T } from "../common/math.js";
|
|
8
|
+
import { classes as w } from "../common/react.js";
|
|
9
|
+
import { AnimatedNumber as F } from "./AnimatedNumber.js";
|
|
10
|
+
import { Box as R } from "./Box.js";
|
|
11
|
+
class H extends x {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
22
14
|
// Ref to the input field to set focus & highlight
|
|
23
|
-
|
|
15
|
+
o(this, "inputRef", D());
|
|
24
16
|
// After this time has elapsed we are in drag mode so no editing when dragging ends
|
|
25
|
-
|
|
17
|
+
o(this, "dragTimeout");
|
|
26
18
|
// Call onDrag at this interval
|
|
27
|
-
|
|
19
|
+
o(this, "dragInterval");
|
|
28
20
|
// default values for the number input state
|
|
29
|
-
|
|
21
|
+
o(this, "state", {
|
|
30
22
|
editing: !1,
|
|
31
23
|
dragging: !1,
|
|
32
24
|
currentValue: 0,
|
|
33
25
|
previousValue: 0,
|
|
34
26
|
origin: 0
|
|
35
27
|
});
|
|
36
|
-
|
|
37
|
-
const { value:
|
|
38
|
-
if (
|
|
28
|
+
o(this, "handleDragStart", (e) => {
|
|
29
|
+
const { value: u, disabled: n } = this.props, { editing: s } = this.state;
|
|
30
|
+
if (n || s)
|
|
39
31
|
return;
|
|
40
32
|
document.body.style["pointer-events"] = "none";
|
|
41
|
-
const r = parseFloat(
|
|
33
|
+
const r = Number.parseFloat(u.toString());
|
|
42
34
|
this.setState({
|
|
43
35
|
dragging: !1,
|
|
44
36
|
origin: e.screenY,
|
|
@@ -49,59 +41,59 @@ class J extends E {
|
|
|
49
41
|
dragging: !0
|
|
50
42
|
});
|
|
51
43
|
}, 250), this.dragInterval = setInterval(() => {
|
|
52
|
-
const { dragging:
|
|
53
|
-
|
|
44
|
+
const { dragging: l, currentValue: i, previousValue: t } = this.state, { onDrag: a } = this.props;
|
|
45
|
+
l && i !== t && (this.setState({
|
|
54
46
|
previousValue: i
|
|
55
|
-
}),
|
|
47
|
+
}), a == null || a(i));
|
|
56
48
|
}, 400), document.addEventListener("mousemove", this.handleDragMove), document.addEventListener("mouseup", this.handleDragEnd);
|
|
57
49
|
});
|
|
58
|
-
|
|
59
|
-
const { minValue:
|
|
60
|
-
|
|
61
|
-
const t = { ...i },
|
|
50
|
+
o(this, "handleDragMove", (e) => {
|
|
51
|
+
const { minValue: u, maxValue: n, step: s, stepPixelSize: r, disabled: l } = this.props;
|
|
52
|
+
l || this.setState((i) => {
|
|
53
|
+
const t = { ...i }, a = t.origin - e.screenY;
|
|
62
54
|
if (i.dragging) {
|
|
63
|
-
const
|
|
64
|
-
t.currentValue +
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
const g = r || 1, c = h(
|
|
56
|
+
t.currentValue + a * s / g,
|
|
57
|
+
u - s,
|
|
58
|
+
n + s
|
|
67
59
|
);
|
|
68
|
-
Math.abs(
|
|
69
|
-
T(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
), t.origin = e.screenY) : Math.abs(
|
|
73
|
-
} else Math.abs(
|
|
60
|
+
Math.abs(c - t.currentValue) >= s ? (t.currentValue = h(
|
|
61
|
+
T(c / s, 0) * s,
|
|
62
|
+
u,
|
|
63
|
+
n
|
|
64
|
+
), t.origin = e.screenY) : Math.abs(a) > g && (t.origin = e.screenY);
|
|
65
|
+
} else Math.abs(a) > 4 && (t.dragging = !0);
|
|
74
66
|
return t;
|
|
75
67
|
});
|
|
76
68
|
});
|
|
77
|
-
|
|
78
|
-
const { dragging:
|
|
79
|
-
if (!
|
|
69
|
+
o(this, "handleDragEnd", (e) => {
|
|
70
|
+
const { dragging: u, currentValue: n } = this.state, { onDrag: s, onChange: r, disabled: l } = this.props;
|
|
71
|
+
if (!l) {
|
|
80
72
|
if (document.body.style["pointer-events"] = "auto", clearInterval(this.dragInterval), clearTimeout(this.dragTimeout), this.setState({
|
|
81
73
|
dragging: !1,
|
|
82
|
-
editing: !
|
|
83
|
-
previousValue:
|
|
84
|
-
}),
|
|
85
|
-
r == null || r(
|
|
74
|
+
editing: !u,
|
|
75
|
+
previousValue: n
|
|
76
|
+
}), u)
|
|
77
|
+
r == null || r(n), s == null || s(n);
|
|
86
78
|
else if (this.inputRef) {
|
|
87
79
|
const i = this.inputRef.current;
|
|
88
|
-
i && (i.value = `${
|
|
80
|
+
i && (i.value = `${n}`, setTimeout(() => {
|
|
89
81
|
i.focus(), i.select();
|
|
90
82
|
}, 10));
|
|
91
83
|
}
|
|
92
84
|
document.removeEventListener("mousemove", this.handleDragMove), document.removeEventListener("mouseup", this.handleDragEnd);
|
|
93
85
|
}
|
|
94
86
|
});
|
|
95
|
-
|
|
96
|
-
const { editing:
|
|
97
|
-
if (t || !
|
|
87
|
+
o(this, "handleBlur", (e) => {
|
|
88
|
+
const { editing: u, previousValue: n } = this.state, { minValue: s, maxValue: r, onChange: l, onDrag: i, disabled: t } = this.props;
|
|
89
|
+
if (t || !u)
|
|
98
90
|
return;
|
|
99
|
-
const
|
|
100
|
-
parseFloat(e.target.value),
|
|
91
|
+
const a = h(
|
|
92
|
+
Number.parseFloat(e.target.value),
|
|
101
93
|
s,
|
|
102
94
|
r
|
|
103
95
|
);
|
|
104
|
-
if (isNaN(
|
|
96
|
+
if (Number.isNaN(a)) {
|
|
105
97
|
this.setState({
|
|
106
98
|
editing: !1
|
|
107
99
|
});
|
|
@@ -109,22 +101,22 @@ class J extends E {
|
|
|
109
101
|
}
|
|
110
102
|
this.setState({
|
|
111
103
|
editing: !1,
|
|
112
|
-
currentValue:
|
|
113
|
-
previousValue:
|
|
114
|
-
}),
|
|
104
|
+
currentValue: a,
|
|
105
|
+
previousValue: a
|
|
106
|
+
}), n !== a && (l == null || l(a), i == null || i(a));
|
|
115
107
|
});
|
|
116
|
-
|
|
117
|
-
const { minValue:
|
|
118
|
-
if (
|
|
108
|
+
o(this, "handleKeyDown", (e) => {
|
|
109
|
+
const { minValue: u, maxValue: n, onChange: s, onDrag: r, disabled: l } = this.props;
|
|
110
|
+
if (l)
|
|
119
111
|
return;
|
|
120
112
|
const { previousValue: i } = this.state;
|
|
121
|
-
if (e.key ===
|
|
122
|
-
const t =
|
|
123
|
-
parseFloat(e.currentTarget.value),
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
if (e.key === _.Enter) {
|
|
114
|
+
const t = h(
|
|
115
|
+
Number.parseFloat(e.currentTarget.value),
|
|
116
|
+
u,
|
|
117
|
+
n
|
|
126
118
|
);
|
|
127
|
-
if (isNaN(t)) {
|
|
119
|
+
if (Number.isNaN(t)) {
|
|
128
120
|
this.setState({
|
|
129
121
|
editing: !1
|
|
130
122
|
});
|
|
@@ -141,71 +133,71 @@ class J extends E {
|
|
|
141
133
|
});
|
|
142
134
|
}
|
|
143
135
|
componentDidMount() {
|
|
144
|
-
const e = parseFloat(this.props.value.toString());
|
|
136
|
+
const e = Number.parseFloat(this.props.value.toString());
|
|
145
137
|
this.setState({
|
|
146
138
|
currentValue: e,
|
|
147
139
|
previousValue: e
|
|
148
140
|
});
|
|
149
141
|
}
|
|
150
142
|
render() {
|
|
151
|
-
const { dragging: e, editing:
|
|
143
|
+
const { dragging: e, editing: u, currentValue: n } = this.state, {
|
|
152
144
|
className: s,
|
|
153
145
|
fluid: r,
|
|
154
|
-
animated:
|
|
146
|
+
animated: l,
|
|
155
147
|
unit: i,
|
|
156
148
|
value: t,
|
|
157
|
-
minValue:
|
|
158
|
-
maxValue:
|
|
159
|
-
height:
|
|
149
|
+
minValue: a,
|
|
150
|
+
maxValue: g,
|
|
151
|
+
height: c,
|
|
160
152
|
width: S,
|
|
161
|
-
lineHeight:
|
|
162
|
-
fontSize:
|
|
163
|
-
format:
|
|
153
|
+
lineHeight: v,
|
|
154
|
+
fontSize: b,
|
|
155
|
+
format: V
|
|
164
156
|
} = this.props;
|
|
165
|
-
let
|
|
166
|
-
e && (
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
i ?
|
|
157
|
+
let p = Number.parseFloat(t.toString());
|
|
158
|
+
e && (p = n);
|
|
159
|
+
const y = /* @__PURE__ */ N("div", { className: "NumberInput__content", children: [
|
|
160
|
+
l && !e ? /* @__PURE__ */ f(F, { value: p, format: V }) : V ? V(p) : p,
|
|
161
|
+
i ? ` ${i}` : ""
|
|
170
162
|
] });
|
|
171
|
-
return /* @__PURE__ */
|
|
172
|
-
|
|
163
|
+
return /* @__PURE__ */ N(
|
|
164
|
+
R,
|
|
173
165
|
{
|
|
174
|
-
className:
|
|
175
|
-
|
|
176
|
-
r &&
|
|
166
|
+
className: w([
|
|
167
|
+
"NumberInput",
|
|
168
|
+
r && "NumberInput--fluid",
|
|
177
169
|
s
|
|
178
170
|
]),
|
|
179
171
|
minWidth: S,
|
|
180
|
-
minHeight:
|
|
181
|
-
lineHeight:
|
|
182
|
-
fontSize:
|
|
172
|
+
minHeight: c,
|
|
173
|
+
lineHeight: v,
|
|
174
|
+
fontSize: b,
|
|
183
175
|
onMouseDown: this.handleDragStart,
|
|
184
176
|
children: [
|
|
185
|
-
/* @__PURE__ */
|
|
177
|
+
/* @__PURE__ */ f("div", { className: "NumberInput__barContainer", children: /* @__PURE__ */ f(
|
|
186
178
|
"div",
|
|
187
179
|
{
|
|
188
|
-
className:
|
|
180
|
+
className: "NumberInput__bar",
|
|
189
181
|
style: {
|
|
190
|
-
height:
|
|
191
|
-
(
|
|
182
|
+
height: `${h(
|
|
183
|
+
(p - a) / (g - a) * 100,
|
|
192
184
|
0,
|
|
193
185
|
100
|
|
194
|
-
)
|
|
186
|
+
)}%`
|
|
195
187
|
}
|
|
196
188
|
}
|
|
197
189
|
) }),
|
|
198
|
-
|
|
199
|
-
/* @__PURE__ */
|
|
190
|
+
y,
|
|
191
|
+
/* @__PURE__ */ f(
|
|
200
192
|
"input",
|
|
201
193
|
{
|
|
202
194
|
ref: this.inputRef,
|
|
203
|
-
className:
|
|
195
|
+
className: "NumberInput__input",
|
|
204
196
|
style: {
|
|
205
|
-
display:
|
|
206
|
-
height:
|
|
207
|
-
lineHeight:
|
|
208
|
-
fontSize:
|
|
197
|
+
display: u ? "inline" : "none",
|
|
198
|
+
height: c,
|
|
199
|
+
lineHeight: v,
|
|
200
|
+
fontSize: b
|
|
209
201
|
},
|
|
210
202
|
onBlur: this.handleBlur,
|
|
211
203
|
onKeyDown: this.handleKeyDown
|
|
@@ -217,5 +209,5 @@ class J extends E {
|
|
|
217
209
|
}
|
|
218
210
|
}
|
|
219
211
|
export {
|
|
220
|
-
|
|
212
|
+
H as NumberInput
|
|
221
213
|
};
|
|
@@ -1,37 +1,32 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { CSS_COLORS as
|
|
3
|
-
import { keyOfMatchingRange as
|
|
4
|
-
import { classes as
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
function w(d) {
|
|
1
|
+
import { jsxs as B, jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { CSS_COLORS as C } from "../common/constants.js";
|
|
3
|
+
import { keyOfMatchingRange as P, toFixed as h, scale as x, clamp01 as _ } from "../common/math.js";
|
|
4
|
+
import { classes as v } from "../common/react.js";
|
|
5
|
+
import { computeBoxProps as y, computeBoxClassName as N } from "./Box.js";
|
|
6
|
+
function j(n) {
|
|
8
7
|
const {
|
|
9
|
-
className:
|
|
10
|
-
value:
|
|
11
|
-
minValue:
|
|
12
|
-
maxValue:
|
|
13
|
-
color:
|
|
14
|
-
ranges:
|
|
15
|
-
children:
|
|
16
|
-
...
|
|
17
|
-
} =
|
|
18
|
-
|
|
19
|
-
f,
|
|
20
|
-
O(t)
|
|
21
|
-
], i = {
|
|
22
|
-
width: _(a) * 100 + "%"
|
|
8
|
+
className: m,
|
|
9
|
+
value: o,
|
|
10
|
+
minValue: d = 0,
|
|
11
|
+
maxValue: f = 1,
|
|
12
|
+
color: u,
|
|
13
|
+
ranges: p = {},
|
|
14
|
+
children: r,
|
|
15
|
+
...l
|
|
16
|
+
} = n, a = x(o, d, f), g = r !== void 0, s = u || P(o, p) || "default", e = y(l), t = ["ProgressBar", m, N(l)], c = {
|
|
17
|
+
width: `${_(a) * 100}%`
|
|
23
18
|
};
|
|
24
|
-
return
|
|
25
|
-
/* @__PURE__ */
|
|
19
|
+
return C.includes(s) || s === "default" ? t.push(`ProgressBar--color--${s}`) : (e.style = { ...e.style, borderColor: s }, c.backgroundColor = s), /* @__PURE__ */ B("div", { className: v(t), ...e, children: [
|
|
20
|
+
/* @__PURE__ */ i(
|
|
26
21
|
"div",
|
|
27
22
|
{
|
|
28
|
-
className:
|
|
29
|
-
style:
|
|
23
|
+
className: "ProgressBar__fill ProgressBar__fill--animated",
|
|
24
|
+
style: c
|
|
30
25
|
}
|
|
31
26
|
),
|
|
32
|
-
/* @__PURE__ */
|
|
27
|
+
/* @__PURE__ */ i("div", { className: "ProgressBar__content", children: g ? r : `${h(a * 100)}%` })
|
|
33
28
|
] });
|
|
34
29
|
}
|
|
35
30
|
export {
|
|
36
|
-
|
|
31
|
+
j as ProgressBar
|
|
37
32
|
};
|
|
@@ -1,89 +1,95 @@
|
|
|
1
1
|
import { jsxs as E, jsx as h } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Component as N, createRef as S } from "react";
|
|
3
|
+
import { KEY_ENTER as I, KEY_ESCAPE as b } from "../common/keycodes.js";
|
|
4
|
+
import { clamp as d } from "../common/math.js";
|
|
4
5
|
import { classes as v } from "../common/react.js";
|
|
5
|
-
import {
|
|
6
|
-
import { Box as C } from "./Box.js";
|
|
6
|
+
import { Box as F } from "./Box.js";
|
|
7
7
|
const g = 0, x = 1e4;
|
|
8
|
-
function
|
|
9
|
-
const i =
|
|
10
|
-
let r =
|
|
11
|
-
return
|
|
8
|
+
function C(s, e, t, n) {
|
|
9
|
+
const i = e || g, o = t || t === 0 ? t : x;
|
|
10
|
+
let r = n ? s.replace(/[^\-\d.]/g, "") : s.replace(/[^\-\d]/g, "");
|
|
11
|
+
return n && (r = V(r, i), r = m(".", r)), e < 0 ? (r = _(r), r = m("-", r)) : r = r.replaceAll("-", ""), i <= 1 && o >= 0 ? M(r, i, o, n) : r;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
if (!isNaN(i) && (
|
|
16
|
-
|
|
13
|
+
const M = (s, e, t, n) => {
|
|
14
|
+
const i = n ? Number.parseFloat(s) : Number.parseInt(s, 10);
|
|
15
|
+
if (!Number.isNaN(i) && (s.slice(-1) !== "." || i < Math.floor(e))) {
|
|
16
|
+
const o = d(i, e, t);
|
|
17
17
|
if (i !== o)
|
|
18
18
|
return String(o);
|
|
19
19
|
}
|
|
20
|
-
return
|
|
20
|
+
return s;
|
|
21
21
|
};
|
|
22
|
-
function _(
|
|
23
|
-
let
|
|
24
|
-
|
|
22
|
+
function _(s) {
|
|
23
|
+
let e = s;
|
|
24
|
+
const t = s.indexOf("-");
|
|
25
|
+
if (t > 0) {
|
|
26
|
+
const n = s.replace("-", "");
|
|
27
|
+
e = "-".concat(n);
|
|
28
|
+
} else t === 0 && s.indexOf("-", t + 1) > 0 && (e = s.replaceAll("-", ""));
|
|
29
|
+
return e;
|
|
25
30
|
}
|
|
26
|
-
function
|
|
27
|
-
let t =
|
|
28
|
-
|
|
31
|
+
function V(s, e) {
|
|
32
|
+
let t = s;
|
|
33
|
+
const n = Math.sign(e) * Math.floor(Math.abs(e));
|
|
34
|
+
return s.indexOf(".") === 0 ? t = String(n).concat(s) : s.indexOf("-") === 0 && s.indexOf(".") === 1 && (t = n + ".".concat(s.slice(2))), t;
|
|
29
35
|
}
|
|
30
|
-
function
|
|
31
|
-
const t =
|
|
32
|
-
let i =
|
|
33
|
-
if (t !== -1 && t <
|
|
34
|
-
let o =
|
|
35
|
-
o = o.replaceAll(
|
|
36
|
+
function m(s, e) {
|
|
37
|
+
const t = e.indexOf(s), n = e.length;
|
|
38
|
+
let i = e;
|
|
39
|
+
if (t !== -1 && t < n - 1) {
|
|
40
|
+
let o = e.slice(t + 1, n);
|
|
41
|
+
o = o.replaceAll(s, ""), i = e.slice(0, t + 1).concat(o);
|
|
36
42
|
}
|
|
37
43
|
return i;
|
|
38
44
|
}
|
|
39
|
-
function f(
|
|
40
|
-
const i =
|
|
41
|
-
if (!
|
|
45
|
+
function f(s, e, t, n) {
|
|
46
|
+
const i = e || g, o = t || t === 0 ? t : x;
|
|
47
|
+
if (!s || !s.length)
|
|
42
48
|
return String(i);
|
|
43
|
-
|
|
44
|
-
return isNaN(r) ? String(i) : String(
|
|
49
|
+
const r = n ? Number.parseFloat(s.replace(/[^\-\d.]/g, "")) : Number.parseInt(s.replace(/[^\-\d]/g, ""), 10);
|
|
50
|
+
return Number.isNaN(r) ? String(i) : String(d(r, i, o));
|
|
45
51
|
}
|
|
46
|
-
class B extends
|
|
47
|
-
constructor(
|
|
48
|
-
super(
|
|
52
|
+
class B extends N {
|
|
53
|
+
constructor(e) {
|
|
54
|
+
super(e), this.inputRef = S(), this.state = {
|
|
49
55
|
editing: !1
|
|
50
56
|
}, this.handleBlur = (t) => {
|
|
51
|
-
const { maxValue:
|
|
57
|
+
const { maxValue: n, minValue: i, onBlur: o, allowFloats: r } = this.props, { editing: l } = this.state;
|
|
52
58
|
l && this.setEditing(!1);
|
|
53
59
|
const a = f(
|
|
54
60
|
t.target.value,
|
|
55
61
|
i,
|
|
56
|
-
|
|
62
|
+
n,
|
|
57
63
|
r
|
|
58
64
|
);
|
|
59
65
|
o && o(t, +a);
|
|
60
66
|
}, this.handleChange = (t) => {
|
|
61
|
-
const { maxValue:
|
|
62
|
-
t.target.value =
|
|
67
|
+
const { maxValue: n, minValue: i, onChange: o, allowFloats: r } = this.props;
|
|
68
|
+
t.target.value = C(
|
|
63
69
|
t.target.value,
|
|
64
70
|
i,
|
|
65
|
-
|
|
71
|
+
n,
|
|
66
72
|
r
|
|
67
73
|
), o && o(t, +t.target.value);
|
|
68
74
|
}, this.handleFocus = (t) => {
|
|
69
|
-
const { editing:
|
|
70
|
-
|
|
75
|
+
const { editing: n } = this.state;
|
|
76
|
+
n || this.setEditing(!0);
|
|
71
77
|
}, this.handleInput = (t) => {
|
|
72
|
-
const { editing:
|
|
73
|
-
|
|
78
|
+
const { editing: n } = this.state, { onInput: i } = this.props;
|
|
79
|
+
n || this.setEditing(!0), i && i(t, +t.target.value);
|
|
74
80
|
}, this.handleKeyDown = (t) => {
|
|
75
|
-
const { maxValue:
|
|
81
|
+
const { maxValue: n, minValue: i, onChange: o, onEnter: r, allowFloats: l } = this.props;
|
|
76
82
|
if (t.keyCode === I) {
|
|
77
83
|
const a = f(
|
|
78
84
|
t.target.value,
|
|
79
85
|
i,
|
|
80
|
-
|
|
86
|
+
n,
|
|
81
87
|
l
|
|
82
88
|
);
|
|
83
89
|
this.setEditing(!1), o && o(t, +a), r && r(t, +a), t.target.blur();
|
|
84
90
|
return;
|
|
85
91
|
}
|
|
86
|
-
if (t.keyCode ===
|
|
92
|
+
if (t.keyCode === b) {
|
|
87
93
|
if (this.props.onEscape) {
|
|
88
94
|
this.props.onEscape(t);
|
|
89
95
|
return;
|
|
@@ -95,41 +101,41 @@ class B extends F {
|
|
|
95
101
|
}
|
|
96
102
|
componentDidMount() {
|
|
97
103
|
var r;
|
|
98
|
-
const { maxValue:
|
|
104
|
+
const { maxValue: e, minValue: t, allowFloats: n } = this.props, i = (r = this.props.value) == null ? void 0 : r.toString(), o = this.inputRef.current;
|
|
99
105
|
o && (o.value = f(
|
|
100
106
|
i,
|
|
101
107
|
t,
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
e,
|
|
109
|
+
n
|
|
104
110
|
)), (this.props.autoFocus || this.props.autoSelect) && setTimeout(() => {
|
|
105
111
|
o.focus(), this.props.autoSelect && o.select();
|
|
106
112
|
}, 1);
|
|
107
113
|
}
|
|
108
|
-
componentDidUpdate(
|
|
109
|
-
var
|
|
110
|
-
const { maxValue:
|
|
114
|
+
componentDidUpdate(e, t) {
|
|
115
|
+
var c, p;
|
|
116
|
+
const { maxValue: n, minValue: i, allowFloats: o } = this.props, { editing: r } = this.state, l = (c = e.value) == null ? void 0 : c.toString(), a = (p = this.props.value) == null ? void 0 : p.toString(), u = this.inputRef.current;
|
|
111
117
|
u && !r && a !== l && a !== u.value && (u.value = f(
|
|
112
118
|
a,
|
|
113
119
|
i,
|
|
114
|
-
|
|
120
|
+
n,
|
|
115
121
|
o
|
|
116
122
|
));
|
|
117
123
|
}
|
|
118
|
-
setEditing(
|
|
119
|
-
this.setState({ editing:
|
|
124
|
+
setEditing(e) {
|
|
125
|
+
this.setState({ editing: e });
|
|
120
126
|
}
|
|
121
127
|
render() {
|
|
122
|
-
const { props:
|
|
128
|
+
const { props: e } = this, { onChange: t, onEnter: n, onInput: i, onBlur: o, value: r, ...l } = e, { className: a, fluid: u, monospace: c, ...p } = l;
|
|
123
129
|
return /* @__PURE__ */ E(
|
|
124
|
-
|
|
130
|
+
F,
|
|
125
131
|
{
|
|
126
132
|
className: v([
|
|
127
133
|
"Input",
|
|
128
134
|
u && "Input--fluid",
|
|
129
|
-
|
|
135
|
+
c && "Input--monospace",
|
|
130
136
|
a
|
|
131
137
|
]),
|
|
132
|
-
...
|
|
138
|
+
...p,
|
|
133
139
|
children: [
|
|
134
140
|
/* @__PURE__ */ h("div", { className: "Input__baseline", children: "." }),
|
|
135
141
|
/* @__PURE__ */ h(
|