@disy/cadenza.js 1.6.0 → 1.7.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,9 @@ 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
+ /**
72
+ * @typedef {Record<string, string | number | Date>} FilterVariables - Filter variable values
73
+ */
71
74
  /**
72
75
  * _Notes:_
73
76
  * * Most public methods can be aborted using an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal).
@@ -101,6 +104,8 @@ export class CadenzaClient {
101
104
  * @param {object} [options]
102
105
  * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
103
106
  * @param {boolean} [options.expandNavigator] - Indicates if the navigator should be expanded.
107
+ * @param {FilterVariables} [options.filter] - Filter variables. The keys should contain the
108
+ * filter variable names and the values the filter variable values.
104
109
  * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
105
110
  * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
106
111
  * @param {GlobalId} [options.highlightGlobalId] - The ID of an item to highlight / expand in the navigator
@@ -112,9 +117,10 @@ export class CadenzaClient {
112
117
  * @return {Promise<void>} A Promise for when the iframe is loaded
113
118
  * @throws For invalid arguments
114
119
  */
115
- show(source: PageSource | WorkbookSource | WorksheetSource | WorkbookViewSource, { disabledUiFeatures, expandNavigator, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, mediaType, operationMode, signal, }?: {
120
+ show(source: PageSource | WorkbookSource | WorksheetSource | WorkbookViewSource, { disabledUiFeatures, expandNavigator, filter, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, mediaType, operationMode, signal, }?: {
116
121
  disabledUiFeatures?: UiFeature[] | undefined;
117
122
  expandNavigator?: boolean | undefined;
123
+ filter?: FilterVariables | undefined;
118
124
  hideMainHeaderAndFooter?: boolean | undefined;
119
125
  hideWorkbookToolBar?: boolean | undefined;
120
126
  highlightGlobalId?: string | undefined;
@@ -130,6 +136,8 @@ export class CadenzaClient {
130
136
  * @param {object} [options] - Options
131
137
  * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
132
138
  * @param {boolean} [options.expandNavigator] - Indicates if the navigator should be expanded.
139
+ * @param {FilterVariables} [options.filter] - Filter variables. The keys should contain the
140
+ * filter variable names and the values the filter variable values.
133
141
  * @param {Geometry} [options.geometry] - A geometry to show on the map
134
142
  * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
135
143
  * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
@@ -142,9 +150,10 @@ export class CadenzaClient {
142
150
  * @return {Promise<void>} A Promise for when the iframe is loaded
143
151
  * @throws For invalid arguments
144
152
  */
145
- showMap(mapView: WorkbookViewSource, { disabledUiFeatures, expandNavigator, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, }?: {
153
+ showMap(mapView: WorkbookViewSource, { disabledUiFeatures, expandNavigator, filter, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, }?: {
146
154
  disabledUiFeatures?: UiFeature[] | undefined;
147
155
  expandNavigator?: boolean | undefined;
156
+ filter?: FilterVariables | undefined;
148
157
  geometry?: Geometry | undefined;
149
158
  hideMainHeaderAndFooter?: boolean | undefined;
150
159
  hideWorkbookToolBar?: boolean | undefined;
@@ -416,6 +425,10 @@ export type MediaType = string;
416
425
  * - A part of a table to export.
417
426
  */
418
427
  export type TablePart = 'columns' | 'values' | 'totals';
428
+ /**
429
+ * - Filter variable values
430
+ */
431
+ export type FilterVariables = Record<string, string | number | Date>;
419
432
  /**
420
433
  * - A Cadenza `postMessage()` event
421
434
  */
package/cadenza.js CHANGED
@@ -74,6 +74,9 @@ 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
+ /**
78
+ * @typedef {Record<string, string | number | Date>} FilterVariables - Filter variable values
79
+ */
77
80
  /**
78
81
  * _Notes:_
79
82
  * * Most public methods can be aborted using an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal).
@@ -149,6 +152,8 @@ export class CadenzaClient {
149
152
  * @param {object} [options]
150
153
  * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
151
154
  * @param {boolean} [options.expandNavigator] - Indicates if the navigator should be expanded.
155
+ * @param {FilterVariables} [options.filter] - Filter variables. The keys should contain the
156
+ * filter variable names and the values the filter variable values.
152
157
  * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
153
158
  * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
154
159
  * @param {GlobalId} [options.highlightGlobalId] - The ID of an item to highlight / expand in the navigator
@@ -160,7 +165,7 @@ export class CadenzaClient {
160
165
  * @return {Promise<void>} A Promise for when the iframe is loaded
161
166
  * @throws For invalid arguments
162
167
  */
163
- show(source, { disabledUiFeatures, expandNavigator, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, mediaType, operationMode, signal, } = {}) {
168
+ show(source, { disabledUiFeatures, expandNavigator, filter, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, mediaType, operationMode, signal, } = {}) {
164
169
  this.#log('CadenzaClient#show', source);
165
170
  if (mediaType) {
166
171
  assertSupportedMediaType(mediaType, [MediaType.PDF]);
@@ -173,6 +178,7 @@ export class CadenzaClient {
173
178
  const params = createParams({
174
179
  disabledUiFeatures,
175
180
  expandNavigator,
181
+ filter,
176
182
  hideMainHeaderAndFooter,
177
183
  hideWorkbookToolBar,
178
184
  highlightGlobalId,
@@ -190,6 +196,8 @@ export class CadenzaClient {
190
196
  * @param {object} [options] - Options
191
197
  * @param {UiFeature[]} [options.disabledUiFeatures] - Cadenza UI features to disable
192
198
  * @param {boolean} [options.expandNavigator] - Indicates if the navigator should be expanded.
199
+ * @param {FilterVariables} [options.filter] - Filter variables. The keys should contain the
200
+ * filter variable names and the values the filter variable values.
193
201
  * @param {Geometry} [options.geometry] - A geometry to show on the map
194
202
  * @param {boolean} [options.hideMainHeaderAndFooter] - Whether to hide the main Cadenza header and footer
195
203
  * @param {boolean} [options.hideWorkbookToolBar] - Whether to hide the workbook toolbar
@@ -202,7 +210,7 @@ export class CadenzaClient {
202
210
  * @return {Promise<void>} A Promise for when the iframe is loaded
203
211
  * @throws For invalid arguments
204
212
  */
205
- async showMap(mapView, { disabledUiFeatures, expandNavigator, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, } = {}) {
213
+ async showMap(mapView, { disabledUiFeatures, expandNavigator, filter, geometry, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, locationFinder, mapExtent, operationMode, useMapSrs, signal, } = {}) {
206
214
  this.#log('CadenzaClient#showMap', mapView, geometry);
207
215
  if (geometry) {
208
216
  assertValidGeometryType(geometry.type);
@@ -210,6 +218,7 @@ export class CadenzaClient {
210
218
  const params = createParams({
211
219
  disabledUiFeatures,
212
220
  expandNavigator,
221
+ filter,
213
222
  hideMainHeaderAndFooter,
214
223
  hideWorkbookToolBar,
215
224
  highlightGlobalId,
@@ -475,7 +484,7 @@ export class CadenzaClient {
475
484
  function resolvePath(
476
485
  /** @type PageSource | WorkbookSource | WorksheetSource | WorkbookViewSource */ source) {
477
486
  if (typeof source === 'string') {
478
- assert(validEmbeddingTargetId(source), `Invalid embedding target ID: ${source}`);
487
+ assert(validKebabCaseString(source), `Invalid embedding target ID: ${source}`);
479
488
  return `/w/${source}`;
480
489
  }
481
490
  else if ('page' in source) {
@@ -518,7 +527,7 @@ function validUrl(/** @type string */ value) {
518
527
  function validPageName(/** @type string */ value) {
519
528
  return ['welcome'].includes(value);
520
529
  }
521
- function validEmbeddingTargetId(/** @type string */ value) {
530
+ function validKebabCaseString(/** @type string */ value) {
522
531
  return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value);
523
532
  }
524
533
  function validRepositoryName(/** @type string */ value) {
@@ -578,6 +587,8 @@ function assertSupportedMediaType(
578
587
  * @param {UiFeature[]} [params.disabledUiFeatures]
579
588
  * @param {boolean} [params.expandNavigator]
580
589
  * @param {string} [params.fileName]
590
+ * @param {FilterVariables} [params.filter] - Filter variables. The keys should contain the filter
591
+ * variable names and the values the filter variable values.
581
592
  * @param {GeometryType} [params.geometryType]
582
593
  * @param {boolean} [params.hideMainHeaderAndFooter]
583
594
  * @param {boolean} [params.hideWorkbookToolBar]
@@ -593,7 +604,7 @@ function assertSupportedMediaType(
593
604
  * @param {ExternalLinkKey} [params.webApplication]
594
605
  * @return {URLSearchParams}
595
606
  */
596
- function createParams({ action, expandNavigator, fileName, geometryType, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, locationFinder, mapExtent, mediaType, minScale, parts, useMapSrs, webApplication, operationMode, disabledUiFeatures, }) {
607
+ function createParams({ action, disabledUiFeatures, expandNavigator, fileName, filter, geometryType, hideMainHeaderAndFooter, hideWorkbookToolBar, highlightGlobalId, labelSet, locationFinder, mapExtent, mediaType, minScale, parts, useMapSrs, webApplication, operationMode, }) {
597
608
  if (disabledUiFeatures) {
598
609
  disabledUiFeatures.forEach((feature) => assert(validUiFeature(feature), `Invalid UI feature: ${feature}`));
599
610
  }
@@ -606,6 +617,9 @@ function createParams({ action, expandNavigator, fileName, geometryType, hideMai
606
617
  if (parts) {
607
618
  parts.forEach((part) => assert(validTablePart(part), `Invalid table part: ${part}`));
608
619
  }
620
+ if (filter) {
621
+ Object.keys(filter).forEach((varName) => assert(validKebabCaseString(varName), `Invalid filter variable name: ${varName}`));
622
+ }
609
623
  return new URLSearchParams({
610
624
  ...(action && { action }),
611
625
  ...(disabledUiFeatures && {
@@ -629,6 +643,11 @@ function createParams({ action, expandNavigator, fileName, geometryType, hideMai
629
643
  webApplicationLink: webApplication.externalLinkId,
630
644
  webApplicationLinkRepository: webApplication.repositoryName,
631
645
  }),
646
+ ...(filter &&
647
+ Object.fromEntries(Object.entries(filter).map(([variable, value]) => [
648
+ `filter.${variable}`,
649
+ JSON.stringify(value instanceof Date ? value.toISOString() : value),
650
+ ]))),
632
651
  });
633
652
  }
634
653
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@disy/cadenza.js",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": "github:DisyInformationssysteme/cadenza.js",
6
6
  "type": "module",
package/sandbox.html CHANGED
@@ -129,7 +129,8 @@
129
129
  minScale,
130
130
  parts,
131
131
  simplifiedOperationMode,
132
- useMapSrs
132
+ useMapSrs,
133
+ filter
133
134
  }) {
134
135
  return {
135
136
  disabledUiFeatures: disabledUiFeatures && disabledUiFeatures.split(','),
@@ -145,9 +146,22 @@
145
146
  minScale,
146
147
  parts: parts && parts.split(','),
147
148
  ...(simplifiedOperationMode === 'on' && { operationMode: 'simplified' }),
148
- useMapSrs: useMapSrs === 'on'
149
+ useMapSrs: useMapSrs === 'on',
150
+ filter: filter && parseFilterVariables(filter)
149
151
  };
150
152
  }
153
+
154
+ function parseFilterVariables (filterString) {
155
+ return JSON.parse(filterString, (_, value) => {
156
+ if (value === '{{currentDate}}') { // convenience for current date
157
+ return new Date();
158
+ }
159
+ if (value.match?.(/....-..-..T..:..:..\....Z/)) {
160
+ return new Date(value);
161
+ }
162
+ return value;
163
+ });
164
+ }
151
165
  </script>
152
166
  </head>
153
167
  <body>
@@ -212,6 +226,10 @@
212
226
  <label for="disabledUiFeatures">Disabled UI features</label>
213
227
  <input name="disabledUiFeatures" id="disabledUiFeatures" placeholder="feature1,feature2...">
214
228
  </div>
229
+ <div>
230
+ <label for="filter">Filter</label>
231
+ <input name="filter" id="filter" placeholder='{ "textvar": "foo", "numbervar": 42.0, "datevar1": "2000-01-01T00.000Z", "datevar2": "{{currentDate}}" }'>
232
+ </div>
215
233
  </template>
216
234
 
217
235
  <template id="common-map">