tgui-core 1.1.7 → 1.1.9
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/lib/common/assets.ts +38 -0
- package/lib/common/collections.ts +27 -0
- package/lib/common/color.ts +88 -0
- package/lib/common/constants.ts +349 -0
- package/lib/common/events.ts +262 -0
- package/{dist/common/exhaustive.d.ts → lib/common/exhaustive.ts} +3 -1
- package/lib/common/format.ts +167 -0
- package/{dist/common/fp.d.ts → lib/common/fp.ts} +16 -2
- package/lib/common/hotkeys.ts +207 -0
- package/lib/common/http.ts +16 -0
- package/lib/common/keycodes.ts +86 -0
- package/{dist/common/keys.d.ts → lib/common/keys.ts} +24 -21
- package/lib/common/math.ts +76 -0
- package/lib/common/perf.ts +72 -0
- package/lib/common/random.ts +32 -0
- package/lib/common/react.ts +59 -0
- package/lib/common/redux.ts +187 -0
- package/lib/common/storage.ts +207 -0
- package/lib/common/string.ts +169 -0
- package/lib/common/timer.ts +63 -0
- package/lib/common/type-utils.ts +41 -0
- package/lib/common/types.d.ts +12 -0
- package/lib/common/uuid.ts +18 -0
- package/lib/components/AnimatedNumber.tsx +180 -0
- package/lib/components/Autofocus.tsx +23 -0
- package/lib/components/Blink.tsx +91 -0
- package/lib/components/BlockQuote.tsx +9 -0
- package/lib/components/BodyZoneSelector.tsx +149 -0
- package/lib/components/Box.tsx +252 -0
- package/lib/components/Button.tsx +425 -0
- package/lib/components/ByondUi.jsx +110 -0
- package/lib/components/Chart.tsx +155 -0
- package/lib/components/Collapsible.tsx +43 -0
- package/lib/components/ColorBox.tsx +29 -0
- package/lib/components/Dialog.tsx +81 -0
- package/lib/components/Dimmer.tsx +13 -0
- package/lib/components/Divider.tsx +20 -0
- package/lib/components/DmIcon.tsx +86 -0
- package/lib/components/DraggableControl.jsx +276 -0
- package/lib/components/Dropdown.tsx +246 -0
- package/lib/components/FakeTerminal.jsx +52 -0
- package/lib/components/FitText.tsx +99 -0
- package/lib/components/Flex.tsx +159 -0
- package/lib/components/Icon.tsx +95 -0
- package/lib/components/Image.tsx +54 -0
- package/lib/components/InfinitePlane.jsx +192 -0
- package/lib/components/Input.tsx +176 -0
- package/lib/components/KeyListener.tsx +40 -0
- package/lib/components/Knob.tsx +178 -0
- package/lib/components/LabeledControls.tsx +44 -0
- package/lib/components/LabeledList.tsx +154 -0
- package/lib/components/MenuBar.tsx +228 -0
- package/lib/components/Modal.tsx +23 -0
- package/lib/components/NoticeBox.tsx +45 -0
- package/lib/components/NumberInput.tsx +328 -0
- package/lib/components/Popper.tsx +100 -0
- package/lib/components/ProgressBar.tsx +105 -0
- package/lib/components/RestrictedInput.jsx +301 -0
- package/lib/components/RoundGauge.tsx +180 -0
- package/lib/components/Section.tsx +120 -0
- package/lib/components/Slider.tsx +169 -0
- package/lib/components/Stack.tsx +96 -0
- package/lib/components/StyleableSection.tsx +33 -0
- package/lib/components/Table.tsx +84 -0
- package/lib/components/Tabs.tsx +89 -0
- package/lib/components/TextArea.tsx +182 -0
- package/lib/components/TimeDisplay.jsx +64 -0
- package/lib/components/Tooltip.tsx +152 -0
- package/lib/components/TrackOutsideClicks.tsx +35 -0
- package/lib/components/VirtualList.tsx +69 -0
- package/lib/styles/atomic/candystripe.scss +8 -0
- package/lib/styles/atomic/centered-image.scss +7 -0
- package/lib/styles/atomic/color.scss +21 -0
- package/lib/styles/atomic/debug-layout.scss +17 -0
- package/lib/styles/atomic/fit-text.scss +14 -0
- package/lib/styles/atomic/links.scss +12 -0
- package/lib/styles/atomic/outline.scss +47 -0
- package/lib/styles/atomic/text.scss +44 -0
- package/lib/styles/base.scss +32 -0
- package/lib/styles/colors.scss +92 -0
- package/lib/styles/components/BlockQuote.module.scss +20 -0
- package/lib/styles/components/BlockQuote.module.scss.d.ts +4 -0
- package/lib/styles/components/Button.module.scss +157 -0
- package/lib/styles/components/Button.module.scss.d.ts +46 -0
- package/lib/styles/components/ColorBox.module.scss +12 -0
- package/lib/styles/components/ColorBox.module.scss.d.ts +4 -0
- package/lib/styles/components/Dialog.module.scss +60 -0
- package/lib/styles/components/Dialog.module.scss.d.ts +10 -0
- package/lib/styles/components/Dimmer.module.scss +22 -0
- package/lib/styles/components/Dimmer.module.scss.d.ts +4 -0
- package/lib/styles/components/Divider.module.scss +27 -0
- package/lib/styles/components/Divider.module.scss.d.ts +6 -0
- package/lib/styles/components/Dropdown.scss +72 -0
- package/lib/styles/components/Flex.module.scss +13 -0
- package/lib/styles/components/Flex.module.scss.d.ts +5 -0
- package/lib/styles/components/Icon.module.scss +25 -0
- package/lib/styles/components/Icon.module.scss.d.ts +5 -0
- package/lib/styles/components/Input.module.scss +64 -0
- package/lib/styles/components/Input.module.scss.d.ts +8 -0
- package/lib/styles/components/Knob.module.scss +131 -0
- package/lib/styles/components/Knob.module.scss.d.ts +33 -0
- package/lib/styles/components/LabeledList.module.scss +49 -0
- package/lib/styles/components/LabeledList.module.scss.d.ts +8 -0
- package/lib/styles/components/MenuBar.module.scss +75 -0
- package/lib/styles/components/MenuBar.module.scss.d.ts +14 -0
- package/lib/styles/components/Modal.module.scss +14 -0
- package/lib/styles/components/Modal.module.scss.d.ts +4 -0
- package/lib/styles/components/NoticeBox.module.scss +65 -0
- package/lib/styles/components/NoticeBox.module.scss.d.ts +27 -0
- package/lib/styles/components/NumberInput.module.scss +71 -0
- package/lib/styles/components/NumberInput.module.scss.d.ts +9 -0
- package/lib/styles/components/ProgressBar.module.scss +63 -0
- package/lib/styles/components/ProgressBar.module.scss.d.ts +27 -0
- package/lib/styles/components/RoundGauge.module.scss +85 -0
- package/lib/styles/components/RoundGauge.module.scss.d.ts +49 -0
- package/lib/styles/components/Section.module.scss +130 -0
- package/lib/styles/components/Section.module.scss.d.ts +13 -0
- package/lib/styles/components/Slider.module.scss +54 -0
- package/lib/styles/components/Slider.module.scss.d.ts +8 -0
- package/lib/styles/components/Stack.module.scss +60 -0
- package/lib/styles/components/Stack.module.scss.d.ts +12 -0
- package/lib/styles/components/Table.module.scss +44 -0
- package/lib/styles/components/Table.module.scss.d.ts +10 -0
- package/lib/styles/components/Tabs.module.scss +144 -0
- package/lib/styles/components/Tabs.module.scss.d.ts +35 -0
- package/lib/styles/components/TextArea.module.scss +86 -0
- package/lib/styles/components/TextArea.module.scss.d.ts +11 -0
- package/lib/styles/components/Tooltip.module.scss +24 -0
- package/lib/styles/components/Tooltip.module.scss.d.ts +4 -0
- package/lib/styles/functions.scss +79 -0
- package/lib/styles/input.scss +9 -0
- package/lib/styles/main.scss +20 -0
- package/lib/styles/reset.scss +68 -0
- package/package.json +6 -6
- package/dist/ProgressBar.module-BkAFfFy0.js +0 -29
- package/dist/Section.module-CLVHJ4yA.js +0 -15
- 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/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
- package/dist/common/assets.d.ts +0 -4
- package/dist/common/assets.js +0 -21
- package/dist/common/collections.d.ts +0 -10
- package/dist/common/collections.js +0 -15
- package/dist/common/color.d.ts +0 -25
- package/dist/common/color.js +0 -69
- package/dist/common/constants.d.ts +0 -102
- package/dist/common/constants.js +0 -312
- package/dist/common/events.d.ts +0 -33
- package/dist/common/events.js +0 -147
- package/dist/common/exhaustive.js +0 -6
- package/dist/common/format.d.ts +0 -11
- package/dist/common/format.js +0 -114
- package/dist/common/fp.js +0 -9
- package/dist/common/hotkeys.d.ts +0 -25
- package/dist/common/hotkeys.js +0 -112
- package/dist/common/http.d.ts +0 -4
- package/dist/common/http.js +0 -10
- package/dist/common/keycodes.d.ts +0 -85
- package/dist/common/keycodes.js +0 -88
- package/dist/common/keys.js +0 -8
- package/dist/common/math.d.ts +0 -39
- package/dist/common/math.js +0 -41
- package/dist/common/perf.d.ts +0 -24
- package/dist/common/perf.js +0 -33
- package/dist/common/random.d.ts +0 -16
- package/dist/common/random.js +0 -18
- package/dist/common/react.d.ts +0 -23
- package/dist/common/react.js +0 -30
- package/dist/common/redux.d.ts +0 -64
- package/dist/common/redux.js +0 -72
- package/dist/common/storage.js +0 -124
- package/dist/common/string.d.ts +0 -65
- package/dist/common/string.js +0 -83
- package/dist/common/timer.d.ts +0 -18
- package/dist/common/timer.js +0 -28
- package/dist/common/type-utils.d.ts +0 -9
- package/dist/common/type-utils.js +0 -25
- package/dist/common/uuid.d.ts +0 -9
- package/dist/common/uuid.js +0 -10
- package/dist/components/AnimatedNumber.d.ts +0 -60
- package/dist/components/AnimatedNumber.js +0 -76
- package/dist/components/Autofocus.d.ts +0 -4
- package/dist/components/Autofocus.js +0 -17
- package/dist/components/Blink.d.ts +0 -26
- package/dist/components/Blink.js +0 -56
- package/dist/components/BlockQuote.d.ts +0 -3
- package/dist/components/BlockQuote.js +0 -13
- package/dist/components/BodyZoneSelector.d.ts +0 -28
- package/dist/components/BodyZoneSelector.js +0 -115
- package/dist/components/Box.d.ts +0 -91
- package/dist/components/Box.js +0 -133
- package/dist/components/Button.d.ts +0 -93
- package/dist/components/Button.js +0 -298
- package/dist/components/ByondUi.js +0 -73
- package/dist/components/Chart.d.ts +0 -28
- package/dist/components/Chart.js +0 -95
- package/dist/components/Collapsible.d.ts +0 -15
- package/dist/components/Collapsible.js +0 -27
- package/dist/components/ColorBox.d.ts +0 -8
- package/dist/components/ColorBox.js +0 -24
- package/dist/components/Dialog.d.ts +0 -24
- package/dist/components/Dialog.js +0 -67
- package/dist/components/Dimmer.d.ts +0 -3
- package/dist/components/Dimmer.js +0 -13
- package/dist/components/Divider.d.ts +0 -6
- package/dist/components/Divider.js +0 -22
- package/dist/components/DmIcon.d.ts +0 -31
- package/dist/components/DmIcon.js +0 -31
- package/dist/components/DraggableControl.js +0 -176
- package/dist/components/Dropdown.d.ts +0 -48
- package/dist/components/Dropdown.js +0 -152
- package/dist/components/FakeTerminal.js +0 -38
- package/dist/components/FitText.d.ts +0 -22
- package/dist/components/FitText.js +0 -63
- package/dist/components/Flex.d.ts +0 -93
- package/dist/components/Flex.js +0 -72
- package/dist/components/Icon.d.ts +0 -30
- package/dist/components/Icon.js +0 -51
- package/dist/components/Image.d.ts +0 -14
- package/dist/components/Image.js +0 -35
- package/dist/components/InfinitePlane.js +0 -139
- package/dist/components/Input.d.ts +0 -61
- package/dist/components/Input.js +0 -89
- package/dist/components/KeyListener.d.ts +0 -15
- package/dist/components/KeyListener.js +0 -23
- package/dist/components/Knob.d.ts +0 -49
- package/dist/components/Knob.js +0 -162
- package/dist/components/LabeledControls.d.ts +0 -11
- package/dist/components/LabeledControls.js +0 -39
- package/dist/components/LabeledList.d.ts +0 -57
- package/dist/components/LabeledList.js +0 -94
- package/dist/components/MenuBar.d.ts +0 -28
- package/dist/components/MenuBar.js +0 -174
- package/dist/components/Modal.d.ts +0 -3
- package/dist/components/Modal.js +0 -25
- package/dist/components/NoticeBox.d.ts +0 -20
- package/dist/components/NoticeBox.js +0 -49
- package/dist/components/NumberInput.d.ts +0 -45
- package/dist/components/NumberInput.js +0 -221
- package/dist/components/Popper.d.ts +0 -27
- package/dist/components/Popper.js +0 -177
- package/dist/components/ProgressBar.d.ts +0 -46
- package/dist/components/ProgressBar.js +0 -37
- package/dist/components/RestrictedInput.js +0 -155
- package/dist/components/RoundGauge.d.ts +0 -53
- package/dist/components/RoundGauge.js +0 -147
- package/dist/components/Section.d.ts +0 -63
- package/dist/components/Section.js +0 -62
- package/dist/components/Slider.d.ts +0 -46
- package/dist/components/Slider.js +0 -124
- package/dist/components/Stack.d.ts +0 -27
- package/dist/components/Stack.js +0 -67
- package/dist/components/StyleableSection.d.ts +0 -11
- package/dist/components/StyleableSection.js +0 -16
- package/dist/components/Table.d.ts +0 -29
- package/dist/components/Table.js +0 -67
- package/dist/components/Tabs.d.ts +0 -23
- package/dist/components/Tabs.js +0 -89
- package/dist/components/TextArea.d.ts +0 -39
- package/dist/components/TextArea.js +0 -118
- package/dist/components/TimeDisplay.js +0 -34
- package/dist/components/Tooltip.d.ts +0 -29
- package/dist/components/Tooltip.js +0 -83
- package/dist/components/TrackOutsideClicks.d.ts +0 -13
- package/dist/components/TrackOutsideClicks.js +0 -24
- package/dist/components/VirtualList.d.ts +0 -8
- package/dist/components/VirtualList.js +0 -34
- package/dist/components/index.js +0 -92
- package/dist/popper-CiqSDJTE.js +0 -906
- /package/{dist/components/index.d.ts → lib/components/index.ts} +0 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
|
|
3
|
+
import { computeBoxProps } from './Box';
|
|
4
|
+
import { Button } from './Button';
|
|
5
|
+
import { ProgressBar } from './ProgressBar';
|
|
6
|
+
import { Stack } from './Stack';
|
|
7
|
+
|
|
8
|
+
const ZOOM_MIN_VAL = 0.5;
|
|
9
|
+
const ZOOM_MAX_VAL = 1.5;
|
|
10
|
+
|
|
11
|
+
const ZOOM_INCREMENT = 0.1;
|
|
12
|
+
|
|
13
|
+
export class InfinitePlane extends Component {
|
|
14
|
+
constructor(props) {
|
|
15
|
+
super(props);
|
|
16
|
+
|
|
17
|
+
this.state = {
|
|
18
|
+
mouseDown: false,
|
|
19
|
+
|
|
20
|
+
left: 0,
|
|
21
|
+
top: 0,
|
|
22
|
+
|
|
23
|
+
lastLeft: 0,
|
|
24
|
+
lastTop: 0,
|
|
25
|
+
|
|
26
|
+
zoom: 1,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
this.handleMouseDown = this.handleMouseDown.bind(this);
|
|
30
|
+
this.handleMouseMove = this.handleMouseMove.bind(this);
|
|
31
|
+
this.handleZoomIncrease = this.handleZoomIncrease.bind(this);
|
|
32
|
+
this.handleZoomDecrease = this.handleZoomDecrease.bind(this);
|
|
33
|
+
this.onMouseUp = this.onMouseUp.bind(this);
|
|
34
|
+
|
|
35
|
+
this.doOffsetMouse = this.doOffsetMouse.bind(this);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
componentDidMount() {
|
|
39
|
+
window.addEventListener('mouseup', this.onMouseUp);
|
|
40
|
+
|
|
41
|
+
window.addEventListener('mousedown', this.doOffsetMouse);
|
|
42
|
+
window.addEventListener('mousemove', this.doOffsetMouse);
|
|
43
|
+
window.addEventListener('mouseup', this.doOffsetMouse);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
componentWillUnmount() {
|
|
47
|
+
window.removeEventListener('mouseup', this.onMouseUp);
|
|
48
|
+
|
|
49
|
+
window.removeEventListener('mousedown', this.doOffsetMouse);
|
|
50
|
+
window.removeEventListener('mousemove', this.doOffsetMouse);
|
|
51
|
+
window.removeEventListener('mouseup', this.doOffsetMouse);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
doOffsetMouse(event) {
|
|
55
|
+
const { zoom } = this.state;
|
|
56
|
+
event.screenZoomX = event.screenX * Math.pow(zoom, -1);
|
|
57
|
+
event.screenZoomY = event.screenY * Math.pow(zoom, -1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
handleMouseDown(event) {
|
|
61
|
+
this.setState((state) => {
|
|
62
|
+
return {
|
|
63
|
+
mouseDown: true,
|
|
64
|
+
lastLeft: event.clientX - state.left,
|
|
65
|
+
lastTop: event.clientY - state.top,
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
onMouseUp() {
|
|
71
|
+
this.setState({
|
|
72
|
+
mouseDown: false,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
handleZoomIncrease(event) {
|
|
77
|
+
const { onZoomChange } = this.props;
|
|
78
|
+
const { zoom } = this.state;
|
|
79
|
+
const newZoomValue = Math.min(zoom + ZOOM_INCREMENT, ZOOM_MAX_VAL);
|
|
80
|
+
this.setState({
|
|
81
|
+
zoom: newZoomValue,
|
|
82
|
+
});
|
|
83
|
+
if (onZoomChange) {
|
|
84
|
+
onZoomChange(newZoomValue);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
handleZoomDecrease(event) {
|
|
89
|
+
const { onZoomChange } = this.props;
|
|
90
|
+
const { zoom } = this.state;
|
|
91
|
+
const newZoomValue = Math.max(zoom - ZOOM_INCREMENT, ZOOM_MIN_VAL);
|
|
92
|
+
this.setState({
|
|
93
|
+
zoom: newZoomValue,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (onZoomChange) {
|
|
97
|
+
onZoomChange(newZoomValue);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
handleMouseMove(event) {
|
|
102
|
+
const { onBackgroundMoved, initialLeft = 0, initialTop = 0 } = this.props;
|
|
103
|
+
if (this.state.mouseDown) {
|
|
104
|
+
let newX, newY;
|
|
105
|
+
this.setState((state) => {
|
|
106
|
+
newX = event.clientX - state.lastLeft;
|
|
107
|
+
newY = event.clientY - state.lastTop;
|
|
108
|
+
return {
|
|
109
|
+
left: newX,
|
|
110
|
+
top: newY,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
if (onBackgroundMoved) {
|
|
114
|
+
onBackgroundMoved(newX + initialLeft, newY + initialTop);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
render() {
|
|
120
|
+
const {
|
|
121
|
+
children,
|
|
122
|
+
backgroundImage,
|
|
123
|
+
imageWidth,
|
|
124
|
+
initialLeft = 0,
|
|
125
|
+
initialTop = 0,
|
|
126
|
+
...rest
|
|
127
|
+
} = this.props;
|
|
128
|
+
const { left, top, zoom } = this.state;
|
|
129
|
+
|
|
130
|
+
const finalLeft = initialLeft + left;
|
|
131
|
+
const finalTop = initialTop + top;
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div
|
|
135
|
+
ref={this.ref}
|
|
136
|
+
{...computeBoxProps({
|
|
137
|
+
...rest,
|
|
138
|
+
style: {
|
|
139
|
+
...rest.style,
|
|
140
|
+
overflow: 'hidden',
|
|
141
|
+
position: 'relative',
|
|
142
|
+
},
|
|
143
|
+
})}
|
|
144
|
+
>
|
|
145
|
+
<div
|
|
146
|
+
onMouseDown={this.handleMouseDown}
|
|
147
|
+
onMouseMove={this.handleMouseMove}
|
|
148
|
+
style={{
|
|
149
|
+
position: 'fixed',
|
|
150
|
+
height: '100%',
|
|
151
|
+
width: '100%',
|
|
152
|
+
backgroundImage: `url("${backgroundImage}")`,
|
|
153
|
+
backgroundPosition: `${finalLeft}px ${finalTop}px`,
|
|
154
|
+
backgroundRepeat: 'repeat',
|
|
155
|
+
backgroundSize: `${zoom * imageWidth}px`,
|
|
156
|
+
}}
|
|
157
|
+
/>
|
|
158
|
+
<div
|
|
159
|
+
onMouseDown={this.handleMouseDown}
|
|
160
|
+
onMouseMove={this.handleMouseMove}
|
|
161
|
+
style={{
|
|
162
|
+
position: 'fixed',
|
|
163
|
+
transform: `translate(${finalLeft}px, ${finalTop}px) scale(${zoom})`,
|
|
164
|
+
transformOrigin: 'top left',
|
|
165
|
+
height: '100%',
|
|
166
|
+
width: '100%',
|
|
167
|
+
}}
|
|
168
|
+
>
|
|
169
|
+
{children}
|
|
170
|
+
</div>
|
|
171
|
+
|
|
172
|
+
<Stack position="absolute" width="100%">
|
|
173
|
+
<Stack.Item>
|
|
174
|
+
<Button icon="minus" onClick={this.handleZoomDecrease} />
|
|
175
|
+
</Stack.Item>
|
|
176
|
+
<Stack.Item grow={1}>
|
|
177
|
+
<ProgressBar
|
|
178
|
+
minValue={ZOOM_MIN_VAL}
|
|
179
|
+
value={zoom}
|
|
180
|
+
maxValue={ZOOM_MAX_VAL}
|
|
181
|
+
>
|
|
182
|
+
{zoom}x
|
|
183
|
+
</ProgressBar>
|
|
184
|
+
</Stack.Item>
|
|
185
|
+
<Stack.Item>
|
|
186
|
+
<Button icon="plus" onClick={this.handleZoomIncrease} />
|
|
187
|
+
</Stack.Item>
|
|
188
|
+
</Stack>
|
|
189
|
+
</div>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { KeyboardEvent, SyntheticEvent, useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { KEY } from '../common/keys';
|
|
4
|
+
import { classes } from '../common/react';
|
|
5
|
+
import { debounce } from '../common/timer';
|
|
6
|
+
import styles from '../styles/components/Input.module.scss';
|
|
7
|
+
import { Box, BoxProps } from './Box';
|
|
8
|
+
|
|
9
|
+
type ConditionalProps =
|
|
10
|
+
| {
|
|
11
|
+
/**
|
|
12
|
+
* Mark this if you want to debounce onInput.
|
|
13
|
+
*
|
|
14
|
+
* This is useful for expensive filters, large lists etc.
|
|
15
|
+
*
|
|
16
|
+
* Requires `onInput` to be set.
|
|
17
|
+
*/
|
|
18
|
+
expensive?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Fires on each key press / value change. Used for searching.
|
|
21
|
+
*
|
|
22
|
+
* If it's a large list, consider using `expensive` prop.
|
|
23
|
+
*/
|
|
24
|
+
onInput: (event: SyntheticEvent<HTMLInputElement>, value: string) => void;
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
/** This prop requires onInput to be set */
|
|
28
|
+
expensive?: never;
|
|
29
|
+
onInput?: never;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type OptionalProps = Partial<{
|
|
33
|
+
/** Automatically focuses the input on mount */
|
|
34
|
+
autoFocus: boolean;
|
|
35
|
+
/** Automatically selects the input value on focus */
|
|
36
|
+
autoSelect: boolean;
|
|
37
|
+
/** The class name of the input */
|
|
38
|
+
className: string;
|
|
39
|
+
/** Disables the input */
|
|
40
|
+
disabled: boolean;
|
|
41
|
+
/** Mark this if you want the input to be as wide as possible */
|
|
42
|
+
fluid: boolean;
|
|
43
|
+
/** The maximum length of the input value */
|
|
44
|
+
maxLength: number;
|
|
45
|
+
/** Mark this if you want to use a monospace font */
|
|
46
|
+
monospace: boolean;
|
|
47
|
+
/** Fires when user is 'done typing': Clicked out, blur, enter key */
|
|
48
|
+
onChange: (event: SyntheticEvent<HTMLInputElement>, value: string) => void;
|
|
49
|
+
/** Fires once the enter key is pressed */
|
|
50
|
+
onEnter?: (event: SyntheticEvent<HTMLInputElement>, value: string) => void;
|
|
51
|
+
/** Fires once the escape key is pressed */
|
|
52
|
+
onEscape: (event: SyntheticEvent<HTMLInputElement>) => void;
|
|
53
|
+
/** The placeholder text when everything is cleared */
|
|
54
|
+
placeholder: string;
|
|
55
|
+
/** Clears the input value on enter */
|
|
56
|
+
selfClear: boolean;
|
|
57
|
+
/** The state variable of the input. */
|
|
58
|
+
value: string | number;
|
|
59
|
+
}>;
|
|
60
|
+
|
|
61
|
+
type Props = OptionalProps & ConditionalProps & BoxProps;
|
|
62
|
+
|
|
63
|
+
export function toInputValue(value: string | number | undefined) {
|
|
64
|
+
return typeof value !== 'number' && typeof value !== 'string'
|
|
65
|
+
? ''
|
|
66
|
+
: String(value);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const inputDebounce = debounce((onInput: () => void) => onInput(), 250);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* ### Input
|
|
73
|
+
* A basic text input which allow users to enter text into a UI.
|
|
74
|
+
* > Input does not support custom font size and height due to the way
|
|
75
|
+
* > it's implemented in CSS. Eventually, this needs to be fixed.
|
|
76
|
+
*/
|
|
77
|
+
export function Input(props: Props) {
|
|
78
|
+
const {
|
|
79
|
+
autoFocus,
|
|
80
|
+
autoSelect,
|
|
81
|
+
className,
|
|
82
|
+
disabled,
|
|
83
|
+
expensive,
|
|
84
|
+
fluid,
|
|
85
|
+
maxLength,
|
|
86
|
+
monospace,
|
|
87
|
+
onChange,
|
|
88
|
+
onEnter,
|
|
89
|
+
onEscape,
|
|
90
|
+
onInput,
|
|
91
|
+
placeholder,
|
|
92
|
+
selfClear,
|
|
93
|
+
value,
|
|
94
|
+
...rest
|
|
95
|
+
} = props;
|
|
96
|
+
|
|
97
|
+
// The ref to the input field
|
|
98
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
99
|
+
|
|
100
|
+
function handleInput(event: SyntheticEvent<HTMLInputElement>) {
|
|
101
|
+
if (!onInput) return;
|
|
102
|
+
|
|
103
|
+
const value = event.currentTarget?.value;
|
|
104
|
+
|
|
105
|
+
if (expensive) {
|
|
106
|
+
inputDebounce(() => onInput(event, value));
|
|
107
|
+
} else {
|
|
108
|
+
onInput(event, value);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function handleKeyDown(event: KeyboardEvent<HTMLInputElement>) {
|
|
113
|
+
if (event.key === KEY.Enter) {
|
|
114
|
+
onEnter?.(event, event.currentTarget.value);
|
|
115
|
+
if (selfClear) {
|
|
116
|
+
event.currentTarget.value = '';
|
|
117
|
+
} else {
|
|
118
|
+
event.currentTarget.blur();
|
|
119
|
+
onChange?.(event, event.currentTarget.value);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (event.key === KEY.Escape) {
|
|
126
|
+
onEscape?.(event);
|
|
127
|
+
|
|
128
|
+
event.currentTarget.value = toInputValue(value);
|
|
129
|
+
event.currentTarget.blur();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Focuses the input on mount */
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
const input = inputRef.current;
|
|
136
|
+
if (!input) return;
|
|
137
|
+
|
|
138
|
+
const newValue = toInputValue(value);
|
|
139
|
+
|
|
140
|
+
if (input.value !== newValue) input.value = newValue;
|
|
141
|
+
|
|
142
|
+
if (!autoFocus && !autoSelect) return;
|
|
143
|
+
|
|
144
|
+
setTimeout(() => {
|
|
145
|
+
input.focus();
|
|
146
|
+
|
|
147
|
+
if (autoSelect) {
|
|
148
|
+
input.select();
|
|
149
|
+
}
|
|
150
|
+
}, 1);
|
|
151
|
+
}, []);
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<Box
|
|
155
|
+
className={classes([
|
|
156
|
+
styles.input,
|
|
157
|
+
fluid && styles.fluid,
|
|
158
|
+
monospace && styles.monospace,
|
|
159
|
+
className,
|
|
160
|
+
])}
|
|
161
|
+
{...rest}
|
|
162
|
+
>
|
|
163
|
+
<div className={styles.baseline}>.</div>
|
|
164
|
+
<input
|
|
165
|
+
className={styles.inner}
|
|
166
|
+
disabled={disabled}
|
|
167
|
+
maxLength={maxLength}
|
|
168
|
+
onBlur={(event) => onChange?.(event, event.target.value)}
|
|
169
|
+
onChange={handleInput}
|
|
170
|
+
onKeyDown={handleKeyDown}
|
|
171
|
+
placeholder={placeholder}
|
|
172
|
+
ref={inputRef}
|
|
173
|
+
/>
|
|
174
|
+
</Box>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
|
|
3
|
+
import { KeyEvent } from '../common/events';
|
|
4
|
+
import { listenForKeyEvents } from '../common/hotkeys';
|
|
5
|
+
|
|
6
|
+
type KeyListenerProps = Partial<{
|
|
7
|
+
onKey: (key: KeyEvent) => void;
|
|
8
|
+
onKeyDown: (key: KeyEvent) => void;
|
|
9
|
+
onKeyUp: (key: KeyEvent) => void;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export class KeyListener extends Component<KeyListenerProps> {
|
|
13
|
+
dispose: () => void;
|
|
14
|
+
|
|
15
|
+
constructor(props) {
|
|
16
|
+
super(props);
|
|
17
|
+
|
|
18
|
+
this.dispose = listenForKeyEvents((key) => {
|
|
19
|
+
if (this.props.onKey) {
|
|
20
|
+
this.props.onKey(key);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (key.isDown() && this.props.onKeyDown) {
|
|
24
|
+
this.props.onKeyDown(key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (key.isUp() && this.props.onKeyUp) {
|
|
28
|
+
this.props.onKeyUp(key);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
componentWillUnmount() {
|
|
34
|
+
this.dispose();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
render() {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { keyOfMatchingRange, scale } from '../common/math';
|
|
2
|
+
import { BooleanLike, classes } from '../common/react';
|
|
3
|
+
import styles from '../styles/components/Knob.module.scss';
|
|
4
|
+
import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';
|
|
5
|
+
import { DraggableControl } from './DraggableControl';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
/** Value itself, controls the position of the cursor. */
|
|
9
|
+
value: number;
|
|
10
|
+
} & Partial<{
|
|
11
|
+
/** Animates the value if it was changed externally. */
|
|
12
|
+
animated: boolean;
|
|
13
|
+
/** Knob can be bipolar or unipolar. */
|
|
14
|
+
bipolar: boolean;
|
|
15
|
+
/** Color of the outer ring around the knob. */
|
|
16
|
+
color: string | BooleanLike;
|
|
17
|
+
/** If set, this value will be used to set the fill percentage of the outer ring independently of the main value. */
|
|
18
|
+
fillValue: number;
|
|
19
|
+
/** Format value using this function before displaying it. */
|
|
20
|
+
format: (value: number) => string;
|
|
21
|
+
/** Highest possible value. */
|
|
22
|
+
maxValue: number;
|
|
23
|
+
/** Lowest possible value. */
|
|
24
|
+
minValue: number;
|
|
25
|
+
/** Adjust value by this amount when dragging the input. */
|
|
26
|
+
onChange: (event: Event, value: number) => void;
|
|
27
|
+
/** An event, which fires about every 500ms when you drag the input up and down, on release and on manual editing. */
|
|
28
|
+
onDrag: (event: Event, value: number) => void;
|
|
29
|
+
/** Applies a `color` to the outer ring around the knob based on whether the value lands in the range between `from` and `to`. */
|
|
30
|
+
ranges: Record<string, [number, number]>;
|
|
31
|
+
/** Relative size of the knob. `1` is normal size, `2` is two times bigger. Fractional numbers are supported. */
|
|
32
|
+
size: number;
|
|
33
|
+
/** Adjust value by this amount when dragging the input. */
|
|
34
|
+
step: number;
|
|
35
|
+
/** Screen distance mouse needs to travel to adjust value by one `step`. */
|
|
36
|
+
stepPixelSize: number;
|
|
37
|
+
/** A number in milliseconds, for which the input will hold off from updating while events propagate through the backend. Default is about 250ms, increase it if you still see flickering. */
|
|
38
|
+
suppressFlicker: boolean;
|
|
39
|
+
/** Whether to clamp the value to the range. */
|
|
40
|
+
unclamped: boolean;
|
|
41
|
+
/** Unit to display to the right of value. */
|
|
42
|
+
unit: string;
|
|
43
|
+
}> &
|
|
44
|
+
BoxProps;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* ## Knob
|
|
48
|
+
* A radial control which allows dialing in precise values by dragging it
|
|
49
|
+
* up and down.
|
|
50
|
+
*
|
|
51
|
+
* Single click opens an input box to manually type in a number.
|
|
52
|
+
*/
|
|
53
|
+
export function Knob(props: Props) {
|
|
54
|
+
const {
|
|
55
|
+
// Draggable props (passthrough)
|
|
56
|
+
animated,
|
|
57
|
+
format,
|
|
58
|
+
maxValue,
|
|
59
|
+
minValue,
|
|
60
|
+
onChange,
|
|
61
|
+
onDrag,
|
|
62
|
+
step,
|
|
63
|
+
stepPixelSize,
|
|
64
|
+
suppressFlicker,
|
|
65
|
+
unclamped,
|
|
66
|
+
unit,
|
|
67
|
+
value,
|
|
68
|
+
// Own props
|
|
69
|
+
bipolar,
|
|
70
|
+
className,
|
|
71
|
+
color,
|
|
72
|
+
fillValue,
|
|
73
|
+
ranges = {},
|
|
74
|
+
size = 1,
|
|
75
|
+
style,
|
|
76
|
+
...rest
|
|
77
|
+
} = props;
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<DraggableControl
|
|
81
|
+
dragMatrix={[0, -1]}
|
|
82
|
+
{...{
|
|
83
|
+
animated,
|
|
84
|
+
format,
|
|
85
|
+
maxValue,
|
|
86
|
+
minValue,
|
|
87
|
+
onChange,
|
|
88
|
+
onDrag,
|
|
89
|
+
step,
|
|
90
|
+
stepPixelSize,
|
|
91
|
+
suppressFlicker,
|
|
92
|
+
unclamped,
|
|
93
|
+
unit,
|
|
94
|
+
value,
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
{(control) => {
|
|
98
|
+
const {
|
|
99
|
+
displayElement,
|
|
100
|
+
displayValue,
|
|
101
|
+
dragging,
|
|
102
|
+
handleDragStart,
|
|
103
|
+
inputElement,
|
|
104
|
+
value,
|
|
105
|
+
} = control;
|
|
106
|
+
const scaledFillValue = scale(
|
|
107
|
+
fillValue ?? displayValue,
|
|
108
|
+
minValue,
|
|
109
|
+
maxValue,
|
|
110
|
+
);
|
|
111
|
+
const scaledDisplayValue = scale(displayValue, minValue, maxValue);
|
|
112
|
+
const effectiveColor =
|
|
113
|
+
color || keyOfMatchingRange(fillValue ?? value, ranges) || 'default';
|
|
114
|
+
const rotation = Math.min((scaledDisplayValue - 0.5) * 270, 225);
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<div
|
|
118
|
+
className={classes([
|
|
119
|
+
styles.knob,
|
|
120
|
+
styles['color__' + effectiveColor],
|
|
121
|
+
bipolar && styles.bipolar,
|
|
122
|
+
className,
|
|
123
|
+
computeBoxClassName(rest),
|
|
124
|
+
])}
|
|
125
|
+
{...computeBoxProps({
|
|
126
|
+
style: {
|
|
127
|
+
fontSize: size + 'em',
|
|
128
|
+
...style,
|
|
129
|
+
},
|
|
130
|
+
...rest,
|
|
131
|
+
})}
|
|
132
|
+
onMouseDown={handleDragStart}
|
|
133
|
+
>
|
|
134
|
+
<div className={styles.circle}>
|
|
135
|
+
<div
|
|
136
|
+
className={styles.cursorBox}
|
|
137
|
+
style={{
|
|
138
|
+
transform: `rotate(${rotation}deg)`,
|
|
139
|
+
}}
|
|
140
|
+
>
|
|
141
|
+
<div className={styles.cursor} />
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
{dragging && (
|
|
145
|
+
<div className={styles.popupValue}>{displayElement}</div>
|
|
146
|
+
)}
|
|
147
|
+
<svg
|
|
148
|
+
className={classes([styles.ring, styles.ringTrackPivot])}
|
|
149
|
+
viewBox="0 0 100 100"
|
|
150
|
+
>
|
|
151
|
+
<circle className="Knob__ringTrack" cx="50" cy="50" r="50" />
|
|
152
|
+
</svg>
|
|
153
|
+
<svg
|
|
154
|
+
className={classes([styles.ring, styles.ringFillPivot])}
|
|
155
|
+
viewBox="0 0 100 100"
|
|
156
|
+
>
|
|
157
|
+
<circle
|
|
158
|
+
className={styles.ringFill}
|
|
159
|
+
style={{
|
|
160
|
+
strokeDashoffset: Math.max(
|
|
161
|
+
((bipolar ? 2.75 : 2.0) - scaledFillValue * 1.5) *
|
|
162
|
+
Math.PI *
|
|
163
|
+
50,
|
|
164
|
+
0,
|
|
165
|
+
),
|
|
166
|
+
}}
|
|
167
|
+
cx="50"
|
|
168
|
+
cy="50"
|
|
169
|
+
r="50"
|
|
170
|
+
/>
|
|
171
|
+
</svg>
|
|
172
|
+
{inputElement}
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
}}
|
|
176
|
+
</DraggableControl>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Flex, FlexProps } from './Flex';
|
|
2
|
+
|
|
3
|
+
export function LabeledControls(props: FlexProps) {
|
|
4
|
+
const { children, wrap, ...rest } = props;
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
<Flex
|
|
8
|
+
mx={-0.5}
|
|
9
|
+
wrap={wrap}
|
|
10
|
+
align="stretch"
|
|
11
|
+
justify="space-between"
|
|
12
|
+
{...rest}
|
|
13
|
+
>
|
|
14
|
+
{children}
|
|
15
|
+
</Flex>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ItemProps = {
|
|
20
|
+
label: string;
|
|
21
|
+
} & FlexProps;
|
|
22
|
+
|
|
23
|
+
function LabeledControlsItem(props: ItemProps) {
|
|
24
|
+
const { label, children, mx = 1, ...rest } = props;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Flex.Item mx={mx}>
|
|
28
|
+
<Flex
|
|
29
|
+
height="100%"
|
|
30
|
+
direction="column"
|
|
31
|
+
align="center"
|
|
32
|
+
textAlign="center"
|
|
33
|
+
justify="space-between"
|
|
34
|
+
{...rest}
|
|
35
|
+
>
|
|
36
|
+
<Flex.Item />
|
|
37
|
+
<Flex.Item>{children}</Flex.Item>
|
|
38
|
+
<Flex.Item color="label">{label}</Flex.Item>
|
|
39
|
+
</Flex>
|
|
40
|
+
</Flex.Item>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
LabeledControls.Item = LabeledControlsItem;
|