project-graph-mcp 2.2.6 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +81 -0
- package/CHANGELOG.md +57 -0
- package/README.md +9 -4
- package/package.json +6 -13
- package/src/compact/expand.js +1 -1
- package/src/core/graph-builder.js +2 -2
- package/src/core/parser.js +2 -2
- package/src/network/server.js +1 -2
- package/vendor/symbiote-node/CHANGELOG.md +31 -0
- package/vendor/symbiote-node/LICENSE +21 -0
- package/vendor/symbiote-node/README.md +206 -0
- package/vendor/symbiote-node/canvas/AutoLayout.js +725 -0
- package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.css.js +73 -0
- package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.js +93 -0
- package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.tpl.js +9 -0
- package/vendor/symbiote-node/canvas/CanvasConnectionRenderer.js +962 -0
- package/vendor/symbiote-node/canvas/ConnectionRenderer.js +1468 -0
- package/vendor/symbiote-node/canvas/FlowSimulator.js +323 -0
- package/vendor/symbiote-node/canvas/ForceLayout.js +189 -0
- package/vendor/symbiote-node/canvas/ForceWorker.js +1325 -0
- package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.css.js +97 -0
- package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.js +176 -0
- package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.tpl.js +12 -0
- package/vendor/symbiote-node/canvas/LODManager.js +88 -0
- package/vendor/symbiote-node/canvas/Minimap/Minimap.css.js +71 -0
- package/vendor/symbiote-node/canvas/Minimap/Minimap.js +207 -0
- package/vendor/symbiote-node/canvas/Minimap/Minimap.tpl.js +9 -0
- package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.css.js +261 -0
- package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.js +1840 -0
- package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.tpl.js +22 -0
- package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.css.js +97 -0
- package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.js +132 -0
- package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.tpl.js +21 -0
- package/vendor/symbiote-node/canvas/NodeViewManager.js +584 -0
- package/vendor/symbiote-node/canvas/PinExpansion.js +131 -0
- package/vendor/symbiote-node/canvas/PseudoConnection.js +80 -0
- package/vendor/symbiote-node/canvas/SubgraphManager.js +201 -0
- package/vendor/symbiote-node/canvas/SubgraphRouter.js +443 -0
- package/vendor/symbiote-node/canvas/ViewportActions.js +446 -0
- package/vendor/symbiote-node/core/Connection.js +45 -0
- package/vendor/symbiote-node/core/Editor.js +451 -0
- package/vendor/symbiote-node/core/Frame.js +31 -0
- package/vendor/symbiote-node/core/GraphMermaid.js +348 -0
- package/vendor/symbiote-node/core/GraphText.js +210 -0
- package/vendor/symbiote-node/core/Node.js +143 -0
- package/vendor/symbiote-node/core/Portal.js +104 -0
- package/vendor/symbiote-node/core/Socket.js +185 -0
- package/vendor/symbiote-node/core/SubgraphNode.js +125 -0
- package/vendor/symbiote-node/index.js +103 -0
- package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.css.js +361 -0
- package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.js +332 -0
- package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.tpl.js +96 -0
- package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.css.js +104 -0
- package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.js +133 -0
- package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.tpl.js +33 -0
- package/vendor/symbiote-node/interactions/ConnectFlow.js +307 -0
- package/vendor/symbiote-node/interactions/Drag.js +102 -0
- package/vendor/symbiote-node/interactions/Selector.js +132 -0
- package/vendor/symbiote-node/interactions/SnapGrid.js +65 -0
- package/vendor/symbiote-node/interactions/Zoom.js +140 -0
- package/vendor/symbiote-node/layout/ActionZone/ActionZone.css.js +88 -0
- package/vendor/symbiote-node/layout/ActionZone/ActionZone.js +254 -0
- package/vendor/symbiote-node/layout/ActionZone/ActionZone.tpl.js +11 -0
- package/vendor/symbiote-node/layout/Layout/Layout.css.js +88 -0
- package/vendor/symbiote-node/layout/Layout/Layout.js +622 -0
- package/vendor/symbiote-node/layout/Layout/Layout.tpl.js +25 -0
- package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.css.js +293 -0
- package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.js +467 -0
- package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.tpl.js +33 -0
- package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.css.js +46 -0
- package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.js +102 -0
- package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.tpl.js +6 -0
- package/vendor/symbiote-node/layout/LayoutRouter/LayoutRouter.js +156 -0
- package/vendor/symbiote-node/layout/LayoutRouter/routerSync.js +250 -0
- package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.css.js +379 -0
- package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.js +263 -0
- package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.tpl.js +20 -0
- package/vendor/symbiote-node/layout/LayoutSidebar/SidebarSection.js +183 -0
- package/vendor/symbiote-node/layout/LayoutTree.js +246 -0
- package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.css.js +43 -0
- package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.js +89 -0
- package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.tpl.js +14 -0
- package/vendor/symbiote-node/layout/index.js +16 -0
- package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.css.js +61 -0
- package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.js +79 -0
- package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.tpl.js +19 -0
- package/vendor/symbiote-node/node/CtrlItem/CtrlItem.css.js +41 -0
- package/vendor/symbiote-node/node/CtrlItem/CtrlItem.js +24 -0
- package/vendor/symbiote-node/node/CtrlItem/CtrlItem.tpl.js +16 -0
- package/vendor/symbiote-node/node/GraphFrame/GraphFrame.css.js +65 -0
- package/vendor/symbiote-node/node/GraphFrame/GraphFrame.js +29 -0
- package/vendor/symbiote-node/node/GraphFrame/GraphFrame.tpl.js +13 -0
- package/vendor/symbiote-node/node/GraphNode/GraphNode.css.js +683 -0
- package/vendor/symbiote-node/node/GraphNode/GraphNode.js +92 -0
- package/vendor/symbiote-node/node/GraphNode/GraphNode.tpl.js +17 -0
- package/vendor/symbiote-node/node/NodeSocket/NodeSocket.js +25 -0
- package/vendor/symbiote-node/node/NodeSocket/NodeSocket.tpl.js +7 -0
- package/vendor/symbiote-node/node/PortItem/PortItem.css.js +90 -0
- package/vendor/symbiote-node/node/PortItem/PortItem.js +87 -0
- package/vendor/symbiote-node/node/PortItem/PortItem.tpl.js +10 -0
- package/vendor/symbiote-node/package.json +59 -0
- package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.css.js +143 -0
- package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.js +131 -0
- package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.tpl.js +16 -0
- package/vendor/symbiote-node/plugins/History.js +384 -0
- package/vendor/symbiote-node/plugins/Readonly.js +59 -0
- package/vendor/symbiote-node/shapes/CircleShape.js +80 -0
- package/vendor/symbiote-node/shapes/CommentShape.js +35 -0
- package/vendor/symbiote-node/shapes/DiamondShape.js +115 -0
- package/vendor/symbiote-node/shapes/NodeShape.js +80 -0
- package/vendor/symbiote-node/shapes/PillShape.js +91 -0
- package/vendor/symbiote-node/shapes/RectShape.js +72 -0
- package/vendor/symbiote-node/shapes/SVGShape.js +494 -0
- package/vendor/symbiote-node/shapes/index.js +53 -0
- package/vendor/symbiote-node/themes/Palette.js +32 -0
- package/vendor/symbiote-node/themes/Skin.js +113 -0
- package/vendor/symbiote-node/themes/Theme.js +84 -0
- package/vendor/symbiote-node/themes/carbon.js +137 -0
- package/vendor/symbiote-node/themes/dark.js +137 -0
- package/vendor/symbiote-node/themes/ebook.js +138 -0
- package/vendor/symbiote-node/themes/grey.js +137 -0
- package/vendor/symbiote-node/themes/light.js +137 -0
- package/vendor/symbiote-node/themes/neon.js +138 -0
- package/vendor/symbiote-node/themes/pcb.js +273 -0
- package/vendor/symbiote-node/themes/synthwave.js +137 -0
- package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.css.js +86 -0
- package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.js +128 -0
- package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.tpl.js +29 -0
- package/web/app.js +6 -5
- package/web/components/canvas-graph.js +1666 -0
- package/web/components/event-feed/CodeWidget.js +32 -0
- package/web/components/event-feed/EventWidget.js +97 -0
- package/web/components/event-feed/ListWidget.js +57 -0
- package/web/components/event-feed/MiniGraphWidget.js +69 -0
- package/web/dashboard.js +1 -1
- package/web/index.html +4 -0
- package/web/panels/ActionBoard/ActionBoard.js +1 -1
- package/web/panels/SettingsPanel/SettingsPanel.tpl.js +1 -1
- package/web/panels/code-viewer.js +50 -15
- package/web/panels/dep-graph.js +2712 -7
- package/web/panels/file-tree.js +5 -2
- package/web/panels/live-monitor.js +75 -3
- package/web/style.css +33 -0
- package/docs/img/explorer-compact.jpg +0 -0
- package/docs/img/explorer-expanded.jpg +0 -0
- package/src/.contextignore +0 -22
- package/src/.project-graph-cache.json +0 -1
- package/src/compact/.project-graph-cache.json +0 -1
- package/web/.project-graph-cache.json +0 -1
- package/web/panels/SettingsPanel/.project-graph-cache.json +0 -1
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ViewportActions — context menu, keyboard shortcuts, viewport utilities
|
|
3
|
+
*
|
|
4
|
+
* Handles right-click menus (canvas/node/connection),
|
|
5
|
+
* keyboard shortcuts (Delete, Ctrl+A, Escape),
|
|
6
|
+
* fitView, selectAll, deleteSelected, and socket highlighting.
|
|
7
|
+
* Extracted from NodeCanvas to reduce complexity.
|
|
8
|
+
*
|
|
9
|
+
* @module symbiote-node/canvas/ViewportActions
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export class ViewportActions {
|
|
13
|
+
|
|
14
|
+
/** @type {import('../core/Editor.js').NodeEditor} */
|
|
15
|
+
#editor;
|
|
16
|
+
|
|
17
|
+
/** @type {import('../interactions/Selector.js').Selector} */
|
|
18
|
+
#selector;
|
|
19
|
+
|
|
20
|
+
/** @type {Map<string, HTMLElement>} */
|
|
21
|
+
#nodeViews;
|
|
22
|
+
|
|
23
|
+
/** @type {boolean} */
|
|
24
|
+
#readonly = false;
|
|
25
|
+
|
|
26
|
+
/** @type {Array|null} - clipboard for copy/paste */
|
|
27
|
+
#clipboard = null;
|
|
28
|
+
|
|
29
|
+
/** @type {import('./NodeCanvas/NodeCanvas.js').NodeCanvas} */
|
|
30
|
+
#canvas;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {object} config
|
|
34
|
+
* @param {import('../core/Editor.js').NodeEditor} config.editor
|
|
35
|
+
* @param {import('../interactions/Selector.js').Selector} config.selector
|
|
36
|
+
* @param {Map<string, HTMLElement>} config.nodeViews
|
|
37
|
+
* @param {import('./NodeCanvas/NodeCanvas.js').NodeCanvas} config.canvas
|
|
38
|
+
*/
|
|
39
|
+
constructor({ editor, selector, nodeViews, canvas }) {
|
|
40
|
+
this.#editor = editor;
|
|
41
|
+
this.#selector = selector;
|
|
42
|
+
this.#nodeViews = nodeViews;
|
|
43
|
+
this.#canvas = canvas;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @param {boolean} readonly */
|
|
47
|
+
setReadonly(readonly) {
|
|
48
|
+
this.#readonly = readonly;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Keyboard handler — bind to container
|
|
53
|
+
* @param {KeyboardEvent} e
|
|
54
|
+
*/
|
|
55
|
+
handleKeydown = (e) => {
|
|
56
|
+
if (this.#readonly) return;
|
|
57
|
+
|
|
58
|
+
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
this.deleteSelected();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (e.key === 'a' && (e.ctrlKey || e.metaKey)) {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
this.selectAll();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (e.key === 'Escape') {
|
|
69
|
+
this.#selector.unselectAll();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Copy selected nodes
|
|
73
|
+
if (e.key === 'c' && (e.ctrlKey || e.metaKey)) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
this.#copySelected();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Paste nodes
|
|
79
|
+
if (e.key === 'v' && (e.ctrlKey || e.metaKey)) {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
this.#pasteNodes();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Align horizontal
|
|
85
|
+
if (e.key === 'h' && (e.ctrlKey || e.metaKey) && e.shiftKey) {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
this.alignSelectedHorizontal();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Align vertical
|
|
91
|
+
if (e.key === 'j' && (e.ctrlKey || e.metaKey) && e.shiftKey) {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
this.alignSelectedVertical();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** Select all nodes */
|
|
98
|
+
selectAll() {
|
|
99
|
+
for (const [id] of this.#nodeViews) {
|
|
100
|
+
this.#selector.selectNode(id, true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Delete all selected nodes and connections */
|
|
105
|
+
deleteSelected() {
|
|
106
|
+
if (!this.#editor || this.#readonly) return;
|
|
107
|
+
|
|
108
|
+
for (const connId of this.#selector.getSelectedConnections()) {
|
|
109
|
+
this.#editor.removeConnection(connId);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
for (const nodeId of this.#selector.getSelectedNodes()) {
|
|
113
|
+
this.#editor.removeNode(nodeId);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this.#selector.unselectAll();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Delete a single node */
|
|
120
|
+
deleteNode(nodeId) {
|
|
121
|
+
if (!this.#editor || this.#readonly) return;
|
|
122
|
+
this.#editor.removeNode(nodeId);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Emit clone event for a node */
|
|
126
|
+
cloneNode(nodeId) {
|
|
127
|
+
if (!this.#editor || this.#readonly) return;
|
|
128
|
+
this.#editor.emit('contextclone', { nodeId });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Generic toggle: flip a boolean on node, sync DOM attribute, emit event
|
|
133
|
+
* @param {string} nodeId
|
|
134
|
+
* @param {string} prop - node property name (e.g. 'collapsed', 'muted')
|
|
135
|
+
* @param {string} attr - DOM attribute name (e.g. 'data-collapsed', 'data-muted')
|
|
136
|
+
* @param {string} eventName - editor event (e.g. 'nodecollapse', 'nodemute')
|
|
137
|
+
*/
|
|
138
|
+
#toggleNodeState(nodeId, prop, attr, eventName) {
|
|
139
|
+
if (!this.#editor) return;
|
|
140
|
+
const node = this.#editor.getNode(nodeId);
|
|
141
|
+
if (!node) return;
|
|
142
|
+
node[prop] = !node[prop];
|
|
143
|
+
const el = this.#nodeViews.get(nodeId);
|
|
144
|
+
if (el) {
|
|
145
|
+
node[prop] ? el.setAttribute(attr, '') : el.removeAttribute(attr);
|
|
146
|
+
}
|
|
147
|
+
this.#editor.emit(eventName, { nodeId, [prop]: node[prop] });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @param {string} nodeId */
|
|
151
|
+
collapseNode(nodeId) { this.#toggleNodeState(nodeId, 'collapsed', 'data-collapsed', 'nodecollapse'); }
|
|
152
|
+
|
|
153
|
+
/** @param {string} nodeId */
|
|
154
|
+
muteNode(nodeId) { this.#toggleNodeState(nodeId, 'muted', 'data-muted', 'nodemute'); }
|
|
155
|
+
|
|
156
|
+
/** Delete a single connection */
|
|
157
|
+
deleteConnection(connId) {
|
|
158
|
+
if (!this.#editor || this.#readonly) return;
|
|
159
|
+
this.#editor.removeConnection(connId);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Show context menu based on click target
|
|
164
|
+
* @param {MouseEvent} e
|
|
165
|
+
* @param {HTMLElement} contextMenuEl - context-menu component
|
|
166
|
+
* @param {HTMLElement} container - canvas container for coordinate calc
|
|
167
|
+
* @param {{ panX: number, panY: number, zoom: number }} transform
|
|
168
|
+
*/
|
|
169
|
+
showContextMenu(e, contextMenuEl, container, transform) {
|
|
170
|
+
if (this.#readonly) return;
|
|
171
|
+
e.preventDefault();
|
|
172
|
+
|
|
173
|
+
const target = e.target.closest('graph-node');
|
|
174
|
+
const connTarget = e.target.closest('.sn-conn-path');
|
|
175
|
+
if (!contextMenuEl) return;
|
|
176
|
+
|
|
177
|
+
const rect = container.getBoundingClientRect();
|
|
178
|
+
const menuX = e.clientX - rect.left;
|
|
179
|
+
const menuY = e.clientY - rect.top;
|
|
180
|
+
|
|
181
|
+
if (target) {
|
|
182
|
+
const nodeId = target.getAttribute('node-id');
|
|
183
|
+
contextMenuEl.show(menuX, menuY, [
|
|
184
|
+
{ label: 'Delete Node', icon: 'delete', action: () => this.deleteNode(nodeId) },
|
|
185
|
+
{ label: 'Clone Node', icon: 'content_copy', action: () => this.cloneNode(nodeId) },
|
|
186
|
+
{ label: 'Select All', icon: 'select_all', action: () => this.selectAll() },
|
|
187
|
+
]);
|
|
188
|
+
} else if (connTarget) {
|
|
189
|
+
const connId = connTarget.getAttribute('data-conn-id');
|
|
190
|
+
contextMenuEl.show(menuX, menuY, [
|
|
191
|
+
{ label: 'Delete Connection', icon: 'link_off', action: () => this.deleteConnection(connId) },
|
|
192
|
+
]);
|
|
193
|
+
} else {
|
|
194
|
+
const graphX = (e.clientX - rect.left - transform.panX) / transform.zoom;
|
|
195
|
+
const graphY = (e.clientY - rect.top - transform.panY) / transform.zoom;
|
|
196
|
+
contextMenuEl.show(menuX, menuY, [
|
|
197
|
+
{ label: 'Add Node', icon: 'add_box', action: () => this.#editor?.emit('contextadd', { x: graphX, y: graphY }) },
|
|
198
|
+
{ label: 'Add Comment', icon: 'sticky_note_2', action: () => this.#editor?.emit('contextaddcomment', { x: graphX, y: graphY }) },
|
|
199
|
+
{ label: 'Add Frame', icon: 'dashboard', action: () => this.#editor?.emit('contextaddframe', { x: graphX, y: graphY }) },
|
|
200
|
+
{ label: 'Paste', icon: 'content_paste', action: () => this.#pasteNodes(graphX, graphY) },
|
|
201
|
+
{ label: 'Select All', icon: 'select_all', action: () => this.selectAll() },
|
|
202
|
+
{ label: 'Fit View', icon: 'fit_screen', action: () => this.#canvas?.fitView() },
|
|
203
|
+
{ label: 'Auto Layout', icon: 'auto_fix_high', action: () => this.#editor?.emit('autolayout') },
|
|
204
|
+
]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Highlight sockets compatible with picked socket
|
|
212
|
+
* @param {object} socketData
|
|
213
|
+
* @param {HTMLElement} nodesLayer
|
|
214
|
+
*/
|
|
215
|
+
highlightCompatibleSockets(socketData, nodesLayer) {
|
|
216
|
+
const node = this.#editor.getNode(socketData.nodeId);
|
|
217
|
+
if (!node) return;
|
|
218
|
+
|
|
219
|
+
const isOutput = socketData.side === 'output';
|
|
220
|
+
const pickedPort = isOutput ? node.outputs[socketData.key] : node.inputs[socketData.key];
|
|
221
|
+
if (!pickedPort) return;
|
|
222
|
+
|
|
223
|
+
const pickedSocket = pickedPort.socket;
|
|
224
|
+
|
|
225
|
+
for (const [nodeId, el] of this.#nodeViews) {
|
|
226
|
+
if (nodeId === socketData.nodeId) continue;
|
|
227
|
+
const targetNode = this.#editor.getNode(nodeId);
|
|
228
|
+
if (!targetNode) continue;
|
|
229
|
+
|
|
230
|
+
const ports = isOutput ? targetNode.inputs : targetNode.outputs;
|
|
231
|
+
for (const [key, port] of Object.entries(ports)) {
|
|
232
|
+
const sockets = el.querySelectorAll(`.sn-socket[data-key="${key}"]`);
|
|
233
|
+
for (const sock of sockets) {
|
|
234
|
+
if (pickedSocket.isCompatibleWith(port.socket)) {
|
|
235
|
+
sock.setAttribute('data-compatible', '');
|
|
236
|
+
} else {
|
|
237
|
+
sock.setAttribute('data-incompatible', '');
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const sameSidePorts = isOutput ? targetNode.outputs : targetNode.inputs;
|
|
243
|
+
for (const [key] of Object.entries(sameSidePorts)) {
|
|
244
|
+
const sockets = el.querySelectorAll(`.sn-socket[data-key="${key}"]`);
|
|
245
|
+
for (const sock of sockets) {
|
|
246
|
+
sock.setAttribute('data-incompatible', '');
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Clear all socket highlights
|
|
254
|
+
* @param {HTMLElement} nodesLayer
|
|
255
|
+
*/
|
|
256
|
+
clearSocketHighlights(nodesLayer) {
|
|
257
|
+
const all = nodesLayer.querySelectorAll('.sn-socket[data-compatible], .sn-socket[data-incompatible]');
|
|
258
|
+
for (const sock of all) {
|
|
259
|
+
sock.removeAttribute('data-compatible');
|
|
260
|
+
sock.removeAttribute('data-incompatible');
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Show port hints: highlight compatible ports on nearest side
|
|
266
|
+
* @param {number} worldX - Cursor X in graph coordinates
|
|
267
|
+
* @param {number} worldY - Cursor Y in graph coordinates
|
|
268
|
+
* @param {object} socketData - Picked socket data
|
|
269
|
+
* @returns {Set<string>}
|
|
270
|
+
*/
|
|
271
|
+
updatePortHints(worldX, worldY, socketData) {
|
|
272
|
+
const compatibleIds = this.getCompatibleNodeIds(socketData);
|
|
273
|
+
|
|
274
|
+
for (const [nodeId, el] of this.#nodeViews) {
|
|
275
|
+
if (compatibleIds.has(nodeId)) {
|
|
276
|
+
const nodePos = el._position;
|
|
277
|
+
const nodeW = el.offsetWidth || 180;
|
|
278
|
+
const nodeCenterX = nodePos ? nodePos.x + nodeW / 2 : 0;
|
|
279
|
+
el.setAttribute('data-port-hint', worldX < nodeCenterX ? 'left' : 'right');
|
|
280
|
+
} else {
|
|
281
|
+
el.removeAttribute('data-port-hint');
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return compatibleIds;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Get set of node IDs with compatible ports (no teleportation)
|
|
290
|
+
* @param {object} socketData - Picked socket data
|
|
291
|
+
* @returns {Set<string>}
|
|
292
|
+
*/
|
|
293
|
+
getCompatibleNodeIds(socketData) {
|
|
294
|
+
const pickedNode = this.#editor.getNode(socketData.nodeId);
|
|
295
|
+
if (!pickedNode) return new Set();
|
|
296
|
+
|
|
297
|
+
const isOutput = socketData.side === 'output';
|
|
298
|
+
const pickedPort = isOutput ? pickedNode.outputs[socketData.key] : pickedNode.inputs[socketData.key];
|
|
299
|
+
if (!pickedPort) return new Set();
|
|
300
|
+
|
|
301
|
+
const pickedSocket = pickedPort.socket;
|
|
302
|
+
const compatibleIds = new Set();
|
|
303
|
+
|
|
304
|
+
for (const [nodeId] of this.#nodeViews) {
|
|
305
|
+
if (nodeId === socketData.nodeId) continue;
|
|
306
|
+
const targetNode = this.#editor.getNode(nodeId);
|
|
307
|
+
if (!targetNode) continue;
|
|
308
|
+
|
|
309
|
+
const ports = isOutput ? targetNode.inputs : targetNode.outputs;
|
|
310
|
+
for (const [, port] of Object.entries(ports)) {
|
|
311
|
+
if (pickedSocket.isCompatibleWith(port.socket)) {
|
|
312
|
+
compatibleIds.add(nodeId);
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return compatibleIds;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Clear all port hints
|
|
323
|
+
*/
|
|
324
|
+
clearPortHints() {
|
|
325
|
+
for (const [, el] of this.#nodeViews) {
|
|
326
|
+
el.removeAttribute('data-port-hint');
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Handle connection dropped in empty space
|
|
332
|
+
* @param {number} x
|
|
333
|
+
* @param {number} y
|
|
334
|
+
* @param {object} socketData
|
|
335
|
+
*/
|
|
336
|
+
handleDropEmpty(x, y, socketData) {
|
|
337
|
+
const node = this.#editor.getNode(socketData.nodeId);
|
|
338
|
+
if (!node) return;
|
|
339
|
+
|
|
340
|
+
const isOutput = socketData.side === 'output';
|
|
341
|
+
const port = isOutput ? node.outputs[socketData.key] : node.inputs[socketData.key];
|
|
342
|
+
const socketType = port?.socket?.type || 'any';
|
|
343
|
+
|
|
344
|
+
this.#editor.emit('dropinempty', {
|
|
345
|
+
x, y,
|
|
346
|
+
sourceNodeId: socketData.nodeId,
|
|
347
|
+
sourceKey: socketData.key,
|
|
348
|
+
sourceSide: socketData.side,
|
|
349
|
+
socketType,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// --- Copy/Paste ---
|
|
354
|
+
|
|
355
|
+
#copySelected() {
|
|
356
|
+
const selected = this.#selector.getSelectedNodes();
|
|
357
|
+
if (selected.length === 0) return;
|
|
358
|
+
|
|
359
|
+
this.#clipboard = selected.map(nodeId => {
|
|
360
|
+
const node = this.#editor.getNode(nodeId);
|
|
361
|
+
const el = this.#nodeViews.get(nodeId);
|
|
362
|
+
if (!node) return null;
|
|
363
|
+
return {
|
|
364
|
+
label: node.label,
|
|
365
|
+
type: node.type,
|
|
366
|
+
category: node.category,
|
|
367
|
+
shape: node.shape,
|
|
368
|
+
params: { ...node.params },
|
|
369
|
+
position: el?._position ? { ...el._position } : { x: 0, y: 0 },
|
|
370
|
+
};
|
|
371
|
+
}).filter(Boolean);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Paste copied nodes at optional position
|
|
376
|
+
* @param {number} [x]
|
|
377
|
+
* @param {number} [y]
|
|
378
|
+
*/
|
|
379
|
+
#pasteNodes(x, y) {
|
|
380
|
+
if (!this.#clipboard || this.#clipboard.length === 0) return;
|
|
381
|
+
|
|
382
|
+
const offset = 30;
|
|
383
|
+
for (const data of this.#clipboard) {
|
|
384
|
+
const posX = x != null ? x : data.position.x + offset;
|
|
385
|
+
const posY = y != null ? y : data.position.y + offset;
|
|
386
|
+
this.#editor.emit('contextclone', {
|
|
387
|
+
label: data.label,
|
|
388
|
+
type: data.type,
|
|
389
|
+
category: data.category,
|
|
390
|
+
shape: data.shape,
|
|
391
|
+
x: posX,
|
|
392
|
+
y: posY,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// --- Align Tools ---
|
|
398
|
+
|
|
399
|
+
/** Align selected nodes horizontally (same Y) */
|
|
400
|
+
alignSelectedHorizontal() {
|
|
401
|
+
const selected = this.#selector.getSelectedNodes();
|
|
402
|
+
if (selected.length < 2) return;
|
|
403
|
+
|
|
404
|
+
let totalY = 0;
|
|
405
|
+
for (const nodeId of selected) {
|
|
406
|
+
const el = this.#nodeViews.get(nodeId);
|
|
407
|
+
totalY += el?._position?.y || 0;
|
|
408
|
+
}
|
|
409
|
+
const avgY = totalY / selected.length;
|
|
410
|
+
|
|
411
|
+
for (const nodeId of selected) {
|
|
412
|
+
const el = this.#nodeViews.get(nodeId);
|
|
413
|
+
if (el?._position) {
|
|
414
|
+
this.#editor.emit('nodemovetopos', {
|
|
415
|
+
nodeId,
|
|
416
|
+
x: el._position.x,
|
|
417
|
+
y: avgY,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** Align selected nodes vertically (same X) */
|
|
424
|
+
alignSelectedVertical() {
|
|
425
|
+
const selected = this.#selector.getSelectedNodes();
|
|
426
|
+
if (selected.length < 2) return;
|
|
427
|
+
|
|
428
|
+
let totalX = 0;
|
|
429
|
+
for (const nodeId of selected) {
|
|
430
|
+
const el = this.#nodeViews.get(nodeId);
|
|
431
|
+
totalX += el?._position?.x || 0;
|
|
432
|
+
}
|
|
433
|
+
const avgX = totalX / selected.length;
|
|
434
|
+
|
|
435
|
+
for (const nodeId of selected) {
|
|
436
|
+
const el = this.#nodeViews.get(nodeId);
|
|
437
|
+
if (el?._position) {
|
|
438
|
+
this.#editor.emit('nodemovetopos', {
|
|
439
|
+
nodeId,
|
|
440
|
+
x: avgX,
|
|
441
|
+
y: el._position.y,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection — link between two node ports
|
|
3
|
+
*
|
|
4
|
+
* Uses symbiote-node naming: from/out/to/in
|
|
5
|
+
* Adds connection ID for selection/history support.
|
|
6
|
+
*
|
|
7
|
+
* @module symbiote-node/core/Connection
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { uid } from './Socket.js';
|
|
11
|
+
|
|
12
|
+
export class Connection {
|
|
13
|
+
/**
|
|
14
|
+
* @param {import('./Node.js').Node} sourceNode - Source node
|
|
15
|
+
* @param {string} sourceOutput - Output port key
|
|
16
|
+
* @param {import('./Node.js').Node} targetNode - Target node
|
|
17
|
+
* @param {string} targetInput - Input port key
|
|
18
|
+
*/
|
|
19
|
+
constructor(sourceNode, sourceOutput, targetNode, targetInput) {
|
|
20
|
+
if (!sourceNode.outputs[sourceOutput]) {
|
|
21
|
+
throw new Error(`source node doesn't have output '${sourceOutput}'`);
|
|
22
|
+
}
|
|
23
|
+
if (!targetNode.inputs[targetInput]) {
|
|
24
|
+
throw new Error(`target node doesn't have input '${targetInput}'`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @type {string} */
|
|
28
|
+
this.id = uid('conn');
|
|
29
|
+
|
|
30
|
+
/** @type {string} - Source node ID (symbiote-node: 'from') */
|
|
31
|
+
this.from = sourceNode.id;
|
|
32
|
+
|
|
33
|
+
/** @type {string} - Source output key (symbiote-node: 'out') */
|
|
34
|
+
this.out = sourceOutput;
|
|
35
|
+
|
|
36
|
+
/** @type {string} - Target node ID (symbiote-node: 'to') */
|
|
37
|
+
this.to = targetNode.id;
|
|
38
|
+
|
|
39
|
+
/** @type {string} - Target input key (symbiote-node: 'in') */
|
|
40
|
+
this.in = targetInput;
|
|
41
|
+
|
|
42
|
+
/** @type {boolean} */
|
|
43
|
+
this.selected = false;
|
|
44
|
+
}
|
|
45
|
+
}
|