@pipelex/mthds-form 0.7.0 → 0.9.0

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 (45) hide show
  1. package/README.md +6 -3
  2. package/dist/chunk-AZZAAGNX.js +194 -0
  3. package/dist/chunk-AZZAAGNX.js.map +1 -0
  4. package/dist/{chunk-IIU3YK4O.js → chunk-DARLDVJM.js} +3 -3
  5. package/dist/{chunk-IIU3YK4O.js.map → chunk-DARLDVJM.js.map} +1 -1
  6. package/dist/{chunk-R7B7ID25.js → chunk-IUWLOSAM.js} +4 -4
  7. package/dist/{chunk-R7B7ID25.js.map → chunk-IUWLOSAM.js.map} +1 -1
  8. package/dist/chunk-KG4IYFWI.js +2721 -0
  9. package/dist/chunk-KG4IYFWI.js.map +1 -0
  10. package/dist/{chunk-J4L32LD6.js → chunk-KIEOLP2L.js} +3 -3
  11. package/dist/{chunk-J4L32LD6.js.map → chunk-KIEOLP2L.js.map} +1 -1
  12. package/dist/{chunk-4BSBBG2T.js → chunk-S4CB423P.js} +3 -3
  13. package/dist/{chunk-4BSBBG2T.js.map → chunk-S4CB423P.js.map} +1 -1
  14. package/dist/{chunk-XYQ7NXQZ.js → chunk-WYH56SOZ.js} +2 -2
  15. package/dist/chunk-WYH56SOZ.js.map +1 -0
  16. package/dist/{chunk-YEVVR6FE.js → chunk-Y2ND6W4W.js} +3 -3
  17. package/dist/{chunk-YEVVR6FE.js.map → chunk-Y2ND6W4W.js.map} +1 -1
  18. package/dist/{chunk-T4NSAGOS.js → chunk-YABRYTQ4.js} +4 -4
  19. package/dist/{chunk-T4NSAGOS.js.map → chunk-YABRYTQ4.js.map} +1 -1
  20. package/dist/core/contracts.d.ts +4 -4
  21. package/dist/core/contracts.js +1 -1
  22. package/dist/core/derive.js +2 -2
  23. package/dist/core/gate.js +3 -3
  24. package/dist/core/gating-fields.js +2 -2
  25. package/dist/core/index.d.ts +1 -1
  26. package/dist/core/index.js +8 -8
  27. package/dist/core/native-content.d.ts +56 -9
  28. package/dist/core/native-content.js +1 -1
  29. package/dist/core/output-form.js +2 -2
  30. package/dist/core/stuff-files.js +2 -2
  31. package/dist/core/values.js +3 -3
  32. package/dist/field-renderer-BSU2hMf6.d.ts +34 -0
  33. package/dist/generative/index.d.ts +2013 -0
  34. package/dist/generative/index.js +3171 -0
  35. package/dist/generative/index.js.map +1 -0
  36. package/dist/react/index.d.ts +42 -36
  37. package/dist/react/index.js +8 -2614
  38. package/dist/react/index.js.map +1 -1
  39. package/dist/styles.css +2 -2
  40. package/dist/theme.css +53 -44
  41. package/dist/ui-designer.mthds +304 -0
  42. package/package.json +24 -10
  43. package/dist/chunk-45C2MKK6.js +0 -94
  44. package/dist/chunk-45C2MKK6.js.map +0 -1
  45. package/dist/chunk-XYQ7NXQZ.js.map +0 -1
@@ -0,0 +1,2721 @@
1
+ import { collectStuffFiles } from './chunk-S4CB423P.js';
2
+ import { viewableUrl, isNativeDateNode, isNativeHtmlNode, readHtmlContent, isNativeCompositeNode, readCompositeContent, readDataUrl, readDateContent, formatDateContent, readImageContent, readDocumentContent } from './chunk-AZZAAGNX.js';
3
+ import { conceptCategory } from './chunk-25I6JDIK.js';
4
+ import { isAcceptedFile, acceptMapForKind, DOCUMENT_FORMATS, IMAGE_FORMATS } from './chunk-2JWRG53S.js';
5
+ import { isFilled } from './chunk-PM55AHRO.js';
6
+ import { toStoredDateValue, toDateInputValue } from './chunk-GKV77RAS.js';
7
+ import { ownProp } from './chunk-V3OV2XQT.js';
8
+ import { clsx } from 'clsx';
9
+ import { twMerge } from 'tailwind-merge';
10
+ import { ChevronDown, ChevronUp, Check, List, Braces, ListChecks, ToggleLeft, Hash, Image, FileText, CalendarDays, Type, Loader2, ImageOff, Upload, Link2, EyeOff, Eye, X, Minus, Plus, Trash2, Copy, Download, ChevronRight } from 'lucide-react';
11
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
12
+ import * as React2 from 'react';
13
+ import { createContext, use, useId, useMemo, useContext, useState, useRef, useCallback, useEffect, Fragment as Fragment$1, useLayoutEffect } from 'react';
14
+ import * as SwitchPrimitives from '@radix-ui/react-switch';
15
+ import { useDropzone } from 'react-dropzone';
16
+ import * as SelectPrimitive from '@radix-ui/react-select';
17
+ import * as ToggleGroupPrimitive from '@radix-ui/react-toggle-group';
18
+ import * as TogglePrimitive from '@radix-ui/react-toggle';
19
+ import { cva } from 'class-variance-authority';
20
+ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
21
+ import { marked } from 'marked';
22
+
23
+ function cn(...inputs) {
24
+ return twMerge(clsx(inputs));
25
+ }
26
+ var CATEGORY_ICON = {
27
+ text: Type,
28
+ date: CalendarDays,
29
+ document: FileText,
30
+ image: Image,
31
+ number: Hash,
32
+ boolean: ToggleLeft,
33
+ choice: ListChecks,
34
+ structured: Braces,
35
+ list: List
36
+ };
37
+ function ConceptPill({ conceptRef, category, className }) {
38
+ const Icon2 = CATEGORY_ICON[category];
39
+ const label = conceptRef ?? category;
40
+ return /* @__PURE__ */ jsxs(
41
+ "span",
42
+ {
43
+ className: cn(
44
+ "inline-flex items-center gap-1 font-mono text-[10.5px] leading-none text-muted-foreground",
45
+ className
46
+ ),
47
+ children: [
48
+ /* @__PURE__ */ jsx(Icon2, { className: "h-3 w-3 shrink-0 opacity-70", strokeWidth: 1.75, "aria-hidden": true }),
49
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: label })
50
+ ]
51
+ }
52
+ );
53
+ }
54
+ var FieldPresentationContext = createContext("studio");
55
+ function FieldPresentationProvider({
56
+ presentation,
57
+ children
58
+ }) {
59
+ return /* @__PURE__ */ jsx(FieldPresentationContext, { value: presentation, children });
60
+ }
61
+ function useFieldPresentation() {
62
+ return use(FieldPresentationContext);
63
+ }
64
+ function humanizeFieldName(name) {
65
+ const words = name.replace(/[_-]+/g, " ").trim();
66
+ if (words === "") return name;
67
+ return words.charAt(0).toUpperCase() + words.slice(1);
68
+ }
69
+ function fieldLabel(title, name, presentation) {
70
+ if (title !== void 0) return title;
71
+ return presentation === "app" ? humanizeFieldName(name) : name;
72
+ }
73
+ var Switch = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
74
+ SwitchPrimitives.Root,
75
+ {
76
+ className: cn(
77
+ "peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
78
+ className
79
+ ),
80
+ ...props,
81
+ ref,
82
+ children: /* @__PURE__ */ jsx(
83
+ SwitchPrimitives.Thumb,
84
+ {
85
+ className: cn(
86
+ "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"
87
+ )
88
+ }
89
+ )
90
+ }
91
+ ));
92
+ Switch.displayName = SwitchPrimitives.Root.displayName;
93
+ var FieldDomIdContext = createContext(null);
94
+ function FieldDomIdProvider({
95
+ prefix,
96
+ children
97
+ }) {
98
+ const generated = useId();
99
+ return /* @__PURE__ */ jsx(FieldDomIdContext, { value: prefix ?? generated, children });
100
+ }
101
+ function useFieldDomId(path) {
102
+ const scoped = use(FieldDomIdContext);
103
+ const local = useId();
104
+ const prefix = scoped ?? local;
105
+ return prefix === "" ? path : `${prefix}-${path}`;
106
+ }
107
+ function BooleanField({ field, value, onChange, id, disabled }) {
108
+ const presentation = useFieldPresentation();
109
+ const isApp = presentation === "app";
110
+ const domId = useFieldDomId(id);
111
+ return /* @__PURE__ */ jsxs(
112
+ "div",
113
+ {
114
+ className: cn(
115
+ "flex items-center justify-between gap-4 rounded-md border border-border bg-input px-3.5 py-3",
116
+ disabled && "opacity-50"
117
+ ),
118
+ children: [
119
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 space-y-1", children: [
120
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-1", children: [
121
+ /* @__PURE__ */ jsx(
122
+ "label",
123
+ {
124
+ htmlFor: domId,
125
+ className: cn(
126
+ "text-[13px] font-medium leading-none text-foreground",
127
+ isApp ? "text-[13.5px]" : "font-mono"
128
+ ),
129
+ children: fieldLabel(field.title, field.name, presentation)
130
+ }
131
+ ),
132
+ !isApp && /* @__PURE__ */ jsx(ConceptPill, { conceptRef: field.conceptRef, category: "boolean" })
133
+ ] }),
134
+ field.description && /* @__PURE__ */ jsx("p", { className: "text-[12px] leading-relaxed text-muted-foreground", children: field.description })
135
+ ] }),
136
+ /* @__PURE__ */ jsx(
137
+ Switch,
138
+ {
139
+ id: domId,
140
+ checked: value ?? false,
141
+ onCheckedChange: onChange,
142
+ disabled,
143
+ className: "shrink-0"
144
+ }
145
+ )
146
+ ]
147
+ }
148
+ );
149
+ }
150
+ function formatBytes(bytes) {
151
+ if (bytes < 1024) return bytes === 1 ? "1 byte" : `${bytes} bytes`;
152
+ if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
153
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
154
+ }
155
+ var DEFAULT_FIELD_STRINGS = {
156
+ optionalBadge: "optional",
157
+ selectPlaceholder: "Select\u2026",
158
+ typeValuePlaceholder: "Type a value\u2026",
159
+ writeHerePlaceholder: "Write here\u2026",
160
+ jsonHint: "Enter this value as raw JSON.",
161
+ decrease: "Decrease",
162
+ increase: "Increase",
163
+ noItemsYet: "No items yet",
164
+ addItem: "Add item",
165
+ removeItemAria: (index) => `Remove item ${index}`,
166
+ itemsCount: (count) => count === 1 ? "1 item" : `${count} items`,
167
+ itemsCountOf: (count, total) => `${count} of ${total} ${total === 1 ? "item" : "items"}`,
168
+ fieldsCount: (count) => count === 1 ? "1 field" : `${count} fields`,
169
+ uploading: "Uploading\u2026",
170
+ dropToUpload: "Drop to upload",
171
+ dropOrBrowse: "Drop a file or click to browse",
172
+ pasteUrlInstead: "paste a URL instead",
173
+ urlPlaceholder: "https://\u2026 or pipelex-storage://\u2026",
174
+ uploadedFile: "Uploaded file",
175
+ encodedFileSummary: (format, bytes) => `${format} \xB7 ${formatBytes(bytes)}`,
176
+ preview: "Preview",
177
+ removeFileAria: "Remove file",
178
+ previewUnavailablePdf: "Preview unavailable - open to view.",
179
+ // U+002D HYPHEN-MINUS, deliberately: not an en dash, not an em dash.
180
+ resultAbsent: "-",
181
+ resultAbsentDescription: "Not provided",
182
+ resultUndescribed: "No output descriptor for this pipe \u2014 showing the raw value.",
183
+ toggleRowDetails: (index) => `Show or hide the details of row ${index}`,
184
+ rowDetailsColumn: "Details",
185
+ copyUrl: "Copy the URL",
186
+ copyText: "Copy the text",
187
+ download: "Download",
188
+ downloading: "Downloading\u2026",
189
+ viewRendered: "Result",
190
+ viewJson: "JSON",
191
+ copyJson: "Copy the JSON",
192
+ resultViewGroup: "Result view",
193
+ yes: "Yes",
194
+ no: "No",
195
+ unsupportedFileType: (accept) => `That file type is not supported. Accepted formats: ${accept}.`,
196
+ hideOptionalFields: "Hide optional fields",
197
+ hideOptionalInputs: "Hide optional inputs",
198
+ optionalFieldsCount: (count) => count === 1 ? "1 optional field" : `${count} optional fields`,
199
+ optionalInputsCount: (count) => count === 1 ? "1 optional input" : `${count} optional inputs`
200
+ };
201
+ var FieldStringsContext = createContext(DEFAULT_FIELD_STRINGS);
202
+ function FieldStringsProvider({
203
+ strings,
204
+ children
205
+ }) {
206
+ const merged = useMemo(() => ({ ...DEFAULT_FIELD_STRINGS, ...strings }), [strings]);
207
+ return /* @__PURE__ */ jsx(FieldStringsContext.Provider, { value: merged, children });
208
+ }
209
+ function useFieldStrings() {
210
+ return useContext(FieldStringsContext);
211
+ }
212
+ function FieldShell({
213
+ name,
214
+ title,
215
+ conceptRef,
216
+ category,
217
+ description,
218
+ required,
219
+ error,
220
+ htmlFor,
221
+ children,
222
+ className
223
+ }) {
224
+ const s = useFieldStrings();
225
+ const presentation = useFieldPresentation();
226
+ const isApp = presentation === "app";
227
+ const Label3 = htmlFor ? "label" : "div";
228
+ const labelText = fieldLabel(title, name, presentation);
229
+ const showLabel = labelText.trim() !== "";
230
+ return /* @__PURE__ */ jsxs("div", { className: cn("space-y-2", className), children: [
231
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-1", children: [
232
+ showLabel && /* @__PURE__ */ jsx(
233
+ Label3,
234
+ {
235
+ ...htmlFor ? { htmlFor } : {},
236
+ className: cn(
237
+ "text-[13px] font-medium leading-none text-foreground",
238
+ isApp ? "text-[13.5px]" : "font-mono"
239
+ ),
240
+ children: labelText
241
+ }
242
+ ),
243
+ !isApp && /* @__PURE__ */ jsx(ConceptPill, { conceptRef, category }),
244
+ !required && /* @__PURE__ */ jsx("span", { className: "ml-auto font-mono text-[10px] uppercase tracking-wider text-muted-foreground", children: s.optionalBadge })
245
+ ] }),
246
+ description && /* @__PURE__ */ jsx("p", { className: "text-[12px] leading-relaxed text-muted-foreground", children: description }),
247
+ isApp && error ? /* @__PURE__ */ jsx("div", { className: "rounded-lg ring-1 ring-destructive/70 ring-offset-4 ring-offset-background", children }) : children,
248
+ error && /* @__PURE__ */ jsx("p", { className: "flex items-center gap-1 text-[11px] text-destructive", role: "alert", children: error })
249
+ ] });
250
+ }
251
+
252
+ // src/react/field-styles.ts
253
+ var fieldControlClass = cn(
254
+ "w-full rounded-md border border-border bg-input text-sm text-foreground",
255
+ "placeholder:text-muted-foreground/70 transition-colors",
256
+ "focus-visible:outline-hidden focus-visible:border-primary focus-visible:ring-1 focus-visible:ring-primary/40",
257
+ "disabled:cursor-not-allowed disabled:opacity-50",
258
+ "aria-invalid:border-destructive aria-invalid:ring-destructive/30"
259
+ );
260
+ function DateField({ field, value, onChange, id, error, disabled }) {
261
+ const domId = useFieldDomId(id);
262
+ return /* @__PURE__ */ jsx(
263
+ FieldShell,
264
+ {
265
+ name: field.name,
266
+ title: field.title,
267
+ conceptRef: field.conceptRef,
268
+ category: "date",
269
+ description: field.description,
270
+ required: field.required,
271
+ error,
272
+ htmlFor: domId,
273
+ children: /* @__PURE__ */ jsx(
274
+ "input",
275
+ {
276
+ id: domId,
277
+ type: "date",
278
+ value: toDateInputValue(value),
279
+ disabled,
280
+ "aria-invalid": !!error,
281
+ onChange: (e) => onChange(toStoredDateValue(e.target.value, field.datetime)),
282
+ className: cn(fieldControlClass, "h-11 px-3 font-mono tabular-nums")
283
+ }
284
+ )
285
+ }
286
+ );
287
+ }
288
+
289
+ // src/react/encoded-file.ts
290
+ function encodedFileSummary(url, strings) {
291
+ const view = readDataUrl(url);
292
+ if (!view) return void 0;
293
+ const format = [...DOCUMENT_FORMATS, ...IMAGE_FORMATS].find((known) => known.mimeType === view.mediaType)?.label ?? view.mediaType;
294
+ return strings.encodedFileSummary(format, view.bytes);
295
+ }
296
+ var IMAGE_EXT_RE = /\.(jpg|jpeg|png|gif|webp|bmp|svg|avif)(\?|$)/i;
297
+ var PDF_EXT_RE = /\.pdf(\?|$)/i;
298
+ var DATA_URL_MIME_RE = /^data:([^;,]+)/i;
299
+ function dataUrlMime(url) {
300
+ return DATA_URL_MIME_RE.exec(url)?.[1]?.toLowerCase();
301
+ }
302
+ function DocumentField(props) {
303
+ return /* @__PURE__ */ jsx(FileField, { ...props, category: "document" });
304
+ }
305
+ function ImageField(props) {
306
+ return /* @__PURE__ */ jsx(FileField, { ...props, category: "image" });
307
+ }
308
+ function FileField({
309
+ field,
310
+ value,
311
+ onDropFile,
312
+ onChange,
313
+ id,
314
+ uploading,
315
+ resolveUrl,
316
+ error,
317
+ disabled,
318
+ category
319
+ }) {
320
+ const s = useFieldStrings();
321
+ const domId = useFieldDomId(id);
322
+ const [showUrl, setShowUrl] = useState(false);
323
+ const [previewOpen, setPreviewOpen] = useState(false);
324
+ const [localPreview, setLocalPreview] = useState(null);
325
+ const [resolved, setResolved] = useState(null);
326
+ const localUrlRef = useRef(null);
327
+ const setLocal = useCallback((next) => {
328
+ if (localUrlRef.current) URL.revokeObjectURL(localUrlRef.current);
329
+ localUrlRef.current = next?.objectUrl ?? null;
330
+ setLocalPreview(next);
331
+ }, []);
332
+ useEffect(() => () => setLocal(null), [setLocal]);
333
+ const [rejected, setRejected] = useState(null);
334
+ const handleFile = useCallback(
335
+ (file) => {
336
+ if (!isAcceptedFile(field.kind, file)) {
337
+ setRejected(file.name);
338
+ return;
339
+ }
340
+ setRejected(null);
341
+ setLocal({ objectUrl: URL.createObjectURL(file), type: file.type });
342
+ onDropFile(file);
343
+ },
344
+ [field.kind, setLocal, onDropFile]
345
+ );
346
+ const busy = disabled || uploading;
347
+ const { getRootProps, getInputProps, isDragActive } = useDropzone({
348
+ maxFiles: 1,
349
+ multiple: false,
350
+ disabled: busy,
351
+ // Filters the OS picker so a wrong file is hard to choose in the first
352
+ // place. It is NOT the enforcement: a drag-and-drop bypasses the picker
353
+ // entirely, and a browser reporting an empty `File.type` slips through
354
+ // react-dropzone's own matcher. `handleFile` is where the answer is
355
+ // decided; this is the affordance in front of it.
356
+ accept: acceptMapForKind(field.kind),
357
+ // The tab stop belongs on the INPUT, not on this div - see the root element
358
+ // below. Without this, react-dropzone puts `tabIndex: 0` and its own key
359
+ // handlers on a `role="presentation"` div, and the element a keyboard or
360
+ // voice-control user lands on is a generic with no role and no name.
361
+ noKeyboard: true,
362
+ onDrop: (files) => {
363
+ const file = files[0];
364
+ if (file) handleFile(file);
365
+ },
366
+ // react-dropzone rejects a file its own matcher refuses without ever calling
367
+ // `onDrop`, so without this a wrong drop is silently swallowed - the control
368
+ // simply does nothing, which reads as a broken dropzone rather than a
369
+ // refused file.
370
+ onDropRejected: (rejections) => {
371
+ const name = rejections[0]?.file.name;
372
+ if (name) setRejected(name);
373
+ }
374
+ });
375
+ const clear = useCallback(() => {
376
+ setLocal(null);
377
+ setResolved(null);
378
+ setPreviewOpen(false);
379
+ setRejected(null);
380
+ onChange(void 0);
381
+ }, [setLocal, onChange]);
382
+ const localIsCurrent = !!localPreview && (localPreview.boundUrl === void 0 || localPreview.boundUrl === value?.url);
383
+ useEffect(() => {
384
+ if (!localPreview) return;
385
+ if (localPreview.boundUrl === void 0) {
386
+ if (uploading || !value?.url) return;
387
+ setLocalPreview({ ...localPreview, boundUrl: value.url });
388
+ return;
389
+ }
390
+ if (value?.url !== localPreview.boundUrl) setLocal(null);
391
+ }, [localPreview, value?.url, uploading, setLocal]);
392
+ const hasFile = !!value?.url;
393
+ const localType = localIsCurrent ? localPreview?.type : void 0;
394
+ const filename = value?.filename ?? "";
395
+ const url = value?.url ?? "";
396
+ const urlMime = dataUrlMime(url);
397
+ const isImage = category === "image" || localType?.startsWith("image/") === true || urlMime?.startsWith("image/") === true || IMAGE_EXT_RE.test(filename) || IMAGE_EXT_RE.test(url);
398
+ const isPdf = localType === "application/pdf" || urlMime === "application/pdf" || PDF_EXT_RE.test(filename) || PDF_EXT_RE.test(url);
399
+ const canPreview = isImage || isPdf;
400
+ const directSrc = viewableUrl(value?.url);
401
+ const storageUri = value?.url && !directSrc && urlMime === void 0 ? value.url : null;
402
+ useEffect(() => {
403
+ if (!previewOpen || !storageUri || localIsCurrent || !resolveUrl) return;
404
+ let cancelled = false;
405
+ void resolveUrl(storageUri).then((src) => {
406
+ if (!cancelled) setResolved(src ? { uri: storageUri, src } : null);
407
+ }).catch(() => {
408
+ if (!cancelled) setResolved(null);
409
+ });
410
+ return () => {
411
+ cancelled = true;
412
+ };
413
+ }, [previewOpen, storageUri, localIsCurrent, resolveUrl]);
414
+ const resolvedSrc = resolved && resolved.uri === storageUri ? viewableUrl(resolved.src) : void 0;
415
+ const previewSrc = (localIsCurrent ? localPreview?.objectUrl : void 0) ?? directSrc ?? resolvedSrc;
416
+ const previewPending = !previewSrc && !!storageUri && resolved?.uri !== storageUri;
417
+ return /* @__PURE__ */ jsxs(
418
+ FieldShell,
419
+ {
420
+ name: field.name,
421
+ title: field.title,
422
+ conceptRef: field.conceptRef,
423
+ category,
424
+ description: field.description,
425
+ required: field.required,
426
+ error,
427
+ htmlFor: domId,
428
+ children: [
429
+ hasFile && !uploading ? /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
430
+ /* @__PURE__ */ jsx(
431
+ FileChip,
432
+ {
433
+ value,
434
+ disabled,
435
+ onClear: clear,
436
+ canPreview,
437
+ previewOpen,
438
+ onTogglePreview: () => setPreviewOpen((v) => !v)
439
+ }
440
+ ),
441
+ previewOpen && (previewSrc && isImage ? /* @__PURE__ */ jsx(ImagePreview, { src: previewSrc, filename: value?.filename }) : previewSrc && isPdf ? /* @__PURE__ */ jsx(PdfPreview, { src: previewSrc }) : previewPending ? /* @__PURE__ */ jsx("div", { className: "flex h-24 items-center justify-center rounded-md border border-border bg-muted", children: /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : (
442
+ // Nothing to show and nothing on its way: a reference the gate
443
+ // refuses, or a stored one with no resolver behind it. A spinner
444
+ // here said "loading" about something that was never going to
445
+ // load, which is the one thing a refusal must not look like.
446
+ /* @__PURE__ */ jsx("div", { className: "flex h-24 items-center justify-center rounded-md border border-border bg-muted", children: /* @__PURE__ */ jsx(ImageOff, { className: "h-5 w-5 text-muted-foreground" }) })
447
+ ))
448
+ ] }) : (
449
+ // `role="presentation"` and no tab stop: this div is the drop TARGET and
450
+ // the visual affordance, and the control inside it is a real
451
+ // `<input type="file">`, which already has the right role and now has a
452
+ // name. Giving the div a `role="button"` of its own would put a second
453
+ // named control in the accessibility tree for one value. The focus ring
454
+ // is `focus-within` because the element that takes focus is clip-hidden.
455
+ /* @__PURE__ */ jsxs(
456
+ "div",
457
+ {
458
+ ...getRootProps(),
459
+ className: cn(
460
+ "flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed px-4 py-6 text-center",
461
+ "cursor-pointer select-none transition-colors",
462
+ "focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background",
463
+ isDragActive ? "border-primary/60 bg-primary/5" : "border-border bg-input hover:border-border hover:bg-muted",
464
+ busy && "cursor-not-allowed opacity-60"
465
+ ),
466
+ children: [
467
+ /* @__PURE__ */ jsx(
468
+ "input",
469
+ {
470
+ ...getInputProps({ tabIndex: 0 }),
471
+ id: domId,
472
+ disabled: busy,
473
+ "aria-invalid": !!error
474
+ }
475
+ ),
476
+ uploading ? /* @__PURE__ */ jsxs(Fragment, { children: [
477
+ /* @__PURE__ */ jsx(Loader2, { className: "h-5 w-5 animate-spin text-muted-foreground" }),
478
+ /* @__PURE__ */ jsx("p", { className: "text-[12px] text-muted-foreground", children: s.uploading })
479
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
480
+ /* @__PURE__ */ jsx(Upload, { className: "h-5 w-5 text-muted-foreground", strokeWidth: 1.75 }),
481
+ /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
482
+ /* @__PURE__ */ jsx("p", { className: "text-[13px] text-foreground", children: isDragActive ? s.dropToUpload : s.dropOrBrowse }),
483
+ field.accept && /* @__PURE__ */ jsx("p", { className: "font-mono text-[10.5px] text-muted-foreground", children: field.accept })
484
+ ] })
485
+ ] })
486
+ ]
487
+ }
488
+ )
489
+ ),
490
+ rejected && !busy && /* @__PURE__ */ jsxs("p", { role: "alert", className: "text-[12px] text-destructive", children: [
491
+ /* @__PURE__ */ jsx("span", { className: "font-mono", children: rejected }),
492
+ " \u2014",
493
+ " ",
494
+ s.unsupportedFileType(field.accept ?? "")
495
+ ] }),
496
+ !showUrl ? /* @__PURE__ */ jsxs(
497
+ "button",
498
+ {
499
+ type: "button",
500
+ disabled: busy,
501
+ onClick: () => setShowUrl(true),
502
+ className: "flex w-fit items-center gap-1 font-mono text-[11px] text-muted-foreground transition-colors hover:text-foreground disabled:opacity-50",
503
+ children: [
504
+ /* @__PURE__ */ jsx(Link2, { className: "h-3 w-3" }),
505
+ s.pasteUrlInstead
506
+ ]
507
+ }
508
+ ) : /* @__PURE__ */ jsx(
509
+ "input",
510
+ {
511
+ type: "text",
512
+ autoFocus: true,
513
+ value: value?.url ?? "",
514
+ disabled: busy,
515
+ placeholder: s.urlPlaceholder,
516
+ onChange: (e) => {
517
+ setLocal(null);
518
+ onChange(e.target.value ? { url: e.target.value } : void 0);
519
+ },
520
+ className: cn(fieldControlClass, "h-9 px-3 font-mono text-[12px]")
521
+ }
522
+ )
523
+ ]
524
+ }
525
+ );
526
+ }
527
+ function ImagePreview({ src, filename }) {
528
+ const s = useFieldStrings();
529
+ const [broken, setBroken] = useState(false);
530
+ if (broken) {
531
+ return /* @__PURE__ */ jsx("div", { className: "flex h-28 items-center justify-center rounded-md border border-border bg-muted", children: /* @__PURE__ */ jsx(ImageOff, { className: "h-5 w-5 text-muted-foreground" }) });
532
+ }
533
+ return /* @__PURE__ */ jsx("div", { className: "flex max-h-[640px] justify-center overflow-auto rounded-md border border-border bg-muted", children: /* @__PURE__ */ jsx(
534
+ "img",
535
+ {
536
+ src,
537
+ alt: filename ?? s.preview,
538
+ referrerPolicy: "no-referrer",
539
+ className: "h-auto w-full max-w-full object-contain",
540
+ onError: () => setBroken(true)
541
+ }
542
+ ) });
543
+ }
544
+ function PdfPreview({ src }) {
545
+ const s = useFieldStrings();
546
+ return /* @__PURE__ */ jsx(
547
+ "object",
548
+ {
549
+ data: `${src}#view=FitH`,
550
+ type: "application/pdf",
551
+ className: "h-[78vh] min-h-[520px] w-full rounded-md border border-border bg-muted",
552
+ children: /* @__PURE__ */ jsxs("div", { className: "flex h-28 flex-col items-center justify-center gap-1.5 text-center", children: [
553
+ /* @__PURE__ */ jsx(FileText, { className: "h-5 w-5 text-muted-foreground" }),
554
+ /* @__PURE__ */ jsx("p", { className: "text-[12px] text-muted-foreground", children: s.previewUnavailablePdf })
555
+ ] })
556
+ }
557
+ );
558
+ }
559
+ function FileChip({
560
+ value,
561
+ disabled,
562
+ onClear,
563
+ canPreview,
564
+ previewOpen,
565
+ onTogglePreview
566
+ }) {
567
+ const s = useFieldStrings();
568
+ const url = value?.url;
569
+ const subtitle = useMemo(
570
+ () => url === void 0 ? void 0 : encodedFileSummary(url, s) ?? url,
571
+ [url, s]
572
+ );
573
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 rounded-md border border-border bg-input px-3 py-2.5", children: [
574
+ /* @__PURE__ */ jsx("span", { className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-muted", children: /* @__PURE__ */ jsx(FileText, { className: "h-4 w-4 text-muted-foreground" }) }),
575
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
576
+ /* @__PURE__ */ jsx("p", { className: "truncate text-[13px] font-medium text-foreground", children: value?.filename ?? s.uploadedFile }),
577
+ /* @__PURE__ */ jsx("p", { className: "truncate font-mono text-[10.5px] text-muted-foreground", children: subtitle })
578
+ ] }),
579
+ canPreview && /* @__PURE__ */ jsxs(
580
+ "button",
581
+ {
582
+ type: "button",
583
+ onClick: onTogglePreview,
584
+ className: "inline-flex h-7 shrink-0 items-center gap-1 rounded-md border border-border px-2 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
585
+ children: [
586
+ previewOpen ? /* @__PURE__ */ jsx(EyeOff, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ jsx(Eye, { className: "h-3.5 w-3.5" }),
587
+ s.preview
588
+ ]
589
+ }
590
+ ),
591
+ /* @__PURE__ */ jsx(ClearButton, { disabled, onClick: onClear })
592
+ ] });
593
+ }
594
+ function ClearButton({ disabled, onClick }) {
595
+ const s = useFieldStrings();
596
+ return /* @__PURE__ */ jsx(
597
+ "button",
598
+ {
599
+ type: "button",
600
+ onClick,
601
+ disabled,
602
+ "aria-label": s.removeFileAria,
603
+ className: "flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-50",
604
+ children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
605
+ }
606
+ );
607
+ }
608
+ var Select = SelectPrimitive.Root;
609
+ var SelectValue = SelectPrimitive.Value;
610
+ var SelectTrigger = React2.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxs(
611
+ SelectPrimitive.Trigger,
612
+ {
613
+ ref,
614
+ className: cn(
615
+ // Adapted from the registry to DESIGN.md ("Inputs"): the `--input` surface,
616
+ // a hairline `--border`, and a border-color focus signal instead of the
617
+ // upstream 2px focus ring ("No focus glow by default").
618
+ "flex h-10 w-full items-center justify-between rounded-md border border-border bg-input px-3 py-2 text-sm transition-colors data-placeholder:text-muted-foreground focus:border-ring focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive [&>span]:line-clamp-1",
619
+ className
620
+ ),
621
+ ...props,
622
+ children: [
623
+ children,
624
+ /* @__PURE__ */ jsx(SelectPrimitive.Icon, { asChild: true, children: /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4 opacity-50" }) })
625
+ ]
626
+ }
627
+ ));
628
+ SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
629
+ var SelectScrollUpButton = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
630
+ SelectPrimitive.ScrollUpButton,
631
+ {
632
+ ref,
633
+ className: cn("flex cursor-default items-center justify-center py-1", className),
634
+ ...props,
635
+ children: /* @__PURE__ */ jsx(ChevronUp, { className: "h-4 w-4" })
636
+ }
637
+ ));
638
+ SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
639
+ var SelectScrollDownButton = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
640
+ SelectPrimitive.ScrollDownButton,
641
+ {
642
+ ref,
643
+ className: cn("flex cursor-default items-center justify-center py-1", className),
644
+ ...props,
645
+ children: /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4" })
646
+ }
647
+ ));
648
+ SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
649
+ var SelectContent = React2.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ jsx(SelectPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
650
+ SelectPrimitive.Content,
651
+ {
652
+ ref,
653
+ className: cn(
654
+ "relative z-50 max-h-(--radix-select-content-available-height) min-w-32 overflow-y-auto overflow-x-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--radix-select-content-transform-origin)",
655
+ position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
656
+ className
657
+ ),
658
+ position,
659
+ ...props,
660
+ children: [
661
+ /* @__PURE__ */ jsx(SelectScrollUpButton, {}),
662
+ /* @__PURE__ */ jsx(
663
+ SelectPrimitive.Viewport,
664
+ {
665
+ className: cn(
666
+ "p-1",
667
+ position === "popper" && "h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width)"
668
+ ),
669
+ children
670
+ }
671
+ ),
672
+ /* @__PURE__ */ jsx(SelectScrollDownButton, {})
673
+ ]
674
+ }
675
+ ) }));
676
+ SelectContent.displayName = SelectPrimitive.Content.displayName;
677
+ var SelectLabel = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
678
+ SelectPrimitive.Label,
679
+ {
680
+ ref,
681
+ className: cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className),
682
+ ...props
683
+ }
684
+ ));
685
+ SelectLabel.displayName = SelectPrimitive.Label.displayName;
686
+ var SelectItem = React2.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxs(
687
+ SelectPrimitive.Item,
688
+ {
689
+ ref,
690
+ className: cn(
691
+ "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-hidden focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",
692
+ className
693
+ ),
694
+ ...props,
695
+ children: [
696
+ /* @__PURE__ */ jsx("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ jsx(SelectPrimitive.ItemIndicator, { children: /* @__PURE__ */ jsx(Check, { className: "h-4 w-4" }) }) }),
697
+ /* @__PURE__ */ jsx(SelectPrimitive.ItemText, { children })
698
+ ]
699
+ }
700
+ ));
701
+ SelectItem.displayName = SelectPrimitive.Item.displayName;
702
+ var SelectSeparator = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
703
+ SelectPrimitive.Separator,
704
+ {
705
+ ref,
706
+ className: cn("-mx-1 my-1 h-px bg-muted", className),
707
+ ...props
708
+ }
709
+ ));
710
+ SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
711
+ var toggleVariants = cva(
712
+ "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 gap-2",
713
+ {
714
+ variants: {
715
+ variant: {
716
+ default: "bg-transparent",
717
+ outline: "border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"
718
+ },
719
+ size: {
720
+ default: "h-10 px-3 min-w-10",
721
+ sm: "h-9 px-2.5 min-w-9",
722
+ lg: "h-11 px-5 min-w-11"
723
+ }
724
+ },
725
+ defaultVariants: {
726
+ variant: "default",
727
+ size: "default"
728
+ }
729
+ }
730
+ );
731
+ var Toggle = React2.forwardRef(({ className, variant, size, ...props }, ref) => /* @__PURE__ */ jsx(
732
+ TogglePrimitive.Root,
733
+ {
734
+ ref,
735
+ className: cn(toggleVariants({ variant, size, className })),
736
+ ...props
737
+ }
738
+ ));
739
+ Toggle.displayName = TogglePrimitive.Root.displayName;
740
+ var ToggleGroupContext = React2.createContext({
741
+ size: "default",
742
+ variant: "default"
743
+ });
744
+ var ToggleGroup = React2.forwardRef(({ className, variant, size, children, ...props }, ref) => /* @__PURE__ */ jsx(
745
+ ToggleGroupPrimitive.Root,
746
+ {
747
+ ref,
748
+ className: cn("flex items-center justify-center gap-1", className),
749
+ ...props,
750
+ children: /* @__PURE__ */ jsx(ToggleGroupContext.Provider, { value: { variant, size }, children })
751
+ }
752
+ ));
753
+ ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName;
754
+ var ToggleGroupItem = React2.forwardRef(({ className, children, variant, size, ...props }, ref) => {
755
+ const context = React2.useContext(ToggleGroupContext);
756
+ return /* @__PURE__ */ jsx(
757
+ ToggleGroupPrimitive.Item,
758
+ {
759
+ ref,
760
+ className: cn(
761
+ toggleVariants({
762
+ variant: context.variant || variant,
763
+ size: context.size || size
764
+ }),
765
+ className
766
+ ),
767
+ ...props,
768
+ children
769
+ }
770
+ );
771
+ });
772
+ ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName;
773
+ var CLEAR_VALUE = "__none__";
774
+ function EnumField({ field, value, onChange, id, error, disabled }) {
775
+ const s = useFieldStrings();
776
+ const isSegmented = field.options.length <= 4 && field.options.every((o) => o.length <= 16);
777
+ const domId = useFieldDomId(id);
778
+ return /* @__PURE__ */ jsx(
779
+ FieldShell,
780
+ {
781
+ name: field.name,
782
+ title: field.title,
783
+ conceptRef: field.conceptRef,
784
+ category: "choice",
785
+ description: field.description,
786
+ required: field.required,
787
+ error,
788
+ htmlFor: isSegmented ? void 0 : domId,
789
+ children: isSegmented ? (
790
+ // `type="single"` gives the roving tabindex and arrow-key navigation a
791
+ // radiogroup owes its user, and emits `''` when the active item is
792
+ // pressed again - which is the field's "clear" path.
793
+ /* @__PURE__ */ jsx(
794
+ ToggleGroup,
795
+ {
796
+ type: "single",
797
+ value: value ?? "",
798
+ onValueChange: (next) => onChange(next === "" ? void 0 : next),
799
+ disabled,
800
+ "aria-label": field.title ?? field.name,
801
+ className: "flex flex-wrap justify-start gap-1.5",
802
+ children: field.options.map((option) => /* @__PURE__ */ jsxs(
803
+ ToggleGroupItem,
804
+ {
805
+ value: option,
806
+ variant: "outline",
807
+ className: "h-9 min-w-0 gap-1.5 border-border bg-input px-3 text-[13px] text-muted-foreground hover:bg-muted hover:text-foreground data-[state=on]:border-primary/40 data-[state=on]:bg-primary/10 data-[state=on]:font-medium data-[state=on]:text-foreground",
808
+ children: [
809
+ value === option && /* @__PURE__ */ jsx(Check, { className: "size-3.5 text-primary", strokeWidth: 2.5, "aria-hidden": "true" }),
810
+ option
811
+ ]
812
+ },
813
+ option
814
+ ))
815
+ }
816
+ )
817
+ ) : /* @__PURE__ */ jsxs(
818
+ Select,
819
+ {
820
+ value: value ?? "",
821
+ disabled,
822
+ onValueChange: (next) => onChange(next === CLEAR_VALUE ? void 0 : next),
823
+ children: [
824
+ /* @__PURE__ */ jsx(SelectTrigger, { id: domId, "aria-invalid": !!error, className: "h-11", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: s.selectPlaceholder }) }),
825
+ /* @__PURE__ */ jsxs(SelectContent, { children: [
826
+ /* @__PURE__ */ jsx(SelectItem, { value: CLEAR_VALUE, children: s.selectPlaceholder }),
827
+ field.options.map((option) => /* @__PURE__ */ jsx(SelectItem, { value: option, children: option }, option))
828
+ ] })
829
+ ]
830
+ }
831
+ )
832
+ }
833
+ );
834
+ }
835
+ function NumberField({ field, value, onChange, id, error, disabled }) {
836
+ const s = useFieldStrings();
837
+ const domId = useFieldDomId(id);
838
+ const step = field.integer ? 1 : 0.1;
839
+ const clamp = (n) => {
840
+ let next = n;
841
+ if (typeof field.min === "number") next = Math.max(field.min, next);
842
+ if (typeof field.max === "number") next = Math.min(field.max, next);
843
+ return field.integer ? Math.round(next) : next;
844
+ };
845
+ const nudge = (delta) => onChange(clamp((value ?? 0) + delta));
846
+ const rangeHint = field.min !== void 0 || field.max !== void 0 ? `${field.min ?? "\u2212\u221E"} \u2013 ${field.max ?? "\u221E"}` : void 0;
847
+ return /* @__PURE__ */ jsx(
848
+ FieldShell,
849
+ {
850
+ name: field.name,
851
+ title: field.title,
852
+ conceptRef: field.conceptRef,
853
+ category: "number",
854
+ description: field.description ?? rangeHint,
855
+ required: field.required,
856
+ error,
857
+ htmlFor: domId,
858
+ children: /* @__PURE__ */ jsxs("div", { className: "flex items-stretch gap-1.5", children: [
859
+ /* @__PURE__ */ jsx(
860
+ "input",
861
+ {
862
+ id: domId,
863
+ type: "number",
864
+ inputMode: field.integer ? "numeric" : "decimal",
865
+ value: value ?? "",
866
+ step,
867
+ min: field.min,
868
+ max: field.max,
869
+ disabled,
870
+ "aria-invalid": !!error,
871
+ placeholder: "0",
872
+ onChange: (e) => onChange(e.target.value === "" ? void 0 : Number(e.target.value)),
873
+ className: cn(
874
+ fieldControlClass,
875
+ "h-11 px-3 font-mono tabular-nums [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none"
876
+ )
877
+ }
878
+ ),
879
+ /* @__PURE__ */ jsx(StepButton, { onClick: () => nudge(-step), disabled, label: s.decrease, children: /* @__PURE__ */ jsx(Minus, { className: "h-4 w-4" }) }),
880
+ /* @__PURE__ */ jsx(StepButton, { onClick: () => nudge(step), disabled, label: s.increase, children: /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }) })
881
+ ] })
882
+ }
883
+ );
884
+ }
885
+ function StepButton({
886
+ onClick,
887
+ disabled,
888
+ label,
889
+ children
890
+ }) {
891
+ return /* @__PURE__ */ jsx(
892
+ "button",
893
+ {
894
+ type: "button",
895
+ onClick,
896
+ disabled,
897
+ "aria-label": label,
898
+ className: cn(
899
+ "flex h-11 w-11 shrink-0 items-center justify-center rounded-md border border-border bg-input text-muted-foreground transition-colors",
900
+ "hover:border-border hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
901
+ ),
902
+ children
903
+ }
904
+ );
905
+ }
906
+ function TextField({ field, value, onChange, id, error, disabled }) {
907
+ const s = useFieldStrings();
908
+ const domId = useFieldDomId(id);
909
+ return /* @__PURE__ */ jsx(
910
+ FieldShell,
911
+ {
912
+ name: field.name,
913
+ title: field.title,
914
+ conceptRef: field.conceptRef,
915
+ category: "text",
916
+ description: field.description,
917
+ required: field.required,
918
+ error,
919
+ htmlFor: domId,
920
+ children: /* @__PURE__ */ jsx(
921
+ "input",
922
+ {
923
+ id: domId,
924
+ type: "text",
925
+ value: value ?? "",
926
+ disabled,
927
+ "aria-invalid": !!error,
928
+ placeholder: field.placeholder ?? s.typeValuePlaceholder,
929
+ onChange: (e) => onChange(e.target.value === "" ? void 0 : e.target.value),
930
+ className: cn(fieldControlClass, "h-11 px-3")
931
+ }
932
+ )
933
+ }
934
+ );
935
+ }
936
+ function ProseField({ field, value, onChange, id, error, disabled }) {
937
+ const s = useFieldStrings();
938
+ const domId = useFieldDomId(id);
939
+ return /* @__PURE__ */ jsx(
940
+ FieldShell,
941
+ {
942
+ name: field.name,
943
+ title: field.title,
944
+ conceptRef: field.conceptRef,
945
+ category: "text",
946
+ description: field.description,
947
+ required: field.required,
948
+ error,
949
+ htmlFor: domId,
950
+ children: /* @__PURE__ */ jsx(
951
+ "textarea",
952
+ {
953
+ id: domId,
954
+ value: value ?? "",
955
+ disabled,
956
+ "aria-invalid": !!error,
957
+ rows: 3,
958
+ placeholder: field.placeholder ?? s.writeHerePlaceholder,
959
+ onChange: (e) => onChange(e.target.value === "" ? void 0 : e.target.value),
960
+ className: cn(
961
+ fieldControlClass,
962
+ "min-h-[88px] resize-y px-3 py-2.5 leading-relaxed field-sizing-content"
963
+ )
964
+ }
965
+ )
966
+ }
967
+ );
968
+ }
969
+ function OptionalToggle({ count, expanded, onToggle, noun = "field" }) {
970
+ const s = useFieldStrings();
971
+ return /* @__PURE__ */ jsxs(
972
+ "button",
973
+ {
974
+ type: "button",
975
+ onClick: onToggle,
976
+ className: "flex w-fit items-center gap-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground",
977
+ children: [
978
+ expanded ? /* @__PURE__ */ jsx(Minus, { className: "h-3 w-3" }) : /* @__PURE__ */ jsx(Plus, { className: "h-3 w-3" }),
979
+ expanded ? noun === "field" ? s.hideOptionalFields : s.hideOptionalInputs : noun === "field" ? s.optionalFieldsCount(count) : s.optionalInputsCount(count)
980
+ ]
981
+ }
982
+ );
983
+ }
984
+ function ObjectField({ field, value, onChange, id, error, env }) {
985
+ const s = useFieldStrings();
986
+ const [showOptional, setShowOptional] = useState(false);
987
+ const presentation = useFieldPresentation();
988
+ const isApp = presentation === "app";
989
+ const data = value ?? {};
990
+ const setChild = (name, childValue) => onChange({ ...data, [name]: childValue });
991
+ const optionalEmpty = field.fields.filter((f) => !f.required && !isFilled(ownProp(data, f.name)));
992
+ const visible = showOptional ? field.fields : field.fields.filter((f) => f.required || isFilled(ownProp(data, f.name)));
993
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
994
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-1", children: [
995
+ /* @__PURE__ */ jsx(
996
+ "span",
997
+ {
998
+ className: cn(
999
+ "text-[13px] font-medium leading-none text-foreground",
1000
+ isApp ? "text-[13.5px]" : "font-mono"
1001
+ ),
1002
+ children: fieldLabel(field.title, field.name, presentation)
1003
+ }
1004
+ ),
1005
+ !isApp && /* @__PURE__ */ jsx(ConceptPill, { conceptRef: field.conceptRef, category: "structured" }),
1006
+ !field.required && /* @__PURE__ */ jsx("span", { className: "ml-auto font-mono text-[10px] uppercase tracking-wider text-muted-foreground", children: s.optionalBadge })
1007
+ ] }),
1008
+ field.description && /* @__PURE__ */ jsx("p", { className: "text-[12px] leading-relaxed text-muted-foreground", children: field.description }),
1009
+ /* @__PURE__ */ jsxs(
1010
+ "div",
1011
+ {
1012
+ className: cn(
1013
+ "space-y-4 rounded-lg border bg-card/40 p-4",
1014
+ error ? "border-destructive/50" : "border-border"
1015
+ ),
1016
+ children: [
1017
+ visible.map((child) => /* @__PURE__ */ jsx(
1018
+ FieldRenderer,
1019
+ {
1020
+ field: child,
1021
+ value: ownProp(data, child.name),
1022
+ onChange: (v) => setChild(child.name, v),
1023
+ id: `${id}.${child.name}`,
1024
+ env
1025
+ },
1026
+ child.name
1027
+ )),
1028
+ optionalEmpty.length > 0 && /* @__PURE__ */ jsx(
1029
+ OptionalToggle,
1030
+ {
1031
+ count: optionalEmpty.length,
1032
+ expanded: showOptional,
1033
+ onToggle: () => setShowOptional((v) => !v),
1034
+ noun: "field"
1035
+ }
1036
+ )
1037
+ ]
1038
+ }
1039
+ ),
1040
+ error && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-destructive", role: "alert", children: error })
1041
+ ] });
1042
+ }
1043
+ function ListField({ field, value, onChange, id, error, env }) {
1044
+ const s = useFieldStrings();
1045
+ const presentation = useFieldPresentation();
1046
+ const isApp = presentation === "app";
1047
+ const items = value ?? [];
1048
+ const [rowKeys, setRowKeys] = useRowKeys(items.length);
1049
+ const setItem = (index, itemValue) => {
1050
+ const next = items.slice();
1051
+ next[index] = itemValue;
1052
+ onChange(next);
1053
+ };
1054
+ const removeItem = (index) => {
1055
+ setRowKeys((prev) => prev.filter((_, i) => i !== index));
1056
+ onChange(items.filter((_, i) => i !== index));
1057
+ };
1058
+ const addItem = () => onChange([...items, emptyValue(field.item)]);
1059
+ const busy = listIsBusy(id, env?.uploadingIds);
1060
+ const isFull = field.maxItemCount !== void 0 && items.length >= field.maxItemCount;
1061
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
1062
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-1", children: [
1063
+ /* @__PURE__ */ jsx(
1064
+ "span",
1065
+ {
1066
+ className: cn(
1067
+ "text-[13px] font-medium leading-none text-foreground",
1068
+ isApp ? "text-[13.5px]" : "font-mono"
1069
+ ),
1070
+ children: fieldLabel(field.title, field.name, presentation)
1071
+ }
1072
+ ),
1073
+ !isApp && /* @__PURE__ */ jsx(ConceptPill, { conceptRef: field.conceptRef, category: "list" }),
1074
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-[10.5px] text-muted-foreground", children: field.itemCount !== void 0 && field.maxItemCount === field.itemCount ? s.itemsCountOf(items.length, field.itemCount) : s.itemsCount(items.length) }),
1075
+ !field.required && /* @__PURE__ */ jsx("span", { className: "ml-auto font-mono text-[10px] uppercase tracking-wider text-muted-foreground", children: s.optionalBadge })
1076
+ ] }),
1077
+ field.description && /* @__PURE__ */ jsx("p", { className: "text-[12px] leading-relaxed text-muted-foreground", children: field.description }),
1078
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
1079
+ items.length === 0 && /* @__PURE__ */ jsx("p", { className: "rounded-md border border-dashed border-border bg-input/50 px-3 py-4 text-center text-[12px] text-muted-foreground", children: s.noItemsYet }),
1080
+ items.map((item, index) => /* @__PURE__ */ jsxs(
1081
+ "div",
1082
+ {
1083
+ className: "flex items-start gap-2 rounded-md border border-border bg-card/40 p-3",
1084
+ children: [
1085
+ /* @__PURE__ */ jsx("span", { className: "mt-1 w-5 shrink-0 text-center font-mono text-[11px] text-muted-foreground", children: index + 1 }),
1086
+ /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx(
1087
+ FieldRenderer,
1088
+ {
1089
+ field: { ...field.item, title: "", name: `${field.name}[${index}]` },
1090
+ value: item,
1091
+ onChange: (v) => setItem(index, v),
1092
+ id: `${id}.${index}`,
1093
+ env
1094
+ }
1095
+ ) }),
1096
+ /* @__PURE__ */ jsx(
1097
+ "button",
1098
+ {
1099
+ type: "button",
1100
+ onClick: () => removeItem(index),
1101
+ disabled: env?.disabled || busy,
1102
+ "aria-label": s.removeItemAria(index + 1),
1103
+ className: "mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-destructive disabled:opacity-50",
1104
+ children: /* @__PURE__ */ jsx(Trash2, { className: "h-3.5 w-3.5" })
1105
+ }
1106
+ )
1107
+ ]
1108
+ },
1109
+ rowKeys[index] ?? index
1110
+ )),
1111
+ /* @__PURE__ */ jsxs(
1112
+ "button",
1113
+ {
1114
+ type: "button",
1115
+ onClick: addItem,
1116
+ disabled: env?.disabled || isFull,
1117
+ className: cn(
1118
+ "inline-flex h-9 w-full items-center justify-center gap-1.5 rounded-md border border-dashed border-border text-[13px] text-muted-foreground transition-colors",
1119
+ "hover:border-primary/40 hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"
1120
+ ),
1121
+ children: [
1122
+ /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
1123
+ s.addItem
1124
+ ]
1125
+ }
1126
+ )
1127
+ ] }),
1128
+ error && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-destructive", role: "alert", children: error })
1129
+ ] });
1130
+ }
1131
+ function listIsBusy(id, uploadingIds) {
1132
+ if (!uploadingIds?.size) return false;
1133
+ const prefix = `${id}.`;
1134
+ for (const uploading of uploadingIds) if (uploading.startsWith(prefix)) return true;
1135
+ return false;
1136
+ }
1137
+ function useRowKeys(length) {
1138
+ const [state, setState] = useState(() => ({
1139
+ keys: Array.from({ length }, (_, i) => i),
1140
+ next: length
1141
+ }));
1142
+ if (state.keys.length !== length) {
1143
+ setState((prev) => {
1144
+ if (length <= prev.keys.length) return { keys: prev.keys.slice(0, length), next: prev.next };
1145
+ const added = length - prev.keys.length;
1146
+ return {
1147
+ keys: [...prev.keys, ...Array.from({ length: added }, (_, i) => prev.next + i)],
1148
+ next: prev.next + added
1149
+ };
1150
+ });
1151
+ }
1152
+ const update = (fn) => setState((prev) => ({ keys: fn(prev.keys), next: prev.next }));
1153
+ return [state.keys, update];
1154
+ }
1155
+ function emptyValue(field) {
1156
+ switch (field.kind) {
1157
+ case "boolean":
1158
+ return false;
1159
+ case "object":
1160
+ return {};
1161
+ case "list":
1162
+ return [];
1163
+ case "document":
1164
+ case "image":
1165
+ return void 0;
1166
+ default:
1167
+ return void 0;
1168
+ }
1169
+ }
1170
+ function UnknownField({ field, value, onChange, id, error, disabled }) {
1171
+ const s = useFieldStrings();
1172
+ const domId = useFieldDomId(id);
1173
+ return /* @__PURE__ */ jsx(
1174
+ FieldShell,
1175
+ {
1176
+ name: field.name,
1177
+ title: field.title,
1178
+ conceptRef: field.conceptRef,
1179
+ category: "structured",
1180
+ description: field.description ?? s.jsonHint,
1181
+ required: field.required,
1182
+ error,
1183
+ htmlFor: domId,
1184
+ children: /* @__PURE__ */ jsx(
1185
+ "textarea",
1186
+ {
1187
+ id: domId,
1188
+ value: value ?? "",
1189
+ disabled,
1190
+ "aria-invalid": !!error,
1191
+ rows: 3,
1192
+ spellCheck: false,
1193
+ placeholder: '{\n "key": "value"\n}',
1194
+ onChange: (e) => onChange(e.target.value === "" ? void 0 : e.target.value),
1195
+ className: cn(fieldControlClass, "min-h-[80px] resize-y px-3 py-2.5 font-mono text-[12px]")
1196
+ }
1197
+ )
1198
+ }
1199
+ );
1200
+ }
1201
+ function FieldRenderer({ field, value, onChange, id, error, env }) {
1202
+ const disabled = env?.disabled;
1203
+ switch (field.kind) {
1204
+ case "text":
1205
+ return /* @__PURE__ */ jsx(
1206
+ TextField,
1207
+ {
1208
+ field,
1209
+ value,
1210
+ onChange,
1211
+ id,
1212
+ error,
1213
+ disabled
1214
+ }
1215
+ );
1216
+ case "prose":
1217
+ return /* @__PURE__ */ jsx(
1218
+ ProseField,
1219
+ {
1220
+ field,
1221
+ value,
1222
+ onChange,
1223
+ id,
1224
+ error,
1225
+ disabled
1226
+ }
1227
+ );
1228
+ case "date":
1229
+ return /* @__PURE__ */ jsx(
1230
+ DateField,
1231
+ {
1232
+ field,
1233
+ value,
1234
+ onChange,
1235
+ id,
1236
+ error,
1237
+ disabled
1238
+ }
1239
+ );
1240
+ case "number":
1241
+ return /* @__PURE__ */ jsx(
1242
+ NumberField,
1243
+ {
1244
+ field,
1245
+ value,
1246
+ onChange,
1247
+ id,
1248
+ error,
1249
+ disabled
1250
+ }
1251
+ );
1252
+ case "boolean":
1253
+ return /* @__PURE__ */ jsx(
1254
+ BooleanField,
1255
+ {
1256
+ field,
1257
+ value,
1258
+ onChange,
1259
+ id,
1260
+ disabled
1261
+ }
1262
+ );
1263
+ case "enum":
1264
+ return /* @__PURE__ */ jsx(
1265
+ EnumField,
1266
+ {
1267
+ field,
1268
+ value,
1269
+ onChange,
1270
+ id,
1271
+ error,
1272
+ disabled
1273
+ }
1274
+ );
1275
+ case "document":
1276
+ return /* @__PURE__ */ jsx(
1277
+ DocumentField,
1278
+ {
1279
+ field,
1280
+ value,
1281
+ onChange,
1282
+ onDropFile: (file) => env?.onDropFile?.(id, file),
1283
+ uploading: env?.uploadingIds?.has(id),
1284
+ resolveUrl: env?.resolveUrl,
1285
+ id,
1286
+ error,
1287
+ disabled
1288
+ }
1289
+ );
1290
+ case "image":
1291
+ return /* @__PURE__ */ jsx(
1292
+ ImageField,
1293
+ {
1294
+ field,
1295
+ value,
1296
+ onChange,
1297
+ onDropFile: (file) => env?.onDropFile?.(id, file),
1298
+ uploading: env?.uploadingIds?.has(id),
1299
+ resolveUrl: env?.resolveUrl,
1300
+ id,
1301
+ error,
1302
+ disabled
1303
+ }
1304
+ );
1305
+ case "object":
1306
+ return /* @__PURE__ */ jsx(
1307
+ ObjectField,
1308
+ {
1309
+ field,
1310
+ value,
1311
+ onChange,
1312
+ id,
1313
+ error,
1314
+ env
1315
+ }
1316
+ );
1317
+ case "list":
1318
+ return /* @__PURE__ */ jsx(
1319
+ ListField,
1320
+ {
1321
+ field,
1322
+ value,
1323
+ onChange,
1324
+ id,
1325
+ error,
1326
+ env
1327
+ }
1328
+ );
1329
+ default:
1330
+ return /* @__PURE__ */ jsx(
1331
+ UnknownField,
1332
+ {
1333
+ field,
1334
+ value,
1335
+ onChange,
1336
+ id,
1337
+ error,
1338
+ disabled
1339
+ }
1340
+ );
1341
+ }
1342
+ }
1343
+ var ResultEnvContext = createContext({});
1344
+ function ResultEnvProvider({
1345
+ resolveUrl,
1346
+ resolveShareUrl,
1347
+ proseImages,
1348
+ children
1349
+ }) {
1350
+ const env = useMemo(
1351
+ () => ({ resolveUrl, resolveShareUrl, proseImages }),
1352
+ [resolveUrl, resolveShareUrl, proseImages]
1353
+ );
1354
+ return /* @__PURE__ */ jsx(ResultEnvContext, { value: env, children });
1355
+ }
1356
+ function useResolvedUrl(url) {
1357
+ return use(ResultEnvContext).resolveUrl?.(url) ?? url;
1358
+ }
1359
+ function useResolveUrl() {
1360
+ return use(ResultEnvContext).resolveUrl;
1361
+ }
1362
+ function useResolveShareUrl() {
1363
+ return use(ResultEnvContext).resolveShareUrl;
1364
+ }
1365
+ function useProseImages() {
1366
+ return use(ResultEnvContext).proseImages ?? "link";
1367
+ }
1368
+ var TooltipProvider = TooltipPrimitive.Provider;
1369
+ var TooltipRoot = TooltipPrimitive.Root;
1370
+ var TooltipTrigger = TooltipPrimitive.Trigger;
1371
+ var TooltipContent = React2.forwardRef(({ className, sideOffset = 6, ...props }, ref) => /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsx(
1372
+ TooltipPrimitive.Content,
1373
+ {
1374
+ ref,
1375
+ sideOffset,
1376
+ className: cn(
1377
+ "z-50 max-w-xs rounded-md border border-border bg-popover px-2.5 py-1.5 text-[12px] leading-relaxed text-popover-foreground shadow-md",
1378
+ "animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
1379
+ "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
1380
+ className
1381
+ ),
1382
+ ...props
1383
+ }
1384
+ ) }));
1385
+ TooltipContent.displayName = TooltipPrimitive.Content.displayName;
1386
+ var DEFAULT_IMG_SRC = "data: https:";
1387
+ function frameStyles(color, mutedColor, borderColor, font) {
1388
+ return `
1389
+ :root { color-scheme: inherit; }
1390
+ body {
1391
+ margin: 0;
1392
+ color: ${color};
1393
+ font-family: ${font};
1394
+ font-size: 13px;
1395
+ line-height: 1.55;
1396
+ background: transparent;
1397
+ overflow-wrap: anywhere;
1398
+ }
1399
+ :where(h1, h2, h3, h4, h5, h6) { margin: 0 0 0.4em; line-height: 1.25; }
1400
+ :where(h1) { font-size: 1.4em; }
1401
+ :where(h2) { font-size: 1.2em; }
1402
+ :where(h3) { font-size: 1.05em; }
1403
+ :where(p, ul, ol, table, pre, blockquote) { margin: 0 0 0.75em; }
1404
+ :where(ul, ol) { padding-inline-start: 1.25em; }
1405
+ :where(table) { border-collapse: collapse; width: 100%; }
1406
+ :where(th, td) {
1407
+ border: 1px solid ${borderColor};
1408
+ padding: 4px 8px;
1409
+ text-align: left;
1410
+ vertical-align: top;
1411
+ }
1412
+ :where(th) { font-weight: 600; }
1413
+ :where(caption) { caption-side: top; color: ${mutedColor}; padding-bottom: 4px; text-align: left; }
1414
+ :where(a) { color: inherit; }
1415
+ :where(code, pre) { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
1416
+ :where(pre) { white-space: pre-wrap; }
1417
+ :where(blockquote) { border-inline-start: 2px solid ${borderColor}; margin-inline-start: 0; padding-inline-start: 0.75em; color: ${mutedColor}; }
1418
+ :where(img) { max-width: 100%; height: auto; }
1419
+ :where(hr) { border: 0; border-top: 1px solid ${borderColor}; }
1420
+ :where(*:last-child) { margin-bottom: 0; }
1421
+ `;
1422
+ }
1423
+ function frameDocument(content, styles, imgSrc) {
1424
+ const body = content.cssClass ? (
1425
+ // The class the value states, honoured the way the runtime's own HTML
1426
+ // rendering honours it: as a wrapper, not as something merged into ours.
1427
+ `<div class="${escapeAttribute(content.cssClass)}">${content.innerHtml}</div>`
1428
+ ) : content.innerHtml;
1429
+ return [
1430
+ '<!doctype html><html><head><meta charset="utf-8">',
1431
+ `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src ${imgSrc}; base-uri 'none'; form-action 'none'">`,
1432
+ `<style>${styles}</style></head><body>${body}</body></html>`
1433
+ ].join("");
1434
+ }
1435
+ function escapeAttribute(value) {
1436
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
1437
+ }
1438
+ var useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
1439
+ function HtmlPreview({
1440
+ content,
1441
+ maxHeight = 1400,
1442
+ imgSrc = DEFAULT_IMG_SRC
1443
+ }) {
1444
+ const hostRef = useRef(null);
1445
+ const frameRef = useRef(null);
1446
+ const [doc, setDoc] = useState(null);
1447
+ const [height, setHeight] = useState(0);
1448
+ useIsomorphicLayoutEffect(() => {
1449
+ const host = hostRef.current;
1450
+ if (!host) return;
1451
+ const computed = getComputedStyle(host);
1452
+ setDoc(
1453
+ frameDocument(
1454
+ content,
1455
+ frameStyles(
1456
+ computed.color,
1457
+ computed.getPropertyValue("--muted-foreground").trim() || computed.color,
1458
+ computed.borderColor || computed.color,
1459
+ computed.fontFamily
1460
+ ),
1461
+ imgSrc
1462
+ )
1463
+ );
1464
+ }, [content, imgSrc]);
1465
+ const measure = () => {
1466
+ const body = frameRef.current?.contentDocument?.body;
1467
+ if (body) setHeight(body.scrollHeight);
1468
+ };
1469
+ useEffect(() => {
1470
+ if (!doc || !hostRef.current || typeof ResizeObserver === "undefined") return;
1471
+ const observer = new ResizeObserver(measure);
1472
+ observer.observe(hostRef.current);
1473
+ return () => observer.disconnect();
1474
+ }, [doc]);
1475
+ return /* @__PURE__ */ jsx(
1476
+ "div",
1477
+ {
1478
+ ref: hostRef,
1479
+ className: "overflow-hidden rounded-lg border border-border bg-card/40 px-3.5 py-3 text-[13px] text-foreground",
1480
+ children: doc === null ? null : /* @__PURE__ */ jsx(
1481
+ "iframe",
1482
+ {
1483
+ ref: frameRef,
1484
+ title: content.cssClass ? `HTML result (${content.cssClass})` : "HTML result",
1485
+ srcDoc: doc,
1486
+ onLoad: measure,
1487
+ sandbox: "allow-same-origin",
1488
+ style: {
1489
+ display: "block",
1490
+ width: "100%",
1491
+ border: 0,
1492
+ height: height === 0 ? void 0 : Math.min(height, maxHeight),
1493
+ maxHeight
1494
+ }
1495
+ }
1496
+ )
1497
+ }
1498
+ );
1499
+ }
1500
+ var LEX_OPTIONS = { gfm: true, breaks: true };
1501
+ function Markdown({ text, className, proseImages }) {
1502
+ const tokens = React2.useMemo(() => marked.lexer(text, LEX_OPTIONS), [text]);
1503
+ const fromEnv = useProseImages();
1504
+ const mode = proseImages ?? fromEnv;
1505
+ return /* @__PURE__ */ jsx(ProseImagesContext, { value: mode, children: /* @__PURE__ */ jsx("div", { className: cn("space-y-2 text-[13px] leading-relaxed text-foreground", className), children: /* @__PURE__ */ jsx(Blocks, { tokens }) }) });
1506
+ }
1507
+ var ProseImagesContext = React2.createContext("link");
1508
+ var HEADING_CLASS = {
1509
+ 1: "text-[16px] font-semibold",
1510
+ 2: "text-[14.5px] font-semibold",
1511
+ 3: "text-[13.5px] font-semibold",
1512
+ 4: "text-[13px] font-semibold",
1513
+ 5: "text-[13px] font-semibold",
1514
+ 6: "text-[13px] font-semibold"
1515
+ };
1516
+ function Blocks({ tokens }) {
1517
+ return /* @__PURE__ */ jsx(Fragment, { children: tokens.map((token, index) => /* @__PURE__ */ jsx(Block, { token }, index)) });
1518
+ }
1519
+ function Block({ token }) {
1520
+ switch (token.type) {
1521
+ case "space":
1522
+ return null;
1523
+ case "heading": {
1524
+ const heading = token;
1525
+ const level = Math.min(Math.max(heading.depth, 1), 6);
1526
+ const Tag = `h${level}`;
1527
+ return /* @__PURE__ */ jsx(Tag, { className: cn("mt-3 first:mt-0", HEADING_CLASS[level]), children: /* @__PURE__ */ jsx(Inline, { tokens: heading.tokens }) });
1528
+ }
1529
+ case "paragraph":
1530
+ return /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(Inline, { tokens: token.tokens }) });
1531
+ // A `text` token in BLOCK position, which is what a tight list's items are
1532
+ // made of: the lexer wraps a loose item's content in a paragraph and a
1533
+ // tight one's in a bare `text`. Without this arm it fell through to the raw
1534
+ // fallback below and a bulleted `**Type:** …` rendered with its asterisks
1535
+ // showing - typeset everywhere except inside a list, which is where model
1536
+ // output puts most of its emphasis.
1537
+ case "text":
1538
+ return /* @__PURE__ */ jsx(Inline, { tokens: token.tokens ?? [token] });
1539
+ case "list": {
1540
+ const list = token;
1541
+ const Tag = list.ordered ? "ol" : "ul";
1542
+ return /* @__PURE__ */ jsx(
1543
+ Tag,
1544
+ {
1545
+ className: cn("space-y-1 ps-5", list.ordered ? "list-decimal" : "list-disc"),
1546
+ ...list.ordered && list.start !== 1 ? { start: Number(list.start) } : {},
1547
+ children: list.items.map((item, index) => /* @__PURE__ */ jsxs("li", { className: "marker:text-muted-foreground", children: [
1548
+ item.task ? /* @__PURE__ */ jsx(
1549
+ "input",
1550
+ {
1551
+ type: "checkbox",
1552
+ checked: item.checked ?? false,
1553
+ disabled: true,
1554
+ readOnly: true,
1555
+ className: "me-1.5 align-middle"
1556
+ }
1557
+ ) : null,
1558
+ /* @__PURE__ */ jsx(Blocks, { tokens: item.tokens })
1559
+ ] }, index))
1560
+ }
1561
+ );
1562
+ }
1563
+ case "code": {
1564
+ const code = token;
1565
+ return (
1566
+ // WRAPPED, not scrolled. A code block in a side panel is usually not
1567
+ // code at all: it is a model that opened a fence and did not close it,
1568
+ // or closed one it never opened, and the rest of a report ends up
1569
+ // inside it. Scrolling that sideways hides the text behind a scrollbar
1570
+ // for no gain — the lines are prose, and prose wraps. Real code loses
1571
+ // its column alignment and keeps every character, which is the better
1572
+ // half of that trade at this width.
1573
+ /* @__PURE__ */ jsx("pre", { className: "whitespace-pre-wrap wrap-break-word rounded-md border border-border bg-card/40 p-2.5 text-[12px]", children: /* @__PURE__ */ jsx("code", { children: code.text }) })
1574
+ );
1575
+ }
1576
+ case "blockquote":
1577
+ return /* @__PURE__ */ jsx("blockquote", { className: "border-s-2 border-border ps-3 text-muted-foreground", children: /* @__PURE__ */ jsx(Blocks, { tokens: token.tokens }) });
1578
+ case "hr":
1579
+ return /* @__PURE__ */ jsx("hr", { className: "border-border" });
1580
+ case "table": {
1581
+ const table = token;
1582
+ return (
1583
+ // The same overflow rule the result tables follow: a wide table scrolls
1584
+ // inside its own box rather than widening the panel around it.
1585
+ /* @__PURE__ */ jsx("div", { className: "overflow-x-auto rounded-lg border border-border", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full border-collapse text-[12.5px]", children: [
1586
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { className: "border-b border-border bg-card/40", children: table.header.map((cell, index) => /* @__PURE__ */ jsx(
1587
+ "th",
1588
+ {
1589
+ scope: "col",
1590
+ className: "px-2.5 py-1.5 text-start font-semibold",
1591
+ style: alignOf(table.align[index]),
1592
+ children: /* @__PURE__ */ jsx(Inline, { tokens: cell.tokens })
1593
+ },
1594
+ index
1595
+ )) }) }),
1596
+ /* @__PURE__ */ jsx("tbody", { children: table.rows.map((row, rowIndex) => /* @__PURE__ */ jsx("tr", { className: "border-b border-border/60 last:border-b-0", children: row.map((cell, cellIndex) => /* @__PURE__ */ jsx(
1597
+ "td",
1598
+ {
1599
+ className: "px-2.5 py-1.5 align-top",
1600
+ style: alignOf(table.align[cellIndex]),
1601
+ children: /* @__PURE__ */ jsx(Inline, { tokens: cell.tokens })
1602
+ },
1603
+ cellIndex
1604
+ )) }, rowIndex)) })
1605
+ ] }) })
1606
+ );
1607
+ }
1608
+ // `html` and anything this version of the lexer grows that we have no arm
1609
+ // for: shown as its own source text. Rendering markup we have decided not to
1610
+ // execute as the characters it is made of is the honest fallback - it never
1611
+ // silently drops content, and it never injects any.
1612
+ default:
1613
+ return /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap", children: rawOf(token) });
1614
+ }
1615
+ }
1616
+ function Inline({ tokens }) {
1617
+ if (!tokens) return null;
1618
+ return /* @__PURE__ */ jsx(Fragment, { children: tokens.map((token, index) => /* @__PURE__ */ jsx(InlineToken, { token }, index)) });
1619
+ }
1620
+ function InlineToken({ token }) {
1621
+ switch (token.type) {
1622
+ case "text": {
1623
+ const text = token;
1624
+ return text.tokens ? /* @__PURE__ */ jsx(Inline, { tokens: text.tokens }) : /* @__PURE__ */ jsx(Fragment, { children: decode(text.text) });
1625
+ }
1626
+ case "escape":
1627
+ return /* @__PURE__ */ jsx(Fragment, { children: token.text });
1628
+ case "strong":
1629
+ return /* @__PURE__ */ jsx("strong", { className: "font-semibold", children: /* @__PURE__ */ jsx(Inline, { tokens: token.tokens }) });
1630
+ case "em":
1631
+ return /* @__PURE__ */ jsx("em", { className: "italic", children: /* @__PURE__ */ jsx(Inline, { tokens: token.tokens }) });
1632
+ case "del":
1633
+ return /* @__PURE__ */ jsx("del", { className: "line-through", children: /* @__PURE__ */ jsx(Inline, { tokens: token.tokens }) });
1634
+ case "codespan":
1635
+ return /* @__PURE__ */ jsx("code", { className: "rounded border border-border bg-card/40 px-1 py-0.5 text-[0.92em]", children: decode(token.text) });
1636
+ case "br":
1637
+ return /* @__PURE__ */ jsx("br", {});
1638
+ case "link": {
1639
+ const link = token;
1640
+ const href = safeHref(link.href);
1641
+ if (!href) return /* @__PURE__ */ jsx(Inline, { tokens: link.tokens });
1642
+ return (
1643
+ // The flag is set for everything under the anchor, so a nested `image`
1644
+ // token knows not to open one of its own — see {@link ProseImage}.
1645
+ /* @__PURE__ */ jsx(InsideLinkContext, { value: true, children: /* @__PURE__ */ jsx(
1646
+ "a",
1647
+ {
1648
+ href,
1649
+ target: "_blank",
1650
+ rel: "noreferrer noopener",
1651
+ className: "underline underline-offset-2",
1652
+ children: /* @__PURE__ */ jsx(Inline, { tokens: link.tokens })
1653
+ }
1654
+ ) })
1655
+ );
1656
+ }
1657
+ case "image":
1658
+ return /* @__PURE__ */ jsx(ProseImage, { token });
1659
+ default:
1660
+ return /* @__PURE__ */ jsx(Fragment, { children: rawOf(token) });
1661
+ }
1662
+ }
1663
+ function ProseImage({ token }) {
1664
+ const mode = React2.use(ProseImagesContext);
1665
+ const insideLink = React2.use(InsideLinkContext);
1666
+ const src = proseImageUrl(token.href);
1667
+ if (!src) return /* @__PURE__ */ jsx(Fragment, { children: token.text });
1668
+ if (mode === "load") {
1669
+ return /* @__PURE__ */ jsx(
1670
+ "img",
1671
+ {
1672
+ src,
1673
+ alt: token.text,
1674
+ referrerPolicy: "no-referrer",
1675
+ className: "max-w-full rounded-md"
1676
+ }
1677
+ );
1678
+ }
1679
+ if (insideLink) return /* @__PURE__ */ jsx(Fragment, { children: token.text || src });
1680
+ return /* @__PURE__ */ jsx(
1681
+ "a",
1682
+ {
1683
+ href: src,
1684
+ target: "_blank",
1685
+ rel: "noreferrer noopener",
1686
+ className: "underline underline-offset-2",
1687
+ children: token.text || src
1688
+ }
1689
+ );
1690
+ }
1691
+ var InsideLinkContext = React2.createContext(false);
1692
+ function proseImageUrl(href) {
1693
+ const url = viewableUrl(href);
1694
+ return url && /^https?:/.test(url) ? url : void 0;
1695
+ }
1696
+ function safeHref(href) {
1697
+ const trimmed = href.trim();
1698
+ if (/^(https?:|mailto:)/i.test(trimmed)) return trimmed;
1699
+ if (trimmed.startsWith("#")) return trimmed;
1700
+ if (trimmed.startsWith("/")) return viewableUrl(trimmed);
1701
+ return void 0;
1702
+ }
1703
+ function alignOf(align) {
1704
+ return align ? { textAlign: align } : void 0;
1705
+ }
1706
+ function rawOf(token) {
1707
+ return "raw" in token && typeof token.raw === "string" ? token.raw : "";
1708
+ }
1709
+ var ENTITIES = {
1710
+ "&amp;": "&",
1711
+ "&lt;": "<",
1712
+ "&gt;": ">",
1713
+ "&quot;": '"',
1714
+ "&#39;": "'",
1715
+ "&#x27;": "'"
1716
+ };
1717
+ function decode(text) {
1718
+ return text.replace(/&(?:amp|lt|gt|quot|#39|#x27);/g, (entity) => ENTITIES[entity] ?? entity);
1719
+ }
1720
+ function unwrap(field, value) {
1721
+ if (!field.contentKey) return value;
1722
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return value;
1723
+ const unwrapped = ownProp(value, field.contentKey);
1724
+ return unwrapped === void 0 ? value : unwrapped;
1725
+ }
1726
+ function Described({ description, children }) {
1727
+ if (!description) return /* @__PURE__ */ jsx(Fragment, { children });
1728
+ return /* @__PURE__ */ jsx(TooltipProvider, { delayDuration: 200, children: /* @__PURE__ */ jsxs(TooltipRoot, { children: [
1729
+ /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
1730
+ "span",
1731
+ {
1732
+ tabIndex: 0,
1733
+ className: "-mx-1 cursor-help rounded px-1 outline-hidden transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring",
1734
+ children
1735
+ }
1736
+ ) }),
1737
+ /* @__PURE__ */ jsx(TooltipContent, { children: description })
1738
+ ] }) });
1739
+ }
1740
+ function ResultHeader({ field }) {
1741
+ return /* @__PURE__ */ jsx(Label2, { field, describe: true });
1742
+ }
1743
+ function Label2({ field, describe = false }) {
1744
+ const presentation = useFieldPresentation();
1745
+ const isApp = presentation === "app";
1746
+ const labelText = fieldLabel(field.title, field.name, presentation);
1747
+ if (labelText.trim() === "") {
1748
+ return /* @__PURE__ */ jsx(ConceptPill, { conceptRef: field.conceptRef, category: conceptCategory(field) });
1749
+ }
1750
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2", children: [
1751
+ /* @__PURE__ */ jsx(Described, { description: describe ? field.description : void 0, children: /* @__PURE__ */ jsx(
1752
+ "span",
1753
+ {
1754
+ className: cn(
1755
+ "text-[13px] font-semibold text-foreground",
1756
+ isApp ? "text-[13.5px]" : "font-mono"
1757
+ ),
1758
+ children: labelText
1759
+ }
1760
+ ) }),
1761
+ !isApp && /* @__PURE__ */ jsx(ConceptPill, { conceptRef: field.conceptRef, category: conceptCategory(field) })
1762
+ ] });
1763
+ }
1764
+ function Absent() {
1765
+ const s = useFieldStrings();
1766
+ return /* @__PURE__ */ jsxs("span", { className: "text-[13px] text-muted-foreground", children: [
1767
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, children: s.resultAbsent }),
1768
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: s.resultAbsentDescription })
1769
+ ] });
1770
+ }
1771
+ function stringifyValue(value) {
1772
+ try {
1773
+ const text = JSON.stringify(
1774
+ value,
1775
+ (_key, member) => typeof member === "bigint" ? member.toString() : member
1776
+ );
1777
+ if (text === void 0 || text === "{}" || text === "[]") return void 0;
1778
+ return JSON.stringify(JSON.parse(text), null, 2);
1779
+ } catch {
1780
+ const keys = Array.isArray(value) ? [] : Object.keys(value);
1781
+ return keys.length > 0 ? `{ ${keys.join(", ")} }` : void 0;
1782
+ }
1783
+ }
1784
+ function RawValue({ value, compact }) {
1785
+ const text = stringifyValue(value);
1786
+ if (text === void 0) return /* @__PURE__ */ jsx(Absent, {});
1787
+ return compact ? /* @__PURE__ */ jsx("span", { title: text, className: "truncate font-mono text-[12px] text-foreground", children: text }) : /* @__PURE__ */ jsx("pre", { className: "overflow-x-auto whitespace-pre-wrap wrap-break-word rounded-md border border-border bg-card/40 px-2.5 py-1.5 font-mono text-[12px] leading-relaxed text-foreground", children: text });
1788
+ }
1789
+ function Scalar({ value, compact = false }) {
1790
+ if (value === null || value === void 0 || value === "") return /* @__PURE__ */ jsx(Absent, {});
1791
+ if (typeof value === "object") return /* @__PURE__ */ jsx(RawValue, { value, compact });
1792
+ return /* @__PURE__ */ jsx(
1793
+ "span",
1794
+ {
1795
+ className: cn(
1796
+ "text-[13px] leading-relaxed text-foreground",
1797
+ compact ? "whitespace-nowrap" : "whitespace-pre-wrap"
1798
+ ),
1799
+ children: String(value)
1800
+ }
1801
+ );
1802
+ }
1803
+ function Bool({ value, compact = false }) {
1804
+ const s = useFieldStrings();
1805
+ if (value === null || value === void 0 || value === "") return /* @__PURE__ */ jsx(Absent, {});
1806
+ if (typeof value !== "boolean") return /* @__PURE__ */ jsx(Scalar, { value, compact });
1807
+ return /* @__PURE__ */ jsx("span", { className: "text-[13px] text-foreground", children: value ? s.yes : s.no });
1808
+ }
1809
+ function DateValue({ value }) {
1810
+ const content = readDateContent(value);
1811
+ if (!content) return /* @__PURE__ */ jsx(Absent, {});
1812
+ return /* @__PURE__ */ jsx("span", { className: "text-[13px] text-foreground", children: formatDateContent(content) });
1813
+ }
1814
+ function fileLabel(url, filename, strings) {
1815
+ if (filename) return filename;
1816
+ const encoded = encodedFileSummary(url, strings);
1817
+ if (encoded !== void 0) return encoded;
1818
+ return pathLabel(url);
1819
+ }
1820
+ function pathLabel(url) {
1821
+ const path = url.split(/[?#]/)[0] ?? url;
1822
+ const segment = path.split("/").filter(Boolean).pop();
1823
+ return segment && segment.length > 0 ? segment : url;
1824
+ }
1825
+ function CopyButton({
1826
+ value,
1827
+ provide,
1828
+ label,
1829
+ title
1830
+ }) {
1831
+ const [copied, setCopied] = useState(false);
1832
+ if (typeof navigator === "undefined" || !navigator.clipboard) return null;
1833
+ return /* @__PURE__ */ jsx(
1834
+ "button",
1835
+ {
1836
+ type: "button",
1837
+ onClick: () => {
1838
+ const done = () => {
1839
+ setCopied(true);
1840
+ window.setTimeout(() => setCopied(false), 1500);
1841
+ };
1842
+ if (!provide) {
1843
+ void navigator.clipboard.writeText(value ?? "").then(done);
1844
+ return;
1845
+ }
1846
+ const text = provide();
1847
+ if (typeof ClipboardItem === "function" && "write" in navigator.clipboard) {
1848
+ void navigator.clipboard.write([
1849
+ new ClipboardItem({
1850
+ "text/plain": text.then((t) => new Blob([t], { type: "text/plain" }))
1851
+ })
1852
+ ]).then(done, () => void text.then((t) => navigator.clipboard.writeText(t)).then(done));
1853
+ return;
1854
+ }
1855
+ void text.then((t) => navigator.clipboard.writeText(t)).then(done);
1856
+ },
1857
+ ...title ? { title } : {},
1858
+ "aria-label": label,
1859
+ className: "shrink-0 rounded p-0.5 text-muted-foreground hover:bg-card hover:text-foreground focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1",
1860
+ children: copied ? /* @__PURE__ */ jsx(Check, { "aria-hidden": true, className: "size-3.5" }) : /* @__PURE__ */ jsx(Copy, { "aria-hidden": true, className: "size-3.5" })
1861
+ }
1862
+ );
1863
+ }
1864
+ function CopyUrlButton({ url, storageUrl }) {
1865
+ const s = useFieldStrings();
1866
+ const resolveShare = useResolveShareUrl();
1867
+ const provide = async () => {
1868
+ if (resolveShare && storageUrl) {
1869
+ const shared = await resolveShare(storageUrl);
1870
+ if (shared) return shared;
1871
+ }
1872
+ return absoluteUrl(url);
1873
+ };
1874
+ return /* @__PURE__ */ jsx(CopyButton, { provide, label: s.copyUrl, title: url });
1875
+ }
1876
+ function absoluteUrl(url) {
1877
+ if (!/^\/(?!\/)/.test(url) || typeof window === "undefined") return url;
1878
+ return `${window.location.origin}${url}`;
1879
+ }
1880
+ function FileRef({
1881
+ url,
1882
+ storageUrl,
1883
+ mimeType,
1884
+ filename
1885
+ }) {
1886
+ const s = useFieldStrings();
1887
+ const encoded = encodedFileSummary(url, s);
1888
+ const label = filename ? filename : encoded ?? pathLabel(url);
1889
+ const reference = encoded ?? url;
1890
+ const title = mimeType ? `${reference} \xB7 ${mimeType}` : reference;
1891
+ const href = viewableUrl(url);
1892
+ return /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-1.5", children: [
1893
+ href ? /* @__PURE__ */ jsx(
1894
+ "a",
1895
+ {
1896
+ href,
1897
+ target: "_blank",
1898
+ rel: "noreferrer",
1899
+ title,
1900
+ className: "min-w-0 truncate font-mono text-[12px] text-foreground underline underline-offset-2",
1901
+ children: label
1902
+ }
1903
+ ) : /* @__PURE__ */ jsx(
1904
+ "span",
1905
+ {
1906
+ title,
1907
+ className: "min-w-0 truncate font-mono text-[12px] text-muted-foreground",
1908
+ children: label
1909
+ }
1910
+ ),
1911
+ /* @__PURE__ */ jsx(CopyUrlButton, { url, ...storageUrl ? { storageUrl } : {} })
1912
+ ] });
1913
+ }
1914
+ function paintable(content, resolve) {
1915
+ const resolved = viewableUrl(resolve?.(content.url));
1916
+ if (resolved) return { url: resolved, fromResolver: true };
1917
+ const stated = viewableUrl(content.publicUrl) ?? viewableUrl(content.url);
1918
+ return stated ? { url: stated, fromResolver: false } : void 0;
1919
+ }
1920
+ function paintableUrl(content, resolve) {
1921
+ return paintable(content, resolve)?.url;
1922
+ }
1923
+ var PREVIEWABLE_EXT_RE = /\.(pdf|png|jpe?g|gif|webp|avif|svg)(\?|#|$)/i;
1924
+ var PREVIEWABLE_MIME_RE = /^(application\/pdf|image\/)/i;
1925
+ function frameableUrl(candidate) {
1926
+ if (!candidate) return void 0;
1927
+ if (/^https?:/.test(candidate.url)) return candidate.url;
1928
+ return candidate.fromResolver && candidate.url.startsWith("/") ? candidate.url : void 0;
1929
+ }
1930
+ function previewableUrl(content, resolve) {
1931
+ const url = frameableUrl(paintable(content, resolve));
1932
+ if (!url) return void 0;
1933
+ const named = content.filename ?? url;
1934
+ const renderable = content.mimeType ? PREVIEWABLE_MIME_RE.test(content.mimeType) : PREVIEWABLE_EXT_RE.test(named);
1935
+ return renderable ? url : void 0;
1936
+ }
1937
+ function DocumentPreview({ url, name }) {
1938
+ return /* @__PURE__ */ jsx(
1939
+ "iframe",
1940
+ {
1941
+ src: url,
1942
+ title: name,
1943
+ loading: "lazy",
1944
+ referrerPolicy: "no-referrer",
1945
+ className: "h-112 w-full rounded-lg border border-border bg-card/40"
1946
+ }
1947
+ );
1948
+ }
1949
+ function DocumentValue({ value }) {
1950
+ const s = useFieldStrings();
1951
+ const resolve = useResolveUrl();
1952
+ const [open, setOpen] = useState(false);
1953
+ const content = readDocumentContent(value);
1954
+ if (!content) return /* @__PURE__ */ jsx(Absent, {});
1955
+ const name = content.title ?? content.filename ?? fileLabel(content.url, content.filename, s);
1956
+ const preview = previewableUrl(content, resolve);
1957
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
1958
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-start gap-2.5", children: [
1959
+ /* @__PURE__ */ jsx(FileText, { "aria-hidden": true, className: "mt-0.5 size-4 shrink-0 text-muted-foreground" }),
1960
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-0.5", children: [
1961
+ name && /* @__PURE__ */ jsx("span", { className: "block truncate text-[13px] text-foreground", children: name }),
1962
+ /* @__PURE__ */ jsx(
1963
+ FileRef,
1964
+ {
1965
+ url: paintableUrl(content, resolve) ?? content.url,
1966
+ storageUrl: content.url,
1967
+ mimeType: content.mimeType,
1968
+ ...content.filename ? { filename: content.filename } : {}
1969
+ }
1970
+ ),
1971
+ content.snippet && /* @__PURE__ */ jsx("p", { className: "line-clamp-2 text-[12px] leading-relaxed text-muted-foreground", children: content.snippet })
1972
+ ] }),
1973
+ preview && /* @__PURE__ */ jsxs(
1974
+ "button",
1975
+ {
1976
+ type: "button",
1977
+ onClick: () => setOpen((current) => !current),
1978
+ "aria-expanded": open,
1979
+ className: "flex shrink-0 items-center gap-1.5 rounded-md border border-border px-2 py-1 text-[12px] text-muted-foreground hover:bg-card hover:text-foreground focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1",
1980
+ children: [
1981
+ open ? /* @__PURE__ */ jsx(EyeOff, { "aria-hidden": true, className: "size-3.5" }) : /* @__PURE__ */ jsx(Eye, { "aria-hidden": true, className: "size-3.5" }),
1982
+ s.preview
1983
+ ]
1984
+ }
1985
+ )
1986
+ ] }),
1987
+ preview && open && /* @__PURE__ */ jsx(DocumentPreview, { url: preview, name })
1988
+ ] });
1989
+ }
1990
+ function ImageValue({
1991
+ value,
1992
+ inGallery = false,
1993
+ inRow = false,
1994
+ compact = false
1995
+ }) {
1996
+ const s = useFieldStrings();
1997
+ const resolve = useResolveUrl();
1998
+ const content = readImageContent(value);
1999
+ if (!content) return /* @__PURE__ */ jsx(Absent, {});
2000
+ const src = paintableUrl(content, resolve);
2001
+ return /* @__PURE__ */ jsxs("div", { className: inGallery ? "space-y-1" : "space-y-1.5", children: [
2002
+ src ? (
2003
+ // Wrapped in a link: the picture is a PREVIEW of a file, and clicking a
2004
+ // preview to see the thing it previews is what a reader expects. The
2005
+ // reference underneath is the other half - a picture with no URL beside
2006
+ // it is a result you can look at and cannot use.
2007
+ /* @__PURE__ */ jsx(
2008
+ "a",
2009
+ {
2010
+ href: src,
2011
+ target: "_blank",
2012
+ rel: "noreferrer",
2013
+ title: content.url,
2014
+ className: inGallery || compact ? "inline-block" : "block w-full",
2015
+ children: /* @__PURE__ */ jsx(
2016
+ LoadingImage,
2017
+ {
2018
+ src,
2019
+ alt: content.caption ?? s.preview,
2020
+ className: cn(
2021
+ inGallery && "block aspect-square w-full object-cover",
2022
+ // A cell is one line tall. An image column rendered at the standalone
2023
+ // height turns every row into a picture and the table into a
2024
+ // slideshow, so a cell gets a thumbnail and the row's expansion gets
2025
+ // the picture.
2026
+ compact && "h-10 w-auto rounded border border-border object-cover",
2027
+ // On its own: the full width it is given, capped generously in
2028
+ // height. `max-h-64` was a 256px thumbnail in a panel several
2029
+ // times that tall — a generated report image is the RESULT here,
2030
+ // not a decoration beside one, and it was unreadable at that size.
2031
+ // `object-contain` keeps the aspect ratio when the cap bites.
2032
+ !inGallery && !compact && "max-h-176 w-full rounded-lg border border-border object-contain"
2033
+ )
2034
+ }
2035
+ )
2036
+ }
2037
+ )
2038
+ ) : inRow ? (
2039
+ // The row variant of "nothing to paint": an icon and a name, exactly as
2040
+ // a document row reads, because that is what this has become.
2041
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2.5", children: [
2042
+ /* @__PURE__ */ jsx(ImageOff, { "aria-hidden": true, className: "size-4 shrink-0 text-muted-foreground" }),
2043
+ /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx(
2044
+ FileRef,
2045
+ {
2046
+ url: content.url,
2047
+ mimeType: content.mimeType,
2048
+ ...content.filename ? { filename: content.filename } : {}
2049
+ }
2050
+ ) })
2051
+ ] })
2052
+ ) : inGallery ? (
2053
+ // Nothing to paint, so the tile says what it is rather than dumping a
2054
+ // ninety-character storage reference into a 140px box. This is what a
2055
+ // host with no resolver sees, so it has to be a design and not a
2056
+ // fallback.
2057
+ /* @__PURE__ */ jsxs("div", { className: "flex aspect-square w-full flex-col items-center justify-center gap-1.5 px-2 text-center", children: [
2058
+ /* @__PURE__ */ jsx(ImageOff, { "aria-hidden": true, className: "size-5 text-muted-foreground" }),
2059
+ /* @__PURE__ */ jsx(
2060
+ "span",
2061
+ {
2062
+ title: content.url,
2063
+ className: "w-full truncate font-mono text-[10.5px] text-muted-foreground",
2064
+ children: fileLabel(content.url, content.filename, s)
2065
+ }
2066
+ )
2067
+ ] })
2068
+ ) : /* @__PURE__ */ jsx(
2069
+ FileRef,
2070
+ {
2071
+ url: content.url,
2072
+ mimeType: content.mimeType,
2073
+ ...content.filename ? { filename: content.filename } : {}
2074
+ }
2075
+ ),
2076
+ src && !compact && /* @__PURE__ */ jsx("div", { className: inGallery ? "px-2.5" : void 0, children: /* @__PURE__ */ jsx(
2077
+ FileRef,
2078
+ {
2079
+ url: src,
2080
+ storageUrl: content.url,
2081
+ mimeType: content.mimeType,
2082
+ ...content.filename ? { filename: content.filename } : {}
2083
+ }
2084
+ ) }),
2085
+ content.caption && /* @__PURE__ */ jsx(
2086
+ "p",
2087
+ {
2088
+ className: cn(
2089
+ "text-[12px] leading-relaxed text-muted-foreground",
2090
+ inGallery && "px-2.5 pb-1.5"
2091
+ ),
2092
+ children: content.caption
2093
+ }
2094
+ )
2095
+ ] });
2096
+ }
2097
+ var TABULAR_KINDS = /* @__PURE__ */ new Set(["text", "number", "boolean", "date", "enum"]);
2098
+ function LeafValue({
2099
+ field,
2100
+ value: raw,
2101
+ compact = false
2102
+ }) {
2103
+ const value = unwrap(field, raw);
2104
+ switch (field.kind) {
2105
+ case "list": {
2106
+ const entries = Array.isArray(value) ? value : [];
2107
+ return TABULAR_KINDS.has(field.item.kind) ? /* @__PURE__ */ jsx(ScalarChips, { field: field.item, items: entries }) : /* @__PURE__ */ jsx(ItemCount, { count: entries.length });
2108
+ }
2109
+ case "prose":
2110
+ return compact ? /* @__PURE__ */ jsx(Scalar, { value, compact: true }) : typeof value === "string" && value !== "" ? /* @__PURE__ */ jsx(Markdown, { text: value }) : /* @__PURE__ */ jsx(Scalar, { value });
2111
+ case "boolean":
2112
+ return /* @__PURE__ */ jsx(Bool, { value, compact });
2113
+ case "date":
2114
+ return /* @__PURE__ */ jsx(DateValue, { value });
2115
+ case "document":
2116
+ return /* @__PURE__ */ jsx(DocumentValue, { value });
2117
+ case "image":
2118
+ return /* @__PURE__ */ jsx(ImageValue, { value, compact });
2119
+ case "object":
2120
+ return compact ? /* @__PURE__ */ jsx(RecordSummary, { field, value }) : /* @__PURE__ */ jsx(Scalar, { value });
2121
+ default:
2122
+ return /* @__PURE__ */ jsx(Scalar, { value, compact });
2123
+ }
2124
+ }
2125
+ function RecordSummary({ field, value }) {
2126
+ const s = useFieldStrings();
2127
+ if (isNativeDateNode(field)) return /* @__PURE__ */ jsx(DateValue, { value });
2128
+ if (!isRecord(value) || Object.keys(value).length === 0) return /* @__PURE__ */ jsx(Absent, {});
2129
+ const naming = isNativeHtmlNode(field) ? void 0 : field.fields.find((member) => member.kind === "text") ?? field.fields.find((member) => member.kind === "prose");
2130
+ if (naming === void 0) {
2131
+ return /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap text-[12.5px] text-muted-foreground", children: s.fieldsCount(field.fields.length) });
2132
+ }
2133
+ return /* @__PURE__ */ jsx(LeafValue, { field: naming, value: ownProp(value, naming.name), compact: true });
2134
+ }
2135
+ function LoadingImage({ src, alt, className }) {
2136
+ const [state, setState] = useState("loading");
2137
+ const [current, setCurrent] = useState(src);
2138
+ if (current !== src) {
2139
+ setCurrent(src);
2140
+ setState("loading");
2141
+ }
2142
+ return /* @__PURE__ */ jsxs("span", { className: "relative block", children: [
2143
+ state === "loading" && /* @__PURE__ */ jsx(
2144
+ "span",
2145
+ {
2146
+ role: "status",
2147
+ "aria-label": alt,
2148
+ className: "absolute inset-0 flex items-center justify-center rounded-lg border border-border bg-card/40",
2149
+ children: /* @__PURE__ */ jsx(Loader2, { "aria-hidden": true, className: "size-4 animate-spin text-muted-foreground" })
2150
+ }
2151
+ ),
2152
+ /* @__PURE__ */ jsx(
2153
+ "img",
2154
+ {
2155
+ src,
2156
+ alt,
2157
+ referrerPolicy: "no-referrer",
2158
+ onLoad: () => setState("done"),
2159
+ onError: () => setState("done"),
2160
+ className: cn(className, state === "loading" && "min-h-40 opacity-0")
2161
+ }
2162
+ )
2163
+ ] });
2164
+ }
2165
+ function ScalarChips({ field, items }) {
2166
+ return (
2167
+ // `data-chips` is the hook the definition grid's value cell reaches through:
2168
+ // the cell ends its VALUE at the right edge, and a row of tags long enough
2169
+ // to wrap fills the column, so without the hook each line of tags would
2170
+ // start at the left while every value beside it ended at the right. The attribute keeps that one selector out of this component's own
2171
+ // class list - chips are laid out the same way everywhere, and only the
2172
+ // caller knows which edge they should end on.
2173
+ /* @__PURE__ */ jsx("div", { "data-chips": true, className: "flex flex-wrap gap-1.5", children: items.map((item, index) => /* @__PURE__ */ jsx(
2174
+ "span",
2175
+ {
2176
+ className: "rounded-md border border-border bg-card/40 px-2 py-0.5 text-[12.5px] text-foreground",
2177
+ children: /* @__PURE__ */ jsx(LeafValue, { field, value: item })
2178
+ },
2179
+ index
2180
+ )) })
2181
+ );
2182
+ }
2183
+ function ItemCount({ count }) {
2184
+ const s = useFieldStrings();
2185
+ return /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap text-[12.5px] text-muted-foreground", children: s.itemsCount(count) });
2186
+ }
2187
+ function isInlineColumn(field) {
2188
+ if (field.kind === "list") return TABULAR_KINDS.has(field.item.kind);
2189
+ return TABULAR_KINDS.has(field.kind);
2190
+ }
2191
+ var CELL_LENGTH_LIMIT = 80;
2192
+ var EXPAND_COLUMN = "2rem";
2193
+ function fitsACellWhole(field) {
2194
+ switch (field.kind) {
2195
+ case "boolean":
2196
+ case "date":
2197
+ case "number":
2198
+ case "enum":
2199
+ return true;
2200
+ case "text":
2201
+ return field.maxLength !== void 0 && field.maxLength <= CELL_LENGTH_LIMIT;
2202
+ case "list":
2203
+ return fitsACellWhole(field.item);
2204
+ default:
2205
+ return false;
2206
+ }
2207
+ }
2208
+ function ObjectTable({
2209
+ columns,
2210
+ element,
2211
+ items,
2212
+ label
2213
+ }) {
2214
+ const s = useFieldStrings();
2215
+ const presentation = useFieldPresentation();
2216
+ const scrollerRef = useRef(null);
2217
+ const [expanded, setExpanded] = useState(() => /* @__PURE__ */ new Set());
2218
+ const [viewportWidth, setViewportWidth] = useState();
2219
+ const canExpand = columns.some((column) => !fitsACellWhole(column));
2220
+ useEffect(() => {
2221
+ const scroller = scrollerRef.current;
2222
+ if (!scroller) return;
2223
+ const measure = () => setViewportWidth(scroller.clientWidth);
2224
+ measure();
2225
+ if (typeof ResizeObserver === "undefined") return;
2226
+ const observer = new ResizeObserver(measure);
2227
+ observer.observe(scroller);
2228
+ return () => observer.disconnect();
2229
+ }, []);
2230
+ const toggle = (index) => setExpanded((current) => {
2231
+ const next = new Set(current);
2232
+ if (!next.delete(index)) next.add(index);
2233
+ return next;
2234
+ });
2235
+ return (
2236
+ // `min-w-full` rather than `w-full`, and a floor under each cell: with
2237
+ // `w-full` the table is pinned to the container's width, so twelve columns
2238
+ // do not overflow - they crush, and a reading's date wraps onto four lines.
2239
+ // A floor makes the table wider than the panel instead, which is what the
2240
+ // scroller is for.
2241
+ //
2242
+ // A scrollable region must be reachable by keyboard. A table of values has
2243
+ // nothing to tab to, so the region itself takes focus; without `tabIndex` the
2244
+ // columns past the fold are reachable with a mouse and by no other means,
2245
+ // which the a11y gate catches as `scrollable-region-focusable`. The name
2246
+ // makes the focus stop announce itself rather than being a silent one.
2247
+ //
2248
+ // `group` rather than `region`, and that is not a detail: `region` is a
2249
+ // LANDMARK, so every table would enter the document's landmark list, and two
2250
+ // of them with the same name - which is what a result rendered twice, or a
2251
+ // structure holding two lists, produces - is `landmark-unique`. A group is
2252
+ // named without claiming to be a section of the page.
2253
+ /* @__PURE__ */ jsx(
2254
+ "div",
2255
+ {
2256
+ ref: scrollerRef,
2257
+ role: "group",
2258
+ "aria-label": label,
2259
+ tabIndex: 0,
2260
+ className: "overflow-x-auto rounded-lg border border-border",
2261
+ children: /* @__PURE__ */ jsxs("table", { className: "w-full min-w-full border-collapse text-[13px]", children: [
2262
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b border-border bg-muted text-left", children: [
2263
+ canExpand && /* @__PURE__ */ jsx("th", { scope: "col", style: { width: EXPAND_COLUMN }, className: "px-1", children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: s.rowDetailsColumn }) }),
2264
+ columns.map((column) => /* @__PURE__ */ jsx(
2265
+ "th",
2266
+ {
2267
+ scope: "col",
2268
+ className: cn(
2269
+ "whitespace-nowrap px-3 py-2 text-[12px] font-semibold text-foreground",
2270
+ presentation === "app" ? void 0 : "font-mono"
2271
+ ),
2272
+ children: /* @__PURE__ */ jsx(Described, { description: column.description, children: fieldLabel(column.title, column.name, presentation) })
2273
+ },
2274
+ column.name
2275
+ ))
2276
+ ] }) }),
2277
+ /* @__PURE__ */ jsx("tbody", { children: items.map((item, index) => {
2278
+ const isOpen = expanded.has(index);
2279
+ return /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsxs("tr", { className: "border-b border-border/60 last:border-b-0", children: [
2280
+ canExpand && /* @__PURE__ */ jsx("td", { className: "px-1 pt-px align-top", children: /* @__PURE__ */ jsx(
2281
+ "button",
2282
+ {
2283
+ type: "button",
2284
+ onClick: () => toggle(index),
2285
+ "aria-expanded": isOpen,
2286
+ "aria-label": s.toggleRowDetails(index + 1),
2287
+ className: "mt-0.5 flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-card hover:text-foreground focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1",
2288
+ children: isOpen ? /* @__PURE__ */ jsx(ChevronDown, { "aria-hidden": true, className: "size-3.5" }) : /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": true, className: "size-3.5" })
2289
+ }
2290
+ ) }),
2291
+ isOpen ? /* @__PURE__ */ jsx("td", { colSpan: columns.length, className: "bg-card/40 p-0", children: /* @__PURE__ */ jsx(
2292
+ "div",
2293
+ {
2294
+ className: "sticky left-0 px-3.5 py-3",
2295
+ ...viewportWidth ? {
2296
+ style: {
2297
+ // Minus the chevron column: this cell starts
2298
+ // after it, so pinning it to the FULL visible
2299
+ // width pushes its right edge that far past the
2300
+ // scroller. See `EXPAND_COLUMN`.
2301
+ width: canExpand ? `calc(${viewportWidth}px - ${EXPAND_COLUMN})` : viewportWidth
2302
+ }
2303
+ } : {},
2304
+ children: /* @__PURE__ */ jsx(ResultField, { field: element, value: item, hideLabel: true })
2305
+ }
2306
+ ) }) : columns.map((column) => {
2307
+ const cell = typeof item === "object" && item !== null ? ownProp(item, column.name) : void 0;
2308
+ return /* @__PURE__ */ jsx("td", { className: "px-3 py-1.5 align-top", children: /* @__PURE__ */ jsx(
2309
+ "div",
2310
+ {
2311
+ className: cn(
2312
+ "max-w-[44ch]",
2313
+ column.kind === "list" && isInlineColumn(column) ? "min-w-[16ch]" : "truncate"
2314
+ ),
2315
+ ...typeof cell === "string" || typeof cell === "number" ? { title: String(cell) } : {},
2316
+ children: /* @__PURE__ */ jsx(LeafValue, { field: column, value: cell, compact: true })
2317
+ }
2318
+ ) }, column.name);
2319
+ })
2320
+ ] }) }, index);
2321
+ }) })
2322
+ ] })
2323
+ }
2324
+ )
2325
+ );
2326
+ }
2327
+ function CompositeValue({ members }) {
2328
+ return /* @__PURE__ */ jsx("div", { className: "space-y-3", children: members.map((member) => /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
2329
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-[12px] font-semibold text-foreground", children: member.name }),
2330
+ /* @__PURE__ */ jsx(NativeValue, { value: member.value })
2331
+ ] }, member.name)) });
2332
+ }
2333
+ function NativeValue({ value }) {
2334
+ if (value === null || value === void 0 || value === "") return /* @__PURE__ */ jsx(Absent, {});
2335
+ const html = readHtmlContent(value);
2336
+ if (html) return /* @__PURE__ */ jsx(HtmlPreview, { content: html });
2337
+ const date = readDateContent(value);
2338
+ if (date) return /* @__PURE__ */ jsx("span", { className: "text-[13px] text-foreground", children: formatDateContent(date) });
2339
+ const document2 = readDocumentContent(value);
2340
+ if (document2?.url !== void 0) {
2341
+ return /* @__PURE__ */ jsx(
2342
+ FileRef,
2343
+ {
2344
+ url: document2.url,
2345
+ ...document2.mimeType !== void 0 ? { mimeType: document2.mimeType } : {},
2346
+ ...document2.filename !== void 0 ? { filename: document2.filename } : {}
2347
+ }
2348
+ );
2349
+ }
2350
+ if (isRecord(value) && Array.isArray(value.items)) {
2351
+ const items = value.items;
2352
+ if (items.length === 0) return /* @__PURE__ */ jsx(Absent, {});
2353
+ return /* @__PURE__ */ jsx("div", { className: "divide-y divide-border/60 overflow-hidden rounded-lg border border-border", children: items.map((item, index) => /* @__PURE__ */ jsx("div", { className: "bg-card/40 px-3 py-1.5", children: /* @__PURE__ */ jsx(NativeValue, { value: item }) }, index)) });
2354
+ }
2355
+ if (isRecord(value)) {
2356
+ const text = value.text;
2357
+ if (typeof text === "string") {
2358
+ return text === "" ? /* @__PURE__ */ jsx(Absent, {}) : /* @__PURE__ */ jsx(Markdown, { text });
2359
+ }
2360
+ }
2361
+ if (typeof value === "string") return /* @__PURE__ */ jsx(Markdown, { text: value });
2362
+ if (typeof value !== "object") return /* @__PURE__ */ jsx(Scalar, { value });
2363
+ return /* @__PURE__ */ jsx(RawValue, { value, compact: false });
2364
+ }
2365
+ function isRecord(value) {
2366
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2367
+ }
2368
+ function ScalarLines({ field, items }) {
2369
+ return /* @__PURE__ */ jsx("div", { className: "divide-y divide-border/60 overflow-hidden rounded-lg border border-border", children: items.map((item, index) => /* @__PURE__ */ jsx("div", { className: "bg-card/40 px-3 py-1.5", children: /* @__PURE__ */ jsx(LeafValue, { field, value: item }) }, index)) });
2370
+ }
2371
+ function ImageGallery({ items }) {
2372
+ const anyViewable = items.some((item) => {
2373
+ const content = readImageContent(item);
2374
+ return content ? !!(viewableUrl(content.publicUrl) ?? viewableUrl(content.url)) : false;
2375
+ });
2376
+ if (!anyViewable) return /* @__PURE__ */ jsx(FileRows, { items, kind: "image" });
2377
+ return /* @__PURE__ */ jsx("div", { className: "grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-2", children: items.map((item, index) => /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-lg border border-border bg-card/40", children: /* @__PURE__ */ jsx(ImageValue, { value: item, inGallery: true }) }, index)) });
2378
+ }
2379
+ function FileRows({ items, kind }) {
2380
+ return /* @__PURE__ */ jsx("div", { className: "divide-y divide-border overflow-hidden rounded-lg border border-border", children: items.map((item, index) => /* @__PURE__ */ jsx("div", { className: "bg-card/40 px-3.5 py-2", children: kind === "document" ? /* @__PURE__ */ jsx(DocumentValue, { value: item }) : /* @__PURE__ */ jsx(ImageValue, { value: item, inRow: true }) }, index)) });
2381
+ }
2382
+ function tableColumns(item) {
2383
+ if (item.kind !== "object" || item.fields.length === 0) return void 0;
2384
+ return item.fields;
2385
+ }
2386
+ function ResultField({ field, value, depth = 0, hideLabel = false }) {
2387
+ const s = useFieldStrings();
2388
+ const unwrapped = unwrap(field, value);
2389
+ const header = hideLabel ? null : /* @__PURE__ */ jsx(Label2, { field, describe: true });
2390
+ const copyText = (field.kind === "text" || field.kind === "prose") && typeof unwrapped === "string" && unwrapped !== "" ? unwrapped : void 0;
2391
+ if (isNativeDateNode(field)) {
2392
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
2393
+ header,
2394
+ /* @__PURE__ */ jsx(DateValue, { value: unwrapped })
2395
+ ] });
2396
+ }
2397
+ if (isNativeHtmlNode(field)) {
2398
+ const content = readHtmlContent(unwrapped);
2399
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
2400
+ header,
2401
+ content ? /* @__PURE__ */ jsx(HtmlPreview, { content }) : /* @__PURE__ */ jsx(Absent, {})
2402
+ ] });
2403
+ }
2404
+ if (isNativeCompositeNode(field)) {
2405
+ const members = readCompositeContent(unwrapped);
2406
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
2407
+ header,
2408
+ members && members.length > 0 ? /* @__PURE__ */ jsx(CompositeValue, { members }) : /* @__PURE__ */ jsx(Absent, {})
2409
+ ] });
2410
+ }
2411
+ switch (field.kind) {
2412
+ case "object": {
2413
+ const memberValue = (child) => typeof unwrapped === "object" && unwrapped !== null ? ownProp(unwrapped, child.name) : void 0;
2414
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
2415
+ header,
2416
+ /* @__PURE__ */ jsx(
2417
+ "div",
2418
+ {
2419
+ className: cn(
2420
+ // A definition grid, not a stack. Label above value spends two
2421
+ // lines on every field, so a structure of ten is twenty lines of
2422
+ // alternating label and answer with nothing aligned. Beside each
2423
+ // other they take one line and the values line up, which is what
2424
+ // makes a record scannable.
2425
+ //
2426
+ // The label column is CAPPED at 40%, and that is not cosmetic. A
2427
+ // bare `auto` sizes to the widest label in the grid - label text
2428
+ // plus its concept pill - so one long field name starved every
2429
+ // value beside it, and inside a 400px panel a paragraph came out
2430
+ // as a ten-line ribbon in a 130px column. `min-content` keeps a
2431
+ // short label short; the cap stops any label taking more than its
2432
+ // share, whatever the panel width turns out to be.
2433
+ "grid grid-cols-[minmax(min-content,40%)_minmax(0,1fr)] items-baseline gap-x-3 gap-y-1.5",
2434
+ // A list item already sits in its own bordered row; nesting a
2435
+ // second card inside it draws a box in a box for no information
2436
+ // gained.
2437
+ !hideLabel && "rounded-lg border border-border bg-card/40 px-3.5 py-3"
2438
+ ),
2439
+ children: field.fields.map(
2440
+ (child) => (
2441
+ // Only a SHORT value shares a line. Prose needs the full width, and
2442
+ // so does anything with chrome of its own - a table, a gallery, a
2443
+ // frame - which beside a label would be squeezed into whatever the
2444
+ // longest label left over.
2445
+ isInlineColumn(child) ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
2446
+ /* @__PURE__ */ jsx("div", { className: "min-w-0", children: /* @__PURE__ */ jsx(Label2, { field: child, describe: true }) }),
2447
+ /* @__PURE__ */ jsx("div", { className: "flex min-w-0 justify-end **:data-chips:justify-end", children: /* @__PURE__ */ jsx("div", { className: "min-w-0 text-left wrap-break-word", children: /* @__PURE__ */ jsx(LeafValue, { field: child, value: memberValue(child) }) }) })
2448
+ ] }, child.name) : /* @__PURE__ */ jsx("div", { className: "col-span-2 min-w-0", children: /* @__PURE__ */ jsx(ResultField, { field: child, value: memberValue(child), depth: depth + 1 }) }, child.name)
2449
+ )
2450
+ )
2451
+ }
2452
+ )
2453
+ ] });
2454
+ }
2455
+ case "list": {
2456
+ const items = Array.isArray(unwrapped) ? unwrapped : [];
2457
+ const columns = tableColumns(field.item);
2458
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
2459
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2", children: [
2460
+ header,
2461
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-[10.5px] text-muted-foreground", children: s.itemsCount(items.length) })
2462
+ ] }),
2463
+ items.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-[13px] italic text-muted-foreground", children: s.noItemsYet }) : columns ? (
2464
+ // Same shape every row: the labels are column headers, not per-row
2465
+ // labels. See `ObjectTable`.
2466
+ /* @__PURE__ */ jsx(
2467
+ ObjectTable,
2468
+ {
2469
+ columns,
2470
+ element: field.item,
2471
+ items,
2472
+ label: field.title ?? humanizeFieldName(field.name)
2473
+ }
2474
+ )
2475
+ ) : TABULAR_KINDS.has(field.item.kind) ? /* @__PURE__ */ jsx(ScalarChips, { field: field.item, items }) : field.item.kind === "prose" || field.item.kind === "unknown" ? (
2476
+ // `unknown` shares the LINES layout, and that is a reading of the
2477
+ // standard rather than a convenience. `unknown` is the deliberate
2478
+ // escape hatch: the producer could not map the node honestly and
2479
+ // said so, which is what an untyped `type = "list"` field derives
2480
+ // to. A card per entry would spend a bordered box and an index on
2481
+ // each value to say nothing extra - the card earns its place around
2482
+ // a STRUCTURE, and this is precisely the node we have been told is
2483
+ // not known to be one. Lines cost nothing and read the same whether
2484
+ // the entries turn out to be words or objects, because `LeafValue`
2485
+ // falls through to `RawValue` either way.
2486
+ /* @__PURE__ */ jsx(ScalarLines, { field: field.item, items })
2487
+ ) : field.item.kind === "image" ? /* @__PURE__ */ jsx(ImageGallery, { items }) : field.item.kind === "document" ? /* @__PURE__ */ jsx(FileRows, { items, kind: "document" }) : (
2488
+ // Nested, or carrying prose: a card per entry is what a table cell
2489
+ // cannot hold. The index label earns its place here, where the
2490
+ // entries are structures rather than values.
2491
+ /* @__PURE__ */ jsx("div", { className: "space-y-2", children: items.map((item, index) => /* @__PURE__ */ jsxs(
2492
+ "div",
2493
+ {
2494
+ className: "space-y-2 rounded-lg border border-border bg-card/40 px-3.5 py-3",
2495
+ children: [
2496
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-[10px] text-muted-foreground", children: index + 1 }),
2497
+ /* @__PURE__ */ jsx(ResultField, { field: field.item, value: item, depth: depth + 1, hideLabel: true })
2498
+ ]
2499
+ },
2500
+ index
2501
+ )) })
2502
+ )
2503
+ ] });
2504
+ }
2505
+ case "boolean":
2506
+ case "date":
2507
+ case "document":
2508
+ case "image":
2509
+ case "text":
2510
+ case "prose":
2511
+ case "number":
2512
+ case "enum":
2513
+ case "unknown":
2514
+ return /* @__PURE__ */ jsxs("div", { className: field.kind === "image" ? "space-y-1.5" : "space-y-0.5", children: [
2515
+ copyText === void 0 ? header : /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
2516
+ /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: header }),
2517
+ /* @__PURE__ */ jsx(CopyButton, { value: copyText, label: s.copyText })
2518
+ ] }),
2519
+ /* @__PURE__ */ jsx(LeafValue, { field, value })
2520
+ ] });
2521
+ }
2522
+ return null;
2523
+ }
2524
+
2525
+ // src/react/download-stuff.ts
2526
+ function saveBlob(blob, filename) {
2527
+ const href = URL.createObjectURL(blob);
2528
+ const anchor = document.createElement("a");
2529
+ anchor.href = href;
2530
+ anchor.download = filename;
2531
+ document.body.appendChild(anchor);
2532
+ anchor.click();
2533
+ anchor.remove();
2534
+ setTimeout(() => URL.revokeObjectURL(href), 0);
2535
+ }
2536
+ function mimeForExtension(extension) {
2537
+ return extension === "html" ? "text/html;charset=utf-8" : "text/plain;charset=utf-8";
2538
+ }
2539
+ function extensionOf(url, filename) {
2540
+ const named = filename?.match(/\.([A-Za-z0-9]{1,8})$/)?.[1];
2541
+ if (named) return named.toLowerCase();
2542
+ const path = url.split(/[?#]/)[0] ?? url;
2543
+ const match = path.match(/\.([A-Za-z0-9]{1,8})$/)?.[1];
2544
+ return match ? match.toLowerCase() : "";
2545
+ }
2546
+ function fileNameFor(file, base) {
2547
+ if (file.filename) return file.filename;
2548
+ const extension = file.extension ?? extensionOf(file.url ?? "", file.filename);
2549
+ const stem = `${base}-${file.path.replace(/\./g, "-")}`;
2550
+ return extension ? `${stem}.${extension}` : stem;
2551
+ }
2552
+ async function downloadStuff({
2553
+ field,
2554
+ value,
2555
+ baseName,
2556
+ resolveUrl
2557
+ }) {
2558
+ const files = collectStuffFiles(field, value);
2559
+ const isBareFile = files.length === 1 && files[0]?.path === field.name;
2560
+ let deliveredAFile = false;
2561
+ for (const file of files) {
2562
+ const name = fileNameFor(file, baseName);
2563
+ if (file.text !== void 0) {
2564
+ saveBlob(new Blob([file.text], { type: mimeForExtension(file.extension) }), name);
2565
+ deliveredAFile = true;
2566
+ continue;
2567
+ }
2568
+ const href = viewableUrl(resolveUrl?.(file.url ?? "")) ?? viewableUrl(file.publicUrl) ?? viewableUrl(file.url);
2569
+ if (!href) continue;
2570
+ try {
2571
+ const response = await fetch(href);
2572
+ if (!response.ok) throw new Error(String(response.status));
2573
+ saveBlob(await response.blob(), name);
2574
+ } catch {
2575
+ window.open(href, "_blank", "noopener");
2576
+ }
2577
+ deliveredAFile = true;
2578
+ }
2579
+ if (isBareFile && deliveredAFile) return;
2580
+ saveBlob(
2581
+ new Blob([JSON.stringify(value, null, 2)], { type: "application/json;charset=utf-8" }),
2582
+ `${baseName}.json`
2583
+ );
2584
+ }
2585
+ var JSON_TOKEN_RE = /("(?:\\.|[^"\\])*"\s*:)|("(?:\\.|[^"\\])*")|(\b(?:true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g;
2586
+ function highlight(json) {
2587
+ const out = [];
2588
+ let last = 0;
2589
+ for (const match of json.matchAll(JSON_TOKEN_RE)) {
2590
+ const [token, key, str, literal] = match;
2591
+ const at = match.index;
2592
+ if (at > last) {
2593
+ out.push(
2594
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: json.slice(last, at) }, `p${last}`)
2595
+ );
2596
+ }
2597
+ out.push(
2598
+ /* @__PURE__ */ jsx(
2599
+ "span",
2600
+ {
2601
+ className: key ? "text-muted-foreground" : str ? "text-foreground" : "font-semibold text-foreground",
2602
+ children: token
2603
+ },
2604
+ at
2605
+ )
2606
+ );
2607
+ last = at + token.length;
2608
+ }
2609
+ if (last < json.length) {
2610
+ out.push(
2611
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: json.slice(last) }, "tail")
2612
+ );
2613
+ }
2614
+ return out;
2615
+ }
2616
+ function JsonView({ value }) {
2617
+ const s = useFieldStrings();
2618
+ const [copied, setCopied] = useState(false);
2619
+ const text = value === null || value === void 0 ? void 0 : typeof value === "object" ? stringifyValue(value) : JSON.stringify(value);
2620
+ if (text === void 0) {
2621
+ return /* @__PURE__ */ jsx(Absent, {});
2622
+ }
2623
+ return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
2624
+ typeof navigator !== "undefined" && navigator.clipboard && /* @__PURE__ */ jsx(
2625
+ "button",
2626
+ {
2627
+ type: "button",
2628
+ onClick: () => {
2629
+ void navigator.clipboard.writeText(text).then(() => {
2630
+ setCopied(true);
2631
+ window.setTimeout(() => setCopied(false), 1500);
2632
+ });
2633
+ },
2634
+ "aria-label": s.copyJson,
2635
+ className: "absolute right-2 top-2 rounded border border-border bg-card p-1 text-muted-foreground hover:text-foreground focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1",
2636
+ children: copied ? /* @__PURE__ */ jsx(Check, { "aria-hidden": true, className: "size-3.5" }) : /* @__PURE__ */ jsx(Copy, { "aria-hidden": true, className: "size-3.5" })
2637
+ }
2638
+ ),
2639
+ /* @__PURE__ */ jsx("pre", { className: "overflow-x-auto rounded-lg border border-border bg-card/40 px-3.5 py-3 pr-12 font-mono text-[12px] leading-relaxed", children: highlight(text) })
2640
+ ] });
2641
+ }
2642
+ function StuffViewer({
2643
+ field,
2644
+ value,
2645
+ name,
2646
+ defaultView = "rendered",
2647
+ downloadBaseName,
2648
+ hideDownload = false,
2649
+ className
2650
+ }) {
2651
+ const s = useFieldStrings();
2652
+ const named = name ? { ...field, name } : field;
2653
+ const [view, setView] = useState(defaultView);
2654
+ const [saving, setSaving] = useState(false);
2655
+ const resolveUrl = useResolveUrl();
2656
+ const handleDownload = useCallback(async () => {
2657
+ setSaving(true);
2658
+ try {
2659
+ await downloadStuff({
2660
+ field,
2661
+ value,
2662
+ baseName: downloadBaseName ?? named.name ?? "result",
2663
+ resolveUrl
2664
+ });
2665
+ } finally {
2666
+ setSaving(false);
2667
+ }
2668
+ }, [field, named.name, value, downloadBaseName, resolveUrl]);
2669
+ const views = [
2670
+ { id: "rendered", label: s.viewRendered },
2671
+ { id: "json", label: s.viewJson }
2672
+ ];
2673
+ return /* @__PURE__ */ jsxs("div", { className: cn("space-y-2", className), children: [
2674
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-start justify-between gap-x-4 gap-y-1", children: [
2675
+ /* @__PURE__ */ jsx("div", { className: "min-w-0 space-y-1", children: /* @__PURE__ */ jsx(ResultHeader, { field: named }) }),
2676
+ /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [
2677
+ !hideDownload && /* @__PURE__ */ jsxs(
2678
+ "button",
2679
+ {
2680
+ type: "button",
2681
+ onClick: () => void handleDownload(),
2682
+ disabled: saving,
2683
+ "aria-label": s.download,
2684
+ className: "inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-[12px] text-muted-foreground hover:text-foreground focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1 disabled:opacity-60",
2685
+ children: [
2686
+ saving ? /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ jsx(Download, { className: "h-3.5 w-3.5" }),
2687
+ saving ? s.downloading : s.download
2688
+ ]
2689
+ }
2690
+ ),
2691
+ /* @__PURE__ */ jsx(
2692
+ "div",
2693
+ {
2694
+ role: "group",
2695
+ "aria-label": s.resultViewGroup,
2696
+ className: "flex rounded-md border border-border p-0.5",
2697
+ children: views.map(({ id, label }) => /* @__PURE__ */ jsx(
2698
+ "button",
2699
+ {
2700
+ type: "button",
2701
+ onClick: () => setView(id),
2702
+ "aria-pressed": view === id,
2703
+ className: cn(
2704
+ "rounded px-2 py-0.5 text-[12px] focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1",
2705
+ view === id ? "bg-card font-medium text-foreground" : "text-muted-foreground hover:text-foreground"
2706
+ ),
2707
+ children: label
2708
+ },
2709
+ id
2710
+ ))
2711
+ }
2712
+ )
2713
+ ] })
2714
+ ] }),
2715
+ view === "json" ? /* @__PURE__ */ jsx(JsonView, { value }) : /* @__PURE__ */ jsx(ResultField, { field, value, hideLabel: true })
2716
+ ] });
2717
+ }
2718
+
2719
+ export { BooleanField, ConceptPill, DEFAULT_FIELD_STRINGS, DateField, DocumentField, EnumField, FieldDomIdProvider, FieldPresentationProvider, FieldRenderer, FieldShell, FieldStringsProvider, HtmlPreview, ImageField, JsonView, ListField, Markdown, NumberField, ObjectField, OptionalToggle, ProseField, ResultEnvProvider, ResultField, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, StuffViewer, Switch, TextField, ToggleGroup, ToggleGroupItem, UnknownField, cn, downloadStuff, fieldControlClass, humanizeFieldName, useFieldDomId, useFieldPresentation, useFieldStrings, useProseImages, useResolveShareUrl, useResolveUrl, useResolvedUrl };
2720
+ //# sourceMappingURL=chunk-KG4IYFWI.js.map
2721
+ //# sourceMappingURL=chunk-KG4IYFWI.js.map