notesy::views

Everything a plugin builds a view for: a panel beside the note, a tab of its own, and its part of the tree's hover cards. A script adds them as it runs, says what each shows, and can take them away again. They take the ui permission; a card takes notes.read as well, since it shows what is in the vault.

rustuse notesy::{log, view, views};

pub fn ready() {
    let tasks = views::panel("tasks", #{ title: "Tasks", icon: "check" }, tasks);
    tasks.on_click(|target, note| log::info(`clicked ${target}`));
    let board = views::tab("board", #{ title: "Task board", icon: "list" }, |note| view::note("Every task, on one board."));
}

fn tasks(note) {
    let note = match note {
        Some(note) => note,
        None => return view::empty("check", "No note open", "Open a note to see its tasks."),
    };
    view::note(`${note.words()} words in ${note.title()}`)
}

#Adding them

Function What it does
views::panel(key, options, build) Adds a side panel, with a command that shows and hides it, and returns it. build(note) makes what it shows (notesy::view): note is Some(note) for the note in front, a Note (its path, text, properties, headings, tasks … a method away), or None when there's none. A plugin that may read neither the note in front nor the vault's notes (editor or notes.read) always gets None: ui alone shows nothing of your notes to it.
views::tab(key, options, build) Adds a kind of tab, with an "Open" command in the palette, and returns it. build(note) gets None: a tab isn't about a note.
views::card(key, options, build) Adds its part to the tree's hover cards, and returns it. options is #{ on }note, file or folder, one or a list, all three unless it says — and build(target) makes what it shows, or None to show nothing on this one.

key names it for good: lowercase letters, digits, -, _ and ., starting with a letter. notesy remembers a pinned panel by it, so keep it the same from one version to the next. A panel and a tab can't share a key. options is its title, or #{ title, icon } (an icon by name). Adding one with a key it has already changes its title and what builds it.

#A panel, a tab

Method What it does
refresh() Builds it again wherever it shows: after the script's own data changed.
on_click(handler) handler(target, path) when something in it with a target is clicked; path is the note's, or None.
on_change(handler) handler(target, value, path) when a switch, box, field or choice in it with a target changes (notesy::view); it's built again after.
on_suggest(handler) handler(target, text, path) once typing pauses in a field of it that asks for suggestions (suggest: true); it answers with suggest, then or once it knows (notesy::view).
suggest(target, text, items) What it suggests for text in its field target: a list of text, or of #{ text, detail, icon, value }. Shown while that's what was last typed; a pick reaches on_change with its value (its text, unless it has one).
open() A tab only: opens it.
show() A panel only: shows it in the side panel, as its command does (it doesn't hide it): for a command of its own, or a preview.
badge(count) A panel only: how many things are waiting in it, as a count on its button; 0 takes the count away. Past nine the button says 9+.
menu(key, options, run) A panel only: adds an item to its button's right-click menu, and returns it (notesy::zones); run() when it's picked.
remove() Takes it away, with its command, its count and its menu items.

#When it's built

notesy asks the script for a view when it first shows, when the note in front changes (each edit, or another note), and after refresh. In between it draws the last one it got, so a slow script never slows the window: at worst the panel is a moment behind. Building a view runs within 5,000,000 instructions (Scripts); one that fails shows why in its place, and counts as a failure.

#Where they show

A plugin's panels are listed under its name in the list of every panel (the side panel's name, or the tab bar's panel button), where the user can pin them to the tab bar. A pinned panel's button carries its count (badge) and its own right-click menu (menu); while it is not pinned, its count is added to the one on the button that lists them, so nothing goes unsaid for being out of sight. Its views open from the palette ("Open: Task board"), like any tab. Whatever a script added goes when it stops.

#A card: when it's built, and what it's about

notesy asks the script for it when the pointer first rests on something, again once that's changed on disk, and after refresh. In between it shows the last one built, so a card never waits on a script: a plugin's part shows a moment after notesy's own, once it's built. It's built within a view's budget of 5,000,000 instructions (Scripts); one that fails shows why in its place, and counts as a failure. notesy keeps the last few dozen built.

A card is only looked at (the pointer leaves it to click anything), so nothing in it is heard: its targets and inputs do nothing there.

#A card

Method What it does
refresh() Builds it again wherever it shows: after the script's own data changed.
remove() Takes it away.

Every page