Update the browser, editor, settings, and installer
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { mount, unmount } from "svelte";
|
||||
import QuickOpen from "../layout/QuickOpen.svelte";
|
||||
|
||||
/** Use the workspace file picker without opening or switching the active note. */
|
||||
export function pickLinkDocument(signal: AbortSignal): Promise<string | null> {
|
||||
if (signal.aborted) return Promise.resolve(null);
|
||||
return new Promise(resolve => {
|
||||
const target = document.createElement("div");
|
||||
document.body.append(target);
|
||||
let component: ReturnType<typeof mount> | undefined;
|
||||
let finished = false;
|
||||
const finish = (path: string | null) => {
|
||||
if (finished) return;
|
||||
finished = true;
|
||||
signal.removeEventListener("abort", cancel);
|
||||
if (component) void unmount(component).finally(() => target.remove());
|
||||
else target.remove();
|
||||
resolve(path);
|
||||
};
|
||||
const cancel = () => finish(null);
|
||||
try {
|
||||
component = mount(QuickOpen, { target, props: {
|
||||
onOpen: entry => finish(entry.rel_path),
|
||||
onClose: cancel,
|
||||
purpose: "Add workspace link",
|
||||
actionLabel: "insert link",
|
||||
} });
|
||||
} catch (error) { target.remove(); throw error; }
|
||||
signal.addEventListener("abort", cancel, { once: true });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user