pynode-flow 0.2.0__py3-none-any.whl

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.
Files changed (227) hide show
  1. pynode/__init__.py +37 -0
  2. pynode/__main__.py +9 -0
  3. pynode/_perf.py +65 -0
  4. pynode/_version.py +24 -0
  5. pynode/api/__init__.py +15 -0
  6. pynode/api/helpers.py +79 -0
  7. pynode/api/nodes.py +423 -0
  8. pynode/api/services.py +124 -0
  9. pynode/api/sse.py +58 -0
  10. pynode/api/uploads.py +59 -0
  11. pynode/api/workflows.py +466 -0
  12. pynode/config.py +93 -0
  13. pynode/install_nodes.py +143 -0
  14. pynode/main.py +118 -0
  15. pynode/node_registry.py +156 -0
  16. pynode/nodes/AutoSyncNode/auto_sync_node.py +151 -0
  17. pynode/nodes/BBoxMetricsNode/__init__.py +3 -0
  18. pynode/nodes/BBoxMetricsNode/bbox_metrics_node.py +250 -0
  19. pynode/nodes/BBoxMetricsNode/requirements.txt +1 -0
  20. pynode/nodes/BatchNode/__init__.py +3 -0
  21. pynode/nodes/BatchNode/batch_node.py +86 -0
  22. pynode/nodes/BatchNode/requirements.txt +1 -0
  23. pynode/nodes/CameraNode/__init__.py +4 -0
  24. pynode/nodes/CameraNode/camera_node.py +204 -0
  25. pynode/nodes/CameraNode/requirements.txt +2 -0
  26. pynode/nodes/ChangeNode/__init__.py +1 -0
  27. pynode/nodes/ChangeNode/change_node.py +255 -0
  28. pynode/nodes/ChangeNode/requirements.txt +1 -0
  29. pynode/nodes/ConfidenceFilterNode/__init__.py +4 -0
  30. pynode/nodes/ConfidenceFilterNode/confidence_filter_node.py +208 -0
  31. pynode/nodes/ConfidenceFilterNode/requirements.txt +1 -0
  32. pynode/nodes/CounterNode/__init__.py +3 -0
  33. pynode/nodes/CounterNode/counter_node.py +191 -0
  34. pynode/nodes/CropNode/__init__.py +4 -0
  35. pynode/nodes/CropNode/crop_node.py +317 -0
  36. pynode/nodes/CropNode/requirements.txt +2 -0
  37. pynode/nodes/DebugNode/__init__.py +4 -0
  38. pynode/nodes/DebugNode/debug_node.py +169 -0
  39. pynode/nodes/DebugNode/requirements.txt +1 -0
  40. pynode/nodes/DelayNode/delay_node.py +218 -0
  41. pynode/nodes/DelayNode/requirements.txt +1 -0
  42. pynode/nodes/DrawPredictionsNode/__init__.py +3 -0
  43. pynode/nodes/DrawPredictionsNode/draw_predictions_node.py +365 -0
  44. pynode/nodes/DrawPredictionsNode/requirements.txt +2 -0
  45. pynode/nodes/ErrorNode/error_node.py +94 -0
  46. pynode/nodes/ErrorNode/requirements.txt +1 -0
  47. pynode/nodes/FilterNode/__init__.py +3 -0
  48. pynode/nodes/FilterNode/filter_node.py +102 -0
  49. pynode/nodes/FilterNode/requirements.txt +1 -0
  50. pynode/nodes/FrameSourceNode/__init__.py +4 -0
  51. pynode/nodes/FrameSourceNode/frame_source_node.py +319 -0
  52. pynode/nodes/FrameSourceNode/requirements.txt +1 -0
  53. pynode/nodes/FunctionNode/__init__.py +3 -0
  54. pynode/nodes/FunctionNode/function_node.py +168 -0
  55. pynode/nodes/FunctionNode/requirements.txt +1 -0
  56. pynode/nodes/GateNode/gate_node.py +60 -0
  57. pynode/nodes/GateNode/requirements.txt +1 -0
  58. pynode/nodes/GetiUploadNode/__init__.py +3 -0
  59. pynode/nodes/GetiUploadNode/geti_upload_node.py +278 -0
  60. pynode/nodes/GetiUploadNode/requirements.txt +1 -0
  61. pynode/nodes/ImageFormatNode/__init__.py +4 -0
  62. pynode/nodes/ImageFormatNode/image_format_node.py +310 -0
  63. pynode/nodes/ImageFormatNode/requirements.txt +2 -0
  64. pynode/nodes/ImageUploadNode/image_upload_node.py +96 -0
  65. pynode/nodes/ImageViewerNode/__init__.py +4 -0
  66. pynode/nodes/ImageViewerNode/image_viewer_node.py +162 -0
  67. pynode/nodes/ImageViewerNode/requirements.txt +2 -0
  68. pynode/nodes/ImageWriterNode/__init__.py +3 -0
  69. pynode/nodes/ImageWriterNode/imagewriter_node.py +352 -0
  70. pynode/nodes/ImageWriterNode/requirements.txt +1 -0
  71. pynode/nodes/InferenceNode/InferenceEngine/__init__.py +15 -0
  72. pynode/nodes/InferenceNode/InferenceEngine/device_detection.py +149 -0
  73. pynode/nodes/InferenceNode/InferenceEngine/engines/base_engine.py +155 -0
  74. pynode/nodes/InferenceNode/InferenceEngine/engines/example_engine_template.py +272 -0
  75. pynode/nodes/InferenceNode/InferenceEngine/engines/geti_engine.py +309 -0
  76. pynode/nodes/InferenceNode/InferenceEngine/engines/onnx_engine.py +346 -0
  77. pynode/nodes/InferenceNode/InferenceEngine/engines/pass_engine.py +86 -0
  78. pynode/nodes/InferenceNode/InferenceEngine/engines/ultralytics_engine.py +863 -0
  79. pynode/nodes/InferenceNode/InferenceEngine/inference_engine_factory.py +533 -0
  80. pynode/nodes/InferenceNode/InferenceEngine/readme.md +107 -0
  81. pynode/nodes/InferenceNode/InferenceEngine/result_converters.py +121 -0
  82. pynode/nodes/InferenceNode/inference_node.py +451 -0
  83. pynode/nodes/InferenceNode/requirements.txt +13 -0
  84. pynode/nodes/InjectNode/inject_node.py +245 -0
  85. pynode/nodes/InjectNode/requirements.txt +1 -0
  86. pynode/nodes/JoinNode/__init__.py +3 -0
  87. pynode/nodes/JoinNode/join_node.py +156 -0
  88. pynode/nodes/JoinNode/requirements.txt +1 -0
  89. pynode/nodes/LabelFilterNode/__init__.py +3 -0
  90. pynode/nodes/LabelFilterNode/label_filter_node.py +188 -0
  91. pynode/nodes/LabelFilterNode/requirements.txt +1 -0
  92. pynode/nodes/MQTTNode/__init__.py +8 -0
  93. pynode/nodes/MQTTNode/mqtt_in_node.py +148 -0
  94. pynode/nodes/MQTTNode/mqtt_out_node.py +157 -0
  95. pynode/nodes/MQTTNode/mqtt_service.py +367 -0
  96. pynode/nodes/MQTTNode/requirements.txt +1 -0
  97. pynode/nodes/MessageWriterNode/__init__.py +7 -0
  98. pynode/nodes/MessageWriterNode/messagereader_node.py +568 -0
  99. pynode/nodes/MessageWriterNode/messagewriter_node.py +505 -0
  100. pynode/nodes/OmronCameraNode/__init__.py +3 -0
  101. pynode/nodes/OmronCameraNode/omron_camera_node.py +652 -0
  102. pynode/nodes/OmronCameraNode/requirements.txt +4 -0
  103. pynode/nodes/OpenCV/__init__.py +1 -0
  104. pynode/nodes/OpenCV/arithmetic_node.py +376 -0
  105. pynode/nodes/OpenCV/bitwise_node.py +127 -0
  106. pynode/nodes/OpenCV/blend_node.py +127 -0
  107. pynode/nodes/OpenCV/blob_detector_node.py +233 -0
  108. pynode/nodes/OpenCV/blur_node.py +141 -0
  109. pynode/nodes/OpenCV/color_space_node.py +139 -0
  110. pynode/nodes/OpenCV/colormap_node.py +262 -0
  111. pynode/nodes/OpenCV/contours_node.py +258 -0
  112. pynode/nodes/OpenCV/denormalize_coords_node.py +365 -0
  113. pynode/nodes/OpenCV/draw_node.py +312 -0
  114. pynode/nodes/OpenCV/edge_detector_node.py +177 -0
  115. pynode/nodes/OpenCV/equirectangular_node.py +447 -0
  116. pynode/nodes/OpenCV/fft_node.py +102 -0
  117. pynode/nodes/OpenCV/focus_estimation_node.py +189 -0
  118. pynode/nodes/OpenCV/frequency_filter_node.py +241 -0
  119. pynode/nodes/OpenCV/histogram_node.py +160 -0
  120. pynode/nodes/OpenCV/hough_circles_node.py +224 -0
  121. pynode/nodes/OpenCV/hough_lines_node.py +243 -0
  122. pynode/nodes/OpenCV/in_range_node.py +186 -0
  123. pynode/nodes/OpenCV/morphology_node.py +136 -0
  124. pynode/nodes/OpenCV/normalize_coords_node.py +344 -0
  125. pynode/nodes/OpenCV/paste_node.py +244 -0
  126. pynode/nodes/OpenCV/perspective_node.py +174 -0
  127. pynode/nodes/OpenCV/realsense_depth_node.py +253 -0
  128. pynode/nodes/OpenCV/requirements.txt +2 -0
  129. pynode/nodes/OpenCV/resize_node.py +175 -0
  130. pynode/nodes/OpenCV/rotate_node.py +159 -0
  131. pynode/nodes/OpenCV/template_match_node.py +227 -0
  132. pynode/nodes/OpenCV/threshold_node.py +167 -0
  133. pynode/nodes/PointInShapeNode/__init__.py +3 -0
  134. pynode/nodes/PointInShapeNode/point_in_shape_node.py +313 -0
  135. pynode/nodes/PointInShapeNode/requirements.txt +2 -0
  136. pynode/nodes/PolygonMetricsNode/__init__.py +3 -0
  137. pynode/nodes/PolygonMetricsNode/polygon_metrics_node.py +331 -0
  138. pynode/nodes/PolygonMetricsNode/requirements.txt +2 -0
  139. pynode/nodes/QueueLengthProbeNode/__init__.py +3 -0
  140. pynode/nodes/QueueLengthProbeNode/queue_length_probe_node.py +116 -0
  141. pynode/nodes/Qwen3VLMNode/__init__.py +3 -0
  142. pynode/nodes/Qwen3VLMNode/qwen3_vlm_node.py +519 -0
  143. pynode/nodes/Qwen3VLMNode/requirements.txt +5 -0
  144. pynode/nodes/RESTEndpointNode/__init__.py +3 -0
  145. pynode/nodes/RESTEndpointNode/rest_endpoint_node.py +491 -0
  146. pynode/nodes/RangeNode/__init__.py +3 -0
  147. pynode/nodes/RangeNode/range_node.py +115 -0
  148. pynode/nodes/RangeNode/requirements.txt +1 -0
  149. pynode/nodes/RateProbeNode/__init__.py +3 -0
  150. pynode/nodes/RateProbeNode/rate_probe_node.py +183 -0
  151. pynode/nodes/RateProbeNode/requirements.txt +1 -0
  152. pynode/nodes/RoboflowUploadNode/__init__.py +3 -0
  153. pynode/nodes/RoboflowUploadNode/requirements.txt +1 -0
  154. pynode/nodes/RoboflowUploadNode/roboflow_upload_node.py +229 -0
  155. pynode/nodes/SliceNode/README.md +149 -0
  156. pynode/nodes/SliceNode/__init__.py +5 -0
  157. pynode/nodes/SliceNode/merge_predictions_node.py +444 -0
  158. pynode/nodes/SliceNode/requirements.txt +3 -0
  159. pynode/nodes/SliceNode/slice_collector_node.py +370 -0
  160. pynode/nodes/SliceNode/slice_image_node.py +380 -0
  161. pynode/nodes/SplitNode/__init__.py +3 -0
  162. pynode/nodes/SplitNode/requirements.txt +1 -0
  163. pynode/nodes/SplitNode/split_node.py +155 -0
  164. pynode/nodes/SwitchNode/requirements.txt +1 -0
  165. pynode/nodes/SwitchNode/switch_node.py +259 -0
  166. pynode/nodes/SyncNode/__init__.py +3 -0
  167. pynode/nodes/SyncNode/sync_node.py +287 -0
  168. pynode/nodes/TemplateNode/requirements.txt +1 -0
  169. pynode/nodes/TemplateNode/template_node.py +86 -0
  170. pynode/nodes/TrackerNode/__init__.py +2 -0
  171. pynode/nodes/TrackerNode/supervision_tracker_node.py +248 -0
  172. pynode/nodes/TrackerNode/tracker_node.py +745 -0
  173. pynode/nodes/UltralyticsNode/__init__.py +4 -0
  174. pynode/nodes/UltralyticsNode/requirements.txt +2 -0
  175. pynode/nodes/UltralyticsNode/ultralytics_node.py +364 -0
  176. pynode/nodes/UnknownNode/__init__.py +93 -0
  177. pynode/nodes/VLLMNode/__init__.py +3 -0
  178. pynode/nodes/VLLMNode/vllm_node.py +345 -0
  179. pynode/nodes/VideoReaderNode/__init__.py +3 -0
  180. pynode/nodes/VideoReaderNode/video_reader_node.py +425 -0
  181. pynode/nodes/VideoWriterNode/__init__.py +3 -0
  182. pynode/nodes/VideoWriterNode/video_writer_node.py +441 -0
  183. pynode/nodes/WebhookNode/__init__.py +3 -0
  184. pynode/nodes/WebhookNode/webhook_node.py +591 -0
  185. pynode/nodes/__init__.py +109 -0
  186. pynode/nodes/base_node.py +562 -0
  187. pynode/nodes/image_utils.py +291 -0
  188. pynode/nodes/info.py +109 -0
  189. pynode/nodes/mDNSNode/__init__.py +13 -0
  190. pynode/nodes/mDNSNode/mdns_broadcast_node.py +214 -0
  191. pynode/nodes/mDNSNode/mdns_discovery_node.py +362 -0
  192. pynode/nodes/mDNSNode/mdns_manager.py +399 -0
  193. pynode/nodes/mDNSNode/requirements.txt +1 -0
  194. pynode/nodes/messages.py +81 -0
  195. pynode/server.py +187 -0
  196. pynode/static/images/favicon4.png +0 -0
  197. pynode/static/index.html +200 -0
  198. pynode/static/js/README.md +139 -0
  199. pynode/static/js/auth.js +89 -0
  200. pynode/static/js/clipboard.js +152 -0
  201. pynode/static/js/config.js +14 -0
  202. pynode/static/js/connections.js +844 -0
  203. pynode/static/js/debug.js +524 -0
  204. pynode/static/js/events.js +775 -0
  205. pynode/static/js/history.js +199 -0
  206. pynode/static/js/main.js +55 -0
  207. pynode/static/js/minimap.js +242 -0
  208. pynode/static/js/nodes.js +995 -0
  209. pynode/static/js/palette.js +255 -0
  210. pynode/static/js/properties.js +1270 -0
  211. pynode/static/js/selection.js +241 -0
  212. pynode/static/js/state.js +211 -0
  213. pynode/static/js/ui-utils.js +28 -0
  214. pynode/static/js/viewport.js +204 -0
  215. pynode/static/js/workflow.js +469 -0
  216. pynode/static/js/workflows.js +344 -0
  217. pynode/static/style.css +2751 -0
  218. pynode/workflow_engine.py +483 -0
  219. pynode/workflow_manager.py +440 -0
  220. pynode_flow-0.2.0.dist-info/METADATA +520 -0
  221. pynode_flow-0.2.0.dist-info/RECORD +227 -0
  222. pynode_flow-0.2.0.dist-info/WHEEL +5 -0
  223. pynode_flow-0.2.0.dist-info/entry_points.txt +3 -0
  224. pynode_flow-0.2.0.dist-info/licenses/LICENSE +21 -0
  225. pynode_flow-0.2.0.dist-info/scm_file_list.json +270 -0
  226. pynode_flow-0.2.0.dist-info/scm_version.json +8 -0
  227. pynode_flow-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,775 @@
1
+ // Event handlers
2
+ import { state } from './state.js';
3
+ import { createNode, deleteNode, deleteNodeAndReconnect, snapNodeToGrid } from './nodes.js';
4
+ import { deselectNode, deselectAllNodes, selectNode } from './selection.js';
5
+ import { deployWorkflow, deployWorkflowFull, restartWorkflow, stopWorkflow, clearWorkflow, exportWorkflow, importWorkflow } from './workflow.js';
6
+ import { clearDebug, toggleDebugPaused } from './debug.js';
7
+ import { getConnectionAtPoint, highlightConnectionForInsert, clearConnectionHighlight, getHoveredConnection, insertNodeIntoConnection } from './connections.js';
8
+ import { clientToCanvas, getZoom } from './viewport.js';
9
+
10
+ // Track deploy mode: 'modified' or 'full'
11
+ let deployMode = 'modified';
12
+
13
+ export function setupEventListeners() {
14
+ const nodesContainer = document.getElementById('nodes-container');
15
+ const canvasContainer = document.querySelector('.canvas-container');
16
+
17
+ // Canvas drop event
18
+ nodesContainer.addEventListener('dragover', handleCanvasDragOver);
19
+ nodesContainer.addEventListener('dragleave', handleCanvasDragLeave);
20
+ nodesContainer.addEventListener('drop', handleCanvasDrop);
21
+
22
+ // Middle mouse button panning
23
+ setupCanvasPanning(canvasContainer);
24
+
25
+ // Header buttons - deploy with current mode
26
+ document.getElementById('deploy-btn').addEventListener('click', () => {
27
+ if (deployMode === 'full') {
28
+ deployWorkflowFull();
29
+ } else {
30
+ deployWorkflow();
31
+ }
32
+ });
33
+ document.getElementById('clear-btn').addEventListener('click', clearWorkflow);
34
+ // Export submenu: default is Export Flow, also support Export Selected
35
+ const exportBtn = document.getElementById('export-btn');
36
+ const exportSubmenu = document.getElementById('export-submenu');
37
+ const exportFlowBtn = document.getElementById('export-flow-btn');
38
+ const exportSelectedBtn = document.getElementById('export-selected-btn');
39
+
40
+ // Submenu display handled via CSS hover/focus; no click toggle here.
41
+
42
+ if (exportFlowBtn) {
43
+ exportFlowBtn.addEventListener('click', () => {
44
+ exportWorkflow();
45
+ menuDropdown.classList.add('hidden');
46
+ exportSubmenu.classList.add('hidden');
47
+ });
48
+ }
49
+
50
+ if (exportSelectedBtn) {
51
+ exportSelectedBtn.addEventListener('click', () => {
52
+ // Lazy-import to avoid circular deps
53
+ import('./workflow.js').then(({ exportSelected }) => {
54
+ exportSelected();
55
+ });
56
+ menuDropdown.classList.add('hidden');
57
+ exportSubmenu.classList.add('hidden');
58
+ });
59
+ }
60
+
61
+ document.getElementById('import-btn').addEventListener('click', importWorkflow);
62
+ document.getElementById('clear-debug-btn').addEventListener('click', clearDebug);
63
+
64
+ // Pause/resume debug list updates. While paused the button pulses and
65
+ // shows a play icon as a reminder that new messages are being withheld.
66
+ // Plain SVG (currentColor) instead of emoji glyphs for a crisp, theme-
67
+ // consistent icon instead of the platform's (often colored) emoji font.
68
+ const PAUSE_ICON = `<svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><rect x="3" y="2" width="4" height="12" rx="1"></rect><rect x="9" y="2" width="4" height="12" rx="1"></rect></svg>`;
69
+ const PLAY_ICON = `<svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M4 2.5v11l10-5.5z"></path></svg>`;
70
+ const pauseDebugBtn = document.getElementById('pause-debug-btn');
71
+ if (pauseDebugBtn) {
72
+ pauseDebugBtn.innerHTML = PAUSE_ICON;
73
+ pauseDebugBtn.addEventListener('click', () => {
74
+ const paused = toggleDebugPaused();
75
+ pauseDebugBtn.classList.toggle('debug-paused-active', paused);
76
+ pauseDebugBtn.innerHTML = paused ? PLAY_ICON : PAUSE_ICON;
77
+ pauseDebugBtn.title = paused ? 'Resume updates (paused)' : 'Pause updates';
78
+ });
79
+ }
80
+
81
+ // Add workflow button
82
+ const addWorkflowBtn = document.getElementById('add-workflow-btn');
83
+ if (addWorkflowBtn) {
84
+ addWorkflowBtn.addEventListener('click', () => {
85
+ import('./workflows.js').then(({ createNewWorkflow }) => {
86
+ createNewWorkflow();
87
+ });
88
+ });
89
+ }
90
+
91
+ // Deploy dropdown
92
+ const deployDropdownBtn = document.getElementById('deploy-dropdown-btn');
93
+ const deployDropdown = document.getElementById('deploy-dropdown');
94
+ const deployModifiedBtn = document.getElementById('deploy-modified-btn');
95
+ const deployFullBtn = document.getElementById('deploy-full-btn');
96
+ const deployModeIcon = document.getElementById('deploy-mode-icon');
97
+
98
+ deployDropdownBtn.addEventListener('click', (e) => {
99
+ e.stopPropagation();
100
+ deployDropdown.classList.toggle('hidden');
101
+ });
102
+
103
+ deployModifiedBtn.addEventListener('click', () => {
104
+ deployMode = 'modified';
105
+ deployModifiedBtn.classList.add('active');
106
+ deployFullBtn.classList.remove('active');
107
+ deployModeIcon.textContent = '◐';
108
+ deployDropdown.classList.add('hidden');
109
+ });
110
+
111
+ deployFullBtn.addEventListener('click', () => {
112
+ deployMode = 'full';
113
+ deployFullBtn.classList.add('active');
114
+ deployModifiedBtn.classList.remove('active');
115
+ deployModeIcon.textContent = '●';
116
+ deployDropdown.classList.add('hidden');
117
+ });
118
+
119
+ // Restart button
120
+ const deployRestartBtn = document.getElementById('deploy-restart-btn');
121
+ deployRestartBtn.addEventListener('click', () => {
122
+ restartWorkflow();
123
+ deployDropdown.classList.add('hidden');
124
+ });
125
+
126
+ // Stop button - an action like Restart, not a deploy mode: it does not
127
+ // change the selected Modified/Full mode.
128
+ const deployStopBtn = document.getElementById('deploy-stop-btn');
129
+ deployStopBtn.addEventListener('click', () => {
130
+ stopWorkflow();
131
+ deployDropdown.classList.add('hidden');
132
+ });
133
+
134
+ // Close deploy dropdown when clicking outside
135
+ document.addEventListener('click', (e) => {
136
+ if (!deployDropdown.classList.contains('hidden') &&
137
+ !deployDropdown.contains(e.target) &&
138
+ e.target !== deployDropdownBtn) {
139
+ deployDropdown.classList.add('hidden');
140
+ }
141
+ });
142
+
143
+ // Hamburger menu toggle
144
+ const menuBtn = document.getElementById('menu-btn');
145
+ const menuDropdown = document.getElementById('menu-dropdown');
146
+
147
+ menuBtn.addEventListener('click', (e) => {
148
+ e.stopPropagation();
149
+ menuDropdown.classList.toggle('hidden');
150
+ });
151
+
152
+ // Close menu when clicking outside
153
+ document.addEventListener('click', (e) => {
154
+ if (!menuDropdown.classList.contains('hidden') &&
155
+ !menuDropdown.contains(e.target) &&
156
+ e.target !== menuBtn) {
157
+ menuDropdown.classList.add('hidden');
158
+ }
159
+ });
160
+
161
+ // Close menu after clicking a menu item
162
+ document.getElementById('clear-btn').addEventListener('click', () => {
163
+ menuDropdown.classList.add('hidden');
164
+ });
165
+
166
+ // Submenu visibility is managed by CSS (:hover / :focus-within).
167
+
168
+ document.getElementById('import-btn').addEventListener('click', () => {
169
+ menuDropdown.classList.add('hidden');
170
+ if (exportSubmenu) exportSubmenu.classList.add('hidden');
171
+ });
172
+
173
+ // Close properties button
174
+ document.getElementById('close-properties-btn').addEventListener('click', () => {
175
+ const propertiesPanel = document.getElementById('properties-panel-container');
176
+ propertiesPanel.classList.add('hidden');
177
+ });
178
+
179
+ // Sidebar tab switching
180
+ document.querySelectorAll('.sidebar-tab').forEach(tab => {
181
+ tab.addEventListener('click', () => {
182
+ const panelId = tab.dataset.panel;
183
+
184
+ // Update active tab
185
+ document.querySelectorAll('.sidebar-tab').forEach(t => t.classList.remove('active'));
186
+ tab.classList.add('active');
187
+
188
+ // Show corresponding panel
189
+ document.querySelectorAll('.sidebar-panel').forEach(p => p.classList.remove('active'));
190
+ document.getElementById(`${panelId}-panel`).classList.add('active');
191
+ });
192
+ });
193
+
194
+ // Debug filter controls
195
+ document.getElementById('filter-info').addEventListener('click', (e) => {
196
+ e.currentTarget.classList.toggle('active');
197
+ const isActive = e.currentTarget.classList.contains('active');
198
+ import('./debug.js').then(({ toggleInfoMessages }) => {
199
+ toggleInfoMessages(isActive);
200
+ });
201
+ });
202
+
203
+ document.getElementById('filter-errors').addEventListener('click', (e) => {
204
+ e.currentTarget.classList.toggle('active');
205
+ const isActive = e.currentTarget.classList.contains('active');
206
+ import('./debug.js').then(({ toggleErrorMessages }) => {
207
+ toggleErrorMessages(isActive);
208
+ });
209
+ });
210
+
211
+ document.getElementById('collapse-similar').addEventListener('click', (e) => {
212
+ e.currentTarget.classList.toggle('active');
213
+ const isActive = e.currentTarget.classList.contains('active');
214
+ import('./debug.js').then(({ toggleCollapseSimilar }) => {
215
+ toggleCollapseSimilar(isActive);
216
+ });
217
+ });
218
+
219
+ // Properties panel resize
220
+ setupPropertiesResize();
221
+
222
+ // Left palette + right sidebar resize/toggle handles
223
+ setupSidePanelGrabs();
224
+
225
+ // Canvas click to deselect or select connections
226
+ nodesContainer.addEventListener('click', (e) => {
227
+ if (e.target === nodesContainer && !state.justSelectedConnection) {
228
+ // Check if clicking near a connection
229
+ import('./connections.js').then(({ getConnectionAtPoint, selectConnection, deselectConnection }) => {
230
+ // Get click coordinates in canvas (SVG) space, zoom-aware.
231
+ // Threshold scales with 1/zoom so the click slop stays ~20 screen px.
232
+ const canvasPoint = clientToCanvas(e.clientX, e.clientY);
233
+
234
+ const clickedConnection = getConnectionAtPoint(canvasPoint.x, canvasPoint.y, 20 / getZoom());
235
+ if (clickedConnection) {
236
+ // Select the connection
237
+ selectConnection(clickedConnection.source, clickedConnection.target, clickedConnection.sourceOutput);
238
+ state.justSelectedConnection = true;
239
+ setTimeout(() => {
240
+ state.justSelectedConnection = false;
241
+ }, 100);
242
+ } else {
243
+ // Deselect everything
244
+ deselectNode();
245
+ deselectConnection();
246
+ }
247
+ });
248
+ }
249
+ });
250
+
251
+ // Keyboard shortcuts
252
+ document.addEventListener('keydown', (e) => {
253
+ // Check if user is actively editing a form field (use activeElement, not e.target
254
+ // which is always the document for listeners attached to document).
255
+ // Only text-entry controls swallow Delete/Backspace - non-text inputs
256
+ // (checkboxes, buttons, etc.) must not block node deletion.
257
+ const activeEl = document.activeElement;
258
+ const NON_TEXT_INPUT_TYPES = ['checkbox', 'radio', 'button', 'submit', 'reset', 'range', 'color', 'file'];
259
+ const isEditingInput = activeEl && (
260
+ (activeEl.tagName === 'INPUT' && !NON_TEXT_INPUT_TYPES.includes(activeEl.type)) ||
261
+ activeEl.tagName === 'TEXTAREA' ||
262
+ activeEl.tagName === 'SELECT' ||
263
+ activeEl.isContentEditable
264
+ );
265
+
266
+ if (e.key === 'Escape') {
267
+ deselectAllNodes();
268
+ // Return focus to the canvas so keyboard shortcuts work immediately
269
+ const canvas = document.getElementById('canvas');
270
+ if (canvas) canvas.focus();
271
+ }
272
+
273
+ // Delete works unless user is actively editing a text field
274
+ if ((e.key === 'Delete' || e.key === 'Backspace') && !isEditingInput) {
275
+ console.log('Delete key pressed, selectedNodes:', state.selectedNodes.size, 'selectedConnection:', state.selectedConnection);
276
+ if (state.selectedNodes.size > 0) {
277
+ const nodesToDelete = Array.from(state.selectedNodes);
278
+
279
+ // Save state before deleting - must be sync or await
280
+ import('./history.js').then(({ saveState }) => {
281
+ saveState('delete nodes');
282
+
283
+ if (e.ctrlKey || e.metaKey) {
284
+ // Ctrl+Delete: Delete and reconnect nodes on either side
285
+ nodesToDelete.forEach(nodeId => deleteNodeAndReconnect(nodeId));
286
+ } else {
287
+ // Normal Delete: Just delete the nodes
288
+ nodesToDelete.forEach(nodeId => deleteNode(nodeId));
289
+ }
290
+ deselectAllNodes();
291
+ });
292
+ } else if (state.selectedConnection) {
293
+ console.log('Deleting selected connection');
294
+ import('./history.js').then(({ saveState }) => {
295
+ saveState('delete connection');
296
+ import('./connections.js').then(({ deleteSelectedConnection }) => {
297
+ deleteSelectedConnection();
298
+ });
299
+ });
300
+ }
301
+ }
302
+
303
+ // Copy (Ctrl+C or Cmd+C)
304
+ if ((e.ctrlKey || e.metaKey) && e.key === 'c' && !isEditingInput) {
305
+ e.preventDefault();
306
+ import('./clipboard.js').then(({ copySelectedNodes }) => {
307
+ copySelectedNodes();
308
+ });
309
+ }
310
+
311
+ // Cut (Ctrl+X or Cmd+X)
312
+ if ((e.ctrlKey || e.metaKey) && e.key === 'x' && !isEditingInput) {
313
+ e.preventDefault();
314
+ import('./clipboard.js').then(({ cutSelectedNodes }) => {
315
+ cutSelectedNodes();
316
+ });
317
+ import('./history.js').then(({ saveState }) => {
318
+ saveState('cut nodes');
319
+ });
320
+ }
321
+
322
+ // Paste (Ctrl+V or Cmd+V)
323
+ if ((e.ctrlKey || e.metaKey) && e.key === 'v' && !isEditingInput) {
324
+ e.preventDefault();
325
+ import('./clipboard.js').then(({ pasteNodes }) => {
326
+ pasteNodes();
327
+ });
328
+ import('./history.js').then(({ saveState }) => {
329
+ saveState('paste nodes');
330
+ });
331
+ }
332
+
333
+ // Undo (Ctrl+Z or Cmd+Z)
334
+ if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey && !isEditingInput) {
335
+ e.preventDefault();
336
+ import('./history.js').then(({ undo }) => {
337
+ undo();
338
+ });
339
+ }
340
+
341
+ // Redo (Ctrl+Y or Cmd+Shift+Z)
342
+ if (((e.ctrlKey && e.key === 'y') || (e.metaKey && e.shiftKey && e.key === 'z')) && !isEditingInput) {
343
+ e.preventDefault();
344
+ import('./history.js').then(({ redo }) => {
345
+ redo();
346
+ });
347
+ }
348
+ });
349
+
350
+ setupSelectionBox();
351
+ }
352
+
353
+ function setupSidePanelGrabs() {
354
+ const leftPanel = document.getElementById('left-palette');
355
+ const leftGrab = document.getElementById('left-palette-grab');
356
+ const rightPanel = document.getElementById('right-sidebar');
357
+ const rightGrab = document.getElementById('right-sidebar-grab');
358
+
359
+ setupOneSidePanelGrab({
360
+ panel: leftPanel,
361
+ grab: leftGrab,
362
+ side: 'left',
363
+ minWidth: 180,
364
+ maxWidth: 600,
365
+ collapsedWidth: 18,
366
+ storageKey: 'pynode.leftPalette'
367
+ });
368
+
369
+ setupOneSidePanelGrab({
370
+ panel: rightPanel,
371
+ grab: rightGrab,
372
+ side: 'right',
373
+ minWidth: 240,
374
+ maxWidth: 700,
375
+ collapsedWidth: 18,
376
+ storageKey: 'pynode.rightSidebar'
377
+ });
378
+ }
379
+
380
+ function setupOneSidePanelGrab({ panel, grab, side, minWidth, maxWidth, collapsedWidth, storageKey }) {
381
+ if (!panel || !grab) return;
382
+
383
+ const toggleBtn = grab.querySelector('.panel-toggle-btn');
384
+
385
+ const widthKey = `${storageKey}.width`;
386
+ const collapsedKey = `${storageKey}.collapsed`;
387
+
388
+ const applyCollapsed = (collapsed) => {
389
+ if (collapsed) {
390
+ panel.classList.add('collapsed');
391
+ panel.style.width = `${collapsedWidth}px`;
392
+ } else {
393
+ panel.classList.remove('collapsed');
394
+ const savedWidth = parseInt(localStorage.getItem(widthKey) || '', 10);
395
+ if (!Number.isNaN(savedWidth)) {
396
+ panel.style.width = `${savedWidth}px`;
397
+ }
398
+ }
399
+ localStorage.setItem(collapsedKey, collapsed ? '1' : '0');
400
+ updateToggleIcon();
401
+ };
402
+
403
+ const updateToggleIcon = () => {
404
+ if (!toggleBtn) return;
405
+ const isCollapsed = panel.classList.contains('collapsed');
406
+ if (side === 'left') {
407
+ // Left panel: expanded shows '<' (collapse left), collapsed shows '>' (expand right)
408
+ toggleBtn.textContent = isCollapsed ? '>' : '<';
409
+ } else {
410
+ // Right panel: expanded shows '>' (collapse right), collapsed shows '<' (expand left)
411
+ toggleBtn.textContent = isCollapsed ? '<' : '>';
412
+ }
413
+ };
414
+
415
+ // Initial state
416
+ const savedCollapsed = localStorage.getItem(collapsedKey) === '1';
417
+ const savedWidth = parseInt(localStorage.getItem(widthKey) || '', 10);
418
+ if (!Number.isNaN(savedWidth)) {
419
+ panel.style.width = `${savedWidth}px`;
420
+ }
421
+ applyCollapsed(savedCollapsed);
422
+
423
+ if (toggleBtn) {
424
+ toggleBtn.addEventListener('click', (e) => {
425
+ e.preventDefault();
426
+ e.stopPropagation();
427
+ applyCollapsed(!panel.classList.contains('collapsed'));
428
+ });
429
+ }
430
+
431
+ let isResizing = false;
432
+ let didDrag = false;
433
+ let startX = 0;
434
+ let startWidth = 0;
435
+
436
+ const beginResize = (e) => {
437
+ if (toggleBtn && e.target === toggleBtn) return;
438
+
439
+ // If currently collapsed and user starts dragging, expand first.
440
+ if (panel.classList.contains('collapsed')) {
441
+ applyCollapsed(false);
442
+ }
443
+
444
+ isResizing = true;
445
+ didDrag = false;
446
+ startX = e.clientX;
447
+ startWidth = panel.offsetWidth;
448
+ document.body.style.cursor = 'ew-resize';
449
+ e.preventDefault();
450
+ e.stopPropagation();
451
+ };
452
+
453
+ const onMove = (e) => {
454
+ if (!isResizing) return;
455
+
456
+ const rawDelta = side === 'left' ? (e.clientX - startX) : (startX - e.clientX);
457
+ if (Math.abs(rawDelta) > 3) didDrag = true;
458
+
459
+ const nextWidth = Math.max(minWidth, Math.min(maxWidth, startWidth + rawDelta));
460
+ panel.style.width = `${nextWidth}px`;
461
+ };
462
+
463
+ const endResize = () => {
464
+ if (!isResizing) return;
465
+ isResizing = false;
466
+ document.body.style.cursor = '';
467
+
468
+ if (didDrag) {
469
+ const w = panel.offsetWidth;
470
+ localStorage.setItem(widthKey, String(w));
471
+ }
472
+ };
473
+
474
+ grab.addEventListener('mousedown', beginResize);
475
+ document.addEventListener('mousemove', onMove);
476
+ document.addEventListener('mouseup', endResize);
477
+ }
478
+
479
+ function togglePropertiesPanel() {
480
+ const propertiesPanel = document.getElementById('properties-panel-container');
481
+ propertiesPanel.classList.toggle('hidden');
482
+ }
483
+
484
+ // Throttle helper for dragover
485
+ let lastDragOverTime = 0;
486
+ const DRAG_THROTTLE_MS = 50; // Only check every 50ms
487
+
488
+ function handleCanvasDragOver(e) {
489
+ e.preventDefault();
490
+
491
+ // Throttle the connection check for performance
492
+ const now = Date.now();
493
+ if (now - lastDragOverTime < DRAG_THROTTLE_MS) {
494
+ return;
495
+ }
496
+ lastDragOverTime = now;
497
+
498
+ // Check if dragging over a connection and highlight it (canvas coords, zoom-aware)
499
+ const canvasPoint = clientToCanvas(e.clientX, e.clientY);
500
+
501
+ const hoveredConnection = getConnectionAtPoint(canvasPoint.x, canvasPoint.y, 15 / getZoom());
502
+ if (hoveredConnection) {
503
+ highlightConnectionForInsert(hoveredConnection);
504
+ } else {
505
+ clearConnectionHighlight();
506
+ }
507
+ }
508
+
509
+ function handleCanvasDragLeave(e) {
510
+ // Clear highlight when leaving the canvas
511
+ clearConnectionHighlight();
512
+ }
513
+
514
+ function handleCanvasDrop(e) {
515
+ e.preventDefault();
516
+
517
+ // Get the hovered connection before clearing
518
+ const connectionToInsertInto = getHoveredConnection();
519
+
520
+ // Clear any connection highlight
521
+ clearConnectionHighlight();
522
+
523
+ const nodeType = e.dataTransfer.getData('nodeType');
524
+ if (!nodeType) return;
525
+
526
+ // Get the drag offset from where the user clicked on the palette item
527
+ const offsetX = parseFloat(e.dataTransfer.getData('dragOffsetX')) || 0;
528
+ const offsetY = parseFloat(e.dataTransfer.getData('dragOffsetY')) || 0;
529
+
530
+ // Drop position in canvas coordinates (zoom-aware). The drag offset is the
531
+ // grab point within the palette item in client px, so subtract it in
532
+ // client space before converting.
533
+ const canvasPoint = clientToCanvas(e.clientX - offsetX, e.clientY - offsetY);
534
+ const x = canvasPoint.x;
535
+ const y = canvasPoint.y;
536
+
537
+ const newNodeId = createNode(nodeType, x, y);
538
+
539
+ if (newNodeId) {
540
+ // Drop focus out of the palette search (or any other input) so keyboard
541
+ // shortcuts like Delete work immediately on the new node.
542
+ const activeEl = document.activeElement;
543
+ if (activeEl && activeEl !== document.body && typeof activeEl.blur === 'function') {
544
+ activeEl.blur();
545
+ }
546
+
547
+ // Select the freshly dropped node so it can be deleted/moved right away.
548
+ selectNode(newNodeId, false);
549
+
550
+ // Snap the new node so input port 0 aligns to the grid.
551
+ setTimeout(() => {
552
+ snapNodeToGrid(newNodeId);
553
+ }, 0);
554
+ }
555
+
556
+ // If dropped on a connection, insert the node into it
557
+ if (connectionToInsertInto && newNodeId) {
558
+ // Small delay to ensure node is fully rendered
559
+ setTimeout(() => {
560
+ insertNodeIntoConnection(newNodeId, connectionToInsertInto);
561
+ }, 50);
562
+ }
563
+ }
564
+
565
+ // The selection box is an HTML overlay on document.body and works entirely in
566
+ // CLIENT coordinates: the box rect and each node's getBoundingClientRect()
567
+ // are compared in the same (zoomed) client space, so hit-testing stays
568
+ // correct at every zoom level without conversion.
569
+ function setupSelectionBox() {
570
+ const canvasContainer = document.querySelector('.canvas-container');
571
+
572
+ canvasContainer.addEventListener('mousedown', (e) => {
573
+ // Only start selection box with left mouse button (button === 0)
574
+ if (e.button !== 0) return;
575
+
576
+ const isNode = e.target.closest('.node');
577
+ const isPort = e.target.classList.contains('port');
578
+ const isSvgPath = e.target.tagName === 'path';
579
+
580
+ // Don't start selection box if clicking on node, port, or connection
581
+ if (isNode || isPort || isSvgPath) return;
582
+
583
+ if (!e.ctrlKey && !e.metaKey) {
584
+ deselectAllNodes();
585
+ }
586
+
587
+ state.selectionStart = { x: e.clientX, y: e.clientY };
588
+ state.selectionBox = document.createElement('div');
589
+ state.selectionBox.className = 'selection-box';
590
+ state.selectionBox.style.left = `${e.clientX}px`;
591
+ state.selectionBox.style.top = `${e.clientY}px`;
592
+ state.selectionBox.style.width = '0';
593
+ state.selectionBox.style.height = '0';
594
+ document.body.appendChild(state.selectionBox);
595
+
596
+ e.preventDefault();
597
+ });
598
+
599
+ document.addEventListener('mousemove', (e) => {
600
+ if (!state.selectionBox || !state.selectionStart) return;
601
+
602
+ const currentX = e.clientX;
603
+ const currentY = e.clientY;
604
+ const startX = state.selectionStart.x;
605
+ const startY = state.selectionStart.y;
606
+
607
+ const left = Math.min(startX, currentX);
608
+ const top = Math.min(startY, currentY);
609
+ const width = Math.abs(currentX - startX);
610
+ const height = Math.abs(currentY - startY);
611
+
612
+ state.selectionBox.style.left = `${left}px`;
613
+ state.selectionBox.style.top = `${top}px`;
614
+ state.selectionBox.style.width = `${width}px`;
615
+ state.selectionBox.style.height = `${height}px`;
616
+
617
+ const nodesInBox = new Set();
618
+
619
+ state.nodes.forEach((nodeData, nodeId) => {
620
+ const nodeEl = document.getElementById(`node-${nodeId}`);
621
+ if (!nodeEl) return;
622
+
623
+ const rect = nodeEl.getBoundingClientRect();
624
+ const boxLeft = left;
625
+ const boxTop = top;
626
+ const boxRight = left + width;
627
+ const boxBottom = top + height;
628
+
629
+ if (rect.left < boxRight && rect.right > boxLeft &&
630
+ rect.top < boxBottom && rect.bottom > boxTop) {
631
+ nodesInBox.add(nodeId);
632
+ }
633
+ });
634
+
635
+ nodesInBox.forEach(nodeId => {
636
+ if (!state.selectedNodes.has(nodeId)) {
637
+ state.selectedNodes.add(nodeId);
638
+ const nodeEl = document.getElementById(`node-${nodeId}`);
639
+ if (nodeEl) nodeEl.classList.add('selected');
640
+ }
641
+ });
642
+ });
643
+
644
+ document.addEventListener('mouseup', () => {
645
+ if (state.selectionBox) {
646
+ // Check if we should select a connection instead of nodes
647
+ const boxRect = state.selectionBox.getBoundingClientRect();
648
+
649
+ // If selection box is very small (like a click), check for connection using distance
650
+ const isSmallBox = boxRect.width < 50 && boxRect.height < 50;
651
+
652
+ if (isSmallBox) {
653
+ // Use proper distance-based connection detection instead of bounding box
654
+ const centerX = boxRect.left + boxRect.width / 2;
655
+ const centerY = boxRect.top + boxRect.height / 2;
656
+
657
+ // Transform to canvas (SVG) coordinates, zoom-aware
658
+ const canvasPoint = clientToCanvas(centerX, centerY);
659
+
660
+ import('./connections.js').then(({ getConnectionAtPoint, selectConnection }) => {
661
+ const foundConnection = getConnectionAtPoint(canvasPoint.x, canvasPoint.y, 20 / getZoom());
662
+
663
+ if (foundConnection) {
664
+ console.log('Found connection via distance check:', foundConnection);
665
+ selectConnection(foundConnection.source, foundConnection.target, foundConnection.sourceOutput);
666
+
667
+ // Prevent canvas click from deselecting immediately
668
+ state.justSelectedConnection = true;
669
+ setTimeout(() => {
670
+ state.justSelectedConnection = false;
671
+ }, 100);
672
+ }
673
+ });
674
+ }
675
+
676
+ state.selectionBox.remove();
677
+ state.selectionBox = null;
678
+ state.selectionStart = null;
679
+ }
680
+ });
681
+ }
682
+
683
+ // Middle-mouse panning works in scroll/client px (1 scroll px == 1 client px
684
+ // regardless of zoom), so no canvas-coordinate conversion is needed here.
685
+ function setupCanvasPanning(canvasContainer) {
686
+ let isPanning = false;
687
+ let startScrollLeft = 0;
688
+ let startScrollTop = 0;
689
+ let startX = 0;
690
+ let startY = 0;
691
+
692
+ canvasContainer.addEventListener('mousedown', (e) => {
693
+ // Middle mouse button (button === 1)
694
+ if (e.button === 1) {
695
+ isPanning = true;
696
+ startScrollLeft = canvasContainer.scrollLeft;
697
+ startScrollTop = canvasContainer.scrollTop;
698
+ startX = e.clientX;
699
+ startY = e.clientY;
700
+ canvasContainer.style.cursor = 'grabbing';
701
+ e.preventDefault();
702
+ }
703
+ });
704
+
705
+ canvasContainer.addEventListener('mousemove', (e) => {
706
+ if (!isPanning) return;
707
+
708
+ const deltaX = e.clientX - startX;
709
+ const deltaY = e.clientY - startY;
710
+
711
+ canvasContainer.scrollLeft = startScrollLeft - deltaX;
712
+ canvasContainer.scrollTop = startScrollTop - deltaY;
713
+ });
714
+
715
+ canvasContainer.addEventListener('mouseup', (e) => {
716
+ if (e.button === 1) {
717
+ isPanning = false;
718
+ canvasContainer.style.cursor = '';
719
+ }
720
+ });
721
+
722
+ canvasContainer.addEventListener('mouseleave', () => {
723
+ if (isPanning) {
724
+ isPanning = false;
725
+ canvasContainer.style.cursor = '';
726
+ }
727
+ });
728
+
729
+ // Prevent context menu on middle click
730
+ canvasContainer.addEventListener('contextmenu', (e) => {
731
+ if (e.button === 1) {
732
+ e.preventDefault();
733
+ }
734
+ });
735
+ }
736
+
737
+ function setupPropertiesResize() {
738
+ const resizeHandle = document.getElementById('properties-resize-handle');
739
+ const propertiesPanel = document.getElementById('properties-panel-container');
740
+
741
+ if (!resizeHandle || !propertiesPanel) return;
742
+
743
+ let isResizing = false;
744
+ let startX = 0;
745
+ let startWidth = 0;
746
+
747
+ resizeHandle.addEventListener('mousedown', (e) => {
748
+ isResizing = true;
749
+ startX = e.clientX;
750
+ startWidth = propertiesPanel.offsetWidth;
751
+ propertiesPanel.classList.add('resizing');
752
+ document.body.style.cursor = 'ew-resize';
753
+ e.preventDefault();
754
+ });
755
+
756
+ document.addEventListener('mousemove', (e) => {
757
+ if (!isResizing) return;
758
+
759
+ const deltaX = startX - e.clientX;
760
+ const newWidth = startWidth + deltaX;
761
+
762
+ // Respect min and max width constraints
763
+ if (newWidth >= 380 && newWidth <= 800) {
764
+ propertiesPanel.style.width = `${newWidth}px`;
765
+ }
766
+ });
767
+
768
+ document.addEventListener('mouseup', () => {
769
+ if (isResizing) {
770
+ isResizing = false;
771
+ propertiesPanel.classList.remove('resizing');
772
+ document.body.style.cursor = '';
773
+ }
774
+ });
775
+ }