Phase 5-7. - A changed tab asks Save, Don't save, or Cancel through the native dialog, instead of OK and Cancel to discard. - The conflict banner uses --rs-warn with a warning icon. Keep my edits is the primary choice and comes first. Use disk version comes last, in the error color. The banner wraps in a narrow pane. - The status bar shows the save state, the line and column, the word count, the line endings, and the view. It shows the watch mode only when it polls a network folder. - The outline and the document facts follow the active tab. A tab without a document has no outline and no document facts. - Tables: only formula cells have a hover hint, so no hint covers the next cell. The table adds no gap above its control area. The add controls show while a cell has focus. - The plugin review marks Install and enable as the primary action. The other choice is Install, keep disabled. - Read follows CommonMark soft breaks. Settings, General, Keep line breaks shows each source line break. The table preview and cell editors of Write keep their line breaks, because their editing depends on them. - Catalog rows in French, Japanese, and Simplified Chinese. - Docs: UI-053, the user guide, and plugins.md. Tests: the new layout/plainFixes, the keepLineBreaks cases in the settings unit tests, and the new install button name.
174 lines
9.3 KiB
Svelte
174 lines
9.3 KiB
Svelte
<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 Icon from "$lib/ui/Icon.svelte";
|
|
import type { ViewMode } from "./ViewModes.svelte";
|
|
import TabBar from "./TabBar.svelte";
|
|
|
|
type EditorProps = ComponentProps<typeof EditorPane>;
|
|
type DocumentView = { id: string; reading: boolean; split: 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"];
|
|
onView: (pane: DocumentView, view: ViewMode) => void;
|
|
onSplitView: (pane: DocumentView, split: boolean) => void;
|
|
onCursor: (pane: DocumentView, line: number, column: number) => 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, onView, onSplitView, onCursor, 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"><Icon icon="alert" /><span>{pane.buffer.diskError}</span><button class="primary" onclick={() => void documents?.refresh()}>{$t("Retry")}</button><button onclick={() => onSaveCopy(pane.buffer)}>{$t("Save a copy")}</button></div>
|
|
{:else if pane.buffer?.diskContents != null}
|
|
<div class="conflict" role="alert">
|
|
<!-- The safe choice comes first. The choice that discards your edits comes last, in the error color. -->
|
|
<Icon icon="alert" />
|
|
<span>{$t("This file changed on disk. Your edits are preserved. Review both versions before saving.")}</span>
|
|
<button class="primary" 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>
|
|
<button class="danger" onclick={() => { if (pane.buffer) documents?.resolve(pane.buffer.id, true); }}>{$t("Use disk version")}</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}
|
|
split={pane.split}
|
|
focusLine={activePane === pane.id ? focusLine : null}
|
|
{onChange}
|
|
onInsertImage={file => onInsertImage(file, pane.buffer)}
|
|
{onRenameTitle}
|
|
tableActions={tableActions(pane)}
|
|
linkActions={linkActions(pane)}
|
|
onView={view => onView(pane, view)}
|
|
onSplit={next => onSplitView(pane, next)}
|
|
onCursor={(line, column) => onCursor(pane, line, column)}
|
|
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;
|
|
}
|
|
|
|
/* The conflict banner uses the warning status color and icon. Its text and buttons wrap in a narrow pane. */
|
|
.conflict { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; background: color-mix(in srgb, var(--rs-warn) 14%, var(--rs-bg)); border-bottom: 2px solid var(--rs-warn); color: var(--rs-text-strong); }
|
|
.conflict > :global(svg) { width: 18px; height: 18px; flex-shrink: 0; color: var(--rs-warn); }
|
|
.conflict span { flex: 1 1 220px; min-width: 0; }
|
|
.conflict button { min-height: 28px; border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); background: var(--rs-bg); color: var(--rs-text); padding: 4px 10px; }
|
|
.conflict button:hover { background: var(--rs-bg-active); }
|
|
.conflict button.primary { border-color: var(--rs-accent); background: var(--rs-accent); color: var(--rs-on-accent); }
|
|
.conflict button.danger { border-color: var(--rs-error); color: var(--rs-error); }
|
|
.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>
|