UNPKG

@botonic/react

Version:

Build Chatbots using React

74 lines 2.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeWebchatSettings = exports.WebchatSettings = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const core_1 = require("@botonic/core"); const react_1 = require("react"); const react_2 = require("../util/react"); const regexs_1 = require("../util/regexs"); const context_1 = require("../webchat/context"); const WebchatSettings = ({ theme, blockInputs, persistentMenu, enableEmojiPicker, enableAttachments, enableUserInput, enableAnimations, user, }) => { const renderBrowser = () => { // eslint-disable-next-line react-hooks/rules-of-hooks const { updateWebchatDevSettings } = (0, react_1.useContext)(context_1.WebchatContext); updateWebchatDevSettings({ theme, blockInputs, persistentMenu, enableEmojiPicker, enableAttachments, enableUserInput, enableAnimations, }); return null; }; const renderNode = () => { const updatedTheme = (0, exports.normalizeWebchatSettings)({ theme, blockInputs, persistentMenu, enableEmojiPicker, enableAttachments, enableUserInput, enableAnimations, }); return ( //@ts-ignore (0, jsx_runtime_1.jsx)("message", { type: core_1.INPUT.WEBCHAT_SETTINGS, settings: (0, regexs_1.stringifyWithRegexs)({ theme: updatedTheme, user }) })); }; return (0, react_2.renderComponent)({ renderBrowser, renderNode }); }; exports.WebchatSettings = WebchatSettings; const normalizeWebchatSettings = (settings) => { let { theme, blockInputs, persistentMenu, enableEmojiPicker, enableAttachments, enableUserInput, enableAnimations, } = settings; if (!theme) theme = {}; if (!theme.userInput) theme.userInput = {}; if (persistentMenu !== undefined) { theme.userInput.persistentMenu = persistentMenu; } if (enableEmojiPicker !== undefined) { if (!theme.userInput.emojiPicker) theme.userInput.emojiPicker = {}; theme.userInput.emojiPicker.enable = enableEmojiPicker; } if (enableAttachments !== undefined) { if (!theme.userInput.attachments) theme.userInput.attachments = {}; theme.userInput.attachments.enable = enableAttachments; } if (enableUserInput !== undefined) { theme.userInput.enable = enableUserInput; } if (blockInputs !== undefined) theme.userInput.blockInputs = blockInputs; if (!theme.animations) theme.animations = {}; if (enableAnimations !== undefined) { theme.animations.enable = enableAnimations; } return theme; }; exports.normalizeWebchatSettings = normalizeWebchatSettings; //# sourceMappingURL=webchat-settings.js.map