@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.
Files changed (49) hide show
  1. package/AreaChartComponent.svelte +24 -15
  2. package/BarChartComponent.svelte +24 -12
  3. package/BubbleChartComponent.svelte +23 -11
  4. package/ColorPickerComponent.svelte +2 -2
  5. package/ColumnChartComponent.svelte +23 -11
  6. package/ControlsComponent.svelte +12 -34
  7. package/DecoratorComponent.svelte +15 -23
  8. package/DiagramComponent.svelte +2 -2
  9. package/DiagramPaletteComponent.svelte +24 -31
  10. package/DiagramProvider.svelte +3 -1
  11. package/EdgeTypePickerComponent.svelte +1 -1
  12. package/ExportControlsComponent.svelte +15 -33
  13. package/GaugeChartComponent.svelte +2 -7
  14. package/InspectorComponent.svelte +24 -36
  15. package/LineChartComponent.svelte +23 -13
  16. package/MiniviewComponent.svelte +28 -48
  17. package/OverlayWrapperComponent.svelte +35 -0
  18. package/PaletteComponent.svelte +28 -41
  19. package/PaperComponent.svelte +365 -0
  20. package/PaperProvider.svelte +11 -0
  21. package/PieChartComponent.svelte +23 -8
  22. package/SankeyChartComponent.svelte +35 -14
  23. package/ScatterChartComponent.svelte +23 -11
  24. package/ShapePaletteComponent.svelte +11 -22
  25. package/SurfaceComponent.svelte +100 -5
  26. package/SurfacePopup.svelte +32 -0
  27. package/SurfaceProvider.svelte +3 -1
  28. package/WrapperComponent.svelte +3 -1
  29. package/XYChartComponent.svelte +33 -12
  30. package/charts/definitions.d.ts +119 -0
  31. package/charts/definitions.js +1 -0
  32. package/components.d.ts +4 -0
  33. package/components.js +4 -0
  34. package/definitions.d.ts +111 -259
  35. package/diagram-store.d.ts +0 -5
  36. package/diagram-store.js +0 -15
  37. package/index.d.ts +4 -0
  38. package/index.js +4 -0
  39. package/package.json +1 -1
  40. package/surface-store.d.ts +19 -4
  41. package/surface-store.js +43 -12
  42. package/use-diagram.svelte.d.ts +8 -0
  43. package/use-diagram.svelte.js +18 -0
  44. package/use-surface.svelte.d.ts +7 -0
  45. package/use-surface.svelte.js +18 -0
  46. package/use-visuallyjs-update.svelte.d.ts +19 -0
  47. package/use-visuallyjs-update.svelte.js +37 -0
  48. package/use-zoom.svelte.d.ts +1 -3
  49. 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
+ }
@@ -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(ui: BrowserUI): {
5
+ export declare function useZoom(): {
8
6
  readonly current: number;
9
7
  };
@@ -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(ui) {
8
- let zoom = $state(ui.getZoom());
7
+ export function useZoom() {
8
+ let zoom = $state(1);
9
+ let uiRef = useSurface();
9
10
  // Manage event listener lifecycle
10
11
  $effect(() => {
11
- const handler = (p) => {
12
- zoom = p.zoom;
13
- };
14
- ui.bind(EVENT_ZOOM, handler);
15
- // Auto-cleanup when the component/effect is destroyed
16
- return () => {
17
- ui.unbind(EVENT_ZOOM, handler);
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 {