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