@poolse/react-ui 1.0.4 → 1.0.5

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,7 @@
1
1
  'use client';
2
- import { useUser, useMembers, useAttachmentUrl, useReactions, useMe, useThread, useMessages, useTyping, useRealtimeStatus, useAttachmentUpload, useConversations, usePresence } from '@poolse/react';
3
- import { useEffect, useState, useRef, Fragment as Fragment$1, useMemo } from 'react';
4
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { useMembers, useAttachmentUpload, useUser, useAttachmentUrl, useReactions, useMe, useThread, useMessages, useTyping, useRealtimeStatus, useConversations, usePresence } from '@poolse/react';
3
+ import { forwardRef, useState, useRef, useImperativeHandle, useEffect, Fragment as Fragment$1, useMemo } from 'react';
4
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
5
  import ReactMarkdown from 'react-markdown';
6
6
  import remarkGfm from 'remark-gfm';
7
7
 
@@ -317,6 +317,63 @@ function PoolseIcon({
317
317
  }
318
318
  );
319
319
  }
320
+ function UploadQueueStrip({ items, onCancel, onDismiss }) {
321
+ if (items.length === 0) return null;
322
+ return /* @__PURE__ */ jsx("div", { className: "poolse-upload-strip", role: "status", "aria-live": "polite", children: items.map((item) => /* @__PURE__ */ jsx(
323
+ UploadChip,
324
+ {
325
+ item,
326
+ onCancel: () => onCancel(item.localId),
327
+ onDismiss: () => onDismiss(item.localId)
328
+ },
329
+ item.localId
330
+ )) });
331
+ }
332
+ function UploadChip({
333
+ item,
334
+ onCancel,
335
+ onDismiss
336
+ }) {
337
+ const pct = item.byteSize > 0 ? Math.min(100, Math.round(item.loaded / item.byteSize * 100)) : 0;
338
+ const isError = item.status === "error";
339
+ const isInFlight = item.status === "pending" || item.status === "uploading";
340
+ return /* @__PURE__ */ jsxs(
341
+ "div",
342
+ {
343
+ className: `poolse-upload-chip poolse-upload-chip--${item.status}`,
344
+ "data-status": item.status,
345
+ children: [
346
+ /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx(PoolseIcon, { name: isError ? "attachment" : "attachment", size: 18, label: null }) }),
347
+ /* @__PURE__ */ jsxs("div", { className: "poolse-upload-chip__body", children: [
348
+ /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__filename", title: item.filename, children: item.filename }),
349
+ isError ? /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__error", children: item.error?.message ?? "Upload failed" }) : /* @__PURE__ */ jsx(
350
+ "div",
351
+ {
352
+ className: "poolse-upload-chip__bar",
353
+ role: "progressbar",
354
+ "aria-valuemin": 0,
355
+ "aria-valuemax": 100,
356
+ "aria-valuenow": pct,
357
+ "aria-label": `Uploading ${item.filename}`,
358
+ children: /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__bar-fill", style: { width: `${pct}%` } })
359
+ }
360
+ )
361
+ ] }),
362
+ /* @__PURE__ */ jsx(
363
+ "button",
364
+ {
365
+ type: "button",
366
+ className: "poolse-upload-chip__action",
367
+ onClick: isInFlight ? onCancel : onDismiss,
368
+ "aria-label": isInFlight ? `Cancel upload of ${item.filename}` : `Dismiss ${item.filename}`,
369
+ title: isInFlight ? "Cancel" : "Dismiss",
370
+ children: "\xD7"
371
+ }
372
+ )
373
+ ]
374
+ }
375
+ );
376
+ }
320
377
  var MAX_NAME_CHARS = 24;
321
378
  function UserName({
322
379
  userId,
@@ -342,317 +399,467 @@ function truncate(s) {
342
399
  if (s.length <= MAX_NAME_CHARS) return s;
343
400
  return s.slice(0, MAX_NAME_CHARS - 1) + "\u2026";
344
401
  }
345
- function MentionInput({
346
- conversationId,
347
- onSend,
348
- onTyping,
349
- placeholder = "Type a message\u2026",
350
- disabled = false,
351
- labelFor,
352
- replyingTo,
353
- onCancelReply
354
- }) {
355
- const { members } = useMembers(conversationId);
356
- const [value, setValue] = useState("");
357
- const [sending, setSending] = useState(false);
358
- const [mention, setMention] = useState(null);
359
- const [activeIdx, setActiveIdx] = useState(0);
360
- const selectedMentions = useRef(/* @__PURE__ */ new Set());
361
- const taRef = useRef(null);
362
- const label = labelFor ?? ((id) => id.slice(0, 8));
363
- const filtered = mention ? members.filter((m) => label(m.user_id).toLowerCase().includes(mention.query.toLowerCase())) : [];
402
+ function useAutogrow(ref, value) {
364
403
  useEffect(() => {
365
- setActiveIdx(0);
366
- }, [filtered.length, mention?.query]);
367
- const submit = async () => {
368
- const trimmed = value.trim();
369
- if (!trimmed || sending) return;
370
- setSending(true);
371
- try {
372
- const mentions = Array.from(selectedMentions.current);
373
- await onSend({
374
- body: trimmed,
375
- ...mentions.length > 0 ? { mentions } : {},
376
- ...replyingTo ? { quoted_message_id: replyingTo.id } : {}
404
+ const ta = ref.current;
405
+ if (!ta) return;
406
+ ta.style.height = "auto";
407
+ ta.style.height = `${ta.scrollHeight}px`;
408
+ }, [ref, value]);
409
+ }
410
+ var MentionInput = forwardRef(
411
+ function MentionInput2({
412
+ conversationId,
413
+ onSend,
414
+ onTyping,
415
+ placeholder = "Type a message\u2026",
416
+ disabled = false,
417
+ labelFor,
418
+ replyingTo,
419
+ onCancelReply,
420
+ attachments = true
421
+ }, ref) {
422
+ const { members } = useMembers(conversationId);
423
+ const [value, setValue] = useState("");
424
+ const [sending, setSending] = useState(false);
425
+ const [mention, setMention] = useState(null);
426
+ const [activeIdx, setActiveIdx] = useState(0);
427
+ const selectedMentions = useRef(/* @__PURE__ */ new Set());
428
+ const taRef = useRef(null);
429
+ const fileInputRef = useRef(null);
430
+ useAutogrow(taRef, value);
431
+ const { queue, uploadAll, cancel: cancelUpload, remove: removeUpload } = useAttachmentUpload();
432
+ const visibleUploads = queue.filter(
433
+ (it) => it.status === "pending" || it.status === "uploading" || it.status === "error"
434
+ );
435
+ const readyCount = queue.filter((it) => it.status === "ready").length;
436
+ const uploading = queue.some((it) => it.status === "pending" || it.status === "uploading");
437
+ const addFiles = (files) => {
438
+ if (!attachments || files.length === 0) return;
439
+ void uploadAll(
440
+ files.map((f) => ({
441
+ body: f,
442
+ contentType: f.type || "application/octet-stream",
443
+ byteSize: f.size,
444
+ filename: f.name
445
+ }))
446
+ ).catch(() => {
377
447
  });
378
- setValue("");
379
- selectedMentions.current = /* @__PURE__ */ new Set();
380
- } finally {
381
- setSending(false);
382
- }
383
- };
384
- const insertMention = (m) => {
385
- if (!mention) return;
386
- const name = label(m.user_id);
387
- const before = value.slice(0, mention.start);
388
- const after = value.slice(mention.start + 1 + mention.query.length);
389
- const inserted = `@${name} `;
390
- const next = `${before}${inserted}${after}`;
391
- selectedMentions.current.add(m.user_id);
392
- setValue(next);
393
- setMention(null);
394
- requestAnimationFrame(() => {
395
- const ta = taRef.current;
396
- if (!ta) return;
397
- const pos = before.length + inserted.length;
398
- ta.focus();
399
- ta.setSelectionRange(pos, pos);
400
- });
401
- };
402
- const onChange = (e) => {
403
- const next = e.target.value;
404
- setValue(next);
405
- onTyping?.();
406
- const caret = e.target.selectionStart ?? next.length;
407
- const head = next.slice(0, caret);
408
- const at = head.lastIndexOf("@");
409
- if (at === -1) {
410
- setMention(null);
411
- return;
412
- }
413
- const charBefore = at === 0 ? " " : head.charAt(at - 1);
414
- const isAtBoundary = /\s/.test(charBefore);
415
- const query = head.slice(at + 1);
416
- if (isAtBoundary && !/\s/.test(query)) {
417
- setMention({ start: at, query });
418
- } else {
448
+ };
449
+ useImperativeHandle(ref, () => ({ addFiles }), [addFiles, attachments]);
450
+ const label = labelFor ?? ((id) => id.slice(0, 8));
451
+ const filtered = mention ? members.filter((m) => label(m.user_id).toLowerCase().includes(mention.query.toLowerCase())) : [];
452
+ useEffect(() => {
453
+ setActiveIdx(0);
454
+ }, [filtered.length, mention?.query]);
455
+ const submit = async () => {
456
+ const trimmed = value.trim();
457
+ const ready = queue.filter((it) => it.status === "ready");
458
+ const hasReady = ready.length > 0;
459
+ if (!trimmed && !hasReady || sending || uploading) return;
460
+ setSending(true);
461
+ try {
462
+ const mentions = Array.from(selectedMentions.current);
463
+ await onSend({
464
+ body: trimmed,
465
+ ...mentions.length > 0 ? { mentions } : {},
466
+ ...replyingTo ? { quoted_message_id: replyingTo.id } : {},
467
+ ...hasReady ? { attachment_ids: ready.map((it) => it.attachment.id) } : {}
468
+ });
469
+ setValue("");
470
+ selectedMentions.current = /* @__PURE__ */ new Set();
471
+ for (const it of ready) removeUpload(it.localId);
472
+ } finally {
473
+ setSending(false);
474
+ }
475
+ };
476
+ const insertMention = (m) => {
477
+ if (!mention) return;
478
+ const name = label(m.user_id);
479
+ const before = value.slice(0, mention.start);
480
+ const after = value.slice(mention.start + 1 + mention.query.length);
481
+ const inserted = `@${name} `;
482
+ const next = `${before}${inserted}${after}`;
483
+ selectedMentions.current.add(m.user_id);
484
+ setValue(next);
419
485
  setMention(null);
420
- }
421
- };
422
- const onKeyDown = (e) => {
423
- if (mention && filtered.length > 0) {
424
- if (e.key === "ArrowDown") {
425
- e.preventDefault();
426
- setActiveIdx((i) => (i + 1) % filtered.length);
486
+ requestAnimationFrame(() => {
487
+ const ta = taRef.current;
488
+ if (!ta) return;
489
+ const pos = before.length + inserted.length;
490
+ ta.focus();
491
+ ta.setSelectionRange(pos, pos);
492
+ });
493
+ };
494
+ const onChange = (e) => {
495
+ const next = e.target.value;
496
+ setValue(next);
497
+ onTyping?.();
498
+ const caret = e.target.selectionStart ?? next.length;
499
+ const head = next.slice(0, caret);
500
+ const at = head.lastIndexOf("@");
501
+ if (at === -1) {
502
+ setMention(null);
427
503
  return;
428
504
  }
429
- if (e.key === "ArrowUp") {
430
- e.preventDefault();
431
- setActiveIdx((i) => (i - 1 + filtered.length) % filtered.length);
432
- return;
505
+ const charBefore = at === 0 ? " " : head.charAt(at - 1);
506
+ const isAtBoundary = /\s/.test(charBefore);
507
+ const query = head.slice(at + 1);
508
+ if (isAtBoundary && !/\s/.test(query)) {
509
+ setMention({ start: at, query });
510
+ } else {
511
+ setMention(null);
433
512
  }
434
- if (e.key === "Enter" || e.key === "Tab") {
435
- const pick = filtered[activeIdx];
436
- if (pick) {
513
+ };
514
+ const onKeyDown = (e) => {
515
+ if (mention && filtered.length > 0) {
516
+ if (e.key === "ArrowDown") {
517
+ e.preventDefault();
518
+ setActiveIdx((i) => (i + 1) % filtered.length);
519
+ return;
520
+ }
521
+ if (e.key === "ArrowUp") {
522
+ e.preventDefault();
523
+ setActiveIdx((i) => (i - 1 + filtered.length) % filtered.length);
524
+ return;
525
+ }
526
+ if (e.key === "Enter" || e.key === "Tab") {
527
+ const pick = filtered[activeIdx];
528
+ if (pick) {
529
+ e.preventDefault();
530
+ insertMention(pick);
531
+ return;
532
+ }
533
+ }
534
+ if (e.key === "Escape") {
437
535
  e.preventDefault();
438
- insertMention(pick);
536
+ setMention(null);
439
537
  return;
440
538
  }
441
539
  }
442
- if (e.key === "Escape") {
540
+ if (e.key === "Enter" && !e.shiftKey) {
541
+ const ta = e.currentTarget;
542
+ const caret = ta.selectionStart;
543
+ const result = handleListEnter(value, caret);
544
+ if (result) {
545
+ e.preventDefault();
546
+ setValue(result.value);
547
+ requestAnimationFrame(() => {
548
+ taRef.current?.setSelectionRange(result.caret, result.caret);
549
+ });
550
+ return;
551
+ }
443
552
  e.preventDefault();
444
- setMention(null);
445
- return;
553
+ void submit();
446
554
  }
447
- }
448
- if (e.key === "Enter" && !e.shiftKey) {
449
- const ta = e.currentTarget;
450
- const caret = ta.selectionStart;
451
- const result = handleListEnter(value, caret);
452
- if (result) {
555
+ if (e.key === "Escape" && replyingTo && onCancelReply && !mention) {
453
556
  e.preventDefault();
454
- setValue(result.value);
455
- requestAnimationFrame(() => {
456
- taRef.current?.setSelectionRange(result.caret, result.caret);
457
- });
458
- return;
557
+ onCancelReply();
459
558
  }
460
- e.preventDefault();
461
- void submit();
462
- }
463
- if (e.key === "Escape" && replyingTo && onCancelReply && !mention) {
464
- e.preventDefault();
465
- onCancelReply();
466
- }
467
- };
468
- const replyLabel = replyingTo?.sender_id ? labelFor?.(replyingTo.sender_id) ?? `User ${replyingTo.sender_id.slice(0, 6)}` : "Unknown";
469
- return /* @__PURE__ */ jsxs(
470
- "form",
471
- {
472
- className: "poolse-composer",
473
- onSubmit: (e) => {
474
- e.preventDefault();
475
- void submit();
476
- },
477
- style: { position: "relative" },
478
- children: [
479
- replyingTo && /* @__PURE__ */ jsxs("div", { className: "poolse-composer__reply", role: "status", children: [
480
- /* @__PURE__ */ jsxs("div", { className: "poolse-composer__reply-body", children: [
481
- /* @__PURE__ */ jsxs("span", { className: "poolse-composer__reply-label", children: [
482
- "Replying to ",
483
- replyLabel
559
+ };
560
+ const replyLabel = replyingTo?.sender_id ? labelFor?.(replyingTo.sender_id) ?? `User ${replyingTo.sender_id.slice(0, 6)}` : "Unknown";
561
+ const canSend = !disabled && !sending && !uploading && (value.trim() !== "" || readyCount > 0);
562
+ return /* @__PURE__ */ jsxs(
563
+ "form",
564
+ {
565
+ className: "poolse-composer",
566
+ onSubmit: (e) => {
567
+ e.preventDefault();
568
+ void submit();
569
+ },
570
+ style: { position: "relative" },
571
+ children: [
572
+ replyingTo && /* @__PURE__ */ jsxs("div", { className: "poolse-composer__reply", role: "status", children: [
573
+ /* @__PURE__ */ jsxs("div", { className: "poolse-composer__reply-body", children: [
574
+ /* @__PURE__ */ jsxs("span", { className: "poolse-composer__reply-label", children: [
575
+ "Replying to ",
576
+ replyLabel
577
+ ] }),
578
+ /* @__PURE__ */ jsx("span", { className: "poolse-composer__reply-preview", children: replyingTo.body ?? "" })
484
579
  ] }),
485
- /* @__PURE__ */ jsx("span", { className: "poolse-composer__reply-preview", children: replyingTo.body ?? "" })
580
+ onCancelReply && /* @__PURE__ */ jsx(
581
+ "button",
582
+ {
583
+ type: "button",
584
+ className: "poolse-composer__reply-cancel",
585
+ onClick: onCancelReply,
586
+ "aria-label": "Cancel reply",
587
+ title: "Cancel reply",
588
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "close", size: 14, label: null })
589
+ }
590
+ )
486
591
  ] }),
487
- onCancelReply && /* @__PURE__ */ jsx(
488
- "button",
489
- {
490
- type: "button",
491
- className: "poolse-composer__reply-cancel",
492
- onClick: onCancelReply,
493
- "aria-label": "Cancel reply",
494
- title: "Cancel reply",
495
- children: /* @__PURE__ */ jsx(PoolseIcon, { name: "close", size: 14, label: null })
496
- }
497
- )
498
- ] }),
499
- /* @__PURE__ */ jsxs("div", { className: "poolse-composer__row", children: [
500
- /* @__PURE__ */ jsx(
501
- "textarea",
592
+ attachments && visibleUploads.length > 0 && /* @__PURE__ */ jsx(
593
+ UploadQueueStrip,
502
594
  {
503
- ref: taRef,
504
- className: "poolse-composer__input",
505
- rows: 1,
506
- value,
507
- onChange,
508
- onKeyDown,
509
- placeholder,
510
- disabled: disabled || sending,
511
- "aria-label": placeholder,
512
- role: "combobox",
513
- "aria-expanded": Boolean(mention && filtered.length > 0),
514
- "aria-controls": "poolse-mention-menu",
515
- "aria-autocomplete": "list",
516
- ...mention && filtered.length > 0 ? { "aria-activedescendant": `poolse-mention-opt-${activeIdx}` } : {}
595
+ items: visibleUploads,
596
+ onCancel: cancelUpload,
597
+ onDismiss: removeUpload
517
598
  }
518
599
  ),
519
- /* @__PURE__ */ jsx(
520
- "button",
600
+ /* @__PURE__ */ jsxs("div", { className: "poolse-composer__row", children: [
601
+ attachments && /* @__PURE__ */ jsxs(Fragment, { children: [
602
+ /* @__PURE__ */ jsx(
603
+ "input",
604
+ {
605
+ ref: fileInputRef,
606
+ type: "file",
607
+ multiple: true,
608
+ className: "poolse-attach-input",
609
+ onChange: (e) => {
610
+ const files = Array.from(e.target.files ?? []);
611
+ if (files.length > 0) addFiles(files);
612
+ e.target.value = "";
613
+ }
614
+ }
615
+ ),
616
+ /* @__PURE__ */ jsx(
617
+ "button",
618
+ {
619
+ type: "button",
620
+ className: "poolse-composer__attach",
621
+ onClick: () => fileInputRef.current?.click(),
622
+ disabled: disabled || sending,
623
+ "aria-label": "Attach files",
624
+ title: "Attach files",
625
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 20, label: null })
626
+ }
627
+ )
628
+ ] }),
629
+ /* @__PURE__ */ jsx(
630
+ "textarea",
631
+ {
632
+ ref: taRef,
633
+ className: "poolse-composer__input",
634
+ rows: 1,
635
+ value,
636
+ onChange,
637
+ onKeyDown,
638
+ placeholder,
639
+ disabled: disabled || sending,
640
+ "aria-label": placeholder,
641
+ role: "combobox",
642
+ "aria-expanded": Boolean(mention && filtered.length > 0),
643
+ "aria-controls": "poolse-mention-menu",
644
+ "aria-autocomplete": "list",
645
+ ...mention && filtered.length > 0 ? { "aria-activedescendant": `poolse-mention-opt-${activeIdx}` } : {}
646
+ }
647
+ ),
648
+ /* @__PURE__ */ jsx(
649
+ "button",
650
+ {
651
+ type: "submit",
652
+ className: "poolse-composer__send",
653
+ disabled: !canSend,
654
+ "aria-label": "Send message",
655
+ title: uploading ? "Waiting for uploads\u2026" : "Send message",
656
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "send-fill", label: null })
657
+ }
658
+ )
659
+ ] }),
660
+ mention && filtered.length > 0 && /* @__PURE__ */ jsx(
661
+ "div",
521
662
  {
522
- type: "submit",
523
- className: "poolse-composer__send",
524
- disabled: disabled || sending || value.trim() === "",
525
- "aria-label": "Send message",
526
- children: /* @__PURE__ */ jsx(PoolseIcon, { name: "send-fill", label: null })
663
+ id: "poolse-mention-menu",
664
+ className: "poolse-mention-menu",
665
+ role: "listbox",
666
+ "aria-label": "Members",
667
+ children: filtered.map((m, i) => /* @__PURE__ */ jsxs(
668
+ "div",
669
+ {
670
+ id: `poolse-mention-opt-${i}`,
671
+ role: "option",
672
+ "aria-selected": i === activeIdx,
673
+ className: `poolse-mention-menu__item${i === activeIdx ? " poolse-mention-menu__item--active" : ""}`,
674
+ onMouseDown: (e) => {
675
+ e.preventDefault();
676
+ insertMention(m);
677
+ },
678
+ children: [
679
+ /* @__PURE__ */ jsx("span", { children: "@" }),
680
+ /* @__PURE__ */ jsx(UserName, { userId: m.user_id, ...labelFor ? { labelFor } : {} })
681
+ ]
682
+ },
683
+ m.id
684
+ ))
527
685
  }
528
686
  )
529
- ] }),
530
- mention && filtered.length > 0 && /* @__PURE__ */ jsx(
531
- "div",
532
- {
533
- id: "poolse-mention-menu",
534
- className: "poolse-mention-menu",
535
- role: "listbox",
536
- "aria-label": "Members",
537
- children: filtered.map((m, i) => /* @__PURE__ */ jsxs(
538
- "div",
539
- {
540
- id: `poolse-mention-opt-${i}`,
541
- role: "option",
542
- "aria-selected": i === activeIdx,
543
- className: `poolse-mention-menu__item${i === activeIdx ? " poolse-mention-menu__item--active" : ""}`,
544
- onMouseDown: (e) => {
545
- e.preventDefault();
546
- insertMention(m);
547
- },
548
- children: [
549
- /* @__PURE__ */ jsx("span", { children: "@" }),
550
- /* @__PURE__ */ jsx(UserName, { userId: m.user_id, ...labelFor ? { labelFor } : {} })
551
- ]
552
- },
553
- m.id
554
- ))
555
- }
556
- )
557
- ]
558
- }
559
- );
560
- }
561
- function MessageComposer({
562
- onSend,
563
- onTyping,
564
- placeholder = "Type a message\u2026",
565
- disabled = false,
566
- replyingTo,
567
- onCancelReply,
568
- labelFor
569
- }) {
570
- const [value, setValue] = useState("");
571
- const [sending, setSending] = useState(false);
572
- const taRef = useRef(null);
573
- const submit = async () => {
574
- const trimmed = value.trim();
575
- if (!trimmed || sending) return;
576
- setSending(true);
577
- try {
578
- await onSend(trimmed, replyingTo ? { quoted_message_id: replyingTo.id } : void 0);
579
- setValue("");
580
- } finally {
581
- setSending(false);
582
- }
583
- };
584
- const onKeyDown = (e) => {
585
- if (e.key === "Enter" && !e.shiftKey) {
586
- const ta = e.currentTarget;
587
- const caret = ta.selectionStart;
588
- const result = handleListEnter(value, caret);
589
- if (result) {
590
- e.preventDefault();
591
- setValue(result.value);
592
- requestAnimationFrame(() => {
593
- taRef.current?.setSelectionRange(result.caret, result.caret);
594
- });
595
- return;
687
+ ]
596
688
  }
597
- e.preventDefault();
598
- void submit();
599
- }
600
- if (e.key === "Escape" && replyingTo && onCancelReply) {
601
- e.preventDefault();
602
- onCancelReply();
603
- }
604
- };
605
- const onChange = (e) => {
606
- setValue(e.target.value);
607
- onTyping?.();
608
- };
609
- return /* @__PURE__ */ jsxs(
610
- "form",
611
- {
612
- className: "poolse-composer",
613
- onSubmit: (e) => {
689
+ );
690
+ }
691
+ );
692
+ var MessageComposer = forwardRef(
693
+ function MessageComposer2({
694
+ onSend,
695
+ onTyping,
696
+ placeholder = "Type a message\u2026",
697
+ disabled = false,
698
+ replyingTo,
699
+ onCancelReply,
700
+ labelFor,
701
+ attachments = true
702
+ }, ref) {
703
+ const [value, setValue] = useState("");
704
+ const [sending, setSending] = useState(false);
705
+ const taRef = useRef(null);
706
+ const fileInputRef = useRef(null);
707
+ useAutogrow(taRef, value);
708
+ const {
709
+ queue,
710
+ uploadAll,
711
+ cancel: cancelUpload,
712
+ remove: removeUpload
713
+ } = useAttachmentUpload();
714
+ const visibleUploads = queue.filter(
715
+ (it) => it.status === "pending" || it.status === "uploading" || it.status === "error"
716
+ );
717
+ const readyCount = queue.filter((it) => it.status === "ready").length;
718
+ const uploading = queue.some(
719
+ (it) => it.status === "pending" || it.status === "uploading"
720
+ );
721
+ const addFiles = (files) => {
722
+ if (!attachments || files.length === 0) return;
723
+ void uploadAll(
724
+ files.map((f) => ({
725
+ body: f,
726
+ contentType: f.type || "application/octet-stream",
727
+ byteSize: f.size,
728
+ filename: f.name
729
+ }))
730
+ ).catch(() => {
731
+ });
732
+ };
733
+ useImperativeHandle(ref, () => ({ addFiles }), [addFiles, attachments]);
734
+ const submit = async () => {
735
+ const trimmed = value.trim();
736
+ const ready = queue.filter((it) => it.status === "ready");
737
+ const hasReady = ready.length > 0;
738
+ if (!trimmed && !hasReady || sending || uploading) return;
739
+ setSending(true);
740
+ try {
741
+ const opts = {
742
+ ...replyingTo ? { quoted_message_id: replyingTo.id } : {},
743
+ ...hasReady ? { attachment_ids: ready.map((it) => it.attachment.id) } : {}
744
+ };
745
+ await onSend(trimmed, Object.keys(opts).length > 0 ? opts : void 0);
746
+ setValue("");
747
+ for (const it of ready) removeUpload(it.localId);
748
+ } finally {
749
+ setSending(false);
750
+ }
751
+ };
752
+ const onKeyDown = (e) => {
753
+ if (e.key === "Enter" && !e.shiftKey) {
754
+ const ta = e.currentTarget;
755
+ const caret = ta.selectionStart;
756
+ const result = handleListEnter(value, caret);
757
+ if (result) {
758
+ e.preventDefault();
759
+ setValue(result.value);
760
+ requestAnimationFrame(() => {
761
+ taRef.current?.setSelectionRange(result.caret, result.caret);
762
+ });
763
+ return;
764
+ }
614
765
  e.preventDefault();
615
766
  void submit();
616
- },
617
- children: [
618
- replyingTo && /* @__PURE__ */ jsx(
619
- ReplyChip,
620
- {
621
- message: replyingTo,
622
- ...labelFor ? { labelFor } : {},
623
- ...onCancelReply ? { onCancel: onCancelReply } : {}
624
- }
625
- ),
626
- /* @__PURE__ */ jsxs("div", { className: "poolse-composer__row", children: [
627
- /* @__PURE__ */ jsx(
628
- "textarea",
767
+ }
768
+ if (e.key === "Escape" && replyingTo && onCancelReply) {
769
+ e.preventDefault();
770
+ onCancelReply();
771
+ }
772
+ };
773
+ const onChange = (e) => {
774
+ setValue(e.target.value);
775
+ onTyping?.();
776
+ };
777
+ const canSend = !disabled && !sending && !uploading && (value.trim() !== "" || readyCount > 0);
778
+ return /* @__PURE__ */ jsxs(
779
+ "form",
780
+ {
781
+ className: "poolse-composer",
782
+ onSubmit: (e) => {
783
+ e.preventDefault();
784
+ void submit();
785
+ },
786
+ children: [
787
+ replyingTo && /* @__PURE__ */ jsx(
788
+ ReplyChip,
629
789
  {
630
- ref: taRef,
631
- className: "poolse-composer__input",
632
- rows: 1,
633
- value,
634
- onChange,
635
- onKeyDown,
636
- placeholder,
637
- disabled: disabled || sending,
638
- "aria-label": placeholder
790
+ message: replyingTo,
791
+ ...labelFor ? { labelFor } : {},
792
+ ...onCancelReply ? { onCancel: onCancelReply } : {}
639
793
  }
640
794
  ),
641
- /* @__PURE__ */ jsx(
642
- "button",
795
+ attachments && visibleUploads.length > 0 && /* @__PURE__ */ jsx(
796
+ UploadQueueStrip,
643
797
  {
644
- type: "submit",
645
- className: "poolse-composer__send",
646
- disabled: disabled || sending || value.trim() === "",
647
- "aria-label": "Send message",
648
- children: /* @__PURE__ */ jsx(PoolseIcon, { name: "send-fill", label: null })
798
+ items: visibleUploads,
799
+ onCancel: cancelUpload,
800
+ onDismiss: removeUpload
649
801
  }
650
- )
651
- ] })
652
- ]
653
- }
654
- );
655
- }
802
+ ),
803
+ /* @__PURE__ */ jsxs("div", { className: "poolse-composer__row", children: [
804
+ attachments && /* @__PURE__ */ jsxs(Fragment, { children: [
805
+ /* @__PURE__ */ jsx(
806
+ "input",
807
+ {
808
+ ref: fileInputRef,
809
+ type: "file",
810
+ multiple: true,
811
+ className: "poolse-attach-input",
812
+ onChange: (e) => {
813
+ const files = Array.from(e.target.files ?? []);
814
+ if (files.length > 0) addFiles(files);
815
+ e.target.value = "";
816
+ }
817
+ }
818
+ ),
819
+ /* @__PURE__ */ jsx(
820
+ "button",
821
+ {
822
+ type: "button",
823
+ className: "poolse-composer__attach",
824
+ onClick: () => fileInputRef.current?.click(),
825
+ disabled: disabled || sending,
826
+ "aria-label": "Attach files",
827
+ title: "Attach files",
828
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 20, label: null })
829
+ }
830
+ )
831
+ ] }),
832
+ /* @__PURE__ */ jsx(
833
+ "textarea",
834
+ {
835
+ ref: taRef,
836
+ className: "poolse-composer__input",
837
+ rows: 1,
838
+ value,
839
+ onChange,
840
+ onKeyDown,
841
+ placeholder,
842
+ disabled: disabled || sending,
843
+ "aria-label": placeholder
844
+ }
845
+ ),
846
+ /* @__PURE__ */ jsx(
847
+ "button",
848
+ {
849
+ type: "submit",
850
+ className: "poolse-composer__send",
851
+ disabled: !canSend,
852
+ "aria-label": "Send message",
853
+ title: uploading ? "Waiting for uploads\u2026" : "Send message",
854
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "send-fill", label: null })
855
+ }
856
+ )
857
+ ] })
858
+ ]
859
+ }
860
+ );
861
+ }
862
+ );
656
863
  function ReplyChip({
657
864
  message,
658
865
  labelFor,
@@ -1544,6 +1751,35 @@ function ThreadView({
1544
1751
  const listRef = useRef(null);
1545
1752
  const closeBtnRef = useRef(null);
1546
1753
  const lastReplyIdRef = useRef(null);
1754
+ const composerRef = useRef(null);
1755
+ const [dragActive, setDragActive] = useState(false);
1756
+ const dragDepthRef = useRef(0);
1757
+ const isFileDrag = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
1758
+ const onDragEnter = (e) => {
1759
+ if (!isFileDrag(e)) return;
1760
+ e.preventDefault();
1761
+ dragDepthRef.current += 1;
1762
+ setDragActive(true);
1763
+ };
1764
+ const onDragOver = (e) => {
1765
+ if (!isFileDrag(e)) return;
1766
+ e.preventDefault();
1767
+ if (e.dataTransfer) e.dataTransfer.dropEffect = "copy";
1768
+ };
1769
+ const onDragLeave = (e) => {
1770
+ if (!isFileDrag(e)) return;
1771
+ e.preventDefault();
1772
+ dragDepthRef.current = Math.max(0, dragDepthRef.current - 1);
1773
+ if (dragDepthRef.current === 0) setDragActive(false);
1774
+ };
1775
+ const onDrop = (e) => {
1776
+ if (!isFileDrag(e)) return;
1777
+ e.preventDefault();
1778
+ dragDepthRef.current = 0;
1779
+ setDragActive(false);
1780
+ const files = Array.from(e.dataTransfer?.files ?? []);
1781
+ if (files.length > 0) composerRef.current?.addFiles(files);
1782
+ };
1547
1783
  useEffect(() => {
1548
1784
  const tail = replies[replies.length - 1];
1549
1785
  if (!tail) return;
@@ -1585,9 +1821,13 @@ function ThreadView({
1585
1821
  return /* @__PURE__ */ jsxs(
1586
1822
  "aside",
1587
1823
  {
1588
- className: "poolse-thread",
1824
+ className: `poolse-thread${dragActive ? " is-drag-active" : ""}`,
1589
1825
  role: "complementary",
1590
1826
  "aria-label": "Message thread",
1827
+ onDragEnter,
1828
+ onDragOver,
1829
+ onDragLeave,
1830
+ onDrop,
1591
1831
  children: [
1592
1832
  /* @__PURE__ */ jsxs("header", { className: "poolse-thread__header", children: [
1593
1833
  /* @__PURE__ */ jsx("div", { className: "poolse-thread__title", children: "Thread" }),
@@ -1616,7 +1856,22 @@ function ThreadView({
1616
1856
  error.message
1617
1857
  ] })
1618
1858
  ] }),
1619
- /* @__PURE__ */ jsx(MessageComposer, { onSend: (body) => sendReply({ body }), placeholder: "Reply in thread\u2026" })
1859
+ /* @__PURE__ */ jsx(
1860
+ MessageComposer,
1861
+ {
1862
+ ref: composerRef,
1863
+ onSend: (body, opts) => sendReply({
1864
+ body,
1865
+ ...opts?.attachment_ids && opts.attachment_ids.length > 0 ? { attachment_ids: opts.attachment_ids } : {}
1866
+ }),
1867
+ placeholder: "Reply in thread\u2026"
1868
+ }
1869
+ ),
1870
+ dragActive && /* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__drop-overlay-inner", children: [
1871
+ /* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 40, label: null }),
1872
+ /* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay-title", children: "Drop files to upload" }),
1873
+ /* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay-hint", children: "They'll be sent in one reply" })
1874
+ ] }) })
1620
1875
  ]
1621
1876
  }
1622
1877
  );
@@ -1664,63 +1919,6 @@ function TypingLabel({ ids, labelFor }) {
1664
1919
  " people are typing"
1665
1920
  ] });
1666
1921
  }
1667
- function UploadQueueStrip({ items, onCancel, onDismiss }) {
1668
- if (items.length === 0) return null;
1669
- return /* @__PURE__ */ jsx("div", { className: "poolse-upload-strip", role: "status", "aria-live": "polite", children: items.map((item) => /* @__PURE__ */ jsx(
1670
- UploadChip,
1671
- {
1672
- item,
1673
- onCancel: () => onCancel(item.localId),
1674
- onDismiss: () => onDismiss(item.localId)
1675
- },
1676
- item.localId
1677
- )) });
1678
- }
1679
- function UploadChip({
1680
- item,
1681
- onCancel,
1682
- onDismiss
1683
- }) {
1684
- const pct = item.byteSize > 0 ? Math.min(100, Math.round(item.loaded / item.byteSize * 100)) : 0;
1685
- const isError = item.status === "error";
1686
- const isInFlight = item.status === "pending" || item.status === "uploading";
1687
- return /* @__PURE__ */ jsxs(
1688
- "div",
1689
- {
1690
- className: `poolse-upload-chip poolse-upload-chip--${item.status}`,
1691
- "data-status": item.status,
1692
- children: [
1693
- /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx(PoolseIcon, { name: isError ? "attachment" : "attachment", size: 18, label: null }) }),
1694
- /* @__PURE__ */ jsxs("div", { className: "poolse-upload-chip__body", children: [
1695
- /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__filename", title: item.filename, children: item.filename }),
1696
- isError ? /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__error", children: item.error?.message ?? "Upload failed" }) : /* @__PURE__ */ jsx(
1697
- "div",
1698
- {
1699
- className: "poolse-upload-chip__bar",
1700
- role: "progressbar",
1701
- "aria-valuemin": 0,
1702
- "aria-valuemax": 100,
1703
- "aria-valuenow": pct,
1704
- "aria-label": `Uploading ${item.filename}`,
1705
- children: /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__bar-fill", style: { width: `${pct}%` } })
1706
- }
1707
- )
1708
- ] }),
1709
- /* @__PURE__ */ jsx(
1710
- "button",
1711
- {
1712
- type: "button",
1713
- className: "poolse-upload-chip__action",
1714
- onClick: isInFlight ? onCancel : onDismiss,
1715
- "aria-label": isInFlight ? `Cancel upload of ${item.filename}` : `Dismiss ${item.filename}`,
1716
- title: isInFlight ? "Cancel" : "Dismiss",
1717
- children: "\xD7"
1718
- }
1719
- )
1720
- ]
1721
- }
1722
- );
1723
- }
1724
1922
  var TRUE = true;
1725
1923
  function ConversationView({
1726
1924
  conversationId,
@@ -1883,28 +2081,7 @@ function ConversationView({
1883
2081
  el.classList.add("poolse-message-row--highlight");
1884
2082
  setTimeout(() => el.classList.remove("poolse-message-row--highlight"), 1600);
1885
2083
  };
1886
- const { queue: uploadQueue, uploadAll, cancel: cancelUpload, remove: removeUpload, uploading } = useAttachmentUpload();
1887
- const visibleUploads = uploadQueue.filter(
1888
- (it) => it.status === "pending" || it.status === "uploading" || it.status === "error"
1889
- );
1890
- const onPickFiles = async (files) => {
1891
- if (files.length === 0) return;
1892
- try {
1893
- const atts = await uploadAll(
1894
- files.map((f) => ({
1895
- body: f,
1896
- contentType: f.type || "application/octet-stream",
1897
- byteSize: f.size,
1898
- filename: f.name
1899
- }))
1900
- );
1901
- await send({ body: "", attachment_ids: atts.map((a) => a.id) });
1902
- for (const it of uploadQueue) {
1903
- if (it.status === "ready") removeUpload(it.localId);
1904
- }
1905
- } catch {
1906
- }
1907
- };
2084
+ const composerRef = useRef(null);
1908
2085
  const [dragActive, setDragActive] = useState(false);
1909
2086
  const dragDepthRef = useRef(0);
1910
2087
  const isFileDrag = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
@@ -1931,12 +2108,13 @@ function ConversationView({
1931
2108
  dragDepthRef.current = 0;
1932
2109
  setDragActive(false);
1933
2110
  const files = Array.from(e.dataTransfer?.files ?? []);
1934
- if (files.length > 0) void onPickFiles(files);
2111
+ if (files.length > 0) composerRef.current?.addFiles(files);
1935
2112
  };
1936
2113
  const onSendBody = async (body, opts) => {
1937
2114
  await send({
1938
2115
  body,
1939
- ...opts?.quoted_message_id ? { quoted_message_id: opts.quoted_message_id } : {}
2116
+ ...opts?.quoted_message_id ? { quoted_message_id: opts.quoted_message_id } : {},
2117
+ ...opts?.attachment_ids && opts.attachment_ids.length > 0 ? { attachment_ids: opts.attachment_ids } : {}
1940
2118
  });
1941
2119
  setReplyingTo(null);
1942
2120
  };
@@ -1947,17 +2125,21 @@ function ConversationView({
1947
2125
  const Composer = mentions && members.length > 0 ? /* @__PURE__ */ jsx(
1948
2126
  MentionInput,
1949
2127
  {
2128
+ ref: composerRef,
1950
2129
  conversationId,
1951
2130
  onSend: onSendWithMentions,
1952
2131
  onTyping: signalTyping,
2132
+ attachments,
1953
2133
  ...labelFor ? { labelFor } : {},
1954
2134
  ...quotations ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
1955
2135
  }
1956
2136
  ) : /* @__PURE__ */ jsx(
1957
2137
  MessageComposer,
1958
2138
  {
2139
+ ref: composerRef,
1959
2140
  onSend: onSendBody,
1960
2141
  onTyping: signalTyping,
2142
+ attachments,
1961
2143
  ...labelFor ? { labelFor } : {},
1962
2144
  ...quotations ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
1963
2145
  }
@@ -2078,18 +2260,7 @@ function ConversationView({
2078
2260
  }
2079
2261
  ),
2080
2262
  /* @__PURE__ */ jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
2081
- attachments && /* @__PURE__ */ jsx(
2082
- UploadQueueStrip,
2083
- {
2084
- items: visibleUploads,
2085
- onCancel: cancelUpload,
2086
- onDismiss: removeUpload
2087
- }
2088
- ),
2089
- /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__composer-row", children: [
2090
- attachments && /* @__PURE__ */ jsx(AttachmentPickerButton, { onPick: onPickFiles, disabled: uploading }),
2091
- /* @__PURE__ */ jsx("div", { className: "poolse-conversation__composer-flex", children: Composer })
2092
- ] }),
2263
+ /* @__PURE__ */ jsx("div", { className: "poolse-conversation__composer-row", children: /* @__PURE__ */ jsx("div", { className: "poolse-conversation__composer-flex", children: Composer }) }),
2093
2264
  dragActive && /* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__drop-overlay-inner", children: [
2094
2265
  /* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 40, label: null }),
2095
2266
  /* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay-title", children: "Drop files to upload" }),
@@ -2108,40 +2279,6 @@ function ConversationView({
2108
2279
  ) })
2109
2280
  ] });
2110
2281
  }
2111
- function AttachmentPickerButton({
2112
- onPick,
2113
- disabled
2114
- }) {
2115
- const inputRef = useRef(null);
2116
- return /* @__PURE__ */ jsxs(Fragment, { children: [
2117
- /* @__PURE__ */ jsx(
2118
- "input",
2119
- {
2120
- ref: inputRef,
2121
- type: "file",
2122
- multiple: true,
2123
- className: "poolse-attach-input",
2124
- onChange: (e) => {
2125
- const files = Array.from(e.target.files ?? []);
2126
- if (files.length > 0) onPick(files);
2127
- e.target.value = "";
2128
- }
2129
- }
2130
- ),
2131
- /* @__PURE__ */ jsx(
2132
- "button",
2133
- {
2134
- type: "button",
2135
- className: "poolse-attach-btn",
2136
- onClick: () => inputRef.current?.click(),
2137
- disabled,
2138
- "aria-label": "Attach files",
2139
- title: "Attach files",
2140
- children: /* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 20, label: null })
2141
- }
2142
- )
2143
- ] });
2144
- }
2145
2282
  function ConversationList({
2146
2283
  selectedId,
2147
2284
  onSelect,