Skip to content

Commit c6e1834

Browse files
authored
feature/MIG-6673 Expose handlers and other props to the diagram (#31)
* feature/MIG-6673 Expose handlers * feature/MIG-6673 Default to false for connectable prop * feature/MIG-6673 Enforce markers
1 parent fb7a799 commit c6e1834

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

src/components/canvas/canvas.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import styled from '@emotion/styled';
2-
import { Background, ProOptions, ReactFlow, ReactFlowProps, useEdgesState, useNodesState } from '@xyflow/react';
2+
import {
3+
Background,
4+
ConnectionMode,
5+
ProOptions,
6+
ReactFlow,
7+
ReactFlowProps,
8+
SelectionMode,
9+
useEdgesState,
10+
useNodesState,
11+
} from '@xyflow/react';
312
import { useEffect } from 'react';
413

514
import { MiniMap } from '@/components/controls/mini-map';
@@ -66,8 +75,11 @@ export const Canvas = ({ title, nodes: externalNodes, edges: externalEdges, onCo
6675
onlyRenderVisibleElements={true}
6776
edges={edges}
6877
connectionLineComponent={ConnectionLine}
78+
connectionMode={ConnectionMode.Loose}
6979
onNodesChange={onNodesChange}
7080
onEdgesChange={onEdgesChange}
81+
selectionMode={SelectionMode.Partial}
82+
nodesDraggable={true}
7183
onConnect={onConnect}
7284
{...rest}
7385
>

src/components/canvas/use-canvas.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('use-canvas', () => {
1616
y: 100,
1717
},
1818
draggable: false,
19+
connectable: false,
1920
measured: {
2021
height: 36,
2122
width: 244,
@@ -42,6 +43,7 @@ describe('use-canvas', () => {
4243
width: 244,
4344
},
4445
draggable: true,
46+
connectable: false,
4547
data: {
4648
disabled: undefined,
4749
borderVariant: undefined,

src/components/canvas/use-canvas.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ export const useCanvas = (externalNodes: ExternalNode[], externalEdges: EdgeProp
77
const initialNodes: InternalNode[] = useMemo(
88
() =>
99
externalNodes.map(node => {
10-
const { title, fields, borderVariant, disabled, ...rest } = node;
10+
const { title, fields, borderVariant, disabled, connectable, ...rest } = node;
1111
return {
1212
...rest,
1313
draggable: !disabled,
14+
connectable: connectable || false,
1415
data: {
1516
title,
1617
disabled,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from '@/components/diagram';
22
export * from '@/utilities/apply-layout';
33
export * from '@/utilities/add-nodes-within-bounds';
44
export * from '@/types';
5+
export { ReactFlowProvider as DiagramProvider, useReactFlow as useDiagram, useOnSelectionChange } from '@xyflow/react';

src/types/component-props.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,32 @@ import { ReactFlowProps } from '@xyflow/react';
22

33
import { EdgeProps } from '@/types/edge';
44
import { NodeProps } from '@/types/node';
5+
import { InternalEdge, InternalNode } from '@/types/internal';
56

6-
type BaseProps = Pick<ReactFlowProps, 'title' | 'onConnect' | 'onPaneClick'>;
7+
type BaseProps = Pick<
8+
ReactFlowProps<InternalNode, InternalEdge>,
9+
| 'title'
10+
| 'id'
11+
| 'className'
12+
| 'onConnect'
13+
| 'onPaneClick'
14+
| 'onEdgeClick'
15+
| 'onNodeContextMenu'
16+
| 'onSelectionContextMenu'
17+
| 'onSelectionChange'
18+
| 'onSelectionDragStop'
19+
| 'onNodeDrag'
20+
| 'onNodeDragStop'
21+
| 'onConnectStart'
22+
| 'panOnDrag'
23+
| 'fitViewOptions'
24+
| 'selectionKeyCode'
25+
| 'multiSelectionKeyCode'
26+
| 'zoomOnPinch'
27+
| 'zoomOnScroll'
28+
| 'maxZoom'
29+
| 'minZoom'
30+
>;
731

832
export interface DiagramProps extends BaseProps {
933
isDarkMode?: boolean;

0 commit comments

Comments
 (0)