@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 CHANGED
@@ -367,7 +367,12 @@ One message can't break a thread: each row renders inside `ChatErrorBoundary` ("
367
367
  couldn't be shown"), an `attachment` slot that throws falls back to `GenericAttachment`, and an
368
368
  `attachmentKinds` entry is used only for its own key (never `constructor` and the like) when its
369
369
  `title` returns a string; a kind whose functions throw or return the wrong shapes gets the
370
- generic card. Errors go to the console.
370
+ generic card. A row that can't be drawn is reported through `reportError` from
371
+ `@marktiderman/genesis-core/errors` (source `chat:render`), unless you pass `ChatErrorBoundary`
372
+ an `onError`. On native, a card's action that fails and an `attachmentKinds` entry that throws are
373
+ reported the same way (`chat:attachment-action`, `chat:attachment-kind`): the native
374
+ observability block sends them to Sentry; without a reporter they go to the console in
375
+ development.
371
376
 
372
377
  - **Topics**: `ChatThread` shows `ChatTopicBar` (All plus each topic, a lock on closed ones) when
373
378
  the conversation has topics (`showTopics` shows it before the first, for owners). Owners and
@@ -1,5 +1,6 @@
1
1
  import { previewText } from './chunk-A4YJX7KT.js';
2
2
  import { Component } from 'react';
3
+ import { reportError } from '@marktiderman/genesis-core/errors';
3
4
 
4
5
  // src/react/previews.ts
5
6
  var callAttachmentKind = (kind, key, a, ctx) => kind?.[key]?.call(kind, a, ctx);
@@ -40,7 +41,7 @@ var ChatErrorBoundary = class extends Component {
40
41
  }
41
42
  componentDidCatch(error, info) {
42
43
  if (this.props.onError) this.props.onError(error, info);
43
- else console.error("genesis-chat: a message couldn't be drawn", error);
44
+ else reportError(error, "chat:render");
44
45
  }
45
46
  render() {
46
47
  return this.state.failed ? this.props.fallback : this.props.children;
@@ -48,5 +49,5 @@ var ChatErrorBoundary = class extends Component {
48
49
  };
49
50
 
50
51
  export { ChatErrorBoundary, attachmentPreview, callAttachmentKind, cardTitle, messagePreview };
51
- //# sourceMappingURL=chunk-IEFULAC2.js.map
52
- //# sourceMappingURL=chunk-IEFULAC2.js.map
52
+ //# sourceMappingURL=chunk-RYD6WJE5.js.map
53
+ //# sourceMappingURL=chunk-RYD6WJE5.js.map
@@ -0,0 +1 @@
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,KAA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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,WAAA,CAAY,OAAO,aAAa,CAAA;AAAA,EACvC;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-RYD6WJE5.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 * (by default `reportError` from genesis-core, source `chat:render`: the app's crash reporter\n * when it registered one, the console in development) 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\";\nimport { reportError } from \"@marktiderman/genesis-core/errors\";\n\nexport interface ChatErrorBoundaryProps {\n /** Drawn instead of the children once they throw. */\n fallback: ReactNode;\n /** Told about the error. Default `reportError(error, \"chat:render\")` from genesis-core. */\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 reportError(error, \"chat:render\");\n }\n\n override render() {\n return this.state.failed ? this.props.fallback : this.props.children;\n }\n}\n"]}
package/dist/native.js CHANGED
@@ -1,5 +1,5 @@
1
- import { cardTitle, attachmentPreview, callAttachmentKind, ChatErrorBoundary, messagePreview } from './chunk-IEFULAC2.js';
2
- export { attachmentPreview, cardTitle, messagePreview } from './chunk-IEFULAC2.js';
1
+ import { cardTitle, attachmentPreview, callAttachmentKind, ChatErrorBoundary, messagePreview } from './chunk-RYD6WJE5.js';
2
+ export { attachmentPreview, cardTitle, messagePreview } from './chunk-RYD6WJE5.js';
3
3
  import { isHttpsUrl, extractLinks, scheduleLabel, scheduleQuickPicks, isSchedulable, topicKey, snippetParts } from './chunk-BJCE5O7V.js';
4
4
  import { useChat, useInbox, usePeople, chatKeys, useScheduled, useAvailability, useTopics, useConversation, usePins, useMessageActions, useFileUrls, useLinkPreviews, useStartConversation, useBroadcast, useSearch } from './chunk-XQ2ULNHV.js';
5
5
  import { summarizeReactions, parseMentions, startsDay, dayLabel, itemTime, itemSender, startsGroup, activityLine } from './chunk-A4YJX7KT.js';
@@ -10,6 +10,7 @@ import { NativeText, NativeAvatar, NativeImage, NativeIcon, NativeButton, Native
10
10
  import { InboxPage, SettingsSubPage, getThreadPageStackOptions, formatInboxTime } from '@marktiderman/genesis-ui-native/layouts';
11
11
  import { Pressable, Animated, PanResponder, View, Linking, useWindowDimensions, ActivityIndicator, AppState, Modal, AccessibilityInfo, ScrollView, FlatList, TextInput, Platform, KeyboardAvoidingView, Alert } from 'react-native';
12
12
  import { useThemeRoles, useReducedMotion } from '@marktiderman/genesis-ui-native/hooks';
13
+ import { reportError } from '@marktiderman/genesis-core/errors';
13
14
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
14
15
  import { useQueryClient } from '@tanstack/react-query';
15
16
  import { useSafeAreaInsets, SafeAreaView } from 'react-native-safe-area-context';
@@ -330,7 +331,7 @@ function useCardRuns(options) {
330
331
  async (id, task) => {
331
332
  if (busy.current.has(id)) return;
332
333
  const failed = (e, text = failedText) => {
333
- if (typeof __DEV__ !== "undefined" && __DEV__) console.warn("[genesis-chat] an attachment card's action failed:", e);
334
+ reportError(e, "chat:attachment-action");
334
335
  setStates((s) => ({ ...s, [id]: { pending: false, error: text } }));
335
336
  };
336
337
  let result;
@@ -386,7 +387,7 @@ function ChatAttachmentCard({ attachment, message, kind, mine = false, onOpenAtt
386
387
  title = callAttachmentKind(kind, "title", attachment, ctx) ?? "";
387
388
  subtitle = callAttachmentKind(kind, "subtitle", attachment, ctx);
388
389
  } catch (e) {
389
- if (typeof __DEV__ !== "undefined" && __DEV__) console.warn(`[genesis-chat] attachment kind "${attachment.kind}" threw:`, e);
390
+ reportError(e, { source: "chat:attachment-kind", tags: { kind: attachment.kind } });
390
391
  }
391
392
  title = title || attachment.name || attachment.kind;
392
393
  const action = cardAction(kind, attachment, message, onOpenAttachment, ctx);