mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 22:43:58 +00:00
jsonl preview
This commit is contained in:
@@ -266,11 +266,16 @@ registerCommand({
|
|||||||
name: 'JSON Lines',
|
name: 'JSON Lines',
|
||||||
menuName: 'New JSON lines file',
|
menuName: 'New JSON lines file',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
openNewTab({
|
openNewTab(
|
||||||
|
{
|
||||||
title: 'Lines #',
|
title: 'Lines #',
|
||||||
icon: 'img archive',
|
icon: 'img archive',
|
||||||
tabComponent: 'JsonLinesEditorTab',
|
tabComponent: 'JsonLinesEditorTab',
|
||||||
});
|
},
|
||||||
|
{
|
||||||
|
editor: '{"col1": "val1", "col2": "val2"}',
|
||||||
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,24 @@
|
|||||||
testEnabled: () => getCurrentEditor() != null,
|
testEnabled: () => getCurrentEditor() != null,
|
||||||
onClick: () => getCurrentEditor().preview(),
|
onClick: () => getCurrentEditor().preview(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'jsonl.previewNewTab',
|
||||||
|
category: 'JSON Lines editor',
|
||||||
|
name: 'Preview in new tab',
|
||||||
|
icon: 'icon preview',
|
||||||
|
testEnabled: () => getCurrentEditor() != null,
|
||||||
|
onClick: () => getCurrentEditor().previewMewTab(),
|
||||||
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'jsonl.closePreview',
|
||||||
|
category: 'JSON Lines editor',
|
||||||
|
name: 'Close preview',
|
||||||
|
icon: 'icon close',
|
||||||
|
testEnabled: () => getCurrentEditor()?.isPreview(),
|
||||||
|
onClick: () => getCurrentEditor().closePreview(),
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -53,11 +71,17 @@
|
|||||||
import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
|
import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
|
||||||
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
|
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
|
import VerticalSplitter from '../elements/VerticalSplitter.svelte';
|
||||||
|
import JslDataGrid from '../datagrid/JslDataGrid.svelte';
|
||||||
|
import runCommand from '../commands/runCommand';
|
||||||
|
import ToolStripSplitDropDownButton from '../buttons/ToolStripSplitDropDownButton.svelte';
|
||||||
|
|
||||||
export let tabid;
|
export let tabid;
|
||||||
export let archiveFolder;
|
export let archiveFolder;
|
||||||
export let archiveFile;
|
export let archiveFile;
|
||||||
|
|
||||||
|
let jslid = null;
|
||||||
|
|
||||||
const tabVisible: any = getContext('tabVisible');
|
const tabVisible: any = getContext('tabVisible');
|
||||||
|
|
||||||
export const activator = createActivator('JsonLinesEditorTab', false);
|
export const activator = createActivator('JsonLinesEditorTab', false);
|
||||||
@@ -84,6 +108,14 @@
|
|||||||
return tabid;
|
return tabid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPreview() {
|
||||||
|
return !!jslid;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function closePreview() {
|
||||||
|
jslid = null;
|
||||||
|
}
|
||||||
|
|
||||||
export function save() {
|
export function save() {
|
||||||
showModal(SaveArchiveModal, {
|
showModal(SaveArchiveModal, {
|
||||||
folder: archiveFolder,
|
folder: archiveFolder,
|
||||||
@@ -92,19 +124,27 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function preview() {
|
export async function previewMewTab() {
|
||||||
const jslid = uuidv1();
|
const jslid = uuidv1();
|
||||||
await apiCall('jsldata/save-text', { jslid, text: $editorState.value || '' });
|
await apiCall('jsldata/save-text', { jslid, text: $editorState.value || '' });
|
||||||
|
|
||||||
openNewTab({
|
openNewTab(
|
||||||
|
{
|
||||||
title: 'Preview #',
|
title: 'Preview #',
|
||||||
icon: 'img archive',
|
icon: 'img archive',
|
||||||
tabComponent: 'ArchiveFileTab',
|
tabComponent: 'ArchiveFileTab',
|
||||||
forceNewTab: true,
|
|
||||||
props: {
|
props: {
|
||||||
jslid,
|
jslid,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
undefined,
|
||||||
|
{ forceNewTab: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function preview() {
|
||||||
|
jslid = uuidv1();
|
||||||
|
await apiCall('jsldata/save-text', { jslid, text: $editorState.value || '' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const doSave = async (folder, file) => {
|
const doSave = async (folder, file) => {
|
||||||
@@ -134,6 +174,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ToolStripContainer>
|
<ToolStripContainer>
|
||||||
|
<VerticalSplitter isSplitter={jslid}>
|
||||||
|
<svelte:fragment slot="1">
|
||||||
<AceEditor
|
<AceEditor
|
||||||
value={$editorState.value || ''}
|
value={$editorState.value || ''}
|
||||||
menu={createMenu()}
|
menu={createMenu()}
|
||||||
@@ -145,8 +187,24 @@
|
|||||||
bind:this={domEditor}
|
bind:this={domEditor}
|
||||||
mode="json"
|
mode="json"
|
||||||
/>
|
/>
|
||||||
|
</svelte:fragment>
|
||||||
|
<svelte:fragment slot="2">
|
||||||
|
{#if jslid}
|
||||||
|
{#key jslid}
|
||||||
|
<JslDataGrid {jslid} supportsReload />
|
||||||
|
{/key}
|
||||||
|
{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
</VerticalSplitter>
|
||||||
|
|
||||||
<svelte:fragment slot="toolstrip">
|
<svelte:fragment slot="toolstrip">
|
||||||
<ToolStripCommandButton command="jsonl.save" />
|
<ToolStripCommandButton command="jsonl.save" />
|
||||||
<ToolStripCommandButton command="jsonl.preview" />
|
<ToolStripCommandButton
|
||||||
|
command="jsonl.preview"
|
||||||
|
component={ToolStripSplitDropDownButton}
|
||||||
|
menu={[{ command: 'jsonl.preview' }, { command: 'jsonl.previewNewTab' }]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ToolStripCommandButton command="jsonl.closePreview" />
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
</ToolStripContainer>
|
</ToolStripContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user