@partrunner-ai/ui 2.2.5 → 2.3.1
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 +767 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +174 -1
- package/dist/index.d.ts +174 -1
- package/dist/index.js +762 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/styles/light.css +574 -0
- package/styles/theme.css +574 -0
- package/styles/ui.css +574 -0
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { forwardRef, isValidElement, Children, cloneElement, createContext, useEffect, useId, useState, useRef, useCallback, useLayoutEffect, useContext, useMemo } from 'react';
|
|
3
|
-
import { X, Upload, FileText, Loader2, ChevronDown, Search, Check, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight, Copy, TrendingUp, TrendingDown, CalendarDays } from 'lucide-react';
|
|
2
|
+
import { forwardRef, isValidElement, Children, cloneElement, createContext, useEffect, useId, useState, useRef, useCallback, useLayoutEffect, useContext, useMemo, Fragment as Fragment$1 } from 'react';
|
|
3
|
+
import { X, Upload, FileText, Loader2, ChevronDown, Search, Check, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight, Copy, TrendingUp, TrendingDown, CalendarDays, BellRing, BellOff, Bell, Bot, CornerUpLeft, SmilePlus, Pencil, Trash2, Paperclip, SendHorizontal } from 'lucide-react';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { createPortal } from 'react-dom';
|
|
6
6
|
|
|
@@ -6341,6 +6341,765 @@ function PresetOption({
|
|
|
6341
6341
|
);
|
|
6342
6342
|
}
|
|
6343
6343
|
|
|
6344
|
-
|
|
6344
|
+
// src/commentText.ts
|
|
6345
|
+
var TOKEN_RE = /<@(u|a):([0-9A-Za-z_-]+)>/g;
|
|
6346
|
+
function parseCommentBody(body, mentions = []) {
|
|
6347
|
+
const names = new Map(mentions.map((m) => [`${m.kind}:${m.id.toLowerCase()}`, m.name]));
|
|
6348
|
+
const segments = [];
|
|
6349
|
+
let last = 0;
|
|
6350
|
+
for (const match of body.matchAll(TOKEN_RE)) {
|
|
6351
|
+
const index = match.index ?? 0;
|
|
6352
|
+
if (index > last) segments.push({ type: "text", text: body.slice(last, index) });
|
|
6353
|
+
const kind = match[1] === "u" ? "user" : "agent";
|
|
6354
|
+
const id = match[2] ?? "";
|
|
6355
|
+
const name = names.get(`${kind}:${id.toLowerCase()}`) ?? (kind === "agent" ? id : "alguien");
|
|
6356
|
+
segments.push({ type: "mention", kind, id, name });
|
|
6357
|
+
last = index + match[0].length;
|
|
6358
|
+
}
|
|
6359
|
+
if (last < body.length) segments.push({ type: "text", text: body.slice(last) });
|
|
6360
|
+
return segments;
|
|
6361
|
+
}
|
|
6362
|
+
function commentPlainText(body, mentions = []) {
|
|
6363
|
+
return parseCommentBody(body, mentions).map((s) => s.type === "text" ? s.text : `@${s.name}`).join("");
|
|
6364
|
+
}
|
|
6365
|
+
function serializeCommentDraft(text, picked) {
|
|
6366
|
+
const unique = /* @__PURE__ */ new Map();
|
|
6367
|
+
for (const m of picked) unique.set(`${m.kind}:${m.id}`, m);
|
|
6368
|
+
const ordered = [...unique.values()].sort((a, b) => b.name.length - a.name.length);
|
|
6369
|
+
if (ordered.length === 0) return text;
|
|
6370
|
+
const escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6371
|
+
const pattern = new RegExp(`@(${ordered.map((m) => escape(m.name)).join("|")})(?![\\p{L}\\p{N}_])`, "gu");
|
|
6372
|
+
const byName = new Map(ordered.map((m) => [m.name, m]));
|
|
6373
|
+
return text.replace(pattern, (whole, name) => {
|
|
6374
|
+
const m = byName.get(name);
|
|
6375
|
+
if (!m) return whole;
|
|
6376
|
+
return m.kind === "user" ? `<@u:${m.id}>` : `<@a:${m.id}>`;
|
|
6377
|
+
});
|
|
6378
|
+
}
|
|
6379
|
+
function commentDraftFromBody(body, mentions = []) {
|
|
6380
|
+
const picked = [];
|
|
6381
|
+
const text = parseCommentBody(body, mentions).map((s) => {
|
|
6382
|
+
if (s.type === "text") return s.text;
|
|
6383
|
+
picked.push({ kind: s.kind, id: s.id, name: s.name });
|
|
6384
|
+
return `@${s.name}`;
|
|
6385
|
+
}).join("");
|
|
6386
|
+
return { text, picked };
|
|
6387
|
+
}
|
|
6388
|
+
function activeMentionQuery(text, caret) {
|
|
6389
|
+
const before = text.slice(0, caret);
|
|
6390
|
+
const at = before.lastIndexOf("@");
|
|
6391
|
+
if (at < 0) return null;
|
|
6392
|
+
if (at > 0 && !/\s/.test(before[at - 1] ?? "")) return null;
|
|
6393
|
+
const query = before.slice(at + 1);
|
|
6394
|
+
if (query.length > 40 || /[\n@]/.test(query) || /\s{2}/.test(query)) return null;
|
|
6395
|
+
return { start: at, query };
|
|
6396
|
+
}
|
|
6397
|
+
function mergeCommentMessages(current, changes) {
|
|
6398
|
+
if (changes.length === 0) return current;
|
|
6399
|
+
const byId = new Map(current.map((m) => [m.id, m]));
|
|
6400
|
+
for (const m of changes) byId.set(m.id, m);
|
|
6401
|
+
return [...byId.values()].sort(
|
|
6402
|
+
(a, b) => a.createdAt === b.createdAt ? a.id.localeCompare(b.id) : a.createdAt < b.createdAt ? -1 : 1
|
|
6403
|
+
);
|
|
6404
|
+
}
|
|
6405
|
+
var cx = (...parts) => parts.filter(Boolean).join(" ");
|
|
6406
|
+
var QUICK_REACTIONS = ["\u{1F44D}", "\u2764\uFE0F", "\u{1F602}", "\u{1F62E}", "\u{1F64F}", "\u2705", "\u{1F440}", "\u{1F525}"];
|
|
6407
|
+
var MAX_FILES = 10;
|
|
6408
|
+
var timeFormat = new Intl.DateTimeFormat("es-MX", { hour: "2-digit", minute: "2-digit" });
|
|
6409
|
+
var dayFormat = new Intl.DateTimeFormat("es-MX", { weekday: "long", day: "numeric", month: "long" });
|
|
6410
|
+
function dayKey(iso) {
|
|
6411
|
+
const d = new Date(iso);
|
|
6412
|
+
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
|
|
6413
|
+
}
|
|
6414
|
+
function dayLabel(iso) {
|
|
6415
|
+
const d = new Date(iso);
|
|
6416
|
+
const today = /* @__PURE__ */ new Date();
|
|
6417
|
+
const yesterday = new Date(today);
|
|
6418
|
+
yesterday.setDate(today.getDate() - 1);
|
|
6419
|
+
if (dayKey(iso) === dayKey(today.toISOString())) return "Hoy";
|
|
6420
|
+
if (dayKey(iso) === dayKey(yesterday.toISOString())) return "Ayer";
|
|
6421
|
+
const label = dayFormat.format(d);
|
|
6422
|
+
return label.charAt(0).toUpperCase() + label.slice(1);
|
|
6423
|
+
}
|
|
6424
|
+
function fileSize(bytes) {
|
|
6425
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
6426
|
+
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
|
|
6427
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
6428
|
+
}
|
|
6429
|
+
var isInlineImage = (mime) => ["image/jpeg", "image/png", "image/webp", "image/gif"].includes(mime);
|
|
6430
|
+
function MessageBody({ message }) {
|
|
6431
|
+
const segments = useMemo(() => parseCommentBody(message.body, message.mentions), [message.body, message.mentions]);
|
|
6432
|
+
return /* @__PURE__ */ jsx("p", { className: "pr-comments__text", children: segments.map(
|
|
6433
|
+
(s, i) => s.type === "text" ? /* @__PURE__ */ jsx(Fragment$1, { children: s.text }, i) : /* @__PURE__ */ jsxs("span", { className: cx("pr-comments__mention", s.kind === "agent" && "pr-comments__mention--agent"), children: [
|
|
6434
|
+
"@",
|
|
6435
|
+
s.name
|
|
6436
|
+
] }, i)
|
|
6437
|
+
) });
|
|
6438
|
+
}
|
|
6439
|
+
function Attachments({
|
|
6440
|
+
attachments,
|
|
6441
|
+
attachmentHref
|
|
6442
|
+
}) {
|
|
6443
|
+
if (attachments.length === 0) return null;
|
|
6444
|
+
const images = attachments.filter((a) => isInlineImage(a.mimeType));
|
|
6445
|
+
const files = attachments.filter((a) => !isInlineImage(a.mimeType));
|
|
6446
|
+
return /* @__PURE__ */ jsxs("div", { className: "pr-comments__attachments", children: [
|
|
6447
|
+
images.length > 0 && /* @__PURE__ */ jsx("div", { className: "pr-comments__images", children: images.map((a) => /* @__PURE__ */ jsx("a", { href: attachmentHref(a.id), target: "_blank", rel: "noreferrer", className: "pr-comments__image", children: /* @__PURE__ */ jsx(
|
|
6448
|
+
"img",
|
|
6449
|
+
{
|
|
6450
|
+
src: attachmentHref(a.id),
|
|
6451
|
+
alt: a.fileName,
|
|
6452
|
+
loading: "lazy",
|
|
6453
|
+
width: a.width ?? void 0,
|
|
6454
|
+
height: a.height ?? void 0
|
|
6455
|
+
}
|
|
6456
|
+
) }, a.id)) }),
|
|
6457
|
+
files.map((a) => /* @__PURE__ */ jsxs("a", { href: attachmentHref(a.id, { download: true }), className: "pr-comments__file", download: a.fileName, children: [
|
|
6458
|
+
/* @__PURE__ */ jsx(FileText, { size: 16, "aria-hidden": true }),
|
|
6459
|
+
/* @__PURE__ */ jsx("span", { className: "pr-comments__file-name", children: a.fileName }),
|
|
6460
|
+
/* @__PURE__ */ jsx("span", { className: "pr-comments__file-size", children: fileSize(a.sizeBytes) })
|
|
6461
|
+
] }, a.id))
|
|
6462
|
+
] });
|
|
6463
|
+
}
|
|
6464
|
+
function MessageRow({
|
|
6465
|
+
message,
|
|
6466
|
+
own,
|
|
6467
|
+
canWrite,
|
|
6468
|
+
highlighted,
|
|
6469
|
+
attachmentHref,
|
|
6470
|
+
onReply,
|
|
6471
|
+
onJumpTo,
|
|
6472
|
+
onReact,
|
|
6473
|
+
onEdit,
|
|
6474
|
+
onDelete
|
|
6475
|
+
}) {
|
|
6476
|
+
const [picker, setPicker] = useState(false);
|
|
6477
|
+
const [editing, setEditing] = useState(null);
|
|
6478
|
+
const [confirmDelete, setConfirmDelete] = useState(false);
|
|
6479
|
+
const [busy, setBusy] = useState(false);
|
|
6480
|
+
const isAgent = message.author.kind === "agent";
|
|
6481
|
+
const writing = isAgent && (message.status === "pending" || message.status === "streaming");
|
|
6482
|
+
const canAct = canWrite && !message.deleted && message.status === "sent";
|
|
6483
|
+
const saveEdit = async () => {
|
|
6484
|
+
if (!editing || !onEdit) return;
|
|
6485
|
+
setBusy(true);
|
|
6486
|
+
try {
|
|
6487
|
+
await onEdit(message.id, serializeCommentDraft(editing.text, editing.picked));
|
|
6488
|
+
setEditing(null);
|
|
6489
|
+
} finally {
|
|
6490
|
+
setBusy(false);
|
|
6491
|
+
}
|
|
6492
|
+
};
|
|
6493
|
+
const remove = async () => {
|
|
6494
|
+
if (!onDelete) return;
|
|
6495
|
+
setBusy(true);
|
|
6496
|
+
try {
|
|
6497
|
+
await onDelete(message.id);
|
|
6498
|
+
} finally {
|
|
6499
|
+
setBusy(false);
|
|
6500
|
+
setConfirmDelete(false);
|
|
6501
|
+
}
|
|
6502
|
+
};
|
|
6503
|
+
return /* @__PURE__ */ jsxs(
|
|
6504
|
+
"li",
|
|
6505
|
+
{
|
|
6506
|
+
id: `pr-comment-${message.id}`,
|
|
6507
|
+
className: cx("pr-comments__row", own && "pr-comments__row--own", highlighted && "pr-comments__row--highlight"),
|
|
6508
|
+
children: [
|
|
6509
|
+
!own && /* @__PURE__ */ jsx("span", { className: "pr-comments__avatar", children: isAgent ? /* @__PURE__ */ jsx("span", { className: "pr-comments__agent-avatar", "aria-hidden": true, children: /* @__PURE__ */ jsx(Bot, { size: 16 }) }) : /* @__PURE__ */ jsx(Avatar, { name: message.author.name, src: message.author.avatarUrl ?? void 0, size: "sm", decorative: true }) }),
|
|
6510
|
+
/* @__PURE__ */ jsxs("div", { className: "pr-comments__bubble-wrap", children: [
|
|
6511
|
+
/* @__PURE__ */ jsxs("div", { className: cx("pr-comments__bubble", isAgent && "pr-comments__bubble--agent"), children: [
|
|
6512
|
+
/* @__PURE__ */ jsxs("div", { className: "pr-comments__meta", children: [
|
|
6513
|
+
!own && /* @__PURE__ */ jsx("span", { className: "pr-comments__author", children: message.author.name }),
|
|
6514
|
+
isAgent && /* @__PURE__ */ jsx("span", { className: "pr-comments__badge", children: "IA" }),
|
|
6515
|
+
/* @__PURE__ */ jsx("time", { className: "pr-comments__time", dateTime: message.createdAt, children: timeFormat.format(new Date(message.createdAt)) }),
|
|
6516
|
+
message.editedAt && !message.deleted && /* @__PURE__ */ jsx("span", { className: "pr-comments__edited", children: "editado" })
|
|
6517
|
+
] }),
|
|
6518
|
+
message.replyTo && /* @__PURE__ */ jsxs("button", { type: "button", className: "pr-comments__quote", onClick: () => onJumpTo(message.replyTo.id), children: [
|
|
6519
|
+
/* @__PURE__ */ jsx("span", { className: "pr-comments__quote-author", children: message.replyTo.authorName }),
|
|
6520
|
+
/* @__PURE__ */ jsx("span", { className: "pr-comments__quote-text", children: message.replyTo.deleted ? "Mensaje eliminado" : message.replyTo.excerpt || (message.replyTo.hasAttachments ? "Archivo" : "") })
|
|
6521
|
+
] }),
|
|
6522
|
+
message.deleted ? /* @__PURE__ */ jsx("p", { className: "pr-comments__text pr-comments__text--deleted", children: "Mensaje eliminado" }) : editing ? /* @__PURE__ */ jsxs("div", { className: "pr-comments__edit", children: [
|
|
6523
|
+
/* @__PURE__ */ jsx(
|
|
6524
|
+
"textarea",
|
|
6525
|
+
{
|
|
6526
|
+
className: "pr-comments__edit-input",
|
|
6527
|
+
value: editing.text,
|
|
6528
|
+
"aria-label": "Editar mensaje",
|
|
6529
|
+
autoFocus: true,
|
|
6530
|
+
rows: 3,
|
|
6531
|
+
onChange: (e) => setEditing({ ...editing, text: e.target.value }),
|
|
6532
|
+
onKeyDown: (e) => {
|
|
6533
|
+
if (e.key === "Escape") setEditing(null);
|
|
6534
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
6535
|
+
e.preventDefault();
|
|
6536
|
+
void saveEdit();
|
|
6537
|
+
}
|
|
6538
|
+
}
|
|
6539
|
+
}
|
|
6540
|
+
),
|
|
6541
|
+
/* @__PURE__ */ jsxs("div", { className: "pr-comments__edit-actions", children: [
|
|
6542
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pr-comments__link", onClick: () => setEditing(null), disabled: busy, children: "Cancelar" }),
|
|
6543
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pr-comments__link pr-comments__link--strong", onClick: saveEdit, disabled: busy, children: "Guardar" })
|
|
6544
|
+
] })
|
|
6545
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6546
|
+
message.body && /* @__PURE__ */ jsx(MessageBody, { message }),
|
|
6547
|
+
writing && /* @__PURE__ */ jsxs("span", { className: "pr-comments__typing", "aria-label": "Escribiendo", children: [
|
|
6548
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
6549
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
6550
|
+
/* @__PURE__ */ jsx("span", {})
|
|
6551
|
+
] }),
|
|
6552
|
+
isAgent && message.status === "failed" && /* @__PURE__ */ jsx("p", { className: "pr-comments__failed", children: "No se pudo completar la respuesta." }),
|
|
6553
|
+
/* @__PURE__ */ jsx(Attachments, { attachments: message.attachments, attachmentHref })
|
|
6554
|
+
] })
|
|
6555
|
+
] }),
|
|
6556
|
+
!message.deleted && message.reactions.length > 0 && /* @__PURE__ */ jsx("div", { className: "pr-comments__reactions", children: message.reactions.map((r) => /* @__PURE__ */ jsxs(
|
|
6557
|
+
"button",
|
|
6558
|
+
{
|
|
6559
|
+
type: "button",
|
|
6560
|
+
className: cx("pr-comments__reaction", r.mine && "pr-comments__reaction--mine"),
|
|
6561
|
+
"aria-pressed": r.mine,
|
|
6562
|
+
title: r.names.join(", "),
|
|
6563
|
+
disabled: !canWrite || !onReact,
|
|
6564
|
+
onClick: () => onReact?.(message.id, r.emoji, !r.mine),
|
|
6565
|
+
children: [
|
|
6566
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": true, children: r.emoji }),
|
|
6567
|
+
/* @__PURE__ */ jsx("span", { className: "pr-comments__reaction-count", children: r.count })
|
|
6568
|
+
]
|
|
6569
|
+
},
|
|
6570
|
+
r.emoji
|
|
6571
|
+
)) }),
|
|
6572
|
+
confirmDelete && /* @__PURE__ */ jsxs("div", { className: "pr-comments__confirm", role: "group", "aria-label": "Confirmar borrado", children: [
|
|
6573
|
+
/* @__PURE__ */ jsx("span", { children: "\xBFBorrar este mensaje?" }),
|
|
6574
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pr-comments__link", onClick: () => setConfirmDelete(false), disabled: busy, children: "No" }),
|
|
6575
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "pr-comments__link pr-comments__link--danger", onClick: remove, disabled: busy, children: "S\xED, borrar" })
|
|
6576
|
+
] }),
|
|
6577
|
+
picker && /* @__PURE__ */ jsx("div", { className: "pr-comments__picker", role: "group", "aria-label": "Reaccionar", children: QUICK_REACTIONS.map((emoji) => /* @__PURE__ */ jsx(
|
|
6578
|
+
"button",
|
|
6579
|
+
{
|
|
6580
|
+
type: "button",
|
|
6581
|
+
className: "pr-comments__picker-item",
|
|
6582
|
+
"aria-label": `Reaccionar con ${emoji}`,
|
|
6583
|
+
onClick: () => {
|
|
6584
|
+
const mine = message.reactions.find((r) => r.emoji === emoji)?.mine ?? false;
|
|
6585
|
+
void onReact?.(message.id, emoji, !mine);
|
|
6586
|
+
setPicker(false);
|
|
6587
|
+
},
|
|
6588
|
+
children: emoji
|
|
6589
|
+
},
|
|
6590
|
+
emoji
|
|
6591
|
+
)) })
|
|
6592
|
+
] }),
|
|
6593
|
+
canAct && !editing && /* @__PURE__ */ jsxs("div", { className: "pr-comments__actions", children: [
|
|
6594
|
+
/* @__PURE__ */ jsx(IconButton, { size: "sm", compact: true, variant: "ghost", label: "Responder", icon: /* @__PURE__ */ jsx(CornerUpLeft, { size: 14 }), onClick: () => onReply(message) }),
|
|
6595
|
+
onReact && /* @__PURE__ */ jsx(
|
|
6596
|
+
IconButton,
|
|
6597
|
+
{
|
|
6598
|
+
size: "sm",
|
|
6599
|
+
compact: true,
|
|
6600
|
+
variant: "ghost",
|
|
6601
|
+
label: "Reaccionar",
|
|
6602
|
+
icon: /* @__PURE__ */ jsx(SmilePlus, { size: 14 }),
|
|
6603
|
+
"aria-expanded": picker,
|
|
6604
|
+
onClick: () => setPicker((v) => !v)
|
|
6605
|
+
}
|
|
6606
|
+
),
|
|
6607
|
+
own && onEdit && message.author.kind === "user" && /* @__PURE__ */ jsx(
|
|
6608
|
+
IconButton,
|
|
6609
|
+
{
|
|
6610
|
+
size: "sm",
|
|
6611
|
+
compact: true,
|
|
6612
|
+
variant: "ghost",
|
|
6613
|
+
label: "Editar",
|
|
6614
|
+
icon: /* @__PURE__ */ jsx(Pencil, { size: 14 }),
|
|
6615
|
+
onClick: () => setEditing(commentDraftFromBody(message.body, message.mentions))
|
|
6616
|
+
}
|
|
6617
|
+
),
|
|
6618
|
+
own && onDelete && message.author.kind === "user" && /* @__PURE__ */ jsx(IconButton, { size: "sm", compact: true, variant: "ghost", label: "Borrar", icon: /* @__PURE__ */ jsx(Trash2, { size: 14 }), onClick: () => setConfirmDelete(true) })
|
|
6619
|
+
] })
|
|
6620
|
+
]
|
|
6621
|
+
}
|
|
6622
|
+
);
|
|
6623
|
+
}
|
|
6624
|
+
function Composer({
|
|
6625
|
+
replyTo,
|
|
6626
|
+
onCancelReply,
|
|
6627
|
+
onSend,
|
|
6628
|
+
onSearchMentions,
|
|
6629
|
+
onUpload,
|
|
6630
|
+
placeholder,
|
|
6631
|
+
droppedFiles,
|
|
6632
|
+
onDroppedFilesTaken,
|
|
6633
|
+
inputRef
|
|
6634
|
+
}) {
|
|
6635
|
+
const [text, setText] = useState("");
|
|
6636
|
+
const [picked, setPicked] = useState([]);
|
|
6637
|
+
const [files, setFiles] = useState([]);
|
|
6638
|
+
const [sending, setSending] = useState(false);
|
|
6639
|
+
const [sendError, setSendError] = useState(null);
|
|
6640
|
+
const [mention, setMention] = useState(null);
|
|
6641
|
+
const [candidates, setCandidates] = useState([]);
|
|
6642
|
+
const [active, setActive] = useState(0);
|
|
6643
|
+
const fileInput = useRef(null);
|
|
6644
|
+
const listId = useId();
|
|
6645
|
+
const seq = useRef(0);
|
|
6646
|
+
useEffect(() => {
|
|
6647
|
+
if (!mention || !onSearchMentions) {
|
|
6648
|
+
setCandidates([]);
|
|
6649
|
+
return;
|
|
6650
|
+
}
|
|
6651
|
+
const ticket = ++seq.current;
|
|
6652
|
+
const timer = setTimeout(() => {
|
|
6653
|
+
onSearchMentions(mention.query).then((found) => {
|
|
6654
|
+
if (ticket === seq.current) {
|
|
6655
|
+
setCandidates(found.slice(0, 8));
|
|
6656
|
+
setActive(0);
|
|
6657
|
+
}
|
|
6658
|
+
}).catch(() => {
|
|
6659
|
+
if (ticket === seq.current) setCandidates([]);
|
|
6660
|
+
});
|
|
6661
|
+
}, 150);
|
|
6662
|
+
return () => clearTimeout(timer);
|
|
6663
|
+
}, [mention, onSearchMentions]);
|
|
6664
|
+
const addFiles = useCallback(
|
|
6665
|
+
(list) => {
|
|
6666
|
+
if (!onUpload || list.length === 0) return;
|
|
6667
|
+
const room = MAX_FILES - files.length;
|
|
6668
|
+
for (const file of list.slice(0, Math.max(room, 0))) {
|
|
6669
|
+
const localId = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
6670
|
+
setFiles((prev) => [...prev, { localId, fileName: file.name, status: "uploading" }]);
|
|
6671
|
+
onUpload(file).then(
|
|
6672
|
+
(attachment) => setFiles((prev) => prev.map((f) => f.localId === localId ? { ...f, status: "done", attachment } : f))
|
|
6673
|
+
).catch(
|
|
6674
|
+
(err) => setFiles(
|
|
6675
|
+
(prev) => prev.map(
|
|
6676
|
+
(f) => f.localId === localId ? { ...f, status: "error", error: err instanceof Error ? err.message : "No se pudo subir" } : f
|
|
6677
|
+
)
|
|
6678
|
+
)
|
|
6679
|
+
);
|
|
6680
|
+
}
|
|
6681
|
+
},
|
|
6682
|
+
[files.length, onUpload]
|
|
6683
|
+
);
|
|
6684
|
+
useEffect(() => {
|
|
6685
|
+
if (droppedFiles.length > 0) {
|
|
6686
|
+
addFiles(droppedFiles);
|
|
6687
|
+
onDroppedFilesTaken();
|
|
6688
|
+
}
|
|
6689
|
+
}, [droppedFiles, addFiles, onDroppedFilesTaken]);
|
|
6690
|
+
const pendingCaret = useRef(null);
|
|
6691
|
+
useLayoutEffect(() => {
|
|
6692
|
+
const el = inputRef.current;
|
|
6693
|
+
if (!el) return;
|
|
6694
|
+
el.style.height = "auto";
|
|
6695
|
+
el.style.height = `${Math.min(el.scrollHeight, 180)}px`;
|
|
6696
|
+
if (pendingCaret.current !== null) {
|
|
6697
|
+
const pos = pendingCaret.current;
|
|
6698
|
+
pendingCaret.current = null;
|
|
6699
|
+
el.focus();
|
|
6700
|
+
el.setSelectionRange(pos, pos);
|
|
6701
|
+
}
|
|
6702
|
+
}, [text, inputRef]);
|
|
6703
|
+
const updateText = (value, caret) => {
|
|
6704
|
+
setText(value);
|
|
6705
|
+
setSendError(null);
|
|
6706
|
+
setMention(onSearchMentions ? activeMentionQuery(value, caret) : null);
|
|
6707
|
+
};
|
|
6708
|
+
const choose = (candidate) => {
|
|
6709
|
+
if (!mention) return;
|
|
6710
|
+
const el = inputRef.current;
|
|
6711
|
+
const caret = el?.selectionStart ?? text.length;
|
|
6712
|
+
const inserted = `@${candidate.name} `;
|
|
6713
|
+
const next = text.slice(0, mention.start) + inserted + text.slice(caret);
|
|
6714
|
+
setText(next);
|
|
6715
|
+
setPicked((prev) => [...prev, { kind: candidate.kind, id: candidate.id, name: candidate.name }]);
|
|
6716
|
+
setMention(null);
|
|
6717
|
+
pendingCaret.current = mention.start + inserted.length;
|
|
6718
|
+
};
|
|
6719
|
+
const uploading = files.some((f) => f.status === "uploading");
|
|
6720
|
+
const ready = files.filter((f) => f.status === "done" && f.attachment);
|
|
6721
|
+
const canSend = !sending && !uploading && (text.trim().length > 0 || ready.length > 0);
|
|
6722
|
+
const send = async () => {
|
|
6723
|
+
if (!canSend) return;
|
|
6724
|
+
setSending(true);
|
|
6725
|
+
setSendError(null);
|
|
6726
|
+
try {
|
|
6727
|
+
await onSend({
|
|
6728
|
+
body: serializeCommentDraft(text.trim(), picked),
|
|
6729
|
+
replyTo: replyTo?.id ?? null,
|
|
6730
|
+
attachmentIds: ready.map((f) => f.attachment.id)
|
|
6731
|
+
});
|
|
6732
|
+
setText("");
|
|
6733
|
+
setPicked([]);
|
|
6734
|
+
setFiles([]);
|
|
6735
|
+
onCancelReply();
|
|
6736
|
+
} catch (err) {
|
|
6737
|
+
setSendError(err instanceof Error ? err.message : "No se pudo enviar el mensaje.");
|
|
6738
|
+
} finally {
|
|
6739
|
+
setSending(false);
|
|
6740
|
+
}
|
|
6741
|
+
};
|
|
6742
|
+
const onKeyDown = (e) => {
|
|
6743
|
+
if (mention && candidates.length > 0) {
|
|
6744
|
+
if (e.key === "ArrowDown") {
|
|
6745
|
+
e.preventDefault();
|
|
6746
|
+
setActive((i) => (i + 1) % candidates.length);
|
|
6747
|
+
return;
|
|
6748
|
+
}
|
|
6749
|
+
if (e.key === "ArrowUp") {
|
|
6750
|
+
e.preventDefault();
|
|
6751
|
+
setActive((i) => (i - 1 + candidates.length) % candidates.length);
|
|
6752
|
+
return;
|
|
6753
|
+
}
|
|
6754
|
+
if (e.key === "Enter" || e.key === "Tab") {
|
|
6755
|
+
e.preventDefault();
|
|
6756
|
+
const candidate = candidates[active];
|
|
6757
|
+
if (candidate) choose(candidate);
|
|
6758
|
+
return;
|
|
6759
|
+
}
|
|
6760
|
+
if (e.key === "Escape") {
|
|
6761
|
+
e.preventDefault();
|
|
6762
|
+
setMention(null);
|
|
6763
|
+
return;
|
|
6764
|
+
}
|
|
6765
|
+
}
|
|
6766
|
+
if (e.key === "Escape" && replyTo) onCancelReply();
|
|
6767
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
6768
|
+
e.preventDefault();
|
|
6769
|
+
void send();
|
|
6770
|
+
}
|
|
6771
|
+
};
|
|
6772
|
+
const onPaste = (e) => {
|
|
6773
|
+
const pasted = Array.from(e.clipboardData.files);
|
|
6774
|
+
if (pasted.length > 0 && onUpload) {
|
|
6775
|
+
e.preventDefault();
|
|
6776
|
+
addFiles(pasted);
|
|
6777
|
+
}
|
|
6778
|
+
};
|
|
6779
|
+
const showSuggestions = mention !== null && candidates.length > 0;
|
|
6780
|
+
return /* @__PURE__ */ jsxs("div", { className: "pr-comments__composer", children: [
|
|
6781
|
+
replyTo && /* @__PURE__ */ jsxs("div", { className: "pr-comments__replying", children: [
|
|
6782
|
+
/* @__PURE__ */ jsxs("div", { className: "pr-comments__replying-text", children: [
|
|
6783
|
+
/* @__PURE__ */ jsxs("span", { className: "pr-comments__quote-author", children: [
|
|
6784
|
+
"Respondiendo a ",
|
|
6785
|
+
replyTo.author.name
|
|
6786
|
+
] }),
|
|
6787
|
+
/* @__PURE__ */ jsx("span", { className: "pr-comments__quote-text", children: commentPlainText(replyTo.body, replyTo.mentions) || (replyTo.attachments.length > 0 ? "Archivo" : "") })
|
|
6788
|
+
] }),
|
|
6789
|
+
/* @__PURE__ */ jsx(IconButton, { size: "sm", compact: true, variant: "ghost", label: "Cancelar respuesta", icon: /* @__PURE__ */ jsx(X, { size: 14 }), onClick: onCancelReply })
|
|
6790
|
+
] }),
|
|
6791
|
+
files.length > 0 && /* @__PURE__ */ jsx("ul", { className: "pr-comments__pending", children: files.map((f) => /* @__PURE__ */ jsxs("li", { className: cx("pr-comments__pending-file", f.status === "error" && "pr-comments__pending-file--error"), children: [
|
|
6792
|
+
f.status === "uploading" ? /* @__PURE__ */ jsx(Spinner, { size: "sm" }) : /* @__PURE__ */ jsx(FileText, { size: 14, "aria-hidden": true }),
|
|
6793
|
+
/* @__PURE__ */ jsx("span", { className: "pr-comments__file-name", title: f.error ?? f.fileName, children: f.status === "error" ? `${f.fileName}: ${f.error}` : f.fileName }),
|
|
6794
|
+
/* @__PURE__ */ jsx(
|
|
6795
|
+
IconButton,
|
|
6796
|
+
{
|
|
6797
|
+
size: "sm",
|
|
6798
|
+
compact: true,
|
|
6799
|
+
variant: "ghost",
|
|
6800
|
+
label: `Quitar ${f.fileName}`,
|
|
6801
|
+
icon: /* @__PURE__ */ jsx(X, { size: 12 }),
|
|
6802
|
+
onClick: () => setFiles((prev) => prev.filter((p) => p.localId !== f.localId))
|
|
6803
|
+
}
|
|
6804
|
+
)
|
|
6805
|
+
] }, f.localId)) }),
|
|
6806
|
+
/* @__PURE__ */ jsxs("div", { className: "pr-comments__input-row", children: [
|
|
6807
|
+
onUpload && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6808
|
+
/* @__PURE__ */ jsx(
|
|
6809
|
+
IconButton,
|
|
6810
|
+
{
|
|
6811
|
+
size: "sm",
|
|
6812
|
+
variant: "ghost",
|
|
6813
|
+
label: "Adjuntar archivos",
|
|
6814
|
+
icon: /* @__PURE__ */ jsx(Paperclip, { size: 16 }),
|
|
6815
|
+
disabled: files.length >= MAX_FILES,
|
|
6816
|
+
onClick: () => fileInput.current?.click()
|
|
6817
|
+
}
|
|
6818
|
+
),
|
|
6819
|
+
/* @__PURE__ */ jsx(
|
|
6820
|
+
"input",
|
|
6821
|
+
{
|
|
6822
|
+
ref: fileInput,
|
|
6823
|
+
type: "file",
|
|
6824
|
+
multiple: true,
|
|
6825
|
+
hidden: true,
|
|
6826
|
+
accept: "image/*,.pdf,.xlsx,.xls,.docx,.doc,.csv,.txt",
|
|
6827
|
+
onChange: (e) => {
|
|
6828
|
+
addFiles(Array.from(e.target.files ?? []));
|
|
6829
|
+
e.target.value = "";
|
|
6830
|
+
}
|
|
6831
|
+
}
|
|
6832
|
+
)
|
|
6833
|
+
] }),
|
|
6834
|
+
/* @__PURE__ */ jsxs("div", { className: "pr-comments__input-wrap", children: [
|
|
6835
|
+
/* @__PURE__ */ jsx(
|
|
6836
|
+
"textarea",
|
|
6837
|
+
{
|
|
6838
|
+
ref: inputRef,
|
|
6839
|
+
className: "pr-comments__input",
|
|
6840
|
+
rows: 1,
|
|
6841
|
+
value: text,
|
|
6842
|
+
placeholder,
|
|
6843
|
+
"aria-label": "Escribe un comentario",
|
|
6844
|
+
role: "combobox",
|
|
6845
|
+
"aria-expanded": showSuggestions,
|
|
6846
|
+
"aria-controls": showSuggestions ? listId : void 0,
|
|
6847
|
+
"aria-autocomplete": "list",
|
|
6848
|
+
"aria-activedescendant": showSuggestions ? `${listId}-${active}` : void 0,
|
|
6849
|
+
onChange: (e) => updateText(e.target.value, e.target.selectionStart),
|
|
6850
|
+
onKeyDown,
|
|
6851
|
+
onPaste,
|
|
6852
|
+
onBlur: () => setTimeout(() => setMention(null), 150)
|
|
6853
|
+
}
|
|
6854
|
+
),
|
|
6855
|
+
showSuggestions && /* @__PURE__ */ jsx("ul", { id: listId, role: "listbox", className: "pr-comments__suggestions", children: candidates.map((c, i) => /* @__PURE__ */ jsxs(
|
|
6856
|
+
"li",
|
|
6857
|
+
{
|
|
6858
|
+
id: `${listId}-${i}`,
|
|
6859
|
+
role: "option",
|
|
6860
|
+
"aria-selected": i === active,
|
|
6861
|
+
className: cx("pr-comments__suggestion", i === active && "pr-comments__suggestion--active"),
|
|
6862
|
+
onMouseDown: (e) => {
|
|
6863
|
+
e.preventDefault();
|
|
6864
|
+
choose(c);
|
|
6865
|
+
},
|
|
6866
|
+
children: [
|
|
6867
|
+
c.kind === "agent" ? /* @__PURE__ */ jsx("span", { className: "pr-comments__agent-avatar", "aria-hidden": true, children: /* @__PURE__ */ jsx(Bot, { size: 14 }) }) : /* @__PURE__ */ jsx(Avatar, { name: c.name, src: c.avatarUrl ?? void 0, size: "xs", decorative: true }),
|
|
6868
|
+
/* @__PURE__ */ jsx("span", { className: "pr-comments__suggestion-name", children: c.name }),
|
|
6869
|
+
/* @__PURE__ */ jsx("span", { className: "pr-comments__suggestion-hint", children: c.kind === "agent" ? c.description ?? "Agente IA" : c.email })
|
|
6870
|
+
]
|
|
6871
|
+
},
|
|
6872
|
+
`${c.kind}:${c.id}`
|
|
6873
|
+
)) })
|
|
6874
|
+
] }),
|
|
6875
|
+
/* @__PURE__ */ jsx(
|
|
6876
|
+
IconButton,
|
|
6877
|
+
{
|
|
6878
|
+
size: "sm",
|
|
6879
|
+
variant: "primary",
|
|
6880
|
+
label: "Enviar",
|
|
6881
|
+
icon: sending ? /* @__PURE__ */ jsx(Spinner, { size: "sm", tone: "inherit" }) : /* @__PURE__ */ jsx(SendHorizontal, { size: 16 }),
|
|
6882
|
+
disabled: !canSend,
|
|
6883
|
+
onClick: send
|
|
6884
|
+
}
|
|
6885
|
+
)
|
|
6886
|
+
] }),
|
|
6887
|
+
sendError && /* @__PURE__ */ jsx("p", { className: "pr-comments__error", role: "alert", children: sendError })
|
|
6888
|
+
] });
|
|
6889
|
+
}
|
|
6890
|
+
var FOLLOW_LABEL = {
|
|
6891
|
+
none: "Seguir",
|
|
6892
|
+
following: "Siguiendo",
|
|
6893
|
+
muted: "Silenciado"
|
|
6894
|
+
};
|
|
6895
|
+
function CommentThread({
|
|
6896
|
+
messages,
|
|
6897
|
+
viewerId,
|
|
6898
|
+
canWrite,
|
|
6899
|
+
loading = false,
|
|
6900
|
+
error = null,
|
|
6901
|
+
hasMore = false,
|
|
6902
|
+
loadingOlder = false,
|
|
6903
|
+
onLoadOlder,
|
|
6904
|
+
lastReadAt = null,
|
|
6905
|
+
follow,
|
|
6906
|
+
onFollowChange,
|
|
6907
|
+
attachmentHref,
|
|
6908
|
+
onSend,
|
|
6909
|
+
onEdit,
|
|
6910
|
+
onDelete,
|
|
6911
|
+
onReact,
|
|
6912
|
+
onSearchMentions,
|
|
6913
|
+
onUpload,
|
|
6914
|
+
title = "Comentarios",
|
|
6915
|
+
emptyText = "Todav\xEDa no hay comentarios. Escribe el primero; con @ etiquetas a alguien.",
|
|
6916
|
+
placeholder = "Escribe un comentario\u2026 usa @ para etiquetar",
|
|
6917
|
+
className
|
|
6918
|
+
}) {
|
|
6919
|
+
const listRef = useRef(null);
|
|
6920
|
+
const inputRef = useRef(null);
|
|
6921
|
+
const [replyTo, setReplyTo] = useState(null);
|
|
6922
|
+
const [highlight, setHighlight] = useState(null);
|
|
6923
|
+
const [dragging, setDragging] = useState(false);
|
|
6924
|
+
const [dropped, setDropped] = useState([]);
|
|
6925
|
+
const nearBottom = useRef(true);
|
|
6926
|
+
const lastId = messages[messages.length - 1]?.id;
|
|
6927
|
+
const firstId = messages[0]?.id;
|
|
6928
|
+
const prevFirst = useRef(void 0);
|
|
6929
|
+
const prevHeight = useRef(0);
|
|
6930
|
+
useLayoutEffect(() => {
|
|
6931
|
+
const el = listRef.current;
|
|
6932
|
+
if (!el) return;
|
|
6933
|
+
if (prevFirst.current && firstId !== prevFirst.current && prevHeight.current) {
|
|
6934
|
+
el.scrollTop += el.scrollHeight - prevHeight.current;
|
|
6935
|
+
} else if (nearBottom.current) {
|
|
6936
|
+
el.scrollTop = el.scrollHeight;
|
|
6937
|
+
}
|
|
6938
|
+
prevFirst.current = firstId;
|
|
6939
|
+
prevHeight.current = el.scrollHeight;
|
|
6940
|
+
}, [firstId, lastId, messages]);
|
|
6941
|
+
const firstUnread = useMemo(() => {
|
|
6942
|
+
if (!lastReadAt) return null;
|
|
6943
|
+
return messages.find((m) => m.createdAt > lastReadAt && m.author.userId !== viewerId && !m.deleted)?.id ?? null;
|
|
6944
|
+
}, [lastReadAt, firstId]);
|
|
6945
|
+
const jumpTo = (id) => {
|
|
6946
|
+
const target = document.getElementById(`pr-comment-${id}`);
|
|
6947
|
+
if (!target) return;
|
|
6948
|
+
target.scrollIntoView({ block: "center", behavior: "smooth" });
|
|
6949
|
+
setHighlight(id);
|
|
6950
|
+
setTimeout(() => setHighlight((h) => h === id ? null : h), 1600);
|
|
6951
|
+
};
|
|
6952
|
+
const reply = (message) => {
|
|
6953
|
+
setReplyTo(message);
|
|
6954
|
+
inputRef.current?.focus();
|
|
6955
|
+
};
|
|
6956
|
+
const dropProps = canWrite && onUpload ? {
|
|
6957
|
+
onDragOver: (e) => {
|
|
6958
|
+
if (Array.from(e.dataTransfer.types).includes("Files")) {
|
|
6959
|
+
e.preventDefault();
|
|
6960
|
+
setDragging(true);
|
|
6961
|
+
}
|
|
6962
|
+
},
|
|
6963
|
+
onDragLeave: (e) => {
|
|
6964
|
+
if (e.currentTarget === e.target) setDragging(false);
|
|
6965
|
+
},
|
|
6966
|
+
onDrop: (e) => {
|
|
6967
|
+
e.preventDefault();
|
|
6968
|
+
setDragging(false);
|
|
6969
|
+
setDropped(Array.from(e.dataTransfer.files));
|
|
6970
|
+
}
|
|
6971
|
+
} : {};
|
|
6972
|
+
let lastDay = "";
|
|
6973
|
+
return /* @__PURE__ */ jsxs("section", { className: cx("pr-comments", dragging && "pr-comments--dragging", className), "aria-label": "Comentarios", ...dropProps, children: [
|
|
6974
|
+
/* @__PURE__ */ jsxs("header", { className: "pr-comments__header", children: [
|
|
6975
|
+
/* @__PURE__ */ jsx("h3", { className: "pr-comments__title", children: title }),
|
|
6976
|
+
onFollowChange && follow && /* @__PURE__ */ jsx("div", { className: "pr-comments__follow", role: "group", "aria-label": "Avisos de esta conversaci\xF3n", children: ["following", "none", "muted"].map((state) => /* @__PURE__ */ jsxs(
|
|
6977
|
+
"button",
|
|
6978
|
+
{
|
|
6979
|
+
type: "button",
|
|
6980
|
+
className: cx("pr-comments__follow-option", follow === state && "pr-comments__follow-option--active"),
|
|
6981
|
+
"aria-pressed": follow === state,
|
|
6982
|
+
title: state === "following" ? "Te avisamos de cada mensaje nuevo" : state === "muted" ? "S\xF3lo te avisamos si te etiquetan" : "Te avisamos si te etiquetan; al etiquetarte empiezas a seguirla",
|
|
6983
|
+
onClick: () => follow !== state && onFollowChange(state),
|
|
6984
|
+
children: [
|
|
6985
|
+
state === "following" ? /* @__PURE__ */ jsx(BellRing, { size: 14, "aria-hidden": true }) : state === "muted" ? /* @__PURE__ */ jsx(BellOff, { size: 14, "aria-hidden": true }) : /* @__PURE__ */ jsx(Bell, { size: 14, "aria-hidden": true }),
|
|
6986
|
+
FOLLOW_LABEL[state]
|
|
6987
|
+
]
|
|
6988
|
+
},
|
|
6989
|
+
state
|
|
6990
|
+
)) })
|
|
6991
|
+
] }),
|
|
6992
|
+
/* @__PURE__ */ jsxs(
|
|
6993
|
+
"div",
|
|
6994
|
+
{
|
|
6995
|
+
ref: listRef,
|
|
6996
|
+
className: "pr-comments__list",
|
|
6997
|
+
onScroll: (e) => {
|
|
6998
|
+
const el = e.currentTarget;
|
|
6999
|
+
nearBottom.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80;
|
|
7000
|
+
},
|
|
7001
|
+
children: [
|
|
7002
|
+
hasMore && onLoadOlder && /* @__PURE__ */ jsx("div", { className: "pr-comments__older", children: /* @__PURE__ */ jsx("button", { type: "button", className: "pr-comments__link", onClick: onLoadOlder, disabled: loadingOlder, children: loadingOlder ? "Cargando\u2026" : "Ver mensajes anteriores" }) }),
|
|
7003
|
+
loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "pr-comments__empty", children: /* @__PURE__ */ jsx(Spinner, { size: "md" }) }) : messages.length === 0 ? /* @__PURE__ */ jsx("p", { className: "pr-comments__empty", children: emptyText }) : /* @__PURE__ */ jsx("ul", { className: "pr-comments__messages", children: messages.map((m) => {
|
|
7004
|
+
const day = dayKey(m.createdAt);
|
|
7005
|
+
const showDay = day !== lastDay;
|
|
7006
|
+
lastDay = day;
|
|
7007
|
+
const own = m.author.kind === "user" && viewerId !== null && m.author.userId === viewerId;
|
|
7008
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
7009
|
+
showDay && /* @__PURE__ */ jsx("li", { className: "pr-comments__day", "aria-hidden": true, children: /* @__PURE__ */ jsx("span", { children: dayLabel(m.createdAt) }) }),
|
|
7010
|
+
m.id === firstUnread && /* @__PURE__ */ jsx("li", { className: "pr-comments__unread", children: /* @__PURE__ */ jsx("span", { children: "Nuevos" }) }),
|
|
7011
|
+
/* @__PURE__ */ jsx(
|
|
7012
|
+
MessageRow,
|
|
7013
|
+
{
|
|
7014
|
+
message: m,
|
|
7015
|
+
own,
|
|
7016
|
+
canWrite,
|
|
7017
|
+
highlighted: highlight === m.id,
|
|
7018
|
+
attachmentHref,
|
|
7019
|
+
onReply: reply,
|
|
7020
|
+
onJumpTo: jumpTo,
|
|
7021
|
+
onReact,
|
|
7022
|
+
onEdit,
|
|
7023
|
+
onDelete
|
|
7024
|
+
}
|
|
7025
|
+
)
|
|
7026
|
+
] }, m.id);
|
|
7027
|
+
}) })
|
|
7028
|
+
]
|
|
7029
|
+
}
|
|
7030
|
+
),
|
|
7031
|
+
error && /* @__PURE__ */ jsx("p", { className: "pr-comments__error", role: "alert", children: error }),
|
|
7032
|
+
canWrite ? /* @__PURE__ */ jsx(
|
|
7033
|
+
Composer,
|
|
7034
|
+
{
|
|
7035
|
+
replyTo,
|
|
7036
|
+
onCancelReply: () => setReplyTo(null),
|
|
7037
|
+
onSend,
|
|
7038
|
+
onSearchMentions,
|
|
7039
|
+
onUpload,
|
|
7040
|
+
placeholder,
|
|
7041
|
+
droppedFiles: dropped,
|
|
7042
|
+
onDroppedFilesTaken: () => setDropped([]),
|
|
7043
|
+
inputRef
|
|
7044
|
+
}
|
|
7045
|
+
) : /* @__PURE__ */ jsx("p", { className: "pr-comments__readonly", children: "Puedes leer estos comentarios, pero no tienes permiso para escribir." })
|
|
7046
|
+
] });
|
|
7047
|
+
}
|
|
7048
|
+
|
|
7049
|
+
// src/commentImage.ts
|
|
7050
|
+
var RESIZABLE = /* @__PURE__ */ new Set(["image/jpeg", "image/png", "image/webp"]);
|
|
7051
|
+
var MAX_SIDE = 2560;
|
|
7052
|
+
var SHRINK_ABOVE_BYTES = 1.5 * 1024 * 1024;
|
|
7053
|
+
function loadImage(file) {
|
|
7054
|
+
return new Promise((resolve, reject) => {
|
|
7055
|
+
const url = URL.createObjectURL(file);
|
|
7056
|
+
const img = new Image();
|
|
7057
|
+
img.onload = () => {
|
|
7058
|
+
URL.revokeObjectURL(url);
|
|
7059
|
+
resolve(img);
|
|
7060
|
+
};
|
|
7061
|
+
img.onerror = () => {
|
|
7062
|
+
URL.revokeObjectURL(url);
|
|
7063
|
+
reject(new Error("image_decode_failed"));
|
|
7064
|
+
};
|
|
7065
|
+
img.src = url;
|
|
7066
|
+
});
|
|
7067
|
+
}
|
|
7068
|
+
async function prepareCommentFile(file) {
|
|
7069
|
+
if (!RESIZABLE.has(file.type) || typeof document === "undefined") {
|
|
7070
|
+
return { file, width: null, height: null };
|
|
7071
|
+
}
|
|
7072
|
+
let img;
|
|
7073
|
+
try {
|
|
7074
|
+
img = await loadImage(file);
|
|
7075
|
+
} catch {
|
|
7076
|
+
return { file, width: null, height: null };
|
|
7077
|
+
}
|
|
7078
|
+
const width = img.naturalWidth;
|
|
7079
|
+
const height = img.naturalHeight;
|
|
7080
|
+
const longSide = Math.max(width, height);
|
|
7081
|
+
if (file.size <= SHRINK_ABOVE_BYTES && longSide <= MAX_SIDE) {
|
|
7082
|
+
return { file, width, height };
|
|
7083
|
+
}
|
|
7084
|
+
const scale = Math.min(1, MAX_SIDE / longSide);
|
|
7085
|
+
const canvas = document.createElement("canvas");
|
|
7086
|
+
canvas.width = Math.round(width * scale);
|
|
7087
|
+
canvas.height = Math.round(height * scale);
|
|
7088
|
+
const ctx = canvas.getContext("2d");
|
|
7089
|
+
if (!ctx) return { file, width, height };
|
|
7090
|
+
ctx.fillStyle = "#ffffff";
|
|
7091
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
7092
|
+
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
7093
|
+
const blob = await new Promise((resolve) => canvas.toBlob(resolve, "image/jpeg", 0.85));
|
|
7094
|
+
if (!blob || blob.size >= file.size) return { file, width, height };
|
|
7095
|
+
const name = file.name.replace(/\.[^.]+$/, "") + ".jpg";
|
|
7096
|
+
return {
|
|
7097
|
+
file: new File([blob], name, { type: "image/jpeg", lastModified: file.lastModified }),
|
|
7098
|
+
width: canvas.width,
|
|
7099
|
+
height: canvas.height
|
|
7100
|
+
};
|
|
7101
|
+
}
|
|
7102
|
+
|
|
7103
|
+
export { AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogRoot, AlertDialogTitle, AlertDialogTrigger, AmbientBackground, Avatar, Badge, Button, Calendar, Card, CardContent, CardDescription, CardHeader, CardTitle, Checkbox, CheckboxGroup, Combobox, CommentThread, ConfirmDialog, CopyField, DataTable, DatePicker, DateRangeFilter, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogLayer, DialogRoot, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, EMPTY_DATE_RANGE, EmptyState, FileDropzone, FilterChip, FilterChipRow, FormField, IconButton, IconTile, Input, Label, MultiSelect, NavigationTabs, OtpInput, Page, PageHeader, Pagination, Popover, PopoverContent, PopoverDescription, PopoverHeader, PopoverTitle, PopoverTrigger, ProgressBar, ProgressDots, ProgressRing, RadioGroup, RichSelect, RichSelectContent, RichSelectEmpty, RichSelectGroup, RichSelectItem, RichSelectLabel, RichSelectSearch, RichSelectSeparator, RichSelectTrigger, RichSelectValue, SearchField, SectionHeading, SegmentedControl, Select, Separator, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetRoot, SheetTitle, SheetTrigger, Skeleton, Slot, Spinner, StatTile, StatTileGrid, StatusDot, Stepper, Switch, TINT_TONES, Table2 as Table, TableBody, TableCaption, TableCell, TableFooter, TableFrame, TableHead, TableHeader, TableRow, TableSkeleton, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Toolbar, ToolbarGroup, ToolbarSpacer, Tooltip, ValidationSummary, activeMentionQuery, avatarInitials, commentDraftFromBody, commentPlainText, formatCalendarDate, formatDateRange, isCalendarDate, isSameDateRange, isValidDateRange, menuStyle, mergeCommentMessages, parseCalendarDate, parseCommentBody, prepareCommentFile, registerDialogLayerPortal, resolveActiveNavigationHref, serializeCalendarDate, serializeCommentDraft, toneFromString, useAnchoredMenu };
|
|
6345
7104
|
//# sourceMappingURL=index.js.map
|
|
6346
7105
|
//# sourceMappingURL=index.js.map
|