reachat 1.0.1 → 1.0.2

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/index.js CHANGED
@@ -21,21 +21,18 @@ const ChatContext = createContext({
21
21
  });
22
22
  const ChatInput = ({
23
23
  allowedFiles,
24
- onSendMessage,
25
24
  placeholder,
26
- onStopMessage,
27
- onFileUpload,
28
25
  defaultValue,
29
26
  sendIcon = /* @__PURE__ */ jsx(SvgSend, {}),
30
27
  stopIcon = /* @__PURE__ */ jsx(SvgStop, {}),
31
28
  attachIcon = /* @__PURE__ */ jsx(SvgPaperclip, {})
32
29
  }) => {
33
- const { theme, isLoading, disabled } = useContext(ChatContext);
30
+ const { theme, isLoading, disabled, sendMessage, stopMessage, fileUpload } = useContext(ChatContext);
34
31
  const [message, setMessage] = useState("");
35
32
  const fileInputRef = useRef(null);
36
33
  const handleSendMessage = () => {
37
34
  if (message.trim()) {
38
- onSendMessage == null ? void 0 : onSendMessage(message);
35
+ sendMessage == null ? void 0 : sendMessage(message);
39
36
  setMessage("");
40
37
  }
41
38
  };
@@ -48,8 +45,8 @@ const ChatInput = ({
48
45
  const handleFileUpload = (event) => {
49
46
  var _a;
50
47
  const file = (_a = event.target.files) == null ? void 0 : _a[0];
51
- if (file && onFileUpload) {
52
- onFileUpload(file);
48
+ if (file && fileUpload) {
49
+ fileUpload(file);
53
50
  }
54
51
  };
55
52
  return /* @__PURE__ */ jsxs("div", { className: cn(theme.input.base), children: [
@@ -97,7 +94,7 @@ const ChatInput = ({
97
94
  {
98
95
  title: "Stop",
99
96
  className: cn(theme.input.stop),
100
- onClick: onStopMessage,
97
+ onClick: stopMessage,
101
98
  disabled,
102
99
  children: stopIcon
103
100
  }
@@ -1316,6 +1313,7 @@ const MessageFile = ({
1316
1313
  fileIcon = /* @__PURE__ */ jsx(SvgFile, {})
1317
1314
  }) => {
1318
1315
  const { theme } = useContext(ChatContext);
1316
+ const isImage = type == null ? void 0 : type.startsWith("image/");
1319
1317
  return /* @__PURE__ */ jsxs(
1320
1318
  "figure",
1321
1319
  {
@@ -1324,8 +1322,8 @@ const MessageFile = ({
1324
1322
  window.open(url, "_blank");
1325
1323
  },
1326
1324
  children: [
1327
- fileIcon,
1328
- (name || type) && /* @__PURE__ */ jsx("figcaption", { children: name && /* @__PURE__ */ jsx("span", { className: cn(theme.messages.message.files.file.name), children: /* @__PURE__ */ jsx(Ellipsis, { value: name, limit }) }) })
1325
+ isImage ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("img", { src: url, className: "h-10 w-10" }) }) : /* @__PURE__ */ jsx(Fragment, { children: fileIcon }),
1326
+ name && /* @__PURE__ */ jsx("figcaption", { children: name && /* @__PURE__ */ jsx("span", { className: cn(theme.messages.message.files.file.name), children: /* @__PURE__ */ jsx(Ellipsis, { value: name, limit }) }) })
1329
1327
  ]
1330
1328
  }
1331
1329
  );
@@ -1638,6 +1636,9 @@ const Chat = ({
1638
1636
  sessions,
1639
1637
  onSelectSession,
1640
1638
  onDeleteSession,
1639
+ onSendMessage,
1640
+ onStopMessage,
1641
+ onFileUpload,
1641
1642
  isLoading,
1642
1643
  activeSessionId,
1643
1644
  theme: customTheme = chatTheme,
@@ -1699,7 +1700,10 @@ const Chat = ({
1699
1700
  activeSessionId: internalActiveSessionID,
1700
1701
  selectSession: handleSelectSession,
1701
1702
  deleteSession: handleDeleteSession,
1702
- createSession: handleCreateNewSession
1703
+ createSession: handleCreateNewSession,
1704
+ sendMessage: onSendMessage,
1705
+ stopMessage: onStopMessage,
1706
+ fileUpload: onFileUpload
1703
1707
  }),
1704
1708
  [
1705
1709
  isLoading,
@@ -1712,7 +1716,10 @@ const Chat = ({
1712
1716
  internalActiveSessionID,
1713
1717
  handleSelectSession,
1714
1718
  handleDeleteSession,
1715
- handleCreateNewSession
1719
+ handleCreateNewSession,
1720
+ onSendMessage,
1721
+ onStopMessage,
1722
+ onFileUpload
1716
1723
  ]
1717
1724
  );
1718
1725
  return /* @__PURE__ */ jsx(ChatContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(AnimatePresence, { initial: false, children: /* @__PURE__ */ jsx(