@yext/chat-ui-react 0.7.3 → 0.8.1-alpha
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/README.md +10 -2
- package/lib/bundle.css +1 -1
- package/lib/commonjs/package.json.js +1 -1
- package/lib/commonjs/src/components/ChatInput.js +1 -1
- package/lib/commonjs/src/components/ChatPanel.d.ts.map +1 -1
- package/lib/commonjs/src/components/ChatPanel.js +7 -45
- package/lib/commonjs/src/components/ChatPanel.js.map +1 -1
- package/lib/commonjs/src/components/ChatPopUp.d.ts +31 -4
- package/lib/commonjs/src/components/ChatPopUp.d.ts.map +1 -1
- package/lib/commonjs/src/components/ChatPopUp.js +57 -10
- package/lib/commonjs/src/components/ChatPopUp.js.map +1 -1
- package/lib/commonjs/src/components/FeedbackButtons.d.ts +3 -4
- package/lib/commonjs/src/components/FeedbackButtons.d.ts.map +1 -1
- package/lib/commonjs/src/components/FeedbackButtons.js +2 -1
- package/lib/commonjs/src/components/FeedbackButtons.js.map +1 -1
- package/lib/commonjs/src/components/InitialMessagePopUp.d.ts +33 -0
- package/lib/commonjs/src/components/InitialMessagePopUp.d.ts.map +1 -0
- package/lib/commonjs/src/components/InitialMessagePopUp.js +44 -0
- package/lib/commonjs/src/components/InitialMessagePopUp.js.map +1 -0
- package/lib/commonjs/src/components/Markdown.d.ts +7 -3
- package/lib/commonjs/src/components/Markdown.d.ts.map +1 -1
- package/lib/commonjs/src/components/Markdown.js +1 -1
- package/lib/commonjs/src/components/Markdown.js.map +1 -1
- package/lib/commonjs/src/components/index.d.ts +5 -1
- package/lib/commonjs/src/components/index.d.ts.map +1 -1
- package/lib/commonjs/src/hooks/index.d.ts +4 -0
- package/lib/commonjs/src/hooks/index.d.ts.map +1 -1
- package/lib/commonjs/src/hooks/useDefaultHandleApiError.d.ts +1 -1
- package/lib/commonjs/src/hooks/useDefaultHandleApiError.js +1 -1
- package/lib/commonjs/src/hooks/useDefaultHandleApiError.js.map +1 -1
- package/lib/commonjs/src/hooks/useFetchInitialMessage.d.ts +13 -0
- package/lib/commonjs/src/hooks/useFetchInitialMessage.d.ts.map +1 -0
- package/lib/commonjs/src/hooks/useFetchInitialMessage.js +53 -0
- package/lib/commonjs/src/hooks/useFetchInitialMessage.js.map +1 -0
- package/lib/commonjs/src/hooks/useReportAnalyticsEvent.d.ts +1 -1
- package/lib/commonjs/src/hooks/useReportAnalyticsEvent.js +1 -1
- package/lib/commonjs/src/hooks/useReportAnalyticsEvent.js.map +1 -1
- package/lib/commonjs/src/hooks/useScrollToLastMessage.d.ts +15 -0
- package/lib/commonjs/src/hooks/useScrollToLastMessage.d.ts.map +1 -0
- package/lib/commonjs/src/hooks/useScrollToLastMessage.js +45 -0
- package/lib/commonjs/src/hooks/useScrollToLastMessage.js.map +1 -0
- package/lib/commonjs/src/index.js +12 -0
- package/lib/commonjs/src/index.js.map +1 -1
- package/lib/esm/index.d.ts +132 -4
- package/lib/esm/package.json.mjs +1 -1
- package/lib/esm/src/components/ChatInput.mjs +1 -1
- package/lib/esm/src/components/ChatPanel.d.ts.map +1 -1
- package/lib/esm/src/components/ChatPanel.mjs +9 -47
- package/lib/esm/src/components/ChatPanel.mjs.map +1 -1
- package/lib/esm/src/components/ChatPopUp.d.ts +31 -4
- package/lib/esm/src/components/ChatPopUp.d.ts.map +1 -1
- package/lib/esm/src/components/ChatPopUp.mjs +57 -10
- package/lib/esm/src/components/ChatPopUp.mjs.map +1 -1
- package/lib/esm/src/components/FeedbackButtons.d.ts +3 -4
- package/lib/esm/src/components/FeedbackButtons.d.ts.map +1 -1
- package/lib/esm/src/components/FeedbackButtons.mjs +2 -1
- package/lib/esm/src/components/FeedbackButtons.mjs.map +1 -1
- package/lib/esm/src/components/InitialMessagePopUp.d.ts +33 -0
- package/lib/esm/src/components/InitialMessagePopUp.d.ts.map +1 -0
- package/lib/esm/src/components/InitialMessagePopUp.mjs +38 -0
- package/lib/esm/src/components/InitialMessagePopUp.mjs.map +1 -0
- package/lib/esm/src/components/Markdown.d.ts +7 -3
- package/lib/esm/src/components/Markdown.d.ts.map +1 -1
- package/lib/esm/src/components/Markdown.mjs +1 -1
- package/lib/esm/src/components/Markdown.mjs.map +1 -1
- package/lib/esm/src/components/index.d.ts +5 -1
- package/lib/esm/src/components/index.d.ts.map +1 -1
- package/lib/esm/src/hooks/index.d.ts +4 -0
- package/lib/esm/src/hooks/index.d.ts.map +1 -1
- package/lib/esm/src/hooks/useDefaultHandleApiError.d.ts +1 -1
- package/lib/esm/src/hooks/useDefaultHandleApiError.mjs +1 -1
- package/lib/esm/src/hooks/useDefaultHandleApiError.mjs.map +1 -1
- package/lib/esm/src/hooks/useFetchInitialMessage.d.ts +13 -0
- package/lib/esm/src/hooks/useFetchInitialMessage.d.ts.map +1 -0
- package/lib/esm/src/hooks/useFetchInitialMessage.mjs +51 -0
- package/lib/esm/src/hooks/useFetchInitialMessage.mjs.map +1 -0
- package/lib/esm/src/hooks/useReportAnalyticsEvent.d.ts +1 -1
- package/lib/esm/src/hooks/useReportAnalyticsEvent.mjs +1 -1
- package/lib/esm/src/hooks/useReportAnalyticsEvent.mjs.map +1 -1
- package/lib/esm/src/hooks/useScrollToLastMessage.d.ts +15 -0
- package/lib/esm/src/hooks/useScrollToLastMessage.d.ts.map +1 -0
- package/lib/esm/src/hooks/useScrollToLastMessage.mjs +43 -0
- package/lib/esm/src/hooks/useScrollToLastMessage.mjs.map +1 -0
- package/lib/esm/src/index.mjs +6 -0
- package/lib/esm/src/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/ChatPanel.tsx +12 -56
- package/src/components/ChatPopUp.tsx +143 -21
- package/src/components/FeedbackButtons.tsx +3 -3
- package/src/components/InitialMessagePopUp.tsx +76 -0
- package/src/components/Markdown.tsx +7 -2
- package/src/components/index.ts +8 -2
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useDefaultHandleApiError.ts +1 -1
- package/src/hooks/useFetchInitialMessage.ts +58 -0
- package/src/hooks/useReportAnalyticsEvent.ts +1 -1
- package/src/hooks/useScrollToLastMessage.ts +47 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* The CSS class interface for the InitialMessagePopUp component.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface InitialMessagePopUpCssClasses {
|
|
8
|
+
container?: string;
|
|
9
|
+
closeButton?: string;
|
|
10
|
+
closeButtonIcon?: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The props for the {@link InitialMessagePopUp} component.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
interface InitialMessagePopUpProps {
|
|
19
|
+
/** CSS classes for customizing the component styling. */
|
|
20
|
+
customCssClasses?: InitialMessagePopUpCssClasses;
|
|
21
|
+
/** Function to call when user click on the close button */
|
|
22
|
+
onClose: () => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A component that renders a popup bubble displaying the initial message from chat bot.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*
|
|
29
|
+
* @param props - {@link InitialMessagePopUpProps}
|
|
30
|
+
*/
|
|
31
|
+
export declare function InitialMessagePopUp({ onClose, customCssClasses, }: InitialMessagePopUpProps): React.JSX.Element;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=InitialMessagePopUp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitialMessagePopUp.d.ts","sourceRoot":"","sources":["../../../../src/components/InitialMessagePopUp.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAMvC;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,UAAU,wBAAwB;IAChC,yDAAyD;IACzD,gBAAgB,CAAC,EAAE,6BAA6B,CAAC;IACjD,2DAA2D;IAC3D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAWD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,OAAO,EACP,gBAAgB,GACjB,EAAE,wBAAwB,qBA0B1B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var Cross = require('../icons/Cross.js');
|
|
5
|
+
var useComposedCssClasses = require('../hooks/useComposedCssClasses.js');
|
|
6
|
+
var chatHeadlessReact = require('@yext/chat-headless-react');
|
|
7
|
+
var withStylelessCssClasses = require('../utils/withStylelessCssClasses.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
12
|
+
|
|
13
|
+
const builtInCssClasses = withStylelessCssClasses.withStylelessCssClasses("InitialMessagePopUp", {
|
|
14
|
+
container: "flex gap-x-1 animate-fade-in",
|
|
15
|
+
closeButton: "bg-white w-4 h-4 rounded-full border border-slate-300",
|
|
16
|
+
closeButtonIcon: "",
|
|
17
|
+
message: "line-clamp-2 w-60 p-2.5 bg-white rounded-xl shadow-xl text-sm lg:text-base",
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* A component that renders a popup bubble displaying the initial message from chat bot.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*
|
|
24
|
+
* @param props - {@link InitialMessagePopUpProps}
|
|
25
|
+
*/
|
|
26
|
+
function InitialMessagePopUp({ onClose, customCssClasses, }) {
|
|
27
|
+
const messages = chatHeadlessReact.useChatState((s) => s.conversation.messages);
|
|
28
|
+
const cssClasses = useComposedCssClasses.useComposedCssClasses(builtInCssClasses, customCssClasses);
|
|
29
|
+
const firstBotMessage = React.useMemo(() => {
|
|
30
|
+
return messages.length !== 0 && messages[0].source === chatHeadlessReact.MessageSource.BOT
|
|
31
|
+
? messages[0].text
|
|
32
|
+
: "";
|
|
33
|
+
}, [messages]);
|
|
34
|
+
if (firstBotMessage.length === 0) {
|
|
35
|
+
return React__default.default.createElement(React__default.default.Fragment, null);
|
|
36
|
+
}
|
|
37
|
+
return (React__default.default.createElement("div", { className: cssClasses.container },
|
|
38
|
+
React__default.default.createElement("button", { "aria-label": "Close Initial Message", onClick: onClose, className: cssClasses.closeButton },
|
|
39
|
+
React__default.default.createElement(Cross.CrossIcon, { className: cssClasses.closeButtonIcon })),
|
|
40
|
+
React__default.default.createElement("div", { className: cssClasses.message }, firstBotMessage)));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.InitialMessagePopUp = InitialMessagePopUp;
|
|
44
|
+
//# sourceMappingURL=InitialMessagePopUp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitialMessagePopUp.js","sources":["../../../../src/components/InitialMessagePopUp.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { CrossIcon } from \"../icons/Cross\";\nimport { useComposedCssClasses } from \"../hooks\";\nimport { withStylelessCssClasses } from \"../utils/withStylelessCssClasses\";\nimport { MessageSource, useChatState } from \"@yext/chat-headless-react\";\n\n/**\n * The CSS class interface for the InitialMessagePopUp component.\n *\n * @public\n */\nexport interface InitialMessagePopUpCssClasses {\n container?: string;\n closeButton?: string;\n closeButtonIcon?: string;\n message?: string;\n}\n\n/**\n * The props for the {@link InitialMessagePopUp} component.\n *\n * @internal\n */\ninterface InitialMessagePopUpProps {\n /** CSS classes for customizing the component styling. */\n customCssClasses?: InitialMessagePopUpCssClasses;\n /** Function to call when user click on the close button */\n onClose: () => void;\n}\n\nconst builtInCssClasses: InitialMessagePopUpCssClasses =\n withStylelessCssClasses(\"InitialMessagePopUp\", {\n container: \"flex gap-x-1 animate-fade-in\",\n closeButton: \"bg-white w-4 h-4 rounded-full border border-slate-300\",\n closeButtonIcon: \"\",\n message:\n \"line-clamp-2 w-60 p-2.5 bg-white rounded-xl shadow-xl text-sm lg:text-base\",\n });\n\n/**\n * A component that renders a popup bubble displaying the initial message from chat bot.\n *\n * @internal\n *\n * @param props - {@link InitialMessagePopUpProps}\n */\nexport function InitialMessagePopUp({\n onClose,\n customCssClasses,\n}: InitialMessagePopUpProps) {\n const messages = useChatState((s) => s.conversation.messages);\n const cssClasses = useComposedCssClasses(builtInCssClasses, customCssClasses);\n\n const firstBotMessage: string = useMemo(() => {\n return messages.length !== 0 && messages[0].source === MessageSource.BOT\n ? messages[0].text\n : \"\";\n }, [messages]);\n\n if (firstBotMessage.length === 0) {\n return <></>;\n }\n\n return (\n <div className={cssClasses.container}>\n <button\n aria-label=\"Close Initial Message\"\n onClick={onClose}\n className={cssClasses.closeButton}\n >\n <CrossIcon className={cssClasses.closeButtonIcon} />\n </button>\n <div className={cssClasses.message}>{firstBotMessage}</div>\n </div>\n );\n}\n"],"names":["withStylelessCssClasses","useChatState","useComposedCssClasses","useMemo","MessageSource","React","CrossIcon"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,iBAAiB,GACrBA,+CAAuB,CAAC,qBAAqB,EAAE;AAC7C,IAAA,SAAS,EAAE,8BAA8B;AACzC,IAAA,WAAW,EAAE,uDAAuD;AACpE,IAAA,eAAe,EAAE,EAAE;AACnB,IAAA,OAAO,EACL,4EAA4E;AAC/E,CAAA,CAAC,CAAC;AAEL;;;;;;AAMG;SACa,mBAAmB,CAAC,EAClC,OAAO,EACP,gBAAgB,GACS,EAAA;AACzB,IAAA,MAAM,QAAQ,GAAGC,8BAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9D,MAAM,UAAU,GAAGC,2CAAqB,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;AAE9E,IAAA,MAAM,eAAe,GAAWC,aAAO,CAAC,MAAK;AAC3C,QAAA,OAAO,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,KAAKC,+BAAa,CAAC,GAAG;AACtE,cAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI;cAChB,EAAE,CAAC;AACT,KAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEf,IAAA,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE;AAChC,QAAA,OAAOC,2EAAK,CAAC;AACd,KAAA;AAED,IAAA,QACEA,sBAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,UAAU,CAAC,SAAS,EAAA;QAClCA,sBACa,CAAA,aAAA,CAAA,QAAA,EAAA,EAAA,YAAA,EAAA,uBAAuB,EAClC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,UAAU,CAAC,WAAW,EAAA;YAEjCA,sBAAC,CAAA,aAAA,CAAAC,eAAS,IAAC,SAAS,EAAE,UAAU,CAAC,eAAe,GAAI,CAC7C;QACTD,sBAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,UAAU,CAAC,OAAO,IAAG,eAAe,CAAO,CACvD,EACN;AACJ;;;;"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The props for the {@link Markdown} component.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface MarkdownProps {
|
|
3
8
|
/** Stringified markdown. */
|
|
4
9
|
content: string;
|
|
5
10
|
/** The response ID correlates to the current message. */
|
|
@@ -14,8 +19,7 @@ interface MarkdownProps {
|
|
|
14
19
|
* @remarks
|
|
15
20
|
* A link click will send a CHAT_LINK_CLICK analytics event
|
|
16
21
|
*
|
|
17
|
-
* @
|
|
22
|
+
* @public
|
|
18
23
|
*/
|
|
19
24
|
export declare function Markdown({ content, responseId, className }: MarkdownProps): React.JSX.Element;
|
|
20
|
-
export {};
|
|
21
25
|
//# sourceMappingURL=Markdown.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../../../../src/components/Markdown.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAcvC,
|
|
1
|
+
{"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../../../../src/components/Markdown.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAcvC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,aAAa,qBAuCzE"}
|
|
@@ -32,7 +32,7 @@ const unifiedPlugins = {
|
|
|
32
32
|
* @remarks
|
|
33
33
|
* A link click will send a CHAT_LINK_CLICK analytics event
|
|
34
34
|
*
|
|
35
|
-
* @
|
|
35
|
+
* @public
|
|
36
36
|
*/
|
|
37
37
|
function Markdown({ content, responseId, className }) {
|
|
38
38
|
const reportAnalyticsEvent = useReportAnalyticsEvent.useReportAnalyticsEvent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.js","sources":["../../../../src/components/Markdown.tsx"],"sourcesContent":["import ReactMarkdown, {\n PluggableList,\n ReactMarkdownOptions,\n} from \"react-markdown\";\nimport remarkGfm from \"remark-gfm\";\nimport rehypeRaw from \"rehype-raw\";\nimport rehypeSanitize from \"rehype-sanitize\";\nimport React, { useMemo } from \"react\";\nimport { useReportAnalyticsEvent } from \"../hooks/useReportAnalyticsEvent\";\n\n// The Remark and Rehype plugins to use in conjunction with ReactMarkdown.\nconst unifiedPlugins: { remark?: PluggableList; rehype: PluggableList } = {\n remark: [\n remarkGfm, //renders Github-Flavored Markdown\n ],\n rehype: [\n rehypeRaw, //to support HTML embedded in markdown\n rehypeSanitize, //to sanitize HTML content\n ],\n};\n\
|
|
1
|
+
{"version":3,"file":"Markdown.js","sources":["../../../../src/components/Markdown.tsx"],"sourcesContent":["import ReactMarkdown, {\n PluggableList,\n ReactMarkdownOptions,\n} from \"react-markdown\";\nimport remarkGfm from \"remark-gfm\";\nimport rehypeRaw from \"rehype-raw\";\nimport rehypeSanitize from \"rehype-sanitize\";\nimport React, { useMemo } from \"react\";\nimport { useReportAnalyticsEvent } from \"../hooks/useReportAnalyticsEvent\";\n\n// The Remark and Rehype plugins to use in conjunction with ReactMarkdown.\nconst unifiedPlugins: { remark?: PluggableList; rehype: PluggableList } = {\n remark: [\n remarkGfm, //renders Github-Flavored Markdown\n ],\n rehype: [\n rehypeRaw, //to support HTML embedded in markdown\n rehypeSanitize, //to sanitize HTML content\n ],\n};\n\n/**\n * The props for the {@link Markdown} component.\n * \n * @public\n */\nexport interface MarkdownProps {\n /** Stringified markdown. */\n content: string;\n /** The response ID correlates to the current message. */\n responseId?: string;\n /** Classnames for the container. */\n className?: string;\n}\n\n/**\n * Renders Github-Flavored Markdown from the Knowledge Graph. This Markdown can include\n * arbitrary HTML. Any HTML will be sanitized according to Rehype's default Schema.\n *\n * @remarks\n * A link click will send a CHAT_LINK_CLICK analytics event\n *\n * @public\n */\nexport function Markdown({ content, responseId, className }: MarkdownProps) {\n const reportAnalyticsEvent = useReportAnalyticsEvent();\n\n const components: ReactMarkdownOptions[\"components\"] = useMemo(() => {\n const createClickHandlerFn = (href?: string) => () => {\n reportAnalyticsEvent({\n action: \"CHAT_LINK_CLICK\",\n destinationUrl: href,\n chat: {\n responseId,\n },\n });\n };\n return {\n a: ({ node: _, children, ...props }) => {\n return (\n <a\n {...props}\n onClick={createClickHandlerFn(props.href)}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"cursor-pointer\"\n >\n {children}\n </a>\n );\n },\n };\n }, [reportAnalyticsEvent, responseId]);\n\n return (\n <ReactMarkdown\n className={className}\n children={content}\n remarkPlugins={unifiedPlugins.remark}\n rehypePlugins={unifiedPlugins.rehype}\n components={components}\n />\n );\n}\n"],"names":["remarkGfm","rehypeRaw","rehypeSanitize","useReportAnalyticsEvent","useMemo","React","ReactMarkdown"],"mappings":";;;;;;;;;;;;;;;;;AAUA;AACA,MAAM,cAAc,GAAsD;AACxE,IAAA,MAAM,EAAE;AACN,QAAAA,0BAAS;AACV,KAAA;AACD,IAAA,MAAM,EAAE;QACNC,0BAAS;AACT,QAAAC,+BAAc;AACf,KAAA;CACF,CAAC;AAgBF;;;;;;;;AAQG;AACG,SAAU,QAAQ,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAiB,EAAA;AACxE,IAAA,MAAM,oBAAoB,GAAGC,+CAAuB,EAAE,CAAC;AAEvD,IAAA,MAAM,UAAU,GAAuCC,aAAO,CAAC,MAAK;QAClE,MAAM,oBAAoB,GAAG,CAAC,IAAa,KAAK,MAAK;AACnD,YAAA,oBAAoB,CAAC;AACnB,gBAAA,MAAM,EAAE,iBAAiB;AACzB,gBAAA,cAAc,EAAE,IAAI;AACpB,gBAAA,IAAI,EAAE;oBACJ,UAAU;AACX,iBAAA;AACF,aAAA,CAAC,CAAC;AACL,SAAC,CAAC;QACF,OAAO;AACL,YAAA,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,KAAI;AACrC,gBAAA,QACEC,sBAAA,CAAA,aAAA,CAAA,GAAA,EAAA,EAAA,GACM,KAAK,EACT,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,EACzC,MAAM,EAAC,QAAQ,EACf,GAAG,EAAC,qBAAqB,EACzB,SAAS,EAAC,gBAAgB,EAEzB,EAAA,QAAQ,CACP,EACJ;aACH;SACF,CAAC;AACJ,KAAC,EAAE,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC,CAAC;AAEvC,IAAA,QACEA,sBAAA,CAAA,aAAA,CAACC,8BAAa,EAAA,EACZ,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,cAAc,CAAC,MAAM,EACpC,aAAa,EAAE,cAAc,CAAC,MAAM,EACpC,UAAU,EAAE,UAAU,EAAA,CACtB,EACF;AACJ;;;;"}
|
|
@@ -4,9 +4,13 @@ export { ChatHeader } from "./ChatHeader";
|
|
|
4
4
|
export type { ChatHeaderCssClasses, ChatHeaderProps } from "./ChatHeader";
|
|
5
5
|
export { MessageBubble } from "./MessageBubble";
|
|
6
6
|
export type { MessageBubbleCssClasses, MessageBubbleProps, } from "./MessageBubble";
|
|
7
|
-
export type { FeedbackButtonsCssClasses } from "./FeedbackButtons";
|
|
8
7
|
export { ChatPanel } from "./ChatPanel";
|
|
9
8
|
export type { ChatPanelCssClasses, ChatPanelProps } from "./ChatPanel";
|
|
10
9
|
export { ChatPopUp } from "./ChatPopUp";
|
|
11
10
|
export type { ChatPopUpCssClasses, ChatPopUpProps } from "./ChatPopUp";
|
|
11
|
+
export { FeedbackButtons } from "./FeedbackButtons";
|
|
12
|
+
export type { FeedbackButtonsCssClasses, FeedbackButtonsProps } from "./FeedbackButtons";
|
|
13
|
+
export { Markdown } from "./Markdown";
|
|
14
|
+
export { MarkdownProps } from "./Markdown";
|
|
15
|
+
export type { InitialMessagePopUpCssClasses } from "./InitialMessagePopUp";
|
|
12
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,YAAY,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export { useComposedCssClasses } from "./useComposedCssClasses";
|
|
2
|
+
export { useDefaultHandleApiError } from "./useDefaultHandleApiError";
|
|
3
|
+
export { useFetchInitialMessage } from "./useFetchInitialMessage";
|
|
4
|
+
export { useReportAnalyticsEvent } from "./useReportAnalyticsEvent";
|
|
5
|
+
export { useScrollToLastMessage } from "./useScrollToLastMessage";
|
|
2
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
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,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Returns a default handler function for API errors. It will log the error and
|
|
3
3
|
* add a default error message to state.
|
|
4
4
|
*
|
|
5
|
-
* @
|
|
5
|
+
* @public
|
|
6
6
|
*/
|
|
7
7
|
export declare function useDefaultHandleApiError(): (e: unknown) => void;
|
|
8
8
|
//# sourceMappingURL=useDefaultHandleApiError.d.ts.map
|
|
@@ -7,7 +7,7 @@ var React = require('react');
|
|
|
7
7
|
* Returns a default handler function for API errors. It will log the error and
|
|
8
8
|
* add a default error message to state.
|
|
9
9
|
*
|
|
10
|
-
* @
|
|
10
|
+
* @public
|
|
11
11
|
*/
|
|
12
12
|
function useDefaultHandleApiError() {
|
|
13
13
|
const chat = chatHeadlessReact.useChatActions();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDefaultHandleApiError.js","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 * @
|
|
1
|
+
{"version":3,"file":"useDefaultHandleApiError.js","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 * @public\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":["useChatActions","useCallback","MessageSource"],"mappings":";;;;;AAGA;;;;;AAKG;SACa,wBAAwB,GAAA;AACtC,IAAA,MAAM,IAAI,GAAGA,gCAAc,EAAE,CAAC;AAE9B,IAAA,OAAOC,iBAAW,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,EAAEC,+BAAa,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;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
* @public
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,QAuCvB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var chatHeadlessReact = require('@yext/chat-headless-react');
|
|
5
|
+
var useDefaultHandleApiError = require('./useDefaultHandleApiError.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Sends a request to Chat API to fetch the initial message when the
|
|
9
|
+
* conversation first start or when the message history is reset.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*
|
|
13
|
+
* @param handleError - A function which is called when an error occurs while fetching for initial message.
|
|
14
|
+
* By default, the error is logged to the console and an error message is added to state.
|
|
15
|
+
* @param stream - Enable streaming behavior by making a request to Chat Streaming API. Defaults to false.
|
|
16
|
+
* @param customCondition - additional condition for when to fetch initial message
|
|
17
|
+
*/
|
|
18
|
+
function useFetchInitialMessage(handleError, stream = false, customCondition = true) {
|
|
19
|
+
const chat = chatHeadlessReact.useChatActions();
|
|
20
|
+
const defaultHandleApiError = useDefaultHandleApiError.useDefaultHandleApiError();
|
|
21
|
+
const messages = chatHeadlessReact.useChatState((state) => state.conversation.messages);
|
|
22
|
+
const [fetchInitialMessage, setFetchInitialMessage] = React.useState(messages.length === 0);
|
|
23
|
+
const [messagesLength, setMessagesLength] = React.useState(messages.length);
|
|
24
|
+
const canSendMessage = chatHeadlessReact.useChatState((state) => state.conversation.canSendMessage);
|
|
25
|
+
//handle message history resets
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
const newMessagesLength = messages.length;
|
|
28
|
+
// Fetch data only when the conversation messages changes from non-zero to zero
|
|
29
|
+
if (messagesLength > 0 && newMessagesLength === 0) {
|
|
30
|
+
setFetchInitialMessage(true);
|
|
31
|
+
}
|
|
32
|
+
setMessagesLength(newMessagesLength);
|
|
33
|
+
}, [messages.length, messagesLength]);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (!fetchInitialMessage || !canSendMessage || !customCondition) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
setFetchInitialMessage(false);
|
|
39
|
+
const res = stream ? chat.streamNextMessage() : chat.getNextMessage();
|
|
40
|
+
res.catch((e) => (handleError ? handleError(e) : defaultHandleApiError(e)));
|
|
41
|
+
}, [
|
|
42
|
+
chat,
|
|
43
|
+
stream,
|
|
44
|
+
handleError,
|
|
45
|
+
defaultHandleApiError,
|
|
46
|
+
fetchInitialMessage,
|
|
47
|
+
canSendMessage,
|
|
48
|
+
customCondition,
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.useFetchInitialMessage = useFetchInitialMessage;
|
|
53
|
+
//# sourceMappingURL=useFetchInitialMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFetchInitialMessage.js","sources":["../../../../src/hooks/useFetchInitialMessage.ts"],"sourcesContent":["import { useEffect, useState } 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 * @public\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 [fetchInitialMessage, setFetchInitialMessage] = useState(\n messages.length === 0\n );\n const [messagesLength, setMessagesLength] = useState(messages.length);\n const canSendMessage = useChatState(\n (state) => state.conversation.canSendMessage\n );\n\n //handle message history resets\n useEffect(() => {\n const newMessagesLength = messages.length;\n // Fetch data only when the conversation messages changes from non-zero to zero\n if (messagesLength > 0 && newMessagesLength === 0) {\n setFetchInitialMessage(true);\n }\n setMessagesLength(newMessagesLength);\n }, [messages.length, messagesLength]);\n\n useEffect(() => {\n if (!fetchInitialMessage || !canSendMessage || !customCondition) {\n return;\n }\n setFetchInitialMessage(false);\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 fetchInitialMessage,\n canSendMessage,\n customCondition,\n ]);\n}\n"],"names":["useChatActions","useDefaultHandleApiError","useChatState","useState","useEffect"],"mappings":";;;;;;AAIA;;;;;;;;;;AAUG;AACG,SAAU,sBAAsB,CACpC,WAAkC,EAClC,MAAM,GAAG,KAAK,EACd,eAAe,GAAG,IAAI,EAAA;AAEtB,IAAA,MAAM,IAAI,GAAGA,gCAAc,EAAE,CAAC;AAC9B,IAAA,MAAM,qBAAqB,GAAGC,iDAAwB,EAAE,CAAC;AACzD,IAAA,MAAM,QAAQ,GAAGC,8BAAY,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AACtE,IAAA,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAGC,cAAQ,CAC5D,QAAQ,CAAC,MAAM,KAAK,CAAC,CACtB,CAAC;AACF,IAAA,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAGA,cAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACtE,IAAA,MAAM,cAAc,GAAGD,8BAAY,CACjC,CAAC,KAAK,KAAK,KAAK,CAAC,YAAY,CAAC,cAAc,CAC7C,CAAC;;IAGFE,eAAS,CAAC,MAAK;AACb,QAAA,MAAM,iBAAiB,GAAG,QAAQ,CAAC,MAAM,CAAC;;AAE1C,QAAA,IAAI,cAAc,GAAG,CAAC,IAAI,iBAAiB,KAAK,CAAC,EAAE;YACjD,sBAAsB,CAAC,IAAI,CAAC,CAAC;AAC9B,SAAA;QACD,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;KACtC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IAEtCA,eAAS,CAAC,MAAK;QACb,IAAI,CAAC,mBAAmB,IAAI,CAAC,cAAc,IAAI,CAAC,eAAe,EAAE;YAC/D,OAAO;AACR,SAAA;QACD,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAC9B,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,mBAAmB;QACnB,cAAc;QACd,eAAe;AAChB,KAAA,CAAC,CAAC;AACL;;;;"}
|
|
@@ -4,7 +4,7 @@ import { ChatHeadless } from "@yext/chat-headless-react";
|
|
|
4
4
|
* The payload will automatically includes chat-ui-react's
|
|
5
5
|
* package version for "clientSdk" field.
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
7
|
+
* @public
|
|
8
8
|
*/
|
|
9
9
|
export declare function useReportAnalyticsEvent(): ChatHeadless["report"];
|
|
10
10
|
//# sourceMappingURL=useReportAnalyticsEvent.d.ts.map
|
|
@@ -9,7 +9,7 @@ var React = require('react');
|
|
|
9
9
|
* The payload will automatically includes chat-ui-react's
|
|
10
10
|
* package version for "clientSdk" field.
|
|
11
11
|
*
|
|
12
|
-
* @
|
|
12
|
+
* @public
|
|
13
13
|
*/
|
|
14
14
|
function useReportAnalyticsEvent() {
|
|
15
15
|
const chat = chatHeadlessReact.useChatActions();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReportAnalyticsEvent.js","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 * The payload will automatically includes chat-ui-react's\n * package version for \"clientSdk\" field.\n *\n * @
|
|
1
|
+
{"version":3,"file":"useReportAnalyticsEvent.js","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 * The payload will automatically includes chat-ui-react's\n * package version for \"clientSdk\" field.\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":["useChatActions","version","useCallback"],"mappings":";;;;;;AAIA;;;;;;AAMG;SACa,uBAAuB,GAAA;AACrC,IAAA,MAAM,IAAI,GAAGA,gCAAc,EAAE,CAAC;IAC9B,IAAI,CAAC,YAAY,CAAC;AAChB,QAAA,aAAa,EAAEC,gBAAO;AACvB,KAAA,CAAC,CAAC;AACH,IAAA,OAAOC,iBAAW,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AAChE;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Scroll the messsages container to the top of the last message whenever there's
|
|
4
|
+
* an update to the messages state.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*
|
|
8
|
+
* @returns a ref to set on the messages container element and
|
|
9
|
+
* a function to set ref on individual message element
|
|
10
|
+
*/
|
|
11
|
+
export declare function useScrollToLastMessage(): [
|
|
12
|
+
React.RefObject<HTMLDivElement>,
|
|
13
|
+
(index: number) => ((message: HTMLDivElement) => void) | undefined
|
|
14
|
+
];
|
|
15
|
+
//# sourceMappingURL=useScrollToLastMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollToLastMessage.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useScrollToLastMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAE9D;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,IAAI;IACxC,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;IAC/B,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC,GAAG,SAAS;CACnE,CA+BA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chatHeadlessReact = require('@yext/chat-headless-react');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Scroll the messsages container to the top of the last message whenever there's
|
|
8
|
+
* an update to the messages state.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*
|
|
12
|
+
* @returns a ref to set on the messages container element and
|
|
13
|
+
* a function to set ref on individual message element
|
|
14
|
+
*/
|
|
15
|
+
function useScrollToLastMessage() {
|
|
16
|
+
const messagesRef = React.useRef([]);
|
|
17
|
+
const messagesContainerRef = React.useRef(null);
|
|
18
|
+
const messages = chatHeadlessReact.useChatState((state) => state.conversation.messages);
|
|
19
|
+
// Handle scrolling when messages change
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
let scrollTop = 0;
|
|
22
|
+
messagesRef.current = messagesRef.current.slice(0, messages.length);
|
|
23
|
+
// Sums up scroll heights of all messages except the last one
|
|
24
|
+
if (messagesRef?.current.length > 1) {
|
|
25
|
+
scrollTop = messagesRef.current
|
|
26
|
+
.slice(0, -1)
|
|
27
|
+
.map((elem, _) => elem?.scrollHeight ?? 0)
|
|
28
|
+
.reduce((total, height) => total + height);
|
|
29
|
+
}
|
|
30
|
+
// Scroll to the top of the last message
|
|
31
|
+
messagesContainerRef.current?.scroll({
|
|
32
|
+
top: scrollTop,
|
|
33
|
+
behavior: "smooth",
|
|
34
|
+
});
|
|
35
|
+
}, [messages]);
|
|
36
|
+
const setMessageRef = React.useCallback((index) => {
|
|
37
|
+
if (!messagesRef?.current)
|
|
38
|
+
return undefined;
|
|
39
|
+
return (message) => (messagesRef.current[index] = message);
|
|
40
|
+
}, []);
|
|
41
|
+
return [messagesContainerRef, setMessageRef];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
exports.useScrollToLastMessage = useScrollToLastMessage;
|
|
45
|
+
//# sourceMappingURL=useScrollToLastMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollToLastMessage.js","sources":["../../../../src/hooks/useScrollToLastMessage.ts"],"sourcesContent":["import { useChatState } from \"@yext/chat-headless-react\";\nimport React, { useCallback, useEffect, useRef } from \"react\";\n\n/**\n * Scroll the messsages container to the top of the last message whenever there's\n * an update to the messages state.\n * \n * @public\n * \n * @returns a ref to set on the messages container element and\n * a function to set ref on individual message element\n */\nexport function useScrollToLastMessage(): [\n React.RefObject<HTMLDivElement>,\n (index: number) => ((message: HTMLDivElement) => void) | undefined\n] {\n const messagesRef = useRef<Array<HTMLDivElement | null>>([]);\n const messagesContainerRef = useRef<HTMLDivElement>(null);\n const messages = useChatState((state) => state.conversation.messages);\n\n // Handle scrolling when messages change\n useEffect(() => {\n let scrollTop = 0;\n messagesRef.current = messagesRef.current.slice(0, messages.length);\n\n // Sums up scroll heights of all messages except the last one\n if (messagesRef?.current.length > 1) {\n scrollTop = messagesRef.current\n .slice(0, -1)\n .map((elem, _) => elem?.scrollHeight ?? 0)\n .reduce((total, height) => total + height);\n }\n\n // Scroll to the top of the last message\n messagesContainerRef.current?.scroll({\n top: scrollTop,\n behavior: \"smooth\",\n });\n }, [messages]);\n\n const setMessageRef = useCallback((index) => {\n if (!messagesRef?.current) return undefined;\n return (message: HTMLDivElement) => (messagesRef.current[index] = message);\n }, []);\n\n return [messagesContainerRef, setMessageRef]\n}"],"names":["useRef","useChatState","useEffect","useCallback"],"mappings":";;;;;AAGA;;;;;;;;AAQG;SACa,sBAAsB,GAAA;AAIpC,IAAA,MAAM,WAAW,GAAGA,YAAM,CAA+B,EAAE,CAAC,CAAC;AAC7D,IAAA,MAAM,oBAAoB,GAAGA,YAAM,CAAiB,IAAI,CAAC,CAAC;AAC1D,IAAA,MAAM,QAAQ,GAAGC,8BAAY,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;;IAGtEC,eAAS,CAAC,MAAK;QACb,IAAI,SAAS,GAAG,CAAC,CAAC;AAClB,QAAA,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;;AAGpE,QAAA,IAAI,WAAW,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YACnC,SAAS,GAAG,WAAW,CAAC,OAAO;AAC5B,iBAAA,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACZ,iBAAA,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,EAAE,YAAY,IAAI,CAAC,CAAC;AACzC,iBAAA,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,GAAG,MAAM,CAAC,CAAC;AAC9C,SAAA;;AAGD,QAAA,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC;AACnC,YAAA,GAAG,EAAE,SAAS;AACd,YAAA,QAAQ,EAAE,QAAQ;AACnB,SAAA,CAAC,CAAC;AACL,KAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEf,IAAA,MAAM,aAAa,GAAGC,iBAAW,CAAC,CAAC,KAAK,KAAI;QAC1C,IAAI,CAAC,WAAW,EAAE,OAAO;AAAE,YAAA,OAAO,SAAS,CAAC;AAC5C,QAAA,OAAO,CAAC,OAAuB,MAAM,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC;KAC5E,EAAE,EAAE,CAAC,CAAC;AAEP,IAAA,OAAO,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAA;AAC9C;;;;"}
|
|
@@ -5,7 +5,13 @@ var ChatHeader = require('./components/ChatHeader.js');
|
|
|
5
5
|
var MessageBubble = require('./components/MessageBubble.js');
|
|
6
6
|
var ChatPanel = require('./components/ChatPanel.js');
|
|
7
7
|
var ChatPopUp = require('./components/ChatPopUp.js');
|
|
8
|
+
var FeedbackButtons = require('./components/FeedbackButtons.js');
|
|
9
|
+
var Markdown = require('./components/Markdown.js');
|
|
8
10
|
var useComposedCssClasses = require('./hooks/useComposedCssClasses.js');
|
|
11
|
+
var useDefaultHandleApiError = require('./hooks/useDefaultHandleApiError.js');
|
|
12
|
+
var useFetchInitialMessage = require('./hooks/useFetchInitialMessage.js');
|
|
13
|
+
var useReportAnalyticsEvent = require('./hooks/useReportAnalyticsEvent.js');
|
|
14
|
+
var useScrollToLastMessage = require('./hooks/useScrollToLastMessage.js');
|
|
9
15
|
|
|
10
16
|
|
|
11
17
|
|
|
@@ -14,5 +20,11 @@ exports.ChatHeader = ChatHeader.ChatHeader;
|
|
|
14
20
|
exports.MessageBubble = MessageBubble.MessageBubble;
|
|
15
21
|
exports.ChatPanel = ChatPanel.ChatPanel;
|
|
16
22
|
exports.ChatPopUp = ChatPopUp.ChatPopUp;
|
|
23
|
+
exports.FeedbackButtons = FeedbackButtons.FeedbackButtons;
|
|
24
|
+
exports.Markdown = Markdown.Markdown;
|
|
17
25
|
exports.useComposedCssClasses = useComposedCssClasses.useComposedCssClasses;
|
|
26
|
+
exports.useDefaultHandleApiError = useDefaultHandleApiError.useDefaultHandleApiError;
|
|
27
|
+
exports.useFetchInitialMessage = useFetchInitialMessage.useFetchInitialMessage;
|
|
28
|
+
exports.useReportAnalyticsEvent = useReportAnalyticsEvent.useReportAnalyticsEvent;
|
|
29
|
+
exports.useScrollToLastMessage = useScrollToLastMessage.useScrollToLastMessage;
|
|
18
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ChatHeadless } from '@yext/chat-headless-react';
|
|
1
2
|
import { Message } from '@yext/chat-headless-react';
|
|
2
3
|
import { default as React_2 } from 'react';
|
|
3
4
|
|
|
@@ -169,11 +170,16 @@ export declare interface ChatPopUpCssClasses {
|
|
|
169
170
|
panel__display?: string;
|
|
170
171
|
panel__hidden?: string;
|
|
171
172
|
button?: string;
|
|
172
|
-
button__display?: string;
|
|
173
|
-
button__hidden?: string;
|
|
174
173
|
buttonIcon?: string;
|
|
174
|
+
ctaLabelContainer?: string;
|
|
175
|
+
ctaLabel?: string;
|
|
176
|
+
notification?: string;
|
|
177
|
+
closedPopupContainer?: string;
|
|
178
|
+
closedPopupContainer__display?: string;
|
|
179
|
+
closedPopupContainer__hidden?: string;
|
|
175
180
|
headerCssClasses?: ChatHeaderCssClasses;
|
|
176
181
|
panelCssClasses?: ChatPanelCssClasses;
|
|
182
|
+
initialMessagePopUpCssClasses?: InitialMessagePopUpCssClasses;
|
|
177
183
|
}
|
|
178
184
|
|
|
179
185
|
/**
|
|
@@ -184,12 +190,41 @@ export declare interface ChatPopUpCssClasses {
|
|
|
184
190
|
export declare interface ChatPopUpProps extends Omit<ChatHeaderProps, "showCloseButton" | "customCssClasses">, Omit<ChatPanelProps, "header" | "customCssClasses"> {
|
|
185
191
|
/** Custom icon for the popup button to open the panel. */
|
|
186
192
|
openPanelButtonIcon?: JSX.Element;
|
|
193
|
+
/** CSS classes for customizing the component styling. */
|
|
194
|
+
customCssClasses?: ChatPopUpCssClasses;
|
|
195
|
+
/** Whether to show the panel on load. Defaults to false. */
|
|
196
|
+
openOnLoad?: boolean;
|
|
187
197
|
/**
|
|
188
|
-
*
|
|
198
|
+
* Whether to show the initial message popup when the panel is hidden on load.
|
|
199
|
+
* Defaults to false.
|
|
189
200
|
*/
|
|
190
|
-
|
|
201
|
+
showInitialMessagePopUp?: boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Whether to show a heartbeat animation on the popup button when the panel is hidden.
|
|
204
|
+
* Defaults to false.
|
|
205
|
+
*/
|
|
206
|
+
showHeartBeatAnimation?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Whether to show notification showing number of unread messages.
|
|
209
|
+
* Defaults to false.
|
|
210
|
+
*/
|
|
211
|
+
showUnreadNotification?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* The "Call to Action" label to be displayed next to the popup button.
|
|
214
|
+
* By default, the CTA is not shown.
|
|
215
|
+
* This prop will override the "showInitialMessagePopUp" prop, if specified.
|
|
216
|
+
*/
|
|
217
|
+
ctaLabel?: string;
|
|
191
218
|
}
|
|
192
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Displays feedback buttons (e.g. thumbs up and thumbs down) that will
|
|
222
|
+
* report analytic events on click.
|
|
223
|
+
*
|
|
224
|
+
* @public
|
|
225
|
+
*/
|
|
226
|
+
export declare function FeedbackButtons({ customCssClasses, responseId, }: FeedbackButtonsProps): React_2.JSX.Element;
|
|
227
|
+
|
|
193
228
|
/**
|
|
194
229
|
* The CSS class interface for the FeedbackButtons component.
|
|
195
230
|
*
|
|
@@ -205,6 +240,55 @@ export declare interface FeedbackButtonsCssClasses {
|
|
|
205
240
|
thumbsDownFillIcon?: string;
|
|
206
241
|
}
|
|
207
242
|
|
|
243
|
+
/**
|
|
244
|
+
* The props for the FeedbackButtons component.
|
|
245
|
+
*
|
|
246
|
+
* @public
|
|
247
|
+
*/
|
|
248
|
+
export declare interface FeedbackButtonsProps {
|
|
249
|
+
/** The response ID correlates to the current message to give feedback on. */
|
|
250
|
+
responseId?: string;
|
|
251
|
+
/** CSS classes for customizing the component styling. */
|
|
252
|
+
customCssClasses?: FeedbackButtonsCssClasses;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* The CSS class interface for the InitialMessagePopUp component.
|
|
257
|
+
*
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
260
|
+
export declare interface InitialMessagePopUpCssClasses {
|
|
261
|
+
container?: string;
|
|
262
|
+
closeButton?: string;
|
|
263
|
+
closeButtonIcon?: string;
|
|
264
|
+
message?: string;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Renders Github-Flavored Markdown from the Knowledge Graph. This Markdown can include
|
|
269
|
+
* arbitrary HTML. Any HTML will be sanitized according to Rehype's default Schema.
|
|
270
|
+
*
|
|
271
|
+
* @remarks
|
|
272
|
+
* A link click will send a CHAT_LINK_CLICK analytics event
|
|
273
|
+
*
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
export declare function Markdown({ content, responseId, className }: MarkdownProps): React_2.JSX.Element;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The props for the {@link Markdown} component.
|
|
280
|
+
*
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
export declare interface MarkdownProps {
|
|
284
|
+
/** Stringified markdown. */
|
|
285
|
+
content: string;
|
|
286
|
+
/** The response ID correlates to the current message. */
|
|
287
|
+
responseId?: string;
|
|
288
|
+
/** Classnames for the container. */
|
|
289
|
+
className?: string;
|
|
290
|
+
}
|
|
291
|
+
|
|
208
292
|
/**
|
|
209
293
|
* A component that displays the provided message.
|
|
210
294
|
*
|
|
@@ -294,4 +378,48 @@ export declare interface MessageBubbleProps {
|
|
|
294
378
|
*/
|
|
295
379
|
export declare function useComposedCssClasses<ClassInterface extends Partial<Record<keyof ClassInterface, string | object>>>(builtInClasses: Readonly<ClassInterface>, customClasses?: Partial<ClassInterface>): ClassInterface;
|
|
296
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Returns a default handler function for API errors. It will log the error and
|
|
383
|
+
* add a default error message to state.
|
|
384
|
+
*
|
|
385
|
+
* @public
|
|
386
|
+
*/
|
|
387
|
+
export declare function useDefaultHandleApiError(): (e: unknown) => void;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Sends a request to Chat API to fetch the initial message when the
|
|
391
|
+
* conversation first start or when the message history is reset.
|
|
392
|
+
*
|
|
393
|
+
* @public
|
|
394
|
+
*
|
|
395
|
+
* @param handleError - A function which is called when an error occurs while fetching for initial message.
|
|
396
|
+
* By default, the error is logged to the console and an error message is added to state.
|
|
397
|
+
* @param stream - Enable streaming behavior by making a request to Chat Streaming API. Defaults to false.
|
|
398
|
+
* @param customCondition - additional condition for when to fetch initial message
|
|
399
|
+
*/
|
|
400
|
+
export declare function useFetchInitialMessage(handleError?: (e: unknown) => void, stream?: boolean, customCondition?: boolean): void;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Returns a function to send requests to Yext Analytics API.
|
|
404
|
+
* The payload will automatically includes chat-ui-react's
|
|
405
|
+
* package version for "clientSdk" field.
|
|
406
|
+
*
|
|
407
|
+
* @public
|
|
408
|
+
*/
|
|
409
|
+
export declare function useReportAnalyticsEvent(): ChatHeadless["report"];
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Scroll the messsages container to the top of the last message whenever there's
|
|
413
|
+
* an update to the messages state.
|
|
414
|
+
*
|
|
415
|
+
* @public
|
|
416
|
+
*
|
|
417
|
+
* @returns a ref to set on the messages container element and
|
|
418
|
+
* a function to set ref on individual message element
|
|
419
|
+
*/
|
|
420
|
+
export declare function useScrollToLastMessage(): [
|
|
421
|
+
React_2.RefObject<HTMLDivElement>,
|
|
422
|
+
(index: number) => ((message: HTMLDivElement) => void) | undefined
|
|
423
|
+
];
|
|
424
|
+
|
|
297
425
|
export { }
|
package/lib/esm/package.json.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import React, { useState, useCallback } from 'react';
|
|
|
2
2
|
import { useChatActions, useChatState } from '@yext/chat-headless-react';
|
|
3
3
|
import { ArrowIcon } from '../icons/Arrow.mjs';
|
|
4
4
|
import { useComposedCssClasses } from '../hooks/useComposedCssClasses.mjs';
|
|
5
|
-
import TextareaAutosize from 'react-textarea-autosize';
|
|
6
5
|
import { useDefaultHandleApiError } from '../hooks/useDefaultHandleApiError.mjs';
|
|
6
|
+
import TextareaAutosize from 'react-textarea-autosize';
|
|
7
7
|
import { withStylelessCssClasses } from '../utils/withStylelessCssClasses.mjs';
|
|
8
8
|
|
|
9
9
|
const builtInCssClasses = withStylelessCssClasses("Input", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatPanel.d.ts","sourceRoot":"","sources":["../../../../src/components/ChatPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ChatPanel.d.ts","sourceRoot":"","sources":["../../../../src/components/ChatPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAEL,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAa,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAU7E;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;CACnD;AAeD;;;;GAIG;AACH,MAAM,WAAW,cACf,SAAQ,IAAI,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,SAAS,CAAC,EAC9D,IAAI,CAAC,cAAc,EAAE,kBAAkB,CAAC;IAC1C,kDAAkD;IAClD,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACrB;;OAEG;IACH,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;CACxC;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,qBAuC9C"}
|