@sirenodeck/sirenodeck 0.2.6 → 0.2.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/config-ui/index.html +13 -0
- package/config-ui/src/App.tsx +675 -0
- package/config-ui/src/DeckFrame.tsx +445 -0
- package/config-ui/src/Shell.tsx +108 -0
- package/config-ui/src/SidePanel.tsx +96 -0
- package/config-ui/src/bridge-log-store.ts +115 -0
- package/config-ui/src/bridge.ts +303 -0
- package/config-ui/src/components/ActionValueEditor.tsx +209 -0
- package/config-ui/src/components/ButtonActionsEditor.tsx +84 -0
- package/config-ui/src/components/DisconnectedOverlay.tsx +77 -0
- package/config-ui/src/components/EmojiPicker.tsx +65 -0
- package/config-ui/src/components/IconPicker.tsx +264 -0
- package/config-ui/src/components/MacroPreview.tsx +22 -0
- package/config-ui/src/components/ReconnectingBanner.tsx +35 -0
- package/config-ui/src/gesture.ts +45 -0
- package/config-ui/src/index.css +8 -0
- package/config-ui/src/main.tsx +20 -0
- package/config-ui/src/pages/AboutPage.tsx +65 -0
- package/config-ui/src/pages/AddonsPage.tsx +232 -0
- package/config-ui/src/pages/BridgeLogsPage.tsx +94 -0
- package/config-ui/src/pages/ButtonConfigEditor/ButtonAppearanceFields.tsx +77 -0
- package/config-ui/src/pages/ButtonConfigEditor/ButtonTypePicker.tsx +80 -0
- package/config-ui/src/pages/ButtonConfigEditor/ConfigForm.tsx +50 -0
- package/config-ui/src/pages/ButtonConfigEditor/FormFieldParts.tsx +23 -0
- package/config-ui/src/pages/ButtonConfigEditor/PositionPicker.tsx +68 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/ActionControl.tsx +27 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/ArrayControl.tsx +77 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/BooleanControl.tsx +34 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/DeckSelectControl.tsx +47 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/EmojiControl.tsx +70 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/IconControl.tsx +31 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/ObjectControl.tsx +52 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/RecordControl.tsx +104 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/SelectControl.tsx +46 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/ShellControl.tsx +29 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/TextControl.tsx +36 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/UnionControl.tsx +96 -0
- package/config-ui/src/pages/ButtonConfigEditor/controls/registry.ts +17 -0
- package/config-ui/src/pages/ButtonConfigEditor/types.ts +67 -0
- package/config-ui/src/pages/ButtonConfigEditor/utils.ts +56 -0
- package/config-ui/src/pages/ButtonConfigEditor.tsx +226 -0
- package/config-ui/src/pages/ConfigPage.tsx +326 -0
- package/config-ui/src/pages/DecksPage.tsx +104 -0
- package/config-ui/src/pages/EditorPage.tsx +1697 -0
- package/config-ui/src/pages/ServiceLogsPage.tsx +130 -0
- package/config-ui/vite.config.ts +105 -0
- package/dist/main.mjs +403 -41501
- package/frontend/index.html +12 -0
- package/frontend/src/App.tsx +536 -0
- package/frontend/src/__mocks__/addons-registry.ts +2 -0
- package/frontend/src/__mocks__/theme.ts +1 -0
- package/frontend/src/__mocks__/themes-manifest.tsx +78 -0
- package/frontend/src/__mocks__/token.ts +2 -0
- package/frontend/src/bridge/client.ts +186 -0
- package/frontend/src/bridge/use-button-action.ts +31 -0
- package/frontend/src/bridge/ws-context.tsx +24 -0
- package/frontend/src/components/Deck.tsx +486 -0
- package/frontend/src/components/DisconnectedOverlay.tsx +82 -0
- package/frontend/src/components/ErrorBoundary.tsx +92 -0
- package/frontend/src/components/ReconnectingBanner.tsx +40 -0
- package/frontend/src/index.css +40 -0
- package/frontend/src/main.tsx +23 -0
- package/frontend/vite.config.ts +132 -0
- package/package.json +20 -6
- package/src/builtin-addons/internal-settings/index.ts +0 -1
- package/src/builtin-addons/internal-settings/logo72x72.png +0 -0
- package/src/cli/commands/emulator-mode.ts +26 -4
- package/src/cli/commands/run.ts +28 -1
- package/src/cli/commands/service-manager.ts +53 -1
- package/src/cli/commands/start.ts +17 -0
- package/src/cli/startup-display.ts +1 -1
- package/src/core/settings.ts +5 -3
- package/src/device/black-frame.ts +5 -14
- package/src/outputClient/real.ts +2 -0
- package/src/vite/virtual-modules.ts +16 -1
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BUTTON_SIZE_PX,
|
|
5
|
+
DECK_GAP_PX,
|
|
6
|
+
DECK_PADDING_PX,
|
|
7
|
+
deckDimensions,
|
|
8
|
+
type DeviceModelSpec,
|
|
9
|
+
} from "@sirenodeck/sirenodeck"
|
|
10
|
+
import { Button, Dropdown, Label, Modal } from "@heroui/react"
|
|
11
|
+
import {
|
|
12
|
+
ArrowDown,
|
|
13
|
+
ArrowUp,
|
|
14
|
+
Copy,
|
|
15
|
+
CopyPlus,
|
|
16
|
+
Pencil,
|
|
17
|
+
Trash2,
|
|
18
|
+
} from "lucide-react"
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
createEmulatorGestureDetector,
|
|
22
|
+
dispatchMouseEvent,
|
|
23
|
+
gestureKindToWsMessage,
|
|
24
|
+
type GestureDetector,
|
|
25
|
+
} from "./gesture"
|
|
26
|
+
|
|
27
|
+
export interface DeckFrameProps {
|
|
28
|
+
readonly frontendUrl: string
|
|
29
|
+
readonly device: DeviceModelSpec
|
|
30
|
+
readonly deckId: string
|
|
31
|
+
readonly token?: string
|
|
32
|
+
readonly gap?: boolean
|
|
33
|
+
readonly onGesture?: (msg: {
|
|
34
|
+
deckId: string
|
|
35
|
+
position: number
|
|
36
|
+
gesture: "tap" | "dbl-tap" | "hold"
|
|
37
|
+
}) => void
|
|
38
|
+
readonly onDropPosition?: (position: number, event: React.DragEvent) => void
|
|
39
|
+
readonly onKeyAction?: (position: number, action: KeyAction) => void
|
|
40
|
+
readonly systemPositions?: readonly number[]
|
|
41
|
+
readonly highlightedKey?: number | null
|
|
42
|
+
readonly previewConfig?: {
|
|
43
|
+
index: number
|
|
44
|
+
position?: number
|
|
45
|
+
type?: string
|
|
46
|
+
config: Record<string, unknown>
|
|
47
|
+
appearance?: {
|
|
48
|
+
icon: string
|
|
49
|
+
label: string
|
|
50
|
+
variant: string
|
|
51
|
+
actions: { tap?: string; dbltap?: string; hold?: string }
|
|
52
|
+
}
|
|
53
|
+
assets?: Array<{ filename: string; preview: string }>
|
|
54
|
+
} | null
|
|
55
|
+
readonly fitToContainer?: boolean
|
|
56
|
+
/** Render without editor chrome for the dedicated remote deck surface. */
|
|
57
|
+
readonly bare?: boolean
|
|
58
|
+
// ponytail: lets the parent trigger `iframe.contentWindow.location.reload()`
|
|
59
|
+
// on `iframe-reload` WS messages without giving the parent a real DOM ref
|
|
60
|
+
// (which would force React to re-render and discard internal state).
|
|
61
|
+
readonly onIframeRef?: (iframe: HTMLIFrameElement | null) => void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const KEY_ACTIONS = [
|
|
65
|
+
{ action: "edit", label: "Edit", Icon: Pencil },
|
|
66
|
+
{ action: "copy", label: "Copy config", Icon: Copy },
|
|
67
|
+
{ action: "duplicate", label: "Duplicate", Icon: CopyPlus },
|
|
68
|
+
{ action: "up", label: "Move up", Icon: ArrowUp },
|
|
69
|
+
{ action: "down", label: "Move down", Icon: ArrowDown },
|
|
70
|
+
{ action: "delete", label: "Delete", Icon: Trash2 },
|
|
71
|
+
] as const
|
|
72
|
+
|
|
73
|
+
type KeyAction = (typeof KEY_ACTIONS)[number]["action"]
|
|
74
|
+
|
|
75
|
+
export const DeckFrame = ({
|
|
76
|
+
frontendUrl,
|
|
77
|
+
device,
|
|
78
|
+
deckId,
|
|
79
|
+
token = "",
|
|
80
|
+
gap = true,
|
|
81
|
+
onGesture,
|
|
82
|
+
onDropPosition,
|
|
83
|
+
onKeyAction,
|
|
84
|
+
systemPositions = [],
|
|
85
|
+
highlightedKey,
|
|
86
|
+
previewConfig = null,
|
|
87
|
+
fitToContainer = false,
|
|
88
|
+
bare = false,
|
|
89
|
+
onIframeRef,
|
|
90
|
+
}: DeckFrameProps): React.ReactElement => {
|
|
91
|
+
const { columns, keyCount } = device
|
|
92
|
+
const detectorRef = useRef<GestureDetector | null>(null)
|
|
93
|
+
const onGestureRef = useRef(onGesture)
|
|
94
|
+
onGestureRef.current = onGesture
|
|
95
|
+
const [pressedIndex, setPressedIndex] = useState<number | null>(null)
|
|
96
|
+
const [deleteConfirmationPosition, setDeleteConfirmationPosition] = useState<
|
|
97
|
+
number | null
|
|
98
|
+
>(null)
|
|
99
|
+
const [iframeState, setIframeState] = useState<
|
|
100
|
+
"loading" | "loaded" | "error"
|
|
101
|
+
>("loading")
|
|
102
|
+
const [reloadNonce, setReloadNonce] = useState(0)
|
|
103
|
+
const previousPreview = useRef<typeof previewConfig>(null)
|
|
104
|
+
const iframeRef = useRef<HTMLIFrameElement | null>(null)
|
|
105
|
+
const frameRef = useRef<HTMLDivElement | null>(null)
|
|
106
|
+
const [scale, setScale] = useState(1)
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
const detector = createEmulatorGestureDetector((result) => {
|
|
110
|
+
const cb = onGestureRef.current
|
|
111
|
+
if (cb !== undefined) cb(gestureKindToWsMessage(result, deckId))
|
|
112
|
+
})
|
|
113
|
+
detectorRef.current = detector
|
|
114
|
+
return () => {
|
|
115
|
+
detector.reset()
|
|
116
|
+
detectorRef.current = null
|
|
117
|
+
}
|
|
118
|
+
}, [deckId])
|
|
119
|
+
|
|
120
|
+
const handleDown = (keyIndex: number): void => {
|
|
121
|
+
setPressedIndex(keyIndex)
|
|
122
|
+
dispatchMouseEvent(detectorRef.current!, {
|
|
123
|
+
kind: "down",
|
|
124
|
+
keyIndex,
|
|
125
|
+
timestamp: Date.now(),
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const handleUp = (keyIndex: number): void => {
|
|
130
|
+
setPressedIndex(null)
|
|
131
|
+
dispatchMouseEvent(detectorRef.current!, {
|
|
132
|
+
kind: "up",
|
|
133
|
+
keyIndex,
|
|
134
|
+
timestamp: Date.now(),
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ponytail: use the page's current hostname so the iframe works regardless of
|
|
139
|
+
// which interface the phone used to reach the config UI (LAN, Tailscale, VPN).
|
|
140
|
+
// The injected URL still carries the correct frontend port.
|
|
141
|
+
const resolvedFrontendUrl = ((): string => {
|
|
142
|
+
if (typeof window === "undefined") return frontendUrl
|
|
143
|
+
try {
|
|
144
|
+
const parsed = new URL(frontendUrl)
|
|
145
|
+
return `${parsed.protocol}//${window.location.hostname}:${parsed.port}${parsed.pathname}${parsed.search}${parsed.hash}`
|
|
146
|
+
} catch {
|
|
147
|
+
return frontendUrl
|
|
148
|
+
}
|
|
149
|
+
})()
|
|
150
|
+
|
|
151
|
+
const iframeUrl = ((): string => {
|
|
152
|
+
let parsed: URL
|
|
153
|
+
try {
|
|
154
|
+
parsed = new URL(resolvedFrontendUrl)
|
|
155
|
+
} catch {
|
|
156
|
+
return resolvedFrontendUrl
|
|
157
|
+
}
|
|
158
|
+
parsed.searchParams.set("device", device.id)
|
|
159
|
+
parsed.searchParams.set("_r", String(reloadNonce))
|
|
160
|
+
parsed.searchParams.set("compact", "0")
|
|
161
|
+
parsed.searchParams.set("gap", String(gap))
|
|
162
|
+
if (token.length > 0) parsed.searchParams.set("token", token)
|
|
163
|
+
const base = parsed.toString()
|
|
164
|
+
// ponytail: --remote puts the deck behind the daemon's token. The
|
|
165
|
+
// config UI's own bundle already authenticates via the sireno-token
|
|
166
|
+
// cookie, but the iframe loads the *frontend* on a different origin
|
|
167
|
+
// (port 5180), which can't read the config UI's cookie. Append the
|
|
168
|
+
// token to the iframe URL so the frontend's middleware lets the
|
|
169
|
+
// request through on first paint — the injected cookie script in
|
|
170
|
+
// that HTML then keeps subsequent module requests authenticated.
|
|
171
|
+
return base
|
|
172
|
+
})()
|
|
173
|
+
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
setIframeState("loading")
|
|
176
|
+
const iframe = iframeRef.current
|
|
177
|
+
if (iframe === null) return
|
|
178
|
+
const handleError = (): void => setIframeState("error")
|
|
179
|
+
iframe.addEventListener("error", handleError)
|
|
180
|
+
return () => iframe.removeEventListener("error", handleError)
|
|
181
|
+
}, [iframeUrl])
|
|
182
|
+
|
|
183
|
+
const setIframeRef = (el: HTMLIFrameElement | null): void => {
|
|
184
|
+
iframeRef.current = el
|
|
185
|
+
onIframeRef?.(el)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
if (iframeState !== "loaded") return
|
|
190
|
+
if (previewConfig === null) {
|
|
191
|
+
if (previousPreview.current !== null) setReloadNonce((n) => n + 1)
|
|
192
|
+
} else {
|
|
193
|
+
iframeRef.current?.contentWindow?.postMessage(
|
|
194
|
+
{ type: "editor-preview-config", deckId, ...previewConfig },
|
|
195
|
+
new URL(resolvedFrontendUrl).origin,
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
previousPreview.current = previewConfig
|
|
199
|
+
}, [deckId, iframeState, previewConfig, resolvedFrontendUrl])
|
|
200
|
+
|
|
201
|
+
const resolvedGap = gap ? DECK_GAP_PX : 0
|
|
202
|
+
const { width: frameWidth, height: frameHeight } = deckDimensions(
|
|
203
|
+
{ columns, rows: Math.ceil(keyCount / columns) },
|
|
204
|
+
resolvedGap,
|
|
205
|
+
DECK_PADDING_PX,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (!fitToContainer) {
|
|
210
|
+
setScale(1)
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
const parent = frameRef.current?.parentElement
|
|
214
|
+
if (parent === null || parent === undefined) return
|
|
215
|
+
const resize = (): void =>
|
|
216
|
+
setScale(Math.min(1, Math.max(0.1, parent.clientWidth / frameWidth)))
|
|
217
|
+
resize()
|
|
218
|
+
if (typeof ResizeObserver === "undefined") return
|
|
219
|
+
const observer = new ResizeObserver(resize)
|
|
220
|
+
observer.observe(parent)
|
|
221
|
+
return () => observer.disconnect()
|
|
222
|
+
}, [fitToContainer, frameWidth])
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<div
|
|
226
|
+
ref={frameRef}
|
|
227
|
+
className={
|
|
228
|
+
bare
|
|
229
|
+
? "relative overflow-hidden"
|
|
230
|
+
: "relative overflow-hidden rounded-xl border border-neutral-800 bg-neutral-900 shadow-lg"
|
|
231
|
+
}
|
|
232
|
+
style={{
|
|
233
|
+
width: frameWidth * scale,
|
|
234
|
+
height: frameHeight * scale,
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
<div
|
|
238
|
+
className="absolute left-0 top-0"
|
|
239
|
+
style={{
|
|
240
|
+
width: frameWidth,
|
|
241
|
+
height: frameHeight,
|
|
242
|
+
transform: `scale(${scale})`,
|
|
243
|
+
transformOrigin: "top left",
|
|
244
|
+
}}
|
|
245
|
+
>
|
|
246
|
+
<iframe
|
|
247
|
+
ref={setIframeRef}
|
|
248
|
+
src={iframeUrl}
|
|
249
|
+
onLoad={() => setIframeState("loaded")}
|
|
250
|
+
className="block"
|
|
251
|
+
style={{ width: frameWidth, height: frameHeight }}
|
|
252
|
+
title="Deck Preview"
|
|
253
|
+
/>
|
|
254
|
+
{iframeState !== "loaded" && (
|
|
255
|
+
<div
|
|
256
|
+
data-testid="iframe-status"
|
|
257
|
+
data-status={iframeState}
|
|
258
|
+
className="absolute inset-0 z-10 flex flex-col items-center justify-center gap-3 bg-neutral-950/80 p-4 text-center text-xs text-neutral-400"
|
|
259
|
+
>
|
|
260
|
+
{iframeState === "loading" ? (
|
|
261
|
+
<>
|
|
262
|
+
<span className="inline-block h-5 w-5 animate-spin rounded-full border-2 border-neutral-600 border-t-sky-400" />
|
|
263
|
+
<p>Loading deck…</p>
|
|
264
|
+
</>
|
|
265
|
+
) : (
|
|
266
|
+
<>
|
|
267
|
+
<p className="font-medium text-red-400">Could not load deck</p>
|
|
268
|
+
<p className="max-w-[220px]">
|
|
269
|
+
Check that this device can reach
|
|
270
|
+
<br />
|
|
271
|
+
<span className="break-all font-mono text-neutral-300">
|
|
272
|
+
{resolvedFrontendUrl}
|
|
273
|
+
</span>
|
|
274
|
+
</p>
|
|
275
|
+
<button
|
|
276
|
+
type="button"
|
|
277
|
+
onClick={() => {
|
|
278
|
+
setIframeState("loading")
|
|
279
|
+
setReloadNonce((n) => n + 1)
|
|
280
|
+
}}
|
|
281
|
+
className="rounded bg-sky-600 px-3 py-1.5 text-neutral-100 hover:bg-sky-500"
|
|
282
|
+
>
|
|
283
|
+
Retry
|
|
284
|
+
</button>
|
|
285
|
+
</>
|
|
286
|
+
)}
|
|
287
|
+
</div>
|
|
288
|
+
)}
|
|
289
|
+
<div
|
|
290
|
+
data-testid="deck-frame"
|
|
291
|
+
data-deck={deckId}
|
|
292
|
+
data-key-count={keyCount}
|
|
293
|
+
data-columns={columns}
|
|
294
|
+
className="absolute inset-0 z-10 grid p-4 pointer-events-none"
|
|
295
|
+
style={{
|
|
296
|
+
gridTemplateColumns: `repeat(${columns}, ${BUTTON_SIZE_PX}px)`,
|
|
297
|
+
gridTemplateRows: `repeat(${Math.ceil(keyCount / columns)}, ${BUTTON_SIZE_PX}px)`,
|
|
298
|
+
gap: `${resolvedGap}px`,
|
|
299
|
+
}}
|
|
300
|
+
>
|
|
301
|
+
{Array.from({ length: keyCount }, (_, i) => {
|
|
302
|
+
const isPressed = pressedIndex === i
|
|
303
|
+
const editorControls =
|
|
304
|
+
onKeyAction === undefined ||
|
|
305
|
+
systemPositions.includes(i) ? null : (
|
|
306
|
+
<div className="pointer-events-none absolute top-0 right-0 z-20 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 focus-within:pointer-events-auto focus-within:opacity-100 [@media(hover:none)]:pointer-events-auto [@media(hover:none)]:opacity-100">
|
|
307
|
+
<Dropdown>
|
|
308
|
+
<Button
|
|
309
|
+
type="button"
|
|
310
|
+
aria-label={`Actions for key ${i}`}
|
|
311
|
+
className="h-6 w-6 min-w-6 rounded-full bg-neutral-950/90 p-0 text-xs text-neutral-200"
|
|
312
|
+
onMouseDown={(event) => event.stopPropagation()}
|
|
313
|
+
>
|
|
314
|
+
⋮
|
|
315
|
+
</Button>
|
|
316
|
+
<Dropdown.Popover>
|
|
317
|
+
<Dropdown.Menu
|
|
318
|
+
aria-label="Key actions"
|
|
319
|
+
onAction={(key) => {
|
|
320
|
+
const action = String(key) as KeyAction
|
|
321
|
+
if (action === "delete") {
|
|
322
|
+
setDeleteConfirmationPosition(i)
|
|
323
|
+
return
|
|
324
|
+
}
|
|
325
|
+
onKeyAction(i, action)
|
|
326
|
+
}}
|
|
327
|
+
>
|
|
328
|
+
{KEY_ACTIONS.map(({ action, label, Icon }) => (
|
|
329
|
+
<Dropdown.Item
|
|
330
|
+
key={action}
|
|
331
|
+
id={action}
|
|
332
|
+
textValue={label}
|
|
333
|
+
className={
|
|
334
|
+
action === "delete" ? "text-danger" : undefined
|
|
335
|
+
}
|
|
336
|
+
>
|
|
337
|
+
<Icon
|
|
338
|
+
aria-hidden="true"
|
|
339
|
+
className={`size-4 ${action === "delete" ? "text-danger" : ""}`}
|
|
340
|
+
/>
|
|
341
|
+
<Label
|
|
342
|
+
className={
|
|
343
|
+
action === "delete" ? "text-danger" : undefined
|
|
344
|
+
}
|
|
345
|
+
>
|
|
346
|
+
{label}
|
|
347
|
+
</Label>
|
|
348
|
+
</Dropdown.Item>
|
|
349
|
+
))}
|
|
350
|
+
</Dropdown.Menu>
|
|
351
|
+
</Dropdown.Popover>
|
|
352
|
+
</Dropdown>
|
|
353
|
+
</div>
|
|
354
|
+
)
|
|
355
|
+
return (
|
|
356
|
+
<div key={i} className="group relative">
|
|
357
|
+
<button
|
|
358
|
+
type="button"
|
|
359
|
+
data-testid={`deck-key-${i}`}
|
|
360
|
+
data-key-index={i}
|
|
361
|
+
aria-label={`Key ${i}`}
|
|
362
|
+
aria-pressed={isPressed}
|
|
363
|
+
onPointerDown={() => handleDown(i)}
|
|
364
|
+
onPointerUp={() => handleUp(i)}
|
|
365
|
+
onPointerLeave={(e) => {
|
|
366
|
+
if (e.buttons === 1) handleUp(i)
|
|
367
|
+
}}
|
|
368
|
+
onPointerCancel={() => handleUp(i)}
|
|
369
|
+
onDragOver={
|
|
370
|
+
onDropPosition === undefined
|
|
371
|
+
? undefined
|
|
372
|
+
: (event) => event.preventDefault()
|
|
373
|
+
}
|
|
374
|
+
onDrop={
|
|
375
|
+
onDropPosition === undefined
|
|
376
|
+
? undefined
|
|
377
|
+
: (event) => onDropPosition(i, event)
|
|
378
|
+
}
|
|
379
|
+
className={[
|
|
380
|
+
"h-full w-full rounded-lg border",
|
|
381
|
+
"bg-gradient-to-br from-black/40 via-black/20 to-white/5",
|
|
382
|
+
"border-white/10",
|
|
383
|
+
"pointer-events-auto transition-all duration-200",
|
|
384
|
+
"touch-none",
|
|
385
|
+
"hover:from-black/20 hover:via-black/0 hover:to-white/10 hover:border-white/25",
|
|
386
|
+
isPressed
|
|
387
|
+
? "from-white/60 via-white/30 to-white/10 border-white/60 shadow-[0_0_18px_rgba(255,255,255,0.5)] scale-[0.96]"
|
|
388
|
+
: highlightedKey === i
|
|
389
|
+
? "outline outline-2 outline-offset-2 outline-primary"
|
|
390
|
+
: "",
|
|
391
|
+
].join(" ")}
|
|
392
|
+
/>
|
|
393
|
+
{editorControls}
|
|
394
|
+
</div>
|
|
395
|
+
)
|
|
396
|
+
})}
|
|
397
|
+
</div>
|
|
398
|
+
</div>
|
|
399
|
+
<Modal>
|
|
400
|
+
{deleteConfirmationPosition !== null && (
|
|
401
|
+
<Modal.Backdrop
|
|
402
|
+
isOpen
|
|
403
|
+
onOpenChange={(isOpen) => {
|
|
404
|
+
if (!isOpen) setDeleteConfirmationPosition(null)
|
|
405
|
+
}}
|
|
406
|
+
>
|
|
407
|
+
<Modal.Container placement="center" size="sm">
|
|
408
|
+
<Modal.Dialog aria-label="Confirm deleting button">
|
|
409
|
+
<Modal.Header>
|
|
410
|
+
<Modal.Heading>
|
|
411
|
+
Delete key {deleteConfirmationPosition + 1}?
|
|
412
|
+
</Modal.Heading>
|
|
413
|
+
</Modal.Header>
|
|
414
|
+
<Modal.Body>
|
|
415
|
+
<p>This removes the button from this deck.</p>
|
|
416
|
+
</Modal.Body>
|
|
417
|
+
<Modal.Footer>
|
|
418
|
+
<Button
|
|
419
|
+
type="button"
|
|
420
|
+
variant="tertiary"
|
|
421
|
+
onPress={() => setDeleteConfirmationPosition(null)}
|
|
422
|
+
>
|
|
423
|
+
Cancel
|
|
424
|
+
</Button>
|
|
425
|
+
<Button
|
|
426
|
+
type="button"
|
|
427
|
+
variant="primary"
|
|
428
|
+
className="bg-danger text-foreground-contrast"
|
|
429
|
+
onPress={() => {
|
|
430
|
+
const position = deleteConfirmationPosition
|
|
431
|
+
setDeleteConfirmationPosition(null)
|
|
432
|
+
onKeyAction?.(position, "delete")
|
|
433
|
+
}}
|
|
434
|
+
>
|
|
435
|
+
Delete button
|
|
436
|
+
</Button>
|
|
437
|
+
</Modal.Footer>
|
|
438
|
+
</Modal.Dialog>
|
|
439
|
+
</Modal.Container>
|
|
440
|
+
</Modal.Backdrop>
|
|
441
|
+
)}
|
|
442
|
+
</Modal>
|
|
443
|
+
</div>
|
|
444
|
+
)
|
|
445
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { SidePanel } from "./SidePanel"
|
|
2
|
+
import { useState } from "react"
|
|
3
|
+
import { PanelLeft, PanelLeftClose } from "lucide-react"
|
|
4
|
+
import { Button } from "@heroui/react"
|
|
5
|
+
|
|
6
|
+
export interface ShellProps {
|
|
7
|
+
readonly activeSection: string
|
|
8
|
+
readonly onSelect: (path: string) => void
|
|
9
|
+
readonly content: React.ReactNode
|
|
10
|
+
readonly hideSidebar?: boolean
|
|
11
|
+
readonly emulatorMode?: boolean
|
|
12
|
+
readonly devMode?: boolean
|
|
13
|
+
readonly deviceSelector?: React.ReactNode
|
|
14
|
+
readonly pageTitle: string
|
|
15
|
+
readonly wsUrl: string
|
|
16
|
+
readonly frontendUrl: string
|
|
17
|
+
readonly connectionStatus: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Shell = ({
|
|
21
|
+
activeSection,
|
|
22
|
+
onSelect,
|
|
23
|
+
content,
|
|
24
|
+
hideSidebar = false,
|
|
25
|
+
emulatorMode = false,
|
|
26
|
+
devMode = false,
|
|
27
|
+
deviceSelector,
|
|
28
|
+
pageTitle,
|
|
29
|
+
wsUrl,
|
|
30
|
+
frontendUrl,
|
|
31
|
+
connectionStatus,
|
|
32
|
+
}: ShellProps) => {
|
|
33
|
+
const [sidebarCollapsed, setSidebarCollapsed] = useState(false)
|
|
34
|
+
if (hideSidebar) {
|
|
35
|
+
return (
|
|
36
|
+
<main
|
|
37
|
+
data-testid="config-ui-shell"
|
|
38
|
+
className="flex h-[100dvh] w-full flex-1 overflow-hidden bg-background text-foreground"
|
|
39
|
+
>
|
|
40
|
+
{content}
|
|
41
|
+
</main>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
return (
|
|
45
|
+
<div
|
|
46
|
+
data-testid="config-ui-shell"
|
|
47
|
+
className="flex h-screen bg-background text-foreground"
|
|
48
|
+
>
|
|
49
|
+
<SidePanel
|
|
50
|
+
activeSection={activeSection}
|
|
51
|
+
onSelect={onSelect}
|
|
52
|
+
emulatorMode={emulatorMode}
|
|
53
|
+
devMode={devMode}
|
|
54
|
+
collapsed={sidebarCollapsed}
|
|
55
|
+
deviceSelector={deviceSelector}
|
|
56
|
+
/>
|
|
57
|
+
<main className="flex min-w-0 flex-1 flex-col overflow-hidden">
|
|
58
|
+
<header className="flex min-h-14 shrink-0 flex-wrap items-center gap-3 border-b border-separator bg-background px-4 py-2">
|
|
59
|
+
<Button
|
|
60
|
+
type="button"
|
|
61
|
+
isIconOnly
|
|
62
|
+
variant="tertiary"
|
|
63
|
+
aria-label={
|
|
64
|
+
sidebarCollapsed ? "Expand sidebar" : "Collapse sidebar"
|
|
65
|
+
}
|
|
66
|
+
onPress={() => setSidebarCollapsed((value) => !value)}
|
|
67
|
+
>
|
|
68
|
+
{sidebarCollapsed ? (
|
|
69
|
+
<PanelLeft size={18} />
|
|
70
|
+
) : (
|
|
71
|
+
<PanelLeftClose size={18} />
|
|
72
|
+
)}
|
|
73
|
+
</Button>
|
|
74
|
+
<h1 className="min-w-0 flex-1 truncate text-sm font-semibold">
|
|
75
|
+
{pageTitle}
|
|
76
|
+
</h1>
|
|
77
|
+
<div className="flex min-w-0 flex-wrap items-center justify-end gap-x-3 gap-y-1 text-xs text-muted">
|
|
78
|
+
<span className="whitespace-nowrap">
|
|
79
|
+
ws:{" "}
|
|
80
|
+
<strong
|
|
81
|
+
className={
|
|
82
|
+
connectionStatus === "open"
|
|
83
|
+
? "text-emerald-400"
|
|
84
|
+
: "text-amber-400"
|
|
85
|
+
}
|
|
86
|
+
>
|
|
87
|
+
{connectionStatus}
|
|
88
|
+
</strong>
|
|
89
|
+
</span>
|
|
90
|
+
<span className="hidden truncate sm:inline" title={wsUrl}>
|
|
91
|
+
ws://{wsUrl.replace(/^wss?:\/\//, "")}
|
|
92
|
+
</span>
|
|
93
|
+
<a
|
|
94
|
+
href={frontendUrl}
|
|
95
|
+
target="_blank"
|
|
96
|
+
rel="noopener noreferrer"
|
|
97
|
+
className="hidden truncate text-sky-400 hover:underline md:inline"
|
|
98
|
+
title={frontendUrl}
|
|
99
|
+
>
|
|
100
|
+
fe: {frontendUrl}
|
|
101
|
+
</a>
|
|
102
|
+
</div>
|
|
103
|
+
</header>
|
|
104
|
+
<div className="min-h-0 flex-1">{content}</div>
|
|
105
|
+
</main>
|
|
106
|
+
</div>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import logoUrl from "../../src/assets/logo72x72.png"
|
|
2
|
+
import { VERSION } from "../../src/version"
|
|
3
|
+
import { Button } from "@heroui/react"
|
|
4
|
+
import {
|
|
5
|
+
CircleHelp,
|
|
6
|
+
FileText,
|
|
7
|
+
LayoutDashboard,
|
|
8
|
+
Monitor,
|
|
9
|
+
Puzzle,
|
|
10
|
+
Server,
|
|
11
|
+
} from "lucide-react"
|
|
12
|
+
|
|
13
|
+
const SECTIONS = [
|
|
14
|
+
{ path: "config", label: "Config", icon: LayoutDashboard },
|
|
15
|
+
{ path: "about", label: "About", icon: CircleHelp },
|
|
16
|
+
{ path: "addons", label: "Addons", icon: Puzzle, devOnly: true },
|
|
17
|
+
{ path: "device", label: "Device", icon: Monitor, devOnly: true },
|
|
18
|
+
{ path: "bridge-logs", label: "Bridge logs", icon: Server, devOnly: true },
|
|
19
|
+
{
|
|
20
|
+
path: "service-logs",
|
|
21
|
+
label: "Service logs",
|
|
22
|
+
icon: FileText,
|
|
23
|
+
devOnly: true,
|
|
24
|
+
},
|
|
25
|
+
] as const
|
|
26
|
+
|
|
27
|
+
export interface SidePanelProps {
|
|
28
|
+
readonly activeSection: string
|
|
29
|
+
readonly onSelect: (path: string) => void
|
|
30
|
+
readonly emulatorMode?: boolean
|
|
31
|
+
readonly devMode?: boolean
|
|
32
|
+
readonly collapsed?: boolean
|
|
33
|
+
readonly deviceSelector?: React.ReactNode
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const SidePanel = ({
|
|
37
|
+
activeSection,
|
|
38
|
+
onSelect,
|
|
39
|
+
emulatorMode = false,
|
|
40
|
+
devMode = false,
|
|
41
|
+
collapsed = false,
|
|
42
|
+
deviceSelector,
|
|
43
|
+
}: SidePanelProps) => {
|
|
44
|
+
return (
|
|
45
|
+
<nav
|
|
46
|
+
data-testid="side-panel"
|
|
47
|
+
className={`flex shrink-0 flex-col border-r border-separator bg-background transition-[width] ${collapsed ? "w-16" : "w-64"}`}
|
|
48
|
+
>
|
|
49
|
+
<div
|
|
50
|
+
className={`flex items-center border-b border-separator py-5 ${collapsed ? "justify-center px-2" : "gap-3 px-5"}`}
|
|
51
|
+
>
|
|
52
|
+
<img
|
|
53
|
+
src={logoUrl}
|
|
54
|
+
alt="sirenodeck logo"
|
|
55
|
+
className="h-9 w-9 shrink-0 rounded"
|
|
56
|
+
/>
|
|
57
|
+
{!collapsed && (
|
|
58
|
+
<div className="min-w-0">
|
|
59
|
+
<div className="truncate text-sm font-semibold">sirenodeck</div>
|
|
60
|
+
<div className="text-xs text-muted">UI</div>
|
|
61
|
+
</div>
|
|
62
|
+
)}
|
|
63
|
+
</div>
|
|
64
|
+
<div className="flex flex-1 flex-col gap-1 p-3">
|
|
65
|
+
{!collapsed && deviceSelector}
|
|
66
|
+
{SECTIONS.filter(
|
|
67
|
+
(s) =>
|
|
68
|
+
(s.emulatorOnly !== true || emulatorMode) &&
|
|
69
|
+
(s.devOnly !== true || devMode),
|
|
70
|
+
).map((s) => {
|
|
71
|
+
const active = activeSection === s.path
|
|
72
|
+
return (
|
|
73
|
+
<Button
|
|
74
|
+
key={s.path}
|
|
75
|
+
type="button"
|
|
76
|
+
onPress={() => onSelect(s.path)}
|
|
77
|
+
variant="tertiary"
|
|
78
|
+
data-testid={`side-panel-${s.path}`}
|
|
79
|
+
aria-current={active ? "page" : undefined}
|
|
80
|
+
title={collapsed ? s.label : undefined}
|
|
81
|
+
className={`w-full justify-start hover:bg-surface-secondary ${active ? "bg-surface-secondary" : "bg-transparent"} ${collapsed ? "justify-center px-0" : ""}`}
|
|
82
|
+
>
|
|
83
|
+
<s.icon size={17} aria-hidden="true" />
|
|
84
|
+
{!collapsed && s.label}
|
|
85
|
+
</Button>
|
|
86
|
+
)
|
|
87
|
+
})}
|
|
88
|
+
</div>
|
|
89
|
+
<div
|
|
90
|
+
className={`${collapsed ? "hidden" : "block"} border-t border-separator px-4 py-3 text-xs text-muted`}
|
|
91
|
+
>
|
|
92
|
+
v{VERSION}
|
|
93
|
+
</div>
|
|
94
|
+
</nav>
|
|
95
|
+
)
|
|
96
|
+
}
|