@marktiderman/genesis-chat 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +132 -3
  2. package/dist/{chunk-GBJ3YI4E.js → chunk-5XYDVUPS.js} +6 -3
  3. package/dist/chunk-5XYDVUPS.js.map +1 -0
  4. package/dist/{chunk-XQ2ULNHV.js → chunk-D4RPOYB7.js} +4 -4
  5. package/dist/chunk-D4RPOYB7.js.map +1 -0
  6. package/dist/{chunk-RYD6WJE5.js → chunk-O2QSBRSH.js} +3 -3
  7. package/dist/{chunk-RYD6WJE5.js.map → chunk-O2QSBRSH.js.map} +1 -1
  8. package/dist/{chunk-A4YJX7KT.js → chunk-ZQFREERR.js} +3 -3
  9. package/dist/{chunk-A4YJX7KT.js.map → chunk-ZQFREERR.js.map} +1 -1
  10. package/dist/{client-DUIG1hum.d.ts → client-DP7rhJ1U.d.ts} +17 -6
  11. package/dist/index.d.ts +4 -4
  12. package/dist/index.js +2 -2
  13. package/dist/native.d.ts +31 -15
  14. package/dist/native.js +74 -328
  15. package/dist/native.js.map +1 -1
  16. package/dist/{outbox-B9NAWQ58.d.ts → outbox-C4LnqpKT.d.ts} +1 -1
  17. package/dist/push.d.ts +2 -2
  18. package/dist/react.d.ts +4 -8
  19. package/dist/react.js +3 -3
  20. package/dist/server.d.ts +1 -1
  21. package/dist/server.js +1 -1
  22. package/dist/{thread-oPra7pkW.d.ts → thread-CSzdqNR_.d.ts} +1 -1
  23. package/dist/web.d.ts +201 -7
  24. package/dist/web.js +580 -56
  25. package/dist/web.js.map +1 -1
  26. package/migrations/0004_genesis_chat_tenants.sql +716 -0
  27. package/migrations/tests/0001_genesis_chat.test.sql +10 -2
  28. package/migrations/tests/0002_genesis_chat_coaching.test.sql +8 -0
  29. package/migrations/tests/0003_genesis_chat_search_threads.test.sql +8 -0
  30. package/migrations/tests/0004_genesis_chat_tenants.test.sql +259 -0
  31. package/package.json +18 -7
  32. package/src/__tests__/core.test.ts +12 -0
  33. package/src/__tests__/web-dock.test.tsx +465 -0
  34. package/src/__tests__/web-photo-viewer.test.tsx +43 -0
  35. package/src/__tests__/web.test.tsx +26 -0
  36. package/src/core/client.ts +5 -1
  37. package/src/core/types.ts +16 -0
  38. package/src/native/__tests__/photo-viewer.test.tsx +24 -5
  39. package/src/native/photo-viewer.tsx +109 -422
  40. package/src/native/thread-screen.tsx +14 -5
  41. package/src/native/use-jump.ts +3 -0
  42. package/src/react/index.tsx +2 -1
  43. package/src/web/attachments.tsx +39 -55
  44. package/src/web/composer.tsx +5 -0
  45. package/src/web/dock.tsx +889 -0
  46. package/src/web/inbox.tsx +5 -0
  47. package/src/web/index.ts +23 -0
  48. package/src/web/memory-client.ts +1 -1
  49. package/src/web/thread.tsx +42 -3
  50. package/dist/chunk-GBJ3YI4E.js.map +0 -1
  51. package/dist/chunk-XQ2ULNHV.js.map +0 -1
@@ -5,18 +5,9 @@
5
5
  * form, a lesson) through the `attachment` slot, a generic card by default.
6
6
  * Pending uploads draw from their local previews with a spinner.
7
7
  */
8
- import { useCallback, useState, type ComponentType, type KeyboardEvent } from "react";
9
- import { ChevronLeft, ChevronRight, Download, FileText, Link2, Paperclip } from "lucide-react";
10
- import {
11
- Button,
12
- Dialog,
13
- DialogContent,
14
- DialogDescription,
15
- DialogTitle,
16
- Spinner,
17
- VisuallyHidden,
18
- cn,
19
- } from "@marktiderman/genesis-ui";
8
+ import { useMemo, useState, type ComponentType } from "react";
9
+ import { Download, FileText, Link2, Paperclip } from "lucide-react";
10
+ import { Button, Lightbox as GenesisLightbox, Spinner, cn, type GalleryItem } from "@marktiderman/genesis-ui";
20
11
  import type { ChatAttachment, ChatMessage } from "../core/types";
21
12
  import type { ChatAttachmentKind, ChatCardContext } from "../react/index";
22
13
  import { ChatAttachmentCard, type ChatAttachmentCardProps } from "./cards";
@@ -156,7 +147,7 @@ export function ImageGrid({ images, className }: ImageGridProps) {
156
147
  );
157
148
  })}
158
149
  </div>
159
- <Lightbox images={images} index={open} onIndexChange={setOpen} />
150
+ <ChatLightbox images={images} index={open} onIndexChange={setOpen} />
160
151
  </>
161
152
  );
162
153
  }
@@ -168,53 +159,46 @@ export interface LightboxProps {
168
159
  onIndexChange: (index: number | null) => void;
169
160
  }
170
161
 
171
- /** A photo full size, with the previous and next ones on the arrow keys. */
172
- export function Lightbox({ images, index, onIndexChange }: LightboxProps) {
173
- const img = index === null ? null : images[index];
174
- const go = useCallback(
175
- (delta: number) => {
176
- if (index === null || images.length < 2) return;
177
- onIndexChange((index + delta + images.length) % images.length);
178
- },
179
- [images.length, index, onIndexChange],
162
+ /** A message's photos full size: genesis-ui's `Lightbox` (arrow keys, a counter, focus kept on the arrows), fed chat's attachments. */
163
+ function ChatLightbox({ images, index, onIndexChange }: LightboxProps) {
164
+ // Only photos with a link open: one still uploading has nothing to show full size. `at` maps
165
+ // between the viewer's positions and `images`' indexes.
166
+ const at = useMemo(() => images.flatMap((img, i) => (img.url ? [i] : [])), [images]);
167
+ const items = useMemo<GalleryItem[]>(
168
+ () =>
169
+ at.map((i) => {
170
+ const img = images[i]!;
171
+ return {
172
+ id: img.key,
173
+ src: img.url!,
174
+ alt: img.name ?? "Photo",
175
+ ...(img.width ? { width: img.width } : {}),
176
+ ...(img.height ? { height: img.height } : {}),
177
+ };
178
+ }),
179
+ [images, at],
180
180
  );
181
- const onKey = (e: KeyboardEvent) => {
182
- if (e.key === "ArrowRight") {
183
- e.preventDefault();
184
- go(1);
185
- } else if (e.key === "ArrowLeft") {
186
- e.preventDefault();
187
- go(-1);
188
- }
189
- };
181
+ const shown = index === null ? -1 : at.indexOf(index);
190
182
  return (
191
- <Dialog open={img != null} onOpenChange={(o) => !o && onIndexChange(null)}>
192
- <DialogContent className="max-w-[min(64rem,95vw)] border-0 bg-background p-2" onKeyDown={onKey} data-testid="genesis-chat-lightbox">
193
- <VisuallyHidden>
194
- <DialogTitle>{img?.name ?? "Photo"}</DialogTitle>
195
- <DialogDescription>
196
- Photo {index === null ? 0 : index + 1} of {images.length}. Use the arrow keys for the others.
197
- </DialogDescription>
198
- </VisuallyHidden>
199
- {img?.url ? <img src={img.url} alt={img.name ?? "Photo"} className="mx-auto max-h-[80vh] w-auto rounded-md object-contain" /> : null}
200
- {images.length > 1 ? (
201
- <div className="flex items-center justify-between gap-2">
202
- <Button type="button" variant="ghost" size="icon" onClick={() => go(-1)} aria-label="Previous photo">
203
- <ChevronLeft />
204
- </Button>
205
- <span className="text-sm tabular-nums text-muted-foreground">
206
- {(index ?? 0) + 1} / {images.length}
207
- </span>
208
- <Button type="button" variant="ghost" size="icon" onClick={() => go(1)} aria-label="Next photo">
209
- <ChevronRight />
210
- </Button>
211
- </div>
212
- ) : null}
213
- </DialogContent>
214
- </Dialog>
183
+ <GenesisLightbox
184
+ open={shown !== -1}
185
+ onOpenChange={(open) => !open && onIndexChange(null)}
186
+ items={items}
187
+ index={Math.max(0, shown)}
188
+ onIndexChange={(i) => onIndexChange(at[i] ?? null)}
189
+ labels={{ previous: "Previous photo", next: "Next photo", photo: (n, count) => `Photo ${n} of ${count}` }}
190
+ className="genesis-chat-lightbox"
191
+ />
215
192
  );
216
193
  }
217
194
 
195
+ /**
196
+ * @deprecated Chat's photo grid opens its photos itself. To show photos full size elsewhere, render
197
+ * `Lightbox` from `@marktiderman/genesis-ui` with `GalleryItem`s. This adapter is removed in a
198
+ * later minor.
199
+ */
200
+ export const Lightbox = ChatLightbox;
201
+
218
202
  /** A video: a hosted one (Mux) streams once ready and says "Processing…" until then; a file plays from storage. */
219
203
  export function VideoAttachment({ view }: { view: AttachmentView }) {
220
204
  const a = view.attachment;
@@ -6,6 +6,11 @@
6
6
  * internal notes for observers, voice notes recorded in place, videos from the
7
7
  * camera, emoji, and scheduled send (the arrow beside Send). Where you may not
8
8
  * post it says why instead; when who you are couldn't load, it offers a retry.
9
+ *
10
+ * Moving onto genesis-ui (feature `inbox-thread`): its scrolling, list and composer are the same
11
+ * behaviour as genesis-ui's `ComposerBar`, which were promoted from here. This screen keeps its data
12
+ * wiring (the chat client, realtime, read state) and moves its rendering onto `ComposerBar` with chat's
13
+ * builder; until then fix behaviour in both places.
9
14
  */
10
15
  import {
11
16
  useCallback,