reachat 1.6.1 → 1.7.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("reablocks"), require("react"), require("motion/react"), require("@radix-ui/react-slot"), 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", "reablocks", "react", "motion/react", "@radix-ui/react-slot", "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.reablocks, global.React, global.react, global.reactSlot, global.ReactMarkdown, global.reactSyntaxHighlighter, global.rehypeKatex, global.mdastUtilFindAndReplace, global.reakeys, global.remarkGfm, global.remarkYoutube, global.remarkMath, global.dateFns));
15
- })(this, function(exports2, jsxRuntime, reablocks, React, react, reactSlot, ReactMarkdown, reactSyntaxHighlighter, rehypeKatex, mdastUtilFindAndReplace, reakeys, remarkGfm, remarkYoutube, remarkMath, dateFns) {
14
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("reablocks"), require("react"), require("motion/react"), require("@radix-ui/react-slot"), 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"), require("react-dom")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "reablocks", "react", "motion/react", "@radix-ui/react-slot", "react-markdown", "react-syntax-highlighter", "rehype-katex", "mdast-util-find-and-replace", "reakeys", "remark-gfm", "remark-youtube", "remark-math", "date-fns", "react-dom"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.reachat = {}, global.jsxRuntime, global.reablocks, global.React, global.react, global.reactSlot, global.ReactMarkdown, global.reactSyntaxHighlighter, global.rehypeKatex, global.mdastUtilFindAndReplace, global.reakeys, global.remarkGfm, global.remarkYoutube, global.remarkMath, global.dateFns, global.reactDom));
15
+ })(this, function(exports2, jsxRuntime, reablocks, React, react, reactSlot, ReactMarkdown, reactSyntaxHighlighter, rehypeKatex, mdastUtilFindAndReplace, reakeys, remarkGfm, remarkYoutube, remarkMath, dateFns, reactDom) {
16
16
  "use strict";
17
17
  function _interopNamespaceDefault(e) {
18
18
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -189,7 +189,10 @@
189
189
  ] }) });
190
190
  };
191
191
  const SvgBack = (props) => /* @__PURE__ */ React__namespace.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1, strokeLinecap: "round", strokeLinejoin: "round", className: "lucide lucide-chevron-left", ...props }, /* @__PURE__ */ React__namespace.createElement("path", { d: "m15 18-6-6 6-6" }));
192
- const SessionMessagePanel = ({ children }) => {
192
+ const SessionMessagePanel = ({
193
+ children,
194
+ allowBack = true
195
+ }) => {
193
196
  const { activeSessionId, theme, isCompact, selectSession, viewType } = React.useContext(ChatContext);
194
197
  const isVisible = isCompact && activeSessionId || viewType === "chat" || !isCompact;
195
198
  return isVisible && /* @__PURE__ */ jsxRuntime.jsx(
@@ -211,7 +214,7 @@
211
214
  [theme.messages.console]: !isCompact
212
215
  }),
213
216
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: reablocks.cn(theme.messages.inner), children: [
214
- isCompact && viewType !== "chat" && /* @__PURE__ */ jsxRuntime.jsxs(
217
+ allowBack && isCompact && viewType !== "chat" && /* @__PURE__ */ jsxRuntime.jsxs(
215
218
  reablocks.Button,
216
219
  {
217
220
  variant: "text",
@@ -1906,6 +1909,7 @@ ${response}`),
1906
1909
  console: "flex w-full gap-4 h-full",
1907
1910
  companion: "w-full h-full overflow-hidden",
1908
1911
  empty: "text-center flex-1",
1912
+ appbar: "flex p-5",
1909
1913
  sessions: {
1910
1914
  base: "overflow-auto",
1911
1915
  console: "min-w-[150px] w-[30%] max-w-[300px] dark:bg-[#11111F] bg-[#F2F3F7] p-5 rounded-3xl",
@@ -1947,7 +1951,10 @@ ${response}`),
1947
1951
  "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",
1948
1952
  "dark:bg-gray-900/60 dark:border-gray-700/50 dark:text-gray-100"
1949
1953
  ].join(" "),
1950
- response: ["relative data-[compact=false]:px-4 text-gray-900", "dark:text-gray-100"].join(" "),
1954
+ response: [
1955
+ "relative data-[compact=false]:px-4 text-gray-900",
1956
+ "dark:text-gray-100"
1957
+ ].join(" "),
1951
1958
  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`,
1952
1959
  cursor: "inline-block w-1 h-4 bg-current",
1953
1960
  expand: "absolute bottom-1 right-1 z-10",
@@ -2143,31 +2150,6 @@ ${response}`),
2143
2150
  }
2144
2151
  ) }) });
2145
2152
  };
2146
- const SessionsList = ({ children }) => {
2147
- const { theme, isCompact, activeSessionId } = React.useContext(ChatContext);
2148
- const isVisible = isCompact && !activeSessionId;
2149
- return (!isCompact || isVisible) && /* @__PURE__ */ jsxRuntime.jsx(
2150
- react.motion.div,
2151
- {
2152
- initial: { translateX: "-100%" },
2153
- animate: {
2154
- translateX: "0%",
2155
- transition: {
2156
- type: "tween",
2157
- ease: "linear",
2158
- duration: 0.2,
2159
- when: "beforeChildren"
2160
- }
2161
- },
2162
- exit: { translateX: "-100%" },
2163
- className: reablocks.cn(theme.sessions.base, {
2164
- [theme.sessions.companion]: isCompact,
2165
- [theme.sessions.console]: !isCompact
2166
- }),
2167
- children: /* @__PURE__ */ jsxRuntime.jsx(reablocks.List, { children })
2168
- }
2169
- );
2170
- };
2171
2153
  const SvgTrash = (props) => /* @__PURE__ */ React__namespace.createElement("svg", { width: 14, height: 14, viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React__namespace.createElement("g", { id: "Delete" }, /* @__PURE__ */ React__namespace.createElement("path", { id: "Vector", d: "M5.97905 1.16666C5.90859 1.16576 5.83895 1.18189 5.77605 1.21368C5.71316 1.24547 5.65888 1.29199 5.61783 1.34926C5.57677 1.40654 5.55016 1.47288 5.54025 1.54265C5.53034 1.61242 5.53743 1.68355 5.56092 1.75H4.27007C3.7342 1.75 3.2324 2.01817 2.93535 2.46435L2.24492 3.5H2.18738C2.12941 3.49918 2.07185 3.50989 2.01805 3.5315C1.96425 3.55312 1.91529 3.58522 1.874 3.62593C1.83271 3.66663 1.79993 3.71514 1.77755 3.76863C1.75518 3.82211 1.74365 3.87952 1.74365 3.9375C1.74365 3.99548 1.75518 4.05288 1.77755 4.10636C1.79993 4.15985 1.83271 4.20836 1.874 4.24907C1.91529 4.28977 1.96425 4.32187 2.01805 4.34349C2.07185 4.3651 2.12941 4.37582 2.18738 4.375H2.41012C2.44765 4.38067 2.48576 4.38143 2.52348 4.37727L3.24468 11.1084C3.33169 11.9199 4.02367 12.5417 4.83973 12.5417H9.15947C9.97553 12.5417 10.6675 11.9199 10.7545 11.1084L11.4763 4.37727C11.5133 4.38124 11.5506 4.38047 11.5874 4.375H11.8124C11.8704 4.37582 11.9279 4.3651 11.9817 4.34349C12.0355 4.32187 12.0845 4.28977 12.1258 4.24907C12.1671 4.20836 12.1998 4.15985 12.2222 4.10636C12.2446 4.05288 12.2561 3.99548 12.2561 3.9375C12.2561 3.87952 12.2446 3.82211 12.2222 3.76863C12.1998 3.71514 12.1671 3.66663 12.1258 3.62593C12.0845 3.58522 12.0355 3.55312 11.9817 3.5315C11.9279 3.50989 11.8704 3.49918 11.8124 3.5H11.7548L11.0644 2.46435C10.7671 2.01841 10.2654 1.75 9.7297 1.75H8.43885C8.46234 1.68355 8.46943 1.61242 8.45952 1.54265C8.44961 1.47288 8.423 1.40654 8.38194 1.34926C8.34089 1.29199 8.2866 1.24547 8.22371 1.21368C8.16082 1.18189 8.09118 1.16576 8.02072 1.16666H5.97905ZM4.27007 2.625H9.7297C9.97394 2.625 10.2009 2.74639 10.3364 2.9497L10.7033 3.5H3.29651L3.66338 2.9497L3.66395 2.94913C3.79913 2.74608 4.02543 2.625 4.27007 2.625ZM3.40361 4.375H10.5962L9.88465 11.015C9.8445 11.3894 9.53575 11.6667 9.15947 11.6667H4.83973C4.46345 11.6667 4.15527 11.3894 4.11512 11.015L3.40361 4.375Z", fill: "currentColor" })));
2172
2154
  const SvgChat = (props) => /* @__PURE__ */ React__namespace.createElement("svg", { width: 16, height: 17, viewBox: "0 0 16 17", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React__namespace.createElement("path", { d: "M8 3C4.55375 3 1.75 5.23753 1.75 7.98828C1.75 9.70653 2.83659 11.2762 4.62109 12.188C4.11184 13.0465 3.62587 13.7378 3.62012 13.7461C3.50687 13.9071 3.49862 14.1196 3.59912 14.2891C3.69012 14.4418 3.8543 14.5342 4.0293 14.5342C4.0483 14.5342 4.06743 14.533 4.08643 14.5308C4.15168 14.5233 5.66214 14.3364 7.50439 12.9604C7.67239 12.9712 7.8385 12.9766 8 12.9766C11.4462 12.9766 14.25 10.739 14.25 7.98828C14.25 5.23753 11.4462 3 8 3ZM8 4C10.8948 4 13.25 5.78903 13.25 7.98828C13.25 10.1875 10.8948 11.9766 8 11.9766C7.8055 11.9766 7.60225 11.968 7.396 11.9497C7.271 11.9382 7.1454 11.9752 7.0459 12.0527C6.3589 12.5855 5.72033 12.9308 5.20508 13.1528C5.38383 12.8648 5.57691 12.5418 5.76416 12.2061C5.83416 12.0813 5.84705 11.9324 5.7998 11.7974C5.75255 11.6624 5.64983 11.5542 5.51758 11.5C3.81033 10.7993 2.75 9.45328 2.75 7.98828C2.75 5.78903 5.10525 4 8 4ZM5.5 7.25C5.08575 7.25 4.75 7.58575 4.75 8C4.75 8.41425 5.08575 8.75 5.5 8.75C5.91425 8.75 6.25 8.41425 6.25 8C6.25 7.58575 5.91425 7.25 5.5 7.25ZM8 7.25C7.58575 7.25 7.25 7.58575 7.25 8C7.25 8.41425 7.58575 8.75 8 8.75C8.41425 8.75 8.75 8.41425 8.75 8C8.75 7.58575 8.41425 7.25 8 7.25ZM10.5 7.25C10.0857 7.25 9.75 7.58575 9.75 8C9.75 8.41425 10.0857 8.75 10.5 8.75C10.9143 8.75 11.25 8.41425 11.25 8C11.25 7.58575 10.9143 7.25 10.5 7.25Z", fill: "currentColor" }));
2173
2155
  const SessionListItem = ({
@@ -2208,6 +2190,48 @@ ${response}`),
2208
2190
  }
2209
2191
  );
2210
2192
  };
2193
+ const SessionsList = ({
2194
+ children,
2195
+ templates
2196
+ }) => {
2197
+ const { theme, isCompact, activeSessionId, createSession } = React.useContext(ChatContext);
2198
+ const isVisible = isCompact && !activeSessionId;
2199
+ return (!isCompact || isVisible) && /* @__PURE__ */ jsxRuntime.jsxs(
2200
+ react.motion.div,
2201
+ {
2202
+ initial: { translateX: "-100%" },
2203
+ animate: {
2204
+ translateX: "0%",
2205
+ transition: {
2206
+ type: "tween",
2207
+ ease: "linear",
2208
+ duration: 0.2,
2209
+ when: "beforeChildren"
2210
+ }
2211
+ },
2212
+ exit: { translateX: "-100%" },
2213
+ className: reablocks.cn(theme.sessions.base, {
2214
+ [theme.sessions.companion]: isCompact,
2215
+ [theme.sessions.console]: !isCompact
2216
+ }),
2217
+ children: [
2218
+ /* @__PURE__ */ jsxRuntime.jsx(reablocks.List, { children }),
2219
+ templates && !activeSessionId && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4", children: templates.map((template) => /* @__PURE__ */ jsxRuntime.jsx("div", { onClick: () => createSession == null ? void 0 : createSession(), children: /* @__PURE__ */ jsxRuntime.jsx(
2220
+ SessionListItem,
2221
+ {
2222
+ session: {
2223
+ id: template.id,
2224
+ title: template.title,
2225
+ conversations: []
2226
+ },
2227
+ chatIcon: template.icon,
2228
+ deletable: false
2229
+ }
2230
+ ) }, template.id)) })
2231
+ ]
2232
+ }
2233
+ );
2234
+ };
2211
2235
  const SvgPlus = (props) => /* @__PURE__ */ React__namespace.createElement("svg", { width: 17, height: 17, viewBox: "0 0 17 17", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React__namespace.createElement("g", { id: "add" }, /* @__PURE__ */ React__namespace.createElement("path", { id: "Vector", d: "M13.1667 9.16658H9.16671V13.1666H7.83337V9.16658H3.83337V7.83325H7.83337V3.83325H9.16671V7.83325H13.1667V9.16658Z", fill: "currentColor" })));
2212
2236
  const NewSessionButton = ({
2213
2237
  children,
@@ -2315,7 +2339,156 @@ ${response}`),
2315
2339
  const groups = React.useMemo(() => groupSessionsByDate(sessions), [sessions]);
2316
2340
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children ? children(groups) : groups.map(({ heading, sessions: sessions2 }) => /* @__PURE__ */ jsxRuntime.jsx(SessionsGroup, { heading, children: sessions2.map((session) => /* @__PURE__ */ jsxRuntime.jsx(SessionListItem, { session }, session.id)) })) });
2317
2341
  };
2342
+ const AppBar = ({
2343
+ content,
2344
+ theme: customTheme = chatTheme
2345
+ }) => {
2346
+ const theme = reablocks.useComponentTheme("chat", customTheme);
2347
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: reablocks.cn(theme.appbar), children: content });
2348
+ };
2349
+ const defaultPositions = {
2350
+ "bottom-left": "bottom-5 left-5",
2351
+ "bottom-right": "bottom-5 right-5",
2352
+ "top-left": "top-5 left-5",
2353
+ "top-right": "top-5 right-5"
2354
+ };
2355
+ const ChatBubble = React.memo(
2356
+ ({
2357
+ children,
2358
+ bubbleContent,
2359
+ position = "bottom-left",
2360
+ customPosition,
2361
+ portalTarget = typeof document !== "undefined" ? document.body : null,
2362
+ className
2363
+ }) => {
2364
+ const [isOpen, setIsOpen] = React.useState(false);
2365
+ const bubbleRef = React.useRef(null);
2366
+ const contentRef = React.useRef(null);
2367
+ const [bubbleRect, setBubbleRect] = React.useState(null);
2368
+ React.useEffect(() => {
2369
+ if (bubbleRef.current) {
2370
+ setBubbleRect(bubbleRef.current.getBoundingClientRect());
2371
+ }
2372
+ }, [isOpen]);
2373
+ const handleClose = React.useCallback(() => {
2374
+ setIsOpen(false);
2375
+ }, []);
2376
+ const handleToggle = React.useCallback(() => {
2377
+ setIsOpen((prev) => !prev);
2378
+ }, []);
2379
+ const getContentPosition = () => {
2380
+ if (!bubbleRect) return {};
2381
+ const positions = {
2382
+ "bottom-left": {
2383
+ bottom: `calc(100vh - ${bubbleRect.top}px)`,
2384
+ left: `${bubbleRect.right}px`
2385
+ },
2386
+ "bottom-right": {
2387
+ bottom: `calc(100vh - ${bubbleRect.top}px)`,
2388
+ right: `calc(100vw - ${bubbleRect.left}px)`
2389
+ },
2390
+ "top-left": {
2391
+ top: `${bubbleRect.bottom}px`,
2392
+ left: `${bubbleRect.right}px`
2393
+ },
2394
+ "top-right": {
2395
+ top: `${bubbleRect.bottom}px`,
2396
+ right: `calc(100vw - ${bubbleRect.left}px)`
2397
+ }
2398
+ };
2399
+ return positions[position];
2400
+ };
2401
+ const content = React.useMemo(
2402
+ () => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2403
+ /* @__PURE__ */ jsxRuntime.jsx(
2404
+ "div",
2405
+ {
2406
+ ref: bubbleRef,
2407
+ style: {
2408
+ ...customPosition,
2409
+ ...portalTarget ? { position: "absolute" } : {}
2410
+ },
2411
+ onClick: handleToggle,
2412
+ className: reablocks.cn(
2413
+ "z-[1000]",
2414
+ !portalTarget && "fixed",
2415
+ defaultPositions[position],
2416
+ "cursor-pointer",
2417
+ className
2418
+ ),
2419
+ role: "button",
2420
+ tabIndex: 0,
2421
+ "aria-label": "Open chat",
2422
+ children: bubbleContent
2423
+ }
2424
+ ),
2425
+ /* @__PURE__ */ jsxRuntime.jsx(react.AnimatePresence, { children: children && isOpen && bubbleRect && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2426
+ /* @__PURE__ */ jsxRuntime.jsx(
2427
+ react.motion.div,
2428
+ {
2429
+ initial: { opacity: 0 },
2430
+ animate: { opacity: 0.5 },
2431
+ exit: { opacity: 0 },
2432
+ className: "fixed inset-0 z-[998]",
2433
+ onClick: handleClose
2434
+ }
2435
+ ),
2436
+ /* @__PURE__ */ jsxRuntime.jsx(
2437
+ react.motion.div,
2438
+ {
2439
+ ref: contentRef,
2440
+ initial: false,
2441
+ animate: {
2442
+ opacity: 1,
2443
+ scale: 1,
2444
+ x: 0,
2445
+ pointerEvents: "auto"
2446
+ },
2447
+ exit: {
2448
+ opacity: 0,
2449
+ scale: 0.8,
2450
+ x: position.includes("right") ? 20 : -20,
2451
+ pointerEvents: "none"
2452
+ },
2453
+ transition: { type: "spring", duration: 0.5 },
2454
+ className: reablocks.cn(
2455
+ "fixed z-[999]",
2456
+ position.includes("right") ? "origin-right" : "origin-left",
2457
+ position.includes("top") ? "origin-top" : "origin-bottom"
2458
+ ),
2459
+ style: getContentPosition(),
2460
+ children
2461
+ }
2462
+ )
2463
+ ] }) })
2464
+ ] }),
2465
+ [
2466
+ children,
2467
+ customPosition,
2468
+ portalTarget,
2469
+ position,
2470
+ className,
2471
+ bubbleContent,
2472
+ isOpen,
2473
+ handleClose,
2474
+ handleToggle,
2475
+ bubbleRect
2476
+ ]
2477
+ );
2478
+ if (!portalTarget) {
2479
+ return content;
2480
+ }
2481
+ try {
2482
+ return reactDom.createPortal(content, portalTarget);
2483
+ } catch (error) {
2484
+ console.error("Failed to create portal for ChatBubble:", error);
2485
+ return content;
2486
+ }
2487
+ }
2488
+ );
2489
+ exports2.AppBar = AppBar;
2318
2490
  exports2.Chat = Chat;
2491
+ exports2.ChatBubble = ChatBubble;
2319
2492
  exports2.ChatContext = ChatContext;
2320
2493
  exports2.ChatInput = ChatInput;
2321
2494
  exports2.CodeHighlighter = CodeHighlighter;