@poolse/react-ui 1.0.4 → 1.0.6

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