UNPKG

@memori.ai/memori-react

Version:

[![npm version](https://img.shields.io/github/package-json/v/memori-ai/memori-react)](https://www.npmjs.com/package/@memori.ai/memori-react) ![Tests](https://github.com/memori-ai/memori-react/workflows/CI/badge.svg?branch=main) ![TypeScript Support](https

41 lines 4.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const react_1 = require("react"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_2 = require("react"); const ui_1 = require("@memori.ai/ui"); const Blob_1 = tslib_1.__importDefault(require("../../Blob/Blob")); const lucide_react_1 = require("lucide-react"); const react_i18next_1 = require("react-i18next"); const ArtifactContext_1 = require("../../MemoriArtifactSystem/context/ArtifactContext"); const ArtifactDrawer_1 = tslib_1.__importDefault(require("../../MemoriArtifactSystem/components/ArtifactDrawer/ArtifactDrawer")); const WebsiteAssistantLayout = ({ Header, headerProps, Avatar, avatarProps, Chat, chatProps, StartPanel, startPanelProps, integrationStyle, sessionId, hasUserActivatedSpeak, loading = false, poweredBy, avatar3dHidden, }) => { var _a, _b; const { t } = (0, react_i18next_1.useTranslation)(); const { state: artifactState } = (0, ArtifactContext_1.useArtifact)(); const useSideArtifactChrome = artifactState.isDrawerOpen && !artifactState.isChatLogPanelPresentation; const [collapsed, _setCollapsed] = (0, react_2.useState)(true); const [expandedKey, setExpandedKey] = (0, react_2.useState)(); const stopAudio = (0, react_2.useMemo)(() => chatProps === null || chatProps === void 0 ? void 0 : chatProps.stopAudio, [chatProps === null || chatProps === void 0 ? void 0 : chatProps.stopAudio]); const setCollapsed = (collapsed) => { _setCollapsed(collapsed); setExpandedKey(collapsed ? undefined : new Date().toISOString()); try { stopAudio === null || stopAudio === void 0 ? void 0 : stopAudio(); } catch (e) { console.log(e); } }; return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [collapsed && ((0, jsx_runtime_1.jsx)("div", { className: "memori-website_assistant--trigger", children: (0, jsx_runtime_1.jsx)(ui_1.Button, { className: "memori-website_assistant--trigger-button", variant: "ghost", shape: "circle", onClick: () => setCollapsed(false), "aria-label": t('expand') || 'Expand', "aria-expanded": false, title: t('expand') || 'Expand', children: (0, jsx_runtime_1.jsx)(Blob_1.default, { avatar: avatarProps === null || avatarProps === void 0 ? void 0 : avatarProps.memori.avatarURL }) }) })), (0, jsx_runtime_1.jsx)("div", { className: `memori-website_assistant--${collapsed ? 'collapsed' : 'expanded'}`, children: !collapsed && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [integrationStyle, (0, jsx_runtime_1.jsxs)(ui_1.Spin, { spinning: loading, className: "memori-website_assistant-layout", children: [poweredBy, (0, jsx_runtime_1.jsxs)("div", { className: "memori-website_assistant-layout--header-row", children: [Header && headerProps && ((0, jsx_runtime_1.jsx)(Header, { buttonVariant: "outline", ...headerProps, showSettings: false, showReload: false })), (0, jsx_runtime_1.jsx)("div", { className: "memori-website_assistant--close-button-wrapper", children: (0, jsx_runtime_1.jsx)(ui_1.Button, { className: "memori-website_assistant--close-button", variant: "ghost", onClick: () => setCollapsed(true), "aria-label": t('close') || 'Close', icon: (0, jsx_runtime_1.jsx)(lucide_react_1.X, { "aria-hidden": true }), title: t('close') || 'Close' }) })] }), !(avatar3dHidden === true || avatar3dHidden === 'true') && ((0, jsx_runtime_1.jsx)("div", { className: "memori-website_assistant-layout--avatar", children: Avatar && avatarProps && ((0, react_1.createElement)(Avatar, { ...avatarProps, integrationConfig: avatarProps.integrationConfig ? { ...avatarProps.integrationConfig, avatarURL: ((_a = avatarProps.integrationConfig) === null || _a === void 0 ? void 0 : _a.avatarURL) ? `${(_b = avatarProps.integrationConfig) === null || _b === void 0 ? void 0 : _b.avatarURL.split('#')[0]}#${expandedKey}` : undefined, } : {}, key: expandedKey })) })), (0, jsx_runtime_1.jsx)("div", { id: "extension" }), (0, jsx_runtime_1.jsx)("div", { className: "memori-website_assistant-layout--controls", children: sessionId && hasUserActivatedSpeak && Chat && chatProps ? ((0, jsx_runtime_1.jsx)(Chat, { ...chatProps })) : startPanelProps ? ((0, jsx_runtime_1.jsx)(StartPanel, { ...startPanelProps, showFullDescriptionOnMobile: true })) : null })] })] })) }), useSideArtifactChrome && (0, jsx_runtime_1.jsx)(ArtifactDrawer_1.default, {})] })); }; exports.default = WebsiteAssistantLayout; //# sourceMappingURL=WebsiteAssistant.js.map