480 lines
29 KiB
Svelte
480 lines
29 KiB
Svelte
<script lang="ts">
|
|
import { t } from "$lib/i18n";
|
|
import { pluginHost } from "$lib/plugins/registry";
|
|
import { isSpellingTarget } from "./spellingMenu";
|
|
import { untrack } from "svelte";
|
|
import { Compartment, EditorState, EditorSelection, Transaction } from "@codemirror/state";
|
|
import { EditorView, drawSelection, keymap } from "@codemirror/view";
|
|
import { defaultKeymap, indentWithTab, isolateHistory } from "@codemirror/commands";
|
|
import { writerHistory, historyKeymap } from "./writerHistory";
|
|
import { markdown, markdownLanguage } from "@codemirror/lang-markdown";
|
|
import { noteFormats } from "./noteFormats";
|
|
import { closeSearchPanel, findNext, findPrevious, openSearchPanel, searchKeymap } from "@codemirror/search";
|
|
import { htmlToMarkdown } from "$lib/workspace/htmlToMarkdown";
|
|
import { writerSearch } from "./writerSearch";
|
|
import type { OpenBuffer } from "$lib/workspace/types";
|
|
import { workspaceReadDataUrl, workspaceReveal } from "$lib/workspace/api";
|
|
import { linkCandidates } from "$lib/workspace/markdownLinks";
|
|
import { editImageSource, imageSource } from "./imageSource";
|
|
import { markdownImages, documentBodyStart } from "$lib/workspace/noteHtml";
|
|
import { isRemoteImage, resolveImageRel, imageFiles, hasFileDrag, imageInsertion, workspaceImageLink } from "$lib/workspace/media";
|
|
import { registerImageDropTarget } from "./workspaceImageDrop";
|
|
import { workspaceFileLink } from "./workspaceFileLink";
|
|
import { editorSession, releaseEditorSession } from "./sessions";
|
|
import { registerSelection } from "./selection";
|
|
import { liveMarkdown, refreshImages } from "./liveMarkdown";
|
|
import { imageDrops, trackImageDrop, clearImageDrop } from "./imageDrop";
|
|
import { noteTitle } from "./noteTitle";
|
|
import { markdownTitle } from "$lib/workspace/media";
|
|
import type { TableContextActions } from "./tableCellActions";
|
|
import { markdownMenu } from "./markdownMenu";
|
|
import type { DocumentLinkActions } from "./linkMenu";
|
|
import { tableNavigation } from "./tableNavigation";
|
|
import { completionExtension } from "$lib/completion/codemirror";
|
|
import { documentLinkAt } from "./documentLinks";
|
|
import { headingFolding } from "./headingFolding";
|
|
import "./headingFolding.css";
|
|
|
|
type Props = {
|
|
buffer: OpenBuffer;
|
|
onChange: (value: string, id: string) => void;
|
|
onRenameTitle?: (id: string, title: string) => Promise<void>;
|
|
onOpenLink?: (kind: "md" | "wiki", target: string) => void;
|
|
onInsertImage?: (file: File) => Promise<string | null>;
|
|
focusLine?: number | null;
|
|
onSelectionLine?: (line: number) => void;
|
|
tableActions?: TableContextActions;
|
|
linkActions?: DocumentLinkActions;
|
|
shouldFocusOnMount?: () => boolean;
|
|
focusTitle?: boolean;
|
|
onTitleFocused?: () => void;
|
|
};
|
|
let { buffer, onChange, onRenameTitle, onOpenLink, onInsertImage, focusLine = null, onSelectionLine, tableActions = {}, linkActions = {}, shouldFocusOnMount = () => true, focusTitle = false, onTitleFocused }: Props = $props();
|
|
let host: HTMLDivElement | undefined = $state();
|
|
let editor = $state.raw<EditorView>();
|
|
export function focus() { editor?.focus(); }
|
|
export function openFind(replace = false) {
|
|
if (!editor) return;
|
|
openSearchPanel(editor);
|
|
editor.dom.querySelector<HTMLInputElement>(replace ? 'input[name="replace"]' : 'input[name="search"]')?.select();
|
|
}
|
|
export function closeFind() { if (editor) closeSearchPanel(editor); }
|
|
export function nextMatch(backward = false) { if (editor) (backward ? findPrevious : findNext)(editor); }
|
|
let error = $state("");
|
|
let model: import("monaco-editor").editor.ITextModel | undefined;
|
|
let ModelSelection: typeof import("monaco-editor").Selection;
|
|
let lastValue = "";
|
|
let publishing = false;
|
|
let historySelections: Map<number, EditorSelection> | undefined;
|
|
let freshState: ((source: string) => EditorState) | undefined;
|
|
let refreshVersion = 0;
|
|
let historyTimer: ReturnType<typeof setTimeout> | undefined;
|
|
const urls = new Map<string, string>();
|
|
const loading = new Map<string, Promise<void>>();
|
|
const title = new Compartment();
|
|
const renameTitle = (name: string) => onRenameTitle!(buffer.id, name);
|
|
|
|
async function loadImages(path: string, value: string) {
|
|
const previousSize = urls.size;
|
|
await Promise.all(markdownImages(value).map(async source => {
|
|
if (urls.has(source)) return;
|
|
if (loading.has(source)) return loading.get(source);
|
|
const task = (async () => {
|
|
if (isRemoteImage(source)) { urls.set(source, source); return; }
|
|
let decoded = source;
|
|
try { decoded = decodeURIComponent(source); } catch { /* Literal filename. */ }
|
|
for (const candidate of new Set([resolveImageRel(path, decoded), decoded.replace(/^\/+/, ""), decoded.split("/").pop()!])) {
|
|
try { urls.set(source, await workspaceReadDataUrl(candidate)); return; } catch { /* Try attachment location. */ }
|
|
}
|
|
})();
|
|
loading.set(source, task);
|
|
try { await task; } finally { loading.delete(source); }
|
|
}));
|
|
return urls.size !== previousSize;
|
|
}
|
|
|
|
// CodeMirror stores one character per line break. Serialize only at the model
|
|
// boundary, so pasted LF and CRLF text both create real editor lines.
|
|
function modelSource(state: EditorState) {
|
|
return state.doc.sliceString(0, undefined, model?.getEOL() ?? "\n");
|
|
}
|
|
|
|
function publish(value: string, id: string, startState: EditorState, state: EditorState) {
|
|
if (!model || value === model.getValue()) return;
|
|
historySelections?.set(model.getAlternativeVersionId(), startState.selection);
|
|
const previous = model.getValue();
|
|
let start = 0;
|
|
while (start < previous.length && start < value.length && previous[start] === value[start]) start++;
|
|
let oldEnd = previous.length, newEnd = value.length;
|
|
while (oldEnd > start && newEnd > start && previous[oldEnd - 1] === value[newEnd - 1]) { oldEnd--; newEnd--; }
|
|
const from = model.getPositionAt(start), to = model.getPositionAt(oldEnd);
|
|
const cursorState = (state: EditorState) => state.selection.ranges.map(range => {
|
|
const anchor = state.doc.lineAt(range.anchor), head = state.doc.lineAt(range.head);
|
|
return new ModelSelection(anchor.number, range.anchor - anchor.from + 1, head.number, range.head - head.from + 1);
|
|
});
|
|
// The model emits changes synchronously. Do not echo this Writer edit back
|
|
// into CodeMirror while its update listener still runs.
|
|
publishing = true;
|
|
try {
|
|
model.pushEditOperations(cursorState(startState), [{ range: { startLineNumber: from.lineNumber, startColumn: from.column, endLineNumber: to.lineNumber, endColumn: to.column }, text: value.slice(start, newEnd) }], () => cursorState(state));
|
|
} finally { publishing = false; }
|
|
historySelections?.set(model.getAlternativeVersionId(), state.selection);
|
|
clearTimeout(historyTimer);
|
|
historyTimer = setTimeout(() => model?.pushStackElement(), 500);
|
|
lastValue = model.getValue();
|
|
onChange(lastValue, id);
|
|
}
|
|
|
|
async function insertImages(event: ClipboardEvent | DragEvent, view: EditorView) {
|
|
const data = "clipboardData" in event ? event.clipboardData : event.dataTransfer;
|
|
const files = imageFiles(data);
|
|
if (!files.length || !onInsertImage) return;
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
const position = event instanceof DragEvent ? view.posAtCoords({ x: event.clientX, y: event.clientY }, false) : null;
|
|
await importImages(view, files, position);
|
|
}
|
|
|
|
async function importImages(view: EditorView, files: File[], position: number | null, linkedPath?: string) {
|
|
const range = position === null ? view.state.selection.main : { from: position, to: position };
|
|
const id = Symbol(), path = buffer.relPath;
|
|
view.dispatch({ effects: trackImageDrop.of({ id, from: range.from, to: range.to }) });
|
|
try {
|
|
const snippets: string[] = linkedPath ? [workspaceFileLink(path, linkedPath)] : [];
|
|
for (const file of files) {
|
|
if (editor !== view) return;
|
|
const snippet = await onInsertImage?.(file);
|
|
if (snippet) snippets.push(snippet);
|
|
}
|
|
if (editor !== view || !snippets.length) return;
|
|
await loadImages(path, snippets.join("\n\n"));
|
|
if (editor !== view) return;
|
|
const target = view.state.field(imageDrops).get(id);
|
|
if (!target) return;
|
|
const insert = imageInsertion(view.state.doc.toString(), target.from, target.to, snippets);
|
|
view.dispatch({ changes: { ...target, insert }, selection: { anchor: target.from + insert.length }, userEvent: "input.image", annotations: isolateHistory.of("full") });
|
|
view.focus();
|
|
} catch (reason) { if (editor === view) error = String(reason); }
|
|
finally { if (editor === view) view.dispatch({ effects: clearImageDrop.of(id) }); }
|
|
}
|
|
|
|
$effect(() => {
|
|
const el = host;
|
|
if (!el) return;
|
|
let cancelled = false;
|
|
let session: ReturnType<typeof editorSession> | undefined;
|
|
let contentListener: { dispose(): void } | undefined;
|
|
let releaseSelection: (() => void) | undefined;
|
|
let menu: ReturnType<typeof markdownMenu> | undefined;
|
|
let releaseDrop: (() => void) | undefined;
|
|
let releaseScroll: (() => void) | undefined;
|
|
let scroll: ReturnType<EditorView["scrollSnapshot"]> | undefined;
|
|
const current = untrack(() => buffer);
|
|
void import("./monacoEnv").then(async ({ monaco }) => {
|
|
await loadImages(current.relPath, current.contents);
|
|
if (cancelled) return;
|
|
session = editorSession(monaco, untrack(() => buffer));
|
|
model = session.model;
|
|
ModelSelection = monaco.Selection;
|
|
historySelections = session.writerSelections;
|
|
lastValue = untrack(() => buffer.contents);
|
|
if (model.getValue() !== lastValue) model.setValue(lastValue);
|
|
model.pushStackElement();
|
|
const extensions = [
|
|
completionExtension(current.id),
|
|
markdown({ base: markdownLanguage, extensions: [noteFormats] }),
|
|
headingFolding,
|
|
writerHistory.of({
|
|
undo: () => {
|
|
clearTimeout(historyTimer);
|
|
model!.pushStackElement();
|
|
if (!model!.canUndo()) return false;
|
|
void model!.undo();
|
|
return true;
|
|
},
|
|
redo: () => {
|
|
clearTimeout(historyTimer);
|
|
if (!model!.canRedo()) return false;
|
|
void model!.redo();
|
|
return true;
|
|
},
|
|
}), drawSelection(),
|
|
EditorView.theme({}, { dark: true }),
|
|
tableNavigation,
|
|
writerSearch,
|
|
keymap.of([{ key: "Escape", run: view => {
|
|
if (!view.state.field(imageSource)) return false;
|
|
view.dispatch({ effects: editImageSource.of(null) }); return true;
|
|
} }, indentWithTab, ...searchKeymap, ...historyKeymap, ...defaultKeymap]), EditorView.lineWrapping,
|
|
liveMarkdown(urls, { ...untrack(() => tableActions), linkActions: () => ({ ...linkActions, open: link => onOpenLink?.(link.kind, link.target) }) }, {
|
|
open: image => onOpenLink?.(image.dataset.mdKind === "wiki" ? "wiki" : "md", image.dataset.mdSrc || ""),
|
|
reveal: async image => {
|
|
for (const path of linkCandidates(current.relPath, image.dataset.mdSrc || "", "md")) {
|
|
try { await workspaceReadDataUrl(path); await workspaceReveal(path); return; } catch { /* Try the workspace-relative image. */ }
|
|
}
|
|
throw new Error("Could not find this image in the workspace.");
|
|
},
|
|
validate: async source => {
|
|
if (isRemoteImage(source)) return;
|
|
for (const path of linkCandidates(current.relPath, source, "md")) {
|
|
try { await workspaceReadDataUrl(path); return; } catch { /* Try the workspace-relative image. */ }
|
|
}
|
|
throw new Error("Choose an image that exists in the workspace.");
|
|
},
|
|
report: message => { error = message; },
|
|
}),
|
|
imageDrops,
|
|
title.of(noteTitle(markdownTitle(current.relPath), onRenameTitle ? renameTitle : undefined)),
|
|
EditorView.contentAttributes.of({ role: "textbox", "aria-label": $t("Writing editor"), "aria-multiline": "true", spellcheck: "true" }),
|
|
EditorView.updateListener.of(update => {
|
|
if (update.docChanged || update.selectionSet) {
|
|
menu?.close(false);
|
|
onSelectionLine?.(update.state.doc.lineAt(update.state.selection.main.head).number);
|
|
}
|
|
const isolation = update.transactions.map(transaction => transaction.annotation(isolateHistory));
|
|
const separate = update.transactions.some(transaction => {
|
|
const event = transaction.annotation(Transaction.userEvent);
|
|
return transaction.docChanged && event && !/^(input\.type|delete)($|\.)/.test(event);
|
|
});
|
|
if (separate || (update.selectionSet && !update.docChanged)) model?.pushStackElement();
|
|
if (isolation.some(value => value === "before" || value === "full")) model?.pushStackElement();
|
|
if (update.docChanged) {
|
|
scroll = scroll?.map(update.changes);
|
|
publish(modelSource(update.state), current.id, update.startState, update.state);
|
|
void loadImages(current.relPath, update.state.sliceDoc()).then(changed => {
|
|
if (changed && editor === update.view) update.view.dispatch({ effects: refreshImages.of() });
|
|
});
|
|
}
|
|
if (isolation.some(value => value === "after" || value === "full")) {
|
|
clearTimeout(historyTimer);
|
|
model?.pushStackElement();
|
|
}
|
|
}),
|
|
EditorView.domEventHandlers({
|
|
contextmenu(event, view) {
|
|
if (event.target instanceof Element && event.target.closest(".writer-table")) return false;
|
|
event.preventDefault();
|
|
const position = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
|
|
const selection = view.state.selection.main;
|
|
if (position !== null && (selection.empty || position < selection.from || position > selection.to)) view.dispatch({ selection: { anchor: position } });
|
|
menu?.open(event.clientX, event.clientY, selection.empty && isSpellingTarget(event.target) ? position ?? undefined : undefined, position ?? undefined);
|
|
return true;
|
|
},
|
|
keydown(event, view) {
|
|
if (event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10")) return false;
|
|
if (event.target instanceof Element && event.target.closest(".writer-table")) return false;
|
|
event.preventDefault();
|
|
const coords = view.coordsAtPos(view.state.selection.main.head);
|
|
if (coords) menu?.open(coords.left, coords.bottom, view.state.selection.main.empty ? view.state.selection.main.head : undefined);
|
|
return true;
|
|
},
|
|
mousedown(event, view) {
|
|
if (!event.ctrlKey && !event.metaKey) return false;
|
|
if (event.button !== 0) return false;
|
|
const link = event.target instanceof Element ? event.target.closest("[data-href], a") : null;
|
|
const position = view.posAtCoords({ x: event.clientX, y: event.clientY });
|
|
const sourceLink = position === null ? undefined : documentLinkAt(view.state.doc.toString(), position);
|
|
if (!link && !sourceLink) return false;
|
|
event.preventDefault();
|
|
onOpenLink?.(sourceLink?.kind ?? (link?.getAttribute("data-kind") === "wiki" ? "wiki" : "md"), sourceLink?.target ?? link?.getAttribute("data-href") ?? link?.getAttribute("href") ?? "");
|
|
return true;
|
|
},
|
|
paste(event, view) {
|
|
const html = event.clipboardData?.getData("text/html") || "";
|
|
if (/<table[\s>]/i.test(html)) {
|
|
const markdown = htmlToMarkdown(html).replace(/\r\n?/g, "\n").trim();
|
|
if (markdown) {
|
|
event.preventDefault(); event.stopPropagation();
|
|
const { from, to } = view.state.selection.main;
|
|
const insert = imageInsertion(view.state.doc.toString(), from, to, [markdown]);
|
|
view.dispatch({ changes: { from, to, insert }, selection: { anchor: from + insert.length }, userEvent: "input.paste", annotations: isolateHistory.of("full") });
|
|
return true;
|
|
}
|
|
}
|
|
if (!onInsertImage || !imageFiles(event.clipboardData).length) return false;
|
|
void insertImages(event, view); return true;
|
|
},
|
|
}),
|
|
];
|
|
// Start in the body so the initial caret does not reveal properties source.
|
|
// Saved selections and explicit line navigation still restore their positions.
|
|
freshState = source => {
|
|
const doc = EditorState.create({ doc: source }).doc;
|
|
return EditorState.create({ doc, selection: { anchor: documentBodyStart(doc.toString()) }, extensions });
|
|
};
|
|
const saved = session.writer;
|
|
const state = saved?.source === lastValue
|
|
? EditorState.fromJSON(saved.state, { extensions })
|
|
: freshState(lastValue);
|
|
// Restore through CodeMirror's layout pass, once its viewport is measured.
|
|
const view = new EditorView({ state, parent: el, scrollTo: saved?.source === lastValue ? saved.scroll : undefined });
|
|
editor = view;
|
|
onSelectionLine?.(view.state.doc.lineAt(view.state.selection.main.head).number);
|
|
// Writer and IDE use the same model and undo stack for this document.
|
|
contentListener = model.onDidChangeContent(event => {
|
|
if (publishing) return;
|
|
const value = model!.getValue();
|
|
if (value === modelSource(view.state)) return;
|
|
lastValue = value;
|
|
const changes = event.changes.map(change => ({
|
|
from: view.state.doc.line(change.range.startLineNumber).from + change.range.startColumn - 1,
|
|
to: view.state.doc.line(change.range.endLineNumber).from + change.range.endColumn - 1,
|
|
insert: change.text,
|
|
}));
|
|
if (event.isFlush) historySelections?.clear();
|
|
const selection = event.isUndoing || event.isRedoing ? historySelections?.get(model!.getAlternativeVersionId()) : undefined;
|
|
view.dispatch({ changes, selection, scrollIntoView: !!selection, annotations: Transaction.addToHistory.of(false) });
|
|
onChange(value, current.id);
|
|
});
|
|
scroll = saved?.source === lastValue ? saved.scroll : view.scrollSnapshot();
|
|
// Svelte may detach the old tab before effect cleanup runs, at which point
|
|
// DOM scroll offsets read as zero. Capture while the view is still mounted.
|
|
const saveScroll = () => { if (view.dom.isConnected) scroll = view.scrollSnapshot(); };
|
|
view.scrollDOM.addEventListener("scroll", saveScroll);
|
|
releaseScroll = () => view.scrollDOM.removeEventListener("scroll", saveScroll);
|
|
releaseDrop = registerImageDropTarget(el, (path, point) => { void importImages(view, [], view.posAtCoords(point, false), path); });
|
|
releaseSelection = registerSelection(current.id, () => view.state.selection.ranges.map(range => view.state.sliceDoc(range.from, range.to)).join("\n"));
|
|
menu = markdownMenu({
|
|
snapshot() {
|
|
const { doc, selection } = view.state;
|
|
return { source: doc.toString(), selection: selection.main, valid: () => editor === view && view.state.doc === doc && view.state.selection.eq(selection) };
|
|
},
|
|
apply(edit) { view.dispatch({ changes: { from: edit.from, to: edit.to, insert: edit.insert }, selection: { anchor: edit.anchor, head: edit.head }, userEvent: "input.markdown", annotations: isolateHistory.of("full") }); },
|
|
select(from, to) { view.dispatch({ selection: { anchor: from, head: to }, scrollIntoView: true }); },
|
|
selectAll() { view.dispatch({ selection: { anchor: 0, head: view.state.doc.length } }); view.focus(); },
|
|
focus() { view.focus(); },
|
|
undo() { clearTimeout(historyTimer); model?.pushStackElement(); void model?.undo(); },
|
|
redo() { clearTimeout(historyTimer); void model?.redo(); },
|
|
canUndo() { return model?.canUndo() ?? false; },
|
|
canRedo() { return model?.canRedo() ?? false; },
|
|
}, untrack(() => tableActions), message => { error = message; }, () => ({ ...linkActions, open: link => onOpenLink?.(link.kind, link.target) }));
|
|
if (!focusTitle && shouldFocusOnMount()) view.focus();
|
|
}).catch(reason => { if (!cancelled) error = String(reason); });
|
|
return () => {
|
|
cancelled = true;
|
|
refreshVersion++;
|
|
clearTimeout(historyTimer);
|
|
model?.pushStackElement();
|
|
contentListener?.dispose();
|
|
menu?.destroy();
|
|
releaseDrop?.();
|
|
releaseScroll?.();
|
|
if (session && editor && scroll) session.writer = { source: modelSource(editor.state), state: editor.state.toJSON(), scroll };
|
|
editor?.destroy();
|
|
if (session) releaseEditorSession(session);
|
|
releaseSelection?.();
|
|
editor = undefined;
|
|
};
|
|
});
|
|
|
|
$effect(() => {
|
|
void $pluginHost;
|
|
editor?.dispatch({ effects: refreshImages.of() });
|
|
});
|
|
|
|
$effect(() => {
|
|
const name = markdownTitle(buffer.relPath);
|
|
const view = editor;
|
|
if (view) view.dispatch({ effects: title.reconfigure(noteTitle(name, onRenameTitle ? renameTitle : undefined)) });
|
|
});
|
|
|
|
$effect(() => {
|
|
if (!focusTitle || !editor) return;
|
|
const button = editor.dom.querySelector<HTMLButtonElement>(".note-title-button");
|
|
if (!button) return;
|
|
button.click();
|
|
onTitleFocused?.();
|
|
});
|
|
|
|
$effect(() => {
|
|
const value = buffer.contents;
|
|
const path = buffer.relPath;
|
|
const view = editor;
|
|
if (!view || value === lastValue) return;
|
|
const version = ++refreshVersion;
|
|
void loadImages(path, value).then(() => {
|
|
if (version !== refreshVersion || editor !== view || buffer.contents !== value || !freshState) return;
|
|
lastValue = value;
|
|
if (model?.getValue() !== value) model?.setValue(value);
|
|
// Reloads start fresh history, so undo cannot revive a discarded disk version.
|
|
const anchor = Math.min(view.state.selection.main.head, value.replace(/\r\n/g, "\n").length);
|
|
view.setState(freshState(value));
|
|
view.dispatch({ selection: { anchor }, effects: title.reconfigure(noteTitle(markdownTitle(buffer.relPath), onRenameTitle ? renameTitle : undefined)) });
|
|
});
|
|
});
|
|
|
|
$effect(() => {
|
|
const line = focusLine;
|
|
const view = editor;
|
|
if (!view || line == null) return;
|
|
untrack(() => {
|
|
const anchor = view.state.doc.line(Math.min(view.state.doc.lines, Math.max(1, line))).from;
|
|
view.dispatch({ selection: { anchor }, effects: EditorView.scrollIntoView(anchor, { y: "center" }) });
|
|
view.focus();
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<div class="live-writer" bind:this={host} role="application" aria-label={$t("Markdown writing editor")}
|
|
ondragovercapture={(event) => {
|
|
if (!onInsertImage || !hasFileDrag(event.dataTransfer)) return;
|
|
event.preventDefault();
|
|
if (event.dataTransfer) event.dataTransfer.dropEffect = "copy";
|
|
}}
|
|
ondropcapture={(event) => { if (editor) void insertImages(event, editor); }}
|
|
></div>
|
|
{#if error}<p class="editor-notice" role="alert">{error}<button onclick={() => { error = ""; }}>{$t("Dismiss")}</button></p>{/if}
|
|
|
|
<style>
|
|
.live-writer { position: absolute; inset: 0; }
|
|
.live-writer :global(.cm-editor) { height: 100%; color: var(--rs-text); background: transparent; }
|
|
.live-writer :global(.cm-editor.cm-focused) { outline: none; }
|
|
.live-writer :global(.cm-scroller) { overflow: auto; font: var(--rs-font-weight) var(--rs-prose-size)/var(--rs-prose-line) var(--rs-font-prose); scrollbar-gutter: stable; }
|
|
.live-writer :global(.cm-content) { max-width: 868px; width: 100%; margin: 0 auto; padding: clamp(24px, 4vw, 56px) clamp(22px, 4vw, 64px) 35vh; caret-color: var(--rs-text-strong); }
|
|
.live-writer :global(.cm-line) { padding-inline: 0; position: relative; }
|
|
.live-writer :global(.cm-line:hover)::before { content: ""; position: absolute; left: -14px; top: 2px; bottom: 2px; width: 3px; border-radius: var(--rs-control-radius); background: var(--rs-text-dim); opacity: .5; pointer-events: none; }
|
|
.live-writer :global(.writer-heading:hover)::before { display: none; }
|
|
.live-writer :global(.cm-panels) { background: var(--rs-bg-elevated); color: var(--rs-text); }
|
|
.live-writer :global(.cm-cursor) { border-left-color: var(--rs-text-strong); }
|
|
.live-writer :global(.cm-editor .cm-selectionLayer .cm-selectionBackground), .live-writer :global(.cm-editor.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground) { background: var(--rs-selection); }
|
|
.live-writer :global(.writer-blank) { font-size: .75em; }
|
|
.live-writer :global(.writer-strong) { font-weight: 600; color: var(--rs-text-strong); }
|
|
.live-writer :global(.writer-emphasis) { font-style: italic; }
|
|
.live-writer :global(.writer-strike), .live-writer :global(.writer-completed) { text-decoration: line-through; color: var(--rs-text-dim); }
|
|
.live-writer :global(.writer-link) { color: var(--rs-accent); text-decoration: underline; text-underline-offset: 3px; }
|
|
.live-writer :global(.writer-link-source) { color: var(--rs-accent); }
|
|
.live-writer :global(.writer-link-target) { text-decoration: underline; text-underline-offset: 3px; }
|
|
.live-writer :global(.writer-inline-code), .live-writer :global(.writer-code-source) { font-family: var(--rs-font-mono); font-size: .9em; }
|
|
.live-writer :global(.writer-inline-code) { background: var(--rs-bg-elevated); border-radius: 3px; }
|
|
.live-writer :global(.writer-code-line) { padding: 0 20px; border-inline: 1px solid var(--rs-border); background: var(--rs-code-block-bg); font: 13px/1.65 var(--rs-font-mono); tab-size: 4; }
|
|
.live-writer :global(.writer-code-first) { padding-top: 10px; border-top: 1px solid var(--rs-border); border-radius: var(--rs-control-radius) var(--rs-control-radius) 0 0; padding-right: 44px; }
|
|
.live-writer :global(.writer-code-last) { padding-bottom: 10px; border-bottom: 1px solid var(--rs-border); border-radius: 0 0 var(--rs-control-radius) var(--rs-control-radius); }
|
|
.live-writer :global(.writer-code-fence) { color: var(--rs-text-dim); }
|
|
.live-writer :global(.writer-code-copy) { top: 4px; border-radius: var(--rs-control-radius); }
|
|
.live-writer :global(.writer-code-copy:focus-visible) { outline: 1px solid var(--rs-accent); outline-offset: -2px; }
|
|
.live-writer :global(.writer-highlight) { background: #e7c56a38; color: var(--rs-text-strong); }
|
|
.live-writer :global(.writer-math) { font-family: var(--rs-font-mono); font-style: italic; }
|
|
.live-writer :global(.writer-comment) { color: var(--rs-text-dim); background: var(--rs-bg-active); }
|
|
.live-writer :global(.writer-divider-line) { display: flex; align-items: center; }
|
|
.live-writer :global(.writer-divider) { display: inline-flex; align-items: center; flex: 1; min-width: 0; height: 1.75em; cursor: text; }
|
|
.live-writer :global(.writer-divider::after) { content: ""; width: 100%; border-top: 1px solid var(--rs-border); }
|
|
.live-writer :global(.writer-checkbox) { display: inline-block; position: static; width: 15px; height: 15px; margin: 0 .55em 0 0; vertical-align: -.1em; accent-color: var(--rs-accent); cursor: pointer; }
|
|
/* Keep child margins inside the measured widget; collapsed margins otherwise
|
|
shift mouse hit-testing to the next line after a table or other preview. */
|
|
.live-writer :global(.writer-preview) { display: flow-root; max-width: none; margin: 0; }
|
|
.live-writer :global(.writer-preview > :last-child) { margin-bottom: 0; }
|
|
.live-writer :global(.writer-preview img) { max-width: 100%; }
|
|
.live-writer :global(.writer-table) { position: relative; width: fit-content; max-width: 100%; margin: 1.4em 0 0; padding: 26px; }
|
|
.live-writer :global(.writer-table .md-table-scroll) { margin: 0; border-radius: 0; }
|
|
.live-writer :global(.writer-table td), .live-writer :global(.writer-table th) { cursor: text; }
|
|
.live-writer :global(.writer-cell-editor) { outline: none; min-height: 1lh; white-space: pre-wrap; overflow-wrap: break-word; }
|
|
.live-writer :global(.writer-table p) { margin: 0; }
|
|
.live-writer :global(.table-add) { position: absolute; display: block; padding: 0; opacity: 0; border: 1px solid var(--rs-border); background: var(--rs-bg-elevated); color: var(--rs-text-dim); cursor: pointer; transition: opacity 100ms; }
|
|
.live-writer :global(.table-add:hover), .live-writer :global(.table-add:focus-visible) { opacity: 1; color: var(--rs-accent); border-color: var(--rs-accent-deep); outline: none; }
|
|
.live-writer :global(.table-add-column) { right: 0; top: 26px; bottom: 26px; width: 26px; border-radius: 0 4px 4px 0; }
|
|
.live-writer :global(.table-add-row) { left: 26px; right: 26px; bottom: 0; height: 26px; border-radius: 0 0 4px 4px; }
|
|
.live-writer :global(.table-add span) { position: absolute; font: 20px/24px var(--rs-font-ui); width: 24px; height: 24px; text-align: center; pointer-events: none; }
|
|
.live-writer :global(.table-add-column span) { left: 0; top: var(--table-add-position, 50%); transform: translateY(-50%); }
|
|
.live-writer :global(.table-add-row span) { top: 0; left: var(--table-add-position, 50%); transform: translateX(-50%); }
|
|
</style>
|