95 /******/ // __webpack_public_path__ |
95 /******/ // __webpack_public_path__ |
96 /******/ __webpack_require__.p = ""; |
96 /******/ __webpack_require__.p = ""; |
97 /******/ |
97 /******/ |
98 /******/ |
98 /******/ |
99 /******/ // Load entry module and return exports |
99 /******/ // Load entry module and return exports |
100 /******/ return __webpack_require__(__webpack_require__.s = 0); |
100 /******/ return __webpack_require__(__webpack_require__.s = 6); |
101 /******/ }) |
101 /******/ }) |
102 /************************************************************************/ |
102 /************************************************************************/ |
103 /******/ ([ |
103 /******/ ([ |
104 /* 0 */ |
104 /* 0 */ |
105 /***/ (function(module, exports, __webpack_require__) { |
105 /***/ (function(module, exports) { |
106 |
106 |
107 "use strict"; |
107 function select(element) { |
108 |
108 var selectedText; |
109 |
109 |
110 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; |
110 if (element.nodeName === 'SELECT') { |
111 |
111 element.focus(); |
112 var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
112 |
113 |
113 selectedText = element.value; |
114 var _clipboardAction = __webpack_require__(1); |
114 } |
115 |
115 else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { |
116 var _clipboardAction2 = _interopRequireDefault(_clipboardAction); |
116 var isReadOnly = element.hasAttribute('readonly'); |
117 |
117 |
118 var _tinyEmitter = __webpack_require__(3); |
118 if (!isReadOnly) { |
119 |
119 element.setAttribute('readonly', ''); |
120 var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter); |
120 } |
121 |
121 |
122 var _goodListener = __webpack_require__(4); |
122 element.select(); |
123 |
123 element.setSelectionRange(0, element.value.length); |
124 var _goodListener2 = _interopRequireDefault(_goodListener); |
124 |
125 |
125 if (!isReadOnly) { |
126 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
126 element.removeAttribute('readonly'); |
127 |
127 } |
128 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
128 |
129 |
129 selectedText = element.value; |
130 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } |
130 } |
131 |
131 else { |
132 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } |
132 if (element.hasAttribute('contenteditable')) { |
133 |
133 element.focus(); |
134 /** |
134 } |
135 * Base class which takes one or more elements, adds event listeners to them, |
135 |
136 * and instantiates a new `ClipboardAction` on each click. |
136 var selection = window.getSelection(); |
137 */ |
137 var range = document.createRange(); |
138 var Clipboard = function (_Emitter) { |
138 |
139 _inherits(Clipboard, _Emitter); |
139 range.selectNodeContents(element); |
140 |
140 selection.removeAllRanges(); |
141 /** |
141 selection.addRange(range); |
142 * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
142 |
143 * @param {Object} options |
143 selectedText = selection.toString(); |
144 */ |
144 } |
145 function Clipboard(trigger, options) { |
145 |
146 _classCallCheck(this, Clipboard); |
146 return selectedText; |
147 |
147 } |
148 var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this)); |
148 |
149 |
149 module.exports = select; |
150 _this.resolveOptions(options); |
150 |
151 _this.listenClick(trigger); |
|
152 return _this; |
|
153 } |
|
154 |
|
155 /** |
|
156 * Defines if attributes would be resolved using internal setter functions |
|
157 * or custom functions that were passed in the constructor. |
|
158 * @param {Object} options |
|
159 */ |
|
160 |
|
161 |
|
162 _createClass(Clipboard, [{ |
|
163 key: 'resolveOptions', |
|
164 value: function resolveOptions() { |
|
165 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
166 |
|
167 this.action = typeof options.action === 'function' ? options.action : this.defaultAction; |
|
168 this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; |
|
169 this.text = typeof options.text === 'function' ? options.text : this.defaultText; |
|
170 this.container = _typeof(options.container) === 'object' ? options.container : document.body; |
|
171 } |
|
172 |
|
173 /** |
|
174 * Adds a click event listener to the passed trigger. |
|
175 * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
|
176 */ |
|
177 |
|
178 }, { |
|
179 key: 'listenClick', |
|
180 value: function listenClick(trigger) { |
|
181 var _this2 = this; |
|
182 |
|
183 this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) { |
|
184 return _this2.onClick(e); |
|
185 }); |
|
186 } |
|
187 |
|
188 /** |
|
189 * Defines a new `ClipboardAction` on each click event. |
|
190 * @param {Event} e |
|
191 */ |
|
192 |
|
193 }, { |
|
194 key: 'onClick', |
|
195 value: function onClick(e) { |
|
196 var trigger = e.delegateTarget || e.currentTarget; |
|
197 |
|
198 if (this.clipboardAction) { |
|
199 this.clipboardAction = null; |
|
200 } |
|
201 |
|
202 this.clipboardAction = new _clipboardAction2.default({ |
|
203 action: this.action(trigger), |
|
204 target: this.target(trigger), |
|
205 text: this.text(trigger), |
|
206 container: this.container, |
|
207 trigger: trigger, |
|
208 emitter: this |
|
209 }); |
|
210 } |
|
211 |
|
212 /** |
|
213 * Default `action` lookup function. |
|
214 * @param {Element} trigger |
|
215 */ |
|
216 |
|
217 }, { |
|
218 key: 'defaultAction', |
|
219 value: function defaultAction(trigger) { |
|
220 return getAttributeValue('action', trigger); |
|
221 } |
|
222 |
|
223 /** |
|
224 * Default `target` lookup function. |
|
225 * @param {Element} trigger |
|
226 */ |
|
227 |
|
228 }, { |
|
229 key: 'defaultTarget', |
|
230 value: function defaultTarget(trigger) { |
|
231 var selector = getAttributeValue('target', trigger); |
|
232 |
|
233 if (selector) { |
|
234 return document.querySelector(selector); |
|
235 } |
|
236 } |
|
237 |
|
238 /** |
|
239 * Returns the support of the given action, or all actions if no action is |
|
240 * given. |
|
241 * @param {String} [action] |
|
242 */ |
|
243 |
|
244 }, { |
|
245 key: 'defaultText', |
|
246 |
|
247 |
|
248 /** |
|
249 * Default `text` lookup function. |
|
250 * @param {Element} trigger |
|
251 */ |
|
252 value: function defaultText(trigger) { |
|
253 return getAttributeValue('text', trigger); |
|
254 } |
|
255 |
|
256 /** |
|
257 * Destroy lifecycle. |
|
258 */ |
|
259 |
|
260 }, { |
|
261 key: 'destroy', |
|
262 value: function destroy() { |
|
263 this.listener.destroy(); |
|
264 |
|
265 if (this.clipboardAction) { |
|
266 this.clipboardAction.destroy(); |
|
267 this.clipboardAction = null; |
|
268 } |
|
269 } |
|
270 }], [{ |
|
271 key: 'isSupported', |
|
272 value: function isSupported() { |
|
273 var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; |
|
274 |
|
275 var actions = typeof action === 'string' ? [action] : action; |
|
276 var support = !!document.queryCommandSupported; |
|
277 |
|
278 actions.forEach(function (action) { |
|
279 support = support && !!document.queryCommandSupported(action); |
|
280 }); |
|
281 |
|
282 return support; |
|
283 } |
|
284 }]); |
|
285 |
|
286 return Clipboard; |
|
287 }(_tinyEmitter2.default); |
|
288 |
|
289 /** |
|
290 * Helper function to retrieve attribute value. |
|
291 * @param {String} suffix |
|
292 * @param {Element} element |
|
293 */ |
|
294 |
|
295 |
|
296 function getAttributeValue(suffix, element) { |
|
297 var attribute = 'data-clipboard-' + suffix; |
|
298 |
|
299 if (!element.hasAttribute(attribute)) { |
|
300 return; |
|
301 } |
|
302 |
|
303 return element.getAttribute(attribute); |
|
304 } |
|
305 |
|
306 module.exports = Clipboard; |
|
307 |
151 |
308 /***/ }), |
152 /***/ }), |
309 /* 1 */ |
153 /* 1 */ |
|
154 /***/ (function(module, exports) { |
|
155 |
|
156 function E () { |
|
157 // Keep this empty so it's easier to inherit from |
|
158 // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) |
|
159 } |
|
160 |
|
161 E.prototype = { |
|
162 on: function (name, callback, ctx) { |
|
163 var e = this.e || (this.e = {}); |
|
164 |
|
165 (e[name] || (e[name] = [])).push({ |
|
166 fn: callback, |
|
167 ctx: ctx |
|
168 }); |
|
169 |
|
170 return this; |
|
171 }, |
|
172 |
|
173 once: function (name, callback, ctx) { |
|
174 var self = this; |
|
175 function listener () { |
|
176 self.off(name, listener); |
|
177 callback.apply(ctx, arguments); |
|
178 }; |
|
179 |
|
180 listener._ = callback |
|
181 return this.on(name, listener, ctx); |
|
182 }, |
|
183 |
|
184 emit: function (name) { |
|
185 var data = [].slice.call(arguments, 1); |
|
186 var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); |
|
187 var i = 0; |
|
188 var len = evtArr.length; |
|
189 |
|
190 for (i; i < len; i++) { |
|
191 evtArr[i].fn.apply(evtArr[i].ctx, data); |
|
192 } |
|
193 |
|
194 return this; |
|
195 }, |
|
196 |
|
197 off: function (name, callback) { |
|
198 var e = this.e || (this.e = {}); |
|
199 var evts = e[name]; |
|
200 var liveEvents = []; |
|
201 |
|
202 if (evts && callback) { |
|
203 for (var i = 0, len = evts.length; i < len; i++) { |
|
204 if (evts[i].fn !== callback && evts[i].fn._ !== callback) |
|
205 liveEvents.push(evts[i]); |
|
206 } |
|
207 } |
|
208 |
|
209 // Remove event from queue to prevent memory leak |
|
210 // Suggested by https://github.com/lazd |
|
211 // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 |
|
212 |
|
213 (liveEvents.length) |
|
214 ? e[name] = liveEvents |
|
215 : delete e[name]; |
|
216 |
|
217 return this; |
|
218 } |
|
219 }; |
|
220 |
|
221 module.exports = E; |
|
222 module.exports.TinyEmitter = E; |
|
223 |
|
224 |
|
225 /***/ }), |
|
226 /* 2 */ |
310 /***/ (function(module, exports, __webpack_require__) { |
227 /***/ (function(module, exports, __webpack_require__) { |
311 |
228 |
|
229 var is = __webpack_require__(3); |
|
230 var delegate = __webpack_require__(4); |
|
231 |
|
232 /** |
|
233 * Validates all params and calls the right |
|
234 * listener function based on its target type. |
|
235 * |
|
236 * @param {String|HTMLElement|HTMLCollection|NodeList} target |
|
237 * @param {String} type |
|
238 * @param {Function} callback |
|
239 * @return {Object} |
|
240 */ |
|
241 function listen(target, type, callback) { |
|
242 if (!target && !type && !callback) { |
|
243 throw new Error('Missing required arguments'); |
|
244 } |
|
245 |
|
246 if (!is.string(type)) { |
|
247 throw new TypeError('Second argument must be a String'); |
|
248 } |
|
249 |
|
250 if (!is.fn(callback)) { |
|
251 throw new TypeError('Third argument must be a Function'); |
|
252 } |
|
253 |
|
254 if (is.node(target)) { |
|
255 return listenNode(target, type, callback); |
|
256 } |
|
257 else if (is.nodeList(target)) { |
|
258 return listenNodeList(target, type, callback); |
|
259 } |
|
260 else if (is.string(target)) { |
|
261 return listenSelector(target, type, callback); |
|
262 } |
|
263 else { |
|
264 throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList'); |
|
265 } |
|
266 } |
|
267 |
|
268 /** |
|
269 * Adds an event listener to a HTML element |
|
270 * and returns a remove listener function. |
|
271 * |
|
272 * @param {HTMLElement} node |
|
273 * @param {String} type |
|
274 * @param {Function} callback |
|
275 * @return {Object} |
|
276 */ |
|
277 function listenNode(node, type, callback) { |
|
278 node.addEventListener(type, callback); |
|
279 |
|
280 return { |
|
281 destroy: function() { |
|
282 node.removeEventListener(type, callback); |
|
283 } |
|
284 } |
|
285 } |
|
286 |
|
287 /** |
|
288 * Add an event listener to a list of HTML elements |
|
289 * and returns a remove listener function. |
|
290 * |
|
291 * @param {NodeList|HTMLCollection} nodeList |
|
292 * @param {String} type |
|
293 * @param {Function} callback |
|
294 * @return {Object} |
|
295 */ |
|
296 function listenNodeList(nodeList, type, callback) { |
|
297 Array.prototype.forEach.call(nodeList, function(node) { |
|
298 node.addEventListener(type, callback); |
|
299 }); |
|
300 |
|
301 return { |
|
302 destroy: function() { |
|
303 Array.prototype.forEach.call(nodeList, function(node) { |
|
304 node.removeEventListener(type, callback); |
|
305 }); |
|
306 } |
|
307 } |
|
308 } |
|
309 |
|
310 /** |
|
311 * Add an event listener to a selector |
|
312 * and returns a remove listener function. |
|
313 * |
|
314 * @param {String} selector |
|
315 * @param {String} type |
|
316 * @param {Function} callback |
|
317 * @return {Object} |
|
318 */ |
|
319 function listenSelector(selector, type, callback) { |
|
320 return delegate(document.body, selector, type, callback); |
|
321 } |
|
322 |
|
323 module.exports = listen; |
|
324 |
|
325 |
|
326 /***/ }), |
|
327 /* 3 */ |
|
328 /***/ (function(module, exports) { |
|
329 |
|
330 /** |
|
331 * Check if argument is a HTML element. |
|
332 * |
|
333 * @param {Object} value |
|
334 * @return {Boolean} |
|
335 */ |
|
336 exports.node = function(value) { |
|
337 return value !== undefined |
|
338 && value instanceof HTMLElement |
|
339 && value.nodeType === 1; |
|
340 }; |
|
341 |
|
342 /** |
|
343 * Check if argument is a list of HTML elements. |
|
344 * |
|
345 * @param {Object} value |
|
346 * @return {Boolean} |
|
347 */ |
|
348 exports.nodeList = function(value) { |
|
349 var type = Object.prototype.toString.call(value); |
|
350 |
|
351 return value !== undefined |
|
352 && (type === '[object NodeList]' || type === '[object HTMLCollection]') |
|
353 && ('length' in value) |
|
354 && (value.length === 0 || exports.node(value[0])); |
|
355 }; |
|
356 |
|
357 /** |
|
358 * Check if argument is a string. |
|
359 * |
|
360 * @param {Object} value |
|
361 * @return {Boolean} |
|
362 */ |
|
363 exports.string = function(value) { |
|
364 return typeof value === 'string' |
|
365 || value instanceof String; |
|
366 }; |
|
367 |
|
368 /** |
|
369 * Check if argument is a function. |
|
370 * |
|
371 * @param {Object} value |
|
372 * @return {Boolean} |
|
373 */ |
|
374 exports.fn = function(value) { |
|
375 var type = Object.prototype.toString.call(value); |
|
376 |
|
377 return type === '[object Function]'; |
|
378 }; |
|
379 |
|
380 |
|
381 /***/ }), |
|
382 /* 4 */ |
|
383 /***/ (function(module, exports, __webpack_require__) { |
|
384 |
|
385 var closest = __webpack_require__(5); |
|
386 |
|
387 /** |
|
388 * Delegates event to a selector. |
|
389 * |
|
390 * @param {Element} element |
|
391 * @param {String} selector |
|
392 * @param {String} type |
|
393 * @param {Function} callback |
|
394 * @param {Boolean} useCapture |
|
395 * @return {Object} |
|
396 */ |
|
397 function _delegate(element, selector, type, callback, useCapture) { |
|
398 var listenerFn = listener.apply(this, arguments); |
|
399 |
|
400 element.addEventListener(type, listenerFn, useCapture); |
|
401 |
|
402 return { |
|
403 destroy: function() { |
|
404 element.removeEventListener(type, listenerFn, useCapture); |
|
405 } |
|
406 } |
|
407 } |
|
408 |
|
409 /** |
|
410 * Delegates event to a selector. |
|
411 * |
|
412 * @param {Element|String|Array} [elements] |
|
413 * @param {String} selector |
|
414 * @param {String} type |
|
415 * @param {Function} callback |
|
416 * @param {Boolean} useCapture |
|
417 * @return {Object} |
|
418 */ |
|
419 function delegate(elements, selector, type, callback, useCapture) { |
|
420 // Handle the regular Element usage |
|
421 if (typeof elements.addEventListener === 'function') { |
|
422 return _delegate.apply(null, arguments); |
|
423 } |
|
424 |
|
425 // Handle Element-less usage, it defaults to global delegation |
|
426 if (typeof type === 'function') { |
|
427 // Use `document` as the first parameter, then apply arguments |
|
428 // This is a short way to .unshift `arguments` without running into deoptimizations |
|
429 return _delegate.bind(null, document).apply(null, arguments); |
|
430 } |
|
431 |
|
432 // Handle Selector-based usage |
|
433 if (typeof elements === 'string') { |
|
434 elements = document.querySelectorAll(elements); |
|
435 } |
|
436 |
|
437 // Handle Array-like based usage |
|
438 return Array.prototype.map.call(elements, function (element) { |
|
439 return _delegate(element, selector, type, callback, useCapture); |
|
440 }); |
|
441 } |
|
442 |
|
443 /** |
|
444 * Finds closest match and invokes callback. |
|
445 * |
|
446 * @param {Element} element |
|
447 * @param {String} selector |
|
448 * @param {String} type |
|
449 * @param {Function} callback |
|
450 * @return {Function} |
|
451 */ |
|
452 function listener(element, selector, type, callback) { |
|
453 return function(e) { |
|
454 e.delegateTarget = closest(e.target, selector); |
|
455 |
|
456 if (e.delegateTarget) { |
|
457 callback.call(element, e); |
|
458 } |
|
459 } |
|
460 } |
|
461 |
|
462 module.exports = delegate; |
|
463 |
|
464 |
|
465 /***/ }), |
|
466 /* 5 */ |
|
467 /***/ (function(module, exports) { |
|
468 |
|
469 var DOCUMENT_NODE_TYPE = 9; |
|
470 |
|
471 /** |
|
472 * A polyfill for Element.matches() |
|
473 */ |
|
474 if (typeof Element !== 'undefined' && !Element.prototype.matches) { |
|
475 var proto = Element.prototype; |
|
476 |
|
477 proto.matches = proto.matchesSelector || |
|
478 proto.mozMatchesSelector || |
|
479 proto.msMatchesSelector || |
|
480 proto.oMatchesSelector || |
|
481 proto.webkitMatchesSelector; |
|
482 } |
|
483 |
|
484 /** |
|
485 * Finds the closest parent that matches a selector. |
|
486 * |
|
487 * @param {Element} element |
|
488 * @param {String} selector |
|
489 * @return {Function} |
|
490 */ |
|
491 function closest (element, selector) { |
|
492 while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { |
|
493 if (typeof element.matches === 'function' && |
|
494 element.matches(selector)) { |
|
495 return element; |
|
496 } |
|
497 element = element.parentNode; |
|
498 } |
|
499 } |
|
500 |
|
501 module.exports = closest; |
|
502 |
|
503 |
|
504 /***/ }), |
|
505 /* 6 */ |
|
506 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
507 |
312 "use strict"; |
508 "use strict"; |
313 |
509 __webpack_require__.r(__webpack_exports__); |
314 |
510 |
|
511 // EXTERNAL MODULE: ./node_modules/select/src/select.js |
|
512 var src_select = __webpack_require__(0); |
|
513 var select_default = /*#__PURE__*/__webpack_require__.n(src_select); |
|
514 |
|
515 // CONCATENATED MODULE: ./src/clipboard-action.js |
315 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; |
516 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; |
316 |
517 |
317 var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
518 var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
318 |
519 |
319 var _select = __webpack_require__(2); |
|
320 |
|
321 var _select2 = _interopRequireDefault(_select); |
|
322 |
|
323 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
|
324 |
|
325 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
520 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
521 |
|
522 |
326 |
523 |
327 /** |
524 /** |
328 * Inner class which performs selection from either `text` or `target` |
525 * Inner class which performs selection from either `text` or `target` |
329 * properties and then executes copy or cut operations. |
526 * properties and then executes copy or cut operations. |
330 */ |
527 */ |
331 var ClipboardAction = function () { |
528 |
|
529 var clipboard_action_ClipboardAction = function () { |
332 /** |
530 /** |
333 * @param {Object} options |
531 * @param {Object} options |
334 */ |
532 */ |
335 function ClipboardAction(options) { |
533 function ClipboardAction(options) { |
336 _classCallCheck(this, ClipboardAction); |
534 _classCallCheck(this, ClipboardAction); |
569 }]); |
767 }]); |
570 |
768 |
571 return ClipboardAction; |
769 return ClipboardAction; |
572 }(); |
770 }(); |
573 |
771 |
574 module.exports = ClipboardAction; |
772 /* harmony default export */ var clipboard_action = (clipboard_action_ClipboardAction); |
575 |
773 // EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js |
576 /***/ }), |
774 var tiny_emitter = __webpack_require__(1); |
577 /* 2 */ |
775 var tiny_emitter_default = /*#__PURE__*/__webpack_require__.n(tiny_emitter); |
578 /***/ (function(module, exports) { |
776 |
579 |
777 // EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js |
580 function select(element) { |
778 var listen = __webpack_require__(2); |
581 var selectedText; |
779 var listen_default = /*#__PURE__*/__webpack_require__.n(listen); |
582 |
780 |
583 if (element.nodeName === 'SELECT') { |
781 // CONCATENATED MODULE: ./src/clipboard.js |
584 element.focus(); |
782 var clipboard_typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; |
585 |
783 |
586 selectedText = element.value; |
784 var clipboard_createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
587 } |
785 |
588 else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { |
786 function clipboard_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
589 var isReadOnly = element.hasAttribute('readonly'); |
787 |
590 |
788 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } |
591 if (!isReadOnly) { |
789 |
592 element.setAttribute('readonly', ''); |
790 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } |
593 } |
791 |
594 |
792 |
595 element.select(); |
793 |
596 element.setSelectionRange(0, element.value.length); |
794 |
597 |
795 |
598 if (!isReadOnly) { |
796 /** |
599 element.removeAttribute('readonly'); |
797 * Base class which takes one or more elements, adds event listeners to them, |
600 } |
798 * and instantiates a new `ClipboardAction` on each click. |
601 |
799 */ |
602 selectedText = element.value; |
800 |
603 } |
801 var clipboard_Clipboard = function (_Emitter) { |
604 else { |
802 _inherits(Clipboard, _Emitter); |
605 if (element.hasAttribute('contenteditable')) { |
803 |
606 element.focus(); |
804 /** |
607 } |
805 * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
608 |
806 * @param {Object} options |
609 var selection = window.getSelection(); |
807 */ |
610 var range = document.createRange(); |
808 function Clipboard(trigger, options) { |
611 |
809 clipboard_classCallCheck(this, Clipboard); |
612 range.selectNodeContents(element); |
810 |
613 selection.removeAllRanges(); |
811 var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this)); |
614 selection.addRange(range); |
812 |
615 |
813 _this.resolveOptions(options); |
616 selectedText = selection.toString(); |
814 _this.listenClick(trigger); |
617 } |
815 return _this; |
618 |
816 } |
619 return selectedText; |
817 |
620 } |
818 /** |
621 |
819 * Defines if attributes would be resolved using internal setter functions |
622 module.exports = select; |
820 * or custom functions that were passed in the constructor. |
623 |
821 * @param {Object} options |
624 |
822 */ |
625 /***/ }), |
823 |
626 /* 3 */ |
824 |
627 /***/ (function(module, exports) { |
825 clipboard_createClass(Clipboard, [{ |
628 |
826 key: 'resolveOptions', |
629 function E () { |
827 value: function resolveOptions() { |
630 // Keep this empty so it's easier to inherit from |
828 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
631 // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) |
829 |
632 } |
830 this.action = typeof options.action === 'function' ? options.action : this.defaultAction; |
633 |
831 this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; |
634 E.prototype = { |
832 this.text = typeof options.text === 'function' ? options.text : this.defaultText; |
635 on: function (name, callback, ctx) { |
833 this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body; |
636 var e = this.e || (this.e = {}); |
834 } |
637 |
835 |
638 (e[name] || (e[name] = [])).push({ |
836 /** |
639 fn: callback, |
837 * Adds a click event listener to the passed trigger. |
640 ctx: ctx |
838 * @param {String|HTMLElement|HTMLCollection|NodeList} trigger |
641 }); |
839 */ |
642 |
840 |
643 return this; |
841 }, { |
644 }, |
842 key: 'listenClick', |
645 |
843 value: function listenClick(trigger) { |
646 once: function (name, callback, ctx) { |
844 var _this2 = this; |
647 var self = this; |
845 |
648 function listener () { |
846 this.listener = listen_default()(trigger, 'click', function (e) { |
649 self.off(name, listener); |
847 return _this2.onClick(e); |
650 callback.apply(ctx, arguments); |
|
651 }; |
|
652 |
|
653 listener._ = callback |
|
654 return this.on(name, listener, ctx); |
|
655 }, |
|
656 |
|
657 emit: function (name) { |
|
658 var data = [].slice.call(arguments, 1); |
|
659 var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); |
|
660 var i = 0; |
|
661 var len = evtArr.length; |
|
662 |
|
663 for (i; i < len; i++) { |
|
664 evtArr[i].fn.apply(evtArr[i].ctx, data); |
|
665 } |
|
666 |
|
667 return this; |
|
668 }, |
|
669 |
|
670 off: function (name, callback) { |
|
671 var e = this.e || (this.e = {}); |
|
672 var evts = e[name]; |
|
673 var liveEvents = []; |
|
674 |
|
675 if (evts && callback) { |
|
676 for (var i = 0, len = evts.length; i < len; i++) { |
|
677 if (evts[i].fn !== callback && evts[i].fn._ !== callback) |
|
678 liveEvents.push(evts[i]); |
|
679 } |
|
680 } |
|
681 |
|
682 // Remove event from queue to prevent memory leak |
|
683 // Suggested by https://github.com/lazd |
|
684 // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 |
|
685 |
|
686 (liveEvents.length) |
|
687 ? e[name] = liveEvents |
|
688 : delete e[name]; |
|
689 |
|
690 return this; |
|
691 } |
|
692 }; |
|
693 |
|
694 module.exports = E; |
|
695 |
|
696 |
|
697 /***/ }), |
|
698 /* 4 */ |
|
699 /***/ (function(module, exports, __webpack_require__) { |
|
700 |
|
701 var is = __webpack_require__(5); |
|
702 var delegate = __webpack_require__(6); |
|
703 |
|
704 /** |
|
705 * Validates all params and calls the right |
|
706 * listener function based on its target type. |
|
707 * |
|
708 * @param {String|HTMLElement|HTMLCollection|NodeList} target |
|
709 * @param {String} type |
|
710 * @param {Function} callback |
|
711 * @return {Object} |
|
712 */ |
|
713 function listen(target, type, callback) { |
|
714 if (!target && !type && !callback) { |
|
715 throw new Error('Missing required arguments'); |
|
716 } |
|
717 |
|
718 if (!is.string(type)) { |
|
719 throw new TypeError('Second argument must be a String'); |
|
720 } |
|
721 |
|
722 if (!is.fn(callback)) { |
|
723 throw new TypeError('Third argument must be a Function'); |
|
724 } |
|
725 |
|
726 if (is.node(target)) { |
|
727 return listenNode(target, type, callback); |
|
728 } |
|
729 else if (is.nodeList(target)) { |
|
730 return listenNodeList(target, type, callback); |
|
731 } |
|
732 else if (is.string(target)) { |
|
733 return listenSelector(target, type, callback); |
|
734 } |
|
735 else { |
|
736 throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList'); |
|
737 } |
|
738 } |
|
739 |
|
740 /** |
|
741 * Adds an event listener to a HTML element |
|
742 * and returns a remove listener function. |
|
743 * |
|
744 * @param {HTMLElement} node |
|
745 * @param {String} type |
|
746 * @param {Function} callback |
|
747 * @return {Object} |
|
748 */ |
|
749 function listenNode(node, type, callback) { |
|
750 node.addEventListener(type, callback); |
|
751 |
|
752 return { |
|
753 destroy: function() { |
|
754 node.removeEventListener(type, callback); |
|
755 } |
|
756 } |
|
757 } |
|
758 |
|
759 /** |
|
760 * Add an event listener to a list of HTML elements |
|
761 * and returns a remove listener function. |
|
762 * |
|
763 * @param {NodeList|HTMLCollection} nodeList |
|
764 * @param {String} type |
|
765 * @param {Function} callback |
|
766 * @return {Object} |
|
767 */ |
|
768 function listenNodeList(nodeList, type, callback) { |
|
769 Array.prototype.forEach.call(nodeList, function(node) { |
|
770 node.addEventListener(type, callback); |
|
771 }); |
|
772 |
|
773 return { |
|
774 destroy: function() { |
|
775 Array.prototype.forEach.call(nodeList, function(node) { |
|
776 node.removeEventListener(type, callback); |
|
777 }); |
848 }); |
778 } |
849 } |
779 } |
850 |
780 } |
851 /** |
781 |
852 * Defines a new `ClipboardAction` on each click event. |
782 /** |
853 * @param {Event} e |
783 * Add an event listener to a selector |
854 */ |
784 * and returns a remove listener function. |
855 |
785 * |
856 }, { |
786 * @param {String} selector |
857 key: 'onClick', |
787 * @param {String} type |
858 value: function onClick(e) { |
788 * @param {Function} callback |
859 var trigger = e.delegateTarget || e.currentTarget; |
789 * @return {Object} |
860 |
790 */ |
861 if (this.clipboardAction) { |
791 function listenSelector(selector, type, callback) { |
862 this.clipboardAction = null; |
792 return delegate(document.body, selector, type, callback); |
863 } |
793 } |
864 |
794 |
865 this.clipboardAction = new clipboard_action({ |
795 module.exports = listen; |
866 action: this.action(trigger), |
796 |
867 target: this.target(trigger), |
797 |
868 text: this.text(trigger), |
798 /***/ }), |
869 container: this.container, |
799 /* 5 */ |
870 trigger: trigger, |
800 /***/ (function(module, exports) { |
871 emitter: this |
801 |
872 }); |
802 /** |
873 } |
803 * Check if argument is a HTML element. |
874 |
804 * |
875 /** |
805 * @param {Object} value |
876 * Default `action` lookup function. |
806 * @return {Boolean} |
877 * @param {Element} trigger |
807 */ |
878 */ |
808 exports.node = function(value) { |
879 |
809 return value !== undefined |
880 }, { |
810 && value instanceof HTMLElement |
881 key: 'defaultAction', |
811 && value.nodeType === 1; |
882 value: function defaultAction(trigger) { |
812 }; |
883 return getAttributeValue('action', trigger); |
813 |
884 } |
814 /** |
885 |
815 * Check if argument is a list of HTML elements. |
886 /** |
816 * |
887 * Default `target` lookup function. |
817 * @param {Object} value |
888 * @param {Element} trigger |
818 * @return {Boolean} |
889 */ |
819 */ |
890 |
820 exports.nodeList = function(value) { |
891 }, { |
821 var type = Object.prototype.toString.call(value); |
892 key: 'defaultTarget', |
822 |
893 value: function defaultTarget(trigger) { |
823 return value !== undefined |
894 var selector = getAttributeValue('target', trigger); |
824 && (type === '[object NodeList]' || type === '[object HTMLCollection]') |
895 |
825 && ('length' in value) |
896 if (selector) { |
826 && (value.length === 0 || exports.node(value[0])); |
897 return document.querySelector(selector); |
827 }; |
898 } |
828 |
899 } |
829 /** |
900 |
830 * Check if argument is a string. |
901 /** |
831 * |
902 * Returns the support of the given action, or all actions if no action is |
832 * @param {Object} value |
903 * given. |
833 * @return {Boolean} |
904 * @param {String} [action] |
834 */ |
905 */ |
835 exports.string = function(value) { |
906 |
836 return typeof value === 'string' |
907 }, { |
837 || value instanceof String; |
908 key: 'defaultText', |
838 }; |
909 |
839 |
910 |
840 /** |
911 /** |
841 * Check if argument is a function. |
912 * Default `text` lookup function. |
842 * |
913 * @param {Element} trigger |
843 * @param {Object} value |
914 */ |
844 * @return {Boolean} |
915 value: function defaultText(trigger) { |
845 */ |
916 return getAttributeValue('text', trigger); |
846 exports.fn = function(value) { |
917 } |
847 var type = Object.prototype.toString.call(value); |
918 |
848 |
919 /** |
849 return type === '[object Function]'; |
920 * Destroy lifecycle. |
850 }; |
921 */ |
851 |
922 |
852 |
923 }, { |
853 /***/ }), |
924 key: 'destroy', |
854 /* 6 */ |
925 value: function destroy() { |
855 /***/ (function(module, exports, __webpack_require__) { |
926 this.listener.destroy(); |
856 |
927 |
857 var closest = __webpack_require__(7); |
928 if (this.clipboardAction) { |
858 |
929 this.clipboardAction.destroy(); |
859 /** |
930 this.clipboardAction = null; |
860 * Delegates event to a selector. |
931 } |
861 * |
932 } |
|
933 }], [{ |
|
934 key: 'isSupported', |
|
935 value: function isSupported() { |
|
936 var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; |
|
937 |
|
938 var actions = typeof action === 'string' ? [action] : action; |
|
939 var support = !!document.queryCommandSupported; |
|
940 |
|
941 actions.forEach(function (action) { |
|
942 support = support && !!document.queryCommandSupported(action); |
|
943 }); |
|
944 |
|
945 return support; |
|
946 } |
|
947 }]); |
|
948 |
|
949 return Clipboard; |
|
950 }(tiny_emitter_default.a); |
|
951 |
|
952 /** |
|
953 * Helper function to retrieve attribute value. |
|
954 * @param {String} suffix |
862 * @param {Element} element |
955 * @param {Element} element |
863 * @param {String} selector |
956 */ |
864 * @param {String} type |
957 |
865 * @param {Function} callback |
958 |
866 * @param {Boolean} useCapture |
959 function getAttributeValue(suffix, element) { |
867 * @return {Object} |
960 var attribute = 'data-clipboard-' + suffix; |
868 */ |
961 |
869 function _delegate(element, selector, type, callback, useCapture) { |
962 if (!element.hasAttribute(attribute)) { |
870 var listenerFn = listener.apply(this, arguments); |
963 return; |
871 |
964 } |
872 element.addEventListener(type, listenerFn, useCapture); |
965 |
873 |
966 return element.getAttribute(attribute); |
874 return { |
967 } |
875 destroy: function() { |
968 |
876 element.removeEventListener(type, listenerFn, useCapture); |
969 /* harmony default export */ var clipboard = __webpack_exports__["default"] = (clipboard_Clipboard); |
877 } |
|
878 } |
|
879 } |
|
880 |
|
881 /** |
|
882 * Delegates event to a selector. |
|
883 * |
|
884 * @param {Element|String|Array} [elements] |
|
885 * @param {String} selector |
|
886 * @param {String} type |
|
887 * @param {Function} callback |
|
888 * @param {Boolean} useCapture |
|
889 * @return {Object} |
|
890 */ |
|
891 function delegate(elements, selector, type, callback, useCapture) { |
|
892 // Handle the regular Element usage |
|
893 if (typeof elements.addEventListener === 'function') { |
|
894 return _delegate.apply(null, arguments); |
|
895 } |
|
896 |
|
897 // Handle Element-less usage, it defaults to global delegation |
|
898 if (typeof type === 'function') { |
|
899 // Use `document` as the first parameter, then apply arguments |
|
900 // This is a short way to .unshift `arguments` without running into deoptimizations |
|
901 return _delegate.bind(null, document).apply(null, arguments); |
|
902 } |
|
903 |
|
904 // Handle Selector-based usage |
|
905 if (typeof elements === 'string') { |
|
906 elements = document.querySelectorAll(elements); |
|
907 } |
|
908 |
|
909 // Handle Array-like based usage |
|
910 return Array.prototype.map.call(elements, function (element) { |
|
911 return _delegate(element, selector, type, callback, useCapture); |
|
912 }); |
|
913 } |
|
914 |
|
915 /** |
|
916 * Finds closest match and invokes callback. |
|
917 * |
|
918 * @param {Element} element |
|
919 * @param {String} selector |
|
920 * @param {String} type |
|
921 * @param {Function} callback |
|
922 * @return {Function} |
|
923 */ |
|
924 function listener(element, selector, type, callback) { |
|
925 return function(e) { |
|
926 e.delegateTarget = closest(e.target, selector); |
|
927 |
|
928 if (e.delegateTarget) { |
|
929 callback.call(element, e); |
|
930 } |
|
931 } |
|
932 } |
|
933 |
|
934 module.exports = delegate; |
|
935 |
|
936 |
|
937 /***/ }), |
|
938 /* 7 */ |
|
939 /***/ (function(module, exports) { |
|
940 |
|
941 var DOCUMENT_NODE_TYPE = 9; |
|
942 |
|
943 /** |
|
944 * A polyfill for Element.matches() |
|
945 */ |
|
946 if (typeof Element !== 'undefined' && !Element.prototype.matches) { |
|
947 var proto = Element.prototype; |
|
948 |
|
949 proto.matches = proto.matchesSelector || |
|
950 proto.mozMatchesSelector || |
|
951 proto.msMatchesSelector || |
|
952 proto.oMatchesSelector || |
|
953 proto.webkitMatchesSelector; |
|
954 } |
|
955 |
|
956 /** |
|
957 * Finds the closest parent that matches a selector. |
|
958 * |
|
959 * @param {Element} element |
|
960 * @param {String} selector |
|
961 * @return {Function} |
|
962 */ |
|
963 function closest (element, selector) { |
|
964 while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { |
|
965 if (typeof element.matches === 'function' && |
|
966 element.matches(selector)) { |
|
967 return element; |
|
968 } |
|
969 element = element.parentNode; |
|
970 } |
|
971 } |
|
972 |
|
973 module.exports = closest; |
|
974 |
|
975 |
970 |
976 /***/ }) |
971 /***/ }) |
977 /******/ ]); |
972 /******/ ])["default"]; |
978 }); |
973 }); |