Skip to content

Commit 11891f6

Browse files
committed
Add context menu to DataField
Refs vuejs#442 * Adds more actions to dropdown * Currently adds one item - Copy Value (to clipboard)
1 parent 28df5c4 commit 11891f6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/devtools/components/DataField.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@
111111
v-tooltip="'Remove value'"
112112
@click="removeField()"
113113
/>
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>
114125
</span>
115126
</template>
116127

@@ -166,11 +177,13 @@ import {
166177
isPlainObject,
167178
sortByKey,
168179
openInEditor,
180+
stringify,
169181
escape
170182
} from 'src/util'
171183
172184
import DataFieldEdit from '../mixins/data-field-edit'
173185
186+
174187
const rawTypeRE = /^\[object (\w+)]$/
175188
const specialTypeRE = /^\[native (\w+) (.*)\]$/
176189
@@ -184,6 +197,15 @@ function subFieldCount (value) {
184197
}
185198
}
186199
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+
187209
export default {
188210
name: 'DataField',
189211
@@ -200,6 +222,7 @@ export default {
200222
201223
data () {
202224
return {
225+
contextMenuOpen: false,
203226
limit: Array.isArray(this.field.value) ? 10 : Infinity,
204227
expanded: this.depth === 0 && this.field.key !== '$route' && (subFieldCount(this.field.value) < 5)
205228
}
@@ -378,6 +401,9 @@ export default {
378401
},
379402
380403
methods: {
404+
copyToClipboard () {
405+
copyToClipboard(this.field.value)
406+
},
381407
onClick (event) {
382408
// Cancel if target is interactive
383409
if (event.target.tagName === 'INPUT' || event.target.className.includes('button')) {
@@ -572,4 +598,11 @@ export default {
572598
573599
.remove-field
574600
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
575608
</style>

src/devtools/locales/en.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export default {
2727
tooltip: '[[{{keys.enter}}]] Submit change'
2828
}
2929
},
30+
contextMenu: {
31+
copyValue: 'Copy Value'
32+
},
3033
quickEdit: {
3134
number: {
3235
tooltip: `Quick Edit<br><br>

0 commit comments

Comments
 (0)