1 | "use strict";
|
---|
2 |
|
---|
3 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
---|
4 |
|
---|
5 | Object.defineProperty(exports, "__esModule", {
|
---|
6 | value: true
|
---|
7 | });
|
---|
8 | exports.CopyToClipboard = void 0;
|
---|
9 |
|
---|
10 | var _react = _interopRequireDefault(require("react"));
|
---|
11 |
|
---|
12 | var _copyToClipboard = _interopRequireDefault(require("copy-to-clipboard"));
|
---|
13 |
|
---|
14 | var _excluded = ["text", "onCopy", "options", "children"];
|
---|
15 |
|
---|
16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
17 |
|
---|
18 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
---|
19 |
|
---|
20 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
---|
21 |
|
---|
22 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
---|
23 |
|
---|
24 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
---|
25 |
|
---|
26 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
---|
27 |
|
---|
28 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
29 |
|
---|
30 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
---|
31 |
|
---|
32 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
---|
33 |
|
---|
34 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
---|
35 |
|
---|
36 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
---|
37 |
|
---|
38 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
---|
39 |
|
---|
40 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
---|
41 |
|
---|
42 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
---|
43 |
|
---|
44 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
---|
45 |
|
---|
46 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
---|
47 |
|
---|
48 | var CopyToClipboard = /*#__PURE__*/function (_React$PureComponent) {
|
---|
49 | _inherits(CopyToClipboard, _React$PureComponent);
|
---|
50 |
|
---|
51 | var _super = _createSuper(CopyToClipboard);
|
---|
52 |
|
---|
53 | function CopyToClipboard() {
|
---|
54 | var _this;
|
---|
55 |
|
---|
56 | _classCallCheck(this, CopyToClipboard);
|
---|
57 |
|
---|
58 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
---|
59 | args[_key] = arguments[_key];
|
---|
60 | }
|
---|
61 |
|
---|
62 | _this = _super.call.apply(_super, [this].concat(args));
|
---|
63 |
|
---|
64 | _defineProperty(_assertThisInitialized(_this), "onClick", function (event) {
|
---|
65 | var _this$props = _this.props,
|
---|
66 | text = _this$props.text,
|
---|
67 | onCopy = _this$props.onCopy,
|
---|
68 | children = _this$props.children,
|
---|
69 | options = _this$props.options;
|
---|
70 |
|
---|
71 | var elem = _react["default"].Children.only(children);
|
---|
72 |
|
---|
73 | var result = (0, _copyToClipboard["default"])(text, options);
|
---|
74 |
|
---|
75 | if (onCopy) {
|
---|
76 | onCopy(text, result);
|
---|
77 | } // Bypass onClick if it was present
|
---|
78 |
|
---|
79 |
|
---|
80 | if (elem && elem.props && typeof elem.props.onClick === 'function') {
|
---|
81 | elem.props.onClick(event);
|
---|
82 | }
|
---|
83 | });
|
---|
84 |
|
---|
85 | return _this;
|
---|
86 | }
|
---|
87 |
|
---|
88 | _createClass(CopyToClipboard, [{
|
---|
89 | key: "render",
|
---|
90 | value: function render() {
|
---|
91 | var _this$props2 = this.props,
|
---|
92 | _text = _this$props2.text,
|
---|
93 | _onCopy = _this$props2.onCopy,
|
---|
94 | _options = _this$props2.options,
|
---|
95 | children = _this$props2.children,
|
---|
96 | props = _objectWithoutProperties(_this$props2, _excluded);
|
---|
97 |
|
---|
98 | var elem = _react["default"].Children.only(children);
|
---|
99 |
|
---|
100 | return /*#__PURE__*/_react["default"].cloneElement(elem, _objectSpread(_objectSpread({}, props), {}, {
|
---|
101 | onClick: this.onClick
|
---|
102 | }));
|
---|
103 | }
|
---|
104 | }]);
|
---|
105 |
|
---|
106 | return CopyToClipboard;
|
---|
107 | }(_react["default"].PureComponent);
|
---|
108 |
|
---|
109 | exports.CopyToClipboard = CopyToClipboard;
|
---|
110 |
|
---|
111 | _defineProperty(CopyToClipboard, "defaultProps", {
|
---|
112 | onCopy: undefined,
|
---|
113 | options: undefined
|
---|
114 | }); |
---|