Files
xyflow/packages/svelte
Moritz KlackandGitHub 1dab08f36e feat(utils): add vanilla drag and panzoom (#3108)
* refactor(panzoom): create vanilla helper

* feat(svelte): add interaction example

* refactor(panzoom): cleanup

* Update function-runner.ts

* refactor(panzoom): cleanup

* refactor(panzoom): rename functions

* feat(utils): add vanilla drag helper (#3107)

* feat(utils): add vanilla drag helper

* refactor(drag): cleanup

* refactor(drag): cleanup

* chore(packages): cleanup

* refactor(panzoom): cleanup and simplify
2023-05-31 15:55:36 +02:00
..
2023-02-28 12:48:52 +01:00
2023-02-01 09:41:09 +01:00
2023-02-01 09:41:09 +01:00
2023-02-28 12:48:52 +01:00
2023-03-20 18:20:32 +01:00
2023-02-28 12:48:52 +01:00
2023-02-28 12:48:52 +01:00

SvelteFlow

A highly customizable Svelte component for building interactive graphs and node-based editors. This package is currently under heavy development and the API is very likely to change.

Getting started

If you want to check out the current version you need to run the following command from the root directory:

  1. pnpm install - installs dependencies
  2. pnpm build - needs to be done once
  3. pnpm dev - starts dev server

You can now access the examples under http://127.0.0.1:5173

A basic flow

A basic flow looks like this:

<script lang="ts">
  import SvelteFlow, {
    SvelteFlowProvider,
    Controls,
    Background,
    BackgroundVariant,
    Minimap,
    Panel,
    createNodes,
    createEdges,
    type NodeTypes
  } from '../../lib/index';
  import { CustomNode } from './CustomNode';

  const nodeTypes: NodeTypes = {
    custom: CustomNode
  };
  
  const nodes = createNodes([
    {
      id: '1',
      type: 'input',
      data: { label: 'Input Node' },
      position: { x: 0, y: 0 }
    },
    {
      id: '2',
      type: 'custom',
      data: { label: 'Node' },
      position: { x: 0, y: 150 }
    }
  ], { style: 'width: 125px;' });

  const edges = createEdges([
    {
      id: '1-2',
      type: 'default',
      source: '1',
      target: '2',
      label: 'Edge Text'
    }
  ], { animated: true });
</script>

<SvelteFlowProvider
  {nodes}
  {edges}
>
  <SvelteFlow
    {nodeTypes}
    fitView
    snapGrid={[25, 25]}
    on:node:click={(event) => console.log('on node click', event)}
  >
    <Controls />
    <Background variant={BackgroundVariant.Dots} />
    <Minimap />
  </SvelteFlow>
</SvelteFlowProvider>