Bläck StudioPlugin SDK v1.0.0 · API 10
Contents

Start

Building

Beyond Bläck Studio

How it runs

Sharing

Look up

The book

this.app.project reads the open book and, with project:write, changes it. Every method returns a promise. You refer to items by id. You get ids from nodes(), manuscript() and selected().

const p = this.app.project
for (const id of await p.manuscript()) {             // the scenes, in reading order
  const text = await p.readText(id)                  // or read(id) for its HTML
  const meta = await p.meta(id)                      // synopsis, notes, keywords, fields, when, words
  if (meta && text.length > 20_000) await p.setMeta(id, { keywords: [...meta.keywords, 'long'] })
}

These methods read the book: info(), nodes(), node(id), manuscript(), selected(), read, readText, meta, labels(), statuses(), comments(id), snapshots(id), search(query, { wholeWord, caseSensitive, regex }) (which works like Find in project) and series().

With project:write, these methods change the book:

  • Text: write(id, html).
  • The navigator: create(type, title, parentId?), rename, move(id, folderId, index?), and trash, which moves an item to the trash and never deletes it for good.
  • Cards and comments: setMeta(id, patch) (synopsis, notes, keywords, fields, when), setLabel, setStatus (by id; '' for none), and resolveComment.

Some things are always safe:

  • Snapshots: before a plugin first rewrites a document, Bläck Studio keeps a snapshot of it under the plugin's name. snapshot(id, label) keeps one yourself, and needs no permission.
  • Undo: every change is saved, can be undone, and is committed like the writer's own changes.
  • Settings → Plugins lists what each plugin changed recently.
  • Ids: a method that takes an item's id throws if the book has no such item. An id therefore always refers to an item in the book.

getData() and setData(value) keep your plugin's data in the book, saved with it. Data that belongs to the plugin rather than to one book goes in loadData and saveData.

To find out when the navigator changes (an item is created, renamed, moved or trashed), listen for nodes-change: this.on('nodes-change', () => …).