Alpine Flow
About
Alpine Flow makes creating directed step based flowcharts and node based workflow UIs (DAG) in AlpineJS an easier task.
- Alpine Flow
- About
- Features
- Installation
- Concepts
- What is a node?
- What is an edge?
- Quickstart
- Building your first flow
- 1. Create a node component
- 2. Create an editor
- 3. Putting it together
- Building your first flow
- API reference
- Node
- Configuration
- The
$nodesmagic
- flowEditor
- Configuration
- Methods
- editor.hasNodes()
- editor.hasNoNodes()
- editor.addNode(incompleteNode, dependsOn=null)
- editor.deleteNode(nodeId, dependsOn=null)
- editor.getNodeById(nodeId)
- editor.findParents(nodeId)
- editor.findChildren(nodeId)
- editor.findDescendantsOfNode(nodeId)
- editor.zoomOut(zoomStep = 1 / 1.2)
- editor.zoomIn(zoomStep = 1.2)
- editor.setViewportToCenter(paddingY = 0.1, paddingX = 0.3)
- editor.setViewport(x=0, y=0, zoom=1)
- editor.toObject()
- Node
- Events
@flow-init.window@flow-nodes-updated.window@flow-nodes-deleted.window
- Dependencies
Features
- Easy and familiar syntax well integrated with Alpine.js.
- Automatic handling of layout and arrow drawing.
- Full styling control across background, nodes, edges and toolbar. Use Tailwind, CSS or anything you want.
- Built-in zooming, panning and dragging.
- Pre-built toolbar component.
- Methods to delete nodes, add nodes and traverse your workflow.
- Configurable node settings to allow/disallow deleting, branching and children access.
- Custom events to hook-into.
Installation
via cdn
href="https://unpkg.com/@copyfactory/alpine-flow@latest/dist/flow.css"
rel="stylesheet"
type="text/css"
/>
<script
defer
src="https://unpkg.com/@copyfactory/alpine-flow@latest/dist/alpine-flow.cdn.min.js"
>script>
via npm
import { node, flowEditor } from '@copyfactory/alpine-flow';
import '@copyfactory/alpine-flow/dist/flow.css'
window.Alpine = Alpine
window.Alpine.plugin(node);
window.Alpine.data('flowEditor', flowEditor);
Alpine.start()
Concepts
What is a node?
A node in Alpine Flow is an alpine component with the x-node directive.
That means it can render anything you like. You can find all the options for customizing your nodes further down.
The term 'node' and 'component' will be used interchangeably.
What is an edge?
An edge connects two nodes. Every edge needs a target node ID and a source node ID. The the most part edges addition and removal will be handled for you when using the public methods.
Quickstart
The Alpine flow package is composed of a directive to declare components x-node
and a data component flowEditor to start a new editor.
The flowEditor only requires nodes and edges to get something going.
Building your first flow
1. Create a node component
Nodes are the building blocks of your editor. Building them is easy. Just add the x-node directive
to any Alpine component with a type and add a props object to your x-data.
The props is automatically synced to any node instances data attribute.
Think of the props as being all the attributes you want to persist to your database.
Consider the following example for a node where we want to apply styling based on some state.
When saving this node we likely don't want to save the 'isClicked' attribute.
Having a clear namespace for properties that should be persisted to each node instance makes it easy to separate styling and data.
x-cloak
x-node="{type: 'my first node'}"
x-data="{isClicked: false, props: {text: 'Default text'}}"
@click="
props.text = (Math.random() + 1).toString(36).substring(7);
isClicked = !isClicked"
>
<div>
<p :style="isClicked && { color: 'green' }" x-text="props.text">p>
div>
div>