notesy::sections

A section of the sidebar, under notesy's notes and tags: a tree of the plugin's own (bookmarks, tasks, a list from somewhere), drawn like the vault's and folded the same way. Its script adds it; takes the ui permission.

rustuse notesy::{events, sections, Event};

pub fn ready() {
    let pinned = sections::add("pinned", "Pinned");
    pinned.set([
        #{ id: "plan", name: "Launch plan", icon: "pin", note: "Projects/Launch plan.md" },
        #{ id: "reading", name: "Reading", children: [
            #{ id: "book", name: "The book", note: "Reading/The book.md", detail: "p. 120" },
        ] },
    ]);
    events::on(Event::SidebarItem, |event| { /* event.section, event.item */ });
    // Right-click an item: "Unpin". `item` is the id of the one it was opened on.
    pinned.menu("unpin", #{ title: "Unpin", icon: "pin" }, |item| { /* unpin it */ });
}
Function What it does
sections::add(key, options) Adds a section, empty until it's set, and returns it. options is its title, or #{ title }.
section.set(items) Replaces what it shows.
section.action(key, options, run) Adds a button to its heading, and returns it: options as a menu item's (#{ title, icon }, notesy::menus), the title its tip; run() when it's clicked.
sections::action(section, key, options, run) The same on one of notesy's own sections' headings: Sidebar::Notes or Sidebar::Tags (Names: Icon, Color, Tone, Side, Method, Command, Menu, Sidebar, Event).
section.menu(key, options, run) Adds an item to its items' right-click menu, and returns it: options as a menu item's (notesy::menus), and run(item) gets the id of the item the menu was opened on.
section.remove() Takes it away.

key names it for good (lowercase letters, digits, -, _ and ., starting with a letter): notesy remembers which of its folders are open by it.

An item is #{ id, name } and any of:

Field What it is
icon Its icon, by name (notesy::view).
detail Faint text at its right, like a count.
note A note (relative to the vault) a click opens.
command A command a click runs, instead: a command's id(), or notesy's own.
children Items inside it: it's a folder.
menu Which of its section's menu items its right-click menu has, by key (["unpin"]); every one unless it says, and none for [].

Ids are unique within the section: they say which item was clicked, and which folders stay open. The plugin hears every click as the sidebar.item event, whatever the item opens (notesy::events). A heading's buttons show at its right while the pointer's on it: notesy's own first (Notes has New note, New folder and Close every folder), then plugins', at most 4 of a plugin's on one heading. remove() on what action returned takes a button away.

An item that opens a note has "Open in new tab" in its menu too, before the section's own items. At most 500 items at the top, nested 8 deep. Whatever a script added goes when it stops.

Every page