@visuallyjs/browser-ui-svelte 1.1.4 → 1.2.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.
- package/AreaChartComponent.svelte +24 -15
- package/BarChartComponent.svelte +24 -12
- package/BubbleChartComponent.svelte +23 -11
- 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/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/PaletteComponent.svelte +28 -41
- package/PieChartComponent.svelte +23 -8
- package/SankeyChartComponent.svelte +35 -14
- package/ScatterChartComponent.svelte +23 -11
- package/ShapePaletteComponent.svelte +11 -22
- package/SurfaceProvider.svelte +3 -1
- package/XYChartComponent.svelte +33 -12
- package/charts/definitions.d.ts +119 -0
- package/charts/definitions.js +1 -0
- package/definitions.d.ts +22 -256
- 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 +0 -5
- package/surface-store.js +5 -15
- 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
package/definitions.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 } 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
|
*/
|
|
@@ -33,6 +33,12 @@ export interface SveltePortMapping extends Omit<PortMapping<any>, "templateIdRes
|
|
|
33
33
|
*/
|
|
34
34
|
component?: any;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Defines a value holder. This is a direct copy of the `RefObject` concept from React.
|
|
38
|
+
*/
|
|
39
|
+
export type RefObject<T> = {
|
|
40
|
+
current: T | null;
|
|
41
|
+
};
|
|
36
42
|
/**
|
|
37
43
|
* Spec for a react component overlay. A ctx object is passed in to your component and you are expected to return JSX.
|
|
38
44
|
*/
|
|
@@ -282,17 +288,13 @@ export interface InspectorComponentProps extends DOMAttributes<HTMLDivElement> {
|
|
|
282
288
|
* Optional class name to set on the component's root element.
|
|
283
289
|
*/
|
|
284
290
|
className?: string;
|
|
285
|
-
/**
|
|
286
|
-
* Callback invoked when the inspector is cleared.
|
|
287
|
-
* @internal
|
|
288
|
-
*/
|
|
289
|
-
renderEmptyContainer: () => void;
|
|
290
291
|
/**
|
|
291
292
|
* Callback invoked when a new object has started to be edited.
|
|
292
293
|
* @param obj
|
|
293
294
|
* @param cb
|
|
295
|
+
* @deprecated From 1.2.0 onwards, use the `current` state object approach instead.
|
|
294
296
|
*/
|
|
295
|
-
refresh
|
|
297
|
+
refresh?: (obj: Base) => void;
|
|
296
298
|
/**
|
|
297
299
|
* Optional filter function that you can supply if you want to ignore certain objects in your dataset.
|
|
298
300
|
*/
|
|
@@ -306,6 +308,12 @@ export interface InspectorComponentProps extends DOMAttributes<HTMLDivElement> {
|
|
|
306
308
|
* Whether or not to auto commit changes on blur or enter keypress. Defaults to true.
|
|
307
309
|
*/
|
|
308
310
|
autoCommit?: boolean;
|
|
311
|
+
/**
|
|
312
|
+
* 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.
|
|
313
|
+
* @since 1.2.0
|
|
314
|
+
*/
|
|
315
|
+
current?: Base | null;
|
|
316
|
+
children?: Snippet;
|
|
309
317
|
}
|
|
310
318
|
/**
|
|
311
319
|
* @group Props
|
|
@@ -478,256 +486,10 @@ export interface DiagramComponentProps extends DOMAttributes<HTMLDivElement> {
|
|
|
478
486
|
* 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
487
|
*/
|
|
480
488
|
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
|
-
/**
|
|
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
489
|
/**
|
|
724
|
-
*
|
|
725
|
-
*/
|
|
726
|
-
interactive?: boolean;
|
|
727
|
-
/**
|
|
728
|
-
* Optional property to pivot the sankey chart on.
|
|
490
|
+
* @internal
|
|
729
491
|
*/
|
|
730
|
-
|
|
492
|
+
children?: Snippet;
|
|
731
493
|
}
|
|
732
494
|
/**
|
|
733
495
|
* Props for the diagram palette.
|
|
@@ -846,4 +608,8 @@ export interface DecoratorComponentProps extends DOMAttributes<HTMLDivElement> {
|
|
|
846
608
|
* Optional constraints when using fixed placement.
|
|
847
609
|
*/
|
|
848
610
|
constraints?: FixedElementConstraints;
|
|
611
|
+
/**
|
|
612
|
+
* @internal
|
|
613
|
+
*/
|
|
614
|
+
children?: Snippet;
|
|
849
615
|
}
|
package/diagram-store.d.ts
CHANGED
|
@@ -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
|
+
{"name":"@visuallyjs/browser-ui-svelte","version":"1.2.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.2.0"},"homepage":"https://visuallyjs.com/svelte","bugs":"https://github.com/visuallyjs/visuallyjs/issues"}
|
package/surface-store.d.ts
CHANGED
|
@@ -29,11 +29,6 @@ export declare function internal_createSurfaceContext(): SurfaceRef;
|
|
|
29
29
|
* @internal
|
|
30
30
|
*/
|
|
31
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
32
|
/**
|
|
38
33
|
* Hook to expose the current model. This hook is asynchronous and returns a Promise.
|
|
39
34
|
* @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
|
|
@@ -41,31 +42,20 @@ export function internal_getSurfaceContext(doNotCreate) {
|
|
|
41
42
|
}
|
|
42
43
|
return ctx;
|
|
43
44
|
}
|
|
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
45
|
/**
|
|
60
46
|
* Hook to expose the current model. This hook is asynchronous and returns a Promise.
|
|
61
47
|
* @group Hooks
|
|
62
48
|
*/
|
|
63
49
|
export function useVisuallyJsModel() {
|
|
64
50
|
const ref = internal_getSurfaceContext(true);
|
|
51
|
+
const diagramRef = internal_getDiagramContext(true);
|
|
65
52
|
return new Promise((resolve, reject) => {
|
|
66
53
|
if (ref != null) {
|
|
67
54
|
ref.listen((s) => resolve(s.model));
|
|
68
55
|
}
|
|
56
|
+
else if (diagramRef != null) {
|
|
57
|
+
diagramRef.listen((d) => resolve(d.model));
|
|
58
|
+
}
|
|
69
59
|
else {
|
|
70
60
|
reject();
|
|
71
61
|
}
|
|
@@ -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,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 {
|