@poolse/react-ui 1.0.3 → 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.cjs +582 -430
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -8
- package/dist/index.d.ts +37 -8
- package/dist/index.js +585 -433
- package/dist/index.js.map +1 -1
- package/dist/styles.css +78 -12
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
|
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
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
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
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
-
|
|
536
|
+
setMention(null);
|
|
439
537
|
return;
|
|
440
538
|
}
|
|
441
539
|
}
|
|
442
|
-
if (e.key === "
|
|
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
|
-
|
|
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
|
-
|
|
455
|
-
requestAnimationFrame(() => {
|
|
456
|
-
taRef.current?.setSelectionRange(result.caret, result.caret);
|
|
457
|
-
});
|
|
458
|
-
return;
|
|
557
|
+
onCancelReply();
|
|
459
558
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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(
|
|
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
|
-
|
|
488
|
-
|
|
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
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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__ */
|
|
520
|
-
|
|
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
|
-
|
|
523
|
-
className: "poolse-
|
|
524
|
-
|
|
525
|
-
"aria-label": "
|
|
526
|
-
children: /* @__PURE__ */
|
|
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
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
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
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
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
|
-
|
|
631
|
-
|
|
632
|
-
|
|
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
|
-
|
|
795
|
+
attachments && visibleUploads.length > 0 && /* @__PURE__ */ jsx(
|
|
796
|
+
UploadQueueStrip,
|
|
643
797
|
{
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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,
|
|
@@ -1222,7 +1429,6 @@ function ReactionPicker({
|
|
|
1222
1429
|
className: "poolse-reaction-picker",
|
|
1223
1430
|
role: "menu",
|
|
1224
1431
|
"aria-label": "Pick a reaction",
|
|
1225
|
-
style: { position: "absolute", bottom: "100%", left: 0, marginBottom: 6 },
|
|
1226
1432
|
onKeyDown: onKey,
|
|
1227
1433
|
children: COMMON_EMOJIS.map((e) => /* @__PURE__ */ jsx(
|
|
1228
1434
|
"button",
|
|
@@ -1528,13 +1734,52 @@ function ThreadView({
|
|
|
1528
1734
|
renderMessage
|
|
1529
1735
|
}) {
|
|
1530
1736
|
const { me } = useMe();
|
|
1531
|
-
const {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1737
|
+
const {
|
|
1738
|
+
replies,
|
|
1739
|
+
loading,
|
|
1740
|
+
error,
|
|
1741
|
+
hasMore,
|
|
1742
|
+
loadMore,
|
|
1743
|
+
sendReply,
|
|
1744
|
+
edit,
|
|
1745
|
+
delete: deleteReply
|
|
1746
|
+
} = useThread(conversationId, rootMessage.id);
|
|
1747
|
+
const [editingId, setEditingId] = useState(null);
|
|
1748
|
+
useEffect(() => {
|
|
1749
|
+
setEditingId(null);
|
|
1750
|
+
}, [rootMessage.id]);
|
|
1535
1751
|
const listRef = useRef(null);
|
|
1536
1752
|
const closeBtnRef = useRef(null);
|
|
1537
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
|
+
};
|
|
1538
1783
|
useEffect(() => {
|
|
1539
1784
|
const tail = replies[replies.length - 1];
|
|
1540
1785
|
if (!tail) return;
|
|
@@ -1552,13 +1797,37 @@ function ThreadView({
|
|
|
1552
1797
|
document.addEventListener("keydown", onKey);
|
|
1553
1798
|
return () => document.removeEventListener("keydown", onKey);
|
|
1554
1799
|
}, [onClose]);
|
|
1555
|
-
const
|
|
1800
|
+
const renderDefault = (msg) => /* @__PURE__ */ jsx(
|
|
1801
|
+
MessageRow,
|
|
1802
|
+
{
|
|
1803
|
+
msg,
|
|
1804
|
+
meId: me?.id ?? null,
|
|
1805
|
+
reactions: true,
|
|
1806
|
+
attachments: true,
|
|
1807
|
+
actions: true,
|
|
1808
|
+
threads: false,
|
|
1809
|
+
quotations: false,
|
|
1810
|
+
editing: editingId === msg.id,
|
|
1811
|
+
onStartEdit: () => setEditingId(msg.id),
|
|
1812
|
+
onCancelEdit: () => setEditingId(null),
|
|
1813
|
+
onSaveEdit: async (body) => {
|
|
1814
|
+
await edit(msg.id, body);
|
|
1815
|
+
setEditingId(null);
|
|
1816
|
+
},
|
|
1817
|
+
onDelete: () => void deleteReply(msg.id)
|
|
1818
|
+
}
|
|
1819
|
+
);
|
|
1820
|
+
const renderOne = renderMessage ? (msg, currentUserId) => renderMessage(msg, currentUserId) : (msg) => renderDefault(msg);
|
|
1556
1821
|
return /* @__PURE__ */ jsxs(
|
|
1557
1822
|
"aside",
|
|
1558
1823
|
{
|
|
1559
|
-
className:
|
|
1824
|
+
className: `poolse-thread${dragActive ? " is-drag-active" : ""}`,
|
|
1560
1825
|
role: "complementary",
|
|
1561
1826
|
"aria-label": "Message thread",
|
|
1827
|
+
onDragEnter,
|
|
1828
|
+
onDragOver,
|
|
1829
|
+
onDragLeave,
|
|
1830
|
+
onDrop,
|
|
1562
1831
|
children: [
|
|
1563
1832
|
/* @__PURE__ */ jsxs("header", { className: "poolse-thread__header", children: [
|
|
1564
1833
|
/* @__PURE__ */ jsx("div", { className: "poolse-thread__title", children: "Thread" }),
|
|
@@ -1587,25 +1856,26 @@ function ThreadView({
|
|
|
1587
1856
|
error.message
|
|
1588
1857
|
] })
|
|
1589
1858
|
] }),
|
|
1590
|
-
/* @__PURE__ */ jsx(
|
|
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
|
+
] }) })
|
|
1591
1875
|
]
|
|
1592
1876
|
}
|
|
1593
1877
|
);
|
|
1594
1878
|
}
|
|
1595
|
-
function defaultRenderReply(msg, currentUserId) {
|
|
1596
|
-
return /* @__PURE__ */ jsx(
|
|
1597
|
-
MessageRow,
|
|
1598
|
-
{
|
|
1599
|
-
msg,
|
|
1600
|
-
meId: currentUserId,
|
|
1601
|
-
reactions: true,
|
|
1602
|
-
attachments: true,
|
|
1603
|
-
actions: true,
|
|
1604
|
-
threads: false,
|
|
1605
|
-
quotations: false
|
|
1606
|
-
}
|
|
1607
|
-
);
|
|
1608
|
-
}
|
|
1609
1879
|
function TypingIndicator({ typing, labelFor }) {
|
|
1610
1880
|
const ids = Array.from(typing);
|
|
1611
1881
|
const isTyping = ids.length > 0;
|
|
@@ -1649,63 +1919,6 @@ function TypingLabel({ ids, labelFor }) {
|
|
|
1649
1919
|
" people are typing"
|
|
1650
1920
|
] });
|
|
1651
1921
|
}
|
|
1652
|
-
function UploadQueueStrip({ items, onCancel, onDismiss }) {
|
|
1653
|
-
if (items.length === 0) return null;
|
|
1654
|
-
return /* @__PURE__ */ jsx("div", { className: "poolse-upload-strip", role: "status", "aria-live": "polite", children: items.map((item) => /* @__PURE__ */ jsx(
|
|
1655
|
-
UploadChip,
|
|
1656
|
-
{
|
|
1657
|
-
item,
|
|
1658
|
-
onCancel: () => onCancel(item.localId),
|
|
1659
|
-
onDismiss: () => onDismiss(item.localId)
|
|
1660
|
-
},
|
|
1661
|
-
item.localId
|
|
1662
|
-
)) });
|
|
1663
|
-
}
|
|
1664
|
-
function UploadChip({
|
|
1665
|
-
item,
|
|
1666
|
-
onCancel,
|
|
1667
|
-
onDismiss
|
|
1668
|
-
}) {
|
|
1669
|
-
const pct = item.byteSize > 0 ? Math.min(100, Math.round(item.loaded / item.byteSize * 100)) : 0;
|
|
1670
|
-
const isError = item.status === "error";
|
|
1671
|
-
const isInFlight = item.status === "pending" || item.status === "uploading";
|
|
1672
|
-
return /* @__PURE__ */ jsxs(
|
|
1673
|
-
"div",
|
|
1674
|
-
{
|
|
1675
|
-
className: `poolse-upload-chip poolse-upload-chip--${item.status}`,
|
|
1676
|
-
"data-status": item.status,
|
|
1677
|
-
children: [
|
|
1678
|
-
/* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx(PoolseIcon, { name: isError ? "attachment" : "attachment", size: 18, label: null }) }),
|
|
1679
|
-
/* @__PURE__ */ jsxs("div", { className: "poolse-upload-chip__body", children: [
|
|
1680
|
-
/* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__filename", title: item.filename, children: item.filename }),
|
|
1681
|
-
isError ? /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__error", children: item.error?.message ?? "Upload failed" }) : /* @__PURE__ */ jsx(
|
|
1682
|
-
"div",
|
|
1683
|
-
{
|
|
1684
|
-
className: "poolse-upload-chip__bar",
|
|
1685
|
-
role: "progressbar",
|
|
1686
|
-
"aria-valuemin": 0,
|
|
1687
|
-
"aria-valuemax": 100,
|
|
1688
|
-
"aria-valuenow": pct,
|
|
1689
|
-
"aria-label": `Uploading ${item.filename}`,
|
|
1690
|
-
children: /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__bar-fill", style: { width: `${pct}%` } })
|
|
1691
|
-
}
|
|
1692
|
-
)
|
|
1693
|
-
] }),
|
|
1694
|
-
/* @__PURE__ */ jsx(
|
|
1695
|
-
"button",
|
|
1696
|
-
{
|
|
1697
|
-
type: "button",
|
|
1698
|
-
className: "poolse-upload-chip__action",
|
|
1699
|
-
onClick: isInFlight ? onCancel : onDismiss,
|
|
1700
|
-
"aria-label": isInFlight ? `Cancel upload of ${item.filename}` : `Dismiss ${item.filename}`,
|
|
1701
|
-
title: isInFlight ? "Cancel" : "Dismiss",
|
|
1702
|
-
children: "\xD7"
|
|
1703
|
-
}
|
|
1704
|
-
)
|
|
1705
|
-
]
|
|
1706
|
-
}
|
|
1707
|
-
);
|
|
1708
|
-
}
|
|
1709
1922
|
var TRUE = true;
|
|
1710
1923
|
function ConversationView({
|
|
1711
1924
|
conversationId,
|
|
@@ -1868,28 +2081,7 @@ function ConversationView({
|
|
|
1868
2081
|
el.classList.add("poolse-message-row--highlight");
|
|
1869
2082
|
setTimeout(() => el.classList.remove("poolse-message-row--highlight"), 1600);
|
|
1870
2083
|
};
|
|
1871
|
-
const
|
|
1872
|
-
const visibleUploads = uploadQueue.filter(
|
|
1873
|
-
(it) => it.status === "pending" || it.status === "uploading" || it.status === "error"
|
|
1874
|
-
);
|
|
1875
|
-
const onPickFiles = async (files) => {
|
|
1876
|
-
if (files.length === 0) return;
|
|
1877
|
-
try {
|
|
1878
|
-
const atts = await uploadAll(
|
|
1879
|
-
files.map((f) => ({
|
|
1880
|
-
body: f,
|
|
1881
|
-
contentType: f.type || "application/octet-stream",
|
|
1882
|
-
byteSize: f.size,
|
|
1883
|
-
filename: f.name
|
|
1884
|
-
}))
|
|
1885
|
-
);
|
|
1886
|
-
await send({ body: "", attachment_ids: atts.map((a) => a.id) });
|
|
1887
|
-
for (const it of uploadQueue) {
|
|
1888
|
-
if (it.status === "ready") removeUpload(it.localId);
|
|
1889
|
-
}
|
|
1890
|
-
} catch {
|
|
1891
|
-
}
|
|
1892
|
-
};
|
|
2084
|
+
const composerRef = useRef(null);
|
|
1893
2085
|
const [dragActive, setDragActive] = useState(false);
|
|
1894
2086
|
const dragDepthRef = useRef(0);
|
|
1895
2087
|
const isFileDrag = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
|
|
@@ -1916,12 +2108,13 @@ function ConversationView({
|
|
|
1916
2108
|
dragDepthRef.current = 0;
|
|
1917
2109
|
setDragActive(false);
|
|
1918
2110
|
const files = Array.from(e.dataTransfer?.files ?? []);
|
|
1919
|
-
if (files.length > 0)
|
|
2111
|
+
if (files.length > 0) composerRef.current?.addFiles(files);
|
|
1920
2112
|
};
|
|
1921
2113
|
const onSendBody = async (body, opts) => {
|
|
1922
2114
|
await send({
|
|
1923
2115
|
body,
|
|
1924
|
-
...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 } : {}
|
|
1925
2118
|
});
|
|
1926
2119
|
setReplyingTo(null);
|
|
1927
2120
|
};
|
|
@@ -1932,17 +2125,21 @@ function ConversationView({
|
|
|
1932
2125
|
const Composer = mentions && members.length > 0 ? /* @__PURE__ */ jsx(
|
|
1933
2126
|
MentionInput,
|
|
1934
2127
|
{
|
|
2128
|
+
ref: composerRef,
|
|
1935
2129
|
conversationId,
|
|
1936
2130
|
onSend: onSendWithMentions,
|
|
1937
2131
|
onTyping: signalTyping,
|
|
2132
|
+
attachments,
|
|
1938
2133
|
...labelFor ? { labelFor } : {},
|
|
1939
2134
|
...quotations ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
|
|
1940
2135
|
}
|
|
1941
2136
|
) : /* @__PURE__ */ jsx(
|
|
1942
2137
|
MessageComposer,
|
|
1943
2138
|
{
|
|
2139
|
+
ref: composerRef,
|
|
1944
2140
|
onSend: onSendBody,
|
|
1945
2141
|
onTyping: signalTyping,
|
|
2142
|
+
attachments,
|
|
1946
2143
|
...labelFor ? { labelFor } : {},
|
|
1947
2144
|
...quotations ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
|
|
1948
2145
|
}
|
|
@@ -2063,18 +2260,7 @@ function ConversationView({
|
|
|
2063
2260
|
}
|
|
2064
2261
|
),
|
|
2065
2262
|
/* @__PURE__ */ jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
|
|
2066
|
-
|
|
2067
|
-
UploadQueueStrip,
|
|
2068
|
-
{
|
|
2069
|
-
items: visibleUploads,
|
|
2070
|
-
onCancel: cancelUpload,
|
|
2071
|
-
onDismiss: removeUpload
|
|
2072
|
-
}
|
|
2073
|
-
),
|
|
2074
|
-
/* @__PURE__ */ jsxs("div", { className: "poolse-conversation__composer-row", children: [
|
|
2075
|
-
attachments && /* @__PURE__ */ jsx(AttachmentPickerButton, { onPick: onPickFiles, disabled: uploading }),
|
|
2076
|
-
/* @__PURE__ */ jsx("div", { className: "poolse-conversation__composer-flex", children: Composer })
|
|
2077
|
-
] }),
|
|
2263
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-conversation__composer-row", children: /* @__PURE__ */ jsx("div", { className: "poolse-conversation__composer-flex", children: Composer }) }),
|
|
2078
2264
|
dragActive && /* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__drop-overlay-inner", children: [
|
|
2079
2265
|
/* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 40, label: null }),
|
|
2080
2266
|
/* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay-title", children: "Drop files to upload" }),
|
|
@@ -2093,40 +2279,6 @@ function ConversationView({
|
|
|
2093
2279
|
) })
|
|
2094
2280
|
] });
|
|
2095
2281
|
}
|
|
2096
|
-
function AttachmentPickerButton({
|
|
2097
|
-
onPick,
|
|
2098
|
-
disabled
|
|
2099
|
-
}) {
|
|
2100
|
-
const inputRef = useRef(null);
|
|
2101
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2102
|
-
/* @__PURE__ */ jsx(
|
|
2103
|
-
"input",
|
|
2104
|
-
{
|
|
2105
|
-
ref: inputRef,
|
|
2106
|
-
type: "file",
|
|
2107
|
-
multiple: true,
|
|
2108
|
-
className: "poolse-attach-input",
|
|
2109
|
-
onChange: (e) => {
|
|
2110
|
-
const files = Array.from(e.target.files ?? []);
|
|
2111
|
-
if (files.length > 0) onPick(files);
|
|
2112
|
-
e.target.value = "";
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
),
|
|
2116
|
-
/* @__PURE__ */ jsx(
|
|
2117
|
-
"button",
|
|
2118
|
-
{
|
|
2119
|
-
type: "button",
|
|
2120
|
-
className: "poolse-attach-btn",
|
|
2121
|
-
onClick: () => inputRef.current?.click(),
|
|
2122
|
-
disabled,
|
|
2123
|
-
"aria-label": "Attach files",
|
|
2124
|
-
title: "Attach files",
|
|
2125
|
-
children: /* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 20, label: null })
|
|
2126
|
-
}
|
|
2127
|
-
)
|
|
2128
|
-
] });
|
|
2129
|
-
}
|
|
2130
2282
|
function ConversationList({
|
|
2131
2283
|
selectedId,
|
|
2132
2284
|
onSelect,
|