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')) { … }promptandchooseresolve with the writer's answer, or withnullif the writer cancels.confirmasks a yes or no question and resolves withtrueorfalse. 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>
),
})