### Basic Canvas Setup with Nodes and Edges
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/canvas/selection.md
This example demonstrates the basic setup of a canvas with predefined nodes and edges. It configures the canvas to be non-pannable and non-zoomable, primarily for showcasing selection interactions.
```html
```
--------------------------------
### Full Canvas Example with Default Handles
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/handles/positions.md
A complete example of an Alpine.js flow canvas setup demonstrating nodes with default source and target handles. This serves as a foundational example for integrating flow diagrams.
```html
```
--------------------------------
### Full Directive Example
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/animation/timeline.md
An example demonstrating the full usage of the `x-flow-timeline` directive with various configuration options and playback controls.
```APIDOC
## Full Directive Example
```html
```
```
--------------------------------
### Basic Canvas with Interactive Nodes
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/canvas/keyboard-shortcuts.md
Demonstrates a basic flow canvas setup with nodes that can be interacted with using keyboard shortcuts like arrow keys for movement and delete for removal. This example initializes the canvas with predefined nodes and edges.
```html
```
--------------------------------
### Install AlpineFlow and Alpine.js
Source: https://github.com/getartisanflow/alpineflow/blob/main/README.md
Install the necessary packages using npm. Ensure both Alpine.js and AlpineFlow are included in your project dependencies.
```bash
npm install @getartisanflow/alpineflow alpinejs
```
--------------------------------
### Minimal Flow Setup
Source: https://github.com/getartisanflow/alpineflow/blob/main/boost/skills/alpineflow-development/SKILL.md
Use this for basic flow diagrams with nodes and edges. Ensure the container has a defined height.
```html
```
--------------------------------
### Install Optional Real-time Collaboration Addon
Source: https://github.com/getartisanflow/alpineflow/blob/main/README.md
Install the necessary packages for real-time collaboration features. This includes yjs, y-websocket, and y-protocols.
```bash
# Real-time collaboration
npm install yjs y-websocket y-protocols
import AlpineFlowCollab from '@getartisanflow/alpineflow/collab';
```
--------------------------------
### Basic Flow Canvas Setup
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/configuration/connections.md
Sets up a basic flow canvas with nodes and configures connection snapping and cycle prevention.
```html
```
--------------------------------
### Canvas Setup with Selection on Drag Enabled
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/canvas/selection.md
This example configures the canvas to enable selection on drag, allowing users to draw a selection box to select multiple nodes. It also includes pan-on-drag functionality for a smoother user experience.
```html
```
--------------------------------
### Install Collaboration Addon Dependencies
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/addons/collab.md
Install the necessary peer dependencies for the Collaboration addon using npm.
```bash
npm install yjs y-websocket y-protocols
```
--------------------------------
### Basic Flow Canvas with Touch Interactions
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/interaction/touch.md
This example demonstrates a basic flow canvas setup with nodes and edges, designed to work with touch interactions like dragging, zooming, and connecting handles.
```html
```
--------------------------------
### Basic Node and Edge Toolbar Example
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/interaction/toolbars.md
Demonstrates the integration of node and edge toolbars within a basic AlpineFlow canvas setup. Node toolbars appear when a node is selected, and edge toolbars appear when an edge is selected. Requires explicit edge rendering for edge toolbars.
```html
```
--------------------------------
### Edge Routing Example
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/compute/overview.md
An example of an edge configuration that routes the 'value' output from a source node to the 'a' input of a target node.
```javascript
{ source: 'num1', sourceHandle: 'value', target: 'adder', targetHandle: 'a' }
```
--------------------------------
### Basic Resizable Node Example
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/nodes/resize.md
Demonstrates adding a resizable node with default handles. The 'fixed' node is explicitly set to non-resizable.
```html
```
--------------------------------
### Full Timeline Directive Example
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/animation/timeline.md
A comprehensive example of the `x-flow-timeline` directive, including configuration options like autoplay, loop, speed, and defining complex animation steps.
```html
```
--------------------------------
### Install AlpineFlow Whiteboard Addon
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/addons/whiteboard.md
Import and register the AlpineFlow Whiteboard addon. No additional peer dependencies are required.
```javascript
import AlpineFlowWhiteboard from '@getartisanflow/alpineflow/whiteboard'
Alpine.plugin(AlpineFlowWhiteboard)
```
--------------------------------
### Install Optional Layout Engines
Source: https://github.com/getartisanflow/alpineflow/blob/main/README.md
Install specific layout engines if needed for advanced graph organization. Choose from Dagre, ELK, or d3-force based on your requirements.
```bash
# Layout engines (install only what you need)
npm install @dagrejs/dagre # for @getartisanflow/alpineflow/dagre
npm install elkjs # for @getartisanflow/alpineflow/elk
npm install d3-force # for @getartisanflow/alpineflow/force
```
--------------------------------
### viewport-move-start
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/api/events.md
Fired when a user gesture (pan/zoom) starts. Config callback: `onViewportMoveStart`.
```APIDOC
## viewport-move-start
### Description
Fired when a user gesture (pan/zoom) starts.
### Payload
```ts
{ viewport: Viewport }
```
### Config Callback
`onViewportMoveStart`
```
--------------------------------
### Edge Toolbar Example - AlpineFlow
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/interaction/toolbars.md
This example demonstrates how to display a toolbar when an edge is selected. The toolbar contains a button to delete the selected edge.
```html
```
--------------------------------
### Mixed Panel Behaviors Example
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/canvas/panels.md
This example showcases two panels with different behaviors: a static legend panel (top-left) and a draggable but non-resizable info panel (bottom-right).
```html
Legend
Static — can't move
```
--------------------------------
### Demo Flow Canvas Setup
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/compute/overview.md
Sets up a flow canvas with number and adder nodes, registering compute functions for each and an event listener to trigger computation.
```html
```
--------------------------------
### Straight Connection Line Example
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/connections/drag-connect.md
Uses the 'straight' connection line type, which is the default. Suitable for simple, direct connections.
```html
```
--------------------------------
### Enable Easy Connect with Alt/Option Key
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/connections/easy-connect.md
This example demonstrates how to enable easy connect functionality and set 'alt' as the modifier key for initiating connections from a node's body.
```html
```
--------------------------------
### Edge Labels: Center, Start, and End Positions
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/edges/labels.md
Demonstrates how to define labels at the center, start, and end of an edge. This setup uses HTML divs for labels, supporting rich styling.
```html
```
--------------------------------
### Full Canvas Example with Left-to-Right Handles
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/handles/positions.md
A complete example of an Alpine.js flow canvas setup, featuring nodes with source handles on the right and target handles on the left. This configuration is ideal for visualizing left-to-right data flows.
```html
```
--------------------------------
### Disable Starting Connections in a Flow Canvas
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/handles/connectable.md
This example illustrates disabling the 'start' connection capability for a specific handle within a flow canvas. The 'no-start' node's source handle cannot initiate connections, but the 'normal' node's handles function as usual.
```html
```
--------------------------------
### Demo: Animate Node and Follow
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/animation/camera-follow.md
This example demonstrates animating a node and having the camera follow its movement. It includes buttons to play the animation and reset the view. The camera follows the animation handle with a zoom level of 2.
```html
```
--------------------------------
### Edge Configuration with Labels and Visibility
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/edges/labels.md
An example JavaScript object defining an edge with custom labels for center, start, and end positions, along with 'hover' visibility.
```javascript
{
id: 'e1',
source: 'a',
target: 'b',
label: 'main',
labelStart: '1',
labelEnd: '*',
labelVisibility: 'hover',
}
```
--------------------------------
### Demo: Multi-Layer Background with Nodes
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/canvas/background.md
This example demonstrates a canvas with a node and a multi-layer background, combining a dot grid with a coarser line grid. It also shows how to configure canvas behavior like `fitViewOnInit`, `controls`, `pannable`, and `zoomable`.
```html
```
--------------------------------
### Initialize Alpine.js with AlpineFlow Plugin
Source: https://github.com/getartisanflow/alpineflow/blob/main/README.md
Import Alpine.js and the AlpineFlow plugin, then register the plugin with Alpine.js before starting the application. This setup is required for using AlpineFlow directives.
```javascript
import Alpine from 'alpinejs';
import AlpineFlow from '@getartisanflow/alpineflow';
Alpine.plugin(AlpineFlow);
Alpine.start();
```
--------------------------------
### Enable Edge Reconnection Globally
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/connections/drag-connect.md
Use the `edgesReconnectable` option to globally enable or disable edge reconnection. This example demonstrates a basic flow setup with reconnection enabled.
```html
```
--------------------------------
### Demo: Loading Overlay with Button Trigger
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/canvas/loading.md
This example demonstrates how to use the x-flow-loading directive with a button to manually trigger a loading state for a specified duration.
```html
```
--------------------------------
### Complete Editable Edge Example
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/edges/editable.md
This example demonstrates a complete setup for an editable edge within an AlpineFlow canvas. It includes node and edge definitions, with the edge specified as 'editable' and configured with control points and path style. Users can interact with this edge by double-clicking to add waypoints, dragging them to reshape the path, and double-clicking waypoints to remove them.
```html
```
--------------------------------
### Handle Arrow Drawing Completion
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/addons/whiteboard.md
Use the `@flow-arrow-draw` event to capture arrow drawing data and create annotation nodes. This example extracts start and end points, `strokeColor`, `strokeWidth`, and `opacity`.
```html
@flow-arrow-draw="addNodes([{
id: 'ann-' + Date.now() + '-' + Math.random().toString(36).slice(2, 7),
position: { x: 0, y: 0 },
draggable: false, selectable: false,
class: 'flow-node-annotation',
data: { annotation: 'arrow', start: $event.detail.start, end: $event.detail.end, strokeColor: $event.detail.strokeColor, strokeWidth: $event.detail.strokeWidth, opacity: $event.detail.opacity },
}])"
```
--------------------------------
### Basic Drag to Connect Canvas Setup
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/connections/drag-connect.md
Sets up a canvas with nodes and handles for drag-to-connect functionality. Ensure the 'flow-container' class and 'x-flow-viewport' directive are applied.
```html
```
--------------------------------
### Set Edge Color to Gradient
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/edges/gradients.md
Use a gradient object with 'from' and 'to' properties to define a two-color linear gradient along the edge stroke. This example shows a basic setup for a gradient edge.
```javascript
{
id: 'e1',
source: 'a',
target: 'b',
color: { from: '#22c55e', to: '#ef4444' },
}
```
--------------------------------
### init
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/api/events.md
Fired after the canvas is fully initialized. Config callback: `onInit`.
```APIDOC
## init
### Description
Fired after the canvas is fully initialized.
### Payload
```ts
undefined
```
### Config Callback
`onInit`
```
--------------------------------
### Animate Node Along Wave Path
Source: https://github.com/getartisanflow/alpineflow/blob/main/docs/animation/paths.md
Animates a node named 'data' to follow a wave motion between specified start and end points. This example uses the `wave` path function with a 'reverse' loop for a ping-pong effect.
```javascript
$flow.animate({
nodes: {
'data': {
followPath: wave({
startX: 0, startY: 100,
endX: 400, endY: 100,
amplitude: 50,
frequency: 2,
}),
},
},
}, { duration: 2000, loop: 'reverse' });
```