@black-studio/plugin 1.0.0 → 1.1.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 +160 -13
- package/index.d.ts +120 -10
- 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
|
|
@@ -263,7 +263,7 @@ regex })` (which works like Find in project) and `series()`.
|
|
|
263
263
|
|
|
264
264
|
With `project:write`, these methods change the book:
|
|
265
265
|
- **Text:** `write(id, html)`.
|
|
266
|
-
- **The
|
|
266
|
+
- **The navigator:** `create(type, title, parentId?)`, `rename`,
|
|
267
267
|
`move(id, folderId, index?)`, and `trash`, which moves an item to the
|
|
268
268
|
trash and never deletes it for good.
|
|
269
269
|
- **Cards and comments:** `setMeta(id, patch)` (synopsis, notes, keywords,
|
|
@@ -280,12 +280,158 @@ Some things are always safe:
|
|
|
280
280
|
- **Ids:** a method that takes an item's id throws if the book has no such
|
|
281
281
|
item. An id therefore always refers to an item in the book.
|
|
282
282
|
|
|
283
|
+
To find out when the navigator changes (an item is created, renamed, moved or
|
|
284
|
+
trashed), listen for `nodes-change`: `this.on('nodes-change', () => …)`.
|
|
285
|
+
|
|
286
|
+
## Your plugin's data
|
|
287
|
+
|
|
288
|
+
A plugin can keep data in five places. Choose by who it's for and where it should go:
|
|
289
|
+
|
|
290
|
+
| For | Use | Where it's kept | Shared on Bläck Sync |
|
|
291
|
+
| --- | --- | --- | --- |
|
|
292
|
+
| Settings of this computer | `loadData` / `saveData` | This computer | No |
|
|
293
|
+
| This computer's settings for the project | `getProjectData` / `setProjectData` | `project.json` | No |
|
|
294
|
+
| The whole project, such as a world | `getSharedData` / `setSharedData` | `project.json` | Yes |
|
|
295
|
+
| One book | `getData` / `setData` | `book.json` | Yes |
|
|
296
|
+
| One item | `getItemData` / `setItemData` | `book.json`, with the item | Yes |
|
|
297
|
+
|
|
283
298
|
`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`.
|
|
299
|
+
with it and shared on Bläck Sync. Data that belongs to the plugin rather than
|
|
300
|
+
to one book goes in `loadData` and `saveData`.
|
|
301
|
+
|
|
302
|
+
- **Plain JSON only:** objects, lists, strings, finite numbers, booleans and
|
|
303
|
+
`null`. A `Date`, a `Map` or a class instance throws, because it would arrive
|
|
304
|
+
on other devices changed or empty. Store a date as a string.
|
|
305
|
+
- **At most 1 MB,** as JSON. Everything in it goes to every device the book is
|
|
306
|
+
on, and to everyone it's shared with.
|
|
307
|
+
- **When the book can't be changed** on this device (a reader or commenter of
|
|
308
|
+
a shared book, or after the trial), `setData` throws an error whose `name` is
|
|
309
|
+
`"ReadOnly"`. Catch it if your plugin writes as the writer works.
|
|
310
|
+
- **From API 11, `setData` needs `project:write`.** A plugin that declares an
|
|
311
|
+
older API keeps writing without it.
|
|
312
|
+
|
|
313
|
+
Data that belongs to one item goes with that item (API 11):
|
|
314
|
+
`getItemData(id)`, `setItemData(id, value)` and `itemsWithData()`. It moves
|
|
315
|
+
with the item, goes to the Trash with it, is copied when the item is
|
|
316
|
+
duplicated, and is deleted with it, so you never key book data by item id
|
|
317
|
+
yourself. The same rules apply, at most 64 KB per item, and it needs
|
|
318
|
+
`project:write`. Listen for `item-data-change` (its argument is the item's
|
|
319
|
+
id) to follow changes made on another device or by a co-author: read the
|
|
320
|
+
item's data again rather than writing back a copy you kept.
|
|
321
|
+
|
|
322
|
+
Data for the whole project, every book of a series, goes in
|
|
323
|
+
`getSharedData()` and `setSharedData(value)` (API 11). It's kept in the
|
|
324
|
+
project's `project.json` and shared on Bläck Sync. The same rules apply, and
|
|
325
|
+
`shared-data-change` tells you when it changed elsewhere.
|
|
326
|
+
|
|
327
|
+
The first time your plugin stores anything in a project (book data, item
|
|
328
|
+
data, shared data, text fields or a kind), the project lists it in
|
|
329
|
+
`project.json` as `plugins`, with the list it was installed from and its
|
|
330
|
+
version. When the project opens on a device without your plugin, or with it
|
|
331
|
+
turned off, Bläck Studio offers to install it from that list or turn it on.
|
|
332
|
+
|
|
333
|
+
### Writing at the same time as others (API 11)
|
|
334
|
+
|
|
335
|
+
On Bläck Sync, plugin data is merged key by key, and a value is replaced
|
|
336
|
+
whole: if two people change the same description at once, one change is lost.
|
|
337
|
+
For text that people write, call `textFields` when a book opens, with the
|
|
338
|
+
paths of those texts in your data:
|
|
286
339
|
|
|
287
|
-
|
|
288
|
-
|
|
340
|
+
```js
|
|
341
|
+
this.on('project-open', () => this.app.project.textFields(['description', 'chapters/*/summary']))
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Those are then merged letter by letter, in the book's, each item's and the
|
|
345
|
+
shared data. `*` matches any key or list item.
|
|
346
|
+
|
|
347
|
+
From API 11 a write is refused if the data changed since your plugin last
|
|
348
|
+
read or wrote it, here or on another device: `setData`, `setItemData` and
|
|
349
|
+
`setSharedData` throw an error whose `name` is `"Stale"`. Read it again, apply
|
|
350
|
+
your change to what you read, and write that. Listen for `item-data-change`
|
|
351
|
+
and `shared-data-change` to take in changes as they come, so you never write
|
|
352
|
+
back an older copy:
|
|
353
|
+
|
|
354
|
+
```js
|
|
355
|
+
async rename(id, name) {
|
|
356
|
+
const entry = (await this.app.project.getItemData(id)) ?? {}
|
|
357
|
+
await this.app.project.setItemData(id, { ...entry, name })
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
## Kinds of entry (API 12)
|
|
363
|
+
|
|
364
|
+
A plugin can add kinds of entry of its own, such as factions or cultures.
|
|
365
|
+
An entry is a sheet like a character's or a place's: a title, a picture,
|
|
366
|
+
fields and a text. Define each kind when a book opens. It needs
|
|
367
|
+
`project:write`:
|
|
368
|
+
|
|
369
|
+
```js
|
|
370
|
+
this.on('project-open', async () => {
|
|
371
|
+
await this.app.project.defineKind({
|
|
372
|
+
id: 'faction',
|
|
373
|
+
name: 'Faction',
|
|
374
|
+
plural: 'Factions',
|
|
375
|
+
icon: 'banner',
|
|
376
|
+
fields: ['Leader', 'Seat', 'Goals'],
|
|
377
|
+
section: { id: 'world', name: 'World' },
|
|
378
|
+
})
|
|
379
|
+
})
|
|
380
|
+
const id = await this.app.project.create({ kind: 'faction' }, 'The Guild')
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
- **The book keeps the kind,** so its entries show with their name, icon and
|
|
384
|
+
fields even where your plugin isn't installed. Defining it again with
|
|
385
|
+
changes updates the book: a new version of your plugin can add a field.
|
|
386
|
+
A field it drops stays on the entries that have it.
|
|
387
|
+
- **Entries live in your section,** a folder at the top of the navigator
|
|
388
|
+
named by `section`, where each kind has a folder of its own named by its
|
|
389
|
+
`plural` ("Factions"). New entries go into their kind's folder. Entries
|
|
390
|
+
can't be moved out of the section, and neither the section nor a kind's
|
|
391
|
+
folder can be moved or put in the Trash. Several kinds can share a
|
|
392
|
+
section.
|
|
393
|
+
- **Ids** of kinds and sections are lower-case letters, digits and `-`.
|
|
394
|
+
`nodes()` and `node(id)` give an entry's `kind` as `"<plugin id>:<kind id>"`.
|
|
395
|
+
- **Icons** are names from the app's own set: `KindIcon` in the types lists
|
|
396
|
+
them.
|
|
397
|
+
- **A kind can be turned off** by defining it again with `hidden: true`, for
|
|
398
|
+
a writer who doesn't want it. Its entries aren't shown and none can be
|
|
399
|
+
made, but they're kept, and come back when you define it without `hidden`.
|
|
400
|
+
- **Writers can add fields** of their own for each kind in Templates. New
|
|
401
|
+
entries start with your fields and then theirs.
|
|
402
|
+
- **Where your plugin isn't there** (not installed, turned off, or unable
|
|
403
|
+
to run on a phone), its entries aren't shown. Your section becomes one
|
|
404
|
+
line that offers to get the plugin. Nothing about the entries changes:
|
|
405
|
+
they stay in the book, sync, and keep their links, and emptying the Trash
|
|
406
|
+
leaves them alone.
|
|
407
|
+
|
|
408
|
+
To show entries across a series, list them in your shared data as
|
|
409
|
+
`entries`. The series bible shows them under each kind's plural, beside the
|
|
410
|
+
characters and places, but only your plugin changes them:
|
|
411
|
+
|
|
412
|
+
```js
|
|
413
|
+
await this.app.project.setSharedData({
|
|
414
|
+
...shared,
|
|
415
|
+
entries: [{ id: 'guild', kind: 'faction', title: 'The Guild', synopsis: 'Merchants', fields: { Leader: 'Ama' } }],
|
|
416
|
+
})
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
Names in a world are often words no spelling dictionary knows. With
|
|
420
|
+
`project:write`, `addToDictionary(['Gillet', 'Ödemark'])` adds single words
|
|
421
|
+
to the book's dictionary, so they aren't marked. The writer can remove them
|
|
422
|
+
there.
|
|
423
|
+
|
|
424
|
+
To show an item's picture, such as a map, `picture(id)` gives an address
|
|
425
|
+
for an `<img>`. `storyTime(id)` gives a scene's story time as the timeline
|
|
426
|
+
reads it, as a day number, a date, or both, so a plugin can show it in a
|
|
427
|
+
calendar of its own. Your own checks go in the series' Continuity tab with
|
|
428
|
+
`addContinuityCheck({ id, name, run })`: `run` returns findings, each with a
|
|
429
|
+
`key`, a `message` and the `itemId` it's about, and the writer can open each
|
|
430
|
+
one or mark it as handled.
|
|
431
|
+
|
|
432
|
+
A book importer can bring entries too: return `kinds` (as you'd give them to
|
|
433
|
+
`defineKind`), and give an item `type: 'entry'` and the `kind` id. An
|
|
434
|
+
entry of a kind that isn't listed is read as an ordinary item.
|
|
289
435
|
|
|
290
436
|
## The editor
|
|
291
437
|
|
|
@@ -387,7 +533,7 @@ Suggesters work in sandboxed plugins too.
|
|
|
387
533
|
|
|
388
534
|
## More of the interface
|
|
389
535
|
|
|
390
|
-
- **`addSidebarPanel({ id, name, render })`:** a tab beside the
|
|
536
|
+
- **`addSidebarPanel({ id, name, render })`:** a tab beside the navigator,
|
|
391
537
|
drawn with React (window only).
|
|
392
538
|
- **`addToolbarButton({ id, title, icon, active?, run })`:** a button in the
|
|
393
539
|
editor's toolbar. In the window the icon is a component. In either mode it
|
|
@@ -406,7 +552,7 @@ Suggesters work in sandboxed plugins too.
|
|
|
406
552
|
by its path there), plus `read(path)` and `readText(path)` to read one of
|
|
407
553
|
them. You return the book:
|
|
408
554
|
- its `title`, labels, statuses and storylines;
|
|
409
|
-
- the items in each part of the
|
|
555
|
+
- the items in each part of the navigator (`manuscript`, `characters`,
|
|
410
556
|
`places`, `notes`, `research`, `trash`), each with its text as HTML,
|
|
411
557
|
synopsis, notes, keywords, label and status;
|
|
412
558
|
- beats on the storylines.
|
|
@@ -522,8 +668,9 @@ call for restoring. The writer restores a document from the list, and the app re
|
|
|
522
668
|
|
|
523
669
|
`this.during(event, handler)` registers a handler for a moment when the app waits for plugins, up
|
|
524
670
|
to a time limit:
|
|
525
|
-
- `'copy-due'`: the writing timer is due and something has changed,
|
|
526
|
-
(`info.reason` says which
|
|
671
|
+
- `'copy-due'`: the writing timer is due and something has changed, a new book was created, or
|
|
672
|
+
the writer is about to remove a plugin's data from the project (`info.reason` says which:
|
|
673
|
+
`'timer'`, `'new-book'` or `'before-removal'`). 30 seconds.
|
|
527
674
|
- `'project-closing'`: a book is closing, or the app is quitting (then `info.quitting` is set).
|
|
528
675
|
30 seconds.
|
|
529
676
|
- `'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,40 @@ 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' | '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
|
+
}
|
|
132
161
|
|
|
133
162
|
export interface NodeInfo {
|
|
134
163
|
id: string
|
|
135
164
|
title: string
|
|
136
165
|
type: NodeType
|
|
166
|
+
/** An entry's kind, "<plugin id>:<kind id>". API 12. */
|
|
167
|
+
kind?: string
|
|
137
168
|
parentId: string | null
|
|
138
169
|
children: string[]
|
|
139
170
|
inTrash: boolean
|
|
@@ -148,6 +179,10 @@ export interface MetaInfo {
|
|
|
148
179
|
/** When the scene happens, as written on its card: "Day 3", "1888-05-01"… */
|
|
149
180
|
when: string
|
|
150
181
|
words: number
|
|
182
|
+
/** A scene's point-of-view character, its cast, and its setting, by item id ('' or [] for none). Read only. API 12. */
|
|
183
|
+
povId?: string
|
|
184
|
+
castIds?: string[]
|
|
185
|
+
placeId?: string
|
|
151
186
|
}
|
|
152
187
|
|
|
153
188
|
export interface Label {
|
|
@@ -258,8 +293,15 @@ export interface App {
|
|
|
258
293
|
/** A document's text as plain text. */
|
|
259
294
|
readText(id: string): Promise<string>
|
|
260
295
|
write(id: string, html: string): Promise<void>
|
|
261
|
-
create(type: 'text' | 'folder' | 'character' | 'place' | 'note' | 'research', title: string, parentId?: string): Promise<string>
|
|
296
|
+
create(type: 'text' | 'folder' | 'character' | 'place' | 'note' | 'research' | { kind: string }, title: string, parentId?: string): Promise<string>
|
|
262
297
|
meta(id: string): Promise<MetaInfo | null>
|
|
298
|
+
/** 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. */
|
|
299
|
+
picture?(id: string): Promise<string | null>
|
|
300
|
+
/**
|
|
301
|
+
* A scene's story time, as the timeline reads its "when": a day number, a date, or both when the series says which
|
|
302
|
+
* date is day 1. Null if it has none the timeline understands. API 12.
|
|
303
|
+
*/
|
|
304
|
+
storyTime?(id: string): Promise<{ day: number | null; date: string | null; time: string | null } | null>
|
|
263
305
|
setMeta(id: string, patch: Partial<Pick<MetaInfo, 'synopsis' | 'notes' | 'keywords' | 'fields' | 'when'>>): Promise<void>
|
|
264
306
|
/** Moves an item to the trash, where the writer can restore it. */
|
|
265
307
|
trash(id: string): Promise<void>
|
|
@@ -294,9 +336,57 @@ export interface App {
|
|
|
294
336
|
setProjectData?(value: unknown): Promise<void>
|
|
295
337
|
/** 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
338
|
open?(key: string): Promise<boolean>
|
|
297
|
-
/**
|
|
339
|
+
/**
|
|
340
|
+
* This plugin's data for this book, saved in the book and shared on Bläck Sync. The value must be plain JSON
|
|
341
|
+
* (objects, lists, strings, finite numbers, booleans and null), at most 1 MB, or setData throws. When the book can't
|
|
342
|
+
* be changed on this device (a reader or commenter of a shared book, or after the trial), setData throws an error
|
|
343
|
+
* named "ReadOnly". The same JSON rules and size apply to setProjectData.
|
|
344
|
+
*/
|
|
298
345
|
getData(): Promise<unknown>
|
|
299
346
|
setData(value: unknown): Promise<void>
|
|
347
|
+
/**
|
|
348
|
+
* Adds words to the book's spelling dictionary, so they aren't marked as misspelt: single words, without spaces.
|
|
349
|
+
* Words already there are left. Returns how many were new. Needs "project:write". API 12.
|
|
350
|
+
*/
|
|
351
|
+
addToDictionary?(words: string[]): Promise<number>
|
|
352
|
+
/** This plugin's data for one item, or undefined. API 11: check that it exists. */
|
|
353
|
+
getItemData?(id: string): Promise<unknown>
|
|
354
|
+
/**
|
|
355
|
+
* Keeps this plugin's data with one item. It moves with the item, goes to the Trash with it, is copied when the
|
|
356
|
+
* item is duplicated, and is deleted with it, and it's shared on Bläck Sync. Plain JSON, at most 64 KB per item;
|
|
357
|
+
* undefined removes it. Needs "project:write"; throws "ReadOnly" when the book can't be changed. Listen for
|
|
358
|
+
* `item-data-change` to follow changes made elsewhere. API 11: check that it exists.
|
|
359
|
+
*/
|
|
360
|
+
setItemData?(id: string, value: unknown): Promise<void>
|
|
361
|
+
/** Every item that has this plugin's data, with that data, by item id. API 11: check that it exists. */
|
|
362
|
+
itemsWithData?(): Promise<Record<string, unknown>>
|
|
363
|
+
/** This plugin's data shared by the whole project (every book of a series), or undefined. API 11: check that it exists. */
|
|
364
|
+
getSharedData?(): Promise<unknown>
|
|
365
|
+
/**
|
|
366
|
+
* Keeps this plugin's data for the whole project, in its project.json, shared on Bläck Sync with every book of the
|
|
367
|
+
* series. Plain JSON, at most 1 MB; undefined removes it. Needs "project:write"; throws "ReadOnly" when the series
|
|
368
|
+
* can't be changed on this device. Listen for `shared-data-change` to follow changes made elsewhere. API 11: check
|
|
369
|
+
* that it exists.
|
|
370
|
+
*/
|
|
371
|
+
setSharedData?(value: unknown): Promise<void>
|
|
372
|
+
/**
|
|
373
|
+
* Says which paths in this plugin's data are text people write in: 'description', or 'chapters/<star>/summary',
|
|
374
|
+
* where <star> is a * that matches any key or list item. Keys are letters, digits, - and _, separated by /. On
|
|
375
|
+
* Bläck Sync these are merged letter by letter, so two people writing in the same one at once both keep what they
|
|
376
|
+
* wrote; other values are replaced whole. The paths apply to the book's, each item's and the shared data, and are
|
|
377
|
+
* kept in the book and the series, so every device merges them the same way. Call it when a book opens. Needs
|
|
378
|
+
* "project:write". API 11: check that it exists.
|
|
379
|
+
*/
|
|
380
|
+
textFields?(paths: string[]): Promise<void>
|
|
381
|
+
/**
|
|
382
|
+
* Defines a kind of entry, such as a faction, kept in the book, so its entries show with their name, icon and
|
|
383
|
+
* fields without the plugin too. Its entries live in the plugin's own section of the navigator, made the first
|
|
384
|
+
* time, which can't be moved or put in the Trash. Call it when a book opens; defining it again with changes updates
|
|
385
|
+
* the book, and a field a new version drops stays on the entries that have it. Create entries with
|
|
386
|
+
* create({ kind: 'faction' }, title). Returns "<plugin id>:<kind id>". Needs "project:write". API 12: check that
|
|
387
|
+
* it exists.
|
|
388
|
+
*/
|
|
389
|
+
defineKind?(kind: KindDefinition): Promise<string>
|
|
300
390
|
}
|
|
301
391
|
|
|
302
392
|
editor: {
|
|
@@ -631,7 +721,12 @@ export interface SettingField {
|
|
|
631
721
|
folded?: string
|
|
632
722
|
}
|
|
633
723
|
|
|
634
|
-
|
|
724
|
+
/**
|
|
725
|
+
* `item-data-change` (API 11): this plugin's data for an item changed, here or on another device or by a co-author.
|
|
726
|
+
* The argument is the item's id. `shared-data-change` (API 11): this plugin's shared data changed, the same way; its
|
|
727
|
+
* argument is null. Only the plugin whose data it is hears either.
|
|
728
|
+
*/
|
|
729
|
+
export type PluginEvent = 'project-open' | 'project-close' | 'selection-change' | 'doc-change' | 'nodes-change' | 'item-data-change' | 'shared-data-change'
|
|
635
730
|
|
|
636
731
|
/** A suggestion offered as the writer types after a trigger. */
|
|
637
732
|
export interface Suggestion {
|
|
@@ -676,10 +771,12 @@ export interface ImportSource {
|
|
|
676
771
|
export interface ImportedItem {
|
|
677
772
|
id?: string
|
|
678
773
|
/**
|
|
679
|
-
* The item's type. Without one, an item with children is a folder. Any other item takes the type of the
|
|
774
|
+
* The item's type. Without one, an item with children is a folder. Any other item takes the type of the navigator
|
|
680
775
|
* section it's in: a scene in the manuscript, a sheet in characters, a note in Notes, a document in Research.
|
|
681
776
|
*/
|
|
682
777
|
type?: NodeType
|
|
778
|
+
/** An entry's kind: the `id` of one of the book's `kinds` (API 12). */
|
|
779
|
+
kind?: string
|
|
683
780
|
title: string
|
|
684
781
|
/** The text as HTML: paragraphs, headings, emphasis, lists, quotes, and <hr> for a scene break. */
|
|
685
782
|
html?: string
|
|
@@ -734,6 +831,8 @@ export interface ImportedBook {
|
|
|
734
831
|
trash?: ImportedItem[]
|
|
735
832
|
/** Beats (cards on the plot grid). Each names its storyline by id, and its scene by id if it belongs to one. */
|
|
736
833
|
beats?: { storyline: string; scene?: string; title: string; description?: string }[]
|
|
834
|
+
/** Kinds of entry, as you'd give them to defineKind (API 12). Items use them with `type: 'entry'` and `kind`. */
|
|
835
|
+
kinds?: KindDefinition[]
|
|
737
836
|
}
|
|
738
837
|
|
|
739
838
|
export declare class Plugin {
|
|
@@ -770,7 +869,8 @@ export declare class Plugin {
|
|
|
770
869
|
addInspectorTab(tab: {
|
|
771
870
|
id: string
|
|
772
871
|
name: string | ((nodeId: string) => string)
|
|
773
|
-
|
|
872
|
+
/** Whether the tab is for this item. `kind` is an entry's kind, "<plugin id>:<kind id>" (API 12). */
|
|
873
|
+
when?: (nodeId: string, node: { type: NodeType; title: string; kind?: string }) => boolean
|
|
774
874
|
render: (nodeId: string) => ReactNode
|
|
775
875
|
}): () => void
|
|
776
876
|
/** 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 +886,7 @@ export declare class Plugin {
|
|
|
786
886
|
when?: (ctx: EditorContext) => boolean
|
|
787
887
|
run: (ctx: EditorContext) => void | Promise<void>
|
|
788
888
|
}): () => void
|
|
789
|
-
/** Adds an item to the
|
|
889
|
+
/** Adds an item to the navigator's right-click menu. */
|
|
790
890
|
addBinderMenuItem(item: {
|
|
791
891
|
id: string
|
|
792
892
|
label: string | ((nodeId: string) => string)
|
|
@@ -823,6 +923,16 @@ export declare class Plugin {
|
|
|
823
923
|
active?: () => boolean
|
|
824
924
|
run: () => void | Promise<void>
|
|
825
925
|
}): () => void
|
|
926
|
+
/**
|
|
927
|
+
* Adds a check to the series' Continuity tab, run on the open book with the app's own whenever the tab shows or the
|
|
928
|
+
* book changes, for at most 10 seconds. Each finding's `key` says which finding it is, so one the writer marks as
|
|
929
|
+
* handled stays handled until its key changes; `itemId` is what "Open" goes to. At most 200 findings. API 12.
|
|
930
|
+
*/
|
|
931
|
+
addContinuityCheck?(check: {
|
|
932
|
+
id: string
|
|
933
|
+
name: string
|
|
934
|
+
run: () => { key: string; message: string; itemId?: string }[] | Promise<{ key: string; message: string; itemId?: string }[]>
|
|
935
|
+
}): () => void
|
|
826
936
|
/** Shows suggestions under the caret as the writer types after `trigger` ("@", "#"…) at the start of a word. `trigger` must be a single character. */
|
|
827
937
|
addSuggester(suggester: {
|
|
828
938
|
id: string
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@black-studio/plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.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/",
|