@svadmin/ai-elements 0.2.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 +27 -4
- package/dist/ai.css +35 -1
- package/dist/components/ChatDialog.svelte +10 -7
- 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/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/package.json +4 -3
package/README.md
CHANGED
|
@@ -58,7 +58,8 @@ The packed-package verification loads the root entry through `vite.ssrLoadModule
|
|
|
58
58
|
import {
|
|
59
59
|
Conversation,
|
|
60
60
|
Message,
|
|
61
|
-
|
|
61
|
+
MessageContent,
|
|
62
|
+
MessageResponse,
|
|
62
63
|
messageText,
|
|
63
64
|
PromptInput,
|
|
64
65
|
} from '@svadmin/ai-elements';
|
|
@@ -75,9 +76,9 @@ The packed-package verification loads the root entry through `vite.ssrLoadModule
|
|
|
75
76
|
|
|
76
77
|
<Conversation>
|
|
77
78
|
<Message from={message.role} data-message-id={message.id}>
|
|
78
|
-
<
|
|
79
|
-
<
|
|
80
|
-
</
|
|
79
|
+
<MessageContent>
|
|
80
|
+
<MessageResponse content={messageText(message)} />
|
|
81
|
+
</MessageContent>
|
|
81
82
|
</Message>
|
|
82
83
|
</Conversation>
|
|
83
84
|
|
|
@@ -107,6 +108,28 @@ export const componentRegistry = {
|
|
|
107
108
|
};
|
|
108
109
|
```
|
|
109
110
|
|
|
111
|
+
Admin tools use the same TypeBox boundary. Call tools through
|
|
112
|
+
`executeAdminTool` so untrusted model arguments are decoded before the tool
|
|
113
|
+
implementation runs:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { Type } from '@sinclair/typebox';
|
|
117
|
+
import { defineAdminTool, executeAdminTool } from '@svadmin/core';
|
|
118
|
+
|
|
119
|
+
const searchInventory = defineAdminTool({
|
|
120
|
+
name: 'searchInventory',
|
|
121
|
+
description: 'Search inventory by warehouse',
|
|
122
|
+
parameters: Type.Object({
|
|
123
|
+
warehouse: Type.String(),
|
|
124
|
+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100 })),
|
|
125
|
+
}),
|
|
126
|
+
readOnly: true,
|
|
127
|
+
execute: async ({ warehouse, limit }) => inventory.search({ warehouse, limit }),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
await executeAdminTool(searchInventory, modelArguments);
|
|
131
|
+
```
|
|
132
|
+
|
|
110
133
|
## Upstream parity
|
|
111
134
|
|
|
112
135
|
`AI_ELEMENT_PARITY` pins the audited `vercel/ai-elements` commit and verifies
|
package/dist/ai.css
CHANGED
|
@@ -56,6 +56,39 @@
|
|
|
56
56
|
border-color: var(--border, currentColor);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
.svadmin-ai__icon-button {
|
|
60
|
+
display: inline-flex;
|
|
61
|
+
width: 2rem;
|
|
62
|
+
height: 2rem;
|
|
63
|
+
min-height: 2rem;
|
|
64
|
+
align-items: center;
|
|
65
|
+
justify-content: center;
|
|
66
|
+
border: 1px solid transparent;
|
|
67
|
+
border-radius: min(var(--radius, 0.5rem), 0.375rem);
|
|
68
|
+
padding: 0;
|
|
69
|
+
background: transparent;
|
|
70
|
+
color: var(--muted-foreground, currentColor);
|
|
71
|
+
font: inherit;
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.svadmin-ai__icon-button:hover:not(:disabled) {
|
|
77
|
+
border-color: var(--border, currentColor);
|
|
78
|
+
background: var(--muted, transparent);
|
|
79
|
+
color: var(--foreground, currentColor);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.svadmin-ai__icon-button:focus-visible {
|
|
83
|
+
outline: 2px solid var(--ring, currentColor);
|
|
84
|
+
outline-offset: 2px;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.svadmin-ai__icon-button:disabled {
|
|
88
|
+
cursor: not-allowed;
|
|
89
|
+
opacity: 0.5;
|
|
90
|
+
}
|
|
91
|
+
|
|
59
92
|
.svadmin-ai__button--danger {
|
|
60
93
|
background: var(--destructive, currentColor);
|
|
61
94
|
color: var(--destructive-foreground, Canvas);
|
|
@@ -102,5 +135,6 @@
|
|
|
102
135
|
}
|
|
103
136
|
|
|
104
137
|
@media (prefers-reduced-motion: reduce) {
|
|
105
|
-
.svadmin-ai__button
|
|
138
|
+
.svadmin-ai__button,
|
|
139
|
+
.svadmin-ai__icon-button { transition: none; }
|
|
106
140
|
}
|
|
@@ -1173,14 +1173,14 @@
|
|
|
1173
1173
|
aria-label="AI assistant"
|
|
1174
1174
|
aria-busy={isStreaming}
|
|
1175
1175
|
>
|
|
1176
|
-
<header class="flex shrink-0 items-center justify-between gap-3 border-b border-border/70 bg-
|
|
1176
|
+
<header class="flex shrink-0 items-center justify-between gap-3 border-b border-border/70 bg-card px-4 py-3 text-card-foreground">
|
|
1177
1177
|
<div class="flex min-w-0 items-center gap-2">
|
|
1178
|
-
<span class="flex size-8 shrink-0 items-center justify-center rounded-
|
|
1179
|
-
<Bot size={
|
|
1178
|
+
<span class="flex size-8 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground" aria-hidden="true">
|
|
1179
|
+
<Bot size={16} />
|
|
1180
1180
|
</span>
|
|
1181
1181
|
<div class="min-w-0">
|
|
1182
1182
|
<h2 class="truncate text-sm font-semibold">AI assistant</h2>
|
|
1183
|
-
<p class="truncate text-xs
|
|
1183
|
+
<p class="svadmin-ai__muted truncate text-xs" aria-live="polite">
|
|
1184
1184
|
{isStreaming ? 'Generating response' : (chatContext.currentResource ?? 'Workspace')}
|
|
1185
1185
|
</p>
|
|
1186
1186
|
</div>
|
|
@@ -1189,8 +1189,9 @@
|
|
|
1189
1189
|
{#if messages.length > 0}
|
|
1190
1190
|
<button
|
|
1191
1191
|
type="button"
|
|
1192
|
-
class="svadmin-
|
|
1192
|
+
class="svadmin-ai__icon-button"
|
|
1193
1193
|
aria-label="Clear conversation"
|
|
1194
|
+
title="Clear conversation"
|
|
1194
1195
|
onclick={clearChat}
|
|
1195
1196
|
>
|
|
1196
1197
|
<Trash2 size={15} aria-hidden="true" />
|
|
@@ -1198,8 +1199,9 @@
|
|
|
1198
1199
|
{/if}
|
|
1199
1200
|
<button
|
|
1200
1201
|
type="button"
|
|
1201
|
-
class="svadmin-
|
|
1202
|
+
class="svadmin-ai__icon-button"
|
|
1202
1203
|
aria-label={minimized ? 'Expand AI assistant' : 'Minimize AI assistant'}
|
|
1204
|
+
title={minimized ? 'Expand AI assistant' : 'Minimize AI assistant'}
|
|
1203
1205
|
aria-expanded={!minimized}
|
|
1204
1206
|
onclick={() => { minimized = !minimized; }}
|
|
1205
1207
|
>
|
|
@@ -1211,8 +1213,9 @@
|
|
|
1211
1213
|
</button>
|
|
1212
1214
|
<button
|
|
1213
1215
|
type="button"
|
|
1214
|
-
class="svadmin-
|
|
1216
|
+
class="svadmin-ai__icon-button"
|
|
1215
1217
|
aria-label="Close AI assistant"
|
|
1218
|
+
title="Close AI assistant"
|
|
1216
1219
|
onclick={closeDialog}
|
|
1217
1220
|
>
|
|
1218
1221
|
<X size={15} aria-hidden="true" />
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
4
|
+
export interface ActionProps extends Omit<HTMLButtonAttributes, 'children' | 'class' | 'size'> {
|
|
5
|
+
tooltip?: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
size?: 'xs' | 'sm' | 'default' | 'lg' | 'icon-xs' | 'icon-sm' | 'icon' | 'icon-lg';
|
|
8
|
+
variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
|
|
9
|
+
class?: string;
|
|
10
|
+
children?: Snippet;
|
|
11
|
+
}
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import Tooltip from '../../internal/Tooltip.svelte';
|
|
16
|
+
import { cn } from '../../utils.js';
|
|
17
|
+
let { tooltip, label, size = 'icon-sm', variant = 'ghost', class: className = '', type = 'button', children, 'aria-describedby': ariaDescribedBy, ...rest }: ActionProps = $props();
|
|
18
|
+
const actionChildren = $derived(children);
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<Tooltip content={tooltip}>
|
|
22
|
+
{#snippet children({ describedBy })}
|
|
23
|
+
<button {...rest} {type} class={cn('svadmin-ai-action', className)} data-slot="action" data-size={size} data-variant={variant} aria-describedby={[ariaDescribedBy, describedBy].filter(Boolean).join(' ') || undefined}>
|
|
24
|
+
{@render actionChildren?.()}
|
|
25
|
+
{#if label || tooltip}<span class="svadmin-ai__sr-only">{label ?? tooltip}</span>{/if}
|
|
26
|
+
</button>
|
|
27
|
+
{/snippet}
|
|
28
|
+
</Tooltip>
|
|
29
|
+
|
|
30
|
+
<style>
|
|
31
|
+
.svadmin-ai-action { display: inline-flex; min-height: 2rem; align-items: center; justify-content: center; gap: .375rem; border: 1px solid transparent; border-radius: min(var(--radius, .5rem), .375rem); padding: .375rem .625rem; background: transparent; color: var(--muted-foreground, currentColor); font: inherit; font-size: .8125rem; cursor: pointer; }
|
|
32
|
+
.svadmin-ai-action[data-size='xs'] { min-height: 1.5rem; padding: .2rem .4rem; font-size: .75rem; }
|
|
33
|
+
.svadmin-ai-action[data-size='lg'] { min-height: 2.5rem; padding-inline: 1rem; }
|
|
34
|
+
.svadmin-ai-action[data-size^='icon'] { width: 2rem; padding: 0; }
|
|
35
|
+
.svadmin-ai-action[data-size='icon-xs'] { width: 1.5rem; min-height: 1.5rem; }
|
|
36
|
+
.svadmin-ai-action[data-size='icon-lg'] { width: 2.5rem; min-height: 2.5rem; }
|
|
37
|
+
.svadmin-ai-action[data-variant='outline'] { border-color: var(--border, currentColor); }
|
|
38
|
+
.svadmin-ai-action[data-variant='default'] { background: var(--primary, currentColor); color: var(--primary-foreground, Canvas); }
|
|
39
|
+
.svadmin-ai-action[data-variant='secondary'] { background: var(--secondary, var(--muted, transparent)); color: var(--secondary-foreground, var(--foreground, currentColor)); }
|
|
40
|
+
.svadmin-ai-action[data-variant='destructive'] { background: var(--destructive, currentColor); color: var(--destructive-foreground, Canvas); }
|
|
41
|
+
.svadmin-ai-action[data-variant='link'] { padding-inline: 0; color: var(--primary, currentColor); text-decoration: underline; text-underline-offset: .2rem; }
|
|
42
|
+
.svadmin-ai-action[data-variant='ghost']:hover:not(:disabled), .svadmin-ai-action[data-variant='outline']:hover:not(:disabled) { background: var(--muted, transparent); color: var(--foreground, currentColor); }
|
|
43
|
+
.svadmin-ai-action[data-variant='default']:hover:not(:disabled) { background: color-mix(in oklch, var(--primary, currentColor) 88%, var(--background, Canvas)); color: var(--primary-foreground, Canvas); }
|
|
44
|
+
.svadmin-ai-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)); }
|
|
45
|
+
.svadmin-ai-action[data-variant='destructive']:hover:not(:disabled) { background: color-mix(in oklch, var(--destructive, currentColor) 88%, var(--background, Canvas)); color: var(--destructive-foreground, Canvas); }
|
|
46
|
+
.svadmin-ai-action:disabled { cursor: not-allowed; opacity: .5; }
|
|
47
|
+
.svadmin-ai-action:focus-visible { outline: 2px solid var(--ring, currentColor); outline-offset: 2px; }
|
|
48
|
+
</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
3
|
+
export interface ActionProps extends Omit<HTMLButtonAttributes, 'children' | 'class' | 'size'> {
|
|
4
|
+
tooltip?: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
size?: 'xs' | 'sm' | 'default' | 'lg' | 'icon-xs' | 'icon-sm' | 'icon' | 'icon-lg';
|
|
7
|
+
variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
|
|
8
|
+
class?: string;
|
|
9
|
+
children?: Snippet;
|
|
10
|
+
}
|
|
11
|
+
declare const Action: import("svelte").Component<ActionProps, {}, "">;
|
|
12
|
+
type Action = ReturnType<typeof Action>;
|
|
13
|
+
export default Action;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
export type ActionsProps = 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 }: ActionsProps = $props();
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<div {...rest} class={cn('flex items-center gap-1', className)} data-slot="actions">{@render children?.()}</div>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
export type ActionsProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
|
|
4
|
+
class?: string;
|
|
5
|
+
children?: Snippet;
|
|
6
|
+
};
|
|
7
|
+
declare const Actions: import("svelte").Component<ActionsProps, {}, "">;
|
|
8
|
+
type Actions = ReturnType<typeof Actions>;
|
|
9
|
+
export default Actions;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
label?: string;
|
|
8
8
|
tooltip?: string;
|
|
9
9
|
icon?: LucideIcon;
|
|
10
|
-
size?: 'sm' | 'default' | 'icon' | 'icon-sm' | 'lg';
|
|
11
|
-
variant?: 'default' | 'outline' | 'ghost';
|
|
10
|
+
size?: 'xs' | 'sm' | 'default' | 'lg' | 'icon-xs' | 'icon-sm' | 'icon' | 'icon-lg';
|
|
11
|
+
variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
|
|
12
12
|
title?: string;
|
|
13
13
|
class?: string;
|
|
14
14
|
children?: Snippet;
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
<script lang="ts">
|
|
19
19
|
import { cn } from '../../utils.js';
|
|
20
|
+
import Tooltip from '../../internal/Tooltip.svelte';
|
|
20
21
|
let {
|
|
21
22
|
label,
|
|
22
23
|
tooltip,
|
|
@@ -32,30 +33,34 @@
|
|
|
32
33
|
}: ArtifactActionProps = $props();
|
|
33
34
|
const accessibleLabel = $derived(label ?? tooltip);
|
|
34
35
|
const Icon = $derived(icon);
|
|
35
|
-
const
|
|
36
|
-
const describedBy = $derived([ariaDescribedBy, tooltip ? tooltipId : undefined].filter(Boolean).join(' ') || undefined);
|
|
36
|
+
const actionChildren = $derived(children);
|
|
37
37
|
</script>
|
|
38
38
|
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
<Tooltip content={tooltip}>
|
|
40
|
+
{#snippet children({ describedBy: tooltipDescribedBy })}
|
|
41
|
+
<button {...rest} {type} class={cn('svadmin-ai-artifact-part__action', className)} aria-label={accessibleLabel} aria-describedby={[ariaDescribedBy, tooltipDescribedBy].filter(Boolean).join(' ') || undefined} {title} data-slot="artifact-action" data-size={size} data-variant={variant}>
|
|
42
|
+
{#if Icon}<Icon size={16} aria-hidden="true" />{:else}{@render actionChildren?.()}{/if}
|
|
42
43
|
{#if accessibleLabel}<span class="svadmin-ai__sr-only">{accessibleLabel}</span>{/if}
|
|
43
44
|
</button>
|
|
44
|
-
{
|
|
45
|
-
</
|
|
45
|
+
{/snippet}
|
|
46
|
+
</Tooltip>
|
|
46
47
|
|
|
47
48
|
<style>
|
|
48
|
-
.svadmin-ai-artifact-part__action-anchor { position: relative; display: inline-flex; }
|
|
49
49
|
.svadmin-ai-artifact-part__action { display: inline-flex; min-height: 2rem; align-items: center; justify-content: center; gap: .35rem; border: 1px solid transparent; border-radius: min(var(--radius, .5rem), .5rem); padding: .35rem .5rem; background: transparent; color: var(--muted-foreground, currentColor); font: inherit; font-size: .78rem; cursor: pointer; }
|
|
50
|
-
.svadmin-ai-artifact-part__action[data-size='
|
|
50
|
+
.svadmin-ai-artifact-part__action[data-size='xs'] { min-height: 1.5rem; padding: .2rem .4rem; font-size: .72rem; }
|
|
51
|
+
.svadmin-ai-artifact-part__action[data-size^='icon'] { width: 2rem; padding: 0; }
|
|
52
|
+
.svadmin-ai-artifact-part__action[data-size='icon-xs'] { width: 1.5rem; min-height: 1.5rem; }
|
|
53
|
+
.svadmin-ai-artifact-part__action[data-size='icon-lg'] { width: 2.5rem; min-height: 2.5rem; }
|
|
51
54
|
.svadmin-ai-artifact-part__action[data-size='lg'] { min-height: 2.5rem; padding-inline: .75rem; }
|
|
52
55
|
.svadmin-ai-artifact-part__action[data-variant='outline'] { border-color: var(--border, currentColor); }
|
|
53
56
|
.svadmin-ai-artifact-part__action[data-variant='default'] { border-color: var(--primary, currentColor); background: var(--primary, currentColor); color: var(--primary-foreground, Canvas); }
|
|
54
|
-
.svadmin-ai-artifact-part__action
|
|
57
|
+
.svadmin-ai-artifact-part__action[data-variant='secondary'] { background: var(--secondary, var(--muted, transparent)); color: var(--secondary-foreground, var(--foreground, currentColor)); }
|
|
58
|
+
.svadmin-ai-artifact-part__action[data-variant='destructive'] { background: var(--destructive, currentColor); color: var(--destructive-foreground, Canvas); }
|
|
59
|
+
.svadmin-ai-artifact-part__action[data-variant='link'] { padding-inline: 0; color: var(--primary, currentColor); text-decoration: underline; text-underline-offset: .2rem; }
|
|
60
|
+
.svadmin-ai-artifact-part__action[data-variant='ghost']:hover:not(:disabled), .svadmin-ai-artifact-part__action[data-variant='outline']:hover:not(:disabled) { border-color: var(--border, currentColor); background: var(--muted, transparent); color: var(--foreground, currentColor); }
|
|
61
|
+
.svadmin-ai-artifact-part__action[data-variant='default']:hover:not(:disabled) { border-color: var(--primary, currentColor); background: color-mix(in oklch, var(--primary, currentColor) 88%, var(--background, Canvas)); color: var(--primary-foreground, Canvas); }
|
|
62
|
+
.svadmin-ai-artifact-part__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)); }
|
|
63
|
+
.svadmin-ai-artifact-part__action[data-variant='destructive']:hover:not(:disabled) { border-color: var(--destructive, currentColor); background: color-mix(in oklch, var(--destructive, currentColor) 88%, var(--background, Canvas)); color: var(--destructive-foreground, Canvas); }
|
|
55
64
|
.svadmin-ai-artifact-part__action:focus-visible { outline: 2px solid var(--ring, currentColor); outline-offset: 2px; }
|
|
56
65
|
.svadmin-ai-artifact-part__action:disabled { cursor: not-allowed; opacity: .5; }
|
|
57
|
-
.svadmin-ai-artifact-part__tooltip { position: absolute; z-index: 50; bottom: calc(100% + .5rem); left: 50%; width: max-content; max-width: 16rem; transform: translateX(-50%); visibility: hidden; border-radius: min(var(--radius, .5rem), .375rem); padding: .375rem .5rem; background: var(--popover, var(--foreground, currentColor)); color: var(--popover-foreground, var(--background, Canvas)); font-size: .75rem; line-height: 1.25; opacity: 0; pointer-events: none; transition: opacity 120ms ease, visibility 120ms ease; }
|
|
58
|
-
.svadmin-ai-artifact-part__action-anchor:hover .svadmin-ai-artifact-part__tooltip,
|
|
59
|
-
.svadmin-ai-artifact-part__action-anchor:focus-within .svadmin-ai-artifact-part__tooltip { visibility: visible; opacity: 1; }
|
|
60
|
-
@media (prefers-reduced-motion: reduce) { .svadmin-ai-artifact-part__tooltip { transition: none; } }
|
|
61
66
|
</style>
|
|
@@ -5,8 +5,8 @@ export interface ArtifactActionProps extends Omit<HTMLButtonAttributes, 'childre
|
|
|
5
5
|
label?: string;
|
|
6
6
|
tooltip?: string;
|
|
7
7
|
icon?: LucideIcon;
|
|
8
|
-
size?: 'sm' | 'default' | 'icon' | 'icon-sm' | 'lg';
|
|
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
|
title?: string;
|
|
11
11
|
class?: string;
|
|
12
12
|
children?: Snippet;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { CodeBlockProps } from '../code-block/CodeBlock.svelte';
|
|
3
|
+
export type CodeRootProps = Omit<CodeBlockProps, 'language' | 'lang' | 'showLineNumbers'> & {
|
|
4
|
+
code: string;
|
|
5
|
+
lang?: string;
|
|
6
|
+
language?: string;
|
|
7
|
+
hideLines?: boolean;
|
|
8
|
+
};
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import CodeBlock from '../code-block/CodeBlock.svelte';
|
|
13
|
+
let { code, lang = 'typescript', language, hideLines = false, ...rest }: CodeRootProps = $props();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<CodeBlock {...rest} {code} language={language ?? lang} showLineNumbers={!hideLines} />
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CodeBlockProps } from '../code-block/CodeBlock.svelte';
|
|
2
|
+
export type CodeRootProps = Omit<CodeBlockProps, 'language' | 'lang' | 'showLineNumbers'> & {
|
|
3
|
+
code: string;
|
|
4
|
+
lang?: string;
|
|
5
|
+
language?: string;
|
|
6
|
+
hideLines?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare const Code: import("svelte").Component<CodeRootProps, {}, "">;
|
|
9
|
+
type Code = ReturnType<typeof Code>;
|
|
10
|
+
export default Code;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type VariantProps } from 'tailwind-variants';
|
|
2
|
+
export declare const codeVariants: import("tailwind-variants").TVReturnType<{
|
|
3
|
+
variant: {
|
|
4
|
+
default: "";
|
|
5
|
+
secondary: "border-transparent bg-secondary";
|
|
6
|
+
};
|
|
7
|
+
}, undefined, "relative h-full overflow-auto rounded-md border border-border bg-background text-foreground", {
|
|
8
|
+
variant: {
|
|
9
|
+
default: "";
|
|
10
|
+
secondary: "border-transparent bg-secondary";
|
|
11
|
+
};
|
|
12
|
+
}, undefined, import("tailwind-variants").TVReturnTypeLike<{
|
|
13
|
+
variant: {
|
|
14
|
+
default: "";
|
|
15
|
+
secondary: "border-transparent bg-secondary";
|
|
16
|
+
};
|
|
17
|
+
}, undefined>>;
|
|
18
|
+
export type CodeVariant = VariantProps<typeof codeVariants>['variant'];
|
|
19
|
+
export { default, default as Root, default as Code } from './Code.svelte';
|
|
20
|
+
export { default as Overflow, default as CodeOverflow } from '../code-block/CodeBlockOverflow.svelte';
|
|
21
|
+
export { default as CopyButton, default as CodeCopyButton } from '../code-block/CodeBlockCopyButton.svelte';
|
|
22
|
+
export type { CodeBlockOverflowProps as CodeOverflowProps } from '../code-block/CodeBlockOverflow.svelte';
|
|
23
|
+
export type { CodeRootProps } from './Code.svelte';
|
|
@@ -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';
|