mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 10:08:52 +08:00
#127 fix copy to clipboard
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<modal
|
<modal
|
||||||
:modalId="name"
|
v-model="show"
|
||||||
class="dialog"
|
class="dialog"
|
||||||
:clickToClose="false"
|
:clickToClose="false"
|
||||||
:contentTransition="{ name: 'loading-dialog' }"
|
:contentTransition="{ name: 'loading-dialog' }"
|
||||||
:overlayTransition="{ name: 'loading-dialog' }"
|
:overlayTransition="{ name: 'loading-dialog' }"
|
||||||
|
@update:modelValue="$emit('update:modelValue', $event)"
|
||||||
>
|
>
|
||||||
<div class="dialog-header">
|
<div class="dialog-header">
|
||||||
{{ title }}
|
{{ title }}
|
||||||
<close-icon :disabled="loading" @click="$emit('cancel')" />
|
<close-icon :disabled="loading" @click="cancel" />
|
||||||
</div>
|
</div>
|
||||||
<div class="dialog-body">
|
<div class="dialog-body">
|
||||||
<div v-if="loading" class="loading-dialog-body">
|
<div v-if="loading" class="loading-dialog-body">
|
||||||
@@ -28,7 +29,7 @@
|
|||||||
class="secondary"
|
class="secondary"
|
||||||
type="button"
|
type="button"
|
||||||
:disabled="loading"
|
:disabled="loading"
|
||||||
@click="$emit('cancel')"
|
@click="cancel"
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
@@ -52,24 +53,33 @@ export default {
|
|||||||
name: 'LoadingDialog',
|
name: 'LoadingDialog',
|
||||||
components: { LoadingIndicator, CloseIcon },
|
components: { LoadingIndicator, CloseIcon },
|
||||||
props: {
|
props: {
|
||||||
|
modelValue: Boolean,
|
||||||
loadingMsg: String,
|
loadingMsg: String,
|
||||||
successMsg: String,
|
successMsg: String,
|
||||||
actionBtnName: String,
|
actionBtnName: String,
|
||||||
name: String,
|
|
||||||
title: String,
|
title: String,
|
||||||
loading: Boolean
|
loading: Boolean
|
||||||
},
|
},
|
||||||
emits: ['cancel', 'action'],
|
data() {
|
||||||
|
return {
|
||||||
|
show: this.modelValue
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['cancel', 'action', 'update:modelValue'],
|
||||||
watch: {
|
watch: {
|
||||||
|
modelValue() {
|
||||||
|
this.show = this.modelValue
|
||||||
|
},
|
||||||
loading() {
|
loading() {
|
||||||
if (this.loading) {
|
if (this.loading) {
|
||||||
this.$modal.show(this.name)
|
this.$emit('update:modelValue', true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
cancel() {
|
cancel() {
|
||||||
this.$emit('cancel')
|
this.$emit('cancel')
|
||||||
|
this.$emit('update:modelValue', false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,11 +161,8 @@ export default {
|
|||||||
'text/html'
|
'text/html'
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
async prepareCopy(type = 'png') {
|
prepareCopy(type = 'png') {
|
||||||
return await chartHelper.getImageDataUrl(
|
return chartHelper.getImageDataUrl(this.$refs.plotlyEditor.$el, type)
|
||||||
this.$refs.plotlyEditor.$el,
|
|
||||||
type
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,10 +72,10 @@
|
|||||||
</side-tool-bar>
|
</side-tool-bar>
|
||||||
|
|
||||||
<loading-dialog
|
<loading-dialog
|
||||||
|
v-model="showLoadingDialog"
|
||||||
loadingMsg="Rendering the visualisation..."
|
loadingMsg="Rendering the visualisation..."
|
||||||
successMsg="Image is ready"
|
successMsg="Image is ready"
|
||||||
actionBtnName="Copy"
|
actionBtnName="Copy"
|
||||||
name="prepareCopy"
|
|
||||||
title="Copy to clipboard"
|
title="Copy to clipboard"
|
||||||
:loading="preparingCopy"
|
:loading="preparingCopy"
|
||||||
@action="copyToClipboard"
|
@action="copyToClipboard"
|
||||||
@@ -85,8 +85,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Chart from './Chart'
|
import Chart from './Chart/index.vue'
|
||||||
import Pivot from './Pivot'
|
import Pivot from './Pivot/index.vue'
|
||||||
import SideToolBar from '../SideToolBar'
|
import SideToolBar from '../SideToolBar'
|
||||||
import IconButton from '@/components/IconButton'
|
import IconButton from '@/components/IconButton'
|
||||||
import ChartIcon from '@/components/svg/chart'
|
import ChartIcon from '@/components/svg/chart'
|
||||||
@@ -96,7 +96,7 @@ import ExportToSvgIcon from '@/components/svg/exportToSvg'
|
|||||||
import PngIcon from '@/components/svg/png'
|
import PngIcon from '@/components/svg/png'
|
||||||
import ClipboardIcon from '@/components/svg/clipboard'
|
import ClipboardIcon from '@/components/svg/clipboard'
|
||||||
import cIo from '@/lib/utils/clipboardIo'
|
import cIo from '@/lib/utils/clipboardIo'
|
||||||
import loadingDialog from '@/components/LoadingDialog'
|
import loadingDialog from '@/components/LoadingDialog.vue'
|
||||||
import time from '@/lib/utils/time'
|
import time from '@/lib/utils/time'
|
||||||
import events from '@/lib/utils/events'
|
import events from '@/lib/utils/events'
|
||||||
|
|
||||||
@@ -129,7 +129,8 @@ export default {
|
|||||||
loadingImage: false,
|
loadingImage: false,
|
||||||
copyingImage: false,
|
copyingImage: false,
|
||||||
preparingCopy: false,
|
preparingCopy: false,
|
||||||
dataToCopy: null
|
dataToCopy: null,
|
||||||
|
showLoadingDialog: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -170,14 +171,13 @@ export default {
|
|||||||
async prepareCopy() {
|
async prepareCopy() {
|
||||||
if ('ClipboardItem' in window) {
|
if ('ClipboardItem' in window) {
|
||||||
this.preparingCopy = true
|
this.preparingCopy = true
|
||||||
this.$modal.show('prepareCopy')
|
this.showLoadingDialog = true
|
||||||
const t0 = performance.now()
|
const t0 = performance.now()
|
||||||
|
|
||||||
await time.sleep(0)
|
await time.sleep(0)
|
||||||
this.dataToCopy = await this.$refs.viewComponent.prepareCopy()
|
this.dataToCopy = await this.$refs.viewComponent.prepareCopy()
|
||||||
const t1 = performance.now()
|
const t1 = performance.now()
|
||||||
if (t1 - t0 < 950) {
|
if (t1 - t0 < 950) {
|
||||||
this.$modal.hide('prepareCopy')
|
|
||||||
this.copyToClipboard()
|
this.copyToClipboard()
|
||||||
} else {
|
} else {
|
||||||
this.preparingCopy = false
|
this.preparingCopy = false
|
||||||
@@ -190,14 +190,13 @@ export default {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async copyToClipboard() {
|
copyToClipboard() {
|
||||||
cIo.copyImage(this.dataToCopy)
|
cIo.copyImage(this.dataToCopy)
|
||||||
this.$modal.hide('prepareCopy')
|
this.showLoadingDialog = false
|
||||||
this.exportSignal('clipboard')
|
this.exportSignal('clipboard')
|
||||||
},
|
},
|
||||||
cancelCopy() {
|
cancelCopy() {
|
||||||
this.dataToCopy = null
|
this.dataToCopy = null
|
||||||
this.$modal.hide('prepareCopy')
|
|
||||||
},
|
},
|
||||||
|
|
||||||
saveAsSvg() {
|
saveAsSvg() {
|
||||||
|
|||||||
@@ -80,10 +80,10 @@
|
|||||||
</side-tool-bar>
|
</side-tool-bar>
|
||||||
|
|
||||||
<loading-dialog
|
<loading-dialog
|
||||||
|
v-model="showLoadingDialog"
|
||||||
loadingMsg="Building CSV..."
|
loadingMsg="Building CSV..."
|
||||||
successMsg="CSV is ready"
|
successMsg="CSV is ready"
|
||||||
actionBtnName="Copy"
|
actionBtnName="Copy"
|
||||||
name="prepareCSVCopy"
|
|
||||||
title="Copy to clipboard"
|
title="Copy to clipboard"
|
||||||
:loading="preparingCopy"
|
:loading="preparingCopy"
|
||||||
@action="copyToClipboard"
|
@action="copyToClipboard"
|
||||||
@@ -190,7 +190,8 @@ export default {
|
|||||||
viewRecord: false,
|
viewRecord: false,
|
||||||
defaultPage: 1,
|
defaultPage: 1,
|
||||||
defaultSelectedCell: null,
|
defaultSelectedCell: null,
|
||||||
enableTeleport: this.$store.state.isWorkspaceVisible
|
enableTeleport: this.$store.state.isWorkspaceVisible,
|
||||||
|
showLoadingDialog: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -264,14 +265,13 @@ export default {
|
|||||||
|
|
||||||
if ('ClipboardItem' in window) {
|
if ('ClipboardItem' in window) {
|
||||||
this.preparingCopy = true
|
this.preparingCopy = true
|
||||||
this.$modal.show('prepareCSVCopy')
|
this.showLoadingDialog = true
|
||||||
const t0 = performance.now()
|
const t0 = performance.now()
|
||||||
|
|
||||||
await time.sleep(0)
|
await time.sleep(0)
|
||||||
this.dataToCopy = csv.serialize(this.result)
|
this.dataToCopy = csv.serialize(this.result)
|
||||||
const t1 = performance.now()
|
const t1 = performance.now()
|
||||||
if (t1 - t0 < 950) {
|
if (t1 - t0 < 950) {
|
||||||
this.$modal.hide('prepareCSVCopy')
|
|
||||||
this.copyToClipboard()
|
this.copyToClipboard()
|
||||||
} else {
|
} else {
|
||||||
this.preparingCopy = false
|
this.preparingCopy = false
|
||||||
@@ -287,12 +287,11 @@ export default {
|
|||||||
|
|
||||||
copyToClipboard() {
|
copyToClipboard() {
|
||||||
cIo.copyText(this.dataToCopy, 'CSV copied to clipboard successfully')
|
cIo.copyText(this.dataToCopy, 'CSV copied to clipboard successfully')
|
||||||
this.$modal.hide('prepareCSVCopy')
|
this.showLoadingDialog = false
|
||||||
},
|
},
|
||||||
|
|
||||||
cancelCopy() {
|
cancelCopy() {
|
||||||
this.dataToCopy = null
|
this.dataToCopy = null
|
||||||
this.$modal.hide('prepareCSVCopy')
|
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleViewValuePanel() {
|
toggleViewValuePanel() {
|
||||||
|
|||||||
Reference in New Issue
Block a user