graphwise-reactodia 0.0.1-TR17 → 0.0.1-TR18

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 (33) hide show
  1. package/README.md +30 -8
  2. package/dist/cjs/{error-code-NpXlqCEN.js → error-code-BdRU0RQ9.js} +8 -0
  3. package/dist/cjs/graphwise-reactodia.cjs.entry.js +64 -54
  4. package/dist/cjs/index.cjs.js +8 -4
  5. package/dist/collection/components/graphwise-reactodia/graphwise-reactodia.js +14 -12
  6. package/dist/collection/components/graphwise-reactodia/models/error/error-report.js +1 -4
  7. package/dist/collection/components/graphwise-reactodia/models/event/event-detail.js +4 -0
  8. package/dist/collection/components/graphwise-reactodia/models/event/event-type.js +7 -0
  9. package/dist/collection/components/graphwise-reactodia/services/error/error.service.js +5 -16
  10. package/dist/collection/components/graphwise-reactodia/services/event/event.service.js +23 -0
  11. package/dist/collection/index.js +2 -1
  12. package/dist/collection/pages/graphwise-reactodia/main.js +6 -2
  13. package/dist/esm/{error-code-7lGYbTwb.js → error-code-DHI2bePh.js} +9 -1
  14. package/dist/esm/graphwise-reactodia.entry.js +64 -54
  15. package/dist/esm/index.js +4 -4
  16. package/dist/graphwise-reactodia/graphwise-reactodia.esm.js +1 -1
  17. package/dist/graphwise-reactodia/index.esm.js +1 -1
  18. package/dist/graphwise-reactodia/p-DHI2bePh.js +1 -0
  19. package/dist/graphwise-reactodia/p-abfb5091.entry.js +1 -0
  20. package/dist/types/components/graphwise-reactodia/graphwise-reactodia.d.ts +4 -4
  21. package/dist/types/components/graphwise-reactodia/models/error/error-report.d.ts +0 -4
  22. package/dist/types/components/graphwise-reactodia/models/event/event-callback.d.ts +5 -0
  23. package/dist/types/components/graphwise-reactodia/models/event/event-detail.d.ts +48 -0
  24. package/dist/types/components/graphwise-reactodia/models/event/event-type.d.ts +6 -0
  25. package/dist/types/components/graphwise-reactodia/services/error/error.service.d.ts +1 -10
  26. package/dist/types/components/graphwise-reactodia/services/event/event.service.d.ts +16 -0
  27. package/dist/types/components.d.ts +5 -5
  28. package/dist/types/index.d.ts +3 -1
  29. package/package.json +1 -1
  30. package/dist/graphwise-reactodia/p-7lGYbTwb.js +0 -1
  31. package/dist/graphwise-reactodia/p-ec30185a.entry.js +0 -1
  32. package/dist/types/components/graphwise-reactodia/models/error/error-callback.d.ts +0 -5
  33. /package/dist/collection/components/graphwise-reactodia/models/{error/error-callback.js → event/event-callback.js} +0 -0
package/README.md CHANGED
@@ -66,19 +66,41 @@ persisted in the DB, so they can't be fetched lazily and must be supplied by the
66
66
 
67
67
  When both are supplied `seedGraph` takes precedence over `seedIris`.
68
68
 
69
- ## Error handling
69
+ ## Events
70
+
71
+ The element sends every event to the host through one DOM event, `graphwiseReactodiaEvent`. The event
72
+ only informs the host and it bubbles. Its name is exported as `GRAPHWISE_REACTODIA_EVENT`.
73
+
74
+ `detail` is an `EventDetail`: `{type, payload}`. `type` is an `EventType`; `payload` depends on it:
70
75
 
71
- The element dispatches a `graphwiseReactodiaError` DOM event for every error it reports; the codes below
72
- list them. The event only informs the host and it bubbles. Its name is exported as
73
- `GRAPHWISE_REACTODIA_ERROR_EVENT`.
76
+ | `type` | `payload` |
77
+ |---------|-----------------|
78
+ | `error` | `ErrorReport` |
74
79
 
75
- ```js
76
- element.addEventListener('graphwiseReactodiaError', (event) => {
77
- const {code, error} = event.detail;
80
+ Checking `type` narrows `payload`:
81
+
82
+ ```ts
83
+ element.addEventListener(GRAPHWISE_REACTODIA_EVENT, (event) => {
84
+ const detail = (event as CustomEvent<EventDetail>).detail;
85
+ if (detail.type === EventType.ERROR) {
86
+ const {code, error} = detail.payload; // an ErrorReport
87
+ }
78
88
  });
79
89
  ```
80
90
 
81
- `detail` is an `ErrorReport`:
91
+ `EventDetail<T>` is one event, e.g. for a handler of a single type:
92
+
93
+ ```ts
94
+ function onError(detail: EventDetail<EventType.ERROR>): void {
95
+ const {code, error} = detail.payload;
96
+ }
97
+ ```
98
+
99
+ ## Error handling
100
+
101
+ The element dispatches an `error` event for every error it reports; the codes below list them.
102
+
103
+ `payload` is an `ErrorReport`:
82
104
 
83
105
  | Field | Description |
84
106
  |---------|-----------------------------------------------------------------------------------------|
@@ -6,6 +6,14 @@
6
6
  */
7
7
  const CLEAR_DIAGRAM_STORAGE_EVENT = 'graphwise-reactodia:clear-diagram-storage';
8
8
 
9
+ /**
10
+ * The kind of event the wrapper announces to the host. It selects the payload of an {@link EventDetail}.
11
+ */
12
+ exports.EventType = void 0;
13
+ (function (EventType) {
14
+ EventType["ERROR"] = "error";
15
+ })(exports.EventType || (exports.EventType = {}));
16
+
9
17
  /**
10
18
  * The stable category of a reported error. The host uses it to choose its own message.
11
19
  */
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-DtzCybH4.js');
4
- var errorCode = require('./error-code-NpXlqCEN.js');
4
+ var errorCode = require('./error-code-BdRU0RQ9.js');
5
5
 
6
6
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
7
7
 
@@ -31475,12 +31475,63 @@ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators,
31475
31475
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
31476
31476
  return c > 3 && r && Object.defineProperty(target, key, r), r;
31477
31477
  };
31478
+ /**
31479
+ * Service for event based operations
31480
+ */
31481
+ let EventService = class EventService {
31482
+ /**
31483
+ * Announces an event to the host.
31484
+ *
31485
+ * @param detail The event detail.
31486
+ */
31487
+ emit(detail) {
31488
+ var _a;
31489
+ (_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, detail);
31490
+ }
31491
+ /**
31492
+ * Subscribes to the emitted events, replacing the previous subscriber.
31493
+ *
31494
+ * @param callback Called with every emitted event.
31495
+ * @returns A {@link Subscription} that, when called, removes the callback, unless it has already been replaced.
31496
+ */
31497
+ subscribe(callback) {
31498
+ this.callback = callback;
31499
+ return () => {
31500
+ if (this.callback === callback) {
31501
+ this.callback = undefined;
31502
+ }
31503
+ };
31504
+ }
31505
+ /**
31506
+ * Subscribes to the host's "clear persisted diagram" command.
31507
+ *
31508
+ * @param onClear Called whenever the event fires.
31509
+ * @returns A {@link Subscription} that, when called, removes the listener.
31510
+ */
31511
+ subscribeToClearDiagramStorage(onClear) {
31512
+ const target = service(WindowService).getWindow();
31513
+ target.addEventListener(errorCode.CLEAR_DIAGRAM_STORAGE_EVENT, onClear);
31514
+ return () => target.removeEventListener(errorCode.CLEAR_DIAGRAM_STORAGE_EVENT, onClear);
31515
+ }
31516
+ };
31517
+ EventService.ID = 'EventService';
31518
+ EventService = __decorate$3([
31519
+ Service
31520
+ ], EventService);
31521
+
31522
+ var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
31523
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31524
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31525
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
31526
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
31527
+ };
31478
31528
  var ErrorService_1;
31479
31529
  /**
31480
31530
  * Service that collects the failures of the wrapper and the fork, so they can be announced to the host.
31481
31531
  */
31482
31532
  let ErrorService = ErrorService_1 = class ErrorService {
31483
31533
  constructor() {
31534
+ this.eventService = service(EventService);
31484
31535
  this.reported = new WeakSet();
31485
31536
  }
31486
31537
  /**
@@ -31506,27 +31557,12 @@ let ErrorService = ErrorService_1 = class ErrorService {
31506
31557
  * @param thrown The thrown value.
31507
31558
  */
31508
31559
  report(code, thrown) {
31509
- var _a;
31510
31560
  const causes = this.causeChain(thrown);
31511
31561
  if (this.isAbortedOrAlreadyReported(causes)) {
31512
31562
  return;
31513
31563
  }
31514
31564
  causes.forEach((cause) => this.reported.add(cause));
31515
- (_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, { code, error: thrown });
31516
- }
31517
- /**
31518
- * Subscribes to the reported errors, replacing the previous subscriber.
31519
- *
31520
- * @param callback Called with every reported error.
31521
- * @returns A {@link Subscription} that, when called, removes the callback, unless it has already been replaced.
31522
- */
31523
- subscribe(callback) {
31524
- this.callback = callback;
31525
- return () => {
31526
- if (this.callback === callback) {
31527
- this.callback = undefined;
31528
- }
31529
- };
31565
+ this.eventService.emit({ type: errorCode.EventType.ERROR, payload: { code, error: thrown } });
31530
31566
  }
31531
31567
  /**
31532
31568
  * Whether any link of the given cause chain is an abort or is already reported.
@@ -31549,11 +31585,11 @@ let ErrorService = ErrorService_1 = class ErrorService {
31549
31585
  };
31550
31586
  ErrorService.ID = 'ErrorService';
31551
31587
  ErrorService.ABORT_ERROR_NAME = 'AbortError';
31552
- ErrorService = ErrorService_1 = __decorate$3([
31588
+ ErrorService = ErrorService_1 = __decorate$2([
31553
31589
  Service
31554
31590
  ], ErrorService);
31555
31591
 
31556
- var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
31592
+ var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
31557
31593
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31558
31594
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31559
31595
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -31611,37 +31647,10 @@ let DiagramStorageService = DiagramStorageService_1 = class DiagramStorageServic
31611
31647
  };
31612
31648
  DiagramStorageService.ID = 'DiagramStorageService';
31613
31649
  DiagramStorageService.STORAGE_KEY = 'diagram.state';
31614
- DiagramStorageService = DiagramStorageService_1 = __decorate$2([
31650
+ DiagramStorageService = DiagramStorageService_1 = __decorate$1([
31615
31651
  Service
31616
31652
  ], DiagramStorageService);
31617
31653
 
31618
- var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
31619
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31620
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31621
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
31622
- return c > 3 && r && Object.defineProperty(target, key, r), r;
31623
- };
31624
- /**
31625
- * Service for event based operations
31626
- */
31627
- let EventService = class EventService {
31628
- /**
31629
- * Subscribes to the host's "clear persisted diagram" command.
31630
- *
31631
- * @param onClear Called whenever the event fires.
31632
- * @returns A {@link Subscription} that, when called, removes the listener.
31633
- */
31634
- subscribeToClearDiagramStorage(onClear) {
31635
- const target = service(WindowService).getWindow();
31636
- target.addEventListener(errorCode.CLEAR_DIAGRAM_STORAGE_EVENT, onClear);
31637
- return () => target.removeEventListener(errorCode.CLEAR_DIAGRAM_STORAGE_EVENT, onClear);
31638
- }
31639
- };
31640
- EventService.ID = 'EventService';
31641
- EventService = __decorate$1([
31642
- Service
31643
- ], EventService);
31644
-
31645
31654
  /**
31646
31655
  * A collection of {@link Subscription}s that can be released together. Components collect the
31647
31656
  * subscriptions they open and call {@link unsubscribeAll} on teardown so nothing is left
@@ -31852,7 +31861,7 @@ const subscriptions = new SubscriptionList();
31852
31861
  let diagramStorageSubscription;
31853
31862
  const diagramService = service(DiagramService);
31854
31863
  const diagramStorageService = service(DiagramStorageService);
31855
- const eventService = service(EventService);
31864
+ const eventService$1 = service(EventService);
31856
31865
  const errorService$1 = service(ErrorService);
31857
31866
  /**
31858
31867
  * Reports every failed data provider call, unless the call was aborted, and passes the failure on to the caller.
@@ -31949,7 +31958,7 @@ function subscribeToDiagramChange(model) {
31949
31958
  * @param model The diagram model whose edits are persisted
31950
31959
  */
31951
31960
  function onClearDiagramStorage(model) {
31952
- subscriptions.add(eventService.subscribeToClearDiagramStorage(() => {
31961
+ subscriptions.add(eventService$1.subscribeToClearDiagramStorage(() => {
31953
31962
  // re-subscribe, to avoid any pending debounced saves, which may write over the cleared diagram
31954
31963
  subscribeToDiagramChange(model);
31955
31964
  diagramStorageService.clear();
@@ -32070,10 +32079,11 @@ function unmountReactodia(root) {
32070
32079
  const graphwiseReactodiaCss = "graphwise-reactodia{--_graphwise-reactodia-type-color-01:var(--graphwise-reactodia-type-color-01);--_graphwise-reactodia-type-color-02:var(--graphwise-reactodia-type-color-02);--_graphwise-reactodia-type-color-03:var(--graphwise-reactodia-type-color-03);--_graphwise-reactodia-type-color-04:var(--graphwise-reactodia-type-color-04);--_graphwise-reactodia-type-color-05:var(--graphwise-reactodia-type-color-05);--_graphwise-reactodia-type-color-06:var(--graphwise-reactodia-type-color-06);--_graphwise-reactodia-type-color-07:var(--graphwise-reactodia-type-color-07);--_graphwise-reactodia-type-color-08:var(--graphwise-reactodia-type-color-08);--_graphwise-reactodia-type-color-09:var(--graphwise-reactodia-type-color-09);--_graphwise-reactodia-type-color-10:var(--graphwise-reactodia-type-color-10);--_graphwise-reactodia-type-color-11:var(--graphwise-reactodia-type-color-11);--_graphwise-reactodia-type-color-12:var(--graphwise-reactodia-type-color-12);--_graphwise-reactodia-type-color-13:var(--graphwise-reactodia-type-color-13);--_graphwise-reactodia-type-color-14:var(--graphwise-reactodia-type-color-14);--_graphwise-reactodia-type-color-15:var(--graphwise-reactodia-type-color-15);--_graphwise-reactodia-type-color-16:var(--graphwise-reactodia-type-color-16);--_graphwise-reactodia-type-color-17:var(--graphwise-reactodia-type-color-17);--_graphwise-reactodia-type-color-18:var(--graphwise-reactodia-type-color-18);--_graphwise-reactodia-type-color-19:var(--graphwise-reactodia-type-color-19);--_graphwise-reactodia-type-color-20:var(--graphwise-reactodia-type-color-20);--_graphwise-reactodia-type-color-contrast:var(--graphwise-reactodia-type-color-contrast, #fff)}graphwise-reactodia{display:block;width:100%;height:100%}graphwise-reactodia .reactodia-container{position:relative;width:100%;height:100%}graphwise-reactodia .reactodia-selection-action__link{display:none}graphwise-reactodia .reactodia-standard-element__thumbnail:not(:has(img)){background:var(--reactodia-element-style-color);border-radius:50%;color:var(--_graphwise-reactodia-type-color-contrast)}";
32071
32080
 
32072
32081
  const errorService = service(ErrorService);
32082
+ const eventService = service(EventService);
32073
32083
  const GraphwiseReactodia = class {
32074
32084
  constructor(hostRef) {
32075
32085
  index.registerInstance(this, hostRef);
32076
- this.errorEmitter = index.createEvent(this, "graphwiseReactodiaError");
32086
+ this.eventEmitter = index.createEvent(this, "graphwiseReactodiaEvent");
32077
32087
  this.subscriptions = new SubscriptionList();
32078
32088
  /**
32079
32089
  * UI language code (e.g. `en`, `fr`) for the Reactodia interface. Defaults to English.
@@ -32102,7 +32112,7 @@ const GraphwiseReactodia = class {
32102
32112
  this.renderGraph(true);
32103
32113
  }
32104
32114
  connectedCallback() {
32105
- this.subscribeToErrors();
32115
+ this.subscribeToEvents();
32106
32116
  this.renderGraph();
32107
32117
  }
32108
32118
  componentDidLoad() {
@@ -32117,10 +32127,10 @@ const GraphwiseReactodia = class {
32117
32127
  }
32118
32128
  }
32119
32129
  render() {
32120
- return (index.h(index.Host, { key: 'a96eea05561061bbed34b5134abc44f07402211f' }));
32130
+ return (index.h(index.Host, { key: '2e8541c791f478484c4bad64ad758df99aba2059' }));
32121
32131
  }
32122
- subscribeToErrors() {
32123
- this.subscriptions.add(errorService.subscribe((error) => this.errorEmitter.emit(error)));
32132
+ subscribeToEvents() {
32133
+ this.subscriptions.add(eventService.subscribe((detail) => this.eventEmitter.emit(detail)));
32124
32134
  }
32125
32135
  renderGraph(isReloading) {
32126
32136
  var _a;
@@ -1,15 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var errorCode = require('./error-code-NpXlqCEN.js');
3
+ var errorCode = require('./error-code-BdRU0RQ9.js');
4
4
 
5
5
  /**
6
- * Name of the DOM event the `graphwise-reactodia` element dispatches for every reported error.
6
+ * Name of the DOM event the `graphwise-reactodia` element dispatches for every event.
7
7
  */
8
- const GRAPHWISE_REACTODIA_ERROR_EVENT = 'graphwiseReactodiaError';
8
+ const GRAPHWISE_REACTODIA_EVENT = 'graphwiseReactodiaEvent';
9
9
 
10
10
  exports.CLEAR_DIAGRAM_STORAGE_EVENT = errorCode.CLEAR_DIAGRAM_STORAGE_EVENT;
11
11
  Object.defineProperty(exports, "ErrorCode", {
12
12
  enumerable: true,
13
13
  get: function () { return errorCode.ErrorCode; }
14
14
  });
15
- exports.GRAPHWISE_REACTODIA_ERROR_EVENT = GRAPHWISE_REACTODIA_ERROR_EVENT;
15
+ Object.defineProperty(exports, "EventType", {
16
+ enumerable: true,
17
+ get: function () { return errorCode.EventType; }
18
+ });
19
+ exports.GRAPHWISE_REACTODIA_EVENT = GRAPHWISE_REACTODIA_EVENT;
@@ -5,8 +5,10 @@ import { ErrorCode } from "./models/error/error-code";
5
5
  import { SubscriptionList } from "./models/subscription-list";
6
6
  import { service } from "./providers/service/service-inject";
7
7
  import { ErrorService } from "./services/error/error.service";
8
+ import { EventService } from "./services/event/event.service";
8
9
  import { resetColors } from "./styles/type-style.resolver";
9
10
  const errorService = service(ErrorService);
11
+ const eventService = service(EventService);
10
12
  /**
11
13
  * A web component that renders a graph with the Reactodia workspace.
12
14
  *
@@ -48,7 +50,7 @@ export class GraphwiseReactodia {
48
50
  this.renderGraph(true);
49
51
  }
50
52
  connectedCallback() {
51
- this.subscribeToErrors();
53
+ this.subscribeToEvents();
52
54
  this.renderGraph();
53
55
  }
54
56
  componentDidLoad() {
@@ -63,10 +65,10 @@ export class GraphwiseReactodia {
63
65
  }
64
66
  }
65
67
  render() {
66
- return (h(Host, { key: 'a96eea05561061bbed34b5134abc44f07402211f' }));
68
+ return (h(Host, { key: '2e8541c791f478484c4bad64ad758df99aba2059' }));
67
69
  }
68
- subscribeToErrors() {
69
- this.subscriptions.add(errorService.subscribe((error) => this.errorEmitter.emit(error)));
70
+ subscribeToEvents() {
71
+ this.subscriptions.add(eventService.subscribe((detail) => this.eventEmitter.emit(detail)));
70
72
  }
71
73
  renderGraph(isReloading) {
72
74
  var _a;
@@ -234,23 +236,23 @@ export class GraphwiseReactodia {
234
236
  }
235
237
  static get events() {
236
238
  return [{
237
- "method": "errorEmitter",
238
- "name": "graphwiseReactodiaError",
239
+ "method": "eventEmitter",
240
+ "name": "graphwiseReactodiaEvent",
239
241
  "bubbles": true,
240
242
  "cancelable": true,
241
243
  "composed": true,
242
244
  "docs": {
243
245
  "tags": [],
244
- "text": "Fires, when an error has occurred. The host decides how to handle it."
246
+ "text": "Fires for every event to the host, differentiated by `detail.type`."
245
247
  },
246
248
  "complexType": {
247
- "original": "ErrorReport",
248
- "resolved": "ErrorReport",
249
+ "original": "EventDetail",
250
+ "resolved": "{ type: EventType; payload: ErrorReport; }",
249
251
  "references": {
250
- "ErrorReport": {
252
+ "EventDetail": {
251
253
  "location": "import",
252
- "path": "./models/error/error-report",
253
- "id": "src/components/graphwise-reactodia/models/error/error-report.ts::ErrorReport"
254
+ "path": "./models/event/event-detail",
255
+ "id": "src/components/graphwise-reactodia/models/event/event-detail.ts::EventDetail"
254
256
  }
255
257
  }
256
258
  }
@@ -1,4 +1 @@
1
- /**
2
- * Name of the DOM event the `graphwise-reactodia` element dispatches for every reported error.
3
- */
4
- export const GRAPHWISE_REACTODIA_ERROR_EVENT = 'graphwiseReactodiaError';
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Name of the DOM event the `graphwise-reactodia` element dispatches for every event.
3
+ */
4
+ export const GRAPHWISE_REACTODIA_EVENT = 'graphwiseReactodiaEvent';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The kind of event the wrapper announces to the host. It selects the payload of an {@link EventDetail}.
3
+ */
4
+ export var EventType;
5
+ (function (EventType) {
6
+ EventType["ERROR"] = "error";
7
+ })(EventType || (EventType = {}));
@@ -10,11 +10,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
10
10
  };
11
11
  var ErrorService_1;
12
12
  import { Service } from "../../providers/service/service";
13
+ import { service } from "../../providers/service/service-inject";
14
+ import { EventType } from "../../models/event/event-type";
15
+ import { EventService } from "../event/event.service";
13
16
  /**
14
17
  * Service that collects the failures of the wrapper and the fork, so they can be announced to the host.
15
18
  */
16
19
  let ErrorService = ErrorService_1 = class ErrorService {
17
20
  constructor() {
21
+ this.eventService = service(EventService);
18
22
  this.reported = new WeakSet();
19
23
  }
20
24
  /**
@@ -40,27 +44,12 @@ let ErrorService = ErrorService_1 = class ErrorService {
40
44
  * @param thrown The thrown value.
41
45
  */
42
46
  report(code, thrown) {
43
- var _a;
44
47
  const causes = this.causeChain(thrown);
45
48
  if (this.isAbortedOrAlreadyReported(causes)) {
46
49
  return;
47
50
  }
48
51
  causes.forEach((cause) => this.reported.add(cause));
49
- (_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, { code, error: thrown });
50
- }
51
- /**
52
- * Subscribes to the reported errors, replacing the previous subscriber.
53
- *
54
- * @param callback Called with every reported error.
55
- * @returns A {@link Subscription} that, when called, removes the callback, unless it has already been replaced.
56
- */
57
- subscribe(callback) {
58
- this.callback = callback;
59
- return () => {
60
- if (this.callback === callback) {
61
- this.callback = undefined;
62
- }
63
- };
52
+ this.eventService.emit({ type: EventType.ERROR, payload: { code, error: thrown } });
64
53
  }
65
54
  /**
66
55
  * Whether any link of the given cause chain is an abort or is already reported.
@@ -16,6 +16,29 @@ import { WindowService } from "../window/window.service";
16
16
  * Service for event based operations
17
17
  */
18
18
  let EventService = class EventService {
19
+ /**
20
+ * Announces an event to the host.
21
+ *
22
+ * @param detail The event detail.
23
+ */
24
+ emit(detail) {
25
+ var _a;
26
+ (_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, detail);
27
+ }
28
+ /**
29
+ * Subscribes to the emitted events, replacing the previous subscriber.
30
+ *
31
+ * @param callback Called with every emitted event.
32
+ * @returns A {@link Subscription} that, when called, removes the callback, unless it has already been replaced.
33
+ */
34
+ subscribe(callback) {
35
+ this.callback = callback;
36
+ return () => {
37
+ if (this.callback === callback) {
38
+ this.callback = undefined;
39
+ }
40
+ };
41
+ }
19
42
  /**
20
43
  * Subscribes to the host's "clear persisted diagram" command.
21
44
  *
@@ -1,3 +1,4 @@
1
1
  export { CLEAR_DIAGRAM_STORAGE_EVENT } from './components/graphwise-reactodia/models/clear-diagram-storage-event';
2
- export { GRAPHWISE_REACTODIA_ERROR_EVENT } from './components/graphwise-reactodia/models/error/error-report';
2
+ export { GRAPHWISE_REACTODIA_EVENT } from './components/graphwise-reactodia/models/event/event-detail';
3
+ export { EventType } from './components/graphwise-reactodia/models/event/event-type';
3
4
  export { ErrorCode } from './components/graphwise-reactodia/models/error/error-code';
@@ -42,8 +42,12 @@ function hangingQueryFunction(params) {
42
42
  const reportedErrors = [];
43
43
  window.reportedErrors = reportedErrors;
44
44
  // The listener is on the document, since the tests replace the element.
45
- document.addEventListener('graphwiseReactodiaError', (event) => {
46
- reportedErrors.push({code: event.detail.code, message: event.detail.error.message});
45
+ document.addEventListener('graphwiseReactodiaEvent', (event) => {
46
+ if (event.detail.type !== 'error') {
47
+ return;
48
+ }
49
+ const {code, error} = event.detail.payload;
50
+ reportedErrors.push({code, message: error.message});
47
51
  });
48
52
 
49
53
  const SEED_NODES = ['http://example.com/alice', 'http://example.com/bob'];
@@ -4,6 +4,14 @@
4
4
  */
5
5
  const CLEAR_DIAGRAM_STORAGE_EVENT = 'graphwise-reactodia:clear-diagram-storage';
6
6
 
7
+ /**
8
+ * The kind of event the wrapper announces to the host. It selects the payload of an {@link EventDetail}.
9
+ */
10
+ var EventType;
11
+ (function (EventType) {
12
+ EventType["ERROR"] = "error";
13
+ })(EventType || (EventType = {}));
14
+
7
15
  /**
8
16
  * The stable category of a reported error. The host uses it to choose its own message.
9
17
  */
@@ -23,4 +31,4 @@ var ErrorCode;
23
31
  ErrorCode["LOCAL_DIAGRAM_SAVE"] = "local-diagram-save";
24
32
  })(ErrorCode || (ErrorCode = {}));
25
33
 
26
- export { CLEAR_DIAGRAM_STORAGE_EVENT as C, ErrorCode as E };
34
+ export { CLEAR_DIAGRAM_STORAGE_EVENT as C, EventType as E, ErrorCode as a };