reachat 2.0.0-beta.0 → 2.0.0-beta.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.d.ts CHANGED
@@ -6,3 +6,5 @@ export * from './types';
6
6
  export * from './theme';
7
7
  export * from './Markdown';
8
8
  export * from './ChatContext';
9
+ export * from './AppBar';
10
+ export * from './ChatBubble';
package/dist/index.js CHANGED
@@ -10,13 +10,15 @@
10
10
  console.error("vite-plugin-css-injected-by-js", e);
11
11
  }
12
12
  })();
13
- import { m, z, C, v, F, s, f, g, h, i, j, M, k, N, b, p, o, e, d, l, c, q, n, T, u, t, r, x, y, w } from "./index-9RlgGcc-.js";
13
+ import { A, m, B, z, C, v, F, s, f, g, h, i, j, M, k, N, b, p, o, e, d, l, c, q, n, T, u, t, r, x, y, w } from "./index-B1krf7tH.js";
14
14
  import "react/jsx-runtime";
15
15
  import "react";
16
16
  import "reablocks";
17
17
  import "motion/react";
18
18
  export {
19
+ A as AppBar,
19
20
  m as Chat,
21
+ B as ChatBubble,
20
22
  z as ChatContext,
21
23
  C as ChatInput,
22
24
  v as CodeHighlighter,
@@ -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",
@@ -1899,6 +1902,7 @@ ${response}`),
1899
1902
  console: "flex w-full gap-4 h-full",
1900
1903
  companion: "w-full h-full overflow-hidden",
1901
1904
  empty: "text-center flex-1",
1905
+ appbar: "flex p-5",
1902
1906
  sessions: {
1903
1907
  base: "overflow-auto",
1904
1908
  console: "min-w-[150px] w-[30%] max-w-[300px] dark:bg-[#11111F] bg-[#F2F3F7] p-5 rounded-3xl",
@@ -2139,31 +2143,6 @@ ${response}`),
2139
2143
  }
2140
2144
  ) }) });
2141
2145
  };
2142
- const SessionsList = ({ children }) => {
2143
- const { theme, isCompact, activeSessionId } = React.useContext(ChatContext);
2144
- const isVisible = isCompact && !activeSessionId;
2145
- return (!isCompact || isVisible) && /* @__PURE__ */ jsxRuntime.jsx(
2146
- react.motion.div,
2147
- {
2148
- initial: { translateX: "-100%" },
2149
- animate: {
2150
- translateX: "0%",
2151
- transition: {
2152
- type: "tween",
2153
- ease: "linear",
2154
- duration: 0.2,
2155
- when: "beforeChildren"
2156
- }
2157
- },
2158
- exit: { translateX: "-100%" },
2159
- className: reablocks.cn(theme.sessions.base, {
2160
- [theme.sessions.companion]: isCompact,
2161
- [theme.sessions.console]: !isCompact
2162
- }),
2163
- children: /* @__PURE__ */ jsxRuntime.jsx(reablocks.List, { children })
2164
- }
2165
- );
2166
- };
2167
2146
  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" })));
2168
2147
  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" }));
2169
2148
  const SessionListItem = ({
@@ -2204,6 +2183,48 @@ ${response}`),
2204
2183
  }
2205
2184
  );
2206
2185
  };
2186
+ const SessionsList = ({
2187
+ children,
2188
+ templates
2189
+ }) => {
2190
+ const { theme, isCompact, activeSessionId, createSession } = React.useContext(ChatContext);
2191
+ const isVisible = isCompact && !activeSessionId;
2192
+ return (!isCompact || isVisible) && /* @__PURE__ */ jsxRuntime.jsxs(
2193
+ react.motion.div,
2194
+ {
2195
+ initial: { translateX: "-100%" },
2196
+ animate: {
2197
+ translateX: "0%",
2198
+ transition: {
2199
+ type: "tween",
2200
+ ease: "linear",
2201
+ duration: 0.2,
2202
+ when: "beforeChildren"
2203
+ }
2204
+ },
2205
+ exit: { translateX: "-100%" },
2206
+ className: reablocks.cn(theme.sessions.base, {
2207
+ [theme.sessions.companion]: isCompact,
2208
+ [theme.sessions.console]: !isCompact
2209
+ }),
2210
+ children: [
2211
+ /* @__PURE__ */ jsxRuntime.jsx(reablocks.List, { children }),
2212
+ 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(
2213
+ SessionListItem,
2214
+ {
2215
+ session: {
2216
+ id: template.id,
2217
+ title: template.title,
2218
+ conversations: []
2219
+ },
2220
+ chatIcon: template.icon,
2221
+ deletable: false
2222
+ }
2223
+ ) }, template.id)) })
2224
+ ]
2225
+ }
2226
+ );
2227
+ };
2207
2228
  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" })));
2208
2229
  const NewSessionButton = ({
2209
2230
  children,
@@ -2311,7 +2332,156 @@ ${response}`),
2311
2332
  const groups = React.useMemo(() => groupSessionsByDate(sessions), [sessions]);
2312
2333
  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)) })) });
2313
2334
  };
2335
+ const AppBar = ({
2336
+ content,
2337
+ theme: customTheme = chatTheme
2338
+ }) => {
2339
+ const theme = reablocks.useComponentTheme("chat", customTheme);
2340
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: reablocks.cn(theme.appbar), children: content });
2341
+ };
2342
+ const defaultPositions = {
2343
+ "bottom-left": "bottom-5 left-5",
2344
+ "bottom-right": "bottom-5 right-5",
2345
+ "top-left": "top-5 left-5",
2346
+ "top-right": "top-5 right-5"
2347
+ };
2348
+ const ChatBubble = React.memo(
2349
+ ({
2350
+ children,
2351
+ bubbleContent,
2352
+ position = "bottom-left",
2353
+ customPosition,
2354
+ portalTarget = typeof document !== "undefined" ? document.body : null,
2355
+ className
2356
+ }) => {
2357
+ const [isOpen, setIsOpen] = React.useState(false);
2358
+ const bubbleRef = React.useRef(null);
2359
+ const contentRef = React.useRef(null);
2360
+ const [bubbleRect, setBubbleRect] = React.useState(null);
2361
+ React.useEffect(() => {
2362
+ if (bubbleRef.current) {
2363
+ setBubbleRect(bubbleRef.current.getBoundingClientRect());
2364
+ }
2365
+ }, [isOpen]);
2366
+ const handleClose = React.useCallback(() => {
2367
+ setIsOpen(false);
2368
+ }, []);
2369
+ const handleToggle = React.useCallback(() => {
2370
+ setIsOpen((prev) => !prev);
2371
+ }, []);
2372
+ const getContentPosition = () => {
2373
+ if (!bubbleRect) return {};
2374
+ const positions = {
2375
+ "bottom-left": {
2376
+ bottom: `calc(100vh - ${bubbleRect.top}px)`,
2377
+ left: `${bubbleRect.right}px`
2378
+ },
2379
+ "bottom-right": {
2380
+ bottom: `calc(100vh - ${bubbleRect.top}px)`,
2381
+ right: `calc(100vw - ${bubbleRect.left}px)`
2382
+ },
2383
+ "top-left": {
2384
+ top: `${bubbleRect.bottom}px`,
2385
+ left: `${bubbleRect.right}px`
2386
+ },
2387
+ "top-right": {
2388
+ top: `${bubbleRect.bottom}px`,
2389
+ right: `calc(100vw - ${bubbleRect.left}px)`
2390
+ }
2391
+ };
2392
+ return positions[position];
2393
+ };
2394
+ const content = React.useMemo(
2395
+ () => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2396
+ /* @__PURE__ */ jsxRuntime.jsx(
2397
+ "div",
2398
+ {
2399
+ ref: bubbleRef,
2400
+ style: {
2401
+ ...customPosition,
2402
+ ...portalTarget ? { position: "absolute" } : {}
2403
+ },
2404
+ onClick: handleToggle,
2405
+ className: reablocks.cn(
2406
+ "z-[1000]",
2407
+ !portalTarget && "fixed",
2408
+ defaultPositions[position],
2409
+ "cursor-pointer",
2410
+ className
2411
+ ),
2412
+ role: "button",
2413
+ tabIndex: 0,
2414
+ "aria-label": "Open chat",
2415
+ children: bubbleContent
2416
+ }
2417
+ ),
2418
+ /* @__PURE__ */ jsxRuntime.jsx(react.AnimatePresence, { children: children && isOpen && bubbleRect && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2419
+ /* @__PURE__ */ jsxRuntime.jsx(
2420
+ react.motion.div,
2421
+ {
2422
+ initial: { opacity: 0 },
2423
+ animate: { opacity: 0.5 },
2424
+ exit: { opacity: 0 },
2425
+ className: "fixed inset-0 z-[998]",
2426
+ onClick: handleClose
2427
+ }
2428
+ ),
2429
+ /* @__PURE__ */ jsxRuntime.jsx(
2430
+ react.motion.div,
2431
+ {
2432
+ ref: contentRef,
2433
+ initial: false,
2434
+ animate: {
2435
+ opacity: 1,
2436
+ scale: 1,
2437
+ x: 0,
2438
+ pointerEvents: "auto"
2439
+ },
2440
+ exit: {
2441
+ opacity: 0,
2442
+ scale: 0.8,
2443
+ x: position.includes("right") ? 20 : -20,
2444
+ pointerEvents: "none"
2445
+ },
2446
+ transition: { type: "spring", duration: 0.5 },
2447
+ className: reablocks.cn(
2448
+ "fixed z-[999]",
2449
+ position.includes("right") ? "origin-right" : "origin-left",
2450
+ position.includes("top") ? "origin-top" : "origin-bottom"
2451
+ ),
2452
+ style: getContentPosition(),
2453
+ children
2454
+ }
2455
+ )
2456
+ ] }) })
2457
+ ] }),
2458
+ [
2459
+ children,
2460
+ customPosition,
2461
+ portalTarget,
2462
+ position,
2463
+ className,
2464
+ bubbleContent,
2465
+ isOpen,
2466
+ handleClose,
2467
+ handleToggle,
2468
+ bubbleRect
2469
+ ]
2470
+ );
2471
+ if (!portalTarget) {
2472
+ return content;
2473
+ }
2474
+ try {
2475
+ return reactDom.createPortal(content, portalTarget);
2476
+ } catch (error) {
2477
+ console.error("Failed to create portal for ChatBubble:", error);
2478
+ return content;
2479
+ }
2480
+ }
2481
+ );
2482
+ exports2.AppBar = AppBar;
2314
2483
  exports2.Chat = Chat;
2484
+ exports2.ChatBubble = ChatBubble;
2315
2485
  exports2.ChatContext = ChatContext;
2316
2486
  exports2.ChatInput = ChatInput;
2317
2487
  exports2.CodeHighlighter = CodeHighlighter;