@adea-ai/ui 0.155.0 → 0.156.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NOTICE +27 -0
- package/dist/components/composites/model-selector/model-selector.js +45 -53
- package/dist/components/composites/model-selector/model-selector.js.map +1 -1
- package/dist/components/composites/prompt-input/index.d.ts +2 -0
- package/dist/components/composites/prompt-input/index.d.ts.map +1 -0
- package/dist/components/composites/prompt-input/index.js +1 -0
- package/dist/components/composites/prompt-input/prompt-input.d.ts +71 -0
- package/dist/components/composites/prompt-input/prompt-input.d.ts.map +1 -0
- package/dist/components/composites/prompt-input/prompt-input.js +247 -0
- package/dist/components/composites/prompt-input/prompt-input.js.map +1 -0
- package/dist/components/conversation/chat-composer.d.ts.map +1 -1
- package/dist/components/conversation/chat-composer.js +43 -29
- package/dist/components/conversation/chat-composer.js.map +1 -1
- package/dist/components/conversation/internal/chat-composer-shell.d.ts.map +1 -1
- package/dist/components/conversation/internal/chat-composer-shell.js +155 -163
- package/dist/components/conversation/internal/chat-composer-shell.js.map +1 -1
- package/dist/components/conversation/message-composer.d.ts.map +1 -1
- package/dist/components/conversation/message-composer.js +186 -192
- package/dist/components/conversation/message-composer.js.map +1 -1
- package/dist/components/conversation/paste-token-editor.js +2 -2
- package/dist/components/conversation/paste-token-editor.js.map +1 -1
- package/dist/components/theme/theme-provider-value.d.ts.map +1 -1
- package/dist/components/theme/theme-provider-value.js +9 -1
- package/dist/components/theme/theme-provider-value.js.map +1 -1
- package/dist/components/ui/badge/badge.js +1 -1
- package/dist/components/ui/badge/badge.js.map +1 -1
- package/dist/components/ui/input-group/index.d.ts +1 -1
- package/dist/components/ui/input-group/index.d.ts.map +1 -1
- package/dist/components/ui/input-group/index.js +2 -2
- package/dist/components/ui/input-group/input-group.d.ts +34 -9
- package/dist/components/ui/input-group/input-group.d.ts.map +1 -1
- package/dist/components/ui/input-group/input-group.js +101 -28
- package/dist/components/ui/input-group/input-group.js.map +1 -1
- package/dist/components/ui/kbd/kbd.d.ts.map +1 -1
- package/dist/components/ui/kbd/kbd.js +6 -1
- package/dist/components/ui/kbd/kbd.js.map +1 -1
- package/dist/components/ui/message/index.d.ts +1 -1
- package/dist/components/ui/message/index.d.ts.map +1 -1
- package/dist/components/ui/message/index.js +2 -2
- package/dist/components/ui/message/message.d.ts +16 -0
- package/dist/components/ui/message/message.d.ts.map +1 -1
- package/dist/components/ui/message/message.js +52 -1
- package/dist/components/ui/message/message.js.map +1 -1
- package/dist/components/ui/tooltip/tooltip.js +1 -1
- package/dist/components/ui/tooltip/tooltip.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/lib/overlay.d.ts +5 -5
- package/dist/lib/overlay.d.ts.map +1 -1
- package/dist/lib/overlay.js +5 -5
- package/dist/lib/overlay.js.map +1 -1
- package/dist/r/conversation.json +1 -2
- package/dist/r/input-group.json +1 -0
- package/dist/r/message.json +4 -1
- package/dist/r/model-selector.json +1 -1
- package/dist/r/prompt-input.json +28 -0
- package/dist/r/registry.json +35 -4
- package/dist/r/src/components/composites/model-selector/model-selector.tsx +19 -25
- package/dist/r/src/components/composites/prompt-input/index.ts +15 -0
- package/dist/r/src/components/composites/prompt-input/prompt-input.tsx +267 -0
- package/dist/r/src/components/conversation/chat-composer.tsx +4 -2
- package/dist/r/src/components/conversation/internal/chat-composer-shell.tsx +27 -38
- package/dist/r/src/components/conversation/message-composer.tsx +93 -97
- package/dist/r/src/components/conversation/paste-token-editor.tsx +2 -2
- package/dist/r/src/components/theme/theme-provider-value.ts +7 -4
- package/dist/r/src/components/ui/badge/badge.tsx +1 -1
- package/dist/r/src/components/ui/input-group/index.ts +3 -0
- package/dist/r/src/components/ui/input-group/input-group.tsx +121 -29
- package/dist/r/src/components/ui/kbd/kbd.tsx +3 -0
- package/dist/r/src/components/ui/message/index.ts +3 -0
- package/dist/r/src/components/ui/message/message.tsx +56 -0
- package/dist/r/src/components/ui/tooltip/tooltip.tsx +1 -1
- package/dist/r/src/lib/overlay.ts +5 -6
- package/package.json +1 -1
- package/registry.json +35 -4
- package/src/components/composites/model-selector/model-selector.tsx +19 -25
- package/src/components/composites/prompt-input/index.ts +15 -0
- package/src/components/composites/prompt-input/prompt-input.tsx +267 -0
- package/src/components/conversation/chat-composer.tsx +4 -2
- package/src/components/conversation/internal/chat-composer-shell.tsx +27 -38
- package/src/components/conversation/message-composer.tsx +93 -97
- package/src/components/conversation/paste-token-editor.tsx +2 -2
- package/src/components/theme/theme-provider-value.ts +7 -4
- package/src/components/ui/badge/badge.tsx +1 -1
- package/src/components/ui/input-group/index.ts +3 -0
- package/src/components/ui/input-group/input-group.tsx +121 -29
- package/src/components/ui/kbd/kbd.tsx +3 -0
- package/src/components/ui/message/index.ts +3 -0
- package/src/components/ui/message/message.tsx +56 -0
- package/src/components/ui/tooltip/tooltip.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/lib/overlay.ts +5 -6
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Part structure and names ported from Vercel AI Elements prompt-input.tsx
|
|
3
|
+
* (https://elements.ai-sdk.dev, Apache-2.0). The control pill is ported from
|
|
4
|
+
* T3 Code apps/web/src/components/chat/ComposerControl.tsx and the card from
|
|
5
|
+
* ComposerSurface.tsx at ff7aa5ace3 (MIT, Copyright (c) T3 Tools Inc.).
|
|
6
|
+
* Translated from React to Solid onto this library's InputGroup, Button and
|
|
7
|
+
* ActionButton. See NOTICE.
|
|
8
|
+
*/
|
|
9
|
+
import { ArrowUp, Square, X } from 'lucide-solid'
|
|
10
|
+
import {
|
|
11
|
+
Show,
|
|
12
|
+
children as resolveChildren,
|
|
13
|
+
splitProps,
|
|
14
|
+
type ComponentProps,
|
|
15
|
+
type JSX,
|
|
16
|
+
type ValidComponent,
|
|
17
|
+
} from 'solid-js'
|
|
18
|
+
import { callHandler } from '#lib/events'
|
|
19
|
+
import { cn } from '#lib/utils'
|
|
20
|
+
import { Button, type ButtonProps } from '../../ui/button'
|
|
21
|
+
import { InputGroup, InputGroupAddon, InputGroupTextarea } from '../../ui/input-group'
|
|
22
|
+
import { Spinner } from '../../ui/spinner'
|
|
23
|
+
import { ActionButton, type ActionButtonProps } from '../action-button'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* PromptInput.
|
|
27
|
+
*
|
|
28
|
+
* The one box a person writes to an agent in. It is shadcn's InputGroup in its
|
|
29
|
+
* column form: an optional header row (attachments, a reply strip), the field,
|
|
30
|
+
* and a footer row of tools on the left and the submit control on the right.
|
|
31
|
+
* Every chat surface draws this box, so the agent view, the dev chat and a new
|
|
32
|
+
* thread page cannot drift apart in radius, focus ring or button placement.
|
|
33
|
+
*
|
|
34
|
+
* It knows nothing about drafts, sending or keys beyond Enter. The composers in
|
|
35
|
+
* `conversation/` own those and render their chrome through these parts.
|
|
36
|
+
*/
|
|
37
|
+
export type PromptInputProps = Omit<ComponentProps<'form'>, 'onSubmit'> & {
|
|
38
|
+
onSubmit?: JSX.EventHandlerUnion<HTMLFormElement, SubmitEvent>
|
|
39
|
+
/** Classes for the box itself; `class` lands on the form. */
|
|
40
|
+
groupClass?: string
|
|
41
|
+
/** Dims the box. The field and buttons carry their own disabled state. */
|
|
42
|
+
disabled?: boolean
|
|
43
|
+
/** Rendered inside the form above the box: a mention menu, a reply strip. */
|
|
44
|
+
before?: JSX.Element
|
|
45
|
+
/** Rendered inside the form under the box: a hint, a live status region. */
|
|
46
|
+
after?: JSX.Element
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function PromptInput(props: PromptInputProps) {
|
|
50
|
+
const [local, rest] = splitProps(props, [
|
|
51
|
+
'class',
|
|
52
|
+
'groupClass',
|
|
53
|
+
'children',
|
|
54
|
+
'onSubmit',
|
|
55
|
+
'disabled',
|
|
56
|
+
'before',
|
|
57
|
+
'after',
|
|
58
|
+
])
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<form
|
|
62
|
+
data-slot="prompt-input"
|
|
63
|
+
class={cn('flex w-full flex-col gap-2', local.class)}
|
|
64
|
+
onSubmit={(event) => {
|
|
65
|
+
event.preventDefault()
|
|
66
|
+
callHandler(local.onSubmit, event)
|
|
67
|
+
}}
|
|
68
|
+
{...rest}
|
|
69
|
+
>
|
|
70
|
+
{local.before}
|
|
71
|
+
<InputGroup
|
|
72
|
+
data-disabled={local.disabled ? '' : undefined}
|
|
73
|
+
class={cn(
|
|
74
|
+
'bg-card h-auto gap-0 overflow-hidden rounded-2xl px-0 shadow-xs',
|
|
75
|
+
'data-[disabled]:opacity-50',
|
|
76
|
+
local.groupClass
|
|
77
|
+
)}
|
|
78
|
+
>
|
|
79
|
+
{local.children}
|
|
80
|
+
</InputGroup>
|
|
81
|
+
{local.after}
|
|
82
|
+
</form>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A row above the field: staged attachments, a reply target, a context chip. */
|
|
87
|
+
export function PromptInputHeader(props: ComponentProps<'div'>) {
|
|
88
|
+
const [local, rest] = splitProps(props, ['class'])
|
|
89
|
+
return (
|
|
90
|
+
<InputGroupAddon
|
|
91
|
+
align="block-start"
|
|
92
|
+
data-slot="prompt-input-header"
|
|
93
|
+
class={cn('flex-wrap gap-1 px-3', local.class)}
|
|
94
|
+
{...rest}
|
|
95
|
+
/>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Wraps a custom field (a token editor) so it spans the box like the textarea. */
|
|
100
|
+
export function PromptInputBody(props: ComponentProps<'div'>) {
|
|
101
|
+
const [local, rest] = splitProps(props, ['class'])
|
|
102
|
+
return <div data-slot="prompt-input-body" class={cn('w-full min-w-0', local.class)} {...rest} />
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type PromptInputTextareaProps = ComponentProps<'textarea'> & {
|
|
106
|
+
/**
|
|
107
|
+
* Enter submits the form and Shift+Enter breaks the line, unless an IME is
|
|
108
|
+
* composing. A composer that runs its own key policy passes false.
|
|
109
|
+
*/
|
|
110
|
+
submitOnEnter?: boolean
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function PromptInputTextarea(props: PromptInputTextareaProps) {
|
|
114
|
+
const [local, rest] = splitProps(props, ['class', 'submitOnEnter', 'onKeyDown'])
|
|
115
|
+
return (
|
|
116
|
+
<InputGroupTextarea
|
|
117
|
+
data-slot="prompt-input-textarea"
|
|
118
|
+
placeholder="Write a message…"
|
|
119
|
+
class={cn('min-h-11 px-3 pt-3', local.class)}
|
|
120
|
+
onKeyDown={(event) => {
|
|
121
|
+
callHandler(local.onKeyDown, event)
|
|
122
|
+
if (local.submitOnEnter === false || event.defaultPrevented) return
|
|
123
|
+
if (event.key !== 'Enter' || event.shiftKey || event.isComposing) return
|
|
124
|
+
event.preventDefault()
|
|
125
|
+
event.currentTarget.form?.requestSubmit()
|
|
126
|
+
}}
|
|
127
|
+
{...rest}
|
|
128
|
+
/>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The row under the field: tools on the start edge, submit on the end. */
|
|
133
|
+
export function PromptInputFooter(props: ComponentProps<'div'>) {
|
|
134
|
+
const [local, rest] = splitProps(props, ['class'])
|
|
135
|
+
return (
|
|
136
|
+
<InputGroupAddon
|
|
137
|
+
align="block-end"
|
|
138
|
+
data-slot="prompt-input-footer"
|
|
139
|
+
class={cn('justify-between gap-2 px-2', local.class)}
|
|
140
|
+
{...rest}
|
|
141
|
+
/>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** A group of tools in the footer, kept on one line. */
|
|
146
|
+
export function PromptInputTools(props: ComponentProps<'div'>) {
|
|
147
|
+
const [local, rest] = splitProps(props, ['class'])
|
|
148
|
+
return (
|
|
149
|
+
<div
|
|
150
|
+
data-slot="prompt-input-tools"
|
|
151
|
+
class={cn('flex min-w-0 items-center gap-1', local.class)}
|
|
152
|
+
{...rest}
|
|
153
|
+
/>
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* An icon tool in the footer (attach, dictate, mention). Always carries a
|
|
159
|
+
* tooltip, because an icon alone does not say what it does.
|
|
160
|
+
*/
|
|
161
|
+
export function PromptInputButton<T extends ValidComponent = 'button'>(
|
|
162
|
+
props: ActionButtonProps<T>
|
|
163
|
+
) {
|
|
164
|
+
return (
|
|
165
|
+
<ActionButton
|
|
166
|
+
type="button"
|
|
167
|
+
variant="ghost"
|
|
168
|
+
size="icon-sm"
|
|
169
|
+
data-slot="prompt-input-button"
|
|
170
|
+
tooltipSide="top"
|
|
171
|
+
{...(props as ActionButtonProps)}
|
|
172
|
+
/>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A labelled control in the footer: a model, an effort, a mode, a location.
|
|
178
|
+
* T3's ComposerControl: a ghost pill in muted text that brightens on hover and
|
|
179
|
+
* holds the accent tint while its menu is open. Use it as a menu trigger with
|
|
180
|
+
* `as={PromptInputControl}`, or directly as a toggle with `aria-pressed`.
|
|
181
|
+
*/
|
|
182
|
+
export function PromptInputControl<T extends ValidComponent = 'button'>(props: ButtonProps<T>) {
|
|
183
|
+
const [local, rest] = splitProps(props as ButtonProps, ['class'])
|
|
184
|
+
return (
|
|
185
|
+
<Button
|
|
186
|
+
variant="toolbar"
|
|
187
|
+
size="sm"
|
|
188
|
+
data-slot="prompt-input-control"
|
|
189
|
+
class={cn(
|
|
190
|
+
'text-muted-foreground hover:text-foreground min-w-0 font-normal',
|
|
191
|
+
'aria-pressed:bg-primary-subtle aria-pressed:text-primary',
|
|
192
|
+
'[&_[data-control-label]]:truncate',
|
|
193
|
+
local.class
|
|
194
|
+
)}
|
|
195
|
+
{...rest}
|
|
196
|
+
/>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type PromptInputStatus = 'ready' | 'submitted' | 'streaming' | 'error'
|
|
201
|
+
|
|
202
|
+
export type PromptInputSubmitProps = Omit<ActionButtonProps, 'children' | 'tooltip'> & {
|
|
203
|
+
/** Drives the glyph: arrow, spinner, stop square, or a cross after a failure. */
|
|
204
|
+
status?: PromptInputStatus
|
|
205
|
+
/** While streaming, the button stops the turn instead of submitting. */
|
|
206
|
+
onStop?: () => void
|
|
207
|
+
/** The action's name. Defaults to "Send message", or "Stop" while streaming. */
|
|
208
|
+
label?: string
|
|
209
|
+
children?: JSX.Element
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The send control. A filled circle at the end of the footer, as in T3 and
|
|
214
|
+
* AI Elements; while a turn streams and `onStop` is given it becomes Stop.
|
|
215
|
+
*/
|
|
216
|
+
export function PromptInputSubmit(props: PromptInputSubmitProps) {
|
|
217
|
+
const [local, rest] = splitProps(props, [
|
|
218
|
+
'status',
|
|
219
|
+
'onStop',
|
|
220
|
+
'label',
|
|
221
|
+
'children',
|
|
222
|
+
'class',
|
|
223
|
+
'onClick',
|
|
224
|
+
])
|
|
225
|
+
const custom = resolveChildren(() => local.children)
|
|
226
|
+
const stopping = () => local.status === 'streaming' && local.onStop !== undefined
|
|
227
|
+
const label = () => local.label ?? (stopping() ? 'Stop' : 'Send message')
|
|
228
|
+
|
|
229
|
+
return (
|
|
230
|
+
<ActionButton
|
|
231
|
+
type={stopping() ? 'button' : 'submit'}
|
|
232
|
+
variant="default"
|
|
233
|
+
size="icon-sm"
|
|
234
|
+
data-slot="prompt-input-submit"
|
|
235
|
+
data-status={local.status ?? 'ready'}
|
|
236
|
+
aria-label={label()}
|
|
237
|
+
tooltip={label()}
|
|
238
|
+
tooltipSide="top"
|
|
239
|
+
class={cn('rounded-full', local.class)}
|
|
240
|
+
onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
|
|
241
|
+
if (stopping()) {
|
|
242
|
+
event.preventDefault()
|
|
243
|
+
local.onStop?.()
|
|
244
|
+
return
|
|
245
|
+
}
|
|
246
|
+
callHandler(local.onClick as JSX.EventHandlerUnion<HTMLButtonElement, MouseEvent>, event)
|
|
247
|
+
}}
|
|
248
|
+
{...(rest as ActionButtonProps)}
|
|
249
|
+
>
|
|
250
|
+
<Show when={custom()} fallback={<SubmitGlyph status={local.status} stop={stopping()} />}>
|
|
251
|
+
{custom()}
|
|
252
|
+
</Show>
|
|
253
|
+
</ActionButton>
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function SubmitGlyph(props: { status?: PromptInputStatus; stop: boolean }) {
|
|
258
|
+
return (
|
|
259
|
+
<Show when={!props.stop} fallback={<Square class="fill-current" />}>
|
|
260
|
+
<Show when={props.status !== 'submitted'} fallback={<Spinner size="sm" label={false} />}>
|
|
261
|
+
<Show when={props.status !== 'error'} fallback={<X />}>
|
|
262
|
+
<ArrowUp />
|
|
263
|
+
</Show>
|
|
264
|
+
</Show>
|
|
265
|
+
</Show>
|
|
266
|
+
)
|
|
267
|
+
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { JSX } from 'solid-js'
|
|
8
8
|
import type { BusySendButtonProps, BusySendMode } from './busy-send-button'
|
|
9
|
+
import { PromptInputTextarea } from '../composites/prompt-input'
|
|
9
10
|
import { ChatComposerShell } from './internal/chat-composer-shell'
|
|
10
11
|
|
|
11
12
|
export type ChatComposerControl = {
|
|
@@ -63,11 +64,12 @@ export function ChatComposer(props: ChatComposerProps) {
|
|
|
63
64
|
{...props}
|
|
64
65
|
createSubmitExtra={() => ({})}
|
|
65
66
|
renderInput={(input) => (
|
|
66
|
-
<
|
|
67
|
+
<PromptInputTextarea
|
|
67
68
|
ref={input.ref}
|
|
68
69
|
data-slot="composer-input"
|
|
70
|
+
submitOnEnter={false}
|
|
69
71
|
aria-label={input.inputLabel()}
|
|
70
|
-
class="
|
|
72
|
+
class="max-h-36 py-3"
|
|
71
73
|
value={input.value()}
|
|
72
74
|
onInput={(event) => props.onValueChange(event.currentTarget.value)}
|
|
73
75
|
disabled={input.disabled()}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
ChevronsDownUp as LucideChevronsDownUp,
|
|
9
9
|
ChevronsUpDown as LucideChevronsUpDown,
|
|
10
10
|
MoreHorizontal as LucideMoreHorizontal,
|
|
11
|
-
ArrowUp as LucideArrowUp,
|
|
12
11
|
} from 'lucide-solid'
|
|
13
12
|
import { Show, createEffect, on, onCleanup, onMount, type Accessor, type JSX } from 'solid-js'
|
|
14
13
|
import type {
|
|
@@ -23,7 +22,14 @@ import {
|
|
|
23
22
|
DropdownMenuItem,
|
|
24
23
|
DropdownMenuTrigger,
|
|
25
24
|
} from '../../ui/dropdown-menu'
|
|
26
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
PromptInput,
|
|
27
|
+
PromptInputButton,
|
|
28
|
+
PromptInputFooter,
|
|
29
|
+
PromptInputHeader,
|
|
30
|
+
PromptInputSubmit,
|
|
31
|
+
PromptInputTools,
|
|
32
|
+
} from '../../composites/prompt-input'
|
|
27
33
|
import { BusySendButton, type BusySendMode } from '../busy-send-button'
|
|
28
34
|
import { createComposerCore } from '../composer-core'
|
|
29
35
|
import { fastIcon } from '#lib/fast-icon'
|
|
@@ -32,7 +38,6 @@ import { fastIcon } from '#lib/fast-icon'
|
|
|
32
38
|
const ChevronsDownUp = fastIcon(LucideChevronsDownUp)
|
|
33
39
|
const ChevronsUpDown = fastIcon(LucideChevronsUpDown)
|
|
34
40
|
const MoreHorizontal = fastIcon(LucideMoreHorizontal)
|
|
35
|
-
const ArrowUp = fastIcon(LucideArrowUp)
|
|
36
41
|
|
|
37
42
|
/** Private typed seam: public wrappers supply the native or atomic input. */
|
|
38
43
|
type ChatComposerInputRenderProps = {
|
|
@@ -279,17 +284,16 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
|
|
|
279
284
|
</Button>
|
|
280
285
|
}
|
|
281
286
|
>
|
|
282
|
-
<
|
|
287
|
+
<PromptInput
|
|
283
288
|
data-slot="composer-input-box"
|
|
284
|
-
|
|
285
|
-
onSubmit={(
|
|
286
|
-
event.preventDefault()
|
|
287
|
-
submit()
|
|
288
|
-
}}
|
|
289
|
+
disabled={props.disabled}
|
|
290
|
+
onSubmit={() => submit()}
|
|
289
291
|
>
|
|
290
292
|
<Show when={props.attachments}>
|
|
291
293
|
{(attachmentsSlot) => (
|
|
292
|
-
<
|
|
294
|
+
<PromptInputHeader data-slot="composer-staged-content">
|
|
295
|
+
{attachmentsSlot()}
|
|
296
|
+
</PromptInputHeader>
|
|
293
297
|
)}
|
|
294
298
|
</Show>
|
|
295
299
|
{props.renderInput({
|
|
@@ -316,19 +320,14 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
|
|
|
316
320
|
onBlur: composer.onBlur,
|
|
317
321
|
onKeyDown: handleInputKeyDown,
|
|
318
322
|
})}
|
|
319
|
-
<
|
|
320
|
-
|
|
321
|
-
class="flex items-center justify-between gap-2 px-2.5 pb-2 pt-0.5"
|
|
322
|
-
>
|
|
323
|
-
<div class="flex min-w-0 items-center gap-1">
|
|
323
|
+
<PromptInputFooter data-slot="composer-action-row">
|
|
324
|
+
<PromptInputTools>
|
|
324
325
|
<Show when={props.collapse || props.menuItems}>
|
|
325
326
|
<DropdownMenu placement="top-start">
|
|
326
327
|
<DropdownMenuTrigger
|
|
327
|
-
as={
|
|
328
|
-
type="button"
|
|
329
|
-
variant="ghost"
|
|
330
|
-
size="icon-sm"
|
|
328
|
+
as={PromptInputButton}
|
|
331
329
|
aria-label="Message input options"
|
|
330
|
+
tooltip="Options"
|
|
332
331
|
>
|
|
333
332
|
<MoreHorizontal />
|
|
334
333
|
</DropdownMenuTrigger>
|
|
@@ -341,34 +340,24 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
|
|
|
341
340
|
<Show when={props.collapse}>
|
|
342
341
|
<DropdownMenuItem onSelect={() => changeCollapsed(true)}>
|
|
343
342
|
<ChevronsDownUp />
|
|
344
|
-
|
|
345
|
-
<span>Collapse the message input</span>
|
|
346
|
-
<span class="text-muted-foreground text-xs">
|
|
347
|
-
Make room to read; keep your draft
|
|
348
|
-
</span>
|
|
349
|
-
</div>
|
|
343
|
+
Collapse the message input
|
|
350
344
|
</DropdownMenuItem>
|
|
351
345
|
</Show>
|
|
352
346
|
</DropdownMenuContent>
|
|
353
347
|
</DropdownMenu>
|
|
354
348
|
</Show>
|
|
355
349
|
{props.leadingActions}
|
|
356
|
-
</
|
|
357
|
-
<
|
|
350
|
+
</PromptInputTools>
|
|
351
|
+
<PromptInputTools class="shrink-0">
|
|
358
352
|
{props.trailingActions}
|
|
359
353
|
<Show
|
|
360
354
|
when={props.busy}
|
|
361
355
|
fallback={
|
|
362
|
-
<
|
|
363
|
-
|
|
364
|
-
size="icon-sm"
|
|
356
|
+
<PromptInputSubmit
|
|
357
|
+
status={pending() ? 'submitted' : 'ready'}
|
|
365
358
|
disabled={!canSend()}
|
|
366
359
|
aria-label={pending() ? 'Sending message' : 'Send message'}
|
|
367
|
-
|
|
368
|
-
<Show when={pending()} fallback={<ArrowUp />}>
|
|
369
|
-
<Spinner size="sm" label={false} />
|
|
370
|
-
</Show>
|
|
371
|
-
</Button>
|
|
360
|
+
/>
|
|
372
361
|
}
|
|
373
362
|
>
|
|
374
363
|
{(busy) => (
|
|
@@ -384,9 +373,9 @@ export function ChatComposerShell<Extra extends object>(props: ChatComposerShell
|
|
|
384
373
|
/>
|
|
385
374
|
)}
|
|
386
375
|
</Show>
|
|
387
|
-
</
|
|
388
|
-
</
|
|
389
|
-
</
|
|
376
|
+
</PromptInputTools>
|
|
377
|
+
</PromptInputFooter>
|
|
378
|
+
</PromptInput>
|
|
390
379
|
<Show when={props.context}>
|
|
391
380
|
{(contextSlot) => (
|
|
392
381
|
<div data-slot="composer-context" class="flex min-w-0 items-center gap-2 pt-1">
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CornerDownLeft as LucideCornerDownLeft,
|
|
3
3
|
Paperclip as LucidePaperclip,
|
|
4
|
-
Send as LucideSend,
|
|
5
4
|
X as LucideX,
|
|
6
5
|
} from 'lucide-solid'
|
|
7
6
|
import type { ComponentProps, JSX, Ref } from 'solid-js'
|
|
@@ -11,15 +10,20 @@ import { cn } from '#lib/utils'
|
|
|
11
10
|
import { ActionButton } from '../composites/action-button'
|
|
12
11
|
import { Button } from '../ui/button'
|
|
13
12
|
import { Kbd } from '../ui/kbd'
|
|
14
|
-
import {
|
|
15
|
-
|
|
13
|
+
import {
|
|
14
|
+
PromptInput,
|
|
15
|
+
PromptInputFooter,
|
|
16
|
+
PromptInputHeader,
|
|
17
|
+
PromptInputSubmit,
|
|
18
|
+
PromptInputTextarea,
|
|
19
|
+
PromptInputTools,
|
|
20
|
+
} from '../composites/prompt-input'
|
|
16
21
|
import { createComposerCore } from './composer-core'
|
|
17
22
|
import { fastIcon } from '#lib/fast-icon'
|
|
18
23
|
|
|
19
24
|
// lucide icons drawn from a cloned template (see fastIcon).
|
|
20
25
|
const CornerDownLeft = fastIcon(LucideCornerDownLeft)
|
|
21
26
|
const Paperclip = fastIcon(LucidePaperclip)
|
|
22
|
-
const Send = fastIcon(LucideSend)
|
|
23
27
|
const X = fastIcon(LucideX)
|
|
24
28
|
|
|
25
29
|
/**
|
|
@@ -156,22 +160,50 @@ export function MessageComposer(props: MessageComposerProps) {
|
|
|
156
160
|
}
|
|
157
161
|
|
|
158
162
|
return (
|
|
159
|
-
<
|
|
163
|
+
<PromptInput
|
|
160
164
|
data-slot="message-composer"
|
|
161
|
-
class={
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
send()
|
|
165
|
-
}}
|
|
165
|
+
class={local.class}
|
|
166
|
+
disabled={local.disabled}
|
|
167
|
+
onSubmit={() => send()}
|
|
166
168
|
onKeyDown={onFormKeyDown}
|
|
169
|
+
before={<Show when={local.menu}>{(menuSlot) => <div>{menuSlot()}</div>}</Show>}
|
|
170
|
+
after={
|
|
171
|
+
<>
|
|
172
|
+
<Show when={local.showHint}>
|
|
173
|
+
<p class="text-muted-foreground flex items-center gap-1.5 text-2xs">
|
|
174
|
+
<Kbd>Enter</Kbd> to send
|
|
175
|
+
<span aria-hidden="true">·</span>
|
|
176
|
+
<Kbd>Shift</Kbd> <Kbd>Enter</Kbd> for a new line
|
|
177
|
+
</p>
|
|
178
|
+
</Show>
|
|
179
|
+
|
|
180
|
+
{/* A live region, so the outcome is announced without moving focus out of the
|
|
181
|
+
field the user is typing in. */}
|
|
182
|
+
<div role="status" aria-live="polite" class="min-h-0">
|
|
183
|
+
<Show
|
|
184
|
+
when={sending()}
|
|
185
|
+
fallback={
|
|
186
|
+
<Show when={composer.error()}>
|
|
187
|
+
{(message) => (
|
|
188
|
+
<p class="text-foreground border-s-2 border-destructive ps-2 text-xs">
|
|
189
|
+
{message()}
|
|
190
|
+
</p>
|
|
191
|
+
)}
|
|
192
|
+
</Show>
|
|
193
|
+
}
|
|
194
|
+
>
|
|
195
|
+
{pendingLabel()}…
|
|
196
|
+
</Show>
|
|
197
|
+
<Show when={local.status}>{(statusSlot) => <>{statusSlot()}</>}</Show>
|
|
198
|
+
</div>
|
|
199
|
+
</>
|
|
200
|
+
}
|
|
167
201
|
{...rest}
|
|
168
202
|
>
|
|
169
|
-
<Show when={local.menu}>{(menuSlot) => <div>{menuSlot()}</div>}</Show>
|
|
170
|
-
|
|
171
203
|
<Show when={local.replyTo}>
|
|
172
204
|
{(reply) => (
|
|
173
|
-
<
|
|
174
|
-
<span class="min-w-0 flex-1 truncate">Replying to {reply().label}</span>
|
|
205
|
+
<PromptInputHeader>
|
|
206
|
+
<span class="min-w-0 flex-1 truncate text-xs">Replying to {reply().label}</span>
|
|
175
207
|
<ActionButton
|
|
176
208
|
type="button"
|
|
177
209
|
variant="ghost"
|
|
@@ -182,94 +214,59 @@ export function MessageComposer(props: MessageComposerProps) {
|
|
|
182
214
|
>
|
|
183
215
|
<X />
|
|
184
216
|
</ActionButton>
|
|
185
|
-
</
|
|
217
|
+
</PromptInputHeader>
|
|
186
218
|
)}
|
|
187
219
|
</Show>
|
|
188
220
|
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
221
|
+
<PromptInputTextarea
|
|
222
|
+
ref={local.inputRef}
|
|
223
|
+
id={local.inputId}
|
|
224
|
+
submitOnEnter={false}
|
|
225
|
+
onCompositionStart={composer.onCompositionStart}
|
|
226
|
+
onCompositionEnd={composer.onCompositionEnd}
|
|
227
|
+
onFocus={composer.onFocus}
|
|
228
|
+
onBlur={composer.onBlur}
|
|
229
|
+
value={local.value}
|
|
230
|
+
onInput={(event) => local.onValueChange(event.currentTarget.value)}
|
|
231
|
+
onKeyDown={onKeyDown}
|
|
232
|
+
placeholder={local.placeholder ?? 'Write a message…'}
|
|
233
|
+
disabled={local.disabled}
|
|
234
|
+
aria-label={
|
|
235
|
+
local.inputLabel ?? (local.submitLabel ? `${local.submitLabel} message` : 'Message')
|
|
236
|
+
}
|
|
237
|
+
aria-describedby={describedBy()}
|
|
238
|
+
// InputGroupTextarea caps growth at max-h-48; `default` keeps Textarea's uncapped
|
|
239
|
+
// default size, so it lifts that cap rather than just not adding one.
|
|
240
|
+
class={cn('min-h-16', {
|
|
241
|
+
'max-h-48': (local.inputSize ?? 'comfortable') === 'comfortable',
|
|
242
|
+
'max-h-none': local.inputSize === 'default',
|
|
243
|
+
'resize-y': (local.inputResize ?? 'vertical') === 'vertical',
|
|
244
|
+
resize: local.inputResize === 'both',
|
|
245
|
+
})}
|
|
246
|
+
/>
|
|
247
|
+
<Show when={local.inputDescription}>
|
|
248
|
+
{(description) => (
|
|
249
|
+
<span id={descriptionId} class="sr-only">
|
|
250
|
+
{description()}
|
|
251
|
+
</span>
|
|
195
252
|
)}
|
|
196
|
-
>
|
|
197
|
-
<Textarea
|
|
198
|
-
ref={local.inputRef}
|
|
199
|
-
id={local.inputId}
|
|
200
|
-
onCompositionStart={composer.onCompositionStart}
|
|
201
|
-
onCompositionEnd={composer.onCompositionEnd}
|
|
202
|
-
onFocus={composer.onFocus}
|
|
203
|
-
onBlur={composer.onBlur}
|
|
204
|
-
value={local.value}
|
|
205
|
-
onInput={(event) => local.onValueChange(event.currentTarget.value)}
|
|
206
|
-
onKeyDown={onKeyDown}
|
|
207
|
-
placeholder={local.placeholder ?? 'Write a message…'}
|
|
208
|
-
disabled={local.disabled}
|
|
209
|
-
rows={1}
|
|
210
|
-
aria-label={
|
|
211
|
-
local.inputLabel ?? (local.submitLabel ? `${local.submitLabel} message` : 'Message')
|
|
212
|
-
}
|
|
213
|
-
aria-describedby={describedBy()}
|
|
214
|
-
variant="composer"
|
|
215
|
-
size={local.inputSize ?? 'comfortable'}
|
|
216
|
-
resize={local.inputResize ?? 'vertical'}
|
|
217
|
-
/>
|
|
218
|
-
<Show when={local.inputDescription}>
|
|
219
|
-
{(description) => (
|
|
220
|
-
<span id={descriptionId} class="sr-only">
|
|
221
|
-
{description()}
|
|
222
|
-
</span>
|
|
223
|
-
)}
|
|
224
|
-
</Show>
|
|
225
|
-
|
|
226
|
-
<div class="flex items-center gap-1">
|
|
227
|
-
<Show when={local.leading}>{(leadingSlot) => <>{leadingSlot()}</>}</Show>
|
|
228
|
-
<div class="ms-auto flex items-center gap-1">
|
|
229
|
-
<Show when={local.trailing}>{(trailingSlot) => <>{trailingSlot()}</>}</Show>
|
|
230
|
-
<ActionButton
|
|
231
|
-
type="submit"
|
|
232
|
-
size="icon-sm"
|
|
233
|
-
disabled={!canSend()}
|
|
234
|
-
aria-label={sending() ? pendingLabel() : actionLabel()}
|
|
235
|
-
tooltip={actionLabel()}
|
|
236
|
-
>
|
|
237
|
-
<Show when={sending()} fallback={<Send />}>
|
|
238
|
-
<Spinner size="sm" label={false} class="text-primary-foreground" />
|
|
239
|
-
</Show>
|
|
240
|
-
</ActionButton>
|
|
241
|
-
</div>
|
|
242
|
-
</div>
|
|
243
|
-
</div>
|
|
244
|
-
|
|
245
|
-
<Show when={local.showHint}>
|
|
246
|
-
<p class="text-muted-foreground flex items-center gap-1.5 text-2xs">
|
|
247
|
-
<Kbd>Enter</Kbd> to send
|
|
248
|
-
<span aria-hidden="true">·</span>
|
|
249
|
-
<Kbd>Shift</Kbd> <Kbd>Enter</Kbd> for a new line
|
|
250
|
-
</p>
|
|
251
253
|
</Show>
|
|
252
254
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
{pendingLabel()}…
|
|
269
|
-
</Show>
|
|
270
|
-
<Show when={local.status}>{(statusSlot) => <>{statusSlot()}</>}</Show>
|
|
271
|
-
</div>
|
|
272
|
-
</form>
|
|
255
|
+
<PromptInputFooter>
|
|
256
|
+
<PromptInputTools>
|
|
257
|
+
<Show when={local.leading}>{(leadingSlot) => <>{leadingSlot()}</>}</Show>
|
|
258
|
+
</PromptInputTools>
|
|
259
|
+
<PromptInputTools>
|
|
260
|
+
<Show when={local.trailing}>{(trailingSlot) => <>{trailingSlot()}</>}</Show>
|
|
261
|
+
<PromptInputSubmit
|
|
262
|
+
status={sending() ? 'submitted' : 'ready'}
|
|
263
|
+
disabled={!canSend()}
|
|
264
|
+
label={actionLabel()}
|
|
265
|
+
aria-label={sending() ? pendingLabel() : actionLabel()}
|
|
266
|
+
/>
|
|
267
|
+
</PromptInputTools>
|
|
268
|
+
</PromptInputFooter>
|
|
269
|
+
</PromptInput>
|
|
273
270
|
)
|
|
274
271
|
}
|
|
275
272
|
|
|
@@ -294,7 +291,6 @@ export function ComposerAttachmentButton(
|
|
|
294
291
|
aria-label={local.count ? `${local.count} attached, add an attachment` : 'Add an attachment'}
|
|
295
292
|
aria-expanded={local.open}
|
|
296
293
|
tooltip="Add an attachment"
|
|
297
|
-
class="text-muted-foreground"
|
|
298
294
|
{...rest}
|
|
299
295
|
>
|
|
300
296
|
{local.children ?? <Paperclip />}
|
|
@@ -718,7 +718,7 @@ export function PasteTokenEditor(props: PasteTokenEditorProps) {
|
|
|
718
718
|
ref={(element) => (mirror = element)}
|
|
719
719
|
data-slot="paste-token-mirror"
|
|
720
720
|
aria-hidden="true"
|
|
721
|
-
class="pointer-events-none absolute inset-0 overflow-hidden select-none whitespace-pre-wrap break-words px-
|
|
721
|
+
class="pointer-events-none absolute inset-0 overflow-hidden select-none whitespace-pre-wrap break-words px-3 py-3 text-sm text-transparent"
|
|
722
722
|
>
|
|
723
723
|
<For each={segments()}>
|
|
724
724
|
{(segment) =>
|
|
@@ -749,7 +749,7 @@ export function PasteTokenEditor(props: PasteTokenEditorProps) {
|
|
|
749
749
|
aria-label={props.inputLabel}
|
|
750
750
|
aria-describedby={preview() ? `${keyboardHintId} ${descriptionId}` : keyboardHintId}
|
|
751
751
|
aria-keyshortcuts="Alt+ArrowDown"
|
|
752
|
-
class="relative field-sizing-content text-foreground placeholder:text-muted-foreground min-h-11 max-h-36 w-full resize-none border-0 bg-transparent px-
|
|
752
|
+
class="relative field-sizing-content text-foreground placeholder:text-muted-foreground min-h-11 max-h-36 w-full resize-none border-0 bg-transparent px-3 py-3 text-sm outline-none disabled:opacity-50"
|
|
753
753
|
value={props.value}
|
|
754
754
|
disabled={props.disabled}
|
|
755
755
|
readOnly={props.readOnly}
|