@snaptrude/plugin-core 0.9.9 → 0.9.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snaptrude/plugin-core",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -29,10 +29,14 @@ export interface PluginCoreModeSetResult {
29
29
  * Not to be confused with the viewport's 2D/3D camera mode
30
30
  * (`core.camera.setMode`) or saved presentation views (`presentation.views`).
31
31
  *
32
- * `set` covers `design`, `bim`, and `present` — in-page switches.
33
- * `program` opens in its own browser tab in the product, which a plugin worker
34
- * cannot do, so `set("program")` fails with `PRECONDITION_FAILED`; `get()`
35
- * still reports `"program"` for code running in the Program tab.
32
+ * `set` covers `design`, `bim`, and `present` — in-page switches — and
33
+ * `program`, which opens the Program tab (a paired browser window) through the
34
+ * same path as the top bar's Program button. Because the open happens outside a
35
+ * user gesture the browser may block the pop-up; the editor then shows its
36
+ * "Allow pop-up to continue" modal and the tab opens when the user confirms.
37
+ * `get()` reports `"program"` only for code running in the Program tab itself.
38
+ * Prefer {@linkcode PluginWorkspaceApi.openProgramMode} when you need to know
39
+ * the tab is ready before calling `program.spreadsheet.*`.
36
40
  */
37
41
  export abstract class PluginCoreModeApi {
38
42
  constructor() {}
@@ -74,16 +78,24 @@ export abstract class PluginCoreModeApi {
74
78
  * Switch the editor to another application mode — the same action as
75
79
  * clicking that tab in the top menu bar.
76
80
  *
77
- * Supported: `"design"`, `"bim"`, `"present"`. Switching to
78
- * `"program"` is rejected with `PRECONDITION_FAILED` (the Program surface
79
- * opens in its own browser tab in the product; a plugin cannot open one).
81
+ * `"design"`, `"bim"` and `"present"` switch in place. `"program"` opens
82
+ * the Program tab (a paired browser window) exactly as the top bar's Program
83
+ * button does, and resolves once that tab has connected to the editor (up to
84
+ * ~90s — the browser may block the pop-up, in which case the editor shows an
85
+ * "Allow pop-up to continue" modal and waits for the user to confirm).
86
+ * Idempotent when the Program tab is already open. Note `get()` in the model
87
+ * tab keeps reporting the model tab's own mode afterwards; the Program tab is
88
+ * a separate window.
80
89
  *
81
90
  * @param mode - Target mode token from {@linkcode PluginAppMode}
82
91
  * @returns The committed `{ mode }` after the switch.
92
+ * @throws `PRECONDITION_FAILED` for `"program"` when the user dismisses the
93
+ * pop-up modal or the tab does not connect within the timeout.
83
94
  *
84
95
  * @examplePrompt Switch to present mode
85
96
  * @examplePrompt Open BIM mode
86
97
  * @examplePrompt Go back to design mode
98
+ * @examplePrompt Open program mode
87
99
  *
88
100
  * # Example
89
101
  * ```ts
@@ -10,13 +10,16 @@ import { PluginApiReturn } from "../../types"
10
10
  * Teams are **read-only** here (no create/invite/delete in v1, a deliberate
11
11
  * safety decision); there are no folders in v1. A `projectId` is the project's
12
12
  * floorkey. Plan limits are enforced by the backend — a limit rejection surfaces
13
- * as a normal host error. It also carries the workspace-level mode switch for
13
+ * as a normal host error. It also carries the workspace-level mode switches for
14
14
  * Present mode ({@linkcode PluginWorkspaceApi.openPresentMode} /
15
- * {@linkcode PluginWorkspaceApi.closePresentMode}).
15
+ * {@linkcode PluginWorkspaceApi.closePresentMode}) and Program mode
16
+ * ({@linkcode PluginWorkspaceApi.openProgramMode} /
17
+ * {@linkcode PluginWorkspaceApi.closeProgramMode}).
16
18
  *
17
19
  * - {@linkcode PluginWorkspaceApi.projects} — Create, copy, list, read & rename projects
18
20
  * - {@linkcode PluginWorkspaceApi.teams} — Read teams and their members
19
21
  * - {@linkcode PluginWorkspaceApi.openPresentMode} / {@linkcode PluginWorkspaceApi.closePresentMode} — Open/close the Present-mode documentation editor
22
+ * - {@linkcode PluginWorkspaceApi.openProgramMode} / {@linkcode PluginWorkspaceApi.closeProgramMode} — Open/close the Program tab (the spreadsheet the `program.spreadsheet.*` calls run in)
20
23
  */
21
24
  export abstract class PluginWorkspaceApi {
22
25
  /** Projects — create, copy, list, read & rename. See {@linkcode PluginWorkspaceProjectsApi}. */
@@ -68,6 +71,52 @@ export abstract class PluginWorkspaceApi {
68
71
  */
69
72
  public abstract closePresentMode(): PluginApiReturn<void>
70
73
 
74
+ /**
75
+ * Open Program mode — the Program tab the `program.spreadsheet.*` calls run in.
76
+ *
77
+ * Runs the top bar's own Program-button sequence (remember the preference,
78
+ * open or re-link the paired Program window) and resolves only once that tab
79
+ * has connected to the editor over its channel, so a `program.spreadsheet.*`
80
+ * call issued right after this resolves finds the tab open. The open happens
81
+ * outside a user gesture, so the browser may block the pop-up; the editor
82
+ * then shows its "Allow pop-up to continue" modal and this call keeps waiting
83
+ * (up to ~90s) for the user to confirm. Idempotent — resolves immediately
84
+ * when the Program tab is already connected, and is a no-op when the plugin is
85
+ * itself running in the Program tab. Write-gated.
86
+ *
87
+ * @throws `PRECONDITION_FAILED` if the user dismisses the pop-up modal or the
88
+ * Program tab does not connect within the timeout.
89
+ *
90
+ * @examplePrompt Open program mode
91
+ * @examplePrompt Open the Program tab so I can build a custom sheet
92
+ * @examplePrompt Switch to the program spreadsheet
93
+ *
94
+ * # Example
95
+ * ```ts
96
+ * await snaptrude.workspace.openProgramMode()
97
+ * const { sheets } = await snaptrude.program.spreadsheet.listSheets()
98
+ * ```
99
+ */
100
+ public abstract openProgramMode(): PluginApiReturn<void>
101
+
102
+ /**
103
+ * Close the Program tab.
104
+ *
105
+ * Idempotent — a no-op when no Program tab is connected. Write-gated, like
106
+ * {@linkcode PluginWorkspaceApi.openProgramMode}.
107
+ *
108
+ * @throws `PRECONDITION_FAILED` if the tab is still connected after ~15s.
109
+ *
110
+ * @examplePrompt Close program mode
111
+ * @examplePrompt Close the Program tab
112
+ *
113
+ * # Example
114
+ * ```ts
115
+ * await snaptrude.workspace.closeProgramMode()
116
+ * ```
117
+ */
118
+ public abstract closeProgramMode(): PluginApiReturn<void>
119
+
71
120
  constructor() {}
72
121
  }
73
122