@mieweb/ui 0.6.1-dev.149 → 0.6.1-dev.150
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/brands/index.cjs +22 -22
- package/dist/brands/index.js +5 -5
- package/dist/chunk-2T4JU5RH.cjs +1156 -0
- package/dist/chunk-2T4JU5RH.cjs.map +1 -0
- package/dist/chunk-3SSXDWD7.js +363 -0
- package/dist/chunk-3SSXDWD7.js.map +1 -0
- package/dist/{chunk-MARLXJQO.cjs → chunk-6R2ZPDN7.cjs} +7 -7
- package/dist/{chunk-MARLXJQO.cjs.map → chunk-6R2ZPDN7.cjs.map} +1 -1
- package/dist/{chunk-WHUD3XHR.cjs → chunk-7PA26KBF.cjs} +15 -3
- package/dist/chunk-7PA26KBF.cjs.map +1 -0
- package/dist/chunk-ASLZUFH4.js +1967 -0
- package/dist/chunk-ASLZUFH4.js.map +1 -0
- package/dist/chunk-FADQVM4M.cjs +2017 -0
- package/dist/chunk-FADQVM4M.cjs.map +1 -0
- package/dist/{chunk-DFT7TYKL.cjs → chunk-H4T5T65N.cjs} +6 -3
- package/dist/chunk-H4T5T65N.cjs.map +1 -0
- package/dist/chunk-I6CY5C6A.js +12 -0
- package/dist/chunk-I6CY5C6A.js.map +1 -0
- package/dist/chunk-JFLC7SHM.cjs +35 -0
- package/dist/chunk-JFLC7SHM.cjs.map +1 -0
- package/dist/chunk-LZPPH5BW.cjs +368 -0
- package/dist/chunk-LZPPH5BW.cjs.map +1 -0
- package/dist/{chunk-3OHVUXDG.js → chunk-M7BLVBL4.js} +6 -3
- package/dist/chunk-M7BLVBL4.js.map +1 -0
- package/dist/chunk-PM2I3QKM.cjs +1419 -0
- package/dist/chunk-PM2I3QKM.cjs.map +1 -0
- package/dist/{chunk-TW6DXMSD.js → chunk-R6PBBPU3.js} +2 -2
- package/dist/{chunk-TW6DXMSD.js.map → chunk-R6PBBPU3.js.map} +1 -1
- package/dist/{chunk-33PO3J4O.js → chunk-RXY5SD3O.js} +15 -3
- package/dist/chunk-RXY5SD3O.js.map +1 -0
- package/dist/{chunk-AEGYWRSL.js → chunk-TXYTMU3K.js} +3 -3
- package/dist/{chunk-AEGYWRSL.js.map → chunk-TXYTMU3K.js.map} +1 -1
- package/dist/chunk-UHPQYBXQ.js +1124 -0
- package/dist/chunk-UHPQYBXQ.js.map +1 -0
- package/dist/chunk-XQE26F3G.js +1383 -0
- package/dist/chunk-XQE26F3G.js.map +1 -0
- package/dist/{chunk-26YNFCOC.cjs → chunk-Z6NRP4Z5.cjs} +2 -2
- package/dist/{chunk-26YNFCOC.cjs.map → chunk-Z6NRP4Z5.cjs.map} +1 -1
- package/dist/components/Dropdown/index.cjs +7 -7
- package/dist/components/Dropdown/index.d.cts +1 -1
- package/dist/components/Dropdown/index.d.ts +1 -1
- package/dist/components/Dropdown/index.js +1 -1
- package/dist/components/RichTextEditor/index.cjs +5 -5
- package/dist/components/RichTextEditor/index.js +2 -2
- package/dist/components/SuperChat/index.cjs +1319 -0
- package/dist/components/SuperChat/index.cjs.map +1 -0
- package/dist/components/SuperChat/index.d.cts +189 -0
- package/dist/components/SuperChat/index.d.ts +189 -0
- package/dist/components/SuperChat/index.js +1282 -0
- package/dist/components/SuperChat/index.js.map +1 -0
- package/dist/components/SuperChat/plugins/index.cjs +1221 -0
- package/dist/components/SuperChat/plugins/index.cjs.map +1 -0
- package/dist/components/SuperChat/plugins/index.d.cts +253 -0
- package/dist/components/SuperChat/plugins/index.d.ts +253 -0
- package/dist/components/SuperChat/plugins/index.js +1181 -0
- package/dist/components/SuperChat/plugins/index.js.map +1 -0
- package/dist/datavis.cjs +18 -362
- package/dist/datavis.cjs.map +1 -1
- package/dist/datavis.js +1 -361
- package/dist/datavis.js.map +1 -1
- package/dist/index.cjs +1297 -5412
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -240
- package/dist/index.d.ts +44 -240
- package/dist/index.js +759 -5037
- package/dist/index.js.map +1 -1
- package/dist/nitroTableGrid-FWRCDE4N.js +22 -0
- package/dist/nitroTableGrid-FWRCDE4N.js.map +1 -0
- package/dist/nitroTableGrid-IY75TQJ2.cjs +44 -0
- package/dist/nitroTableGrid-IY75TQJ2.cjs.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/tailwind-preset.cjs +4 -4
- package/dist/tailwind-preset.js +1 -1
- package/dist/types-BFFgW6qy.d.ts +240 -0
- package/dist/types-BzeY_kYO.d.cts +242 -0
- package/dist/types-BzeY_kYO.d.ts +242 -0
- package/dist/types-CRt5IPNL.d.cts +240 -0
- package/package.json +41 -4
- package/dist/chunk-33PO3J4O.js.map +0 -1
- package/dist/chunk-3OHVUXDG.js.map +0 -1
- package/dist/chunk-DFT7TYKL.cjs.map +0 -1
- package/dist/chunk-WHUD3XHR.cjs.map +0 -1
|
@@ -0,0 +1,1967 @@
|
|
|
1
|
+
import { DragDropZone, MessageComposer } from './chunk-UHPQYBXQ.js';
|
|
2
|
+
import { cn } from './chunk-F3SOEIN2.js';
|
|
3
|
+
import * as React5 from 'react';
|
|
4
|
+
import { cva } from 'class-variance-authority';
|
|
5
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
var statusIconVariants = cva(
|
|
8
|
+
"inline-flex items-center gap-0.5 text-current",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
status: {
|
|
12
|
+
sending: "text-neutral-500",
|
|
13
|
+
sent: "text-neutral-500",
|
|
14
|
+
delivered: "text-muted-foreground",
|
|
15
|
+
read: "text-primary-800 dark:text-primary-300",
|
|
16
|
+
failed: "text-red-500"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
status: "sent"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
function MessageStatusIcon({ status, className }) {
|
|
25
|
+
return /* @__PURE__ */ jsxs(
|
|
26
|
+
"span",
|
|
27
|
+
{
|
|
28
|
+
className: cn(statusIconVariants({ status }), className),
|
|
29
|
+
role: "img",
|
|
30
|
+
"aria-label": `Message ${status}`,
|
|
31
|
+
children: [
|
|
32
|
+
status === "sending" && /* @__PURE__ */ jsxs(
|
|
33
|
+
"svg",
|
|
34
|
+
{
|
|
35
|
+
"aria-hidden": "true",
|
|
36
|
+
className: "h-3.5 w-3.5 animate-spin",
|
|
37
|
+
fill: "none",
|
|
38
|
+
viewBox: "0 0 24 24",
|
|
39
|
+
children: [
|
|
40
|
+
/* @__PURE__ */ jsx(
|
|
41
|
+
"circle",
|
|
42
|
+
{
|
|
43
|
+
className: "opacity-25",
|
|
44
|
+
cx: "12",
|
|
45
|
+
cy: "12",
|
|
46
|
+
r: "10",
|
|
47
|
+
stroke: "currentColor",
|
|
48
|
+
strokeWidth: "4"
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
/* @__PURE__ */ jsx(
|
|
52
|
+
"path",
|
|
53
|
+
{
|
|
54
|
+
className: "opacity-75",
|
|
55
|
+
fill: "currentColor",
|
|
56
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
),
|
|
62
|
+
status === "sent" && /* @__PURE__ */ jsx(
|
|
63
|
+
"svg",
|
|
64
|
+
{
|
|
65
|
+
"aria-hidden": "true",
|
|
66
|
+
className: "h-3.5 w-3.5",
|
|
67
|
+
fill: "none",
|
|
68
|
+
viewBox: "0 0 24 24",
|
|
69
|
+
stroke: "currentColor",
|
|
70
|
+
strokeWidth: "2",
|
|
71
|
+
children: /* @__PURE__ */ jsx(
|
|
72
|
+
"path",
|
|
73
|
+
{
|
|
74
|
+
strokeLinecap: "round",
|
|
75
|
+
strokeLinejoin: "round",
|
|
76
|
+
d: "M5 13l4 4L19 7"
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
),
|
|
81
|
+
(status === "delivered" || status === "read") && /* @__PURE__ */ jsxs(
|
|
82
|
+
"svg",
|
|
83
|
+
{
|
|
84
|
+
"aria-hidden": "true",
|
|
85
|
+
className: "h-4 w-4",
|
|
86
|
+
fill: "none",
|
|
87
|
+
viewBox: "0 0 24 24",
|
|
88
|
+
stroke: "currentColor",
|
|
89
|
+
strokeWidth: "2",
|
|
90
|
+
children: [
|
|
91
|
+
/* @__PURE__ */ jsx(
|
|
92
|
+
"path",
|
|
93
|
+
{
|
|
94
|
+
strokeLinecap: "round",
|
|
95
|
+
strokeLinejoin: "round",
|
|
96
|
+
d: "M5 13l4 4L19 7"
|
|
97
|
+
}
|
|
98
|
+
),
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
"path",
|
|
101
|
+
{
|
|
102
|
+
strokeLinecap: "round",
|
|
103
|
+
strokeLinejoin: "round",
|
|
104
|
+
d: "M12 13l4 4L26 7",
|
|
105
|
+
transform: "translate(-5, 0)"
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
),
|
|
111
|
+
status === "failed" && /* @__PURE__ */ jsx(
|
|
112
|
+
"svg",
|
|
113
|
+
{
|
|
114
|
+
"aria-hidden": "true",
|
|
115
|
+
className: "h-3.5 w-3.5",
|
|
116
|
+
fill: "none",
|
|
117
|
+
viewBox: "0 0 24 24",
|
|
118
|
+
stroke: "currentColor",
|
|
119
|
+
strokeWidth: "2",
|
|
120
|
+
children: /* @__PURE__ */ jsx(
|
|
121
|
+
"path",
|
|
122
|
+
{
|
|
123
|
+
strokeLinecap: "round",
|
|
124
|
+
strokeLinejoin: "round",
|
|
125
|
+
d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
function ReadReceiptIndicator({
|
|
135
|
+
receipts,
|
|
136
|
+
maxAvatars = 3,
|
|
137
|
+
size = "xs",
|
|
138
|
+
className
|
|
139
|
+
}) {
|
|
140
|
+
if (receipts.length === 0) return null;
|
|
141
|
+
const visibleReceipts = receipts.slice(0, maxAvatars);
|
|
142
|
+
const remainingCount = receipts.length - maxAvatars;
|
|
143
|
+
const sizeClasses = {
|
|
144
|
+
xs: "h-4 w-4 text-[8px]",
|
|
145
|
+
sm: "h-5 w-5 text-[10px]"
|
|
146
|
+
};
|
|
147
|
+
return /* @__PURE__ */ jsxs(
|
|
148
|
+
"div",
|
|
149
|
+
{
|
|
150
|
+
className: cn("flex items-center -space-x-1", className),
|
|
151
|
+
"aria-label": `Read by ${receipts.map((r) => r.participant.name).join(", ")}`,
|
|
152
|
+
children: [
|
|
153
|
+
visibleReceipts.map((receipt) => /* @__PURE__ */ jsx(
|
|
154
|
+
"div",
|
|
155
|
+
{
|
|
156
|
+
className: cn(
|
|
157
|
+
"rounded-full ring-2 ring-white dark:ring-neutral-900",
|
|
158
|
+
"bg-primary-800 font-medium text-white",
|
|
159
|
+
"flex items-center justify-center",
|
|
160
|
+
sizeClasses[size]
|
|
161
|
+
),
|
|
162
|
+
title: `Read by ${receipt.participant.name}`,
|
|
163
|
+
children: receipt.participant.avatarUrl ? /* @__PURE__ */ jsx(
|
|
164
|
+
"img",
|
|
165
|
+
{
|
|
166
|
+
src: receipt.participant.avatarUrl,
|
|
167
|
+
alt: receipt.participant.name,
|
|
168
|
+
className: "h-full w-full rounded-full object-cover"
|
|
169
|
+
}
|
|
170
|
+
) : receipt.participant.name.charAt(0).toUpperCase()
|
|
171
|
+
},
|
|
172
|
+
receipt.participant.id
|
|
173
|
+
)),
|
|
174
|
+
remainingCount > 0 && /* @__PURE__ */ jsxs(
|
|
175
|
+
"div",
|
|
176
|
+
{
|
|
177
|
+
className: cn(
|
|
178
|
+
"rounded-full ring-2 ring-white dark:ring-neutral-900",
|
|
179
|
+
"bg-neutral-500 font-medium text-white",
|
|
180
|
+
"flex items-center justify-center",
|
|
181
|
+
sizeClasses[size]
|
|
182
|
+
),
|
|
183
|
+
children: [
|
|
184
|
+
"+",
|
|
185
|
+
remainingCount
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
)
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
function AttachmentPreview({
|
|
194
|
+
attachment,
|
|
195
|
+
onClick,
|
|
196
|
+
className
|
|
197
|
+
}) {
|
|
198
|
+
const isImage = attachment.type === "image";
|
|
199
|
+
const isVideo = attachment.type === "video";
|
|
200
|
+
if (isImage || isVideo) {
|
|
201
|
+
return /* @__PURE__ */ jsxs(
|
|
202
|
+
"button",
|
|
203
|
+
{
|
|
204
|
+
type: "button",
|
|
205
|
+
onClick,
|
|
206
|
+
className: cn(
|
|
207
|
+
"relative block overflow-hidden rounded-lg",
|
|
208
|
+
"focus:ring-primary-500 focus:ring-2 focus:outline-none",
|
|
209
|
+
"transition-transform hover:scale-[1.02]",
|
|
210
|
+
className
|
|
211
|
+
),
|
|
212
|
+
"aria-label": `View ${attachment.alt || attachment.filename}`,
|
|
213
|
+
children: [
|
|
214
|
+
/* @__PURE__ */ jsx(
|
|
215
|
+
"img",
|
|
216
|
+
{
|
|
217
|
+
src: attachment.thumbnailUrl || attachment.url,
|
|
218
|
+
alt: attachment.alt || attachment.filename,
|
|
219
|
+
className: "max-h-64 w-auto rounded-lg object-cover",
|
|
220
|
+
loading: "lazy"
|
|
221
|
+
}
|
|
222
|
+
),
|
|
223
|
+
isVideo && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/30", children: /* @__PURE__ */ jsx("div", { className: "rounded-full bg-white/90 p-3", children: /* @__PURE__ */ jsx(
|
|
224
|
+
"svg",
|
|
225
|
+
{
|
|
226
|
+
"aria-hidden": "true",
|
|
227
|
+
className: "h-6 w-6 text-neutral-900",
|
|
228
|
+
fill: "currentColor",
|
|
229
|
+
viewBox: "0 0 24 24",
|
|
230
|
+
children: /* @__PURE__ */ jsx("path", { d: "M8 5v14l11-7z" })
|
|
231
|
+
}
|
|
232
|
+
) }) }),
|
|
233
|
+
attachment.state === "uploading" && attachment.progress !== void 0 && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ jsxs("div", { className: "text-center text-white", children: [
|
|
234
|
+
/* @__PURE__ */ jsxs(
|
|
235
|
+
"svg",
|
|
236
|
+
{
|
|
237
|
+
"aria-hidden": "true",
|
|
238
|
+
className: "mx-auto h-8 w-8 animate-spin",
|
|
239
|
+
fill: "none",
|
|
240
|
+
viewBox: "0 0 24 24",
|
|
241
|
+
children: [
|
|
242
|
+
/* @__PURE__ */ jsx(
|
|
243
|
+
"circle",
|
|
244
|
+
{
|
|
245
|
+
className: "opacity-25",
|
|
246
|
+
cx: "12",
|
|
247
|
+
cy: "12",
|
|
248
|
+
r: "10",
|
|
249
|
+
stroke: "currentColor",
|
|
250
|
+
strokeWidth: "4"
|
|
251
|
+
}
|
|
252
|
+
),
|
|
253
|
+
/* @__PURE__ */ jsx(
|
|
254
|
+
"path",
|
|
255
|
+
{
|
|
256
|
+
className: "opacity-75",
|
|
257
|
+
fill: "currentColor",
|
|
258
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
|
259
|
+
}
|
|
260
|
+
)
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
),
|
|
264
|
+
/* @__PURE__ */ jsxs("span", { className: "mt-1 text-sm", children: [
|
|
265
|
+
attachment.progress,
|
|
266
|
+
"%"
|
|
267
|
+
] })
|
|
268
|
+
] }) }),
|
|
269
|
+
attachment.state === "failed" && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ jsxs("div", { className: "text-center text-white", children: [
|
|
270
|
+
/* @__PURE__ */ jsx(
|
|
271
|
+
"svg",
|
|
272
|
+
{
|
|
273
|
+
"aria-hidden": "true",
|
|
274
|
+
className: "mx-auto h-8 w-8 text-red-400",
|
|
275
|
+
fill: "none",
|
|
276
|
+
viewBox: "0 0 24 24",
|
|
277
|
+
stroke: "currentColor",
|
|
278
|
+
children: /* @__PURE__ */ jsx(
|
|
279
|
+
"path",
|
|
280
|
+
{
|
|
281
|
+
strokeLinecap: "round",
|
|
282
|
+
strokeLinejoin: "round",
|
|
283
|
+
strokeWidth: 2,
|
|
284
|
+
d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
|
|
285
|
+
}
|
|
286
|
+
)
|
|
287
|
+
}
|
|
288
|
+
),
|
|
289
|
+
/* @__PURE__ */ jsx("span", { className: "mt-1 text-sm", children: "Upload failed" })
|
|
290
|
+
] }) })
|
|
291
|
+
]
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
return /* @__PURE__ */ jsxs(
|
|
296
|
+
"button",
|
|
297
|
+
{
|
|
298
|
+
type: "button",
|
|
299
|
+
onClick,
|
|
300
|
+
className: cn(
|
|
301
|
+
"flex items-center gap-3 rounded-lg p-3",
|
|
302
|
+
"bg-white/10 hover:bg-white/20",
|
|
303
|
+
"transition-colors",
|
|
304
|
+
"focus:ring-primary-500 focus:ring-2 focus:outline-none",
|
|
305
|
+
className
|
|
306
|
+
),
|
|
307
|
+
children: [
|
|
308
|
+
/* @__PURE__ */ jsx("div", { className: "rounded-lg bg-white/20 p-2", children: /* @__PURE__ */ jsx(
|
|
309
|
+
"svg",
|
|
310
|
+
{
|
|
311
|
+
"aria-hidden": "true",
|
|
312
|
+
className: "h-6 w-6",
|
|
313
|
+
fill: "none",
|
|
314
|
+
viewBox: "0 0 24 24",
|
|
315
|
+
stroke: "currentColor",
|
|
316
|
+
children: /* @__PURE__ */ jsx(
|
|
317
|
+
"path",
|
|
318
|
+
{
|
|
319
|
+
strokeLinecap: "round",
|
|
320
|
+
strokeLinejoin: "round",
|
|
321
|
+
strokeWidth: 2,
|
|
322
|
+
d: "M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
|
|
323
|
+
}
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
) }),
|
|
327
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 text-left", children: [
|
|
328
|
+
/* @__PURE__ */ jsx("p", { className: "truncate text-sm font-medium", children: attachment.filename }),
|
|
329
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs opacity-70", children: formatFileSize(attachment.size) })
|
|
330
|
+
] })
|
|
331
|
+
]
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
function formatFileSize(bytes) {
|
|
336
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
337
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
338
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
339
|
+
}
|
|
340
|
+
var bubbleVariants = cva(
|
|
341
|
+
[
|
|
342
|
+
"relative max-w-[85%] sm:max-w-[70%]",
|
|
343
|
+
"rounded-2xl px-4 py-2",
|
|
344
|
+
"transition-all duration-200"
|
|
345
|
+
],
|
|
346
|
+
{
|
|
347
|
+
variants: {
|
|
348
|
+
variant: {
|
|
349
|
+
outgoing: ["bg-primary-800 text-white", "rounded-br-md", "ml-auto"],
|
|
350
|
+
incoming: [
|
|
351
|
+
"bg-neutral-100 text-neutral-900",
|
|
352
|
+
"dark:bg-neutral-800 dark:text-neutral-100",
|
|
353
|
+
"rounded-bl-md",
|
|
354
|
+
"mr-auto"
|
|
355
|
+
],
|
|
356
|
+
system: [
|
|
357
|
+
"mx-auto max-w-none",
|
|
358
|
+
"bg-transparent text-muted-foreground",
|
|
359
|
+
"text-center text-sm",
|
|
360
|
+
"py-1 px-2"
|
|
361
|
+
]
|
|
362
|
+
},
|
|
363
|
+
status: {
|
|
364
|
+
sending: "",
|
|
365
|
+
sent: "",
|
|
366
|
+
delivered: "",
|
|
367
|
+
read: "",
|
|
368
|
+
failed: "ring-2 ring-red-500/50"
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
defaultVariants: {
|
|
372
|
+
variant: "incoming",
|
|
373
|
+
status: "sent"
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
);
|
|
377
|
+
function defaultFormatTimestamp(timestamp) {
|
|
378
|
+
const date = typeof timestamp === "string" ? new Date(timestamp) : timestamp;
|
|
379
|
+
return date.toLocaleTimeString(void 0, {
|
|
380
|
+
hour: "numeric",
|
|
381
|
+
minute: "2-digit"
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
var MessageBubble = React5.forwardRef(
|
|
385
|
+
({
|
|
386
|
+
className,
|
|
387
|
+
message,
|
|
388
|
+
showAvatar = false,
|
|
389
|
+
showSenderName = false,
|
|
390
|
+
showTimestamp = true,
|
|
391
|
+
showStatus = true,
|
|
392
|
+
showReadReceipts = true,
|
|
393
|
+
onRetry,
|
|
394
|
+
onAttachmentClick,
|
|
395
|
+
isOutgoing,
|
|
396
|
+
formatTimestamp = defaultFormatTimestamp,
|
|
397
|
+
...props
|
|
398
|
+
}, ref) => {
|
|
399
|
+
const isSystem = message.type === "system";
|
|
400
|
+
const variant = isSystem ? "system" : isOutgoing ? "outgoing" : "incoming";
|
|
401
|
+
const hasAttachments = message.attachments && message.attachments.length > 0;
|
|
402
|
+
const hasText = message.content && message.content.trim().length > 0;
|
|
403
|
+
const isFailed = message.status === "failed";
|
|
404
|
+
if (isSystem) {
|
|
405
|
+
return /* @__PURE__ */ jsx(
|
|
406
|
+
"div",
|
|
407
|
+
{
|
|
408
|
+
ref,
|
|
409
|
+
"data-slot": "message-system",
|
|
410
|
+
className: cn(bubbleVariants({ variant: "system" }), className),
|
|
411
|
+
role: "status",
|
|
412
|
+
"aria-live": "polite",
|
|
413
|
+
...props,
|
|
414
|
+
children: message.content
|
|
415
|
+
}
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
return /* @__PURE__ */ jsxs(
|
|
419
|
+
"div",
|
|
420
|
+
{
|
|
421
|
+
ref,
|
|
422
|
+
"data-slot": "message-bubble",
|
|
423
|
+
className: cn(
|
|
424
|
+
"group flex items-end gap-2",
|
|
425
|
+
isOutgoing ? "flex-row-reverse" : "flex-row",
|
|
426
|
+
className
|
|
427
|
+
),
|
|
428
|
+
...props,
|
|
429
|
+
children: [
|
|
430
|
+
showAvatar && !isOutgoing && /* @__PURE__ */ jsx("div", { "data-slot": "message-avatar", className: "mb-1 shrink-0", children: /* @__PURE__ */ jsx(
|
|
431
|
+
"div",
|
|
432
|
+
{
|
|
433
|
+
className: cn(
|
|
434
|
+
"flex h-8 w-8 items-center justify-center rounded-full",
|
|
435
|
+
"bg-primary-800 text-sm font-medium text-white"
|
|
436
|
+
),
|
|
437
|
+
children: message.sender.avatarUrl ? /* @__PURE__ */ jsx(
|
|
438
|
+
"img",
|
|
439
|
+
{
|
|
440
|
+
src: message.sender.avatarUrl,
|
|
441
|
+
alt: message.sender.name,
|
|
442
|
+
className: "h-full w-full rounded-full object-cover"
|
|
443
|
+
}
|
|
444
|
+
) : message.sender.name.charAt(0).toUpperCase()
|
|
445
|
+
}
|
|
446
|
+
) }),
|
|
447
|
+
/* @__PURE__ */ jsxs(
|
|
448
|
+
"div",
|
|
449
|
+
{
|
|
450
|
+
className: cn(
|
|
451
|
+
"flex min-w-0 flex-1 flex-col",
|
|
452
|
+
isOutgoing ? "items-end" : "items-start"
|
|
453
|
+
),
|
|
454
|
+
children: [
|
|
455
|
+
showSenderName && !isOutgoing && /* @__PURE__ */ jsx(
|
|
456
|
+
"span",
|
|
457
|
+
{
|
|
458
|
+
"data-slot": "message-sender-name",
|
|
459
|
+
className: "text-muted-foreground mb-1 px-1 text-xs font-medium",
|
|
460
|
+
children: message.sender.name
|
|
461
|
+
}
|
|
462
|
+
),
|
|
463
|
+
message.replyTo && /* @__PURE__ */ jsxs(
|
|
464
|
+
"div",
|
|
465
|
+
{
|
|
466
|
+
"data-slot": "message-reply-preview",
|
|
467
|
+
className: cn(
|
|
468
|
+
"mb-1 max-w-full rounded-lg px-3 py-1.5 text-xs",
|
|
469
|
+
isOutgoing ? "bg-primary-700/50 text-white/80" : "bg-neutral-200 text-neutral-600 dark:bg-neutral-700 dark:text-neutral-300"
|
|
470
|
+
),
|
|
471
|
+
children: [
|
|
472
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: message.replyTo.sender.name }),
|
|
473
|
+
/* @__PURE__ */ jsx("p", { className: "truncate", children: message.replyTo.content })
|
|
474
|
+
]
|
|
475
|
+
}
|
|
476
|
+
),
|
|
477
|
+
/* @__PURE__ */ jsxs(
|
|
478
|
+
"div",
|
|
479
|
+
{
|
|
480
|
+
"data-slot": "message-bubble-content",
|
|
481
|
+
className: cn(bubbleVariants({ variant, status: message.status })),
|
|
482
|
+
role: "article",
|
|
483
|
+
"aria-label": `Message from ${message.sender.name}`,
|
|
484
|
+
children: [
|
|
485
|
+
hasAttachments && /* @__PURE__ */ jsx("div", { className: cn("space-y-2", hasText && "mb-2"), children: message.attachments.map((attachment) => /* @__PURE__ */ jsx(
|
|
486
|
+
AttachmentPreview,
|
|
487
|
+
{
|
|
488
|
+
attachment,
|
|
489
|
+
onClick: () => onAttachmentClick?.(attachment)
|
|
490
|
+
},
|
|
491
|
+
attachment.id
|
|
492
|
+
)) }),
|
|
493
|
+
hasText && /* @__PURE__ */ jsx("p", { className: "break-words whitespace-pre-wrap", children: message.isDeleted ? /* @__PURE__ */ jsx("span", { className: "italic opacity-60", children: "This message was deleted" }) : message.content }),
|
|
494
|
+
message.isEdited && !message.isDeleted && /* @__PURE__ */ jsx("span", { className: "ml-1 text-xs opacity-60", children: "(edited)" })
|
|
495
|
+
]
|
|
496
|
+
}
|
|
497
|
+
),
|
|
498
|
+
/* @__PURE__ */ jsxs(
|
|
499
|
+
"div",
|
|
500
|
+
{
|
|
501
|
+
"data-slot": "message-footer",
|
|
502
|
+
className: cn(
|
|
503
|
+
"mt-1 flex items-center gap-2 px-1",
|
|
504
|
+
isOutgoing ? "flex-row-reverse" : "flex-row"
|
|
505
|
+
),
|
|
506
|
+
children: [
|
|
507
|
+
showTimestamp && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: formatTimestamp(message.timestamp) }),
|
|
508
|
+
showStatus && isOutgoing && /* @__PURE__ */ jsx(MessageStatusIcon, { status: message.status }),
|
|
509
|
+
showReadReceipts && isOutgoing && message.readReceipts && message.readReceipts.length > 0 && /* @__PURE__ */ jsx(ReadReceiptIndicator, { receipts: message.readReceipts }),
|
|
510
|
+
isFailed && onRetry && /* @__PURE__ */ jsxs(
|
|
511
|
+
"button",
|
|
512
|
+
{
|
|
513
|
+
type: "button",
|
|
514
|
+
onClick: onRetry,
|
|
515
|
+
className: cn(
|
|
516
|
+
"flex items-center gap-1 rounded px-2 py-0.5",
|
|
517
|
+
"text-xs font-medium text-red-700 dark:text-red-400",
|
|
518
|
+
"hover:bg-red-50 dark:hover:bg-red-900/20",
|
|
519
|
+
"focus:ring-2 focus:ring-red-500 focus:outline-none"
|
|
520
|
+
),
|
|
521
|
+
"aria-label": "Retry sending message",
|
|
522
|
+
children: [
|
|
523
|
+
/* @__PURE__ */ jsx(
|
|
524
|
+
"svg",
|
|
525
|
+
{
|
|
526
|
+
"aria-hidden": "true",
|
|
527
|
+
className: "h-3 w-3",
|
|
528
|
+
fill: "none",
|
|
529
|
+
viewBox: "0 0 24 24",
|
|
530
|
+
stroke: "currentColor",
|
|
531
|
+
children: /* @__PURE__ */ jsx(
|
|
532
|
+
"path",
|
|
533
|
+
{
|
|
534
|
+
strokeLinecap: "round",
|
|
535
|
+
strokeLinejoin: "round",
|
|
536
|
+
strokeWidth: 2,
|
|
537
|
+
d: "M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
|
|
538
|
+
}
|
|
539
|
+
)
|
|
540
|
+
}
|
|
541
|
+
),
|
|
542
|
+
"Retry"
|
|
543
|
+
]
|
|
544
|
+
}
|
|
545
|
+
)
|
|
546
|
+
]
|
|
547
|
+
}
|
|
548
|
+
),
|
|
549
|
+
message.reactions && message.reactions.length > 0 && /* @__PURE__ */ jsx(
|
|
550
|
+
"div",
|
|
551
|
+
{
|
|
552
|
+
"data-slot": "message-reactions",
|
|
553
|
+
className: cn(
|
|
554
|
+
"-mt-1 flex flex-wrap gap-1",
|
|
555
|
+
isOutgoing ? "justify-end" : "justify-start"
|
|
556
|
+
),
|
|
557
|
+
children: message.reactions.map((reaction) => /* @__PURE__ */ jsxs(
|
|
558
|
+
"span",
|
|
559
|
+
{
|
|
560
|
+
className: cn(
|
|
561
|
+
"inline-flex items-center gap-1 rounded-full px-2 py-0.5",
|
|
562
|
+
"bg-neutral-100 text-xs dark:bg-neutral-800",
|
|
563
|
+
"border border-neutral-200 dark:border-neutral-700"
|
|
564
|
+
),
|
|
565
|
+
title: reaction.participants.map((p) => p.name).join(", "),
|
|
566
|
+
children: [
|
|
567
|
+
/* @__PURE__ */ jsx("span", { children: reaction.emoji }),
|
|
568
|
+
reaction.count > 1 && /* @__PURE__ */ jsx("span", { className: "text-neutral-500", children: reaction.count })
|
|
569
|
+
]
|
|
570
|
+
},
|
|
571
|
+
reaction.emoji
|
|
572
|
+
))
|
|
573
|
+
}
|
|
574
|
+
)
|
|
575
|
+
]
|
|
576
|
+
}
|
|
577
|
+
),
|
|
578
|
+
showAvatar && isOutgoing && /* @__PURE__ */ jsx("div", { className: "w-8 shrink-0" })
|
|
579
|
+
]
|
|
580
|
+
}
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
);
|
|
584
|
+
MessageBubble.displayName = "MessageBubble";
|
|
585
|
+
function groupMessagesByDate(messages) {
|
|
586
|
+
const groups = /* @__PURE__ */ new Map();
|
|
587
|
+
messages.forEach((message) => {
|
|
588
|
+
const date = new Date(message.timestamp);
|
|
589
|
+
const dateKey = date.toDateString();
|
|
590
|
+
const existing = groups.get(dateKey) || [];
|
|
591
|
+
groups.set(dateKey, [...existing, message]);
|
|
592
|
+
});
|
|
593
|
+
return Array.from(groups.entries()).map(([dateKey, msgs]) => ({
|
|
594
|
+
date: dateKey,
|
|
595
|
+
label: formatDateLabel(new Date(dateKey)),
|
|
596
|
+
messages: msgs
|
|
597
|
+
}));
|
|
598
|
+
}
|
|
599
|
+
function formatDateLabel(date) {
|
|
600
|
+
const now = /* @__PURE__ */ new Date();
|
|
601
|
+
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
602
|
+
const yesterday = new Date(today);
|
|
603
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
604
|
+
const messageDate = new Date(
|
|
605
|
+
date.getFullYear(),
|
|
606
|
+
date.getMonth(),
|
|
607
|
+
date.getDate()
|
|
608
|
+
);
|
|
609
|
+
if (messageDate.getTime() === today.getTime()) {
|
|
610
|
+
return "Today";
|
|
611
|
+
}
|
|
612
|
+
if (messageDate.getTime() === yesterday.getTime()) {
|
|
613
|
+
return "Yesterday";
|
|
614
|
+
}
|
|
615
|
+
if (date.getFullYear() === now.getFullYear()) {
|
|
616
|
+
return date.toLocaleDateString(void 0, {
|
|
617
|
+
weekday: "long",
|
|
618
|
+
month: "long",
|
|
619
|
+
day: "numeric"
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
return date.toLocaleDateString(void 0, {
|
|
623
|
+
weekday: "long",
|
|
624
|
+
month: "long",
|
|
625
|
+
day: "numeric",
|
|
626
|
+
year: "numeric"
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
function isSameSenderGroup(prev, current, thresholdMinutes = 5) {
|
|
630
|
+
if (!prev) return false;
|
|
631
|
+
if (prev.sender.id !== current.sender.id) return false;
|
|
632
|
+
if (prev.type === "system" || current.type === "system") return false;
|
|
633
|
+
const prevTime = new Date(prev.timestamp).getTime();
|
|
634
|
+
const currentTime = new Date(current.timestamp).getTime();
|
|
635
|
+
const diffMinutes = (currentTime - prevTime) / (1e3 * 60);
|
|
636
|
+
return diffMinutes < thresholdMinutes;
|
|
637
|
+
}
|
|
638
|
+
function SkeletonMessage({
|
|
639
|
+
isOutgoing = false,
|
|
640
|
+
showAvatar = true,
|
|
641
|
+
className
|
|
642
|
+
}) {
|
|
643
|
+
return /* @__PURE__ */ jsxs(
|
|
644
|
+
"div",
|
|
645
|
+
{
|
|
646
|
+
"data-slot": "skeleton-message",
|
|
647
|
+
className: cn(
|
|
648
|
+
"flex items-end gap-2",
|
|
649
|
+
isOutgoing ? "flex-row-reverse" : "flex-row",
|
|
650
|
+
className
|
|
651
|
+
),
|
|
652
|
+
"aria-hidden": "true",
|
|
653
|
+
children: [
|
|
654
|
+
showAvatar && !isOutgoing && /* @__PURE__ */ jsx(
|
|
655
|
+
"div",
|
|
656
|
+
{
|
|
657
|
+
"data-slot": "skeleton-avatar",
|
|
658
|
+
className: "h-8 w-8 animate-pulse rounded-full bg-neutral-200 dark:bg-neutral-700"
|
|
659
|
+
}
|
|
660
|
+
),
|
|
661
|
+
/* @__PURE__ */ jsx(
|
|
662
|
+
"div",
|
|
663
|
+
{
|
|
664
|
+
"data-slot": "skeleton-bubble",
|
|
665
|
+
className: cn(
|
|
666
|
+
"animate-pulse rounded-2xl",
|
|
667
|
+
isOutgoing ? "bg-primary-800/30 rounded-br-md" : "rounded-bl-md bg-neutral-200 dark:bg-neutral-700",
|
|
668
|
+
"h-10 w-48"
|
|
669
|
+
)
|
|
670
|
+
}
|
|
671
|
+
),
|
|
672
|
+
showAvatar && isOutgoing && /* @__PURE__ */ jsx("div", { "data-slot": "skeleton-spacer", className: "w-8" })
|
|
673
|
+
]
|
|
674
|
+
}
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
SkeletonMessage.displayName = "SkeletonMessage";
|
|
678
|
+
function TypingIndicator({ typingState, className }) {
|
|
679
|
+
const { participants } = typingState;
|
|
680
|
+
if (participants.length === 0) return null;
|
|
681
|
+
const typingText = participants.length === 1 ? `${participants[0].name} is typing` : participants.length === 2 ? `${participants[0].name} and ${participants[1].name} are typing` : `${participants[0].name} and ${participants.length - 1} others are typing`;
|
|
682
|
+
return /* @__PURE__ */ jsxs(
|
|
683
|
+
"div",
|
|
684
|
+
{
|
|
685
|
+
"data-slot": "typing-indicator",
|
|
686
|
+
className: cn("flex items-center gap-2 px-4 py-2", className),
|
|
687
|
+
role: "status",
|
|
688
|
+
"aria-live": "polite",
|
|
689
|
+
"aria-label": typingText,
|
|
690
|
+
children: [
|
|
691
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 rounded-2xl rounded-bl-md bg-neutral-200 px-4 py-3 dark:bg-neutral-700", children: [
|
|
692
|
+
/* @__PURE__ */ jsx(
|
|
693
|
+
"span",
|
|
694
|
+
{
|
|
695
|
+
className: "h-2 w-2 animate-bounce rounded-full bg-neutral-500",
|
|
696
|
+
style: { animationDelay: "0ms" }
|
|
697
|
+
}
|
|
698
|
+
),
|
|
699
|
+
/* @__PURE__ */ jsx(
|
|
700
|
+
"span",
|
|
701
|
+
{
|
|
702
|
+
className: "h-2 w-2 animate-bounce rounded-full bg-neutral-500",
|
|
703
|
+
style: { animationDelay: "150ms" }
|
|
704
|
+
}
|
|
705
|
+
),
|
|
706
|
+
/* @__PURE__ */ jsx(
|
|
707
|
+
"span",
|
|
708
|
+
{
|
|
709
|
+
className: "h-2 w-2 animate-bounce rounded-full bg-neutral-500",
|
|
710
|
+
style: { animationDelay: "300ms" }
|
|
711
|
+
}
|
|
712
|
+
)
|
|
713
|
+
] }),
|
|
714
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: typingText })
|
|
715
|
+
]
|
|
716
|
+
}
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
TypingIndicator.displayName = "TypingIndicator";
|
|
720
|
+
function DateSeparator({ label, className }) {
|
|
721
|
+
return /* @__PURE__ */ jsx(
|
|
722
|
+
"div",
|
|
723
|
+
{
|
|
724
|
+
"data-slot": "date-separator",
|
|
725
|
+
className: cn("flex items-center justify-center py-4", className),
|
|
726
|
+
role: "separator",
|
|
727
|
+
"aria-label": label,
|
|
728
|
+
children: /* @__PURE__ */ jsx(
|
|
729
|
+
"span",
|
|
730
|
+
{
|
|
731
|
+
className: cn(
|
|
732
|
+
"rounded-full px-3 py-1 text-xs font-medium",
|
|
733
|
+
"bg-neutral-100 text-neutral-500",
|
|
734
|
+
"dark:bg-neutral-800 dark:text-neutral-400"
|
|
735
|
+
),
|
|
736
|
+
children: label
|
|
737
|
+
}
|
|
738
|
+
)
|
|
739
|
+
}
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
DateSeparator.displayName = "DateSeparator";
|
|
743
|
+
function EmptyState({
|
|
744
|
+
title = "No messages yet",
|
|
745
|
+
description = "Start the conversation by sending a message below.",
|
|
746
|
+
icon,
|
|
747
|
+
action,
|
|
748
|
+
className
|
|
749
|
+
}) {
|
|
750
|
+
return /* @__PURE__ */ jsxs(
|
|
751
|
+
"div",
|
|
752
|
+
{
|
|
753
|
+
"data-slot": "message-empty-state",
|
|
754
|
+
className: cn(
|
|
755
|
+
"flex flex-1 flex-col items-center justify-center p-8 text-center",
|
|
756
|
+
className
|
|
757
|
+
),
|
|
758
|
+
role: "status",
|
|
759
|
+
"aria-label": title,
|
|
760
|
+
children: [
|
|
761
|
+
icon || /* @__PURE__ */ jsx(
|
|
762
|
+
"div",
|
|
763
|
+
{
|
|
764
|
+
"data-slot": "message-empty-state-icon",
|
|
765
|
+
className: "mb-4 rounded-full bg-neutral-100 p-4 dark:bg-neutral-800",
|
|
766
|
+
children: /* @__PURE__ */ jsx(
|
|
767
|
+
"svg",
|
|
768
|
+
{
|
|
769
|
+
"aria-hidden": "true",
|
|
770
|
+
className: "h-12 w-12 text-neutral-500",
|
|
771
|
+
fill: "none",
|
|
772
|
+
viewBox: "0 0 24 24",
|
|
773
|
+
stroke: "currentColor",
|
|
774
|
+
children: /* @__PURE__ */ jsx(
|
|
775
|
+
"path",
|
|
776
|
+
{
|
|
777
|
+
strokeLinecap: "round",
|
|
778
|
+
strokeLinejoin: "round",
|
|
779
|
+
strokeWidth: 1.5,
|
|
780
|
+
d: "M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"
|
|
781
|
+
}
|
|
782
|
+
)
|
|
783
|
+
}
|
|
784
|
+
)
|
|
785
|
+
}
|
|
786
|
+
),
|
|
787
|
+
/* @__PURE__ */ jsx("h3", { className: "mb-2 text-lg font-semibold text-neutral-900 dark:text-neutral-100", children: title }),
|
|
788
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground mb-4 max-w-sm text-sm", children: description }),
|
|
789
|
+
action
|
|
790
|
+
]
|
|
791
|
+
}
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
EmptyState.displayName = "EmptyState";
|
|
795
|
+
function LoadMoreButton({
|
|
796
|
+
isLoading,
|
|
797
|
+
onClick,
|
|
798
|
+
className
|
|
799
|
+
}) {
|
|
800
|
+
return /* @__PURE__ */ jsx(
|
|
801
|
+
"div",
|
|
802
|
+
{
|
|
803
|
+
"data-slot": "load-more-button",
|
|
804
|
+
className: cn("flex justify-center py-4", className),
|
|
805
|
+
children: /* @__PURE__ */ jsx(
|
|
806
|
+
"button",
|
|
807
|
+
{
|
|
808
|
+
type: "button",
|
|
809
|
+
onClick,
|
|
810
|
+
disabled: isLoading,
|
|
811
|
+
className: cn(
|
|
812
|
+
"rounded-full px-4 py-2 text-sm font-medium",
|
|
813
|
+
"bg-neutral-100 text-neutral-600 dark:bg-neutral-800 dark:text-neutral-300",
|
|
814
|
+
"hover:bg-neutral-200 dark:hover:bg-neutral-700",
|
|
815
|
+
"focus:ring-primary-500 focus:ring-2 focus:outline-none",
|
|
816
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
817
|
+
"transition-colors"
|
|
818
|
+
),
|
|
819
|
+
"aria-label": isLoading ? "Loading more messages" : "Load more messages",
|
|
820
|
+
children: isLoading ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
821
|
+
/* @__PURE__ */ jsxs(
|
|
822
|
+
"svg",
|
|
823
|
+
{
|
|
824
|
+
"aria-hidden": "true",
|
|
825
|
+
className: "h-4 w-4 animate-spin",
|
|
826
|
+
fill: "none",
|
|
827
|
+
viewBox: "0 0 24 24",
|
|
828
|
+
children: [
|
|
829
|
+
/* @__PURE__ */ jsx(
|
|
830
|
+
"circle",
|
|
831
|
+
{
|
|
832
|
+
className: "opacity-25",
|
|
833
|
+
cx: "12",
|
|
834
|
+
cy: "12",
|
|
835
|
+
r: "10",
|
|
836
|
+
stroke: "currentColor",
|
|
837
|
+
strokeWidth: "4"
|
|
838
|
+
}
|
|
839
|
+
),
|
|
840
|
+
/* @__PURE__ */ jsx(
|
|
841
|
+
"path",
|
|
842
|
+
{
|
|
843
|
+
className: "opacity-75",
|
|
844
|
+
fill: "currentColor",
|
|
845
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
|
846
|
+
}
|
|
847
|
+
)
|
|
848
|
+
]
|
|
849
|
+
}
|
|
850
|
+
),
|
|
851
|
+
"Loading..."
|
|
852
|
+
] }) : "Load earlier messages"
|
|
853
|
+
}
|
|
854
|
+
)
|
|
855
|
+
}
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
LoadMoreButton.displayName = "LoadMoreButton";
|
|
859
|
+
var MessageList = React5.forwardRef(
|
|
860
|
+
({
|
|
861
|
+
messages,
|
|
862
|
+
currentUser,
|
|
863
|
+
isLoading = false,
|
|
864
|
+
hasMore = false,
|
|
865
|
+
isLoadingMore = false,
|
|
866
|
+
typingState,
|
|
867
|
+
showAvatars = true,
|
|
868
|
+
showSenderNames = false,
|
|
869
|
+
groupByDate = true,
|
|
870
|
+
onLoadMore,
|
|
871
|
+
onRetryMessage,
|
|
872
|
+
onAttachmentClick,
|
|
873
|
+
emptyState,
|
|
874
|
+
formatTimestamp,
|
|
875
|
+
className,
|
|
876
|
+
autoScroll = "onNewMessage"
|
|
877
|
+
}, ref) => {
|
|
878
|
+
const scrollContainerRef = React5.useRef(null);
|
|
879
|
+
const bottomRef = React5.useRef(null);
|
|
880
|
+
const [isUserScrolled, setIsUserScrolled] = React5.useState(false);
|
|
881
|
+
const prevMessageCountRef = React5.useRef(messages.length);
|
|
882
|
+
React5.useImperativeHandle(ref, () => scrollContainerRef.current);
|
|
883
|
+
const handleScroll = React5.useCallback(() => {
|
|
884
|
+
const container = scrollContainerRef.current;
|
|
885
|
+
if (!container) return;
|
|
886
|
+
const { scrollTop, scrollHeight, clientHeight } = container;
|
|
887
|
+
const isAtBottom = scrollHeight - scrollTop - clientHeight < 100;
|
|
888
|
+
setIsUserScrolled(!isAtBottom);
|
|
889
|
+
}, []);
|
|
890
|
+
React5.useEffect(() => {
|
|
891
|
+
const container = scrollContainerRef.current;
|
|
892
|
+
const bottom = bottomRef.current;
|
|
893
|
+
if (!container || !bottom) return;
|
|
894
|
+
const messageCountChanged = messages.length !== prevMessageCountRef.current;
|
|
895
|
+
prevMessageCountRef.current = messages.length;
|
|
896
|
+
if (autoScroll === "always") {
|
|
897
|
+
bottom.scrollIntoView({ behavior: "smooth" });
|
|
898
|
+
} else if (autoScroll === "onNewMessage" && messageCountChanged) {
|
|
899
|
+
const lastMessage = messages[messages.length - 1];
|
|
900
|
+
const isOutgoing = lastMessage?.sender.id === currentUser.id;
|
|
901
|
+
if (isOutgoing || !isUserScrolled) {
|
|
902
|
+
bottom.scrollIntoView({ behavior: "smooth" });
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}, [messages, currentUser.id, autoScroll, isUserScrolled]);
|
|
906
|
+
React5.useEffect(() => {
|
|
907
|
+
const bottom = bottomRef.current;
|
|
908
|
+
if (bottom && !isLoading) {
|
|
909
|
+
bottom.scrollIntoView();
|
|
910
|
+
}
|
|
911
|
+
}, [isLoading]);
|
|
912
|
+
const messageGroups = groupByDate ? groupMessagesByDate(messages) : [{ date: "all", label: "", messages }];
|
|
913
|
+
if (isLoading) {
|
|
914
|
+
return /* @__PURE__ */ jsx(
|
|
915
|
+
"div",
|
|
916
|
+
{
|
|
917
|
+
role: "status",
|
|
918
|
+
className: cn(
|
|
919
|
+
"flex flex-1 flex-col gap-3 overflow-y-auto p-4",
|
|
920
|
+
className
|
|
921
|
+
),
|
|
922
|
+
"aria-busy": "true",
|
|
923
|
+
"aria-label": "Loading messages",
|
|
924
|
+
children: Array.from({ length: 8 }).map((_, i) => /* @__PURE__ */ jsx(
|
|
925
|
+
SkeletonMessage,
|
|
926
|
+
{
|
|
927
|
+
isOutgoing: i % 3 === 0,
|
|
928
|
+
showAvatar: showAvatars
|
|
929
|
+
},
|
|
930
|
+
i
|
|
931
|
+
))
|
|
932
|
+
}
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
if (messages.length === 0) {
|
|
936
|
+
return emptyState || /* @__PURE__ */ jsx(EmptyState, {});
|
|
937
|
+
}
|
|
938
|
+
return /* @__PURE__ */ jsxs(
|
|
939
|
+
"div",
|
|
940
|
+
{
|
|
941
|
+
ref: scrollContainerRef,
|
|
942
|
+
"data-slot": "message-list",
|
|
943
|
+
className: cn(
|
|
944
|
+
"flex flex-1 flex-col overflow-y-auto",
|
|
945
|
+
"scroll-smooth",
|
|
946
|
+
className
|
|
947
|
+
),
|
|
948
|
+
onScroll: handleScroll,
|
|
949
|
+
role: "log",
|
|
950
|
+
"aria-label": "Message history",
|
|
951
|
+
"aria-live": "polite",
|
|
952
|
+
children: [
|
|
953
|
+
hasMore && onLoadMore && /* @__PURE__ */ jsx(LoadMoreButton, { isLoading: isLoadingMore, onClick: onLoadMore }),
|
|
954
|
+
/* @__PURE__ */ jsx(
|
|
955
|
+
"div",
|
|
956
|
+
{
|
|
957
|
+
"data-slot": "message-list-content",
|
|
958
|
+
className: "flex flex-col gap-1 p-4",
|
|
959
|
+
children: messageGroups.map((group) => /* @__PURE__ */ jsxs(React5.Fragment, { children: [
|
|
960
|
+
groupByDate && group.label && /* @__PURE__ */ jsx(DateSeparator, { label: group.label }),
|
|
961
|
+
group.messages.map((message, index) => {
|
|
962
|
+
const prevMessage = group.messages[index - 1];
|
|
963
|
+
const isOutgoing = message.sender.id === currentUser.id;
|
|
964
|
+
const isSameGroup = isSameSenderGroup(prevMessage, message);
|
|
965
|
+
return /* @__PURE__ */ jsx(
|
|
966
|
+
"div",
|
|
967
|
+
{
|
|
968
|
+
className: cn(
|
|
969
|
+
"transition-opacity duration-200",
|
|
970
|
+
isSameGroup ? "mt-0.5" : "mt-3",
|
|
971
|
+
index === 0 && "mt-0"
|
|
972
|
+
),
|
|
973
|
+
children: /* @__PURE__ */ jsx(
|
|
974
|
+
MessageBubble,
|
|
975
|
+
{
|
|
976
|
+
message,
|
|
977
|
+
isOutgoing,
|
|
978
|
+
showAvatar: showAvatars && !isSameGroup && !isOutgoing,
|
|
979
|
+
showSenderName: showSenderNames && !isSameGroup && !isOutgoing,
|
|
980
|
+
showTimestamp: !isSameGroup,
|
|
981
|
+
onRetry: message.status === "failed" && onRetryMessage ? () => onRetryMessage(message.id) : void 0,
|
|
982
|
+
onAttachmentClick: (attachment) => onAttachmentClick?.(attachment, message),
|
|
983
|
+
formatTimestamp
|
|
984
|
+
}
|
|
985
|
+
)
|
|
986
|
+
},
|
|
987
|
+
message.id
|
|
988
|
+
);
|
|
989
|
+
})
|
|
990
|
+
] }, group.date))
|
|
991
|
+
}
|
|
992
|
+
),
|
|
993
|
+
typingState && typingState.participants.length > 0 && /* @__PURE__ */ jsx(TypingIndicator, { typingState }),
|
|
994
|
+
/* @__PURE__ */ jsx("div", { ref: bottomRef, className: "h-0", "aria-hidden": "true" }),
|
|
995
|
+
isUserScrolled && /* @__PURE__ */ jsx(
|
|
996
|
+
"button",
|
|
997
|
+
{
|
|
998
|
+
type: "button",
|
|
999
|
+
onClick: () => {
|
|
1000
|
+
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
1001
|
+
},
|
|
1002
|
+
className: cn(
|
|
1003
|
+
"fixed right-4 bottom-24 z-10",
|
|
1004
|
+
"rounded-full p-3 shadow-lg",
|
|
1005
|
+
"bg-white dark:bg-neutral-800",
|
|
1006
|
+
"border border-neutral-200 dark:border-neutral-700",
|
|
1007
|
+
"hover:bg-neutral-50 dark:hover:bg-neutral-700",
|
|
1008
|
+
"focus:ring-primary-500 focus:ring-2 focus:outline-none",
|
|
1009
|
+
"transition-all"
|
|
1010
|
+
),
|
|
1011
|
+
"aria-label": "Scroll to bottom",
|
|
1012
|
+
children: /* @__PURE__ */ jsx(
|
|
1013
|
+
"svg",
|
|
1014
|
+
{
|
|
1015
|
+
"aria-hidden": "true",
|
|
1016
|
+
className: "h-5 w-5 text-neutral-600 dark:text-neutral-300",
|
|
1017
|
+
fill: "none",
|
|
1018
|
+
viewBox: "0 0 24 24",
|
|
1019
|
+
stroke: "currentColor",
|
|
1020
|
+
children: /* @__PURE__ */ jsx(
|
|
1021
|
+
"path",
|
|
1022
|
+
{
|
|
1023
|
+
strokeLinecap: "round",
|
|
1024
|
+
strokeLinejoin: "round",
|
|
1025
|
+
strokeWidth: 2,
|
|
1026
|
+
d: "M19 14l-7 7m0 0l-7-7m7 7V3"
|
|
1027
|
+
}
|
|
1028
|
+
)
|
|
1029
|
+
}
|
|
1030
|
+
)
|
|
1031
|
+
}
|
|
1032
|
+
)
|
|
1033
|
+
]
|
|
1034
|
+
}
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
);
|
|
1038
|
+
MessageList.displayName = "MessageList";
|
|
1039
|
+
var headerVariants = cva(
|
|
1040
|
+
[
|
|
1041
|
+
"flex items-center gap-3 px-4 py-3",
|
|
1042
|
+
"bg-white dark:bg-neutral-900",
|
|
1043
|
+
"border-b border-neutral-200 dark:border-neutral-700"
|
|
1044
|
+
],
|
|
1045
|
+
{
|
|
1046
|
+
variants: {
|
|
1047
|
+
size: {
|
|
1048
|
+
sm: "py-2",
|
|
1049
|
+
md: "py-3",
|
|
1050
|
+
lg: "py-4"
|
|
1051
|
+
}
|
|
1052
|
+
},
|
|
1053
|
+
defaultVariants: {
|
|
1054
|
+
size: "md"
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
);
|
|
1058
|
+
function getConversationTitle(conversation, participant) {
|
|
1059
|
+
if (conversation?.name) return conversation.name;
|
|
1060
|
+
if (participant?.name) return participant.name;
|
|
1061
|
+
if (conversation?.participants && conversation.participants.length > 0) {
|
|
1062
|
+
const names = conversation.participants.filter((p) => !p.isCurrentUser).map((p) => p.name);
|
|
1063
|
+
if (names.length <= 2) return names.join(" & ");
|
|
1064
|
+
return `${names[0]} and ${names.length - 1} others`;
|
|
1065
|
+
}
|
|
1066
|
+
return "Conversation";
|
|
1067
|
+
}
|
|
1068
|
+
function getConversationSubtitle(conversation, participant, showOnlineStatus) {
|
|
1069
|
+
if (participant) {
|
|
1070
|
+
if (showOnlineStatus && participant.isOnline) {
|
|
1071
|
+
return "Online";
|
|
1072
|
+
}
|
|
1073
|
+
if (participant.lastSeen) {
|
|
1074
|
+
const lastSeen = new Date(participant.lastSeen);
|
|
1075
|
+
return `Last seen ${formatLastSeen(lastSeen)}`;
|
|
1076
|
+
}
|
|
1077
|
+
if (participant.phoneNumber) {
|
|
1078
|
+
return participant.phoneNumber;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
if (conversation?.type === "group" && conversation.participants) {
|
|
1082
|
+
return `${conversation.participants.length} participants`;
|
|
1083
|
+
}
|
|
1084
|
+
return void 0;
|
|
1085
|
+
}
|
|
1086
|
+
function formatLastSeen(date) {
|
|
1087
|
+
const now = /* @__PURE__ */ new Date();
|
|
1088
|
+
const diffMs = now.getTime() - date.getTime();
|
|
1089
|
+
const diffMins = Math.floor(diffMs / (1e3 * 60));
|
|
1090
|
+
const diffHours = Math.floor(diffMs / (1e3 * 60 * 60));
|
|
1091
|
+
const diffDays = Math.floor(diffMs / (1e3 * 60 * 60 * 24));
|
|
1092
|
+
if (diffMins < 1) return "just now";
|
|
1093
|
+
if (diffMins < 60) return `${diffMins}m ago`;
|
|
1094
|
+
if (diffHours < 24) return `${diffHours}h ago`;
|
|
1095
|
+
if (diffDays < 7) return `${diffDays}d ago`;
|
|
1096
|
+
return date.toLocaleDateString();
|
|
1097
|
+
}
|
|
1098
|
+
var ConversationHeader = React5.forwardRef(
|
|
1099
|
+
({
|
|
1100
|
+
className,
|
|
1101
|
+
size,
|
|
1102
|
+
conversation,
|
|
1103
|
+
title,
|
|
1104
|
+
subtitle,
|
|
1105
|
+
avatarUrl,
|
|
1106
|
+
participant,
|
|
1107
|
+
showOnlineStatus = true,
|
|
1108
|
+
showBackButton = false,
|
|
1109
|
+
onBack,
|
|
1110
|
+
actions,
|
|
1111
|
+
leftContent,
|
|
1112
|
+
rightContent,
|
|
1113
|
+
...props
|
|
1114
|
+
}, ref) => {
|
|
1115
|
+
const displayTitle = title || getConversationTitle(conversation, participant);
|
|
1116
|
+
const displaySubtitle = subtitle || getConversationSubtitle(conversation, participant, showOnlineStatus);
|
|
1117
|
+
const displayAvatar = avatarUrl || conversation?.avatarUrl || participant?.avatarUrl;
|
|
1118
|
+
const isOnline = participant?.isOnline;
|
|
1119
|
+
return /* @__PURE__ */ jsxs(
|
|
1120
|
+
"header",
|
|
1121
|
+
{
|
|
1122
|
+
ref,
|
|
1123
|
+
"data-slot": "conversation-header",
|
|
1124
|
+
className: cn(headerVariants({ size }), className),
|
|
1125
|
+
...props,
|
|
1126
|
+
children: [
|
|
1127
|
+
leftContent || showBackButton && onBack && /* @__PURE__ */ jsx(
|
|
1128
|
+
"button",
|
|
1129
|
+
{
|
|
1130
|
+
type: "button",
|
|
1131
|
+
onClick: onBack,
|
|
1132
|
+
className: cn(
|
|
1133
|
+
"-ml-2 rounded-full p-2",
|
|
1134
|
+
"text-neutral-500 hover:text-neutral-700",
|
|
1135
|
+
"dark:text-neutral-400 dark:hover:text-neutral-200",
|
|
1136
|
+
"hover:bg-neutral-100 dark:hover:bg-neutral-800",
|
|
1137
|
+
"focus:ring-primary-500 focus:ring-2 focus:outline-none",
|
|
1138
|
+
"transition-colors"
|
|
1139
|
+
),
|
|
1140
|
+
"aria-label": "Go back",
|
|
1141
|
+
children: /* @__PURE__ */ jsx(
|
|
1142
|
+
"svg",
|
|
1143
|
+
{
|
|
1144
|
+
"aria-hidden": "true",
|
|
1145
|
+
className: "h-5 w-5",
|
|
1146
|
+
fill: "none",
|
|
1147
|
+
viewBox: "0 0 24 24",
|
|
1148
|
+
stroke: "currentColor",
|
|
1149
|
+
children: /* @__PURE__ */ jsx(
|
|
1150
|
+
"path",
|
|
1151
|
+
{
|
|
1152
|
+
strokeLinecap: "round",
|
|
1153
|
+
strokeLinejoin: "round",
|
|
1154
|
+
strokeWidth: 2,
|
|
1155
|
+
d: "M15 19l-7-7 7-7"
|
|
1156
|
+
}
|
|
1157
|
+
)
|
|
1158
|
+
}
|
|
1159
|
+
)
|
|
1160
|
+
}
|
|
1161
|
+
),
|
|
1162
|
+
/* @__PURE__ */ jsxs(
|
|
1163
|
+
"div",
|
|
1164
|
+
{
|
|
1165
|
+
"data-slot": "conversation-header-avatar",
|
|
1166
|
+
className: "relative shrink-0",
|
|
1167
|
+
children: [
|
|
1168
|
+
/* @__PURE__ */ jsx(
|
|
1169
|
+
"div",
|
|
1170
|
+
{
|
|
1171
|
+
className: cn(
|
|
1172
|
+
"flex h-10 w-10 items-center justify-center rounded-full",
|
|
1173
|
+
"bg-primary-800 font-medium text-white"
|
|
1174
|
+
),
|
|
1175
|
+
children: displayAvatar ? /* @__PURE__ */ jsx(
|
|
1176
|
+
"img",
|
|
1177
|
+
{
|
|
1178
|
+
src: displayAvatar,
|
|
1179
|
+
alt: displayTitle,
|
|
1180
|
+
className: "h-full w-full rounded-full object-cover"
|
|
1181
|
+
}
|
|
1182
|
+
) : displayTitle.charAt(0).toUpperCase()
|
|
1183
|
+
}
|
|
1184
|
+
),
|
|
1185
|
+
showOnlineStatus && isOnline && /* @__PURE__ */ jsx(
|
|
1186
|
+
"span",
|
|
1187
|
+
{
|
|
1188
|
+
className: cn(
|
|
1189
|
+
"absolute right-0 bottom-0",
|
|
1190
|
+
"h-3 w-3 rounded-full",
|
|
1191
|
+
"bg-green-500 ring-2 ring-white dark:ring-neutral-900"
|
|
1192
|
+
),
|
|
1193
|
+
role: "status",
|
|
1194
|
+
"aria-label": "Online"
|
|
1195
|
+
}
|
|
1196
|
+
)
|
|
1197
|
+
]
|
|
1198
|
+
}
|
|
1199
|
+
),
|
|
1200
|
+
/* @__PURE__ */ jsxs("div", { "data-slot": "conversation-header-info", className: "min-w-0 flex-1", children: [
|
|
1201
|
+
/* @__PURE__ */ jsx("h2", { className: "truncate font-semibold text-neutral-900 dark:text-neutral-100", children: displayTitle }),
|
|
1202
|
+
displaySubtitle && /* @__PURE__ */ jsx(
|
|
1203
|
+
"p",
|
|
1204
|
+
{
|
|
1205
|
+
className: cn(
|
|
1206
|
+
"truncate text-sm",
|
|
1207
|
+
isOnline ? "text-green-700 dark:text-green-400" : "text-muted-foreground"
|
|
1208
|
+
),
|
|
1209
|
+
children: displaySubtitle
|
|
1210
|
+
}
|
|
1211
|
+
)
|
|
1212
|
+
] }),
|
|
1213
|
+
rightContent || actions && /* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-center gap-1", children: actions })
|
|
1214
|
+
]
|
|
1215
|
+
}
|
|
1216
|
+
);
|
|
1217
|
+
}
|
|
1218
|
+
);
|
|
1219
|
+
ConversationHeader.displayName = "ConversationHeader";
|
|
1220
|
+
var ConversationListItem = React5.forwardRef(({ className, conversation, isSelected, onSelect, ...props }, ref) => {
|
|
1221
|
+
const participant = conversation.participants.find((p) => !p.isCurrentUser);
|
|
1222
|
+
const title = getConversationTitle(conversation, participant);
|
|
1223
|
+
const avatarUrl = conversation.avatarUrl || participant?.avatarUrl;
|
|
1224
|
+
const lastMessage = conversation.lastMessage;
|
|
1225
|
+
const isUnread = conversation.unreadCount > 0;
|
|
1226
|
+
const formatTime = (timestamp) => {
|
|
1227
|
+
const date = new Date(timestamp);
|
|
1228
|
+
const now = /* @__PURE__ */ new Date();
|
|
1229
|
+
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
1230
|
+
const messageDate = new Date(
|
|
1231
|
+
date.getFullYear(),
|
|
1232
|
+
date.getMonth(),
|
|
1233
|
+
date.getDate()
|
|
1234
|
+
);
|
|
1235
|
+
if (messageDate.getTime() === today.getTime()) {
|
|
1236
|
+
return date.toLocaleTimeString(void 0, {
|
|
1237
|
+
hour: "numeric",
|
|
1238
|
+
minute: "2-digit"
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
const yesterday = new Date(today);
|
|
1242
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
1243
|
+
if (messageDate.getTime() === yesterday.getTime()) {
|
|
1244
|
+
return "Yesterday";
|
|
1245
|
+
}
|
|
1246
|
+
return date.toLocaleDateString(void 0, {
|
|
1247
|
+
month: "short",
|
|
1248
|
+
day: "numeric"
|
|
1249
|
+
});
|
|
1250
|
+
};
|
|
1251
|
+
return /* @__PURE__ */ jsxs(
|
|
1252
|
+
"button",
|
|
1253
|
+
{
|
|
1254
|
+
ref,
|
|
1255
|
+
type: "button",
|
|
1256
|
+
onClick: () => onSelect?.(conversation),
|
|
1257
|
+
"data-slot": "conversation-list-item",
|
|
1258
|
+
className: cn(
|
|
1259
|
+
"flex w-full items-center gap-3 px-4 py-3",
|
|
1260
|
+
"text-left transition-colors",
|
|
1261
|
+
isSelected ? "bg-primary-50 dark:bg-primary-900/20" : "hover:bg-neutral-50 dark:hover:bg-neutral-800/50",
|
|
1262
|
+
"focus:bg-neutral-50 focus:outline-none dark:focus:bg-neutral-800/50",
|
|
1263
|
+
className
|
|
1264
|
+
),
|
|
1265
|
+
"aria-current": isSelected ? "true" : void 0,
|
|
1266
|
+
...props,
|
|
1267
|
+
children: [
|
|
1268
|
+
/* @__PURE__ */ jsxs(
|
|
1269
|
+
"div",
|
|
1270
|
+
{
|
|
1271
|
+
"data-slot": "conversation-list-item-avatar",
|
|
1272
|
+
className: "relative shrink-0",
|
|
1273
|
+
children: [
|
|
1274
|
+
/* @__PURE__ */ jsx(
|
|
1275
|
+
"div",
|
|
1276
|
+
{
|
|
1277
|
+
className: cn(
|
|
1278
|
+
"flex h-12 w-12 items-center justify-center rounded-full",
|
|
1279
|
+
"bg-primary-800 font-medium text-white"
|
|
1280
|
+
),
|
|
1281
|
+
children: avatarUrl ? /* @__PURE__ */ jsx(
|
|
1282
|
+
"img",
|
|
1283
|
+
{
|
|
1284
|
+
src: avatarUrl,
|
|
1285
|
+
alt: title,
|
|
1286
|
+
className: "h-full w-full rounded-full object-cover"
|
|
1287
|
+
}
|
|
1288
|
+
) : title.charAt(0).toUpperCase()
|
|
1289
|
+
}
|
|
1290
|
+
),
|
|
1291
|
+
participant?.isOnline && /* @__PURE__ */ jsx(
|
|
1292
|
+
"span",
|
|
1293
|
+
{
|
|
1294
|
+
className: cn(
|
|
1295
|
+
"absolute right-0 bottom-0",
|
|
1296
|
+
"h-3 w-3 rounded-full",
|
|
1297
|
+
"bg-green-500 ring-2 ring-white dark:ring-neutral-900"
|
|
1298
|
+
)
|
|
1299
|
+
}
|
|
1300
|
+
)
|
|
1301
|
+
]
|
|
1302
|
+
}
|
|
1303
|
+
),
|
|
1304
|
+
/* @__PURE__ */ jsxs(
|
|
1305
|
+
"div",
|
|
1306
|
+
{
|
|
1307
|
+
"data-slot": "conversation-list-item-content",
|
|
1308
|
+
className: "min-w-0 flex-1",
|
|
1309
|
+
children: [
|
|
1310
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
1311
|
+
/* @__PURE__ */ jsx(
|
|
1312
|
+
"h3",
|
|
1313
|
+
{
|
|
1314
|
+
className: cn(
|
|
1315
|
+
"truncate text-sm",
|
|
1316
|
+
isUnread ? "font-semibold text-neutral-900 dark:text-neutral-100" : "font-medium text-neutral-700 dark:text-neutral-300"
|
|
1317
|
+
),
|
|
1318
|
+
children: title
|
|
1319
|
+
}
|
|
1320
|
+
),
|
|
1321
|
+
lastMessage && /* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs text-neutral-600 dark:text-neutral-400", children: formatTime(lastMessage.timestamp) })
|
|
1322
|
+
] }),
|
|
1323
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
1324
|
+
/* @__PURE__ */ jsx(
|
|
1325
|
+
"p",
|
|
1326
|
+
{
|
|
1327
|
+
className: cn(
|
|
1328
|
+
"truncate text-sm",
|
|
1329
|
+
isUnread ? "text-neutral-700 dark:text-neutral-300" : "text-neutral-600 dark:text-neutral-400"
|
|
1330
|
+
),
|
|
1331
|
+
children: lastMessage?.content || "No messages yet"
|
|
1332
|
+
}
|
|
1333
|
+
),
|
|
1334
|
+
isUnread && /* @__PURE__ */ jsx(
|
|
1335
|
+
"span",
|
|
1336
|
+
{
|
|
1337
|
+
"data-slot": "conversation-list-item-badge",
|
|
1338
|
+
className: cn(
|
|
1339
|
+
"flex shrink-0 items-center justify-center",
|
|
1340
|
+
"h-5 min-w-[20px] rounded-full px-1.5",
|
|
1341
|
+
"bg-primary-800 text-xs font-medium text-white"
|
|
1342
|
+
),
|
|
1343
|
+
children: conversation.unreadCount > 99 ? "99+" : conversation.unreadCount
|
|
1344
|
+
}
|
|
1345
|
+
)
|
|
1346
|
+
] })
|
|
1347
|
+
]
|
|
1348
|
+
}
|
|
1349
|
+
),
|
|
1350
|
+
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 flex-col items-center gap-1", children: [
|
|
1351
|
+
conversation.isPinned && /* @__PURE__ */ jsx(
|
|
1352
|
+
"svg",
|
|
1353
|
+
{
|
|
1354
|
+
"aria-hidden": "true",
|
|
1355
|
+
className: "text-primary-800 h-4 w-4",
|
|
1356
|
+
fill: "currentColor",
|
|
1357
|
+
viewBox: "0 0 24 24",
|
|
1358
|
+
children: /* @__PURE__ */ jsx("path", { d: "M16 4v8l2 2v2h-6v6l-1 1-1-1v-6H4v-2l2-2V4c0-1.1.9-2 2-2h6c1.1 0 2 .9 2 2z" })
|
|
1359
|
+
}
|
|
1360
|
+
),
|
|
1361
|
+
conversation.isMuted && /* @__PURE__ */ jsxs(
|
|
1362
|
+
"svg",
|
|
1363
|
+
{
|
|
1364
|
+
"aria-hidden": "true",
|
|
1365
|
+
className: "h-4 w-4 text-neutral-500",
|
|
1366
|
+
fill: "none",
|
|
1367
|
+
viewBox: "0 0 24 24",
|
|
1368
|
+
stroke: "currentColor",
|
|
1369
|
+
children: [
|
|
1370
|
+
/* @__PURE__ */ jsx(
|
|
1371
|
+
"path",
|
|
1372
|
+
{
|
|
1373
|
+
strokeLinecap: "round",
|
|
1374
|
+
strokeLinejoin: "round",
|
|
1375
|
+
strokeWidth: 2,
|
|
1376
|
+
d: "M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"
|
|
1377
|
+
}
|
|
1378
|
+
),
|
|
1379
|
+
/* @__PURE__ */ jsx(
|
|
1380
|
+
"path",
|
|
1381
|
+
{
|
|
1382
|
+
strokeLinecap: "round",
|
|
1383
|
+
strokeLinejoin: "round",
|
|
1384
|
+
strokeWidth: 2,
|
|
1385
|
+
d: "M17 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2"
|
|
1386
|
+
}
|
|
1387
|
+
)
|
|
1388
|
+
]
|
|
1389
|
+
}
|
|
1390
|
+
)
|
|
1391
|
+
] })
|
|
1392
|
+
]
|
|
1393
|
+
}
|
|
1394
|
+
);
|
|
1395
|
+
});
|
|
1396
|
+
ConversationListItem.displayName = "ConversationListItem";
|
|
1397
|
+
function ConversationListSkeleton({
|
|
1398
|
+
count = 5,
|
|
1399
|
+
className
|
|
1400
|
+
}) {
|
|
1401
|
+
return /* @__PURE__ */ jsx(
|
|
1402
|
+
"div",
|
|
1403
|
+
{
|
|
1404
|
+
className: cn(
|
|
1405
|
+
"divide-y divide-neutral-200 dark:divide-neutral-700",
|
|
1406
|
+
className
|
|
1407
|
+
),
|
|
1408
|
+
children: Array.from({ length: count }).map((_, i) => /* @__PURE__ */ jsxs(
|
|
1409
|
+
"div",
|
|
1410
|
+
{
|
|
1411
|
+
className: "flex items-center gap-3 px-4 py-3",
|
|
1412
|
+
"aria-hidden": "true",
|
|
1413
|
+
children: [
|
|
1414
|
+
/* @__PURE__ */ jsx("div", { className: "h-12 w-12 animate-pulse rounded-full bg-neutral-200 dark:bg-neutral-700" }),
|
|
1415
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-2", children: [
|
|
1416
|
+
/* @__PURE__ */ jsx("div", { className: "h-4 w-32 animate-pulse rounded bg-neutral-200 dark:bg-neutral-700" }),
|
|
1417
|
+
/* @__PURE__ */ jsx("div", { className: "h-3 w-48 animate-pulse rounded bg-neutral-200 dark:bg-neutral-700" })
|
|
1418
|
+
] })
|
|
1419
|
+
]
|
|
1420
|
+
},
|
|
1421
|
+
i
|
|
1422
|
+
))
|
|
1423
|
+
}
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
ConversationListSkeleton.displayName = "ConversationListSkeleton";
|
|
1427
|
+
function LightboxModal({ attachment, onClose }) {
|
|
1428
|
+
React5.useEffect(() => {
|
|
1429
|
+
const handleKeyDown = (event) => {
|
|
1430
|
+
if (event.key === "Escape") {
|
|
1431
|
+
onClose();
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
if (attachment) {
|
|
1435
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
1436
|
+
document.body.style.overflow = "hidden";
|
|
1437
|
+
}
|
|
1438
|
+
return () => {
|
|
1439
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
1440
|
+
document.body.style.overflow = "";
|
|
1441
|
+
};
|
|
1442
|
+
}, [attachment, onClose]);
|
|
1443
|
+
if (!attachment) return null;
|
|
1444
|
+
const isImage = attachment.type === "image";
|
|
1445
|
+
const isVideo = attachment.type === "video";
|
|
1446
|
+
return /* @__PURE__ */ jsxs(
|
|
1447
|
+
"div",
|
|
1448
|
+
{
|
|
1449
|
+
"data-slot": "message-lightbox",
|
|
1450
|
+
className: cn("fixed inset-0 z-50", "flex items-center justify-center"),
|
|
1451
|
+
role: "dialog",
|
|
1452
|
+
"aria-modal": "true",
|
|
1453
|
+
"aria-label": `View ${attachment.filename}`,
|
|
1454
|
+
children: [
|
|
1455
|
+
/* @__PURE__ */ jsx(
|
|
1456
|
+
"button",
|
|
1457
|
+
{
|
|
1458
|
+
type: "button",
|
|
1459
|
+
className: "absolute inset-0 cursor-default bg-black/90",
|
|
1460
|
+
onClick: onClose,
|
|
1461
|
+
"aria-label": "Close lightbox"
|
|
1462
|
+
}
|
|
1463
|
+
),
|
|
1464
|
+
/* @__PURE__ */ jsx(
|
|
1465
|
+
"button",
|
|
1466
|
+
{
|
|
1467
|
+
type: "button",
|
|
1468
|
+
onClick: onClose,
|
|
1469
|
+
className: cn(
|
|
1470
|
+
"absolute top-4 right-4 z-10",
|
|
1471
|
+
"rounded-full p-2",
|
|
1472
|
+
"bg-white/10 text-white",
|
|
1473
|
+
"hover:bg-white/20",
|
|
1474
|
+
"focus:ring-2 focus:ring-white focus:outline-none",
|
|
1475
|
+
"transition-colors"
|
|
1476
|
+
),
|
|
1477
|
+
"aria-label": "Close",
|
|
1478
|
+
children: /* @__PURE__ */ jsx(
|
|
1479
|
+
"svg",
|
|
1480
|
+
{
|
|
1481
|
+
"aria-hidden": "true",
|
|
1482
|
+
className: "h-6 w-6",
|
|
1483
|
+
fill: "none",
|
|
1484
|
+
viewBox: "0 0 24 24",
|
|
1485
|
+
stroke: "currentColor",
|
|
1486
|
+
children: /* @__PURE__ */ jsx(
|
|
1487
|
+
"path",
|
|
1488
|
+
{
|
|
1489
|
+
strokeLinecap: "round",
|
|
1490
|
+
strokeLinejoin: "round",
|
|
1491
|
+
strokeWidth: 2,
|
|
1492
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
1493
|
+
}
|
|
1494
|
+
)
|
|
1495
|
+
}
|
|
1496
|
+
)
|
|
1497
|
+
}
|
|
1498
|
+
),
|
|
1499
|
+
/* @__PURE__ */ jsxs("div", { className: "relative z-10 max-h-[90vh] max-w-[90vw]", children: [
|
|
1500
|
+
isImage && /* @__PURE__ */ jsx(
|
|
1501
|
+
"img",
|
|
1502
|
+
{
|
|
1503
|
+
src: attachment.url,
|
|
1504
|
+
alt: attachment.alt || attachment.filename,
|
|
1505
|
+
className: "max-h-[90vh] max-w-[90vw] object-contain"
|
|
1506
|
+
}
|
|
1507
|
+
),
|
|
1508
|
+
isVideo && /* @__PURE__ */ jsx(
|
|
1509
|
+
"video",
|
|
1510
|
+
{
|
|
1511
|
+
src: attachment.url,
|
|
1512
|
+
controls: true,
|
|
1513
|
+
autoPlay: true,
|
|
1514
|
+
className: "max-h-[90vh] max-w-[90vw]",
|
|
1515
|
+
children: /* @__PURE__ */ jsx("track", { kind: "captions" })
|
|
1516
|
+
}
|
|
1517
|
+
)
|
|
1518
|
+
] }),
|
|
1519
|
+
/* @__PURE__ */ jsx("div", { className: "absolute bottom-4 left-1/2 -translate-x-1/2", children: /* @__PURE__ */ jsx("p", { className: "rounded-full bg-black/50 px-4 py-2 text-sm text-white", children: attachment.filename }) })
|
|
1520
|
+
]
|
|
1521
|
+
}
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
LightboxModal.displayName = "LightboxModal";
|
|
1525
|
+
var MessageThread = React5.forwardRef(
|
|
1526
|
+
({
|
|
1527
|
+
conversation,
|
|
1528
|
+
messages,
|
|
1529
|
+
currentUser,
|
|
1530
|
+
typingState,
|
|
1531
|
+
isLoading = false,
|
|
1532
|
+
hasMore = false,
|
|
1533
|
+
isLoadingMore = false,
|
|
1534
|
+
isSending = false,
|
|
1535
|
+
eventHandlers = {},
|
|
1536
|
+
showHeader = true,
|
|
1537
|
+
showBackButton = false,
|
|
1538
|
+
onBack,
|
|
1539
|
+
headerActions,
|
|
1540
|
+
placeholder = "Type a message...",
|
|
1541
|
+
maxMessageLength = 1600,
|
|
1542
|
+
showCharacterCount = false,
|
|
1543
|
+
showAttachmentPicker = true,
|
|
1544
|
+
showCameraButton = false,
|
|
1545
|
+
acceptedFileTypes,
|
|
1546
|
+
maxFileSize,
|
|
1547
|
+
maxAttachments,
|
|
1548
|
+
showAvatars = true,
|
|
1549
|
+
showSenderNames = false,
|
|
1550
|
+
groupByDate = true,
|
|
1551
|
+
emptyState,
|
|
1552
|
+
formatTimestamp,
|
|
1553
|
+
onError,
|
|
1554
|
+
className
|
|
1555
|
+
}, ref) => {
|
|
1556
|
+
const [lightboxAttachment, setLightboxAttachment] = React5.useState(null);
|
|
1557
|
+
const [replyTo, setReplyTo] = React5.useState(null);
|
|
1558
|
+
const participant = conversation?.type === "direct" ? conversation.participants.find((p) => p.id !== currentUser.id) : void 0;
|
|
1559
|
+
const handleAttachmentClick = (attachment, message) => {
|
|
1560
|
+
if (attachment.type === "image" || attachment.type === "video") {
|
|
1561
|
+
setLightboxAttachment(attachment);
|
|
1562
|
+
}
|
|
1563
|
+
eventHandlers.onAttachmentClick?.(attachment, message);
|
|
1564
|
+
};
|
|
1565
|
+
const handleSendMessage = async (newMessage) => {
|
|
1566
|
+
const messageWithReply = {
|
|
1567
|
+
...newMessage,
|
|
1568
|
+
replyToId: replyTo?.id || newMessage.replyToId
|
|
1569
|
+
};
|
|
1570
|
+
setReplyTo(null);
|
|
1571
|
+
await eventHandlers.onSendMessage?.(messageWithReply);
|
|
1572
|
+
};
|
|
1573
|
+
return /* @__PURE__ */ jsxs(
|
|
1574
|
+
"div",
|
|
1575
|
+
{
|
|
1576
|
+
ref,
|
|
1577
|
+
"data-slot": "message-thread",
|
|
1578
|
+
className: cn(
|
|
1579
|
+
"flex h-full flex-col",
|
|
1580
|
+
"bg-white dark:bg-neutral-900",
|
|
1581
|
+
className
|
|
1582
|
+
),
|
|
1583
|
+
children: [
|
|
1584
|
+
showHeader && /* @__PURE__ */ jsx(
|
|
1585
|
+
ConversationHeader,
|
|
1586
|
+
{
|
|
1587
|
+
conversation,
|
|
1588
|
+
participant,
|
|
1589
|
+
showBackButton,
|
|
1590
|
+
onBack,
|
|
1591
|
+
actions: headerActions
|
|
1592
|
+
}
|
|
1593
|
+
),
|
|
1594
|
+
/* @__PURE__ */ jsx(
|
|
1595
|
+
DragDropZone,
|
|
1596
|
+
{
|
|
1597
|
+
onFilesDropped: () => {
|
|
1598
|
+
onError?.("Drop files on the composer to attach them");
|
|
1599
|
+
},
|
|
1600
|
+
disabled: !showAttachmentPicker,
|
|
1601
|
+
className: "flex-1 overflow-hidden",
|
|
1602
|
+
children: /* @__PURE__ */ jsx(
|
|
1603
|
+
MessageList,
|
|
1604
|
+
{
|
|
1605
|
+
messages,
|
|
1606
|
+
currentUser,
|
|
1607
|
+
isLoading,
|
|
1608
|
+
hasMore,
|
|
1609
|
+
isLoadingMore,
|
|
1610
|
+
typingState,
|
|
1611
|
+
showAvatars,
|
|
1612
|
+
showSenderNames,
|
|
1613
|
+
groupByDate,
|
|
1614
|
+
onLoadMore: eventHandlers.onLoadMore,
|
|
1615
|
+
onRetryMessage: eventHandlers.onRetryMessage,
|
|
1616
|
+
onAttachmentClick: handleAttachmentClick,
|
|
1617
|
+
emptyState,
|
|
1618
|
+
formatTimestamp,
|
|
1619
|
+
className: "h-full"
|
|
1620
|
+
}
|
|
1621
|
+
)
|
|
1622
|
+
}
|
|
1623
|
+
),
|
|
1624
|
+
/* @__PURE__ */ jsx(
|
|
1625
|
+
MessageComposer,
|
|
1626
|
+
{
|
|
1627
|
+
onSend: handleSendMessage,
|
|
1628
|
+
onTypingStart: eventHandlers.onTypingStart,
|
|
1629
|
+
onTypingStop: eventHandlers.onTypingStop,
|
|
1630
|
+
placeholder,
|
|
1631
|
+
maxLength: maxMessageLength,
|
|
1632
|
+
showCharacterCount,
|
|
1633
|
+
isSending,
|
|
1634
|
+
showAttachmentPicker,
|
|
1635
|
+
showCameraButton,
|
|
1636
|
+
acceptedFileTypes,
|
|
1637
|
+
maxFileSize,
|
|
1638
|
+
maxAttachments,
|
|
1639
|
+
onError,
|
|
1640
|
+
replyTo,
|
|
1641
|
+
onCancelReply: () => setReplyTo(null)
|
|
1642
|
+
}
|
|
1643
|
+
),
|
|
1644
|
+
/* @__PURE__ */ jsx(
|
|
1645
|
+
LightboxModal,
|
|
1646
|
+
{
|
|
1647
|
+
attachment: lightboxAttachment,
|
|
1648
|
+
onClose: () => setLightboxAttachment(null)
|
|
1649
|
+
}
|
|
1650
|
+
)
|
|
1651
|
+
]
|
|
1652
|
+
}
|
|
1653
|
+
);
|
|
1654
|
+
}
|
|
1655
|
+
);
|
|
1656
|
+
MessageThread.displayName = "MessageThread";
|
|
1657
|
+
function MessagingSplitView({
|
|
1658
|
+
conversationList,
|
|
1659
|
+
messageThread,
|
|
1660
|
+
hasSelectedConversation = false,
|
|
1661
|
+
listWidth = 320,
|
|
1662
|
+
mobileBreakpoint = "md",
|
|
1663
|
+
className
|
|
1664
|
+
}) {
|
|
1665
|
+
const breakpointClasses = {
|
|
1666
|
+
sm: "sm:flex",
|
|
1667
|
+
md: "md:flex",
|
|
1668
|
+
lg: "lg:flex"
|
|
1669
|
+
};
|
|
1670
|
+
const hideMobileClasses = {
|
|
1671
|
+
sm: hasSelectedConversation ? "hidden sm:block" : "block sm:block",
|
|
1672
|
+
md: hasSelectedConversation ? "hidden md:block" : "block md:block",
|
|
1673
|
+
lg: hasSelectedConversation ? "hidden lg:block" : "block lg:block"
|
|
1674
|
+
};
|
|
1675
|
+
const showMobileClasses = {
|
|
1676
|
+
sm: hasSelectedConversation ? "block sm:block" : "hidden sm:block",
|
|
1677
|
+
md: hasSelectedConversation ? "block md:block" : "hidden md:block",
|
|
1678
|
+
lg: hasSelectedConversation ? "block lg:block" : "hidden lg:block"
|
|
1679
|
+
};
|
|
1680
|
+
return /* @__PURE__ */ jsxs(
|
|
1681
|
+
"div",
|
|
1682
|
+
{
|
|
1683
|
+
"data-slot": "messaging-split-view",
|
|
1684
|
+
className: cn(
|
|
1685
|
+
"h-full w-full",
|
|
1686
|
+
breakpointClasses[mobileBreakpoint],
|
|
1687
|
+
className
|
|
1688
|
+
),
|
|
1689
|
+
children: [
|
|
1690
|
+
/* @__PURE__ */ jsx(
|
|
1691
|
+
"div",
|
|
1692
|
+
{
|
|
1693
|
+
"data-slot": "messaging-list-pane",
|
|
1694
|
+
className: cn(
|
|
1695
|
+
"h-full w-full flex-shrink-0",
|
|
1696
|
+
"border-r border-neutral-200 dark:border-neutral-700",
|
|
1697
|
+
hideMobileClasses[mobileBreakpoint]
|
|
1698
|
+
),
|
|
1699
|
+
style: {
|
|
1700
|
+
width: typeof listWidth === "number" ? `${listWidth}px` : listWidth
|
|
1701
|
+
},
|
|
1702
|
+
children: conversationList
|
|
1703
|
+
}
|
|
1704
|
+
),
|
|
1705
|
+
/* @__PURE__ */ jsx(
|
|
1706
|
+
"div",
|
|
1707
|
+
{
|
|
1708
|
+
"data-slot": "messaging-thread-pane",
|
|
1709
|
+
className: cn(
|
|
1710
|
+
"h-full min-w-0 flex-1",
|
|
1711
|
+
showMobileClasses[mobileBreakpoint]
|
|
1712
|
+
),
|
|
1713
|
+
children: messageThread
|
|
1714
|
+
}
|
|
1715
|
+
)
|
|
1716
|
+
]
|
|
1717
|
+
}
|
|
1718
|
+
);
|
|
1719
|
+
}
|
|
1720
|
+
MessagingSplitView.displayName = "MessagingSplitView";
|
|
1721
|
+
function useMessages(options) {
|
|
1722
|
+
const {
|
|
1723
|
+
initialMessages = [],
|
|
1724
|
+
currentUser,
|
|
1725
|
+
onSend,
|
|
1726
|
+
onRetry,
|
|
1727
|
+
onLoadMore
|
|
1728
|
+
} = options;
|
|
1729
|
+
const [messages, setMessages] = React5.useState(initialMessages);
|
|
1730
|
+
const [isSending, setIsSending] = React5.useState(false);
|
|
1731
|
+
const [isLoadingMore, setIsLoadingMore] = React5.useState(false);
|
|
1732
|
+
React5.useEffect(() => {
|
|
1733
|
+
setMessages(initialMessages);
|
|
1734
|
+
}, [initialMessages]);
|
|
1735
|
+
const addMessage = React5.useCallback((message) => {
|
|
1736
|
+
setMessages((prev) => {
|
|
1737
|
+
if (prev.some((m) => m.id === message.id)) {
|
|
1738
|
+
return prev;
|
|
1739
|
+
}
|
|
1740
|
+
return [...prev, message];
|
|
1741
|
+
});
|
|
1742
|
+
}, []);
|
|
1743
|
+
const updateMessage = React5.useCallback(
|
|
1744
|
+
(messageId, updates) => {
|
|
1745
|
+
setMessages(
|
|
1746
|
+
(prev) => prev.map((m) => m.id === messageId ? { ...m, ...updates } : m)
|
|
1747
|
+
);
|
|
1748
|
+
},
|
|
1749
|
+
[]
|
|
1750
|
+
);
|
|
1751
|
+
const removeMessage = React5.useCallback((messageId) => {
|
|
1752
|
+
setMessages((prev) => prev.filter((m) => m.id !== messageId));
|
|
1753
|
+
}, []);
|
|
1754
|
+
const updateStatus = React5.useCallback(
|
|
1755
|
+
(messageId, status) => {
|
|
1756
|
+
updateMessage(messageId, { status });
|
|
1757
|
+
},
|
|
1758
|
+
[updateMessage]
|
|
1759
|
+
);
|
|
1760
|
+
const markAsRead = React5.useCallback(
|
|
1761
|
+
(messageId) => {
|
|
1762
|
+
updateStatus(messageId, "read");
|
|
1763
|
+
},
|
|
1764
|
+
[updateStatus]
|
|
1765
|
+
);
|
|
1766
|
+
const sendMessage = React5.useCallback(
|
|
1767
|
+
async (newMessage) => {
|
|
1768
|
+
const optimisticId = `optimistic-${Date.now()}`;
|
|
1769
|
+
const optimisticMessage = {
|
|
1770
|
+
id: optimisticId,
|
|
1771
|
+
type: "text",
|
|
1772
|
+
content: newMessage.content,
|
|
1773
|
+
sender: currentUser,
|
|
1774
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
1775
|
+
status: "sending",
|
|
1776
|
+
attachments: []
|
|
1777
|
+
// Would handle attachment uploads here
|
|
1778
|
+
};
|
|
1779
|
+
addMessage(optimisticMessage);
|
|
1780
|
+
setIsSending(true);
|
|
1781
|
+
try {
|
|
1782
|
+
if (onSend) {
|
|
1783
|
+
const sentMessage = await onSend(newMessage);
|
|
1784
|
+
setMessages(
|
|
1785
|
+
(prev) => prev.map((m) => m.id === optimisticId ? sentMessage : m)
|
|
1786
|
+
);
|
|
1787
|
+
} else {
|
|
1788
|
+
updateStatus(optimisticId, "sent");
|
|
1789
|
+
}
|
|
1790
|
+
} catch {
|
|
1791
|
+
updateStatus(optimisticId, "failed");
|
|
1792
|
+
} finally {
|
|
1793
|
+
setIsSending(false);
|
|
1794
|
+
}
|
|
1795
|
+
},
|
|
1796
|
+
[currentUser, onSend, addMessage, updateStatus]
|
|
1797
|
+
);
|
|
1798
|
+
const retryMessage = React5.useCallback(
|
|
1799
|
+
async (messageId) => {
|
|
1800
|
+
updateStatus(messageId, "sending");
|
|
1801
|
+
try {
|
|
1802
|
+
if (onRetry) {
|
|
1803
|
+
await onRetry(messageId);
|
|
1804
|
+
updateStatus(messageId, "sent");
|
|
1805
|
+
}
|
|
1806
|
+
} catch {
|
|
1807
|
+
updateStatus(messageId, "failed");
|
|
1808
|
+
}
|
|
1809
|
+
},
|
|
1810
|
+
[onRetry, updateStatus]
|
|
1811
|
+
);
|
|
1812
|
+
const loadMore = React5.useCallback(async () => {
|
|
1813
|
+
if (isLoadingMore || !onLoadMore) return;
|
|
1814
|
+
setIsLoadingMore(true);
|
|
1815
|
+
try {
|
|
1816
|
+
const olderMessages = await onLoadMore();
|
|
1817
|
+
setMessages((prev) => [...olderMessages, ...prev]);
|
|
1818
|
+
} finally {
|
|
1819
|
+
setIsLoadingMore(false);
|
|
1820
|
+
}
|
|
1821
|
+
}, [isLoadingMore, onLoadMore]);
|
|
1822
|
+
return {
|
|
1823
|
+
messages,
|
|
1824
|
+
addMessage,
|
|
1825
|
+
updateMessage,
|
|
1826
|
+
removeMessage,
|
|
1827
|
+
sendMessage,
|
|
1828
|
+
retryMessage,
|
|
1829
|
+
loadMore,
|
|
1830
|
+
isSending,
|
|
1831
|
+
isLoadingMore,
|
|
1832
|
+
markAsRead,
|
|
1833
|
+
updateStatus
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
function useTypingIndicator(options = {}) {
|
|
1837
|
+
const {
|
|
1838
|
+
typingParticipants: initialParticipants = [],
|
|
1839
|
+
debounceTime = 2e3,
|
|
1840
|
+
onTypingStart,
|
|
1841
|
+
onTypingStop
|
|
1842
|
+
} = options;
|
|
1843
|
+
const [participants, setParticipants] = React5.useState(initialParticipants);
|
|
1844
|
+
const [isLocalTyping, setIsLocalTyping] = React5.useState(false);
|
|
1845
|
+
const typingTimeoutRef = React5.useRef(null);
|
|
1846
|
+
React5.useEffect(() => {
|
|
1847
|
+
setParticipants(initialParticipants);
|
|
1848
|
+
}, [initialParticipants]);
|
|
1849
|
+
const startTyping = React5.useCallback(() => {
|
|
1850
|
+
if (!isLocalTyping) {
|
|
1851
|
+
setIsLocalTyping(true);
|
|
1852
|
+
onTypingStart?.();
|
|
1853
|
+
}
|
|
1854
|
+
if (typingTimeoutRef.current) {
|
|
1855
|
+
clearTimeout(typingTimeoutRef.current);
|
|
1856
|
+
}
|
|
1857
|
+
typingTimeoutRef.current = setTimeout(() => {
|
|
1858
|
+
setIsLocalTyping(false);
|
|
1859
|
+
onTypingStop?.();
|
|
1860
|
+
}, debounceTime);
|
|
1861
|
+
}, [isLocalTyping, debounceTime, onTypingStart, onTypingStop]);
|
|
1862
|
+
const stopTyping = React5.useCallback(() => {
|
|
1863
|
+
if (typingTimeoutRef.current) {
|
|
1864
|
+
clearTimeout(typingTimeoutRef.current);
|
|
1865
|
+
}
|
|
1866
|
+
setIsLocalTyping(false);
|
|
1867
|
+
onTypingStop?.();
|
|
1868
|
+
}, [onTypingStop]);
|
|
1869
|
+
React5.useEffect(() => {
|
|
1870
|
+
return () => {
|
|
1871
|
+
if (typingTimeoutRef.current) {
|
|
1872
|
+
clearTimeout(typingTimeoutRef.current);
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
}, []);
|
|
1876
|
+
const typingState = React5.useMemo(
|
|
1877
|
+
() => ({
|
|
1878
|
+
participants,
|
|
1879
|
+
lastUpdated: /* @__PURE__ */ new Date()
|
|
1880
|
+
}),
|
|
1881
|
+
[participants]
|
|
1882
|
+
);
|
|
1883
|
+
return {
|
|
1884
|
+
typingState,
|
|
1885
|
+
startTyping,
|
|
1886
|
+
stopTyping,
|
|
1887
|
+
setTypingParticipants: setParticipants
|
|
1888
|
+
};
|
|
1889
|
+
}
|
|
1890
|
+
function useMessageScroll(options) {
|
|
1891
|
+
const { messages, currentUserId, threshold = 100 } = options;
|
|
1892
|
+
const scrollContainerRef = React5.useRef(null);
|
|
1893
|
+
const bottomRef = React5.useRef(null);
|
|
1894
|
+
const [isScrolledUp, setIsScrolledUp] = React5.useState(false);
|
|
1895
|
+
const prevMessageCountRef = React5.useRef(messages.length);
|
|
1896
|
+
React5.useEffect(() => {
|
|
1897
|
+
const container = scrollContainerRef.current;
|
|
1898
|
+
if (!container) return;
|
|
1899
|
+
const handleScroll = () => {
|
|
1900
|
+
const { scrollTop, scrollHeight, clientHeight } = container;
|
|
1901
|
+
const isAtBottom = scrollHeight - scrollTop - clientHeight < threshold;
|
|
1902
|
+
setIsScrolledUp(!isAtBottom);
|
|
1903
|
+
};
|
|
1904
|
+
container.addEventListener("scroll", handleScroll);
|
|
1905
|
+
return () => container.removeEventListener("scroll", handleScroll);
|
|
1906
|
+
}, [threshold]);
|
|
1907
|
+
const scrollToBottom = React5.useCallback((smooth = true) => {
|
|
1908
|
+
bottomRef.current?.scrollIntoView({
|
|
1909
|
+
behavior: smooth ? "smooth" : "auto"
|
|
1910
|
+
});
|
|
1911
|
+
}, []);
|
|
1912
|
+
React5.useEffect(() => {
|
|
1913
|
+
const messageCountChanged = messages.length !== prevMessageCountRef.current;
|
|
1914
|
+
prevMessageCountRef.current = messages.length;
|
|
1915
|
+
if (!messageCountChanged) return;
|
|
1916
|
+
const lastMessage = messages[messages.length - 1];
|
|
1917
|
+
const isOutgoing = lastMessage?.sender.id === currentUserId;
|
|
1918
|
+
if (isOutgoing || !isScrolledUp) {
|
|
1919
|
+
scrollToBottom(true);
|
|
1920
|
+
}
|
|
1921
|
+
}, [messages, currentUserId, isScrolledUp, scrollToBottom]);
|
|
1922
|
+
return {
|
|
1923
|
+
scrollContainerRef,
|
|
1924
|
+
bottomRef,
|
|
1925
|
+
isScrolledUp,
|
|
1926
|
+
scrollToBottom
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
function useReadReceipts(options) {
|
|
1930
|
+
const { currentUserId, onMarkRead, threshold = 0.5 } = options;
|
|
1931
|
+
const observerRef = React5.useRef(null);
|
|
1932
|
+
const observedMessagesRef = React5.useRef(/* @__PURE__ */ new Set());
|
|
1933
|
+
React5.useEffect(() => {
|
|
1934
|
+
observerRef.current = new IntersectionObserver(
|
|
1935
|
+
(entries) => {
|
|
1936
|
+
entries.forEach((entry) => {
|
|
1937
|
+
if (entry.isIntersecting) {
|
|
1938
|
+
const messageId = entry.target.getAttribute("data-message-id");
|
|
1939
|
+
if (messageId && !observedMessagesRef.current.has(messageId)) {
|
|
1940
|
+
observedMessagesRef.current.add(messageId);
|
|
1941
|
+
onMarkRead?.(messageId);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
});
|
|
1945
|
+
},
|
|
1946
|
+
{ threshold }
|
|
1947
|
+
);
|
|
1948
|
+
return () => {
|
|
1949
|
+
observerRef.current?.disconnect();
|
|
1950
|
+
};
|
|
1951
|
+
}, [onMarkRead, threshold]);
|
|
1952
|
+
const observeMessage = React5.useCallback(
|
|
1953
|
+
(element, message) => {
|
|
1954
|
+
if (!element || !observerRef.current) return;
|
|
1955
|
+
if (message.sender.id !== currentUserId && message.status !== "read" && !observedMessagesRef.current.has(message.id)) {
|
|
1956
|
+
element.setAttribute("data-message-id", message.id);
|
|
1957
|
+
observerRef.current.observe(element);
|
|
1958
|
+
}
|
|
1959
|
+
},
|
|
1960
|
+
[currentUserId]
|
|
1961
|
+
);
|
|
1962
|
+
return { observeMessage };
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
export { AttachmentPreview, ConversationHeader, ConversationListItem, ConversationListSkeleton, DateSeparator, EmptyState, LightboxModal, LoadMoreButton, MessageBubble, MessageList, MessageStatusIcon, MessageThread, MessagingSplitView, ReadReceiptIndicator, SkeletonMessage, TypingIndicator, bubbleVariants, formatDateLabel, formatFileSize, formatLastSeen, getConversationSubtitle, getConversationTitle, groupMessagesByDate, headerVariants, isSameSenderGroup, useMessageScroll, useMessages, useReadReceipts, useTypingIndicator };
|
|
1966
|
+
//# sourceMappingURL=chunk-ASLZUFH4.js.map
|
|
1967
|
+
//# sourceMappingURL=chunk-ASLZUFH4.js.map
|