@scm-js/plugin-api 1.44.0 → 1.46.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 +45 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -2565,6 +2565,8 @@ export interface DocumentInfo {
|
|
|
2565
2565
|
version: number;
|
|
2566
2566
|
fileName: string | null;
|
|
2567
2567
|
modified: boolean;
|
|
2568
|
+
/** Open to look at only (`OpenDocumentOptions.viewOnly`): every write throws and it is never saved. */
|
|
2569
|
+
viewOnly: boolean;
|
|
2568
2570
|
}
|
|
2569
2571
|
/** What one `document.edit` changed, per list. */
|
|
2570
2572
|
export interface EditResult {
|
|
@@ -2741,6 +2743,20 @@ export interface ResizeDocumentOptions {
|
|
|
2741
2743
|
export type OpenInto = "new" | "current";
|
|
2742
2744
|
export interface OpenDocumentOptions {
|
|
2743
2745
|
into?: OpenInto;
|
|
2746
|
+
/**
|
|
2747
|
+
* Open the map to look at, not to change — a replay's map, a preview. It always opens
|
|
2748
|
+
* beside the open map (`into` is ignored), so nothing is replaced and nothing is asked.
|
|
2749
|
+
* Panning, zooming, the layers and selecting work; every tool, menu and dialog that
|
|
2750
|
+
* would change it is off, and every write throws — `edit`, `update`, `sections` (except
|
|
2751
|
+
* `replaceFile(…, { asOpened: true })`, a reading of the file rather than an edit), `resize`,
|
|
2752
|
+
* `changeTileset`, `extras`, the clipboard's `cut` and `paste`, `save` and `saveAs` unless
|
|
2753
|
+
* as a copy, `sync.start`. It is never kept in Open Recent, and closing it asks nothing. File ▸ Edit a Copy
|
|
2754
|
+
* opens an ordinary copy. `label` is what the tab and the status bar call it ("Replay");
|
|
2755
|
+
* `true` is the plain "View only".
|
|
2756
|
+
*/
|
|
2757
|
+
viewOnly?: boolean | {
|
|
2758
|
+
label?: string;
|
|
2759
|
+
};
|
|
2744
2760
|
}
|
|
2745
2761
|
/** One open map, as `document.list()` reports it. `active` marks the one in front — the one every other call reads and writes. */
|
|
2746
2762
|
export interface OpenDocumentInfo {
|
|
@@ -2754,6 +2770,8 @@ export interface OpenDocumentInfo {
|
|
|
2754
2770
|
height: number;
|
|
2755
2771
|
modified: boolean;
|
|
2756
2772
|
active: boolean;
|
|
2773
|
+
/** Open to look at only; see `OpenDocumentOptions.viewOnly`. */
|
|
2774
|
+
viewOnly: boolean;
|
|
2757
2775
|
}
|
|
2758
2776
|
/** File ▸ New's form: size, tileset, and the two strings the dialog asks for. */
|
|
2759
2777
|
export interface NewDocumentOptions {
|
|
@@ -2869,11 +2887,14 @@ export interface DocumentApi {
|
|
|
2869
2887
|
* In place of a map with unsaved changes, when Preferences say to ask, the Close
|
|
2870
2888
|
* Scenario dialog comes first and the user may cancel. Resolves true once the file is
|
|
2871
2889
|
* the map in front, false when the user kept the current map or the file could not be
|
|
2872
|
-
* read (the status bar says why).
|
|
2890
|
+
* read (the status bar says why). `options.viewOnly` opens it to look at only.
|
|
2873
2891
|
*
|
|
2874
2892
|
* @example
|
|
2875
2893
|
* const [file] = await api.ui.pickFiles({ accept: ".scx,.scm,.chk" });
|
|
2876
2894
|
* if (file) await api.document.open(file, file.name, { into: "new" });
|
|
2895
|
+
* @example
|
|
2896
|
+
* // A replay's map, to draw over and not to change.
|
|
2897
|
+
* await api.document.open(chk, "Lost Temple.scx", { viewOnly: { label: "Replay" } });
|
|
2877
2898
|
*/
|
|
2878
2899
|
open(file: File | Blob | Uint8Array, fileName?: string, options?: OpenDocumentOptions): Promise<boolean>;
|
|
2879
2900
|
/**
|
|
@@ -2963,6 +2984,24 @@ export interface RawEditResult {
|
|
|
2963
2984
|
/** Warnings from parsing the edited file (a truncated section, no usable DIM, …); empty when it read cleanly. */
|
|
2964
2985
|
warnings: string[];
|
|
2965
2986
|
}
|
|
2987
|
+
/** How `document.sections.replaceFile` installs the bytes. */
|
|
2988
|
+
export interface ReplaceFileOptions {
|
|
2989
|
+
/**
|
|
2990
|
+
* Take the bytes as the file that was opened rather than as an edit: the map stays
|
|
2991
|
+
* unmodified, so closing it does not ask to save, while Save writes the bytes as given.
|
|
2992
|
+
* For a plugin that repairs a map as it opens — nothing the user did changed it. Use it
|
|
2993
|
+
* only right after an `"open"`, or to put back what was opened; anything else would
|
|
2994
|
+
* hide a change from the user. The history is dropped either way.
|
|
2995
|
+
*
|
|
2996
|
+
* @example
|
|
2997
|
+
* api.events.on("document", (e) => {
|
|
2998
|
+
* if (e.reason !== "open") return;
|
|
2999
|
+
* const fixed = repair(api.document.sections.file());
|
|
3000
|
+
* if (fixed) api.document.sections.replaceFile(fixed, { asOpened: true });
|
|
3001
|
+
* });
|
|
3002
|
+
*/
|
|
3003
|
+
asOpened?: boolean;
|
|
3004
|
+
}
|
|
2966
3005
|
/**
|
|
2967
3006
|
* The scenario file at the byte level: every section occurrence in the order Save would
|
|
2968
3007
|
* write them, with the bytes it would write — unsaved edits already encoded — and raw
|
|
@@ -3007,8 +3046,11 @@ export interface SectionsApi {
|
|
|
3007
3046
|
remove(index: number): RawEditResult;
|
|
3008
3047
|
/** Move the occurrence at `from` so that it sits at `to`. */
|
|
3009
3048
|
move(from: number, to: number): RawEditResult;
|
|
3010
|
-
/**
|
|
3011
|
-
|
|
3049
|
+
/**
|
|
3050
|
+
* Replace the whole CHK, the way File ▸ Open reads one. The map is marked modified,
|
|
3051
|
+
* unless `asOpened` says the bytes are a reading of the file as it was opened.
|
|
3052
|
+
*/
|
|
3053
|
+
replaceFile(bytes: Uint8Array, options?: ReplaceFileOptions): RawEditResult;
|
|
3012
3054
|
/**
|
|
3013
3055
|
* The CHK inside a map file — an `.scx` / `.scm` archive's `staredit\scenario.chk`, or
|
|
3014
3056
|
* the bytes themselves for a bare CHK — the way File ▸ Open reads it, for `replaceFile`.
|