111
111
v-tooltip =" 'Remove value'"
112
112
@click =" removeField()"
113
113
/>
114
+ <v-popover
115
+ popoverClass =" context-menu-popover"
116
+ placement =" bottom"
117
+ :open.sync =" contextMenuOpen"
118
+ >
119
+ <BaseIcon
120
+ class =" context-field icon-button"
121
+ icon =" more_horiz"
122
+ />
123
+ <div
124
+ slot =" popover"
125
+ class =" context-menu"
126
+ @mouseleave =" contextMenuOpen = false"
127
+ >
128
+ <div
129
+ class =" context-menu-item"
130
+ v-close-popover
131
+ @click =" copyToClipboard"
132
+ >
133
+ {{ $t('DataField.contextMenu.copyValue') }}
134
+ </div >
135
+ </div >
136
+ </v-popover >
114
137
</span >
115
138
</template >
116
139
@@ -167,6 +190,7 @@ import {
167
190
sortByKey ,
168
191
openInEditor ,
169
192
escape ,
193
+ stringify ,
170
194
specialTokenToString
171
195
} from ' src/util'
172
196
@@ -185,6 +209,15 @@ function subFieldCount (value) {
185
209
}
186
210
}
187
211
212
+ function copyToClipboard (state ) {
213
+ const dummyTextArea = document .createElement (' textarea' )
214
+ dummyTextArea .textContent = stringify (state)
215
+ document .body .appendChild (dummyTextArea)
216
+ dummyTextArea .select ()
217
+ document .execCommand (' copy' )
218
+ document .body .removeChild (dummyTextArea)
219
+ }
220
+
188
221
export default {
189
222
name: ' DataField' ,
190
223
@@ -201,6 +234,7 @@ export default {
201
234
202
235
data () {
203
236
return {
237
+ contextMenuOpen: false ,
204
238
limit: Array .isArray (this .field .value ) ? 10 : Infinity ,
205
239
expanded: this .depth === 0 && this .field .key !== ' $route' && (subFieldCount (this .field .value ) < 5 )
206
240
}
@@ -372,6 +406,9 @@ export default {
372
406
},
373
407
374
408
methods: {
409
+ copyToClipboard () {
410
+ copyToClipboard (this .field .value )
411
+ },
375
412
onClick (event ) {
376
413
// Cancel if target is interactive
377
414
if (event .target .tagName === ' INPUT' || event .target .className .includes (' button' )) {
@@ -566,4 +603,17 @@ export default {
566
603
567
604
.remove-field
568
605
margin-left 10px
606
+
607
+ .context-menu-item
608
+ padding 4px 8px
609
+ cursor pointer
610
+ background-color transparent
611
+ & :hover
612
+ background-color $hover-color
613
+ </style >
614
+
615
+ <style lang="stylus">
616
+ .popover.context-menu-popover
617
+ .popover-inner
618
+ padding 6px 0
569
619
</style >
0 commit comments