44 import type { Node , Edge , NodeTypes } from ' @xyflow/svelte' ;
55
66 import {Logs , VaultNode } from ' $lib/fragments' ;
7- import { HugeiconsIcon } from ' @hugeicons/svelte' ;
8- import { PauseFreeIcons , PlayFreeIcons } from ' @hugeicons/core-free-icons' ;
9- import {ButtonAction } from ' $lib/ui' ;
7+ import { HugeiconsIcon } from ' @hugeicons/svelte' ;
8+ import { PauseFreeIcons , PlayFreeIcons } from ' @hugeicons/core-free-icons' ;
9+ import {ButtonAction } from ' $lib/ui' ;
1010
1111
1212 let SvelteFlowComponent: typeof import (' @xyflow/svelte' ).SvelteFlow | null = $state (null );
1616 };
1717
1818 let isPaused = $state (false );
19+ let modal: HTMLDialogElement | undefined = $state ();
1920
2021 let nodes: Node [] = $state ([
2122 {
4546 ]);
4647
4748 let edges: Edge [] = $derived (
48- nodes .flatMap ((node , index , arr ) => {
49- if (index < arr .length - 1 ) {
50- return [{
51- id: ` e${node .id }-${arr [index + 1 ].id } ` ,
52- source: node .id ,
53- target: arr [index + 1 ].id ,
49+ (() => {
50+ const generatedEdges: Edge [] = [];
51+
52+ nodes .forEach ((node , index , arr ) => {
53+ if (index < arr .length - 1 ) {
54+ // Skip default connection if it's part of the explicit two-way connection
55+ // This ensures we don't have duplicate edges
56+ if ((node .id === ' 1' && arr [index + 1 ].id === ' 2' ) || (node .id === ' 2' && arr [index + 1 ].id === ' 1' )) {
57+ return ;
58+ }
59+ generatedEdges .push ({
60+ id: ` e${node .id }-${arr [index + 1 ].id } ` ,
61+ source: node .id ,
62+ target: arr [index + 1 ].id ,
63+ animated: ! isPaused ,
64+ type: ' smoothstep' ,
65+ label: ` from ${node .data .label } ` ,
66+ style: ' stroke: #4CAF50; stroke-width: 2;' ,
67+ });
68+ }
69+ });
70+
71+ generatedEdges .push (
72+ {
73+ id: ' e-alice-to-pictique' ,
74+ source: ' 1' ,
75+ target: ' 2' ,
76+ animated: ! isPaused ,
77+ type: ' smoothstep' ,
78+ label: ' from Alice' ,
79+ labelStyle: ' fill: #fff; fontWeight: 700' ,
80+ style: ' stroke: #007BFF; stroke-width: 2;' ,
81+ },
82+ {
83+ id: ' e-pictique-from-alice' ,
84+ source: ' 2' ,
85+ target: ' 1' ,
5486 animated: ! isPaused ,
5587 type: ' smoothstep' ,
56- style: ' stroke: #4CAF50; stroke-width: 2;' ,
57- }];
58- }
59- return [];
60- })
88+ label: ' from Pictique' ,
89+ labelStyle: ' fill: #fff; fontWeight: 700' ,
90+ style: ' stroke: #FFA500; stroke-width: 2;' ,
91+ }
92+ );
93+
94+ return generatedEdges ;
95+ })()
6196 );
6297
6398 let currentSelectedEventIndex = $state (- 1 );
6499
65- const events = [
66- {
67- timestamp: new Date (),
68- action: ' upload' ,
69- message: ' msg_123' ,
70- to: ' alice.vault.dev'
71- },
72- {
73- timestamp: new Date (),
74- action: ' fetch' ,
75- message: ' msg_124' ,
76- from: ' bob.vault.dev'
77- },
78- {
79- timestamp: new Date (),
80- action: ' webhook' ,
81- to: ' Alice' ,
82- from: ' Pic'
83- }
84- ];
100+ const events = [
101+ {
102+ timestamp: new Date (),
103+ action: ' upload' ,
104+ message: ' msg_123' ,
105+ to: ' alice.vault.dev'
106+ },
107+ {
108+ timestamp: new Date (),
109+ action: ' fetch' ,
110+ message: ' msg_124' ,
111+ from: ' bob.vault.dev'
112+ },
113+ {
114+ timestamp: new Date (),
115+ action: ' webhook' ,
116+ to: ' Alice' ,
117+ from: ' Pic'
118+ }
119+ ];
85120
86121 onMount (async () => {
87122 const mod = await import (' @xyflow/svelte' );
94129 <div class =" w-full flex justify-between items-center p-4 bg-white shadow-sm z-10" >
95130 <h4 class =" text-xl text-gray-800 font-semibold" >Live Monitoring</h4 >
96131 <div class =" flex gap-2" >
97- <ButtonAction class =" w-[max-content]" variant =" soft" size =" sm" >Add Vault</ButtonAction >
132+ <ButtonAction class ="w-[max-content]" variant ="soft" size ="sm" callback ={() => { modal ?. show ()}} >Add Vault</ButtonAction >
98133 <button
99134 onclick ={() => isPaused = ! isPaused }
100135 class =" px-4 py-2 flex items-center gap-2 text-base font-geist font-medium text-gray-700 bg-white border border-[#e5e5e5] rounded-full shadow-md hover:bg-gray-50 transition-colors"
121156 {:else }
122157 <div class =" flex-grow flex justify-center items-center text-gray-700" >Loading flow chart...</div >
123158 {/if }
124- </div >
125- <Logs class ="w-[40%]" {events } bind:activeEventIndex ={currentSelectedEventIndex } />
159+ </div >
160+ <Logs class ="w-[40%]" {events } bind:activeEventIndex ={currentSelectedEventIndex } />
126161</section >
127162
163+
128164<style >
165+ /*
129166 :global(.svelte-flow__edge-path) {
130167 stroke: #4CAF50 !important;
131168 stroke-width: 2 !important;
132169 }
170+ */
133171
134172 :global(.svelte-flow__edge.animated .svelte-flow__edge-path ) {
135173 stroke-dasharray : 5 5 ;
136174 }
137175
138176 :global(.svelte-flow ) {
139- background-color : transparent !important ;
177+ background-color : transparent !important ;
178+ --xy-edge-label-color-default : black ;
179+ }
180+
181+ :global(.svelte-flow__edge-label ) {
182+ background : #d2d2d2 ;
183+ border-radius : 10px ;
184+ padding : 5px ;
185+ }
186+
187+ :global(.svelte-flow__edge-label ):nth-child (3 ) {
188+ translate : -100px 0 ;
189+ }
190+
191+ :global(.svelte-flow__edge-label ):nth-child (4 ) {
192+ translate : 0 -100px ;
140193 }
141194 </style >
0 commit comments