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

Start

Building

Beyond Bläck Studio

How it runs

Sharing

Look up

Dialogs

this.app.ui asks the writer questions in dialogs that Bläck Studio draws:

const name = await this.app.ui.prompt({ title: 'Name the scene', label: 'Title', value: 'Untitled' })
if (name === null) return                                  // cancelled

const kind = await this.app.ui.choose({
  title: 'Export as',
  options: [
    { value: 'odt', label: 'OpenDocument', detail: '.odt' },
    { value: 'tex', label: 'LaTeX', detail: '.tex' },
  ],
})

if (await this.app.ui.confirm('Replace every em dash?', 'In every scene.', 'Replace')) { … }
  • prompt and choose resolve with the writer's answer, or with null if the writer cancels.
  • confirm asks a yes or no question and resolves with true or false. The dialog says that your plugin is asking.
  • notify(message, action?) shows a notice, with a button if you pass an action.

All of these work in sandboxed plugins too, except that a sandboxed plugin's notice can't have a button.

openModal({ title, render, wide?, onClose? }) shows a dialog that you draw yourself (window only). Bläck Studio passes render a close function, and openModal returns one too. onClose tells you why the dialog went away: 'closed' if the writer closed it (Escape, ✕) or you called close, or 'replaced' if another dialog opened over it.

const close = this.app.ui.openModal({
  title: 'Word of the day',
  render: (close) => (
    <div>
      <p className="insp-hint">{word}</p>
      <button className="btn primary" onClick={close}>Thanks</button>
    </div>
  ),
})