Add interface languages and improve themes and workspace controls for 0.1.36

This commit is contained in:
Knotty Wyvern
2026-10-15 10:55:59 -07:00
parent b066359b66
commit 68e86ab6eb
98 changed files with 5499 additions and 874 deletions
+18 -17
View File
@@ -1,3 +1,4 @@
import { tr } from '../i18n/index.ts';
import { getMarkRange, type Editor, type JSONContent } from "@tiptap/core";
import { requestText } from "../workspace/dialogs.svelte";
import { extractedCellMarkdown } from "./tableCellMarkdown";
@@ -29,15 +30,15 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
}
function link(external: boolean) {
void request(async () => {
const target = await requestText(external ? "External link URL" : "Link to note (name or workspace path)", external ? "https://" : text);
const target = await requestText(external ? tr("External link URL") : tr("Link to note (name or workspace path)"), external ? "https://" : text);
if (!target || !valid()) return;
if (external) {
try {
const url = new URL(target);
if (!(["http:", "https:"].includes(url.protocol) && url.hostname || url.protocol === "mailto:" && url.pathname.includes("@")) || /\s/.test(target)) throw new Error("Invalid URL");
} catch { report("Enter a valid http, https, or mailto link."); return; }
} catch { report(tr("Enter a valid http, https, or mailto link.")); return; }
}
if (!external && /[\[\]|\r\n]|^[a-z][a-z\d+.-]*:/i.test(target)) { report("Enter a note name or path without brackets or pipes."); return; }
if (!external && /[\[\]|\r\n]|^[a-z][a-z\d+.-]*:/i.test(target)) { report(tr("Enter a note name or path without brackets or pipes.")); return; }
run(() => {
const attrs = { href: target, "data-kind": external ? "md" : "wiki" };
if (selection.empty) editor.commands.insertContent({ type: "text", text: target, marks: [{ type: "link", attrs }] });
@@ -88,35 +89,35 @@ export function tableTextItems(editor: Editor, actions: TableContextActions, clo
}
});
}
} catch { report("Clipboard unavailable. Use the keyboard shortcut to copy, cut, or paste."); }
} catch { report(tr("Clipboard unavailable. Use the keyboard shortcut to copy, cut, or paste.")); }
});
}
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) },
{ label: tr("Add link"), icon: "link", run: () => link(false) },
{ label: tr("Add external link"), icon: "external", run: () => link(true) },
{ separator: true },
{ label: text ? `Search for “${text.length > 32 ? text.slice(0, 32) + "…" : text}”` : "Search selection", icon: "search", disabled: !text || !actions.onSearch, run: () => { close(); actions.onSearch?.(text); } },
{ label: "Extract current selection…", icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
{ label: text ? tr("Search for “{text}”", { text: text.length > 32 ? text.slice(0, 32) + "…" : text }) : tr("Search selection"), icon: "search", disabled: !text || !actions.onSearch, run: () => { close(); actions.onSearch?.(text); } },
{ label: tr("Extract current selection…"), icon: "extract", disabled: !text || !actions.onExtract, run: () => void request(async () => {
const selected = doc.slice(selection.from, selection.to).content.toJSON() as JSONContent[] | null;
const markdown = extractedCellMarkdown(selected || []);
const target = await actions.onExtract?.(markdown, text, valid);
if (target) run(() => { editor.commands.insertContent({ type: "text", text: text.replace(/\s+/g, " ").trim(), marks: [{ type: "link", attrs: { href: target, "data-kind": "wiki" } }] }); });
}) },
{ label: "Format", icon: "format", children: cellFormats.map(([label, kind]) => ({ label, icon: kind, disabled: selection.empty, run: () => run(() => {
{ label: tr("Format"), icon: "format", children: cellFormats.map(([label, kind]) => ({ label: tr(label), icon: kind, disabled: selection.empty, run: () => run(() => {
if (kind === "clear") editor.commands.unsetAllMarks(); else editor.commands.toggleMark(kind);
}) })) },
{ label: "Paragraph", icon: "paragraph", disabled: true, title: "Markdown table cells contain inline text" },
{ label: "Insert", icon: "insert", disabled: true, title: "Use the Row and Column menus to change the table" },
{ label: tr("Paragraph"), icon: "paragraph", disabled: true, title: tr("Markdown table cells contain inline text") },
{ label: tr("Insert"), icon: "insert", disabled: true, title: tr("Use the Row and Column menus to change the table") },
{ separator: true },
{ label: "Cut", icon: "cut", disabled: selection.empty, run: () => void clipboard("cut") },
{ label: "Copy", icon: "copy", disabled: selection.empty, run: () => void clipboard("copy") },
{ label: "Paste", icon: "paste", run: () => void clipboard("paste") },
{ 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(); } },
{ label: tr("Cut"), icon: "cut", disabled: selection.empty, run: () => void clipboard("cut") },
{ label: tr("Copy"), icon: "copy", disabled: selection.empty, run: () => void clipboard("copy") },
{ label: tr("Paste"), icon: "paste", run: () => void clipboard("paste") },
{ label: tr("Paste as plain text"), icon: "paste-text", run: () => void clipboard("plain") },
{ label: tr("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.slice(items.findIndex(item => "label" in item && item.label === tr("Cut"))),
] : items;
}