Release RuneStone 0.1.7 with plugin documents and shared menus

This commit is contained in:
Knotty Wyvern
2026-10-06 09:29:09 -07:00
parent 6b7af0d527
commit 5d0a4a24f9
75 changed files with 2286 additions and 1665 deletions
+88 -17
View File
@@ -1,6 +1,9 @@
<script lang="ts">
import TerminalSlot from "$lib/plugins/TerminalSlot.svelte";
import PluginTools from "$lib/plugins/PluginTools.svelte";
import PluginEditor from "$lib/plugins/PluginEditor.svelte";
import PluginEditorTab from "$lib/plugins/PluginEditorTab.svelte";
import { pluginNavigation, openPluginView, pluginView, pluginEditors, pluginEditorActive, closePluginEditor, openPluginDocument, renamePluginDocuments, removePluginDocuments, notifyPluginWorkspace, guardPluginWrites, handlePluginDocumentRename, cancelPluginDocumentOpen } from "$lib/plugins/external";
import { onMount, tick } from "svelte";
import { selectedEditorText } from "$lib/editor/selection";
import { pluginHost } from "$lib/plugins/registry";
@@ -44,7 +47,7 @@
workspaceWriteBytes,
} from "$lib/workspace/api";
import { detectChrome } from "$lib/workspace/chrome";
import { planRename, planMarkdownTitleRename } from "$lib/workspace/renamePath";
import { planRename, planMarkdownTitleRename, planDocumentTitleRename } from "$lib/workspace/renamePath";
import { attachmentRel, isImagePath, isMarkdownPath } from "$lib/workspace/media";
import { linkCandidates } from "$lib/workspace/markdownLinks";
import type { Chrome, OpenBuffer, TreeEntry, WorkspaceInfo } from "$lib/workspace/types";
@@ -109,6 +112,7 @@
let dragging = $state<"left" | "right" | "bottom" | null>(null);
let centerStack: HTMLElement | undefined = $state();
const editorPluginVisible = $derived($pluginView?.placement === "editor" && $pluginEditorActive);
const dirty = $derived(buffer !== null && buffer.contents !== buffer.saved);
const isIde = $derived(view === "Ide");
const outlineItems = $derived(
@@ -202,13 +206,17 @@
}
function selectTab(relPath: string) {
cancelPluginDocumentOpen();
pluginEditorActive.set(false);
focusLine = null;
documents?.select(relPath);
status = documents?.active?.kind === "empty" ? "New tab" : relPath;
}
function newTab() {
cancelPluginDocumentOpen();
if (switching) return;
pluginEditorActive.set(false);
documents ??= createDocuments();
focusLine = null;
documents.newTab();
@@ -276,8 +284,13 @@
const current = documents;
if (!current || switching) return;
try {
const open = current.buffers.find(tab => tab.relPath === entry.rel_path);
if (!line && !(open && open.contents !== open.saved) && await openPluginDocument(entry.rel_path, () => documents === current && !switching)) {
status = entry.rel_path; error = null; return;
}
await current.open(entry, target);
if (documents !== current) return;
pluginEditorActive.set(false);
status = entry.rel_path;
error = null;
focusLine = null;
@@ -454,7 +467,7 @@
}
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "s") {
event.preventDefault();
void save();
if (!editorPluginVisible) void save();
}
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "o") {
event.preventDefault();
@@ -466,7 +479,7 @@
}
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "e") {
event.preventDefault();
toggleChrome();
if (!editorPluginVisible) toggleChrome();
}
if (terminalEnabled && (event.ctrlKey || event.metaKey) && event.key === "`") {
event.preventDefault();
@@ -474,7 +487,9 @@
}
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "w") {
event.preventDefault();
if (activePath) {
if (editorPluginVisible) {
if ($pluginView) closePluginEditor($pluginView.key);
} else if (activePath) {
closeTab(activePath);
}
}
@@ -487,7 +502,7 @@
return;
}
event.preventDefault();
if (!(leftOpen && leftView === "files")) {
if (!editorPluginVisible && !(leftOpen && leftView === "files")) {
void renameActive();
}
}
@@ -495,6 +510,7 @@
function applyPathRename(from: string, to: string) {
documents?.rename(from, to);
renamePluginDocuments(from, to);
}
async function renameNoteTitle(id: string, title: string) {
@@ -566,7 +582,7 @@
const shell = event.currentTarget as HTMLElement;
const rect = shell.getBoundingClientRect();
if (dragging === "left") {
leftWidth = Math.min(480, Math.max(160, event.clientX - rect.left));
leftWidth = Math.min(480, Math.max(160, event.clientX - rect.left - ($pluginNavigation.length ? 44 : 0)));
}
if (dragging === "right") {
rightWidth = Math.min(480, Math.max(160, rect.right - event.clientX));
@@ -608,6 +624,22 @@
void restoreLast();
let disposed = false;
const unlisteners: (() => void)[] = [];
unlisteners.push(handlePluginDocumentRename(async (from, name) => {
const current = documents;
if (!current || switching) throw new Error("Open a workspace before renaming a document.");
const plan = planDocumentTitleRename(from, name);
if (plan.action === "error") throw new Error(plan.message);
if (plan.action === "noop") return from;
await workspaceRename(from, plan.to);
if (documents !== current) throw new Error("The workspace changed. Reopen the document.");
applyPathRename(from, plan.to);
refreshToken++;
return plan.to;
}));
unlisteners.push(guardPluginWrites(path => {
const open = documents?.buffers.find(tab => tab.relPath === path);
if (open && open.contents !== open.saved) throw new Error("Save or discard the open note's edits before changing it from a plugin.");
}));
let refreshTimer: ReturnType<typeof setTimeout>;
const register = (off: () => void) => { if (disposed) off(); else unlisteners.push(off); };
void onWorkspaceEvent((event) => {
@@ -617,6 +649,7 @@
refreshTimer = setTimeout(() => {
refreshToken++;
void documents?.refresh();
notifyPluginWorkspace();
}, 200);
}).then(register).catch(err => error = String(err));
let closing = false;
@@ -651,6 +684,7 @@
<div
class="shell"
class:has-ribbon={$pluginNavigation.length > 0}
class:left-open={leftOpen}
class:right-open={rightOpen}
role="application"
@@ -685,16 +719,17 @@
</div>
<div class="header-center" data-tauri-drag-region>
{#if tabs.length > 0}
<TabBar {tabs} {activePath} onSelect={selectTab} onClose={closeTab}
<TabBar {tabs} activePath={editorPluginVisible ? null : activePath} onSelect={selectTab} onClose={closeTab}
onCloseTabs={(path, scope) => void closeTabs(path, scope)} onPin={(path) => documents?.togglePin(path)}
fileActions={tabFileActions} onMove={(path, index) => documents?.move(path, index)} />
{/if}
<PluginEditorTab />
<IconButton icon="plus" label="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>
<PluginTools />
<IconButton icon="save" label="Save" disabled={!dirty || saving} onclick={() => void save()} />
<IconButton icon="save" label="Save" disabled={editorPluginVisible || !dirty || saving} onclick={() => void save()} />
{#if terminalEnabled}<IconButton icon="terminal" label="Terminal" active={terminalOpen} onclick={toggleTerminal} />{/if}
<IconButton
icon="panel-right"
@@ -706,6 +741,18 @@
</div>
</header>
<nav class="plugin-ribbon" aria-label="Plugin shortcuts" hidden={$pluginNavigation.length === 0}>
{#each $pluginNavigation as item (`${item.owner}:${item.id}`)}
<IconButton
icon={item.icon === "list" || item.icon === "kanban" ? item.icon : "puzzle"}
label={item.title}
side="right"
active={$pluginView?.owner === item.owner && $pluginView?.id === item.id && !$pluginView?.document && ($pluginView?.placement === "dialog" || $pluginEditorActive)}
onclick={() => openPluginView(item.owner, item.id)}
/>
{/each}
</nav>
{#if leftOpen}
<aside class="left">
<div class="left-body">
@@ -716,7 +763,7 @@
<div class="left-layer" class:shown={leftView === "files"}>
<FileTree
workspaceRoot={workspace.root}
{activePath}
activePath={editorPluginVisible ? $pluginView?.document?.path ?? null : activePath}
onOpenFile={(entry, newTab) => void openFile(entry, undefined, newTab ? "new" : "current")}
{refreshToken}
keysActive={leftView === "files"}
@@ -727,7 +774,7 @@
status = message;
error = null;
}}
onEntryGone={() => { void documents?.refresh(); }}
onEntryGone={(path) => { removePluginDocuments(path); void documents?.refresh(); }}
onEntryRenamed={applyPathRename}
/>
</div>
@@ -760,7 +807,8 @@
<div class="center-stack" class:terminal-maximized={terminalOpen && terminalMaximized} bind:this={centerStack}>
<main class="center">
<div class="editor-host">
{#each $pluginEditors as view (view.key)}<PluginEditor {view} />{/each}
<div class="editor-host" class:plugin-covered={editorPluginVisible}>
{#if buffer?.diskError}
<div class="conflict" role="alert"><span>{buffer.diskError}</span><button onclick={() => void saveCopy()}>Save a copy</button><button onclick={() => void documents?.refresh()}>Retry</button></div>
{:else if buffer?.diskContents != null}
@@ -824,6 +872,7 @@
<OutlinePane
items={outlineItems}
onJump={(line) => {
pluginEditorActive.set(false);
reading = false;
focusLine = null;
queueMicrotask(() => {
@@ -855,23 +904,43 @@
.shell {
height: 100vh;
display: grid;
grid-template-columns: minmax(0, 1fr);
--ribbon-width: 0px;
grid-template-columns: var(--ribbon-width) minmax(0, 1fr);
grid-template-rows: 36px minmax(0, 1fr) 22px;
background: var(--rs-bg);
}
.shell.left-open {
grid-template-columns: var(--left) 1px minmax(0, 1fr);
grid-template-columns: var(--ribbon-width) var(--left) 1px minmax(0, 1fr);
}
.shell.right-open {
grid-template-columns: minmax(0, 1fr) 1px var(--right);
grid-template-columns: var(--ribbon-width) minmax(0, 1fr) 1px var(--right);
}
.shell.left-open.right-open {
grid-template-columns: var(--left) 1px minmax(0, 1fr) 1px var(--right);
grid-template-columns: var(--ribbon-width) var(--left) 1px minmax(0, 1fr) 1px var(--right);
}
.shell.has-ribbon { --ribbon-width: 44px; }
.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-bg-elevated);
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;
@@ -885,7 +954,7 @@
}
.shell.left-open .header {
grid-template-columns: var(--left) minmax(0, 1fr) auto;
grid-template-columns: calc(var(--left) + var(--ribbon-width)) minmax(0, 1fr) auto;
}
.shell.right-open .header {
@@ -893,7 +962,7 @@
}
.shell.left-open.right-open .header {
grid-template-columns: var(--left) minmax(0, 1fr) minmax(max-content, var(--right));
grid-template-columns: calc(var(--left) + var(--ribbon-width)) minmax(0, 1fr) minmax(max-content, var(--right));
}
.header-left,
@@ -977,6 +1046,8 @@
position: relative;
}
.editor-host.plugin-covered { display: none; }
.left,
.right {
background: var(--rs-bg-elevated);