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
+28 -4
View File
@@ -1,9 +1,12 @@
import type { Editor, JSONContent } from "@tiptap/core";
import { getMarkRange, type Editor, type JSONContent } from "@tiptap/core";
import { requestText } from "../workspace/dialogs.svelte";
import { extractedCellMarkdown } from "./tableCellMarkdown";
import type { ActionMenuItem } from "../ui/actionMenu";
import { linkMenuItems, type DocumentLinkActions } from "./linkMenu";
import { documentLinkAt } from "./documentLinks";
export type TableContextActions = {
linkActions?: () => DocumentLinkActions;
onSearch?: (text: string) => void;
onExtract?: (markdown: string, label: string, valid: () => boolean) => Promise<string | null>;
};
@@ -13,8 +16,9 @@ export const cellFormats = [
["Code", "code"], ["Math", "math"], ["Comment", "comment"], ["Clear formatting", "clear"],
] as const;
export function tableTextItems(editor: Editor, actions: TableContextActions, close: () => void, transaction: (run: () => void) => void, pending: (value: boolean) => void, report: (message: string) => void): ActionMenuItem[] {
export function tableTextItems(editor: Editor, actions: TableContextActions, close: () => void, transaction: (run: () => void) => void, pending: (value: boolean) => void, report: (message: string) => void, editSource: (range: { from: number; to: number }) => void): ActionMenuItem[] {
const selection = editor.state.selection, doc = editor.state.doc;
const sourceEditing = editor.view.dom.parentElement?.classList.contains("is-source-editing");
const text = doc.textBetween(selection.from, selection.to, "\n");
const valid = () => !editor.isDestroyed && editor.state.doc === doc && editor.state.selection.eq(selection);
function run(command: () => void) { if (!valid()) return; close(); transaction(() => { editor.view.focus(); command(); }); }
@@ -41,6 +45,21 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
});
});
}
const at = doc.resolve(selection.from);
const mark = [...at.marks(), ...(at.nodeAfter?.marks || [])].find(mark => mark.type.name === "link");
const linkRange = mark && getMarkRange(doc.resolve(selection.from), mark.type, mark.attrs);
const sourceLink = sourceEditing ? documentLinkAt(doc.textContent, selection.from - 1)
|| documentLinkAt(doc.textContent, selection.from - 2) : undefined;
const selectedLink = sourceLink || (mark && linkRange ? { kind: mark.attrs["data-kind"] === "wiki" ? "wiki" as const : "md" as const, target: String(mark.attrs.href) } : undefined);
function editLink() {
if (!selectedLink) return;
if (!valid()) return;
close();
if (sourceLink) {
editor.commands.setTextSelection({ from: sourceLink.targetFrom + 1, to: sourceLink.targetTo + 1 });
editor.view.focus();
} else if (linkRange) editSource(linkRange);
}
async function clipboard(action: "cut" | "copy" | "paste" | "plain") {
await request(async () => {
try {
@@ -49,7 +68,7 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
if (action === "cut") run(() => { editor.commands.deleteSelection(); });
} else {
let html = "", value = "";
if (action === "paste" && navigator.clipboard.read) {
if (!sourceEditing && action === "paste" && navigator.clipboard.read) {
try {
const data = await navigator.clipboard.read();
const rich = data.find(item => item.types.includes("text/html"));
@@ -72,7 +91,8 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
} catch { report("Clipboard unavailable. Use the keyboard shortcut to copy, cut, or paste."); }
});
}
return [
const items: ActionMenuItem[] = [
...(selectedLink ? [...linkMenuItems(selectedLink, actions.linkActions?.() || {}, close, report, editLink), { separator: true as const }] : []),
{ label: "Add link", icon: "link", run: () => link(false) },
{ label: "Add external link", icon: "external", run: () => link(true) },
{ separator: true },
@@ -95,4 +115,8 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
{ label: "Paste as plain text", icon: "paste-text", run: () => void clipboard("plain") },
{ label: "Select all", icon: "select", run: () => { close(); editor.commands.selectAll(); editor.view.focus(); } },
];
return sourceEditing ? [
...(selectedLink ? [...linkMenuItems(selectedLink, actions.linkActions?.() || {}, close, report, editLink), { separator: true as const }] : []),
...items.slice(items.findIndex(item => "label" in item && item.label === "Cut")),
] : items;
}