graphwise-reactodia 0.0.1-TR16 → 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 (48) hide show
  1. package/README.md +57 -0
  2. package/dist/cjs/error-code-BdRU0RQ9.js +36 -0
  3. package/dist/cjs/graphwise-reactodia.cjs.entry.js +270 -65
  4. package/dist/cjs/graphwise-reactodia.cjs.js +1 -1
  5. package/dist/cjs/{index-CII9aUQC.js → index-DtzCybH4.js} +16 -0
  6. package/dist/cjs/index.cjs.js +14 -4
  7. package/dist/cjs/loader.cjs.js +1 -1
  8. package/dist/collection/components/graphwise-reactodia/graphwise-reactodia.js +46 -4
  9. package/dist/collection/components/graphwise-reactodia/menu/graphwise-menu.js +4 -1
  10. package/dist/collection/components/graphwise-reactodia/models/error/error-cause.js +1 -0
  11. package/dist/collection/components/graphwise-reactodia/models/error/error-code.js +18 -0
  12. package/dist/collection/components/graphwise-reactodia/models/error/error-report.js +1 -0
  13. package/dist/collection/components/graphwise-reactodia/models/event/event-callback.js +1 -0
  14. package/dist/collection/components/graphwise-reactodia/models/event/event-detail.js +4 -0
  15. package/dist/collection/components/graphwise-reactodia/models/event/event-type.js +7 -0
  16. package/dist/collection/components/graphwise-reactodia/reactodia-app.js +53 -19
  17. package/dist/collection/components/graphwise-reactodia/services/diagram-storage/diagram-storage.service.js +20 -4
  18. package/dist/collection/components/graphwise-reactodia/services/error/error.service.js +78 -0
  19. package/dist/collection/components/graphwise-reactodia/services/event/event.service.js +23 -0
  20. package/dist/collection/index.js +3 -0
  21. package/dist/collection/pages/graphwise-reactodia/main.js +41 -0
  22. package/dist/esm/error-code-DHI2bePh.js +34 -0
  23. package/dist/esm/graphwise-reactodia.entry.js +268 -63
  24. package/dist/esm/graphwise-reactodia.js +2 -2
  25. package/dist/esm/{index-Cypw7ydc.js → index-DpCR6zMg.js} +16 -1
  26. package/dist/esm/index.js +5 -4
  27. package/dist/esm/loader.js +2 -2
  28. package/dist/graphwise-reactodia/graphwise-reactodia.esm.js +1 -1
  29. package/dist/graphwise-reactodia/index.esm.js +1 -1
  30. package/dist/graphwise-reactodia/p-DHI2bePh.js +1 -0
  31. package/dist/graphwise-reactodia/p-DpCR6zMg.js +2 -0
  32. package/dist/graphwise-reactodia/p-abfb5091.entry.js +1 -0
  33. package/dist/types/components/graphwise-reactodia/graphwise-reactodia.d.ts +9 -0
  34. package/dist/types/components/graphwise-reactodia/models/error/error-cause.d.ts +10 -0
  35. package/dist/types/components/graphwise-reactodia/models/error/error-code.d.ts +17 -0
  36. package/dist/types/components/graphwise-reactodia/models/error/error-report.d.ts +13 -0
  37. package/dist/types/components/graphwise-reactodia/models/event/event-callback.d.ts +5 -0
  38. package/dist/types/components/graphwise-reactodia/models/event/event-detail.d.ts +48 -0
  39. package/dist/types/components/graphwise-reactodia/models/event/event-type.d.ts +6 -0
  40. package/dist/types/components/graphwise-reactodia/reactodia-app.d.ts +1 -1
  41. package/dist/types/components/graphwise-reactodia/services/diagram-storage/diagram-storage.service.d.ts +1 -0
  42. package/dist/types/components/graphwise-reactodia/services/error/error.service.d.ts +41 -0
  43. package/dist/types/components/graphwise-reactodia/services/event/event.service.d.ts +16 -0
  44. package/dist/types/components.d.ts +21 -0
  45. package/dist/types/index.d.ts +5 -0
  46. package/package.json +1 -1
  47. package/dist/graphwise-reactodia/p-20637a6f.entry.js +0 -1
  48. package/dist/graphwise-reactodia/p-Cypw7ydc.js +0 -2
@@ -1,6 +1,8 @@
1
+ import { EventEmitter } from '../../stencil-public-runtime';
1
2
  import { SparqlDataProviderSettings } from '@reactodia/workspace';
2
3
  import { LanguageKey } from './i18n/language-key';
3
4
  import { ReactodiaConfig } from './models/reactodia-config';
5
+ import { EventDetail } from './models/event/event-detail';
4
6
  /**
5
7
  * A web component that renders a graph with the Reactodia workspace.
6
8
  *
@@ -14,6 +16,7 @@ import { ReactodiaConfig } from './models/reactodia-config';
14
16
  */
15
17
  export declare class GraphwiseReactodia {
16
18
  private readonly hostElement?;
19
+ private readonly subscriptions;
17
20
  /**
18
21
  * The active repository id. Appended to {@link queryFunction} as the request `url`;
19
22
  * changing it re-points the graph at the new repository (and resets the canvas),
@@ -43,6 +46,10 @@ export declare class GraphwiseReactodia {
43
46
  * The reactodia theme to use
44
47
  */
45
48
  theme?: 'light' | 'dark';
49
+ /**
50
+ * Fires for every event to the host, differentiated by `detail.type`.
51
+ */
52
+ eventEmitter: EventEmitter<EventDetail>;
46
53
  private reactRoot?;
47
54
  /**
48
55
  * `connectedCallback` and the watchers can run before all props are set: when the component's
@@ -59,5 +66,7 @@ export declare class GraphwiseReactodia {
59
66
  componentDidLoad(): void;
60
67
  disconnectedCallback(): void;
61
68
  render(): any;
69
+ private subscribeToEvents;
62
70
  private renderGraph;
71
+ private reportMissingPropError;
63
72
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A link in the `cause` chain of a thrown value: the value itself, its `cause`, the cause of that, and so on.
3
+ * Anything can be thrown, so a link is not necessarily an `Error` and neither field is guaranteed.
4
+ */
5
+ export interface ErrorCause {
6
+ /** The error name, e.g. `AbortError`. */
7
+ name?: unknown;
8
+ /** The next link in the chain. */
9
+ cause?: unknown;
10
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The stable category of a reported error. The host uses it to choose its own message.
3
+ */
4
+ export declare enum ErrorCode {
5
+ /** A required prop is missing. */
6
+ MISSING_REQUIRED_PROP = "missing-required-prop",
7
+ /** A SPARQL data provider call failed. */
8
+ DATA_FETCH = "data-fetch",
9
+ /** The startup load, a reload or a repository switch failed. */
10
+ DIAGRAM_LOAD = "diagram-load",
11
+ /** The uploaded file was rejected or its import failed. */
12
+ DIAGRAM_IMPORT = "diagram-import",
13
+ /** Reading the diagram from local storage failed. */
14
+ LOCAL_DIAGRAM_READ = "local-diagram-read",
15
+ /** Saving the diagram in local storage failed. */
16
+ LOCAL_DIAGRAM_SAVE = "local-diagram-save"
17
+ }
@@ -0,0 +1,13 @@
1
+ import { ErrorCode } from './error-code';
2
+ /**
3
+ * A failure the wrapper announces to the host.
4
+ */
5
+ export interface ErrorReport {
6
+ code: ErrorCode;
7
+ /**
8
+ * The thrown value, passed on unchanged. The wrapper and the fork throw `Error`s with an untranslated `message`, but
9
+ * a failure of the host's `config.queryFunction` arrives as whatever it rejected with (e.g. an HTTP error response),
10
+ * so narrow it before use.
11
+ */
12
+ error: unknown;
13
+ }
@@ -0,0 +1,5 @@
1
+ import { EventDetail } from './event-detail';
2
+ /**
3
+ * Callback invoked with every emitted event.
4
+ */
5
+ export type EventCallback = (detail: EventDetail) => void;
@@ -0,0 +1,48 @@
1
+ import { EventType } from './event-type';
2
+ import { ErrorReport } from '../error/error-report';
3
+ /**
4
+ * Name of the DOM event the `graphwise-reactodia` element dispatches for every event.
5
+ */
6
+ export declare const GRAPHWISE_REACTODIA_EVENT = "graphwiseReactodiaEvent";
7
+ /**
8
+ * The payload of each {@link EventType}. It is the single place that ties an event type to its payload, so
9
+ * adding an event is one {@link EventType} value and one entry here.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * interface EventPayloadMap {
14
+ * [EventType.ERROR]: ErrorReport;
15
+ * // A new event:
16
+ * [EventType.NEW_TYPE]: NewTypePayload;
17
+ * }
18
+ * ```
19
+ */
20
+ interface EventPayloadMap {
21
+ [EventType.ERROR]: ErrorReport;
22
+ }
23
+ /**
24
+ * Maps an {@link EventType} to its event detail: `{type, payload}`, with the payload from
25
+ * {@link EventPayloadMap}. If no event type is provided, it is the union of the details of all event types.
26
+ *
27
+ * @template T The event type to map.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // Any event, narrowed by its type.
32
+ * function onEvent(detail: EventDetail): void {
33
+ * if (detail.type === EventType.ERROR) {
34
+ * const {code, error} = detail.payload; // an ErrorReport
35
+ * }
36
+ * }
37
+ *
38
+ * // One event.
39
+ * const detail: EventDetail<EventType.ERROR> = {type: EventType.ERROR, payload: {code, error}};
40
+ * ```
41
+ */
42
+ export type EventDetail<T extends EventType = EventType> = {
43
+ [K in T]: {
44
+ type: K;
45
+ payload: EventPayloadMap[K];
46
+ };
47
+ }[T];
48
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The kind of event the wrapper announces to the host. It selects the payload of an {@link EventDetail}.
3
+ */
4
+ export declare enum EventType {
5
+ ERROR = "error"
6
+ }
@@ -8,7 +8,7 @@ export declare function mountReactodia(container: HTMLElement, props: ReactodiaA
8
8
  /**
9
9
  * Re-points the diagram at a new SPARQL endpoint by recreating it with a fresh data provider.
10
10
  * The canvas is reset to empty, matching the initial mount, since the data of another repository
11
- * has nothing to do with the current graph.
11
+ * has nothing to do with the current graph. A failure is reported, not thrown.
12
12
  */
13
13
  export declare function updateReactodia(props: ReactodiaAppProps): Promise<void>;
14
14
  /**
@@ -5,6 +5,7 @@ import type { SerializedDiagram } from '@reactodia/workspace';
5
5
  export declare class DiagramStorageService {
6
6
  static readonly ID = "DiagramStorageService";
7
7
  private static readonly STORAGE_KEY;
8
+ private readonly errorService;
8
9
  /**
9
10
  * Load the persisted diagram from the local store, or `undefined` when nothing is stored (or the stored value
10
11
  * is unreadable).
@@ -0,0 +1,41 @@
1
+ import { ErrorCode } from '../../models/error/error-code';
2
+ /**
3
+ * Service that collects the failures of the wrapper and the fork, so they can be announced to the host.
4
+ */
5
+ export declare class ErrorService {
6
+ static readonly ID = "ErrorService";
7
+ private static readonly ABORT_ERROR_NAME;
8
+ private readonly eventService;
9
+ private readonly reported;
10
+ /**
11
+ * Reports a failure to the host, unless it's an abort, or this exact error object is already reported
12
+ * from another place.
13
+ *
14
+ * The same error object may be reported from different places. E.g. a query that fails while a diagram loads is
15
+ * reported by the data provider decorator as `data-fetch`, and then reaches the `catch` around the load, which
16
+ * reports it as `diagram-load`. Only the first one is announced.
17
+ *
18
+ * The `cause` is checked because the fork wraps whatever fails during a diagram import in a new error:
19
+ *
20
+ * ```ts
21
+ * // reactodia-workspace/src/editor/dataDiagramModel.ts, importLayout
22
+ * } catch (error) {
23
+ * throw new Error('Reactodia: failed to import a layout', {cause: error});
24
+ * }
25
+ * ```
26
+ *
27
+ * We need to check the cause to make sure we don't report the same error/abort more than once.
28
+ *
29
+ * @param code The category of the failure.
30
+ * @param thrown The thrown value.
31
+ */
32
+ report(code: ErrorCode, thrown: unknown): void;
33
+ /**
34
+ * Whether any link of the given cause chain is an abort or is already reported.
35
+ */
36
+ private isAbortedOrAlreadyReported;
37
+ /**
38
+ * The thrown value followed by its `cause`, the cause of that, and so on, for as long as they are objects.
39
+ */
40
+ private causeChain;
41
+ }
@@ -1,9 +1,25 @@
1
1
  import { Subscription } from '../../models/subscription';
2
+ import { EventCallback } from '../../models/event/event-callback';
3
+ import { EventDetail } from '../../models/event/event-detail';
2
4
  /**
3
5
  * Service for event based operations
4
6
  */
5
7
  export declare class EventService {
6
8
  static readonly ID = "EventService";
9
+ private callback?;
10
+ /**
11
+ * Announces an event to the host.
12
+ *
13
+ * @param detail The event detail.
14
+ */
15
+ emit(detail: EventDetail): void;
16
+ /**
17
+ * Subscribes to the emitted events, replacing the previous subscriber.
18
+ *
19
+ * @param callback Called with every emitted event.
20
+ * @returns A {@link Subscription} that, when called, removes the callback, unless it has already been replaced.
21
+ */
22
+ subscribe(callback: EventCallback): Subscription;
7
23
  /**
8
24
  * Subscribes to the host's "clear persisted diagram" command.
9
25
  *
@@ -8,9 +8,11 @@ import { HTMLStencilElement, JSXBase } from "./stencil-public-runtime";
8
8
  import { ReactodiaConfig } from "./components/graphwise-reactodia/models/reactodia-config";
9
9
  import { LanguageKey } from "./components/graphwise-reactodia/i18n/language-key";
10
10
  import { SparqlDataProviderSettings } from "@reactodia/workspace";
11
+ import { EventDetail } from "./components/graphwise-reactodia/models/event/event-detail";
11
12
  export { ReactodiaConfig } from "./components/graphwise-reactodia/models/reactodia-config";
12
13
  export { LanguageKey } from "./components/graphwise-reactodia/i18n/language-key";
13
14
  export { SparqlDataProviderSettings } from "@reactodia/workspace";
15
+ export { EventDetail } from "./components/graphwise-reactodia/models/event/event-detail";
14
16
  export namespace Components {
15
17
  /**
16
18
  * A web component that renders a graph with the Reactodia workspace.
@@ -45,7 +47,14 @@ export namespace Components {
45
47
  "theme"?: 'light' | 'dark';
46
48
  }
47
49
  }
50
+ export interface GraphwiseReactodiaCustomEvent<T> extends CustomEvent<T> {
51
+ detail: T;
52
+ target: HTMLGraphwiseReactodiaElement;
53
+ }
48
54
  declare global {
55
+ interface HTMLGraphwiseReactodiaElementEventMap {
56
+ "graphwiseReactodiaEvent": EventDetail;
57
+ }
49
58
  /**
50
59
  * A web component that renders a graph with the Reactodia workspace.
51
60
  * The component is backed by a SPARQL endpoint but is endpoint-agnostic: the host passes
@@ -56,6 +65,14 @@ declare global {
56
65
  * wrapper and is supplied through the `providerSettings` prop.
57
66
  */
58
67
  interface HTMLGraphwiseReactodiaElement extends Components.GraphwiseReactodia, HTMLStencilElement {
68
+ addEventListener<K extends keyof HTMLGraphwiseReactodiaElementEventMap>(type: K, listener: (this: HTMLGraphwiseReactodiaElement, ev: GraphwiseReactodiaCustomEvent<HTMLGraphwiseReactodiaElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
69
+ addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
70
+ addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
71
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
72
+ removeEventListener<K extends keyof HTMLGraphwiseReactodiaElementEventMap>(type: K, listener: (this: HTMLGraphwiseReactodiaElement, ev: GraphwiseReactodiaCustomEvent<HTMLGraphwiseReactodiaElementEventMap[K]>) => any, options?: boolean | EventListenerOptions): void;
73
+ removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
74
+ removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
75
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
59
76
  }
60
77
  var HTMLGraphwiseReactodiaElement: {
61
78
  prototype: HTMLGraphwiseReactodiaElement;
@@ -89,6 +106,10 @@ declare namespace LocalJSX {
89
106
  * @default LanguageKey.EN
90
107
  */
91
108
  "language"?: LanguageKey;
109
+ /**
110
+ * Fires for every event to the host, differentiated by `detail.type`.
111
+ */
112
+ "onGraphwiseReactodiaEvent"?: (event: GraphwiseReactodiaCustomEvent<EventDetail>) => void;
92
113
  /**
93
114
  * Query preset for the SPARQL data provider, owned and configured by the host. A DOM property (an object, not an attribute) passed in from outside the wrapper. Required: the wrapper has no default preset and throws when it is missing. Changing it rebuilds the data provider and reloads the graph with it, keeping the current diagram.
94
115
  */
@@ -1 +1,6 @@
1
1
  export { CLEAR_DIAGRAM_STORAGE_EVENT } from './components/graphwise-reactodia/models/clear-diagram-storage-event';
2
+ export { GRAPHWISE_REACTODIA_EVENT } from './components/graphwise-reactodia/models/event/event-detail';
3
+ export { EventType } from './components/graphwise-reactodia/models/event/event-type';
4
+ export type { EventDetail } from './components/graphwise-reactodia/models/event/event-detail';
5
+ export { ErrorCode } from './components/graphwise-reactodia/models/error/error-code';
6
+ export type { ErrorReport } from './components/graphwise-reactodia/models/error/error-report';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphwise-reactodia",
3
- "version": "0.0.1-TR16",
3
+ "version": "0.0.1-TR18",
4
4
  "description": "Graphwise wrapper around the Reactodia graph explorer.",
5
5
  "license": "LGPL-3.0-or-later",
6
6
  "author": "Ontotext AD",