@widgetic/chat 0.1.45 → 0.1.48
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 +148 -20
- 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 +514 -94
- package/dist/components/Chat.svelte.d.ts +19 -2
- package/dist/components/ChatComposer.svelte +126 -72
- package/dist/components/ChatComposer.svelte.d.ts +13 -3
- package/dist/components/ChatDropOverlay.svelte +58 -0
- package/dist/components/ChatDropOverlay.svelte.d.ts +8 -0
- package/dist/components/ChatInput.svelte +42 -1
- package/dist/components/ChatInput.svelte.d.ts +2 -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/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/messages.d.ts +45 -3
- package/dist/i18n/messages.js +51 -5
- 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
package/README.md
CHANGED
|
@@ -168,13 +168,22 @@ Three kinds of icon sit around the messages. None of them is shown while somethi
|
|
|
168
168
|
- **At the end of the last message**, one row of up to four icons: **copy** (the words the assistant said, else the title of the commit the turn
|
|
169
169
|
made; the icon says "Copied" for a moment), **regenerate** (runs the prompt of that turn again, through `onRetryMessage`; left out when the
|
|
170
170
|
prompt cannot be run again), and **thumbs up** and **thumbs down** (see [Rating a version](#rating-a-version)). An icon that has nothing to do
|
|
171
|
-
is left out, and the whole row with it.
|
|
171
|
+
is left out, and the whole row with it. The icons rest in the **placeholder grey** (the colour of the hint in the message box), so the row does
|
|
172
|
+
not compete with the words above it; they take the full text colour under the pointer or the keyboard, and a thumb that was pressed keeps the full
|
|
173
|
+
colour with its filled shape, so the vote that was given stays easy to see.
|
|
172
174
|
- **On a message the person sent**, one **restore** icon ("Restore Checkpoint") at the end of the message, shown when the pointer is over the
|
|
173
175
|
message or the keyboard is on the icon (always shown on a screen with no hover). It puts the widget back to how it was **before that
|
|
174
176
|
message**: the chat asks the page, through `onRestoreCheckpointBackend`, to restore the version of the nearest earlier prompt that made one,
|
|
175
177
|
and then adds the restored prompt and "Restored from Version N" to the list. Only a message that made a version has the icon, and no icon is
|
|
176
178
|
drawn when the page gave no `onRestoreCheckpointBackend`. The first version has nothing before it: while the widget sits on it, its icon undoes
|
|
177
179
|
it (the page decides what that means); once later versions exist it has no icon. After a restore, the next message goes back to the restored version.
|
|
180
|
+
**A restore asks first**: the icon sits right under a message, where a click can be a mistake, and a restore throws away what came after the
|
|
181
|
+
checkpoint, so pressing it opens the design system's action modal, "Restore this checkpoint?" with "You will lose the changes made after this checkpoint.",
|
|
182
|
+
a destructive **Restore** and a **Cancel** (`chat.checkpoint.confirmTitle`, `…confirmMessage`, `…confirmRestore`, `…confirmCancel`). The page is asked only
|
|
183
|
+
after the person confirms; Cancel, the cross, Escape or a click beside the card changes nothing. A redo (the icon that brings undone work back) asks nothing.
|
|
184
|
+
`ChatMessages`' `onRestoreCheckpoint` is called with a third word, `'restore'` or `'redo'`, for a page that draws the messages itself. The card is as
|
|
185
|
+
tall as its words (a fixed card would put the two-line message's buttons on its edge). To try it, open `/agent`: its pretend host answers a confirmed restore
|
|
186
|
+
with a new commit, which the chat shows as the "Restored from …" turn.
|
|
178
187
|
|
|
179
188
|
There is no "You are here" mark: the person is always at the end of the conversation. The `viewingVersion` prop of `Chat` is still accepted and
|
|
180
189
|
ignored, so a page that passes it keeps compiling.
|
|
@@ -184,7 +193,8 @@ ignored, so a page that passes it keeps compiling.
|
|
|
184
193
|
At the end of the last message (the reply that announced a change of the widget) the chat can draw two thumbs, so a person can say whether
|
|
185
194
|
that version is good: a thumbs up helps the code generator learn what works, a thumbs down what does not. The thumbs are **opt-in**: give
|
|
186
195
|
`Chat` an `onRateVersion` callback and they appear, leave it out and the chat draws no thumbs. The chat keeps no rating of its own: the page
|
|
187
|
-
decides where a rating goes. A rating is one of three words: `up`, `down`, or `none` (the person took their rating back).
|
|
196
|
+
decides where a rating goes. A rating is one of three words: `up`, `down`, or `none` (the person took their rating back). The demo page (`/agent`)
|
|
197
|
+
gives a pretend callback, so the thumbs show under the last message there.
|
|
188
198
|
|
|
189
199
|
```svelte
|
|
190
200
|
<script lang="ts">
|
|
@@ -402,6 +412,11 @@ Lower the flag when the plan arrives, or when no plan is coming. It is ignored w
|
|
|
402
412
|
once the coder's thinking or its code streams (both come after the plan, so a plan that was never made is not waited for).
|
|
403
413
|
Left `false`, the default, nothing is drawn until `generationPlan` arrives, as before.
|
|
404
414
|
|
|
415
|
+
A plan of more than four tasks shows the first four and folds the rest behind a toggle ("Show 2 more tasks", `chat.plan.showMoreTasks`). Opening it
|
|
416
|
+
lists the folded tasks **right after the visible ones**, and the toggle ("Show fewer tasks", `chat.plan.showFewerTasks`) is the last thing of the card.
|
|
417
|
+
A folded card is grey under the pointer, as a chip is, and a press on it (outside its buttons and links; the end of a text selection does not count)
|
|
418
|
+
opens it, like the toggle does. A closed code card is drawn the same way: grey under the pointer, and its whole surface opens it.
|
|
419
|
+
|
|
405
420
|
The plan card belongs to the run in front of the person. When the run ends, however it ends (finished, failed or **stopped**),
|
|
406
421
|
the card goes in the same pass: the plan is not kept in the conversation, and no task is left shimmering, turning or struck
|
|
407
422
|
through. A host does not have to clear `generationPlan` first for that, but it should, so that the next run does not begin
|
|
@@ -483,6 +498,41 @@ wire format and the bounds). A page reads it with **`readCodeChangesFromMetadata
|
|
|
483
498
|
so the green is Tailwind's (`green-500/15` for the ground, `green-700` for the numbers, `green-400` on the dark theme through the `.dark` class);
|
|
484
499
|
the red is the design system's `destructive`.
|
|
485
500
|
|
|
501
|
+
#### What the agent said it changed: the conclusion
|
|
502
|
+
|
|
503
|
+
Under a finished run the chat draws one line, the **conclusion**. It used to be the same sentence for every run ("Done. Your changes are ready.",
|
|
504
|
+
`chat.generation.doneMessage`). A page that has the agent's own summary of the round gives it to `Chat` as **`generationSummary`**, and the conclusion
|
|
505
|
+
says that instead (the sentence stays for a run whose agent said nothing: a first build, a build that was not kept, a gateway that sends no summary).
|
|
506
|
+
The gateway sends it in the completed operation's `metadata.summary`: a string of plain text, a sentence or two, in the agent's voice. A page reads it
|
|
507
|
+
with **`readGenerationSummary`** (the same reader the chat uses: the words become one paragraph, anything that is not text reads as none, and what is
|
|
508
|
+
longer than `MAX_KEPT_SUMMARY_CHARS`, 600, is cut and ends in "…"):
|
|
509
|
+
|
|
510
|
+
```svelte
|
|
511
|
+
<script lang="ts">
|
|
512
|
+
import { Chat, readGenerationSummary } from '@widgetic/chat';
|
|
513
|
+
|
|
514
|
+
let summary = $state(null);
|
|
515
|
+
|
|
516
|
+
function onRunStarted() {
|
|
517
|
+
summary = null; // the summary of the run before is not this run's
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function onOperationCompleted(operation) {
|
|
521
|
+
summary = readGenerationSummary(operation.metadata?.summary);
|
|
522
|
+
}
|
|
523
|
+
</script>
|
|
524
|
+
|
|
525
|
+
<Chat {context} isGenerating={codegenRunning} generationSummary={summary} />
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
- It behaves exactly like `generationChanges` above: it is **not** given up when `isGenerating` ends (it is what the run leaves behind), it may come
|
|
529
|
+
**after** the flag fell (the chat puts it into the work of the run that just ended, never into work that came back from the archive), the value the chat
|
|
530
|
+
held when the run began is ignored (a page that forgets to clear it is safe), and it is kept with the run's work in this browser, so it is there after a
|
|
531
|
+
reload.
|
|
532
|
+
- The conclusion is only drawn for a run the person watched, as before; the summary changes its words and nothing else.
|
|
533
|
+
- Nothing is invented on this side: the chat does not write a summary from the code. The gateway has to send `operation.metadata.summary` (a string, no
|
|
534
|
+
new capability key). The demo page's `edit` scenario ends with one (`/agent?scenario=edit`); the first build there shows the sentence.
|
|
535
|
+
|
|
486
536
|
### The assistant's turn: avatar, sound, faces and bubbles
|
|
487
537
|
|
|
488
538
|
The messages list plays the assistant's turn around an **avatar**. The avatar, its sound and the team's faces come from the page: the chat
|
|
@@ -567,8 +617,23 @@ typed by hand and a picture taken out, both. A bubble with badges is still tight
|
|
|
567
617
|
searched the same way as any bubble and checked against what the browser made, and it keeps CSS's width when the two disagree. Needs a design
|
|
568
618
|
system that has `@widgetic/design-system/prompt-references`; `referenceBadges={false}` shows every text as it was sent.
|
|
569
619
|
|
|
620
|
+
**A refusal because of the credits or the plan.** When a request is refused because the credits are used up, or because the plan does not include
|
|
621
|
+
it (a free trial that ended, an account that is not subscribed), the chat says so in one plain sentence (a failure, in red, with the avatar's error
|
|
622
|
+
look) and draws an **Upgrade** button right under it: a filled button, the call to action of the reply, with no "try again" icon beside the failure
|
|
623
|
+
(trying again cannot help). The sketch assistant (`runSketchAssistantLoop`) says it in one of three catalog sentences: `chat.sketch.noCredits`
|
|
624
|
+
("You're out of credits."), `chat.sketch.planRequired` ("Your plan doesn't include this.") and, for the visitor of a page that is not their own, who has
|
|
625
|
+
neither (`neutralLimits: true`), `chat.sketch.limitReached` ("You've reached a usage limit."). Which refusal is which is `limitFailureKindOfRefusal`
|
|
626
|
+
(exported with the services): a 402 is the credits, except the 402s that are not a shortage (the balance could not be read, which is a reason to try
|
|
627
|
+
again, and an account that holds no credits); a 403 is the plan when the gateway marks it (`AUTHZ_PLAN_RESTRICTION`, or `error.details.limit`) or says so
|
|
628
|
+
in its own words ("…free trial has ended…", "…not available in your plan…"); any other 403 is an ordinary refusal. A saved reply carries only its words, so
|
|
629
|
+
after a reload the chat knows those three sentences again by their **whole words** (in English, which is what a host saves, and in the page's language),
|
|
630
|
+
and never by looser ones: a reply of the model that mentions a free trial stays a reply. The lines a host saves for a code generation ("Code generation
|
|
631
|
+
failed: … Upgrade your plan to continue.") are read by their words as before. A press on the button calls `onUpgradePlans`; without it the billing page
|
|
632
|
+
of the Widgetic site opens. A page that translates the catalog should translate `chat.sketch.planRequired` and `chat.sketch.limitReached` (until then
|
|
633
|
+
they show in English), and say `chat.sketch.noCredits` again: its words changed.
|
|
634
|
+
|
|
570
635
|
To see it all on a real chat played by a pretend host, run `npm run dev` and open `/agent`. It loads the mascot and its sound from the
|
|
571
|
-
sibling `brand` checkout when it is there, and answers on `window.__agentDemo` for scripted checks. Query: `scenario=success|edit|failure|earlyFailure|question|stopped|plain` (`edit` ends with the changes of a later round, so the code card opens on the diff),
|
|
636
|
+
sibling `brand` checkout when it is there, and answers on `window.__agentDemo` for scripted checks. Query: `scenario=success|edit|failure|earlyFailure|noCredits|planRequired|question|stopped|plain` (`edit` ends with the changes of a later round, so the code card opens on the diff; `noCredits` and `planRequired` end with the sentence of a refusal because of money and its Upgrade button, and `window.__agentDemo.upgradePresses()` counts the presses),
|
|
572
637
|
`run=1`, `step=1`, `speed=4`, `panel=0`, `rtl=1`, `mascot=0`, `sound=0`, `people=0`, `tight=0`.
|
|
573
638
|
sibling `brand` checkout when it is there, and answers on `window.__agentDemo` for scripted checks. Query: `scenario=success|failure|question|questions|stopped|plain`,
|
|
574
639
|
`run=1`, `step=1`, `speed=4`, `panel=0`, `rtl=1`, `mascot=0`, `sound=0`, `people=0`, `tight=0`. The `success` scenario ends with the
|
|
@@ -749,10 +814,12 @@ system (`npm run package` in the design-system checkout) that has the `inline-co
|
|
|
749
814
|
### Referring to attached files with `#`
|
|
750
815
|
|
|
751
816
|
A message can point at a file that is attached to it. Type **#** in the message box and the files of the tray open as a list, each with its
|
|
752
|
-
picture, its name and its
|
|
817
|
+
small picture, its name and its number in the tray (the picture is the preview: no larger card opens beside the list; a long name takes two lines, and
|
|
818
|
+
the whole name and the size show when the pointer rests on a row); the arrow keys and Enter (or a click) pick one, **Esc** closes the list. The pick becomes a **badge** in the
|
|
753
819
|
text: the file's picture, its label (`#hero_banner`) and an X that takes the badge out. Typing the start of a label, of a file name or a tray
|
|
754
820
|
number after the `#` narrows the list. What is sent is the plain text (`#hero_banner`), so a message reads the same wherever it is shown, and
|
|
755
|
-
the files it names go with it.
|
|
821
|
+
the files it names go with it. Nothing says so: no line under the box and nothing told to a screen reader either (a person who has attached a file
|
|
822
|
+
needs no line of help for it).
|
|
756
823
|
|
|
757
824
|
- **Labels.** A file is called by the words of its name: `hero-banner-final.png` is `#hero_banner_final`, and a second file of that name is
|
|
758
825
|
`#hero_banner_final_2`. A name that says nothing (a screenshot, a camera's name, a paste) is `#Image_1`, `#Image_2` and so on, in the order the
|
|
@@ -770,7 +837,7 @@ the files it names go with it. While a file is attached, a line under the box sa
|
|
|
770
837
|
is plain `#label` text again: no word of a restored draft is tied to a picture by luck.
|
|
771
838
|
- **Ghost-text suggestions never see a file's name.** With `completion` on, each reference reaches the source as the neutral word `#file`.
|
|
772
839
|
- The tray rings the tile of the file a badge, or a row of the list, is on.
|
|
773
|
-
- Catalog: `chat.input.
|
|
840
|
+
- Catalog: `chat.input.referenceMenuLabel` ("Attached files") and `chat.input.referenceRemove` ("Remove {name}"). (There is no message for a line of help about `#`.)
|
|
774
841
|
`ChatComposer` takes `referenceItems`, `maxReferences` and `onReferenceHover` for a page that builds its own panel.
|
|
775
842
|
|
|
776
843
|
Needs a design system with the `Composer`'s `references` prop (`npm run package` in the design-system checkout).
|
|
@@ -886,25 +953,86 @@ it reads the language of that chat, so two chats on one page can speak two langu
|
|
|
886
953
|
|
|
887
954
|
### Supported File Types
|
|
888
955
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
956
|
+
The message box takes these, whether they are dropped on the chat, picked with the "+" or pasted. Anything else (a zip, a Word file, a sound, a folder) is
|
|
957
|
+
left out with a toast that says why. The rules are in `utils/attachmentPolicy.ts`:
|
|
958
|
+
|
|
959
|
+
- **Images** (`image/*`, or `.png .jpg .jpeg .gif .webp .svg .avif .bmp` when the system gives no type): up to 10 MB, checked on the picture that is
|
|
960
|
+
sent (a large one is made smaller first).
|
|
961
|
+
- **Videos** (`video/*`, or `.mp4 .webm .mov .m4v`): up to 100 MB.
|
|
962
|
+
- **Documents** (`text/*`, PDF, JSON, CSV, or `.pdf .txt .md .markdown .csv .tsv .json .mermaid .mmd`): up to 25 MB.
|
|
963
|
+
|
|
964
|
+
The chat keeps and shows every one of them with the message. Whether the **page's builder** reads them is the page's business: the widget creator's builder
|
|
965
|
+
reads pictures, CSV and Markdown or text files, keeps a video or a PDF with the message without reading it, and says so in a warning after the send. The
|
|
966
|
+
tooltip of the "+" says it before (`chat.actions.uploadTooltip`: "Add images, CSV or text files. The builder does not read video or PDF yet."); a page whose
|
|
967
|
+
builder reads more says its own words.
|
|
968
|
+
|
|
969
|
+
### The files of the message box and of a sent message
|
|
970
|
+
|
|
971
|
+
The attached files live **inside the message box, over the text**, and the box grows to hold them (its text scrolls when it has more than fits). They are
|
|
972
|
+
arranged the same way in the box and, once it is sent, in the message (`arrangeTrayAttachments` in `utils/attachmentTray.ts`, `arrangeSentAttachments` in
|
|
973
|
+
`utils/sentAttachments.ts`; Figma: Chat states, "Attachments", "Sent picture" and "Thread"):
|
|
974
|
+
|
|
975
|
+
- **The files that are not pictures come first**, each as a chip with the glyph of its kind (PDF, video, sheet, text, other), whatever order they were
|
|
976
|
+
added in; **the pictures follow below them**, one after the other, as small thumbnails. In a sent message both rows stand above its bubble, at its end;
|
|
977
|
+
a message of files only has no bubble.
|
|
978
|
+
- **A picture shows no progress bar while it uploads**: the thumbnail is there, and that is all there is to see. A chip keeps its fill. The cross that takes a
|
|
979
|
+
thumbnail out shows only while the pointer (or the keyboard) is on it, on its outer top-right corner, in the dark colours of the interface; a touch screen
|
|
980
|
+
always shows it.
|
|
981
|
+
- **A file that comes again is attached once.** The same picture dragged twice, a screenshot pasted after it was dropped, a file picked a second time are the
|
|
982
|
+
same bytes under another name or none (`image.png` is every screenshot's name), so the box compares **what the files are made of**: `fingerprintFile`
|
|
983
|
+
(`utils/attachmentDuplicates.ts`) makes a SHA-256 of the bytes (of the two ends and the size for a file over 32 MB; of the name, size and date where the
|
|
984
|
+
browser cannot hash), and a file whose fingerprint is in the box, in the same batch, or being made ready is left out. The tile that already has it is ringed
|
|
985
|
+
for a moment, so the person sees it is there.
|
|
986
|
+
- **A text that was pasted has no tile**: see the next section.
|
|
987
|
+
- A thumbnail or a chip of a file the preview can show opens it (see "The preview of a file").
|
|
988
|
+
|
|
989
|
+
### Dropping files on the chat
|
|
990
|
+
|
|
991
|
+
**The whole chat is the drop area**, not only the message box. While files are dragged over any part of it (the header, a message, the box), a white veil dims
|
|
992
|
+
the chat and a dashed frame says what releasing them does (`ChatDropOverlay`; Figma: Chat states, "Chat / Drop files" and "Chat / Drop not allowed"):
|
|
993
|
+
|
|
994
|
+
- **Green, "Drop to attach"** (`chat.drop.title`, `chat.drop.hint`: "Images, CSV or text files") when the files are of a kind the box takes;
|
|
995
|
+
- **Red, "This file type is not supported"** (`chat.drop.refusedTitle`, `chat.drop.refusedHint`) when every file is of a kind it does not take.
|
|
996
|
+
|
|
997
|
+
Only the types are known while a file is dragged, so the sizes are judged on the drop: a file that is too large, a kind the box does not take, or a folder
|
|
998
|
+
is left out with one toast for each kind of refusal (`chat.attachment.refusedTypeOne`, `…TypeMany`, `…SizeOne`, `…SizeMany`, `…Folder`), and the rest is
|
|
999
|
+
attached. A mixed drag is taken: the files that can be taken are attached. The veil lets the pointer through (the chat below keeps receiving the drag), and
|
|
1000
|
+
the drop is the chat's own: a host that also listens for dropped files above the chat does not get it too. A text or a link dragged over the chat is not for it,
|
|
1001
|
+
and a host that switched uploads off (`config.features.fileUpload: false`) gets no veil and no drop. The rules for the drag are in `utils/chatFileDrag.ts`: a
|
|
1002
|
+
`dragleave` between two parts of the chat does not end the drag, and a drag that ends with no word from the browser (the Escape key, a window that took the
|
|
1003
|
+
files) ends after 1.5 s without a `dragover`. A person who asked for reduced motion gets no fade.
|
|
1004
|
+
|
|
1005
|
+
### The preview of a file
|
|
1006
|
+
|
|
1007
|
+
A thumbnail or a file chip, in the message box and in a sent message, opens the file in a **card that looks and moves like the File Browser's preview**
|
|
1008
|
+
(`AttachmentPreviewDialog`): the design system's `BaseModal` (the same fade and slide as every dialog; the focus stays inside; Escape or a click on the dark
|
|
1009
|
+
layer closes it), the name and the details of the file on top with the arrows to the file before and after it and the close button, and below it the file
|
|
1010
|
+
itself: a picture at its own size, a video that plays, a PDF with its pages, or a text (its first part; "The rest of this file is not shown." when it is cut).
|
|
1011
|
+
The left and right arrow keys step through the files of the same message, or of the same box, in the order they are drawn. A chip of a file that has no
|
|
1012
|
+
preview only names it. The words are the catalog keys `chat.preview.*`. (It replaces the old lightbox of `AttachmentDisplay`, a picture or a PDF over a dark
|
|
1013
|
+
layer with a caption.)
|
|
892
1014
|
|
|
893
1015
|
### Pasting into the message box
|
|
894
1016
|
|
|
895
|
-
What a person copies can be pasted into the message box, and it is attached the way a file dropped on the box is
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
- **A screenshot**, or a picture copied from a page, becomes an image attachment. A file copied in the file manager is attached as that file.
|
|
899
|
-
- **A long text** (500 characters or more, or 12 lines or more), like a reply copied from a chat, becomes a text file, `pasted-text.txt`, and
|
|
900
|
-
|
|
1017
|
+
What a person copies can be pasted into the message box, and it is attached the way a file dropped on the box is (and uploaded and sent like a dropped file,
|
|
1018
|
+
through `onUploadChatFile` and `onSendMessage`):
|
|
1019
|
+
|
|
1020
|
+
- **A screenshot**, or a picture copied from a page, becomes an image attachment, with a thumbnail. A file copied in the file manager is attached as that file.
|
|
1021
|
+
- **A long text** (500 characters or more, or 12 lines or more), like a reply copied from a chat, becomes a text file, `pasted-text.txt`, and the message names it
|
|
1022
|
+
with a **badge written into the words, exactly where the caret was** (or in place of the selection that the paste replaces): a text pasted after the second
|
|
1023
|
+
paragraph of a brief is named after the second paragraph, and the person can write "…as the error in `#pasted_text` shows" around it (the badge is
|
|
1024
|
+
`#pasted_text`, then `#pasted_text_2`; the rules are in `utils/pasteInsertion.ts`, and the box's `placeCaret(position)` puts the caret after the badge). It
|
|
1025
|
+
has no tile in the tray: the badge is how the message holds it. **The card over the badge says the beginning of the text**, with an ellipsis when it is cut
|
|
1026
|
+
(`pastedTextExcerpt`); in a sent message the beginning is read once, when the pointer first rests on the badge, and the badge says the name of the file when
|
|
1027
|
+
that cannot be done. A badge that is deleted takes its text with it from the send (a file that nothing on the screen shows is not sent), and a draft that
|
|
1028
|
+
comes back drops the badge of a text it has no file for. A host that reads text documents (the Widget Creator does) gives its words to the model.
|
|
901
1029
|
- **A short text** is not attached: the browser types it into the box, as it always did.
|
|
902
1030
|
|
|
903
1031
|
When a picture and a text come together (a spreadsheet writes its cells as a text and as a picture), the text is what was copied: a long one is
|
|
904
1032
|
attached as a text file, a short one goes into the box. The name or the link of a copied file, which come as a text next to it, do not count as a text.
|
|
905
1033
|
|
|
906
|
-
Every paste is an attachment of its own: three screenshots and two long texts pasted one after another are five
|
|
907
|
-
and none replaces, joins or hides another. Each is uploaded by itself (one can be taken out while the others are still uploading) and goes to the host
|
|
1034
|
+
Every paste is an attachment of its own: three screenshots and two long texts pasted one after another are five attachments (three thumbnails, in the order
|
|
1035
|
+
they were pasted, and two badges in the words, each where its paste happened), and none replaces, joins or hides another. Each is uploaded by itself (one can be taken out while the others are still uploading) and goes to the host
|
|
908
1036
|
as its own attachment, with its own stored address and upload id. Files that would share a name are told apart by it, counting the files already in the
|
|
909
1037
|
tray: the second screenshot is `image-2.png`, the third `image-3.png`, and a second long text is `pasted-text-2.txt`. A host that reads text documents
|
|
910
1038
|
(the Widget Creator does) names each one by its file name, which is why two texts that were both `pasted-text.txt` could not be told apart.
|
|
@@ -912,12 +1040,12 @@ tray: the second screenshot is `image-2.png`, the third `image-3.png`, and a sec
|
|
|
912
1040
|
A large picture is made smaller before it is uploaded, the way a dropped or picked one is (its long edge is brought to 1568 px and the file to about 1.5 MB,
|
|
913
1041
|
by `prepareChatImageFileForUpload`; a small one is left as it is, and a picture made smaller is named by what it became, `image.png` → `image.jpg`). This holds
|
|
914
1042
|
for a screenshot pasted into the box and for the pictures a page hands to `addImageAttachment` (the Widget Creator catches a screenshot pasted in its panel
|
|
915
|
-
and does that). A big picture takes longer to prepare than a small one, but the
|
|
916
|
-
waits for the screenshot's
|
|
1043
|
+
and does that). A big picture takes longer to prepare than a small one, but the attachments still come in the order of the pastes (a text pasted after a screenshot
|
|
1044
|
+
waits for the screenshot's thumbnail), and the uploads still run side by side. A picture that cannot be made ready, or is not ready after 15 seconds, is attached as it
|
|
917
1045
|
came: a paste is never lost for that, and a picture that never gets ready cannot hold up the pastes after it.
|
|
918
1046
|
|
|
919
1047
|
Pasting follows the "+" button: it is on unless `config.features.fileUpload` is `false`, and then the box pastes as the browser does. The name of the
|
|
920
|
-
file never says what is in the text (it is the name the server stores the file under)
|
|
1048
|
+
file never says what is in the text (it is the name the server stores the file under): what the text says is shown by the card over its badge.
|
|
921
1049
|
|
|
922
1050
|
A page with a message box of its own can use the same rules:
|
|
923
1051
|
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { fileSizeText } from '../i18n/labels.js';
|
|
5
5
|
import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
|
|
6
6
|
import { buildImageThumbnailUrl } from '../utils/imageTransform.js';
|
|
7
|
+
import { previewGroupOf, type PreviewableFile } from '../utils/attachmentPreview.js';
|
|
8
|
+
import AttachmentPreviewDialog from './AttachmentPreviewDialog.svelte';
|
|
7
9
|
|
|
8
10
|
// The words of the attachments, and the language the numbers of a size are written in
|
|
9
11
|
const { t, locale } = useChatLanguage();
|
|
@@ -30,28 +32,6 @@
|
|
|
30
32
|
onView
|
|
31
33
|
}: Props = $props();
|
|
32
34
|
|
|
33
|
-
/**
|
|
34
|
-
* Moves the node up to the top of the page it is on, so that it covers everything (a lightbox, say). That is the page's
|
|
35
|
-
* <body> — unless the chat is in a shadow root, on a partner's page: the styles reach only what is inside the shadow
|
|
36
|
-
* root, and the partner's <body> is not ours, so there it goes to the top of the shadow root (into the element that
|
|
37
|
-
* holds the whole chat, which also keeps the colors and the fonts that element gives).
|
|
38
|
-
*/
|
|
39
|
-
function portalToBody(node: HTMLElement) {
|
|
40
|
-
const root = node.getRootNode();
|
|
41
|
-
if (root instanceof ShadowRoot) {
|
|
42
|
-
let topElement: Node = node;
|
|
43
|
-
while (topElement.parentNode && topElement.parentNode !== root) topElement = topElement.parentNode;
|
|
44
|
-
(topElement !== node ? topElement : root).appendChild(node);
|
|
45
|
-
} else {
|
|
46
|
-
document.body.appendChild(node);
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
destroy() {
|
|
50
|
-
node.remove();
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
35
|
/**
|
|
56
36
|
* The key of an attachment in a keyed list. A saved message brings the id of its database row; an attachment that was just
|
|
57
37
|
* sent, or one a server answered without an id, has none, and two of them under the same key (`undefined`) stop the list
|
|
@@ -90,25 +70,24 @@
|
|
|
90
70
|
return fileType.startsWith('video/');
|
|
91
71
|
}
|
|
92
72
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
function isViewableInLightbox(fileType: string): boolean {
|
|
96
|
-
return fileType.startsWith('image/') || fileType.includes('pdf');
|
|
97
|
-
}
|
|
73
|
+
/** The files the open preview steps through and the place of the open one, or null while no preview is open. */
|
|
74
|
+
let preview: { files: PreviewableFile[]; openIndex: number } | null = $state(null);
|
|
98
75
|
|
|
76
|
+
// A file opens in the same preview card as the files of the message box (the look of the File Browser's preview); a file with no
|
|
77
|
+
// preview is opened from its address in a new tab, as it always was.
|
|
99
78
|
function handleView(attachment: ContentItemOutput) {
|
|
100
79
|
if (onView) {
|
|
101
80
|
onView(attachment);
|
|
102
|
-
|
|
103
|
-
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const group = previewGroupOf(displayedAttachments);
|
|
84
|
+
const openIndex = group.indexOf(attachment);
|
|
85
|
+
if (openIndex >= 0) {
|
|
86
|
+
preview = { files: group.files, openIndex };
|
|
104
87
|
} else if (attachment.url) {
|
|
105
88
|
window.open(attachment.url, '_blank', 'noopener,noreferrer');
|
|
106
89
|
}
|
|
107
90
|
}
|
|
108
|
-
|
|
109
|
-
function closeLightbox() {
|
|
110
|
-
lightboxAttachment = null;
|
|
111
|
-
}
|
|
112
91
|
|
|
113
92
|
function handleRemove(attachment: ContentItemOutput) {
|
|
114
93
|
if (attachment.url && attachment.url.startsWith('blob:')) {
|
|
@@ -286,37 +265,16 @@
|
|
|
286
265
|
</div>
|
|
287
266
|
{/if}
|
|
288
267
|
|
|
289
|
-
<!--
|
|
290
|
-
{#if
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
300
|
-
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
301
|
-
<div class="lightbox-content" onclick={(e) => e.stopPropagation()}>
|
|
302
|
-
{#if isImageType(lightboxAttachment.file_type, lightboxAttachment.url)}
|
|
303
|
-
<img
|
|
304
|
-
src={lightboxAttachment.url}
|
|
305
|
-
alt={lightboxAttachment.file_name || $t('chat.attachment.alt')}
|
|
306
|
-
class="lightbox-image"
|
|
307
|
-
/>
|
|
308
|
-
{:else if lightboxAttachment.file_type.includes('pdf')}
|
|
309
|
-
<iframe
|
|
310
|
-
src={lightboxAttachment.url}
|
|
311
|
-
class="lightbox-pdf"
|
|
312
|
-
title={lightboxAttachment.file_name || $t('chat.attachment.pdfTitle')}
|
|
313
|
-
></iframe>
|
|
314
|
-
{/if}
|
|
315
|
-
{#if lightboxAttachment.file_name}
|
|
316
|
-
<div class="lightbox-caption" dir={dirForUserText($textDirection)}>{lightboxAttachment.file_name}</div>
|
|
317
|
-
{/if}
|
|
318
|
-
</div>
|
|
319
|
-
</div>
|
|
268
|
+
<!-- The preview card of a file: the same card the message box opens (see AttachmentPreviewDialog) -->
|
|
269
|
+
{#if preview}
|
|
270
|
+
<AttachmentPreviewDialog
|
|
271
|
+
files={preview.files}
|
|
272
|
+
openIndex={preview.openIndex}
|
|
273
|
+
onNavigate={(index) => {
|
|
274
|
+
if (preview) preview = { ...preview, openIndex: index };
|
|
275
|
+
}}
|
|
276
|
+
onClose={() => (preview = null)}
|
|
277
|
+
/>
|
|
320
278
|
{/if}
|
|
321
279
|
|
|
322
280
|
<style>
|
|
@@ -537,70 +495,4 @@
|
|
|
537
495
|
padding: 0.5rem;
|
|
538
496
|
}
|
|
539
497
|
}
|
|
540
|
-
|
|
541
|
-
/* Lightbox overlay */
|
|
542
|
-
.lightbox-overlay {
|
|
543
|
-
position: fixed;
|
|
544
|
-
inset: 0;
|
|
545
|
-
z-index: 100000;
|
|
546
|
-
display: flex;
|
|
547
|
-
align-items: center;
|
|
548
|
-
justify-content: center;
|
|
549
|
-
background: rgba(0, 0, 0, 0.85);
|
|
550
|
-
backdrop-filter: blur(4px);
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
.lightbox-close {
|
|
554
|
-
position: absolute;
|
|
555
|
-
top: 16px;
|
|
556
|
-
inset-inline-end: 16px;
|
|
557
|
-
width: 36px;
|
|
558
|
-
height: 36px;
|
|
559
|
-
border-radius: 50%;
|
|
560
|
-
border: none;
|
|
561
|
-
background: rgba(255, 255, 255, 0.15);
|
|
562
|
-
color: white;
|
|
563
|
-
font-size: 18px;
|
|
564
|
-
cursor: pointer;
|
|
565
|
-
display: flex;
|
|
566
|
-
align-items: center;
|
|
567
|
-
justify-content: center;
|
|
568
|
-
transition: background 0.2s;
|
|
569
|
-
z-index: 10;
|
|
570
|
-
}
|
|
571
|
-
.lightbox-close:hover {
|
|
572
|
-
background: rgba(255, 255, 255, 0.3);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
.lightbox-content {
|
|
576
|
-
display: flex;
|
|
577
|
-
flex-direction: column;
|
|
578
|
-
align-items: center;
|
|
579
|
-
gap: 12px;
|
|
580
|
-
max-width: 90vw;
|
|
581
|
-
max-height: 90vh;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
.lightbox-image {
|
|
585
|
-
max-width: 90vw;
|
|
586
|
-
max-height: 85vh;
|
|
587
|
-
object-fit: contain;
|
|
588
|
-
border-radius: 8px;
|
|
589
|
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
.lightbox-pdf {
|
|
593
|
-
width: 80vw;
|
|
594
|
-
height: 85vh;
|
|
595
|
-
border: none;
|
|
596
|
-
border-radius: 8px;
|
|
597
|
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
|
|
598
|
-
background: white;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
.lightbox-caption {
|
|
602
|
-
color: rgba(255, 255, 255, 0.7);
|
|
603
|
-
font-size: 0.875rem;
|
|
604
|
-
text-align: center;
|
|
605
|
-
}
|
|
606
498
|
</style>
|