@poolse/react-ui 3.7.1 → 3.9.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/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  'use client';
2
2
  import { forwardRef, useState, useId, useReducer, useRef, useEffect, useImperativeHandle, useCallback, useMemo, createContext, Fragment as Fragment$1, useLayoutEffect, useContext } from 'react';
3
3
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
4
- import { usePoolse, useMembers, useUser, useMe, useConversations, useAttachmentUpload, useConversation, usePresence, useUserPresence, useMessages, useTyping, useMessageStreams, useRealtimeStatus, isMessageVisibleTo, receiptsOf, computeGroupPosition, sameDay, formatDayLabel, useLiveCall, canEditOwnMessage, callLogDisplayFor, useThread, usePresenceMany, formatCallLogPreview, useReactions, useAttachmentUrl, ApiError } from '@poolse/react';
4
+ import { safeUuid, MessageQueuedError } from '@poolse/sdk';
5
+ import { usePoolse, useMembers, useUser, useMe, useConversations, useAttachmentUpload, filterConversations, useConversation, usePresence, useUserPresence, useMessages, useTyping, useMessageStreams, useRealtimeStatus, isMessageVisibleTo, receiptsOf, computeGroupPosition, sameDay, formatDayLabel, canEditOwnMessage, useLiveCall, recordingNoticeDisplayFor, callLogDisplayFor, useThread, usePresenceMany, formatCallLogPreview, formatRecordingNoticePreview, ApiError, useReactions, useAttachmentUrl, captureLabel, useRecording, captureErrorMessage, useLiveTranscript, groupTranscript, formatCallDuration, useTranscript, findInText } from '@poolse/react';
5
6
  import ReactMarkdown from 'react-markdown';
6
7
  import remarkGfm from 'remark-gfm';
7
8
  import { resolveTheme, tokensToCssVariables } from '@poolse/theme';
@@ -604,7 +605,7 @@ function CallControlButton({
604
605
  label,
605
606
  onClick,
606
607
  active = false,
607
- highlight = false,
608
+ highlight: highlight2 = false,
608
609
  tone = "neutral",
609
610
  large = false,
610
611
  disabled = false,
@@ -615,7 +616,7 @@ function CallControlButton({
615
616
  "callbtn",
616
617
  tone !== "neutral" ? `callbtn--${tone}` : "",
617
618
  active ? "callbtn--active" : "",
618
- highlight ? "callbtn--highlight" : "",
619
+ highlight2 ? "callbtn--highlight" : "",
619
620
  large ? "callbtn--large" : ""
620
621
  ].filter(Boolean).join(" ");
621
622
  return /* @__PURE__ */ jsxs("span", { className: "callbtn__slot", children: [
@@ -631,7 +632,7 @@ function CallControlButton({
631
632
  className: classes,
632
633
  onClick,
633
634
  disabled,
634
- "aria-pressed": tone === "neutral" ? active || highlight : void 0,
635
+ "aria-pressed": tone === "neutral" ? active || highlight2 : void 0,
635
636
  "aria-label": label,
636
637
  title: label,
637
638
  children: /* @__PURE__ */ jsx(PoolseIcon, { name: icon, size: large ? 26 : 22, label: null })
@@ -769,47 +770,133 @@ var localDraftStorage = {
769
770
  }
770
771
  }
771
772
  };
772
- var memory = /* @__PURE__ */ new Map();
773
773
  function draftKey(userId, conversationId) {
774
774
  return `poolse:draft:${userId}:${conversationId}`;
775
775
  }
776
776
  var isEmpty = (d) => d.text.trim() === "" && !d.replyTo;
777
- function readDraft(storage, key) {
778
- const held = memory.get(key);
779
- if (held) return held;
780
- let raw;
781
- try {
782
- raw = storage.get(key);
783
- } catch {
784
- return null;
777
+ var DraftScope = class {
778
+ constructor(namespace) {
779
+ this.namespace = namespace;
785
780
  }
786
- const hold = (d) => {
787
- if (d && !memory.has(key)) memory.set(key, d);
788
- return memory.get(key) ?? d;
789
- };
790
- if (raw instanceof Promise)
791
- return raw.then(
792
- (r) => hold(parse(r)),
793
- () => null
794
- );
795
- return hold(parse(raw));
796
- }
797
- function writeDraft(storage, key, draft) {
798
- if (isEmpty(draft)) {
799
- clearDraft(storage, key);
800
- return;
781
+ namespace;
782
+ memory = /* @__PURE__ */ new Map();
783
+ /** Storages written to, and the keys written to each. */
784
+ written = /* @__PURE__ */ new Map();
785
+ /** The storage key for a conversation's draft; null until the namespace is known. */
786
+ key(conversationId) {
787
+ const ns = this.namespace();
788
+ return ns ? `${ns}:draft:${conversationId}` : null;
789
+ }
790
+ /** The draft for `key`: from memory, else from `storage` (else from `legacyKey`, moved over). */
791
+ read(storage, key, legacyKey) {
792
+ const held = this.memory.get(key);
793
+ if (held) return held;
794
+ const hold = (d) => {
795
+ if (d && !this.memory.has(key)) this.memory.set(key, d);
796
+ return this.memory.get(key) ?? d;
797
+ };
798
+ const fromLegacy = () => {
799
+ if (!legacyKey) return null;
800
+ const old = safeGet(storage, legacyKey);
801
+ const move = (raw2) => {
802
+ const d = parse(raw2);
803
+ if (!d) return null;
804
+ this.write(storage, key, d);
805
+ swallow(() => storage.remove(legacyKey));
806
+ return hold(d);
807
+ };
808
+ return old instanceof Promise ? old.then(move, () => null) : move(old);
809
+ };
810
+ const raw = safeGet(storage, key);
811
+ const take = (r) => {
812
+ const d = parse(r);
813
+ return d ? hold(d) : fromLegacy();
814
+ };
815
+ return raw instanceof Promise ? raw.then(take, () => null) : take(raw);
816
+ }
817
+ /** Save (or, when empty, drop) the draft for `key`. */
818
+ write(storage, key, draft) {
819
+ if (isEmpty(draft)) {
820
+ this.clear(storage, key);
821
+ return;
822
+ }
823
+ this.memory.set(key, draft);
824
+ this.track(storage, key);
825
+ const value = JSON.stringify({ v: 1, text: draft.text, replyTo: draft.replyTo });
826
+ swallow(() => storage.set(key, value));
827
+ }
828
+ clear(storage, key) {
829
+ this.memory.delete(key);
830
+ swallow(() => storage.remove(key));
831
+ }
832
+ /** Called by `chat.destroy()`. @internal */
833
+ async destroy(opts) {
834
+ this.memory.clear();
835
+ if (!opts.clearStorage) return;
836
+ const ns = this.namespace();
837
+ const storages = /* @__PURE__ */ new Set([...this.written.keys(), localDraftStorage]);
838
+ for (const storage of storages) {
839
+ const keys = new Set(this.written.get(storage) ?? []);
840
+ if (ns) {
841
+ try {
842
+ const raw = await storage.get(indexKey(ns));
843
+ const listed = raw ? JSON.parse(raw) : [];
844
+ if (Array.isArray(listed)) {
845
+ for (const k of listed) if (typeof k === "string") keys.add(k);
846
+ }
847
+ } catch {
848
+ }
849
+ swallow(() => storage.remove(indexKey(ns)));
850
+ }
851
+ for (const k of keys) swallow(() => storage.remove(k));
852
+ }
853
+ this.written.clear();
801
854
  }
802
- memory.set(key, draft);
803
- const value = JSON.stringify({ v: 1, text: draft.text, replyTo: draft.replyTo });
855
+ // Remember the key in an index entry, so a sign-out finds drafts
856
+ // written in earlier sessions too.
857
+ track(storage, key) {
858
+ let keys = this.written.get(storage);
859
+ if (!keys) {
860
+ keys = /* @__PURE__ */ new Set();
861
+ this.written.set(storage, keys);
862
+ }
863
+ if (keys.has(key)) return;
864
+ keys.add(key);
865
+ const ns = this.namespace();
866
+ if (!ns) return;
867
+ const all = keys;
868
+ const merge = (raw2) => {
869
+ let listed = [];
870
+ try {
871
+ const v = raw2 ? JSON.parse(raw2) : [];
872
+ if (Array.isArray(v)) listed = v.filter((k) => typeof k === "string");
873
+ } catch {
874
+ }
875
+ const next = [.../* @__PURE__ */ new Set([...listed, ...all])];
876
+ swallow(() => storage.set(indexKey(ns), JSON.stringify(next)));
877
+ };
878
+ const raw = safeGet(storage, indexKey(ns));
879
+ if (raw instanceof Promise) void raw.then(merge, () => void 0);
880
+ else merge(raw);
881
+ }
882
+ };
883
+ function draftsOf(chat) {
884
+ return chat.scoped("react-ui:drafts", (c) => new DraftScope(() => c.namespace));
885
+ }
886
+ var indexKey = (ns) => `${ns}:draft-index`;
887
+ function safeGet(storage, key) {
804
888
  try {
805
- void Promise.resolve(storage.set(key, value)).catch(() => void 0);
889
+ return storage.get(key);
806
890
  } catch {
891
+ return null;
807
892
  }
808
893
  }
809
- function clearDraft(storage, key) {
810
- memory.delete(key);
894
+ function swallow(fn) {
811
895
  try {
812
- void Promise.resolve(storage.remove(key)).catch(() => void 0);
896
+ const r = fn();
897
+ if (r && typeof r.catch === "function") {
898
+ r.catch(() => void 0);
899
+ }
813
900
  } catch {
814
901
  }
815
902
  }
@@ -825,6 +912,93 @@ function parse(raw) {
825
912
  return null;
826
913
  }
827
914
  }
915
+ function EmptyState({ title, hint, action, className }) {
916
+ return /* @__PURE__ */ jsxs("div", { className: ["poolse-empty-state", className].filter(Boolean).join(" "), role: "status", children: [
917
+ /* @__PURE__ */ jsx("p", { className: "poolse-empty-state__title", children: title }),
918
+ hint ? /* @__PURE__ */ jsx("p", { className: "poolse-empty-state__hint", children: hint }) : null,
919
+ action ? /* @__PURE__ */ jsx("div", { className: "poolse-empty-state__action", children: action }) : null
920
+ ] });
921
+ }
922
+
923
+ // src/keymap.ts
924
+ var DEFAULT_KEYMAP = {
925
+ composer: {
926
+ send: ["Enter", "Mod+Enter"],
927
+ newline: ["Shift+Enter"],
928
+ editLast: ["ArrowUp"],
929
+ cancel: ["Escape"]
930
+ },
931
+ messageList: {
932
+ next: ["j", "ArrowDown"],
933
+ prev: ["k", "ArrowUp"],
934
+ last: ["End"],
935
+ first: ["Home"],
936
+ reply: ["r"],
937
+ thread: ["t"],
938
+ edit: ["e"],
939
+ delete: ["Delete", "Backspace"],
940
+ composer: ["Escape"]
941
+ }
942
+ };
943
+ var MOD_ENTER_COMPOSER = {
944
+ send: ["Mod+Enter"],
945
+ newline: ["Enter", "Shift+Enter"]
946
+ };
947
+ function resolveKeymap(overrides, sendOn = "enter") {
948
+ return {
949
+ composer: {
950
+ ...DEFAULT_KEYMAP.composer,
951
+ ...sendOn === "mod+enter" ? MOD_ENTER_COMPOSER : {},
952
+ ...overrides?.composer
953
+ },
954
+ messageList: { ...DEFAULT_KEYMAP.messageList, ...overrides?.messageList }
955
+ };
956
+ }
957
+ function matchesKey(e, binding) {
958
+ const parts = binding.split("+");
959
+ const key = parts.pop() ?? "";
960
+ const mods = new Set(parts.map((p) => p.toLowerCase()));
961
+ const wantMod = mods.has("mod");
962
+ const wantCtrl = mods.has("ctrl");
963
+ const wantMeta = mods.has("meta") || mods.has("cmd");
964
+ const wantAlt = mods.has("alt") || mods.has("option");
965
+ const wantShift = mods.has("shift");
966
+ if (wantMod ? !(e.metaKey || e.ctrlKey) : !wantCtrl && !wantMeta && (e.metaKey || e.ctrlKey)) {
967
+ return false;
968
+ }
969
+ if (wantCtrl && !e.ctrlKey) return false;
970
+ if (wantMeta && !e.metaKey) return false;
971
+ if (wantAlt !== e.altKey) return false;
972
+ const letter = key.length === 1;
973
+ if (!letter && wantShift !== e.shiftKey) return false;
974
+ if (letter && wantShift && !e.shiftKey) return false;
975
+ return letter ? e.key.toLowerCase() === key.toLowerCase() : e.key === key;
976
+ }
977
+ function matchesAny(e, bindings) {
978
+ return bindings.some((b) => matchesKey(e, b));
979
+ }
980
+ function isTypingTarget(target) {
981
+ if (!target || typeof target.closest !== "function") return false;
982
+ const el = target;
983
+ if (el.isContentEditable) return true;
984
+ return !!el.closest('input, textarea, select, [contenteditable="true"]');
985
+ }
986
+ function composerAction(e, keymap) {
987
+ if (matchesAny(e, keymap.newline)) return "newline";
988
+ if (matchesAny(e, keymap.send)) return "send";
989
+ if (matchesAny(e, keymap.editLast)) return "editLast";
990
+ if (matchesAny(e, keymap.cancel)) return "cancel";
991
+ return null;
992
+ }
993
+
994
+ // src/motion.ts
995
+ function prefersReducedMotion() {
996
+ try {
997
+ return typeof globalThis.matchMedia === "function" && globalThis.matchMedia("(prefers-reduced-motion: reduce)").matches;
998
+ } catch {
999
+ return false;
1000
+ }
1001
+ }
828
1002
 
829
1003
  // src/layout.ts
830
1004
  function gutterTime(time) {
@@ -1482,7 +1656,9 @@ var MentionInput = forwardRef(
1482
1656
  emojiPicker = true,
1483
1657
  maxFileSize,
1484
1658
  acceptFileTypes,
1485
- onValueChange
1659
+ onValueChange,
1660
+ keymap = DEFAULT_KEYMAP.composer,
1661
+ onEditLast
1486
1662
  }, ref) {
1487
1663
  const chat = usePoolse();
1488
1664
  const { members } = useMembers(conversationId);
@@ -1633,10 +1809,26 @@ var MentionInput = forwardRef(
1633
1809
  return;
1634
1810
  }
1635
1811
  }
1636
- if (e.key === "Enter" && !e.shiftKey) {
1812
+ const action = composerAction(e, keymap);
1813
+ if (action === "editLast") {
1814
+ if (value === "" && onEditLast && onEditLast() !== false) e.preventDefault();
1815
+ return;
1816
+ }
1817
+ if (action === "newline" && e.key === "Enter" && !e.shiftKey) {
1818
+ const result = handleListEnter(value, e.currentTarget.selectionStart);
1819
+ if (result) {
1820
+ e.preventDefault();
1821
+ setValue(result.value);
1822
+ requestAnimationFrame(() => {
1823
+ taRef.current?.setSelectionRange(result.caret, result.caret);
1824
+ });
1825
+ }
1826
+ return;
1827
+ }
1828
+ if (action === "send") {
1637
1829
  const ta = e.currentTarget;
1638
1830
  const caret = ta.selectionStart;
1639
- const result = handleListEnter(value, caret);
1831
+ const result = e.key === "Enter" && !e.metaKey && !e.ctrlKey ? handleListEnter(value, caret) : null;
1640
1832
  if (result) {
1641
1833
  e.preventDefault();
1642
1834
  setValue(result.value);
@@ -1648,7 +1840,7 @@ var MentionInput = forwardRef(
1648
1840
  e.preventDefault();
1649
1841
  void submit();
1650
1842
  }
1651
- if (e.key === "Escape" && replyingTo && onCancelReply && !mention) {
1843
+ if (action === "cancel" && replyingTo && onCancelReply && !mention) {
1652
1844
  e.preventDefault();
1653
1845
  onCancelReply();
1654
1846
  }
@@ -1704,6 +1896,8 @@ var MentionInput = forwardRef(
1704
1896
  multiple: true,
1705
1897
  ...uploads.accept ? { accept: uploads.accept } : {},
1706
1898
  className: "poolse-attach-input",
1899
+ "aria-label": "Attach files",
1900
+ tabIndex: -1,
1707
1901
  onChange: (e) => {
1708
1902
  const files = Array.from(e.target.files ?? []);
1709
1903
  if (files.length > 0) addFiles(files);
@@ -1737,11 +1931,11 @@ var MentionInput = forwardRef(
1737
1931
  placeholder,
1738
1932
  disabled: disabled || sending,
1739
1933
  "aria-label": placeholder,
1740
- role: "combobox",
1741
- "aria-expanded": Boolean(mention && filtered.length > 0),
1742
- "aria-controls": menuId,
1743
1934
  "aria-autocomplete": "list",
1744
- ...mention && filtered.length > 0 ? { "aria-activedescendant": `${menuId}-opt-${activeIdx}` } : {}
1935
+ ...mention && filtered.length > 0 ? {
1936
+ "aria-controls": menuId,
1937
+ "aria-activedescendant": `${menuId}-opt-${activeIdx}`
1938
+ } : {}
1745
1939
  }
1746
1940
  ),
1747
1941
  emojiPicker && /* @__PURE__ */ jsx(
@@ -1815,7 +2009,9 @@ var MessageComposer = forwardRef(
1815
2009
  emojiPicker = true,
1816
2010
  maxFileSize,
1817
2011
  acceptFileTypes,
1818
- onValueChange
2012
+ onValueChange,
2013
+ keymap = DEFAULT_KEYMAP.composer,
2014
+ onEditLast
1819
2015
  }, ref) {
1820
2016
  const [value, setValue] = useState("");
1821
2017
  const [sending, setSending] = useState(false);
@@ -1869,10 +2065,26 @@ var MessageComposer = forwardRef(
1869
2065
  }
1870
2066
  };
1871
2067
  const onKeyDown = (e) => {
1872
- if (e.key === "Enter" && !e.shiftKey) {
2068
+ const action = composerAction(e, keymap);
2069
+ if (action === "editLast") {
2070
+ if (value === "" && onEditLast && onEditLast() !== false) e.preventDefault();
2071
+ return;
2072
+ }
2073
+ if (action === "newline" && e.key === "Enter" && !e.shiftKey) {
2074
+ const result = handleListEnter(value, e.currentTarget.selectionStart);
2075
+ if (result) {
2076
+ e.preventDefault();
2077
+ setValue(result.value);
2078
+ requestAnimationFrame(() => {
2079
+ taRef.current?.setSelectionRange(result.caret, result.caret);
2080
+ });
2081
+ }
2082
+ return;
2083
+ }
2084
+ if (action === "send") {
1873
2085
  const ta = e.currentTarget;
1874
2086
  const caret = ta.selectionStart;
1875
- const result = handleListEnter(value, caret);
2087
+ const result = e.key === "Enter" && !e.metaKey && !e.ctrlKey ? handleListEnter(value, caret) : null;
1876
2088
  if (result) {
1877
2089
  e.preventDefault();
1878
2090
  setValue(result.value);
@@ -1884,7 +2096,7 @@ var MessageComposer = forwardRef(
1884
2096
  e.preventDefault();
1885
2097
  void submit();
1886
2098
  }
1887
- if (e.key === "Escape" && replyingTo && onCancelReply) {
2099
+ if (action === "cancel" && replyingTo && onCancelReply) {
1888
2100
  e.preventDefault();
1889
2101
  onCancelReply();
1890
2102
  }
@@ -1930,6 +2142,8 @@ var MessageComposer = forwardRef(
1930
2142
  multiple: true,
1931
2143
  ...uploads.accept ? { accept: uploads.accept } : {},
1932
2144
  className: "poolse-attach-input",
2145
+ "aria-label": "Attach files",
2146
+ tabIndex: -1,
1933
2147
  onChange: (e) => {
1934
2148
  const files = Array.from(e.target.files ?? []);
1935
2149
  if (files.length > 0) addFiles(files);
@@ -2068,6 +2282,189 @@ function formatTime(iso) {
2068
2282
  if (Number.isNaN(d.getTime())) return "";
2069
2283
  return d.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" });
2070
2284
  }
2285
+ function RecordingBanner({
2286
+ recording,
2287
+ transcribing = false,
2288
+ mode,
2289
+ consentRequired = false,
2290
+ myConsent,
2291
+ onStop,
2292
+ onChangeConsent,
2293
+ pending = false,
2294
+ className
2295
+ }) {
2296
+ const label = captureLabel(recording, transcribing, mode);
2297
+ if (!label) return null;
2298
+ const listenOnly = consentRequired && myConsent === "declined";
2299
+ const meta = listenOnly ? "You declined \u2014 you are listen-only" : consentRequired ? "Only people who agreed are captured" : "Everyone in the call is told";
2300
+ return /* @__PURE__ */ jsxs(
2301
+ "div",
2302
+ {
2303
+ className: ["poolse-rec-banner", className].filter(Boolean).join(" "),
2304
+ role: "status",
2305
+ "aria-label": `${label}. ${meta}`,
2306
+ children: [
2307
+ /* @__PURE__ */ jsx("span", { className: "poolse-rec-dot", "aria-hidden": "true" }),
2308
+ /* @__PURE__ */ jsxs("span", { className: "poolse-rec-banner__text", children: [
2309
+ /* @__PURE__ */ jsx("span", { className: "poolse-rec-banner__title", children: label }),
2310
+ /* @__PURE__ */ jsx("span", { className: "poolse-rec-banner__meta", children: meta })
2311
+ ] }),
2312
+ listenOnly && onChangeConsent && /* @__PURE__ */ jsx(
2313
+ "button",
2314
+ {
2315
+ type: "button",
2316
+ className: "poolse-rec-banner__btn",
2317
+ onClick: onChangeConsent,
2318
+ disabled: pending,
2319
+ children: "Change"
2320
+ }
2321
+ ),
2322
+ recording && onStop && /* @__PURE__ */ jsx(
2323
+ "button",
2324
+ {
2325
+ type: "button",
2326
+ className: "poolse-rec-banner__btn",
2327
+ onClick: onStop,
2328
+ disabled: pending,
2329
+ children: "Stop"
2330
+ }
2331
+ )
2332
+ ]
2333
+ }
2334
+ );
2335
+ }
2336
+ function RecordingIndicator({
2337
+ recording,
2338
+ transcribing = false,
2339
+ mode,
2340
+ className
2341
+ }) {
2342
+ const label = captureLabel(recording, transcribing, mode);
2343
+ if (!label) return null;
2344
+ return /* @__PURE__ */ jsxs(
2345
+ "span",
2346
+ {
2347
+ className: ["poolse-rec-indicator", className].filter(Boolean).join(" "),
2348
+ role: "img",
2349
+ "aria-label": label,
2350
+ title: label,
2351
+ children: [
2352
+ /* @__PURE__ */ jsx("span", { className: "poolse-rec-dot", "aria-hidden": "true" }),
2353
+ recording ? "REC" : "Transcript"
2354
+ ]
2355
+ }
2356
+ );
2357
+ }
2358
+ function ConsentPrompt({
2359
+ recording,
2360
+ transcribing = false,
2361
+ mode,
2362
+ startedByName,
2363
+ onAnswer,
2364
+ onAccepted,
2365
+ onDeclined,
2366
+ pending = false,
2367
+ error,
2368
+ overlay = true,
2369
+ className
2370
+ }) {
2371
+ const [busy, setBusy] = useState(false);
2372
+ const [failed, setFailed] = useState(false);
2373
+ const agree = useRef(null);
2374
+ const id = useId();
2375
+ useEffect(() => agree.current?.focus(), []);
2376
+ const what = recording && transcribing ? "recorded and transcribed" : recording ? mode === "audio" ? "recorded (audio)" : "recorded" : "transcribed";
2377
+ const answer = async (decision) => {
2378
+ setBusy(true);
2379
+ setFailed(false);
2380
+ try {
2381
+ const ok = await onAnswer(decision);
2382
+ if (ok === false) {
2383
+ setFailed(true);
2384
+ return;
2385
+ }
2386
+ if (decision === "accepted") onAccepted?.();
2387
+ else onDeclined?.();
2388
+ } catch {
2389
+ setFailed(true);
2390
+ } finally {
2391
+ setBusy(false);
2392
+ }
2393
+ };
2394
+ const disabled = busy || pending;
2395
+ const shownError = error ?? (failed ? "That didn\u2019t go through. Try again." : null);
2396
+ const card = /* @__PURE__ */ jsxs(
2397
+ "div",
2398
+ {
2399
+ className: ["poolse-consent", className].filter(Boolean).join(" "),
2400
+ role: "alertdialog",
2401
+ "aria-modal": overlay ? true : void 0,
2402
+ "aria-labelledby": `${id}-title`,
2403
+ "aria-describedby": `${id}-body`,
2404
+ children: [
2405
+ /* @__PURE__ */ jsxs("div", { className: "poolse-consent__head", children: [
2406
+ /* @__PURE__ */ jsx("span", { className: "poolse-rec-dot", "aria-hidden": "true" }),
2407
+ /* @__PURE__ */ jsxs("h2", { id: `${id}-title`, className: "poolse-consent__title", children: [
2408
+ "This call is being ",
2409
+ what
2410
+ ] })
2411
+ ] }),
2412
+ /* @__PURE__ */ jsxs("p", { id: `${id}-body`, className: "poolse-consent__body", children: [
2413
+ startedByName ? `${startedByName} started it. ` : "",
2414
+ "Your microphone and camera stay off until you agree. You can still hear and see everyone."
2415
+ ] }),
2416
+ /* @__PURE__ */ jsxs("div", { className: "poolse-consent__actions", children: [
2417
+ /* @__PURE__ */ jsx(
2418
+ "button",
2419
+ {
2420
+ type: "button",
2421
+ className: "poolse-consent__btn",
2422
+ onClick: () => void answer("declined"),
2423
+ disabled,
2424
+ children: "Stay listen-only"
2425
+ }
2426
+ ),
2427
+ /* @__PURE__ */ jsx(
2428
+ "button",
2429
+ {
2430
+ ref: agree,
2431
+ type: "button",
2432
+ className: "poolse-consent__btn poolse-consent__btn--primary",
2433
+ onClick: () => void answer("accepted"),
2434
+ disabled,
2435
+ children: "Agree"
2436
+ }
2437
+ )
2438
+ ] }),
2439
+ shownError && /* @__PURE__ */ jsx("p", { className: "poolse-consent__error", role: "alert", children: shownError })
2440
+ ]
2441
+ }
2442
+ );
2443
+ return overlay ? /* @__PURE__ */ jsx("div", { className: "poolse-consent-scrim", children: card }) : card;
2444
+ }
2445
+ function RecordingNoticeRow({ msg, meId, nameFor }) {
2446
+ const display = recordingNoticeDisplayFor(msg, meId, nameFor);
2447
+ if (!display) return null;
2448
+ const time = formatTime2(msg.inserted_at);
2449
+ const label = [display.title, display.detail, time].filter(Boolean).join(", ");
2450
+ return /* @__PURE__ */ jsx("div", { className: "poolse-call-log poolse-rec-notice", role: "note", "aria-label": label, children: /* @__PURE__ */ jsxs("span", { className: "poolse-call-log__chip", children: [
2451
+ /* @__PURE__ */ jsx(
2452
+ "span",
2453
+ {
2454
+ className: `poolse-rec-dot${display.event === "stopped" ? " poolse-rec-dot--off" : ""}`,
2455
+ "aria-hidden": "true"
2456
+ }
2457
+ ),
2458
+ /* @__PURE__ */ jsx("span", { className: "poolse-call-log__title", children: display.title }),
2459
+ display.detail && /* @__PURE__ */ jsx("span", { className: "poolse-call-log__detail", children: display.detail }),
2460
+ time && /* @__PURE__ */ jsx("span", { className: "poolse-call-log__time", children: time })
2461
+ ] }) });
2462
+ }
2463
+ function formatTime2(iso) {
2464
+ const d = new Date(iso);
2465
+ if (Number.isNaN(d.getTime())) return "";
2466
+ return d.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" });
2467
+ }
2071
2468
  function AttachmentPreview({ attachment, onClick }) {
2072
2469
  const isFullRow = "content_type" in attachment;
2073
2470
  const { url, loading, error } = useAttachmentUrl(attachment.id);
@@ -3143,6 +3540,35 @@ function InlineReactions({
3143
3540
  );
3144
3541
  }) });
3145
3542
  }
3543
+ function SendStatus({ message, onRetry, onDiscard, align = "right" }) {
3544
+ const status = message.local_status;
3545
+ if (status !== "queued" && status !== "failed") return null;
3546
+ const failed = status === "failed";
3547
+ return /* @__PURE__ */ jsxs(
3548
+ "div",
3549
+ {
3550
+ className: [
3551
+ "poolse-send-status",
3552
+ `poolse-send-status--${status}`,
3553
+ `poolse-send-status--${align}`
3554
+ ].join(" "),
3555
+ role: "status",
3556
+ children: [
3557
+ /* @__PURE__ */ jsx("span", { className: "poolse-send-status__text", children: failed ? message.local_error ? `Not sent: ${message.local_error}` : "Not sent" : "Waiting for network\u2026" }),
3558
+ onRetry && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-send-status__button", onClick: onRetry, children: failed ? "Retry" : "Send now" }),
3559
+ failed && onDiscard && /* @__PURE__ */ jsx(
3560
+ "button",
3561
+ {
3562
+ type: "button",
3563
+ className: "poolse-send-status__button poolse-send-status__button--danger",
3564
+ onClick: onDiscard,
3565
+ children: "Delete"
3566
+ }
3567
+ )
3568
+ ]
3569
+ }
3570
+ );
3571
+ }
3146
3572
  function ThreadSummary({ message, onOpen, maxAvatars = 3, className }) {
3147
3573
  const now = useNow();
3148
3574
  const count = message.reply_count ?? 0;
@@ -3204,7 +3630,9 @@ function FlatMessageRow({
3204
3630
  onAvatarPress,
3205
3631
  timeFormat,
3206
3632
  slots,
3207
- mentionsMe = false
3633
+ mentionsMe = false,
3634
+ onRetrySend,
3635
+ onDiscardSend
3208
3636
  }) {
3209
3637
  const compact = layout === "compact";
3210
3638
  const isSelf = meId !== null && msg.sender_id === meId;
@@ -3228,7 +3656,8 @@ function FlatMessageRow({
3228
3656
  const time = formatMessageTime(msg.inserted_at, timeFormat);
3229
3657
  const replyCount = msg.reply_count ?? 0;
3230
3658
  const showThreadLink = threads && !msg.thread_root_id && replyCount > 0;
3231
- const showActions = actions && !deleted && !editing;
3659
+ const unsent = !!msg.local_status;
3660
+ const showActions = actions && !deleted && !editing && !unsent;
3232
3661
  const timeEl = (className) => /* @__PURE__ */ jsx("time", { className, dateTime: msg.inserted_at, children: className === "poolse-row__gutter-time" ? gutterTime(time) : time });
3233
3662
  const avatarSize = compact ? "sm" : "md";
3234
3663
  const avatarEl = /* @__PURE__ */ jsx(
@@ -3321,7 +3750,7 @@ function FlatMessageRow({
3321
3750
  meta
3322
3751
  }
3323
3752
  );
3324
- const reactionsEl = reactions && !deleted ? /* @__PURE__ */ jsx(
3753
+ const reactionsEl = reactions && !deleted && !unsent ? /* @__PURE__ */ jsx(
3325
3754
  InlineReactions,
3326
3755
  {
3327
3756
  reactions: reactionsHook.reactions,
@@ -3362,7 +3791,16 @@ function FlatMessageRow({
3362
3791
  renderSlot(slots?.body, ctx, body),
3363
3792
  linkPreviews && !editing && hasLinkPreviews(msg) ? /* @__PURE__ */ jsx(MessageLinkPreviews, { message: msg, canRemove: isSelf }) : null,
3364
3793
  renderSlot(slots?.reactions, ctx, reactionsEl),
3365
- renderSlot(slots?.thread, ctx, threadEl)
3794
+ renderSlot(slots?.thread, ctx, threadEl),
3795
+ /* @__PURE__ */ jsx(
3796
+ SendStatus,
3797
+ {
3798
+ message: msg,
3799
+ align: "left",
3800
+ ...onRetrySend ? { onRetry: onRetrySend } : {},
3801
+ ...onDiscardSend ? { onDiscard: onDiscardSend } : {}
3802
+ }
3803
+ )
3366
3804
  ] });
3367
3805
  return /* @__PURE__ */ jsxs(
3368
3806
  "div",
@@ -3374,9 +3812,13 @@ function FlatMessageRow({
3374
3812
  isRunStart ? "poolse-row--run-start" : "poolse-row--continued",
3375
3813
  isSelf ? "poolse-row--self" : "",
3376
3814
  mentionsMe ? "poolse-row--mention" : "",
3377
- editing ? "poolse-row--editing" : ""
3815
+ editing ? "poolse-row--editing" : "",
3816
+ unsent ? "poolse-row--unsent" : ""
3378
3817
  ].filter(Boolean).join(" "),
3379
3818
  "data-message-id": msg.id,
3819
+ role: "article",
3820
+ "aria-label": `Message from ${isSelf ? "you" : senderName}`,
3821
+ tabIndex: -1,
3380
3822
  "data-actions-open": actionsOpen || void 0,
3381
3823
  onClick: onRowClick,
3382
3824
  children: [
@@ -3446,6 +3888,16 @@ function FlatBody({
3446
3888
  );
3447
3889
  }
3448
3890
  function MessageRow(props) {
3891
+ if (recordingNoticeDisplayFor(props.msg, props.meId)) {
3892
+ return /* @__PURE__ */ jsx(
3893
+ RecordingNoticeRow,
3894
+ {
3895
+ msg: props.msg,
3896
+ meId: props.meId,
3897
+ ...props.nameForUserId ? { nameFor: props.nameForUserId } : {}
3898
+ }
3899
+ );
3900
+ }
3449
3901
  const callLog = callLogDisplayFor(props.msg, props.meId);
3450
3902
  if (callLog !== void 0) {
3451
3903
  return callLog ? /* @__PURE__ */ jsx(
@@ -3491,7 +3943,9 @@ function BubbleMessageRow({
3491
3943
  onSenderPress,
3492
3944
  onAvatarPress,
3493
3945
  timeFormat,
3494
- slots
3946
+ slots,
3947
+ onRetrySend,
3948
+ onDiscardSend
3495
3949
  }) {
3496
3950
  const { profile: senderProfile } = useUser(msg.sender_external_id);
3497
3951
  const senderFallbackName = msg.sender_external_id ?? (msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown");
@@ -3508,8 +3962,9 @@ function BubbleMessageRow({
3508
3962
  initialReactions: msg.reactions,
3509
3963
  currentUserId: meId
3510
3964
  });
3511
- const showReactions = reactions && !msg.deleted_at;
3512
- const showActions = actions && !msg.deleted_at && !editing;
3965
+ const unsent = !!msg.local_status;
3966
+ const showReactions = reactions && !msg.deleted_at && !unsent;
3967
+ const showActions = actions && !msg.deleted_at && !editing && !unsent;
3513
3968
  const replyCount = msg.reply_count ?? 0;
3514
3969
  const showThreadPill = threads && !msg.thread_root_id && replyCount > 0;
3515
3970
  const handleSave = onSaveEdit ?? (async () => void 0);
@@ -3533,9 +3988,13 @@ function BubbleMessageRow({
3533
3988
  // tighten the inter-bubble gap inside a cluster (first/middle/
3534
3989
  // last) and widen it between clusters (standalone or the
3535
3990
  // first of a new run).
3536
- `poolse-message-row--${groupPosition}`
3991
+ `poolse-message-row--${groupPosition}`,
3992
+ unsent ? "poolse-message-row--unsent" : ""
3537
3993
  ].filter(Boolean).join(" "),
3538
3994
  "data-message-id": msg.id,
3995
+ role: "article",
3996
+ "aria-label": `Message from ${isSelf ? "you" : senderName}`,
3997
+ tabIndex: -1,
3539
3998
  "data-actions-open": actionsOpen || void 0,
3540
3999
  "data-avatar": showAvatar && !isSelf ? true : void 0,
3541
4000
  onClick: onRowClick,
@@ -3597,6 +4056,15 @@ function BubbleMessageRow({
3597
4056
  )
3598
4057
  }
3599
4058
  ),
4059
+ /* @__PURE__ */ jsx(
4060
+ SendStatus,
4061
+ {
4062
+ message: msg,
4063
+ align: isSelf ? "right" : "left",
4064
+ ...onRetrySend ? { onRetry: onRetrySend } : {},
4065
+ ...onDiscardSend ? { onDiscard: onDiscardSend } : {}
4066
+ }
4067
+ ),
3600
4068
  renderSlot(
3601
4069
  slots?.reactions,
3602
4070
  slotContext,
@@ -3762,13 +4230,12 @@ function ThreadView({
3762
4230
  }, [replies]);
3763
4231
  useEffect(() => {
3764
4232
  closeBtnRef.current?.focus();
3765
- if (!onClose) return;
3766
- const onKey = (e) => {
3767
- if (e.key === "Escape") onClose();
3768
- };
3769
- document.addEventListener("keydown", onKey);
3770
- return () => document.removeEventListener("keydown", onKey);
3771
- }, [onClose]);
4233
+ }, []);
4234
+ const onPaneKeyDown = (e) => {
4235
+ if (e.key !== "Escape" || e.defaultPrevented || !onClose) return;
4236
+ e.preventDefault();
4237
+ onClose();
4238
+ };
3772
4239
  const renderDefault = (msg) => /* @__PURE__ */ jsx(
3773
4240
  MessageRow,
3774
4241
  {
@@ -3801,6 +4268,7 @@ function ThreadView({
3801
4268
  className: `poolse-thread${density ? ` poolse-conversation--density-${density}` : ""}${dragActive ? " is-drag-active" : ""}`,
3802
4269
  role: "complementary",
3803
4270
  "aria-label": "Message thread",
4271
+ onKeyDown: onPaneKeyDown,
3804
4272
  onDragEnter,
3805
4273
  onDragOver,
3806
4274
  onDragLeave,
@@ -3821,9 +4289,9 @@ function ThreadView({
3821
4289
  )
3822
4290
  ] }),
3823
4291
  /* @__PURE__ */ jsx("div", { className: "poolse-thread__root", children: /* @__PURE__ */ jsx(MessageBubble, { message: rootMessage, currentUserId: me?.id ?? null }) }),
3824
- /* @__PURE__ */ jsxs("div", { className: "poolse-thread__messages", ref: listRef, children: [
4292
+ /* @__PURE__ */ jsxs("div", { className: "poolse-thread__messages", ref: listRef, role: "log", "aria-label": "Replies", children: [
3825
4293
  hasMore && !loading && replies.length > 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older replies" }),
3826
- loading && replies.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading replies\u2026" }) : replies.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "No replies yet \u2014 start the thread." }) : (
4294
+ loading && replies.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading replies\u2026" }) : replies.length === 0 ? /* @__PURE__ */ jsx(EmptyState, { title: "No replies yet", hint: "Write a reply below to start the thread." }) : (
3827
4295
  // Same Fragment trick as ConversationView so MessageBubble
3828
4296
  // remains the direct flex child for align-self to work.
3829
4297
  replies.map((msg) => /* @__PURE__ */ jsx(Fragment$1, { children: renderOne(msg, me?.id ?? null) }, msg.id))
@@ -3960,7 +4428,11 @@ function ConversationView({
3960
4428
  onJoinCall,
3961
4429
  currentCallId = null,
3962
4430
  persistDrafts = TRUE,
3963
- draftStorage
4431
+ draftStorage,
4432
+ keymap: keymapOverrides,
4433
+ sendOn = "enter",
4434
+ keyboardShortcuts = TRUE,
4435
+ confirmDelete
3964
4436
  }) {
3965
4437
  usePoolseFonts(loadFonts);
3966
4438
  const showComposer = composer && !readOnly;
@@ -3975,10 +4447,13 @@ function ConversationView({
3975
4447
  loadMore,
3976
4448
  loadUntil,
3977
4449
  send,
4450
+ retry: retrySend,
4451
+ discard: discardSend,
3978
4452
  edit,
3979
4453
  delete: deleteMsg,
3980
4454
  markReadUpTo
3981
4455
  } = useMessages(conversationId);
4456
+ const keymap = useMemo(() => resolveKeymap(keymapOverrides, sendOn), [keymapOverrides, sendOn]);
3982
4457
  const { typing: typingPeople, signalTyping } = useTyping(conversationId);
3983
4458
  const streams = useMessageStreams(conversationId);
3984
4459
  const typing = useMemo(() => {
@@ -3994,6 +4469,14 @@ function ConversationView({
3994
4469
  const membersOn = mentions || readReceipts || wantsMemberCount;
3995
4470
  const { members, loading: membersLoading } = useMembers(membersOn ? conversationId : "");
3996
4471
  const chat = usePoolse();
4472
+ const nameForUserId = useCallback(
4473
+ (userId) => {
4474
+ const ext = members.find((m) => m.user_id === userId)?.external_id;
4475
+ if (!ext) return null;
4476
+ return chat.users.peek(ext)?.displayName ?? labelFor?.(ext) ?? null;
4477
+ },
4478
+ [members, chat, labelFor]
4479
+ );
3997
4480
  const isGroupChat = members.length > 2;
3998
4481
  const showSenderLabelsResolved = senderLabels === "always" || senderLabels === "auto" && isGroupChat;
3999
4482
  const showAvatarsResolved = showAvatars ?? (layout === "list" ? true : layout === "compact" ? false : avatars === "always" || avatars === "auto" && isGroupChat);
@@ -4271,18 +4754,19 @@ function ConversationView({
4271
4754
  const meIdForDrafts = me?.id ?? null;
4272
4755
  const draftsOn = persistDrafts && showComposer;
4273
4756
  const storage = draftStorage ?? localDraftStorage;
4757
+ const drafts = draftsOf(chat);
4274
4758
  const draftRef = useRef({ text: "", replyTo: null });
4275
4759
  const draftKeyFor = useCallback(
4276
- () => draftsOn && meIdForDrafts ? draftKey(meIdForDrafts, conversationIdRef.current) : null,
4277
- [draftsOn, meIdForDrafts]
4760
+ () => draftsOn && meIdForDrafts ? drafts.key(conversationIdRef.current) : null,
4761
+ [draftsOn, meIdForDrafts, drafts]
4278
4762
  );
4279
4763
  const saveDraft = useCallback(
4280
4764
  (patch) => {
4281
4765
  draftRef.current = { ...draftRef.current, ...patch };
4282
4766
  const key = draftKeyFor();
4283
- if (key) writeDraft(storage, key, draftRef.current);
4767
+ if (key) drafts.write(storage, key, draftRef.current);
4284
4768
  },
4285
- [draftKeyFor, storage]
4769
+ [draftKeyFor, storage, drafts]
4286
4770
  );
4287
4771
  const setReplyingTo = useCallback(
4288
4772
  (m) => {
@@ -4303,13 +4787,14 @@ function ConversationView({
4303
4787
  draftRef.current = { text: composer2?.getText() || d.text, replyTo: d.replyTo };
4304
4788
  if (d.replyTo && canQuote) setReplyingToState((cur) => cur ?? d.replyTo);
4305
4789
  };
4306
- const found = readDraft(storage, key);
4790
+ const legacy = meIdForDrafts ? draftKey(meIdForDrafts, conversationIdRef.current) : void 0;
4791
+ const found = drafts.read(storage, key, legacy);
4307
4792
  if (found instanceof Promise) void found.then(apply);
4308
4793
  else apply(found);
4309
4794
  return () => {
4310
4795
  live = false;
4311
4796
  };
4312
- }, [conversationId, draftKeyFor, storage, canQuote, mentionComposer]);
4797
+ }, [conversationId, draftKeyFor, storage, canQuote, mentionComposer, drafts, meIdForDrafts]);
4313
4798
  const onComposerChange = useCallback((text) => saveDraft({ text }), [saveDraft]);
4314
4799
  useEffect(() => {
4315
4800
  if (!replyingTo) return;
@@ -4358,11 +4843,13 @@ function ConversationView({
4358
4843
  const files = Array.from(e.dataTransfer?.files ?? []);
4359
4844
  if (files.length > 0) composerRef.current?.addFiles(files);
4360
4845
  };
4361
- const sendRequest = async (req) => {
4846
+ const sendRequest = async (input) => {
4847
+ const req = { ...input, id: input.id ?? safeUuid() };
4362
4848
  try {
4363
4849
  await send(req);
4364
4850
  } catch (err) {
4365
4851
  if (err instanceof ApiError && err.code === "quoted_message_deleted") {
4852
+ discardSend(req.id);
4366
4853
  setReplyingTo(null);
4367
4854
  setSendNotice("The message you replied to was deleted.");
4368
4855
  const body = req.body;
@@ -4374,13 +4861,91 @@ function ConversationView({
4374
4861
  }
4375
4862
  return;
4376
4863
  }
4377
- throw err;
4864
+ if (!(err instanceof MessageQueuedError) && !chat.outboxEnabled) throw err;
4378
4865
  }
4379
4866
  setReplyingToState(null);
4380
4867
  setUnreadMarker(null);
4381
4868
  draftRef.current = { text: "", replyTo: null };
4382
4869
  const key = draftKeyFor();
4383
- if (key) clearDraft(storage, key);
4870
+ if (key) drafts.clear(storage, key);
4871
+ };
4872
+ const editLast = () => {
4873
+ for (let i = messages.length - 1; i >= 0; i--) {
4874
+ const m = messages[i];
4875
+ if (!me || m.sender_id !== me.id || m.deleted_at || m.local_status) continue;
4876
+ if (m.thread_root_id) continue;
4877
+ const isRead = maxReadByOthers !== null && maxReadByOthers >= m.sequence;
4878
+ const editable = canEditOwnMessage({
4879
+ isSelf: true,
4880
+ deleted: false,
4881
+ receiptsVisible,
4882
+ readState: showReadState && maxReadByOthers !== null ? isRead ? "read" : "sent" : void 0,
4883
+ insertedAt: m.inserted_at
4884
+ });
4885
+ if (!editable) return false;
4886
+ setEditingId(m.id);
4887
+ return true;
4888
+ }
4889
+ return false;
4890
+ };
4891
+ const rowsInList = () => Array.from(listRef.current?.querySelectorAll("[data-message-id]") ?? []).filter(
4892
+ (el) => el.closest(".poolse-conversation__messages") === listRef.current
4893
+ );
4894
+ const focusRow = (el) => {
4895
+ if (!el) return;
4896
+ el.focus();
4897
+ if (typeof el.scrollIntoView === "function") {
4898
+ el.scrollIntoView({ block: "nearest", behavior: prefersReducedMotion() ? "auto" : "smooth" });
4899
+ }
4900
+ };
4901
+ const onListKeyDown = (e) => {
4902
+ if (!keyboardShortcuts || isTypingTarget(e.target)) return;
4903
+ const km = keymap.messageList;
4904
+ const rows = rowsInList();
4905
+ if (rows.length === 0) return;
4906
+ const focused = e.target.closest?.("[data-message-id]");
4907
+ const idx = focused ? rows.indexOf(focused) : -1;
4908
+ const focusedMsg = focused ? messages.find((m) => m.id === focused.dataset["messageId"]) ?? null : null;
4909
+ const handled = () => {
4910
+ e.preventDefault();
4911
+ e.stopPropagation();
4912
+ };
4913
+ if (matchesAny(e, km.next)) {
4914
+ handled();
4915
+ focusRow(rows[idx === -1 ? rows.length - 1 : Math.min(rows.length - 1, idx + 1)]);
4916
+ } else if (matchesAny(e, km.prev)) {
4917
+ handled();
4918
+ focusRow(rows[idx === -1 ? rows.length - 1 : Math.max(0, idx - 1)]);
4919
+ } else if (matchesAny(e, km.last)) {
4920
+ handled();
4921
+ focusRow(rows[rows.length - 1]);
4922
+ } else if (matchesAny(e, km.first)) {
4923
+ handled();
4924
+ focusRow(rows[0]);
4925
+ } else if (matchesAny(e, km.composer)) {
4926
+ if (!showComposer) return;
4927
+ handled();
4928
+ composerRef.current?.focus();
4929
+ } else if (focusedMsg && !focusedMsg.deleted_at && !focusedMsg.local_status) {
4930
+ const isSelf = me !== null && focusedMsg.sender_id === me.id;
4931
+ if (matchesAny(e, km.reply) && canQuote) {
4932
+ handled();
4933
+ setReplyingTo(focusedMsg);
4934
+ composerRef.current?.focus();
4935
+ } else if (matchesAny(e, km.thread) && threads) {
4936
+ handled();
4937
+ setThreadRootId(focusedMsg.id);
4938
+ } else if (matchesAny(e, km.edit) && isSelf && showComposer) {
4939
+ handled();
4940
+ setEditingId(focusedMsg.id);
4941
+ } else if (matchesAny(e, km.delete) && isSelf && actions) {
4942
+ handled();
4943
+ const ask = confirmDelete ?? (() => typeof globalThis.confirm === "function" ? globalThis.confirm("Delete this message?") : false);
4944
+ void Promise.resolve(ask(focusedMsg)).then((ok) => {
4945
+ if (ok) void deleteMsg(focusedMsg.id).catch(() => void 0);
4946
+ });
4947
+ }
4948
+ }
4384
4949
  };
4385
4950
  const onSendBody = (body, opts) => sendRequest({
4386
4951
  body,
@@ -4400,6 +4965,8 @@ function ConversationView({
4400
4965
  conversationId,
4401
4966
  onSend: onSendWithMentions,
4402
4967
  onTyping: signalTyping,
4968
+ keymap: keymap.composer,
4969
+ onEditLast: editLast,
4403
4970
  attachments,
4404
4971
  emojiPicker,
4405
4972
  ...attachmentRules,
@@ -4414,6 +4981,8 @@ function ConversationView({
4414
4981
  onValueChange: onComposerChange,
4415
4982
  onSend: onSendBody,
4416
4983
  onTyping: signalTyping,
4984
+ keymap: keymap.composer,
4985
+ onEditLast: editLast,
4417
4986
  attachments,
4418
4987
  emojiPicker,
4419
4988
  ...attachmentRules,
@@ -4478,6 +5047,8 @@ function ConversationView({
4478
5047
  "aria-label": "Conversation messages",
4479
5048
  "aria-live": "polite",
4480
5049
  "aria-relevant": "additions",
5050
+ tabIndex: 0,
5051
+ onKeyDown: onListKeyDown,
4481
5052
  children: [
4482
5053
  hasMore && /* @__PURE__ */ jsx("div", { ref: topSentinelRef, "aria-hidden": "true", style: { height: 1 } }),
4483
5054
  showJump && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__jump-unread", children: [
@@ -4505,7 +5076,13 @@ function ConversationView({
4505
5076
  }
4506
5077
  )
4507
5078
  ] }),
4508
- loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : visibleMessages.map((msg, idx) => {
5079
+ loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 && !error ? typeof emptyState === "function" ? emptyState({ readOnly: !showComposer }) : emptyState !== void 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState }) : /* @__PURE__ */ jsx(
5080
+ EmptyState,
5081
+ {
5082
+ title: "No messages yet",
5083
+ ...showComposer ? { hint: "Write the first message below \u2014 everyone here will see it." } : {}
5084
+ }
5085
+ ) : visibleMessages.map((msg, idx) => {
4509
5086
  const prev = idx > 0 ? visibleMessages[idx - 1] ?? null : null;
4510
5087
  const next = idx < visibleMessages.length - 1 ? visibleMessages[idx + 1] ?? null : null;
4511
5088
  const groupPosition = grouping ? computeGroupPosition(msg, prev, next, groupWindowMs) : "standalone";
@@ -4564,7 +5141,12 @@ function ConversationView({
4564
5141
  onQuote: () => setReplyingTo(msg),
4565
5142
  ...!isSelf && msg.sequence !== Number.MAX_SAFE_INTEGER ? { onMarkUnread: () => void markUnreadFrom(msg) } : {},
4566
5143
  onQuotedClick: scrollToOriginal,
5144
+ ...msg.local_status ? {
5145
+ onRetrySend: () => void retrySend(msg.id).catch(() => void 0),
5146
+ onDiscardSend: () => discardSend(msg.id)
5147
+ } : {},
4567
5148
  ...onCallBack ? { onCallBack } : {},
5149
+ nameForUserId,
4568
5150
  ...layoutProps,
4569
5151
  mentionsMe: mentionsViewer(msg, me?.id ?? null)
4570
5152
  }
@@ -4665,12 +5247,12 @@ function ConversationView({
4665
5247
  var NO_MESSAGE = "00000000-0000-0000-0000-000000000000";
4666
5248
  function scrollDividerIntoView(el) {
4667
5249
  if (el && typeof el.scrollIntoView === "function") {
4668
- el.scrollIntoView({ behavior: "smooth", block: "start" });
5250
+ el.scrollIntoView({ behavior: prefersReducedMotion() ? "auto" : "smooth", block: "start" });
4669
5251
  }
4670
5252
  }
4671
5253
  function highlightRow(el) {
4672
5254
  if (typeof el.scrollIntoView === "function") {
4673
- el.scrollIntoView({ behavior: "smooth", block: "center" });
5255
+ el.scrollIntoView({ behavior: prefersReducedMotion() ? "auto" : "smooth", block: "center" });
4674
5256
  }
4675
5257
  el.classList.add("poolse-message-row--highlight");
4676
5258
  setTimeout(() => el.classList.remove("poolse-message-row--highlight"), 1600);
@@ -4779,6 +5361,8 @@ function ConversationList({
4779
5361
  onSelect,
4780
5362
  renderItem,
4781
5363
  emptyState,
5364
+ query = "",
5365
+ noResultsState,
4782
5366
  conversations: controlledConversations,
4783
5367
  loading: controlledLoading,
4784
5368
  error: controlledError,
@@ -4799,7 +5383,15 @@ function ConversationList({
4799
5383
  const meExternalId = me?.external_id ?? null;
4800
5384
  const meId = me?.id ?? null;
4801
5385
  const isControlled = controlledConversations !== void 0;
4802
- const conversations = isControlled ? controlledConversations : auto.conversations;
5386
+ const allConversations = isControlled ? controlledConversations : auto.conversations;
5387
+ const needle = query.trim().toLowerCase();
5388
+ const conversations = useMemo(
5389
+ () => needle ? filterConversations(allConversations, needle, {
5390
+ meExternalId,
5391
+ ...labelFor ? { labelFor } : {}
5392
+ }) : allConversations,
5393
+ [allConversations, needle, meExternalId, labelFor]
5394
+ );
4803
5395
  const loading = isControlled ? controlledLoading ?? false : auto.loading;
4804
5396
  const error = isControlled ? controlledError ?? null : auto.error;
4805
5397
  const counts = unreadCounts ?? (isControlled ? void 0 : auto.unreadCounts);
@@ -4847,8 +5439,23 @@ function ConversationList({
4847
5439
  if (error && conversations.length === 0) {
4848
5440
  return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder poolse-list--error", children: "Failed to load conversations." });
4849
5441
  }
5442
+ if (conversations.length === 0 && needle && allConversations.length > 0) {
5443
+ return typeof noResultsState === "function" ? noResultsState(query.trim()) : noResultsState !== void 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: noResultsState }) : /* @__PURE__ */ jsx(
5444
+ EmptyState,
5445
+ {
5446
+ title: `Nothing matches \u201C${query.trim()}\u201D`,
5447
+ hint: "Check the spelling, or search by a person's or channel's name."
5448
+ }
5449
+ );
5450
+ }
4850
5451
  if (conversations.length === 0) {
4851
- return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: emptyState ?? "No conversations yet." });
5452
+ return emptyState !== void 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: emptyState }) : /* @__PURE__ */ jsx(
5453
+ EmptyState,
5454
+ {
5455
+ title: "No conversations yet",
5456
+ hint: "Start a chat with someone, or join a channel \u2014 it shows up here."
5457
+ }
5458
+ );
4852
5459
  }
4853
5460
  const row = (conv) => {
4854
5461
  const selected = selectedId === conv.id;
@@ -4887,10 +5494,10 @@ function ConversationList({
4887
5494
  );
4888
5495
  };
4889
5496
  return /* @__PURE__ */ jsxs("ul", { ref: listRef, className: "poolse-list", role: "listbox", "aria-label": "Conversations", children: [
4890
- groups === null ? conversations.map(row) : groups.map((g) => /* @__PURE__ */ jsxs("li", { role: "group", "aria-label": g.title, className: "poolse-list__section", children: [
5497
+ groups === null ? conversations.map(row) : groups.map((g) => /* @__PURE__ */ jsx("li", { role: "presentation", className: "poolse-list__section", children: /* @__PURE__ */ jsxs("div", { role: "group", "aria-label": g.title, children: [
4891
5498
  /* @__PURE__ */ jsx("div", { className: "poolse-list__section-title", "aria-hidden": "true", children: g.title }),
4892
5499
  /* @__PURE__ */ jsx("ul", { className: "poolse-list__section-items", role: "presentation", children: g.conversations.map(row) })
4893
- ] }, g.title)),
5500
+ ] }) }, g.title)),
4894
5501
  loadingMore && /* @__PURE__ */ jsx("li", { className: "poolse-list__loading-more", role: "presentation", children: "Loading\u2026" }),
4895
5502
  hasMore && /* @__PURE__ */ jsx(
4896
5503
  "li",
@@ -4939,7 +5546,7 @@ function DefaultRow({
4939
5546
  const avatarUrl = isDirect ? otherExtId ? avatarFor?.(otherExtId) ?? other?.avatarUrl ?? null : conv.avatar_url ?? null : conv.avatar_url ?? null;
4940
5547
  const time = conv.last_message_at ? formatRelative(conv.last_message_at) : "";
4941
5548
  const hasUnread = unread > 0;
4942
- const preview = formatCallLogPreview(conv.last_message_preview, meId) ?? conv.last_message_preview ?? (conv.last_sequence > 0 ? `${conv.last_sequence} message${conv.last_sequence === 1 ? "" : "s"}` : "No messages yet");
5549
+ const preview = formatCallLogPreview(conv.last_message_preview, meId) ?? formatRecordingNoticePreview(conv.last_message_preview, meId) ?? conv.last_message_preview ?? (conv.last_sequence > 0 ? `${conv.last_sequence} message${conv.last_sequence === 1 ? "" : "s"}` : "No messages yet");
4943
5550
  return /* @__PURE__ */ jsxs(Fragment, { children: [
4944
5551
  /* @__PURE__ */ jsx(
4945
5552
  Avatar,
@@ -5208,7 +5815,7 @@ function UserPickerSheet({
5208
5815
  }
5209
5816
  )
5210
5817
  ] }),
5211
- /* @__PURE__ */ jsx("ul", { className: "poolse-user-picker", role: "listbox", "aria-label": "Users", children: filtered.length === 0 ? /* @__PURE__ */ jsx("li", { className: "poolse-user-picker__empty", children: "No matching users." }) : filtered.map((u) => {
5818
+ /* @__PURE__ */ jsx("ul", { className: "poolse-user-picker", role: "listbox", "aria-label": "Users", children: filtered.length === 0 ? /* @__PURE__ */ jsx("li", { className: "poolse-user-picker__empty", children: "No one matches that. Try part of a first or last name." }) : filtered.map((u) => {
5212
5819
  const isSelected = selected.has(u.externalId);
5213
5820
  return /* @__PURE__ */ jsxs(
5214
5821
  "li",
@@ -5505,8 +6112,24 @@ function RoomJoinBar({ room, allowStart = true }) {
5505
6112
  ] })
5506
6113
  ] });
5507
6114
  }
5508
- function RoomStage({ room, title, labelFor, className }) {
6115
+ function RoomStage({
6116
+ room,
6117
+ title,
6118
+ labelFor,
6119
+ className,
6120
+ capture = true,
6121
+ allowRecord = false
6122
+ }) {
5509
6123
  const media = room.media;
6124
+ const live = room.live;
6125
+ const rec = useRecording(
6126
+ capture || allowRecord ? live?.id ?? null : null,
6127
+ live?.conversation_id ?? null,
6128
+ live
6129
+ );
6130
+ const [consentDismissed, setConsentDismissed] = useState(false);
6131
+ const transcribing = !!rec.transcription?.active;
6132
+ const starter = rec.recording?.started_by_user_id;
5510
6133
  const stage = useRef(null);
5511
6134
  const fullscreen = useFullscreen(stage);
5512
6135
  const [menu, setMenu] = useState(null);
@@ -5535,6 +6158,15 @@ function RoomStage({ room, title, labelFor, className }) {
5535
6158
  /* @__PURE__ */ jsx("span", { className: "poolse-room__dot", "aria-hidden": "true" }),
5536
6159
  elapsed
5537
6160
  ] }),
6161
+ capture && /* @__PURE__ */ jsx(
6162
+ RecordingIndicator,
6163
+ {
6164
+ recording: rec.active,
6165
+ transcribing,
6166
+ mode: rec.recording?.mode ?? null,
6167
+ className: "poolse-room__chip"
6168
+ }
6169
+ ),
5538
6170
  /* @__PURE__ */ jsxs("span", { className: "poolse-room__chip", "aria-label": `${count} in the room`, children: [
5539
6171
  /* @__PURE__ */ jsx(PoolseIcon, { name: "users", size: 14, label: null }),
5540
6172
  count
@@ -5559,6 +6191,19 @@ function RoomStage({ room, title, labelFor, className }) {
5559
6191
  }
5560
6192
  )
5561
6193
  ] }),
6194
+ capture && /* @__PURE__ */ jsx(
6195
+ RecordingBanner,
6196
+ {
6197
+ className: "poolse-room__rec",
6198
+ recording: rec.active,
6199
+ transcribing,
6200
+ mode: rec.recording?.mode ?? null,
6201
+ consentRequired: rec.consentRequired,
6202
+ myConsent: rec.myConsent,
6203
+ onChangeConsent: () => setConsentDismissed(false),
6204
+ pending: rec.pending
6205
+ }
6206
+ ),
5562
6207
  /* @__PURE__ */ jsx("div", { className: "poolse-room__stage", children: count > 0 ? /* @__PURE__ */ jsx(
5563
6208
  CallVideoGrid,
5564
6209
  {
@@ -5573,6 +6218,20 @@ function RoomStage({ room, title, labelFor, className }) {
5573
6218
  /* @__PURE__ */ jsx("button", { type: "button", onClick: () => void media.setScreenShareEnabled(false), children: "Stop sharing" })
5574
6219
  ] }),
5575
6220
  room.error && /* @__PURE__ */ jsx("p", { className: "poolse-room__error", children: room.error.message }),
6221
+ rec.error && /* @__PURE__ */ jsx("p", { className: "poolse-room__error", children: captureErrorMessage(rec.error) }),
6222
+ capture && rec.needsConsent && !(consentDismissed && rec.myConsent === "declined") && /* @__PURE__ */ jsx(
6223
+ ConsentPrompt,
6224
+ {
6225
+ recording: rec.active,
6226
+ transcribing,
6227
+ mode: rec.recording?.mode ?? null,
6228
+ startedByName: starter ? labelFor?.(starter) ?? null : null,
6229
+ onAnswer: rec.consent,
6230
+ onAccepted: () => void media.republish(),
6231
+ onDeclined: () => setConsentDismissed(true),
6232
+ pending: rec.pending
6233
+ }
6234
+ ),
5576
6235
  /* @__PURE__ */ jsxs("div", { className: "poolse-room__bar", children: [
5577
6236
  /* @__PURE__ */ jsxs("span", { className: "callsheet__control", children: [
5578
6237
  /* @__PURE__ */ jsx(
@@ -5650,6 +6309,16 @@ function RoomStage({ room, title, labelFor, className }) {
5650
6309
  }
5651
6310
  )
5652
6311
  ] }),
6312
+ allowRecord && rec.available && /* @__PURE__ */ jsx(
6313
+ CallControlButton,
6314
+ {
6315
+ icon: "presence",
6316
+ highlight: rec.active,
6317
+ label: rec.active ? "Stop recording" : "Record",
6318
+ onClick: () => void (rec.active ? rec.stop() : rec.start()),
6319
+ disabled: rec.pending || media.status !== "connected"
6320
+ }
6321
+ ),
5653
6322
  /* @__PURE__ */ jsx(
5654
6323
  CallControlButton,
5655
6324
  {
@@ -5681,6 +6350,324 @@ function useElapsed(startedAt, running) {
5681
6350
  const s = String(total % 60).padStart(2, "0");
5682
6351
  return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${s}` : `${m}:${s}`;
5683
6352
  }
6353
+ function LiveTranscriptPanel({
6354
+ callId,
6355
+ enabled = true,
6356
+ showControls = true,
6357
+ onClose,
6358
+ title = "Live transcript",
6359
+ className
6360
+ }) {
6361
+ const live = useLiveTranscript(callId, { enabled });
6362
+ const blocks = useMemo(() => groupTranscript(live.segments), [live.segments]);
6363
+ const scroller = useRef(null);
6364
+ const pinned = useRef(true);
6365
+ useEffect(() => {
6366
+ const el = scroller.current;
6367
+ if (el && pinned.current) el.scrollTop = el.scrollHeight;
6368
+ }, [live.segments]);
6369
+ const error = live.error ? transcriptError(live.error) : null;
6370
+ return /* @__PURE__ */ jsxs(
6371
+ "section",
6372
+ {
6373
+ className: ["poolse-transcript", "poolse-transcript--live", className].filter(Boolean).join(" "),
6374
+ "aria-label": title,
6375
+ children: [
6376
+ /* @__PURE__ */ jsxs("header", { className: "poolse-transcript__head", children: [
6377
+ /* @__PURE__ */ jsxs("span", { className: "poolse-transcript__title", children: [
6378
+ live.live && /* @__PURE__ */ jsx("span", { className: "poolse-rec-dot", "aria-hidden": "true" }),
6379
+ title
6380
+ ] }),
6381
+ showControls && callId && /* @__PURE__ */ jsx(
6382
+ "button",
6383
+ {
6384
+ type: "button",
6385
+ className: "poolse-transcript__btn",
6386
+ onClick: () => void (live.live ? live.stop() : live.start()),
6387
+ disabled: live.pending,
6388
+ children: live.live ? "Stop" : live.transcript ? "Resume" : "Start"
6389
+ }
6390
+ ),
6391
+ onClose && /* @__PURE__ */ jsx(
6392
+ "button",
6393
+ {
6394
+ type: "button",
6395
+ className: "poolse-transcript__icon-btn",
6396
+ onClick: onClose,
6397
+ "aria-label": "Close transcript",
6398
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "close", size: 16, label: null })
6399
+ }
6400
+ )
6401
+ ] }),
6402
+ /* @__PURE__ */ jsx(
6403
+ "div",
6404
+ {
6405
+ ref: scroller,
6406
+ className: "poolse-transcript__body",
6407
+ role: "log",
6408
+ "aria-live": "polite",
6409
+ "aria-relevant": "additions",
6410
+ onScroll: (e) => {
6411
+ const el = e.currentTarget;
6412
+ pinned.current = el.scrollHeight - el.scrollTop - el.clientHeight < 24;
6413
+ },
6414
+ children: blocks.length === 0 ? /* @__PURE__ */ jsx("p", { className: "poolse-transcript__empty", children: error ?? (live.live ? "Listening\u2026" : live.joined ? "Transcription is off. Start it to see what is said." : "Opening the transcript\u2026") }) : blocks.map((b, i) => /* @__PURE__ */ jsxs("div", { className: "poolse-transcript__block", children: [
6415
+ /* @__PURE__ */ jsxs("div", { className: "poolse-transcript__who", children: [
6416
+ /* @__PURE__ */ jsx("span", { className: "poolse-transcript__name", children: b.name }),
6417
+ /* @__PURE__ */ jsx("span", { className: "poolse-transcript__time", children: formatCallDuration(b.startMs) })
6418
+ ] }),
6419
+ /* @__PURE__ */ jsx("p", { className: "poolse-transcript__text", children: b.segments.map((s, k) => /* @__PURE__ */ jsxs("span", { className: s.final ? void 0 : "poolse-transcript__interim", children: [
6420
+ k > 0 ? " " : "",
6421
+ s.text
6422
+ ] }, k)) })
6423
+ ] }, `${b.speaker}-${b.startMs}-${i}`))
6424
+ }
6425
+ ),
6426
+ error && blocks.length > 0 && /* @__PURE__ */ jsx("p", { className: "poolse-transcript__error", role: "alert", children: error })
6427
+ ]
6428
+ }
6429
+ );
6430
+ }
6431
+ function TranscriptViewer({
6432
+ callId,
6433
+ canRename = true,
6434
+ onSeek,
6435
+ title = "Transcript",
6436
+ className
6437
+ }) {
6438
+ const { transcript, loading, missing, error, renameSpeakers } = useTranscript(callId);
6439
+ const [query, setQuery] = useState("");
6440
+ const [hit, setHit] = useState(0);
6441
+ const blocks = useMemo(() => groupTranscript(transcript?.segments ?? []), [transcript]);
6442
+ const hits = useMemo(() => {
6443
+ const out = [];
6444
+ if (!query.trim()) return out;
6445
+ blocks.forEach(
6446
+ (block, b) => block.segments.forEach((seg, s) => {
6447
+ for (const r of findInText(seg.text, query)) out.push({ b, s, r });
6448
+ })
6449
+ );
6450
+ return out;
6451
+ }, [blocks, query]);
6452
+ useEffect(() => setHit(0), [query]);
6453
+ const body = useRef(null);
6454
+ useEffect(() => {
6455
+ body.current?.querySelector(".poolse-transcript__hit--current")?.scrollIntoView({ block: "center" });
6456
+ }, [hit, hits]);
6457
+ const step = (d) => setHit((h) => hits.length ? (h + d + hits.length) % hits.length : 0);
6458
+ if (!callId) return null;
6459
+ const meta = transcript ? [
6460
+ transcript.started_at ? formatDate(transcript.started_at) : null,
6461
+ duration(transcript),
6462
+ transcript.speakers.length === 1 ? "1 speaker" : `${transcript.speakers.length} speakers`
6463
+ ].filter(Boolean).join(" \xB7 ") : null;
6464
+ return /* @__PURE__ */ jsxs(
6465
+ "section",
6466
+ {
6467
+ className: ["poolse-transcript", "poolse-transcript--viewer", className].filter(Boolean).join(" "),
6468
+ "aria-label": title,
6469
+ children: [
6470
+ /* @__PURE__ */ jsx("header", { className: "poolse-transcript__head", children: /* @__PURE__ */ jsxs("span", { className: "poolse-transcript__heading", children: [
6471
+ /* @__PURE__ */ jsx("span", { className: "poolse-transcript__title", children: title }),
6472
+ meta && /* @__PURE__ */ jsx("span", { className: "poolse-transcript__meta", children: meta })
6473
+ ] }) }),
6474
+ transcript && transcript.segments.length > 0 && /* @__PURE__ */ jsxs("div", { className: "poolse-transcript__search", role: "search", children: [
6475
+ /* @__PURE__ */ jsx(PoolseIcon, { name: "search", size: 15, label: null }),
6476
+ /* @__PURE__ */ jsx(
6477
+ "input",
6478
+ {
6479
+ type: "search",
6480
+ value: query,
6481
+ onChange: (e) => setQuery(e.target.value),
6482
+ onKeyDown: (e) => {
6483
+ if (e.key === "Enter") {
6484
+ e.preventDefault();
6485
+ step(e.shiftKey ? -1 : 1);
6486
+ }
6487
+ },
6488
+ placeholder: "Search the transcript",
6489
+ "aria-label": "Search the transcript"
6490
+ }
6491
+ ),
6492
+ query.trim() && /* @__PURE__ */ jsxs(Fragment, { children: [
6493
+ /* @__PURE__ */ jsx("span", { className: "poolse-transcript__count", "aria-live": "polite", children: hits.length ? `${hit + 1} of ${hits.length}` : "No matches" }),
6494
+ /* @__PURE__ */ jsx(
6495
+ "button",
6496
+ {
6497
+ type: "button",
6498
+ className: "poolse-transcript__icon-btn",
6499
+ onClick: () => step(-1),
6500
+ disabled: !hits.length,
6501
+ "aria-label": "Previous match",
6502
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "chevron-up", size: 15, label: null })
6503
+ }
6504
+ ),
6505
+ /* @__PURE__ */ jsx(
6506
+ "button",
6507
+ {
6508
+ type: "button",
6509
+ className: "poolse-transcript__icon-btn",
6510
+ onClick: () => step(1),
6511
+ disabled: !hits.length,
6512
+ "aria-label": "Next match",
6513
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "chevron-down", size: 15, label: null })
6514
+ }
6515
+ )
6516
+ ] })
6517
+ ] }),
6518
+ transcript && transcript.speakers.length > 0 && /* @__PURE__ */ jsx(
6519
+ SpeakerList,
6520
+ {
6521
+ speakers: transcript.speakers,
6522
+ canRename,
6523
+ onRename: renameSpeakers
6524
+ }
6525
+ ),
6526
+ /* @__PURE__ */ jsx("div", { ref: body, className: "poolse-transcript__body", children: loading && !transcript ? /* @__PURE__ */ jsx("p", { className: "poolse-transcript__empty", children: "Loading the transcript\u2026" }) : missing ? /* @__PURE__ */ jsx("p", { className: "poolse-transcript__empty", children: "This call has no transcript." }) : error && !transcript ? /* @__PURE__ */ jsx("p", { className: "poolse-transcript__empty", children: transcriptError(error) }) : transcript && transcript.segments.length === 0 ? /* @__PURE__ */ jsx("p", { className: "poolse-transcript__empty", children: "Nothing was said in this call." }) : blocks.map((block, b) => /* @__PURE__ */ jsxs(
6527
+ "div",
6528
+ {
6529
+ className: "poolse-transcript__block",
6530
+ children: [
6531
+ /* @__PURE__ */ jsxs("div", { className: "poolse-transcript__who", children: [
6532
+ /* @__PURE__ */ jsx("span", { className: "poolse-transcript__name", children: block.name }),
6533
+ onSeek ? /* @__PURE__ */ jsx(
6534
+ "button",
6535
+ {
6536
+ type: "button",
6537
+ className: "poolse-transcript__time poolse-transcript__time--link",
6538
+ onClick: () => onSeek(block.startMs),
6539
+ "aria-label": `Play from ${formatCallDuration(block.startMs)}`,
6540
+ children: formatCallDuration(block.startMs)
6541
+ }
6542
+ ) : /* @__PURE__ */ jsx("span", { className: "poolse-transcript__time", children: formatCallDuration(block.startMs) })
6543
+ ] }),
6544
+ /* @__PURE__ */ jsx("p", { className: "poolse-transcript__text", children: block.segments.map((seg, s) => /* @__PURE__ */ jsxs("span", { children: [
6545
+ s > 0 ? " " : "",
6546
+ highlight(seg, hits, b, s, hit)
6547
+ ] }, s)) })
6548
+ ]
6549
+ },
6550
+ `${block.speaker}-${block.startMs}-${b}`
6551
+ )) })
6552
+ ]
6553
+ }
6554
+ );
6555
+ }
6556
+ function SpeakerList({
6557
+ speakers,
6558
+ canRename,
6559
+ onRename
6560
+ }) {
6561
+ const [editing, setEditing] = useState(null);
6562
+ const [draft, setDraft] = useState("");
6563
+ const [busy, setBusy] = useState(false);
6564
+ const [error, setError] = useState(null);
6565
+ const save = async (key, name) => {
6566
+ setBusy(true);
6567
+ setError(null);
6568
+ try {
6569
+ await onRename({ [key]: name });
6570
+ setEditing(null);
6571
+ } catch (err) {
6572
+ setError(
6573
+ err instanceof ApiError && err.status === 403 ? "Only people who were in the call can rename speakers." : err instanceof ApiError && err.code === "validation_failed" ? "Names can be up to 100 characters." : "The name could not be saved. Try again."
6574
+ );
6575
+ } finally {
6576
+ setBusy(false);
6577
+ }
6578
+ };
6579
+ return /* @__PURE__ */ jsxs("div", { className: "poolse-transcript__speakers", children: [
6580
+ /* @__PURE__ */ jsx("ul", { "aria-label": "Speakers", children: speakers.map((sp) => /* @__PURE__ */ jsx("li", { className: "poolse-transcript__speaker", children: editing === sp.key ? /* @__PURE__ */ jsxs(
6581
+ "form",
6582
+ {
6583
+ className: "poolse-transcript__rename",
6584
+ onSubmit: (e) => {
6585
+ e.preventDefault();
6586
+ const name = draft.trim();
6587
+ if (name) void save(sp.key, name);
6588
+ },
6589
+ children: [
6590
+ /* @__PURE__ */ jsx(
6591
+ "input",
6592
+ {
6593
+ value: draft,
6594
+ onChange: (e) => setDraft(e.target.value),
6595
+ maxLength: 100,
6596
+ "aria-label": "Speaker name",
6597
+ autoFocus: true,
6598
+ onKeyDown: (e) => {
6599
+ if (e.key === "Escape") setEditing(null);
6600
+ }
6601
+ }
6602
+ ),
6603
+ /* @__PURE__ */ jsx("button", { type: "submit", disabled: busy || !draft.trim(), children: "Save" }),
6604
+ sp.corrected && /* @__PURE__ */ jsx("button", { type: "button", disabled: busy, onClick: () => void save(sp.key, null), children: "Use their own name" }),
6605
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: busy, onClick: () => setEditing(null), children: "Cancel" })
6606
+ ]
6607
+ }
6608
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
6609
+ /* @__PURE__ */ jsx("span", { className: "poolse-transcript__speaker-name", title: sp.name ?? void 0, children: sp.name?.trim() || "Speaker" }),
6610
+ canRename && /* @__PURE__ */ jsx(
6611
+ "button",
6612
+ {
6613
+ type: "button",
6614
+ className: "poolse-transcript__icon-btn",
6615
+ onClick: () => {
6616
+ setDraft(sp.name ?? "");
6617
+ setError(null);
6618
+ setEditing(sp.key);
6619
+ },
6620
+ "aria-label": `Rename ${sp.name?.trim() || "speaker"}`,
6621
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "edit", size: 13, label: null })
6622
+ }
6623
+ )
6624
+ ] }) }, sp.key)) }),
6625
+ error && /* @__PURE__ */ jsx("p", { className: "poolse-transcript__error", role: "alert", children: error })
6626
+ ] });
6627
+ }
6628
+ function highlight(seg, hits, b, s, current) {
6629
+ const mine = hits.map((h, i) => ({ ...h, i })).filter((h) => h.b === b && h.s === s);
6630
+ if (!mine.length) return seg.text;
6631
+ const out = [];
6632
+ let at = 0;
6633
+ for (const h of mine) {
6634
+ if (h.r[0] > at) out.push(seg.text.slice(at, h.r[0]));
6635
+ out.push(
6636
+ /* @__PURE__ */ jsx(
6637
+ "mark",
6638
+ {
6639
+ className: `poolse-transcript__hit${h.i === current ? " poolse-transcript__hit--current" : ""}`,
6640
+ children: seg.text.slice(h.r[0], h.r[1])
6641
+ },
6642
+ h.i
6643
+ )
6644
+ );
6645
+ at = h.r[1];
6646
+ }
6647
+ if (at < seg.text.length) out.push(seg.text.slice(at));
6648
+ return out;
6649
+ }
6650
+ function duration(t) {
6651
+ if (!t.started_at || !t.ended_at) return null;
6652
+ const ms = Date.parse(t.ended_at) - Date.parse(t.started_at);
6653
+ return Number.isFinite(ms) && ms > 0 ? formatCallDuration(ms) : null;
6654
+ }
6655
+ function formatDate(iso) {
6656
+ const d = new Date(iso);
6657
+ if (Number.isNaN(d.getTime())) return null;
6658
+ return d.toLocaleString(void 0, {
6659
+ month: "short",
6660
+ day: "numeric",
6661
+ hour: "2-digit",
6662
+ minute: "2-digit"
6663
+ });
6664
+ }
6665
+ function transcriptError(err) {
6666
+ const code = err instanceof ApiError ? err.code : err.message;
6667
+ if (code === "forbidden") return "You can\u2019t open this transcript.";
6668
+ if (code === "not_found") return "There is no transcript for this call.";
6669
+ return captureErrorMessage(err instanceof ApiError ? err : { code });
6670
+ }
5684
6671
  var ThemeContext = createContext(null);
5685
6672
  var DARK_QUERY = "(prefers-color-scheme: dark)";
5686
6673
  function systemScheme() {
@@ -5844,6 +6831,6 @@ function PoolseLogo({
5844
6831
  );
5845
6832
  }
5846
6833
 
5847
- export { AttachmentPreview, Avatar, CallControlButton, CallDeviceMenu, CallLogRow, CallVideoGrid, ChatHeader, ConversationList, ConversationView, EditableMessageBubble, EditedLabel, EmojiPicker, GroupDetailsSheet, LinkPreviewCard, LiveCallBanner, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseInbox, PoolseLogo, PoolseTheme, PresenceBadge, ReactionPicker, ReactionStrip, RoomJoinBar, RoomStage, ThreadSummary, ThreadView, TypingIndicator, UploadQueueStrip, UserName, UserPickerSheet, formatRelativeTime, loadEmojiData, localDraftStorage, presenceStateLabel, presenceText, useDisplayName, useEditHistory, usePoolseFonts, useSystemColorScheme, useTheme };
6834
+ export { AttachmentPreview, Avatar, CallControlButton, CallDeviceMenu, CallLogRow, CallVideoGrid, ChatHeader, ConsentPrompt, ConversationList, ConversationView, DEFAULT_KEYMAP, DraftScope, EditableMessageBubble, EditedLabel, EmojiPicker, EmptyState, GroupDetailsSheet, LinkPreviewCard, LiveCallBanner, LiveTranscriptPanel, MOD_ENTER_COMPOSER, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseInbox, PoolseLogo, PoolseTheme, PresenceBadge, ReactionPicker, ReactionStrip, RecordingBanner, RecordingIndicator, RecordingNoticeRow, RoomJoinBar, RoomStage, SendStatus, ThreadSummary, ThreadView, TranscriptViewer, TypingIndicator, UploadQueueStrip, UserName, UserPickerSheet, draftsOf, formatRelativeTime, loadEmojiData, localDraftStorage, matchesAny, matchesKey, presenceStateLabel, presenceText, resolveKeymap, useDisplayName, useEditHistory, usePoolseFonts, useSystemColorScheme, useTheme };
5848
6835
  //# sourceMappingURL=index.js.map
5849
6836
  //# sourceMappingURL=index.js.map