Update the browser, editor, settings, and installer
This commit is contained in:
@@ -24,7 +24,8 @@
|
||||
function convert(entries: MenuItem[]): ActionMenuItem[] {
|
||||
return entries.map(item => {
|
||||
if (item.kind === "sep") return { separator: true };
|
||||
if (item.kind === "group") return { label: item.label, icon: item.icon, children: convert(item.items) };
|
||||
if (item.kind === "group") return { label: item.label, icon: item.icon, children: convert(item.items),
|
||||
...(item.run ? { run: () => { close(true); item.run?.(); } } : {}) };
|
||||
return { label: item.label, icon: item.icon, disabled: item.disabled, run: () => {
|
||||
close(true);
|
||||
item.run();
|
||||
|
||||
@@ -214,12 +214,20 @@
|
||||
}
|
||||
|
||||
.empty {
|
||||
background-color: var(--rs-new-tab-bg, var(--rs-bg));
|
||||
background-image: var(--rs-background-image, var(--rs-new-tab-image, none));
|
||||
background-size: 100% 100%, var(--rs-background-size, cover);
|
||||
background-position: center, var(--rs-background-position, center);
|
||||
background-repeat: no-repeat;
|
||||
overflow: auto;
|
||||
box-sizing: border-box;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--rs-text-dim);
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
.empty h1,.empty>p{background:color-mix(in srgb,var(--rs-bg) 92%,transparent);padding:8px 14px;border-radius:var(--rs-control-radius)}
|
||||
|
||||
.chrome-bar {
|
||||
display: flex;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
type DropTarget,
|
||||
} from "$lib/workspace/treeDrop";
|
||||
import { planRename } from "$lib/workspace/renamePath";
|
||||
import { isImagePath } from "$lib/workspace/media";
|
||||
import { selectTreePath, treeSelectionEdges, visibleTreePaths, type SelectionModifiers, type TreeSelection } from "$lib/workspace/treeSelection";
|
||||
import ContextMenu from "./ContextMenu.svelte";
|
||||
import type { MenuItem } from "./menuTypes";
|
||||
@@ -49,6 +50,7 @@
|
||||
keysActive?: boolean;
|
||||
showInternal?: boolean;
|
||||
onSaveTemplate?: (entry: TreeEntry) => void;
|
||||
onManageTemplates?: () => void;
|
||||
};
|
||||
|
||||
let {
|
||||
@@ -63,6 +65,7 @@
|
||||
keysActive = true,
|
||||
showInternal = false,
|
||||
onSaveTemplate,
|
||||
onManageTemplates,
|
||||
}: Props = $props();
|
||||
|
||||
let expanded = $state<Set<string>>(new Set([""]));
|
||||
@@ -86,11 +89,17 @@
|
||||
let cancelDrag: (() => void) | undefined;
|
||||
let treeElement: HTMLDivElement;
|
||||
let clipboard = $state<{ root: string; paths: string[]; cut: boolean } | null>(null);
|
||||
type MoveBatch = { moves: { from: string; to: string }[]; before: Marks; after: Marks };
|
||||
type MoveBatch = { action?: "rename"; moves: { from: string; to: string }[]; before: Marks; after: Marks };
|
||||
let undoMoves = $state<MoveBatch[]>([]);
|
||||
let redoMoves = $state<MoveBatch[]>([]);
|
||||
let moving = $state(false);
|
||||
let templates = $state<NoteTemplate[]>([]);
|
||||
$effect(() => {
|
||||
void workspaceRoot; void refreshToken;
|
||||
let cancelled = false;
|
||||
void noteTemplates().then(value => { if (!cancelled) templates = value; });
|
||||
return () => { cancelled = true; };
|
||||
});
|
||||
onMount(() => {
|
||||
const read = () => { void noteTemplates().then(value => templates = value); };
|
||||
read(); window.addEventListener("runestone-templates-changed", read);
|
||||
@@ -383,7 +392,7 @@
|
||||
|
||||
async function commitRename() {
|
||||
const from = renameRel;
|
||||
if (!from) {
|
||||
if (!from || moving) {
|
||||
return;
|
||||
}
|
||||
const plan = planRename(from, renameDraft);
|
||||
@@ -395,15 +404,25 @@
|
||||
error = plan.message;
|
||||
return;
|
||||
}
|
||||
const operationRoot = workspaceRoot;
|
||||
const before = structuredClone($state.snapshot(marks));
|
||||
moving = true;
|
||||
try {
|
||||
await workspaceRename(from, plan.to);
|
||||
await workspaceRename(from, plan.to, operationRoot);
|
||||
if (workspaceRoot !== operationRoot) return;
|
||||
const after = moveMarks(marks, from, plan.to);
|
||||
undoMoves = [...undoMoves, { action: "rename", moves: [{ from, to: plan.to }], before, after: structuredClone(after) }];
|
||||
redoMoves = [];
|
||||
renameTreePaths(from, plan.to);
|
||||
onEntryRenamed?.(from, plan.to);
|
||||
await persistMarks(after);
|
||||
await load(parentRel(from));
|
||||
selectOnly(plan.to);
|
||||
onEntryRenamed?.(from, plan.to);
|
||||
await focusTreePath(plan.to);
|
||||
onStatus?.(`Renamed to ${plan.to}`);
|
||||
} catch (err) {
|
||||
error = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
} finally { moving = false; }
|
||||
}
|
||||
|
||||
function onWindowKey(event: KeyboardEvent) {
|
||||
@@ -492,6 +511,16 @@
|
||||
expanded = new Set([...expanded].filter(path => path !== rel && !path.startsWith(`${rel}/`)));
|
||||
}
|
||||
|
||||
function renameTreePaths(from: string, to: string) {
|
||||
const rename = (path: string) => path === from || path.startsWith(`${from}/`) ? to + path.slice(from.length) : path;
|
||||
expanded = new Set([...expanded].map(rename));
|
||||
childrenMap = Object.fromEntries(Object.entries(childrenMap).map(([parent, entries]) => [rename(parent), entries.map(entry => {
|
||||
const rel_path = rename(entry.rel_path);
|
||||
return rel_path === entry.rel_path ? entry : { ...entry, rel_path, name: rel_path.split("/").pop()! };
|
||||
})]));
|
||||
selection = { paths: new Set([...selection.paths].map(rename)), anchor: selection.anchor === null ? null : rename(selection.anchor) };
|
||||
}
|
||||
|
||||
async function handleDrop(target: TreeEntry, entries: TreeEntry[], place: DropPlace) {
|
||||
if (moving) return;
|
||||
const operationRoot = workspaceRoot;
|
||||
@@ -573,11 +602,12 @@
|
||||
await persistMarks(replayMoveMarks(marks, batch.before, batch.after, batch.moves, redo));
|
||||
if (redo) { redoMoves = redoMoves.slice(0, -1); undoMoves = [...undoMoves, batch]; }
|
||||
else { undoMoves = undoMoves.slice(0, -1); redoMoves = [...redoMoves, batch]; }
|
||||
childrenMap = {}; expanded = new Set([""]);
|
||||
await load("");
|
||||
for (const move of applied) renameTreePaths(move.from, move.to);
|
||||
const folders = new Set([...Object.keys(childrenMap), ...applied.flatMap(move => [parentRel(move.from), parentRel(move.to)])]);
|
||||
for (const folder of folders) await load(folder);
|
||||
selection = { paths: new Set(applied.map(move => move.to)), anchor: applied.at(-1)?.to ?? null };
|
||||
await focusTreePath(applied.at(-1)?.to);
|
||||
onStatus?.(redo ? "File move restored." : "File move undone.");
|
||||
onStatus?.(redo ? "File change restored." : "File change undone.");
|
||||
} catch (reason) {
|
||||
const rollbackErrors: string[] = [];
|
||||
for (const move of applied.reverse()) {
|
||||
@@ -659,9 +689,10 @@
|
||||
icon: "file-plus",
|
||||
run: () => { void createIn(parent, "file"); },
|
||||
},
|
||||
...(templates.length ? [{ kind: "group" as const, label: "New note", icon: "file-plus" as const, items: [
|
||||
...(templates.length || onManageTemplates ? [{ kind: "group" as const, label: "New note", icon: "file-plus" as const, run: () => { void fromTemplate(); }, items: [
|
||||
{ kind: "action" as const, label: "Blank note", icon: "file-plus" as const, run: () => { void fromTemplate(); } },
|
||||
...templates.map(template => ({ kind: "action" as const, label: template.name, icon: "file-plus" as const, run: () => { void fromTemplate(template); } })),
|
||||
...(onManageTemplates ? [{ kind: "sep" as const }, { kind: "action" as const, label: "Manage templates…", icon: "copy" as const, run: onManageTemplates }] : []),
|
||||
] }] : [{ kind: "action" as const, label: "New note", icon: "file-plus" as const, run: () => { void fromTemplate(); } }]),
|
||||
{ kind: "action", label: "New folder", icon: "folder-plus", run: () => { void createIn(parent, "folder"); } },
|
||||
...$pluginDocumentTypes.filter(item => item.type.create).map(({ owner, type }): MenuItem => ({
|
||||
@@ -689,10 +720,9 @@
|
||||
return [
|
||||
{ kind: "action", label: "Open in terminal", icon: "terminal", run: () => { void workspaceOpenTerminal(parent).catch(reason => error = String(reason)); } },
|
||||
{ kind: "action", label: "Paste", icon: "paste", disabled: !clipboard || clipboard.root !== workspaceRoot || moving, run: () => { void pasteEntries(parent); } },
|
||||
{ kind: "action", label: "Copy path", icon: "copy", run: () => { void workspaceAbsPath(parent).then(path => copyText(path, "path")).catch(reason => error = String(reason)); } },
|
||||
{ kind: "sep" },
|
||||
{ kind: "action", label: "Undo file move", icon: "undo", disabled: !undoMoves.length || moving, run: () => { void replayMoves(); } },
|
||||
{ kind: "action", label: "Redo file move", icon: "redo", disabled: !redoMoves.length || moving, run: () => { void replayMoves(true); } },
|
||||
{ kind: "action", label: undoMoves.at(-1)?.action === "rename" ? "Undo rename" : "Undo file move", icon: "undo", disabled: !undoMoves.length || moving, run: () => { void replayMoves(); } },
|
||||
{ kind: "action", label: redoMoves.at(-1)?.action === "rename" ? "Redo rename" : "Redo file move", icon: "redo", disabled: !redoMoves.length || moving, run: () => { void replayMoves(true); } },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -896,7 +926,7 @@
|
||||
<div class="drag-ghost" style:left="{dragPoint.x + 12}px" style:top="{dragPoint.y + 12}px">
|
||||
<span>{dragEntries.length > 1 ? `${dragEntries.length} items` : dragRel.split("/").pop()}</span>
|
||||
{#if imageLanding}
|
||||
<span class="hint">Insert image</span>
|
||||
<span class="hint">{isImagePath(dragRel ?? "") ? "Insert image" : "Insert link"}</span>
|
||||
{:else if landing && dropTarget}
|
||||
<span class="hint">{dropHint(landing.name, dropTarget.place)}</span>
|
||||
{/if}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
import { renderDiagrams } from "$lib/workspace/diagrams";
|
||||
import { isRemoteImage, resolveImageRel, markdownTitle } from "$lib/workspace/media";
|
||||
import { imageControls } from "$lib/editor/imageControls";
|
||||
import { readerHeadingFolding } from "$lib/editor/headingFolding";
|
||||
import "$lib/editor/headingFolding.css";
|
||||
|
||||
type Props = {
|
||||
noteRel: string;
|
||||
@@ -20,6 +22,9 @@
|
||||
let html = $state("");
|
||||
let sections = $state<MarkdownSection[]>([]);
|
||||
let root: HTMLDivElement | undefined = $state();
|
||||
const collapsedHeadings = new Set<string>();
|
||||
let foldingNote = "";
|
||||
let headingControls: ReturnType<typeof readerHeadingFolding> | undefined;
|
||||
|
||||
async function loadUrls(noteRel: string, contents: string): Promise<Map<string, string>> {
|
||||
const urls = new Map<string, string>();
|
||||
@@ -47,6 +52,7 @@
|
||||
$effect(() => {
|
||||
void $pluginHost;
|
||||
const path = noteRel;
|
||||
if (foldingNote !== path) { collapsedHeadings.clear(); foldingNote = path; }
|
||||
const text = contents;
|
||||
let cancelled = false;
|
||||
html = renderMarkdownHtml(text, new Map());
|
||||
@@ -67,12 +73,14 @@
|
||||
const el = root;
|
||||
let cancelled = false;
|
||||
let releaseImages: (() => void) | undefined;
|
||||
let currentHeadings: ReturnType<typeof readerHeadingFolding> | undefined;
|
||||
if (el) void tick().then(() => {
|
||||
if (cancelled) return;
|
||||
releaseImages = imageControls(el);
|
||||
headingControls = currentHeadings = readerHeadingFolding(el, collapsedHeadings);
|
||||
return renderDiagrams(el, () => cancelled);
|
||||
});
|
||||
return () => { cancelled = true; releaseImages?.(); };
|
||||
return () => { cancelled = true; releaseImages?.(); currentHeadings?.destroy(); };
|
||||
});
|
||||
|
||||
async function copyFence(button: HTMLButtonElement, body: string) {
|
||||
@@ -134,6 +142,17 @@
|
||||
return;
|
||||
}
|
||||
const href = node.getAttribute("href") ?? "";
|
||||
if (node.hasAttribute("data-footnote-link")) {
|
||||
event.preventDefault();
|
||||
const target = root?.querySelector<HTMLElement>(`[id="${href.slice(1)}"]`);
|
||||
if (target) {
|
||||
// A footnote can sit in a folded section. Reveal it before navigation.
|
||||
headingControls?.reveal(target);
|
||||
target.scrollIntoView({ block: "center" });
|
||||
target.focus({ preventScroll: true });
|
||||
}
|
||||
return;
|
||||
}
|
||||
const kind = node.getAttribute("data-kind");
|
||||
if (kind === "wiki") {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { workspaceList } from "$lib/workspace/api";
|
||||
import type { TreeEntry } from "$lib/workspace/types";
|
||||
import { onMount } from "svelte";
|
||||
let { onOpen, onClose }: { onOpen: (entry: TreeEntry) => void; onClose: () => void } = $props();
|
||||
let { onOpen, onClose, purpose = "Find a file", actionLabel = "open" }: { onOpen: (entry: TreeEntry) => void; onClose: () => void; purpose?: string; actionLabel?: string } = $props();
|
||||
let query = $state("");
|
||||
let files = $state<TreeEntry[]>([]);
|
||||
let selected = $state(0);
|
||||
@@ -31,7 +31,10 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<dialog bind:this={dialog} oncancel={onClose}>
|
||||
<dialog bind:this={dialog} aria-label={purpose} onpointerdown={(event) => {
|
||||
const bounds = dialog.getBoundingClientRect();
|
||||
if (event.target === dialog && (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom)) onClose();
|
||||
}} oncancel={onClose}>
|
||||
<input bind:this={input} bind:value={query} oninput={() => selected = 0} aria-label="Find a file" placeholder="Find a note or code file…" onkeydown={(event) => {
|
||||
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
||||
event.preventDefault(); selected = Math.max(0, Math.min(matches.length - 1, selected + (event.key === "ArrowDown" ? 1 : -1)));
|
||||
@@ -45,7 +48,7 @@
|
||||
{/each}
|
||||
{#if !matches.length}<p>{loading ? "Finding files…" : "No matching files."}</p>{/if}
|
||||
</div>
|
||||
<footer>{error || `${files.length} files${loading ? " · indexing…" : ""}`} <span>↑ ↓ select · Enter open · Esc close</span></footer>
|
||||
<footer>{error || `${files.length} files${loading ? " · indexing…" : ""}`} <span>↑ ↓ select · Enter {actionLabel} · Esc close</span></footer>
|
||||
</dialog>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
{:else}
|
||||
<div class="brand"><img src="/runestone.svg" alt="" width="88" height="88" /><h2>RuneStone</h2><p>Version {version}</p></div>
|
||||
<div class="card help-card">
|
||||
<details open><summary><Icon icon="book-open" /> Get started</summary><div class="help-copy"><p>Use the folder button to open a workspace or create one. Your notes and scripts stay as ordinary files on disk.</p><p>Use the + beside the tabs for a new tab. Press Ctrl+N to create a file, or Ctrl+P to find one.</p><p>Press Ctrl+E to switch between writing and source editing. Use the terminal button to work with a shell beside your files.</p></div></details>
|
||||
<details><summary><Icon icon="book-open" /> Get started</summary><div class="help-copy"><p>Use the folder button to open a workspace or create one. Your notes and scripts stay as ordinary files on disk.</p><p>Use the + beside the tabs for a new tab. Press Ctrl+N to create a file, or Ctrl+P to find one.</p><p>Press Ctrl+E to switch between writing and source editing. Use the terminal button to work with a shell beside your files.</p></div></details>
|
||||
<details><summary><Icon icon="save" /> Save your work</summary><div class="help-copy"><p>Auto-save saves changed files at the interval in Settings → General. Ctrl+S saves the active file immediately.</p><p>If another app changes a file, RuneStone keeps your edits and offers both versions for review.</p></div></details>
|
||||
<details><summary><Icon icon="code" /> Keyboard shortcuts</summary><dl><div><dt>Open a workspace</dt><dd><kbd>Ctrl+O</kbd></dd></div><div><dt>Find a file</dt><dd><kbd>Ctrl+P</kbd></dd></div><div><dt>Save the active file</dt><dd><kbd>Ctrl+S</kbd></dd></div><div><dt>Search the workspace</dt><dd><kbd>Ctrl+Shift+F</kbd></dd></div><div><dt>Open settings</dt><dd><kbd>Ctrl+,</kbd></dd></div><div><dt>Help and about</dt><dd><kbd>F1</kbd></dd></div></dl></details>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { confirm } from "@tauri-apps/plugin-dialog";
|
||||
import { isTauri } from "@tauri-apps/api/core";
|
||||
import IconButton from "$lib/ui/IconButton.svelte";
|
||||
import Icon from "$lib/ui/Icon.svelte";
|
||||
import { requestText } from "$lib/workspace/dialogs.svelte";
|
||||
import { noteTemplates, saveNoteTemplate, TEMPLATE_FOLDER, type NoteTemplate } from "$lib/workspace/templates";
|
||||
import { workspaceDelete, workspaceRename } from "$lib/workspace/api";
|
||||
import type { TreeEntry } from "$lib/workspace/types";
|
||||
let { onClose, onEdit, onRenamed, onDeleted }: { onClose: () => void; onEdit: (entry: TreeEntry) => void;
|
||||
onRenamed: (from: string, to: string) => void; onDeleted: (path: string) => void } = $props();
|
||||
let dialog: HTMLDialogElement;
|
||||
let templates = $state<NoteTemplate[]>([]);
|
||||
let error = $state("");
|
||||
let busy = $state(false);
|
||||
const edit = (template: NoteTemplate) => onEdit({ rel_path: template.path, name: template.name + ".md", kind: "file" });
|
||||
async function refresh() { templates = await noteTemplates(); window.dispatchEvent(new Event("runestone-templates-changed")); }
|
||||
onMount(() => { dialog.showModal(); void refresh(); });
|
||||
async function create() {
|
||||
const name = await requestText("Template name", "New template");
|
||||
if (!name) return;
|
||||
busy = true; error = "";
|
||||
try { const path = await saveNoteTemplate(name, ""); await refresh(); edit({ path, name: path.split("/").at(-1)!.replace(/\.md$/i, "") }); }
|
||||
catch (reason) { error = String(reason); }
|
||||
finally { busy = false; }
|
||||
}
|
||||
async function rename(template: NoteTemplate) {
|
||||
const name = await requestText("Template name", template.name);
|
||||
if (!name) return;
|
||||
const title = name.trim().replace(/\.md$/i, "");
|
||||
if (!title || /[<>:"/\\|?*\x00-\x1f]/.test(title) || /[. ]$/.test(title)) { error = "Enter a valid template name."; return; }
|
||||
const path = `${TEMPLATE_FOLDER}/${title}.md`;
|
||||
if (path === template.path) return;
|
||||
busy = true; error = "";
|
||||
try { await workspaceRename(template.path, path); onRenamed(template.path, path); await refresh(); }
|
||||
catch (reason) { error = String(reason); }
|
||||
finally { busy = false; }
|
||||
}
|
||||
async function remove(template: NoteTemplate) {
|
||||
const message = `Delete the template “${template.name}”? Existing notes stay unchanged.`;
|
||||
const accepted = isTauri() ? await confirm(message, { title: "Delete template", kind: "warning" }) : window.confirm(message);
|
||||
if (!accepted) return;
|
||||
busy = true; error = "";
|
||||
try { await workspaceDelete(template.path); onDeleted(template.path); await refresh(); }
|
||||
catch (reason) { error = String(reason); }
|
||||
finally { busy = false; }
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog bind:this={dialog} aria-labelledby="templates-title" oncancel={event => { event.preventDefault(); if (!busy) onClose(); }}>
|
||||
<header><h2 id="templates-title">Document templates</h2><IconButton icon="close" label="Close templates" disabled={busy} onclick={onClose} /></header>
|
||||
<p>Templates belong to this workspace. Edit a template to change future notes.</p>
|
||||
<button class="new" disabled={busy} onclick={() => void create()}><Icon icon="file-plus" /> New template</button>
|
||||
<div class="list">
|
||||
{#each templates as template (template.path)}
|
||||
<div class="row"><span title={template.name}>{template.name}</span><div class="actions">
|
||||
<IconButton icon="pen" label={`Edit ${template.name}`} disabled={busy} onclick={() => edit(template)} />
|
||||
<button class="rename" aria-label={`Rename ${template.name}`} title={`Rename ${template.name}`} disabled={busy} onclick={() => void rename(template)}><Icon icon="text" /> Rename</button>
|
||||
<IconButton icon="trash" label={`Delete ${template.name}`} disabled={busy} onclick={() => void remove(template)} />
|
||||
</div></div>
|
||||
{:else}<p>No templates yet. Create one or use Save as template on a note.</p>{/each}
|
||||
</div>
|
||||
{#if error}<p role="alert">{error}</p>{/if}
|
||||
</dialog>
|
||||
|
||||
<style>
|
||||
dialog{width:min(600px,90vw);max-height:80vh;padding:var(--rs-settings-section-gap);background:var(--rs-bg);color:var(--rs-text);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius)}
|
||||
dialog::backdrop{background:#0008}
|
||||
header,.row,.actions,.new{display:flex;align-items:center;gap:var(--rs-settings-gap)}
|
||||
header{justify-content:space-between}h2{margin:0;font-size:var(--rs-settings-heading-size)}
|
||||
p{font-size:var(--rs-settings-description-size);color:var(--rs-text-dim);line-height:1.5}
|
||||
.list{margin-top:var(--rs-settings-gap);max-height:50vh;overflow:auto}.row{padding:var(--rs-settings-row-padding);border-bottom:1px solid var(--rs-border);flex-wrap:wrap}.row>span{flex:1;min-width:100px;overflow-wrap:anywhere}
|
||||
.new{min-height:var(--rs-settings-control-height);padding:4px 8px;background:var(--rs-bg-elevated);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius)}
|
||||
.new :global(svg){width:16px;height:16px}[role=alert]{color:var(--rs-error)}
|
||||
.rename{display:flex;align-items:center;gap:4px;min-height:28px;padding:4px 8px;background:transparent;border:0;border-radius:var(--rs-control-radius)}.rename:hover{background:var(--rs-bg-active)}.rename:focus-visible{outline:2px solid var(--rs-accent)}.rename :global(svg){width:16px;height:16px}
|
||||
</style>
|
||||
@@ -10,7 +10,10 @@
|
||||
</script>
|
||||
|
||||
{#if dialogs.text}
|
||||
<dialog bind:this={element} oncancel={(event) => { event.preventDefault(); finishText(null); }}>
|
||||
<dialog bind:this={element} onpointerdown={(event) => {
|
||||
const bounds = element!.getBoundingClientRect();
|
||||
if (event.target === element && (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom)) finishText(null);
|
||||
}} oncancel={(event) => { event.preventDefault(); finishText(null); }}>
|
||||
<form onsubmit={(event) => { event.preventDefault(); finishText(dialogs.text?.value.trim() || null); }}>
|
||||
<label for="text-request">{dialogs.text.title}</label>
|
||||
<input id="text-request" bind:this={input} bind:value={dialogs.text.value} autocomplete="off" />
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
import { requestText } from "$lib/workspace/dialogs.svelte";
|
||||
import TextDialog from "./TextDialog.svelte";
|
||||
import QuickOpen from "./QuickOpen.svelte";
|
||||
import TemplateManager from "./TemplateManager.svelte";
|
||||
import WorkspacePicker from "./WorkspacePicker.svelte";
|
||||
import SettingsDialog from "./SettingsDialog.svelte";
|
||||
import BrowserSlot from "$lib/plugins/BrowserSlot.svelte";
|
||||
@@ -74,6 +75,7 @@
|
||||
let settingsReady = $state(false);
|
||||
let workspaceAnchor: HTMLDivElement | undefined = $state();
|
||||
const desktop = isTauri();
|
||||
const transferredWindow = /^[0-9a-f-]{36}$/i.test(new URLSearchParams(location.search).get("tabTransfer") ?? "");
|
||||
let tabs = $state<OpenBuffer[]>([]);
|
||||
let activePath = $state<string | null>(null);
|
||||
const buffer = $derived(tabs.find((tab) => tab.relPath === activePath) ?? null);
|
||||
@@ -87,18 +89,19 @@
|
||||
let bottomHeight = $state(180);
|
||||
let leftView = $state<WorkbenchLayout["leftView"]>(DEFAULT_WORKBENCH_LAYOUT.leftView);
|
||||
let searchRequest = $state<{ text: string; id: number } | null>(null);
|
||||
let leftOpen = $state(DEFAULT_WORKBENCH_LAYOUT.leftOpen);
|
||||
let rightOpen = $state(DEFAULT_WORKBENCH_LAYOUT.rightOpen);
|
||||
$effect(() => { if ($pluginSidebar) leftOpen = true; });
|
||||
let leftOpen = $state(!transferredWindow && DEFAULT_WORKBENCH_LAYOUT.leftOpen);
|
||||
let rightOpen = $state(!transferredWindow && DEFAULT_WORKBENCH_LAYOUT.rightOpen);
|
||||
$effect(() => { if ($pluginSidebar && !transferredWindow) leftOpen = true; });
|
||||
let terminalOpen = $state(false);
|
||||
let reading = $state(false);
|
||||
let quickOpen = $state(false);
|
||||
let templateManager = $state(false);
|
||||
let terminalStarted = $state(false);
|
||||
let terminalMaximized = $state(false);
|
||||
let terminalDock: TerminalSlot | undefined = $state();
|
||||
const terminalContribution = $derived.by(() => { void $pluginHost; return pluginHost.get("terminal"); });
|
||||
const terminalEnabled = $derived(!!terminalContribution);
|
||||
const sidebarNavigation = $derived($pluginNavigation.filter(item => item.placement === "sidebar" && !item.toolbar));
|
||||
const sidebarNavigation = $derived($pluginNavigation.filter(item => item.placement === "sidebar"));
|
||||
const ribbonNavigation = $derived($pluginNavigation.filter(item => item.placement !== "sidebar" && !item.toolbar));
|
||||
const browserContribution = $derived.by(() => { void $pluginHost; return pluginHost.get("browser"); });
|
||||
let browserOpening = $state(false);
|
||||
@@ -255,6 +258,7 @@
|
||||
}
|
||||
|
||||
function selectLeft(next: "files" | "search" | "bookmarks") {
|
||||
if (transferredWindow) return;
|
||||
const hadSidebar = !!$pluginSidebar;
|
||||
closePluginSidebar();
|
||||
if (!hadSidebar && leftOpen && leftView === next) {
|
||||
@@ -357,7 +361,8 @@
|
||||
if (action && "run" in action && !action.disabled) { action.run?.(); return; }
|
||||
}
|
||||
const current = documents;
|
||||
const snapshot = JSON.stringify("buffer" in tab ? tab.buffer : pluginTabState(tab.plugin));
|
||||
const bufferSnapshot = (buffer?: OpenBuffer) => JSON.stringify(buffer ? { ...buffer, diskError: buffer.diskError ?? null } : undefined);
|
||||
const snapshot = "buffer" in tab ? bufferSnapshot(tab.buffer) : JSON.stringify(pluginTabState(tab.plugin));
|
||||
const token = crypto.randomUUID(), key = `runestone.tab-transfer.${token}`;
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
const finish = () => {
|
||||
@@ -369,7 +374,7 @@
|
||||
const accepted = (event: StorageEvent) => {
|
||||
if (event.key !== key + ".accepted" || event.newValue !== "true") return;
|
||||
if ("buffer" in tab) {
|
||||
if (documents === current && JSON.stringify(current?.buffers.find(buffer => buffer.id === tab.buffer.id)) === snapshot) current?.close(tab.relPath);
|
||||
if (documents === current && bufferSnapshot(current?.buffers.find(buffer => buffer.id === tab.buffer.id)) === snapshot) current?.close(tab.relPath);
|
||||
} else if (JSON.stringify(pluginTabState(tab.plugin)) === snapshot) closePluginEditor(tab.plugin.key);
|
||||
finish();
|
||||
};
|
||||
@@ -688,7 +693,7 @@
|
||||
event.preventDefault(); newTab(); return;
|
||||
}
|
||||
if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.key.toLowerCase() === "f") {
|
||||
event.preventDefault(); leftOpen = true; leftView = "search"; return;
|
||||
event.preventDefault(); if (!transferredWindow) { leftOpen = true; leftView = "search"; } return;
|
||||
}
|
||||
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "s") {
|
||||
event.preventDefault();
|
||||
@@ -720,7 +725,7 @@
|
||||
}
|
||||
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "b") {
|
||||
event.preventDefault();
|
||||
leftOpen = !leftOpen;
|
||||
if (!transferredWindow) leftOpen = !leftOpen;
|
||||
}
|
||||
if (event.key === "F2" && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
||||
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) {
|
||||
@@ -830,12 +835,13 @@
|
||||
try {
|
||||
const layout = parseWorkbenchLayout(localStorage.getItem(WORKBENCH_LAYOUT_KEY));
|
||||
({ leftOpen, rightOpen, leftWidth, rightWidth, leftView } = layout);
|
||||
if (transferredWindow) { leftOpen = false; rightOpen = false; }
|
||||
layoutReady = true;
|
||||
} catch { error = "Could not read your layout. Default layout applies for this window."; }
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (!layoutReady) return;
|
||||
if (!layoutReady || transferredWindow) return;
|
||||
try { saveWorkbenchLayout(localStorage, { leftOpen, rightOpen, leftWidth, rightWidth, leftView }); }
|
||||
catch { error = "Could not save your layout. Layout changes apply for this window only."; }
|
||||
});
|
||||
@@ -926,12 +932,17 @@
|
||||
<WorkspacePicker bind:this={workspacePicker} currentRoot={workspace?.root} anchor={workspaceAnchor} onOpen={openPath} />
|
||||
{#if preferences}<SettingsDialog {settings} help={preferences === "help"} onSave={updateSettings} onClose={() => preferences = null} />{/if}
|
||||
{#if quickOpen && workspace}<QuickOpen onOpen={(entry) => void openFile(entry)} onClose={() => quickOpen = false} />{/if}
|
||||
{#if templateManager && workspace}<TemplateManager onClose={() => templateManager = false}
|
||||
onEdit={(entry) => { templateManager = false; void openFile(entry, undefined, "new"); }}
|
||||
onRenamed={(from, to) => { applyPathRename(from, to); refreshToken++; }}
|
||||
onDeleted={(path) => { removePluginDocuments(path); void documents?.refresh(); refreshToken++; }} />{/if}
|
||||
|
||||
<div
|
||||
class="shell"
|
||||
class:has-ribbon={ribbonNavigation.length > 0}
|
||||
class:left-open={leftOpen}
|
||||
class:right-open={rightOpen}
|
||||
class:detached={transferredWindow}
|
||||
class:has-ribbon={!transferredWindow && ribbonNavigation.length > 0}
|
||||
class:left-open={!transferredWindow && leftOpen}
|
||||
class:right-open={!transferredWindow && rightOpen}
|
||||
role="application"
|
||||
aria-label="RuneStone workbench"
|
||||
style:--left="{leftWidth}px"
|
||||
@@ -943,6 +954,7 @@
|
||||
>
|
||||
<header class="header" data-tauri-drag-region>
|
||||
<div class="header-left" data-tauri-drag-region>
|
||||
{#if !transferredWindow}
|
||||
<IconButton
|
||||
icon="files"
|
||||
label="Files"
|
||||
@@ -969,6 +981,7 @@
|
||||
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}
|
||||
@@ -977,30 +990,26 @@
|
||||
onDetach={(tab) => { void detachTab(tab); }}
|
||||
tabDragData={workingTabDragData} onDropTab={(data, index) => void receiveTab(data, index)} />
|
||||
<IconButton icon="plus" label="New tab (Ctrl T)" onclick={newTab} />
|
||||
<PluginAccessMenu surface="open" compact />
|
||||
{#if desktop}<div class="window-drag-space" data-tauri-drag-region></div>{/if}
|
||||
</div>
|
||||
<div class="header-right" data-tauri-drag-region>
|
||||
{#each $pluginNavigation.filter(item => item.toolbar) as item (item.owner + ":" + item.id)}
|
||||
<IconButton icon={item.icon ?? "puzzle"} label={item.title}
|
||||
active={$pluginView?.owner === item.owner && $pluginView?.id === item.id && $pluginEditorActive}
|
||||
onclick={() => openPluginView(item.owner, item.id)} />
|
||||
{/each}
|
||||
{#if browserContribution?.newTab}<IconButton icon="globe" label="New browser tab" disabled={browserOpening} onclick={() => void openBrowser()} />{/if}
|
||||
<PluginAccessMenu surface="open" compact />
|
||||
<PluginTools />
|
||||
<PluginAccessMenu surface="commands" compact />
|
||||
<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
|
||||
{#if !transferredWindow}<IconButton
|
||||
icon="panel-right"
|
||||
label={rightOpen ? "Hide outline" : "Show outline"}
|
||||
active={rightOpen}
|
||||
onclick={() => (rightOpen = !rightOpen)}
|
||||
/>
|
||||
/>{/if}
|
||||
{#if desktop}<WindowControls onError={(message) => error = message} />{/if}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<nav class="plugin-ribbon" aria-label="Plugin shortcuts" hidden={ribbonNavigation.length === 0}>
|
||||
{#if !transferredWindow}<nav class="plugin-ribbon" aria-label="Plugin shortcuts" hidden={ribbonNavigation.length === 0}>
|
||||
{#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"}
|
||||
@@ -1010,9 +1019,9 @@
|
||||
onclick={() => openPluginView(item.owner, item.id)}
|
||||
/>
|
||||
{/each}
|
||||
</nav>
|
||||
</nav>{/if}
|
||||
|
||||
{#if leftOpen}
|
||||
{#if leftOpen && !transferredWindow}
|
||||
<aside class="left">
|
||||
<div class="left-body">
|
||||
{#if $pluginSidebar}
|
||||
@@ -1028,6 +1037,7 @@
|
||||
workspaceRoot={workspace.root}
|
||||
showInternal={settings.showInternalFolder}
|
||||
onSaveTemplate={(entry) => { void saveTemplate(entry); }}
|
||||
onManageTemplates={() => templateManager = true}
|
||||
activePath={editorPluginVisible ? $pluginView?.document?.path ?? null : activePath}
|
||||
onOpenFile={(entry, newTab) => void openFile(entry, undefined, newTab ? "new" : "current")}
|
||||
{refreshToken}
|
||||
@@ -1137,7 +1147,7 @@
|
||||
<section class="bottom" class:terminal-hidden={!terminalOpen}>
|
||||
{#if workspace}
|
||||
{#key workspace.root}
|
||||
<TerminalSlot contribution={terminalContribution} bind:this={terminalDock} cwd={workspace.root} visible={terminalOpen} onClose={toggleTerminal}
|
||||
<TerminalSlot contribution={terminalContribution} bind:this={terminalDock} cwd={workspace.root} visible={terminalOpen} onClose={() => { terminalOpen = false; terminalStarted = false; terminalMaximized = false; }}
|
||||
maximized={terminalMaximized} onMaximize={() => terminalMaximized = !terminalMaximized}
|
||||
activeFile={buffer?.kind === "text" && !reading} onRunFile={terminalFile}
|
||||
getSelection={() => selectedEditorText(buffer?.id)} onConfigureTasks={configureTasks} />
|
||||
@@ -1149,7 +1159,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if rightOpen}
|
||||
{#if rightOpen && !transferredWindow}
|
||||
<div
|
||||
class="gutter gutter-v"
|
||||
role="separator"
|
||||
@@ -1210,6 +1220,7 @@
|
||||
}
|
||||
|
||||
.shell.has-ribbon { --ribbon-width: 44px; }
|
||||
.shell.detached { grid-template-columns: minmax(0, 1fr); }
|
||||
|
||||
.plugin-ribbon {
|
||||
grid-column: 1;
|
||||
|
||||
@@ -13,6 +13,7 @@ export type MenuSep = { kind: "sep" };
|
||||
export type MenuGroup = {
|
||||
kind: "group";
|
||||
label: string;
|
||||
run?: () => void;
|
||||
icon?: ActionIcon;
|
||||
items: MenuItem[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user