mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
#115 formats and call selections
This commit is contained in:
@@ -77,10 +77,6 @@ table.sqliteviz-table {
|
|||||||
border-bottom: 1px solid var(--color-border-light);
|
border-bottom: 1px solid var(--color-border-light);
|
||||||
border-right: 1px solid var(--color-border-light);
|
border-right: 1px solid var(--color-border-light);
|
||||||
}
|
}
|
||||||
.sqliteviz-table tbody td:focus {
|
|
||||||
outline: none;
|
|
||||||
box-shadow:inset 0 0 0 1px var(--color-accent);
|
|
||||||
}
|
|
||||||
.sqliteviz-table td,
|
.sqliteviz-table td,
|
||||||
.sqliteviz-table th,
|
.sqliteviz-table th,
|
||||||
.fixed-header {
|
.fixed-header {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
<table
|
<table
|
||||||
ref="table"
|
ref="table"
|
||||||
class="sqliteviz-table"
|
class="sqliteviz-table"
|
||||||
|
tabindex="0"
|
||||||
@keydown="onTableKeydown"
|
@keydown="onTableKeydown"
|
||||||
>
|
>
|
||||||
<thead>
|
<thead>
|
||||||
@@ -37,7 +38,8 @@
|
|||||||
:data-col="colIndex"
|
:data-col="colIndex"
|
||||||
:data-row="rowIndex - 1"
|
:data-row="rowIndex - 1"
|
||||||
:key="colIndex"
|
:key="colIndex"
|
||||||
tabindex="0"
|
:aria-selected="false"
|
||||||
|
@click="selectCell($event.target)"
|
||||||
>
|
>
|
||||||
<div class="cell-data" :style="cellStyle">
|
<div class="cell-data" :style="cellStyle">
|
||||||
{{ dataSet.values[col][rowIndex - 1 + currentPageData.start] }}
|
{{ dataSet.values[col][rowIndex - 1 + currentPageData.start] }}
|
||||||
@@ -79,7 +81,8 @@ export default {
|
|||||||
header: null,
|
header: null,
|
||||||
tableWidth: null,
|
tableWidth: null,
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
resizeObserver: null
|
resizeObserver: null,
|
||||||
|
selectedCellElement: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -133,7 +136,15 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.moveFocusInTable(e.target, keyCodeMap[e.keyCode])
|
this.moveFocusInTable(this.selectedCellElement, keyCodeMap[e.keyCode])
|
||||||
|
},
|
||||||
|
selectCell (cell) {
|
||||||
|
if (this.selectedCellElement) {
|
||||||
|
this.selectedCellElement.ariaSelected = false
|
||||||
|
}
|
||||||
|
cell.ariaSelected = true
|
||||||
|
this.selectedCellElement = cell
|
||||||
|
this.$emit('updateSelectedCell', cell)
|
||||||
},
|
},
|
||||||
moveFocusInTable (initialCell, direction) {
|
moveFocusInTable (initialCell, direction) {
|
||||||
const currentRowIndex = +initialCell.dataset.row
|
const currentRowIndex = +initialCell.dataset.row
|
||||||
@@ -167,7 +178,7 @@ export default {
|
|||||||
const newCell = this.$refs.table
|
const newCell = this.$refs.table
|
||||||
.querySelector(`td[data-col="${newColIndex}"][data-row="${newRowIndex}"]`)
|
.querySelector(`td[data-col="${newColIndex}"][data-row="${newRowIndex}"]`)
|
||||||
if (newCell) {
|
if (newCell) {
|
||||||
newCell.focus()
|
this.selectCell(newCell)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -189,4 +200,13 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
table.sqliteviz-table:focus {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.sqliteviz-table tbody td:hover {
|
||||||
|
background-color: var(--color-bg-light-3);
|
||||||
|
}
|
||||||
|
.sqliteviz-table tbody td[aria-selected="true"] {
|
||||||
|
box-shadow:inset 0 0 0 1px var(--color-accent);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,9 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div class="value-viewer">
|
||||||
|
<div class="value-viewer-toolbar">
|
||||||
|
<button
|
||||||
|
v-for="format in formats"
|
||||||
|
:key="format.value"
|
||||||
|
type="button"
|
||||||
|
:aria-selected="currentFormat === format.value"
|
||||||
|
@click="currentFormat = format.value"
|
||||||
|
>
|
||||||
|
{{ format.text }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<codemirror
|
<codemirror
|
||||||
:value="cellValue"
|
v-if="currentFormat === 'json'"
|
||||||
|
:value="formattedJson"
|
||||||
:options="cmOptions"
|
:options="cmOptions"
|
||||||
/>
|
/>
|
||||||
|
<div v-else class="text-value">
|
||||||
|
{{ cellValue }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -26,6 +41,11 @@ export default {
|
|||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
formats: [
|
||||||
|
{ text: 'JSON', value: 'json' },
|
||||||
|
{ text: 'TEXT', value: 'text' }
|
||||||
|
],
|
||||||
|
currentFormat: 'text',
|
||||||
cmOptions: {
|
cmOptions: {
|
||||||
tabSize: 4,
|
tabSize: 4,
|
||||||
mode: { name: 'javascript', json: true },
|
mode: { name: 'javascript', json: true },
|
||||||
@@ -35,14 +55,65 @@ export default {
|
|||||||
foldGutter: true,
|
foldGutter: true,
|
||||||
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
},
|
||||||
|
formattedJson: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
currentFormat () {
|
||||||
|
this.formattedJson = ''
|
||||||
|
if (this.currentFormat === 'json') {
|
||||||
|
this.formatJson(this.cellValue)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cellValue () {
|
||||||
|
if (this.currentFormat === 'json') {
|
||||||
|
this.formatJson(this.cellValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
formatJson (jsonStr) {
|
||||||
|
try {
|
||||||
|
this.formattedJson = JSON.stringify(
|
||||||
|
JSON.parse(jsonStr), null, 4
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
this.formattedJson = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.value-viewer {
|
||||||
|
background-color: var(--color-white);
|
||||||
|
}
|
||||||
|
.value-viewer-toolbar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: end;
|
||||||
|
}
|
||||||
|
.text-value {
|
||||||
|
padding: 2px 8px;
|
||||||
|
color: var(--color-text-base);
|
||||||
|
}
|
||||||
|
|
||||||
|
.value-viewer-toolbar button {
|
||||||
|
font-size: 10px;
|
||||||
|
height: 20px;
|
||||||
|
padding: 0 8px;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-text-base);
|
||||||
|
border-radius: var(--border-radius-small);
|
||||||
|
}
|
||||||
|
|
||||||
|
.value-viewer-toolbar button:hover {
|
||||||
|
background-color: var(--color-bg-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.value-viewer-toolbar button[aria-selected="true"] {
|
||||||
|
color: var(--color-accent);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
</template>
|
</template>
|
||||||
<div :id="'run-result-result-set-'+tab.id" class="result-set-container"/>
|
<div :id="'run-result-result-set-'+tab.id" class="result-set-container"/>
|
||||||
<template #right-pane v-if="viewValuePanelVisible">
|
<template #right-pane v-if="viewValuePanelVisible">
|
||||||
<div><value-viewer :cellValue="testCell"/></div>
|
<div class="value-viewer-container">
|
||||||
|
<value-viewer v-show="selectedCell" :cellValue="selectedCellValue"/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
@@ -81,6 +83,7 @@
|
|||||||
:time="time"
|
:time="time"
|
||||||
:pageSize="pageSize"
|
:pageSize="pageSize"
|
||||||
class="straight"
|
class="straight"
|
||||||
|
@updateSelectedCell="onUpdateSelectedCell"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</teleport>
|
</teleport>
|
||||||
@@ -121,11 +124,8 @@ export default {
|
|||||||
preparingCopy: false,
|
preparingCopy: false,
|
||||||
dataToCopy: null,
|
dataToCopy: null,
|
||||||
viewValuePanelVisible: false,
|
viewValuePanelVisible: false,
|
||||||
testCell: JSON.stringify(
|
selectedCell: null,
|
||||||
JSON.parse('{"x": 1, "y": 2, "vector": [1,2,3]}'),
|
selectedCellValue: ''
|
||||||
null,
|
|
||||||
4
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
@@ -227,6 +227,11 @@ export default {
|
|||||||
|
|
||||||
toggleViewValuePanel () {
|
toggleViewValuePanel () {
|
||||||
this.viewValuePanelVisible = !this.viewValuePanelVisible
|
this.viewValuePanelVisible = !this.viewValuePanelVisible
|
||||||
|
},
|
||||||
|
|
||||||
|
onUpdateSelectedCell (e) {
|
||||||
|
this.selectedCell = e
|
||||||
|
this.selectedCellValue = this.selectedCell?.innerText
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,6 +256,11 @@ export default {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
.value-viewer-container {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
background-color: var(--color-white);
|
||||||
|
}
|
||||||
|
|
||||||
.table-preview {
|
.table-preview {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
Reference in New Issue
Block a user