@octanejs/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/LICENSE +21 -0
- package/README.md +26 -0
- package/package.json +69 -0
- package/src/additional-components/Background/Background.tsrx +144 -0
- package/src/additional-components/Background/Patterns.tsrx +32 -0
- package/src/additional-components/Background/index.tsrx +2 -0
- package/src/additional-components/Background/types.ts +60 -0
- package/src/additional-components/Controls/ControlButton.tsrx +34 -0
- package/src/additional-components/Controls/Controls.tsrx +148 -0
- package/src/additional-components/Controls/Icons/FitView.tsrx +7 -0
- package/src/additional-components/Controls/Icons/Lock.tsrx +7 -0
- package/src/additional-components/Controls/Icons/Minus.tsrx +5 -0
- package/src/additional-components/Controls/Icons/Plus.tsrx +5 -0
- package/src/additional-components/Controls/Icons/Unlock.tsrx +7 -0
- package/src/additional-components/Controls/index.tsrx +3 -0
- package/src/additional-components/Controls/types.ts +68 -0
- package/src/additional-components/EdgeToolbar/EdgeToolbar.tsrx +79 -0
- package/src/additional-components/EdgeToolbar/index.tsrx +2 -0
- package/src/additional-components/EdgeToolbar/types.ts +14 -0
- package/src/additional-components/MiniMap/MiniMap.tsrx +249 -0
- package/src/additional-components/MiniMap/MiniMapNode.tsrx +43 -0
- package/src/additional-components/MiniMap/MiniMapNodes.tsrx +136 -0
- package/src/additional-components/MiniMap/index.ts +3 -0
- package/src/additional-components/MiniMap/types.ts +139 -0
- package/src/additional-components/NodeResizer/NodeResizeControl.tsrx +250 -0
- package/src/additional-components/NodeResizer/NodeResizer.tsrx +102 -0
- package/src/additional-components/NodeResizer/index.ts +4 -0
- package/src/additional-components/NodeResizer/types.ts +122 -0
- package/src/additional-components/NodeToolbar/NodeToolbar.tsrx +141 -0
- package/src/additional-components/NodeToolbar/NodeToolbarPortal.tsrx +17 -0
- package/src/additional-components/NodeToolbar/index.tsrx +2 -0
- package/src/additional-components/NodeToolbar/types.ts +32 -0
- package/src/additional-components/index.ts +6 -0
- package/src/components/A11yDescriptions/index.tsrx +58 -0
- package/src/components/Attribution/index.tsrx +31 -0
- package/src/components/BatchProvider/index.tsrx +122 -0
- package/src/components/BatchProvider/types.ts +7 -0
- package/src/components/BatchProvider/useQueue.ts +62 -0
- package/src/components/ConnectionLine/index.tsrx +140 -0
- package/src/components/EdgeLabelRenderer/index.tsrx +62 -0
- package/src/components/EdgeWrapper/EdgeUpdateAnchors.tsrx +151 -0
- package/src/components/EdgeWrapper/index.tsrx +274 -0
- package/src/components/EdgeWrapper/utils.ts +26 -0
- package/src/components/Edges/BaseEdge.tsrx +76 -0
- package/src/components/Edges/BezierEdge.tsrx +94 -0
- package/src/components/Edges/EdgeAnchor.tsrx +54 -0
- package/src/components/Edges/EdgeText.tsrx +97 -0
- package/src/components/Edges/SimpleBezierEdge.tsrx +150 -0
- package/src/components/Edges/SmoothStepEdge.tsrx +96 -0
- package/src/components/Edges/StepEdge.tsrx +55 -0
- package/src/components/Edges/StraightEdge.tsrx +81 -0
- package/src/components/Edges/index.ts +11 -0
- package/src/components/Handle/index.tsrx +314 -0
- package/src/components/NodeWrapper/index.tsrx +259 -0
- package/src/components/NodeWrapper/useNodeObserver.ts +79 -0
- package/src/components/NodeWrapper/utils.tsrx +40 -0
- package/src/components/Nodes/DefaultNode.tsrx +17 -0
- package/src/components/Nodes/GroupNode.tsrx +3 -0
- package/src/components/Nodes/InputNode.tsrx +13 -0
- package/src/components/Nodes/OutputNode.tsrx +13 -0
- package/src/components/Nodes/utils.ts +45 -0
- package/src/components/NodesSelection/index.tsrx +103 -0
- package/src/components/Panel/index.tsrx +34 -0
- package/src/components/ReactFlowProvider/index.tsrx +128 -0
- package/src/components/SelectionListener/index.tsrx +73 -0
- package/src/components/StoreUpdater/index.tsrx +173 -0
- package/src/components/UserSelection/index.tsrx +27 -0
- package/src/components/ViewportPortal/index.tsrx +42 -0
- package/src/container/EdgeRenderer/MarkerDefinitions.tsrx +87 -0
- package/src/container/EdgeRenderer/MarkerSymbols.tsrx +60 -0
- package/src/container/EdgeRenderer/index.tsrx +98 -0
- package/src/container/FlowRenderer/index.tsrx +146 -0
- package/src/container/GraphView/index.tsrx +212 -0
- package/src/container/GraphView/useNodeOrEdgeTypesWarning.ts +39 -0
- package/src/container/GraphView/useStylesLoadedWarning.ts +26 -0
- package/src/container/NodeRenderer/index.tsrx +103 -0
- package/src/container/NodeRenderer/useResizeObserver.ts +38 -0
- package/src/container/Pane/index.tsrx +397 -0
- package/src/container/ReactFlow/Wrapper.tsrx +66 -0
- package/src/container/ReactFlow/index.tsrx +352 -0
- package/src/container/ReactFlow/init-values.ts +4 -0
- package/src/container/Viewport/index.tsrx +52 -0
- package/src/container/ZoomPane/index.tsrx +159 -0
- package/src/contexts/HandleConfigContext.tsrx +38 -0
- package/src/contexts/NodeIdContext.ts +39 -0
- package/src/contexts/StoreContext.ts +8 -0
- package/src/custom.d.ts +13 -0
- package/src/hooks/slot.ts +22 -0
- package/src/hooks/useColorModeClass.ts +50 -0
- package/src/hooks/useConnection.ts +69 -0
- package/src/hooks/useDrag.ts +95 -0
- package/src/hooks/useEdges.ts +32 -0
- package/src/hooks/useGlobalKeyHandler.ts +55 -0
- package/src/hooks/useHandleConnections.ts +77 -0
- package/src/hooks/useInternalNode.ts +47 -0
- package/src/hooks/useIsomorphicLayoutEffect.ts +5 -0
- package/src/hooks/useKeyPress.ts +217 -0
- package/src/hooks/useMoveSelectedNodes.ts +82 -0
- package/src/hooks/useNodeConnections.ts +86 -0
- package/src/hooks/useNodes.ts +33 -0
- package/src/hooks/useNodesData.ts +66 -0
- package/src/hooks/useNodesEdgesState.ts +138 -0
- package/src/hooks/useNodesInitialized.ts +74 -0
- package/src/hooks/useOnEdgesChangeMiddleware.ts +46 -0
- package/src/hooks/useOnInitHandler.ts +27 -0
- package/src/hooks/useOnNodesChangeMiddleware.ts +46 -0
- package/src/hooks/useOnSelectionChange.ts +78 -0
- package/src/hooks/useOnViewportChange.ts +68 -0
- package/src/hooks/useReactFlow.ts +347 -0
- package/src/hooks/useResizeHandler.ts +54 -0
- package/src/hooks/useStore.ts +58 -0
- package/src/hooks/useUpdateNodeInternals.ts +73 -0
- package/src/hooks/useViewport.ts +48 -0
- package/src/hooks/useViewportHelper.ts +103 -0
- package/src/hooks/useViewportSync.ts +33 -0
- package/src/hooks/useVisibleEdgeIds.ts +52 -0
- package/src/hooks/useVisibleNodeIds.ts +36 -0
- package/src/index.ts +151 -0
- package/src/react-shim.ts +93 -0
- package/src/store/index.ts +516 -0
- package/src/store/initialState.ts +162 -0
- package/src/styles/base.css +516 -0
- package/src/styles/style.css +648 -0
- package/src/styles/utils.ts +9 -0
- package/src/types/component-props.ts +716 -0
- package/src/types/edges.ts +312 -0
- package/src/types/general.ts +239 -0
- package/src/types/index.ts +6 -0
- package/src/types/instance.ts +265 -0
- package/src/types/nodes.ts +144 -0
- package/src/types/store.ts +198 -0
- package/src/utils/changes.ts +329 -0
- package/src/utils/edges.ts +34 -0
- package/src/utils/general.ts +72 -0
- package/src/utils/index.ts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dominic Gannaway
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @octanejs/xyflow
|
|
2
|
+
|
|
3
|
+
Octane binding for [`@xyflow/react`](https://www.npmjs.com/package/@xyflow/react) — node-based graphs and flow editors (React Flow).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
// Scaffold — exports will land as the port progresses.
|
|
9
|
+
import {} from '@octanejs/xyflow';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Compatibility
|
|
13
|
+
|
|
14
|
+
Pinned to `@xyflow/react@12.11.2`.
|
|
15
|
+
|
|
16
|
+
## Known differences
|
|
17
|
+
|
|
18
|
+
None documented yet.
|
|
19
|
+
|
|
20
|
+
## Tests
|
|
21
|
+
|
|
22
|
+
Organized per the hook-form / react-parity contract:
|
|
23
|
+
|
|
24
|
+
- `tests/conformance/` — package-authored contract tests (ordinary CI shards)
|
|
25
|
+
- `tests/differential/` — Octane vs React oracle (dedicated project + `globalSetup`)
|
|
26
|
+
- Vitest projects declare `testExecution.group: 'react-parity'` on parity-owned lanes
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octanejs/xyflow",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22.22.2"
|
|
8
|
+
},
|
|
9
|
+
"octane": {
|
|
10
|
+
"hookSlots": {
|
|
11
|
+
"manual": [
|
|
12
|
+
"src"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"description": "React Flow for the octane renderer — an Octane binding for @xyflow/react node-based graphs and flow editors.",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Dominic Gannaway",
|
|
19
|
+
"email": "dg@domgan.com"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/octanejs/octane.git",
|
|
27
|
+
"directory": "packages/xyflow"
|
|
28
|
+
},
|
|
29
|
+
"main": "src/index.ts",
|
|
30
|
+
"module": "src/index.ts",
|
|
31
|
+
"types": "src/index.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"src",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": [
|
|
37
|
+
"./src/styles/base.css",
|
|
38
|
+
"./src/styles/style.css"
|
|
39
|
+
],
|
|
40
|
+
"exports": {
|
|
41
|
+
".": "./src/index.ts",
|
|
42
|
+
"./dist/base.css": "./src/styles/base.css",
|
|
43
|
+
"./dist/style.css": "./src/styles/style.css"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@xyflow/system": "0.0.79",
|
|
47
|
+
"classcat": "5.0.5",
|
|
48
|
+
"@octanejs/zustand": "0.1.48"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"octane": "0.1.49"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@tsrx/react": "^0.2.61",
|
|
55
|
+
"@types/react": "^19.2.17",
|
|
56
|
+
"@types/react-dom": "^19.2.3",
|
|
57
|
+
"@xyflow/react": "12.11.2",
|
|
58
|
+
"esbuild": "^0.28.1",
|
|
59
|
+
"react": "^19.2.7",
|
|
60
|
+
"react-dom": "^19.2.7",
|
|
61
|
+
"vitest": "^4.1.10",
|
|
62
|
+
"octane": "0.1.49",
|
|
63
|
+
"@octanejs/zustand": "0.1.48"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"test": "vitest run --root ../.. --project xyflow --project xyflow-differential",
|
|
67
|
+
"port:upstream": "node ./scripts/port-upstream.mjs"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { memo, useRef } from 'octane';
|
|
2
|
+
import type { CSSProperties } from '../../react-shim.js';
|
|
3
|
+
import cc from 'classcat';
|
|
4
|
+
import { shallow } from '@octanejs/zustand/shallow';
|
|
5
|
+
|
|
6
|
+
import { useStore } from '../../hooks/useStore';
|
|
7
|
+
import { DotPattern, LinePattern } from './Patterns.tsrx';
|
|
8
|
+
import { containerStyle } from '../../styles/utils';
|
|
9
|
+
import { type BackgroundProps, BackgroundVariant } from './types';
|
|
10
|
+
import { type ReactFlowState } from '../../types';
|
|
11
|
+
|
|
12
|
+
const defaultSize = {
|
|
13
|
+
[BackgroundVariant.Dots]: 1,
|
|
14
|
+
[BackgroundVariant.Lines]: 1,
|
|
15
|
+
[BackgroundVariant.Cross]: 6,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const selector = (s: ReactFlowState) => ({
|
|
19
|
+
transform: s.transform,
|
|
20
|
+
patternId: `pattern-${s.rfId}`,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function BackgroundComponent({
|
|
24
|
+
id,
|
|
25
|
+
variant = BackgroundVariant.Dots,
|
|
26
|
+
// only used for dots and cross
|
|
27
|
+
gap = 20,
|
|
28
|
+
// only used for lines and cross
|
|
29
|
+
size,
|
|
30
|
+
lineWidth = 1,
|
|
31
|
+
offset = 0,
|
|
32
|
+
color,
|
|
33
|
+
bgColor,
|
|
34
|
+
style,
|
|
35
|
+
className,
|
|
36
|
+
patternClassName,
|
|
37
|
+
}: BackgroundProps) {
|
|
38
|
+
const ref = useRef<SVGSVGElement | null>(null);
|
|
39
|
+
const { transform, patternId } = useStore(selector, shallow);
|
|
40
|
+
const patternSize = size || defaultSize[variant];
|
|
41
|
+
const isDots = variant === BackgroundVariant.Dots;
|
|
42
|
+
const isCross = variant === BackgroundVariant.Cross;
|
|
43
|
+
const gapXY: [number, number] = Array.isArray(gap) ? gap : [gap, gap];
|
|
44
|
+
const scaledGap: [number, number] = [gapXY[0] * transform[2] || 1, gapXY[1] * transform[2] || 1];
|
|
45
|
+
const scaledSize = patternSize * transform[2];
|
|
46
|
+
const offsetXY: [number, number] = Array.isArray(offset) ? offset : [offset, offset];
|
|
47
|
+
|
|
48
|
+
const patternDimensions: [number, number] = isCross ? [scaledSize, scaledSize] : scaledGap;
|
|
49
|
+
const scaledOffset: [number, number] = [
|
|
50
|
+
offsetXY[0] * transform[2] || 1 + patternDimensions[0] / 2,
|
|
51
|
+
offsetXY[1] * transform[2] || 1 + patternDimensions[1] / 2,
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const _patternId = `${patternId}${id ? id : ''}`;
|
|
55
|
+
|
|
56
|
+
return <svg
|
|
57
|
+
className={cc(['react-flow__background', className])}
|
|
58
|
+
style={{
|
|
59
|
+
...style,
|
|
60
|
+
...containerStyle,
|
|
61
|
+
'--xy-background-color-props': bgColor,
|
|
62
|
+
'--xy-background-pattern-color-props': color,
|
|
63
|
+
} as CSSProperties}
|
|
64
|
+
ref={ref}
|
|
65
|
+
data-testid="rf__background"
|
|
66
|
+
>
|
|
67
|
+
<pattern
|
|
68
|
+
id={_patternId}
|
|
69
|
+
x={transform[0] % scaledGap[0]}
|
|
70
|
+
y={transform[1] % scaledGap[1]}
|
|
71
|
+
width={scaledGap[0]}
|
|
72
|
+
height={scaledGap[1]}
|
|
73
|
+
patternUnits="userSpaceOnUse"
|
|
74
|
+
patternTransform={`translate(-${scaledOffset[0]},-${scaledOffset[1]})`}
|
|
75
|
+
>
|
|
76
|
+
{isDots
|
|
77
|
+
? <DotPattern radius={scaledSize / 2} className={patternClassName} />
|
|
78
|
+
: <LinePattern
|
|
79
|
+
dimensions={patternDimensions}
|
|
80
|
+
lineWidth={lineWidth}
|
|
81
|
+
variant={variant}
|
|
82
|
+
className={patternClassName}
|
|
83
|
+
/>}
|
|
84
|
+
</pattern>
|
|
85
|
+
<rect x="0" y="0" width="100%" height="100%" fill={`url(#${_patternId})`} />
|
|
86
|
+
</svg>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
BackgroundComponent.displayName = 'Background';
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The `<Background />` component makes it convenient to render different types of backgrounds common in node-based UIs. It comes with three variants: lines, dots and cross.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
*
|
|
96
|
+
* A simple example of how to use the Background component.
|
|
97
|
+
*
|
|
98
|
+
* ```tsx
|
|
99
|
+
* import { useState } from 'octane';
|
|
100
|
+
* import { ReactFlow, Background, BackgroundVariant } from '@xyflow/react';
|
|
101
|
+
*
|
|
102
|
+
* export default function Flow() {
|
|
103
|
+
* return (
|
|
104
|
+
* <ReactFlow defaultNodes={[...]} defaultEdges={[...]}>
|
|
105
|
+
* <Background color="#ccc" variant={BackgroundVariant.Dots} />
|
|
106
|
+
* </ReactFlow>
|
|
107
|
+
* );
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
*
|
|
113
|
+
* In this example you can see how to combine multiple backgrounds
|
|
114
|
+
*
|
|
115
|
+
* ```tsx
|
|
116
|
+
* import { ReactFlow, Background, BackgroundVariant } from '@xyflow/react';
|
|
117
|
+
* import '@xyflow/react/dist/style.css';
|
|
118
|
+
*
|
|
119
|
+
* export default function Flow() {
|
|
120
|
+
* return (
|
|
121
|
+
* <ReactFlow defaultNodes={[...]} defaultEdges={[...]}>
|
|
122
|
+
* <Background
|
|
123
|
+
* id="1"
|
|
124
|
+
* gap={10}
|
|
125
|
+
* color="#f1f1f1"
|
|
126
|
+
* variant={BackgroundVariant.Lines}
|
|
127
|
+
* />
|
|
128
|
+
* <Background
|
|
129
|
+
* id="2"
|
|
130
|
+
* gap={100}
|
|
131
|
+
* color="#ccc"
|
|
132
|
+
* variant={BackgroundVariant.Lines}
|
|
133
|
+
* />
|
|
134
|
+
* </ReactFlow>
|
|
135
|
+
* );
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @remarks
|
|
140
|
+
*
|
|
141
|
+
* When combining multiple <Background /> components it’s important to give each of them a unique id prop!
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
144
|
+
export const Background = memo(BackgroundComponent);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import cc from 'classcat';
|
|
2
|
+
|
|
3
|
+
import { BackgroundVariant } from './types';
|
|
4
|
+
|
|
5
|
+
type LinePatternProps = {
|
|
6
|
+
dimensions: [number, number];
|
|
7
|
+
variant: BackgroundVariant;
|
|
8
|
+
lineWidth?: number;
|
|
9
|
+
className?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function LinePattern({ dimensions, lineWidth, variant, className }: LinePatternProps) {
|
|
13
|
+
return <path
|
|
14
|
+
strokeWidth={lineWidth}
|
|
15
|
+
d={`M${dimensions[0] / 2} 0 V${dimensions[1]} M0 ${dimensions[1] / 2} H${dimensions[0]}`}
|
|
16
|
+
className={cc(['react-flow__background-pattern', variant, className])}
|
|
17
|
+
/>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type DotPatternProps = {
|
|
21
|
+
radius: number;
|
|
22
|
+
className?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function DotPattern({ radius, className }: DotPatternProps) {
|
|
26
|
+
return <circle
|
|
27
|
+
cx={radius}
|
|
28
|
+
cy={radius}
|
|
29
|
+
r={radius}
|
|
30
|
+
className={cc(['react-flow__background-pattern', 'dots', className])}
|
|
31
|
+
/>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { CSSProperties } from '../../react-shim.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The three variants are exported as an enum for convenience. You can either import
|
|
5
|
+
* the enum and use it like `BackgroundVariant.Lines` or you can use the raw string
|
|
6
|
+
* value directly.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export enum BackgroundVariant {
|
|
10
|
+
Lines = 'lines',
|
|
11
|
+
Dots = 'dots',
|
|
12
|
+
Cross = 'cross',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @expand
|
|
17
|
+
*/
|
|
18
|
+
export type BackgroundProps = {
|
|
19
|
+
/** When multiple backgrounds are present on the page, each one should have a unique id. */
|
|
20
|
+
id?: string;
|
|
21
|
+
/** Color of the pattern. */
|
|
22
|
+
color?: string;
|
|
23
|
+
/** Color of the background. */
|
|
24
|
+
bgColor?: string;
|
|
25
|
+
/** Class applied to the container. */
|
|
26
|
+
className?: string;
|
|
27
|
+
/** Class applied to the pattern. */
|
|
28
|
+
patternClassName?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The gap between patterns. Passing in a tuple allows you to control the x and y gap
|
|
31
|
+
* independently.
|
|
32
|
+
* @default 20
|
|
33
|
+
*/
|
|
34
|
+
gap?: number | [number, number];
|
|
35
|
+
/**
|
|
36
|
+
* The radius of each dot or the size of each rectangle if `BackgroundVariant.Dots` or
|
|
37
|
+
* `BackgroundVariant.Cross` is used. This defaults to 1 or 6 respectively, or ignored if
|
|
38
|
+
* `BackgroundVariant.Lines` is used.
|
|
39
|
+
*/
|
|
40
|
+
size?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Offset of the pattern.
|
|
43
|
+
* @default 0
|
|
44
|
+
*/
|
|
45
|
+
offset?: number | [number, number];
|
|
46
|
+
/**
|
|
47
|
+
* The stroke thickness used when drawing the pattern.
|
|
48
|
+
* @default 1
|
|
49
|
+
*/
|
|
50
|
+
lineWidth?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Variant of the pattern.
|
|
53
|
+
* @default BackgroundVariant.Dots
|
|
54
|
+
* @example BackgroundVariant.Lines, BackgroundVariant.Dots, BackgroundVariant.Cross
|
|
55
|
+
* 'lines', 'dots', 'cross'
|
|
56
|
+
*/
|
|
57
|
+
variant?: BackgroundVariant;
|
|
58
|
+
/** Style applied to the container. */
|
|
59
|
+
style?: CSSProperties;
|
|
60
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import cc from 'classcat';
|
|
2
|
+
|
|
3
|
+
import type { ControlButtonProps } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* You can add buttons to the control panel by using the `<ControlButton />` component
|
|
7
|
+
* and pass it as a child to the [`<Controls />`](/api-reference/components/controls) component.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
* @example
|
|
11
|
+
*```jsx
|
|
12
|
+
*import { MagicWand } from '@radix-ui/react-icons'
|
|
13
|
+
*import { ReactFlow, Controls, ControlButton } from '@xyflow/react'
|
|
14
|
+
*
|
|
15
|
+
*export default function Flow() {
|
|
16
|
+
* return (
|
|
17
|
+
* <ReactFlow nodes={[...]} edges={[...]}>
|
|
18
|
+
* <Controls>
|
|
19
|
+
* <ControlButton onClick={() => alert('Something magical just happened. ✨')}>
|
|
20
|
+
* <MagicWand />
|
|
21
|
+
* </ControlButton>
|
|
22
|
+
* </Controls>
|
|
23
|
+
* </ReactFlow>
|
|
24
|
+
* )
|
|
25
|
+
*}
|
|
26
|
+
*```
|
|
27
|
+
*/
|
|
28
|
+
export function ControlButton({ children, className, ...rest }: ControlButtonProps) {
|
|
29
|
+
return <button
|
|
30
|
+
type="button"
|
|
31
|
+
className={cc(['react-flow__controls-button', className])}
|
|
32
|
+
{...rest}
|
|
33
|
+
>{children}</button>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { memo } from 'octane';
|
|
2
|
+
import cc from 'classcat';
|
|
3
|
+
import { shallow } from '@octanejs/zustand/shallow';
|
|
4
|
+
|
|
5
|
+
import { useStore, useStoreApi } from '../../hooks/useStore';
|
|
6
|
+
import { useReactFlow } from '../../hooks/useReactFlow';
|
|
7
|
+
import { Panel } from '../../components/Panel/index.tsrx';
|
|
8
|
+
import { type ReactFlowState } from '../../types';
|
|
9
|
+
|
|
10
|
+
import { PlusIcon } from './Icons/Plus.tsrx';
|
|
11
|
+
import { MinusIcon } from './Icons/Minus.tsrx';
|
|
12
|
+
import { FitViewIcon } from './Icons/FitView.tsrx';
|
|
13
|
+
import { LockIcon } from './Icons/Lock.tsrx';
|
|
14
|
+
import { UnlockIcon } from './Icons/Unlock.tsrx';
|
|
15
|
+
import { ControlButton } from './ControlButton.tsrx';
|
|
16
|
+
import type { ControlProps } from './types';
|
|
17
|
+
|
|
18
|
+
const selector = (s: ReactFlowState) => ({
|
|
19
|
+
isInteractive: s.nodesDraggable || s.nodesConnectable || s.elementsSelectable,
|
|
20
|
+
minZoomReached: s.transform[2] <= s.minZoom,
|
|
21
|
+
maxZoomReached: s.transform[2] >= s.maxZoom,
|
|
22
|
+
ariaLabelConfig: s.ariaLabelConfig,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function ControlsComponent({
|
|
26
|
+
style,
|
|
27
|
+
showZoom = true,
|
|
28
|
+
showFitView = true,
|
|
29
|
+
showInteractive = true,
|
|
30
|
+
fitViewOptions,
|
|
31
|
+
onZoomIn,
|
|
32
|
+
onZoomOut,
|
|
33
|
+
onFitView,
|
|
34
|
+
onInteractiveChange,
|
|
35
|
+
className,
|
|
36
|
+
children,
|
|
37
|
+
position = 'bottom-left',
|
|
38
|
+
orientation = 'vertical',
|
|
39
|
+
'aria-label': ariaLabel,
|
|
40
|
+
}: ControlProps) {
|
|
41
|
+
const store = useStoreApi();
|
|
42
|
+
const { isInteractive, minZoomReached, maxZoomReached, ariaLabelConfig } = useStore(
|
|
43
|
+
selector,
|
|
44
|
+
shallow,
|
|
45
|
+
);
|
|
46
|
+
const { zoomIn, zoomOut, fitView } = useReactFlow();
|
|
47
|
+
|
|
48
|
+
const onZoomInHandler = () => {
|
|
49
|
+
zoomIn();
|
|
50
|
+
onZoomIn?.();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const onZoomOutHandler = () => {
|
|
54
|
+
zoomOut();
|
|
55
|
+
onZoomOut?.();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const onFitViewHandler = () => {
|
|
59
|
+
fitView(fitViewOptions);
|
|
60
|
+
onFitView?.();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const onToggleInteractivity = () => {
|
|
64
|
+
store.setState({
|
|
65
|
+
nodesDraggable: !isInteractive,
|
|
66
|
+
nodesConnectable: !isInteractive,
|
|
67
|
+
elementsSelectable: !isInteractive,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
onInteractiveChange?.(!isInteractive);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const orientationClass =
|
|
74
|
+
orientation === 'horizontal' ? 'horizontal' : 'vertical';
|
|
75
|
+
return <Panel
|
|
76
|
+
className={cc(['react-flow__controls', orientationClass, className])}
|
|
77
|
+
position={position}
|
|
78
|
+
style={style}
|
|
79
|
+
data-testid="rf__controls"
|
|
80
|
+
aria-label={ariaLabel ?? ariaLabelConfig['controls.ariaLabel']}
|
|
81
|
+
>
|
|
82
|
+
{showZoom &&
|
|
83
|
+
<>
|
|
84
|
+
<ControlButton
|
|
85
|
+
onClick={onZoomInHandler}
|
|
86
|
+
className="react-flow__controls-zoomin"
|
|
87
|
+
title={ariaLabelConfig['controls.zoomIn.ariaLabel']}
|
|
88
|
+
aria-label={ariaLabelConfig['controls.zoomIn.ariaLabel']}
|
|
89
|
+
disabled={maxZoomReached}
|
|
90
|
+
>
|
|
91
|
+
<PlusIcon />
|
|
92
|
+
</ControlButton>
|
|
93
|
+
<ControlButton
|
|
94
|
+
onClick={onZoomOutHandler}
|
|
95
|
+
className="react-flow__controls-zoomout"
|
|
96
|
+
title={ariaLabelConfig['controls.zoomOut.ariaLabel']}
|
|
97
|
+
aria-label={ariaLabelConfig['controls.zoomOut.ariaLabel']}
|
|
98
|
+
disabled={minZoomReached}
|
|
99
|
+
>
|
|
100
|
+
<MinusIcon />
|
|
101
|
+
</ControlButton>
|
|
102
|
+
</>}
|
|
103
|
+
{showFitView &&
|
|
104
|
+
<ControlButton
|
|
105
|
+
className="react-flow__controls-fitview"
|
|
106
|
+
onClick={onFitViewHandler}
|
|
107
|
+
title={ariaLabelConfig['controls.fitView.ariaLabel']}
|
|
108
|
+
aria-label={ariaLabelConfig['controls.fitView.ariaLabel']}
|
|
109
|
+
>
|
|
110
|
+
<FitViewIcon />
|
|
111
|
+
</ControlButton>}
|
|
112
|
+
{showInteractive &&
|
|
113
|
+
<ControlButton
|
|
114
|
+
className="react-flow__controls-interactive"
|
|
115
|
+
onClick={onToggleInteractivity}
|
|
116
|
+
title={ariaLabelConfig['controls.interactive.ariaLabel']}
|
|
117
|
+
aria-label={ariaLabelConfig['controls.interactive.ariaLabel']}
|
|
118
|
+
>
|
|
119
|
+
{isInteractive ? <UnlockIcon /> : <LockIcon />}
|
|
120
|
+
</ControlButton>}
|
|
121
|
+
{children}
|
|
122
|
+
</Panel>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
ControlsComponent.displayName = 'Controls';
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The `<Controls />` component renders a small panel that contains convenient
|
|
129
|
+
* buttons to zoom in, zoom out, fit the view, and lock the viewport.
|
|
130
|
+
*
|
|
131
|
+
* @public
|
|
132
|
+
* @example
|
|
133
|
+
*```tsx
|
|
134
|
+
*import { ReactFlow, Controls } from '@xyflow/react'
|
|
135
|
+
*
|
|
136
|
+
*export default function Flow() {
|
|
137
|
+
* return (
|
|
138
|
+
* <ReactFlow nodes={[...]} edges={[...]}>
|
|
139
|
+
* <Controls />
|
|
140
|
+
* </ReactFlow>
|
|
141
|
+
* )
|
|
142
|
+
*}
|
|
143
|
+
*```
|
|
144
|
+
*
|
|
145
|
+
* @remarks To extend or customise the controls, you can use the [`<ControlButton />`](/api-reference/components/control-button) component
|
|
146
|
+
*
|
|
147
|
+
*/
|
|
148
|
+
export const Controls = memo(ControlsComponent);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function FitViewIcon() {
|
|
2
|
+
return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 30">
|
|
3
|
+
<path
|
|
4
|
+
d="M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"
|
|
5
|
+
/>
|
|
6
|
+
</svg>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function LockIcon() {
|
|
2
|
+
return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 32">
|
|
3
|
+
<path
|
|
4
|
+
d="M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"
|
|
5
|
+
/>
|
|
6
|
+
</svg>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function UnlockIcon() {
|
|
2
|
+
return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 32">
|
|
3
|
+
<path
|
|
4
|
+
d="M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"
|
|
5
|
+
/>
|
|
6
|
+
</svg>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, CSSProperties, OctaneNode } from '../../react-shim.js';
|
|
2
|
+
import type { PanelPosition } from '@xyflow/system';
|
|
3
|
+
|
|
4
|
+
import type { FitViewOptions } from '../../types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @expand
|
|
8
|
+
*/
|
|
9
|
+
export type ControlProps = {
|
|
10
|
+
/**
|
|
11
|
+
* Whether or not to show the zoom in and zoom out buttons. These buttons will adjust the viewport
|
|
12
|
+
* zoom by a fixed amount each press.
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
showZoom?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether or not to show the fit view button. By default, this button will adjust the viewport so
|
|
18
|
+
* that all nodes are visible at once.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
showFitView?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Show button for toggling interactivity
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
showInteractive?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Customise the options for the fit view button. These are the same options you would pass to the
|
|
29
|
+
* fitView function.
|
|
30
|
+
*/
|
|
31
|
+
fitViewOptions?: FitViewOptions;
|
|
32
|
+
/** Called in addition the default zoom behavior when the zoom in button is clicked. */
|
|
33
|
+
onZoomIn?: () => void;
|
|
34
|
+
/** Called in addition the default zoom behavior when the zoom out button is clicked. */
|
|
35
|
+
onZoomOut?: () => void;
|
|
36
|
+
/**
|
|
37
|
+
* Called when the fit view button is clicked. When this is not provided, the viewport will be
|
|
38
|
+
* adjusted so that all nodes are visible.
|
|
39
|
+
*/
|
|
40
|
+
onFitView?: () => void;
|
|
41
|
+
/** Called when the interactive (lock) button is clicked. */
|
|
42
|
+
onInteractiveChange?: (interactiveStatus: boolean) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Position of the controls on the pane
|
|
45
|
+
* @default PanelPosition.BottomLeft
|
|
46
|
+
* @example PanelPosition.TopLeft, PanelPosition.TopRight,
|
|
47
|
+
* PanelPosition.BottomLeft, PanelPosition.BottomRight
|
|
48
|
+
*/
|
|
49
|
+
position?: PanelPosition;
|
|
50
|
+
children?: OctaneNode;
|
|
51
|
+
/** Style applied to container */
|
|
52
|
+
style?: CSSProperties;
|
|
53
|
+
/** Class name applied to container */
|
|
54
|
+
className?: string;
|
|
55
|
+
/**
|
|
56
|
+
* @default 'React Flow controls'
|
|
57
|
+
*/
|
|
58
|
+
'aria-label'?: string;
|
|
59
|
+
/**
|
|
60
|
+
* @default 'vertical'
|
|
61
|
+
*/
|
|
62
|
+
orientation?: 'horizontal' | 'vertical';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @expand
|
|
67
|
+
*/
|
|
68
|
+
export type ControlButtonProps = ButtonHTMLAttributes<HTMLButtonElement>;
|