panel-reactflow 0.5.0b0__tar.gz → 0.5.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.
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/PKG-INFO +1 -1
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/react-to-events.md +46 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/releases.md +38 -6
- panel_reactflow-0.5.1/examples/drop_from_menu.py +75 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/pixi.lock +350 -315
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/src/panel_reactflow/base.py +42 -7
- panel_reactflow-0.5.1/src/panel_reactflow/dist/panel-reactflow.bundle.js +88 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/src/panel_reactflow/models/reactflow.jsx +89 -4
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/test_api.py +28 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/test_core.py +34 -1
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/ui/test_ui.py +224 -0
- panel_reactflow-0.5.0b0/src/panel_reactflow/dist/panel-reactflow.bundle.js +0 -88
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.copier-answers.yml +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.gitattributes +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.github/CODEOWNERS +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.github/dependabot.yml +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.github/workflows/build.yml +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.github/workflows/docs.yml +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.github/workflows/test.yml +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.gitignore +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.pre-commit-config.yaml +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/.prettierrc +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/LICENSE.txt +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/MANIFEST.in +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/README.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/logo.svg +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/declare-types.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/define-editors-edge.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/define-editors-node.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/define-nodes-edges.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/embed-views-in-nodes.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/examples/advanced.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/examples/custom_editor.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/examples/edge_editors.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/examples/node_edge_instances.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/examples/schema_types.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/examples/simple.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/examples/threejs_viewer.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/examples/threejs_viewer_instances.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/quickstart.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/react-to-events.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/assets/screenshots/style-nodes-edges.png +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/examples/advanced.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/examples/custom-editor.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/examples/edge-editors.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/examples/index.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/examples/node-edge-instances.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/examples/schema-types.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/examples/simple.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/examples/threejs-viewer-instances.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/examples/threejs-viewer.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/context-menu.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/control-handle-connectivity.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/declare-types.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/define-editors.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/define-nodes-edges.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/embed-views-in-nodes.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/recover-from-errors.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/style-nodes-edges.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/how-to/validate-connections.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/index.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/quickstart.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/docs/reference/panel_reactflow.md +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/advanced.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/connection_validation.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/context_menu.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/custom_editor.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/edge_editors.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/edge_types_comparison.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/node_edge_instances.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/port_value_inspection.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/schema_types.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/simple.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/smart_edges_example.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/threejs_viewer.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/examples/threejs_viewer_instances.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/hatch_build.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/pixi.toml +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/pyproject.toml +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/src/panel_reactflow/__init__.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/src/panel_reactflow/__version.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/src/panel_reactflow/dist/css/reactflow.css +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/src/panel_reactflow/dist/icons/gear.svg +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/src/panel_reactflow/dist/panel-reactflow.bundle.css +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/src/panel_reactflow/py.typed +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/src/panel_reactflow/schema.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/__init__.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/conftest.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/test_connectable_handles.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/test_connectable_integration.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/test_error_recovery.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/ui/__init__.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/ui/test_context_menu.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/ui/test_error_recovery.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/tests/ui/test_value_popup.py +0 -0
- {panel_reactflow-0.5.0b0 → panel_reactflow-0.5.1}/zensical.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: panel-reactflow
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: A Panel wrapper for the Reactflow JS library.
|
|
5
5
|
Project-URL: Homepage, https://github.com/panel-extensions/panel-reactflow
|
|
6
6
|
Project-URL: Source, https://github.com/panel-extensions/panel-reactflow
|
|
@@ -30,6 +30,7 @@ the `ReactFlow` instance as a second argument. You can also listen for
|
|
|
30
30
|
| `edge_data_changed` | Edge data is patched (via API, editor patch, or parameter-driven sync). | `edge_id`, `patch` |
|
|
31
31
|
| `selection_changed` | The active selection changes. | `nodes`, `edges` |
|
|
32
32
|
| `sync` | A batch sync from the frontend. | *(varies)* |
|
|
33
|
+
| `drop` | Data of one of the `drop_types` is dropped onto the canvas. See [Handle drops](#handle-drops-onto-the-canvas). | `drop_type`, `data`, `position`, `target` |
|
|
33
34
|
| `client_error` | The graph view hit a rendering error in the browser. See [Recover from Rendering Errors](recover-from-errors.md). | `source`, `message`, `stack`, `component_stack`, `attempt`, `mode` |
|
|
34
35
|
|
|
35
36
|
---
|
|
@@ -151,6 +152,51 @@ flow.on("selection_changed", on_selection)
|
|
|
151
152
|
|
|
152
153
|
---
|
|
153
154
|
|
|
155
|
+
## Handle drops onto the canvas
|
|
156
|
+
|
|
157
|
+
Set `drop_types` to the MIME types the canvas accepts, and each drop of one
|
|
158
|
+
of them emits `drop`. Anything that sets data under that type when a drag
|
|
159
|
+
starts can be the source; a `panel_material_ui.MenuList` with
|
|
160
|
+
`draggable=True` sends `{"path": [...], "label": ...}` under its
|
|
161
|
+
`drag_type`. The payload's `position` is in flow coordinates, and `target`
|
|
162
|
+
names the node, and handle when there is one, under the pointer, so a
|
|
163
|
+
handler can add the dropped item there or wire it to the handle it landed
|
|
164
|
+
on. Drops are ignored while `editable` is False.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
palette = pmui.MenuList(items=[{"label": "CSV file"}, {"label": "Database"}], draggable=True)
|
|
168
|
+
flow = ReactFlow(drop_types=[palette.drag_type])
|
|
169
|
+
|
|
170
|
+
def on_drop(payload, flow):
|
|
171
|
+
item = palette.items[payload["data"]["path"][0]]
|
|
172
|
+
node_id = f"node-{len(flow.nodes)}"
|
|
173
|
+
flow.add_node({"id": node_id, "label": item["label"], "position": payload["position"], "data": {}})
|
|
174
|
+
target = payload["target"]
|
|
175
|
+
if target and target["direction"] == "input":
|
|
176
|
+
flow.add_edge({"source": node_id, "target": target["node_id"], "targetHandle": target["handle_id"]})
|
|
177
|
+
|
|
178
|
+
flow.on("drop", on_drop)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`examples/drop_from_menu.py` extends this with a grouped palette and places
|
|
182
|
+
a node dropped on an input handle beside the node it feeds.
|
|
183
|
+
|
|
184
|
+
To accept files dragged in from the operating system, add `"Files"` to `drop_types`. The payload's `data` is then a list with one `{"name", "type", "size", "content"}` entry per file, each read as text:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
flow = ReactFlow(drop_types=["Files"])
|
|
188
|
+
|
|
189
|
+
def on_file_drop(payload, flow):
|
|
190
|
+
for file in payload["data"]:
|
|
191
|
+
if file["name"].endswith(".json"):
|
|
192
|
+
graph = json.loads(file["content"])
|
|
193
|
+
flow.param.update(nodes=graph["nodes"], edges=graph["edges"])
|
|
194
|
+
|
|
195
|
+
flow.on("drop", on_file_drop)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
154
200
|
## Register multiple handlers
|
|
155
201
|
|
|
156
202
|
You can register as many handlers as you like for the same event — they
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## Version 0.5.1
|
|
4
|
+
|
|
5
|
+
A small enhancement release that lets the canvas accept files dragged in from the operating system.
|
|
6
|
+
|
|
7
|
+
### Enhancements
|
|
8
|
+
|
|
9
|
+
- **Drop files onto the canvas**: add `"Files"` to `drop_types` to accept files dragged in from the operating system. The `drop` event's `data` lists each file's `name`, `type`, `size` and text `content`, so a handler can, for example, load a graph saved as JSON. See [React to Events](how-to/react-to-events.md#handle-drops-onto-the-canvas) ([#79](https://github.com/panel-extensions/panel-reactflow/pull/79)).
|
|
10
|
+
|
|
3
11
|
## Version 0.5.0
|
|
4
12
|
|
|
5
|
-
This release adds port and edge value inspection
|
|
6
|
-
for interactive graph editing. `Node` and `Edge` properties now sync to
|
|
13
|
+
This release adds port and edge value inspection, connection checks
|
|
14
|
+
and canvas drops for interactive graph editing. `Node` and `Edge` properties now sync to
|
|
7
15
|
the browser in place, batches of changes render as a single update, and
|
|
8
16
|
an error boundary keeps a malformed graph from blanking the canvas.
|
|
9
17
|
|
|
@@ -26,7 +34,7 @@ an error boundary keeps a malformed graph from blanking the canvas.
|
|
|
26
34
|
`examples/connection_validation.py`
|
|
27
35
|
([#75](https://github.com/panel-extensions/panel-reactflow/pull/75)).
|
|
28
36
|
|
|
29
|
-
- **Error recovery
|
|
37
|
+
- **Error recovery**: the canvas is now wrapped in an error boundary,
|
|
30
38
|
controlled by the new `error_recovery` parameter (`"auto"` by default,
|
|
31
39
|
or `"manual"` / `"off"`). In `"auto"` mode a React render error
|
|
32
40
|
remounts the canvas, then remounts again in a view-only safe mode that
|
|
@@ -39,7 +47,7 @@ an error boundary keeps a malformed graph from blanking the canvas.
|
|
|
39
47
|
to the server
|
|
40
48
|
([#70](https://github.com/panel-extensions/panel-reactflow/pull/70)).
|
|
41
49
|
|
|
42
|
-
- **Base property sync
|
|
50
|
+
- **Base property sync**: the top-level React Flow fields on `Node` and
|
|
43
51
|
`Edge` (`label`, `type`, `style`, `className`, `draggable`,
|
|
44
52
|
`connectable`, `deletable`, ...) are now synced to the frontend, so
|
|
45
53
|
assigning `node.label = "Start (running)"` patches the browser in place
|
|
@@ -55,7 +63,7 @@ an error boundary keeps a malformed graph from blanking the canvas.
|
|
|
55
63
|
|
|
56
64
|
### Enhancements
|
|
57
65
|
|
|
58
|
-
- **Batch removal
|
|
66
|
+
- **Batch removal**: `remove_node()` and `remove_edge()` now accept
|
|
59
67
|
several ids, either as separate arguments
|
|
60
68
|
(`flow.remove_node("n1", "n2")`) or as a sequence
|
|
61
69
|
(`flow.remove_node(["n1", "n2"])`), and remove them in a single update.
|
|
@@ -63,9 +71,24 @@ an error boundary keeps a malformed graph from blanking the canvas.
|
|
|
63
71
|
`pn.io.hold()` to render them at once
|
|
64
72
|
([#72](https://github.com/panel-extensions/panel-reactflow/pull/72)).
|
|
65
73
|
|
|
74
|
+
- **Drop data onto the canvas**: `drop_types` lists MIME types the canvas
|
|
75
|
+
accepts, and each drop of one of them emits a `drop` event with the
|
|
76
|
+
dropped data, its flow position, and the node or handle under the
|
|
77
|
+
pointer, so a handler can add and wire what was dropped. Draggable
|
|
78
|
+
`panel_material_ui.MenuList` items work as a source; see
|
|
79
|
+
[React to Events](how-to/react-to-events.md#handle-drops-onto-the-canvas)
|
|
80
|
+
([#77](https://github.com/panel-extensions/panel-reactflow/pull/77)).
|
|
81
|
+
|
|
66
82
|
### Bug fixes
|
|
67
83
|
|
|
68
|
-
- **
|
|
84
|
+
- **Nodes remounted when node types change**: any change to
|
|
85
|
+
`node_types` rebuilt the component for every node type, so React
|
|
86
|
+
remounted every node and detached its embedded view, which could leave
|
|
87
|
+
Bokeh plots blank. Each type's component is now reused until its own
|
|
88
|
+
spec or the popup settings change
|
|
89
|
+
([#77](https://github.com/panel-extensions/panel-reactflow/pull/77)).
|
|
90
|
+
|
|
91
|
+
- **Progressive re-render when deleting multiple elements**: deleting a
|
|
69
92
|
multi-node selection removed the nodes one at a time, syncing an
|
|
70
93
|
intermediate graph to the browser per node so the nodes visibly
|
|
71
94
|
disappeared one by one. Updates triggered by a frontend message are now
|
|
@@ -73,6 +96,15 @@ an error boundary keeps a malformed graph from blanking the canvas.
|
|
|
73
96
|
`nodes` and `edges` once
|
|
74
97
|
([#72](https://github.com/panel-extensions/panel-reactflow/pull/72)).
|
|
75
98
|
|
|
99
|
+
- **Serialization error when updating `node_types`**: assigning
|
|
100
|
+
`NodeType` or `EdgeType` descriptors with a `schema` class after
|
|
101
|
+
construction synced them to the browser before they were converted to
|
|
102
|
+
JSON descriptors, so the server failed with `can't serialize
|
|
103
|
+
ParameterizedMetaclass`. They are now converted before syncing, and
|
|
104
|
+
updating `node_types` and `edge_types` together no longer raises a
|
|
105
|
+
`TypeError`
|
|
106
|
+
([#76](https://github.com/panel-extensions/panel-reactflow/pull/76)).
|
|
107
|
+
|
|
76
108
|
## Version 0.4.1
|
|
77
109
|
|
|
78
110
|
A small enhancement release adding viewport zoom controls.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Drag items from a panel-material-ui MenuList onto the canvas to add nodes.
|
|
2
|
+
|
|
3
|
+
Dropping an item on empty canvas adds a node there; dropping it on a node's
|
|
4
|
+
input handle also connects the new node to that input.
|
|
5
|
+
|
|
6
|
+
Run from the repository root with:
|
|
7
|
+
|
|
8
|
+
PYTHONPATH=src pixi run panel serve examples/drop_from_menu.py --show
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import panel as pn
|
|
12
|
+
import panel_material_ui as pmui
|
|
13
|
+
|
|
14
|
+
from panel_reactflow import NodeSpec, NodeType, ReactFlow
|
|
15
|
+
|
|
16
|
+
pn.extension()
|
|
17
|
+
|
|
18
|
+
PALETTE_ITEMS = [
|
|
19
|
+
{"label": "Sources", "draggable": False, "items": [
|
|
20
|
+
{"label": "CSV file", "icon": "description", "kind": "source"},
|
|
21
|
+
{"label": "Database", "icon": "storage", "kind": "source"},
|
|
22
|
+
]},
|
|
23
|
+
{"label": "Transforms", "draggable": False, "items": [
|
|
24
|
+
{"label": "Filter", "icon": "filter_alt", "kind": "transform"},
|
|
25
|
+
]},
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def lookup(items, path):
|
|
30
|
+
item = {"items": items}
|
|
31
|
+
for index in path:
|
|
32
|
+
item = item["items"][index]
|
|
33
|
+
return item
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
palette = pmui.MenuList(
|
|
37
|
+
items=PALETTE_ITEMS, draggable=True, expanded=[(0,), (1,)], width=220, label="Drag onto the canvas"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
flow = ReactFlow(
|
|
41
|
+
nodes=[NodeSpec(id="sink", type="transform", label="Sink", position={"x": 400, "y": 150}).to_dict()],
|
|
42
|
+
node_types={
|
|
43
|
+
"source": NodeType(type="source", inputs=[], outputs=["out"]),
|
|
44
|
+
"transform": NodeType(type="transform", inputs=["in"], outputs=["out"]),
|
|
45
|
+
},
|
|
46
|
+
drop_types=[palette.drag_type],
|
|
47
|
+
# Keeps fitView from zooming in on the lone starting node, so nodes placed
|
|
48
|
+
# beside it stay on screen.
|
|
49
|
+
max_zoom=1,
|
|
50
|
+
sizing_mode="stretch_both",
|
|
51
|
+
min_height=500,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def on_drop(payload, flow):
|
|
56
|
+
item = lookup(palette.items, payload["data"]["path"])
|
|
57
|
+
node_id = f"{item['kind']}-{len(flow.nodes)}"
|
|
58
|
+
target = payload["target"]
|
|
59
|
+
wire = target is not None and target["direction"] == "input"
|
|
60
|
+
position = payload["position"]
|
|
61
|
+
if wire:
|
|
62
|
+
# Place the new node left of the input it feeds rather than on top of it.
|
|
63
|
+
target_node = next(n for n in flow.nodes if n["id"] == target["node_id"])
|
|
64
|
+
position = {"x": target_node["position"]["x"] - 320, "y": target_node["position"]["y"]}
|
|
65
|
+
flow.add_node(NodeSpec(id=node_id, type=item["kind"], label=item["label"], position=position).to_dict())
|
|
66
|
+
if wire:
|
|
67
|
+
flow.add_edge(
|
|
68
|
+
{"source": node_id, "sourceHandle": "out", "target": target["node_id"], "targetHandle": target["handle_id"]}
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
flow.on("drop", on_drop)
|
|
73
|
+
|
|
74
|
+
demo = pmui.Row(palette, flow, sizing_mode="stretch_both")
|
|
75
|
+
demo.servable()
|