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:
Knotty Wyvern
2026-10-28 18:40:50 -07:00
parent 5483881bc2
commit b2348d0fe8
8 changed files with 677 additions and 454 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ A new command needs an entry in `generate_handler!` in `lib.rs`, in the command
| Folder | Responsibility | | Folder | Responsibility |
| --- | --- | | --- | --- |
| `layout/` | The app shell (`Workbench.svelte`), the file tree, tabs, panes, Settings, and dialogs | | `layout/` | The app shell: `Workbench.svelte` holds the state and the commands, and `WorkbenchHeader`, `PluginRibbon`, `LeftPane`, `DocumentArea`, `RightPane`, and `StatusBar` draw its regions. Also the file tree, tabs, panes, Settings, and dialogs |
| `editor/` | The document editor (`DocumentEditor.svelte`) with its Write and Source configurations, Markdown lists, tables, links, images, and editor menus | | `editor/` | The document editor (`DocumentEditor.svelte`) with its Write and Source configurations, Markdown lists, tables, links, images, and editor menus |
| `formulas/` | Table formulas: the parser and evaluator (`engine.ts`), the rendered results, the formula help, and the `tableFormulas` setting (`index.ts`) | | `formulas/` | Table formulas: the parser and evaluator (`engine.ts`), the rendered results, the formula help, and the `tableFormulas` setting (`index.ts`) |
| `workspace/` | Tauri wrappers, document buffers, the workspace session (`session.svelte.ts`: marks, renames, change events, and the note index), paths, templates, and tab transfer (`tabTransfer.ts`) | | `workspace/` | Tauri wrappers, document buffers, the workspace session (`session.svelte.ts`: marks, renames, change events, and the note index), paths, templates, and tab transfer (`tabTransfer.ts`) |
+161
View File
@@ -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>
+171
View File
@@ -0,0 +1,171 @@
<script lang="ts">
// The left pane: a plugin sidebar view, or the files, search, and bookmarks views, and the workspace footer.
import { t } from "$lib/i18n";
import IconButton from "$lib/ui/IconButton.svelte";
import PluginEditor from "$lib/plugins/PluginEditor.svelte";
import BrowserSlot from "$lib/plugins/BrowserSlot.svelte";
import { pluginSidebar } from "$lib/plugins/external";
import type { WorkspaceSession } from "$lib/workspace/session.svelte";
import type { TreeEntry, WorkspaceInfo } from "$lib/workspace/types";
import FileTree from "./FileTree.svelte";
import SearchPane from "./SearchPane.svelte";
import BookmarksPane from "./BookmarksPane.svelte";
type Props = {
workspace: WorkspaceInfo | null;
session: WorkspaceSession;
leftView: "files" | "search" | "bookmarks";
keysActive: boolean;
showInternal: boolean;
activePath: string | null;
searchRequest: { text: string; id: number } | null;
fileTree?: FileTree;
workspaceAnchor?: HTMLDivElement;
onOpenFile: (entry: TreeEntry, line?: number, target?: "current" | "new") => void;
onCreated: (entry: TreeEntry) => void;
onSaveTemplate: (entry: TreeEntry) => void;
onManageTemplates: () => void;
onStatus: (message: string) => void;
onChooseWorkspace: () => void;
onHelp: () => void;
onSettings: () => void;
};
let { workspace, session, leftView, keysActive, showInternal, activePath, searchRequest, fileTree = $bindable(), workspaceAnchor = $bindable(),
onOpenFile, onCreated, onSaveTemplate, onManageTemplates, onStatus, onChooseWorkspace, onHelp, onSettings }: Props = $props();
</script>
<aside class="left">
<div class="left-body">
{#if $pluginSidebar}
{#key $pluginSidebar.key}<PluginEditor view={$pluginSidebar} />{/key}
{/if}
<div class="native-left" class:sidebar-covered={!!$pluginSidebar}>
{#if !workspace}
{#if leftView === "bookmarks"}<BrowserSlot kind="bookmarks" />{:else}<p class="placeholder">{$t("No folder is open.")}</p>{/if}
{:else}
<div class="left-stack">
<div class="left-layer" class:shown={leftView === "files"}>
<FileTree
bind:this={fileTree}
workspaceRoot={workspace.root}
{showInternal}
{onSaveTemplate}
{onManageTemplates}
{activePath}
onOpenFile={(entry, newTab) => onOpenFile(entry, undefined, newTab ? "new" : "current")}
{session}
{keysActive}
{onCreated}
{onStatus}
/>
</div>
{#if leftView === "search"}
<SearchPane {searchRequest} onOpen={(entry, line) => onOpenFile(entry, line)} />
{:else if leftView === "bookmarks"}
<BookmarksPane {session} onOpen={(entry) => onOpenFile(entry)} />
{/if}
</div>
{/if}
</div>
</div>
<div class="left-footer">
<div class="footer-start" bind:this={workspaceAnchor}>
<IconButton icon="folder-open" label={$t("Open folder")} onclick={onChooseWorkspace} />
<span class="ws">{workspace ? workspace.name : $t("No workspace")}</span>
</div>
<div class="footer-actions">
<IconButton icon="help" label={$t("Help and about (F1)")} onclick={onHelp} />
<IconButton icon="settings" label={$t("Settings (Ctrl+,)")} onclick={onSettings} />
</div>
</div>
</aside>
<style>
.left {
display: flex;
flex-direction: column;
min-width: 0;
min-height: 0;
overflow: hidden;
background: var(--rs-workarea-sidebar-bg);
}
.left-body {
flex: 1;
min-height: 0;
overflow: hidden;
display: flex;
flex-direction: column;
}
.left-body > :global(*) {
flex: 1;
min-height: 0;
}
.native-left { display: flex; flex-direction: column; min-height: 0; }
.native-left.sidebar-covered { display: none; }
.left-stack {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.left-layer {
display: none;
flex: 1;
min-height: 0;
}
.left-layer.shown {
display: flex;
flex-direction: column;
}
.left-layer.shown > :global(*) {
flex: 1;
min-height: 0;
}
.left-stack > :global(.pane) {
flex: 1;
min-height: 0;
}
.left-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 4px 6px;
border-top: 1px solid var(--rs-border);
flex: 0 0 auto;
}
.footer-start {
flex: 1;
display: flex;
align-items: center;
gap: 2px;
min-width: 0;
}
.footer-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.footer-actions :global(.icon-btn) { width: 32px; height: 32px; flex-basis: 32px; }
.ws {
color: var(--rs-text-dim);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
flex: 1;
}
.placeholder {
margin: 12px;
color: var(--rs-text-dim);
}
</style>
+39
View File
@@ -0,0 +1,39 @@
<script lang="ts">
// The left ribbon of plugin views. The shell gives it width only when a plugin uses it.
import { t } from "$lib/i18n";
import IconButton from "$lib/ui/IconButton.svelte";
import { openPluginView, pluginEditorActive, pluginSidebar, pluginView } from "$lib/plugins/external";
let { items }: { items: { owner: string; id: string; title: string; icon?: string }[] } = $props();
</script>
<nav class="plugin-ribbon" aria-label={$t("Plugin shortcuts")} hidden={items.length === 0}>
{#each items as item (`${item.owner}:${item.id}`)}
<IconButton
icon={item.icon === "list" || item.icon === "kanban" || item.icon === "globe" || item.icon === "git" ? item.icon : "puzzle"}
label={item.title}
side="right"
active={($pluginSidebar?.owner === item.owner && $pluginSidebar?.id === item.id) || $pluginView?.owner === item.owner && $pluginView?.id === item.id && !$pluginView?.document && ($pluginView?.placement === "dialog" || $pluginEditorActive)}
onclick={() => openPluginView(item.owner, item.id)}
/>
{/each}
</nav>
<style>
.plugin-ribbon {
grid-column: 1;
grid-row: 2;
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
min-height: 0;
padding: 6px 5px;
overflow-y: auto;
background: var(--rs-workarea-sidebar-bg);
border-right: 1px solid var(--rs-border);
}
.plugin-ribbon[hidden] { display: block; visibility: hidden; padding: 0; border: 0; }
.plugin-ribbon :global(.icon-btn) { width: 32px; height: 32px; flex-basis: 32px; }
</style>
+33
View File
@@ -0,0 +1,33 @@
<script lang="ts">
// The right pane: the outline of the active document and its backlinks.
import type { ComponentProps } from "svelte";
import type { WorkspaceSession } from "$lib/workspace/session.svelte";
import type { Backlink } from "$lib/workspace/noteIndex";
import OutlinePane from "./OutlinePane.svelte";
import Backlinks from "./Backlinks.svelte";
type Props = {
outlineItems: ComponentProps<typeof OutlinePane>["items"];
onJump: (line: number) => void;
showBacklinks: boolean;
backlinks: Backlink[];
session: WorkspaceSession;
onOpenBacklink: (entry: Backlink) => void;
};
let { outlineItems, onJump, showBacklinks, backlinks, session, onOpenBacklink }: Props = $props();
</script>
<aside class="right">
<div class="outline-area">
<OutlinePane items={outlineItems} {onJump} />
</div>
{#if showBacklinks}
<Backlinks entries={backlinks} busy={session.indexBusy} error={session.indexError} onOpen={onOpenBacklink} onRebuild={() => void session.rebuildIndex()} />
{/if}
</aside>
<style>
.right { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--rs-workarea-sidebar-bg); }
.outline-area { flex: 1; min-height: 80px; overflow: hidden; }
.right > :global(.backlinks) { flex: 0 1 auto; max-height: 50%; }
</style>
+35
View File
@@ -0,0 +1,35 @@
<script lang="ts">
// The status bar at the bottom of the workbench.
import { t } from "$lib/i18n";
let { message, watchMode, source }: { message: string; watchMode: string | null; source: boolean } = $props();
</script>
<footer class="status">
<span>{message}</span>
{#if watchMode}
<span>{watchMode} watch</span>
{/if}
<span>{source ? $t("IDE") : $t("Writer")}</span>
</footer>
<style>
.status {
grid-column: 1 / -1;
display: flex;
justify-content: space-between;
gap: 12px;
padding: 0 10px;
background: var(--rs-bg-elevated);
border-top: 1px solid var(--rs-border);
color: var(--rs-text-dim);
font-size: 12px;
}
.status :first-child {
color: var(--rs-text);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
+79 -426
View File
@@ -1,9 +1,7 @@
<script lang="ts"> <script lang="ts">
import { t } from "$lib/i18n"; import { t } from "$lib/i18n";
import TerminalSlot from "$lib/plugins/TerminalSlot.svelte"; import TerminalSlot from "$lib/plugins/TerminalSlot.svelte";
import PluginTools from "$lib/plugins/PluginTools.svelte"; import type PluginEditor from "$lib/plugins/PluginEditor.svelte";
import PluginAccessMenu from "$lib/plugins/PluginAccessMenu.svelte";
import PluginEditor from "$lib/plugins/PluginEditor.svelte";
import { pluginSplits, pinPluginEditor, pluginTabActions, pluginTabState, restorePluginTab, pluginTabDragData, dropPluginTab, waitForPluginStartup } from "$lib/plugins/external"; import { pluginSplits, pinPluginEditor, pluginTabActions, pluginTabState, restorePluginTab, pluginTabDragData, dropPluginTab, waitForPluginStartup } from "$lib/plugins/external";
import { containsPane, paneBounds } from "$lib/workspace/splitLayout"; import { containsPane, paneBounds } from "$lib/workspace/splitLayout";
import { pluginSidebar, closePluginSidebar, pluginNavigation, openPluginView, pluginView, pluginEditors, pluginEditorActive, selectPluginEditor, closePluginEditor, openPluginDocument, renamePluginDocuments, removePluginDocuments, notifyPluginWorkspace, guardPluginWrites, handlePluginFileOpen, handlePluginDocumentRename, cancelPluginDocumentOpen, type OpenPluginView } from "$lib/plugins/external"; import { pluginSidebar, closePluginSidebar, pluginNavigation, openPluginView, pluginView, pluginEditors, pluginEditorActive, selectPluginEditor, closePluginEditor, openPluginDocument, renamePluginDocuments, removePluginDocuments, notifyPluginWorkspace, guardPluginWrites, handlePluginFileOpen, handlePluginDocumentRename, cancelPluginDocumentOpen, type OpenPluginView } from "$lib/plugins/external";
@@ -32,23 +30,20 @@
import WorkspacePicker from "./WorkspacePicker.svelte"; import WorkspacePicker from "./WorkspacePicker.svelte";
import SettingsDialog from "./SettingsDialog.svelte"; import SettingsDialog from "./SettingsDialog.svelte";
import { THEME_EDITOR_EVENT } from "$lib/theme/themeEditorRequest"; import { THEME_EDITOR_EVENT } from "$lib/theme/themeEditorRequest";
import BrowserSlot from "$lib/plugins/BrowserSlot.svelte";
import { DEFAULT_SETTINGS, readSettings, saveSettings, type AppSettings } from "$lib/workspace/settings"; import { DEFAULT_SETTINGS, readSettings, saveSettings, type AppSettings } from "$lib/workspace/settings";
import { onSettingsChange, takeSettingsNotice } from "$lib/settings/store"; import { onSettingsChange, takeSettingsNotice } from "$lib/settings/store";
import { TAB_TRANSFER_ID, cancelTabTransfer, finishTabTransfer, offerTabTransfer, onTabTransferAccepted, parseTabTransfer, takeTabTransfer } from "$lib/workspace/tabTransfer"; import { TAB_TRANSFER_ID, cancelTabTransfer, finishTabTransfer, offerTabTransfer, onTabTransferAccepted, parseTabTransfer, takeTabTransfer } from "$lib/workspace/tabTransfer";
import { DEFAULT_WORKBENCH_LAYOUT, WORKBENCH_LAYOUT_KEY, parseWorkbenchLayout, saveWorkbenchLayout, type WorkbenchLayout } from "$lib/workspace/workbenchLayout"; import { DEFAULT_WORKBENCH_LAYOUT, WORKBENCH_LAYOUT_KEY, parseWorkbenchLayout, saveWorkbenchLayout, type WorkbenchLayout } from "$lib/workspace/workbenchLayout";
import FileTree from "./FileTree.svelte"; import type FileTree from "./FileTree.svelte";
import { preferenceKeys, workbenchCommand, type WorkbenchCommand } from "./workbenchKeys"; import { preferenceKeys, workbenchCommand, type WorkbenchCommand } from "./workbenchKeys";
import EditorPane from "./EditorPane.svelte"; import type EditorPane from "./EditorPane.svelte";
import TabBar from "./TabBar.svelte"; import WorkbenchHeader from "./WorkbenchHeader.svelte";
import OutlinePane from "./OutlinePane.svelte"; import PluginRibbon from "./PluginRibbon.svelte";
import Backlinks from "./Backlinks.svelte"; import LeftPane from "./LeftPane.svelte";
import DocumentArea from "./DocumentArea.svelte";
import RightPane from "./RightPane.svelte";
import StatusBar from "./StatusBar.svelte";
import type { Backlink } from "$lib/workspace/noteIndex"; import type { Backlink } from "$lib/workspace/noteIndex";
import IconButton from "$lib/ui/IconButton.svelte";
import WindowControls from "$lib/ui/WindowControls.svelte";
import SearchPane from "./SearchPane.svelte";
import BookmarksPane from "./BookmarksPane.svelte";
import { buildOutline } from "$lib/workspace/outline"; import { buildOutline } from "$lib/workspace/outline";
import { import {
onWorkspaceEvent, onWorkspaceEvent,
@@ -344,6 +339,10 @@
const activeTabPath = $derived(editorPluginVisible && $pluginView ? `plugin:${$pluginView.key}` : activePath); const activeTabPath = $derived(editorPluginVisible && $pluginView ? `plugin:${$pluginView.key}` : activePath);
const activeSplit = $derived($pluginSplits.find(tree => $pluginView && containsPane(tree, $pluginView.key))); const activeSplit = $derived($pluginSplits.find(tree => $pluginView && containsPane(tree, $pluginView.key)));
const pluginBounds = $derived(activeSplit ? paneBounds(activeSplit) : $pluginView ? paneBounds($pluginView.key) : {}); const pluginBounds = $derived(activeSplit ? paneBounds(activeSplit) : $pluginView ? paneBounds($pluginView.key) : {});
// The working tabs, for the header and for the tab bar of each plugin pane in a split.
const tabBarProps = $derived({ tabs: workingTabs, activePath: activeTabPath, onSelect: selectWorkingTab, onClose: closeTab,
onCloseTabs: (path: string, scope: TabCloseScope) => void closeTabs(path, scope), onPin: pinWorkingTab, fileActions: workingTabFileActions,
tabActions: workingTabActions, onMove: moveWorkingTab, tabDragData: workingTabDragData, onDropTab: (data: string, index: number) => void receiveTab(data, index) });
$effect(() => { $effect(() => {
const order = workingTabs.map(tab => tab.id); const order = workingTabs.map(tab => tab.id);
if (order.length !== tabOrder.length || order.some((id, index) => id !== tabOrder[index])) tabOrder = order; if (order.length !== tabOrder.length || order.some((id, index) => id !== tabOrder[index])) tabOrder = order;
@@ -1182,126 +1181,50 @@
onpointerleave={() => (dragging = null)} onpointerleave={() => (dragging = null)}
> >
<div class="workarea-background" aria-hidden="true"></div> <div class="workarea-background" aria-hidden="true"></div>
<header class="header" data-tauri-drag-region> <WorkbenchHeader
<div class="header-left" data-tauri-drag-region> detached={transferredWindow}
{#if !transferredWindow} {desktop}
<IconButton {leftOpen}
icon="files" {leftView}
label={$t("Files")} {sidebarNavigation}
active={leftOpen && !$pluginSidebar && leftView === "files"} onSelectLeft={selectLeft}
onclick={() => selectLeft("files")} tabBar={{ ...tabBarProps, onDetach: (tab) => { void detachTab(tab); } }}
onNewTab={newTab}
canOpenBrowser={!!browserContribution?.newTab}
{browserOpening}
onOpenBrowser={() => void openBrowser()}
saveDisabled={editorPluginVisible || !dirty || saving}
onSave={() => void save()}
{terminalEnabled}
{terminalOpen}
onToggleTerminal={toggleTerminal}
{rightOpen}
onToggleRight={() => (rightOpen = !rightOpen)}
onError={(message) => error = message}
/> />
<IconButton
icon="search"
label={$t("Search")}
active={leftOpen && !$pluginSidebar && leftView === "search"}
onclick={() => selectLeft("search")}
/>
<IconButton
icon="bookmark"
label={$t("Bookmarks")}
active={leftOpen && !$pluginSidebar && leftView === "bookmarks"}
onclick={() => selectLeft("bookmarks")}
/>
{#each sidebarNavigation as item (`${item.owner}:${item.id}`)}
<IconButton
icon={item.icon === "list" || item.icon === "kanban" || item.icon === "globe" || item.icon === "git" ? item.icon : "puzzle"}
label={item.title}
active={leftOpen && $pluginSidebar?.owner === item.owner && $pluginSidebar?.id === item.id}
onclick={() => openPluginView(item.owner, item.id)}
/>
{/each}
{/if}
</div>
<div class="header-center" data-tauri-drag-region>
<TabBar tabs={workingTabs} activePath={activeTabPath} onSelect={selectWorkingTab} onClose={closeTab}
onCloseTabs={(path, scope) => void closeTabs(path, scope)} onPin={pinWorkingTab}
fileActions={workingTabFileActions} tabActions={workingTabActions} onMove={moveWorkingTab}
onDetach={(tab) => { void detachTab(tab); }}
tabDragData={workingTabDragData} onDropTab={(data, index) => void receiveTab(data, index)} />
<IconButton icon="plus" label={$t("New tab (Ctrl T)")} onclick={newTab} />
{#if desktop}<div class="window-drag-space" data-tauri-drag-region></div>{/if}
</div>
<div class="header-right" data-tauri-drag-region>
{#if browserContribution?.newTab}<IconButton icon="globe" label={$t("New browser tab")} disabled={browserOpening} onclick={() => void openBrowser()} />{/if}
<PluginAccessMenu surface="open" compact />
<PluginTools />
<PluginAccessMenu surface="commands" compact />
<IconButton icon="save" label={$t("Save")} disabled={editorPluginVisible || !dirty || saving} onclick={() => void save()} />
{#if terminalEnabled}<IconButton icon="terminal" label={$t("Terminal")} active={terminalOpen} onclick={toggleTerminal} />{/if}
{#if !transferredWindow}<IconButton
icon="panel-right"
label={rightOpen ? $t("Hide outline") : $t("Show outline")}
active={rightOpen}
onclick={() => (rightOpen = !rightOpen)}
/>{/if}
{#if desktop}<WindowControls onError={(message) => error = message} />{/if}
</div>
</header>
{#if !transferredWindow}<nav class="plugin-ribbon" aria-label={$t("Plugin shortcuts")} hidden={ribbonNavigation.length === 0}> {#if !transferredWindow}<PluginRibbon items={ribbonNavigation} />{/if}
{#each ribbonNavigation as item (`${item.owner}:${item.id}`)}
<IconButton
icon={item.icon === "list" || item.icon === "kanban" || item.icon === "globe" || item.icon === "git" ? item.icon : "puzzle"}
label={item.title}
side="right"
active={($pluginSidebar?.owner === item.owner && $pluginSidebar?.id === item.id) || $pluginView?.owner === item.owner && $pluginView?.id === item.id && !$pluginView?.document && ($pluginView?.placement === "dialog" || $pluginEditorActive)}
onclick={() => openPluginView(item.owner, item.id)}
/>
{/each}
</nav>{/if}
{#if leftOpen && !transferredWindow} {#if leftOpen && !transferredWindow}
<aside class="left"> <LeftPane
<div class="left-body"> bind:fileTree
{#if $pluginSidebar} bind:workspaceAnchor
{#key $pluginSidebar.key}<PluginEditor view={$pluginSidebar} />{/key} {workspace}
{/if} {session}
<div class="native-left" class:sidebar-covered={!!$pluginSidebar}> {leftView}
{#if !workspace} keysActive={leftOpen && !$pluginSidebar && leftView === "files"}
{#if leftView === "bookmarks"}<BrowserSlot kind="bookmarks" />{:else}<p class="placeholder">{$t("No folder is open.")}</p>{/if}
{:else}
<div class="left-stack">
<div class="left-layer" class:shown={leftView === "files"}>
<FileTree
bind:this={fileTree}
workspaceRoot={workspace.root}
showInternal={settings.showInternalFolder} showInternal={settings.showInternalFolder}
activePath={editorPluginVisible ? $pluginView?.document?.path ?? null : activePath}
{searchRequest}
onOpenFile={(entry, line, target) => void openFile(entry, line, target)}
onCreated={(entry) => { void openCreatedFile(entry); }}
onSaveTemplate={(entry) => { void saveTemplate(entry); }} onSaveTemplate={(entry) => { void saveTemplate(entry); }}
onManageTemplates={() => templateManager = true} onManageTemplates={() => templateManager = true}
activePath={editorPluginVisible ? $pluginView?.document?.path ?? null : activePath} onStatus={(message) => { status = message; error = null; }}
onOpenFile={(entry, newTab) => void openFile(entry, undefined, newTab ? "new" : "current")} onChooseWorkspace={chooseWorkspace}
{session} onHelp={() => preferences = "help"}
keysActive={leftOpen && !$pluginSidebar && leftView === "files"} onSettings={() => void openSettings()}
onCreated={(entry) => {
void openCreatedFile(entry);
}}
onStatus={(message) => {
status = message;
error = null;
}}
/> />
</div>
{#if leftView === "search"}
<SearchPane {searchRequest} onOpen={(entry, line) => void openFile(entry, line)} />
{:else if leftView === "bookmarks"}
<BookmarksPane {session} onOpen={(entry) => void openFile(entry)} />
{/if}
</div>
{/if}
</div>
</div>
<div class="left-footer">
<div class="footer-start" bind:this={workspaceAnchor}>
<IconButton icon="folder-open" label={$t("Open folder")} onclick={chooseWorkspace} />
<span class="ws">{workspace ? workspace.name : $t("No workspace")}</span>
</div>
<div class="footer-actions">
<IconButton icon="help" label={$t("Help and about (F1)")} onclick={() => preferences = "help"} />
<IconButton icon="settings" label={$t("Settings (Ctrl+,)")} onclick={() => void openSettings()} />
</div>
</div>
</aside>
<div <div
class="gutter gutter-v" class="gutter gutter-v"
@@ -1311,80 +1234,41 @@
{/if} {/if}
<div class="center-stack" class:terminal-maximized={terminalOpen && terminalMaximized} bind:this={centerStack}> <div class="center-stack" class:terminal-maximized={terminalOpen && terminalMaximized} bind:this={centerStack}>
<main class="center"> <DocumentArea
<div class="plugin-panes" class:inactive={!editorPluginVisible}> bind:pluginPaneComponents
{#each $pluginEditors as pane (pane.key)} bind:paneComponents
{@const bounds = pluginBounds[pane.key]} {editorPluginVisible}
<!-- svelte-ignore a11y_no_static_element_interactions (Focus selects the pane that owns the input.) --> split={!!activeSplit}
<div class="plugin-pane" class:inactive={!bounds} class:split={!!activeSplit} class:focused={$pluginView?.key === pane.key} {pluginBounds}
style:left={`${bounds?.left ?? 0}%`} style:top={`${bounds?.top ?? 0}%`} tabBar={tabBarProps}
style:width={`${bounds?.width ?? 100}%`} style:height={`${bounds?.height ?? 100}%`} {documentViews}
onfocusin={() => { if ($pluginView?.key !== pane.key) selectPluginEditor(pane); }} activePane={documentPanes.active}
onpointerdown={() => { if ($pluginView?.key !== pane.key) selectPluginEditor(pane); }}> {documents}
{#if activeSplit && bounds}
<TabBar tabs={workingTabs.filter(tab => tab.id === pane.key)} activePath={activeTabPath}
onSelect={selectWorkingTab} onClose={closeTab} onMove={moveWorkingTab} onPin={pinWorkingTab}
onCloseTabs={(path, scope) => void closeTabs(path, scope)} fileActions={workingTabFileActions} tabActions={workingTabActions}
tabDragData={workingTabDragData} onDropTab={(data, index) => void receiveTab(data, index)} />
{/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={documentPanes.active === pane.id}
data-document-pane={pane.id} data-document-path={pane.buffer?.relPath ?? ""}
style:--pane-weight={pane.bounds.width}
onpointerdowncapture={() => focusDocumentPane(pane.id)}
onfocusin={() => focusDocumentPane(pane.id)}>
{#if pane.buffer?.diskError}
<div class="conflict" role="alert"><span>{pane.buffer.diskError}</span><button onclick={() => void saveCopy(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={() => void saveCopy(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} {tabs}
active={documentPanes.active === pane.id}
onCloseSplit={documentViews.length > 1 ? () => closeSplit(pane.id) : undefined}
hasWorkspace={!!workspace} hasWorkspace={!!workspace}
{browserOpening}
{focusLine}
onFocusPane={(id) => focusDocumentPane(id)}
onCloseSplit={closeSplit}
onSaveCopy={(tab) => void saveCopy(tab)}
onOpenWorkspace={() => void chooseWorkspace()} onOpenWorkspace={() => void chooseWorkspace()}
onNewFile={() => void newFile()} onNewFile={() => void newFile()}
onNewNote={(event) => { void newNote(event); }} onNewNote={(event) => { void newNote(event); }}
onQuickOpen={() => quickOpen = true} onQuickOpen={() => quickOpen = true}
onOpenBrowser={browserContribution?.newTab ? () => void openBrowser() : undefined} onOpenBrowser={browserContribution?.newTab ? () => void openBrowser() : undefined}
{browserOpening}
buffer={pane.buffer}
chrome={pane.buffer?.chromeOverride ?? pane.buffer?.chrome ?? "Writing"}
reading={pane.reading}
focusLine={documentPanes.active === pane.id ? focusLine : null}
{onChange} {onChange}
onInsertImage={file => insertImage(file, pane.buffer)} onInsertImage={(file, tab) => insertImage(file, tab)}
onRenameTitle={renameNoteTitle} onRenameTitle={renameNoteTitle}
tableActions={{ onSearch: searchSelection, onExtract: (markdown, label, valid) => extractSelection(markdown, label, valid, pane.buffer) }} tableActions={(pane) => ({ onSearch: searchSelection, onExtract: (markdown, label, valid) => extractSelection(markdown, label, valid, pane.buffer) })}
linkActions={{ linkActions={(pane) => ({
browser: browserContribution ? async target => { if (!await browserContribution?.open(target)) throw new Error($t("Could not open the app browser.")); } : undefined, browser: browserContribution ? async target => { if (!await browserContribution?.open(target)) throw new Error($t("Could not open the app browser.")); } : undefined,
defaultBrowser: target => openUrl(target), defaultBrowser: target => openUrl(target),
workspaceItems: link => workspaceLinkItems(link, pane.buffer?.relPath ?? "", pane.id), workspaceItems: link => workspaceLinkItems(link, pane.buffer?.relPath ?? "", pane.id),
}} })}
onToggleReading={() => setReading(!pane.reading, pane.id)} onToggleReading={(pane) => setReading(!pane.reading, pane.id)}
onToggleChrome={() => { focusDocumentPane(pane.id); toggleChrome(); }} onToggleChrome={(pane) => { focusDocumentPane(pane.id); toggleChrome(); }}
onOpenLink={(kind, target) => void openLink(kind, target, pane.buffer?.relPath ?? "", pane.id)} onOpenLink={(pane, kind, target) => void openLink(kind, target, pane.buffer?.relPath ?? "", pane.id)}
/> />
</div>
{/each}
</div>
</div>
</main>
{#if terminalContribution && terminalStarted} {#if terminalContribution && terminalStarted}
<div <div
class="gutter gutter-h" class:terminal-hidden={!terminalOpen} class="gutter gutter-h" class:terminal-hidden={!terminalOpen}
@@ -1412,10 +1296,8 @@
role="separator" role="separator"
onpointerdown={() => (dragging = "right")} onpointerdown={() => (dragging = "right")}
></div> ></div>
<aside class="right"> <RightPane
<div class="outline-area"> {outlineItems}
<OutlinePane
items={outlineItems}
onJump={(line) => { onJump={(line) => {
pluginEditorActive.set(false); pluginEditorActive.set(false);
setReading(false); setReading(false);
@@ -1424,35 +1306,20 @@
focusLine = line; focusLine = line;
}); });
}} }}
showBacklinks={buffer?.kind === "text" && isMarkdownPath(buffer.relPath) && !editorPluginVisible}
{backlinks}
{session}
onOpenBacklink={(entry) => void openBacklink(entry)}
/> />
</div>
{#if buffer?.kind === "text" && isMarkdownPath(buffer.relPath) && !editorPluginVisible}
<Backlinks entries={backlinks} busy={session.indexBusy} error={session.indexError} onOpen={entry => void openBacklink(entry)} onRebuild={() => void session.rebuildIndex()} />
{/if}
</aside>
{/if} {/if}
<footer class="status"> <StatusBar message={error ?? status} watchMode={workspace?.watch_mode ?? null} source={isIde} />
<span>{error ?? status}</span>
{#if workspace}
<span>{workspace.watch_mode} watch</span>
{/if}
<span>{isIde ? $t("IDE") : $t("Writer")}</span>
</footer>
</div> </div>
<style> <style>
.right { display: flex; flex-direction: column; }
.outline-area { flex: 1; min-height: 80px; overflow: hidden; }
.right > :global(.backlinks) { flex: 0 1 auto; max-height: 50%; }
.terminal-hidden { display: none !important; } .terminal-hidden { display: none !important; }
.terminal-maximized > .center, .terminal-maximized > .gutter-h { display: none; } .terminal-maximized > :global(.center), .terminal-maximized > .gutter-h { display: none; }
.terminal-maximized > .bottom { flex: 1; height: auto; } .terminal-maximized > .bottom { flex: 1; height: auto; }
.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; }
.shell { .shell {
position: relative; position: relative;
isolation: isolate; isolation: isolate;
@@ -1512,94 +1379,6 @@
.shell.has-ribbon { --ribbon-width: 44px; } .shell.has-ribbon { --ribbon-width: 44px; }
.shell.detached { grid-template-columns: minmax(0, 1fr); } .shell.detached { grid-template-columns: minmax(0, 1fr); }
.plugin-ribbon {
grid-column: 1;
grid-row: 2;
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
min-height: 0;
padding: 6px 5px;
overflow-y: auto;
background: var(--rs-workarea-sidebar-bg);
border-right: 1px solid var(--rs-border);
}
.plugin-ribbon[hidden] { display: block; visibility: hidden; padding: 0; border: 0; }
.plugin-ribbon :global(.icon-btn) { width: 32px; height: 32px; flex-basis: 32px; }
.header {
grid-column: 1 / -1;
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 0;
padding: 0;
background: var(--rs-bg-elevated);
box-shadow: inset 0 -1px var(--rs-border);
user-select: none;
}
.header-left,
.header-right {
display: flex;
align-items: center;
justify-content: center;
gap: 2px;
min-width: 0;
padding: 0 4px;
}
.header-center {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 6px;
min-width: 0;
padding: 0;
border-left: 1px solid var(--rs-border);
border-right: 1px solid var(--rs-border);
}
.header-left, .header-center, .header-right { height: 100%; }
.shell.left-open .header-left { width: calc(var(--ribbon-width) + var(--left) + 1px); padding-left: calc(var(--ribbon-width) + 4px); }
.header-left :global(.icon-btn), .header-right :global(.icon-btn) { flex-shrink: 0; }
.header-right { justify-content: flex-end; }
.window-drag-space { flex: 0 0 40px; align-self: stretch; }
.header-center :global(.tabs) {
flex: 0 1 auto;
align-self: stretch;
min-width: 0;
min-height: 28px;
background: transparent;
border-bottom: 0;
}
.header-center :global(.tab) {
flex: 0 1 180px;
width: 180px;
min-width: 96px;
max-width: 180px;
background: transparent;
}
.header-center :global(.tab.active) {
background: var(--rs-bg);
}
.ws {
color: var(--rs-text-dim);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
flex: 1;
}
.left,
.center,
.right,
.bottom, .bottom,
.center-stack { .center-stack {
min-width: 0; min-width: 0;
@@ -1613,113 +1392,6 @@
flex-direction: column; flex-direction: column;
} }
.center {
flex: 1;
display: flex;
flex-direction: column;
}
.editor-host {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
position: relative;
}
.editor-host { 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; }
.center { position: relative; }
.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; }
.left,
.right {
background: var(--rs-workarea-sidebar-bg);
}
.left {
display: flex;
flex-direction: column;
}
.left-body {
flex: 1;
min-height: 0;
overflow: hidden;
display: flex;
flex-direction: column;
}
.left-body > :global(*) {
flex: 1;
min-height: 0;
}
.native-left { display: flex; flex-direction: column; min-height: 0; }
.native-left.sidebar-covered { display: none; }
.left-stack {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.left-layer {
display: none;
flex: 1;
min-height: 0;
}
.left-layer.shown {
display: flex;
flex-direction: column;
}
.left-layer.shown > :global(*) {
flex: 1;
min-height: 0;
}
.left-stack > :global(.pane) {
flex: 1;
min-height: 0;
}
.left-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 4px 6px;
border-top: 1px solid var(--rs-border);
flex: 0 0 auto;
}
.footer-start {
flex: 1;
display: flex;
align-items: center;
gap: 2px;
min-width: 0;
}
.footer-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.footer-actions :global(.icon-btn) { width: 32px; height: 32px; flex-basis: 32px; }
.placeholder { .placeholder {
margin: 12px; margin: 12px;
color: var(--rs-text-dim); color: var(--rs-text-dim);
@@ -1794,23 +1466,4 @@
flex: 1; flex: 1;
min-height: 0; min-height: 0;
} }
.status {
grid-column: 1 / -1;
display: flex;
justify-content: space-between;
gap: 12px;
padding: 0 10px;
background: var(--rs-bg-elevated);
border-top: 1px solid var(--rs-border);
color: var(--rs-text-dim);
font-size: 12px;
}
.status :first-child {
color: var(--rs-text);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style> </style>
+131
View File
@@ -0,0 +1,131 @@
<script lang="ts">
// The workbench header: the side pane buttons, the working tabs, the actions, and the window controls.
import type { ComponentProps } from "svelte";
import { t } from "$lib/i18n";
import IconButton from "$lib/ui/IconButton.svelte";
import WindowControls from "$lib/ui/WindowControls.svelte";
import PluginTools from "$lib/plugins/PluginTools.svelte";
import PluginAccessMenu from "$lib/plugins/PluginAccessMenu.svelte";
import { openPluginView, pluginSidebar } from "$lib/plugins/external";
import TabBar from "./TabBar.svelte";
type LeftView = "files" | "search" | "bookmarks";
type Props = {
detached: boolean;
desktop: boolean;
leftOpen: boolean;
leftView: LeftView;
sidebarNavigation: { owner: string; id: string; title: string; icon?: string }[];
onSelectLeft: (view: LeftView) => void;
tabBar: ComponentProps<typeof TabBar>;
onNewTab: () => void;
canOpenBrowser: boolean;
browserOpening: boolean;
onOpenBrowser: () => void;
saveDisabled: boolean;
onSave: () => void;
terminalEnabled: boolean;
terminalOpen: boolean;
onToggleTerminal: () => void;
rightOpen: boolean;
onToggleRight: () => void;
onError: (message: string) => void;
};
let { detached, desktop, leftOpen, leftView, sidebarNavigation, onSelectLeft, tabBar, onNewTab, canOpenBrowser, browserOpening, onOpenBrowser,
saveDisabled, onSave, terminalEnabled, terminalOpen, onToggleTerminal, rightOpen, onToggleRight, onError }: Props = $props();
</script>
<header class="header" data-tauri-drag-region>
<div class="header-left" data-tauri-drag-region>
{#if !detached}
<IconButton icon="files" label={$t("Files")} active={leftOpen && !$pluginSidebar && leftView === "files"} onclick={() => onSelectLeft("files")} />
<IconButton icon="search" label={$t("Search")} active={leftOpen && !$pluginSidebar && leftView === "search"} onclick={() => onSelectLeft("search")} />
<IconButton icon="bookmark" label={$t("Bookmarks")} active={leftOpen && !$pluginSidebar && leftView === "bookmarks"} onclick={() => onSelectLeft("bookmarks")} />
{#each sidebarNavigation as item (`${item.owner}:${item.id}`)}
<IconButton
icon={item.icon === "list" || item.icon === "kanban" || item.icon === "globe" || item.icon === "git" ? item.icon : "puzzle"}
label={item.title}
active={leftOpen && $pluginSidebar?.owner === item.owner && $pluginSidebar?.id === item.id}
onclick={() => openPluginView(item.owner, item.id)}
/>
{/each}
{/if}
</div>
<div class="header-center" data-tauri-drag-region>
<TabBar {...tabBar} />
<IconButton icon="plus" label={$t("New tab (Ctrl T)")} onclick={onNewTab} />
{#if desktop}<div class="window-drag-space" data-tauri-drag-region></div>{/if}
</div>
<div class="header-right" data-tauri-drag-region>
{#if canOpenBrowser}<IconButton icon="globe" label={$t("New browser tab")} disabled={browserOpening} onclick={onOpenBrowser} />{/if}
<PluginAccessMenu surface="open" compact />
<PluginTools />
<PluginAccessMenu surface="commands" compact />
<IconButton icon="save" label={$t("Save")} disabled={saveDisabled} onclick={onSave} />
{#if terminalEnabled}<IconButton icon="terminal" label={$t("Terminal")} active={terminalOpen} onclick={onToggleTerminal} />{/if}
{#if !detached}<IconButton icon="panel-right" label={rightOpen ? $t("Hide outline") : $t("Show outline")} active={rightOpen} onclick={onToggleRight} />{/if}
{#if desktop}<WindowControls {onError} />{/if}
</div>
</header>
<style>
.header {
grid-column: 1 / -1;
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 0;
padding: 0;
background: var(--rs-bg-elevated);
box-shadow: inset 0 -1px var(--rs-border);
user-select: none;
}
.header-left,
.header-right {
display: flex;
align-items: center;
justify-content: center;
gap: 2px;
min-width: 0;
padding: 0 4px;
}
.header-center {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 6px;
min-width: 0;
padding: 0;
border-left: 1px solid var(--rs-border);
border-right: 1px solid var(--rs-border);
}
.header-left, .header-center, .header-right { height: 100%; }
/* The left group spans the ribbon and the open left pane (the shell sets the widths). */
:global(.shell.left-open) .header-left { width: calc(var(--ribbon-width) + var(--left) + 1px); padding-left: calc(var(--ribbon-width) + 4px); }
.header-left :global(.icon-btn), .header-right :global(.icon-btn) { flex-shrink: 0; }
.header-right { justify-content: flex-end; }
.window-drag-space { flex: 0 0 40px; align-self: stretch; }
.header-center :global(.tabs) {
flex: 0 1 auto;
align-self: stretch;
min-width: 0;
min-height: 28px;
background: transparent;
border-bottom: 0;
}
.header-center :global(.tab) {
flex: 0 1 180px;
width: 180px;
min-width: 96px;
max-width: 180px;
background: transparent;
}
.header-center :global(.tab.active) {
background: var(--rs-bg);
}
</style>