From ac1f7de62cd49eadf0114132e6318b00da1c06dd Mon Sep 17 00:00:00 2001 From: lana-k Date: Fri, 27 Oct 2023 22:50:54 +0200 Subject: [PATCH] #115 formats and call selections --- src/assets/styles/tables.css | 4 - src/components/SqlTable/index.vue | 28 ++++++- .../Tabs/Tab/RunResult/ValueViewer.vue | 77 ++++++++++++++++++- .../Workspace/Tabs/Tab/RunResult/index.vue | 22 ++++-- 4 files changed, 114 insertions(+), 17 deletions(-) diff --git a/src/assets/styles/tables.css b/src/assets/styles/tables.css index 758b10c..59d1d69 100644 --- a/src/assets/styles/tables.css +++ b/src/assets/styles/tables.css @@ -77,10 +77,6 @@ table.sqliteviz-table { border-bottom: 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 th, .fixed-header { diff --git a/src/components/SqlTable/index.vue b/src/components/SqlTable/index.vue index 6872d17..6d44168 100644 --- a/src/components/SqlTable/index.vue +++ b/src/components/SqlTable/index.vue @@ -21,6 +21,7 @@ @@ -37,7 +38,8 @@ :data-col="colIndex" :data-row="rowIndex - 1" :key="colIndex" - tabindex="0" + :aria-selected="false" + @click="selectCell($event.target)" >
{{ dataSet.values[col][rowIndex - 1 + currentPageData.start] }} @@ -79,7 +81,8 @@ export default { header: null, tableWidth: null, currentPage: 1, - resizeObserver: null + resizeObserver: null, + selectedCellElement: null } }, computed: { @@ -133,7 +136,15 @@ export default { 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) { const currentRowIndex = +initialCell.dataset.row @@ -167,7 +178,7 @@ export default { const newCell = this.$refs.table .querySelector(`td[data-col="${newColIndex}"][data-row="${newRowIndex}"]`) if (newCell) { - newCell.focus() + this.selectCell(newCell) } } }, @@ -189,4 +200,13 @@ export default { diff --git a/src/views/Main/Workspace/Tabs/Tab/RunResult/ValueViewer.vue b/src/views/Main/Workspace/Tabs/Tab/RunResult/ValueViewer.vue index c2d618c..aee6613 100644 --- a/src/views/Main/Workspace/Tabs/Tab/RunResult/ValueViewer.vue +++ b/src/views/Main/Workspace/Tabs/Tab/RunResult/ValueViewer.vue @@ -1,9 +1,24 @@ @@ -26,6 +41,11 @@ export default { }, data () { return { + formats: [ + { text: 'JSON', value: 'json' }, + { text: 'TEXT', value: 'text' } + ], + currentFormat: 'text', cmOptions: { tabSize: 4, mode: { name: 'javascript', json: true }, @@ -35,14 +55,65 @@ export default { foldGutter: true, gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'], 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: { - + formatJson (jsonStr) { + try { + this.formattedJson = JSON.stringify( + JSON.parse(jsonStr), null, 4 + ) + } catch { + this.formattedJson = '' + } + } } } diff --git a/src/views/Main/Workspace/Tabs/Tab/RunResult/index.vue b/src/views/Main/Workspace/Tabs/Tab/RunResult/index.vue index 79edb54..3519066 100644 --- a/src/views/Main/Workspace/Tabs/Tab/RunResult/index.vue +++ b/src/views/Main/Workspace/Tabs/Tab/RunResult/index.vue @@ -12,7 +12,9 @@
@@ -81,6 +83,7 @@ :time="time" :pageSize="pageSize" class="straight" + @updateSelectedCell="onUpdateSelectedCell" />
@@ -121,11 +124,8 @@ export default { preparingCopy: false, dataToCopy: null, viewValuePanelVisible: false, - testCell: JSON.stringify( - JSON.parse('{"x": 1, "y": 2, "vector": [1,2,3]}'), - null, - 4 - ) + selectedCell: null, + selectedCellValue: '' } }, components: { @@ -227,6 +227,11 @@ export default { toggleViewValuePanel () { this.viewValuePanelVisible = !this.viewValuePanelVisible + }, + + onUpdateSelectedCell (e) { + this.selectedCell = e + this.selectedCellValue = this.selectedCell?.innerText } } } @@ -251,6 +256,11 @@ export default { width: 100%; box-sizing: border-box; } +.value-viewer-container { + height: 100%; + width: 100%; + background-color: var(--color-white); +} .table-preview { position: absolute;