@black-studio/plugin 1.1.0 → 1.3.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 +39 -1
  2. package/index.d.ts +86 -10
  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
@@ -563,6 +590,17 @@ Suggesters work in sandboxed plugins too.
563
590
  why a file can't be read, throw an Error. Book importers need no
564
591
  permission and work in sandboxed plugins. They need `"apiVersion": 7`. The
565
592
  Scrivener and Plottr imports on the list are built this way.
593
+
594
+ For a file that holds several books, `import` can return a series instead
595
+ (`ImportedSeries`, API 13): its `books`, each an `ImportedBook` with an `id`;
596
+ the `characters` and `places` they share, which go in the series bible; the
597
+ `storylines` through the series, with what each does in each book (`beats`,
598
+ by the book's `id`); and the series' `notes`. Bläck Studio makes it a new
599
+ series, and each book gets a sheet linked to the bible for every shared
600
+ character and place its scenes name (or its `shared` list names). Only
601
+ Bläck Studio with API 13 or later reads a series, so check
602
+ `this.app.apiVersion` and return a single book to older versions, as the
603
+ Plottr import does. Its manifest can then keep `"apiVersion": 7`.
566
604
  - **`styles.css`:** if it's next to the manifest, Bläck Studio loads it with
567
605
  the plugin and removes it when the plugin is removed. Put your plugin's id
568
606
  in your class names, so they don't clash with Bläck Studio's or another
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 {
@@ -765,7 +789,7 @@ export interface ImportSource {
765
789
  }
766
790
 
767
791
  /**
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
792
+ * An item in an imported book's navigator. `id` is only for other items in the import to refer to it, such as a
769
793
  * scene's cast or a beat's scene. The app assigns its own id. API 7.
770
794
  */
771
795
  export interface ImportedItem {
@@ -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[]
@@ -833,6 +863,39 @@ export interface ImportedBook {
833
863
  beats?: { storyline: string; scene?: string; title: string; description?: string }[]
834
864
  /** Kinds of entry, as you'd give them to defineKind (API 12). Items use them with `type: 'entry'` and `kind`. */
835
865
  kinds?: KindDefinition[]
866
+ /** In a series: the book's id in the import, for the series' storylines to refer to it (API 13). */
867
+ id?: string
868
+ /**
869
+ * In a series: the shared characters and places this book has a sheet for, by their ids in the series, besides
870
+ * those its scenes name in `cast` and `place` (API 13).
871
+ */
872
+ shared?: string[]
873
+ }
874
+
875
+ /**
876
+ * What a book importer returns for a file that holds several books, such as a Plottr file of a series (API 13).
877
+ * Bläck Studio makes it a new project with one book for each of `books`, in order. The writer can't add it to the
878
+ * open book.
879
+ *
880
+ * - `characters` and `places` are shared in the series bible. Each book gets a sheet, linked to the bible, for every
881
+ * one its scenes name in `cast` and `place`, and for those its `shared` list names. A book's own `characters` and
882
+ * `places` stay in that book.
883
+ * - `storylines` run through the series. `beats` says what each one does in each book, by the book's `id`.
884
+ * - `notes` are the series' notes, as plain text.
885
+ *
886
+ * Only Bläck Studio with API 13 or later reads it. Check `app.apiVersion`, and return an ImportedBook to an older
887
+ * version.
888
+ */
889
+ export interface ImportedSeries {
890
+ title: string
891
+ author?: string
892
+ /** A summary of what was imported, shown in the dialog before the writer chooses. */
893
+ about?: string
894
+ books: ImportedBook[]
895
+ characters?: ImportedItem[]
896
+ places?: ImportedItem[]
897
+ storylines?: { name: string; color?: string; beats?: Record<string, string> }[]
898
+ notes?: { title: string; text: string }[]
836
899
  }
837
900
 
838
901
  export declare class Plugin {
@@ -864,7 +927,18 @@ export declare class Plugin {
864
927
  run: () => void | Promise<void>
865
928
  }): () => void
866
929
  /** Adds a view beside the corkboard and outliner. Window only. */
867
- addView(view: { id: string; name: string; icon?: ComponentType<{ size?: number }>; render: () => ReactNode }): () => void
930
+ addView(view: {
931
+ id: string
932
+ name: string
933
+ icon?: ComponentType<{ size?: number }>
934
+ render: () => ReactNode
935
+ /**
936
+ * The inspector beside the view. It shows what the writer picks in the view with `select`, and stays closed until
937
+ * something is picked. `hint` is what the status bar says meanwhile, such as "Click a card to show it beside the
938
+ * view". `false` is for a view with nothing to pick, which has no inspector. API 12.
939
+ */
940
+ inspector?: false | { hint: string }
941
+ }): () => void
868
942
  /** Adds a tab to the inspector, for items where `when` returns true. Window only. */
869
943
  addInspectorTab(tab: {
870
944
  id: string
@@ -913,7 +987,7 @@ export declare class Plugin {
913
987
  refreshHighlights(): void
914
988
  /** Adds TipTap extensions to every editor. Window only. */
915
989
  registerEditorExtension(extension: AnyExtension | AnyExtension[]): () => void
916
- /** Adds a panel to the sidebar, beside the binder. Window only. */
990
+ /** Adds a panel to the sidebar, beside the navigator. Window only. */
917
991
  addSidebarPanel(panel: { id: string; name: string; render: () => ReactNode }): () => void
918
992
  /** Adds a button to the editor's toolbar. In a sandboxed plugin, the icon is text, such as an emoji. */
919
993
  addToolbarButton(button: {
@@ -953,6 +1027,8 @@ export declare class Plugin {
953
1027
  * The app asks for the file or folder, passes it to `import`, and shows the writer the result. The writer can
954
1028
  * 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
1029
  * writer sees its message. This needs no permission, because it reads only what the writer picked. API 7.
1030
+ *
1031
+ * For a file of several books, `import` can return an ImportedSeries instead, which becomes a new series (API 13).
956
1032
  */
957
1033
  addBookImporter(importer: {
958
1034
  id: string
@@ -964,7 +1040,7 @@ export declare class Plugin {
964
1040
  extensions: string[]
965
1041
  /** 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
1042
  folder?: boolean
967
- import: (source: ImportSource) => ImportedBook | Promise<ImportedBook>
1043
+ import: (source: ImportSource) => ImportedBook | ImportedSeries | Promise<ImportedBook | ImportedSeries>
968
1044
  }): () => void
969
1045
  /**
970
1046
  * Adds a card to the welcome screen's dashboard, shown while no book is open. `size` is 'half' (the default) or
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@black-studio/plugin",
3
- "version": "1.1.0",
3
+ "version": "1.3.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/",