Skip to content

PluginQuery

Searches the library, and extends the search. The search language is the text that the person types in the search field, for example #phone is:open. A plugin can add words to this language (clause), hide rows from every search (filter), and hide rows from outlines (hideRows). It can also run a search itself (run) and offer lists to the screen (view). Requires read.

Find the open rows that have the tag #phone

const hits = ctx.query.run('#phone is:open'); // [{ outline, id }, …]
for (const hit of hits) ctx.log('info', ctx.state.row(hit.id)?.title ?? '');
clause(parse): object;

Adds words to the search language. The app calls parse with the words of a search that no other parser has understood yet. The function returns the conditions that it built from the words that it knows (clauses), and the words that it did not use (rest), which stay available to the other parsers.

Parameter Type Description
parse (tokens, context) => | void | { clauses: QueryClause[]; rest: string[]; } receives the words of the search and a context that holds the current time and the person, and returns { clauses, rest }

object

an object with dispose(), which removes the parser

Name Type
dispose() () => void

dayParser(parse): object;

Teaches the search to read a day that is written in words, as in before:friday.

Parameter Type Description
parse (text, now) => string | null receives the text and the current time, and returns the day, or null when it does not understand the text

object

an object with dispose(), which removes the parser

Name Type
dispose() () => void

declare<A>(name): ViewRef<A>;

Creates the reference of a view of the plugin. The name is written here once, and it starts with the id of the plugin. The screen opens the view through the reference that this call returns.

Type Parameter Default type Description
A undefined the type of the arguments that the view accepts
Parameter Type Description
name string the name of the view, which starts with the id of the plugin

ViewRef<A>

the reference that identifies the view


filter(filter, options?): object;

Adds a condition that every search has to satisfy, so that some rows never appear, whatever the person asks. The app calls when once for each search, and when says whether the condition can hide anything. When it cannot, the app checks no row.

Parameter Type Description
filter (row, view, options) => boolean receives a row, the state of the library and the options of the search, and returns true to keep the row
options? { when?: (view, options) => boolean; } when states whether the condition can hide anything in this search
options.when? (view, options) => boolean -

object

an object with dispose(), which removes the condition

Name Type
dispose() () => void

hideRows(hide, options?): object;

Hides some rows of an outline, for example the finished to-dos. hide returns true for a row to hide, and the rows under it are hidden with it.

Set time when the answer depends on the time, so that the outlines update as time passes. Provide narrow whenever the indexes can tell which rows may be hidden: it returns the ids of those rows, the app checks only those, and a large outline opens quickly. Without narrow, the app checks every row of an opened outline, so the cost grows with the size of the outline.

Parameter Type Description
hide (row, context) => boolean receives a row and a context that holds the outline, the state of the library and the current time, and returns true to hide the row
options? { narrow?: (lookup, context) => Iterable<string>; time?: boolean; } time states that the answer depends on the time, and narrow returns the ids of the rows that may be hidden
options.narrow? (lookup, context) => Iterable<string> -
options.time? boolean -

object

an object with dispose(), which removes the rule

Name Type
dispose() () => void

run(query, options?): QueryHit[];

Runs a search and returns the rows that it finds, in the order of the library.

Parameter Type Description
query string the text of the search, for example #phone is:open
options? QueryOptions the options of the search

QueryHit[]

the rows that match, each as an { outline, id } pair


view<A>(ref, declaration): object;

Declares a list that the screen can open through its reference. The screen receives the list, and then each change to it as it happens. The reference is either one of the app (ctx.views.outlines.header) or one that the plugin created with declare. Only the plugin that created a view can declare it.

Type Parameter Default type Description
A undefined the type of the arguments that the view accepts
Parameter Type Description
ref ViewRef<A> the reference that identifies the view
declaration ViewDeclaration<A> says how to compute the list: a compute function and, optionally, time, byText and touches

object

an object with dispose(), which removes the view

Name Type
dispose() () => void