Update the browser, editor, settings, and installer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { actionMenu, type ActionMenuItem } from "../ui/actionMenu";
|
||||
import { requestText } from "../workspace/dialogs.svelte";
|
||||
import { pickLinkDocument } from "./documentPicker";
|
||||
import { externalLinkText, workspaceLinkText } from "./linkCommands";
|
||||
import { htmlToMarkdown } from "../workspace/htmlToMarkdown";
|
||||
import { cellFormats, type TableContextActions } from "./tableCellActions";
|
||||
import { formatText, insertBlock, paragraphText, replacement, type MarkdownEdit, type TextSelection, type ParagraphStyle, type InsertBlock } from "./markdownCommands";
|
||||
@@ -15,6 +16,7 @@ export type MarkdownMenuEditor = {
|
||||
// identical in the writing editor and the source editor.
|
||||
export function markdownMenu(editor: MarkdownMenuEditor, actions: TableContextActions, report: (message: string) => void) {
|
||||
let root: HTMLElement | undefined, destroyed = false;
|
||||
const pending = new AbortController();
|
||||
function close(focus = true) {
|
||||
root?.remove(); root = undefined;
|
||||
if (focus && !destroyed) editor.focus();
|
||||
@@ -41,21 +43,11 @@ export function markdownMenu(editor: MarkdownMenuEditor, actions: TableContextAc
|
||||
finally { if (valid()) editor.focus(); }
|
||||
}
|
||||
function link(external: boolean) {
|
||||
if (external) { apply(externalLinkText(source, selection)); return; }
|
||||
void request(async () => {
|
||||
const target = (await requestText(external ? "External link URL" : "Link to note (name or workspace path)", external ? "https://" : text))?.trim();
|
||||
const target = await pickLinkDocument(pending.signal);
|
||||
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();
|
||||
} catch { report("Enter a valid http, https, or mailto link."); return; }
|
||||
const label = (text || target).replace(/[\\[\]]/g, "\\$&").replace(/\r?\n/g, " ");
|
||||
apply(replacement(selection, `[${label}](${target.replace(/[()<>]/g, char => encodeURIComponent(char).replace("(", "%28").replace(")", "%29"))})`));
|
||||
} else {
|
||||
if (/[\[\]|\r\n]|^[a-z][a-z\d+.-]*:/i.test(target)) { report("Enter a note name or path without brackets or pipes."); return; }
|
||||
const label = text.replace(/[\[\]|]/g, "").replace(/\s+/g, " ").trim();
|
||||
apply(replacement(selection, `[[${target}${label && label !== target ? "|" + label : ""}]]`));
|
||||
}
|
||||
apply(workspaceLinkText(source, selection, target));
|
||||
});
|
||||
}
|
||||
function clipboard(kind: "cut" | "copy" | "paste" | "plain") {
|
||||
@@ -114,7 +106,7 @@ export function markdownMenu(editor: MarkdownMenuEditor, actions: TableContextAc
|
||||
root = actionMenu(x, y, items, close, "Markdown text actions");
|
||||
}
|
||||
return { open, close, destroy() {
|
||||
destroyed = true; close(false);
|
||||
destroyed = true; pending.abort(); close(false);
|
||||
document.removeEventListener("mousedown", outside, true);
|
||||
document.removeEventListener("scroll", scroll, true);
|
||||
window.removeEventListener("resize", resize);
|
||||
|
||||
Reference in New Issue
Block a user