@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
package/definitions.d.ts CHANGED
@@ -1,11 +1,16 @@
1
- import type { DOMAttributes } from "svelte/elements";
2
- import { SurfaceOptions, Vertex, Group, Node, ControlsComponentButtons, DataGeneratorFunction, type BrowserElement, Base, Size, ObjectData, DropTargetInfo, PaletteMode, SvgExportUIOptions, ImageExportUIOptions, ShapeLibraryImpl, ModelOptions, DiagramOptions, ColumnChartOptions, BarChartOptions, CategoryValueChartOptions, Diagram, DiagramCell, NodeMapping, GroupMapping, PortMapping, BrowserUI, EdgeMapping, OnVertexAddedCallback, CanvasDropFilter, LineChartOptions, AreaChartOptions, PieChartOptions, ScatterChartOptions, BubbleChartOptions, GaugeChartOptions, SankeyOptions, FontSpec, BrowserUIModel, PreparedShape, ChartModelFilter, VisuallyJsDefaultJSON, PointXY, FixedElementConstraints } from "@visuallyjs/browser-ui";
3
1
  import { type Snippet } from "svelte";
2
+ import type { DOMAttributes } from "svelte/elements";
3
+ import { SurfaceOptions, Vertex, Group, Node, ControlsComponentButtons, DataGeneratorFunction, type BrowserElement, Base, Size, ObjectData, DropTargetInfo, PaletteMode, SvgExportUIOptions, ImageExportUIOptions, ShapeLibraryImpl, ModelOptions, DiagramOptions, Diagram, DiagramCell, NodeMapping, GroupMapping, PortMapping, BrowserUI, EdgeMapping, OnVertexAddedCallback, CanvasDropFilter, FontSpec, BrowserUIModel, PreparedShape, PointXY, FixedElementConstraints, PopupPosition, OverlaySpec, PaperOptions } from "@visuallyjs/browser-ui";
4
4
  /**
5
5
  * Render options for a SurfaceComponent. This interface is the same as SurfaceOptions but with several vanilla-only options removed.
6
6
  */
7
7
  export interface SvelteSurfaceRenderOptions extends Omit<SurfaceOptions, "directRender" | "enhancedView" | "view" | "templates"> {
8
8
  }
9
+ /**
10
+ * Render options for a PaperComponent. This interface is the same as PaperOptions but with several vanilla-only options removed.
11
+ */
12
+ export interface SveltePaperRenderOptions extends Omit<PaperOptions, "directRender" | "enhancedView" | "view" | "templates"> {
13
+ }
9
14
  /**
10
15
  * Definition of a node - its component, and behaviour.
11
16
  */
@@ -34,15 +39,29 @@ export interface SveltePortMapping extends Omit<PortMapping<any>, "templateIdRes
34
39
  component?: any;
35
40
  }
36
41
  /**
37
- * Spec for a react component overlay. A ctx object is passed in to your component and you are expected to return JSX.
42
+ * Defines a value holder. This is a direct copy of the `RefObject` concept from React.
38
43
  */
44
+ export type RefObject<T> = {
45
+ current: T | null;
46
+ };
39
47
  /**
40
- * Edge mappings for a view.
48
+ * Definition for an overlay when using Svelte components.
41
49
  */
50
+ export interface SvelteOverlaySpec {
51
+ /**
52
+ * Component used to render this overlay.
53
+ */
54
+ component: any;
55
+ /**
56
+ * Props to pass to the component.
57
+ */
58
+ props?: Record<string, any>;
59
+ }
42
60
  /**
43
61
  * Mapping definition for edges in a Svelte view.
44
62
  */
45
- export interface SvelteEdgeMapping extends EdgeMapping {
63
+ export interface SvelteEdgeMapping extends Omit<EdgeMapping, "overlays"> {
64
+ overlays?: Array<OverlaySpec | SvelteOverlaySpec>;
46
65
  }
47
66
  /**
48
67
  * Options for the view in the Svelte surface component. Maps node/group/port/edge types to components and behaviour.
@@ -65,6 +84,11 @@ export interface SvelteSurfaceViewOptions {
65
84
  */
66
85
  edges?: Record<string, SvelteEdgeMapping>;
67
86
  }
87
+ /**
88
+ * Options for the view in the Svelte paper component. Maps node/group/port/edge types to components and behaviour.
89
+ */
90
+ export interface SveltePaperViewOptions extends SvelteSurfaceViewOptions {
91
+ }
68
92
  /**
69
93
  * @group Props
70
94
  */
@@ -109,6 +133,56 @@ export interface SurfaceComponentProps extends DOMAttributes<HTMLDivElement> {
109
133
  * Shape library to use to render SVG shapes. Optional.
110
134
  */
111
135
  shapeLibrary?: ShapeLibraryImpl<ObjectData>;
136
+ /**
137
+ * An optional array of reactive objects. The properties from these objects will be
138
+ * merged into the props passed to each WrapperComponent, preserving reactivity.
139
+ */
140
+ additionalProps?: Array<Record<string, any>>;
141
+ }
142
+ /**
143
+ * @group Props
144
+ */
145
+ export interface PaperComponentProps extends DOMAttributes<HTMLDivElement> {
146
+ /**
147
+ * @internal
148
+ */
149
+ children?: Snippet;
150
+ /**
151
+ * Optional class name to set on the paper component's container
152
+ */
153
+ className?: string;
154
+ /**
155
+ * Render options for the Paper.
156
+ */
157
+ renderOptions?: SveltePaperRenderOptions;
158
+ /**
159
+ * View options for the Paper.
160
+ */
161
+ viewOptions?: SveltePaperViewOptions;
162
+ /**
163
+ * Options for the underlying model instance.
164
+ */
165
+ modelOptions?: ModelOptions;
166
+ /**
167
+ * Optional Visually JS instance to use. If this is not provided, a Visually JS instance will be created, with `modelOptions` if you provide them.
168
+ */
169
+ model?: BrowserUIModel;
170
+ /**
171
+ * Optional function that is used to generate a set of props for a given vertex before rendering it. This provides a mechanism for you to inject specific items into the components you use to render your vertices. The return value of this function should be `Record<string, any>`. It may be null.
172
+ */
173
+ injector?: (v: Vertex) => Record<string, any>;
174
+ /**
175
+ * Optional data to load after the component has been mounted.
176
+ */
177
+ data?: any;
178
+ /**
179
+ * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
180
+ */
181
+ url?: string;
182
+ /**
183
+ * Shape library to use to render SVG shapes. Optional.
184
+ */
185
+ shapeLibrary?: ShapeLibraryImpl<ObjectData>;
112
186
  }
113
187
  /**
114
188
  * @group Props
@@ -282,17 +356,13 @@ export interface InspectorComponentProps extends DOMAttributes<HTMLDivElement> {
282
356
  * Optional class name to set on the component's root element.
283
357
  */
284
358
  className?: string;
285
- /**
286
- * Callback invoked when the inspector is cleared.
287
- * @internal
288
- */
289
- renderEmptyContainer: () => void;
290
359
  /**
291
360
  * Callback invoked when a new object has started to be edited.
292
361
  * @param obj
293
362
  * @param cb
363
+ * @deprecated From 1.2.0 onwards, use the `current` state object approach instead.
294
364
  */
295
- refresh: (obj: Base) => void;
365
+ refresh?: (obj: Base) => void;
296
366
  /**
297
367
  * Optional filter function that you can supply if you want to ignore certain objects in your dataset.
298
368
  */
@@ -306,6 +376,12 @@ export interface InspectorComponentProps extends DOMAttributes<HTMLDivElement> {
306
376
  * Whether or not to auto commit changes on blur or enter keypress. Defaults to true.
307
377
  */
308
378
  autoCommit?: boolean;
379
+ /**
380
+ * A $state ref that the inspector will apply 2-way binding to. Since 1.2.0 this is the preferred way to use an inspector, as it reduces the amount of boilerplate you need to configure.
381
+ * @since 1.2.0
382
+ */
383
+ current?: Base | null;
384
+ children?: Snippet;
309
385
  }
310
386
  /**
311
387
  * @group Props
@@ -478,256 +554,10 @@ export interface DiagramComponentProps extends DOMAttributes<HTMLDivElement> {
478
554
  * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
479
555
  */
480
556
  url?: string;
481
- }
482
- /**
483
- * @group Props
484
- */
485
- export interface ColumnChartComponentProps extends DOMAttributes<HTMLDivElement> {
486
- /**
487
- * Options for the chart
488
- */
489
- options: Omit<ColumnChartOptions, "data" | "url" | "model">;
490
- /**
491
- * Optional class name to set on the chart component's container
492
- */
493
- className?: string;
494
- /**
495
- * Optional data to load after the chart has been mounted.
496
- */
497
- data?: Array<ObjectData>;
498
- /**
499
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
500
- */
501
- url?: string;
502
- /**
503
- * Optional filter to apply to the data source.
504
- */
505
- dataSourceFilter?: ChartModelFilter;
506
- }
507
- /**
508
- * @group Props
509
- */
510
- export interface BarChartComponentProps extends DOMAttributes<HTMLDivElement> {
511
- /**
512
- * Options for the chart
513
- */
514
- options: Omit<BarChartOptions, "data" | "url" | "model">;
515
- /**
516
- * Optional class name to set on the chart component's container
517
- */
518
- className?: string;
519
- /**
520
- * Optional data to load after the chart has been mounted.
521
- */
522
- data?: Array<ObjectData>;
523
- /**
524
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
525
- */
526
- url?: string;
527
- /**
528
- * Optional filter to apply to the data source.
529
- */
530
- dataSourceFilter?: ChartModelFilter;
531
- }
532
- /**
533
- * @group Props
534
- */
535
- export interface XYChartComponentProps extends DOMAttributes<HTMLDivElement> {
536
- /**
537
- * Options for the chart
538
- */
539
- options: Omit<CategoryValueChartOptions, "data" | "url" | "model">;
540
- /**
541
- * Optional class name to set on the chart component's container
542
- */
543
- className?: string;
544
- /**
545
- * Optional data to load after the chart has been mounted.
546
- */
547
- data?: Array<ObjectData>;
548
- /**
549
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
550
- */
551
- url?: string;
552
- }
553
- /**
554
- * @group Props
555
- */
556
- export interface LineChartComponentProps extends DOMAttributes<HTMLDivElement> {
557
- /**
558
- * Options for the chart
559
- */
560
- options: Omit<LineChartOptions, "data" | "url" | "model">;
561
- /**
562
- * Optional class name to set on the chart component's container
563
- */
564
- className?: string;
565
- /**
566
- * Optional data to load after the chart has been mounted.
567
- */
568
- data?: Array<ObjectData>;
569
- /**
570
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
571
- */
572
- url?: string;
573
- /**
574
- * Optional filter to apply to the data source.
575
- */
576
- dataSourceFilter?: ChartModelFilter;
577
- }
578
- /**
579
- * @group Props
580
- */
581
- export interface AreaChartComponentProps extends DOMAttributes<HTMLDivElement> {
582
- /**
583
- * Options for the chart
584
- */
585
- options: Omit<AreaChartOptions, "data" | "url" | "model">;
586
- /**
587
- * Optional class name to set on the chart component's container
588
- */
589
- className?: string;
590
- /**
591
- * Optional data to load after the chart has been mounted.
592
- */
593
- data?: Array<ObjectData>;
594
- /**
595
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
596
- */
597
- url?: string;
598
- /**
599
- * Optional filter to apply to the data source.
600
- */
601
- dataSourceFilter?: ChartModelFilter;
602
- }
603
- /**
604
- * @group Props
605
- */
606
- export interface PieChartComponentProps extends DOMAttributes<HTMLDivElement> {
607
- /**
608
- * Options for the chart
609
- */
610
- options: Omit<PieChartOptions, "data" | "url" | "model">;
611
- /**
612
- * Optional class name to set on the chart component's container
613
- */
614
- className?: string;
615
- /**
616
- * Optional data to load after the chart has been mounted.
617
- */
618
- data?: Array<ObjectData>;
619
- /**
620
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
621
- */
622
- url?: string;
623
- /**
624
- * Optional filter to apply to the data source.
625
- */
626
- dataSourceFilter?: ChartModelFilter;
627
- }
628
- /**
629
- * @group Props
630
- */
631
- export interface ScatterChartComponentProps extends DOMAttributes<HTMLDivElement> {
632
- /**
633
- * Options for the chart
634
- */
635
- options: Omit<ScatterChartOptions, "data" | "url" | "model">;
636
- /**
637
- * Optional class name to set on the chart component's container
638
- */
639
- className?: string;
640
- /**
641
- * Optional data to load after the chart has been mounted.
642
- */
643
- data?: Array<ObjectData>;
644
- /**
645
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
646
- */
647
- url?: string;
648
- /**
649
- * Optional filter to apply to the data source.
650
- */
651
- dataSourceFilter?: ChartModelFilter;
652
- }
653
- /**
654
- * @group Props
655
- */
656
- export interface BubbleChartComponentProps extends DOMAttributes<HTMLDivElement> {
657
- /**
658
- * Options for the chart
659
- */
660
- options: Omit<BubbleChartOptions, "data" | "url" | "model">;
661
- /**
662
- * Optional class name to set on the chart component's container
663
- */
664
- className?: string;
665
- /**
666
- * Optional data to load after the chart has been mounted.
667
- */
668
- data?: Array<ObjectData>;
669
- /**
670
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
671
- */
672
- url?: string;
673
- /**
674
- * Optional filter to apply to the data source.
675
- */
676
- dataSourceFilter?: ChartModelFilter;
677
- }
678
- /**
679
- * @group Props
680
- */
681
- export interface GaugeChartComponentProps extends DOMAttributes<HTMLDivElement> {
682
557
  /**
683
- * Options for the chart
684
- */
685
- options: Omit<GaugeChartOptions, "data" | "url" | "model">;
686
- /**
687
- * Optional class name to set on the chart component's container
688
- */
689
- className?: string;
690
- /**
691
- * Optional data to load after the chart has been mounted.
692
- */
693
- data?: Array<ObjectData>;
694
- /**
695
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
696
- */
697
- url?: string;
698
- }
699
- /**
700
- * @group Props
701
- */
702
- export interface SankeyChartComponentProps extends DOMAttributes<HTMLDivElement> {
703
- /**
704
- * Options for the chart
705
- */
706
- options: Omit<SankeyOptions, "data" | "url" | "model">;
707
- /**
708
- * Optional class name to set on the chart component's container
709
- */
710
- className?: string;
711
- /**
712
- * Optional data to load into the chart (in CSV format)
713
- */
714
- csvData?: string;
715
- /**
716
- * Optional data to load into the chart (in VisuallyJs default json format)
717
- */
718
- jsonData?: VisuallyJsDefaultJSON;
719
- /**
720
- * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
721
- */
722
- url?: string;
723
- /**
724
- * Whether the chart is interactive.
725
- */
726
- interactive?: boolean;
727
- /**
728
- * Optional property to pivot the sankey chart on.
558
+ * @internal
729
559
  */
730
- pivot?: string;
560
+ children?: Snippet;
731
561
  }
732
562
  /**
733
563
  * Props for the diagram palette.
@@ -846,4 +676,26 @@ export interface DecoratorComponentProps extends DOMAttributes<HTMLDivElement> {
846
676
  * Optional constraints when using fixed placement.
847
677
  */
848
678
  constraints?: FixedElementConstraints;
679
+ /**
680
+ * @internal
681
+ */
682
+ children?: Snippet;
683
+ }
684
+ /**
685
+ * Props for the SurfacePopup component.
686
+ * @group Props
687
+ */
688
+ export interface SurfacePopupProps {
689
+ /**
690
+ * CSS3 selector identifying elements from which this popup is launched.
691
+ */
692
+ selector: string;
693
+ /**
694
+ * Optional position to place this popup. Defaults to "bottom", and can also be overridden on a per-launcher basis via a DOM attribute.
695
+ */
696
+ anchor?: PopupPosition;
697
+ /**
698
+ * The snippet that renders the content for the popup.
699
+ */
700
+ popup: Snippet<[Vertex | null, BrowserUIModel, BrowserUI]>;
849
701
  }
@@ -23,8 +23,3 @@ export declare function internal_createDiagramContext(): DiagramRef;
23
23
  * @internal
24
24
  */
25
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>;
package/diagram-store.js CHANGED
@@ -41,18 +41,3 @@ export function internal_getDiagramContext(doNotCreate) {
41
41
  }
42
42
  return ctx;
43
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 CHANGED
@@ -11,7 +11,11 @@ export * from './diagram-store';
11
11
  export * from './surface-store';
12
12
  export * from './inspector-store';
13
13
  export * from './definitions';
14
+ export * from './charts/definitions';
14
15
  export * from './use-zoom.svelte';
16
+ export * from './use-surface.svelte';
17
+ export * from './use-diagram.svelte';
18
+ export * from './use-visuallyjs-update.svelte';
15
19
  import { BrowserElement, BrowserUIModel, BrowserUIOptions, TemplateRenderer, ModelOptions } from "@visuallyjs/browser-ui";
16
20
  /**
17
21
  * Extension of VisuallyJsModel suitable for use with the Svelte integration.
package/index.js CHANGED
@@ -11,7 +11,11 @@ export * from './diagram-store';
11
11
  export * from './surface-store';
12
12
  export * from './inspector-store';
13
13
  export * from './definitions';
14
+ export * from './charts/definitions';
14
15
  export * from './use-zoom.svelte';
16
+ export * from './use-surface.svelte';
17
+ export * from './use-diagram.svelte';
18
+ export * from './use-visuallyjs-update.svelte';
15
19
  import { BrowserUIModel, log } from "@visuallyjs/browser-ui";
16
20
  /**
17
21
  * Extension of VisuallyJsModel suitable for use with the Svelte integration.
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@visuallyjs/browser-ui-svelte","version":"1.1.4","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.1.4"},"homepage":"https://visuallyjs.com/svelte","bugs":"https://github.com/visuallyjs/visuallyjs/issues"}
1
+ {"name":"@visuallyjs/browser-ui-svelte","version":"1.2.1","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","PaperComponent.svelte","DecoratorComponent.svelte","DefaultGroupComponent.svelte","DefaultNodeComponent.svelte","MiniviewComponent.svelte","ControlsComponent.svelte","SurfaceProvider.svelte","PaperProvider.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","OverlayWrapperComponent.svelte","DiagramProvider.svelte","DiagramPaletteComponent.svelte","ColorPickerComponent.svelte","ScatterChartComponent.svelte","BubbleChartComponent.svelte","GaugeChartComponent.svelte","SankeyChartComponent.svelte","SurfacePopup.svelte"],"author":"VisuallyJs <hello@visuallyjs.com> (https://visuallyjs.com)","license":"Commercial","dependencies":{"@visuallyjs/browser-ui":"1.2.1"},"homepage":"https://visuallyjs.com/svelte","bugs":"https://github.com/visuallyjs/visuallyjs/issues"}
@@ -1,4 +1,4 @@
1
- import type { Surface } from "@visuallyjs/browser-ui";
1
+ import type { Paper, Surface } from "@visuallyjs/browser-ui";
2
2
  import { BrowserUISvelteModel } from "./index";
3
3
  /**
4
4
  * Key for the surface context
@@ -17,11 +17,24 @@ export interface SurfaceRef {
17
17
  set: (surface: Surface) => void;
18
18
  listen: (l: (s: Surface) => any) => void;
19
19
  }
20
+ /**
21
+ * Handle for a paper - use `set` to set the paper and `listen` to register a listener.
22
+ * @internal
23
+ */
24
+ export interface PaperRef {
25
+ set: (paper: Paper) => void;
26
+ listen: (l: (s: Paper) => any) => void;
27
+ }
20
28
  /**
21
29
  * Create a surface context, and set it on Svelte via `setContext`.
22
30
  * @internal
23
31
  */
24
32
  export declare function internal_createSurfaceContext(): SurfaceRef;
33
+ /**
34
+ * Create a paper context, and set it on Svelte via `setContext`.
35
+ * @internal
36
+ */
37
+ export declare function internal_createPaperContext(): PaperRef;
25
38
  /**
26
39
  * 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
40
  * This method is NOT to be invoked by users of the API. Use {@link useSurface} to access the current Surface.
@@ -30,10 +43,12 @@ export declare function internal_createSurfaceContext(): SurfaceRef;
30
43
  */
31
44
  export declare function internal_getSurfaceContext(doNotCreate: boolean): SurfaceRef;
32
45
  /**
33
- * Hook to expose the current Surface. This hook is asynchronous and returns a Promise.
34
- * @group Hooks
46
+ * Gets the current paper context from Svelte, optionally creating it if it does not exist. The Paper and the PaperProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
47
+ * This method is NOT to be invoked by users of the API. Use {@link usePaper} to access the current Paper.
48
+ * @param doNotCreate
49
+ * @internal
35
50
  */
36
- export declare function useSurface(): Promise<Surface>;
51
+ export declare function internal_getPaperContext(doNotCreate: boolean): PaperRef;
37
52
  /**
38
53
  * Hook to expose the current model. This hook is asynchronous and returns a Promise.
39
54
  * @group Hooks
package/surface-store.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { getContext, setContext } from "svelte";
2
+ import { internal_getDiagramContext } from "./index";
2
3
  /**
3
4
  * Key for the surface context
4
5
  * @internal
@@ -28,6 +29,30 @@ export function internal_createSurfaceContext() {
28
29
  setContext(STORE_KEY, ref);
29
30
  return ref;
30
31
  }
32
+ /**
33
+ * Create a paper context, and set it on Svelte via `setContext`.
34
+ * @internal
35
+ */
36
+ export function internal_createPaperContext() {
37
+ const listeners = [];
38
+ const handle = { current: null };
39
+ const ref = {
40
+ set: (paper) => {
41
+ handle.current = paper;
42
+ listeners.forEach(l => l(paper));
43
+ },
44
+ listen: (l) => {
45
+ if (handle.current == null) {
46
+ listeners.push(l);
47
+ }
48
+ else {
49
+ l(handle.current);
50
+ }
51
+ }
52
+ };
53
+ setContext(STORE_KEY, ref);
54
+ return ref;
55
+ }
31
56
  /**
32
57
  * 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
58
  * This method is NOT to be invoked by users of the API. Use {@link useSurface} to access the current Surface.
@@ -42,19 +67,17 @@ export function internal_getSurfaceContext(doNotCreate) {
42
67
  return ctx;
43
68
  }
44
69
  /**
45
- * Hook to expose the current Surface. This hook is asynchronous and returns a Promise.
46
- * @group Hooks
70
+ * Gets the current paper context from Svelte, optionally creating it if it does not exist. The Paper and the PaperProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
71
+ * This method is NOT to be invoked by users of the API. Use {@link usePaper} to access the current Paper.
72
+ * @param doNotCreate
73
+ * @internal
47
74
  */
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
- });
75
+ export function internal_getPaperContext(doNotCreate) {
76
+ let ctx = getContext(STORE_KEY);
77
+ if (ctx == null && !doNotCreate) {
78
+ ctx = internal_createPaperContext();
79
+ }
80
+ return ctx;
58
81
  }
59
82
  /**
60
83
  * Hook to expose the current model. This hook is asynchronous and returns a Promise.
@@ -62,10 +85,18 @@ export function useSurface() {
62
85
  */
63
86
  export function useVisuallyJsModel() {
64
87
  const ref = internal_getSurfaceContext(true);
88
+ const paperRef = internal_getPaperContext(true);
89
+ const diagramRef = internal_getDiagramContext(true);
65
90
  return new Promise((resolve, reject) => {
66
91
  if (ref != null) {
67
92
  ref.listen((s) => resolve(s.model));
68
93
  }
94
+ else if (paperRef != null) {
95
+ paperRef.listen((s) => resolve(s.model));
96
+ }
97
+ else if (diagramRef != null) {
98
+ diagramRef.listen((d) => resolve(d.model));
99
+ }
69
100
  else {
70
101
  reject();
71
102
  }
@@ -0,0 +1,8 @@
1
+ import { Diagram } from '@visuallyjs/browser-ui';
2
+ /**
3
+ *
4
+ * @group Hooks
5
+ */
6
+ export declare function useDiagram(): {
7
+ readonly current: Diagram | null;
8
+ };
@@ -0,0 +1,18 @@
1
+ import { internal_getDiagramContext } from "./diagram-store";
2
+ /**
3
+ *
4
+ * @group Hooks
5
+ */
6
+ export function useDiagram() {
7
+ const ctx = internal_getDiagramContext(true);
8
+ let diagram = $state(null);
9
+ if (ctx != null) {
10
+ ctx.listen((s) => diagram = s);
11
+ }
12
+ // Return an object with a getter to maintain reactivity across function boundaries
13
+ return {
14
+ get current() {
15
+ return diagram;
16
+ }
17
+ };
18
+ }
@@ -0,0 +1,7 @@
1
+ import { Surface } from '@visuallyjs/browser-ui';
2
+ import { RefObject } from "./definitions";
3
+ /**
4
+ * Creates a reactive zoom state for a VisuallyJS UI
5
+ * @group Hooks
6
+ */
7
+ export declare function useSurface(): RefObject<Surface>;