Split the workbench markup into region components
Phase 5-1. Workbench.svelte keeps the state and the commands. Six components now draw its regions, each with its own styles: - WorkbenchHeader: the side pane buttons, the working tabs, the actions, and the window controls. - PluginRibbon: the ribbon of plugin views. - LeftPane: the plugin sidebar, files, search, bookmarks, and the workspace footer. - DocumentArea: the plugin editor panes, the document panes, and the save conflict banners. - RightPane: the outline and the backlinks. - StatusBar: the status line. Each component keeps the root element of its region, so the shell grid places them as before. Workbench.svelte has about 450 fewer lines. There is no visible change. pnpm check passes. pnpm test: 451 of 451 pass. Full smoke suite: 95 passed, 2 known. plugins/access failed one time and passed on retry and 3 of 3 times alone.
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
<script lang="ts">
|
||||
// The document area: plugin editor panes over the document panes, with the save conflict banner of each document.
|
||||
import type { ComponentProps } from "svelte";
|
||||
import { t } from "$lib/i18n";
|
||||
import PluginEditor from "$lib/plugins/PluginEditor.svelte";
|
||||
import { pluginEditors, pluginView, selectPluginEditor } from "$lib/plugins/external";
|
||||
import type { Documents } from "$lib/workspace/documents.svelte";
|
||||
import type { OpenBuffer } from "$lib/workspace/types";
|
||||
import EditorPane from "./EditorPane.svelte";
|
||||
import TabBar from "./TabBar.svelte";
|
||||
|
||||
type EditorProps = ComponentProps<typeof EditorPane>;
|
||||
type DocumentView = { id: string; reading: boolean; buffer: OpenBuffer | null; bounds: { width: number } };
|
||||
type Bounds = { left: number; top: number; width: number; height: number };
|
||||
type Props = {
|
||||
editorPluginVisible: boolean;
|
||||
split: boolean;
|
||||
pluginBounds: Record<string, Bounds | undefined>;
|
||||
tabBar: ComponentProps<typeof TabBar>;
|
||||
pluginPaneComponents: Record<string, PluginEditor | undefined>;
|
||||
documentViews: DocumentView[];
|
||||
activePane: string;
|
||||
paneComponents: Record<string, EditorPane | undefined>;
|
||||
documents: Documents | null;
|
||||
tabs: OpenBuffer[];
|
||||
hasWorkspace: boolean;
|
||||
browserOpening: boolean;
|
||||
focusLine: number | null;
|
||||
onFocusPane: (id: string) => void;
|
||||
onCloseSplit: (id: string) => void;
|
||||
onSaveCopy: (buffer: OpenBuffer | null) => void;
|
||||
onOpenWorkspace: () => void;
|
||||
onNewFile: () => void;
|
||||
onNewNote: (event?: MouseEvent) => void;
|
||||
onQuickOpen: () => void;
|
||||
onOpenBrowser?: () => void;
|
||||
onChange: EditorProps["onChange"];
|
||||
onInsertImage: (file: File, buffer: OpenBuffer | null) => Promise<string | null>;
|
||||
onRenameTitle: EditorProps["onRenameTitle"];
|
||||
tableActions: (pane: DocumentView) => EditorProps["tableActions"];
|
||||
linkActions: (pane: DocumentView) => EditorProps["linkActions"];
|
||||
onToggleReading: (pane: DocumentView) => void;
|
||||
onToggleChrome: (pane: DocumentView) => void;
|
||||
onOpenLink: (pane: DocumentView, kind: "md" | "wiki", target: string) => void;
|
||||
};
|
||||
let { editorPluginVisible, split, pluginBounds, tabBar, pluginPaneComponents = $bindable(), documentViews, activePane, paneComponents = $bindable(),
|
||||
documents, tabs, hasWorkspace, browserOpening, focusLine, onFocusPane, onCloseSplit, onSaveCopy, onOpenWorkspace, onNewFile, onNewNote,
|
||||
onQuickOpen, onOpenBrowser, onChange, onInsertImage, onRenameTitle, tableActions, linkActions, onToggleReading, onToggleChrome, onOpenLink }: Props = $props();
|
||||
</script>
|
||||
|
||||
<main class="center">
|
||||
<div class="plugin-panes" class:inactive={!editorPluginVisible}>
|
||||
{#each $pluginEditors as pane (pane.key)}
|
||||
{@const bounds = pluginBounds[pane.key]}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions (Focus selects the pane that owns the input.) -->
|
||||
<div class="plugin-pane" class:inactive={!bounds} class:split class:focused={$pluginView?.key === pane.key}
|
||||
style:left={`${bounds?.left ?? 0}%`} style:top={`${bounds?.top ?? 0}%`}
|
||||
style:width={`${bounds?.width ?? 100}%`} style:height={`${bounds?.height ?? 100}%`}
|
||||
onfocusin={() => { if ($pluginView?.key !== pane.key) selectPluginEditor(pane); }}
|
||||
onpointerdown={() => { if ($pluginView?.key !== pane.key) selectPluginEditor(pane); }}>
|
||||
{#if split && bounds}
|
||||
<TabBar {...tabBar} tabs={tabBar.tabs.filter(tab => tab.id === pane.key)} />
|
||||
{/if}
|
||||
<PluginEditor bind:this={pluginPaneComponents[pane.key]} view={pane} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="editor-host" class:plugin-covered={editorPluginVisible}>
|
||||
<div class="document-panes" class:split={documentViews.length > 1}>
|
||||
{#each documentViews as pane (pane.id)}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions (Focus identifies the document for shared commands.) -->
|
||||
<div class="document-pane" class:focused={activePane === pane.id}
|
||||
data-document-pane={pane.id} data-document-path={pane.buffer?.relPath ?? ""}
|
||||
style:--pane-weight={pane.bounds.width}
|
||||
onpointerdowncapture={() => onFocusPane(pane.id)}
|
||||
onfocusin={() => onFocusPane(pane.id)}>
|
||||
{#if pane.buffer?.diskError}
|
||||
<div class="conflict" role="alert"><span>{pane.buffer.diskError}</span><button onclick={() => onSaveCopy(pane.buffer)}>{$t("Save a copy")}</button><button onclick={() => void documents?.refresh()}>{$t("Retry")}</button></div>
|
||||
{:else if pane.buffer?.diskContents != null}
|
||||
<div class="conflict" role="alert">
|
||||
<span>{$t("This file changed on disk. Your edits are preserved. Review both versions before saving.")}</span>
|
||||
<button onclick={() => { if (pane.buffer) documents?.resolve(pane.buffer.id, true); }}>{$t("Use disk version")}</button>
|
||||
<button onclick={() => { if (pane.buffer) documents?.resolve(pane.buffer.id, false); }}>{$t("Keep my edits")}</button>
|
||||
<button onclick={() => onSaveCopy(pane.buffer)}>{$t("Save a copy")}</button>
|
||||
</div>
|
||||
<details class="disk-review"><summary>{$t("View disk version")}</summary><pre>{pane.buffer.diskContents}</pre></details>
|
||||
{/if}
|
||||
<EditorPane
|
||||
bind:this={paneComponents[pane.id]}
|
||||
{tabs}
|
||||
active={activePane === pane.id}
|
||||
onCloseSplit={documentViews.length > 1 ? () => onCloseSplit(pane.id) : undefined}
|
||||
{hasWorkspace}
|
||||
{onOpenWorkspace}
|
||||
{onNewFile}
|
||||
{onNewNote}
|
||||
{onQuickOpen}
|
||||
{onOpenBrowser}
|
||||
{browserOpening}
|
||||
buffer={pane.buffer}
|
||||
chrome={pane.buffer?.chromeOverride ?? pane.buffer?.chrome ?? "Writing"}
|
||||
reading={pane.reading}
|
||||
focusLine={activePane === pane.id ? focusLine : null}
|
||||
{onChange}
|
||||
onInsertImage={file => onInsertImage(file, pane.buffer)}
|
||||
{onRenameTitle}
|
||||
tableActions={tableActions(pane)}
|
||||
linkActions={linkActions(pane)}
|
||||
onToggleReading={() => onToggleReading(pane)}
|
||||
onToggleChrome={() => onToggleChrome(pane)}
|
||||
onOpenLink={(kind, target) => onOpenLink(pane, kind, target)}
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.center {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.conflict { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; background: var(--rs-bg-active); border-bottom: 1px solid var(--rs-warn); }
|
||||
.conflict span { flex: 1 1 300px; }
|
||||
.conflict button { border: 1px solid var(--rs-border); background: var(--rs-bg); padding: 4px 8px; }
|
||||
.disk-review { padding: 8px 12px; max-height: 35vh; overflow: auto; flex: 0 0 auto; }
|
||||
.disk-review pre { white-space: pre-wrap; user-select: text; }
|
||||
|
||||
.editor-host {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
container-type: inline-size;
|
||||
}
|
||||
|
||||
.document-panes { flex: 1; min-height: 0; display: flex; overflow: hidden; }
|
||||
.document-pane { flex: var(--pane-weight) 1 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
|
||||
.document-pane + .document-pane { border-left: 1px solid var(--rs-border); }
|
||||
.document-panes.split .document-pane.focused :global(.chrome-bar) { background: var(--rs-bg-active); }
|
||||
@container (max-width: 640px) {
|
||||
.document-panes.split { flex-direction: column; overflow-y: auto; }
|
||||
.document-panes.split .document-pane { flex: 1 0 320px; }
|
||||
.document-pane + .document-pane { border-left: 0; border-top: 1px solid var(--rs-border); }
|
||||
}
|
||||
.editor-host.plugin-covered { display: none; }
|
||||
.plugin-panes { position: relative; flex: 1; min-height: 0; min-width: 0; overflow: hidden; }
|
||||
.plugin-pane { position: absolute; display: flex; flex-direction: column; min-width: 0; min-height: 0; box-sizing: border-box; }
|
||||
.plugin-pane.split { border: 1px solid var(--rs-border); }
|
||||
.plugin-pane.split.focused { border-color: var(--rs-accent); }
|
||||
.plugin-panes.inactive, .plugin-pane.inactive { display: none; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user