@visuallyjs/browser-ui-svelte 1.1.4 → 1.2.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.
- package/AreaChartComponent.svelte +24 -15
- package/BarChartComponent.svelte +24 -12
- package/BubbleChartComponent.svelte +23 -11
- package/ColorPickerComponent.svelte +2 -2
- package/ColumnChartComponent.svelte +23 -11
- package/ControlsComponent.svelte +12 -34
- package/DecoratorComponent.svelte +15 -23
- package/DiagramComponent.svelte +2 -2
- package/DiagramPaletteComponent.svelte +24 -31
- package/DiagramProvider.svelte +3 -1
- package/EdgeTypePickerComponent.svelte +1 -1
- package/ExportControlsComponent.svelte +15 -33
- package/GaugeChartComponent.svelte +2 -7
- package/InspectorComponent.svelte +24 -36
- package/LineChartComponent.svelte +23 -13
- package/MiniviewComponent.svelte +28 -48
- package/OverlayWrapperComponent.svelte +35 -0
- package/PaletteComponent.svelte +28 -41
- package/PaperComponent.svelte +365 -0
- package/PaperProvider.svelte +11 -0
- package/PieChartComponent.svelte +23 -8
- package/SankeyChartComponent.svelte +35 -14
- package/ScatterChartComponent.svelte +23 -11
- package/ShapePaletteComponent.svelte +11 -22
- package/SurfaceComponent.svelte +100 -5
- package/SurfacePopup.svelte +32 -0
- package/SurfaceProvider.svelte +3 -1
- package/WrapperComponent.svelte +3 -1
- package/XYChartComponent.svelte +33 -12
- package/charts/definitions.d.ts +119 -0
- package/charts/definitions.js +1 -0
- package/components.d.ts +4 -0
- package/components.js +4 -0
- package/definitions.d.ts +111 -259
- package/diagram-store.d.ts +0 -5
- package/diagram-store.js +0 -15
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/package.json +1 -1
- package/surface-store.d.ts +19 -4
- package/surface-store.js +43 -12
- package/use-diagram.svelte.d.ts +8 -0
- package/use-diagram.svelte.js +18 -0
- package/use-surface.svelte.d.ts +7 -0
- package/use-surface.svelte.js +18 -0
- package/use-visuallyjs-update.svelte.d.ts +19 -0
- package/use-visuallyjs-update.svelte.js +37 -0
- package/use-zoom.svelte.d.ts +1 -3
- package/use-zoom.svelte.js +14 -11
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { internal_getSurfaceContext } from "./surface-store";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a reactive zoom state for a VisuallyJS UI
|
|
4
|
+
* @group Hooks
|
|
5
|
+
*/
|
|
6
|
+
export function useSurface() {
|
|
7
|
+
const ctx = internal_getSurfaceContext(true);
|
|
8
|
+
let surface = $state(null);
|
|
9
|
+
if (ctx != null) {
|
|
10
|
+
ctx.listen((s) => surface = s);
|
|
11
|
+
}
|
|
12
|
+
// Return an object with a getter to maintain reactivity across function boundaries
|
|
13
|
+
return {
|
|
14
|
+
get current() {
|
|
15
|
+
return surface;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BrowserUISvelteModel } from "./index";
|
|
2
|
+
/**
|
|
3
|
+
* Simple hook that responds to all update events in the model, including when the model is cleared. You pass in a function that takes the model as argument, and that should be invoked when an update/clear event occurs. The function is also invoked when the initial model reference is obtained.
|
|
4
|
+
*
|
|
5
|
+
* ```jsx
|
|
6
|
+
* <script>
|
|
7
|
+
* import { useVisuallyJsUpdate } from "@visuallyjs/browser-ui-svelte"
|
|
8
|
+
*
|
|
9
|
+
* let count = $state(0)
|
|
10
|
+
* useVisuallyJsUpdate((model) => count = model.getNodeCount())
|
|
11
|
+
* </script>
|
|
12
|
+
*
|
|
13
|
+
* <h1>{count}</h1>
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param callback Callback to invoke when an update occurs.
|
|
17
|
+
* @group Hooks
|
|
18
|
+
*/
|
|
19
|
+
export declare function useVisuallyJsUpdate(callback: (model: BrowserUISvelteModel) => any): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EVENT_DATA_UPDATED, EVENT_GRAPH_CLEARED } from "@visuallyjs/browser-ui";
|
|
2
|
+
import { useDiagram } from "./index";
|
|
3
|
+
import { useSurface } from "./use-surface.svelte";
|
|
4
|
+
/**
|
|
5
|
+
* Simple hook that responds to all update events in the model, including when the model is cleared. You pass in a function that takes the model as argument, and that should be invoked when an update/clear event occurs. The function is also invoked when the initial model reference is obtained.
|
|
6
|
+
*
|
|
7
|
+
* ```jsx
|
|
8
|
+
* <script>
|
|
9
|
+
* import { useVisuallyJsUpdate } from "@visuallyjs/browser-ui-svelte"
|
|
10
|
+
*
|
|
11
|
+
* let count = $state(0)
|
|
12
|
+
* useVisuallyJsUpdate((model) => count = model.getNodeCount())
|
|
13
|
+
* </script>
|
|
14
|
+
*
|
|
15
|
+
* <h1>{count}</h1>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param callback Callback to invoke when an update occurs.
|
|
19
|
+
* @group Hooks
|
|
20
|
+
*/
|
|
21
|
+
export function useVisuallyJsUpdate(callback) {
|
|
22
|
+
const ui = useSurface();
|
|
23
|
+
const diagram = useDiagram();
|
|
24
|
+
$effect(() => {
|
|
25
|
+
const vjs = ui.current?.model || diagram.current?.model;
|
|
26
|
+
if (vjs != null) {
|
|
27
|
+
const fn = () => callback(vjs);
|
|
28
|
+
vjs.bind(EVENT_DATA_UPDATED, fn);
|
|
29
|
+
vjs.bind(EVENT_GRAPH_CLEARED, fn);
|
|
30
|
+
fn();
|
|
31
|
+
return (() => {
|
|
32
|
+
vjs.unbind(EVENT_DATA_UPDATED, fn);
|
|
33
|
+
vjs.unbind(EVENT_GRAPH_CLEARED, fn);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
package/use-zoom.svelte.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { BrowserUI } from '@visuallyjs/browser-ui';
|
|
2
1
|
/**
|
|
3
2
|
* Creates a reactive zoom state for a VisuallyJS UI
|
|
4
|
-
* @param ui The Surface instance provided via props.
|
|
5
3
|
* @group Hooks
|
|
6
4
|
*/
|
|
7
|
-
export declare function useZoom(
|
|
5
|
+
export declare function useZoom(): {
|
|
8
6
|
readonly current: number;
|
|
9
7
|
};
|
package/use-zoom.svelte.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { EVENT_ZOOM } from '@visuallyjs/browser-ui';
|
|
2
|
+
import { useSurface } from "./use-surface.svelte";
|
|
2
3
|
/**
|
|
3
4
|
* Creates a reactive zoom state for a VisuallyJS UI
|
|
4
|
-
* @param ui The Surface instance provided via props.
|
|
5
5
|
* @group Hooks
|
|
6
6
|
*/
|
|
7
|
-
export function useZoom(
|
|
8
|
-
let zoom = $state(
|
|
7
|
+
export function useZoom() {
|
|
8
|
+
let zoom = $state(1);
|
|
9
|
+
let uiRef = useSurface();
|
|
9
10
|
// Manage event listener lifecycle
|
|
10
11
|
$effect(() => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
if (uiRef.current != null) {
|
|
13
|
+
const handler = (p) => {
|
|
14
|
+
zoom = p.zoom;
|
|
15
|
+
};
|
|
16
|
+
uiRef.current.bind(EVENT_ZOOM, handler);
|
|
17
|
+
// Auto-cleanup when the component/effect is destroyed
|
|
18
|
+
return () => {
|
|
19
|
+
uiRef.current.unbind(EVENT_ZOOM, handler);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
19
22
|
});
|
|
20
23
|
// Return an object with a getter to maintain reactivity across function boundaries
|
|
21
24
|
return {
|