symbiote-ui 0.3.0-alpha.4
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/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/canvas/AutoLayout.js +731 -0
- package/canvas/Breadcrumb/Breadcrumb.css.js +75 -0
- package/canvas/Breadcrumb/Breadcrumb.js +96 -0
- package/canvas/Breadcrumb/Breadcrumb.tpl.js +7 -0
- package/canvas/CanvasConnectionRenderer.js +971 -0
- package/canvas/CanvasGraph/CanvasGraph.css.js +29 -0
- package/canvas/CanvasGraph/CanvasGraph.js +1697 -0
- package/canvas/CanvasGraph/CanvasGraphDrawState.js +280 -0
- package/canvas/CanvasGraph/CanvasGraphGeometry.js +194 -0
- package/canvas/CanvasViewport.js +550 -0
- package/canvas/ConnectionRenderer.js +1283 -0
- package/canvas/FlowSimulator.js +326 -0
- package/canvas/ForceLayout.js +226 -0
- package/canvas/ForceWorker.js +1303 -0
- package/canvas/FrameManager.js +223 -0
- package/canvas/GraphExplorerShell/GraphExplorerShell.css.js +136 -0
- package/canvas/GraphExplorerShell/GraphExplorerShell.js +129 -0
- package/canvas/GraphExplorerShell/GraphExplorerShell.tpl.js +12 -0
- package/canvas/GraphTabs/GraphTabs.css.js +101 -0
- package/canvas/GraphTabs/GraphTabs.js +189 -0
- package/canvas/GraphTabs/GraphTabs.tpl.js +12 -0
- package/canvas/LODManager.js +88 -0
- package/canvas/Minimap/Minimap.css.js +73 -0
- package/canvas/Minimap/Minimap.js +210 -0
- package/canvas/Minimap/Minimap.tpl.js +7 -0
- package/canvas/NodeCanvas/NodeCanvas.css.js +398 -0
- package/canvas/NodeCanvas/NodeCanvas.js +1499 -0
- package/canvas/NodeCanvas/NodeCanvas.tpl.js +22 -0
- package/canvas/NodeSearch/NodeSearch.css.js +97 -0
- package/canvas/NodeSearch/NodeSearch.js +140 -0
- package/canvas/NodeSearch/NodeSearch.tpl.js +25 -0
- package/canvas/NodeViewManager.js +748 -0
- package/canvas/PcbRouteDiagnostics.js +463 -0
- package/canvas/PcbRouter.js +1127 -0
- package/canvas/PinExpansion.js +134 -0
- package/canvas/PseudoConnection.js +84 -0
- package/canvas/SelectionSync.js +163 -0
- package/canvas/SubgraphManager.js +203 -0
- package/canvas/SubgraphRouter.js +452 -0
- package/canvas/ViewportActions.js +473 -0
- package/canvas/graph-explorer.js +339 -0
- package/canvas/graph-layout.js +148 -0
- package/canvas/graph-model.js +68 -0
- package/canvas/html-in-canvas.js +202 -0
- package/canvas/project-graph-builder.js +440 -0
- package/canvas/project-graph-model.js +183 -0
- package/chat/ChatComposer/ChatComposer.css.js +652 -0
- package/chat/ChatComposer/ChatComposer.js +304 -0
- package/chat/ChatList/ChatList.css.js +102 -0
- package/chat/ChatList/ChatList.js +99 -0
- package/chat/ChatList/ChatList.tpl.js +20 -0
- package/chat/ChatListItem/ChatListItem.css.js +117 -0
- package/chat/ChatListItem/ChatListItem.js +32 -0
- package/chat/ChatListItem/ChatListItem.tpl.js +17 -0
- package/chat/ChatMessageItem/ChatMessageItem.css.js +628 -0
- package/chat/ChatMessageItem/ChatMessageItem.js +156 -0
- package/chat/ChatSidebar/ChatSidebar.css.js +150 -0
- package/chat/ChatSidebar/ChatSidebar.js +230 -0
- package/chat/ChatSidebar/ChatSidebar.tpl.js +18 -0
- package/chat/ChatSidebar/constants.js +11 -0
- package/chat/ChatSidebarItem/ChatSidebarItem.css.js +445 -0
- package/chat/ChatSidebarItem/ChatSidebarItem.js +304 -0
- package/chat/ChatTranscript/ChatTranscript.css.js +90 -0
- package/chat/ChatTranscript/ChatTranscript.js +244 -0
- package/chat/chat-context.js +123 -0
- package/chat/message-model.js +156 -0
- package/cli.js +20 -0
- package/control/Button/Button.css.js +93 -0
- package/control/Button/Button.js +78 -0
- package/control/Button/Button.tpl.js +3 -0
- package/control/Field/Field.css.js +91 -0
- package/control/Field/Field.js +17 -0
- package/control/Field/Field.tpl.js +3 -0
- package/core/Connection.js +47 -0
- package/core/Editor.js +449 -0
- package/core/Frame.js +33 -0
- package/core/GraphMermaid.js +348 -0
- package/core/GraphText.js +228 -0
- package/core/Node.js +145 -0
- package/core/Portal.js +106 -0
- package/core/Socket.js +187 -0
- package/core/SubgraphNode.js +121 -0
- package/core/base-path.js +55 -0
- package/core/dom-utils.js +14 -0
- package/core/index.js +18 -0
- package/core/local-cache.js +26 -0
- package/core/state-sync.js +227 -0
- package/custom-elements.json +6380 -0
- package/discover.js +240 -0
- package/display/Badge/Badge.css.js +44 -0
- package/display/Badge/Badge.js +17 -0
- package/display/Badge/Badge.tpl.js +3 -0
- package/display/Banner/Banner.css.js +61 -0
- package/display/Banner/Banner.js +17 -0
- package/display/Banner/Banner.tpl.js +3 -0
- package/display/CodeBlock/CodeBlock.css.js +194 -0
- package/display/CodeBlock/CodeBlock.js +220 -0
- package/display/CodeBlock/CodeBlock.tpl.js +11 -0
- package/display/DataTable/DataTable.css.js +101 -0
- package/display/DataTable/DataTable.js +136 -0
- package/display/DataTable/DataTable.tpl.js +13 -0
- package/display/EmptyState/EmptyState.css.js +33 -0
- package/display/EmptyState/EmptyState.js +17 -0
- package/display/EmptyState/EmptyState.tpl.js +3 -0
- package/display/EventFeed/EventFeed.css.js +145 -0
- package/display/EventFeed/EventFeed.js +64 -0
- package/display/EventFeed/EventFeed.tpl.js +14 -0
- package/display/EventFeed/EventFeedItem.js +116 -0
- package/display/EventFeed/EventFeedItem.tpl.js +22 -0
- package/display/LoadingOverlay/LoadingOverlay.css.js +91 -0
- package/display/LoadingOverlay/LoadingOverlay.js +48 -0
- package/display/LoadingOverlay/LoadingOverlay.tpl.js +12 -0
- package/display/Metric/Metric.css.js +60 -0
- package/display/Metric/Metric.js +17 -0
- package/display/Metric/Metric.tpl.js +6 -0
- package/display/OutputGraphPreview/OutputGraphPreview.css.js +122 -0
- package/display/OutputGraphPreview/OutputGraphPreview.js +89 -0
- package/display/OutputGraphPreview/OutputGraphPreview.tpl.js +13 -0
- package/display/OutputListPreview/OutputListPreview.css.js +109 -0
- package/display/OutputListPreview/OutputListPreview.js +77 -0
- package/display/OutputListPreview/OutputListPreview.tpl.js +13 -0
- package/display/SourceEditor/SourceEditor.css.js +39 -0
- package/display/SourceEditor/SourceEditor.js +129 -0
- package/display/SourceEditor/SourceEditor.tpl.js +10 -0
- package/display/SourceViewer/SourceViewer.css.js +80 -0
- package/display/SourceViewer/SourceViewer.js +418 -0
- package/display/SourceViewer/SourceViewer.tpl.js +17 -0
- package/display/StatusRibbon/StatusRibbon.css.js +73 -0
- package/display/StatusRibbon/StatusRibbon.js +87 -0
- package/display/StatusRibbon/StatusRibbon.tpl.js +7 -0
- package/display/event-feed-adapter.js +72 -0
- package/display/format-utils.js +29 -0
- package/display/highlight.js +659 -0
- package/display/icons.js +37 -0
- package/display/markdown-formatter.js +60 -0
- package/display/network-approval-page.js +487 -0
- package/display/output-preview.js +261 -0
- package/effects/CellBg/CellBg.css.js +33 -0
- package/effects/CellBg/CellBg.js +410 -0
- package/effects/CellBg/CellBg.tpl.js +5 -0
- package/graph/canvas-adapter.js +223 -0
- package/graph/graph-algorithms.js +31 -0
- package/graph/index.js +46 -0
- package/graph/model.js +176 -0
- package/graph/project-graph-build.js +66 -0
- package/graph/project-graph-metadata.js +253 -0
- package/graph/project-package.js +128 -0
- package/graph/project-runtime.js +116 -0
- package/graph/project-transaction.js +284 -0
- package/graph/skeleton-utils.js +84 -0
- package/graph/theme-contract.js +36 -0
- package/graph/transaction-parser.js +56 -0
- package/icons/MaterialSymbols.js +69 -0
- package/icons/material-symbols-outlined-400.ttf +0 -0
- package/icons/material-symbols.css +24 -0
- package/index.js +95 -0
- package/inspector/InspectorPanel/InspectorPanel.css.js +375 -0
- package/inspector/InspectorPanel/InspectorPanel.js +368 -0
- package/inspector/InspectorPanel/InspectorPanel.tpl.js +96 -0
- package/inspector/TemplatePreview/TemplatePreview.css.js +104 -0
- package/inspector/TemplatePreview/TemplatePreview.js +145 -0
- package/inspector/TemplatePreview/TemplatePreview.tpl.js +33 -0
- package/interactions/ConnectFlow.js +304 -0
- package/interactions/Drag.js +104 -0
- package/interactions/Selector.js +133 -0
- package/interactions/SnapGrid.js +66 -0
- package/interactions/Zoom.js +139 -0
- package/layout/ActionZone/ActionZone.css.js +88 -0
- package/layout/ActionZone/ActionZone.js +261 -0
- package/layout/ActionZone/ActionZone.tpl.js +11 -0
- package/layout/CrossLayoutPortalBridge/CrossLayoutPortalBridge.js +255 -0
- package/layout/Layout/Layout.css.js +91 -0
- package/layout/Layout/Layout.js +637 -0
- package/layout/Layout/Layout.tpl.js +27 -0
- package/layout/LayoutNode/LayoutNode.css.js +302 -0
- package/layout/LayoutNode/LayoutNode.js +509 -0
- package/layout/LayoutNode/LayoutNode.tpl.js +39 -0
- package/layout/LayoutPreview/LayoutPreview.css.js +46 -0
- package/layout/LayoutPreview/LayoutPreview.js +102 -0
- package/layout/LayoutPreview/LayoutPreview.tpl.js +6 -0
- package/layout/LayoutRouter/LayoutRouter.js +274 -0
- package/layout/LayoutRouter/SectionRegistry.js +135 -0
- package/layout/LayoutRouter/routerSync.js +250 -0
- package/layout/LayoutSidebar/LayoutSidebar.css.js +411 -0
- package/layout/LayoutSidebar/LayoutSidebar.js +368 -0
- package/layout/LayoutSidebar/LayoutSidebar.tpl.js +26 -0
- package/layout/LayoutSidebar/SidebarSection.css.js +20 -0
- package/layout/LayoutSidebar/SidebarSection.js +184 -0
- package/layout/LayoutSidebar/SidebarSection.tpl.js +22 -0
- package/layout/LayoutTree.js +373 -0
- package/layout/PanelMenu/PanelMenu.css.js +43 -0
- package/layout/PanelMenu/PanelMenu.js +95 -0
- package/layout/PanelMenu/PanelMenu.tpl.js +17 -0
- package/layout/ProjectTabs/ProjectTabs.css.js +188 -0
- package/layout/ProjectTabs/ProjectTabs.js +77 -0
- package/layout/ProjectTabs/ProjectTabs.tpl.js +15 -0
- package/layout/index.js +40 -0
- package/list/ListDetailShell/ListDetailShell.css.js +128 -0
- package/list/ListDetailShell/ListDetailShell.js +72 -0
- package/list/ListDetailShell/ListDetailShell.tpl.js +36 -0
- package/list/ListItem/ListItem.css.js +111 -0
- package/list/ListItem/ListItem.js +66 -0
- package/list/ListItem/ListItem.tpl.js +18 -0
- package/locale/index.js +503 -0
- package/manifest/component-registry.js +2446 -0
- package/manifest/graph-schema.js +285 -0
- package/manifest/index.js +6 -0
- package/manifest/project-schema-catalog.js +246 -0
- package/manifest/rule-catalog.js +201 -0
- package/manifest/theme-catalog.js +2149 -0
- package/manifest/ui-schema-catalog.js +334 -0
- package/menu/ContextMenu/ContextMenu.css.js +61 -0
- package/menu/ContextMenu/ContextMenu.js +82 -0
- package/menu/ContextMenu/ContextMenu.tpl.js +19 -0
- package/navigation/QuickOpen/QuickOpen.css.js +92 -0
- package/navigation/QuickOpen/QuickOpen.js +185 -0
- package/navigation/QuickOpen/QuickOpen.tpl.js +15 -0
- package/navigation/quick-open-utils.js +101 -0
- package/node/CtrlItem/CtrlItem.css.js +41 -0
- package/node/CtrlItem/CtrlItem.js +24 -0
- package/node/CtrlItem/CtrlItem.tpl.js +17 -0
- package/node/GraphFrame/GraphFrame.css.js +66 -0
- package/node/GraphFrame/GraphFrame.js +32 -0
- package/node/GraphFrame/GraphFrame.tpl.js +13 -0
- package/node/GraphNode/GraphNode.css.js +815 -0
- package/node/GraphNode/GraphNode.js +173 -0
- package/node/GraphNode/GraphNode.tpl.js +33 -0
- package/node/NodeCallout/NodeCallout.css.js +91 -0
- package/node/NodeCallout/NodeCallout.js +281 -0
- package/node/NodeCallout/NodeCallout.tpl.js +8 -0
- package/node/NodeSocket/NodeSocket.css.js +68 -0
- package/node/NodeSocket/NodeSocket.js +26 -0
- package/node/NodeSocket/NodeSocket.tpl.js +7 -0
- package/node/PortItem/PortItem.css.js +93 -0
- package/node/PortItem/PortItem.js +87 -0
- package/node/PortItem/PortItem.tpl.js +10 -0
- package/package.json +165 -0
- package/palette/PaletteBrowser/PaletteBrowser.css.js +143 -0
- package/palette/PaletteBrowser/PaletteBrowser.js +152 -0
- package/palette/PaletteBrowser/PaletteBrowser.tpl.js +23 -0
- package/plugins/History.js +408 -0
- package/plugins/Readonly.js +60 -0
- package/rules/symbiote-3x.json +170 -0
- package/schemas/component-descriptor-v1.json +91 -0
- package/schemas/component-descriptor-v2.json +145 -0
- package/schemas/graph-model-v1.json +179 -0
- package/schemas/graph-v1.json +91 -0
- package/schemas/project-package-v1.json +102 -0
- package/schemas/project-transaction-v1.json +114 -0
- package/schemas/runtime-ui-v1.json +80 -0
- package/schemas/theme-rule-block-v1.json +73 -0
- package/shapes/CircleShape.js +79 -0
- package/shapes/CommentShape.js +35 -0
- package/shapes/DiamondShape.js +130 -0
- package/shapes/NodeShape.js +79 -0
- package/shapes/PillShape.js +91 -0
- package/shapes/RectShape.js +84 -0
- package/shapes/SVGShape.js +525 -0
- package/shapes/index.js +63 -0
- package/surface/Card/Card.css.js +57 -0
- package/surface/Card/Card.js +17 -0
- package/surface/Card/Card.tpl.js +3 -0
- package/themes/Palette.js +30 -0
- package/themes/Skin.js +113 -0
- package/themes/Theme.js +82 -0
- package/themes/carbon.js +135 -0
- package/themes/dark.js +140 -0
- package/themes/default-dark.js +714 -0
- package/themes/default-provider.css +635 -0
- package/themes/default-provider.js +718 -0
- package/themes/ebook.js +136 -0
- package/themes/grey.js +137 -0
- package/themes/light.js +139 -0
- package/themes/neon.js +138 -0
- package/themes/pcb.js +273 -0
- package/themes/synthwave.js +138 -0
- package/tokens/base.json +29 -0
- package/tokens/themes/carbon.json +11 -0
- package/tokens/themes/dark.json +12 -0
- package/tokens/themes/default-dark.json +1543 -0
- package/tokens/themes/default-provider.json +1543 -0
- package/tokens/themes/ebook.json +11 -0
- package/tokens/themes/grey.json +11 -0
- package/tokens/themes/light.json +12 -0
- package/tokens/themes/neon.json +11 -0
- package/tokens/themes/pcb.json +11 -0
- package/tokens/themes/synthwave.json +11 -0
- package/toolbar/QuickToolbar/QuickToolbar.css.js +152 -0
- package/toolbar/QuickToolbar/QuickToolbar.js +529 -0
- package/toolbar/QuickToolbar/QuickToolbar.tpl.js +34 -0
- package/tree/TreePanel/TreePanel.css.js +112 -0
- package/tree/TreePanel/TreePanel.js +147 -0
- package/tree/TreePanel/TreePanel.tpl.js +18 -0
- package/tree/TreeView/TreeView.css.js +122 -0
- package/tree/TreeView/TreeView.js +365 -0
- package/tree/TreeView/TreeView.tpl.js +10 -0
- package/ui/dialogs.js +221 -0
- package/ui/host-adapters.js +114 -0
- package/ui/index.js +660 -0
- package/ui/locale.js +50 -0
- package/ui/overlay-stack.js +89 -0
- package/ui/shared-styles.js +26 -0
- package/webmcp.js +37 -0
- package/xr/deep-graph.js +646 -0
- package/xr/emulation.js +198 -0
- package/xr/gesture.js +228 -0
- package/xr/html-canvas-renderer.js +472 -0
- package/xr/index.js +15 -0
- package/xr/layout-projection.js +1046 -0
- package/xr/panel-frame.js +128 -0
- package/xr/panel-host.js +267 -0
- package/xr/pointer.js +258 -0
- package/xr/scene-controller.js +242 -0
- package/xr/spatial-scene.js +212 -0
- package/xr/theme-bridge.js +105 -0
- package/xr/three-webxr-adapter.js +3439 -0
- package/xr/webgl-layer-renderer.js +419 -0
- package/xr/webxr.js +679 -0
- package/xr/workbench.js +516 -0
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
/**
|
|
3
|
+
* NodeViewManager — creates/destroys graph-node elements with group drag
|
|
4
|
+
*
|
|
5
|
+
* Handles DOM creation, drag initialization with snap-to-grid,
|
|
6
|
+
* group drag for multi-selected nodes, and twitch click detection.
|
|
7
|
+
* Extracted from NodeCanvas to reduce complexity (was 27 cyclomatic).
|
|
8
|
+
*
|
|
9
|
+
* @module symbiote-node/canvas/NodeViewManager
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Drag } from '../interactions/Drag.js';
|
|
13
|
+
import { Selector } from '../interactions/Selector.js';
|
|
14
|
+
import { animateOut } from '@symbiotejs/symbiote';
|
|
15
|
+
import { getShape } from '../shapes/index.js';
|
|
16
|
+
import { ensureMaterialSymbols } from '../icons/MaterialSymbols.js';
|
|
17
|
+
|
|
18
|
+
let svgMediaClipSeq = 0;
|
|
19
|
+
let svgPathBoundsCache = new Map();
|
|
20
|
+
|
|
21
|
+
function nodeTypeTokenName(type) {
|
|
22
|
+
let segment = String(type || 'default')
|
|
23
|
+
.trim()
|
|
24
|
+
.toLowerCase()
|
|
25
|
+
.replace(/[^a-z0-9_-]+/g, '-')
|
|
26
|
+
.replace(/^-+|-+$/g, '');
|
|
27
|
+
return `--sn-type-${segment || 'default'}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function readCssToken(source, token) {
|
|
31
|
+
return getComputedStyle(source).getPropertyValue(token).trim();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getFallbackPathBounds(viewBox) {
|
|
35
|
+
let [x, y, width, height] = viewBox;
|
|
36
|
+
return { x, y, width, height };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function measureSvgPathBounds(shape, viewBox) {
|
|
40
|
+
let cacheKey = `${shape.viewBox}|${shape.pathData}`;
|
|
41
|
+
if (svgPathBoundsCache.has(cacheKey)) return svgPathBoundsCache.get(cacheKey);
|
|
42
|
+
if (typeof document === 'undefined' || !document.body) return getFallbackPathBounds(viewBox);
|
|
43
|
+
|
|
44
|
+
let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
45
|
+
let path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
46
|
+
svg.setAttribute('viewBox', shape.viewBox);
|
|
47
|
+
svg.style.position = 'absolute';
|
|
48
|
+
svg.style.inlineSize = '0';
|
|
49
|
+
svg.style.blockSize = '0';
|
|
50
|
+
svg.style.overflow = 'hidden';
|
|
51
|
+
path.setAttribute('d', shape.pathData);
|
|
52
|
+
svg.appendChild(path);
|
|
53
|
+
document.body.appendChild(svg);
|
|
54
|
+
|
|
55
|
+
let bounds;
|
|
56
|
+
try {
|
|
57
|
+
let box = path.getBBox();
|
|
58
|
+
bounds = {
|
|
59
|
+
x: box.x,
|
|
60
|
+
y: box.y,
|
|
61
|
+
width: box.width,
|
|
62
|
+
height: box.height,
|
|
63
|
+
};
|
|
64
|
+
} catch {
|
|
65
|
+
bounds = getFallbackPathBounds(viewBox);
|
|
66
|
+
} finally {
|
|
67
|
+
svg.remove();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!Number.isFinite(bounds.width) || !Number.isFinite(bounds.height) || bounds.width <= 0 || bounds.height <= 0) {
|
|
71
|
+
bounds = getFallbackPathBounds(viewBox);
|
|
72
|
+
}
|
|
73
|
+
svgPathBoundsCache.set(cacheKey, bounds);
|
|
74
|
+
return bounds;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function percent(value) {
|
|
78
|
+
return `${value * 100}%`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function setSvgMediaClip(el, svg, shape) {
|
|
82
|
+
let [vx, vy, vw, vh] = shape.viewBox.split(' ').map(Number);
|
|
83
|
+
if (!Number.isFinite(vw) || !Number.isFinite(vh) || vw <= 0 || vh <= 0) return;
|
|
84
|
+
|
|
85
|
+
let bounds = measureSvgPathBounds(shape, [vx, vy, vw, vh]);
|
|
86
|
+
let clipId = `sn-node-media-clip-${++svgMediaClipSeq}`;
|
|
87
|
+
let defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
|
|
88
|
+
let clipPath = document.createElementNS('http://www.w3.org/2000/svg', 'clipPath');
|
|
89
|
+
let clipShape = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
90
|
+
|
|
91
|
+
clipPath.setAttribute('id', clipId);
|
|
92
|
+
clipPath.setAttribute('clipPathUnits', 'objectBoundingBox');
|
|
93
|
+
clipShape.setAttribute('d', shape.pathData);
|
|
94
|
+
clipShape.setAttribute(
|
|
95
|
+
'transform',
|
|
96
|
+
`matrix(${1 / bounds.width} 0 0 ${1 / bounds.height} ${-bounds.x / bounds.width} ${-bounds.y / bounds.height})`
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
clipPath.appendChild(clipShape);
|
|
100
|
+
defs.appendChild(clipPath);
|
|
101
|
+
svg.prepend(defs);
|
|
102
|
+
el.style.setProperty('--sn-svg-shape-media-clip', `url(#${clipId})`);
|
|
103
|
+
el.style.setProperty('--sn-svg-shape-media-left', percent((bounds.x - vx) / vw));
|
|
104
|
+
el.style.setProperty('--sn-svg-shape-media-top', percent((bounds.y - vy) / vh));
|
|
105
|
+
el.style.setProperty('--sn-svg-shape-media-width', percent(bounds.width / vw));
|
|
106
|
+
el.style.setProperty('--sn-svg-shape-media-height', percent(bounds.height / vh));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export class NodeViewManager {
|
|
110
|
+
/** @type {Map<string, HTMLElement>} */
|
|
111
|
+
#nodeViews;
|
|
112
|
+
|
|
113
|
+
/** @type {import('../core/Editor.js').NodeEditor} */
|
|
114
|
+
#editor;
|
|
115
|
+
|
|
116
|
+
/** @type {import('../interactions/Selector.js').Selector} */
|
|
117
|
+
#selector;
|
|
118
|
+
|
|
119
|
+
/** @type {import('../interactions/SnapGrid.js').SnapGrid} */
|
|
120
|
+
#snapGrid;
|
|
121
|
+
|
|
122
|
+
/** @type {function} */
|
|
123
|
+
#getZoom;
|
|
124
|
+
|
|
125
|
+
/** @type {function} */
|
|
126
|
+
#setNodePosition;
|
|
127
|
+
|
|
128
|
+
/** @type {function} */
|
|
129
|
+
#animateNodeToPosition;
|
|
130
|
+
|
|
131
|
+
/** @type {function} */
|
|
132
|
+
#onNodeClick;
|
|
133
|
+
|
|
134
|
+
/** @type {function|null} */
|
|
135
|
+
#onNodePointerEnter = null;
|
|
136
|
+
|
|
137
|
+
/** @type {function|null} */
|
|
138
|
+
#onNodePointerLeave = null;
|
|
139
|
+
|
|
140
|
+
/** @type {function|null} */
|
|
141
|
+
#onNodeDragStart = null;
|
|
142
|
+
|
|
143
|
+
/** @type {function|null} */
|
|
144
|
+
#onNodeDragEnd = null;
|
|
145
|
+
|
|
146
|
+
/** @type {Object} */
|
|
147
|
+
#canvas;
|
|
148
|
+
|
|
149
|
+
/** @type {function|null} */
|
|
150
|
+
#onSvgShapeReady = null;
|
|
151
|
+
|
|
152
|
+
/** @type {boolean} */
|
|
153
|
+
#readonly = false;
|
|
154
|
+
|
|
155
|
+
/** @type {boolean} */
|
|
156
|
+
#readonlyNodeDragging = false;
|
|
157
|
+
|
|
158
|
+
/** @type {boolean} */
|
|
159
|
+
#snapEnabled = false;
|
|
160
|
+
|
|
161
|
+
/** @type {HTMLElement} */
|
|
162
|
+
#nodesLayer;
|
|
163
|
+
|
|
164
|
+
/** @type {number} Z-index counter: increments on each select/drag */
|
|
165
|
+
#zCounter = 1;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @param {object} config
|
|
169
|
+
* @param {Map<string, HTMLElement>} config.nodeViews - shared Map
|
|
170
|
+
* @param {import('../core/Editor.js').NodeEditor} config.editor
|
|
171
|
+
* @param {import('../interactions/Selector.js').Selector} config.selector
|
|
172
|
+
* @param {import('../interactions/SnapGrid.js').SnapGrid} config.snapGrid
|
|
173
|
+
* @param {function} config.getZoom
|
|
174
|
+
* @param {function} config.setNodePosition
|
|
175
|
+
* @param {function} config.animateNodeToPosition
|
|
176
|
+
* @param {function} config.onNodeClick
|
|
177
|
+
* @param {function} [config.onNodePointerEnter]
|
|
178
|
+
* @param {function} [config.onNodePointerLeave]
|
|
179
|
+
* @param {function} [config.onNodeDragStart]
|
|
180
|
+
* @param {function} [config.onNodeDragEnd]
|
|
181
|
+
* @param {HTMLElement} config.nodesLayer
|
|
182
|
+
* @param {Object} config.canvas - NodeCanvas reference for socket registration
|
|
183
|
+
*/
|
|
184
|
+
constructor({
|
|
185
|
+
nodeViews,
|
|
186
|
+
editor,
|
|
187
|
+
selector,
|
|
188
|
+
snapGrid,
|
|
189
|
+
getZoom,
|
|
190
|
+
setNodePosition,
|
|
191
|
+
animateNodeToPosition,
|
|
192
|
+
onNodeClick,
|
|
193
|
+
onNodePointerEnter,
|
|
194
|
+
onNodePointerLeave,
|
|
195
|
+
onNodeDragStart,
|
|
196
|
+
onNodeDragEnd,
|
|
197
|
+
nodesLayer,
|
|
198
|
+
canvas,
|
|
199
|
+
onSvgShapeReady,
|
|
200
|
+
}) {
|
|
201
|
+
this.#nodeViews = nodeViews;
|
|
202
|
+
this.#editor = editor;
|
|
203
|
+
this.#selector = selector;
|
|
204
|
+
this.#snapGrid = snapGrid;
|
|
205
|
+
this.#getZoom = getZoom;
|
|
206
|
+
this.#setNodePosition = setNodePosition;
|
|
207
|
+
this.#animateNodeToPosition = animateNodeToPosition;
|
|
208
|
+
this.#onNodeClick = onNodeClick;
|
|
209
|
+
this.#onNodePointerEnter = onNodePointerEnter || null;
|
|
210
|
+
this.#onNodePointerLeave = onNodePointerLeave || null;
|
|
211
|
+
this.#onNodeDragStart = onNodeDragStart || null;
|
|
212
|
+
this.#onNodeDragEnd = onNodeDragEnd || null;
|
|
213
|
+
this.#nodesLayer = nodesLayer;
|
|
214
|
+
this.#canvas = canvas;
|
|
215
|
+
this.#onSvgShapeReady = onSvgShapeReady || null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** @param {boolean} readonly */
|
|
219
|
+
setReadonly(readonly) {
|
|
220
|
+
this.#readonly = readonly;
|
|
221
|
+
for (const [, el] of this.#nodeViews) {
|
|
222
|
+
el.toggleAttribute('data-readonly', readonly);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** @param {boolean} enabled */
|
|
227
|
+
setReadonlyNodeDragging(enabled) {
|
|
228
|
+
this.#readonlyNodeDragging = enabled;
|
|
229
|
+
for (const [, el] of this.#nodeViews) {
|
|
230
|
+
el.toggleAttribute('data-readonly-node-dragging', enabled);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** @param {boolean} enabled */
|
|
235
|
+
setSnapEnabled(enabled) {
|
|
236
|
+
this.#snapEnabled = enabled;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Create and append multiple node views in a single DOM batch.
|
|
241
|
+
* This prevents layout thrashing and O(N) mutation overhead during graph inflation.
|
|
242
|
+
* @param {import('../core/Node.js').Node[]} nodes
|
|
243
|
+
*/
|
|
244
|
+
addViews(nodes) {
|
|
245
|
+
if (!nodes || nodes.length === 0) return;
|
|
246
|
+
|
|
247
|
+
let fragment = document.createDocumentFragment();
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
for (const node of nodes) {
|
|
251
|
+
let el = this.#createNodeElement(node);
|
|
252
|
+
fragment.appendChild(el);
|
|
253
|
+
this.#nodeViews.set(node.id, el);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
this.#nodesLayer.appendChild(fragment);
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
for (const node of nodes) {
|
|
261
|
+
let el = this.#nodeViews.get(node.id);
|
|
262
|
+
if (el) this.#postProcessNodeView(node, el);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Create a graph-node element for a Node
|
|
268
|
+
* @param {import('../core/Node.js').Node} node
|
|
269
|
+
*/
|
|
270
|
+
addView(node) {
|
|
271
|
+
let el = this.#createNodeElement(node);
|
|
272
|
+
this.#nodesLayer.appendChild(el);
|
|
273
|
+
this.#nodeViews.set(node.id, el);
|
|
274
|
+
this.#postProcessNodeView(node, el);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Creates the HTMLElement for a node with its drag behavior initialized.
|
|
279
|
+
* Does NOT append to the live DOM layer.
|
|
280
|
+
* @private
|
|
281
|
+
* @param {import('../core/Node.js').Node} node
|
|
282
|
+
* @returns {HTMLElement}
|
|
283
|
+
*/
|
|
284
|
+
#createNodeElement(node) {
|
|
285
|
+
let el = document.createElement('graph-node');
|
|
286
|
+
el.style.position = 'absolute';
|
|
287
|
+
el.style.transform = 'translate(0px, 0px)';
|
|
288
|
+
el._position = { x: 0, y: 0 };
|
|
289
|
+
el._nodeData = node;
|
|
290
|
+
el.setAttribute('node-id', node.id);
|
|
291
|
+
el.setAttribute('node-label', node.label);
|
|
292
|
+
el.setAttribute('node-category', node.category);
|
|
293
|
+
el.setAttribute('node-shape', node.shape);
|
|
294
|
+
let nodeType = node.type || 'default';
|
|
295
|
+
el.setAttribute('node-type', nodeType);
|
|
296
|
+
el.style.setProperty('--sn-node-type-accent', `var(${nodeTypeTokenName(nodeType)}, var(--sn-node-category-accent))`);
|
|
297
|
+
el.toggleAttribute('data-readonly', this.#readonly);
|
|
298
|
+
el.toggleAttribute('data-readonly-node-dragging', this.#readonlyNodeDragging);
|
|
299
|
+
el._canvas = this.#canvas;
|
|
300
|
+
el.addEventListener('pointerenter', (event) => {
|
|
301
|
+
this.#onNodePointerEnter?.(node.id, el, event);
|
|
302
|
+
});
|
|
303
|
+
el.addEventListener('pointerleave', (event) => {
|
|
304
|
+
this.#onNodePointerLeave?.(node.id, el, event);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
let drag = new Drag();
|
|
308
|
+
let dragStart = null;
|
|
309
|
+
let dragMoved = false;
|
|
310
|
+
|
|
311
|
+
drag.initialize(
|
|
312
|
+
el,
|
|
313
|
+
{
|
|
314
|
+
getPosition: () => el._position,
|
|
315
|
+
getZoom: this.#getZoom,
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
shouldStart: (e) => {
|
|
319
|
+
if (this.#readonly && !this.#readonlyNodeDragging) return false;
|
|
320
|
+
|
|
321
|
+
let svgPath = el.querySelector('svg > path');
|
|
322
|
+
if (!svgPath) return true;
|
|
323
|
+
let svg = svgPath.ownerSVGElement;
|
|
324
|
+
let rect = svg.getBoundingClientRect();
|
|
325
|
+
let vb = svg.viewBox.baseVal;
|
|
326
|
+
|
|
327
|
+
let sx = ((e.clientX - rect.left) / rect.width) * vb.width + vb.x;
|
|
328
|
+
let sy = ((e.clientY - rect.top) / rect.height) * vb.height + vb.y;
|
|
329
|
+
let pt = new DOMPoint(sx, sy);
|
|
330
|
+
return svgPath.isPointInFill(pt);
|
|
331
|
+
},
|
|
332
|
+
onStart: (e) => {
|
|
333
|
+
dragStart = { x: e.pageX, y: e.pageY };
|
|
334
|
+
dragMoved = false;
|
|
335
|
+
this.#autoSelectOnDragStart(node.id, e);
|
|
336
|
+
this.#captureDragStartPositions();
|
|
337
|
+
this.#bringToFront(node.id);
|
|
338
|
+
this.#applyLift(el);
|
|
339
|
+
this.#editor.emit('nodepicked', node);
|
|
340
|
+
},
|
|
341
|
+
onTranslate: (x, y, e) => {
|
|
342
|
+
if (!dragMoved) {
|
|
343
|
+
dragMoved = true;
|
|
344
|
+
this.#onNodeDragStart?.(node.id, el, e);
|
|
345
|
+
}
|
|
346
|
+
this.#handleGroupTranslate(node.id, el, x, y);
|
|
347
|
+
},
|
|
348
|
+
onDrop: (e) => {
|
|
349
|
+
let wasDragging = dragMoved;
|
|
350
|
+
this.#handleDrop(node.id, el, e, dragStart);
|
|
351
|
+
if (wasDragging) this.#onNodeDragEnd?.(node.id, el, e);
|
|
352
|
+
dragStart = null;
|
|
353
|
+
dragMoved = false;
|
|
354
|
+
},
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
el._drag = drag;
|
|
358
|
+
|
|
359
|
+
return el;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Applies SVG shaping or subgraph previews after the element is in the live DOM.
|
|
364
|
+
* @private
|
|
365
|
+
* @param {import('../core/Node.js').Node} node
|
|
366
|
+
* @param {HTMLElement} el
|
|
367
|
+
*/
|
|
368
|
+
#postProcessNodeView(node, el) {
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
let shape = getShape(node.shape);
|
|
372
|
+
if (shape && shape.pathData) {
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
let vb = shape.viewBox.split(' ').map(Number);
|
|
376
|
+
let vbW = vb[2];
|
|
377
|
+
let vbH = vb[3];
|
|
378
|
+
let params = node.params || {};
|
|
379
|
+
let baseSize = Number(params.size || params.shapeSize) || 120;
|
|
380
|
+
let aspect = vbW / vbH;
|
|
381
|
+
let nodeW = Number(params.width) || (aspect >= 1 ? baseSize : Math.round(baseSize * aspect));
|
|
382
|
+
let nodeH = Number(params.height) || (aspect >= 1 ? Math.round(baseSize / aspect) : baseSize);
|
|
383
|
+
el.style.width = nodeW + 'px';
|
|
384
|
+
el.style.height = nodeH + 'px';
|
|
385
|
+
el.style.minWidth = nodeW + 'px';
|
|
386
|
+
el.style.minHeight = nodeH + 'px';
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
requestAnimationFrame(() => {
|
|
390
|
+
if (shape && shape.pathData) {
|
|
391
|
+
let svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
392
|
+
svg.classList.add('sn-node-shape-svg');
|
|
393
|
+
svg.setAttribute('viewBox', shape.viewBox);
|
|
394
|
+
svg.setAttribute('preserveAspectRatio', 'none');
|
|
395
|
+
let path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
396
|
+
path.setAttribute('d', shape.pathData);
|
|
397
|
+
path.setAttribute(
|
|
398
|
+
'fill',
|
|
399
|
+
`var(--sn-shape-${shape.name}-fill, var(--sn-shape-fill, var(--sn-node-bg)))`
|
|
400
|
+
);
|
|
401
|
+
path.setAttribute(
|
|
402
|
+
'stroke',
|
|
403
|
+
`var(--sn-shape-${shape.name}-stroke, var(--sn-shape-stroke, var(--sn-node-border)))`
|
|
404
|
+
);
|
|
405
|
+
path.setAttribute('stroke-width', 'var(--sn-shape-stroke-width, 0.4)');
|
|
406
|
+
path.setAttribute('stroke-linejoin', 'round');
|
|
407
|
+
svg.appendChild(path);
|
|
408
|
+
setSvgMediaClip(el, svg, shape);
|
|
409
|
+
el.prepend(svg);
|
|
410
|
+
el.setAttribute('data-svg-shape', shape.name);
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
let iconEl = el.querySelector('.sn-node-icon');
|
|
414
|
+
if (iconEl) {
|
|
415
|
+
let watermark = document.createElement('span');
|
|
416
|
+
watermark.className = 'sn-shape-watermark material-symbols-outlined';
|
|
417
|
+
watermark.textContent = iconEl.textContent;
|
|
418
|
+
ensureMaterialSymbols([iconEl.textContent]);
|
|
419
|
+
el.appendChild(watermark);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
if (this.#onSvgShapeReady) this.#onSvgShapeReady(node.id);
|
|
424
|
+
} else if (shape) {
|
|
425
|
+
|
|
426
|
+
let size = { width: el.offsetWidth || 180, height: el.offsetHeight || 60 };
|
|
427
|
+
let radius = shape.getBorderRadius(size);
|
|
428
|
+
if (radius && radius !== 'var(--sn-node-radius)') {
|
|
429
|
+
el.style.borderRadius = radius;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
if (node._isSubgraph) {
|
|
436
|
+
let body = el.querySelector('.sn-node-body');
|
|
437
|
+
if (body) {
|
|
438
|
+
let canvas = document.createElement('canvas');
|
|
439
|
+
canvas.className = 'sn-subgraph-preview';
|
|
440
|
+
canvas.width = 200;
|
|
441
|
+
canvas.height = 80;
|
|
442
|
+
body.appendChild(canvas);
|
|
443
|
+
el._previewCanvas = canvas;
|
|
444
|
+
requestAnimationFrame(() => {
|
|
445
|
+
this.#initSubgraphPreview(el, node, canvas);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Remove a graph-node element
|
|
453
|
+
* @param {import('../core/Node.js').Node} node
|
|
454
|
+
*/
|
|
455
|
+
removeView(node) {
|
|
456
|
+
let el = this.#nodeViews.get(node.id);
|
|
457
|
+
if (!el) return;
|
|
458
|
+
if (el._previewRaf) clearTimeout(el._previewRaf);
|
|
459
|
+
el._previewRaf = null;
|
|
460
|
+
if (el._drag) el._drag.destroy();
|
|
461
|
+
animateOut(el);
|
|
462
|
+
this.#nodeViews.delete(node.id);
|
|
463
|
+
this.#selector.getSelectedNodes().delete(node.id);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Remove a node view instantly (no animation) for virtualization demote.
|
|
468
|
+
* Returns captured position/size for phantom conversion.
|
|
469
|
+
* @param {string} nodeId
|
|
470
|
+
* @returns {{ x: number, y: number, w: number, h: number } | null}
|
|
471
|
+
*/
|
|
472
|
+
removeViewInstant(nodeId) {
|
|
473
|
+
let el = this.#nodeViews.get(nodeId);
|
|
474
|
+
if (!el) return null;
|
|
475
|
+
let pos = el._position || { x: 0, y: 0 };
|
|
476
|
+
let w = el._cachedW || el.offsetWidth || 180;
|
|
477
|
+
let h = el._cachedH || el.offsetHeight || 60;
|
|
478
|
+
if (el._previewRaf) clearTimeout(el._previewRaf);
|
|
479
|
+
if (el._drag) el._drag.destroy();
|
|
480
|
+
el.remove();
|
|
481
|
+
this.#nodeViews.delete(nodeId);
|
|
482
|
+
this.#selector.getSelectedNodes().delete(nodeId);
|
|
483
|
+
return { x: pos.x, y: pos.y, w, h };
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
#autoSelectOnDragStart(nodeId, e) {
|
|
488
|
+
if (!this.#selector.isNodeSelected(nodeId)) {
|
|
489
|
+
let accumulate = e.ctrlKey || e.metaKey;
|
|
490
|
+
this.#selector.selectNode(nodeId, accumulate);
|
|
491
|
+
}
|
|
492
|
+
this.#bringToFront(nodeId);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Bring a node to front by setting highest z-index
|
|
497
|
+
* @param {string} nodeId
|
|
498
|
+
*/
|
|
499
|
+
#bringToFront(nodeId) {
|
|
500
|
+
let el = this.#nodeViews.get(nodeId);
|
|
501
|
+
if (el) {
|
|
502
|
+
el.style.zIndex = ++this.#zCounter;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Apply lift effect: scale up + shadow + parallax offset
|
|
508
|
+
* @param {HTMLElement} el
|
|
509
|
+
*/
|
|
510
|
+
#applyLift(el) {
|
|
511
|
+
el.classList.add('sn-node-lifted');
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Remove lift effect on drop
|
|
516
|
+
* @param {HTMLElement} el
|
|
517
|
+
*/
|
|
518
|
+
#removeLift(el) {
|
|
519
|
+
el.classList.remove('sn-node-lifted');
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
#captureDragStartPositions() {
|
|
523
|
+
let selected = this.#selector.getSelectedNodes();
|
|
524
|
+
for (const id of selected) {
|
|
525
|
+
let nodeEl = this.#nodeViews.get(id);
|
|
526
|
+
if (nodeEl) nodeEl._dragStartPos = { ...nodeEl._position };
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
#handleGroupTranslate(nodeId, el, x, y) {
|
|
531
|
+
let finalX = x;
|
|
532
|
+
let finalY = y;
|
|
533
|
+
|
|
534
|
+
if (this.#snapEnabled && this.#snapGrid.isDynamic) {
|
|
535
|
+
let snapped = this.#snapGrid.snap(x, y);
|
|
536
|
+
finalX = snapped.x;
|
|
537
|
+
finalY = snapped.y;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
let prev = el._dragStartPos || el._position;
|
|
541
|
+
let dx = finalX - prev.x;
|
|
542
|
+
let dy = finalY - prev.y;
|
|
543
|
+
|
|
544
|
+
let selected = this.#selector.getSelectedNodes();
|
|
545
|
+
if (selected.size > 1 && selected.has(nodeId)) {
|
|
546
|
+
for (const id of selected) {
|
|
547
|
+
let nodeEl = this.#nodeViews.get(id);
|
|
548
|
+
if (!nodeEl?._dragStartPos) continue;
|
|
549
|
+
let nx = nodeEl._dragStartPos.x + dx;
|
|
550
|
+
let ny = nodeEl._dragStartPos.y + dy;
|
|
551
|
+
if (this.#snapEnabled && this.#snapGrid.isDynamic) {
|
|
552
|
+
let snapped = this.#snapGrid.snap(nx, ny);
|
|
553
|
+
nx = snapped.x;
|
|
554
|
+
ny = snapped.y;
|
|
555
|
+
}
|
|
556
|
+
this.#setNodePosition(id, nx, ny);
|
|
557
|
+
}
|
|
558
|
+
} else {
|
|
559
|
+
this.#setNodePosition(nodeId, finalX, finalY);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
this.#editor.emit('nodetranslated', { id: nodeId, position: { x: finalX, y: finalY } });
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
#handleDrop(nodeId, el, e, dragStart) {
|
|
566
|
+
|
|
567
|
+
if (this.#snapEnabled && !this.#snapGrid.isDynamic) {
|
|
568
|
+
let selected = this.#selector.getSelectedNodes();
|
|
569
|
+
let targets = selected.size > 0 && selected.has(nodeId) ? selected : new Set([nodeId]);
|
|
570
|
+
for (const id of targets) {
|
|
571
|
+
let nodeEl = this.#nodeViews.get(id);
|
|
572
|
+
if (!nodeEl) continue;
|
|
573
|
+
let snapped = this.#snapGrid.snap(nodeEl._position.x, nodeEl._position.y);
|
|
574
|
+
this.#animateNodeToPosition(id, snapped.x, snapped.y);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
for (const [, nodeEl] of this.#nodeViews) {
|
|
580
|
+
delete nodeEl._dragStartPos;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
this.#removeLift(el);
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
if (dragStart && e && Selector.isTwitch(dragStart, { x: e.pageX, y: e.pageY })) {
|
|
588
|
+
this.#onNodeClick(nodeId, e);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
this.#editor.emit('nodedragged', { id: nodeId });
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Initialize subgraph preview canvas inside a graph-node
|
|
596
|
+
* @param {HTMLElement} el - graph-node element
|
|
597
|
+
* @param {import('../core/SubgraphNode.js').SubgraphNode} node
|
|
598
|
+
* @param {HTMLCanvasElement} canvas - pre-created canvas element (already in DOM)
|
|
599
|
+
*/
|
|
600
|
+
#initSubgraphPreview(el, node, canvas) {
|
|
601
|
+
let ctx = canvas.getContext('2d');
|
|
602
|
+
|
|
603
|
+
let drawPreview = () => {
|
|
604
|
+
if (!el.isConnected) return;
|
|
605
|
+
|
|
606
|
+
let w = canvas.width;
|
|
607
|
+
let h = canvas.height;
|
|
608
|
+
ctx.clearRect(0, 0, w, h);
|
|
609
|
+
let previewColors = {
|
|
610
|
+
connection: readCssToken(el, '--sn-subgraph-preview-connection'),
|
|
611
|
+
completedConnection: readCssToken(el, '--sn-subgraph-preview-completed-connection'),
|
|
612
|
+
processingFill: readCssToken(el, '--sn-subgraph-preview-processing-fill'),
|
|
613
|
+
processingStroke: readCssToken(el, '--sn-subgraph-preview-processing-stroke'),
|
|
614
|
+
processingGlow: readCssToken(el, '--sn-subgraph-preview-processing-glow'),
|
|
615
|
+
completedFill: readCssToken(el, '--sn-subgraph-preview-completed-fill'),
|
|
616
|
+
completedStroke: readCssToken(el, '--sn-subgraph-preview-completed-stroke'),
|
|
617
|
+
idleFill: readCssToken(el, '--sn-subgraph-preview-idle-fill'),
|
|
618
|
+
idleStroke: readCssToken(el, '--sn-subgraph-preview-idle-stroke'),
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
let innerEditor = node.innerEditor;
|
|
622
|
+
if (!innerEditor) return;
|
|
623
|
+
|
|
624
|
+
let nodes = innerEditor.getNodes();
|
|
625
|
+
if (nodes.length === 0) return;
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
let positions = node.innerPositions;
|
|
629
|
+
let nodeRects = [];
|
|
630
|
+
|
|
631
|
+
for (const n of nodes) {
|
|
632
|
+
let pos = positions[n.id];
|
|
633
|
+
let x = pos ? pos.x : 0;
|
|
634
|
+
let y = pos ? pos.y : 0;
|
|
635
|
+
nodeRects.push({ x, y, w: 160, h: 60, id: n.id });
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
let minX = Infinity,
|
|
640
|
+
minY = Infinity,
|
|
641
|
+
maxX = -Infinity,
|
|
642
|
+
maxY = -Infinity;
|
|
643
|
+
for (const r of nodeRects) {
|
|
644
|
+
minX = Math.min(minX, r.x);
|
|
645
|
+
minY = Math.min(minY, r.y);
|
|
646
|
+
maxX = Math.max(maxX, r.x + r.w);
|
|
647
|
+
maxY = Math.max(maxY, r.y + r.h);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
let pad = 30;
|
|
651
|
+
minX -= pad;
|
|
652
|
+
minY -= pad;
|
|
653
|
+
maxX += pad;
|
|
654
|
+
maxY += pad;
|
|
655
|
+
|
|
656
|
+
let graphW = maxX - minX;
|
|
657
|
+
let graphH = maxY - minY;
|
|
658
|
+
let scale = Math.min(w / graphW, h / graphH);
|
|
659
|
+
let offsetX = (w - graphW * scale) / 2;
|
|
660
|
+
let offsetY = (h - graphH * scale) / 2;
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
let states = el._innerFlowStates || {};
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
let conns = innerEditor.getConnections();
|
|
667
|
+
for (const conn of conns) {
|
|
668
|
+
let src = nodeRects.find((r) => r.id === conn.from);
|
|
669
|
+
let tgt = nodeRects.find((r) => r.id === conn.to);
|
|
670
|
+
if (src && tgt) {
|
|
671
|
+
let sx = (src.x + src.w - minX) * scale + offsetX;
|
|
672
|
+
let sy = (src.y + src.h / 2 - minY) * scale + offsetY;
|
|
673
|
+
let tx = (tgt.x - minX) * scale + offsetX;
|
|
674
|
+
let ty = (tgt.y + tgt.h / 2 - minY) * scale + offsetY;
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
let srcState = states[conn.from];
|
|
678
|
+
if (srcState === 'completed') {
|
|
679
|
+
ctx.strokeStyle = previewColors.completedConnection;
|
|
680
|
+
ctx.lineWidth = 2;
|
|
681
|
+
} else {
|
|
682
|
+
ctx.strokeStyle = previewColors.connection;
|
|
683
|
+
ctx.lineWidth = 1;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
ctx.beginPath();
|
|
687
|
+
ctx.moveTo(sx, sy);
|
|
688
|
+
ctx.lineTo(tx, ty);
|
|
689
|
+
ctx.stroke();
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
for (const r of nodeRects) {
|
|
695
|
+
let rx = (r.x - minX) * scale + offsetX;
|
|
696
|
+
let ry = (r.y - minY) * scale + offsetY;
|
|
697
|
+
let rw = r.w * scale;
|
|
698
|
+
let rh = r.h * scale;
|
|
699
|
+
let state = states[r.id];
|
|
700
|
+
let radius = 4;
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
ctx.beginPath();
|
|
704
|
+
ctx.moveTo(rx + radius, ry);
|
|
705
|
+
ctx.lineTo(rx + rw - radius, ry);
|
|
706
|
+
ctx.quadraticCurveTo(rx + rw, ry, rx + rw, ry + radius);
|
|
707
|
+
ctx.lineTo(rx + rw, ry + rh - radius);
|
|
708
|
+
ctx.quadraticCurveTo(rx + rw, ry + rh, rx + rw - radius, ry + rh);
|
|
709
|
+
ctx.lineTo(rx + radius, ry + rh);
|
|
710
|
+
ctx.quadraticCurveTo(rx, ry + rh, rx, ry + rh - radius);
|
|
711
|
+
ctx.lineTo(rx, ry + radius);
|
|
712
|
+
ctx.quadraticCurveTo(rx, ry, rx + radius, ry);
|
|
713
|
+
ctx.closePath();
|
|
714
|
+
|
|
715
|
+
if (state === 'processing') {
|
|
716
|
+
ctx.fillStyle = previewColors.processingFill;
|
|
717
|
+
ctx.fill();
|
|
718
|
+
ctx.strokeStyle = previewColors.processingStroke;
|
|
719
|
+
ctx.lineWidth = 1.5;
|
|
720
|
+
ctx.stroke();
|
|
721
|
+
|
|
722
|
+
ctx.shadowColor = previewColors.processingGlow;
|
|
723
|
+
ctx.shadowBlur = 8;
|
|
724
|
+
ctx.stroke();
|
|
725
|
+
ctx.shadowBlur = 0;
|
|
726
|
+
} else if (state === 'completed') {
|
|
727
|
+
ctx.fillStyle = previewColors.completedFill;
|
|
728
|
+
ctx.fill();
|
|
729
|
+
ctx.strokeStyle = previewColors.completedStroke;
|
|
730
|
+
ctx.lineWidth = 1;
|
|
731
|
+
ctx.stroke();
|
|
732
|
+
} else {
|
|
733
|
+
ctx.fillStyle = previewColors.idleFill;
|
|
734
|
+
ctx.fill();
|
|
735
|
+
ctx.strokeStyle = previewColors.idleStroke;
|
|
736
|
+
ctx.lineWidth = 0.5;
|
|
737
|
+
ctx.stroke();
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
el._redrawPreview = drawPreview;
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
drawPreview();
|
|
747
|
+
}
|
|
748
|
+
}
|