@snaptrude/plugin-core 0.9.8 → 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/AGENTS.md +4 -0
- package/CHANGELOG.md +12 -4
- package/api-manifest.json +242 -1
- package/dist/api/core/mode/index.d.ts +19 -7
- package/dist/api/core/mode/index.d.ts.map +1 -1
- package/dist/api/core/tags.d.ts +81 -0
- package/dist/api/core/tags.d.ts.map +1 -1
- package/dist/api/program/departments.d.ts +58 -2
- package/dist/api/program/departments.d.ts.map +1 -1
- package/dist/api/program/index.d.ts +16 -6
- package/dist/api/program/index.d.ts.map +1 -1
- package/dist/api/program/labels.d.ts +355 -0
- package/dist/api/program/labels.d.ts.map +1 -0
- package/dist/api/program/metadata.d.ts +328 -0
- package/dist/api/program/metadata.d.ts.map +1 -0
- package/dist/api/program/spreadsheet.d.ts +263 -0
- package/dist/api/program/spreadsheet.d.ts.map +1 -1
- package/dist/api/workspace/index.d.ts +49 -2
- package/dist/api/workspace/index.d.ts.map +1 -1
- package/dist/index.cjs +1079 -831
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1034 -831
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
- package/src/api/core/mode/index.ts +19 -7
- package/src/api/core/tags.ts +76 -0
- package/src/api/program/departments.ts +54 -2
- package/src/api/program/index.ts +16 -6
- package/src/api/program/labels.ts +332 -0
- package/src/api/program/metadata.ts +364 -0
- package/src/api/program/spreadsheet.ts +282 -0
- package/src/api/workspace/index.ts +51 -2
- package/api-manifest.full.json +0 -8443
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
import { PluginApiReturn } from "../../types"
|
|
3
|
+
import { ComponentHandle } from "../../handles"
|
|
4
|
+
import { PluginSpreadsheetCell } from "./spreadsheet"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Program metadata — the user-defined **custom columns** of the Program Data
|
|
8
|
+
* sheet and their per-space values.
|
|
9
|
+
*
|
|
10
|
+
* In program mode a **metadata header** is a custom column (e.g. "Department
|
|
11
|
+
* Code", "Occupancy", "Finish Level") added to the Program Data sheet; every
|
|
12
|
+
* space can then carry one **value** per header. This is the same store the
|
|
13
|
+
* Program tab reads and writes — values set here appear in the default Program
|
|
14
|
+
* Data sheet and in every custom sheet that shows the column, and values typed
|
|
15
|
+
* into the sheet are read back here. The store lives in the editor, so **no
|
|
16
|
+
* method in this namespace needs the Program tab open**.
|
|
17
|
+
*
|
|
18
|
+
* Headers are identified by a stable `headerId`. Values are plain cells
|
|
19
|
+
* (`string | number | boolean | null`); `null` clears a value. Departments and
|
|
20
|
+
* labels also carry metadata in the engine, but this namespace covers **spaces**
|
|
21
|
+
* (Mass/Floor components) — the per-space case plugins asked for.
|
|
22
|
+
*
|
|
23
|
+
* Reads never throw for a miss (`get` returns `null`, `list*` return `[]`).
|
|
24
|
+
* Writes are undoable and autosaved.
|
|
25
|
+
*
|
|
26
|
+
* Accessed via `snaptrude.program.metadata`.
|
|
27
|
+
*/
|
|
28
|
+
export abstract class PluginProgramMetadataApi {
|
|
29
|
+
constructor() {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* List the metadata headers (custom columns) of the Program Data sheet.
|
|
33
|
+
*
|
|
34
|
+
* @returns A {@linkcode PluginProgramMetadataListHeadersResult} with a
|
|
35
|
+
* `headers` array (empty when the project has no custom columns).
|
|
36
|
+
*
|
|
37
|
+
* @examplePrompt List the custom metadata columns in program mode
|
|
38
|
+
* @examplePrompt What metadata headers does the program sheet have?
|
|
39
|
+
* @examplePrompt Show every custom column with its id
|
|
40
|
+
*
|
|
41
|
+
* # Example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const { headers } = await snaptrude.program.metadata.listHeaders()
|
|
44
|
+
* for (const h of headers) console.log(h.headerId, h.name)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
public abstract listHeaders(): PluginApiReturn<PluginProgramMetadataListHeadersResult>
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Create a metadata header (a custom column on the Program Data sheet).
|
|
51
|
+
*
|
|
52
|
+
* Header names are unique per sheet: when a header with the same name already
|
|
53
|
+
* exists it is **reused** and returned (no duplicate column is created), so
|
|
54
|
+
* re-running a plugin is safe. The new column is appended after the sheet's
|
|
55
|
+
* existing custom columns.
|
|
56
|
+
*
|
|
57
|
+
* @param name - Column header text (non-empty).
|
|
58
|
+
* @param options - Optional `description` shown in the column's description
|
|
59
|
+
* row.
|
|
60
|
+
* @returns The created (or reused) {@linkcode PluginProgramMetadataHeader}.
|
|
61
|
+
* @throws If `name` is blank.
|
|
62
|
+
*
|
|
63
|
+
* @examplePrompt Add a custom column called Occupancy to the program sheet
|
|
64
|
+
* @examplePrompt Create a metadata header named Department Code
|
|
65
|
+
* @examplePrompt Make a new program-mode column for Finish Level
|
|
66
|
+
*
|
|
67
|
+
* # Example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const header = await snaptrude.program.metadata.createHeader("Occupancy", {
|
|
70
|
+
* description: "People per room",
|
|
71
|
+
* })
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
public abstract createHeader(
|
|
75
|
+
name: string,
|
|
76
|
+
options?: { description?: string },
|
|
77
|
+
): PluginApiReturn<PluginProgramMetadataCreateHeaderResult>
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get one space's metadata values, keyed by header id.
|
|
81
|
+
*
|
|
82
|
+
* @param spaceId - The space (component id) to read.
|
|
83
|
+
* @returns A {@linkcode PluginProgramMetadataRecord} — `values` holds one entry
|
|
84
|
+
* per header the space has a value for — or `null` when no space has that id.
|
|
85
|
+
*
|
|
86
|
+
* @examplePrompt Get the metadata on this space
|
|
87
|
+
* @examplePrompt Read the custom column values for space sp_12
|
|
88
|
+
* @examplePrompt What is this room's Occupancy metadata?
|
|
89
|
+
*
|
|
90
|
+
* # Example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const record = await snaptrude.program.metadata.get("sp_12")
|
|
93
|
+
* if (record) console.log(record.values)
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
public abstract get(
|
|
97
|
+
spaceId: ComponentHandle,
|
|
98
|
+
): PluginApiReturn<PluginProgramMetadataGetResult>
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* List metadata values for many spaces at once.
|
|
102
|
+
*
|
|
103
|
+
* Pass `spaceIds` to read specific spaces (unknown ids are skipped), or omit
|
|
104
|
+
* it to read every space in the project. One host round-trip regardless of
|
|
105
|
+
* the number of spaces — prefer this over calling
|
|
106
|
+
* {@linkcode PluginProgramMetadataApi.get} in a loop.
|
|
107
|
+
*
|
|
108
|
+
* @param spaceIds - Optional space ids to read; omit for all spaces.
|
|
109
|
+
* @returns A {@linkcode PluginProgramMetadataListResult} with one
|
|
110
|
+
* {@linkcode PluginProgramMetadataRecord} per space.
|
|
111
|
+
*
|
|
112
|
+
* @performance One round-trip for any number of spaces — use this instead of a `get` loop.
|
|
113
|
+
*
|
|
114
|
+
* @examplePrompt List the metadata of every space
|
|
115
|
+
* @examplePrompt Read the custom column values for all rooms
|
|
116
|
+
* @examplePrompt Get the metadata for these three spaces in one call
|
|
117
|
+
*
|
|
118
|
+
* # Example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const { records } = await snaptrude.program.metadata.list()
|
|
121
|
+
* const byId = Object.fromEntries(records.map((r) => [r.spaceId, r.values]))
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
public abstract list(
|
|
125
|
+
spaceIds?: ComponentHandle[],
|
|
126
|
+
): PluginApiReturn<PluginProgramMetadataListResult>
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Update a space's metadata values (sparse).
|
|
130
|
+
*
|
|
131
|
+
* Only the headers present in `values` change; `null` clears a value. Every
|
|
132
|
+
* key must be an existing `headerId` (create columns first with
|
|
133
|
+
* {@linkcode PluginProgramMetadataApi.createHeader}). Undoable as one step.
|
|
134
|
+
*
|
|
135
|
+
* @param spaceId - The space (component id) to write.
|
|
136
|
+
* @param values - Header id → new cell value (`null` clears).
|
|
137
|
+
* @returns The space's full {@linkcode PluginProgramMetadataRecord} after the
|
|
138
|
+
* write.
|
|
139
|
+
* @throws If the space or any header id does not exist.
|
|
140
|
+
*
|
|
141
|
+
* @examplePrompt Set the Occupancy metadata of this space to 4
|
|
142
|
+
* @examplePrompt Store a department code on the selected rooms
|
|
143
|
+
* @examplePrompt Write custom column values onto space sp_12
|
|
144
|
+
* @examplePrompt Clear the Finish Level metadata on this space
|
|
145
|
+
*
|
|
146
|
+
* # Example
|
|
147
|
+
* ```ts
|
|
148
|
+
* const header = await snaptrude.program.metadata.createHeader("Occupancy")
|
|
149
|
+
* await snaptrude.program.metadata.update("sp_12", { [header.headerId]: 4 })
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
public abstract update(
|
|
153
|
+
spaceId: ComponentHandle,
|
|
154
|
+
values: Record<string, PluginSpreadsheetCell>,
|
|
155
|
+
): PluginApiReturn<PluginProgramMetadataUpdateResult>
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Update metadata values on many spaces in one undoable step.
|
|
159
|
+
*
|
|
160
|
+
* The plural of {@linkcode PluginProgramMetadataApi.update}: each item names a
|
|
161
|
+
* space and its sparse `values`. Results are in input order. Capped at 1000
|
|
162
|
+
* items per call.
|
|
163
|
+
*
|
|
164
|
+
* @param items - The spaces and the values to write on each.
|
|
165
|
+
* @returns A {@linkcode PluginProgramMetadataUpdateManyResult} with one record
|
|
166
|
+
* per item, in input order.
|
|
167
|
+
* @throws If any space or header id does not exist (nothing is written).
|
|
168
|
+
*
|
|
169
|
+
* @performance One round-trip and one undo step for up to 1000 spaces — use this instead of an `update` loop.
|
|
170
|
+
*
|
|
171
|
+
* @examplePrompt Fill the Occupancy column for all bedrooms
|
|
172
|
+
* @examplePrompt Write metadata onto every selected space at once
|
|
173
|
+
* @examplePrompt Bulk-update custom column values
|
|
174
|
+
*
|
|
175
|
+
* # Example
|
|
176
|
+
* ```ts
|
|
177
|
+
* await snaptrude.program.metadata.updateMany([
|
|
178
|
+
* { spaceId: "sp_12", values: { [headerId]: 4 } },
|
|
179
|
+
* { spaceId: "sp_13", values: { [headerId]: 2 } },
|
|
180
|
+
* ])
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
public abstract updateMany(
|
|
184
|
+
items: PluginProgramMetadataUpdateItem[],
|
|
185
|
+
): PluginApiReturn<PluginProgramMetadataUpdateManyResult>
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A metadata header — one custom column of the Program Data sheet.
|
|
190
|
+
*
|
|
191
|
+
* | Property | Type | Description |
|
|
192
|
+
* |---|---|---|
|
|
193
|
+
* | `headerId` | `string` | Stable header id (the key used in metadata `values`) |
|
|
194
|
+
* | `name` | `string` | Column header text |
|
|
195
|
+
* | `description` | `string` | Column description (`""` when none) |
|
|
196
|
+
* | `columnIndex` | `number` | Zero-based column index on the Program Data sheet |
|
|
197
|
+
*/
|
|
198
|
+
export const PluginProgramMetadataHeader = z.object({
|
|
199
|
+
headerId: z.string(),
|
|
200
|
+
name: z.string(),
|
|
201
|
+
description: z.string(),
|
|
202
|
+
columnIndex: z.number(),
|
|
203
|
+
})
|
|
204
|
+
export type PluginProgramMetadataHeader = z.infer<
|
|
205
|
+
typeof PluginProgramMetadataHeader
|
|
206
|
+
>
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Result of {@linkcode PluginProgramMetadataApi.listHeaders}.
|
|
210
|
+
*
|
|
211
|
+
* | Property | Type | Description |
|
|
212
|
+
* |---|---|---|
|
|
213
|
+
* | `headers` | {@linkcode PluginProgramMetadataHeader}`[]` | Every custom column, in sheet column order |
|
|
214
|
+
*/
|
|
215
|
+
export const PluginProgramMetadataListHeadersResult = z.object({
|
|
216
|
+
headers: z.array(PluginProgramMetadataHeader),
|
|
217
|
+
})
|
|
218
|
+
export type PluginProgramMetadataListHeadersResult = z.infer<
|
|
219
|
+
typeof PluginProgramMetadataListHeadersResult
|
|
220
|
+
>
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Arguments for {@linkcode PluginProgramMetadataApi.createHeader}.
|
|
224
|
+
*
|
|
225
|
+
* | Property | Type | Description |
|
|
226
|
+
* |---|---|---|
|
|
227
|
+
* | `name` | `string` | Column header text (non-empty) |
|
|
228
|
+
* | `description` | `string?` | Column description |
|
|
229
|
+
*/
|
|
230
|
+
export const PluginProgramMetadataCreateHeaderArgs = z.object({
|
|
231
|
+
name: z.string().trim().min(1),
|
|
232
|
+
description: z.string().optional(),
|
|
233
|
+
})
|
|
234
|
+
export type PluginProgramMetadataCreateHeaderArgs = z.infer<
|
|
235
|
+
typeof PluginProgramMetadataCreateHeaderArgs
|
|
236
|
+
>
|
|
237
|
+
|
|
238
|
+
/** Result of {@linkcode PluginProgramMetadataApi.createHeader} — the created or reused header. */
|
|
239
|
+
export const PluginProgramMetadataCreateHeaderResult = PluginProgramMetadataHeader
|
|
240
|
+
export type PluginProgramMetadataCreateHeaderResult = z.infer<
|
|
241
|
+
typeof PluginProgramMetadataCreateHeaderResult
|
|
242
|
+
>
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* One space's metadata values.
|
|
246
|
+
*
|
|
247
|
+
* | Property | Type | Description |
|
|
248
|
+
* |---|---|---|
|
|
249
|
+
* | `spaceId` | `ComponentHandle` | The space's component id |
|
|
250
|
+
* | `values` | `Record<string, cell>` | Header id → value, one entry per header the space has a value for |
|
|
251
|
+
*/
|
|
252
|
+
export const PluginProgramMetadataRecord = z.object({
|
|
253
|
+
spaceId: ComponentHandle,
|
|
254
|
+
values: z.record(z.string(), PluginSpreadsheetCell),
|
|
255
|
+
})
|
|
256
|
+
export type PluginProgramMetadataRecord = z.infer<
|
|
257
|
+
typeof PluginProgramMetadataRecord
|
|
258
|
+
>
|
|
259
|
+
|
|
260
|
+
/** Arguments for {@linkcode PluginProgramMetadataApi.get}. */
|
|
261
|
+
export const PluginProgramMetadataGetArgs = z.object({
|
|
262
|
+
spaceId: ComponentHandle,
|
|
263
|
+
})
|
|
264
|
+
export type PluginProgramMetadataGetArgs = z.infer<
|
|
265
|
+
typeof PluginProgramMetadataGetArgs
|
|
266
|
+
>
|
|
267
|
+
|
|
268
|
+
/** Result of {@linkcode PluginProgramMetadataApi.get} — the record, or `null` when the space does not exist. */
|
|
269
|
+
export const PluginProgramMetadataGetResult = PluginProgramMetadataRecord.nullable()
|
|
270
|
+
export type PluginProgramMetadataGetResult = z.infer<
|
|
271
|
+
typeof PluginProgramMetadataGetResult
|
|
272
|
+
>
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Arguments for {@linkcode PluginProgramMetadataApi.list}.
|
|
276
|
+
*
|
|
277
|
+
* | Property | Type | Description |
|
|
278
|
+
* |---|---|---|
|
|
279
|
+
* | `spaceIds` | `ComponentHandle[]?` | Spaces to read; omit for every space |
|
|
280
|
+
*/
|
|
281
|
+
export const PluginProgramMetadataListArgs = z.object({
|
|
282
|
+
spaceIds: z.array(ComponentHandle).optional(),
|
|
283
|
+
})
|
|
284
|
+
export type PluginProgramMetadataListArgs = z.infer<
|
|
285
|
+
typeof PluginProgramMetadataListArgs
|
|
286
|
+
>
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Result of {@linkcode PluginProgramMetadataApi.list}.
|
|
290
|
+
*
|
|
291
|
+
* | Property | Type | Description |
|
|
292
|
+
* |---|---|---|
|
|
293
|
+
* | `records` | {@linkcode PluginProgramMetadataRecord}`[]` | One record per space (unknown ids skipped) |
|
|
294
|
+
*/
|
|
295
|
+
export const PluginProgramMetadataListResult = z.object({
|
|
296
|
+
records: z.array(PluginProgramMetadataRecord),
|
|
297
|
+
})
|
|
298
|
+
export type PluginProgramMetadataListResult = z.infer<
|
|
299
|
+
typeof PluginProgramMetadataListResult
|
|
300
|
+
>
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Arguments for {@linkcode PluginProgramMetadataApi.update}.
|
|
304
|
+
*
|
|
305
|
+
* | Property | Type | Description |
|
|
306
|
+
* |---|---|---|
|
|
307
|
+
* | `spaceId` | `ComponentHandle` | The space to write |
|
|
308
|
+
* | `values` | `Record<string, cell>` | Header id → new value (`null` clears); at least one entry |
|
|
309
|
+
*/
|
|
310
|
+
export const PluginProgramMetadataUpdateArgs = z.object({
|
|
311
|
+
spaceId: ComponentHandle,
|
|
312
|
+
values: z
|
|
313
|
+
.record(z.string(), PluginSpreadsheetCell)
|
|
314
|
+
.refine((v) => Object.keys(v).length > 0, "values must not be empty"),
|
|
315
|
+
})
|
|
316
|
+
export type PluginProgramMetadataUpdateArgs = z.infer<
|
|
317
|
+
typeof PluginProgramMetadataUpdateArgs
|
|
318
|
+
>
|
|
319
|
+
|
|
320
|
+
/** Result of {@linkcode PluginProgramMetadataApi.update} — the space's record after the write. */
|
|
321
|
+
export const PluginProgramMetadataUpdateResult = PluginProgramMetadataRecord
|
|
322
|
+
export type PluginProgramMetadataUpdateResult = z.infer<
|
|
323
|
+
typeof PluginProgramMetadataUpdateResult
|
|
324
|
+
>
|
|
325
|
+
|
|
326
|
+
/** One item of {@linkcode PluginProgramMetadataApi.updateMany} — mirrors the `update` args. */
|
|
327
|
+
export const PluginProgramMetadataUpdateItem = PluginProgramMetadataUpdateArgs
|
|
328
|
+
export type PluginProgramMetadataUpdateItem = z.infer<
|
|
329
|
+
typeof PluginProgramMetadataUpdateItem
|
|
330
|
+
>
|
|
331
|
+
|
|
332
|
+
/** Maximum items per {@linkcode PluginProgramMetadataApi.updateMany} call. */
|
|
333
|
+
export const PLUGIN_PROGRAM_METADATA_BATCH_LIMIT = 1000
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Arguments for {@linkcode PluginProgramMetadataApi.updateMany}.
|
|
337
|
+
*
|
|
338
|
+
* | Property | Type | Description |
|
|
339
|
+
* |---|---|---|
|
|
340
|
+
* | `items` | {@linkcode PluginProgramMetadataUpdateItem}`[]` | 1–1000 space updates |
|
|
341
|
+
*/
|
|
342
|
+
export const PluginProgramMetadataUpdateManyArgs = z.object({
|
|
343
|
+
items: z
|
|
344
|
+
.array(PluginProgramMetadataUpdateItem)
|
|
345
|
+
.min(1)
|
|
346
|
+
.max(PLUGIN_PROGRAM_METADATA_BATCH_LIMIT),
|
|
347
|
+
})
|
|
348
|
+
export type PluginProgramMetadataUpdateManyArgs = z.infer<
|
|
349
|
+
typeof PluginProgramMetadataUpdateManyArgs
|
|
350
|
+
>
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Result of {@linkcode PluginProgramMetadataApi.updateMany}.
|
|
354
|
+
*
|
|
355
|
+
* | Property | Type | Description |
|
|
356
|
+
* |---|---|---|
|
|
357
|
+
* | `records` | {@linkcode PluginProgramMetadataRecord}`[]` | One record per item, in input order |
|
|
358
|
+
*/
|
|
359
|
+
export const PluginProgramMetadataUpdateManyResult = z.object({
|
|
360
|
+
records: z.array(PluginProgramMetadataRecord),
|
|
361
|
+
})
|
|
362
|
+
export type PluginProgramMetadataUpdateManyResult = z.infer<
|
|
363
|
+
typeof PluginProgramMetadataUpdateManyResult
|
|
364
|
+
>
|
|
@@ -820,6 +820,144 @@ export abstract class PluginProgramSpreadsheetApi {
|
|
|
820
820
|
* ```
|
|
821
821
|
*/
|
|
822
822
|
public abstract ping(): PluginApiReturn<PluginProgramSpreadsheetPingResult>
|
|
823
|
+
|
|
824
|
+
// --- Custom program sheets (grouped program views) -----------------------------
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* Create a **custom program sheet** — a live view of the program grouped by a
|
|
828
|
+
* configurable hierarchy (the Program tab's "Custom" sheet with *Organize →
|
|
829
|
+
* Group by*).
|
|
830
|
+
*
|
|
831
|
+
* Unlike {@linkcode PluginProgramSpreadsheetApi.createSheet} (a blank sheet you
|
|
832
|
+
* write cells into), a custom sheet is data-bound: its rows are the project's
|
|
833
|
+
* spaces, re-rendered from the model, grouped by `groupBy` in order (e.g.
|
|
834
|
+
* `["departmentName", "<metadataHeaderId>", "label"]` for a healthcare
|
|
835
|
+
* department → sub-department → room hierarchy) and showing the `properties`
|
|
836
|
+
* columns. Valid property ids come from
|
|
837
|
+
* {@linkcode PluginProgramSpreadsheetApi.listCustomSheetProperties} — built-in
|
|
838
|
+
* properties plus every program metadata header id. The configuration is
|
|
839
|
+
* saved with the sheet.
|
|
840
|
+
*
|
|
841
|
+
* @param name - The sheet name to create (must not already exist).
|
|
842
|
+
* @param options - Optional `groupBy` (property ids, outermost first; default
|
|
843
|
+
* none), `properties` (column property ids, in order; default
|
|
844
|
+
* `["label", "areas"]`), and `groupColors` (property id → CSS hex fill for
|
|
845
|
+
* that level's group headers).
|
|
846
|
+
* @returns The sheet's {@linkcode PluginSpreadsheetCustomSheet} configuration.
|
|
847
|
+
* @throws If a sheet named `name` already exists, or a property id is unknown.
|
|
848
|
+
*
|
|
849
|
+
* @examplePrompt Create a custom sheet grouped by department then sub-department
|
|
850
|
+
* @examplePrompt Make a program view grouped by storey and label
|
|
851
|
+
* @examplePrompt Build a grouped program sheet for the healthcare hierarchy
|
|
852
|
+
* @examplePrompt Add a custom sheet with a department → room type group-by
|
|
853
|
+
*
|
|
854
|
+
* # Example
|
|
855
|
+
* ```ts
|
|
856
|
+
* const { headers } = await snaptrude.program.metadata.listHeaders()
|
|
857
|
+
* const subDept = headers.find((h) => h.name === "Sub-department")
|
|
858
|
+
* await snaptrude.program.spreadsheet.createCustomSheet("Clinical Program", {
|
|
859
|
+
* groupBy: ["departmentName", subDept.headerId, "label"],
|
|
860
|
+
* properties: ["label", "count", "areas", "netAreaAchieved"],
|
|
861
|
+
* })
|
|
862
|
+
* ```
|
|
863
|
+
*/
|
|
864
|
+
public abstract createCustomSheet(
|
|
865
|
+
name: string,
|
|
866
|
+
options?: {
|
|
867
|
+
groupBy?: string[]
|
|
868
|
+
properties?: string[]
|
|
869
|
+
groupColors?: Record<string, string>
|
|
870
|
+
},
|
|
871
|
+
): PluginApiReturn<PluginProgramSpreadsheetCustomSheetResult>
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Update a custom program sheet's group-by hierarchy, columns, or group colors.
|
|
875
|
+
*
|
|
876
|
+
* A **sparse** update: omitted fields are left unchanged. The sheet is
|
|
877
|
+
* re-rendered once and the configuration saved.
|
|
878
|
+
*
|
|
879
|
+
* @param sheetName - The custom sheet to update.
|
|
880
|
+
* @param options - Any of `groupBy`, `properties`, `groupColors` (see
|
|
881
|
+
* {@linkcode PluginProgramSpreadsheetApi.createCustomSheet}).
|
|
882
|
+
* @returns The sheet's updated {@linkcode PluginSpreadsheetCustomSheet}.
|
|
883
|
+
* @throws If `sheetName` is not a custom program sheet, or a property id is
|
|
884
|
+
* unknown.
|
|
885
|
+
*
|
|
886
|
+
* @examplePrompt Change the custom sheet to group by storey first
|
|
887
|
+
* @examplePrompt Add the Occupancy column to my grouped program sheet
|
|
888
|
+
* @examplePrompt Regroup the Clinical Program sheet by department only
|
|
889
|
+
*
|
|
890
|
+
* # Example
|
|
891
|
+
* ```ts
|
|
892
|
+
* await snaptrude.program.spreadsheet.updateCustomSheet("Clinical Program", {
|
|
893
|
+
* groupBy: ["storey", "departmentName"],
|
|
894
|
+
* })
|
|
895
|
+
* ```
|
|
896
|
+
*/
|
|
897
|
+
public abstract updateCustomSheet(
|
|
898
|
+
sheetName: string,
|
|
899
|
+
options: {
|
|
900
|
+
groupBy?: string[]
|
|
901
|
+
properties?: string[]
|
|
902
|
+
groupColors?: Record<string, string>
|
|
903
|
+
},
|
|
904
|
+
): PluginApiReturn<PluginProgramSpreadsheetCustomSheetResult>
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Get a custom program sheet's configuration.
|
|
908
|
+
*
|
|
909
|
+
* @param sheetName - The sheet to read.
|
|
910
|
+
* @returns Its {@linkcode PluginSpreadsheetCustomSheet}, or `null` when no
|
|
911
|
+
* custom program sheet has that name (plain sheets return `null` too).
|
|
912
|
+
*
|
|
913
|
+
* @examplePrompt How is the Clinical Program sheet grouped?
|
|
914
|
+
* @examplePrompt Get the group-by configuration of this custom sheet
|
|
915
|
+
*
|
|
916
|
+
* # Example
|
|
917
|
+
* ```ts
|
|
918
|
+
* const cfg = await snaptrude.program.spreadsheet.getCustomSheet("Clinical Program")
|
|
919
|
+
* if (cfg) console.log(cfg.groupBy, cfg.properties)
|
|
920
|
+
* ```
|
|
921
|
+
*/
|
|
922
|
+
public abstract getCustomSheet(
|
|
923
|
+
sheetName: string,
|
|
924
|
+
): PluginApiReturn<PluginProgramSpreadsheetGetCustomSheetResult>
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* List the custom program sheets in the workbook with their configurations.
|
|
928
|
+
*
|
|
929
|
+
* @returns A {@linkcode PluginProgramSpreadsheetListCustomSheetsResult} with a
|
|
930
|
+
* `sheets` array (empty when there are none).
|
|
931
|
+
*
|
|
932
|
+
* @examplePrompt List the custom program sheets
|
|
933
|
+
* @examplePrompt Which sheets are grouped program views?
|
|
934
|
+
*
|
|
935
|
+
* # Example
|
|
936
|
+
* ```ts
|
|
937
|
+
* const { sheets } = await snaptrude.program.spreadsheet.listCustomSheets()
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
940
|
+
public abstract listCustomSheets(): PluginApiReturn<PluginProgramSpreadsheetListCustomSheetsResult>
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* List the property ids a custom program sheet can show as columns or group by.
|
|
944
|
+
*
|
|
945
|
+
* Built-in properties (`label`, `departmentName`, `storey`, `areas`, …) plus
|
|
946
|
+
* one entry per program metadata header (its `headerId`). `groupable` is
|
|
947
|
+
* `false` for computed properties that can only be columns.
|
|
948
|
+
*
|
|
949
|
+
* @returns A {@linkcode PluginProgramSpreadsheetListCustomSheetPropertiesResult}.
|
|
950
|
+
*
|
|
951
|
+
* @examplePrompt What can I group a custom program sheet by?
|
|
952
|
+
* @examplePrompt List the columns available for a custom sheet
|
|
953
|
+
*
|
|
954
|
+
* # Example
|
|
955
|
+
* ```ts
|
|
956
|
+
* const { properties } = await snaptrude.program.spreadsheet.listCustomSheetProperties()
|
|
957
|
+
* const groupable = properties.filter((p) => p.groupable).map((p) => p.id)
|
|
958
|
+
* ```
|
|
959
|
+
*/
|
|
960
|
+
public abstract listCustomSheetProperties(): PluginApiReturn<PluginProgramSpreadsheetListCustomSheetPropertiesResult>
|
|
823
961
|
}
|
|
824
962
|
|
|
825
963
|
/**
|
|
@@ -2414,3 +2552,147 @@ export const PluginProgramSpreadsheetAddImageResult = z.object({
|
|
|
2414
2552
|
export type PluginProgramSpreadsheetAddImageResult = z.infer<
|
|
2415
2553
|
typeof PluginProgramSpreadsheetAddImageResult
|
|
2416
2554
|
>
|
|
2555
|
+
|
|
2556
|
+
/**
|
|
2557
|
+
* A custom program sheet's configuration — the grouped, data-bound program view
|
|
2558
|
+
* created by {@linkcode PluginProgramSpreadsheetApi.createCustomSheet}.
|
|
2559
|
+
*
|
|
2560
|
+
* | Property | Type | Description |
|
|
2561
|
+
* |---|---|---|
|
|
2562
|
+
* | `sheetName` | `string` | The sheet's name |
|
|
2563
|
+
* | `groupBy` | `string[]` | Group-by hierarchy, outermost first (property ids); `[]` when ungrouped |
|
|
2564
|
+
* | `properties` | `string[]` | Column property ids in column order (`""` marks an unassigned column) |
|
|
2565
|
+
* | `groupColors` | `Record<string, string>` | Property id → CSS hex fill of that level's group headers |
|
|
2566
|
+
* | `proposalId` | `string \| null` | The proposal the sheet belongs to, or `null` when the project has none |
|
|
2567
|
+
*/
|
|
2568
|
+
export const PluginSpreadsheetCustomSheet = z.object({
|
|
2569
|
+
sheetName: z.string(),
|
|
2570
|
+
groupBy: z.array(z.string()),
|
|
2571
|
+
properties: z.array(z.string()),
|
|
2572
|
+
groupColors: z.record(z.string(), z.string()),
|
|
2573
|
+
proposalId: z.string().nullable(),
|
|
2574
|
+
})
|
|
2575
|
+
export type PluginSpreadsheetCustomSheet = z.infer<
|
|
2576
|
+
typeof PluginSpreadsheetCustomSheet
|
|
2577
|
+
>
|
|
2578
|
+
|
|
2579
|
+
/**
|
|
2580
|
+
* The configurable part of a custom program sheet, for
|
|
2581
|
+
* {@linkcode PluginProgramSpreadsheetApi.createCustomSheet} /
|
|
2582
|
+
* {@linkcode PluginProgramSpreadsheetApi.updateCustomSheet}. All fields optional.
|
|
2583
|
+
*
|
|
2584
|
+
* | Property | Type | Description |
|
|
2585
|
+
* |---|---|---|
|
|
2586
|
+
* | `groupBy` | `string[]?` | Group-by hierarchy, outermost first (property ids) |
|
|
2587
|
+
* | `properties` | `string[]?` | Column property ids, in order |
|
|
2588
|
+
* | `groupColors` | `Record<string, string>?` | Property id → CSS hex fill for that level's group headers |
|
|
2589
|
+
*/
|
|
2590
|
+
export const PluginSpreadsheetCustomSheetConfig = z.object({
|
|
2591
|
+
groupBy: z.array(z.string().trim().min(1)).max(10).optional(),
|
|
2592
|
+
properties: z.array(z.string()).max(50).optional(),
|
|
2593
|
+
groupColors: z.record(z.string(), z.string()).optional(),
|
|
2594
|
+
})
|
|
2595
|
+
export type PluginSpreadsheetCustomSheetConfig = z.infer<
|
|
2596
|
+
typeof PluginSpreadsheetCustomSheetConfig
|
|
2597
|
+
>
|
|
2598
|
+
|
|
2599
|
+
/**
|
|
2600
|
+
* Arguments for {@linkcode PluginProgramSpreadsheetApi.createCustomSheet}.
|
|
2601
|
+
*
|
|
2602
|
+
* | Property | Type | Description |
|
|
2603
|
+
* |---|---|---|
|
|
2604
|
+
* | `name` | `string` | The sheet name to create |
|
|
2605
|
+
* | `groupBy` / `properties` / `groupColors` | — | See {@linkcode PluginSpreadsheetCustomSheetConfig} |
|
|
2606
|
+
*/
|
|
2607
|
+
export const PluginProgramSpreadsheetCreateCustomSheetArgs =
|
|
2608
|
+
PluginSpreadsheetCustomSheetConfig.extend({
|
|
2609
|
+
name: z.string().trim().min(1),
|
|
2610
|
+
})
|
|
2611
|
+
export type PluginProgramSpreadsheetCreateCustomSheetArgs = z.infer<
|
|
2612
|
+
typeof PluginProgramSpreadsheetCreateCustomSheetArgs
|
|
2613
|
+
>
|
|
2614
|
+
|
|
2615
|
+
/**
|
|
2616
|
+
* Arguments for {@linkcode PluginProgramSpreadsheetApi.updateCustomSheet}.
|
|
2617
|
+
*
|
|
2618
|
+
* | Property | Type | Description |
|
|
2619
|
+
* |---|---|---|
|
|
2620
|
+
* | `sheetName` | `string` | The custom sheet to update |
|
|
2621
|
+
* | `groupBy` / `properties` / `groupColors` | — | Sparse; see {@linkcode PluginSpreadsheetCustomSheetConfig} |
|
|
2622
|
+
*/
|
|
2623
|
+
export const PluginProgramSpreadsheetUpdateCustomSheetArgs =
|
|
2624
|
+
PluginSpreadsheetCustomSheetConfig.extend({
|
|
2625
|
+
sheetName: z.string().trim().min(1),
|
|
2626
|
+
})
|
|
2627
|
+
export type PluginProgramSpreadsheetUpdateCustomSheetArgs = z.infer<
|
|
2628
|
+
typeof PluginProgramSpreadsheetUpdateCustomSheetArgs
|
|
2629
|
+
>
|
|
2630
|
+
|
|
2631
|
+
/** Result of `createCustomSheet` / `updateCustomSheet` — the sheet's configuration. */
|
|
2632
|
+
export const PluginProgramSpreadsheetCustomSheetResult = PluginSpreadsheetCustomSheet
|
|
2633
|
+
export type PluginProgramSpreadsheetCustomSheetResult = z.infer<
|
|
2634
|
+
typeof PluginProgramSpreadsheetCustomSheetResult
|
|
2635
|
+
>
|
|
2636
|
+
|
|
2637
|
+
/** Arguments for {@linkcode PluginProgramSpreadsheetApi.getCustomSheet}. */
|
|
2638
|
+
export const PluginProgramSpreadsheetGetCustomSheetArgs = z.object({
|
|
2639
|
+
sheetName: z.string().trim().min(1),
|
|
2640
|
+
})
|
|
2641
|
+
export type PluginProgramSpreadsheetGetCustomSheetArgs = z.infer<
|
|
2642
|
+
typeof PluginProgramSpreadsheetGetCustomSheetArgs
|
|
2643
|
+
>
|
|
2644
|
+
|
|
2645
|
+
/** Result of {@linkcode PluginProgramSpreadsheetApi.getCustomSheet} — the configuration, or `null`. */
|
|
2646
|
+
export const PluginProgramSpreadsheetGetCustomSheetResult =
|
|
2647
|
+
PluginSpreadsheetCustomSheet.nullable()
|
|
2648
|
+
export type PluginProgramSpreadsheetGetCustomSheetResult = z.infer<
|
|
2649
|
+
typeof PluginProgramSpreadsheetGetCustomSheetResult
|
|
2650
|
+
>
|
|
2651
|
+
|
|
2652
|
+
/**
|
|
2653
|
+
* Result of {@linkcode PluginProgramSpreadsheetApi.listCustomSheets}.
|
|
2654
|
+
*
|
|
2655
|
+
* | Property | Type | Description |
|
|
2656
|
+
* |---|---|---|
|
|
2657
|
+
* | `sheets` | {@linkcode PluginSpreadsheetCustomSheet}`[]` | Every custom program sheet |
|
|
2658
|
+
*/
|
|
2659
|
+
export const PluginProgramSpreadsheetListCustomSheetsResult = z.object({
|
|
2660
|
+
sheets: z.array(PluginSpreadsheetCustomSheet),
|
|
2661
|
+
})
|
|
2662
|
+
export type PluginProgramSpreadsheetListCustomSheetsResult = z.infer<
|
|
2663
|
+
typeof PluginProgramSpreadsheetListCustomSheetsResult
|
|
2664
|
+
>
|
|
2665
|
+
|
|
2666
|
+
/**
|
|
2667
|
+
* A property a custom program sheet can show or group by.
|
|
2668
|
+
*
|
|
2669
|
+
* | Property | Type | Description |
|
|
2670
|
+
* |---|---|---|
|
|
2671
|
+
* | `id` | `string` | Property id (built-in key, or a metadata `headerId`) |
|
|
2672
|
+
* | `name` | `string` | Display name |
|
|
2673
|
+
* | `groupable` | `boolean` | Whether the sheet can group by it |
|
|
2674
|
+
* | `custom` | `boolean` | `true` for program metadata headers, `false` for built-ins |
|
|
2675
|
+
*/
|
|
2676
|
+
export const PluginSpreadsheetCustomSheetProperty = z.object({
|
|
2677
|
+
id: z.string(),
|
|
2678
|
+
name: z.string(),
|
|
2679
|
+
groupable: z.boolean(),
|
|
2680
|
+
custom: z.boolean(),
|
|
2681
|
+
})
|
|
2682
|
+
export type PluginSpreadsheetCustomSheetProperty = z.infer<
|
|
2683
|
+
typeof PluginSpreadsheetCustomSheetProperty
|
|
2684
|
+
>
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* Result of {@linkcode PluginProgramSpreadsheetApi.listCustomSheetProperties}.
|
|
2688
|
+
*
|
|
2689
|
+
* | Property | Type | Description |
|
|
2690
|
+
* |---|---|---|
|
|
2691
|
+
* | `properties` | {@linkcode PluginSpreadsheetCustomSheetProperty}`[]` | Built-ins first, then metadata headers |
|
|
2692
|
+
*/
|
|
2693
|
+
export const PluginProgramSpreadsheetListCustomSheetPropertiesResult = z.object({
|
|
2694
|
+
properties: z.array(PluginSpreadsheetCustomSheetProperty),
|
|
2695
|
+
})
|
|
2696
|
+
export type PluginProgramSpreadsheetListCustomSheetPropertiesResult = z.infer<
|
|
2697
|
+
typeof PluginProgramSpreadsheetListCustomSheetPropertiesResult
|
|
2698
|
+
>
|