@scm-js/plugin-api 1.14.0 → 1.16.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 +124 -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.
2147
2191
  */
2148
- open(file: File | Blob | Uint8Array, fileName?: string): Promise<boolean>;
2192
+ activate(id: number): boolean;
2149
2193
  /**
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
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
@@ -2799,6 +2855,17 @@ export interface ViewApi {
2799
2855
  visible(): Rect;
2800
2856
  /** Scroll so a tile is in the middle of the viewport. */
2801
2857
  center(x: number, y: number): void;
2858
+ /**
2859
+ * Bring a tile rect onto the screen, gliding there by the shortest way rather than
2860
+ * jumping, and leaving the view alone when the rect is already visible. With `fit` the
2861
+ * view zooms out (never in) as far as the rect needs. Resolves once the view is there;
2862
+ * `false` when the user, or another request, moved it first — a plugin that follows its
2863
+ * own work around the map takes that as its cue to stop.
2864
+ *
2865
+ * @example
2866
+ * if (!(await api.view.reveal(rect))) following = false;
2867
+ */
2868
+ reveal(rect: Rect, options?: RevealOptions): Promise<boolean>;
2802
2869
  /** Scroll to an object (and select it, for a unit, sprite or location). */
2803
2870
  goTo(target: GoTo): void;
2804
2871
  /** The tile under the pointer, as the status bar shows it. */
@@ -2823,6 +2890,15 @@ export interface ViewApi {
2823
2890
  */
2824
2891
  flash(target: FlashTarget): void;
2825
2892
  }
2893
+ /** How `view.reveal` brings a rect on screen. */
2894
+ export interface RevealOptions {
2895
+ /** Zoom out to the zoom control's nearest step that fits the rect (plus the margin); never zooms in. Off by default. */
2896
+ fit?: boolean;
2897
+ /** Glide rather than jump. On by default. */
2898
+ animate?: boolean;
2899
+ /** Tiles kept clear between the rect and the viewport's edge when the view has to move. 1 by default. */
2900
+ margin?: number;
2901
+ }
2826
2902
  export interface CommandSpec {
2827
2903
  /**
2828
2904
  * The command's id. One without a dot is namespaced under the plugin
@@ -3603,6 +3679,15 @@ export interface PanelSpec {
3603
3679
  title: string;
3604
3680
  /** In CSS pixels; 260 by default. The panel is as tall as its content, up to the map's height. Ignored when docked. */
3605
3681
  width?: number;
3682
+ /** Floating only: a height in CSS pixels instead of the content's own; the body then scrolls, or fills, as its content asks. */
3683
+ height?: number;
3684
+ /**
3685
+ * Floating only: a grip at the bottom-right corner lets the user resize the panel, and
3686
+ * the size is remembered with the position for the session. The body is a column flex
3687
+ * box, so a root element with `flex: 1; min-height: 0` fills whatever size it has —
3688
+ * what a code editor or a long list beside the map wants.
3689
+ */
3690
+ resizable?: boolean;
3606
3691
  /**
3607
3692
  * Where the panel lives. `"float"` (the default) is a frame over the map the user drags
3608
3693
  * about. `"right"` puts it in the right dock as a panel of its own, under Minimap, Layers
@@ -3819,6 +3904,17 @@ export interface PickOptions {
3819
3904
  /** Shown in the viewport's HUD while the user picks; also the status line. */
3820
3905
  prompt?: string;
3821
3906
  }
3907
+ /** What `ui.pickObject` can pick. */
3908
+ export type PickObjectKind = "unit" | "location";
3909
+ export interface PickObjectOptions extends PickOptions {
3910
+ /** Which kinds count; every kind when omitted. Under the pointer, a unit wins over a location. */
3911
+ kinds?: PickObjectKind[];
3912
+ }
3913
+ /** What the user picked: the record's index in `document.scenario().units` or `.locations`. */
3914
+ export interface PickedObject {
3915
+ kind: PickObjectKind;
3916
+ index: number;
3917
+ }
3822
3918
  export interface PickFilesOptions {
3823
3919
  /** `accept` for the file input, e.g. `"image/*"` or `".png,.jpg"`. */
3824
3920
  accept?: string;
@@ -3901,6 +3997,12 @@ export interface UiApi {
3901
3997
  x: number;
3902
3998
  y: number;
3903
3999
  } | null>;
4000
+ /**
4001
+ * As `pickTile`, for an object: the user clicks a unit or a location. The viewport
4002
+ * outlines and names what is under the pointer as it moves; a click on nothing keeps
4003
+ * picking. Resolves with the kind and the record's index, or null as `pickArea` does.
4004
+ */
4005
+ pickObject(options?: PickObjectOptions): Promise<PickedObject | null>;
3904
4006
  /**
3905
4007
  * Decode a picture: a `File` / `Blob`, a `data:` URL, or an `http(s)` URL (fetched, and
3906
4008
  * when the site refuses cross-origin reads, loaded through an `<img>` with
@@ -4367,10 +4469,18 @@ export type DocumentChangeReason =
4367
4469
  /** File ▸ Close: `document.isOpen()` is now false. */
4368
4470
  | "close"
4369
4471
  /** The open map parsed again from edited bytes — a `document.sections` write, by any plugin. */
4370
- | "replace";
4472
+ | "replace"
4473
+ /**
4474
+ * Another open map came to the front — a tab clicked, `document.activate`, or the map
4475
+ * in front closed with others still open. Nothing was read or written; the map that
4476
+ * was in front is still open behind, as it was. `id` says which map is in front now.
4477
+ */
4478
+ | "switch";
4371
4479
  export interface DocumentEvent {
4372
4480
  reason: DocumentChangeReason;
4373
4481
  fileName: string | null;
4482
+ /** `document.id()` after the change: the map now in front, or null after a close. */
4483
+ id: number | null;
4374
4484
  }
4375
4485
  /**
4376
4486
  * 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.16.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",