@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,232 @@
|
|
|
1
|
+
import { useEffect, useState } from "react"
|
|
2
|
+
|
|
3
|
+
interface DeckInfo {
|
|
4
|
+
id: string
|
|
5
|
+
sourceId?: string
|
|
6
|
+
generated?: boolean
|
|
7
|
+
pageIndex?: number
|
|
8
|
+
isOverlay: boolean
|
|
9
|
+
paginated: boolean
|
|
10
|
+
buttons:
|
|
11
|
+
| number
|
|
12
|
+
| Array<{
|
|
13
|
+
type: string
|
|
14
|
+
generated?: boolean
|
|
15
|
+
position?: number
|
|
16
|
+
config?: unknown
|
|
17
|
+
}>
|
|
18
|
+
internal: boolean
|
|
19
|
+
addonIndex?: number
|
|
20
|
+
overrideKey?: string
|
|
21
|
+
overrideFields?: string[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ButtonTypeInfo {
|
|
25
|
+
type: string
|
|
26
|
+
internal: boolean
|
|
27
|
+
generated?: boolean
|
|
28
|
+
defaultConfig?: unknown
|
|
29
|
+
gestureHandlers?: Array<"tap" | "dbl-tap" | "hold">
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AddonInfo {
|
|
33
|
+
name: string
|
|
34
|
+
addonIndex?: number
|
|
35
|
+
path?: string
|
|
36
|
+
internal: boolean
|
|
37
|
+
source: string
|
|
38
|
+
buttonTypes: ButtonTypeInfo[]
|
|
39
|
+
defaultButton: string | null
|
|
40
|
+
defaultConfig?: unknown
|
|
41
|
+
decks: DeckInfo[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface AddonInventory {
|
|
45
|
+
addons: AddonInfo[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const groupPaginated = (decks: DeckInfo[]): DeckInfo[] => {
|
|
49
|
+
const groups = new Map<string, DeckInfo>()
|
|
50
|
+
for (const deck of decks) {
|
|
51
|
+
const match = deck.id.match(/^(.+)-p(\d+)$/)
|
|
52
|
+
if (match?.[1] !== undefined && deck.paginated) {
|
|
53
|
+
const base = match[1]
|
|
54
|
+
if (!groups.has(base)) {
|
|
55
|
+
groups.set(base, { ...deck, id: base })
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
groups.set(deck.id, deck)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [...groups.values()]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const stripAddonPrefix = (id: string): string => {
|
|
65
|
+
const idx = id.indexOf(":")
|
|
66
|
+
return idx >= 0 ? id.slice(idx + 1) : id
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const deckModifiers = (deck: DeckInfo): string[] => {
|
|
70
|
+
const out: string[] = []
|
|
71
|
+
if (deck.isOverlay) out.push("◐")
|
|
72
|
+
else if (deck.paginated) out.push("⠿")
|
|
73
|
+
if (deck.internal) out.push("🔒")
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const Chip = ({
|
|
78
|
+
id,
|
|
79
|
+
label,
|
|
80
|
+
tone,
|
|
81
|
+
modifiers,
|
|
82
|
+
}: {
|
|
83
|
+
id: string
|
|
84
|
+
label: string
|
|
85
|
+
tone: "deck" | "button"
|
|
86
|
+
modifiers?: string[]
|
|
87
|
+
}) => {
|
|
88
|
+
const cls =
|
|
89
|
+
tone === "deck"
|
|
90
|
+
? "border-sky-500/60 text-sky-300 bg-sky-500/10"
|
|
91
|
+
: "border-emerald-500/60 text-emerald-300 bg-emerald-500/10"
|
|
92
|
+
const modSuffix =
|
|
93
|
+
modifiers !== undefined && modifiers.length > 0
|
|
94
|
+
? ` ${modifiers.join("")}`
|
|
95
|
+
: ""
|
|
96
|
+
return (
|
|
97
|
+
<span
|
|
98
|
+
title={id}
|
|
99
|
+
className={`inline-block rounded-full border px-2 py-0 font-mono text-[10px] font-bold uppercase tracking-wide ${cls}`}
|
|
100
|
+
>
|
|
101
|
+
{label}
|
|
102
|
+
{modSuffix}
|
|
103
|
+
</span>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const LegendModifier = ({ emoji, label }: { emoji: string; label: string }) => (
|
|
108
|
+
<span className="inline-flex items-center gap-1 text-neutral-400">
|
|
109
|
+
<span aria-hidden="true">{emoji}</span>
|
|
110
|
+
<span>{label}</span>
|
|
111
|
+
</span>
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
export interface AddonsPageProps {
|
|
115
|
+
addonInventory?: AddonInventory | null
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const AddonsPage = ({ addonInventory }: AddonsPageProps) => {
|
|
119
|
+
const [data, setData] = useState<AddonInventory | null>(
|
|
120
|
+
addonInventory ?? null,
|
|
121
|
+
)
|
|
122
|
+
const [error, setError] = useState<string | null>(null)
|
|
123
|
+
const [fetching, setFetching] = useState(addonInventory === undefined)
|
|
124
|
+
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (addonInventory !== undefined) return
|
|
127
|
+
let cancelled = false
|
|
128
|
+
void fetch("/api/addons")
|
|
129
|
+
.then((res) => {
|
|
130
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
|
131
|
+
return res.json() as Promise<{ addons: AddonInfo[] }>
|
|
132
|
+
})
|
|
133
|
+
.then((payload) => {
|
|
134
|
+
if (!cancelled) {
|
|
135
|
+
setData(payload)
|
|
136
|
+
setFetching(false)
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
.catch((err: unknown) => {
|
|
140
|
+
if (!cancelled) {
|
|
141
|
+
setError((err as Error).message)
|
|
142
|
+
setFetching(false)
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
return () => {
|
|
146
|
+
cancelled = true
|
|
147
|
+
}
|
|
148
|
+
}, [addonInventory])
|
|
149
|
+
|
|
150
|
+
if (fetching) {
|
|
151
|
+
return <div className="p-3 text-neutral-500">loading…</div>
|
|
152
|
+
}
|
|
153
|
+
if (error !== null) {
|
|
154
|
+
return (
|
|
155
|
+
<div className="p-3 text-red-400">Failed to load addons: {error}</div>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
if (data === null) {
|
|
159
|
+
return <div className="p-3 text-neutral-500">loading…</div>
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<div className="space-y-3 p-3" data-testid="addons-page">
|
|
164
|
+
<div
|
|
165
|
+
data-testid="addons-legend"
|
|
166
|
+
className="flex flex-wrap items-center gap-2 border-b border-neutral-800 pb-2 text-[10px] text-neutral-400"
|
|
167
|
+
>
|
|
168
|
+
<span className="font-semibold uppercase tracking-wide">Legend:</span>
|
|
169
|
+
<Chip id="kind-deck" label="deck" tone="deck" />
|
|
170
|
+
<Chip id="kind-button" label="button" tone="button" />
|
|
171
|
+
<LegendModifier emoji="◐" label="overlay" />
|
|
172
|
+
<LegendModifier emoji="⠿" label="paginated" />
|
|
173
|
+
<LegendModifier emoji="🔒" label="internal" />
|
|
174
|
+
<LegendModifier emoji="📦" label="builtin" />
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
{data.addons.map((addon) => (
|
|
178
|
+
<section
|
|
179
|
+
key={addon.name}
|
|
180
|
+
className="rounded-lg border border-neutral-800 bg-neutral-950 p-3"
|
|
181
|
+
>
|
|
182
|
+
<div className="flex items-baseline gap-2">
|
|
183
|
+
<h3 className="font-mono text-sm font-semibold text-neutral-100">
|
|
184
|
+
{addon.name}
|
|
185
|
+
{addon.internal === true && (
|
|
186
|
+
<span
|
|
187
|
+
title="builtin addon"
|
|
188
|
+
className="ml-1.5 font-mono text-[10px] text-neutral-500"
|
|
189
|
+
>
|
|
190
|
+
📦
|
|
191
|
+
</span>
|
|
192
|
+
)}
|
|
193
|
+
</h3>
|
|
194
|
+
{addon.source !== "cli" && (addon.path ?? addon.source) && (
|
|
195
|
+
<span className="font-mono text-[10px] text-neutral-500">
|
|
196
|
+
{addon.path ?? addon.source}
|
|
197
|
+
</span>
|
|
198
|
+
)}
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<div className="mt-2 flex flex-wrap gap-1.5">
|
|
202
|
+
{groupPaginated(addon.decks.filter((deck) => !deck.internal)).map(
|
|
203
|
+
(deck) => (
|
|
204
|
+
<Chip
|
|
205
|
+
key={deck.id}
|
|
206
|
+
id={deck.id}
|
|
207
|
+
label={stripAddonPrefix(deck.id)}
|
|
208
|
+
tone="deck"
|
|
209
|
+
modifiers={[
|
|
210
|
+
...deckModifiers(deck),
|
|
211
|
+
...(deck.generated === true ? ["generated"] : []),
|
|
212
|
+
]}
|
|
213
|
+
/>
|
|
214
|
+
),
|
|
215
|
+
)}
|
|
216
|
+
{addon.buttonTypes
|
|
217
|
+
.filter((bt) => !bt.internal)
|
|
218
|
+
.map((bt) => (
|
|
219
|
+
<Chip
|
|
220
|
+
key={bt.type}
|
|
221
|
+
id={bt.type}
|
|
222
|
+
label={stripAddonPrefix(bt.type)}
|
|
223
|
+
tone="button"
|
|
224
|
+
modifiers={bt.internal ? ["🔒"] : []}
|
|
225
|
+
/>
|
|
226
|
+
))}
|
|
227
|
+
</div>
|
|
228
|
+
</section>
|
|
229
|
+
))}
|
|
230
|
+
</div>
|
|
231
|
+
)
|
|
232
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useState } from "react"
|
|
2
|
+
|
|
3
|
+
import { getBridgeMessages, type BridgeMessageEntry } from "../bridge-log-store"
|
|
4
|
+
|
|
5
|
+
const formatPayload = (payload: unknown): string => {
|
|
6
|
+
try {
|
|
7
|
+
return JSON.stringify(payload)
|
|
8
|
+
} catch {
|
|
9
|
+
return String(payload)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const BridgeLogsPage = () => {
|
|
14
|
+
const [direction, setDirection] = useState<"all" | "sent" | "received">("all")
|
|
15
|
+
const [typeFilter, setTypeFilter] = useState("")
|
|
16
|
+
const [content, setContent] = useState("")
|
|
17
|
+
const [, force] = useState(0)
|
|
18
|
+
|
|
19
|
+
const messages: BridgeMessageEntry[] = getBridgeMessages({
|
|
20
|
+
direction,
|
|
21
|
+
...(typeFilter !== "" ? { type: typeFilter } : {}),
|
|
22
|
+
...(content !== "" ? { contentSubstring: content } : {}),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
data-testid="bridge-logs-page"
|
|
28
|
+
className="flex h-full flex-col gap-2 p-3"
|
|
29
|
+
>
|
|
30
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
31
|
+
<select
|
|
32
|
+
value={direction}
|
|
33
|
+
onChange={(e) =>
|
|
34
|
+
setDirection(e.target.value as "all" | "sent" | "received")
|
|
35
|
+
}
|
|
36
|
+
className="rounded bg-neutral-800 px-2 py-1 text-xs text-neutral-200"
|
|
37
|
+
data-testid="bridge-logs-direction"
|
|
38
|
+
>
|
|
39
|
+
<option value="all">all</option>
|
|
40
|
+
<option value="sent">sent</option>
|
|
41
|
+
<option value="received">received</option>
|
|
42
|
+
</select>
|
|
43
|
+
<input
|
|
44
|
+
type="text"
|
|
45
|
+
placeholder="type filter"
|
|
46
|
+
value={typeFilter}
|
|
47
|
+
onChange={(e) => setTypeFilter(e.target.value)}
|
|
48
|
+
className="rounded bg-neutral-800 px-2 py-1 text-xs text-neutral-200"
|
|
49
|
+
/>
|
|
50
|
+
<input
|
|
51
|
+
type="text"
|
|
52
|
+
placeholder="content substring"
|
|
53
|
+
value={content}
|
|
54
|
+
onChange={(e) => setContent(e.target.value)}
|
|
55
|
+
className="rounded bg-neutral-800 px-2 py-1 text-xs text-neutral-200"
|
|
56
|
+
data-testid="bridge-logs-content"
|
|
57
|
+
/>
|
|
58
|
+
<button
|
|
59
|
+
type="button"
|
|
60
|
+
onClick={() => force((n) => n + 1)}
|
|
61
|
+
className="rounded bg-neutral-700 px-2 py-1 text-xs text-neutral-200"
|
|
62
|
+
>
|
|
63
|
+
refresh
|
|
64
|
+
</button>
|
|
65
|
+
</div>
|
|
66
|
+
<ul
|
|
67
|
+
data-testid="bridge-logs-list"
|
|
68
|
+
className="flex-1 space-y-1 overflow-y-auto font-mono text-[11px]"
|
|
69
|
+
>
|
|
70
|
+
{messages.map((m, i) => (
|
|
71
|
+
<li
|
|
72
|
+
key={`${m.ts}-${i}`}
|
|
73
|
+
className={`rounded px-2 py-1 ${m.direction === "sent" ? "bg-sky-900/30" : "bg-emerald-900/30"}`}
|
|
74
|
+
>
|
|
75
|
+
<span className="text-neutral-500">
|
|
76
|
+
{new Date(m.ts).toISOString().slice(11, 19)}
|
|
77
|
+
</span>{" "}
|
|
78
|
+
<span className="text-neutral-400">{m.direction}</span>{" "}
|
|
79
|
+
<span className="font-semibold text-neutral-200">{m.type}</span>
|
|
80
|
+
{m.channel !== null && (
|
|
81
|
+
<span className="ml-2 text-neutral-500">#{m.channel}</span>
|
|
82
|
+
)}
|
|
83
|
+
<div className="truncate text-neutral-400">
|
|
84
|
+
{formatPayload(m.payload)}
|
|
85
|
+
</div>
|
|
86
|
+
</li>
|
|
87
|
+
))}
|
|
88
|
+
{messages.length === 0 && (
|
|
89
|
+
<li className="text-neutral-500">no messages</li>
|
|
90
|
+
)}
|
|
91
|
+
</ul>
|
|
92
|
+
</div>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ReactNode } from "react"
|
|
2
|
+
|
|
3
|
+
import { Description, Fieldset, Label, ListBox, Select } from "@heroui/react"
|
|
4
|
+
|
|
5
|
+
import { ButtonActionsEditor } from "../../components/ButtonActionsEditor"
|
|
6
|
+
import type { ButtonAppearance, ButtonThemeVariant } from "./types"
|
|
7
|
+
|
|
8
|
+
export const ButtonAppearanceFields = ({
|
|
9
|
+
value,
|
|
10
|
+
variants,
|
|
11
|
+
positionControl,
|
|
12
|
+
ownedGestures,
|
|
13
|
+
onChange,
|
|
14
|
+
}: {
|
|
15
|
+
readonly value: ButtonAppearance
|
|
16
|
+
readonly variants: Readonly<Record<string, ButtonThemeVariant>>
|
|
17
|
+
readonly positionControl: ReactNode
|
|
18
|
+
readonly ownedGestures?: readonly ("tap" | "dbl-tap" | "hold")[]
|
|
19
|
+
readonly onChange: (value: ButtonAppearance) => void
|
|
20
|
+
}) => (
|
|
21
|
+
<Fieldset className="grid min-w-0 gap-2 rounded-lg border border-separator bg-surface-secondary p-2">
|
|
22
|
+
<Fieldset.Legend className="px-1 text-sm font-medium">
|
|
23
|
+
Button appearance
|
|
24
|
+
</Fieldset.Legend>
|
|
25
|
+
<div className="grid min-w-0 grid-cols-1 items-start gap-3 md:grid-cols-2 xl:grid-cols-[auto_repeat(3,minmax(0,1fr))]">
|
|
26
|
+
{positionControl}
|
|
27
|
+
<Select
|
|
28
|
+
className="grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-2"
|
|
29
|
+
variant="secondary"
|
|
30
|
+
aria-label="Theme variant"
|
|
31
|
+
selectedKey={value.variant || "default"}
|
|
32
|
+
onSelectionChange={(key) =>
|
|
33
|
+
onChange({
|
|
34
|
+
...value,
|
|
35
|
+
variant: String(key) === "default" ? "" : String(key),
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
>
|
|
39
|
+
<Label className="min-w-0 break-words">Theme variant</Label>
|
|
40
|
+
<Select.Trigger className="w-full min-w-0 border border-separator bg-field-background">
|
|
41
|
+
<Select.Value />
|
|
42
|
+
<Select.Indicator />
|
|
43
|
+
</Select.Trigger>
|
|
44
|
+
<Select.Popover>
|
|
45
|
+
<ListBox>
|
|
46
|
+
{Object.entries(variants).map(([name, colors]) => (
|
|
47
|
+
<ListBox.Item key={name} id={name} textValue={name}>
|
|
48
|
+
<span
|
|
49
|
+
aria-hidden="true"
|
|
50
|
+
className="size-4 shrink-0 rounded-full border"
|
|
51
|
+
style={{
|
|
52
|
+
backgroundColor: colors.background,
|
|
53
|
+
borderColor: colors.border,
|
|
54
|
+
color: colors.foreground,
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
{name}
|
|
58
|
+
<ListBox.ItemIndicator />
|
|
59
|
+
</ListBox.Item>
|
|
60
|
+
))}
|
|
61
|
+
</ListBox>
|
|
62
|
+
</Select.Popover>
|
|
63
|
+
{value.variant !== "" && variants[value.variant] !== undefined && (
|
|
64
|
+
<Description
|
|
65
|
+
className="col-span-full h-2 rounded-full"
|
|
66
|
+
style={{ backgroundColor: variants[value.variant]!.background }}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
</Select>
|
|
70
|
+
</div>
|
|
71
|
+
<ButtonActionsEditor
|
|
72
|
+
value={value.actions}
|
|
73
|
+
ownedGestures={ownedGestures}
|
|
74
|
+
onChange={(actions) => onChange({ ...value, actions })}
|
|
75
|
+
/>
|
|
76
|
+
</Fieldset>
|
|
77
|
+
)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useState } from "react"
|
|
2
|
+
|
|
3
|
+
import { Button, Header, Input, Label, TextField } from "@heroui/react"
|
|
4
|
+
|
|
5
|
+
export interface ButtonTypeOption {
|
|
6
|
+
readonly addon: string
|
|
7
|
+
readonly type: string
|
|
8
|
+
readonly defaultConfig?: unknown
|
|
9
|
+
readonly gestureHandlers?: Array<"tap" | "dbl-tap" | "hold">
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const CONTROL_ROW_CLASS =
|
|
13
|
+
"grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-x-3 gap-y-1"
|
|
14
|
+
|
|
15
|
+
export const ButtonTypePicker = ({
|
|
16
|
+
options,
|
|
17
|
+
value,
|
|
18
|
+
label,
|
|
19
|
+
onSelect,
|
|
20
|
+
}: {
|
|
21
|
+
readonly options: readonly ButtonTypeOption[]
|
|
22
|
+
readonly value?: string
|
|
23
|
+
readonly label: string
|
|
24
|
+
readonly onSelect: (type: ButtonTypeOption) => void
|
|
25
|
+
}) => {
|
|
26
|
+
const [query, setQuery] = useState<string | null>(null)
|
|
27
|
+
const groups = [...new Set(options.map((option) => option.addon))]
|
|
28
|
+
.map((addon) => ({
|
|
29
|
+
addon,
|
|
30
|
+
options: options.filter(
|
|
31
|
+
(option) =>
|
|
32
|
+
option.addon === addon &&
|
|
33
|
+
`${option.addon} ${option.type}`
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.includes((query ?? "").toLowerCase()),
|
|
36
|
+
),
|
|
37
|
+
}))
|
|
38
|
+
.filter((group) => group.options.length > 0)
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col gap-2">
|
|
42
|
+
<TextField className={CONTROL_ROW_CLASS}>
|
|
43
|
+
<Label className="min-w-0 break-words">{label}</Label>
|
|
44
|
+
<Input
|
|
45
|
+
aria-label={label}
|
|
46
|
+
autoComplete="off"
|
|
47
|
+
placeholder="Search add-ons and button types"
|
|
48
|
+
value={query ?? value ?? ""}
|
|
49
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
50
|
+
/>
|
|
51
|
+
</TextField>
|
|
52
|
+
<div className="min-h-0 min-w-0 flex-1 overflow-y-auto rounded-lg border border-separator bg-surface-secondary p-1">
|
|
53
|
+
{groups.length === 0 ? (
|
|
54
|
+
<p className="px-2 py-1 text-sm text-muted">
|
|
55
|
+
No matching button types
|
|
56
|
+
</p>
|
|
57
|
+
) : (
|
|
58
|
+
groups.map(({ addon, options: addonOptions }) => (
|
|
59
|
+
<div key={addon} role="group" aria-label={addon} className="grid">
|
|
60
|
+
<Header className="px-2 py-1 text-xs text-muted">{addon}</Header>
|
|
61
|
+
{addonOptions.map((option) => (
|
|
62
|
+
<Button
|
|
63
|
+
key={option.type}
|
|
64
|
+
type="button"
|
|
65
|
+
size="sm"
|
|
66
|
+
variant="tertiary"
|
|
67
|
+
className="justify-start"
|
|
68
|
+
aria-pressed={option.type === value}
|
|
69
|
+
onPress={() => onSelect(option)}
|
|
70
|
+
>
|
|
71
|
+
{option.type}
|
|
72
|
+
</Button>
|
|
73
|
+
))}
|
|
74
|
+
</div>
|
|
75
|
+
))
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ArrayControl } from "./controls/ArrayControl"
|
|
2
|
+
import { BooleanControl } from "./controls/BooleanControl"
|
|
3
|
+
import { DeckSelectControl } from "./controls/DeckSelectControl"
|
|
4
|
+
import { ObjectControl } from "./controls/ObjectControl"
|
|
5
|
+
import { RecordControl } from "./controls/RecordControl"
|
|
6
|
+
import { SelectControl } from "./controls/SelectControl"
|
|
7
|
+
import { TextControl } from "./controls/TextControl"
|
|
8
|
+
import { UnionControl } from "./controls/UnionControl"
|
|
9
|
+
import { X_CONTROL_COMPONENTS } from "./controls/registry"
|
|
10
|
+
import { labelFor } from "./utils"
|
|
11
|
+
import type { ConfigFormProps, ControlProps } from "./types"
|
|
12
|
+
|
|
13
|
+
export const ConfigForm = (props: ConfigFormProps) => {
|
|
14
|
+
const { schema, path } = props
|
|
15
|
+
const controlProps: ControlProps = {
|
|
16
|
+
...props,
|
|
17
|
+
label: schema.title ?? labelFor(path.split(".").at(-1) ?? "Value"),
|
|
18
|
+
description: schema.description,
|
|
19
|
+
renderConfig: ConfigForm,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const variants = schema.oneOf ?? schema.anyOf
|
|
23
|
+
if (variants !== undefined && variants.length > 0)
|
|
24
|
+
return <UnionControl {...controlProps} />
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
schema.type === "object" &&
|
|
28
|
+
schema.additionalProperties !== undefined &&
|
|
29
|
+
Object.keys(schema.properties ?? {}).length === 0
|
|
30
|
+
)
|
|
31
|
+
return <RecordControl {...controlProps} />
|
|
32
|
+
|
|
33
|
+
const customControl = X_CONTROL_COMPONENTS[schema["x-control"] ?? ""]
|
|
34
|
+
if (customControl !== undefined) {
|
|
35
|
+
const CustomControl = customControl
|
|
36
|
+
return <CustomControl {...controlProps} />
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (schema.enum !== undefined) return <SelectControl {...controlProps} />
|
|
40
|
+
|
|
41
|
+
if (path.split(".").at(-1) === "deck" && props.deckOptions !== undefined)
|
|
42
|
+
return <DeckSelectControl {...controlProps} />
|
|
43
|
+
|
|
44
|
+
if (schema.type === "object" || schema.properties !== undefined)
|
|
45
|
+
return <ObjectControl {...controlProps} />
|
|
46
|
+
|
|
47
|
+
if (schema.type === "array") return <ArrayControl {...controlProps} />
|
|
48
|
+
if (schema.type === "boolean") return <BooleanControl {...controlProps} />
|
|
49
|
+
return <TextControl {...controlProps} />
|
|
50
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Description, Label } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import type { FieldPartsProps } from "./types"
|
|
4
|
+
|
|
5
|
+
export const FormFieldParts = ({
|
|
6
|
+
label,
|
|
7
|
+
description,
|
|
8
|
+
error,
|
|
9
|
+
children,
|
|
10
|
+
}: FieldPartsProps) => (
|
|
11
|
+
<>
|
|
12
|
+
<Label className="min-w-0 break-words">{label}</Label>
|
|
13
|
+
<div className="min-w-0">{children}</div>
|
|
14
|
+
{description && (
|
|
15
|
+
<Description className="col-span-full">{description}</Description>
|
|
16
|
+
)}
|
|
17
|
+
{error && (
|
|
18
|
+
<p role="alert" className="col-span-full text-sm text-danger">
|
|
19
|
+
{error}
|
|
20
|
+
</p>
|
|
21
|
+
)}
|
|
22
|
+
</>
|
|
23
|
+
)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Button, Label } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
export interface PositionPickerProps {
|
|
4
|
+
readonly mode: "edit" | "add"
|
|
5
|
+
readonly keyCount: number
|
|
6
|
+
readonly selected: number | null
|
|
7
|
+
readonly unset?: boolean
|
|
8
|
+
readonly disabledPositions?: readonly number[]
|
|
9
|
+
readonly onSelect: (position: number) => void
|
|
10
|
+
readonly onHover?: (position: number | null) => void
|
|
11
|
+
readonly onFirstAvailable?: () => void
|
|
12
|
+
readonly onUnset?: () => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const PositionPicker = ({
|
|
16
|
+
mode,
|
|
17
|
+
keyCount,
|
|
18
|
+
selected,
|
|
19
|
+
unset = false,
|
|
20
|
+
disabledPositions = [],
|
|
21
|
+
onSelect,
|
|
22
|
+
onHover,
|
|
23
|
+
onFirstAvailable,
|
|
24
|
+
onUnset,
|
|
25
|
+
}: PositionPickerProps) => (
|
|
26
|
+
<div className="grid content-start gap-1 text-sm">
|
|
27
|
+
<Label>Position</Label>
|
|
28
|
+
{onFirstAvailable !== undefined && (
|
|
29
|
+
<Button
|
|
30
|
+
type="button"
|
|
31
|
+
size="sm"
|
|
32
|
+
variant="tertiary"
|
|
33
|
+
className="h-[30px] min-w-0 justify-start px-2 text-xs"
|
|
34
|
+
onPress={onFirstAvailable}
|
|
35
|
+
>
|
|
36
|
+
First available
|
|
37
|
+
</Button>
|
|
38
|
+
)}
|
|
39
|
+
<div className="grid grid-cols-[repeat(5,30px)] justify-center gap-[3px]">
|
|
40
|
+
{Array.from({ length: keyCount }, (_, position) => {
|
|
41
|
+
const isLastPosition = mode === "add" && position === keyCount - 1
|
|
42
|
+
const isSelected = isLastPosition ? unset : selected === position
|
|
43
|
+
const isDisabled =
|
|
44
|
+
!isLastPosition && disabledPositions.includes(position)
|
|
45
|
+
return (
|
|
46
|
+
<Button
|
|
47
|
+
key={position}
|
|
48
|
+
type="button"
|
|
49
|
+
size="sm"
|
|
50
|
+
variant="secondary"
|
|
51
|
+
aria-label={`Position ${position}`}
|
|
52
|
+
aria-pressed={isSelected}
|
|
53
|
+
isDisabled={isDisabled}
|
|
54
|
+
onMouseEnter={() => onHover?.(position)}
|
|
55
|
+
onMouseLeave={() => onHover?.(null)}
|
|
56
|
+
onPress={() => {
|
|
57
|
+
if (isLastPosition) onUnset?.()
|
|
58
|
+
else onSelect(position)
|
|
59
|
+
}}
|
|
60
|
+
className="h-[30px] min-w-[30px] rounded border border-separator bg-surface-secondary p-0 text-xs text-foreground hover:bg-surface-secondary hover:outline hover:outline-2 hover:outline-offset-1 hover:outline-primary aria-pressed:border-primary aria-pressed:bg-white aria-pressed:text-neutral-950 aria-pressed:outline aria-pressed:outline-2 aria-pressed:outline-offset-1 aria-pressed:outline-primary"
|
|
61
|
+
>
|
|
62
|
+
{isLastPosition ? "∅" : position + 1}
|
|
63
|
+
</Button>
|
|
64
|
+
)
|
|
65
|
+
})}
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Description } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import { ActionValueEditor } from "../../../components/ActionValueEditor"
|
|
4
|
+
import type { ControlProps } from "../types"
|
|
5
|
+
|
|
6
|
+
export const ActionControl = ({
|
|
7
|
+
value,
|
|
8
|
+
path,
|
|
9
|
+
label,
|
|
10
|
+
description,
|
|
11
|
+
error,
|
|
12
|
+
onChange,
|
|
13
|
+
}: ControlProps) => (
|
|
14
|
+
<div className="grid min-w-0 gap-2">
|
|
15
|
+
<ActionValueEditor
|
|
16
|
+
label={label}
|
|
17
|
+
value={typeof value === "string" ? value : ""}
|
|
18
|
+
onChange={(next) => onChange(path, next)}
|
|
19
|
+
/>
|
|
20
|
+
{description && <Description>{description}</Description>}
|
|
21
|
+
{error && (
|
|
22
|
+
<p role="alert" className="text-sm text-danger">
|
|
23
|
+
{error}
|
|
24
|
+
</p>
|
|
25
|
+
)}
|
|
26
|
+
</div>
|
|
27
|
+
)
|