diff --git a/dist/react-simple-chatbot.js b/dist/react-simple-chatbot.js index 97df0537..b286762c 100644 --- a/dist/react-simple-chatbot.js +++ b/dist/react-simple-chatbot.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("styled-components")):"function"==typeof define&&define.amd?define(["styled-components"],t):"object"==typeof exports?exports.ReactSimpleChatbot=t(require("styled-components")):e.ReactSimpleChatbot=t(e["styled-components"])}("undefined"!=typeof self?self:this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(t){return e[t]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="dist/",t(t.s=14)}([function(e,t,n){e.exports=n(10)()},function(e,t,n){"use strict";e.exports=n(5)},function(t,n){t.exports=e},function(e,t){function n(e,t,o){return t instanceof Array?function(e,t,r){for(var o=0,i=t.length;oR.length&&R.push(e)}function p(e,t,n,o){var i=typeof e;"undefined"!==i&&"boolean"!==i||(e=null);var a=!1;if(null===e)a=!0;else switch(i){case"string":case"number":a=!0;break;case"object":switch(e.$$typeof){case j:case M:a=!0}}if(a)return n(o,e,""===t?"."+f(e,0):t),1;if(a=0,t=""===t?".":t+":",Array.isArray(e))for(var u=0;u1&&void 0!==arguments[1]?arguments[1]:1,n=function(e){e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(e,t,n,r){return t+t+n+n+r+r});var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null}(e);return"rgba(".concat(n.r,", ").concat(n.g,", ").concat(n.b,", ").concat(t,")")},pe=Object(se.keyframes)(a()),fe=Object(se.keyframes)(i()),de=Object(se.keyframes)(o()),ye=ce.a.span(s(),pe,function(e){return e.delay}),ge=function(){return re.a.createElement("span",{className:"rsc-loading"},re.a.createElement(ye,{delay:"0s"},"."),re.a.createElement(ye,{delay:".2s"},"."),re.a.createElement(ye,{delay:".4s"},"."))},be=ce.a.div(c()),he=function(e){function t(){var e,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,o=new Array(r),i=0;i0&&void 0!==arguments[0]?arguments[0]:it,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:it,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:it,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"en";return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),ot||(ot=this),this.state={inputValue:"",lang:o,onChange:t,onEnd:n,onStop:r},this.onResult=this.onResult.bind(this),this.onEnd=this.onEnd.bind(this),this.setup(),ot}return H(e,null,[{key:"isSupported",value:function(){return"webkitSpeechRecognition"in window}}]),H(e,[{key:"onChange",value:function(e){var t=this.state.onChange;this.setState({inputValue:e}),t(e)}},{key:"onFinal",value:function(e){this.setState({inputValue:e}),this.recognition.stop()}},{key:"onEnd",value:function(){var e=this.state,t=e.onStop,n=e.onEnd,r=e.force;this.setState({speaking:!1}),r?t():n()}},{key:"onResult",value:function(e){for(var t="",n="",r=e.resultIndex;r0?t.length-1:0,o=n.generateRenderedStepsById(),i=t[r].value;return"function"==typeof e?e({previousValue:i,steps:o}):e}),te(ee(ee(n)),"generateRenderedStepsById",function(){for(var e=n.state.previousSteps,t={},r=0,o=e.length;r0}),te(ee(ee(n)),"isLastPosition",function(e){var t=n.state.renderedSteps,r=t.length,o=t.map(function(e){return e.key}).indexOf(e.key);if(r<=1||o+1===r)return!0;var i=t[o+1];return!i.message&&!i.asMessage||e.user!==i.user}),te(ee(ee(n)),"isFirstPosition",function(e){var t=n.state.renderedSteps,r=t.map(function(e){return e.key}).indexOf(e.key);if(0===r)return!0;var o=t[r-1];return!o.message&&!o.asMessage||e.user!==o.user}),te(ee(ee(n)),"handleKeyPress",function(e){"Enter"===e.key&&n.submitUserMessage()}),te(ee(ee(n)),"handleSubmitButton",function(){var e=n.state,t=e.speaking,r=e.recognitionEnable;if((n.isInputValueEmpty()||t)&&r)return n.recognition.speak(),void(t||n.setState({speaking:!0}));n.submitUserMessage()}),te(ee(ee(n)),"submitUserMessage",function(){var e=n.state,t=e.defaultUserSettings,r=e.inputValue,o=e.previousSteps,i=e.renderedSteps,a=n.state.currentStep;if(!a.validator||!n.checkInvalidInput()){var u={message:r,value:r};a=Object.assign({},t,a,u),i.push(a),o.push(a),n.setState({currentStep:a,renderedSteps:i,previousSteps:o,disabled:!0,inputValue:""},function(){n.input&&n.input.blur()})}}),te(ee(ee(n)),"checkInvalidInput",function(){var e=n.props.enableMobileAutoFocus,t=n.state,r=t.currentStep,o=t.inputValue,i=r.validator(o),a=o;return!("boolean"==typeof i&&i||(n.setState({inputValue:i.toString(),inputInvalid:!0,disabled:!0},function(){setTimeout(function(){n.setState({inputValue:a,inputInvalid:!1,disabled:!1},function(){!e&&dt()||n.input&&n.input.focus()})},2e3)}),0))}),te(ee(ee(n)),"toggleChatBot",function(e){var t=n.props.toggleFloating;t?t({opened:e}):n.setState({opened:e})}),te(ee(ee(n)),"renderStep",function(e,t){var r=n.state.renderedSteps,o=n.props,i=o.avatarStyle,a=o.bubbleStyle,u=o.bubbleOptionStyle,s=o.customStyle,c=o.hideBotAvatar,l=o.hideUserAvatar,p=o.speechSynthesis,f=e.options,d=e.component,y=e.asMessage,g=n.generateRenderedStepsById(),b=t>0?r[t-1]:{};return d&&!y?re.a.createElement(ve,{key:t,speak:n.speak,step:e,steps:g,style:s,previousStep:b,previousValue:b.value,triggerNextStep:n.triggerNextStep}):f?re.a.createElement(Ie,{key:t,step:e,speak:n.speak,previousValue:b.value,triggerNextStep:n.triggerNextStep,bubbleOptionStyle:u}):re.a.createElement(Ce,{key:t,step:e,steps:g,speak:n.speak,previousStep:b,previousValue:b.value,triggerNextStep:n.triggerNextStep,avatarStyle:i,bubbleStyle:a,hideBotAvatar:c,hideUserAvatar:l,speechSynthesis:p,isFirst:n.isFirstPosition(e),isLast:n.isLastPosition(e)})}),n.state={renderedSteps:[],previousSteps:[],currentStep:{},previousStep:{},steps:{},disabled:!0,opened:e.opened||!e.floating,inputValue:"",inputInvalid:!1,speaking:!1,recognitionEnable:e.recognitionEnable&&at.isSupported(),defaultUserSettings:{}},n.speak=gt(e.speechSynthesis),n}return $(t,ne.Component),function(e,t,n){t&&X(e.prototype,t),n&&X(e,n)}(t,[{key:"componentWillMount",value:function(){for(var e=this,t=this.props.steps,n=this.props,r=n.botDelay,o=n.botAvatar,i=n.cache,a=n.cacheName,u=n.customDelay,s=n.enableMobileAutoFocus,c=n.userAvatar,l={},p={delay:r,avatar:o},f={delay:n.userDelay,avatar:c,hideInput:!1},d={delay:u},y=0,g=t.length;y1&&void 0!==arguments[1]?arguments[1]:1,n=function(e){e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(e,t,n,r){return t+t+n+n+r+r});var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null}(e);return"rgba(".concat(n.r,", ").concat(n.g,", ").concat(n.b,", ").concat(t,")")},be=Object(fe.keyframes)(a()),ge=Object(fe.keyframes)(i()),ye=Object(fe.keyframes)(o()),ve=de.a.span(u(),be,function(e){return e.delay}),me=function(){return se.a.createElement("span",{className:"rsc-loading"},se.a.createElement(ve,{delay:"0s"},"."),se.a.createElement(ve,{delay:".2s"},"."),se.a.createElement(ve,{delay:".4s"},"."))},Se=de.a.div(c()),xe=function(e){function t(){var e,n;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,o=new Array(r),i=0;i0&&void 0!==arguments[0]?arguments[0]:ct,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:ct,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ct,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"en";return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),ut||(ut=this),this.state={inputValue:"",lang:o,onChange:t,onEnd:n,onStop:r},this.onResult=this.onResult.bind(this),this.onEnd=this.onEnd.bind(this),this.setup(),ut}return Q(e,null,[{key:"isSupported",value:function(){return"webkitSpeechRecognition"in window}}]),Q(e,[{key:"onChange",value:function(e){var t=this.state.onChange;this.setState({inputValue:e}),t(e)}},{key:"onFinal",value:function(e){this.setState({inputValue:e}),this.recognition.stop()}},{key:"onEnd",value:function(){var e=this.state,t=e.onStop,n=e.onEnd,r=e.force;this.setState({speaking:!1}),r?t():n()}},{key:"onResult",value:function(e){for(var t="",n="",r=e.resultIndex;r0?t.length-1:0,o=n.generateRenderedStepsById(),i=t[r].value;return"function"==typeof e?e({previousValue:i,steps:o}):e}),ie(oe(oe(n)),"generateRenderedStepsById",function(){for(var e=n.state.previousSteps,t={},r=0,o=e.length;r0}),ie(oe(oe(n)),"isLastPosition",function(e){var t=n.state.renderedSteps,r=t.length,o=t.map(function(e){return e.key}).indexOf(e.key);if(r<=1||o+1===r)return!0;var i=t[o+1];return!i.message&&!i.asMessage||e.user!==i.user}),ie(oe(oe(n)),"isFirstPosition",function(e){var t=n.state.renderedSteps,r=t.map(function(e){return e.key}).indexOf(e.key);if(0===r)return!0;var o=t[r-1];return!o.message&&!o.asMessage||e.user!==o.user}),ie(oe(oe(n)),"handleKeyPress",function(e){"Enter"===e.key&&n.submitUserMessage()}),ie(oe(oe(n)),"handleSubmitButton",function(){var e=n.state,t=e.speaking,r=e.recognitionEnable;if((n.isInputValueEmpty()||t)&&r)return n.recognition.speak(),void(t||n.setState({speaking:!0}));n.submitUserMessage()}),ie(oe(oe(n)),"submitUserMessage",function(){var e=n.state,t=e.defaultUserSettings,r=e.inputValue,o=e.previousSteps,i=e.renderedSteps,a=n.state.currentStep;if(!a.validator||!n.checkInvalidInput()){var s={message:r,value:r};a=Object.assign({},t,a,s),i.push(a),o.push(a),n.setState({currentStep:a,renderedSteps:i,previousSteps:o,disabled:!0,inputValue:""},function(){n.input&&n.input.blur()})}}),ie(oe(oe(n)),"checkInvalidInput",function(){var e=n.props.enableMobileAutoFocus,t=n.state,r=t.currentStep,o=t.inputValue,i=r.validator(o),a=o;return!("boolean"==typeof i&&i||(n.setState({inputValue:i.toString(),inputInvalid:!0,disabled:!0},function(){setTimeout(function(){n.setState({inputValue:a,inputInvalid:!1,disabled:!1},function(){!e&&yt()||n.input&&n.input.focus()})},2e3)}),0))}),ie(oe(oe(n)),"toggleChatBot",function(e){var t=n.props.toggleFloating;t?t({opened:e}):n.setState({opened:e})}),ie(oe(oe(n)),"renderStep",function(e,t){var r=n.state.renderedSteps,o=n.props,i=o.avatarStyle,a=o.bubbleStyle,s=o.bubbleOptionStyle,u=o.customStyle,c=o.hideBotAvatar,l=o.hideUserAvatar,p=o.speechSynthesis,f=e.options,d=e.component,h=e.asMessage,b=n.generateRenderedStepsById(),g=t>0?r[t-1]:{};return d&&!h?se.a.createElement(we,{key:t,speak:n.speak,step:e,steps:b,style:u,previousStep:g,previousValue:g.value,triggerNextStep:n.triggerNextStep}):f?se.a.createElement(Ce,{key:t,step:e,speak:n.speak,previousValue:g.value,triggerNextStep:n.triggerNextStep,bubbleOptionStyle:s}):se.a.createElement(_e,{key:t,step:e,steps:b,speak:n.speak,previousStep:g,previousValue:g.value,triggerNextStep:n.triggerNextStep,avatarStyle:i,bubbleStyle:a,hideBotAvatar:c,hideUserAvatar:l,speechSynthesis:p,isFirst:n.isFirstPosition(e),isLast:n.isLastPosition(e)})}),n.content=null,n.input=null,n.setContentRef=function(e){n.content=e},n.setInputRef=function(e){n.input=e},n.state={renderedSteps:[],previousSteps:[],currentStep:{},previousStep:{},steps:{},disabled:!0,opened:e.opened||!e.floating,inputValue:"",inputInvalid:!1,speaking:!1,recognitionEnable:e.recognitionEnable&<.isSupported(),defaultUserSettings:{}},n.speak=mt(e.speechSynthesis),n}return re(t,ae.Component),function(e,t,n){t&&te(e.prototype,t),n&&te(e,n)}(t,[{key:"componentWillMount",value:function(){for(var e=this,t=this.props.steps,n=this.props,r=n.botDelay,o=n.botAvatar,i=n.cache,a=n.cacheName,s=n.customDelay,u=n.enableMobileAutoFocus,c=n.userAvatar,l={},p={delay:r,avatar:o},f={delay:n.userDelay,avatar:c,hideInput:!1},d={delay:s},h=0,b=t.length;h