glacia-native 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -7
- package/README.md +178 -0
- package/lib/module/Dialog.js +128 -0
- package/lib/module/Form.js +125 -0
- package/lib/module/Input.js +64 -0
- package/lib/module/Table.js +81 -0
- package/lib/module/ai.js +246 -0
- package/lib/module/charts/AreaChart.js +32 -0
- package/lib/module/charts/BarChart.js +65 -0
- package/lib/module/charts/FunnelChart.js +48 -0
- package/lib/module/charts/HeatmapChart.js +69 -0
- package/lib/module/charts/LineChart.js +79 -0
- package/lib/module/charts/PlotChart.js +44 -0
- package/lib/module/charts/RadarChart.js +76 -0
- package/lib/module/charts/RingChart.js +50 -0
- package/lib/module/charts/ScatterChart.js +78 -0
- package/lib/module/charts/WaterfallChart.js +76 -0
- package/lib/module/charts/advanced.js +307 -0
- package/lib/module/charts/extra.js +105 -0
- package/lib/module/charts/index.js +50 -0
- package/lib/module/charts/primitives.js +212 -0
- package/lib/module/charts/scales.js +140 -0
- package/lib/module/index.js +48 -1
- package/lib/module/internal/tokens.js +3 -0
- package/lib/typescript/Dialog.d.ts +71 -0
- package/lib/typescript/Form.d.ts +81 -0
- package/lib/typescript/Input.d.ts +47 -0
- package/lib/typescript/Table.d.ts +55 -0
- package/lib/typescript/ai.d.ts +163 -0
- package/lib/typescript/charts/AreaChart.d.ts +44 -0
- package/lib/typescript/charts/BarChart.d.ts +19 -0
- package/lib/typescript/charts/FunnelChart.d.ts +25 -0
- package/lib/typescript/charts/HeatmapChart.d.ts +23 -0
- package/lib/typescript/charts/LineChart.d.ts +30 -0
- package/lib/typescript/charts/PlotChart.d.ts +31 -0
- package/lib/typescript/charts/RadarChart.d.ts +27 -0
- package/lib/typescript/charts/RingChart.d.ts +28 -0
- package/lib/typescript/charts/ScatterChart.d.ts +34 -0
- package/lib/typescript/charts/WaterfallChart.d.ts +22 -0
- package/lib/typescript/charts/advanced.d.ts +107 -0
- package/lib/typescript/charts/extra.d.ts +63 -0
- package/lib/typescript/charts/index.d.ts +13 -0
- package/lib/typescript/charts/primitives.d.ts +23 -0
- package/lib/typescript/charts/scales.d.ts +35 -0
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/internal/tokens.d.ts +2 -0
- package/package.json +10 -3
- package/src/Dialog.tsx +345 -0
- package/src/Form.tsx +360 -0
- package/src/Input.tsx +172 -0
- package/src/Table.tsx +207 -0
- package/src/ai.tsx +655 -0
- package/src/charts/AreaChart.tsx +73 -0
- package/src/charts/BarChart.tsx +181 -0
- package/src/charts/FunnelChart.tsx +123 -0
- package/src/charts/HeatmapChart.tsx +153 -0
- package/src/charts/LineChart.tsx +245 -0
- package/src/charts/PlotChart.tsx +148 -0
- package/src/charts/RadarChart.tsx +206 -0
- package/src/charts/RingChart.tsx +131 -0
- package/src/charts/ScatterChart.tsx +202 -0
- package/src/charts/WaterfallChart.tsx +183 -0
- package/src/charts/advanced.tsx +670 -0
- package/src/charts/extra.tsx +239 -0
- package/src/charts/index.ts +86 -0
- package/src/charts/primitives.ts +262 -0
- package/src/charts/scales.ts +163 -0
- package/src/index.ts +68 -0
- package/src/internal/tokens.ts +3 -0
package/src/ai.tsx
ADDED
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
import { useEffect, useState, type ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import { colors, radii } from "./internal/tokens";
|
|
4
|
+
import { primitives } from "./charts/primitives";
|
|
5
|
+
|
|
6
|
+
export interface NativePlanStep {
|
|
7
|
+
id: string;
|
|
8
|
+
title: string;
|
|
9
|
+
detail?: string;
|
|
10
|
+
status: "pending" | "running" | "done" | "failed";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface NativePlanProps {
|
|
14
|
+
title?: string;
|
|
15
|
+
steps: NativePlanStep[];
|
|
16
|
+
isDark?: boolean;
|
|
17
|
+
style?: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The ordered steps a model intends to take.
|
|
22
|
+
*
|
|
23
|
+
* Each step carries its own status, so a half-finished plan is legible instead
|
|
24
|
+
* of appearing blank until the whole thing completes.
|
|
25
|
+
*/
|
|
26
|
+
export function NativePlan({ title = "Plan", steps, isDark = false, style }: NativePlanProps) {
|
|
27
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
28
|
+
const { View, Text } = primitives();
|
|
29
|
+
const done = steps.filter((step) => step.status === "done").length;
|
|
30
|
+
|
|
31
|
+
const markerColor = (status: NativePlanStep["status"]) =>
|
|
32
|
+
status === "done"
|
|
33
|
+
? "#34c759"
|
|
34
|
+
: status === "failed"
|
|
35
|
+
? theme.destructive
|
|
36
|
+
: status === "running"
|
|
37
|
+
? theme.fill
|
|
38
|
+
: theme.muted;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<View style={style}>
|
|
42
|
+
<View
|
|
43
|
+
style={{
|
|
44
|
+
flexDirection: "row",
|
|
45
|
+
justifyContent: "space-between",
|
|
46
|
+
alignItems: "center",
|
|
47
|
+
marginBottom: 8,
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<Text style={{ fontSize: 13, fontWeight: "600", color: theme.foreground }}>{title}</Text>
|
|
51
|
+
<Text style={{ fontSize: 11, color: theme.muted }}>
|
|
52
|
+
{done}/{steps.length}
|
|
53
|
+
</Text>
|
|
54
|
+
</View>
|
|
55
|
+
|
|
56
|
+
{steps.map((step) => (
|
|
57
|
+
<View
|
|
58
|
+
key={step.id}
|
|
59
|
+
accessibilityRole="text"
|
|
60
|
+
accessibilityLabel={`${step.title}: ${step.status}`}
|
|
61
|
+
style={{ flexDirection: "row", alignItems: "flex-start", gap: 9, marginBottom: 8 }}
|
|
62
|
+
>
|
|
63
|
+
<View
|
|
64
|
+
style={{
|
|
65
|
+
width: 16,
|
|
66
|
+
height: 16,
|
|
67
|
+
borderRadius: 8,
|
|
68
|
+
borderWidth: step.status === "pending" ? 1.5 : 0,
|
|
69
|
+
borderColor: theme.edge,
|
|
70
|
+
backgroundColor: step.status === "pending" ? "transparent" : markerColor(step.status),
|
|
71
|
+
alignItems: "center",
|
|
72
|
+
justifyContent: "center",
|
|
73
|
+
marginTop: 1,
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
{step.status !== "pending" && (
|
|
77
|
+
<Text style={{ fontSize: 9, color: "#fff", fontWeight: "700" }}>
|
|
78
|
+
{step.status === "done" ? "✓" : step.status === "failed" ? "!" : "•"}
|
|
79
|
+
</Text>
|
|
80
|
+
)}
|
|
81
|
+
</View>
|
|
82
|
+
|
|
83
|
+
<View style={{ flex: 1 }}>
|
|
84
|
+
<Text
|
|
85
|
+
style={{
|
|
86
|
+
fontSize: 13,
|
|
87
|
+
color: step.status === "pending" ? theme.muted : theme.foreground,
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
{step.title}
|
|
91
|
+
</Text>
|
|
92
|
+
{step.detail && (
|
|
93
|
+
<Text style={{ fontSize: 11, color: theme.muted, marginTop: 2 }}>{step.detail}</Text>
|
|
94
|
+
)}
|
|
95
|
+
</View>
|
|
96
|
+
</View>
|
|
97
|
+
))}
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface NativeSource {
|
|
103
|
+
id: string;
|
|
104
|
+
title: string;
|
|
105
|
+
url: string;
|
|
106
|
+
snippet?: string;
|
|
107
|
+
domain?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface NativeSourcesProps {
|
|
111
|
+
sources: NativeSource[];
|
|
112
|
+
title?: string;
|
|
113
|
+
isDark?: boolean;
|
|
114
|
+
style?: any;
|
|
115
|
+
onSourcePress?: (source: NativeSource) => void;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Citations behind an answer, so a claim can be traced to its origin.
|
|
120
|
+
*
|
|
121
|
+
* Native has no anchor element, so a row hands the source to the caller's
|
|
122
|
+
* `onSourcePress` instead of opening a browser the component cannot control.
|
|
123
|
+
*/
|
|
124
|
+
export function NativeSources({
|
|
125
|
+
sources,
|
|
126
|
+
title = "Sources",
|
|
127
|
+
isDark = false,
|
|
128
|
+
style,
|
|
129
|
+
onSourcePress,
|
|
130
|
+
}: NativeSourcesProps) {
|
|
131
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
132
|
+
const { View, Text, Pressable } = primitives();
|
|
133
|
+
|
|
134
|
+
if (sources.length === 0) return null;
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<View style={style}>
|
|
138
|
+
<Text style={{ fontSize: 11, fontWeight: "600", color: theme.muted, marginBottom: 6 }}>
|
|
139
|
+
{title}
|
|
140
|
+
</Text>
|
|
141
|
+
|
|
142
|
+
{sources.map((source, index) => (
|
|
143
|
+
<Pressable
|
|
144
|
+
key={source.id}
|
|
145
|
+
accessibilityRole="link"
|
|
146
|
+
accessibilityLabel={source.title}
|
|
147
|
+
onPress={() => onSourcePress?.(source)}
|
|
148
|
+
style={{
|
|
149
|
+
flexDirection: "row",
|
|
150
|
+
gap: 9,
|
|
151
|
+
paddingVertical: 7,
|
|
152
|
+
paddingHorizontal: 10,
|
|
153
|
+
borderRadius: radii.md,
|
|
154
|
+
borderWidth: 1,
|
|
155
|
+
borderColor: theme.edge,
|
|
156
|
+
marginBottom: 6,
|
|
157
|
+
}}
|
|
158
|
+
>
|
|
159
|
+
<Text style={{ fontSize: 10, color: theme.muted, marginTop: 1 }}>{index + 1}</Text>
|
|
160
|
+
<View style={{ flex: 1 }}>
|
|
161
|
+
<Text style={{ fontSize: 12, color: theme.foreground, fontWeight: "500" }}>
|
|
162
|
+
{source.title}
|
|
163
|
+
</Text>
|
|
164
|
+
{source.snippet && (
|
|
165
|
+
<Text style={{ fontSize: 11, color: theme.muted, marginTop: 2 }}>
|
|
166
|
+
{source.snippet}
|
|
167
|
+
</Text>
|
|
168
|
+
)}
|
|
169
|
+
{source.domain && (
|
|
170
|
+
<Text style={{ fontSize: 10, color: theme.muted, marginTop: 3 }}>
|
|
171
|
+
{source.domain}
|
|
172
|
+
</Text>
|
|
173
|
+
)}
|
|
174
|
+
</View>
|
|
175
|
+
</Pressable>
|
|
176
|
+
))}
|
|
177
|
+
</View>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface NativeResponseProps {
|
|
182
|
+
text: string;
|
|
183
|
+
/** Characters to reveal. Omit to show the whole string. */
|
|
184
|
+
revealed?: number;
|
|
185
|
+
streaming?: boolean;
|
|
186
|
+
isDark?: boolean;
|
|
187
|
+
style?: any;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Text revealed progressively as a streamed answer arrives.
|
|
192
|
+
*
|
|
193
|
+
* The caller owns the streaming clock (usually a network stream); this only
|
|
194
|
+
* renders the first `revealed` characters and shows a caret while incomplete.
|
|
195
|
+
*/
|
|
196
|
+
export function NativeResponse({
|
|
197
|
+
text,
|
|
198
|
+
revealed,
|
|
199
|
+
streaming,
|
|
200
|
+
isDark = false,
|
|
201
|
+
style,
|
|
202
|
+
}: NativeResponseProps) {
|
|
203
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
204
|
+
const { View, Text } = primitives();
|
|
205
|
+
|
|
206
|
+
const shown = revealed == null ? text : text.slice(0, Math.max(0, revealed));
|
|
207
|
+
const isStreaming = streaming ?? (revealed != null && revealed < text.length);
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<View style={style}>
|
|
211
|
+
<Text
|
|
212
|
+
accessibilityRole="text"
|
|
213
|
+
accessibilityLabel={shown}
|
|
214
|
+
style={{ fontSize: 14, lineHeight: 21, color: theme.foreground }}
|
|
215
|
+
>
|
|
216
|
+
{shown}
|
|
217
|
+
{isStreaming ? "▍" : ""}
|
|
218
|
+
</Text>
|
|
219
|
+
{/* Announced as a status so screen readers know it is still arriving. */}
|
|
220
|
+
<Text accessibilityRole="alert" style={{ height: 0, opacity: 0, fontSize: 0 }}>
|
|
221
|
+
{isStreaming ? "Response streaming" : "Response complete"}
|
|
222
|
+
</Text>
|
|
223
|
+
</View>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface NativeTaskProps {
|
|
228
|
+
task: {
|
|
229
|
+
/** 0–1, or omit for an indeterminate task. */
|
|
230
|
+
progress?: number;
|
|
231
|
+
label?: string;
|
|
232
|
+
detail?: string;
|
|
233
|
+
status?: "running" | "done" | "failed" | "queued";
|
|
234
|
+
};
|
|
235
|
+
isDark?: boolean;
|
|
236
|
+
style?: any;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Progress of a long-running background task. */
|
|
240
|
+
export function NativeTask({ task, isDark = false, style }: NativeTaskProps) {
|
|
241
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
242
|
+
const { View, Text } = primitives();
|
|
243
|
+
|
|
244
|
+
const percent =
|
|
245
|
+
task.progress == null ? null : Math.round(Math.min(1, Math.max(0, task.progress)) * 100);
|
|
246
|
+
const status = task.status ?? "running";
|
|
247
|
+
const fillColor =
|
|
248
|
+
status === "failed" ? theme.destructive : status === "done" ? "#34c759" : theme.fill;
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<View
|
|
252
|
+
accessibilityRole="progressbar"
|
|
253
|
+
accessibilityLabel={task.label ?? "Task progress"}
|
|
254
|
+
accessibilityState={{
|
|
255
|
+
disabled: false,
|
|
256
|
+
}}
|
|
257
|
+
style={style}
|
|
258
|
+
>
|
|
259
|
+
<View
|
|
260
|
+
style={{ flexDirection: "row", justifyContent: "space-between", marginBottom: 6 }}
|
|
261
|
+
>
|
|
262
|
+
<Text style={{ fontSize: 12, fontWeight: "500", color: theme.foreground }}>
|
|
263
|
+
{task.label ?? "Task"}
|
|
264
|
+
</Text>
|
|
265
|
+
<Text style={{ fontSize: 11, color: theme.muted }}>
|
|
266
|
+
{percent == null ? "…" : `${percent}%`}
|
|
267
|
+
</Text>
|
|
268
|
+
</View>
|
|
269
|
+
|
|
270
|
+
<View
|
|
271
|
+
style={{
|
|
272
|
+
height: 6,
|
|
273
|
+
borderRadius: 3,
|
|
274
|
+
backgroundColor: isDark ? "rgba(235,235,245,0.15)" : "rgba(0,0,0,0.08)",
|
|
275
|
+
overflow: "hidden",
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
<View
|
|
279
|
+
style={{
|
|
280
|
+
// An indeterminate task fills partially rather than pretending 0%.
|
|
281
|
+
width: percent == null ? "35%" : `${percent}%`,
|
|
282
|
+
height: "100%",
|
|
283
|
+
borderRadius: 3,
|
|
284
|
+
backgroundColor: fillColor,
|
|
285
|
+
opacity: percent == null ? 0.6 : 1,
|
|
286
|
+
}}
|
|
287
|
+
/>
|
|
288
|
+
</View>
|
|
289
|
+
|
|
290
|
+
{task.detail && (
|
|
291
|
+
<Text style={{ fontSize: 11, color: theme.muted, marginTop: 6 }}>{task.detail}</Text>
|
|
292
|
+
)}
|
|
293
|
+
</View>
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface NativeSoundwaveProps {
|
|
298
|
+
levels?: number[];
|
|
299
|
+
bars?: number;
|
|
300
|
+
active?: boolean;
|
|
301
|
+
height?: number;
|
|
302
|
+
color?: string;
|
|
303
|
+
isDark?: boolean;
|
|
304
|
+
style?: any;
|
|
305
|
+
label?: string;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* A waveform driven by real amplitude.
|
|
310
|
+
*
|
|
311
|
+
* Bars follow `levels` when supplied, so it can show live microphone input.
|
|
312
|
+
* Without levels it rests at a low, static profile instead of animating:
|
|
313
|
+
* continuous motion with no audio behind it would be decorative noise.
|
|
314
|
+
*/
|
|
315
|
+
export function NativeSoundwave({
|
|
316
|
+
levels,
|
|
317
|
+
bars = 28,
|
|
318
|
+
active = true,
|
|
319
|
+
height = 40,
|
|
320
|
+
color,
|
|
321
|
+
isDark = false,
|
|
322
|
+
style,
|
|
323
|
+
label = "Audio level",
|
|
324
|
+
}: NativeSoundwaveProps) {
|
|
325
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
326
|
+
const { View } = primitives();
|
|
327
|
+
|
|
328
|
+
const count = levels?.length || bars;
|
|
329
|
+
const tint = color ?? theme.foreground;
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
<View
|
|
333
|
+
accessibilityRole="image"
|
|
334
|
+
accessibilityLabel={label}
|
|
335
|
+
style={{ flexDirection: "row", alignItems: "center", gap: 2, height, ...style }}
|
|
336
|
+
>
|
|
337
|
+
{Array.from({ length: count }, (_, i) => {
|
|
338
|
+
const level = levels ? levels[i] ?? 0 : 0;
|
|
339
|
+
// Idle bars taper at the edges so the shape still reads as a wave.
|
|
340
|
+
const idle = 0.12 + Math.sin((i / count) * Math.PI) * 0.1;
|
|
341
|
+
const scale = Math.max(0.06, Math.min(1, active && levels ? level : idle));
|
|
342
|
+
return (
|
|
343
|
+
<View
|
|
344
|
+
key={i}
|
|
345
|
+
style={{
|
|
346
|
+
width: 3,
|
|
347
|
+
height: height * scale,
|
|
348
|
+
borderRadius: 2,
|
|
349
|
+
backgroundColor: tint,
|
|
350
|
+
opacity: active ? 0.85 : 0.35,
|
|
351
|
+
}}
|
|
352
|
+
/>
|
|
353
|
+
);
|
|
354
|
+
})}
|
|
355
|
+
</View>
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export interface NativeThinkingOrbProps {
|
|
360
|
+
label?: string;
|
|
361
|
+
size?: number;
|
|
362
|
+
paused?: boolean;
|
|
363
|
+
isDark?: boolean;
|
|
364
|
+
style?: any;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* A pulsing indicator shown while a model is working.
|
|
369
|
+
*
|
|
370
|
+
* Purely decorative, so it is hidden from screen readers and the label is
|
|
371
|
+
* exposed as text instead of relying on the motion being perceived.
|
|
372
|
+
*/
|
|
373
|
+
export function NativeThinkingOrb({
|
|
374
|
+
label = "Thinking",
|
|
375
|
+
size = 22,
|
|
376
|
+
paused = false,
|
|
377
|
+
isDark = false,
|
|
378
|
+
style,
|
|
379
|
+
}: NativeThinkingOrbProps) {
|
|
380
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
381
|
+
const { View, Text } = primitives();
|
|
382
|
+
const [tick, setTick] = useState(0);
|
|
383
|
+
|
|
384
|
+
useEffect(() => {
|
|
385
|
+
if (paused) return;
|
|
386
|
+
const timer = setInterval(() => setTick((value) => value + 1), 700);
|
|
387
|
+
return () => clearInterval(timer);
|
|
388
|
+
}, [paused]);
|
|
389
|
+
|
|
390
|
+
const scale = paused ? 1 : [1, 1.12, 1][tick % 3]!;
|
|
391
|
+
|
|
392
|
+
return (
|
|
393
|
+
<View
|
|
394
|
+
accessibilityRole="text"
|
|
395
|
+
accessibilityLabel={label}
|
|
396
|
+
style={{ flexDirection: "row", alignItems: "center", gap: 8, ...style }}
|
|
397
|
+
>
|
|
398
|
+
<View
|
|
399
|
+
style={{
|
|
400
|
+
width: size,
|
|
401
|
+
height: size,
|
|
402
|
+
borderRadius: size / 2,
|
|
403
|
+
backgroundColor: theme.fill,
|
|
404
|
+
opacity: paused ? 0.5 : 0.85,
|
|
405
|
+
transform: [{ scale }],
|
|
406
|
+
}}
|
|
407
|
+
/>
|
|
408
|
+
<Text style={{ fontSize: 12, color: theme.muted }}>{label}</Text>
|
|
409
|
+
</View>
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export interface NativePanelNavItem {
|
|
414
|
+
id: string;
|
|
415
|
+
label: string;
|
|
416
|
+
count?: number;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export interface NativePanelsideProps {
|
|
420
|
+
items: NativePanelNavItem[];
|
|
421
|
+
value?: string;
|
|
422
|
+
onValueChange?: (id: string) => void;
|
|
423
|
+
isDark?: boolean;
|
|
424
|
+
style?: any;
|
|
425
|
+
title?: string;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* A rail for an AI workspace: conversations, saved prompts or tasks.
|
|
430
|
+
*
|
|
431
|
+
* Selection is a press rather than navigation because the panel's content is
|
|
432
|
+
* client state; the caller decides what a selection means.
|
|
433
|
+
*/
|
|
434
|
+
export function NativePanelside({
|
|
435
|
+
items,
|
|
436
|
+
value,
|
|
437
|
+
onValueChange,
|
|
438
|
+
isDark = false,
|
|
439
|
+
style,
|
|
440
|
+
title,
|
|
441
|
+
}: NativePanelsideProps) {
|
|
442
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
443
|
+
const { View, Text, Pressable } = primitives();
|
|
444
|
+
|
|
445
|
+
return (
|
|
446
|
+
<View style={style}>
|
|
447
|
+
{title && (
|
|
448
|
+
<Text style={{ fontSize: 11, fontWeight: "600", color: theme.muted, marginBottom: 6 }}>
|
|
449
|
+
{title}
|
|
450
|
+
</Text>
|
|
451
|
+
)}
|
|
452
|
+
|
|
453
|
+
{items.map((item) => {
|
|
454
|
+
const isActive = item.id === value;
|
|
455
|
+
return (
|
|
456
|
+
<Pressable
|
|
457
|
+
key={item.id}
|
|
458
|
+
accessibilityRole="button"
|
|
459
|
+
accessibilityState={{ selected: isActive }}
|
|
460
|
+
accessibilityLabel={item.label}
|
|
461
|
+
onPress={() => onValueChange?.(item.id)}
|
|
462
|
+
style={{
|
|
463
|
+
flexDirection: "row",
|
|
464
|
+
alignItems: "center",
|
|
465
|
+
justifyContent: "space-between",
|
|
466
|
+
paddingVertical: 9,
|
|
467
|
+
paddingHorizontal: 11,
|
|
468
|
+
borderRadius: radii.md,
|
|
469
|
+
backgroundColor: isActive ? theme.glassActive : "transparent",
|
|
470
|
+
marginBottom: 2,
|
|
471
|
+
}}
|
|
472
|
+
>
|
|
473
|
+
<Text
|
|
474
|
+
style={{
|
|
475
|
+
fontSize: 13,
|
|
476
|
+
color: isActive ? theme.foreground : theme.muted,
|
|
477
|
+
fontWeight: isActive ? "600" : "400",
|
|
478
|
+
}}
|
|
479
|
+
>
|
|
480
|
+
{item.label}
|
|
481
|
+
</Text>
|
|
482
|
+
{item.count != null && (
|
|
483
|
+
<Text style={{ fontSize: 10, color: theme.muted }}>{item.count}</Text>
|
|
484
|
+
)}
|
|
485
|
+
</Pressable>
|
|
486
|
+
);
|
|
487
|
+
})}
|
|
488
|
+
</View>
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export interface NativeAIInputProps {
|
|
493
|
+
value?: string;
|
|
494
|
+
onChangeText?: (text: string) => void;
|
|
495
|
+
onSubmit?: () => void;
|
|
496
|
+
placeholder?: string;
|
|
497
|
+
disabled?: boolean;
|
|
498
|
+
/** Shown as a spinner-free label while a response is pending. */
|
|
499
|
+
busy?: boolean;
|
|
500
|
+
sendLabel?: string;
|
|
501
|
+
isDark?: boolean;
|
|
502
|
+
style?: any;
|
|
503
|
+
footer?: ReactNode;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* The composer for an AI conversation.
|
|
508
|
+
*
|
|
509
|
+
* Send stays disabled until there is non-whitespace to send, which is the rule
|
|
510
|
+
* that prevents empty submissions rather than a validation message afterwards.
|
|
511
|
+
*/
|
|
512
|
+
export function NativeAIInput({
|
|
513
|
+
value = "",
|
|
514
|
+
onChangeText,
|
|
515
|
+
onSubmit,
|
|
516
|
+
placeholder = "Ask anything",
|
|
517
|
+
disabled = false,
|
|
518
|
+
busy = false,
|
|
519
|
+
sendLabel = "Send",
|
|
520
|
+
isDark = false,
|
|
521
|
+
style,
|
|
522
|
+
footer,
|
|
523
|
+
}: NativeAIInputProps) {
|
|
524
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
525
|
+
const { View, Text, TextInput, Pressable } = primitives();
|
|
526
|
+
|
|
527
|
+
const canSend = !disabled && !busy && value.trim().length > 0;
|
|
528
|
+
|
|
529
|
+
return (
|
|
530
|
+
<View style={style}>
|
|
531
|
+
<View
|
|
532
|
+
style={{
|
|
533
|
+
flexDirection: "row",
|
|
534
|
+
alignItems: "flex-end",
|
|
535
|
+
gap: 8,
|
|
536
|
+
padding: 8,
|
|
537
|
+
borderRadius: radii.lg,
|
|
538
|
+
borderWidth: 1,
|
|
539
|
+
borderColor: theme.edge,
|
|
540
|
+
backgroundColor: theme.glass,
|
|
541
|
+
opacity: disabled ? 0.5 : 1,
|
|
542
|
+
}}
|
|
543
|
+
>
|
|
544
|
+
<TextInput
|
|
545
|
+
value={value}
|
|
546
|
+
onChangeText={onChangeText}
|
|
547
|
+
placeholder={placeholder}
|
|
548
|
+
editable={!disabled}
|
|
549
|
+
multiline
|
|
550
|
+
numberOfLines={3}
|
|
551
|
+
accessibilityLabel={placeholder}
|
|
552
|
+
style={{
|
|
553
|
+
flex: 1,
|
|
554
|
+
minHeight: 34,
|
|
555
|
+
maxHeight: 120,
|
|
556
|
+
paddingHorizontal: 6,
|
|
557
|
+
paddingVertical: 7,
|
|
558
|
+
fontSize: 14,
|
|
559
|
+
color: theme.foreground,
|
|
560
|
+
}}
|
|
561
|
+
/>
|
|
562
|
+
|
|
563
|
+
<Pressable
|
|
564
|
+
accessibilityRole="button"
|
|
565
|
+
accessibilityLabel={sendLabel}
|
|
566
|
+
accessibilityState={{ disabled: !canSend }}
|
|
567
|
+
disabled={!canSend}
|
|
568
|
+
onPress={() => canSend && onSubmit?.()}
|
|
569
|
+
style={{
|
|
570
|
+
paddingVertical: 8,
|
|
571
|
+
paddingHorizontal: 14,
|
|
572
|
+
borderRadius: radii.pill,
|
|
573
|
+
backgroundColor: canSend ? theme.fill : theme.edge,
|
|
574
|
+
}}
|
|
575
|
+
>
|
|
576
|
+
<Text style={{ fontSize: 13, fontWeight: "600", color: canSend ? "#fff" : theme.muted }}>
|
|
577
|
+
{busy ? "…" : sendLabel}
|
|
578
|
+
</Text>
|
|
579
|
+
</Pressable>
|
|
580
|
+
</View>
|
|
581
|
+
|
|
582
|
+
{footer}
|
|
583
|
+
</View>
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
export interface NativeGeneratedImage {
|
|
588
|
+
url: string;
|
|
589
|
+
alt: string;
|
|
590
|
+
width?: number;
|
|
591
|
+
height?: number;
|
|
592
|
+
/** Shown under the image while generation is still running. */
|
|
593
|
+
progress?: number;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export interface NativeImageGenerationProps {
|
|
597
|
+
image?: NativeGeneratedImage;
|
|
598
|
+
prompt?: string;
|
|
599
|
+
status?: "queued" | "generating" | "done" | "failed";
|
|
600
|
+
isDark?: boolean;
|
|
601
|
+
style?: any;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* A generated image with its prompt and state.
|
|
606
|
+
*
|
|
607
|
+
* While generating, a placeholder with the same aspect ratio holds the space so
|
|
608
|
+
* the layout does not jump when the image arrives.
|
|
609
|
+
*/
|
|
610
|
+
export function NativeImageGeneration({
|
|
611
|
+
image,
|
|
612
|
+
prompt,
|
|
613
|
+
status = "queued",
|
|
614
|
+
isDark = false,
|
|
615
|
+
style,
|
|
616
|
+
}: NativeImageGenerationProps) {
|
|
617
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
618
|
+
const { View, Text, Image } = primitives();
|
|
619
|
+
|
|
620
|
+
const width = image?.width ?? 320;
|
|
621
|
+
const height = image?.height ?? 200;
|
|
622
|
+
const showImage = image && status === "done";
|
|
623
|
+
|
|
624
|
+
return (
|
|
625
|
+
<View style={style}>
|
|
626
|
+
<View
|
|
627
|
+
style={{
|
|
628
|
+
width: "100%",
|
|
629
|
+
aspectRatio: width / height,
|
|
630
|
+
borderRadius: radii.md,
|
|
631
|
+
overflow: "hidden",
|
|
632
|
+
backgroundColor: isDark ? "rgba(235,235,245,0.08)" : "rgba(0,0,0,0.05)",
|
|
633
|
+
alignItems: "center",
|
|
634
|
+
justifyContent: "center",
|
|
635
|
+
}}
|
|
636
|
+
>
|
|
637
|
+
{showImage ? (
|
|
638
|
+
<Image
|
|
639
|
+
source={{ uri: image.url }}
|
|
640
|
+
accessibilityLabel={image.alt}
|
|
641
|
+
style={{ width: "100%", height: "100%" }}
|
|
642
|
+
/>
|
|
643
|
+
) : (
|
|
644
|
+
<Text style={{ fontSize: 12, color: theme.muted }}>
|
|
645
|
+
{status === "failed" ? "Generation failed" : "Generating…"}
|
|
646
|
+
</Text>
|
|
647
|
+
)}
|
|
648
|
+
</View>
|
|
649
|
+
|
|
650
|
+
{prompt && (
|
|
651
|
+
<Text style={{ fontSize: 11, color: theme.muted, marginTop: 6 }}>{prompt}</Text>
|
|
652
|
+
)}
|
|
653
|
+
</View>
|
|
654
|
+
);
|
|
655
|
+
}
|