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