@barefootjs/xyflow 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -0
- package/dist/classes.d.ts +31 -0
- package/dist/classes.d.ts.map +1 -0
- package/dist/compat.d.ts +67 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/connection.d.ts +20 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/context.d.ts +7 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/edge-path.d.ts +14 -0
- package/dist/edge-path.d.ts.map +1 -0
- package/dist/flow-subsystems.d.ts +28 -0
- package/dist/flow-subsystems.d.ts.map +1 -0
- package/dist/hooks.d.ts +34 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6572 -0
- package/dist/node-resizer.d.ts +52 -0
- package/dist/node-resizer.d.ts.map +1 -0
- package/dist/node-type-dispatch.d.ts +34 -0
- package/dist/node-type-dispatch.d.ts.map +1 -0
- package/dist/selection.d.ts +32 -0
- package/dist/selection.d.ts.map +1 -0
- package/dist/store.d.ts +8 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/types.d.ts +214 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/xyflow.browser.min.js +95 -0
- package/dist/xyflow.browser.min.js.map +129 -0
- package/package.json +58 -0
- package/src/__tests__/clamp-drag-position.test.ts +111 -0
- package/src/__tests__/compat.test.ts +157 -0
- package/src/__tests__/host-element-store.test.ts +33 -0
- package/src/__tests__/jsx-smoke.test.ts +33 -0
- package/src/__tests__/jsx-smoke.tsx +23 -0
- package/src/__tests__/node-type-dispatch.test.ts +104 -0
- package/src/__tests__/store.test.ts +399 -0
- package/src/__tests__/tsconfig.json +23 -0
- package/src/classes.ts +41 -0
- package/src/compat.ts +237 -0
- package/src/connection.ts +459 -0
- package/src/constants.ts +8 -0
- package/src/context.ts +8 -0
- package/src/edge-path.ts +89 -0
- package/src/flow-subsystems.ts +506 -0
- package/src/hooks.ts +72 -0
- package/src/index.ts +134 -0
- package/src/node-resizer.ts +276 -0
- package/src/node-type-dispatch.ts +46 -0
- package/src/selection.ts +407 -0
- package/src/store.ts +526 -0
- package/src/types.ts +329 -0
- package/src/utils.ts +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @barefootjs/xyflow
|
|
2
|
+
|
|
3
|
+
Signal-based wrapper around [`@xyflow/system`](https://www.npmjs.com/package/@xyflow/system)
|
|
4
|
+
for [BarefootJS](https://barefootjs.dev). Ships the **utility layer**
|
|
5
|
+
(store, signal hooks, types, geometry helpers, imperative
|
|
6
|
+
pointer-paced subsystems). The **JSX-native renderer components**
|
|
7
|
+
(`Flow`, `Background`, `Controls`, `MiniMap`, `Handle`, `NodeWrapper`,
|
|
8
|
+
`SimpleEdge`) live in the shadcn-style registry at
|
|
9
|
+
[`ui/components/ui/xyflow/`](../../ui/components/ui/xyflow/) and ship
|
|
10
|
+
to consumers via:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
bf add xyflow # via the BarefootJS CLI
|
|
14
|
+
npx shadcn@latest add https://ui.barefootjs.dev/r/xyflow.json
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This split mirrors the chart pattern (`@barefootjs/chart` for utility,
|
|
18
|
+
`ui/components/ui/chart/` for JSX components).
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
"use client"
|
|
24
|
+
|
|
25
|
+
import { Flow, Background, Controls, MiniMap } from "@/components/ui/xyflow"
|
|
26
|
+
import { useNodesState, useEdgesState } from "@barefootjs/xyflow"
|
|
27
|
+
|
|
28
|
+
const initialNodes = [
|
|
29
|
+
{ id: "1", position: { x: 100, y: 100 }, data: { label: "Input" } },
|
|
30
|
+
{ id: "2", position: { x: 350, y: 50 }, data: { label: "Transform" } },
|
|
31
|
+
{ id: "3", position: { x: 600, y: 125 }, data: { label: "Output" } },
|
|
32
|
+
]
|
|
33
|
+
const initialEdges = [
|
|
34
|
+
{ id: "e1-2", source: "1", target: "2" },
|
|
35
|
+
{ id: "e2-3", source: "2", target: "3" },
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
export function MyCanvas() {
|
|
39
|
+
const [nodes, setNodes] = useNodesState(initialNodes)
|
|
40
|
+
const [edges, setEdges] = useEdgesState(initialEdges)
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className="w-full h-[420px]">
|
|
44
|
+
<Flow nodes={nodes()} edges={edges()}>
|
|
45
|
+
<Background variant="dots" gap={20} />
|
|
46
|
+
<Controls />
|
|
47
|
+
<MiniMap pannable zoomable />
|
|
48
|
+
</Flow>
|
|
49
|
+
</div>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Custom node bodies
|
|
55
|
+
|
|
56
|
+
The default `<Flow>` loop renders `data.label ?? id` inside each
|
|
57
|
+
`<NodeWrapper>`. To compose custom node bodies, mount your own
|
|
58
|
+
`<NodeWrapper>` instances as Flow children:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
<Flow nodes={nodes()} edges={edges()}>
|
|
62
|
+
<Background />
|
|
63
|
+
{nodes().map((n) => (
|
|
64
|
+
<NodeWrapper key={n.id} nodeId={n.id}>
|
|
65
|
+
<div className="rounded-md border bg-card px-3 py-2">
|
|
66
|
+
{n.data.label}
|
|
67
|
+
<Handle type="target" position={Position.Left} nodeId={n.id} />
|
|
68
|
+
<Handle type="source" position={Position.Right} nodeId={n.id} />
|
|
69
|
+
</div>
|
|
70
|
+
</NodeWrapper>
|
|
71
|
+
))}
|
|
72
|
+
</Flow>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## What this package exports
|
|
76
|
+
|
|
77
|
+
| Surface | Item | Purpose |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| Store / state | `createFlowStore`, `FlowContext` | Reactive node / edge / viewport state |
|
|
80
|
+
| Hooks | `useFlow`, `useViewport`, `useNodes`, `useEdges`, `useNodesInitialized`, `useStore`, `screenToFlowPosition` | Read store from descendants |
|
|
81
|
+
| React Flow shim | `useNodesState`, `useEdgesState`, `useReactFlow`, `addEdge`, `reconnectEdge` | Drop-in helpers for migrators |
|
|
82
|
+
| Geometry | `computeEdgePosition`, `getEdgePath` | Path math shared with `<SimpleEdge>` |
|
|
83
|
+
| Subsystem attach | `attachFlowSubsystems` | `<Flow>`'s `ref` calls this — pan / zoom / keyboard / selection rectangle / pane click |
|
|
84
|
+
| Subsystem attach | `attachConnectionHandler`, `attachReconnectionHandler` | `<Handle>` and reconnect overlay refs |
|
|
85
|
+
| Imperative-only | `setupKeyboardHandlers`, `setupNodeSelection`, `setupSelectionRectangle`, `initNodeResizer` | Pointer-paced primitives that JSX gives no leverage to |
|
|
86
|
+
| Re-exports | `getBezierPath`, `getSmoothStepPath`, `getStraightPath`, `getConnectedEdges`, `getOutgoers`, `getIncomers`, `getNodesBounds`, `getNodesInside`, `getEdgeToolbarTransform`, `Position`, `MarkerType`, `ConnectionMode` | From `@xyflow/system` |
|
|
87
|
+
| Types | `FlowProps`, `FlowStore`, `InternalFlowStore`, `NodeBase`, `EdgeBase`, `Viewport`, `NodeLookup`, `EdgeLookup`, `Connection`, `OnConnect`, `OnReconnect`, `IsValidConnection`, `HandleType`, … | (see `src/types.ts`) |
|
|
88
|
+
|
|
89
|
+
## Source layout
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
src/
|
|
93
|
+
├── index.ts re-exports the utility surface above
|
|
94
|
+
├── store.ts createFlowStore + signal wiring
|
|
95
|
+
├── hooks.ts useFlow / useViewport / useNodes / ...
|
|
96
|
+
├── context.ts FlowContext
|
|
97
|
+
├── types.ts FlowProps / FlowStore / InternalFlowStore / ...
|
|
98
|
+
├── constants.ts SVG_NS / INFINITE_EXTENT / ...
|
|
99
|
+
├── utils.ts misc helpers
|
|
100
|
+
├── edge-path.ts computeEdgePosition / getEdgePath
|
|
101
|
+
├── flow-subsystems.ts attachFlowSubsystems (panZoom + ResizeObserver + ...)
|
|
102
|
+
├── connection.ts attachConnectionHandler / attachReconnectionHandler
|
|
103
|
+
├── selection.ts setupKeyboardHandlers / setupSelectionRectangle / setupNodeSelection
|
|
104
|
+
├── node-resizer.ts initNodeResizer (pointer-paced resize handles)
|
|
105
|
+
├── compat.ts React Flow API shims
|
|
106
|
+
└── __tests__/ store / compat / jsx-smoke unit tests
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
JSX-native components are deliberately **not** in this package — they
|
|
110
|
+
live in `ui/components/ui/xyflow/index.tsx` so consumers `add` the
|
|
111
|
+
source directly into their app, can edit it, and own their own copy
|
|
112
|
+
(shadcn pattern). This avoids the JSX-runtime resolution headaches
|
|
113
|
+
that come from publishing `.tsx` directly from a workspace package.
|
|
114
|
+
|
|
115
|
+
## Related
|
|
116
|
+
|
|
117
|
+
- [`@xyflow/system`](https://www.npmjs.com/package/@xyflow/system) — upstream pan/zoom + edge-path math library this package wraps.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable CSS class names for xyflow primitives.
|
|
3
|
+
*
|
|
4
|
+
* Exported as constants so the registry-side `<Flow>` / `<Background>` /
|
|
5
|
+
* etc. can reference them via `className={BF_FLOW}` instead of
|
|
6
|
+
* `className="bf-flow"`. site/ui's `cssLayerPrefixer` only rewrites
|
|
7
|
+
* locally-declared static `className` literals; imported identifiers are
|
|
8
|
+
* left alone, which keeps `bf-flow*` un-prefixed for the e2e selectors
|
|
9
|
+
* (the same trick chart uses with `CHART_CLASS_GRID` etc.).
|
|
10
|
+
*/
|
|
11
|
+
export declare const BF_FLOW = "bf-flow";
|
|
12
|
+
export declare const BF_FLOW_VIEWPORT = "bf-flow__viewport";
|
|
13
|
+
export declare const BF_FLOW_EDGES = "bf-flow__edges";
|
|
14
|
+
export declare const BF_FLOW_NODES = "bf-flow__nodes";
|
|
15
|
+
export declare const BF_FLOW_NODE = "bf-flow__node";
|
|
16
|
+
export declare const BF_FLOW_NODE_GROUP = "bf-flow__node--group";
|
|
17
|
+
export declare const BF_FLOW_NODE_CHILD = "bf-flow__node--child";
|
|
18
|
+
export declare const BF_FLOW_NODE_SELECTED = "bf-flow__node--selected";
|
|
19
|
+
export declare const BF_FLOW_NODE_CUSTOM = "bf-flow__node--custom";
|
|
20
|
+
export declare const BF_FLOW_EDGE = "bf-flow__edge";
|
|
21
|
+
export declare const BF_FLOW_EDGE_SELECTED = "bf-flow__edge--selected";
|
|
22
|
+
export declare const BF_FLOW_EDGE_ANIMATED = "bf-flow__edge--animated";
|
|
23
|
+
export declare const BF_FLOW_HANDLE = "bf-flow__handle";
|
|
24
|
+
export declare const BF_FLOW_HANDLE_TARGET = "bf-flow__handle--target";
|
|
25
|
+
export declare const BF_FLOW_HANDLE_SOURCE = "bf-flow__handle--source";
|
|
26
|
+
export declare const BF_FLOW_CONTROLS = "bf-flow__controls";
|
|
27
|
+
export declare const BF_FLOW_CONTROLS_BUTTON = "bf-flow__controls-button";
|
|
28
|
+
export declare const BF_FLOW_MINIMAP = "bf-flow__minimap";
|
|
29
|
+
export declare const BF_FLOW_MINIMAP_MASK = "bf-flow__minimap-mask";
|
|
30
|
+
export declare const XYFLOW_VIEWPORT = "xyflow__viewport";
|
|
31
|
+
//# sourceMappingURL=classes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../src/classes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,eAAO,MAAM,OAAO,YAAY,CAAA;AAChC,eAAO,MAAM,gBAAgB,sBAAsB,CAAA;AACnD,eAAO,MAAM,aAAa,mBAAmB,CAAA;AAC7C,eAAO,MAAM,aAAa,mBAAmB,CAAA;AAE7C,eAAO,MAAM,YAAY,kBAAkB,CAAA;AAC3C,eAAO,MAAM,kBAAkB,yBAAyB,CAAA;AACxD,eAAO,MAAM,kBAAkB,yBAAyB,CAAA;AACxD,eAAO,MAAM,qBAAqB,4BAA4B,CAAA;AAG9D,eAAO,MAAM,mBAAmB,0BAA0B,CAAA;AAE1D,eAAO,MAAM,YAAY,kBAAkB,CAAA;AAC3C,eAAO,MAAM,qBAAqB,4BAA4B,CAAA;AAC9D,eAAO,MAAM,qBAAqB,4BAA4B,CAAA;AAE9D,eAAO,MAAM,cAAc,oBAAoB,CAAA;AAC/C,eAAO,MAAM,qBAAqB,4BAA4B,CAAA;AAC9D,eAAO,MAAM,qBAAqB,4BAA4B,CAAA;AAE9D,eAAO,MAAM,gBAAgB,sBAAsB,CAAA;AACnD,eAAO,MAAM,uBAAuB,6BAA6B,CAAA;AAEjE,eAAO,MAAM,eAAe,qBAAqB,CAAA;AACjD,eAAO,MAAM,oBAAoB,0BAA0B,CAAA;AAI3D,eAAO,MAAM,eAAe,qBAAqB,CAAA"}
|
package/dist/compat.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Flow compatibility shims for desk migration.
|
|
3
|
+
*
|
|
4
|
+
* These functions mirror the React Flow hooks API so that
|
|
5
|
+
* desk components can be ported with minimal changes.
|
|
6
|
+
*/
|
|
7
|
+
import type { NodeBase, EdgeBase, Viewport, XYPosition } from './types';
|
|
8
|
+
import type { Connection, NodeChange, EdgeChange } from '@xyflow/system';
|
|
9
|
+
/**
|
|
10
|
+
* useNodesState — mirrors React Flow's useNodesState.
|
|
11
|
+
* Returns [nodes getter, setNodes, onNodesChange handler].
|
|
12
|
+
*/
|
|
13
|
+
export declare function useNodesState<NodeType extends NodeBase = NodeBase>(initialNodes: NodeType[]): [() => NodeType[], (updater: NodeType[] | ((prev: NodeType[]) => NodeType[])) => void, (changes: NodeChange[]) => void];
|
|
14
|
+
/**
|
|
15
|
+
* useEdgesState — mirrors React Flow's useEdgesState.
|
|
16
|
+
* Returns [edges getter, setEdges, onEdgesChange handler].
|
|
17
|
+
*/
|
|
18
|
+
export declare function useEdgesState<EdgeType extends EdgeBase = EdgeBase>(initialEdges: EdgeType[]): [() => EdgeType[], (updater: EdgeType[] | ((prev: EdgeType[]) => EdgeType[])) => void, (changes: EdgeChange[]) => void];
|
|
19
|
+
/**
|
|
20
|
+
* useReactFlow — mirrors React Flow's useReactFlow hook.
|
|
21
|
+
* Returns an object with common flow manipulation methods.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useReactFlow<NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(): {
|
|
24
|
+
getNodes: () => NodeType[];
|
|
25
|
+
getEdges: () => EdgeType[];
|
|
26
|
+
getNode: (id: string) => NodeType | undefined;
|
|
27
|
+
getZoom: () => number;
|
|
28
|
+
getViewport: () => Viewport;
|
|
29
|
+
setNodes: (valueOrFn: NodeType[] | ((prev: NodeType[]) => NodeType[])) => void;
|
|
30
|
+
setEdges: (valueOrFn: EdgeType[] | ((prev: EdgeType[]) => EdgeType[])) => void;
|
|
31
|
+
setViewport: (vp: Viewport) => void;
|
|
32
|
+
setCenter: (x: number, y: number, options?: {
|
|
33
|
+
zoom?: number;
|
|
34
|
+
duration?: number;
|
|
35
|
+
}) => void;
|
|
36
|
+
fitView: (options?: import("./types").FitViewOptions) => void;
|
|
37
|
+
zoomIn: (options?: {
|
|
38
|
+
duration?: number;
|
|
39
|
+
}) => void;
|
|
40
|
+
zoomOut: (options?: {
|
|
41
|
+
duration?: number;
|
|
42
|
+
}) => void;
|
|
43
|
+
zoomTo: (zoom: number, options?: {
|
|
44
|
+
duration?: number;
|
|
45
|
+
}) => void;
|
|
46
|
+
updateNode: (id: string, update: Partial<NodeType> | ((node: NodeType) => Partial<NodeType>)) => void;
|
|
47
|
+
updateNodeData: (id: string, data: Partial<NodeType['data']> | ((prev: NodeType['data']) => Partial<NodeType['data']>)) => void;
|
|
48
|
+
addEdges: (newEdges: EdgeType[]) => void;
|
|
49
|
+
deleteElements: (params: {
|
|
50
|
+
nodes?: NodeType[] | undefined;
|
|
51
|
+
edges?: EdgeType[] | undefined;
|
|
52
|
+
}) => void;
|
|
53
|
+
screenToFlowPosition: (position: XYPosition) => XYPosition;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* useViewport — reactive viewport getter.
|
|
57
|
+
*/
|
|
58
|
+
export { useViewport } from './hooks';
|
|
59
|
+
/**
|
|
60
|
+
* addEdge utility — wraps @xyflow/system's addEdge.
|
|
61
|
+
*/
|
|
62
|
+
export declare function addEdge<EdgeType extends EdgeBase = EdgeBase>(connection: Connection, edges: EdgeType[]): EdgeType[];
|
|
63
|
+
/**
|
|
64
|
+
* reconnectEdge utility — wraps @xyflow/system's reconnectEdge.
|
|
65
|
+
*/
|
|
66
|
+
export declare function reconnectEdge<EdgeType extends EdgeBase = EdgeBase>(oldEdge: EdgeType, newConnection: Connection, edges: EdgeType[]): EdgeType[];
|
|
67
|
+
//# sourceMappingURL=compat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../src/compat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAExE;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EAChE,YAAY,EAAE,QAAQ,EAAE,GACvB,CAAC,MAAM,QAAQ,EAAE,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC,CASzH;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EAChE,YAAY,EAAE,QAAQ,EAAE,GACvB,CAAC,MAAM,QAAQ,EAAE,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC,CASzH;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EACpC,QAAQ,SAAS,QAAQ,GAAG,QAAQ;IAMlC,QAAQ,QAAM,QAAQ,EAAE;IACxB,QAAQ,QAAM,QAAQ,EAAE;IACxB,OAAO,OAAO,MAAM,KAAG,QAAQ,GAAG,SAAS;IAE3C,OAAO,QAAM,MAAM;IACnB,WAAW,QAAM,QAAQ;IAGzB,QAAQ;IACR,QAAQ;IACR,WAAW,OAAO,QAAQ;IAI1B,SAAS,MAAM,MAAM,KAAK,MAAM,YAAY;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;IAahF,OAAO;IACP,MAAM,aAAa;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;IAIxC,OAAO,aAAa;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;IAIzC,MAAM,SAAS,MAAM,YAAY;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE;IAMtD,UAAU,OAAO,MAAM,UAAU,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAS5F,cAAc,OAAO,MAAM,QAAQ,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAWtH,QAAQ,aAAa,QAAQ,EAAE;IAK/B,cAAc;;;;IAGd,oBAAoB,aAAa,UAAU,KAAG,UAAU;EAW3D;AAED;;GAEG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAErC;;GAEG;AACH,wBAAgB,OAAO,CAAC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EAC1D,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,QAAQ,EAAE,GAChB,QAAQ,EAAE,CAEZ;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EAChE,OAAO,EAAE,QAAQ,EACjB,aAAa,EAAE,UAAU,EACzB,KAAK,EAAE,QAAQ,EAAE,GAChB,QAAQ,EAAE,CAEZ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FlowStore, NodeBase, EdgeBase } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Attach a connection drag handler to a handle element.
|
|
4
|
+
* Called when creating each handle in node-wrapper.
|
|
5
|
+
*/
|
|
6
|
+
export declare function attachConnectionHandler<NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(handleEl: HTMLElement, nodeId: string, handleType: 'source' | 'target', container: HTMLElement, _edgesSvg: SVGSVGElement, store: FlowStore<NodeType, EdgeType>): void;
|
|
7
|
+
/**
|
|
8
|
+
* Attach a reconnection drag handler to an edge endpoint handle.
|
|
9
|
+
* Dragging this handle detaches the edge from its source/target and allows
|
|
10
|
+
* reconnecting to a different handle.
|
|
11
|
+
*
|
|
12
|
+
* @param handleEl - The SVG circle element acting as the reconnection grip
|
|
13
|
+
* @param edge - The edge being reconnected
|
|
14
|
+
* @param endpointType - Which endpoint of the edge is being dragged ('source' | 'target')
|
|
15
|
+
* @param container - The flow container element
|
|
16
|
+
* @param edgesSvg - The SVG element containing edge paths
|
|
17
|
+
* @param store - The flow store
|
|
18
|
+
*/
|
|
19
|
+
export declare function attachReconnectionHandler<NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(handleEl: SVGCircleElement, edge: EdgeType, endpointType: 'source' | 'target', container: HTMLElement, edgesSvg: SVGSVGElement, store: FlowStore<NodeType, EdgeType>): void;
|
|
20
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAc,MAAM,SAAS,CAAA;AA4CxE;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EACpC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EAEpC,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,QAAQ,GAAG,QAAQ,EAC/B,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,aAAa,EACxB,KAAK,EAAE,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,GACnC,IAAI,CAoON;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EACpC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EAEpC,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,QAAQ,EACd,YAAY,EAAE,QAAQ,GAAG,QAAQ,EACjC,SAAS,EAAE,WAAW,EACtB,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,GACnC,IAAI,CAkJN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,eAAO,MAAM,MAAM,+BAA+B,CAAA;AAElD,eAAO,MAAM,eAAe,EAAE,gBAG7B,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FlowStore } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Context for sharing the flow store across child components.
|
|
4
|
+
* Provided by initFlow, consumed by child init functions (e.g., handles, custom nodes).
|
|
5
|
+
*/
|
|
6
|
+
export declare const FlowContext: import("@barefootjs/client").Context<FlowStore>;
|
|
7
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC;;;GAGG;AACH,eAAO,MAAM,WAAW,iDAA6B,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EdgeBase, EdgePosition, InternalNodeBase } from '@xyflow/system';
|
|
2
|
+
export type EdgePathTuple = [string, number, number, number, number];
|
|
3
|
+
/**
|
|
4
|
+
* Compute endpoint positions for an edge, falling back to a node-center
|
|
5
|
+
* straight line when no handle bounds are available yet (e.g. before the
|
|
6
|
+
* first measure has populated `nodeLookup`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function computeEdgePosition(edge: EdgeBase, sourceNode: InternalNodeBase, targetNode: InternalNodeBase): EdgePosition | null;
|
|
9
|
+
/**
|
|
10
|
+
* Calculate edge path based on edge type. Returns
|
|
11
|
+
* `[d, labelX, labelY, offsetX, offsetY]` or `null`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEdgePath(edge: EdgeBase, pos: EdgePosition): EdgePathTuple | null;
|
|
14
|
+
//# sourceMappingURL=edge-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edge-path.d.ts","sourceRoot":"","sources":["../src/edge-path.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAE9E,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAEpE;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,QAAQ,EACd,UAAU,EAAE,gBAAgB,EAC5B,UAAU,EAAE,gBAAgB,GAC3B,YAAY,GAAG,IAAI,CA2BrB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,QAAQ,EACd,GAAG,EAAE,YAAY,GAChB,aAAa,GAAG,IAAI,CA0BtB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { InternalNodeBase, NodeLookup, XYPosition } from '@xyflow/system';
|
|
2
|
+
import type { FlowProps, InternalFlowStore, NodeBase, EdgeBase } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Clamp a child node's drag position so the node's rect stays inside
|
|
5
|
+
* its parent's rect — implements xyflow's `extent: 'parent'` contract
|
|
6
|
+
* for the pointer-paced single-node drag handler.
|
|
7
|
+
*
|
|
8
|
+
* Operates on the **relative** coordinate the parent-relative model
|
|
9
|
+
* stores in `userNode.position`: the constraint per axis is
|
|
10
|
+
* `0 ≤ pos ≤ parentSize − childSize`. Returns the input unchanged when
|
|
11
|
+
* the node has no `parentId`, isn't `extent: 'parent'`, the parent is
|
|
12
|
+
* missing, or either node is unmeasured.
|
|
13
|
+
*
|
|
14
|
+
* Exposed (non-default-export) so the same primitive can be reused if
|
|
15
|
+
* the C4 XYDrag integration replaces the inline drag handler — the
|
|
16
|
+
* extent contract remains the same.
|
|
17
|
+
*/
|
|
18
|
+
export declare function clampDragPositionToParent(position: XYPosition, nodeId: string, lookup: NodeLookup<InternalNodeBase<NodeBase>>): XYPosition;
|
|
19
|
+
/**
|
|
20
|
+
* Attach all pointer-paced + ResizeObserver-based subsystems to the
|
|
21
|
+
* outer `<div class="bf-flow">` rendered by the JSX `<Flow>` component.
|
|
22
|
+
*
|
|
23
|
+
* Inside a reactive root (`createRoot`), this also registers
|
|
24
|
+
* `onCleanup` callbacks for the panZoom destroy / ResizeObserver
|
|
25
|
+
* disconnect / keyboard listener removal lifecycle.
|
|
26
|
+
*/
|
|
27
|
+
export declare function attachFlowSubsystems<NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(el: HTMLElement, store: InternalFlowStore<NodeType, EdgeType>, props: FlowProps<NodeType, EdgeType>): void;
|
|
28
|
+
//# sourceMappingURL=flow-subsystems.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-subsystems.d.ts","sourceRoot":"","sources":["../src/flow-subsystems.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAuB,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAInG,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAE/E;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,UAAU,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,GAC7C,UAAU,CAqBZ;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EACpC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EAEpC,EAAE,EAAE,WAAW,EACf,KAAK,EAAE,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAC5C,KAAK,EAAE,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,GACnC,IAAI,CAiTN"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FlowStore, Viewport, NodeBase, EdgeBase, XYPosition } from './types';
|
|
2
|
+
import type { Signal, Memo } from '@barefootjs/client/runtime';
|
|
3
|
+
/**
|
|
4
|
+
* Access the flow store from any child component.
|
|
5
|
+
* Must be called within a component rendered inside a Flow.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useFlow<NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(): FlowStore<NodeType, EdgeType>;
|
|
8
|
+
/**
|
|
9
|
+
* Access the current viewport (reactive getter).
|
|
10
|
+
*/
|
|
11
|
+
export declare function useViewport(): Signal<Viewport>[0];
|
|
12
|
+
/**
|
|
13
|
+
* Access the nodes array (reactive getter).
|
|
14
|
+
*/
|
|
15
|
+
export declare function useNodes<NodeType extends NodeBase = NodeBase>(): Signal<NodeType[]>[0];
|
|
16
|
+
/**
|
|
17
|
+
* Access the edges array (reactive getter).
|
|
18
|
+
*/
|
|
19
|
+
export declare function useEdges<EdgeType extends EdgeBase = EdgeBase>(): Signal<EdgeType[]>[0];
|
|
20
|
+
/**
|
|
21
|
+
* Access whether nodes have been initialized (all measured).
|
|
22
|
+
*/
|
|
23
|
+
export declare function useNodesInitialized(): Memo<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Select derived state from the flow store.
|
|
26
|
+
* Similar to React Flow's useStore(selector).
|
|
27
|
+
*/
|
|
28
|
+
export declare function useStore<T>(selector: (store: FlowStore) => T): Memo<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Convert a screen position to flow coordinates.
|
|
31
|
+
* Accounts for viewport transform (pan/zoom) and container offset.
|
|
32
|
+
*/
|
|
33
|
+
export declare function screenToFlowPosition(position: XYPosition): XYPosition;
|
|
34
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAA;AAE9D;;;GAGG;AACH,wBAAgB,OAAO,CACrB,QAAQ,SAAS,QAAQ,GAAG,QAAQ,EACpC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,KACjC,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAEjC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEjD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAEtF;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,SAAS,QAAQ,GAAG,QAAQ,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAEtF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAAC,OAAO,CAAC,CAEnD;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAGtE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,UAAU,GAAG,UAAU,CAYrE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { createFlowStore } from './store';
|
|
2
|
+
export { FlowContext } from './context';
|
|
3
|
+
export { useFlow, useViewport, useNodes, useEdges, useNodesInitialized, useStore, screenToFlowPosition, } from './hooks';
|
|
4
|
+
export { computeEdgePosition, getEdgePath } from './edge-path';
|
|
5
|
+
export type { EdgePathTuple } from './edge-path';
|
|
6
|
+
export { attachFlowSubsystems, clampDragPositionToParent } from './flow-subsystems';
|
|
7
|
+
export { attachConnectionHandler, attachReconnectionHandler } from './connection';
|
|
8
|
+
export { dispatchNodeType } from './node-type-dispatch';
|
|
9
|
+
export type { NodeInitFn } from './node-type-dispatch';
|
|
10
|
+
export { initNodeResizer, ResizeControlVariant } from './node-resizer';
|
|
11
|
+
export type { NodeResizerOptions, ControlPosition, ControlLinePosition, OnResize, OnResizeStart, OnResizeEnd, ShouldResize, ResizeControlDirection, } from './node-resizer';
|
|
12
|
+
export { setupKeyboardHandlers, setupNodeSelection, setupSelectionRectangle } from './selection';
|
|
13
|
+
export type { SelectionRectOptions } from './selection';
|
|
14
|
+
export { BF_FLOW, BF_FLOW_VIEWPORT, BF_FLOW_EDGES, BF_FLOW_NODES, BF_FLOW_NODE, BF_FLOW_NODE_GROUP, BF_FLOW_NODE_CHILD, BF_FLOW_NODE_SELECTED, BF_FLOW_NODE_CUSTOM, BF_FLOW_EDGE, BF_FLOW_EDGE_SELECTED, BF_FLOW_EDGE_ANIMATED, BF_FLOW_HANDLE, BF_FLOW_HANDLE_TARGET, BF_FLOW_HANDLE_SOURCE, BF_FLOW_CONTROLS, BF_FLOW_CONTROLS_BUTTON, BF_FLOW_MINIMAP, BF_FLOW_MINIMAP_MASK, XYFLOW_VIEWPORT, } from './classes';
|
|
15
|
+
export type { FlowProps, FlowStore, InternalFlowStore, FlowStoreOptions, FitViewOptions, NodeBase, EdgeBase, InternalNodeBase, Viewport, NodeLookup, ParentLookup, EdgeLookup, ConnectionLookup, CoordinateExtent, SnapGrid, NodeOrigin, Transform, PanZoomInstance, XYPosition, OnConnect, OnConnectStart, OnConnectEnd, IsValidConnection, NodeDragItem, ConnectionMode, NodeComponentProps, EdgeComponentProps, SelectionMode, OnReconnect, Connection, } from './types';
|
|
16
|
+
export type { HandleType } from '@xyflow/system';
|
|
17
|
+
export { useNodesState, useEdgesState, useReactFlow, addEdge, reconnectEdge } from './compat';
|
|
18
|
+
export { getBezierPath, getSmoothStepPath, getStraightPath, getConnectedEdges, getOutgoers, getIncomers, getNodesBounds, getNodesInside, getEdgeToolbarTransform, Position, ConnectionMode as ConnectionModeEnum, MarkerType, } from '@xyflow/system';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EACL,OAAO,EACP,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,QAAQ,EACR,oBAAoB,GACrB,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9D,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAOhD,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AACnF,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACtE,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,QAAQ,EACR,aAAa,EACb,WAAW,EACX,YAAY,EACZ,sBAAsB,GACvB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAChG,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAMvD,OAAO,EACL,OAAO,EACP,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,eAAe,GAChB,MAAM,WAAW,CAAA;AAIlB,YAAY,EACV,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,SAAS,EACT,eAAe,EACf,UAAU,EACV,SAAS,EACT,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,UAAU,GACX,MAAM,SAAS,CAAA;AAIhB,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGhD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAG7F,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,cAAc,EACd,cAAc,EACd,uBAAuB,EACvB,QAAQ,EACR,cAAc,IAAI,kBAAkB,EACpC,UAAU,GACX,MAAM,gBAAgB,CAAA"}
|