@svadmin/ai-elements 0.2.0 → 0.4.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 +32 -4
- package/UPSTREAM_PARITY.md +69 -0
- package/dist/ai.css +49 -1
- package/dist/components/ChatDialog.svelte +44 -38
- package/dist/components/ChatDialog.svelte.d.ts +5 -5
- package/dist/components/CopilotPanel.svelte +2 -2
- 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 +21 -16
- package/dist/components/artifact/ArtifactAction.svelte.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/commit/CommitActions.svelte +10 -1
- package/dist/components/message/MessageAction.svelte +22 -16
- 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 +9 -7
- package/dist/components/message/MessageResponse.svelte.d.ts +1 -1
- package/dist/components/message/index.d.ts +6 -0
- package/dist/components/message/index.js +3 -0
- package/dist/components/prompt-input/PromptInput.svelte +1 -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/PromptInputToolbar.svelte +14 -0
- package/dist/components/prompt-input/PromptInputToolbar.svelte.d.ts +9 -0
- package/dist/components/prompt-input/index.d.ts +8 -0
- package/dist/components/prompt-input/index.js +4 -0
- package/dist/components/response/index.d.ts +2 -0
- package/dist/components/response/index.js +1 -0
- package/dist/components/tool/ToolHeader.svelte +4 -17
- package/dist/components/voice-selector/VoiceSelectorRoot.svelte.d.ts +1 -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/contracts.d.ts +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +7 -3
- package/dist/internal/Tooltip.svelte +124 -0
- package/dist/internal/Tooltip.svelte.d.ts +12 -0
- package/dist/parity-manifest.d.ts +1 -0
- package/dist/parity-manifest.js +97 -0
- package/dist/utils.d.ts +1 -2
- package/dist/utils.js +1 -5
- package/package.json +6 -4
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { tv } from 'tailwind-variants';
|
|
2
|
+
export const codeVariants = tv({
|
|
3
|
+
base: 'relative h-full overflow-auto rounded-md border border-border bg-background text-foreground',
|
|
4
|
+
variants: {
|
|
5
|
+
variant: {
|
|
6
|
+
default: '',
|
|
7
|
+
secondary: 'border-transparent bg-secondary',
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
defaultVariants: { variant: 'default' },
|
|
11
|
+
});
|
|
12
|
+
export { default, default as Root, default as Code } from './Code.svelte';
|
|
13
|
+
export { default as Overflow, default as CodeOverflow } from '../code-block/CodeBlockOverflow.svelte';
|
|
14
|
+
export { default as CopyButton, default as CodeCopyButton } from '../code-block/CodeBlockCopyButton.svelte';
|
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
<script lang="ts">
|
|
1
|
+
<script module lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export interface CodeBlockProps {
|
|
5
|
+
code: string;
|
|
6
|
+
language?: string;
|
|
7
|
+
lang?: string;
|
|
8
|
+
showLineNumbers?: boolean;
|
|
9
|
+
hideLines?: boolean;
|
|
10
|
+
highlight?: Array<number | [number, number]>;
|
|
11
|
+
variant?: 'default' | 'secondary';
|
|
12
|
+
class?: string;
|
|
13
|
+
children?: Snippet;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { cn } from '../../utils.js';
|
|
3
20
|
import { provideCodeBlockContext } from './context.svelte.js';
|
|
4
21
|
import CodeBlockContainer from './CodeBlockContainer.svelte';
|
|
5
22
|
import CodeBlockContent from './CodeBlockContent.svelte';
|
|
6
23
|
|
|
7
|
-
let { code, language, showLineNumbers =
|
|
24
|
+
let { code, language, lang, showLineNumbers, hideLines, highlight = [], variant = 'default', class: className = '', children, ...rest }: CodeBlockProps = $props();
|
|
25
|
+
const resolvedLanguage = $derived(language ?? lang ?? 'typescript');
|
|
26
|
+
const resolvedLineNumbers = $derived(showLineNumbers ?? (hideLines === undefined ? false : !hideLines));
|
|
8
27
|
provideCodeBlockContext({ get code() { return code; } });
|
|
9
28
|
</script>
|
|
10
|
-
<CodeBlockContainer class={className} {
|
|
29
|
+
<CodeBlockContainer class={cn(variant === 'secondary' && 'bg-secondary border-transparent', className)} language={resolvedLanguage} {...rest}>
|
|
11
30
|
{@render children?.()}
|
|
12
|
-
<CodeBlockContent {code} {
|
|
31
|
+
<CodeBlockContent {code} language={resolvedLanguage} showLineNumbers={resolvedLineNumbers} {highlight} />
|
|
13
32
|
</CodeBlockContainer>
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
-
|
|
2
|
+
export interface CodeBlockProps {
|
|
3
3
|
code: string;
|
|
4
|
-
language
|
|
4
|
+
language?: string;
|
|
5
|
+
lang?: string;
|
|
5
6
|
showLineNumbers?: boolean;
|
|
7
|
+
hideLines?: boolean;
|
|
8
|
+
highlight?: Array<number | [number, number]>;
|
|
9
|
+
variant?: 'default' | 'secondary';
|
|
6
10
|
class?: string;
|
|
7
11
|
children?: Snippet;
|
|
8
12
|
[key: string]: unknown;
|
|
9
|
-
}
|
|
10
|
-
declare const CodeBlock: import("svelte").Component
|
|
13
|
+
}
|
|
14
|
+
declare const CodeBlock: import("svelte").Component<CodeBlockProps, {}, "">;
|
|
11
15
|
type CodeBlock = ReturnType<typeof CodeBlock>;
|
|
12
16
|
export default CodeBlock;
|
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
code,
|
|
8
8
|
language,
|
|
9
9
|
showLineNumbers = false,
|
|
10
|
+
highlight = [],
|
|
10
11
|
class: className = '',
|
|
11
12
|
}: {
|
|
12
13
|
code: string;
|
|
13
14
|
language: string;
|
|
14
15
|
showLineNumbers?: boolean;
|
|
16
|
+
highlight?: Array<number | [number, number]>;
|
|
15
17
|
class?: string;
|
|
16
18
|
} = $props();
|
|
17
19
|
|
|
@@ -22,6 +24,10 @@
|
|
|
22
24
|
);
|
|
23
25
|
const highlighted = $derived(highlightedResult?.key === requestKey);
|
|
24
26
|
|
|
27
|
+
function isLineHighlighted(line: number): boolean {
|
|
28
|
+
return highlight.some((entry) => typeof entry === 'number' ? entry === line : entry[0] <= line && line <= entry[1]);
|
|
29
|
+
}
|
|
30
|
+
|
|
25
31
|
$effect(() => {
|
|
26
32
|
const requestedCode = code;
|
|
27
33
|
const requestedLanguage = language;
|
|
@@ -45,5 +51,5 @@
|
|
|
45
51
|
<pre
|
|
46
52
|
class={cn('m-0 min-w-max bg-muted/30 p-4 text-sm text-foreground', className)}
|
|
47
53
|
data-highlighted={highlighted}
|
|
48
|
-
><code class="font-mono text-sm">{#each tokenized.tokens as line, lineIndex (lineIndex)}<CodeBlockLine tokens={line} lineNumber={lineIndex + 1} {showLineNumbers} />{/each}</code></pre>
|
|
54
|
+
><code class="font-mono text-sm">{#each tokenized.tokens as line, lineIndex (lineIndex)}<CodeBlockLine tokens={line} lineNumber={lineIndex + 1} {showLineNumbers} highlighted={isLineHighlighted(lineIndex + 1)} />{/each}</code></pre>
|
|
49
55
|
</div>
|
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
tokens,
|
|
9
9
|
lineNumber,
|
|
10
10
|
showLineNumbers,
|
|
11
|
+
highlighted = false,
|
|
11
12
|
}: {
|
|
12
13
|
tokens: CodeToken[];
|
|
13
14
|
lineNumber: number;
|
|
14
15
|
showLineNumbers: boolean;
|
|
16
|
+
highlighted?: boolean;
|
|
15
17
|
} = $props();
|
|
16
18
|
</script>
|
|
17
19
|
|
|
18
|
-
<span class=
|
|
20
|
+
<span class={cn('block px-1', highlighted && 'bg-secondary')} data-line-number={lineNumber} data-highlighted={highlighted}><span class={cn('mr-4 inline-block w-8 select-none text-right text-muted-foreground opacity-60', !showLineNumbers && 'hidden')} aria-hidden="true">{lineNumber}</span>{#if tokens.length === 0}{EMPTY_LINE}{:else}{#each tokens as token, tokenIndex (tokenIndex)}<span class="svadmin-ai-code-token" style:--shiki-light={token.color} style:--shiki-light-bg={token.backgroundColor} style:--shiki-dark={token.darkColor} style:--shiki-dark-bg={token.darkBackgroundColor} style:--shiki-light-font-style={token.fontStyle} style:--shiki-light-font-weight={token.fontWeight} style:--shiki-light-text-decoration={token.textDecoration} style:--shiki-dark-font-style={token.darkFontStyle} style:--shiki-dark-font-weight={token.darkFontWeight} style:--shiki-dark-text-decoration={token.darkTextDecoration}>{token.content}</span>{/each}{/if}</span>
|
|
19
21
|
|
|
20
22
|
<style>
|
|
21
23
|
.svadmin-ai-code-token {
|
|
@@ -3,6 +3,7 @@ type $$ComponentProps = {
|
|
|
3
3
|
tokens: CodeToken[];
|
|
4
4
|
lineNumber: number;
|
|
5
5
|
showLineNumbers: boolean;
|
|
6
|
+
highlighted?: boolean;
|
|
6
7
|
};
|
|
7
8
|
declare const CodeBlockLine: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
9
|
type CodeBlockLine = ReturnType<typeof CodeBlockLine>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
export interface CodeBlockOverflowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> {
|
|
5
|
+
collapsed?: boolean;
|
|
6
|
+
maxHeight?: number;
|
|
7
|
+
expandLabel?: string;
|
|
8
|
+
collapseLabel?: string;
|
|
9
|
+
class?: string;
|
|
10
|
+
children?: Snippet;
|
|
11
|
+
}
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { ChevronDown, ChevronUp } from '@lucide/svelte';
|
|
16
|
+
import { cn } from '../../utils.js';
|
|
17
|
+
let { collapsed = $bindable(true), maxHeight = 300, expandLabel = 'Expand', collapseLabel = 'Collapse', class: className = '', children, ...rest }: CodeBlockOverflowProps = $props();
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<div {...rest} class={cn('svadmin-ai-code-overflow', className)} data-code-overflow data-collapsed={collapsed} style:max-height={collapsed ? `${maxHeight}px` : undefined}>
|
|
21
|
+
{@render children?.()}
|
|
22
|
+
<button type="button" class="svadmin-ai-code-overflow__toggle" aria-expanded={!collapsed} onclick={() => collapsed = !collapsed}>
|
|
23
|
+
{#if collapsed}<ChevronDown size={14} aria-hidden="true" /> {expandLabel}{:else}<ChevronUp size={14} aria-hidden="true" /> {collapseLabel}{/if}
|
|
24
|
+
</button>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<style>
|
|
28
|
+
.svadmin-ai-code-overflow { position: relative; overflow: hidden; padding-bottom: 2.5rem; }
|
|
29
|
+
.svadmin-ai-code-overflow[data-collapsed='true']::after { position: absolute; right: 0; bottom: 0; left: 0; height: 4rem; background: var(--background, Canvas); opacity: .88; content: ''; pointer-events: none; }
|
|
30
|
+
.svadmin-ai-code-overflow__toggle { position: absolute; z-index: 1; bottom: .5rem; left: 50%; display: inline-flex; min-height: 1.75rem; align-items: center; gap: .25rem; transform: translateX(-50%); border: 1px solid var(--border, currentColor); border-radius: min(var(--radius, .5rem), .375rem); padding: .25rem .625rem; background: var(--secondary, var(--background, Canvas)); color: var(--secondary-foreground, var(--foreground, currentColor)); font: inherit; font-size: .75rem; cursor: pointer; }
|
|
31
|
+
.svadmin-ai-code-overflow__toggle:focus-visible { outline: 2px solid var(--ring, currentColor); outline-offset: 2px; }
|
|
32
|
+
</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
export interface CodeBlockOverflowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> {
|
|
4
|
+
collapsed?: boolean;
|
|
5
|
+
maxHeight?: number;
|
|
6
|
+
expandLabel?: string;
|
|
7
|
+
collapseLabel?: string;
|
|
8
|
+
class?: string;
|
|
9
|
+
children?: Snippet;
|
|
10
|
+
}
|
|
11
|
+
declare const CodeBlockOverflow: import("svelte").Component<CodeBlockOverflowProps, {}, "collapsed">;
|
|
12
|
+
type CodeBlockOverflow = ReturnType<typeof CodeBlockOverflow>;
|
|
13
|
+
export default CodeBlockOverflow;
|
|
@@ -6,6 +6,7 @@ export { default as Title, default as CodeBlockTitle } from './CodeBlockTitle.sv
|
|
|
6
6
|
export { default as Filename, default as CodeBlockFilename } from './CodeBlockFilename.svelte';
|
|
7
7
|
export { default as Actions, default as CodeBlockActions } from './CodeBlockActions.svelte';
|
|
8
8
|
export { default as CopyButton, default as CodeBlockCopyButton } from './CodeBlockCopyButton.svelte';
|
|
9
|
+
export { default as Overflow, default as CodeBlockOverflow } from './CodeBlockOverflow.svelte';
|
|
9
10
|
export { default as LanguageSelector, default as CodeBlockLanguageSelector } from './CodeBlockLanguageSelector.svelte';
|
|
10
11
|
export { default as LanguageSelectorTrigger, default as CodeBlockLanguageSelectorTrigger } from './CodeBlockLanguageSelectorTrigger.svelte';
|
|
11
12
|
export { default as LanguageSelectorValue, default as CodeBlockLanguageSelectorValue } from './CodeBlockLanguageSelectorValue.svelte';
|
|
@@ -13,3 +14,5 @@ export { default as LanguageSelectorContent, default as CodeBlockLanguageSelecto
|
|
|
13
14
|
export { default as LanguageSelectorItem, default as CodeBlockLanguageSelectorItem } from './CodeBlockLanguageSelectorItem.svelte';
|
|
14
15
|
export { createRawTokens, highlightCode } from './highlight.js';
|
|
15
16
|
export type { CodeToken, TokenizedCode } from './highlight.js';
|
|
17
|
+
export type { CodeBlockProps } from './CodeBlock.svelte';
|
|
18
|
+
export type { CodeBlockOverflowProps } from './CodeBlockOverflow.svelte';
|
|
@@ -6,6 +6,7 @@ export { default as Title, default as CodeBlockTitle } from './CodeBlockTitle.sv
|
|
|
6
6
|
export { default as Filename, default as CodeBlockFilename } from './CodeBlockFilename.svelte';
|
|
7
7
|
export { default as Actions, default as CodeBlockActions } from './CodeBlockActions.svelte';
|
|
8
8
|
export { default as CopyButton, default as CodeBlockCopyButton } from './CodeBlockCopyButton.svelte';
|
|
9
|
+
export { default as Overflow, default as CodeBlockOverflow } from './CodeBlockOverflow.svelte';
|
|
9
10
|
export { default as LanguageSelector, default as CodeBlockLanguageSelector } from './CodeBlockLanguageSelector.svelte';
|
|
10
11
|
export { default as LanguageSelectorTrigger, default as CodeBlockLanguageSelectorTrigger } from './CodeBlockLanguageSelectorTrigger.svelte';
|
|
11
12
|
export { default as LanguageSelectorValue, default as CodeBlockLanguageSelectorValue } from './CodeBlockLanguageSelectorValue.svelte';
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
<script lang="ts">import type { Snippet } from 'svelte'; import { cn } from '../../utils.js'; let { class: className = '', children, ...rest }: { class?: string; children?: Snippet; [key: string]: unknown } = $props();</script>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
class={cn('flex items-center gap-1', className)}
|
|
4
|
+
role="group"
|
|
5
|
+
onclickcapture={(event) => event.preventDefault()}
|
|
6
|
+
onclick={(event) => {
|
|
7
|
+
event.stopPropagation();
|
|
8
|
+
}}
|
|
9
|
+
onkeydown={(event) => event.stopPropagation()}
|
|
10
|
+
{...rest}
|
|
11
|
+
>{@render children?.()}</div>
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
export type MessageActionProps = Omit<HTMLButtonAttributes, 'children' | 'class' | 'size'> & {
|
|
6
6
|
tooltip?: string;
|
|
7
7
|
label?: string;
|
|
8
|
-
size?: 'sm' | 'default' | 'icon' | 'icon-sm';
|
|
9
|
-
variant?: 'default' | 'outline' | 'ghost';
|
|
8
|
+
size?: 'xs' | 'sm' | 'default' | 'lg' | 'icon-xs' | 'icon-sm' | 'icon' | 'icon-lg';
|
|
9
|
+
variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
|
|
10
10
|
class?: string;
|
|
11
11
|
children?: Snippet;
|
|
12
12
|
};
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
<script lang="ts">
|
|
16
16
|
import { cn } from '../../utils.js';
|
|
17
|
+
import Tooltip from '../../internal/Tooltip.svelte';
|
|
17
18
|
|
|
18
19
|
let {
|
|
19
20
|
tooltip,
|
|
@@ -27,11 +28,11 @@
|
|
|
27
28
|
'aria-describedby': ariaDescribedBy,
|
|
28
29
|
...rest
|
|
29
30
|
}: MessageActionProps = $props();
|
|
30
|
-
const
|
|
31
|
-
const describedBy = $derived([ariaDescribedBy, tooltip ? tooltipId : undefined].filter(Boolean).join(' ') || undefined);
|
|
31
|
+
const actionChildren = $derived(children);
|
|
32
32
|
</script>
|
|
33
33
|
|
|
34
|
-
<
|
|
34
|
+
<Tooltip content={tooltip}>
|
|
35
|
+
{#snippet children({ describedBy: tooltipDescribedBy })}
|
|
35
36
|
<button
|
|
36
37
|
{...rest}
|
|
37
38
|
{type}
|
|
@@ -40,25 +41,30 @@
|
|
|
40
41
|
data-slot="message-action"
|
|
41
42
|
data-size={size}
|
|
42
43
|
data-variant={variant}
|
|
43
|
-
aria-describedby={
|
|
44
|
+
aria-describedby={[ariaDescribedBy, tooltipDescribedBy].filter(Boolean).join(' ') || undefined}
|
|
44
45
|
>
|
|
45
|
-
{@render
|
|
46
|
+
{@render actionChildren?.()}
|
|
46
47
|
{#if label || tooltip}<span class="svadmin-ai__sr-only">{label ?? tooltip}</span>{/if}
|
|
47
48
|
</button>
|
|
48
|
-
{
|
|
49
|
-
</
|
|
49
|
+
{/snippet}
|
|
50
|
+
</Tooltip>
|
|
50
51
|
|
|
51
52
|
<style>
|
|
52
|
-
.svadmin-ai-message-action__anchor { position: relative; display: inline-flex; }
|
|
53
53
|
.svadmin-ai-message-action { display: inline-flex; min-height: 2rem; align-items: center; justify-content: center; gap: 0.375rem; border: 1px solid transparent; border-radius: min(var(--radius, 0.5rem), 0.375rem); padding: 0.375rem 0.625rem; background: transparent; color: var(--muted-foreground, currentColor); font: inherit; font-size: 0.8125rem; cursor: pointer; }
|
|
54
|
-
.svadmin-ai-message-action[data-size='
|
|
54
|
+
.svadmin-ai-message-action[data-size='xs'] { min-height: 1.5rem; padding: 0.2rem 0.4rem; font-size: 0.75rem; }
|
|
55
|
+
.svadmin-ai-message-action[data-size='lg'] { min-height: 2.5rem; padding-inline: 1rem; }
|
|
56
|
+
.svadmin-ai-message-action[data-size^='icon'] { width: 2rem; padding: 0; }
|
|
57
|
+
.svadmin-ai-message-action[data-size='icon-xs'] { width: 1.5rem; min-height: 1.5rem; }
|
|
58
|
+
.svadmin-ai-message-action[data-size='icon-lg'] { width: 2.5rem; min-height: 2.5rem; }
|
|
55
59
|
.svadmin-ai-message-action[data-variant='outline'] { border-color: var(--border, currentColor); }
|
|
56
60
|
.svadmin-ai-message-action[data-variant='default'] { background: var(--primary, currentColor); color: var(--primary-foreground, Canvas); }
|
|
57
|
-
.svadmin-ai-message-action
|
|
61
|
+
.svadmin-ai-message-action[data-variant='secondary'] { background: var(--secondary, var(--muted, transparent)); color: var(--secondary-foreground, var(--foreground, currentColor)); }
|
|
62
|
+
.svadmin-ai-message-action[data-variant='destructive'] { background: var(--destructive, currentColor); color: var(--destructive-foreground, Canvas); }
|
|
63
|
+
.svadmin-ai-message-action[data-variant='link'] { padding-inline: 0; color: var(--primary, currentColor); text-decoration: underline; text-underline-offset: 0.2rem; }
|
|
64
|
+
.svadmin-ai-message-action[data-variant='ghost']:hover:not(:disabled), .svadmin-ai-message-action[data-variant='outline']:hover:not(:disabled) { background: var(--muted, transparent); color: var(--foreground, currentColor); }
|
|
65
|
+
.svadmin-ai-message-action[data-variant='default']:hover:not(:disabled) { background: color-mix(in oklch, var(--primary, currentColor) 88%, var(--background, Canvas)); color: var(--primary-foreground, Canvas); }
|
|
66
|
+
.svadmin-ai-message-action[data-variant='secondary']:hover:not(:disabled) { background: color-mix(in oklch, var(--secondary, var(--muted, transparent)) 80%, var(--foreground, currentColor)); color: var(--secondary-foreground, var(--foreground, currentColor)); }
|
|
67
|
+
.svadmin-ai-message-action[data-variant='destructive']:hover:not(:disabled) { background: color-mix(in oklch, var(--destructive, currentColor) 88%, var(--background, Canvas)); color: var(--destructive-foreground, Canvas); }
|
|
58
68
|
.svadmin-ai-message-action:disabled { cursor: not-allowed; opacity: 0.5; }
|
|
59
69
|
.svadmin-ai-message-action:focus-visible { outline: 2px solid var(--ring, currentColor); outline-offset: 2px; }
|
|
60
|
-
.svadmin-ai-message-action__tooltip { position: absolute; z-index: 50; bottom: calc(100% + 0.5rem); left: 50%; width: max-content; max-width: 16rem; transform: translateX(-50%); visibility: hidden; border-radius: min(var(--radius, 0.5rem), 0.375rem); padding: 0.375rem 0.5rem; background: var(--popover, var(--foreground, currentColor)); color: var(--popover-foreground, var(--background, Canvas)); font-size: 0.75rem; line-height: 1.25; opacity: 0; pointer-events: none; transition: opacity 120ms ease, visibility 120ms ease; }
|
|
61
|
-
.svadmin-ai-message-action__anchor:hover .svadmin-ai-message-action__tooltip,
|
|
62
|
-
.svadmin-ai-message-action__anchor:focus-within .svadmin-ai-message-action__tooltip { visibility: visible; opacity: 1; }
|
|
63
|
-
@media (prefers-reduced-motion: reduce) { .svadmin-ai-message-action__tooltip { transition: none; } }
|
|
64
70
|
</style>
|
|
@@ -3,8 +3,8 @@ import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
|
3
3
|
export type MessageActionProps = Omit<HTMLButtonAttributes, 'children' | 'class' | 'size'> & {
|
|
4
4
|
tooltip?: string;
|
|
5
5
|
label?: string;
|
|
6
|
-
size?: 'sm' | 'default' | 'icon' | 'icon-sm';
|
|
7
|
-
variant?: 'default' | 'outline' | 'ghost';
|
|
6
|
+
size?: 'xs' | 'sm' | 'default' | 'lg' | 'icon-xs' | 'icon-sm' | 'icon' | 'icon-lg';
|
|
7
|
+
variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
|
|
8
8
|
class?: string;
|
|
9
9
|
children?: Snippet;
|
|
10
10
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
|
|
5
|
+
export interface MessageAttachmentData {
|
|
6
|
+
id: string;
|
|
7
|
+
filename?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
mediaType?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface MessageAttachmentProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> {
|
|
14
|
+
data: MessageAttachmentData;
|
|
15
|
+
class?: string;
|
|
16
|
+
onRemove?: () => void;
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { Paperclip, X } from '@lucide/svelte';
|
|
23
|
+
import { cn, safeResourceUrl } from '../../utils.js';
|
|
24
|
+
import MessageAttachmentPreview from './MessageAttachmentPreview.svelte';
|
|
25
|
+
|
|
26
|
+
let { data, class: className = '', onRemove, children, ...rest }: MessageAttachmentProps = $props();
|
|
27
|
+
const filename = $derived(data.filename ?? data.name ?? '');
|
|
28
|
+
const isImage = $derived(Boolean(data.url && data.mediaType?.startsWith('image/')));
|
|
29
|
+
const safeUrl = $derived(safeResourceUrl(data.url));
|
|
30
|
+
|
|
31
|
+
function remove(event: MouseEvent): void {
|
|
32
|
+
event.stopPropagation();
|
|
33
|
+
onRemove?.();
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<div {...rest} class={cn('svadmin-ai-message-attachment', className)} data-slot="message-attachment" data-media={isImage ? 'image' : 'file'}>
|
|
38
|
+
{#if children}
|
|
39
|
+
{@render children()}
|
|
40
|
+
{:else if isImage && safeUrl}
|
|
41
|
+
<MessageAttachmentPreview {data} />
|
|
42
|
+
{:else}
|
|
43
|
+
<div class="svadmin-ai-message-attachment__file" title={filename || 'Attachment'}>
|
|
44
|
+
<Paperclip size={16} aria-hidden="true" />
|
|
45
|
+
<span>{filename || 'Attachment'}</span>
|
|
46
|
+
</div>
|
|
47
|
+
{/if}
|
|
48
|
+
{#if onRemove}
|
|
49
|
+
<button class="svadmin-ai-message-attachment__remove" type="button" aria-label="Remove attachment" title="Remove attachment" onclick={remove}>
|
|
50
|
+
<X size={13} aria-hidden="true" />
|
|
51
|
+
</button>
|
|
52
|
+
{/if}
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<style>
|
|
56
|
+
.svadmin-ai-message-attachment { position: relative; width: 6rem; height: 6rem; overflow: hidden; border: 1px solid var(--border, currentColor); border-radius: min(var(--radius, .5rem), .5rem); background: var(--muted, transparent); color: var(--foreground, currentColor); }
|
|
57
|
+
.svadmin-ai-message-attachment[data-media='file'] { display: flex; width: auto; min-width: 8rem; max-width: min(18rem, 100%); height: 2.25rem; align-items: center; padding: .35rem .6rem; background: var(--card, transparent); }
|
|
58
|
+
.svadmin-ai-message-attachment__file { display: flex; min-width: 0; align-items: center; gap: .45rem; color: var(--muted-foreground, currentColor); font-size: .78rem; }
|
|
59
|
+
.svadmin-ai-message-attachment__file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
60
|
+
.svadmin-ai-message-attachment__remove { position: absolute; top: .35rem; right: .35rem; display: inline-flex; width: 1.5rem; height: 1.5rem; align-items: center; justify-content: center; border: 1px solid var(--border, currentColor); border-radius: 999px; background: color-mix(in oklch, var(--background, transparent) 86%, transparent); color: var(--muted-foreground, currentColor); cursor: pointer; opacity: 0; }
|
|
61
|
+
.svadmin-ai-message-attachment:hover .svadmin-ai-message-attachment__remove, .svadmin-ai-message-attachment__remove:focus-visible { opacity: 1; }
|
|
62
|
+
.svadmin-ai-message-attachment__remove:hover { color: var(--destructive, currentColor); }
|
|
63
|
+
.svadmin-ai-message-attachment__remove:focus-visible { outline: 2px solid var(--ring, currentColor); outline-offset: 2px; }
|
|
64
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
export interface MessageAttachmentData {
|
|
4
|
+
id: string;
|
|
5
|
+
filename?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
mediaType?: string;
|
|
8
|
+
url?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface MessageAttachmentProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> {
|
|
11
|
+
data: MessageAttachmentData;
|
|
12
|
+
class?: string;
|
|
13
|
+
onRemove?: () => void;
|
|
14
|
+
children?: Snippet;
|
|
15
|
+
}
|
|
16
|
+
declare const MessageAttachment: import("svelte").Component<MessageAttachmentProps, {}, "">;
|
|
17
|
+
type MessageAttachment = ReturnType<typeof MessageAttachment>;
|
|
18
|
+
export default MessageAttachment;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { MessageAttachmentData } from './MessageAttachment.svelte';
|
|
4
|
+
|
|
5
|
+
export interface MessageAttachmentPreviewProps extends Omit<HTMLAttributes<HTMLButtonElement>, 'class'> {
|
|
6
|
+
data: MessageAttachmentData;
|
|
7
|
+
class?: string;
|
|
8
|
+
}
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { X } from '@lucide/svelte';
|
|
13
|
+
import { cn, safeResourceUrl } from '../../utils.js';
|
|
14
|
+
|
|
15
|
+
let { data, class: className = '', ...rest }: MessageAttachmentPreviewProps = $props();
|
|
16
|
+
const src = $derived(safeResourceUrl(data.url));
|
|
17
|
+
const label = $derived(data.filename ?? data.name ?? 'Image attachment');
|
|
18
|
+
let dialog = $state<HTMLDialogElement | null>(null);
|
|
19
|
+
|
|
20
|
+
function openPreview(): void {
|
|
21
|
+
if (typeof dialog?.showModal === 'function') dialog.showModal();
|
|
22
|
+
else dialog?.setAttribute('open', '');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function closePreview(): void {
|
|
26
|
+
if (typeof dialog?.close === 'function') dialog.close();
|
|
27
|
+
else dialog?.removeAttribute('open');
|
|
28
|
+
}
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<button {...rest} class={cn('svadmin-ai-message-attachment-preview', className)} type="button" aria-label={`Preview ${label}`} onclick={openPreview}>
|
|
32
|
+
{#if src}<img src={src} alt={label} width="96" height="96" />{:else}<X aria-hidden="true" />{/if}
|
|
33
|
+
</button>
|
|
34
|
+
{#if src}
|
|
35
|
+
<dialog bind:this={dialog} class="svadmin-ai-message-attachment-dialog" aria-label={`${label} preview`} onclick={(event) => { if (event.target === dialog) closePreview(); }}>
|
|
36
|
+
<button type="button" class="svadmin-ai-message-attachment-dialog__close" aria-label="Close preview" onclick={closePreview}><X size={18} aria-hidden="true" /></button>
|
|
37
|
+
<img src={src} alt={`${label} preview`} />
|
|
38
|
+
</dialog>
|
|
39
|
+
{/if}
|
|
40
|
+
|
|
41
|
+
<style>
|
|
42
|
+
.svadmin-ai-message-attachment-preview { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
|
|
43
|
+
.svadmin-ai-message-attachment-preview img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .2s ease; }
|
|
44
|
+
.svadmin-ai-message-attachment-preview:hover img { transform: scale(1.03); }
|
|
45
|
+
.svadmin-ai-message-attachment-preview:focus-visible { outline: 2px solid var(--ring, currentColor); outline-offset: -2px; }
|
|
46
|
+
.svadmin-ai-message-attachment-dialog { width: min(94vw, 68rem); max-width: none; max-height: 88vh; 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); }
|
|
47
|
+
.svadmin-ai-message-attachment-dialog::backdrop { background: color-mix(in oklch, var(--foreground, currentColor) 45%, transparent); }
|
|
48
|
+
.svadmin-ai-message-attachment-dialog img { display: block; width: 100%; max-height: calc(88vh - 3.5rem); object-fit: contain; }
|
|
49
|
+
.svadmin-ai-message-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; }
|
|
50
|
+
.svadmin-ai-message-attachment-dialog__close:focus-visible { outline: 2px solid var(--ring, currentColor); outline-offset: 2px; }
|
|
51
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
import type { MessageAttachmentData } from './MessageAttachment.svelte';
|
|
3
|
+
export interface MessageAttachmentPreviewProps extends Omit<HTMLAttributes<HTMLButtonElement>, 'class'> {
|
|
4
|
+
data: MessageAttachmentData;
|
|
5
|
+
class?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const MessageAttachmentPreview: import("svelte").Component<MessageAttachmentPreviewProps, {}, "">;
|
|
8
|
+
type MessageAttachmentPreview = ReturnType<typeof MessageAttachmentPreview>;
|
|
9
|
+
export default MessageAttachmentPreview;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
|
|
5
|
+
export interface MessageAttachmentsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> {
|
|
6
|
+
class?: string;
|
|
7
|
+
children?: Snippet;
|
|
8
|
+
}
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { cn } from '../../utils.js';
|
|
13
|
+
|
|
14
|
+
let { class: className = '', children, ...rest }: MessageAttachmentsProps = $props();
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
{#if children}
|
|
18
|
+
<div {...rest} class={cn('svadmin-ai-message-attachments', className)} data-slot="message-attachments">
|
|
19
|
+
{@render children()}
|
|
20
|
+
</div>
|
|
21
|
+
{/if}
|
|
22
|
+
|
|
23
|
+
<style>
|
|
24
|
+
.svadmin-ai-message-attachments { display: flex; width: fit-content; max-width: 100%; flex-wrap: wrap; align-items: flex-start; justify-content: flex-end; gap: .5rem; margin-inline-start: auto; }
|
|
25
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
export interface MessageAttachmentsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> {
|
|
4
|
+
class?: string;
|
|
5
|
+
children?: Snippet;
|
|
6
|
+
}
|
|
7
|
+
declare const MessageAttachments: import("svelte").Component<MessageAttachmentsProps, {}, "">;
|
|
8
|
+
type MessageAttachments = ReturnType<typeof MessageAttachments>;
|
|
9
|
+
export default MessageAttachments;
|
|
@@ -5,29 +5,31 @@
|
|
|
5
5
|
export type MessageResponseProps = Omit<ResponseProps, 'children' | 'streaming'> & {
|
|
6
6
|
streaming?: boolean;
|
|
7
7
|
isAnimating?: boolean;
|
|
8
|
-
children?: Snippet;
|
|
8
|
+
children?: Snippet | string;
|
|
9
9
|
};
|
|
10
10
|
</script>
|
|
11
11
|
|
|
12
12
|
<script lang="ts">
|
|
13
13
|
import Response from '../Response.svelte';
|
|
14
|
-
import { cn } from '../../utils.js';
|
|
15
|
-
|
|
16
14
|
let {
|
|
17
15
|
content = '',
|
|
18
16
|
text,
|
|
19
17
|
streaming = false,
|
|
20
18
|
isAnimating,
|
|
21
|
-
class: className = '',
|
|
22
19
|
children,
|
|
20
|
+
class: className = '',
|
|
23
21
|
...rest
|
|
24
22
|
}: MessageResponseProps = $props();
|
|
25
23
|
</script>
|
|
26
24
|
|
|
27
|
-
{#if children}
|
|
28
|
-
<
|
|
25
|
+
{#if typeof children === 'string'}
|
|
26
|
+
<Response {...rest} content={children} streaming={isAnimating ?? streaming} class={className} />
|
|
27
|
+
{:else if text ?? content}
|
|
28
|
+
<Response {...rest} content={text ?? content} streaming={isAnimating ?? streaming} class={className} />
|
|
29
|
+
{:else if children}
|
|
30
|
+
<div {...rest} class={`svadmin-ai__markdown ${className}`.trim()}>
|
|
29
31
|
{@render children()}
|
|
30
32
|
</div>
|
|
31
33
|
{:else}
|
|
32
|
-
<Response {...rest} content=
|
|
34
|
+
<Response {...rest} content="" streaming={isAnimating ?? streaming} class={className} />
|
|
33
35
|
{/if}
|
|
@@ -3,7 +3,7 @@ import type { ResponseProps } from '../Response.svelte';
|
|
|
3
3
|
export type MessageResponseProps = Omit<ResponseProps, 'children' | 'streaming'> & {
|
|
4
4
|
streaming?: boolean;
|
|
5
5
|
isAnimating?: boolean;
|
|
6
|
-
children?: Snippet;
|
|
6
|
+
children?: Snippet | string;
|
|
7
7
|
};
|
|
8
8
|
declare const MessageResponse: import("svelte").Component<MessageResponseProps, {}, "">;
|
|
9
9
|
type MessageResponse = ReturnType<typeof MessageResponse>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { default, default as Root, default as Message } from '../Message.svelte';
|
|
2
|
+
export { default as MessageAttachments, default as Attachments } from './MessageAttachments.svelte';
|
|
3
|
+
export { default as MessageAttachment, default as Attachment } from './MessageAttachment.svelte';
|
|
4
|
+
export { default as MessageAttachmentPreview, default as AttachmentPreview } from './MessageAttachmentPreview.svelte';
|
|
2
5
|
export { default as Content, default as MessageContent } from '../MessageContent.svelte';
|
|
3
6
|
export { default as Avatar, default as MessageAvatar } from '../MessageAvatar.svelte';
|
|
4
7
|
export { default as Actions, default as MessageActions } from '../MessageActions.svelte';
|
|
@@ -16,3 +19,6 @@ export type { MessageContentProps } from '../MessageContent.svelte';
|
|
|
16
19
|
export type { MessageActionProps } from './MessageAction.svelte';
|
|
17
20
|
export type { MessageBranchContentProps } from './MessageBranchContent.svelte';
|
|
18
21
|
export type { MessageResponseProps } from './MessageResponse.svelte';
|
|
22
|
+
export type { MessageAttachmentsProps } from './MessageAttachments.svelte';
|
|
23
|
+
export type { MessageAttachmentData, MessageAttachmentProps } from './MessageAttachment.svelte';
|
|
24
|
+
export type { MessageAttachmentPreviewProps } from './MessageAttachmentPreview.svelte';
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { default, default as Root, default as Message } from '../Message.svelte';
|
|
2
|
+
export { default as MessageAttachments, default as Attachments } from './MessageAttachments.svelte';
|
|
3
|
+
export { default as MessageAttachment, default as Attachment } from './MessageAttachment.svelte';
|
|
4
|
+
export { default as MessageAttachmentPreview, default as AttachmentPreview } from './MessageAttachmentPreview.svelte';
|
|
2
5
|
export { default as Content, default as MessageContent } from '../MessageContent.svelte';
|
|
3
6
|
export { default as Avatar, default as MessageAvatar } from '../MessageAvatar.svelte';
|
|
4
7
|
export { default as Actions, default as MessageActions } from '../MessageActions.svelte';
|
|
@@ -369,7 +369,7 @@
|
|
|
369
369
|
>
|
|
370
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 ?? [])} />
|
|
371
371
|
{#if syncHiddenInput}<input type="hidden" name="message" value={activeText} />{/if}
|
|
372
|
-
{#if activeFiles.length > 0}
|
|
372
|
+
{#if activeFiles.length > 0 && !children}
|
|
373
373
|
<ul class="flex flex-wrap gap-2" aria-label="Attachments">
|
|
374
374
|
{#each activeFiles as file, index (file.id)}
|
|
375
375
|
<li class="flex min-w-0 items-center gap-1 rounded border border-border px-2 py-1 text-xs">
|
|
@@ -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>
|