@black-studio/plugin 1.1.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.
Files changed (3) hide show
  1. package/README.md +28 -1
  2. package/index.d.ts +48 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -261,6 +261,23 @@ 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
283
  - **The navigator:** `create(type, title, parentId?)`, `rename`,
@@ -397,6 +414,13 @@ const id = await this.app.project.create({ kind: 'faction' }, 'The Guild')
397
414
  - **A kind can be turned off** by defining it again with `hidden: true`, for
398
415
  a writer who doesn't want it. Its entries aren't shown and none can be
399
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.
400
424
  - **Writers can add fields** of their own for each kind in Templates. New
401
425
  entries start with your fields and then theirs.
402
426
  - **Where your plugin isn't there** (not installed, turned off, or unable
@@ -554,7 +578,10 @@ Suggesters work in sandboxed plugins too.
554
578
  - its `title`, labels, statuses and storylines;
555
579
  - the items in each part of the navigator (`manuscript`, `characters`,
556
580
  `places`, `notes`, `research`, `trash`), each with its text as HTML,
557
- 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);
558
585
  - beats on the storylines.
559
586
 
560
587
  Items refer to each other (a scene's cast and place, a beat's scene) by ids
package/index.d.ts CHANGED
@@ -137,7 +137,7 @@ export type NodeType = 'text' | 'folder' | 'character' | 'place' | 'note' | 'res
137
137
  /** The icons a kind of entry may use, from the app's own. API 12. */
138
138
  export type KindIcon =
139
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'
140
+ | 'mountain' | 'globe' | 'map' | 'compass' | 'paw' | 'bird' | 'fish' | 'bug' | 'users' | 'user' | 'map-pin' | 'languages' | 'feather' | 'hourglass' | 'star' | 'sparkles'
141
141
 
142
142
  /** A kind of entry, as a plugin defines it (defineKind, API 12). */
143
143
  export interface KindDefinition {
@@ -157,13 +157,20 @@ export interface KindDefinition {
157
157
  * kind is defined again without it. A section whose kinds are all off isn't shown.
158
158
  */
159
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'
160
167
  }
161
168
 
162
169
  export interface NodeInfo {
163
170
  id: string
164
171
  title: string
165
172
  type: NodeType
166
- /** An entry's kind, "<plugin id>:<kind id>". API 12. */
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. */
167
174
  kind?: string
168
175
  parentId: string | null
169
176
  children: string[]
@@ -287,7 +294,12 @@ export interface App {
287
294
  /** The manuscript's documents, in reading order. */
288
295
  manuscript(): Promise<string[]>
289
296
  selected(): Promise<string | null>
290
- select(id: string): Promise<void>
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>
291
303
  /** A document's text as HTML. */
292
304
  read(id: string): Promise<string>
293
305
  /** A document's text as plain text. */
@@ -412,6 +424,17 @@ export interface App {
412
424
  confirm(title: string, detail?: string, confirmLabel?: string): Promise<boolean>
413
425
  /** Shows one of this plugin's views. Window only. */
414
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
415
438
  /** Shows this plugin's settings. */
416
439
  openSettings(): void
417
440
  /** Opens a dialog that the plugin draws itself. Returns a function that closes it. Window only. */
@@ -724,9 +747,10 @@ export interface SettingField {
724
747
  /**
725
748
  * `item-data-change` (API 11): this plugin's data for an item changed, here or on another device or by a co-author.
726
749
  * 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.
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.
728
752
  */
729
- export type PluginEvent = 'project-open' | 'project-close' | 'selection-change' | 'doc-change' | 'nodes-change' | 'item-data-change' | 'shared-data-change'
753
+ export type PluginEvent = 'project-open' | 'project-close' | 'selection-change' | 'doc-change' | 'nodes-change' | 'item-data-change' | 'shared-data-change' | 'pick-change'
730
754
 
731
755
  /** A suggestion offered as the writer types after a trigger. */
732
756
  export interface Suggestion {
@@ -778,8 +802,14 @@ export interface ImportedItem {
778
802
  /** An entry's kind: the `id` of one of the book's `kinds` (API 12). */
779
803
  kind?: string
780
804
  title: string
781
- /** The text as HTML: paragraphs, headings, emphasis, lists, quotes, and <hr> for a scene break. */
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
+ */
782
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 }[]
783
813
  synopsis?: string
784
814
  notes?: string
785
815
  keywords?: string[]
@@ -864,7 +894,18 @@ export declare class Plugin {
864
894
  run: () => void | Promise<void>
865
895
  }): () => void
866
896
  /** Adds a view beside the corkboard and outliner. Window only. */
867
- addView(view: { id: string; name: string; icon?: ComponentType<{ size?: number }>; render: () => ReactNode }): () => void
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
868
909
  /** Adds a tab to the inspector, for items where `when` returns true. Window only. */
869
910
  addInspectorTab(tab: {
870
911
  id: string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@black-studio/plugin",
3
- "version": "1.1.0",
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/",