mirror of
https://github.com/JoshiCodes/knock.git
synced 2026-12-04 15:29:40 +01:00
Skeleton, REST core, variables and JSON editor (M0–M2)
- knock-core: YAML collection format with unknown-field round trip, variable resolution across scopes with secrets and dynamic values, HTTP engine with manual redirects, cookie jar and large-body spill, basic/bearer/API key auth with debug output, assertions and extracts - Tauri app: collection commands, file watcher, SQLite history, keyring-backed secrets - Svelte UI: sidebar tree, tabs, request editor, response viewer, JSON form/code editor with schema hints, environments, settings
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<script lang="ts">
|
||||
import { Resizable, ResizablePanel, ResizableHandle } from '@joshicodes/cock';
|
||||
import UrlBar from './UrlBar.svelte';
|
||||
import RequestPane from './RequestPane.svelte';
|
||||
import ResponsePane from '$lib/views/response/ResponsePane.svelte';
|
||||
import WsView from '$lib/views/ws/WsView.svelte';
|
||||
import Icon from '$lib/ui/Icon.svelte';
|
||||
import { ws, type Tab, snapshot } from '$lib/state/workspace.svelte';
|
||||
import { varsStore } from '$lib/state/vars.svelte';
|
||||
import { api } from '$lib/api';
|
||||
import { normalizeRequest } from '$lib/request';
|
||||
|
||||
let { tab }: { tab: Tab } = $props();
|
||||
|
||||
let env = $derived(ws.env(tab.col));
|
||||
let envEntry = $derived(ws.collection(tab.col)?.environments.find((e) => e.id === env));
|
||||
|
||||
// Keep the variable map in sync with the request, its folder chain and the environment.
|
||||
$effect(() => {
|
||||
varsStore.mask = ws.maskSecrets;
|
||||
varsStore.refresh(tab.col, tab.id, tab.draft, env);
|
||||
// Re-run when vars, auth or URL change; cheap because it is debounced.
|
||||
JSON.stringify(tab.draft?.vars);
|
||||
});
|
||||
|
||||
// Editing a preview tab pins it.
|
||||
$effect(() => {
|
||||
if (tab.preview && ws.isDirty(tab)) tab.preview = false;
|
||||
});
|
||||
|
||||
async function reloadFromDisk() {
|
||||
if (!tab.col || !tab.id) return;
|
||||
const fresh = normalizeRequest(await api.requestGet(tab.col, tab.id));
|
||||
tab.draft = fresh;
|
||||
tab.saved = snapshot(fresh);
|
||||
tab.diskChanged = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex h-full min-h-0 flex-col">
|
||||
{#if envEntry?.protected}
|
||||
<div class="flex shrink-0 items-center gap-2 px-3 py-1 text-[12px] font-bold" style:background={envEntry.color ?? 'var(--method-post)'} style:color="var(--on-accent)">
|
||||
<Icon name="lock" size={12} />
|
||||
Sending to {envEntry.name}
|
||||
</div>
|
||||
{/if}
|
||||
{#if tab.diskChanged}
|
||||
<div class="flex shrink-0 items-center gap-3 border-b border-line bg-post/10 px-3 py-1.5 text-[12px]">
|
||||
<Icon name="alert" size={13} class="text-post" />
|
||||
<span class="flex-1 text-fg">This file changed on disk while you had unsaved edits.</span>
|
||||
<button class="text-accent hover:underline" onclick={reloadFromDisk}>Load the disk version</button>
|
||||
<button class="text-fg-muted hover:text-fg" onclick={() => (tab.diskChanged = false)}>Keep mine</button>
|
||||
</div>
|
||||
{/if}
|
||||
{#if tab.draft?.settings && !tab.draft.settings.verify_tls}
|
||||
<div class="flex shrink-0 items-center gap-2 border-b border-line bg-delete/10 px-3 py-1 text-[12px] text-delete">
|
||||
<Icon name="lock" size={12} />TLS verification is off for this request
|
||||
</div>
|
||||
{/if}
|
||||
<UrlBar {tab} />
|
||||
<div class="min-h-0 flex-1">
|
||||
{#if tab.draft?.type === 'ws'}
|
||||
<WsView {tab} />
|
||||
{:else}
|
||||
{#key ws.layout}
|
||||
<Resizable direction={ws.layout === 'columns' ? 'horizontal' : 'vertical'}>
|
||||
<ResizablePanel size={50} min={20}>
|
||||
<RequestPane {tab} />
|
||||
</ResizablePanel>
|
||||
<ResizableHandle />
|
||||
<ResizablePanel min={20}>
|
||||
<div class="h-full {ws.layout === 'columns' ? 'border-l' : 'border-t'} border-line">
|
||||
<ResponsePane {tab} />
|
||||
</div>
|
||||
</ResizablePanel>
|
||||
</Resizable>
|
||||
{/key}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user