UNPKG

react-freshdesk-widget-query-string

Version:

A component of React for use the Freshdesk Widget

6 lines 18.8 kB
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var n=t("object"==typeof exports?require("react"):e.react);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var c=function(){function e(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&a.return&&a.return()}finally{if(o)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),f=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),s=n(12),l=r(s),p=n(11),d=r(p);n(6);var y=function(e){function t(e){i(this,t);var n=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.renderPopUp=n.renderPopUp.bind(n),n.renderWithChildren=n.renderWithChildren.bind(n),n.renderIncorporated=n.renderIncorporated.bind(n),n}return a(t,e),f(t,[{key:"componentWillMount",value:function(){function e(){var e=document.createElement("script");e.src="https://s3.amazonaws.com/assets.freshdesk.com/widget/freshwidget.js",e.type="text/javascript",document.body.appendChild(e)}return e}()},{key:"componentWillUnmount",value:function(){function e(){var e=this.props.type;"pop-up"===e&&window.FreshWidget&&window.FreshWidget.destroy()}return e}()},{key:"getAlignmentByPositionLabel",value:function(){function e(e){var t={left:4,right:2,top:1,bottom:3};return t[e]}return e}()},{key:"renderWithChildren",value:function(){function e(){var e=this.props,t=e.url,n=e.additionalQueryString,r=e.formTitle,i=e.formHeight,u=e.submitThanks,a=e.autofill,f=Object.entries(a).map(function(e){var t=c(e,2),n=t[0],r=t[1];return"helpdesk_ticket["+n+"]="+r}),s=["&widgetType=popup","formTitle="+r,"submitThanks="+u].concat(o(f)).join("&"),p={utf8:"✓",widgetType:"popup",url:t,formTitle:r,formHeight:i,submitThanks:u,queryString:s+n,offset:"-3000px"},d=function(){function e(){window.FreshWidget.init("",p),setTimeout(function(){window.FreshWidget.create(),window.FreshWidget.show()},100)}return e}(),y=l.default.cloneElement(this.props.children,{onClick:d.bind(this)});return l.default.createElement("div",null,y)}return e}()},{key:"renderPopUp",value:function(){function e(){var e=this.props,t=e.url,n=e.additionalQueryString,r=e.buttonType,i=e.buttonText,u=e.buttonColor,a=e.buttonBackgroundColor,f=e.buttonBackgroundImage,s=e.buttonPosition,p=e.buttonOffset,d=e.formTitle,y=e.submitThanks,h=e.formHeight,v=e.autofill,m=Object.entries(v).map(function(e){var t=c(e,2),n=t[0],r=t[1];return"helpdesk_ticket["+n+"]="+r}),b=["&widgetType=popup","formTitle="+d,"submitThanks="+y].concat(o(m)).join("&"),g={utf8:"✓",widgetType:"popup",alignment:this.getAlignmentByPositionLabel(s),offset:p,buttonBg:a,backgroundImage:f,url:t,buttonType:r,buttonText:i,buttonColor:u,submitThanks:y,formHeight:h,formTitle:d,queryString:b+n};return window.FreshWidget.init("",g),l.default.createElement("div",{id:"freshdesk"})}return e}()},{key:"renderIncorporated",value:function(){function e(){var e=this.props,t=e.additionalQueryString,n=e.url,r=e.formTitle,i=e.formHeight,u=e.submitThanks,a=e.autofill,f=n+"/widgets/feedback_widget/new?",s=Object.entries(a).map(function(e){var t=c(e,2),n=t[0],r=t[1];return"helpdesk_ticket["+n+"]="+r}),p=["widgetType=embedded","screenshot=no","formTitle="+r,"formHeight="+i,"submitThanks="+u].concat(o(s)).join("&");return l.default.createElement("div",null,l.default.createElement("iframe",{className:"freshwidget-embedded-form",frameBorder:"0",id:"freshwidget-embedded-form",src:f+p+t,scrolling:"no",height:i,width:"100%"}))}return e}()},{key:"render",value:function(){function e(){var e=this.props.type;if("incorporated"===e)return this.renderIncorporated();var t=l.default.Children.count(this.props.children)>=1;return t?this.renderWithChildren():this.renderPopUp()}return e}()}]),t}(s.Component);y.propTypes={url:d.default.string.isRequired,type:d.default.oneOf(["pop-up","incorporated"]),additionalQueryString:d.default.string,buttonType:d.default.oneOf(["text","image"]),buttonText:d.default.string,buttonColor:d.default.string,buttonBackgroundColor:d.default.string,buttonBackgroundImage:d.default.string,buttonPosition:d.default.oneOf(["left","right","top","bottom"]),buttonOffset:d.default.string,formTitle:d.default.string,submitThanks:d.default.string,formHeight:d.default.string,autofill:d.default.objectOf(d.default.string),children:d.default.oneOfType([d.default.arrayOf(d.default.node),d.default.node])},y.defaultProps={type:"incorporated",additionalQueryString:"",formTitle:"Help and support",submitThanks:"Thank you, one of our representatives will respond to you soon! =)",formHeight:"500px",buttonType:"text",buttonText:"Support",buttonColor:"white",buttonBackgroundColor:"#015453",buttonPosition:"top",buttonOffset:"235px",autofill:{},children:null},t.default=y},function(e,t){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function o(e){if(s===setTimeout)return setTimeout(e,0);if((s===n||!s)&&setTimeout)return s=setTimeout,setTimeout(e,0);try{return s(e,0)}catch(t){try{return s.call(null,e,0)}catch(t){return s.call(this,e,0)}}}function i(e){if(l===clearTimeout)return clearTimeout(e);if((l===r||!l)&&clearTimeout)return l=clearTimeout,clearTimeout(e);try{return l(e)}catch(t){try{return l.call(null,e)}catch(t){return l.call(this,e)}}}function u(){h&&d&&(h=!1,d.length?y=d.concat(y):v=-1,y.length&&a())}function a(){if(!h){var e=o(u);h=!0;for(var t=y.length;t;){for(d=y,y=[];++v<t;)d&&d[v].run();v=-1,t=y.length}d=null,h=!1,i(e)}}function c(e,t){this.fun=e,this.array=t}function f(){}var s,l,p=e.exports={};!function(){try{s="function"==typeof setTimeout?setTimeout:n}catch(e){s=n}try{l="function"==typeof clearTimeout?clearTimeout:r}catch(e){l=r}}();var d,y=[],h=!1,v=-1;p.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];y.push(new c(e,t)),1!==y.length||h||o(a)},c.prototype.run=function(){this.fun.apply(null,this.array)},p.title="browser",p.browser=!0,p.env={},p.argv=[],p.version="",p.versions={},p.on=f,p.addListener=f,p.once=f,p.off=f,p.removeListener=f,p.removeAllListeners=f,p.emit=f,p.prependListener=f,p.prependOnceListener=f,p.listeners=function(e){return[]},p.binding=function(e){throw new Error("process.binding is not supported")},p.cwd=function(){return"/"},p.chdir=function(e){throw new Error("process.chdir is not supported")},p.umask=function(){return 0}},function(e,t){"use strict";var n="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";e.exports=n},function(e,t){"use strict";function n(e){return function(){return e}}var r=function(){};r.thatReturns=n,r.thatReturnsFalse=n(!1),r.thatReturnsTrue=n(!0),r.thatReturnsNull=n(null),r.thatReturnsThis=function(){return this},r.thatReturnsArgument=function(e){return e},e.exports=r},function(e,t,n){(function(t){"use strict";function n(e,t,n,o,i,u,a,c){if(r(t),!e){var f;if(void 0===t)f=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,o,i,u,a,c],l=0;f=new Error(t.replace(/%s/g,function(){return s[l++]})),f.name="Invariant Violation"}throw f.framesToPop=1,f}}var r=function(e){};"production"!==t.env.NODE_ENV&&(r=function(e){if(void 0===e)throw new Error("invariant requires an error message argument")}),e.exports=n}).call(t,n(1))},function(e,t,n){(function(t){"use strict";var r=n(3),o=r;if("production"!==t.env.NODE_ENV){var i=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=0,i="Warning: "+e.replace(/%s/g,function(){return n[o++]});"undefined"!=typeof console&&console.error(i);try{throw new Error(i)}catch(e){}};o=function(e,t){if(void 0===t)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");if(0!==t.indexOf("Failed Composite propType: ")&&!e){for(var n=arguments.length,r=Array(n>2?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];i.apply(void 0,[t].concat(r))}}}e.exports=o}).call(t,n(1))},function(e,t){"use strict";var n=Function.bind.call(Function.call,Array.prototype.reduce),r=Function.bind.call(Function.call,Object.prototype.propertyIsEnumerable),o=Function.bind.call(Function.call,Array.prototype.concat),i=Reflect.ownKeys;Object.values||(Object.values=function(){function e(e){return n(i(e),function(t,n){return o(t,"string"==typeof n&&r(e,n)?[e[n]]:[])},[])}return e}()),Object.entries||(Object.entries=function(){function e(e){return n(i(e),function(t,n){return o(t,"string"==typeof n&&r(e,n)?[[n,e[n]]]:[])},[])}return e}())},function(e,t){/* object-assign (c) Sindre Sorhus @license MIT */ "use strict";function n(e){if(null===e||void 0===e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}function r(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;var r=Object.getOwnPropertyNames(t).map(function(e){return t[e]});if("0123456789"!==r.join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach(function(e){o[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(e){return!1}}var o=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,u=Object.prototype.propertyIsEnumerable;e.exports=r()?Object.assign:function(e,t){for(var r,a,c=n(e),f=1;f<arguments.length;f++){r=Object(arguments[f]);for(var s in r)i.call(r,s)&&(c[s]=r[s]);if(o){a=o(r);for(var l=0;l<a.length;l++)u.call(r,a[l])&&(c[a[l]]=r[a[l]])}}return c}},function(e,t,n){(function(t){"use strict";function r(e,n,r,c,f){if("production"!==t.env.NODE_ENV)for(var s in e)if(e.hasOwnProperty(s)){var l;try{o("function"==typeof e[s],"%s: %s type `%s` is invalid; it must be a function, usually from the `prop-types` package, but received `%s`.",c||"React class",r,s,typeof e[s]),l=e[s](n,s,c,r,null,u)}catch(e){l=e}if(i(!l||l instanceof Error,"%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",c||"React class",r,s,typeof l),l instanceof Error&&!(l.message in a)){a[l.message]=!0;var p=f?f():"";i(!1,"Failed %s type: %s%s",r,l.message,null!=p?p:"")}}}if("production"!==t.env.NODE_ENV)var o=n(4),i=n(5),u=n(2),a={};e.exports=r}).call(t,n(1))},function(e,t,n){"use strict";var r=n(3),o=n(4),i=n(2);e.exports=function(){function e(e,t,n,r,u,a){a!==i&&o(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return n.checkPropTypes=r,n.PropTypes=n,n}},function(e,t,n){(function(t){"use strict";var r=n(3),o=n(4),i=n(5),u=n(7),a=n(2),c=n(8);e.exports=function(e,n){function f(e){var t=e&&(S&&e[S]||e[I]);if("function"==typeof t)return t}function s(e,t){return e===t?0!==e||1/e===1/t:e!==e&&t!==t}function l(e){this.message=e,this.stack=""}function p(e){function r(r,f,s,p,d,y,h){if(p=p||R,y=y||s,h!==a)if(n)o(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");else if("production"!==t.env.NODE_ENV&&"undefined"!=typeof console){var v=p+":"+s;!u[v]&&c<3&&(i(!1,"You are manually calling a React.PropTypes validation function for the `%s` prop on `%s`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details.",y,p),u[v]=!0,c++)}return null==f[s]?r?new l(null===f[s]?"The "+d+" `"+y+"` is marked as required "+("in `"+p+"`, but its value is `null`."):"The "+d+" `"+y+"` is marked as required in "+("`"+p+"`, but its value is `undefined`.")):null:e(f,s,p,d,y)}if("production"!==t.env.NODE_ENV)var u={},c=0;var f=r.bind(null,!1);return f.isRequired=r.bind(null,!0),f}function d(e){function t(t,n,r,o,i,u){var a=t[n],c=E(a);if(c!==e){var f=P(a);return new l("Invalid "+o+" `"+i+"` of type "+("`"+f+"` supplied to `"+r+"`, expected ")+("`"+e+"`."))}return null}return p(t)}function y(){return p(r.thatReturnsNull)}function h(e){function t(t,n,r,o,i){if("function"!=typeof e)return new l("Property `"+i+"` of component `"+r+"` has invalid PropType notation inside arrayOf.");var u=t[n];if(!Array.isArray(u)){var c=E(u);return new l("Invalid "+o+" `"+i+"` of type "+("`"+c+"` supplied to `"+r+"`, expected an array."))}for(var f=0;f<u.length;f++){var s=e(u,f,r,o,i+"["+f+"]",a);if(s instanceof Error)return s}return null}return p(t)}function v(){function t(t,n,r,o,i){var u=t[n];if(!e(u)){var a=E(u);return new l("Invalid "+o+" `"+i+"` of type "+("`"+a+"` supplied to `"+r+"`, expected a single ReactElement."))}return null}return p(t)}function m(e){function t(t,n,r,o,i){if(!(t[n]instanceof e)){var u=e.name||R,a=N(t[n]);return new l("Invalid "+o+" `"+i+"` of type "+("`"+a+"` supplied to `"+r+"`, expected ")+("instance of `"+u+"`."))}return null}return p(t)}function b(e){function n(t,n,r,o,i){for(var u=t[n],a=0;a<e.length;a++)if(s(u,e[a]))return null;var c=JSON.stringify(e);return new l("Invalid "+o+" `"+i+"` of value `"+u+"` "+("supplied to `"+r+"`, expected one of "+c+"."))}return Array.isArray(e)?p(n):("production"!==t.env.NODE_ENV?i(!1,"Invalid argument supplied to oneOf, expected an instance of array."):void 0,r.thatReturnsNull)}function g(e){function t(t,n,r,o,i){if("function"!=typeof e)return new l("Property `"+i+"` of component `"+r+"` has invalid PropType notation inside objectOf.");var u=t[n],c=E(u);if("object"!==c)return new l("Invalid "+o+" `"+i+"` of type "+("`"+c+"` supplied to `"+r+"`, expected an object."));for(var f in u)if(u.hasOwnProperty(f)){var s=e(u,f,r,o,i+"."+f,a);if(s instanceof Error)return s}return null}return p(t)}function w(e){function n(t,n,r,o,i){for(var u=0;u<e.length;u++){var c=e[u];if(null==c(t,n,r,o,i,a))return null}return new l("Invalid "+o+" `"+i+"` supplied to "+("`"+r+"`."))}if(!Array.isArray(e))return"production"!==t.env.NODE_ENV?i(!1,"Invalid argument supplied to oneOfType, expected an instance of array."):void 0,r.thatReturnsNull;for(var o=0;o<e.length;o++){var u=e[o];if("function"!=typeof u)return i(!1,"Invalid argument supplied to oneOfType. Expected an array of check functions, but received %s at index %s.",_(u),o),r.thatReturnsNull}return p(n)}function T(){function e(e,t,n,r,o){return k(e[t])?null:new l("Invalid "+r+" `"+o+"` supplied to "+("`"+n+"`, expected a ReactNode."))}return p(e)}function O(e){function t(t,n,r,o,i){var u=t[n],c=E(u);if("object"!==c)return new l("Invalid "+o+" `"+i+"` of type `"+c+"` "+("supplied to `"+r+"`, expected `object`."));for(var f in e){var s=e[f];if(s){var p=s(u,f,r,o,i+"."+f,a);if(p)return p}}return null}return p(t)}function j(e){function t(t,n,r,o,i){var c=t[n],f=E(c);if("object"!==f)return new l("Invalid "+o+" `"+i+"` of type `"+f+"` "+("supplied to `"+r+"`, expected `object`."));var s=u({},t[n],e);for(var p in s){var d=e[p];if(!d)return new l("Invalid "+o+" `"+i+"` key `"+p+"` supplied to `"+r+"`.\nBad object: "+JSON.stringify(t[n],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var y=d(c,p,r,o,i+"."+p,a);if(y)return y}return null}return p(t)}function k(t){switch(typeof t){case"number":case"string":case"undefined":return!0;case"boolean":return!t;case"object":if(Array.isArray(t))return t.every(k);if(null===t||e(t))return!0;var n=f(t);if(!n)return!1;var r,o=n.call(t);if(n!==t.entries){for(;!(r=o.next()).done;)if(!k(r.value))return!1}else for(;!(r=o.next()).done;){var i=r.value;if(i&&!k(i[1]))return!1}return!0;default:return!1}}function x(e,t){return"symbol"===e||"Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol}function E(e){var t=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":x(t,e)?"symbol":t}function P(e){if("undefined"==typeof e||null===e)return""+e;var t=E(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function _(e){var t=P(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}function N(e){return e.constructor&&e.constructor.name?e.constructor.name:R}var S="function"==typeof Symbol&&Symbol.iterator,I="@@iterator",R="<<anonymous>>",A={array:d("array"),bool:d("boolean"),func:d("function"),number:d("number"),object:d("object"),string:d("string"),symbol:d("symbol"),any:y(),arrayOf:h,element:v(),instanceOf:m,node:T(),objectOf:g,oneOf:b,oneOfType:w,shape:O,exact:j};return l.prototype=Error.prototype,A.checkPropTypes=c,A.PropTypes=A,A}}).call(t,n(1))},function(e,t,n){(function(t){if("production"!==t.env.NODE_ENV){var r="function"==typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103,o=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===r},i=!0;e.exports=n(10)(o,i)}else e.exports=n(9)()}).call(t,n(1))},function(t,n){t.exports=e}])});