From 76fe779f346a3fd9f2e725c0897f2bedd4a87d58 Mon Sep 17 00:00:00 2001
From: braks <78412429+bcakmakoglu@users.noreply.github.com>
Date: Thu, 13 Jun 2024 22:27:07 +0200
Subject: [PATCH] docs: update nodes / edges pages
---
docs/src/guide/edge.md | 364 ++++++++++++++++++++++++-----------------
docs/src/guide/node.md | 273 +++++++++++++++++--------------
2 files changed, 363 insertions(+), 274 deletions(-)
diff --git a/docs/src/guide/edge.md b/docs/src/guide/edge.md
index a40d81c2..aab31179 100644
--- a/docs/src/guide/edge.md
+++ b/docs/src/guide/edge.md
@@ -73,6 +73,10 @@ const straightEdge = ref([
target: '2',
},
]);
+
+function logEvent(name, data) {
+ console.log(name, data)
+}
# Introduction to Edges
@@ -86,8 +90,7 @@ For the full list of options available for an edge, check out the [Edge Type](/t
## Adding Edges to the Graph
-Edges are generally created by adding them to the `mode-value` (using `v-model`) or to the `edges` prop of the Vue Flow component.
-This can be done dynamically at any point in your component's lifecycle.
+Edges are rendered by passing them to the `edges` prop (or the deprecated `v-model` prop) of the Vue Flow component.
:::code-group
@@ -97,30 +100,30 @@ This can be done dynamically at any point in your component's lifecycle.
import { ref, onMounted } from 'vue'
import { VueFlow } from '@vue-flow/core'
-const elements = ref([
+const nodes = ref([
{
id: '1',
position: { x: 50, y: 50 },
- label: 'Node 1',
+ data: { label: 'Node 1', },
},
{
id: '2',
position: { x: 50, y: 250 },
- label: 'Node 2',
+ data: { label: 'Node 2', },
}
]);
-onMounted(() => {
- elements.value.push({
- id: 'e1-2',
+const edges = ref([
+ {
+ id: 'e1->2',
source: '1',
target: '2',
- })
-})
+ }
+]);
-
+
```
@@ -128,42 +131,42 @@ onMounted(() => {
-
+
```
:::
-If you are working with more complex graphs that necessitate extensive state access, the `useVueFlow` composable should
-be employed.
-The [`addEdges`](/typedocs/interfaces/Actions#addEdges) action is available
-through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to add edges straight to the state.
+If you are working with more complex graphs or simply require access to the internal state,
+the [useVueFlow](/typedocs/functions/useVueFlow) composable will come in handy.
+
+The [`addEdges`](/typedocs/interfaces/Actions#addEdges) action is available through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to add edges straight to the state.
What's more, this action isn't limited to the component rendering the graph; it can be utilized elsewhere, like in a
Sidebar or Toolbar.
@@ -176,31 +179,28 @@ const initialNodes = ref([
{
id: '1',
position: { x: 50, y: 50 },
- label: 'Node 1',
+ data: { label: 'Node 1', },
},
{
id: '2',
position: { x: 50, y: 250 },
- label: 'Node 2',
+ data: { label: 'Node 2', },
}
])
const { addEdges } = useVueFlow()
-onMounted(() => {
- // add an edge after mount
- addEdges([
- {
- source: '1',
- target: '2',
-
- // if a node has multiple handles of the same type,
- // you should specify which handle to use by id
- sourceHandle: null,
- targetHandle: null,
- }
- ])
-})
+addEdges([
+ {
+ source: '1',
+ target: '2',
+
+ // if a node has multiple handles of the same type,
+ // you should specify which handle to use by id
+ sourceHandle: null,
+ targetHandle: null,
+ }
+])
@@ -213,81 +213,118 @@ onMounted(() => {
Similar to adding edges, edges can be removed from the graph by removing them from the `mode-value` (using `v-model`) or from the `edges` prop of the Vue Flow component.
```vue
-
-
+
+
+
+
+
```
-When working with complex graphs with extensive state access, you should use the useVueFlow composable.
-The [`removeEdges`](/typedocs/interfaces/Actions#removeEdges) action is available through [useVueFlow](/typedocs/functions/useVueFlow),
-allowing you to remove edges straight from the state.
+The [`removeEdges`](/typedocs/interfaces/Actions#removeEdges) action is available through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to remove edges straight from the state.
-What's more, this action isn't limited to the component rendering the graph; it can be utilized elsewhere, like in a
-Sidebar, Toolbar or the Edge itself.
+You can also use this action outside the component rendering the graph, like in a Sidebar or Toolbar.
```vue
-
+
+
+
+
+
+
```
@@ -300,13 +337,34 @@ There are multiple ways of achieving this, here are some examples:
::: code-group
+```ts [useVueFlow]
+import { useVueFlow } from '@vue-flow/core'
+
+const instance = useVueFlow()
+
+// use the `updateEdgeData` method to update the data of an edge
+instance.updateEdgeData(edgeId, { hello: 'mona' })
+
+// find the edge in the state by its id
+const edge = instance.findEdge(edgeId)
+
+edge.data = {
+ ...edge.data,
+ hello: 'world',
+}
+
+// you can also mutate properties like `selectable` or `animated`
+edge.selectable = !edge.selectable
+edge.animated = !edge.animated
+```
+
```vue [useEdge]
```
-```ts [useVueFlow]
-import { useVueFlow } from '@vue-flow/core'
-
-const instance = useVueFlow()
-
-// find the node in the state by its id
-const edge = instance.findEdge(edgeId)
-
-edge.data = {
- ...edge.data,
- hello: 'world',
-}
-
-// you can also mutate properties like `selectable` or `animated`
-edge.selectable = !edge.selectable
-edge.animated = !edge.animated
-```
-
```vue [v-model]
@@ -576,23 +619,23 @@ export const edges = ref([
const nodes = ref([
{
id: '1',
- label: 'Node 1',
position: { x: 50, y: 50 },
+ data: { label: 'Node 1', },
},
{
id: '2',
- label: 'Node 2',
position: { x: 50, y: 250 },
+ data: { label: 'Node 2', },
},
{
id: '3',
- label: 'Node 3',
position: { x: 250, y: 50 },
+ data: { label: 'Node 3', },
},
{
id: '4',
- label: 'Node 4',
position: { x: 250, y: 250 },
+ data: { label: 'Node 4', },
},
])
@@ -656,32 +699,37 @@ One of the easiest ways to define custom edges is, by passing them as template s
Dynamic resolution to slot-names is done for your user-defined edge-types,
meaning a edge with the type `custom` is expected to have a slot named `#edge-custom`.
-```vue{18,26}
+```vue
+
-
+
@@ -697,7 +745,7 @@ Alternatively, edge-types can also be defined by passing an object as a prop to
Take precaution to mark your components as raw (utilizing the marked function from the Vue library) to prevent their conversion into reactive objects. Otherwise, Vue will display a warning on the console.
:::
-```vue{5-7,28}
+```vue
-
diff --git a/docs/src/guide/node.md b/docs/src/guide/node.md
index 03e23c0f..226b09a4 100644
--- a/docs/src/guide/node.md
+++ b/docs/src/guide/node.md
@@ -44,6 +44,10 @@ const outputNode = ref([
position: { x: 50, y: 75 },
}
]);
+
+function logEvent(name, data) {
+ console.log(name, data)
+}
# Introduction to Nodes
@@ -67,27 +71,33 @@ This can be done dynamically at any point in your component's lifecycle.
-
+
+
+
+
+
```
@@ -95,37 +105,43 @@ onMounted(() => {
-
+
+
+
+
+
```
:::
-If you are working with more complex graphs that necessitate extensive state access, the `useVueFlow` composable should
-be employed.
-The [`addNodes`](/typedocs/interfaces/Actions#addnodes) action is available
-through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to add nodes straight to the state.
+If you are working with more complex graphs or simply require access to the internal state,
+the [useVueFlow](/typedocs/functions/useVueFlow) composable will come in handy.
+
+The [`addNodes`](/typedocs/interfaces/Actions#addnodes) action is available through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to add nodes straight to the state.
What's more, this action isn't limited to the component rendering the graph; it can be utilized elsewhere, like in a
Sidebar or Toolbar.
@@ -133,7 +149,6 @@ Sidebar or Toolbar.
::: code-group
```vue []
-
-
-
-
+
+
+
+
+
+
```
-When working with complex graphs with extensive state access, you should use the useVueFlow composable.
-The [`removeNodes`](/typedocs/interfaces/Actions#removeNodes) action is available through [useVueFlow](/typedocs/functions/useVueFlow),
-allowing you to remove nodes straight from the state.
+The [`removeNodes`](/typedocs/interfaces/Actions#removeNodes) action is available through [useVueFlow](/typedocs/functions/useVueFlow), allowing you to remove nodes straight from the state.
-What's more, this action isn't limited to the component rendering the graph; it can be utilized elsewhere, like in a
-Sidebar, Toolbar or the Edge itself.
+You can also use this action outside the component rendering the graph, like in a Sidebar or Toolbar.
```vue
-
-
-
-
-
+
+
+
+
+
+
```
@@ -316,6 +329,30 @@ There are multiple ways of achieving this, here are some examples:
::: code-group
+```ts [useVueFlow]
+import { useVueFlow } from '@vue-flow/core'
+
+const instance = useVueFlow()
+
+// use the `updateNodeData` method to update the data of an edge
+instance.updateNodeData(edgeId, { hello: 'mona' })
+
+// find the node in the state by its id
+const node = instance.findNode(nodeId)
+
+node.data = {
+ ...node.data,
+ hello: 'world',
+}
+
+// you can also mutate properties like `selectable` or `draggable`
+node.selectable = false
+node.draggable = false
+
+// or use `updateNode` to update the node directly
+instance.updateNode(nodeId, { selectable: false, draggable: false })
+```
+
```vue [useNode]
```
-```ts [useVueFlow]
-import { useVueFlow } from '@vue-flow/core'
-
-const instance = useVueFlow()
-
-// find the node in the state by its id
-const node = instance.findNode(nodeId)
-
-node.data = {
- ...node.data,
- hello: 'world',
-}
-
-// you can also mutate properties like `selectable` or `draggable`
-node.selectable = false
-node.draggable = false
-```
-
```vue [v-model]
-
+
+
+
+
+
```
@@ -410,10 +433,10 @@ import { Position } from '@vue-flow/core'
const nodes = ref([
{
id: '1',
- label: 'Default Node',
type: 'default', // You can omit this as it's the fallback type
targetPosition: Position.Top, // or Bottom, Left, Right,
sourcePosition: Position.Bottom, // or Top, Left, Right,
+ data: { label: 'Default Node' },
}
])
```
@@ -436,9 +459,9 @@ import { Position } from '@vue-flow/core'
const nodes = ref([
{
id: '1',
- label: 'Input Node',
type: 'input',
sourcePosition: Position.Bottom, // or Top, Left, Right,
+ data: { label: 'Input Node' },
}
])
```
@@ -461,9 +484,9 @@ import { Position } from '@vue-flow/core'
const nodes = ref([
{
id: '1',
- label: 'Output Node',
type: 'output',
targetPosition: Position.Top, // or Bottom, Left, Right,
+ data: { label: 'Output Node' },
}
])
```
@@ -482,7 +505,7 @@ Node-types are determined from your nodes' definitions.
::: code-group
-```vue{11-12,18-19} [App.vue ]
+```vue [App.vue ]
-
+
@@ -685,22 +708,22 @@ const nodeTypes = {
special: markRaw(SpecialNode),
}
-const elements = ref([
+const nodes = ref([
{
id: '1',
- label: 'Node 1',
+ data: { label: 'Node 1' },
type: 'custom',
},
{
id: '1',
- label: 'Node 1',
+ data: { label: 'Node 1' },
type: 'special',
}
])
-
+
```
@@ -759,10 +782,10 @@ const {
onNodeMouseMove
} = useVueFlow()
-const elements = ref([
+const nodes = ref([
{
id: '1',
- label: 'Node 1',
+ data: { label: 'Node 1' },
position: { x: 50, y: 50 },
},
])
@@ -784,7 +807,7 @@ onNodeDragStop((event) => {
-
+
```
@@ -793,28 +816,32 @@ onNodeDragStop((event) => {
import { ref } from 'vue'
import { VueFlow } from '@vue-flow/core'
-const elements = ref([
+const nodes = ref([
{
id: '1',
- label: 'Node 1',
+ data: { label: 'Node 1' },
position: { x: 50, y: 50 },
},
])
+
+function logEvent(name, data) {
+ console.log(name, data)
+}
```
@@ -824,15 +851,15 @@ const elements = ref([