Skip to content

Commit 6cfb501

Browse files
committed
Add context menu to DataField
Refs #442 * Adds more actions to dropdown * Currently adds one item - Copy Value (to clipboard)
1 parent b277dca commit 6cfb501

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/devtools/components/DataField.vue

Lines changed: 50 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

@@ -167,6 +190,7 @@ import {
167190
sortByKey,
168191
openInEditor,
169192
escape,
193+
stringify,
170194
specialTokenToString
171195
} from 'src/util'
172196
@@ -185,6 +209,15 @@ function subFieldCount (value) {
185209
}
186210
}
187211
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+
188221
export default {
189222
name: 'DataField',
190223
@@ -201,6 +234,7 @@ export default {
201234
202235
data () {
203236
return {
237+
contextMenuOpen: false,
204238
limit: Array.isArray(this.field.value) ? 10 : Infinity,
205239
expanded: this.depth === 0 && this.field.key !== '$route' && (subFieldCount(this.field.value) < 5)
206240
}
@@ -372,6 +406,9 @@ export default {
372406
},
373407
374408
methods: {
409+
copyToClipboard () {
410+
copyToClipboard(this.field.value)
411+
},
375412
onClick (event) {
376413
// Cancel if target is interactive
377414
if (event.target.tagName === 'INPUT' || event.target.className.includes('button')) {
@@ -566,4 +603,17 @@ export default {
566603
567604
.remove-field
568605
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
569619
</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)