tgui-core 1.0.0
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/.editorconfig +10 -0
- package/.eslintrc.cjs +78 -0
- package/.gitattributes +4 -0
- package/.prettierrc.yml +1 -0
- package/.vscode/extensions.json +6 -0
- package/.vscode/settings.json +5 -0
- package/README.md +1 -0
- package/global.d.ts +173 -0
- package/package.json +25 -0
- package/src/assets.ts +43 -0
- package/src/backend.ts +369 -0
- package/src/common/collections.ts +349 -0
- package/src/common/color.ts +94 -0
- package/src/common/events.ts +45 -0
- package/src/common/exhaustive.ts +19 -0
- package/src/common/fp.ts +38 -0
- package/src/common/keycodes.ts +86 -0
- package/src/common/keys.ts +39 -0
- package/src/common/math.ts +98 -0
- package/src/common/perf.ts +72 -0
- package/src/common/random.ts +32 -0
- package/src/common/react.ts +65 -0
- package/src/common/redux.ts +196 -0
- package/src/common/storage.js +196 -0
- package/src/common/string.ts +173 -0
- package/src/common/timer.ts +68 -0
- package/src/common/type-utils.ts +41 -0
- package/src/common/types.ts +9 -0
- package/src/common/uuid.ts +24 -0
- package/src/common/vector.ts +51 -0
- package/src/components/AnimatedNumber.tsx +185 -0
- package/src/components/Autofocus.tsx +23 -0
- package/src/components/Blink.jsx +69 -0
- package/src/components/BlockQuote.tsx +15 -0
- package/src/components/BodyZoneSelector.tsx +149 -0
- package/src/components/Box.tsx +255 -0
- package/src/components/Button.tsx +415 -0
- package/src/components/ByondUi.jsx +121 -0
- package/src/components/Chart.tsx +160 -0
- package/src/components/Collapsible.tsx +45 -0
- package/src/components/ColorBox.tsx +30 -0
- package/src/components/Dialog.tsx +85 -0
- package/src/components/Dimmer.tsx +19 -0
- package/src/components/Divider.tsx +26 -0
- package/src/components/DmIcon.tsx +72 -0
- package/src/components/DraggableControl.jsx +282 -0
- package/src/components/Dropdown.tsx +246 -0
- package/src/components/FakeTerminal.jsx +52 -0
- package/src/components/FitText.tsx +99 -0
- package/src/components/Flex.tsx +105 -0
- package/src/components/Grid.tsx +44 -0
- package/src/components/Icon.tsx +91 -0
- package/src/components/Image.tsx +63 -0
- package/src/components/InfinitePlane.jsx +192 -0
- package/src/components/Input.tsx +181 -0
- package/src/components/KeyListener.tsx +40 -0
- package/src/components/Knob.tsx +185 -0
- package/src/components/LabeledControls.tsx +50 -0
- package/src/components/LabeledList.tsx +130 -0
- package/src/components/MenuBar.tsx +238 -0
- package/src/components/Modal.tsx +25 -0
- package/src/components/NoticeBox.tsx +48 -0
- package/src/components/NumberInput.tsx +328 -0
- package/src/components/Popper.tsx +100 -0
- package/src/components/ProgressBar.tsx +79 -0
- package/src/components/RestrictedInput.jsx +301 -0
- package/src/components/RoundGauge.tsx +189 -0
- package/src/components/Section.tsx +125 -0
- package/src/components/Slider.tsx +173 -0
- package/src/components/Stack.tsx +101 -0
- package/src/components/StyleableSection.tsx +30 -0
- package/src/components/Table.tsx +90 -0
- package/src/components/Tabs.tsx +90 -0
- package/src/components/TextArea.tsx +198 -0
- package/src/components/TimeDisplay.jsx +64 -0
- package/src/components/Tooltip.tsx +147 -0
- package/src/components/TrackOutsideClicks.tsx +35 -0
- package/src/components/VirtualList.tsx +69 -0
- package/src/constants.ts +355 -0
- package/src/debug/KitchenSink.jsx +56 -0
- package/src/debug/actions.js +11 -0
- package/src/debug/hooks.js +10 -0
- package/src/debug/index.ts +10 -0
- package/src/debug/middleware.js +86 -0
- package/src/debug/reducer.js +22 -0
- package/src/debug/selectors.js +7 -0
- package/src/drag.ts +280 -0
- package/src/events.ts +237 -0
- package/src/focus.ts +25 -0
- package/src/format.ts +173 -0
- package/src/hotkeys.ts +212 -0
- package/src/http.ts +16 -0
- package/src/layouts/Layout.tsx +75 -0
- package/src/layouts/NtosWindow.tsx +162 -0
- package/src/layouts/Pane.tsx +56 -0
- package/src/layouts/Window.tsx +227 -0
- package/src/renderer.ts +50 -0
- package/styles/base.scss +32 -0
- package/styles/colors.scss +92 -0
- package/styles/components/BlockQuote.scss +20 -0
- package/styles/components/Button.scss +175 -0
- package/styles/components/ColorBox.scss +12 -0
- package/styles/components/Dialog.scss +105 -0
- package/styles/components/Dimmer.scss +22 -0
- package/styles/components/Divider.scss +27 -0
- package/styles/components/Dropdown.scss +72 -0
- package/styles/components/Flex.scss +31 -0
- package/styles/components/Icon.scss +25 -0
- package/styles/components/Input.scss +68 -0
- package/styles/components/Knob.scss +131 -0
- package/styles/components/LabeledList.scss +49 -0
- package/styles/components/MenuBar.scss +75 -0
- package/styles/components/Modal.scss +14 -0
- package/styles/components/NoticeBox.scss +65 -0
- package/styles/components/NumberInput.scss +76 -0
- package/styles/components/ProgressBar.scss +63 -0
- package/styles/components/RoundGauge.scss +88 -0
- package/styles/components/Section.scss +143 -0
- package/styles/components/Slider.scss +54 -0
- package/styles/components/Stack.scss +59 -0
- package/styles/components/Table.scss +44 -0
- package/styles/components/Tabs.scss +144 -0
- package/styles/components/TextArea.scss +84 -0
- package/styles/components/Tooltip.scss +24 -0
- package/styles/functions.scss +79 -0
- package/styles/layouts/Layout.scss +57 -0
- package/styles/layouts/NtosHeader.scss +20 -0
- package/styles/layouts/NtosWindow.scss +26 -0
- package/styles/layouts/TitleBar.scss +111 -0
- package/styles/layouts/Window.scss +103 -0
- package/styles/main.scss +97 -0
- package/styles/reset.scss +68 -0
- package/styles/themes/abductor.scss +68 -0
- package/styles/themes/admin.scss +38 -0
- package/styles/themes/cardtable.scss +57 -0
- package/styles/themes/hackerman.scss +70 -0
- package/styles/themes/malfunction.scss +67 -0
- package/styles/themes/neutral.scss +50 -0
- package/styles/themes/ntOS95.scss +166 -0
- package/styles/themes/ntos.scss +44 -0
- package/styles/themes/ntos_cat.scss +148 -0
- package/styles/themes/ntos_darkmode.scss +44 -0
- package/styles/themes/ntos_lightmode.scss +67 -0
- package/styles/themes/ntos_spooky.scss +69 -0
- package/styles/themes/ntos_synth.scss +99 -0
- package/styles/themes/ntos_terminal.scss +112 -0
- package/styles/themes/paper.scss +184 -0
- package/styles/themes/retro.scss +72 -0
- package/styles/themes/spookyconsole.scss +73 -0
- package/styles/themes/syndicate.scss +67 -0
- package/styles/themes/wizard.scss +68 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @copyright 2020 Aleksej Komarov
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { shallowDiffers } from '../common/react';
|
|
8
|
+
import { debounce } from '../common/timer';
|
|
9
|
+
import { Component, createRef } from 'react';
|
|
10
|
+
|
|
11
|
+
import { computeBoxProps } from './Box';
|
|
12
|
+
|
|
13
|
+
const logger = createLogger('ByondUi');
|
|
14
|
+
|
|
15
|
+
// Stack of currently allocated BYOND UI element ids.
|
|
16
|
+
const byondUiStack = [];
|
|
17
|
+
|
|
18
|
+
const createByondUiElement = (elementId) => {
|
|
19
|
+
// Reserve an index in the stack
|
|
20
|
+
const index = byondUiStack.length;
|
|
21
|
+
byondUiStack.push(null);
|
|
22
|
+
// Get a unique id
|
|
23
|
+
const id = elementId || 'byondui_' + index;
|
|
24
|
+
// Return a control structure
|
|
25
|
+
return {
|
|
26
|
+
render: (params) => {
|
|
27
|
+
logger.log(`rendering '${id}'`);
|
|
28
|
+
byondUiStack[index] = id;
|
|
29
|
+
Byond.winset(id, params);
|
|
30
|
+
},
|
|
31
|
+
unmount: () => {
|
|
32
|
+
logger.log(`unmounting '${id}'`);
|
|
33
|
+
byondUiStack[index] = null;
|
|
34
|
+
Byond.winset(id, {
|
|
35
|
+
parent: '',
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
window.addEventListener('beforeunload', () => {
|
|
42
|
+
// Cleanly unmount all visible UI elements
|
|
43
|
+
for (let index = 0; index < byondUiStack.length; index++) {
|
|
44
|
+
const id = byondUiStack[index];
|
|
45
|
+
if (typeof id === 'string') {
|
|
46
|
+
logger.log(`unmounting '${id}' (beforeunload)`);
|
|
47
|
+
byondUiStack[index] = null;
|
|
48
|
+
Byond.winset(id, {
|
|
49
|
+
parent: '',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get the bounding box of the DOM element in display-pixels.
|
|
57
|
+
*/
|
|
58
|
+
const getBoundingBox = (element) => {
|
|
59
|
+
const pixelRatio = window.devicePixelRatio ?? 1;
|
|
60
|
+
const rect = element.getBoundingClientRect();
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
pos: [rect.left * pixelRatio, rect.top * pixelRatio],
|
|
64
|
+
size: [
|
|
65
|
+
(rect.right - rect.left) * pixelRatio,
|
|
66
|
+
(rect.bottom - rect.top) * pixelRatio,
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export class ByondUi extends Component {
|
|
72
|
+
constructor(props) {
|
|
73
|
+
super(props);
|
|
74
|
+
this.containerRef = createRef();
|
|
75
|
+
this.byondUiElement = createByondUiElement(props.params?.id);
|
|
76
|
+
this.handleResize = debounce(() => {
|
|
77
|
+
this.forceUpdate();
|
|
78
|
+
}, 100);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
shouldComponentUpdate(nextProps) {
|
|
82
|
+
const { params: prevParams = {}, ...prevRest } = this.props;
|
|
83
|
+
const { params: nextParams = {}, ...nextRest } = nextProps;
|
|
84
|
+
return (
|
|
85
|
+
shallowDiffers(prevParams, nextParams) ||
|
|
86
|
+
shallowDiffers(prevRest, nextRest)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
componentDidMount() {
|
|
91
|
+
window.addEventListener('resize', this.handleResize);
|
|
92
|
+
this.componentDidUpdate();
|
|
93
|
+
this.handleResize();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
componentDidUpdate() {
|
|
97
|
+
const { params = {} } = this.props;
|
|
98
|
+
const box = getBoundingBox(this.containerRef.current);
|
|
99
|
+
this.byondUiElement.render({
|
|
100
|
+
parent: Byond.windowId,
|
|
101
|
+
...params,
|
|
102
|
+
pos: box.pos[0] + ',' + box.pos[1],
|
|
103
|
+
size: box.size[0] + 'x' + box.size[1],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
componentWillUnmount() {
|
|
108
|
+
window.removeEventListener('resize', this.handleResize);
|
|
109
|
+
this.byondUiElement.unmount();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
render() {
|
|
113
|
+
const { params, ...rest } = this.props;
|
|
114
|
+
return (
|
|
115
|
+
<div ref={this.containerRef} {...computeBoxProps(rest)}>
|
|
116
|
+
{/* Filler */}
|
|
117
|
+
<div style={{ minHeight: '22px' }} />
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @copyright 2020 Aleksej Komarov
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { map, zip } from '../common/collections';
|
|
8
|
+
import { Component, createRef, RefObject } from 'react';
|
|
9
|
+
|
|
10
|
+
import { Box, BoxProps } from './Box';
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
data: number[][];
|
|
14
|
+
} & Partial<{
|
|
15
|
+
fillColor: string;
|
|
16
|
+
rangeX: [number, number];
|
|
17
|
+
rangeY: [number, number];
|
|
18
|
+
strokeColor: string;
|
|
19
|
+
strokeWidth: number;
|
|
20
|
+
}> &
|
|
21
|
+
BoxProps;
|
|
22
|
+
|
|
23
|
+
type State = {
|
|
24
|
+
viewBox: [number, number];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type Point = number[];
|
|
28
|
+
type Range = [number, number];
|
|
29
|
+
|
|
30
|
+
const normalizeData = (
|
|
31
|
+
data: Point[],
|
|
32
|
+
scale: number[],
|
|
33
|
+
rangeX?: Range,
|
|
34
|
+
rangeY?: Range
|
|
35
|
+
) => {
|
|
36
|
+
if (data.length === 0) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const min = map(zip(...data), (p) => Math.min(...p));
|
|
41
|
+
const max = map(zip(...data), (p) => Math.max(...p));
|
|
42
|
+
|
|
43
|
+
if (rangeX !== undefined) {
|
|
44
|
+
min[0] = rangeX[0];
|
|
45
|
+
max[0] = rangeX[1];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (rangeY !== undefined) {
|
|
49
|
+
min[1] = rangeY[0];
|
|
50
|
+
max[1] = rangeY[1];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const normalized = map(data, (point) =>
|
|
54
|
+
map(
|
|
55
|
+
zip(point, min, max, scale),
|
|
56
|
+
([value, min, max, scale]) => ((value - min) / (max - min)) * scale
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return normalized;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const dataToPolylinePoints = (data) => {
|
|
64
|
+
let points = '';
|
|
65
|
+
for (let i = 0; i < data.length; i++) {
|
|
66
|
+
const point = data[i];
|
|
67
|
+
points += point[0] + ',' + point[1] + ' ';
|
|
68
|
+
}
|
|
69
|
+
return points;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
class LineChart extends Component<Props> {
|
|
73
|
+
ref: RefObject<HTMLDivElement>;
|
|
74
|
+
state: State;
|
|
75
|
+
|
|
76
|
+
constructor(props: Props) {
|
|
77
|
+
super(props);
|
|
78
|
+
this.ref = createRef();
|
|
79
|
+
this.state = {
|
|
80
|
+
// Initial guess
|
|
81
|
+
viewBox: [600, 200],
|
|
82
|
+
};
|
|
83
|
+
this.handleResize = this.handleResize.bind(this);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
componentDidMount() {
|
|
87
|
+
window.addEventListener('resize', this.handleResize);
|
|
88
|
+
this.handleResize();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
componentWillUnmount() {
|
|
92
|
+
window.removeEventListener('resize', this.handleResize);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
handleResize = () => {
|
|
96
|
+
const element = this.ref.current;
|
|
97
|
+
if (!element) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.setState({
|
|
101
|
+
viewBox: [element.offsetWidth, element.offsetHeight],
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
render() {
|
|
106
|
+
const {
|
|
107
|
+
data = [],
|
|
108
|
+
rangeX,
|
|
109
|
+
rangeY,
|
|
110
|
+
fillColor = 'none',
|
|
111
|
+
strokeColor = '#ffffff',
|
|
112
|
+
strokeWidth = 2,
|
|
113
|
+
...rest
|
|
114
|
+
} = this.props;
|
|
115
|
+
const { viewBox } = this.state;
|
|
116
|
+
const normalized = normalizeData(data, viewBox, rangeX, rangeY);
|
|
117
|
+
// Push data outside viewBox and form a fillable polygon
|
|
118
|
+
if (normalized.length > 0) {
|
|
119
|
+
const first = normalized[0];
|
|
120
|
+
const last = normalized[normalized.length - 1];
|
|
121
|
+
normalized.push([viewBox[0] + strokeWidth, last[1]]);
|
|
122
|
+
normalized.push([viewBox[0] + strokeWidth, -strokeWidth]);
|
|
123
|
+
normalized.push([-strokeWidth, -strokeWidth]);
|
|
124
|
+
normalized.push([-strokeWidth, first[1]]);
|
|
125
|
+
}
|
|
126
|
+
const points = dataToPolylinePoints(normalized);
|
|
127
|
+
const divProps = { ...rest, className: '', ref: this.ref };
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<Box position="relative" {...rest}>
|
|
131
|
+
<Box {...divProps}>
|
|
132
|
+
<svg
|
|
133
|
+
viewBox={`0 0 ${viewBox[0]} ${viewBox[1]}`}
|
|
134
|
+
preserveAspectRatio="none"
|
|
135
|
+
style={{
|
|
136
|
+
position: 'absolute',
|
|
137
|
+
top: 0,
|
|
138
|
+
left: 0,
|
|
139
|
+
right: 0,
|
|
140
|
+
bottom: 0,
|
|
141
|
+
overflow: 'hidden',
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<polyline
|
|
145
|
+
transform={`scale(1, -1) translate(0, -${viewBox[1]})`}
|
|
146
|
+
fill={fillColor}
|
|
147
|
+
stroke={strokeColor}
|
|
148
|
+
strokeWidth={strokeWidth}
|
|
149
|
+
points={points}
|
|
150
|
+
/>
|
|
151
|
+
</svg>
|
|
152
|
+
</Box>
|
|
153
|
+
</Box>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const Chart = {
|
|
159
|
+
Line: LineChart,
|
|
160
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @copyright 2020 Aleksej Komarov
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { ReactNode, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Box, BoxProps } from './Box';
|
|
10
|
+
import { Button } from './Button';
|
|
11
|
+
|
|
12
|
+
type Props = Partial<{
|
|
13
|
+
buttons: ReactNode;
|
|
14
|
+
open: boolean;
|
|
15
|
+
title: ReactNode;
|
|
16
|
+
icon: string;
|
|
17
|
+
}> &
|
|
18
|
+
BoxProps;
|
|
19
|
+
|
|
20
|
+
export function Collapsible(props: Props) {
|
|
21
|
+
const { children, color, title, buttons, icon, ...rest } = props;
|
|
22
|
+
const [open, setOpen] = useState(props.open);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Box mb={1}>
|
|
26
|
+
<div className="Table">
|
|
27
|
+
<div className="Table__cell">
|
|
28
|
+
<Button
|
|
29
|
+
fluid
|
|
30
|
+
color={color}
|
|
31
|
+
icon={icon ? icon : open ? 'chevron-down' : 'chevron-right'}
|
|
32
|
+
onClick={() => setOpen(!open)}
|
|
33
|
+
{...rest}
|
|
34
|
+
>
|
|
35
|
+
{title}
|
|
36
|
+
</Button>
|
|
37
|
+
</div>
|
|
38
|
+
{buttons && (
|
|
39
|
+
<div className="Table__cell Table__cell--collapsing">{buttons}</div>
|
|
40
|
+
)}
|
|
41
|
+
</div>
|
|
42
|
+
{open && <Box mt={1}>{children}</Box>}
|
|
43
|
+
</Box>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @copyright 2020 Aleksej Komarov
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { classes } from '../common/react';
|
|
8
|
+
import { ReactNode } from 'react';
|
|
9
|
+
|
|
10
|
+
import { BoxProps, computeBoxClassName, computeBoxProps } from './Box';
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
content?: ReactNode;
|
|
14
|
+
} & BoxProps;
|
|
15
|
+
|
|
16
|
+
export function ColorBox(props: Props) {
|
|
17
|
+
const { content, children, className, ...rest } = props;
|
|
18
|
+
|
|
19
|
+
rest.color = content ? null : 'default';
|
|
20
|
+
rest.backgroundColor = props.color || 'default';
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<div
|
|
24
|
+
className={classes(['ColorBox', className, computeBoxClassName(rest)])}
|
|
25
|
+
{...computeBoxProps(rest)}
|
|
26
|
+
>
|
|
27
|
+
{content || '.'}
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @copyright 2022 raffclar
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
import { Box } from './Box';
|
|
7
|
+
import { Button } from './Button';
|
|
8
|
+
|
|
9
|
+
type DialogProps = {
|
|
10
|
+
title: any;
|
|
11
|
+
onClose: () => void;
|
|
12
|
+
children: any;
|
|
13
|
+
width?: string;
|
|
14
|
+
height?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const Dialog = (props: DialogProps) => {
|
|
18
|
+
const { title, onClose, children, width, height } = props;
|
|
19
|
+
return (
|
|
20
|
+
<div className="Dialog">
|
|
21
|
+
<Box className="Dialog__content" width={width || '370px'} height={height}>
|
|
22
|
+
<div className="Dialog__header">
|
|
23
|
+
<div className="Dialog__title">{title}</div>
|
|
24
|
+
<Box mr={2}>
|
|
25
|
+
<Button
|
|
26
|
+
mr="-3px"
|
|
27
|
+
width="26px"
|
|
28
|
+
lineHeight="22px"
|
|
29
|
+
textAlign="center"
|
|
30
|
+
color="transparent"
|
|
31
|
+
icon="window-close-o"
|
|
32
|
+
tooltip="Close"
|
|
33
|
+
tooltipPosition="bottom-start"
|
|
34
|
+
onClick={onClose}
|
|
35
|
+
/>
|
|
36
|
+
</Box>
|
|
37
|
+
</div>
|
|
38
|
+
{children}
|
|
39
|
+
</Box>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type DialogButtonProps = {
|
|
45
|
+
onClick: () => void;
|
|
46
|
+
children: any;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const DialogButton = (props: DialogButtonProps) => {
|
|
50
|
+
const { onClick, children } = props;
|
|
51
|
+
return (
|
|
52
|
+
<Button
|
|
53
|
+
onClick={onClick}
|
|
54
|
+
className="Dialog__button"
|
|
55
|
+
verticalAlignContent="middle"
|
|
56
|
+
>
|
|
57
|
+
{children}
|
|
58
|
+
</Button>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
Dialog.Button = DialogButton;
|
|
63
|
+
|
|
64
|
+
type UnsavedChangesDialogProps = {
|
|
65
|
+
documentName: string;
|
|
66
|
+
onSave: () => void;
|
|
67
|
+
onDiscard: () => void;
|
|
68
|
+
onClose: () => void;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const UnsavedChangesDialog = (props: UnsavedChangesDialogProps) => {
|
|
72
|
+
const { documentName, onSave, onDiscard, onClose } = props;
|
|
73
|
+
return (
|
|
74
|
+
<Dialog title="Notepad" onClose={onClose}>
|
|
75
|
+
<div className="Dialog__body">
|
|
76
|
+
Do you want to save changes to {documentName}?
|
|
77
|
+
</div>
|
|
78
|
+
<div className="Dialog__footer">
|
|
79
|
+
<DialogButton onClick={onSave}>Save</DialogButton>
|
|
80
|
+
<DialogButton onClick={onDiscard}>Don't Save</DialogButton>
|
|
81
|
+
<DialogButton onClick={onClose}>Cancel</DialogButton>
|
|
82
|
+
</div>
|
|
83
|
+
</Dialog>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @copyright 2020 Aleksej Komarov
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { classes } from '../common/react';
|
|
8
|
+
|
|
9
|
+
import { Box, BoxProps } from './Box';
|
|
10
|
+
|
|
11
|
+
export function Dimmer(props: BoxProps) {
|
|
12
|
+
const { className, children, ...rest } = props;
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Box className={classes(['Dimmer', className])} {...rest}>
|
|
16
|
+
<div className="Dimmer__inner">{children}</div>
|
|
17
|
+
</Box>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @copyright 2020 Aleksej Komarov
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { classes } from '../common/react';
|
|
8
|
+
|
|
9
|
+
type Props = Partial<{
|
|
10
|
+
hidden: boolean;
|
|
11
|
+
vertical: boolean;
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
export function Divider(props: Props) {
|
|
15
|
+
const { hidden, vertical } = props;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div
|
|
19
|
+
className={classes([
|
|
20
|
+
'Divider',
|
|
21
|
+
hidden && 'Divider--hidden',
|
|
22
|
+
vertical ? 'Divider--vertical' : 'Divider--horizontal',
|
|
23
|
+
])}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ReactNode, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { resolveAsset } from '../assets';
|
|
4
|
+
import { fetchRetry } from '../http';
|
|
5
|
+
import { BoxProps } from './Box';
|
|
6
|
+
import { Image } from './Image';
|
|
7
|
+
|
|
8
|
+
enum Direction {
|
|
9
|
+
NORTH = 1,
|
|
10
|
+
SOUTH = 2,
|
|
11
|
+
EAST = 4,
|
|
12
|
+
WEST = 8,
|
|
13
|
+
NORTHEAST = NORTH | EAST,
|
|
14
|
+
NORTHWEST = NORTH | WEST,
|
|
15
|
+
SOUTHEAST = SOUTH | EAST,
|
|
16
|
+
SOUTHWEST = SOUTH | WEST,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
/** Required: The path of the icon */
|
|
21
|
+
icon: string;
|
|
22
|
+
/** Required: The state of the icon */
|
|
23
|
+
icon_state: string;
|
|
24
|
+
} & Partial<{
|
|
25
|
+
/** Facing direction. See direction enum. Default is South */
|
|
26
|
+
direction: Direction;
|
|
27
|
+
/** Fallback icon. */
|
|
28
|
+
fallback: ReactNode;
|
|
29
|
+
/** Frame number. Default is 1 */
|
|
30
|
+
frame: number;
|
|
31
|
+
/** Movement state. Default is false */
|
|
32
|
+
movement: boolean;
|
|
33
|
+
}> &
|
|
34
|
+
BoxProps;
|
|
35
|
+
|
|
36
|
+
let refMap: Record<string, string> | undefined;
|
|
37
|
+
|
|
38
|
+
export function DmIcon(props: Props) {
|
|
39
|
+
const {
|
|
40
|
+
className,
|
|
41
|
+
direction = Direction.SOUTH,
|
|
42
|
+
fallback,
|
|
43
|
+
frame = 1,
|
|
44
|
+
icon_state,
|
|
45
|
+
icon,
|
|
46
|
+
movement = false,
|
|
47
|
+
...rest
|
|
48
|
+
} = props;
|
|
49
|
+
|
|
50
|
+
const [iconRef, setIconRef] = useState('');
|
|
51
|
+
|
|
52
|
+
const query = `${iconRef}?state=${icon_state}&dir=${direction}&movement=${movement}&frame=${frame}`;
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
async function fetchRefMap() {
|
|
56
|
+
const response = await fetchRetry(resolveAsset('icon_ref_map.json'));
|
|
57
|
+
const data = await response.json();
|
|
58
|
+
refMap = data;
|
|
59
|
+
setIconRef(data[icon]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!refMap) {
|
|
63
|
+
fetchRefMap();
|
|
64
|
+
} else {
|
|
65
|
+
setIconRef(refMap[icon]);
|
|
66
|
+
}
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
if (!iconRef) return fallback;
|
|
70
|
+
|
|
71
|
+
return <Image fixErrors src={query} {...rest} />;
|
|
72
|
+
}
|