@statewalker/platform.core 0.1.1 → 0.5.2

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 (56) hide show
  1. package/README.md +82 -36
  2. package/dist/adapters.d.ts +23 -0
  3. package/dist/adapters.d.ts.map +1 -0
  4. package/dist/adapters.js +32 -0
  5. package/dist/adapters.js.map +1 -0
  6. package/dist/commands/copy-to-clipboard/index.d.ts +8 -0
  7. package/dist/commands/copy-to-clipboard/index.d.ts.map +1 -0
  8. package/dist/commands/copy-to-clipboard/index.js +8 -0
  9. package/dist/commands/copy-to-clipboard/index.js.map +1 -0
  10. package/dist/commands/download-blob/index.d.ts +9 -0
  11. package/dist/commands/download-blob/index.d.ts.map +1 -0
  12. package/dist/commands/download-blob/index.js +8 -0
  13. package/dist/commands/download-blob/index.js.map +1 -0
  14. package/dist/commands/download-to-files/index.d.ts +21 -0
  15. package/dist/commands/download-to-files/index.d.ts.map +1 -0
  16. package/dist/commands/download-to-files/index.js +8 -0
  17. package/dist/commands/download-to-files/index.js.map +1 -0
  18. package/dist/commands/index.d.ts +8 -0
  19. package/dist/commands/pick-directory/index.d.ts +13 -0
  20. package/dist/commands/pick-directory/index.d.ts.map +1 -0
  21. package/dist/commands/pick-directory/index.js +8 -0
  22. package/dist/commands/pick-directory/index.js.map +1 -0
  23. package/dist/commands/pick-file/index.d.ts +14 -0
  24. package/dist/commands/pick-file/index.d.ts.map +1 -0
  25. package/dist/commands/pick-file/index.js +8 -0
  26. package/dist/commands/pick-file/index.js.map +1 -0
  27. package/dist/commands/preference-get/index.d.ts +11 -0
  28. package/dist/commands/preference-get/index.d.ts.map +1 -0
  29. package/dist/commands/preference-get/index.js +8 -0
  30. package/dist/commands/preference-get/index.js.map +1 -0
  31. package/dist/commands/preference-set/index.d.ts +9 -0
  32. package/dist/commands/preference-set/index.d.ts.map +1 -0
  33. package/dist/commands/preference-set/index.js +8 -0
  34. package/dist/commands/preference-set/index.js.map +1 -0
  35. package/dist/errors.d.ts +16 -0
  36. package/dist/errors.d.ts.map +1 -0
  37. package/dist/errors.js +22 -0
  38. package/dist/errors.js.map +1 -0
  39. package/dist/index.d.ts +12 -0
  40. package/dist/index.js +11 -0
  41. package/dist/url-state-view.d.ts +46 -0
  42. package/dist/url-state-view.d.ts.map +1 -0
  43. package/dist/url-state-view.js +63 -0
  44. package/dist/url-state-view.js.map +1 -0
  45. package/package.json +18 -9
  46. package/src/commands/copy-to-clipboard/index.ts +1 -1
  47. package/src/commands/download-blob/index.ts +1 -1
  48. package/src/commands/download-to-files/index.ts +1 -1
  49. package/src/commands/pick-directory/index.ts +1 -1
  50. package/src/commands/pick-file/index.ts +1 -1
  51. package/src/commands/preference-get/index.ts +1 -1
  52. package/src/commands/preference-set/index.ts +1 -1
  53. package/dist/index.d.mts +0 -160
  54. package/dist/index.d.mts.map +0 -1
  55. package/dist/index.mjs +0 -139
  56. package/dist/index.mjs.map +0 -1
package/README.md CHANGED
@@ -1,52 +1,78 @@
1
1
  # @statewalker/platform.core
2
2
 
3
- Type-only vocabulary of platform-capability commands shared by every application composed of `statewalker-workbench` fragments. A platform-specific implementation is provided by a peer fragment (`@statewalker/platform.browser` for browsers; future `platform-node` / `platform-electron`); this package stays free of runtime browser code and runs unchanged under Node.
3
+ ## What it is
4
+
5
+ The contract for host capabilities: pick a directory or files, download, copy to the clipboard, read and write durable preferences, and keep application state in the URL. Each capability is a command declaration for the workspace's `Commands` bus (`@statewalker/shared-commands`). This package declares them; `@statewalker/platform.browser` and `@statewalker/platform.node` answer them.
4
6
 
5
7
  ## Why it exists
6
8
 
7
- Fragments need a single, typed surface to ask the host environment to do environment-y things — pick a directory, save a file, copy to clipboard, persist a preference, sync URL state — without binding to any particular host. Keeping the contract here (and the implementations in `platform.browser` / future siblings) means a fragment that uses `runPickDirectory` works the same in a browser app, a Node test, and a future Electron build.
9
+ Fragments need to ask the host for things like "let the user choose a folder" without knowing whether they run in a browser tab, a Node test or another shell. Putting the typed contract here, with no host code, lets a fragment call `PickDirectoryCommand` the same way everywhere, and lets tests register fake handlers. The package touches no `window`, `document` or other browser global, so it runs unchanged in Node.
8
10
 
9
- ## Commands
11
+ ## How to use
10
12
 
11
- Each command is a self-contained folder under `src/commands/` exporting four things: the string key constant, the payload / result type declarations, and the `run*` / `handle*` factory pair created via `@statewalker/shared-commands`.
13
+ ```sh
14
+ pnpm add @statewalker/platform.core
15
+ ```
12
16
 
13
- | Folder | Key | Purpose |
14
- |---|---|---|
15
- | [`pick-directory/`](src/commands/pick-directory/) | `platform:pick-directory` | Ask the environment to present a directory picker; returns `{ files: FilesApi; label }`. |
16
- | [`pick-file/`](src/commands/pick-file/) | `platform:pick-file` | File picker returning `{ blobs: Blob[]; names }`. |
17
- | [`download-to-files/`](src/commands/download-to-files/) | `platform:download-to-files` | Stream a URL into a `FilesApi` path with optional resume + `AbortSignal`. |
18
- | [`copy-to-clipboard/`](src/commands/copy-to-clipboard/) | `platform:copy-to-clipboard` | Copy text. |
19
- | [`download-blob/`](src/commands/download-blob/) | `platform:download-blob` | Trigger a browser "Save As" for a `Blob`. |
20
- | [`preference-get/`](src/commands/preference-get/) | `platform:preference-get` | Read a durable host-provided key/value pair. |
21
- | [`preference-set/`](src/commands/preference-set/) | `platform:preference-set` | Write a durable host-provided key/value pair. |
17
+ 1. Make sure a host implementation is active (for example `@statewalker/platform.browser` as a manifest root).
18
+ 2. Get the bus with `getCommands(ctx)`.
19
+ 3. Call a declaration: `getCommands(ctx).call(Declaration, payload).promise`.
22
20
 
23
- `src/commands/index.ts` re-exports every folder; `src/index.ts` re-exports `./commands/index.ts` plus the adapters and `UrlStateView`.
21
+ | Declaration | Key | Payload -> result |
22
+ | --- | --- | --- |
23
+ | `PickDirectoryCommand` | `platform:pick-directory` | `{ title? }` -> `{ files: FilesApi; label }` |
24
+ | `PickFileCommand` | `platform:pick-file` | `{ title?, accept?, multiple? }` -> `{ blobs: Blob[]; names: string[] }` |
25
+ | `DownloadToFilesCommand` | `platform:download-to-files` | `{ url, files, path, resume?, onProgress?, signal? }` -> `{ bytes }` |
26
+ | `CopyToClipboardCommand` | `platform:copy-to-clipboard` | `{ text }` -> `void` |
27
+ | `DownloadBlobCommand` | `platform:download-blob` | `{ blob, filename }` -> `void` |
28
+ | `PreferenceGetCommand` | `platform:preference-get` | `{ key }` -> `{ value }` |
29
+ | `PreferenceSetCommand` | `platform:preference-set` | `{ key, value }` -> `void` |
24
30
 
25
- ## Adapters
31
+ Each key is also exported as a constant (`PICK_DIRECTORY_COMMAND_KEY`, `PICK_FILE_COMMAND_KEY`, `DOWNLOAD_TO_FILES_COMMAND_KEY`, `COPY_TO_CLIPBOARD_COMMAND_KEY`, `DOWNLOAD_BLOB_COMMAND_KEY`, `PREFERENCE_GET_COMMAND_KEY`, `PREFERENCE_SET_COMMAND_KEY`), with payload and result types named after the command (`PickDirectoryPayload`, `PickDirectoryResult`, ..., `DownloadProgress`). `FilesApi` is from `@statewalker/webrun-files`.
26
32
 
27
- The package owns three context-bound adapters consumed by every fragment:
33
+ ## Examples
28
34
 
29
- ```ts
30
- import { getCommands, getUrlStateView } from "@statewalker/platform.core";
35
+ Ask for a directory and handle cancellation:
31
36
 
32
- const commands = getCommands(ctx); // Commands bus (auto-created on first access)
33
- const urlState = getUrlStateView(ctx); // URL ↔ state sync model
37
+ ```ts
38
+ import { getCommands, isUserCancelled, PickDirectoryCommand } from "@statewalker/platform.core";
39
+
40
+ try {
41
+ const { files, label } = await getCommands(ctx).call(PickDirectoryCommand, {
42
+ title: "Select workspace",
43
+ }).promise;
44
+ } catch (error) {
45
+ if (!isUserCancelled(error)) throw error;
46
+ }
34
47
  ```
35
48
 
36
- - **`Commands`** — the single `Commands` bus shared by every fragment in a composed app. Auto-creates on first access; no explicit bootstrap step.
37
- - **`UrlStateView`** — bidirectional URL ↔ model state synchronisation. Fragments register `UrlSerializer`s; the browser binding (in `platform.browser`) flushes serialised state to `location.hash` and feeds incoming `hashchange` back. Auto-created on first access.
38
-
39
- ## Usage
49
+ Store a preference:
40
50
 
41
51
  ```ts
42
- import { getCommands, runPickDirectory } from "@statewalker/platform.core";
52
+ import { getCommands, PreferenceGetCommand, PreferenceSetCommand } from "@statewalker/platform.core";
43
53
 
44
- const { files, label } = await runPickDirectory(getCommands(ctx), {
45
- title: "Select workspace",
46
- });
54
+ const commands = getCommands(ctx);
55
+ await commands.call(PreferenceSetCommand, { key: "theme", value: "dark" }).promise;
56
+ const { value } = await commands.call(PreferenceGetCommand, { key: "theme" }).promise;
47
57
  ```
48
58
 
49
- Registering a serializer with `UrlStateView`:
59
+ Download into a `FilesApi` with progress:
60
+
61
+ ```ts
62
+ import { DownloadToFilesCommand, getCommands } from "@statewalker/platform.core";
63
+
64
+ const controller = new AbortController();
65
+ const { bytes } = await getCommands(ctx).call(DownloadToFilesCommand, {
66
+ url: "https://example.com/model.bin",
67
+ files,
68
+ path: "/models/model.bin",
69
+ resume: true,
70
+ onProgress: ({ loaded, total }) => console.log(loaded, total),
71
+ signal: controller.signal,
72
+ }).promise;
73
+ ```
74
+
75
+ Keep state in the URL:
50
76
 
51
77
  ```ts
52
78
  import { getUrlStateView, type UrlSerializer } from "@statewalker/platform.core";
@@ -56,19 +82,39 @@ const serializer: UrlSerializer = {
56
82
  deserialize: (state) => switchToSession(state.query.session),
57
83
  };
58
84
 
59
- const dispose = getUrlStateView(ctx).register(serializer);
85
+ const view = getUrlStateView(ctx);
86
+ const unregister = view.register(serializer);
87
+ view.sync(); // the host binding writes view.buildState() to the URL
88
+ ```
89
+
90
+ Signal cancellation from a handler:
91
+
92
+ ```ts
93
+ import { UserCancelledError } from "@statewalker/platform.core";
94
+
95
+ command.reject(new UserCancelledError());
60
96
  ```
61
97
 
62
98
  ## Internals
63
99
 
64
- - **Zero runtime DOM dependencies.** `UrlStateView` extends `BaseClass` and is built from observable primitives only; nothing in the package touches `window`, `document`, or any browser global.
65
- - **Command-folder layout** — every command lives in its own folder so a future code-gen (e.g. JSON-RPC bindings) can iterate cleanly without text-grepping.
66
- - **Loop prevention in `UrlStateView`** — a single `#syncing` flag blocks reentrancy: `applyUrl()` is a no-op while `sync()` is running, and vice versa.
100
+ ### A call with no handler fails at once
101
+
102
+ Every declaration uses the `async` dispatch policy of `@statewalker/shared-commands`: when no handler is registered at call time, the call rejects immediately with `CommandError` with `kind: "no-handlers"` (`commandKey` names the command). A handler registered later does not pick up earlier calls. This happens on a host that does not implement a command (for example the pickers or the clipboard under `@statewalker/platform.node`), or when the call is made before the host fragment has started: start the platform fragment before the fragments that call it, and catch the error where the host may lack the command. A handler that takes the call without settling it (a listener that only observes) still leaves it pending.
103
+
104
+ ### Cancellation is a type, not a string
105
+
106
+ `UserCancelledError` (`name === "UserCancelledError"`) and `isUserCancelled(error)` let callers tell "the user closed the dialog" from a real failure with one `instanceof` check, instead of matching `AbortError` names or messages.
107
+
108
+ ### The bus and the URL view are per workspace or per context
109
+
110
+ `getCommands(ctx)` returns `getWorkspace(ctx).requireAdapter(Commands)` from `@statewalker/workspace.core`, created on first use, so all fragments under one workspace share one bus. `setCommands` and `removeCommands` are kept only so old start-up code compiles; they do nothing except log `[platform-api] setCommands is deprecated and a no-op: ...`.
111
+
112
+ `getUrlStateView(ctx)` (with `setUrlStateView` and `removeUrlStateView`) stores a `Navigation` instance (also exported as `UrlStateView`) under the context key `model:url-state`. `Navigation` extends `BaseClass` from `@statewalker/shared-baseclass`; `sync()` notifies `onUpdate` listeners, `buildState()` folds all serializers over `{ path: "", query: {} }`, and `applyUrl(state)` feeds an incoming URL state to every serializer. One `#syncing` flag blocks re-entry, so a write to the URL never triggers a read back into the model in the same turn, and the reverse.
67
113
 
68
- ## Related
114
+ ### Dependencies
69
115
 
70
- - `@statewalker/platform.browser` — browser implementation of every command above plus `bindUrlState`.
116
+ `@statewalker/shared-commands` (command declarations and bus), `@statewalker/workspace.core` (the workspace that owns the bus), `@statewalker/shared-adapters` and `@statewalker/shared-baseclass` (the URL view adapter and its observable base), `@statewalker/webrun-files` (the `FilesApi` type in payloads).
71
117
 
72
118
  ## License
73
119
 
74
- MIT — see the monorepo root `LICENSE`.
120
+ MIT
@@ -0,0 +1,23 @@
1
+ import { Commands } from "@statewalker/shared-commands";
2
+ //#region src/adapters.d.ts
3
+ /**
4
+ * Resolve the workspace-scoped `Commands` bus for the given context bag.
5
+ * Delegates to `workspace.requireAdapter(Commands)`, which auto-instantiates
6
+ * a single shared bus on first lookup so every fragment composed under the
7
+ * same workspace dispatches through the same instance.
8
+ */
9
+ export declare function getCommands(ctx: Record<string, unknown>): Commands;
10
+ /**
11
+ * @deprecated The commands bus is now workspace-scoped and auto-instantiated;
12
+ * explicit registration is a no-op. Kept for one release so legacy bootstrap
13
+ * code keeps compiling. Will be removed in a follow-up phase.
14
+ */
15
+ export declare function setCommands(_ctx: Record<string, unknown>, _commands: Commands): void;
16
+ /**
17
+ * @deprecated The commands bus is now workspace-scoped and lifecycle-managed by
18
+ * the workspace; explicit removal is a no-op. Kept for one release so legacy
19
+ * teardown code keeps compiling. Will be removed in a follow-up phase.
20
+ */
21
+ export declare function removeCommands(_ctx: Record<string, unknown>): void;
22
+ //#endregion
23
+ //# sourceMappingURL=adapters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapters.d.ts","names":[],"sources":["../src/adapters.ts"],"mappings":";;;;;;;;wBASgB,YAAY,KAAK,0BAA0B;;;;;;wBAS3C,YAAY,MAAM,yBAAyB,WAAW;;;;;;wBAWtD,eAAe,MAAM"}
@@ -0,0 +1,32 @@
1
+ import { Commands } from "@statewalker/shared-commands";
2
+ import { getWorkspace } from "@statewalker/workspace.core";
3
+ //#region src/adapters.ts
4
+ /**
5
+ * Resolve the workspace-scoped `Commands` bus for the given context bag.
6
+ * Delegates to `workspace.requireAdapter(Commands)`, which auto-instantiates
7
+ * a single shared bus on first lookup so every fragment composed under the
8
+ * same workspace dispatches through the same instance.
9
+ */
10
+ function getCommands(ctx) {
11
+ return getWorkspace(ctx).requireAdapter(Commands);
12
+ }
13
+ /**
14
+ * @deprecated The commands bus is now workspace-scoped and auto-instantiated;
15
+ * explicit registration is a no-op. Kept for one release so legacy bootstrap
16
+ * code keeps compiling. Will be removed in a follow-up phase.
17
+ */
18
+ function setCommands(_ctx, _commands) {
19
+ console.warn("[platform-api] setCommands is deprecated and a no-op: the Commands bus is now workspace-bound and auto-instantiated via workspace.requireAdapter(Commands).");
20
+ }
21
+ /**
22
+ * @deprecated The commands bus is now workspace-scoped and lifecycle-managed by
23
+ * the workspace; explicit removal is a no-op. Kept for one release so legacy
24
+ * teardown code keeps compiling. Will be removed in a follow-up phase.
25
+ */
26
+ function removeCommands(_ctx) {
27
+ console.warn("[platform-api] removeCommands is deprecated and a no-op: the Commands bus lifecycle is owned by workspace.close().");
28
+ }
29
+ //#endregion
30
+ export { getCommands, removeCommands, setCommands };
31
+
32
+ //# sourceMappingURL=adapters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapters.js","names":[],"sources":["../src/adapters.ts"],"sourcesContent":["import { Commands } from \"@statewalker/shared-commands\";\nimport { getWorkspace } from \"@statewalker/workspace.core\";\n\n/**\n * Resolve the workspace-scoped `Commands` bus for the given context bag.\n * Delegates to `workspace.requireAdapter(Commands)`, which auto-instantiates\n * a single shared bus on first lookup so every fragment composed under the\n * same workspace dispatches through the same instance.\n */\nexport function getCommands(ctx: Record<string, unknown>): Commands {\n return getWorkspace(ctx).requireAdapter(Commands);\n}\n\n/**\n * @deprecated The commands bus is now workspace-scoped and auto-instantiated;\n * explicit registration is a no-op. Kept for one release so legacy bootstrap\n * code keeps compiling. Will be removed in a follow-up phase.\n */\nexport function setCommands(_ctx: Record<string, unknown>, _commands: Commands): void {\n console.warn(\n \"[platform-api] setCommands is deprecated and a no-op: the Commands bus is now workspace-bound and auto-instantiated via workspace.requireAdapter(Commands).\",\n );\n}\n\n/**\n * @deprecated The commands bus is now workspace-scoped and lifecycle-managed by\n * the workspace; explicit removal is a no-op. Kept for one release so legacy\n * teardown code keeps compiling. Will be removed in a follow-up phase.\n */\nexport function removeCommands(_ctx: Record<string, unknown>): void {\n console.warn(\n \"[platform-api] removeCommands is deprecated and a no-op: the Commands bus lifecycle is owned by workspace.close().\",\n );\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,YAAY,KAAwC;CAClE,OAAO,aAAa,GAAG,CAAC,CAAC,eAAe,QAAQ;AAClD;;;;;;AAOA,SAAgB,YAAY,MAA+B,WAA2B;CACpF,QAAQ,KACN,6JACF;AACF;;;;;;AAOA,SAAgB,eAAe,MAAqC;CAClE,QAAQ,KACN,oHACF;AACF"}
@@ -0,0 +1,8 @@
1
+ //#region src/commands/copy-to-clipboard/index.d.ts
2
+ export declare const COPY_TO_CLIPBOARD_COMMAND_KEY = "platform:copy-to-clipboard";
3
+ export interface CopyToClipboardPayload {
4
+ text: string;
5
+ }
6
+ export declare const CopyToClipboardCommand: import("@statewalker/shared-commands").CommandDeclaration<CopyToClipboardPayload, void>;
7
+ //#endregion
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/commands/copy-to-clipboard/index.ts"],"mappings":";qBAEa;iBAEI;EACf;;qBAGW,+DAAsB,mBAAA"}
@@ -0,0 +1,8 @@
1
+ import { Command, passthrough } from "@statewalker/shared-commands";
2
+ //#region src/commands/copy-to-clipboard/index.ts
3
+ const COPY_TO_CLIPBOARD_COMMAND_KEY = "platform:copy-to-clipboard";
4
+ const CopyToClipboardCommand = Command.async(COPY_TO_CLIPBOARD_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
5
+ //#endregion
6
+ export { COPY_TO_CLIPBOARD_COMMAND_KEY, CopyToClipboardCommand };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/commands/copy-to-clipboard/index.ts"],"sourcesContent":["import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const COPY_TO_CLIPBOARD_COMMAND_KEY = \"platform:copy-to-clipboard\";\n\nexport interface CopyToClipboardPayload {\n text: string;\n}\n\nexport const CopyToClipboardCommand = Command.async(COPY_TO_CLIPBOARD_COMMAND_KEY)\n .input(passthrough<CopyToClipboardPayload>())\n .output(passthrough<void>())\n .build();\n"],"mappings":";;AAEA,MAAa,gCAAgC;AAM7C,MAAa,yBAAyB,QAAQ,MAAM,6BAA6B,CAAC,CAC/E,MAAM,YAAoC,CAAC,CAAC,CAC5C,OAAO,YAAkB,CAAC,CAAC,CAC3B,MAAM"}
@@ -0,0 +1,9 @@
1
+ //#region src/commands/download-blob/index.d.ts
2
+ export declare const DOWNLOAD_BLOB_COMMAND_KEY = "platform:download-blob";
3
+ export interface DownloadBlobPayload {
4
+ blob: Blob;
5
+ filename: string;
6
+ }
7
+ export declare const DownloadBlobCommand: import("@statewalker/shared-commands").CommandDeclaration<DownloadBlobPayload, void>;
8
+ //#endregion
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/commands/download-blob/index.ts"],"mappings":";qBAEa;iBAEI;EACf,MAAM;EACN;;qBAGW,4DAAmB,mBAAA"}
@@ -0,0 +1,8 @@
1
+ import { Command, passthrough } from "@statewalker/shared-commands";
2
+ //#region src/commands/download-blob/index.ts
3
+ const DOWNLOAD_BLOB_COMMAND_KEY = "platform:download-blob";
4
+ const DownloadBlobCommand = Command.async(DOWNLOAD_BLOB_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
5
+ //#endregion
6
+ export { DOWNLOAD_BLOB_COMMAND_KEY, DownloadBlobCommand };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/commands/download-blob/index.ts"],"sourcesContent":["import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const DOWNLOAD_BLOB_COMMAND_KEY = \"platform:download-blob\";\n\nexport interface DownloadBlobPayload {\n blob: Blob;\n filename: string;\n}\n\nexport const DownloadBlobCommand = Command.async(DOWNLOAD_BLOB_COMMAND_KEY)\n .input(passthrough<DownloadBlobPayload>())\n .output(passthrough<void>())\n .build();\n"],"mappings":";;AAEA,MAAa,4BAA4B;AAOzC,MAAa,sBAAsB,QAAQ,MAAM,yBAAyB,CAAC,CACxE,MAAM,YAAiC,CAAC,CAAC,CACzC,OAAO,YAAkB,CAAC,CAAC,CAC3B,MAAM"}
@@ -0,0 +1,21 @@
1
+ import { FilesApi } from "@statewalker/webrun-files";
2
+ //#region src/commands/download-to-files/index.d.ts
3
+ export declare const DOWNLOAD_TO_FILES_COMMAND_KEY = "platform:download-to-files";
4
+ export interface DownloadProgress {
5
+ loaded: number;
6
+ total?: number;
7
+ }
8
+ export interface DownloadToFilesPayload {
9
+ url: string;
10
+ files: FilesApi;
11
+ path: string;
12
+ resume?: boolean;
13
+ onProgress?: (progress: DownloadProgress) => void;
14
+ signal?: AbortSignal;
15
+ }
16
+ export interface DownloadToFilesResult {
17
+ bytes: number;
18
+ }
19
+ export declare const DownloadToFilesCommand: import("@statewalker/shared-commands").CommandDeclaration<DownloadToFilesPayload, DownloadToFilesResult>;
20
+ //#endregion
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/commands/download-to-files/index.ts"],"mappings":";;qBAGa;iBAEI;EACf;EACA;;iBAGe;EACf;EACA,OAAO;EACP;EACA;EACA,cAAc,UAAU;EACxB,SAAS;;iBAGM;EACf;;qBAGW,+DAAsB,mBAAA,wBAAA"}
@@ -0,0 +1,8 @@
1
+ import { Command, passthrough } from "@statewalker/shared-commands";
2
+ //#region src/commands/download-to-files/index.ts
3
+ const DOWNLOAD_TO_FILES_COMMAND_KEY = "platform:download-to-files";
4
+ const DownloadToFilesCommand = Command.async(DOWNLOAD_TO_FILES_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
5
+ //#endregion
6
+ export { DOWNLOAD_TO_FILES_COMMAND_KEY, DownloadToFilesCommand };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/commands/download-to-files/index.ts"],"sourcesContent":["import { Command, passthrough } from \"@statewalker/shared-commands\";\nimport type { FilesApi } from \"@statewalker/webrun-files\";\n\nexport const DOWNLOAD_TO_FILES_COMMAND_KEY = \"platform:download-to-files\";\n\nexport interface DownloadProgress {\n loaded: number;\n total?: number;\n}\n\nexport interface DownloadToFilesPayload {\n url: string;\n files: FilesApi;\n path: string;\n resume?: boolean;\n onProgress?: (progress: DownloadProgress) => void;\n signal?: AbortSignal;\n}\n\nexport interface DownloadToFilesResult {\n bytes: number;\n}\n\nexport const DownloadToFilesCommand = Command.async(DOWNLOAD_TO_FILES_COMMAND_KEY)\n .input(passthrough<DownloadToFilesPayload>())\n .output(passthrough<DownloadToFilesResult>())\n .build();\n"],"mappings":";;AAGA,MAAa,gCAAgC;AAoB7C,MAAa,yBAAyB,QAAQ,MAAM,6BAA6B,CAAC,CAC/E,MAAM,YAAoC,CAAC,CAAC,CAC5C,OAAO,YAAmC,CAAC,CAAC,CAC5C,MAAM"}
@@ -0,0 +1,8 @@
1
+ import { COPY_TO_CLIPBOARD_COMMAND_KEY, CopyToClipboardCommand, CopyToClipboardPayload } from "./copy-to-clipboard/index.js";
2
+ import { DOWNLOAD_BLOB_COMMAND_KEY, DownloadBlobCommand, DownloadBlobPayload } from "./download-blob/index.js";
3
+ import { DOWNLOAD_TO_FILES_COMMAND_KEY, DownloadProgress, DownloadToFilesCommand, DownloadToFilesPayload, DownloadToFilesResult } from "./download-to-files/index.js";
4
+ import { PICK_DIRECTORY_COMMAND_KEY, PickDirectoryCommand, PickDirectoryPayload, PickDirectoryResult } from "./pick-directory/index.js";
5
+ import { PICK_FILE_COMMAND_KEY, PickFileCommand, PickFilePayload, PickFileResult } from "./pick-file/index.js";
6
+ import { PREFERENCE_GET_COMMAND_KEY, PreferenceGetCommand, PreferenceGetPayload, PreferenceGetResult } from "./preference-get/index.js";
7
+ import { PREFERENCE_SET_COMMAND_KEY, PreferenceSetCommand, PreferenceSetPayload } from "./preference-set/index.js";
8
+ export { COPY_TO_CLIPBOARD_COMMAND_KEY, CopyToClipboardCommand, CopyToClipboardPayload, DOWNLOAD_BLOB_COMMAND_KEY, DOWNLOAD_TO_FILES_COMMAND_KEY, DownloadBlobCommand, DownloadBlobPayload, DownloadProgress, DownloadToFilesCommand, DownloadToFilesPayload, DownloadToFilesResult, PICK_DIRECTORY_COMMAND_KEY, PICK_FILE_COMMAND_KEY, PREFERENCE_GET_COMMAND_KEY, PREFERENCE_SET_COMMAND_KEY, PickDirectoryCommand, PickDirectoryPayload, PickDirectoryResult, PickFileCommand, PickFilePayload, PickFileResult, PreferenceGetCommand, PreferenceGetPayload, PreferenceGetResult, PreferenceSetCommand, PreferenceSetPayload };
@@ -0,0 +1,13 @@
1
+ import { FilesApi } from "@statewalker/webrun-files";
2
+ //#region src/commands/pick-directory/index.d.ts
3
+ export declare const PICK_DIRECTORY_COMMAND_KEY = "platform:pick-directory";
4
+ export interface PickDirectoryPayload {
5
+ title?: string;
6
+ }
7
+ export interface PickDirectoryResult {
8
+ files: FilesApi;
9
+ label: string;
10
+ }
11
+ export declare const PickDirectoryCommand: import("@statewalker/shared-commands").CommandDeclaration<PickDirectoryPayload, PickDirectoryResult>;
12
+ //#endregion
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/commands/pick-directory/index.ts"],"mappings":";;qBAGa;iBAEI;EACf;;iBAGe;EACf,OAAO;EACP;;qBAGW,6DAAoB,mBAAA,sBAAA"}
@@ -0,0 +1,8 @@
1
+ import { Command, passthrough } from "@statewalker/shared-commands";
2
+ //#region src/commands/pick-directory/index.ts
3
+ const PICK_DIRECTORY_COMMAND_KEY = "platform:pick-directory";
4
+ const PickDirectoryCommand = Command.async(PICK_DIRECTORY_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
5
+ //#endregion
6
+ export { PICK_DIRECTORY_COMMAND_KEY, PickDirectoryCommand };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/commands/pick-directory/index.ts"],"sourcesContent":["import { Command, passthrough } from \"@statewalker/shared-commands\";\nimport type { FilesApi } from \"@statewalker/webrun-files\";\n\nexport const PICK_DIRECTORY_COMMAND_KEY = \"platform:pick-directory\";\n\nexport interface PickDirectoryPayload {\n title?: string;\n}\n\nexport interface PickDirectoryResult {\n files: FilesApi;\n label: string;\n}\n\nexport const PickDirectoryCommand = Command.async(PICK_DIRECTORY_COMMAND_KEY)\n .input(passthrough<PickDirectoryPayload>())\n .output(passthrough<PickDirectoryResult>())\n .build();\n"],"mappings":";;AAGA,MAAa,6BAA6B;AAW1C,MAAa,uBAAuB,QAAQ,MAAM,0BAA0B,CAAC,CAC1E,MAAM,YAAkC,CAAC,CAAC,CAC1C,OAAO,YAAiC,CAAC,CAAC,CAC1C,MAAM"}
@@ -0,0 +1,14 @@
1
+ //#region src/commands/pick-file/index.d.ts
2
+ export declare const PICK_FILE_COMMAND_KEY = "platform:pick-file";
3
+ export interface PickFilePayload {
4
+ title?: string;
5
+ accept?: string[];
6
+ multiple?: boolean;
7
+ }
8
+ export interface PickFileResult {
9
+ blobs: Blob[];
10
+ names: string[];
11
+ }
12
+ export declare const PickFileCommand: import("@statewalker/shared-commands").CommandDeclaration<PickFilePayload, PickFileResult>;
13
+ //#endregion
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/commands/pick-file/index.ts"],"mappings":";qBAEa;iBAEI;EACf;EACA;EACA;;iBAGe;EACf,OAAO;EACP;;qBAGW,wDAAe,mBAAA,iBAAA"}
@@ -0,0 +1,8 @@
1
+ import { Command, passthrough } from "@statewalker/shared-commands";
2
+ //#region src/commands/pick-file/index.ts
3
+ const PICK_FILE_COMMAND_KEY = "platform:pick-file";
4
+ const PickFileCommand = Command.async(PICK_FILE_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
5
+ //#endregion
6
+ export { PICK_FILE_COMMAND_KEY, PickFileCommand };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/commands/pick-file/index.ts"],"sourcesContent":["import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const PICK_FILE_COMMAND_KEY = \"platform:pick-file\";\n\nexport interface PickFilePayload {\n title?: string;\n accept?: string[];\n multiple?: boolean;\n}\n\nexport interface PickFileResult {\n blobs: Blob[];\n names: string[];\n}\n\nexport const PickFileCommand = Command.async(PICK_FILE_COMMAND_KEY)\n .input(passthrough<PickFilePayload>())\n .output(passthrough<PickFileResult>())\n .build();\n"],"mappings":";;AAEA,MAAa,wBAAwB;AAarC,MAAa,kBAAkB,QAAQ,MAAM,qBAAqB,CAAC,CAChE,MAAM,YAA6B,CAAC,CAAC,CACrC,OAAO,YAA4B,CAAC,CAAC,CACrC,MAAM"}
@@ -0,0 +1,11 @@
1
+ //#region src/commands/preference-get/index.d.ts
2
+ export declare const PREFERENCE_GET_COMMAND_KEY = "platform:preference-get";
3
+ export interface PreferenceGetPayload {
4
+ key: string;
5
+ }
6
+ export interface PreferenceGetResult {
7
+ value: unknown | undefined;
8
+ }
9
+ export declare const PreferenceGetCommand: import("@statewalker/shared-commands").CommandDeclaration<PreferenceGetPayload, PreferenceGetResult>;
10
+ //#endregion
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/commands/preference-get/index.ts"],"mappings":";qBAEa;iBAEI;EACf;;iBAGe;EACf;;qBAGW,6DAAoB,mBAAA,sBAAA"}
@@ -0,0 +1,8 @@
1
+ import { Command, passthrough } from "@statewalker/shared-commands";
2
+ //#region src/commands/preference-get/index.ts
3
+ const PREFERENCE_GET_COMMAND_KEY = "platform:preference-get";
4
+ const PreferenceGetCommand = Command.async(PREFERENCE_GET_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
5
+ //#endregion
6
+ export { PREFERENCE_GET_COMMAND_KEY, PreferenceGetCommand };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/commands/preference-get/index.ts"],"sourcesContent":["import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const PREFERENCE_GET_COMMAND_KEY = \"platform:preference-get\";\n\nexport interface PreferenceGetPayload {\n key: string;\n}\n\nexport interface PreferenceGetResult {\n value: unknown | undefined;\n}\n\nexport const PreferenceGetCommand = Command.async(PREFERENCE_GET_COMMAND_KEY)\n .input(passthrough<PreferenceGetPayload>())\n .output(passthrough<PreferenceGetResult>())\n .build();\n"],"mappings":";;AAEA,MAAa,6BAA6B;AAU1C,MAAa,uBAAuB,QAAQ,MAAM,0BAA0B,CAAC,CAC1E,MAAM,YAAkC,CAAC,CAAC,CAC1C,OAAO,YAAiC,CAAC,CAAC,CAC1C,MAAM"}
@@ -0,0 +1,9 @@
1
+ //#region src/commands/preference-set/index.d.ts
2
+ export declare const PREFERENCE_SET_COMMAND_KEY = "platform:preference-set";
3
+ export interface PreferenceSetPayload {
4
+ key: string;
5
+ value: unknown;
6
+ }
7
+ export declare const PreferenceSetCommand: import("@statewalker/shared-commands").CommandDeclaration<PreferenceSetPayload, void>;
8
+ //#endregion
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/commands/preference-set/index.ts"],"mappings":";qBAEa;iBAEI;EACf;EACA;;qBAGW,6DAAoB,mBAAA"}
@@ -0,0 +1,8 @@
1
+ import { Command, passthrough } from "@statewalker/shared-commands";
2
+ //#region src/commands/preference-set/index.ts
3
+ const PREFERENCE_SET_COMMAND_KEY = "platform:preference-set";
4
+ const PreferenceSetCommand = Command.async(PREFERENCE_SET_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
5
+ //#endregion
6
+ export { PREFERENCE_SET_COMMAND_KEY, PreferenceSetCommand };
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/commands/preference-set/index.ts"],"sourcesContent":["import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const PREFERENCE_SET_COMMAND_KEY = \"platform:preference-set\";\n\nexport interface PreferenceSetPayload {\n key: string;\n value: unknown;\n}\n\nexport const PreferenceSetCommand = Command.async(PREFERENCE_SET_COMMAND_KEY)\n .input(passthrough<PreferenceSetPayload>())\n .output(passthrough<void>())\n .build();\n"],"mappings":";;AAEA,MAAa,6BAA6B;AAO1C,MAAa,uBAAuB,QAAQ,MAAM,0BAA0B,CAAC,CAC1E,MAAM,YAAkC,CAAC,CAAC,CAC1C,OAAO,YAAkB,CAAC,CAAC,CAC3B,MAAM"}
@@ -0,0 +1,16 @@
1
+ //#region src/errors.d.ts
2
+ /**
3
+ * Canonical signal that the user dismissed an interactive prompt (folder
4
+ * picker, dialog, file picker, etc.). Throwing this class — instead of a
5
+ * raw `DOMException` with `name === "AbortError"` or an ad-hoc string — lets
6
+ * every consumer distinguish cancellation from real failure with a single
7
+ * `instanceof` check.
8
+ */
9
+ export declare class UserCancelledError extends Error {
10
+ readonly name = "UserCancelledError";
11
+ constructor(message?: string);
12
+ }
13
+ /** Returns `true` if `err` is an instance of {@link UserCancelledError}. */
14
+ export declare function isUserCancelled(err: unknown): boolean;
15
+ //#endregion
16
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";;;;;;;;qBAOa,2BAA2B;WAC7B;EAET,YAAY;;;wBAME,gBAAgB"}
package/dist/errors.js ADDED
@@ -0,0 +1,22 @@
1
+ //#region src/errors.ts
2
+ /**
3
+ * Canonical signal that the user dismissed an interactive prompt (folder
4
+ * picker, dialog, file picker, etc.). Throwing this class — instead of a
5
+ * raw `DOMException` with `name === "AbortError"` or an ad-hoc string — lets
6
+ * every consumer distinguish cancellation from real failure with a single
7
+ * `instanceof` check.
8
+ */
9
+ var UserCancelledError = class extends Error {
10
+ name = "UserCancelledError";
11
+ constructor(message = "User cancelled the operation") {
12
+ super(message);
13
+ }
14
+ };
15
+ /** Returns `true` if `err` is an instance of {@link UserCancelledError}. */
16
+ function isUserCancelled(err) {
17
+ return err instanceof UserCancelledError;
18
+ }
19
+ //#endregion
20
+ export { UserCancelledError, isUserCancelled };
21
+
22
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Canonical signal that the user dismissed an interactive prompt (folder\n * picker, dialog, file picker, etc.). Throwing this class — instead of a\n * raw `DOMException` with `name === \"AbortError\"` or an ad-hoc string — lets\n * every consumer distinguish cancellation from real failure with a single\n * `instanceof` check.\n */\nexport class UserCancelledError extends Error {\n readonly name = \"UserCancelledError\";\n\n constructor(message = \"User cancelled the operation\") {\n super(message);\n }\n}\n\n/** Returns `true` if `err` is an instance of {@link UserCancelledError}. */\nexport function isUserCancelled(err: unknown): boolean {\n return err instanceof UserCancelledError;\n}\n"],"mappings":";;;;;;;;AAOA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,OAAgB;CAEhB,YAAY,UAAU,gCAAgC;EACpD,MAAM,OAAO;CACf;AACF;;AAGA,SAAgB,gBAAgB,KAAuB;CACrD,OAAO,eAAe;AACxB"}
@@ -0,0 +1,12 @@
1
+ import { getCommands, removeCommands, setCommands } from "./adapters.js";
2
+ import { COPY_TO_CLIPBOARD_COMMAND_KEY, CopyToClipboardCommand, CopyToClipboardPayload } from "./commands/copy-to-clipboard/index.js";
3
+ import { DOWNLOAD_BLOB_COMMAND_KEY, DownloadBlobCommand, DownloadBlobPayload } from "./commands/download-blob/index.js";
4
+ import { DOWNLOAD_TO_FILES_COMMAND_KEY, DownloadProgress, DownloadToFilesCommand, DownloadToFilesPayload, DownloadToFilesResult } from "./commands/download-to-files/index.js";
5
+ import { PICK_DIRECTORY_COMMAND_KEY, PickDirectoryCommand, PickDirectoryPayload, PickDirectoryResult } from "./commands/pick-directory/index.js";
6
+ import { PICK_FILE_COMMAND_KEY, PickFileCommand, PickFilePayload, PickFileResult } from "./commands/pick-file/index.js";
7
+ import { PREFERENCE_GET_COMMAND_KEY, PreferenceGetCommand, PreferenceGetPayload, PreferenceGetResult } from "./commands/preference-get/index.js";
8
+ import { PREFERENCE_SET_COMMAND_KEY, PreferenceSetCommand, PreferenceSetPayload } from "./commands/preference-set/index.js";
9
+ import "./commands/index.js";
10
+ import { UserCancelledError, isUserCancelled } from "./errors.js";
11
+ import { Navigation, UrlSerializer, UrlState, getUrlStateView, removeUrlStateView, setUrlStateView } from "./url-state-view.js";
12
+ export { COPY_TO_CLIPBOARD_COMMAND_KEY, CopyToClipboardCommand, CopyToClipboardPayload, DOWNLOAD_BLOB_COMMAND_KEY, DOWNLOAD_TO_FILES_COMMAND_KEY, DownloadBlobCommand, DownloadBlobPayload, DownloadProgress, DownloadToFilesCommand, DownloadToFilesPayload, DownloadToFilesResult, Navigation, Navigation as UrlStateView, PICK_DIRECTORY_COMMAND_KEY, PICK_FILE_COMMAND_KEY, PREFERENCE_GET_COMMAND_KEY, PREFERENCE_SET_COMMAND_KEY, PickDirectoryCommand, PickDirectoryPayload, PickDirectoryResult, PickFileCommand, PickFilePayload, PickFileResult, PreferenceGetCommand, PreferenceGetPayload, PreferenceGetResult, PreferenceSetCommand, PreferenceSetPayload, UrlSerializer, UrlState, UserCancelledError, getCommands, getUrlStateView, isUserCancelled, removeCommands, removeUrlStateView, setCommands, setUrlStateView };
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import { getCommands, removeCommands, setCommands } from "./adapters.js";
2
+ import { COPY_TO_CLIPBOARD_COMMAND_KEY, CopyToClipboardCommand } from "./commands/copy-to-clipboard/index.js";
3
+ import { DOWNLOAD_BLOB_COMMAND_KEY, DownloadBlobCommand } from "./commands/download-blob/index.js";
4
+ import { DOWNLOAD_TO_FILES_COMMAND_KEY, DownloadToFilesCommand } from "./commands/download-to-files/index.js";
5
+ import { PICK_DIRECTORY_COMMAND_KEY, PickDirectoryCommand } from "./commands/pick-directory/index.js";
6
+ import { PICK_FILE_COMMAND_KEY, PickFileCommand } from "./commands/pick-file/index.js";
7
+ import { PREFERENCE_GET_COMMAND_KEY, PreferenceGetCommand } from "./commands/preference-get/index.js";
8
+ import { PREFERENCE_SET_COMMAND_KEY, PreferenceSetCommand } from "./commands/preference-set/index.js";
9
+ import { UserCancelledError, isUserCancelled } from "./errors.js";
10
+ import { Navigation, getUrlStateView, removeUrlStateView, setUrlStateView } from "./url-state-view.js";
11
+ export { COPY_TO_CLIPBOARD_COMMAND_KEY, CopyToClipboardCommand, DOWNLOAD_BLOB_COMMAND_KEY, DOWNLOAD_TO_FILES_COMMAND_KEY, DownloadBlobCommand, DownloadToFilesCommand, Navigation, Navigation as UrlStateView, PICK_DIRECTORY_COMMAND_KEY, PICK_FILE_COMMAND_KEY, PREFERENCE_GET_COMMAND_KEY, PREFERENCE_SET_COMMAND_KEY, PickDirectoryCommand, PickFileCommand, PreferenceGetCommand, PreferenceSetCommand, UserCancelledError, getCommands, getUrlStateView, isUserCancelled, removeCommands, removeUrlStateView, setCommands, setUrlStateView };
@@ -0,0 +1,46 @@
1
+ import { BaseClass } from "@statewalker/shared-baseclass";
2
+ //#region src/url-state-view.d.ts
3
+ /**
4
+ * Serialized URL state — what gets written to / read from the URL hash.
5
+ */
6
+ export interface UrlState {
7
+ path: string;
8
+ query: Record<string, string>;
9
+ }
10
+ /**
11
+ * A reversible mapping between application state and the URL.
12
+ * `serialize` builds an outgoing URL state from the in-memory model;
13
+ * `deserialize` applies an incoming URL state back onto the model.
14
+ */
15
+ export interface UrlSerializer {
16
+ serialize(state: UrlState): UrlState;
17
+ deserialize(state: UrlState): void;
18
+ }
19
+ /**
20
+ * Navigation token — workspace-scoped bidirectional URL ↔ model state
21
+ * synchronisation. Apps reach the workspace-scoped instance via
22
+ * `workspace.requireAdapter(Navigation)`. Models register
23
+ * `UrlSerializer`s; the browser binding (provided by
24
+ * `@statewalker/platform-browser`) flushes the serialized state to
25
+ * `location.hash` whenever `sync()` notifies, and feeds incoming
26
+ * `hashchange` events back to all deserializers via `applyUrl()`.
27
+ *
28
+ * A directional lock prevents feedback loops: at any moment sync flows
29
+ * in only one direction.
30
+ *
31
+ * Inlined into `platform-api` (was re-exported from `workbench-views`)
32
+ * so the substrate can retire the legacy package — see the
33
+ * `workbench-canonical-substrate` capability spec.
34
+ */
35
+ export declare class Navigation extends BaseClass {
36
+ #private;
37
+ register(serializer: UrlSerializer): () => void;
38
+ sync(): void;
39
+ buildState(): UrlState;
40
+ applyUrl(state: UrlState): void;
41
+ get isSyncing(): boolean;
42
+ }
43
+ export declare const getUrlStateView: (context: Record<string, unknown>, optional?: boolean) => Navigation, setUrlStateView: (context: Record<string, unknown>, value: Navigation) => void, removeUrlStateView: (context: Record<string, unknown>) => void;
44
+ //#endregion
45
+ export { Navigation as UrlStateView };
46
+ //# sourceMappingURL=url-state-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-state-view.d.ts","names":[],"sources":["../src/url-state-view.ts"],"mappings":";;;;;iBAMiB;EACf;EACA,OAAO;;;;;;;iBAQQ;EACf,UAAU,OAAO,WAAW;EAC5B,YAAY,OAAO;;;;;;;;;;;;;;;;;;qBAmBR,mBAAmB;;EAI9B,SAAS,YAAY;EAOrB;EAUA,cAAc;EAQd,SAAS,OAAO;MAYZ;;qBAOQ,kBAAe,SAAA,yBAAA,uBAAA,YAAE,kBAAe,SAAA,yBAAA,OAAA,qBAAE,qBAAkB,SAAA"}
@@ -0,0 +1,63 @@
1
+ import { newAdapter } from "@statewalker/shared-adapters";
2
+ import { BaseClass } from "@statewalker/shared-baseclass";
3
+ //#region src/url-state-view.ts
4
+ /**
5
+ * Navigation token — workspace-scoped bidirectional URL ↔ model state
6
+ * synchronisation. Apps reach the workspace-scoped instance via
7
+ * `workspace.requireAdapter(Navigation)`. Models register
8
+ * `UrlSerializer`s; the browser binding (provided by
9
+ * `@statewalker/platform-browser`) flushes the serialized state to
10
+ * `location.hash` whenever `sync()` notifies, and feeds incoming
11
+ * `hashchange` events back to all deserializers via `applyUrl()`.
12
+ *
13
+ * A directional lock prevents feedback loops: at any moment sync flows
14
+ * in only one direction.
15
+ *
16
+ * Inlined into `platform-api` (was re-exported from `workbench-views`)
17
+ * so the substrate can retire the legacy package — see the
18
+ * `workbench-canonical-substrate` capability spec.
19
+ */
20
+ var Navigation = class extends BaseClass {
21
+ #serializers = /* @__PURE__ */ new Set();
22
+ #syncing = false;
23
+ register(serializer) {
24
+ this.#serializers.add(serializer);
25
+ return () => {
26
+ this.#serializers.delete(serializer);
27
+ };
28
+ }
29
+ sync() {
30
+ if (this.#syncing) return;
31
+ this.#syncing = true;
32
+ try {
33
+ this.notify();
34
+ } finally {
35
+ this.#syncing = false;
36
+ }
37
+ }
38
+ buildState() {
39
+ let state = {
40
+ path: "",
41
+ query: {}
42
+ };
43
+ for (const s of this.#serializers) state = s.serialize(state);
44
+ return state;
45
+ }
46
+ applyUrl(state) {
47
+ if (this.#syncing) return;
48
+ this.#syncing = true;
49
+ try {
50
+ for (const s of this.#serializers) s.deserialize(state);
51
+ } finally {
52
+ this.#syncing = false;
53
+ }
54
+ }
55
+ get isSyncing() {
56
+ return this.#syncing;
57
+ }
58
+ };
59
+ const [getUrlStateView, setUrlStateView, removeUrlStateView] = newAdapter("model:url-state", () => new Navigation());
60
+ //#endregion
61
+ export { Navigation, Navigation as UrlStateView, getUrlStateView, removeUrlStateView, setUrlStateView };
62
+
63
+ //# sourceMappingURL=url-state-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-state-view.js","names":[],"sources":["../src/url-state-view.ts"],"sourcesContent":["import { newAdapter } from \"@statewalker/shared-adapters\";\nimport { BaseClass } from \"@statewalker/shared-baseclass\";\n\n/**\n * Serialized URL state — what gets written to / read from the URL hash.\n */\nexport interface UrlState {\n path: string;\n query: Record<string, string>;\n}\n\n/**\n * A reversible mapping between application state and the URL.\n * `serialize` builds an outgoing URL state from the in-memory model;\n * `deserialize` applies an incoming URL state back onto the model.\n */\nexport interface UrlSerializer {\n serialize(state: UrlState): UrlState;\n deserialize(state: UrlState): void;\n}\n\n/**\n * Navigation token — workspace-scoped bidirectional URL ↔ model state\n * synchronisation. Apps reach the workspace-scoped instance via\n * `workspace.requireAdapter(Navigation)`. Models register\n * `UrlSerializer`s; the browser binding (provided by\n * `@statewalker/platform-browser`) flushes the serialized state to\n * `location.hash` whenever `sync()` notifies, and feeds incoming\n * `hashchange` events back to all deserializers via `applyUrl()`.\n *\n * A directional lock prevents feedback loops: at any moment sync flows\n * in only one direction.\n *\n * Inlined into `platform-api` (was re-exported from `workbench-views`)\n * so the substrate can retire the legacy package — see the\n * `workbench-canonical-substrate` capability spec.\n */\nexport class Navigation extends BaseClass {\n #serializers: Set<UrlSerializer> = new Set();\n #syncing = false;\n\n register(serializer: UrlSerializer): () => void {\n this.#serializers.add(serializer);\n return () => {\n this.#serializers.delete(serializer);\n };\n }\n\n sync(): void {\n if (this.#syncing) return;\n this.#syncing = true;\n try {\n this.notify();\n } finally {\n this.#syncing = false;\n }\n }\n\n buildState(): UrlState {\n let state: UrlState = { path: \"\", query: {} };\n for (const s of this.#serializers) {\n state = s.serialize(state);\n }\n return state;\n }\n\n applyUrl(state: UrlState): void {\n if (this.#syncing) return;\n this.#syncing = true;\n try {\n for (const s of this.#serializers) {\n s.deserialize(state);\n }\n } finally {\n this.#syncing = false;\n }\n }\n\n get isSyncing(): boolean {\n return this.#syncing;\n }\n}\n\nexport { Navigation as UrlStateView };\n\nexport const [getUrlStateView, setUrlStateView, removeUrlStateView] = newAdapter<Navigation>(\n \"model:url-state\",\n () => new Navigation(),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqCA,IAAa,aAAb,cAAgC,UAAU;CACxC,+BAAmC,IAAI,IAAI;CAC3C,WAAW;CAEX,SAAS,YAAuC;EAC9C,KAAK,aAAa,IAAI,UAAU;EAChC,aAAa;GACX,KAAK,aAAa,OAAO,UAAU;EACrC;CACF;CAEA,OAAa;EACX,IAAI,KAAK,UAAU;EACnB,KAAK,WAAW;EAChB,IAAI;GACF,KAAK,OAAO;EACd,UAAU;GACR,KAAK,WAAW;EAClB;CACF;CAEA,aAAuB;EACrB,IAAI,QAAkB;GAAE,MAAM;GAAI,OAAO,CAAC;EAAE;EAC5C,KAAK,MAAM,KAAK,KAAK,cACnB,QAAQ,EAAE,UAAU,KAAK;EAE3B,OAAO;CACT;CAEA,SAAS,OAAuB;EAC9B,IAAI,KAAK,UAAU;EACnB,KAAK,WAAW;EAChB,IAAI;GACF,KAAK,MAAM,KAAK,KAAK,cACnB,EAAE,YAAY,KAAK;EAEvB,UAAU;GACR,KAAK,WAAW;EAClB;CACF;CAEA,IAAI,YAAqB;EACvB,OAAO,KAAK;CACd;AACF;AAIA,MAAa,CAAC,iBAAiB,iBAAiB,sBAAsB,WACpE,yBACM,IAAI,WAAW,CACvB"}
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@statewalker/platform.core",
3
- "version": "0.1.1",
3
+ "version": "0.5.2",
4
4
  "private": false,
5
5
  "type": "module",
6
- "description": "Platform-capability intent vocabulary shared by every application composed of statewalker-workbench fragments.",
7
- "homepage": "https://github.com/statewalker/statewalker-workbench",
6
+ "description": "Platform-capability command declarations (pickers, downloads, clipboard, preferences, URL state) shared by statewalker fragments.",
7
+ "bugs": {
8
+ "url": "https://github.com/statewalker/statewalker-kernel/issues"
9
+ },
10
+ "homepage": "https://github.com/statewalker/statewalker-kernel/tree/main/packages/platform.core#readme",
8
11
  "author": {
9
12
  "name": "Mikhail Kotelnikov",
10
13
  "email": "mikhail.kotelnikov@gmail.com"
@@ -12,10 +15,16 @@
12
15
  "license": "MIT",
13
16
  "repository": {
14
17
  "type": "git",
15
- "url": "git+ssh://git@github.com/statewalker/statewalker-workbench.git"
18
+ "url": "git+https://github.com/statewalker/statewalker-kernel.git",
19
+ "directory": "packages/platform.core"
16
20
  },
17
21
  "exports": {
18
- ".": "./src/index.ts"
22
+ ".": {
23
+ "source": "./src/index.ts",
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "default": "./dist/index.js"
27
+ }
19
28
  },
20
29
  "files": [
21
30
  "dist",
@@ -25,14 +34,14 @@
25
34
  "@statewalker/shared-adapters": "^0.1.0",
26
35
  "@statewalker/shared-baseclass": "^0.1.0",
27
36
  "@statewalker/shared-commands": "^0.2.0",
28
- "@statewalker/webrun-files": "^0.7.0",
29
- "@statewalker/workspace.core": "0.1.1"
37
+ "@statewalker/webrun-files": "^0.10.0",
38
+ "@statewalker/workspace.core": "^0.5.2"
30
39
  },
31
40
  "devDependencies": {
32
41
  "rimraf": "^6.1.3",
33
- "tsdown": "^0.22.14",
42
+ "tsdown": "^0.23.0",
34
43
  "typescript": "^7.0.2",
35
- "vitest": "^4.1.10"
44
+ "vitest": "^5.0.3"
36
45
  },
37
46
  "sideEffects": false,
38
47
  "publishConfig": {
@@ -6,7 +6,7 @@ export interface CopyToClipboardPayload {
6
6
  text: string;
7
7
  }
8
8
 
9
- export const CopyToClipboardCommand = Command.silent(COPY_TO_CLIPBOARD_COMMAND_KEY)
9
+ export const CopyToClipboardCommand = Command.async(COPY_TO_CLIPBOARD_COMMAND_KEY)
10
10
  .input(passthrough<CopyToClipboardPayload>())
11
11
  .output(passthrough<void>())
12
12
  .build();
@@ -7,7 +7,7 @@ export interface DownloadBlobPayload {
7
7
  filename: string;
8
8
  }
9
9
 
10
- export const DownloadBlobCommand = Command.silent(DOWNLOAD_BLOB_COMMAND_KEY)
10
+ export const DownloadBlobCommand = Command.async(DOWNLOAD_BLOB_COMMAND_KEY)
11
11
  .input(passthrough<DownloadBlobPayload>())
12
12
  .output(passthrough<void>())
13
13
  .build();
@@ -21,7 +21,7 @@ export interface DownloadToFilesResult {
21
21
  bytes: number;
22
22
  }
23
23
 
24
- export const DownloadToFilesCommand = Command.silent(DOWNLOAD_TO_FILES_COMMAND_KEY)
24
+ export const DownloadToFilesCommand = Command.async(DOWNLOAD_TO_FILES_COMMAND_KEY)
25
25
  .input(passthrough<DownloadToFilesPayload>())
26
26
  .output(passthrough<DownloadToFilesResult>())
27
27
  .build();
@@ -12,7 +12,7 @@ export interface PickDirectoryResult {
12
12
  label: string;
13
13
  }
14
14
 
15
- export const PickDirectoryCommand = Command.silent(PICK_DIRECTORY_COMMAND_KEY)
15
+ export const PickDirectoryCommand = Command.async(PICK_DIRECTORY_COMMAND_KEY)
16
16
  .input(passthrough<PickDirectoryPayload>())
17
17
  .output(passthrough<PickDirectoryResult>())
18
18
  .build();
@@ -13,7 +13,7 @@ export interface PickFileResult {
13
13
  names: string[];
14
14
  }
15
15
 
16
- export const PickFileCommand = Command.silent(PICK_FILE_COMMAND_KEY)
16
+ export const PickFileCommand = Command.async(PICK_FILE_COMMAND_KEY)
17
17
  .input(passthrough<PickFilePayload>())
18
18
  .output(passthrough<PickFileResult>())
19
19
  .build();
@@ -10,7 +10,7 @@ export interface PreferenceGetResult {
10
10
  value: unknown | undefined;
11
11
  }
12
12
 
13
- export const PreferenceGetCommand = Command.silent(PREFERENCE_GET_COMMAND_KEY)
13
+ export const PreferenceGetCommand = Command.async(PREFERENCE_GET_COMMAND_KEY)
14
14
  .input(passthrough<PreferenceGetPayload>())
15
15
  .output(passthrough<PreferenceGetResult>())
16
16
  .build();
@@ -7,7 +7,7 @@ export interface PreferenceSetPayload {
7
7
  value: unknown;
8
8
  }
9
9
 
10
- export const PreferenceSetCommand = Command.silent(PREFERENCE_SET_COMMAND_KEY)
10
+ export const PreferenceSetCommand = Command.async(PREFERENCE_SET_COMMAND_KEY)
11
11
  .input(passthrough<PreferenceSetPayload>())
12
12
  .output(passthrough<void>())
13
13
  .build();
package/dist/index.d.mts DELETED
@@ -1,160 +0,0 @@
1
- import { Commands } from "@statewalker/shared-commands";
2
- import { BaseClass } from "@statewalker/shared-baseclass";
3
- import { FilesApi } from "@statewalker/webrun-files";
4
- //#region src/adapters.d.ts
5
- /**
6
- * Resolve the workspace-scoped `Commands` bus for the given context bag.
7
- * Delegates to `workspace.requireAdapter(Commands)`, which auto-instantiates
8
- * a single shared bus on first lookup so every fragment composed under the
9
- * same workspace dispatches through the same instance.
10
- */
11
- declare function getCommands(ctx: Record<string, unknown>): Commands;
12
- /**
13
- * @deprecated The commands bus is now workspace-scoped and auto-instantiated;
14
- * explicit registration is a no-op. Kept for one release so legacy bootstrap
15
- * code keeps compiling. Will be removed in a follow-up phase.
16
- */
17
- declare function setCommands(_ctx: Record<string, unknown>, _commands: Commands): void;
18
- /**
19
- * @deprecated The commands bus is now workspace-scoped and lifecycle-managed by
20
- * the workspace; explicit removal is a no-op. Kept for one release so legacy
21
- * teardown code keeps compiling. Will be removed in a follow-up phase.
22
- */
23
- declare function removeCommands(_ctx: Record<string, unknown>): void;
24
- //#endregion
25
- //#region src/commands/copy-to-clipboard/index.d.ts
26
- declare const COPY_TO_CLIPBOARD_COMMAND_KEY = "platform:copy-to-clipboard";
27
- interface CopyToClipboardPayload {
28
- text: string;
29
- }
30
- declare const CopyToClipboardCommand: import("@statewalker/shared-commands").CommandDeclaration<CopyToClipboardPayload, void>;
31
- //#endregion
32
- //#region src/commands/download-blob/index.d.ts
33
- declare const DOWNLOAD_BLOB_COMMAND_KEY = "platform:download-blob";
34
- interface DownloadBlobPayload {
35
- blob: Blob;
36
- filename: string;
37
- }
38
- declare const DownloadBlobCommand: import("@statewalker/shared-commands").CommandDeclaration<DownloadBlobPayload, void>;
39
- //#endregion
40
- //#region src/commands/download-to-files/index.d.ts
41
- declare const DOWNLOAD_TO_FILES_COMMAND_KEY = "platform:download-to-files";
42
- interface DownloadProgress {
43
- loaded: number;
44
- total?: number;
45
- }
46
- interface DownloadToFilesPayload {
47
- url: string;
48
- files: FilesApi;
49
- path: string;
50
- resume?: boolean;
51
- onProgress?: (progress: DownloadProgress) => void;
52
- signal?: AbortSignal;
53
- }
54
- interface DownloadToFilesResult {
55
- bytes: number;
56
- }
57
- declare const DownloadToFilesCommand: import("@statewalker/shared-commands").CommandDeclaration<DownloadToFilesPayload, DownloadToFilesResult>;
58
- //#endregion
59
- //#region src/commands/pick-directory/index.d.ts
60
- declare const PICK_DIRECTORY_COMMAND_KEY = "platform:pick-directory";
61
- interface PickDirectoryPayload {
62
- title?: string;
63
- }
64
- interface PickDirectoryResult {
65
- files: FilesApi;
66
- label: string;
67
- }
68
- declare const PickDirectoryCommand: import("@statewalker/shared-commands").CommandDeclaration<PickDirectoryPayload, PickDirectoryResult>;
69
- //#endregion
70
- //#region src/commands/pick-file/index.d.ts
71
- declare const PICK_FILE_COMMAND_KEY = "platform:pick-file";
72
- interface PickFilePayload {
73
- title?: string;
74
- accept?: string[];
75
- multiple?: boolean;
76
- }
77
- interface PickFileResult {
78
- blobs: Blob[];
79
- names: string[];
80
- }
81
- declare const PickFileCommand: import("@statewalker/shared-commands").CommandDeclaration<PickFilePayload, PickFileResult>;
82
- //#endregion
83
- //#region src/commands/preference-get/index.d.ts
84
- declare const PREFERENCE_GET_COMMAND_KEY = "platform:preference-get";
85
- interface PreferenceGetPayload {
86
- key: string;
87
- }
88
- interface PreferenceGetResult {
89
- value: unknown | undefined;
90
- }
91
- declare const PreferenceGetCommand: import("@statewalker/shared-commands").CommandDeclaration<PreferenceGetPayload, PreferenceGetResult>;
92
- //#endregion
93
- //#region src/commands/preference-set/index.d.ts
94
- declare const PREFERENCE_SET_COMMAND_KEY = "platform:preference-set";
95
- interface PreferenceSetPayload {
96
- key: string;
97
- value: unknown;
98
- }
99
- declare const PreferenceSetCommand: import("@statewalker/shared-commands").CommandDeclaration<PreferenceSetPayload, void>;
100
- //#endregion
101
- //#region src/errors.d.ts
102
- /**
103
- * Canonical signal that the user dismissed an interactive prompt (folder
104
- * picker, dialog, file picker, etc.). Throwing this class — instead of a
105
- * raw `DOMException` with `name === "AbortError"` or an ad-hoc string — lets
106
- * every consumer distinguish cancellation from real failure with a single
107
- * `instanceof` check.
108
- */
109
- declare class UserCancelledError extends Error {
110
- readonly name = "UserCancelledError";
111
- constructor(message?: string);
112
- }
113
- /** Returns `true` if `err` is an instance of {@link UserCancelledError}. */
114
- declare function isUserCancelled(err: unknown): boolean;
115
- //#endregion
116
- //#region src/url-state-view.d.ts
117
- /**
118
- * Serialized URL state — what gets written to / read from the URL hash.
119
- */
120
- interface UrlState {
121
- path: string;
122
- query: Record<string, string>;
123
- }
124
- /**
125
- * A reversible mapping between application state and the URL.
126
- * `serialize` builds an outgoing URL state from the in-memory model;
127
- * `deserialize` applies an incoming URL state back onto the model.
128
- */
129
- interface UrlSerializer {
130
- serialize(state: UrlState): UrlState;
131
- deserialize(state: UrlState): void;
132
- }
133
- /**
134
- * Navigation token — workspace-scoped bidirectional URL ↔ model state
135
- * synchronisation. Apps reach the workspace-scoped instance via
136
- * `workspace.requireAdapter(Navigation)`. Models register
137
- * `UrlSerializer`s; the browser binding (provided by
138
- * `@statewalker/platform-browser`) flushes the serialized state to
139
- * `location.hash` whenever `sync()` notifies, and feeds incoming
140
- * `hashchange` events back to all deserializers via `applyUrl()`.
141
- *
142
- * A directional lock prevents feedback loops: at any moment sync flows
143
- * in only one direction.
144
- *
145
- * Inlined into `platform-api` (was re-exported from `workbench-views`)
146
- * so the substrate can retire the legacy package — see the
147
- * `workbench-canonical-substrate` capability spec.
148
- */
149
- declare class Navigation extends BaseClass {
150
- #private;
151
- register(serializer: UrlSerializer): () => void;
152
- sync(): void;
153
- buildState(): UrlState;
154
- applyUrl(state: UrlState): void;
155
- get isSyncing(): boolean;
156
- }
157
- declare const getUrlStateView: (context: Record<string, unknown>, optional?: boolean) => Navigation, setUrlStateView: (context: Record<string, unknown>, value: Navigation) => void, removeUrlStateView: (context: Record<string, unknown>) => void;
158
- //#endregion
159
- export { COPY_TO_CLIPBOARD_COMMAND_KEY, CopyToClipboardCommand, CopyToClipboardPayload, DOWNLOAD_BLOB_COMMAND_KEY, DOWNLOAD_TO_FILES_COMMAND_KEY, DownloadBlobCommand, DownloadBlobPayload, DownloadProgress, DownloadToFilesCommand, DownloadToFilesPayload, DownloadToFilesResult, Navigation, Navigation as UrlStateView, PICK_DIRECTORY_COMMAND_KEY, PICK_FILE_COMMAND_KEY, PREFERENCE_GET_COMMAND_KEY, PREFERENCE_SET_COMMAND_KEY, PickDirectoryCommand, PickDirectoryPayload, PickDirectoryResult, PickFileCommand, PickFilePayload, PickFileResult, PreferenceGetCommand, PreferenceGetPayload, PreferenceGetResult, PreferenceSetCommand, PreferenceSetPayload, UrlSerializer, UrlState, UserCancelledError, getCommands, getUrlStateView, isUserCancelled, removeCommands, removeUrlStateView, setCommands, setUrlStateView };
160
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/adapters.ts","../src/commands/copy-to-clipboard/index.ts","../src/commands/download-blob/index.ts","../src/commands/download-to-files/index.ts","../src/commands/pick-directory/index.ts","../src/commands/pick-file/index.ts","../src/commands/preference-get/index.ts","../src/commands/preference-set/index.ts","../src/errors.ts","../src/url-state-view.ts"],"mappings":";;;;;;;;;;iBASgB,YAAY,KAAK,0BAA0B;;;;;;iBAS3C,YAAY,MAAM,yBAAyB,WAAW;;;;;;iBAWtD,eAAe,MAAM;;;cC3BxB;UAEI;EACf;;cAGW,+DAAsB,mBAAA;;;cCNtB;UAEI;EACf,MAAM;EACN;;cAGW,4DAAmB,mBAAA;;;cCNnB;UAEI;EACf;EACA;;UAGe;EACf;EACA,OAAO;EACP;EACA;EACA,cAAc,UAAU;EACxB,SAAS;;UAGM;EACf;;cAGW,+DAAsB,mBAAA,wBAAA;;;cCpBtB;UAEI;EACf;;UAGe;EACf,OAAO;EACP;;cAGW,6DAAoB,mBAAA,sBAAA;;;cCZpB;UAEI;EACf;EACA;EACA;;UAGe;EACf,OAAO;EACP;;cAGW,wDAAe,mBAAA,iBAAA;;;cCbf;UAEI;EACf;;UAGe;EACf;;cAGW,6DAAoB,mBAAA,sBAAA;;;cCVpB;UAEI;EACf;EACA;;cAGW,6DAAoB,mBAAA;;;;;;;;;;cCFpB,2BAA2B;WAC7B;EAET,YAAY;;;iBAME,gBAAgB;;;;;;UCVf;EACf;EACA,OAAO;;;;;;;UAQQ;EACf,UAAU,OAAO,WAAW;EAC5B,YAAY,OAAO;;;;;;;;;;;;;;;;;;cAmBR,mBAAmB;;EAI9B,SAAS,YAAY;EAOrB;EAUA,cAAc;EAQd,SAAS,OAAO;MAYZ;;cAOQ,kBAAe,SAAA,yBAAA,uBAAA,YAAE,kBAAe,SAAA,yBAAA,OAAA,qBAAE,qBAAkB,SAAA"}
package/dist/index.mjs DELETED
@@ -1,139 +0,0 @@
1
- import { Command, Commands, passthrough } from "@statewalker/shared-commands";
2
- import { getWorkspace } from "@statewalker/workspace.core";
3
- import { newAdapter } from "@statewalker/shared-adapters";
4
- import { BaseClass } from "@statewalker/shared-baseclass";
5
- //#region src/adapters.ts
6
- /**
7
- * Resolve the workspace-scoped `Commands` bus for the given context bag.
8
- * Delegates to `workspace.requireAdapter(Commands)`, which auto-instantiates
9
- * a single shared bus on first lookup so every fragment composed under the
10
- * same workspace dispatches through the same instance.
11
- */
12
- function getCommands(ctx) {
13
- return getWorkspace(ctx).requireAdapter(Commands);
14
- }
15
- /**
16
- * @deprecated The commands bus is now workspace-scoped and auto-instantiated;
17
- * explicit registration is a no-op. Kept for one release so legacy bootstrap
18
- * code keeps compiling. Will be removed in a follow-up phase.
19
- */
20
- function setCommands(_ctx, _commands) {
21
- console.warn("[platform-api] setCommands is deprecated and a no-op: the Commands bus is now workspace-bound and auto-instantiated via workspace.requireAdapter(Commands).");
22
- }
23
- /**
24
- * @deprecated The commands bus is now workspace-scoped and lifecycle-managed by
25
- * the workspace; explicit removal is a no-op. Kept for one release so legacy
26
- * teardown code keeps compiling. Will be removed in a follow-up phase.
27
- */
28
- function removeCommands(_ctx) {
29
- console.warn("[platform-api] removeCommands is deprecated and a no-op: the Commands bus lifecycle is owned by workspace.close().");
30
- }
31
- //#endregion
32
- //#region src/commands/copy-to-clipboard/index.ts
33
- const COPY_TO_CLIPBOARD_COMMAND_KEY = "platform:copy-to-clipboard";
34
- const CopyToClipboardCommand = Command.silent(COPY_TO_CLIPBOARD_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
35
- //#endregion
36
- //#region src/commands/download-blob/index.ts
37
- const DOWNLOAD_BLOB_COMMAND_KEY = "platform:download-blob";
38
- const DownloadBlobCommand = Command.silent(DOWNLOAD_BLOB_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
39
- //#endregion
40
- //#region src/commands/download-to-files/index.ts
41
- const DOWNLOAD_TO_FILES_COMMAND_KEY = "platform:download-to-files";
42
- const DownloadToFilesCommand = Command.silent(DOWNLOAD_TO_FILES_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
43
- //#endregion
44
- //#region src/commands/pick-directory/index.ts
45
- const PICK_DIRECTORY_COMMAND_KEY = "platform:pick-directory";
46
- const PickDirectoryCommand = Command.silent(PICK_DIRECTORY_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
47
- //#endregion
48
- //#region src/commands/pick-file/index.ts
49
- const PICK_FILE_COMMAND_KEY = "platform:pick-file";
50
- const PickFileCommand = Command.silent(PICK_FILE_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
51
- //#endregion
52
- //#region src/commands/preference-get/index.ts
53
- const PREFERENCE_GET_COMMAND_KEY = "platform:preference-get";
54
- const PreferenceGetCommand = Command.silent(PREFERENCE_GET_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
55
- //#endregion
56
- //#region src/commands/preference-set/index.ts
57
- const PREFERENCE_SET_COMMAND_KEY = "platform:preference-set";
58
- const PreferenceSetCommand = Command.silent(PREFERENCE_SET_COMMAND_KEY).input(passthrough()).output(passthrough()).build();
59
- //#endregion
60
- //#region src/errors.ts
61
- /**
62
- * Canonical signal that the user dismissed an interactive prompt (folder
63
- * picker, dialog, file picker, etc.). Throwing this class — instead of a
64
- * raw `DOMException` with `name === "AbortError"` or an ad-hoc string — lets
65
- * every consumer distinguish cancellation from real failure with a single
66
- * `instanceof` check.
67
- */
68
- var UserCancelledError = class extends Error {
69
- name = "UserCancelledError";
70
- constructor(message = "User cancelled the operation") {
71
- super(message);
72
- }
73
- };
74
- /** Returns `true` if `err` is an instance of {@link UserCancelledError}. */
75
- function isUserCancelled(err) {
76
- return err instanceof UserCancelledError;
77
- }
78
- //#endregion
79
- //#region src/url-state-view.ts
80
- /**
81
- * Navigation token — workspace-scoped bidirectional URL ↔ model state
82
- * synchronisation. Apps reach the workspace-scoped instance via
83
- * `workspace.requireAdapter(Navigation)`. Models register
84
- * `UrlSerializer`s; the browser binding (provided by
85
- * `@statewalker/platform-browser`) flushes the serialized state to
86
- * `location.hash` whenever `sync()` notifies, and feeds incoming
87
- * `hashchange` events back to all deserializers via `applyUrl()`.
88
- *
89
- * A directional lock prevents feedback loops: at any moment sync flows
90
- * in only one direction.
91
- *
92
- * Inlined into `platform-api` (was re-exported from `workbench-views`)
93
- * so the substrate can retire the legacy package — see the
94
- * `workbench-canonical-substrate` capability spec.
95
- */
96
- var Navigation = class extends BaseClass {
97
- #serializers = /* @__PURE__ */ new Set();
98
- #syncing = false;
99
- register(serializer) {
100
- this.#serializers.add(serializer);
101
- return () => {
102
- this.#serializers.delete(serializer);
103
- };
104
- }
105
- sync() {
106
- if (this.#syncing) return;
107
- this.#syncing = true;
108
- try {
109
- this.notify();
110
- } finally {
111
- this.#syncing = false;
112
- }
113
- }
114
- buildState() {
115
- let state = {
116
- path: "",
117
- query: {}
118
- };
119
- for (const s of this.#serializers) state = s.serialize(state);
120
- return state;
121
- }
122
- applyUrl(state) {
123
- if (this.#syncing) return;
124
- this.#syncing = true;
125
- try {
126
- for (const s of this.#serializers) s.deserialize(state);
127
- } finally {
128
- this.#syncing = false;
129
- }
130
- }
131
- get isSyncing() {
132
- return this.#syncing;
133
- }
134
- };
135
- const [getUrlStateView, setUrlStateView, removeUrlStateView] = newAdapter("model:url-state", () => new Navigation());
136
- //#endregion
137
- export { COPY_TO_CLIPBOARD_COMMAND_KEY, CopyToClipboardCommand, DOWNLOAD_BLOB_COMMAND_KEY, DOWNLOAD_TO_FILES_COMMAND_KEY, DownloadBlobCommand, DownloadToFilesCommand, Navigation, Navigation as UrlStateView, PICK_DIRECTORY_COMMAND_KEY, PICK_FILE_COMMAND_KEY, PREFERENCE_GET_COMMAND_KEY, PREFERENCE_SET_COMMAND_KEY, PickDirectoryCommand, PickFileCommand, PreferenceGetCommand, PreferenceSetCommand, UserCancelledError, getCommands, getUrlStateView, isUserCancelled, removeCommands, removeUrlStateView, setCommands, setUrlStateView };
138
-
139
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/adapters.ts","../src/commands/copy-to-clipboard/index.ts","../src/commands/download-blob/index.ts","../src/commands/download-to-files/index.ts","../src/commands/pick-directory/index.ts","../src/commands/pick-file/index.ts","../src/commands/preference-get/index.ts","../src/commands/preference-set/index.ts","../src/errors.ts","../src/url-state-view.ts"],"sourcesContent":["import { Commands } from \"@statewalker/shared-commands\";\nimport { getWorkspace } from \"@statewalker/workspace.core\";\n\n/**\n * Resolve the workspace-scoped `Commands` bus for the given context bag.\n * Delegates to `workspace.requireAdapter(Commands)`, which auto-instantiates\n * a single shared bus on first lookup so every fragment composed under the\n * same workspace dispatches through the same instance.\n */\nexport function getCommands(ctx: Record<string, unknown>): Commands {\n return getWorkspace(ctx).requireAdapter(Commands);\n}\n\n/**\n * @deprecated The commands bus is now workspace-scoped and auto-instantiated;\n * explicit registration is a no-op. Kept for one release so legacy bootstrap\n * code keeps compiling. Will be removed in a follow-up phase.\n */\nexport function setCommands(_ctx: Record<string, unknown>, _commands: Commands): void {\n console.warn(\n \"[platform-api] setCommands is deprecated and a no-op: the Commands bus is now workspace-bound and auto-instantiated via workspace.requireAdapter(Commands).\",\n );\n}\n\n/**\n * @deprecated The commands bus is now workspace-scoped and lifecycle-managed by\n * the workspace; explicit removal is a no-op. Kept for one release so legacy\n * teardown code keeps compiling. Will be removed in a follow-up phase.\n */\nexport function removeCommands(_ctx: Record<string, unknown>): void {\n console.warn(\n \"[platform-api] removeCommands is deprecated and a no-op: the Commands bus lifecycle is owned by workspace.close().\",\n );\n}\n","import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const COPY_TO_CLIPBOARD_COMMAND_KEY = \"platform:copy-to-clipboard\";\n\nexport interface CopyToClipboardPayload {\n text: string;\n}\n\nexport const CopyToClipboardCommand = Command.silent(COPY_TO_CLIPBOARD_COMMAND_KEY)\n .input(passthrough<CopyToClipboardPayload>())\n .output(passthrough<void>())\n .build();\n","import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const DOWNLOAD_BLOB_COMMAND_KEY = \"platform:download-blob\";\n\nexport interface DownloadBlobPayload {\n blob: Blob;\n filename: string;\n}\n\nexport const DownloadBlobCommand = Command.silent(DOWNLOAD_BLOB_COMMAND_KEY)\n .input(passthrough<DownloadBlobPayload>())\n .output(passthrough<void>())\n .build();\n","import { Command, passthrough } from \"@statewalker/shared-commands\";\nimport type { FilesApi } from \"@statewalker/webrun-files\";\n\nexport const DOWNLOAD_TO_FILES_COMMAND_KEY = \"platform:download-to-files\";\n\nexport interface DownloadProgress {\n loaded: number;\n total?: number;\n}\n\nexport interface DownloadToFilesPayload {\n url: string;\n files: FilesApi;\n path: string;\n resume?: boolean;\n onProgress?: (progress: DownloadProgress) => void;\n signal?: AbortSignal;\n}\n\nexport interface DownloadToFilesResult {\n bytes: number;\n}\n\nexport const DownloadToFilesCommand = Command.silent(DOWNLOAD_TO_FILES_COMMAND_KEY)\n .input(passthrough<DownloadToFilesPayload>())\n .output(passthrough<DownloadToFilesResult>())\n .build();\n","import { Command, passthrough } from \"@statewalker/shared-commands\";\nimport type { FilesApi } from \"@statewalker/webrun-files\";\n\nexport const PICK_DIRECTORY_COMMAND_KEY = \"platform:pick-directory\";\n\nexport interface PickDirectoryPayload {\n title?: string;\n}\n\nexport interface PickDirectoryResult {\n files: FilesApi;\n label: string;\n}\n\nexport const PickDirectoryCommand = Command.silent(PICK_DIRECTORY_COMMAND_KEY)\n .input(passthrough<PickDirectoryPayload>())\n .output(passthrough<PickDirectoryResult>())\n .build();\n","import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const PICK_FILE_COMMAND_KEY = \"platform:pick-file\";\n\nexport interface PickFilePayload {\n title?: string;\n accept?: string[];\n multiple?: boolean;\n}\n\nexport interface PickFileResult {\n blobs: Blob[];\n names: string[];\n}\n\nexport const PickFileCommand = Command.silent(PICK_FILE_COMMAND_KEY)\n .input(passthrough<PickFilePayload>())\n .output(passthrough<PickFileResult>())\n .build();\n","import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const PREFERENCE_GET_COMMAND_KEY = \"platform:preference-get\";\n\nexport interface PreferenceGetPayload {\n key: string;\n}\n\nexport interface PreferenceGetResult {\n value: unknown | undefined;\n}\n\nexport const PreferenceGetCommand = Command.silent(PREFERENCE_GET_COMMAND_KEY)\n .input(passthrough<PreferenceGetPayload>())\n .output(passthrough<PreferenceGetResult>())\n .build();\n","import { Command, passthrough } from \"@statewalker/shared-commands\";\n\nexport const PREFERENCE_SET_COMMAND_KEY = \"platform:preference-set\";\n\nexport interface PreferenceSetPayload {\n key: string;\n value: unknown;\n}\n\nexport const PreferenceSetCommand = Command.silent(PREFERENCE_SET_COMMAND_KEY)\n .input(passthrough<PreferenceSetPayload>())\n .output(passthrough<void>())\n .build();\n","/**\n * Canonical signal that the user dismissed an interactive prompt (folder\n * picker, dialog, file picker, etc.). Throwing this class — instead of a\n * raw `DOMException` with `name === \"AbortError\"` or an ad-hoc string — lets\n * every consumer distinguish cancellation from real failure with a single\n * `instanceof` check.\n */\nexport class UserCancelledError extends Error {\n readonly name = \"UserCancelledError\";\n\n constructor(message = \"User cancelled the operation\") {\n super(message);\n }\n}\n\n/** Returns `true` if `err` is an instance of {@link UserCancelledError}. */\nexport function isUserCancelled(err: unknown): boolean {\n return err instanceof UserCancelledError;\n}\n","import { newAdapter } from \"@statewalker/shared-adapters\";\nimport { BaseClass } from \"@statewalker/shared-baseclass\";\n\n/**\n * Serialized URL state — what gets written to / read from the URL hash.\n */\nexport interface UrlState {\n path: string;\n query: Record<string, string>;\n}\n\n/**\n * A reversible mapping between application state and the URL.\n * `serialize` builds an outgoing URL state from the in-memory model;\n * `deserialize` applies an incoming URL state back onto the model.\n */\nexport interface UrlSerializer {\n serialize(state: UrlState): UrlState;\n deserialize(state: UrlState): void;\n}\n\n/**\n * Navigation token — workspace-scoped bidirectional URL ↔ model state\n * synchronisation. Apps reach the workspace-scoped instance via\n * `workspace.requireAdapter(Navigation)`. Models register\n * `UrlSerializer`s; the browser binding (provided by\n * `@statewalker/platform-browser`) flushes the serialized state to\n * `location.hash` whenever `sync()` notifies, and feeds incoming\n * `hashchange` events back to all deserializers via `applyUrl()`.\n *\n * A directional lock prevents feedback loops: at any moment sync flows\n * in only one direction.\n *\n * Inlined into `platform-api` (was re-exported from `workbench-views`)\n * so the substrate can retire the legacy package — see the\n * `workbench-canonical-substrate` capability spec.\n */\nexport class Navigation extends BaseClass {\n #serializers: Set<UrlSerializer> = new Set();\n #syncing = false;\n\n register(serializer: UrlSerializer): () => void {\n this.#serializers.add(serializer);\n return () => {\n this.#serializers.delete(serializer);\n };\n }\n\n sync(): void {\n if (this.#syncing) return;\n this.#syncing = true;\n try {\n this.notify();\n } finally {\n this.#syncing = false;\n }\n }\n\n buildState(): UrlState {\n let state: UrlState = { path: \"\", query: {} };\n for (const s of this.#serializers) {\n state = s.serialize(state);\n }\n return state;\n }\n\n applyUrl(state: UrlState): void {\n if (this.#syncing) return;\n this.#syncing = true;\n try {\n for (const s of this.#serializers) {\n s.deserialize(state);\n }\n } finally {\n this.#syncing = false;\n }\n }\n\n get isSyncing(): boolean {\n return this.#syncing;\n }\n}\n\nexport { Navigation as UrlStateView };\n\nexport const [getUrlStateView, setUrlStateView, removeUrlStateView] = newAdapter<Navigation>(\n \"model:url-state\",\n () => new Navigation(),\n);\n"],"mappings":";;;;;;;;;;;AASA,SAAgB,YAAY,KAAwC;CAClE,OAAO,aAAa,GAAG,CAAC,CAAC,eAAe,QAAQ;AAClD;;;;;;AAOA,SAAgB,YAAY,MAA+B,WAA2B;CACpF,QAAQ,KACN,6JACF;AACF;;;;;;AAOA,SAAgB,eAAe,MAAqC;CAClE,QAAQ,KACN,oHACF;AACF;;;AC/BA,MAAa,gCAAgC;AAM7C,MAAa,yBAAyB,QAAQ,OAAO,6BAA6B,CAAC,CAChF,MAAM,YAAoC,CAAC,CAAC,CAC5C,OAAO,YAAkB,CAAC,CAAC,CAC3B,MAAM;;;ACTT,MAAa,4BAA4B;AAOzC,MAAa,sBAAsB,QAAQ,OAAO,yBAAyB,CAAC,CACzE,MAAM,YAAiC,CAAC,CAAC,CACzC,OAAO,YAAkB,CAAC,CAAC,CAC3B,MAAM;;;ACTT,MAAa,gCAAgC;AAoB7C,MAAa,yBAAyB,QAAQ,OAAO,6BAA6B,CAAC,CAChF,MAAM,YAAoC,CAAC,CAAC,CAC5C,OAAO,YAAmC,CAAC,CAAC,CAC5C,MAAM;;;ACvBT,MAAa,6BAA6B;AAW1C,MAAa,uBAAuB,QAAQ,OAAO,0BAA0B,CAAC,CAC3E,MAAM,YAAkC,CAAC,CAAC,CAC1C,OAAO,YAAiC,CAAC,CAAC,CAC1C,MAAM;;;ACfT,MAAa,wBAAwB;AAarC,MAAa,kBAAkB,QAAQ,OAAO,qBAAqB,CAAC,CACjE,MAAM,YAA6B,CAAC,CAAC,CACrC,OAAO,YAA4B,CAAC,CAAC,CACrC,MAAM;;;AChBT,MAAa,6BAA6B;AAU1C,MAAa,uBAAuB,QAAQ,OAAO,0BAA0B,CAAC,CAC3E,MAAM,YAAkC,CAAC,CAAC,CAC1C,OAAO,YAAiC,CAAC,CAAC,CAC1C,MAAM;;;ACbT,MAAa,6BAA6B;AAO1C,MAAa,uBAAuB,QAAQ,OAAO,0BAA0B,CAAC,CAC3E,MAAM,YAAkC,CAAC,CAAC,CAC1C,OAAO,YAAkB,CAAC,CAAC,CAC3B,MAAM;;;;;;;;;;ACLT,IAAa,qBAAb,cAAwC,MAAM;CAC5C,OAAgB;CAEhB,YAAY,UAAU,gCAAgC;EACpD,MAAM,OAAO;CACf;AACF;;AAGA,SAAgB,gBAAgB,KAAuB;CACrD,OAAO,eAAe;AACxB;;;;;;;;;;;;;;;;;;;ACmBA,IAAa,aAAb,cAAgC,UAAU;CACxC,+BAAmC,IAAI,IAAI;CAC3C,WAAW;CAEX,SAAS,YAAuC;EAC9C,KAAK,aAAa,IAAI,UAAU;EAChC,aAAa;GACX,KAAK,aAAa,OAAO,UAAU;EACrC;CACF;CAEA,OAAa;EACX,IAAI,KAAK,UAAU;EACnB,KAAK,WAAW;EAChB,IAAI;GACF,KAAK,OAAO;EACd,UAAU;GACR,KAAK,WAAW;EAClB;CACF;CAEA,aAAuB;EACrB,IAAI,QAAkB;GAAE,MAAM;GAAI,OAAO,CAAC;EAAE;EAC5C,KAAK,MAAM,KAAK,KAAK,cACnB,QAAQ,EAAE,UAAU,KAAK;EAE3B,OAAO;CACT;CAEA,SAAS,OAAuB;EAC9B,IAAI,KAAK,UAAU;EACnB,KAAK,WAAW;EAChB,IAAI;GACF,KAAK,MAAM,KAAK,KAAK,cACnB,EAAE,YAAY,KAAK;EAEvB,UAAU;GACR,KAAK,WAAW;EAClB;CACF;CAEA,IAAI,YAAqB;EACvB,OAAO,KAAK;CACd;AACF;AAIA,MAAa,CAAC,iBAAiB,iBAAiB,sBAAsB,WACpE,yBACM,IAAI,WAAW,CACvB"}