reachat 1.2.0 → 1.3.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.
@@ -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("remark-gfm"), require("react-syntax-highlighter"), require("rehype-katex"), require("remark-math"), 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", "rehype-katex", "remark-math", "mdast-util-find-and-replace", "remark-youtube", "reakeys", "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.remarkGfm, global.reactSyntaxHighlighter, global.rehypeKatex, global.remarkMath, global.mdastUtilFindAndReplace, global.remarkYoutube, global.reakeys, global.dateFns));
15
- })(this, function(exports2, jsxRuntime, React, reablocks, reactSlot, framerMotion, ReactMarkdown, remarkGfm, reactSyntaxHighlighter, rehypeKatex, remarkMath, mdastUtilFindAndReplace, remarkYoutube, reakeys, dateFns) {
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) {
16
16
  "use strict";
17
17
  function _interopNamespaceDefault(e) {
18
18
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -38,17 +38,24 @@
38
38
  sessions: [],
39
39
  activeSessionId: null
40
40
  });
41
- const ChatInput = ({
41
+ const ChatInput = React.forwardRef(({
42
42
  allowedFiles,
43
43
  placeholder,
44
44
  defaultValue,
45
45
  sendIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgSend, {}),
46
46
  stopIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgStop, {}),
47
47
  attachIcon = /* @__PURE__ */ jsxRuntime.jsx(SvgPaperclip, {})
48
- }) => {
48
+ }, ref) => {
49
49
  const { theme, isLoading, disabled, sendMessage, stopMessage, fileUpload } = React.useContext(ChatContext);
50
50
  const [message, setMessage] = React.useState("");
51
51
  const fileInputRef = React.useRef(null);
52
+ const inputRef = React.useRef(null);
53
+ React.useImperativeHandle(ref, () => ({
54
+ focus: () => {
55
+ var _a;
56
+ (_a = inputRef.current) == null ? void 0 : _a.focus();
57
+ }
58
+ }));
52
59
  const handleSendMessage = () => {
53
60
  if (message.trim()) {
54
61
  sendMessage == null ? void 0 : sendMessage(message);
@@ -72,15 +79,16 @@
72
79
  /* @__PURE__ */ jsxRuntime.jsx(
73
80
  reablocks.Textarea,
74
81
  {
82
+ inputRef,
75
83
  containerClassName: reablocks.cn(theme.input.input),
76
84
  minRows: 1,
77
85
  autoFocus: true,
78
86
  value: message,
79
- onChange: (e) => setMessage(e.target.value),
80
87
  defaultValue,
81
88
  onKeyPress: handleKeyPress,
82
89
  placeholder,
83
- disabled: isLoading || disabled
90
+ disabled: isLoading || disabled,
91
+ onChange: (e) => setMessage(e.target.value)
84
92
  }
85
93
  ),
86
94
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: reablocks.cn(theme.input.actions.base), children: [
@@ -132,7 +140,7 @@
132
140
  )
133
141
  ] })
134
142
  ] });
135
- };
143
+ });
136
144
  const SessionEmpty = ({
137
145
  children
138
146
  }) => {
@@ -1245,7 +1253,7 @@
1245
1253
  const TableDataCell = ({ children, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("td", { ...props, children });
1246
1254
  const Markdown = ({
1247
1255
  children,
1248
- remarkPlugins = [remarkGfm, remarkMath],
1256
+ remarkPlugins,
1249
1257
  rehypePlugins = [rehypeKatex]
1250
1258
  }) => {
1251
1259
  const { theme } = React.useContext(ChatContext);
@@ -1302,9 +1310,25 @@
1302
1310
  question,
1303
1311
  children
1304
1312
  }) => {
1305
- const { theme, remarkPlugins = [remarkGfm, remarkYoutube] } = React.useContext(ChatContext);
1313
+ const { theme, remarkPlugins } = React.useContext(ChatContext);
1306
1314
  const Comp = children ? reactSlot.Slot : "div";
1307
- return /* @__PURE__ */ jsxRuntime.jsx(Comp, { className: reablocks.cn(theme.messages.message.question), children: children || /* @__PURE__ */ jsxRuntime.jsx(Markdown, { remarkPlugins, children: question }) });
1315
+ const [expanded, setExpanded] = React.useState(false);
1316
+ const isLong = question.length > 500;
1317
+ return /* @__PURE__ */ jsxRuntime.jsxs(Comp, { className: reablocks.cn(theme.messages.message.question, {
1318
+ [theme.messages.message.overlay]: isLong && !expanded
1319
+ }), children: [
1320
+ children || /* @__PURE__ */ jsxRuntime.jsx(Markdown, { remarkPlugins, children: question }),
1321
+ isLong && !expanded && /* @__PURE__ */ jsxRuntime.jsx(
1322
+ reablocks.Button,
1323
+ {
1324
+ variant: "link",
1325
+ size: "small",
1326
+ className: theme.messages.message.expand,
1327
+ onClick: () => setExpanded(true),
1328
+ children: "Show more"
1329
+ }
1330
+ )
1331
+ ] });
1308
1332
  };
1309
1333
  const MessageResponse = ({
1310
1334
  response,
@@ -1314,7 +1338,7 @@
1314
1338
  const {
1315
1339
  theme,
1316
1340
  isCompact,
1317
- remarkPlugins = [remarkGfm, remarkYoutube]
1341
+ remarkPlugins
1318
1342
  } = React.useContext(ChatContext);
1319
1343
  const Comp = children ? reactSlot.Slot : "div";
1320
1344
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -1635,11 +1659,13 @@ ${response}`),
1635
1659
  message: {
1636
1660
  base: "mt-4 mb-4 flex flex-col p-0 rounded border-none bg-transparent",
1637
1661
  question: [
1638
- "font-semibold mb-4 px-4 py-4 pb-2 rounded-3xl rounded-br-none text-typography border bg-gray-200 border-gray-300 text-gray-900",
1662
+ "relative font-semibold mb-4 px-4 py-4 pb-2 rounded-3xl rounded-br-none text-typography border bg-gray-200 border-gray-300 text-gray-900",
1639
1663
  "dark:bg-gray-900/60 dark:border-gray-700/50 dark:text-gray-100"
1640
1664
  ].join(" "),
1641
- response: ["data-[compact=false]:px-4 text-gray-900", "dark:text-gray-100"].join(" "),
1665
+ response: ["relative data-[compact=false]:px-4 text-gray-900", "dark:text-gray-100"].join(" "),
1666
+ overlay: `overflow-y-hidden max-h-[350px] after:content-[''] after:absolute after:inset-x-0 after:bottom-0 after:h-16 after:bg-gradient-to-b after:from-transparent dark:after:to-gray-900 after:to-gray-200`,
1642
1667
  cursor: "inline-block w-1 h-4 bg-current",
1668
+ expand: "absolute bottom-1 right-1 z-10",
1643
1669
  files: {
1644
1670
  base: "mb-2 flex flex-wrap gap-3 ",
1645
1671
  file: {
@@ -1738,7 +1764,7 @@ ${response}`),
1738
1764
  activeSessionId,
1739
1765
  theme: customTheme = chatTheme,
1740
1766
  onNewSession,
1741
- remarkPlugins,
1767
+ remarkPlugins = [remarkGfm, remarkYoutube, remarkMath],
1742
1768
  disabled,
1743
1769
  style,
1744
1770
  className