mirror of
https://github.com/JoshiCodes/knock.git
synced 2026-12-04 15:19:41 +01:00
- Welcome screen: the mark as a peephole and actions as plain lines instead of a card grid and key chips - Title bar: search as a small button, documentation (F1) next to it; help entries in the command palette - The vertical cyan rule marks what needs attention (redirect URI, inactive environment, banners) instead of nested framed boxes - JSON form: fixed key column so types and values line up at any depth, type glyphs in the code view's colours, row actions float on hover - Crisper corners; Send carries the mark; Saved instead of a disabled Save button - Open tabs are restored after a restart again
81 lines
3.0 KiB
Svelte
81 lines
3.0 KiB
Svelte
<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-l-2 border-b-line border-l-post bg-post/8 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-l-2 border-b-line border-l-delete bg-delete/8 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>
|