reachat 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ChatInput/ChatInput.d.ts +1 -1
- package/dist/docs.json +1 -1
- package/dist/index.js +60 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +60 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +1 -1
package/dist/docs.json
CHANGED
package/dist/index.js
CHANGED
|
@@ -1351,10 +1351,69 @@ const MessageFile = ({
|
|
|
1351
1351
|
const MessageFiles = ({ files, children }) => {
|
|
1352
1352
|
const { theme } = useContext(ChatContext);
|
|
1353
1353
|
const Comp = children ? Slot : MessageFile;
|
|
1354
|
+
const [expanded, setExpanded] = useState(false);
|
|
1354
1355
|
if (!files || files.length === 0) {
|
|
1355
1356
|
return null;
|
|
1356
1357
|
}
|
|
1357
|
-
|
|
1358
|
+
const { imageFiles, otherFiles } = files.reduce(
|
|
1359
|
+
(acc, file) => {
|
|
1360
|
+
if (file.type.startsWith("image/")) {
|
|
1361
|
+
acc.imageFiles.push(file);
|
|
1362
|
+
} else {
|
|
1363
|
+
acc.otherFiles.push(file);
|
|
1364
|
+
}
|
|
1365
|
+
return acc;
|
|
1366
|
+
},
|
|
1367
|
+
{
|
|
1368
|
+
imageFiles: [],
|
|
1369
|
+
otherFiles: []
|
|
1370
|
+
}
|
|
1371
|
+
);
|
|
1372
|
+
const maxImageLength = 3;
|
|
1373
|
+
const truncateImages = !expanded && imageFiles.length > maxImageLength;
|
|
1374
|
+
const renderImageFiles = (images) => {
|
|
1375
|
+
return truncateImages ? images.slice(0, maxImageLength).map((image, index) => /* @__PURE__ */ jsxs(
|
|
1376
|
+
"figure",
|
|
1377
|
+
{
|
|
1378
|
+
className: index === 0 ? "col-span-2 row-span-2" : "relative",
|
|
1379
|
+
children: [
|
|
1380
|
+
/* @__PURE__ */ jsx(
|
|
1381
|
+
"img",
|
|
1382
|
+
{
|
|
1383
|
+
src: image.url,
|
|
1384
|
+
alt: image.name,
|
|
1385
|
+
className: "relative w-full h-full object-cover rounded-lg"
|
|
1386
|
+
}
|
|
1387
|
+
),
|
|
1388
|
+
index === maxImageLength - 1 && /* @__PURE__ */ jsxs(
|
|
1389
|
+
"div",
|
|
1390
|
+
{
|
|
1391
|
+
className: "absolute top-0 left-0 w-full h-full flex justify-center items-center bg-black bg-opacity-50 rounded-lg cursor-pointer",
|
|
1392
|
+
onClick: () => setExpanded(true),
|
|
1393
|
+
children: [
|
|
1394
|
+
"+",
|
|
1395
|
+
(imageFiles.length - maxImageLength).toLocaleString()
|
|
1396
|
+
]
|
|
1397
|
+
}
|
|
1398
|
+
)
|
|
1399
|
+
]
|
|
1400
|
+
},
|
|
1401
|
+
index
|
|
1402
|
+
)) : images.map((image, index) => /* @__PURE__ */ jsx(Comp, { ...image, children }, index));
|
|
1403
|
+
};
|
|
1404
|
+
return /* @__PURE__ */ jsxs(
|
|
1405
|
+
"div",
|
|
1406
|
+
{
|
|
1407
|
+
className: cn(
|
|
1408
|
+
theme.messages.message.files.base,
|
|
1409
|
+
truncateImages ? "grid grid-rows-2 grid-flow-col gap-2 w-1/3" : ""
|
|
1410
|
+
),
|
|
1411
|
+
children: [
|
|
1412
|
+
imageFiles.length > 0 && renderImageFiles(imageFiles),
|
|
1413
|
+
otherFiles.length > 0 && otherFiles.map((file, index) => /* @__PURE__ */ jsx(Comp, { ...file, children }, index))
|
|
1414
|
+
]
|
|
1415
|
+
}
|
|
1416
|
+
);
|
|
1358
1417
|
};
|
|
1359
1418
|
const MessageQuestion = ({
|
|
1360
1419
|
children,
|