@marktiderman/genesis-chat 0.6.1 → 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.
- package/README.md +132 -3
- package/dist/{chunk-GBJ3YI4E.js → chunk-5XYDVUPS.js} +6 -3
- package/dist/chunk-5XYDVUPS.js.map +1 -0
- package/dist/{chunk-XQ2ULNHV.js → chunk-D4RPOYB7.js} +4 -4
- package/dist/chunk-D4RPOYB7.js.map +1 -0
- package/dist/{chunk-RYD6WJE5.js → chunk-O2QSBRSH.js} +3 -3
- package/dist/{chunk-RYD6WJE5.js.map → chunk-O2QSBRSH.js.map} +1 -1
- package/dist/{chunk-A4YJX7KT.js → chunk-ZQFREERR.js} +3 -3
- package/dist/{chunk-A4YJX7KT.js.map → chunk-ZQFREERR.js.map} +1 -1
- package/dist/{client-DUIG1hum.d.ts → client-DP7rhJ1U.d.ts} +17 -6
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/native.d.ts +31 -15
- package/dist/native.js +74 -328
- package/dist/native.js.map +1 -1
- package/dist/{outbox-B9NAWQ58.d.ts → outbox-C4LnqpKT.d.ts} +1 -1
- package/dist/push.d.ts +2 -2
- package/dist/react.d.ts +4 -8
- package/dist/react.js +3 -3
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/{thread-oPra7pkW.d.ts → thread-CSzdqNR_.d.ts} +1 -1
- package/dist/web.d.ts +205 -8
- package/dist/web.js +582 -71
- package/dist/web.js.map +1 -1
- package/migrations/0004_genesis_chat_tenants.sql +716 -0
- package/migrations/tests/0001_genesis_chat.test.sql +10 -2
- package/migrations/tests/0002_genesis_chat_coaching.test.sql +8 -0
- package/migrations/tests/0003_genesis_chat_search_threads.test.sql +8 -0
- package/migrations/tests/0004_genesis_chat_tenants.test.sql +259 -0
- package/package.json +19 -8
- package/src/__tests__/core.test.ts +12 -0
- package/src/__tests__/web-dock.test.tsx +465 -0
- package/src/__tests__/web-format.test.ts +28 -0
- package/src/__tests__/web-photo-viewer.test.tsx +43 -0
- package/src/__tests__/web.test.tsx +26 -0
- package/src/core/client.ts +5 -1
- package/src/core/types.ts +16 -0
- package/src/native/__tests__/photo-viewer.test.tsx +24 -5
- package/src/native/photo-viewer.tsx +109 -422
- package/src/native/thread-screen.tsx +14 -5
- package/src/native/use-jump.ts +3 -0
- package/src/react/index.tsx +2 -1
- package/src/web/attachments.tsx +39 -55
- package/src/web/composer.tsx +5 -0
- package/src/web/dock.tsx +889 -0
- package/src/web/format.ts +6 -15
- package/src/web/inbox.tsx +5 -0
- package/src/web/index.ts +23 -0
- package/src/web/memory-client.ts +1 -1
- package/src/web/thread.tsx +42 -3
- package/dist/chunk-GBJ3YI4E.js.map +0 -1
- package/dist/chunk-XQ2ULNHV.js.map +0 -1
|
@@ -51,7 +51,7 @@ import { attachmentPaths } from "./media";
|
|
|
51
51
|
import { ChatPhotoViewer, galleryFor, type ChatPhoto } from "./photo-viewer";
|
|
52
52
|
import { MessageActionsSheet } from "./message-actions-sheet";
|
|
53
53
|
import { displayBody, MessageBubble } from "./message-bubble";
|
|
54
|
-
import { haptic } from "./modules";
|
|
54
|
+
import { haptic, type KeyboardAvoidingLike } from "./modules";
|
|
55
55
|
import { pauseChatPlayback } from "./voice-player";
|
|
56
56
|
import { buildThreadRows, type ThreadRow } from "./rows";
|
|
57
57
|
|
|
@@ -127,7 +127,10 @@ interface ChatListProps {
|
|
|
127
127
|
testID?: string;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* Points from the bottom that still count as "at the bottom" (FlatList, which follows by hand).
|
|
132
|
+
* @deprecated Promoted to genesis-ui-native as `THREAD_AT_BOTTOM_POINTS`. ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
|
|
133
|
+
*/
|
|
131
134
|
export const AT_BOTTOM_POINTS = 120;
|
|
132
135
|
|
|
133
136
|
/**
|
|
@@ -136,6 +139,7 @@ export const AT_BOTTOM_POINTS = 120;
|
|
|
136
139
|
* a screen of it, keeps the first visible row in place when earlier ones load
|
|
137
140
|
* at the top). FlatList: keeps its place when earlier rows load at the top;
|
|
138
141
|
* the screen follows new rows itself (`followsByHand`).
|
|
142
|
+
* @deprecated Promoted to genesis-ui-native as `threadListMode` (which anchors FlatList past the header, `minIndexForVisible: 1`). ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
|
|
139
143
|
*/
|
|
140
144
|
export function threadListMode(flash: boolean, reducedMotion: boolean): { followsByHand: boolean; maintainVisibleContentPosition: Record<string, unknown> } {
|
|
141
145
|
if (flash) {
|
|
@@ -147,7 +151,10 @@ export function threadListMode(flash: boolean, reducedMotion: boolean): { follow
|
|
|
147
151
|
return { followsByHand: true, maintainVisibleContentPosition: { minIndexForVisible: 0 } };
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
/**
|
|
154
|
+
/**
|
|
155
|
+
* Whether a scroll position is at (or near) the bottom of its content.
|
|
156
|
+
* @deprecated Promoted to genesis-ui-native as `threadNearBottom`. ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
|
|
157
|
+
*/
|
|
151
158
|
export function nearBottom(m: { contentOffset: { y: number }; contentSize: { height: number }; layoutMeasurement: { height: number } }, slack = AT_BOTTOM_POINTS): boolean {
|
|
152
159
|
return m.contentOffset.y + m.layoutMeasurement.height >= m.contentSize.height - slack;
|
|
153
160
|
}
|
|
@@ -470,9 +477,11 @@ export function ChatThreadScreen(props: ChatThreadScreenProps) {
|
|
|
470
477
|
setRetryingAccess(true);
|
|
471
478
|
void Promise.resolve(refetchAccess()).finally(() => setRetryingAccess(false));
|
|
472
479
|
}, [refetchAccess]);
|
|
473
|
-
|
|
480
|
+
// Chat's own module, else the one the app gave Genesis (so it's passed once).
|
|
481
|
+
const keyboardModule = modules.keyboardAvoidingView ?? (genesis as { keyboardAvoidingView?: KeyboardAvoidingLike }).keyboardAvoidingView;
|
|
482
|
+
const KeyboardAvoiding = (keyboardModule ?? KeyboardAvoidingView) as ComponentType<Record<string, unknown>>;
|
|
474
483
|
const offset = keyboardVerticalOffset ?? measuredTop;
|
|
475
|
-
const keyboardProps =
|
|
484
|
+
const keyboardProps = keyboardModule
|
|
476
485
|
? { behavior: "translate-with-padding", keyboardVerticalOffset: offset }
|
|
477
486
|
: { behavior: Platform.OS === "ios" ? "padding" : undefined, keyboardVerticalOffset: offset };
|
|
478
487
|
|
package/src/native/use-jump.ts
CHANGED
|
@@ -38,6 +38,9 @@ export interface UseJumpOptions {
|
|
|
38
38
|
|
|
39
39
|
type Pending = JumpTarget & { phase: "new" | "loading" | "loaded" };
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Promoted to genesis-ui-native as `useThreadJump`. ChatThreadScreen moves onto NativeThreadList with its builder (feature `inbox-thread`); this copy is removed then.
|
|
43
|
+
*/
|
|
41
44
|
export function useJumpToMessage({ target, rows, loading, has, loadUntil, scrollTo, onStart, onLanded, onGone, onError }: UseJumpOptions) {
|
|
42
45
|
const [pending, setPending] = useState<Pending | null>(target ? { ...target, phase: "new" } : null);
|
|
43
46
|
const [highlightedId, setHighlightedId] = useState<string | null>(null);
|
package/src/react/index.tsx
CHANGED
|
@@ -33,6 +33,7 @@ import type {
|
|
|
33
33
|
ScheduleInput,
|
|
34
34
|
ScheduledMessage,
|
|
35
35
|
SendInput,
|
|
36
|
+
StartConversationOptions,
|
|
36
37
|
TopicInput,
|
|
37
38
|
} from "../core/types";
|
|
38
39
|
|
|
@@ -668,7 +669,7 @@ export function useStartConversation() {
|
|
|
668
669
|
const { client } = useChat();
|
|
669
670
|
const queryClient = useQueryClient();
|
|
670
671
|
return useCallback(
|
|
671
|
-
async (kind: string, memberIds: string[], opts?:
|
|
672
|
+
async (kind: string, memberIds: string[], opts?: StartConversationOptions) => {
|
|
672
673
|
const id = await client.startConversation(kind, memberIds, opts);
|
|
673
674
|
void queryClient.invalidateQueries({ queryKey: ["genesis-chat", "inbox"] });
|
|
674
675
|
return id;
|
package/src/web/attachments.tsx
CHANGED
|
@@ -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 {
|
|
9
|
-
import {
|
|
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
|
-
<
|
|
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
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
|
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
|
-
<
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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;
|
package/src/web/composer.tsx
CHANGED
|
@@ -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,
|