UNPKG

fe-pilot

Version:

scanner in web, phonebook in web, autofill otp in web, share web, TextToSpeech in web, Voice Recognition in web, live location tracking in web, detect my location web, wakelock in web, color picker, WhatsappShare, SnapScanner, NetworkMonitor, View360

1 lines 3.44 kB
function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!=_typeof(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}import React from"react";import{handleSuccess,handleError,handleLoading}from"../services/handlerService";import Wrapper from"../Wrapper/Wrapper";var failureMsgDefault={unSupported:"Share is not supporting in your device",badRequest:"Mandatory props are missing",error:""},isShareAPIDataValid=function(a){return!navigator.canShare||navigator.canShare(a)},isBrowserSupport=function(){var a;return null===(a=globalThis.navigator)||void 0===a?void 0:a.share},share=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},b=a.successCb,c=void 0===b?function(){}:b,d=a.failureCb,e=void 0===d?function(){}:d,f=a.loadingCb,g=void 0===f?function(){}:f,h=a.successMsg,i=void 0===h?"Shared Successfully":h,j=a.failureMsg,k=void 0===j?_objectSpread({},failureMsgDefault):j,l=a.title,m=void 0===l?"fe-pilot":l,n=a.description,o=void 0===n?"A React library for advanced JS features":n,p=a.url,q=void 0===p?"https://www.npmjs.com/package/fe-pilot":p,r=_objectSpread(_objectSpread({},failureMsgDefault),k),s={title:m,text:o,url:q};(function(){if(!isBrowserSupport())return handleError({msgType:"UN_SUPPORTED_FEATURE",msg:r.unSupported,failureCb:e});if(handleLoading({loadingCb:g}),isShareAPIDataValid(s))navigator.share(s).then(function(){handleSuccess({msgType:"SUCCESSFUL",msg:i,successCb:c,data:s})})["catch"](function(a){return handleError({msgType:"ERROR",msg:r.error||(null===a||void 0===a?void 0:a.message)||"Unable to share",failureCb:e})});else return handleError({msgType:"BAD_REQUEST",msg:r.badRequest,failureCb:e});return!0})()};function Share(a){var b=a.children,c=a.successCb,d=a.failureCb,e=a.loadingCb,f=a.successMsg,g=a.failureMsg,h=a.title,i=a.description,j=a.url;return React.Children.map(b||"Share",function(a){return React.cloneElement("string"==typeof a?React.createElement("span",null,a):a,{onClick:function(){return share({successCb:c,failureCb:d,loadingCb:e,successMsg:f,failureMsg:g,title:h,description:i,url:j})}})})}var WShare=Wrapper(Share,isBrowserSupport);export{share,WShare as Share};export default WShare;