111
111
v-tooltip =" 'Remove value'"
112
112
@click =" removeField()"
113
113
/>
114
+ <v-popover placement =' bottom' :open.sync =' contextMenuOpen' >
115
+ <BaseIcon
116
+ class =" context-field icon-button"
117
+ icon =" more_horiz"
118
+ />
119
+ <div slot =" popover" class =' context-menu' @mouseleave =' contextMenuOpen = false' >
120
+ <div v-close-popover class =' context-menu-item' @click =' copyToClipboard' >
121
+ {{ $t('DataField.contextMenu.copyValue') }}
122
+ </div >
123
+ </div >
124
+ </v-popover >
114
125
</span >
115
126
</template >
116
127
@@ -166,11 +177,13 @@ import {
166
177
isPlainObject ,
167
178
sortByKey ,
168
179
openInEditor ,
180
+ stringify ,
169
181
escape
170
182
} from ' src/util'
171
183
172
184
import DataFieldEdit from ' ../mixins/data-field-edit'
173
185
186
+
174
187
const rawTypeRE = / ^ \[ object (\w + )]$ /
175
188
const specialTypeRE = / ^ \[ native (\w + ) (. * )\] $ /
176
189
@@ -184,6 +197,15 @@ function subFieldCount (value) {
184
197
}
185
198
}
186
199
200
+ function copyToClipboard (state ) {
201
+ const dummyTextArea = document .createElement (' textarea' )
202
+ dummyTextArea .textContent = stringify (state)
203
+ document .body .appendChild (dummyTextArea)
204
+ dummyTextArea .select ()
205
+ document .execCommand (' copy' )
206
+ document .body .removeChild (dummyTextArea)
207
+ }
208
+
187
209
export default {
188
210
name: ' DataField' ,
189
211
@@ -200,6 +222,7 @@ export default {
200
222
201
223
data () {
202
224
return {
225
+ contextMenuOpen: false ,
203
226
limit: Array .isArray (this .field .value ) ? 10 : Infinity ,
204
227
expanded: this .depth === 0 && this .field .key !== ' $route' && (subFieldCount (this .field .value ) < 5 )
205
228
}
@@ -378,6 +401,9 @@ export default {
378
401
},
379
402
380
403
methods: {
404
+ copyToClipboard () {
405
+ copyToClipboard (this .field .value )
406
+ },
381
407
onClick (event ) {
382
408
// Cancel if target is interactive
383
409
if (event .target .tagName === ' INPUT' || event .target .className .includes (' button' )) {
@@ -572,4 +598,11 @@ export default {
572
598
573
599
.remove-field
574
600
margin-left 10px
601
+
602
+ .context-menu-item
603
+ padding 4px 8px
604
+ cursor pointer
605
+ background-color transparent
606
+ & :hover
607
+ background-color $hover-color
575
608
</style >
0 commit comments