@yext/chat-ui-react 0.12.1 → 0.12.3
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/THIRD-PARTY-NOTICES +3 -3
- package/package.json +15 -4
- package/lib/bundle.css +0 -1
- package/lib/commonjs/package.json.js +0 -6
- package/lib/commonjs/package.json.js.map +0 -1
- package/lib/commonjs/src/components/ChatHeader.d.ts +0 -53
- package/lib/commonjs/src/components/ChatHeader.d.ts.map +0 -1
- package/lib/commonjs/src/components/ChatHeader.js +0 -52
- package/lib/commonjs/src/components/ChatHeader.js.map +0 -1
- package/lib/commonjs/src/components/ChatInput.d.ts +0 -60
- package/lib/commonjs/src/components/ChatInput.d.ts.map +0 -1
- package/lib/commonjs/src/components/ChatInput.js +0 -76
- package/lib/commonjs/src/components/ChatInput.js.map +0 -1
- package/lib/commonjs/src/components/ChatPanel.d.ts +0 -74
- package/lib/commonjs/src/components/ChatPanel.d.ts.map +0 -1
- package/lib/commonjs/src/components/ChatPanel.js +0 -178
- package/lib/commonjs/src/components/ChatPanel.js.map +0 -1
- package/lib/commonjs/src/components/ChatPopUp.d.ts +0 -76
- package/lib/commonjs/src/components/ChatPopUp.d.ts.map +0 -1
- package/lib/commonjs/src/components/ChatPopUp.js +0 -160
- package/lib/commonjs/src/components/ChatPopUp.js.map +0 -1
- package/lib/commonjs/src/components/FeedbackButtons.d.ts +0 -35
- package/lib/commonjs/src/components/FeedbackButtons.d.ts.map +0 -1
- package/lib/commonjs/src/components/FeedbackButtons.js +0 -59
- package/lib/commonjs/src/components/FeedbackButtons.js.map +0 -1
- package/lib/commonjs/src/components/InitialMessagePopUp.d.ts +0 -33
- package/lib/commonjs/src/components/InitialMessagePopUp.d.ts.map +0 -1
- package/lib/commonjs/src/components/InitialMessagePopUp.js +0 -44
- package/lib/commonjs/src/components/InitialMessagePopUp.js.map +0 -1
- package/lib/commonjs/src/components/LoadingDots.d.ts +0 -10
- package/lib/commonjs/src/components/LoadingDots.d.ts.map +0 -1
- package/lib/commonjs/src/components/LoadingDots.js +0 -23
- package/lib/commonjs/src/components/LoadingDots.js.map +0 -1
- package/lib/commonjs/src/components/Markdown.d.ts +0 -39
- package/lib/commonjs/src/components/Markdown.d.ts.map +0 -1
- package/lib/commonjs/src/components/Markdown.js +0 -72
- package/lib/commonjs/src/components/Markdown.js.map +0 -1
- package/lib/commonjs/src/components/MessageBubble.d.ts +0 -64
- package/lib/commonjs/src/components/MessageBubble.d.ts.map +0 -1
- package/lib/commonjs/src/components/MessageBubble.js +0 -77
- package/lib/commonjs/src/components/MessageBubble.js.map +0 -1
- package/lib/commonjs/src/components/MessageSuggestions.d.ts +0 -37
- package/lib/commonjs/src/components/MessageSuggestions.d.ts.map +0 -1
- package/lib/commonjs/src/components/MessageSuggestions.js +0 -55
- package/lib/commonjs/src/components/MessageSuggestions.js.map +0 -1
- package/lib/commonjs/src/components/index.d.ts +0 -14
- package/lib/commonjs/src/components/index.d.ts.map +0 -1
- package/lib/commonjs/src/hooks/index.d.ts +0 -3
- package/lib/commonjs/src/hooks/index.d.ts.map +0 -1
- package/lib/commonjs/src/hooks/useComposedCssClasses.d.ts +0 -30
- package/lib/commonjs/src/hooks/useComposedCssClasses.d.ts.map +0 -1
- package/lib/commonjs/src/hooks/useComposedCssClasses.js +0 -61
- package/lib/commonjs/src/hooks/useComposedCssClasses.js.map +0 -1
- package/lib/commonjs/src/hooks/useDefaultHandleApiError.d.ts +0 -8
- package/lib/commonjs/src/hooks/useDefaultHandleApiError.d.ts.map +0 -1
- package/lib/commonjs/src/hooks/useDefaultHandleApiError.js +0 -25
- package/lib/commonjs/src/hooks/useDefaultHandleApiError.js.map +0 -1
- package/lib/commonjs/src/hooks/useFetchInitialMessage.d.ts +0 -13
- package/lib/commonjs/src/hooks/useFetchInitialMessage.d.ts.map +0 -1
- package/lib/commonjs/src/hooks/useFetchInitialMessage.js +0 -41
- package/lib/commonjs/src/hooks/useFetchInitialMessage.js.map +0 -1
- package/lib/commonjs/src/hooks/useReportAnalyticsEvent.d.ts +0 -8
- package/lib/commonjs/src/hooks/useReportAnalyticsEvent.d.ts.map +0 -1
- package/lib/commonjs/src/hooks/useReportAnalyticsEvent.js +0 -21
- package/lib/commonjs/src/hooks/useReportAnalyticsEvent.js.map +0 -1
- package/lib/commonjs/src/hooks/useSendMessageWithRetries.d.ts +0 -17
- package/lib/commonjs/src/hooks/useSendMessageWithRetries.d.ts.map +0 -1
- package/lib/commonjs/src/hooks/useSendMessageWithRetries.js +0 -54
- package/lib/commonjs/src/hooks/useSendMessageWithRetries.js.map +0 -1
- package/lib/commonjs/src/icons/Arrow.d.ts +0 -3
- package/lib/commonjs/src/icons/Arrow.d.ts.map +0 -1
- package/lib/commonjs/src/icons/Arrow.js +0 -16
- package/lib/commonjs/src/icons/Arrow.js.map +0 -1
- package/lib/commonjs/src/icons/Chat.d.ts +0 -5
- package/lib/commonjs/src/icons/Chat.d.ts.map +0 -1
- package/lib/commonjs/src/icons/Chat.js +0 -20
- package/lib/commonjs/src/icons/Chat.js.map +0 -1
- package/lib/commonjs/src/icons/Cross.d.ts +0 -5
- package/lib/commonjs/src/icons/Cross.d.ts.map +0 -1
- package/lib/commonjs/src/icons/Cross.js +0 -16
- package/lib/commonjs/src/icons/Cross.js.map +0 -1
- package/lib/commonjs/src/icons/DualSync.d.ts +0 -5
- package/lib/commonjs/src/icons/DualSync.d.ts.map +0 -1
- package/lib/commonjs/src/icons/DualSync.js +0 -16
- package/lib/commonjs/src/icons/DualSync.js.map +0 -1
- package/lib/commonjs/src/icons/ThumbsDown.d.ts +0 -5
- package/lib/commonjs/src/icons/ThumbsDown.d.ts.map +0 -1
- package/lib/commonjs/src/icons/ThumbsDown.js +0 -15
- package/lib/commonjs/src/icons/ThumbsDown.js.map +0 -1
- package/lib/commonjs/src/icons/ThumbsDownFill.d.ts +0 -5
- package/lib/commonjs/src/icons/ThumbsDownFill.d.ts.map +0 -1
- package/lib/commonjs/src/icons/ThumbsDownFill.js +0 -15
- package/lib/commonjs/src/icons/ThumbsDownFill.js.map +0 -1
- package/lib/commonjs/src/icons/ThumbsUp.d.ts +0 -5
- package/lib/commonjs/src/icons/ThumbsUp.d.ts.map +0 -1
- package/lib/commonjs/src/icons/ThumbsUp.js +0 -15
- package/lib/commonjs/src/icons/ThumbsUp.js.map +0 -1
- package/lib/commonjs/src/icons/ThumbsUpFill.d.ts +0 -5
- package/lib/commonjs/src/icons/ThumbsUpFill.d.ts.map +0 -1
- package/lib/commonjs/src/icons/ThumbsUpFill.js +0 -15
- package/lib/commonjs/src/icons/ThumbsUpFill.js.map +0 -1
- package/lib/commonjs/src/index.d.ts +0 -3
- package/lib/commonjs/src/index.d.ts.map +0 -1
- package/lib/commonjs/src/index.js +0 -20
- package/lib/commonjs/src/index.js.map +0 -1
- package/lib/commonjs/src/tsdoc-metadata.json +0 -11
- package/lib/commonjs/src/utils/withStylelessCssClasses.d.ts +0 -17
- package/lib/commonjs/src/utils/withStylelessCssClasses.d.ts.map +0 -1
- package/lib/commonjs/src/utils/withStylelessCssClasses.js +0 -30
- package/lib/commonjs/src/utils/withStylelessCssClasses.js.map +0 -1
- package/lib/esm/index.d.ts +0 -411
- package/lib/esm/package.json.mjs +0 -4
- package/lib/esm/package.json.mjs.map +0 -1
- package/lib/esm/src/components/ChatHeader.d.ts +0 -53
- package/lib/esm/src/components/ChatHeader.d.ts.map +0 -1
- package/lib/esm/src/components/ChatHeader.mjs +0 -46
- package/lib/esm/src/components/ChatHeader.mjs.map +0 -1
- package/lib/esm/src/components/ChatInput.d.ts +0 -60
- package/lib/esm/src/components/ChatInput.d.ts.map +0 -1
- package/lib/esm/src/components/ChatInput.mjs +0 -69
- package/lib/esm/src/components/ChatInput.mjs.map +0 -1
- package/lib/esm/src/components/ChatPanel.d.ts +0 -74
- package/lib/esm/src/components/ChatPanel.d.ts.map +0 -1
- package/lib/esm/src/components/ChatPanel.mjs +0 -169
- package/lib/esm/src/components/ChatPanel.mjs.map +0 -1
- package/lib/esm/src/components/ChatPopUp.d.ts +0 -76
- package/lib/esm/src/components/ChatPopUp.d.ts.map +0 -1
- package/lib/esm/src/components/ChatPopUp.mjs +0 -154
- package/lib/esm/src/components/ChatPopUp.mjs.map +0 -1
- package/lib/esm/src/components/FeedbackButtons.d.ts +0 -35
- package/lib/esm/src/components/FeedbackButtons.d.ts.map +0 -1
- package/lib/esm/src/components/FeedbackButtons.mjs +0 -53
- package/lib/esm/src/components/FeedbackButtons.mjs.map +0 -1
- package/lib/esm/src/components/InitialMessagePopUp.d.ts +0 -33
- package/lib/esm/src/components/InitialMessagePopUp.d.ts.map +0 -1
- package/lib/esm/src/components/InitialMessagePopUp.mjs +0 -38
- package/lib/esm/src/components/InitialMessagePopUp.mjs.map +0 -1
- package/lib/esm/src/components/LoadingDots.d.ts +0 -10
- package/lib/esm/src/components/LoadingDots.d.ts.map +0 -1
- package/lib/esm/src/components/LoadingDots.mjs +0 -17
- package/lib/esm/src/components/LoadingDots.mjs.map +0 -1
- package/lib/esm/src/components/Markdown.d.ts +0 -39
- package/lib/esm/src/components/Markdown.d.ts.map +0 -1
- package/lib/esm/src/components/Markdown.mjs +0 -62
- package/lib/esm/src/components/Markdown.mjs.map +0 -1
- package/lib/esm/src/components/MessageBubble.d.ts +0 -64
- package/lib/esm/src/components/MessageBubble.d.ts.map +0 -1
- package/lib/esm/src/components/MessageBubble.mjs +0 -71
- package/lib/esm/src/components/MessageBubble.mjs.map +0 -1
- package/lib/esm/src/components/MessageSuggestions.d.ts +0 -37
- package/lib/esm/src/components/MessageSuggestions.d.ts.map +0 -1
- package/lib/esm/src/components/MessageSuggestions.mjs +0 -49
- package/lib/esm/src/components/MessageSuggestions.mjs.map +0 -1
- package/lib/esm/src/components/index.d.ts +0 -14
- package/lib/esm/src/components/index.d.ts.map +0 -1
- package/lib/esm/src/hooks/index.d.ts +0 -3
- package/lib/esm/src/hooks/index.d.ts.map +0 -1
- package/lib/esm/src/hooks/useComposedCssClasses.d.ts +0 -30
- package/lib/esm/src/hooks/useComposedCssClasses.d.ts.map +0 -1
- package/lib/esm/src/hooks/useComposedCssClasses.mjs +0 -59
- package/lib/esm/src/hooks/useComposedCssClasses.mjs.map +0 -1
- package/lib/esm/src/hooks/useDefaultHandleApiError.d.ts +0 -8
- package/lib/esm/src/hooks/useDefaultHandleApiError.d.ts.map +0 -1
- package/lib/esm/src/hooks/useDefaultHandleApiError.mjs +0 -23
- package/lib/esm/src/hooks/useDefaultHandleApiError.mjs.map +0 -1
- package/lib/esm/src/hooks/useFetchInitialMessage.d.ts +0 -13
- package/lib/esm/src/hooks/useFetchInitialMessage.d.ts.map +0 -1
- package/lib/esm/src/hooks/useFetchInitialMessage.mjs +0 -39
- package/lib/esm/src/hooks/useFetchInitialMessage.mjs.map +0 -1
- package/lib/esm/src/hooks/useReportAnalyticsEvent.d.ts +0 -8
- package/lib/esm/src/hooks/useReportAnalyticsEvent.d.ts.map +0 -1
- package/lib/esm/src/hooks/useReportAnalyticsEvent.mjs +0 -19
- package/lib/esm/src/hooks/useReportAnalyticsEvent.mjs.map +0 -1
- package/lib/esm/src/hooks/useSendMessageWithRetries.d.ts +0 -17
- package/lib/esm/src/hooks/useSendMessageWithRetries.d.ts.map +0 -1
- package/lib/esm/src/hooks/useSendMessageWithRetries.mjs +0 -52
- package/lib/esm/src/hooks/useSendMessageWithRetries.mjs.map +0 -1
- package/lib/esm/src/icons/Arrow.d.ts +0 -3
- package/lib/esm/src/icons/Arrow.d.ts.map +0 -1
- package/lib/esm/src/icons/Arrow.mjs +0 -10
- package/lib/esm/src/icons/Arrow.mjs.map +0 -1
- package/lib/esm/src/icons/Chat.d.ts +0 -5
- package/lib/esm/src/icons/Chat.d.ts.map +0 -1
- package/lib/esm/src/icons/Chat.mjs +0 -14
- package/lib/esm/src/icons/Chat.mjs.map +0 -1
- package/lib/esm/src/icons/Cross.d.ts +0 -5
- package/lib/esm/src/icons/Cross.d.ts.map +0 -1
- package/lib/esm/src/icons/Cross.mjs +0 -10
- package/lib/esm/src/icons/Cross.mjs.map +0 -1
- package/lib/esm/src/icons/DualSync.d.ts +0 -5
- package/lib/esm/src/icons/DualSync.d.ts.map +0 -1
- package/lib/esm/src/icons/DualSync.mjs +0 -10
- package/lib/esm/src/icons/DualSync.mjs.map +0 -1
- package/lib/esm/src/icons/ThumbsDown.d.ts +0 -5
- package/lib/esm/src/icons/ThumbsDown.d.ts.map +0 -1
- package/lib/esm/src/icons/ThumbsDown.mjs +0 -9
- package/lib/esm/src/icons/ThumbsDown.mjs.map +0 -1
- package/lib/esm/src/icons/ThumbsDownFill.d.ts +0 -5
- package/lib/esm/src/icons/ThumbsDownFill.d.ts.map +0 -1
- package/lib/esm/src/icons/ThumbsDownFill.mjs +0 -9
- package/lib/esm/src/icons/ThumbsDownFill.mjs.map +0 -1
- package/lib/esm/src/icons/ThumbsUp.d.ts +0 -5
- package/lib/esm/src/icons/ThumbsUp.d.ts.map +0 -1
- package/lib/esm/src/icons/ThumbsUp.mjs +0 -9
- package/lib/esm/src/icons/ThumbsUp.mjs.map +0 -1
- package/lib/esm/src/icons/ThumbsUpFill.d.ts +0 -5
- package/lib/esm/src/icons/ThumbsUpFill.d.ts.map +0 -1
- package/lib/esm/src/icons/ThumbsUpFill.mjs +0 -9
- package/lib/esm/src/icons/ThumbsUpFill.mjs.map +0 -1
- package/lib/esm/src/index.d.ts +0 -3
- package/lib/esm/src/index.d.ts.map +0 -1
- package/lib/esm/src/index.mjs +0 -8
- package/lib/esm/src/index.mjs.map +0 -1
- package/lib/esm/src/utils/withStylelessCssClasses.d.ts +0 -17
- package/lib/esm/src/utils/withStylelessCssClasses.d.ts.map +0 -1
- package/lib/esm/src/utils/withStylelessCssClasses.mjs +0 -28
- package/lib/esm/src/utils/withStylelessCssClasses.mjs.map +0 -1
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
2
|
-
import { MessageSource } from '@yext/chat-headless-react';
|
|
3
|
-
import { useComposedCssClasses } from '../hooks/useComposedCssClasses.mjs';
|
|
4
|
-
import { twMerge } from 'tailwind-merge';
|
|
5
|
-
import { Markdown } from './Markdown.mjs';
|
|
6
|
-
import { withStylelessCssClasses } from '../utils/withStylelessCssClasses.mjs';
|
|
7
|
-
import { FeedbackButtons } from './FeedbackButtons.mjs';
|
|
8
|
-
|
|
9
|
-
const builtInCssClasses = withStylelessCssClasses("MessageBubble", {
|
|
10
|
-
topContainer: "w-full animate-fade-in @container",
|
|
11
|
-
subContainer: "flex flex-col @lg:flex-row @lg:items-center @lg:gap-x-2 @lg:m-1",
|
|
12
|
-
subContainer__bot: "",
|
|
13
|
-
subContainer__user: "@lg:flex-row-reverse",
|
|
14
|
-
bubble: "relative group peer w-fit max-w-[80%] rounded-2xl p-4",
|
|
15
|
-
bubble__bot: "bg-gradient-to-tr from-slate-50 to-slate-100",
|
|
16
|
-
bubble__user: "ml-auto @lg:ml-0 bg-gradient-to-tr from-blue-600 to-blue-700 text-white",
|
|
17
|
-
text: "text-[13px] @[480px]:text-base prose overflow-x-auto",
|
|
18
|
-
text__bot: "text-slate-900",
|
|
19
|
-
text__user: "text-white break-words",
|
|
20
|
-
timestamp: "w-fit ml-4 @lg:ml-0 text-slate-400 text-[10px] @[480px]:text-[13px] opacity-0 peer-hover:opacity-100 duration-200 whitespace-pre-wrap",
|
|
21
|
-
timestamp__bot: "",
|
|
22
|
-
timestamp__user: "ml-auto",
|
|
23
|
-
feedbackButtonsCssClasses: {},
|
|
24
|
-
});
|
|
25
|
-
/**
|
|
26
|
-
* A component that displays the provided message.
|
|
27
|
-
*
|
|
28
|
-
* @public
|
|
29
|
-
*
|
|
30
|
-
* @param props - {@link MessageBubbleProps}
|
|
31
|
-
*/
|
|
32
|
-
function MessageBubble({ message, showFeedbackButtons = true, showTimestamp = true, customCssClasses, formatTimestamp = defaultFormatTimestamp, linkTarget, onLinkClick, }) {
|
|
33
|
-
const cssClasses = useComposedCssClasses(builtInCssClasses, customCssClasses);
|
|
34
|
-
const bubbleCssClasses = twMerge(cssClasses.bubble, message.source === MessageSource.USER
|
|
35
|
-
? cssClasses.bubble__user
|
|
36
|
-
: cssClasses.bubble__bot);
|
|
37
|
-
const textCssClasses = twMerge(cssClasses.text, message.source === MessageSource.USER
|
|
38
|
-
? cssClasses.text__user
|
|
39
|
-
: cssClasses.text__bot);
|
|
40
|
-
const subContainerCssClasses = twMerge(cssClasses.subContainer, message.source === MessageSource.USER
|
|
41
|
-
? cssClasses.subContainer__user
|
|
42
|
-
: cssClasses.subContainer__bot);
|
|
43
|
-
const timestampCssClasses = twMerge(cssClasses.timestamp, message.source === MessageSource.USER
|
|
44
|
-
? cssClasses.timestamp__user
|
|
45
|
-
: cssClasses.timestamp__bot);
|
|
46
|
-
const markdownCssClasses = useMemo(() => ({
|
|
47
|
-
container: textCssClasses,
|
|
48
|
-
}), [textCssClasses]);
|
|
49
|
-
return (React.createElement("div", { className: cssClasses.topContainer },
|
|
50
|
-
React.createElement("div", { className: subContainerCssClasses },
|
|
51
|
-
React.createElement("div", { className: bubbleCssClasses },
|
|
52
|
-
showFeedbackButtons && message.source === MessageSource.BOT && (React.createElement(FeedbackButtons, { customCssClasses: cssClasses.feedbackButtonsCssClasses, responseId: message.responseId })),
|
|
53
|
-
React.createElement(Markdown, { content: message.text, responseId: message.responseId, customCssClasses: markdownCssClasses, linkTarget: linkTarget, onLinkClick: onLinkClick })),
|
|
54
|
-
showTimestamp && (React.createElement("div", { className: timestampCssClasses }, message.timestamp ? formatTimestamp(message.timestamp) : " ")))));
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Formats message's timestamp from "2023-05-18T19:33:34.553Z" to "7:33 PM"
|
|
58
|
-
*
|
|
59
|
-
* @param timestamp - the timestamp to convert from
|
|
60
|
-
* @returns formatted timestamp
|
|
61
|
-
*/
|
|
62
|
-
function defaultFormatTimestamp(timestamp) {
|
|
63
|
-
return new Date(timestamp).toLocaleString(undefined, {
|
|
64
|
-
hour: "numeric",
|
|
65
|
-
minute: "numeric",
|
|
66
|
-
hour12: true,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { MessageBubble };
|
|
71
|
-
//# sourceMappingURL=MessageBubble.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageBubble.mjs","sources":["../../../../src/components/MessageBubble.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { Message, MessageSource } from \"@yext/chat-headless-react\";\nimport { useComposedCssClasses } from \"../hooks\";\nimport { twMerge } from \"tailwind-merge\";\nimport { Markdown, MarkdownCssClasses } from \"./Markdown\";\nimport { withStylelessCssClasses } from \"../utils/withStylelessCssClasses\";\nimport { FeedbackButtons, FeedbackButtonsCssClasses } from \"./FeedbackButtons\";\n\n/**\n * The CSS class interface for the {@link MessageBubble} component.\n *\n * @public\n */\nexport interface MessageBubbleCssClasses {\n topContainer?: string;\n subContainer?: string;\n subContainer__bot?: string;\n subContainer__user?: string;\n bubble?: string;\n bubble__bot?: string;\n bubble__user?: string;\n text?: string;\n text__bot?: string;\n text__user?: string;\n timestamp?: string;\n timestamp__bot?: string;\n timestamp__user?: string;\n feedbackButtonsCssClasses?: FeedbackButtonsCssClasses;\n}\n\nconst builtInCssClasses: MessageBubbleCssClasses =\n withStylelessCssClasses<MessageBubbleCssClasses>(\"MessageBubble\", {\n topContainer: \"w-full animate-fade-in @container\",\n subContainer:\n \"flex flex-col @lg:flex-row @lg:items-center @lg:gap-x-2 @lg:m-1\",\n subContainer__bot: \"\",\n subContainer__user: \"@lg:flex-row-reverse\",\n bubble: \"relative group peer w-fit max-w-[80%] rounded-2xl p-4\",\n bubble__bot: \"bg-gradient-to-tr from-slate-50 to-slate-100\",\n bubble__user:\n \"ml-auto @lg:ml-0 bg-gradient-to-tr from-blue-600 to-blue-700 text-white\",\n text: \"text-[13px] @[480px]:text-base prose overflow-x-auto\",\n text__bot: \"text-slate-900\",\n text__user: \"text-white break-words\",\n timestamp:\n \"w-fit ml-4 @lg:ml-0 text-slate-400 text-[10px] @[480px]:text-[13px] opacity-0 peer-hover:opacity-100 duration-200 whitespace-pre-wrap\",\n timestamp__bot: \"\",\n timestamp__user: \"ml-auto\",\n feedbackButtonsCssClasses: {},\n });\n\n/**\n * The props for the {@link MessageBubble} component.\n *\n * @public\n */\nexport interface MessageBubbleProps {\n /** The message to display. */\n message: Message;\n /**\n * Whether to show the feedback buttons on the message bubble.\n * Defaults to true.\n */\n showFeedbackButtons?: boolean;\n /**\n * Whether to show the timestamp of the message with the message bubble.\n * Defaults to true.\n */\n showTimestamp?: boolean;\n /**\n * A function which is called to format the message's timestamp given in\n * ISO format (e.g. \"2023-05-18T19:33:34.553Z\").\n * Defaults to \"HH:MM A\" (e.g. \"7:33 PM\").\n */\n formatTimestamp?: (timestamp: string) => string;\n /** CSS classes for customizing the component styling. */\n customCssClasses?: MessageBubbleCssClasses;\n /** Link target open behavior on click. */\n linkTarget?: string;\n /** A callback which is called when user clicks a link. */\n onLinkClick?: (href?: string) => void;\n}\n\n/**\n * A component that displays the provided message.\n *\n * @public\n *\n * @param props - {@link MessageBubbleProps}\n */\nexport function MessageBubble({\n message,\n showFeedbackButtons = true,\n showTimestamp = true,\n customCssClasses,\n formatTimestamp = defaultFormatTimestamp,\n linkTarget,\n onLinkClick,\n}: MessageBubbleProps) {\n const cssClasses = useComposedCssClasses(builtInCssClasses, customCssClasses);\n const bubbleCssClasses = twMerge(\n cssClasses.bubble,\n message.source === MessageSource.USER\n ? cssClasses.bubble__user\n : cssClasses.bubble__bot\n );\n const textCssClasses = twMerge(\n cssClasses.text,\n message.source === MessageSource.USER\n ? cssClasses.text__user\n : cssClasses.text__bot\n );\n const subContainerCssClasses = twMerge(\n cssClasses.subContainer,\n message.source === MessageSource.USER\n ? cssClasses.subContainer__user\n : cssClasses.subContainer__bot\n );\n const timestampCssClasses = twMerge(\n cssClasses.timestamp,\n message.source === MessageSource.USER\n ? cssClasses.timestamp__user\n : cssClasses.timestamp__bot\n );\n\n const markdownCssClasses: MarkdownCssClasses = useMemo(\n () => ({\n container: textCssClasses,\n }),\n [textCssClasses]\n );\n\n return (\n <div className={cssClasses.topContainer}>\n <div className={subContainerCssClasses}>\n <div className={bubbleCssClasses}>\n {showFeedbackButtons && message.source === MessageSource.BOT && (\n <FeedbackButtons\n customCssClasses={cssClasses.feedbackButtonsCssClasses}\n responseId={message.responseId}\n />\n )}\n <Markdown\n content={message.text}\n responseId={message.responseId}\n customCssClasses={markdownCssClasses}\n linkTarget={linkTarget}\n onLinkClick={onLinkClick}\n />\n </div>\n {/* fallback on empty space here to perserve the height for timestamp div */}\n {showTimestamp && (\n <div className={timestampCssClasses}>\n {message.timestamp ? formatTimestamp(message.timestamp) : \" \"}\n </div>\n )}\n </div>\n </div>\n );\n}\n\n/**\n * Formats message's timestamp from \"2023-05-18T19:33:34.553Z\" to \"7:33 PM\"\n *\n * @param timestamp - the timestamp to convert from\n * @returns formatted timestamp\n */\nfunction defaultFormatTimestamp(timestamp: string): string {\n return new Date(timestamp).toLocaleString(undefined, {\n hour: \"numeric\",\n minute: \"numeric\",\n hour12: true,\n });\n}\n"],"names":[],"mappings":";;;;;;;;AA8BA,MAAM,iBAAiB,GACrB,uBAAuB,CAA0B,eAAe,EAAE;AAChE,IAAA,YAAY,EAAE,mCAAmC;AACjD,IAAA,YAAY,EACV,iEAAiE;AACnE,IAAA,iBAAiB,EAAE,EAAE;AACrB,IAAA,kBAAkB,EAAE,sBAAsB;AAC1C,IAAA,MAAM,EAAE,uDAAuD;AAC/D,IAAA,WAAW,EAAE,8CAA8C;AAC3D,IAAA,YAAY,EACV,yEAAyE;AAC3E,IAAA,IAAI,EAAE,sDAAsD;AAC5D,IAAA,SAAS,EAAE,gBAAgB;AAC3B,IAAA,UAAU,EAAE,wBAAwB;AACpC,IAAA,SAAS,EACP,uIAAuI;AACzI,IAAA,cAAc,EAAE,EAAE;AAClB,IAAA,eAAe,EAAE,SAAS;AAC1B,IAAA,yBAAyB,EAAE,EAAE;AAC9B,CAAA,CAAC,CAAC;AAkCL;;;;;;AAMG;AACG,SAAU,aAAa,CAAC,EAC5B,OAAO,EACP,mBAAmB,GAAG,IAAI,EAC1B,aAAa,GAAG,IAAI,EACpB,gBAAgB,EAChB,eAAe,GAAG,sBAAsB,EACxC,UAAU,EACV,WAAW,GACQ,EAAA;IACnB,MAAM,UAAU,GAAG,qBAAqB,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;AAC9E,IAAA,MAAM,gBAAgB,GAAG,OAAO,CAC9B,UAAU,CAAC,MAAM,EACjB,OAAO,CAAC,MAAM,KAAK,aAAa,CAAC,IAAI;UACjC,UAAU,CAAC,YAAY;AACzB,UAAE,UAAU,CAAC,WAAW,CAC3B,CAAC;AACF,IAAA,MAAM,cAAc,GAAG,OAAO,CAC5B,UAAU,CAAC,IAAI,EACf,OAAO,CAAC,MAAM,KAAK,aAAa,CAAC,IAAI;UACjC,UAAU,CAAC,UAAU;AACvB,UAAE,UAAU,CAAC,SAAS,CACzB,CAAC;AACF,IAAA,MAAM,sBAAsB,GAAG,OAAO,CACpC,UAAU,CAAC,YAAY,EACvB,OAAO,CAAC,MAAM,KAAK,aAAa,CAAC,IAAI;UACjC,UAAU,CAAC,kBAAkB;AAC/B,UAAE,UAAU,CAAC,iBAAiB,CACjC,CAAC;AACF,IAAA,MAAM,mBAAmB,GAAG,OAAO,CACjC,UAAU,CAAC,SAAS,EACpB,OAAO,CAAC,MAAM,KAAK,aAAa,CAAC,IAAI;UACjC,UAAU,CAAC,eAAe;AAC5B,UAAE,UAAU,CAAC,cAAc,CAC9B,CAAC;AAEF,IAAA,MAAM,kBAAkB,GAAuB,OAAO,CACpD,OAAO;AACL,QAAA,SAAS,EAAE,cAAc;AAC1B,KAAA,CAAC,EACF,CAAC,cAAc,CAAC,CACjB,CAAC;AAEF,IAAA,QACE,KAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,UAAU,CAAC,YAAY,EAAA;QACrC,KAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,sBAAsB,EAAA;YACpC,KAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,gBAAgB,EAAA;gBAC7B,mBAAmB,IAAI,OAAO,CAAC,MAAM,KAAK,aAAa,CAAC,GAAG,KAC1D,KAAC,CAAA,aAAA,CAAA,eAAe,IACd,gBAAgB,EAAE,UAAU,CAAC,yBAAyB,EACtD,UAAU,EAAE,OAAO,CAAC,UAAU,EAAA,CAC9B,CACH;gBACD,KAAC,CAAA,aAAA,CAAA,QAAQ,EACP,EAAA,OAAO,EAAE,OAAO,CAAC,IAAI,EACrB,UAAU,EAAE,OAAO,CAAC,UAAU,EAC9B,gBAAgB,EAAE,kBAAkB,EACpC,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EAAA,CACxB,CACE;AAEL,YAAA,aAAa,KACZ,KAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,mBAAmB,EAChC,EAAA,OAAO,CAAC,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,GAAG,CACzD,CACP,CACG,CACF,EACN;AACJ,CAAC;AAED;;;;;AAKG;AACH,SAAS,sBAAsB,CAAC,SAAiB,EAAA;IAC/C,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,SAAS,EAAE;AACnD,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,MAAM,EAAE,SAAS;AACjB,QAAA,MAAM,EAAE,IAAI;AACb,KAAA,CAAC,CAAC;AACL;;;;"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* The CSS class interface for the MessageSuggestion component.
|
|
4
|
-
*
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export interface MessageSuggestionCssClasses {
|
|
8
|
-
container?: string;
|
|
9
|
-
suggestion?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* The props for the MessageSuggestions component.
|
|
13
|
-
*
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export interface MessageSuggestionsProps {
|
|
17
|
-
/** List of clickable message suggestions to render. */
|
|
18
|
-
suggestions: string[];
|
|
19
|
-
/** {@inheritdoc ChatInputProps.handleError} */
|
|
20
|
-
handleError?: (e: unknown) => void;
|
|
21
|
-
/** CSS classes for customizing the component styling. */
|
|
22
|
-
customCssClasses?: MessageSuggestionCssClasses;
|
|
23
|
-
/** {@inheritdoc ChatInputProps.stream} */
|
|
24
|
-
stream?: boolean;
|
|
25
|
-
/** {@inheritdoc ChatInputProps.onSend} */
|
|
26
|
-
onSend?: (message: string) => void;
|
|
27
|
-
/** {@inheritdoc ChatInputProps.onRetry} */
|
|
28
|
-
onRetry?: (e: unknown) => void;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* A component that displays a list of suggested messages
|
|
32
|
-
* to the user, which they can click to send the message to the bot.
|
|
33
|
-
*
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
export declare const MessageSuggestions: React.FC<MessageSuggestionsProps>;
|
|
37
|
-
//# sourceMappingURL=MessageSuggestions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageSuggestions.d.ts","sourceRoot":"","sources":["../../../../src/components/MessageSuggestions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAW3C;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,uDAAuD;IACvD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,yDAAyD;IACzD,gBAAgB,CAAC,EAAE,2BAA2B,CAAC;IAC/C,0CAA0C;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,2CAA2C;IAC3C,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CAChC;AAWD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAmDhE,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
2
|
-
import { useChatActions, useChatState } from '@yext/chat-headless-react';
|
|
3
|
-
import { useDefaultHandleApiError } from '../hooks/useDefaultHandleApiError.mjs';
|
|
4
|
-
import { withStylelessCssClasses } from '../utils/withStylelessCssClasses.mjs';
|
|
5
|
-
import { useComposedCssClasses } from '../hooks/useComposedCssClasses.mjs';
|
|
6
|
-
import { useSendMessageWithRetries } from '../hooks/useSendMessageWithRetries.mjs';
|
|
7
|
-
|
|
8
|
-
const defaultClassnames = withStylelessCssClasses("Suggestions", {
|
|
9
|
-
container: "flex gap-2 mb-4 w-full overflow-x-auto flex-wrap",
|
|
10
|
-
suggestion: "hover:cursor-pointer px-2 py-1 bg-white hover:bg-slate-300 rounded-full text-sm text-blue-700 border border-blue-700 hover:underline",
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* A component that displays a list of suggested messages
|
|
14
|
-
* to the user, which they can click to send the message to the bot.
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
const MessageSuggestions = ({ handleError, suggestions, customCssClasses, stream = false, onSend, onRetry, }) => {
|
|
19
|
-
const actions = useChatActions();
|
|
20
|
-
const notes = useChatState((state) => state.conversation.notes);
|
|
21
|
-
const defaultHandleApiError = useDefaultHandleApiError();
|
|
22
|
-
const sendMessageWithRetries = useSendMessageWithRetries(stream, 1, onRetry);
|
|
23
|
-
const sendMsg = useCallback((msg) => {
|
|
24
|
-
const newNotes = {
|
|
25
|
-
...(notes || {}),
|
|
26
|
-
suggestedReplies: undefined,
|
|
27
|
-
};
|
|
28
|
-
actions.setMessageNotes(newNotes);
|
|
29
|
-
sendMessageWithRetries(msg)
|
|
30
|
-
.catch(handleError ?? defaultHandleApiError)
|
|
31
|
-
.finally(() => {
|
|
32
|
-
onSend?.(msg);
|
|
33
|
-
});
|
|
34
|
-
}, [
|
|
35
|
-
notes,
|
|
36
|
-
actions,
|
|
37
|
-
sendMessageWithRetries,
|
|
38
|
-
handleError,
|
|
39
|
-
defaultHandleApiError,
|
|
40
|
-
onSend,
|
|
41
|
-
]);
|
|
42
|
-
const classes = useComposedCssClasses(defaultClassnames, customCssClasses);
|
|
43
|
-
return (React.createElement("div", { className: classes.container }, suggestions.map((suggestion, index) => (React.createElement("button", { key: index, className: classes.suggestion,
|
|
44
|
-
// eslint-disable-next-line react-perf/jsx-no-new-function-as-prop
|
|
45
|
-
onClick: () => sendMsg(suggestion) }, suggestion)))));
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export { MessageSuggestions };
|
|
49
|
-
//# sourceMappingURL=MessageSuggestions.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageSuggestions.mjs","sources":["../../../../src/components/MessageSuggestions.tsx"],"sourcesContent":["import React, { useCallback } from \"react\";\nimport {\n MessageNotes,\n useChatActions,\n useChatState,\n} from \"@yext/chat-headless-react\";\nimport { useDefaultHandleApiError } from \"../hooks/useDefaultHandleApiError\";\nimport { withStylelessCssClasses } from \"../utils/withStylelessCssClasses\";\nimport { useComposedCssClasses } from \"../hooks\";\nimport { useSendMessageWithRetries } from \"../hooks/useSendMessageWithRetries\";\n\n/**\n * The CSS class interface for the MessageSuggestion component.\n *\n * @public\n */\nexport interface MessageSuggestionCssClasses {\n container?: string;\n suggestion?: string;\n}\n\n/**\n * The props for the MessageSuggestions component.\n *\n * @public\n */\nexport interface MessageSuggestionsProps {\n /** List of clickable message suggestions to render. */\n suggestions: string[];\n /** {@inheritdoc ChatInputProps.handleError} */\n handleError?: (e: unknown) => void;\n /** CSS classes for customizing the component styling. */\n customCssClasses?: MessageSuggestionCssClasses;\n /** {@inheritdoc ChatInputProps.stream} */\n stream?: boolean;\n /** {@inheritdoc ChatInputProps.onSend} */\n onSend?: (message: string) => void;\n /** {@inheritdoc ChatInputProps.onRetry} */\n onRetry?: (e: unknown) => void;\n}\n\nconst defaultClassnames: MessageSuggestionCssClasses = withStylelessCssClasses(\n \"Suggestions\",\n {\n container: \"flex gap-2 mb-4 w-full overflow-x-auto flex-wrap\",\n suggestion:\n \"hover:cursor-pointer px-2 py-1 bg-white hover:bg-slate-300 rounded-full text-sm text-blue-700 border border-blue-700 hover:underline\",\n }\n);\n\n/**\n * A component that displays a list of suggested messages\n * to the user, which they can click to send the message to the bot.\n *\n * @internal\n */\nexport const MessageSuggestions: React.FC<MessageSuggestionsProps> = ({\n handleError,\n suggestions,\n customCssClasses,\n stream = false,\n onSend,\n onRetry,\n}) => {\n const actions = useChatActions();\n const notes = useChatState((state) => state.conversation.notes);\n const defaultHandleApiError = useDefaultHandleApiError();\n const sendMessageWithRetries = useSendMessageWithRetries(stream, 1, onRetry);\n const sendMsg = useCallback(\n (msg: string) => {\n const newNotes = {\n ...(notes || {}),\n suggestedReplies: undefined,\n } satisfies MessageNotes;\n actions.setMessageNotes(newNotes);\n sendMessageWithRetries(msg)\n .catch(handleError ?? defaultHandleApiError)\n .finally(() => {\n onSend?.(msg);\n });\n },\n [\n notes,\n actions,\n sendMessageWithRetries,\n handleError,\n defaultHandleApiError,\n onSend,\n ]\n );\n\n const classes = useComposedCssClasses(defaultClassnames, customCssClasses);\n\n return (\n <div className={classes.container}>\n {suggestions.map((suggestion, index) => (\n <button\n key={index}\n className={classes.suggestion}\n // eslint-disable-next-line react-perf/jsx-no-new-function-as-prop\n onClick={() => sendMsg(suggestion)}\n >\n {suggestion}\n </button>\n ))}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;AAyCA,MAAM,iBAAiB,GAAgC,uBAAuB,CAC5E,aAAa,EACb;AACE,IAAA,SAAS,EAAE,kDAAkD;AAC7D,IAAA,UAAU,EACR,sIAAsI;AACzI,CAAA,CACF,CAAC;AAEF;;;;;AAKG;MACU,kBAAkB,GAAsC,CAAC,EACpE,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,MAAM,GAAG,KAAK,EACd,MAAM,EACN,OAAO,GACR,KAAI;AACH,IAAA,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;AACjC,IAAA,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAChE,IAAA,MAAM,qBAAqB,GAAG,wBAAwB,EAAE,CAAC;IACzD,MAAM,sBAAsB,GAAG,yBAAyB,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;AAC7E,IAAA,MAAM,OAAO,GAAG,WAAW,CACzB,CAAC,GAAW,KAAI;AACd,QAAA,MAAM,QAAQ,GAAG;AACf,YAAA,IAAI,KAAK,IAAI,EAAE,CAAC;AAChB,YAAA,gBAAgB,EAAE,SAAS;SACL,CAAC;AACzB,QAAA,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAClC,sBAAsB,CAAC,GAAG,CAAC;AACxB,aAAA,KAAK,CAAC,WAAW,IAAI,qBAAqB,CAAC;aAC3C,OAAO,CAAC,MAAK;AACZ,YAAA,MAAM,GAAG,GAAG,CAAC,CAAC;AAChB,SAAC,CAAC,CAAC;AACP,KAAC,EACD;QACE,KAAK;QACL,OAAO;QACP,sBAAsB;QACtB,WAAW;QACX,qBAAqB;QACrB,MAAM;AACP,KAAA,CACF,CAAC;IAEF,MAAM,OAAO,GAAG,qBAAqB,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;AAE3E,IAAA,QACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,OAAO,CAAC,SAAS,EAAA,EAC9B,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,MACjC,KACE,CAAA,aAAA,CAAA,QAAA,EAAA,EAAA,GAAG,EAAE,KAAK,EACV,SAAS,EAAE,OAAO,CAAC,UAAU;;AAE7B,QAAA,OAAO,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,EAAA,EAEjC,UAAU,CACJ,CACV,CAAC,CACE,EACN;AACJ;;;;"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { ChatInput } from "./ChatInput";
|
|
2
|
-
export type { ChatInputCssClasses, ChatInputProps } from "./ChatInput";
|
|
3
|
-
export { ChatHeader } from "./ChatHeader";
|
|
4
|
-
export type { ChatHeaderCssClasses, ChatHeaderProps } from "./ChatHeader";
|
|
5
|
-
export { MessageBubble } from "./MessageBubble";
|
|
6
|
-
export type { MessageBubbleCssClasses, MessageBubbleProps, } from "./MessageBubble";
|
|
7
|
-
export { ChatPanel } from "./ChatPanel";
|
|
8
|
-
export type { ChatPanelCssClasses, ChatPanelProps } from "./ChatPanel";
|
|
9
|
-
export { ChatPopUp } from "./ChatPopUp";
|
|
10
|
-
export type { ChatPopUpCssClasses, ChatPopUpProps } from "./ChatPopUp";
|
|
11
|
-
export type { FeedbackButtonsCssClasses } from "./FeedbackButtons";
|
|
12
|
-
export type { InitialMessagePopUpCssClasses } from "./InitialMessagePopUp";
|
|
13
|
-
export type { MessageSuggestionCssClasses, MessageSuggestionsProps, } from "./MessageSuggestions";
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE1E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EACV,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEvE,YAAY,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACnE,YAAY,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAE3E,YAAY,EACV,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useComposedCssClasses merges a component's built-in tailwind classes with custom tailwind classes.
|
|
3
|
-
*
|
|
4
|
-
* @remarks
|
|
5
|
-
* Tailwind classes will be merged without conflict, with custom classes having higher priority
|
|
6
|
-
* than built-in ones.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* Suppose a component has built-in classes of `{ container: 'px-4 text-slate-700' }`.
|
|
10
|
-
*
|
|
11
|
-
* Passing in the custom classes:
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* { container: 'text-red-200 mb-3' }
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* results in the merged classes of:
|
|
18
|
-
*
|
|
19
|
-
* ```ts
|
|
20
|
-
* { container: 'px-4 text-red-200 mb-3' }
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @public
|
|
24
|
-
*
|
|
25
|
-
* @param builtInClasses - The component's built-in tailwind classes
|
|
26
|
-
* @param customClasses - The custom tailwind classes to merge with the built-in ones
|
|
27
|
-
* @returns The composed CSS classes
|
|
28
|
-
*/
|
|
29
|
-
export declare function useComposedCssClasses<ClassInterface extends Partial<Record<keyof ClassInterface, string | object>>>(builtInClasses: Readonly<ClassInterface>, customClasses?: Partial<ClassInterface>): ClassInterface;
|
|
30
|
-
//# sourceMappingURL=useComposedCssClasses.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useComposedCssClasses.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useComposedCssClasses.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,SAAS,OAAO,CAAC,MAAM,CAAC,MAAM,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAE7E,cAAc,EAAE,QAAQ,CAAC,cAAc,CAAC,EACxC,aAAa,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GACtC,cAAc,CAyBhB"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { twMerge } from 'tailwind-merge';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* useComposedCssClasses merges a component's built-in tailwind classes with custom tailwind classes.
|
|
6
|
-
*
|
|
7
|
-
* @remarks
|
|
8
|
-
* Tailwind classes will be merged without conflict, with custom classes having higher priority
|
|
9
|
-
* than built-in ones.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* Suppose a component has built-in classes of `{ container: 'px-4 text-slate-700' }`.
|
|
13
|
-
*
|
|
14
|
-
* Passing in the custom classes:
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* { container: 'text-red-200 mb-3' }
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* results in the merged classes of:
|
|
21
|
-
*
|
|
22
|
-
* ```ts
|
|
23
|
-
* { container: 'px-4 text-red-200 mb-3' }
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @public
|
|
27
|
-
*
|
|
28
|
-
* @param builtInClasses - The component's built-in tailwind classes
|
|
29
|
-
* @param customClasses - The custom tailwind classes to merge with the built-in ones
|
|
30
|
-
* @returns The composed CSS classes
|
|
31
|
-
*/
|
|
32
|
-
function useComposedCssClasses(builtInClasses, customClasses) {
|
|
33
|
-
return useMemo(() => {
|
|
34
|
-
const mergeCssClasses = (builtInClasses, customClasses) => {
|
|
35
|
-
const mergedCssClasses = { ...builtInClasses };
|
|
36
|
-
if (!customClasses) {
|
|
37
|
-
return mergedCssClasses;
|
|
38
|
-
}
|
|
39
|
-
Object.keys(customClasses).forEach((key) => {
|
|
40
|
-
const builtIn = builtInClasses[key];
|
|
41
|
-
const custom = customClasses[key];
|
|
42
|
-
if (!builtIn || !custom) {
|
|
43
|
-
mergedCssClasses[key] = custom || builtIn;
|
|
44
|
-
}
|
|
45
|
-
else if (typeof builtIn === "object" && typeof custom === "object") {
|
|
46
|
-
mergedCssClasses[key] = mergeCssClasses(builtIn, custom);
|
|
47
|
-
}
|
|
48
|
-
else if (typeof builtIn === "string" && typeof custom === "string") {
|
|
49
|
-
mergedCssClasses[key] = twMerge(builtIn, custom);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return mergedCssClasses;
|
|
53
|
-
};
|
|
54
|
-
return mergeCssClasses(builtInClasses, customClasses);
|
|
55
|
-
}, [builtInClasses, customClasses]);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { useComposedCssClasses };
|
|
59
|
-
//# sourceMappingURL=useComposedCssClasses.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useComposedCssClasses.mjs","sources":["../../../../src/hooks/useComposedCssClasses.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\n\n/**\n * useComposedCssClasses merges a component's built-in tailwind classes with custom tailwind classes.\n *\n * @remarks\n * Tailwind classes will be merged without conflict, with custom classes having higher priority\n * than built-in ones.\n *\n * @example\n * Suppose a component has built-in classes of `{ container: 'px-4 text-slate-700' }`.\n *\n * Passing in the custom classes:\n *\n * ```ts\n * { container: 'text-red-200 mb-3' }\n * ```\n *\n * results in the merged classes of:\n *\n * ```ts\n * { container: 'px-4 text-red-200 mb-3' }\n * ```\n *\n * @public\n *\n * @param builtInClasses - The component's built-in tailwind classes\n * @param customClasses - The custom tailwind classes to merge with the built-in ones\n * @returns The composed CSS classes\n */\nexport function useComposedCssClasses<\n ClassInterface extends Partial<Record<keyof ClassInterface, string | object>>\n>(\n builtInClasses: Readonly<ClassInterface>,\n customClasses?: Partial<ClassInterface>\n): ClassInterface {\n return useMemo(() => {\n const mergeCssClasses = (\n builtInClasses: Readonly<ClassInterface>,\n customClasses?: Partial<ClassInterface>\n ) => {\n const mergedCssClasses = { ...builtInClasses };\n if (!customClasses) {\n return mergedCssClasses;\n }\n Object.keys(customClasses).forEach((key) => {\n const builtIn = builtInClasses[key];\n const custom = customClasses[key];\n if (!builtIn || !custom) {\n mergedCssClasses[key] = custom || builtIn;\n } else if (typeof builtIn === \"object\" && typeof custom === \"object\") {\n mergedCssClasses[key] = mergeCssClasses(builtIn, custom);\n } else if (typeof builtIn === \"string\" && typeof custom === \"string\") {\n mergedCssClasses[key] = twMerge(builtIn, custom);\n }\n });\n return mergedCssClasses;\n };\n return mergeCssClasses(builtInClasses, customClasses);\n }, [builtInClasses, customClasses]);\n}\n"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACa,SAAA,qBAAqB,CAGnC,cAAwC,EACxC,aAAuC,EAAA;IAEvC,OAAO,OAAO,CAAC,MAAK;AAClB,QAAA,MAAM,eAAe,GAAG,CACtB,cAAwC,EACxC,aAAuC,KACrC;AACF,YAAA,MAAM,gBAAgB,GAAG,EAAE,GAAG,cAAc,EAAE,CAAC;YAC/C,IAAI,CAAC,aAAa,EAAE;AAClB,gBAAA,OAAO,gBAAgB,CAAC;AACzB,aAAA;YACD,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;AACzC,gBAAA,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;AACpC,gBAAA,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AAClC,gBAAA,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,EAAE;AACvB,oBAAA,gBAAgB,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,OAAO,CAAC;AAC3C,iBAAA;qBAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;oBACpE,gBAAgB,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC1D,iBAAA;qBAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;oBACpE,gBAAgB,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAClD,iBAAA;AACH,aAAC,CAAC,CAAC;AACH,YAAA,OAAO,gBAAgB,CAAC;AAC1B,SAAC,CAAC;AACF,QAAA,OAAO,eAAe,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AACxD,KAAC,EAAE,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC;AACtC;;;;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a default handler function for API errors. It will log the error and
|
|
3
|
-
* add a default error message to state.
|
|
4
|
-
*
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export declare function useDefaultHandleApiError(): (e: unknown) => void;
|
|
8
|
-
//# sourceMappingURL=useDefaultHandleApiError.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDefaultHandleApiError.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDefaultHandleApiError.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,wBAAwB,QAIhC,OAAO,UAUd"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useChatActions, MessageSource } from '@yext/chat-headless-react';
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns a default handler function for API errors. It will log the error and
|
|
6
|
-
* add a default error message to state.
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
function useDefaultHandleApiError() {
|
|
11
|
-
const chat = useChatActions();
|
|
12
|
-
return useCallback((e) => {
|
|
13
|
-
console.error(e);
|
|
14
|
-
chat.addMessage({
|
|
15
|
-
text: "Sorry, I'm unable to respond at the moment. Please try again later!",
|
|
16
|
-
source: MessageSource.BOT,
|
|
17
|
-
timestamp: new Date().toISOString(),
|
|
18
|
-
});
|
|
19
|
-
}, [chat]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { useDefaultHandleApiError };
|
|
23
|
-
//# sourceMappingURL=useDefaultHandleApiError.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDefaultHandleApiError.mjs","sources":["../../../../src/hooks/useDefaultHandleApiError.ts"],"sourcesContent":["import { MessageSource, useChatActions } from \"@yext/chat-headless-react\";\nimport { useCallback } from \"react\";\n\n/**\n * Returns a default handler function for API errors. It will log the error and\n * add a default error message to state.\n *\n * @internal\n */\nexport function useDefaultHandleApiError() {\n const chat = useChatActions();\n\n return useCallback(\n (e: unknown) => {\n console.error(e);\n chat.addMessage({\n text: \"Sorry, I'm unable to respond at the moment. Please try again later!\",\n source: MessageSource.BOT,\n timestamp: new Date().toISOString(),\n });\n },\n [chat]\n );\n}\n"],"names":[],"mappings":";;;AAGA;;;;;AAKG;SACa,wBAAwB,GAAA;AACtC,IAAA,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC;AAE9B,IAAA,OAAO,WAAW,CAChB,CAAC,CAAU,KAAI;AACb,QAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,IAAI,CAAC,UAAU,CAAC;AACd,YAAA,IAAI,EAAE,qEAAqE;YAC3E,MAAM,EAAE,aAAa,CAAC,GAAG;AACzB,YAAA,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;AACpC,SAAA,CAAC,CAAC;AACL,KAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAC;AACJ;;;;"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sends a request to Chat API to fetch the initial message when the
|
|
3
|
-
* conversation first start or when the message history is reset.
|
|
4
|
-
*
|
|
5
|
-
* @internal
|
|
6
|
-
*
|
|
7
|
-
* @param handleError - A function which is called when an error occurs while fetching for initial message.
|
|
8
|
-
* By default, the error is logged to the console and an error message is added to state.
|
|
9
|
-
* @param stream - Enable streaming behavior by making a request to Chat Streaming API. Defaults to false.
|
|
10
|
-
* @param customCondition - additional condition for when to fetch initial message
|
|
11
|
-
*/
|
|
12
|
-
export declare function useFetchInitialMessage(handleError?: (e: unknown) => void, stream?: boolean, customCondition?: boolean): void;
|
|
13
|
-
//# sourceMappingURL=useFetchInitialMessage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchInitialMessage.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useFetchInitialMessage.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,EAClC,MAAM,UAAQ,EACd,eAAe,UAAO,QAwBvB"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
import { useChatActions, useChatState } from '@yext/chat-headless-react';
|
|
3
|
-
import { useDefaultHandleApiError } from './useDefaultHandleApiError.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Sends a request to Chat API to fetch the initial message when the
|
|
7
|
-
* conversation first start or when the message history is reset.
|
|
8
|
-
*
|
|
9
|
-
* @internal
|
|
10
|
-
*
|
|
11
|
-
* @param handleError - A function which is called when an error occurs while fetching for initial message.
|
|
12
|
-
* By default, the error is logged to the console and an error message is added to state.
|
|
13
|
-
* @param stream - Enable streaming behavior by making a request to Chat Streaming API. Defaults to false.
|
|
14
|
-
* @param customCondition - additional condition for when to fetch initial message
|
|
15
|
-
*/
|
|
16
|
-
function useFetchInitialMessage(handleError, stream = false, customCondition = true) {
|
|
17
|
-
const chat = useChatActions();
|
|
18
|
-
const defaultHandleApiError = useDefaultHandleApiError();
|
|
19
|
-
const messages = useChatState((state) => state.conversation.messages);
|
|
20
|
-
const canSendMessage = useChatState((state) => state.conversation.canSendMessage);
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (messages.length !== 0 || !canSendMessage || !customCondition) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const res = stream ? chat.streamNextMessage() : chat.getNextMessage();
|
|
26
|
-
res.catch((e) => (handleError ? handleError(e) : defaultHandleApiError(e)));
|
|
27
|
-
}, [
|
|
28
|
-
chat,
|
|
29
|
-
stream,
|
|
30
|
-
handleError,
|
|
31
|
-
defaultHandleApiError,
|
|
32
|
-
canSendMessage,
|
|
33
|
-
customCondition,
|
|
34
|
-
messages.length,
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { useFetchInitialMessage };
|
|
39
|
-
//# sourceMappingURL=useFetchInitialMessage.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchInitialMessage.mjs","sources":["../../../../src/hooks/useFetchInitialMessage.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useChatState, useChatActions } from \"@yext/chat-headless-react\";\nimport { useDefaultHandleApiError } from \"../hooks/useDefaultHandleApiError\";\n\n/**\n * Sends a request to Chat API to fetch the initial message when the\n * conversation first start or when the message history is reset.\n *\n * @internal\n *\n * @param handleError - A function which is called when an error occurs while fetching for initial message.\n * By default, the error is logged to the console and an error message is added to state.\n * @param stream - Enable streaming behavior by making a request to Chat Streaming API. Defaults to false.\n * @param customCondition - additional condition for when to fetch initial message\n */\nexport function useFetchInitialMessage(\n handleError?: (e: unknown) => void,\n stream = false,\n customCondition = true\n) {\n const chat = useChatActions();\n const defaultHandleApiError = useDefaultHandleApiError();\n const messages = useChatState((state) => state.conversation.messages);\n const canSendMessage = useChatState(\n (state) => state.conversation.canSendMessage\n );\n\n useEffect(() => {\n if (messages.length !== 0 || !canSendMessage || !customCondition) {\n return;\n }\n const res = stream ? chat.streamNextMessage() : chat.getNextMessage();\n res.catch((e) => (handleError ? handleError(e) : defaultHandleApiError(e)));\n }, [\n chat,\n stream,\n handleError,\n defaultHandleApiError,\n canSendMessage,\n customCondition,\n messages.length,\n ]);\n}\n"],"names":[],"mappings":";;;;AAIA;;;;;;;;;;AAUG;AACG,SAAU,sBAAsB,CACpC,WAAkC,EAClC,MAAM,GAAG,KAAK,EACd,eAAe,GAAG,IAAI,EAAA;AAEtB,IAAA,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC;AAC9B,IAAA,MAAM,qBAAqB,GAAG,wBAAwB,EAAE,CAAC;AACzD,IAAA,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AACtE,IAAA,MAAM,cAAc,GAAG,YAAY,CACjC,CAAC,KAAK,KAAK,KAAK,CAAC,YAAY,CAAC,cAAc,CAC7C,CAAC;IAEF,SAAS,CAAC,MAAK;QACb,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,cAAc,IAAI,CAAC,eAAe,EAAE;YAChE,OAAO;AACR,SAAA;AACD,QAAA,MAAM,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC,iBAAiB,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACtE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E,KAAC,EAAE;QACD,IAAI;QACJ,MAAM;QACN,WAAW;QACX,qBAAqB;QACrB,cAAc;QACd,eAAe;AACf,QAAA,QAAQ,CAAC,MAAM;AAChB,KAAA,CAAC,CAAC;AACL;;;;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ChatHeadless } from "@yext/chat-headless-react";
|
|
2
|
-
/**
|
|
3
|
-
* Returns a function to send requests to Yext Analytics API.
|
|
4
|
-
*
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export declare function useReportAnalyticsEvent(): ChatHeadless["report"];
|
|
8
|
-
//# sourceMappingURL=useReportAnalyticsEvent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useReportAnalyticsEvent.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useReportAnalyticsEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAkB,MAAM,2BAA2B,CAAC;AAIzE;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,YAAY,CAAC,QAAQ,CAAC,CAMhE"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useChatActions } from '@yext/chat-headless-react';
|
|
2
|
-
import { version } from '../../package.json.mjs';
|
|
3
|
-
import { useCallback } from 'react';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns a function to send requests to Yext Analytics API.
|
|
7
|
-
*
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
function useReportAnalyticsEvent() {
|
|
11
|
-
const chat = useChatActions();
|
|
12
|
-
chat.addClientSdk({
|
|
13
|
-
CHAT_UI_REACT: version,
|
|
14
|
-
});
|
|
15
|
-
return useCallback((payload) => chat.report(payload), [chat]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { useReportAnalyticsEvent };
|
|
19
|
-
//# sourceMappingURL=useReportAnalyticsEvent.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useReportAnalyticsEvent.mjs","sources":["../../../../src/hooks/useReportAnalyticsEvent.ts"],"sourcesContent":["import { ChatHeadless, useChatActions } from \"@yext/chat-headless-react\";\nimport { version } from \"../../package.json\";\nimport { useCallback } from \"react\";\n\n/**\n * Returns a function to send requests to Yext Analytics API.\n *\n * @public\n */\nexport function useReportAnalyticsEvent(): ChatHeadless[\"report\"] {\n const chat = useChatActions();\n chat.addClientSdk({\n CHAT_UI_REACT: version,\n });\n return useCallback((payload) => chat.report(payload), [chat]);\n}\n"],"names":[],"mappings":";;;;AAIA;;;;AAIG;SACa,uBAAuB,GAAA;AACrC,IAAA,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC;IAC9B,IAAI,CAAC,YAAY,CAAC;AAChB,QAAA,aAAa,EAAE,OAAO;AACvB,KAAA,CAAC,CAAC;AACH,IAAA,OAAO,WAAW,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AAChE;;;;"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a function that sends a message to the chat API with retries
|
|
3
|
-
* if the API returns a 5xx status code.
|
|
4
|
-
*
|
|
5
|
-
* @remarks
|
|
6
|
-
* The function will throw the error if the maximum number of retries is reached
|
|
7
|
-
* or if the error is not a 5xx status code.
|
|
8
|
-
*
|
|
9
|
-
* @internal
|
|
10
|
-
*
|
|
11
|
-
* @param stream - If true, use streaming API
|
|
12
|
-
* @param maxRetries - Maximum number of retries
|
|
13
|
-
* @param onRetry - Callback to handle error on each retry
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
export declare function useSendMessageWithRetries(stream?: boolean, maxRetries?: number, onRetry?: (e: unknown) => void): (input: string) => Promise<void>;
|
|
17
|
-
//# sourceMappingURL=useSendMessageWithRetries.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSendMessageWithRetries.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useSendMessageWithRetries.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,UAAQ,EACd,UAAU,SAAI,EACd,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,GAC7B,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAiClC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { useChatActions, ApiError } from '@yext/chat-headless-react';
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns a function that sends a message to the chat API with retries
|
|
6
|
-
* if the API returns a 5xx status code.
|
|
7
|
-
*
|
|
8
|
-
* @remarks
|
|
9
|
-
* The function will throw the error if the maximum number of retries is reached
|
|
10
|
-
* or if the error is not a 5xx status code.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*
|
|
14
|
-
* @param stream - If true, use streaming API
|
|
15
|
-
* @param maxRetries - Maximum number of retries
|
|
16
|
-
* @param onRetry - Callback to handle error on each retry
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
function useSendMessageWithRetries(stream = false, maxRetries = 0, onRetry) {
|
|
20
|
-
const chat = useChatActions();
|
|
21
|
-
return useCallback(async (input) => {
|
|
22
|
-
let err;
|
|
23
|
-
let text = input;
|
|
24
|
-
for (let numRetries = 0; numRetries <= maxRetries; numRetries++) {
|
|
25
|
-
if (numRetries > 0 && !!err) {
|
|
26
|
-
if (err instanceof ApiError &&
|
|
27
|
-
!!err.statusCode &&
|
|
28
|
-
err.statusCode >= 500) {
|
|
29
|
-
onRetry?.(err);
|
|
30
|
-
// avoid re-adding user message to conversation history on retry
|
|
31
|
-
text = "";
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
await (stream
|
|
39
|
-
? chat.streamNextMessage(text)
|
|
40
|
-
: chat.getNextMessage(text));
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
err = e;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
throw err;
|
|
48
|
-
}, [chat, maxRetries, onRetry, stream]);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { useSendMessageWithRetries };
|
|
52
|
-
//# sourceMappingURL=useSendMessageWithRetries.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSendMessageWithRetries.mjs","sources":["../../../../src/hooks/useSendMessageWithRetries.ts"],"sourcesContent":["import { ApiError, useChatActions } from \"@yext/chat-headless-react\";\nimport { useCallback } from \"react\";\n\n/**\n * Returns a function that sends a message to the chat API with retries\n * if the API returns a 5xx status code.\n *\n * @remarks\n * The function will throw the error if the maximum number of retries is reached\n * or if the error is not a 5xx status code.\n *\n * @internal\n *\n * @param stream - If true, use streaming API\n * @param maxRetries - Maximum number of retries\n * @param onRetry - Callback to handle error on each retry\n *\n */\nexport function useSendMessageWithRetries(\n stream = false,\n maxRetries = 0,\n onRetry?: (e: unknown) => void\n): (input: string) => Promise<void> {\n const chat = useChatActions();\n return useCallback(\n async (input: string) => {\n let err: unknown;\n let text = input;\n for (let numRetries = 0; numRetries <= maxRetries; numRetries++) {\n if (numRetries > 0 && !!err) {\n if (\n err instanceof ApiError &&\n !!err.statusCode &&\n err.statusCode >= 500\n ) {\n onRetry?.(err);\n // avoid re-adding user message to conversation history on retry\n text = \"\";\n } else {\n throw err;\n }\n }\n try {\n await (stream\n ? chat.streamNextMessage(text)\n : chat.getNextMessage(text));\n return;\n } catch (e) {\n err = e;\n }\n }\n throw err;\n },\n [chat, maxRetries, onRetry, stream]\n );\n}\n"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;AAcG;AACG,SAAU,yBAAyB,CACvC,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,CAAC,EACd,OAA8B,EAAA;AAE9B,IAAA,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC;AAC9B,IAAA,OAAO,WAAW,CAChB,OAAO,KAAa,KAAI;AACtB,QAAA,IAAI,GAAY,CAAC;QACjB,IAAI,IAAI,GAAG,KAAK,CAAC;QACjB,KAAK,IAAI,UAAU,GAAG,CAAC,EAAE,UAAU,IAAI,UAAU,EAAE,UAAU,EAAE,EAAE;AAC/D,YAAA,IAAI,UAAU,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE;gBAC3B,IACE,GAAG,YAAY,QAAQ;oBACvB,CAAC,CAAC,GAAG,CAAC,UAAU;AAChB,oBAAA,GAAG,CAAC,UAAU,IAAI,GAAG,EACrB;AACA,oBAAA,OAAO,GAAG,GAAG,CAAC,CAAC;;oBAEf,IAAI,GAAG,EAAE,CAAC;AACX,iBAAA;AAAM,qBAAA;AACL,oBAAA,MAAM,GAAG,CAAC;AACX,iBAAA;AACF,aAAA;YACD,IAAI;AACF,gBAAA,OAAO,MAAM;AACX,sBAAE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;sBAC5B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC/B,OAAO;AACR,aAAA;AAAC,YAAA,OAAO,CAAC,EAAE;gBACV,GAAG,GAAG,CAAC,CAAC;AACT,aAAA;AACF,SAAA;AACD,QAAA,MAAM,GAAG,CAAC;KACX,EACD,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CACpC,CAAC;AACJ;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Arrow.d.ts","sourceRoot":"","sources":["../../../../src/icons/Arrow.tsx"],"names":[],"mappings":";AAEA,wBAAgB,SAAS,IAAI,GAAG,CAAC,OAAO,CAevC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
function ArrowIcon() {
|
|
4
|
-
return (React.createElement("svg", { width: "100%", height: "100%", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeLinecap: "square", xmlns: "http://www.w3.org/2000/svg" },
|
|
5
|
-
React.createElement("path", { d: "M10 5V15" }),
|
|
6
|
-
React.createElement("path", { d: "M15 8.84615L10 4L5 8.84615" })));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export { ArrowIcon };
|
|
10
|
-
//# sourceMappingURL=Arrow.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Arrow.mjs","sources":["../../../../src/icons/Arrow.tsx"],"sourcesContent":["import React from \"react\";\n\nexport function ArrowIcon(): JSX.Element {\n return (\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox=\"0 0 20 20\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeLinecap=\"square\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M10 5V15\" />\n <path d=\"M15 8.84615L10 4L5 8.84615\" />\n </svg>\n );\n}\n"],"names":[],"mappings":";;SAEgB,SAAS,GAAA;AACvB,IAAA,QACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EACE,KAAK,EAAC,MAAM,EACZ,MAAM,EAAC,MAAM,EACb,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,aAAa,EAAC,QAAQ,EACtB,KAAK,EAAC,4BAA4B,EAAA;QAElC,KAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,CAAC,EAAC,UAAU,EAAG,CAAA;AACrB,QAAA,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAM,CAAC,EAAC,4BAA4B,EAAG,CAAA,CACnC,EACN;AACJ;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../../src/icons/Chat.tsx"],"names":[],"mappings":";AAEA,wBAAgB,QAAQ,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,GAAG,CAAC,OAAO,CAsC3E"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
function ChatIcon({ className }) {
|
|
4
|
-
return (React.createElement("svg", { width: "100%", height: "100%", viewBox: "0 0 20 20", fill: "none", className: className, xmlns: "http://www.w3.org/2000/svg" },
|
|
5
|
-
React.createElement("path", { d: "M15.3028 12.8082L15.1553 12.9342L15.1729 13.1273L15.3973 15.5959C15.3983 15.6063 15.3964 15.6126 15.3943 15.617C15.3918 15.6223 15.3873 15.6283 15.3805 15.6332C15.3737 15.6382 15.3667 15.6408 15.3608 15.6416C15.356 15.6422 15.3495 15.6422 15.3398 15.6381L12.3578 14.3956L12.245 14.3486L12.1261 14.3771C11.4553 14.5381 10.7412 14.625 10 14.625C5.9718 14.625 2.875 12.099 2.875 9.16667C2.875 6.23436 5.9718 3.70834 10 3.70834C14.0282 3.70834 17.125 6.23436 17.125 9.16667C17.125 10.5493 16.4496 11.8289 15.3028 12.8082Z", fill: "white", stroke: "white", strokeWidth: "0.75" }),
|
|
6
|
-
React.createElement("path", { d: "M7 7.54584C7 7.38015 7.13431 7.24584 7.3 7.24584H8.725C8.89069 7.24584 9.025 7.38015 9.025 7.54584C9.025 7.71152 8.89069 7.84584 8.725 7.84584H7.3C7.13431 7.84584 7 7.71152 7 7.54584Z", fill: "currentColor" }),
|
|
7
|
-
React.createElement("path", { d: "M9.625 7.54584C9.625 7.15233 9.944 6.83334 10.3375 6.83334H12.2875C12.681 6.83334 13 7.15233 13 7.54584C13 7.93934 12.681 8.25834 12.2875 8.25834H10.3375C9.944 8.25834 9.625 7.93934 9.625 7.54584Z", fill: "currentColor" }),
|
|
8
|
-
React.createElement("path", { d: "M7 9.30834C7 9.14265 7.13431 9.00834 7.3 9.00834H12.7C12.8657 9.00834 13 9.14265 13 9.30834C13 9.47402 12.8657 9.60834 12.7 9.60834H7.3C7.13431 9.60834 7 9.47402 7 9.30834Z", fill: "currentColor" }),
|
|
9
|
-
React.createElement("path", { d: "M7 11.0708C7 10.6773 7.319 10.3583 7.7125 10.3583H8.1625C8.556 10.3583 8.875 10.6773 8.875 11.0708C8.875 11.4643 8.556 11.7833 8.1625 11.7833H7.7125C7.319 11.7833 7 11.4643 7 11.0708Z", fill: "currentColor" }),
|
|
10
|
-
React.createElement("path", { d: "M9.475 11.0708C9.475 10.9052 9.60931 10.7708 9.775 10.7708H12.7C12.8657 10.7708 13 10.9052 13 11.0708C13 11.2365 12.8657 11.3708 12.7 11.3708H9.775C9.60931 11.3708 9.475 11.2365 9.475 11.0708Z", fill: "currentColor" })));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { ChatIcon };
|
|
14
|
-
//# sourceMappingURL=Chat.mjs.map
|