import { Component, TFile } from "obsidian"; import { mount } from "svelte"; import App from "../src/ui/app.svelte"; import { DEFAULT_SETTINGS } from "../src/settings"; import { BoardStore } from "../src/vault/store.svelte"; const BOARDS = ["personal", "work", "reading", "home"]; const FOLDER = "Boards"; async function main(): Promise { const files = new Map(); await Promise.all( BOARDS.map(async (name) => { const response = await fetch(`/tests/fixtures/${name}.md`); files.set(`${FOLDER}/${name}.md`, await response.text()); }), ); const handles = new Map( [...files.keys()].map((path) => [path, new TFile(path)]), ); const app = { vault: { getMarkdownFiles: () => [...handles.values()], getAbstractFileByPath: (path: string) => handles.get(path) ?? null, cachedRead: async (file: TFile) => files.get(file.path) ?? "", read: async (file: TFile) => files.get(file.path) ?? "", process: async (file: TFile, fn: (data: string) => string) => { const next = fn(files.get(file.path) ?? ""); files.set(file.path, next); store.queueReload(file.path); return next; }, on: () => ({}), }, workspace: { getLeaf: () => ({}), activeEditor: null }, plugins: { plugins: {} }, }; const settings = { ...DEFAULT_SETTINGS, boardsFolder: FOLDER }; const store = new BoardStore(app as never, settings, () => {}); await store.reloadAll(); mount(App, { target: document.getElementById("app") as HTMLElement, props: { app: app as never, store, settings, component: new Component() as never, }, }); // Scenes for screenshots: open the page with a hash to land in a state. const scene = location.hash.slice(1); if (!scene) return; const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); await wait(50); store.keyboard = true; const first = store.spheres[0]; if (scene.startsWith("rail")) { store.toggleRail(); store.railExpanded = new Set([first.path, store.spheres[1].path]); if (scene === "rail-some") { store.toggleSphere(store.spheres[2].path); store.toggleLane(first.path, first.projects[0]); store.cursorRail = `lane:${encodeURIComponent(first.path)} ${encodeURIComponent(first.projects[0])}`; } if (scene === "rail-none") store.filterNone(); } if (scene.startsWith("peek")) { if (scene === "peek-cal") store.view = "calendar"; if (scene === "peek-notes") store.showDone = true; await wait(20); const task = store.visible.find((item) => item.body.length > 0) ?? store.visible[0]; if (scene === "peek-cal") { const key = task.due ?? task.scheduled; if (key) store.focusDay(key); } store.zone = "task"; store.cursorTask = task.id; await wait(50); store.peek(); } if (scene === "date") { store.write(null, "[data-composer='toolbar']"); await wait(50); for (let i = 0; i < 3; i += 1) { document.activeElement?.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab", bubbles: true })); await wait(20); } } } void main();