@marktiderman/genesis-chat 0.3.2 → 0.3.4
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 +6 -1
- package/dist/{chunk-IEFULAC2.js → chunk-RYD6WJE5.js} +4 -3
- package/dist/chunk-RYD6WJE5.js.map +1 -0
- package/dist/native.js +5 -4
- package/dist/native.js.map +1 -1
- package/dist/web.d.ts +3 -2
- package/dist/web.js +2 -2
- package/package.json +9 -9
- package/src/__tests__/review-fixes-web.test.tsx +20 -0
- package/src/native/__tests__/attachment-slot.test.tsx +6 -1
- package/src/native/attachment-cards.tsx +4 -4
- package/src/react/error-boundary.tsx +5 -3
- package/dist/chunk-IEFULAC2.js.map +0 -1
package/dist/web.d.ts
CHANGED
|
@@ -584,14 +584,15 @@ declare function ChatSearch({ resolveUser, conversationId, onOpen, conversationT
|
|
|
584
584
|
* `ChatErrorBoundary`: what one message (or one app attachment card) draws can't take the whole
|
|
585
585
|
* thread down. Messages carry what other people sent, and app renderers get sender-controlled
|
|
586
586
|
* data, so a render that throws shows its fallback instead, and the error goes to `onError`
|
|
587
|
-
* (
|
|
587
|
+
* (by default `reportError` from genesis-core, source `chat:render`: the app's crash reporter
|
|
588
|
+
* when it registered one, the console in development) so it is never silent. `resetKeys` lets it try again once what it
|
|
588
589
|
* draws changes (the app's data arrived).
|
|
589
590
|
*/
|
|
590
591
|
|
|
591
592
|
interface ChatErrorBoundaryProps {
|
|
592
593
|
/** Drawn instead of the children once they throw. */
|
|
593
594
|
fallback: ReactNode;
|
|
594
|
-
/** Told about the error
|
|
595
|
+
/** Told about the error. Default `reportError(error, "chat:render")` from genesis-core. */
|
|
595
596
|
onError?: (error: unknown, info: ErrorInfo) => void;
|
|
596
597
|
/** When any of these changes (by identity), a boundary showing its fallback tries the children again. */
|
|
597
598
|
resetKeys?: readonly unknown[];
|
package/dist/web.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { attachmentPreview, ChatErrorBoundary } from './chunk-
|
|
2
|
-
export { ChatErrorBoundary } from './chunk-
|
|
1
|
+
import { attachmentPreview, ChatErrorBoundary } from './chunk-RYD6WJE5.js';
|
|
2
|
+
export { ChatErrorBoundary } from './chunk-RYD6WJE5.js';
|
|
3
3
|
import { snippetParts, isHttpsUrl, scheduleQuickPicks, isSchedulable, scheduleLabel, extractLinks, topicKey } from './chunk-BJCE5O7V.js';
|
|
4
4
|
import { useChat, useInbox, useSearch, useScheduled, useAvailability, useTopics, useConversation, useMessageActions, usePins, useFileUrls, useLinkPreviews, useBroadcast } from './chunk-XQ2ULNHV.js';
|
|
5
5
|
import { previewText, summarizeReactions, activityLine, itemSender, startsDay, dayLabel, itemTime, startsGroup, parseMentions } from './chunk-A4YJX7KT.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-chat",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -61,13 +61,13 @@
|
|
|
61
61
|
"README.md"
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@marktiderman/genesis-features": "^0.6.
|
|
64
|
+
"@marktiderman/genesis-features": "^0.6.1",
|
|
65
65
|
"frimousse": "0.4.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@marktiderman/genesis-core": "
|
|
69
|
-
"@marktiderman/genesis-ui": "^2.
|
|
70
|
-
"@marktiderman/genesis-ui-native": "
|
|
68
|
+
"@marktiderman/genesis-core": ">=1.17.0 <3.0.0",
|
|
69
|
+
"@marktiderman/genesis-ui": "^2.22.0",
|
|
70
|
+
"@marktiderman/genesis-ui-native": ">=2.9.0 <4.0.0",
|
|
71
71
|
"@supabase/supabase-js": "^2.118.0",
|
|
72
72
|
"@tanstack/react-query": "^5.0.0",
|
|
73
73
|
"hls.js": "^1.5.0",
|
|
@@ -140,10 +140,10 @@
|
|
|
140
140
|
}
|
|
141
141
|
},
|
|
142
142
|
"devDependencies": {
|
|
143
|
-
"@marktiderman/genesis-core": "^
|
|
144
|
-
"@marktiderman/genesis-notifications": "^0.
|
|
145
|
-
"@marktiderman/genesis-ui": "^2.
|
|
146
|
-
"@marktiderman/genesis-ui-native": "^
|
|
143
|
+
"@marktiderman/genesis-core": "^2.0.0",
|
|
144
|
+
"@marktiderman/genesis-notifications": "^0.3.1",
|
|
145
|
+
"@marktiderman/genesis-ui": "^2.22.0",
|
|
146
|
+
"@marktiderman/genesis-ui-native": "^3.0.0",
|
|
147
147
|
"@supabase/supabase-js": "^2.118.0",
|
|
148
148
|
"@tanstack/react-query": "^5.75.0",
|
|
149
149
|
"@testing-library/react": "^16.3.2",
|
|
@@ -9,6 +9,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
9
9
|
import { act, cleanup, configure, fireEvent, render, renderHook, screen, waitFor } from "@testing-library/react";
|
|
10
10
|
import type { ReactNode } from "react";
|
|
11
11
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
12
|
+
import { setErrorReporter } from "@marktiderman/genesis-core/errors";
|
|
12
13
|
import { ChatError } from "../core/client";
|
|
13
14
|
import type { ChatAttachment } from "../core/types";
|
|
14
15
|
import { CATCH_UP_MAX_PAGES, CATCH_UP_PAGE, ChatProvider, chatKeys, useConversation, useLinkPreviews, type ChatProviderProps } from "../react";
|
|
@@ -129,6 +130,25 @@ describe("one bad message can't take the thread down", () => {
|
|
|
129
130
|
expect(screen.getByText("could not draw")).toBeTruthy();
|
|
130
131
|
expect(onError).toHaveBeenCalled();
|
|
131
132
|
});
|
|
133
|
+
|
|
134
|
+
it("ChatErrorBoundary without onError reports through genesis-core's reportError", () => {
|
|
135
|
+
vi.spyOn(console, "error").mockImplementation(() => undefined);
|
|
136
|
+
const reporter = vi.fn();
|
|
137
|
+
const restore = setErrorReporter(reporter);
|
|
138
|
+
const Boom = () => {
|
|
139
|
+
throw new Error("row broke");
|
|
140
|
+
};
|
|
141
|
+
try {
|
|
142
|
+
render(
|
|
143
|
+
<ChatErrorBoundary fallback={<span>could not draw</span>}>
|
|
144
|
+
<Boom />
|
|
145
|
+
</ChatErrorBoundary>,
|
|
146
|
+
);
|
|
147
|
+
} finally {
|
|
148
|
+
restore();
|
|
149
|
+
}
|
|
150
|
+
expect(reporter).toHaveBeenCalledWith(expect.objectContaining({ message: "row broke" }), { source: "chat:render" });
|
|
151
|
+
});
|
|
132
152
|
});
|
|
133
153
|
|
|
134
154
|
describe("catch-up after a long time away", () => {
|
|
@@ -4,6 +4,7 @@ import { act, cleanup, fireEvent, render, screen } from "@testing-library/react"
|
|
|
4
4
|
import { createElement, useLayoutEffect, type ReactNode } from "react";
|
|
5
5
|
import { Pressable, Text, View } from "react-native";
|
|
6
6
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { setErrorReporter } from "@marktiderman/genesis-core/errors";
|
|
7
8
|
import type { ChatAttachment, ChatMessage } from "../../core/types";
|
|
8
9
|
import type { ChatAttachmentKind } from "../../react/index";
|
|
9
10
|
import { attachmentPreview, slotUrl, splitCardAttachments, type ChatAttachmentSlotProps } from "../attachment-cards";
|
|
@@ -127,7 +128,8 @@ describe("the attachment slot", () => {
|
|
|
127
128
|
it("shows pending while an async action runs, then an error when it rejects", async () => {
|
|
128
129
|
let reject!: (e: Error) => void;
|
|
129
130
|
const toggle = vi.fn(() => new Promise((_, r) => (reject = r)));
|
|
130
|
-
vi.
|
|
131
|
+
const reporter = vi.fn();
|
|
132
|
+
const restore = setErrorReporter(reporter);
|
|
131
133
|
const task = attachment({ ref: { title: "Journal" } });
|
|
132
134
|
render(<MessageBubble row={row(message({ attachments: [task] }))} me={ME} urls={{}} group={false} reducedMotion attachmentKinds={{ task: taskKind({ done: false }, toggle) }} attachmentSlot={TaskCard} testID="b" />);
|
|
133
135
|
fireEvent.click(screen.getByTestId("b-card-0-check"));
|
|
@@ -138,6 +140,9 @@ describe("the attachment slot", () => {
|
|
|
138
140
|
expect(toggle).toHaveBeenCalledTimes(1);
|
|
139
141
|
await act(async () => reject(new Error("offline")));
|
|
140
142
|
expect(screen.getByTestId("b-card-0-slot-error").textContent).toBe(chatNativeCopy.cardActionFailed);
|
|
143
|
+
// Reported through genesis-core's seam (the app's crash reporter), not only the console.
|
|
144
|
+
expect(reporter).toHaveBeenCalledWith(expect.objectContaining({ message: "offline" }), { source: "chat:attachment-action" });
|
|
145
|
+
restore();
|
|
141
146
|
expect(screen.getByTestId("b-bubble").getAttribute("aria-label")).toContain(chatNativeCopy.cardActionFailed);
|
|
142
147
|
expect(screen.getByTestId("b-card-0-check").getAttribute("aria-busy")).toBe("false");
|
|
143
148
|
});
|
|
@@ -21,6 +21,7 @@ import { useCallback, useLayoutEffect, useRef, useState, type ComponentType, typ
|
|
|
21
21
|
import { Linking, View } from "react-native";
|
|
22
22
|
import { NativeButton, NativeIcon, NativeText } from "@marktiderman/genesis-ui-native/components";
|
|
23
23
|
import { useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
|
|
24
|
+
import { reportError } from "@marktiderman/genesis-core/errors";
|
|
24
25
|
import type { ChatAttachment, ChatMessage } from "../core/types";
|
|
25
26
|
import type { ChatAttachmentKind, ChatCardContext } from "../react/index";
|
|
26
27
|
import { attachmentPreview, callAttachmentKind as call, cardTitle, messagePreview } from "../react/previews";
|
|
@@ -126,7 +127,7 @@ export function useCardRuns(options: CardRunOptions | string): { stateOf(id: str
|
|
|
126
127
|
async (id: string, task: () => unknown) => {
|
|
127
128
|
if (busy.current.has(id)) return;
|
|
128
129
|
const failed = (e: unknown, text = failedText) => {
|
|
129
|
-
|
|
130
|
+
reportError(e, "chat:attachment-action");
|
|
130
131
|
setStates((s) => ({ ...s, [id]: { pending: false, error: text } }));
|
|
131
132
|
};
|
|
132
133
|
let result: unknown;
|
|
@@ -237,8 +238,8 @@ export function ChatAttachmentCard({ attachment, message, kind, mine = false, on
|
|
|
237
238
|
title = call(kind, "title", attachment, ctx) ?? "";
|
|
238
239
|
subtitle = call(kind, "subtitle", attachment, ctx);
|
|
239
240
|
} catch (e) {
|
|
240
|
-
// An app's kind that throws shows as a plain card, and
|
|
241
|
-
|
|
241
|
+
// An app's kind that throws shows as a plain card, and is reported (the kind is the app's name for it, not content).
|
|
242
|
+
reportError(e, { source: "chat:attachment-kind", tags: { kind: attachment.kind } });
|
|
242
243
|
}
|
|
243
244
|
title = title || attachment.name || attachment.kind;
|
|
244
245
|
const action = cardAction(kind, attachment, message, onOpenAttachment, ctx);
|
|
@@ -367,4 +368,3 @@ function Reported({ id, empty, onEmpty, children }: { id: string; empty: boolean
|
|
|
367
368
|
return <>{children}</>;
|
|
368
369
|
}
|
|
369
370
|
|
|
370
|
-
declare const __DEV__: boolean | undefined;
|
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
* `ChatErrorBoundary`: what one message (or one app attachment card) draws can't take the whole
|
|
4
4
|
* thread down. Messages carry what other people sent, and app renderers get sender-controlled
|
|
5
5
|
* data, so a render that throws shows its fallback instead, and the error goes to `onError`
|
|
6
|
-
* (
|
|
6
|
+
* (by default `reportError` from genesis-core, source `chat:render`: the app's crash reporter
|
|
7
|
+
* when it registered one, the console in development) so it is never silent. `resetKeys` lets it try again once what it
|
|
7
8
|
* draws changes (the app's data arrived).
|
|
8
9
|
*/
|
|
9
10
|
import { Component, type ErrorInfo, type ReactNode } from "react";
|
|
11
|
+
import { reportError } from "@marktiderman/genesis-core/errors";
|
|
10
12
|
|
|
11
13
|
export interface ChatErrorBoundaryProps {
|
|
12
14
|
/** Drawn instead of the children once they throw. */
|
|
13
15
|
fallback: ReactNode;
|
|
14
|
-
/** Told about the error
|
|
16
|
+
/** Told about the error. Default `reportError(error, "chat:render")` from genesis-core. */
|
|
15
17
|
onError?: (error: unknown, info: ErrorInfo) => void;
|
|
16
18
|
/** When any of these changes (by identity), a boundary showing its fallback tries the children again. */
|
|
17
19
|
resetKeys?: readonly unknown[];
|
|
@@ -37,7 +39,7 @@ export class ChatErrorBoundary extends Component<ChatErrorBoundaryProps, { faile
|
|
|
37
39
|
|
|
38
40
|
override componentDidCatch(error: unknown, info: ErrorInfo) {
|
|
39
41
|
if (this.props.onError) this.props.onError(error, info);
|
|
40
|
-
else
|
|
42
|
+
else reportError(error, "chat:render");
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
override render() {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/previews.ts","../src/react/error-boundary.tsx"],"names":[],"mappings":";;;;AAWO,IAAM,kBAAA,GAAqB,CAA4C,IAAA,EAAsC,GAAA,EAAQ,CAAA,EAAmB,GAAA,KAC5I,IAAA,GAAO,GAAG,CAAA,EAAoG,IAAA,CAAK,IAAA,EAAO,CAAA,EAAG,GAAG;AAK5H,SAAS,UAAU,IAAA,EAAsC,CAAA,EAAmB,MAAuB,EAAE,IAAA,EAAM,OAAM,EAAW;AACjI,EAAA,IAAI;AACF,IAAA,OAAO,kBAAA,CAAmB,MAAM,OAAA,EAAS,CAAA,EAAG,GAAG,CAAA,IAAK,CAAA,CAAE,QAAQ,CAAA,CAAE,IAAA;AAAA,EAClE,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,CAAA,CAAE,QAAQ,CAAA,CAAE,IAAA;AAAA,EACrB;AACF;AAGA,SAAS,eAAe,IAAA,EAA8B;AACpD,EAAA,OAAO,EAAE,IAAI,EAAA,EAAI,SAAA,EAAW,IAAI,QAAA,EAAU,CAAA,EAAG,MAAM,GAAA,EAAK,IAAI,QAAA,EAAU,MAAA,EAAQ,MAAM,IAAA,EAAM,UAAA,EAAY,MAAM,UAAA,EAAY,IAAA,EAAM,KAAK,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAM,IAAA,EAAM,MAAM,IAAA,EAAM,KAAA,EAAO,MAAM,KAAA,EAAO,IAAA,EAAM,QAAQ,IAAA,EAAM,UAAA,EAAY,MAAM,QAAA,EAAU,IAAA,EAAM,YAAY,IAAA,EAAM,SAAA,EAAW,MAAM,UAAA,EAAY,IAAA,EAAM,kBAAkB,IAAA,EAAK;AAC1U;AAOO,SAAS,iBAAA,CAAkB,IAAA,EAAc,UAAA,EAAwD,KAAA,EAAuD,UAAU,KAAA,EAAe;AACtL,EAAA,MAAM,IAAA,GAAO,OAAO,UAAA,KAAe,QAAA,GAAW,aAAa,UAAA,EAAY,IAAA;AACvE,EAAA,MAAM,IAAA,GAAO,WAAA,CAAY,IAAA,EAAM,IAAA,EAAM,OAAO,CAAA;AAE5C,EAAA,IAAI,WAAW,CAAC,IAAA,IAAQ,CAAC,KAAA,IAAS,CAAC,MAAA,CAAO,SAAA,CAAU,cAAA,CAAe,IAAA,CAAK,OAAO,IAAI,CAAA,IAAK,YAAY,IAAA,EAAM,IAAI,GAAG,OAAO,IAAA;AACxH,EAAA,MAAM,IAAI,OAAO,UAAA,KAAe,QAAA,GAAW,cAAA,CAAe,UAAU,CAAA,GAAI,UAAA;AACxE,EAAA,MAAM,CAAA,GAAI,MAAM,IAAI,CAAA;AACpB,EAAA,MAAM,KAAA,GAAQ,OAAO,CAAA,EAAG,KAAA,KAAU,YAAY,CAAA,CAAE,KAAA,CAAM,IAAA,EAAK,GAAI,EAAE,KAAA,CAAM,IAAA,EAAK,GAAI,SAAA,CAAU,GAAG,CAAC,CAAA;AAC9F,EAAA,OAAO,KAAA,IAAS,KAAA,KAAU,IAAA,GAAO,KAAA,GAAQ,IAAA;AAC3C;AAGO,SAAS,cAAA,CAAe,SAAsB,KAAA,EAA+D;AAClH,EAAA,OAAO,iBAAA,CAAkB,OAAA,CAAQ,IAAA,EAAM,OAAA,CAAQ,WAAA,CAAY,CAAC,CAAA,EAAG,KAAA,EAAO,OAAA,CAAQ,OAAA,CAAQ,SAAS,CAAC,CAAA;AAClG;AC7BA,SAAS,OAAA,CAAQ,GAAmC,CAAA,EAA4C;AAC9F,EAAA,IAAI,CAAA,KAAM,GAAG,OAAO,KAAA;AACpB,EAAA,IAAI,CAAC,KAAK,CAAC,CAAA,IAAK,EAAE,MAAA,KAAW,CAAA,CAAE,QAAQ,OAAO,IAAA;AAC9C,EAAA,OAAO,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM,CAAC,MAAA,CAAO,EAAA,CAAG,CAAA,EAAG,CAAA,CAAE,CAAC,CAAC,CAAC,CAAA;AAC7C;AAEO,IAAM,iBAAA,GAAN,cAAgC,SAAA,CAAuD;AAAA,EACnF,KAAA,GAAQ,EAAE,MAAA,EAAQ,KAAA,EAAM;AAAA,EAEjC,OAAO,wBAAA,GAAgD;AACrD,IAAA,OAAO,EAAE,QAAQ,IAAA,EAAK;AAAA,EACxB;AAAA,EAES,mBAAmB,IAAA,EAA8B;AACxD,IAAA,IAAI,IAAA,CAAK,KAAA,CAAM,MAAA,IAAU,OAAA,CAAQ,KAAK,SAAA,EAAW,IAAA,CAAK,KAAA,CAAM,SAAS,GAAG,IAAA,CAAK,QAAA,CAAS,EAAE,MAAA,EAAQ,OAAO,CAAA;AAAA,EACzG;AAAA,EAES,iBAAA,CAAkB,OAAgB,IAAA,EAAiB;AAC1D,IAAA,IAAI,KAAK,KAAA,CAAM,OAAA,OAAc,KAAA,CAAM,OAAA,CAAQ,OAAO,IAAI,CAAA;AAAA,SACjD,OAAA,CAAQ,KAAA,CAAM,2CAAA,EAA6C,KAAK,CAAA;AAAA,EACvE;AAAA,EAES,MAAA,GAAS;AAChB,IAAA,OAAO,KAAK,KAAA,CAAM,MAAA,GAAS,KAAK,KAAA,CAAM,QAAA,GAAW,KAAK,KAAA,CAAM,QAAA;AAAA,EAC9D;AACF","file":"chunk-IEFULAC2.js","sourcesContent":["/**\n * @feat:chat\n * One-line previews of a message (the inbox, the long-press sheet) where an app attachment kind\n * reads as its `label`, else its title (\"Check-in\"), not \"Attachment\". No React or DOM: web and\n * native both draw from it.\n */\nimport { previewText } from \"../core/thread\";\nimport type { ChatAttachment, ChatMessage } from \"../core/types\";\nimport type { ChatAttachmentKind, ChatCardContext } from \"./index\";\n\n/** Calls a kind's `title`, `subtitle` or `action` with the card context. */\nexport const callAttachmentKind = <K extends \"title\" | \"subtitle\" | \"action\">(kind: ChatAttachmentKind | undefined, key: K, a: ChatAttachment, ctx: ChatCardContext) =>\n (kind?.[key] as ((this: ChatAttachmentKind, a: ChatAttachment, ctx: ChatCardContext) => unknown) | undefined)?.call(kind!, a, ctx) as\n | ReturnType<NonNullable<ChatAttachmentKind[K]>>\n | undefined;\n\n/** A card's title (the kind's, else the file's name, else the kind); an app kind that throws reads as its name. */\nexport function cardTitle(kind: ChatAttachmentKind | undefined, a: ChatAttachment, ctx: ChatCardContext = { mine: false }): string {\n try {\n return callAttachmentKind(kind, \"title\", a, ctx) || a.name || a.kind;\n } catch {\n return a.name || a.kind;\n }\n}\n\n/** An attachment with only its kind, for a preview that knows no more (the inbox's last message). */\nfunction bareAttachment(kind: string): ChatAttachment {\n return { id: \"\", messageId: \"\", position: 0, kind, ref: {}, provider: \"none\", path: null, providerId: null, playbackId: null, url: null, status: \"ready\", name: null, mime: null, bytes: null, width: null, height: null, durationMs: null, waveform: null, posterPath: null, thumbhash: null, transcript: null, transcriptStatus: null };\n}\n\n/**\n * A message's one-line preview: its text, else what it carries, where an app kind reads as its\n * title (\"Check-in\") instead of \"Attachment\". `attachment` is the kind alone (the inbox) or the\n * attachment itself.\n */\nexport function attachmentPreview(body: string, attachment: string | ChatAttachment | null | undefined, kinds: Record<string, ChatAttachmentKind> | undefined, deleted = false): string {\n const kind = typeof attachment === \"string\" ? attachment : attachment?.kind;\n const text = previewText(body, kind, deleted);\n // Text that reads as something (not only markdown marks) is the preview, as previewText has it.\n if (deleted || !kind || !kinds || !Object.prototype.hasOwnProperty.call(kinds, kind) || previewText(body, null)) return text;\n const a = typeof attachment === \"string\" ? bareAttachment(attachment) : attachment!;\n const k = kinds[kind];\n const title = typeof k?.label === \"string\" && k.label.trim() ? k.label.trim() : cardTitle(k, a);\n return title && title !== kind ? title : text;\n}\n\n/** The long-press sheet's caption for a message. */\nexport function messagePreview(message: ChatMessage, kinds: Record<string, ChatAttachmentKind> | undefined): string {\n return attachmentPreview(message.body, message.attachments[0], kinds, Boolean(message.deletedAt));\n}\n\n","/**\n * @feat:chat\n * `ChatErrorBoundary`: what one message (or one app attachment card) draws can't take the whole\n * thread down. Messages carry what other people sent, and app renderers get sender-controlled\n * data, so a render that throws shows its fallback instead, and the error goes to `onError`\n * (console.error by default) so it is never silent. `resetKeys` lets it try again once what it\n * draws changes (the app's data arrived).\n */\nimport { Component, type ErrorInfo, type ReactNode } from \"react\";\n\nexport interface ChatErrorBoundaryProps {\n /** Drawn instead of the children once they throw. */\n fallback: ReactNode;\n /** Told about the error; console.error by default. */\n onError?: (error: unknown, info: ErrorInfo) => void;\n /** When any of these changes (by identity), a boundary showing its fallback tries the children again. */\n resetKeys?: readonly unknown[];\n children: ReactNode;\n}\n\nfunction changed(a: readonly unknown[] | undefined, b: readonly unknown[] | undefined): boolean {\n if (a === b) return false;\n if (!a || !b || a.length !== b.length) return true;\n return a.some((v, i) => !Object.is(v, b[i]));\n}\n\nexport class ChatErrorBoundary extends Component<ChatErrorBoundaryProps, { failed: boolean }> {\n override state = { failed: false };\n\n static getDerivedStateFromError(): { failed: boolean } {\n return { failed: true };\n }\n\n override componentDidUpdate(prev: ChatErrorBoundaryProps) {\n if (this.state.failed && changed(prev.resetKeys, this.props.resetKeys)) this.setState({ failed: false });\n }\n\n override componentDidCatch(error: unknown, info: ErrorInfo) {\n if (this.props.onError) this.props.onError(error, info);\n else console.error(\"genesis-chat: a message couldn't be drawn\", error);\n }\n\n override render() {\n return this.state.failed ? this.props.fallback : this.props.children;\n }\n}\n"]}
|