0.12.0 • Published 2 years ago

svelte-flow-diagram v0.12.0

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Svelte Flow Diagram

Early preview version...

Features

  • svelte components as diagram nodes
  • mousewheel zoom
  • space to drag around

Install

npm i svelte-flow-diagram

Usage

The best way is to check out the example index route.

Example

Data passed to data will react to changes. Currently, props is only intended to be used for initial/static properties. The uuid of each node is available to the "content component" as a prop.

<script>
	import { Diagram } from 'svelte-flow-diagram';

	let diagram;

	// add a node
	diagram.insertNode({
		uuid: 'test-uuid-1', // optional, gets generated when omitted
		data: { ... }, // optional data
		components: {
			content: { component: MyNodeComponent, props: { ... } },
			connectors: {
				input: { component: MyInputConnector },
				output: { component: MyOutputConnector }
			}
		},
		inputNames: ['in'],
		outputNames: ['out'],
		position: { x: 200, y: 100 }
	});

    	// add another node
	diagram.insertNode({
		uuid: 'test-uuid-2', // optional, gets generated when omitted
		data: { ... }, // optional data
		components: {
			content: { component: MyNodeComponent, props: { ... } },
			connectors: {
				input: { component: MyInputConnector },
				output: { component: MyOutputConnector }
			}
		},
		inputNames: ['in'],
		outputNames: ['out'],
		position: { x: 400, y: 100 }
	});

    	// add a connection
	diagram.addConnection({
		uuid: 'test-connection', // optional, gets generated when omitted
		from: {
			name: 'out',
			uuid: 'test-uuid-1'
		},
		to: {
			name: 'in',
			uuid: 'test-uuid-2'
		}
	});
</script>

<Diagram bind:this={diagram} />

Methods

namedescription
insertNodeinsert a node
removeNoderemove a node (also removes associated connections)
addConnectionadd a connection
removeConnectionremove a connection
clearclears the diagram
setNodeDataupdate the data of the given node
setNodePositionupdate the position of the given node

Props

namedefaultdescription
nodes{}All of the nodes
connections{}All of the connections
zoomLevel1Zoom in or out; 1 => 100%
connectionRenderer{}Change the appearance of connections
zoomMin0.1minimal zoom level
zoomMax5maximal zoom level
zoomStep0.1increase/decrease zoom by this much per step

ConnectionRenderer

The connection line can be manipulated for the following states:

interface ConnectionRenderer {
	default?: (context: CanvasRenderingContext2D) => void;
	hovered?: (context: CanvasRenderingContext2D) => void;
	selected?: (context: CanvasRenderingContext2D) => void;
	creating?: (context: CanvasRenderingContext2D) => void;
}

Optional Events

namepayloaddescription
hoverConnection{ uuid }Is fired when hovering over a connection.
selectConnection{ uuid }Is fired when selecting a connection.

Development

Run test app

npm run dev

Build package

npm run package

Publish package

npm run publish
0.11.0

2 years ago

0.10.1

2 years ago

0.12.0

2 years ago

0.11.1

2 years ago

0.10.2

2 years ago

0.11.2

2 years ago

0.10.3

2 years ago

0.11.3

2 years ago

0.10.4

2 years ago

0.11.4

2 years ago

0.10.5

2 years ago

0.11.5

2 years ago

0.10.6

2 years ago

0.11.6

2 years ago

0.10.7

2 years ago

0.11.7

2 years ago

0.10.8

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.9.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago