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.
- package/dist/ChatInput.d.ts +8 -2
- package/dist/docs.json +4 -4
- package/dist/index.js +42 -16
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +40 -14
- package/dist/index.umd.cjs.map +1 -1
- package/dist/theme.d.ts +2 -0
- package/package.json +1 -1
package/dist/ChatInput.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
2
|
|
|
3
3
|
interface ChatInputProps {
|
|
4
4
|
/**
|
|
@@ -26,5 +26,11 @@ interface ChatInputProps {
|
|
|
26
26
|
*/
|
|
27
27
|
attachIcon?: ReactElement;
|
|
28
28
|
}
|
|
29
|
-
export
|
|
29
|
+
export interface ChatInputRef {
|
|
30
|
+
/**
|
|
31
|
+
* Focus the input.
|
|
32
|
+
*/
|
|
33
|
+
focus: () => void;
|
|
34
|
+
}
|
|
35
|
+
export declare const ChatInput: import('react').ForwardRefExoticComponent<ChatInputProps & import('react').RefAttributes<ChatInputRef>>;
|
|
30
36
|
export {};
|
package/dist/docs.json
CHANGED
|
@@ -123,7 +123,9 @@
|
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
"remarkPlugins": {
|
|
126
|
-
"defaultValue":
|
|
126
|
+
"defaultValue": {
|
|
127
|
+
"value": "[remarkGfm, remarkYoutube, remarkMath]"
|
|
128
|
+
},
|
|
127
129
|
"description": "Remark plugins to apply to the request/response.",
|
|
128
130
|
"name": "remarkPlugins",
|
|
129
131
|
"parent": {
|
|
@@ -559,9 +561,7 @@
|
|
|
559
561
|
"methods": [],
|
|
560
562
|
"props": {
|
|
561
563
|
"remarkPlugins": {
|
|
562
|
-
"defaultValue":
|
|
563
|
-
"value": "[remarkGfm, remarkMath]"
|
|
564
|
-
},
|
|
564
|
+
"defaultValue": null,
|
|
565
565
|
"description": "Remark plugins to apply to the markdown content.",
|
|
566
566
|
"name": "remarkPlugins",
|
|
567
567
|
"parent": {
|
package/dist/index.js
CHANGED
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
})();
|
|
13
13
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
14
14
|
import * as React from "react";
|
|
15
|
-
import { createContext, useContext, useState, useRef, useEffect, useMemo, useCallback } from "react";
|
|
15
|
+
import { createContext, forwardRef, useContext, useState, useRef, useImperativeHandle, useEffect, useMemo, useCallback } from "react";
|
|
16
16
|
import { cn, Textarea, Button, Ellipsis, DateFormat, IconButton, Card, Divider, useInfinityList, useComponentTheme, List, ListItem } from "reablocks";
|
|
17
17
|
import { Slot } from "@radix-ui/react-slot";
|
|
18
18
|
import { motion, AnimatePresence } from "framer-motion";
|
|
19
19
|
import ReactMarkdown from "react-markdown";
|
|
20
|
-
import remarkGfm from "remark-gfm";
|
|
21
20
|
import { Prism } from "react-syntax-highlighter";
|
|
22
21
|
import rehypeKatex from "rehype-katex";
|
|
23
|
-
import remarkMath from "remark-math";
|
|
24
22
|
import { findAndReplace } from "mdast-util-find-and-replace";
|
|
25
|
-
import remarkYoutube from "remark-youtube";
|
|
26
23
|
import { useHotkeys } from "reakeys";
|
|
24
|
+
import remarkGfm from "remark-gfm";
|
|
25
|
+
import remarkYoutube from "remark-youtube";
|
|
26
|
+
import remarkMath from "remark-math";
|
|
27
27
|
import { isToday, isYesterday, isThisWeek, isThisMonth, isThisYear, format } from "date-fns";
|
|
28
28
|
const SvgSend = (props) => /* @__PURE__ */ React.createElement("svg", { width: 17, height: 17, viewBox: "0 0 17 17", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React.createElement("g", { id: "send" }, /* @__PURE__ */ React.createElement("path", { id: "Vector", d: "M14.6111 2.33327C14.5349 2.3339 14.4598 2.35194 14.3917 2.386L2.39168 8.386C2.31456 8.42456 2.24872 8.4824 2.20055 8.55391C2.15238 8.62543 2.12352 8.70818 2.11677 8.79414C2.11002 8.88009 2.12561 8.96634 2.16203 9.04449C2.19845 9.12264 2.25446 9.19005 2.32462 9.24017L4.52514 10.8124L5.47371 13.6581C5.50257 13.7447 5.55457 13.8217 5.62406 13.8808C5.69355 13.9399 5.7779 13.9789 5.86796 13.9935C5.95802 14.0082 6.05036 13.9979 6.13499 13.9638C6.21962 13.9297 6.2933 13.873 6.34806 13.8001L7.05249 12.8606L10.3207 15.2376C10.3843 15.2839 10.4579 15.3146 10.5355 15.3271C10.6132 15.3396 10.6927 15.3336 10.7676 15.3097C10.8425 15.2857 10.9107 15.2444 10.9667 15.1891C11.0226 15.1338 11.0647 15.0661 11.0896 14.9915L15.0896 2.99147C15.1148 2.91597 15.1216 2.83555 15.1094 2.7569C15.0972 2.67825 15.0665 2.60363 15.0197 2.53926C14.9729 2.47488 14.9114 2.42261 14.8403 2.38678C14.7693 2.35096 14.6907 2.33261 14.6111 2.33327ZM13.2478 5.35345L10.3565 14.0266L7.67293 12.0755L13.2478 5.35345ZM10.684 5.35801L4.934 9.87559L3.58113 8.90879L10.684 5.35801ZM11.2784 6.16205L6.56746 11.843C6.56681 11.8437 6.56616 11.8443 6.56551 11.845L6.56355 11.8476C6.55841 11.8538 6.55342 11.8601 6.54858 11.8665C6.54319 11.8733 6.53798 11.8802 6.53295 11.8873L6.12085 12.4361L5.53426 10.6751L11.2784 6.16205Z", fill: "currentColor" })));
|
|
29
29
|
const SvgStop = (props) => /* @__PURE__ */ React.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-octagon-x", ...props }, /* @__PURE__ */ React.createElement("path", { d: "m15 9-6 6" }), /* @__PURE__ */ React.createElement("path", { d: "M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z" }), /* @__PURE__ */ React.createElement("path", { d: "m9 9 6 6" }));
|
|
@@ -32,17 +32,24 @@ const ChatContext = createContext({
|
|
|
32
32
|
sessions: [],
|
|
33
33
|
activeSessionId: null
|
|
34
34
|
});
|
|
35
|
-
const ChatInput = ({
|
|
35
|
+
const ChatInput = forwardRef(({
|
|
36
36
|
allowedFiles,
|
|
37
37
|
placeholder,
|
|
38
38
|
defaultValue,
|
|
39
39
|
sendIcon = /* @__PURE__ */ jsx(SvgSend, {}),
|
|
40
40
|
stopIcon = /* @__PURE__ */ jsx(SvgStop, {}),
|
|
41
41
|
attachIcon = /* @__PURE__ */ jsx(SvgPaperclip, {})
|
|
42
|
-
}) => {
|
|
42
|
+
}, ref) => {
|
|
43
43
|
const { theme, isLoading, disabled, sendMessage, stopMessage, fileUpload } = useContext(ChatContext);
|
|
44
44
|
const [message, setMessage] = useState("");
|
|
45
45
|
const fileInputRef = useRef(null);
|
|
46
|
+
const inputRef = useRef(null);
|
|
47
|
+
useImperativeHandle(ref, () => ({
|
|
48
|
+
focus: () => {
|
|
49
|
+
var _a;
|
|
50
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
46
53
|
const handleSendMessage = () => {
|
|
47
54
|
if (message.trim()) {
|
|
48
55
|
sendMessage == null ? void 0 : sendMessage(message);
|
|
@@ -66,15 +73,16 @@ const ChatInput = ({
|
|
|
66
73
|
/* @__PURE__ */ jsx(
|
|
67
74
|
Textarea,
|
|
68
75
|
{
|
|
76
|
+
inputRef,
|
|
69
77
|
containerClassName: cn(theme.input.input),
|
|
70
78
|
minRows: 1,
|
|
71
79
|
autoFocus: true,
|
|
72
80
|
value: message,
|
|
73
|
-
onChange: (e) => setMessage(e.target.value),
|
|
74
81
|
defaultValue,
|
|
75
82
|
onKeyPress: handleKeyPress,
|
|
76
83
|
placeholder,
|
|
77
|
-
disabled: isLoading || disabled
|
|
84
|
+
disabled: isLoading || disabled,
|
|
85
|
+
onChange: (e) => setMessage(e.target.value)
|
|
78
86
|
}
|
|
79
87
|
),
|
|
80
88
|
/* @__PURE__ */ jsxs("div", { className: cn(theme.input.actions.base), children: [
|
|
@@ -126,7 +134,7 @@ const ChatInput = ({
|
|
|
126
134
|
)
|
|
127
135
|
] })
|
|
128
136
|
] });
|
|
129
|
-
};
|
|
137
|
+
});
|
|
130
138
|
const SessionEmpty = ({
|
|
131
139
|
children
|
|
132
140
|
}) => {
|
|
@@ -1239,7 +1247,7 @@ const TableHeaderCell = ({ children, ...props }) => /* @__PURE__ */ jsx("th", {
|
|
|
1239
1247
|
const TableDataCell = ({ children, ...props }) => /* @__PURE__ */ jsx("td", { ...props, children });
|
|
1240
1248
|
const Markdown = ({
|
|
1241
1249
|
children,
|
|
1242
|
-
remarkPlugins
|
|
1250
|
+
remarkPlugins,
|
|
1243
1251
|
rehypePlugins = [rehypeKatex]
|
|
1244
1252
|
}) => {
|
|
1245
1253
|
const { theme } = useContext(ChatContext);
|
|
@@ -1296,9 +1304,25 @@ const MessageQuestion = ({
|
|
|
1296
1304
|
question,
|
|
1297
1305
|
children
|
|
1298
1306
|
}) => {
|
|
1299
|
-
const { theme, remarkPlugins
|
|
1307
|
+
const { theme, remarkPlugins } = useContext(ChatContext);
|
|
1300
1308
|
const Comp = children ? Slot : "div";
|
|
1301
|
-
|
|
1309
|
+
const [expanded, setExpanded] = useState(false);
|
|
1310
|
+
const isLong = question.length > 500;
|
|
1311
|
+
return /* @__PURE__ */ jsxs(Comp, { className: cn(theme.messages.message.question, {
|
|
1312
|
+
[theme.messages.message.overlay]: isLong && !expanded
|
|
1313
|
+
}), children: [
|
|
1314
|
+
children || /* @__PURE__ */ jsx(Markdown, { remarkPlugins, children: question }),
|
|
1315
|
+
isLong && !expanded && /* @__PURE__ */ jsx(
|
|
1316
|
+
Button,
|
|
1317
|
+
{
|
|
1318
|
+
variant: "link",
|
|
1319
|
+
size: "small",
|
|
1320
|
+
className: theme.messages.message.expand,
|
|
1321
|
+
onClick: () => setExpanded(true),
|
|
1322
|
+
children: "Show more"
|
|
1323
|
+
}
|
|
1324
|
+
)
|
|
1325
|
+
] });
|
|
1302
1326
|
};
|
|
1303
1327
|
const MessageResponse = ({
|
|
1304
1328
|
response,
|
|
@@ -1308,7 +1332,7 @@ const MessageResponse = ({
|
|
|
1308
1332
|
const {
|
|
1309
1333
|
theme,
|
|
1310
1334
|
isCompact,
|
|
1311
|
-
remarkPlugins
|
|
1335
|
+
remarkPlugins
|
|
1312
1336
|
} = useContext(ChatContext);
|
|
1313
1337
|
const Comp = children ? Slot : "div";
|
|
1314
1338
|
return /* @__PURE__ */ jsx(
|
|
@@ -1629,11 +1653,13 @@ const chatTheme = {
|
|
|
1629
1653
|
message: {
|
|
1630
1654
|
base: "mt-4 mb-4 flex flex-col p-0 rounded border-none bg-transparent",
|
|
1631
1655
|
question: [
|
|
1632
|
-
"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",
|
|
1656
|
+
"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",
|
|
1633
1657
|
"dark:bg-gray-900/60 dark:border-gray-700/50 dark:text-gray-100"
|
|
1634
1658
|
].join(" "),
|
|
1635
|
-
response: ["data-[compact=false]:px-4 text-gray-900", "dark:text-gray-100"].join(" "),
|
|
1659
|
+
response: ["relative data-[compact=false]:px-4 text-gray-900", "dark:text-gray-100"].join(" "),
|
|
1660
|
+
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`,
|
|
1636
1661
|
cursor: "inline-block w-1 h-4 bg-current",
|
|
1662
|
+
expand: "absolute bottom-1 right-1 z-10",
|
|
1637
1663
|
files: {
|
|
1638
1664
|
base: "mb-2 flex flex-wrap gap-3 ",
|
|
1639
1665
|
file: {
|
|
@@ -1732,7 +1758,7 @@ const Chat = ({
|
|
|
1732
1758
|
activeSessionId,
|
|
1733
1759
|
theme: customTheme = chatTheme,
|
|
1734
1760
|
onNewSession,
|
|
1735
|
-
remarkPlugins,
|
|
1761
|
+
remarkPlugins = [remarkGfm, remarkYoutube, remarkMath],
|
|
1736
1762
|
disabled,
|
|
1737
1763
|
style,
|
|
1738
1764
|
className
|