Skip to content

Commit 01af916

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 01af916

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/devtools/components/DataField.vue

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

@@ -166,11 +189,13 @@ import {
166189
isPlainObject,
167190
sortByKey,
168191
openInEditor,
192+
stringify,
169193
escape
170194
} from 'src/util'
171195
172196
import DataFieldEdit from '../mixins/data-field-edit'
173197
198+
174199
const rawTypeRE = /^\[object (\w+)]$/
175200
const specialTypeRE = /^\[native (\w+) (.*)\]$/
176201
@@ -184,6 +209,15 @@ function subFieldCount (value) {
184209
}
185210
}
186211
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+
187221
export default {
188222
name: 'DataField',
189223
@@ -200,6 +234,7 @@ export default {
200234
201235
data () {
202236
return {
237+
contextMenuOpen: false,
203238
limit: Array.isArray(this.field.value) ? 10 : Infinity,
204239
expanded: this.depth === 0 && this.field.key !== '$route' && (subFieldCount(this.field.value) < 5)
205240
}
@@ -378,6 +413,9 @@ export default {
378413
},
379414
380415
methods: {
416+
copyToClipboard () {
417+
copyToClipboard(this.field.value)
418+
},
381419
onClick (event) {
382420
// Cancel if target is interactive
383421
if (event.target.tagName === 'INPUT' || event.target.className.includes('button')) {
@@ -572,4 +610,19 @@ export default {
572610
573611
.remove-field
574612
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+
}
575628
</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)