@poolse/react-ui 3.10.1 → 3.10.2

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/CHANGELOG.md CHANGED
@@ -4,6 +4,32 @@ All notable changes to `@poolse/react-ui` are documented here. Format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
5
5
  [semver](https://semver.org).
6
6
 
7
+ ## [3.10.2] - 2026-11-23
8
+
9
+ ### Added
10
+
11
+ - `ConversationView` / `ThreadView`: `composerProps` (passed through to the
12
+ composer; `onValueChange` / `onTyping` run alongside the view's own),
13
+ `composerAccessory` (rendered above the composer), `composerHandle` (ref:
14
+ `focus`, `insertText`, `setText`, `getText`, `clear`, `addFiles`) and
15
+ `beforeSend` (`async (draft) => draft | false`: change or cancel a send;
16
+ cancelled, the text and files stay). `ConversationView` passes
17
+ `composerProps` and `beforeSend` on to its thread pane.
18
+ - `MessageComposerHandle` (exported) gains `insertText` and `clear`; a
19
+ composer's `onSend` resolving to `false` keeps the draft. Types
20
+ `BeforeSend`, `ComposerPassThroughProps`.
21
+
22
+ ### Fixed
23
+
24
+ - `Avatar` works outside a `PoolseProvider` (a public booking page):
25
+ `presence={true}` then draws no badge instead of throwing, and a broken
26
+ `src` falls back to the initials.
27
+
28
+ ### Changed
29
+
30
+ - `MessageComposer` keeps sent files' chips until the send finishes
31
+ (they used to vanish as Send was pressed), so a held-back send keeps them.
32
+
7
33
  ## [3.10.0] - 2026-11-23
8
34
 
9
35
  ### Added
package/README.md CHANGED
@@ -103,6 +103,12 @@ preview>` draws one on its own.
103
103
  - **Drafts** per conversation (text and quote) survive switching and reloads;
104
104
  `persistDrafts={false}` turns them off, `draftStorage={{ get, set, remove }}`
105
105
  stores them elsewhere.
106
+ - **Composer hooks** (`ConversationView` and `ThreadView`): `composerProps`
107
+ go to the composer (`placeholder`, `disabled`, `formattingToolbar`,
108
+ `commands`…), `composerAccessory` renders above it, `composerHandle` is a
109
+ ref with `focus`, `insertText` (at the caret), `setText`, `getText`,
110
+ `clear`, `addFiles`, and `beforeSend={async (draft) => draft | false}`
111
+ changes or cancels a send (cancelled, the text and files stay).
106
112
  - **Unread.** A "New messages" divider above the first unread message (from
107
113
  where you'd read to when you opened the conversation), a "Jump to first
108
114
  unread" pill while it's off-screen, and a "Mark unread" action on others'
package/dist/index.cjs CHANGED
@@ -2378,6 +2378,8 @@ function Avatar({
2378
2378
  className
2379
2379
  }) {
2380
2380
  const initials = computeInitials(name);
2381
+ const [failedSrc, setFailedSrc] = react.useState(null);
2382
+ const showImage = !!src && failedSrc !== src;
2381
2383
  const classes = [
2382
2384
  "poolse-avatar",
2383
2385
  size !== "md" ? `poolse-avatar--${size}` : null,
@@ -2385,7 +2387,7 @@ function Avatar({
2385
2387
  className
2386
2388
  ].filter(Boolean).join(" ");
2387
2389
  const label = agent ? `${name ?? "Agent"} (agent)` : name ?? "avatar";
2388
- const badge = presence === true ? userId ? /* @__PURE__ */ jsxRuntime.jsx(LivePresenceBadge, { userId, size }) : null : presence ? typeof presence === "string" ? /* @__PURE__ */ jsxRuntime.jsx(PresenceBadge, { state: presence, size, className: "poolse-avatar__badge" }) : /* @__PURE__ */ jsxRuntime.jsx(
2390
+ const badge = presence === true ? userId ? /* @__PURE__ */ jsxRuntime.jsx(OptionalLivePresenceBadge, { userId, size }) : null : presence ? typeof presence === "string" ? /* @__PURE__ */ jsxRuntime.jsx(PresenceBadge, { state: presence, size, className: "poolse-avatar__badge" }) : /* @__PURE__ */ jsxRuntime.jsx(
2389
2391
  PresenceBadge,
2390
2392
  {
2391
2393
  state: presence.state,
@@ -2395,11 +2397,14 @@ function Avatar({
2395
2397
  }
2396
2398
  ) : online ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null;
2397
2399
  return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: classes, "aria-label": label, role: "img", children: [
2398
- src ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: initials }),
2400
+ showImage ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: name ?? "", onError: () => setFailedSrc(src) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: initials }),
2399
2401
  agent && size !== "xs" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-avatar__agent", "aria-hidden": "true" }) : null,
2400
2402
  badge
2401
2403
  ] });
2402
2404
  }
2405
+ function OptionalLivePresenceBadge(props) {
2406
+ return react$1.useOptionalPoolse() ? /* @__PURE__ */ jsxRuntime.jsx(LivePresenceBadge, { ...props }) : null;
2407
+ }
2403
2408
  function LivePresenceBadge({ userId, size }) {
2404
2409
  const presence = react$1.useUserPresence(userId);
2405
2410
  if (!presence) return null;
@@ -3170,6 +3175,8 @@ var MentionInput = react.forwardRef(
3170
3175
  addFiles,
3171
3176
  getText: () => valueRef.current,
3172
3177
  setText: (text) => setValue(text),
3178
+ insertText: (text) => setValue((v) => insertAtCaret(v, text, taRef)),
3179
+ clear: () => setValue(""),
3173
3180
  focus: () => taRef.current?.focus()
3174
3181
  }),
3175
3182
  [addFiles]
@@ -3217,11 +3224,11 @@ var MentionInput = react.forwardRef(
3217
3224
  ...replyingTo ? { quoted_message_id: replyingTo.id } : {},
3218
3225
  ...hasReady ? { attachment_ids: ready.map((it) => it.attachment.id) } : {}
3219
3226
  };
3220
- const sent = await dlp.guard(
3221
- trimmed,
3222
- (ack) => onSend(ack ? { ...req, dlp_acknowledged: true } : req)
3223
- );
3224
- if (!sent) return;
3227
+ let kept = false;
3228
+ const sent = await dlp.guard(trimmed, async (ack) => {
3229
+ if (await onSend(ack ? { ...req, dlp_acknowledged: true } : req) === false) kept = true;
3230
+ });
3231
+ if (!sent || kept) return;
3225
3232
  setValue("");
3226
3233
  selectedMentions.current = /* @__PURE__ */ new Map();
3227
3234
  for (const it of ready) uploads.remove(it.localId);
@@ -3601,6 +3608,8 @@ var MessageComposer = react.forwardRef(
3601
3608
  addFiles,
3602
3609
  getText: () => valueRef.current,
3603
3610
  setText: (text) => setValue(text),
3611
+ insertText: (text) => setValue((v) => insertAtCaret(v, text, taRef)),
3612
+ clear: () => setValue(""),
3604
3613
  focus: () => taRef.current?.focus()
3605
3614
  }),
3606
3615
  [addFiles]
@@ -3615,15 +3624,21 @@ var MessageComposer = react.forwardRef(
3615
3624
  ...hasReady ? { attachment_ids: ready.map((it) => it.attachment.id) } : {}
3616
3625
  };
3617
3626
  setValue("");
3618
- for (const it of ready) uploads.remove(it.localId);
3619
- uploads.clearRejected();
3620
3627
  setSending(true);
3621
3628
  try {
3622
- const sent = await dlp.guard(trimmed, (ack) => {
3629
+ let kept = false;
3630
+ const sent = await dlp.guard(trimmed, async (ack) => {
3623
3631
  const o = ack ? { ...opts, dlp_acknowledged: true } : opts;
3624
- return onSend(trimmed, Object.keys(o).length > 0 ? o : void 0);
3632
+ if (await onSend(trimmed, Object.keys(o).length > 0 ? o : void 0) === false) {
3633
+ kept = true;
3634
+ }
3625
3635
  });
3626
- if (!sent) setValue((now) => now ? now : trimmed);
3636
+ if (sent && !kept) {
3637
+ for (const it of ready) uploads.remove(it.localId);
3638
+ uploads.clearRejected();
3639
+ } else {
3640
+ setValue((now) => now ? now : trimmed);
3641
+ }
3627
3642
  } finally {
3628
3643
  setSending(false);
3629
3644
  }
@@ -6546,7 +6561,11 @@ function ThreadView({
6546
6561
  maxFileSize,
6547
6562
  acceptFileTypes,
6548
6563
  follow = true,
6549
- alsoSendToChannel = true
6564
+ alsoSendToChannel = true,
6565
+ composerProps,
6566
+ composerAccessory,
6567
+ composerHandle,
6568
+ beforeSend
6550
6569
  }) {
6551
6570
  const { me } = react$1.useMe();
6552
6571
  const followState = react$1.useThreadFollow(follow ? rootMessage.id : null);
@@ -6569,6 +6588,18 @@ function ThreadView({
6569
6588
  const closeBtnRef = react.useRef(null);
6570
6589
  const lastReplyIdRef = react.useRef(null);
6571
6590
  const composerRef = react.useRef(null);
6591
+ react.useImperativeHandle(
6592
+ composerHandle,
6593
+ () => ({
6594
+ addFiles: (files) => composerRef.current?.addFiles(files),
6595
+ getText: () => composerRef.current?.getText() ?? "",
6596
+ setText: (text) => composerRef.current?.setText(text),
6597
+ insertText: (text) => composerRef.current?.insertText(text),
6598
+ clear: () => composerRef.current?.clear(),
6599
+ focus: () => composerRef.current?.focus()
6600
+ }),
6601
+ []
6602
+ );
6572
6603
  const [dragActive, setDragActive] = react.useState(false);
6573
6604
  const dragDepthRef = react.useRef(0);
6574
6605
  const isFileDrag = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
@@ -6692,22 +6723,31 @@ function ThreadView({
6692
6723
  error.message
6693
6724
  ] })
6694
6725
  ] }),
6726
+ composerAccessory,
6695
6727
  /* @__PURE__ */ jsxRuntime.jsx(
6696
6728
  MessageComposer,
6697
6729
  {
6698
6730
  ref: composerRef,
6699
6731
  onSend: async (body, opts) => {
6700
- await sendReply({
6732
+ let draft = {
6701
6733
  body,
6702
6734
  ...opts?.attachment_ids && opts.attachment_ids.length > 0 ? { attachment_ids: opts.attachment_ids } : {},
6703
6735
  ...opts?.dlp_acknowledged ? { dlp_acknowledged: true } : {},
6704
6736
  ...alsoSendToChannel && alsoToChannel ? { also_send_to_channel: true } : {}
6705
- });
6737
+ };
6738
+ if (beforeSend) {
6739
+ const changed = await beforeSend(draft);
6740
+ if (changed === false) return false;
6741
+ draft = changed;
6742
+ }
6743
+ await sendReply(draft);
6706
6744
  setAlsoToChannel(false);
6745
+ return void 0;
6707
6746
  },
6708
6747
  placeholder: "Reply in thread\u2026",
6709
6748
  ...maxFileSize !== void 0 ? { maxFileSize } : {},
6710
- ...acceptFileTypes ? { acceptFileTypes } : {}
6749
+ ...acceptFileTypes ? { acceptFileTypes } : {},
6750
+ ...composerProps
6711
6751
  }
6712
6752
  ),
6713
6753
  alsoSendToChannel && /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "poolse-thread__also", children: [
@@ -6817,7 +6857,11 @@ function ConversationView({
6817
6857
  keymap: keymapOverrides,
6818
6858
  sendOn = "enter",
6819
6859
  keyboardShortcuts = TRUE,
6820
- confirmDelete
6860
+ confirmDelete,
6861
+ composerProps,
6862
+ composerAccessory,
6863
+ composerHandle,
6864
+ beforeSend
6821
6865
  }) {
6822
6866
  usePoolseFonts(loadFonts);
6823
6867
  const showComposer = composer && !readOnly;
@@ -7220,6 +7264,18 @@ function ConversationView({
7220
7264
  highlightRow(el);
7221
7265
  };
7222
7266
  const composerRef = react.useRef(null);
7267
+ react.useImperativeHandle(
7268
+ composerHandle,
7269
+ () => ({
7270
+ addFiles: (files) => composerRef.current?.addFiles(files),
7271
+ getText: () => composerRef.current?.getText() ?? "",
7272
+ setText: (text) => composerRef.current?.setText(text),
7273
+ insertText: (text) => composerRef.current?.insertText(text),
7274
+ clear: () => composerRef.current?.clear(),
7275
+ focus: () => composerRef.current?.focus()
7276
+ }),
7277
+ []
7278
+ );
7223
7279
  const [dragActive, setDragActive] = react.useState(false);
7224
7280
  const dragDepthRef = react.useRef(0);
7225
7281
  const isFileDrag = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
@@ -7249,7 +7305,13 @@ function ConversationView({
7249
7305
  if (files.length > 0) composerRef.current?.addFiles(files);
7250
7306
  };
7251
7307
  const sendRequest = async (input) => {
7252
- const req = { ...sendDefaults, ...input, id: input.id ?? sdk.safeUuid() };
7308
+ let draft = { ...sendDefaults, ...input };
7309
+ if (beforeSend) {
7310
+ const changed = await beforeSend(draft);
7311
+ if (changed === false) return false;
7312
+ draft = changed;
7313
+ }
7314
+ const req = { ...draft, id: draft.id ?? sdk.safeUuid() };
7253
7315
  try {
7254
7316
  await send(req);
7255
7317
  } catch (err) {
@@ -7362,20 +7424,30 @@ function ConversationView({
7362
7424
  ...maxFileSize !== void 0 ? { maxFileSize } : {},
7363
7425
  ...acceptFileTypes ? { acceptFileTypes } : {}
7364
7426
  };
7427
+ const passThrough = {
7428
+ ...composerProps,
7429
+ onValueChange: (text) => {
7430
+ onComposerChange(text);
7431
+ composerProps?.onValueChange?.(text);
7432
+ },
7433
+ onTyping: () => {
7434
+ signalTyping();
7435
+ composerProps?.onTyping?.();
7436
+ },
7437
+ onEditLast: editLast
7438
+ };
7365
7439
  const Composer = mentionComposer ? /* @__PURE__ */ jsxRuntime.jsx(
7366
7440
  MentionInput,
7367
7441
  {
7368
7442
  ref: composerRef,
7369
- onValueChange: onComposerChange,
7370
7443
  conversationId,
7371
7444
  onSend: onSendWithMentions,
7372
- onTyping: signalTyping,
7373
7445
  keymap: keymap.composer,
7374
- onEditLast: editLast,
7375
7446
  attachments,
7376
7447
  emojiPicker,
7377
7448
  ...attachmentRules,
7378
7449
  ...labelFor ? { labelFor } : {},
7450
+ ...passThrough,
7379
7451
  ...canQuote ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
7380
7452
  },
7381
7453
  conversationId
@@ -7383,15 +7455,13 @@ function ConversationView({
7383
7455
  MessageComposer,
7384
7456
  {
7385
7457
  ref: composerRef,
7386
- onValueChange: onComposerChange,
7387
7458
  onSend: onSendBody,
7388
- onTyping: signalTyping,
7389
7459
  keymap: keymap.composer,
7390
- onEditLast: editLast,
7391
7460
  attachments,
7392
7461
  emojiPicker,
7393
7462
  ...attachmentRules,
7394
7463
  ...labelFor ? { labelFor } : {},
7464
+ ...passThrough,
7395
7465
  ...canQuote ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
7396
7466
  },
7397
7467
  conversationId
@@ -7624,7 +7694,10 @@ function ConversationView({
7624
7694
  }
7625
7695
  ),
7626
7696
  /* @__PURE__ */ jsxRuntime.jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
7627
- showComposer && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__composer-row", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__composer-flex", children: Composer }) }),
7697
+ showComposer && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__composer-row", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__composer-flex", children: [
7698
+ composerAccessory,
7699
+ Composer
7700
+ ] }) }),
7628
7701
  dragActive && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__drop-overlay", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__drop-overlay-inner", children: [
7629
7702
  /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "attachment", size: 40, label: null }),
7630
7703
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__drop-overlay-title", children: "Drop files to upload" }),
@@ -7644,7 +7717,9 @@ function ConversationView({
7644
7717
  showAvatars: showAvatarsResolved,
7645
7718
  showPresence,
7646
7719
  linkPreviews,
7647
- ...attachmentRules
7720
+ ...attachmentRules,
7721
+ ...composerProps ? { composerProps } : {},
7722
+ ...beforeSend ? { beforeSend } : {}
7648
7723
  }
7649
7724
  ) })
7650
7725
  ] }) });