@svadmin/ai-elements 0.1.0 → 0.3.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/README.md +45 -9
- package/dist/ai.css +35 -1
- package/dist/components/ChatDialog.svelte +93 -35
- package/dist/components/ChatDialog.svelte.d.ts +6 -0
- package/dist/components/Conversation.svelte +37 -17
- package/dist/components/Conversation.svelte.d.ts +3 -2
- package/dist/components/ConversationContent.svelte +29 -4
- package/dist/components/ConversationContent.svelte.d.ts +3 -2
- package/dist/components/ConversationEmptyState.svelte +33 -7
- package/dist/components/ConversationEmptyState.svelte.d.ts +4 -2
- package/dist/components/ConversationScrollButton.svelte +47 -2
- package/dist/components/ConversationScrollButton.svelte.d.ts +8 -2
- package/dist/components/Message.svelte +30 -16
- package/dist/components/Message.svelte.d.ts +5 -5
- package/dist/components/MessageContent.svelte +23 -4
- package/dist/components/MessageContent.svelte.d.ts +3 -2
- package/dist/components/Reasoning.svelte +51 -9
- package/dist/components/Reasoning.svelte.d.ts +4 -3
- package/dist/components/action/Action.svelte +48 -0
- package/dist/components/action/Action.svelte.d.ts +13 -0
- package/dist/components/action/Actions.svelte +12 -0
- package/dist/components/action/Actions.svelte.d.ts +9 -0
- package/dist/components/action/index.d.ts +4 -0
- package/dist/components/action/index.js +2 -0
- package/dist/components/artifact/ArtifactAction.svelte +43 -7
- package/dist/components/artifact/ArtifactAction.svelte.d.ts +5 -0
- package/dist/components/artifact/ArtifactClose.svelte +26 -6
- package/dist/components/artifact/ArtifactClose.svelte.d.ts +5 -2
- package/dist/components/artifact/index.d.ts +1 -0
- package/dist/components/audio-player/AudioPlayerControlBar.svelte +0 -1
- package/dist/components/audio-player/AudioPlayerDurationDisplay.svelte +0 -1
- package/dist/components/audio-player/AudioPlayerElement.svelte +0 -1
- package/dist/components/audio-player/AudioPlayerMuteButton.svelte +0 -1
- package/dist/components/audio-player/AudioPlayerPlayButton.svelte +0 -1
- package/dist/components/audio-player/AudioPlayerSeekBackwardButton.svelte +0 -1
- package/dist/components/audio-player/AudioPlayerSeekForwardButton.svelte +0 -1
- package/dist/components/audio-player/AudioPlayerTimeDisplay.svelte +0 -1
- package/dist/components/audio-player/AudioPlayerTimeRange.svelte +0 -1
- package/dist/components/audio-player/AudioPlayerVolumeRange.svelte +0 -1
- package/dist/components/checkpoint/index.d.ts +2 -2
- package/dist/components/code/Code.svelte +16 -0
- package/dist/components/code/Code.svelte.d.ts +10 -0
- package/dist/components/code/index.d.ts +23 -0
- package/dist/components/code/index.js +14 -0
- package/dist/components/code-block/CodeBlock.svelte +23 -4
- package/dist/components/code-block/CodeBlock.svelte.d.ts +8 -4
- package/dist/components/code-block/CodeBlockContent.svelte +7 -1
- package/dist/components/code-block/CodeBlockContent.svelte.d.ts +1 -0
- package/dist/components/code-block/CodeBlockLine.svelte +3 -1
- package/dist/components/code-block/CodeBlockLine.svelte.d.ts +1 -0
- package/dist/components/code-block/CodeBlockOverflow.svelte +32 -0
- package/dist/components/code-block/CodeBlockOverflow.svelte.d.ts +13 -0
- package/dist/components/code-block/index.d.ts +3 -0
- package/dist/components/code-block/index.js +1 -0
- package/dist/components/context/Context.svelte +46 -5
- package/dist/components/context/Context.svelte.d.ts +5 -1
- package/dist/components/conversation/index.d.ts +4 -0
- package/dist/components/file-tree/FileTree.svelte +35 -16
- package/dist/components/file-tree/FileTree.svelte.d.ts +7 -1
- package/dist/components/file-tree/FileTreeFile.svelte +3 -3
- package/dist/components/file-tree/FileTreeFile.svelte.d.ts +1 -0
- package/dist/components/file-tree/context.svelte.d.ts +2 -0
- package/dist/components/inline-citation/InlineCitation.svelte +0 -1
- package/dist/components/inline-citation/InlineCitationCardBody.svelte +0 -1
- package/dist/components/inline-citation/InlineCitationCarouselHeader.svelte +0 -1
- package/dist/components/inline-citation/InlineCitationCarouselIndex.svelte +0 -1
- package/dist/components/inline-citation/InlineCitationCarouselNext.svelte +0 -1
- package/dist/components/inline-citation/InlineCitationCarouselPrev.svelte +0 -1
- package/dist/components/inline-citation/InlineCitationQuote.svelte +0 -1
- package/dist/components/inline-citation/InlineCitationText.svelte +0 -1
- package/dist/components/jsx-preview/JSXPreviewContent.svelte +43 -31
- package/dist/components/jsx-preview/index.d.ts +1 -1
- package/dist/components/jsx-preview/parser.d.ts +18 -8
- package/dist/components/jsx-preview/parser.js +1 -1
- package/dist/components/message/MessageAction.svelte +45 -9
- package/dist/components/message/MessageAction.svelte.d.ts +2 -2
- package/dist/components/message/MessageAttachment.svelte +64 -0
- package/dist/components/message/MessageAttachment.svelte.d.ts +18 -0
- package/dist/components/message/MessageAttachmentPreview.svelte +51 -0
- package/dist/components/message/MessageAttachmentPreview.svelte.d.ts +9 -0
- package/dist/components/message/MessageAttachments.svelte +25 -0
- package/dist/components/message/MessageAttachments.svelte.d.ts +9 -0
- package/dist/components/message/MessageResponse.svelte +26 -8
- package/dist/components/message/MessageResponse.svelte.d.ts +5 -5
- package/dist/components/message/index.d.ts +8 -0
- package/dist/components/message/index.js +3 -0
- package/dist/components/prompt-input/PromptInput.svelte +17 -4
- package/dist/components/prompt-input/PromptInput.svelte.d.ts +3 -1
- package/dist/components/prompt-input/PromptInputActionAddAttachments.svelte +0 -1
- package/dist/components/prompt-input/PromptInputActionMenuContent.svelte +0 -1
- package/dist/components/prompt-input/PromptInputActionMenuTrigger.svelte +0 -1
- package/dist/components/prompt-input/PromptInputAttachment.svelte +31 -0
- package/dist/components/prompt-input/PromptInputAttachment.svelte.d.ts +9 -0
- package/dist/components/prompt-input/PromptInputAttachmentImagePreview.svelte +34 -0
- package/dist/components/prompt-input/PromptInputAttachmentImagePreview.svelte.d.ts +9 -0
- package/dist/components/prompt-input/PromptInputAttachments.svelte +22 -0
- package/dist/components/prompt-input/PromptInputAttachments.svelte.d.ts +10 -0
- package/dist/components/prompt-input/PromptInputBody.svelte +0 -1
- package/dist/components/prompt-input/PromptInputButton.svelte +0 -1
- package/dist/components/prompt-input/PromptInputCommand.svelte +0 -1
- package/dist/components/prompt-input/PromptInputCommandEmpty.svelte +0 -1
- package/dist/components/prompt-input/PromptInputCommandGroup.svelte +0 -1
- package/dist/components/prompt-input/PromptInputCommandInput.svelte +0 -1
- package/dist/components/prompt-input/PromptInputCommandList.svelte +0 -1
- package/dist/components/prompt-input/PromptInputCommandSeparator.svelte +0 -1
- package/dist/components/prompt-input/PromptInputFooter.svelte +0 -1
- package/dist/components/prompt-input/PromptInputHeader.svelte +0 -1
- package/dist/components/prompt-input/PromptInputHoverCardContent.svelte +0 -1
- package/dist/components/prompt-input/PromptInputHoverCardTrigger.svelte +0 -1
- package/dist/components/prompt-input/PromptInputSelectContent.svelte +0 -1
- package/dist/components/prompt-input/PromptInputSelectItem.svelte +0 -1
- package/dist/components/prompt-input/PromptInputSelectTrigger.svelte +0 -1
- package/dist/components/prompt-input/PromptInputSubmit.svelte +0 -1
- package/dist/components/prompt-input/PromptInputTab.svelte +0 -1
- package/dist/components/prompt-input/PromptInputTabBody.svelte +0 -1
- package/dist/components/prompt-input/PromptInputTabItem.svelte +0 -1
- package/dist/components/prompt-input/PromptInputTabLabel.svelte +0 -1
- package/dist/components/prompt-input/PromptInputTabsList.svelte +0 -1
- package/dist/components/prompt-input/PromptInputTextarea.svelte +3 -3
- package/dist/components/prompt-input/PromptInputToolbar.svelte +14 -0
- package/dist/components/prompt-input/PromptInputToolbar.svelte.d.ts +9 -0
- package/dist/components/prompt-input/PromptInputTools.svelte +0 -1
- package/dist/components/prompt-input/context.svelte.d.ts +1 -0
- package/dist/components/prompt-input/index.d.ts +8 -0
- package/dist/components/prompt-input/index.js +4 -0
- package/dist/components/reasoning/index.d.ts +1 -0
- package/dist/components/response/index.d.ts +2 -0
- package/dist/components/response/index.js +1 -0
- package/dist/components/sandbox/SandboxHeader.svelte +13 -4
- package/dist/components/sandbox/SandboxHeader.svelte.d.ts +6 -5
- package/dist/components/sandbox/SandboxTabContent.svelte +1 -1
- package/dist/components/sandbox/SandboxTabs.svelte +2 -2
- package/dist/components/sandbox/SandboxTabs.svelte.d.ts +1 -0
- package/dist/components/sandbox/SandboxTabsTrigger.svelte +12 -2
- package/dist/components/sandbox/SandboxTabsTrigger.svelte.d.ts +4 -5
- package/dist/components/sandbox/context.svelte.d.ts +2 -0
- package/dist/components/snippet/index.d.ts +2 -2
- package/dist/components/stack-trace/StackTrace.svelte +6 -4
- package/dist/components/stack-trace/StackTrace.svelte.d.ts +2 -1
- package/dist/components/stack-trace/StackTraceCopyButton.svelte +48 -2
- package/dist/components/stack-trace/StackTraceHeader.svelte +37 -2
- package/dist/components/stack-trace/StackTraceHeader.svelte.d.ts +2 -2
- package/dist/components/suggestion/index.d.ts +1 -1
- package/dist/components/terminal/AnsiText.svelte +42 -0
- package/dist/components/terminal/AnsiText.svelte.d.ts +6 -0
- package/dist/components/terminal/Terminal.svelte +20 -10
- package/dist/components/terminal/Terminal.svelte.d.ts +2 -1
- package/dist/components/terminal/TerminalContent.svelte +2 -2
- package/dist/components/terminal/ansi.d.ts +12 -0
- package/dist/components/terminal/ansi.js +76 -0
- package/dist/components/tool/ToolHeader.svelte +4 -16
- package/dist/components/tool/ToolStatusBadge.svelte +4 -3
- package/dist/components/tool/index.d.ts +1 -1
- package/dist/components/tool/status.d.ts +4 -1
- package/dist/components/tool/status.js +7 -7
- package/dist/components/transcription/Transcription.svelte +22 -14
- package/dist/components/transcription/Transcription.svelte.d.ts +2 -1
- package/dist/components/transcription/TranscriptionSegment.svelte +1 -1
- package/dist/components/transcription/context.svelte.d.ts +1 -0
- package/dist/components/voice-selector/VoiceSelectorAccent.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorAge.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorAttributes.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorBullet.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorContent.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorDescription.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorDialog.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorEmpty.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorGender.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorGroup.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorInput.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorList.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorName.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorPreview.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorRoot.svelte.d.ts +1 -1
- package/dist/components/voice-selector/VoiceSelectorSeparator.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorShortcut.svelte +0 -1
- package/dist/components/voice-selector/VoiceSelectorTrigger.svelte +0 -1
- package/dist/components/workflow/index.d.ts +6 -0
- package/dist/components/workflow/index.js +3 -0
- package/dist/components/workflow/node/index.d.ts +1 -0
- package/dist/components/workflow/node/index.js +1 -0
- package/dist/components/workflow/panel/index.d.ts +1 -0
- package/dist/components/workflow/panel/index.js +1 -0
- package/dist/components/workflow/toolbar/index.d.ts +1 -0
- package/dist/components/workflow/toolbar/index.js +1 -0
- package/dist/context.svelte.d.ts +1 -0
- package/dist/contracts.d.ts +1 -1
- package/dist/generated-components.d.ts +2 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.js +8 -4
- package/dist/internal/Tooltip.svelte +124 -0
- package/dist/internal/Tooltip.svelte.d.ts +12 -0
- package/dist/parity-manifest.js +1 -0
- package/package.json +4 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLFormAttributes } from 'svelte/elements';
|
|
3
4
|
import type { ChatAttachment, ChatSource } from '../../contracts.js';
|
|
4
5
|
|
|
5
6
|
export interface PromptInputMessage {
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
event: SubmitEvent;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export interface PromptInputProps {
|
|
18
|
+
export interface PromptInputProps extends Omit<HTMLFormAttributes, 'children' | 'class' | 'onerror' | 'onsubmit'> {
|
|
18
19
|
value?: string;
|
|
19
20
|
attachments?: ChatAttachment[];
|
|
20
21
|
accept?: string;
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
maxFiles?: number;
|
|
27
28
|
maxFileSize?: number;
|
|
28
29
|
globalDrop?: boolean;
|
|
30
|
+
syncHiddenInput?: boolean;
|
|
29
31
|
placeholder?: string;
|
|
30
32
|
ariaLabel?: string;
|
|
31
33
|
class?: string;
|
|
@@ -70,8 +72,10 @@
|
|
|
70
72
|
maxFiles,
|
|
71
73
|
maxFileSize,
|
|
72
74
|
globalDrop = false,
|
|
75
|
+
syncHiddenInput = false,
|
|
73
76
|
placeholder = 'What would you like to know?',
|
|
74
77
|
ariaLabel = 'Prompt input',
|
|
78
|
+
'aria-label': formAriaLabel,
|
|
75
79
|
class: className = '',
|
|
76
80
|
children,
|
|
77
81
|
onsubmit,
|
|
@@ -81,6 +85,7 @@
|
|
|
81
85
|
onattachmentadd,
|
|
82
86
|
onattachmentremove,
|
|
83
87
|
onerror,
|
|
88
|
+
...rest
|
|
84
89
|
}: PromptInputProps = $props();
|
|
85
90
|
|
|
86
91
|
const parentController = getOptionalPromptInputController();
|
|
@@ -297,6 +302,7 @@
|
|
|
297
302
|
openFileDialog,
|
|
298
303
|
get fileInputRef() { return inputElement; },
|
|
299
304
|
},
|
|
305
|
+
get syncHiddenInput() { return syncHiddenInput; },
|
|
300
306
|
registerFileInput,
|
|
301
307
|
};
|
|
302
308
|
providePromptInputController(localController);
|
|
@@ -354,9 +360,16 @@
|
|
|
354
360
|
});
|
|
355
361
|
</script>
|
|
356
362
|
|
|
357
|
-
<form
|
|
363
|
+
<form
|
|
364
|
+
{...rest}
|
|
365
|
+
class={cn('svadmin-ai svadmin-ai__surface flex flex-col gap-2 p-2', className)}
|
|
366
|
+
aria-label={formAriaLabel ?? ariaLabel}
|
|
367
|
+
data-slot="prompt-input"
|
|
368
|
+
onsubmit={submit}
|
|
369
|
+
>
|
|
358
370
|
<input bind:this={inputElement} class="svadmin-ai__sr-only" type="file" {accept} {multiple} disabled={disabled} aria-label="Upload files" onchange={(event) => addFiles((event.currentTarget as HTMLInputElement).files ?? [])} />
|
|
359
|
-
{#if
|
|
371
|
+
{#if syncHiddenInput}<input type="hidden" name="message" value={activeText} />{/if}
|
|
372
|
+
{#if activeFiles.length > 0 && !children}
|
|
360
373
|
<ul class="flex flex-wrap gap-2" aria-label="Attachments">
|
|
361
374
|
{#each activeFiles as file, index (file.id)}
|
|
362
375
|
<li class="flex min-w-0 items-center gap-1 rounded border border-border px-2 py-1 text-xs">
|
|
@@ -368,7 +381,7 @@
|
|
|
368
381
|
{/if}
|
|
369
382
|
{#if errorMessage}<p class="text-destructive text-xs" role="alert">{errorMessage}</p>{/if}
|
|
370
383
|
{#if children}{@render children()}{:else}
|
|
371
|
-
<textarea class="svadmin-ai__textarea min-h-20 border-0 bg-transparent outline-none" name=
|
|
384
|
+
<textarea class="svadmin-ai__textarea min-h-20 border-0 bg-transparent outline-none" name={syncHiddenInput ? undefined : 'message'} value={activeText} {disabled} maxlength={maxLength} {placeholder} aria-label={ariaLabel} oninput={(event) => setValue(event.currentTarget.value)} onkeydown={handleKeydown} onpaste={handlePaste} oncompositionstart={() => composition = true} oncompositionend={() => composition = false}></textarea>
|
|
372
385
|
<div class="flex items-center justify-between gap-2">
|
|
373
386
|
<button type="button" class="svadmin-ai__button svadmin-ai__button--ghost size-8 min-h-8 p-0" aria-label="Add attachments" title="Add attachments" disabled={disabled} onclick={openFileDialog}><Paperclip size={15} aria-hidden="true" /></button>
|
|
374
387
|
{#if busy}<button type="button" class="svadmin-ai__button svadmin-ai__button--ghost min-h-8 px-3" onclick={() => onstop?.()}><Square size={13} fill="currentColor" aria-hidden="true" /> Stop</button>{:else}<button type="submit" class="svadmin-ai__button min-h-8 px-3" disabled={!canSubmit}><Send size={14} aria-hidden="true" /> Send</button>{/if}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLFormAttributes } from 'svelte/elements';
|
|
2
3
|
import type { ChatAttachment, ChatSource } from '../../contracts.js';
|
|
3
4
|
export interface PromptInputMessage {
|
|
4
5
|
text: string;
|
|
@@ -10,7 +11,7 @@ export interface PromptInputSubmitDetail extends PromptInputMessage {
|
|
|
10
11
|
attachments: ChatAttachment[];
|
|
11
12
|
event: SubmitEvent;
|
|
12
13
|
}
|
|
13
|
-
export interface PromptInputProps {
|
|
14
|
+
export interface PromptInputProps extends Omit<HTMLFormAttributes, 'children' | 'class' | 'onerror' | 'onsubmit'> {
|
|
14
15
|
value?: string;
|
|
15
16
|
attachments?: ChatAttachment[];
|
|
16
17
|
accept?: string;
|
|
@@ -22,6 +23,7 @@ export interface PromptInputProps {
|
|
|
22
23
|
maxFiles?: number;
|
|
23
24
|
maxFileSize?: number;
|
|
24
25
|
globalDrop?: boolean;
|
|
26
|
+
syncHiddenInput?: boolean;
|
|
25
27
|
placeholder?: string;
|
|
26
28
|
ariaLabel?: string;
|
|
27
29
|
class?: string;
|
|
@@ -6,4 +6,3 @@
|
|
|
6
6
|
</script>
|
|
7
7
|
<input bind:this={input} class="svadmin-ai__sr-only" type="file" {accept} {multiple} aria-label={label} onchange={(event) => { const files = event.currentTarget.files; if (files) attachments.add(files); event.currentTarget.value = ''; }} />
|
|
8
8
|
<button {...rest} type="button" role="menuitem" class={cn('flex min-h-9 w-full items-center gap-2 rounded px-2 text-left text-sm hover:bg-muted focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring', className)} data-slot="prompt-input-action-add-attachments" onclick={open}><Image size={16} aria-hidden="true" />{label}</button>
|
|
9
|
-
|
|
@@ -4,4 +4,3 @@
|
|
|
4
4
|
let { class: className = '', children, align = 'start', ...rest }: Props = $props(); const menu = usePromptInputMenu();
|
|
5
5
|
</script>
|
|
6
6
|
{#if menu.open}<div {...rest} class={cn('absolute bottom-full z-30 mb-1 grid min-w-48 gap-0.5 rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md', align === 'end' && 'right-0', align === 'center' && 'left-1/2 -translate-x-1/2', align === 'start' && 'left-0', className)} role="menu" data-slot="prompt-input-action-menu-content">{@render children?.()}</div>{/if}
|
|
7
|
-
|
|
@@ -5,4 +5,3 @@
|
|
|
5
5
|
function click(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }): void { onclick?.(event); if (!event.defaultPrevented) menu.setOpen(!menu.open); }
|
|
6
6
|
</script>
|
|
7
7
|
<button {...rest} type="button" class={cn('svadmin-ai__button svadmin-ai__button--ghost size-8 min-h-8 p-0', className)} aria-haspopup="menu" aria-expanded={menu.open} aria-label={rest['aria-label'] ?? 'Prompt actions'} data-slot="prompt-input-action-menu-trigger" onclick={click}>{#if children}{@render children()}{:else}<Plus size={16} aria-hidden="true" />{/if}</button>
|
|
8
|
-
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { PromptInputFile } from './context.svelte.js';
|
|
4
|
+
export interface PromptInputAttachmentProps extends Omit<HTMLAttributes<HTMLDivElement>, 'class'> {
|
|
5
|
+
data: PromptInputFile;
|
|
6
|
+
class?: string;
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { Paperclip, X } from '@lucide/svelte';
|
|
12
|
+
import { cn, safeResourceUrl } from '../../utils.js';
|
|
13
|
+
import { usePromptInputAttachments } from './context.svelte.js';
|
|
14
|
+
import PromptInputAttachmentImagePreview from './PromptInputAttachmentImagePreview.svelte';
|
|
15
|
+
let { data, class: className = '', ...rest }: PromptInputAttachmentProps = $props();
|
|
16
|
+
const attachments = usePromptInputAttachments();
|
|
17
|
+
const isImage = $derived(Boolean(data.mediaType?.startsWith('image/') && safeResourceUrl(data.url)));
|
|
18
|
+
const label = $derived(data.filename ?? data.name ?? 'Attachment');
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<div {...rest} class={cn('group relative flex h-8 max-w-full min-w-0 items-center gap-2 overflow-hidden rounded border border-border px-2 text-xs', isImage && 'size-16 p-0', className)} data-slot="prompt-input-attachment">
|
|
22
|
+
{#if isImage}
|
|
23
|
+
<PromptInputAttachmentImagePreview {data} />
|
|
24
|
+
{:else}
|
|
25
|
+
<Paperclip size={14} aria-hidden="true" />
|
|
26
|
+
<span class="truncate" title={label}>{label}</span>
|
|
27
|
+
{/if}
|
|
28
|
+
<button type="button" class="absolute right-0.5 top-0.5 inline-flex size-5 items-center justify-center rounded-full border border-border bg-background text-muted-foreground opacity-0 group-hover:opacity-100 focus-visible:opacity-100" aria-label={`Remove ${label}`} title={`Remove ${label}`} onclick={() => attachments.remove(data.id)}>
|
|
29
|
+
<X size={12} aria-hidden="true" />
|
|
30
|
+
</button>
|
|
31
|
+
</div>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
import type { PromptInputFile } from './context.svelte.js';
|
|
3
|
+
export interface PromptInputAttachmentProps extends Omit<HTMLAttributes<HTMLDivElement>, 'class'> {
|
|
4
|
+
data: PromptInputFile;
|
|
5
|
+
class?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const PromptInputAttachment: import("svelte").Component<PromptInputAttachmentProps, {}, "">;
|
|
8
|
+
type PromptInputAttachment = ReturnType<typeof PromptInputAttachment>;
|
|
9
|
+
export default PromptInputAttachment;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { PromptInputFile } from './context.svelte.js';
|
|
4
|
+
export interface PromptInputAttachmentImagePreviewProps extends Omit<HTMLAttributes<HTMLButtonElement>, 'class'> { data: PromptInputFile; class?: string; }
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { X } from '@lucide/svelte';
|
|
9
|
+
import { cn, safeResourceUrl } from '../../utils.js';
|
|
10
|
+
let { data, class: className = '', ...rest }: PromptInputAttachmentImagePreviewProps = $props();
|
|
11
|
+
const src = $derived(safeResourceUrl(data.url));
|
|
12
|
+
const label = $derived(data.filename ?? data.name ?? 'Image attachment');
|
|
13
|
+
let dialog = $state<HTMLDialogElement | null>(null);
|
|
14
|
+
function openPreview(): void { if (typeof dialog?.showModal === 'function') dialog.showModal(); else dialog?.setAttribute('open', ''); }
|
|
15
|
+
function closePreview(): void { if (typeof dialog?.close === 'function') dialog.close(); else dialog?.removeAttribute('open'); }
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<button {...rest} class={cn('block size-full cursor-zoom-in overflow-hidden', className)} type="button" aria-label={`Preview ${label}`} onclick={openPreview}>
|
|
19
|
+
{#if src}<img src={src} alt={label} width="64" height="64" class="size-full object-cover" />{/if}
|
|
20
|
+
</button>
|
|
21
|
+
{#if src}
|
|
22
|
+
<dialog bind:this={dialog} class="svadmin-ai-prompt-attachment-dialog" aria-label={`${label} preview`} onclick={(event) => { if (event.target === dialog) closePreview(); }}>
|
|
23
|
+
<button type="button" class="svadmin-ai-prompt-attachment-dialog__close" aria-label="Close preview" onclick={closePreview}><X size={18} aria-hidden="true" /></button>
|
|
24
|
+
<img src={src} alt={`${label} preview`} />
|
|
25
|
+
</dialog>
|
|
26
|
+
{/if}
|
|
27
|
+
|
|
28
|
+
<style>
|
|
29
|
+
.svadmin-ai-prompt-attachment-dialog { width: min(92vw, 60rem); max-width: none; max-height: 84vh; padding: 2.5rem 1rem 1rem; border: 1px solid var(--border, currentColor); border-radius: min(var(--radius, .5rem), .5rem); background: var(--background, Canvas); color: var(--foreground, currentColor); }
|
|
30
|
+
.svadmin-ai-prompt-attachment-dialog::backdrop { background: color-mix(in oklch, var(--foreground, currentColor) 45%, transparent); }
|
|
31
|
+
.svadmin-ai-prompt-attachment-dialog img { display: block; width: 100%; max-height: calc(84vh - 3.5rem); object-fit: contain; }
|
|
32
|
+
.svadmin-ai-prompt-attachment-dialog__close { position: absolute; top: .5rem; right: .5rem; display: inline-flex; width: 2rem; height: 2rem; align-items: center; justify-content: center; border: 1px solid var(--border, currentColor); border-radius: min(var(--radius, .5rem), .375rem); background: var(--background, Canvas); color: var(--foreground, currentColor); cursor: pointer; }
|
|
33
|
+
.svadmin-ai-prompt-attachment-dialog__close:focus-visible { outline: 2px solid var(--ring, currentColor); outline-offset: 2px; }
|
|
34
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
import type { PromptInputFile } from './context.svelte.js';
|
|
3
|
+
export interface PromptInputAttachmentImagePreviewProps extends Omit<HTMLAttributes<HTMLButtonElement>, 'class'> {
|
|
4
|
+
data: PromptInputFile;
|
|
5
|
+
class?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const PromptInputAttachmentImagePreview: import("svelte").Component<PromptInputAttachmentImagePreviewProps, {}, "">;
|
|
8
|
+
type PromptInputAttachmentImagePreview = ReturnType<typeof PromptInputAttachmentImagePreview>;
|
|
9
|
+
export default PromptInputAttachmentImagePreview;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
import type { PromptInputFile } from './context.svelte.js';
|
|
5
|
+
export interface PromptInputAttachmentsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> {
|
|
6
|
+
class?: string;
|
|
7
|
+
children?: Snippet<[PromptInputFile]>;
|
|
8
|
+
}
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { cn } from '../../utils.js';
|
|
13
|
+
import { usePromptInputAttachments } from './context.svelte.js';
|
|
14
|
+
let { class: className = '', children, ...rest }: PromptInputAttachmentsProps = $props();
|
|
15
|
+
const context = usePromptInputAttachments();
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<div {...rest} class={cn('flex flex-wrap gap-2 overflow-hidden', className)} data-slot="prompt-input-attachments" aria-live="polite">
|
|
19
|
+
{#each context.files as file (file.id)}
|
|
20
|
+
{@render children?.(file)}
|
|
21
|
+
{/each}
|
|
22
|
+
</div>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { PromptInputFile } from './context.svelte.js';
|
|
4
|
+
export interface PromptInputAttachmentsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> {
|
|
5
|
+
class?: string;
|
|
6
|
+
children?: Snippet<[PromptInputFile]>;
|
|
7
|
+
}
|
|
8
|
+
declare const PromptInputAttachments: import("svelte").Component<PromptInputAttachmentsProps, {}, "">;
|
|
9
|
+
type PromptInputAttachments = ReturnType<typeof PromptInputAttachments>;
|
|
10
|
+
export default PromptInputAttachments;
|
|
@@ -9,4 +9,3 @@
|
|
|
9
9
|
const tooltipText = $derived(typeof tooltip === 'string' ? tooltip : tooltip?.content);
|
|
10
10
|
</script>
|
|
11
11
|
<button {...rest} {type} title={title ?? tooltipText} class={cn('svadmin-ai__button', variant === 'ghost' && 'svadmin-ai__button--ghost', variant === 'outline' && 'border border-border bg-transparent', size === 'icon-sm' ? 'size-8 min-h-8 p-0' : 'min-h-8 px-3', className)} data-slot="prompt-input-button">{@render children?.()}{#if tooltip && typeof tooltip !== 'string' && tooltip.shortcut}<span class="svadmin-ai__sr-only">{tooltip.shortcut}</span>{/if}</button>
|
|
12
|
-
|
|
@@ -13,4 +13,3 @@
|
|
|
13
13
|
function keydown(event: KeyboardEvent & { currentTarget: EventTarget & HTMLDivElement }): void { onkeydown?.(event); if (event.defaultPrevented) return; if (event.key === 'ArrowDown') { event.preventDefault(); move(1); } else if (event.key === 'ArrowUp') { event.preventDefault(); move(-1); } else if (event.key === 'Enter') { event.preventDefault(); selectActive(); } }
|
|
14
14
|
</script>
|
|
15
15
|
<div {...rest} class={cn('grid max-h-72 min-w-48 overflow-auto rounded-md border border-border bg-popover p-1 text-popover-foreground', className)} role="listbox" aria-label="Command menu" data-slot="prompt-input-command" onkeydown={keydown}>{@render children?.()}</div>
|
|
16
|
-
|
|
@@ -3,4 +3,3 @@
|
|
|
3
3
|
let { class: className = '', children }: { class?: string; children?: Snippet } = $props(); const command = usePromptInputCommand();
|
|
4
4
|
</script>
|
|
5
5
|
{#if command.visibleCount === 0}<p class={cn('px-3 py-6 text-center text-sm text-muted-foreground', className)} data-slot="prompt-input-command-empty">{#if children}{@render children()}{:else}No results found.{/if}</p>{/if}
|
|
6
|
-
|
|
@@ -4,4 +4,3 @@
|
|
|
4
4
|
let { class: className = '', children, heading, ...rest }: Props = $props();
|
|
5
5
|
</script>
|
|
6
6
|
<div {...rest} class={cn('grid gap-0.5 p-1', className)} role="group" data-slot="prompt-input-command-group">{#if heading}<h3 class="px-2 py-1 text-xs font-medium text-muted-foreground">{heading}</h3>{/if}{@render children?.()}</div>
|
|
7
|
-
|
|
@@ -5,4 +5,3 @@
|
|
|
5
5
|
function input(event: Event & { currentTarget: EventTarget & HTMLInputElement }): void { command.setQuery(event.currentTarget.value); oninput?.(event); }
|
|
6
6
|
</script>
|
|
7
7
|
<label class={cn('flex min-h-9 items-center gap-2 border-b border-border px-2 text-sm', className)} data-slot="prompt-input-command-input"><Search size={14} aria-hidden="true" /><input {...rest} class="min-w-0 flex-1 border-0 bg-transparent outline-none" value={resolved} {placeholder} aria-label={rest['aria-label'] ?? 'Search'} oninput={input} /></label>
|
|
8
|
-
|
|
@@ -4,4 +4,3 @@
|
|
|
4
4
|
let { class: className = '', children, ...rest }: Props = $props(); const card = usePromptInputHoverCard();
|
|
5
5
|
</script>
|
|
6
6
|
{#if card.open}<div {...rest} class={cn('absolute bottom-full left-0 z-30 mb-2 w-64 rounded-md border border-border bg-popover p-3 text-popover-foreground shadow-md', className)} role="dialog" data-slot="prompt-input-hover-card-content">{@render children?.()}</div>{/if}
|
|
7
|
-
|
|
@@ -4,4 +4,3 @@
|
|
|
4
4
|
let { class: className = '', children, ...rest }: Props = $props(); const select = usePromptInputSelect();
|
|
5
5
|
</script>
|
|
6
6
|
{#if select.open}<div {...rest} class={cn('absolute bottom-full left-0 z-30 mb-1 grid min-w-40 gap-0.5 rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md', className)} role="listbox" data-slot="prompt-input-select-content">{@render children?.()}</div>{/if}
|
|
7
|
-
|
|
@@ -5,4 +5,3 @@
|
|
|
5
5
|
function click(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }): void { onclick?.(event); if (!event.defaultPrevented) select.setValue(value); }
|
|
6
6
|
</script>
|
|
7
7
|
<button {...rest} type="button" role="option" aria-selected={select.value === value} class={cn('flex min-h-8 w-full items-center gap-2 rounded px-2 text-left text-sm hover:bg-muted focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring', className)} data-slot="prompt-input-select-item" onclick={click}>{#if select.value === value}<Check size={14} aria-hidden="true" />{:else}<span class="size-3" aria-hidden="true"></span>{/if}{#if children}{@render children()}{:else}{value}{/if}</button>
|
|
8
|
-
|
|
@@ -5,4 +5,3 @@
|
|
|
5
5
|
function click(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }): void { onclick?.(event); if (!event.defaultPrevented) select.setOpen(!select.open); }
|
|
6
6
|
</script>
|
|
7
7
|
<button {...rest} type="button" class={cn('inline-flex min-h-8 items-center gap-1 rounded px-2 text-xs font-medium text-muted-foreground hover:bg-muted focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring', className)} aria-haspopup="listbox" aria-expanded={select.open} data-slot="prompt-input-select-trigger" onclick={click}>{#if children}{@render children()}{:else}{select.value || 'Select'}{/if}<ChevronDown size={13} aria-hidden="true" /></button>
|
|
8
|
-
|
|
@@ -9,4 +9,3 @@
|
|
|
9
9
|
<button {...rest} type={generating && (onstop || onStop) ? 'button' : 'submit'} class={cn('svadmin-ai__button size-8 min-h-8 p-0', className)} aria-label={generating ? 'Stop' : 'Submit'} data-slot="prompt-input-submit" onclick={click}>
|
|
10
10
|
{#if children}{@render children()}{:else if status === 'submitted'}<LoaderCircle class="animate-spin" size={15} aria-hidden="true" />{:else if status === 'streaming'}<Square size={14} fill="currentColor" aria-hidden="true" />{:else if status === 'error'}<X size={15} aria-hidden="true" />{:else}<CornerDownLeft size={15} aria-hidden="true" />{/if}
|
|
11
11
|
</button>
|
|
12
|
-
|
|
@@ -4,4 +4,3 @@
|
|
|
4
4
|
let { class: className = '', children, value, active = false, ...rest }: Props = $props();
|
|
5
5
|
</script>
|
|
6
6
|
<div {...rest} class={cn('grid gap-2', className)} data-slot="prompt-input-tab" data-value={value} data-state={active ? 'active' : 'inactive'}>{@render children?.()}</div>
|
|
7
|
-
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
import { cn } from '../../utils.js';
|
|
4
4
|
import { usePromptInputAttachments, usePromptInputController } from './context.svelte.js';
|
|
5
5
|
interface Props extends Omit<HTMLTextareaAttributes, 'class' | 'value'> { class?: string; value?: string; }
|
|
6
|
-
let { class: className = '', value, name
|
|
6
|
+
let { class: className = '', value, name, placeholder = 'What would you like to know?', oninput, onkeydown, onpaste, oncompositionstart, oncompositionend, ...rest }: Props = $props();
|
|
7
7
|
const controller = usePromptInputController();
|
|
8
8
|
const attachments = usePromptInputAttachments();
|
|
9
9
|
let composing = $state(false);
|
|
10
10
|
const resolvedValue = $derived(value ?? controller.textInput.value);
|
|
11
|
+
const resolvedName = $derived(name ?? (controller.syncHiddenInput ? undefined : 'message'));
|
|
11
12
|
function input(event: Event & { currentTarget: EventTarget & HTMLTextAreaElement }): void { controller.textInput.setInput(event.currentTarget.value); oninput?.(event); }
|
|
12
13
|
function keydown(event: KeyboardEvent & { currentTarget: EventTarget & HTMLTextAreaElement }): void {
|
|
13
14
|
onkeydown?.(event); if (event.defaultPrevented) return;
|
|
@@ -18,5 +19,4 @@
|
|
|
18
19
|
function start(event: CompositionEvent & { currentTarget: EventTarget & HTMLTextAreaElement }): void { composing = true; oncompositionstart?.(event); }
|
|
19
20
|
function end(event: CompositionEvent & { currentTarget: EventTarget & HTMLTextAreaElement }): void { composing = false; oncompositionend?.(event); }
|
|
20
21
|
</script>
|
|
21
|
-
<textarea {...rest} {
|
|
22
|
-
|
|
22
|
+
<textarea {...rest} name={resolvedName} {placeholder} value={resolvedValue} class={cn('svadmin-ai__textarea field-sizing-content max-h-48 min-h-16 border-0 bg-transparent outline-none', className)} data-slot="prompt-input-textarea" oninput={input} onkeydown={keydown} onpaste={paste} oncompositionstart={start} oncompositionend={end}></textarea>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
export type PromptInputToolbarProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & { class?: string; children?: Snippet };
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { cn } from '../../utils.js';
|
|
9
|
+
let { class: className = '', children, ...rest }: PromptInputToolbarProps = $props();
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<div {...rest} class={cn('flex items-center justify-between gap-1 p-1', className)} data-slot="prompt-input-toolbar">
|
|
13
|
+
{@render children?.()}
|
|
14
|
+
</div>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
export type PromptInputToolbarProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
|
|
4
|
+
class?: string;
|
|
5
|
+
children?: Snippet;
|
|
6
|
+
};
|
|
7
|
+
declare const PromptInputToolbar: import("svelte").Component<PromptInputToolbarProps, {}, "">;
|
|
8
|
+
type PromptInputToolbar = ReturnType<typeof PromptInputToolbar>;
|
|
9
|
+
export default PromptInputToolbar;
|
|
@@ -21,6 +21,7 @@ export interface PromptInputTextContext {
|
|
|
21
21
|
export interface PromptInputController {
|
|
22
22
|
readonly textInput: PromptInputTextContext;
|
|
23
23
|
readonly attachments: PromptInputAttachmentsContext;
|
|
24
|
+
readonly syncHiddenInput?: boolean;
|
|
24
25
|
registerFileInput(input: HTMLInputElement | null, open?: () => void): void;
|
|
25
26
|
}
|
|
26
27
|
export interface PromptInputReferencedSourcesContext {
|
|
@@ -5,6 +5,10 @@ export { default as Textarea, default as PromptInputTextarea } from './PromptInp
|
|
|
5
5
|
export { default as Header, default as PromptInputHeader } from './PromptInputHeader.svelte';
|
|
6
6
|
export { default as Footer, default as PromptInputFooter } from './PromptInputFooter.svelte';
|
|
7
7
|
export { default as Tools, default as PromptInputTools } from './PromptInputTools.svelte';
|
|
8
|
+
export { default as Toolbar, default as PromptInputToolbar } from './PromptInputToolbar.svelte';
|
|
9
|
+
export { default as Attachment, default as PromptInputAttachment } from './PromptInputAttachment.svelte';
|
|
10
|
+
export { default as AttachmentImagePreview, default as PromptInputAttachmentImagePreview } from './PromptInputAttachmentImagePreview.svelte';
|
|
11
|
+
export { default as Attachments, default as PromptInputAttachments } from './PromptInputAttachments.svelte';
|
|
8
12
|
export { default as Button, default as PromptInputButton } from './PromptInputButton.svelte';
|
|
9
13
|
export { default as ActionAddAttachments, default as PromptInputActionAddAttachments } from './PromptInputActionAddAttachments.svelte';
|
|
10
14
|
export { default as ActionAddScreenshot, default as PromptInputActionAddScreenshot } from './PromptInputActionAddScreenshot.svelte';
|
|
@@ -38,5 +42,9 @@ export { PROMPT_INPUT_REFERENCED_SOURCES as LocalReferencedSourcesContext, usePr
|
|
|
38
42
|
export type { PromptInputMessage, PromptInputProps, PromptInputSubmitDetail } from './PromptInput.svelte';
|
|
39
43
|
export type { PromptInputProviderProps } from './PromptInputProvider.svelte';
|
|
40
44
|
export type { PromptInputButtonProps, PromptInputButtonTooltip } from './PromptInputButton.svelte';
|
|
45
|
+
export type { PromptInputToolbarProps } from './PromptInputToolbar.svelte';
|
|
46
|
+
export type { PromptInputAttachmentProps } from './PromptInputAttachment.svelte';
|
|
47
|
+
export type { PromptInputAttachmentImagePreviewProps } from './PromptInputAttachmentImagePreview.svelte';
|
|
48
|
+
export type { PromptInputAttachmentsProps } from './PromptInputAttachments.svelte';
|
|
41
49
|
export type { PromptInputSpeechButtonProps } from './PromptInputSpeechButton.svelte';
|
|
42
50
|
export type { PromptInputAttachmentsContext, PromptInputController, PromptInputFile, PromptInputReferencedSourcesContext } from './context.svelte.js';
|
|
@@ -5,6 +5,10 @@ export { default as Textarea, default as PromptInputTextarea } from './PromptInp
|
|
|
5
5
|
export { default as Header, default as PromptInputHeader } from './PromptInputHeader.svelte';
|
|
6
6
|
export { default as Footer, default as PromptInputFooter } from './PromptInputFooter.svelte';
|
|
7
7
|
export { default as Tools, default as PromptInputTools } from './PromptInputTools.svelte';
|
|
8
|
+
export { default as Toolbar, default as PromptInputToolbar } from './PromptInputToolbar.svelte';
|
|
9
|
+
export { default as Attachment, default as PromptInputAttachment } from './PromptInputAttachment.svelte';
|
|
10
|
+
export { default as AttachmentImagePreview, default as PromptInputAttachmentImagePreview } from './PromptInputAttachmentImagePreview.svelte';
|
|
11
|
+
export { default as Attachments, default as PromptInputAttachments } from './PromptInputAttachments.svelte';
|
|
8
12
|
export { default as Button, default as PromptInputButton } from './PromptInputButton.svelte';
|
|
9
13
|
export { default as ActionAddAttachments, default as PromptInputActionAddAttachments } from './PromptInputActionAddAttachments.svelte';
|
|
10
14
|
export { default as ActionAddScreenshot, default as PromptInputActionAddScreenshot } from './PromptInputActionAddScreenshot.svelte';
|
|
@@ -2,6 +2,7 @@ export { default, default as Root, default as Reasoning } from '../Reasoning.sve
|
|
|
2
2
|
export { default as Trigger, default as ReasoningTrigger } from './ReasoningTrigger.svelte';
|
|
3
3
|
export { default as Content, default as ReasoningContent } from './ReasoningContent.svelte';
|
|
4
4
|
export { useReasoning } from './context.svelte.js';
|
|
5
|
+
export type { ReasoningProps } from '../Reasoning.svelte';
|
|
5
6
|
export type { ReasoningContextValue } from './context.svelte.js';
|
|
6
7
|
export type { ReasoningTriggerProps } from './ReasoningTrigger.svelte';
|
|
7
8
|
export type { ReasoningContentProps } from './ReasoningContent.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, default as Root, default as Response } from '../Response.svelte';
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
4
|
+
import { ChevronDown, Code2 } from '@lucide/svelte';
|
|
5
|
+
import { cn } from '../../utils.js';
|
|
6
|
+
import { getStatusBadge, type ToolDisplayState } from '../tool/status.js';
|
|
7
|
+
import { useSandboxContext } from './context.svelte.js';
|
|
8
|
+
|
|
9
|
+
interface Props extends Omit<HTMLButtonAttributes, 'children' | 'class' | 'title'> { title?: string; state: ToolDisplayState; class?: string; children?: Snippet; }
|
|
10
|
+
let { title = 'Sandbox', state, class: className = '', children, onclick, ...rest }: Props = $props();
|
|
11
|
+
const context = useSandboxContext();
|
|
12
|
+
const badge = $derived(getStatusBadge(state));
|
|
13
|
+
function toggle(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }): void { onclick?.(event); if (!event.defaultPrevented) context.setOpen(!context.open); }
|
|
5
14
|
</script>
|
|
6
|
-
<button type="button" class={cn('flex w-full items-center justify-between gap-4 border-0 bg-transparent p-3 text-left hover:bg-muted/50 focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-ring', className)} aria-expanded={context.open} onclick={
|
|
15
|
+
<button {...rest} type="button" class={cn('flex w-full items-center justify-between gap-4 border-0 bg-transparent p-3 text-left hover:bg-muted/50 focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-ring', className)} aria-expanded={context.open} onclick={toggle}><span class="flex min-w-0 items-center gap-2"><Code2 class="size-4 shrink-0 text-muted-foreground" aria-hidden="true" /><span class="truncate text-sm font-medium">{title}</span><span class="rounded-md bg-muted px-2 py-0.5 text-xs text-muted-foreground" data-state={state} data-tone={badge.tone}>{badge.label}</span>{#if children}{@render children()}{/if}</span><ChevronDown class={cn('size-4 shrink-0 text-muted-foreground transition-transform', context.open && 'rotate-180')} aria-hidden="true" /></button>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
-
type
|
|
2
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
3
|
+
import { type ToolDisplayState } from '../tool/status.js';
|
|
4
|
+
interface Props extends Omit<HTMLButtonAttributes, 'children' | 'class' | 'title'> {
|
|
3
5
|
title?: string;
|
|
4
|
-
state
|
|
6
|
+
state: ToolDisplayState;
|
|
5
7
|
class?: string;
|
|
6
8
|
children?: Snippet;
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
declare const SandboxHeader: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
}
|
|
10
|
+
declare const SandboxHeader: import("svelte").Component<Props, {}, "">;
|
|
10
11
|
type SandboxHeader = ReturnType<typeof SandboxHeader>;
|
|
11
12
|
export default SandboxHeader;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
<script lang="ts">import type { Snippet } from 'svelte'; import { cn } from '../../utils.js'; import { useSandboxTabsContext } from './context.svelte.js'; let { value, class: className = '', children, ...rest }: { value: string; class?: string; children?: Snippet; [key: string]: unknown } = $props(); const context = useSandboxTabsContext(); const active = $derived(context.value === value);</script>
|
|
2
|
-
{#if active}<div role="tabpanel" data-value={value} class={cn('mt-0 text-sm', className)}
|
|
2
|
+
{#if active}<div {...rest} id={context.panelId(value)} role="tabpanel" aria-labelledby={context.tabId(value)} tabindex="0" data-state="active" data-value={value} class={cn('mt-0 text-sm', className)}>{@render children?.()}</div>{/if}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<script lang="ts">import type { Snippet } from 'svelte'; import { cn } from '../../utils.js'; import { provideSandboxTabsContext } from './context.svelte.js'; let { defaultValue = '', value = $bindable(defaultValue), class: className = '', children, onvaluechange, ...rest }: { value?: string; defaultValue?: string; class?: string; children?: Snippet; onvaluechange?: (value: string) => void; [key: string]: unknown } = $props(); function setValue(next: string): void { value = next; onvaluechange?.(next); } provideSandboxTabsContext({ get value() { return value; }, setValue });</script>
|
|
2
|
-
<div class={cn('w-full', className)} data-value={value}
|
|
1
|
+
<script lang="ts">import type { Snippet } from 'svelte'; import { cn } from '../../utils.js'; import { provideSandboxTabsContext } from './context.svelte.js'; let { defaultValue = '', value = $bindable(defaultValue), class: className = '', children, onvaluechange, onValueChange, ...rest }: { value?: string; defaultValue?: string; class?: string; children?: Snippet; onvaluechange?: (value: string) => void; onValueChange?: (value: string) => void; [key: string]: unknown } = $props(); const id = $props.id(); function setValue(next: string): void { value = next; onvaluechange?.(next); if (onValueChange !== onvaluechange) onValueChange?.(next); } function partId(kind: 'tab' | 'panel', next: string): string { return `${id}-${kind}-${encodeURIComponent(next)}`; } provideSandboxTabsContext({ get value() { return value; }, setValue, tabId(next) { return partId('tab', next); }, panelId(next) { return partId('panel', next); } });</script>
|
|
2
|
+
<div {...rest} class={cn('w-full', className)} data-value={value}>{@render children?.()}</div>
|
|
@@ -5,6 +5,7 @@ type $$ComponentProps = {
|
|
|
5
5
|
class?: string;
|
|
6
6
|
children?: Snippet;
|
|
7
7
|
onvaluechange?: (value: string) => void;
|
|
8
|
+
onValueChange?: (value: string) => void;
|
|
8
9
|
[key: string]: unknown;
|
|
9
10
|
};
|
|
10
11
|
declare const SandboxTabs: import("svelte").Component<$$ComponentProps, {}, "value">;
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte'; import type { HTMLButtonAttributes } from 'svelte/elements'; import { cn } from '../../utils.js'; import { useSandboxTabsContext } from './context.svelte.js';
|
|
3
|
+
interface Props extends Omit<HTMLButtonAttributes, 'children' | 'class' | 'value'> { value: string; class?: string; children?: Snippet; }
|
|
4
|
+
let { value, class: className = '', children, disabled = false, onclick, onkeydown, ...rest }: Props = $props(); const context = useSandboxTabsContext(); const active = $derived(context.value === value);
|
|
5
|
+
function select(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }): void { onclick?.(event); if (!event.defaultPrevented) context.setValue(value); }
|
|
6
|
+
function moveFocus(event: KeyboardEvent & { currentTarget: EventTarget & HTMLButtonElement }): void {
|
|
7
|
+
onkeydown?.(event); if (event.defaultPrevented || !['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(event.key)) return;
|
|
8
|
+
const tabs = Array.from(event.currentTarget.closest('[role="tablist"]')?.querySelectorAll<HTMLButtonElement>('[role="tab"]:not(:disabled)') ?? []); const current = tabs.indexOf(event.currentTarget); if (current < 0 || tabs.length === 0) return;
|
|
9
|
+
event.preventDefault(); const delta = event.key === 'ArrowLeft' || event.key === 'ArrowUp' ? -1 : 1; const target = event.key === 'Home' ? tabs[0] : event.key === 'End' ? tabs.at(-1) : tabs[(current + delta + tabs.length) % tabs.length]; target?.focus(); target?.click();
|
|
10
|
+
}
|
|
11
|
+
</script>
|
|
12
|
+
<button {...rest} id={context.tabId(value)} type="button" role="tab" aria-controls={context.panelId(value)} aria-selected={active} data-state={active ? 'active' : 'inactive'} tabindex={active ? 0 : -1} class={cn('rounded-none border-0 border-b-2 border-transparent bg-transparent px-4 py-2 text-sm font-medium text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring', active && 'border-primary text-foreground', className)} {disabled} onclick={select} onkeydown={moveFocus}>{@render children?.()}</button>
|