@disy/cadenza.js 2.5.0 → 2.6.1

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/apidoc/assets/search.js +1 -1
  3. package/apidoc/classes/AbortError.html +2 -2
  4. package/apidoc/classes/CadenzaClient.html +24 -20
  5. package/apidoc/classes/CadenzaError.html +3 -3
  6. package/apidoc/functions/cadenza.html +1 -1
  7. package/apidoc/interfaces/CadenzaEvent.html +3 -3
  8. package/apidoc/interfaces/ExternalLinkKey.html +3 -3
  9. package/apidoc/interfaces/Geometry.html +2 -2
  10. package/apidoc/interfaces/PageSource.html +2 -2
  11. package/apidoc/types/CadenzaChangeSelectionEvent.html +1 -1
  12. package/apidoc/types/CadenzaDrillThroughEvent.html +1 -1
  13. package/apidoc/types/CadenzaEditGeometryCancelEvent.html +1 -1
  14. package/apidoc/types/CadenzaEditGeometryOkEvent.html +1 -1
  15. package/apidoc/types/CadenzaEditGeometryUpdateEvent.html +1 -1
  16. package/apidoc/types/CadenzaErrorEvent.html +1 -1
  17. package/apidoc/types/CadenzaEventByType.html +1 -1
  18. package/apidoc/types/CadenzaEventType.html +1 -1
  19. package/apidoc/types/CadenzaObjectInfoEvent.html +1 -1
  20. package/apidoc/types/CadenzaSelectObjectsCancelEvent.html +1 -1
  21. package/apidoc/types/CadenzaSelectObjectsOkEvent.html +1 -1
  22. package/apidoc/types/DataType.html +1 -1
  23. package/apidoc/types/EmbeddingTargetId.html +1 -1
  24. package/apidoc/types/Extent.html +1 -1
  25. package/apidoc/types/FilterVariables.html +1 -1
  26. package/apidoc/types/GeometryType.html +1 -1
  27. package/apidoc/types/GlobalId.html +1 -1
  28. package/apidoc/types/OpaqueString.html +1 -1
  29. package/apidoc/types/OperationMode.html +1 -1
  30. package/apidoc/types/TablePart.html +1 -1
  31. package/apidoc/types/UiFeature.html +1 -1
  32. package/apidoc/types/WorkbookLayerPath.html +1 -1
  33. package/cadenza.d.ts +15 -3
  34. package/cadenza.js +25 -7
  35. package/package.json +1 -1
  36. package/sandbox.html +3 -3
package/cadenza.js CHANGED
@@ -162,6 +162,9 @@ export class CadenzaClient {
162
162
  }
163
163
  return this.#iframeElement;
164
164
  }
165
+ get #targetWindow() {
166
+ return /** @type {WindowProxy | null} */ this.iframe?.contentWindow;
167
+ }
165
168
  get #requiredIframe() {
166
169
  const iframe = /** @type {HTMLIFrameElement} */ (this.iframe);
167
170
  assert(iframe instanceof HTMLIFrameElement, 'Required iframe is not present.');
@@ -358,6 +361,7 @@ export class CadenzaClient {
358
361
  * @param {EmbeddingTargetId} backgroundMapView - The workbook map view in the background
359
362
  * @param {GeometryType} geometryType - The geometry type
360
363
  * @param {object} [options] - Options
364
+ * @param {FilterVariables} [options.filter] - Filter variables
361
365
  * @param {string} [options.locationFinder] - A search query for the location finder
362
366
  * @param {Extent} [options.mapExtent] - A map extent to set
363
367
  * @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.
@@ -370,10 +374,11 @@ export class CadenzaClient {
370
374
  * - {@link CadenzaEditGeometryOkEvent}
371
375
  * - {@link CadenzaEditGeometryCancelEvent}
372
376
  */
373
- createGeometry(backgroundMapView, geometryType, { locationFinder, mapExtent, minScale, useMapSrs, signal } = {}) {
377
+ createGeometry(backgroundMapView, geometryType, { filter, locationFinder, mapExtent, minScale, useMapSrs, signal } = {}) {
374
378
  this.#log('CadenzaClient#createGeometry', ...arguments);
375
379
  const params = createParams({
376
380
  action: 'editGeometry',
381
+ filter,
377
382
  geometryType,
378
383
  locationFinder,
379
384
  mapExtent,
@@ -388,6 +393,7 @@ export class CadenzaClient {
388
393
  * @param {EmbeddingTargetId} backgroundMapView - The workbook map view in the background
389
394
  * @param {Geometry} geometry - The geometry
390
395
  * @param {object} [options] - Options
396
+ * @param {FilterVariables} [options.filter] - Filter variables
391
397
  * @param {string} [options.locationFinder] - A search query for the location finder
392
398
  * @param {Extent} [options.mapExtent] - A map extent to set
393
399
  * @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.
@@ -400,11 +406,12 @@ export class CadenzaClient {
400
406
  * - {@link CadenzaEditGeometryOkEvent}
401
407
  * - {@link CadenzaEditGeometryCancelEvent}
402
408
  */
403
- async editGeometry(backgroundMapView, geometry, { locationFinder, mapExtent, minScale, useMapSrs, signal } = {}) {
409
+ async editGeometry(backgroundMapView, geometry, { filter, locationFinder, mapExtent, minScale, useMapSrs, signal } = {}) {
404
410
  this.#log('CadenzaClient#editGeometry', ...arguments);
405
411
  assertValidGeometryType(geometry.type);
406
412
  const params = createParams({
407
413
  action: 'editGeometry',
414
+ filter,
408
415
  locationFinder,
409
416
  mapExtent,
410
417
  minScale,
@@ -420,6 +427,7 @@ export class CadenzaClient {
420
427
  *
421
428
  * @param {EmbeddingTargetId} backgroundMapView - The workbook map view
422
429
  * @param {object} [options] - Options
430
+ * @param {FilterVariables} [options.filter] - Filter variables
423
431
  * @param {(WorkbookLayerPath | string)[]} [options.layers] - Layers to restrict the selection to
424
432
  * (identified using layer paths or print names)
425
433
  * @param {string} [options.locationFinder] - A search query for the location finder
@@ -434,10 +442,11 @@ export class CadenzaClient {
434
442
  * - {@link CadenzaSelectObjectsOkEvent}
435
443
  * - {@link CadenzaSelectObjectsCancelEvent}
436
444
  */
437
- selectObjects(backgroundMapView, { layers, locationFinder, mapExtent, useMapSrs, signal } = {}) {
445
+ selectObjects(backgroundMapView, { filter, layers, locationFinder, mapExtent, useMapSrs, signal } = {}) {
438
446
  this.#log('CadenzaClient#selectObjects', ...arguments);
439
447
  const params = createParams({
440
448
  action: 'selectObjects',
449
+ filter,
441
450
  layers: layers?.map(array),
442
451
  locationFinder,
443
452
  mapExtent,
@@ -559,8 +568,7 @@ export class CadenzaClient {
559
568
  // Use arrow function so that it's bound to this.
560
569
  #onMessage = (
561
570
  /** @type MessageEvent<CadenzaEvent<never, never>> */ event) => {
562
- if (event.origin !== this.#origin ||
563
- event.source !== this.#requiredIframe.contentWindow) {
571
+ if (event.origin !== this.#origin || event.source !== this.#targetWindow) {
564
572
  return;
565
573
  }
566
574
  const cadenzaEvent = event.data;
@@ -571,6 +579,15 @@ export class CadenzaClient {
571
579
  }
572
580
  });
573
581
  };
582
+ /**
583
+ * Remove all subscriptions.
584
+ *
585
+ * @see {@link CadenzaClient#on}
586
+ */
587
+ destroy() {
588
+ this.#subscriptions = [];
589
+ window.removeEventListener('message', this.#onMessage);
590
+ }
574
591
  /**
575
592
  * Posts an event to Cadenza and returns a `Promise` for the response.
576
593
  *
@@ -606,8 +623,9 @@ export class CadenzaClient {
606
623
  #postEvent(type, detail, transfer) {
607
624
  const cadenzaEvent = { type, detail };
608
625
  this.#log('postMessage', cadenzaEvent);
609
- const contentWindow = /** @type {WindowProxy} */ (this.#requiredIframe.contentWindow);
610
- contentWindow.postMessage(cadenzaEvent, {
626
+ const targetWindow = this.#targetWindow;
627
+ assert(targetWindow != null, 'Cannot find target window');
628
+ /** @type {WindowProxy} */ (targetWindow).postMessage(cadenzaEvent, {
611
629
  targetOrigin: this.#origin,
612
630
  transfer,
613
631
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@disy/cadenza.js",
3
- "version": "2.5.0",
3
+ "version": "2.6.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": "github:DisyInformationssysteme/cadenza.js",
6
6
  "type": "module",
package/sandbox.html CHANGED
@@ -440,7 +440,7 @@
440
440
 
441
441
  <template data-action="setFilter" data-common="filter"></template>
442
442
 
443
- <template data-action="createGeometry" data-common="map">
443
+ <template data-action="createGeometry" data-common="map,filter">
444
444
  <div>
445
445
  <label for="embeddingTargetId">Embedding target ID of the map view *</label>
446
446
  <input name="embeddingTargetId" id="embeddingTargetId" required>
@@ -462,7 +462,7 @@
462
462
  </div>
463
463
  </template>
464
464
 
465
- <template data-action="editGeometry" data-common="map">
465
+ <template data-action="editGeometry" data-common="map,filter">
466
466
  <div>
467
467
  <label for="embeddingTargetId">Embedding target ID of the map view *</label>
468
468
  <input name="embeddingTargetId" id="embeddingTargetId" required>
@@ -477,7 +477,7 @@
477
477
  </div>
478
478
  </template>
479
479
 
480
- <template data-action="selectObjects" data-common="map">
480
+ <template data-action="selectObjects" data-common="map,filter">
481
481
  <div>
482
482
  <label for="embeddingTargetId">Embedding target ID of the map view *</label>
483
483
  <input name="embeddingTargetId" id="embeddingTargetId" required>