@sirenodeck/sirenodeck 0.2.7 → 0.2.10
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 +327 -41554
- 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/coding-agents/global/backend.ts +15 -1
- package/src/builtin-addons/internal-settings/index.ts +0 -1
- package/src/builtin-addons/internal-settings/logo72x72.png +0 -0
- package/src/builtin-addons/media/backend.ts +21 -0
- package/src/builtin-addons/system-status/README.md +1 -1
- package/src/builtin-addons/system-status/domain/display-metrics.ts +1 -1
- package/src/builtin-addons/system-status/manifest.ts +1 -1
- package/src/cli/commands/emulator-mode.ts +27 -4
- package/src/cli/commands/service-manager.ts +53 -1
- package/src/device/black-frame.ts +3 -7
- package/src/vite/virtual-modules.ts +16 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Button, Description, Fieldset } from "@heroui/react"
|
|
2
|
+
import { Trash2 } from "lucide-react"
|
|
3
|
+
|
|
4
|
+
import { defaultValue, joinPath, labelFor } from "../utils"
|
|
5
|
+
import type { ControlProps } from "../types"
|
|
6
|
+
|
|
7
|
+
export const ArrayControl = ({
|
|
8
|
+
schema,
|
|
9
|
+
value,
|
|
10
|
+
path,
|
|
11
|
+
error,
|
|
12
|
+
onChange,
|
|
13
|
+
renderConfig,
|
|
14
|
+
deckOptions,
|
|
15
|
+
onPendingAssetChange,
|
|
16
|
+
}: ControlProps) => {
|
|
17
|
+
const items = Array.isArray(value) ? value : []
|
|
18
|
+
const itemSchema = schema.items ?? { type: "string" }
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Fieldset className="grid gap-2 rounded-lg border border-separator bg-surface-secondary p-2">
|
|
22
|
+
<Fieldset.Legend className="px-1 text-sm text-neutral-300">
|
|
23
|
+
{schema.title ?? labelFor(path.split(".").at(-1) ?? "Items")}
|
|
24
|
+
</Fieldset.Legend>
|
|
25
|
+
{schema.description && <Description>{schema.description}</Description>}
|
|
26
|
+
{error && (
|
|
27
|
+
<p role="alert" className="text-sm text-danger">
|
|
28
|
+
{error}
|
|
29
|
+
</p>
|
|
30
|
+
)}
|
|
31
|
+
{items.map((item, index) => (
|
|
32
|
+
<div
|
|
33
|
+
key={`${path}-${index}`}
|
|
34
|
+
className="flex min-w-0 items-start gap-2"
|
|
35
|
+
>
|
|
36
|
+
<div className="min-w-0 flex-1">
|
|
37
|
+
{renderConfig({
|
|
38
|
+
schema: itemSchema,
|
|
39
|
+
value: item,
|
|
40
|
+
path: joinPath(path, index),
|
|
41
|
+
onChange,
|
|
42
|
+
deckOptions,
|
|
43
|
+
compact: true,
|
|
44
|
+
onPendingAssetChange,
|
|
45
|
+
})}
|
|
46
|
+
</div>
|
|
47
|
+
<Button
|
|
48
|
+
type="button"
|
|
49
|
+
size="sm"
|
|
50
|
+
variant="tertiary"
|
|
51
|
+
isIconOnly
|
|
52
|
+
aria-label={`Delete item ${index + 1}`}
|
|
53
|
+
onPress={() =>
|
|
54
|
+
onChange(
|
|
55
|
+
path,
|
|
56
|
+
items.filter((_, itemIndex) => itemIndex !== index),
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
>
|
|
60
|
+
<Trash2 aria-hidden="true" className="size-4" />
|
|
61
|
+
</Button>
|
|
62
|
+
</div>
|
|
63
|
+
))}
|
|
64
|
+
<Button
|
|
65
|
+
type="button"
|
|
66
|
+
size="sm"
|
|
67
|
+
variant="secondary"
|
|
68
|
+
isDisabled={
|
|
69
|
+
schema.maxItems !== undefined && items.length >= schema.maxItems
|
|
70
|
+
}
|
|
71
|
+
onPress={() => onChange(path, [...items, defaultValue(itemSchema)])}
|
|
72
|
+
>
|
|
73
|
+
+ Add item
|
|
74
|
+
</Button>
|
|
75
|
+
</Fieldset>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Description, Label, Switch } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import type { ControlProps } from "../types"
|
|
4
|
+
|
|
5
|
+
const CONTROL_ROW_CLASS =
|
|
6
|
+
"grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-x-3 gap-y-1"
|
|
7
|
+
|
|
8
|
+
export const BooleanControl = ({
|
|
9
|
+
value,
|
|
10
|
+
path,
|
|
11
|
+
label,
|
|
12
|
+
description,
|
|
13
|
+
error,
|
|
14
|
+
onChange,
|
|
15
|
+
}: ControlProps) => (
|
|
16
|
+
<Switch
|
|
17
|
+
isSelected={value === true}
|
|
18
|
+
onChange={(next) => onChange(path, next)}
|
|
19
|
+
className="w-full min-w-0"
|
|
20
|
+
>
|
|
21
|
+
<Switch.Content className={`${CONTROL_ROW_CLASS} w-full cursor-pointer`}>
|
|
22
|
+
<Label className="min-w-0 break-words">{label}</Label>
|
|
23
|
+
<Switch.Control className="justify-self-start">
|
|
24
|
+
<Switch.Thumb />
|
|
25
|
+
</Switch.Control>
|
|
26
|
+
</Switch.Content>
|
|
27
|
+
{description && <Description>{description}</Description>}
|
|
28
|
+
{error && (
|
|
29
|
+
<p role="alert" className="text-sm text-danger">
|
|
30
|
+
{error}
|
|
31
|
+
</p>
|
|
32
|
+
)}
|
|
33
|
+
</Switch>
|
|
34
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ListBox, Select } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import { FormFieldParts } from "../FormFieldParts"
|
|
4
|
+
import type { ControlProps } from "../types"
|
|
5
|
+
|
|
6
|
+
const CONTROL_ROW_CLASS =
|
|
7
|
+
"grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-x-3 gap-y-1"
|
|
8
|
+
|
|
9
|
+
export const DeckSelectControl = ({
|
|
10
|
+
value,
|
|
11
|
+
path,
|
|
12
|
+
label,
|
|
13
|
+
description,
|
|
14
|
+
error,
|
|
15
|
+
deckOptions = [],
|
|
16
|
+
onChange,
|
|
17
|
+
}: ControlProps) => (
|
|
18
|
+
<Select
|
|
19
|
+
className={CONTROL_ROW_CLASS}
|
|
20
|
+
variant="secondary"
|
|
21
|
+
selectedKey={typeof value === "string" ? value : ""}
|
|
22
|
+
onSelectionChange={(key) => onChange(path, String(key))}
|
|
23
|
+
aria-label={label}
|
|
24
|
+
>
|
|
25
|
+
<FormFieldParts label={label} description={description} error={error}>
|
|
26
|
+
<Select.Trigger className="w-full min-w-0 border border-separator bg-field-background">
|
|
27
|
+
<Select.Value />
|
|
28
|
+
<Select.Indicator />
|
|
29
|
+
</Select.Trigger>
|
|
30
|
+
</FormFieldParts>
|
|
31
|
+
<Select.Popover>
|
|
32
|
+
<ListBox>
|
|
33
|
+
{deckOptions.map((deck) => (
|
|
34
|
+
<ListBox.Item
|
|
35
|
+
key={deck.id}
|
|
36
|
+
id={deck.id}
|
|
37
|
+
textValue={`${deck.name} ${deck.id}`}
|
|
38
|
+
>
|
|
39
|
+
{deck.name}{" "}
|
|
40
|
+
<span className="text-xs text-neutral-500">#{deck.id}</span>
|
|
41
|
+
<ListBox.ItemIndicator />
|
|
42
|
+
</ListBox.Item>
|
|
43
|
+
))}
|
|
44
|
+
</ListBox>
|
|
45
|
+
</Select.Popover>
|
|
46
|
+
</Select>
|
|
47
|
+
)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useState } from "react"
|
|
2
|
+
|
|
3
|
+
import { Button, TextField } from "@heroui/react"
|
|
4
|
+
|
|
5
|
+
import { EmojiPicker } from "../../../components/EmojiPicker"
|
|
6
|
+
import { FormFieldParts } from "../FormFieldParts"
|
|
7
|
+
import type { ControlProps } from "../types"
|
|
8
|
+
|
|
9
|
+
const CONTROL_ROW_CLASS =
|
|
10
|
+
"grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-x-3 gap-y-1"
|
|
11
|
+
|
|
12
|
+
export const EmojiControl = ({
|
|
13
|
+
value,
|
|
14
|
+
path,
|
|
15
|
+
label,
|
|
16
|
+
description,
|
|
17
|
+
error,
|
|
18
|
+
onChange,
|
|
19
|
+
}: ControlProps) => {
|
|
20
|
+
const [open, setOpen] = useState(false)
|
|
21
|
+
const [draft, setDraft] = useState(typeof value === "string" ? value : "")
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<TextField className={CONTROL_ROW_CLASS}>
|
|
25
|
+
<FormFieldParts label={label} description={description} error={error}>
|
|
26
|
+
<Button
|
|
27
|
+
type="button"
|
|
28
|
+
variant="tertiary"
|
|
29
|
+
className="w-full justify-start"
|
|
30
|
+
onPress={() => {
|
|
31
|
+
setDraft(typeof value === "string" ? value : "")
|
|
32
|
+
setOpen(true)
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
{typeof value === "string" && value !== "" ? value : "Choose emoji"}
|
|
36
|
+
</Button>
|
|
37
|
+
</FormFieldParts>
|
|
38
|
+
{open && (
|
|
39
|
+
<dialog
|
|
40
|
+
open
|
|
41
|
+
aria-label={`Choose ${label}`}
|
|
42
|
+
className="fixed inset-0 z-50 m-auto max-h-[85vh] w-[min(36rem,calc(100vw-2rem))] overflow-auto rounded-xl border border-separator bg-overlay p-4 text-overlay-foreground shadow-2xl"
|
|
43
|
+
>
|
|
44
|
+
<h3 className="mb-3 font-semibold">Choose {label}</h3>
|
|
45
|
+
<EmojiPicker value={draft} onSelect={setDraft} />
|
|
46
|
+
<div className="mt-3 flex justify-end gap-2 border-t border-separator pt-3">
|
|
47
|
+
<Button
|
|
48
|
+
type="button"
|
|
49
|
+
variant="tertiary"
|
|
50
|
+
onPress={() => setOpen(false)}
|
|
51
|
+
>
|
|
52
|
+
Cancel
|
|
53
|
+
</Button>
|
|
54
|
+
<Button
|
|
55
|
+
type="button"
|
|
56
|
+
variant="primary"
|
|
57
|
+
isDisabled={draft === ""}
|
|
58
|
+
onPress={() => {
|
|
59
|
+
onChange(path, draft)
|
|
60
|
+
setOpen(false)
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
Apply
|
|
64
|
+
</Button>
|
|
65
|
+
</div>
|
|
66
|
+
</dialog>
|
|
67
|
+
)}
|
|
68
|
+
</TextField>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Description } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import { IconPicker } from "../../../components/IconPicker"
|
|
4
|
+
import type { ControlProps } from "../types"
|
|
5
|
+
|
|
6
|
+
export const IconControl = ({
|
|
7
|
+
value,
|
|
8
|
+
path,
|
|
9
|
+
label,
|
|
10
|
+
description,
|
|
11
|
+
error,
|
|
12
|
+
onChange,
|
|
13
|
+
onPendingAssetChange,
|
|
14
|
+
}: ControlProps) => (
|
|
15
|
+
<div className="grid min-w-0 gap-2">
|
|
16
|
+
<IconPicker
|
|
17
|
+
label={label}
|
|
18
|
+
value={typeof value === "string" ? value : ""}
|
|
19
|
+
onApply={(next, asset) => {
|
|
20
|
+
onChange(path, next)
|
|
21
|
+
onPendingAssetChange?.(path, asset ?? null)
|
|
22
|
+
}}
|
|
23
|
+
/>
|
|
24
|
+
{description && <Description>{description}</Description>}
|
|
25
|
+
{error && (
|
|
26
|
+
<p role="alert" className="text-sm text-danger">
|
|
27
|
+
{error}
|
|
28
|
+
</p>
|
|
29
|
+
)}
|
|
30
|
+
</div>
|
|
31
|
+
)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Description } from "@heroui/react"
|
|
2
|
+
import { Fragment } from "react"
|
|
3
|
+
|
|
4
|
+
import { joinPath, labelFor } from "../utils"
|
|
5
|
+
import type { ControlProps } from "../types"
|
|
6
|
+
|
|
7
|
+
export const ObjectControl = ({
|
|
8
|
+
schema,
|
|
9
|
+
value,
|
|
10
|
+
path,
|
|
11
|
+
error,
|
|
12
|
+
compact,
|
|
13
|
+
onChange,
|
|
14
|
+
renderConfig,
|
|
15
|
+
deckOptions,
|
|
16
|
+
onPendingAssetChange,
|
|
17
|
+
}: ControlProps) => (
|
|
18
|
+
<div className="grid min-w-0 gap-3 border-l border-neutral-800 pl-3">
|
|
19
|
+
{schema.description && <Description>{schema.description}</Description>}
|
|
20
|
+
{error && (
|
|
21
|
+
<p role="alert" className="text-sm text-danger">
|
|
22
|
+
{error}
|
|
23
|
+
</p>
|
|
24
|
+
)}
|
|
25
|
+
{Object.entries(schema.properties ?? {})
|
|
26
|
+
.filter(([, child]) => child.internal !== true)
|
|
27
|
+
.map(([key, child]) => (
|
|
28
|
+
<Fragment key={key}>
|
|
29
|
+
{renderConfig({
|
|
30
|
+
schema: child,
|
|
31
|
+
value:
|
|
32
|
+
typeof value === "object" && value !== null
|
|
33
|
+
? (value as Record<string, unknown>)[key]
|
|
34
|
+
: undefined,
|
|
35
|
+
path: joinPath(path, key),
|
|
36
|
+
onChange,
|
|
37
|
+
deckOptions,
|
|
38
|
+
compact,
|
|
39
|
+
onPendingAssetChange,
|
|
40
|
+
})}
|
|
41
|
+
</Fragment>
|
|
42
|
+
))}
|
|
43
|
+
{Object.entries(schema.properties ?? {}).filter(
|
|
44
|
+
([, child]) => child.internal !== true,
|
|
45
|
+
).length === 0 && (
|
|
46
|
+
<p className="text-xs text-neutral-500">
|
|
47
|
+
{schema.title ?? labelFor(path.split(".").at(-1) ?? "Config")} has no
|
|
48
|
+
fields.
|
|
49
|
+
</p>
|
|
50
|
+
)}
|
|
51
|
+
</div>
|
|
52
|
+
)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useState } from "react"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Description,
|
|
6
|
+
Fieldset,
|
|
7
|
+
Input,
|
|
8
|
+
Label,
|
|
9
|
+
TextField,
|
|
10
|
+
} from "@heroui/react"
|
|
11
|
+
import { Trash2 } from "lucide-react"
|
|
12
|
+
|
|
13
|
+
import { defaultValue, joinPath, labelFor } from "../utils"
|
|
14
|
+
import type { ControlProps } from "../types"
|
|
15
|
+
|
|
16
|
+
const ENTRY_ROW_CLASS =
|
|
17
|
+
"grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-x-3 gap-y-1"
|
|
18
|
+
|
|
19
|
+
export const RecordControl = ({
|
|
20
|
+
schema,
|
|
21
|
+
value,
|
|
22
|
+
path,
|
|
23
|
+
error,
|
|
24
|
+
onChange,
|
|
25
|
+
renderConfig,
|
|
26
|
+
deckOptions,
|
|
27
|
+
onPendingAssetChange,
|
|
28
|
+
}: ControlProps) => {
|
|
29
|
+
const [newKey, setNewKey] = useState("")
|
|
30
|
+
const record =
|
|
31
|
+
typeof value === "object" && value !== null && !Array.isArray(value)
|
|
32
|
+
? (value as Record<string, unknown>)
|
|
33
|
+
: {}
|
|
34
|
+
const itemSchema =
|
|
35
|
+
typeof schema.additionalProperties === "object"
|
|
36
|
+
? schema.additionalProperties
|
|
37
|
+
: { type: "string" }
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Fieldset className="grid gap-2 rounded-lg border border-separator bg-surface-secondary p-2">
|
|
41
|
+
<Fieldset.Legend className="px-1 text-sm text-neutral-300">
|
|
42
|
+
{schema.title ?? labelFor(path.split(".").at(-1) ?? "Entries")}
|
|
43
|
+
</Fieldset.Legend>
|
|
44
|
+
{schema.description && <Description>{schema.description}</Description>}
|
|
45
|
+
{error && (
|
|
46
|
+
<p role="alert" className="text-sm text-danger">
|
|
47
|
+
{error}
|
|
48
|
+
</p>
|
|
49
|
+
)}
|
|
50
|
+
{Object.entries(record).map(([key, item]) => (
|
|
51
|
+
<div
|
|
52
|
+
key={key}
|
|
53
|
+
className="grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-start gap-2"
|
|
54
|
+
>
|
|
55
|
+
{renderConfig({
|
|
56
|
+
schema: itemSchema,
|
|
57
|
+
value: item,
|
|
58
|
+
path: joinPath(path, key),
|
|
59
|
+
onChange,
|
|
60
|
+
deckOptions,
|
|
61
|
+
onPendingAssetChange,
|
|
62
|
+
})}
|
|
63
|
+
<Button
|
|
64
|
+
type="button"
|
|
65
|
+
size="sm"
|
|
66
|
+
variant="tertiary"
|
|
67
|
+
isIconOnly
|
|
68
|
+
aria-label={`Delete ${key}`}
|
|
69
|
+
onPress={() => {
|
|
70
|
+
const next = { ...record }
|
|
71
|
+
delete next[key]
|
|
72
|
+
onChange(path, next)
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
<Trash2 aria-hidden="true" className="size-4" />
|
|
76
|
+
</Button>
|
|
77
|
+
</div>
|
|
78
|
+
))}
|
|
79
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
80
|
+
<TextField className={`${ENTRY_ROW_CLASS} flex-1`}>
|
|
81
|
+
<Label className="min-w-0 break-words">Entry name</Label>
|
|
82
|
+
<Input
|
|
83
|
+
aria-label="New entry name"
|
|
84
|
+
value={newKey}
|
|
85
|
+
onChange={(event) => setNewKey(event.target.value)}
|
|
86
|
+
/>
|
|
87
|
+
</TextField>
|
|
88
|
+
<Button
|
|
89
|
+
type="button"
|
|
90
|
+
variant="secondary"
|
|
91
|
+
isDisabled={newKey.trim() === "" || newKey in record}
|
|
92
|
+
onPress={() => {
|
|
93
|
+
const key = newKey.trim()
|
|
94
|
+
if (key === "" || key in record) return
|
|
95
|
+
onChange(path, { ...record, [key]: defaultValue(itemSchema) })
|
|
96
|
+
setNewKey("")
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
Add
|
|
100
|
+
</Button>
|
|
101
|
+
</div>
|
|
102
|
+
</Fieldset>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ListBox, Select } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import { FormFieldParts } from "../FormFieldParts"
|
|
4
|
+
import type { ControlProps } from "../types"
|
|
5
|
+
|
|
6
|
+
const CONTROL_ROW_CLASS =
|
|
7
|
+
"grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-x-3 gap-y-1"
|
|
8
|
+
|
|
9
|
+
export const SelectControl = ({
|
|
10
|
+
schema,
|
|
11
|
+
value,
|
|
12
|
+
path,
|
|
13
|
+
label,
|
|
14
|
+
description,
|
|
15
|
+
error,
|
|
16
|
+
onChange,
|
|
17
|
+
}: ControlProps) => (
|
|
18
|
+
<Select
|
|
19
|
+
className={CONTROL_ROW_CLASS}
|
|
20
|
+
variant="secondary"
|
|
21
|
+
selectedKey={JSON.stringify(value)}
|
|
22
|
+
onSelectionChange={(key) => onChange(path, JSON.parse(String(key)))}
|
|
23
|
+
aria-label={label}
|
|
24
|
+
>
|
|
25
|
+
<FormFieldParts label={label} description={description} error={error}>
|
|
26
|
+
<Select.Trigger className="w-full min-w-0 border border-separator bg-field-background">
|
|
27
|
+
<Select.Value />
|
|
28
|
+
<Select.Indicator />
|
|
29
|
+
</Select.Trigger>
|
|
30
|
+
</FormFieldParts>
|
|
31
|
+
<Select.Popover>
|
|
32
|
+
<ListBox>
|
|
33
|
+
{(schema.enum ?? []).map((option) => (
|
|
34
|
+
<ListBox.Item
|
|
35
|
+
key={JSON.stringify(option)}
|
|
36
|
+
id={JSON.stringify(option)}
|
|
37
|
+
textValue={String(option)}
|
|
38
|
+
>
|
|
39
|
+
{String(option)}
|
|
40
|
+
<ListBox.ItemIndicator />
|
|
41
|
+
</ListBox.Item>
|
|
42
|
+
))}
|
|
43
|
+
</ListBox>
|
|
44
|
+
</Select.Popover>
|
|
45
|
+
</Select>
|
|
46
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TextArea, TextField } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import { FormFieldParts } from "../FormFieldParts"
|
|
4
|
+
import type { ControlProps } from "../types"
|
|
5
|
+
|
|
6
|
+
const CONTROL_ROW_CLASS =
|
|
7
|
+
"grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-start gap-x-3 gap-y-1"
|
|
8
|
+
|
|
9
|
+
export const ShellControl = ({
|
|
10
|
+
value,
|
|
11
|
+
path,
|
|
12
|
+
label,
|
|
13
|
+
description,
|
|
14
|
+
error,
|
|
15
|
+
onChange,
|
|
16
|
+
}: ControlProps) => (
|
|
17
|
+
<TextField className={CONTROL_ROW_CLASS}>
|
|
18
|
+
<FormFieldParts label={label} description={description} error={error}>
|
|
19
|
+
<TextArea
|
|
20
|
+
aria-label={label}
|
|
21
|
+
rows={3}
|
|
22
|
+
value={typeof value === "string" ? value : ""}
|
|
23
|
+
onChange={(event) => onChange(path, event.target.value)}
|
|
24
|
+
spellCheck={false}
|
|
25
|
+
className="min-h-20 w-full resize-y font-mono text-sm"
|
|
26
|
+
/>
|
|
27
|
+
</FormFieldParts>
|
|
28
|
+
</TextField>
|
|
29
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Input, TextField } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import { FormFieldParts } from "../FormFieldParts"
|
|
4
|
+
import type { ControlProps } from "../types"
|
|
5
|
+
|
|
6
|
+
const CONTROL_ROW_CLASS =
|
|
7
|
+
"grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-x-3 gap-y-1"
|
|
8
|
+
|
|
9
|
+
export const TextControl = ({
|
|
10
|
+
schema,
|
|
11
|
+
value,
|
|
12
|
+
path,
|
|
13
|
+
label,
|
|
14
|
+
description,
|
|
15
|
+
error,
|
|
16
|
+
onChange,
|
|
17
|
+
}: ControlProps) => {
|
|
18
|
+
const inputType =
|
|
19
|
+
schema.type === "number" || schema.type === "integer" ? "number" : "text"
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<TextField className={`${CONTROL_ROW_CLASS} text-sm`}>
|
|
23
|
+
<FormFieldParts label={label} description={description} error={error}>
|
|
24
|
+
<Input
|
|
25
|
+
aria-label={label}
|
|
26
|
+
type={inputType}
|
|
27
|
+
value={String(value ?? "")}
|
|
28
|
+
onChange={(event) => {
|
|
29
|
+
const raw = event.target.value
|
|
30
|
+
onChange(path, inputType === "number" ? Number(raw) : raw)
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
</FormFieldParts>
|
|
34
|
+
</TextField>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ListBox, Select } from "@heroui/react"
|
|
2
|
+
|
|
3
|
+
import { FormFieldParts } from "../FormFieldParts"
|
|
4
|
+
import { defaultValue, labelFor } from "../utils"
|
|
5
|
+
import type { ControlProps } from "../types"
|
|
6
|
+
|
|
7
|
+
const CONTROL_ROW_CLASS =
|
|
8
|
+
"grid min-w-0 grid-cols-[minmax(min(10rem,42%),0.85fr)_minmax(0,1.15fr)] items-center gap-x-3 gap-y-1"
|
|
9
|
+
|
|
10
|
+
export const UnionControl = (props: ControlProps) => {
|
|
11
|
+
const { schema, value, path, onChange, renderConfig } = props
|
|
12
|
+
const variants = schema.oneOf ?? schema.anyOf ?? []
|
|
13
|
+
const currentType =
|
|
14
|
+
typeof value === "object" && value !== null
|
|
15
|
+
? (value as Record<string, unknown>).type
|
|
16
|
+
: undefined
|
|
17
|
+
const discriminatedIndex = variants.findIndex(
|
|
18
|
+
(variant) =>
|
|
19
|
+
variant.properties?.type?.enum?.includes(currentType) ||
|
|
20
|
+
variant.properties?.type?.const === currentType,
|
|
21
|
+
)
|
|
22
|
+
const currentKeys =
|
|
23
|
+
typeof value === "object" && value !== null && !Array.isArray(value)
|
|
24
|
+
? Object.keys(value)
|
|
25
|
+
: []
|
|
26
|
+
const selectedIndex =
|
|
27
|
+
discriminatedIndex >= 0
|
|
28
|
+
? discriminatedIndex
|
|
29
|
+
: Math.max(
|
|
30
|
+
0,
|
|
31
|
+
variants.reduce((bestIndex, variant, index) => {
|
|
32
|
+
const score = currentKeys.filter((key) =>
|
|
33
|
+
Object.prototype.hasOwnProperty.call(
|
|
34
|
+
variant.properties ?? {},
|
|
35
|
+
key,
|
|
36
|
+
),
|
|
37
|
+
).length
|
|
38
|
+
const best = variants[bestIndex]!
|
|
39
|
+
const bestScore = currentKeys.filter((key) =>
|
|
40
|
+
Object.prototype.hasOwnProperty.call(best.properties ?? {}, key),
|
|
41
|
+
).length
|
|
42
|
+
return score > bestScore ? index : bestIndex
|
|
43
|
+
}, 0),
|
|
44
|
+
)
|
|
45
|
+
const selectedSchema = variants[selectedIndex] ?? variants[0]!
|
|
46
|
+
const label = `${labelFor(path.split(".").at(-1) ?? "Value")} type`
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div className="grid gap-2">
|
|
50
|
+
<Select
|
|
51
|
+
className={CONTROL_ROW_CLASS}
|
|
52
|
+
variant="secondary"
|
|
53
|
+
selectedKey={String(selectedIndex)}
|
|
54
|
+
aria-label={label}
|
|
55
|
+
onSelectionChange={(key) => {
|
|
56
|
+
const nextSchema = variants[Number(key)] ?? selectedSchema
|
|
57
|
+
onChange(path, defaultValue(nextSchema))
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
<FormFieldParts
|
|
61
|
+
label={label}
|
|
62
|
+
description={schema.description}
|
|
63
|
+
error={props.error}
|
|
64
|
+
>
|
|
65
|
+
<Select.Trigger className="w-full min-w-0 border border-separator bg-field-background">
|
|
66
|
+
<Select.Value />
|
|
67
|
+
<Select.Indicator />
|
|
68
|
+
</Select.Trigger>
|
|
69
|
+
</FormFieldParts>
|
|
70
|
+
<Select.Popover>
|
|
71
|
+
<ListBox>
|
|
72
|
+
{variants.map((variant, index) => (
|
|
73
|
+
<ListBox.Item
|
|
74
|
+
key={index}
|
|
75
|
+
id={String(index)}
|
|
76
|
+
textValue={String(variant.title ?? `Option ${index + 1}`)}
|
|
77
|
+
>
|
|
78
|
+
{String(variant.title ?? `Option ${index + 1}`)}
|
|
79
|
+
<ListBox.ItemIndicator />
|
|
80
|
+
</ListBox.Item>
|
|
81
|
+
))}
|
|
82
|
+
</ListBox>
|
|
83
|
+
</Select.Popover>
|
|
84
|
+
</Select>
|
|
85
|
+
{renderConfig({
|
|
86
|
+
schema: selectedSchema,
|
|
87
|
+
value,
|
|
88
|
+
path,
|
|
89
|
+
onChange,
|
|
90
|
+
deckOptions: props.deckOptions,
|
|
91
|
+
compact: props.compact,
|
|
92
|
+
onPendingAssetChange: props.onPendingAssetChange,
|
|
93
|
+
})}
|
|
94
|
+
</div>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ComponentType } from "react"
|
|
2
|
+
|
|
3
|
+
import type { ControlProps } from "../types"
|
|
4
|
+
import { ActionControl } from "./ActionControl"
|
|
5
|
+
import { EmojiControl } from "./EmojiControl"
|
|
6
|
+
import { IconControl } from "./IconControl"
|
|
7
|
+
import { ShellControl } from "./ShellControl"
|
|
8
|
+
|
|
9
|
+
export const X_CONTROL_COMPONENTS: Record<
|
|
10
|
+
string,
|
|
11
|
+
ComponentType<ControlProps>
|
|
12
|
+
> = {
|
|
13
|
+
action: ActionControl,
|
|
14
|
+
emoji: EmojiControl,
|
|
15
|
+
icon: IconControl,
|
|
16
|
+
shell: ShellControl,
|
|
17
|
+
}
|