@scm-js/plugin-api 1.64.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.
- package/README.md +31 -23
- package/index.d.ts +54 -0
- 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
|
-
|
|
19
|
-
loader
|
|
20
|
-
|
|
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
|
|
25
|
-
|
|
26
|
-
plugin
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
41
|
-
|
|
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
|
-
|
|
53
|
+
```sh
|
|
54
|
+
npm i -D github:scm-js/plugin-api#v1.64.0
|
|
55
|
+
```
|
|
45
56
|
|
|
46
|
-
|
|
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
|
|
@@ -5429,6 +5433,50 @@ export interface PreferencesPageSpec {
|
|
|
5429
5433
|
/** Called by Reset to defaults while the page is the one showing. */
|
|
5430
5434
|
reset?(): void;
|
|
5431
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
|
+
}
|
|
5432
5480
|
/** What a preferences page's `mount` is handed. */
|
|
5433
5481
|
export interface PreferencesPageHost {
|
|
5434
5482
|
readonly plugin: PluginInfo;
|
|
@@ -5723,6 +5771,12 @@ export interface UiApi {
|
|
|
5723
5771
|
* Returns the registration; it leaves with `dispose()` or the plugin.
|
|
5724
5772
|
*/
|
|
5725
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;
|
|
5726
5780
|
/**
|
|
5727
5781
|
* Take over the pointer on the map until `stop()`, Esc, a right-click, a map change
|
|
5728
5782
|
* or another tool. One tool runs at a time — starting one stops the previous — and a
|