Update editor, themes, menus, backgrounds, and release tooling

This commit is contained in:
Knotty Wyvern
2026-10-14 16:19:51 -07:00
parent f6eaa52949
commit edef2520af
113 changed files with 5722 additions and 386 deletions
+29 -14
View File
@@ -1,5 +1,5 @@
import { StateEffect, StateField, type EditorState, type Range } from "@codemirror/state";
import { Decoration, EditorView, WidgetType, type DecorationSet } from "@codemirror/view";
import { Decoration, EditorView, ViewPlugin, WidgetType, type DecorationSet } from "@codemirror/view";
import { syntaxTree, foldedRanges, foldEffect, unfoldEffect } from "@codemirror/language";
import { renderMarkdownSections } from "../workspace/noteHtml";
import { renderDiagrams } from "../workspace/diagrams";
@@ -10,6 +10,8 @@ import { imageControls } from "./imageControls";
import { ImagePreview, type ImageContext } from "./imagePreview";
import { imageSource, editImageSource, imageSourceRanges } from "./imageSource";
import { actionIcon } from "../ui/actionIcons";
import { attachTooltip } from "../ui/tooltip";
import { documentLinks } from "./documentLinks";
import { pluginHost } from "../plugins/registry.ts";
@@ -17,6 +19,20 @@ const previewFormulas = new WeakMap<HTMLElement, unknown>();
export const refreshImages = StateEffect.define<void>();
const imageCleanups = new WeakMap<HTMLElement, () => void>();
const linkTooltips = ViewPlugin.define(view => {
const attached = new Map<HTMLElement, () => void>();
const refresh = () => {
for (const [node, dispose] of attached) if (!view.dom.contains(node)) { dispose(); attached.delete(node); }
for (const node of view.dom.querySelectorAll<HTMLElement>("[data-editor-tooltip]")) {
if (!attached.has(node)) attached.set(node, attachTooltip(node, () => node.dataset.editorTooltip || ""));
}
};
const observer = new MutationObserver(refresh);
observer.observe(view.dom, { childList: true, subtree: true });
refresh();
return { destroy() { observer.disconnect(); attached.forEach(dispose => dispose()); } };
});
class CodeCopy extends WidgetType {
constructor(readonly code: string) { super(); }
eq(other: CodeCopy) { return this.code === other.code; }
@@ -25,24 +41,18 @@ class CodeCopy extends WidgetType {
button.type = "button";
button.className = "rs-fence-copy writer-code-copy";
button.setAttribute("aria-label", "Copy code");
button.title = "Copy code";
const help = document.createElement("span");
help.className = "writer-code-tooltip";
help.setAttribute("role", "tooltip");
help.textContent = "Copy code";
button.append(actionIcon("copy"), help);
button.dataset.editorTooltip = "Copy code";
button.append(actionIcon("copy"));
button.onmousedown = event => event.preventDefault();
button.onclick = async event => {
event.preventDefault(); event.stopPropagation();
try {
await navigator.clipboard.writeText(this.code);
button.dataset.copied = "true";
button.title = "Copied";
help.textContent = "Copied";
button.dataset.editorTooltip = "Copied";
button.setAttribute("aria-label", "Code copied");
} catch {
button.title = "Could not copy code";
help.textContent = "Could not copy code";
button.dataset.editorTooltip = "Could not copy code";
button.setAttribute("aria-label", "Could not copy code");
}
};
@@ -238,7 +248,7 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
if (!match) return;
replace(node.from, node.from + 1);
replace(node.from + 1 + match[1].length, node.to);
ranges.push(Decoration.mark({ class: "writer-link", attributes: { "data-href": match[2], "data-kind": "md", title: "Ctrl+click to open link" } }).range(node.from + 1, node.from + 1 + match[1].length));
ranges.push(Decoration.mark({ class: "writer-link", attributes: { "data-href": match[2], "data-kind": "md", "data-editor-tooltip": "Ctrl+click to open link" } }).range(node.from + 1, node.from + 1 + match[1].length));
return false;
}
if (node.name === "TaskMarker") {
@@ -261,11 +271,16 @@ export function liveMarkdown(urls: Map<string, string>, actions: TableContextAct
const labelStart = from + 2 + (separator < 0 ? 0 : separator + 1);
replace(from, labelStart);
replace(to - 2, to);
ranges.push(Decoration.mark({ class: "writer-link", attributes: { "data-kind": "wiki", "data-href": match[1].split("|")[0] } }).range(labelStart, to - 2));
ranges.push(Decoration.mark({ class: "writer-link", attributes: { "data-kind": "wiki", "data-href": match[1].split("|")[0], "data-editor-tooltip": "Ctrl+click to open link" } }).range(labelStart, to - 2));
}
for (const link of documentLinks(source)) {
if (!selected(link.from, link.to) || hidden(link.from, link.to)) continue;
mark(link.from, link.to, "writer-link-source");
mark(link.targetFrom, link.targetTo, "writer-link-target");
}
return Decoration.set(ranges, true);
}
return [imageSource, StateField.define<DecorationSet>({
return [imageSource, linkTooltips, StateField.define<DecorationSet>({
create: build,
update(value, transaction) {
return transaction.docChanged || transaction.selection