@@ -74,7 +74,7 @@ Here's a simple example to get you started:
74
74
75
75
::: code-group
76
76
77
- ``` vue [<LogosJavascript />]
77
+ ``` vue [App.vue <LogosJavascript />]
78
78
<script setup>
79
79
import { ref } from 'vue'
80
80
import { VueFlow } from '@vue-flow/core'
@@ -182,7 +182,100 @@ const edges = ref([
182
182
</style>
183
183
```
184
184
185
- ``` vue [<LogosTypescript />]
185
+ ``` vue [SpecialNode.vue <LogosJavascript />]
186
+ <script setup>
187
+ import { computed } from 'vue'
188
+
189
+ const props = defineProps({
190
+ position: {
191
+ type: Object,
192
+ required: true,
193
+ }
194
+ })
195
+
196
+ const x = computed(() => `${Math.round(props.position.x)}px`)
197
+ const y = computed(() => `${Math.round(props.position.y)}px`)
198
+ </script>
199
+
200
+ <template>
201
+ <div class="vue-flow__node-default">
202
+ <div>{{ data.label }}</div>
203
+
204
+ <div>
205
+ {x} {y}
206
+ </div>
207
+
208
+ <Handle type="source" :position="Position.Bottom" />
209
+ </div>
210
+ </template>
211
+ ```
212
+
213
+ ``` vue [SpecialEdge.vue <LogosJavascript />]
214
+ <script setup>
215
+ import { BaseEdge, EdgeLabelRenderer, getBezierPath } from '@vue-flow/core'
216
+ import { computed } from 'vue'
217
+
218
+ const props = defineProps({
219
+ sourceX: {
220
+ type: Number,
221
+ required: true,
222
+ },
223
+ sourceY: {
224
+ type: Number,
225
+ required: true,
226
+ },
227
+ targetX: {
228
+ type: Number,
229
+ required: true,
230
+ },
231
+ targetY: {
232
+ type: Number,
233
+ required: true,
234
+ },
235
+ sourcePosition: {
236
+ type: String,
237
+ required: true,
238
+ },
239
+ targetPosition: {
240
+ type: String,
241
+ required: true,
242
+ },
243
+ data: {
244
+ type: Object,
245
+ required: true,
246
+ }
247
+ })
248
+
249
+ const path = computed(() => getBezierPath(props))
250
+ </script>
251
+
252
+ <script>
253
+ export default {
254
+ inheritAttrs: false,
255
+ }
256
+ </script>
257
+
258
+ <template>
259
+ <!-- You can use the `BaseEdge` component to create your own custom edge more easily -->
260
+ <BaseEdge :path="path[0]" />
261
+
262
+ <!-- Use the `EdgeLabelRenderer` to escape the SVG world of edges and render your own custom label in a `<div>` ctx -->
263
+ <EdgeLabelRenderer>
264
+ <div
265
+ :style="{
266
+ pointerEvents: 'all',
267
+ position: 'absolute',
268
+ transform: `translate(-50%, -50%) translate(${path[1]}px,${path[2]}px)`,
269
+ }"
270
+ class="nodrag nopan"
271
+ >
272
+ {{ data.hello }}
273
+ </div>
274
+ </EdgeLabelRenderer>
275
+ </template>
276
+ ```
277
+
278
+ ``` vue [App.vue <LogosTypescript />]
186
279
<script setup lang="ts">
187
280
import { ref } from 'vue'
188
281
import type { Node, Edge } from '@vue-flow/core'
@@ -291,6 +384,66 @@ const edges = ref<Edge[]>([
291
384
</style>
292
385
```
293
386
387
+ ``` vue [SpecialNode.vue <LogosTypescript />]
388
+ <script setup lang="ts">
389
+ import { computed } from 'vue'
390
+ import type { NodeProps } from '@vue-flow/core'
391
+
392
+ const props = defineProps<NodeProps>()
393
+
394
+ const x = computed(() => `${Math.round(props.position.x)}px`)
395
+ const y = computed(() => `${Math.round(props.position.y)}px`)
396
+ </script>
397
+
398
+ <template>
399
+ <div class="vue-flow__node-default">
400
+ <div>{{ data.label }}</div>
401
+
402
+ <div>
403
+ {x} {y}
404
+ </div>
405
+
406
+ <Handle type="source" :position="Position.Bottom" />
407
+ </div>
408
+ </template>
409
+ ```
410
+
411
+ ``` vue [SpecialEdge.vue <LogosTypescript />]
412
+ <script setup lang="ts">
413
+ import { BaseEdge, EdgeLabelRenderer, getBezierPath, type EdgeProps } from '@vue-flow/core'
414
+ import { computed } from 'vue'
415
+
416
+ const props = defineProps<EdgeProps>()
417
+
418
+ const path = computed(() => getBezierPath(props))
419
+ </script>
420
+
421
+ <script>
422
+ export default {
423
+ inheritAttrs: false,
424
+ }
425
+ </script>
426
+
427
+ <template>
428
+ <!-- You can use the `BaseEdge` component to create your own custom edge more easily -->
429
+ <BaseEdge :path="path[0]" />
430
+
431
+ <!-- Use the `EdgeLabelRenderer` to escape the SVG world of edges and render your own custom label in a `<div>` ctx -->
432
+ <EdgeLabelRenderer>
433
+ <div
434
+ :style="{
435
+ pointerEvents: 'all',
436
+ position: 'absolute',
437
+ transform: `translate(-50%, -50%) translate(${path[1]}px,${path[2]}px)`,
438
+ }"
439
+ class="nodrag nopan"
440
+ >
441
+ {{ data.hello }}
442
+ </div>
443
+ </EdgeLabelRenderer>
444
+ </template>
445
+ ```
446
+
294
447
:::
295
448
296
449
## TypeScript
0 commit comments