Flow.svelte 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <script>
  2. import { createEventDispatcher } from 'svelte';
  3. const dispatch = createEventDispatcher();
  4. import { theme } from '$lib/stores';
  5. import {
  6. Background,
  7. Controls,
  8. SvelteFlow,
  9. BackgroundVariant,
  10. ControlButton
  11. } from '@xyflow/svelte';
  12. import BarsArrowUp from '$lib/components/icons/BarsArrowUp.svelte';
  13. import Bars3BottomLeft from '$lib/components/icons/Bars3BottomLeft.svelte';
  14. export let nodes;
  15. export let nodeTypes;
  16. export let edges;
  17. export let setLayoutDirection;
  18. </script>
  19. <SvelteFlow
  20. {nodes}
  21. {nodeTypes}
  22. {edges}
  23. fitView
  24. minZoom={0.001}
  25. colorMode={$theme.includes('dark')
  26. ? 'dark'
  27. : $theme === 'system'
  28. ? window.matchMedia('(prefers-color-scheme: dark)').matches
  29. ? 'dark'
  30. : 'light'
  31. : 'light'}
  32. nodesConnectable={false}
  33. nodesDraggable={false}
  34. on:nodeclick={(e) => dispatch('nodeclick', e.detail)}
  35. oninit={() => {
  36. console.log('Flow initialized');
  37. }}
  38. >
  39. <Controls showLock={false}>
  40. <ControlButton on:click={() => setLayoutDirection('vertical')} title="Vertical Layout">
  41. <BarsArrowUp class="size-4" />
  42. </ControlButton>
  43. <ControlButton on:click={() => setLayoutDirection('horizontal')} title="Horizontal Layout">
  44. <Bars3BottomLeft class="size-4" />
  45. </ControlButton>
  46. </Controls>
  47. <Background variant={BackgroundVariant.Dots} />
  48. </SvelteFlow>