@widgetic/chat 0.1.44 → 0.1.47
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 +162 -20
- package/dist/components/ActionBar.svelte +14 -1
- package/dist/components/ActionBar.svelte.d.ts +6 -0
- package/dist/components/AttachmentDisplay.svelte +22 -130
- package/dist/components/AttachmentPreviewDialog.svelte +428 -0
- package/dist/components/AttachmentPreviewDialog.svelte.d.ts +14 -0
- package/dist/components/Chat.svelte +556 -121
- package/dist/components/Chat.svelte.d.ts +15 -2
- package/dist/components/ChatComposer.svelte +63 -69
- package/dist/components/ChatComposer.svelte.d.ts +8 -3
- package/dist/components/ChatDropOverlay.svelte +58 -0
- package/dist/components/ChatDropOverlay.svelte.d.ts +8 -0
- package/dist/components/ChatMessages.svelte +322 -98
- package/dist/components/ChatMessages.svelte.d.ts +11 -2
- package/dist/components/ComposerAttachmentsTray.svelte +144 -56
- package/dist/components/ComposerAttachmentsTray.svelte.d.ts +11 -1
- package/dist/components/FileGlyphIcon.svelte +34 -0
- package/dist/components/FileGlyphIcon.svelte.d.ts +8 -0
- package/dist/components/PanelSuggestionButtons.svelte +67 -19
- package/dist/components/PanelSuggestionButtons.svelte.d.ts +3 -1
- package/dist/components/RestoreCheckpointDialog.svelte +66 -0
- package/dist/components/RestoreCheckpointDialog.svelte.d.ts +11 -0
- package/dist/components/SentAttachments.svelte +118 -0
- package/dist/components/SentAttachments.svelte.d.ts +12 -0
- package/dist/components/agent/AgentTurn.svelte +17 -2
- package/dist/components/agent/CodeCard.svelte +9 -3
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/messages.d.ts +52 -4
- package/dist/i18n/messages.js +58 -6
- package/dist/i18n/suggestions.d.ts +17 -2
- package/dist/i18n/suggestions.js +11 -12
- package/dist/services/index.d.ts +4 -2
- package/dist/services/index.js +2 -1
- package/dist/services/limitRefusal.d.ts +42 -0
- package/dist/services/limitRefusal.js +60 -0
- package/dist/services/sketchAssistantClient.d.ts +11 -3
- package/dist/services/sketchAssistantClient.js +37 -10
- package/dist/services/sketchAssistantErrors.d.ts +16 -1
- package/dist/services/sketchAssistantErrors.js +25 -4
- package/dist/services/sketchAssistantOrchestrator.d.ts +7 -1
- package/dist/services/sketchAssistantOrchestrator.js +2 -2
- package/dist/types/attachment.d.ts +11 -0
- package/dist/utils/agentTurn.d.ts +32 -1
- package/dist/utils/agentTurn.js +46 -3
- package/dist/utils/attachmentDuplicates.d.ts +48 -0
- package/dist/utils/attachmentDuplicates.js +70 -0
- package/dist/utils/attachmentPolicy.d.ts +88 -0
- package/dist/utils/attachmentPolicy.js +135 -0
- package/dist/utils/attachmentPreview.d.ts +146 -0
- package/dist/utils/attachmentPreview.js +224 -0
- package/dist/utils/attachmentTray.d.ts +35 -0
- package/dist/utils/attachmentTray.js +27 -0
- package/dist/utils/chatFileDrag.d.ts +39 -0
- package/dist/utils/chatFileDrag.js +29 -0
- package/dist/utils/composerPreview.d.ts +33 -0
- package/dist/utils/composerPreview.js +31 -0
- package/dist/utils/generationArchiveStore.d.ts +5 -1
- package/dist/utils/generationArchiveStore.js +9 -4
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/limitFailureLine.d.ts +20 -0
- package/dist/utils/limitFailureLine.js +40 -0
- package/dist/utils/panelListPadding.d.ts +20 -0
- package/dist/utils/panelListPadding.js +31 -0
- package/dist/utils/pasteInsertion.d.ts +43 -0
- package/dist/utils/pasteInsertion.js +94 -0
- package/dist/utils/pastedContent.d.ts +13 -0
- package/dist/utils/pastedContent.js +18 -1
- package/dist/utils/referenceItems.js +11 -3
- package/dist/utils/sentAttachments.d.ts +43 -0
- package/dist/utils/sentAttachments.js +38 -0
- package/dist/utils/sentReferenceBadges.d.ts +11 -1
- package/dist/utils/sentReferenceBadges.js +47 -2
- package/package.json +3 -3
|
@@ -75,6 +75,14 @@ interface Props {
|
|
|
75
75
|
* began, so a host that forgets to clear it never shows a run the changes of the run before.
|
|
76
76
|
*/
|
|
77
77
|
generationChanges?: CodeChanges | null;
|
|
78
|
+
/**
|
|
79
|
+
* The agent's own words about what the last run changed, from the host (the gateway sends them with the completed operation,
|
|
80
|
+
* as `metadata.summary`). The conclusion under the run says them instead of "Done. Your changes are ready.". Give it when the
|
|
81
|
+
* operation completes (before or after `isGenerating` turns false: a value that comes after goes into the work of the run that
|
|
82
|
+
* just ended), and clear it when the next run starts; like the changes, the chat ignores the very value it held when a run began.
|
|
83
|
+
* Without it the conclusion keeps its catalog sentence.
|
|
84
|
+
*/
|
|
85
|
+
generationSummary?: string | null;
|
|
78
86
|
onSuggestionSelected?: (suggestion: string) => void;
|
|
79
87
|
/**
|
|
80
88
|
* What is in the message box now. The follow-up card under the last reply (ideas for what to improve next, as small pills)
|
|
@@ -85,9 +93,10 @@ interface Props {
|
|
|
85
93
|
/**
|
|
86
94
|
* Draws a restore icon on the messages the person sent, shown when the pointer is over the message. Pressing it asks the host to
|
|
87
95
|
* put the widget back to how it was BEFORE that message: called with the id of the saved reply that stands for that earlier state
|
|
88
|
-
* and its place in `messages`. Without it no restore icon is drawn.
|
|
96
|
+
* and its place in `messages`. Without it no restore icon is drawn. The third word says whether it is a restore (which throws away
|
|
97
|
+
* what came after the checkpoint, so the chat asks to confirm it) or a redo (which brings that work back).
|
|
89
98
|
*/
|
|
90
|
-
onRestoreCheckpoint?: (messageId: string, messageIndex: number) => void;
|
|
99
|
+
onRestoreCheckpoint?: (messageId: string, messageIndex: number, kind?: 'restore' | 'redo') => void;
|
|
91
100
|
/**
|
|
92
101
|
* Gives the last message a thumbs up and a thumbs down (next to copy and regenerate). Called with the id of the assistant message
|
|
93
102
|
* that announced the version and the thumb that was pressed; the host keeps the rating. Without it no thumbs are drawn.
|
|
@@ -4,93 +4,181 @@
|
|
|
4
4
|
import IconX from '@tabler/icons-svelte/icons/x';
|
|
5
5
|
import { useChatLanguage } from '../i18n/language.js';
|
|
6
6
|
import { attachmentChipProgress } from '../utils/attachmentProgress.js';
|
|
7
|
+
import { arrangeTrayAttachments, type TrayEntry } from '../utils/attachmentTray.js';
|
|
7
8
|
import { buildImageThumbnailUrl } from '../utils/imageTransform.js';
|
|
9
|
+
import { fileGlyphOf, previewKindOf, type FileGlyph } from '../utils/attachmentPreview.js';
|
|
8
10
|
import { isHighlightedAttachment } from '../utils/referenceItems.js';
|
|
11
|
+
import FileGlyphIcon from './FileGlyphIcon.svelte';
|
|
9
12
|
|
|
10
13
|
interface Props {
|
|
11
14
|
attachments: AttachmentInput[];
|
|
12
15
|
previewUrl: (attachment: AttachmentInput) => string;
|
|
13
16
|
isImage: (attachment: AttachmentInput) => boolean;
|
|
17
|
+
/** Removes a file. The index is the file's place in `attachments` (the list as it was given, not as it is drawn). */
|
|
14
18
|
onRemove: (index: number) => void;
|
|
15
|
-
|
|
19
|
+
/**
|
|
20
|
+
* A picture, or a chip of a file that has a preview, was pressed: the page opens the file in its preview card. The page knows the
|
|
21
|
+
* files of the box, so it can give the card the arrows to the next one.
|
|
22
|
+
*/
|
|
23
|
+
onOpenPreview?: (attachment: AttachmentInput) => void;
|
|
16
24
|
/**
|
|
17
25
|
* The label of the file a badge in the message or a row of the `#` menu is on: the tile of that file is ringed, so the person
|
|
18
26
|
* sees which attachment the word stands for. Null (or a label no file has) rings nothing.
|
|
19
27
|
*/
|
|
20
28
|
highlightedLabel?: string | null;
|
|
29
|
+
/**
|
|
30
|
+
* The files the person tried to attach again (they were in the tray already): their tiles are ringed for a moment, so the
|
|
31
|
+
* person sees that they are there and that they were not added a second time. None rings nothing.
|
|
32
|
+
*/
|
|
33
|
+
flashedAttachmentIds?: readonly string[];
|
|
21
34
|
}
|
|
22
35
|
|
|
23
|
-
let {
|
|
36
|
+
let {
|
|
37
|
+
attachments,
|
|
38
|
+
previewUrl,
|
|
39
|
+
isImage,
|
|
40
|
+
onRemove,
|
|
41
|
+
onOpenPreview,
|
|
42
|
+
highlightedLabel = null,
|
|
43
|
+
flashedAttachmentIds = [],
|
|
44
|
+
}: Props = $props();
|
|
24
45
|
const { t } = useChatLanguage();
|
|
25
46
|
|
|
26
47
|
const IMAGE_PREVIEW_CSS_PX = 56;
|
|
27
48
|
|
|
49
|
+
// The files that are not pictures come first, each as a chip, and the pictures follow them below, whatever order they were added in.
|
|
50
|
+
// A text that was pasted has no tile here: it is a badge in the words of the message.
|
|
51
|
+
const arrangement = $derived(arrangeTrayAttachments(attachments, isImage));
|
|
52
|
+
|
|
53
|
+
/** What tells one tile from the others while the tray draws them (the id; two screenshots are both "image.png"). */
|
|
54
|
+
function tileKey(entry: TrayEntry): string | number {
|
|
55
|
+
const { attachment, index } = entry;
|
|
56
|
+
return attachment.id || attachment.preview || attachment.uploadedUrl || attachment.file?.name || index;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Whether the file of a chip can be opened in the preview card: its kind says so (the address is not needed: a text opens from the file). */
|
|
60
|
+
function isPreviewable(attachment: AttachmentInput): boolean {
|
|
61
|
+
return (
|
|
62
|
+
previewKindOf({ url: previewUrl(attachment), name: attachment.file?.name, type: attachment.file?.type }) !== null
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The glyph in front of the name of a chip: what kind of file it is. */
|
|
67
|
+
function glyphOf(attachment: AttachmentInput): FileGlyph {
|
|
68
|
+
return fileGlyphOf({ url: previewUrl(attachment), name: attachment.file?.name, type: attachment.file?.type });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Whether a tile is ringed: the file a badge is on, or a file that was tried a second time. */
|
|
72
|
+
function isTileRinged(attachment: AttachmentInput): boolean {
|
|
73
|
+
return (
|
|
74
|
+
isHighlightedAttachment(attachment, highlightedLabel) ||
|
|
75
|
+
(!!attachment.id && flashedAttachmentIds.includes(attachment.id))
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
28
79
|
/**
|
|
29
80
|
* What a file chip is given while its file goes up: the share sent, which the chip draws as its own background, and how a
|
|
30
81
|
* screen reader says it. Nothing while the file is not going up. The props go in as a spread because a design system older
|
|
31
|
-
* than the one that brought `progress` does not know them and simply draws the chip without a fill.
|
|
82
|
+
* than the one that brought `progress` does not know them and simply draws the chip without a fill. (A picture shows no
|
|
83
|
+
* progress at all: its thumbnail is there, and that is all a person needs to see of it.)
|
|
32
84
|
*/
|
|
33
85
|
function chipProgressProps(attachment: AttachmentInput): Record<string, unknown> {
|
|
34
86
|
const shareSent = attachmentChipProgress(attachment.uploadProgress);
|
|
35
87
|
if (shareSent === undefined) return {};
|
|
36
88
|
return {
|
|
37
89
|
progress: shareSent,
|
|
38
|
-
progressLabel: $t('chat.attachment.uploadProgress', { percent: Math.round(shareSent) })
|
|
90
|
+
progressLabel: $t('chat.attachment.uploadProgress', { percent: Math.round(shareSent) }),
|
|
39
91
|
};
|
|
40
92
|
}
|
|
41
93
|
</script>
|
|
42
94
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
95
|
+
<!--
|
|
96
|
+
The files of the message, inside the message box over the text: the chips first, then the pictures as small thumbnails below them.
|
|
97
|
+
The box grows with them (its text scrolls when it has more than fits), so this has no height of its own.
|
|
98
|
+
-->
|
|
99
|
+
<div class="composer-attachments-tray flex w-full min-w-0 flex-col gap-2" data-testid="composer-attachments-tray">
|
|
100
|
+
{#if arrangement.chips.length > 0}
|
|
101
|
+
<div class="composer-attachment-chips flex min-w-0 flex-wrap gap-1.5 p-0.5" data-testid="composer-attachment-chips">
|
|
102
|
+
{#each arrangement.chips as entry (tileKey(entry))}
|
|
103
|
+
{@const ringed = isTileRinged(entry.attachment)}
|
|
104
|
+
{@const canPreview = isPreviewable(entry.attachment)}
|
|
105
|
+
<!-- A file that is not a picture is ringed through the box around its chip (the chip draws no ring of its own). The chip is a
|
|
106
|
+
label with an x, so a file that has a preview gets a button laid over the chip except over the x: pressing the name opens
|
|
107
|
+
the preview, pressing the x removes the file, and neither button is inside the other. -->
|
|
108
|
+
<span
|
|
109
|
+
class="group/chip relative inline-flex max-w-full rounded-lg {ringed ? 'ring-ring ring-2' : ''} has-[[data-chip-open]:focus-visible]:ring-ring has-[[data-chip-open]:focus-visible]:ring-2"
|
|
110
|
+
data-label={entry.attachment.referenceLabel}
|
|
111
|
+
data-highlighted={ringed ? 'true' : undefined}
|
|
112
|
+
>
|
|
113
|
+
<Chip
|
|
114
|
+
class={canPreview ? 'group-hover/chip:bg-accent' : ''}
|
|
115
|
+
label={entry.attachment.label || entry.attachment.file?.name || $t('chat.attachment.namelessAlt')}
|
|
116
|
+
showRemove={true}
|
|
117
|
+
removeLabel={$t('chat.attachment.remove')}
|
|
118
|
+
onRemove={() => onRemove(entry.index)}
|
|
119
|
+
{...chipProgressProps(entry.attachment)}
|
|
120
|
+
>
|
|
121
|
+
<!-- The glyph of the chip: what kind of file it is -->
|
|
122
|
+
{#snippet leading()}
|
|
123
|
+
<FileGlyphIcon glyph={glyphOf(entry.attachment)} />
|
|
124
|
+
{/snippet}
|
|
125
|
+
</Chip>
|
|
126
|
+
{#if canPreview}
|
|
127
|
+
<button
|
|
128
|
+
type="button"
|
|
129
|
+
class="absolute inset-y-0 start-0 end-7 cursor-pointer rounded-s-lg focus-visible:outline-none"
|
|
130
|
+
aria-label={$t('chat.attachment.view', { name: entry.attachment.label || entry.attachment.file?.name || $t('chat.attachment.namelessAlt') })}
|
|
131
|
+
onclick={() => onOpenPreview?.(entry.attachment)}
|
|
132
|
+
data-chip-open
|
|
133
|
+
data-testid="composer-file-preview"
|
|
134
|
+
></button>
|
|
135
|
+
{/if}
|
|
136
|
+
</span>
|
|
137
|
+
{/each}
|
|
138
|
+
</div>
|
|
139
|
+
{/if}
|
|
140
|
+
|
|
141
|
+
{#if arrangement.pictures.length > 0}
|
|
142
|
+
<!-- The room above and at the end is for the cross of a thumbnail, which sits on its outer corner, and the room around is for the
|
|
143
|
+
ring of a thumbnail (the wrapper the box puts around this clips what leaves it). -->
|
|
144
|
+
<div class="composer-attachment-pictures flex min-w-0 flex-wrap gap-2 pb-0.5 ps-0.5 pe-1.5 pt-1.5" data-testid="composer-attachment-pictures">
|
|
145
|
+
{#each arrangement.pictures as entry (tileKey(entry))}
|
|
146
|
+
{@const rawUrl = previewUrl(entry.attachment)}
|
|
147
|
+
{@const ringed = isTileRinged(entry.attachment)}
|
|
148
|
+
<div
|
|
149
|
+
class="group relative size-14 shrink-0 rounded-lg {ringed ? 'ring-ring ring-2' : ''}"
|
|
150
|
+
data-testid="composer-image-preview"
|
|
151
|
+
data-label={entry.attachment.referenceLabel}
|
|
152
|
+
data-highlighted={ringed ? 'true' : undefined}
|
|
67
153
|
>
|
|
68
|
-
<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
154
|
+
<button
|
|
155
|
+
type="button"
|
|
156
|
+
class="border-border bg-muted block size-full cursor-zoom-in overflow-hidden rounded-lg border"
|
|
157
|
+
aria-label={entry.attachment.file?.name || $t('chat.attachment.namelessAlt')}
|
|
158
|
+
onclick={() => rawUrl && onOpenPreview?.(entry.attachment)}
|
|
159
|
+
>
|
|
160
|
+
<img
|
|
161
|
+
src={buildImageThumbnailUrl(rawUrl, IMAGE_PREVIEW_CSS_PX) || rawUrl}
|
|
162
|
+
alt=""
|
|
163
|
+
class="size-full object-cover"
|
|
164
|
+
draggable="false"
|
|
165
|
+
/>
|
|
166
|
+
</button>
|
|
167
|
+
<!--
|
|
168
|
+
The cross shows only while the pointer (or the keyboard) is on the thumbnail, on its outer top-right corner and in the
|
|
169
|
+
dark colours of the interface. A touch screen has no hover, so there it stays.
|
|
170
|
+
-->
|
|
171
|
+
<button
|
|
172
|
+
type="button"
|
|
173
|
+
class="bg-inverse text-inverse-foreground hover:bg-inverse/90 focus-visible:ring-ring absolute -end-1.5 -top-1.5 flex size-5 cursor-pointer items-center justify-center rounded-full opacity-0 shadow-sm transition-opacity duration-150 group-focus-within:opacity-100 group-hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-2 pointer-coarse:opacity-100 motion-reduce:transition-none"
|
|
174
|
+
data-testid="composer-image-remove"
|
|
175
|
+
aria-label={$t('chat.attachment.remove')}
|
|
176
|
+
onclick={() => onRemove(entry.index)}
|
|
177
|
+
>
|
|
178
|
+
<IconX class="size-3 stroke-[2.5]" aria-hidden="true" />
|
|
179
|
+
</button>
|
|
180
|
+
</div>
|
|
181
|
+
{/each}
|
|
182
|
+
</div>
|
|
183
|
+
{/if}
|
|
96
184
|
</div>
|
|
@@ -3,13 +3,23 @@ interface Props {
|
|
|
3
3
|
attachments: AttachmentInput[];
|
|
4
4
|
previewUrl: (attachment: AttachmentInput) => string;
|
|
5
5
|
isImage: (attachment: AttachmentInput) => boolean;
|
|
6
|
+
/** Removes a file. The index is the file's place in `attachments` (the list as it was given, not as it is drawn). */
|
|
6
7
|
onRemove: (index: number) => void;
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A picture, or a chip of a file that has a preview, was pressed: the page opens the file in its preview card. The page knows the
|
|
10
|
+
* files of the box, so it can give the card the arrows to the next one.
|
|
11
|
+
*/
|
|
12
|
+
onOpenPreview?: (attachment: AttachmentInput) => void;
|
|
8
13
|
/**
|
|
9
14
|
* The label of the file a badge in the message or a row of the `#` menu is on: the tile of that file is ringed, so the person
|
|
10
15
|
* sees which attachment the word stands for. Null (or a label no file has) rings nothing.
|
|
11
16
|
*/
|
|
12
17
|
highlightedLabel?: string | null;
|
|
18
|
+
/**
|
|
19
|
+
* The files the person tried to attach again (they were in the tray already): their tiles are ringed for a moment, so the
|
|
20
|
+
* person sees that they are there and that they were not added a second time. None rings nothing.
|
|
21
|
+
*/
|
|
22
|
+
flashedAttachmentIds?: readonly string[];
|
|
13
23
|
}
|
|
14
24
|
declare const ComposerAttachmentsTray: import("svelte").Component<Props, {}, "">;
|
|
15
25
|
type ComposerAttachmentsTray = ReturnType<typeof ComposerAttachmentsTray>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The small glyph in front of the name of a file chip (in the message box and in a sent message): it says at a glance what the file
|
|
4
|
+
* is, a PDF, a video, a sheet, a text, or any other file. Which glyph a file gets is `fileGlyphOf`'s rule (`utils/attachmentPreview.ts`).
|
|
5
|
+
*/
|
|
6
|
+
import IconFile from '@tabler/icons-svelte/icons/file';
|
|
7
|
+
import IconFileSpreadsheet from '@tabler/icons-svelte/icons/file-spreadsheet';
|
|
8
|
+
import IconFileText from '@tabler/icons-svelte/icons/file-text';
|
|
9
|
+
import IconFileTypePdf from '@tabler/icons-svelte/icons/file-type-pdf';
|
|
10
|
+
import IconVideo from '@tabler/icons-svelte/icons/video';
|
|
11
|
+
import type { FileGlyph } from '../utils/attachmentPreview.js';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
glyph: FileGlyph;
|
|
15
|
+
class?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let { glyph, class: className = '' }: Props = $props();
|
|
19
|
+
|
|
20
|
+
/** The look every glyph shares: 16 px, the muted colour of the words around it (the chip's name is the foreground colour). */
|
|
21
|
+
const glyphClasses = $derived(`text-muted-foreground size-4 shrink-0 stroke-2 ${className}`);
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
{#if glyph === 'pdf'}
|
|
25
|
+
<IconFileTypePdf class={glyphClasses} aria-hidden="true" data-testid="file-glyph-pdf" />
|
|
26
|
+
{:else if glyph === 'video'}
|
|
27
|
+
<IconVideo class={glyphClasses} aria-hidden="true" data-testid="file-glyph-video" />
|
|
28
|
+
{:else if glyph === 'sheet'}
|
|
29
|
+
<IconFileSpreadsheet class={glyphClasses} aria-hidden="true" data-testid="file-glyph-sheet" />
|
|
30
|
+
{:else if glyph === 'text'}
|
|
31
|
+
<IconFileText class={glyphClasses} aria-hidden="true" data-testid="file-glyph-text" />
|
|
32
|
+
{:else}
|
|
33
|
+
<IconFile class={glyphClasses} aria-hidden="true" data-testid="file-glyph-file" />
|
|
34
|
+
{/if}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FileGlyph } from '../utils/attachmentPreview.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
glyph: FileGlyph;
|
|
4
|
+
class?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const FileGlyphIcon: import("svelte").Component<Props, {}, "">;
|
|
7
|
+
type FileGlyphIcon = ReturnType<typeof FileGlyphIcon>;
|
|
8
|
+
export default FileGlyphIcon;
|
|
@@ -1,32 +1,48 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The starter ideas of an empty docked chat (Figma: Chat / Empty): a few words on each card, and the whole request behind it.
|
|
4
|
+
*
|
|
5
|
+
* - The tooltip shows the whole request while the pointer rests on a card or the keyboard is on it, as the follow-up card does.
|
|
6
|
+
* - A click puts that whole request in the message box (the host does that, through `onPick`), never the few words of the card,
|
|
7
|
+
* so the person can read, change and send what was shown.
|
|
8
|
+
*
|
|
9
|
+
* `Tooltip` comes from the components barrel of the design system, as `FollowUpCard`'s does: its export map has no path to it
|
|
10
|
+
* anywhere else. It shows no word of its own, only the request it is given. The tooltip is not hoverable content: it closes when
|
|
11
|
+
* the pointer leaves the card, so it never stays over the cards above it (it opens over the card, upwards, as the follow-up card's).
|
|
12
|
+
*/
|
|
2
13
|
import IconClock from '@tabler/icons-svelte/icons/clock';
|
|
3
14
|
import IconMessage from '@tabler/icons-svelte/icons/message';
|
|
4
15
|
import IconPhoto from '@tabler/icons-svelte/icons/photo';
|
|
5
16
|
import IconArrowsMaximize from '@tabler/icons-svelte/icons/arrows-maximize';
|
|
17
|
+
import { Tooltip } from '@widgetic/design-system/components';
|
|
6
18
|
import { SuggestionCard } from '@widgetic/design-system/components/chat/index';
|
|
7
19
|
import { useChatLanguage } from '../i18n/language.js';
|
|
8
20
|
import {
|
|
9
|
-
|
|
21
|
+
panelEmptySuggestions,
|
|
10
22
|
panelEmptySuggestionTitleKey,
|
|
23
|
+
type PanelStarterSuggestion,
|
|
11
24
|
} from '../i18n/suggestions.js';
|
|
12
25
|
import type { ChatMessageKey } from '../i18n/messages.js';
|
|
13
26
|
|
|
14
27
|
const { t } = useChatLanguage();
|
|
15
28
|
|
|
16
29
|
interface Props {
|
|
30
|
+
/** A card was picked: the whole request of its idea, for the message box (not the few words the card shows). */
|
|
17
31
|
onPick: (text: string) => void;
|
|
18
32
|
disabled?: boolean;
|
|
19
33
|
titleKey?: ChatMessageKey;
|
|
20
|
-
|
|
34
|
+
suggestions?: readonly PanelStarterSuggestion[];
|
|
21
35
|
}
|
|
22
36
|
|
|
23
37
|
let {
|
|
24
38
|
onPick,
|
|
25
39
|
disabled = false,
|
|
26
40
|
titleKey = panelEmptySuggestionTitleKey(),
|
|
27
|
-
|
|
41
|
+
suggestions = panelEmptySuggestions(),
|
|
28
42
|
}: Props = $props();
|
|
29
43
|
|
|
44
|
+
type TriggerProps = Record<string, unknown>;
|
|
45
|
+
|
|
30
46
|
const ICON_BY_KEY: Partial<Record<ChatMessageKey, typeof IconClock>> = {
|
|
31
47
|
'chat.suggestions.panel.countdown': IconClock,
|
|
32
48
|
'chat.suggestions.panel.testimonials': IconMessage,
|
|
@@ -38,24 +54,56 @@
|
|
|
38
54
|
function iconForKey(key: ChatMessageKey) {
|
|
39
55
|
return ICON_BY_KEY[key] ?? IconMessage;
|
|
40
56
|
}
|
|
57
|
+
|
|
58
|
+
/** The click of a card: the tooltip's own handler first (it closes the tooltip), then the pick of the whole request. */
|
|
59
|
+
function handlePick(triggerProps: TriggerProps, event: MouseEvent, request: string) {
|
|
60
|
+
try {
|
|
61
|
+
const closeTooltip = triggerProps.onclick;
|
|
62
|
+
if (typeof closeTooltip === 'function') closeTooltip(event);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.warn('[Chat] The suggestion tooltip could not be closed:', error);
|
|
65
|
+
}
|
|
66
|
+
if (disabled) return;
|
|
67
|
+
try {
|
|
68
|
+
onPick(request);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error('[Chat] A starter suggestion could not be picked:', error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
41
73
|
</script>
|
|
42
74
|
|
|
43
75
|
<div class="panel-suggestion-ct flex w-full max-w-full flex-col gap-1 pb-2">
|
|
44
76
|
<h4 class="text-caption text-muted-foreground">{$t(titleKey)}</h4>
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
<Tooltip.Provider delayDuration={200} disableHoverableContent>
|
|
78
|
+
<div class="flex w-full flex-col gap-1">
|
|
79
|
+
{#each suggestions as suggestion (suggestion.titleKey)}
|
|
80
|
+
{@const title = $t(suggestion.titleKey)}
|
|
81
|
+
{@const request = $t(suggestion.requestKey)}
|
|
82
|
+
{@const Icon = iconForKey(suggestion.titleKey)}
|
|
83
|
+
<Tooltip.Root>
|
|
84
|
+
<Tooltip.Trigger>
|
|
85
|
+
{#snippet child({ props }: { props: TriggerProps })}
|
|
86
|
+
<SuggestionCard
|
|
87
|
+
{...props}
|
|
88
|
+
{title}
|
|
89
|
+
{disabled}
|
|
90
|
+
class="min-h-11"
|
|
91
|
+
data-testid="panel-suggestion-card"
|
|
92
|
+
onclick={(event: MouseEvent) => handlePick(props, event, request)}
|
|
93
|
+
>
|
|
94
|
+
{#snippet icon()}
|
|
95
|
+
<Icon class="size-4 stroke-2" aria-hidden="true" />
|
|
96
|
+
{/snippet}
|
|
97
|
+
</SuggestionCard>
|
|
98
|
+
{/snippet}
|
|
99
|
+
</Tooltip.Trigger>
|
|
100
|
+
<Tooltip.Portal>
|
|
101
|
+
<Tooltip.Content side="top" align="center" collisionPadding={8} data-testid="panel-suggestion-tooltip">
|
|
102
|
+
{request}
|
|
103
|
+
</Tooltip.Content>
|
|
104
|
+
</Tooltip.Portal>
|
|
105
|
+
</Tooltip.Root>
|
|
106
|
+
{/each}
|
|
107
|
+
</div>
|
|
108
|
+
</Tooltip.Provider>
|
|
61
109
|
</div>
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { type PanelStarterSuggestion } from '../i18n/suggestions.js';
|
|
1
2
|
import type { ChatMessageKey } from '../i18n/messages.js';
|
|
2
3
|
interface Props {
|
|
4
|
+
/** A card was picked: the whole request of its idea, for the message box (not the few words the card shows). */
|
|
3
5
|
onPick: (text: string) => void;
|
|
4
6
|
disabled?: boolean;
|
|
5
7
|
titleKey?: ChatMessageKey;
|
|
6
|
-
|
|
8
|
+
suggestions?: readonly PanelStarterSuggestion[];
|
|
7
9
|
}
|
|
8
10
|
declare const PanelSuggestionButtons: import("svelte").Component<Props, {}, "">;
|
|
9
11
|
type PanelSuggestionButtons = ReturnType<typeof PanelSuggestionButtons>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The question a person is asked before the widget goes back to an earlier checkpoint: a restore throws away what came after the
|
|
4
|
+
* checkpoint, and the button that does it sits right under a message, where a click can happen by mistake. The question is the
|
|
5
|
+
* design system's action modal (the same card, motion and buttons as every other confirmation of the product); it says what is lost
|
|
6
|
+
* and keeps the destructive look on the button that confirms.
|
|
7
|
+
*
|
|
8
|
+
* The chat asks the question and the page does the restore: this component only tells which button was pressed.
|
|
9
|
+
*/
|
|
10
|
+
import { ActionModal } from '@widgetic/design-system/components';
|
|
11
|
+
import { useChatLanguage } from '../i18n/language.js';
|
|
12
|
+
import { chatLog, chatWarn } from '../utils/logger.js';
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
/** Whether the question is open. */
|
|
16
|
+
open: boolean;
|
|
17
|
+
/** The person confirmed: the restore goes ahead. */
|
|
18
|
+
onConfirm: () => void;
|
|
19
|
+
/** The question was closed (the cancel button, the cross, Escape or a click beside the card): nothing changes. */
|
|
20
|
+
onCancel: () => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let { open, onConfirm, onCancel }: Props = $props();
|
|
24
|
+
|
|
25
|
+
const { t } = useChatLanguage();
|
|
26
|
+
|
|
27
|
+
/** The confirm button was pressed: the restore goes ahead (an error of the page must not leave the question open). */
|
|
28
|
+
async function handleConfirm(): Promise<void> {
|
|
29
|
+
try {
|
|
30
|
+
chatLog('[RestoreCheckpointDialog] The restore was confirmed.');
|
|
31
|
+
onConfirm();
|
|
32
|
+
} catch (error) {
|
|
33
|
+
chatWarn('[RestoreCheckpointDialog] The restore of the checkpoint failed:', error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The question was closed without a confirmation. */
|
|
38
|
+
function handleCancel(): void {
|
|
39
|
+
chatLog('[RestoreCheckpointDialog] The restore was cancelled.');
|
|
40
|
+
onCancel();
|
|
41
|
+
}
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<!--
|
|
45
|
+
The card is as tall as its words (`height="auto"`, like the product's other confirmations that say more than a line). The action
|
|
46
|
+
modal's own default is a fixed 168 px card, sized for a one-line message: this message takes two lines (and a translation may
|
|
47
|
+
take three), so in the fixed card the buttons sat on the bottom edge, with none of the padding the card has everywhere else.
|
|
48
|
+
-->
|
|
49
|
+
{#if open}
|
|
50
|
+
<ActionModal
|
|
51
|
+
isOpen={true}
|
|
52
|
+
title={$t('chat.checkpoint.confirmTitle')}
|
|
53
|
+
message={$t('chat.checkpoint.confirmMessage')}
|
|
54
|
+
confirmLabel={$t('chat.checkpoint.confirmRestore')}
|
|
55
|
+
cancelLabel={$t('chat.checkpoint.confirmCancel')}
|
|
56
|
+
closeLabel={$t('chat.attachment.close')}
|
|
57
|
+
width="450px"
|
|
58
|
+
height="auto"
|
|
59
|
+
confirmVariant="attention"
|
|
60
|
+
actionType="restoreCheckpoint"
|
|
61
|
+
modalType="restoreCheckpointConfirmation"
|
|
62
|
+
target="chat-restore-checkpoint-modal"
|
|
63
|
+
onConfirm={handleConfirm}
|
|
64
|
+
onCancel={handleCancel}
|
|
65
|
+
/>
|
|
66
|
+
{/if}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** Whether the question is open. */
|
|
3
|
+
open: boolean;
|
|
4
|
+
/** The person confirmed: the restore goes ahead. */
|
|
5
|
+
onConfirm: () => void;
|
|
6
|
+
/** The question was closed (the cancel button, the cross, Escape or a click beside the card): nothing changes. */
|
|
7
|
+
onCancel: () => void;
|
|
8
|
+
}
|
|
9
|
+
declare const RestoreCheckpointDialog: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type RestoreCheckpointDialog = ReturnType<typeof RestoreCheckpointDialog>;
|
|
11
|
+
export default RestoreCheckpointDialog;
|