fumadocs-openapi 12.6.1 → 12.6.3

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.
@@ -1,24 +1,34 @@
1
1
  "use client";
2
2
  import { anyFields, useFieldInfo, useResolvedSchema, useSchemaContext, useSchemaUtils } from "./schema.js";
3
- import { Select as Select$2, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
3
+ import { Select as Select$2, SelectContent, SelectItem, SelectValue } from "../select.js";
4
4
  import { cn } from "../../utils/cn.js";
5
5
  import { Fragment, useId, useMemo, useState } from "react";
6
6
  import { dereference, matches, matchesType, mergeAllOf, stringify } from "@fumadocs/json-schema";
7
7
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
8
  import { useTranslations } from "@fuma-translate/react";
9
- import { Check, ChevronDown, ChevronRight, ChevronsUpDown, Copy, Info, Plus, Trash2, Upload, X } from "lucide-react";
9
+ import { Check, ChevronDown, ChevronRight, ChevronsUpDown, Copy, Plus, Trash2, Upload, X } from "lucide-react";
10
10
  import { Select } from "@base-ui/react/select";
11
11
  import { buttonVariants } from "fumadocs-ui/components/ui/button";
12
12
  import { useCopyButton } from "fumadocs-ui/utils/use-copy-button";
13
+ import { flushSync } from "react-dom";
13
14
  import { useArray, useDataEngine, useFieldValue, useObject } from "@fumari/stf";
14
15
  import { isPlainObject, stringifyFieldKey } from "@fumari/stf/lib/utils";
15
16
  import { Autocomplete } from "@base-ui/react/autocomplete";
16
17
  import { Popover } from "@base-ui/react/popover";
17
18
  // ../shared-api/dist/components/playground/fields.js
18
- /** the type of a field, at the end of its cell like a unit */
19
- const typeClassName = "flex shrink-0 items-center pe-1 font-mono text-xs text-fd-muted-foreground";
20
- /** holds the actions of field, reserved in tables so their types align, an end padding when stacked */
21
- const slotClassName = "flex w-7 shrink-0 items-center justify-center @max-sm:pe-2 @max-sm:empty:w-2";
19
+ /** a segment of the type pill, the type or an action on the field */
20
+ const segmentClassName = "flex items-center transition-colors not-first:border-s hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:bg-fd-accent focus-visible:outline-none data-popup-open:bg-fd-accent data-popup-open:text-fd-accent-foreground";
21
+ /** the type of a field and the actions on it, like changing its type or unsetting it */
22
+ function TypePill({ type, action, quiet = false }) {
23
+ return /* @__PURE__ */ jsxs("span", {
24
+ className: cn("flex h-6 shrink-0 items-stretch overflow-hidden rounded-md border bg-fd-secondary font-mono text-xs", quiet ? "text-fd-muted-foreground/70" : "text-fd-muted-foreground"),
25
+ children: [typeof type === "string" ? /* @__PURE__ */ jsx("span", {
26
+ className: "max-w-40 truncate px-1.5 leading-[1.375rem]",
27
+ title: type,
28
+ children: type
29
+ }) : type, action]
30
+ });
31
+ }
22
32
  const rowButtonClassName = "flex h-10 w-full items-center gap-2 px-4 text-[0.8125rem] text-fd-muted-foreground transition-colors hover:bg-fd-accent/40 hover:text-fd-accent-foreground focus-visible:bg-fd-secondary focus-visible:text-fd-accent-foreground focus-visible:outline-none";
23
33
  function getType(field) {
24
34
  if (typeof field.type === "string") return field.type;
@@ -39,7 +49,7 @@ function getOptions(field) {
39
49
  value: item.const,
40
50
  label: item.title ?? valueLabel(item.const)
41
51
  }));
42
- return (field.const !== void 0 ? [field.const] : field.enum)?.map((value) => ({
52
+ return (field.const !== void 0 ? [field.const] : field.enum ?? (field.type === "boolean" ? [true, false] : void 0))?.map((value) => ({
43
53
  value,
44
54
  label: valueLabel(value)
45
55
  }));
@@ -103,19 +113,7 @@ function SchemaSwitch({ fieldName, schema, depth = 0, children }) {
103
113
  const { info, updateInfo } = useFieldInfo(fieldName, field, depth);
104
114
  const union = info.unionField ? field[info.unionField] : void 0;
105
115
  const types = Array.isArray(field.type) ? field.type : void 0;
106
- const member = useMemo(() => {
107
- if (union && union.length > 0) return union[info.oneOf];
108
- if (types) return {
109
- ...field,
110
- type: info.selectedType ?? types[0]
111
- };
112
- }, [
113
- field,
114
- union,
115
- types,
116
- info.oneOf,
117
- info.selectedType
118
- ]);
116
+ const member = useMemo(() => getMember(field, info), [field, info]);
119
117
  if (member === void 0 || isConstUnion(union) || getSuggestions(field)) return children(field, null);
120
118
  let selector = null;
121
119
  if (union && union.length > 1) selector = /* @__PURE__ */ jsx(TypeSelect, {
@@ -141,6 +139,19 @@ function SchemaSwitch({ fieldName, schema, depth = 0, children }) {
141
139
  children: (resolved, inner) => children(resolved, joinNodes(selector, inner))
142
140
  });
143
141
  }
142
+ /** the member of a union or a multi-type field chosen by `info` */
143
+ function getMember(field, info) {
144
+ const union = info.unionField ? field[info.unionField] : void 0;
145
+ if (union && union.length > 0) return union[info.oneOf];
146
+ if (!Array.isArray(field.type)) return;
147
+ const type = info.selectedType ?? field.type[0];
148
+ return {
149
+ ...field,
150
+ type,
151
+ default: matchesType(field.default, type) ? field.default : void 0,
152
+ examples: field.examples?.filter((example) => matchesType(example, type))
153
+ };
154
+ }
144
155
  function TypeSelect({ value, options, onChange }) {
145
156
  const t = useTranslations({ note: "playground" });
146
157
  return /* @__PURE__ */ jsxs(Select$2, {
@@ -149,7 +160,7 @@ function TypeSelect({ value, options, onChange }) {
149
160
  onValueChange: (v) => v !== null && onChange(v),
150
161
  children: [/* @__PURE__ */ jsxs(Select.Trigger, {
151
162
  "aria-label": t("Type"),
152
- className: "flex h-5 max-w-40 min-w-0 cursor-pointer items-center gap-0.5 rounded-md border bg-fd-secondary ps-1.5 pe-1 font-mono text-xs text-fd-muted-foreground transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring/50 data-popup-open:bg-fd-accent data-popup-open:text-fd-accent-foreground",
163
+ className: cn(segmentClassName, "max-w-40 min-w-0 cursor-pointer gap-0.5 ps-1.5 pe-1"),
153
164
  children: [/* @__PURE__ */ jsx(SelectValue, { className: "truncate" }), /* @__PURE__ */ jsx(Select.Icon, {
154
165
  className: "shrink-0",
155
166
  children: /* @__PURE__ */ jsx(ChevronsUpDown, { className: "size-3" })
@@ -161,28 +172,55 @@ function TypeSelect({ value, options, onChange }) {
161
172
  }, option.value)) })]
162
173
  });
163
174
  }
164
- /** a field in the editor: its name on the left, its input filling the cell on the right */
165
- function Row({ name, required = false, info, htmlFor, readOnly = false, children }) {
175
+ /** a field in the editor: its name, its input filling the cell, then its type and actions */
176
+ function Row({ name, required = false, info, htmlFor, readOnly = false, quiet = false, aside, children }) {
177
+ const nameClassName = cn("truncate font-mono text-[0.8125rem]", quiet ? "text-fd-muted-foreground" : "text-fd-foreground");
166
178
  return /* @__PURE__ */ jsxs("div", {
167
- className: "group/row grid border-b last:border-b-0 @max-sm:pb-3 @sm:min-h-10 @sm:grid-cols-[minmax(9rem,1fr)_minmax(0,2fr)]",
179
+ className: cn("group/row grid grid-cols-[minmax(0,1fr)_auto] border-b transition-colors last:border-b-0 @max-sm:pb-3 @sm:min-h-10 @sm:grid-cols-[minmax(9rem,1fr)_minmax(0,2fr)]", !readOnly && "hover:bg-fd-accent/40 has-focus-visible:bg-fd-secondary"),
168
180
  children: [/* @__PURE__ */ jsxs("div", {
169
181
  className: "flex min-w-0 items-center gap-1 py-2 ps-4 pe-3 @max-sm:pb-1.5",
170
- children: [
182
+ children: [info ? /* @__PURE__ */ jsxs(Popover.Root, { children: [
171
183
  /* @__PURE__ */ jsx("label", {
172
184
  htmlFor,
173
- title: name,
174
- className: "truncate font-mono text-[0.8125rem] text-fd-foreground",
185
+ className: "sr-only",
175
186
  children: name
176
187
  }),
177
- required && /* @__PURE__ */ jsx("span", {
178
- className: "-ms-0.5 text-red-400",
179
- children: "*"
188
+ /* @__PURE__ */ jsx(Popover.Trigger, {
189
+ openOnHover: true,
190
+ delay: 200,
191
+ closeDelay: 100,
192
+ title: name,
193
+ className: cn(nameClassName, "cursor-help rounded-sm decoration-dotted underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring data-popup-open:underline"),
194
+ children: name
180
195
  }),
181
- info
182
- ]
183
- }), /* @__PURE__ */ jsx("div", {
184
- className: cn("flex min-h-9 min-w-0 items-stretch text-[0.8125rem] transition-colors @max-sm:mx-4 @max-sm:overflow-hidden @max-sm:rounded-lg @max-sm:border @max-sm:bg-fd-secondary/50 @sm:min-h-10 @sm:border-s", !readOnly && "hover:bg-fd-accent/40 has-focus-visible:border-fd-ring has-focus-visible:bg-fd-secondary"),
185
- children
196
+ /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, {
197
+ side: "bottom",
198
+ align: "start",
199
+ sideOffset: 6,
200
+ className: "z-50",
201
+ children: /* @__PURE__ */ jsx(Popover.Popup, {
202
+ className: "w-72 max-w-[calc(100vw-2rem)] origin-(--transform-origin) rounded-xl border bg-fd-popover p-3 text-fd-popover-foreground shadow-lg outline-none transition-[opacity,scale] duration-150 ease-out data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0 motion-reduce:transition-none",
203
+ children: info
204
+ })
205
+ }) })
206
+ ] }) : /* @__PURE__ */ jsx("label", {
207
+ htmlFor,
208
+ title: name,
209
+ className: nameClassName,
210
+ children: name
211
+ }), required && /* @__PURE__ */ jsx("span", {
212
+ className: "-ms-0.5 text-red-400",
213
+ children: "*"
214
+ })]
215
+ }), /* @__PURE__ */ jsxs("div", {
216
+ className: "contents @sm:flex @sm:min-w-0",
217
+ children: [/* @__PURE__ */ jsx("div", {
218
+ className: "col-span-full row-start-2 flex min-h-9 min-w-0 flex-1 items-stretch text-[0.8125rem] @max-sm:mx-4 @max-sm:overflow-hidden @max-sm:rounded-lg @max-sm:border @max-sm:bg-fd-secondary/50 @sm:min-h-10 @sm:border-s",
219
+ children
220
+ }), aside && /* @__PURE__ */ jsx("div", {
221
+ className: "col-start-2 row-start-1 flex shrink-0 items-center pe-4 @max-sm:pt-2 @max-sm:pb-1.5",
222
+ children: aside
223
+ })]
186
224
  })]
187
225
  });
188
226
  }
@@ -195,10 +233,9 @@ function formatRange(value, min, exclusiveMin, max, exclusiveMax) {
195
233
  else if (exclusiveMax !== void 0) out.push(`< ${exclusiveMax}`);
196
234
  if (out.length > 1) return out.join(" ");
197
235
  }
198
- /** the description and constraints of a field, opened from an info button on hover or click */
199
- function FieldInfo({ name, field, description }) {
236
+ /** the card of a field: its description and constraints, `null` without them */
237
+ function useFieldCard(name, field, description) {
200
238
  const t = useTranslations({ note: "schema UI" });
201
- const tPlayground = useTranslations({ note: "playground" });
202
239
  const constraints = [];
203
240
  if (field.default !== void 0) constraints.push([t("Default"), JSON.stringify(field.default)]);
204
241
  let range = formatRange("value", field.minimum, field.exclusiveMinimum, field.maximum, field.exclusiveMaximum);
@@ -211,112 +248,77 @@ function FieldInfo({ name, field, description }) {
211
248
  if (field.pattern) constraints.push([t("Match"), field.pattern]);
212
249
  if (field.examples && field.examples.length > 0) constraints.push([t("Example"), JSON.stringify(field.examples[0])]);
213
250
  if (!description && constraints.length === 0) return null;
214
- return /* @__PURE__ */ jsxs(Popover.Root, { children: [/* @__PURE__ */ jsx(Popover.Trigger, {
215
- openOnHover: true,
216
- delay: 200,
217
- closeDelay: 100,
218
- "aria-label": tPlayground("Field Info"),
219
- className: "inline-flex size-5 shrink-0 ms-auto items-center justify-center rounded text-fd-muted-foreground/70 transition-colors hover:text-fd-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring data-popup-open:text-fd-foreground",
220
- children: /* @__PURE__ */ jsx(Info, { className: "size-3.5" })
221
- }), /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, {
222
- side: "bottom",
223
- align: "start",
224
- sideOffset: 6,
225
- className: "z-50",
226
- children: /* @__PURE__ */ jsxs(Popover.Popup, {
227
- className: "w-72 max-w-[calc(100vw-2rem)] origin-(--transform-origin) rounded-xl border bg-fd-popover p-3 text-fd-popover-foreground shadow-lg outline-none transition-[opacity,scale] duration-150 ease-out data-ending-style:scale-95 data-ending-style:opacity-0 data-starting-style:scale-95 data-starting-style:opacity-0 motion-reduce:transition-none",
228
- children: [
229
- /* @__PURE__ */ jsxs("p", {
230
- className: "flex items-baseline gap-3",
231
- children: [/* @__PURE__ */ jsx("span", {
232
- className: "truncate font-mono text-[0.8125rem] font-medium",
233
- children: name
234
- }), /* @__PURE__ */ jsx("span", {
235
- className: "ms-auto shrink-0 font-mono text-xs text-fd-muted-foreground",
236
- children: typeLabel(field)
237
- })]
238
- }),
239
- description && /* @__PURE__ */ jsx("div", {
240
- className: "mt-1.5 text-xs leading-relaxed text-fd-muted-foreground prose-no-margin [&_a]:underline [&_code]:font-mono",
241
- children: /* @__PURE__ */ jsx(FieldMarkdown, { md: description })
242
- }),
243
- constraints.length > 0 && /* @__PURE__ */ jsx("dl", {
244
- className: "mt-2.5 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 border-t pt-2.5 text-xs",
245
- children: constraints.map(([label, value]) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
246
- className: "text-fd-muted-foreground",
247
- children: label
248
- }), /* @__PURE__ */ jsx("dd", {
249
- className: "truncate font-mono",
250
- title: value,
251
- children: value
252
- })] }, label))
253
- })
254
- ]
251
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
252
+ /* @__PURE__ */ jsxs("p", {
253
+ className: "flex items-baseline gap-3",
254
+ children: [/* @__PURE__ */ jsx("span", {
255
+ className: "truncate font-mono text-[0.8125rem] font-medium",
256
+ children: name
257
+ }), /* @__PURE__ */ jsx("span", {
258
+ className: "ms-auto shrink-0 font-mono text-xs text-fd-muted-foreground",
259
+ children: typeLabel(field)
260
+ })]
261
+ }),
262
+ description && /* @__PURE__ */ jsx("div", {
263
+ className: "mt-1.5 text-xs leading-relaxed text-fd-muted-foreground prose-no-margin [&_a]:underline [&_code]:font-mono",
264
+ children: /* @__PURE__ */ jsx(FieldMarkdown, { md: description })
265
+ }),
266
+ constraints.length > 0 && /* @__PURE__ */ jsx("dl", {
267
+ className: "mt-2.5 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 border-t pt-2.5 text-xs",
268
+ children: constraints.map(([label, value]) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
269
+ className: "text-fd-muted-foreground",
270
+ children: label
271
+ }), /* @__PURE__ */ jsx("dd", {
272
+ className: "truncate font-mono",
273
+ title: value,
274
+ children: value
275
+ })] }, label))
255
276
  })
256
- }) })] });
277
+ ] });
257
278
  }
258
- function SlotButton({ label, onClick, children }) {
279
+ function ActionButton({ label, onClick, tabIndex, children }) {
259
280
  return /* @__PURE__ */ jsx("button", {
260
281
  type: "button",
261
282
  "aria-label": label,
262
283
  title: label,
284
+ tabIndex,
263
285
  onClick,
264
- className: "inline-flex size-5 items-center justify-center rounded text-fd-muted-foreground transition-colors hover:bg-fd-accent hover:text-fd-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring [&_svg]:size-3",
286
+ className: cn(segmentClassName, "w-6 justify-center [&_svg]:size-3"),
265
287
  children
266
288
  });
267
289
  }
268
- function UnsetButton({ fieldName }) {
269
- const engine = useDataEngine();
270
- const t = useTranslations({ note: "playground" });
271
- const [isDefined] = useFieldValue(fieldName, { compute: (value) => value !== void 0 });
272
- if (!isDefined) return null;
273
- return /* @__PURE__ */ jsx(SlotButton, {
274
- label: t("Unset"),
275
- onClick: () => engine.delete(fieldName),
276
- children: /* @__PURE__ */ jsx(X, {})
277
- });
278
- }
279
- function ValueRow({ fieldName, field, type, end, required, marked = required, name, description, slot }) {
290
+ function ValueRow({ fieldName, field, type, start, end, required, marked = required, name, description, action }) {
280
291
  const id = stringifyFieldKey(fieldName);
281
292
  return /* @__PURE__ */ jsxs(Row, {
282
293
  name,
283
294
  required: marked,
284
295
  htmlFor: id,
285
- info: /* @__PURE__ */ jsx(FieldInfo, {
286
- name,
287
- field,
288
- description
296
+ info: useFieldCard(name, field, description),
297
+ aside: (type || action) && /* @__PURE__ */ jsx(TypePill, {
298
+ type,
299
+ action
289
300
  }),
290
301
  children: [
302
+ start && /* @__PURE__ */ jsx("label", {
303
+ htmlFor: id,
304
+ className: "flex shrink-0 items-center ps-3 text-fd-muted-foreground",
305
+ children: start
306
+ }),
291
307
  /* @__PURE__ */ jsx(FieldValue, {
292
308
  id,
293
309
  fieldName,
294
- field,
295
- required
296
- }),
297
- type && /* @__PURE__ */ jsx("span", {
298
- className: typeClassName,
299
- children: type
310
+ field
300
311
  }),
301
- end,
302
- /* @__PURE__ */ jsx("span", {
303
- className: slotClassName,
304
- children: slot
305
- })
312
+ end
306
313
  ]
307
314
  });
308
315
  }
309
- /** the type in the cell of a primitive field, its selector when it has multiple */
310
- function cellType(field, selector) {
311
- if (selector) return selector;
312
- if (field.type !== "null" && !getOptions(field) && !getSuggestions(field)) return typeLabel(field);
313
- }
314
316
  /** the input of a primitive field */
315
- function FieldValue({ id, fieldName, field, required = false }) {
317
+ function FieldValue({ id, fieldName, field }) {
316
318
  const [value, setValue] = useFieldValue(fieldName);
317
319
  const t = useTranslations({ note: "playground" });
318
320
  if (field.type === "null") return /* @__PURE__ */ jsx("span", {
319
- className: "flex flex-1 items-center px-3 font-mono text-fd-muted-foreground",
321
+ className: "flex flex-1 items-center px-3 font-mono text-xs",
320
322
  children: "null"
321
323
  });
322
324
  if (field.type === "string" && field.format === "binary") return /* @__PURE__ */ jsxs("label", {
@@ -353,44 +355,30 @@ function FieldValue({ id, fieldName, field, required = false }) {
353
355
  const options = getOptions(field);
354
356
  if (options && options.length > 0) {
355
357
  const idx = options.findIndex((option) => option.value === value);
356
- const items = options.map((option, i) => ({
357
- value: String(i),
358
- label: option.label
359
- }));
360
- if (!required) items.push({
361
- value: "-1",
362
- label: /* @__PURE__ */ jsx("span", {
363
- className: "text-fd-muted-foreground",
364
- children: t("Unset")
365
- })
366
- });
367
358
  return /* @__PURE__ */ jsx(CellSelect, {
368
359
  id,
369
- items,
370
- value: idx !== -1 ? String(idx) : required ? null : "-1",
371
- onValueChange: (v) => setValue(v === "-1" ? void 0 : options[Number(v)].value),
360
+ items: options.map((option, i) => ({
361
+ value: String(i),
362
+ label: /* @__PURE__ */ jsx("span", {
363
+ className: "font-mono text-xs",
364
+ children: option.label
365
+ })
366
+ })),
367
+ value: idx !== -1 ? String(idx) : null,
368
+ onValueChange: (v) => setValue(options[Number(v)].value),
372
369
  placeholder: t("Select")
373
370
  });
374
371
  }
375
- if (field.type === "boolean") return /* @__PURE__ */ jsx("div", {
376
- className: "flex flex-1 items-center gap-0.5 ps-1 pe-2",
377
- children: [true, false].map((option) => /* @__PURE__ */ jsx("button", {
378
- type: "button",
379
- "aria-pressed": value === option,
380
- onClick: () => setValue(option),
381
- className: "h-6 rounded px-2 font-mono text-xs text-fd-muted-foreground transition-colors hover:text-fd-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring aria-pressed:bg-fd-background aria-pressed:text-fd-foreground aria-pressed:shadow-sm aria-pressed:ring-1 aria-pressed:ring-fd-border dark:aria-pressed:bg-fd-accent",
382
- children: String(option)
383
- }, String(option)))
384
- });
385
372
  const isNumber = field.type === "integer" || field.type === "number";
373
+ const isSecret = field.format === "password";
386
374
  const hint = field.default ?? field.examples?.[0];
387
375
  return /* @__PURE__ */ jsx("input", {
388
376
  id,
389
- type: isNumber ? "number" : field.format === "password" ? "password" : "text",
377
+ type: isNumber ? "number" : isSecret ? "password" : "text",
390
378
  step: isNumber ? "any" : void 0,
391
379
  autoComplete: "off",
392
380
  spellCheck: false,
393
- placeholder: value === "" ? "\"\"" : hint !== void 0 && typeof hint !== "object" ? String(hint) : t("Enter value"),
381
+ placeholder: value === "" && !isSecret ? "\"\"" : hint !== void 0 && typeof hint !== "object" ? String(hint) : t("Enter value"),
394
382
  value: value == null ? "" : String(value),
395
383
  onChange: (e) => {
396
384
  if (!isNumber) setValue(e.target.value);
@@ -400,7 +388,7 @@ function FieldValue({ id, fieldName, field, required = false }) {
400
388
  });
401
389
  }
402
390
  /** an object or array, opened in its own panel */
403
- function NavRow({ fieldName, field, type, required, marked = required, name, description, onNavigate }) {
391
+ function NavRow({ fieldName, field, type, required, marked = required, name, description, action, onNavigate }) {
404
392
  const t = useTranslations({ note: "playground" });
405
393
  const id = stringifyFieldKey(fieldName);
406
394
  const [preview] = useFieldValue(fieldName, { compute(value) {
@@ -417,57 +405,44 @@ function NavRow({ fieldName, field, type, required, marked = required, name, des
417
405
  name,
418
406
  required: marked,
419
407
  htmlFor: id,
420
- info: /* @__PURE__ */ jsx(FieldInfo, {
421
- name,
422
- field,
423
- description
408
+ info: useFieldCard(name, field, description),
409
+ aside: /* @__PURE__ */ jsx(TypePill, {
410
+ type,
411
+ action
424
412
  }),
425
- children: /* @__PURE__ */ jsx(NavButton, {
413
+ children: /* @__PURE__ */ jsx("button", {
426
414
  id,
427
- type,
415
+ type: "button",
428
416
  onClick: onNavigate,
429
- children: /* @__PURE__ */ jsx("span", {
430
- className: cn("font-mono text-xs", preview === null ? "text-fd-muted-foreground/70" : "text-fd-muted-foreground"),
431
- children: preview ?? t("Not set")
417
+ className: "flex min-w-0 flex-1 items-center px-3 text-start outline-none",
418
+ children: preview !== null ? /* @__PURE__ */ jsx("span", {
419
+ className: "truncate font-mono text-xs",
420
+ children: preview
421
+ }) : /* @__PURE__ */ jsx("span", {
422
+ className: "text-fd-muted-foreground/70",
423
+ children: t("Not set")
432
424
  })
433
425
  })
434
426
  });
435
427
  }
436
- /** fills a cell, opens something else on click */
437
- function NavButton({ id, type, onClick, children }) {
438
- return /* @__PURE__ */ jsxs("button", {
439
- id,
440
- type: "button",
441
- onClick,
442
- className: "group/nav flex min-w-0 flex-1 items-center ps-3 text-start outline-none",
443
- children: [
444
- /* @__PURE__ */ jsx("span", {
445
- className: "min-w-0 flex-1 truncate pe-2",
446
- children
447
- }),
448
- type && /* @__PURE__ */ jsx("span", {
449
- className: typeClassName,
450
- children: type
451
- }),
452
- /* @__PURE__ */ jsx("span", {
453
- className: slotClassName,
454
- children: /* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 text-fd-muted-foreground transition-transform duration-200 group-hover/nav:translate-x-0.5 motion-reduce:transition-none" })
455
- })
456
- ]
457
- });
458
- }
459
428
  /** a select filling a cell */
460
429
  function CellSelect({ id, items, value, onValueChange, placeholder }) {
461
430
  return /* @__PURE__ */ jsxs(Select$2, {
462
431
  items,
463
432
  value,
464
433
  onValueChange: (v) => v !== null && onValueChange(v),
465
- children: [/* @__PURE__ */ jsx(SelectTrigger, {
434
+ children: [/* @__PURE__ */ jsx(Select.Trigger, {
466
435
  id,
467
- className: "h-auto min-w-0 flex-1 rounded-none border-0 bg-transparent py-0 ps-3 pe-1 text-[0.8125rem] hover:bg-transparent focus:ring-0 focus-visible:outline-none",
468
- children: /* @__PURE__ */ jsx(SelectValue, {
469
- className: "truncate",
470
- placeholder
436
+ className: "flex min-w-0 flex-1 cursor-pointer items-center px-3 text-start text-fd-foreground outline-none data-placeholder:text-fd-muted-foreground",
437
+ children: /* @__PURE__ */ jsxs("span", {
438
+ className: "flex min-w-0 flex-1 items-center justify-between gap-2 font-mono text-xs",
439
+ children: [/* @__PURE__ */ jsx(SelectValue, {
440
+ className: "truncate",
441
+ placeholder
442
+ }), /* @__PURE__ */ jsx(Select.Icon, {
443
+ className: "shrink-0 text-fd-muted-foreground",
444
+ children: /* @__PURE__ */ jsx(ChevronDown, { className: "size-3.5" })
445
+ })]
471
446
  })
472
447
  }), /* @__PURE__ */ jsx(SelectContent, { children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
473
448
  value: item.value,
@@ -485,7 +460,6 @@ function matchesSuggestion(item, query) {
485
460
  return item.value.toLowerCase().includes(q) || item.label.toLowerCase().includes(q);
486
461
  }
487
462
  function CellAutocomplete({ id, items, value, onValueChange, placeholder }) {
488
- const t = useTranslations({ note: "playground" });
489
463
  const filled = items.some((item) => item.value === value);
490
464
  return /* @__PURE__ */ jsxs(Autocomplete.Root, {
491
465
  items,
@@ -494,18 +468,14 @@ function CellAutocomplete({ id, items, value, onValueChange, placeholder }) {
494
468
  itemToStringValue: (item) => item.value,
495
469
  filter: filled ? null : matchesSuggestion,
496
470
  openOnInputClick: true,
497
- children: [/* @__PURE__ */ jsxs(Autocomplete.InputGroup, {
471
+ children: [/* @__PURE__ */ jsx(Autocomplete.InputGroup, {
498
472
  className: "flex min-w-0 flex-1 items-center",
499
- children: [/* @__PURE__ */ jsx(Autocomplete.Input, {
473
+ children: /* @__PURE__ */ jsx(Autocomplete.Input, {
500
474
  id,
501
475
  spellCheck: false,
502
476
  placeholder,
503
477
  className: "min-w-0 flex-1 self-stretch bg-transparent px-3 text-fd-foreground outline-none placeholder:text-fd-muted-foreground/70"
504
- }), /* @__PURE__ */ jsx(Autocomplete.Trigger, {
505
- "aria-label": t("Suggestions"),
506
- className: "flex shrink-0 items-center pe-1 text-fd-muted-foreground",
507
- children: /* @__PURE__ */ jsx(ChevronDown, { className: "size-3.5" })
508
- })]
478
+ })
509
479
  }), /* @__PURE__ */ jsx(Autocomplete.Portal, { children: /* @__PURE__ */ jsx(Autocomplete.Positioner, {
510
480
  align: "start",
511
481
  sideOffset: 4,
@@ -523,41 +493,35 @@ function CellAutocomplete({ id, items, value, onValueChange, placeholder }) {
523
493
  }
524
494
  function SelectRow({ name, ...props }) {
525
495
  const id = useId();
526
- return /* @__PURE__ */ jsxs(Row, {
496
+ return /* @__PURE__ */ jsx(Row, {
527
497
  name,
528
498
  htmlFor: id,
529
- children: [/* @__PURE__ */ jsx(CellSelect, {
499
+ children: /* @__PURE__ */ jsx(CellSelect, {
530
500
  id,
531
501
  ...props
532
- }), /* @__PURE__ */ jsx("span", { className: slotClassName })]
502
+ })
533
503
  });
534
504
  }
535
505
  /** a row of read-only text */
536
506
  function TextRow({ name, description, copyable = false, children }) {
537
- return /* @__PURE__ */ jsxs(Row, {
507
+ return /* @__PURE__ */ jsx(Row, {
538
508
  name,
539
509
  readOnly: true,
540
- info: /* @__PURE__ */ jsx(FieldInfo, {
541
- name,
542
- field: { type: "string" },
543
- description
544
- }),
545
- children: [/* @__PURE__ */ jsx("span", {
510
+ info: useFieldCard(name, { type: "string" }, description),
511
+ aside: copyable && /* @__PURE__ */ jsx(TypePill, { action: /* @__PURE__ */ jsx(CopyButton, { text: children }) }),
512
+ children: /* @__PURE__ */ jsx("span", {
546
513
  className: "flex min-w-0 flex-1 items-center px-3 text-fd-muted-foreground",
547
514
  children: /* @__PURE__ */ jsx("span", {
548
515
  className: "truncate",
549
516
  children
550
517
  })
551
- }), /* @__PURE__ */ jsx("span", {
552
- className: slotClassName,
553
- children: copyable && /* @__PURE__ */ jsx(CopyButton, { text: children })
554
- })]
518
+ })
555
519
  });
556
520
  }
557
521
  function CopyButton({ text }) {
558
522
  const t = useTranslations({ note: "playground" });
559
523
  const [isChecked, onCopy] = useCopyButton(() => navigator.clipboard.writeText(text));
560
- return /* @__PURE__ */ jsx(SlotButton, {
524
+ return /* @__PURE__ */ jsx(ActionButton, {
561
525
  label: isChecked ? t("Copied", { note: "aria-label" }) : t("Copy", { note: "aria-label" }),
562
526
  onClick: onCopy,
563
527
  children: isChecked ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(Copy, {})
@@ -569,20 +533,19 @@ function LinkRow({ name, onClick, children }) {
569
533
  type: "button",
570
534
  onClick,
571
535
  className: cn(rowButtonClassName, "group/nav border-b last:border-b-0"),
572
- children: [
573
- /* @__PURE__ */ jsx("span", {
574
- className: "min-w-0 flex-1 truncate text-start",
536
+ children: [/* @__PURE__ */ jsxs("span", {
537
+ className: "flex min-w-0 flex-1 items-center gap-1.5 text-start",
538
+ children: [/* @__PURE__ */ jsx("span", {
539
+ className: "truncate",
575
540
  children
576
- }),
577
- /* @__PURE__ */ jsx("span", {
578
- className: typeClassName,
579
- children: name
580
- }),
581
- /* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 transition-transform duration-200 group-hover/nav:translate-x-0.5 motion-reduce:transition-none" })
582
- ]
541
+ }), /* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 shrink-0 text-fd-muted-foreground transition-transform duration-200 group-hover/nav:translate-x-0.5 motion-reduce:transition-none" })]
542
+ }), /* @__PURE__ */ jsx("span", {
543
+ className: "shrink-0 font-mono text-xs text-fd-muted-foreground",
544
+ children: name
545
+ })]
583
546
  });
584
547
  }
585
- /** a row toggled on click, its check box takes the slot */
548
+ /** a row toggled on click, its check box in the last column */
586
549
  function CheckRow({ name, checked, onCheckedChange, children }) {
587
550
  const id = useId();
588
551
  return /* @__PURE__ */ jsx(Row, {
@@ -594,12 +557,12 @@ function CheckRow({ name, checked, onCheckedChange, children }) {
594
557
  role: "checkbox",
595
558
  "aria-checked": checked,
596
559
  onClick: () => onCheckedChange(!checked),
597
- className: "flex min-w-0 flex-1 items-center ps-3 text-start outline-none",
560
+ className: "flex min-w-0 flex-1 items-center gap-2 px-3 text-start outline-none",
598
561
  children: [/* @__PURE__ */ jsx("span", {
599
- className: "min-w-0 flex-1 truncate pe-2 text-fd-muted-foreground",
562
+ className: "min-w-0 flex-1 truncate text-fd-muted-foreground",
600
563
  children
601
564
  }), /* @__PURE__ */ jsx("span", {
602
- className: slotClassName,
565
+ className: "flex shrink-0",
603
566
  children: /* @__PURE__ */ jsx("span", {
604
567
  className: cn("flex size-4 items-center justify-center rounded-[5px] border transition-colors", checked ? "border-fd-primary bg-fd-primary text-fd-primary-foreground" : "border-fd-muted-foreground/50"),
605
568
  children: checked && /* @__PURE__ */ jsx(Check, { className: "size-3" })
@@ -608,6 +571,58 @@ function CheckRow({ name, checked, onCheckedChange, children }) {
608
571
  })
609
572
  });
610
573
  }
574
+ /** an optional field out of the request, clicking it adds the field and moves to its input */
575
+ function QuietRow({ name, fieldName, field, description, type, onNavigate }) {
576
+ const engine = useDataEngine();
577
+ const { generateDefault } = useSchemaUtils();
578
+ const { info } = useFieldInfo(fieldName, field);
579
+ const t = useTranslations({ note: "playground" });
580
+ const id = stringifyFieldKey(fieldName);
581
+ const label = t("Add {name}", { variables: { name } });
582
+ const example = field.const ?? field.default ?? field.examples?.[0];
583
+ const hint = example !== null && typeof example === "object" ? void 0 : example;
584
+ const member = getMember(field, info) ?? field;
585
+ function add() {
586
+ engine.update(fieldName, generateDefault(member));
587
+ }
588
+ /** add it, then move to its editor */
589
+ function edit() {
590
+ flushSync(add);
591
+ const kind = getType(resolveField(member, engine.get(fieldName)) ?? field);
592
+ if (kind === "object" || kind === "array") return onNavigate();
593
+ const editor = document.getElementById(id);
594
+ editor?.focus();
595
+ if (editor instanceof HTMLInputElement) editor.select();
596
+ else editor?.click();
597
+ }
598
+ return /* @__PURE__ */ jsx(Row, {
599
+ name,
600
+ htmlFor: id,
601
+ quiet: true,
602
+ info: useFieldCard(name, field, description),
603
+ aside: /* @__PURE__ */ jsx(TypePill, {
604
+ quiet: true,
605
+ type: type ?? typeLabel(field, true),
606
+ action: /* @__PURE__ */ jsx(ActionButton, {
607
+ label,
608
+ tabIndex: -1,
609
+ onClick: add,
610
+ children: /* @__PURE__ */ jsx(Plus, {})
611
+ })
612
+ }),
613
+ children: /* @__PURE__ */ jsx("button", {
614
+ id,
615
+ type: "button",
616
+ "aria-label": label,
617
+ onClick: edit,
618
+ className: "flex min-w-0 flex-1 items-center px-3 text-start text-fd-muted-foreground/70 outline-none",
619
+ children: hint !== void 0 && /* @__PURE__ */ jsx("span", {
620
+ className: cn("truncate", (typeof hint !== "string" || getOptions(field)) && "font-mono text-xs"),
621
+ children: valueLabel(hint)
622
+ })
623
+ })
624
+ });
625
+ }
611
626
  function getRemoval(required, removable) {
612
627
  if (removable) return "remove";
613
628
  if (!required) return "unset";
@@ -615,8 +630,21 @@ function getRemoval(required, removable) {
615
630
  function FieldRow({ entry: { name, fieldName, schema }, required = false, description, type: label, onNavigate, onRemove }) {
616
631
  const { readOnly, writeOnly } = useSchemaContext();
617
632
  const resolved = useResolvedSchema(schema);
633
+ const engine = useDataEngine();
618
634
  const t = useTranslations({ note: "playground" });
635
+ const [isUnset] = useFieldValue(fieldName, { compute: (value) => value === void 0 });
619
636
  if (schema === false) return null;
637
+ if (!required && isUnset) {
638
+ if (resolved.readOnly && !readOnly || resolved.writeOnly && !writeOnly) return null;
639
+ return /* @__PURE__ */ jsx(QuietRow, {
640
+ name,
641
+ fieldName,
642
+ field: resolved,
643
+ description: description ?? resolved.description,
644
+ type: label,
645
+ onNavigate
646
+ });
647
+ }
620
648
  return /* @__PURE__ */ jsx(SchemaSwitch, {
621
649
  fieldName,
622
650
  schema,
@@ -629,11 +657,15 @@ function FieldRow({ entry: { name, fieldName, schema }, required = false, descri
629
657
  description: description ?? resolved.description ?? field.description,
630
658
  fieldName,
631
659
  field,
632
- slot: onRemove ? /* @__PURE__ */ jsx(SlotButton, {
660
+ action: onRemove ? /* @__PURE__ */ jsx(ActionButton, {
633
661
  label: t("Remove Item", { note: "aria-label" }),
634
662
  onClick: onRemove,
635
663
  children: /* @__PURE__ */ jsx(Trash2, {})
636
- }) : !required && /* @__PURE__ */ jsx(UnsetButton, { fieldName })
664
+ }) : !required && /* @__PURE__ */ jsx(ActionButton, {
665
+ label: t("Unset"),
666
+ onClick: () => engine.delete(fieldName),
667
+ children: /* @__PURE__ */ jsx(X, {})
668
+ })
637
669
  };
638
670
  const type = getType(field);
639
671
  if (type === "object" || type === "array") return /* @__PURE__ */ jsx(NavRow, {
@@ -643,7 +675,7 @@ function FieldRow({ entry: { name, fieldName, schema }, required = false, descri
643
675
  });
644
676
  return /* @__PURE__ */ jsx(ValueRow, {
645
677
  ...props,
646
- type: selector ?? label ?? cellType(field, null)
678
+ type: selector ?? label ?? typeLabel(field)
647
679
  });
648
680
  }
649
681
  });
@@ -678,9 +710,18 @@ function ObjectRows({ fieldName, field, onNavigate }) {
678
710
  hiddenKeys.length > 0 && /* @__PURE__ */ jsxs(Select$2, {
679
711
  value: null,
680
712
  onValueChange: (v) => v !== null && onAppend(v),
681
- children: [/* @__PURE__ */ jsxs(SelectTrigger, {
682
- className: cn(rowButtonClassName, "rounded-none border-0 border-b bg-transparent p-0 ps-4 last:border-b-0 focus:ring-0"),
683
- children: [/* @__PURE__ */ jsx(Plus, { className: "size-3.5" }), /* @__PURE__ */ jsx(SelectValue, { placeholder: t("Show Property") })]
713
+ children: [/* @__PURE__ */ jsxs(Select.Trigger, {
714
+ className: cn(rowButtonClassName, "cursor-pointer border-b last:border-b-0"),
715
+ children: [/* @__PURE__ */ jsx(Plus, { className: "size-3.5 shrink-0" }), /* @__PURE__ */ jsxs("span", {
716
+ className: "flex min-w-0 items-center gap-1.5",
717
+ children: [/* @__PURE__ */ jsx(SelectValue, {
718
+ className: "truncate",
719
+ placeholder: t("Show Property")
720
+ }), /* @__PURE__ */ jsx(Select.Icon, {
721
+ className: "shrink-0",
722
+ children: /* @__PURE__ */ jsx(ChevronDown, { className: "size-3.5" })
723
+ })]
724
+ })]
684
725
  }), /* @__PURE__ */ jsx(SelectContent, { children: hiddenKeys.map((key) => /* @__PURE__ */ jsx(SelectItem, {
685
726
  value: key,
686
727
  className: "font-mono text-[0.8125rem]",
@@ -698,7 +739,7 @@ function NewPropertyRow({ onAppend }) {
698
739
  setName("");
699
740
  }
700
741
  return /* @__PURE__ */ jsxs("div", {
701
- className: "flex min-h-10 items-center gap-2 border-b ps-4 pe-1.5 last:border-b-0",
742
+ className: "flex min-h-10 items-center gap-2 border-b ps-4 pe-4 last:border-b-0",
702
743
  children: [
703
744
  /* @__PURE__ */ jsx(Plus, { className: "size-3.5 shrink-0 text-fd-muted-foreground" }),
704
745
  /* @__PURE__ */ jsx("input", {
@@ -770,7 +811,7 @@ function FieldRows({ entry, onNavigate, showDescription = false }) {
770
811
  });
771
812
  else rows = /* @__PURE__ */ jsx(ValueRow, {
772
813
  name: entry.name,
773
- type: cellType(field, null),
814
+ type: typeLabel(field),
774
815
  required: true,
775
816
  fieldName: entry.fieldName,
776
817
  field
@@ -781,10 +822,10 @@ function FieldRows({ entry, onNavigate, showDescription = false }) {
781
822
  children: /* @__PURE__ */ jsx(FieldMarkdown, { md: field.description })
782
823
  }),
783
824
  selector && /* @__PURE__ */ jsxs("div", {
784
- className: "flex min-h-10 items-center gap-2 border-b ps-4 pe-4 text-xs text-fd-muted-foreground @sm:pe-8",
825
+ className: "flex min-h-10 items-center gap-2 border-b ps-4 pe-4 text-xs text-fd-muted-foreground",
785
826
  children: [t("Schema"), /* @__PURE__ */ jsx("span", {
786
827
  className: "ms-auto",
787
- children: selector
828
+ children: /* @__PURE__ */ jsx(TypePill, { type: selector })
788
829
  })]
789
830
  }),
790
831
  rows