@widgetic/design-system 0.5.28 → 0.5.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chat/ChatHeader.svelte +29 -3
- package/dist/components/chat/ChatHeader.svelte.d.ts +5 -0
- package/dist/components/chat/Composer.svelte +58 -1
- package/dist/components/chat/Composer.svelte.d.ts +8 -0
- package/dist/components/chat/MessageCheckpointRow.svelte +87 -0
- package/dist/components/chat/MessageCheckpointRow.svelte.d.ts +21 -0
- package/dist/components/chat/MessageRatingActions.svelte +157 -0
- package/dist/components/chat/MessageRatingActions.svelte.d.ts +26 -0
- package/dist/components/chat/SuggestionCard.svelte +13 -1
- package/dist/components/chat/SuggestionCard.svelte.d.ts +5 -0
- package/dist/components/chat/chatHeaderLogic.d.ts +8 -0
- package/dist/components/chat/chatHeaderLogic.js +14 -0
- package/dist/components/chat/composerModelMenuLogic.d.ts +9 -0
- package/dist/components/chat/composerModelMenuLogic.js +12 -0
- package/dist/components/chat/index.d.ts +10 -0
- package/dist/components/chat/index.js +8 -0
- package/dist/components/chat/messageRatingActionsLogic.d.ts +11 -0
- package/dist/components/chat/messageRatingActionsLogic.js +17 -0
- package/dist/components/chat/messageRatingTypes.d.ts +2 -0
- package/dist/components/chat/messageRatingTypes.js +1 -0
- package/dist/components/color-picker/ColorPicker.svelte +324 -0
- package/dist/components/color-picker/ColorPicker.svelte.d.ts +34 -0
- package/dist/components/color-picker/colorPickerLogic.d.ts +77 -0
- package/dist/components/color-picker/colorPickerLogic.js +184 -0
- package/dist/components/color-picker/index.d.ts +2 -0
- package/dist/components/color-picker/index.js +3 -0
- package/dist/components/font-picker/FontPicker.svelte +169 -0
- package/dist/components/font-picker/FontPicker.svelte.d.ts +41 -0
- package/dist/components/font-picker/fontPickerLogic.d.ts +21 -0
- package/dist/components/font-picker/fontPickerLogic.js +29 -0
- package/dist/components/font-picker/index.d.ts +2 -0
- package/dist/components/font-picker/index.js +3 -0
- package/dist/components/index.d.ts +3 -1
- package/dist/components/index.js +3 -1
- package/dist/components/shell/ErrorState.svelte +5 -2
- package/dist/components/shell/ErrorState.svelte.d.ts +2 -1
- package/dist/components/shell/NotificationDetail.svelte +96 -0
- package/dist/components/shell/NotificationDetail.svelte.d.ts +28 -0
- package/dist/components/shell/NotificationRow.svelte +6 -4
- package/dist/components/shell/SettingsDialog.svelte +106 -9
- package/dist/components/shell/SettingsDialog.svelte.d.ts +5 -0
- package/dist/components/shell/SettingsNav.svelte +72 -23
- package/dist/components/shell/SettingsNav.svelte.d.ts +7 -0
- package/dist/components/shell/WidgetRow.svelte +6 -6
- package/dist/components/shell/WidgetRow.svelte.d.ts +2 -2
- package/dist/components/shell/index.d.ts +1 -0
- package/dist/components/shell/index.js +1 -0
- package/dist/components/toast/ToasterModal.svelte +4 -2
- package/dist/components/ui/button/button.svelte +11 -9
- package/dist/components/ui/button/button.svelte.d.ts +2 -2
- package/dist/components/ui/icon-button/icon-button.svelte +7 -6
- package/dist/components/ui/icon-button/icon-button.svelte.d.ts +2 -2
- package/dist/components/ui/scroll-area/scroll-area-scrollbar.svelte +1 -1
- package/dist/components/ui/select/select-item.svelte +18 -7
- package/dist/components/ui/select/select-item.svelte.d.ts +8 -2
- package/dist/components/ui/slider/slider.svelte +16 -1
- package/package.json +1 -1
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
import IconMessagePlus from '@tabler/icons-svelte/icons/message-plus';
|
|
8
8
|
import IconMessages from '@tabler/icons-svelte/icons/messages';
|
|
9
9
|
import IconPin from '@tabler/icons-svelte/icons/pin';
|
|
10
|
+
import IconTerminal2 from '@tabler/icons-svelte/icons/terminal-2';
|
|
10
11
|
import IconX from '@tabler/icons-svelte/icons/x';
|
|
12
|
+
import { shouldShowConsoleButton, shouldShowPinButton } from './chatHeaderLogic.js';
|
|
11
13
|
import { Button } from '../ui/button';
|
|
12
14
|
import { IconButton } from '../ui/icon-button';
|
|
13
15
|
import { cn } from '../../utils.js';
|
|
@@ -18,6 +20,7 @@
|
|
|
18
20
|
newChat: string;
|
|
19
21
|
history: string;
|
|
20
22
|
pin: string;
|
|
23
|
+
console: string;
|
|
21
24
|
close: string;
|
|
22
25
|
openHistory: string;
|
|
23
26
|
};
|
|
@@ -26,6 +29,7 @@
|
|
|
26
29
|
newChat: 'New chat',
|
|
27
30
|
history: 'Chat history',
|
|
28
31
|
pin: 'Pin chat',
|
|
32
|
+
console: 'Console',
|
|
29
33
|
close: 'Close chat',
|
|
30
34
|
openHistory: 'Open chat history'
|
|
31
35
|
};
|
|
@@ -37,11 +41,15 @@
|
|
|
37
41
|
title?: string;
|
|
38
42
|
status?: string;
|
|
39
43
|
showClose?: boolean;
|
|
44
|
+
/** When true with `onToggleConsole`, the header shows the debug console icon instead of pin. */
|
|
45
|
+
showConsole?: boolean;
|
|
46
|
+
consoleOpen?: boolean;
|
|
40
47
|
messages?: Partial<ChatHeaderMessages>;
|
|
41
48
|
onTitleClick?: () => void;
|
|
42
49
|
onNewChat?: () => void;
|
|
43
50
|
onHistory?: () => void;
|
|
44
51
|
onPin?: () => void;
|
|
52
|
+
onToggleConsole?: () => void;
|
|
45
53
|
onClose?: () => void;
|
|
46
54
|
};
|
|
47
55
|
|
|
@@ -52,17 +60,22 @@
|
|
|
52
60
|
title,
|
|
53
61
|
status,
|
|
54
62
|
showClose = false,
|
|
63
|
+
showConsole = false,
|
|
64
|
+
consoleOpen = false,
|
|
55
65
|
messages: messagesProp,
|
|
56
66
|
onTitleClick,
|
|
57
67
|
onNewChat,
|
|
58
68
|
onHistory,
|
|
59
69
|
onPin,
|
|
70
|
+
onToggleConsole,
|
|
60
71
|
onClose,
|
|
61
72
|
...restProps
|
|
62
73
|
}: Props = $props();
|
|
63
74
|
|
|
64
75
|
const messages = $derived({ ...defaultMessages, ...messagesProp });
|
|
65
76
|
const displayTitle = $derived(title?.trim() || messages.newChat);
|
|
77
|
+
const consoleVisible = $derived(shouldShowConsoleButton(showConsole, onToggleConsole));
|
|
78
|
+
const pinVisible = $derived(shouldShowPinButton(showConsole, onToggleConsole, onPin));
|
|
66
79
|
</script>
|
|
67
80
|
|
|
68
81
|
<header
|
|
@@ -92,13 +105,26 @@
|
|
|
92
105
|
|
|
93
106
|
<span class="min-w-0 flex-1" aria-hidden="true"></span>
|
|
94
107
|
|
|
95
|
-
|
|
96
|
-
<
|
|
97
|
-
|
|
108
|
+
{#if consoleVisible}
|
|
109
|
+
<IconButton
|
|
110
|
+
variant="ghost"
|
|
111
|
+
label={messages.console}
|
|
112
|
+
aria-pressed={consoleOpen}
|
|
113
|
+
onclick={onToggleConsole}
|
|
114
|
+
>
|
|
115
|
+
<IconTerminal2 class="stroke-2" />
|
|
116
|
+
</IconButton>
|
|
117
|
+
{:else if pinVisible}
|
|
118
|
+
<IconButton variant="ghost" label={messages.pin} onclick={onPin}>
|
|
119
|
+
<IconPin class="stroke-2" />
|
|
120
|
+
</IconButton>
|
|
121
|
+
{/if}
|
|
98
122
|
|
|
123
|
+
{#if onNewChat}
|
|
99
124
|
<IconButton variant="ghost" label={messages.newChat} onclick={onNewChat}>
|
|
100
125
|
<IconMessagePlus class="stroke-2" />
|
|
101
126
|
</IconButton>
|
|
127
|
+
{/if}
|
|
102
128
|
|
|
103
129
|
{#if onHistory}
|
|
104
130
|
<IconButton variant="ghost" label={messages.history} onclick={onHistory}>
|
|
@@ -4,6 +4,7 @@ export type ChatHeaderMessages = {
|
|
|
4
4
|
newChat: string;
|
|
5
5
|
history: string;
|
|
6
6
|
pin: string;
|
|
7
|
+
console: string;
|
|
7
8
|
close: string;
|
|
8
9
|
openHistory: string;
|
|
9
10
|
};
|
|
@@ -14,11 +15,15 @@ type Props = HTMLAttributes<HTMLElement> & {
|
|
|
14
15
|
title?: string;
|
|
15
16
|
status?: string;
|
|
16
17
|
showClose?: boolean;
|
|
18
|
+
/** When true with `onToggleConsole`, the header shows the debug console icon instead of pin. */
|
|
19
|
+
showConsole?: boolean;
|
|
20
|
+
consoleOpen?: boolean;
|
|
17
21
|
messages?: Partial<ChatHeaderMessages>;
|
|
18
22
|
onTitleClick?: () => void;
|
|
19
23
|
onNewChat?: () => void;
|
|
20
24
|
onHistory?: () => void;
|
|
21
25
|
onPin?: () => void;
|
|
26
|
+
onToggleConsole?: () => void;
|
|
22
27
|
onClose?: () => void;
|
|
23
28
|
};
|
|
24
29
|
declare const ChatHeader: import("svelte").Component<Props, {}, "ref">;
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
characterLimit: string;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
export type ComposerModelOption = {
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
15
20
|
export type ComposerProps = HTMLAttributes<HTMLDivElement> & {
|
|
16
21
|
ref?: HTMLDivElement | null;
|
|
17
22
|
class?: string;
|
|
@@ -21,6 +26,10 @@
|
|
|
21
26
|
disabled?: boolean;
|
|
22
27
|
maxLength?: number;
|
|
23
28
|
allowEmpty?: boolean;
|
|
29
|
+
assistantLabel?: string;
|
|
30
|
+
models?: ComposerModelOption[];
|
|
31
|
+
selectedModelId?: string | null;
|
|
32
|
+
onSelectModel?: (modelId: string) => void;
|
|
24
33
|
messages?: Partial<ComposerMessages>;
|
|
25
34
|
onSend?: (text: string) => void;
|
|
26
35
|
onStop?: () => void;
|
|
@@ -31,11 +40,19 @@
|
|
|
31
40
|
</script>
|
|
32
41
|
|
|
33
42
|
<script lang="ts">
|
|
43
|
+
import IconCheck from '@tabler/icons-svelte/icons/check';
|
|
44
|
+
import IconChevronDown from '@tabler/icons-svelte/icons/chevron-down';
|
|
34
45
|
import IconPlayerStop from '@tabler/icons-svelte/icons/player-stop';
|
|
35
46
|
import IconSend from '@tabler/icons-svelte/icons/send';
|
|
36
47
|
import { cn } from '../../utils.js';
|
|
48
|
+
import { Button } from '../ui/button/index.js';
|
|
37
49
|
import { IconButton } from '../ui/icon-button/index.js';
|
|
50
|
+
import * as DropdownMenu from '../ui/dropdown-menu';
|
|
38
51
|
import { canSendText, clampTextareaHeight, shouldSendOnKeyDown } from './composerLogic.js';
|
|
52
|
+
import {
|
|
53
|
+
selectedModelLabel,
|
|
54
|
+
shouldShowComposerModelMenu
|
|
55
|
+
} from './composerModelMenuLogic.js';
|
|
39
56
|
|
|
40
57
|
const defaultMessages: ComposerMessages = {
|
|
41
58
|
send: 'Send message',
|
|
@@ -53,6 +70,10 @@
|
|
|
53
70
|
disabled = false,
|
|
54
71
|
maxLength,
|
|
55
72
|
allowEmpty = false,
|
|
73
|
+
assistantLabel = 'Assistant',
|
|
74
|
+
models = [],
|
|
75
|
+
selectedModelId = null,
|
|
76
|
+
onSelectModel,
|
|
56
77
|
messages: messagesProp,
|
|
57
78
|
onSend,
|
|
58
79
|
onStop,
|
|
@@ -63,6 +84,9 @@
|
|
|
63
84
|
}: ComposerProps = $props();
|
|
64
85
|
|
|
65
86
|
const messages = $derived({ ...defaultMessages, ...messagesProp });
|
|
87
|
+
const modelMenuVisible = $derived(shouldShowComposerModelMenu(models));
|
|
88
|
+
const modelMenuLabel = $derived(selectedModelLabel(models, selectedModelId, assistantLabel));
|
|
89
|
+
let modelMenuOpen = $state(false);
|
|
66
90
|
|
|
67
91
|
let textareaRef = $state<HTMLTextAreaElement | null>(null);
|
|
68
92
|
let isComposing = $state(false);
|
|
@@ -148,10 +172,43 @@
|
|
|
148
172
|
</div>
|
|
149
173
|
|
|
150
174
|
<div class="flex items-center gap-2">
|
|
151
|
-
<div class="flex min-w-0 flex-1 items-center gap-1">
|
|
175
|
+
<div class="relative flex min-w-0 flex-1 items-center gap-1">
|
|
176
|
+
<!-- Figma toolbar order: the host's controls first (attach), then the model menu (mode). -->
|
|
152
177
|
{#if leading}
|
|
153
178
|
{@render leading()}
|
|
154
179
|
{/if}
|
|
180
|
+
{#if modelMenuVisible}
|
|
181
|
+
<!-- The DS dropdown handles outside click, Escape, arrow keys and focus return; the menu opens upwards because the composer sits at the bottom edge. -->
|
|
182
|
+
<DropdownMenu.Root bind:open={modelMenuOpen}>
|
|
183
|
+
<DropdownMenu.Trigger>
|
|
184
|
+
{#snippet child({ props }: { props: Record<string, unknown> })}
|
|
185
|
+
<Button
|
|
186
|
+
{...props}
|
|
187
|
+
variant="ghost"
|
|
188
|
+
size="sm"
|
|
189
|
+
class="max-w-[11rem] shrink-0 gap-1 px-2"
|
|
190
|
+
disabled={busy || disabled}
|
|
191
|
+
>
|
|
192
|
+
<span class="truncate">{modelMenuLabel}</span>
|
|
193
|
+
<IconChevronDown class="size-4 shrink-0 stroke-2" aria-hidden="true" />
|
|
194
|
+
</Button>
|
|
195
|
+
{/snippet}
|
|
196
|
+
</DropdownMenu.Trigger>
|
|
197
|
+
<DropdownMenu.Content side="top" align="start" class="max-h-48 w-56 overflow-y-auto">
|
|
198
|
+
{#each models as model (model.id)}
|
|
199
|
+
<DropdownMenu.Item
|
|
200
|
+
class="justify-between gap-2"
|
|
201
|
+
onSelect={() => onSelectModel?.(model.id)}
|
|
202
|
+
>
|
|
203
|
+
<span class="truncate">{model.label}</span>
|
|
204
|
+
{#if model.id === selectedModelId}
|
|
205
|
+
<IconCheck class="size-4 shrink-0 stroke-2" aria-hidden="true" />
|
|
206
|
+
{/if}
|
|
207
|
+
</DropdownMenu.Item>
|
|
208
|
+
{/each}
|
|
209
|
+
</DropdownMenu.Content>
|
|
210
|
+
</DropdownMenu.Root>
|
|
211
|
+
{/if}
|
|
155
212
|
</div>
|
|
156
213
|
{#if trailing}
|
|
157
214
|
{@render trailing()}
|
|
@@ -6,6 +6,10 @@ export type ComposerMessages = {
|
|
|
6
6
|
attach: string;
|
|
7
7
|
characterLimit: string;
|
|
8
8
|
};
|
|
9
|
+
export type ComposerModelOption = {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
};
|
|
9
13
|
export type ComposerProps = HTMLAttributes<HTMLDivElement> & {
|
|
10
14
|
ref?: HTMLDivElement | null;
|
|
11
15
|
class?: string;
|
|
@@ -15,6 +19,10 @@ export type ComposerProps = HTMLAttributes<HTMLDivElement> & {
|
|
|
15
19
|
disabled?: boolean;
|
|
16
20
|
maxLength?: number;
|
|
17
21
|
allowEmpty?: boolean;
|
|
22
|
+
assistantLabel?: string;
|
|
23
|
+
models?: ComposerModelOption[];
|
|
24
|
+
selectedModelId?: string | null;
|
|
25
|
+
onSelectModel?: (modelId: string) => void;
|
|
18
26
|
messages?: Partial<ComposerMessages>;
|
|
19
27
|
onSend?: (text: string) => void;
|
|
20
28
|
onStop?: () => void;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Figma: checkpoint row under a user turn (version label, restore, redo).
|
|
3
|
+
-->
|
|
4
|
+
<script lang="ts" module>
|
|
5
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
|
|
7
|
+
export type MessageCheckpointRowMessages = {
|
|
8
|
+
version: string;
|
|
9
|
+
restore: string;
|
|
10
|
+
redo: string;
|
|
11
|
+
restored: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type MessageCheckpointRowProps = HTMLAttributes<HTMLDivElement> & {
|
|
15
|
+
ref?: HTMLDivElement | null;
|
|
16
|
+
class?: string;
|
|
17
|
+
versionLabel?: string | null;
|
|
18
|
+
showRestore?: boolean;
|
|
19
|
+
showRedo?: boolean;
|
|
20
|
+
restoredToVersion?: string | null;
|
|
21
|
+
messages?: Partial<MessageCheckpointRowMessages>;
|
|
22
|
+
onRestore?: () => void;
|
|
23
|
+
onRedo?: () => void;
|
|
24
|
+
};
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script lang="ts">
|
|
28
|
+
import IconHistory from '@tabler/icons-svelte/icons/history';
|
|
29
|
+
import IconArrowBackUp from '@tabler/icons-svelte/icons/arrow-back-up';
|
|
30
|
+
import { cn } from '../../utils.js';
|
|
31
|
+
import { Button } from '../ui/button/index.js';
|
|
32
|
+
|
|
33
|
+
const defaultMessages: MessageCheckpointRowMessages = {
|
|
34
|
+
version: 'Version {n}',
|
|
35
|
+
restore: 'Restore',
|
|
36
|
+
redo: 'Redo',
|
|
37
|
+
restored: 'Restored to version {n}'
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let {
|
|
41
|
+
ref = $bindable(null),
|
|
42
|
+
class: className,
|
|
43
|
+
versionLabel = null,
|
|
44
|
+
showRestore = false,
|
|
45
|
+
showRedo = false,
|
|
46
|
+
restoredToVersion = null,
|
|
47
|
+
messages: messagesProp,
|
|
48
|
+
onRestore,
|
|
49
|
+
onRedo,
|
|
50
|
+
...restProps
|
|
51
|
+
}: MessageCheckpointRowProps = $props();
|
|
52
|
+
|
|
53
|
+
const messages = $derived({ ...defaultMessages, ...messagesProp });
|
|
54
|
+
const restoredText = $derived(
|
|
55
|
+
restoredToVersion
|
|
56
|
+
? messages.restored.replace('{n}', restoredToVersion)
|
|
57
|
+
: ''
|
|
58
|
+
);
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<div
|
|
62
|
+
bind:this={ref}
|
|
63
|
+
class={cn('flex w-full min-w-0 items-center justify-between gap-2', className)}
|
|
64
|
+
{...restProps}
|
|
65
|
+
>
|
|
66
|
+
<div class="flex min-w-0 items-center gap-2">
|
|
67
|
+
{#if restoredText}
|
|
68
|
+
<span class="text-caption text-muted-foreground truncate">{restoredText}</span>
|
|
69
|
+
{:else if versionLabel}
|
|
70
|
+
<span class="text-caption text-muted-foreground truncate">{versionLabel}</span>
|
|
71
|
+
{/if}
|
|
72
|
+
</div>
|
|
73
|
+
<div class="flex shrink-0 items-center gap-1">
|
|
74
|
+
{#if showRestore && onRestore}
|
|
75
|
+
<Button variant="ghost" size="sm" onclick={onRestore}>
|
|
76
|
+
<IconArrowBackUp class="size-4 stroke-2" aria-hidden="true" />
|
|
77
|
+
{messages.restore}
|
|
78
|
+
</Button>
|
|
79
|
+
{/if}
|
|
80
|
+
{#if showRedo && onRedo}
|
|
81
|
+
<Button variant="ghost" size="sm" onclick={onRedo}>
|
|
82
|
+
<IconHistory class="size-4 stroke-2" aria-hidden="true" />
|
|
83
|
+
{messages.redo}
|
|
84
|
+
</Button>
|
|
85
|
+
{/if}
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
export type MessageCheckpointRowMessages = {
|
|
3
|
+
version: string;
|
|
4
|
+
restore: string;
|
|
5
|
+
redo: string;
|
|
6
|
+
restored: string;
|
|
7
|
+
};
|
|
8
|
+
export type MessageCheckpointRowProps = HTMLAttributes<HTMLDivElement> & {
|
|
9
|
+
ref?: HTMLDivElement | null;
|
|
10
|
+
class?: string;
|
|
11
|
+
versionLabel?: string | null;
|
|
12
|
+
showRestore?: boolean;
|
|
13
|
+
showRedo?: boolean;
|
|
14
|
+
restoredToVersion?: string | null;
|
|
15
|
+
messages?: Partial<MessageCheckpointRowMessages>;
|
|
16
|
+
onRestore?: () => void;
|
|
17
|
+
onRedo?: () => void;
|
|
18
|
+
};
|
|
19
|
+
declare const MessageCheckpointRow: import("svelte").Component<MessageCheckpointRowProps, {}, "ref">;
|
|
20
|
+
type MessageCheckpointRow = ReturnType<typeof MessageCheckpointRow>;
|
|
21
|
+
export default MessageCheckpointRow;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Figma: Message actions row (copy, regenerate, thumbs) on assistant turns.
|
|
3
|
+
-->
|
|
4
|
+
<script lang="ts" module>
|
|
5
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
import type { VersionRatingKind } from './messageRatingTypes.js';
|
|
7
|
+
import type { VersionThumb } from './messageRatingActionsLogic.js';
|
|
8
|
+
|
|
9
|
+
export type MessageRatingActionsMessages = {
|
|
10
|
+
copy: string;
|
|
11
|
+
copied: string;
|
|
12
|
+
regenerate: string;
|
|
13
|
+
rateGroup: string;
|
|
14
|
+
rateUp: string;
|
|
15
|
+
rateDown: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type MessageRatingActionsProps = HTMLAttributes<HTMLDivElement> & {
|
|
19
|
+
ref?: HTMLDivElement | null;
|
|
20
|
+
class?: string;
|
|
21
|
+
copyText?: string;
|
|
22
|
+
canRegenerate?: boolean;
|
|
23
|
+
ratedMessageId?: string | null;
|
|
24
|
+
rating?: VersionRatingKind;
|
|
25
|
+
messages?: Partial<MessageRatingActionsMessages>;
|
|
26
|
+
onCopy?: () => void | Promise<void>;
|
|
27
|
+
onRegenerate?: () => void;
|
|
28
|
+
onRate?: (messageId: string, pressed: VersionThumb) => void;
|
|
29
|
+
};
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<script lang="ts">
|
|
33
|
+
import IconCopy from '@tabler/icons-svelte/icons/copy';
|
|
34
|
+
import IconRefresh from '@tabler/icons-svelte/icons/refresh';
|
|
35
|
+
import IconThumbDown from '@tabler/icons-svelte/icons/thumb-down';
|
|
36
|
+
import IconThumbUp from '@tabler/icons-svelte/icons/thumb-up';
|
|
37
|
+
import IconCheck from '@tabler/icons-svelte/icons/check';
|
|
38
|
+
import { cn } from '../../utils.js';
|
|
39
|
+
import { IconButton } from '../ui/icon-button/index.js';
|
|
40
|
+
import {
|
|
41
|
+
shouldRenderMessageRatingBar,
|
|
42
|
+
shouldShowCopyAction,
|
|
43
|
+
shouldShowRatingActions,
|
|
44
|
+
shouldShowRegenerateAction,
|
|
45
|
+
thumbIsPressed
|
|
46
|
+
} from './messageRatingActionsLogic.js';
|
|
47
|
+
|
|
48
|
+
const defaultMessages: MessageRatingActionsMessages = {
|
|
49
|
+
copy: 'Copy message',
|
|
50
|
+
copied: 'Copied',
|
|
51
|
+
regenerate: 'Regenerate response',
|
|
52
|
+
rateGroup: 'Rate this version',
|
|
53
|
+
rateUp: 'Good result',
|
|
54
|
+
rateDown: 'Poor result'
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
let {
|
|
58
|
+
ref = $bindable(null),
|
|
59
|
+
class: className,
|
|
60
|
+
copyText = '',
|
|
61
|
+
canRegenerate = false,
|
|
62
|
+
ratedMessageId = null,
|
|
63
|
+
rating = 'none',
|
|
64
|
+
messages: messagesProp,
|
|
65
|
+
onCopy,
|
|
66
|
+
onRegenerate,
|
|
67
|
+
onRate,
|
|
68
|
+
...restProps
|
|
69
|
+
}: MessageRatingActionsProps = $props();
|
|
70
|
+
|
|
71
|
+
const messages = $derived({ ...defaultMessages, ...messagesProp });
|
|
72
|
+
const visible = $derived(
|
|
73
|
+
shouldRenderMessageRatingBar({ copyText, canRegenerate, ratedMessageId })
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
let copied = $state(false);
|
|
77
|
+
let copiedTimer: ReturnType<typeof setTimeout> | null = null;
|
|
78
|
+
|
|
79
|
+
async function handleCopy(event: MouseEvent) {
|
|
80
|
+
const button = event.currentTarget instanceof HTMLElement ? event.currentTarget : null;
|
|
81
|
+
try {
|
|
82
|
+
await onCopy?.();
|
|
83
|
+
copied = true;
|
|
84
|
+
if (copiedTimer) clearTimeout(copiedTimer);
|
|
85
|
+
copiedTimer = setTimeout(() => {
|
|
86
|
+
copied = false;
|
|
87
|
+
copiedTimer = null;
|
|
88
|
+
}, 2000);
|
|
89
|
+
button?.focus({ preventScroll: true });
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error('[MessageRatingActions] Copy failed:', error);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
$effect(() => {
|
|
96
|
+
return () => {
|
|
97
|
+
if (copiedTimer) clearTimeout(copiedTimer);
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
</script>
|
|
101
|
+
|
|
102
|
+
{#if visible}
|
|
103
|
+
<div
|
|
104
|
+
bind:this={ref}
|
|
105
|
+
class={cn('flex min-h-8 flex-wrap items-center gap-1', className)}
|
|
106
|
+
role="group"
|
|
107
|
+
aria-label={messages.rateGroup}
|
|
108
|
+
{...restProps}
|
|
109
|
+
>
|
|
110
|
+
{#if shouldShowCopyAction(copyText) && onCopy}
|
|
111
|
+
<IconButton variant="ghost" label={copied ? messages.copied : messages.copy} onclick={handleCopy}>
|
|
112
|
+
{#if copied}
|
|
113
|
+
<IconCheck class="size-4 stroke-2" aria-hidden="true" />
|
|
114
|
+
{:else}
|
|
115
|
+
<IconCopy class="size-4 stroke-2" aria-hidden="true" />
|
|
116
|
+
{/if}
|
|
117
|
+
</IconButton>
|
|
118
|
+
{/if}
|
|
119
|
+
|
|
120
|
+
{#if shouldShowRegenerateAction(canRegenerate) && onRegenerate}
|
|
121
|
+
<IconButton variant="ghost" label={messages.regenerate} onclick={onRegenerate}>
|
|
122
|
+
<IconRefresh class="size-4 stroke-2" aria-hidden="true" />
|
|
123
|
+
</IconButton>
|
|
124
|
+
{/if}
|
|
125
|
+
|
|
126
|
+
{#if shouldShowRatingActions(ratedMessageId) && onRate && ratedMessageId}
|
|
127
|
+
<span class="inline-flex items-center gap-0.5" role="group" aria-label={messages.rateGroup}>
|
|
128
|
+
<IconButton
|
|
129
|
+
variant="ghost"
|
|
130
|
+
label={messages.rateUp}
|
|
131
|
+
aria-pressed={thumbIsPressed(rating, 'up')}
|
|
132
|
+
onclick={() => onRate(ratedMessageId, 'up')}
|
|
133
|
+
>
|
|
134
|
+
<IconThumbUp
|
|
135
|
+
class="size-4 stroke-2"
|
|
136
|
+
fill={thumbIsPressed(rating, 'up') ? 'currentColor' : 'none'}
|
|
137
|
+
aria-hidden="true"
|
|
138
|
+
/>
|
|
139
|
+
</IconButton>
|
|
140
|
+
<IconButton
|
|
141
|
+
variant="ghost"
|
|
142
|
+
label={messages.rateDown}
|
|
143
|
+
aria-pressed={thumbIsPressed(rating, 'down')}
|
|
144
|
+
onclick={() => onRate(ratedMessageId, 'down')}
|
|
145
|
+
>
|
|
146
|
+
<IconThumbDown
|
|
147
|
+
class="size-4 stroke-2"
|
|
148
|
+
fill={thumbIsPressed(rating, 'down') ? 'currentColor' : 'none'}
|
|
149
|
+
aria-hidden="true"
|
|
150
|
+
/>
|
|
151
|
+
</IconButton>
|
|
152
|
+
</span>
|
|
153
|
+
{/if}
|
|
154
|
+
|
|
155
|
+
<span class="sr-only" aria-live="polite">{copied ? messages.copied : ''}</span>
|
|
156
|
+
</div>
|
|
157
|
+
{/if}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
import type { VersionRatingKind } from './messageRatingTypes.js';
|
|
3
|
+
import type { VersionThumb } from './messageRatingActionsLogic.js';
|
|
4
|
+
export type MessageRatingActionsMessages = {
|
|
5
|
+
copy: string;
|
|
6
|
+
copied: string;
|
|
7
|
+
regenerate: string;
|
|
8
|
+
rateGroup: string;
|
|
9
|
+
rateUp: string;
|
|
10
|
+
rateDown: string;
|
|
11
|
+
};
|
|
12
|
+
export type MessageRatingActionsProps = HTMLAttributes<HTMLDivElement> & {
|
|
13
|
+
ref?: HTMLDivElement | null;
|
|
14
|
+
class?: string;
|
|
15
|
+
copyText?: string;
|
|
16
|
+
canRegenerate?: boolean;
|
|
17
|
+
ratedMessageId?: string | null;
|
|
18
|
+
rating?: VersionRatingKind;
|
|
19
|
+
messages?: Partial<MessageRatingActionsMessages>;
|
|
20
|
+
onCopy?: () => void | Promise<void>;
|
|
21
|
+
onRegenerate?: () => void;
|
|
22
|
+
onRate?: (messageId: string, pressed: VersionThumb) => void;
|
|
23
|
+
};
|
|
24
|
+
declare const MessageRatingActions: import("svelte").Component<MessageRatingActionsProps, {}, "ref">;
|
|
25
|
+
type MessageRatingActions = ReturnType<typeof MessageRatingActions>;
|
|
26
|
+
export default MessageRatingActions;
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
title: string;
|
|
23
23
|
description?: string;
|
|
24
24
|
showDescription?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* How many lines the description may take. 1 (default) cuts it with an ellipsis, as the chat's one-line cards do;
|
|
27
|
+
* 2 lets it wrap, as the cards of the Brand kit prompt do in Figma (the card then grows to 76px).
|
|
28
|
+
*/
|
|
29
|
+
descriptionLines?: 1 | 2;
|
|
25
30
|
disabled?: boolean;
|
|
26
31
|
messages?: Partial<SuggestionCardMessages>;
|
|
27
32
|
icon?: Snippet;
|
|
@@ -34,6 +39,7 @@
|
|
|
34
39
|
title,
|
|
35
40
|
description = '',
|
|
36
41
|
showDescription = false,
|
|
42
|
+
descriptionLines = 1,
|
|
37
43
|
disabled = false,
|
|
38
44
|
messages: messagesProp,
|
|
39
45
|
icon,
|
|
@@ -69,7 +75,13 @@
|
|
|
69
75
|
<span class="min-w-0 flex-1">
|
|
70
76
|
<span class="text-body-medium text-foreground block truncate">{title}</span>
|
|
71
77
|
{#if showDescription && description}
|
|
72
|
-
<span
|
|
78
|
+
<span
|
|
79
|
+
class={cn(
|
|
80
|
+
'text-caption text-muted-foreground block',
|
|
81
|
+
// Figma: a card with a two-line description is 76 tall (12 + 20 + 32 + 12), with no gap under the title.
|
|
82
|
+
descriptionLines === 2 ? 'line-clamp-2' : 'mt-0.5 truncate'
|
|
83
|
+
)}>{description}</span
|
|
84
|
+
>
|
|
73
85
|
{/if}
|
|
74
86
|
</span>
|
|
75
87
|
<IconChevronRight
|
|
@@ -10,6 +10,11 @@ type Props = HTMLButtonAttributes & {
|
|
|
10
10
|
title: string;
|
|
11
11
|
description?: string;
|
|
12
12
|
showDescription?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* How many lines the description may take. 1 (default) cuts it with an ellipsis, as the chat's one-line cards do;
|
|
15
|
+
* 2 lets it wrap, as the cards of the Brand kit prompt do in Figma (the card then grows to 76px).
|
|
16
|
+
*/
|
|
17
|
+
descriptionLines?: 1 | 2;
|
|
13
18
|
disabled?: boolean;
|
|
14
19
|
messages?: Partial<SuggestionCardMessages>;
|
|
15
20
|
icon?: Snippet;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the chat header shows the debug console control instead of the pin control.
|
|
3
|
+
*/
|
|
4
|
+
export declare function shouldShowConsoleButton(showConsole: boolean, onToggleConsole?: (() => void) | null): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Pin stays available for hosts that still use it; hidden when the console control is shown.
|
|
7
|
+
*/
|
|
8
|
+
export declare function shouldShowPinButton(showConsole: boolean, onToggleConsole?: (() => void) | null, onPin?: (() => void) | null): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the chat header shows the debug console control instead of the pin control.
|
|
3
|
+
*/
|
|
4
|
+
export function shouldShowConsoleButton(showConsole, onToggleConsole) {
|
|
5
|
+
return showConsole && typeof onToggleConsole === 'function';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Pin stays available for hosts that still use it; hidden when the console control is shown.
|
|
9
|
+
*/
|
|
10
|
+
export function shouldShowPinButton(showConsole, onToggleConsole, onPin) {
|
|
11
|
+
if (shouldShowConsoleButton(showConsole, onToggleConsole))
|
|
12
|
+
return false;
|
|
13
|
+
return typeof onPin === 'function';
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ComposerModelOption = {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The Assistant menu is shown only when the host offers at least one model.
|
|
7
|
+
*/
|
|
8
|
+
export declare function shouldShowComposerModelMenu(models: ComposerModelOption[] | null | undefined): boolean;
|
|
9
|
+
export declare function selectedModelLabel(models: ComposerModelOption[], selectedModelId: string | null | undefined, fallbackLabel: string): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Assistant menu is shown only when the host offers at least one model.
|
|
3
|
+
*/
|
|
4
|
+
export function shouldShowComposerModelMenu(models) {
|
|
5
|
+
return Array.isArray(models) && models.length > 0;
|
|
6
|
+
}
|
|
7
|
+
export function selectedModelLabel(models, selectedModelId, fallbackLabel) {
|
|
8
|
+
if (!selectedModelId)
|
|
9
|
+
return fallbackLabel;
|
|
10
|
+
const match = models.find((model) => model.id === selectedModelId);
|
|
11
|
+
return match?.label?.trim() || fallbackLabel;
|
|
12
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { Chip } from '../ui/chip';
|
|
2
|
+
export { IconButton } from '../ui/icon-button';
|
|
1
3
|
export { default as Composer, type ComposerMessages, type ComposerProps } from './Composer.svelte';
|
|
2
4
|
export { default as Message, type MessageMessages, type MessageProps, type MessageRole } from './Message.svelte';
|
|
3
5
|
export { default as ActivityRow, type ActivityRowProps, type ActivityRowStatus } from './ActivityRow.svelte';
|
|
@@ -14,3 +16,11 @@ export type { QuestionCardMessages, QuestionItem, QuestionOption } from './Quest
|
|
|
14
16
|
export { canSubmitQuestion, formatQuestionStep, isFirstQuestion, isLastQuestion, moveFocusedIndex, optionItemRole, primaryQuestionLabel, selectionRole, toggleOption } from './questionCardLogic.js';
|
|
15
17
|
export { default as SuggestionCard } from './SuggestionCard.svelte';
|
|
16
18
|
export type { SuggestionCardMessages } from './SuggestionCard.svelte';
|
|
19
|
+
export { default as MessageRatingActions } from './MessageRatingActions.svelte';
|
|
20
|
+
export type { MessageRatingActionsMessages, MessageRatingActionsProps } from './MessageRatingActions.svelte';
|
|
21
|
+
export { default as MessageCheckpointRow } from './MessageCheckpointRow.svelte';
|
|
22
|
+
export type { MessageCheckpointRowMessages, MessageCheckpointRowProps } from './MessageCheckpointRow.svelte';
|
|
23
|
+
export { shouldShowConsoleButton, shouldShowPinButton } from './chatHeaderLogic.js';
|
|
24
|
+
export { shouldRenderMessageRatingBar, shouldShowCopyAction, shouldShowRatingActions, shouldShowRegenerateAction, thumbIsPressed, type VersionThumb } from './messageRatingActionsLogic.js';
|
|
25
|
+
export type { VersionRatingKind } from './messageRatingTypes.js';
|
|
26
|
+
export { selectedModelLabel, shouldShowComposerModelMenu, type ComposerModelOption } from './composerModelMenuLogic.js';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// Chat components (composer, messages, plan and question cards) built from the Figma design system.
|
|
2
2
|
// Each component is exported here by the agent that owns src/lib/components/chat.
|
|
3
3
|
// [C1 exports]
|
|
4
|
+
export { Chip } from '../ui/chip';
|
|
5
|
+
// The chat's composer draws its attach "+" with the same icon button (the chat imports only this barrel).
|
|
6
|
+
export { IconButton } from '../ui/icon-button';
|
|
4
7
|
export { default as Composer } from './Composer.svelte';
|
|
5
8
|
export { default as Message } from './Message.svelte';
|
|
6
9
|
export { default as ActivityRow } from './ActivityRow.svelte';
|
|
@@ -14,3 +17,8 @@ export { default as PlanCard } from './PlanCard.svelte';
|
|
|
14
17
|
export { default as QuestionCard } from './QuestionCard.svelte';
|
|
15
18
|
export { canSubmitQuestion, formatQuestionStep, isFirstQuestion, isLastQuestion, moveFocusedIndex, optionItemRole, primaryQuestionLabel, selectionRole, toggleOption } from './questionCardLogic.js';
|
|
16
19
|
export { default as SuggestionCard } from './SuggestionCard.svelte';
|
|
20
|
+
export { default as MessageRatingActions } from './MessageRatingActions.svelte';
|
|
21
|
+
export { default as MessageCheckpointRow } from './MessageCheckpointRow.svelte';
|
|
22
|
+
export { shouldShowConsoleButton, shouldShowPinButton } from './chatHeaderLogic.js';
|
|
23
|
+
export { shouldRenderMessageRatingBar, shouldShowCopyAction, shouldShowRatingActions, shouldShowRegenerateAction, thumbIsPressed } from './messageRatingActionsLogic.js';
|
|
24
|
+
export { selectedModelLabel, shouldShowComposerModelMenu } from './composerModelMenuLogic.js';
|