@scm-js/plugin-api 1.9.0 → 1.10.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/index.d.ts +61 -2
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1810,7 +1810,20 @@ export interface Preferences {
|
|
|
1810
1810
|
checkOnStart: boolean;
|
|
1811
1811
|
nightly: boolean;
|
|
1812
1812
|
};
|
|
1813
|
+
/**
|
|
1814
|
+
* What to do when an installed plugin has a newer release than the one running
|
|
1815
|
+
* (`plugins/updates.ts`). `notify` looks a few seconds after the plugins start and
|
|
1816
|
+
* raises a notice with a button to the rows offering the update; `manual` asks nothing
|
|
1817
|
+
* until **Check for update** is pressed on a row; `auto` installs what it finds, for the
|
|
1818
|
+
* plugins the user added — a default moves with the editor's own releases and is only
|
|
1819
|
+
* ever named in the notice. Every mode leaves the confirmation on a row's button alone.
|
|
1820
|
+
*/
|
|
1821
|
+
plugins: {
|
|
1822
|
+
updates: PluginUpdateMode;
|
|
1823
|
+
};
|
|
1813
1824
|
}
|
|
1825
|
+
/** See `Preferences.plugins.updates`. */
|
|
1826
|
+
export type PluginUpdateMode = "notify" | "manual" | "auto";
|
|
1814
1827
|
/**
|
|
1815
1828
|
* The version a host provides; a manifest that asks for a newer one is refused. It stays
|
|
1816
1829
|
* at 1 while the API is only used by the plugins in the scm-js organisation and grows
|
|
@@ -1954,6 +1967,8 @@ export interface PluginApi {
|
|
|
1954
1967
|
/** Key combinations, tried before the editor's own and never while a text field has focus. */
|
|
1955
1968
|
readonly hotkeys: HotkeyApi;
|
|
1956
1969
|
readonly commands: CommandsApi;
|
|
1970
|
+
/** Live objects one plugin holds out for others to use, found by name and watched for arriving. */
|
|
1971
|
+
readonly services: ServicesApi;
|
|
1957
1972
|
readonly events: EventsApi;
|
|
1958
1973
|
/**
|
|
1959
1974
|
* A small key-value store of the plugin's own, kept in the browser's local storage under
|
|
@@ -2806,6 +2821,46 @@ export interface CommandsApi {
|
|
|
2806
2821
|
/** Every command registered by every plugin. */
|
|
2807
2822
|
list(): CommandInfo[];
|
|
2808
2823
|
}
|
|
2824
|
+
export interface ServiceInfo {
|
|
2825
|
+
id: string;
|
|
2826
|
+
pluginId: string;
|
|
2827
|
+
version: number;
|
|
2828
|
+
}
|
|
2829
|
+
export interface ServiceOptions {
|
|
2830
|
+
/** The provider's version of the contract, 1 by default; a consumer that needs a newer one checks `ServiceInfo.version`. */
|
|
2831
|
+
version?: number;
|
|
2832
|
+
}
|
|
2833
|
+
/**
|
|
2834
|
+
* A command is one thing to do; a service is a thing to *hold* — an account another
|
|
2835
|
+
* plugin signs in through, a connection, a catalogue. A plugin provides one live object
|
|
2836
|
+
* under a name and every other plugin reaches it by that name, whatever order they were
|
|
2837
|
+
* activated in: `watch` answers at once with what is there and again whenever the
|
|
2838
|
+
* provider arrives or goes.
|
|
2839
|
+
*
|
|
2840
|
+
* The object's shape is the provider's to publish (a `contract.d.ts` in its repository,
|
|
2841
|
+
* taken as a dev dependency and imported with `import type`, which is erased before the
|
|
2842
|
+
* loader sees it); the editor never reads it. A name without a dot is namespaced under
|
|
2843
|
+
* the plugin (`"account"` → `"scmjs-dev.account"`); one with a dot is taken as it is.
|
|
2844
|
+
*
|
|
2845
|
+
* @example
|
|
2846
|
+
* // The provider:
|
|
2847
|
+
* api.services.provide("account", accountService);
|
|
2848
|
+
* // A consumer:
|
|
2849
|
+
* api.services.watch<AccountService>("scmjs-dev.account", (account) => {
|
|
2850
|
+
* if (account) useSessionFrom(account); else useOwnSignIn();
|
|
2851
|
+
* });
|
|
2852
|
+
*/
|
|
2853
|
+
export interface ServicesApi {
|
|
2854
|
+
/** Hold an object out under a name. Providing the same name again replaces it; the Disposable withdraws it. */
|
|
2855
|
+
provide<T extends object>(id: string, service: T, options?: ServiceOptions): Disposable;
|
|
2856
|
+
/** The object under a name, or null when no plugin provides it. */
|
|
2857
|
+
get<T extends object>(id: string): T | null;
|
|
2858
|
+
has(id: string): boolean;
|
|
2859
|
+
/** Called at once with the current object (or null) and again on every change of provider. */
|
|
2860
|
+
watch<T extends object>(id: string, listener: (service: T | null, info: ServiceInfo | null) => void): Disposable;
|
|
2861
|
+
/** Every service provided by every plugin. */
|
|
2862
|
+
list(): ServiceInfo[];
|
|
2863
|
+
}
|
|
2809
2864
|
/** A picture the editor already has: the canvas it draws from, and its size in pixels. */
|
|
2810
2865
|
export interface PluginImage {
|
|
2811
2866
|
image: HTMLCanvasElement;
|
|
@@ -4068,9 +4123,11 @@ export interface WidgetsApi {
|
|
|
4068
4123
|
export type TopMenu = "File" | "Edit" | "View" | "Layer" | "Scenario" | "Triggers" | "Tools" | "Plugins" | "Help";
|
|
4069
4124
|
/**
|
|
4070
4125
|
* A top-level menu, or a submenu by label: `"File/Import"`. A last segment that names no
|
|
4071
|
-
* submenu gets one of the plugin's own, at the end of the menu (`"Tools/AI"`)
|
|
4126
|
+
* submenu gets one of the plugin's own, at the end of the menu (`"Tools/AI"`), and a
|
|
4127
|
+
* first segment that names no top-level menu gets one made for the plugin, placed before
|
|
4128
|
+
* Help (`"Account"`).
|
|
4072
4129
|
*/
|
|
4073
|
-
export type MenuPath = TopMenu | `${TopMenu}/${string}
|
|
4130
|
+
export type MenuPath = TopMenu | `${TopMenu}/${string}` | (string & {});
|
|
4074
4131
|
export interface MenuItemSpec {
|
|
4075
4132
|
label: string;
|
|
4076
4133
|
/** Display only — bind the key with `hotkeys.add`. */
|
|
@@ -4174,6 +4231,8 @@ export type PluginEvent =
|
|
|
4174
4231
|
| "file"
|
|
4175
4232
|
/** A plugin registered or removed a command — how a plugin learns that one it calls by id has arrived. */
|
|
4176
4233
|
| "commands"
|
|
4234
|
+
/** A plugin provided or withdrew a service — `services.watch` is the usual way to hear this for one name. */
|
|
4235
|
+
| "services"
|
|
4177
4236
|
/** The game data source changed: installed, switched to another data set, or a copy removed. `gameData.source()` says what it is now. */
|
|
4178
4237
|
| "gameData";
|
|
4179
4238
|
/** Why the document changed. */
|