@disy/cadenza.js 1.6.0 → 1.8.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
@@ -68,6 +68,7 @@ export function cadenza(baseUrl: string, options?: {
68
68
  * See {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types}
69
69
  */
70
70
  /** @typedef {'columns' | 'values' | 'totals'} TablePart - A part of a table to export. */
71
+ /** @typedef {Record<string, string | number | Date>} FilterVariables - Filter variable names and values */
71
72
  /**
72
73
  * _Notes:_
73
74
  * * Most public methods can be aborted using an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal).
@@ -101,6 +102,7 @@ export class CadenzaClient {
101
102
  * @param {object} [options]
102
103
  * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
103
104
  * @param {boolean} [options.expandNavigator] - Indicates if the navigator should be expanded.
105
+ * @param {FilterVariables} [options.filter] - Filter variables
104
106
  * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
105
107
  * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
106
108
  * @param {GlobalId} [options.highlightGlobalId] - The ID of an item to highlight / expand in the navigator
@@ -112,9 +114,10 @@ export class CadenzaClient {
112
114
  * @return {Promise<void>} A Promise for when the iframe is loaded
113
115
  * @throws For invalid arguments
114
116
  */
115
- show(source: PageSource | WorkbookSource | WorksheetSource | WorkbookViewSource, { disabledUiFeatures, expandNavigator, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, mediaType, operationMode, signal, }?: {
117
+ show(source: PageSource | WorkbookSource | WorksheetSource | WorkbookViewSource, { disabledUiFeatures, expandNavigator, filter, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, mediaType, operationMode, signal, }?: {
116
118
  disabledUiFeatures?: UiFeature[] | undefined;
117
119
  expandNavigator?: boolean | undefined;
120
+ filter?: FilterVariables | undefined;
118
121
  hideMainHeaderAndFooter?: boolean | undefined;
119
122
  hideWorkbookToolBar?: boolean | undefined;
120
123
  highlightGlobalId?: string | undefined;
@@ -130,6 +133,7 @@ export class CadenzaClient {
130
133
  * @param {object} [options] - Options
131
134
  * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
132
135
  * @param {boolean} [options.expandNavigator] - Indicates if the navigator should be expanded.
136
+ * @param {FilterVariables} [options.filter] - Filter variables
133
137
  * @param {Geometry} [options.geometry] - A geometry to show on the map
134
138
  * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
135
139
  * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
@@ -142,9 +146,10 @@ export class CadenzaClient {
142
146
  * @return {Promise<void>} A Promise for when the iframe is loaded
143
147
  * @throws For invalid arguments
144
148
  */
145
- showMap(mapView: WorkbookViewSource, { disabledUiFeatures, expandNavigator, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, }?: {
149
+ showMap(mapView: WorkbookViewSource, { disabledUiFeatures, expandNavigator, filter, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, }?: {
146
150
  disabledUiFeatures?: UiFeature[] | undefined;
147
151
  expandNavigator?: boolean | undefined;
152
+ filter?: FilterVariables | undefined;
148
153
  geometry?: Geometry | undefined;
149
154
  hideMainHeaderAndFooter?: boolean | undefined;
150
155
  hideWorkbookToolBar?: boolean | undefined;
@@ -416,6 +421,10 @@ export type MediaType = string;
416
421
  * - A part of a table to export.
417
422
  */
418
423
  export type TablePart = 'columns' | 'values' | 'totals';
424
+ /**
425
+ * - Filter variable names and values
426
+ */
427
+ export type FilterVariables = Record<string, string | number | Date>;
419
428
  /**
420
429
  * - A Cadenza `postMessage()` event
421
430
  */
package/cadenza.js CHANGED
@@ -74,6 +74,7 @@ globalThis.cadenza = Object.assign((/** @type Parameters<cadenza> */ ...args) =>
74
74
  * See {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types}
75
75
  */
76
76
  /** @typedef {'columns' | 'values' | 'totals'} TablePart - A part of a table to export. */
77
+ /** @typedef {Record<string, string | number | Date>} FilterVariables - Filter variable names and values */
77
78
  /**
78
79
  * _Notes:_
79
80
  * * Most public methods can be aborted using an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal).
@@ -149,6 +150,7 @@ export class CadenzaClient {
149
150
  * @param {object} [options]
150
151
  * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
151
152
  * @param {boolean} [options.expandNavigator] - Indicates if the navigator should be expanded.
153
+ * @param {FilterVariables} [options.filter] - Filter variables
152
154
  * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
153
155
  * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
154
156
  * @param {GlobalId} [options.highlightGlobalId] - The ID of an item to highlight / expand in the navigator
@@ -160,7 +162,7 @@ export class CadenzaClient {
160
162
  * @return {Promise<void>} A Promise for when the iframe is loaded
161
163
  * @throws For invalid arguments
162
164
  */
163
- show(source, { disabledUiFeatures, expandNavigator, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, mediaType, operationMode, signal, } = {}) {
165
+ show(source, { disabledUiFeatures, expandNavigator, filter, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, mediaType, operationMode, signal, } = {}) {
164
166
  this.#log('CadenzaClient#show', source);
165
167
  if (mediaType) {
166
168
  assertSupportedMediaType(mediaType, [MediaType.PDF]);
@@ -173,6 +175,7 @@ export class CadenzaClient {
173
175
  const params = createParams({
174
176
  disabledUiFeatures,
175
177
  expandNavigator,
178
+ filter,
176
179
  hideMainHeaderAndFooter,
177
180
  hideWorkbookToolBar,
178
181
  highlightGlobalId,
@@ -190,6 +193,7 @@ export class CadenzaClient {
190
193
  * @param {object} [options] - Options
191
194
  * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
192
195
  * @param {boolean} [options.expandNavigator] - Indicates if the navigator should be expanded.
196
+ * @param {FilterVariables} [options.filter] - Filter variables
193
197
  * @param {Geometry} [options.geometry] - A geometry to show on the map
194
198
  * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
195
199
  * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
@@ -202,7 +206,7 @@ export class CadenzaClient {
202
206
  * @return {Promise<void>} A Promise for when the iframe is loaded
203
207
  * @throws For invalid arguments
204
208
  */
205
- async showMap(mapView, { disabledUiFeatures, expandNavigator, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, } = {}) {
209
+ async showMap(mapView, { disabledUiFeatures, expandNavigator, filter, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, } = {}) {
206
210
  this.#log('CadenzaClient#showMap', mapView, geometry);
207
211
  if (geometry) {
208
212
  assertValidGeometryType(geometry.type);
@@ -210,6 +214,7 @@ export class CadenzaClient {
210
214
  const params = createParams({
211
215
  disabledUiFeatures,
212
216
  expandNavigator,
217
+ filter,
213
218
  hideMainHeaderAndFooter,
214
219
  hideWorkbookToolBar,
215
220
  highlightGlobalId,
@@ -475,7 +480,7 @@ export class CadenzaClient {
475
480
  function resolvePath(
476
481
  /** @type PageSource | WorkbookSource | WorksheetSource | WorkbookViewSource */ source) {
477
482
  if (typeof source === 'string') {
478
- assert(validEmbeddingTargetId(source), `Invalid embedding target ID: ${source}`);
483
+ assert(validKebabCaseString(source), `Invalid embedding target ID: ${source}`);
479
484
  return `/w/${source}`;
480
485
  }
481
486
  else if ('page' in source) {
@@ -518,7 +523,7 @@ function validUrl(/** @type string */ value) {
518
523
  function validPageName(/** @type string */ value) {
519
524
  return ['welcome'].includes(value);
520
525
  }
521
- function validEmbeddingTargetId(/** @type string */ value) {
526
+ function validKebabCaseString(/** @type string */ value) {
522
527
  return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value);
523
528
  }
524
529
  function validRepositoryName(/** @type string */ value) {
@@ -578,6 +583,7 @@ function assertSupportedMediaType(
578
583
  * @param {UiFeature[]} [params.disabledUiFeatures]
579
584
  * @param {boolean} [params.expandNavigator]
580
585
  * @param {string} [params.fileName]
586
+ * @param {FilterVariables} [params.filter]
581
587
  * @param {GeometryType} [params.geometryType]
582
588
  * @param {boolean} [params.hideMainHeaderAndFooter]
583
589
  * @param {boolean} [params.hideWorkbookToolBar]
@@ -593,10 +599,13 @@ function assertSupportedMediaType(
593
599
  * @param {ExternalLinkKey} [params.webApplication]
594
600
  * @return {URLSearchParams}
595
601
  */
596
- function createParams({ action, expandNavigator, fileName, geometryType, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, locationFinder, mapExtent, mediaType, minScale, parts, useMapSrs, webApplication, operationMode, disabledUiFeatures, }) {
602
+ function createParams({ action, disabledUiFeatures, expandNavigator, fileName, filter, geometryType, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, locationFinder, mapExtent, mediaType, minScale, parts, useMapSrs, webApplication, operationMode, }) {
597
603
  if (disabledUiFeatures) {
598
604
  disabledUiFeatures.forEach((feature) => assert(validUiFeature(feature), `Invalid UI feature: ${feature}`));
599
605
  }
606
+ if (filter) {
607
+ Object.keys(filter).forEach((varName) => assert(validKebabCaseString(varName), `Invalid filter variable name: ${varName}`));
608
+ }
600
609
  if (geometryType) {
601
610
  assertValidGeometryType(geometryType);
602
611
  }
@@ -613,6 +622,11 @@ function createParams({ action, expandNavigator, fileName, geometryType, hideMai
613
622
  }),
614
623
  ...(expandNavigator && { expandNavigator: 'true' }),
615
624
  ...(fileName && { fileName }),
625
+ ...(filter &&
626
+ Object.fromEntries(Object.entries(filter).map(([variable, value]) => [
627
+ `filter.${variable}`,
628
+ JSON.stringify(value instanceof Date ? value.toISOString() : value),
629
+ ]))),
616
630
  ...(geometryType && { geometryType }),
617
631
  ...(hideMainHeaderAndFooter && { hideMainHeaderAndFooter: 'true' }),
618
632
  ...(hideWorkbookToolBar && { hideWorkbookToolBar: 'true' }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@disy/cadenza.js",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": "github:DisyInformationssysteme/cadenza.js",
6
6
  "type": "module",
package/sandbox.html CHANGED
@@ -28,7 +28,21 @@
28
28
  form, fieldset {
29
29
  display: flex;
30
30
  flex-direction: column;
31
- gap: 16px;
31
+ gap: 12px;
32
+ }
33
+ fieldset > div {
34
+ display: flex;
35
+ flex-direction: column;
36
+ gap: 4px;
37
+ }
38
+ fieldset small {
39
+ display: flex;
40
+ flex-direction: column;
41
+ gap: 4px;
42
+
43
+ & > * {
44
+ margin-block: 0;
45
+ }
32
46
  }
33
47
  main {
34
48
  flex: 1;
@@ -57,11 +71,13 @@
57
71
  const action = actionSelect.value;
58
72
  const settingsTemplate = document.querySelector(`[data-action=${action}]`);
59
73
  settingsContainer.append(settingsTemplate.content.cloneNode(true));
60
- const commonSettingsTemplate = document.getElementById(`common-${settingsTemplate.dataset.common}`);
61
- if (commonSettingsTemplate) {
62
- settingsContainer.append(
63
- document.createElement('hr'),
64
- commonSettingsTemplate.content.cloneNode(true));
74
+ if (settingsTemplate.dataset.common) {
75
+ settingsTemplate.dataset.common.split(',').forEach(commonId => {
76
+ const commonSettingsTemplate = document.getElementById(`common-${commonId}`);
77
+ settingsContainer.append(
78
+ document.createElement('hr'),
79
+ commonSettingsTemplate.content.cloneNode(true));
80
+ })
65
81
  }
66
82
 
67
83
  const data = localStorage.getItem(`cadenzajs-sandbox-${action}`);
@@ -118,6 +134,7 @@
118
134
  function getOptions ({
119
135
  disabledUiFeatures,
120
136
  expandNavigator,
137
+ filter,
121
138
  geometry,
122
139
  hideMainHeaderAndFooter,
123
140
  hideWorkbookToolBar,
@@ -134,6 +151,7 @@
134
151
  return {
135
152
  disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(','),
136
153
  expandNavigator: (expandNavigator === 'on'),
154
+ filter: filter && parseFilterVariables(filter),
137
155
  geometry: geometry && JSON.parse(geometry),
138
156
  hideMainHeaderAndFooter: (hideMainHeaderAndFooter === 'on'),
139
157
  hideWorkbookToolBar: (hideWorkbookToolBar === 'on'),
@@ -148,6 +166,18 @@
148
166
  useMapSrs: useMapSrs === 'on'
149
167
  };
150
168
  }
169
+
170
+ function parseFilterVariables (filterString) {
171
+ return JSON.parse(filterString, (_, value) => {
172
+ if (value === '{{currentDate}}') { // convenience for current date
173
+ return new Date();
174
+ }
175
+ if (value.match?.(/....-..-..T..:..:..\....Z/)) {
176
+ return new Date(value);
177
+ }
178
+ return value;
179
+ });
180
+ }
151
181
  </script>
152
182
  </head>
153
183
  <body>
@@ -210,7 +240,25 @@
210
240
  </div>
211
241
  <div>
212
242
  <label for="disabledUiFeatures">Disabled UI features</label>
213
- <input name="disabledUiFeatures" id="disabledUiFeatures" placeholder="feature1,feature2...">
243
+ <input name="disabledUiFeatures" id="disabledUiFeatures" placeholder="feature1,feature2,...">
244
+
245
+ <small>
246
+ <p>Comma-separated list of features</p>
247
+
248
+ Supported features:
249
+ <ul>
250
+ <li>workbook-design</li>
251
+ <li>workbook-view-management</li>
252
+ </ul>
253
+ </small>
254
+ </div>
255
+ <div>
256
+ <label for="filter">Filter</label>
257
+ <textarea name="filter" id="filter" rows="3"></textarea>
258
+ <small>
259
+ <p>A JSON object with filter variable names and values</p>
260
+ <p>Dates need to be ISO strings<br>(e.g. <code>"2023-11-17T17:12:06.175Z"</code>).<br>Use <code>"{{currentDate}}"</code> for the current date.</p>
261
+ </small>
214
262
  </div>
215
263
  </template>
216
264
 
@@ -283,7 +331,7 @@
283
331
  </div>
284
332
  </template>
285
333
 
286
- <template data-action="showMap" data-common="show">
334
+ <template data-action="showMap" data-common="map,show">
287
335
  <div>
288
336
  <label for="embeddingTargetId">Embedding target ID of the map view *</label>
289
337
  <input name="embeddingTargetId" id="embeddingTargetId" required>