1 line
4.4 KiB
JavaScript
1 line
4.4 KiB
JavaScript
(function(a,b){'object'==typeof exports&&'object'==typeof module?module.exports=b(require('React')):'function'==typeof define&&define.amd?define(['React'],b):'object'==typeof exports?exports.CopyToClipboard=b(require('React')):a.CopyToClipboard=b(a.React)})(this,function(a){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{configurable:!1,enumerable:!0,get:d})},b.n=function(a){var c=a&&a.__esModule?function(){return a['default']}:function(){return a};return b.d(c,'a',c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p='',b(b.s=0)}([function(a,b,c){'use strict';var d=c(1),e=d.CopyToClipboard;e.CopyToClipboard=e,a.exports=e},function(a,b,c){'use strict';function d(a,b){var c={};for(var d in a)0<=b.indexOf(d)||Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);return c}function e(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}function f(a,b){if(!a)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return b&&('object'==typeof b||'function'==typeof b)?b:a}function g(a,b){if('function'!=typeof b&&null!==b)throw new TypeError('Super expression must either be null or a function, not '+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}Object.defineProperty(b,'__esModule',{value:!0}),c.d(b,'CopyToClipboard',function(){return n});var h=c(2);var i=c.n(h);var j=c(3);var k=c.n(j);var l=Object.assign||function(a){for(var b=1;b<arguments.length;b++){var c=arguments[b];for(var d in c)Object.prototype.hasOwnProperty.call(c,d)&&(a[d]=c[d])}return a};var m=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,'value'in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();var n=function(a){function b(){var a;var c,d,g;e(this,b);for(var h=arguments.length,j=Array(h),l=0;l<h;l++)j[l]=arguments[l];return g=(c=(d=f(this,(a=b.__proto__||Object.getPrototypeOf(b)).call.apply(a,[this].concat(j))),d),d.onClick=function(a){var b=d.props,c=b.text,e=b.onCopy,f=b.children,g=b.options;var h=i.a.Children.only(f);var j=k()(c,g);e&&e(c,j),h&&h.props&&'function'==typeof h.props.onClick&&h.props.onClick(a)},c),f(d,g)}return g(b,a),m(b,[{key:'render',value:function(){var a=this.props,b=a.text,c=a.onCopy,e=a.options,f=a.children,g=d(a,['text','onCopy','options','children']);var h=i.a.Children.only(f);return i.a.cloneElement(h,l({},g,{onClick:this.onClick}))}}]),b}(i.a.PureComponent);n.defaultProps={onCopy:void 0,options:void 0}},function(b){b.exports=a},function(a,b,c){'use strict';function d(a){var b=(/mac os x/i.test(navigator.userAgent)?'\u2318':'Ctrl')+'+C';return a.replace(/#{\s*key\s*}/g,b)}var e=c(4);a.exports=function(a,b){var c,f,g,h,i,j,k=!1;b||(b={}),c=b.debug||!1;try{g=e(),h=document.createRange(),i=document.getSelection(),j=document.createElement('span'),j.textContent=a,j.style.all='unset',j.style.position='fixed',j.style.top=0,j.style.clip='rect(0, 0, 0, 0)',j.style.whiteSpace='pre',j.style.webkitUserSelect='text',j.style.MozUserSelect='text',j.style.msUserSelect='text',j.style.userSelect='text',document.body.appendChild(j),h.selectNode(j),i.addRange(h);var l=document.execCommand('copy');if(!l)throw new Error('copy command was unsuccessful');k=!0}catch(e){c&&console.error('unable to copy using execCommand: ',e),c&&console.warn('trying IE specific stuff');try{window.clipboardData.setData('text',a),k=!0}catch(e){c&&console.error('unable to copy using clipboardData: ',e),c&&console.error('falling back to prompt'),f=d('message'in b?b.message:'Copy to clipboard: #{key}, Enter'),window.prompt(f,a)}}finally{i&&('function'==typeof i.removeRange?i.removeRange(h):i.removeAllRanges()),j&&document.body.removeChild(j),g()}return k}},function(a){a.exports=function(){var a=document.getSelection();if(!a.rangeCount)return function(){};var b=document.activeElement;var c=[];for(var d=0;d<a.rangeCount;d++)c.push(a.getRangeAt(d));switch(b.tagName.toUpperCase()){case'INPUT':case'TEXTAREA':b.blur();break;default:b=null;}return a.removeAllRanges(),function(){'Caret'===a.type&&a.removeAllRanges(),a.rangeCount||c.forEach(function(b){a.addRange(b)}),b&&b.focus()}}}])}); |