@visuallyjs/browser-ui-react 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.
@@ -0,0 +1,84 @@
1
+ import React, { Context, MutableRefObject, ReactElement, ReactNode } from 'react';
2
+ import { Diagram, DiagramOptions } from "@visuallyjs/browser-ui";
3
+ import { RefHandle } from "./definitions";
4
+ import { ModelOptions } from "@visuallyjs/browser-ui/types/core";
5
+ /**
6
+ * @internal
7
+ */
8
+ export declare const DiagramContext: Context<DiagramRef>;
9
+ /**
10
+ * Handle for a reference to a mutable ref object which holds a diagram. See implementation below.
11
+ * @internal
12
+ */
13
+ export interface DiagramRef extends RefHandle<Diagram> {
14
+ }
15
+ /**
16
+ * Implementation of the DiagramRef handler. The `set` method sets the ref object's value and then propagates the diagram to all registered listeners. The `listen` method either queues a listener, if the handle is not yet ready, or calls back the listener immediately, if the handle is already populated with a surface. The `_ref` method provides access to the underlying mutable ref object; the DiagramComponent uses this when it is created inside a DiagramProvider. None of this
17
+ * code is public facing.
18
+ * @param ref
19
+ * @internal
20
+ */
21
+ export declare function createDiagramRef(ref: MutableRefObject<Diagram>): DiagramRef;
22
+ /**
23
+ * Provider for a Diagram. You can use this at some high level in your UI - some common parent component between the parent of where you want to put a Diagram and where you want to put some other component such as miniview, controls or DiagramPalette . Whenever a `DiagramComponent` is declared as a descendant of this provider, the provider's underlying diagram is set and this is propagated to all the other components using this context. To use this you just declare a DiagramProvider element and put some children inside of it.
24
+ *
25
+ * @group Providers
26
+ */
27
+ export declare function DiagramProvider(props: {
28
+ children?: Array<ReactNode | ReactElement<any, any>> | ReactNode | ReactElement<any, any>;
29
+ }): JSX.Element;
30
+ /**
31
+ * Hook to expose the current Diagram. This hook is asynchronous and returns a Promise.
32
+ * @group Hooks
33
+ */
34
+ export declare function useDiagram(): Promise<Diagram>;
35
+ /**
36
+ * Handle for a DiagramComponent.
37
+ * @group Handles
38
+ */
39
+ export interface DiagramComponentRef {
40
+ /**
41
+ * Gets the underlying Diagram from UI core.
42
+ */
43
+ getDiagram: () => Diagram;
44
+ }
45
+ /**
46
+ * Props for the {@link DiagramComponent}
47
+ * @group Props
48
+ */
49
+ export interface DiagramComponentProps {
50
+ /**
51
+ * Optional class name to set on the container
52
+ */
53
+ className?: string;
54
+ /**
55
+ * Options for the underlying model
56
+ */
57
+ modelOptions?: ModelOptions;
58
+ /**
59
+ * Options for the Diagram
60
+ */
61
+ options?: DiagramOptions;
62
+ /**
63
+ * Optional initial data
64
+ */
65
+ data?: any;
66
+ /**
67
+ * Optional URL to load initial data from.
68
+ */
69
+ url?: string;
70
+ /**
71
+ * You do not pass this prop yourself; React constructs this prop from any elements that are children of the diagram component element in the JSX.
72
+ * @internal
73
+ */
74
+ children?: Array<ReactNode | ReactElement<any, any>> | ReactNode | ReactElement<any, any>;
75
+ /**
76
+ * Optional style object to apply to the container element.
77
+ */
78
+ style?: Record<string, string>;
79
+ }
80
+ /**
81
+ * Provides an SVG diagram that renders nodes and groups from a shape library.
82
+ * @group Components
83
+ */
84
+ export declare const DiagramComponent: React.ForwardRefExoticComponent<DiagramComponentProps & React.RefAttributes<DiagramComponentRef>>;
@@ -0,0 +1,94 @@
1
+ import React from "react";
2
+ import { Diagram, DiagramCell, Size, PaletteMode, OnVertexAddedCallback, PreparedShape } from "@visuallyjs/browser-ui";
3
+ /**
4
+ * Options for a palette for a diagram.
5
+ * @group Props
6
+ */
7
+ export interface DiagramPaletteComponentProps {
8
+ /**
9
+ * Optional fill color to use for dragged elements. This should be in RGB format, _not_ a color like 'white' or 'cyan' etc.
10
+ */
11
+ fill?: string;
12
+ /**
13
+ * Optional color to use for outline of dragged elements. Should be in RGB format.
14
+ */
15
+ outline?: string;
16
+ /**
17
+ * Optional size to use for dragged elements.
18
+ */
19
+ dragSize?: Size;
20
+ /**
21
+ * Indicates that when one or more vertices are selected, clicking on an entry in the palette will change the type of the selected vertices to that type. Defaults to true.
22
+ */
23
+ inspector?: boolean;
24
+ /**
25
+ * Optional size to use for icons. Defaults to 150x100 pixels. If you provide this but not `dragSize` this size will also be used for an icon that is being dragged.
26
+ */
27
+ iconSize?: Size;
28
+ /**
29
+ * Optionally show each shape icon's label underneath it
30
+ */
31
+ showLabels?: boolean;
32
+ /**
33
+ * Stroke width to use for shapes in palette. Defaults to 1.
34
+ */
35
+ paletteStrokeWidth?: number;
36
+ /**
37
+ * Message to use for the 'show all' option in the shape set drop down when there is more than one set of shapes. Defaults to `Show all`.
38
+ */
39
+ showAllMessage?: string;
40
+ /**
41
+ * Callback to invoke when a new diagram cell has been added.
42
+ * @param dc
43
+ */
44
+ onCellAdded?: (dc: DiagramCell) => any;
45
+ /**
46
+ * Mode to operate in - 'drag' or 'tap'. Defaults to 'drag' (PALETTE_MODE_DRAG).
47
+ */
48
+ mode?: PaletteMode;
49
+ /**
50
+ * When in tap mode, allow addition of new vertices simply by clicking, instead of requiring a shape be drawn. (When this is true, the drawing method also still works)
51
+ */
52
+ allowClickToAdd?: boolean;
53
+ /**
54
+ * Defaults to true: when in 'tap' mode and a new group/node has been drawn on the canvas, the UI is set back to pan mode.
55
+ */
56
+ autoExitDrawMode?: boolean;
57
+ /**
58
+ * When true (which is the default), a newly dropped shape will be set as the underlying model's selection.
59
+ */
60
+ selectAfterAdd?: boolean;
61
+ /**
62
+ * Optional diagram to attach to. In most cases it is better to use a DiagramProvider to provision the diagram to this component.
63
+ */
64
+ diagram?: Diagram;
65
+ /**
66
+ * Optional class name to set on the diagram palette root element.
67
+ */
68
+ className?: string;
69
+ /**
70
+ * Optional style object to apply to the container element.
71
+ */
72
+ style?: Record<string, string>;
73
+ /**
74
+ * Optional callback that will be invoked after a new vertex has been dropped and added to the dataset.
75
+ * @param v
76
+ */
77
+ onVertexAdded?: OnVertexAddedCallback;
78
+ /**
79
+ * Optional set of prepared shapes to show in the palette. When this is provided, the palette will only render these shapes, and not the contents of the shape library.
80
+ */
81
+ preparedShapes?: Array<PreparedShape>;
82
+ }
83
+ /**
84
+ * Ref handle for a {@link DiagramPaletteComponent}
85
+ * @group Handles
86
+ */
87
+ export interface DiagramPaletteRef {
88
+ }
89
+ /**
90
+ * A palette that renders the shape library in use by a Diagram.
91
+ *
92
+ * @group Components
93
+ */
94
+ export declare const DiagramPaletteComponent: React.ForwardRefExoticComponent<DiagramPaletteComponentProps & React.RefAttributes<DiagramPaletteRef>>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Props for the EdgeTypePickerComponent
3
+ * @group Props
4
+ */
5
+ export interface EdgeTypePickerComponentProps {
6
+ /**
7
+ * Name of the property to get/set in the edge data
8
+ */
9
+ propertyName: string;
10
+ }
11
+ /**
12
+ * A component that provides a picker for edge types.
13
+ * @group Components
14
+ */
15
+ export declare function EdgeTypePickerComponent(props: EdgeTypePickerComponentProps): JSX.Element;
@@ -0,0 +1,50 @@
1
+ import { SvgExportUIOptions, ImageExportUIOptions, PointXY } from "@visuallyjs/browser-ui";
2
+ /**
3
+ * Options for the ExportControlsComponent
4
+ * @group Props
5
+ */
6
+ export interface ExportControlsComponentProps {
7
+ /**
8
+ * The ID of surface to attach to. Optional. The component is context aware and will try to resolve the Surface/Paper
9
+ * to attach to from an ancestor {@link SurfaceProvider} {@link SurfaceComponent} or {@link PaperComponent}.
10
+ */
11
+ surfaceId?: string;
12
+ /**
13
+ * Whether or not to show a label in front of the buttons. Defaults to true.
14
+ */
15
+ showLabel?: boolean;
16
+ /**
17
+ * What to show in the label, if visible. Defaults to "Export:".
18
+ */
19
+ label?: string;
20
+ /**
21
+ * Optional margins to apply to both SVG and image exports. Will not override any margins specified in svgOptions or imageOptions.
22
+ */
23
+ margins?: PointXY;
24
+ /**
25
+ * Options for SVG exports.
26
+ */
27
+ svgOptions?: SvgExportUIOptions;
28
+ /**
29
+ * Options for image exports.
30
+ */
31
+ imageOptions?: ImageExportUIOptions;
32
+ /**
33
+ * Defaults to true.
34
+ */
35
+ allowSvgExport?: boolean;
36
+ /**
37
+ * Defaults to true.
38
+ */
39
+ allowPngExport?: boolean;
40
+ /**
41
+ * Defaults to true.
42
+ */
43
+ allowJpgExport?: boolean;
44
+ }
45
+ /**
46
+ * Provides export svg/png/jpg buttons. This component is context aware and by default will locate the surface/paper to
47
+ * attach to from an ancestor {@link SurfaceProvider} {@link SurfaceComponent} or {@link PaperComponent}.
48
+ * @group Components
49
+ */
50
+ export declare function ExportControlsComponent(props: ExportControlsComponentProps): JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { SurfaceComponentRef } from "./definitions";
2
+ /**
3
+ * @internal
4
+ */
5
+ export type SurfaceComponentRefCallback = (s: SurfaceComponentRef) => any;
6
+ /**
7
+ * @internal
8
+ * @param id
9
+ * @param ref
10
+ */
11
+ export declare function registerSurface(id: string, ref: SurfaceComponentRef): void;
12
+ /**
13
+ * Accessor for globally registered surfaces
14
+ * @internal
15
+ * @param id
16
+ * @param cb
17
+ */
18
+ export declare function getSurfaceComponent(id: string, cb: SurfaceComponentRefCallback): void;
package/index.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Provides integration with React (17+). This package has a dependency on @visuallyjs/browser-ui.
3
+ *
4
+ * For a detailed discussion of this package, see https://visuallyjs.com/react.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export * from './global-context';
9
+ export * from './definitions';
10
+ export * from './jsx-wrapper';
11
+ export * from './browser-ui-react';
12
+ export * from './edge-type-picker';
13
+ export * from './surface-component';
14
+ export * from './miniview-component';
15
+ export * from './inspector-component';
16
+ export * from './controls-component';
17
+ export * from './export-controls-component';
18
+ export * from './shape-palette-component';
19
+ export * from './shape-component';
20
+ export * from './palette-component';
21
+ export * from './color-picker-component';
22
+ export * from './visuallyjs-context';
23
+ export * from './surface-context';
24
+ export * from './inspector-context';
25
+ export * from './diagram-component';
26
+ export * from './diagram-palette-component';
27
+ export * from './chart-component';
28
+ export * from './decorator-component';
29
+ export * from './background-component';
@@ -0,0 +1,72 @@
1
+ import { Base, Inspector, Surface, VisuallyJsModel } from "@visuallyjs/browser-ui";
2
+ import React, { ReactNode } from "react";
3
+ /**
4
+ * Props for the InspectorComponent
5
+ * @group Props
6
+ */
7
+ export interface InspectorComponentProps {
8
+ /**
9
+ * Surface to attach to. It is not mandatory that you supply this - the component is context aware and can try to resolve a surface from an ancestor {@link SurfaceProvider} {@link SurfaceComponent} or {@link PaperComponent}.
10
+ */
11
+ surface?: Surface;
12
+ /**
13
+ * Child elements. Internal.
14
+ * @internal
15
+ */
16
+ children?: Array<ReactNode> | ReactNode | ((obj: Base, model: VisuallyJsModel) => Array<ReactNode> | ReactNode);
17
+ /**
18
+ * Whether or not to auto commit on enter keypress/blur. Defaults to true.
19
+ */
20
+ autoCommit?: boolean;
21
+ /**
22
+ * Whether or not to support multiple selections. Defaults to true.
23
+ */
24
+ multipleSelections?: boolean;
25
+ /**
26
+ * Optional filter you can use to instruct the inspector to ignore certain items.
27
+ * @param b The object to test
28
+ */
29
+ filter?: (b: Base) => boolean;
30
+ /**
31
+ * Callback invoked when the inspector is cleared. You need to provide this if the child content you provide to the Inspector is not a function.
32
+ * @internal
33
+ */
34
+ onSelectionCleared?: () => void;
35
+ /**
36
+ * Callback invoked when a new object has started to be edited. You need to provide this if the child content you provide to the Inspector is not a function.
37
+ * @param obj
38
+ * @param cb
39
+ */
40
+ refresh?: (obj: Base) => void;
41
+ /**
42
+ * Optional extra css classes to set on the root element
43
+ */
44
+ className?: string;
45
+ /**
46
+ * Whether or not to show a close button. Defaults to false.
47
+ */
48
+ showCloseButton?: boolean;
49
+ /**
50
+ * Optional function to invoke after an update.
51
+ * @param s
52
+ */
53
+ afterUpdate?: (s: Surface) => void;
54
+ /**
55
+ * Optional function that returns JSX to use when nothing is selected
56
+ */
57
+ renderEmptyContent?: () => any;
58
+ target?: any;
59
+ }
60
+ /**
61
+ * Ref handle for an InspectorComponent. Allows access to the underlying inspector, for advanced use cases.
62
+ * @group Handles
63
+ */
64
+ export interface InspectorComponentRef {
65
+ getInspector(): Inspector;
66
+ }
67
+ /**
68
+ * Provides an inspector. This component is context aware and will resolve a surface from an ancestor
69
+ * {@link SurfaceProvider} {@link SurfaceComponent} or {@link PaperComponent}.
70
+ * @group Components
71
+ */
72
+ export declare const InspectorComponent: React.ForwardRefExoticComponent<InspectorComponentProps & React.RefAttributes<InspectorComponentRef>>;
@@ -0,0 +1,25 @@
1
+ import { Context, MutableRefObject } from "react";
2
+ import { RefHandle } from "./definitions";
3
+ import { Inspector } from "@visuallyjs/browser-ui";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare const InspectorContext: Context<InspectorRef>;
8
+ /**
9
+ * Handle for a reference to a mutable ref object which holds an inspector. See implementation below.
10
+ * @internal
11
+ */
12
+ export interface InspectorRef extends RefHandle<Inspector> {
13
+ }
14
+ /**
15
+ * Implementation of the InspectorRef handler. The `set` method sets the ref object's value and then
16
+ * propagates the surface to all registered listeners. The `listen` method either queues a listener, if the handle is not yet
17
+ * ready, or calls back the listener immediately, if the handle is already populated with a surface.
18
+ * @param ref
19
+ * @internal
20
+ */
21
+ export declare function createInspectorRef(ref: MutableRefObject<Inspector>): InspectorRef;
22
+ /**
23
+ * Hook to expose current inspector for components that need one.
24
+ */
25
+ export declare function useInspector(): Inspector;
@@ -0,0 +1,52 @@
1
+ import { ReactNode } from "react";
2
+ import { Base, BrowserUI, BrowserUIModel, ObjectData } from "@visuallyjs/browser-ui";
3
+ /**
4
+ * These are the props that are passed to the `jsx` you provide to map a node, group or overlay component in the `viewOptions` of a {@link SurfaceComponent} or {@link PaperComponent}. VisuallyJs passes in the UI, the model (which you can get from the UI anyway), the object being rendered, the object's data, and any `childProps` that have been configured.
5
+ * @group Props
6
+ */
7
+ export interface JsxWrapperProps<T extends Base> {
8
+ /**
9
+ * The object to be rendered - a Node, Group or Edge.
10
+ */
11
+ obj: T;
12
+ /**
13
+ * The UI that is rendering this object.
14
+ */
15
+ ui: BrowserUI;
16
+ /**
17
+ * Underlying model. Can also be accessed via `ui.model`.
18
+ */
19
+ model: BrowserUIModel;
20
+ /**
21
+ * The object's backing data
22
+ */
23
+ data: ObjectData;
24
+ /**
25
+ * Any extra props configured by the view to present to this JSX.
26
+ */
27
+ props: any;
28
+ }
29
+ /**
30
+ * @internal
31
+ */
32
+ export interface ComponentFacade<T extends Base> {
33
+ def: {
34
+ jsx?: (p: JsxWrapperProps<any>) => ReactNode;
35
+ component?: any;
36
+ };
37
+ obj: T;
38
+ payload?: any;
39
+ }
40
+ /**
41
+ * Placeholder component to render some JSX and inform the UI on load. This is for internal use. In its return value it writes out the JSX provided, as well as, if the `initialized` ref is false, a placeholder element. A useEffect checks to see if `initialized` is not yet true, and if it isn't, the callback provided in the wrapper's props is invoked, passing in the previous element sibling to the placeholder, ie. the JSX that a user provided. After `initialized.current` is set to true, React will at some point re-render the component and flush the placeholder element, because it only gets drawn when initialized is false.
42
+ *
43
+ * @param props
44
+ * @internal
45
+ */
46
+ export declare function JSXWrapper<REP extends ComponentFacade<any>>(props: {
47
+ ns: REP;
48
+ model: BrowserUIModel;
49
+ ui: BrowserUI;
50
+ childProps: any;
51
+ cb: (ns: REP) => any;
52
+ }): JSX.Element;
@@ -0,0 +1,51 @@
1
+ import { Group, Node } from "@visuallyjs/browser-ui";
2
+ import React from "react";
3
+ /**
4
+ * Imperative handle for a miniview component. When you use the miniview component and set a ref:
5
+ *
6
+ * `<MiniviewComponent ref={myRef}/>`
7
+ *
8
+ * Then `myRef` is of type `MiniviewComponentRef`.
9
+ *
10
+ * @group Handles
11
+ */
12
+ export interface MiniviewComponentRef {
13
+ /**
14
+ * Toggle the collapsed state of the miniview.
15
+ */
16
+ toggleCollapsed: () => void;
17
+ }
18
+ /**
19
+ * Props for the MiniviewComponent.
20
+ * @group Props
21
+ */
22
+ export interface MiniviewComponentProps {
23
+ /**
24
+ * Optional filter to decide which elements to show in the miniview.
25
+ * @param obj
26
+ */
27
+ elementFilter?: (obj: Node | Group) => boolean;
28
+ /**
29
+ * Optional function to use to decorate miniview elements with a `vjs-miniview-type` attribute. Can be used for simple styling.
30
+ * @param obj
31
+ */
32
+ typeFunction?: (obj: Node | Group) => string;
33
+ /**
34
+ * Whether or not to move miniview elements at the same time as their related surface element is being dragged. Defaults to true.
35
+ */
36
+ activeTracking?: boolean;
37
+ /**
38
+ * Defaults to true, meaning a click on a node/group in the miniview will cause that node/group to be centered in the related surface.
39
+ */
40
+ clickToCenter?: boolean;
41
+ /**
42
+ * Optional class name to append to the root element's class list.
43
+ */
44
+ className?: string;
45
+ }
46
+ /**
47
+ * Provides a miniview attached to some surface. This component is context aware and will locate the surface to attach
48
+ * to when declared either inside a {@link SurfaceProvider} or as a child element of a {@link SurfaceComponent}.
49
+ * @group Components
50
+ */
51
+ export declare const MiniviewComponent: React.ForwardRefExoticComponent<MiniviewComponentProps & React.RefAttributes<MiniviewComponentRef>>;
package/package.json ADDED
@@ -0,0 +1 @@
1
+ {"name":"@visuallyjs/browser-ui-react","version":"1.0.0","description":"VisuallyJs React for Browser UI renderer","module":"visuallyjs.browser-ui-react.es.js","main":"visuallyjs.browser-ui-react.cjs.js","types":"index.d.ts","files":["visuallyjs.browser-ui-react.es.js","visuallyjs.browser-ui-react.cjs.js","**/*.d.ts"],"author":"VisuallyJs <hello@visuallyjs.com> (https://visuallyjs.com)","license":"Commercial","dependencies":{"@visuallyjs/browser-ui":"1.0.0"}}
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import { PaletteComponentProps, PaletteComponentRef } from "./definitions";
3
+ /**
4
+ * Provides a palette from which new nodes/groups can be dragged onto a surface/paper canvas. This component can function
5
+ * inside a {@link SurfaceContext} - whether provided by a {@link SurfaceComponent}, {@link PaperComponent} or a
6
+ * {@link SurfaceProvider}.
7
+ *
8
+ * @group Components
9
+ *
10
+ */
11
+ export declare const PaletteComponent: React.ForwardRefExoticComponent<PaletteComponentProps & React.RefAttributes<PaletteComponentRef>>;
@@ -0,0 +1,51 @@
1
+ import { JsxWrapperProps } from "./jsx-wrapper";
2
+ import { FontSpec, Vertex } from "@visuallyjs/browser-ui";
3
+ export declare const DEFAULT_SHAPE_WIDTH = 120;
4
+ export declare const DEFAULT_SHAPE_HEIGHT = 90;
5
+ /**
6
+ * Props for a ShapeComponent
7
+ *
8
+ * @group Props
9
+ */
10
+ export interface ShapeComponentProps<T extends Vertex> {
11
+ /**
12
+ * Defaults to false. If true, a label will be written on the shape (using an SVG text element).
13
+ */
14
+ showLabels?: boolean;
15
+ /**
16
+ * The name of the property that identifies some vertex's label. Defaults to "label".
17
+ */
18
+ labelProperty?: string;
19
+ /**
20
+ * Optional stroke width to use for labels. Defaults to "0.25px".
21
+ */
22
+ labelStrokeWidth?: string;
23
+ /**
24
+ * For multiline labels, the proportion of the width of the shape that the longest line can take up.
25
+ */
26
+ labelFillRatio?: number;
27
+ /**
28
+ * Defaults to true - word wrap shape labels so they fit into their shapes
29
+ */
30
+ multilineLabels?: boolean;
31
+ /**
32
+ * Color for the label. Defaults to #000000.
33
+ */
34
+ labelColor?: string;
35
+ /**
36
+ * Context for the vertex, as passed in by the SurfaceComponent.
37
+ */
38
+ ctx: JsxWrapperProps<T>;
39
+ /**
40
+ * Optional font size/style to use for this shape.
41
+ */
42
+ font?: FontSpec;
43
+ }
44
+ /**
45
+ * A component that renders an SVG shape from a shape library. For many SVG use cases you might want to look into
46
+ * using a {@link DiagramComponent} in preference to a {@link SurfaceComponent} or {@link PaperComponent} that renders
47
+ * vertices with a ShapeComponent - take a look through the docs for discussions of the pros and cons of each.
48
+ *
49
+ * @group Components
50
+ */
51
+ export declare function ShapeComponent<T extends Vertex>(props: ShapeComponentProps<T>): JSX.Element;
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { ShapePaletteComponentProps, ShapePaletteComponentRef } from "./definitions";
3
+ /**
4
+ * A palette that renders the contents of a shape library. This component is context aware and can locate a surface to
5
+ * use without you needing to inject one.
6
+ *
7
+ * @group Components
8
+ */
9
+ export declare const ShapePaletteComponent: React.ForwardRefExoticComponent<ShapePaletteComponentProps & React.RefAttributes<ShapePaletteComponentRef>>;
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ import { SurfaceComponentProps, SurfaceComponentRef } from "./definitions";
3
+ /**
4
+ * Provides a pannable and zoomable canvas on which nodes, edges and groups can be drawn, with support for layouts and various plugins.
5
+ * @group Components
6
+ */
7
+ export declare const SurfaceComponent: React.ForwardRefExoticComponent<SurfaceComponentProps & React.RefAttributes<SurfaceComponentRef>>;
@@ -0,0 +1,44 @@
1
+ import { Context, MutableRefObject, ReactNode, ReactElement } from "react";
2
+ import { Surface } from "@visuallyjs/browser-ui";
3
+ import { RefHandle } from "./definitions";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare const SurfaceContext: Context<SurfaceRef>;
8
+ /**
9
+ * Provider for a Surface. You can use this at some high level in your UI - some common parent component between the parent of where you want to put a Surface and where you want to or drag/drop. Whenever a `SurfaceComponent` is declared as a descendant of this provider, the provider's underlying surface is set and this is propagated to all the other components using this context. To use this you just declare a SurfaceProvider element and put some children inside of it
10
+ *
11
+ * @group Providers
12
+ */
13
+ export declare function SurfaceProvider(props: {
14
+ children?: Array<ReactNode | ReactElement<any, any>> | ReactNode | ReactElement<any, any>;
15
+ }): JSX.Element;
16
+ /**
17
+ * Handle for a reference to a mutable ref object which holds a surface. See implementation below.
18
+ * @internal
19
+ */
20
+ export interface SurfaceRef extends RefHandle<Surface> {
21
+ }
22
+ /**
23
+ * Implementation of the SurfaceRef handler. The `set` method sets the ref object's value and then
24
+ * propagates the surface to all registered listeners. The `listen` method either queues a listener, if the handle is not yet
25
+ * ready, or calls back the listener immediately, if the handle is already populated with a surface. The `_ref` method provides access
26
+ * to the underlying mutable ref object; the SurfaceComponent uses this when it is created inside a SurfaceProvider. None of this
27
+ * code is public facing.
28
+ * @param ref
29
+ * @internal
30
+ */
31
+ export declare function createSurfaceRef(ref: MutableRefObject<Surface>): SurfaceRef;
32
+ /**
33
+ * Generic reference handler create routine. This function creates a `RefHandle` for some given type, which is
34
+ * an object with `set` and `listen` methods that you can use inside a context. Visually Js uses this internally for the
35
+ * Surface but we exposed it for usage in some of our demos.
36
+ * @param ref
37
+ * @internal
38
+ */
39
+ export declare function createRefHandler<T, S = Surface>(ref: MutableRefObject<T | null>): RefHandle<T>;
40
+ /**
41
+ * Hook to expose the current Surface. This hook is asynchronous and returns a Promise.
42
+ * @group Hooks
43
+ */
44
+ export declare function useSurface(): Promise<Surface>;
@@ -0,0 +1,22 @@
1
+ import { Context, ReactNode } from "react";
2
+ import { BrowserUIReactModel } from "./browser-ui-react";
3
+ import { ModelOptions } from "@visuallyjs/browser-ui";
4
+ /**
5
+ * Context object for use by the various Visually Js components such as Surface, Miniview, Controls, Inspector, DragDrop. The root value for this context is null: When a SurfaceComponent or PaperComponent is instantiated they check this context and if the value is null, they set a model instance for this context, which miniview/control/inspector components can use.
6
+ * @internal
7
+ */
8
+ export declare const VisuallyJsContext: Context<BrowserUIReactModel>;
9
+ /**
10
+ * Provider for a VisuallyJs model. This component is intended for certain advanced scenarios in which you have a number of UI components that want to share the same model. For instance you may render a model to a pannable and zoomable surface in some part of your UI, and then show a chart in some other part, whose data is the same model that the surface is using.
11
+ *
12
+ * @group Providers
13
+ */
14
+ export declare function VisuallyJsProvider(props: {
15
+ modelOptions?: ModelOptions;
16
+ children?: Array<ReactNode> | ReactNode;
17
+ }): JSX.Element;
18
+ /**
19
+ * Provides access to the VisuallyJsModel that is in scope, either as provided by a VisuallyJsContext, or a PaperContext/SurfaceContext. This hook is asynchronous and returns a Promise.
20
+ * @group Hooks
21
+ */
22
+ export declare function useVisuallyJsModel(): Promise<BrowserUIReactModel>;