Files
beaver-calendar/preview/entry.ts
T
2026-08-08 16:30:22 +02:00

56 lines
1.7 KiB
TypeScript

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<void> {
const files = new Map<string, string>();
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,
},
});
}
void main();