reflex-xyflow 0.0.1__tar.gz
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.
- reflex_xyflow-0.0.1/LICENSE +201 -0
- reflex_xyflow-0.0.1/PKG-INFO +191 -0
- reflex_xyflow-0.0.1/README.md +158 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow/__init__.py +147 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow/_base.py +29 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow/components.py +141 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow/custom.py +124 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow/enums.py +76 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow/flow.py +212 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow/imperative.py +133 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow/utils.py +259 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow.egg-info/PKG-INFO +191 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow.egg-info/SOURCES.txt +20 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow.egg-info/dependency_links.txt +1 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow.egg-info/requires.txt +9 -0
- reflex_xyflow-0.0.1/custom_components/reflex_xyflow.egg-info/top_level.txt +1 -0
- reflex_xyflow-0.0.1/pyproject.toml +66 -0
- reflex_xyflow-0.0.1/setup.cfg +4 -0
- reflex_xyflow-0.0.1/tests/test_components.py +99 -0
- reflex_xyflow-0.0.1/tests/test_custom.py +61 -0
- reflex_xyflow-0.0.1/tests/test_imperative.py +95 -0
- reflex_xyflow-0.0.1/tests/test_utils.py +339 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions for
|
|
125
|
+
use, reproduction, or distribution of Your modifications, or for any
|
|
126
|
+
such Derivative Works as a whole, provided Your use, reproduction,
|
|
127
|
+
and distribution of the Work otherwise complies with the conditions
|
|
128
|
+
stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Ernesto Crespo
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: reflex-xyflow
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Reflex custom component wrapping xyflow / React Flow (@xyflow/react) for building node-based UIs, flow charts, diagrams and graphs in pure Python.
|
|
5
|
+
Author-email: Ernesto Crespo <ecrespo@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/ecrespo/reflex-xyflow
|
|
8
|
+
Project-URL: Repository, https://github.com/ecrespo/reflex-xyflow
|
|
9
|
+
Project-URL: Documentation, https://github.com/ecrespo/reflex-xyflow#readme
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/ecrespo/reflex-xyflow/issues
|
|
11
|
+
Keywords: reflex,reflex-custom-components,xyflow,react-flow,reactflow,node-editor,diagrams,graphs,flowchart
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: reflex>=0.7.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: build; extra == "dev"
|
|
27
|
+
Requires-Dist: twine; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
30
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# reflex-xyflow
|
|
35
|
+
|
|
36
|
+
A [Reflex](https://reflex.dev) custom component that wraps
|
|
37
|
+
[xyflow / React Flow](https://github.com/xyflow/xyflow) (`@xyflow/react`, v12),
|
|
38
|
+
so you can build node-based UIs — flow charts, diagrams, graphs, pipelines and
|
|
39
|
+
no-code editors — in **pure Python**.
|
|
40
|
+
|
|
41
|
+
> Status: **alpha** (v0.0.1). Core controlled-graph functionality works; see the
|
|
42
|
+
> [roadmap](docs/sdd/01-phases.md).
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- Controlled graph driven entirely from Reflex server state (`nodes` / `edges`
|
|
49
|
+
as plain dicts).
|
|
50
|
+
- Wrapped components: `ReactFlow`, `Background`, `Controls`, `MiniMap`, `Panel`,
|
|
51
|
+
`Handle`, `NodeResizer`, `NodeToolbar`.
|
|
52
|
+
- Rich event surface: change / connect / drag / selection / pane / delete
|
|
53
|
+
handlers, forwarded as Python event handlers.
|
|
54
|
+
- Pure-Python state reducers (`apply_node_changes`, `apply_edge_changes`,
|
|
55
|
+
`add_edge`) that mirror React Flow's client-side helpers.
|
|
56
|
+
- Automatic stylesheet injection and React Flow 12 color modes
|
|
57
|
+
(`light` / `dark` / `system`).
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
Using `uv` (recommended):
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
uv pip install reflex-xyflow
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Using `pip`:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install reflex-xyflow
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quick start
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import reflex as rx
|
|
77
|
+
import reflex_xyflow as xyflow
|
|
78
|
+
from reflex_xyflow import add_edge, apply_node_changes, apply_edge_changes
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class State(rx.State):
|
|
82
|
+
nodes: list[dict] = [
|
|
83
|
+
{"id": "1", "type": "input", "data": {"label": "Start"},
|
|
84
|
+
"position": {"x": 250, "y": 25}},
|
|
85
|
+
{"id": "2", "data": {"label": "Middle"}, "position": {"x": 100, "y": 125}},
|
|
86
|
+
{"id": "3", "type": "output", "data": {"label": "End"},
|
|
87
|
+
"position": {"x": 250, "y": 250}},
|
|
88
|
+
]
|
|
89
|
+
edges: list[dict] = [
|
|
90
|
+
{"id": "e1-2", "source": "1", "target": "2", "animated": True},
|
|
91
|
+
{"id": "e2-3", "source": "2", "target": "3"},
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
@rx.event
|
|
95
|
+
def on_nodes_change(self, changes: list[dict]):
|
|
96
|
+
self.nodes = apply_node_changes(changes, self.nodes)
|
|
97
|
+
|
|
98
|
+
@rx.event
|
|
99
|
+
def on_edges_change(self, changes: list[dict]):
|
|
100
|
+
self.edges = apply_edge_changes(changes, self.edges)
|
|
101
|
+
|
|
102
|
+
@rx.event
|
|
103
|
+
def on_connect(self, connection: dict):
|
|
104
|
+
self.edges = add_edge(connection, self.edges)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def index() -> rx.Component:
|
|
108
|
+
return rx.box(
|
|
109
|
+
xyflow.react_flow(
|
|
110
|
+
xyflow.background(variant="dots", gap=16),
|
|
111
|
+
xyflow.controls(),
|
|
112
|
+
xyflow.mini_map(zoomable=True, pannable=True),
|
|
113
|
+
nodes=State.nodes,
|
|
114
|
+
edges=State.edges,
|
|
115
|
+
on_nodes_change=State.on_nodes_change,
|
|
116
|
+
on_edges_change=State.on_edges_change,
|
|
117
|
+
on_connect=State.on_connect,
|
|
118
|
+
fit_view=True,
|
|
119
|
+
),
|
|
120
|
+
width="100vw",
|
|
121
|
+
height="100vh",
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
app = rx.App()
|
|
126
|
+
app.add_page(index)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
> **Sizing**: `ReactFlow` fills its parent (`width/height: 100%`). Always place
|
|
130
|
+
> it inside a sized container (e.g. a `rx.box` with an explicit height).
|
|
131
|
+
|
|
132
|
+
## Components
|
|
133
|
+
|
|
134
|
+
| Component | Factory | Purpose |
|
|
135
|
+
|-----------|---------|---------|
|
|
136
|
+
| `ReactFlow` | `xyflow.react_flow` | The canvas; holds nodes, edges and events. |
|
|
137
|
+
| `ReactFlowProvider` | `xyflow.react_flow_provider` | Context for hooks outside the canvas. |
|
|
138
|
+
| `Background` | `xyflow.background` | Dots / lines / cross pattern. |
|
|
139
|
+
| `Controls` | `xyflow.controls` | Zoom / fit-view / lock controls. |
|
|
140
|
+
| `MiniMap` | `xyflow.mini_map` | Overview map. |
|
|
141
|
+
| `Panel` | `xyflow.panel` | Positioned overlay for toolbars. |
|
|
142
|
+
| `Handle` | `xyflow.handle` | Connection point in a custom node. |
|
|
143
|
+
| `NodeResizer` | `xyflow.node_resizer` | Resize handles for a node. |
|
|
144
|
+
| `NodeToolbar` | `xyflow.node_toolbar` | Floating toolbar on a node. |
|
|
145
|
+
|
|
146
|
+
See the [specification](docs/sdd/02-specification.md) for the full prop and
|
|
147
|
+
event catalogue, and the [data model](docs/sdd/04-data-model.md) for node/edge
|
|
148
|
+
shapes.
|
|
149
|
+
|
|
150
|
+
## Demo app
|
|
151
|
+
|
|
152
|
+
A multi-page demo (Overview, Interactive, Backgrounds, Styling) lives in
|
|
153
|
+
[`xyflow_demo/`](xyflow_demo/):
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
cd xyflow_demo
|
|
157
|
+
uv pip install -e .. # install the component in editable mode
|
|
158
|
+
reflex run
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Documentation
|
|
162
|
+
|
|
163
|
+
- [SDD overview](docs/sdd/00-overview.md)
|
|
164
|
+
- [Phases & roadmap](docs/sdd/01-phases.md)
|
|
165
|
+
- [Specification](docs/sdd/02-specification.md)
|
|
166
|
+
- [Architecture](docs/sdd/03-architecture.md)
|
|
167
|
+
- [Data model](docs/sdd/04-data-model.md)
|
|
168
|
+
- [Implementation plan](docs/sdd/05-implementation-plan.md)
|
|
169
|
+
- [Tasks](docs/sdd/06-tasks.md)
|
|
170
|
+
- [Publishing guide](docs/PUBLISHING.md)
|
|
171
|
+
|
|
172
|
+
## Development
|
|
173
|
+
|
|
174
|
+
This project uses `uv`. Reproduce the Reflex custom-component layout via
|
|
175
|
+
`reflex component init` or work directly in this repo:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
uv venv && source .venv/bin/activate
|
|
179
|
+
uv pip install -e ".[dev]"
|
|
180
|
+
ruff check .
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Acknowledgements
|
|
184
|
+
|
|
185
|
+
- [xyflow / React Flow](https://github.com/xyflow/xyflow) by the xyflow team
|
|
186
|
+
(MIT).
|
|
187
|
+
- [Reflex](https://github.com/reflex-dev/reflex) (Apache-2.0).
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# reflex-xyflow
|
|
2
|
+
|
|
3
|
+
A [Reflex](https://reflex.dev) custom component that wraps
|
|
4
|
+
[xyflow / React Flow](https://github.com/xyflow/xyflow) (`@xyflow/react`, v12),
|
|
5
|
+
so you can build node-based UIs — flow charts, diagrams, graphs, pipelines and
|
|
6
|
+
no-code editors — in **pure Python**.
|
|
7
|
+
|
|
8
|
+
> Status: **alpha** (v0.0.1). Core controlled-graph functionality works; see the
|
|
9
|
+
> [roadmap](docs/sdd/01-phases.md).
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Controlled graph driven entirely from Reflex server state (`nodes` / `edges`
|
|
16
|
+
as plain dicts).
|
|
17
|
+
- Wrapped components: `ReactFlow`, `Background`, `Controls`, `MiniMap`, `Panel`,
|
|
18
|
+
`Handle`, `NodeResizer`, `NodeToolbar`.
|
|
19
|
+
- Rich event surface: change / connect / drag / selection / pane / delete
|
|
20
|
+
handlers, forwarded as Python event handlers.
|
|
21
|
+
- Pure-Python state reducers (`apply_node_changes`, `apply_edge_changes`,
|
|
22
|
+
`add_edge`) that mirror React Flow's client-side helpers.
|
|
23
|
+
- Automatic stylesheet injection and React Flow 12 color modes
|
|
24
|
+
(`light` / `dark` / `system`).
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
Using `uv` (recommended):
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
uv pip install reflex-xyflow
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Using `pip`:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install reflex-xyflow
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick start
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import reflex as rx
|
|
44
|
+
import reflex_xyflow as xyflow
|
|
45
|
+
from reflex_xyflow import add_edge, apply_node_changes, apply_edge_changes
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class State(rx.State):
|
|
49
|
+
nodes: list[dict] = [
|
|
50
|
+
{"id": "1", "type": "input", "data": {"label": "Start"},
|
|
51
|
+
"position": {"x": 250, "y": 25}},
|
|
52
|
+
{"id": "2", "data": {"label": "Middle"}, "position": {"x": 100, "y": 125}},
|
|
53
|
+
{"id": "3", "type": "output", "data": {"label": "End"},
|
|
54
|
+
"position": {"x": 250, "y": 250}},
|
|
55
|
+
]
|
|
56
|
+
edges: list[dict] = [
|
|
57
|
+
{"id": "e1-2", "source": "1", "target": "2", "animated": True},
|
|
58
|
+
{"id": "e2-3", "source": "2", "target": "3"},
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
@rx.event
|
|
62
|
+
def on_nodes_change(self, changes: list[dict]):
|
|
63
|
+
self.nodes = apply_node_changes(changes, self.nodes)
|
|
64
|
+
|
|
65
|
+
@rx.event
|
|
66
|
+
def on_edges_change(self, changes: list[dict]):
|
|
67
|
+
self.edges = apply_edge_changes(changes, self.edges)
|
|
68
|
+
|
|
69
|
+
@rx.event
|
|
70
|
+
def on_connect(self, connection: dict):
|
|
71
|
+
self.edges = add_edge(connection, self.edges)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def index() -> rx.Component:
|
|
75
|
+
return rx.box(
|
|
76
|
+
xyflow.react_flow(
|
|
77
|
+
xyflow.background(variant="dots", gap=16),
|
|
78
|
+
xyflow.controls(),
|
|
79
|
+
xyflow.mini_map(zoomable=True, pannable=True),
|
|
80
|
+
nodes=State.nodes,
|
|
81
|
+
edges=State.edges,
|
|
82
|
+
on_nodes_change=State.on_nodes_change,
|
|
83
|
+
on_edges_change=State.on_edges_change,
|
|
84
|
+
on_connect=State.on_connect,
|
|
85
|
+
fit_view=True,
|
|
86
|
+
),
|
|
87
|
+
width="100vw",
|
|
88
|
+
height="100vh",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
app = rx.App()
|
|
93
|
+
app.add_page(index)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
> **Sizing**: `ReactFlow` fills its parent (`width/height: 100%`). Always place
|
|
97
|
+
> it inside a sized container (e.g. a `rx.box` with an explicit height).
|
|
98
|
+
|
|
99
|
+
## Components
|
|
100
|
+
|
|
101
|
+
| Component | Factory | Purpose |
|
|
102
|
+
|-----------|---------|---------|
|
|
103
|
+
| `ReactFlow` | `xyflow.react_flow` | The canvas; holds nodes, edges and events. |
|
|
104
|
+
| `ReactFlowProvider` | `xyflow.react_flow_provider` | Context for hooks outside the canvas. |
|
|
105
|
+
| `Background` | `xyflow.background` | Dots / lines / cross pattern. |
|
|
106
|
+
| `Controls` | `xyflow.controls` | Zoom / fit-view / lock controls. |
|
|
107
|
+
| `MiniMap` | `xyflow.mini_map` | Overview map. |
|
|
108
|
+
| `Panel` | `xyflow.panel` | Positioned overlay for toolbars. |
|
|
109
|
+
| `Handle` | `xyflow.handle` | Connection point in a custom node. |
|
|
110
|
+
| `NodeResizer` | `xyflow.node_resizer` | Resize handles for a node. |
|
|
111
|
+
| `NodeToolbar` | `xyflow.node_toolbar` | Floating toolbar on a node. |
|
|
112
|
+
|
|
113
|
+
See the [specification](docs/sdd/02-specification.md) for the full prop and
|
|
114
|
+
event catalogue, and the [data model](docs/sdd/04-data-model.md) for node/edge
|
|
115
|
+
shapes.
|
|
116
|
+
|
|
117
|
+
## Demo app
|
|
118
|
+
|
|
119
|
+
A multi-page demo (Overview, Interactive, Backgrounds, Styling) lives in
|
|
120
|
+
[`xyflow_demo/`](xyflow_demo/):
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
cd xyflow_demo
|
|
124
|
+
uv pip install -e .. # install the component in editable mode
|
|
125
|
+
reflex run
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Documentation
|
|
129
|
+
|
|
130
|
+
- [SDD overview](docs/sdd/00-overview.md)
|
|
131
|
+
- [Phases & roadmap](docs/sdd/01-phases.md)
|
|
132
|
+
- [Specification](docs/sdd/02-specification.md)
|
|
133
|
+
- [Architecture](docs/sdd/03-architecture.md)
|
|
134
|
+
- [Data model](docs/sdd/04-data-model.md)
|
|
135
|
+
- [Implementation plan](docs/sdd/05-implementation-plan.md)
|
|
136
|
+
- [Tasks](docs/sdd/06-tasks.md)
|
|
137
|
+
- [Publishing guide](docs/PUBLISHING.md)
|
|
138
|
+
|
|
139
|
+
## Development
|
|
140
|
+
|
|
141
|
+
This project uses `uv`. Reproduce the Reflex custom-component layout via
|
|
142
|
+
`reflex component init` or work directly in this repo:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
uv venv && source .venv/bin/activate
|
|
146
|
+
uv pip install -e ".[dev]"
|
|
147
|
+
ruff check .
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Acknowledgements
|
|
151
|
+
|
|
152
|
+
- [xyflow / React Flow](https://github.com/xyflow/xyflow) by the xyflow team
|
|
153
|
+
(MIT).
|
|
154
|
+
- [Reflex](https://github.com/reflex-dev/reflex) (Apache-2.0).
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""reflex-xyflow: a Reflex custom component wrapping ``@xyflow/react``.
|
|
2
|
+
|
|
3
|
+
Import the factory functions to build node-based UIs in pure Python::
|
|
4
|
+
|
|
5
|
+
import reflex as rx
|
|
6
|
+
import reflex_xyflow as xyflow
|
|
7
|
+
|
|
8
|
+
def index():
|
|
9
|
+
return rx.box(
|
|
10
|
+
xyflow.react_flow(
|
|
11
|
+
xyflow.background(),
|
|
12
|
+
xyflow.controls(),
|
|
13
|
+
xyflow.mini_map(),
|
|
14
|
+
nodes=State.nodes,
|
|
15
|
+
edges=State.edges,
|
|
16
|
+
on_nodes_change=State.on_nodes_change,
|
|
17
|
+
on_connect=State.on_connect,
|
|
18
|
+
fit_view=True,
|
|
19
|
+
),
|
|
20
|
+
width="100vw",
|
|
21
|
+
height="100vh",
|
|
22
|
+
)
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from ._base import XYFLOW_NPM_PACKAGE, XYFLOW_NPM_VERSION
|
|
28
|
+
from .components import (
|
|
29
|
+
Background,
|
|
30
|
+
Controls,
|
|
31
|
+
Handle,
|
|
32
|
+
MiniMap,
|
|
33
|
+
NodeResizer,
|
|
34
|
+
NodeToolbar,
|
|
35
|
+
Panel,
|
|
36
|
+
background,
|
|
37
|
+
controls,
|
|
38
|
+
handle,
|
|
39
|
+
mini_map,
|
|
40
|
+
node_resizer,
|
|
41
|
+
node_toolbar,
|
|
42
|
+
panel,
|
|
43
|
+
)
|
|
44
|
+
from .custom import XYFlowCustomTypes, custom_types, js_component
|
|
45
|
+
from .enums import (
|
|
46
|
+
BackgroundVariant,
|
|
47
|
+
ColorMode,
|
|
48
|
+
ConnectionLineType,
|
|
49
|
+
ConnectionMode,
|
|
50
|
+
HandleType,
|
|
51
|
+
MarkerType,
|
|
52
|
+
PanOnScrollMode,
|
|
53
|
+
Position,
|
|
54
|
+
SelectionMode,
|
|
55
|
+
)
|
|
56
|
+
from .flow import (
|
|
57
|
+
ReactFlow,
|
|
58
|
+
ReactFlowProvider,
|
|
59
|
+
react_flow,
|
|
60
|
+
react_flow_provider,
|
|
61
|
+
)
|
|
62
|
+
from .imperative import (
|
|
63
|
+
XYFlowController,
|
|
64
|
+
download_image,
|
|
65
|
+
fit_view,
|
|
66
|
+
flow_controller,
|
|
67
|
+
get_edges,
|
|
68
|
+
get_nodes,
|
|
69
|
+
get_viewport,
|
|
70
|
+
set_center,
|
|
71
|
+
set_viewport,
|
|
72
|
+
zoom_in,
|
|
73
|
+
zoom_out,
|
|
74
|
+
)
|
|
75
|
+
from .utils import (
|
|
76
|
+
add_edge,
|
|
77
|
+
apply_edge_changes,
|
|
78
|
+
apply_node_changes,
|
|
79
|
+
deserialize_graph,
|
|
80
|
+
layout_nodes,
|
|
81
|
+
reconnect_edge,
|
|
82
|
+
serialize_graph,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
__version__ = "0.0.1"
|
|
86
|
+
|
|
87
|
+
__all__ = [
|
|
88
|
+
# version / package metadata
|
|
89
|
+
"__version__",
|
|
90
|
+
"XYFLOW_NPM_PACKAGE",
|
|
91
|
+
"XYFLOW_NPM_VERSION",
|
|
92
|
+
# core flow
|
|
93
|
+
"ReactFlow",
|
|
94
|
+
"ReactFlowProvider",
|
|
95
|
+
"react_flow",
|
|
96
|
+
"react_flow_provider",
|
|
97
|
+
# components (classes)
|
|
98
|
+
"Background",
|
|
99
|
+
"Controls",
|
|
100
|
+
"MiniMap",
|
|
101
|
+
"Panel",
|
|
102
|
+
"Handle",
|
|
103
|
+
"NodeResizer",
|
|
104
|
+
"NodeToolbar",
|
|
105
|
+
# components (factories)
|
|
106
|
+
"background",
|
|
107
|
+
"controls",
|
|
108
|
+
"mini_map",
|
|
109
|
+
"panel",
|
|
110
|
+
"handle",
|
|
111
|
+
"node_resizer",
|
|
112
|
+
"node_toolbar",
|
|
113
|
+
# enums
|
|
114
|
+
"Position",
|
|
115
|
+
"HandleType",
|
|
116
|
+
"BackgroundVariant",
|
|
117
|
+
"ConnectionMode",
|
|
118
|
+
"ConnectionLineType",
|
|
119
|
+
"MarkerType",
|
|
120
|
+
"PanOnScrollMode",
|
|
121
|
+
"SelectionMode",
|
|
122
|
+
"ColorMode",
|
|
123
|
+
# utils
|
|
124
|
+
"apply_node_changes",
|
|
125
|
+
"apply_edge_changes",
|
|
126
|
+
"add_edge",
|
|
127
|
+
"reconnect_edge",
|
|
128
|
+
"serialize_graph",
|
|
129
|
+
"deserialize_graph",
|
|
130
|
+
"layout_nodes",
|
|
131
|
+
# imperative useReactFlow API
|
|
132
|
+
"XYFlowController",
|
|
133
|
+
"flow_controller",
|
|
134
|
+
"fit_view",
|
|
135
|
+
"zoom_in",
|
|
136
|
+
"zoom_out",
|
|
137
|
+
"set_viewport",
|
|
138
|
+
"set_center",
|
|
139
|
+
"get_nodes",
|
|
140
|
+
"get_edges",
|
|
141
|
+
"get_viewport",
|
|
142
|
+
"download_image",
|
|
143
|
+
# custom node/edge types
|
|
144
|
+
"js_component",
|
|
145
|
+
"custom_types",
|
|
146
|
+
"XYFlowCustomTypes",
|
|
147
|
+
]
|