@poolse/react-ui 1.0.6 → 1.1.0
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/CHANGELOG.md +78 -0
- package/README.md +266 -50
- package/dist/index.cjs +89 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +89 -63
- package/dist/index.js.map +1 -1
- package/dist/styles.css +216 -12
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -158,6 +158,13 @@ interface MessageBubbleProps {
|
|
|
158
158
|
* CSS until the row is hovered.
|
|
159
159
|
*/
|
|
160
160
|
actionsTrigger?: ReactNode;
|
|
161
|
+
/**
|
|
162
|
+
* Render the message's attachments INSIDE the bubble (WhatsApp-
|
|
163
|
+
* style): images mosaic at the top, file cards below, then the
|
|
164
|
+
* message body. Defaults to `true`. Pass `false` if you're rendering
|
|
165
|
+
* attachments yourself outside the bubble.
|
|
166
|
+
*/
|
|
167
|
+
showAttachments?: boolean;
|
|
161
168
|
}
|
|
162
169
|
/**
|
|
163
170
|
* One message bubble. The default renderer for `<ConversationView>` —
|
|
@@ -168,7 +175,7 @@ interface MessageBubbleProps {
|
|
|
168
175
|
* (coral for self, surface-with-border for others), matching the
|
|
169
176
|
* brand-kit chat showcase.
|
|
170
177
|
*/
|
|
171
|
-
declare function MessageBubble({ message, currentUserId, readState, labelFor, onQuotedClick, groupPosition, maxBodyLength, markdown, showSenderName, actionsTrigger, }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
|
|
178
|
+
declare function MessageBubble({ message, currentUserId, readState, labelFor, onQuotedClick, groupPosition, maxBodyLength, markdown, showSenderName, actionsTrigger, showAttachments, }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
|
|
172
179
|
|
|
173
180
|
interface EditableMessageBubbleProps {
|
|
174
181
|
message: Message;
|
package/dist/index.d.ts
CHANGED
|
@@ -158,6 +158,13 @@ interface MessageBubbleProps {
|
|
|
158
158
|
* CSS until the row is hovered.
|
|
159
159
|
*/
|
|
160
160
|
actionsTrigger?: ReactNode;
|
|
161
|
+
/**
|
|
162
|
+
* Render the message's attachments INSIDE the bubble (WhatsApp-
|
|
163
|
+
* style): images mosaic at the top, file cards below, then the
|
|
164
|
+
* message body. Defaults to `true`. Pass `false` if you're rendering
|
|
165
|
+
* attachments yourself outside the bubble.
|
|
166
|
+
*/
|
|
167
|
+
showAttachments?: boolean;
|
|
161
168
|
}
|
|
162
169
|
/**
|
|
163
170
|
* One message bubble. The default renderer for `<ConversationView>` —
|
|
@@ -168,7 +175,7 @@ interface MessageBubbleProps {
|
|
|
168
175
|
* (coral for self, surface-with-border for others), matching the
|
|
169
176
|
* brand-kit chat showcase.
|
|
170
177
|
*/
|
|
171
|
-
declare function MessageBubble({ message, currentUserId, readState, labelFor, onQuotedClick, groupPosition, maxBodyLength, markdown, showSenderName, actionsTrigger, }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
|
|
178
|
+
declare function MessageBubble({ message, currentUserId, readState, labelFor, onQuotedClick, groupPosition, maxBodyLength, markdown, showSenderName, actionsTrigger, showAttachments, }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
|
|
172
179
|
|
|
173
180
|
interface EditableMessageBubbleProps {
|
|
174
181
|
message: Message;
|
package/dist/index.js
CHANGED
|
@@ -709,17 +709,10 @@ var MessageComposer = forwardRef(
|
|
|
709
709
|
const taRef = useRef(null);
|
|
710
710
|
const fileInputRef = useRef(null);
|
|
711
711
|
useAutogrow(taRef, value);
|
|
712
|
-
const {
|
|
713
|
-
queue,
|
|
714
|
-
uploadAll,
|
|
715
|
-
cancel: cancelUpload,
|
|
716
|
-
remove: removeUpload
|
|
717
|
-
} = useAttachmentUpload();
|
|
712
|
+
const { queue, uploadAll, cancel: cancelUpload, remove: removeUpload } = useAttachmentUpload();
|
|
718
713
|
const visibleUploads = queue.filter((it) => it.status !== "cancelled");
|
|
719
714
|
const readyCount = queue.filter((it) => it.status === "ready").length;
|
|
720
|
-
const uploading = queue.some(
|
|
721
|
-
(it) => it.status === "pending" || it.status === "uploading"
|
|
722
|
-
);
|
|
715
|
+
const uploading = queue.some((it) => it.status === "pending" || it.status === "uploading");
|
|
723
716
|
const addFiles = (files) => {
|
|
724
717
|
if (!attachments || files.length === 0) return;
|
|
725
718
|
void uploadAll(
|
|
@@ -890,6 +883,24 @@ function ReplyChip({
|
|
|
890
883
|
)
|
|
891
884
|
] });
|
|
892
885
|
}
|
|
886
|
+
function Avatar({ src, name, online, size = "md", className }) {
|
|
887
|
+
const initials = computeInitials(name);
|
|
888
|
+
const classes = [
|
|
889
|
+
"poolse-avatar",
|
|
890
|
+
size === "sm" ? "poolse-avatar--sm" : null,
|
|
891
|
+
size === "lg" ? "poolse-avatar--lg" : null,
|
|
892
|
+
className
|
|
893
|
+
].filter(Boolean).join(" ");
|
|
894
|
+
return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
|
|
895
|
+
src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
|
|
896
|
+
online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
|
|
897
|
+
] });
|
|
898
|
+
}
|
|
899
|
+
function computeInitials(name) {
|
|
900
|
+
if (!name) return "?";
|
|
901
|
+
const parts = name.trim().split(/\s+/).slice(0, 2);
|
|
902
|
+
return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
|
|
903
|
+
}
|
|
893
904
|
function AttachmentPreview({ attachment, onClick }) {
|
|
894
905
|
const isFullRow = "content_type" in attachment;
|
|
895
906
|
const { url, loading, error } = useAttachmentUrl(attachment.id);
|
|
@@ -1053,24 +1064,6 @@ function formatBytes(n) {
|
|
|
1053
1064
|
if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
1054
1065
|
return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
1055
1066
|
}
|
|
1056
|
-
function Avatar({ src, name, online, size = "md", className }) {
|
|
1057
|
-
const initials = computeInitials(name);
|
|
1058
|
-
const classes = [
|
|
1059
|
-
"poolse-avatar",
|
|
1060
|
-
size === "sm" ? "poolse-avatar--sm" : null,
|
|
1061
|
-
size === "lg" ? "poolse-avatar--lg" : null,
|
|
1062
|
-
className
|
|
1063
|
-
].filter(Boolean).join(" ");
|
|
1064
|
-
return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
|
|
1065
|
-
src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
|
|
1066
|
-
online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
|
|
1067
|
-
] });
|
|
1068
|
-
}
|
|
1069
|
-
function computeInitials(name) {
|
|
1070
|
-
if (!name) return "?";
|
|
1071
|
-
const parts = name.trim().split(/\s+/).slice(0, 2);
|
|
1072
|
-
return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
|
|
1073
|
-
}
|
|
1074
1067
|
|
|
1075
1068
|
// src/userColor.ts
|
|
1076
1069
|
var PALETTE = [
|
|
@@ -1108,7 +1101,8 @@ function MessageBubble({
|
|
|
1108
1101
|
maxBodyLength = 0,
|
|
1109
1102
|
markdown = false,
|
|
1110
1103
|
showSenderName = false,
|
|
1111
|
-
actionsTrigger
|
|
1104
|
+
actionsTrigger,
|
|
1105
|
+
showAttachments = true
|
|
1112
1106
|
}) {
|
|
1113
1107
|
const isSelf = currentUserId !== null && message.sender_id === currentUserId;
|
|
1114
1108
|
const [expanded, setExpanded] = useState(false);
|
|
@@ -1117,17 +1111,27 @@ function MessageBubble({
|
|
|
1117
1111
|
const senderName = sender?.displayName ?? senderFallbackName;
|
|
1118
1112
|
const senderColorHex = message.sender_id ? userColor(message.sender_id) : "currentColor";
|
|
1119
1113
|
const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
|
|
1114
|
+
const rawBody = message.body ?? "";
|
|
1115
|
+
const TRIM_BUFFER = 40;
|
|
1116
|
+
const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
|
|
1117
|
+
const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
|
|
1118
|
+
const attachmentList = showAttachments && !message.deleted_at && Array.isArray(message.attachments) ? message.attachments : [];
|
|
1119
|
+
const imageAttachments = attachmentList.filter((a) => isImageContentType(a.content_type));
|
|
1120
|
+
const fileAttachments = attachmentList.filter((a) => !isImageContentType(a.content_type));
|
|
1121
|
+
const hasAnyAttachment = imageAttachments.length > 0 || fileAttachments.length > 0;
|
|
1122
|
+
const hasVisibleBody = !message.deleted_at && rawBody.length > 0;
|
|
1123
|
+
const metaOverlay = hasAnyAttachment && imageAttachments.length > 0 && !hasVisibleBody && fileAttachments.length === 0;
|
|
1120
1124
|
const className = [
|
|
1121
1125
|
"poolse-message",
|
|
1122
1126
|
isSelf ? "poolse-message--self" : "poolse-message--other",
|
|
1123
1127
|
// Group-position modifier — CSS uses it to toggle which corners
|
|
1124
1128
|
// get the asymmetric tail vs. fully-rounded treatment.
|
|
1125
|
-
`poolse-message--${groupPosition}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1129
|
+
`poolse-message--${groupPosition}`,
|
|
1130
|
+
// Tells the CSS to round the image mosaic's bottom corners to
|
|
1131
|
+
// match the bubble's outer corner when nothing follows the media.
|
|
1132
|
+
hasAnyAttachment ? "poolse-message--has-media" : "",
|
|
1133
|
+
metaOverlay ? "poolse-message--media-only" : ""
|
|
1134
|
+
].filter(Boolean).join(" ");
|
|
1131
1135
|
const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
|
|
1132
1136
|
hour: "2-digit",
|
|
1133
1137
|
minute: "2-digit"
|
|
@@ -1146,7 +1150,9 @@ function MessageBubble({
|
|
|
1146
1150
|
}
|
|
1147
1151
|
),
|
|
1148
1152
|
showQuoteCard === "placeholder" && /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
|
|
1149
|
-
|
|
1153
|
+
imageAttachments.length > 0 && /* @__PURE__ */ jsx(ImageMosaic, { images: imageAttachments }),
|
|
1154
|
+
fileAttachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "poolse-message__files", children: fileAttachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
|
|
1155
|
+
message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : hasVisibleBody ? /* @__PURE__ */ jsxs("div", { className: "poolse-message__body", children: [
|
|
1150
1156
|
markdown ? /* @__PURE__ */ jsx(
|
|
1151
1157
|
ReactMarkdown,
|
|
1152
1158
|
{
|
|
@@ -1183,21 +1189,53 @@ function MessageBubble({
|
|
|
1183
1189
|
children: "Show less"
|
|
1184
1190
|
}
|
|
1185
1191
|
)
|
|
1186
|
-
] }),
|
|
1187
|
-
/* @__PURE__ */ jsxs(
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1192
|
+
] }) : null,
|
|
1193
|
+
/* @__PURE__ */ jsxs(
|
|
1194
|
+
"span",
|
|
1195
|
+
{
|
|
1196
|
+
className: metaOverlay ? "poolse-message__meta poolse-message__meta--overlay" : "poolse-message__meta",
|
|
1197
|
+
children: [
|
|
1198
|
+
/* @__PURE__ */ jsx("span", { children: time }),
|
|
1199
|
+
message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
|
|
1200
|
+
isSelf && readState ? /* @__PURE__ */ jsx(
|
|
1201
|
+
PoolseIcon,
|
|
1202
|
+
{
|
|
1203
|
+
name: readState === "read" ? "check-double" : "check",
|
|
1204
|
+
size: 14,
|
|
1205
|
+
label: readState === "read" ? "Read" : "Sent"
|
|
1206
|
+
}
|
|
1207
|
+
) : null
|
|
1208
|
+
]
|
|
1209
|
+
}
|
|
1210
|
+
)
|
|
1199
1211
|
] });
|
|
1200
1212
|
}
|
|
1213
|
+
function isImageContentType(ct) {
|
|
1214
|
+
return typeof ct === "string" && ct.toLowerCase().startsWith("image/");
|
|
1215
|
+
}
|
|
1216
|
+
function ImageMosaic({ images }) {
|
|
1217
|
+
const total = images.length;
|
|
1218
|
+
const visible = images.slice(0, 4);
|
|
1219
|
+
const layout = Math.min(total, 4);
|
|
1220
|
+
const overflow = Math.max(0, total - 4);
|
|
1221
|
+
return /* @__PURE__ */ jsx(
|
|
1222
|
+
"div",
|
|
1223
|
+
{
|
|
1224
|
+
className: `poolse-message__media poolse-message__media--n${layout}`,
|
|
1225
|
+
"aria-label": total === 1 ? "Image" : `${total} images`,
|
|
1226
|
+
children: visible.map((att, i) => {
|
|
1227
|
+
const isOverflowTile = i === visible.length - 1 && overflow > 0;
|
|
1228
|
+
return /* @__PURE__ */ jsxs("div", { className: "poolse-message__media-tile", children: [
|
|
1229
|
+
/* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }),
|
|
1230
|
+
isOverflowTile && /* @__PURE__ */ jsxs("div", { className: "poolse-message__media-overflow", "aria-hidden": "true", children: [
|
|
1231
|
+
"+",
|
|
1232
|
+
overflow
|
|
1233
|
+
] })
|
|
1234
|
+
] }, att.id);
|
|
1235
|
+
})
|
|
1236
|
+
}
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1201
1239
|
function QuotedPlaceholder({
|
|
1202
1240
|
isSelf,
|
|
1203
1241
|
quotedMessageId: _quotedMessageId
|
|
@@ -1535,7 +1573,6 @@ function MessageRow({
|
|
|
1535
1573
|
currentUserId: meId
|
|
1536
1574
|
});
|
|
1537
1575
|
const showReactions = reactions && !msg.deleted_at;
|
|
1538
|
-
const showAttachments = attachments && Array.isArray(msg.attachments) && msg.attachments.length > 0;
|
|
1539
1576
|
const showActions = actions && !msg.deleted_at && !editing;
|
|
1540
1577
|
const replyCount = msg.reply_count ?? 0;
|
|
1541
1578
|
const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
|
|
@@ -1605,6 +1642,7 @@ function MessageRow({
|
|
|
1605
1642
|
maxBodyLength,
|
|
1606
1643
|
markdown,
|
|
1607
1644
|
showSenderName,
|
|
1645
|
+
showAttachments: attachments,
|
|
1608
1646
|
...readState ? { readState } : {},
|
|
1609
1647
|
...labelFor ? { labelFor } : {},
|
|
1610
1648
|
...onQuotedClick ? { onQuotedClick } : {},
|
|
@@ -1628,7 +1666,6 @@ function MessageRow({
|
|
|
1628
1666
|
)
|
|
1629
1667
|
}
|
|
1630
1668
|
),
|
|
1631
|
-
showAttachments && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__attachments ${isSelf ? "is-self" : ""}`, children: msg.attachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
|
|
1632
1669
|
showReactions && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsx(
|
|
1633
1670
|
InlineReactions,
|
|
1634
1671
|
{
|
|
@@ -1887,16 +1924,7 @@ function TypingIndicator({ typing, labelFor }) {
|
|
|
1887
1924
|
/* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" }),
|
|
1888
1925
|
/* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" })
|
|
1889
1926
|
] }),
|
|
1890
|
-
/* @__PURE__ */ jsx(
|
|
1891
|
-
"span",
|
|
1892
|
-
{
|
|
1893
|
-
className: "poolse-typing__label",
|
|
1894
|
-
role: "status",
|
|
1895
|
-
"aria-live": "polite",
|
|
1896
|
-
"aria-atomic": "true",
|
|
1897
|
-
children: isTyping ? /* @__PURE__ */ jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : ""
|
|
1898
|
-
}
|
|
1899
|
-
)
|
|
1927
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-typing__label", role: "status", "aria-live": "polite", "aria-atomic": "true", children: isTyping ? /* @__PURE__ */ jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : "" })
|
|
1900
1928
|
] });
|
|
1901
1929
|
}
|
|
1902
1930
|
function TypingLabel({ ids, labelFor }) {
|
|
@@ -2376,9 +2404,7 @@ function MemberList({
|
|
|
2376
2404
|
emptyState
|
|
2377
2405
|
}) {
|
|
2378
2406
|
const { members, loading, error, removeMember } = useMembers(conversationId);
|
|
2379
|
-
const { online: presenceOnline } = usePresence(
|
|
2380
|
-
onlineUserIds === void 0 ? conversationId : ""
|
|
2381
|
-
);
|
|
2407
|
+
const { online: presenceOnline } = usePresence(onlineUserIds === void 0 ? conversationId : "");
|
|
2382
2408
|
const effectiveOnline = onlineUserIds ?? presenceOnline;
|
|
2383
2409
|
if (loading && members.length === 0) {
|
|
2384
2410
|
return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: "Loading members\u2026" });
|