1
1
<script setup>
2
- import { ref } from ' vue'
2
+ import { h , ref } from ' vue'
3
3
import { VueFlow , useVueFlow } from ' @vue-flow/core'
4
4
import { Background } from ' @vue-flow/background'
5
5
import { useDialog } from ' ./useDialog'
@@ -10,16 +10,26 @@ const { onConnect, addEdges, onNodesChange, onEdgesChange, applyNodeChanges, app
10
10
const dialog = useDialog ()
11
11
12
12
const nodes = ref ([
13
- { id: ' 1' , type: ' input' , label: ' Node 1' , position: { x: 250 , y: 5 }, class: ' light' },
14
- { id: ' 2' , label: ' Node 2' , position: { x: 100 , y: 100 }, class: ' light' },
15
- { id: ' 3' , label: ' Node 3' , position: { x: 400 , y: 100 }, class: ' light' },
16
- { id: ' 4' , label: ' Node 4' , position: { x: 400 , y: 200 }, class: ' light' },
13
+ { id: ' 1' , type: ' input' , data: { label: ' Click me and' }, position: { x: 0 , y: 0 } },
14
+ { id: ' 2' , data: { label: ` press 'Backspace' to delete me` }, position: { x: 0 , y: 100 } },
17
15
])
18
16
19
- const edges = ref ([
20
- { id: ' e1-2' , source: ' 1' , target: ' 2' , animated: true },
21
- { id: ' e1-3' , source: ' 1' , target: ' 3' },
22
- ])
17
+ const edges = ref ([{ id: ' e1-2' , source: ' 1' , target: ' 2' }])
18
+
19
+ function dialogMsg (id ) {
20
+ return h (
21
+ ' span' ,
22
+ {
23
+ style: {
24
+ display: ' flex' ,
25
+ flexDirection: ' column' ,
26
+ alignItems: ' center' ,
27
+ gap: ' 8px' ,
28
+ },
29
+ },
30
+ [` Are you sure?` , h (' br' ), h (' span' , ` [ELEMENT_ID: ${ id} ]` )],
31
+ )
32
+ }
23
33
24
34
onConnect (addEdges)
25
35
@@ -28,7 +38,7 @@ onNodesChange(async (changes) => {
28
38
29
39
for (const change of changes) {
30
40
if (change .type === ' remove' ) {
31
- const isConfirmed = await dialog .confirm (` Do you really want to delete this node: ${ change .id } ? ` )
41
+ const isConfirmed = await dialog .confirm (dialogMsg ( change .id ) )
32
42
33
43
if (isConfirmed) {
34
44
nextChanges .push (change)
@@ -46,7 +56,7 @@ onEdgesChange(async (changes) => {
46
56
47
57
for (const change of changes) {
48
58
if (change .type === ' remove' ) {
49
- const isConfirmed = await dialog .confirm (` Do you really want to delete this edge: ${ change .id } ? ` )
59
+ const isConfirmed = await dialog .confirm (dialogMsg ( change .id ) )
50
60
51
61
if (isConfirmed) {
52
62
nextChanges .push (change)
@@ -61,7 +71,7 @@ onEdgesChange(async (changes) => {
61
71
</script >
62
72
63
73
<template >
64
- <VueFlow :nodes =" nodes" :edges =" edges" :apply-default =" false" fit-view-on-init class =" vue -flow-basic-example " >
74
+ <VueFlow :nodes =" nodes" :edges =" edges" :apply-default =" false" fit-view-on-init class =" confirm -flow" >
65
75
<Background />
66
76
67
77
<Dialog />
0 commit comments