@black-studio/plugin 0.0.0-stage → 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 +954 -2
- package/build.mjs +118 -0
- package/cli.mjs +28 -0
- package/index.d.ts +1021 -0
- package/package.json +18 -4
package/index.d.ts
ADDED
|
@@ -0,0 +1,1021 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @black-studio/plugin: the API that Bläck Studio plugins are written against.
|
|
3
|
+
*
|
|
4
|
+
* import { Plugin } from '@black-studio/plugin'
|
|
5
|
+
*
|
|
6
|
+
* export default class WordOfTheDay extends Plugin {
|
|
7
|
+
* onload() {
|
|
8
|
+
* this.addCommand({ id: 'hello', name: 'Say hello', run: () => this.app.ui.notify('Hello') })
|
|
9
|
+
* }
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* A plugin runs in one of two places:
|
|
13
|
+
* - In the app's window, where it can draw its own interface with React. It
|
|
14
|
+
* shares the app's copy of React: import React from 'react'.
|
|
15
|
+
* - In a separate worker, if its manifest has "sandboxed": true. It can use
|
|
16
|
+
* everything here except what draws its own interface (views, inspector
|
|
17
|
+
* tabs, sidebar panels, dashboard cards, settings panels, its own dialogs and
|
|
18
|
+
* editor extensions), editor.active, editor.anchor and app.speech.
|
|
19
|
+
*
|
|
20
|
+
* Code that avoids those features works in both places.
|
|
21
|
+
*
|
|
22
|
+
* Everything a plugin adds through these methods is removed when the plugin is
|
|
23
|
+
* turned off or reloaded. A plugin can access the book only through `this.app`,
|
|
24
|
+
* and the internet only through `this.app.net`, limited to the hosts its
|
|
25
|
+
* manifest names (or addresses the writer entered) and the writer allowed.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { ReactNode, ComponentType } from 'react'
|
|
29
|
+
import type { AnyExtension } from '@tiptap/core'
|
|
30
|
+
import type { Editor } from '@tiptap/core'
|
|
31
|
+
|
|
32
|
+
/** A project folder, as returned by app.folder. */
|
|
33
|
+
export interface ProjectFolder {
|
|
34
|
+
key: string
|
|
35
|
+
name: string
|
|
36
|
+
/** The open book's folder, relative to the project: `books/<id>`. Empty for a folder from folder.create. */
|
|
37
|
+
book: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** One version in a plugin's version history (see addVersionHistory). */
|
|
41
|
+
export interface VersionEntry {
|
|
42
|
+
/** The plugin's identifier for the version. The app passes it back to `read`. */
|
|
43
|
+
id: string
|
|
44
|
+
label: string
|
|
45
|
+
/** When it was saved, as an ISO date. */
|
|
46
|
+
at: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** What a `during` handler is told about the moment the app is waiting at. */
|
|
50
|
+
export interface WaitInfo {
|
|
51
|
+
/** The number of words in the whole project. */
|
|
52
|
+
words: number
|
|
53
|
+
/** Whether the project has changed since plugins were last told of a 'copy-due' or 'project-closing'. Always true for a new book. */
|
|
54
|
+
changed: boolean
|
|
55
|
+
/**
|
|
56
|
+
* Only for 'project-closing': true when the window is closing, or the app is going to the background on a phone or
|
|
57
|
+
* tablet. Finish all work in the handler; don't leave anything for later.
|
|
58
|
+
*/
|
|
59
|
+
quitting?: boolean
|
|
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'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface Manifest {
|
|
68
|
+
/** 2 to 64 lower-case letters, digits and dashes, starting with a letter or digit. It's also the name of the plugin's folder. */
|
|
69
|
+
id: string
|
|
70
|
+
name: string
|
|
71
|
+
version: string
|
|
72
|
+
description: string
|
|
73
|
+
author: string
|
|
74
|
+
/**
|
|
75
|
+
* The plugin API version the plugin needs. Defaults to 1.
|
|
76
|
+
*/
|
|
77
|
+
apiVersion: number
|
|
78
|
+
/** The plugin's script, relative to its folder. Defaults to main.js. */
|
|
79
|
+
main: string
|
|
80
|
+
/** Runs the plugin in a separate worker instead of the app's window. */
|
|
81
|
+
sandboxed: boolean
|
|
82
|
+
/** The plugin's name and description in other languages, keyed by language code: { "sv": { "name": "…", "description": "…" } }. */
|
|
83
|
+
locales?: Record<string, { name?: string; description?: string }>
|
|
84
|
+
/**
|
|
85
|
+
* Permissions the plugin can request later with app.permissions.request, when the writer uses a feature that
|
|
86
|
+
* needs them (such as sending text to a service). They take the same values as `permissions`, but the writer
|
|
87
|
+
* isn't asked for them when the plugin is turned on. API 5.
|
|
88
|
+
*
|
|
89
|
+
* "network:ask" lets the plugin request access to an address the writer entered (such as a repository URL), which
|
|
90
|
+
* it can't list in advance. Request `address:https://host/path`: the writer is asked to allow that exact address,
|
|
91
|
+
* and the plugin can then reach that address and the paths under it. API 10.
|
|
92
|
+
*/
|
|
93
|
+
optionalPermissions?: string[]
|
|
94
|
+
/**
|
|
95
|
+
* Why the plugin needs each permission in `permissions` or `optionalPermissions`, keyed by permission. The
|
|
96
|
+
* writer sees the reason when asked to allow the permission, under "it needs to:" and above the app's own
|
|
97
|
+
* description. Write it to complete the sentence "it needs to …", and say what is sent where, and why. Give
|
|
98
|
+
* one string, or one per language code, each up to 300 characters. API 8.
|
|
99
|
+
*
|
|
100
|
+
* "permissionReasons": {
|
|
101
|
+
* "network:api.example.com": {
|
|
102
|
+
* "en": "fetch today's word from Example (api.example.com)",
|
|
103
|
+
* "sv": "hämta dagens ord från Example (api.example.com)"
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
*/
|
|
107
|
+
permissionReasons?: Record<string, string | Record<string, string>>
|
|
108
|
+
/**
|
|
109
|
+
* The group the plugin is listed under in Manage Plugins:
|
|
110
|
+
* - "writing": tools for the text while writing
|
|
111
|
+
* - "planning": the navigator, cards and views
|
|
112
|
+
* - "welcome": the welcome screen
|
|
113
|
+
* - "import-export": importing and exporting books
|
|
114
|
+
* - "other": anything else
|
|
115
|
+
*
|
|
116
|
+
* Without a category, the plugin is grouped by what it adds while it's turned on, and under "other" while it's off. API 8.
|
|
117
|
+
*/
|
|
118
|
+
category?: 'writing' | 'planning' | 'welcome' | 'import-export' | 'other'
|
|
119
|
+
/**
|
|
120
|
+
* What the plugin needs beyond reading the book. The writer is asked to allow each one:
|
|
121
|
+
* - "project:write": change the book.
|
|
122
|
+
* - "library:read": see the writer's recent books and their series (app.library), for the dashboard.
|
|
123
|
+
* - "project:folder": read and change every file in the open project's folder, including hidden ones such as a
|
|
124
|
+
* version history (app.folder). Nothing outside that folder is accessible. API 10.
|
|
125
|
+
* - "microphone": record audio with navigator.mediaDevices.getUserMedia, in the window. API 3.
|
|
126
|
+
* - "network:<host>": connect to that host. Use "network:*.<host>" to include its subdomains, or "network:*" for any
|
|
127
|
+
* public host. "network:*" never covers this computer or the local network: name those hosts explicitly.
|
|
128
|
+
* - "files:read", "files:write": read or change files and folders the writer chooses for the plugin.
|
|
129
|
+
* - "exec:<program>": run that program, found by name on the PATH, without a shell.
|
|
130
|
+
*/
|
|
131
|
+
permissions: string[]
|
|
132
|
+
}
|
|
133
|
+
|
|
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
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface NodeInfo {
|
|
163
|
+
id: string
|
|
164
|
+
title: string
|
|
165
|
+
type: NodeType
|
|
166
|
+
/** An entry's kind, "<plugin id>:<kind id>". API 12. */
|
|
167
|
+
kind?: string
|
|
168
|
+
parentId: string | null
|
|
169
|
+
children: string[]
|
|
170
|
+
inTrash: boolean
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface MetaInfo {
|
|
174
|
+
synopsis: string
|
|
175
|
+
notes: string
|
|
176
|
+
keywords: string[]
|
|
177
|
+
/** The fields on a character's or place's sheet: "Age", "Born"… */
|
|
178
|
+
fields: Record<string, string>
|
|
179
|
+
/** When the scene happens, as written on its card: "Day 3", "1888-05-01"… */
|
|
180
|
+
when: string
|
|
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
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface Label {
|
|
189
|
+
id: string
|
|
190
|
+
name: string
|
|
191
|
+
color: string
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface Status {
|
|
195
|
+
id: string
|
|
196
|
+
name: string
|
|
197
|
+
/** The colour on the corkboard (#rrggbb) when cards are coloured by status. */
|
|
198
|
+
color?: string
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface FileEntry {
|
|
202
|
+
name: string
|
|
203
|
+
path: string
|
|
204
|
+
folder: boolean
|
|
205
|
+
size: number
|
|
206
|
+
modified: string
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface ExecOutput {
|
|
210
|
+
/** The exit code, or null if the program was stopped. */
|
|
211
|
+
code: number | null
|
|
212
|
+
stdout: Uint8Array
|
|
213
|
+
stderr: string
|
|
214
|
+
timedOut: boolean
|
|
215
|
+
/** stdout as text. */
|
|
216
|
+
text(): string
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface FetchResult {
|
|
220
|
+
ok: boolean
|
|
221
|
+
status: number
|
|
222
|
+
statusText: string
|
|
223
|
+
headers: Record<string, string>
|
|
224
|
+
text(): string
|
|
225
|
+
json(): unknown
|
|
226
|
+
bytes(): Uint8Array
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** A summary of one of the writer's books, read from its files, for the welcome screen's dashboard. */
|
|
230
|
+
export interface LibraryBook {
|
|
231
|
+
/** The book's folder. Pass this to app.library.open. */
|
|
232
|
+
path: string
|
|
233
|
+
title: string
|
|
234
|
+
author: string
|
|
235
|
+
/** When it was last opened in the app (ISO), or '' for a book in a series that's never been opened. */
|
|
236
|
+
opened: string
|
|
237
|
+
/** When anything in the book last changed (ISO). */
|
|
238
|
+
modified: string
|
|
239
|
+
/** The book's series: its name and folder, the book's zero-based position in it, and the number of books. Null if it isn't in one. */
|
|
240
|
+
series: { name: string; path: string; index: number; books: number } | null
|
|
241
|
+
/** The number of words and scenes in the manuscript. */
|
|
242
|
+
words: number
|
|
243
|
+
scenes: number
|
|
244
|
+
/** The word target (0 for none) and the deadline (YYYY-MM-DD, or '' for none). */
|
|
245
|
+
target: number
|
|
246
|
+
deadline: string
|
|
247
|
+
/** The daily writing goal (0 for none). */
|
|
248
|
+
sessionTarget: number
|
|
249
|
+
/** Words written per day, keyed by date (YYYY-MM-DD, in the writer's time zone). Empty for a book that isn't counted. */
|
|
250
|
+
history: Record<string, number>
|
|
251
|
+
/**
|
|
252
|
+
* Whether the book counts in the writer's statistics. It's false for a sample, or for a book or series
|
|
253
|
+
* the writer left out, so leave those out of totals and goals. Older versions of the app don't set it, so
|
|
254
|
+
* treat a missing value as true.
|
|
255
|
+
*/
|
|
256
|
+
counted?: boolean
|
|
257
|
+
/** The number of scenes with each status, in the order the book lists its statuses. */
|
|
258
|
+
statuses: { name: string; count: number }[]
|
|
259
|
+
/** The scene most recently written in, with the last few hundred characters of its text (as plain text). */
|
|
260
|
+
last: { id: string; title: string; modified: string; excerpt: string } | null
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Recent activity across the writer's books. */
|
|
264
|
+
export interface LibraryActivity {
|
|
265
|
+
/** The latest saved versions (git commits), newest first. */
|
|
266
|
+
versions: { book: string; title: string; message: string; date: string }[]
|
|
267
|
+
/** The latest zip backups, newest first. */
|
|
268
|
+
backups: { file: string; date: string; size: number }[]
|
|
269
|
+
/** The most recent push of each book's version history, newest first. */
|
|
270
|
+
pushes: { book: string; title: string; ok: boolean; at: string; message: string }[]
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface App {
|
|
274
|
+
readonly apiVersion: number
|
|
275
|
+
/** The language of the app's interface: 'en', 'sv'… */
|
|
276
|
+
readonly language: string
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The open book. Changing it needs "project:write". Every change can be undone, and the app takes a snapshot
|
|
280
|
+
* of a document before a plugin first rewrites it.
|
|
281
|
+
*/
|
|
282
|
+
project: {
|
|
283
|
+
isOpen(): Promise<boolean>
|
|
284
|
+
info(): Promise<{ title: string; author: string; language: string; series: string | null } | null>
|
|
285
|
+
nodes(): Promise<NodeInfo[]>
|
|
286
|
+
node(id: string): Promise<NodeInfo | null>
|
|
287
|
+
/** The manuscript's documents, in reading order. */
|
|
288
|
+
manuscript(): Promise<string[]>
|
|
289
|
+
selected(): Promise<string | null>
|
|
290
|
+
select(id: string): Promise<void>
|
|
291
|
+
/** A document's text as HTML. */
|
|
292
|
+
read(id: string): Promise<string>
|
|
293
|
+
/** A document's text as plain text. */
|
|
294
|
+
readText(id: string): Promise<string>
|
|
295
|
+
write(id: string, html: string): Promise<void>
|
|
296
|
+
create(type: 'text' | 'folder' | 'character' | 'place' | 'note' | 'research' | { kind: string }, title: string, parentId?: string): Promise<string>
|
|
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>
|
|
305
|
+
setMeta(id: string, patch: Partial<Pick<MetaInfo, 'synopsis' | 'notes' | 'keywords' | 'fields' | 'when'>>): Promise<void>
|
|
306
|
+
/** Moves an item to the trash, where the writer can restore it. */
|
|
307
|
+
trash(id: string): Promise<void>
|
|
308
|
+
rename(id: string, title: string): Promise<void>
|
|
309
|
+
/** Moves an item into a folder, at `index` among its children, or at the end if there's no index. */
|
|
310
|
+
move(id: string, parentId: string, index?: number): Promise<void>
|
|
311
|
+
labels(): Promise<Label[]>
|
|
312
|
+
statuses(): Promise<Status[]>
|
|
313
|
+
/** Sets an item's label by the label's id, or '' to clear it. setStatus works the same way. */
|
|
314
|
+
setLabel(id: string, labelId: string): Promise<void>
|
|
315
|
+
setStatus(id: string, statusId: string): Promise<void>
|
|
316
|
+
comments(id: string): Promise<{ id: string; text: string; created: string; resolved: boolean }[]>
|
|
317
|
+
resolveComment(id: string, commentId: string, resolved?: boolean): Promise<void>
|
|
318
|
+
snapshots(id: string): Promise<{ label: string; taken: string; html: string }[]>
|
|
319
|
+
/** Saves a snapshot of a document as it is now. This needs no permission. */
|
|
320
|
+
snapshot(id: string, label: string): Promise<void>
|
|
321
|
+
/** Searches the book, like Find in Project. */
|
|
322
|
+
search(
|
|
323
|
+
query: string,
|
|
324
|
+
opts?: { wholeWord?: boolean; caseSensitive?: boolean; regex?: boolean },
|
|
325
|
+
): Promise<{ id: string; title: string; line: number; excerpt: string }[]>
|
|
326
|
+
/** The book's series and its books in order, or null if the book isn't in a series. */
|
|
327
|
+
series(): Promise<{ name: string; books: { id: string; title: string; current: boolean }[] } | null>
|
|
328
|
+
/** Resolves once every pending change is saved to disk. API 10: check that it exists. */
|
|
329
|
+
flush?(): Promise<void>
|
|
330
|
+
/**
|
|
331
|
+
* This plugin's data for the whole project, or undefined. It's stored in the project's project.json on this device,
|
|
332
|
+
* and isn't shared on Bläck Sync. If the project.json can't be read, getProjectData returns undefined and
|
|
333
|
+
* setProjectData throws. API 10: check that it exists.
|
|
334
|
+
*/
|
|
335
|
+
getProjectData?(): Promise<unknown>
|
|
336
|
+
setProjectData?(value: unknown): Promise<void>
|
|
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. */
|
|
338
|
+
open?(key: string): Promise<boolean>
|
|
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
|
+
*/
|
|
345
|
+
getData(): Promise<unknown>
|
|
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>
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
editor: {
|
|
393
|
+
/** The TipTap editor the writer is using. Window only: it's null in a sandboxed plugin. */
|
|
394
|
+
active(): Editor | null
|
|
395
|
+
selection(): Promise<{ text: string; from: number; to: number } | null>
|
|
396
|
+
/** Types text at the caret, replacing any selection. Returns false if no editor is active. Needs "project:write". */
|
|
397
|
+
insertText(text: string): Promise<boolean>
|
|
398
|
+
/** Adds a margin comment on the selection. Returns false if nothing is selected. Needs "project:write". */
|
|
399
|
+
comment(text: string): Promise<boolean>
|
|
400
|
+
/**
|
|
401
|
+
* Returns a position for inserting text as it arrives, as dictation does: the writer's cursor, or where it was
|
|
402
|
+
* before they clicked a button, or else the end of the open document. The position moves with edits around it.
|
|
403
|
+
* Returns null if no document is open. Needs "project:write". Window only. API 4.
|
|
404
|
+
*/
|
|
405
|
+
anchor(): Promise<EditorAnchor | null>
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
ui: {
|
|
409
|
+
/** Shows a notice, with a button if you pass an action. A sandboxed plugin's notice has no button. */
|
|
410
|
+
notify(message: string, action?: { label: string; run: () => void }): void
|
|
411
|
+
/** Asks a yes-or-no question in an app dialog. `confirmLabel` defaults to "OK". Resolves to true if the writer confirms. */
|
|
412
|
+
confirm(title: string, detail?: string, confirmLabel?: string): Promise<boolean>
|
|
413
|
+
/** Shows one of this plugin's views. Window only. */
|
|
414
|
+
openView(viewId: string): void
|
|
415
|
+
/** Shows this plugin's settings. */
|
|
416
|
+
openSettings(): void
|
|
417
|
+
/** Opens a dialog that the plugin draws itself. Returns a function that closes it. Window only. */
|
|
418
|
+
openModal(modal: {
|
|
419
|
+
title: string
|
|
420
|
+
render: (close: () => void) => ReactNode
|
|
421
|
+
wide?: boolean
|
|
422
|
+
/** Called when the dialog closes: 'closed' if the writer closed it (Escape, ✕) or `close` was called, 'replaced' if another dialog took its place. */
|
|
423
|
+
onClose?: (how: 'closed' | 'replaced') => void
|
|
424
|
+
}): () => void
|
|
425
|
+
/** Asks for a line of text. Returns null if the writer cancels. */
|
|
426
|
+
prompt(opts: { title: string; label?: string; value?: string; placeholder?: string }): Promise<string | null>
|
|
427
|
+
/** Asks the writer to choose one option. Returns null if they cancel. */
|
|
428
|
+
choose(opts: { title: string; options: { value: string; label: string; detail?: string }[] }): Promise<string | null>
|
|
429
|
+
/** Starts a writing sprint of 1 to 600 minutes in the open book, like the status bar's sprint. Throws if no book is open. API 2. */
|
|
430
|
+
startSprint(minutes: number): void
|
|
431
|
+
/**
|
|
432
|
+
* Shows a list of the marks from one of this plugin's highlighters in the current document, each with its
|
|
433
|
+
* surrounding text. The app selects the mark the writer picks. Resolves to false if there are no marks or
|
|
434
|
+
* the writer picks none. API 6: check that it exists before calling it.
|
|
435
|
+
*/
|
|
436
|
+
listMarks?(opts: {
|
|
437
|
+
highlighter: string
|
|
438
|
+
title: string
|
|
439
|
+
/** The heading for quiet marks (HighlightRange.quiet), which are listed last, each with its actions. API 9. */
|
|
440
|
+
quietTitle?: string
|
|
441
|
+
}): Promise<boolean>
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* The open project's folder, which holds its books. Needs "project:folder". API 10: check that it exists before using it.
|
|
446
|
+
*
|
|
447
|
+
* Paths are relative to the project's folder and use "/" as the separator. A path is refused if it's absolute, contains
|
|
448
|
+
* "..", goes through a symbolic link, has a name that isn't valid on every system, or names `.sync` (at any level) or
|
|
449
|
+
* `.git` (below the top level). Every call takes the project's key from current() instead of a path, so work started on one project can't
|
|
450
|
+
* end up in the next one opened. A key stops working two minutes after its project closes.
|
|
451
|
+
*/
|
|
452
|
+
folder?: {
|
|
453
|
+
/** Returns the open project's key, name and book folder (`books/<id>`), or null if no project is open. */
|
|
454
|
+
current(): Promise<ProjectFolder | null>
|
|
455
|
+
/**
|
|
456
|
+
* Asks the writer where to create a new project and creates its folder, for a plugin that brings in a project from
|
|
457
|
+
* elsewhere. `title` is the dialog's title and `name` the suggested folder name. Returns null if the writer cancels.
|
|
458
|
+
*/
|
|
459
|
+
create(title: string, name: string): Promise<ProjectFolder | null>
|
|
460
|
+
/** Deletes a folder made by create() that the plugin couldn't finish. This works only before the project is opened. */
|
|
461
|
+
discard(key: string): Promise<void>
|
|
462
|
+
/** Returns the file's bytes, or null if it doesn't exist. */
|
|
463
|
+
read(key: string, path: string): Promise<Uint8Array | null>
|
|
464
|
+
/** Writes the whole file, creating any missing parent folders. */
|
|
465
|
+
write(key: string, path: string, data: string | Uint8Array): Promise<void>
|
|
466
|
+
/** Deletes a file permanently (it doesn't go to the trash). Returns false if there was no such file. */
|
|
467
|
+
remove(key: string, path: string): Promise<boolean>
|
|
468
|
+
/** Lists a folder's contents ('' for the project's folder itself), or returns null if the folder doesn't exist. */
|
|
469
|
+
list(key: string, path: string): Promise<{ name: string; folder: boolean; link: boolean }[] | null>
|
|
470
|
+
/** Returns information about a file or folder, without following symbolic links, or null if nothing is there. */
|
|
471
|
+
stat(key: string, path: string): Promise<{ folder: boolean; link: boolean; size: number; mode: number; mtimeMs: number; ctimeMs: number; ino: number; uid: number; gid: number; dev: number } | null>
|
|
472
|
+
mkdir(key: string, path: string): Promise<void>
|
|
473
|
+
/** Deletes an empty folder. Returns false if the folder isn't empty or doesn't exist. */
|
|
474
|
+
rmdir(key: string, path: string): Promise<boolean>
|
|
475
|
+
/** Tells the app that these files were changed from outside the app: they're marked as downloaded, and the open book reloads them. */
|
|
476
|
+
arrived(key: string, paths: string[]): Promise<void>
|
|
477
|
+
/** Reports a new version or the result of a push, so the dashboard can list it for the project. */
|
|
478
|
+
note(key: string, note: { version?: { message: string; date: string }; push?: { ok: boolean; message: string } }): Promise<void>
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* The writer's books: those on the recent list, and every book in their series. Needs "library:read". API 2.
|
|
483
|
+
*/
|
|
484
|
+
library: {
|
|
485
|
+
books(): Promise<LibraryBook[]>
|
|
486
|
+
activity(): Promise<LibraryActivity>
|
|
487
|
+
/** Opens a book, closing the current one, optionally at a given document. Returns false if that fails. */
|
|
488
|
+
open(path: string, opts?: { select?: string }): Promise<boolean>
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
net: {
|
|
492
|
+
/**
|
|
493
|
+
* Makes an https request to a host the plugin may reach, and returns the whole response (on a computer, up to
|
|
494
|
+
* 20 MB within 30 seconds). Plain http works only for localhost and 127.0.0.1. Redirects aren't followed.
|
|
495
|
+
*/
|
|
496
|
+
fetch(
|
|
497
|
+
url: string,
|
|
498
|
+
init?: { method?: string; headers?: Record<string, string>; body?: string | Uint8Array },
|
|
499
|
+
): Promise<FetchResult>
|
|
500
|
+
/**
|
|
501
|
+
* Like fetch, but passes the response body to onChunk as text while it arrives, for example an AI model's reply.
|
|
502
|
+
* Resolves with the status and headers once the response is complete. Up to 200 MB and ten minutes. On a phone,
|
|
503
|
+
* the whole body arrives as one chunk. Chromium buffers the first 512 bytes of a text/plain response to detect
|
|
504
|
+
* its type, so they may arrive together unless the response has "X-Content-Type-Options: nosniff". Event
|
|
505
|
+
* streams and JSON aren't affected.
|
|
506
|
+
*/
|
|
507
|
+
stream(
|
|
508
|
+
url: string,
|
|
509
|
+
init: { method?: string; headers?: Record<string, string>; body?: string | Uint8Array } | undefined,
|
|
510
|
+
onChunk: (text: string) => void,
|
|
511
|
+
): Promise<{ ok: boolean; status: number; statusText: string; headers: Record<string, string> }>
|
|
512
|
+
/** Like stream, but passes each chunk as raw bytes, for binary data. Up to 200 MB and ten minutes. API 10: check that it exists. */
|
|
513
|
+
streamBytes?(
|
|
514
|
+
url: string,
|
|
515
|
+
init: { method?: string; headers?: Record<string, string>; body?: string | Uint8Array } | undefined,
|
|
516
|
+
onChunk: (chunk: Uint8Array) => void,
|
|
517
|
+
): Promise<{ ok: boolean; status: number; statusText: string; headers: Record<string, string> }>
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Files on the computer. The plugin can access only what the writer chose for it (with pickFolder and pickFile),
|
|
522
|
+
* and its own temporary folder. Needs "files:read" or "files:write". All paths are absolute.
|
|
523
|
+
*/
|
|
524
|
+
files: {
|
|
525
|
+
/**
|
|
526
|
+
* Asks the writer to choose a folder, and returns its path or null. The plugin can then read what's in it, and
|
|
527
|
+
* change it if `write` is set and the plugin has "files:write".
|
|
528
|
+
*/
|
|
529
|
+
pickFolder(opts?: { write?: boolean; title?: string }): Promise<string | null>
|
|
530
|
+
/** Asks the writer to choose a file to open, or where to save one if `save` is set. Returns the path, or null if they cancel. */
|
|
531
|
+
pickFile(opts?: { save?: boolean; name?: string; extensions?: string[]; title?: string }): Promise<string | null>
|
|
532
|
+
granted(): Promise<{ path: string; write: boolean; file?: boolean }[]>
|
|
533
|
+
/** The plugin's temporary folder, for passing files to programs. */
|
|
534
|
+
temp(): Promise<string>
|
|
535
|
+
read(path: string): Promise<Uint8Array>
|
|
536
|
+
readText(path: string): Promise<string>
|
|
537
|
+
write(path: string, data: string | Uint8Array): Promise<void>
|
|
538
|
+
list(path: string): Promise<FileEntry[]>
|
|
539
|
+
stat(path: string): Promise<{ folder: boolean; size: number; modified: string } | null>
|
|
540
|
+
mkdir(path: string): Promise<void>
|
|
541
|
+
/** Moves a file to the system's trash. */
|
|
542
|
+
trash(path: string): Promise<void>
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Runs programs that the manifest lists as "exec:<program>". Each is found by name on the PATH and runs without a
|
|
547
|
+
* shell. `timeout` is in milliseconds: one minute by default, ten minutes at most.
|
|
548
|
+
*/
|
|
549
|
+
exec: {
|
|
550
|
+
run(
|
|
551
|
+
program: string,
|
|
552
|
+
args?: string[],
|
|
553
|
+
opts?: { input?: string | Uint8Array; cwd?: string; timeout?: number },
|
|
554
|
+
): Promise<ExecOutput>
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** The plugin's optional permissions (see the manifest's optionalPermissions). API 5: check that this exists before using it. */
|
|
558
|
+
permissions?: {
|
|
559
|
+
/** Asks the writer to allow the permission, in the app's own window. Resolves to true if it's allowed, whether now or earlier. */
|
|
560
|
+
request(permission: string | string[]): Promise<boolean>
|
|
561
|
+
/** Whether the plugin has the permission now. In a sandboxed plugin, the answer comes as a promise. */
|
|
562
|
+
has(permission: string): boolean | Promise<boolean>
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Speech recognition on the device: nothing is sent anywhere. On a computer it uses Whisper, whose model is
|
|
567
|
+
* downloaded once the writer agrees. On a phone or tablet it uses the system's recogniser. Needs "microphone",
|
|
568
|
+
* and isn't available to sandboxed plugins. API 4.
|
|
569
|
+
*
|
|
570
|
+
* `language` is a code like "sv" or "en". Use '' to let a computer detect the language from the speech.
|
|
571
|
+
*
|
|
572
|
+
* `model` selects the Whisper model on a computer. Each model is downloaded once:
|
|
573
|
+
* - For every language: "tiny", "base", "small" (the default), "medium", "large-v3-turbo" or "large-v3".
|
|
574
|
+
* - For English only: "tiny.en" to "medium.en".
|
|
575
|
+
* - For Swedish only: "kb-tiny" to "kb-large" (KB-Whisper), or "pianissimo" (Klang's Pianissimo, API 5).
|
|
576
|
+
*
|
|
577
|
+
* Each model is used with Silero voice activity detection, which detects where a phrase ends. A phone uses these
|
|
578
|
+
* models only when it uses Whisper instead of the system's recogniser (see SpeechChoice.engine).
|
|
579
|
+
*/
|
|
580
|
+
speech: {
|
|
581
|
+
/** Reports whether recognition is ready. If not, says what's missing: a download (`size` bytes, if known), or that it's unavailable here. */
|
|
582
|
+
status(language: string, opts?: SpeechChoice): Promise<SpeechStatus>
|
|
583
|
+
/**
|
|
584
|
+
* Loads the model ahead of time, such as when a book opens, so the first dictation is as fast as the rest.
|
|
585
|
+
* It only loads a model already on the device, and never downloads one. The model is unloaded after ten
|
|
586
|
+
* minutes without use. Returns true if it's ready. API 5: check that it exists before calling it.
|
|
587
|
+
*/
|
|
588
|
+
preload?(language: string, opts?: SpeechChoice): Promise<boolean>
|
|
589
|
+
/** Downloads what's needed, after asking the writer. Returns false if they decline. */
|
|
590
|
+
prepare(language: string, opts?: SpeechChoice & { onProgress?: (fraction: number) => void }): Promise<boolean>
|
|
591
|
+
/** Starts listening and resolves with a session. The session's stop() returns the recognised text. On a phone, onPartial receives words as they're heard. */
|
|
592
|
+
listen(opts: SpeechChoice & {
|
|
593
|
+
/** Use '' to detect the language among `languages`, the app's language, the system's language and English. */
|
|
594
|
+
language: string
|
|
595
|
+
languages?: string[]
|
|
596
|
+
/** The current phrase, as recognised so far. */
|
|
597
|
+
onPartial?: (text: string) => void
|
|
598
|
+
/** Receives each finished phrase when the writer pauses. With onSegment, stop() returns only the text not yet passed to it. */
|
|
599
|
+
onSegment?: (text: string) => void
|
|
600
|
+
/** Called when something goes wrong. No more text will arrive. */
|
|
601
|
+
onError?: (message: string) => void
|
|
602
|
+
/** Receives the input level (0 to 1) several times a second, for showing that the microphone hears something. Older versions of the app don't call this. */
|
|
603
|
+
onLevel?: (level: number) => void
|
|
604
|
+
/** How long a pause ends a phrase: 'quick', 'balanced' (the default), 'patient', or a number of seconds. API 5. */
|
|
605
|
+
pause?: 'quick' | 'balanced' | 'patient' | number
|
|
606
|
+
/** The microphone to use, by its id from microphones(). Without one, the system's default is used. API 5. */
|
|
607
|
+
microphone?: string
|
|
608
|
+
}): Promise<SpeechSession>
|
|
609
|
+
/** The available microphones. Their names appear once the writer has allowed the app to use one. API 5. */
|
|
610
|
+
microphones?(): Promise<{ id: string; name: string }[]>
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/** Options for how speech is recognised. Pass the same options to status, prepare and listen. */
|
|
615
|
+
export interface SpeechChoice {
|
|
616
|
+
/** The Whisper model (see app.speech). */
|
|
617
|
+
model?: string
|
|
618
|
+
/** Runs Whisper on the CPU, even if a GPU is available. */
|
|
619
|
+
processor?: boolean
|
|
620
|
+
/** On a phone: 'system' uses the system's recogniser, 'whisper' uses Whisper, and 'auto' uses the system's where it supports the language. */
|
|
621
|
+
engine?: 'auto' | 'system' | 'whisper'
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** A position in the text for inserting text over time. See app.editor.anchor. */
|
|
625
|
+
export interface EditorAnchor {
|
|
626
|
+
docId: string
|
|
627
|
+
/** The character just before the position, to decide whether new text needs a space first. */
|
|
628
|
+
before(): string
|
|
629
|
+
/** The character just after the position, to decide whether new text needs a space after it. API 5: check that it exists. */
|
|
630
|
+
after?(): string
|
|
631
|
+
/** Shows greyed-out words at the position, as dictation does. They aren't part of the text. Use '' to clear them. API 5: check that it exists. */
|
|
632
|
+
draft?(text: string): void
|
|
633
|
+
/** Inserts plain text at the position, after anything inserted earlier. Returns false if the document is no longer open in an editor. */
|
|
634
|
+
insert(text: string): boolean
|
|
635
|
+
/** Call this when you're finished with the anchor. It also clears any draft. */
|
|
636
|
+
release(): void
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
export interface SpeechStatus {
|
|
640
|
+
ready: boolean
|
|
641
|
+
/** The number of bytes still to download, if known. */
|
|
642
|
+
size: number
|
|
643
|
+
/**
|
|
644
|
+
* On a computer, the parts of that download: the model itself (`model: true`) and the voice detection model.
|
|
645
|
+
* API 7: check that it exists.
|
|
646
|
+
*/
|
|
647
|
+
parts?: { title: string; size: number; model: boolean }[]
|
|
648
|
+
/** Why it can't work on this device: there's no recogniser, or it doesn't support this language. */
|
|
649
|
+
unavailable?: 'device' | 'language'
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export interface SpeechSession {
|
|
653
|
+
/** Stops listening and returns what was said. */
|
|
654
|
+
stop(): Promise<string>
|
|
655
|
+
/** Stops listening and discards what was heard. */
|
|
656
|
+
cancel(): void
|
|
657
|
+
/** Pauses listening and releases the microphone until resume() is called. Text recognised so far is kept. Older versions of the app don't have this, so check that it exists. */
|
|
658
|
+
pause?(): void
|
|
659
|
+
resume?(): void
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/** What the writer right-clicked on in the text. */
|
|
663
|
+
export interface EditorContext {
|
|
664
|
+
docId: string
|
|
665
|
+
/** The selected text, or '' if there's none. */
|
|
666
|
+
selection: string
|
|
667
|
+
/** The word at the caret, when nothing is selected. */
|
|
668
|
+
word: string
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/** A part of a paragraph to mark, given as character offsets in its text. */
|
|
672
|
+
export interface HighlightRange {
|
|
673
|
+
from: number
|
|
674
|
+
to: number
|
|
675
|
+
/** Shown as a tooltip when the pointer hovers over the mark, and in its right-click menu. */
|
|
676
|
+
message?: string
|
|
677
|
+
/** Actions for the mark's right-click menu, such as "Ignore". The highlighter's onAction gets the chosen one. API 6. */
|
|
678
|
+
actions?: { id: string; label: string }[]
|
|
679
|
+
/**
|
|
680
|
+
* Hides the mark from the text and the right-click menu. ui.listMarks still lists it separately, with its
|
|
681
|
+
* actions. Use this for something the writer ignored, with an action to show it again. API 9: older versions
|
|
682
|
+
* of the app draw it like any other mark, so only use this when app.apiVersion is 9 or higher.
|
|
683
|
+
*/
|
|
684
|
+
quiet?: boolean
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/** The mark that an action was chosen for. API 6. */
|
|
688
|
+
export interface MarkInfo {
|
|
689
|
+
/** The marked text. */
|
|
690
|
+
text: string
|
|
691
|
+
/** The text of the paragraph it's in, as passed to `find`, and the mark's offsets in it. */
|
|
692
|
+
paragraph: string
|
|
693
|
+
from: number
|
|
694
|
+
to: number
|
|
695
|
+
/** The document it's in. */
|
|
696
|
+
docId: string
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/** The compiled book, passed to an export format. */
|
|
700
|
+
export interface ExportInput {
|
|
701
|
+
title: string
|
|
702
|
+
author: string
|
|
703
|
+
language: string
|
|
704
|
+
/** The whole manuscript as one HTML document, the same as the app's own HTML export. */
|
|
705
|
+
html: string
|
|
706
|
+
/** Each part in reading order: a folder's title, or a scene's title and text as HTML. */
|
|
707
|
+
items: { id: string; title: string; depth: number; isFolder: boolean; section: 'front' | 'body' | 'back'; html: string }[]
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
export interface SettingField {
|
|
711
|
+
key: string
|
|
712
|
+
label: string
|
|
713
|
+
/** 'secret' is text shown as dots, for an API key or password (API 3). */
|
|
714
|
+
type: 'text' | 'secret' | 'textarea' | 'number' | 'toggle' | 'select'
|
|
715
|
+
description?: string
|
|
716
|
+
default?: unknown
|
|
717
|
+
options?: { value: string; label: string }[]
|
|
718
|
+
/** Shows the field only while other settings have one of these values: { source: ['web', 'feed'] }. API 5. */
|
|
719
|
+
showWhen?: Record<string, string[]>
|
|
720
|
+
/** Puts the field in a collapsed section with this heading, with any other fields that use the same heading. API 5. */
|
|
721
|
+
folded?: string
|
|
722
|
+
}
|
|
723
|
+
|
|
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'
|
|
730
|
+
|
|
731
|
+
/** A suggestion offered as the writer types after a trigger. */
|
|
732
|
+
export interface Suggestion {
|
|
733
|
+
label: string
|
|
734
|
+
/** The text that replaces the trigger and everything typed after it. Defaults to `label`. */
|
|
735
|
+
insert?: string
|
|
736
|
+
detail?: string
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/** A file the writer picked to import. */
|
|
740
|
+
export interface ImportFile {
|
|
741
|
+
name: string
|
|
742
|
+
/** The extension in lower case, without the dot. */
|
|
743
|
+
ext: string
|
|
744
|
+
data: Uint8Array
|
|
745
|
+
/** The contents as text (UTF-8). */
|
|
746
|
+
text: string
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/** The file or folder the writer picked for a book importer. API 7. */
|
|
750
|
+
export interface ImportSource {
|
|
751
|
+
/** Its name: "Sample.scriv", "outline.pltr". */
|
|
752
|
+
name: string
|
|
753
|
+
/** The extension in lower case, without the dot. */
|
|
754
|
+
ext: string
|
|
755
|
+
/** True for a folder. On a phone, this is the folder inside the zip the writer chose. */
|
|
756
|
+
folder: boolean
|
|
757
|
+
/** A file's contents as bytes and as text (UTF-8). Not set for a folder. */
|
|
758
|
+
data?: Uint8Array
|
|
759
|
+
text?: string
|
|
760
|
+
/** Every file in a folder, at any depth, with paths using "/". Empty for a single file. */
|
|
761
|
+
files: { path: string; size: number }[]
|
|
762
|
+
/** Reads a file in the folder, by its path in `files`. */
|
|
763
|
+
read(path: string): Promise<Uint8Array>
|
|
764
|
+
readText(path: string): Promise<string>
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* An item in an imported book's binder. `id` is only for other items in the import to refer to it, such as a
|
|
769
|
+
* scene's cast or a beat's scene. The app assigns its own id. API 7.
|
|
770
|
+
*/
|
|
771
|
+
export interface ImportedItem {
|
|
772
|
+
id?: string
|
|
773
|
+
/**
|
|
774
|
+
* The item's type. Without one, an item with children is a folder. Any other item takes the type of the navigator
|
|
775
|
+
* section it's in: a scene in the manuscript, a sheet in characters, a note in Notes, a document in Research.
|
|
776
|
+
*/
|
|
777
|
+
type?: NodeType
|
|
778
|
+
/** An entry's kind: the `id` of one of the book's `kinds` (API 12). */
|
|
779
|
+
kind?: string
|
|
780
|
+
title: string
|
|
781
|
+
/** The text as HTML: paragraphs, headings, emphasis, lists, quotes, and <hr> for a scene break. */
|
|
782
|
+
html?: string
|
|
783
|
+
synopsis?: string
|
|
784
|
+
notes?: string
|
|
785
|
+
keywords?: string[]
|
|
786
|
+
/** The label and status, by their ids in the book's `labels` and `statuses`. */
|
|
787
|
+
label?: string
|
|
788
|
+
status?: string
|
|
789
|
+
/** Whether Compile includes the item. Defaults to true. */
|
|
790
|
+
includeInCompile?: boolean
|
|
791
|
+
/** Fields for a sheet ("Age", "Born"…), added to the fields the book already has. */
|
|
792
|
+
fields?: Record<string, string>
|
|
793
|
+
/** When the scene happens, as written on its card. */
|
|
794
|
+
when?: string
|
|
795
|
+
/** The characters in a scene, and where it's set, by their item ids. */
|
|
796
|
+
cast?: string[]
|
|
797
|
+
place?: string
|
|
798
|
+
/** For a "file" item: its path in the picked folder, and the name to save it under. */
|
|
799
|
+
file?: { path: string; name: string }
|
|
800
|
+
children?: ImportedItem[]
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* The book that a book importer returns. The writer can make it a new book or add it to the open one.
|
|
805
|
+
*
|
|
806
|
+
* As a new book, its labels and statuses, if any, replace the writer's defaults.
|
|
807
|
+
*
|
|
808
|
+
* When it's added to the open book:
|
|
809
|
+
* - The manuscript and research each go in a new folder.
|
|
810
|
+
* - Characters and places are merged with the existing sheets, matching sheets by name.
|
|
811
|
+
* - Labels, statuses and storylines are matched by name.
|
|
812
|
+
* - The trash is left out.
|
|
813
|
+
*
|
|
814
|
+
* API 7.
|
|
815
|
+
*/
|
|
816
|
+
export interface ImportedBook {
|
|
817
|
+
title: string
|
|
818
|
+
author?: string
|
|
819
|
+
/** A summary of what was imported, shown in the dialog before the writer chooses. */
|
|
820
|
+
about?: string
|
|
821
|
+
/** The name of the new folders when adding to the open book: "From Scrivener — Sample". */
|
|
822
|
+
folder?: string
|
|
823
|
+
labels?: { id: string; name: string; color?: string }[]
|
|
824
|
+
statuses?: { id: string; name: string; color?: string }[]
|
|
825
|
+
storylines?: { id: string; name: string; color?: string; description?: string }[]
|
|
826
|
+
manuscript?: ImportedItem[]
|
|
827
|
+
characters?: ImportedItem[]
|
|
828
|
+
places?: ImportedItem[]
|
|
829
|
+
notes?: ImportedItem[]
|
|
830
|
+
research?: ImportedItem[]
|
|
831
|
+
trash?: ImportedItem[]
|
|
832
|
+
/** Beats (cards on the plot grid). Each names its storyline by id, and its scene by id if it belongs to one. */
|
|
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[]
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
export declare class Plugin {
|
|
839
|
+
readonly app: App
|
|
840
|
+
readonly manifest: Manifest
|
|
841
|
+
/** The current values of the settings declared with `addSettings`. */
|
|
842
|
+
settings: Record<string, unknown>
|
|
843
|
+
|
|
844
|
+
/** Called when the plugin starts. Add commands, views and so on here. */
|
|
845
|
+
onload(): void | Promise<void>
|
|
846
|
+
/** Called when the plugin is turned off. Clean up anything the app doesn't remove itself. */
|
|
847
|
+
onunload(): void
|
|
848
|
+
/*
|
|
849
|
+
* Every add… method returns a function that removes what it added (the text form of addStatusBarItem returns an
|
|
850
|
+
* object instead), which is useful when a setting changes what a plugin offers. Anything still there is removed
|
|
851
|
+
* when the plugin is turned off.
|
|
852
|
+
*/
|
|
853
|
+
|
|
854
|
+
/** Registers something to clean up when the plugin is turned off, such as a timer or a listener. */
|
|
855
|
+
register(dispose: () => void): void
|
|
856
|
+
|
|
857
|
+
/** Adds a command to the command palette (Ctrl+K) and, unless `menu` is false, the Plugins menu. `hotkey` looks like "Mod+Shift+F", where Mod is Ctrl or ⌘. */
|
|
858
|
+
addCommand(command: {
|
|
859
|
+
id: string
|
|
860
|
+
name: string
|
|
861
|
+
hotkey?: string
|
|
862
|
+
menu?: boolean
|
|
863
|
+
when?: () => boolean
|
|
864
|
+
run: () => void | Promise<void>
|
|
865
|
+
}): () => void
|
|
866
|
+
/** Adds a view beside the corkboard and outliner. Window only. */
|
|
867
|
+
addView(view: { id: string; name: string; icon?: ComponentType<{ size?: number }>; render: () => ReactNode }): () => void
|
|
868
|
+
/** Adds a tab to the inspector, for items where `when` returns true. Window only. */
|
|
869
|
+
addInspectorTab(tab: {
|
|
870
|
+
id: string
|
|
871
|
+
name: string | ((nodeId: string) => string)
|
|
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
|
|
874
|
+
render: (nodeId: string) => ReactNode
|
|
875
|
+
}): () => void
|
|
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. */
|
|
877
|
+
addStatusBarItem(item: { id: string; render: () => ReactNode }): () => void
|
|
878
|
+
addStatusBarItem(item: { id: string; text: string; title?: string; onClick?: () => unknown }): {
|
|
879
|
+
setText(text: string, title?: string): void
|
|
880
|
+
}
|
|
881
|
+
/** Adds an item to the editor's right-click menu. `show` defaults to 'always'. In a sandboxed plugin, the label must be a string and `when` isn't available, so use `show`. */
|
|
882
|
+
addEditorMenuItem(item: {
|
|
883
|
+
id: string
|
|
884
|
+
label: string | ((ctx: EditorContext) => string)
|
|
885
|
+
show?: 'selection' | 'no-selection' | 'always'
|
|
886
|
+
when?: (ctx: EditorContext) => boolean
|
|
887
|
+
run: (ctx: EditorContext) => void | Promise<void>
|
|
888
|
+
}): () => void
|
|
889
|
+
/** Adds an item to the navigator's right-click menu. */
|
|
890
|
+
addBinderMenuItem(item: {
|
|
891
|
+
id: string
|
|
892
|
+
label: string | ((nodeId: string) => string)
|
|
893
|
+
when?: (nodeId: string) => boolean
|
|
894
|
+
run: (nodeId: string) => void | Promise<void>
|
|
895
|
+
}): () => void
|
|
896
|
+
/** Adds a format to Compile. Return text, or bytes for a binary format. */
|
|
897
|
+
addExporter(exporter: {
|
|
898
|
+
id: string
|
|
899
|
+
name: string
|
|
900
|
+
description?: string
|
|
901
|
+
extension: string
|
|
902
|
+
export: (book: ExportInput) => string | Uint8Array | Promise<string | Uint8Array>
|
|
903
|
+
}): () => void
|
|
904
|
+
/** Adds marks to the text, found one paragraph at a time. The app draws them, and they're never saved. */
|
|
905
|
+
addHighlighter(highlighter: {
|
|
906
|
+
id: string
|
|
907
|
+
color?: string
|
|
908
|
+
find: (text: string) => HighlightRange[] | Promise<HighlightRange[]>
|
|
909
|
+
/** Called when the writer chooses one of a mark's `actions` from its right-click menu. API 6. */
|
|
910
|
+
onAction?: (action: string, mark: MarkInfo) => unknown
|
|
911
|
+
}): () => void
|
|
912
|
+
/** Runs every highlighter again, for example after a setting that affects them changes. */
|
|
913
|
+
refreshHighlights(): void
|
|
914
|
+
/** Adds TipTap extensions to every editor. Window only. */
|
|
915
|
+
registerEditorExtension(extension: AnyExtension | AnyExtension[]): () => void
|
|
916
|
+
/** Adds a panel to the sidebar, beside the binder. Window only. */
|
|
917
|
+
addSidebarPanel(panel: { id: string; name: string; render: () => ReactNode }): () => void
|
|
918
|
+
/** Adds a button to the editor's toolbar. In a sandboxed plugin, the icon is text, such as an emoji. */
|
|
919
|
+
addToolbarButton(button: {
|
|
920
|
+
id: string
|
|
921
|
+
title: string
|
|
922
|
+
icon?: ComponentType<{ size?: number }> | string
|
|
923
|
+
active?: () => boolean
|
|
924
|
+
run: () => void | Promise<void>
|
|
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
|
|
936
|
+
/** Shows suggestions under the caret as the writer types after `trigger` ("@", "#"…) at the start of a word. `trigger` must be a single character. */
|
|
937
|
+
addSuggester(suggester: {
|
|
938
|
+
id: string
|
|
939
|
+
trigger: string
|
|
940
|
+
find: (query: string, ctx: { docId: string }) => Suggestion[] | Promise<Suggestion[]>
|
|
941
|
+
}): () => void
|
|
942
|
+
/** Adds a file type the app can't read itself to File → Import Documents. Each file becomes one or more documents. */
|
|
943
|
+
addImporter(importer: {
|
|
944
|
+
id: string
|
|
945
|
+
name: string
|
|
946
|
+
extensions: string[]
|
|
947
|
+
import: (file: ImportFile) => { title: string; html: string }[] | Promise<{ title: string; html: string }[]>
|
|
948
|
+
}): () => void
|
|
949
|
+
/**
|
|
950
|
+
* Imports a whole book from another app's file or folder, such as a Scrivener project or a Plottr outline. It
|
|
951
|
+
* appears in File → Import, and on the welcome screen while the plugin is on.
|
|
952
|
+
*
|
|
953
|
+
* The app asks for the file or folder, passes it to `import`, and shows the writer the result. The writer can
|
|
954
|
+
* then make it a new book or add it to the open one. To explain why a file can't be read, throw an Error: the
|
|
955
|
+
* writer sees its message. This needs no permission, because it reads only what the writer picked. API 7.
|
|
956
|
+
*/
|
|
957
|
+
addBookImporter(importer: {
|
|
958
|
+
id: string
|
|
959
|
+
/** The name in File → Import: "Scrivener Project". */
|
|
960
|
+
name: string
|
|
961
|
+
/** The app name for "Import from …" on the welcome screen: "Scrivener". Defaults to `name`. */
|
|
962
|
+
from?: string
|
|
963
|
+
/** The file extensions without the dot: ["pltr"]. For a folder, use the folder's extension: ["scriv"]. */
|
|
964
|
+
extensions: string[]
|
|
965
|
+
/** True if it reads a folder (a .scriv), not a file. Phones can't choose folders, so the writer chooses a zip of it. */
|
|
966
|
+
folder?: boolean
|
|
967
|
+
import: (source: ImportSource) => ImportedBook | Promise<ImportedBook>
|
|
968
|
+
}): () => void
|
|
969
|
+
/**
|
|
970
|
+
* Adds a card to the welcome screen's dashboard, shown while no book is open. `size` is 'half' (the default) or
|
|
971
|
+
* 'full' width. Cards are sorted by `order`, lowest first (default 100). These only set where a card starts: the
|
|
972
|
+
* writer can move it and change its width later. Window only. API 2.
|
|
973
|
+
*/
|
|
974
|
+
addDashboardWidget(widget: {
|
|
975
|
+
id: string
|
|
976
|
+
name: string
|
|
977
|
+
size?: 'half' | 'full'
|
|
978
|
+
order?: number
|
|
979
|
+
render: () => ReactNode
|
|
980
|
+
}): () => void
|
|
981
|
+
/** Adds settings that the app draws in Settings → Plugins. Read their values from `this.settings`. */
|
|
982
|
+
addSettings(fields: SettingField[]): () => void
|
|
983
|
+
/** Adds a settings panel that the plugin draws itself. Window only. */
|
|
984
|
+
addSettingsPanel(render: () => ReactNode): () => void
|
|
985
|
+
onSettingsChange(listener: (settings: Record<string, unknown>) => void): void
|
|
986
|
+
updateSettings(patch: Record<string, unknown>): Promise<void>
|
|
987
|
+
on(event: PluginEvent, handler: (arg: string | null) => void): void
|
|
988
|
+
/**
|
|
989
|
+
* Registers a handler for a moment when the app waits for plugins:
|
|
990
|
+
* - 'session-end': a writing session ended, after 30 minutes without writing or because the book is closing.
|
|
991
|
+
* - 'copy-due': the writing timer is due and something has changed, or a new book was created.
|
|
992
|
+
* - 'project-closing': a book is closing, or the app is quitting.
|
|
993
|
+
*
|
|
994
|
+
* If the handler returns a promise, the app waits for it for up to 30 seconds (10 for 'session-end'), then carries
|
|
995
|
+
* on. A plugin has one handler per event: calling `during` again for the same event replaces it. API 10.
|
|
996
|
+
*/
|
|
997
|
+
during(event: 'session-end' | 'copy-due' | 'project-closing', handler: (info: WaitInfo) => unknown): () => void
|
|
998
|
+
/**
|
|
999
|
+
* Provides a version history of the project, which the app shows in Book → Versions & Backups and in a document's
|
|
1000
|
+
* history. The app does the drawing, so this works in a sandboxed plugin. The plugin implements:
|
|
1001
|
+
* - `list`: the versions, newest first. With `file` (a path in the project's folder), only those that changed it.
|
|
1002
|
+
* - `read`: a file's text in a version.
|
|
1003
|
+
* - `save`: saves a version with the writer's message. Returns false if nothing has changed since the last one.
|
|
1004
|
+
* - `status` (optional): a message for the writer, such as a failed backup, or null.
|
|
1005
|
+
*
|
|
1006
|
+
* The app handles restoring, and always takes a snapshot of the document first. If more than one plugin provides a
|
|
1007
|
+
* history, the app shows the first. API 10.
|
|
1008
|
+
*/
|
|
1009
|
+
addVersionHistory(history: {
|
|
1010
|
+
id: string
|
|
1011
|
+
list(file?: string): Promise<VersionEntry[]>
|
|
1012
|
+
read(version: string, file: string): Promise<string>
|
|
1013
|
+
save(message: string): Promise<boolean>
|
|
1014
|
+
status?(): Promise<{ text: string; problem?: boolean } | null>
|
|
1015
|
+
}): () => void
|
|
1016
|
+
/** Tells the app that the list of versions changed, so it reloads what it shows. API 10. */
|
|
1017
|
+
versionsChanged(): void
|
|
1018
|
+
/** The plugin's own data on this computer. For data stored in the book, see app.project.getData. */
|
|
1019
|
+
loadData(): Promise<unknown>
|
|
1020
|
+
saveData(data: unknown): Promise<void>
|
|
1021
|
+
}
|