graphwise-reactodia 0.0.1-TR7 → 0.0.1-TR9

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 (42) hide show
  1. package/README.md +32 -0
  2. package/dist/cjs/graphwise-reactodia.cjs.entry.js +309 -41
  3. package/dist/cjs/index.cjs.js +7 -0
  4. package/dist/collection/components/graphwise-reactodia/graphwise-reactodia.js +10 -10
  5. package/dist/collection/components/graphwise-reactodia/models/clear-diagram-storage-event.js +5 -0
  6. package/dist/collection/components/graphwise-reactodia/models/subscription-list.js +35 -0
  7. package/dist/collection/components/graphwise-reactodia/models/triple.js +1 -0
  8. package/dist/collection/components/graphwise-reactodia/providers/service/service-inject.js +15 -0
  9. package/dist/collection/components/graphwise-reactodia/providers/service/service.js +19 -0
  10. package/dist/collection/components/graphwise-reactodia/providers/service/service.provider.js +20 -0
  11. package/dist/collection/components/graphwise-reactodia/reactodia-app.js +61 -28
  12. package/dist/collection/components/graphwise-reactodia/services/diagram/diagram.service.js +54 -0
  13. package/dist/collection/components/graphwise-reactodia/services/diagram-storage/diagram-storage.service.js +55 -0
  14. package/dist/collection/components/graphwise-reactodia/services/event/event.service.js +35 -0
  15. package/dist/collection/components/graphwise-reactodia/services/window/window.service.js +24 -0
  16. package/dist/collection/components/graphwise-reactodia/testing/storage.mock.js +35 -0
  17. package/dist/collection/index.js +1 -1
  18. package/dist/collection/pages/graphwise-reactodia/main.js +17 -7
  19. package/dist/esm/graphwise-reactodia.entry.js +306 -38
  20. package/dist/esm/index.js +6 -0
  21. package/dist/graphwise-reactodia/graphwise-reactodia.esm.js +1 -1
  22. package/dist/graphwise-reactodia/index.esm.js +1 -0
  23. package/dist/graphwise-reactodia/p-5b907998.entry.js +1 -0
  24. package/dist/types/components/graphwise-reactodia/i18n/translations.d.ts +2 -6
  25. package/dist/types/components/graphwise-reactodia/models/clear-diagram-storage-event.d.ts +5 -0
  26. package/dist/types/components/graphwise-reactodia/models/reactodia-app-props.d.ts +6 -7
  27. package/dist/types/components/graphwise-reactodia/models/reactodia-config.d.ts +8 -6
  28. package/dist/types/components/graphwise-reactodia/models/subscription-list.d.ts +26 -0
  29. package/dist/types/components/graphwise-reactodia/models/subscription.d.ts +4 -0
  30. package/dist/types/components/graphwise-reactodia/models/{reactodia-seed-link.d.ts → triple.d.ts} +2 -6
  31. package/dist/types/components/graphwise-reactodia/providers/service/service-inject.d.ts +13 -0
  32. package/dist/types/components/graphwise-reactodia/providers/service/service.d.ts +28 -0
  33. package/dist/types/components/graphwise-reactodia/providers/service/service.provider.d.ts +16 -0
  34. package/dist/types/components/graphwise-reactodia/services/diagram/diagram.service.d.ts +26 -0
  35. package/dist/types/components/graphwise-reactodia/services/diagram-storage/diagram-storage.service.d.ts +26 -0
  36. package/dist/types/components/graphwise-reactodia/services/event/event.service.d.ts +14 -0
  37. package/dist/types/components/graphwise-reactodia/services/window/window.service.d.ts +7 -0
  38. package/dist/types/components/graphwise-reactodia/testing/storage.mock.d.ts +18 -0
  39. package/dist/types/index.d.ts +1 -1
  40. package/package.json +9 -3
  41. package/dist/graphwise-reactodia/p-eb362faa.entry.js +0 -1
  42. /package/dist/collection/components/graphwise-reactodia/models/{reactodia-seed-link.js → subscription.js} +0 -0
@@ -1,6 +1,2 @@
1
- import { LanguageKey } from './language-key';
2
- type TranslationBundle = {
3
- [language: string]: Record<string, TranslationBundle | string | null>;
4
- };
5
- export declare const TRANSLATIONS: Partial<Record<LanguageKey, TranslationBundle>>;
6
- export {};
1
+ export type TranslationBundle = Record<string, Record<string, string | null> | string>;
2
+ export declare const TRANSLATIONS: Partial<Record<string, TranslationBundle>>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Event name for clearing the local store state of the diagram. There is an event listener listening for it, which
3
+ * will clear the local store state, whenever this event is fired.
4
+ */
5
+ export declare const CLEAR_DIAGRAM_STORAGE_EVENT = "graphwise-reactodia:clear-diagram-storage";
@@ -1,4 +1,4 @@
1
- import { SerializedDiagram, SparqlDataProviderSettings } from '@reactodia/workspace';
1
+ import { SparqlDataProviderSettings } from '@reactodia/workspace';
2
2
  import { LanguageKey } from '../i18n/language-key';
3
3
  import { ReactodiaConfig } from './reactodia-config';
4
4
  /**
@@ -22,15 +22,14 @@ export interface ReactodiaAppProps {
22
22
  * and is also used as the initial graph-data language.
23
23
  */
24
24
  language: LanguageKey;
25
- /**
26
- * A previously exported diagram to restore on mount. Used to carry the user's current
27
- * canvas across a remount (e.g. forced by a language change). When omitted, the canvas
28
- * starts empty.
29
- */
30
- initialDiagram?: SerializedDiagram;
31
25
  /**
32
26
  * Query preset for the SPARQL data provider, owned and configured by the host. Falls back
33
27
  * to Reactodia's generic `OwlRdfsSettings` OWL/RDFS preset when omitted.
34
28
  */
35
29
  providerSettings?: SparqlDataProviderSettings;
30
+ /**
31
+ * When true, the host is remounting the component switch languages, so the workspace should not be seeded, if a seed is present.
32
+ * Rather, the current state should simply be reloaded.
33
+ */
34
+ isReload?: boolean;
36
35
  }
@@ -1,5 +1,5 @@
1
1
  import { SparqlQueryFunction } from '@reactodia/workspace';
2
- import { ReactodiaSeedLink } from './reactodia-seed-link';
2
+ import { Triple } from './triple';
3
3
  /**
4
4
  * Host-supplied configuration read once when the workspace mounts (not reactive).
5
5
  *
@@ -14,16 +14,18 @@ export interface ReactodiaConfig {
14
14
  */
15
15
  queryFunction: SparqlQueryFunction;
16
16
  /**
17
- * IRIs of the entities to place on the canvas on startup. When provided, each IRI is added
17
+ * IRIs of the elements(nodes) to place on the canvas on startup. When provided, each IRI is added
18
18
  * as an element and its data (labels, types, properties) and links are resolved from the
19
19
  * SPARQL provider, then the workspace lays them out. Note that when using this seed method reactodia will request data
20
- * from the connected sparql endpoint, so if the resources are not in the DB, then this approach will not work.
20
+ * from the connected sparql endpoint for both elements and links, so if the resources are not in the DB, then this approach will not work.
21
21
  * (e.g. in the case of a construct query)
22
22
  */
23
23
  seedIris?: string[];
24
24
  /**
25
- * Pre-resolved edges to place on the canvas on startup. When provided, each link is added to the canvas and we do not
26
- * request data from the connected sparql endpoint, since this is meant for non-persisted data, like construct and describe queries.
25
+ * Pre-resolved triples (source, rawPredicate, target) to place on the canvas on startup. Date for the links is provided
26
+ * here, so reactodia will not request data for them. Data for nodes will be requested based on the IRIs of the source
27
+ * and target of the links. This is useful for visualizing the result of a CONSTRUCT query, whose relationships are
28
+ * computed and not persisted in the repository
27
29
  */
28
- seedGraph?: ReactodiaSeedLink[];
30
+ seedGraph?: Triple[];
29
31
  }
@@ -0,0 +1,26 @@
1
+ import { Subscription } from './subscription';
2
+ /**
3
+ * A collection of {@link Subscription}s that can be released together. Components collect the
4
+ * subscriptions they open and call {@link unsubscribeAll} on teardown so nothing is left
5
+ * listening.
6
+ */
7
+ export declare class SubscriptionList {
8
+ private items;
9
+ constructor(subscriptions?: Subscription[]);
10
+ /**
11
+ * Adds a subscription to the list.
12
+ */
13
+ add(subscription: Subscription): void;
14
+ /**
15
+ * Adds multiple subscriptions to the list.
16
+ */
17
+ addAll(subscriptions: Subscription[]): void;
18
+ /**
19
+ * Removes a subscription from the list without unsubscribing it.
20
+ */
21
+ remove(subscription: Subscription): void;
22
+ /**
23
+ * Calls every subscription (unsubscribing it) and clears the list.
24
+ */
25
+ unsubscribeAll(): void;
26
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * A subscription: calling it unsubscribes (removes the underlying listener).
3
+ */
4
+ export type Subscription = () => void;
@@ -5,17 +5,13 @@
5
5
  * fetched lazily through the SPARQL provider and must be supplied directly.
6
6
  *
7
7
  * The host adapts its source data into this neutral shape (e.g. the workbench maps the
8
- * `rest/explore-graph/graph` response, mapping its `rawPredicates` onto {@link predicates}).
8
+ * `rest/explore-graph/graph` response onto {@link rawPredicates}).
9
9
  */
10
- export interface ReactodiaSeedLink {
10
+ export interface Triple {
11
11
  /** Source element IRI. */
12
12
  source: string;
13
13
  /** Target element IRI. */
14
14
  target: string;
15
- /**
16
- * Short display friendly predicate
17
- */
18
- predicates: string[];
19
15
  /**
20
16
  * Full (absolute) predicate IRIs.
21
17
  */
@@ -0,0 +1,13 @@
1
+ import { Service } from './service';
2
+ /**
3
+ * Injects the singleton instance of the given service class from the {@link ServiceProvider}.
4
+ *
5
+ * @param serviceClass The class of the service to inject.
6
+ * @returns The shared instance of the specified service class.
7
+ * @template T The type of the service to inject.
8
+ * @example
9
+ * ```typescript
10
+ * const diagramStateService = service(DiagramStateService);
11
+ * ```
12
+ */
13
+ export declare function service<T>(serviceClass: Service<T>): T;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Interface for injectable services by the service provider. Each service needs to have a static unique ID, which
3
+ * is used by the {@link ServiceProvider} to cache and retrieve the singleton instance of the service. Unique IDs ensure
4
+ * correct working of the service provider, when the services are minified
5
+ *
6
+ * @template T the type of the service
7
+ */
8
+ export interface Service<T> {
9
+ readonly ID: string;
10
+ new (): T;
11
+ }
12
+ /**
13
+ * Decorator for a service class.
14
+ * It receives the class and simply type checks it with the {@link Service} interface.
15
+ * Works as a contract, which enforces the service class to have a static ID member.
16
+ * We can't simply implement the interface, since this will enforce the ID to be an instance member, which is not what we want.
17
+ *
18
+ * @param _serviceClass The decorated service class, checked for its ID and discarded.
19
+ * @template T The type of the service instance.
20
+ * @example
21
+ * ```TypeScript
22
+ * @Service
23
+ * export class WindowService {
24
+ * static readonly ID = 'WindowService';
25
+ * }
26
+ * ```
27
+ */
28
+ export declare function Service<T>(_serviceClass: Service<T>): void;
@@ -0,0 +1,16 @@
1
+ import { Service } from './service';
2
+ /**
3
+ * Provider for all {@link Service} instances. Services are singletons: there is only one
4
+ * instance of each service, created on demand and cached here so every consumer shares it.
5
+ */
6
+ export declare class ServiceProvider {
7
+ private static readonly SERVICE_INSTANCES;
8
+ /**
9
+ * Returns the instance of the given service type, creating and caching it on first request.
10
+ *
11
+ * @param type The service type to retrieve.
12
+ * @returns The shared instance of the service.
13
+ * @template T The type of the service to retrieve.
14
+ */
15
+ static get<T>(type: Service<T>): T;
16
+ }
@@ -0,0 +1,26 @@
1
+ import type { DataDiagramModel, SerializedDiagram } from '@reactodia/workspace';
2
+ import { Subscription } from '../../models/subscription';
3
+ /**
4
+ * Callback invoked with the current diagram layout whenever it changes.
5
+ */
6
+ export type DiagramChangeCallback = (diagram: SerializedDiagram) => void;
7
+ /**
8
+ * Service for diagram related operations and subscriptions
9
+ */
10
+ export declare class DiagramService {
11
+ static readonly ID = "DiagramService";
12
+ private static readonly NOTIFY_DEBOUNCE_MS;
13
+ private static readonly HISTORY_CHANGED_EVENT;
14
+ /**
15
+ * Subscribes to diagram changes. On every debounced change the current layout is
16
+ * exported and passed to the callback.
17
+ * Debounce time for the callback trigger is needed, because certain events (like moving a node) can trigger
18
+ * multiple `historyChanged` events in a short time.
19
+ *
20
+ * @param model The diagram model to observe.
21
+ * @param onChangeCallback Called with the exported layout when the diagram changes.
22
+ * @returns A {@link Subscription} that, when called, removes the listener and drops any
23
+ * pending notification.
24
+ */
25
+ subscribeToDiagramChange(model: DataDiagramModel, onChangeCallback: DiagramChangeCallback): Subscription;
26
+ }
@@ -0,0 +1,26 @@
1
+ import type { SerializedDiagram } from '@reactodia/workspace';
2
+ /**
3
+ * Service for local store-related diagram operations
4
+ */
5
+ export declare class DiagramStorageService {
6
+ static readonly ID = "DiagramStorageService";
7
+ private static readonly STORAGE_KEY;
8
+ /**
9
+ * Load the persisted diagram from the local store, or `undefined` when nothing is stored (or the stored value
10
+ * is unreadable).
11
+ */
12
+ load(): SerializedDiagram | undefined;
13
+ /**
14
+ * Persists the given diagram serialization.
15
+ */
16
+ save(diagram: SerializedDiagram): void;
17
+ /**
18
+ * Removes the persisted diagram. Used when a new view (a seed) should take precedence over
19
+ * previously saved edits.
20
+ */
21
+ clear(): void;
22
+ /**
23
+ * Local storage getter
24
+ */
25
+ private get storage();
26
+ }
@@ -0,0 +1,14 @@
1
+ import { Subscription } from '../../models/subscription';
2
+ /**
3
+ * Service for event based operations
4
+ */
5
+ export declare class EventService {
6
+ static readonly ID = "EventService";
7
+ /**
8
+ * Subscribes to the host's "clear persisted diagram" command.
9
+ *
10
+ * @param onClear Called whenever the event fires.
11
+ * @returns A {@link Subscription} that, when called, removes the listener.
12
+ */
13
+ subscribeToClearDiagramStorage(onClear: () => void): Subscription;
14
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Service that provides access to browser window-related functionality.
3
+ */
4
+ export declare class WindowService {
5
+ static readonly ID = "WindowService";
6
+ getWindow(): Window;
7
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Minimal in-memory {@link Storage}, so services that read `localStorage` can be exercised
3
+ * without a real browser store and asserted against directly. Shared across test suites.
4
+ */
5
+ export declare class StorageMock implements Storage {
6
+ private readonly store;
7
+ get length(): number;
8
+ clear(): void;
9
+ getItem(key: string): string | null;
10
+ key(index: number): string | null;
11
+ removeItem(key: string): void;
12
+ setItem(key: string, value: string): void;
13
+ }
14
+ /**
15
+ * Creates a fresh {@link StorageMock}. Suites install the returned instance as the global
16
+ * `localStorage` themselves.
17
+ */
18
+ export declare function createStorageMock(): StorageMock;
@@ -1 +1 @@
1
- export {};
1
+ export { CLEAR_DIAGRAM_STORAGE_EVENT } from './components/graphwise-reactodia/models/clear-diagram-storage-event';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphwise-reactodia",
3
- "version": "0.0.1-TR7",
3
+ "version": "0.0.1-TR9",
4
4
  "description": "Graphwise wrapper around the Reactodia graph explorer.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Ontotext AD",
@@ -9,7 +9,8 @@
9
9
  "collection": "dist/collection/collection-manifest.json",
10
10
  "exports": {
11
11
  ".": {
12
- "import": "./dist/graphwise-reactodia/graphwise-reactodia.esm.js",
12
+ "types": "./dist/types/index.d.ts",
13
+ "import": "./dist/esm/index.js",
13
14
  "require": "./dist/index.cjs.js"
14
15
  },
15
16
  "./loader": {
@@ -30,16 +31,21 @@
30
31
  "start": "npm run reactodia:build && stencil build --dev --watch --serve",
31
32
  "cy:open": "cypress open",
32
33
  "cy:run": "cypress run",
33
- "cy:run:ci": "docker compose --ansi never up --exit-code-from cypress"
34
+ "cy:run:ci": "docker compose --ansi never up --exit-code-from cypress",
35
+ "test": "stencil test --spec",
36
+ "test.watch": "stencil test --spec --watchAll"
34
37
  },
35
38
  "devDependencies": {
36
39
  "@rdfjs/types": "^2.0.1",
37
40
  "@reactodia/workspace": "file:./reactodia-workspace",
38
41
  "@stencil/core": "4.35.1",
39
42
  "@stencil/sass": "^3.2.3",
43
+ "@types/jest": "^29.5.14",
40
44
  "@types/react": "^18.3.12",
41
45
  "@types/react-dom": "^18.3.1",
42
46
  "cypress": "^15.17.0",
47
+ "jest": "^29.7.0",
48
+ "jest-cli": "^29.7.0",
43
49
  "react": "^18.3.1",
44
50
  "react-dom": "^18.3.1",
45
51
  "rollup-plugin-node-polyfills": "^0.2.1"