Skip to content

Commit

Permalink
Cleanup and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkmcc committed Jan 12, 2024
1 parent dfe94c5 commit 9cb2776
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# xyflow-node-editor
A blender-style node editor built on xyflow

#![](./assets/screenshot.png)
Binary file added assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 33 additions & 18 deletions src/NodeGraphEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { GraphConfigProvider } from './context/GraphConfigContext'
import 'reactflow/dist/style.css'
import { useNodeTypes } from './hooks/config'
import { useMemo } from 'react'
import { forwardRef, useImperativeHandle, useMemo } from 'react'
import { defaultEdgeTypes } from './edge-types'
import { IGraphConfig } from './config'
import { useSocketConnect } from './hooks/connect'
Expand Down Expand Up @@ -60,23 +60,38 @@ export function ExampleNodeGraphEditor({
}

type FlowProps = ReactFlowProps
// type FlowHandle = {
// layout: () => void
// }

function Flow({ defaultNodes, defaultEdges, ...props }: FlowProps) {
const nodeTypes = useNodeTypes()
const edgeTypes = useMemo(() => defaultEdgeTypes, [])
const onConnect = useSocketConnect()
const Flow = forwardRef(
({ defaultNodes, defaultEdges, ...props }: FlowProps, ref) => {
const nodeTypes = useNodeTypes()
const edgeTypes = useMemo(() => defaultEdgeTypes, [])
const onConnect = useSocketConnect()

return (
<div style={{ backgroundColor: '#1d1d1d', width: '100%', height: '100%' }}>
<ReactFlow
{...props}
onConnect={onConnect}
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
useImperativeHandle(
ref,
() => ({
layout: () => {},
}),
[],
)

return (
<div
style={{ backgroundColor: '#1d1d1d', width: '100%', height: '100%' }}
>
{props.children}
<Background color="#52525b" variant={BackgroundVariant.Dots} />
</ReactFlow>
</div>
)
}
<ReactFlow
{...props}
onConnect={onConnect}
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
>
{props.children}
<Background color="#52525b" variant={BackgroundVariant.Dots} />
</ReactFlow>
</div>
)
},
)

0 comments on commit 9cb2776

Please sign in to comment.