@istmx/ui 0.1.11 → 0.1.13
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 +21 -21
- package/README.md +533 -463
- package/bin/istmx.mjs +481 -314
- package/package.json +27 -27
- package/registry/accordion.tsx +186 -0
- package/registry/ai-chat-block/ai-chat-block.tsx +456 -460
- package/registry/ai-chat-block/ai-chat-input.tsx +694 -694
- package/registry/ai-chat-block/attachment.tsx +466 -466
- package/registry/ai-chat-block/chat-code-block.tsx +50 -50
- package/registry/ai-chat-block/chat-composer.tsx +51 -51
- package/registry/ai-chat-block/chat-logo.tsx +18 -18
- package/registry/ai-chat-block/chat-message.tsx +161 -161
- package/registry/ai-chat-block/chat-sidebar.tsx +273 -273
- package/registry/ai-chat-block/chat-user-avatar.tsx +9 -9
- package/registry/ai-chat-block/code-highlighter.tsx +342 -357
- package/registry/ai-chat-block/default-attachments.tsx +42 -42
- package/registry/ai-chat-block/index.ts +30 -30
- package/registry/ai-chat-block/message-content.tsx +287 -287
- package/registry/ai-chat-block/message-list.tsx +93 -93
- package/registry/ai-chat-block/send-button.tsx +102 -102
- package/registry/ai-chat-block/types.ts +70 -71
- package/registry/ai-chat-block/utils.ts +6 -6
- package/registry/ai-chat-block/voice-button.tsx +66 -66
- package/registry/alert-dialog.tsx +229 -0
- package/registry/alert.tsx +188 -0
- package/registry/animated-text.tsx +228 -225
- package/registry/aspect-ratio.tsx +32 -0
- package/registry/avatar-group.tsx +66 -0
- package/registry/avatar.tsx +121 -0
- package/registry/badge.tsx +52 -0
- package/registry/bento-grid.tsx +438 -433
- package/registry/button.tsx +156 -237
- package/registry/carousel.tsx +184 -0
- package/registry/dock-navigation.tsx +200 -198
- package/registry/drift-canvas.tsx +383 -0
- package/registry/drift-wall.tsx +361 -0
- package/registry/flex-carousel.tsx +1430 -0
- package/registry/guided-gallery.tsx +1506 -0
- package/registry/image-accordion.tsx +306 -302
- package/registry/image-trail.tsx +126 -121
- package/registry/infinite-image-canvas.tsx +268 -263
- package/registry/input-otp.tsx +332 -0
- package/registry/list-card.tsx +130 -0
- package/registry/mobile-menu-dock.tsx +216 -211
- package/registry/morph-slider.tsx +756 -0
- package/registry/pixel-cat.tsx +972 -1020
- package/registry/scroll-canvas-cards.tsx +643 -0
- package/registry/scroll-parallax-hero.tsx +566 -565
- package/registry/scroll-story-cards.tsx +443 -438
- package/registry/slider.tsx +163 -0
- package/registry/spotlight-grid.tsx +226 -0
- package/registry/streaming-text.tsx +269 -278
- package/registry/text-reveal.tsx +311 -307
- package/registry/user-avatar.tsx +99 -0
- package/registry/utils.ts +6 -6
|
@@ -1,694 +1,694 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { useEffect, useId, useRef, useState } from 'react'
|
|
4
|
-
import type { ChangeEvent, CSSProperties, KeyboardEvent } from 'react'
|
|
5
|
-
import {
|
|
6
|
-
AnimatePresence,
|
|
7
|
-
motion,
|
|
8
|
-
useAnimationControls,
|
|
9
|
-
useReducedMotion,
|
|
10
|
-
} from 'motion/react'
|
|
11
|
-
import { IconPlus, IconX } from '@tabler/icons-react'
|
|
12
|
-
import { cn } from './utils'
|
|
13
|
-
import AttachmentDialog, { AttachmentPreview } from './attachment'
|
|
14
|
-
import SendButton from './send-button'
|
|
15
|
-
import VoiceButton from './voice-button'
|
|
16
|
-
import type { AttachmentOption, ChatAttachment } from './types'
|
|
17
|
-
|
|
18
|
-
type AnimatedAccentBorderProps = {
|
|
19
|
-
color: string
|
|
20
|
-
duration?: number
|
|
21
|
-
intensity?: number
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function AnimatedAccentBorder({
|
|
25
|
-
color,
|
|
26
|
-
duration = 5,
|
|
27
|
-
intensity = 1,
|
|
28
|
-
}: AnimatedAccentBorderProps) {
|
|
29
|
-
const borderRef = useRef<SVGSVGElement>(null)
|
|
30
|
-
const glowFilterId = `${useId().replace(/:/g, '')}-organic-glow`
|
|
31
|
-
const [size, setSize] = useState({ width: 0, height: 0 })
|
|
32
|
-
const reduceMotion = useReducedMotion()
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
const border = borderRef.current
|
|
36
|
-
if (!border) return
|
|
37
|
-
|
|
38
|
-
const observer = new ResizeObserver(() => {
|
|
39
|
-
const { width, height } = border.getBoundingClientRect()
|
|
40
|
-
setSize((current) =>
|
|
41
|
-
Math.abs(current.width - width) < 0.5 &&
|
|
42
|
-
Math.abs(current.height - height) < 0.5
|
|
43
|
-
? current
|
|
44
|
-
: { width, height },
|
|
45
|
-
)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
observer.observe(border)
|
|
49
|
-
return () => observer.disconnect()
|
|
50
|
-
}, [])
|
|
51
|
-
|
|
52
|
-
const measuredWidth = Math.max(1, size.width)
|
|
53
|
-
const measuredHeight = Math.max(1, size.height)
|
|
54
|
-
const width = Math.max(0, measuredWidth - 1)
|
|
55
|
-
const height = Math.max(0, measuredHeight - 1)
|
|
56
|
-
const radius = Math.min(15.5, width / 2, height / 2)
|
|
57
|
-
const pathLength = Math.max(
|
|
58
|
-
0,
|
|
59
|
-
2 * (width + height - 4 * radius) + 2 * Math.PI * radius,
|
|
60
|
-
)
|
|
61
|
-
const dashLength = pathLength * 0.22
|
|
62
|
-
const highlightColor = `color-mix(in srgb, ${color} 62%, white)`
|
|
63
|
-
const animate = reduceMotion ? undefined : { strokeDashoffset: -pathLength }
|
|
64
|
-
const transition = {
|
|
65
|
-
duration: Math.max(1, duration),
|
|
66
|
-
ease: 'linear' as const,
|
|
67
|
-
repeat: Infinity,
|
|
68
|
-
}
|
|
69
|
-
const shape = {
|
|
70
|
-
x: 0.5,
|
|
71
|
-
y: 0.5,
|
|
72
|
-
width,
|
|
73
|
-
height,
|
|
74
|
-
rx: radius,
|
|
75
|
-
fill: 'none',
|
|
76
|
-
}
|
|
77
|
-
const animatedShape = {
|
|
78
|
-
...shape,
|
|
79
|
-
strokeDasharray: `${dashLength} ${pathLength - dashLength}`,
|
|
80
|
-
strokeLinecap: 'round' as const,
|
|
81
|
-
initial: { strokeDashoffset: 0 },
|
|
82
|
-
animate,
|
|
83
|
-
transition,
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return (
|
|
87
|
-
<svg
|
|
88
|
-
ref={borderRef}
|
|
89
|
-
aria-hidden="true"
|
|
90
|
-
viewBox={`0 0 ${measuredWidth} ${measuredHeight}`}
|
|
91
|
-
className="pointer-events-none absolute -top-px -left-px z-20 overflow-visible"
|
|
92
|
-
style={{
|
|
93
|
-
width: 'calc(100% + 2px)',
|
|
94
|
-
height: 'calc(100% + 2px)',
|
|
95
|
-
opacity: Math.min(1, Math.max(0, intensity)),
|
|
96
|
-
}}
|
|
97
|
-
>
|
|
98
|
-
<defs>
|
|
99
|
-
<filter
|
|
100
|
-
id={glowFilterId}
|
|
101
|
-
x="-35%"
|
|
102
|
-
y="-60%"
|
|
103
|
-
width="170%"
|
|
104
|
-
height="220%"
|
|
105
|
-
colorInterpolationFilters="sRGB"
|
|
106
|
-
>
|
|
107
|
-
<feTurbulence
|
|
108
|
-
type="fractalNoise"
|
|
109
|
-
baseFrequency="0.01 0.08"
|
|
110
|
-
numOctaves="2"
|
|
111
|
-
seed="7"
|
|
112
|
-
result="edgeNoise"
|
|
113
|
-
/>
|
|
114
|
-
<feDisplacementMap
|
|
115
|
-
in="SourceGraphic"
|
|
116
|
-
in2="edgeNoise"
|
|
117
|
-
scale="18"
|
|
118
|
-
xChannelSelector="R"
|
|
119
|
-
yChannelSelector="G"
|
|
120
|
-
result="unevenEdge"
|
|
121
|
-
/>
|
|
122
|
-
<feGaussianBlur in="unevenEdge" stdDeviation="10" />
|
|
123
|
-
</filter>
|
|
124
|
-
</defs>
|
|
125
|
-
<rect {...shape} stroke={color} strokeWidth="1.5" opacity="0.38" />
|
|
126
|
-
<rect
|
|
127
|
-
{...shape}
|
|
128
|
-
stroke={color}
|
|
129
|
-
strokeWidth="8"
|
|
130
|
-
filter={`url(#${glowFilterId})`}
|
|
131
|
-
opacity="0.55"
|
|
132
|
-
/>
|
|
133
|
-
<motion.rect
|
|
134
|
-
{...animatedShape}
|
|
135
|
-
stroke={color}
|
|
136
|
-
strokeWidth="14"
|
|
137
|
-
filter={`url(#${glowFilterId})`}
|
|
138
|
-
opacity="0.7"
|
|
139
|
-
/>
|
|
140
|
-
<motion.rect
|
|
141
|
-
{...animatedShape}
|
|
142
|
-
stroke={color}
|
|
143
|
-
strokeWidth="8"
|
|
144
|
-
filter={`url(#${glowFilterId})`}
|
|
145
|
-
opacity="0.9"
|
|
146
|
-
/>
|
|
147
|
-
<motion.rect
|
|
148
|
-
{...animatedShape}
|
|
149
|
-
stroke={highlightColor}
|
|
150
|
-
strokeWidth="3.5"
|
|
151
|
-
/>
|
|
152
|
-
</svg>
|
|
153
|
-
)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export type AiChatInputAction = AttachmentOption & {
|
|
157
|
-
hint?: string
|
|
158
|
-
}
|
|
159
|
-
export type AiChatInputAttachment = ChatAttachment
|
|
160
|
-
|
|
161
|
-
export type AiChatInputProps = {
|
|
162
|
-
actions?: readonly AiChatInputAction[]
|
|
163
|
-
placeholder?: string
|
|
164
|
-
|
|
165
|
-
label?: string
|
|
166
|
-
menuLabel?: string
|
|
167
|
-
submitLabel?: string
|
|
168
|
-
startVoiceLabel?: string
|
|
169
|
-
stopVoiceLabel?: string
|
|
170
|
-
defaultValue?: string
|
|
171
|
-
onValueChange?: (value: string) => void
|
|
172
|
-
onAttachmentsChange?: (attachments: AiChatInputAttachment[]) => void
|
|
173
|
-
onSubmit?: (value: string, attachments: AiChatInputAttachment[]) => void
|
|
174
|
-
onStop?: () => void
|
|
175
|
-
onListeningChange?: (listening: boolean) => void
|
|
176
|
-
maxLength?: number
|
|
177
|
-
maxRows?: number
|
|
178
|
-
maxAttachments?: number
|
|
179
|
-
maxFileSizeBytes?: number
|
|
180
|
-
showVoice?: boolean
|
|
181
|
-
busy?: boolean
|
|
182
|
-
disabled?: boolean
|
|
183
|
-
className?: string
|
|
184
|
-
textareaClassName?: string
|
|
185
|
-
accentColor?: string
|
|
186
|
-
|
|
187
|
-
glow?: false | AiChatInputGlow
|
|
188
|
-
onAttachmentError?: (message: string) => void
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export type AiChatInputGlow = {
|
|
192
|
-
color?: string
|
|
193
|
-
|
|
194
|
-
duration?: number
|
|
195
|
-
|
|
196
|
-
intensity?: number
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const LINE_HEIGHT = 24
|
|
200
|
-
const PADDING_Y = 16
|
|
201
|
-
|
|
202
|
-
const MEDIA_EXTENSION: Record<string, AiChatInputAttachment['kind']> = {
|
|
203
|
-
png: 'image',
|
|
204
|
-
jpg: 'image',
|
|
205
|
-
jpeg: 'image',
|
|
206
|
-
gif: 'image',
|
|
207
|
-
webp: 'image',
|
|
208
|
-
avif: 'image',
|
|
209
|
-
svg: 'image',
|
|
210
|
-
bmp: 'image',
|
|
211
|
-
mp4: 'video',
|
|
212
|
-
webm: 'video',
|
|
213
|
-
mov: 'video',
|
|
214
|
-
mkv: 'video',
|
|
215
|
-
mp3: 'audio',
|
|
216
|
-
wav: 'audio',
|
|
217
|
-
ogg: 'audio',
|
|
218
|
-
m4a: 'audio',
|
|
219
|
-
flac: 'audio',
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function attachmentKind(type: string, name: string) {
|
|
223
|
-
if (type.startsWith('image/')) return 'image' as const
|
|
224
|
-
if (type.startsWith('video/')) return 'video' as const
|
|
225
|
-
if (type.startsWith('audio/')) return 'audio' as const
|
|
226
|
-
|
|
227
|
-
const extension = name.split('.').pop()?.toLowerCase() ?? ''
|
|
228
|
-
return MEDIA_EXTENSION[extension] ?? ('file' as const)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function formatBytes(size?: number) {
|
|
232
|
-
if (typeof size !== 'number' || Number.isNaN(size)) return ''
|
|
233
|
-
if (size < 1024) return `${size} B`
|
|
234
|
-
if (size < 1024 * 1024) return `${Math.round(size / 1024)} KB`
|
|
235
|
-
return `${(size / (1024 * 1024)).toFixed(1)} MB`
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function Equalizer({ reduceMotion }: { reduceMotion: boolean | null }) {
|
|
239
|
-
return (
|
|
240
|
-
<span
|
|
241
|
-
aria-hidden="true"
|
|
242
|
-
className="flex h-3 shrink-0 items-center gap-[2px]"
|
|
243
|
-
>
|
|
244
|
-
{[0, 1, 2, 3, 4].map((index) => (
|
|
245
|
-
<motion.span
|
|
246
|
-
key={index}
|
|
247
|
-
className="bg-foreground block h-3 w-[2px] rounded-full"
|
|
248
|
-
style={{ transformOrigin: 'center' }}
|
|
249
|
-
animate={
|
|
250
|
-
reduceMotion
|
|
251
|
-
? { scaleY: 0.55 }
|
|
252
|
-
: { scaleY: [0.22, 1, 0.4, 0.85, 0.22] }
|
|
253
|
-
}
|
|
254
|
-
transition={
|
|
255
|
-
reduceMotion
|
|
256
|
-
? undefined
|
|
257
|
-
: {
|
|
258
|
-
duration: 1 + index * 0.14,
|
|
259
|
-
repeat: Infinity,
|
|
260
|
-
ease: 'easeInOut',
|
|
261
|
-
delay: index * 0.07,
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
/>
|
|
265
|
-
))}
|
|
266
|
-
</span>
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export function AiChatInput({
|
|
271
|
-
actions,
|
|
272
|
-
placeholder = 'Ask anything…',
|
|
273
|
-
label = 'Message',
|
|
274
|
-
menuLabel = 'Add to message',
|
|
275
|
-
submitLabel = 'Send message',
|
|
276
|
-
startVoiceLabel = 'Start voice input',
|
|
277
|
-
stopVoiceLabel = 'Stop voice input',
|
|
278
|
-
defaultValue = '',
|
|
279
|
-
onValueChange,
|
|
280
|
-
onAttachmentsChange,
|
|
281
|
-
onSubmit,
|
|
282
|
-
onStop,
|
|
283
|
-
onListeningChange,
|
|
284
|
-
maxLength = 4000,
|
|
285
|
-
maxRows = 8,
|
|
286
|
-
maxAttachments = 10,
|
|
287
|
-
maxFileSizeBytes,
|
|
288
|
-
showVoice = true,
|
|
289
|
-
busy = false,
|
|
290
|
-
disabled = false,
|
|
291
|
-
className,
|
|
292
|
-
textareaClassName,
|
|
293
|
-
accentColor,
|
|
294
|
-
glow = false,
|
|
295
|
-
onAttachmentError,
|
|
296
|
-
}: AiChatInputProps) {
|
|
297
|
-
const rootId = useId().replace(/:/g, '')
|
|
298
|
-
const attachmentCounter = useRef(0)
|
|
299
|
-
const attachmentsRef = useRef<AiChatInputAttachment[]>([])
|
|
300
|
-
|
|
301
|
-
const [value, setValue] = useState(defaultValue)
|
|
302
|
-
const [attachments, setAttachments] = useState<AiChatInputAttachment[]>([])
|
|
303
|
-
const [menuOpen, setMenuOpen] = useState(false)
|
|
304
|
-
const [listening, setListening] = useState(false)
|
|
305
|
-
const [sent, setSent] = useState(false)
|
|
306
|
-
|
|
307
|
-
const fieldRef = useRef<HTMLTextAreaElement>(null)
|
|
308
|
-
const menuTriggerRef = useRef<HTMLButtonElement>(null)
|
|
309
|
-
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
310
|
-
const sentTimer = useRef<number | null>(null)
|
|
311
|
-
const shakeControls = useAnimationControls()
|
|
312
|
-
const reduceMotion = useReducedMotion()
|
|
313
|
-
|
|
314
|
-
const hasActions = Boolean(actions && actions.length > 0)
|
|
315
|
-
const canSend =
|
|
316
|
-
!disabled && !busy && (value.trim().length > 0 || attachments.length > 0)
|
|
317
|
-
const sendState = busy ? 'busy' : canSend ? 'ready' : sent ? 'sent' : 'idle'
|
|
318
|
-
const glowOptions = typeof glow === 'object' ? glow : {}
|
|
319
|
-
const glowColor = accentColor ?? glowOptions.color ?? '#0369a1'
|
|
320
|
-
function updateValue(next: string) {
|
|
321
|
-
const bounded = next.slice(0, maxLength)
|
|
322
|
-
setValue(bounded)
|
|
323
|
-
onValueChange?.(bounded)
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function commitAttachments(next: AiChatInputAttachment[]) {
|
|
327
|
-
setAttachments(next)
|
|
328
|
-
onAttachmentsChange?.(next)
|
|
329
|
-
}
|
|
330
|
-
useEffect(() => {
|
|
331
|
-
const field = fieldRef.current
|
|
332
|
-
if (!field) return
|
|
333
|
-
|
|
334
|
-
field.style.height = 'auto'
|
|
335
|
-
const ceiling = maxRows * LINE_HEIGHT + PADDING_Y
|
|
336
|
-
const next = Math.min(field.scrollHeight, ceiling)
|
|
337
|
-
field.style.height = `${next}px`
|
|
338
|
-
field.style.overflowY = field.scrollHeight > ceiling ? 'auto' : 'hidden'
|
|
339
|
-
}, [value, maxRows])
|
|
340
|
-
useEffect(() => {
|
|
341
|
-
attachmentsRef.current = attachments
|
|
342
|
-
}, [attachments])
|
|
343
|
-
useEffect(() => {
|
|
344
|
-
return () => {
|
|
345
|
-
if (sentTimer.current) window.clearTimeout(sentTimer.current)
|
|
346
|
-
attachmentsRef.current.forEach((item) => {
|
|
347
|
-
if (item.url?.startsWith('blob:')) URL.revokeObjectURL(item.url)
|
|
348
|
-
})
|
|
349
|
-
}
|
|
350
|
-
}, [])
|
|
351
|
-
|
|
352
|
-
function closeMenu(refocusTrigger = false) {
|
|
353
|
-
setMenuOpen(false)
|
|
354
|
-
if (refocusTrigger)
|
|
355
|
-
requestAnimationFrame(() => menuTriggerRef.current?.focus())
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function runAction(action: AiChatInputAction) {
|
|
359
|
-
if (action.disabled || disabled) return
|
|
360
|
-
|
|
361
|
-
setMenuOpen(false)
|
|
362
|
-
|
|
363
|
-
if (action.accept) {
|
|
364
|
-
const input = fileInputRef.current
|
|
365
|
-
if (input) {
|
|
366
|
-
input.accept = action.accept
|
|
367
|
-
input.multiple = Boolean(action.multiple)
|
|
368
|
-
if (action.capture) input.setAttribute('capture', action.capture)
|
|
369
|
-
else input.removeAttribute('capture')
|
|
370
|
-
input.value = ''
|
|
371
|
-
input.click()
|
|
372
|
-
}
|
|
373
|
-
} else {
|
|
374
|
-
requestAnimationFrame(() => menuTriggerRef.current?.focus())
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
action.onSelect?.()
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
function handleFiles(event: ChangeEvent<HTMLInputElement>) {
|
|
381
|
-
const files = Array.from(event.target.files ?? [])
|
|
382
|
-
event.target.value = ''
|
|
383
|
-
if (!files.length) return
|
|
384
|
-
|
|
385
|
-
const capacity = Math.max(0, maxAttachments - attachments.length)
|
|
386
|
-
const accepted = files.filter((file) => {
|
|
387
|
-
if (maxFileSizeBytes && file.size > maxFileSizeBytes) {
|
|
388
|
-
onAttachmentError?.(
|
|
389
|
-
`${file.name} is larger than the allowed file size.`,
|
|
390
|
-
)
|
|
391
|
-
return false
|
|
392
|
-
}
|
|
393
|
-
return true
|
|
394
|
-
})
|
|
395
|
-
if (accepted.length > capacity) {
|
|
396
|
-
onAttachmentError?.(`You can attach up to ${maxAttachments} files.`)
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
const next: AiChatInputAttachment[] = accepted
|
|
400
|
-
.slice(0, capacity)
|
|
401
|
-
.map((file) => ({
|
|
402
|
-
id: `${rootId}-attachment-${attachmentCounter.current++}`,
|
|
403
|
-
name: file.name,
|
|
404
|
-
kind: attachmentKind(file.type, file.name),
|
|
405
|
-
size: file.size,
|
|
406
|
-
file,
|
|
407
|
-
url:
|
|
408
|
-
file.type.startsWith('image/') || file.type.startsWith('video/')
|
|
409
|
-
? URL.createObjectURL(file)
|
|
410
|
-
: undefined,
|
|
411
|
-
}))
|
|
412
|
-
|
|
413
|
-
commitAttachments([...attachments, ...next])
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
function removeAttachment(id: string) {
|
|
417
|
-
const target = attachments.find((item) => item.id === id)
|
|
418
|
-
if (target?.url?.startsWith('blob:')) URL.revokeObjectURL(target.url)
|
|
419
|
-
commitAttachments(attachments.filter((item) => item.id !== id))
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
function toggleListening() {
|
|
423
|
-
if (disabled) return
|
|
424
|
-
const next = !listening
|
|
425
|
-
setListening(next)
|
|
426
|
-
onListeningChange?.(next)
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
function submit() {
|
|
430
|
-
if (disabled || busy) return
|
|
431
|
-
|
|
432
|
-
if (!canSend) {
|
|
433
|
-
if (!reduceMotion) {
|
|
434
|
-
void shakeControls.start({
|
|
435
|
-
x: [0, -5, 5, -4, 4, -2, 0],
|
|
436
|
-
transition: { duration: 0.36, ease: 'easeOut' },
|
|
437
|
-
})
|
|
438
|
-
}
|
|
439
|
-
fieldRef.current?.focus()
|
|
440
|
-
return
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
onSubmit?.(value.trim(), attachments)
|
|
444
|
-
attachments.forEach((item) => {
|
|
445
|
-
if (item.url?.startsWith('blob:')) URL.revokeObjectURL(item.url)
|
|
446
|
-
})
|
|
447
|
-
updateValue('')
|
|
448
|
-
commitAttachments([])
|
|
449
|
-
setSent(true)
|
|
450
|
-
fieldRef.current?.focus()
|
|
451
|
-
|
|
452
|
-
if (sentTimer.current) window.clearTimeout(sentTimer.current)
|
|
453
|
-
sentTimer.current = window.setTimeout(() => setSent(false), 1200)
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
function handleFieldKeyDown(event: KeyboardEvent<HTMLTextAreaElement>) {
|
|
457
|
-
if (event.key === 'Escape' && busy) {
|
|
458
|
-
event.preventDefault()
|
|
459
|
-
onStop?.()
|
|
460
|
-
return
|
|
461
|
-
}
|
|
462
|
-
if (
|
|
463
|
-
event.key === 'Enter' &&
|
|
464
|
-
!event.shiftKey &&
|
|
465
|
-
!event.nativeEvent.isComposing
|
|
466
|
-
) {
|
|
467
|
-
event.preventDefault()
|
|
468
|
-
submit()
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
return (
|
|
473
|
-
<div
|
|
474
|
-
style={{ '--chat-accent': glowColor } as CSSProperties}
|
|
475
|
-
className={cn(
|
|
476
|
-
'bg-background/85 border-border/70 focus-within:border-foreground/40 relative rounded-2xl border shadow-sm backdrop-blur-xl transition-[border-color] duration-300',
|
|
477
|
-
disabled && 'opacity-60',
|
|
478
|
-
className,
|
|
479
|
-
)}
|
|
480
|
-
>
|
|
481
|
-
{glow !== false ? (
|
|
482
|
-
<AnimatedAccentBorder
|
|
483
|
-
color={glowColor}
|
|
484
|
-
duration={glowOptions.duration}
|
|
485
|
-
intensity={glowOptions.intensity}
|
|
486
|
-
/>
|
|
487
|
-
) : null}
|
|
488
|
-
|
|
489
|
-
<AnimatePresence initial={false}>
|
|
490
|
-
{attachments.length > 0 ? (
|
|
491
|
-
<motion.div
|
|
492
|
-
key="attachments"
|
|
493
|
-
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, height: 0 }}
|
|
494
|
-
animate={
|
|
495
|
-
reduceMotion ? { opacity: 1 } : { opacity: 1, height: 'auto' }
|
|
496
|
-
}
|
|
497
|
-
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, height: 0 }}
|
|
498
|
-
transition={
|
|
499
|
-
reduceMotion
|
|
500
|
-
? { duration: 0.1 }
|
|
501
|
-
: { type: 'spring', stiffness: 340, damping: 34, mass: 0.7 }
|
|
502
|
-
}
|
|
503
|
-
className="overflow-hidden"
|
|
504
|
-
>
|
|
505
|
-
<div className="flex flex-wrap gap-2 px-2.5 pt-2.5 sm:px-3 sm:pt-3">
|
|
506
|
-
<AnimatePresence initial={false}>
|
|
507
|
-
{attachments.map((item) => {
|
|
508
|
-
return (
|
|
509
|
-
<motion.div
|
|
510
|
-
key={item.id}
|
|
511
|
-
layout={!reduceMotion}
|
|
512
|
-
initial={
|
|
513
|
-
reduceMotion
|
|
514
|
-
? { opacity: 0 }
|
|
515
|
-
: { opacity: 0, scale: 0.9, y: 8 }
|
|
516
|
-
}
|
|
517
|
-
animate={{ opacity: 1, scale: 1, y: 0 }}
|
|
518
|
-
exit={
|
|
519
|
-
reduceMotion
|
|
520
|
-
? { opacity: 0 }
|
|
521
|
-
: { opacity: 0, scale: 0.9, y: -6 }
|
|
522
|
-
}
|
|
523
|
-
transition={
|
|
524
|
-
reduceMotion
|
|
525
|
-
? { duration: 0.1 }
|
|
526
|
-
: {
|
|
527
|
-
type: 'spring',
|
|
528
|
-
stiffness: 440,
|
|
529
|
-
damping: 30,
|
|
530
|
-
mass: 0.6,
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
className="border-border/70 bg-surface/40 group/chip flex max-w-full min-w-0 items-center gap-2 rounded-lg border p-1 pr-1.5"
|
|
534
|
-
>
|
|
535
|
-
<AttachmentPreview
|
|
536
|
-
file={item.file}
|
|
537
|
-
src={item.url}
|
|
538
|
-
name={item.name}
|
|
539
|
-
kind={item.kind}
|
|
540
|
-
thumbnailClassName="size-7 rounded-md"
|
|
541
|
-
/>
|
|
542
|
-
|
|
543
|
-
<span className="text-foreground max-w-[9rem] truncate text-xs font-medium sm:max-w-[12rem]">
|
|
544
|
-
{item.name}
|
|
545
|
-
</span>
|
|
546
|
-
{item.size !== undefined ? (
|
|
547
|
-
<span className="text-muted/70 hidden font-mono text-[9px] tracking-wide uppercase sm:block">
|
|
548
|
-
{formatBytes(item.size)}
|
|
549
|
-
</span>
|
|
550
|
-
) : null}
|
|
551
|
-
|
|
552
|
-
<button
|
|
553
|
-
type="button"
|
|
554
|
-
aria-label={`Remove ${item.name}`}
|
|
555
|
-
onClick={() => removeAttachment(item.id)}
|
|
556
|
-
className="text-muted hover:text-foreground focus-visible:outline-foreground inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-2 focus-visible:outline-offset-2"
|
|
557
|
-
>
|
|
558
|
-
<IconX
|
|
559
|
-
size={13}
|
|
560
|
-
stroke={1.8}
|
|
561
|
-
aria-hidden="true"
|
|
562
|
-
className="transition-transform duration-300 group-hover/chip:rotate-90"
|
|
563
|
-
/>
|
|
564
|
-
</button>
|
|
565
|
-
</motion.div>
|
|
566
|
-
)
|
|
567
|
-
})}
|
|
568
|
-
</AnimatePresence>
|
|
569
|
-
</div>
|
|
570
|
-
</motion.div>
|
|
571
|
-
) : null}
|
|
572
|
-
</AnimatePresence>
|
|
573
|
-
|
|
574
|
-
<div className="flex items-end gap-2 p-2.5 sm:gap-3 sm:p-3">
|
|
575
|
-
{hasActions ? (
|
|
576
|
-
<motion.button
|
|
577
|
-
type="button"
|
|
578
|
-
ref={menuTriggerRef}
|
|
579
|
-
data-chat-input-trigger=""
|
|
580
|
-
onClick={() => setMenuOpen((open) => !open)}
|
|
581
|
-
aria-label={menuOpen ? 'Close attachment options' : menuLabel}
|
|
582
|
-
aria-haspopup="dialog"
|
|
583
|
-
aria-expanded={menuOpen}
|
|
584
|
-
aria-controls={`${rootId}-attachment-dialog`}
|
|
585
|
-
disabled={disabled}
|
|
586
|
-
whileTap={reduceMotion ? undefined : { scale: 0.9 }}
|
|
587
|
-
className="border-border/70 bg-surface/40 text-muted hover:border-foreground/40 hover:text-foreground focus-visible:outline-foreground group/plus relative flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-xl border transition-colors duration-200 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-50 sm:size-9"
|
|
588
|
-
>
|
|
589
|
-
<span
|
|
590
|
-
aria-hidden="true"
|
|
591
|
-
className="pointer-events-none absolute inset-0 rounded-[inherit] bg-[linear-gradient(145deg,rgba(255,255,255,0.14)_0%,transparent_48%,rgba(0,0,0,0.06)_100%)] opacity-0 transition-opacity duration-200 group-hover/plus:opacity-100"
|
|
592
|
-
/>
|
|
593
|
-
<motion.span
|
|
594
|
-
aria-hidden="true"
|
|
595
|
-
animate={{ rotate: menuOpen ? 45 : 0 }}
|
|
596
|
-
transition={
|
|
597
|
-
reduceMotion
|
|
598
|
-
? { duration: 0 }
|
|
599
|
-
: { type: 'spring', stiffness: 480, damping: 22 }
|
|
600
|
-
}
|
|
601
|
-
className="relative flex items-center justify-center"
|
|
602
|
-
>
|
|
603
|
-
<IconPlus size={17} stroke={1.8} />
|
|
604
|
-
</motion.span>
|
|
605
|
-
</motion.button>
|
|
606
|
-
) : null}
|
|
607
|
-
|
|
608
|
-
<div className="relative min-w-0 flex-1">
|
|
609
|
-
<textarea
|
|
610
|
-
ref={fieldRef}
|
|
611
|
-
value={value}
|
|
612
|
-
onChange={(event) => updateValue(event.target.value)}
|
|
613
|
-
onKeyDown={handleFieldKeyDown}
|
|
614
|
-
placeholder={listening ? '' : placeholder}
|
|
615
|
-
aria-label={label}
|
|
616
|
-
rows={1}
|
|
617
|
-
maxLength={maxLength}
|
|
618
|
-
enterKeyHint="send"
|
|
619
|
-
spellCheck={false}
|
|
620
|
-
disabled={disabled}
|
|
621
|
-
className={cn(
|
|
622
|
-
'placeholder:text-muted/70 text-foreground block w-full resize-none bg-transparent px-1 py-2 text-sm leading-6 outline-none disabled:cursor-not-allowed motion-safe:transition-[height] motion-safe:duration-200',
|
|
623
|
-
textareaClassName,
|
|
624
|
-
)}
|
|
625
|
-
/>
|
|
626
|
-
|
|
627
|
-
<AnimatePresence>
|
|
628
|
-
{listening && value.length === 0 ? (
|
|
629
|
-
<motion.div
|
|
630
|
-
aria-hidden="true"
|
|
631
|
-
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 5 }}
|
|
632
|
-
animate={{ opacity: 1, y: 0 }}
|
|
633
|
-
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: -5 }}
|
|
634
|
-
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
635
|
-
className="pointer-events-none absolute inset-0 flex items-center gap-2.5 px-1 py-2"
|
|
636
|
-
>
|
|
637
|
-
<Equalizer reduceMotion={reduceMotion} />
|
|
638
|
-
<span className="text-muted text-sm">Listening…</span>
|
|
639
|
-
</motion.div>
|
|
640
|
-
) : null}
|
|
641
|
-
</AnimatePresence>
|
|
642
|
-
</div>
|
|
643
|
-
|
|
644
|
-
<div className="flex shrink-0 items-center gap-1 sm:gap-1.5">
|
|
645
|
-
{showVoice ? (
|
|
646
|
-
<VoiceButton
|
|
647
|
-
listening={listening}
|
|
648
|
-
disabled={disabled}
|
|
649
|
-
onClick={toggleListening}
|
|
650
|
-
startLabel={startVoiceLabel}
|
|
651
|
-
stopLabel={stopVoiceLabel}
|
|
652
|
-
/>
|
|
653
|
-
) : null}
|
|
654
|
-
<SendButton
|
|
655
|
-
state={sendState === 'busy' ? 'sending' : sendState}
|
|
656
|
-
disabled={disabled}
|
|
657
|
-
label={submitLabel}
|
|
658
|
-
shakeControls={shakeControls}
|
|
659
|
-
onClick={submit}
|
|
660
|
-
onStop={onStop}
|
|
661
|
-
/>
|
|
662
|
-
</div>
|
|
663
|
-
</div>
|
|
664
|
-
|
|
665
|
-
<input
|
|
666
|
-
ref={fileInputRef}
|
|
667
|
-
type="file"
|
|
668
|
-
tabIndex={-1}
|
|
669
|
-
aria-hidden="true"
|
|
670
|
-
onChange={handleFiles}
|
|
671
|
-
className="sr-only"
|
|
672
|
-
/>
|
|
673
|
-
<AttachmentDialog
|
|
674
|
-
id={`${rootId}-attachment-dialog`}
|
|
675
|
-
anchorRef={menuTriggerRef}
|
|
676
|
-
open={menuOpen}
|
|
677
|
-
title={menuLabel}
|
|
678
|
-
options={
|
|
679
|
-
actions?.map((action) => ({
|
|
680
|
-
...action,
|
|
681
|
-
description: action.description ?? action.hint,
|
|
682
|
-
})) ?? []
|
|
683
|
-
}
|
|
684
|
-
onSelect={runAction}
|
|
685
|
-
onClose={() => closeMenu(true)}
|
|
686
|
-
accentColor={
|
|
687
|
-
accentColor ?? (typeof glow === 'object' ? glow.color : undefined)
|
|
688
|
-
}
|
|
689
|
-
/>
|
|
690
|
-
</div>
|
|
691
|
-
)
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
export default AiChatInput
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useId, useRef, useState } from 'react'
|
|
4
|
+
import type { ChangeEvent, CSSProperties, KeyboardEvent } from 'react'
|
|
5
|
+
import {
|
|
6
|
+
AnimatePresence,
|
|
7
|
+
motion,
|
|
8
|
+
useAnimationControls,
|
|
9
|
+
useReducedMotion,
|
|
10
|
+
} from 'motion/react'
|
|
11
|
+
import { IconPlus, IconX } from '@tabler/icons-react'
|
|
12
|
+
import { cn } from './utils'
|
|
13
|
+
import AttachmentDialog, { AttachmentPreview } from './attachment'
|
|
14
|
+
import SendButton from './send-button'
|
|
15
|
+
import VoiceButton from './voice-button'
|
|
16
|
+
import type { AttachmentOption, ChatAttachment } from './types'
|
|
17
|
+
|
|
18
|
+
type AnimatedAccentBorderProps = {
|
|
19
|
+
color: string
|
|
20
|
+
duration?: number
|
|
21
|
+
intensity?: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function AnimatedAccentBorder({
|
|
25
|
+
color,
|
|
26
|
+
duration = 5,
|
|
27
|
+
intensity = 1,
|
|
28
|
+
}: AnimatedAccentBorderProps) {
|
|
29
|
+
const borderRef = useRef<SVGSVGElement>(null)
|
|
30
|
+
const glowFilterId = `${useId().replace(/:/g, '')}-organic-glow`
|
|
31
|
+
const [size, setSize] = useState({ width: 0, height: 0 })
|
|
32
|
+
const reduceMotion = useReducedMotion()
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const border = borderRef.current
|
|
36
|
+
if (!border) return
|
|
37
|
+
|
|
38
|
+
const observer = new ResizeObserver(() => {
|
|
39
|
+
const { width, height } = border.getBoundingClientRect()
|
|
40
|
+
setSize((current) =>
|
|
41
|
+
Math.abs(current.width - width) < 0.5 &&
|
|
42
|
+
Math.abs(current.height - height) < 0.5
|
|
43
|
+
? current
|
|
44
|
+
: { width, height },
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
observer.observe(border)
|
|
49
|
+
return () => observer.disconnect()
|
|
50
|
+
}, [])
|
|
51
|
+
|
|
52
|
+
const measuredWidth = Math.max(1, size.width)
|
|
53
|
+
const measuredHeight = Math.max(1, size.height)
|
|
54
|
+
const width = Math.max(0, measuredWidth - 1)
|
|
55
|
+
const height = Math.max(0, measuredHeight - 1)
|
|
56
|
+
const radius = Math.min(15.5, width / 2, height / 2)
|
|
57
|
+
const pathLength = Math.max(
|
|
58
|
+
0,
|
|
59
|
+
2 * (width + height - 4 * radius) + 2 * Math.PI * radius,
|
|
60
|
+
)
|
|
61
|
+
const dashLength = pathLength * 0.22
|
|
62
|
+
const highlightColor = `color-mix(in srgb, ${color} 62%, white)`
|
|
63
|
+
const animate = reduceMotion ? undefined : { strokeDashoffset: -pathLength }
|
|
64
|
+
const transition = {
|
|
65
|
+
duration: Math.max(1, duration),
|
|
66
|
+
ease: 'linear' as const,
|
|
67
|
+
repeat: Infinity,
|
|
68
|
+
}
|
|
69
|
+
const shape = {
|
|
70
|
+
x: 0.5,
|
|
71
|
+
y: 0.5,
|
|
72
|
+
width,
|
|
73
|
+
height,
|
|
74
|
+
rx: radius,
|
|
75
|
+
fill: 'none',
|
|
76
|
+
}
|
|
77
|
+
const animatedShape = {
|
|
78
|
+
...shape,
|
|
79
|
+
strokeDasharray: `${dashLength} ${pathLength - dashLength}`,
|
|
80
|
+
strokeLinecap: 'round' as const,
|
|
81
|
+
initial: { strokeDashoffset: 0 },
|
|
82
|
+
animate,
|
|
83
|
+
transition,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<svg
|
|
88
|
+
ref={borderRef}
|
|
89
|
+
aria-hidden="true"
|
|
90
|
+
viewBox={`0 0 ${measuredWidth} ${measuredHeight}`}
|
|
91
|
+
className="pointer-events-none absolute -top-px -left-px z-20 overflow-visible"
|
|
92
|
+
style={{
|
|
93
|
+
width: 'calc(100% + 2px)',
|
|
94
|
+
height: 'calc(100% + 2px)',
|
|
95
|
+
opacity: Math.min(1, Math.max(0, intensity)),
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
<defs>
|
|
99
|
+
<filter
|
|
100
|
+
id={glowFilterId}
|
|
101
|
+
x="-35%"
|
|
102
|
+
y="-60%"
|
|
103
|
+
width="170%"
|
|
104
|
+
height="220%"
|
|
105
|
+
colorInterpolationFilters="sRGB"
|
|
106
|
+
>
|
|
107
|
+
<feTurbulence
|
|
108
|
+
type="fractalNoise"
|
|
109
|
+
baseFrequency="0.01 0.08"
|
|
110
|
+
numOctaves="2"
|
|
111
|
+
seed="7"
|
|
112
|
+
result="edgeNoise"
|
|
113
|
+
/>
|
|
114
|
+
<feDisplacementMap
|
|
115
|
+
in="SourceGraphic"
|
|
116
|
+
in2="edgeNoise"
|
|
117
|
+
scale="18"
|
|
118
|
+
xChannelSelector="R"
|
|
119
|
+
yChannelSelector="G"
|
|
120
|
+
result="unevenEdge"
|
|
121
|
+
/>
|
|
122
|
+
<feGaussianBlur in="unevenEdge" stdDeviation="10" />
|
|
123
|
+
</filter>
|
|
124
|
+
</defs>
|
|
125
|
+
<rect {...shape} stroke={color} strokeWidth="1.5" opacity="0.38" />
|
|
126
|
+
<rect
|
|
127
|
+
{...shape}
|
|
128
|
+
stroke={color}
|
|
129
|
+
strokeWidth="8"
|
|
130
|
+
filter={`url(#${glowFilterId})`}
|
|
131
|
+
opacity="0.55"
|
|
132
|
+
/>
|
|
133
|
+
<motion.rect
|
|
134
|
+
{...animatedShape}
|
|
135
|
+
stroke={color}
|
|
136
|
+
strokeWidth="14"
|
|
137
|
+
filter={`url(#${glowFilterId})`}
|
|
138
|
+
opacity="0.7"
|
|
139
|
+
/>
|
|
140
|
+
<motion.rect
|
|
141
|
+
{...animatedShape}
|
|
142
|
+
stroke={color}
|
|
143
|
+
strokeWidth="8"
|
|
144
|
+
filter={`url(#${glowFilterId})`}
|
|
145
|
+
opacity="0.9"
|
|
146
|
+
/>
|
|
147
|
+
<motion.rect
|
|
148
|
+
{...animatedShape}
|
|
149
|
+
stroke={highlightColor}
|
|
150
|
+
strokeWidth="3.5"
|
|
151
|
+
/>
|
|
152
|
+
</svg>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export type AiChatInputAction = AttachmentOption & {
|
|
157
|
+
hint?: string
|
|
158
|
+
}
|
|
159
|
+
export type AiChatInputAttachment = ChatAttachment
|
|
160
|
+
|
|
161
|
+
export type AiChatInputProps = {
|
|
162
|
+
actions?: readonly AiChatInputAction[]
|
|
163
|
+
placeholder?: string
|
|
164
|
+
|
|
165
|
+
label?: string
|
|
166
|
+
menuLabel?: string
|
|
167
|
+
submitLabel?: string
|
|
168
|
+
startVoiceLabel?: string
|
|
169
|
+
stopVoiceLabel?: string
|
|
170
|
+
defaultValue?: string
|
|
171
|
+
onValueChange?: (value: string) => void
|
|
172
|
+
onAttachmentsChange?: (attachments: AiChatInputAttachment[]) => void
|
|
173
|
+
onSubmit?: (value: string, attachments: AiChatInputAttachment[]) => void
|
|
174
|
+
onStop?: () => void
|
|
175
|
+
onListeningChange?: (listening: boolean) => void
|
|
176
|
+
maxLength?: number
|
|
177
|
+
maxRows?: number
|
|
178
|
+
maxAttachments?: number
|
|
179
|
+
maxFileSizeBytes?: number
|
|
180
|
+
showVoice?: boolean
|
|
181
|
+
busy?: boolean
|
|
182
|
+
disabled?: boolean
|
|
183
|
+
className?: string
|
|
184
|
+
textareaClassName?: string
|
|
185
|
+
accentColor?: string
|
|
186
|
+
|
|
187
|
+
glow?: false | AiChatInputGlow
|
|
188
|
+
onAttachmentError?: (message: string) => void
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type AiChatInputGlow = {
|
|
192
|
+
color?: string
|
|
193
|
+
|
|
194
|
+
duration?: number
|
|
195
|
+
|
|
196
|
+
intensity?: number
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const LINE_HEIGHT = 24
|
|
200
|
+
const PADDING_Y = 16
|
|
201
|
+
|
|
202
|
+
const MEDIA_EXTENSION: Record<string, AiChatInputAttachment['kind']> = {
|
|
203
|
+
png: 'image',
|
|
204
|
+
jpg: 'image',
|
|
205
|
+
jpeg: 'image',
|
|
206
|
+
gif: 'image',
|
|
207
|
+
webp: 'image',
|
|
208
|
+
avif: 'image',
|
|
209
|
+
svg: 'image',
|
|
210
|
+
bmp: 'image',
|
|
211
|
+
mp4: 'video',
|
|
212
|
+
webm: 'video',
|
|
213
|
+
mov: 'video',
|
|
214
|
+
mkv: 'video',
|
|
215
|
+
mp3: 'audio',
|
|
216
|
+
wav: 'audio',
|
|
217
|
+
ogg: 'audio',
|
|
218
|
+
m4a: 'audio',
|
|
219
|
+
flac: 'audio',
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function attachmentKind(type: string, name: string) {
|
|
223
|
+
if (type.startsWith('image/')) return 'image' as const
|
|
224
|
+
if (type.startsWith('video/')) return 'video' as const
|
|
225
|
+
if (type.startsWith('audio/')) return 'audio' as const
|
|
226
|
+
|
|
227
|
+
const extension = name.split('.').pop()?.toLowerCase() ?? ''
|
|
228
|
+
return MEDIA_EXTENSION[extension] ?? ('file' as const)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function formatBytes(size?: number) {
|
|
232
|
+
if (typeof size !== 'number' || Number.isNaN(size)) return ''
|
|
233
|
+
if (size < 1024) return `${size} B`
|
|
234
|
+
if (size < 1024 * 1024) return `${Math.round(size / 1024)} KB`
|
|
235
|
+
return `${(size / (1024 * 1024)).toFixed(1)} MB`
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function Equalizer({ reduceMotion }: { reduceMotion: boolean | null }) {
|
|
239
|
+
return (
|
|
240
|
+
<span
|
|
241
|
+
aria-hidden="true"
|
|
242
|
+
className="flex h-3 shrink-0 items-center gap-[2px]"
|
|
243
|
+
>
|
|
244
|
+
{[0, 1, 2, 3, 4].map((index) => (
|
|
245
|
+
<motion.span
|
|
246
|
+
key={index}
|
|
247
|
+
className="bg-foreground block h-3 w-[2px] rounded-full"
|
|
248
|
+
style={{ transformOrigin: 'center' }}
|
|
249
|
+
animate={
|
|
250
|
+
reduceMotion
|
|
251
|
+
? { scaleY: 0.55 }
|
|
252
|
+
: { scaleY: [0.22, 1, 0.4, 0.85, 0.22] }
|
|
253
|
+
}
|
|
254
|
+
transition={
|
|
255
|
+
reduceMotion
|
|
256
|
+
? undefined
|
|
257
|
+
: {
|
|
258
|
+
duration: 1 + index * 0.14,
|
|
259
|
+
repeat: Infinity,
|
|
260
|
+
ease: 'easeInOut',
|
|
261
|
+
delay: index * 0.07,
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/>
|
|
265
|
+
))}
|
|
266
|
+
</span>
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function AiChatInput({
|
|
271
|
+
actions,
|
|
272
|
+
placeholder = 'Ask anything…',
|
|
273
|
+
label = 'Message',
|
|
274
|
+
menuLabel = 'Add to message',
|
|
275
|
+
submitLabel = 'Send message',
|
|
276
|
+
startVoiceLabel = 'Start voice input',
|
|
277
|
+
stopVoiceLabel = 'Stop voice input',
|
|
278
|
+
defaultValue = '',
|
|
279
|
+
onValueChange,
|
|
280
|
+
onAttachmentsChange,
|
|
281
|
+
onSubmit,
|
|
282
|
+
onStop,
|
|
283
|
+
onListeningChange,
|
|
284
|
+
maxLength = 4000,
|
|
285
|
+
maxRows = 8,
|
|
286
|
+
maxAttachments = 10,
|
|
287
|
+
maxFileSizeBytes,
|
|
288
|
+
showVoice = true,
|
|
289
|
+
busy = false,
|
|
290
|
+
disabled = false,
|
|
291
|
+
className,
|
|
292
|
+
textareaClassName,
|
|
293
|
+
accentColor,
|
|
294
|
+
glow = false,
|
|
295
|
+
onAttachmentError,
|
|
296
|
+
}: AiChatInputProps) {
|
|
297
|
+
const rootId = useId().replace(/:/g, '')
|
|
298
|
+
const attachmentCounter = useRef(0)
|
|
299
|
+
const attachmentsRef = useRef<AiChatInputAttachment[]>([])
|
|
300
|
+
|
|
301
|
+
const [value, setValue] = useState(defaultValue)
|
|
302
|
+
const [attachments, setAttachments] = useState<AiChatInputAttachment[]>([])
|
|
303
|
+
const [menuOpen, setMenuOpen] = useState(false)
|
|
304
|
+
const [listening, setListening] = useState(false)
|
|
305
|
+
const [sent, setSent] = useState(false)
|
|
306
|
+
|
|
307
|
+
const fieldRef = useRef<HTMLTextAreaElement>(null)
|
|
308
|
+
const menuTriggerRef = useRef<HTMLButtonElement>(null)
|
|
309
|
+
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
310
|
+
const sentTimer = useRef<number | null>(null)
|
|
311
|
+
const shakeControls = useAnimationControls()
|
|
312
|
+
const reduceMotion = useReducedMotion()
|
|
313
|
+
|
|
314
|
+
const hasActions = Boolean(actions && actions.length > 0)
|
|
315
|
+
const canSend =
|
|
316
|
+
!disabled && !busy && (value.trim().length > 0 || attachments.length > 0)
|
|
317
|
+
const sendState = busy ? 'busy' : canSend ? 'ready' : sent ? 'sent' : 'idle'
|
|
318
|
+
const glowOptions = typeof glow === 'object' ? glow : {}
|
|
319
|
+
const glowColor = accentColor ?? glowOptions.color ?? '#0369a1'
|
|
320
|
+
function updateValue(next: string) {
|
|
321
|
+
const bounded = next.slice(0, maxLength)
|
|
322
|
+
setValue(bounded)
|
|
323
|
+
onValueChange?.(bounded)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function commitAttachments(next: AiChatInputAttachment[]) {
|
|
327
|
+
setAttachments(next)
|
|
328
|
+
onAttachmentsChange?.(next)
|
|
329
|
+
}
|
|
330
|
+
useEffect(() => {
|
|
331
|
+
const field = fieldRef.current
|
|
332
|
+
if (!field) return
|
|
333
|
+
|
|
334
|
+
field.style.height = 'auto'
|
|
335
|
+
const ceiling = maxRows * LINE_HEIGHT + PADDING_Y
|
|
336
|
+
const next = Math.min(field.scrollHeight, ceiling)
|
|
337
|
+
field.style.height = `${next}px`
|
|
338
|
+
field.style.overflowY = field.scrollHeight > ceiling ? 'auto' : 'hidden'
|
|
339
|
+
}, [value, maxRows])
|
|
340
|
+
useEffect(() => {
|
|
341
|
+
attachmentsRef.current = attachments
|
|
342
|
+
}, [attachments])
|
|
343
|
+
useEffect(() => {
|
|
344
|
+
return () => {
|
|
345
|
+
if (sentTimer.current) window.clearTimeout(sentTimer.current)
|
|
346
|
+
attachmentsRef.current.forEach((item) => {
|
|
347
|
+
if (item.url?.startsWith('blob:')) URL.revokeObjectURL(item.url)
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
}, [])
|
|
351
|
+
|
|
352
|
+
function closeMenu(refocusTrigger = false) {
|
|
353
|
+
setMenuOpen(false)
|
|
354
|
+
if (refocusTrigger)
|
|
355
|
+
requestAnimationFrame(() => menuTriggerRef.current?.focus())
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function runAction(action: AiChatInputAction) {
|
|
359
|
+
if (action.disabled || disabled) return
|
|
360
|
+
|
|
361
|
+
setMenuOpen(false)
|
|
362
|
+
|
|
363
|
+
if (action.accept) {
|
|
364
|
+
const input = fileInputRef.current
|
|
365
|
+
if (input) {
|
|
366
|
+
input.accept = action.accept
|
|
367
|
+
input.multiple = Boolean(action.multiple)
|
|
368
|
+
if (action.capture) input.setAttribute('capture', action.capture)
|
|
369
|
+
else input.removeAttribute('capture')
|
|
370
|
+
input.value = ''
|
|
371
|
+
input.click()
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
requestAnimationFrame(() => menuTriggerRef.current?.focus())
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
action.onSelect?.()
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function handleFiles(event: ChangeEvent<HTMLInputElement>) {
|
|
381
|
+
const files = Array.from(event.target.files ?? [])
|
|
382
|
+
event.target.value = ''
|
|
383
|
+
if (!files.length) return
|
|
384
|
+
|
|
385
|
+
const capacity = Math.max(0, maxAttachments - attachments.length)
|
|
386
|
+
const accepted = files.filter((file) => {
|
|
387
|
+
if (maxFileSizeBytes && file.size > maxFileSizeBytes) {
|
|
388
|
+
onAttachmentError?.(
|
|
389
|
+
`${file.name} is larger than the allowed file size.`,
|
|
390
|
+
)
|
|
391
|
+
return false
|
|
392
|
+
}
|
|
393
|
+
return true
|
|
394
|
+
})
|
|
395
|
+
if (accepted.length > capacity) {
|
|
396
|
+
onAttachmentError?.(`You can attach up to ${maxAttachments} files.`)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const next: AiChatInputAttachment[] = accepted
|
|
400
|
+
.slice(0, capacity)
|
|
401
|
+
.map((file) => ({
|
|
402
|
+
id: `${rootId}-attachment-${attachmentCounter.current++}`,
|
|
403
|
+
name: file.name,
|
|
404
|
+
kind: attachmentKind(file.type, file.name),
|
|
405
|
+
size: file.size,
|
|
406
|
+
file,
|
|
407
|
+
url:
|
|
408
|
+
file.type.startsWith('image/') || file.type.startsWith('video/')
|
|
409
|
+
? URL.createObjectURL(file)
|
|
410
|
+
: undefined,
|
|
411
|
+
}))
|
|
412
|
+
|
|
413
|
+
commitAttachments([...attachments, ...next])
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function removeAttachment(id: string) {
|
|
417
|
+
const target = attachments.find((item) => item.id === id)
|
|
418
|
+
if (target?.url?.startsWith('blob:')) URL.revokeObjectURL(target.url)
|
|
419
|
+
commitAttachments(attachments.filter((item) => item.id !== id))
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function toggleListening() {
|
|
423
|
+
if (disabled) return
|
|
424
|
+
const next = !listening
|
|
425
|
+
setListening(next)
|
|
426
|
+
onListeningChange?.(next)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function submit() {
|
|
430
|
+
if (disabled || busy) return
|
|
431
|
+
|
|
432
|
+
if (!canSend) {
|
|
433
|
+
if (!reduceMotion) {
|
|
434
|
+
void shakeControls.start({
|
|
435
|
+
x: [0, -5, 5, -4, 4, -2, 0],
|
|
436
|
+
transition: { duration: 0.36, ease: 'easeOut' },
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
fieldRef.current?.focus()
|
|
440
|
+
return
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
onSubmit?.(value.trim(), attachments)
|
|
444
|
+
attachments.forEach((item) => {
|
|
445
|
+
if (item.url?.startsWith('blob:')) URL.revokeObjectURL(item.url)
|
|
446
|
+
})
|
|
447
|
+
updateValue('')
|
|
448
|
+
commitAttachments([])
|
|
449
|
+
setSent(true)
|
|
450
|
+
fieldRef.current?.focus()
|
|
451
|
+
|
|
452
|
+
if (sentTimer.current) window.clearTimeout(sentTimer.current)
|
|
453
|
+
sentTimer.current = window.setTimeout(() => setSent(false), 1200)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function handleFieldKeyDown(event: KeyboardEvent<HTMLTextAreaElement>) {
|
|
457
|
+
if (event.key === 'Escape' && busy) {
|
|
458
|
+
event.preventDefault()
|
|
459
|
+
onStop?.()
|
|
460
|
+
return
|
|
461
|
+
}
|
|
462
|
+
if (
|
|
463
|
+
event.key === 'Enter' &&
|
|
464
|
+
!event.shiftKey &&
|
|
465
|
+
!event.nativeEvent.isComposing
|
|
466
|
+
) {
|
|
467
|
+
event.preventDefault()
|
|
468
|
+
submit()
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return (
|
|
473
|
+
<div
|
|
474
|
+
style={{ '--chat-accent': glowColor } as CSSProperties}
|
|
475
|
+
className={cn(
|
|
476
|
+
'bg-background/85 border-border/70 focus-within:border-foreground/40 relative rounded-2xl border shadow-sm backdrop-blur-xl transition-[border-color] duration-300',
|
|
477
|
+
disabled && 'opacity-60',
|
|
478
|
+
className,
|
|
479
|
+
)}
|
|
480
|
+
>
|
|
481
|
+
{glow !== false ? (
|
|
482
|
+
<AnimatedAccentBorder
|
|
483
|
+
color={glowColor}
|
|
484
|
+
duration={glowOptions.duration}
|
|
485
|
+
intensity={glowOptions.intensity}
|
|
486
|
+
/>
|
|
487
|
+
) : null}
|
|
488
|
+
|
|
489
|
+
<AnimatePresence initial={false}>
|
|
490
|
+
{attachments.length > 0 ? (
|
|
491
|
+
<motion.div
|
|
492
|
+
key="attachments"
|
|
493
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, height: 0 }}
|
|
494
|
+
animate={
|
|
495
|
+
reduceMotion ? { opacity: 1 } : { opacity: 1, height: 'auto' }
|
|
496
|
+
}
|
|
497
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, height: 0 }}
|
|
498
|
+
transition={
|
|
499
|
+
reduceMotion
|
|
500
|
+
? { duration: 0.1 }
|
|
501
|
+
: { type: 'spring', stiffness: 340, damping: 34, mass: 0.7 }
|
|
502
|
+
}
|
|
503
|
+
className="overflow-hidden"
|
|
504
|
+
>
|
|
505
|
+
<div className="flex flex-wrap gap-2 px-2.5 pt-2.5 sm:px-3 sm:pt-3">
|
|
506
|
+
<AnimatePresence initial={false}>
|
|
507
|
+
{attachments.map((item) => {
|
|
508
|
+
return (
|
|
509
|
+
<motion.div
|
|
510
|
+
key={item.id}
|
|
511
|
+
layout={!reduceMotion}
|
|
512
|
+
initial={
|
|
513
|
+
reduceMotion
|
|
514
|
+
? { opacity: 0 }
|
|
515
|
+
: { opacity: 0, scale: 0.9, y: 8 }
|
|
516
|
+
}
|
|
517
|
+
animate={{ opacity: 1, scale: 1, y: 0 }}
|
|
518
|
+
exit={
|
|
519
|
+
reduceMotion
|
|
520
|
+
? { opacity: 0 }
|
|
521
|
+
: { opacity: 0, scale: 0.9, y: -6 }
|
|
522
|
+
}
|
|
523
|
+
transition={
|
|
524
|
+
reduceMotion
|
|
525
|
+
? { duration: 0.1 }
|
|
526
|
+
: {
|
|
527
|
+
type: 'spring',
|
|
528
|
+
stiffness: 440,
|
|
529
|
+
damping: 30,
|
|
530
|
+
mass: 0.6,
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
className="border-border/70 bg-surface/40 group/chip flex max-w-full min-w-0 items-center gap-2 rounded-lg border p-1 pr-1.5"
|
|
534
|
+
>
|
|
535
|
+
<AttachmentPreview
|
|
536
|
+
file={item.file}
|
|
537
|
+
src={item.url}
|
|
538
|
+
name={item.name}
|
|
539
|
+
kind={item.kind}
|
|
540
|
+
thumbnailClassName="size-7 rounded-md"
|
|
541
|
+
/>
|
|
542
|
+
|
|
543
|
+
<span className="text-foreground max-w-[9rem] truncate text-xs font-medium sm:max-w-[12rem]">
|
|
544
|
+
{item.name}
|
|
545
|
+
</span>
|
|
546
|
+
{item.size !== undefined ? (
|
|
547
|
+
<span className="text-muted/70 hidden font-mono text-[9px] tracking-wide uppercase sm:block">
|
|
548
|
+
{formatBytes(item.size)}
|
|
549
|
+
</span>
|
|
550
|
+
) : null}
|
|
551
|
+
|
|
552
|
+
<button
|
|
553
|
+
type="button"
|
|
554
|
+
aria-label={`Remove ${item.name}`}
|
|
555
|
+
onClick={() => removeAttachment(item.id)}
|
|
556
|
+
className="text-muted hover:text-foreground focus-visible:outline-foreground inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-md transition-colors focus-visible:outline-2 focus-visible:outline-offset-2"
|
|
557
|
+
>
|
|
558
|
+
<IconX
|
|
559
|
+
size={13}
|
|
560
|
+
stroke={1.8}
|
|
561
|
+
aria-hidden="true"
|
|
562
|
+
className="transition-transform duration-300 group-hover/chip:rotate-90"
|
|
563
|
+
/>
|
|
564
|
+
</button>
|
|
565
|
+
</motion.div>
|
|
566
|
+
)
|
|
567
|
+
})}
|
|
568
|
+
</AnimatePresence>
|
|
569
|
+
</div>
|
|
570
|
+
</motion.div>
|
|
571
|
+
) : null}
|
|
572
|
+
</AnimatePresence>
|
|
573
|
+
|
|
574
|
+
<div className="flex items-end gap-2 p-2.5 sm:gap-3 sm:p-3">
|
|
575
|
+
{hasActions ? (
|
|
576
|
+
<motion.button
|
|
577
|
+
type="button"
|
|
578
|
+
ref={menuTriggerRef}
|
|
579
|
+
data-chat-input-trigger=""
|
|
580
|
+
onClick={() => setMenuOpen((open) => !open)}
|
|
581
|
+
aria-label={menuOpen ? 'Close attachment options' : menuLabel}
|
|
582
|
+
aria-haspopup="dialog"
|
|
583
|
+
aria-expanded={menuOpen}
|
|
584
|
+
aria-controls={`${rootId}-attachment-dialog`}
|
|
585
|
+
disabled={disabled}
|
|
586
|
+
whileTap={reduceMotion ? undefined : { scale: 0.9 }}
|
|
587
|
+
className="border-border/70 bg-surface/40 text-muted hover:border-foreground/40 hover:text-foreground focus-visible:outline-foreground group/plus relative flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-xl border transition-colors duration-200 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-50 sm:size-9"
|
|
588
|
+
>
|
|
589
|
+
<span
|
|
590
|
+
aria-hidden="true"
|
|
591
|
+
className="pointer-events-none absolute inset-0 rounded-[inherit] bg-[linear-gradient(145deg,rgba(255,255,255,0.14)_0%,transparent_48%,rgba(0,0,0,0.06)_100%)] opacity-0 transition-opacity duration-200 group-hover/plus:opacity-100"
|
|
592
|
+
/>
|
|
593
|
+
<motion.span
|
|
594
|
+
aria-hidden="true"
|
|
595
|
+
animate={{ rotate: menuOpen ? 45 : 0 }}
|
|
596
|
+
transition={
|
|
597
|
+
reduceMotion
|
|
598
|
+
? { duration: 0 }
|
|
599
|
+
: { type: 'spring', stiffness: 480, damping: 22 }
|
|
600
|
+
}
|
|
601
|
+
className="relative flex items-center justify-center"
|
|
602
|
+
>
|
|
603
|
+
<IconPlus size={17} stroke={1.8} />
|
|
604
|
+
</motion.span>
|
|
605
|
+
</motion.button>
|
|
606
|
+
) : null}
|
|
607
|
+
|
|
608
|
+
<div className="relative min-w-0 flex-1">
|
|
609
|
+
<textarea
|
|
610
|
+
ref={fieldRef}
|
|
611
|
+
value={value}
|
|
612
|
+
onChange={(event) => updateValue(event.target.value)}
|
|
613
|
+
onKeyDown={handleFieldKeyDown}
|
|
614
|
+
placeholder={listening ? '' : placeholder}
|
|
615
|
+
aria-label={label}
|
|
616
|
+
rows={1}
|
|
617
|
+
maxLength={maxLength}
|
|
618
|
+
enterKeyHint="send"
|
|
619
|
+
spellCheck={false}
|
|
620
|
+
disabled={disabled}
|
|
621
|
+
className={cn(
|
|
622
|
+
'placeholder:text-muted/70 text-foreground block w-full resize-none bg-transparent px-1 py-2 text-sm leading-6 outline-none disabled:cursor-not-allowed motion-safe:transition-[height] motion-safe:duration-200',
|
|
623
|
+
textareaClassName,
|
|
624
|
+
)}
|
|
625
|
+
/>
|
|
626
|
+
|
|
627
|
+
<AnimatePresence>
|
|
628
|
+
{listening && value.length === 0 ? (
|
|
629
|
+
<motion.div
|
|
630
|
+
aria-hidden="true"
|
|
631
|
+
initial={reduceMotion ? { opacity: 0 } : { opacity: 0, y: 5 }}
|
|
632
|
+
animate={{ opacity: 1, y: 0 }}
|
|
633
|
+
exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: -5 }}
|
|
634
|
+
transition={{ duration: reduceMotion ? 0 : 0.18 }}
|
|
635
|
+
className="pointer-events-none absolute inset-0 flex items-center gap-2.5 px-1 py-2"
|
|
636
|
+
>
|
|
637
|
+
<Equalizer reduceMotion={reduceMotion} />
|
|
638
|
+
<span className="text-muted text-sm">Listening…</span>
|
|
639
|
+
</motion.div>
|
|
640
|
+
) : null}
|
|
641
|
+
</AnimatePresence>
|
|
642
|
+
</div>
|
|
643
|
+
|
|
644
|
+
<div className="flex shrink-0 items-center gap-1 sm:gap-1.5">
|
|
645
|
+
{showVoice ? (
|
|
646
|
+
<VoiceButton
|
|
647
|
+
listening={listening}
|
|
648
|
+
disabled={disabled}
|
|
649
|
+
onClick={toggleListening}
|
|
650
|
+
startLabel={startVoiceLabel}
|
|
651
|
+
stopLabel={stopVoiceLabel}
|
|
652
|
+
/>
|
|
653
|
+
) : null}
|
|
654
|
+
<SendButton
|
|
655
|
+
state={sendState === 'busy' ? 'sending' : sendState}
|
|
656
|
+
disabled={disabled}
|
|
657
|
+
label={submitLabel}
|
|
658
|
+
shakeControls={shakeControls}
|
|
659
|
+
onClick={submit}
|
|
660
|
+
onStop={onStop}
|
|
661
|
+
/>
|
|
662
|
+
</div>
|
|
663
|
+
</div>
|
|
664
|
+
|
|
665
|
+
<input
|
|
666
|
+
ref={fileInputRef}
|
|
667
|
+
type="file"
|
|
668
|
+
tabIndex={-1}
|
|
669
|
+
aria-hidden="true"
|
|
670
|
+
onChange={handleFiles}
|
|
671
|
+
className="sr-only"
|
|
672
|
+
/>
|
|
673
|
+
<AttachmentDialog
|
|
674
|
+
id={`${rootId}-attachment-dialog`}
|
|
675
|
+
anchorRef={menuTriggerRef}
|
|
676
|
+
open={menuOpen}
|
|
677
|
+
title={menuLabel}
|
|
678
|
+
options={
|
|
679
|
+
actions?.map((action) => ({
|
|
680
|
+
...action,
|
|
681
|
+
description: action.description ?? action.hint,
|
|
682
|
+
})) ?? []
|
|
683
|
+
}
|
|
684
|
+
onSelect={runAction}
|
|
685
|
+
onClose={() => closeMenu(true)}
|
|
686
|
+
accentColor={
|
|
687
|
+
accentColor ?? (typeof glow === 'object' ? glow.color : undefined)
|
|
688
|
+
}
|
|
689
|
+
/>
|
|
690
|
+
</div>
|
|
691
|
+
)
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
export default AiChatInput
|