Repository navigation
Expand file tree
/
Copy pathnotez-plugin.d.ts
More file actions
112 lines (102 loc) · 4.46 KB
/
Copy pathnotez-plugin.d.ts
File metadata and controls
112 lines (102 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// NoteZ plugin API — type definitions (API version 1.1.0).
// Use with JSDoc in main.js: /** @param {import("./notez-plugin").NoteZApi} api */
import type { Extension } from "@codemirror/state";
import type { EditorView } from "@codemirror/view";
export type Disposer = () => void;
export interface Command {
/** Without a dot it is prefixed with your plugin id. */
id: string;
title: string;
/** e.g. "Mod-Shift-k" (Mod = Ctrl). */
key?: string;
palette?: boolean;
run: () => unknown;
}
export interface ToolbarButton { id: string; title: string; /** inline SVG or short text */ icon: string; group?: string; run: () => void }
export interface StatusItem { id: string; priority?: number; title?: string; render: () => string; onClick?: () => void }
export interface Panel { id: string; title: string; icon: string; mount: (el: HTMLElement) => void | (() => void); /** Show the title next to the icon. */ label?: boolean }
export interface BlockRenderer {
/** Fenced-code language, e.g. "progress" for ```progress blocks. */
lang: string;
/** Typst markup inserted into the PDF in place of the block. */
toTypst: (code: string) => string | Promise<string>;
/** HTML/SVG shown inside the editor. */
preview?: (code: string, ctx: { dark: boolean }) => string | Promise<string>;
}
/** A "/" menu command. Typed as `/id arg1 arg2…`; the last argument takes the rest of the line. */
export interface SlashCommand {
/** Letters, digits and "-": what follows the "/". */
id: string;
title: string;
icon?: string;
/** Menu group (default "Plugins"). */
section?: string;
/** More search words, in any language. */
keys?: string;
/** Shown at the right of the menu entry. */
hint?: string;
/** Arguments; `options` completes one (e.g. a list of names). */
args?: { name: string; options?: () => string[] | Promise<string[]> }[];
mdOnly?: boolean;
typOnly?: boolean;
/** The typed "/command args" is already removed when this runs. */
run: (view: EditorView, args: string[]) => void;
}
export interface SearchHit { path: string; line: number; snippet: string; marks?: string[] }
export interface NoteMeta { tags: string[]; icon?: string; cover?: string; title?: string; aliases?: string[] }
export interface Events {
"vault:opened": { root: string };
"vault:changed": void;
"note:opened": { path: string };
"note:changed": { path: string; content: string };
"note:saved": { path: string };
"note:reloaded": { path: string; content: string };
"preview:rendered": { path: string; pages: number; millis: number; errors: number };
}
export interface NoteZApi {
version: string;
pluginId: string;
commands: { register(c: Command): Disposer; run(id: string): void };
events: { on<K extends keyof Events>(event: K, fn: (p: Events[K]) => void): Disposer };
toolbar: { addButton(b: ToolbarButton): Disposer };
statusBar: { addItem(s: StatusItem): Disposer };
panels: { add(p: Panel): Disposer };
blocks: { register(r: BlockRenderer): Disposer };
slash: { register(c: SlashCommand): Disposer };
editor: {
registerExtension(e: Extension): Disposer;
/** A CodeMirror completion source, asked after the built-in ones. */
registerCompletion(source: import("@codemirror/autocomplete").CompletionSource): Disposer;
view(): EditorView | null;
insert(text: string): void;
insertBlock(text: string): void;
selection(): string;
cm: { state: typeof import("@codemirror/state"); view: typeof import("@codemirror/view"); language: typeof import("@codemirror/language") };
};
notes: {
active(): { path: string; content: string } | null;
open(path: string): Promise<void>;
list(): Promise<string[]>;
};
vault: {
root(): string | null;
read(path: string): Promise<string>;
write(path: string, content: string): Promise<void>;
/** Search with the full query syntax (docs/SEARCH.md). */
search(q: string): Promise<SearchHit[]>;
/** Every tag with its note count. */
tags(): Promise<{ tag: string; count: number }[]>;
/** Tags, icon, cover, title and aliases of notes that have them, by path. */
meta(): Promise<Record<string, NoteMeta>>;
};
ui: {
notify(msg: string, kind?: "info" | "success" | "error"): void;
prompt(title: string, initial?: string): Promise<string | null>;
isDark(): boolean;
};
settings: { get<T>(key: string, fallback: T): T; set(key: string, value: unknown): void };
}
export interface NoteZPlugin {
onload(api: NoteZApi): void | Promise<void>;
onunload?(): void;
}