UNPKG

@livechat/widget-vue

Version:

This library allows to render and interact with the LiveChat Chat Widget inside a Vue 3 application

2 lines (1 loc) 5.91 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("@livechat/widget-core")):"function"==typeof define&&define.amd?define(["exports","vue","@livechat/widget-core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LiveChatWidgetVue={},e.Vue,e.LiveChatWidgetCore)}(this,(function(e,t,n){"use strict";function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function u(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(){var e=t.ref(null),i=null,u=null,o=function(t){e.value=t.customerData},r=function(){e.value=n.getData("customer")};return t.onMounted((function(){i=n.lcOnInit((function(){n.assignEventHandlers("once",{onReady:o}),n.assignEventHandlers("on",{onCustomerStatusChanged:r})})),u=n.lcOnDestroy((function(){e.value=null}))})),t.onUnmounted((function(){var e,t;n.assignEventHandlers("off",{onReady:o,onCustomerStatusChanged:r}),null===(e=i)||void 0===e||e(),null===(t=u)||void 0===t||t()})),e}var a=t.defineComponent({props:{license:{type:String,required:!0},group:{type:String,required:!1,default:void 0},visibility:{type:String,required:!1,default:void 0},customerName:{type:String,required:!1,default:void 0},customerEmail:{type:String,required:!1,default:void 0},sessionVariables:{type:Object,required:!1,default:void 0},chatBetweenGroups:{type:Boolean,required:!1,default:void 0},customIdentityProvider:{type:Function,required:!1,default:void 0}},emits:["ready","new-event","form-submitted","rating-submitted","greeting-hidden","greeting-displayed","visibility-changed","customer-status-changed","rich-message-button-clicked","availability-changed"],data:function(){return{widget:null}},watch:{license:"reinitialize",group:"reinitialize",chatBetweenGroups:"reinitialize",visibility:function(e){var t;null===(t=this.widget)||void 0===t||t.updateVisibility(e)},customerName:function(e){var t;null===(t=this.widget)||void 0===t||t.updateCustomerData({name:e})},customerEmail:function(e){var t;null===(t=this.widget)||void 0===t||t.updateCustomerData({email:e})},sessionVariables:function(e){var t;null===(t=this.widget)||void 0===t||t.updateSessionVariables(e)}},mounted:function(){this.setupWidget()},unmounted:function(){var e;null===(e=this.widget)||void 0===e||e.destroy()},methods:{setupWidget:function(){var e=this;this.widget=n.createWidget({group:this.group,license:this.license,customerName:this.customerName,customerEmail:this.customerEmail,sessionVariables:this.sessionVariables,chatBetweenGroups:this.chatBetweenGroups,visibility:this.visibility,customIdentityProvider:this.customIdentityProvider,onReady:function(t){return e.$emit("ready",t)},onNewEvent:function(t){return e.$emit("new-event",t)},onFormSubmitted:function(t){return e.$emit("form-submitted",t)},onRatingSubmitted:function(t){return e.$emit("rating-submitted",t)},onGreetingHidden:function(t){return e.$emit("greeting-hidden",t)},onGreetingDisplayed:function(t){return e.$emit("greeting-displayed",t)},onVisibilityChanged:function(t){return e.$emit("visibility-changed",t)},onCustomerStatusChanged:function(t){return e.$emit("customer-status-changed",t)},onRichMessageButtonClicked:function(t){return e.$emit("rich-message-button-clicked",t)},onAvailabilityChanged:function(t){return e.$emit("availability-changed",t)}}),window.__lc.integration_name="@livechat/widget-vue",this.widget.init()},reinitialize:function(){var e;null===(e=this.widget)||void 0===e||e.destroy(),this.setupWidget()}},render:function(){return null}});e.LiveChatWidget=a,e.useWidgetChatData=function(){var e=t.ref(null),i=r();return t.watch((function(){var e;return null===(e=i.value)||void 0===e?void 0:e.status}),(function(t){e.value="chatting"===t?n.getData("chat"):null})),e},e.useWidgetCustomerData=r,e.useWidgetGreeting=function(){var e=t.ref(null),i=null,u=null,o=function(t){e.value=t},r=function(){e.value=null};return t.onMounted((function(){i=n.lcOnInit((function(){n.assignEventHandlers("on",{onGreetingDisplayed:o,onGreetingHidden:r})})),u=n.lcOnDestroy((function(){e.value=null}))})),t.onUnmounted((function(){var e,t;n.assignEventHandlers("off",{onGreetingDisplayed:o,onGreetingHidden:r}),null===(e=i)||void 0===e||e(),null===(t=u)||void 0===t||t()})),e},e.useWidgetIsReady=function(){var e=t.ref(!1),i=null,u=null,o=function(){e.value=!0};return t.onMounted((function(){i=n.lcOnInit((function(){n.assignEventHandlers("once",{onReady:o})})),u=n.lcOnDestroy((function(){e.value=!1}))})),t.onUnmounted((function(){var e,t;n.assignEventHandlers("off",{onReady:o}),null===(e=i)||void 0===e||e(),null===(t=u)||void 0===t||t()})),e},e.useWidgetState=function(){var e=t.ref(null),i=null,o=null,r=function(t){var n=t.state;e.value=n},a=function(t){var n=t.visibility;e.value=e.value?u(u({},e.value),{},{visibility:n}):e.value},l=function(t){var n=t.availability;e.value=e.value?u(u({},e.value),{},{availability:n}):e.value};return t.onMounted((function(){i=n.lcOnInit((function(){n.assignEventHandlers("once",{onReady:r}),n.assignEventHandlers("on",{onVisibilityChanged:a,onAvailabilityChanged:l})})),o=n.lcOnDestroy((function(){e.value=null}))})),t.onUnmounted((function(){var e,t;n.assignEventHandlers("off",{onReady:r,onVisibilityChanged:a,onAvailabilityChanged:l}),null===(e=i)||void 0===e||e(),null===(t=o)||void 0===t||t()})),e},Object.defineProperty(e,"__esModule",{value:!0})}));