34 var listen = __webpack_require__(370); |
34 var listen = __webpack_require__(370); |
35 var listen_default = /*#__PURE__*/__webpack_require__.n(listen); |
35 var listen_default = /*#__PURE__*/__webpack_require__.n(listen); |
36 // EXTERNAL MODULE: ./node_modules/select/src/select.js |
36 // EXTERNAL MODULE: ./node_modules/select/src/select.js |
37 var src_select = __webpack_require__(817); |
37 var src_select = __webpack_require__(817); |
38 var select_default = /*#__PURE__*/__webpack_require__.n(src_select); |
38 var select_default = /*#__PURE__*/__webpack_require__.n(src_select); |
39 ;// CONCATENATED MODULE: ./src/clipboard-action.js |
39 ;// CONCATENATED MODULE: ./src/common/command.js |
|
40 /** |
|
41 * Executes a given operation type. |
|
42 * @param {String} type |
|
43 * @return {Boolean} |
|
44 */ |
|
45 function command(type) { |
|
46 try { |
|
47 return document.execCommand(type); |
|
48 } catch (err) { |
|
49 return false; |
|
50 } |
|
51 } |
|
52 ;// CONCATENATED MODULE: ./src/actions/cut.js |
|
53 |
|
54 |
|
55 /** |
|
56 * Cut action wrapper. |
|
57 * @param {String|HTMLElement} target |
|
58 * @return {String} |
|
59 */ |
|
60 |
|
61 var ClipboardActionCut = function ClipboardActionCut(target) { |
|
62 var selectedText = select_default()(target); |
|
63 command('cut'); |
|
64 return selectedText; |
|
65 }; |
|
66 |
|
67 /* harmony default export */ var actions_cut = (ClipboardActionCut); |
|
68 ;// CONCATENATED MODULE: ./src/common/create-fake-element.js |
|
69 /** |
|
70 * Creates a fake textarea element with a value. |
|
71 * @param {String} value |
|
72 * @return {HTMLElement} |
|
73 */ |
|
74 function createFakeElement(value) { |
|
75 var isRTL = document.documentElement.getAttribute('dir') === 'rtl'; |
|
76 var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS |
|
77 |
|
78 fakeElement.style.fontSize = '12pt'; // Reset box model |
|
79 |
|
80 fakeElement.style.border = '0'; |
|
81 fakeElement.style.padding = '0'; |
|
82 fakeElement.style.margin = '0'; // Move element out of screen horizontally |
|
83 |
|
84 fakeElement.style.position = 'absolute'; |
|
85 fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically |
|
86 |
|
87 var yPosition = window.pageYOffset || document.documentElement.scrollTop; |
|
88 fakeElement.style.top = "".concat(yPosition, "px"); |
|
89 fakeElement.setAttribute('readonly', ''); |
|
90 fakeElement.value = value; |
|
91 return fakeElement; |
|
92 } |
|
93 ;// CONCATENATED MODULE: ./src/actions/copy.js |
|
94 |
|
95 |
|
96 |
|
97 /** |
|
98 * Copy action wrapper. |
|
99 * @param {String|HTMLElement} target |
|
100 * @param {Object} options |
|
101 * @return {String} |
|
102 */ |
|
103 |
|
104 var ClipboardActionCopy = function ClipboardActionCopy(target) { |
|
105 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { |
|
106 container: document.body |
|
107 }; |
|
108 var selectedText = ''; |
|
109 |
|
110 if (typeof target === 'string') { |
|
111 var fakeElement = createFakeElement(target); |
|
112 options.container.appendChild(fakeElement); |
|
113 selectedText = select_default()(fakeElement); |
|
114 command('copy'); |
|
115 fakeElement.remove(); |
|
116 } else { |
|
117 selectedText = select_default()(target); |
|
118 command('copy'); |
|
119 } |
|
120 |
|
121 return selectedText; |
|
122 }; |
|
123 |
|
124 /* harmony default export */ var actions_copy = (ClipboardActionCopy); |
|
125 ;// CONCATENATED MODULE: ./src/actions/default.js |
40 function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
126 function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
41 |
127 |
42 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
128 |
43 |
129 |
44 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); } } |
130 /** |
45 |
131 * Inner function which performs selection from either `text` or `target` |
46 function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } |
|
47 |
|
48 |
|
49 /** |
|
50 * Inner class which performs selection from either `text` or `target` |
|
51 * properties and then executes copy or cut operations. |
132 * properties and then executes copy or cut operations. |
52 */ |
133 * @param {Object} options |
53 |
134 */ |
54 var ClipboardAction = /*#__PURE__*/function () { |
135 |
55 /** |
136 var ClipboardActionDefault = function ClipboardActionDefault() { |
56 * @param {Object} options |
137 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
57 */ |
138 // Defines base properties passed from constructor. |
58 function ClipboardAction(options) { |
139 var _options$action = options.action, |
59 _classCallCheck(this, ClipboardAction); |
140 action = _options$action === void 0 ? 'copy' : _options$action, |
60 |
141 container = options.container, |
61 this.resolveOptions(options); |
142 target = options.target, |
62 this.initSelection(); |
143 text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'. |
|
144 |
|
145 if (action !== 'copy' && action !== 'cut') { |
|
146 throw new Error('Invalid "action" value, use either "copy" or "cut"'); |
|
147 } // Sets the `target` property using an element that will be have its content copied. |
|
148 |
|
149 |
|
150 if (target !== undefined) { |
|
151 if (target && _typeof(target) === 'object' && target.nodeType === 1) { |
|
152 if (action === 'copy' && target.hasAttribute('disabled')) { |
|
153 throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); |
|
154 } |
|
155 |
|
156 if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { |
|
157 throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); |
|
158 } |
|
159 } else { |
|
160 throw new Error('Invalid "target" value, use a valid Element'); |
|
161 } |
|
162 } // Define selection strategy based on `text` property. |
|
163 |
|
164 |
|
165 if (text) { |
|
166 return actions_copy(text, { |
|
167 container: container |
|
168 }); |
|
169 } // Defines which selection strategy based on `target` property. |
|
170 |
|
171 |
|
172 if (target) { |
|
173 return action === 'cut' ? actions_cut(target) : actions_copy(target, { |
|
174 container: container |
|
175 }); |
63 } |
176 } |
64 /** |
177 }; |
65 * Defines base properties passed from constructor. |
178 |
66 * @param {Object} options |
179 /* harmony default export */ var actions_default = (ClipboardActionDefault); |
67 */ |
|
68 |
|
69 |
|
70 _createClass(ClipboardAction, [{ |
|
71 key: "resolveOptions", |
|
72 value: function resolveOptions() { |
|
73 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
74 this.action = options.action; |
|
75 this.container = options.container; |
|
76 this.emitter = options.emitter; |
|
77 this.target = options.target; |
|
78 this.text = options.text; |
|
79 this.trigger = options.trigger; |
|
80 this.selectedText = ''; |
|
81 } |
|
82 /** |
|
83 * Decides which selection strategy is going to be applied based |
|
84 * on the existence of `text` and `target` properties. |
|
85 */ |
|
86 |
|
87 }, { |
|
88 key: "initSelection", |
|
89 value: function initSelection() { |
|
90 if (this.text) { |
|
91 this.selectFake(); |
|
92 } else if (this.target) { |
|
93 this.selectTarget(); |
|
94 } |
|
95 } |
|
96 /** |
|
97 * Creates a fake textarea element, sets its value from `text` property, |
|
98 */ |
|
99 |
|
100 }, { |
|
101 key: "createFakeElement", |
|
102 value: function createFakeElement() { |
|
103 var isRTL = document.documentElement.getAttribute('dir') === 'rtl'; |
|
104 this.fakeElem = document.createElement('textarea'); // Prevent zooming on iOS |
|
105 |
|
106 this.fakeElem.style.fontSize = '12pt'; // Reset box model |
|
107 |
|
108 this.fakeElem.style.border = '0'; |
|
109 this.fakeElem.style.padding = '0'; |
|
110 this.fakeElem.style.margin = '0'; // Move element out of screen horizontally |
|
111 |
|
112 this.fakeElem.style.position = 'absolute'; |
|
113 this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically |
|
114 |
|
115 var yPosition = window.pageYOffset || document.documentElement.scrollTop; |
|
116 this.fakeElem.style.top = "".concat(yPosition, "px"); |
|
117 this.fakeElem.setAttribute('readonly', ''); |
|
118 this.fakeElem.value = this.text; |
|
119 return this.fakeElem; |
|
120 } |
|
121 /** |
|
122 * Get's the value of fakeElem, |
|
123 * and makes a selection on it. |
|
124 */ |
|
125 |
|
126 }, { |
|
127 key: "selectFake", |
|
128 value: function selectFake() { |
|
129 var _this = this; |
|
130 |
|
131 var fakeElem = this.createFakeElement(); |
|
132 |
|
133 this.fakeHandlerCallback = function () { |
|
134 return _this.removeFake(); |
|
135 }; |
|
136 |
|
137 this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true; |
|
138 this.container.appendChild(fakeElem); |
|
139 this.selectedText = select_default()(fakeElem); |
|
140 this.copyText(); |
|
141 this.removeFake(); |
|
142 } |
|
143 /** |
|
144 * Only removes the fake element after another click event, that way |
|
145 * a user can hit `Ctrl+C` to copy because selection still exists. |
|
146 */ |
|
147 |
|
148 }, { |
|
149 key: "removeFake", |
|
150 value: function removeFake() { |
|
151 if (this.fakeHandler) { |
|
152 this.container.removeEventListener('click', this.fakeHandlerCallback); |
|
153 this.fakeHandler = null; |
|
154 this.fakeHandlerCallback = null; |
|
155 } |
|
156 |
|
157 if (this.fakeElem) { |
|
158 this.container.removeChild(this.fakeElem); |
|
159 this.fakeElem = null; |
|
160 } |
|
161 } |
|
162 /** |
|
163 * Selects the content from element passed on `target` property. |
|
164 */ |
|
165 |
|
166 }, { |
|
167 key: "selectTarget", |
|
168 value: function selectTarget() { |
|
169 this.selectedText = select_default()(this.target); |
|
170 this.copyText(); |
|
171 } |
|
172 /** |
|
173 * Executes the copy operation based on the current selection. |
|
174 */ |
|
175 |
|
176 }, { |
|
177 key: "copyText", |
|
178 value: function copyText() { |
|
179 var succeeded; |
|
180 |
|
181 try { |
|
182 succeeded = document.execCommand(this.action); |
|
183 } catch (err) { |
|
184 succeeded = false; |
|
185 } |
|
186 |
|
187 this.handleResult(succeeded); |
|
188 } |
|
189 /** |
|
190 * Fires an event based on the copy operation result. |
|
191 * @param {Boolean} succeeded |
|
192 */ |
|
193 |
|
194 }, { |
|
195 key: "handleResult", |
|
196 value: function handleResult(succeeded) { |
|
197 this.emitter.emit(succeeded ? 'success' : 'error', { |
|
198 action: this.action, |
|
199 text: this.selectedText, |
|
200 trigger: this.trigger, |
|
201 clearSelection: this.clearSelection.bind(this) |
|
202 }); |
|
203 } |
|
204 /** |
|
205 * Moves focus away from `target` and back to the trigger, removes current selection. |
|
206 */ |
|
207 |
|
208 }, { |
|
209 key: "clearSelection", |
|
210 value: function clearSelection() { |
|
211 if (this.trigger) { |
|
212 this.trigger.focus(); |
|
213 } |
|
214 |
|
215 document.activeElement.blur(); |
|
216 window.getSelection().removeAllRanges(); |
|
217 } |
|
218 /** |
|
219 * Sets the `action` to be performed which can be either 'copy' or 'cut'. |
|
220 * @param {String} action |
|
221 */ |
|
222 |
|
223 }, { |
|
224 key: "destroy", |
|
225 |
|
226 /** |
|
227 * Destroy lifecycle. |
|
228 */ |
|
229 value: function destroy() { |
|
230 this.removeFake(); |
|
231 } |
|
232 }, { |
|
233 key: "action", |
|
234 set: function set() { |
|
235 var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy'; |
|
236 this._action = action; |
|
237 |
|
238 if (this._action !== 'copy' && this._action !== 'cut') { |
|
239 throw new Error('Invalid "action" value, use either "copy" or "cut"'); |
|
240 } |
|
241 } |
|
242 /** |
|
243 * Gets the `action` property. |
|
244 * @return {String} |
|
245 */ |
|
246 , |
|
247 get: function get() { |
|
248 return this._action; |
|
249 } |
|
250 /** |
|
251 * Sets the `target` property using an element |
|
252 * that will be have its content copied. |
|
253 * @param {Element} target |
|
254 */ |
|
255 |
|
256 }, { |
|
257 key: "target", |
|
258 set: function set(target) { |
|
259 if (target !== undefined) { |
|
260 if (target && _typeof(target) === 'object' && target.nodeType === 1) { |
|
261 if (this.action === 'copy' && target.hasAttribute('disabled')) { |
|
262 throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); |
|
263 } |
|
264 |
|
265 if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { |
|
266 throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); |
|
267 } |
|
268 |
|
269 this._target = target; |
|
270 } else { |
|
271 throw new Error('Invalid "target" value, use a valid Element'); |
|
272 } |
|
273 } |
|
274 } |
|
275 /** |
|
276 * Gets the `target` property. |
|
277 * @return {String|HTMLElement} |
|
278 */ |
|
279 , |
|
280 get: function get() { |
|
281 return this._target; |
|
282 } |
|
283 }]); |
|
284 |
|
285 return ClipboardAction; |
|
286 }(); |
|
287 |
|
288 /* harmony default export */ var clipboard_action = (ClipboardAction); |
|
289 ;// CONCATENATED MODULE: ./src/clipboard.js |
180 ;// CONCATENATED MODULE: ./src/clipboard.js |
290 function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); } |
181 function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); } |
291 |
182 |
292 function clipboard_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
183 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
293 |
184 |
294 function clipboard_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); } } |
185 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); } } |
295 |
186 |
296 function clipboard_createClass(Constructor, protoProps, staticProps) { if (protoProps) clipboard_defineProperties(Constructor.prototype, protoProps); if (staticProps) clipboard_defineProperties(Constructor, staticProps); return Constructor; } |
187 function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } |
297 |
188 |
298 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); } |
189 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); } |
299 |
190 |
300 function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } |
191 function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } |
301 |
192 |