tgui-core 1.1.11 → 1.1.13

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.
Files changed (292) hide show
  1. package/dist/ProgressBar.module-BkAFfFy0.js +29 -0
  2. package/dist/Section.module-CLVHJ4yA.js +15 -0
  3. package/dist/assets/BlockQuote.css +1 -0
  4. package/dist/assets/Button.css +1 -0
  5. package/dist/assets/ColorBox.css +1 -0
  6. package/dist/assets/Dialog.css +1 -0
  7. package/dist/assets/Dimmer.css +1 -0
  8. package/dist/assets/Divider.css +1 -0
  9. package/dist/assets/Flex.css +1 -0
  10. package/dist/assets/Icon.css +6 -0
  11. package/dist/assets/Input.css +1 -0
  12. package/dist/assets/Knob.css +1 -0
  13. package/dist/assets/LabeledList.css +1 -0
  14. package/dist/assets/MenuBar.css +1 -0
  15. package/dist/assets/Modal.css +1 -0
  16. package/dist/assets/NoticeBox.css +1 -0
  17. package/dist/assets/NumberInput.css +1 -0
  18. package/dist/assets/ProgressBar.css +1 -0
  19. package/dist/assets/RoundGauge.css +1 -0
  20. package/dist/assets/Section.css +1 -0
  21. package/dist/assets/Slider.css +1 -0
  22. package/dist/assets/Stack.css +1 -0
  23. package/dist/assets/Table.css +1 -0
  24. package/dist/assets/Tabs.css +1 -0
  25. package/dist/assets/TextArea.css +1 -0
  26. package/dist/assets/Tooltip.css +1 -0
  27. package/dist/common/assets.d.ts +4 -0
  28. package/dist/common/assets.js +25 -0
  29. package/dist/common/collections.d.ts +10 -0
  30. package/dist/common/collections.js +15 -0
  31. package/dist/common/color.d.ts +25 -0
  32. package/dist/common/color.js +69 -0
  33. package/dist/common/constants.d.ts +102 -0
  34. package/dist/common/constants.js +312 -0
  35. package/dist/common/events.d.ts +33 -0
  36. package/dist/common/events.js +147 -0
  37. package/{lib/common/exhaustive.ts → dist/common/exhaustive.d.ts} +1 -3
  38. package/dist/common/exhaustive.js +6 -0
  39. package/dist/common/format.d.ts +11 -0
  40. package/dist/common/format.js +114 -0
  41. package/{lib/common/fp.ts → dist/common/fp.d.ts} +2 -16
  42. package/dist/common/fp.js +9 -0
  43. package/dist/common/hotkeys.d.ts +25 -0
  44. package/dist/common/hotkeys.js +112 -0
  45. package/dist/common/http.d.ts +4 -0
  46. package/dist/common/http.js +10 -0
  47. package/dist/common/keycodes.d.ts +85 -0
  48. package/dist/common/keycodes.js +88 -0
  49. package/{lib/common/keys.ts → dist/common/keys.d.ts} +21 -24
  50. package/dist/common/keys.js +8 -0
  51. package/dist/common/math.d.ts +39 -0
  52. package/dist/common/math.js +41 -0
  53. package/dist/common/perf.d.ts +24 -0
  54. package/dist/common/perf.js +33 -0
  55. package/dist/common/random.d.ts +16 -0
  56. package/dist/common/random.js +18 -0
  57. package/dist/common/react.d.ts +23 -0
  58. package/dist/common/react.js +30 -0
  59. package/dist/common/redux.d.ts +64 -0
  60. package/dist/common/redux.js +72 -0
  61. package/dist/common/storage.d.ts +24 -0
  62. package/dist/common/storage.js +133 -0
  63. package/dist/common/string.d.ts +65 -0
  64. package/dist/common/string.js +83 -0
  65. package/dist/common/timer.d.ts +18 -0
  66. package/dist/common/timer.js +28 -0
  67. package/dist/common/type-utils.d.ts +9 -0
  68. package/dist/common/type-utils.js +25 -0
  69. package/dist/common/uuid.d.ts +9 -0
  70. package/dist/common/uuid.js +10 -0
  71. package/dist/components/AnimatedNumber.d.ts +60 -0
  72. package/dist/components/AnimatedNumber.js +76 -0
  73. package/dist/components/Autofocus.d.ts +4 -0
  74. package/dist/components/Autofocus.js +17 -0
  75. package/dist/components/Blink.d.ts +26 -0
  76. package/dist/components/Blink.js +56 -0
  77. package/dist/components/BlockQuote.d.ts +3 -0
  78. package/dist/components/BlockQuote.js +13 -0
  79. package/dist/components/BodyZoneSelector.d.ts +28 -0
  80. package/dist/components/BodyZoneSelector.js +115 -0
  81. package/dist/components/Box.d.ts +91 -0
  82. package/dist/components/Box.js +133 -0
  83. package/dist/components/Button.d.ts +93 -0
  84. package/dist/components/Button.js +298 -0
  85. package/dist/components/ByondUi.js +73 -0
  86. package/dist/components/Chart.d.ts +28 -0
  87. package/dist/components/Chart.js +95 -0
  88. package/dist/components/Collapsible.d.ts +15 -0
  89. package/dist/components/Collapsible.js +27 -0
  90. package/dist/components/ColorBox.d.ts +8 -0
  91. package/dist/components/ColorBox.js +24 -0
  92. package/dist/components/Dialog.d.ts +24 -0
  93. package/dist/components/Dialog.js +67 -0
  94. package/dist/components/Dimmer.d.ts +3 -0
  95. package/dist/components/Dimmer.js +13 -0
  96. package/dist/components/Divider.d.ts +6 -0
  97. package/dist/components/Divider.js +22 -0
  98. package/dist/components/DmIcon.d.ts +33 -0
  99. package/dist/components/DmIcon.js +29 -0
  100. package/dist/components/DraggableControl.js +176 -0
  101. package/dist/components/Dropdown.d.ts +48 -0
  102. package/dist/components/Dropdown.js +152 -0
  103. package/dist/components/FakeTerminal.js +38 -0
  104. package/dist/components/FitText.d.ts +22 -0
  105. package/dist/components/FitText.js +63 -0
  106. package/dist/components/Flex.d.ts +93 -0
  107. package/dist/components/Flex.js +72 -0
  108. package/dist/components/Icon.d.ts +30 -0
  109. package/dist/components/Icon.js +51 -0
  110. package/dist/components/Image.d.ts +14 -0
  111. package/dist/components/Image.js +35 -0
  112. package/dist/components/InfinitePlane.js +139 -0
  113. package/dist/components/Input.d.ts +61 -0
  114. package/dist/components/Input.js +89 -0
  115. package/dist/components/KeyListener.d.ts +15 -0
  116. package/dist/components/KeyListener.js +23 -0
  117. package/dist/components/Knob.d.ts +49 -0
  118. package/dist/components/Knob.js +162 -0
  119. package/dist/components/LabeledControls.d.ts +11 -0
  120. package/dist/components/LabeledControls.js +39 -0
  121. package/dist/components/LabeledList.d.ts +57 -0
  122. package/dist/components/LabeledList.js +94 -0
  123. package/dist/components/MenuBar.d.ts +28 -0
  124. package/dist/components/MenuBar.js +174 -0
  125. package/dist/components/Modal.d.ts +3 -0
  126. package/dist/components/Modal.js +25 -0
  127. package/dist/components/NoticeBox.d.ts +20 -0
  128. package/dist/components/NoticeBox.js +49 -0
  129. package/dist/components/NumberInput.d.ts +45 -0
  130. package/dist/components/NumberInput.js +221 -0
  131. package/dist/components/Popper.d.ts +27 -0
  132. package/dist/components/Popper.js +177 -0
  133. package/dist/components/ProgressBar.d.ts +46 -0
  134. package/dist/components/ProgressBar.js +37 -0
  135. package/dist/components/RestrictedInput.js +155 -0
  136. package/dist/components/RoundGauge.d.ts +53 -0
  137. package/dist/components/RoundGauge.js +147 -0
  138. package/dist/components/Section.d.ts +63 -0
  139. package/dist/components/Section.js +62 -0
  140. package/dist/components/Slider.d.ts +46 -0
  141. package/dist/components/Slider.js +124 -0
  142. package/dist/components/Stack.d.ts +27 -0
  143. package/dist/components/Stack.js +67 -0
  144. package/dist/components/StyleableSection.d.ts +11 -0
  145. package/dist/components/StyleableSection.js +16 -0
  146. package/dist/components/Table.d.ts +29 -0
  147. package/dist/components/Table.js +67 -0
  148. package/dist/components/Tabs.d.ts +23 -0
  149. package/dist/components/Tabs.js +89 -0
  150. package/dist/components/TextArea.d.ts +39 -0
  151. package/dist/components/TextArea.js +118 -0
  152. package/dist/components/TimeDisplay.js +34 -0
  153. package/dist/components/Tooltip.d.ts +29 -0
  154. package/dist/components/Tooltip.js +83 -0
  155. package/dist/components/TrackOutsideClicks.d.ts +13 -0
  156. package/dist/components/TrackOutsideClicks.js +24 -0
  157. package/dist/components/VirtualList.d.ts +8 -0
  158. package/dist/components/VirtualList.js +34 -0
  159. package/dist/components/index.js +92 -0
  160. package/dist/popper-CiqSDJTE.js +906 -0
  161. package/package.json +8 -10
  162. package/lib/common/assets.ts +0 -38
  163. package/lib/common/collections.ts +0 -27
  164. package/lib/common/color.ts +0 -88
  165. package/lib/common/constants.ts +0 -349
  166. package/lib/common/events.ts +0 -262
  167. package/lib/common/format.ts +0 -167
  168. package/lib/common/hotkeys.ts +0 -207
  169. package/lib/common/http.ts +0 -16
  170. package/lib/common/keycodes.ts +0 -86
  171. package/lib/common/math.ts +0 -76
  172. package/lib/common/perf.ts +0 -72
  173. package/lib/common/random.ts +0 -32
  174. package/lib/common/react.ts +0 -59
  175. package/lib/common/redux.ts +0 -187
  176. package/lib/common/storage.ts +0 -207
  177. package/lib/common/string.ts +0 -169
  178. package/lib/common/timer.ts +0 -63
  179. package/lib/common/type-utils.ts +0 -41
  180. package/lib/common/types.d.ts +0 -12
  181. package/lib/common/uuid.ts +0 -18
  182. package/lib/components/AnimatedNumber.tsx +0 -180
  183. package/lib/components/Autofocus.tsx +0 -23
  184. package/lib/components/Blink.tsx +0 -91
  185. package/lib/components/BlockQuote.tsx +0 -9
  186. package/lib/components/BodyZoneSelector.tsx +0 -149
  187. package/lib/components/Box.tsx +0 -252
  188. package/lib/components/Button.tsx +0 -425
  189. package/lib/components/ByondUi.jsx +0 -110
  190. package/lib/components/Chart.tsx +0 -155
  191. package/lib/components/Collapsible.tsx +0 -43
  192. package/lib/components/ColorBox.tsx +0 -29
  193. package/lib/components/Dialog.tsx +0 -81
  194. package/lib/components/Dimmer.tsx +0 -13
  195. package/lib/components/Divider.tsx +0 -20
  196. package/lib/components/DmIcon.tsx +0 -86
  197. package/lib/components/DraggableControl.jsx +0 -276
  198. package/lib/components/Dropdown.tsx +0 -246
  199. package/lib/components/FakeTerminal.jsx +0 -52
  200. package/lib/components/FitText.tsx +0 -99
  201. package/lib/components/Flex.tsx +0 -159
  202. package/lib/components/Icon.tsx +0 -95
  203. package/lib/components/Image.tsx +0 -54
  204. package/lib/components/InfinitePlane.jsx +0 -192
  205. package/lib/components/Input.tsx +0 -176
  206. package/lib/components/KeyListener.tsx +0 -40
  207. package/lib/components/Knob.tsx +0 -178
  208. package/lib/components/LabeledControls.tsx +0 -44
  209. package/lib/components/LabeledList.tsx +0 -154
  210. package/lib/components/MenuBar.tsx +0 -228
  211. package/lib/components/Modal.tsx +0 -23
  212. package/lib/components/NoticeBox.tsx +0 -45
  213. package/lib/components/NumberInput.tsx +0 -328
  214. package/lib/components/Popper.tsx +0 -100
  215. package/lib/components/ProgressBar.tsx +0 -105
  216. package/lib/components/RestrictedInput.jsx +0 -301
  217. package/lib/components/RoundGauge.tsx +0 -180
  218. package/lib/components/Section.tsx +0 -120
  219. package/lib/components/Slider.tsx +0 -169
  220. package/lib/components/Stack.tsx +0 -96
  221. package/lib/components/StyleableSection.tsx +0 -33
  222. package/lib/components/Table.tsx +0 -84
  223. package/lib/components/Tabs.tsx +0 -89
  224. package/lib/components/TextArea.tsx +0 -182
  225. package/lib/components/TimeDisplay.jsx +0 -64
  226. package/lib/components/Tooltip.tsx +0 -152
  227. package/lib/components/TrackOutsideClicks.tsx +0 -35
  228. package/lib/components/VirtualList.tsx +0 -69
  229. package/lib/styles/atomic/candystripe.scss +0 -8
  230. package/lib/styles/atomic/centered-image.scss +0 -7
  231. package/lib/styles/atomic/color.scss +0 -21
  232. package/lib/styles/atomic/debug-layout.scss +0 -17
  233. package/lib/styles/atomic/fit-text.scss +0 -14
  234. package/lib/styles/atomic/links.scss +0 -12
  235. package/lib/styles/atomic/outline.scss +0 -47
  236. package/lib/styles/atomic/text.scss +0 -44
  237. package/lib/styles/base.scss +0 -32
  238. package/lib/styles/colors.scss +0 -92
  239. package/lib/styles/components/BlockQuote.module.scss +0 -20
  240. package/lib/styles/components/BlockQuote.module.scss.d.ts +0 -4
  241. package/lib/styles/components/Button.module.scss +0 -157
  242. package/lib/styles/components/Button.module.scss.d.ts +0 -46
  243. package/lib/styles/components/ColorBox.module.scss +0 -12
  244. package/lib/styles/components/ColorBox.module.scss.d.ts +0 -4
  245. package/lib/styles/components/Dialog.module.scss +0 -60
  246. package/lib/styles/components/Dialog.module.scss.d.ts +0 -10
  247. package/lib/styles/components/Dimmer.module.scss +0 -22
  248. package/lib/styles/components/Dimmer.module.scss.d.ts +0 -4
  249. package/lib/styles/components/Divider.module.scss +0 -27
  250. package/lib/styles/components/Divider.module.scss.d.ts +0 -6
  251. package/lib/styles/components/Dropdown.scss +0 -72
  252. package/lib/styles/components/Flex.module.scss +0 -13
  253. package/lib/styles/components/Flex.module.scss.d.ts +0 -5
  254. package/lib/styles/components/Icon.module.scss +0 -25
  255. package/lib/styles/components/Icon.module.scss.d.ts +0 -5
  256. package/lib/styles/components/Input.module.scss +0 -64
  257. package/lib/styles/components/Input.module.scss.d.ts +0 -8
  258. package/lib/styles/components/Knob.module.scss +0 -131
  259. package/lib/styles/components/Knob.module.scss.d.ts +0 -33
  260. package/lib/styles/components/LabeledList.module.scss +0 -49
  261. package/lib/styles/components/LabeledList.module.scss.d.ts +0 -8
  262. package/lib/styles/components/MenuBar.module.scss +0 -75
  263. package/lib/styles/components/MenuBar.module.scss.d.ts +0 -14
  264. package/lib/styles/components/Modal.module.scss +0 -14
  265. package/lib/styles/components/Modal.module.scss.d.ts +0 -4
  266. package/lib/styles/components/NoticeBox.module.scss +0 -65
  267. package/lib/styles/components/NoticeBox.module.scss.d.ts +0 -27
  268. package/lib/styles/components/NumberInput.module.scss +0 -71
  269. package/lib/styles/components/NumberInput.module.scss.d.ts +0 -9
  270. package/lib/styles/components/ProgressBar.module.scss +0 -63
  271. package/lib/styles/components/ProgressBar.module.scss.d.ts +0 -27
  272. package/lib/styles/components/RoundGauge.module.scss +0 -85
  273. package/lib/styles/components/RoundGauge.module.scss.d.ts +0 -49
  274. package/lib/styles/components/Section.module.scss +0 -130
  275. package/lib/styles/components/Section.module.scss.d.ts +0 -13
  276. package/lib/styles/components/Slider.module.scss +0 -54
  277. package/lib/styles/components/Slider.module.scss.d.ts +0 -8
  278. package/lib/styles/components/Stack.module.scss +0 -60
  279. package/lib/styles/components/Stack.module.scss.d.ts +0 -12
  280. package/lib/styles/components/Table.module.scss +0 -44
  281. package/lib/styles/components/Table.module.scss.d.ts +0 -10
  282. package/lib/styles/components/Tabs.module.scss +0 -144
  283. package/lib/styles/components/Tabs.module.scss.d.ts +0 -35
  284. package/lib/styles/components/TextArea.module.scss +0 -86
  285. package/lib/styles/components/TextArea.module.scss.d.ts +0 -11
  286. package/lib/styles/components/Tooltip.module.scss +0 -24
  287. package/lib/styles/components/Tooltip.module.scss.d.ts +0 -4
  288. package/lib/styles/functions.scss +0 -79
  289. package/lib/styles/input.scss +0 -9
  290. package/lib/styles/main.scss +0 -20
  291. package/lib/styles/reset.scss +0 -68
  292. /package/{lib/components/index.ts → dist/components/index.d.ts} +0 -0
@@ -1,192 +0,0 @@
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
- }
@@ -1,176 +0,0 @@
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
- }
@@ -1,40 +0,0 @@
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
- }
@@ -1,178 +0,0 @@
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
- }
@@ -1,44 +0,0 @@
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;