@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,1124 @@
|
|
|
1
|
+
import { cn } from './chunk-F3SOEIN2.js';
|
|
2
|
+
import * as React2 from 'react';
|
|
3
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { cva } from 'class-variance-authority';
|
|
5
|
+
|
|
6
|
+
function getFileType(mimeType) {
|
|
7
|
+
if (mimeType.startsWith("image/")) return "image";
|
|
8
|
+
if (mimeType.startsWith("video/")) return "video";
|
|
9
|
+
if (mimeType.startsWith("audio/")) return "audio";
|
|
10
|
+
if (mimeType.includes("pdf") || mimeType.includes("document") || mimeType.includes("text")) {
|
|
11
|
+
return "document";
|
|
12
|
+
}
|
|
13
|
+
return "file";
|
|
14
|
+
}
|
|
15
|
+
function formatFileSize(bytes) {
|
|
16
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
17
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
18
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
19
|
+
}
|
|
20
|
+
function validateFile(file, acceptedTypes, maxSize) {
|
|
21
|
+
if (acceptedTypes && acceptedTypes.length > 0) {
|
|
22
|
+
const isAccepted = acceptedTypes.some((type) => {
|
|
23
|
+
if (type.startsWith(".")) {
|
|
24
|
+
return file.name.toLowerCase().endsWith(type.toLowerCase());
|
|
25
|
+
}
|
|
26
|
+
if (type.endsWith("/*")) {
|
|
27
|
+
return file.type.startsWith(type.replace("/*", "/"));
|
|
28
|
+
}
|
|
29
|
+
return file.type === type;
|
|
30
|
+
});
|
|
31
|
+
if (!isAccepted) {
|
|
32
|
+
return { valid: false, error: "File type not supported" };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (maxSize && file.size > maxSize) {
|
|
36
|
+
return {
|
|
37
|
+
valid: false,
|
|
38
|
+
error: `File too large (max ${formatFileSize(maxSize)})`
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return { valid: true };
|
|
42
|
+
}
|
|
43
|
+
function generateAttachmentId() {
|
|
44
|
+
return `attachment-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
45
|
+
}
|
|
46
|
+
function AttachmentPreviewItem({
|
|
47
|
+
attachment,
|
|
48
|
+
onRemove,
|
|
49
|
+
onRetry,
|
|
50
|
+
className
|
|
51
|
+
}) {
|
|
52
|
+
const { file, previewUrl, type, state, progress } = attachment;
|
|
53
|
+
const isImage = type === "image";
|
|
54
|
+
const isVideo = type === "video";
|
|
55
|
+
const isUploading = state === "uploading";
|
|
56
|
+
const isFailed = state === "failed";
|
|
57
|
+
return /* @__PURE__ */ jsxs(
|
|
58
|
+
"div",
|
|
59
|
+
{
|
|
60
|
+
className: cn(
|
|
61
|
+
"group relative overflow-hidden rounded-lg",
|
|
62
|
+
"bg-neutral-100 dark:bg-neutral-800",
|
|
63
|
+
"border border-neutral-200 dark:border-neutral-700",
|
|
64
|
+
isFailed && "border-red-500",
|
|
65
|
+
className
|
|
66
|
+
),
|
|
67
|
+
children: [
|
|
68
|
+
(isImage || isVideo) && previewUrl ? /* @__PURE__ */ jsxs("div", { className: "relative h-20 w-20", children: [
|
|
69
|
+
/* @__PURE__ */ jsx(
|
|
70
|
+
"img",
|
|
71
|
+
{
|
|
72
|
+
src: previewUrl,
|
|
73
|
+
alt: file.name,
|
|
74
|
+
className: cn(
|
|
75
|
+
"h-full w-full object-cover",
|
|
76
|
+
(isUploading || isFailed) && "opacity-50"
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
),
|
|
80
|
+
isVideo && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsx(
|
|
81
|
+
"svg",
|
|
82
|
+
{
|
|
83
|
+
"aria-hidden": "true",
|
|
84
|
+
className: "h-6 w-6 text-white drop-shadow",
|
|
85
|
+
fill: "currentColor",
|
|
86
|
+
viewBox: "0 0 24 24",
|
|
87
|
+
children: /* @__PURE__ */ jsx("path", { d: "M8 5v14l11-7z" })
|
|
88
|
+
}
|
|
89
|
+
) })
|
|
90
|
+
] }) : (
|
|
91
|
+
/* File preview */
|
|
92
|
+
/* @__PURE__ */ jsxs("div", { className: "flex h-20 w-20 flex-col items-center justify-center p-2", children: [
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
"svg",
|
|
95
|
+
{
|
|
96
|
+
"aria-hidden": "true",
|
|
97
|
+
className: "h-8 w-8 text-neutral-500",
|
|
98
|
+
fill: "none",
|
|
99
|
+
viewBox: "0 0 24 24",
|
|
100
|
+
stroke: "currentColor",
|
|
101
|
+
children: /* @__PURE__ */ jsx(
|
|
102
|
+
"path",
|
|
103
|
+
{
|
|
104
|
+
strokeLinecap: "round",
|
|
105
|
+
strokeLinejoin: "round",
|
|
106
|
+
strokeWidth: 2,
|
|
107
|
+
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"
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
),
|
|
112
|
+
/* @__PURE__ */ jsx("span", { className: "mt-1 max-w-full truncate px-1 text-xs text-neutral-500", children: file.name.split(".").pop()?.toUpperCase() })
|
|
113
|
+
] })
|
|
114
|
+
),
|
|
115
|
+
isUploading && 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: [
|
|
116
|
+
/* @__PURE__ */ jsxs(
|
|
117
|
+
"svg",
|
|
118
|
+
{
|
|
119
|
+
"aria-hidden": "true",
|
|
120
|
+
className: "mx-auto h-6 w-6 animate-spin",
|
|
121
|
+
fill: "none",
|
|
122
|
+
viewBox: "0 0 24 24",
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ jsx(
|
|
125
|
+
"circle",
|
|
126
|
+
{
|
|
127
|
+
className: "opacity-25",
|
|
128
|
+
cx: "12",
|
|
129
|
+
cy: "12",
|
|
130
|
+
r: "10",
|
|
131
|
+
stroke: "currentColor",
|
|
132
|
+
strokeWidth: "4"
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
/* @__PURE__ */ jsx(
|
|
136
|
+
"path",
|
|
137
|
+
{
|
|
138
|
+
className: "opacity-75",
|
|
139
|
+
fill: "currentColor",
|
|
140
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
),
|
|
146
|
+
/* @__PURE__ */ jsxs("span", { className: "mt-1 text-xs", children: [
|
|
147
|
+
progress,
|
|
148
|
+
"%"
|
|
149
|
+
] })
|
|
150
|
+
] }) }),
|
|
151
|
+
isFailed && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
|
|
152
|
+
/* @__PURE__ */ jsx(
|
|
153
|
+
"svg",
|
|
154
|
+
{
|
|
155
|
+
"aria-hidden": "true",
|
|
156
|
+
className: "mx-auto h-6 w-6 text-red-400",
|
|
157
|
+
fill: "none",
|
|
158
|
+
viewBox: "0 0 24 24",
|
|
159
|
+
stroke: "currentColor",
|
|
160
|
+
children: /* @__PURE__ */ jsx(
|
|
161
|
+
"path",
|
|
162
|
+
{
|
|
163
|
+
strokeLinecap: "round",
|
|
164
|
+
strokeLinejoin: "round",
|
|
165
|
+
strokeWidth: 2,
|
|
166
|
+
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"
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
),
|
|
171
|
+
onRetry && /* @__PURE__ */ jsx(
|
|
172
|
+
"button",
|
|
173
|
+
{
|
|
174
|
+
type: "button",
|
|
175
|
+
onClick: onRetry,
|
|
176
|
+
className: "mt-1 text-xs text-white underline hover:no-underline",
|
|
177
|
+
children: "Retry"
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
] }) }),
|
|
181
|
+
/* @__PURE__ */ jsx(
|
|
182
|
+
"button",
|
|
183
|
+
{
|
|
184
|
+
type: "button",
|
|
185
|
+
onClick: onRemove,
|
|
186
|
+
className: cn(
|
|
187
|
+
"absolute -top-1 -right-1 z-10",
|
|
188
|
+
"rounded-full p-1",
|
|
189
|
+
"bg-neutral-900 text-white",
|
|
190
|
+
"opacity-0 group-hover:opacity-100",
|
|
191
|
+
"focus:ring-primary-500 focus:opacity-100 focus:ring-2 focus:outline-none",
|
|
192
|
+
"transition-opacity"
|
|
193
|
+
),
|
|
194
|
+
"aria-label": `Remove ${file.name}`,
|
|
195
|
+
children: /* @__PURE__ */ jsx(
|
|
196
|
+
"svg",
|
|
197
|
+
{
|
|
198
|
+
"aria-hidden": "true",
|
|
199
|
+
className: "h-3 w-3",
|
|
200
|
+
fill: "none",
|
|
201
|
+
viewBox: "0 0 24 24",
|
|
202
|
+
stroke: "currentColor",
|
|
203
|
+
children: /* @__PURE__ */ jsx(
|
|
204
|
+
"path",
|
|
205
|
+
{
|
|
206
|
+
strokeLinecap: "round",
|
|
207
|
+
strokeLinejoin: "round",
|
|
208
|
+
strokeWidth: 2,
|
|
209
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
),
|
|
216
|
+
/* @__PURE__ */ jsx(
|
|
217
|
+
"div",
|
|
218
|
+
{
|
|
219
|
+
className: cn(
|
|
220
|
+
"absolute right-0 bottom-0 left-0",
|
|
221
|
+
"bg-black/70 px-1 py-0.5",
|
|
222
|
+
"opacity-0 group-hover:opacity-100",
|
|
223
|
+
"transition-opacity"
|
|
224
|
+
),
|
|
225
|
+
children: /* @__PURE__ */ jsx("p", { className: "truncate text-xs text-white", children: file.name })
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
AttachmentPreviewItem.displayName = "AttachmentPreviewItem";
|
|
233
|
+
var AttachmentPicker = React2.forwardRef(
|
|
234
|
+
({
|
|
235
|
+
onFilesSelected,
|
|
236
|
+
acceptedTypes = ["image/*", "video/*", ".pdf", ".doc", ".docx"],
|
|
237
|
+
maxFileSize = 25 * 1024 * 1024,
|
|
238
|
+
// 25MB
|
|
239
|
+
maxFiles = 10,
|
|
240
|
+
multiple = true,
|
|
241
|
+
disabled = false,
|
|
242
|
+
onError,
|
|
243
|
+
className,
|
|
244
|
+
children
|
|
245
|
+
}, ref) => {
|
|
246
|
+
const inputRef = React2.useRef(null);
|
|
247
|
+
React2.useImperativeHandle(ref, () => inputRef.current);
|
|
248
|
+
const handleClick = () => {
|
|
249
|
+
inputRef.current?.click();
|
|
250
|
+
};
|
|
251
|
+
const handleChange = (event) => {
|
|
252
|
+
const files = Array.from(event.target.files || []);
|
|
253
|
+
if (files.length === 0) return;
|
|
254
|
+
const validFiles = [];
|
|
255
|
+
for (const file of files.slice(0, maxFiles)) {
|
|
256
|
+
const validation = validateFile(file, acceptedTypes, maxFileSize);
|
|
257
|
+
if (validation.valid) {
|
|
258
|
+
validFiles.push(file);
|
|
259
|
+
} else if (onError) {
|
|
260
|
+
onError(`${file.name}: ${validation.error}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (files.length > maxFiles && onError) {
|
|
264
|
+
onError(`Maximum ${maxFiles} files allowed`);
|
|
265
|
+
}
|
|
266
|
+
if (validFiles.length > 0) {
|
|
267
|
+
onFilesSelected(validFiles);
|
|
268
|
+
}
|
|
269
|
+
event.target.value = "";
|
|
270
|
+
};
|
|
271
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
272
|
+
/* @__PURE__ */ jsx(
|
|
273
|
+
"input",
|
|
274
|
+
{
|
|
275
|
+
ref: inputRef,
|
|
276
|
+
type: "file",
|
|
277
|
+
accept: acceptedTypes.join(","),
|
|
278
|
+
multiple,
|
|
279
|
+
onChange: handleChange,
|
|
280
|
+
disabled,
|
|
281
|
+
className: "sr-only",
|
|
282
|
+
"aria-label": "Select files to attach"
|
|
283
|
+
}
|
|
284
|
+
),
|
|
285
|
+
/* @__PURE__ */ jsx(
|
|
286
|
+
"button",
|
|
287
|
+
{
|
|
288
|
+
type: "button",
|
|
289
|
+
onClick: handleClick,
|
|
290
|
+
disabled,
|
|
291
|
+
"data-slot": "attachment-picker-button",
|
|
292
|
+
className: cn(
|
|
293
|
+
"inline-flex items-center justify-center",
|
|
294
|
+
"rounded-full p-2",
|
|
295
|
+
"text-neutral-500 hover:text-neutral-700",
|
|
296
|
+
"dark:text-neutral-400 dark:hover:text-neutral-200",
|
|
297
|
+
"hover:bg-neutral-100 dark:hover:bg-neutral-800",
|
|
298
|
+
"focus:ring-primary-500 focus:ring-2 focus:outline-none",
|
|
299
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
300
|
+
"transition-colors",
|
|
301
|
+
className
|
|
302
|
+
),
|
|
303
|
+
"aria-label": "Attach files",
|
|
304
|
+
children: children || /* @__PURE__ */ jsx(
|
|
305
|
+
"svg",
|
|
306
|
+
{
|
|
307
|
+
"aria-hidden": "true",
|
|
308
|
+
className: "h-5 w-5",
|
|
309
|
+
fill: "none",
|
|
310
|
+
viewBox: "0 0 24 24",
|
|
311
|
+
stroke: "currentColor",
|
|
312
|
+
children: /* @__PURE__ */ jsx(
|
|
313
|
+
"path",
|
|
314
|
+
{
|
|
315
|
+
strokeLinecap: "round",
|
|
316
|
+
strokeLinejoin: "round",
|
|
317
|
+
strokeWidth: 2,
|
|
318
|
+
d: "M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"
|
|
319
|
+
}
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
)
|
|
325
|
+
] });
|
|
326
|
+
}
|
|
327
|
+
);
|
|
328
|
+
AttachmentPicker.displayName = "AttachmentPicker";
|
|
329
|
+
function DragDropZone({
|
|
330
|
+
onFilesDropped,
|
|
331
|
+
acceptedTypes,
|
|
332
|
+
maxFileSize,
|
|
333
|
+
maxFiles = 10,
|
|
334
|
+
disabled = false,
|
|
335
|
+
onError,
|
|
336
|
+
children,
|
|
337
|
+
className
|
|
338
|
+
}) {
|
|
339
|
+
const [isDragging, setIsDragging] = React2.useState(false);
|
|
340
|
+
const dragCounterRef = React2.useRef(0);
|
|
341
|
+
const handleDragEnter = (event) => {
|
|
342
|
+
event.preventDefault();
|
|
343
|
+
event.stopPropagation();
|
|
344
|
+
if (disabled) return;
|
|
345
|
+
dragCounterRef.current++;
|
|
346
|
+
if (event.dataTransfer.items && event.dataTransfer.items.length > 0) {
|
|
347
|
+
setIsDragging(true);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
const handleDragLeave = (event) => {
|
|
351
|
+
event.preventDefault();
|
|
352
|
+
event.stopPropagation();
|
|
353
|
+
if (disabled) return;
|
|
354
|
+
dragCounterRef.current--;
|
|
355
|
+
if (dragCounterRef.current === 0) {
|
|
356
|
+
setIsDragging(false);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const handleDragOver = (event) => {
|
|
360
|
+
event.preventDefault();
|
|
361
|
+
event.stopPropagation();
|
|
362
|
+
};
|
|
363
|
+
const handleDrop = (event) => {
|
|
364
|
+
event.preventDefault();
|
|
365
|
+
event.stopPropagation();
|
|
366
|
+
if (disabled) return;
|
|
367
|
+
setIsDragging(false);
|
|
368
|
+
dragCounterRef.current = 0;
|
|
369
|
+
const files = Array.from(event.dataTransfer.files);
|
|
370
|
+
if (files.length === 0) return;
|
|
371
|
+
const validFiles = [];
|
|
372
|
+
for (const file of files.slice(0, maxFiles)) {
|
|
373
|
+
const validation = validateFile(file, acceptedTypes, maxFileSize);
|
|
374
|
+
if (validation.valid) {
|
|
375
|
+
validFiles.push(file);
|
|
376
|
+
} else if (onError) {
|
|
377
|
+
onError(`${file.name}: ${validation.error}`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (files.length > maxFiles && onError) {
|
|
381
|
+
onError(`Maximum ${maxFiles} files allowed`);
|
|
382
|
+
}
|
|
383
|
+
if (validFiles.length > 0) {
|
|
384
|
+
onFilesDropped(validFiles);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
return /* @__PURE__ */ jsxs(
|
|
388
|
+
"div",
|
|
389
|
+
{
|
|
390
|
+
onDragEnter: handleDragEnter,
|
|
391
|
+
onDragLeave: handleDragLeave,
|
|
392
|
+
onDragOver: handleDragOver,
|
|
393
|
+
onDrop: handleDrop,
|
|
394
|
+
className: cn("relative", className),
|
|
395
|
+
children: [
|
|
396
|
+
children,
|
|
397
|
+
isDragging && /* @__PURE__ */ jsx(
|
|
398
|
+
"div",
|
|
399
|
+
{
|
|
400
|
+
className: cn(
|
|
401
|
+
"absolute inset-0 z-50",
|
|
402
|
+
"flex items-center justify-center",
|
|
403
|
+
"bg-primary-50/90 dark:bg-primary-900/90",
|
|
404
|
+
"border-primary-500 border-2 border-dashed",
|
|
405
|
+
"rounded-lg"
|
|
406
|
+
),
|
|
407
|
+
children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
|
|
408
|
+
/* @__PURE__ */ jsx(
|
|
409
|
+
"svg",
|
|
410
|
+
{
|
|
411
|
+
"aria-hidden": "true",
|
|
412
|
+
className: "text-primary-800 mx-auto h-12 w-12",
|
|
413
|
+
fill: "none",
|
|
414
|
+
viewBox: "0 0 24 24",
|
|
415
|
+
stroke: "currentColor",
|
|
416
|
+
children: /* @__PURE__ */ jsx(
|
|
417
|
+
"path",
|
|
418
|
+
{
|
|
419
|
+
strokeLinecap: "round",
|
|
420
|
+
strokeLinejoin: "round",
|
|
421
|
+
strokeWidth: 2,
|
|
422
|
+
d: "M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"
|
|
423
|
+
}
|
|
424
|
+
)
|
|
425
|
+
}
|
|
426
|
+
),
|
|
427
|
+
/* @__PURE__ */ jsx("p", { className: "text-primary-700 dark:text-primary-300 mt-2 text-sm font-medium", children: "Drop files here" })
|
|
428
|
+
] })
|
|
429
|
+
}
|
|
430
|
+
)
|
|
431
|
+
]
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
DragDropZone.displayName = "DragDropZone";
|
|
436
|
+
function CameraButton({
|
|
437
|
+
onCapture,
|
|
438
|
+
useFrontCamera = false,
|
|
439
|
+
disabled = false,
|
|
440
|
+
className
|
|
441
|
+
}) {
|
|
442
|
+
const inputRef = React2.useRef(null);
|
|
443
|
+
const handleClick = () => {
|
|
444
|
+
inputRef.current?.click();
|
|
445
|
+
};
|
|
446
|
+
const handleChange = (event) => {
|
|
447
|
+
const file = event.target.files?.[0];
|
|
448
|
+
if (file) {
|
|
449
|
+
onCapture(file);
|
|
450
|
+
}
|
|
451
|
+
event.target.value = "";
|
|
452
|
+
};
|
|
453
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
454
|
+
/* @__PURE__ */ jsx(
|
|
455
|
+
"input",
|
|
456
|
+
{
|
|
457
|
+
ref: inputRef,
|
|
458
|
+
type: "file",
|
|
459
|
+
accept: "image/*",
|
|
460
|
+
capture: useFrontCamera ? "user" : "environment",
|
|
461
|
+
onChange: handleChange,
|
|
462
|
+
disabled,
|
|
463
|
+
className: "sr-only",
|
|
464
|
+
"aria-label": "Take a photo"
|
|
465
|
+
}
|
|
466
|
+
),
|
|
467
|
+
/* @__PURE__ */ jsx(
|
|
468
|
+
"button",
|
|
469
|
+
{
|
|
470
|
+
type: "button",
|
|
471
|
+
onClick: handleClick,
|
|
472
|
+
disabled,
|
|
473
|
+
className: cn(
|
|
474
|
+
"inline-flex items-center justify-center",
|
|
475
|
+
"rounded-full p-2",
|
|
476
|
+
"text-neutral-500 hover:text-neutral-700",
|
|
477
|
+
"dark:text-neutral-400 dark:hover:text-neutral-200",
|
|
478
|
+
"hover:bg-neutral-100 dark:hover:bg-neutral-800",
|
|
479
|
+
"focus:ring-primary-500 focus:ring-2 focus:outline-none",
|
|
480
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
481
|
+
"transition-colors",
|
|
482
|
+
className
|
|
483
|
+
),
|
|
484
|
+
"aria-label": "Take a photo",
|
|
485
|
+
children: /* @__PURE__ */ jsxs(
|
|
486
|
+
"svg",
|
|
487
|
+
{
|
|
488
|
+
"aria-hidden": "true",
|
|
489
|
+
className: "h-5 w-5",
|
|
490
|
+
fill: "none",
|
|
491
|
+
viewBox: "0 0 24 24",
|
|
492
|
+
stroke: "currentColor",
|
|
493
|
+
children: [
|
|
494
|
+
/* @__PURE__ */ jsx(
|
|
495
|
+
"path",
|
|
496
|
+
{
|
|
497
|
+
strokeLinecap: "round",
|
|
498
|
+
strokeLinejoin: "round",
|
|
499
|
+
strokeWidth: 2,
|
|
500
|
+
d: "M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"
|
|
501
|
+
}
|
|
502
|
+
),
|
|
503
|
+
/* @__PURE__ */ jsx(
|
|
504
|
+
"path",
|
|
505
|
+
{
|
|
506
|
+
strokeLinecap: "round",
|
|
507
|
+
strokeLinejoin: "round",
|
|
508
|
+
strokeWidth: 2,
|
|
509
|
+
d: "M15 13a3 3 0 11-6 0 3 3 0 016 0z"
|
|
510
|
+
}
|
|
511
|
+
)
|
|
512
|
+
]
|
|
513
|
+
}
|
|
514
|
+
)
|
|
515
|
+
}
|
|
516
|
+
)
|
|
517
|
+
] });
|
|
518
|
+
}
|
|
519
|
+
CameraButton.displayName = "CameraButton";
|
|
520
|
+
function activeMentionQuery(value, caret) {
|
|
521
|
+
const upToCaret = value.slice(0, caret);
|
|
522
|
+
const match = /(^|\s)@([^\s@]*)$/.exec(upToCaret);
|
|
523
|
+
if (!match) return null;
|
|
524
|
+
const query = match[2];
|
|
525
|
+
return { query, start: caret - query.length - 1 };
|
|
526
|
+
}
|
|
527
|
+
function isFileAccepted(file, accepted) {
|
|
528
|
+
if (!accepted || accepted.length === 0) return true;
|
|
529
|
+
const mime = file.type;
|
|
530
|
+
const name = file.name.toLowerCase();
|
|
531
|
+
return accepted.some((token) => {
|
|
532
|
+
if (token.startsWith(".")) return name.endsWith(token.toLowerCase());
|
|
533
|
+
if (token.endsWith("/*")) return mime.startsWith(token.slice(0, -1));
|
|
534
|
+
if (token.includes("/")) return mime === token;
|
|
535
|
+
return false;
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
function CharacterCounter({
|
|
539
|
+
current,
|
|
540
|
+
max,
|
|
541
|
+
showWarningAt = 0.9,
|
|
542
|
+
className
|
|
543
|
+
}) {
|
|
544
|
+
const percentage = current / max;
|
|
545
|
+
const isWarning = percentage >= showWarningAt && percentage < 1;
|
|
546
|
+
const isOver = current > max;
|
|
547
|
+
return /* @__PURE__ */ jsxs(
|
|
548
|
+
"span",
|
|
549
|
+
{
|
|
550
|
+
className: cn(
|
|
551
|
+
"text-xs tabular-nums",
|
|
552
|
+
isOver ? "font-medium text-red-700 dark:text-red-400" : isWarning ? "text-amber-700 dark:text-amber-400" : "text-neutral-600 dark:text-neutral-400",
|
|
553
|
+
className
|
|
554
|
+
),
|
|
555
|
+
"aria-live": "polite",
|
|
556
|
+
"aria-label": `${current} of ${max} characters`,
|
|
557
|
+
children: [
|
|
558
|
+
current,
|
|
559
|
+
"/",
|
|
560
|
+
max
|
|
561
|
+
]
|
|
562
|
+
}
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
CharacterCounter.displayName = "CharacterCounter";
|
|
566
|
+
var sendButtonVariants = cva(
|
|
567
|
+
[
|
|
568
|
+
"inline-flex items-center justify-center",
|
|
569
|
+
"rounded-full p-3 self-start",
|
|
570
|
+
"transition-all duration-200",
|
|
571
|
+
"focus:outline-none focus:ring-2 focus:ring-primary-500",
|
|
572
|
+
"disabled:opacity-50 disabled:cursor-not-allowed"
|
|
573
|
+
],
|
|
574
|
+
{
|
|
575
|
+
variants: {
|
|
576
|
+
variant: {
|
|
577
|
+
primary: [
|
|
578
|
+
"bg-primary-800 text-white",
|
|
579
|
+
"hover:bg-primary-900",
|
|
580
|
+
"active:scale-95"
|
|
581
|
+
],
|
|
582
|
+
subtle: [
|
|
583
|
+
"bg-transparent text-primary-800",
|
|
584
|
+
"hover:bg-primary-50 dark:hover:bg-primary-900/20"
|
|
585
|
+
]
|
|
586
|
+
},
|
|
587
|
+
canSend: {
|
|
588
|
+
true: "",
|
|
589
|
+
false: "opacity-50 cursor-not-allowed"
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
defaultVariants: {
|
|
593
|
+
variant: "primary",
|
|
594
|
+
canSend: false
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
);
|
|
598
|
+
var SendButton = React2.forwardRef(
|
|
599
|
+
({ className, variant, canSend, isLoading, disabled, ...props }, ref) => {
|
|
600
|
+
return /* @__PURE__ */ jsx(
|
|
601
|
+
"button",
|
|
602
|
+
{
|
|
603
|
+
ref,
|
|
604
|
+
type: "submit",
|
|
605
|
+
disabled: disabled || !canSend || isLoading,
|
|
606
|
+
"data-slot": "composer-send-button",
|
|
607
|
+
className: cn(sendButtonVariants({ variant, canSend }), className),
|
|
608
|
+
"aria-label": isLoading ? "Sending message" : "Send message",
|
|
609
|
+
...props,
|
|
610
|
+
children: isLoading ? /* @__PURE__ */ jsxs(
|
|
611
|
+
"svg",
|
|
612
|
+
{
|
|
613
|
+
"aria-hidden": "true",
|
|
614
|
+
className: "h-5 w-5 animate-spin",
|
|
615
|
+
fill: "none",
|
|
616
|
+
viewBox: "0 0 24 24",
|
|
617
|
+
children: [
|
|
618
|
+
/* @__PURE__ */ jsx(
|
|
619
|
+
"circle",
|
|
620
|
+
{
|
|
621
|
+
className: "opacity-25",
|
|
622
|
+
cx: "12",
|
|
623
|
+
cy: "12",
|
|
624
|
+
r: "10",
|
|
625
|
+
stroke: "currentColor",
|
|
626
|
+
strokeWidth: "4"
|
|
627
|
+
}
|
|
628
|
+
),
|
|
629
|
+
/* @__PURE__ */ jsx(
|
|
630
|
+
"path",
|
|
631
|
+
{
|
|
632
|
+
className: "opacity-75",
|
|
633
|
+
fill: "currentColor",
|
|
634
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
|
635
|
+
}
|
|
636
|
+
)
|
|
637
|
+
]
|
|
638
|
+
}
|
|
639
|
+
) : /* @__PURE__ */ jsx(
|
|
640
|
+
"svg",
|
|
641
|
+
{
|
|
642
|
+
"aria-hidden": "true",
|
|
643
|
+
className: "h-5 w-5",
|
|
644
|
+
fill: "none",
|
|
645
|
+
viewBox: "0 0 24 24",
|
|
646
|
+
stroke: "currentColor",
|
|
647
|
+
children: /* @__PURE__ */ jsx(
|
|
648
|
+
"path",
|
|
649
|
+
{
|
|
650
|
+
strokeLinecap: "round",
|
|
651
|
+
strokeLinejoin: "round",
|
|
652
|
+
strokeWidth: 2,
|
|
653
|
+
d: "M12 19l9 2-9-18-9 18 9-2zm0 0v-8"
|
|
654
|
+
}
|
|
655
|
+
)
|
|
656
|
+
}
|
|
657
|
+
)
|
|
658
|
+
}
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
SendButton.displayName = "SendButton";
|
|
663
|
+
var MessageComposer = React2.forwardRef(
|
|
664
|
+
({
|
|
665
|
+
onSend,
|
|
666
|
+
onTypingStart,
|
|
667
|
+
onTypingStop,
|
|
668
|
+
value: controlledValue,
|
|
669
|
+
onValueChange,
|
|
670
|
+
placeholder = "Type a message...",
|
|
671
|
+
maxLength = 1600,
|
|
672
|
+
showCharacterCount = false,
|
|
673
|
+
disabled = false,
|
|
674
|
+
isSending = false,
|
|
675
|
+
showAttachmentPicker = true,
|
|
676
|
+
showCameraButton = false,
|
|
677
|
+
acceptedFileTypes = ["image/*", "video/*", ".pdf", ".doc", ".docx"],
|
|
678
|
+
maxFileSize = 25 * 1024 * 1024,
|
|
679
|
+
maxAttachments = 10,
|
|
680
|
+
onError,
|
|
681
|
+
autoFocus = false,
|
|
682
|
+
replyTo = null,
|
|
683
|
+
onCancelReply,
|
|
684
|
+
variant = "default",
|
|
685
|
+
inputTrailing,
|
|
686
|
+
mentionOptions,
|
|
687
|
+
className
|
|
688
|
+
}, ref) => {
|
|
689
|
+
const textareaRef = React2.useRef(null);
|
|
690
|
+
const [internalContent, setInternalContent] = React2.useState("");
|
|
691
|
+
const isControlled = controlledValue !== void 0;
|
|
692
|
+
const content = isControlled ? controlledValue : internalContent;
|
|
693
|
+
const setContent = React2.useCallback(
|
|
694
|
+
(val) => {
|
|
695
|
+
if (isControlled) {
|
|
696
|
+
const newVal = typeof val === "function" ? val(controlledValue) : val;
|
|
697
|
+
onValueChange?.(newVal);
|
|
698
|
+
} else {
|
|
699
|
+
setInternalContent(val);
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
[isControlled, controlledValue, onValueChange]
|
|
703
|
+
);
|
|
704
|
+
const [attachments, setAttachments] = React2.useState(
|
|
705
|
+
[]
|
|
706
|
+
);
|
|
707
|
+
const [isTyping, setIsTyping] = React2.useState(false);
|
|
708
|
+
const typingTimeoutRef = React2.useRef(null);
|
|
709
|
+
React2.useImperativeHandle(ref, () => textareaRef.current);
|
|
710
|
+
React2.useEffect(() => {
|
|
711
|
+
const textarea = textareaRef.current;
|
|
712
|
+
if (textarea) {
|
|
713
|
+
textarea.style.height = "auto";
|
|
714
|
+
textarea.style.height = `${Math.min(textarea.scrollHeight, 150)}px`;
|
|
715
|
+
}
|
|
716
|
+
}, [content]);
|
|
717
|
+
React2.useEffect(() => {
|
|
718
|
+
if (content.length > 0 && !isTyping) {
|
|
719
|
+
setIsTyping(true);
|
|
720
|
+
onTypingStart?.();
|
|
721
|
+
}
|
|
722
|
+
if (typingTimeoutRef.current) {
|
|
723
|
+
clearTimeout(typingTimeoutRef.current);
|
|
724
|
+
}
|
|
725
|
+
typingTimeoutRef.current = setTimeout(() => {
|
|
726
|
+
if (isTyping) {
|
|
727
|
+
setIsTyping(false);
|
|
728
|
+
onTypingStop?.();
|
|
729
|
+
}
|
|
730
|
+
}, 2e3);
|
|
731
|
+
return () => {
|
|
732
|
+
if (typingTimeoutRef.current) {
|
|
733
|
+
clearTimeout(typingTimeoutRef.current);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
}, [content, isTyping, onTypingStart, onTypingStop]);
|
|
737
|
+
React2.useEffect(() => {
|
|
738
|
+
if (autoFocus) {
|
|
739
|
+
textareaRef.current?.focus();
|
|
740
|
+
}
|
|
741
|
+
}, [autoFocus]);
|
|
742
|
+
React2.useEffect(() => {
|
|
743
|
+
if (replyTo) {
|
|
744
|
+
textareaRef.current?.focus();
|
|
745
|
+
}
|
|
746
|
+
}, [replyTo]);
|
|
747
|
+
const mentionsEnabled = !!mentionOptions && mentionOptions.length > 0;
|
|
748
|
+
const [mention, setMention] = React2.useState(null);
|
|
749
|
+
const [mentionHighlight, setMentionHighlight] = React2.useState(0);
|
|
750
|
+
const mentionListId = React2.useId();
|
|
751
|
+
const mentionOptionId = (i) => `${mentionListId}-option-${i}`;
|
|
752
|
+
const mentionSuggestions = React2.useMemo(() => {
|
|
753
|
+
if (!mention || !mentionOptions) return [];
|
|
754
|
+
const q = mention.query.toLowerCase();
|
|
755
|
+
return mentionOptions.filter((o) => o.label.toLowerCase().includes(q));
|
|
756
|
+
}, [mention, mentionOptions]);
|
|
757
|
+
const mentionMenuOpen = mentionsEnabled && mention !== null && mentionSuggestions.length > 0;
|
|
758
|
+
const clampedMentionHighlight = mentionMenuOpen ? Math.min(mentionHighlight, mentionSuggestions.length - 1) : -1;
|
|
759
|
+
const activeMentionOptionId = mentionMenuOpen ? mentionOptionId(clampedMentionHighlight) : void 0;
|
|
760
|
+
const syncMention = React2.useCallback(
|
|
761
|
+
(value, caret) => {
|
|
762
|
+
if (!mentionsEnabled) return;
|
|
763
|
+
setMention(activeMentionQuery(value, caret));
|
|
764
|
+
setMentionHighlight(0);
|
|
765
|
+
},
|
|
766
|
+
[mentionsEnabled]
|
|
767
|
+
);
|
|
768
|
+
const insertMention = (option) => {
|
|
769
|
+
if (!mention) return;
|
|
770
|
+
const insertValue = option.value ?? option.label.split(" ")[0];
|
|
771
|
+
const before = content.slice(0, mention.start);
|
|
772
|
+
const after = content.slice(mention.start + 1 + mention.query.length);
|
|
773
|
+
const insert = `@${insertValue} `;
|
|
774
|
+
setContent(before + insert + after);
|
|
775
|
+
setMention(null);
|
|
776
|
+
const caret = before.length + insert.length;
|
|
777
|
+
requestAnimationFrame(() => {
|
|
778
|
+
const el = textareaRef.current;
|
|
779
|
+
if (el) {
|
|
780
|
+
el.focus();
|
|
781
|
+
el.setSelectionRange(caret, caret);
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
};
|
|
785
|
+
const canSend = (content.trim().length > 0 || attachments.length > 0) && content.length <= maxLength && !disabled && !isSending;
|
|
786
|
+
const handleSubmit = async (event) => {
|
|
787
|
+
event.preventDefault();
|
|
788
|
+
if (!canSend) return;
|
|
789
|
+
const message = {
|
|
790
|
+
content: content.trim(),
|
|
791
|
+
attachments: attachments.map((a) => a.file),
|
|
792
|
+
replyToId: replyTo?.id
|
|
793
|
+
};
|
|
794
|
+
setContent("");
|
|
795
|
+
setAttachments([]);
|
|
796
|
+
setIsTyping(false);
|
|
797
|
+
onTypingStop?.();
|
|
798
|
+
try {
|
|
799
|
+
await onSend(message);
|
|
800
|
+
} catch {
|
|
801
|
+
setContent(message.content);
|
|
802
|
+
onError?.("Failed to send message");
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
const handleKeyDown = (event) => {
|
|
806
|
+
if (mentionMenuOpen) {
|
|
807
|
+
if (event.key === "ArrowDown") {
|
|
808
|
+
event.preventDefault();
|
|
809
|
+
setMentionHighlight((h) => (h + 1) % mentionSuggestions.length);
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
if (event.key === "ArrowUp") {
|
|
813
|
+
event.preventDefault();
|
|
814
|
+
setMentionHighlight(
|
|
815
|
+
(h) => (h - 1 + mentionSuggestions.length) % mentionSuggestions.length
|
|
816
|
+
);
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
if (event.key === "Enter" || event.key === "Tab") {
|
|
820
|
+
event.preventDefault();
|
|
821
|
+
const chosen = mentionSuggestions[mentionHighlight] ?? mentionSuggestions[0];
|
|
822
|
+
if (chosen) insertMention(chosen);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
if (event.key === "Escape") {
|
|
826
|
+
event.preventDefault();
|
|
827
|
+
setMention(null);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
832
|
+
event.preventDefault();
|
|
833
|
+
if (canSend) {
|
|
834
|
+
handleSubmit(event);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
const handleFilesSelected = (files) => {
|
|
839
|
+
const remainingSlots = maxAttachments - attachments.length;
|
|
840
|
+
const filesToAdd = files.slice(0, remainingSlots);
|
|
841
|
+
if (files.length > remainingSlots) {
|
|
842
|
+
onError?.(`Maximum ${maxAttachments} attachments allowed`);
|
|
843
|
+
}
|
|
844
|
+
const newAttachments = filesToAdd.map((file) => {
|
|
845
|
+
const type = getFileType(file.type);
|
|
846
|
+
let previewUrl;
|
|
847
|
+
if (type === "image" || type === "video") {
|
|
848
|
+
previewUrl = URL.createObjectURL(file);
|
|
849
|
+
}
|
|
850
|
+
return {
|
|
851
|
+
id: generateAttachmentId(),
|
|
852
|
+
file,
|
|
853
|
+
previewUrl,
|
|
854
|
+
type,
|
|
855
|
+
state: "pending"
|
|
856
|
+
};
|
|
857
|
+
});
|
|
858
|
+
setAttachments((prev) => [...prev, ...newAttachments]);
|
|
859
|
+
};
|
|
860
|
+
const handlePaste = (event) => {
|
|
861
|
+
if (!showAttachmentPicker || disabled) return;
|
|
862
|
+
const pasted = Array.from(event.clipboardData.items).filter((item) => item.kind === "file").map((item) => item.getAsFile()).filter((f) => f !== null).filter((f) => isFileAccepted(f, acceptedFileTypes));
|
|
863
|
+
if (pasted.length === 0) return;
|
|
864
|
+
event.preventDefault();
|
|
865
|
+
handleFilesSelected(pasted);
|
|
866
|
+
};
|
|
867
|
+
const handleRemoveAttachment = (attachmentId) => {
|
|
868
|
+
setAttachments((prev) => {
|
|
869
|
+
const attachment = prev.find((a) => a.id === attachmentId);
|
|
870
|
+
if (attachment?.previewUrl) {
|
|
871
|
+
URL.revokeObjectURL(attachment.previewUrl);
|
|
872
|
+
}
|
|
873
|
+
return prev.filter((a) => a.id !== attachmentId);
|
|
874
|
+
});
|
|
875
|
+
};
|
|
876
|
+
React2.useEffect(() => {
|
|
877
|
+
const currentAttachments = attachments;
|
|
878
|
+
return () => {
|
|
879
|
+
currentAttachments.forEach((a) => {
|
|
880
|
+
if (a.previewUrl) {
|
|
881
|
+
URL.revokeObjectURL(a.previewUrl);
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
};
|
|
885
|
+
}, [attachments]);
|
|
886
|
+
return /* @__PURE__ */ jsx(
|
|
887
|
+
DragDropZone,
|
|
888
|
+
{
|
|
889
|
+
onFilesDropped: handleFilesSelected,
|
|
890
|
+
acceptedTypes: acceptedFileTypes,
|
|
891
|
+
maxFileSize,
|
|
892
|
+
maxFiles: maxAttachments - attachments.length,
|
|
893
|
+
disabled: disabled || attachments.length >= maxAttachments,
|
|
894
|
+
onError,
|
|
895
|
+
className: cn("w-full", className),
|
|
896
|
+
children: /* @__PURE__ */ jsxs(
|
|
897
|
+
"form",
|
|
898
|
+
{
|
|
899
|
+
onSubmit: handleSubmit,
|
|
900
|
+
"data-slot": "message-composer",
|
|
901
|
+
className: "w-full",
|
|
902
|
+
children: [
|
|
903
|
+
replyTo && /* @__PURE__ */ jsxs(
|
|
904
|
+
"div",
|
|
905
|
+
{
|
|
906
|
+
"data-slot": "composer-reply-preview",
|
|
907
|
+
className: cn(
|
|
908
|
+
"flex items-center gap-2 px-4 py-2",
|
|
909
|
+
"bg-neutral-50 dark:bg-neutral-800/50",
|
|
910
|
+
"border-primary-500 border-l-4"
|
|
911
|
+
),
|
|
912
|
+
children: [
|
|
913
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
914
|
+
/* @__PURE__ */ jsxs("span", { className: "text-primary-800 dark:text-primary-400 text-xs font-medium", children: [
|
|
915
|
+
"Replying to ",
|
|
916
|
+
replyTo.senderName
|
|
917
|
+
] }),
|
|
918
|
+
/* @__PURE__ */ jsx("p", { className: "truncate text-sm text-neutral-600 dark:text-neutral-300", children: replyTo.content })
|
|
919
|
+
] }),
|
|
920
|
+
/* @__PURE__ */ jsx(
|
|
921
|
+
"button",
|
|
922
|
+
{
|
|
923
|
+
type: "button",
|
|
924
|
+
onClick: onCancelReply,
|
|
925
|
+
className: cn(
|
|
926
|
+
"shrink-0 rounded p-1",
|
|
927
|
+
"text-neutral-500 hover:text-neutral-700",
|
|
928
|
+
"dark:text-neutral-400 dark:hover:text-neutral-200",
|
|
929
|
+
"focus:ring-primary-500 focus:ring-2 focus:outline-none"
|
|
930
|
+
),
|
|
931
|
+
"aria-label": "Cancel reply",
|
|
932
|
+
children: /* @__PURE__ */ jsx(
|
|
933
|
+
"svg",
|
|
934
|
+
{
|
|
935
|
+
"aria-hidden": "true",
|
|
936
|
+
className: "h-4 w-4",
|
|
937
|
+
fill: "none",
|
|
938
|
+
viewBox: "0 0 24 24",
|
|
939
|
+
stroke: "currentColor",
|
|
940
|
+
children: /* @__PURE__ */ jsx(
|
|
941
|
+
"path",
|
|
942
|
+
{
|
|
943
|
+
strokeLinecap: "round",
|
|
944
|
+
strokeLinejoin: "round",
|
|
945
|
+
strokeWidth: 2,
|
|
946
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
947
|
+
}
|
|
948
|
+
)
|
|
949
|
+
}
|
|
950
|
+
)
|
|
951
|
+
}
|
|
952
|
+
)
|
|
953
|
+
]
|
|
954
|
+
}
|
|
955
|
+
),
|
|
956
|
+
attachments.length > 0 && /* @__PURE__ */ jsx(
|
|
957
|
+
"div",
|
|
958
|
+
{
|
|
959
|
+
"data-slot": "composer-attachments",
|
|
960
|
+
className: cn(
|
|
961
|
+
"flex flex-wrap gap-2 p-3",
|
|
962
|
+
"border-t border-neutral-200 dark:border-neutral-700"
|
|
963
|
+
),
|
|
964
|
+
children: attachments.map((attachment) => /* @__PURE__ */ jsx(
|
|
965
|
+
AttachmentPreviewItem,
|
|
966
|
+
{
|
|
967
|
+
attachment,
|
|
968
|
+
onRemove: () => handleRemoveAttachment(attachment.id)
|
|
969
|
+
},
|
|
970
|
+
attachment.id
|
|
971
|
+
))
|
|
972
|
+
}
|
|
973
|
+
),
|
|
974
|
+
/* @__PURE__ */ jsxs(
|
|
975
|
+
"div",
|
|
976
|
+
{
|
|
977
|
+
"data-slot": "composer-input-area",
|
|
978
|
+
className: cn(
|
|
979
|
+
"flex items-center gap-2 p-3",
|
|
980
|
+
"bg-white dark:bg-neutral-900",
|
|
981
|
+
variant === "default" && "border-t border-neutral-200 dark:border-neutral-700"
|
|
982
|
+
),
|
|
983
|
+
children: [
|
|
984
|
+
showAttachmentPicker && /* @__PURE__ */ jsx(
|
|
985
|
+
AttachmentPicker,
|
|
986
|
+
{
|
|
987
|
+
onFilesSelected: handleFilesSelected,
|
|
988
|
+
acceptedTypes: acceptedFileTypes,
|
|
989
|
+
maxFileSize,
|
|
990
|
+
maxFiles: maxAttachments - attachments.length,
|
|
991
|
+
disabled: disabled || attachments.length >= maxAttachments,
|
|
992
|
+
onError
|
|
993
|
+
}
|
|
994
|
+
),
|
|
995
|
+
showCameraButton && /* @__PURE__ */ jsx(
|
|
996
|
+
CameraButton,
|
|
997
|
+
{
|
|
998
|
+
onCapture: (file) => handleFilesSelected([file]),
|
|
999
|
+
disabled: disabled || attachments.length >= maxAttachments
|
|
1000
|
+
}
|
|
1001
|
+
),
|
|
1002
|
+
/* @__PURE__ */ jsxs("div", { "data-slot": "composer-input-wrapper", className: "relative flex-1", children: [
|
|
1003
|
+
mentionMenuOpen && /* @__PURE__ */ jsx(
|
|
1004
|
+
"ul",
|
|
1005
|
+
{
|
|
1006
|
+
id: mentionListId,
|
|
1007
|
+
role: "listbox",
|
|
1008
|
+
"aria-label": "Mention",
|
|
1009
|
+
"data-slot": "composer-mention-list",
|
|
1010
|
+
className: "absolute bottom-full left-0 z-10 mb-1 max-h-56 w-64 overflow-y-auto rounded-lg border border-neutral-200 bg-white py-1 shadow-lg dark:border-neutral-700 dark:bg-neutral-800",
|
|
1011
|
+
children: mentionSuggestions.map((option, i) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
1012
|
+
"button",
|
|
1013
|
+
{
|
|
1014
|
+
type: "button",
|
|
1015
|
+
id: mentionOptionId(i),
|
|
1016
|
+
role: "option",
|
|
1017
|
+
"aria-selected": i === clampedMentionHighlight,
|
|
1018
|
+
onMouseDown: (e) => {
|
|
1019
|
+
e.preventDefault();
|
|
1020
|
+
insertMention(option);
|
|
1021
|
+
},
|
|
1022
|
+
onMouseEnter: () => setMentionHighlight(i),
|
|
1023
|
+
className: cn(
|
|
1024
|
+
"flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm",
|
|
1025
|
+
i === clampedMentionHighlight ? "bg-primary-100 text-primary-900 dark:bg-primary-900/40 dark:text-primary-100" : "text-neutral-700 dark:text-neutral-200"
|
|
1026
|
+
),
|
|
1027
|
+
children: [
|
|
1028
|
+
option.icon,
|
|
1029
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1 truncate", children: [
|
|
1030
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: option.label }),
|
|
1031
|
+
option.description && /* @__PURE__ */ jsx("span", { className: "ml-1 text-xs text-neutral-400", children: option.description })
|
|
1032
|
+
] }),
|
|
1033
|
+
option.meta && /* @__PURE__ */ jsx("span", { className: "text-[10px] text-neutral-400", children: option.meta })
|
|
1034
|
+
]
|
|
1035
|
+
}
|
|
1036
|
+
) }, option.id))
|
|
1037
|
+
}
|
|
1038
|
+
),
|
|
1039
|
+
/* @__PURE__ */ jsx(
|
|
1040
|
+
"textarea",
|
|
1041
|
+
{
|
|
1042
|
+
ref: textareaRef,
|
|
1043
|
+
"data-slot": "composer-input",
|
|
1044
|
+
value: content,
|
|
1045
|
+
onChange: (e) => {
|
|
1046
|
+
setContent(e.target.value);
|
|
1047
|
+
syncMention(
|
|
1048
|
+
e.target.value,
|
|
1049
|
+
e.target.selectionStart ?? e.target.value.length
|
|
1050
|
+
);
|
|
1051
|
+
},
|
|
1052
|
+
onClick: (e) => {
|
|
1053
|
+
const el = e.currentTarget;
|
|
1054
|
+
syncMention(el.value, el.selectionStart ?? el.value.length);
|
|
1055
|
+
},
|
|
1056
|
+
onKeyDown: handleKeyDown,
|
|
1057
|
+
onPaste: handlePaste,
|
|
1058
|
+
placeholder,
|
|
1059
|
+
disabled: disabled || isSending,
|
|
1060
|
+
rows: 1,
|
|
1061
|
+
className: cn(
|
|
1062
|
+
"w-full resize-none rounded-2xl py-2.5",
|
|
1063
|
+
inputTrailing ? "pr-10 pl-4" : "px-4",
|
|
1064
|
+
"bg-neutral-100 dark:bg-neutral-800",
|
|
1065
|
+
"text-neutral-900 dark:text-neutral-100",
|
|
1066
|
+
"placeholder:text-neutral-400 dark:placeholder:text-neutral-500",
|
|
1067
|
+
"focus:ring-primary-500 focus:ring-2 focus:outline-none",
|
|
1068
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
1069
|
+
"transition-colors",
|
|
1070
|
+
"max-h-[150px]"
|
|
1071
|
+
),
|
|
1072
|
+
"aria-label": "Message",
|
|
1073
|
+
"aria-describedby": showCharacterCount ? "char-count" : void 0,
|
|
1074
|
+
...mentionsEnabled ? {
|
|
1075
|
+
role: "combobox",
|
|
1076
|
+
"aria-expanded": mentionMenuOpen,
|
|
1077
|
+
"aria-controls": mentionMenuOpen ? mentionListId : void 0,
|
|
1078
|
+
"aria-activedescendant": activeMentionOptionId,
|
|
1079
|
+
"aria-autocomplete": "list",
|
|
1080
|
+
"aria-haspopup": "listbox"
|
|
1081
|
+
} : {}
|
|
1082
|
+
}
|
|
1083
|
+
),
|
|
1084
|
+
inputTrailing && /* @__PURE__ */ jsx(
|
|
1085
|
+
"div",
|
|
1086
|
+
{
|
|
1087
|
+
"data-slot": "composer-input-trailing",
|
|
1088
|
+
className: "pointer-events-none absolute top-0 right-1 flex h-[44px] items-center [&>*]:pointer-events-auto",
|
|
1089
|
+
children: inputTrailing
|
|
1090
|
+
}
|
|
1091
|
+
),
|
|
1092
|
+
showCharacterCount && /* @__PURE__ */ jsx(
|
|
1093
|
+
"div",
|
|
1094
|
+
{
|
|
1095
|
+
"data-slot": "composer-char-count",
|
|
1096
|
+
id: "char-count",
|
|
1097
|
+
className: "absolute right-3 bottom-1.5",
|
|
1098
|
+
children: /* @__PURE__ */ jsx(CharacterCounter, { current: content.length, max: maxLength })
|
|
1099
|
+
}
|
|
1100
|
+
)
|
|
1101
|
+
] }),
|
|
1102
|
+
/* @__PURE__ */ jsx(
|
|
1103
|
+
SendButton,
|
|
1104
|
+
{
|
|
1105
|
+
canSend,
|
|
1106
|
+
isLoading: isSending,
|
|
1107
|
+
disabled
|
|
1108
|
+
}
|
|
1109
|
+
)
|
|
1110
|
+
]
|
|
1111
|
+
}
|
|
1112
|
+
)
|
|
1113
|
+
]
|
|
1114
|
+
}
|
|
1115
|
+
)
|
|
1116
|
+
}
|
|
1117
|
+
);
|
|
1118
|
+
}
|
|
1119
|
+
);
|
|
1120
|
+
MessageComposer.displayName = "MessageComposer";
|
|
1121
|
+
|
|
1122
|
+
export { AttachmentPicker, AttachmentPreviewItem, CameraButton, CharacterCounter, DragDropZone, MessageComposer, SendButton, generateAttachmentId, getFileType, sendButtonVariants, validateFile };
|
|
1123
|
+
//# sourceMappingURL=chunk-UHPQYBXQ.js.map
|
|
1124
|
+
//# sourceMappingURL=chunk-UHPQYBXQ.js.map
|