reachat 1.4.2 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,8 +11,8 @@
11
11
  }
12
12
  })();
13
13
  (function(global, factory) {
14
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("react"), require("reablocks"), require("@radix-ui/react-slot"), require("framer-motion"), require("react-markdown"), require("react-syntax-highlighter"), require("rehype-katex"), require("mdast-util-find-and-replace"), require("reakeys"), require("remark-gfm"), require("remark-youtube"), require("remark-math"), require("date-fns")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react", "reablocks", "@radix-ui/react-slot", "framer-motion", "react-markdown", "react-syntax-highlighter", "rehype-katex", "mdast-util-find-and-replace", "reakeys", "remark-gfm", "remark-youtube", "remark-math", "date-fns"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.reachat = {}, global.jsxRuntime, global.React, global.reablocks, global.reactSlot, global.framerMotion, global.ReactMarkdown, global.reactSyntaxHighlighter, global.rehypeKatex, global.mdastUtilFindAndReplace, global.reakeys, global.remarkGfm, global.remarkYoutube, global.remarkMath, global.dateFns));
15
- })(this, function(exports2, jsxRuntime, React, reablocks, reactSlot, framerMotion, ReactMarkdown, reactSyntaxHighlighter, rehypeKatex, mdastUtilFindAndReplace, reakeys, remarkGfm, remarkYoutube, remarkMath, dateFns) {
14
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("react"), require("reablocks"), require("@radix-ui/react-slot"), require("motion/react"), require("react-markdown"), require("react-syntax-highlighter"), require("rehype-katex"), require("mdast-util-find-and-replace"), require("reakeys"), require("remark-gfm"), require("remark-youtube"), require("remark-math"), require("date-fns")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react", "reablocks", "@radix-ui/react-slot", "motion/react", "react-markdown", "react-syntax-highlighter", "rehype-katex", "mdast-util-find-and-replace", "reakeys", "remark-gfm", "remark-youtube", "remark-math", "date-fns"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.reachat = {}, global.jsxRuntime, global.React, global.reablocks, global.reactSlot, global.react, global.ReactMarkdown, global.reactSyntaxHighlighter, global.rehypeKatex, global.mdastUtilFindAndReplace, global.reakeys, global.remarkGfm, global.remarkYoutube, global.remarkMath, global.dateFns));
15
+ })(this, function(exports2, jsxRuntime, React, reablocks, reactSlot, react, ReactMarkdown, reactSyntaxHighlighter, rehypeKatex, mdastUtilFindAndReplace, reakeys, remarkGfm, remarkYoutube, remarkMath, dateFns) {
16
16
  "use strict";
17
17
  function _interopNamespaceDefault(e) {
18
18
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -193,7 +193,7 @@
193
193
  const { activeSessionId, theme, isCompact, selectSession, viewType } = React.useContext(ChatContext);
194
194
  const isVisible = isCompact && activeSessionId || viewType === "chat" || !isCompact;
195
195
  return isVisible && /* @__PURE__ */ jsxRuntime.jsx(
196
- framerMotion.motion.div,
196
+ react.motion.div,
197
197
  {
198
198
  initial: { translateX: "200%" },
199
199
  animate: {
@@ -1357,10 +1357,69 @@
1357
1357
  const MessageFiles = ({ files, children }) => {
1358
1358
  const { theme } = React.useContext(ChatContext);
1359
1359
  const Comp = children ? reactSlot.Slot : MessageFile;
1360
+ const [expanded, setExpanded] = React.useState(false);
1360
1361
  if (!files || files.length === 0) {
1361
1362
  return null;
1362
1363
  }
1363
- return files.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: reablocks.cn(theme.messages.message.files.base), children: files.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...file, children }, index)) });
1364
+ const { imageFiles, otherFiles } = files.reduce(
1365
+ (acc, file) => {
1366
+ if (file.type.startsWith("image/")) {
1367
+ acc.imageFiles.push(file);
1368
+ } else {
1369
+ acc.otherFiles.push(file);
1370
+ }
1371
+ return acc;
1372
+ },
1373
+ {
1374
+ imageFiles: [],
1375
+ otherFiles: []
1376
+ }
1377
+ );
1378
+ const maxImageLength = 3;
1379
+ const truncateImages = !expanded && imageFiles.length > maxImageLength;
1380
+ const renderImageFiles = (images) => {
1381
+ return truncateImages ? images.slice(0, maxImageLength).map((image, index) => /* @__PURE__ */ jsxRuntime.jsxs(
1382
+ "figure",
1383
+ {
1384
+ className: index === 0 ? "col-span-2 row-span-2" : "relative",
1385
+ children: [
1386
+ /* @__PURE__ */ jsxRuntime.jsx(
1387
+ "img",
1388
+ {
1389
+ src: image.url,
1390
+ alt: image.name,
1391
+ className: "relative w-full h-full object-cover rounded-lg"
1392
+ }
1393
+ ),
1394
+ index === maxImageLength - 1 && /* @__PURE__ */ jsxRuntime.jsxs(
1395
+ "div",
1396
+ {
1397
+ className: "absolute top-0 left-0 w-full h-full flex justify-center items-center bg-black bg-opacity-50 rounded-lg cursor-pointer",
1398
+ onClick: () => setExpanded(true),
1399
+ children: [
1400
+ "+",
1401
+ (imageFiles.length - maxImageLength).toLocaleString()
1402
+ ]
1403
+ }
1404
+ )
1405
+ ]
1406
+ },
1407
+ index
1408
+ )) : images.map((image, index) => /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...image, children }, index));
1409
+ };
1410
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1411
+ "div",
1412
+ {
1413
+ className: reablocks.cn(
1414
+ theme.messages.message.files.base,
1415
+ truncateImages ? "grid grid-rows-2 grid-flow-col gap-2 w-1/3" : ""
1416
+ ),
1417
+ children: [
1418
+ imageFiles.length > 0 && renderImageFiles(imageFiles),
1419
+ otherFiles.length > 0 && otherFiles.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...file, children }, index))
1420
+ ]
1421
+ }
1422
+ );
1364
1423
  };
1365
1424
  const MessageQuestion = ({
1366
1425
  children,
@@ -1414,7 +1473,7 @@
1414
1473
  children: children || /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1415
1474
  /* @__PURE__ */ jsxRuntime.jsx(Markdown, { remarkPlugins, children: response }),
1416
1475
  isLoading && /* @__PURE__ */ jsxRuntime.jsx(
1417
- framerMotion.motion.div,
1476
+ react.motion.div,
1418
1477
  {
1419
1478
  className: reablocks.cn(theme.messages.message.cursor),
1420
1479
  animate: { opacity: [1, 0] },
@@ -1558,7 +1617,7 @@ ${response}`),
1558
1617
  children
1559
1618
  }) => {
1560
1619
  const { theme, isLoading } = React.useContext(ChatContext);
1561
- return /* @__PURE__ */ jsxRuntime.jsxs(framerMotion.motion.div, { variants: messageVariants, children: [
1620
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.motion.div, { variants: messageVariants, children: [
1562
1621
  /* @__PURE__ */ jsxRuntime.jsx(reablocks.Card, { className: reablocks.cn(theme.messages.message.base), children: children || /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1563
1622
  /* @__PURE__ */ jsxRuntime.jsx(MessageQuestion, { question: conversation.question, files: conversation.files }),
1564
1623
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1633,8 +1692,8 @@ ${response}`),
1633
1692
  children: showMoreText
1634
1693
  }
1635
1694
  ),
1636
- /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: /* @__PURE__ */ jsxRuntime.jsx(
1637
- framerMotion.motion.div,
1695
+ /* @__PURE__ */ jsxRuntime.jsx(react.AnimatePresence, { children: /* @__PURE__ */ jsxRuntime.jsx(
1696
+ react.motion.div,
1638
1697
  {
1639
1698
  variants: containerVariants,
1640
1699
  initial: "hidden",
@@ -1884,7 +1943,7 @@ ${response}`),
1884
1943
  onFileUpload
1885
1944
  ]
1886
1945
  );
1887
- return /* @__PURE__ */ jsxRuntime.jsx(ChatContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { initial: false, children: /* @__PURE__ */ jsxRuntime.jsx(
1946
+ return /* @__PURE__ */ jsxRuntime.jsx(ChatContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(react.AnimatePresence, { initial: false, children: /* @__PURE__ */ jsxRuntime.jsx(
1888
1947
  "div",
1889
1948
  {
1890
1949
  ref: observe,
@@ -1901,7 +1960,7 @@ ${response}`),
1901
1960
  const { theme, isCompact, activeSessionId } = React.useContext(ChatContext);
1902
1961
  const isVisible = isCompact && !activeSessionId;
1903
1962
  return (!isCompact || isVisible) && /* @__PURE__ */ jsxRuntime.jsx(
1904
- framerMotion.motion.div,
1963
+ react.motion.div,
1905
1964
  {
1906
1965
  initial: { translateX: "-100%" },
1907
1966
  animate: {