Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/canvas/canvas.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import styled from '@emotion/styled';
import { Background, ProOptions, ReactFlow, ReactFlowProps, useEdgesState, useNodesState } from '@xyflow/react';
import {
Background,
ConnectionMode,
ProOptions,
ReactFlow,
ReactFlowProps,
SelectionMode,
useEdgesState,
useNodesState,
} from '@xyflow/react';
import { useEffect } from 'react';

import { MiniMap } from '@/components/controls/mini-map';
Expand Down Expand Up @@ -66,8 +75,11 @@ export const Canvas = ({ title, nodes: externalNodes, edges: externalEdges, onCo
onlyRenderVisibleElements={true}
edges={edges}
connectionLineComponent={ConnectionLine}
connectionMode={ConnectionMode.Loose}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These props are copied over from the Relational Migrator diagramming component. We can hard code it now as I see no reason to pass these in as a prop (yet)

onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
selectionMode={SelectionMode.Partial}
nodesDraggable={true}
onConnect={onConnect}
{...rest}
>
Expand Down
2 changes: 2 additions & 0 deletions src/components/canvas/use-canvas.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('use-canvas', () => {
y: 100,
},
draggable: false,
connectable: false,
measured: {
height: 36,
width: 244,
Expand All @@ -42,6 +43,7 @@ describe('use-canvas', () => {
width: 244,
},
draggable: true,
connectable: false,
data: {
disabled: undefined,
borderVariant: undefined,
Expand Down
3 changes: 2 additions & 1 deletion src/components/canvas/use-canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ export const useCanvas = (externalNodes: ExternalNode[], externalEdges: EdgeProp
const initialNodes: InternalNode[] = useMemo(
() =>
externalNodes.map(node => {
const { title, fields, borderVariant, disabled, ...rest } = node;
const { title, fields, borderVariant, disabled, connectable, ...rest } = node;
return {
...rest,
draggable: !disabled,
connectable: connectable || false,
data: {
title,
disabled,
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from '@/components/diagram';
export * from '@/utilities/apply-layout';
export * from '@/utilities/add-nodes-within-bounds';
export * from '@/types';
export { ReactFlowProvider as DiagramProvider, useReactFlow as useDiagram, useOnSelectionChange } from '@xyflow/react';
26 changes: 25 additions & 1 deletion src/types/component-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@ import { ReactFlowProps } from '@xyflow/react';

import { EdgeProps } from '@/types/edge';
import { NodeProps } from '@/types/node';
import { InternalEdge, InternalNode } from '@/types/internal';

type BaseProps = Pick<ReactFlowProps, 'title' | 'onConnect' | 'onPaneClick'>;
type BaseProps = Pick<
ReactFlowProps<InternalNode, InternalEdge>,
| 'title'
| 'id'
| 'className'
| 'onConnect'
| 'onPaneClick'
| 'onEdgeClick'
| 'onNodeContextMenu'
| 'onSelectionContextMenu'
| 'onSelectionChange'
| 'onSelectionDragStop'
| 'onNodeDrag'
| 'onNodeDragStop'
| 'onConnectStart'
| 'panOnDrag'
| 'fitViewOptions'
| 'selectionKeyCode'
| 'multiSelectionKeyCode'
| 'zoomOnPinch'
| 'zoomOnScroll'
| 'maxZoom'
| 'minZoom'
>;

export interface DiagramProps extends BaseProps {
isDarkMode?: boolean;
Expand Down