@scm-js/plugin-api 1.13.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 +155 -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.
2147
2183
  */
2148
- open(file: File | Blob | Uint8Array, fileName?: string): Promise<boolean>;
2184
+ list(): OpenDocumentInfo[];
2149
2185
  /**
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
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).
2200
+ */
2201
+ open(file: File | Blob | Uint8Array, fileName?: string, options?: OpenDocumentOptions): Promise<boolean>;
2202
+ /**
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
@@ -4121,6 +4177,79 @@ export interface BusyHandle {
4121
4177
  /** Uncover the box. Safe to call twice. */
4122
4178
  done(): void;
4123
4179
  }
4180
+ export interface StepsOptions extends WidgetOptions {
4181
+ /**
4182
+ * While the list is `running`, show only its last this many rows; the rest come back
4183
+ * when it stops. For a list that grows past what a panel can hold while it is watched.
4184
+ * 0, the default, shows every row.
4185
+ */
4186
+ tail?: number;
4187
+ }
4188
+ export interface StepOptions {
4189
+ /** A character in front of the label, in the list's own vocabulary: ✎ for a change, ▸ for a read. */
4190
+ icon?: string;
4191
+ /** The row's tooltip. */
4192
+ title?: string;
4193
+ /** Begin running (a ring) rather than pending (a hollow mark). */
4194
+ running?: boolean;
4195
+ }
4196
+ /** One row of a `steps` list. Each state takes the detail shown dim after the label. */
4197
+ export type StepHandle = {
4198
+ readonly element: HTMLElement;
4199
+ /** Rename the row (a step named before its arguments were known), and its tooltip. */
4200
+ set(label: string, title?: string): void;
4201
+ start(detail?: string): void;
4202
+ done(detail?: string): void;
4203
+ fail(detail?: string): void;
4204
+ skip(detail?: string): void;
4205
+ /** Change the detail and nothing else — a clock ticking beside a running step. */
4206
+ detail(text: string): void;
4207
+ /** Something under the label — a thumbnail, a line of output. */
4208
+ append(node: Node): void;
4209
+ };
4210
+ /**
4211
+ * A list of steps: one row per unit of work, each pending, running, done, failed or
4212
+ * skipped, with a detail after its label and a mark at its end. What a builder shows
4213
+ * while it builds, and what a tool-using assistant shows while it works.
4214
+ */
4215
+ export type StepsElement = HTMLElement & {
4216
+ add(label: string, options?: StepOptions): StepHandle;
4217
+ /**
4218
+ * A line between rows that is not a step — an assistant's words between its tool
4219
+ * calls. `at` puts it before the row at that index; without it, at the end.
4220
+ */
4221
+ note(content: string | Node, at?: number): HTMLElement;
4222
+ /** Rows and notes so far, for `note`'s `at`. */
4223
+ size(): number;
4224
+ /** Steps so far (rows, not notes). */
4225
+ count(): number;
4226
+ /** Whether work is running: while it is, the `tail` window applies. */
4227
+ running(on: boolean): void;
4228
+ };
4229
+ export interface FoldOptions extends WidgetOptions {
4230
+ /** The line to begin with. */
4231
+ text?: string;
4232
+ /** Open to begin with. */
4233
+ open?: boolean;
4234
+ /** Start with a ring for a mark. */
4235
+ busy?: boolean;
4236
+ }
4237
+ /**
4238
+ * A block that folds to one line: a mark, the line, a control at its end, and a body.
4239
+ * For work worth a line when it is done and a list while it runs — one turn of an
4240
+ * assistant, a pass over the map — and for anything long that most readers skip, such
4241
+ * as a model's reasoning.
4242
+ */
4243
+ export type FoldElement = HTMLDetailsElement & {
4244
+ /** Where the content goes. */
4245
+ readonly body: HTMLElement;
4246
+ /** The line: text, or text and nodes. */
4247
+ set(...content: (string | Node)[]): void;
4248
+ /** The mark in front of the line: `"busy"` for a ring, a character (✓, ✗) in a colour, or null for none. */
4249
+ mark(sym: string | null, kind?: "ok" | "warn" | "error"): void;
4250
+ /** A control at the end of the line — an Undo — whose click does not fold the block; null takes it away. */
4251
+ action(node: HTMLElement | null): void;
4252
+ };
4124
4253
  /**
4125
4254
  * Buttons, fields, forms and lists in the editor's own styles, as plain DOM. A plugin
4126
4255
  * dialog built from these looks like a built-in one; `el` is the escape hatch for
@@ -4165,6 +4294,10 @@ export interface WidgetsApi {
4165
4294
  * Calling it again on a covered box only changes the label.
4166
4295
  */
4167
4296
  busy(target: HTMLElement, options?: BusyOptions | string): BusyHandle;
4297
+ /** A list of steps, each pending → running → done / failed / skipped, with a detail. */
4298
+ steps(options?: StepsOptions): StepsElement;
4299
+ /** A block folded to one line — a mark, a line that can change, a control at its end — over a body. */
4300
+ fold(options?: FoldOptions): FoldElement;
4168
4301
  }
4169
4302
  export type TopMenu = "File" | "Edit" | "View" | "Layer" | "Scenario" | "Triggers" | "Tools" | "Plugins" | "Help";
4170
4303
  /**
@@ -4290,10 +4423,18 @@ export type DocumentChangeReason =
4290
4423
  /** File ▸ Close: `document.isOpen()` is now false. */
4291
4424
  | "close"
4292
4425
  /** The open map parsed again from edited bytes — a `document.sections` write, by any plugin. */
4293
- | "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";
4294
4433
  export interface DocumentEvent {
4295
4434
  reason: DocumentChangeReason;
4296
4435
  fileName: string | null;
4436
+ /** `document.id()` after the change: the map now in front, or null after a close. */
4437
+ id: number | null;
4297
4438
  }
4298
4439
  /**
4299
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.13.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",