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.8 kB
JavaScript
var _excluded=["children","successCb","failureCb","loadingCb","successMsg","failureMsg"];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 _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],-1===b.indexOf(c)&&{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(-1!==b.indexOf(d))continue;c[d]=a[d]}return c}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:"CopyToClipboard is not supporting in your device",error:""},isBrowserSupport=function(){var a;return null===(a=globalThis.navigator)||void 0===a?void 0:a.clipboard},copyToClipboard=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?"Copied Successfully":h,j=a.failureMsg,k=void 0===j?_objectSpread({},failureMsgDefault):j,l=a.elementToBeCopy,m=_objectSpread(_objectSpread({},failureMsgDefault),k);(function(){if(!isBrowserSupport())return handleError({msgType:"UN_SUPPORTED_FEATURE",msg:m.unSupported,failureCb:e});if(handleLoading({loadingCb:g}),l)navigator.clipboard.writeText(l).then(function(){handleSuccess({msgType:"SUCCESSFUL",msg:i,successCb:c,data:l})})["catch"](function(a){return handleError({msgType:"ERROR",msg:m.error||(null===a||void 0===a?void 0:a.message)||"Unable To Copy",failureCb:e})});else return handleError({msgType:"BAD_REQUEST",msg:"elementToBeCopy is missing",failureCb:e});return!0})()};function CopyToClipboard(a){var b=a.children,c=a.successCb,d=a.failureCb,e=a.loadingCb,f=a.successMsg,g=a.failureMsg,h=_objectWithoutProperties(a,_excluded);return React.Children.map(b||"CopyToClipboard",function(a){return React.cloneElement("string"==typeof a?React.createElement("span",null,a):a,{onClick:function(){return copyToClipboard(_objectSpread({successCb:c,failureCb:d,loadingCb:e,successMsg:f,failureMsg:g},h))}})})}var WCopyToClipboard=Wrapper(CopyToClipboard,isBrowserSupport);export{copyToClipboard,WCopyToClipboard as CopyToClipboard};export default WCopyToClipboard;