52
52
<script >
53
53
import Utils from ' ../utils' ;
54
54
import Loading from ' ./internal/Loading.vue' ;
55
+ import CopyMixin from ' ./internal/CopyMixin' ;
55
56
import Vue from ' vue' ;
56
57
57
58
export default {
@@ -60,6 +61,7 @@ export default {
60
61
Loading,
61
62
SearchBox : () => import (' ./SearchBox.vue' )
62
63
},
64
+ mixins: [CopyMixin],
63
65
props: {
64
66
data: {
65
67
type: [Array , Object ],
@@ -137,8 +139,7 @@ export default {
137
139
showDetails: {},
138
140
showList: this .collapsed ? null : true ,
139
141
hideDeprecated: this .hideDeprecatedByDefault ,
140
- summaries: [],
141
- canCopy: false
142
+ summaries: []
142
143
};
143
144
},
144
145
watch: {
@@ -201,9 +202,6 @@ export default {
201
202
created () {
202
203
this .filter ();
203
204
},
204
- mounted () {
205
- this .canCopy = navigator && navigator .clipboard && typeof navigator .clipboard .writeText === ' function' ;
206
- },
207
205
methods: {
208
206
hasActiveFilter () {
209
207
return this .searchTerm .length >= this .searchMinLength || this .hideDeprecated ;
@@ -223,18 +221,9 @@ export default {
223
221
this .$emit (' summaries' , this .summaries );
224
222
},
225
223
copyIdentifier (event , summary ) {
226
- if (this .allowCopy && this .canCopy ) {
227
- let elem = event .composedPath ()[0 ]; // event.target doesn't work in web components
228
- navigator .clipboard .writeText (summary .identifier )
229
- .then (() => this .toggleIcon (elem, ' ✅' ))
230
- .catch (() => this .toggleIcon (elem, ' ❌' ))
231
- }
232
- },
233
- toggleIcon (elem , newIcon ) {
234
- if (elem) {
235
- let oldIcon = elem .innerText ;
236
- elem .innerText = newIcon;
237
- setTimeout (() => elem .innerText = oldIcon, 2000 );
224
+ if (this .allowCopy ) {
225
+ const elem = event .composedPath ()[0 ]; // event.target doesn't work in web components
226
+ this .copyText (summary .identifier , () => this .toggleIcon (elem, ' ✅' ), () => this .toggleIcon (elem, ' ❌' ));
238
227
}
239
228
},
240
229
generateSummaries () {
0 commit comments