@visuallyjs/browser-ui-svelte 1.0.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.
Files changed (43) hide show
  1. package/AreaChartComponent.svelte +37 -0
  2. package/BarChartComponent.svelte +37 -0
  3. package/BubbleChartComponent.svelte +38 -0
  4. package/ColorPickerComponent.svelte +94 -0
  5. package/ColumnChartComponent.svelte +38 -0
  6. package/ControlsComponent.svelte +66 -0
  7. package/DecoratorComponent.svelte +55 -0
  8. package/DefaultGroupComponent.svelte +5 -0
  9. package/DefaultNodeComponent.svelte +5 -0
  10. package/DiagramComponent.svelte +46 -0
  11. package/DiagramPaletteComponent.svelte +47 -0
  12. package/DiagramProvider.svelte +9 -0
  13. package/EdgeTypePickerComponent.svelte +47 -0
  14. package/ExportControlsComponent.svelte +94 -0
  15. package/GaugeChartComponent.svelte +31 -0
  16. package/InspectorComponent.svelte +79 -0
  17. package/LineChartComponent.svelte +38 -0
  18. package/MiniviewComponent.svelte +73 -0
  19. package/PaletteComponent.svelte +73 -0
  20. package/PieChartComponent.svelte +37 -0
  21. package/SankeyChartComponent.svelte +44 -0
  22. package/ScatterChartComponent.svelte +38 -0
  23. package/ShapeComponent.svelte +66 -0
  24. package/ShapePaletteComponent.svelte +82 -0
  25. package/SurfaceComponent.svelte +270 -0
  26. package/SurfaceProvider.svelte +9 -0
  27. package/WrapperComponent.svelte +27 -0
  28. package/XYChartComponent.svelte +32 -0
  29. package/components.d.ts +29 -0
  30. package/components.js +29 -0
  31. package/definitions.d.ts +841 -0
  32. package/definitions.js +1 -0
  33. package/diagram-store.d.ts +30 -0
  34. package/diagram-store.js +58 -0
  35. package/index.d.ts +27 -0
  36. package/index.js +33 -0
  37. package/inspector-store.d.ts +24 -0
  38. package/inspector-store.js +42 -0
  39. package/package.json +1 -0
  40. package/store-adapter.d.ts +15 -0
  41. package/store-adapter.js +47 -0
  42. package/surface-store.d.ts +41 -0
  43. package/surface-store.js +73 -0
package/definitions.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import type { Diagram } from "@visuallyjs/browser-ui";
2
+ import { ComponentRef } from "./surface-store";
3
+ /**
4
+ * Key for the diagram context
5
+ * @internal
6
+ */
7
+ export declare const DIAGRAM_STORE_KEY: unique symbol;
8
+ /**
9
+ * Handle for a diagram - use `set` to set the diagram and `listen` to register a listener.
10
+ * @internal
11
+ */
12
+ export interface DiagramRef extends ComponentRef<Diagram> {
13
+ }
14
+ /**
15
+ * Create a surface context, and set it on Svelte via `setContext`.
16
+ * @internal
17
+ */
18
+ export declare function internal_createDiagramContext(): DiagramRef;
19
+ /**
20
+ * Gets the current diagram context from Svelte, optionally creating it if it does not exist. The Diagram and the DiagramProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
21
+ * DO NOT use as a user of the API. Use {@link useDiagram} instead
22
+ * @param doNotCreate
23
+ * @internal
24
+ */
25
+ export declare function internal_getDiagramContext(doNotCreate: boolean): DiagramRef;
26
+ /**
27
+ * Hook to expose the current Surface. This hook is asynchronous and returns a Promise.
28
+ * @group Hooks
29
+ */
30
+ export declare function useDiagram(): Promise<Diagram>;
@@ -0,0 +1,58 @@
1
+ import { getContext, setContext } from "svelte";
2
+ /**
3
+ * Key for the diagram context
4
+ * @internal
5
+ */
6
+ export const DIAGRAM_STORE_KEY = Symbol();
7
+ /**
8
+ * Create a surface context, and set it on Svelte via `setContext`.
9
+ * @internal
10
+ */
11
+ export function internal_createDiagramContext() {
12
+ const listeners = [];
13
+ const handle = { current: null };
14
+ const ref = {
15
+ set: (d) => {
16
+ handle.current = d;
17
+ listeners.forEach(l => l(d));
18
+ },
19
+ listen: (l) => {
20
+ if (handle.current == null) {
21
+ listeners.push(l);
22
+ }
23
+ else {
24
+ l(handle.current);
25
+ }
26
+ }
27
+ };
28
+ setContext(DIAGRAM_STORE_KEY, ref);
29
+ return ref;
30
+ }
31
+ /**
32
+ * Gets the current diagram context from Svelte, optionally creating it if it does not exist. The Diagram and the DiagramProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
33
+ * DO NOT use as a user of the API. Use {@link useDiagram} instead
34
+ * @param doNotCreate
35
+ * @internal
36
+ */
37
+ export function internal_getDiagramContext(doNotCreate) {
38
+ let ctx = getContext(DIAGRAM_STORE_KEY);
39
+ if (ctx == null && !doNotCreate) {
40
+ ctx = internal_createDiagramContext();
41
+ }
42
+ return ctx;
43
+ }
44
+ /**
45
+ * Hook to expose the current Surface. This hook is asynchronous and returns a Promise.
46
+ * @group Hooks
47
+ */
48
+ export function useDiagram() {
49
+ const ref = internal_getDiagramContext(true);
50
+ return new Promise((resolve, reject) => {
51
+ if (ref != null) {
52
+ ref.listen((s) => resolve(s));
53
+ }
54
+ else {
55
+ reject();
56
+ }
57
+ });
58
+ }
package/index.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Provides integration with Svelte 5. This package has a dependency on @visuallyjs/browser-ui.
3
+ *
4
+ * For a detailed discussion of this package, see https://visuallyjs.com/svelte
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export * from './components';
9
+ export * from './store-adapter';
10
+ export * from './diagram-store';
11
+ export * from './surface-store';
12
+ export * from './inspector-store';
13
+ export * from './definitions';
14
+ import { BrowserElement, BrowserUIModel, BrowserUIOptions, TemplateRenderer, ModelOptions } from "@visuallyjs/browser-ui";
15
+ /**
16
+ * Extension of VisuallyJsModel suitable for use with the Svelte integration.
17
+ * @group Classes
18
+ */
19
+ export declare class BrowserUISvelteModel extends BrowserUIModel {
20
+ render(container: BrowserElement, options?: BrowserUIOptions, templateRenderer?: TemplateRenderer<any>): any;
21
+ }
22
+ /**
23
+ * Creates a new instance of the VisuallyJs model for use with the Svelte integration.
24
+ * @param options
25
+ * @internal
26
+ */
27
+ export declare function newInstance(options: ModelOptions): BrowserUISvelteModel;
package/index.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Provides integration with Svelte 5. This package has a dependency on @visuallyjs/browser-ui.
3
+ *
4
+ * For a detailed discussion of this package, see https://visuallyjs.com/svelte
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export * from './components';
9
+ export * from './store-adapter';
10
+ export * from './diagram-store';
11
+ export * from './surface-store';
12
+ export * from './inspector-store';
13
+ export * from './definitions';
14
+ import { BrowserUIModel, log } from "@visuallyjs/browser-ui";
15
+ /**
16
+ * Extension of VisuallyJsModel suitable for use with the Svelte integration.
17
+ * @group Classes
18
+ */
19
+ export class BrowserUISvelteModel extends BrowserUIModel {
20
+ render(container, options, templateRenderer) {
21
+ log("render called directly on BrowserUISvelteModel class: should not happen. UI components should use internal render.");
22
+ return null;
23
+ }
24
+ }
25
+ /**
26
+ * Creates a new instance of the VisuallyJs model for use with the Svelte integration.
27
+ * @param options
28
+ * @internal
29
+ */
30
+ export function newInstance(options) {
31
+ options = options || {};
32
+ return new BrowserUISvelteModel(options);
33
+ }
@@ -0,0 +1,24 @@
1
+ import type { Inspector } from "@visuallyjs/browser-ui";
2
+ import { ComponentRef } from "./surface-store";
3
+ /**
4
+ * Key for the inspector context
5
+ * @internal
6
+ */
7
+ export declare const INSPECTOR_STORE_KEY: unique symbol;
8
+ /**
9
+ * Handle for an inspector - use `set` to set the inspector and `listen` to register a listener.
10
+ * @internal
11
+ */
12
+ export interface InspectorRef extends ComponentRef<Inspector> {
13
+ }
14
+ /**
15
+ * Create a inspector context, and set it on Svelte via `setContext`.
16
+ * @internal
17
+ */
18
+ export declare function createInspectorContext(): InspectorRef;
19
+ /**
20
+ * Gets the current Inspector context from Svelte, optionally creating it if it does not exist.
21
+ * @param doNotCreate
22
+ * @internal
23
+ */
24
+ export declare function getInspectorContext(doNotCreate: boolean): InspectorRef;
@@ -0,0 +1,42 @@
1
+ import { getContext, setContext } from "svelte";
2
+ /**
3
+ * Key for the inspector context
4
+ * @internal
5
+ */
6
+ export const INSPECTOR_STORE_KEY = Symbol();
7
+ /**
8
+ * Create a inspector context, and set it on Svelte via `setContext`.
9
+ * @internal
10
+ */
11
+ export function createInspectorContext() {
12
+ const listeners = [];
13
+ const handle = { current: null };
14
+ const ref = {
15
+ set: (d) => {
16
+ handle.current = d;
17
+ listeners.forEach(l => l(d));
18
+ },
19
+ listen: (l) => {
20
+ if (handle.current == null) {
21
+ listeners.push(l);
22
+ }
23
+ else {
24
+ l(handle.current);
25
+ }
26
+ }
27
+ };
28
+ setContext(INSPECTOR_STORE_KEY, ref);
29
+ return ref;
30
+ }
31
+ /**
32
+ * Gets the current Inspector context from Svelte, optionally creating it if it does not exist.
33
+ * @param doNotCreate
34
+ * @internal
35
+ */
36
+ export function getInspectorContext(doNotCreate) {
37
+ let ctx = getContext(INSPECTOR_STORE_KEY);
38
+ if (ctx == null && !doNotCreate) {
39
+ ctx = createInspectorContext();
40
+ }
41
+ return ctx;
42
+ }
package/package.json ADDED
@@ -0,0 +1 @@
1
+ {"name":"@visuallyjs/browser-ui-svelte","version":"1.0.0","description":"VisuallyJS Svelte integration for Browser UI renderer","module":"index.js","main":"index.js","types":"index.d.ts","svelte":"index.js","files":["**/*.d.ts","**/*.js","SurfaceComponent.svelte","DecoratorComponent.svelte","DefaultGroupComponent.svelte","DefaultNodeComponent.svelte","MiniviewComponent.svelte","ControlsComponent.svelte","SurfaceProvider.svelte","PaletteComponent.svelte","InspectorComponent.svelte","EdgeTypePickerComponent.svelte","ShapePaletteComponent.svelte","ExportControlsComponent.svelte","ShapeComponent.svelte","DiagramComponent.svelte","BarChartComponent.svelte","ColumnChartComponent.svelte","XYChartComponent.svelte","LineChartComponent.svelte","AreaChartComponent.svelte","PieChartComponent.svelte","WrapperComponent.svelte","DiagramProvider.svelte","DiagramPaletteComponent.svelte","ColorPickerComponent.svelte","ScatterChartComponent.svelte","BubbleChartComponent.svelte","GaugeChartComponent.svelte","SankeyChartComponent.svelte"],"author":"VisuallyJs <hello@visuallyjs.com> (https://visuallyjs.com)","license":"Commercial","dependencies":{"@visuallyjs/browser-ui":"1.0.0"}}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A simple wrapper around a store whose contents are expected to be in VisuallyJs's JSON data format. When the store
3
+ * posts an update event, the contents of the store are queried and VisuallyJs's list of nodes, groups and edges
4
+ * are updated to be in line with the contents of the store.
5
+ *
6
+ */
7
+ import { VisuallyJsModel } from "@visuallyjs/browser-ui";
8
+ export declare class StoreAdapter {
9
+ model: VisuallyJsModel;
10
+ store: any;
11
+ constructor(model: VisuallyJsModel, store: any);
12
+ processNodes(nodes: any): void;
13
+ processGroups(groups: any): void;
14
+ processEdges(edges: any): void;
15
+ }
@@ -0,0 +1,47 @@
1
+ export class StoreAdapter {
2
+ model;
3
+ store;
4
+ constructor(model, store) {
5
+ this.model = model;
6
+ this.store = store;
7
+ store.subscribe((value) => {
8
+ this.processGroups(value.groups || []);
9
+ this.processNodes(value.nodes || []);
10
+ this.processEdges(value.edges || []);
11
+ });
12
+ }
13
+ processNodes(nodes) {
14
+ const vjsNodes = this.model.getNodes();
15
+ const newNodes = nodes.filter((n) => this.model.getNode(n.id) == null);
16
+ const removedNodes = vjsNodes.filter((n) => {
17
+ return nodes.find((_n) => _n.id === n.id) == null;
18
+ });
19
+ removedNodes.forEach((n) => this.model.removeNode(n));
20
+ newNodes.forEach((n) => this.model.addNode(n));
21
+ }
22
+ processGroups(groups) {
23
+ const vjsGroups = this.model.getGroups();
24
+ const newGroups = groups.filter((n) => this.model.getGroup(n.id) == null);
25
+ const removedGroups = vjsGroups.filter((n) => {
26
+ return groups.find((_n) => _n.id === n.id) == null;
27
+ });
28
+ removedGroups.forEach((n) => this.model.removeGroup(n));
29
+ newGroups.forEach((n) => this.model.addGroup(n));
30
+ }
31
+ processEdges(edges) {
32
+ const vjsEdges = this.model.getAllEdges();
33
+ const newEdges = edges.filter((e) => {
34
+ e.data = e.data || {};
35
+ let edgeId = e.data.id;
36
+ return edgeId == null || this.model.getEdge(edgeId) == null;
37
+ });
38
+ const removedEdges = vjsEdges.filter((n) => {
39
+ return edges.find((_n) => _n.id === n.id) == null;
40
+ });
41
+ removedEdges.forEach((n) => this.model.removeEdge(n));
42
+ newEdges.forEach((n) => {
43
+ const e = this.model.addEdge(n);
44
+ n.data.id = e.id;
45
+ });
46
+ }
47
+ }
@@ -0,0 +1,41 @@
1
+ import type { Surface } from "@visuallyjs/browser-ui";
2
+ import { BrowserUISvelteModel } from "./index";
3
+ /**
4
+ * Key for the surface context
5
+ * @internal
6
+ */
7
+ export declare const STORE_KEY: unique symbol;
8
+ export interface ComponentRef<T> {
9
+ set: (o: T) => void;
10
+ listen: (l: (o: T) => any) => void;
11
+ }
12
+ /**
13
+ * Handle for a surface - use `set` to set the surface and `listen` to register a listener.
14
+ * @internal
15
+ */
16
+ export interface SurfaceRef {
17
+ set: (surface: Surface) => void;
18
+ listen: (l: (s: Surface) => any) => void;
19
+ }
20
+ /**
21
+ * Create a surface context, and set it on Svelte via `setContext`.
22
+ * @internal
23
+ */
24
+ export declare function internal_createSurfaceContext(): SurfaceRef;
25
+ /**
26
+ * Gets the current surface context from Svelte, optionally creating it if it does not exist. The Surface and the SurfaceProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
27
+ * This method is NOT to be invoked by users of the API. Use {@link useSurface} to access the current Surface.
28
+ * @param doNotCreate
29
+ * @internal
30
+ */
31
+ export declare function internal_getSurfaceContext(doNotCreate: boolean): SurfaceRef;
32
+ /**
33
+ * Hook to expose the current Surface. This hook is asynchronous and returns a Promise.
34
+ * @group Hooks
35
+ */
36
+ export declare function useSurface(): Promise<Surface>;
37
+ /**
38
+ * Hook to expose the current model. This hook is asynchronous and returns a Promise.
39
+ * @group Hooks
40
+ */
41
+ export declare function useVisuallyJsModel(): Promise<BrowserUISvelteModel>;
@@ -0,0 +1,73 @@
1
+ import { getContext, setContext } from "svelte";
2
+ /**
3
+ * Key for the surface context
4
+ * @internal
5
+ */
6
+ export const STORE_KEY = Symbol();
7
+ /**
8
+ * Create a surface context, and set it on Svelte via `setContext`.
9
+ * @internal
10
+ */
11
+ export function internal_createSurfaceContext() {
12
+ const listeners = [];
13
+ const handle = { current: null };
14
+ const ref = {
15
+ set: (surface) => {
16
+ handle.current = surface;
17
+ listeners.forEach(l => l(surface));
18
+ },
19
+ listen: (l) => {
20
+ if (handle.current == null) {
21
+ listeners.push(l);
22
+ }
23
+ else {
24
+ l(handle.current);
25
+ }
26
+ }
27
+ };
28
+ setContext(STORE_KEY, ref);
29
+ return ref;
30
+ }
31
+ /**
32
+ * Gets the current surface context from Svelte, optionally creating it if it does not exist. The Surface and the SurfaceProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
33
+ * This method is NOT to be invoked by users of the API. Use {@link useSurface} to access the current Surface.
34
+ * @param doNotCreate
35
+ * @internal
36
+ */
37
+ export function internal_getSurfaceContext(doNotCreate) {
38
+ let ctx = getContext(STORE_KEY);
39
+ if (ctx == null && !doNotCreate) {
40
+ ctx = internal_createSurfaceContext();
41
+ }
42
+ return ctx;
43
+ }
44
+ /**
45
+ * Hook to expose the current Surface. This hook is asynchronous and returns a Promise.
46
+ * @group Hooks
47
+ */
48
+ export function useSurface() {
49
+ const ref = internal_getSurfaceContext(true);
50
+ return new Promise((resolve, reject) => {
51
+ if (ref != null) {
52
+ ref.listen((s) => resolve(s));
53
+ }
54
+ else {
55
+ reject();
56
+ }
57
+ });
58
+ }
59
+ /**
60
+ * Hook to expose the current model. This hook is asynchronous and returns a Promise.
61
+ * @group Hooks
62
+ */
63
+ export function useVisuallyJsModel() {
64
+ const ref = internal_getSurfaceContext(true);
65
+ return new Promise((resolve, reject) => {
66
+ if (ref != null) {
67
+ ref.listen((s) => resolve(s.model));
68
+ }
69
+ else {
70
+ reject();
71
+ }
72
+ });
73
+ }