@glasshome/ui 1.21.1 → 1.21.2
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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/use-is-mobile.d.ts +3 -1
- package/dist/solid/index.d.ts +9 -9
- package/dist/solid/index.js +5431 -5424
- package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
- package/package.json +128 -126
- package/scripts/check-gallery.ts +142 -142
- package/scripts/check-pack.ts +13 -13
- package/scripts/check-structural-classes.ts +20 -20
- package/scripts/check-tokens.ts +27 -27
- package/scripts/check-ui-drift.mjs +103 -103
- package/src/index.ts +75 -80
- package/src/lib/alert-tones.ts +41 -41
- package/src/lib/anchor-placement.ts +21 -21
- package/src/lib/button-variants.ts +28 -28
- package/src/lib/card-classes.ts +9 -9
- package/src/lib/carousel-classes.ts +14 -14
- package/src/lib/glass-tone.ts +11 -11
- package/src/lib/input-classes.ts +6 -6
- package/src/lib/layers.ts +4 -4
- package/src/lib/logo-lockup.ts +8 -8
- package/src/lib/menu-classes.ts +2 -2
- package/src/lib/motion-classes.ts +8 -8
- package/src/lib/motion-window.ts +24 -24
- package/src/lib/overlay-classes.ts +6 -6
- package/src/lib/pill-classes.ts +3 -3
- package/src/lib/position-bar-classes.ts +1 -1
- package/src/lib/spotlight-geometry.ts +67 -67
- package/src/lib/thumb-classes.ts +2 -2
- package/src/lib/tier-badge.ts +16 -16
- package/src/lib/use-is-mobile.ts +17 -14
- package/src/lib/utils.ts +1 -1
- package/src/solid/accordion.tsx +41 -41
- package/src/solid/alert-dialog.tsx +95 -95
- package/src/solid/alert.tsx +88 -88
- package/src/solid/area-picker.tsx +204 -204
- package/src/solid/aspect-ratio.tsx +13 -13
- package/src/solid/avatar.tsx +27 -27
- package/src/solid/badge.tsx +49 -49
- package/src/solid/bottom-sheet/arbitration.ts +22 -22
- package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
- package/src/solid/bottom-sheet/drag-controller.ts +201 -201
- package/src/solid/bottom-sheet/focus-trap.ts +51 -47
- package/src/solid/bottom-sheet/index.ts +12 -12
- package/src/solid/bottom-sheet/keyboard.ts +25 -25
- package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
- package/src/solid/bottom-sheet/state-machine.ts +28 -28
- package/src/solid/bottom-sheet/velocity.ts +29 -29
- package/src/solid/breadcrumb.tsx +76 -76
- package/src/solid/button-group.tsx +46 -46
- package/src/solid/button.tsx +19 -19
- package/src/solid/card.tsx +67 -67
- package/src/solid/carousel.tsx +246 -246
- package/src/solid/charts.tsx +253 -253
- package/src/solid/checkbox.tsx +51 -51
- package/src/solid/collapsible.tsx +22 -22
- package/src/solid/color-disc.tsx +213 -213
- package/src/solid/color-slider.tsx +81 -81
- package/src/solid/color-wheel.tsx +61 -61
- package/src/solid/context-menu.tsx +63 -63
- package/src/solid/copy-button.tsx +31 -31
- package/src/solid/count-pill.tsx +11 -11
- package/src/solid/dashboard-preview.tsx +104 -104
- package/src/solid/data-table.tsx +228 -228
- package/src/solid/dialog-parts.tsx +127 -127
- package/src/solid/dialog.tsx +113 -113
- package/src/solid/dock-paging.ts +9 -9
- package/src/solid/dock.tsx +339 -339
- package/src/solid/docked-panel.tsx +35 -35
- package/src/solid/dropdown-menu.tsx +77 -77
- package/src/solid/empty.tsx +70 -70
- package/src/solid/entity-data.ts +38 -38
- package/src/solid/entity-selector.tsx +634 -634
- package/src/solid/field.tsx +205 -205
- package/src/solid/form.tsx +159 -159
- package/src/solid/hero-action.tsx +85 -85
- package/src/solid/hover-card.tsx +11 -11
- package/src/solid/icon-picker.tsx +401 -401
- package/src/solid/icon.tsx +101 -78
- package/src/solid/image-picker.tsx +416 -414
- package/src/solid/index.ts +265 -304
- package/src/solid/input-group.tsx +123 -123
- package/src/solid/input-otp.tsx +143 -143
- package/src/solid/input.tsx +4 -4
- package/src/solid/item.tsx +130 -130
- package/src/solid/kbd.tsx +20 -20
- package/src/solid/label.tsx +12 -12
- package/src/solid/list-reorder.ts +122 -122
- package/src/solid/logo.tsx +60 -60
- package/src/solid/media-copy.ts +21 -21
- package/src/solid/media-store.ts +56 -56
- package/src/solid/media-tile.tsx +85 -85
- package/src/solid/menu-parts.tsx +164 -164
- package/src/solid/number-field.tsx +56 -56
- package/src/solid/option-card.tsx +164 -164
- package/src/solid/ornament.tsx +43 -43
- package/src/solid/overlay.tsx +4 -4
- package/src/solid/page-header.tsx +75 -75
- package/src/solid/pagination.tsx +80 -80
- package/src/solid/password-input.tsx +51 -51
- package/src/solid/picker-row.tsx +83 -83
- package/src/solid/picker-search.tsx +65 -63
- package/src/solid/picker-trigger.tsx +59 -57
- package/src/solid/popover.tsx +54 -54
- package/src/solid/preview-tile.tsx +67 -67
- package/src/solid/progress.tsx +21 -21
- package/src/solid/radio-group.tsx +51 -51
- package/src/solid/resizable.tsx +128 -128
- package/src/solid/responsive-dialog.tsx +134 -134
- package/src/solid/schema-form.tsx +743 -743
- package/src/solid/scope-indicator.tsx +5 -5
- package/src/solid/scroll-area.tsx +16 -16
- package/src/solid/section-card.tsx +281 -281
- package/src/solid/select.tsx +101 -101
- package/src/solid/separator.tsx +25 -25
- package/src/solid/settings-row.tsx +122 -122
- package/src/solid/sheet.tsx +96 -96
- package/src/solid/skeleton.tsx +8 -8
- package/src/solid/slider.tsx +132 -132
- package/src/solid/sliding-indicator.tsx +280 -265
- package/src/solid/sonner.tsx +164 -164
- package/src/solid/spinner.tsx +12 -12
- package/src/solid/spotlight.tsx +140 -140
- package/src/solid/step-indicator.tsx +18 -18
- package/src/solid/swatch-picker.tsx +38 -38
- package/src/solid/switch.tsx +52 -52
- package/src/solid/table.tsx +63 -63
- package/src/solid/tabs.tsx +93 -93
- package/src/solid/textarea.tsx +8 -8
- package/src/solid/toggle-group.tsx +83 -83
- package/src/solid/toggle.tsx +33 -33
- package/src/solid/tooltip.tsx +16 -16
- package/src/solid/widget-card.tsx +90 -90
- package/src/solid/widget-identity.tsx +99 -99
- package/src/solid/widget-trust-badge.tsx +20 -20
- package/src/styles/globals.css +316 -319
- package/src/styles/theme.css +448 -448
- package/src/tokens/hex.ts +29 -29
- package/src/tokens/material.ts +75 -75
- package/src/tokens/presets.ts +303 -303
- package/src/tokens/readability.ts +32 -32
- package/src/tokens/theme-colors.ts +95 -95
- package/src/tokens/theme-css.ts +22 -22
- package/src/tokens/theme-recipe.ts +106 -106
|
@@ -24,26 +24,26 @@ import { Switch } from "./switch.js";
|
|
|
24
24
|
import { ToggleGroup, ToggleGroupItem } from "./toggle-group.js";
|
|
25
25
|
|
|
26
26
|
export interface ExtendedJSONSchema extends JSONSchema7 {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
/* Nested schemas carry the same extensions, so a whole tree types as one. */
|
|
28
|
+
properties?: { [key: string]: ExtendedJSONSchema | boolean };
|
|
29
|
+
items?: ExtendedJSONSchema | (ExtendedJSONSchema | boolean)[] | boolean;
|
|
30
|
+
/** Explicit control choice from the SDK's field.* helpers. */
|
|
31
|
+
formType?: string;
|
|
32
|
+
domain?: string;
|
|
33
|
+
singleSelect?: boolean;
|
|
34
|
+
deviceClass?: string;
|
|
35
|
+
/** formType "variants": the property that selects the active branch. */
|
|
36
|
+
discriminator?: string;
|
|
37
|
+
/** Enum value → display name (field.choice, field.choices, the variants selector). */
|
|
38
|
+
labels?: Record<string, string>;
|
|
39
|
+
/** field.choice: enum value → icon name; set, the choice renders as icon cards. */
|
|
40
|
+
icons?: Record<string, string>;
|
|
41
|
+
/** formType "image-picker": built-in pictures offered beside the uploads. */
|
|
42
|
+
presets?: Record<string, ImagePreset>;
|
|
43
|
+
/** formType "list": add-button caption. */
|
|
44
|
+
addLabel?: string;
|
|
45
|
+
/** formType "list": item field whose value captions the collapsed row. */
|
|
46
|
+
labelField?: string;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
@@ -54,11 +54,11 @@ export interface ExtendedJSONSchema extends JSONSchema7 {
|
|
|
54
54
|
* helpers by dash's formType parity test.
|
|
55
55
|
*/
|
|
56
56
|
export const SCHEMA_FORM_FORM_TYPES = [
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
"icon-picker",
|
|
58
|
+
"image-picker",
|
|
59
|
+
"area-picker",
|
|
60
|
+
"list",
|
|
61
|
+
"variants",
|
|
62
62
|
] as const;
|
|
63
63
|
|
|
64
64
|
const warnedLegacyAreaKeys = new Set<string>();
|
|
@@ -70,74 +70,74 @@ const warnedLegacyAreaKeys = new Set<string>();
|
|
|
70
70
|
* input. Declare `field.area()` instead — it works under any name.
|
|
71
71
|
*/
|
|
72
72
|
function isLegacyAreaKey(key: string, prop: ExtendedJSONSchema): boolean {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
const lower = key.toLowerCase();
|
|
74
|
+
if (prop.type !== "string" || (lower !== "areaid" && lower !== "area_id")) return false;
|
|
75
|
+
const isDev = typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
|
|
76
|
+
if (isDev && !warnedLegacyAreaKeys.has(key)) {
|
|
77
|
+
warnedLegacyAreaKeys.add(key);
|
|
78
|
+
console.warn(
|
|
79
|
+
`[SchemaForm] "${key}" renders an area picker because of its name. That fallback is removed in the next major; declare it with field.area() instead. https://glasshome.app/docs/widget-sdk/config`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function isKnownFormType(prop: ExtendedJSONSchema): boolean {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
return (
|
|
87
|
+
prop.formType === undefined ||
|
|
88
|
+
(SCHEMA_FORM_FORM_TYPES as readonly string[]).includes(prop.formType)
|
|
89
|
+
);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
function schemaOf(definition: unknown): ExtendedJSONSchema {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
return typeof definition === "object" && definition !== null
|
|
94
|
+
? (definition as ExtendedJSONSchema)
|
|
95
|
+
: {};
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function itemsOf(prop: ExtendedJSONSchema): ExtendedJSONSchema {
|
|
99
|
-
|
|
99
|
+
return Array.isArray(prop.items) ? {} : schemaOf(prop.items);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
function propertiesOf(prop: ExtendedJSONSchema): Array<[string, ExtendedJSONSchema]> {
|
|
103
|
-
|
|
103
|
+
return Object.entries(prop.properties ?? {}).map(([key, sub]) => [key, schemaOf(sub)]);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
function isEntityArray(prop: ExtendedJSONSchema): boolean {
|
|
107
|
-
|
|
107
|
+
return prop.type === "array" && itemsOf(prop).type === "string" && prop.domain !== undefined;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
function isStringArray(prop: ExtendedJSONSchema): boolean {
|
|
111
|
-
|
|
111
|
+
return prop.type === "array" && itemsOf(prop).type === "string";
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
function isChoiceArray(prop: ExtendedJSONSchema): boolean {
|
|
115
|
-
|
|
115
|
+
return prop.type === "array" && itemsOf(prop).enum !== undefined;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
function isObjectGroup(prop: ExtendedJSONSchema): boolean {
|
|
119
|
-
|
|
119
|
+
return prop.type === "object" && prop.properties !== undefined && prop.formType === undefined;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
function recordOf(value: unknown): Record<string, unknown> {
|
|
123
|
-
|
|
123
|
+
return typeof value === "object" && value !== null ? (value as Record<string, unknown>) : {};
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
function textOf(value: unknown): string {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean"
|
|
128
|
+
? String(value)
|
|
129
|
+
: "";
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
/** Property defaults declared on the wire (`default`), plus `const` seeds
|
|
133
133
|
* (a variant branch's discriminator literal serializes as `const`). */
|
|
134
134
|
function propertyDefaults(branch: ExtendedJSONSchema): Record<string, unknown> {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
const out: Record<string, unknown> = {};
|
|
136
|
+
for (const [key, sub] of propertiesOf(branch)) {
|
|
137
|
+
if (sub.const !== undefined) out[key] = structuredClone(sub.const);
|
|
138
|
+
else if (sub.default !== undefined) out[key] = structuredClone(sub.default);
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
/**
|
|
@@ -147,21 +147,21 @@ function propertyDefaults(branch: ExtendedJSONSchema): Record<string, unknown> {
|
|
|
147
147
|
* discriminator const.
|
|
148
148
|
*/
|
|
149
149
|
export function extractItemDefaults(schema: ExtendedJSONSchema): Record<string, unknown> {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
if (schema.default !== undefined) return recordOf(structuredClone(schema.default));
|
|
151
|
+
const branches = variantBranches(schema);
|
|
152
|
+
const first = branches[0];
|
|
153
|
+
if (first) return propertyDefaults(first);
|
|
154
|
+
return propertyDefaults(schema);
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
function variantBranches(schema: ExtendedJSONSchema): ExtendedJSONSchema[] {
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
const raw = schema.oneOf ?? schema.anyOf ?? [];
|
|
159
|
+
return raw.map(schemaOf).filter((b) => b.properties !== undefined);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
function branchKind(branch: ExtendedJSONSchema, discriminator: string): string {
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
const disc = schemaOf(branch.properties?.[discriminator]);
|
|
164
|
+
return typeof disc.const === "string" ? disc.const : "";
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
/**
|
|
@@ -169,325 +169,325 @@ function branchKind(branch: ExtendedJSONSchema, discriminator: string): string {
|
|
|
169
169
|
* (matched by name) and drops the rest; missing keys take the branch defaults.
|
|
170
170
|
*/
|
|
171
171
|
export function switchVariantValue(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
branch: ExtendedJSONSchema,
|
|
173
|
+
discriminator: string,
|
|
174
|
+
kind: string,
|
|
175
|
+
current: Record<string, unknown>,
|
|
176
176
|
): Record<string, unknown> {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
177
|
+
const next = propertyDefaults(branch);
|
|
178
|
+
for (const [key] of propertiesOf(branch)) {
|
|
179
|
+
if (key === discriminator) continue;
|
|
180
|
+
if (key in current && current[key] !== undefined) next[key] = current[key];
|
|
181
|
+
}
|
|
182
|
+
next[discriminator] = kind;
|
|
183
|
+
return next;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
interface SchemaFormProps {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
187
|
+
schema: ExtendedJSONSchema;
|
|
188
|
+
data: Record<string, unknown>;
|
|
189
|
+
onChange: (data: Record<string, unknown>) => void;
|
|
190
|
+
errors?: string[];
|
|
191
|
+
/** Passed through to IconPicker for formType: "icon-picker" fields. */
|
|
192
|
+
searchIcons?: IconPickerProps["searchIcons"];
|
|
193
|
+
class?: string;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
export function SchemaForm(props: SchemaFormProps) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
197
|
+
const properties = () => {
|
|
198
|
+
const schema = props.schema;
|
|
199
|
+
if (schema.type !== "object" || !schema.properties) return [];
|
|
200
|
+
return propertiesOf(schema);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// Controlled: props.data is the single source of truth, so parent-driven
|
|
204
|
+
// revert/reset/widget-switch reaches the visible form (audit finding #33).
|
|
205
|
+
const updateField = (key: string, value: unknown) => {
|
|
206
|
+
props.onChange({ ...props.data, [key]: value });
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<div class={cn("flex w-full min-w-0 flex-col gap-6", props.class)} data-slot="schema-form">
|
|
211
|
+
<For each={properties()}>
|
|
212
|
+
{([key, prop]) => (
|
|
213
|
+
<LabeledField
|
|
214
|
+
id={key}
|
|
215
|
+
name={key}
|
|
216
|
+
prop={prop}
|
|
217
|
+
value={props.data[key]}
|
|
218
|
+
onChange={(value) => updateField(key, value)}
|
|
219
|
+
searchIcons={props.searchIcons}
|
|
220
|
+
/>
|
|
221
|
+
)}
|
|
222
|
+
</For>
|
|
223
|
+
|
|
224
|
+
<Show when={props.errors && props.errors.length > 0}>
|
|
225
|
+
<Alert tone="destructive" title="Validation errors">
|
|
226
|
+
<ul class="flex list-inside list-disc flex-col gap-1">
|
|
227
|
+
<For each={props.errors}>{(err) => <li>{err}</li>}</For>
|
|
228
|
+
</ul>
|
|
229
|
+
</Alert>
|
|
230
|
+
</Show>
|
|
231
|
+
</div>
|
|
232
|
+
);
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
interface FieldProps {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
236
|
+
/** Unique control id (dot-path for nested fields). */
|
|
237
|
+
id: string;
|
|
238
|
+
/** Property key: label fallback and the legacy areaId heuristic. */
|
|
239
|
+
name: string;
|
|
240
|
+
prop: ExtendedJSONSchema;
|
|
241
|
+
value: unknown;
|
|
242
|
+
onChange: (value: unknown) => void;
|
|
243
|
+
searchIcons?: IconPickerProps["searchIcons"];
|
|
244
|
+
/** Id of the FieldLabel naming this control, for the kinds that render no
|
|
245
|
+
* element carrying `id`. */
|
|
246
|
+
labelledBy?: string;
|
|
247
|
+
/**
|
|
248
|
+
* This field is the root of a list item: the item Card is already its
|
|
249
|
+
* container and its header row already captions it, so a group renders its
|
|
250
|
+
* properties bare. Never forwarded down, so a group nested below the item
|
|
251
|
+
* root keeps the box that delimits it.
|
|
252
|
+
*/
|
|
253
|
+
bare?: boolean;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
/* The dispatch, as data: first match wins, and the same answer decides how the
|
|
257
257
|
* label reaches the control. Order is the contract (a legacy areaId key is a
|
|
258
258
|
* string like any other, so it has to be asked about before `enum`/`type`). */
|
|
259
259
|
type ControlKind =
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
260
|
+
| "unknown"
|
|
261
|
+
| "list"
|
|
262
|
+
| "variants"
|
|
263
|
+
| "entities"
|
|
264
|
+
| "icon"
|
|
265
|
+
| "image"
|
|
266
|
+
| "area"
|
|
267
|
+
| "enum"
|
|
268
|
+
| "boolean"
|
|
269
|
+
| "number"
|
|
270
|
+
| "choices"
|
|
271
|
+
| "strings"
|
|
272
|
+
| "group"
|
|
273
|
+
| "text";
|
|
274
274
|
|
|
275
275
|
const CONTROL_KINDS: ReadonlyArray<
|
|
276
|
-
|
|
276
|
+
readonly [ControlKind, (prop: ExtendedJSONSchema, name: string) => boolean]
|
|
277
277
|
> = [
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
278
|
+
["unknown", (prop) => !isKnownFormType(prop)],
|
|
279
|
+
["list", (prop) => prop.formType === "list"],
|
|
280
|
+
["variants", (prop) => prop.formType === "variants"],
|
|
281
|
+
["entities", (prop) => isEntityArray(prop)],
|
|
282
|
+
["icon", (prop) => prop.formType === "icon-picker"],
|
|
283
|
+
["image", (prop) => prop.formType === "image-picker"],
|
|
284
|
+
["area", (prop, name) => prop.formType === "area-picker" || isLegacyAreaKey(name, prop)],
|
|
285
|
+
["enum", (prop) => prop.enum !== undefined],
|
|
286
|
+
["boolean", (prop) => prop.type === "boolean"],
|
|
287
|
+
["number", (prop) => prop.type === "number" || prop.type === "integer"],
|
|
288
|
+
["choices", (prop) => isChoiceArray(prop)],
|
|
289
|
+
["strings", (prop) => isStringArray(prop)],
|
|
290
|
+
["group", (prop) => isObjectGroup(prop)],
|
|
291
291
|
];
|
|
292
292
|
|
|
293
293
|
function controlKind(prop: ExtendedJSONSchema, name: string): ControlKind {
|
|
294
|
-
|
|
294
|
+
return CONTROL_KINDS.find(([, matches]) => matches(prop, name))?.[0] ?? "text";
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
/* `for` only where the control really renders an element carrying the field id;
|
|
298
298
|
* a picker trigger or a composite group is named by aria-labelledby instead, so
|
|
299
299
|
* no label points at nothing. `none`: nothing focusable to name. */
|
|
300
300
|
const LABEL_TARGET: Record<ControlKind, "for" | "labelledby" | "none"> = {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
301
|
+
text: "for",
|
|
302
|
+
image: "for",
|
|
303
|
+
number: "for",
|
|
304
|
+
entities: "labelledby",
|
|
305
|
+
icon: "labelledby",
|
|
306
|
+
area: "labelledby",
|
|
307
|
+
enum: "labelledby",
|
|
308
|
+
boolean: "labelledby",
|
|
309
|
+
list: "labelledby",
|
|
310
|
+
variants: "labelledby",
|
|
311
|
+
choices: "labelledby",
|
|
312
|
+
strings: "labelledby",
|
|
313
|
+
unknown: "none",
|
|
314
|
+
group: "none",
|
|
315
315
|
};
|
|
316
316
|
|
|
317
317
|
/* A hint belongs to the label above it, not to the control below: under the
|
|
318
318
|
* control it reads as the next field's. Groups carry their own caption. */
|
|
319
319
|
function LabeledField(props: FieldProps) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
320
|
+
const kind = () => controlKind(props.prop, props.name);
|
|
321
|
+
const labelId = () => `${props.id}-label`;
|
|
322
|
+
const target = () => LABEL_TARGET[kind()];
|
|
323
|
+
return (
|
|
324
|
+
<Show when={kind() !== "group"} fallback={<FieldControl {...props} />}>
|
|
325
|
+
<Field>
|
|
326
|
+
<FieldLabel id={labelId()} for={target() === "for" ? props.id : undefined}>
|
|
327
|
+
{props.prop.title || props.name}
|
|
328
|
+
</FieldLabel>
|
|
329
|
+
<Show when={props.prop.description}>
|
|
330
|
+
{(description) => <FieldDescription>{description()}</FieldDescription>}
|
|
331
|
+
</Show>
|
|
332
|
+
<FieldControl {...props} labelledBy={target() === "labelledby" ? labelId() : undefined} />
|
|
333
|
+
</Field>
|
|
334
|
+
</Show>
|
|
335
|
+
);
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
/** The one recursive dispatch: every nesting level renders through here. */
|
|
339
339
|
function FieldControl(props: FieldProps) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
340
|
+
const current = () => props.value ?? props.prop.default;
|
|
341
|
+
const text = () => textOf(current());
|
|
342
|
+
const enumLabel = (value: string) => props.prop.labels?.[value] ?? value;
|
|
343
|
+
const kind = () => controlKind(props.prop, props.name);
|
|
344
|
+
return (
|
|
345
|
+
<SwitchFlow
|
|
346
|
+
fallback={
|
|
347
|
+
<Input
|
|
348
|
+
id={props.id}
|
|
349
|
+
type="text"
|
|
350
|
+
value={text()}
|
|
351
|
+
onInput={(e) => props.onChange(e.currentTarget.value)}
|
|
352
|
+
/>
|
|
353
|
+
}
|
|
354
|
+
>
|
|
355
|
+
<Match when={kind() === "unknown"}>
|
|
356
|
+
<Alert tone="info" data-slot="schema-form-unknown">
|
|
357
|
+
This setting needs a newer dashboard version to be edited here.
|
|
358
|
+
</Alert>
|
|
359
|
+
</Match>
|
|
360
|
+
<Match when={kind() === "list"}>
|
|
361
|
+
<ListControl {...props} />
|
|
362
|
+
</Match>
|
|
363
|
+
<Match when={kind() === "variants"}>
|
|
364
|
+
<VariantsControl {...props} />
|
|
365
|
+
</Match>
|
|
366
|
+
<Match when={kind() === "entities"}>
|
|
367
|
+
<EntitySelector
|
|
368
|
+
aria-labelledby={props.labelledBy}
|
|
369
|
+
entityIds={(current() as string[]) ?? []}
|
|
370
|
+
onEntityIdsChange={(ids) => props.onChange(ids)}
|
|
371
|
+
domain={props.prop.domain ?? ""}
|
|
372
|
+
deviceClass={props.prop.deviceClass}
|
|
373
|
+
multiple={props.prop.singleSelect !== true}
|
|
374
|
+
/>
|
|
375
|
+
</Match>
|
|
376
|
+
<Match when={kind() === "icon"}>
|
|
377
|
+
<IconPicker
|
|
378
|
+
aria-labelledby={props.labelledBy}
|
|
379
|
+
value={text()}
|
|
380
|
+
onChange={(val) => props.onChange(val)}
|
|
381
|
+
searchIcons={props.searchIcons}
|
|
382
|
+
/>
|
|
383
|
+
</Match>
|
|
384
|
+
<Match when={kind() === "image"}>
|
|
385
|
+
<ImagePicker
|
|
386
|
+
id={props.id}
|
|
387
|
+
presets={props.prop.presets}
|
|
388
|
+
value={text()}
|
|
389
|
+
onChange={(val) => props.onChange(val)}
|
|
390
|
+
/>
|
|
391
|
+
</Match>
|
|
392
|
+
<Match when={kind() === "area"}>
|
|
393
|
+
<AreaPicker
|
|
394
|
+
aria-labelledby={props.labelledBy}
|
|
395
|
+
value={text()}
|
|
396
|
+
onChange={(val) => props.onChange(val)}
|
|
397
|
+
/>
|
|
398
|
+
</Match>
|
|
399
|
+
<Match when={kind() === "enum" && props.prop.icons}>
|
|
400
|
+
{(icons) => (
|
|
401
|
+
<OptionCardGroup
|
|
402
|
+
aria-labelledby={props.labelledBy}
|
|
403
|
+
value={text()}
|
|
404
|
+
onChange={(val) => props.onChange(val)}
|
|
405
|
+
class="grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))]"
|
|
406
|
+
>
|
|
407
|
+
<For each={(props.prop.enum ?? []).map(String)}>
|
|
408
|
+
{(value) => (
|
|
409
|
+
<OptionCard value={value} title={enumLabel(value)} icon={icons()[value]} />
|
|
410
|
+
)}
|
|
411
|
+
</For>
|
|
412
|
+
</OptionCardGroup>
|
|
413
|
+
)}
|
|
414
|
+
</Match>
|
|
415
|
+
<Match when={kind() === "enum"}>
|
|
416
|
+
<Select
|
|
417
|
+
value={text()}
|
|
418
|
+
onChange={(val) => {
|
|
419
|
+
if (val != null) props.onChange(val);
|
|
420
|
+
}}
|
|
421
|
+
options={(props.prop.enum ?? []).map(String)}
|
|
422
|
+
itemComponent={(itemProps) => (
|
|
423
|
+
<SelectItem item={itemProps.item}>
|
|
424
|
+
{enumLabel(String(itemProps.item.rawValue))}
|
|
425
|
+
</SelectItem>
|
|
426
|
+
)}
|
|
427
|
+
>
|
|
428
|
+
<SelectTrigger class="w-full" aria-labelledby={props.labelledBy}>
|
|
429
|
+
<SelectValue<string>>{(state) => enumLabel(state.selectedOption())}</SelectValue>
|
|
430
|
+
</SelectTrigger>
|
|
431
|
+
<SelectContent />
|
|
432
|
+
</Select>
|
|
433
|
+
</Match>
|
|
434
|
+
<Match when={kind() === "boolean"}>
|
|
435
|
+
<div class="flex items-center gap-3">
|
|
436
|
+
<Switch
|
|
437
|
+
aria-labelledby={props.labelledBy}
|
|
438
|
+
checked={Boolean(current() ?? false)}
|
|
439
|
+
onChange={(checked) => props.onChange(checked)}
|
|
440
|
+
/>
|
|
441
|
+
<span class="text-sm">{current() ? "Enabled" : "Disabled"}</span>
|
|
442
|
+
</div>
|
|
443
|
+
</Match>
|
|
444
|
+
<Match when={kind() === "number"}>
|
|
445
|
+
<NumberField
|
|
446
|
+
id={props.id}
|
|
447
|
+
value={Number(current() ?? 0)}
|
|
448
|
+
min={props.prop.minimum}
|
|
449
|
+
max={props.prop.maximum}
|
|
450
|
+
step={props.prop.type === "integer" ? 1 : "any"}
|
|
451
|
+
onInput={(e) => props.onChange(Number(e.currentTarget.value))}
|
|
452
|
+
/>
|
|
453
|
+
</Match>
|
|
454
|
+
<Match when={kind() === "choices"}>
|
|
455
|
+
<ChoicesControl {...props} />
|
|
456
|
+
</Match>
|
|
457
|
+
<Match when={kind() === "strings"}>
|
|
458
|
+
<StringListField
|
|
459
|
+
labelledBy={props.labelledBy}
|
|
460
|
+
value={(current() as string[]) ?? []}
|
|
461
|
+
onChange={(val) => props.onChange(val)}
|
|
462
|
+
/>
|
|
463
|
+
</Match>
|
|
464
|
+
<Match when={kind() === "group"}>
|
|
465
|
+
<FieldSet
|
|
466
|
+
class={cn(props.bare !== true && "border-border rounded-lg border p-3")}
|
|
467
|
+
data-slot="schema-form-object"
|
|
468
|
+
>
|
|
469
|
+
<Show when={props.bare !== true}>
|
|
470
|
+
<FieldLegend variant="label">{props.prop.title || props.name}</FieldLegend>
|
|
471
|
+
</Show>
|
|
472
|
+
<Show when={props.prop.description}>
|
|
473
|
+
{(description) => <FieldDescription>{description()}</FieldDescription>}
|
|
474
|
+
</Show>
|
|
475
|
+
<For each={propertiesOf(props.prop)}>
|
|
476
|
+
{([subKey, subProp]) => (
|
|
477
|
+
<LabeledField
|
|
478
|
+
id={`${props.id}.${subKey}`}
|
|
479
|
+
name={subKey}
|
|
480
|
+
prop={subProp}
|
|
481
|
+
value={recordOf(current())[subKey]}
|
|
482
|
+
onChange={(value) => props.onChange({ ...recordOf(current()), [subKey]: value })}
|
|
483
|
+
searchIcons={props.searchIcons}
|
|
484
|
+
/>
|
|
485
|
+
)}
|
|
486
|
+
</For>
|
|
487
|
+
</FieldSet>
|
|
488
|
+
</Match>
|
|
489
|
+
</SwitchFlow>
|
|
490
|
+
);
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
/* The drop slot the drag preview opens is the list's own gap, so both faces of
|
|
@@ -495,409 +495,409 @@ function FieldControl(props: FieldProps) {
|
|
|
495
495
|
const LIST_GAP = { class: "gap-2", px: 8 } as const;
|
|
496
496
|
|
|
497
497
|
function ListControl(props: FieldProps) {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
498
|
+
const itemSchema = () => itemsOf(props.prop);
|
|
499
|
+
const mediaStore = useMediaStore();
|
|
500
|
+
const [brokenThumbs, setBrokenThumbs] = createSignal<ReadonlySet<string>>(new Set());
|
|
501
|
+
|
|
502
|
+
// One image field is unambiguously the row's picture. Two would need the
|
|
503
|
+
// author to say which, so both zero and two keep the plain text row.
|
|
504
|
+
const imageKey = createMemo(() => {
|
|
505
|
+
const image = propertiesOf(itemSchema()).filter(([, sub]) => sub.formType === "image-picker");
|
|
506
|
+
return image.length === 1 ? image[0]?.[0] : undefined;
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
const thumbUrl = (item: unknown) => {
|
|
510
|
+
const key = imageKey();
|
|
511
|
+
if (key === undefined) return undefined;
|
|
512
|
+
const id = recordOf(item)[key];
|
|
513
|
+
if (typeof id !== "string" || id === "") return undefined;
|
|
514
|
+
const preset = imagePreset(id);
|
|
515
|
+
if (preset !== undefined)
|
|
516
|
+
return propertiesOf(itemSchema()).find(([k]) => k === key)?.[1].presets?.[preset]?.thumb;
|
|
517
|
+
const store = mediaStore;
|
|
518
|
+
if (!store) return undefined;
|
|
519
|
+
// A 32px row chip: the thumb variant, never the original.
|
|
520
|
+
return store.url(id, "thumb");
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
const liveThumbUrl = (item: unknown) => {
|
|
524
|
+
const url = thumbUrl(item);
|
|
525
|
+
return url !== undefined && !brokenThumbs().has(url) ? url : undefined;
|
|
526
|
+
};
|
|
527
|
+
const items = () => {
|
|
528
|
+
const value = props.value ?? props.prop.default;
|
|
529
|
+
return Array.isArray(value) ? (value as unknown[]) : [];
|
|
530
|
+
};
|
|
531
|
+
const minItems = () => props.prop.minItems ?? 0;
|
|
532
|
+
const atMax = () => props.prop.maxItems !== undefined && items().length >= props.prop.maxItems;
|
|
533
|
+
const [openIndex, setOpenIndex] = createSignal(-1);
|
|
534
|
+
|
|
535
|
+
const kindLabel = (item: unknown) => {
|
|
536
|
+
const schema = itemSchema();
|
|
537
|
+
if (schema.formType !== "variants" || schema.discriminator === undefined) return undefined;
|
|
538
|
+
const kind = recordOf(item)[schema.discriminator];
|
|
539
|
+
if (typeof kind !== "string") return undefined;
|
|
540
|
+
return schema.labels?.[kind] ?? kind;
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const labelFieldValue = (item: unknown): string | undefined => {
|
|
544
|
+
const labelField = props.prop.labelField;
|
|
545
|
+
if (labelField === undefined) return undefined;
|
|
546
|
+
const value = recordOf(item)[labelField];
|
|
547
|
+
if (typeof value === "string" && value.trim() !== "") return value;
|
|
548
|
+
if (typeof value === "number") return String(value);
|
|
549
|
+
return undefined;
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
const caption = (item: unknown, index: number) =>
|
|
553
|
+
labelFieldValue(item) ?? kindLabel(item) ?? `Item ${index + 1}`;
|
|
554
|
+
|
|
555
|
+
// Only a row the labelField already named has anything left for the badge.
|
|
556
|
+
const badgeLabel = (item: unknown) =>
|
|
557
|
+
labelFieldValue(item) === undefined ? undefined : kindLabel(item);
|
|
558
|
+
|
|
559
|
+
const replaceAt = (index: number, value: unknown) => {
|
|
560
|
+
props.onChange(items().map((item, i) => (i === index ? value : item)));
|
|
561
|
+
};
|
|
562
|
+
const removeAt = (index: number) => {
|
|
563
|
+
props.onChange(items().filter((_, i) => i !== index));
|
|
564
|
+
if (openIndex() === index) setOpenIndex(-1);
|
|
565
|
+
else if (openIndex() > index) setOpenIndex(openIndex() - 1);
|
|
566
|
+
};
|
|
567
|
+
const reorder = (from: number, to: number) => {
|
|
568
|
+
if (to === from || to < 0 || to >= items().length) return;
|
|
569
|
+
const next = [...items()];
|
|
570
|
+
const [moved] = next.splice(from, 1);
|
|
571
|
+
next.splice(to, 0, moved);
|
|
572
|
+
props.onChange(next);
|
|
573
|
+
const open = openIndex();
|
|
574
|
+
if (open === from) setOpenIndex(to);
|
|
575
|
+
else if (open !== -1) {
|
|
576
|
+
if (from < open && to >= open) setOpenIndex(open - 1);
|
|
577
|
+
else if (from > open && to <= open) setOpenIndex(open + 1);
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
const listDrag = createListReorder({
|
|
582
|
+
count: () => items().length,
|
|
583
|
+
gapPx: LIST_GAP.px,
|
|
584
|
+
onReorder: reorder,
|
|
585
|
+
onDragStart: (index) => {
|
|
586
|
+
if (openIndex() === index) setOpenIndex(-1);
|
|
587
|
+
},
|
|
588
|
+
});
|
|
589
|
+
const add = () => {
|
|
590
|
+
const next = [...items(), extractItemDefaults(itemSchema())];
|
|
591
|
+
props.onChange(next);
|
|
592
|
+
setOpenIndex(next.length - 1);
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
return (
|
|
596
|
+
<fieldset
|
|
597
|
+
aria-labelledby={props.labelledBy}
|
|
598
|
+
class={cn("flex w-full min-w-0 flex-col", LIST_GAP.class)}
|
|
599
|
+
data-slot="schema-form-list"
|
|
600
|
+
>
|
|
601
|
+
<Index each={items()}>
|
|
602
|
+
{(item, index) => (
|
|
603
|
+
<Card
|
|
604
|
+
ref={(el: HTMLElement) => listDrag.setRowEl(index, el)}
|
|
605
|
+
class={cn(
|
|
606
|
+
"w-full min-w-0 overflow-hidden transition-transform duration-(--duration-state)",
|
|
607
|
+
listDrag.draggingIndex() === index && "relative shadow-lg",
|
|
608
|
+
)}
|
|
609
|
+
style={listDrag.rowStyle(index)}
|
|
610
|
+
data-slot="schema-form-list-item"
|
|
611
|
+
>
|
|
612
|
+
<Collapsible
|
|
613
|
+
open={openIndex() === index}
|
|
614
|
+
onOpenChange={(open) => {
|
|
615
|
+
if (listDrag.isToggleSuppressed()) return;
|
|
616
|
+
setOpenIndex(open ? index : -1);
|
|
617
|
+
}}
|
|
618
|
+
>
|
|
619
|
+
<div
|
|
620
|
+
data-slot="schema-form-list-row"
|
|
621
|
+
class={cn(
|
|
622
|
+
"relative flex min-h-11 items-center gap-1.5 py-1 pr-1.5 pl-2 select-none",
|
|
623
|
+
"hover:bg-muted/40 transition-colors duration-(--duration-micro)",
|
|
624
|
+
)}
|
|
625
|
+
onPointerDown={(e: PointerEvent) => {
|
|
626
|
+
const btn = (e.target as HTMLElement).closest("button");
|
|
627
|
+
if (btn && btn.dataset.slot !== "collapsible-trigger") return;
|
|
628
|
+
listDrag.startDrag(index, e, false);
|
|
629
|
+
}}
|
|
630
|
+
>
|
|
631
|
+
{/* Invisible layer over the whole bar: clicking anywhere toggles;
|
|
632
632
|
the action buttons sit above it and win their own clicks. */}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
633
|
+
<CollapsibleTrigger
|
|
634
|
+
class="focus-visible:ring-ring/50 absolute inset-0 rounded-[inherit] py-0 outline-none focus-visible:ring-[3px]"
|
|
635
|
+
aria-label={caption(item(), index)}
|
|
636
|
+
/>
|
|
637
|
+
<Icon
|
|
638
|
+
icon="lucide:chevron-right"
|
|
639
|
+
width={16}
|
|
640
|
+
height={16}
|
|
641
|
+
class={cn(
|
|
642
|
+
"text-muted-foreground pointer-events-none relative shrink-0 transition-transform duration-(--duration-state)",
|
|
643
|
+
openIndex() === index && "rotate-90",
|
|
644
|
+
)}
|
|
645
|
+
aria-hidden="true"
|
|
646
|
+
/>
|
|
647
|
+
<Show when={imageKey() !== undefined && mediaStore !== undefined}>
|
|
648
|
+
<span
|
|
649
|
+
class={cn(
|
|
650
|
+
FIELD_CHROME,
|
|
651
|
+
"text-muted-foreground pointer-events-none relative flex size-8 shrink-0 items-center justify-center overflow-hidden rounded-md",
|
|
652
|
+
)}
|
|
653
|
+
data-slot="schema-form-list-item-thumb"
|
|
654
|
+
>
|
|
655
|
+
<Show
|
|
656
|
+
when={liveThumbUrl(item())}
|
|
657
|
+
fallback={
|
|
658
|
+
<Icon
|
|
659
|
+
icon={
|
|
660
|
+
thumbUrl(item()) === undefined ? "lucide:image" : "lucide:image-off"
|
|
661
|
+
}
|
|
662
|
+
width={16}
|
|
663
|
+
height={16}
|
|
664
|
+
aria-hidden="true"
|
|
665
|
+
/>
|
|
666
|
+
}
|
|
667
|
+
>
|
|
668
|
+
{(url) => (
|
|
669
|
+
<img
|
|
670
|
+
src={url()}
|
|
671
|
+
alt=""
|
|
672
|
+
decoding="async"
|
|
673
|
+
class="absolute inset-0 h-full w-full object-cover"
|
|
674
|
+
onError={() => setBrokenThumbs((broken) => new Set(broken).add(url()))}
|
|
675
|
+
/>
|
|
676
|
+
)}
|
|
677
|
+
</Show>
|
|
678
|
+
</span>
|
|
679
|
+
</Show>
|
|
680
|
+
<span class="pointer-events-none relative min-w-0 flex-1 truncate text-left text-sm">
|
|
681
|
+
{caption(item(), index)}
|
|
682
|
+
</span>
|
|
683
|
+
<Show when={badgeLabel(item())}>
|
|
684
|
+
{(label) => (
|
|
685
|
+
<Badge class="pointer-events-none relative shrink-0">{label()}</Badge>
|
|
686
|
+
)}
|
|
687
|
+
</Show>
|
|
688
|
+
<Button
|
|
689
|
+
variant="ghost"
|
|
690
|
+
size="icon"
|
|
691
|
+
class="relative cursor-grab touch-none active:cursor-grabbing"
|
|
692
|
+
aria-label={`Reorder ${caption(item(), index)}`}
|
|
693
|
+
onPointerDown={(e: PointerEvent) => listDrag.startDrag(index, e, true)}
|
|
694
|
+
onKeyDown={(e: KeyboardEvent) => {
|
|
695
|
+
if (e.key === "ArrowUp") {
|
|
696
|
+
e.preventDefault();
|
|
697
|
+
reorder(index, index - 1);
|
|
698
|
+
} else if (e.key === "ArrowDown") {
|
|
699
|
+
e.preventDefault();
|
|
700
|
+
reorder(index, index + 1);
|
|
701
|
+
}
|
|
702
|
+
}}
|
|
703
|
+
>
|
|
704
|
+
<Icon icon="lucide:grip-vertical" width={16} height={16} aria-hidden="true" />
|
|
705
|
+
</Button>
|
|
706
|
+
<Button
|
|
707
|
+
variant="ghost"
|
|
708
|
+
size="icon"
|
|
709
|
+
class="relative"
|
|
710
|
+
aria-label={`Remove ${caption(item(), index)}`}
|
|
711
|
+
disabled={items().length <= minItems()}
|
|
712
|
+
onClick={() => removeAt(index)}
|
|
713
|
+
>
|
|
714
|
+
<Icon icon="lucide:x" width={16} height={16} aria-hidden="true" />
|
|
715
|
+
</Button>
|
|
716
|
+
</div>
|
|
717
|
+
<CollapsibleContent>
|
|
718
|
+
<div class="border-border border-t p-3">
|
|
719
|
+
<LabeledField
|
|
720
|
+
id={`${props.id}.${index}`}
|
|
721
|
+
name={props.name}
|
|
722
|
+
prop={itemSchema()}
|
|
723
|
+
value={item()}
|
|
724
|
+
onChange={(value) => replaceAt(index, value)}
|
|
725
|
+
searchIcons={props.searchIcons}
|
|
726
|
+
bare
|
|
727
|
+
/>
|
|
728
|
+
</div>
|
|
729
|
+
</CollapsibleContent>
|
|
730
|
+
</Collapsible>
|
|
731
|
+
</Card>
|
|
732
|
+
)}
|
|
733
|
+
</Index>
|
|
734
|
+
<Show when={items().length < minItems()}>
|
|
735
|
+
<p class="text-muted-foreground text-sm">
|
|
736
|
+
Add at least {minItems()} {minItems() === 1 ? "item" : "items"}.
|
|
737
|
+
</p>
|
|
738
|
+
</Show>
|
|
739
|
+
<Button
|
|
740
|
+
variant="outline"
|
|
741
|
+
class="w-full"
|
|
742
|
+
disabled={atMax()}
|
|
743
|
+
onClick={add}
|
|
744
|
+
data-slot="schema-form-list-add"
|
|
745
|
+
>
|
|
746
|
+
<Icon icon="lucide:plus" width={16} height={16} aria-hidden="true" />
|
|
747
|
+
{props.prop.addLabel ?? "Add item"}
|
|
748
|
+
</Button>
|
|
749
|
+
</fieldset>
|
|
750
|
+
);
|
|
751
751
|
}
|
|
752
752
|
|
|
753
753
|
function VariantsControl(props: FieldProps) {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
754
|
+
const branches = () => variantBranches(props.prop);
|
|
755
|
+
const discriminator = () => props.prop.discriminator ?? "";
|
|
756
|
+
const kinds = () => branches().map((b) => branchKind(b, discriminator()));
|
|
757
|
+
const value = () => recordOf(props.value ?? props.prop.default);
|
|
758
|
+
// Memos with default === equality: typing in a field changes value() but not
|
|
759
|
+
// the kind string, so the branch tuples keep their identity and the field
|
|
760
|
+
// subtree is NOT remounted (a remount would drop focus on every keystroke).
|
|
761
|
+
const currentKind = createMemo(() => {
|
|
762
|
+
const kind = value()[discriminator()];
|
|
763
|
+
if (typeof kind === "string" && kinds().includes(kind)) return kind;
|
|
764
|
+
return kinds()[0] ?? "";
|
|
765
|
+
});
|
|
766
|
+
const currentBranch = createMemo(() =>
|
|
767
|
+
branches().find((b) => branchKind(b, discriminator()) === currentKind()),
|
|
768
|
+
);
|
|
769
|
+
const labelFor = (kind: string) => props.prop.labels?.[kind] ?? kind;
|
|
770
|
+
|
|
771
|
+
const switchKind = (kind: string) => {
|
|
772
|
+
if (kind === currentKind()) return;
|
|
773
|
+
const branch = branches().find((b) => branchKind(b, discriminator()) === kind);
|
|
774
|
+
if (!branch) return;
|
|
775
|
+
props.onChange(switchVariantValue(branch, discriminator(), kind, value()));
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
const branchFields = createMemo(() => {
|
|
779
|
+
const branch = currentBranch();
|
|
780
|
+
if (!branch) return [];
|
|
781
|
+
return propertiesOf(branch).filter(([key]) => key !== discriminator());
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
return (
|
|
785
|
+
<fieldset
|
|
786
|
+
aria-labelledby={props.labelledBy}
|
|
787
|
+
class="flex w-full min-w-0 flex-col gap-3"
|
|
788
|
+
data-slot="schema-form-variants"
|
|
789
|
+
>
|
|
790
|
+
<Select
|
|
791
|
+
value={currentKind()}
|
|
792
|
+
onChange={(val) => {
|
|
793
|
+
if (val != null) switchKind(val);
|
|
794
|
+
}}
|
|
795
|
+
options={kinds()}
|
|
796
|
+
itemComponent={(itemProps) => (
|
|
797
|
+
<SelectItem item={itemProps.item}>{labelFor(String(itemProps.item.rawValue))}</SelectItem>
|
|
798
|
+
)}
|
|
799
|
+
>
|
|
800
|
+
<SelectTrigger class="w-full" aria-label={props.prop.title}>
|
|
801
|
+
<SelectValue<string>>{(state) => labelFor(state.selectedOption())}</SelectValue>
|
|
802
|
+
</SelectTrigger>
|
|
803
|
+
<SelectContent />
|
|
804
|
+
</Select>
|
|
805
|
+
<Show when={currentKind()} keyed>
|
|
806
|
+
{(_kind) => (
|
|
807
|
+
<div class={cn(SETTLE_MOTION, "flex flex-col gap-3")}>
|
|
808
|
+
<For each={branchFields()}>
|
|
809
|
+
{([subKey, subProp]) => (
|
|
810
|
+
<LabeledField
|
|
811
|
+
id={`${props.id}.${subKey}`}
|
|
812
|
+
name={subKey}
|
|
813
|
+
prop={subProp}
|
|
814
|
+
value={value()[subKey]}
|
|
815
|
+
onChange={(fieldValue) => props.onChange({ ...value(), [subKey]: fieldValue })}
|
|
816
|
+
searchIcons={props.searchIcons}
|
|
817
|
+
/>
|
|
818
|
+
)}
|
|
819
|
+
</For>
|
|
820
|
+
</div>
|
|
821
|
+
)}
|
|
822
|
+
</Show>
|
|
823
|
+
</fieldset>
|
|
824
|
+
);
|
|
825
825
|
}
|
|
826
826
|
|
|
827
827
|
function ChoicesControl(props: FieldProps) {
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
828
|
+
const current = () => props.value ?? props.prop.default;
|
|
829
|
+
const enumValues = () => (itemsOf(props.prop).enum ?? []).map(String);
|
|
830
|
+
const labelFor = (v: string) => props.prop.labels?.[v] ?? v;
|
|
831
|
+
|
|
832
|
+
return (
|
|
833
|
+
<ToggleGroup
|
|
834
|
+
multiple
|
|
835
|
+
aria-labelledby={props.labelledBy}
|
|
836
|
+
value={(current() as string[] | undefined) ?? []}
|
|
837
|
+
onChange={(vals) => {
|
|
838
|
+
const order = enumValues();
|
|
839
|
+
props.onChange((vals ?? []).slice().sort((a, b) => order.indexOf(a) - order.indexOf(b)));
|
|
840
|
+
}}
|
|
841
|
+
class="flex flex-wrap gap-1"
|
|
842
|
+
>
|
|
843
|
+
<For each={enumValues()}>
|
|
844
|
+
{(v) => <ToggleGroupItem value={v}>{labelFor(v)}</ToggleGroupItem>}
|
|
845
|
+
</For>
|
|
846
|
+
</ToggleGroup>
|
|
847
|
+
);
|
|
848
848
|
}
|
|
849
849
|
|
|
850
850
|
function StringListField(props: {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
851
|
+
value: string[];
|
|
852
|
+
onChange: (value: string[]) => void;
|
|
853
|
+
labelledBy?: string;
|
|
854
854
|
}) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
855
|
+
const [input, setInput] = createSignal("");
|
|
856
|
+
|
|
857
|
+
const addItem = (item: string) => {
|
|
858
|
+
const trimmed = item.trim();
|
|
859
|
+
if (!trimmed || props.value.includes(trimmed)) return;
|
|
860
|
+
props.onChange([...props.value, trimmed]);
|
|
861
|
+
setInput("");
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
return (
|
|
865
|
+
<fieldset
|
|
866
|
+
aria-labelledby={props.labelledBy}
|
|
867
|
+
class="flex min-w-0 flex-col gap-2"
|
|
868
|
+
data-slot="schema-form-string-list"
|
|
869
|
+
>
|
|
870
|
+
<Show when={props.value.length > 0}>
|
|
871
|
+
<div class="flex flex-wrap gap-1.5">
|
|
872
|
+
<For each={props.value}>
|
|
873
|
+
{(item) => (
|
|
874
|
+
<Badge>
|
|
875
|
+
{item}
|
|
876
|
+
<button
|
|
877
|
+
type="button"
|
|
878
|
+
aria-label={`Remove ${item}`}
|
|
879
|
+
onClick={() => props.onChange(props.value.filter((v) => v !== item))}
|
|
880
|
+
class="hover:text-destructive cursor-pointer rounded-sm"
|
|
881
|
+
>
|
|
882
|
+
<Icon icon="lucide:x" width={12} height={12} aria-hidden="true" />
|
|
883
|
+
</button>
|
|
884
|
+
</Badge>
|
|
885
|
+
)}
|
|
886
|
+
</For>
|
|
887
|
+
</div>
|
|
888
|
+
</Show>
|
|
889
|
+
<Input
|
|
890
|
+
type="text"
|
|
891
|
+
placeholder="Type and press Enter to add"
|
|
892
|
+
value={input()}
|
|
893
|
+
onInput={(e) => setInput(e.currentTarget.value)}
|
|
894
|
+
onKeyDown={(e) => {
|
|
895
|
+
if (e.key === "Enter") {
|
|
896
|
+
e.preventDefault();
|
|
897
|
+
addItem(input());
|
|
898
|
+
}
|
|
899
|
+
}}
|
|
900
|
+
/>
|
|
901
|
+
</fieldset>
|
|
902
|
+
);
|
|
903
903
|
}
|