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::zones), the title its tip; run() when it's clicked.
section.heading_menu(key, options, run) Adds an item to its heading's right-click menu, and returns it: options as a menu item's, and run() when it's picked.
button.menu(key, options, run) On a button action returned: adds an item to the button's own right-click menu, and returns it; run() when it's picked. A button with none opens no menu.
section.menu(key, options, run) Adds an item to its items' right-click menu, and returns it: options as a menu item's (notesy::zones), and run(item) gets the id of the item the menu was opened on.
section.on_drop(accept, run) Says what can be dropped on it, and run(drop) gets each drop (below). accept names what it takes, or lists them: "items" (its own, moved about), "notes", "folders", "files", "images", or files by extension, like ".pdf".
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 [].
drag Whether it can be dragged: true or false. Unless it says, it can when its section takes "items", or it opens a note (dragged into a note or onto a board, it drops a link to the note).
drop What can be dropped into it, named as on_drop names them. Unless it says, a folder takes what its section does, and anything else nothing.

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 canvas, New folder and Close every folder), then plugins', at most 4 of a plugin's on one heading. A right-click on a heading opens its menu: Notes' has New note, New canvas and New folder, then plugins' items for the heading; with nothing in it, none opens. remove() on what action or heading_menu returned takes it 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.

#Dragging and dropping

What a section takes can be dropped on it: on its heading or the room it takes (into the section itself), before or after one of its items (a line shows where), or into an item that takes it (lit). Closed folders open when something's held over them, and the sidebar scrolls near its edges. run(drop) gets #{ kind, item, path, onto, place }:

Field What it is
kind "item": one of its own. "note", "folder" or "file": from the vault's tree.
item The id of its item that was dragged, for "item".
path Where the note, folder or file is in the vault, for the rest.
onto The id of the item it was dropped against; left out when it was dropped on the section itself, so ask with drop.get("onto").
place "before" or "after" that item, or "into" it (or into the section).

notesy moves nothing itself: the plugin puts what's dropped where it likes, and sets its items again. A drop from the tree hands over a path, so notes, folders and files are dropped only on sections of plugins with notes.read; without it, a section takes only its own items.

rustuse notesy::sections;

pub fn ready() {
    let pinned = sections::add("pinned", "Pinned");
    pinned.on_drop(["items", "notes"], |drop| {
        if drop.kind == "note" {
            // pin drop.path
        } else {
            // move drop.item drop.place drop.get("onto")
        }
        pinned.set([]); // its items, as they are now
    });
}

Every page