mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
#115 copy cell value
This commit is contained in:
@@ -2,9 +2,11 @@ import Lib from 'plotly.js/src/lib'
|
|||||||
import dataUrlToBlob from 'dataurl-to-blob'
|
import dataUrlToBlob from 'dataurl-to-blob'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async copyCsv (str) {
|
async copyText (str, notifyMessage) {
|
||||||
await navigator.clipboard.writeText(str)
|
await navigator.clipboard.writeText(str)
|
||||||
Lib.notifier('CSV copied to clipboard successfully', 'long')
|
if (notifyMessage) {
|
||||||
|
Lib.notifier(notifyMessage, 'long')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async copyImage (source) {
|
async copyImage (source) {
|
||||||
|
|||||||
@@ -10,7 +10,15 @@
|
|||||||
>
|
>
|
||||||
{{ format.text }}
|
{{ format.text }}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
@click="copyToClipboard"
|
||||||
|
>
|
||||||
|
Copy
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="value-body">
|
||||||
<codemirror
|
<codemirror
|
||||||
v-if="currentFormat === 'json'"
|
v-if="currentFormat === 'json'"
|
||||||
:value="formattedJson"
|
:value="formattedJson"
|
||||||
@@ -20,6 +28,7 @@
|
|||||||
{{ cellValue }}
|
{{ cellValue }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -31,6 +40,7 @@ import 'codemirror/addon/fold/foldgutter.js'
|
|||||||
import 'codemirror/addon/fold/foldgutter.css'
|
import 'codemirror/addon/fold/foldgutter.css'
|
||||||
import 'codemirror/addon/fold/brace-fold.js'
|
import 'codemirror/addon/fold/brace-fold.js'
|
||||||
import 'codemirror/theme/neo.css'
|
import 'codemirror/theme/neo.css'
|
||||||
|
import cIo from '@/lib/utils/clipboardIo'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -43,7 +53,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
formats: [
|
formats: [
|
||||||
{ text: 'JSON', value: 'json' },
|
{ text: 'JSON', value: 'json' },
|
||||||
{ text: 'TEXT', value: 'text' }
|
{ text: 'Text', value: 'text' }
|
||||||
],
|
],
|
||||||
currentFormat: 'text',
|
currentFormat: 'text',
|
||||||
cmOptions: {
|
cmOptions: {
|
||||||
@@ -81,6 +91,13 @@ export default {
|
|||||||
} catch {
|
} catch {
|
||||||
this.formattedJson = ''
|
this.formattedJson = ''
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
copyToClipboard () {
|
||||||
|
cIo.copyText(this.currentFormat === 'json'
|
||||||
|
? this.formattedJson
|
||||||
|
: this.cellValue,
|
||||||
|
'The value is copied to clipboard.'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,13 +106,20 @@ export default {
|
|||||||
<style scoped>
|
<style scoped>
|
||||||
.value-viewer {
|
.value-viewer {
|
||||||
background-color: var(--color-white);
|
background-color: var(--color-white);
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
.value-viewer-toolbar {
|
.value-viewer-toolbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: end;
|
justify-content: end;
|
||||||
}
|
}
|
||||||
|
.value-body {
|
||||||
|
flex-grow: 1;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
.text-value {
|
.text-value {
|
||||||
padding: 2px 8px;
|
padding: 8px 8px;
|
||||||
color: var(--color-text-base);
|
color: var(--color-text-base);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,4 +140,17 @@ export default {
|
|||||||
.value-viewer-toolbar button[aria-selected="true"] {
|
.value-viewer-toolbar button[aria-selected="true"] {
|
||||||
color: var(--color-accent);
|
color: var(--color-accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
>>> .vue-codemirror {
|
||||||
|
height: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
>>> .CodeMirror {
|
||||||
|
height: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
>>> .CodeMirror-cursor {
|
||||||
|
width: 1px;
|
||||||
|
background: var(--color-text-base);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
copyToClipboard () {
|
copyToClipboard () {
|
||||||
cIo.copyCsv(this.dataToCopy)
|
cIo.copyText(this.dataToCopy, 'CSV copied to clipboard successfully')
|
||||||
this.$modal.hide('prepareCSVCopy')
|
this.$modal.hide('prepareCSVCopy')
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ describe('clipboardIo.js', async () => {
|
|||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('copyCsv', async () => {
|
it('copyText', async () => {
|
||||||
sinon.stub(navigator.clipboard, 'writeText').resolves(true)
|
sinon.stub(navigator.clipboard, 'writeText').resolves(true)
|
||||||
await cIo.copyCsv('id\tname\r\n1\t2')
|
await cIo.copyText('id\tname\r\n1\t2')
|
||||||
expect(navigator.clipboard.writeText.calledOnceWith('id\tname\r\n1\t2'))
|
expect(navigator.clipboard.writeText.calledOnceWith('id\tname\r\n1\t2'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user