-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathWidgetIndex.tsx
More file actions
95 lines (91 loc) · 3.24 KB
/
Copy pathWidgetIndex.tsx
File metadata and controls
95 lines (91 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { Standings } from './components/Standings/Standings';
import { Input } from './components/Input';
import { Relative } from './components/Standings/Relative';
import { TrackMap } from './components/TrackMap/TrackMap';
import { FlatTrackMap } from './components/TrackMap/FlatTrackMap';
import { Weather } from './components/Weather';
import { Wind } from './components/Wind';
import { FasterCarsFromBehind } from './components/FasterCarsFromBehind/FasterCarsFromBehind';
import { FuelCalculator } from './components/FuelCalculator';
import { BlindSpotMonitor } from './components/BlindSpotMonitor/BlindSpotMonitor';
import { GarageCover } from './components/GarageCover/GarageCover';
import { RejoinIndicator } from './components/RejoinIndicator/RejoinIndicator';
import { TelemetryInspector } from './components/TelemetryInspector/TelemetryInspector';
import { PitlaneHelper } from './components/PitlaneHelper/PitlaneHelper';
import { Tachometer } from './components/Tachometer/Tachometer';
import { Flag } from './components/Flag';
import { TwitchChat } from './components/TwitchChat/TwitchChat';
import { LapTimeLog } from './components/LapTimeLog/LapTimeLog';
import { InformationBar } from './components/InformationBar/InformationBar';
import { SlowCarAhead } from './components/SlowCarAhead/SlowCarAhead';
import { SectorDelta } from './components/SectorDelta/SectorDelta';
import { HeartRate } from './components/HeartRate/HeartRate';
import { CornerNameOverlay } from './components/CornerNameOverlay';
import { Battle } from './components/Battle/Battle';
import type { WidgetConfigMap } from '@irdashies/types';
import type { ElementType } from 'react';
export {
Standings,
Input,
Relative,
TrackMap,
FlatTrackMap,
Weather,
Wind,
FasterCarsFromBehind,
FuelCalculator,
BlindSpotMonitor,
GarageCover,
RejoinIndicator,
TelemetryInspector,
PitlaneHelper,
Tachometer,
Flag,
TwitchChat,
LapTimeLog,
InformationBar,
SlowCarAhead,
SectorDelta,
HeartRate,
CornerNameOverlay,
Battle,
};
export const WIDGET_MAP: Record<keyof WidgetConfigMap, ElementType> = {
standings: Standings,
input: Input,
relative: Relative,
map: TrackMap,
flatmap: FlatTrackMap,
weather: Weather,
wind: Wind,
fastercarsfrombehind: FasterCarsFromBehind,
fuel: FuelCalculator,
blindspotmonitor: BlindSpotMonitor,
garagecover: GarageCover,
rejoin: RejoinIndicator,
telemetryinspector: TelemetryInspector,
pitlanehelper: PitlaneHelper,
tachometer: Tachometer,
flag: Flag,
twitchchat: TwitchChat,
laptimelog: LapTimeLog,
infobar: InformationBar,
slowcarahead: SlowCarAhead,
sectordelta: SectorDelta,
heartrate: HeartRate,
cornername: CornerNameOverlay,
battle: Battle,
};
export type WidgetId = keyof WidgetConfigMap;
/**
* Looks up a widget component by id. Accepts a raw string because dashboard
* config is user-supplied and may contain unknown ids; returns undefined
* when no widget is registered for that id.
*
* Uses Object.hasOwn so prototype-chain keys (e.g. "__proto__", "toString")
* never resolve to truthy non-component values that React would try to render.
*/
export const getWidget = (id: string) =>
Object.hasOwn(WIDGET_MAP, id)
? (WIDGET_MAP[id as WidgetId] as (typeof WIDGET_MAP)[WidgetId])
: undefined;