@scm-js/plugin-api 1.63.0 → 1.65.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 +31 -23
  2. package/index.d.ts +58 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -11,41 +11,49 @@ npm i -D @scm-js/plugin-api
11
11
  import type { PluginApi } from "@scm-js/plugin-api";
12
12
 
13
13
  export function activate(api: PluginApi) {
14
- api.ui.toast("Hello from a plugin.");
14
+ api.ui.toast({ title: "Hello from a plugin." });
15
15
  }
16
16
  ```
17
17
 
18
- Types only. A plugin imports them with `import type`, which is erased before the editor's
19
- loader ever sees the specifier — which is what lets this be a normal npm dependency
20
- without breaking the rule that a plugin's *runtime* code cannot import packages by name.
18
+ The package has types only. Import them with `import type`. TypeScript removes those imports
19
+ before the editor's loader sees the plugin, so it can be an ordinary npm dependency. A
20
+ plugin's run-time code cannot import packages by name, and everything it needs at run time
21
+ arrives on `api`.
22
+
23
+ ## Where to start
24
+
25
+ - [Plugins](https://docs.scmjs.dev/plugins/) is the author's guide: what a plugin can do and
26
+ how to write, load and publish one.
27
+ - The [API reference](https://docs.scmjs.dev/api/) lists every call, generated from these
28
+ declarations.
29
+ - [plugin-hello-world](https://github.com/scm-js/plugin-hello-world) is the smallest working
30
+ plugin.
21
31
 
22
32
  ## Versions
23
33
 
24
- The major **is** `PLUGIN_API_VERSION`, so `"^1"` is the range to write and it means what
25
- it says: the minor moves whenever the declarations change, and a change that would break a
26
- plugin moves the major and `PLUGIN_API_VERSION` together. The editor's own version is
27
- deliberately not in here — editor 0.1.0 to 0.2.0 is an ordinary release, and semver would
28
- read it as a break.
34
+ The package's major version is `PLUGIN_API_VERSION`, which is 1 and has never changed. Write
35
+ `"^1"` as the range. The minor version moves whenever the declarations change. A change that
36
+ would break a plugin would move the major version and `PLUGIN_API_VERSION` together.
37
+
38
+ The editor's own version is not used here. Going from editor 0.1.0 to 0.2.0 is an ordinary
39
+ release, and semver would read it as a break.
29
40
 
30
- `PLUGIN_API_VERSION` is 1 and has never moved. Your manifest's `"api": 1` is the version
31
- your plugin *needs*; an editor providing an older one refuses to load it.
41
+ Your manifest's `"api": 1` is the version your plugin needs. An editor that provides an
42
+ older one will not load it.
32
43
 
33
44
  ## This repository
34
45
 
35
- **Nothing here is written by hand** except this README and the LICENSE. `index.d.ts` and
36
- `package.json` are generated from `src/plugins/api.ts` in the editor by
37
- `npm run build:plugin-types` and published from there, so the contract has one source and
38
- one copy of its declarations. `main` is the tip; each `v*` tag is a published version.
46
+ Only this README and the LICENSE are written by hand. `index.d.ts` and `package.json` are
47
+ generated from `src/plugins/api.ts` in the editor by `npm run build:plugin-types`, and
48
+ published from there. `main` is the newest version, and each `v*` tag is a published one.
39
49
 
40
- It exists beside the registry as the audit trail behind the tarball, and as the way in for
41
- anyone whose registry the package is not on — `npm i -D github:scm-js/plugin-api#v1.0.0`
42
- works and installs exactly the same two files.
50
+ The repository is the record behind each npm release. It is also a way to install the
51
+ package without the npm registry:
43
52
 
44
- ## What the API covers
53
+ ```sh
54
+ npm i -D github:scm-js/plugin-api#v1.64.0
55
+ ```
45
56
 
46
- [`docs/plugins.md`](https://github.com/scm-js/scm-js/blob/main/docs/plugins.md) in the
47
- editor is the author's guide and the tour of what a plugin can do; this repository is only
48
- the typings for it. [`plugin-hello-world`](https://github.com/scm-js/plugin-hello-world) is
49
- the smallest working example.
57
+ That installs the same files as the registry.
50
58
 
51
59
  MIT, like the editor.
package/index.d.ts CHANGED
@@ -2292,10 +2292,14 @@ export interface Preferences {
2292
2292
  * Tools ▸ Test Map: whether to start the game after writing the map (desktop build), and
2293
2293
  * the game folder to use when the desktop build should not search ("" = search). The
2294
2294
  * browser's folder is a handle in IndexedDB (`services/handleStore.ts`), not here.
2295
+ * `target` is where Test Map, Ctrl+F5 and the toolbar send the map: `"starcraft"`, a
2296
+ * plugin's id for its `ui.testTarget`, or `""` — a plugin's target where there is one
2297
+ * (the browser at scmjs.dev), StarCraft otherwise (`services/testTargets.ts`).
2295
2298
  */
2296
2299
  testMap: {
2297
2300
  launch: boolean;
2298
2301
  dir: string;
2302
+ target: string;
2299
2303
  };
2300
2304
  /**
2301
2305
  * The desktop build's in-app updates (`editor/updates.ts`, `desktop/updater.ts`); the
@@ -2687,7 +2691,8 @@ export interface BuildStepSpec {
2687
2691
  * Build. Return an archive (or a bare scenario) — the editor takes the scenario and any
2688
2692
  * *new* members from it and lays the final file out with the user's save options; the
2689
2693
  * map's own members are written as they were. Throw an `Error` whose message says what
2690
- * is wrong in the user's terms.
2694
+ * is wrong in the user's terms. A plain `Error` is logged as a warning, a refusal the step
2695
+ * meant; anything else thrown (a `TypeError`, a class of your own) is logged as an error.
2691
2696
  */
2692
2697
  run(input: BuildStepInput): Promise<Uint8Array>;
2693
2698
  }
@@ -2707,7 +2712,8 @@ export interface BeforeBuildSpec {
2707
2712
  /**
2708
2713
  * May be asynchronous and may write to the document. A throw does not stop the save:
2709
2714
  * the map is written as it stands and a notice shows the error's message, so word it
2710
- * for the user. Inside it `document.export()` answers the map as it stands, without
2715
+ * for the user. As with a build step, a plain `Error` is logged as a warning and anything
2716
+ * else as an error. Inside it `document.export()` answers the map as it stands, without
2711
2717
  * running anything.
2712
2718
  */
2713
2719
  run(ctx: {
@@ -5427,6 +5433,50 @@ export interface PreferencesPageSpec {
5427
5433
  /** Called by Reset to defaults while the page is the one showing. */
5428
5434
  reset?(): void;
5429
5435
  }
5436
+ /**
5437
+ * Another place Tools ▸ Test Map can send the map — `ui.testTarget`. The editor's own
5438
+ * target is StarCraft (the file written where the game lists it); a target of a plugin's
5439
+ * is a choice beside it on Edit ▸ Preferences ▸ Testing, a Tools menu item of its own
5440
+ * ("Test in …"), and, when the user picks it there, what Test Map, Ctrl+F5 and the
5441
+ * toolbar's Test button do.
5442
+ *
5443
+ * @example
5444
+ * api.ui.testTarget({
5445
+ * label: "This browser",
5446
+ * menuLabel: "Test in Browser",
5447
+ * description: "Plays the map in a tab of its own.",
5448
+ * run: (map) => { const tab = window.open("/play/"); void map.then((m) => m && send(tab, m)); },
5449
+ * });
5450
+ */
5451
+ export interface TestTargetSpec {
5452
+ /** What the choice is called on Preferences ▸ Testing: "This browser". Translated through the plugin's catalogue. */
5453
+ label: string;
5454
+ /** The Tools menu item that tests here whatever the choice is: "Test in Browser". */
5455
+ menuLabel: string;
5456
+ /** A line under the choice saying what happens. */
5457
+ description?: string;
5458
+ /**
5459
+ * Test the map. It is called inside the click or key press itself, before the map is
5460
+ * built, so a target that opens a window can open it at once — a browser lets a click
5461
+ * open a tab, not what follows it later. `map` resolves with the file as Save would
5462
+ * write it (build steps run, always an archive), or null when there is none; it
5463
+ * rejects when the build fails. A promise this returns that rejects is shown to the
5464
+ * user as the reason the test did not start; what it resolves with is the status-bar
5465
+ * line (nothing is shown for none).
5466
+ */
5467
+ run(map: Promise<TestMapFile | null>): void | Promise<string | void>;
5468
+ /**
5469
+ * The target's own settings, drawn under its label on Preferences ▸ Testing — the same
5470
+ * `mount` / `apply` / `reset` as `PreferencesPageSpec`.
5471
+ */
5472
+ settings?: PreferencesPageSpec;
5473
+ }
5474
+ /** The map a test target is handed. */
5475
+ export interface TestMapFile {
5476
+ bytes: Uint8Array;
5477
+ /** The file name the game would list, `.scx` or `.scm`. */
5478
+ name: string;
5479
+ }
5430
5480
  /** What a preferences page's `mount` is handed. */
5431
5481
  export interface PreferencesPageHost {
5432
5482
  readonly plugin: PluginInfo;
@@ -5721,6 +5771,12 @@ export interface UiApi {
5721
5771
  * Returns the registration; it leaves with `dispose()` or the plugin.
5722
5772
  */
5723
5773
  preferencesPage(spec: PreferencesPageSpec): Disposable;
5774
+ /**
5775
+ * A place Test Map can send the map besides StarCraft — see `TestTargetSpec`. One per
5776
+ * plugin: a second registration takes the first one's place. Returns the registration;
5777
+ * it leaves with `dispose()` or the plugin, and Test Map goes back to StarCraft.
5778
+ */
5779
+ testTarget(spec: TestTargetSpec): Disposable;
5724
5780
  /**
5725
5781
  * Take over the pointer on the map until `stop()`, Esc, a right-click, a map change
5726
5782
  * or another tool. One tool runs at a time — starting one stops the previous — and a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-js/plugin-api",
3
- "version": "1.63.0",
3
+ "version": "1.65.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",