@disy/cadenza.js 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cadenza.d.ts CHANGED
@@ -4,14 +4,22 @@
4
4
  * @param {string} baseUrl - The base URL of the Cadenza server
5
5
  * @param {object} [options] - Options
6
6
  * @param {HTMLIFrameElement | string} [options.iframe] - An iframe for embedding Cadenza or the iframe's ID
7
+ * @param {ExternalLinkKey} [options.webApplication] - An external link that Cadenza uses to resolve the [target origin](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#targetorigin) when posting events. This is required if Cadenza and your application are not running on the same origin.
7
8
  * @param {boolean} [options.debug] - Whether to enable debug logging
8
- * @throws For invalid base URL
9
+ * @throws For invalid arguments
9
10
  */
10
11
  export function cadenza(baseUrl: string, options?: {
11
12
  iframe?: string | HTMLIFrameElement | undefined;
13
+ webApplication?: ExternalLinkKey | undefined;
12
14
  debug?: boolean | undefined;
13
15
  } | undefined): CadenzaClient;
14
16
  /** @typedef {string} EmbeddingTargetId - The ID of an embedding target */
17
+ /** @typedef {string} GlobalId - The ID of a navigator item */
18
+ /**
19
+ * @typedef ExternalLinkKey - A tuple qualifying a Cadenza external link
20
+ * @property {string} repositoryName - The name of the link's repository
21
+ * @property {string} externalLinkId - The ID of the external link
22
+ */
15
23
  /**
16
24
  * @typedef WorkbookKey - A tuple qualifying a workbook
17
25
  * @property {string} repositoryName - The name of the workbook's repository
@@ -32,6 +40,14 @@ export function cadenza(baseUrl: string, options?: {
32
40
  /** @typedef {EmbeddingTargetId | WorkbookKey} WorkbookSource - A workbook source */
33
41
  /** @typedef {EmbeddingTargetId | WorksheetKey} WorksheetSource - A worksheet source */
34
42
  /** @typedef {EmbeddingTargetId | WorkbookViewKey} WorkbookViewSource - A workbook view source */
43
+ /** @typedef {'normal'|'simplified'} OperationMode - The mode in which a workbook should be operated */
44
+ /**
45
+ * @typedef {'workbook-design'|'workbook-view-management'} UiFeature - The name of a Cadenza UI feature
46
+ *
47
+ * _Note:_ Supported features are:
48
+ * * 'workbook-design' - The workbook designer
49
+ * * 'workbook-view-management' - Add/Edit/Remove workbook views (Is included in 'workbook-design'.)
50
+ * */
35
51
  /**
36
52
  * @typedef Geometry - A [GeoJSON](https://geojson.org/) geometry object
37
53
  * @property {GeometryType} type - The type of the geometry
@@ -56,10 +72,12 @@ export class CadenzaClient {
56
72
  * @param {string} baseUrl
57
73
  * @param {object} [options]
58
74
  * @param {HTMLIFrameElement | string} [options.iframe]
75
+ * @param {ExternalLinkKey} [options.webApplication]
59
76
  * @param {boolean} [options.debug]
60
77
  */
61
- constructor(baseUrl: string, { debug, iframe }?: {
78
+ constructor(baseUrl: string, { debug, iframe, webApplication }?: {
62
79
  iframe?: string | HTMLIFrameElement | undefined;
80
+ webApplication?: ExternalLinkKey | undefined;
63
81
  debug?: boolean | undefined;
64
82
  } | undefined);
65
83
  /** The base URL of the Cadenza server this client is requesting */
@@ -71,15 +89,24 @@ export class CadenzaClient {
71
89
  *
72
90
  * @param {WorkbookSource | WorksheetSource | WorkbookViewSource} source - The source to show
73
91
  * @param {object} [options]
74
- * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer.
75
- * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar.
92
+ * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
93
+ * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
94
+ * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
95
+ * @param {GlobalId} [options.highlightGlobalId] - The ID of an item to highlight / expand in the navigator
96
+ * @param {string} [options.mediaType] - Set to 'application/pdf' for views of type "JasperReports report"
97
+ * to show the report PDF directly, without any Cadenza headers or footers.
98
+ * @param {OperationMode} [options.operationMode] - The mode in which a workbook should be operated
76
99
  * @param {AbortSignal} [options.signal] - A signal to abort the iframe loading
77
100
  * @return {Promise<void>} A Promise for when the iframe is loaded
78
- * @throws For an invalid source
101
+ * @throws For invalid arguments
79
102
  */
80
- show(source: WorkbookSource | WorksheetSource | WorkbookViewSource, { hideMainHeaderAndFooter, hideWorkbookToolBar, signal }?: {
103
+ show(source: WorkbookSource | WorksheetSource | WorkbookViewSource, { disabledUiFeatures, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, mediaType, operationMode, signal, }?: {
104
+ disabledUiFeatures?: UiFeature[] | undefined;
81
105
  hideMainHeaderAndFooter?: boolean | undefined;
82
106
  hideWorkbookToolBar?: boolean | undefined;
107
+ highlightGlobalId?: string | undefined;
108
+ mediaType?: string | undefined;
109
+ operationMode?: OperationMode | undefined;
83
110
  signal?: AbortSignal | undefined;
84
111
  } | undefined): Promise<void>;
85
112
  /**
@@ -87,22 +114,28 @@ export class CadenzaClient {
87
114
  *
88
115
  * @param {WorkbookViewSource} mapView - The workbook map view to show
89
116
  * @param {object} [options] - Options
117
+ * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
90
118
  * @param {Geometry} [options.geometry] - A geometry to show on the map
91
- * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer.
92
- * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar.
119
+ * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
120
+ * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
121
+ * @param {GlobalId} [options.highlightGlobalId] - The ID of an item to highlight / expand in the navigator
93
122
  * @param {string} [options.locationFinder] - A search query for the location finder
94
123
  * @param {Extent} [options.mapExtent] - A map extent to set
124
+ * @param {OperationMode} [options.operationMode] - The mode in which a workbook should be operated
95
125
  * @param {boolean} [options.useMapSrs] - Whether the geometry and the extent are in the map's SRS (otherwise EPSG:4326 is assumed)
96
126
  * @param {AbortSignal} [options.signal] - A signal to abort the iframe loading
97
127
  * @return {Promise<void>} A Promise for when the iframe is loaded
98
- * @throws For an invalid workbook view source or geometry type
128
+ * @throws For invalid arguments
99
129
  */
100
- showMap(mapView: WorkbookViewSource, { geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, locationFinder, mapExtent, useMapSrs, signal, }?: {
130
+ showMap(mapView: WorkbookViewSource, { disabledUiFeatures, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, }?: {
131
+ disabledUiFeatures?: UiFeature[] | undefined;
101
132
  geometry?: Geometry | undefined;
102
133
  hideMainHeaderAndFooter?: boolean | undefined;
103
134
  hideWorkbookToolBar?: boolean | undefined;
135
+ highlightGlobalId?: string | undefined;
104
136
  locationFinder?: string | undefined;
105
137
  mapExtent?: Extent | undefined;
138
+ operationMode?: OperationMode | undefined;
106
139
  useMapSrs?: boolean | undefined;
107
140
  signal?: AbortSignal | undefined;
108
141
  } | undefined): Promise<void>;
@@ -115,22 +148,22 @@ export class CadenzaClient {
115
148
  * @param {WorkbookViewSource} backgroundMapView - The workbook map view in the background
116
149
  * @param {GeometryType} geometryType - The geometry type
117
150
  * @param {object} [options] - Options
118
- * @param {Extent} [options.mapExtent] - A map extent to set
119
151
  * @param {string} [options.locationFinder] - A search query for the location finder
120
- * @param {boolean} [options.useMapSrs] - Whether the created geometry should use the map's SRS (otherwise EPSG:4326 will be used)
152
+ * @param {Extent} [options.mapExtent] - A map extent to set
121
153
  * @param {number} [options.minScale] - The minimum scale where the user should work on. A warning is shown when the map is zoomed out above the threshold.
154
+ * @param {boolean} [options.useMapSrs] - Whether the created geometry should use the map's SRS (otherwise EPSG:4326 will be used)
122
155
  * @param {AbortSignal} [options.signal] - A signal to abort the iframe loading
123
156
  * @return {Promise<void>} A Promise for when the iframe is loaded
124
- * @throws For an invalid workbook view source or geometry type
157
+ * @throws For invalid arguments
125
158
  * @fires `editGeometry:update` - When the user changed the geometry. The event includes the edited geometry.
126
159
  * @fires `editGeometry:ok` - When the user completed the geometry editing. The event includes the edited geometry.
127
160
  * @fires `editGeometry:cancel` - When the user cancelled the geometry editing in Cadenza.
128
161
  */
129
- createGeometry(backgroundMapView: WorkbookViewSource, geometryType: GeometryType, { mapExtent, locationFinder, useMapSrs, minScale, signal }?: {
130
- mapExtent?: Extent | undefined;
162
+ createGeometry(backgroundMapView: WorkbookViewSource, geometryType: GeometryType, { locationFinder, mapExtent, minScale, useMapSrs, signal }?: {
131
163
  locationFinder?: string | undefined;
132
- useMapSrs?: boolean | undefined;
164
+ mapExtent?: Extent | undefined;
133
165
  minScale?: number | undefined;
166
+ useMapSrs?: boolean | undefined;
134
167
  signal?: AbortSignal | undefined;
135
168
  } | undefined): Promise<void>;
136
169
  /**
@@ -141,20 +174,20 @@ export class CadenzaClient {
141
174
  * @param {object} [options] - Options
142
175
  * @param {string} [options.locationFinder] - A search query for the location finder
143
176
  * @param {Extent} [options.mapExtent] - A map extent to set
144
- * @param {boolean} [options.useMapSrs] - Whether the geometry is in the map's SRS (otherwise EPSG:4326 is assumed)
145
177
  * @param {number} [options.minScale] - The minimum scale where the user should work on. A warning is shown when the map is zoomed out above the threshold.
178
+ * @param {boolean} [options.useMapSrs] - Whether the geometry is in the map's SRS (otherwise EPSG:4326 is assumed)
146
179
  * @param {AbortSignal} [options.signal] - A signal to abort the iframe loading
147
180
  * @return {Promise<void>} A Promise for when the iframe is loaded
148
- * @throws For an invalid workbook view source
181
+ * @throws For invalid arguments
149
182
  * @fires `editGeometry:update` - When the user changed the geometry. The event includes the edited geometry.
150
183
  * @fires `editGeometry:ok` - When the user completed the geometry editing. The event includes the edited geometry.
151
184
  * @fires `editGeometry:cancel` - When the user cancelled the geometry editing in Cadenza.
152
185
  */
153
- editGeometry(backgroundMapView: WorkbookViewSource, geometry: Geometry, { mapExtent, locationFinder, useMapSrs, minScale, signal }?: {
186
+ editGeometry(backgroundMapView: WorkbookViewSource, geometry: Geometry, { locationFinder, mapExtent, minScale, useMapSrs, signal }?: {
154
187
  locationFinder?: string | undefined;
155
188
  mapExtent?: Extent | undefined;
156
- useMapSrs?: boolean | undefined;
157
189
  minScale?: number | undefined;
190
+ useMapSrs?: boolean | undefined;
158
191
  signal?: AbortSignal | undefined;
159
192
  } | undefined): Promise<void>;
160
193
  /**
@@ -166,6 +199,41 @@ export class CadenzaClient {
166
199
  * @return {() => void} An unsubscribe function
167
200
  */
168
201
  on<T = unknown>(type: string, subscriber: (event: CadenzaEvent<T>) => void): () => void;
202
+ /**
203
+ * Fetch data from a workbook view.
204
+ *
205
+ * @param {WorkbookViewSource} source - The workbook view to fetch data from
206
+ * @param {MediaType} mediaType - The media type to use for the data. Allowed are:
207
+ * * 'application/json'
208
+ * * 'application/pdf' (for Jasper Report views)
209
+ * * 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' (Excel)
210
+ * * 'text/csv'
211
+ * @param {object} options - Options
212
+ * @param {AbortSignal} [options.signal] - A signal to abort the data fetching
213
+ * @return {Promise<Response>} A Promise for the fetch response
214
+ * @throws For invalid arguments
215
+ */
216
+ fetchData(source: WorkbookViewSource, mediaType: MediaType, { signal }?: {
217
+ signal?: AbortSignal | undefined;
218
+ }): Promise<Response>;
219
+ /**
220
+ * Download data from a workbook view.
221
+ *
222
+ * _Note:_ The file name, if not provided, is generated from the name of the workbook view and the current date.
223
+ *
224
+ * @param {WorkbookViewSource} source - The workbook view to download data from
225
+ * @param {MediaType} mediaType - The media type to use for the data. Allowed are:
226
+ * * 'application/json'
227
+ * * 'application/pdf' (for Jasper Report views)
228
+ * * 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' (Excel)
229
+ * * 'text/csv'
230
+ * @param {object} options - Options
231
+ * @param {string} [options.fileName] - The file name to use; The file extension is appended by Cadenza.
232
+ * @throws For invalid arguments
233
+ */
234
+ downloadData(source: WorkbookViewSource, mediaType: MediaType, { fileName }: {
235
+ fileName?: string | undefined;
236
+ }): void;
169
237
  #private;
170
238
  }
171
239
  /**
@@ -196,6 +264,23 @@ export class CadenzaError extends Error {
196
264
  * - The ID of an embedding target
197
265
  */
198
266
  export type EmbeddingTargetId = string;
267
+ /**
268
+ * - The ID of a navigator item
269
+ */
270
+ export type GlobalId = string;
271
+ /**
272
+ * - A tuple qualifying a Cadenza external link
273
+ */
274
+ export type ExternalLinkKey = {
275
+ /**
276
+ * - The name of the link's repository
277
+ */
278
+ repositoryName: string;
279
+ /**
280
+ * - The ID of the external link
281
+ */
282
+ externalLinkId: string;
283
+ };
199
284
  /**
200
285
  * - A tuple qualifying a workbook
201
286
  */
@@ -255,6 +340,18 @@ export type WorksheetSource = EmbeddingTargetId | WorksheetKey;
255
340
  * - A workbook view source
256
341
  */
257
342
  export type WorkbookViewSource = EmbeddingTargetId | WorkbookViewKey;
343
+ /**
344
+ * - The mode in which a workbook should be operated
345
+ */
346
+ export type OperationMode = 'normal' | 'simplified';
347
+ /**
348
+ * - The name of a Cadenza UI feature
349
+ *
350
+ * _Note:_ Supported features are:
351
+ * * 'workbook-design' - The workbook designer
352
+ * * 'workbook-view-management' - Add/Edit/Remove workbook views (Is included in 'workbook-design'.)
353
+ */
354
+ export type UiFeature = 'workbook-design' | 'workbook-view-management';
258
355
  /**
259
356
  * - A [GeoJSON](https://geojson.org/) geometry object
260
357
  */
@@ -274,6 +371,12 @@ export type GeometryType = 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineStr
274
371
  * - An array of numbers representing an extent: [minx, miny, maxx, maxy]
275
372
  */
276
373
  export type Extent = [number, number, number, number];
374
+ /**
375
+ * - A media type
376
+ *
377
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types}
378
+ */
379
+ export type MediaType = string;
277
380
  /**
278
381
  * - A Cadenza `postMessage()` event
279
382
  */
@@ -294,3 +397,10 @@ export type CadenzaErrorEvent = CadenzaEvent<{
294
397
  type: string;
295
398
  message?: string;
296
399
  }>;
400
+ declare namespace MediaType {
401
+ let CSV: string;
402
+ let EXCEL: string;
403
+ let JSON: string;
404
+ let PDF: string;
405
+ }
406
+ export {};