json tab, json dark mode style fix

This commit is contained in:
Jan Prochazka
2021-12-02 11:02:03 +01:00
parent 4751e4930e
commit 7522f87066
7 changed files with 99 additions and 23 deletions

View File

@@ -49,17 +49,4 @@
right: 0; right: 0;
bottom: 0; bottom: 0;
} }
:global(.theme-type-dark) .inner {
--json-tree-string-color: #ffc5c5;
--json-tree-symbol-color: #ffc5c5;
--json-tree-boolean-color: #b6c3ff;
--json-tree-function-color: #b6c3ff;
--json-tree-number-color: #bfbdff;
--json-tree-label-color: #e9aaed;
--json-tree-arrow-color: #d4d4d4;
--json-tree-null-color: #dcdcdc;
--json-tree-undefined-color: #dcdcdc;
--json-tree-date-color: #dcdcdc;
}
</style> </style>

View File

@@ -107,6 +107,14 @@
onClick: () => getCurrentDataGrid().editJsonDocument(), onClick: () => getCurrentDataGrid().editJsonDocument(),
}); });
registerCommand({
id: 'dataGrid.viewJsonDocument',
category: 'Data grid',
name: 'View row as JSON document',
testEnabled: () => getCurrentDataGrid()?.viewJsonEnabled(),
onClick: () => getCurrentDataGrid().viewJsonDocument(),
});
registerCommand({ registerCommand({
id: 'dataGrid.copyJsonDocument', id: 'dataGrid.copyJsonDocument',
category: 'Data grid', category: 'Data grid',
@@ -248,9 +256,9 @@
import CollapseButton from './CollapseButton.svelte'; import CollapseButton from './CollapseButton.svelte';
import GenerateSqlFromDataModal from '../modals/GenerateSqlFromDataModal.svelte'; import GenerateSqlFromDataModal from '../modals/GenerateSqlFromDataModal.svelte';
import { showModal } from '../modals/modalTools'; import { showModal } from '../modals/modalTools';
import { updateStatuBarInfo } from '../widgets/StatusBar.svelte';
import StatusBarTabItem from '../widgets/StatusBarTabItem.svelte'; import StatusBarTabItem from '../widgets/StatusBarTabItem.svelte';
import { findCommand } from '../commands/runCommand'; import { findCommand } from '../commands/runCommand';
import { openJsonDocument } from '../tabs/JsonTab.svelte';
export let onLoadNextData = undefined; export let onLoadNextData = undefined;
export let grider = undefined; export let grider = undefined;
@@ -454,12 +462,18 @@
); );
} }
export function editJsonEnabled() { export function viewJsonEnabled() {
return grider.editable && isDynamicStructure && _.uniq(selectedCells.map(x => x[0])).length == 1; return isDynamicStructure && _.uniq(selectedCells.map(x => x[0])).length == 1;
} }
export function copyJsonEnabled() { export function viewJsonDocument() {
return isDynamicStructure && _.uniq(selectedCells.map(x => x[0])).length == 1; const rowIndex = selectedCells[0][0];
const json = grider.getRowData(rowIndex);
openJsonDocument(json);
}
export function editJsonEnabled() {
return grider.editable && isDynamicStructure && _.uniq(selectedCells.map(x => x[0])).length == 1;
} }
export function editJsonDocument() { export function editJsonDocument() {
@@ -467,6 +481,10 @@
editJsonRowDocument(grider, rowIndex); editJsonRowDocument(grider, rowIndex);
} }
export function copyJsonEnabled() {
return isDynamicStructure && _.uniq(selectedCells.map(x => x[0])).length == 1;
}
export function copyJsonDocument() { export function copyJsonDocument() {
const rowIndex = selectedCells[0][0]; const rowIndex = selectedCells[0][0];
const rowData = grider.getRowData(rowIndex); const rowData = grider.getRowData(rowIndex);
@@ -1164,8 +1182,8 @@
{ placeTag: 'switch' }, { placeTag: 'switch' },
{ divider: true }, { divider: true },
{ placeTag: 'save' }, { placeTag: 'save' },
{ command: 'dataGrid.revertRowChanges' }, { command: 'dataGrid.revertRowChanges', hideDisabled: true },
{ command: 'dataGrid.revertAllChanges' }, { command: 'dataGrid.revertAllChanges', hideDisabled: true },
{ command: 'dataGrid.deleteSelectedRows' }, { command: 'dataGrid.deleteSelectedRows' },
{ command: 'dataGrid.insertNewRow' }, { command: 'dataGrid.insertNewRow' },
{ command: 'dataGrid.setNull' }, { command: 'dataGrid.setNull' },
@@ -1175,9 +1193,10 @@
{ command: 'dataGrid.hideColumn' }, { command: 'dataGrid.hideColumn' },
{ command: 'dataGrid.filterSelected' }, { command: 'dataGrid.filterSelected' },
{ command: 'dataGrid.clearFilter' }, { command: 'dataGrid.clearFilter' },
{ command: 'dataGrid.undo' }, { command: 'dataGrid.undo', hideDisabled: true },
{ command: 'dataGrid.redo' }, { command: 'dataGrid.redo', hideDisabled: true },
{ command: 'dataGrid.editJsonDocument', hideDisabled: true }, { command: 'dataGrid.editJsonDocument', hideDisabled: true },
{ command: 'dataGrid.viewJsonDocument', hideDisabled: true },
{ divider: true }, { divider: true },
{ placeTag: 'export' }, { placeTag: 'export' },
{ command: 'dataGrid.generateSqlFromData' }, { command: 'dataGrid.generateSqlFromData' },

View File

@@ -123,6 +123,7 @@
'img free-table': 'mdi mdi-table color-icon-green', 'img free-table': 'mdi mdi-table color-icon-green',
'img macro': 'mdi mdi-hammer-wrench', 'img macro': 'mdi mdi-hammer-wrench',
'img json': 'mdi mdi-code-json icon-magenta',
'img database': 'mdi mdi-database color-icon-gold', 'img database': 'mdi mdi-database color-icon-gold',
'img sqlite-database': 'mdi mdi-database color-icon-blue', 'img sqlite-database': 'mdi mdi-database color-icon-blue',

View File

@@ -23,6 +23,18 @@
</ul> </ul>
<style> <style>
:global(.theme-type-dark) ul {
--json-tree-string-color: #ffc5c5;
--json-tree-symbol-color: #ffc5c5;
--json-tree-boolean-color: #b6c3ff;
--json-tree-function-color: #b6c3ff;
--json-tree-number-color: #bfbdff;
--json-tree-label-color: #e9aaed;
--json-tree-arrow-color: #d4d4d4;
--json-tree-null-color: #dcdcdc;
--json-tree-undefined-color: #dcdcdc;
--json-tree-date-color: #dcdcdc;
}
ul { ul {
--string-color: var(--json-tree-string-color, #cb3f41); --string-color: var(--json-tree-string-color, #cb3f41);
--symbol-color: var(--json-tree-symbol-color, #cb3f41); --symbol-color: var(--json-tree-symbol-color, #cb3f41);

View File

@@ -72,7 +72,7 @@ export default function useEditorData({ tabid, reloadToken = 0, loadFromArgs = n
if (onInitialData) onInitialData(initFallback); if (onInitialData) onInitialData(initFallback);
value = initFallback; value = initFallback;
// move to local forage // move to local forage
await localforage.setItem(localStorageKey, initFallback); await localforage.setItem(localStorageKey, JSON.stringify(initFallback));
localStorage.removeItem(localStorageKey); localStorage.removeItem(localStorageKey);
} else { } else {
const init = await localforage.getItem(localStorageKey); const init = await localforage.getItem(localStorageKey);

View File

@@ -0,0 +1,55 @@
<script lang="ts" context="module">
export function openJsonDocument(json, title = 'JSON') {
openNewTab(
{
title,
icon: 'img json',
tabComponent: 'JsonTab',
},
{ editor: json }
);
}
</script>
<script lang="ts">
import _ from 'lodash';
import ErrorInfo from '../elements/ErrorInfo.svelte';
import JSONTree from '../jsontree/JSONTree.svelte';
import useEditorData from '../query/useEditorData';
import openNewTab from '../utility/openNewTab';
export let selection;
export let showWholeRow = false;
export let tabid;
let json = null;
let error = null;
useEditorData({
tabid,
onInitialData: value => {
json = value;
},
});
</script>
<div class="outer">
<div class="inner">
<JSONTree value={json} expanded />
</div>
</div>
<style>
.outer {
flex: 1;
position: relative;
}
.inner {
overflow: scroll;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
</style>

View File

@@ -16,6 +16,7 @@ import * as QueryDesignTab from './QueryDesignTab.svelte';
import * as CommandListTab from './CommandListTab.svelte'; import * as CommandListTab from './CommandListTab.svelte';
import * as YamlEditorTab from './YamlEditorTab.svelte'; import * as YamlEditorTab from './YamlEditorTab.svelte';
import * as CompareModelTab from './CompareModelTab.svelte'; import * as CompareModelTab from './CompareModelTab.svelte';
import * as JsonTab from './JsonTab.svelte';
export default { export default {
TableDataTab, TableDataTab,
@@ -36,4 +37,5 @@ export default {
CommandListTab, CommandListTab,
YamlEditorTab, YamlEditorTab,
CompareModelTab, CompareModelTab,
JsonTab,
}; };