@black-studio/plugin 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +188 -14
- package/index.d.ts +164 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -190,7 +190,7 @@ list are written this way too, and each shows a part of the API:
|
|
|
190
190
|
| `markdown-export` | sandboxed: a format in Compile |
|
|
191
191
|
| `name-generator` | in the window: a view, an inspector tab, a menu entry, a TipTap shortcut, changing the book |
|
|
192
192
|
| `pomodoro` | in the window: React in the status bar, a hotkey |
|
|
193
|
-
| `cast-suggest` | sandboxed: suggestions as you type, kept up to date as the
|
|
193
|
+
| `cast-suggest` | sandboxed: suggestions as you type, kept up to date as the navigator changes |
|
|
194
194
|
| `pandoc-export` | sandboxed: running a program in its temporary folder, with formats that follow its settings |
|
|
195
195
|
| `continue-writing`, `today`, `book-progress`, `writing-calendar`, `series-overview`, `recent-activity` | in the window: cards on the welcome screen's dashboard, built from the writer's library; starting a sprint |
|
|
196
196
|
| `dictation` | in the window: the microphone, speech turned into text on the device (`app.speech`), a toolbar button, a hotkey, a secret setting, a request to a service using the writer's own key |
|
|
@@ -204,18 +204,18 @@ In short:
|
|
|
204
204
|
| `addInspectorTab` | a tab in the inspector, for the items you choose (window only) |
|
|
205
205
|
| `addStatusBarItem` | an item in the status bar, drawn with React or as text you change |
|
|
206
206
|
| `addEditorMenuItem` | an entry in the text's right-click menu |
|
|
207
|
-
| `addBinderMenuItem` | an entry in the
|
|
207
|
+
| `addBinderMenuItem` | an entry in the navigator's right-click menu |
|
|
208
208
|
| `addExporter` | a format in Compile |
|
|
209
209
|
| `addHighlighter` | marks in the text, found one paragraph at a time and never saved |
|
|
210
210
|
| `registerEditorExtension` | TipTap extensions: marks, nodes, input rules, shortcuts (window only) |
|
|
211
|
-
| `addSidebarPanel` | a tab beside the
|
|
211
|
+
| `addSidebarPanel` | a tab beside the navigator (window only) |
|
|
212
212
|
| `addToolbarButton` | a button in the editor's toolbar |
|
|
213
213
|
| `addSuggester` | suggestions under the caret after a trigger: `@` for characters, `#` for tags… |
|
|
214
214
|
| `addImporter` | a kind of file for File → Import Documents |
|
|
215
215
|
| `addBookImporter` | a whole book from another app's file or folder, in File → Import and on the welcome screen (API 7) |
|
|
216
216
|
| `addSettings` | settings that Bläck Studio draws for you in Settings → Plugins |
|
|
217
217
|
| `addSettingsPanel` | settings that you draw yourself (window only) |
|
|
218
|
-
| `on` | `project-open`, `project-close`, `selection-change`, `doc-change`, `nodes-change` |
|
|
218
|
+
| `on` | `project-open`, `project-close`, `selection-change`, `doc-change`, `nodes-change`, `item-data-change` and `shared-data-change` (API 11) |
|
|
219
219
|
| `loadData`, `saveData` | your plugin's data, stored on this computer |
|
|
220
220
|
|
|
221
221
|
You read settings declared with `addSettings` from `this.settings`. Bläck
|
|
@@ -261,9 +261,26 @@ These methods read the book: `info()`, `nodes()`, `node(id)`, `manuscript()`,
|
|
|
261
261
|
`comments(id)`, `snapshots(id)`, `search(query, { wholeWord, caseSensitive,
|
|
262
262
|
regex })` (which works like Find in project) and `series()`.
|
|
263
263
|
|
|
264
|
+
`select(id)` selects an item, as clicking it in the navigator does. From a view
|
|
265
|
+
of your own, such as a map or a list of cards, use `select(id, { open: true })`:
|
|
266
|
+
the writer also goes back to the editor to see the item (API 12). Without
|
|
267
|
+
`open`, they stay in your view and only the inspector changes.
|
|
268
|
+
|
|
269
|
+
In a view of the whole book, the inspector shows only what was picked in that
|
|
270
|
+
view. When the writer comes into the view, it shows nothing until they pick
|
|
271
|
+
something there. A common pattern is to select on a click and open on a
|
|
272
|
+
double-click. Tell the writer what to pick with `addView`'s
|
|
273
|
+
`inspector: { hint }`, such as "Click a card to see it here". A view with
|
|
274
|
+
nothing to pick can have no inspector at all, with `inspector: false`. If your view has tabs or pages that show different things, call
|
|
275
|
+
`app.ui.clearPick()` when the writer moves to another one, so the inspector
|
|
276
|
+
doesn't keep showing what was picked on the last one (API 12). To mark the
|
|
277
|
+
picked item in your view, read `app.ui.picked()` and listen for the
|
|
278
|
+
`pick-change` event, rather than keeping your own copy: the pick also changes
|
|
279
|
+
when the writer goes Back to it, or when the app clears it.
|
|
280
|
+
|
|
264
281
|
With `project:write`, these methods change the book:
|
|
265
282
|
- **Text:** `write(id, html)`.
|
|
266
|
-
- **The
|
|
283
|
+
- **The navigator:** `create(type, title, parentId?)`, `rename`,
|
|
267
284
|
`move(id, folderId, index?)`, and `trash`, which moves an item to the
|
|
268
285
|
trash and never deletes it for good.
|
|
269
286
|
- **Cards and comments:** `setMeta(id, patch)` (synopsis, notes, keywords,
|
|
@@ -280,12 +297,165 @@ Some things are always safe:
|
|
|
280
297
|
- **Ids:** a method that takes an item's id throws if the book has no such
|
|
281
298
|
item. An id therefore always refers to an item in the book.
|
|
282
299
|
|
|
300
|
+
To find out when the navigator changes (an item is created, renamed, moved or
|
|
301
|
+
trashed), listen for `nodes-change`: `this.on('nodes-change', () => …)`.
|
|
302
|
+
|
|
303
|
+
## Your plugin's data
|
|
304
|
+
|
|
305
|
+
A plugin can keep data in five places. Choose by who it's for and where it should go:
|
|
306
|
+
|
|
307
|
+
| For | Use | Where it's kept | Shared on Bläck Sync |
|
|
308
|
+
| --- | --- | --- | --- |
|
|
309
|
+
| Settings of this computer | `loadData` / `saveData` | This computer | No |
|
|
310
|
+
| This computer's settings for the project | `getProjectData` / `setProjectData` | `project.json` | No |
|
|
311
|
+
| The whole project, such as a world | `getSharedData` / `setSharedData` | `project.json` | Yes |
|
|
312
|
+
| One book | `getData` / `setData` | `book.json` | Yes |
|
|
313
|
+
| One item | `getItemData` / `setItemData` | `book.json`, with the item | Yes |
|
|
314
|
+
|
|
283
315
|
`getData()` and `setData(value)` keep your plugin's data in the book, saved
|
|
284
|
-
with it. Data that belongs to the plugin rather than
|
|
285
|
-
`loadData` and `saveData`.
|
|
316
|
+
with it and shared on Bläck Sync. Data that belongs to the plugin rather than
|
|
317
|
+
to one book goes in `loadData` and `saveData`.
|
|
318
|
+
|
|
319
|
+
- **Plain JSON only:** objects, lists, strings, finite numbers, booleans and
|
|
320
|
+
`null`. A `Date`, a `Map` or a class instance throws, because it would arrive
|
|
321
|
+
on other devices changed or empty. Store a date as a string.
|
|
322
|
+
- **At most 1 MB,** as JSON. Everything in it goes to every device the book is
|
|
323
|
+
on, and to everyone it's shared with.
|
|
324
|
+
- **When the book can't be changed** on this device (a reader or commenter of
|
|
325
|
+
a shared book, or after the trial), `setData` throws an error whose `name` is
|
|
326
|
+
`"ReadOnly"`. Catch it if your plugin writes as the writer works.
|
|
327
|
+
- **From API 11, `setData` needs `project:write`.** A plugin that declares an
|
|
328
|
+
older API keeps writing without it.
|
|
329
|
+
|
|
330
|
+
Data that belongs to one item goes with that item (API 11):
|
|
331
|
+
`getItemData(id)`, `setItemData(id, value)` and `itemsWithData()`. It moves
|
|
332
|
+
with the item, goes to the Trash with it, is copied when the item is
|
|
333
|
+
duplicated, and is deleted with it, so you never key book data by item id
|
|
334
|
+
yourself. The same rules apply, at most 64 KB per item, and it needs
|
|
335
|
+
`project:write`. Listen for `item-data-change` (its argument is the item's
|
|
336
|
+
id) to follow changes made on another device or by a co-author: read the
|
|
337
|
+
item's data again rather than writing back a copy you kept.
|
|
338
|
+
|
|
339
|
+
Data for the whole project, every book of a series, goes in
|
|
340
|
+
`getSharedData()` and `setSharedData(value)` (API 11). It's kept in the
|
|
341
|
+
project's `project.json` and shared on Bläck Sync. The same rules apply, and
|
|
342
|
+
`shared-data-change` tells you when it changed elsewhere.
|
|
343
|
+
|
|
344
|
+
The first time your plugin stores anything in a project (book data, item
|
|
345
|
+
data, shared data, text fields or a kind), the project lists it in
|
|
346
|
+
`project.json` as `plugins`, with the list it was installed from and its
|
|
347
|
+
version. When the project opens on a device without your plugin, or with it
|
|
348
|
+
turned off, Bläck Studio offers to install it from that list or turn it on.
|
|
349
|
+
|
|
350
|
+
### Writing at the same time as others (API 11)
|
|
351
|
+
|
|
352
|
+
On Bläck Sync, plugin data is merged key by key, and a value is replaced
|
|
353
|
+
whole: if two people change the same description at once, one change is lost.
|
|
354
|
+
For text that people write, call `textFields` when a book opens, with the
|
|
355
|
+
paths of those texts in your data:
|
|
286
356
|
|
|
287
|
-
|
|
288
|
-
|
|
357
|
+
```js
|
|
358
|
+
this.on('project-open', () => this.app.project.textFields(['description', 'chapters/*/summary']))
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Those are then merged letter by letter, in the book's, each item's and the
|
|
362
|
+
shared data. `*` matches any key or list item.
|
|
363
|
+
|
|
364
|
+
From API 11 a write is refused if the data changed since your plugin last
|
|
365
|
+
read or wrote it, here or on another device: `setData`, `setItemData` and
|
|
366
|
+
`setSharedData` throw an error whose `name` is `"Stale"`. Read it again, apply
|
|
367
|
+
your change to what you read, and write that. Listen for `item-data-change`
|
|
368
|
+
and `shared-data-change` to take in changes as they come, so you never write
|
|
369
|
+
back an older copy:
|
|
370
|
+
|
|
371
|
+
```js
|
|
372
|
+
async rename(id, name) {
|
|
373
|
+
const entry = (await this.app.project.getItemData(id)) ?? {}
|
|
374
|
+
await this.app.project.setItemData(id, { ...entry, name })
|
|
375
|
+
}
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
## Kinds of entry (API 12)
|
|
380
|
+
|
|
381
|
+
A plugin can add kinds of entry of its own, such as factions or cultures.
|
|
382
|
+
An entry is a sheet like a character's or a place's: a title, a picture,
|
|
383
|
+
fields and a text. Define each kind when a book opens. It needs
|
|
384
|
+
`project:write`:
|
|
385
|
+
|
|
386
|
+
```js
|
|
387
|
+
this.on('project-open', async () => {
|
|
388
|
+
await this.app.project.defineKind({
|
|
389
|
+
id: 'faction',
|
|
390
|
+
name: 'Faction',
|
|
391
|
+
plural: 'Factions',
|
|
392
|
+
icon: 'banner',
|
|
393
|
+
fields: ['Leader', 'Seat', 'Goals'],
|
|
394
|
+
section: { id: 'world', name: 'World' },
|
|
395
|
+
})
|
|
396
|
+
})
|
|
397
|
+
const id = await this.app.project.create({ kind: 'faction' }, 'The Guild')
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
- **The book keeps the kind,** so its entries show with their name, icon and
|
|
401
|
+
fields even where your plugin isn't installed. Defining it again with
|
|
402
|
+
changes updates the book: a new version of your plugin can add a field.
|
|
403
|
+
A field it drops stays on the entries that have it.
|
|
404
|
+
- **Entries live in your section,** a folder at the top of the navigator
|
|
405
|
+
named by `section`, where each kind has a folder of its own named by its
|
|
406
|
+
`plural` ("Factions"). New entries go into their kind's folder. Entries
|
|
407
|
+
can't be moved out of the section, and neither the section nor a kind's
|
|
408
|
+
folder can be moved or put in the Trash. Several kinds can share a
|
|
409
|
+
section.
|
|
410
|
+
- **Ids** of kinds and sections are lower-case letters, digits and `-`.
|
|
411
|
+
`nodes()` and `node(id)` give an entry's `kind` as `"<plugin id>:<kind id>"`.
|
|
412
|
+
- **Icons** are names from the app's own set: `KindIcon` in the types lists
|
|
413
|
+
them.
|
|
414
|
+
- **A kind can be turned off** by defining it again with `hidden: true`, for
|
|
415
|
+
a writer who doesn't want it. Its entries aren't shown and none can be
|
|
416
|
+
made, but they're kept, and come back when you define it without `hidden`.
|
|
417
|
+
- **A kind can make characters or places** instead of entries, with
|
|
418
|
+
`type: 'character'` or `type: 'place'`. They're ordinary characters and
|
|
419
|
+
places, with the book's sheets for them, and can be a scene's point of
|
|
420
|
+
view or setting like any other. They're only kept in your section rather
|
|
421
|
+
than the book's own folders. `create({ kind })` makes one, and `nodes()`
|
|
422
|
+
gives it its `type` and your `kind`. If your plugin's data is removed from
|
|
423
|
+
a book, they move to the book's Characters and Places folders.
|
|
424
|
+
- **Writers can add fields** of their own for each kind in Templates. New
|
|
425
|
+
entries start with your fields and then theirs.
|
|
426
|
+
- **Where your plugin isn't there** (not installed, turned off, or unable
|
|
427
|
+
to run on a phone), its entries aren't shown. Your section becomes one
|
|
428
|
+
line that offers to get the plugin. Nothing about the entries changes:
|
|
429
|
+
they stay in the book, sync, and keep their links, and emptying the Trash
|
|
430
|
+
leaves them alone.
|
|
431
|
+
|
|
432
|
+
To show entries across a series, list them in your shared data as
|
|
433
|
+
`entries`. The series bible shows them under each kind's plural, beside the
|
|
434
|
+
characters and places, but only your plugin changes them:
|
|
435
|
+
|
|
436
|
+
```js
|
|
437
|
+
await this.app.project.setSharedData({
|
|
438
|
+
...shared,
|
|
439
|
+
entries: [{ id: 'guild', kind: 'faction', title: 'The Guild', synopsis: 'Merchants', fields: { Leader: 'Ama' } }],
|
|
440
|
+
})
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
Names in a world are often words no spelling dictionary knows. With
|
|
444
|
+
`project:write`, `addToDictionary(['Gillet', 'Ödemark'])` adds single words
|
|
445
|
+
to the book's dictionary, so they aren't marked. The writer can remove them
|
|
446
|
+
there.
|
|
447
|
+
|
|
448
|
+
To show an item's picture, such as a map, `picture(id)` gives an address
|
|
449
|
+
for an `<img>`. `storyTime(id)` gives a scene's story time as the timeline
|
|
450
|
+
reads it, as a day number, a date, or both, so a plugin can show it in a
|
|
451
|
+
calendar of its own. Your own checks go in the series' Continuity tab with
|
|
452
|
+
`addContinuityCheck({ id, name, run })`: `run` returns findings, each with a
|
|
453
|
+
`key`, a `message` and the `itemId` it's about, and the writer can open each
|
|
454
|
+
one or mark it as handled.
|
|
455
|
+
|
|
456
|
+
A book importer can bring entries too: return `kinds` (as you'd give them to
|
|
457
|
+
`defineKind`), and give an item `type: 'entry'` and the `kind` id. An
|
|
458
|
+
entry of a kind that isn't listed is read as an ordinary item.
|
|
289
459
|
|
|
290
460
|
## The editor
|
|
291
461
|
|
|
@@ -387,7 +557,7 @@ Suggesters work in sandboxed plugins too.
|
|
|
387
557
|
|
|
388
558
|
## More of the interface
|
|
389
559
|
|
|
390
|
-
- **`addSidebarPanel({ id, name, render })`:** a tab beside the
|
|
560
|
+
- **`addSidebarPanel({ id, name, render })`:** a tab beside the navigator,
|
|
391
561
|
drawn with React (window only).
|
|
392
562
|
- **`addToolbarButton({ id, title, icon, active?, run })`:** a button in the
|
|
393
563
|
editor's toolbar. In the window the icon is a component. In either mode it
|
|
@@ -406,9 +576,12 @@ Suggesters work in sandboxed plugins too.
|
|
|
406
576
|
by its path there), plus `read(path)` and `readText(path)` to read one of
|
|
407
577
|
them. You return the book:
|
|
408
578
|
- its `title`, labels, statuses and storylines;
|
|
409
|
-
- the items in each part of the
|
|
579
|
+
- the items in each part of the navigator (`manuscript`, `characters`,
|
|
410
580
|
`places`, `notes`, `research`, `trash`), each with its text as HTML,
|
|
411
|
-
synopsis, notes, keywords, label and status
|
|
581
|
+
synopsis, notes, keywords, label and status. In the HTML, a footnote is
|
|
582
|
+
`<sup data-footnote="its text"></sup>` where its number goes, and the text
|
|
583
|
+
a comment is about is `<span data-comment="id">…</span>`, with the comment
|
|
584
|
+
itself in the item's `comments` (API 12);
|
|
412
585
|
- beats on the storylines.
|
|
413
586
|
|
|
414
587
|
Items refer to each other (a scene's cast and place, a beat's scene) by ids
|
|
@@ -522,8 +695,9 @@ call for restoring. The writer restores a document from the list, and the app re
|
|
|
522
695
|
|
|
523
696
|
`this.during(event, handler)` registers a handler for a moment when the app waits for plugins, up
|
|
524
697
|
to a time limit:
|
|
525
|
-
- `'copy-due'`: the writing timer is due and something has changed,
|
|
526
|
-
(`info.reason` says which
|
|
698
|
+
- `'copy-due'`: the writing timer is due and something has changed, a new book was created, or
|
|
699
|
+
the writer is about to remove a plugin's data from the project (`info.reason` says which:
|
|
700
|
+
`'timer'`, `'new-book'` or `'before-removal'`). 30 seconds.
|
|
527
701
|
- `'project-closing'`: a book is closing, or the app is quitting (then `info.quitting` is set).
|
|
528
702
|
30 seconds.
|
|
529
703
|
- `'session-end'`: a writing session ended, after 30 minutes without writing or because the book is
|
package/index.d.ts
CHANGED
|
@@ -57,8 +57,11 @@ export interface WaitInfo {
|
|
|
57
57
|
* tablet. Finish all work in the handler; don't leave anything for later.
|
|
58
58
|
*/
|
|
59
59
|
quitting?: boolean
|
|
60
|
-
/**
|
|
61
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Only for 'copy-due': 'timer' when the writing timer runs out and something has changed, 'new-book' when a book was
|
|
62
|
+
* just made, 'before-removal' just before the writer removes a plugin's data from the book (API 12).
|
|
63
|
+
*/
|
|
64
|
+
reason?: 'timer' | 'new-book' | 'before-removal'
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
export interface Manifest {
|
|
@@ -105,7 +108,7 @@ export interface Manifest {
|
|
|
105
108
|
/**
|
|
106
109
|
* The group the plugin is listed under in Manage Plugins:
|
|
107
110
|
* - "writing": tools for the text while writing
|
|
108
|
-
* - "planning": the
|
|
111
|
+
* - "planning": the navigator, cards and views
|
|
109
112
|
* - "welcome": the welcome screen
|
|
110
113
|
* - "import-export": importing and exporting books
|
|
111
114
|
* - "other": anything else
|
|
@@ -128,12 +131,47 @@ export interface Manifest {
|
|
|
128
131
|
permissions: string[]
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
|
|
134
|
+
/** `entry` is a sheet of a kind a plugin defines (defineKind, API 12). */
|
|
135
|
+
export type NodeType = 'text' | 'folder' | 'character' | 'place' | 'note' | 'research' | 'file' | 'entry'
|
|
136
|
+
|
|
137
|
+
/** The icons a kind of entry may use, from the app's own. API 12. */
|
|
138
|
+
export type KindIcon =
|
|
139
|
+
| 'banner' | 'crown' | 'shield' | 'swords' | 'castle' | 'landmark' | 'church' | 'scroll' | 'book' | 'gem' | 'key' | 'wand' | 'flame' | 'leaf'
|
|
140
|
+
| 'mountain' | 'globe' | 'map' | 'compass' | 'paw' | 'bird' | 'fish' | 'bug' | 'users' | 'user' | 'map-pin' | 'languages' | 'feather' | 'hourglass' | 'star' | 'sparkles'
|
|
141
|
+
|
|
142
|
+
/** A kind of entry, as a plugin defines it (defineKind, API 12). */
|
|
143
|
+
export interface KindDefinition {
|
|
144
|
+
/** Lower-case letters, digits and -: "faction". Stored as "<plugin id>:faction". */
|
|
145
|
+
id: string
|
|
146
|
+
/** "Faction", in the writer's language. */
|
|
147
|
+
name: string
|
|
148
|
+
/** "Factions". */
|
|
149
|
+
plural: string
|
|
150
|
+
icon: KindIcon
|
|
151
|
+
/** The sheet's fields: "Leader", "Seat", "Goals". At most 40. */
|
|
152
|
+
fields?: string[]
|
|
153
|
+
/** The plugin's section in the navigator, which holds its entries: { id: "world", name: "World" }. */
|
|
154
|
+
section: { id: string; name: string }
|
|
155
|
+
/**
|
|
156
|
+
* Turns the kind off: its entries aren't shown and none can be made, but they're all kept, and come back when the
|
|
157
|
+
* kind is defined again without it. A section whose kinds are all off isn't shown.
|
|
158
|
+
*/
|
|
159
|
+
hidden?: boolean
|
|
160
|
+
/**
|
|
161
|
+
* What its items are. Left out, they're entries. With 'character' or 'place', they're ordinary characters or places,
|
|
162
|
+
* with the book's sheet for them and everything a character or place has (a point of view, the cast of a scene),
|
|
163
|
+
* kept in your section instead of the book's own folders. `fields` isn't used for them. It can't change once the kind
|
|
164
|
+
* is in a book. API 12.
|
|
165
|
+
*/
|
|
166
|
+
type?: 'character' | 'place'
|
|
167
|
+
}
|
|
132
168
|
|
|
133
169
|
export interface NodeInfo {
|
|
134
170
|
id: string
|
|
135
171
|
title: string
|
|
136
172
|
type: NodeType
|
|
173
|
+
/** An item's kind, "<plugin id>:<kind id>": an entry's, or a character's or place's that a plugin keeps. API 12. */
|
|
174
|
+
kind?: string
|
|
137
175
|
parentId: string | null
|
|
138
176
|
children: string[]
|
|
139
177
|
inTrash: boolean
|
|
@@ -148,6 +186,10 @@ export interface MetaInfo {
|
|
|
148
186
|
/** When the scene happens, as written on its card: "Day 3", "1888-05-01"… */
|
|
149
187
|
when: string
|
|
150
188
|
words: number
|
|
189
|
+
/** A scene's point-of-view character, its cast, and its setting, by item id ('' or [] for none). Read only. API 12. */
|
|
190
|
+
povId?: string
|
|
191
|
+
castIds?: string[]
|
|
192
|
+
placeId?: string
|
|
151
193
|
}
|
|
152
194
|
|
|
153
195
|
export interface Label {
|
|
@@ -252,14 +294,26 @@ export interface App {
|
|
|
252
294
|
/** The manuscript's documents, in reading order. */
|
|
253
295
|
manuscript(): Promise<string[]>
|
|
254
296
|
selected(): Promise<string | null>
|
|
255
|
-
|
|
297
|
+
/**
|
|
298
|
+
* Selects an item, as clicking it in the navigator does. With `open: true`, it's also shown: a writer in a view of
|
|
299
|
+
* the whole book (the plot grid, or a plugin's view) goes back to the editor, or the corkboard or outliner if that's
|
|
300
|
+
* where they were, to see it. Earlier app versions ignore `open` and only select. API 12.
|
|
301
|
+
*/
|
|
302
|
+
select(id: string, opts?: { open?: boolean }): Promise<void>
|
|
256
303
|
/** A document's text as HTML. */
|
|
257
304
|
read(id: string): Promise<string>
|
|
258
305
|
/** A document's text as plain text. */
|
|
259
306
|
readText(id: string): Promise<string>
|
|
260
307
|
write(id: string, html: string): Promise<void>
|
|
261
|
-
create(type: 'text' | 'folder' | 'character' | 'place' | 'note' | 'research', title: string, parentId?: string): Promise<string>
|
|
308
|
+
create(type: 'text' | 'folder' | 'character' | 'place' | 'note' | 'research' | { kind: string }, title: string, parentId?: string): Promise<string>
|
|
262
309
|
meta(id: string): Promise<MetaInfo | null>
|
|
310
|
+
/** The address of an item's picture (a character's, a place's or an entry's), for an <img>, or null if it has none. API 12. */
|
|
311
|
+
picture?(id: string): Promise<string | null>
|
|
312
|
+
/**
|
|
313
|
+
* A scene's story time, as the timeline reads its "when": a day number, a date, or both when the series says which
|
|
314
|
+
* date is day 1. Null if it has none the timeline understands. API 12.
|
|
315
|
+
*/
|
|
316
|
+
storyTime?(id: string): Promise<{ day: number | null; date: string | null; time: string | null } | null>
|
|
263
317
|
setMeta(id: string, patch: Partial<Pick<MetaInfo, 'synopsis' | 'notes' | 'keywords' | 'fields' | 'when'>>): Promise<void>
|
|
264
318
|
/** Moves an item to the trash, where the writer can restore it. */
|
|
265
319
|
trash(id: string): Promise<void>
|
|
@@ -294,9 +348,57 @@ export interface App {
|
|
|
294
348
|
setProjectData?(value: unknown): Promise<void>
|
|
295
349
|
/** Opens a project that this plugin created with folder.create, by its key. Returns false if it couldn't be opened. API 10: check that it exists. */
|
|
296
350
|
open?(key: string): Promise<boolean>
|
|
297
|
-
/**
|
|
351
|
+
/**
|
|
352
|
+
* This plugin's data for this book, saved in the book and shared on Bläck Sync. The value must be plain JSON
|
|
353
|
+
* (objects, lists, strings, finite numbers, booleans and null), at most 1 MB, or setData throws. When the book can't
|
|
354
|
+
* be changed on this device (a reader or commenter of a shared book, or after the trial), setData throws an error
|
|
355
|
+
* named "ReadOnly". The same JSON rules and size apply to setProjectData.
|
|
356
|
+
*/
|
|
298
357
|
getData(): Promise<unknown>
|
|
299
358
|
setData(value: unknown): Promise<void>
|
|
359
|
+
/**
|
|
360
|
+
* Adds words to the book's spelling dictionary, so they aren't marked as misspelt: single words, without spaces.
|
|
361
|
+
* Words already there are left. Returns how many were new. Needs "project:write". API 12.
|
|
362
|
+
*/
|
|
363
|
+
addToDictionary?(words: string[]): Promise<number>
|
|
364
|
+
/** This plugin's data for one item, or undefined. API 11: check that it exists. */
|
|
365
|
+
getItemData?(id: string): Promise<unknown>
|
|
366
|
+
/**
|
|
367
|
+
* Keeps this plugin's data with one item. It moves with the item, goes to the Trash with it, is copied when the
|
|
368
|
+
* item is duplicated, and is deleted with it, and it's shared on Bläck Sync. Plain JSON, at most 64 KB per item;
|
|
369
|
+
* undefined removes it. Needs "project:write"; throws "ReadOnly" when the book can't be changed. Listen for
|
|
370
|
+
* `item-data-change` to follow changes made elsewhere. API 11: check that it exists.
|
|
371
|
+
*/
|
|
372
|
+
setItemData?(id: string, value: unknown): Promise<void>
|
|
373
|
+
/** Every item that has this plugin's data, with that data, by item id. API 11: check that it exists. */
|
|
374
|
+
itemsWithData?(): Promise<Record<string, unknown>>
|
|
375
|
+
/** This plugin's data shared by the whole project (every book of a series), or undefined. API 11: check that it exists. */
|
|
376
|
+
getSharedData?(): Promise<unknown>
|
|
377
|
+
/**
|
|
378
|
+
* Keeps this plugin's data for the whole project, in its project.json, shared on Bläck Sync with every book of the
|
|
379
|
+
* series. Plain JSON, at most 1 MB; undefined removes it. Needs "project:write"; throws "ReadOnly" when the series
|
|
380
|
+
* can't be changed on this device. Listen for `shared-data-change` to follow changes made elsewhere. API 11: check
|
|
381
|
+
* that it exists.
|
|
382
|
+
*/
|
|
383
|
+
setSharedData?(value: unknown): Promise<void>
|
|
384
|
+
/**
|
|
385
|
+
* Says which paths in this plugin's data are text people write in: 'description', or 'chapters/<star>/summary',
|
|
386
|
+
* where <star> is a * that matches any key or list item. Keys are letters, digits, - and _, separated by /. On
|
|
387
|
+
* Bläck Sync these are merged letter by letter, so two people writing in the same one at once both keep what they
|
|
388
|
+
* wrote; other values are replaced whole. The paths apply to the book's, each item's and the shared data, and are
|
|
389
|
+
* kept in the book and the series, so every device merges them the same way. Call it when a book opens. Needs
|
|
390
|
+
* "project:write". API 11: check that it exists.
|
|
391
|
+
*/
|
|
392
|
+
textFields?(paths: string[]): Promise<void>
|
|
393
|
+
/**
|
|
394
|
+
* Defines a kind of entry, such as a faction, kept in the book, so its entries show with their name, icon and
|
|
395
|
+
* fields without the plugin too. Its entries live in the plugin's own section of the navigator, made the first
|
|
396
|
+
* time, which can't be moved or put in the Trash. Call it when a book opens; defining it again with changes updates
|
|
397
|
+
* the book, and a field a new version drops stays on the entries that have it. Create entries with
|
|
398
|
+
* create({ kind: 'faction' }, title). Returns "<plugin id>:<kind id>". Needs "project:write". API 12: check that
|
|
399
|
+
* it exists.
|
|
400
|
+
*/
|
|
401
|
+
defineKind?(kind: KindDefinition): Promise<string>
|
|
300
402
|
}
|
|
301
403
|
|
|
302
404
|
editor: {
|
|
@@ -322,6 +424,17 @@ export interface App {
|
|
|
322
424
|
confirm(title: string, detail?: string, confirmLabel?: string): Promise<boolean>
|
|
323
425
|
/** Shows one of this plugin's views. Window only. */
|
|
324
426
|
openView(viewId: string): void
|
|
427
|
+
/**
|
|
428
|
+
* Clears what's picked in this plugin's view, so the side panel shows its empty state. Call it when the view shows
|
|
429
|
+
* something else, such as another tab or page. Has an effect only while one of your views is showing. Window only. API 12.
|
|
430
|
+
*/
|
|
431
|
+
clearPick?(): void
|
|
432
|
+
/**
|
|
433
|
+
* What's picked in this plugin's view, which the inspector shows: an item's id, or null. Null while none of your
|
|
434
|
+
* views is showing. Listen for `pick-change` to hear when it changes, such as when the writer goes Back to a pick.
|
|
435
|
+
* Window only. API 12.
|
|
436
|
+
*/
|
|
437
|
+
picked?(): string | null
|
|
325
438
|
/** Shows this plugin's settings. */
|
|
326
439
|
openSettings(): void
|
|
327
440
|
/** Opens a dialog that the plugin draws itself. Returns a function that closes it. Window only. */
|
|
@@ -631,7 +744,13 @@ export interface SettingField {
|
|
|
631
744
|
folded?: string
|
|
632
745
|
}
|
|
633
746
|
|
|
634
|
-
|
|
747
|
+
/**
|
|
748
|
+
* `item-data-change` (API 11): this plugin's data for an item changed, here or on another device or by a co-author.
|
|
749
|
+
* The argument is the item's id. `shared-data-change` (API 11): this plugin's shared data changed, the same way; its
|
|
750
|
+
* argument is null. Only the plugin whose data it is hears either. `pick-change` (API 12): what's picked in a
|
|
751
|
+
* whole-book view changed; the argument is its id, or null when nothing is.
|
|
752
|
+
*/
|
|
753
|
+
export type PluginEvent = 'project-open' | 'project-close' | 'selection-change' | 'doc-change' | 'nodes-change' | 'item-data-change' | 'shared-data-change' | 'pick-change'
|
|
635
754
|
|
|
636
755
|
/** A suggestion offered as the writer types after a trigger. */
|
|
637
756
|
export interface Suggestion {
|
|
@@ -676,13 +795,21 @@ export interface ImportSource {
|
|
|
676
795
|
export interface ImportedItem {
|
|
677
796
|
id?: string
|
|
678
797
|
/**
|
|
679
|
-
* The item's type. Without one, an item with children is a folder. Any other item takes the type of the
|
|
798
|
+
* The item's type. Without one, an item with children is a folder. Any other item takes the type of the navigator
|
|
680
799
|
* section it's in: a scene in the manuscript, a sheet in characters, a note in Notes, a document in Research.
|
|
681
800
|
*/
|
|
682
801
|
type?: NodeType
|
|
802
|
+
/** An entry's kind: the `id` of one of the book's `kinds` (API 12). */
|
|
803
|
+
kind?: string
|
|
683
804
|
title: string
|
|
684
|
-
/**
|
|
805
|
+
/**
|
|
806
|
+
* The text as HTML: paragraphs, headings, emphasis, lists, quotes, and <hr> for a scene break. A footnote is
|
|
807
|
+
* `<sup data-footnote="its text"></sup>` where its number goes, and the text a comment is about is
|
|
808
|
+
* `<span data-comment="id">…</span>`, with the comment in `comments` (API 12).
|
|
809
|
+
*/
|
|
685
810
|
html?: string
|
|
811
|
+
/** Comments on the text, each anchored by its `id` in `html`. The writer sees them in the margin (API 12). */
|
|
812
|
+
comments?: { id: string; text: string; by?: string }[]
|
|
686
813
|
synopsis?: string
|
|
687
814
|
notes?: string
|
|
688
815
|
keywords?: string[]
|
|
@@ -734,6 +861,8 @@ export interface ImportedBook {
|
|
|
734
861
|
trash?: ImportedItem[]
|
|
735
862
|
/** Beats (cards on the plot grid). Each names its storyline by id, and its scene by id if it belongs to one. */
|
|
736
863
|
beats?: { storyline: string; scene?: string; title: string; description?: string }[]
|
|
864
|
+
/** Kinds of entry, as you'd give them to defineKind (API 12). Items use them with `type: 'entry'` and `kind`. */
|
|
865
|
+
kinds?: KindDefinition[]
|
|
737
866
|
}
|
|
738
867
|
|
|
739
868
|
export declare class Plugin {
|
|
@@ -765,12 +894,24 @@ export declare class Plugin {
|
|
|
765
894
|
run: () => void | Promise<void>
|
|
766
895
|
}): () => void
|
|
767
896
|
/** Adds a view beside the corkboard and outliner. Window only. */
|
|
768
|
-
addView(view: {
|
|
897
|
+
addView(view: {
|
|
898
|
+
id: string
|
|
899
|
+
name: string
|
|
900
|
+
icon?: ComponentType<{ size?: number }>
|
|
901
|
+
render: () => ReactNode
|
|
902
|
+
/**
|
|
903
|
+
* The inspector beside the view. It shows what the writer picks in the view with `select`, and stays closed until
|
|
904
|
+
* something is picked. `hint` is what the status bar says meanwhile, such as "Click a card to show it beside the
|
|
905
|
+
* view". `false` is for a view with nothing to pick, which has no inspector. API 12.
|
|
906
|
+
*/
|
|
907
|
+
inspector?: false | { hint: string }
|
|
908
|
+
}): () => void
|
|
769
909
|
/** Adds a tab to the inspector, for items where `when` returns true. Window only. */
|
|
770
910
|
addInspectorTab(tab: {
|
|
771
911
|
id: string
|
|
772
912
|
name: string | ((nodeId: string) => string)
|
|
773
|
-
|
|
913
|
+
/** Whether the tab is for this item. `kind` is an entry's kind, "<plugin id>:<kind id>" (API 12). */
|
|
914
|
+
when?: (nodeId: string, node: { type: NodeType; title: string; kind?: string }) => boolean
|
|
774
915
|
render: (nodeId: string) => ReactNode
|
|
775
916
|
}): () => void
|
|
776
917
|
/** Adds a status bar item. Either draw it with `render` (window only), or give it `text` and change that with setText, which also works in a sandboxed plugin. */
|
|
@@ -786,7 +927,7 @@ export declare class Plugin {
|
|
|
786
927
|
when?: (ctx: EditorContext) => boolean
|
|
787
928
|
run: (ctx: EditorContext) => void | Promise<void>
|
|
788
929
|
}): () => void
|
|
789
|
-
/** Adds an item to the
|
|
930
|
+
/** Adds an item to the navigator's right-click menu. */
|
|
790
931
|
addBinderMenuItem(item: {
|
|
791
932
|
id: string
|
|
792
933
|
label: string | ((nodeId: string) => string)
|
|
@@ -823,6 +964,16 @@ export declare class Plugin {
|
|
|
823
964
|
active?: () => boolean
|
|
824
965
|
run: () => void | Promise<void>
|
|
825
966
|
}): () => void
|
|
967
|
+
/**
|
|
968
|
+
* Adds a check to the series' Continuity tab, run on the open book with the app's own whenever the tab shows or the
|
|
969
|
+
* book changes, for at most 10 seconds. Each finding's `key` says which finding it is, so one the writer marks as
|
|
970
|
+
* handled stays handled until its key changes; `itemId` is what "Open" goes to. At most 200 findings. API 12.
|
|
971
|
+
*/
|
|
972
|
+
addContinuityCheck?(check: {
|
|
973
|
+
id: string
|
|
974
|
+
name: string
|
|
975
|
+
run: () => { key: string; message: string; itemId?: string }[] | Promise<{ key: string; message: string; itemId?: string }[]>
|
|
976
|
+
}): () => void
|
|
826
977
|
/** Shows suggestions under the caret as the writer types after `trigger` ("@", "#"…) at the start of a word. `trigger` must be a single character. */
|
|
827
978
|
addSuggester(suggester: {
|
|
828
979
|
id: string
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@black-studio/plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Write plugins for Bläck Studio: the plugin API's types, and a build that turns TypeScript or JSX source into a plugin folder.",
|
|
5
5
|
"keywords": ["black-studio", "plugin", "writing"],
|
|
6
6
|
"homepage": "https://blackstudio.app/developers/",
|