93 ;// CONCATENATED MODULE: ./src/actions/copy.js |
93 ;// CONCATENATED MODULE: ./src/actions/copy.js |
94 |
94 |
95 |
95 |
96 |
96 |
97 /** |
97 /** |
|
98 * Create fake copy action wrapper using a fake element. |
|
99 * @param {String} target |
|
100 * @param {Object} options |
|
101 * @return {String} |
|
102 */ |
|
103 |
|
104 var fakeCopyAction = function fakeCopyAction(value, options) { |
|
105 var fakeElement = createFakeElement(value); |
|
106 options.container.appendChild(fakeElement); |
|
107 var selectedText = select_default()(fakeElement); |
|
108 command('copy'); |
|
109 fakeElement.remove(); |
|
110 return selectedText; |
|
111 }; |
|
112 /** |
98 * Copy action wrapper. |
113 * Copy action wrapper. |
99 * @param {String|HTMLElement} target |
114 * @param {String|HTMLElement} target |
100 * @param {Object} options |
115 * @param {Object} options |
101 * @return {String} |
116 * @return {String} |
102 */ |
117 */ |
|
118 |
103 |
119 |
104 var ClipboardActionCopy = function ClipboardActionCopy(target) { |
120 var ClipboardActionCopy = function ClipboardActionCopy(target) { |
105 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { |
121 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { |
106 container: document.body |
122 container: document.body |
107 }; |
123 }; |
108 var selectedText = ''; |
124 var selectedText = ''; |
109 |
125 |
110 if (typeof target === 'string') { |
126 if (typeof target === 'string') { |
111 var fakeElement = createFakeElement(target); |
127 selectedText = fakeCopyAction(target, options); |
112 options.container.appendChild(fakeElement); |
128 } else if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target === null || target === void 0 ? void 0 : target.type)) { |
113 selectedText = select_default()(fakeElement); |
129 // If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange |
114 command('copy'); |
130 selectedText = fakeCopyAction(target.value, options); |
115 fakeElement.remove(); |
|
116 } else { |
131 } else { |
117 selectedText = select_default()(target); |
132 selectedText = select_default()(target); |
118 command('copy'); |
133 command('copy'); |
119 } |
134 } |
120 |
135 |