@botonic/react 0.57.0-rslib-esm.1 → 0.57.0-rslib-esm.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,9 +3,5 @@ import { MultichannelButton } from './multichannel-button.js';
3
3
  import { MultichannelCarousel } from './multichannel-carousel.js';
4
4
  import { MultichannelReply } from './multichannel-reply.js';
5
5
  import { MultichannelText } from './multichannel-text.js';
6
- export { Multichannel };
7
- export { MultichannelText };
8
- export { MultichannelButton };
9
- export { MultichannelReply };
10
- export { MultichannelCarousel };
11
6
  export * from './index-types.js';
7
+ export { Multichannel, MultichannelButton, MultichannelCarousel, MultichannelReply, MultichannelText, };
@@ -12,10 +12,6 @@ export * from "./index-types.js";
12
12
 
13
13
 
14
14
 
15
-
16
-
17
-
18
-
19
15
  export { Multichannel } from "./multichannel.js";
20
16
  export { MultichannelButton } from "./multichannel-button.js";
21
17
  export { MultichannelCarousel } from "./multichannel-carousel.js";
@@ -1 +1 @@
1
- {"version":3,"file":"components/multichannel/index.js","sources":["../../../src/components/multichannel/index.ts"],"sourcesContent":["import { Multichannel } from './multichannel'\nimport { MultichannelButton } from './multichannel-button'\nimport { MultichannelCarousel } from './multichannel-carousel'\nimport { MultichannelReply } from './multichannel-reply'\nimport { MultichannelText } from './multichannel-text'\n\nexport { Multichannel }\nexport { MultichannelText }\nexport { MultichannelButton }\nexport { MultichannelReply }\nexport { MultichannelCarousel }\n\nexport * from './index-types'\n"],"names":["Multichannel","MultichannelButton","MultichannelCarousel","MultichannelReply","MultichannelText"],"mappings":";;;;;;AAA6C;AACa;AACI;AACN;AACF;AAE/B;AACI;AACE;AACD;AACG;AAEF"}
1
+ {"version":3,"file":"components/multichannel/index.js","sources":["../../../src/components/multichannel/index.ts"],"sourcesContent":["import { Multichannel } from './multichannel'\nimport { MultichannelButton } from './multichannel-button'\nimport { MultichannelCarousel } from './multichannel-carousel'\nimport { MultichannelReply } from './multichannel-reply'\nimport { MultichannelText } from './multichannel-text'\n\nexport * from './index-types'\nexport {\n Multichannel,\n MultichannelButton,\n MultichannelCarousel,\n MultichannelReply,\n MultichannelText,\n}\n"],"names":["Multichannel","MultichannelButton","MultichannelCarousel","MultichannelReply","MultichannelText"],"mappings":";;;;;;AAA6C;AACa;AACI;AACN;AACF;AAEzB;AAO5B"}
@@ -89,6 +89,7 @@ const WebchatMessageList = ()=>{
89
89
  });
90
90
  });
91
91
  observer.observe(lastMessageRef.current);
92
+ return ()=>observer.disconnect();
92
93
  }
93
94
  }, [
94
95
  webchatState.messagesComponents
@@ -1 +1 @@
1
- {"version":3,"file":"webchat/message-list/index.js","sources":["../../../src/webchat/message-list/index.tsx"],"sourcesContent":["import React, { useContext, useEffect, useRef, useState } from 'react'\n\nimport { ROLES } from '../../constants'\nimport { SENDERS } from '../../index-types'\nimport { WebchatContext } from '../../webchat/context'\nimport { BotonicContainerId } from '../constants'\nimport TypingIndicator from '../typing-indicator'\nimport { IntroMessage } from './intro-message'\nimport { ScrollButton } from './scroll-button'\nimport { MessageContainer, ScrollableMessageList } from './styles'\nimport { UnreadMessagesBanner } from './unread-messages-banner'\nimport { useNotifications } from './use-notifications'\n\nconst SCROLL_TIMEOUT = 200\nconst scrollOptionsEnd: ScrollIntoViewOptions = {\n block: 'end',\n}\nconst scrollOptionsCenter: ScrollIntoViewOptions = {\n block: 'center',\n}\n\nexport const WebchatMessageList = () => {\n const {\n webchatState,\n resetUnreadMessages,\n setLastMessageVisible,\n scrollableMessagesListRef,\n } = useContext(WebchatContext)\n\n const { notificationsEnabled } = useNotifications()\n\n const [firstUnreadMessageId, setFirstUnreadMessageId] = useState<string>()\n\n const lastMessageRef = useRef<HTMLDivElement>(null)\n const typingRef = useRef<HTMLDivElement>(null)\n const unreadMessagesBannerRef = useRef<HTMLDivElement>(null)\n\n const scrollToTyping = () => {\n setTimeout(() => {\n typingRef.current?.scrollIntoView(scrollOptionsEnd)\n }, SCROLL_TIMEOUT)\n }\n\n const scrollToLastMessage = () => {\n setTimeout(() => {\n lastMessageRef.current?.scrollIntoView(scrollOptionsEnd)\n }, SCROLL_TIMEOUT)\n }\n\n const scrollToBanner = () => {\n setTimeout(() => {\n unreadMessagesBannerRef.current?.scrollIntoView(scrollOptionsCenter)\n }, SCROLL_TIMEOUT)\n }\n\n const handleScrollToBottom = () => {\n resetUnreadMessages()\n if (webchatState.typing) {\n scrollToTyping()\n return\n }\n\n scrollToLastMessage()\n }\n\n const showUnreadMessagesBanner = (messageComponentId: string) => {\n return (\n !webchatState.isInputFocused &&\n firstUnreadMessageId &&\n messageComponentId === firstUnreadMessageId &&\n webchatState.numUnreadMessages > 0\n )\n }\n\n useEffect(() => {\n const firstUnreadMessage = webchatState.messagesComponents.find(\n message => message.props.isUnread\n )\n setFirstUnreadMessageId(firstUnreadMessage?.props?.id)\n }, [webchatState.messagesComponents])\n\n useEffect(() => {\n if (webchatState.messagesComponents.length > 0 && lastMessageRef.current) {\n const observer = new IntersectionObserver(entries => {\n entries.forEach(entry => {\n setLastMessageVisible(entry.isIntersecting)\n })\n })\n observer.observe(lastMessageRef.current)\n }\n }, [webchatState.messagesComponents])\n\n useEffect(() => {\n if (!notificationsEnabled) {\n if (webchatState.typing) {\n scrollToTyping()\n return\n }\n\n scrollToLastMessage()\n }\n }, [webchatState.typing, webchatState.messagesComponents])\n\n useEffect(() => {\n if (webchatState.isWebchatOpen && notificationsEnabled) {\n if (unreadMessagesBannerRef.current) {\n scrollToBanner()\n return\n }\n\n if (webchatState.typing) {\n scrollToTyping()\n return\n }\n\n scrollToLastMessage()\n }\n }, [\n firstUnreadMessageId,\n webchatState.isWebchatOpen,\n webchatState.typing,\n webchatState.messagesComponents,\n ])\n\n const showScrollButton =\n webchatState.numUnreadMessages > 0 && !webchatState.isLastMessageVisible\n\n return (\n <>\n <ScrollableMessageList\n id={BotonicContainerId.ScrollableMessagesList}\n ref={scrollableMessagesListRef}\n role={ROLES.MESSAGE_LIST}\n >\n <IntroMessage />\n {webchatState.messagesComponents.map((messageComponent, index) => {\n const messageId = messageComponent.props.id\n const sentBySystem = messageComponent.props?.sentBy === SENDERS.system\n\n // Check if system message is followed by a regular message (user/bot)\n const nextMessage = webchatState.messagesComponents[index + 1]\n const isSystemMessageFollowedByMessage =\n sentBySystem &&\n nextMessage &&\n nextMessage.props?.sentBy !== SENDERS.system\n\n return (\n <React.Fragment key={messageId}>\n <MessageContainer\n role={sentBySystem ? ROLES.SYSTEM_MESSAGE : ROLES.MESSAGE}\n $isLastSystemMessage={isSystemMessageFollowedByMessage}\n >\n {showUnreadMessagesBanner(messageId) && (\n <UnreadMessagesBanner\n unreadMessagesBannerRef={unreadMessagesBannerRef}\n />\n )}\n {messageComponent}\n </MessageContainer>\n {index === webchatState.messagesComponents.length - 1 && (\n <div\n ref={lastMessageRef}\n style={{\n content: '',\n }}\n ></div>\n )}\n </React.Fragment>\n )\n })}\n {webchatState.typing && <TypingIndicator ref={typingRef} />}\n </ScrollableMessageList>\n {showScrollButton && <ScrollButton handleClick={handleScrollToBottom} />}\n </>\n )\n}\n"],"names":["React","useContext","useEffect","useRef","useState","ROLES","SENDERS","WebchatContext","BotonicContainerId","TypingIndicator","IntroMessage","ScrollButton","MessageContainer","ScrollableMessageList","UnreadMessagesBanner","useNotifications","SCROLL_TIMEOUT","scrollOptionsEnd","scrollOptionsCenter","WebchatMessageList","webchatState","resetUnreadMessages","setLastMessageVisible","scrollableMessagesListRef","notificationsEnabled","firstUnreadMessageId","setFirstUnreadMessageId","lastMessageRef","typingRef","unreadMessagesBannerRef","scrollToTyping","setTimeout","scrollToLastMessage","scrollToBanner","handleScrollToBottom","showUnreadMessagesBanner","messageComponentId","firstUnreadMessage","message","observer","IntersectionObserver","entries","entry","showScrollButton","messageComponent","index","messageId","sentBySystem","nextMessage","isSystemMessageFollowedByMessage"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAsE;AAE/B;AACI;AACW;AACL;AACA;AACH;AACA;AACoB;AACH;AACT;AAEtD,MAAMgB,c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C,eAAe1C,oBAAoB,GAAGA,aAAa;oCACzD,sBAAsB4C;;wCAErBd,yBAAyBW,4BACxB,IAAChC,oBAAoBA;4CACnB,yBAAyBe;;wCAG5Be;;;gCAEFC,UAAUzB,aAAa,kBAAkB,CAAC,MAAM,GAAG,mBAClD,IAAC;oCACC,KAAKO;oCACL,OAAO;wCACL,SAAS;oCACX;;;2BAjBemB;oBAsBzB;oBACC1B,aAAa,MAAM,kBAAI,IAACX,gBAAeA;wBAAC,KAAKmB;;;;YAE/Ce,kCAAoB,IAAChC,YAAYA;gBAAC,aAAauB;;;;AAGtD,EAAC"}
1
+ {"version":3,"file":"webchat/message-list/index.js","sources":["../../../src/webchat/message-list/index.tsx"],"sourcesContent":["import React, { useContext, useEffect, useRef, useState } from 'react'\n\nimport { ROLES } from '../../constants'\nimport { SENDERS } from '../../index-types'\nimport { WebchatContext } from '../../webchat/context'\nimport { BotonicContainerId } from '../constants'\nimport TypingIndicator from '../typing-indicator'\nimport { IntroMessage } from './intro-message'\nimport { ScrollButton } from './scroll-button'\nimport { MessageContainer, ScrollableMessageList } from './styles'\nimport { UnreadMessagesBanner } from './unread-messages-banner'\nimport { useNotifications } from './use-notifications'\n\nconst SCROLL_TIMEOUT = 200\nconst scrollOptionsEnd: ScrollIntoViewOptions = {\n block: 'end',\n}\nconst scrollOptionsCenter: ScrollIntoViewOptions = {\n block: 'center',\n}\n\nexport const WebchatMessageList = () => {\n const {\n webchatState,\n resetUnreadMessages,\n setLastMessageVisible,\n scrollableMessagesListRef,\n } = useContext(WebchatContext)\n\n const { notificationsEnabled } = useNotifications()\n\n const [firstUnreadMessageId, setFirstUnreadMessageId] = useState<string>()\n\n const lastMessageRef = useRef<HTMLDivElement>(null)\n const typingRef = useRef<HTMLDivElement>(null)\n const unreadMessagesBannerRef = useRef<HTMLDivElement>(null)\n\n const scrollToTyping = () => {\n setTimeout(() => {\n typingRef.current?.scrollIntoView(scrollOptionsEnd)\n }, SCROLL_TIMEOUT)\n }\n\n const scrollToLastMessage = () => {\n setTimeout(() => {\n lastMessageRef.current?.scrollIntoView(scrollOptionsEnd)\n }, SCROLL_TIMEOUT)\n }\n\n const scrollToBanner = () => {\n setTimeout(() => {\n unreadMessagesBannerRef.current?.scrollIntoView(scrollOptionsCenter)\n }, SCROLL_TIMEOUT)\n }\n\n const handleScrollToBottom = () => {\n resetUnreadMessages()\n if (webchatState.typing) {\n scrollToTyping()\n return\n }\n\n scrollToLastMessage()\n }\n\n const showUnreadMessagesBanner = (messageComponentId: string) => {\n return (\n !webchatState.isInputFocused &&\n firstUnreadMessageId &&\n messageComponentId === firstUnreadMessageId &&\n webchatState.numUnreadMessages > 0\n )\n }\n\n useEffect(() => {\n const firstUnreadMessage = webchatState.messagesComponents.find(\n message => message.props.isUnread\n )\n setFirstUnreadMessageId(firstUnreadMessage?.props?.id)\n }, [webchatState.messagesComponents])\n\n useEffect(() => {\n if (webchatState.messagesComponents.length > 0 && lastMessageRef.current) {\n const observer = new IntersectionObserver(entries => {\n entries.forEach(entry => {\n setLastMessageVisible(entry.isIntersecting)\n })\n })\n observer.observe(lastMessageRef.current)\n return () => observer.disconnect()\n }\n }, [webchatState.messagesComponents])\n\n useEffect(() => {\n if (!notificationsEnabled) {\n if (webchatState.typing) {\n scrollToTyping()\n return\n }\n\n scrollToLastMessage()\n }\n }, [webchatState.typing, webchatState.messagesComponents])\n\n useEffect(() => {\n if (webchatState.isWebchatOpen && notificationsEnabled) {\n if (unreadMessagesBannerRef.current) {\n scrollToBanner()\n return\n }\n\n if (webchatState.typing) {\n scrollToTyping()\n return\n }\n\n scrollToLastMessage()\n }\n }, [\n firstUnreadMessageId,\n webchatState.isWebchatOpen,\n webchatState.typing,\n webchatState.messagesComponents,\n ])\n\n const showScrollButton =\n webchatState.numUnreadMessages > 0 && !webchatState.isLastMessageVisible\n\n return (\n <>\n <ScrollableMessageList\n id={BotonicContainerId.ScrollableMessagesList}\n ref={scrollableMessagesListRef}\n role={ROLES.MESSAGE_LIST}\n >\n <IntroMessage />\n {webchatState.messagesComponents.map((messageComponent, index) => {\n const messageId = messageComponent.props.id\n const sentBySystem = messageComponent.props?.sentBy === SENDERS.system\n\n // Check if system message is followed by a regular message (user/bot)\n const nextMessage = webchatState.messagesComponents[index + 1]\n const isSystemMessageFollowedByMessage =\n sentBySystem &&\n nextMessage &&\n nextMessage.props?.sentBy !== SENDERS.system\n\n return (\n <React.Fragment key={messageId}>\n <MessageContainer\n role={sentBySystem ? ROLES.SYSTEM_MESSAGE : ROLES.MESSAGE}\n $isLastSystemMessage={isSystemMessageFollowedByMessage}\n >\n {showUnreadMessagesBanner(messageId) && (\n <UnreadMessagesBanner\n unreadMessagesBannerRef={unreadMessagesBannerRef}\n />\n )}\n {messageComponent}\n </MessageContainer>\n {index === webchatState.messagesComponents.length - 1 && (\n <div\n ref={lastMessageRef}\n style={{\n content: '',\n }}\n ></div>\n )}\n </React.Fragment>\n )\n })}\n {webchatState.typing && <TypingIndicator ref={typingRef} />}\n </ScrollableMessageList>\n {showScrollButton && <ScrollButton handleClick={handleScrollToBottom} />}\n </>\n )\n}\n"],"names":["React","useContext","useEffect","useRef","useState","ROLES","SENDERS","WebchatContext","BotonicContainerId","TypingIndicator","IntroMessage","ScrollButton","MessageContainer","ScrollableMessageList","UnreadMessagesBanner","useNotifications","SCROLL_TIMEOUT","scrollOptionsEnd","scrollOptionsCenter","WebchatMessageList","webchatState","resetUnreadMessages","setLastMessageVisible","scrollableMessagesListRef","notificationsEnabled","firstUnreadMessageId","setFirstUnreadMessageId","lastMessageRef","typingRef","unreadMessagesBannerRef","scrollToTyping","setTimeout","scrollToLastMessage","scrollToBanner","handleScrollToBottom","showUnreadMessagesBanner","messageComponentId","firstUnreadMessage","message","observer","IntersectionObserver","entries","entry","showScrollButton","messageComponent","index","messageId","sentBySystem","nextMessage","isSystemMessageFollowedByMessage"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAsE;AAE/B;AACI;AACW;AACL;AACA;AACH;AACA;AACoB;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AE9C,qBACE,KAACN,cAAc;;8CACb,KAACY,gBAAgBA;oCACf,MAAMmC,eAAe1C,oBAAoB,GAAGA,aAAa;oCACzD,sBAAsB4C;;wCAErBd,yBAAyBW,4BACxB,IAAChC,oBAAoBA;4CACnB,yBAAyBe;;wCAG5Be;;;gCAEFC,UAAUzB,aAAa,kBAAkB,CAAC,MAAM,GAAG,mBAClD,IAAC;oCACC,KAAKO;oCACL,OAAO;wCACL,SAAS;oCACX;;;2BAjBemB;oBAsBzB;oBACC1B,aAAa,MAAM,kBAAI,IAACX,gBAAeA;wBAAC,KAAKmB;;;;YAE/Ce,kCAAoB,IAAChC,YAAYA;gBAAC,aAAauB;;;;AAGtD,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"webchat/webchat.js","sources":["../../src/webchat/webchat.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport { BotonicAction, INPUT, params2queryString } from '@botonic/core'\nimport merge from 'lodash.merge'\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheetManager, ThemeProvider } from 'styled-components'\nimport { v7 as uuidv7 } from 'uuid'\n\nimport {\n Audio,\n Document,\n Handoff,\n Image,\n normalizeWebchatSettings,\n Text,\n Video,\n type WebchatSettingsProps,\n type Webview,\n} from '../components'\nimport {\n COLORS,\n MAX_ALLOWED_SIZE_MB,\n ROLES,\n WEBCHAT,\n WEBCHAT_DEFAULT_CONTENTS,\n} from '../constants'\nimport type { CloseWebviewOptions } from '../contexts'\nimport { SENDERS, type WebchatProps, type WebchatRef } from '../index-types'\nimport {\n getMediaType,\n isAllowedSize,\n isAudio,\n isDocument,\n isImage,\n isMedia,\n isText,\n isVideo,\n readDataURL,\n} from '../message-utils'\nimport { msgToBotonic } from '../msg-to-botonic'\nimport { isDev } from '../util/environment'\nimport { deserializeRegex, stringifyWithRegexs } from '../util/regexs'\nimport {\n _getThemeProperty,\n getServerErrorMessage,\n initSession,\n shouldKeepSessionOnReload,\n updateUserLocaleAndCountry,\n} from '../util/webchat'\nimport { ChatArea } from './chat-area'\nimport { OpenedPersistentMenu } from './components/opened-persistent-menu'\nimport { BotonicContainerId } from './constants'\nimport { useWebchat, WebchatContext, type WebchatState } from './context'\nimport { CoverComponent } from './cover-component'\nimport { WebchatHeader } from './header'\nimport {\n useComponentWillMount,\n usePrevious,\n useScrollToBottom,\n useTyping,\n} from './hooks'\nimport { InputPanel } from './input-panel'\nimport {\n DarkBackgroundMenu,\n ErrorMessage,\n ErrorMessageContainer,\n StyledWebchat,\n} from './styles'\nimport type { WebchatTheme } from './theme/types'\nimport { TriggerButton } from './trigger-button'\nimport { useStorageState } from './use-storage-state-hook'\nimport { getParsedAction } from './utils'\nimport { WebviewContainer } from './webview/index'\n\nconst Webchat = forwardRef<WebchatRef | null, WebchatProps>((props, ref) => {\n const {\n addMessage,\n addMessageComponent,\n clearMessages,\n doRenderCustomComponent,\n resetUnreadMessages,\n setCurrentAttachment,\n setError,\n setIsInputFocused,\n setLastMessageVisible,\n setOnline,\n toggleCoverComponent,\n toggleEmojiPicker,\n togglePersistentMenu,\n toggleWebchat,\n updateCustomMessageProps,\n updateDevSettings,\n updateHandoff,\n updateLastMessageDate,\n updateLastRoutePath,\n updateLatestInput,\n updateMessage,\n updateReplies,\n updateSession,\n updateTheme,\n updateTyping,\n updateWebview,\n removeWebview,\n removeReplies,\n webchatState,\n webchatContainerRef,\n chatAreaRef,\n inputPanelRef,\n headerRef,\n repliesRef,\n scrollableMessagesListRef,\n } = props.webchatHooks || useWebchat(props.theme)\n\n const contentsByLocale = props.contentsByLocale\n const firstUpdate = useRef(true)\n const isOnline = () => webchatState.online\n const currentDateString = () => new Date().toISOString()\n const theme = merge(webchatState.theme, props.theme)\n const { initialSession, initialDevSettings, onStateChange } = props\n const getThemeProperty = _getThemeProperty(theme)\n\n const [customComponent, setCustomComponent] = useState(null)\n const storage = props.storage\n const storageKey =\n typeof props.storageKey === 'function'\n ? props.storageKey()\n : props.storageKey\n\n const [botonicState, saveState] = useStorageState(storage, storageKey)\n\n const host = props.host || document.body\n\n const { scrollToBottom } = useScrollToBottom({ host })\n\n const saveWebchatState = (webchatState: WebchatState) => {\n storage &&\n saveState(\n JSON.parse(\n stringifyWithRegexs({\n messages: webchatState.messagesJSON,\n session: webchatState.session,\n lastRoutePath: webchatState.lastRoutePath,\n devSettings: webchatState.devSettings,\n lastMessageUpdate: webchatState.lastMessageUpdate,\n themeUpdates: webchatState.themeUpdates,\n })\n )\n )\n }\n\n const handleAttachment = (event: any) => {\n if (!isAllowedSize(event.target.files[0].size)) {\n throw new Error(\n `The file is too large. A maximum of ${MAX_ALLOWED_SIZE_MB}MB is allowed.`\n )\n }\n\n // TODO: Attach more files?\n setCurrentAttachment(event.target.files[0])\n }\n\n useEffect(() => {\n if (webchatState.currentAttachment) {\n sendAttachment(webchatState.currentAttachment)\n }\n }, [webchatState.currentAttachment])\n\n const sendUserInput = async (input: any) => {\n if (props.onUserInput) {\n resetUnreadMessages()\n scrollToBottom()\n props.onUserInput({\n user: webchatState.session.user,\n // TODO: Review if this input.sentBy exists in the frontend\n input: input,\n //@ts-expect-error\n session: webchatState.session,\n // TODO: Review why we were passing lastRoutePath, is only for devMode?\n lastRoutePath: webchatState.lastRoutePath,\n })\n }\n }\n\n // Load styles stored in window._botonicInsertStyles by Webpack\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: this is a complex useEffect that needs to be refactored, but it's not a problem for now\n useComponentWillMount(() => {\n if (window._botonicInsertStyles?.length) {\n for (const botonicStyle of window._botonicInsertStyles) {\n // Injecting styles at head is needed even if we use shadowDOM\n // as some dependencies like simplebar rely on creating ephemeral elements\n // on document.body and assume styles will be available globally\n document.head.appendChild(botonicStyle)\n\n // injecting styles in host node too so that shadowDOM works\n if (props.shadowDOM) {\n host.appendChild(botonicStyle.cloneNode(true))\n }\n }\n delete window._botonicInsertStyles\n }\n\n if (props.shadowDOM) {\n // emoji-picker-react injects styles in head, so we need to\n // re-inject them in our host node to make it work with shadowDOM\n for (const style of document.querySelectorAll('style')) {\n if (style.textContent?.includes('emoji-picker-react')) {\n host.appendChild(style.cloneNode(true))\n }\n }\n }\n })\n\n // Load initial state from storage\n useEffect(() => {\n let {\n messages,\n session,\n lastRoutePath,\n devSettings,\n lastMessageUpdate,\n themeUpdates,\n } = botonicState || {}\n session = initSession(session)\n updateSession(session)\n if (shouldKeepSessionOnReload({ initialDevSettings, devSettings })) {\n if (messages) {\n messages.forEach(message => {\n addMessage(message)\n const newMessageComponent = msgToBotonic(\n { ...message, delay: 0, typing: 0 },\n props.theme?.message?.customTypes\n )\n if (newMessageComponent) {\n addMessageComponent(newMessageComponent as any)\n }\n })\n }\n if (initialSession) {\n updateSession(merge(initialSession, session))\n }\n if (lastRoutePath) {\n updateLastRoutePath(lastRoutePath)\n }\n } else {\n updateSession(merge(initialSession, session))\n }\n if (devSettings) {\n updateDevSettings(devSettings)\n } else if (initialDevSettings) {\n updateDevSettings(initialDevSettings)\n }\n\n if (lastMessageUpdate) {\n updateLastMessageDate(lastMessageUpdate)\n }\n\n if (themeUpdates !== undefined) {\n updateTheme(merge(props.theme, themeUpdates), themeUpdates)\n }\n\n if (props.onInit) {\n setTimeout(() => {\n if (typeof props.onInit === 'function') {\n props.onInit()\n session.user = updateUserLocaleAndCountry(session.user)\n }\n }, 100)\n }\n }, [])\n\n useEffect(() => {\n if (!webchatState.isWebchatOpen) {\n if (webchatState.isLastMessageVisible) {\n resetUnreadMessages()\n }\n return\n }\n }, [webchatState.isWebchatOpen])\n\n useEffect(() => {\n const { messagesJSON, session } = webchatState\n if (onStateChange && typeof onStateChange === 'function' && session.user) {\n onStateChange({ messagesJSON, user: session.user })\n }\n saveWebchatState(webchatState)\n }, [\n webchatState.messagesJSON,\n webchatState.session,\n webchatState.lastRoutePath,\n webchatState.devSettings,\n webchatState.lastMessageUpdate,\n ])\n\n useEffect(() => {\n if (!webchatState.online) {\n setError({\n message: getServerErrorMessage(props.server),\n })\n } else {\n if (!firstUpdate.current) {\n setError(undefined)\n }\n }\n }, [webchatState.online])\n\n useTyping({ webchatState, updateTyping, updateMessage, host })\n\n useEffect(() => {\n updateTheme(merge(props.theme, theme, webchatState.themeUpdates))\n }, [props.theme, webchatState.themeUpdates])\n\n const openWebview = (\n webviewComponent: Webview,\n params?: Record<string, string>\n ) => {\n updateWebview(webviewComponent, params)\n }\n\n const textareaRef = useRef<HTMLTextAreaElement | undefined>()\n\n const closeWebview = async (options?: CloseWebviewOptions) => {\n removeWebview()\n if (userInputEnabled) {\n textareaRef.current?.focus()\n }\n if (options?.payload) {\n await sendPayload(options.payload)\n } else if (options?.path) {\n const params = options.params ? params2queryString(options.params) : ''\n await sendPayload(`__PATH_PAYLOAD__${options.path}?${params}`)\n }\n }\n\n const persistentMenuOptions = getThemeProperty(\n WEBCHAT.CUSTOM_PROPERTIES.persistentMenu\n )\n\n const darkBackgroundMenu = getThemeProperty(\n WEBCHAT.CUSTOM_PROPERTIES.darkBackgroundMenu\n )\n\n const getBlockInputs = (rule, inputData) => {\n const processedInput = rule.preprocess\n ? rule.preprocess(inputData)\n : inputData\n\n return rule.match.some(regex => {\n if (typeof regex === 'string') {\n regex = deserializeRegex(regex)\n }\n return regex.test(processedInput)\n })\n }\n\n const checkBlockInput = input => {\n // if is a text we check if it is a serialized RE\n const blockInputs = webchatState.theme.userInput?.blockInputs\n if (!Array.isArray(blockInputs)) {\n return false\n }\n for (const rule of blockInputs) {\n if (getBlockInputs(rule, input.data)) {\n addMessageComponent(\n <Text\n // Is necessary to add the id of the input\n // to keep the input.id generated in the frontend as id of the message\n // @ts-expect-error input.id is not typed\n id={input.id}\n sentBy={SENDERS.user}\n blob={false}\n style={{\n backgroundColor: COLORS.SCORPION_GRAY,\n borderColor: COLORS.SCORPION_GRAY,\n padding: '8px 12px',\n }}\n >\n {rule.message}\n </Text>\n )\n removeReplies()\n return true\n }\n }\n return false\n }\n\n const closeMenu = () => {\n togglePersistentMenu(false)\n }\n\n const persistentMenu = () => {\n return (\n <OpenedPersistentMenu\n onClick={closeMenu}\n options={persistentMenuOptions}\n borderRadius={webchatState.theme.style.borderRadius || '10px'}\n />\n )\n }\n\n const coverComponent = webchatState.theme.coverComponent\n const coverComponentProps = webchatState.theme.coverComponent?.props\n\n useEffect(() => {\n if (!coverComponent) {\n return\n }\n if (\n !botonicState ||\n (botonicState.messages && botonicState.messages.length === 0)\n ) {\n toggleCoverComponent(true)\n }\n }, [])\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: messageComponentFromInput is a complex\n const messageComponentFromInput = input => {\n let messageComponent: any = null\n if (isText(input)) {\n messageComponent = (\n <Text\n // Is necessary to add the id of the input\n // to keep the input.id generated in the frontend as id of the message\n // @ts-expect-error input.id is not typed\n id={input.id}\n // Is necessary to add the payload of the input when user clicks a button\n payload={input.payload}\n sentBy={SENDERS.user}\n >\n {input.data}\n </Text>\n )\n } else if (isMedia(input)) {\n const temporaryDisplayUrl = URL.createObjectURL(input.data)\n // TODO: We should use URL.revokeObjectURL(temporaryDisplayUrl) when the component is unmounted\n // https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static#memory_management\n const mediaProps: {\n id: string\n sentBy: SENDERS\n src: string\n input?: any\n } = {\n id: input.id,\n sentBy: SENDERS.user,\n src: temporaryDisplayUrl,\n }\n if (isImage(input)) {\n mediaProps.input = input\n messageComponent = <Image {...mediaProps} />\n } else if (isAudio(input)) {\n messageComponent = <Audio {...mediaProps} />\n } else if (isVideo(input)) {\n messageComponent = <Video {...mediaProps} />\n } else if (isDocument(input)) {\n messageComponent = <Document {...mediaProps} />\n }\n }\n return messageComponent\n }\n\n const sendInput = async (input: any) => {\n if (!input || Object.keys(input).length === 0) {\n return\n }\n if (isText(input) && (!input.data || !input.data.trim())) {\n return // in case trim() doesn't work in a browser we can use !/\\S/.test(input.data)\n }\n if (isText(input) && checkBlockInput(input)) {\n return\n }\n if (!input.id) {\n input.id = uuidv7()\n }\n const messageComponent = messageComponentFromInput(input)\n if (messageComponent) {\n addMessageComponent(messageComponent)\n }\n if (isMedia(input)) {\n input.data = await readDataURL(input.data)\n }\n sendUserInput(input)\n updateLatestInput(input)\n isOnline() && updateLastMessageDate(currentDateString())\n removeReplies()\n togglePersistentMenu(false)\n toggleEmojiPicker(false)\n }\n\n /* This is the public API this component exposes to its parents\n https://stackoverflow.com/questions/37949981/call-child-method-from-parent\n */\n\n const updateSessionWithUser = (userToUpdate: any) => {\n if (contentsByLocale && userToUpdate.system_locale) {\n const placeholder =\n contentsByLocale[userToUpdate.system_locale]?.inputPlaceholder ??\n WEBCHAT_DEFAULT_CONTENTS.INPUT_PLACEHOLDER\n const themeUpdates = { userInput: { box: { placeholder } } }\n updateTheme(\n merge(props.theme, themeUpdates),\n themeUpdates as WebchatTheme\n )\n }\n updateSession(merge(webchatState.session, { user: userToUpdate }))\n }\n\n useImperativeHandle(ref, () => ({\n addBotResponse: ({ response, session, lastRoutePath }) => {\n updateTyping(false)\n\n const isUnread =\n !webchatState.isLastMessageVisible || webchatState.numUnreadMessages > 0\n\n if (Array.isArray(response)) {\n response.forEach(r => {\n addMessageComponent({ ...r, props: { ...r.props, isUnread } })\n })\n } else if (response) {\n addMessageComponent({\n ...response,\n props: { ...response.props, isUnread },\n })\n }\n\n if (session) {\n updateSession(merge(session, { user: webchatState.session.user }))\n const action = session._botonic_action || ''\n const handoff = action.startsWith(BotonicAction.CreateCase)\n if (handoff && isDev) {\n addMessageComponent(<Handoff />)\n }\n updateHandoff(handoff)\n }\n\n if (lastRoutePath) {\n updateLastRoutePath(lastRoutePath)\n }\n\n updateLastMessageDate(currentDateString())\n },\n addSystemResponse: ({ response }) => {\n if (Array.isArray(response)) {\n response.forEach(r => {\n addMessageComponent({ ...r, props: { ...r.props, isUnread: false } })\n })\n } else if (response) {\n addMessageComponent({\n ...response,\n props: { ...response.props, isUnread: false },\n })\n }\n updateLastMessageDate(currentDateString())\n },\n setTyping: (typing: boolean) => updateTyping(typing),\n addUserMessage: message => sendInput(message),\n updateUser: updateSessionWithUser,\n openWebchat: () => toggleWebchat(true),\n closeWebchat: () => toggleWebchat(false),\n toggleWebchat: () => toggleWebchat(!webchatState.isWebchatOpen),\n openCoverComponent: () => toggleCoverComponent(true),\n closeCoverComponent: () => toggleCoverComponent(false),\n renderCustomComponent: _customComponent => {\n setCustomComponent(_customComponent)\n doRenderCustomComponent(true)\n },\n unmountCustomComponent: () => doRenderCustomComponent(false),\n toggleCoverComponent: () =>\n toggleCoverComponent(!webchatState.isCoverComponentOpen),\n setOnline,\n getMessages: () => webchatState.messagesJSON,\n isOnline,\n clearMessages: () => {\n clearMessages()\n removeReplies()\n },\n getLastMessageUpdate: () => webchatState.lastMessageUpdate,\n updateMessageInfo: (msgId: string, messageInfo: any) => {\n const messageToUpdate = webchatState.messagesJSON.filter(\n m => m.id === msgId\n )[0]\n const updatedMsg = merge(messageToUpdate, messageInfo)\n if (updatedMsg.ack === 1) {\n delete updatedMsg.unsentInput\n }\n updateMessage(updatedMsg)\n },\n updateWebchatSettings: (settings: WebchatSettingsProps) => {\n if (settings.user) {\n updateSessionWithUser(settings.user)\n }\n const themeUpdates = normalizeWebchatSettings(settings)\n updateTheme(\n merge(webchatState.theme, themeUpdates),\n themeUpdates as WebchatTheme\n )\n updateTyping(false)\n },\n closeWebview: async (options?: CloseWebviewOptions) =>\n closeWebview(options),\n }))\n\n const resolveCase = () => {\n updateHandoff(false)\n updateSession({ ...webchatState.session, _botonic_action: undefined })\n }\n\n const prevSession = usePrevious(webchatState.session)\n useEffect(() => {\n // Resume conversation after handoff\n if (prevSession?._botonic_action && !webchatState.session._botonic_action) {\n const action = getParsedAction(prevSession._botonic_action)\n if (action?.on_finish) {\n sendPayload(action.on_finish)\n }\n }\n }, [webchatState.session._botonic_action])\n\n const sendText = async (text: string, payload?: string) => {\n if (!text) {\n return\n }\n const input = { type: INPUT.TEXT, data: text, payload }\n await sendInput(input)\n }\n\n const sendPayload = async (payload: string) => {\n if (!payload) {\n return\n }\n const input = { type: INPUT.POSTBACK, payload }\n await sendInput(input)\n }\n\n const sendAttachment = async (attachment: File) => {\n if (attachment) {\n const attachmentType = getMediaType(attachment.type)\n if (!attachmentType) {\n return\n }\n const input = {\n type: attachmentType,\n data: attachment,\n }\n await sendInput(input)\n setCurrentAttachment()\n }\n }\n\n useEffect(() => {\n if (firstUpdate.current) {\n firstUpdate.current = false\n return\n }\n\n if (webchatState.isWebchatOpen && props.onOpen) {\n props.onOpen()\n }\n\n if (!webchatState.isWebchatOpen && props.onClose && !firstUpdate.current) {\n props.onClose()\n toggleEmojiPicker(false)\n togglePersistentMenu(false)\n }\n }, [webchatState.isWebchatOpen])\n\n const isUserInputEnabled = () => {\n const isUserInputEnabled = getThemeProperty(\n WEBCHAT.CUSTOM_PROPERTIES.enableUserInput\n )\n return isUserInputEnabled && !webchatState.isCoverComponentOpen\n }\n\n const userInputEnabled = isUserInputEnabled()\n\n useEffect(() => {\n // Prod mode\n saveWebchatState(webchatState)\n }, [webchatState.themeUpdates])\n\n // Only needed for dev/serve mode\n const updateWebchatDevSettings = settings => {\n useEffect(() => {\n const themeUpdates = normalizeWebchatSettings(settings)\n updateTheme(\n merge(webchatState.theme, themeUpdates),\n themeUpdates as WebchatTheme\n )\n }, [webchatState.messagesJSON])\n }\n\n const DarkenBackground = ({ component }) => {\n return (\n <div>\n {darkBackgroundMenu && (\n <DarkBackgroundMenu\n style={{\n borderRadius: webchatState.theme.style.borderRadius,\n }}\n />\n )}\n {component}\n </div>\n )\n }\n\n const _renderCustomComponent = () => {\n if (!customComponent) {\n return <></>\n } else {\n return customComponent\n }\n }\n\n const WebchatComponent = (\n <WebchatContext.Provider\n value={{\n addMessage,\n getThemeProperty,\n closeWebview,\n openWebview,\n resolveCase,\n resetUnreadMessages,\n setIsInputFocused,\n setLastMessageVisible,\n sendAttachment,\n sendInput,\n sendPayload,\n sendText,\n toggleWebchat,\n toggleEmojiPicker,\n togglePersistentMenu,\n toggleCoverComponent,\n updateCustomMessageProps,\n updateLatestInput,\n updateMessage,\n updateReplies,\n updateUser: updateSessionWithUser,\n updateWebchatDevSettings: updateWebchatDevSettings,\n trackEvent: props.onTrackEvent,\n previewUtils: props.previewUtils,\n webchatState,\n webchatContainerRef,\n chatAreaRef,\n inputPanelRef,\n headerRef,\n repliesRef,\n scrollableMessagesListRef,\n }}\n >\n <ThemeProvider theme={webchatState.theme}>\n {!webchatState.isWebchatOpen && <TriggerButton />}\n\n {webchatState.isWebchatOpen && (\n <StyledWebchat\n id={BotonicContainerId.Webchat}\n ref={webchatContainerRef}\n // TODO: Distinguish between multiple instances of webchat, e.g. `${uniqueId}-botonic-webchat`\n role={ROLES.WEBCHAT}\n >\n <WebchatHeader ref={headerRef} />\n\n {webchatState.isCoverComponentOpen ? (\n <CoverComponent\n component={coverComponent}\n componentProps={coverComponentProps}\n />\n ) : (\n <>\n {webchatState.error.message && (\n <ErrorMessageContainer>\n <ErrorMessage>{webchatState.error.message}</ErrorMessage>\n </ErrorMessageContainer>\n )}\n\n <ChatArea />\n\n {webchatState.isPersistentMenuOpen && (\n <DarkenBackground component={persistentMenu()} />\n )}\n\n {!webchatState.handoff && userInputEnabled && (\n <InputPanel\n handleAttachment={handleAttachment}\n textareaRef={textareaRef}\n host={host}\n onUserInput={props.onUserInput}\n />\n )}\n\n {webchatState.webview && (\n <WebviewContainer localWebviews={props.localWebviews} />\n )}\n\n {webchatState.isCustomComponentRendered &&\n customComponent &&\n _renderCustomComponent()}\n </>\n )}\n </StyledWebchat>\n )}\n </ThemeProvider>\n </WebchatContext.Provider>\n )\n\n return props.shadowDOM ? (\n <StyleSheetManager target={host}>{WebchatComponent}</StyleSheetManager>\n ) : (\n WebchatComponent\n )\n})\n\nWebchat.displayName = 'Webchat'\nexport { Webchat }\n"],"names":["BotonicAction","INPUT","params2queryString","merge","forwardRef","useEffect","useImperativeHandle","useRef","useState","StyleSheetManager","ThemeProvider","v7","uuidv7","Audio","Document","Handoff","Image","normalizeWebchatSettings","Text","Video","COLORS","MAX_ALLOWED_SIZE_MB","ROLES","WEBCHAT","WEBCHAT_DEFAULT_CONTENTS","SENDERS","getMediaType","isAllowedSize","isAudio","isDocument","isImage","isMedia","isText","isVideo","readDataURL","msgToBotonic","isDev","deserializeRegex","stringifyWithRegexs","_getThemeProperty","getServerErrorMessage","initSession","shouldKeepSessionOnReload","updateUserLocaleAndCountry","ChatArea","OpenedPersistentMenu","BotonicContainerId","useWebchat","WebchatContext","CoverComponent","WebchatHeader","useComponentWillMount","usePrevious","useScrollToBottom","useTyping","InputPanel","DarkBackgroundMenu","ErrorMessage","ErrorMessageContainer","StyledWebchat","TriggerButton","useStorageState","getParsedAction","WebviewContainer","Webchat","props","ref","addMessage","addMessageComponent","clearMessages","doRenderCustomComponent","resetUnreadMessages","setCurrentAttachment","setError","setIsInputFocused","setLastMessageVisible","setOnline","toggleCoverComponent","toggleEmojiPicker","togglePersistentMenu","toggleWebchat","updateCustomMessageProps","updateDevSettings","updateHandoff","updateLastMessageDate","updateLastRoutePath","updateLatestInput","updateMessage","updateReplies","updateSession","updateTheme","updateTyping","updateWebview","removeWebview","removeReplies","webchatState","webchatContainerRef","chatAreaRef","inputPanelRef","headerRef","repliesRef","scrollableMessagesListRef","contentsByLocale","firstUpdate","isOnline","currentDateString","Date","theme","initialSession","initialDevSettings","onStateChange","getThemeProperty","customComponent","setCustomComponent","storage","storageKey","botonicState","saveState","host","document","scrollToBottom","saveWebchatState","JSON","handleAttachment","event","Error","sendAttachment","sendUserInput","input","window","botonicStyle","style","messages","session","lastRoutePath","devSettings","lastMessageUpdate","themeUpdates","message","newMessageComponent","undefined","setTimeout","messagesJSON","openWebview","webviewComponent","params","textareaRef","closeWebview","options","userInputEnabled","sendPayload","persistentMenuOptions","darkBackgroundMenu","getBlockInputs","rule","inputData","processedInput","regex","checkBlockInput","blockInputs","Array","closeMenu","persistentMenu","coverComponent","coverComponentProps","messageComponentFromInput","messageComponent","temporaryDisplayUrl","URL","mediaProps","sendInput","Object","updateSessionWithUser","userToUpdate","placeholder","response","isUnread","r","action","handoff","typing","_customComponent","msgId","messageInfo","messageToUpdate","m","updatedMsg","settings","resolveCase","prevSession","sendText","text","payload","attachment","attachmentType","isUserInputEnabled","updateWebchatDevSettings","DarkenBackground","component","_renderCustomComponent","WebchatComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA0D,GACc;AACxC;AAOlB;AACsD;AACjC;AAYb;AAOD;AAEuD;AAWnD;AACuB;AACL;AAC2B;AAO9C;AACc;AACoC;AAC1B;AACyB;AACvB;AACV;AAMxB;AAC0B;AAMzB;AAE+B;AACU;AACjB;AACS;AAElD,MAAMgE,OAAOA,iBAAG5D,UAAUA,CAAkC,CAAC6D,OAAOC;IAClE,MAAM,EACJC,UAAU,EACVC,mBAAmB,EACnBC,aAAa,EACbC,uBAAuB,EACvBC,mBAAmB,EACnBC,oBAAoB,EACpBC,QAAQ,EACRC,iBAAiB,EACjBC,qBAAqB,EACrBC,SAAS,EACTC,oBAAoB,EACpBC,iBAAiB,EACjBC,oBAAoB,EACpBC,aAAa,EACbC,wBAAwB,EACxBC,iBAAiB,EACjBC,aAAa,EACbC,qBAAqB,EACrBC,mBAAmB,EACnBC,iBAAiB,EACjBC,aAAa,EACbC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,YAAY,EACZC,aAAa,EACbC,aAAa,EACbC,aAAa,EACbC,YAAY,EACZC,mBAAmB,EACnBC,WAAW,EACXC,aAAa,EACbC,SAAS,EACTC,UAAU,EACVC,yBAAyB,EAC1B,GAAGpC,MAAM,YAAY,IAAIlB,UAAUA,CAACkB,MAAM,KAAK;IAEhD,MAAMqC,mBAAmBrC,MAAM,gBAAgB;IAC/C,MAAMsC,cAAchG,MAAMA,CAAC;IAC3B,MAAMiG,WAAW,IAAMT,aAAa,MAAM;IAC1C,MAAMU,oBAAoB,IAAM,IAAIC,OAAO,WAAW;IACtD,MAAMC,QAAQxG,YA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AAOA,CAAC,WAAW,GAAG;AACJ"}
1
+ {"version":3,"file":"webchat/webchat.js","sources":["../../src/webchat/webchat.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport { BotonicAction, INPUT, params2queryString } from '@botonic/core'\nimport merge from 'lodash.merge'\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react'\nimport { StyleSheetManager, ThemeProvider } from 'styled-components'\nimport { v7 as uuidv7 } from 'uuid'\n\nimport {\n Audio,\n Document,\n Handoff,\n Image,\n normalizeWebchatSettings,\n Text,\n Video,\n type WebchatSettingsProps,\n type Webview,\n} from '../components'\nimport {\n COLORS,\n MAX_ALLOWED_SIZE_MB,\n ROLES,\n WEBCHAT,\n WEBCHAT_DEFAULT_CONTENTS,\n} from '../constants'\nimport type { CloseWebviewOptions } from '../contexts'\nimport { SENDERS, type WebchatProps, type WebchatRef } from '../index-types'\nimport {\n getMediaType,\n isAllowedSize,\n isAudio,\n isDocument,\n isImage,\n isMedia,\n isText,\n isVideo,\n readDataURL,\n} from '../message-utils'\nimport { msgToBotonic } from '../msg-to-botonic'\nimport { isDev } from '../util/environment'\nimport { deserializeRegex, stringifyWithRegexs } from '../util/regexs'\nimport {\n _getThemeProperty,\n getServerErrorMessage,\n initSession,\n shouldKeepSessionOnReload,\n updateUserLocaleAndCountry,\n} from '../util/webchat'\nimport { ChatArea } from './chat-area'\nimport { OpenedPersistentMenu } from './components/opened-persistent-menu'\nimport { BotonicContainerId } from './constants'\nimport { useWebchat, WebchatContext, type WebchatState } from './context'\nimport { CoverComponent } from './cover-component'\nimport { WebchatHeader } from './header'\nimport {\n useComponentWillMount,\n usePrevious,\n useScrollToBottom,\n useTyping,\n} from './hooks'\nimport { InputPanel } from './input-panel'\nimport {\n DarkBackgroundMenu,\n ErrorMessage,\n ErrorMessageContainer,\n StyledWebchat,\n} from './styles'\nimport type { WebchatTheme } from './theme/types'\nimport { TriggerButton } from './trigger-button'\nimport { useStorageState } from './use-storage-state-hook'\nimport { getParsedAction } from './utils'\nimport { WebviewContainer } from './webview/index'\n\nconst Webchat = forwardRef<WebchatRef | null, WebchatProps>((props, ref) => {\n const {\n addMessage,\n addMessageComponent,\n clearMessages,\n doRenderCustomComponent,\n resetUnreadMessages,\n setCurrentAttachment,\n setError,\n setIsInputFocused,\n setLastMessageVisible,\n setOnline,\n toggleCoverComponent,\n toggleEmojiPicker,\n togglePersistentMenu,\n toggleWebchat,\n updateCustomMessageProps,\n updateDevSettings,\n updateHandoff,\n updateLastMessageDate,\n updateLastRoutePath,\n updateLatestInput,\n updateMessage,\n updateReplies,\n updateSession,\n updateTheme,\n updateTyping,\n updateWebview,\n removeWebview,\n removeReplies,\n webchatState,\n webchatContainerRef,\n chatAreaRef,\n inputPanelRef,\n headerRef,\n repliesRef,\n scrollableMessagesListRef,\n } = props.webchatHooks || useWebchat(props.theme)\n\n const contentsByLocale = props.contentsByLocale\n const firstUpdate = useRef(true)\n const isOnline = () => webchatState.online\n const currentDateString = () => new Date().toISOString()\n const theme = merge(webchatState.theme, props.theme)\n const { initialSession, initialDevSettings, onStateChange } = props\n const getThemeProperty = _getThemeProperty(theme)\n\n const [customComponent, setCustomComponent] = useState(null)\n const storage = props.storage\n const storageKey =\n typeof props.storageKey === 'function'\n ? props.storageKey()\n : props.storageKey\n\n const [botonicState, saveState] = useStorageState(storage, storageKey)\n\n const host = props.host || document.body\n\n const { scrollToBottom } = useScrollToBottom({ host })\n\n const saveWebchatState = (webchatState: WebchatState) => {\n storage &&\n saveState(\n JSON.parse(\n stringifyWithRegexs({\n messages: webchatState.messagesJSON,\n session: webchatState.session,\n lastRoutePath: webchatState.lastRoutePath,\n devSettings: webchatState.devSettings,\n lastMessageUpdate: webchatState.lastMessageUpdate,\n themeUpdates: webchatState.themeUpdates,\n })\n )\n )\n }\n\n const handleAttachment = (event: any) => {\n if (!isAllowedSize(event.target.files[0].size)) {\n throw new Error(\n `The file is too large. A maximum of ${MAX_ALLOWED_SIZE_MB}MB is allowed.`\n )\n }\n\n // TODO: Attach more files?\n setCurrentAttachment(event.target.files[0])\n }\n\n useEffect(() => {\n if (webchatState.currentAttachment) {\n sendAttachment(webchatState.currentAttachment)\n }\n }, [webchatState.currentAttachment])\n\n const sendUserInput = async (input: any) => {\n if (props.onUserInput) {\n resetUnreadMessages()\n scrollToBottom()\n props.onUserInput({\n user: webchatState.session.user,\n // TODO: Review if this input.sentBy exists in the frontend\n input: input,\n //@ts-expect-error\n session: webchatState.session,\n // TODO: Review why we were passing lastRoutePath, is only for devMode?\n lastRoutePath: webchatState.lastRoutePath,\n })\n }\n }\n\n // Load styles stored in window._botonicInsertStyles by Webpack\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: this is a complex useEffect that needs to be refactored, but it's not a problem for now\n useComponentWillMount(() => {\n if (window._botonicInsertStyles?.length) {\n for (const botonicStyle of window._botonicInsertStyles) {\n // Injecting styles at head is needed even if we use shadowDOM\n // as some dependencies like simplebar rely on creating ephemeral elements\n // on document.body and assume styles will be available globally\n document.head.appendChild(botonicStyle)\n\n // injecting styles in host node too so that shadowDOM works\n if (props.shadowDOM) {\n host.appendChild(botonicStyle.cloneNode(true))\n }\n }\n delete window._botonicInsertStyles\n }\n\n if (props.shadowDOM) {\n // emoji-picker-react injects styles in head, so we need to\n // re-inject them in our host node to make it work with shadowDOM\n for (const style of document.querySelectorAll('style')) {\n if (style.textContent?.includes('emoji-picker-react')) {\n host.appendChild(style.cloneNode(true))\n }\n }\n }\n })\n\n // Load initial state from storage\n useEffect(() => {\n let {\n messages,\n session,\n lastRoutePath,\n devSettings,\n lastMessageUpdate,\n themeUpdates,\n } = botonicState || {}\n session = initSession(session)\n updateSession(session)\n if (shouldKeepSessionOnReload({ initialDevSettings, devSettings })) {\n if (messages) {\n messages.forEach(message => {\n addMessage(message)\n const newMessageComponent = msgToBotonic(\n { ...message, delay: 0, typing: 0 },\n props.theme?.message?.customTypes\n )\n if (newMessageComponent) {\n addMessageComponent(newMessageComponent as any)\n }\n })\n }\n if (initialSession) {\n updateSession(merge(initialSession, session))\n }\n if (lastRoutePath) {\n updateLastRoutePath(lastRoutePath)\n }\n } else {\n updateSession(merge(initialSession, session))\n }\n if (devSettings) {\n updateDevSettings(devSettings)\n } else if (initialDevSettings) {\n updateDevSettings(initialDevSettings)\n }\n\n if (lastMessageUpdate) {\n updateLastMessageDate(lastMessageUpdate)\n }\n\n if (themeUpdates !== undefined) {\n updateTheme(merge(props.theme, themeUpdates), themeUpdates)\n }\n\n if (props.onInit) {\n setTimeout(() => {\n if (typeof props.onInit === 'function') {\n props.onInit()\n session.user = updateUserLocaleAndCountry(session.user)\n }\n }, 100)\n }\n }, [])\n\n useEffect(() => {\n if (!webchatState.isWebchatOpen) {\n if (webchatState.isLastMessageVisible) {\n resetUnreadMessages()\n }\n return\n }\n }, [webchatState.isWebchatOpen])\n\n useEffect(() => {\n const { messagesJSON, session } = webchatState\n if (onStateChange && typeof onStateChange === 'function' && session.user) {\n onStateChange({ messagesJSON, user: session.user })\n }\n saveWebchatState(webchatState)\n }, [\n webchatState.messagesJSON,\n webchatState.session,\n webchatState.lastRoutePath,\n webchatState.devSettings,\n webchatState.lastMessageUpdate,\n ])\n\n useEffect(() => {\n if (!webchatState.online) {\n setError({\n message: getServerErrorMessage(props.server),\n })\n } else {\n if (!firstUpdate.current) {\n setError(undefined)\n }\n }\n }, [webchatState.online])\n\n useTyping({ webchatState, updateTyping, updateMessage, host })\n\n useEffect(() => {\n updateTheme(merge(props.theme, theme, webchatState.themeUpdates))\n }, [props.theme, webchatState.themeUpdates])\n\n const openWebview = (\n webviewComponent: Webview,\n params?: Record<string, string>\n ) => {\n updateWebview(webviewComponent, params)\n }\n\n const textareaRef = useRef<HTMLTextAreaElement | undefined>()\n\n const closeWebview = async (options?: CloseWebviewOptions) => {\n removeWebview()\n if (userInputEnabled) {\n textareaRef.current?.focus()\n }\n if (options?.payload) {\n await sendPayload(options.payload)\n } else if (options?.path) {\n const params = options.params ? params2queryString(options.params) : ''\n await sendPayload(`__PATH_PAYLOAD__${options.path}?${params}`)\n }\n }\n\n const persistentMenuOptions = getThemeProperty(\n WEBCHAT.CUSTOM_PROPERTIES.persistentMenu\n )\n\n const darkBackgroundMenu = getThemeProperty(\n WEBCHAT.CUSTOM_PROPERTIES.darkBackgroundMenu\n )\n\n const getBlockInputs = (rule, inputData) => {\n const processedInput = rule.preprocess\n ? rule.preprocess(inputData)\n : inputData\n\n return rule.match.some(regex => {\n if (typeof regex === 'string') {\n regex = deserializeRegex(regex)\n }\n return regex.test(processedInput)\n })\n }\n\n const checkBlockInput = input => {\n // if is a text we check if it is a serialized RE\n const blockInputs = webchatState.theme.userInput?.blockInputs\n if (!Array.isArray(blockInputs)) {\n return false\n }\n for (const rule of blockInputs) {\n if (getBlockInputs(rule, input.data)) {\n addMessageComponent(\n <Text\n // Is necessary to add the id of the input\n // to keep the input.id generated in the frontend as id of the message\n // @ts-expect-error input.id is not typed\n id={input.id}\n sentBy={SENDERS.user}\n blob={false}\n style={{\n backgroundColor: COLORS.SCORPION_GRAY,\n borderColor: COLORS.SCORPION_GRAY,\n padding: '8px 12px',\n }}\n >\n {rule.message}\n </Text>\n )\n removeReplies()\n return true\n }\n }\n return false\n }\n\n const closeMenu = () => {\n togglePersistentMenu(false)\n }\n\n const persistentMenu = () => {\n return (\n <OpenedPersistentMenu\n onClick={closeMenu}\n options={persistentMenuOptions}\n borderRadius={webchatState.theme.style.borderRadius || '10px'}\n />\n )\n }\n\n const coverComponent = webchatState.theme.coverComponent\n const coverComponentProps = webchatState.theme.coverComponent?.props\n\n useEffect(() => {\n if (!coverComponent) {\n return\n }\n if (\n !botonicState ||\n (botonicState.messages && botonicState.messages.length === 0)\n ) {\n toggleCoverComponent(true)\n }\n }, [])\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: messageComponentFromInput is a complex\n const messageComponentFromInput = input => {\n let messageComponent: any = null\n if (isText(input)) {\n messageComponent = (\n <Text\n // Is necessary to add the id of the input\n // to keep the input.id generated in the frontend as id of the message\n // @ts-expect-error input.id is not typed\n id={input.id}\n // Is necessary to add the payload of the input when user clicks a button\n payload={input.payload}\n sentBy={SENDERS.user}\n >\n {input.data}\n </Text>\n )\n } else if (isMedia(input)) {\n const temporaryDisplayUrl = URL.createObjectURL(input.data)\n // TODO: We should use URL.revokeObjectURL(temporaryDisplayUrl) when the component is unmounted\n // https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static#memory_management\n const mediaProps: {\n id: string\n sentBy: SENDERS\n src: string\n input?: any\n } = {\n id: input.id,\n sentBy: SENDERS.user,\n src: temporaryDisplayUrl,\n }\n if (isImage(input)) {\n mediaProps.input = input\n messageComponent = <Image {...mediaProps} />\n } else if (isAudio(input)) {\n messageComponent = <Audio {...mediaProps} />\n } else if (isVideo(input)) {\n messageComponent = <Video {...mediaProps} />\n } else if (isDocument(input)) {\n messageComponent = <Document {...mediaProps} />\n }\n }\n return messageComponent\n }\n\n const sendInput = async (input: any) => {\n if (!input || Object.keys(input).length === 0) {\n return\n }\n if (isText(input) && (!input.data || !input.data.trim())) {\n return // in case trim() doesn't work in a browser we can use !/\\S/.test(input.data)\n }\n if (isText(input) && checkBlockInput(input)) {\n return\n }\n if (!input.id) {\n input.id = uuidv7()\n }\n const messageComponent = messageComponentFromInput(input)\n if (messageComponent) {\n addMessageComponent(messageComponent)\n }\n if (isMedia(input)) {\n input.data = await readDataURL(input.data)\n }\n sendUserInput(input)\n updateLatestInput(input)\n isOnline() && updateLastMessageDate(currentDateString())\n removeReplies()\n togglePersistentMenu(false)\n toggleEmojiPicker(false)\n }\n\n /* This is the public API this component exposes to its parents\n https://stackoverflow.com/questions/37949981/call-child-method-from-parent\n */\n\n const updateSessionWithUser = (userToUpdate: any) => {\n if (contentsByLocale && userToUpdate.system_locale) {\n const placeholder =\n contentsByLocale[userToUpdate.system_locale]?.inputPlaceholder ??\n WEBCHAT_DEFAULT_CONTENTS.INPUT_PLACEHOLDER\n const themeUpdates = { userInput: { box: { placeholder } } }\n updateTheme(\n merge(props.theme, themeUpdates),\n themeUpdates as WebchatTheme\n )\n }\n updateSession(merge(webchatState.session, { user: userToUpdate }))\n }\n\n useImperativeHandle(ref, () => ({\n addBotResponse: ({ response, session, lastRoutePath }) => {\n updateTyping(false)\n\n const isUnread =\n !webchatState.isLastMessageVisible || webchatState.numUnreadMessages > 0\n\n if (Array.isArray(response)) {\n response.forEach(r => {\n addMessageComponent({ ...r, props: { ...r.props, isUnread } })\n })\n } else if (response) {\n addMessageComponent({\n ...response,\n props: { ...response.props, isUnread },\n })\n }\n\n if (session) {\n updateSession(merge(session, { user: webchatState.session.user }))\n const action = session._botonic_action || ''\n const handoff = action.startsWith(BotonicAction.CreateCase)\n if (handoff && isDev) {\n addMessageComponent(<Handoff />)\n }\n updateHandoff(handoff)\n }\n\n if (lastRoutePath) {\n updateLastRoutePath(lastRoutePath)\n }\n\n updateLastMessageDate(currentDateString())\n },\n addSystemResponse: ({ response }) => {\n if (Array.isArray(response)) {\n response.forEach(r => {\n addMessageComponent({ ...r, props: { ...r.props, isUnread: false } })\n })\n } else if (response) {\n addMessageComponent({\n ...response,\n props: { ...response.props, isUnread: false },\n })\n }\n updateLastMessageDate(currentDateString())\n },\n setTyping: (typing: boolean) => updateTyping(typing),\n addUserMessage: message => sendInput(message),\n updateUser: updateSessionWithUser,\n openWebchat: () => toggleWebchat(true),\n closeWebchat: () => toggleWebchat(false),\n toggleWebchat: () => toggleWebchat(!webchatState.isWebchatOpen),\n openCoverComponent: () => toggleCoverComponent(true),\n closeCoverComponent: () => toggleCoverComponent(false),\n renderCustomComponent: _customComponent => {\n setCustomComponent(_customComponent)\n doRenderCustomComponent(true)\n },\n unmountCustomComponent: () => doRenderCustomComponent(false),\n toggleCoverComponent: () =>\n toggleCoverComponent(!webchatState.isCoverComponentOpen),\n setOnline,\n getMessages: () => webchatState.messagesJSON,\n isOnline,\n clearMessages: () => {\n clearMessages()\n removeReplies()\n },\n getLastMessageUpdate: () => webchatState.lastMessageUpdate,\n updateMessageInfo: (msgId: string, messageInfo: any) => {\n const messageToUpdate = webchatState.messagesJSON.filter(\n m => m.id === msgId\n )[0]\n const updatedMsg = merge(messageToUpdate, messageInfo)\n if (updatedMsg.ack === 1) {\n delete updatedMsg.unsentInput\n }\n updateMessage(updatedMsg)\n },\n updateWebchatSettings: (settings: WebchatSettingsProps) => {\n if (settings.user) {\n updateSessionWithUser(settings.user)\n }\n const themeUpdates = normalizeWebchatSettings(settings)\n updateTheme(\n merge(webchatState.theme, themeUpdates),\n themeUpdates as WebchatTheme\n )\n updateTyping(false)\n },\n closeWebview: async (options?: CloseWebviewOptions) =>\n closeWebview(options),\n }))\n\n const resolveCase = () => {\n updateHandoff(false)\n updateSession({ ...webchatState.session, _botonic_action: undefined })\n }\n\n const prevSession = usePrevious(webchatState.session)\n useEffect(() => {\n // Resume conversation after handoff\n if (prevSession?._botonic_action && !webchatState.session._botonic_action) {\n const action = getParsedAction(prevSession._botonic_action)\n if (action?.on_finish) {\n sendPayload(action.on_finish)\n }\n }\n }, [webchatState.session._botonic_action])\n\n const sendText = async (text: string, payload?: string) => {\n if (!text) {\n return\n }\n const input = { type: INPUT.TEXT, data: text, payload }\n await sendInput(input)\n }\n\n const sendPayload = async (payload: string) => {\n if (!payload) {\n return\n }\n const input = { type: INPUT.POSTBACK, payload }\n await sendInput(input)\n }\n\n const sendAttachment = async (attachment: File) => {\n if (attachment) {\n const attachmentType = getMediaType(attachment.type)\n if (!attachmentType) {\n return\n }\n const input = {\n type: attachmentType,\n data: attachment,\n }\n await sendInput(input)\n setCurrentAttachment()\n }\n }\n\n useEffect(() => {\n if (firstUpdate.current) {\n firstUpdate.current = false\n return\n }\n\n if (webchatState.isWebchatOpen && props.onOpen) {\n props.onOpen()\n }\n\n if (!webchatState.isWebchatOpen && props.onClose && !firstUpdate.current) {\n props.onClose()\n toggleEmojiPicker(false)\n togglePersistentMenu(false)\n }\n }, [webchatState.isWebchatOpen])\n\n const isUserInputEnabled = () => {\n const isUserInputEnabled = getThemeProperty(\n WEBCHAT.CUSTOM_PROPERTIES.enableUserInput\n )\n return isUserInputEnabled && !webchatState.isCoverComponentOpen\n }\n\n const userInputEnabled = isUserInputEnabled()\n\n useEffect(() => {\n // Prod mode\n saveWebchatState(webchatState)\n }, [webchatState.themeUpdates])\n\n // Only needed for dev/serve mode\n const updateWebchatDevSettings = settings => {\n useEffect(() => {\n const themeUpdates = normalizeWebchatSettings(settings)\n updateTheme(\n merge(webchatState.theme, themeUpdates),\n themeUpdates as WebchatTheme\n )\n }, [webchatState.messagesJSON])\n }\n\n const DarkenBackground = ({ component }) => {\n return (\n <div>\n {darkBackgroundMenu && (\n <DarkBackgroundMenu\n style={{\n borderRadius: webchatState.theme.style.borderRadius,\n }}\n />\n )}\n {component}\n </div>\n )\n }\n\n const _renderCustomComponent = () => {\n if (!customComponent) {\n return <></>\n } else {\n return customComponent\n }\n }\n\n const WebchatComponent = (\n <WebchatContext.Provider\n value={{\n addMessage,\n getThemeProperty,\n closeWebview,\n openWebview,\n resolveCase,\n resetUnreadMessages,\n setIsInputFocused,\n setLastMessageVisible,\n sendAttachment,\n sendInput,\n sendPayload,\n sendText,\n toggleWebchat,\n toggleEmojiPicker,\n togglePersistentMenu,\n toggleCoverComponent,\n updateCustomMessageProps,\n updateLatestInput,\n updateMessage,\n updateReplies,\n updateUser: updateSessionWithUser,\n updateWebchatDevSettings: updateWebchatDevSettings,\n trackEvent: props.onTrackEvent,\n previewUtils: props.previewUtils,\n webchatState,\n webchatContainerRef,\n chatAreaRef,\n inputPanelRef,\n headerRef,\n repliesRef,\n scrollableMessagesListRef,\n }}\n >\n <ThemeProvider theme={webchatState.theme}>\n {!webchatState.isWebchatOpen && <TriggerButton />}\n\n {webchatState.isWebchatOpen && (\n <StyledWebchat\n id={BotonicContainerId.Webchat}\n ref={webchatContainerRef}\n // TODO: Distinguish between multiple instances of webchat, e.g. `${uniqueId}-botonic-webchat`\n role={ROLES.WEBCHAT}\n >\n <WebchatHeader ref={headerRef} />\n\n {webchatState.isCoverComponentOpen ? (\n <CoverComponent\n component={coverComponent}\n componentProps={coverComponentProps}\n />\n ) : (\n <>\n {webchatState.error.message && (\n <ErrorMessageContainer>\n <ErrorMessage>{webchatState.error.message}</ErrorMessage>\n </ErrorMessageContainer>\n )}\n\n <ChatArea />\n\n {webchatState.isPersistentMenuOpen && (\n <DarkenBackground component={persistentMenu()} />\n )}\n\n {!webchatState.handoff && userInputEnabled && (\n <InputPanel\n handleAttachment={handleAttachment}\n textareaRef={textareaRef}\n host={host}\n onUserInput={props.onUserInput}\n />\n )}\n\n {webchatState.webview && (\n <WebviewContainer localWebviews={props.localWebviews} />\n )}\n\n {webchatState.isCustomComponentRendered &&\n customComponent &&\n _renderCustomComponent()}\n </>\n )}\n </StyledWebchat>\n )}\n </ThemeProvider>\n </WebchatContext.Provider>\n )\n\n return props.shadowDOM ? (\n <StyleSheetManager target={host}>{WebchatComponent}</StyleSheetManager>\n ) : (\n WebchatComponent\n )\n})\n\nWebchat.displayName = 'Webchat'\n\nexport { Webchat }\n"],"names":["BotonicAction","INPUT","params2queryString","merge","forwardRef","useEffect","useImperativeHandle","useRef","useState","StyleSheetManager","ThemeProvider","v7","uuidv7","Audio","Document","Handoff","Image","normalizeWebchatSettings","Text","Video","COLORS","MAX_ALLOWED_SIZE_MB","ROLES","WEBCHAT","WEBCHAT_DEFAULT_CONTENTS","SENDERS","getMediaType","isAllowedSize","isAudio","isDocument","isImage","isMedia","isText","isVideo","readDataURL","msgToBotonic","isDev","deserializeRegex","stringifyWithRegexs","_getThemeProperty","getServerErrorMessage","initSession","shouldKeepSessionOnReload","updateUserLocaleAndCountry","ChatArea","OpenedPersistentMenu","BotonicContainerId","useWebchat","WebchatContext","CoverComponent","WebchatHeader","useComponentWillMount","usePrevious","useScrollToBottom","useTyping","InputPanel","DarkBackgroundMenu","ErrorMessage","ErrorMessageContainer","StyledWebchat","TriggerButton","useStorageState","getParsedAction","WebviewContainer","Webchat","props","ref","addMessage","addMessageComponent","clearMessages","doRenderCustomComponent","resetUnreadMessages","setCurrentAttachment","setError","setIsInputFocused","setLastMessageVisible","setOnline","toggleCoverComponent","toggleEmojiPicker","togglePersistentMenu","toggleWebchat","updateCustomMessageProps","updateDevSettings","updateHandoff","updateLastMessageDate","updateLastRoutePath","updateLatestInput","updateMessage","updateReplies","updateSession","updateTheme","updateTyping","updateWebview","removeWebview","removeReplies","webchatState","webchatContainerRef","chatAreaRef","inputPanelRef","headerRef","repliesRef","scrollableMessagesListRef","contentsByLocale","firstUpdate","isOnline","currentDateString","Date","theme","initialSession","initialDevSettings","onStateChange","getThemeProperty","customComponent","setCustomComponent","storage","storageKey","botonicState","saveState","host","document","scrollToBottom","saveWebchatState","JSON","handleAttachment","event","Error","sendAttachment","sendUserInput","input","window","botonicStyle","style","messages","session","lastRoutePath","devSettings","lastMessageUpdate","themeUpdates","message","newMessageComponent","undefined","setTimeout","messagesJSON","openWebview","webviewComponent","params","textareaRef","closeWebview","options","userInputEnabled","sendPayload","persistentMenuOptions","darkBackgroundMenu","getBlockInputs","rule","inputData","processedInput","regex","checkBlockInput","blockInputs","Array","closeMenu","persistentMenu","coverComponent","coverComponentProps","messageComponentFromInput","messageComponent","temporaryDisplayUrl","URL","mediaProps","sendInput","Object","updateSessionWithUser","userToUpdate","placeholder","response","isUnread","r","action","handoff","typing","_customComponent","msgId","messageInfo","messageToUpdate","m","updatedMsg","settings","resolveCase","prevSession","sendText","text","payload","attachment","attachmentType","isUserInputEnabled","updateWebchatDevSettings","DarkenBackground","component","_renderCustomComponent","WebchatComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA0D,GACc;AACxC;AAOlB;AACsD;AACjC;AAYb;AAOD;AAEuD;AAWnD;AACuB;AACL;AAC2B;AAO9C;AACc;AACoC;AAC1B;AACyB;AACvB;AACV;AAMxB;AAC0B;AAMzB;AAE+B;AACU;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,IAACnC,aAAaA;gBAE7CmC,aAAa,aAAa,kBACzB,KAACpC,aAAaA;oBACZ,IAAIb,0BAA0B;oBAC9B,KAAKkD;oBACL,8FAA8F;oBAC9F,MAAM1E,aAAa;;sCAEnB,IAAC4B,aAAaA;4BAAC,KAAKiD;;wBAEnBJ,aAAa,oBAAoB,iBAChC,IAAC9C,cAAcA;4BACb,WAAWkH;4BACX,gBAAgBC;2CAGlB;;gCACGrE,aAAa,KAAK,CAAC,OAAO,kBACzB,IAACrC,qBAAqBA;8CACpB,kBAACD,YAAYA;kDAAEsC,aAAa,KAAK,CAAC,OAAO;;;8CAI7C,IAACnD,QAAQA;gCAERmD,aAAa,oBAAoB,kBAChC,IAACsG;oCAAiB,WAAWnC;;gCAG9B,CAACnE,aAAa,OAAO,IAAIsD,kCACxB,IAAC9F,UAAUA;oCACT,kBAAkBoE;oCAClB,aAAauB;oCACb,MAAM5B;oCACN,aAAarD,MAAM,WAAW;;gCAIjC8B,aAAa,OAAO,kBACnB,IAAChC,gBAAgBA;oCAAC,eAAeE,MAAM,aAAa;;gCAGrD8B,aAAa,yBAAyB,IACrCiB,mBACAuF;;;;;;;;IAShB,OAAOtI,MAAM,SAAS,iBACpB,IAACxD,iBAAiBA;QAAC,QAAQ6G;kBAAOkF;SAElCA;AAEJ;AAEAxI,OAAOA,CAAC,WAAW,GAAG;AAEJ"}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@botonic/react",
4
- "version": "0.57.0-rslib-esm.1",
4
+ "version": "0.57.0-rslib-esm.2",
5
5
  "license": "MIT",
6
6
  "description": "Build Chatbots using React",
7
7
  "main": "./lib/index.js",
8
8
  "module": "./lib/index.js",
9
9
  "types": "./lib/index.d.ts",
10
10
  "scripts": {
11
- "test:no-coverage": "../../node_modules/.bin/jest -c ./jest.config.cjs",
12
- "test": "../../node_modules/.bin/jest -c ./jest.config.cjs --coverage",
13
- "updateSnapshot": "../../node_modules/.bin/jest -c ./jest.config.cjs --updateSnapshot",
11
+ "test:no-coverage": "vitest run",
12
+ "test": "vitest run --coverage",
13
+ "updateSnapshot": "vitest run --update",
14
14
  "cloc": "../../scripts/qa/cloc-package.sh .",
15
15
  "prepublishOnly": "npm run build && npm run test && npm run lint",
16
16
  "build": "rslib build --no-env",
@@ -20,7 +20,7 @@
20
20
  "format": "biome format --write src/ tests/"
21
21
  },
22
22
  "dependencies": {
23
- "@botonic/core": "0.57.0-rslib-esm.1",
23
+ "@botonic/core": "0.57.0-rslib-esm.2",
24
24
  "axios": "^1.18.1",
25
25
  "emoji-picker-react": "^4.12.0",
26
26
  "lodash.merge": "^4.6.2",
@@ -35,12 +35,9 @@
35
35
  "uuid": "^10.0.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@babel/plugin-transform-runtime": "^7.25.9",
39
- "@babel/preset-react": "^7.26.3",
40
38
  "@testing-library/jest-dom": "^6.6.3",
41
39
  "@testing-library/react": "^16.0.1",
42
40
  "@testing-library/user-event": "^14.6.1",
43
- "@types/jest": "^29.5.14",
44
41
  "@types/lodash.merge": "^4.6.9",
45
42
  "@types/parse5": "^7.0.0",
46
43
  "@types/react": "^18.3.18",
@@ -48,7 +45,6 @@
48
45
  "@types/styled-components": "^5.1.34",
49
46
  "@types/ua-parser-js": "^0.7.39",
50
47
  "@types/uuid": "^10.0.0",
51
- "babel-plugin-add-module-exports": "^1.0.4",
52
48
  "identity-obj-proxy": "^3.0.0",
53
49
  "intersection-observer": "^0.12.2",
54
50
  "react-test-renderer": "^18.3.1"
@@ -87,6 +87,7 @@ export const WebchatMessageList = () => {
87
87
  })
88
88
  })
89
89
  observer.observe(lastMessageRef.current)
90
+ return () => observer.disconnect()
90
91
  }
91
92
  }, [webchatState.messagesComponents])
92
93