@scm-js/plugin-api 1.14.0 → 1.15.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 (2) hide show
  1. package/index.d.ts +78 -14
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1776,6 +1776,13 @@ export interface Preferences {
1776
1776
  splash: boolean;
1777
1777
  /** Ask before closing or replacing a map with unsaved changes. */
1778
1778
  confirmClose: boolean;
1779
+ /**
1780
+ * Open each map beside the ones already open, in its own tab, rather than in place of
1781
+ * the open one. Off is StarEdit's one map at a time: Open and New replace the map, asking
1782
+ * about unsaved changes first. Either way the blank map the editor starts on, untouched,
1783
+ * is replaced by the first map opened rather than kept beside it.
1784
+ */
1785
+ multipleMaps: boolean;
1779
1786
  /** What File ▸ New and the startup map start with. */
1780
1787
  newMap: {
1781
1788
  tileset: TilesetId;
@@ -2070,6 +2077,29 @@ export interface ResizeDocumentOptions {
2070
2077
  /** Pull locations that hang past the new edge back inside; default true. */
2071
2078
  clampLocations?: boolean;
2072
2079
  }
2080
+ /**
2081
+ * Where a map opened or created goes. `"new"` opens it beside the open one, which stays
2082
+ * open behind it; `"current"` opens it in place of the open one, through the unsaved-changes
2083
+ * gate. Omitted, the editor follows its preference (several maps at once, on by default),
2084
+ * except that the untouched blank map it started on is always replaced.
2085
+ */
2086
+ export type OpenInto = "new" | "current";
2087
+ export interface OpenDocumentOptions {
2088
+ into?: OpenInto;
2089
+ }
2090
+ /** One open map, as `document.list()` reports it. `active` marks the one in front — the one every other call reads and writes. */
2091
+ export interface OpenDocumentInfo {
2092
+ /** Stable for the map's life in this session; never reused. */
2093
+ id: number;
2094
+ /** The scenario's name. */
2095
+ name: string;
2096
+ fileName: string | null;
2097
+ tileset: TilesetId;
2098
+ width: number;
2099
+ height: number;
2100
+ modified: boolean;
2101
+ active: boolean;
2102
+ }
2073
2103
  /** File ▸ New's form: size, tileset, and the two strings the dialog asks for. */
2074
2104
  export interface NewDocumentOptions {
2075
2105
  width: number;
@@ -2077,6 +2107,8 @@ export interface NewDocumentOptions {
2077
2107
  tileset: TilesetId;
2078
2108
  /** `Untitled Scenario` when omitted. */
2079
2109
  name?: string;
2110
+ /** Beside the open map or in place of it; see `OpenInto`. */
2111
+ into?: OpenInto;
2080
2112
  description?: string;
2081
2113
  /** ISOM id of the terrain to fill with; the tileset's default ground when omitted. */
2082
2114
  terrainId?: number;
@@ -2139,18 +2171,39 @@ export interface DocumentApi {
2139
2171
  /** The undo and redo stacks' tops — the labels the Edit menu shows — and their depths, without moving anything. */
2140
2172
  history(): DocumentHistory;
2141
2173
  /**
2142
- * Open a map file (`.scx` / `.scm` / `.chk`) in place of the current one, the way
2143
- * File ▸ Open does: when the open map has unsaved changes and Preferences say to ask,
2144
- * the Close Scenario dialog comes first and the user may cancel. Resolves true once
2145
- * the file is the open document, false when the user kept the current map or the
2146
- * file could not be read (the status bar says why).
2174
+ * The id of the map in front — the one `info()`, `scenario()` and every write are
2175
+ * about — or null with no map. Stable for the map's life, so a plugin can key what it
2176
+ * keeps per map on it. (Null too for a scenario a test put in place without the editor.)
2177
+ */
2178
+ id(): number | null;
2179
+ /**
2180
+ * Every open map, in the order the editor lists them, the one in front marked `active`.
2181
+ * Empty with no map. The list changes only through `open`, `create`, `activate` and
2182
+ * `close` (by any plugin or the user), each of which fires the `"document"` event.
2183
+ */
2184
+ list(): OpenDocumentInfo[];
2185
+ /**
2186
+ * Bring an open map to the front, as clicking its tab does: its history, selections and
2187
+ * view come back as they were left, and the `"document"` event fires with reason
2188
+ * `"switch"`. Nothing is re-read. True once it is in front (at once, when it already
2189
+ * was); false for an id that is not open. Call it for something the user asked for —
2190
+ * the map changing under someone mid-stroke is not a thing a plugin should do on its own.
2191
+ */
2192
+ activate(id: number): boolean;
2193
+ /**
2194
+ * Open a map file (`.scx` / `.scm` / `.chk`), the way File ▸ Open does: beside the open
2195
+ * map or in place of it as `options.into` (or, omitted, the editor's preference) says.
2196
+ * In place of a map with unsaved changes, when Preferences say to ask, the Close
2197
+ * Scenario dialog comes first and the user may cancel. Resolves true once the file is
2198
+ * the map in front, false when the user kept the current map or the file could not be
2199
+ * read (the status bar says why).
2147
2200
  */
2148
- open(file: File | Blob | Uint8Array, fileName?: string): Promise<boolean>;
2201
+ open(file: File | Blob | Uint8Array, fileName?: string, options?: OpenDocumentOptions): Promise<boolean>;
2149
2202
  /**
2150
- * A blank map in place of the current one, the way File ▸ New makes one: flat ground
2151
- * of the tileset's default terrain (or `terrainId`), an ISOM lattice to match, every
2152
- * section a fresh map needs. Goes through the same unsaved-changes gate as `open`.
2153
- * Resolves true once the new map is the open document, false when the user kept the
2203
+ * A blank map the way File ▸ New makes one: flat ground of the tileset's default terrain
2204
+ * (or `terrainId`), an ISOM lattice to match, every section a fresh map needs. Beside
2205
+ * the open map or in place of it as `open` decides, through the same unsaved-changes
2206
+ * gate. Resolves true once the new map is in front, false when the user kept the
2154
2207
  * current one.
2155
2208
  */
2156
2209
  create(options: NewDocumentOptions): Promise<boolean>;
@@ -2170,10 +2223,13 @@ export interface DocumentApi {
2170
2223
  /** File ▸ Save As (or Save Copy As with `copy`): the Save dialog, resolving as `save` does. */
2171
2224
  saveAs(options?: SaveDocumentOptions): Promise<boolean>;
2172
2225
  /**
2173
- * File ▸ Close: through the same unsaved-changes gate as `open`. Resolves true once the
2174
- * map is closed (`isOpen()` is then false), false when the user kept it.
2226
+ * File ▸ Close: the map in front, or the open map `id` names, through the same
2227
+ * unsaved-changes gate as `open` (a map behind is brought to the front first, so the
2228
+ * question is about what the user sees). Resolves true once the map is closed — another
2229
+ * open map is then in front, or `isOpen()` is false — false when the user kept it or no
2230
+ * map has that id.
2175
2231
  */
2176
- close(): Promise<boolean>;
2232
+ close(id?: number): Promise<boolean>;
2177
2233
  /**
2178
2234
  * A picture of the map as File ▸ Export ▸ Image draws it, as a PNG. `pixelsPerTile`
2179
2235
  * is the one dial (32 is the game's art 1:1, 1 is a minimap); the other options
@@ -4367,10 +4423,18 @@ export type DocumentChangeReason =
4367
4423
  /** File ▸ Close: `document.isOpen()` is now false. */
4368
4424
  | "close"
4369
4425
  /** The open map parsed again from edited bytes — a `document.sections` write, by any plugin. */
4370
- | "replace";
4426
+ | "replace"
4427
+ /**
4428
+ * Another open map came to the front — a tab clicked, `document.activate`, or the map
4429
+ * in front closed with others still open. Nothing was read or written; the map that
4430
+ * was in front is still open behind, as it was. `id` says which map is in front now.
4431
+ */
4432
+ | "switch";
4371
4433
  export interface DocumentEvent {
4372
4434
  reason: DocumentChangeReason;
4373
4435
  fileName: string | null;
4436
+ /** `document.id()` after the change: the map now in front, or null after a close. */
4437
+ id: number | null;
4374
4438
  }
4375
4439
  /**
4376
4440
  * Listeners are notifications: they run after the change, in the order the plugins were
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-js/plugin-api",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",