feat: Extend options to pass custom nodes / edges

* Accept either a Record<string, Component | boolean> or string[] as nodetypes option
* If bool / string is used a slot will be expected, otherwise no node/edge will be rendered

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-16 09:43:17 +01:00
parent d9e310403c
commit d1dab4cda8
8 changed files with 22 additions and 68 deletions
-24
View File
@@ -1,24 +0,0 @@
import { DefaultNode, InputNode, OutputNode } from '~/components/Nodes'
import { NodeType } from '~/types'
export function createNodeTypes(nodeTypes: Record<string, NodeType>): Record<string, NodeType> {
const standardTypes: Record<string, NodeType> = {
input: nodeTypes.input || InputNode,
default: nodeTypes.default || DefaultNode,
output: nodeTypes.output || OutputNode,
}
const wrappedTypes = {} as NodeType
const specialTypes: NodeType = Object.keys(nodeTypes)
.filter((k) => !['input', 'default', 'output'].includes(k))
.reduce((res, key) => {
res[key] = nodeTypes[key] || DefaultNode
return res
}, wrappedTypes)
return {
...standardTypes,
...specialTypes,
}
}