-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ID can be used to switch between different types of nodes/edges * Add example
- Loading branch information
1 parent
26b3901
commit 0a45e09
Showing
6 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<script lang="ts" setup> | ||
const props = defineProps<{ nodeStyles: Record<string, any> }>() | ||
</script> | ||
<template> | ||
<div :style="props.nodeStyles">A</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<script lang="ts" setup> | ||
const props = defineProps<{ nodeStyles: Record<string, any> }>() | ||
</script> | ||
<template> | ||
<div :style="props.nodeStyles">B</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<script lang="ts" setup> | ||
import { CSSProperties } from 'vue' | ||
import NodeA from './NodeA.vue' | ||
import NodeB from './NodeB.vue' | ||
import Flow, { Elements, Position, NodeType, Connection, Edge, addEdge } from '~/index' | ||
const initialElements: Elements = [ | ||
{ | ||
id: '1', | ||
sourcePosition: Position.Right, | ||
type: 'input', | ||
data: { label: 'Input' }, | ||
position: { x: 0, y: 80 }, | ||
}, | ||
{ | ||
id: '2', | ||
type: 'a', | ||
sourcePosition: Position.Right, | ||
targetPosition: Position.Left, | ||
data: { label: 'A Node' }, | ||
position: { x: 250, y: 0 }, | ||
}, | ||
] | ||
const buttonStyle: CSSProperties = { position: 'absolute', right: 10, top: 30, zIndex: 4 } | ||
const nodeStyles: CSSProperties = { padding: '10px 15px', border: '1px solid #ddd' } | ||
type NodeTypesObject = { | ||
[key: string]: Record<string, NodeType> | ||
} | ||
const nodeTypesObjects: NodeTypesObject = { | ||
a: { | ||
a: NodeA as NodeType, | ||
}, | ||
b: { | ||
b: NodeB as NodeType, | ||
}, | ||
} | ||
const elements = ref(initialElements) | ||
const nodeTypesId = ref('a') | ||
const changeType = () => { | ||
const id = nodeTypesId.value === 'a' ? 'b' : 'a' | ||
elements.value[1].type = id | ||
nodeTypesId.value = id | ||
} | ||
const onConnect = (params: Connection | Edge) => (elements.value = addEdge(params, elements.value)) | ||
</script> | ||
<template> | ||
<Flow :elements="elements" :node-types="nodeTypesObjects[nodeTypesId]" :node-types-id="nodeTypesId" @connect="onConnect"> | ||
<template #node-a> | ||
<NodeA :node-styles="nodeStyles" /> | ||
</template> | ||
<template #node-b> | ||
<NodeB :node-styles="nodeStyles" /> | ||
</template> | ||
<button :style="buttonStyle" @click="changeType">change type</button> | ||
</Flow> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0a45e09
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: