@dudousxd/nestjs-catalog-react 0.4.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useQuery } from '@tanstack/react-query';
3
- import { ArrowLeft, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, Search } from 'lucide-react';
3
+ import { ArrowLeft, ChevronDown, ChevronLeft, ChevronRight, Search } from 'lucide-react';
4
4
  import { useEffect, useMemo, useState } from 'react';
5
5
  import { cn } from './cn';
6
6
  import { catalogQueryKeys, useCatalogClient } from './context';
7
+ import { DataTable } from './ui/data-table';
7
8
  /**
8
9
  * One table for every object type in the catalog.
9
10
  *
@@ -114,6 +115,17 @@ export function ObjectExplorer({ type: typeProp, pageSize = 25, backHref, backLa
114
115
  placeholderData: (previous) => previous,
115
116
  });
116
117
  const selectedType = snapshot?.types.find((t) => t.name === typeName);
118
+ // Derived from what the SERVER said the columns are, not from a type this
119
+ // file knows: the explorer renders whatever was published. The second header
120
+ // line is the physical column name, which is what somebody writing SQL
121
+ // against the same table needs and the display name will not give them.
122
+ const columns = useMemo(() => (data?.columns ?? []).map((column) => ({
123
+ id: column.name,
124
+ accessorFn: (row) => row[column.name],
125
+ header: () => (_jsxs(_Fragment, { children: [_jsxs("span", { children: [column.displayName, column.unit && (_jsxs("span", { className: cn('ml-1 font-mono text-[10px]', MUTED), children: ["(", column.unit, ")"] }))] }), _jsx("div", { className: cn('font-mono text-[10px] font-normal', MUTED), children: column.name })] })),
126
+ cell: (context) => formatCell(context.getValue(), column.type),
127
+ })), [data?.columns]);
128
+ const numericColumns = useMemo(() => new Set((data?.columns ?? []).filter((c) => isNumeric(c.type)).map((c) => c.name)), [data?.columns]);
117
129
  function toggleSort(column) {
118
130
  if (sort === column) {
119
131
  setDir((d) => (d === 'asc' ? 'desc' : 'asc'));
@@ -135,12 +147,7 @@ export function ObjectExplorer({ type: typeProp, pageSize = 25, backHref, backLa
135
147
  setSearch('');
136
148
  }, className: cn('flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm', t.name === typeName
137
149
  ? 'bg-sky-100 dark:bg-sky-950'
138
- : 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx("span", { children: t.icon ?? '◈' }), _jsx("span", { className: "flex-1 truncate", children: t.pluralDisplayName }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: t.tableName })] }, t.name))) }))] }), _jsxs("div", { className: "relative", children: [_jsx(Search, { size: 14, className: cn('pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2', MUTED) }), _jsx("input", { type: "text", value: search, onChange: (e) => setSearch(e.target.value), placeholder: `Search ${selectedType?.pluralDisplayName?.toLowerCase() ?? 'objects'}`, "aria-label": "Search objects", className: cn('w-72 rounded-md border bg-zinc-50 py-2 pl-8 pr-3 text-sm outline-none dark:bg-zinc-950', RULE, 'placeholder:text-zinc-400 focus:border-sky-500 focus:ring-2 focus:ring-sky-500/15') })] })] })] }), _jsxs("div", { className: "min-h-0 flex-1 overflow-auto px-8 py-6", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border transition-opacity', RULE, PANEL, isFetching && 'opacity-60'), children: [_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full min-w-max text-sm", children: [_jsx("thead", { children: _jsx("tr", { className: cn('border-b bg-zinc-50 dark:bg-zinc-950', RULE), children: data?.columns.map((column) => {
139
- const active = sort === column.name;
140
- return (_jsxs("th", { className: cn('whitespace-nowrap px-3 py-2 text-left font-normal', isNumeric(column.type) && 'text-right'), children: [_jsxs("button", { type: "button", onClick: () => toggleSort(column.name), className: cn('group inline-flex items-center gap-1', isNumeric(column.type) && 'flex-row-reverse'), children: [_jsxs("span", { className: cn('text-xs', active
141
- ? 'text-zinc-950 dark:text-zinc-50'
142
- : 'text-zinc-500 dark:text-zinc-400'), children: [column.displayName, column.unit && (_jsxs("span", { className: cn('ml-1 font-mono text-[10px]', MUTED), children: ["(", column.unit, ")"] }))] }), active ? (dir === 'asc' ? (_jsx(ChevronUp, { size: 12 })) : (_jsx(ChevronDown, { size: 12 }))) : (_jsx(ChevronUp, { size: 12, className: "opacity-0 transition-opacity group-hover:opacity-40" }))] }), _jsx("div", { className: cn('font-mono text-[10px] font-normal', MUTED), children: column.name })] }, column.name));
143
- }) }) }), _jsx("tbody", { children: data?.rows.map((row, index) => (_jsx("tr", { className: cn('border-b last:border-0 hover:bg-zinc-50 dark:hover:bg-zinc-950', HAIRLINE), children: data.columns.map((column) => (_jsx("td", { className: cn('whitespace-nowrap px-3 py-2', isNumeric(column.type) && 'text-right font-mono tabular-nums', (row[column.name] === null || row[column.name] === undefined) && MUTED), children: formatCell(row[column.name], column.type) }, column.name))) }, String(row[selectedType?.primaryKey[0] ?? 'id'] ?? index)))) })] }) }), data && data.rows.length === 0 && (_jsx(EmptyState, { type: selectedType, search: debouncedSearch, onClear: () => setSearch('') }))] }), data && data.pages > 1 && (_jsxs("div", { className: "mt-4 flex items-center justify-between", children: [_jsxs("p", { className: cn('font-mono text-[11px]', MUTED), children: ["Page ", data.page, " of ", data.pages] }), _jsxs("div", { className: "flex items-center gap-1", children: [_jsx(PageButton, { onClick: () => setPage((p) => Math.max(1, p - 1)), disabled: data.page <= 1, label: "Previous page", children: _jsx(ChevronLeft, { size: 14 }) }), _jsx(PageButton, { onClick: () => setPage((p) => Math.min(data.pages, p + 1)), disabled: data.page >= data.pages, label: "Next page", children: _jsx(ChevronRight, { size: 14 }) })] })] }))] })] }));
150
+ : 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx("span", { children: t.icon ?? '◈' }), _jsx("span", { className: "flex-1 truncate", children: t.pluralDisplayName }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: t.tableName })] }, t.name))) }))] }), _jsxs("div", { className: "relative", children: [_jsx(Search, { size: 14, className: cn('pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2', MUTED) }), _jsx("input", { type: "text", value: search, onChange: (e) => setSearch(e.target.value), placeholder: `Search ${selectedType?.pluralDisplayName?.toLowerCase() ?? 'objects'}`, "aria-label": "Search objects", className: cn('w-72 rounded-md border bg-zinc-50 py-2 pl-8 pr-3 text-sm outline-none dark:bg-zinc-950', RULE, 'placeholder:text-zinc-400 focus:border-sky-500 focus:ring-2 focus:ring-sky-500/15') })] })] })] }), _jsxs("div", { className: "min-h-0 flex-1 overflow-auto px-8 py-6", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border transition-opacity', RULE, PANEL, isFetching && 'opacity-60'), children: [_jsx(DataTable, { data: data?.rows ?? [], columns: columns, getRowId: (row, index) => String(row[selectedType?.primaryKey[0] ?? 'id'] ?? index), sort: { by: sort ?? null, dir, onSort: toggleSort }, numeric: (id) => numericColumns.has(id) }), data && data.rows.length === 0 && (_jsx(EmptyState, { type: selectedType, search: debouncedSearch, onClear: () => setSearch('') }))] }), data && data.pages > 1 && (_jsxs("div", { className: "mt-4 flex items-center justify-between", children: [_jsxs("p", { className: cn('font-mono text-[11px]', MUTED), children: ["Page ", data.page, " of ", data.pages] }), _jsxs("div", { className: "flex items-center gap-1", children: [_jsx(PageButton, { onClick: () => setPage((p) => Math.max(1, p - 1)), disabled: data.page <= 1, label: "Previous page", children: _jsx(ChevronLeft, { size: 14 }) }), _jsx(PageButton, { onClick: () => setPage((p) => Math.min(data.pages, p + 1)), disabled: data.page >= data.pages, label: "Next page", children: _jsx(ChevronRight, { size: 14 }) })] })] }))] })] }));
144
151
  }
145
152
  function EmptyState({ type, search, onClear, }) {
146
153
  if (search) {
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
3
3
  import { Cable, CircleCheck, CircleX, Code2, KeyRound, Loader2, Play, Plug, Plus, RefreshCw, Trash2, } from 'lucide-react';
4
4
  import { useState } from 'react';
@@ -92,38 +92,52 @@ function ConnectorList({ canEdit }) {
92
92
  * with a blank subtitle — the card said a connector existed and nothing about
93
93
  * where it pointed, which is the one thing the list is for.
94
94
  */
95
+ /** Read a string out of a stored config without believing it is one. */
96
+ function configText(config, key) {
97
+ const value = config[key];
98
+ return typeof value === 'string' ? value : '';
99
+ }
100
+ /** A prefix under a shared bucket, or a bucket of this connector's own. */
101
+ function describeS3Source(config, via) {
102
+ if (via)
103
+ return `${via}${configText(config, 'prefix') || '(whole bucket)'}`;
104
+ const bucket = configText(config, 'bucket');
105
+ if (!bucket)
106
+ return 'no bucket configured';
107
+ return `s3://${bucket}/${configText(config, 'prefix')}`;
108
+ }
109
+ /** The query, shortened to fit a line, plus the watermark when it reads incrementally. */
110
+ function describeSqlSource(config, via) {
111
+ const watermark = configText(config, 'watermarkColumn');
112
+ const query = configText(config, 'query').replace(/\s+/g, ' ').trim();
113
+ const shown = query.length > 70 ? `${query.slice(0, 70)}…` : query;
114
+ return `${via}${watermark ? `${shown} · since ${watermark}` : shown}`;
115
+ }
116
+ /** A path under a shared base URL, or a full URL of this connector's own. */
117
+ function describeHttpSource(config, via) {
118
+ const path = configText(config, 'path');
119
+ if (via)
120
+ return `${via}${path || '/'}`;
121
+ return `${configText(config, 'url')}${path ? ` · ${path}` : ''}`;
122
+ }
95
123
  function describeSource(connector, connection) {
96
124
  const config = connector.config ?? {};
97
- const text = (key) => (typeof config[key] === 'string' ? config[key] : '');
98
125
  // The connection's name first, because when one is in use it is the answer to
99
126
  // "where does this read from" and the connector's own config is only the part
100
127
  // specific to this load.
101
128
  const via = connection ? `${connection.name} · ` : '';
102
- if (connector.kind === 's3') {
103
- const bucket = text('bucket');
104
- if (connection)
105
- return `${via}${text('prefix') || '(whole bucket)'}`;
106
- if (!bucket)
107
- return 'no bucket configured';
108
- return `s3://${bucket}/${text('prefix')}`;
109
- }
110
- if (connector.kind === 'sql') {
111
- const watermark = text('watermarkColumn');
112
- const query = text('query').replace(/\s+/g, ' ').trim();
113
- const shown = query.length > 70 ? `${query.slice(0, 70)}…` : query;
114
- return `${via}${watermark ? `${shown} · since ${watermark}` : shown}`;
115
- }
129
+ if (connector.kind === 's3')
130
+ return describeS3Source(config, via);
131
+ if (connector.kind === 'sql')
132
+ return describeSqlSource(config, via);
116
133
  if (connector.kind === 'file') {
117
- return text('path') || text('url') || 'no path configured';
134
+ return configText(config, 'path') || configText(config, 'url') || 'no path configured';
118
135
  }
119
136
  if (connector.kind === 'inline') {
120
137
  const records = config.records;
121
138
  return `${Array.isArray(records) ? records.length : 0} pasted records`;
122
139
  }
123
- const path = text('path');
124
- if (connection)
125
- return `${via}${path || '/'}`;
126
- return `${text('url')}${path ? ` · ${path}` : ''}`;
140
+ return describeHttpSource(config, via);
127
141
  }
128
142
  function ConnectorCard({ connector, transform, connection, canEdit, running, onRun, onEdit, onDeleted, }) {
129
143
  const client = useCatalogClient();
@@ -145,6 +159,37 @@ function ConnectorCard({ connector, transform, connection, canEdit, running, onR
145
159
  : 'Could not delete it.'
146
160
  : undefined })] }));
147
161
  }
162
+ /**
163
+ * The connection picker, above the address fields it replaces.
164
+ *
165
+ * Offered rather than required: a one-off source does not deserve a second
166
+ * object to manage, and forcing one would make the quickest thing this screen
167
+ * can do — paste a URL, load it once — the slowest.
168
+ */
169
+ function ConnectionPicker({ value, options, viaConnection, onChange, }) {
170
+ return (_jsx(SelectField, { label: "Read through", ariaLabel: "Connection", value: value, onValueChange: onChange, options: [
171
+ {
172
+ value: INLINE_CONNECTION,
173
+ label: 'Configure the address here',
174
+ hint: 'This connector alone',
175
+ },
176
+ ...options,
177
+ ], hint: connectionPickerHint(options.length, viaConnection) }));
178
+ }
179
+ /** Why the picker looks the way it does — nothing to choose, or something chosen. */
180
+ function connectionPickerHint(optionCount, viaConnection) {
181
+ if (optionCount === 0) {
182
+ return 'No connections of this kind yet. One is worth making when a second connector needs the same address.';
183
+ }
184
+ if (viaConnection) {
185
+ return 'The connection supplies the address and the credential. What stays below is only what is specific to this load.';
186
+ }
187
+ return undefined;
188
+ }
189
+ /** Save and cancel, plus whatever the server said when saving failed. */
190
+ function ConnectorFormActions({ editing, pending, incomplete, error, onClose, }) {
191
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "submit", disabled: pending || incomplete, className: "rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: pending ? 'Saving…' : editing ? 'Save changes' : 'Save connector' }), _jsx("button", { type: "button", onClick: onClose, className: cn('rounded-md px-3 py-1.5 text-xs', MUTED), children: "Cancel" })] }), error ? (_jsx("p", { className: "text-[11px] text-red-600", children: error instanceof Error ? error.message : 'Could not save.' })) : null] }));
192
+ }
148
193
  function ConnectorForm({ connector, transforms, connections, onClose, onSaved, }) {
149
194
  const client = useCatalogClient();
150
195
  const [kind, setKind] = useState(toConnectorKind(connector?.kind ?? 'http'));
@@ -210,18 +255,7 @@ function ConnectorForm({ connector, transforms, connections, onClose, onSaved, }
210
255
  return (_jsxs("form", { className: cn('mt-6 space-y-4 rounded-lg border p-4', RULE, PANEL), onSubmit: (event) => {
211
256
  event.preventDefault();
212
257
  save.mutate();
213
- }, children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => setDraft({ ...draft, name }), placeholder: "Nightly fleet load" }), _jsx(TextField, { label: "Target object type", value: draft.targetType, onChange: (targetType) => setDraft({ ...draft, targetType }), placeholder: "e.g. Mvr" }), _jsx(SelectField, { label: "Source kind", ariaLabel: "Source kind", value: kind, onValueChange: (value) => setKind(toConnectorKind(value)), options: KIND_OPTIONS })] }), usesConnection(kind) && (_jsx(SelectField, { label: "Read through", ariaLabel: "Connection", value: chosenConnection, onValueChange: setConnectionId, options: [
214
- {
215
- value: INLINE_CONNECTION,
216
- label: 'Configure the address here',
217
- hint: 'This connector alone',
218
- },
219
- ...connectionOptions,
220
- ], hint: connectionOptions.length === 0
221
- ? 'No connections of this kind yet. One is worth making when a second connector needs the same address.'
222
- : viaConnection
223
- ? 'The connection supplies the address and the credential. What stays below is only what is specific to this load.'
224
- : undefined })), _jsx(SourceFields, { kind: kind, draft: source, onChange: setSource, viaConnection: viaConnection }), _jsx(ReadModeFields, { kind: kind, mode: mode, onModeChange: setMode, draft: source, onChange: setSource }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [!viaConnection && (_jsx(CredentialField, { kind: kind, value: draft.secretEnvVar, onChange: (secretEnvVar) => setDraft({ ...draft, secretEnvVar }) })), _jsx(SelectField, { label: "Transform", ariaLabel: "Transform", value: draft.transformId, onValueChange: (transformId) => setDraft({ ...draft, transformId }), options: [
258
+ }, children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => setDraft({ ...draft, name }), placeholder: "Nightly fleet load" }), _jsx(TextField, { label: "Target object type", value: draft.targetType, onChange: (targetType) => setDraft({ ...draft, targetType }), placeholder: "e.g. Mvr" }), _jsx(SelectField, { label: "Source kind", ariaLabel: "Source kind", value: kind, onValueChange: (value) => setKind(toConnectorKind(value)), options: KIND_OPTIONS })] }), usesConnection(kind) && (_jsx(ConnectionPicker, { value: chosenConnection, options: connectionOptions, viaConnection: viaConnection, onChange: setConnectionId })), _jsx(SourceFields, { kind: kind, draft: source, onChange: setSource, viaConnection: viaConnection }), _jsx(ReadModeFields, { kind: kind, mode: mode, onModeChange: setMode, draft: source, onChange: setSource }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [!viaConnection && (_jsx(CredentialField, { kind: kind, value: draft.secretEnvVar, onChange: (secretEnvVar) => setDraft({ ...draft, secretEnvVar }) })), _jsx(SelectField, { label: "Transform", ariaLabel: "Transform", value: draft.transformId, onValueChange: (transformId) => setDraft({ ...draft, transformId }), options: [
225
259
  {
226
260
  value: '',
227
261
  label: 'No transform',
@@ -232,7 +266,7 @@ function ConnectorForm({ connector, transforms, connections, onClose, onSaved, }
232
266
  label: transform.name,
233
267
  hint: `${transform.language} · v${transform.version}`,
234
268
  })),
235
- ] })] }), _jsx(Switch, { checked: enabled, onCheckedChange: setEnabled, label: "Enabled", hint: "A disabled connector keeps its configuration and its watermark, and refuses to run." }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "submit", disabled: save.isPending || incomplete, className: "rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: save.isPending ? 'Saving…' : connector ? 'Save changes' : 'Save connector' }), _jsx("button", { type: "button", onClick: onClose, className: cn('rounded-md px-3 py-1.5 text-xs', MUTED), children: "Cancel" })] }), save.error && (_jsx("p", { className: "text-[11px] text-red-600", children: save.error instanceof Error ? save.error.message : 'Could not save.' }))] }));
269
+ ] })] }), _jsx(Switch, { checked: enabled, onCheckedChange: setEnabled, label: "Enabled", hint: "A disabled connector keeps its configuration and its watermark, and refuses to run." }), _jsx(ConnectorFormActions, { editing: connector !== undefined, pending: save.isPending, incomplete: incomplete, error: save.error, onClose: onClose })] }));
236
270
  }
237
271
  function TransformList({ canEdit, languages, pythonPackages, }) {
238
272
  const client = useCatalogClient();
@@ -1,11 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useMutation, useQuery } from '@tanstack/react-query';
3
3
  import { AlertTriangle, History, Layers, Play, Sparkles, TableIcon } from 'lucide-react';
4
- import { Highlight, themes } from 'prism-react-renderer';
5
4
  import { useMemo, useRef, useState } from 'react';
6
5
  import { SavedQueryPanel } from './SavedQueryPanel';
7
6
  import { cn } from './cn';
8
7
  import { useCatalogClient } from './context';
8
+ import { CodeEditor } from './ui/code-editor';
9
+ import { DataTable, renderUnknown } from './ui/data-table';
9
10
  import { Tooltip, TooltipProvider } from './ui/tooltip';
10
11
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
11
12
  const PANEL = 'bg-white dark:bg-zinc-900';
@@ -23,6 +24,19 @@ const STARTER = `-- Two relations per object type, and the difference is the poi
23
24
  -- SELECT _snapshot_id, AVG(\`Risk Score\`) FROM obj_mvr GROUP BY _snapshot_id
24
25
 
25
26
  SELECT * FROM `;
27
+ /**
28
+ * Turn a sentence into SQL, and say what the assistant was shown.
29
+ *
30
+ * The note about relation and column names is not decoration: somebody typing a
31
+ * question here is entitled to know that the rows never left the database, and
32
+ * that what comes back is a draft to read rather than a result to trust.
33
+ */
34
+ function AskAssistantPanel({ prompt, onPromptChange, pending, error, onSubmit, }) {
35
+ return (_jsxs("div", { className: cn('shrink-0 border-b bg-sky-50/60 px-4 py-3 dark:bg-sky-950/20', RULE), children: [_jsxs("form", { className: "flex gap-2", onSubmit: (e) => {
36
+ e.preventDefault();
37
+ onSubmit();
38
+ }, children: [_jsx("input", { value: prompt, onChange: (e) => onPromptChange(e.target.value), placeholder: "Which vehicles gained the most work orders since the last load?", "aria-label": "Describe the query", className: cn('flex-1 rounded-md border px-3 py-1.5 text-sm outline-none', RULE, PANEL, 'focus:border-sky-500 focus:ring-2 focus:ring-sky-500/15') }), _jsx("button", { type: "submit", disabled: pending || prompt.trim().length === 0, className: "rounded-md bg-sky-600 px-3 py-1.5 text-xs text-white disabled:opacity-40", children: pending ? 'Writing…' : 'Write the SQL' })] }), _jsx("p", { className: cn('mt-1.5 text-[11px]', MUTED), children: "It sees the relation and column names above, never the rows. Read the SQL before running it." }), error ? (_jsx("p", { className: "mt-1 text-[11px] text-red-600", children: error instanceof Error ? error.message : 'The assistant could not write that.' })) : null] }));
39
+ }
26
40
  export function QueryConsole({ onGenerate, maxRows = 500 }) {
27
41
  const client = useCatalogClient();
28
42
  const [sql, setSql] = useState(STARTER);
@@ -82,12 +96,7 @@ export function QueryConsole({ onGenerate, maxRows = 500 }) {
82
96
  // Tab still moves focus; indentation is Shift-agnostic two spaces on Enter.
83
97
  }
84
98
  const error = run.error instanceof Error ? run.error.message : null;
85
- return (_jsx(TooltipProvider, { children: _jsxs("div", { className: "flex h-full min-h-0", children: [_jsxs("aside", { className: cn('flex w-64 shrink-0 flex-col border-r', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-2', RULE), children: _jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Relations" }) }), _jsxs("div", { className: "min-h-0 flex-1 overflow-y-auto p-2", children: [grouped.length === 0 && (_jsx("p", { className: cn('px-2 py-6 text-center text-xs', MUTED), children: "Nothing has been published yet." })), grouped.map(([objectType, list]) => (_jsxs("div", { className: "mb-3", children: [_jsx("div", { className: cn('px-2 py-1 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: objectType }), list.map((relation) => (_jsx(RelationRow, { relation: relation, onInsert: insert }, relation.name)))] }, objectType)))] }), _jsx(SavedQueryPanel, { currentSql: sql, onLoad: (query) => setSql(query.sql) })] }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsxs("div", { className: cn('flex shrink-0 items-center gap-2 border-b px-4 py-2', RULE, PANEL), children: [_jsxs("button", { type: "button", onClick: () => run.mutate(), disabled: run.isPending, className: "flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 transition-colors hover:bg-zinc-800 disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-950", children: [_jsx(Play, { size: 12 }), run.isPending ? 'Running…' : 'Run'] }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: "\u2318\u21B5" }), onGenerate && (_jsxs("button", { type: "button", onClick: () => setAskOpen((open) => !open), className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs transition-colors', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800', askOpen && 'bg-sky-100 dark:bg-sky-950'), children: [_jsx(Sparkles, { size: 12 }), "Ask"] })), run.data && (_jsxs("span", { className: cn('ml-auto font-mono text-[11px]', MUTED), children: [run.data.rowCount, " rows \u00B7 ", run.data.cached ? 'cached' : `${run.data.elapsedMs} ms`, run.data.truncated && ' · capped'] }))] }), askOpen && onGenerate && (_jsxs("div", { className: cn('shrink-0 border-b bg-sky-50/60 px-4 py-3 dark:bg-sky-950/20', RULE), children: [_jsxs("form", { className: "flex gap-2", onSubmit: (e) => {
86
- e.preventDefault();
87
- generate.mutate();
88
- }, children: [_jsx("input", { value: prompt, onChange: (e) => setPrompt(e.target.value), placeholder: "Which vehicles gained the most work orders since the last load?", "aria-label": "Describe the query", className: cn('flex-1 rounded-md border px-3 py-1.5 text-sm outline-none', RULE, PANEL, 'focus:border-sky-500 focus:ring-2 focus:ring-sky-500/15') }), _jsx("button", { type: "submit", disabled: generate.isPending || prompt.trim().length === 0, className: "rounded-md bg-sky-600 px-3 py-1.5 text-xs text-white disabled:opacity-40", children: generate.isPending ? 'Writing…' : 'Write the SQL' })] }), _jsx("p", { className: cn('mt-1.5 text-[11px]', MUTED), children: "It sees the relation and column names above, never the rows. Read the SQL before running it." }), generate.error && (_jsx("p", { className: "mt-1 text-[11px] text-red-600", children: generate.error instanceof Error
89
- ? generate.error.message
90
- : 'The assistant could not write that.' }))] })), _jsx(SqlEditor, { value: sql, onChange: setSql, onKeyDown: onEditorKeyDown, textareaRef: editorRef }), _jsxs("div", { className: "min-h-0 flex-1 overflow-auto", children: [error && (_jsxs("div", { className: "m-4 flex items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300", children: [_jsx(AlertTriangle, { size: 14, className: "mt-0.5 shrink-0" }), _jsx("span", { className: "font-mono leading-relaxed", children: error })] })), run.data && _jsx(ResultTable, { result: run.data }), !run.data && !error && (_jsx("p", { className: cn('p-8 text-center text-sm', MUTED), children: "Results appear here." }))] })] })] }) }));
99
+ return (_jsx(TooltipProvider, { children: _jsxs("div", { className: "flex h-full min-h-0", children: [_jsxs("aside", { className: cn('flex w-64 shrink-0 flex-col border-r', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-2', RULE), children: _jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Relations" }) }), _jsxs("div", { className: "min-h-0 flex-1 overflow-y-auto p-2", children: [grouped.length === 0 && (_jsx("p", { className: cn('px-2 py-6 text-center text-xs', MUTED), children: "Nothing has been published yet." })), grouped.map(([objectType, list]) => (_jsxs("div", { className: "mb-3", children: [_jsx("div", { className: cn('px-2 py-1 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: objectType }), list.map((relation) => (_jsx(RelationRow, { relation: relation, onInsert: insert }, relation.name)))] }, objectType)))] }), _jsx(SavedQueryPanel, { currentSql: sql, onLoad: (query) => setSql(query.sql) })] }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsxs("div", { className: cn('flex shrink-0 items-center gap-2 border-b px-4 py-2', RULE, PANEL), children: [_jsxs("button", { type: "button", onClick: () => run.mutate(), disabled: run.isPending, className: "flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 transition-colors hover:bg-zinc-800 disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-950", children: [_jsx(Play, { size: 12 }), run.isPending ? 'Running…' : 'Run'] }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: "\u2318\u21B5" }), onGenerate && (_jsxs("button", { type: "button", onClick: () => setAskOpen((open) => !open), className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs transition-colors', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800', askOpen && 'bg-sky-100 dark:bg-sky-950'), children: [_jsx(Sparkles, { size: 12 }), "Ask"] })), run.data && (_jsxs("span", { className: cn('ml-auto font-mono text-[11px]', MUTED), children: [run.data.rowCount, " rows \u00B7 ", run.data.cached ? 'cached' : `${run.data.elapsedMs} ms`, run.data.truncated && ' · capped'] }))] }), askOpen && onGenerate && (_jsx(AskAssistantPanel, { prompt: prompt, onPromptChange: setPrompt, pending: generate.isPending, error: generate.error, onSubmit: () => generate.mutate() })), _jsx(SqlEditor, { value: sql, onChange: setSql, onKeyDown: onEditorKeyDown, textareaRef: editorRef }), _jsxs("div", { className: "min-h-0 flex-1 overflow-auto", children: [error && (_jsxs("div", { className: "m-4 flex items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300", children: [_jsx(AlertTriangle, { size: 14, className: "mt-0.5 shrink-0" }), _jsx("span", { className: "font-mono leading-relaxed", children: error })] })), run.data && _jsx(ResultTable, { result: run.data }), !run.data && !error && (_jsx("p", { className: cn('p-8 text-center text-sm', MUTED), children: "Results appear here." }))] })] })] }) }));
91
100
  }
92
101
  function RelationRow({ relation, onInsert, }) {
93
102
  const [open, setOpen] = useState(false);
@@ -103,42 +112,26 @@ function RelationRow({ relation, onInsert, }) {
103
112
  * contenteditable would look the same and lose all of it.
104
113
  */
105
114
  function SqlEditor({ value, onChange, onKeyDown, textareaRef, }) {
106
- const shared = 'm-0 p-4 font-mono text-[13px] leading-[1.55] whitespace-pre-wrap break-words';
107
- return (
108
- // Two boxes, and the division between them is the whole point.
109
- //
110
- // The outer one is the *only* thing that scrolls. The inner one has no
111
- // height of its own, so it grows to whatever the highlighted code needs —
112
- // which is what lets the textarea be `inset-0` and still cover every line
113
- // rather than only the visible ones.
114
- //
115
- // Both used to scroll: the textarea was pinned to the outer box's visible
116
- // area with `overflow: auto` of its own, so a long query produced two
117
- // scrollbars, and scrolling the outer one left the caret sitting over the
118
- // wrong line because the highlight moved and the input did not.
119
- _jsx("div", { className: cn('relative h-56 shrink-0 overflow-auto border-b', RULE, PANEL), children: _jsxs("div", { className: "relative min-h-full w-full", children: [_jsx(Highlight, { code: value, language: "sql", theme: themes.github, children: ({ tokens, getLineProps, getTokenProps }) => (_jsx("pre", { className: cn(shared, 'pointer-events-none min-h-full'), "aria-hidden": true, children: tokens.map((line, i) => (
120
- // biome-ignore lint/suspicious/noArrayIndexKey: lines have no id
121
- _jsx("div", { ...getLineProps({ line }), children: line.map((token, key) => (
122
- // biome-ignore lint/suspicious/noArrayIndexKey: tokens have no id
123
- _jsx("span", { ...getTokenProps({ token }) }, key))) }, i))) })) }), _jsx("textarea", { ref: textareaRef, value: value, onChange: (e) => onChange(e.target.value), onKeyDown: onKeyDown, spellCheck: false, "aria-label": "SQL query", className: cn(shared,
124
- // `overflow-hidden`, not `auto`: this layer is as tall as the code it
125
- // holds, so it has nothing to scroll — and giving it the option back
126
- // is what produced the second scrollbar.
127
- 'absolute inset-0 h-full w-full resize-none overflow-hidden bg-transparent', 'text-transparent caret-zinc-900 outline-none dark:caret-zinc-100') })] }) }));
115
+ return (_jsx(CodeEditor, { value: value, onChange: onChange, onKeyDown: onKeyDown, textareaRef: textareaRef, language: "sql", label: "SQL query",
116
+ // Roomier than the transform pane: this is the screen's primary input,
117
+ // not a side panel.
118
+ className: cn('h-56 shrink-0 border-b', RULE, PANEL), padding: "p-4", fontSize: "text-[13px]" }));
128
119
  }
129
120
  function ResultTable({ result }) {
130
- if (result.rowCount === 0) {
131
- return (_jsx("p", { className: cn('p-8 text-center text-sm', MUTED), children: "The query ran and matched nothing." }));
132
- }
133
- return (_jsxs("div", { className: "p-4", children: [result.truncated && (_jsxs("p", { className: "mb-2 text-[11px] text-amber-600", children: ["Showing the first ", result.rowCount, " rows. Add a LIMIT or an aggregate to see a complete answer."] })), _jsx("div", { className: cn('overflow-x-auto rounded-lg border', RULE, PANEL), children: _jsxs("table", { className: "w-full min-w-max text-sm", children: [_jsx("thead", { children: _jsx("tr", { className: cn('border-b bg-zinc-50 dark:bg-zinc-950', RULE), children: result.columns.map((column) => (_jsx("th", { className: cn('whitespace-nowrap px-3 py-2 text-left font-mono text-[10px] font-normal uppercase tracking-[0.12em]', MUTED), children: column }, column))) }) }), _jsx("tbody", { children: result.rows.map((row, index) => (
134
- // biome-ignore lint/suspicious/noArrayIndexKey: arbitrary SQL has no key
135
- _jsx("tr", { className: "border-b border-zinc-100 last:border-0 dark:border-zinc-900", children: result.columns.map((column) => {
136
- const value = row[column];
137
- const numeric = typeof value === 'number';
138
- return (_jsx("td", { className: cn('whitespace-nowrap px-3 py-1.5', numeric && 'text-right font-mono tabular-nums', (value === null || value === undefined) && MUTED), children: value === null || value === undefined
139
- ? '—'
140
- : typeof value === 'object'
141
- ? JSON.stringify(value)
142
- : String(value) }, column));
143
- }) }, index))) })] }) })] }));
121
+ // Built from the answer, because the answer decides them: a free SQL query
122
+ // returns whatever columns it returns, and there is no type to derive them
123
+ // from ahead of time.
124
+ const columns = useMemo(() => result.columns.map((column) => ({
125
+ id: column,
126
+ accessorFn: (row) => row[column],
127
+ header: column,
128
+ cell: (context) => renderUnknown(context.getValue()),
129
+ })), [result.columns]);
130
+ // Whether a column is numeric is a property of the DATA here, not of a
131
+ // schema — the first row is the only thing available to ask.
132
+ const numericColumns = useMemo(() => {
133
+ const first = result.rows[0];
134
+ return new Set(first ? result.columns.filter((column) => typeof first[column] === 'number') : []);
135
+ }, [result.columns, result.rows]);
136
+ return (_jsxs("div", { className: "p-4", children: [result.truncated && (_jsxs("p", { className: "mb-2 text-[11px] text-amber-600", children: ["Showing the first ", result.rowCount, " rows. Add a LIMIT or an aggregate to see a complete answer."] })), _jsx(DataTable, { data: result.rows, columns: columns, numeric: (id) => numericColumns.has(id), className: cn('rounded-lg border', RULE, PANEL), empty: _jsx("p", { className: cn('p-8 text-center text-sm', MUTED), children: "The query ran and matched nothing." }) })] }));
144
137
  }
@@ -11,13 +11,4 @@ export interface TransformEditorProps {
11
11
  onClose: () => void;
12
12
  onSaved: () => void;
13
13
  }
14
- /**
15
- * Write the code, and run it against a couple of records before it ever touches
16
- * a load.
17
- *
18
- * The try pane is the point of this screen. A transform is the one place where
19
- * somebody's typo silently reshapes stored data, and the difference between a
20
- * transform you can iterate on and one you can only test in production is
21
- * whether you can see its output beside its input.
22
- */
23
14
  export declare function TransformEditor({ transform, languages, pythonPackages, onClose, onSaved, }: TransformEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -2,10 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { isTransformLanguage } from '@dudousxd/nestjs-catalog/client';
3
3
  import { useMutation } from '@tanstack/react-query';
4
4
  import { ArrowLeft, Play } from 'lucide-react';
5
- import { Highlight, themes } from 'prism-react-renderer';
6
5
  import { useRef, useState } from 'react';
7
6
  import { cn } from './cn';
8
7
  import { useCatalogClient } from './context';
8
+ import { CodeEditor } from './ui/code-editor';
9
9
  import { TextField } from './ui/field';
10
10
  import { SelectField } from './ui/select';
11
11
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
@@ -60,6 +60,28 @@ const SAMPLE = `[
60
60
  * transform you can iterate on and one you can only test in production is
61
61
  * whether you can see its output beside its input.
62
62
  */
63
+ /**
64
+ * What the last run produced: its logs, its rows, or why it failed.
65
+ *
66
+ * An empty result is said out loud rather than shown as `[]`. Two characters in
67
+ * a scroll pane read as "nothing happened yet", and the run that produced no
68
+ * rows is exactly the one somebody needs to notice — a connector using this
69
+ * transform would commit an empty snapshot.
70
+ */
71
+ function TryOutput({ result, error }) {
72
+ return (_jsxs("div", { className: "max-h-64 overflow-auto p-3", children: [error ? (_jsx("p", { className: "font-mono text-[11px] leading-relaxed text-red-600", children: error instanceof Error ? error.message : 'It failed.' })) : null, result && (_jsxs(_Fragment, { children: [result.logs.length > 0 && (_jsx("pre", { className: cn('mb-2 whitespace-pre-wrap font-mono text-[10px]', MUTED), children: result.logs.join('\n') })), result.rows.length === 0 ? (_jsx("p", { className: "text-[11px] text-amber-600", children: "It ran and returned no rows. A connector using this would commit an empty snapshot." })) : (_jsx("pre", { className: "whitespace-pre-wrap font-mono text-[11px]", children: JSON.stringify(result.rows, null, 2) })), _jsxs("p", { className: cn('mt-2 font-mono text-[10px]', MUTED), children: [result.rows.length, " rows \u00B7 ", result.elapsedMs, "ms"] })] })), !result && !error && (_jsx("p", { className: cn('py-4 text-center text-[11px]', MUTED), children: "Run it to see what it produces." }))] }));
73
+ }
74
+ /**
75
+ * Save, and what saving will do.
76
+ *
77
+ * The version note is beside the button rather than in a confirmation, because
78
+ * saving new code always cuts a version — that is how a running connector keeps
79
+ * the code it was pinned to — and it should be visible before the click, not
80
+ * explained after it.
81
+ */
82
+ function SaveBar({ transform, nameIsEmpty, pending, error, onSave, }) {
83
+ return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "button", onClick: onSave, disabled: pending || nameIsEmpty, className: cn('rounded-md border px-3 py-1.5 text-xs disabled:opacity-40', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: pending ? 'Saving…' : transform ? 'Save changes' : 'Save transform' }), transform && (_jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: ["saving new code makes this v", transform.version + 1] })), error ? (_jsx("span", { className: "text-[11px] text-red-600", children: error instanceof Error ? error.message : 'Could not save.' })) : null] }));
84
+ }
63
85
  export function TransformEditor({ transform, languages, pythonPackages = [], onClose, onSaved, }) {
64
86
  const client = useCatalogClient();
65
87
  const [name, setName] = useState(transform?.name ?? '');
@@ -116,14 +138,5 @@ export function TransformEditor({ transform, languages, pythonPackages = [], onC
116
138
  label: option,
117
139
  })) })] }), _jsxs("div", { className: "grid gap-3 lg:grid-cols-2", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsxs("div", { className: cn('flex items-center justify-between border-b px-3 py-1.5', RULE), children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Code" }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: language === 'python' && pythonPackages.length > 0
118
140
  ? `imports: ${pythonPackages.join(', ')}`
119
- : '⌘↵ to try' })] }), _jsx(CodePane, { value: code, onChange: setCode, onKeyDown: onKeyDown, language: language === 'python' ? 'python' : 'tsx', textareaRef: editorRef })] }), _jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Sample records" }) }), _jsx("textarea", { value: sample, onChange: (event) => setSample(event.target.value), "aria-label": "Sample records", spellCheck: false, className: "h-32 w-full resize-none bg-transparent p-3 font-mono text-[12px] outline-none" })] }), _jsxs("button", { type: "button", onClick: () => tryIt.mutate(), disabled: tryIt.isPending, className: "flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: [_jsx(Play, { size: 12 }), tryIt.isPending ? 'Running…' : 'Try it'] }), _jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Output" }) }), _jsxs("div", { className: "max-h-64 overflow-auto p-3", children: [tryIt.error && (_jsx("p", { className: "font-mono text-[11px] leading-relaxed text-red-600", children: tryIt.error instanceof Error ? tryIt.error.message : 'It failed.' })), tryIt.data && (_jsxs(_Fragment, { children: [tryIt.data.logs.length > 0 && (_jsx("pre", { className: cn('mb-2 whitespace-pre-wrap font-mono text-[10px]', MUTED), children: tryIt.data.logs.join('\n') })), tryIt.data.rows.length === 0 ? (_jsx("p", { className: "text-[11px] text-amber-600", children: "It ran and returned no rows. A connector using this would commit an empty snapshot." })) : (_jsx("pre", { className: "whitespace-pre-wrap font-mono text-[11px]", children: JSON.stringify(tryIt.data.rows, null, 2) })), _jsxs("p", { className: cn('mt-2 font-mono text-[10px]', MUTED), children: [tryIt.data.rows.length, " rows \u00B7 ", tryIt.data.elapsedMs, "ms"] })] })), !tryIt.data && !tryIt.error && (_jsx("p", { className: cn('py-4 text-center text-[11px]', MUTED), children: "Run it to see what it produces." }))] })] })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "button", onClick: () => save.mutate(), disabled: save.isPending || name.trim().length === 0, className: cn('rounded-md border px-3 py-1.5 text-xs disabled:opacity-40', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: save.isPending ? 'Saving…' : transform ? 'Save changes' : 'Save transform' }), transform && (_jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: ["saving new code makes this v", transform.version + 1] })), save.error && (_jsx("span", { className: "text-[11px] text-red-600", children: save.error instanceof Error ? save.error.message : 'Could not save.' }))] })] }));
120
- }
121
- /** A textarea under a highlighted `<pre>`, the same shape the query editor uses. */
122
- function CodePane({ value, onChange, onKeyDown, language, textareaRef, }) {
123
- const shared = 'm-0 p-3 font-mono text-[12px] leading-[1.5] whitespace-pre-wrap break-words';
124
- return (_jsxs("div", { className: "relative h-72 overflow-auto", children: [_jsx(Highlight, { code: value, language: language, theme: themes.github, children: ({ tokens, getLineProps, getTokenProps }) => (_jsx("pre", { className: cn(shared, 'pointer-events-none min-h-full'), "aria-hidden": true, children: tokens.map((line, i) => (
125
- // biome-ignore lint/suspicious/noArrayIndexKey: lines have no id
126
- _jsx("div", { ...getLineProps({ line }), children: line.map((token, key) => (
127
- // biome-ignore lint/suspicious/noArrayIndexKey: tokens have no id
128
- _jsx("span", { ...getTokenProps({ token }) }, key))) }, i))) })) }), _jsx("textarea", { ref: textareaRef, value: value, onChange: (event) => onChange(event.target.value), onKeyDown: onKeyDown, spellCheck: false, "aria-label": "Transform code", className: cn(shared, 'absolute inset-0 h-full w-full resize-none bg-transparent', 'text-transparent caret-zinc-900 outline-none dark:caret-zinc-100') })] }));
141
+ : '⌘↵ to try' })] }), _jsx(CodeEditor, { value: code, onChange: setCode, onKeyDown: onKeyDown, language: language === 'python' ? 'python' : 'tsx', label: "Transform code", textareaRef: editorRef, className: "h-72" })] }), _jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Sample records" }) }), _jsx(CodeEditor, { value: sample, onChange: setSample, language: "json", label: "Sample records", className: "h-32" })] }), _jsxs("button", { type: "button", onClick: () => tryIt.mutate(), disabled: tryIt.isPending, className: "flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: [_jsx(Play, { size: 12 }), tryIt.isPending ? 'Running…' : 'Try it'] }), _jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Output" }) }), _jsx(TryOutput, { result: tryIt.data, error: tryIt.error })] })] })] }), _jsx(SaveBar, { transform: transform, nameIsEmpty: name.trim().length === 0, pending: save.isPending, error: save.error, onSave: () => save.mutate() })] }));
129
142
  }