castle-web-sdk 0.4.17 → 0.4.18

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/dist/castle.d.ts CHANGED
@@ -11,7 +11,7 @@ export { Pass } from "./passes";
11
11
  export type { CastlePassApi, PassOfferResult, PassOfferStatus, } from "./passes";
12
12
  export { Portal } from "./portal";
13
13
  export type { CastlePortalApi, PortalOpenResult, PortalOpenStatus, PortalPrefetchResult, PortalPrefetchStatus, } from "./portal";
14
- export { CARD_RATIO, fileUrl, initCard, onBeforeRestart, onFilesChanged, onSaveReloadState, requestReload, setup, takeReloadState, writeFileOnce, } from "./runtime";
14
+ export { CARD_RATIO, deleteFile, fileUrl, initCard, onBeforeRestart, onFilesChanged, onSaveReloadState, openFile, renameFile, requestReload, setup, takeReloadState, writeFileOnce, } from "./runtime";
15
15
  export type { FileChange, FilesChangedEvent } from "./runtime";
16
16
  export { flushSaves, hasPendingSave, onSaveState, writeFile, } from "./saveQueue";
17
17
  export type { SaveState } from "./saveQueue";
package/dist/castle.js CHANGED
@@ -7,7 +7,7 @@ export { Leaderboard } from "./leaderboard";
7
7
  export { Lifecycle } from "./lifecycle";
8
8
  export { Pass } from "./passes";
9
9
  export { Portal } from "./portal";
10
- export { CARD_RATIO, fileUrl, initCard, onBeforeRestart, onFilesChanged, onSaveReloadState, requestReload, setup, takeReloadState, writeFileOnce, } from "./runtime";
10
+ export { CARD_RATIO, deleteFile, fileUrl, initCard, onBeforeRestart, onFilesChanged, onSaveReloadState, openFile, renameFile, requestReload, setup, takeReloadState, writeFileOnce, } from "./runtime";
11
11
  export { flushSaves, hasPendingSave, onSaveState, writeFile, } from "./saveQueue";
12
12
  export { SharedStorage, Storage } from "./storage";
13
13
  export { Time } from "./time";
package/dist/runtime.d.ts CHANGED
@@ -32,6 +32,9 @@ export declare function setup(): void;
32
32
  */
33
33
  export declare function writeFileOnce(path: string, contents: string): Promise<LocalResponse>;
34
34
  export declare function fileUrl(path: string): string;
35
+ export declare function renameFile(from: string, to: string): Promise<void>;
36
+ export declare function deleteFile(path: string): Promise<void>;
37
+ export declare function openFile(path: string): void;
35
38
  export declare function initCard(): HTMLDivElement;
36
39
  export declare function sendLocalCommand<C extends CommandName>(command: C, params: CommandParams[C]): Promise<CommandResponseEnvelope>;
37
40
  /**
package/dist/runtime.js CHANGED
@@ -66,6 +66,41 @@ export function writeFileOnce(path, contents) {
66
66
  export function fileUrl(path) {
67
67
  return `/__castle/files/raw?path=${encodeURIComponent(path)}`;
68
68
  }
69
+ // Move a deck file. `writeFile`'s counterpart for the case where the file's
70
+ // NAME is the thing changing -- an editor renaming a blueprint has to move the
71
+ // file, not write a copy and leave the old one behind. Rejects when the
72
+ // destination exists or the source is gone (the serve's own guards), so a
73
+ // caller can surface the collision instead of silently clobbering.
74
+ export async function renameFile(from, to) {
75
+ await fileOp("rename", { from, to });
76
+ }
77
+ // Delete a deck file. Editor UI only, same as `writeFile` -- a published deck
78
+ // has no serve to ask.
79
+ export async function deleteFile(path) {
80
+ await fileOp("delete", { path });
81
+ }
82
+ async function fileOp(action, body) {
83
+ const res = await fetch(`/__castle/files/${action}`, {
84
+ method: "POST",
85
+ headers: { "content-type": "application/json" },
86
+ body: JSON.stringify(body),
87
+ });
88
+ if (res.ok)
89
+ return;
90
+ const detail = await res.text().catch(() => "");
91
+ throw new Error(`castle: ${action} failed (${res.status}) ${detail}`.trim());
92
+ }
93
+ // Ask the editor shell to open (or focus) an editor for `path`. This is how a
94
+ // kit editor hands the creator off to another file -- the creation modal
95
+ // dropping them into the pixel editor for the sprite it just made. A no-op
96
+ // anywhere there's no shell listening (a published deck, a bare serve), which
97
+ // is why it neither returns nor throws: the handoff is a courtesy, and the
98
+ // file was already written before we asked.
99
+ export function openFile(path) {
100
+ if (typeof window === "undefined" || window.parent === window)
101
+ return;
102
+ window.parent.postMessage({ type: "castle-open-file", path }, "*");
103
+ }
69
104
  export function initCard() {
70
105
  const style = document.createElement("style");
71
106
  style.textContent = `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-sdk",
3
- "version": "0.4.17",
3
+ "version": "0.4.18",
4
4
  "type": "module",
5
5
  "main": "dist/castle.js",
6
6
  "types": "dist/castle.d.ts",