reachat 1.0.1 → 1.0.3

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.
@@ -1,6 +1,6 @@
1
1
  (function(global, factory) {
2
- 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("remark-gfm"), require("react-syntax-highlighter"), require("mdast-util-find-and-replace"), require("remark-youtube"), require("reakeys"), require("react-cool-dimensions"), require("date-fns")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react", "reablocks", "@radix-ui/react-slot", "framer-motion", "react-markdown", "remark-gfm", "react-syntax-highlighter", "mdast-util-find-and-replace", "remark-youtube", "reakeys", "react-cool-dimensions", "date-fns"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.reablocks = {}, global.jsxRuntime, global.React, global.reablocks, global.reactSlot, global.framerMotion, global.ReactMarkdown, global.remarkGfm, global.reactSyntaxHighlighter, global.mdastUtilFindAndReplace, global.remarkYoutube, global.reakeys, global.useDimensions, global.dateFns));
3
- })(this, function(exports2, jsxRuntime, React, reablocks, reactSlot, framerMotion, ReactMarkdown, remarkGfm, reactSyntaxHighlighter, mdastUtilFindAndReplace, remarkYoutube, reakeys, useDimensions, dateFns) {
2
+ 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("remark-gfm"), require("react-syntax-highlighter"), require("mdast-util-find-and-replace"), require("remark-youtube"), require("reakeys"), require("date-fns")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react", "reablocks", "@radix-ui/react-slot", "framer-motion", "react-markdown", "remark-gfm", "react-syntax-highlighter", "mdast-util-find-and-replace", "remark-youtube", "reakeys", "date-fns"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.reablocks = {}, global.jsxRuntime, global.React, global.reablocks, global.reactSlot, global.framerMotion, global.ReactMarkdown, global.remarkGfm, global.reactSyntaxHighlighter, global.mdastUtilFindAndReplace, global.remarkYoutube, global.reakeys, global.dateFns));
3
+ })(this, function(exports2, jsxRuntime, React, reablocks, reactSlot, framerMotion, ReactMarkdown, remarkGfm, reactSyntaxHighlighter, mdastUtilFindAndReplace, remarkYoutube, reakeys, dateFns) {
4
4
  "use strict";
5
5
  function _interopNamespaceDefault(e) {
6
6
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -28,21 +28,18 @@
28
28
  });
29
29
  const ChatInput = ({
30
30
  allowedFiles,
31
- onSendMessage,
32
31
  placeholder,
33
- onStopMessage,
34
- onFileUpload,
35
32
  defaultValue,
36
33
  sendIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgSend, {}),
37
34
  stopIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgStop, {}),
38
35
  attachIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgPaperclip, {})
39
36
  }) => {
40
- const { theme, isLoading, disabled } = React.useContext(ChatContext);
37
+ const { theme, isLoading, disabled, sendMessage, stopMessage, fileUpload } = React.useContext(ChatContext);
41
38
  const [message, setMessage] = React.useState("");
42
39
  const fileInputRef = React.useRef(null);
43
40
  const handleSendMessage = () => {
44
41
  if (message.trim()) {
45
- onSendMessage == null ? void 0 : onSendMessage(message);
42
+ sendMessage == null ? void 0 : sendMessage(message);
46
43
  setMessage("");
47
44
  }
48
45
  };
@@ -55,8 +52,8 @@
55
52
  const handleFileUpload = (event) => {
56
53
  var _a;
57
54
  const file = (_a = event.target.files) == null ? void 0 : _a[0];
58
- if (file && onFileUpload) {
59
- onFileUpload(file);
55
+ if (file && fileUpload) {
56
+ fileUpload(file);
60
57
  }
61
58
  };
62
59
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: reablocks.cn(theme.input.base), children: [
@@ -104,7 +101,7 @@
104
101
  {
105
102
  title: "Stop",
106
103
  className: reablocks.cn(theme.input.stop),
107
- onClick: onStopMessage,
104
+ onClick: stopMessage,
108
105
  disabled,
109
106
  children: stopIcon
110
107
  }
@@ -1323,6 +1320,7 @@
1323
1320
  fileIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgFile, {})
1324
1321
  }) => {
1325
1322
  const { theme } = React.useContext(ChatContext);
1323
+ const isImage = type == null ? void 0 : type.startsWith("image/");
1326
1324
  return /* @__PURE__ */ jsxRuntime.jsxs(
1327
1325
  "figure",
1328
1326
  {
@@ -1331,8 +1329,8 @@
1331
1329
  window.open(url, "_blank");
1332
1330
  },
1333
1331
  children: [
1334
- fileIcon,
1335
- (name || type) && /* @__PURE__ */ jsxRuntime.jsx("figcaption", { children: name && /* @__PURE__ */ jsxRuntime.jsx("span", { className: reablocks.cn(theme.messages.message.files.file.name), children: /* @__PURE__ */ jsxRuntime.jsx(reablocks.Ellipsis, { value: name, limit }) }) })
1332
+ isImage ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: url, className: "h-10 w-10" }) }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fileIcon }),
1333
+ name && /* @__PURE__ */ jsxRuntime.jsx("figcaption", { children: name && /* @__PURE__ */ jsxRuntime.jsx("span", { className: reablocks.cn(theme.messages.message.files.file.name), children: /* @__PURE__ */ jsxRuntime.jsx(reablocks.Ellipsis, { value: name, limit }) }) })
1336
1334
  ]
1337
1335
  }
1338
1336
  );
@@ -1639,12 +1637,35 @@ ${response}`),
1639
1637
  stop: "px-4 py-2 bg-red-500 text-white rounded hover:bg-red-700"
1640
1638
  }
1641
1639
  };
1640
+ const useDimensions = () => {
1641
+ const [ref, setRef] = React.useState(null);
1642
+ const [width, setWidth] = React.useState(void 0);
1643
+ const observe = React.useCallback((element) => {
1644
+ if (element) setRef(element);
1645
+ }, []);
1646
+ React.useEffect(() => {
1647
+ if (!ref) return;
1648
+ const resizeObserver = new ResizeObserver((entries) => {
1649
+ for (let entry of entries) {
1650
+ setWidth(entry.contentRect.width);
1651
+ }
1652
+ });
1653
+ resizeObserver.observe(ref);
1654
+ return () => {
1655
+ resizeObserver.disconnect();
1656
+ };
1657
+ }, [ref]);
1658
+ return { width, observe };
1659
+ };
1642
1660
  const Chat = ({
1643
1661
  children,
1644
1662
  viewType = "console",
1645
1663
  sessions,
1646
1664
  onSelectSession,
1647
1665
  onDeleteSession,
1666
+ onSendMessage,
1667
+ onStopMessage,
1668
+ onFileUpload,
1648
1669
  isLoading,
1649
1670
  activeSessionId,
1650
1671
  theme: customTheme = chatTheme,
@@ -1706,7 +1727,10 @@ ${response}`),
1706
1727
  activeSessionId: internalActiveSessionID,
1707
1728
  selectSession: handleSelectSession,
1708
1729
  deleteSession: handleDeleteSession,
1709
- createSession: handleCreateNewSession
1730
+ createSession: handleCreateNewSession,
1731
+ sendMessage: onSendMessage,
1732
+ stopMessage: onStopMessage,
1733
+ fileUpload: onFileUpload
1710
1734
  }),
1711
1735
  [
1712
1736
  isLoading,
@@ -1719,7 +1743,10 @@ ${response}`),
1719
1743
  internalActiveSessionID,
1720
1744
  handleSelectSession,
1721
1745
  handleDeleteSession,
1722
- handleCreateNewSession
1746
+ handleCreateNewSession,
1747
+ onSendMessage,
1748
+ onStopMessage,
1749
+ onFileUpload
1723
1750
  ]
1724
1751
  );
1725
1752
  return /* @__PURE__ */ jsxRuntime.jsx(ChatContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { initial: false, children: /* @__PURE__ */ jsxRuntime.jsx(