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
@@ -166,11 +189,13 @@ import {
166
189
isPlainObject ,
167
190
sortByKey ,
168
191
openInEditor ,
192
+ stringify ,
169
193
escape
170
194
} from ' src/util'
171
195
172
196
import DataFieldEdit from ' ../mixins/data-field-edit'
173
197
198
+
174
199
const rawTypeRE = / ^ \[ object (\w + )]$ /
175
200
const specialTypeRE = / ^ \[ native (\w + ) (. * )\] $ /
176
201
@@ -184,6 +209,15 @@ function subFieldCount (value) {
184
209
}
185
210
}
186
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
+
187
221
export default {
188
222
name: ' DataField' ,
189
223
@@ -200,6 +234,7 @@ export default {
200
234
201
235
data () {
202
236
return {
237
+ contextMenuOpen: false ,
203
238
limit: Array .isArray (this .field .value ) ? 10 : Infinity ,
204
239
expanded: this .depth === 0 && this .field .key !== ' $route' && (subFieldCount (this .field .value ) < 5 )
205
240
}
@@ -378,6 +413,9 @@ export default {
378
413
},
379
414
380
415
methods: {
416
+ copyToClipboard () {
417
+ copyToClipboard (this .field .value )
418
+ },
381
419
onClick (event ) {
382
420
// Cancel if target is interactive
383
421
if (event .target .tagName === ' INPUT' || event .target .className .includes (' button' )) {
@@ -572,4 +610,19 @@ export default {
572
610
573
611
.remove-field
574
612
margin-left 10px
613
+
614
+ .context-menu-item
615
+ padding 4px 8px
616
+ cursor pointer
617
+ background-color transparent
618
+ & :hover
619
+ background-color $hover-color
620
+ </style >
621
+
622
+ <style lang="stylus">
623
+ .popover.context-menu-popover {
624
+ .popover-inner {
625
+ padding 6px 0
626
+ }
627
+ }
575
628
</style >
0 commit comments